99 OnInit ,
1010 Output ,
1111 SimpleChanges ,
12+ ViewEncapsulation ,
1213 forwardRef ,
1314} from '@angular/core' ;
1415import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
@@ -25,8 +26,8 @@ export type Theme = 'light' | 'dark' | Extension;
2526@Component ( {
2627 selector : 'code-editor' ,
2728 standalone : true ,
28- imports : [ ] ,
2929 template : `` ,
30+ encapsulation : ViewEncapsulation . None ,
3031 changeDetection : ChangeDetectionStrategy . OnPush ,
3132 providers : [
3233 {
@@ -37,6 +38,11 @@ export type Theme = 'light' | 'dark' | Extension;
3738 ] ,
3839} )
3940export class CodeEditor implements OnChanges , OnInit , OnDestroy , ControlValueAccessor {
41+ /**
42+ * The document or shadow root that the view lives in.
43+ *
44+ * https://codemirror.net/docs/ref/#view.EditorView.root
45+ */
4046 @Input ( ) root ?: Document | ShadowRoot ;
4147
4248 /** Editor's value. */
@@ -67,6 +73,7 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
6773
6874 /**
6975 * EditorState's [extensions](https://codemirror.net/docs/ref/#state.EditorStateConfig.extensions).
76+ * It includes the [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup) by default.
7077 */
7178 @Input ( ) extensions : Extension [ ] = [ basicSetup ] ;
7279
@@ -89,8 +96,7 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
8996 /** Register a function to be called every time the view updates. */
9097 private _updateListener = EditorView . updateListener . of ( vu => {
9198 if ( vu . docChanged && ! vu . transactions . some ( tr => tr . annotation ( External ) ) ) {
92- const doc = vu . state . doc ;
93- const value = doc . toString ( ) ;
99+ const value = vu . state . doc . toString ( ) ;
94100 this . _onChange ( value ) ;
95101 this . change . emit ( value ) ;
96102 }
@@ -140,7 +146,10 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
140146 this . view = new EditorView ( {
141147 root : this . root ,
142148 parent : this . _elementRef . nativeElement ,
143- state : EditorState . create ( { doc : this . value , extensions : this . getExtensions ( ) } ) ,
149+ state : EditorState . create ( {
150+ doc : this . value ,
151+ extensions : this . getExtensions ( ) ,
152+ } ) ,
144153 } ) ;
145154
146155 if ( this . autoFocus ) {
0 commit comments