@aiao/code-editor-angular 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,555 +1,610 @@
|
|
|
1
|
-
import { SUPPORT_LANGUAGES,
|
|
2
|
-
import { isPlatformBrowser } from
|
|
3
|
-
import * as i0 from
|
|
4
|
-
import {
|
|
5
|
-
import { NG_VALUE_ACCESSOR } from
|
|
6
|
-
import { indentWithTab } from
|
|
7
|
-
import { indentUnit } from
|
|
8
|
-
import { Annotation, Compartment, EditorState, Transaction } from
|
|
9
|
-
import { oneDark } from
|
|
10
|
-
import { EditorView,
|
|
11
|
-
import { basicSetup, minimalSetup } from
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 标记「外部写入」的注解,用于让 updateListener 跳过 onChange 回调。
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
|
-
* 模块私有,不对外导出:每个框架绑定各有一个互不相同的 Annotation 实例,
|
|
18
|
-
* 一旦暴露就等于承诺了一个三端无法对齐的语义(React / Vue 两端同样是模块私有)。
|
|
19
|
-
*/
|
|
1
|
+
import { SUPPORT_LANGUAGES, buildCodeEditorContentAttributes, codeEditorLanguageLoadFailed, codeEditorLanguageNotFound, computeMinimalDocumentChange, isSameResolvedLanguage, resolveCodeEditorLanguage, shouldAutoFocusCodeEditor } from "@aiao/code-editor";
|
|
2
|
+
import { isPlatformBrowser } from "@angular/common";
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
import { ChangeDetectionStrategy, Component, ElementRef, PLATFORM_ID, booleanAttribute, computed, forwardRef, inject, input, output, signal } from "@angular/core";
|
|
5
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
6
|
+
import { indentWithTab } from "@codemirror/commands";
|
|
7
|
+
import { indentUnit } from "@codemirror/language";
|
|
8
|
+
import { Annotation, Compartment, EditorState, Transaction } from "@codemirror/state";
|
|
9
|
+
import { oneDark } from "@codemirror/theme-one-dark";
|
|
10
|
+
import { EditorView, highlightWhitespace, keymap, placeholder } from "@codemirror/view";
|
|
11
|
+
import { basicSetup, minimalSetup } from "codemirror";
|
|
20
12
|
const External = Annotation.define();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
13
|
+
var CodeEditor = class CodeEditor {
|
|
14
|
+
#view;
|
|
15
|
+
#pendingValue;
|
|
16
|
+
#languageRequest = 0;
|
|
17
|
+
#appliedLanguage;
|
|
18
|
+
#elementRef = inject(ElementRef);
|
|
19
|
+
#platformId = inject(PLATFORM_ID);
|
|
20
|
+
#isBrowser = isPlatformBrowser(this.#platformId);
|
|
21
|
+
#editableConf = new Compartment();
|
|
22
|
+
#readonlyConf = new Compartment();
|
|
23
|
+
#themeConf = new Compartment();
|
|
24
|
+
#placeholderConf = new Compartment();
|
|
25
|
+
#indentWithTabConf = new Compartment();
|
|
26
|
+
#indentUnitConf = new Compartment();
|
|
27
|
+
#lineWrappingConf = new Compartment();
|
|
28
|
+
#highlightWhitespaceConf = new Compartment();
|
|
29
|
+
#languageConf = new Compartment();
|
|
30
|
+
#a11yConf = new Compartment();
|
|
31
|
+
#setupConf = new Compartment();
|
|
32
|
+
#userExtensionsConf = new Compartment();
|
|
33
|
+
#updateListener = EditorView.updateListener.of((vu) => {
|
|
34
|
+
if (vu.docChanged && !vu.transactions.some((tr) => tr.annotation(External))) {
|
|
35
|
+
const value = vu.state.doc.toString();
|
|
36
|
+
this.#onChange?.(value);
|
|
37
|
+
this.aoChange.emit(value);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
#domEventObservers = EditorView.domEventObservers({
|
|
41
|
+
focus: () => {
|
|
42
|
+
this.aoFocus.emit();
|
|
43
|
+
},
|
|
44
|
+
blur: () => {
|
|
45
|
+
this.#onTouched?.();
|
|
46
|
+
this.aoBlur.emit();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
#formDisabled = signal(false, ...ngDevMode ? [{ debugName: "#formDisabled" }] : /* istanbul ignore next */ []);
|
|
50
|
+
#effectiveDisabled = computed(() => this.disabled() || this.#formDisabled(), ...ngDevMode ? [{ debugName: "#effectiveDisabled" }] : /* istanbul ignore next */ []);
|
|
51
|
+
#onChange;
|
|
52
|
+
#onTouched;
|
|
53
|
+
#formOwnsValue = false;
|
|
54
|
+
_ariaDisabled = computed(() => this.#effectiveDisabled() ? "true" : null, ...ngDevMode ? [{ debugName: "_ariaDisabled" }] : /* istanbul ignore next */ []);
|
|
55
|
+
autoFocus = input(false, {
|
|
56
|
+
...ngDevMode ? { debugName: "autoFocus" } : /* istanbul ignore next */ {},
|
|
57
|
+
transform: booleanAttribute
|
|
58
|
+
});
|
|
59
|
+
describedBy = input("", ...ngDevMode ? [{ debugName: "describedBy" }] : /* istanbul ignore next */ []);
|
|
60
|
+
disabled = input(false, {
|
|
61
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
62
|
+
transform: booleanAttribute
|
|
63
|
+
});
|
|
64
|
+
highlightWhitespace = input(false, {
|
|
65
|
+
...ngDevMode ? { debugName: "highlightWhitespace" } : /* istanbul ignore next */ {},
|
|
66
|
+
transform: booleanAttribute
|
|
67
|
+
});
|
|
68
|
+
indentUnit = input(" ", ...ngDevMode ? [{ debugName: "indentUnit" }] : /* istanbul ignore next */ []);
|
|
69
|
+
indentWithTab = input(false, {
|
|
70
|
+
...ngDevMode ? { debugName: "indentWithTab" } : /* istanbul ignore next */ {},
|
|
71
|
+
transform: booleanAttribute
|
|
72
|
+
});
|
|
73
|
+
language = input("sql", ...ngDevMode ? [{ debugName: "language" }] : /* istanbul ignore next */ []);
|
|
74
|
+
languages = input(SUPPORT_LANGUAGES, ...ngDevMode ? [{ debugName: "languages" }] : /* istanbul ignore next */ []);
|
|
75
|
+
label = input("", ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
76
|
+
labelledBy = input("", ...ngDevMode ? [{ debugName: "labelledBy" }] : /* istanbul ignore next */ []);
|
|
77
|
+
lineWrapping = input(false, {
|
|
78
|
+
...ngDevMode ? { debugName: "lineWrapping" } : /* istanbul ignore next */ {},
|
|
79
|
+
transform: booleanAttribute
|
|
80
|
+
});
|
|
81
|
+
placeholder = input("", ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
|
|
82
|
+
readonly = input(false, {
|
|
83
|
+
...ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {},
|
|
84
|
+
transform: booleanAttribute
|
|
85
|
+
});
|
|
86
|
+
root = input(...ngDevMode ? [void 0, { debugName: "root" }] : /* istanbul ignore next */ []);
|
|
87
|
+
setup = input("basic", ...ngDevMode ? [{ debugName: "setup" }] : /* istanbul ignore next */ []);
|
|
88
|
+
theme = input("light", ...ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []);
|
|
89
|
+
value = input("", ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
|
|
90
|
+
aoFocus = output();
|
|
91
|
+
aoChange = output();
|
|
92
|
+
aoBlur = output();
|
|
93
|
+
aoLanguageError = output();
|
|
94
|
+
get view() {
|
|
95
|
+
return this.#view ?? null;
|
|
96
|
+
}
|
|
97
|
+
get host() {
|
|
98
|
+
return this.#view ? this.#elementRef.nativeElement : null;
|
|
99
|
+
}
|
|
100
|
+
focus() {
|
|
101
|
+
this.#view?.focus();
|
|
102
|
+
}
|
|
103
|
+
blur() {
|
|
104
|
+
this.#view?.contentDOM.blur();
|
|
105
|
+
}
|
|
106
|
+
ngOnInit() {
|
|
107
|
+
if (!this.#isBrowser) return;
|
|
108
|
+
const extensions = this._get_all_extensions();
|
|
109
|
+
const state = EditorState.create({
|
|
110
|
+
doc: this.#pendingValue ?? this.value(),
|
|
111
|
+
extensions
|
|
112
|
+
});
|
|
113
|
+
this.#view = new EditorView({
|
|
114
|
+
parent: this.#elementRef.nativeElement,
|
|
115
|
+
root: this.root(),
|
|
116
|
+
state
|
|
117
|
+
});
|
|
118
|
+
this.#syncAccessState();
|
|
119
|
+
if (this.autoFocus() && shouldAutoFocusCodeEditor({
|
|
120
|
+
disabled: this.#effectiveDisabled(),
|
|
121
|
+
readonly: this.readonly()
|
|
122
|
+
})) this.#view.focus();
|
|
123
|
+
this._dispatch_effects(this.#themeConf.reconfigure(this.theme() === "dark" ? oneDark : []));
|
|
124
|
+
this._dispatch_effects(this.#placeholderConf.reconfigure(this.placeholder() ? placeholder(this.placeholder()) : []));
|
|
125
|
+
this._dispatch_effects(this.#indentWithTabConf.reconfigure(this.indentWithTab() ? keymap.of([indentWithTab]) : []));
|
|
126
|
+
this._dispatch_effects(this.#indentUnitConf.reconfigure(this.indentUnit() ? indentUnit.of(this.indentUnit()) : []));
|
|
127
|
+
this._dispatch_effects(this.#lineWrappingConf.reconfigure(this.lineWrapping() ? EditorView.lineWrapping : []));
|
|
128
|
+
this._dispatch_effects(this.#highlightWhitespaceConf.reconfigure(this.highlightWhitespace() ? highlightWhitespace() : []));
|
|
129
|
+
this.setLanguage(this.language());
|
|
130
|
+
}
|
|
131
|
+
ngOnChanges(changes) {
|
|
132
|
+
if (!this.#view) return;
|
|
133
|
+
if (changes["value"] && this.#view && !this.#formOwnsValue) {
|
|
134
|
+
const newValue = this.value();
|
|
135
|
+
const change = computeMinimalDocumentChange(this.#view.state.doc.toString(), newValue);
|
|
136
|
+
if (change) this.#view.dispatch({
|
|
137
|
+
changes: change,
|
|
138
|
+
annotations: [External.of(true), Transaction.addToHistory.of(false)],
|
|
139
|
+
scrollIntoView: false
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (changes["disabled"] || changes["readonly"]) this.#syncAccessState();
|
|
143
|
+
if (changes["describedBy"] || changes["label"] || changes["labelledBy"]) this.#syncContentAttributes();
|
|
144
|
+
if (changes["theme"]) this._dispatch_effects(this.#themeConf.reconfigure(this.theme() === "dark" ? oneDark : []));
|
|
145
|
+
if (changes["placeholder"]) this._dispatch_effects(this.#placeholderConf.reconfigure(this.placeholder() ? placeholder(this.placeholder()) : []));
|
|
146
|
+
if (changes["indentWithTab"]) this._dispatch_effects(this.#indentWithTabConf.reconfigure(this.indentWithTab() ? keymap.of([indentWithTab]) : []));
|
|
147
|
+
if (changes["indentUnit"]) this._dispatch_effects(this.#indentUnitConf.reconfigure(this.indentUnit() ? indentUnit.of(this.indentUnit()) : []));
|
|
148
|
+
if (changes["lineWrapping"]) this._dispatch_effects(this.#lineWrappingConf.reconfigure(this.lineWrapping() ? EditorView.lineWrapping : []));
|
|
149
|
+
if (changes["highlightWhitespace"]) this._dispatch_effects(this.#highlightWhitespaceConf.reconfigure(this.highlightWhitespace() ? highlightWhitespace() : []));
|
|
150
|
+
if (changes["language"] || changes["languages"]) this.#syncLanguage();
|
|
151
|
+
if (changes["setup"]) this._dispatch_effects(this.#setupConf.reconfigure(this.#setupExtension()));
|
|
152
|
+
}
|
|
153
|
+
ngOnDestroy() {
|
|
154
|
+
this.#languageRequest += 1;
|
|
155
|
+
const view = this.#view;
|
|
156
|
+
this.#view = void 0;
|
|
157
|
+
view?.destroy();
|
|
158
|
+
}
|
|
159
|
+
writeValue(value) {
|
|
160
|
+
const normalized = this.#normalizeFormValue(value);
|
|
161
|
+
this.#formOwnsValue = true;
|
|
162
|
+
if (!this.#view) {
|
|
163
|
+
this.#pendingValue = normalized;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const change = computeMinimalDocumentChange(this.#view.state.doc.toString(), normalized);
|
|
167
|
+
if (change) this.#view.dispatch({
|
|
168
|
+
changes: change,
|
|
169
|
+
annotations: [External.of(true), Transaction.addToHistory.of(false)],
|
|
170
|
+
scrollIntoView: false
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
registerOnChange(fn) {
|
|
174
|
+
this.#onChange = fn;
|
|
175
|
+
}
|
|
176
|
+
registerOnTouched(fn) {
|
|
177
|
+
this.#onTouched = fn;
|
|
178
|
+
}
|
|
179
|
+
setDisabledState(isDisabled) {
|
|
180
|
+
this.#formDisabled.set(isDisabled);
|
|
181
|
+
this.#syncAccessState();
|
|
182
|
+
}
|
|
183
|
+
setExtensions(value) {
|
|
184
|
+
this._dispatch_effects(this.#userExtensionsConf.reconfigure(value));
|
|
185
|
+
}
|
|
186
|
+
setLanguage(lang) {
|
|
187
|
+
const request = ++this.#languageRequest;
|
|
188
|
+
const view = this.#view;
|
|
189
|
+
if (!view) return;
|
|
190
|
+
const resolved = resolveCodeEditorLanguage(lang, this.languages());
|
|
191
|
+
this.#appliedLanguage = resolved;
|
|
192
|
+
if (resolved.kind === "none") {
|
|
193
|
+
view.dispatch({ effects: this.#languageConf.reconfigure([]) });
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (resolved.kind === "not-found") {
|
|
197
|
+
view.dispatch({ effects: this.#languageConf.reconfigure([]) });
|
|
198
|
+
console.error(`[CodeEditor] Language '${lang}' not found.`);
|
|
199
|
+
this.aoLanguageError.emit(codeEditorLanguageNotFound(lang));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
let loadPromise;
|
|
203
|
+
try {
|
|
204
|
+
loadPromise = Promise.resolve(resolved.description.load());
|
|
205
|
+
} catch (error) {
|
|
206
|
+
loadPromise = Promise.reject(error);
|
|
207
|
+
}
|
|
208
|
+
loadPromise.then((languageSupport) => {
|
|
209
|
+
if (request !== this.#languageRequest || this.#view !== view) return;
|
|
210
|
+
view.dispatch({ effects: this.#languageConf.reconfigure(languageSupport.extension) });
|
|
211
|
+
}, (error) => {
|
|
212
|
+
if (request !== this.#languageRequest || this.#view !== view) return;
|
|
213
|
+
view.dispatch({ effects: this.#languageConf.reconfigure([]) });
|
|
214
|
+
console.error(`[CodeEditor] Failed to load language '${lang}':`, error);
|
|
215
|
+
this.aoLanguageError.emit(codeEditorLanguageLoadFailed(lang, error));
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
_get_all_extensions() {
|
|
219
|
+
return [
|
|
220
|
+
this.#updateListener,
|
|
221
|
+
this.#domEventObservers,
|
|
222
|
+
this.#editableConf.of([]),
|
|
223
|
+
this.#readonlyConf.of([]),
|
|
224
|
+
this.#themeConf.of([]),
|
|
225
|
+
this.#placeholderConf.of([]),
|
|
226
|
+
this.#indentWithTabConf.of([]),
|
|
227
|
+
this.#indentUnitConf.of([]),
|
|
228
|
+
this.#lineWrappingConf.of([]),
|
|
229
|
+
this.#highlightWhitespaceConf.of([]),
|
|
230
|
+
this.#languageConf.of([]),
|
|
231
|
+
this.#a11yConf.of([]),
|
|
232
|
+
this.#setupConf.of(this.#setupExtension()),
|
|
233
|
+
this.#userExtensionsConf.of([])
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
_dispatch_effects(effects) {
|
|
237
|
+
return this.#view?.dispatch({ effects });
|
|
238
|
+
}
|
|
239
|
+
#syncLanguage() {
|
|
240
|
+
const language = this.language();
|
|
241
|
+
const resolved = resolveCodeEditorLanguage(language, this.languages());
|
|
242
|
+
if (isSameResolvedLanguage(this.#appliedLanguage, resolved)) return;
|
|
243
|
+
this.setLanguage(language);
|
|
244
|
+
}
|
|
245
|
+
#syncContentAttributes() {
|
|
246
|
+
this._dispatch_effects(this.#contentAttributesEffect(this.#effectiveDisabled()));
|
|
247
|
+
}
|
|
248
|
+
#contentAttributesEffect(disabled) {
|
|
249
|
+
const attributes = buildCodeEditorContentAttributes({
|
|
250
|
+
describedBy: this.describedBy(),
|
|
251
|
+
disabled,
|
|
252
|
+
label: this.label(),
|
|
253
|
+
labelledBy: this.labelledBy()
|
|
254
|
+
});
|
|
255
|
+
return this.#a11yConf.reconfigure(EditorView.contentAttributes.of(attributes));
|
|
256
|
+
}
|
|
257
|
+
#syncAccessState() {
|
|
258
|
+
const disabled = this.#effectiveDisabled();
|
|
259
|
+
const readonly = this.readonly();
|
|
260
|
+
this._dispatch_effects([
|
|
261
|
+
this.#readonlyConf.reconfigure(EditorState.readOnly.of(readonly || disabled)),
|
|
262
|
+
this.#editableConf.reconfigure(EditorView.editable.of(!readonly && !disabled)),
|
|
263
|
+
this.#contentAttributesEffect(disabled)
|
|
264
|
+
]);
|
|
265
|
+
}
|
|
266
|
+
#setupExtension() {
|
|
267
|
+
const setup = this.setup();
|
|
268
|
+
if (setup === "basic") return basicSetup;
|
|
269
|
+
if (setup === "minimal") return minimalSetup;
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
#normalizeFormValue(value) {
|
|
273
|
+
if (value === null || value === void 0) return "";
|
|
274
|
+
if (typeof value === "string") return value;
|
|
275
|
+
const actual = typeof value === "object" ? value.constructor?.name ?? "object" : typeof value;
|
|
276
|
+
throw new TypeError(`[@aiao/code-editor-angular] writeValue() 只接受 string | null | undefined,实际收到 ${actual}。请检查绑定的 FormControl 初始值或 ngModel 表达式。`);
|
|
277
|
+
}
|
|
278
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
279
|
+
minVersion: "12.0.0",
|
|
280
|
+
version: "22.2.3",
|
|
281
|
+
ngImport: i0,
|
|
282
|
+
type: CodeEditor,
|
|
283
|
+
deps: [],
|
|
284
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
285
|
+
});
|
|
286
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
287
|
+
minVersion: "17.1.0",
|
|
288
|
+
version: "22.2.3",
|
|
289
|
+
type: CodeEditor,
|
|
290
|
+
isStandalone: true,
|
|
291
|
+
selector: "ao-code-editor",
|
|
292
|
+
inputs: {
|
|
293
|
+
autoFocus: {
|
|
294
|
+
classPropertyName: "autoFocus",
|
|
295
|
+
publicName: "autoFocus",
|
|
296
|
+
isSignal: true,
|
|
297
|
+
isRequired: false,
|
|
298
|
+
transformFunction: null
|
|
299
|
+
},
|
|
300
|
+
describedBy: {
|
|
301
|
+
classPropertyName: "describedBy",
|
|
302
|
+
publicName: "describedBy",
|
|
303
|
+
isSignal: true,
|
|
304
|
+
isRequired: false,
|
|
305
|
+
transformFunction: null
|
|
306
|
+
},
|
|
307
|
+
disabled: {
|
|
308
|
+
classPropertyName: "disabled",
|
|
309
|
+
publicName: "disabled",
|
|
310
|
+
isSignal: true,
|
|
311
|
+
isRequired: false,
|
|
312
|
+
transformFunction: null
|
|
313
|
+
},
|
|
314
|
+
highlightWhitespace: {
|
|
315
|
+
classPropertyName: "highlightWhitespace",
|
|
316
|
+
publicName: "highlightWhitespace",
|
|
317
|
+
isSignal: true,
|
|
318
|
+
isRequired: false,
|
|
319
|
+
transformFunction: null
|
|
320
|
+
},
|
|
321
|
+
indentUnit: {
|
|
322
|
+
classPropertyName: "indentUnit",
|
|
323
|
+
publicName: "indentUnit",
|
|
324
|
+
isSignal: true,
|
|
325
|
+
isRequired: false,
|
|
326
|
+
transformFunction: null
|
|
327
|
+
},
|
|
328
|
+
indentWithTab: {
|
|
329
|
+
classPropertyName: "indentWithTab",
|
|
330
|
+
publicName: "indentWithTab",
|
|
331
|
+
isSignal: true,
|
|
332
|
+
isRequired: false,
|
|
333
|
+
transformFunction: null
|
|
334
|
+
},
|
|
335
|
+
language: {
|
|
336
|
+
classPropertyName: "language",
|
|
337
|
+
publicName: "language",
|
|
338
|
+
isSignal: true,
|
|
339
|
+
isRequired: false,
|
|
340
|
+
transformFunction: null
|
|
341
|
+
},
|
|
342
|
+
languages: {
|
|
343
|
+
classPropertyName: "languages",
|
|
344
|
+
publicName: "languages",
|
|
345
|
+
isSignal: true,
|
|
346
|
+
isRequired: false,
|
|
347
|
+
transformFunction: null
|
|
348
|
+
},
|
|
349
|
+
label: {
|
|
350
|
+
classPropertyName: "label",
|
|
351
|
+
publicName: "label",
|
|
352
|
+
isSignal: true,
|
|
353
|
+
isRequired: false,
|
|
354
|
+
transformFunction: null
|
|
355
|
+
},
|
|
356
|
+
labelledBy: {
|
|
357
|
+
classPropertyName: "labelledBy",
|
|
358
|
+
publicName: "labelledBy",
|
|
359
|
+
isSignal: true,
|
|
360
|
+
isRequired: false,
|
|
361
|
+
transformFunction: null
|
|
362
|
+
},
|
|
363
|
+
lineWrapping: {
|
|
364
|
+
classPropertyName: "lineWrapping",
|
|
365
|
+
publicName: "lineWrapping",
|
|
366
|
+
isSignal: true,
|
|
367
|
+
isRequired: false,
|
|
368
|
+
transformFunction: null
|
|
369
|
+
},
|
|
370
|
+
placeholder: {
|
|
371
|
+
classPropertyName: "placeholder",
|
|
372
|
+
publicName: "placeholder",
|
|
373
|
+
isSignal: true,
|
|
374
|
+
isRequired: false,
|
|
375
|
+
transformFunction: null
|
|
376
|
+
},
|
|
377
|
+
readonly: {
|
|
378
|
+
classPropertyName: "readonly",
|
|
379
|
+
publicName: "readonly",
|
|
380
|
+
isSignal: true,
|
|
381
|
+
isRequired: false,
|
|
382
|
+
transformFunction: null
|
|
383
|
+
},
|
|
384
|
+
root: {
|
|
385
|
+
classPropertyName: "root",
|
|
386
|
+
publicName: "root",
|
|
387
|
+
isSignal: true,
|
|
388
|
+
isRequired: false,
|
|
389
|
+
transformFunction: null
|
|
390
|
+
},
|
|
391
|
+
setup: {
|
|
392
|
+
classPropertyName: "setup",
|
|
393
|
+
publicName: "setup",
|
|
394
|
+
isSignal: true,
|
|
395
|
+
isRequired: false,
|
|
396
|
+
transformFunction: null
|
|
397
|
+
},
|
|
398
|
+
theme: {
|
|
399
|
+
classPropertyName: "theme",
|
|
400
|
+
publicName: "theme",
|
|
401
|
+
isSignal: true,
|
|
402
|
+
isRequired: false,
|
|
403
|
+
transformFunction: null
|
|
404
|
+
},
|
|
405
|
+
value: {
|
|
406
|
+
classPropertyName: "value",
|
|
407
|
+
publicName: "value",
|
|
408
|
+
isSignal: true,
|
|
409
|
+
isRequired: false,
|
|
410
|
+
transformFunction: null
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
outputs: {
|
|
414
|
+
aoFocus: "aoFocus",
|
|
415
|
+
aoChange: "aoChange",
|
|
416
|
+
aoBlur: "aoBlur",
|
|
417
|
+
aoLanguageError: "aoLanguageError"
|
|
418
|
+
},
|
|
419
|
+
host: { properties: { "attr.aria-disabled": "_ariaDisabled()" } },
|
|
420
|
+
providers: [{
|
|
421
|
+
provide: NG_VALUE_ACCESSOR,
|
|
422
|
+
useExisting: forwardRef(() => CodeEditor),
|
|
423
|
+
multi: true
|
|
424
|
+
}],
|
|
425
|
+
usesOnChanges: true,
|
|
426
|
+
ngImport: i0,
|
|
427
|
+
template: ``,
|
|
428
|
+
isInline: true,
|
|
429
|
+
styles: [":host{display:block;height:100%}:host ::ng-deep .cm-editor{height:100%}:host ::ng-deep .cm-editor.cm-focused{outline:2px solid Highlight;outline-offset:-2px}\n"],
|
|
430
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
434
|
+
minVersion: "12.0.0",
|
|
435
|
+
version: "22.2.3",
|
|
436
|
+
ngImport: i0,
|
|
437
|
+
type: CodeEditor,
|
|
438
|
+
decorators: [{
|
|
439
|
+
type: Component,
|
|
440
|
+
args: [{
|
|
441
|
+
selector: "ao-code-editor",
|
|
442
|
+
template: ``,
|
|
443
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
444
|
+
host: { "[attr.aria-disabled]": "_ariaDisabled()" },
|
|
445
|
+
providers: [{
|
|
446
|
+
provide: NG_VALUE_ACCESSOR,
|
|
447
|
+
useExisting: forwardRef(() => CodeEditor),
|
|
448
|
+
multi: true
|
|
449
|
+
}],
|
|
450
|
+
styles: [":host{display:block;height:100%}:host ::ng-deep .cm-editor{height:100%}:host ::ng-deep .cm-editor.cm-focused{outline:2px solid Highlight;outline-offset:-2px}\n"]
|
|
451
|
+
}]
|
|
452
|
+
}],
|
|
453
|
+
propDecorators: {
|
|
454
|
+
autoFocus: [{
|
|
455
|
+
type: i0.Input,
|
|
456
|
+
args: [{
|
|
457
|
+
isSignal: true,
|
|
458
|
+
alias: "autoFocus",
|
|
459
|
+
required: false
|
|
460
|
+
}]
|
|
461
|
+
}],
|
|
462
|
+
describedBy: [{
|
|
463
|
+
type: i0.Input,
|
|
464
|
+
args: [{
|
|
465
|
+
isSignal: true,
|
|
466
|
+
alias: "describedBy",
|
|
467
|
+
required: false
|
|
468
|
+
}]
|
|
469
|
+
}],
|
|
470
|
+
disabled: [{
|
|
471
|
+
type: i0.Input,
|
|
472
|
+
args: [{
|
|
473
|
+
isSignal: true,
|
|
474
|
+
alias: "disabled",
|
|
475
|
+
required: false
|
|
476
|
+
}]
|
|
477
|
+
}],
|
|
478
|
+
highlightWhitespace: [{
|
|
479
|
+
type: i0.Input,
|
|
480
|
+
args: [{
|
|
481
|
+
isSignal: true,
|
|
482
|
+
alias: "highlightWhitespace",
|
|
483
|
+
required: false
|
|
484
|
+
}]
|
|
485
|
+
}],
|
|
486
|
+
indentUnit: [{
|
|
487
|
+
type: i0.Input,
|
|
488
|
+
args: [{
|
|
489
|
+
isSignal: true,
|
|
490
|
+
alias: "indentUnit",
|
|
491
|
+
required: false
|
|
492
|
+
}]
|
|
493
|
+
}],
|
|
494
|
+
indentWithTab: [{
|
|
495
|
+
type: i0.Input,
|
|
496
|
+
args: [{
|
|
497
|
+
isSignal: true,
|
|
498
|
+
alias: "indentWithTab",
|
|
499
|
+
required: false
|
|
500
|
+
}]
|
|
501
|
+
}],
|
|
502
|
+
language: [{
|
|
503
|
+
type: i0.Input,
|
|
504
|
+
args: [{
|
|
505
|
+
isSignal: true,
|
|
506
|
+
alias: "language",
|
|
507
|
+
required: false
|
|
508
|
+
}]
|
|
509
|
+
}],
|
|
510
|
+
languages: [{
|
|
511
|
+
type: i0.Input,
|
|
512
|
+
args: [{
|
|
513
|
+
isSignal: true,
|
|
514
|
+
alias: "languages",
|
|
515
|
+
required: false
|
|
516
|
+
}]
|
|
517
|
+
}],
|
|
518
|
+
label: [{
|
|
519
|
+
type: i0.Input,
|
|
520
|
+
args: [{
|
|
521
|
+
isSignal: true,
|
|
522
|
+
alias: "label",
|
|
523
|
+
required: false
|
|
524
|
+
}]
|
|
525
|
+
}],
|
|
526
|
+
labelledBy: [{
|
|
527
|
+
type: i0.Input,
|
|
528
|
+
args: [{
|
|
529
|
+
isSignal: true,
|
|
530
|
+
alias: "labelledBy",
|
|
531
|
+
required: false
|
|
532
|
+
}]
|
|
533
|
+
}],
|
|
534
|
+
lineWrapping: [{
|
|
535
|
+
type: i0.Input,
|
|
536
|
+
args: [{
|
|
537
|
+
isSignal: true,
|
|
538
|
+
alias: "lineWrapping",
|
|
539
|
+
required: false
|
|
540
|
+
}]
|
|
541
|
+
}],
|
|
542
|
+
placeholder: [{
|
|
543
|
+
type: i0.Input,
|
|
544
|
+
args: [{
|
|
545
|
+
isSignal: true,
|
|
546
|
+
alias: "placeholder",
|
|
547
|
+
required: false
|
|
548
|
+
}]
|
|
549
|
+
}],
|
|
550
|
+
readonly: [{
|
|
551
|
+
type: i0.Input,
|
|
552
|
+
args: [{
|
|
553
|
+
isSignal: true,
|
|
554
|
+
alias: "readonly",
|
|
555
|
+
required: false
|
|
556
|
+
}]
|
|
557
|
+
}],
|
|
558
|
+
root: [{
|
|
559
|
+
type: i0.Input,
|
|
560
|
+
args: [{
|
|
561
|
+
isSignal: true,
|
|
562
|
+
alias: "root",
|
|
563
|
+
required: false
|
|
564
|
+
}]
|
|
565
|
+
}],
|
|
566
|
+
setup: [{
|
|
567
|
+
type: i0.Input,
|
|
568
|
+
args: [{
|
|
569
|
+
isSignal: true,
|
|
570
|
+
alias: "setup",
|
|
571
|
+
required: false
|
|
572
|
+
}]
|
|
573
|
+
}],
|
|
574
|
+
theme: [{
|
|
575
|
+
type: i0.Input,
|
|
576
|
+
args: [{
|
|
577
|
+
isSignal: true,
|
|
578
|
+
alias: "theme",
|
|
579
|
+
required: false
|
|
580
|
+
}]
|
|
581
|
+
}],
|
|
582
|
+
value: [{
|
|
583
|
+
type: i0.Input,
|
|
584
|
+
args: [{
|
|
585
|
+
isSignal: true,
|
|
586
|
+
alias: "value",
|
|
587
|
+
required: false
|
|
588
|
+
}]
|
|
589
|
+
}],
|
|
590
|
+
aoFocus: [{
|
|
591
|
+
type: i0.Output,
|
|
592
|
+
args: ["aoFocus"]
|
|
593
|
+
}],
|
|
594
|
+
aoChange: [{
|
|
595
|
+
type: i0.Output,
|
|
596
|
+
args: ["aoChange"]
|
|
597
|
+
}],
|
|
598
|
+
aoBlur: [{
|
|
599
|
+
type: i0.Output,
|
|
600
|
+
args: ["aoBlur"]
|
|
601
|
+
}],
|
|
602
|
+
aoLanguageError: [{
|
|
603
|
+
type: i0.Output,
|
|
604
|
+
args: ["aoLanguageError"]
|
|
605
|
+
}]
|
|
606
|
+
}
|
|
607
|
+
});
|
|
554
608
|
export { CodeEditor };
|
|
555
|
-
|
|
609
|
+
|
|
610
|
+
//# sourceMappingURL=aiao-code-editor-angular.mjs.map
|