@nonoun/native-codemirror 0.2.4 → 0.2.5

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.
@@ -0,0 +1,563 @@
1
+ import { EditorView as e, drawSelection as t, highlightActiveLine as n, highlightActiveLineGutter as r, highlightSpecialChars as i, keymap as a, lineNumbers as o, placeholder as s } from "@codemirror/view";
2
+ import { HighlightStyle as c, bracketMatching as l, foldGutter as u, foldKeymap as d, indentOnInput as f, syntaxHighlighting as p } from "@codemirror/language";
3
+ import { tags as m } from "@lezer/highlight";
4
+ import { defaultKeymap as h, history as g, historyKeymap as _ } from "@codemirror/commands";
5
+ import { autocompletion as v, closeBrackets as y, closeBracketsKeymap as b, completionKeymap as x } from "@codemirror/autocomplete";
6
+ import { Compartment as S, EditorState as C } from "@codemirror/state";
7
+ import { NativeElement as w, createDisabledEffect as T, signal as E } from "@nonoun/native-ui";
8
+ /**
9
+ * NativeUI CodeMirror Theme
10
+ *
11
+ * Dark theme inspired by one-dark, designed to harmonize with the
12
+ * @nonoun/native-ui OKLCH design system. Uses EditorView.theme()
13
+ * with { dark: true } and HighlightStyle.define() for syntax tokens.
14
+ *
15
+ * All colors flow through --n-code-* CSS custom properties (defined in
16
+ * codemirror.css). When native-ui foundation CSS is loaded, tokens like
17
+ * --n-body and --n-ink provide automatic theme integration. Without it,
18
+ * the one-dark hex fallbacks apply. Consumers can override any
19
+ * --n-code-* var directly on .cm-editor.
20
+ */
21
+ var D = "var(--n-code-bg, #282c34)", O = "var(--n-code-bg-raised, #21252b)", k = "var(--n-code-text, #abb2bf)", A = "var(--n-code-text-muted, #7d8799)", j = "var(--n-code-cursor, #528bff)", M = "var(--n-code-selection, #3E4451)", N = "var(--n-code-line-active, #2c313a)", P = "var(--n-code-bracket, #515a6b)", F = "var(--n-code-border, #3E4451)", I = "var(--n-code-button, #3E4451)", L = "var(--n-code-keyword, #c678dd)", R = "var(--n-code-string, #98c379)", z = "var(--n-code-function, #61afef)", B = "var(--n-code-variable, #e06c75)", V = "var(--n-code-type, #e5c07b)", H = "var(--n-code-operator, #56b6c2)", U = "var(--n-code-number, #d19a66)";
22
+ const W = e.theme({
23
+ "&": {
24
+ color: k,
25
+ backgroundColor: D,
26
+ fontSize: "14px",
27
+ fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, SFMono-Regular, Menlo, monospace"
28
+ },
29
+ ".cm-content": {
30
+ caretColor: j,
31
+ padding: "4px 0"
32
+ },
33
+ "&.cm-focused .cm-cursor": {
34
+ borderLeftColor: j,
35
+ borderLeftWidth: "2px"
36
+ },
37
+ "&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { backgroundColor: M },
38
+ ".cm-activeLine": { backgroundColor: N },
39
+ ".cm-gutters": {
40
+ backgroundColor: O,
41
+ color: A,
42
+ borderRight: "none",
43
+ paddingRight: "4px"
44
+ },
45
+ ".cm-activeLineGutter": {
46
+ backgroundColor: N,
47
+ color: k
48
+ },
49
+ ".cm-lineNumbers .cm-gutterElement": {
50
+ padding: "0 8px 0 16px",
51
+ minWidth: "40px"
52
+ },
53
+ ".cm-foldGutter .cm-gutterElement": {
54
+ padding: "0 4px",
55
+ cursor: "pointer"
56
+ },
57
+ "&.cm-focused .cm-matchingBracket": {
58
+ backgroundColor: P,
59
+ outline: `1px solid ${P}`
60
+ },
61
+ "&.cm-focused .cm-nonmatchingBracket": { color: B },
62
+ ".cm-searchMatch": {
63
+ backgroundColor: "var(--n-code-search, rgba(229, 192, 123, 0.25))",
64
+ outline: "1px solid var(--n-code-search-outline, rgba(229, 192, 123, 0.4))"
65
+ },
66
+ ".cm-searchMatch.cm-searchMatch-selected": { backgroundColor: "var(--n-code-search-active, rgba(97, 175, 239, 0.3))" },
67
+ ".cm-tooltip": {
68
+ backgroundColor: O,
69
+ color: k,
70
+ border: `1px solid ${F}`,
71
+ borderRadius: "6px",
72
+ boxShadow: "var(--n-code-shadow, 0 4px 16px rgba(0, 0, 0, 0.3))"
73
+ },
74
+ ".cm-tooltip .cm-tooltip-arrow::before": {
75
+ borderTopColor: F,
76
+ borderBottomColor: F
77
+ },
78
+ ".cm-tooltip .cm-tooltip-arrow::after": {
79
+ borderTopColor: O,
80
+ borderBottomColor: O
81
+ },
82
+ ".cm-tooltip-autocomplete": {
83
+ "& > ul": {
84
+ fontFamily: "inherit",
85
+ maxHeight: "240px"
86
+ },
87
+ "& > ul > li": { padding: "4px 8px" },
88
+ "& > ul > li[aria-selected]": {
89
+ backgroundColor: M,
90
+ color: k
91
+ }
92
+ },
93
+ ".cm-panels": {
94
+ backgroundColor: O,
95
+ color: k
96
+ },
97
+ ".cm-panels.cm-panels-top": { borderBottom: `1px solid ${F}` },
98
+ ".cm-panels.cm-panels-bottom": { borderTop: `1px solid ${F}` },
99
+ ".cm-panel input, .cm-panel button, .cm-panel select": { fontSize: "inherit" },
100
+ ".cm-panel input": {
101
+ backgroundColor: D,
102
+ color: k,
103
+ border: `1px solid ${F}`,
104
+ borderRadius: "4px",
105
+ padding: "2px 6px"
106
+ },
107
+ ".cm-panel button": {
108
+ backgroundColor: I,
109
+ color: k,
110
+ border: "none",
111
+ borderRadius: "4px",
112
+ padding: "2px 8px",
113
+ cursor: "pointer"
114
+ },
115
+ ".cm-fat-cursor .cm-cursor": {
116
+ display: "block",
117
+ backgroundColor: `${j}77`,
118
+ borderLeft: "none",
119
+ width: "0.5em"
120
+ },
121
+ ".cm-selectionLayer .cm-selectionBackground": { backgroundColor: `${M}80` },
122
+ ".cm-foldPlaceholder": {
123
+ backgroundColor: "transparent",
124
+ border: "none",
125
+ color: A
126
+ }
127
+ }, { dark: !0 }), G = c.define([
128
+ {
129
+ tag: m.comment,
130
+ color: A,
131
+ fontStyle: "italic"
132
+ },
133
+ {
134
+ tag: m.lineComment,
135
+ color: A,
136
+ fontStyle: "italic"
137
+ },
138
+ {
139
+ tag: m.blockComment,
140
+ color: A,
141
+ fontStyle: "italic"
142
+ },
143
+ {
144
+ tag: m.docComment,
145
+ color: A,
146
+ fontStyle: "italic"
147
+ },
148
+ {
149
+ tag: m.keyword,
150
+ color: L
151
+ },
152
+ {
153
+ tag: m.controlKeyword,
154
+ color: L
155
+ },
156
+ {
157
+ tag: m.operatorKeyword,
158
+ color: L
159
+ },
160
+ {
161
+ tag: m.definitionKeyword,
162
+ color: L
163
+ },
164
+ {
165
+ tag: m.moduleKeyword,
166
+ color: L
167
+ },
168
+ {
169
+ tag: m.string,
170
+ color: R
171
+ },
172
+ {
173
+ tag: m.special(m.string),
174
+ color: R
175
+ },
176
+ {
177
+ tag: m.regexp,
178
+ color: R
179
+ },
180
+ {
181
+ tag: m.escape,
182
+ color: H
183
+ },
184
+ {
185
+ tag: m.character,
186
+ color: R
187
+ },
188
+ {
189
+ tag: m.function(m.definition(m.variableName)),
190
+ color: z
191
+ },
192
+ {
193
+ tag: m.function(m.variableName),
194
+ color: z
195
+ },
196
+ {
197
+ tag: m.variableName,
198
+ color: B
199
+ },
200
+ {
201
+ tag: m.definition(m.variableName),
202
+ color: B
203
+ },
204
+ {
205
+ tag: m.propertyName,
206
+ color: B
207
+ },
208
+ {
209
+ tag: m.definition(m.propertyName),
210
+ color: B
211
+ },
212
+ {
213
+ tag: m.typeName,
214
+ color: V
215
+ },
216
+ {
217
+ tag: m.className,
218
+ color: V
219
+ },
220
+ {
221
+ tag: m.namespace,
222
+ color: V
223
+ },
224
+ {
225
+ tag: m.macroName,
226
+ color: V
227
+ },
228
+ {
229
+ tag: m.annotation,
230
+ color: V
231
+ },
232
+ {
233
+ tag: m.number,
234
+ color: U
235
+ },
236
+ {
237
+ tag: m.integer,
238
+ color: U
239
+ },
240
+ {
241
+ tag: m.float,
242
+ color: U
243
+ },
244
+ {
245
+ tag: m.bool,
246
+ color: U
247
+ },
248
+ {
249
+ tag: m.null,
250
+ color: U
251
+ },
252
+ {
253
+ tag: m.atom,
254
+ color: U
255
+ },
256
+ {
257
+ tag: m.operator,
258
+ color: H
259
+ },
260
+ {
261
+ tag: m.punctuation,
262
+ color: k
263
+ },
264
+ {
265
+ tag: m.paren,
266
+ color: k
267
+ },
268
+ {
269
+ tag: m.squareBracket,
270
+ color: k
271
+ },
272
+ {
273
+ tag: m.brace,
274
+ color: k
275
+ },
276
+ {
277
+ tag: m.derefOperator,
278
+ color: k
279
+ },
280
+ {
281
+ tag: m.separator,
282
+ color: k
283
+ },
284
+ {
285
+ tag: m.url,
286
+ color: H,
287
+ textDecoration: "underline"
288
+ },
289
+ {
290
+ tag: m.link,
291
+ color: H
292
+ },
293
+ {
294
+ tag: m.labelName,
295
+ color: B
296
+ },
297
+ {
298
+ tag: m.tagName,
299
+ color: B
300
+ },
301
+ {
302
+ tag: m.attributeName,
303
+ color: U
304
+ },
305
+ {
306
+ tag: m.attributeValue,
307
+ color: R
308
+ },
309
+ {
310
+ tag: m.angleBracket,
311
+ color: k
312
+ },
313
+ {
314
+ tag: m.self,
315
+ color: B
316
+ },
317
+ {
318
+ tag: m.processingInstruction,
319
+ color: A
320
+ },
321
+ {
322
+ tag: m.meta,
323
+ color: A
324
+ },
325
+ {
326
+ tag: m.heading,
327
+ color: B,
328
+ fontWeight: "bold"
329
+ },
330
+ {
331
+ tag: m.heading1,
332
+ color: B,
333
+ fontWeight: "bold"
334
+ },
335
+ {
336
+ tag: m.heading2,
337
+ color: B,
338
+ fontWeight: "bold"
339
+ },
340
+ {
341
+ tag: m.heading3,
342
+ color: B,
343
+ fontWeight: "bold"
344
+ },
345
+ {
346
+ tag: m.emphasis,
347
+ fontStyle: "italic"
348
+ },
349
+ {
350
+ tag: m.strong,
351
+ fontWeight: "bold"
352
+ },
353
+ {
354
+ tag: m.strikethrough,
355
+ textDecoration: "line-through"
356
+ },
357
+ {
358
+ tag: m.invalid,
359
+ color: "var(--n-code-invalid, #ffffff)",
360
+ backgroundColor: B
361
+ }
362
+ ]), K = p(G);
363
+ var q = class extends w {
364
+ static observedAttributes = [
365
+ "value",
366
+ "placeholder",
367
+ "readonly",
368
+ "disabled",
369
+ "line-numbers",
370
+ "line-wrapping",
371
+ "tab-size"
372
+ ];
373
+ #e;
374
+ #t = null;
375
+ #n = E(!1);
376
+ #r = E(!1);
377
+ #i = E("");
378
+ #a = E(2);
379
+ #o = E(!0);
380
+ #s = E(!1);
381
+ #c = E([]);
382
+ #l = new S();
383
+ #u = new S();
384
+ #d = new S();
385
+ #f = new S();
386
+ #p = new S();
387
+ #m = new S();
388
+ #h = "";
389
+ constructor() {
390
+ super(), this.#e = this.attachInternals();
391
+ }
392
+ get value() {
393
+ return this.#t ? this.#t.state.doc.toString() : this.getAttribute("value") ?? "";
394
+ }
395
+ set value(e) {
396
+ this.#t && this.#t.state.doc.toString() !== e && this.#t.dispatch({ changes: {
397
+ from: 0,
398
+ to: this.#t.state.doc.length,
399
+ insert: e
400
+ } });
401
+ }
402
+ get editorView() {
403
+ return this.#t;
404
+ }
405
+ /** Additional CodeMirror extensions (language modes, etc.). */
406
+ get extensions() {
407
+ return this.#c.value;
408
+ }
409
+ set extensions(e) {
410
+ this.#c.value = e;
411
+ }
412
+ get readOnly() {
413
+ return this.#r.value;
414
+ }
415
+ set readOnly(e) {
416
+ this.#r.value = e, this.toggleAttribute("readonly", e);
417
+ }
418
+ get disabled() {
419
+ return this.#n.value;
420
+ }
421
+ set disabled(e) {
422
+ this.#n.value = e, this.toggleAttribute("disabled", e);
423
+ }
424
+ get placeholder() {
425
+ return this.#i.value;
426
+ }
427
+ set placeholder(e) {
428
+ this.#i.value = e, this.setAttribute("placeholder", e);
429
+ }
430
+ focus() {
431
+ this.#t?.focus();
432
+ }
433
+ attributeChangedCallback(e, t, n) {
434
+ if (t !== n) {
435
+ switch (e) {
436
+ case "value":
437
+ this.#t && this.#t.state.doc.toString() !== (n ?? "") && this.#t.dispatch({ changes: {
438
+ from: 0,
439
+ to: this.#t.state.doc.length,
440
+ insert: n ?? ""
441
+ } });
442
+ break;
443
+ case "placeholder":
444
+ this.#i.value = n ?? "";
445
+ break;
446
+ case "readonly":
447
+ this.#r.value = n !== null;
448
+ break;
449
+ case "disabled":
450
+ this.#n.value = n !== null;
451
+ break;
452
+ case "line-numbers":
453
+ this.#o.value = n !== "false";
454
+ break;
455
+ case "line-wrapping":
456
+ this.#s.value = n !== null;
457
+ break;
458
+ case "tab-size":
459
+ this.#a.value = n === null ? 2 : parseInt(n, 10) || 2;
460
+ break;
461
+ }
462
+ super.attributeChangedCallback(e, t, n);
463
+ }
464
+ }
465
+ setup() {
466
+ super.setup(), this.#n.value = this.hasAttribute("disabled"), this.#r.value = this.hasAttribute("readonly"), this.#i.value = this.getAttribute("placeholder") ?? "", this.#o.value = this.getAttribute("line-numbers") !== "false", this.#s.value = this.hasAttribute("line-wrapping");
467
+ let t = this.getAttribute("tab-size");
468
+ t && (this.#a.value = parseInt(t, 10) || 2);
469
+ let n = this.#g();
470
+ this.#h = n, this.#_(n), this.hasAttribute("tabindex") || this.setAttribute("tabindex", "0"), this.addEffect(T(this, this.#n, this.#e, { manageTabindex: !0 })), this.addEffect(() => {
471
+ let t = this.#r.value || this.#n.value;
472
+ this.#t && this.#t.dispatch({ effects: this.#l.reconfigure([C.readOnly.of(t), e.editable.of(!t)]) });
473
+ }), this.addEffect(() => {
474
+ let e = this.#i.value;
475
+ this.#t && this.#t.dispatch({ effects: this.#u.reconfigure(e ? s(e) : []) });
476
+ }), this.addEffect(() => {
477
+ let e = this.#c.value;
478
+ this.#t && this.#t.dispatch({ effects: this.#d.reconfigure(e) });
479
+ }), this.addEffect(() => {
480
+ let e = this.#o.value;
481
+ this.#t && this.#t.dispatch({ effects: this.#f.reconfigure(e ? [
482
+ o(),
483
+ u(),
484
+ r()
485
+ ] : []) });
486
+ }), this.addEffect(() => {
487
+ let t = this.#s.value;
488
+ this.#t && this.#t.dispatch({ effects: this.#p.reconfigure(t ? e.lineWrapping : []) });
489
+ }), this.addEffect(() => {
490
+ let e = this.#a.value;
491
+ this.#t && this.#t.dispatch({ effects: this.#m.reconfigure(C.tabSize.of(e)) });
492
+ });
493
+ }
494
+ teardown() {
495
+ this.#t?.destroy(), this.#t = null, super.teardown();
496
+ }
497
+ #g() {
498
+ let e = this.querySelector("script[type=\"text/plain\"]");
499
+ if (e) {
500
+ let t = e.textContent ?? "";
501
+ return e.remove(), t.replace(/^\n/, "");
502
+ }
503
+ return this.getAttribute("value") ?? "";
504
+ }
505
+ #_(c) {
506
+ let p = this.#r.value || this.#n.value, m = this.#i.value, S = this.#o.value, w = this.#s.value, T = this.#a.value, E = [
507
+ W,
508
+ K,
509
+ i(),
510
+ t(),
511
+ f(),
512
+ g(),
513
+ l(),
514
+ y(),
515
+ v(),
516
+ n(),
517
+ a.of([
518
+ ...b,
519
+ ...h,
520
+ ..._,
521
+ ...d,
522
+ ...x
523
+ ]),
524
+ this.#l.of([C.readOnly.of(p), e.editable.of(!p)]),
525
+ this.#u.of(m ? s(m) : []),
526
+ this.#d.of(this.#c.value),
527
+ this.#f.of(S ? [
528
+ o(),
529
+ u(),
530
+ r()
531
+ ] : []),
532
+ this.#p.of(w ? e.lineWrapping : []),
533
+ this.#m.of(C.tabSize.of(T)),
534
+ e.updateListener.of((e) => {
535
+ if (e.docChanged) {
536
+ let t = e.state.doc.toString();
537
+ this.dispatchEvent(new CustomEvent("native:input", {
538
+ bubbles: !0,
539
+ composed: !0,
540
+ detail: { value: t }
541
+ }));
542
+ }
543
+ if (e.focusChanged && !e.view.hasFocus) {
544
+ let t = e.state.doc.toString();
545
+ t !== this.#h && (this.#h = t, this.dispatchEvent(new CustomEvent("native:change", {
546
+ bubbles: !0,
547
+ composed: !0,
548
+ detail: { value: t }
549
+ })));
550
+ }
551
+ })
552
+ ];
553
+ this.#t = new e({
554
+ state: C.create({
555
+ doc: c,
556
+ extensions: E
557
+ }),
558
+ parent: this,
559
+ root: this.ownerDocument
560
+ });
561
+ }
562
+ };
563
+ export { W as i, G as n, K as r, q as t };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * <native-codemirror> Custom Element
3
+ *
4
+ * Declarative wrapper around CodeMirror 6 for the NativeUI ecosystem.
5
+ * Provides reactive attribute-driven config, event dispatch, and
6
+ * lifecycle management around a themed EditorView.
7
+ *
8
+ * @attr {string} value - Document content
9
+ * @attr {string} placeholder - Placeholder text for empty editor
10
+ * @attr {boolean} readonly - Disable editing (still selectable)
11
+ * @attr {boolean} disabled - Full disabled state
12
+ * @attr {boolean} line-numbers - Show line numbers (default: true)
13
+ * @attr {boolean} line-wrapping - Enable soft line wrapping
14
+ * @attr {number} tab-size - Tab size (default: 2)
15
+ * @fires native:input - On every document change, detail: { value }
16
+ * @fires native:change - On blur (final commit), detail: { value }
17
+ */
18
+ import type { Extension } from '@codemirror/state';
19
+ import { NativeElement } from '@nonoun/native-ui';
20
+ import { EditorView } from '@codemirror/view';
21
+ export declare class NCodemirror extends NativeElement {
22
+ #private;
23
+ static observedAttributes: string[];
24
+ constructor();
25
+ get value(): string;
26
+ set value(val: string);
27
+ get editorView(): EditorView | null;
28
+ /** Additional CodeMirror extensions (language modes, etc.). */
29
+ get extensions(): Extension[];
30
+ set extensions(val: Extension[]);
31
+ get readOnly(): boolean;
32
+ set readOnly(val: boolean);
33
+ get disabled(): boolean;
34
+ set disabled(val: boolean);
35
+ get placeholder(): string;
36
+ set placeholder(val: string);
37
+ focus(): void;
38
+ attributeChangedCallback(name: string, old: string | null, val: string | null): void;
39
+ setup(): void;
40
+ teardown(): void;
41
+ }
42
+ //# sourceMappingURL=codemirror-element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codemirror-element.d.ts","sourceRoot":"","sources":["../src/codemirror-element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAgC,MAAM,mBAAmB,CAAC;AAEhF,OAAO,EACL,UAAU,EAQX,MAAM,kBAAkB,CAAC;AAgB1B,qBAAa,WAAY,SAAQ,aAAa;;IAC5C,MAAM,CAAC,kBAAkB,WAGvB;;IAgCF,IAAI,KAAK,IAAI,MAAM,CAGlB;IAED,IAAI,KAAK,CAAC,GAAG,EAAE,MAAM,EASpB;IAED,IAAI,UAAU,IAAI,UAAU,GAAG,IAAI,CAElC;IAED,+DAA+D;IAC/D,IAAI,UAAU,IAAI,SAAS,EAAE,CAE5B;IAED,IAAI,UAAU,CAAC,GAAG,EAAE,SAAS,EAAE,EAE9B;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,QAAQ,CAAC,GAAG,EAAE,OAAO,EAGxB;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,QAAQ,CAAC,GAAG,EAAE,OAAO,EAGxB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,WAAW,CAAC,GAAG,EAAE,MAAM,EAG1B;IAEQ,KAAK,IAAI,IAAI;IAMtB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAqCpF,KAAK,IAAI,IAAI;IAmGb,QAAQ,IAAI,IAAI;CAiGjB"}
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { NTheme, NHighlightStyle, NSyntaxHighlighting } from './theme.ts';
11
11
  export { NBaseExtensions } from './base-extensions.ts';
12
12
  export { createEditorView } from './factory.ts';
13
13
  export type { CreateEditorOptions } from './factory.ts';
14
+ export { NCodemirror } from './codemirror-element.ts';
14
15
  export { EditorView, keymap, Decoration, ViewPlugin, WidgetType, lineNumbers, highlightActiveLine, highlightActiveLineGutter, drawSelection, } from '@codemirror/view';
15
16
  export type { DecorationSet, ViewUpdate } from '@codemirror/view';
16
17
  export { EditorState, Compartment, StateField, StateEffect } from '@codemirror/state';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAMxD,OAAO,EACL,UAAU,EACV,MAAM,EACN,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMlE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtF,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhE,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAMzF,OAAO,EACL,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAMtD,OAAO,EACL,UAAU,EACV,MAAM,EACN,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMlE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtF,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhE,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAMzF,OAAO,EACL,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC"}
@@ -15,6 +15,26 @@
15
15
  */
16
16
 
17
17
  @layer ui {
18
+ /* -----------------------------------------------------------------------
19
+ * Host element — <native-codemirror>
20
+ * --------------------------------------------------------------------- */
21
+
22
+ :where(native-codemirror) {
23
+ display: block;
24
+ position: relative;
25
+ overflow: hidden;
26
+ border-radius: var(--n-radius, 0.5rem);
27
+ }
28
+
29
+ :where(native-codemirror) :where(.cm-editor) {
30
+ height: 100%;
31
+ }
32
+
33
+ :where(native-codemirror)[aria-disabled="true"] {
34
+ opacity: 0.5;
35
+ pointer-events: none;
36
+ }
37
+
18
38
  /* -----------------------------------------------------------------------
19
39
  * Editor root — color bridge vars
20
40
  * --------------------------------------------------------------------- */
@@ -33,7 +53,7 @@
33
53
  /* Interactive */
34
54
  --n-code-cursor: var(--n-surface-accent, #528bff);
35
55
  --n-code-selection: var(--n-color-neutral-300, #3E4451);
36
- --n-code-line-active: var(--n-color-neutral-200, #2c313a);
56
+ --n-code-line-active: var(--n-color-neutral-200-scrim, #2c313a) !important;
37
57
  --n-code-bracket: var(--n-color-neutral-600, #515a6b);
38
58
  --n-code-accent: var(--n-surface-accent, #61afef);
39
59
 
@@ -1,381 +1,41 @@
1
- import { Decoration as e, EditorView as t, EditorView as n, ViewPlugin as r, WidgetType as i, drawSelection as a, drawSelection as o, highlightActiveLine as s, highlightActiveLine as c, highlightActiveLineGutter as ee, highlightActiveLineGutter as te, highlightSpecialChars as ne, keymap as re, keymap as ie, lineNumbers as ae, lineNumbers as oe } from "@codemirror/view";
2
- import { HighlightStyle as l, HighlightStyle as se, bracketMatching as u, bracketMatching as ce, foldGutter as d, foldGutter as f, foldKeymap as p, indentOnInput as le, indentOnInput as ue, syntaxHighlighting as de, syntaxHighlighting as fe, syntaxTree as pe } from "@codemirror/language";
3
- import { tags as me, tags as m } from "@lezer/highlight";
4
- import { defaultKeymap as he, defaultKeymap as h, history as g, history as _, historyKeymap as v, historyKeymap as y, redo as b, undo as x } from "@codemirror/commands";
5
- import { autocompletion as S, autocompletion as C, closeBrackets as w, closeBrackets as T, closeBracketsKeymap as E, closeBracketsKeymap as D, completionKeymap as O, completionKeymap as k } from "@codemirror/autocomplete";
6
- import { Compartment as A, EditorState as j, EditorState as M, StateEffect as N, StateField as ge } from "@codemirror/state";
1
+ import { i as e, n as t, r as n, t as r } from "./codemirror-element-DqgpO8qM.js";
2
+ import { Decoration as i, EditorView as a, EditorView as o, ViewPlugin as s, WidgetType as c, drawSelection as l, drawSelection as u, highlightActiveLine as d, highlightActiveLine as f, highlightActiveLineGutter as p, highlightActiveLineGutter as m, highlightSpecialChars as h, keymap as g, keymap as _, lineNumbers as v, lineNumbers as y } from "@codemirror/view";
3
+ import { HighlightStyle as b, bracketMatching as x, bracketMatching as S, foldGutter as C, foldGutter as w, foldKeymap as T, indentOnInput as E, indentOnInput as D, syntaxHighlighting as O, syntaxTree as k } from "@codemirror/language";
4
+ import { tags as A } from "@lezer/highlight";
5
+ import { defaultKeymap as j, defaultKeymap as M, history as N, history as P, historyKeymap as F, historyKeymap as I, redo as L, undo as R } from "@codemirror/commands";
6
+ import { autocompletion as z, autocompletion as B, closeBrackets as V, closeBrackets as H, closeBracketsKeymap as U, closeBracketsKeymap as W, completionKeymap as G, completionKeymap as K } from "@codemirror/autocomplete";
7
+ import { Compartment as q, EditorState as J, EditorState as Y, StateEffect as X, StateField as Z } from "@codemirror/state";
7
8
  /**
8
- * NativeUI CodeMirror Theme
9
+ * Base extension set shared by all NativeUI CodeMirror instances.
9
10
  *
10
- * Dark theme inspired by one-dark, designed to harmonize with the
11
- * @nonoun/native-ui OKLCH design system. Uses EditorView.theme()
12
- * with { dark: true } and HighlightStyle.define() for syntax tokens.
13
- *
14
- * All colors flow through --n-code-* CSS custom properties (defined in
15
- * codemirror.css). When native-ui foundation CSS is loaded, tokens like
16
- * --n-body and --n-ink provide automatic theme integration. Without it,
17
- * the one-dark hex fallbacks apply. Consumers can override any
18
- * --n-code-* var directly on .cm-editor.
11
+ * Includes:
12
+ * - Default, history, close-brackets, fold, and completion keymaps
13
+ * - Undo/redo history
14
+ * - Bracket matching and auto-close
15
+ * - Autocompletion
16
+ * - Line numbers with fold gutter
17
+ * - Active line + gutter highlighting
18
+ * - Selection drawing and special character highlighting
19
+ * - Indent on input
19
20
  */
20
- var P = "var(--n-code-bg, #282c34)", F = "var(--n-code-bg-raised, #21252b)", I = "var(--n-code-text, #abb2bf)", L = "var(--n-code-text-muted, #7d8799)", R = "var(--n-code-cursor, #528bff)", z = "var(--n-code-selection, #3E4451)", B = "var(--n-code-line-active, #2c313a)", V = "var(--n-code-bracket, #515a6b)", H = "var(--n-code-border, #3E4451)", _e = "var(--n-code-button, #3E4451)", U = "var(--n-code-keyword, #c678dd)", W = "var(--n-code-string, #98c379)", G = "var(--n-code-function, #61afef)", K = "var(--n-code-variable, #e06c75)", q = "var(--n-code-type, #e5c07b)", J = "var(--n-code-operator, #56b6c2)", Y = "var(--n-code-number, #d19a66)";
21
- const X = n.theme({
22
- "&": {
23
- color: I,
24
- backgroundColor: P,
25
- fontSize: "14px",
26
- fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, SFMono-Regular, Menlo, monospace"
27
- },
28
- ".cm-content": {
29
- caretColor: R,
30
- padding: "4px 0"
31
- },
32
- "&.cm-focused .cm-cursor": {
33
- borderLeftColor: R,
34
- borderLeftWidth: "2px"
35
- },
36
- "&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { backgroundColor: z },
37
- ".cm-activeLine": { backgroundColor: B },
38
- ".cm-gutters": {
39
- backgroundColor: F,
40
- color: L,
41
- borderRight: "none",
42
- paddingRight: "4px"
43
- },
44
- ".cm-activeLineGutter": {
45
- backgroundColor: B,
46
- color: I
47
- },
48
- ".cm-lineNumbers .cm-gutterElement": {
49
- padding: "0 8px 0 16px",
50
- minWidth: "40px"
51
- },
52
- ".cm-foldGutter .cm-gutterElement": {
53
- padding: "0 4px",
54
- cursor: "pointer"
55
- },
56
- "&.cm-focused .cm-matchingBracket": {
57
- backgroundColor: V,
58
- outline: `1px solid ${V}`
59
- },
60
- "&.cm-focused .cm-nonmatchingBracket": { color: K },
61
- ".cm-searchMatch": {
62
- backgroundColor: "var(--n-code-search, rgba(229, 192, 123, 0.25))",
63
- outline: "1px solid var(--n-code-search-outline, rgba(229, 192, 123, 0.4))"
64
- },
65
- ".cm-searchMatch.cm-searchMatch-selected": { backgroundColor: "var(--n-code-search-active, rgba(97, 175, 239, 0.3))" },
66
- ".cm-tooltip": {
67
- backgroundColor: F,
68
- color: I,
69
- border: `1px solid ${H}`,
70
- borderRadius: "6px",
71
- boxShadow: "var(--n-code-shadow, 0 4px 16px rgba(0, 0, 0, 0.3))"
72
- },
73
- ".cm-tooltip .cm-tooltip-arrow::before": {
74
- borderTopColor: H,
75
- borderBottomColor: H
76
- },
77
- ".cm-tooltip .cm-tooltip-arrow::after": {
78
- borderTopColor: F,
79
- borderBottomColor: F
80
- },
81
- ".cm-tooltip-autocomplete": {
82
- "& > ul": {
83
- fontFamily: "inherit",
84
- maxHeight: "240px"
85
- },
86
- "& > ul > li": { padding: "4px 8px" },
87
- "& > ul > li[aria-selected]": {
88
- backgroundColor: z,
89
- color: I
90
- }
91
- },
92
- ".cm-panels": {
93
- backgroundColor: F,
94
- color: I
95
- },
96
- ".cm-panels.cm-panels-top": { borderBottom: `1px solid ${H}` },
97
- ".cm-panels.cm-panels-bottom": { borderTop: `1px solid ${H}` },
98
- ".cm-panel input, .cm-panel button, .cm-panel select": { fontSize: "inherit" },
99
- ".cm-panel input": {
100
- backgroundColor: P,
101
- color: I,
102
- border: `1px solid ${H}`,
103
- borderRadius: "4px",
104
- padding: "2px 6px"
105
- },
106
- ".cm-panel button": {
107
- backgroundColor: _e,
108
- color: I,
109
- border: "none",
110
- borderRadius: "4px",
111
- padding: "2px 8px",
112
- cursor: "pointer"
113
- },
114
- ".cm-fat-cursor .cm-cursor": {
115
- display: "block",
116
- backgroundColor: `${R}77`,
117
- borderLeft: "none",
118
- width: "0.5em"
119
- },
120
- ".cm-selectionLayer .cm-selectionBackground": { backgroundColor: `${z}80` },
121
- ".cm-foldPlaceholder": {
122
- backgroundColor: "transparent",
123
- border: "none",
124
- color: L
125
- }
126
- }, { dark: !0 }), Z = se.define([
127
- {
128
- tag: m.comment,
129
- color: L,
130
- fontStyle: "italic"
131
- },
132
- {
133
- tag: m.lineComment,
134
- color: L,
135
- fontStyle: "italic"
136
- },
137
- {
138
- tag: m.blockComment,
139
- color: L,
140
- fontStyle: "italic"
141
- },
142
- {
143
- tag: m.docComment,
144
- color: L,
145
- fontStyle: "italic"
146
- },
147
- {
148
- tag: m.keyword,
149
- color: U
150
- },
151
- {
152
- tag: m.controlKeyword,
153
- color: U
154
- },
155
- {
156
- tag: m.operatorKeyword,
157
- color: U
158
- },
159
- {
160
- tag: m.definitionKeyword,
161
- color: U
162
- },
163
- {
164
- tag: m.moduleKeyword,
165
- color: U
166
- },
167
- {
168
- tag: m.string,
169
- color: W
170
- },
171
- {
172
- tag: m.special(m.string),
173
- color: W
174
- },
175
- {
176
- tag: m.regexp,
177
- color: W
178
- },
179
- {
180
- tag: m.escape,
181
- color: J
182
- },
183
- {
184
- tag: m.character,
185
- color: W
186
- },
187
- {
188
- tag: m.function(m.definition(m.variableName)),
189
- color: G
190
- },
191
- {
192
- tag: m.function(m.variableName),
193
- color: G
194
- },
195
- {
196
- tag: m.variableName,
197
- color: K
198
- },
199
- {
200
- tag: m.definition(m.variableName),
201
- color: K
202
- },
203
- {
204
- tag: m.propertyName,
205
- color: K
206
- },
207
- {
208
- tag: m.definition(m.propertyName),
209
- color: K
210
- },
211
- {
212
- tag: m.typeName,
213
- color: q
214
- },
215
- {
216
- tag: m.className,
217
- color: q
218
- },
219
- {
220
- tag: m.namespace,
221
- color: q
222
- },
223
- {
224
- tag: m.macroName,
225
- color: q
226
- },
227
- {
228
- tag: m.annotation,
229
- color: q
230
- },
231
- {
232
- tag: m.number,
233
- color: Y
234
- },
235
- {
236
- tag: m.integer,
237
- color: Y
238
- },
239
- {
240
- tag: m.float,
241
- color: Y
242
- },
243
- {
244
- tag: m.bool,
245
- color: Y
246
- },
247
- {
248
- tag: m.null,
249
- color: Y
250
- },
251
- {
252
- tag: m.atom,
253
- color: Y
254
- },
255
- {
256
- tag: m.operator,
257
- color: J
258
- },
259
- {
260
- tag: m.punctuation,
261
- color: I
262
- },
263
- {
264
- tag: m.paren,
265
- color: I
266
- },
267
- {
268
- tag: m.squareBracket,
269
- color: I
270
- },
271
- {
272
- tag: m.brace,
273
- color: I
274
- },
275
- {
276
- tag: m.derefOperator,
277
- color: I
278
- },
279
- {
280
- tag: m.separator,
281
- color: I
282
- },
283
- {
284
- tag: m.url,
285
- color: J,
286
- textDecoration: "underline"
287
- },
288
- {
289
- tag: m.link,
290
- color: J
291
- },
292
- {
293
- tag: m.labelName,
294
- color: K
295
- },
296
- {
297
- tag: m.tagName,
298
- color: K
299
- },
300
- {
301
- tag: m.attributeName,
302
- color: Y
303
- },
304
- {
305
- tag: m.attributeValue,
306
- color: W
307
- },
308
- {
309
- tag: m.angleBracket,
310
- color: I
311
- },
312
- {
313
- tag: m.self,
314
- color: K
315
- },
316
- {
317
- tag: m.processingInstruction,
318
- color: L
319
- },
320
- {
321
- tag: m.meta,
322
- color: L
323
- },
324
- {
325
- tag: m.heading,
326
- color: K,
327
- fontWeight: "bold"
328
- },
329
- {
330
- tag: m.heading1,
331
- color: K,
332
- fontWeight: "bold"
333
- },
334
- {
335
- tag: m.heading2,
336
- color: K,
337
- fontWeight: "bold"
338
- },
339
- {
340
- tag: m.heading3,
341
- color: K,
342
- fontWeight: "bold"
343
- },
344
- {
345
- tag: m.emphasis,
346
- fontStyle: "italic"
347
- },
348
- {
349
- tag: m.strong,
350
- fontWeight: "bold"
351
- },
352
- {
353
- tag: m.strikethrough,
354
- textDecoration: "line-through"
355
- },
356
- {
357
- tag: m.invalid,
358
- color: "var(--n-code-invalid, #ffffff)",
359
- backgroundColor: K
360
- }
361
- ]), Q = fe(Z), $ = [
362
- ne(),
363
- o(),
364
- ue(),
365
- _(),
366
- ce(),
367
- T(),
368
- C(),
369
- oe(),
21
+ const Q = [
22
+ h(),
23
+ u(),
24
+ D(),
25
+ P(),
26
+ S(),
27
+ H(),
28
+ B(),
29
+ y(),
30
+ w(),
370
31
  f(),
371
- c(),
372
- te(),
373
- ie.of([
374
- ...D,
375
- ...h,
376
- ...y,
377
- ...p,
378
- ...k
32
+ m(),
33
+ _.of([
34
+ ...W,
35
+ ...M,
36
+ ...I,
37
+ ...T,
38
+ ...K
379
39
  ])
380
40
  ];
381
41
  /**
@@ -405,20 +65,20 @@ const X = n.theme({
405
65
  * });
406
66
  * ```
407
67
  */
408
- function ve(e, t) {
409
- let { doc: r = "", extensions: i = [], readonly: a = !1 } = t ?? {}, o = [
410
- X,
68
+ function $(t, r) {
69
+ let { doc: i = "", extensions: a = [], readonly: s = !1 } = r ?? {}, c = [
70
+ e,
71
+ n,
411
72
  Q,
412
- $,
413
- ...i
73
+ ...a
414
74
  ];
415
- return a && o.push(M.readOnly.of(!0), n.editable.of(!1)), new n({
416
- state: M.create({
417
- doc: r,
418
- extensions: o
75
+ return s && c.push(Y.readOnly.of(!0), o.editable.of(!1)), new o({
76
+ state: Y.create({
77
+ doc: i,
78
+ extensions: c
419
79
  }),
420
- parent: e,
421
- root: e.ownerDocument
80
+ parent: t,
81
+ root: t.ownerDocument
422
82
  });
423
83
  }
424
- export { A as Compartment, e as Decoration, j as EditorState, t as EditorView, l as HighlightStyle, $ as NBaseExtensions, Z as NHighlightStyle, Q as NSyntaxHighlighting, X as NTheme, N as StateEffect, ge as StateField, r as ViewPlugin, i as WidgetType, S as autocompletion, u as bracketMatching, w as closeBrackets, E as closeBracketsKeymap, O as completionKeymap, ve as createEditorView, he as defaultKeymap, a as drawSelection, d as foldGutter, s as highlightActiveLine, ee as highlightActiveLineGutter, g as history, v as historyKeymap, le as indentOnInput, re as keymap, ae as lineNumbers, b as redo, de as syntaxHighlighting, pe as syntaxTree, me as tags, x as undo };
84
+ export { q as Compartment, i as Decoration, J as EditorState, a as EditorView, b as HighlightStyle, Q as NBaseExtensions, r as NCodemirror, t as NHighlightStyle, n as NSyntaxHighlighting, e as NTheme, X as StateEffect, Z as StateField, s as ViewPlugin, c as WidgetType, z as autocompletion, x as bracketMatching, V as closeBrackets, U as closeBracketsKeymap, G as completionKeymap, $ as createEditorView, j as defaultKeymap, l as drawSelection, C as foldGutter, d as highlightActiveLine, p as highlightActiveLineGutter, N as history, F as historyKeymap, E as indentOnInput, g as keymap, v as lineNumbers, L as redo, O as syntaxHighlighting, k as syntaxTree, A as tags, R as undo };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { t as e } from "./codemirror-element-DqgpO8qM.js";
2
+ import { define as t } from "@nonoun/native-ui";
3
+ t("native-codemirror", e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nonoun/native-codemirror",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Shared CodeMirror 6 integration layer for @nonoun/native-ui ecosystem",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,11 +12,18 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "default": "./dist/native-codemirror.js"
14
14
  },
15
+ "./register": {
16
+ "types": "./dist/register.d.ts",
17
+ "default": "./dist/register.js"
18
+ },
15
19
  "./css": "./dist/native-codemirror.css"
16
20
  },
17
21
  "files": [
18
22
  "dist"
19
23
  ],
24
+ "sideEffects": [
25
+ "./dist/register.js"
26
+ ],
20
27
  "peerDependencies": {
21
28
  "@nonoun/native-ui": ">=0.5.0"
22
29
  },