@nonoun/native-editor 0.2.0 → 0.2.2
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.
- package/dist/{nui-editor-element-S_Z8i0qQ.js → editor-element-lE0uhdJ9.js} +151 -134
- package/dist/{nui-editor-element.d.ts → editor-element.d.ts} +6 -6
- package/dist/editor-element.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/{nui-editor.css → native-editor.css} +98 -40
- package/dist/native-editor.js +2 -0
- package/dist/register.d.ts +2 -2
- package/dist/register.js +3 -11
- package/package.json +3 -3
- package/dist/nui-editor-element.d.ts.map +0 -1
- package/dist/nui-editor.js +0 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GatewayController as e,
|
|
2
|
-
import { Compartment as
|
|
3
|
-
import { markdown as
|
|
4
|
-
import { Decoration as
|
|
5
|
-
import { Compartment as
|
|
6
|
-
import { syntaxTree as
|
|
1
|
+
import { GatewayController as e, NativeElement as t, PresentController as n, ResizeController as r, batch as i, computed as a, createDisabledEffect as o, signal as s } from "@nonoun/native-ui";
|
|
2
|
+
import { Compartment as c, EditorState as l, EditorView as u, NBaseExtensions as d, NSyntaxHighlighting as ee, NTheme as f } from "@nonoun/native-codemirror";
|
|
3
|
+
import { markdown as p } from "@codemirror/lang-markdown";
|
|
4
|
+
import { Decoration as m, ViewPlugin as te, WidgetType as ne, keymap as re, placeholder as h } from "@codemirror/view";
|
|
5
|
+
import { Compartment as g, EditorSelection as _, RangeSetBuilder as v } from "@codemirror/state";
|
|
6
|
+
import { syntaxTree as ie } from "@codemirror/language";
|
|
7
7
|
function y(e, t) {
|
|
8
8
|
let { state: n } = e, r = [], i = [];
|
|
9
9
|
for (let e of n.selection.ranges) {
|
|
@@ -51,7 +51,7 @@ function y(e, t) {
|
|
|
51
51
|
}
|
|
52
52
|
return e.dispatch({
|
|
53
53
|
changes: r,
|
|
54
|
-
selection:
|
|
54
|
+
selection: _.create(i.map((e) => _.range(e.anchor, e.head ?? e.anchor)))
|
|
55
55
|
}), !0;
|
|
56
56
|
}
|
|
57
57
|
/** Get the full lines covered by a selection range. */
|
|
@@ -68,7 +68,7 @@ function b(e, t, n) {
|
|
|
68
68
|
}
|
|
69
69
|
return i;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function x(e, t) {
|
|
72
72
|
let { state: n } = e, r = [];
|
|
73
73
|
for (let e of n.selection.ranges) {
|
|
74
74
|
let i = n.doc.lineAt(e.from), a = i.text.match(/^(#{1,6})\s/), o = "#".repeat(t) + " ";
|
|
@@ -91,7 +91,7 @@ function re(e, t) {
|
|
|
91
91
|
}
|
|
92
92
|
return e.dispatch({ changes: r }), !0;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function S(e) {
|
|
95
95
|
let { state: t } = e, n = [];
|
|
96
96
|
for (let r of t.selection.ranges) {
|
|
97
97
|
let t = b(e, r.from, r.to), i = t.every((e) => /^- /.test(e.text));
|
|
@@ -107,7 +107,7 @@ function ie(e) {
|
|
|
107
107
|
}
|
|
108
108
|
return e.dispatch({ changes: n }), !0;
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function C(e) {
|
|
111
111
|
let { state: t } = e, n = [];
|
|
112
112
|
for (let r of t.selection.ranges) {
|
|
113
113
|
let t = b(e, r.from, r.to), i = t.every((e) => /^\d+\.\s/.test(e.text)), a = 1;
|
|
@@ -133,7 +133,7 @@ function x(e) {
|
|
|
133
133
|
}
|
|
134
134
|
return e.dispatch({ changes: n }), !0;
|
|
135
135
|
}
|
|
136
|
-
function
|
|
136
|
+
function w(e) {
|
|
137
137
|
let { state: t } = e, n = [];
|
|
138
138
|
for (let r of t.selection.ranges) {
|
|
139
139
|
let t = b(e, r.from, r.to), i = t.every((e) => /^> /.test(e.text));
|
|
@@ -149,7 +149,7 @@ function S(e) {
|
|
|
149
149
|
}
|
|
150
150
|
return e.dispatch({ changes: n }), !0;
|
|
151
151
|
}
|
|
152
|
-
function
|
|
152
|
+
function T(e, t, n) {
|
|
153
153
|
let { state: r } = e, i = r.selection.main, a = r.sliceDoc(i.from, i.to), o = n ?? (a || "link text"), s = t ?? "url", c = `[${o}](${s})`, l = i.from + 1 + o.length + 2, u = l + s.length;
|
|
154
154
|
return e.dispatch({
|
|
155
155
|
changes: {
|
|
@@ -163,7 +163,7 @@ function C(e, t, n) {
|
|
|
163
163
|
}
|
|
164
164
|
}), !0;
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function E(e, t, n) {
|
|
167
167
|
let { state: r } = e, i = r.selection.main, a = n ?? "alt text", o = t ?? "url", s = ``, c = i.from + 2 + a.length + 2, l = c + o.length;
|
|
168
168
|
return e.dispatch({
|
|
169
169
|
changes: {
|
|
@@ -177,7 +177,7 @@ function w(e, t, n) {
|
|
|
177
177
|
}
|
|
178
178
|
}), !0;
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function D(e) {
|
|
181
181
|
let t = e.state.selection.main;
|
|
182
182
|
return e.dispatch({
|
|
183
183
|
changes: {
|
|
@@ -188,56 +188,56 @@ function T(e) {
|
|
|
188
188
|
selection: { anchor: t.from + 5 }
|
|
189
189
|
}), !0;
|
|
190
190
|
}
|
|
191
|
-
const
|
|
191
|
+
const O = {
|
|
192
192
|
toggleBold: (e) => y(e, "**"),
|
|
193
193
|
toggleItalic: (e) => y(e, "*"),
|
|
194
194
|
toggleCode: (e) => y(e, "`"),
|
|
195
195
|
toggleStrikethrough: (e) => y(e, "~~"),
|
|
196
|
-
setHeading:
|
|
197
|
-
toggleBulletList:
|
|
198
|
-
toggleOrderedList:
|
|
199
|
-
toggleBlockquote:
|
|
200
|
-
insertLink:
|
|
201
|
-
insertImage:
|
|
202
|
-
insertHorizontalRule:
|
|
203
|
-
},
|
|
196
|
+
setHeading: x,
|
|
197
|
+
toggleBulletList: S,
|
|
198
|
+
toggleOrderedList: C,
|
|
199
|
+
toggleBlockquote: w,
|
|
200
|
+
insertLink: T,
|
|
201
|
+
insertImage: E,
|
|
202
|
+
insertHorizontalRule: D
|
|
203
|
+
}, k = re.of([
|
|
204
204
|
{
|
|
205
205
|
key: "Mod-b",
|
|
206
|
-
run: (e) =>
|
|
206
|
+
run: (e) => O.toggleBold(e)
|
|
207
207
|
},
|
|
208
208
|
{
|
|
209
209
|
key: "Mod-i",
|
|
210
|
-
run: (e) =>
|
|
210
|
+
run: (e) => O.toggleItalic(e)
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
213
|
key: "Mod-e",
|
|
214
|
-
run: (e) =>
|
|
214
|
+
run: (e) => O.toggleCode(e)
|
|
215
215
|
},
|
|
216
216
|
{
|
|
217
217
|
key: "Mod-k",
|
|
218
|
-
run: (e) =>
|
|
218
|
+
run: (e) => O.insertLink(e)
|
|
219
219
|
},
|
|
220
220
|
{
|
|
221
221
|
key: "Mod-Shift-1",
|
|
222
|
-
run: (e) =>
|
|
222
|
+
run: (e) => O.setHeading(e, 1)
|
|
223
223
|
},
|
|
224
224
|
{
|
|
225
225
|
key: "Mod-Shift-2",
|
|
226
|
-
run: (e) =>
|
|
226
|
+
run: (e) => O.setHeading(e, 2)
|
|
227
227
|
},
|
|
228
228
|
{
|
|
229
229
|
key: "Mod-Shift-3",
|
|
230
|
-
run: (e) =>
|
|
231
|
-
}
|
|
232
|
-
]),
|
|
233
|
-
var
|
|
234
|
-
ATXHeading1:
|
|
235
|
-
ATXHeading2:
|
|
236
|
-
ATXHeading3:
|
|
237
|
-
ATXHeading4:
|
|
238
|
-
ATXHeading5:
|
|
239
|
-
ATXHeading6:
|
|
240
|
-
},
|
|
230
|
+
run: (e) => O.setHeading(e, 3)
|
|
231
|
+
}
|
|
232
|
+
]), A = new g();
|
|
233
|
+
var j = m.mark({ class: "md-bold" }), M = m.mark({ class: "md-italic" }), N = m.mark({ class: "md-code" }), P = m.mark({ class: "md-strikethrough" }), F = m.mark({ class: "md-link" }), I = m.mark({ class: "md-url" }), L = m.mark({ class: "md-syntax-marker" }), R = m.mark({ class: "md-syntax-marker md-syntax-visible" }), z = m.line({ class: "md-heading md-heading-1" }), ae = m.line({ class: "md-heading md-heading-2" }), B = m.line({ class: "md-heading md-heading-3" }), V = m.line({ class: "md-heading md-heading-4" }), H = m.line({ class: "md-heading md-heading-5" }), U = m.line({ class: "md-heading md-heading-6" }), W = m.line({ class: "md-list-item md-bullet-item" }), G = m.line({ class: "md-list-item md-ordered-item" }), K = m.line({ class: "md-blockquote" }), q = m.line({ class: "md-code-block" }), J = m.line({ class: "md-hr" }), oe = {
|
|
234
|
+
ATXHeading1: z,
|
|
235
|
+
ATXHeading2: ae,
|
|
236
|
+
ATXHeading3: B,
|
|
237
|
+
ATXHeading4: V,
|
|
238
|
+
ATXHeading5: H,
|
|
239
|
+
ATXHeading6: U
|
|
240
|
+
}, se = new Set([
|
|
241
241
|
"HeaderMark",
|
|
242
242
|
"EmphasisMark",
|
|
243
243
|
"CodeMark",
|
|
@@ -245,7 +245,7 @@ var k = f.mark({ class: "md-bold" }), A = f.mark({ class: "md-italic" }), j = f.
|
|
|
245
245
|
"LinkMark",
|
|
246
246
|
"QuoteMark",
|
|
247
247
|
"ListMark"
|
|
248
|
-
]),
|
|
248
|
+
]), ce = class extends ne {
|
|
249
249
|
src;
|
|
250
250
|
alt;
|
|
251
251
|
constructor(e, t) {
|
|
@@ -265,7 +265,7 @@ var k = f.mark({ class: "md-bold" }), A = f.mark({ class: "md-italic" }), j = f.
|
|
|
265
265
|
function Y(e, t, n) {
|
|
266
266
|
return e.sliceString(t, n);
|
|
267
267
|
}
|
|
268
|
-
var
|
|
268
|
+
var le = te.fromClass(class {
|
|
269
269
|
decorations;
|
|
270
270
|
constructor(e) {
|
|
271
271
|
this.decorations = this.buildDecorations(e);
|
|
@@ -274,10 +274,10 @@ var se = p.fromClass(class {
|
|
|
274
274
|
(e.docChanged || e.viewportChanged || e.selectionSet) && (this.decorations = this.buildDecorations(e.view));
|
|
275
275
|
}
|
|
276
276
|
buildDecorations(e) {
|
|
277
|
-
let t = new
|
|
277
|
+
let t = new v(), n = e.state.doc, r = ie(e.state), i = n.lineAt(e.state.selection.main.head).number, a = [], o = [], s = [], c = [];
|
|
278
278
|
r.iterate({
|
|
279
279
|
enter(e) {
|
|
280
|
-
let t = e.name, r =
|
|
280
|
+
let t = e.name, r = oe[t];
|
|
281
281
|
if (r) {
|
|
282
282
|
let t = n.lineAt(e.from), i = n.lineAt(e.to);
|
|
283
283
|
for (let e = t.number; e <= i.number; e++) {
|
|
@@ -289,7 +289,7 @@ var se = p.fromClass(class {
|
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
if ((t === "BulletList" || t === "OrderedList") && c.push(t), t === "ListItem") {
|
|
292
|
-
let t = c[c.length - 1] === "OrderedList" ?
|
|
292
|
+
let t = c[c.length - 1] === "OrderedList" ? G : W, r = n.lineAt(e.from), i = n.lineAt(e.to);
|
|
293
293
|
for (let e = r.number; e <= i.number; e++) {
|
|
294
294
|
let r = n.line(e);
|
|
295
295
|
a.push({
|
|
@@ -304,7 +304,7 @@ var se = p.fromClass(class {
|
|
|
304
304
|
let t = n.line(e);
|
|
305
305
|
a.push({
|
|
306
306
|
pos: t.from,
|
|
307
|
-
deco:
|
|
307
|
+
deco: K
|
|
308
308
|
});
|
|
309
309
|
}
|
|
310
310
|
}
|
|
@@ -314,7 +314,7 @@ var se = p.fromClass(class {
|
|
|
314
314
|
let t = n.line(e);
|
|
315
315
|
a.push({
|
|
316
316
|
pos: t.from,
|
|
317
|
-
deco:
|
|
317
|
+
deco: q
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
320
|
}
|
|
@@ -322,35 +322,35 @@ var se = p.fromClass(class {
|
|
|
322
322
|
let t = n.lineAt(e.from);
|
|
323
323
|
a.push({
|
|
324
324
|
pos: t.from,
|
|
325
|
-
deco:
|
|
325
|
+
deco: J
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
328
|
if (t === "StrongEmphasis" && o.push({
|
|
329
329
|
from: e.from,
|
|
330
330
|
to: e.to,
|
|
331
|
-
deco:
|
|
331
|
+
deco: j
|
|
332
332
|
}), t === "Emphasis" && o.push({
|
|
333
333
|
from: e.from,
|
|
334
334
|
to: e.to,
|
|
335
|
-
deco:
|
|
335
|
+
deco: M
|
|
336
336
|
}), t === "InlineCode" && o.push({
|
|
337
337
|
from: e.from,
|
|
338
338
|
to: e.to,
|
|
339
|
-
deco:
|
|
339
|
+
deco: N
|
|
340
340
|
}), t === "Strikethrough" && o.push({
|
|
341
341
|
from: e.from,
|
|
342
342
|
to: e.to,
|
|
343
|
-
deco:
|
|
343
|
+
deco: P
|
|
344
344
|
}), t === "Link" && o.push({
|
|
345
345
|
from: e.from,
|
|
346
346
|
to: e.to,
|
|
347
|
-
deco:
|
|
347
|
+
deco: F
|
|
348
348
|
}), t === "URL" && o.push({
|
|
349
349
|
from: e.from,
|
|
350
350
|
to: e.to,
|
|
351
|
-
deco:
|
|
352
|
-
}),
|
|
353
|
-
let t = n.lineAt(e.from).number === i ?
|
|
351
|
+
deco: I
|
|
352
|
+
}), se.has(t)) {
|
|
353
|
+
let t = n.lineAt(e.from).number === i ? R : L;
|
|
354
354
|
o.push({
|
|
355
355
|
from: e.from,
|
|
356
356
|
to: e.to,
|
|
@@ -364,8 +364,8 @@ var se = p.fromClass(class {
|
|
|
364
364
|
while (i.nextSibling());
|
|
365
365
|
t && s.push({
|
|
366
366
|
pos: e.to,
|
|
367
|
-
deco:
|
|
368
|
-
widget: new
|
|
367
|
+
deco: m.widget({
|
|
368
|
+
widget: new ce(t, r),
|
|
369
369
|
side: 1
|
|
370
370
|
})
|
|
371
371
|
});
|
|
@@ -414,7 +414,7 @@ var se = p.fromClass(class {
|
|
|
414
414
|
}, { decorations: (e) => e.decorations });
|
|
415
415
|
/** Create the live preview extension (active state) */
|
|
416
416
|
function X() {
|
|
417
|
-
return
|
|
417
|
+
return le;
|
|
418
418
|
}
|
|
419
419
|
/** Empty extension (source mode -- no decorations) */
|
|
420
420
|
const Z = [], Q = [
|
|
@@ -436,14 +436,14 @@ const Z = [], Q = [
|
|
|
436
436
|
"mode-toggle"
|
|
437
437
|
];
|
|
438
438
|
var $ = class {
|
|
439
|
-
mode =
|
|
440
|
-
disabled =
|
|
441
|
-
readonly =
|
|
442
|
-
placeholder =
|
|
443
|
-
toolbar =
|
|
444
|
-
src =
|
|
439
|
+
mode = s("preview");
|
|
440
|
+
disabled = s(!1);
|
|
441
|
+
readonly = s(!1);
|
|
442
|
+
placeholder = s("");
|
|
443
|
+
toolbar = s(Q);
|
|
444
|
+
src = s(null);
|
|
445
445
|
/** True when disabled OR readonly — drives CodeMirror readOnly + editable. */
|
|
446
|
-
locked =
|
|
446
|
+
locked = a(() => this.disabled.value || this.readonly.value);
|
|
447
447
|
setMode(e) {
|
|
448
448
|
e !== "preview" && e !== "source" || (this.mode.value = e);
|
|
449
449
|
}
|
|
@@ -454,67 +454,67 @@ var $ = class {
|
|
|
454
454
|
this.toolbar.value = typeof e == "string" ? e.split(",").map((e) => e.trim()).filter(Boolean) : e;
|
|
455
455
|
}
|
|
456
456
|
reset() {
|
|
457
|
-
|
|
457
|
+
i(() => {
|
|
458
458
|
this.mode.value = "preview", this.disabled.value = !1, this.readonly.value = !1, this.placeholder.value = "", this.toolbar.value = Q, this.src.value = null;
|
|
459
459
|
});
|
|
460
460
|
}
|
|
461
|
-
},
|
|
461
|
+
}, ue = {
|
|
462
462
|
bold: {
|
|
463
463
|
icon: "text-b",
|
|
464
464
|
label: "Bold",
|
|
465
|
-
action:
|
|
465
|
+
action: O.toggleBold
|
|
466
466
|
},
|
|
467
467
|
italic: {
|
|
468
468
|
icon: "text-italic",
|
|
469
469
|
label: "Italic",
|
|
470
|
-
action:
|
|
470
|
+
action: O.toggleItalic
|
|
471
471
|
},
|
|
472
472
|
code: {
|
|
473
473
|
icon: "code",
|
|
474
474
|
label: "Code",
|
|
475
|
-
action:
|
|
475
|
+
action: O.toggleCode
|
|
476
476
|
},
|
|
477
477
|
h1: {
|
|
478
478
|
icon: "text-h-one",
|
|
479
479
|
label: "Heading 1",
|
|
480
|
-
action: (e) =>
|
|
480
|
+
action: (e) => O.setHeading(e, 1)
|
|
481
481
|
},
|
|
482
482
|
h2: {
|
|
483
483
|
icon: "text-h-two",
|
|
484
484
|
label: "Heading 2",
|
|
485
|
-
action: (e) =>
|
|
485
|
+
action: (e) => O.setHeading(e, 2)
|
|
486
486
|
},
|
|
487
487
|
h3: {
|
|
488
488
|
icon: "text-h-three",
|
|
489
489
|
label: "Heading 3",
|
|
490
|
-
action: (e) =>
|
|
490
|
+
action: (e) => O.setHeading(e, 3)
|
|
491
491
|
},
|
|
492
492
|
"bullet-list": {
|
|
493
493
|
icon: "list-bullets",
|
|
494
494
|
label: "Bullet List",
|
|
495
|
-
action:
|
|
495
|
+
action: O.toggleBulletList
|
|
496
496
|
},
|
|
497
497
|
"ordered-list": {
|
|
498
498
|
icon: "list-numbers",
|
|
499
499
|
label: "Ordered List",
|
|
500
|
-
action:
|
|
500
|
+
action: O.toggleOrderedList
|
|
501
501
|
},
|
|
502
502
|
blockquote: {
|
|
503
503
|
icon: "quotes",
|
|
504
504
|
label: "Blockquote",
|
|
505
|
-
action:
|
|
505
|
+
action: O.toggleBlockquote
|
|
506
506
|
},
|
|
507
507
|
link: {
|
|
508
508
|
icon: "link",
|
|
509
509
|
label: "Link",
|
|
510
|
-
action:
|
|
510
|
+
action: O.insertLink
|
|
511
511
|
},
|
|
512
512
|
image: {
|
|
513
513
|
icon: "image",
|
|
514
514
|
label: "Image",
|
|
515
|
-
action:
|
|
515
|
+
action: O.insertImage
|
|
516
516
|
}
|
|
517
|
-
},
|
|
517
|
+
}, de = class extends t {
|
|
518
518
|
static observedAttributes = [
|
|
519
519
|
"value",
|
|
520
520
|
"mode",
|
|
@@ -532,10 +532,12 @@ var $ = class {
|
|
|
532
532
|
#r = null;
|
|
533
533
|
#i = null;
|
|
534
534
|
#a = "";
|
|
535
|
-
#o = new
|
|
536
|
-
#s = new
|
|
535
|
+
#o = new c();
|
|
536
|
+
#s = new c();
|
|
537
537
|
#c = null;
|
|
538
538
|
#l = null;
|
|
539
|
+
#u = null;
|
|
540
|
+
#d = null;
|
|
539
541
|
constructor() {
|
|
540
542
|
super(), this.#e = this.attachInternals();
|
|
541
543
|
}
|
|
@@ -623,17 +625,17 @@ var $ = class {
|
|
|
623
625
|
};
|
|
624
626
|
}
|
|
625
627
|
return {
|
|
626
|
-
toggleBold: (t) =>
|
|
627
|
-
toggleItalic: (t) =>
|
|
628
|
-
toggleCode: (t) =>
|
|
629
|
-
toggleStrikethrough: (t) =>
|
|
630
|
-
setHeading: (t, n) =>
|
|
631
|
-
toggleBulletList: (t) =>
|
|
632
|
-
toggleOrderedList: (t) =>
|
|
633
|
-
toggleBlockquote: (t) =>
|
|
634
|
-
insertLink: (t, n, r) =>
|
|
635
|
-
insertImage: (t, n, r) =>
|
|
636
|
-
insertHorizontalRule: (t) =>
|
|
628
|
+
toggleBold: (t) => O.toggleBold(e),
|
|
629
|
+
toggleItalic: (t) => O.toggleItalic(e),
|
|
630
|
+
toggleCode: (t) => O.toggleCode(e),
|
|
631
|
+
toggleStrikethrough: (t) => O.toggleStrikethrough(e),
|
|
632
|
+
setHeading: (t, n) => O.setHeading(e, n),
|
|
633
|
+
toggleBulletList: (t) => O.toggleBulletList(e),
|
|
634
|
+
toggleOrderedList: (t) => O.toggleOrderedList(e),
|
|
635
|
+
toggleBlockquote: (t) => O.toggleBlockquote(e),
|
|
636
|
+
insertLink: (t, n, r) => O.insertLink(e, n, r),
|
|
637
|
+
insertImage: (t, n, r) => O.insertImage(e, n, r),
|
|
638
|
+
insertHorizontalRule: (t) => O.insertHorizontalRule(e)
|
|
637
639
|
};
|
|
638
640
|
}
|
|
639
641
|
focus() {
|
|
@@ -666,7 +668,7 @@ var $ = class {
|
|
|
666
668
|
let e = this.#t.src.value;
|
|
667
669
|
if (!e) return !1;
|
|
668
670
|
let t = await this.#n.save(e, this.value);
|
|
669
|
-
return t && this.dispatchEvent(new CustomEvent("
|
|
671
|
+
return t && this.dispatchEvent(new CustomEvent("n-save", {
|
|
670
672
|
bubbles: !0,
|
|
671
673
|
composed: !0
|
|
672
674
|
})), t;
|
|
@@ -676,7 +678,7 @@ var $ = class {
|
|
|
676
678
|
let e = this.#t.src.value;
|
|
677
679
|
if (!e) return;
|
|
678
680
|
let t = await this.#n.load(e);
|
|
679
|
-
t !== null && (this.value = t, this.dispatchEvent(new CustomEvent("
|
|
681
|
+
t !== null && (this.value = t, this.dispatchEvent(new CustomEvent("n-load", {
|
|
680
682
|
bubbles: !0,
|
|
681
683
|
composed: !0,
|
|
682
684
|
detail: { value: t }
|
|
@@ -719,21 +721,25 @@ var $ = class {
|
|
|
719
721
|
let e = this.#t;
|
|
720
722
|
e.mode.value = this.getAttribute("mode") || "preview", e.disabled.value = this.hasAttribute("disabled"), e.readonly.value = this.hasAttribute("readonly"), e.placeholder.value = this.getAttribute("placeholder") ?? "";
|
|
721
723
|
let t = this.getAttribute("toolbar");
|
|
722
|
-
t && e.setToolbar(t), e.src.value = this.getAttribute("src"), this.#a = this.#
|
|
724
|
+
t && e.setToolbar(t), e.src.value = this.getAttribute("src"), this.#a = this.#f(), this.#p(), this.#g(), this.#_(), this.#d = new n(this), this.#u = new r(this, {
|
|
725
|
+
handleSelector: ".native-editor-resize-handle",
|
|
726
|
+
axis: "vertical",
|
|
727
|
+
min: 200
|
|
728
|
+
}), this.addEffect(o(this, e.disabled, this.#e)), this.addEffect(() => {
|
|
723
729
|
let t = e.mode.value;
|
|
724
|
-
this.#r && this.#r.dispatch({ effects:
|
|
730
|
+
this.#r && this.#r.dispatch({ effects: A.reconfigure(t === "preview" ? X() : Z) }), this.#l && this.#l.setAttribute("value", t), this.dispatchEvent(new CustomEvent("mode-change", {
|
|
725
731
|
bubbles: !0,
|
|
726
732
|
composed: !0,
|
|
727
733
|
detail: { mode: t }
|
|
728
734
|
}));
|
|
729
735
|
}), this.addEffect(() => {
|
|
730
736
|
let t = e.locked.value;
|
|
731
|
-
this.#r && this.#r.dispatch({ effects: this.#o.reconfigure([
|
|
737
|
+
this.#r && this.#r.dispatch({ effects: this.#o.reconfigure([l.readOnly.of(t), u.editable.of(!t)]) }), this.#c && this.#c.toggleAttribute("disabled", e.disabled.value);
|
|
732
738
|
}), this.addEffect(() => {
|
|
733
739
|
let t = e.placeholder.value;
|
|
734
740
|
this.#r && this.#r.dispatch({ effects: this.#s.reconfigure(t ? h(t) : []) });
|
|
735
741
|
}), this.addEffect(() => {
|
|
736
|
-
e.toolbar.value, this.#
|
|
742
|
+
e.toolbar.value, this.#m();
|
|
737
743
|
}), this.addEffect(() => {
|
|
738
744
|
e.src.value && this.reload();
|
|
739
745
|
}), this.addEffect(() => {
|
|
@@ -749,7 +755,7 @@ var $ = class {
|
|
|
749
755
|
}));
|
|
750
756
|
}), this.addEffect(() => {
|
|
751
757
|
let e = this.#n.error.value;
|
|
752
|
-
e && this.dispatchEvent(new CustomEvent("
|
|
758
|
+
e && this.dispatchEvent(new CustomEvent("n-error", {
|
|
753
759
|
bubbles: !0,
|
|
754
760
|
composed: !0,
|
|
755
761
|
detail: { error: e }
|
|
@@ -757,13 +763,13 @@ var $ = class {
|
|
|
757
763
|
}), this.#e.setFormValue(this.#a);
|
|
758
764
|
}
|
|
759
765
|
teardown() {
|
|
760
|
-
this.#n.destroy(), this.#r &&= (this.#r.destroy(), null), this.#c = null, this.#l = null, this.#i = null, super.teardown();
|
|
766
|
+
this.#n.destroy(), this.#u?.destroy(), this.#u = null, this.#d?.destroy(), this.#d = null, this.#r &&= (this.#r.destroy(), null), this.#c = null, this.#l = null, this.#i = null, super.teardown();
|
|
761
767
|
}
|
|
762
768
|
/**
|
|
763
769
|
* Read initial content from a `<script type="text/markdown">` child,
|
|
764
770
|
* falling back to the `value` attribute. Consumes the script tag.
|
|
765
771
|
*/
|
|
766
|
-
#
|
|
772
|
+
#f() {
|
|
767
773
|
let e = this.querySelector("script[type=\"text/markdown\"]");
|
|
768
774
|
if (e) {
|
|
769
775
|
let t = e.textContent ?? "";
|
|
@@ -771,57 +777,64 @@ var $ = class {
|
|
|
771
777
|
}
|
|
772
778
|
return this.getAttribute("value") ?? "";
|
|
773
779
|
}
|
|
774
|
-
#
|
|
775
|
-
let e = document.createElement("
|
|
776
|
-
|
|
780
|
+
#p() {
|
|
781
|
+
let e = document.createElement("n-card-header"), t = document.createElement("n-toolbar");
|
|
782
|
+
t.setAttribute("size", "md"), t.setAttribute("variant", "plain"), t.setAttribute("fill", ""), this.#c = t, e.appendChild(t), this.appendChild(e), this.#m();
|
|
777
783
|
}
|
|
778
|
-
#
|
|
784
|
+
#m() {
|
|
779
785
|
let e = this.#c;
|
|
780
786
|
if (!e) return;
|
|
781
787
|
e.innerHTML = "", this.#l = null;
|
|
782
788
|
let t = this.#t.toolbar.value;
|
|
783
789
|
for (let n of t) {
|
|
784
790
|
if (n === "|") {
|
|
785
|
-
let t = document.createElement("
|
|
786
|
-
t.setAttribute("
|
|
791
|
+
let t = document.createElement("n-divider");
|
|
792
|
+
t.setAttribute("orientation", "vertical"), e.appendChild(t);
|
|
787
793
|
continue;
|
|
788
794
|
}
|
|
789
795
|
if (n === "mode-toggle") {
|
|
790
|
-
this.#
|
|
796
|
+
this.#h(e);
|
|
791
797
|
continue;
|
|
792
798
|
}
|
|
793
|
-
let t =
|
|
799
|
+
let t = ue[n];
|
|
794
800
|
if (!t) continue;
|
|
795
|
-
let r = document.createElement("
|
|
801
|
+
let r = document.createElement("n-button");
|
|
796
802
|
r.setAttribute("variant", "ghost"), r.setAttribute("size", "sm"), r.setAttribute("square", ""), r.setAttribute("aria-label", t.label), r.setAttribute("title", t.label);
|
|
797
|
-
let i = document.createElement("
|
|
798
|
-
i.setAttribute("name", t.icon), r.appendChild(i), r.addEventListener("
|
|
803
|
+
let i = document.createElement("n-icon");
|
|
804
|
+
i.setAttribute("name", t.icon), r.appendChild(i), r.addEventListener("native:press", this.#v(t.action)), e.appendChild(r);
|
|
799
805
|
}
|
|
806
|
+
let n = document.createElement("n-button");
|
|
807
|
+
n.setAttribute("variant", "ghost"), n.setAttribute("size", "sm"), n.setAttribute("square", ""), n.setAttribute("aria-label", "Expand"), n.setAttribute("title", "Expand");
|
|
808
|
+
let r = document.createElement("n-icon");
|
|
809
|
+
r.setAttribute("name", "arrows-out"), n.appendChild(r), n.addEventListener("native:press", this.#y), e.appendChild(n);
|
|
800
810
|
}
|
|
801
|
-
#
|
|
802
|
-
let t = document.createElement("
|
|
811
|
+
#h(e) {
|
|
812
|
+
let t = document.createElement("n-segmented-control");
|
|
803
813
|
t.setAttribute("size", "sm"), t.setAttribute("value", this.#t.mode.value), this.#l = t;
|
|
804
|
-
let n = document.createElement("
|
|
814
|
+
let n = document.createElement("n-segment");
|
|
805
815
|
n.setAttribute("value", "preview"), n.textContent = "Preview";
|
|
806
|
-
let r = document.createElement("
|
|
807
|
-
r.setAttribute("value", "source"), r.textContent = "Source", t.appendChild(n), t.appendChild(r), t.addEventListener("
|
|
816
|
+
let r = document.createElement("n-segment");
|
|
817
|
+
r.setAttribute("value", "source"), r.textContent = "Source", t.appendChild(n), t.appendChild(r), t.addEventListener("native:change", this.#b), e.appendChild(t);
|
|
808
818
|
}
|
|
809
|
-
#
|
|
819
|
+
#g() {
|
|
810
820
|
let e = document.createElement("div");
|
|
811
|
-
e.className = "
|
|
821
|
+
e.className = "native-editor-surface", this.#i = e, this.appendChild(e);
|
|
822
|
+
let t = document.createElement("div");
|
|
823
|
+
t.className = "native-editor-resize-handle", this.appendChild(t);
|
|
812
824
|
}
|
|
813
|
-
#
|
|
825
|
+
#_() {
|
|
814
826
|
if (!this.#i) return;
|
|
815
827
|
let e = this.#t, t = this.#a, n = e.mode.value, r = e.placeholder.value, i = e.locked.value, a = [
|
|
828
|
+
f,
|
|
816
829
|
ee,
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
this.#o.of([
|
|
830
|
+
d,
|
|
831
|
+
u.lineWrapping,
|
|
832
|
+
p(),
|
|
833
|
+
k,
|
|
834
|
+
A.of(n === "preview" ? X() : Z),
|
|
835
|
+
this.#o.of([l.readOnly.of(i), u.editable.of(!i)]),
|
|
823
836
|
this.#s.of(r ? h(r) : []),
|
|
824
|
-
|
|
837
|
+
u.updateListener.of((e) => {
|
|
825
838
|
if (e.docChanged) {
|
|
826
839
|
let t = e.state.doc.toString();
|
|
827
840
|
this.#e.setFormValue(t), this.#n.markDirty(), this.dispatchEvent(new CustomEvent("change", {
|
|
@@ -832,22 +845,26 @@ var $ = class {
|
|
|
832
845
|
}
|
|
833
846
|
})
|
|
834
847
|
];
|
|
835
|
-
this.#r = new
|
|
836
|
-
state:
|
|
848
|
+
this.#r = new u({
|
|
849
|
+
state: l.create({
|
|
837
850
|
doc: t,
|
|
838
851
|
extensions: a
|
|
839
852
|
}),
|
|
840
|
-
parent: this.#i
|
|
853
|
+
parent: this.#i,
|
|
854
|
+
root: this.ownerDocument
|
|
841
855
|
});
|
|
842
856
|
}
|
|
843
|
-
#
|
|
857
|
+
#v(e) {
|
|
844
858
|
return () => {
|
|
845
859
|
this.#r && (e(this.#r), this.#r.focus());
|
|
846
860
|
};
|
|
847
861
|
}
|
|
848
|
-
#
|
|
862
|
+
#y = () => {
|
|
863
|
+
this.#d?.present();
|
|
864
|
+
};
|
|
865
|
+
#b = (e) => {
|
|
849
866
|
let t = e.detail;
|
|
850
867
|
t && (t.value === "preview" || t.value === "source") && (this.#t.mode.value = t.value, this.setAttribute("mode", t.value));
|
|
851
868
|
};
|
|
852
869
|
};
|
|
853
|
-
export {
|
|
870
|
+
export { A as a, k as c, X as i, Q as n, Z as o, $ as r, O as s, de as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NativeElement } from '@nonoun/native-ui';
|
|
2
2
|
import type { EditorCommands } from './commands.ts';
|
|
3
3
|
import type { ViewMode } from './editor-store.ts';
|
|
4
4
|
/**
|
|
@@ -17,12 +17,12 @@ import type { ViewMode } from './editor-store.ts';
|
|
|
17
17
|
* @attr {string} src - URL to load/save content from
|
|
18
18
|
* @fires change - Fired when document content changes with `{ value }` detail
|
|
19
19
|
* @fires mode-change - Fired when mode is toggled with `{ mode }` detail
|
|
20
|
-
* @fires
|
|
21
|
-
* @fires
|
|
22
|
-
* @fires
|
|
20
|
+
* @fires n-load - Fired after content is loaded from src
|
|
21
|
+
* @fires n-save - Fired after content is saved to src
|
|
22
|
+
* @fires n-error - Fired on load/save error with `{ error }` detail
|
|
23
23
|
* @fires dirty-change - Fired when dirty state changes with `{ dirty }` detail
|
|
24
24
|
*/
|
|
25
|
-
export declare class
|
|
25
|
+
export declare class NEditor extends NativeElement {
|
|
26
26
|
#private;
|
|
27
27
|
static observedAttributes: string[];
|
|
28
28
|
static formAssociated: boolean;
|
|
@@ -64,4 +64,4 @@ export declare class NuiEditor extends UIElement {
|
|
|
64
64
|
setup(): void;
|
|
65
65
|
teardown(): void;
|
|
66
66
|
}
|
|
67
|
-
//# sourceMappingURL=
|
|
67
|
+
//# sourceMappingURL=editor-element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-element.d.ts","sourceRoot":"","sources":["../src/editor-element.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAgF,MAAM,mBAAmB,CAAC;AAMhI,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA8BlD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,OAAQ,SAAQ,aAAa;;IACxC,MAAM,CAAC,kBAAkB,WAAsF;IAC/G,MAAM,CAAC,cAAc,UAAQ;;IA0B7B,IAAI,KAAK,IAAI,MAAM,CAKlB;IAED,IAAI,KAAK,CAAC,GAAG,EAAE,MAAM,EAUpB;IAED,IAAI,IAAI,IAAI,QAAQ,CAEnB;IAED,IAAI,IAAI,CAAC,GAAG,EAAE,QAAQ,EAGrB;IAED,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAEjC;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,WAAW,CAAC,GAAG,EAAE,MAAM,EAG1B;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,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,GAAG,EAAE,MAAM,EAEnB;IAED,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,CAEvB;IAED,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAIzB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAID,kFAAkF;IAClF,IAAI,QAAQ,IAAI,cAAc,CAgC7B;IAEQ,KAAK,IAAI,IAAI;IAItB,YAAY,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAM1D,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAQjD,qDAAqD;IAC/C,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAU9B,yCAAyC;IACnC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAc7B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAyCpF,KAAK,IAAI,IAAI;IAiIb,QAAQ,IAAI,IAAI;CAsNjB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { NEditor } from './editor-element.ts';
|
|
2
2
|
export { EditorStore, DEFAULT_TOOLBAR } from './editor-store.ts';
|
|
3
3
|
export type { ViewMode } from './editor-store.ts';
|
|
4
4
|
export { commands, markdownKeymap } from './commands.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACjE,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzD,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* native-editor.css
|
|
3
3
|
* Markdown content editor — toolbar + CodeMirror surface + optional preview pane.
|
|
4
4
|
* Follows NativeUI CSS conventions: @layer ui, :where() selectors, --n-* locals.
|
|
5
5
|
*/
|
|
@@ -10,51 +10,77 @@
|
|
|
10
10
|
/* Host element */
|
|
11
11
|
/* ------------------------------------------------------------------ */
|
|
12
12
|
|
|
13
|
-
:where(
|
|
13
|
+
:where(native-editor) {
|
|
14
|
+
/* Code-editor chrome tokens — NativeUI first, one-dark fallbacks */
|
|
15
|
+
--n-code-bg: var(--n-control-neutral, #282c34);
|
|
16
|
+
--n-code-bg-dark: var(--n-panel-neutral, #21252b);
|
|
17
|
+
--n-code-bg-darker: var(--n-body-neutral, #1e2127);
|
|
18
|
+
--n-code-text-muted: var(--n-ink-muted-neutral, #7d8799);
|
|
19
|
+
--n-code-accent: var(--n-ink-accent, #61afef);
|
|
20
|
+
--n-code-border: var(--n-border-muted-neutral, #3e4451);
|
|
21
|
+
--n-code-inline-bg: var(--n-card-neutral, #333843);
|
|
22
|
+
|
|
14
23
|
display: grid;
|
|
15
24
|
grid-template-rows: auto 1fr;
|
|
16
|
-
|
|
25
|
+
position: relative;
|
|
26
|
+
border: 1px solid var(--n-code-border);
|
|
17
27
|
border-radius: var(--n-radius, 0.5rem);
|
|
18
28
|
overflow: hidden;
|
|
19
29
|
min-height: 300px;
|
|
20
|
-
background:
|
|
30
|
+
background: var(--n-code-bg);
|
|
31
|
+
outline: none;
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
/* ------------------------------------------------------------------ */
|
|
24
|
-
/*
|
|
35
|
+
/* Card header (toolbar chrome) */
|
|
25
36
|
/* ------------------------------------------------------------------ */
|
|
26
37
|
|
|
27
|
-
:where(
|
|
28
|
-
border-bottom: 1px solid
|
|
29
|
-
background:
|
|
30
|
-
|
|
38
|
+
:where(native-editor) > :where(n-card-header) {
|
|
39
|
+
border-bottom: 1px solid var(--n-code-border);
|
|
40
|
+
background: var(--n-code-bg-dark);
|
|
41
|
+
padding: 0;
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
/* ------------------------------------------------------------------ */
|
|
34
45
|
/* Editor surface */
|
|
35
46
|
/* ------------------------------------------------------------------ */
|
|
36
47
|
|
|
37
|
-
:where(
|
|
48
|
+
:where(native-editor) :where(.native-editor-surface) {
|
|
38
49
|
min-height: 0;
|
|
39
50
|
overflow: hidden;
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
:where(
|
|
53
|
+
:where(native-editor) :where(.cm-editor) {
|
|
43
54
|
height: 100%;
|
|
44
55
|
font-size: 0.875rem;
|
|
45
56
|
line-height: 1.6;
|
|
46
57
|
}
|
|
47
58
|
|
|
48
|
-
:where(
|
|
59
|
+
:where(native-editor) :where(.cm-editor.cm-focused) {
|
|
60
|
+
outline: none;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
:where(native-editor) :where(.cm-scroller) {
|
|
49
64
|
overflow: auto;
|
|
50
65
|
padding: 1rem;
|
|
51
66
|
}
|
|
52
67
|
|
|
53
|
-
:where(
|
|
68
|
+
:where(native-editor) :where(.cm-content) {
|
|
54
69
|
padding: 0;
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
|
|
72
|
+
|
|
73
|
+
:where(.cm-content):focus-visible,
|
|
74
|
+
:where(.cm-editor.cm-focused) {
|
|
75
|
+
outline: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* WHY: Source mode shows raw markdown — use monospace for code-editing feel */
|
|
79
|
+
:where(native-editor[mode="source"]) :where(.cm-content) {
|
|
80
|
+
font-family: var(--n-font-family-mono, ui-monospace, 'SF Mono', 'Cascadia Code', monospace);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:where(native-editor) :where(.cm-gutters) {
|
|
58
84
|
display: none;
|
|
59
85
|
}
|
|
60
86
|
|
|
@@ -62,31 +88,31 @@
|
|
|
62
88
|
/* Live preview — inline decorations */
|
|
63
89
|
/* ------------------------------------------------------------------ */
|
|
64
90
|
|
|
65
|
-
:where(
|
|
91
|
+
:where(native-editor) :where(.md-bold) {
|
|
66
92
|
font-weight: 700;
|
|
67
93
|
}
|
|
68
94
|
|
|
69
|
-
:where(
|
|
95
|
+
:where(native-editor) :where(.md-italic) {
|
|
70
96
|
font-style: italic;
|
|
71
97
|
}
|
|
72
98
|
|
|
73
|
-
:where(
|
|
99
|
+
:where(native-editor) :where(.md-code) {
|
|
74
100
|
font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
|
|
75
|
-
background:
|
|
101
|
+
background: var(--n-code-inline-bg);
|
|
76
102
|
border-radius: 0.1875rem;
|
|
77
103
|
padding: 0.0625rem 0.25rem;
|
|
78
104
|
}
|
|
79
105
|
|
|
80
|
-
:where(
|
|
106
|
+
:where(native-editor) :where(.md-strikethrough) {
|
|
81
107
|
text-decoration: line-through;
|
|
82
108
|
}
|
|
83
109
|
|
|
84
|
-
:where(
|
|
85
|
-
color:
|
|
110
|
+
:where(native-editor) :where(.md-link) {
|
|
111
|
+
color: var(--n-code-accent);
|
|
86
112
|
text-decoration: underline;
|
|
87
113
|
}
|
|
88
114
|
|
|
89
|
-
:where(
|
|
115
|
+
:where(native-editor) :where(.md-url) {
|
|
90
116
|
opacity: 0.4;
|
|
91
117
|
font-size: 0.85em;
|
|
92
118
|
}
|
|
@@ -95,11 +121,11 @@
|
|
|
95
121
|
/* Live preview — syntax markers */
|
|
96
122
|
/* ------------------------------------------------------------------ */
|
|
97
123
|
|
|
98
|
-
:where(
|
|
124
|
+
:where(native-editor) :where(.md-syntax-marker) {
|
|
99
125
|
opacity: 0.3;
|
|
100
126
|
}
|
|
101
127
|
|
|
102
|
-
:where(
|
|
128
|
+
:where(native-editor) :where(.md-syntax-marker-visible) {
|
|
103
129
|
opacity: 0.6;
|
|
104
130
|
}
|
|
105
131
|
|
|
@@ -107,19 +133,19 @@
|
|
|
107
133
|
/* Live preview — headings */
|
|
108
134
|
/* ------------------------------------------------------------------ */
|
|
109
135
|
|
|
110
|
-
:where(
|
|
136
|
+
:where(native-editor) :where(.md-heading) {
|
|
111
137
|
font-weight: 700;
|
|
112
138
|
}
|
|
113
139
|
|
|
114
|
-
:where(
|
|
140
|
+
:where(native-editor) :where(.md-heading-1) {
|
|
115
141
|
font-size: 1.5em;
|
|
116
142
|
}
|
|
117
143
|
|
|
118
|
-
:where(
|
|
144
|
+
:where(native-editor) :where(.md-heading-2) {
|
|
119
145
|
font-size: 1.25em;
|
|
120
146
|
}
|
|
121
147
|
|
|
122
|
-
:where(
|
|
148
|
+
:where(native-editor) :where(.md-heading-3) {
|
|
123
149
|
font-size: 1.1em;
|
|
124
150
|
}
|
|
125
151
|
|
|
@@ -127,7 +153,7 @@
|
|
|
127
153
|
/* Live preview — lists */
|
|
128
154
|
/* ------------------------------------------------------------------ */
|
|
129
155
|
|
|
130
|
-
:where(
|
|
156
|
+
:where(native-editor) :where(.md-list-item) {
|
|
131
157
|
padding-left: 0.25em;
|
|
132
158
|
}
|
|
133
159
|
|
|
@@ -135,8 +161,8 @@
|
|
|
135
161
|
/* Live preview — blockquote */
|
|
136
162
|
/* ------------------------------------------------------------------ */
|
|
137
163
|
|
|
138
|
-
:where(
|
|
139
|
-
border-left: 3px solid
|
|
164
|
+
:where(native-editor) :where(.md-blockquote) {
|
|
165
|
+
border-left: 3px solid var(--n-code-accent);
|
|
140
166
|
padding-left: 1em;
|
|
141
167
|
opacity: 0.85;
|
|
142
168
|
}
|
|
@@ -145,8 +171,8 @@
|
|
|
145
171
|
/* Live preview — code blocks */
|
|
146
172
|
/* ------------------------------------------------------------------ */
|
|
147
173
|
|
|
148
|
-
:where(
|
|
149
|
-
background:
|
|
174
|
+
:where(native-editor) :where(.md-code-block) {
|
|
175
|
+
background: var(--n-code-bg-darker);
|
|
150
176
|
font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
|
|
151
177
|
font-size: 0.8125rem;
|
|
152
178
|
}
|
|
@@ -155,8 +181,8 @@
|
|
|
155
181
|
/* Live preview — horizontal rule */
|
|
156
182
|
/* ------------------------------------------------------------------ */
|
|
157
183
|
|
|
158
|
-
:where(
|
|
159
|
-
border-bottom: 1px solid
|
|
184
|
+
:where(native-editor) :where(.md-hr) {
|
|
185
|
+
border-bottom: 1px solid var(--n-code-border);
|
|
160
186
|
margin: 0.5em 0;
|
|
161
187
|
}
|
|
162
188
|
|
|
@@ -164,7 +190,7 @@
|
|
|
164
190
|
/* Live preview — image widget */
|
|
165
191
|
/* ------------------------------------------------------------------ */
|
|
166
192
|
|
|
167
|
-
:where(
|
|
193
|
+
:where(native-editor) :where(.md-image) {
|
|
168
194
|
max-width: 100%;
|
|
169
195
|
border-radius: 0.375rem;
|
|
170
196
|
margin: 0.5em 0;
|
|
@@ -174,11 +200,11 @@
|
|
|
174
200
|
/* States */
|
|
175
201
|
/* ------------------------------------------------------------------ */
|
|
176
202
|
|
|
177
|
-
:where(
|
|
203
|
+
:where(native-editor[readonly]) :where(.cm-content) {
|
|
178
204
|
cursor: default;
|
|
179
205
|
}
|
|
180
206
|
|
|
181
|
-
:where(
|
|
207
|
+
:where(native-editor)[aria-disabled="true"] {
|
|
182
208
|
opacity: 0.5;
|
|
183
209
|
pointer-events: none;
|
|
184
210
|
}
|
|
@@ -187,9 +213,41 @@
|
|
|
187
213
|
/* Placeholder */
|
|
188
214
|
/* ------------------------------------------------------------------ */
|
|
189
215
|
|
|
190
|
-
:where(
|
|
191
|
-
color:
|
|
216
|
+
:where(native-editor) :where(.cm-placeholder) {
|
|
217
|
+
color: var(--n-code-text-muted);
|
|
192
218
|
font-style: italic;
|
|
193
219
|
}
|
|
194
220
|
|
|
221
|
+
/* ------------------------------------------------------------------ */
|
|
222
|
+
/* Resize handle */
|
|
223
|
+
/* ------------------------------------------------------------------ */
|
|
224
|
+
|
|
225
|
+
:where(native-editor) :where(.native-editor-resize-handle) {
|
|
226
|
+
position: absolute;
|
|
227
|
+
bottom: 0;
|
|
228
|
+
right: 0;
|
|
229
|
+
width: 16px;
|
|
230
|
+
height: 16px;
|
|
231
|
+
cursor: nwse-resize;
|
|
232
|
+
opacity: 0.3;
|
|
233
|
+
transition: opacity 150ms;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
:where(native-editor) :where(.native-editor-resize-handle):hover,
|
|
237
|
+
:where(native-editor[resizing]) :where(.native-editor-resize-handle) {
|
|
238
|
+
opacity: 0.7;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
:where(native-editor) :where(.native-editor-resize-handle)::before {
|
|
242
|
+
content: '';
|
|
243
|
+
position: absolute;
|
|
244
|
+
bottom: 3px;
|
|
245
|
+
right: 3px;
|
|
246
|
+
width: 8px;
|
|
247
|
+
height: 8px;
|
|
248
|
+
border-right: 2px solid currentColor;
|
|
249
|
+
border-bottom: 2px solid currentColor;
|
|
250
|
+
color: var(--n-code-border);
|
|
251
|
+
}
|
|
252
|
+
|
|
195
253
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as e, c as t, i as n, n as r, o as i, r as a, s as o, t as s } from "./editor-element-lE0uhdJ9.js";
|
|
2
|
+
export { r as DEFAULT_TOOLBAR, a as EditorStore, s as NEditor, o as commands, n as createPreviewExtension, t as markdownKeymap, e as previewCompartment, i as sourceExtension };
|
package/dist/register.d.ts
CHANGED
package/dist/register.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import { t as e } from "./
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
* Register nui-editor
|
|
5
|
-
*
|
|
6
|
-
* Side-effect module that registers the <nui-editor> custom element.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* import '@nonoun/nui-editor/register';
|
|
10
|
-
*/
|
|
11
|
-
t("nui-editor", e);
|
|
1
|
+
import { t as e } from "./editor-element-lE0uhdJ9.js";
|
|
2
|
+
import { NSegment as t, NSegmentedControl as n, define as r } from "@nonoun/native-ui";
|
|
3
|
+
r("n-segmented-control", n), r("n-segment", t), r("native-editor", e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nonoun/native-editor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Markdown content editor with live preview for @nonoun/native-ui",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"@nonoun/native-ui": ">=0.5.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@nonoun/native-codemirror": "^0.
|
|
31
|
+
"@nonoun/native-codemirror": "^0.2.0",
|
|
32
32
|
"@codemirror/lang-markdown": "^6.3.2",
|
|
33
33
|
"@lezer/markdown": "^1.3.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "npm run build:js && npm run build:css && npm run build:types",
|
|
37
37
|
"build:js": "vite build",
|
|
38
|
-
"build:css": "cp src/css/
|
|
38
|
+
"build:css": "cp src/css/editor.css dist/native-editor.css",
|
|
39
39
|
"build:types": "tsc -p tsconfig.build.json"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nui-editor-element.d.ts","sourceRoot":"","sources":["../src/nui-editor-element.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAA2C,MAAM,mBAAmB,CAAC;AAMvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA8BlD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,SAAU,SAAQ,SAAS;;IACtC,MAAM,CAAC,kBAAkB,WAAsF;IAC/G,MAAM,CAAC,cAAc,UAAQ;;IAwB7B,IAAI,KAAK,IAAI,MAAM,CAKlB;IAED,IAAI,KAAK,CAAC,GAAG,EAAE,MAAM,EAUpB;IAED,IAAI,IAAI,IAAI,QAAQ,CAEnB;IAED,IAAI,IAAI,CAAC,GAAG,EAAE,QAAQ,EAGrB;IAED,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAEjC;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,WAAW,CAAC,GAAG,EAAE,MAAM,EAG1B;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,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,GAAG,EAAE,MAAM,EAEnB;IAED,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,CAEvB;IAED,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAIzB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAID,kFAAkF;IAClF,IAAI,QAAQ,IAAI,cAAc,CAgC7B;IAEQ,KAAK,IAAI,IAAI;IAItB,YAAY,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAM1D,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAQjD,qDAAqD;IAC/C,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAU9B,yCAAyC;IACnC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAc7B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAyCpF,KAAK,IAAI,IAAI;IAuHb,QAAQ,IAAI,IAAI;CAkLjB"}
|
package/dist/nui-editor.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as e, c as t, i as n, n as r, o as i, r as a, s as o, t as s } from "./nui-editor-element-S_Z8i0qQ.js";
|
|
2
|
-
export { r as DEFAULT_TOOLBAR, a as EditorStore, s as NuiEditor, o as commands, n as createPreviewExtension, t as markdownKeymap, e as previewCompartment, i as sourceExtension };
|