mcgilman commented on code in PR #10144:
URL: https://github.com/apache/nifi/pull/10144#discussion_r2288691715


##########
nifi-frontend/src/main/frontend/libs/shared/src/components/codemirror/codemirror.component.ts:
##########
@@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {
+    ChangeDetectionStrategy,
+    Component,
+    ElementRef,
+    EventEmitter,
+    Input,
+    OnChanges,
+    OnDestroy,
+    OnInit,
+    Output,
+    SimpleChanges,
+    ViewEncapsulation,
+    forwardRef
+} from '@angular/core';
+import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
+import { Annotation, Compartment, EditorState, Extension } from 
'@codemirror/state';
+import { EditorView } from '@codemirror/view';
+import { defaultTheme } from './themes/defaultTheme';
+
+export interface CodeMirrorConfig {
+    appearance?: Extension;
+    focusOnInit?: boolean;
+    content?: string;
+    disabled?: boolean;
+    readOnly?: boolean;
+    plugins?: Extension[];
+}
+
+/**
+ * Annotation to mark editor changes that come from external sources (not user 
input).
+ * Used to prevent infinite loops in two-way data binding by:
+ * 1. Marking programmatic changes with this annotation
+ * 2. Not emitting change events for changes that have this annotation
+ *
+ * @example
+ * // Mark a change as external
+ * dispatch({
+ *   changes: { from: 0, to: 10, insert: "new text" },
+ *   annotations: [ExternalChange.of(true)]
+ * });
+ *
+ * // Check if a change is external
+ * if (!transaction.annotation(ExternalChange)) {
+ *   // Handle user input...
+ * }
+ */
+export const ExternalChange = Annotation.define<boolean>();
+
+@Component({
+    selector: 'codemirror',
+    standalone: true,
+    templateUrl: './codemirror.component.html',
+    styleUrls: ['./codemirror.component.scss'],
+    host: {
+        class: 'cm-s-nifi'
+    },
+    encapsulation: ViewEncapsulation.None,
+    changeDetection: ChangeDetectionStrategy.OnPush,
+    providers: [
+        {
+            provide: NG_VALUE_ACCESSOR,
+            useExisting: forwardRef(() => Codemirror),
+            multi: true
+        }
+    ]
+})
+export class Codemirror implements OnChanges, OnInit, OnDestroy, 
ControlValueAccessor {
+    @Input() documentRoot?: Document | ShadowRoot;
+    @Input() config: CodeMirrorConfig = {
+        appearance: defaultTheme,
+        focusOnInit: false,
+        content: '',
+        disabled: false,
+        readOnly: false,
+        plugins: []
+    };
+
+    private readonly defaultConfig: CodeMirrorConfig = {
+        appearance: defaultTheme,
+        focusOnInit: false,
+        content: '',
+        disabled: false,
+        readOnly: false,
+        plugins: []
+    };
+
+    @Output() contentChange = new EventEmitter<string>();
+    @Output() ready = new EventEmitter<Codemirror>();
+    @Output() focused = new EventEmitter<void>();
+    @Output() blurred = new EventEmitter<void>();
+
+    private view: EditorView | null = null;
+    public isInitialized = false;

Review Comment:
   Can we make this private? If we need to expose this value outside of this 
component (like in a unit test) we can add a method for it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to