@markput/react 0.2.0 → 0.3.0
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/README.md +3 -1
- package/index.d.ts +11 -0
- package/index.js +603 -329
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
|
-
import { jsx as f, Fragment as
|
|
3
|
-
import { createContext as
|
|
4
|
-
function
|
|
2
|
+
import { jsx as f, Fragment as wt, jsxs as Z } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as at, useContext as ct, useRef as H, useMemo as S, useLayoutEffect as St, memo as O, useState as P, useCallback as k, useEffect as M, useImperativeHandle as Ct } from "react";
|
|
4
|
+
function bt(s) {
|
|
5
5
|
if (s == null) throw new Error("Value must be a non nullable!");
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function Et(s) {
|
|
8
8
|
return s ? Object.fromEntries(
|
|
9
9
|
Object.entries(s).map(([t, e]) => t.startsWith("data") && t.length > 4 && t[4] === t[4].toUpperCase() ? [`data-${t.slice(4).replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()}`, e] : [t, e])
|
|
10
10
|
) : {};
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function Tt(...s) {
|
|
13
13
|
return s.filter(Boolean).join(" ") || void 0;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function Nt(...s) {
|
|
16
16
|
const t = Object.assign({}, ...s.filter(Boolean));
|
|
17
17
|
return Object.keys(t).length > 0 ? t : void 0;
|
|
18
18
|
}
|
|
19
|
-
var
|
|
20
|
-
const
|
|
19
|
+
var x = /* @__PURE__ */ ((s) => (s.UP = "ArrowUp", s.DOWN = "ArrowDown", s.LEFT = "ArrowLeft", s.RIGHT = "ArrowRight", s.END = "End", s.HOME = "Home", s.PAGE_DOWN = "PageDown", s.PAGE_UP = "PageUp", s.ENTER = "Enter", s.TAB = "Tab", s.SPACE = " ", s.BACKSPACE = "Backspace", s.DELETE = "Delete", s.COMMA = ",", s.ESC = "Escape", s))(x || {});
|
|
20
|
+
const It = "@", Pt = "@[__value__](__meta__)", y = {
|
|
21
21
|
Value: "__value__",
|
|
22
22
|
Meta: "__meta__",
|
|
23
23
|
Nested: "__nested__"
|
|
24
|
-
},
|
|
24
|
+
}, N = {
|
|
25
25
|
Value: "value",
|
|
26
26
|
Meta: "meta",
|
|
27
27
|
Nested: "nested"
|
|
28
28
|
};
|
|
29
|
-
function
|
|
30
|
-
const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } =
|
|
31
|
-
|
|
32
|
-
const i = r.value === 2, { segments: a, gapTypes:
|
|
29
|
+
function Mt(s, t) {
|
|
30
|
+
const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } = Lt(s);
|
|
31
|
+
At(r, s);
|
|
32
|
+
const i = r.value === 2, { segments: a, gapTypes: c } = i ? Ot(e, n, o) : { segments: e, gapTypes: n };
|
|
33
33
|
return {
|
|
34
34
|
markup: s,
|
|
35
35
|
index: t,
|
|
36
36
|
segments: a,
|
|
37
|
-
gapTypes:
|
|
37
|
+
gapTypes: c,
|
|
38
38
|
hasNested: r.nested === 1,
|
|
39
39
|
hasTwoValues: i,
|
|
40
40
|
segmentGlobalIndices: Array.from({ length: a.length })
|
|
41
41
|
// Will be populated by MarkupRegistry
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function Lt(s) {
|
|
45
45
|
const t = [], e = [], n = [], r = {
|
|
46
46
|
value: 0,
|
|
47
47
|
meta: 0,
|
|
48
48
|
nested: 0
|
|
49
|
-
}, o = [], i = [
|
|
50
|
-
for (const
|
|
51
|
-
const d =
|
|
52
|
-
let
|
|
53
|
-
for (;
|
|
54
|
-
o.push({ type:
|
|
55
|
-
}
|
|
56
|
-
o.sort((
|
|
49
|
+
}, o = [], i = [N.Value, N.Meta, N.Nested];
|
|
50
|
+
for (const l of i) {
|
|
51
|
+
const d = nt[l];
|
|
52
|
+
let g = s.indexOf(d);
|
|
53
|
+
for (; g !== -1; )
|
|
54
|
+
o.push({ type: l, position: g }), g = s.indexOf(d, g + d.length);
|
|
55
|
+
}
|
|
56
|
+
o.sort((l, d) => l.position - d.position);
|
|
57
57
|
let a = 0;
|
|
58
|
-
for (const
|
|
59
|
-
const d = s.substring(a,
|
|
60
|
-
d.length > 0 && t.push(d), e.push(
|
|
58
|
+
for (const l of o) {
|
|
59
|
+
const d = s.substring(a, l.position);
|
|
60
|
+
d.length > 0 && t.push(d), e.push(l.type), r[l.type]++, l.type === N.Value && n.push(e.length - 1), a = l.position + nt[l.type].length;
|
|
61
61
|
}
|
|
62
|
-
const
|
|
63
|
-
return
|
|
62
|
+
const c = s.substring(a);
|
|
63
|
+
return c.length > 0 && t.push(c), {
|
|
64
64
|
segments: t,
|
|
65
65
|
gapTypes: e,
|
|
66
66
|
counts: r,
|
|
67
67
|
valueGapIndices: n
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function At(s, t) {
|
|
71
71
|
const e = [
|
|
72
|
-
{ count: s.value, max: 2, name:
|
|
73
|
-
{ count: s.meta, max: 1, name:
|
|
74
|
-
{ count: s.nested, max: 1, name:
|
|
72
|
+
{ count: s.value, max: 2, name: y.Value },
|
|
73
|
+
{ count: s.meta, max: 1, name: y.Meta },
|
|
74
|
+
{ count: s.nested, max: 1, name: y.Nested }
|
|
75
75
|
];
|
|
76
76
|
for (const { count: n, max: r, name: o } of e)
|
|
77
77
|
if (n > r)
|
|
78
78
|
throw new Error(`Invalid markup: "${t}". Max ${r} "${o}" placeholders, got ${n}`);
|
|
79
79
|
if (s.value === 0 && s.nested === 0)
|
|
80
80
|
throw new Error(
|
|
81
|
-
`Invalid markup: "${t}". Need at least one "${
|
|
81
|
+
`Invalid markup: "${t}". Need at least one "${y.Value}" or "${y.Nested}"`
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
84
|
+
const nt = {
|
|
85
|
+
[N.Value]: y.Value,
|
|
86
|
+
[N.Meta]: y.Meta,
|
|
87
|
+
[N.Nested]: y.Nested
|
|
88
88
|
};
|
|
89
|
-
function
|
|
89
|
+
function Ot(s, t, e) {
|
|
90
90
|
if (e.length !== 2)
|
|
91
91
|
return { segments: s, gapTypes: t };
|
|
92
92
|
const [n, r] = e, o = [], i = s[n], a = s[n + 1];
|
|
93
|
-
i && a && o.push(
|
|
94
|
-
for (let
|
|
95
|
-
o.push(s[
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const d = t.filter((
|
|
93
|
+
i && a && o.push(g(i, a, s[n + 2]));
|
|
94
|
+
for (let u = n + 2; u < r; u++)
|
|
95
|
+
o.push(s[u]);
|
|
96
|
+
const c = s[r], l = s[r + 1];
|
|
97
|
+
c && l && o.push(g(c, l, s[r + 2]));
|
|
98
|
+
const d = t.filter((u) => u !== N.Value);
|
|
99
99
|
return { segments: o, gapTypes: d };
|
|
100
|
-
function u
|
|
101
|
-
if (!
|
|
102
|
-
const
|
|
103
|
-
return [
|
|
100
|
+
function g(u, h, v) {
|
|
101
|
+
if (!v) return [u, h, ""];
|
|
102
|
+
const C = v.charAt(0), m = C && !h.includes(C) && !v.startsWith(u) ? C : "";
|
|
103
|
+
return [u, h, m];
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
class
|
|
106
|
+
class Dt {
|
|
107
107
|
markups;
|
|
108
108
|
descriptors;
|
|
109
109
|
/** Deduplicated list of unique segment definitions (static strings or dynamic patterns) */
|
|
@@ -116,7 +116,7 @@ class kt {
|
|
|
116
116
|
this.descriptors = t.map((n, r) => {
|
|
117
117
|
if (n === void 0)
|
|
118
118
|
return null;
|
|
119
|
-
const o =
|
|
119
|
+
const o = Mt(n, r);
|
|
120
120
|
return o.segments.forEach((i, a) => {
|
|
121
121
|
this.processSegment(o, i, a, e);
|
|
122
122
|
}), this.addToFirstSegmentIndexMap(o), o;
|
|
@@ -137,8 +137,8 @@ class kt {
|
|
|
137
137
|
this.registerSegment(e, o, r);
|
|
138
138
|
const i = r.get(o);
|
|
139
139
|
if (t.segmentGlobalIndices[n] = i, typeof e != "string") {
|
|
140
|
-
const [a,
|
|
141
|
-
a && this.registerSegment(a, a, r),
|
|
140
|
+
const [a, c] = e;
|
|
141
|
+
a && this.registerSegment(a, a, r), c && this.registerSegment(c, c, r);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
registerSegment(t, e, n) {
|
|
@@ -160,7 +160,7 @@ class kt {
|
|
|
160
160
|
return e || n ? `${e}|${n}|${r}` : "";
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function lt(s, t) {
|
|
164
164
|
if (!t)
|
|
165
165
|
return s;
|
|
166
166
|
let e = 5381;
|
|
@@ -168,7 +168,7 @@ function Q(s, t) {
|
|
|
168
168
|
e = e * 33 ^ t.charCodeAt(n);
|
|
169
169
|
return e = e >>> 0, s * 1e6 + (e & 1048575);
|
|
170
170
|
}
|
|
171
|
-
class
|
|
171
|
+
class _t {
|
|
172
172
|
constructor(t, e) {
|
|
173
173
|
if (this.descriptor = t, this.expectedSegmentIndex = 1, this.start = e.start, this.end = e.end, t.segments.length === 1 && (this.expectedSegmentIndex = NaN, this.gaps.value = { start: this.start, end: this.end }), t.hasTwoValues && e.captured) {
|
|
174
174
|
this.captured = e.captured;
|
|
@@ -215,7 +215,7 @@ class wt {
|
|
|
215
215
|
const t = this.descriptor.segmentGlobalIndices[this.expectedSegmentIndex], e = this.descriptor.segments[this.expectedSegmentIndex];
|
|
216
216
|
if (typeof e == "object" && this.descriptor.hasTwoValues && this.captured && this.isAwaitingLastSegment) {
|
|
217
217
|
const [n, r] = e, o = n + this.captured + r;
|
|
218
|
-
return
|
|
218
|
+
return lt(t, o);
|
|
219
219
|
}
|
|
220
220
|
return t;
|
|
221
221
|
}
|
|
@@ -237,7 +237,7 @@ class wt {
|
|
|
237
237
|
return !t || this.start >= t.end ? !1 : !t.descriptor.hasNested || t.gaps.nested === void 0 ? !0 : !(this.start >= t.gaps.nested.start && this.end <= t.gaps.nested.end);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
class
|
|
240
|
+
class Rt {
|
|
241
241
|
constructor(t) {
|
|
242
242
|
this.registry = t;
|
|
243
243
|
}
|
|
@@ -266,7 +266,7 @@ class St {
|
|
|
266
266
|
}
|
|
267
267
|
tryStartNewStates(t) {
|
|
268
268
|
this.registry.firstSegmentIndexMap.get(t.index)?.forEach((e) => {
|
|
269
|
-
const n = new
|
|
269
|
+
const n = new _t(e, t);
|
|
270
270
|
if (!n.isInvalid) {
|
|
271
271
|
if (n.isCompleted) return this.addToCompleted(n);
|
|
272
272
|
this.addToWaiting(n);
|
|
@@ -278,7 +278,7 @@ class St {
|
|
|
278
278
|
* Uses value-specific index for dynamic segments, base index for static segments
|
|
279
279
|
*/
|
|
280
280
|
dequeueWaitingMatch(t) {
|
|
281
|
-
const e = t.captured ?
|
|
281
|
+
const e = t.captured ? lt(t.index, t.value) : t.index, n = this.completingStates.get(e);
|
|
282
282
|
if (n?.length) return n.pop();
|
|
283
283
|
const r = this.pendingStates.get(e);
|
|
284
284
|
if (r?.length) return r.pop();
|
|
@@ -311,12 +311,12 @@ class St {
|
|
|
311
311
|
n < this.completedStates.length && this.completedStates[n].position === e ? this.completedStates[n].match = t : this.completedStates.splice(n, 0, { position: e, match: t });
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
|
-
const
|
|
315
|
-
function
|
|
316
|
-
const n =
|
|
314
|
+
const A = (s) => s.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
|
|
315
|
+
function Vt(s, t, e) {
|
|
316
|
+
const n = A(s), r = A(t), o = A(t + e);
|
|
317
317
|
return `${n}([^${o}]+?)${r}`;
|
|
318
318
|
}
|
|
319
|
-
class
|
|
319
|
+
class $t {
|
|
320
320
|
staticRegex;
|
|
321
321
|
staticToIndex;
|
|
322
322
|
dynamicRegex;
|
|
@@ -330,25 +330,25 @@ class bt {
|
|
|
330
330
|
if (t.forEach((o, i) => {
|
|
331
331
|
typeof o == "string" ? (e.push(o), r.set(o, i)) : n.push(o);
|
|
332
332
|
}), e.length > 0) {
|
|
333
|
-
const i = [...e].sort((a,
|
|
333
|
+
const i = [...e].sort((a, c) => c.length - a.length).map(A);
|
|
334
334
|
this.staticRegex = new RegExp(`(?:${i.join("|")})`, "gu"), this.staticToIndex = r;
|
|
335
335
|
}
|
|
336
336
|
if (n.length > 0) {
|
|
337
337
|
const o = /* @__PURE__ */ new Set(), i = [];
|
|
338
338
|
n.forEach((a) => {
|
|
339
|
-
const
|
|
339
|
+
const c = t.indexOf(a);
|
|
340
340
|
if (typeof a == "string")
|
|
341
|
-
i.push({ index:
|
|
341
|
+
i.push({ index: c, pattern: A(a), definition: a });
|
|
342
342
|
else {
|
|
343
|
-
const [
|
|
344
|
-
o.add(
|
|
345
|
-
const
|
|
346
|
-
i.push({ index:
|
|
343
|
+
const [l, d, g] = a;
|
|
344
|
+
o.add(c);
|
|
345
|
+
const h = Vt(l, d, g).replace("(", `(?<content${c}>`);
|
|
346
|
+
i.push({ index: c, pattern: h, definition: a });
|
|
347
347
|
}
|
|
348
|
-
}), i.sort((a,
|
|
349
|
-
const
|
|
350
|
-
return (typeof
|
|
351
|
-
}), this.dynamicEntries = i, this.dynamicIndices = o, this.dynamicRegex = new RegExp(i.map((a,
|
|
348
|
+
}), i.sort((a, c) => {
|
|
349
|
+
const l = typeof a.definition == "string" ? a.definition.length : a.pattern.length;
|
|
350
|
+
return (typeof c.definition == "string" ? c.definition.length : c.pattern.length) - l;
|
|
351
|
+
}), this.dynamicEntries = i, this.dynamicIndices = o, this.dynamicRegex = new RegExp(i.map((a, c) => `(?<seg${c}>${a.pattern})`).join("|"), "gu");
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
search(t) {
|
|
@@ -366,20 +366,20 @@ class bt {
|
|
|
366
366
|
if (this.dynamicRegex && this.dynamicEntries && this.dynamicIndices)
|
|
367
367
|
for (const o of t.matchAll(this.dynamicRegex)) {
|
|
368
368
|
const i = o[0], a = o.index;
|
|
369
|
-
let
|
|
369
|
+
let c, l;
|
|
370
370
|
if (o.groups) {
|
|
371
371
|
for (let d = 0; d < this.dynamicEntries.length; d++)
|
|
372
372
|
if (o.groups[`seg${d}`] !== void 0) {
|
|
373
|
-
|
|
373
|
+
c = this.dynamicEntries[d].index, this.dynamicIndices.has(c) && (l = o.groups[`content${c}`]);
|
|
374
374
|
break;
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
|
-
|
|
378
|
-
index:
|
|
377
|
+
c !== void 0 && n.push({
|
|
378
|
+
index: c,
|
|
379
379
|
start: a,
|
|
380
380
|
end: a + i.length,
|
|
381
381
|
value: i,
|
|
382
|
-
captured:
|
|
382
|
+
captured: l
|
|
383
383
|
});
|
|
384
384
|
}
|
|
385
385
|
const r = [...n];
|
|
@@ -390,12 +390,12 @@ class bt {
|
|
|
390
390
|
return r.sort((o, i) => o.start - i.start), r;
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
const
|
|
393
|
+
const dt = (s, t = 0, e = s.length) => ({
|
|
394
394
|
type: "text",
|
|
395
395
|
content: s.substring(t, e),
|
|
396
396
|
position: { start: t, end: e }
|
|
397
397
|
});
|
|
398
|
-
class
|
|
398
|
+
class Ht {
|
|
399
399
|
// Instance fields - only what's needed for single pass
|
|
400
400
|
input;
|
|
401
401
|
// ===== PUBLIC API =====
|
|
@@ -432,30 +432,30 @@ class Et {
|
|
|
432
432
|
if (r && i.conflictsWith(r))
|
|
433
433
|
continue;
|
|
434
434
|
for (r = i; n.length > 0; ) {
|
|
435
|
-
const
|
|
435
|
+
const l = n[n.length - 1], d = this.getContentBounds(l.match);
|
|
436
436
|
if (d.end <= i.start)
|
|
437
|
-
this.finalizeParent(
|
|
437
|
+
this.finalizeParent(l, d.end), n.pop(), n.length > 0 ? n[n.length - 1].token.children.push(l.token) : e.push(l.token);
|
|
438
438
|
else
|
|
439
439
|
break;
|
|
440
440
|
}
|
|
441
441
|
const a = n.length > 0 ? n[n.length - 1] : null;
|
|
442
442
|
if (a) {
|
|
443
|
-
const
|
|
444
|
-
a.token.children.push(
|
|
443
|
+
const l = this.createTextToken(a.textPos, i.start);
|
|
444
|
+
a.token.children.push(l), a.textPos = i.end;
|
|
445
445
|
} else {
|
|
446
|
-
const
|
|
447
|
-
e.push(
|
|
446
|
+
const l = this.createTextToken(o, i.start);
|
|
447
|
+
e.push(l), o = i.end;
|
|
448
448
|
}
|
|
449
|
-
const
|
|
449
|
+
const c = this.createMarkToken(i);
|
|
450
450
|
if (this.hasNestedContent(i)) {
|
|
451
|
-
const
|
|
451
|
+
const l = this.getContentBounds(i);
|
|
452
452
|
n.push({
|
|
453
453
|
match: i,
|
|
454
|
-
token:
|
|
455
|
-
textPos:
|
|
454
|
+
token: c,
|
|
455
|
+
textPos: l.start
|
|
456
456
|
});
|
|
457
457
|
} else
|
|
458
|
-
a ? a.token.children.push(
|
|
458
|
+
a ? a.token.children.push(c) : e.push(c);
|
|
459
459
|
}
|
|
460
460
|
for (; n.length > 0; ) {
|
|
461
461
|
const i = n.pop(), a = this.getContentBounds(i.match);
|
|
@@ -514,7 +514,7 @@ class Et {
|
|
|
514
514
|
* Creates a text token for a range in the input
|
|
515
515
|
*/
|
|
516
516
|
createTextToken(t, e) {
|
|
517
|
-
return
|
|
517
|
+
return dt(this.input, t, e);
|
|
518
518
|
}
|
|
519
519
|
/**
|
|
520
520
|
* Creates nested info object if nested content exists
|
|
@@ -528,19 +528,19 @@ class Et {
|
|
|
528
528
|
};
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function j(s, t) {
|
|
532
532
|
let e = s;
|
|
533
|
-
return t.value !== void 0 && (e = e.replaceAll(
|
|
533
|
+
return t.value !== void 0 && (e = e.replaceAll(y.Value, t.value)), t.meta !== void 0 && (e = e.replaceAll(y.Meta, t.meta)), t.nested !== void 0 && (e = e.replaceAll(y.Nested, t.nested)), e;
|
|
534
534
|
}
|
|
535
|
-
function
|
|
535
|
+
function I(s) {
|
|
536
536
|
let t = "";
|
|
537
537
|
for (const e of s) {
|
|
538
538
|
if (e.type === "text") {
|
|
539
539
|
t += e.content;
|
|
540
540
|
continue;
|
|
541
541
|
}
|
|
542
|
-
const n = e.descriptor.markup, r = n.includes(
|
|
543
|
-
t +=
|
|
542
|
+
const n = e.descriptor.markup, r = n.includes(y.Nested) ? e.children.length > 0 ? I(e.children) : e.nested?.content : void 0;
|
|
543
|
+
t += j(n, {
|
|
544
544
|
value: e.value,
|
|
545
545
|
meta: e.meta,
|
|
546
546
|
nested: r
|
|
@@ -548,13 +548,13 @@ function y(s) {
|
|
|
548
548
|
}
|
|
549
549
|
return t;
|
|
550
550
|
}
|
|
551
|
-
function
|
|
551
|
+
function J(s, t) {
|
|
552
552
|
let e = "";
|
|
553
553
|
for (const n of s)
|
|
554
554
|
if (n.type === "text")
|
|
555
555
|
e += n.content;
|
|
556
556
|
else if (n.children.length > 0) {
|
|
557
|
-
const r =
|
|
557
|
+
const r = J(n.children, t), o = {
|
|
558
558
|
...n,
|
|
559
559
|
value: r
|
|
560
560
|
};
|
|
@@ -563,7 +563,7 @@ function H(s, t) {
|
|
|
563
563
|
e += t(n);
|
|
564
564
|
return e;
|
|
565
565
|
}
|
|
566
|
-
class
|
|
566
|
+
class B {
|
|
567
567
|
registry;
|
|
568
568
|
segmentMatcher;
|
|
569
569
|
patternMatcher;
|
|
@@ -588,7 +588,7 @@ class A {
|
|
|
588
588
|
* ```
|
|
589
589
|
*/
|
|
590
590
|
constructor(t) {
|
|
591
|
-
this.registry = new
|
|
591
|
+
this.registry = new Dt(t), this.segmentMatcher = new $t(this.registry.segments), this.patternMatcher = new Rt(this.registry), this.treeBuilder = new Ht();
|
|
592
592
|
}
|
|
593
593
|
/**
|
|
594
594
|
* Parses text into tokens (static convenience method)
|
|
@@ -606,7 +606,7 @@ class A {
|
|
|
606
606
|
*/
|
|
607
607
|
static parse(t, e) {
|
|
608
608
|
const n = e?.markup;
|
|
609
|
-
return !n || n.length === 0 ? [
|
|
609
|
+
return !n || n.length === 0 ? [dt(t)] : new B(n).parse(t);
|
|
610
610
|
}
|
|
611
611
|
/**
|
|
612
612
|
* Converts tokens back to text (static convenience method)
|
|
@@ -620,7 +620,7 @@ class A {
|
|
|
620
620
|
* ```
|
|
621
621
|
*/
|
|
622
622
|
static stringify(t) {
|
|
623
|
-
return
|
|
623
|
+
return I(t);
|
|
624
624
|
}
|
|
625
625
|
/**
|
|
626
626
|
* Parses text into a nested token tree
|
|
@@ -667,7 +667,7 @@ class A {
|
|
|
667
667
|
* ```
|
|
668
668
|
*/
|
|
669
669
|
stringify(t) {
|
|
670
|
-
return
|
|
670
|
+
return I(t);
|
|
671
671
|
}
|
|
672
672
|
/**
|
|
673
673
|
* Transforms annotated text by processing all mark tokens with a callback
|
|
@@ -696,7 +696,7 @@ class A {
|
|
|
696
696
|
*/
|
|
697
697
|
transform(t, e) {
|
|
698
698
|
const n = this.parse(t);
|
|
699
|
-
return
|
|
699
|
+
return J(n, e);
|
|
700
700
|
}
|
|
701
701
|
/**
|
|
702
702
|
* Escapes markup segments in the given text using backslash
|
|
@@ -738,21 +738,21 @@ class A {
|
|
|
738
738
|
return t.replaceAll(/\\(.)/g, "$1");
|
|
739
739
|
}
|
|
740
740
|
}
|
|
741
|
-
function
|
|
741
|
+
function Be(s, t, e) {
|
|
742
742
|
if (!e.length) return s;
|
|
743
|
-
const n = new
|
|
744
|
-
return
|
|
743
|
+
const n = new B(e).parse(s);
|
|
744
|
+
return J(n, t);
|
|
745
745
|
}
|
|
746
|
-
function
|
|
746
|
+
function z(s, t, e = 0, n) {
|
|
747
747
|
for (const r of s) {
|
|
748
748
|
if (r === t) return { depth: e, parent: n };
|
|
749
749
|
if (r.type === "mark") {
|
|
750
|
-
const o =
|
|
750
|
+
const o = z(r.children, t, e + 1, r);
|
|
751
751
|
if (o) return o;
|
|
752
752
|
}
|
|
753
753
|
}
|
|
754
754
|
}
|
|
755
|
-
function
|
|
755
|
+
function Bt(s = "", t = "") {
|
|
756
756
|
if (s === t) return {};
|
|
757
757
|
let e;
|
|
758
758
|
for (let r = 0; r < s.length; r++)
|
|
@@ -768,7 +768,7 @@ function Tt(s = "", t = "") {
|
|
|
768
768
|
}
|
|
769
769
|
return { left: e, right: n };
|
|
770
770
|
}
|
|
771
|
-
function
|
|
771
|
+
function st(s, t) {
|
|
772
772
|
let e = -1, n = s.length;
|
|
773
773
|
for (; n - e > 1; ) {
|
|
774
774
|
const r = Math.round((e + n) / 2);
|
|
@@ -776,53 +776,53 @@ function q(s, t) {
|
|
|
776
776
|
}
|
|
777
777
|
return s[e] == t && (n = e), [e, n].filter((r) => s[r] !== void 0);
|
|
778
778
|
}
|
|
779
|
-
function
|
|
779
|
+
function Ft(s) {
|
|
780
780
|
const { focus: t } = s.nodes, e = s.state.parser.get(), n = s.state.tokens.get();
|
|
781
781
|
if (!e)
|
|
782
782
|
return n;
|
|
783
783
|
const r = e.parse(t.content);
|
|
784
784
|
return r.length === 1 ? n : n.toSpliced(t.index, 1, ...r);
|
|
785
785
|
}
|
|
786
|
-
function
|
|
787
|
-
const t = s.state.value.get(), e =
|
|
786
|
+
function Wt(s) {
|
|
787
|
+
const t = s.state.value.get(), e = Gt(s), n = Bt(s.state.previousValue.get(), t);
|
|
788
788
|
if (!n.left && !n.right)
|
|
789
789
|
return s.state.previousValue.set(t), s.state.tokens.get();
|
|
790
790
|
s.state.previousValue.set(t);
|
|
791
791
|
const r = s.state.tokens.get();
|
|
792
792
|
switch (!0) {
|
|
793
793
|
case (n.left !== void 0 && e.includes(n.left) && n.right !== void 0 && Math.abs(n.left - n.right) > 1): {
|
|
794
|
-
const o = e.indexOf(n.left), i =
|
|
794
|
+
const o = e.indexOf(n.left), i = G(s, o - 1, o);
|
|
795
795
|
return r.toSpliced(o - 1, 2, ...i);
|
|
796
796
|
}
|
|
797
797
|
case n.left !== void 0: {
|
|
798
|
-
const [o] =
|
|
798
|
+
const [o] = st(e, n.left), i = G(s, o);
|
|
799
799
|
return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
|
|
800
800
|
}
|
|
801
801
|
case n.right !== void 0: {
|
|
802
|
-
const [o] =
|
|
802
|
+
const [o] = st(e, n.right), i = G(s, o);
|
|
803
803
|
return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
|
|
804
804
|
}
|
|
805
805
|
default:
|
|
806
|
-
return
|
|
806
|
+
return _(s, t ?? "");
|
|
807
807
|
}
|
|
808
808
|
}
|
|
809
|
-
function
|
|
809
|
+
function G(s, ...t) {
|
|
810
810
|
let e = "";
|
|
811
811
|
const n = s.state.tokens.get();
|
|
812
812
|
for (const r of t) {
|
|
813
813
|
const o = n[r];
|
|
814
814
|
e += o.content;
|
|
815
815
|
}
|
|
816
|
-
return
|
|
816
|
+
return _(s, e);
|
|
817
817
|
}
|
|
818
|
-
function
|
|
818
|
+
function Gt(s) {
|
|
819
819
|
let t = 0;
|
|
820
820
|
return s.state.tokens.get().map((n) => {
|
|
821
821
|
const r = n.content.length;
|
|
822
822
|
return t += r, t - r;
|
|
823
823
|
}) ?? [];
|
|
824
824
|
}
|
|
825
|
-
function
|
|
825
|
+
function _(s, t) {
|
|
826
826
|
const e = s.state.parser.get();
|
|
827
827
|
return e ? e.parse(t) : [
|
|
828
828
|
{
|
|
@@ -832,16 +832,16 @@ function P(s, t) {
|
|
|
832
832
|
}
|
|
833
833
|
];
|
|
834
834
|
}
|
|
835
|
-
const
|
|
836
|
-
class
|
|
835
|
+
const Ut = (s, t) => s === t;
|
|
836
|
+
class R {
|
|
837
837
|
#t;
|
|
838
838
|
#e = /* @__PURE__ */ new Set();
|
|
839
839
|
#n;
|
|
840
840
|
constructor(t, e) {
|
|
841
|
-
this.#t = t, this.#n = e?.equals ??
|
|
841
|
+
this.#t = t, this.#n = e?.equals ?? Ut;
|
|
842
842
|
}
|
|
843
843
|
static event() {
|
|
844
|
-
return new
|
|
844
|
+
return new R(void 0, { equals: !1 });
|
|
845
845
|
}
|
|
846
846
|
get value() {
|
|
847
847
|
return this.#t;
|
|
@@ -862,14 +862,14 @@ class I {
|
|
|
862
862
|
this.value = t;
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
|
-
function
|
|
865
|
+
function jt(s, t) {
|
|
866
866
|
const e = {};
|
|
867
867
|
return e.get = () => s.get(), e.set = (n) => s.set(n), e.on = (n) => s.on(n), e.use = t(e), e;
|
|
868
868
|
}
|
|
869
|
-
function
|
|
869
|
+
function zt(s, t) {
|
|
870
870
|
const e = /* @__PURE__ */ new Map();
|
|
871
871
|
for (const n in s)
|
|
872
|
-
e.set(n, new
|
|
872
|
+
e.set(n, new R(s[n]));
|
|
873
873
|
return new Proxy(s, {
|
|
874
874
|
get(n, r) {
|
|
875
875
|
if (r === "set")
|
|
@@ -879,35 +879,35 @@ function At(s, t) {
|
|
|
879
879
|
};
|
|
880
880
|
const o = e.get(r);
|
|
881
881
|
if (o)
|
|
882
|
-
return
|
|
882
|
+
return jt(o, t);
|
|
883
883
|
}
|
|
884
884
|
});
|
|
885
885
|
}
|
|
886
|
-
function
|
|
886
|
+
function qt(s) {
|
|
887
887
|
const t = function(e) {
|
|
888
888
|
s.emit(e);
|
|
889
889
|
};
|
|
890
890
|
return t.on = (e) => s.on(e), t;
|
|
891
891
|
}
|
|
892
|
-
function
|
|
892
|
+
function Xt(s) {
|
|
893
893
|
const t = [], e = /* @__PURE__ */ new Map();
|
|
894
894
|
for (const n of t)
|
|
895
|
-
e.set(n,
|
|
895
|
+
e.set(n, R.event());
|
|
896
896
|
return new Proxy({}, {
|
|
897
897
|
get(n, r) {
|
|
898
898
|
let o = e.get(r);
|
|
899
|
-
return o || (o =
|
|
899
|
+
return o || (o = R.event(), e.set(r, o)), qt(o);
|
|
900
900
|
}
|
|
901
901
|
});
|
|
902
902
|
}
|
|
903
|
-
class
|
|
903
|
+
class Zt {
|
|
904
904
|
#t = 1;
|
|
905
905
|
#e = /* @__PURE__ */ new WeakMap();
|
|
906
906
|
get(t) {
|
|
907
907
|
return this.#e.has(t) ? this.#e.get(t) : (this.#e.set(t, this.#t), this.#t++);
|
|
908
908
|
}
|
|
909
909
|
}
|
|
910
|
-
class
|
|
910
|
+
class w {
|
|
911
911
|
static get isSelectedPosition() {
|
|
912
912
|
const t = window.getSelection();
|
|
913
913
|
if (t)
|
|
@@ -968,14 +968,14 @@ class m {
|
|
|
968
968
|
r?.setStart(r.endContainer, e), r?.setEnd(r.endContainer, e);
|
|
969
969
|
}
|
|
970
970
|
}
|
|
971
|
-
const
|
|
972
|
-
class
|
|
971
|
+
const Jt = new RegExp(/^\w*/);
|
|
972
|
+
class Q {
|
|
973
973
|
span;
|
|
974
974
|
node;
|
|
975
975
|
dividedText;
|
|
976
976
|
constructor() {
|
|
977
|
-
const t =
|
|
978
|
-
this.node =
|
|
977
|
+
const t = w.getCurrentPosition();
|
|
978
|
+
this.node = w.getSelectedNode(), this.span = w.getFocusedSpan(), this.dividedText = this.getDividedTextBy(t);
|
|
979
979
|
}
|
|
980
980
|
/**
|
|
981
981
|
* Find overlay match in text using provided options and trigger extractor.
|
|
@@ -993,8 +993,8 @@ class F {
|
|
|
993
993
|
* TriggerFinder.find(vueOptions, (opt) => opt.overlay?.trigger ?? '@')
|
|
994
994
|
*/
|
|
995
995
|
static find(t, e) {
|
|
996
|
-
if (t &&
|
|
997
|
-
return new
|
|
996
|
+
if (t && w.isSelectedPosition)
|
|
997
|
+
return new Q().find(t, e);
|
|
998
998
|
}
|
|
999
999
|
getDividedTextBy(t) {
|
|
1000
1000
|
return { left: this.span.slice(0, t), right: this.span.slice(t) };
|
|
@@ -1032,7 +1032,7 @@ class F {
|
|
|
1032
1032
|
}
|
|
1033
1033
|
matchRightPart() {
|
|
1034
1034
|
const { right: t } = this.dividedText;
|
|
1035
|
-
return { word: t.match(
|
|
1035
|
+
return { word: t.match(Jt)?.[0] };
|
|
1036
1036
|
}
|
|
1037
1037
|
matchLeftPart(t) {
|
|
1038
1038
|
const e = this.makeTriggerRegex(t), { left: n } = this.dividedText, r = n.match(e);
|
|
@@ -1042,11 +1042,11 @@ class F {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
//TODO new overlayMatch option if (isSpaceBeforeRequired) append space check for not first words '\\s'
|
|
1044
1044
|
makeTriggerRegex(t) {
|
|
1045
|
-
const e =
|
|
1045
|
+
const e = A(t) + "(\\w*)$";
|
|
1046
1046
|
return new RegExp(e);
|
|
1047
1047
|
}
|
|
1048
1048
|
}
|
|
1049
|
-
class
|
|
1049
|
+
class V {
|
|
1050
1050
|
#t;
|
|
1051
1051
|
#e;
|
|
1052
1052
|
get target() {
|
|
@@ -1056,10 +1056,10 @@ class M {
|
|
|
1056
1056
|
this.#t = t;
|
|
1057
1057
|
}
|
|
1058
1058
|
get next() {
|
|
1059
|
-
return new
|
|
1059
|
+
return new V(this.target?.nextSibling, this.#e);
|
|
1060
1060
|
}
|
|
1061
1061
|
get prev() {
|
|
1062
|
-
return new
|
|
1062
|
+
return new V(this.target?.previousSibling, this.#e);
|
|
1063
1063
|
}
|
|
1064
1064
|
get isSpan() {
|
|
1065
1065
|
return this.index % 2 === 0;
|
|
@@ -1071,19 +1071,19 @@ class M {
|
|
|
1071
1071
|
return this.target?.isContentEditable ?? !1;
|
|
1072
1072
|
}
|
|
1073
1073
|
get isCaretAtBeginning() {
|
|
1074
|
-
return this.target ?
|
|
1074
|
+
return this.target ? w.getCaretIndex(this.target) === 0 : void 0;
|
|
1075
1075
|
}
|
|
1076
1076
|
get isCaretAtEnd() {
|
|
1077
|
-
return this.target ?
|
|
1077
|
+
return this.target ? w.getCaretIndex(this.target) === this.target.textContent?.length : void 0;
|
|
1078
1078
|
}
|
|
1079
1079
|
get index() {
|
|
1080
1080
|
return this.target?.parentElement ? [...this.target.parentElement.children].indexOf(this.target) : -1;
|
|
1081
1081
|
}
|
|
1082
1082
|
get caret() {
|
|
1083
|
-
return this.target ?
|
|
1083
|
+
return this.target ? w.getCaretIndex(this.target) : -1;
|
|
1084
1084
|
}
|
|
1085
1085
|
set caret(t) {
|
|
1086
|
-
this.target &&
|
|
1086
|
+
this.target && w.trySetIndex(this.target, t);
|
|
1087
1087
|
}
|
|
1088
1088
|
get length() {
|
|
1089
1089
|
return this.target?.textContent?.length ?? -1;
|
|
@@ -1107,7 +1107,7 @@ class M {
|
|
|
1107
1107
|
this.target = t, this.#e = e;
|
|
1108
1108
|
}
|
|
1109
1109
|
setCaretToEnd() {
|
|
1110
|
-
|
|
1110
|
+
w.setCaretToEnd(this.target);
|
|
1111
1111
|
}
|
|
1112
1112
|
focus() {
|
|
1113
1113
|
this.target?.focus();
|
|
@@ -1116,19 +1116,19 @@ class M {
|
|
|
1116
1116
|
this.target = void 0;
|
|
1117
1117
|
}
|
|
1118
1118
|
}
|
|
1119
|
-
function
|
|
1119
|
+
function Qt(s, t, e, n) {
|
|
1120
1120
|
return s.slice(0, e) + t + s.slice(e + n.length);
|
|
1121
1121
|
}
|
|
1122
|
-
function
|
|
1122
|
+
function U(s, t) {
|
|
1123
1123
|
const n = {
|
|
1124
1124
|
prev: 2,
|
|
1125
1125
|
self: 1,
|
|
1126
1126
|
next: 0
|
|
1127
|
-
}[s], { focus: r } = t.nodes, o = t.state.tokens.get(), [i, , a] = o.splice(r.index - n, 3),
|
|
1127
|
+
}[s], { focus: r } = t.nodes, o = t.state.tokens.get(), [i, , a] = o.splice(r.index - n, 3), c = (i.type === "text", i.content), l = (a.type === "text", a.content);
|
|
1128
1128
|
t.state.tokens.set(
|
|
1129
1129
|
o.toSpliced(r.index - n, 0, {
|
|
1130
1130
|
type: "text",
|
|
1131
|
-
content:
|
|
1131
|
+
content: c + l,
|
|
1132
1132
|
position: {
|
|
1133
1133
|
start: i.position.start,
|
|
1134
1134
|
end: a.position.end
|
|
@@ -1136,12 +1136,12 @@ function _(s, t) {
|
|
|
1136
1136
|
})
|
|
1137
1137
|
);
|
|
1138
1138
|
let d = r;
|
|
1139
|
-
for (let
|
|
1139
|
+
for (let u = 0; u < n; u++)
|
|
1140
1140
|
d = d.prev;
|
|
1141
|
-
const
|
|
1142
|
-
t.state.recovery.set({ anchor: d.prev, caret:
|
|
1141
|
+
const g = d.length;
|
|
1142
|
+
t.state.recovery.set({ anchor: d.prev, caret: g }), t.state.onChange.get()?.(I(t.state.tokens.get()));
|
|
1143
1143
|
}
|
|
1144
|
-
class
|
|
1144
|
+
class Kt {
|
|
1145
1145
|
constructor(t) {
|
|
1146
1146
|
this.store = t;
|
|
1147
1147
|
}
|
|
@@ -1153,33 +1153,33 @@ class Dt {
|
|
|
1153
1153
|
const t = this.store.state.onChange.get();
|
|
1154
1154
|
if (!this.store.nodes.focus.target) return;
|
|
1155
1155
|
const e = this.store.state.tokens.get(), n = e[this.store.nodes.focus.index];
|
|
1156
|
-
n.type === "text" ? n.content = this.store.nodes.focus.content : n.type === "mark" && (n.value = this.store.nodes.focus.content), t?.(
|
|
1156
|
+
n.type === "text" ? n.content = this.store.nodes.focus.content : n.type === "mark" && (n.value = this.store.nodes.focus.content), t?.(I(e)), this.store.events.parse();
|
|
1157
1157
|
}), this.#e = this.store.events.delete.on((t) => {
|
|
1158
1158
|
if (!t) return;
|
|
1159
1159
|
const { token: e } = t, n = this.store.state.onChange.get(), r = this.store.state.tokens.get(), o = r.indexOf(e);
|
|
1160
|
-
this.store.state.tokens.set(r.toSpliced(o, 1)), n?.(
|
|
1160
|
+
this.store.state.tokens.set(r.toSpliced(o, 1)), n?.(I(this.store.state.tokens.get()));
|
|
1161
1161
|
}), this.#n = this.store.events.select.on((t) => {
|
|
1162
1162
|
if (!t) return;
|
|
1163
1163
|
const e = this.store.state.Mark.get(), n = this.store.state.onChange.get(), {
|
|
1164
1164
|
mark: r,
|
|
1165
|
-
match: { option: o, span: i, index: a, source:
|
|
1166
|
-
} = t,
|
|
1165
|
+
match: { option: o, span: i, index: a, source: c }
|
|
1166
|
+
} = t, l = r.type === "mark" ? j(o.markup, {
|
|
1167
1167
|
value: r.value,
|
|
1168
1168
|
meta: r.meta
|
|
1169
|
-
}) :
|
|
1169
|
+
}) : j(o.markup, {
|
|
1170
1170
|
value: r.content
|
|
1171
|
-
}), d =
|
|
1171
|
+
}), d = Qt(i, l, a, c);
|
|
1172
1172
|
if (this.store.state.recovery.set(
|
|
1173
1173
|
e ? {
|
|
1174
1174
|
caret: 0,
|
|
1175
1175
|
anchor: this.store.nodes.input.next,
|
|
1176
1176
|
isNext: !0,
|
|
1177
1177
|
childIndex: this.store.nodes.input.index
|
|
1178
|
-
} : { caret: a +
|
|
1178
|
+
} : { caret: a + l.length, anchor: this.store.nodes.input }
|
|
1179
1179
|
), this.store.nodes.input.target) {
|
|
1180
1180
|
this.store.nodes.input.content = d;
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1181
|
+
const g = this.store.state.tokens.get(), u = g[this.store.nodes.input.index];
|
|
1182
|
+
u.type === "text" && (u.content = d), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(I(g)), this.store.events.parse();
|
|
1183
1183
|
}
|
|
1184
1184
|
}));
|
|
1185
1185
|
}
|
|
@@ -1187,7 +1187,7 @@ class Dt {
|
|
|
1187
1187
|
this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0;
|
|
1188
1188
|
}
|
|
1189
1189
|
}
|
|
1190
|
-
class
|
|
1190
|
+
class Yt {
|
|
1191
1191
|
constructor(t) {
|
|
1192
1192
|
this.store = t;
|
|
1193
1193
|
}
|
|
@@ -1204,7 +1204,7 @@ class Ht {
|
|
|
1204
1204
|
this.#t = this.store.events.clearOverlay.on(() => {
|
|
1205
1205
|
e(void 0);
|
|
1206
1206
|
}), this.#e = this.store.events.checkOverlay.on(() => {
|
|
1207
|
-
const r =
|
|
1207
|
+
const r = Q.find(this.store.state.options.get(), t);
|
|
1208
1208
|
e(r);
|
|
1209
1209
|
}), this.#n = this.store.events.change.on(() => {
|
|
1210
1210
|
const r = this.store.state.showOverlayOn.get(), o = "change";
|
|
@@ -1222,7 +1222,7 @@ class Ht {
|
|
|
1222
1222
|
}
|
|
1223
1223
|
enableClose() {
|
|
1224
1224
|
this.#i || (this.#i = (t) => {
|
|
1225
|
-
t.key ===
|
|
1225
|
+
t.key === x.ESC && this.store.events.clearOverlay();
|
|
1226
1226
|
}, this.#a = (t) => {
|
|
1227
1227
|
const e = t.target;
|
|
1228
1228
|
this.store.refs.overlay?.contains(e) || this.store.refs.container?.contains(e) || this.store.events.clearOverlay();
|
|
@@ -1236,7 +1236,7 @@ class Ht {
|
|
|
1236
1236
|
t && this.#r && (t.removeEventListener("focusin", this.#r), t.removeEventListener("focusout", this.#o)), this.#s && document.removeEventListener("selectionchange", this.#s), this.disableClose(), this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0, this.#s = void 0, this.#r = void 0, this.#o = void 0;
|
|
1237
1237
|
}
|
|
1238
1238
|
}
|
|
1239
|
-
class
|
|
1239
|
+
class te {
|
|
1240
1240
|
constructor(t) {
|
|
1241
1241
|
this.store = t;
|
|
1242
1242
|
}
|
|
@@ -1281,7 +1281,7 @@ class Ft {
|
|
|
1281
1281
|
this.store.nodes.focus.caret = n, this.store.state.recovery.set(void 0);
|
|
1282
1282
|
}
|
|
1283
1283
|
}
|
|
1284
|
-
class
|
|
1284
|
+
class ee {
|
|
1285
1285
|
constructor(t) {
|
|
1286
1286
|
this.store = t;
|
|
1287
1287
|
}
|
|
@@ -1309,7 +1309,7 @@ class Ut {
|
|
|
1309
1309
|
this.#t && (document.removeEventListener("mousedown", this.#t), document.removeEventListener("mousemove", this.#e), document.removeEventListener("mouseup", this.#n), document.removeEventListener("selectionchange", this.#s), this.#t = void 0, this.#e = void 0, this.#n = void 0, this.#s = void 0), this.#r = null, this.#o = !1;
|
|
1310
1310
|
}
|
|
1311
1311
|
}
|
|
1312
|
-
function
|
|
1312
|
+
function ne(s, t) {
|
|
1313
1313
|
if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
|
|
1314
1314
|
t.preventDefault();
|
|
1315
1315
|
const e = window.getSelection(), n = s.refs.container?.firstChild, r = s.refs.container?.lastChild;
|
|
@@ -1317,7 +1317,7 @@ function Wt(s, t) {
|
|
|
1317
1317
|
e.setBaseAndExtent(n, 0, r, 1), s.state.selecting.set("all");
|
|
1318
1318
|
}
|
|
1319
1319
|
}
|
|
1320
|
-
function
|
|
1320
|
+
function se(s, t) {
|
|
1321
1321
|
const { focus: e } = s.nodes;
|
|
1322
1322
|
if (e.isMark && !e.isEditable || e.isCaretAtBeginning) {
|
|
1323
1323
|
const n = e.prev;
|
|
@@ -1325,7 +1325,7 @@ function Gt(s, t) {
|
|
|
1325
1325
|
}
|
|
1326
1326
|
return !1;
|
|
1327
1327
|
}
|
|
1328
|
-
function
|
|
1328
|
+
function re(s, t) {
|
|
1329
1329
|
const { focus: e } = s.nodes;
|
|
1330
1330
|
if (e.isMark && !e.isEditable || e.isCaretAtEnd) {
|
|
1331
1331
|
const n = e.next;
|
|
@@ -1333,7 +1333,7 @@ function Bt(s, t) {
|
|
|
1333
1333
|
}
|
|
1334
1334
|
return !1;
|
|
1335
1335
|
}
|
|
1336
|
-
class
|
|
1336
|
+
class oe {
|
|
1337
1337
|
constructor(t) {
|
|
1338
1338
|
this.store = t;
|
|
1339
1339
|
}
|
|
@@ -1344,11 +1344,11 @@ class jt {
|
|
|
1344
1344
|
if (this.#t) return;
|
|
1345
1345
|
const t = this.store.refs.container;
|
|
1346
1346
|
t && (this.#t = (e) => {
|
|
1347
|
-
e.key ===
|
|
1347
|
+
e.key === x.LEFT ? se(this.store, e) : e.key === x.RIGHT && re(this.store, e), this.#s(e), ne(this.store, e);
|
|
1348
1348
|
}, this.#e = (e) => {
|
|
1349
|
-
|
|
1349
|
+
ae(this.store, e);
|
|
1350
1350
|
}, this.#n = (e) => {
|
|
1351
|
-
|
|
1351
|
+
ie(this.store, e);
|
|
1352
1352
|
}, t.addEventListener("keydown", this.#t), t.addEventListener("paste", this.#e), t.addEventListener("beforeinput", this.#n, !0));
|
|
1353
1353
|
}
|
|
1354
1354
|
disable() {
|
|
@@ -1357,37 +1357,37 @@ class jt {
|
|
|
1357
1357
|
}
|
|
1358
1358
|
#s(t) {
|
|
1359
1359
|
const { focus: e } = this.store.nodes;
|
|
1360
|
-
if (t.key ===
|
|
1360
|
+
if (t.key === x.DELETE || t.key === x.BACKSPACE) {
|
|
1361
1361
|
if (e.isMark) {
|
|
1362
|
-
t.preventDefault(),
|
|
1362
|
+
t.preventDefault(), U("self", this.store);
|
|
1363
1363
|
return;
|
|
1364
1364
|
}
|
|
1365
|
-
t.key ===
|
|
1365
|
+
t.key === x.BACKSPACE && e.isSpan && e.isCaretAtBeginning && e.prev.target && (t.preventDefault(), U("prev", this.store)), t.key === x.DELETE && e.isSpan && e.isCaretAtEnd && e.next.target && (t.preventDefault(), U("next", this.store));
|
|
1366
1366
|
}
|
|
1367
1367
|
}
|
|
1368
1368
|
}
|
|
1369
|
-
function
|
|
1369
|
+
function ie(s, t) {
|
|
1370
1370
|
const e = s.state.selecting.get();
|
|
1371
|
-
if (e !== "all" || !
|
|
1371
|
+
if (e !== "all" || !ut(s)) {
|
|
1372
1372
|
e === "all" && s.state.selecting.set(void 0);
|
|
1373
1373
|
return;
|
|
1374
1374
|
}
|
|
1375
1375
|
if (t.inputType === "insertFromPaste") return;
|
|
1376
1376
|
t.preventDefault();
|
|
1377
1377
|
const n = t.inputType.startsWith("delete") ? "" : t.data ?? "";
|
|
1378
|
-
|
|
1378
|
+
ht(s, n);
|
|
1379
1379
|
}
|
|
1380
|
-
function
|
|
1380
|
+
function ae(s, t) {
|
|
1381
1381
|
const e = s.state.selecting.get();
|
|
1382
|
-
if (e !== "all" || !
|
|
1382
|
+
if (e !== "all" || !ut(s)) {
|
|
1383
1383
|
e === "all" && s.state.selecting.set(void 0);
|
|
1384
1384
|
return;
|
|
1385
1385
|
}
|
|
1386
1386
|
t.preventDefault();
|
|
1387
1387
|
const n = t.clipboardData?.getData("text/plain") ?? "";
|
|
1388
|
-
|
|
1388
|
+
ht(s, n);
|
|
1389
1389
|
}
|
|
1390
|
-
function
|
|
1390
|
+
function ut(s) {
|
|
1391
1391
|
const t = window.getSelection(), e = s.refs.container;
|
|
1392
1392
|
if (!t?.rangeCount || !e?.firstChild || !e?.lastChild) return !1;
|
|
1393
1393
|
try {
|
|
@@ -1397,7 +1397,7 @@ function Y(s) {
|
|
|
1397
1397
|
return !1;
|
|
1398
1398
|
}
|
|
1399
1399
|
}
|
|
1400
|
-
function
|
|
1400
|
+
function ht(s, t) {
|
|
1401
1401
|
s.nodes.focus.target = null, s.state.selecting.set(void 0), s.state.onChange.get()?.(t), s.state.value.get() === void 0 && s.state.tokens.set(
|
|
1402
1402
|
s.state.parser.get()?.parse(t) ?? [
|
|
1403
1403
|
{
|
|
@@ -1414,7 +1414,7 @@ function tt(s, t) {
|
|
|
1414
1414
|
}), e.focus());
|
|
1415
1415
|
});
|
|
1416
1416
|
}
|
|
1417
|
-
class
|
|
1417
|
+
class ce {
|
|
1418
1418
|
#t = [];
|
|
1419
1419
|
#e = !1;
|
|
1420
1420
|
register(t) {
|
|
@@ -1427,22 +1427,22 @@ class Xt {
|
|
|
1427
1427
|
this.#e && (this.#e = !1, this.#t.forEach((t) => t.disable()));
|
|
1428
1428
|
}
|
|
1429
1429
|
}
|
|
1430
|
-
const
|
|
1430
|
+
const $ = (s, t) => ({
|
|
1431
1431
|
name: s,
|
|
1432
1432
|
enable: () => t.enable(),
|
|
1433
1433
|
disable: () => t.disable()
|
|
1434
|
-
}),
|
|
1435
|
-
const t = new
|
|
1436
|
-
return t.register(
|
|
1434
|
+
}), le = (s) => {
|
|
1435
|
+
const t = new ce();
|
|
1436
|
+
return t.register($("keydown", s.controllers.keydown)).register($("system", s.controllers.system)).register($("focus", s.controllers.focus)).register($("textSelection", s.controllers.textSelection)), t;
|
|
1437
1437
|
};
|
|
1438
|
-
class
|
|
1438
|
+
class de {
|
|
1439
1439
|
constructor(t) {
|
|
1440
1440
|
this.store = t;
|
|
1441
1441
|
}
|
|
1442
1442
|
#t = [];
|
|
1443
1443
|
#e = !1;
|
|
1444
1444
|
enable(t) {
|
|
1445
|
-
const { store: e } = this, n =
|
|
1445
|
+
const { store: e } = this, n = le(e);
|
|
1446
1446
|
n.enableAll(), this.#t.push(() => n.disableAll()), this.#s(), this.#n(), t?.getTrigger && this.#r(t.getTrigger);
|
|
1447
1447
|
}
|
|
1448
1448
|
disable() {
|
|
@@ -1457,12 +1457,12 @@ class Jt {
|
|
|
1457
1457
|
*/
|
|
1458
1458
|
syncParser(t, e) {
|
|
1459
1459
|
const { store: n } = this, r = e?.map((i) => i.markup);
|
|
1460
|
-
if (r && r.some(Boolean) ? n.state.parser.set(new
|
|
1460
|
+
if (r && r.some(Boolean) ? n.state.parser.set(new B(r)) : n.state.parser.set(void 0), this.#e) {
|
|
1461
1461
|
n.state.recovery.get() || n.events.parse();
|
|
1462
1462
|
return;
|
|
1463
1463
|
}
|
|
1464
1464
|
const o = t ?? n.state.defaultValue.get() ?? "";
|
|
1465
|
-
n.state.tokens.set(
|
|
1465
|
+
n.state.tokens.set(_(n, o)), this.#e = !0;
|
|
1466
1466
|
}
|
|
1467
1467
|
/**
|
|
1468
1468
|
* Recovers focus after tokens change.
|
|
@@ -1483,11 +1483,11 @@ class Jt {
|
|
|
1483
1483
|
this.#t.push(
|
|
1484
1484
|
t.events.parse.on(() => {
|
|
1485
1485
|
if (t.state.recovery.get()) {
|
|
1486
|
-
const e =
|
|
1487
|
-
t.state.tokens.set(
|
|
1486
|
+
const e = I(t.state.tokens.get());
|
|
1487
|
+
t.state.tokens.set(_(t, e)), t.state.previousValue.set(e);
|
|
1488
1488
|
return;
|
|
1489
1489
|
}
|
|
1490
|
-
t.state.tokens.set(t.nodes.focus.target ?
|
|
1490
|
+
t.state.tokens.set(t.nodes.focus.target ? Ft(t) : Wt(t));
|
|
1491
1491
|
})
|
|
1492
1492
|
);
|
|
1493
1493
|
}
|
|
@@ -1500,28 +1500,28 @@ class Jt {
|
|
|
1500
1500
|
);
|
|
1501
1501
|
}
|
|
1502
1502
|
}
|
|
1503
|
-
class
|
|
1504
|
-
key = new
|
|
1503
|
+
class ue {
|
|
1504
|
+
key = new Zt();
|
|
1505
1505
|
nodes = {
|
|
1506
|
-
focus: new
|
|
1507
|
-
input: new
|
|
1506
|
+
focus: new V(void 0, this),
|
|
1507
|
+
input: new V(void 0, this)
|
|
1508
1508
|
};
|
|
1509
1509
|
state;
|
|
1510
|
-
events =
|
|
1510
|
+
events = Xt();
|
|
1511
1511
|
refs = {
|
|
1512
1512
|
container: null,
|
|
1513
1513
|
overlay: null
|
|
1514
1514
|
};
|
|
1515
1515
|
controllers = {
|
|
1516
|
-
overlay: new
|
|
1517
|
-
focus: new
|
|
1518
|
-
keydown: new
|
|
1519
|
-
system: new
|
|
1520
|
-
textSelection: new
|
|
1516
|
+
overlay: new Yt(this),
|
|
1517
|
+
focus: new te(this),
|
|
1518
|
+
keydown: new oe(this),
|
|
1519
|
+
system: new Kt(this),
|
|
1520
|
+
textSelection: new ee(this)
|
|
1521
1521
|
};
|
|
1522
|
-
lifecycle = new
|
|
1522
|
+
lifecycle = new de(this);
|
|
1523
1523
|
constructor(t) {
|
|
1524
|
-
this.state =
|
|
1524
|
+
this.state = zt(
|
|
1525
1525
|
{
|
|
1526
1526
|
tokens: [],
|
|
1527
1527
|
parser: void 0,
|
|
@@ -1560,7 +1560,7 @@ class Qt {
|
|
|
1560
1560
|
};
|
|
1561
1561
|
}
|
|
1562
1562
|
}
|
|
1563
|
-
class
|
|
1563
|
+
class he {
|
|
1564
1564
|
ref;
|
|
1565
1565
|
#t;
|
|
1566
1566
|
#e;
|
|
@@ -1593,13 +1593,13 @@ class Kt {
|
|
|
1593
1593
|
this.#e.meta = t, this.#s();
|
|
1594
1594
|
}
|
|
1595
1595
|
get depth() {
|
|
1596
|
-
return
|
|
1596
|
+
return z(this.#t.state.tokens.get(), this.#e).depth;
|
|
1597
1597
|
}
|
|
1598
1598
|
get hasChildren() {
|
|
1599
1599
|
return this.#e.children.length > 0;
|
|
1600
1600
|
}
|
|
1601
1601
|
get parent() {
|
|
1602
|
-
return
|
|
1602
|
+
return z(this.#t.state.tokens.get(), this.#e)?.parent;
|
|
1603
1603
|
}
|
|
1604
1604
|
get tokens() {
|
|
1605
1605
|
return this.#e.children;
|
|
@@ -1612,57 +1612,192 @@ class Kt {
|
|
|
1612
1612
|
this.#t.events.change();
|
|
1613
1613
|
}
|
|
1614
1614
|
}
|
|
1615
|
-
|
|
1615
|
+
let ft = 0;
|
|
1616
|
+
function rt(s) {
|
|
1617
|
+
return `block-${ft++}-${s}`;
|
|
1618
|
+
}
|
|
1619
|
+
function fe() {
|
|
1620
|
+
ft = 0;
|
|
1621
|
+
}
|
|
1622
|
+
function ge(s) {
|
|
1623
|
+
if (s.length === 0) return [];
|
|
1624
|
+
fe();
|
|
1625
|
+
const t = [];
|
|
1626
|
+
let e = [], n = -1;
|
|
1627
|
+
const r = (o) => {
|
|
1628
|
+
e.length !== 0 && (t.push({
|
|
1629
|
+
id: rt(n),
|
|
1630
|
+
tokens: [...e],
|
|
1631
|
+
startPos: n,
|
|
1632
|
+
endPos: o
|
|
1633
|
+
}), e = [], n = -1);
|
|
1634
|
+
};
|
|
1635
|
+
for (const o of s) {
|
|
1636
|
+
if (o.type === "mark") {
|
|
1637
|
+
o.content.endsWith(`
|
|
1638
|
+
`) ? (r(o.position.start), t.push({
|
|
1639
|
+
id: rt(o.position.start),
|
|
1640
|
+
tokens: [o],
|
|
1641
|
+
startPos: o.position.start,
|
|
1642
|
+
endPos: o.position.end
|
|
1643
|
+
})) : (n === -1 && (n = o.position.start), e.push(o));
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1646
|
+
if (o.type !== "text") continue;
|
|
1647
|
+
const a = pe(o);
|
|
1648
|
+
for (let c = 0; c < a.length; c++) {
|
|
1649
|
+
const l = a[c];
|
|
1650
|
+
if (l.isNewline) {
|
|
1651
|
+
r(l.position.start);
|
|
1652
|
+
continue;
|
|
1653
|
+
}
|
|
1654
|
+
l.content.length !== 0 && (n === -1 && (n = l.position.start), e.push({
|
|
1655
|
+
type: "text",
|
|
1656
|
+
content: l.content,
|
|
1657
|
+
position: l.position
|
|
1658
|
+
}));
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
if (e.length > 0) {
|
|
1662
|
+
const o = e[e.length - 1];
|
|
1663
|
+
r(o.position.end);
|
|
1664
|
+
}
|
|
1665
|
+
return t;
|
|
1666
|
+
}
|
|
1667
|
+
function pe(s) {
|
|
1668
|
+
const t = [], { content: e, position: n } = s;
|
|
1669
|
+
let r = n.start;
|
|
1670
|
+
const o = [], i = () => {
|
|
1671
|
+
if (o.length > 0) {
|
|
1672
|
+
const a = o.join("");
|
|
1673
|
+
t.push({
|
|
1674
|
+
content: a,
|
|
1675
|
+
position: { start: r, end: r + a.length },
|
|
1676
|
+
isNewline: !1
|
|
1677
|
+
}), r += a.length, o.length = 0;
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
for (let a = 0; a < e.length; a++) {
|
|
1681
|
+
const c = e[a];
|
|
1682
|
+
c === `
|
|
1683
|
+
` ? (i(), t.push({
|
|
1684
|
+
content: `
|
|
1685
|
+
`,
|
|
1686
|
+
position: { start: r, end: r + 1 },
|
|
1687
|
+
isNewline: !0
|
|
1688
|
+
}), r += 1) : c === "\r" ? a + 1 < e.length && e[a + 1] === `
|
|
1689
|
+
` ? (i(), t.push({
|
|
1690
|
+
content: `
|
|
1691
|
+
`,
|
|
1692
|
+
position: { start: r, end: r + 2 },
|
|
1693
|
+
isNewline: !0
|
|
1694
|
+
}), r += 2, a++) : (i(), t.push({
|
|
1695
|
+
content: `
|
|
1696
|
+
`,
|
|
1697
|
+
position: { start: r, end: r + 1 },
|
|
1698
|
+
isNewline: !0
|
|
1699
|
+
}), r += 1) : o.push(c);
|
|
1700
|
+
}
|
|
1701
|
+
return i(), t;
|
|
1702
|
+
}
|
|
1703
|
+
function ve(s, t, e, n) {
|
|
1704
|
+
if (e === n || e === n - 1 || t.length < 2 || e < 0 || e >= t.length || n < 0 || n > t.length) return s;
|
|
1705
|
+
const r = me(s, t), o = xe(r, e, n);
|
|
1706
|
+
return ye(o);
|
|
1707
|
+
}
|
|
1708
|
+
function me(s, t) {
|
|
1709
|
+
return t.map((e, n) => {
|
|
1710
|
+
const r = s.substring(e.startPos, e.endPos);
|
|
1711
|
+
let o = "";
|
|
1712
|
+
if (n < t.length - 1) {
|
|
1713
|
+
const i = t[n + 1];
|
|
1714
|
+
o = s.substring(e.endPos, i.startPos);
|
|
1715
|
+
}
|
|
1716
|
+
return {
|
|
1717
|
+
index: n,
|
|
1718
|
+
text: r,
|
|
1719
|
+
separatorAfter: o
|
|
1720
|
+
};
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
function ye(s) {
|
|
1724
|
+
const t = [];
|
|
1725
|
+
for (let e = 0; e < s.length; e++) {
|
|
1726
|
+
const n = s[e], r = e === s.length - 1;
|
|
1727
|
+
let o = n.text;
|
|
1728
|
+
o.endsWith(`
|
|
1729
|
+
`) && (o = o.slice(0, -1)), t.push(o), r || t.push(n.separatorAfter || `
|
|
1730
|
+
`);
|
|
1731
|
+
}
|
|
1732
|
+
return t.join("");
|
|
1733
|
+
}
|
|
1734
|
+
function xe(s, t, e) {
|
|
1735
|
+
const n = [...s], [r] = n.splice(t, 1), o = e > t ? e - 1 : e;
|
|
1736
|
+
return n.splice(o, 0, r), ke(n, s), n;
|
|
1737
|
+
}
|
|
1738
|
+
function ke(s, t) {
|
|
1739
|
+
for (let e = 0; e < s.length - 1; e++) {
|
|
1740
|
+
const n = s[e].index, r = s[e + 1].index;
|
|
1741
|
+
if (Math.abs(n - r) === 1) {
|
|
1742
|
+
const o = Math.min(n, r), i = t[o].separatorAfter;
|
|
1743
|
+
s[e].separatorAfter = i.length > 0 ? i : `
|
|
1744
|
+
`;
|
|
1745
|
+
} else
|
|
1746
|
+
s[e].separatorAfter = `
|
|
1747
|
+
`;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
const we = {
|
|
1616
1751
|
container: "div",
|
|
1617
1752
|
span: "span"
|
|
1618
1753
|
};
|
|
1619
|
-
function
|
|
1620
|
-
return t?.[s] ? t[s] :
|
|
1754
|
+
function K(s, t) {
|
|
1755
|
+
return t?.[s] ? t[s] : we[s];
|
|
1621
1756
|
}
|
|
1622
|
-
function
|
|
1757
|
+
function Y(s, t) {
|
|
1623
1758
|
const e = t?.[s];
|
|
1624
|
-
return e ?
|
|
1759
|
+
return e ? Et(e) : void 0;
|
|
1625
1760
|
}
|
|
1626
|
-
const
|
|
1627
|
-
|
|
1628
|
-
function
|
|
1629
|
-
const s =
|
|
1630
|
-
return
|
|
1761
|
+
const tt = at(void 0);
|
|
1762
|
+
tt.displayName = "StoreContext";
|
|
1763
|
+
function E() {
|
|
1764
|
+
const s = ct(tt);
|
|
1765
|
+
return bt(s), s;
|
|
1631
1766
|
}
|
|
1632
|
-
const
|
|
1633
|
-
const t =
|
|
1767
|
+
const Se = (s) => {
|
|
1768
|
+
const t = at(void 0);
|
|
1634
1769
|
return t.displayName = s, [() => {
|
|
1635
|
-
const n =
|
|
1770
|
+
const n = ct(t);
|
|
1636
1771
|
if (n === void 0)
|
|
1637
1772
|
throw new Error(`Context "${s}" not found. Make sure to wrap component in its Provider.`);
|
|
1638
1773
|
return n;
|
|
1639
1774
|
}, t.Provider, t];
|
|
1640
|
-
}, [
|
|
1641
|
-
function
|
|
1642
|
-
const r =
|
|
1643
|
-
let
|
|
1644
|
-
|
|
1645
|
-
const d =
|
|
1775
|
+
}, [et, ot] = Se("NodeProvider");
|
|
1776
|
+
function gt(s, t, e, n) {
|
|
1777
|
+
const r = E(), o = r.state.Mark.use(), i = r.state.Overlay.use(), a = s === "mark" ? o : i, c = s === "mark" ? t?.mark : t?.overlay;
|
|
1778
|
+
let l;
|
|
1779
|
+
c !== void 0 ? typeof c == "function" ? l = c(e) : l = c : l = e ?? {};
|
|
1780
|
+
const d = l.slot || a || n;
|
|
1646
1781
|
if (!d)
|
|
1647
1782
|
throw new Error(
|
|
1648
1783
|
`No ${s} component found. Provide either option.${s}.slot, global ${s === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
|
|
1649
1784
|
);
|
|
1650
|
-
return [d,
|
|
1785
|
+
return [d, l];
|
|
1651
1786
|
}
|
|
1652
|
-
function
|
|
1653
|
-
const s =
|
|
1787
|
+
function Ce() {
|
|
1788
|
+
const s = et(), t = E(), e = t.state.options.use(), n = t.key, r = e?.[s.descriptor.index], o = s.children.map((l) => /* @__PURE__ */ f(F, { mark: l, isNested: !0 }, n.get(l))), i = {
|
|
1654
1789
|
value: s.value,
|
|
1655
1790
|
meta: s.meta,
|
|
1656
1791
|
nested: s.nested?.content,
|
|
1657
1792
|
children: s.children.length > 0 ? o : void 0
|
|
1658
|
-
}, [a,
|
|
1659
|
-
return /* @__PURE__ */ f(a, { ...
|
|
1793
|
+
}, [a, c] = gt("mark", r, i);
|
|
1794
|
+
return /* @__PURE__ */ f(a, { ...c });
|
|
1660
1795
|
}
|
|
1661
|
-
const
|
|
1662
|
-
const s =
|
|
1796
|
+
const be = () => {
|
|
1797
|
+
const s = et(), t = E(), e = H(null), n = t.state.readOnly.use(), r = t.state.slots.use(), o = t.state.slotProps.use(), i = S(() => K("span", r), [r]), a = S(() => Y("span", o), [o]);
|
|
1663
1798
|
if (s.type !== "text")
|
|
1664
1799
|
throw new Error("TextSpan component expects a TextToken");
|
|
1665
|
-
return
|
|
1800
|
+
return St(() => {
|
|
1666
1801
|
e.current && e.current.textContent !== s.content && (e.current.textContent = s.content);
|
|
1667
1802
|
}, [s.content]), /* @__PURE__ */ f(
|
|
1668
1803
|
i,
|
|
@@ -1670,34 +1805,168 @@ const ne = () => {
|
|
|
1670
1805
|
...a,
|
|
1671
1806
|
ref: e,
|
|
1672
1807
|
contentEditable: !n,
|
|
1673
|
-
onPaste:
|
|
1808
|
+
onPaste: Ee,
|
|
1674
1809
|
suppressContentEditableWarning: !0
|
|
1675
1810
|
}
|
|
1676
1811
|
);
|
|
1677
1812
|
};
|
|
1678
|
-
function
|
|
1813
|
+
function Ee(s) {
|
|
1679
1814
|
s.preventDefault();
|
|
1680
1815
|
const t = s.clipboardData.getData("text");
|
|
1681
1816
|
document.execCommand("insertText", !1, t);
|
|
1682
1817
|
}
|
|
1683
|
-
const
|
|
1684
|
-
|
|
1685
|
-
const
|
|
1686
|
-
const s =
|
|
1818
|
+
const F = O(({ mark: s, isNested: t = !1 }) => s.type === "mark" ? /* @__PURE__ */ f(ot, { value: s, children: /* @__PURE__ */ f(Ce, {}) }) : t ? /* @__PURE__ */ f(wt, { children: s.content }) : /* @__PURE__ */ f(ot, { value: s, children: /* @__PURE__ */ f(be, {}) }));
|
|
1819
|
+
F.displayName = "Token";
|
|
1820
|
+
const pt = O(() => {
|
|
1821
|
+
const s = E(), t = s.state.tokens.use(), e = s.state.slots.use(), n = s.state.slotProps.use(), r = s.state.className.use(), o = s.state.style.use(), i = s.key, a = s.refs, c = S(() => K("container", e), [e]), l = S(() => Y("container", n), [n]);
|
|
1687
1822
|
return /* @__PURE__ */ f(
|
|
1688
|
-
|
|
1823
|
+
c,
|
|
1689
1824
|
{
|
|
1690
1825
|
ref: (d) => a.container = d,
|
|
1691
|
-
...
|
|
1826
|
+
...l,
|
|
1827
|
+
className: r,
|
|
1828
|
+
style: o,
|
|
1829
|
+
children: t.map((d) => /* @__PURE__ */ f(F, { mark: d }, i.get(d)))
|
|
1830
|
+
}
|
|
1831
|
+
);
|
|
1832
|
+
});
|
|
1833
|
+
pt.displayName = "Container";
|
|
1834
|
+
const q = {
|
|
1835
|
+
position: "absolute",
|
|
1836
|
+
left: -28,
|
|
1837
|
+
top: 2,
|
|
1838
|
+
width: 20,
|
|
1839
|
+
height: 20,
|
|
1840
|
+
display: "flex",
|
|
1841
|
+
alignItems: "center",
|
|
1842
|
+
justifyContent: "center",
|
|
1843
|
+
cursor: "grab",
|
|
1844
|
+
borderRadius: 4,
|
|
1845
|
+
opacity: 0,
|
|
1846
|
+
transition: "opacity 0.15s ease",
|
|
1847
|
+
userSelect: "none",
|
|
1848
|
+
color: "#9ca3af",
|
|
1849
|
+
flexShrink: 0,
|
|
1850
|
+
background: "none",
|
|
1851
|
+
border: "none",
|
|
1852
|
+
padding: 0,
|
|
1853
|
+
margin: 0,
|
|
1854
|
+
font: "inherit",
|
|
1855
|
+
lineHeight: 1
|
|
1856
|
+
}, vt = {
|
|
1857
|
+
...q,
|
|
1858
|
+
opacity: 1
|
|
1859
|
+
}, Te = {
|
|
1860
|
+
...vt,
|
|
1861
|
+
cursor: "grabbing"
|
|
1862
|
+
}, Ne = {
|
|
1863
|
+
position: "relative",
|
|
1864
|
+
paddingLeft: 4,
|
|
1865
|
+
transition: "opacity 0.2s ease"
|
|
1866
|
+
}, it = {
|
|
1867
|
+
position: "absolute",
|
|
1868
|
+
left: 0,
|
|
1869
|
+
right: 0,
|
|
1870
|
+
height: 2,
|
|
1871
|
+
backgroundColor: "#3b82f6",
|
|
1872
|
+
borderRadius: 1,
|
|
1873
|
+
pointerEvents: "none",
|
|
1874
|
+
zIndex: 10
|
|
1875
|
+
}, mt = O(() => /* @__PURE__ */ Z("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", children: [
|
|
1876
|
+
/* @__PURE__ */ f("circle", { cx: "5", cy: "3", r: "1.5" }),
|
|
1877
|
+
/* @__PURE__ */ f("circle", { cx: "11", cy: "3", r: "1.5" }),
|
|
1878
|
+
/* @__PURE__ */ f("circle", { cx: "5", cy: "8", r: "1.5" }),
|
|
1879
|
+
/* @__PURE__ */ f("circle", { cx: "11", cy: "8", r: "1.5" }),
|
|
1880
|
+
/* @__PURE__ */ f("circle", { cx: "5", cy: "13", r: "1.5" }),
|
|
1881
|
+
/* @__PURE__ */ f("circle", { cx: "11", cy: "13", r: "1.5" })
|
|
1882
|
+
] }));
|
|
1883
|
+
mt.displayName = "GripIcon";
|
|
1884
|
+
const yt = O(({ blockIndex: s, children: t, readOnly: e, onReorder: n }) => {
|
|
1885
|
+
const [r, o] = P(!1), [i, a] = P(!1), [c, l] = P(null), d = H(null), g = k(() => o(!0), []), u = k(() => o(!1), []), h = k(
|
|
1886
|
+
(p) => {
|
|
1887
|
+
p.dataTransfer.effectAllowed = "move", p.dataTransfer.setData("text/plain", String(s)), a(!0), d.current && p.dataTransfer.setDragImage(d.current, 0, 0);
|
|
1888
|
+
},
|
|
1889
|
+
[s]
|
|
1890
|
+
), v = k(() => {
|
|
1891
|
+
a(!1), l(null);
|
|
1892
|
+
}, []), C = k((p) => {
|
|
1893
|
+
if (p.preventDefault(), p.dataTransfer.dropEffect = "move", !d.current) return;
|
|
1894
|
+
const D = d.current.getBoundingClientRect(), W = D.top + D.height / 2;
|
|
1895
|
+
l(p.clientY < W ? "before" : "after");
|
|
1896
|
+
}, []), m = k((p) => {
|
|
1897
|
+
p.currentTarget.contains(p.relatedTarget) || l(null);
|
|
1898
|
+
}, []), b = k(
|
|
1899
|
+
(p) => {
|
|
1900
|
+
p.preventDefault();
|
|
1901
|
+
const D = parseInt(p.dataTransfer.getData("text/plain"), 10);
|
|
1902
|
+
if (isNaN(D)) return;
|
|
1903
|
+
const W = c === "before" ? s : s + 1;
|
|
1904
|
+
l(null), n(D, W);
|
|
1905
|
+
},
|
|
1906
|
+
[s, c, n]
|
|
1907
|
+
), T = {
|
|
1908
|
+
...Ne,
|
|
1909
|
+
opacity: i ? 0.4 : 1
|
|
1910
|
+
}, L = e ? { ...q, display: "none" } : i ? Te : r ? vt : q;
|
|
1911
|
+
return /* @__PURE__ */ Z(
|
|
1912
|
+
"div",
|
|
1913
|
+
{
|
|
1914
|
+
ref: d,
|
|
1915
|
+
style: T,
|
|
1916
|
+
onMouseEnter: g,
|
|
1917
|
+
onMouseLeave: u,
|
|
1918
|
+
onDragOver: C,
|
|
1919
|
+
onDragLeave: m,
|
|
1920
|
+
onDrop: b,
|
|
1921
|
+
children: [
|
|
1922
|
+
c === "before" && /* @__PURE__ */ f("div", { style: { ...it, top: -1 } }),
|
|
1923
|
+
/* @__PURE__ */ f(
|
|
1924
|
+
"button",
|
|
1925
|
+
{
|
|
1926
|
+
type: "button",
|
|
1927
|
+
draggable: !e,
|
|
1928
|
+
onDragStart: h,
|
|
1929
|
+
onDragEnd: v,
|
|
1930
|
+
style: L,
|
|
1931
|
+
"aria-label": "Drag to reorder",
|
|
1932
|
+
children: /* @__PURE__ */ f(mt, {})
|
|
1933
|
+
}
|
|
1934
|
+
),
|
|
1935
|
+
t,
|
|
1936
|
+
c === "after" && /* @__PURE__ */ f("div", { style: { ...it, bottom: -1 } })
|
|
1937
|
+
]
|
|
1938
|
+
}
|
|
1939
|
+
);
|
|
1940
|
+
});
|
|
1941
|
+
yt.displayName = "DraggableBlock";
|
|
1942
|
+
const xt = O(() => {
|
|
1943
|
+
const s = E(), t = s.state.tokens.use(), e = s.state.slots.use(), n = s.state.slotProps.use(), r = s.state.className.use(), o = s.state.style.use(), i = s.state.readOnly.use(), a = s.state.value.use(), c = s.state.onChange.use(), l = s.key, d = s.refs, g = S(() => K("container", e), [e]), u = S(() => Y("container", n), [n]), h = S(() => ge(t), [t]), v = H(h);
|
|
1944
|
+
v.current = h;
|
|
1945
|
+
const C = k(
|
|
1946
|
+
(m, b) => {
|
|
1947
|
+
if (!a || !c) return;
|
|
1948
|
+
const T = v.current, L = ve(a, T, m, b);
|
|
1949
|
+
if (L !== a) {
|
|
1950
|
+
const p = _(s, L);
|
|
1951
|
+
s.state.tokens.set(p), s.state.previousValue.set(L), c(L);
|
|
1952
|
+
}
|
|
1953
|
+
},
|
|
1954
|
+
[s, a, c]
|
|
1955
|
+
);
|
|
1956
|
+
return /* @__PURE__ */ f(
|
|
1957
|
+
g,
|
|
1958
|
+
{
|
|
1959
|
+
ref: (m) => d.container = m,
|
|
1960
|
+
...u,
|
|
1692
1961
|
className: r,
|
|
1693
1962
|
style: o,
|
|
1694
|
-
children:
|
|
1963
|
+
children: h.map((m, b) => /* @__PURE__ */ f(yt, { blockIndex: b, readOnly: i, onReorder: C, children: m.tokens.map((T) => /* @__PURE__ */ f(F, { mark: T }, l.get(T))) }, m.id))
|
|
1695
1964
|
}
|
|
1696
1965
|
);
|
|
1697
1966
|
});
|
|
1698
|
-
|
|
1699
|
-
function
|
|
1700
|
-
const s =
|
|
1967
|
+
xt.displayName = "BlockContainer";
|
|
1968
|
+
function Ie() {
|
|
1969
|
+
const s = E(), t = s.state.overlayMatch.use(), e = w.getAbsolutePosition(), n = k(() => s.events.clearOverlay(), []), r = k(
|
|
1701
1970
|
(i) => {
|
|
1702
1971
|
const a = {
|
|
1703
1972
|
type: "mark",
|
|
@@ -1715,7 +1984,7 @@ function re() {
|
|
|
1715
1984
|
s.events.select({ mark: a, match: t }), s.events.clearOverlay();
|
|
1716
1985
|
},
|
|
1717
1986
|
[t]
|
|
1718
|
-
), o =
|
|
1987
|
+
), o = S(
|
|
1719
1988
|
() => ({
|
|
1720
1989
|
get current() {
|
|
1721
1990
|
return s.refs.overlay;
|
|
@@ -1728,136 +1997,141 @@ function re() {
|
|
|
1728
1997
|
);
|
|
1729
1998
|
return { match: t, style: e, select: r, close: n, ref: o };
|
|
1730
1999
|
}
|
|
1731
|
-
const
|
|
1732
|
-
Container:
|
|
1733
|
-
Suggestions:
|
|
1734
|
-
suggestionActive:
|
|
1735
|
-
},
|
|
1736
|
-
const s =
|
|
2000
|
+
const Pe = "_Container_1lmfr_1", Me = "_Suggestions_1lmfr_10", Le = "_suggestionActive_1lmfr_38", X = {
|
|
2001
|
+
Container: Pe,
|
|
2002
|
+
Suggestions: Me,
|
|
2003
|
+
suggestionActive: Le
|
|
2004
|
+
}, Ae = () => {
|
|
2005
|
+
const s = E(), { match: t, select: e, style: n, ref: r } = Ie(), [o, i] = P(NaN), a = t.option.overlay?.data || [], c = S(
|
|
1737
2006
|
() => a.filter((d) => d.toLowerCase().indexOf(t.value.toLowerCase()) > -1),
|
|
1738
2007
|
[t.value, a]
|
|
1739
|
-
),
|
|
1740
|
-
return
|
|
2008
|
+
), l = c.length;
|
|
2009
|
+
return M(() => {
|
|
1741
2010
|
const d = s.refs.container;
|
|
1742
2011
|
if (!d) return;
|
|
1743
|
-
const
|
|
1744
|
-
switch (
|
|
1745
|
-
case
|
|
1746
|
-
|
|
2012
|
+
const g = (u) => {
|
|
2013
|
+
switch (u.key) {
|
|
2014
|
+
case x.UP:
|
|
2015
|
+
u.preventDefault(), i((h) => isNaN(h) ? 0 : (l + (h - 1) % l) % l);
|
|
1747
2016
|
break;
|
|
1748
|
-
case
|
|
1749
|
-
|
|
2017
|
+
case x.DOWN:
|
|
2018
|
+
u.preventDefault(), i((h) => isNaN(h) ? 0 : (h + 1) % l);
|
|
1750
2019
|
break;
|
|
1751
|
-
case
|
|
1752
|
-
|
|
1753
|
-
if (isNaN(
|
|
1754
|
-
const
|
|
1755
|
-
return e({ value:
|
|
2020
|
+
case x.ENTER:
|
|
2021
|
+
u.preventDefault(), i((h) => {
|
|
2022
|
+
if (isNaN(h)) return h;
|
|
2023
|
+
const v = c[h];
|
|
2024
|
+
return e({ value: v, meta: h.toString() }), h;
|
|
1756
2025
|
});
|
|
1757
2026
|
break;
|
|
1758
2027
|
}
|
|
1759
2028
|
};
|
|
1760
|
-
return d.addEventListener("keydown",
|
|
1761
|
-
}, [
|
|
1762
|
-
const
|
|
2029
|
+
return d.addEventListener("keydown", g), () => d.removeEventListener("keydown", g);
|
|
2030
|
+
}, [l, c]), c.length ? /* @__PURE__ */ f("ul", { ref: r, className: X.Suggestions, style: n, children: c.map((d, g) => {
|
|
2031
|
+
const u = g === o ? X.suggestionActive : void 0;
|
|
1763
2032
|
return /* @__PURE__ */ f(
|
|
1764
2033
|
"li",
|
|
1765
2034
|
{
|
|
1766
|
-
ref: (
|
|
1767
|
-
|
|
2035
|
+
ref: (h) => {
|
|
2036
|
+
u && h && h.scrollIntoView(!1);
|
|
1768
2037
|
},
|
|
1769
|
-
className:
|
|
1770
|
-
onClick: (
|
|
2038
|
+
className: u,
|
|
2039
|
+
onClick: (h) => e({ value: d, meta: g.toString() }),
|
|
1771
2040
|
children: d
|
|
1772
2041
|
},
|
|
1773
2042
|
d
|
|
1774
2043
|
);
|
|
1775
2044
|
}) }) : null;
|
|
1776
|
-
},
|
|
1777
|
-
const s =
|
|
2045
|
+
}, kt = O(() => {
|
|
2046
|
+
const s = E(), t = s.state.overlayMatch.use(), e = S(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] = gt("overlay", t?.option, void 0, Ae);
|
|
1778
2047
|
if (e) return /* @__PURE__ */ f(n, { ...r ?? {} }, e);
|
|
1779
2048
|
});
|
|
1780
|
-
|
|
1781
|
-
function
|
|
1782
|
-
|
|
2049
|
+
kt.displayName = "OverlayRenderer";
|
|
2050
|
+
function Oe(s, t) {
|
|
2051
|
+
Ct(t, () => s.createHandler(), [s]), M(() => (s.lifecycle.enable({
|
|
1783
2052
|
getTrigger: (a) => a.overlay?.trigger
|
|
1784
2053
|
}), () => s.lifecycle.disable()), []);
|
|
1785
2054
|
const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0;
|
|
1786
|
-
|
|
2055
|
+
M(() => {
|
|
1787
2056
|
s.lifecycle.syncParser(e, o);
|
|
1788
2057
|
}, [e, o]);
|
|
1789
2058
|
const i = s.state.tokens.use();
|
|
1790
|
-
|
|
2059
|
+
M(() => {
|
|
1791
2060
|
s.lifecycle.recoverFocus();
|
|
1792
2061
|
}, [i]);
|
|
1793
2062
|
}
|
|
1794
|
-
const
|
|
1795
|
-
const [t, e] =
|
|
1796
|
-
return
|
|
1797
|
-
},
|
|
2063
|
+
const De = (s) => () => {
|
|
2064
|
+
const [t, e] = P(() => s.get());
|
|
2065
|
+
return M(() => s.on(e), [s]), t;
|
|
2066
|
+
}, _e = [
|
|
1798
2067
|
{
|
|
1799
|
-
markup:
|
|
2068
|
+
markup: Pt,
|
|
1800
2069
|
overlay: {
|
|
1801
|
-
trigger:
|
|
2070
|
+
trigger: It,
|
|
1802
2071
|
data: []
|
|
1803
2072
|
}
|
|
1804
2073
|
}
|
|
1805
2074
|
];
|
|
1806
|
-
function
|
|
2075
|
+
function Fe(s) {
|
|
1807
2076
|
const {
|
|
1808
2077
|
ref: t,
|
|
1809
2078
|
value: e,
|
|
1810
2079
|
defaultValue: n,
|
|
1811
2080
|
onChange: r,
|
|
1812
2081
|
readOnly: o = !1,
|
|
1813
|
-
|
|
1814
|
-
|
|
2082
|
+
block: i = !1,
|
|
2083
|
+
Mark: a,
|
|
2084
|
+
Overlay: c,
|
|
1815
2085
|
slots: l,
|
|
1816
|
-
slotProps:
|
|
1817
|
-
options:
|
|
2086
|
+
slotProps: d,
|
|
2087
|
+
options: g = _e,
|
|
1818
2088
|
showOverlayOn: u = "change",
|
|
1819
2089
|
className: h,
|
|
1820
|
-
style:
|
|
1821
|
-
} = s,
|
|
1822
|
-
|
|
2090
|
+
style: v
|
|
2091
|
+
} = s, C = Tt(X.Container, h, d?.container?.className), m = Nt(v, d?.container?.style), [b] = P(() => new ue({ createUseHook: De }));
|
|
2092
|
+
b.state.set({
|
|
1823
2093
|
value: e,
|
|
1824
2094
|
defaultValue: n,
|
|
1825
2095
|
onChange: r,
|
|
1826
2096
|
readOnly: o,
|
|
1827
|
-
options:
|
|
2097
|
+
options: g,
|
|
1828
2098
|
showOverlayOn: u,
|
|
1829
|
-
Mark:
|
|
1830
|
-
Overlay:
|
|
1831
|
-
className:
|
|
1832
|
-
style:
|
|
2099
|
+
Mark: a,
|
|
2100
|
+
Overlay: c,
|
|
2101
|
+
className: C,
|
|
2102
|
+
style: m,
|
|
1833
2103
|
slots: l,
|
|
1834
|
-
slotProps:
|
|
1835
|
-
}),
|
|
1836
|
-
|
|
1837
|
-
|
|
2104
|
+
slotProps: d
|
|
2105
|
+
}), Oe(b, t);
|
|
2106
|
+
const T = i ? xt : pt;
|
|
2107
|
+
return /* @__PURE__ */ Z(tt.Provider, { value: b, children: [
|
|
2108
|
+
/* @__PURE__ */ f(T, {}),
|
|
2109
|
+
/* @__PURE__ */ f(kt, {})
|
|
1838
2110
|
] });
|
|
1839
2111
|
}
|
|
1840
|
-
const
|
|
1841
|
-
const t =
|
|
2112
|
+
const We = (s = {}) => {
|
|
2113
|
+
const t = E(), e = et(), n = H(null);
|
|
1842
2114
|
if (e.type !== "mark")
|
|
1843
2115
|
throw new Error("useMark can only be used with mark tokens");
|
|
1844
|
-
const [r] =
|
|
1845
|
-
|
|
2116
|
+
const [r] = P(() => new he({ ref: n, store: t, token: e }));
|
|
2117
|
+
Re(n, s, e);
|
|
1846
2118
|
const o = t.state.readOnly.use();
|
|
1847
|
-
return
|
|
2119
|
+
return M(() => {
|
|
1848
2120
|
r.readOnly = o;
|
|
1849
2121
|
}, [o]), r;
|
|
1850
2122
|
};
|
|
1851
|
-
function
|
|
1852
|
-
|
|
2123
|
+
function Re(s, t, e) {
|
|
2124
|
+
M(() => {
|
|
1853
2125
|
s.current && !t.controlled && (s.current.textContent = e.content);
|
|
1854
2126
|
}, []);
|
|
1855
2127
|
}
|
|
1856
2128
|
export {
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
2129
|
+
he as MarkHandler,
|
|
2130
|
+
Fe as MarkedInput,
|
|
2131
|
+
j as annotate,
|
|
2132
|
+
Be as denote,
|
|
2133
|
+
ve as reorderBlocks,
|
|
2134
|
+
ge as splitTokensIntoBlocks,
|
|
2135
|
+
We as useMark,
|
|
2136
|
+
Ie as useOverlay
|
|
1863
2137
|
};
|