@markput/react 0.3.0 → 0.5.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 +5 -2
- package/index.d.ts +2 -14
- package/index.js +528 -471
- package/package.json +15 -15
package/index.js
CHANGED
|
@@ -1,35 +1,54 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { jsxs as J, jsx as h, Fragment as wt } from "react/jsx-runtime";
|
|
3
|
+
import { useState as M, useEffect as P, useImperativeHandle as St, createContext as at, useContext as ct, memo as O, useRef as H, useCallback as k, useMemo as S, useLayoutEffect as Ct } from "react";
|
|
4
4
|
function bt(s) {
|
|
5
|
-
if (s == null) throw new Error("Value must be a non nullable!");
|
|
6
|
-
}
|
|
7
|
-
function Et(s) {
|
|
8
5
|
return s ? Object.fromEntries(
|
|
9
6
|
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
7
|
) : {};
|
|
11
8
|
}
|
|
12
|
-
function
|
|
9
|
+
function Et(...s) {
|
|
13
10
|
return s.filter(Boolean).join(" ") || void 0;
|
|
14
11
|
}
|
|
15
|
-
function
|
|
12
|
+
function Tt(...s) {
|
|
16
13
|
const t = Object.assign({}, ...s.filter(Boolean));
|
|
17
14
|
return Object.keys(t).length > 0 ? t : void 0;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
function Nt(s, t) {
|
|
17
|
+
return s !== void 0 ? typeof s == "function" ? s(t) : s : t ?? {};
|
|
18
|
+
}
|
|
19
|
+
const It = {
|
|
20
|
+
container: "div",
|
|
21
|
+
span: "span"
|
|
22
|
+
};
|
|
23
|
+
function Q(s, t) {
|
|
24
|
+
return t?.[s] ?? It[s];
|
|
25
|
+
}
|
|
26
|
+
function K(s, t) {
|
|
27
|
+
const e = t?.[s];
|
|
28
|
+
return e ? bt(e) : void 0;
|
|
29
|
+
}
|
|
30
|
+
var v = /* @__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))(v || {});
|
|
31
|
+
const Mt = "@", Pt = "@[__value__](__meta__)", Lt = [
|
|
32
|
+
{
|
|
33
|
+
markup: Pt,
|
|
34
|
+
overlay: {
|
|
35
|
+
trigger: Mt,
|
|
36
|
+
data: []
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
], x = {
|
|
21
40
|
Value: "__value__",
|
|
22
41
|
Meta: "__meta__",
|
|
23
42
|
Nested: "__nested__"
|
|
24
|
-
},
|
|
43
|
+
}, T = {
|
|
25
44
|
Value: "value",
|
|
26
45
|
Meta: "meta",
|
|
27
46
|
Nested: "nested"
|
|
28
47
|
};
|
|
29
|
-
function
|
|
30
|
-
const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } =
|
|
31
|
-
|
|
32
|
-
const i = r.value === 2, { segments: a, gapTypes: c } = i ?
|
|
48
|
+
function At(s, t) {
|
|
49
|
+
const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } = Ot(s);
|
|
50
|
+
Dt(r, s);
|
|
51
|
+
const i = r.value === 2, { segments: a, gapTypes: c } = i ? Rt(e, n, o) : { segments: e, gapTypes: n };
|
|
33
52
|
return {
|
|
34
53
|
markup: s,
|
|
35
54
|
index: t,
|
|
@@ -41,23 +60,23 @@ function Mt(s, t) {
|
|
|
41
60
|
// Will be populated by MarkupRegistry
|
|
42
61
|
};
|
|
43
62
|
}
|
|
44
|
-
function
|
|
63
|
+
function Ot(s) {
|
|
45
64
|
const t = [], e = [], n = [], r = {
|
|
46
65
|
value: 0,
|
|
47
66
|
meta: 0,
|
|
48
67
|
nested: 0
|
|
49
|
-
}, o = [], i = [
|
|
68
|
+
}, o = [], i = [T.Value, T.Meta, T.Nested];
|
|
50
69
|
for (const l of i) {
|
|
51
|
-
const d =
|
|
52
|
-
let
|
|
53
|
-
for (;
|
|
54
|
-
o.push({ type: l, position:
|
|
70
|
+
const d = st[l];
|
|
71
|
+
let f = s.indexOf(d);
|
|
72
|
+
for (; f !== -1; )
|
|
73
|
+
o.push({ type: l, position: f }), f = s.indexOf(d, f + d.length);
|
|
55
74
|
}
|
|
56
75
|
o.sort((l, d) => l.position - d.position);
|
|
57
76
|
let a = 0;
|
|
58
77
|
for (const l of o) {
|
|
59
78
|
const d = s.substring(a, l.position);
|
|
60
|
-
d.length > 0 && t.push(d), e.push(l.type), r[l.type]++, l.type ===
|
|
79
|
+
d.length > 0 && t.push(d), e.push(l.type), r[l.type]++, l.type === T.Value && n.push(e.length - 1), a = l.position + st[l.type].length;
|
|
61
80
|
}
|
|
62
81
|
const c = s.substring(a);
|
|
63
82
|
return c.length > 0 && t.push(c), {
|
|
@@ -67,43 +86,43 @@ function Lt(s) {
|
|
|
67
86
|
valueGapIndices: n
|
|
68
87
|
};
|
|
69
88
|
}
|
|
70
|
-
function
|
|
89
|
+
function Dt(s, t) {
|
|
71
90
|
const e = [
|
|
72
|
-
{ count: s.value, max: 2, name:
|
|
73
|
-
{ count: s.meta, max: 1, name:
|
|
74
|
-
{ count: s.nested, max: 1, name:
|
|
91
|
+
{ count: s.value, max: 2, name: x.Value },
|
|
92
|
+
{ count: s.meta, max: 1, name: x.Meta },
|
|
93
|
+
{ count: s.nested, max: 1, name: x.Nested }
|
|
75
94
|
];
|
|
76
95
|
for (const { count: n, max: r, name: o } of e)
|
|
77
96
|
if (n > r)
|
|
78
97
|
throw new Error(`Invalid markup: "${t}". Max ${r} "${o}" placeholders, got ${n}`);
|
|
79
98
|
if (s.value === 0 && s.nested === 0)
|
|
80
99
|
throw new Error(
|
|
81
|
-
`Invalid markup: "${t}". Need at least one "${
|
|
100
|
+
`Invalid markup: "${t}". Need at least one "${x.Value}" or "${x.Nested}"`
|
|
82
101
|
);
|
|
83
102
|
}
|
|
84
|
-
const
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
103
|
+
const st = {
|
|
104
|
+
[T.Value]: x.Value,
|
|
105
|
+
[T.Meta]: x.Meta,
|
|
106
|
+
[T.Nested]: x.Nested
|
|
88
107
|
};
|
|
89
|
-
function
|
|
108
|
+
function Rt(s, t, e) {
|
|
90
109
|
if (e.length !== 2)
|
|
91
110
|
return { segments: s, gapTypes: t };
|
|
92
111
|
const [n, r] = e, o = [], i = s[n], a = s[n + 1];
|
|
93
|
-
i && a && o.push(
|
|
112
|
+
i && a && o.push(f(i, a, s[n + 2]));
|
|
94
113
|
for (let u = n + 2; u < r; u++)
|
|
95
114
|
o.push(s[u]);
|
|
96
115
|
const c = s[r], l = s[r + 1];
|
|
97
|
-
c && l && o.push(
|
|
98
|
-
const d = t.filter((u) => u !==
|
|
116
|
+
c && l && o.push(f(c, l, s[r + 2]));
|
|
117
|
+
const d = t.filter((u) => u !== T.Value);
|
|
99
118
|
return { segments: o, gapTypes: d };
|
|
100
|
-
function
|
|
101
|
-
if (!
|
|
102
|
-
const C =
|
|
103
|
-
return [u,
|
|
119
|
+
function f(u, g, m) {
|
|
120
|
+
if (!m) return [u, g, ""];
|
|
121
|
+
const C = m.charAt(0), y = C && !g.includes(C) && !m.startsWith(u) ? C : "";
|
|
122
|
+
return [u, g, y];
|
|
104
123
|
}
|
|
105
124
|
}
|
|
106
|
-
class
|
|
125
|
+
class _t {
|
|
107
126
|
markups;
|
|
108
127
|
descriptors;
|
|
109
128
|
/** Deduplicated list of unique segment definitions (static strings or dynamic patterns) */
|
|
@@ -116,7 +135,7 @@ class Dt {
|
|
|
116
135
|
this.descriptors = t.map((n, r) => {
|
|
117
136
|
if (n === void 0)
|
|
118
137
|
return null;
|
|
119
|
-
const o =
|
|
138
|
+
const o = At(n, r);
|
|
120
139
|
return o.segments.forEach((i, a) => {
|
|
121
140
|
this.processSegment(o, i, a, e);
|
|
122
141
|
}), this.addToFirstSegmentIndexMap(o), o;
|
|
@@ -168,7 +187,7 @@ function lt(s, t) {
|
|
|
168
187
|
e = e * 33 ^ t.charCodeAt(n);
|
|
169
188
|
return e = e >>> 0, s * 1e6 + (e & 1048575);
|
|
170
189
|
}
|
|
171
|
-
class
|
|
190
|
+
class Bt {
|
|
172
191
|
constructor(t, e) {
|
|
173
192
|
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
193
|
this.captured = e.captured;
|
|
@@ -237,7 +256,7 @@ class _t {
|
|
|
237
256
|
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
257
|
}
|
|
239
258
|
}
|
|
240
|
-
class
|
|
259
|
+
class Vt {
|
|
241
260
|
constructor(t) {
|
|
242
261
|
this.registry = t;
|
|
243
262
|
}
|
|
@@ -266,7 +285,7 @@ class Rt {
|
|
|
266
285
|
}
|
|
267
286
|
tryStartNewStates(t) {
|
|
268
287
|
this.registry.firstSegmentIndexMap.get(t.index)?.forEach((e) => {
|
|
269
|
-
const n = new
|
|
288
|
+
const n = new Bt(e, t);
|
|
270
289
|
if (!n.isInvalid) {
|
|
271
290
|
if (n.isCompleted) return this.addToCompleted(n);
|
|
272
291
|
this.addToWaiting(n);
|
|
@@ -312,11 +331,11 @@ class Rt {
|
|
|
312
331
|
}
|
|
313
332
|
}
|
|
314
333
|
const A = (s) => s.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
|
|
315
|
-
function
|
|
334
|
+
function $t(s, t, e) {
|
|
316
335
|
const n = A(s), r = A(t), o = A(t + e);
|
|
317
336
|
return `${n}([^${o}]+?)${r}`;
|
|
318
337
|
}
|
|
319
|
-
class
|
|
338
|
+
class Ht {
|
|
320
339
|
staticRegex;
|
|
321
340
|
staticToIndex;
|
|
322
341
|
dynamicRegex;
|
|
@@ -340,10 +359,10 @@ class $t {
|
|
|
340
359
|
if (typeof a == "string")
|
|
341
360
|
i.push({ index: c, pattern: A(a), definition: a });
|
|
342
361
|
else {
|
|
343
|
-
const [l, d,
|
|
362
|
+
const [l, d, f] = a;
|
|
344
363
|
o.add(c);
|
|
345
|
-
const
|
|
346
|
-
i.push({ index: c, pattern:
|
|
364
|
+
const g = $t(l, d, f).replace("(", `(?<content${c}>`);
|
|
365
|
+
i.push({ index: c, pattern: g, definition: a });
|
|
347
366
|
}
|
|
348
367
|
}), i.sort((a, c) => {
|
|
349
368
|
const l = typeof a.definition == "string" ? a.definition.length : a.pattern.length;
|
|
@@ -395,7 +414,7 @@ const dt = (s, t = 0, e = s.length) => ({
|
|
|
395
414
|
content: s.substring(t, e),
|
|
396
415
|
position: { start: t, end: e }
|
|
397
416
|
});
|
|
398
|
-
class
|
|
417
|
+
class Ft {
|
|
399
418
|
// Instance fields - only what's needed for single pass
|
|
400
419
|
input;
|
|
401
420
|
// ===== PUBLIC API =====
|
|
@@ -528,19 +547,34 @@ class Ht {
|
|
|
528
547
|
};
|
|
529
548
|
}
|
|
530
549
|
}
|
|
531
|
-
function
|
|
550
|
+
function Y(s, t) {
|
|
551
|
+
let e = "";
|
|
552
|
+
for (const n of s)
|
|
553
|
+
if (n.type === "text")
|
|
554
|
+
e += n.content;
|
|
555
|
+
else if (n.children.length > 0) {
|
|
556
|
+
const r = Y(n.children, t), o = {
|
|
557
|
+
...n,
|
|
558
|
+
value: r
|
|
559
|
+
};
|
|
560
|
+
e += t(o);
|
|
561
|
+
} else
|
|
562
|
+
e += t(n);
|
|
563
|
+
return e;
|
|
564
|
+
}
|
|
565
|
+
function q(s, t) {
|
|
532
566
|
let e = s;
|
|
533
|
-
return t.value !== void 0 && (e = e.replaceAll(
|
|
567
|
+
return t.value !== void 0 && (e = e.replaceAll(x.Value, t.value)), t.meta !== void 0 && (e = e.replaceAll(x.Meta, t.meta)), t.nested !== void 0 && (e = e.replaceAll(x.Nested, t.nested)), e;
|
|
534
568
|
}
|
|
535
|
-
function
|
|
569
|
+
function N(s) {
|
|
536
570
|
let t = "";
|
|
537
571
|
for (const e of s) {
|
|
538
572
|
if (e.type === "text") {
|
|
539
573
|
t += e.content;
|
|
540
574
|
continue;
|
|
541
575
|
}
|
|
542
|
-
const n = e.descriptor.markup, r = n.includes(
|
|
543
|
-
t +=
|
|
576
|
+
const n = e.descriptor.markup, r = n.includes(x.Nested) ? e.children.length > 0 ? N(e.children) : e.nested?.content : void 0;
|
|
577
|
+
t += q(n, {
|
|
544
578
|
value: e.value,
|
|
545
579
|
meta: e.meta,
|
|
546
580
|
nested: r
|
|
@@ -548,22 +582,7 @@ function I(s) {
|
|
|
548
582
|
}
|
|
549
583
|
return t;
|
|
550
584
|
}
|
|
551
|
-
|
|
552
|
-
let e = "";
|
|
553
|
-
for (const n of s)
|
|
554
|
-
if (n.type === "text")
|
|
555
|
-
e += n.content;
|
|
556
|
-
else if (n.children.length > 0) {
|
|
557
|
-
const r = J(n.children, t), o = {
|
|
558
|
-
...n,
|
|
559
|
-
value: r
|
|
560
|
-
};
|
|
561
|
-
e += t(o);
|
|
562
|
-
} else
|
|
563
|
-
e += t(n);
|
|
564
|
-
return e;
|
|
565
|
-
}
|
|
566
|
-
class B {
|
|
585
|
+
class F {
|
|
567
586
|
registry;
|
|
568
587
|
segmentMatcher;
|
|
569
588
|
patternMatcher;
|
|
@@ -588,7 +607,7 @@ class B {
|
|
|
588
607
|
* ```
|
|
589
608
|
*/
|
|
590
609
|
constructor(t) {
|
|
591
|
-
this.registry = new
|
|
610
|
+
this.registry = new _t(t), this.segmentMatcher = new Ht(this.registry.segments), this.patternMatcher = new Vt(this.registry), this.treeBuilder = new Ft();
|
|
592
611
|
}
|
|
593
612
|
/**
|
|
594
613
|
* Parses text into tokens (static convenience method)
|
|
@@ -606,7 +625,7 @@ class B {
|
|
|
606
625
|
*/
|
|
607
626
|
static parse(t, e) {
|
|
608
627
|
const n = e?.markup;
|
|
609
|
-
return !n || n.length === 0 ? [dt(t)] : new
|
|
628
|
+
return !n || n.length === 0 ? [dt(t)] : new F(n).parse(t);
|
|
610
629
|
}
|
|
611
630
|
/**
|
|
612
631
|
* Converts tokens back to text (static convenience method)
|
|
@@ -620,7 +639,7 @@ class B {
|
|
|
620
639
|
* ```
|
|
621
640
|
*/
|
|
622
641
|
static stringify(t) {
|
|
623
|
-
return
|
|
642
|
+
return N(t);
|
|
624
643
|
}
|
|
625
644
|
/**
|
|
626
645
|
* Parses text into a nested token tree
|
|
@@ -667,7 +686,7 @@ class B {
|
|
|
667
686
|
* ```
|
|
668
687
|
*/
|
|
669
688
|
stringify(t) {
|
|
670
|
-
return
|
|
689
|
+
return N(t);
|
|
671
690
|
}
|
|
672
691
|
/**
|
|
673
692
|
* Transforms annotated text by processing all mark tokens with a callback
|
|
@@ -696,7 +715,7 @@ class B {
|
|
|
696
715
|
*/
|
|
697
716
|
transform(t, e) {
|
|
698
717
|
const n = this.parse(t);
|
|
699
|
-
return
|
|
718
|
+
return Y(n, e);
|
|
700
719
|
}
|
|
701
720
|
/**
|
|
702
721
|
* Escapes markup segments in the given text using backslash
|
|
@@ -738,10 +757,10 @@ class B {
|
|
|
738
757
|
return t.replaceAll(/\\(.)/g, "$1");
|
|
739
758
|
}
|
|
740
759
|
}
|
|
741
|
-
function
|
|
760
|
+
function Ge(s, t, e) {
|
|
742
761
|
if (!e.length) return s;
|
|
743
|
-
const n = new
|
|
744
|
-
return
|
|
762
|
+
const n = new F(e).parse(s);
|
|
763
|
+
return Y(n, t);
|
|
745
764
|
}
|
|
746
765
|
function z(s, t, e = 0, n) {
|
|
747
766
|
for (const r of s) {
|
|
@@ -752,7 +771,7 @@ function z(s, t, e = 0, n) {
|
|
|
752
771
|
}
|
|
753
772
|
}
|
|
754
773
|
}
|
|
755
|
-
function
|
|
774
|
+
function Wt(s = "", t = "") {
|
|
756
775
|
if (s === t) return {};
|
|
757
776
|
let e;
|
|
758
777
|
for (let r = 0; r < s.length; r++)
|
|
@@ -768,7 +787,7 @@ function Bt(s = "", t = "") {
|
|
|
768
787
|
}
|
|
769
788
|
return { left: e, right: n };
|
|
770
789
|
}
|
|
771
|
-
function
|
|
790
|
+
function rt(s, t) {
|
|
772
791
|
let e = -1, n = s.length;
|
|
773
792
|
for (; n - e > 1; ) {
|
|
774
793
|
const r = Math.round((e + n) / 2);
|
|
@@ -776,37 +795,37 @@ function st(s, t) {
|
|
|
776
795
|
}
|
|
777
796
|
return s[e] == t && (n = e), [e, n].filter((r) => s[r] !== void 0);
|
|
778
797
|
}
|
|
779
|
-
function
|
|
798
|
+
function Gt(s) {
|
|
780
799
|
const { focus: t } = s.nodes, e = s.state.parser.get(), n = s.state.tokens.get();
|
|
781
800
|
if (!e)
|
|
782
801
|
return n;
|
|
783
802
|
const r = e.parse(t.content);
|
|
784
803
|
return r.length === 1 ? n : n.toSpliced(t.index, 1, ...r);
|
|
785
804
|
}
|
|
786
|
-
function
|
|
787
|
-
const t = s.state.value.get(), e =
|
|
805
|
+
function Ut(s) {
|
|
806
|
+
const t = s.state.value.get(), e = jt(s), n = Wt(s.state.previousValue.get(), t);
|
|
788
807
|
if (!n.left && !n.right)
|
|
789
808
|
return s.state.previousValue.set(t), s.state.tokens.get();
|
|
790
809
|
s.state.previousValue.set(t);
|
|
791
810
|
const r = s.state.tokens.get();
|
|
792
811
|
switch (!0) {
|
|
793
812
|
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 =
|
|
813
|
+
const o = e.indexOf(n.left), i = U(s, o - 1, o);
|
|
795
814
|
return r.toSpliced(o - 1, 2, ...i);
|
|
796
815
|
}
|
|
797
816
|
case n.left !== void 0: {
|
|
798
|
-
const [o] =
|
|
817
|
+
const [o] = rt(e, n.left), i = U(s, o);
|
|
799
818
|
return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
|
|
800
819
|
}
|
|
801
820
|
case n.right !== void 0: {
|
|
802
|
-
const [o] =
|
|
821
|
+
const [o] = rt(e, n.right), i = U(s, o);
|
|
803
822
|
return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
|
|
804
823
|
}
|
|
805
824
|
default:
|
|
806
825
|
return _(s, t ?? "");
|
|
807
826
|
}
|
|
808
827
|
}
|
|
809
|
-
function
|
|
828
|
+
function U(s, ...t) {
|
|
810
829
|
let e = "";
|
|
811
830
|
const n = s.state.tokens.get();
|
|
812
831
|
for (const r of t) {
|
|
@@ -815,7 +834,7 @@ function G(s, ...t) {
|
|
|
815
834
|
}
|
|
816
835
|
return _(s, e);
|
|
817
836
|
}
|
|
818
|
-
function
|
|
837
|
+
function jt(s) {
|
|
819
838
|
let t = 0;
|
|
820
839
|
return s.state.tokens.get().map((n) => {
|
|
821
840
|
const r = n.content.length;
|
|
@@ -832,16 +851,16 @@ function _(s, t) {
|
|
|
832
851
|
}
|
|
833
852
|
];
|
|
834
853
|
}
|
|
835
|
-
const
|
|
836
|
-
class
|
|
854
|
+
const qt = (s, t) => s === t;
|
|
855
|
+
class B {
|
|
837
856
|
#t;
|
|
838
857
|
#e = /* @__PURE__ */ new Set();
|
|
839
858
|
#n;
|
|
840
859
|
constructor(t, e) {
|
|
841
|
-
this.#t = t, this.#n = e?.equals ??
|
|
860
|
+
this.#t = t, this.#n = e?.equals ?? qt;
|
|
842
861
|
}
|
|
843
862
|
static event() {
|
|
844
|
-
return new
|
|
863
|
+
return new B(void 0, { equals: !1 });
|
|
845
864
|
}
|
|
846
865
|
get value() {
|
|
847
866
|
return this.#t;
|
|
@@ -862,14 +881,14 @@ class R {
|
|
|
862
881
|
this.value = t;
|
|
863
882
|
}
|
|
864
883
|
}
|
|
865
|
-
function
|
|
884
|
+
function zt(s, t) {
|
|
866
885
|
const e = {};
|
|
867
886
|
return e.get = () => s.get(), e.set = (n) => s.set(n), e.on = (n) => s.on(n), e.use = t(e), e;
|
|
868
887
|
}
|
|
869
|
-
function
|
|
888
|
+
function Xt(s, t) {
|
|
870
889
|
const e = /* @__PURE__ */ new Map();
|
|
871
890
|
for (const n in s)
|
|
872
|
-
e.set(n, new
|
|
891
|
+
e.set(n, new B(s[n]));
|
|
873
892
|
return new Proxy(s, {
|
|
874
893
|
get(n, r) {
|
|
875
894
|
if (r === "set")
|
|
@@ -879,28 +898,28 @@ function zt(s, t) {
|
|
|
879
898
|
};
|
|
880
899
|
const o = e.get(r);
|
|
881
900
|
if (o)
|
|
882
|
-
return
|
|
901
|
+
return zt(o, t);
|
|
883
902
|
}
|
|
884
903
|
});
|
|
885
904
|
}
|
|
886
|
-
function
|
|
905
|
+
function Zt(s) {
|
|
887
906
|
const t = function(e) {
|
|
888
907
|
s.emit(e);
|
|
889
908
|
};
|
|
890
909
|
return t.on = (e) => s.on(e), t;
|
|
891
910
|
}
|
|
892
|
-
function
|
|
911
|
+
function Jt(s) {
|
|
893
912
|
const t = [], e = /* @__PURE__ */ new Map();
|
|
894
913
|
for (const n of t)
|
|
895
|
-
e.set(n,
|
|
914
|
+
e.set(n, B.event());
|
|
896
915
|
return new Proxy({}, {
|
|
897
916
|
get(n, r) {
|
|
898
917
|
let o = e.get(r);
|
|
899
|
-
return o || (o =
|
|
918
|
+
return o || (o = B.event(), e.set(r, o)), Zt(o);
|
|
900
919
|
}
|
|
901
920
|
});
|
|
902
921
|
}
|
|
903
|
-
class
|
|
922
|
+
class Qt {
|
|
904
923
|
#t = 1;
|
|
905
924
|
#e = /* @__PURE__ */ new WeakMap();
|
|
906
925
|
get(t) {
|
|
@@ -968,8 +987,8 @@ class w {
|
|
|
968
987
|
r?.setStart(r.endContainer, e), r?.setEnd(r.endContainer, e);
|
|
969
988
|
}
|
|
970
989
|
}
|
|
971
|
-
const
|
|
972
|
-
class
|
|
990
|
+
const Kt = new RegExp(/^\w*/);
|
|
991
|
+
class tt {
|
|
973
992
|
span;
|
|
974
993
|
node;
|
|
975
994
|
dividedText;
|
|
@@ -994,7 +1013,7 @@ class Q {
|
|
|
994
1013
|
*/
|
|
995
1014
|
static find(t, e) {
|
|
996
1015
|
if (t && w.isSelectedPosition)
|
|
997
|
-
return new
|
|
1016
|
+
return new tt().find(t, e);
|
|
998
1017
|
}
|
|
999
1018
|
getDividedTextBy(t) {
|
|
1000
1019
|
return { left: this.span.slice(0, t), right: this.span.slice(t) };
|
|
@@ -1032,7 +1051,7 @@ class Q {
|
|
|
1032
1051
|
}
|
|
1033
1052
|
matchRightPart() {
|
|
1034
1053
|
const { right: t } = this.dividedText;
|
|
1035
|
-
return { word: t.match(
|
|
1054
|
+
return { word: t.match(Kt)?.[0] };
|
|
1036
1055
|
}
|
|
1037
1056
|
matchLeftPart(t) {
|
|
1038
1057
|
const e = this.makeTriggerRegex(t), { left: n } = this.dividedText, r = n.match(e);
|
|
@@ -1116,10 +1135,10 @@ class V {
|
|
|
1116
1135
|
this.target = void 0;
|
|
1117
1136
|
}
|
|
1118
1137
|
}
|
|
1119
|
-
function
|
|
1138
|
+
function Yt(s, t, e, n) {
|
|
1120
1139
|
return s.slice(0, e) + t + s.slice(e + n.length);
|
|
1121
1140
|
}
|
|
1122
|
-
function
|
|
1141
|
+
function j(s, t) {
|
|
1123
1142
|
const n = {
|
|
1124
1143
|
prev: 2,
|
|
1125
1144
|
self: 1,
|
|
@@ -1138,10 +1157,29 @@ function U(s, t) {
|
|
|
1138
1157
|
let d = r;
|
|
1139
1158
|
for (let u = 0; u < n; u++)
|
|
1140
1159
|
d = d.prev;
|
|
1141
|
-
const
|
|
1142
|
-
t.state.recovery.set({ anchor: d.prev, caret:
|
|
1160
|
+
const f = d.length;
|
|
1161
|
+
t.state.recovery.set({ anchor: d.prev, caret: f }), t.state.onChange.get()?.(N(t.state.tokens.get()));
|
|
1143
1162
|
}
|
|
1144
|
-
class
|
|
1163
|
+
class te {
|
|
1164
|
+
constructor(t) {
|
|
1165
|
+
this.store = t;
|
|
1166
|
+
}
|
|
1167
|
+
#t;
|
|
1168
|
+
enable() {
|
|
1169
|
+
this.#t || (this.#t = this.store.state.readOnly.on(() => this.sync()), this.sync());
|
|
1170
|
+
}
|
|
1171
|
+
disable() {
|
|
1172
|
+
this.#t?.(), this.#t = void 0;
|
|
1173
|
+
}
|
|
1174
|
+
sync() {
|
|
1175
|
+
const t = this.store.refs.container;
|
|
1176
|
+
if (!t) return;
|
|
1177
|
+
const n = this.store.state.readOnly.get() ? "false" : "true", r = t.children;
|
|
1178
|
+
for (let o = 0; o < r.length; o += 2)
|
|
1179
|
+
r[o].contentEditable = n;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
class ee {
|
|
1145
1183
|
constructor(t) {
|
|
1146
1184
|
this.store = t;
|
|
1147
1185
|
}
|
|
@@ -1153,22 +1191,22 @@ class Kt {
|
|
|
1153
1191
|
const t = this.store.state.onChange.get();
|
|
1154
1192
|
if (!this.store.nodes.focus.target) return;
|
|
1155
1193
|
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?.(
|
|
1194
|
+
n.type === "text" ? n.content = this.store.nodes.focus.content : n.type === "mark" && (n.value = this.store.nodes.focus.content), t?.(N(e)), this.store.events.parse();
|
|
1157
1195
|
}), this.#e = this.store.events.delete.on((t) => {
|
|
1158
1196
|
if (!t) return;
|
|
1159
1197
|
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?.(
|
|
1198
|
+
this.store.state.tokens.set(r.toSpliced(o, 1)), n?.(N(this.store.state.tokens.get()));
|
|
1161
1199
|
}), this.#n = this.store.events.select.on((t) => {
|
|
1162
1200
|
if (!t) return;
|
|
1163
1201
|
const e = this.store.state.Mark.get(), n = this.store.state.onChange.get(), {
|
|
1164
1202
|
mark: r,
|
|
1165
1203
|
match: { option: o, span: i, index: a, source: c }
|
|
1166
|
-
} = t, l = r.type === "mark" ?
|
|
1204
|
+
} = t, l = r.type === "mark" ? q(o.markup, {
|
|
1167
1205
|
value: r.value,
|
|
1168
1206
|
meta: r.meta
|
|
1169
|
-
}) :
|
|
1207
|
+
}) : q(o.markup, {
|
|
1170
1208
|
value: r.content
|
|
1171
|
-
}), d =
|
|
1209
|
+
}), d = Yt(i, l, a, c);
|
|
1172
1210
|
if (this.store.state.recovery.set(
|
|
1173
1211
|
e ? {
|
|
1174
1212
|
caret: 0,
|
|
@@ -1178,8 +1216,8 @@ class Kt {
|
|
|
1178
1216
|
} : { caret: a + l.length, anchor: this.store.nodes.input }
|
|
1179
1217
|
), this.store.nodes.input.target) {
|
|
1180
1218
|
this.store.nodes.input.content = d;
|
|
1181
|
-
const
|
|
1182
|
-
u.type === "text" && (u.content = d), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(
|
|
1219
|
+
const f = this.store.state.tokens.get(), u = f[this.store.nodes.input.index];
|
|
1220
|
+
u.type === "text" && (u.content = d), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(N(f)), this.store.events.parse();
|
|
1183
1221
|
}
|
|
1184
1222
|
}));
|
|
1185
1223
|
}
|
|
@@ -1187,56 +1225,7 @@ class Kt {
|
|
|
1187
1225
|
this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0;
|
|
1188
1226
|
}
|
|
1189
1227
|
}
|
|
1190
|
-
class
|
|
1191
|
-
constructor(t) {
|
|
1192
|
-
this.store = t;
|
|
1193
|
-
}
|
|
1194
|
-
#t;
|
|
1195
|
-
#e;
|
|
1196
|
-
#n;
|
|
1197
|
-
#s;
|
|
1198
|
-
#r;
|
|
1199
|
-
#o;
|
|
1200
|
-
#i;
|
|
1201
|
-
#a;
|
|
1202
|
-
enableTrigger(t, e) {
|
|
1203
|
-
if (this.#t) return;
|
|
1204
|
-
this.#t = this.store.events.clearOverlay.on(() => {
|
|
1205
|
-
e(void 0);
|
|
1206
|
-
}), this.#e = this.store.events.checkOverlay.on(() => {
|
|
1207
|
-
const r = Q.find(this.store.state.options.get(), t);
|
|
1208
|
-
e(r);
|
|
1209
|
-
}), this.#n = this.store.events.change.on(() => {
|
|
1210
|
-
const r = this.store.state.showOverlayOn.get(), o = "change";
|
|
1211
|
-
(r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
|
|
1212
|
-
}), this.#s = () => {
|
|
1213
|
-
const r = this.store.state.showOverlayOn.get(), o = "selectionChange";
|
|
1214
|
-
(r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
|
|
1215
|
-
}, this.#r = () => {
|
|
1216
|
-
document.addEventListener("selectionchange", this.#s);
|
|
1217
|
-
}, this.#o = () => {
|
|
1218
|
-
document.removeEventListener("selectionchange", this.#s);
|
|
1219
|
-
};
|
|
1220
|
-
const n = this.store.refs.container;
|
|
1221
|
-
n && (n.addEventListener("focusin", this.#r), n.addEventListener("focusout", this.#o));
|
|
1222
|
-
}
|
|
1223
|
-
enableClose() {
|
|
1224
|
-
this.#i || (this.#i = (t) => {
|
|
1225
|
-
t.key === x.ESC && this.store.events.clearOverlay();
|
|
1226
|
-
}, this.#a = (t) => {
|
|
1227
|
-
const e = t.target;
|
|
1228
|
-
this.store.refs.overlay?.contains(e) || this.store.refs.container?.contains(e) || this.store.events.clearOverlay();
|
|
1229
|
-
}, window.addEventListener("keydown", this.#i), document.addEventListener("click", this.#a, !0));
|
|
1230
|
-
}
|
|
1231
|
-
disableClose() {
|
|
1232
|
-
this.#i && (window.removeEventListener("keydown", this.#i), document.removeEventListener("click", this.#a, !0), this.#i = void 0, this.#a = void 0);
|
|
1233
|
-
}
|
|
1234
|
-
disable() {
|
|
1235
|
-
const t = this.store.refs.container;
|
|
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
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
class te {
|
|
1228
|
+
class ne {
|
|
1240
1229
|
constructor(t) {
|
|
1241
1230
|
this.store = t;
|
|
1242
1231
|
}
|
|
@@ -1281,7 +1270,23 @@ class te {
|
|
|
1281
1270
|
this.store.nodes.focus.caret = n, this.store.state.recovery.set(void 0);
|
|
1282
1271
|
}
|
|
1283
1272
|
}
|
|
1284
|
-
|
|
1273
|
+
function se(s, t) {
|
|
1274
|
+
const { focus: e } = s.nodes;
|
|
1275
|
+
if (e.isMark && !e.isEditable || e.isCaretAtBeginning) {
|
|
1276
|
+
const n = e.prev;
|
|
1277
|
+
return n.focus(), n.isFocused || (n.prev.focus(), t.preventDefault()), e.setCaretToEnd(), !0;
|
|
1278
|
+
}
|
|
1279
|
+
return !1;
|
|
1280
|
+
}
|
|
1281
|
+
function re(s, t) {
|
|
1282
|
+
const { focus: e } = s.nodes;
|
|
1283
|
+
if (e.isMark && !e.isEditable || e.isCaretAtEnd) {
|
|
1284
|
+
const n = e.next;
|
|
1285
|
+
return n.focus(), n.isFocused || (n.next.focus(), t.preventDefault()), !0;
|
|
1286
|
+
}
|
|
1287
|
+
return !1;
|
|
1288
|
+
}
|
|
1289
|
+
class oe {
|
|
1285
1290
|
constructor(t) {
|
|
1286
1291
|
this.store = t;
|
|
1287
1292
|
}
|
|
@@ -1309,7 +1314,7 @@ class ee {
|
|
|
1309
1314
|
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
1315
|
}
|
|
1311
1316
|
}
|
|
1312
|
-
function
|
|
1317
|
+
function ie(s, t) {
|
|
1313
1318
|
if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
|
|
1314
1319
|
t.preventDefault();
|
|
1315
1320
|
const e = window.getSelection(), n = s.refs.container?.firstChild, r = s.refs.container?.lastChild;
|
|
@@ -1317,23 +1322,7 @@ function ne(s, t) {
|
|
|
1317
1322
|
e.setBaseAndExtent(n, 0, r, 1), s.state.selecting.set("all");
|
|
1318
1323
|
}
|
|
1319
1324
|
}
|
|
1320
|
-
|
|
1321
|
-
const { focus: e } = s.nodes;
|
|
1322
|
-
if (e.isMark && !e.isEditable || e.isCaretAtBeginning) {
|
|
1323
|
-
const n = e.prev;
|
|
1324
|
-
return n.focus(), n.isFocused || (n.prev.focus(), t.preventDefault()), e.setCaretToEnd(), !0;
|
|
1325
|
-
}
|
|
1326
|
-
return !1;
|
|
1327
|
-
}
|
|
1328
|
-
function re(s, t) {
|
|
1329
|
-
const { focus: e } = s.nodes;
|
|
1330
|
-
if (e.isMark && !e.isEditable || e.isCaretAtEnd) {
|
|
1331
|
-
const n = e.next;
|
|
1332
|
-
return n.focus(), n.isFocused || (n.next.focus(), t.preventDefault()), !0;
|
|
1333
|
-
}
|
|
1334
|
-
return !1;
|
|
1335
|
-
}
|
|
1336
|
-
class oe {
|
|
1325
|
+
class ae {
|
|
1337
1326
|
constructor(t) {
|
|
1338
1327
|
this.store = t;
|
|
1339
1328
|
}
|
|
@@ -1344,11 +1333,11 @@ class oe {
|
|
|
1344
1333
|
if (this.#t) return;
|
|
1345
1334
|
const t = this.store.refs.container;
|
|
1346
1335
|
t && (this.#t = (e) => {
|
|
1347
|
-
e.key ===
|
|
1336
|
+
e.key === v.LEFT ? se(this.store, e) : e.key === v.RIGHT && re(this.store, e), this.#s(e), ie(this.store, e);
|
|
1348
1337
|
}, this.#e = (e) => {
|
|
1349
|
-
|
|
1338
|
+
de(this.store, e);
|
|
1350
1339
|
}, this.#n = (e) => {
|
|
1351
|
-
|
|
1340
|
+
ce(this.store, e);
|
|
1352
1341
|
}, t.addEventListener("keydown", this.#t), t.addEventListener("paste", this.#e), t.addEventListener("beforeinput", this.#n, !0));
|
|
1353
1342
|
}
|
|
1354
1343
|
disable() {
|
|
@@ -1357,27 +1346,68 @@ class oe {
|
|
|
1357
1346
|
}
|
|
1358
1347
|
#s(t) {
|
|
1359
1348
|
const { focus: e } = this.store.nodes;
|
|
1360
|
-
if (t.key ===
|
|
1349
|
+
if (t.key === v.DELETE || t.key === v.BACKSPACE) {
|
|
1361
1350
|
if (e.isMark) {
|
|
1362
|
-
|
|
1351
|
+
if (e.isEditable && (t.key === v.BACKSPACE && !e.isCaretAtBeginning || t.key === v.DELETE && !e.isCaretAtEnd))
|
|
1352
|
+
return;
|
|
1353
|
+
t.preventDefault(), j("self", this.store);
|
|
1363
1354
|
return;
|
|
1364
1355
|
}
|
|
1365
|
-
t.key ===
|
|
1356
|
+
t.key === v.BACKSPACE && e.isSpan && e.isCaretAtBeginning && e.prev.target && (t.preventDefault(), j("prev", this.store)), t.key === v.DELETE && e.isSpan && e.isCaretAtEnd && e.next.target && (t.preventDefault(), j("next", this.store));
|
|
1366
1357
|
}
|
|
1367
1358
|
}
|
|
1368
1359
|
}
|
|
1369
|
-
function
|
|
1360
|
+
function ce(s, t) {
|
|
1370
1361
|
const e = s.state.selecting.get();
|
|
1371
|
-
if (e
|
|
1372
|
-
|
|
1362
|
+
if (e === "all" && ut(s)) {
|
|
1363
|
+
if (t.inputType === "insertFromPaste") {
|
|
1364
|
+
t.preventDefault();
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
t.preventDefault();
|
|
1368
|
+
const r = t.inputType.startsWith("delete") ? "" : t.data ?? "";
|
|
1369
|
+
ht(s, r);
|
|
1373
1370
|
return;
|
|
1374
1371
|
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1372
|
+
e === "all" && s.state.selecting.set(void 0);
|
|
1373
|
+
const { focus: n } = s.nodes;
|
|
1374
|
+
!n.target || !n.isEditable || le(n, t) && s.events.change();
|
|
1375
|
+
}
|
|
1376
|
+
function le(s, t) {
|
|
1377
|
+
const e = s.caret, n = s.content;
|
|
1378
|
+
let r, o;
|
|
1379
|
+
switch (t.inputType) {
|
|
1380
|
+
case "insertText": {
|
|
1381
|
+
t.preventDefault();
|
|
1382
|
+
const i = t.data ?? "";
|
|
1383
|
+
r = n.slice(0, e) + i + n.slice(e), o = e + i.length;
|
|
1384
|
+
break;
|
|
1385
|
+
}
|
|
1386
|
+
case "deleteContentBackward":
|
|
1387
|
+
case "deleteContentForward":
|
|
1388
|
+
case "deleteWordBackward":
|
|
1389
|
+
case "deleteWordForward":
|
|
1390
|
+
case "deleteSoftLineBackward":
|
|
1391
|
+
case "deleteSoftLineForward": {
|
|
1392
|
+
const i = t.getTargetRanges();
|
|
1393
|
+
if (!i.length) return !1;
|
|
1394
|
+
const { startOffset: a, endOffset: c } = i[0];
|
|
1395
|
+
if (a === c) return !1;
|
|
1396
|
+
t.preventDefault(), r = n.slice(0, a) + n.slice(c), o = a;
|
|
1397
|
+
break;
|
|
1398
|
+
}
|
|
1399
|
+
case "insertFromPaste":
|
|
1400
|
+
case "insertReplacementText": {
|
|
1401
|
+
const i = t.dataTransfer?.getData("text/plain") ?? "", a = t.getTargetRanges(), c = a[0]?.startOffset ?? e, l = a[0]?.endOffset ?? e;
|
|
1402
|
+
t.preventDefault(), r = n.slice(0, c) + i + n.slice(l), o = c + i.length;
|
|
1403
|
+
break;
|
|
1404
|
+
}
|
|
1405
|
+
default:
|
|
1406
|
+
return !1;
|
|
1407
|
+
}
|
|
1408
|
+
return s.content = r, s.caret = o, !0;
|
|
1379
1409
|
}
|
|
1380
|
-
function
|
|
1410
|
+
function de(s, t) {
|
|
1381
1411
|
const e = s.state.selecting.get();
|
|
1382
1412
|
if (e !== "all" || !ut(s)) {
|
|
1383
1413
|
e === "all" && s.state.selecting.set(void 0);
|
|
@@ -1414,7 +1444,7 @@ function ht(s, t) {
|
|
|
1414
1444
|
}), e.focus());
|
|
1415
1445
|
});
|
|
1416
1446
|
}
|
|
1417
|
-
class
|
|
1447
|
+
class ue {
|
|
1418
1448
|
#t = [];
|
|
1419
1449
|
#e = !1;
|
|
1420
1450
|
register(t) {
|
|
@@ -1427,23 +1457,23 @@ class ce {
|
|
|
1427
1457
|
this.#e && (this.#e = !1, this.#t.forEach((t) => t.disable()));
|
|
1428
1458
|
}
|
|
1429
1459
|
}
|
|
1430
|
-
const
|
|
1460
|
+
const R = (s, t) => ({
|
|
1431
1461
|
name: s,
|
|
1432
1462
|
enable: () => t.enable(),
|
|
1433
1463
|
disable: () => t.disable()
|
|
1434
|
-
}),
|
|
1435
|
-
const t = new
|
|
1436
|
-
return t.register(
|
|
1464
|
+
}), he = (s) => {
|
|
1465
|
+
const t = new ue();
|
|
1466
|
+
return t.register(R("keydown", s.controllers.keydown)).register(R("system", s.controllers.system)).register(R("focus", s.controllers.focus)).register(R("textSelection", s.controllers.textSelection)).register(R("contentEditable", s.controllers.contentEditable)), t;
|
|
1437
1467
|
};
|
|
1438
|
-
class
|
|
1468
|
+
class fe {
|
|
1439
1469
|
constructor(t) {
|
|
1440
1470
|
this.store = t;
|
|
1441
1471
|
}
|
|
1442
1472
|
#t = [];
|
|
1443
1473
|
#e = !1;
|
|
1444
1474
|
enable(t) {
|
|
1445
|
-
const { store: e } = this, n =
|
|
1446
|
-
n.enableAll(), this.#t.push(() => n.disableAll()), this.#
|
|
1475
|
+
const { store: e } = this, n = he(e);
|
|
1476
|
+
n.enableAll(), this.#t.push(() => n.disableAll()), this.#n(), t?.getTrigger && this.#s(t.getTrigger);
|
|
1447
1477
|
}
|
|
1448
1478
|
disable() {
|
|
1449
1479
|
for (const t of this.#t)
|
|
@@ -1457,7 +1487,7 @@ class de {
|
|
|
1457
1487
|
*/
|
|
1458
1488
|
syncParser(t, e) {
|
|
1459
1489
|
const { store: n } = this, r = e?.map((i) => i.markup);
|
|
1460
|
-
if (r && r.some(Boolean) ? n.state.parser.set(new
|
|
1490
|
+
if (r && r.some(Boolean) ? n.state.parser.set(new F(r)) : n.state.parser.set(void 0), this.#e) {
|
|
1461
1491
|
n.state.recovery.get() || n.events.parse();
|
|
1462
1492
|
return;
|
|
1463
1493
|
}
|
|
@@ -1470,28 +1500,22 @@ class de {
|
|
|
1470
1500
|
* since focus recovery requires the new DOM to be committed.
|
|
1471
1501
|
*/
|
|
1472
1502
|
recoverFocus() {
|
|
1473
|
-
this.store.state.Mark.get() && this.store.controllers.focus.recover();
|
|
1503
|
+
this.store.controllers.contentEditable.sync(), this.store.state.Mark.get() && this.store.controllers.focus.recover();
|
|
1474
1504
|
}
|
|
1475
1505
|
#n() {
|
|
1476
|
-
const t = this.store.refs.container;
|
|
1477
|
-
if (!t) return;
|
|
1478
|
-
const e = () => this.store.events.change();
|
|
1479
|
-
t.addEventListener("input", e), this.#t.push(() => t.removeEventListener("input", e));
|
|
1480
|
-
}
|
|
1481
|
-
#s() {
|
|
1482
1506
|
const { store: t } = this;
|
|
1483
1507
|
this.#t.push(
|
|
1484
1508
|
t.events.parse.on(() => {
|
|
1485
1509
|
if (t.state.recovery.get()) {
|
|
1486
|
-
const e =
|
|
1510
|
+
const e = N(t.state.tokens.get());
|
|
1487
1511
|
t.state.tokens.set(_(t, e)), t.state.previousValue.set(e);
|
|
1488
1512
|
return;
|
|
1489
1513
|
}
|
|
1490
|
-
t.state.tokens.set(t.nodes.focus.target ?
|
|
1514
|
+
t.state.tokens.set(t.nodes.focus.target ? Gt(t) : Ut(t));
|
|
1491
1515
|
})
|
|
1492
1516
|
);
|
|
1493
1517
|
}
|
|
1494
|
-
#
|
|
1518
|
+
#s(t) {
|
|
1495
1519
|
const { store: e } = this;
|
|
1496
1520
|
e.controllers.overlay.enableTrigger(t, (n) => e.state.overlayMatch.set(n)), this.#t.push(() => e.controllers.overlay.disable()), this.#t.push(
|
|
1497
1521
|
e.state.overlayMatch.on((n) => {
|
|
@@ -1500,28 +1524,119 @@ class de {
|
|
|
1500
1524
|
);
|
|
1501
1525
|
}
|
|
1502
1526
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1527
|
+
function ge(s, t) {
|
|
1528
|
+
const e = t.toLowerCase();
|
|
1529
|
+
return s.filter((n) => n.toLowerCase().indexOf(e) > -1);
|
|
1530
|
+
}
|
|
1531
|
+
function pe(s, t, e) {
|
|
1532
|
+
return {
|
|
1533
|
+
type: "mark",
|
|
1534
|
+
value: t,
|
|
1535
|
+
meta: e,
|
|
1536
|
+
content: "",
|
|
1537
|
+
position: {
|
|
1538
|
+
start: s.index,
|
|
1539
|
+
end: s.index + s.span.length
|
|
1540
|
+
},
|
|
1541
|
+
descriptor: {
|
|
1542
|
+
markup: s.option.markup,
|
|
1543
|
+
index: 0,
|
|
1544
|
+
segments: [],
|
|
1545
|
+
gapTypes: [],
|
|
1546
|
+
hasNested: !1,
|
|
1547
|
+
hasTwoValues: !1,
|
|
1548
|
+
segmentGlobalIndices: []
|
|
1549
|
+
},
|
|
1550
|
+
children: [],
|
|
1551
|
+
nested: void 0
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
class ve {
|
|
1555
|
+
constructor(t) {
|
|
1556
|
+
this.store = t;
|
|
1557
|
+
}
|
|
1558
|
+
#t;
|
|
1559
|
+
#e;
|
|
1560
|
+
#n;
|
|
1561
|
+
#s;
|
|
1562
|
+
#r;
|
|
1563
|
+
#o;
|
|
1564
|
+
#i;
|
|
1565
|
+
#a;
|
|
1566
|
+
enableTrigger(t, e) {
|
|
1567
|
+
if (this.#t) return;
|
|
1568
|
+
this.#t = this.store.events.clearOverlay.on(() => {
|
|
1569
|
+
e(void 0);
|
|
1570
|
+
}), this.#e = this.store.events.checkOverlay.on(() => {
|
|
1571
|
+
const r = tt.find(this.store.state.options.get(), t);
|
|
1572
|
+
e(r);
|
|
1573
|
+
}), this.#n = this.store.events.change.on(() => {
|
|
1574
|
+
const r = this.store.state.showOverlayOn.get(), o = "change";
|
|
1575
|
+
(r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
|
|
1576
|
+
}), this.#s = () => {
|
|
1577
|
+
const r = this.store.state.showOverlayOn.get(), o = "selectionChange";
|
|
1578
|
+
(r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
|
|
1579
|
+
}, this.#r = () => {
|
|
1580
|
+
document.addEventListener("selectionchange", this.#s);
|
|
1581
|
+
}, this.#o = () => {
|
|
1582
|
+
document.removeEventListener("selectionchange", this.#s);
|
|
1583
|
+
};
|
|
1584
|
+
const n = this.store.refs.container;
|
|
1585
|
+
n && (n.addEventListener("focusin", this.#r), n.addEventListener("focusout", this.#o));
|
|
1586
|
+
}
|
|
1587
|
+
enableClose() {
|
|
1588
|
+
this.#i || (this.#i = (t) => {
|
|
1589
|
+
t.key === v.ESC && this.store.events.clearOverlay();
|
|
1590
|
+
}, this.#a = (t) => {
|
|
1591
|
+
const e = t.target;
|
|
1592
|
+
this.store.refs.overlay?.contains(e) || this.store.refs.container?.contains(e) || this.store.events.clearOverlay();
|
|
1593
|
+
}, window.addEventListener("keydown", this.#i), document.addEventListener("click", this.#a, !0));
|
|
1594
|
+
}
|
|
1595
|
+
disableClose() {
|
|
1596
|
+
this.#i && (window.removeEventListener("keydown", this.#i), document.removeEventListener("click", this.#a, !0), this.#i = void 0, this.#a = void 0);
|
|
1597
|
+
}
|
|
1598
|
+
disable() {
|
|
1599
|
+
const t = this.store.refs.container;
|
|
1600
|
+
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;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
function me(s, t, e) {
|
|
1604
|
+
if (e === 0) return { action: "none", index: t };
|
|
1605
|
+
const n = !isNaN(t);
|
|
1606
|
+
switch (s) {
|
|
1607
|
+
case v.UP:
|
|
1608
|
+
return { action: "up", index: n ? (e + (t - 1) % e) % e : 0 };
|
|
1609
|
+
case v.DOWN:
|
|
1610
|
+
return { action: "down", index: n ? (t + 1) % e : 0 };
|
|
1611
|
+
case v.ENTER:
|
|
1612
|
+
return n ? { action: "select", index: t } : { action: "none", index: t };
|
|
1613
|
+
default:
|
|
1614
|
+
return { action: "none", index: t };
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
class ye {
|
|
1618
|
+
key = new Qt();
|
|
1505
1619
|
nodes = {
|
|
1506
1620
|
focus: new V(void 0, this),
|
|
1507
1621
|
input: new V(void 0, this)
|
|
1508
1622
|
};
|
|
1509
1623
|
state;
|
|
1510
|
-
events =
|
|
1624
|
+
events = Jt();
|
|
1511
1625
|
refs = {
|
|
1512
1626
|
container: null,
|
|
1513
1627
|
overlay: null
|
|
1514
1628
|
};
|
|
1515
1629
|
controllers = {
|
|
1516
|
-
overlay: new
|
|
1517
|
-
focus: new
|
|
1518
|
-
keydown: new
|
|
1519
|
-
system: new
|
|
1520
|
-
textSelection: new
|
|
1630
|
+
overlay: new ve(this),
|
|
1631
|
+
focus: new ne(this),
|
|
1632
|
+
keydown: new ae(this),
|
|
1633
|
+
system: new ee(this),
|
|
1634
|
+
textSelection: new oe(this),
|
|
1635
|
+
contentEditable: new te(this)
|
|
1521
1636
|
};
|
|
1522
|
-
lifecycle = new
|
|
1637
|
+
lifecycle = new fe(this);
|
|
1523
1638
|
constructor(t) {
|
|
1524
|
-
this.state =
|
|
1639
|
+
this.state = Xt(
|
|
1525
1640
|
{
|
|
1526
1641
|
tokens: [],
|
|
1527
1642
|
parser: void 0,
|
|
@@ -1560,7 +1675,7 @@ class ue {
|
|
|
1560
1675
|
};
|
|
1561
1676
|
}
|
|
1562
1677
|
}
|
|
1563
|
-
class
|
|
1678
|
+
class xe {
|
|
1564
1679
|
ref;
|
|
1565
1680
|
#t;
|
|
1566
1681
|
#e;
|
|
@@ -1613,20 +1728,20 @@ class he {
|
|
|
1613
1728
|
}
|
|
1614
1729
|
}
|
|
1615
1730
|
let ft = 0;
|
|
1616
|
-
function
|
|
1731
|
+
function ot(s) {
|
|
1617
1732
|
return `block-${ft++}-${s}`;
|
|
1618
1733
|
}
|
|
1619
|
-
function
|
|
1734
|
+
function ke() {
|
|
1620
1735
|
ft = 0;
|
|
1621
1736
|
}
|
|
1622
|
-
function
|
|
1737
|
+
function we(s) {
|
|
1623
1738
|
if (s.length === 0) return [];
|
|
1624
|
-
|
|
1739
|
+
ke();
|
|
1625
1740
|
const t = [];
|
|
1626
1741
|
let e = [], n = -1;
|
|
1627
1742
|
const r = (o) => {
|
|
1628
1743
|
e.length !== 0 && (t.push({
|
|
1629
|
-
id:
|
|
1744
|
+
id: ot(n),
|
|
1630
1745
|
tokens: [...e],
|
|
1631
1746
|
startPos: n,
|
|
1632
1747
|
endPos: o
|
|
@@ -1636,7 +1751,7 @@ function ge(s) {
|
|
|
1636
1751
|
if (o.type === "mark") {
|
|
1637
1752
|
o.content.endsWith(`
|
|
1638
1753
|
`) ? (r(o.position.start), t.push({
|
|
1639
|
-
id:
|
|
1754
|
+
id: ot(o.position.start),
|
|
1640
1755
|
tokens: [o],
|
|
1641
1756
|
startPos: o.position.start,
|
|
1642
1757
|
endPos: o.position.end
|
|
@@ -1644,7 +1759,7 @@ function ge(s) {
|
|
|
1644
1759
|
continue;
|
|
1645
1760
|
}
|
|
1646
1761
|
if (o.type !== "text") continue;
|
|
1647
|
-
const a =
|
|
1762
|
+
const a = Se(o);
|
|
1648
1763
|
for (let c = 0; c < a.length; c++) {
|
|
1649
1764
|
const l = a[c];
|
|
1650
1765
|
if (l.isNewline) {
|
|
@@ -1664,7 +1779,7 @@ function ge(s) {
|
|
|
1664
1779
|
}
|
|
1665
1780
|
return t;
|
|
1666
1781
|
}
|
|
1667
|
-
function
|
|
1782
|
+
function Se(s) {
|
|
1668
1783
|
const t = [], { content: e, position: n } = s;
|
|
1669
1784
|
let r = n.start;
|
|
1670
1785
|
const o = [], i = () => {
|
|
@@ -1700,12 +1815,12 @@ function pe(s) {
|
|
|
1700
1815
|
}
|
|
1701
1816
|
return i(), t;
|
|
1702
1817
|
}
|
|
1703
|
-
function
|
|
1818
|
+
function Ce(s, t, e, n) {
|
|
1704
1819
|
if (e === n || e === n - 1 || t.length < 2 || e < 0 || e >= t.length || n < 0 || n > t.length) return s;
|
|
1705
|
-
const r =
|
|
1706
|
-
return
|
|
1820
|
+
const r = be(s, t), o = Te(r, e, n);
|
|
1821
|
+
return Ee(o);
|
|
1707
1822
|
}
|
|
1708
|
-
function
|
|
1823
|
+
function be(s, t) {
|
|
1709
1824
|
return t.map((e, n) => {
|
|
1710
1825
|
const r = s.substring(e.startPos, e.endPos);
|
|
1711
1826
|
let o = "";
|
|
@@ -1720,7 +1835,7 @@ function me(s, t) {
|
|
|
1720
1835
|
};
|
|
1721
1836
|
});
|
|
1722
1837
|
}
|
|
1723
|
-
function
|
|
1838
|
+
function Ee(s) {
|
|
1724
1839
|
const t = [];
|
|
1725
1840
|
for (let e = 0; e < s.length; e++) {
|
|
1726
1841
|
const n = s[e], r = e === s.length - 1;
|
|
@@ -1731,11 +1846,11 @@ function ye(s) {
|
|
|
1731
1846
|
}
|
|
1732
1847
|
return t.join("");
|
|
1733
1848
|
}
|
|
1734
|
-
function
|
|
1849
|
+
function Te(s, t, e) {
|
|
1735
1850
|
const n = [...s], [r] = n.splice(t, 1), o = e > t ? e - 1 : e;
|
|
1736
|
-
return n.splice(o, 0, r),
|
|
1851
|
+
return n.splice(o, 0, r), Ne(n, s), n;
|
|
1737
1852
|
}
|
|
1738
|
-
function
|
|
1853
|
+
function Ne(s, t) {
|
|
1739
1854
|
for (let e = 0; e < s.length - 1; e++) {
|
|
1740
1855
|
const n = s[e].index, r = s[e + 1].index;
|
|
1741
1856
|
if (Math.abs(n - r) === 1) {
|
|
@@ -1747,91 +1862,30 @@ function ke(s, t) {
|
|
|
1747
1862
|
`;
|
|
1748
1863
|
}
|
|
1749
1864
|
}
|
|
1750
|
-
const
|
|
1751
|
-
|
|
1752
|
-
|
|
1865
|
+
const Ie = (s) => () => {
|
|
1866
|
+
const [t, e] = M(() => s.get());
|
|
1867
|
+
return P(() => s.on(e), [s]), t;
|
|
1753
1868
|
};
|
|
1754
|
-
function
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
const e =
|
|
1759
|
-
|
|
1869
|
+
function Me(s, t) {
|
|
1870
|
+
St(t, () => s.createHandler(), [s]), P(() => (s.lifecycle.enable({
|
|
1871
|
+
getTrigger: (a) => a.overlay?.trigger
|
|
1872
|
+
}), () => s.lifecycle.disable()), []);
|
|
1873
|
+
const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0, i = s.state.tokens.use();
|
|
1874
|
+
P(() => {
|
|
1875
|
+
s.lifecycle.syncParser(e, o);
|
|
1876
|
+
}, [e, o]), P(() => {
|
|
1877
|
+
s.lifecycle.recoverFocus();
|
|
1878
|
+
}, [i]);
|
|
1760
1879
|
}
|
|
1761
|
-
const
|
|
1762
|
-
|
|
1880
|
+
const et = at(void 0);
|
|
1881
|
+
et.displayName = "StoreContext";
|
|
1763
1882
|
function E() {
|
|
1764
|
-
const s = ct(
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
const t = at(void 0);
|
|
1769
|
-
return t.displayName = s, [() => {
|
|
1770
|
-
const n = ct(t);
|
|
1771
|
-
if (n === void 0)
|
|
1772
|
-
throw new Error(`Context "${s}" not found. Make sure to wrap component in its Provider.`);
|
|
1773
|
-
return n;
|
|
1774
|
-
}, t.Provider, t];
|
|
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;
|
|
1781
|
-
if (!d)
|
|
1782
|
-
throw new Error(
|
|
1783
|
-
`No ${s} component found. Provide either option.${s}.slot, global ${s === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
|
|
1784
|
-
);
|
|
1785
|
-
return [d, l];
|
|
1883
|
+
const s = ct(et);
|
|
1884
|
+
if (s === void 0)
|
|
1885
|
+
throw new Error("Store not found. Make sure to wrap component in StoreContext.");
|
|
1886
|
+
return s;
|
|
1786
1887
|
}
|
|
1787
|
-
|
|
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 = {
|
|
1789
|
-
value: s.value,
|
|
1790
|
-
meta: s.meta,
|
|
1791
|
-
nested: s.nested?.content,
|
|
1792
|
-
children: s.children.length > 0 ? o : void 0
|
|
1793
|
-
}, [a, c] = gt("mark", r, i);
|
|
1794
|
-
return /* @__PURE__ */ f(a, { ...c });
|
|
1795
|
-
}
|
|
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]);
|
|
1798
|
-
if (s.type !== "text")
|
|
1799
|
-
throw new Error("TextSpan component expects a TextToken");
|
|
1800
|
-
return St(() => {
|
|
1801
|
-
e.current && e.current.textContent !== s.content && (e.current.textContent = s.content);
|
|
1802
|
-
}, [s.content]), /* @__PURE__ */ f(
|
|
1803
|
-
i,
|
|
1804
|
-
{
|
|
1805
|
-
...a,
|
|
1806
|
-
ref: e,
|
|
1807
|
-
contentEditable: !n,
|
|
1808
|
-
onPaste: Ee,
|
|
1809
|
-
suppressContentEditableWarning: !0
|
|
1810
|
-
}
|
|
1811
|
-
);
|
|
1812
|
-
};
|
|
1813
|
-
function Ee(s) {
|
|
1814
|
-
s.preventDefault();
|
|
1815
|
-
const t = s.clipboardData.getData("text");
|
|
1816
|
-
document.execCommand("insertText", !1, t);
|
|
1817
|
-
}
|
|
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]);
|
|
1822
|
-
return /* @__PURE__ */ f(
|
|
1823
|
-
c,
|
|
1824
|
-
{
|
|
1825
|
-
ref: (d) => a.container = d,
|
|
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 = {
|
|
1888
|
+
const X = {
|
|
1835
1889
|
position: "absolute",
|
|
1836
1890
|
left: -28,
|
|
1837
1891
|
top: 2,
|
|
@@ -1853,13 +1907,13 @@ const q = {
|
|
|
1853
1907
|
margin: 0,
|
|
1854
1908
|
font: "inherit",
|
|
1855
1909
|
lineHeight: 1
|
|
1856
|
-
},
|
|
1857
|
-
...
|
|
1910
|
+
}, gt = {
|
|
1911
|
+
...X,
|
|
1858
1912
|
opacity: 1
|
|
1859
|
-
},
|
|
1860
|
-
...
|
|
1913
|
+
}, Pe = {
|
|
1914
|
+
...gt,
|
|
1861
1915
|
cursor: "grabbing"
|
|
1862
|
-
},
|
|
1916
|
+
}, Le = {
|
|
1863
1917
|
position: "relative",
|
|
1864
1918
|
paddingLeft: 4,
|
|
1865
1919
|
transition: "opacity 0.2s ease"
|
|
@@ -1872,80 +1926,114 @@ const q = {
|
|
|
1872
1926
|
borderRadius: 1,
|
|
1873
1927
|
pointerEvents: "none",
|
|
1874
1928
|
zIndex: 10
|
|
1875
|
-
},
|
|
1876
|
-
/* @__PURE__ */
|
|
1877
|
-
/* @__PURE__ */
|
|
1878
|
-
/* @__PURE__ */
|
|
1879
|
-
/* @__PURE__ */
|
|
1880
|
-
/* @__PURE__ */
|
|
1881
|
-
/* @__PURE__ */
|
|
1929
|
+
}, pt = O(() => /* @__PURE__ */ J("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", children: [
|
|
1930
|
+
/* @__PURE__ */ h("circle", { cx: "5", cy: "3", r: "1.5" }),
|
|
1931
|
+
/* @__PURE__ */ h("circle", { cx: "11", cy: "3", r: "1.5" }),
|
|
1932
|
+
/* @__PURE__ */ h("circle", { cx: "5", cy: "8", r: "1.5" }),
|
|
1933
|
+
/* @__PURE__ */ h("circle", { cx: "11", cy: "8", r: "1.5" }),
|
|
1934
|
+
/* @__PURE__ */ h("circle", { cx: "5", cy: "13", r: "1.5" }),
|
|
1935
|
+
/* @__PURE__ */ h("circle", { cx: "11", cy: "13", r: "1.5" })
|
|
1882
1936
|
] }));
|
|
1883
|
-
|
|
1884
|
-
const
|
|
1885
|
-
const [r, o] =
|
|
1937
|
+
pt.displayName = "GripIcon";
|
|
1938
|
+
const vt = O(({ blockIndex: s, children: t, readOnly: e, onReorder: n }) => {
|
|
1939
|
+
const [r, o] = M(!1), [i, a] = M(!1), [c, l] = M(null), d = H(null), f = k(() => o(!0), []), u = k(() => o(!1), []), g = k(
|
|
1886
1940
|
(p) => {
|
|
1887
1941
|
p.dataTransfer.effectAllowed = "move", p.dataTransfer.setData("text/plain", String(s)), a(!0), d.current && p.dataTransfer.setDragImage(d.current, 0, 0);
|
|
1888
1942
|
},
|
|
1889
1943
|
[s]
|
|
1890
|
-
),
|
|
1944
|
+
), m = k(() => {
|
|
1891
1945
|
a(!1), l(null);
|
|
1892
1946
|
}, []), C = k((p) => {
|
|
1893
1947
|
if (p.preventDefault(), p.dataTransfer.dropEffect = "move", !d.current) return;
|
|
1894
|
-
const D = d.current.getBoundingClientRect(),
|
|
1895
|
-
l(p.clientY <
|
|
1896
|
-
}, []),
|
|
1948
|
+
const D = d.current.getBoundingClientRect(), G = D.top + D.height / 2;
|
|
1949
|
+
l(p.clientY < G ? "before" : "after");
|
|
1950
|
+
}, []), y = k((p) => {
|
|
1897
1951
|
p.currentTarget.contains(p.relatedTarget) || l(null);
|
|
1898
1952
|
}, []), b = k(
|
|
1899
1953
|
(p) => {
|
|
1900
1954
|
p.preventDefault();
|
|
1901
1955
|
const D = parseInt(p.dataTransfer.getData("text/plain"), 10);
|
|
1902
1956
|
if (isNaN(D)) return;
|
|
1903
|
-
const
|
|
1904
|
-
l(null), n(D,
|
|
1957
|
+
const G = c === "before" ? s : s + 1;
|
|
1958
|
+
l(null), n(D, G);
|
|
1905
1959
|
},
|
|
1906
1960
|
[s, c, n]
|
|
1907
|
-
),
|
|
1908
|
-
...
|
|
1961
|
+
), I = {
|
|
1962
|
+
...Le,
|
|
1909
1963
|
opacity: i ? 0.4 : 1
|
|
1910
|
-
}, L = e ? { ...
|
|
1911
|
-
return /* @__PURE__ */
|
|
1964
|
+
}, L = e ? { ...X, display: "none" } : i ? Pe : r ? gt : X;
|
|
1965
|
+
return /* @__PURE__ */ J(
|
|
1912
1966
|
"div",
|
|
1913
1967
|
{
|
|
1914
1968
|
ref: d,
|
|
1915
|
-
style:
|
|
1916
|
-
onMouseEnter:
|
|
1969
|
+
style: I,
|
|
1970
|
+
onMouseEnter: f,
|
|
1917
1971
|
onMouseLeave: u,
|
|
1918
1972
|
onDragOver: C,
|
|
1919
|
-
onDragLeave:
|
|
1973
|
+
onDragLeave: y,
|
|
1920
1974
|
onDrop: b,
|
|
1921
1975
|
children: [
|
|
1922
|
-
c === "before" && /* @__PURE__ */
|
|
1923
|
-
/* @__PURE__ */
|
|
1976
|
+
c === "before" && /* @__PURE__ */ h("div", { style: { ...it, top: -1 } }),
|
|
1977
|
+
/* @__PURE__ */ h(
|
|
1924
1978
|
"button",
|
|
1925
1979
|
{
|
|
1926
1980
|
type: "button",
|
|
1927
1981
|
draggable: !e,
|
|
1928
|
-
onDragStart:
|
|
1929
|
-
onDragEnd:
|
|
1982
|
+
onDragStart: g,
|
|
1983
|
+
onDragEnd: m,
|
|
1930
1984
|
style: L,
|
|
1931
1985
|
"aria-label": "Drag to reorder",
|
|
1932
|
-
children: /* @__PURE__ */
|
|
1986
|
+
children: /* @__PURE__ */ h(pt, {})
|
|
1933
1987
|
}
|
|
1934
1988
|
),
|
|
1935
1989
|
t,
|
|
1936
|
-
c === "after" && /* @__PURE__ */
|
|
1990
|
+
c === "after" && /* @__PURE__ */ h("div", { style: { ...it, bottom: -1 } })
|
|
1937
1991
|
]
|
|
1938
1992
|
}
|
|
1939
1993
|
);
|
|
1940
1994
|
});
|
|
1941
|
-
|
|
1942
|
-
const
|
|
1943
|
-
|
|
1944
|
-
|
|
1995
|
+
vt.displayName = "DraggableBlock";
|
|
1996
|
+
const $ = at(void 0);
|
|
1997
|
+
$.displayName = "TokenProvider";
|
|
1998
|
+
function nt() {
|
|
1999
|
+
const s = ct($);
|
|
2000
|
+
if (s === void 0)
|
|
2001
|
+
throw new Error("Token not found. Make sure to wrap component in TokenContext.Provider.");
|
|
2002
|
+
return s;
|
|
2003
|
+
}
|
|
2004
|
+
function mt(s, t, e, n) {
|
|
2005
|
+
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, l = Nt(c, e ?? {}), d = l.slot || a || n;
|
|
2006
|
+
if (!d)
|
|
2007
|
+
throw new Error(
|
|
2008
|
+
`No ${s} component found. Provide either option.${s}.slot, global ${s === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
|
|
2009
|
+
);
|
|
2010
|
+
return [d, l];
|
|
2011
|
+
}
|
|
2012
|
+
function Ae() {
|
|
2013
|
+
const s = nt(), t = E(), e = t.state.options.use(), n = t.key, r = e?.[s.descriptor.index], o = s.children.map((l) => /* @__PURE__ */ h(W, { mark: l, isNested: !0 }, n.get(l))), i = {
|
|
2014
|
+
value: s.value,
|
|
2015
|
+
meta: s.meta,
|
|
2016
|
+
nested: s.nested?.content,
|
|
2017
|
+
children: s.children.length > 0 ? o : void 0
|
|
2018
|
+
}, [a, c] = mt("mark", r, i);
|
|
2019
|
+
return /* @__PURE__ */ h(a, { ...c });
|
|
2020
|
+
}
|
|
2021
|
+
const Oe = () => {
|
|
2022
|
+
const s = nt(), t = E(), e = H(null), n = t.state.slots.use(), r = t.state.slotProps.use(), o = S(() => Q("span", n), [n]), i = S(() => K("span", r), [r]);
|
|
2023
|
+
if (s.type !== "text")
|
|
2024
|
+
throw new Error("TextSpan component expects a TextToken");
|
|
2025
|
+
return Ct(() => {
|
|
2026
|
+
e.current && e.current.textContent !== s.content && (e.current.textContent = s.content);
|
|
2027
|
+
}, [s.content]), /* @__PURE__ */ h(o, { ...i, ref: e });
|
|
2028
|
+
}, W = O(({ mark: s, isNested: t = !1 }) => s.type === "mark" ? /* @__PURE__ */ h($, { value: s, children: /* @__PURE__ */ h(Ae, {}) }) : t ? /* @__PURE__ */ h(wt, { children: s.content }) : /* @__PURE__ */ h($, { value: s, children: /* @__PURE__ */ h(Oe, {}) }));
|
|
2029
|
+
W.displayName = "Token";
|
|
2030
|
+
const yt = O(() => {
|
|
2031
|
+
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, f = S(() => Q("container", e), [e]), u = S(() => K("container", n), [n]), g = S(() => we(t), [t]), m = H(g);
|
|
2032
|
+
m.current = g;
|
|
1945
2033
|
const C = k(
|
|
1946
|
-
(
|
|
2034
|
+
(y, b) => {
|
|
1947
2035
|
if (!a || !c) return;
|
|
1948
|
-
const
|
|
2036
|
+
const I = m.current, L = Ce(a, I, y, b);
|
|
1949
2037
|
if (L !== a) {
|
|
1950
2038
|
const p = _(s, L);
|
|
1951
2039
|
s.state.tokens.set(p), s.state.previousValue.set(L), c(L);
|
|
@@ -1953,34 +2041,36 @@ const xt = O(() => {
|
|
|
1953
2041
|
},
|
|
1954
2042
|
[s, a, c]
|
|
1955
2043
|
);
|
|
1956
|
-
return /* @__PURE__ */
|
|
1957
|
-
|
|
2044
|
+
return /* @__PURE__ */ h(
|
|
2045
|
+
f,
|
|
1958
2046
|
{
|
|
1959
|
-
ref: (
|
|
2047
|
+
ref: (y) => d.container = y,
|
|
1960
2048
|
...u,
|
|
1961
2049
|
className: r,
|
|
1962
2050
|
style: o,
|
|
1963
|
-
children:
|
|
2051
|
+
children: g.map((y, b) => /* @__PURE__ */ h(vt, { blockIndex: b, readOnly: i, onReorder: C, children: y.tokens.map((I) => /* @__PURE__ */ h(W, { mark: I }, l.get(I))) }, y.id))
|
|
1964
2052
|
}
|
|
1965
2053
|
);
|
|
1966
2054
|
});
|
|
1967
|
-
|
|
1968
|
-
|
|
2055
|
+
yt.displayName = "BlockContainer";
|
|
2056
|
+
const xt = O(() => {
|
|
2057
|
+
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(() => Q("container", e), [e]), l = S(() => K("container", n), [n]);
|
|
2058
|
+
return /* @__PURE__ */ h(
|
|
2059
|
+
c,
|
|
2060
|
+
{
|
|
2061
|
+
ref: (d) => a.container = d,
|
|
2062
|
+
...l,
|
|
2063
|
+
className: r,
|
|
2064
|
+
style: o,
|
|
2065
|
+
children: t.map((d) => /* @__PURE__ */ h(W, { mark: d }, i.get(d)))
|
|
2066
|
+
}
|
|
2067
|
+
);
|
|
2068
|
+
});
|
|
2069
|
+
xt.displayName = "Container";
|
|
2070
|
+
function De() {
|
|
1969
2071
|
const s = E(), t = s.state.overlayMatch.use(), e = w.getAbsolutePosition(), n = k(() => s.events.clearOverlay(), []), r = k(
|
|
1970
2072
|
(i) => {
|
|
1971
|
-
const a =
|
|
1972
|
-
type: "mark",
|
|
1973
|
-
value: i.value,
|
|
1974
|
-
meta: i.meta,
|
|
1975
|
-
content: "",
|
|
1976
|
-
position: { start: t.index, end: t.index + t.span.length },
|
|
1977
|
-
descriptor: {
|
|
1978
|
-
index: 0,
|
|
1979
|
-
markup: t.option.markup
|
|
1980
|
-
},
|
|
1981
|
-
children: [],
|
|
1982
|
-
nested: void 0
|
|
1983
|
-
};
|
|
2073
|
+
const a = pe(t, i.value, i.meta);
|
|
1984
2074
|
s.events.select({ mark: a, match: t }), s.events.clearOverlay();
|
|
1985
2075
|
},
|
|
1986
2076
|
[t]
|
|
@@ -1997,82 +2087,51 @@ function Ie() {
|
|
|
1997
2087
|
);
|
|
1998
2088
|
return { match: t, style: e, select: r, close: n, ref: o };
|
|
1999
2089
|
}
|
|
2000
|
-
const
|
|
2001
|
-
Container:
|
|
2002
|
-
Suggestions:
|
|
2003
|
-
suggestionActive:
|
|
2004
|
-
},
|
|
2005
|
-
const s = E(), { match: t, select: e, style: n, ref: r } =
|
|
2006
|
-
|
|
2007
|
-
[t.value, a]
|
|
2008
|
-
), l = c.length;
|
|
2009
|
-
return M(() => {
|
|
2090
|
+
const Re = "_Container_1lmfr_1", _e = "_Suggestions_1lmfr_10", Be = "_suggestionActive_1lmfr_38", Z = {
|
|
2091
|
+
Container: Re,
|
|
2092
|
+
Suggestions: _e,
|
|
2093
|
+
suggestionActive: Be
|
|
2094
|
+
}, Ve = () => {
|
|
2095
|
+
const s = E(), { match: t, select: e, style: n, ref: r } = De(), [o, i] = M(NaN), a = t.option.overlay?.data || [], c = S(() => ge(a, t.value), [t.value, a]), l = c.length;
|
|
2096
|
+
return P(() => {
|
|
2010
2097
|
const d = s.refs.container;
|
|
2011
2098
|
if (!d) return;
|
|
2012
|
-
const
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
u.preventDefault(), i((h) => isNaN(h) ? 0 : (h + 1) % l);
|
|
2099
|
+
const f = (u) => {
|
|
2100
|
+
const g = me(u.key, o, l);
|
|
2101
|
+
switch (g.action) {
|
|
2102
|
+
case "up":
|
|
2103
|
+
case "down":
|
|
2104
|
+
u.preventDefault(), i(g.index);
|
|
2019
2105
|
break;
|
|
2020
|
-
case
|
|
2021
|
-
u.preventDefault()
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
return e({ value: v, meta: h.toString() }), h;
|
|
2025
|
-
});
|
|
2106
|
+
case "select":
|
|
2107
|
+
u.preventDefault();
|
|
2108
|
+
const m = c[g.index];
|
|
2109
|
+
e({ value: m, meta: g.index.toString() });
|
|
2026
2110
|
break;
|
|
2027
2111
|
}
|
|
2028
2112
|
};
|
|
2029
|
-
return d.addEventListener("keydown",
|
|
2030
|
-
}, [l, c]), c.length ? /* @__PURE__ */
|
|
2031
|
-
const u =
|
|
2032
|
-
return /* @__PURE__ */
|
|
2113
|
+
return d.addEventListener("keydown", f), () => d.removeEventListener("keydown", f);
|
|
2114
|
+
}, [l, c, o]), c.length ? /* @__PURE__ */ h("ul", { ref: r, className: Z.Suggestions, style: n, children: c.map((d, f) => {
|
|
2115
|
+
const u = f === o ? Z.suggestionActive : void 0;
|
|
2116
|
+
return /* @__PURE__ */ h(
|
|
2033
2117
|
"li",
|
|
2034
2118
|
{
|
|
2035
|
-
ref: (
|
|
2036
|
-
u &&
|
|
2119
|
+
ref: (g) => {
|
|
2120
|
+
u && g && g.scrollIntoView(!1);
|
|
2037
2121
|
},
|
|
2038
2122
|
className: u,
|
|
2039
|
-
onClick: (
|
|
2123
|
+
onClick: (g) => e({ value: d, meta: f.toString() }),
|
|
2040
2124
|
children: d
|
|
2041
2125
|
},
|
|
2042
2126
|
d
|
|
2043
2127
|
);
|
|
2044
2128
|
}) }) : null;
|
|
2045
2129
|
}, kt = O(() => {
|
|
2046
|
-
const s = E(), t = s.state.overlayMatch.use(), e = S(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] =
|
|
2047
|
-
if (e) return /* @__PURE__ */
|
|
2130
|
+
const s = E(), t = s.state.overlayMatch.use(), e = S(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] = mt("overlay", t?.option, void 0, Ve);
|
|
2131
|
+
if (e) return /* @__PURE__ */ h(n, { ...r ?? {} }, e);
|
|
2048
2132
|
});
|
|
2049
2133
|
kt.displayName = "OverlayRenderer";
|
|
2050
|
-
function
|
|
2051
|
-
Ct(t, () => s.createHandler(), [s]), M(() => (s.lifecycle.enable({
|
|
2052
|
-
getTrigger: (a) => a.overlay?.trigger
|
|
2053
|
-
}), () => s.lifecycle.disable()), []);
|
|
2054
|
-
const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0;
|
|
2055
|
-
M(() => {
|
|
2056
|
-
s.lifecycle.syncParser(e, o);
|
|
2057
|
-
}, [e, o]);
|
|
2058
|
-
const i = s.state.tokens.use();
|
|
2059
|
-
M(() => {
|
|
2060
|
-
s.lifecycle.recoverFocus();
|
|
2061
|
-
}, [i]);
|
|
2062
|
-
}
|
|
2063
|
-
const De = (s) => () => {
|
|
2064
|
-
const [t, e] = P(() => s.get());
|
|
2065
|
-
return M(() => s.on(e), [s]), t;
|
|
2066
|
-
}, _e = [
|
|
2067
|
-
{
|
|
2068
|
-
markup: Pt,
|
|
2069
|
-
overlay: {
|
|
2070
|
-
trigger: It,
|
|
2071
|
-
data: []
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
];
|
|
2075
|
-
function Fe(s) {
|
|
2134
|
+
function Ue(s) {
|
|
2076
2135
|
const {
|
|
2077
2136
|
ref: t,
|
|
2078
2137
|
value: e,
|
|
@@ -2084,54 +2143,52 @@ function Fe(s) {
|
|
|
2084
2143
|
Overlay: c,
|
|
2085
2144
|
slots: l,
|
|
2086
2145
|
slotProps: d,
|
|
2087
|
-
options:
|
|
2146
|
+
options: f = Lt,
|
|
2088
2147
|
showOverlayOn: u = "change",
|
|
2089
|
-
className:
|
|
2090
|
-
style:
|
|
2091
|
-
} = s, C =
|
|
2092
|
-
b.state.set({
|
|
2148
|
+
className: g,
|
|
2149
|
+
style: m
|
|
2150
|
+
} = s, C = Et(Z.Container, g, d?.container?.className), y = Tt(m, d?.container?.style), [b] = M(() => new ye({ createUseHook: Ie }));
|
|
2151
|
+
return b.state.set({
|
|
2093
2152
|
value: e,
|
|
2094
2153
|
defaultValue: n,
|
|
2095
2154
|
onChange: r,
|
|
2096
2155
|
readOnly: o,
|
|
2097
|
-
options:
|
|
2156
|
+
options: f,
|
|
2098
2157
|
showOverlayOn: u,
|
|
2099
2158
|
Mark: a,
|
|
2100
2159
|
Overlay: c,
|
|
2101
2160
|
className: C,
|
|
2102
|
-
style:
|
|
2161
|
+
style: y,
|
|
2103
2162
|
slots: l,
|
|
2104
2163
|
slotProps: d
|
|
2105
|
-
}),
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
/* @__PURE__ */ f(T, {}),
|
|
2109
|
-
/* @__PURE__ */ f(kt, {})
|
|
2164
|
+
}), Me(b, t), /* @__PURE__ */ J(et, { value: b, children: [
|
|
2165
|
+
/* @__PURE__ */ h(i ? yt : xt, {}),
|
|
2166
|
+
/* @__PURE__ */ h(kt, {})
|
|
2110
2167
|
] });
|
|
2111
2168
|
}
|
|
2112
|
-
const
|
|
2113
|
-
const t = E(), e =
|
|
2169
|
+
const je = (s = {}) => {
|
|
2170
|
+
const t = E(), e = nt(), n = H(null);
|
|
2114
2171
|
if (e.type !== "mark")
|
|
2115
2172
|
throw new Error("useMark can only be used with mark tokens");
|
|
2116
|
-
const [r] =
|
|
2117
|
-
|
|
2173
|
+
const [r] = M(() => new xe({ ref: n, store: t, token: e }));
|
|
2174
|
+
$e(n, s, e);
|
|
2118
2175
|
const o = t.state.readOnly.use();
|
|
2119
|
-
return
|
|
2176
|
+
return P(() => {
|
|
2120
2177
|
r.readOnly = o;
|
|
2121
2178
|
}, [o]), r;
|
|
2122
2179
|
};
|
|
2123
|
-
function
|
|
2124
|
-
|
|
2180
|
+
function $e(s, t, e) {
|
|
2181
|
+
P(() => {
|
|
2125
2182
|
s.current && !t.controlled && (s.current.textContent = e.content);
|
|
2126
2183
|
}, []);
|
|
2127
2184
|
}
|
|
2128
2185
|
export {
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2186
|
+
xe as MarkHandler,
|
|
2187
|
+
Ue as MarkedInput,
|
|
2188
|
+
q as annotate,
|
|
2189
|
+
Ge as denote,
|
|
2190
|
+
Ce as reorderBlocks,
|
|
2191
|
+
we as splitTokensIntoBlocks,
|
|
2192
|
+
je as useMark,
|
|
2193
|
+
De as useOverlay
|
|
2137
2194
|
};
|