Skip to content

Commit 733945a

Browse files
committed
chore(docs): improve comments
1 parent 874d144 commit 733945a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

projects/code-editor/code-editor.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
OnInit,
1010
Output,
1111
SimpleChanges,
12+
ViewEncapsulation,
1213
forwardRef,
1314
} from '@angular/core';
1415
import { 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
})
3940
export 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) {

projects/dev-app/src/app/app.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<code-editor #editor
2121
[(ngModel)]="code"
2222
[ngModelOptions]="{updateOn:'blur'}"
23-
(ngModelChange)="log(editor)"
23+
(ngModelChange)="log($event)"
2424
[theme]="theme"
2525
[disabled]="disabled"
2626
[readonly]="readonly"
@@ -36,3 +36,5 @@
3636
</label>
3737

3838
<code-editor [formControl]="editorControl" />
39+
40+
<pre>{{editorControl.value}}</pre>

projects/dev-app/src/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { RouterOutlet } from '@angular/router';
1111
styleUrl: './app.component.scss',
1212
})
1313
export class AppComponent {
14-
code = 'console.log("Hello world")';
15-
1614
theme: Theme = 'light';
1715
disabled = false;
1816
readonly = false;
1917
placeholder = 'Type your code here...';
2018

19+
code = 'console.log("Hello world")';
20+
2121
editorControl = new FormControl({ value: 'hello', disabled: true });
2222

2323
log(e: any) {

0 commit comments

Comments
 (0)