@markput/react 0.1.0 → 0.2.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 +10 -3
- package/index.d.ts +21 -84
- package/index.js +1196 -1088
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,161 +1,150 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
Object.entries(t).map(([e, n]) => e.startsWith("data") && e.length > 4 && e[4] === e[4].toUpperCase() ? [`data-${e.slice(4).replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()}`, n] : [e, n])
|
|
7
|
-
) : {};
|
|
8
|
-
}
|
|
9
|
-
const fe = {
|
|
10
|
-
container: "div",
|
|
11
|
-
span: "span"
|
|
12
|
-
};
|
|
13
|
-
function Z(t, e) {
|
|
14
|
-
return e.props.slots?.[t] ? e.props.slots[t] : fe[t];
|
|
15
|
-
}
|
|
16
|
-
function J(t, e) {
|
|
17
|
-
const n = e.props.slotProps?.[t];
|
|
18
|
-
return n ? he(n) : void 0;
|
|
2
|
+
import { jsx as f, Fragment as it, jsxs as at } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as X, useContext as Z, useRef as J, useMemo as C, useLayoutEffect as ct, memo as D, useCallback as B, useState as L, useEffect as S, useImperativeHandle as lt } from "react";
|
|
4
|
+
function dt(s) {
|
|
5
|
+
if (s == null) throw new Error("Value must be a non nullable!");
|
|
19
6
|
}
|
|
20
|
-
function
|
|
21
|
-
return
|
|
7
|
+
function ht(s) {
|
|
8
|
+
return s ? Object.fromEntries(
|
|
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
|
+
) : {};
|
|
22
11
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
return Object.keys(e).length > 0 ? e : void 0;
|
|
12
|
+
function ut(...s) {
|
|
13
|
+
return s.filter(Boolean).join(" ") || void 0;
|
|
26
14
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
15
|
+
function gt(...s) {
|
|
16
|
+
const t = Object.assign({}, ...s.filter(Boolean));
|
|
17
|
+
return Object.keys(t).length > 0 ? t : void 0;
|
|
29
18
|
}
|
|
30
|
-
var
|
|
31
|
-
const
|
|
19
|
+
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 || {});
|
|
20
|
+
const ft = "@", pt = "@[__value__](__meta__)", p = {
|
|
32
21
|
Value: "__value__",
|
|
33
22
|
Meta: "__meta__",
|
|
34
23
|
Nested: "__nested__"
|
|
35
|
-
},
|
|
24
|
+
}, x = {
|
|
36
25
|
Value: "value",
|
|
37
26
|
Meta: "meta",
|
|
38
27
|
Nested: "nested"
|
|
39
28
|
};
|
|
40
|
-
function
|
|
41
|
-
const { segments:
|
|
42
|
-
|
|
43
|
-
const i = r.value === 2, { segments: a, gapTypes:
|
|
29
|
+
function vt(s, t) {
|
|
30
|
+
const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } = mt(s);
|
|
31
|
+
xt(r, s);
|
|
32
|
+
const i = r.value === 2, { segments: a, gapTypes: l } = i ? yt(e, n, o) : { segments: e, gapTypes: n };
|
|
44
33
|
return {
|
|
45
|
-
markup:
|
|
46
|
-
index:
|
|
34
|
+
markup: s,
|
|
35
|
+
index: t,
|
|
47
36
|
segments: a,
|
|
48
|
-
gapTypes:
|
|
37
|
+
gapTypes: l,
|
|
49
38
|
hasNested: r.nested === 1,
|
|
50
39
|
hasTwoValues: i,
|
|
51
40
|
segmentGlobalIndices: Array.from({ length: a.length })
|
|
52
41
|
// Will be populated by MarkupRegistry
|
|
53
42
|
};
|
|
54
43
|
}
|
|
55
|
-
function
|
|
56
|
-
const
|
|
44
|
+
function mt(s) {
|
|
45
|
+
const t = [], e = [], n = [], r = {
|
|
57
46
|
value: 0,
|
|
58
47
|
meta: 0,
|
|
59
48
|
nested: 0
|
|
60
|
-
}, o = [], i = [
|
|
61
|
-
for (const
|
|
62
|
-
const
|
|
63
|
-
let u =
|
|
49
|
+
}, o = [], i = [x.Value, x.Meta, x.Nested];
|
|
50
|
+
for (const c of i) {
|
|
51
|
+
const d = j[c];
|
|
52
|
+
let u = s.indexOf(d);
|
|
64
53
|
for (; u !== -1; )
|
|
65
|
-
o.push({ type:
|
|
54
|
+
o.push({ type: c, position: u }), u = s.indexOf(d, u + d.length);
|
|
66
55
|
}
|
|
67
|
-
o.sort((
|
|
56
|
+
o.sort((c, d) => c.position - d.position);
|
|
68
57
|
let a = 0;
|
|
69
|
-
for (const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
const
|
|
74
|
-
return
|
|
75
|
-
segments:
|
|
76
|
-
gapTypes:
|
|
58
|
+
for (const c of o) {
|
|
59
|
+
const d = s.substring(a, c.position);
|
|
60
|
+
d.length > 0 && t.push(d), e.push(c.type), r[c.type]++, c.type === x.Value && n.push(e.length - 1), a = c.position + j[c.type].length;
|
|
61
|
+
}
|
|
62
|
+
const l = s.substring(a);
|
|
63
|
+
return l.length > 0 && t.push(l), {
|
|
64
|
+
segments: t,
|
|
65
|
+
gapTypes: e,
|
|
77
66
|
counts: r,
|
|
78
|
-
valueGapIndices:
|
|
67
|
+
valueGapIndices: n
|
|
79
68
|
};
|
|
80
69
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
{ count:
|
|
84
|
-
{ count:
|
|
85
|
-
{ count:
|
|
70
|
+
function xt(s, t) {
|
|
71
|
+
const e = [
|
|
72
|
+
{ count: s.value, max: 2, name: p.Value },
|
|
73
|
+
{ count: s.meta, max: 1, name: p.Meta },
|
|
74
|
+
{ count: s.nested, max: 1, name: p.Nested }
|
|
86
75
|
];
|
|
87
|
-
for (const { count:
|
|
88
|
-
if (
|
|
89
|
-
throw new Error(`Invalid markup: "${
|
|
90
|
-
if (
|
|
76
|
+
for (const { count: n, max: r, name: o } of e)
|
|
77
|
+
if (n > r)
|
|
78
|
+
throw new Error(`Invalid markup: "${t}". Max ${r} "${o}" placeholders, got ${n}`);
|
|
79
|
+
if (s.value === 0 && s.nested === 0)
|
|
91
80
|
throw new Error(
|
|
92
|
-
`Invalid markup: "${
|
|
81
|
+
`Invalid markup: "${t}". Need at least one "${p.Value}" or "${p.Nested}"`
|
|
93
82
|
);
|
|
94
83
|
}
|
|
95
84
|
const j = {
|
|
96
|
-
[
|
|
97
|
-
[
|
|
98
|
-
[
|
|
85
|
+
[x.Value]: p.Value,
|
|
86
|
+
[x.Meta]: p.Meta,
|
|
87
|
+
[x.Nested]: p.Nested
|
|
99
88
|
};
|
|
100
|
-
function
|
|
101
|
-
if (
|
|
102
|
-
return { segments:
|
|
103
|
-
const [
|
|
104
|
-
i && a && o.push(u(i, a,
|
|
105
|
-
for (let
|
|
106
|
-
o.push(
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
return { segments: o, gapTypes:
|
|
111
|
-
function u(
|
|
112
|
-
if (!
|
|
113
|
-
const
|
|
114
|
-
return [
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
class
|
|
89
|
+
function yt(s, t, e) {
|
|
90
|
+
if (e.length !== 2)
|
|
91
|
+
return { segments: s, gapTypes: t };
|
|
92
|
+
const [n, r] = e, o = [], i = s[n], a = s[n + 1];
|
|
93
|
+
i && a && o.push(u(i, a, s[n + 2]));
|
|
94
|
+
for (let h = n + 2; h < r; h++)
|
|
95
|
+
o.push(s[h]);
|
|
96
|
+
const l = s[r], c = s[r + 1];
|
|
97
|
+
l && c && o.push(u(l, c, s[r + 2]));
|
|
98
|
+
const d = t.filter((h) => h !== x.Value);
|
|
99
|
+
return { segments: o, gapTypes: d };
|
|
100
|
+
function u(h, g, w) {
|
|
101
|
+
if (!w) return [h, g, ""];
|
|
102
|
+
const E = w.charAt(0), T = E && !g.includes(E) && !w.startsWith(h) ? E : "";
|
|
103
|
+
return [h, g, T];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
class kt {
|
|
118
107
|
markups;
|
|
119
108
|
descriptors;
|
|
120
109
|
/** Deduplicated list of unique segment definitions (static strings or dynamic patterns) */
|
|
121
110
|
segments = [];
|
|
122
111
|
/** Map from first segment index to descriptors that start with this segment (for O(1) lookup) */
|
|
123
112
|
firstSegmentIndexMap = /* @__PURE__ */ new Map();
|
|
124
|
-
constructor(
|
|
125
|
-
this.markups =
|
|
126
|
-
const
|
|
127
|
-
this.descriptors =
|
|
128
|
-
if (
|
|
113
|
+
constructor(t) {
|
|
114
|
+
this.markups = t;
|
|
115
|
+
const e = /* @__PURE__ */ new Map();
|
|
116
|
+
this.descriptors = t.map((n, r) => {
|
|
117
|
+
if (n === void 0)
|
|
129
118
|
return null;
|
|
130
|
-
const o =
|
|
119
|
+
const o = vt(n, r);
|
|
131
120
|
return o.segments.forEach((i, a) => {
|
|
132
|
-
this.processSegment(o, i, a,
|
|
121
|
+
this.processSegment(o, i, a, e);
|
|
133
122
|
}), this.addToFirstSegmentIndexMap(o), o;
|
|
134
|
-
}).filter((
|
|
123
|
+
}).filter((n) => n !== null);
|
|
135
124
|
}
|
|
136
125
|
/**
|
|
137
126
|
* Adds a descriptor to the firstSegmentIndexMap using its first segment's global index
|
|
138
127
|
*/
|
|
139
|
-
addToFirstSegmentIndexMap(
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
processSegment(e, n,
|
|
146
|
-
const o = this.getSegmentKey(
|
|
128
|
+
addToFirstSegmentIndexMap(t) {
|
|
129
|
+
const e = t.segmentGlobalIndices[0];
|
|
130
|
+
if (e === void 0) return;
|
|
131
|
+
const n = this.firstSegmentIndexMap.get(e);
|
|
132
|
+
n ? n.push(t) : this.firstSegmentIndexMap.set(e, [t]);
|
|
133
|
+
}
|
|
134
|
+
processSegment(t, e, n, r) {
|
|
135
|
+
const o = this.getSegmentKey(e);
|
|
147
136
|
if (!o) return;
|
|
148
|
-
this.registerSegment(
|
|
137
|
+
this.registerSegment(e, o, r);
|
|
149
138
|
const i = r.get(o);
|
|
150
|
-
if (
|
|
151
|
-
const [a,
|
|
152
|
-
a && this.registerSegment(a, a, r),
|
|
139
|
+
if (t.segmentGlobalIndices[n] = i, typeof e != "string") {
|
|
140
|
+
const [a, l] = e;
|
|
141
|
+
a && this.registerSegment(a, a, r), l && this.registerSegment(l, l, r);
|
|
153
142
|
}
|
|
154
143
|
}
|
|
155
|
-
registerSegment(e, n
|
|
156
|
-
if (!
|
|
144
|
+
registerSegment(t, e, n) {
|
|
145
|
+
if (!n.has(e)) {
|
|
157
146
|
const r = this.segments.length;
|
|
158
|
-
this.segments.push(
|
|
147
|
+
this.segments.push(t), n.set(e, r);
|
|
159
148
|
}
|
|
160
149
|
}
|
|
161
150
|
/**
|
|
@@ -164,27 +153,27 @@ class Ce {
|
|
|
164
153
|
* For dynamic segments (arrays), returns before|after|exclusions if before or after is non-empty
|
|
165
154
|
* Returns empty string for segments that should be ignored
|
|
166
155
|
*/
|
|
167
|
-
getSegmentKey(
|
|
168
|
-
if (typeof
|
|
169
|
-
return
|
|
170
|
-
const [
|
|
171
|
-
return
|
|
156
|
+
getSegmentKey(t) {
|
|
157
|
+
if (typeof t == "string")
|
|
158
|
+
return t;
|
|
159
|
+
const [e, n, r] = t;
|
|
160
|
+
return e || n ? `${e}|${n}|${r}` : "";
|
|
172
161
|
}
|
|
173
162
|
}
|
|
174
|
-
function
|
|
175
|
-
if (!
|
|
176
|
-
return
|
|
177
|
-
let
|
|
178
|
-
for (let
|
|
179
|
-
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
class
|
|
183
|
-
constructor(
|
|
184
|
-
if (this.descriptor =
|
|
185
|
-
this.captured =
|
|
186
|
-
const
|
|
187
|
-
this.gaps.value = { start:
|
|
163
|
+
function Q(s, t) {
|
|
164
|
+
if (!t)
|
|
165
|
+
return s;
|
|
166
|
+
let e = 5381;
|
|
167
|
+
for (let n = 0; n < t.length; n++)
|
|
168
|
+
e = e * 33 ^ t.charCodeAt(n);
|
|
169
|
+
return e = e >>> 0, s * 1e6 + (e & 1048575);
|
|
170
|
+
}
|
|
171
|
+
class wt {
|
|
172
|
+
constructor(t, e) {
|
|
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
|
+
this.captured = e.captured;
|
|
175
|
+
const n = e.start + e.value.indexOf(e.captured), r = n + e.captured.length;
|
|
176
|
+
this.gaps.value = { start: n, end: r };
|
|
188
177
|
}
|
|
189
178
|
}
|
|
190
179
|
gaps = {};
|
|
@@ -223,44 +212,44 @@ class we {
|
|
|
223
212
|
get nextSegment() {
|
|
224
213
|
if (this.isCompleted || this.isInvalid)
|
|
225
214
|
return;
|
|
226
|
-
const
|
|
227
|
-
if (typeof
|
|
228
|
-
const [
|
|
229
|
-
return
|
|
215
|
+
const t = this.descriptor.segmentGlobalIndices[this.expectedSegmentIndex], e = this.descriptor.segments[this.expectedSegmentIndex];
|
|
216
|
+
if (typeof e == "object" && this.descriptor.hasTwoValues && this.captured && this.isAwaitingLastSegment) {
|
|
217
|
+
const [n, r] = e, o = n + this.captured + r;
|
|
218
|
+
return Q(t, o);
|
|
230
219
|
}
|
|
231
|
-
return
|
|
220
|
+
return t;
|
|
232
221
|
}
|
|
233
222
|
/**
|
|
234
223
|
* Update state with new segment by setting gap positions
|
|
235
224
|
*/
|
|
236
|
-
processNext(
|
|
237
|
-
const
|
|
238
|
-
if (
|
|
225
|
+
processNext(t) {
|
|
226
|
+
const e = this.end, n = t.start, r = this.descriptor.gapTypes[this.expectedSegmentIndex - 1];
|
|
227
|
+
if (n < e) {
|
|
239
228
|
this.expectedSegmentIndex = -1;
|
|
240
229
|
return;
|
|
241
230
|
}
|
|
242
|
-
this.gaps[r] = { start:
|
|
231
|
+
this.gaps[r] = { start: e, end: n }, this.end = t.end, this.expectedSegmentIndex++, this.expectedSegmentIndex >= this.descriptor.segments.length && (this.expectedSegmentIndex = NaN);
|
|
243
232
|
}
|
|
244
233
|
/**
|
|
245
234
|
* Checks if this match conflicts with another match (overlaps and cannot nest properly)
|
|
246
235
|
*/
|
|
247
|
-
conflictsWith(
|
|
248
|
-
return !
|
|
236
|
+
conflictsWith(t) {
|
|
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);
|
|
249
238
|
}
|
|
250
239
|
}
|
|
251
|
-
class
|
|
252
|
-
constructor(
|
|
253
|
-
this.registry =
|
|
240
|
+
class St {
|
|
241
|
+
constructor(t) {
|
|
242
|
+
this.registry = t;
|
|
254
243
|
}
|
|
255
244
|
pendingStates = /* @__PURE__ */ new Map();
|
|
256
245
|
completingStates = /* @__PURE__ */ new Map();
|
|
257
246
|
completedStates = [];
|
|
258
247
|
/** Main method that converts found segments into structured matches */
|
|
259
|
-
process(
|
|
248
|
+
process(t) {
|
|
260
249
|
this.pendingStates.clear(), this.completingStates.clear(), this.completedStates.length = 0;
|
|
261
|
-
for (const
|
|
262
|
-
this.processWaitingStates(
|
|
263
|
-
return this.completedStates.map((
|
|
250
|
+
for (const e of t)
|
|
251
|
+
this.processWaitingStates(e), this.tryStartNewStates(e);
|
|
252
|
+
return this.completedStates.map((e) => e.match);
|
|
264
253
|
}
|
|
265
254
|
/**
|
|
266
255
|
* Process states waiting for this segment
|
|
@@ -268,19 +257,19 @@ class Te {
|
|
|
268
257
|
* Process completing states first (higher priority), then pending states
|
|
269
258
|
* Process only one state per call
|
|
270
259
|
*/
|
|
271
|
-
processWaitingStates(
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
if (
|
|
275
|
-
this.addToWaiting(
|
|
260
|
+
processWaitingStates(t) {
|
|
261
|
+
const e = this.dequeueWaitingMatch(t);
|
|
262
|
+
if (e && (e.processNext(t), !e.isInvalid)) {
|
|
263
|
+
if (e.isCompleted) return this.addToCompleted(e);
|
|
264
|
+
this.addToWaiting(e);
|
|
276
265
|
}
|
|
277
266
|
}
|
|
278
|
-
tryStartNewStates(
|
|
279
|
-
this.registry.firstSegmentIndexMap.get(
|
|
280
|
-
const
|
|
281
|
-
if (!
|
|
282
|
-
if (
|
|
283
|
-
this.addToWaiting(
|
|
267
|
+
tryStartNewStates(t) {
|
|
268
|
+
this.registry.firstSegmentIndexMap.get(t.index)?.forEach((e) => {
|
|
269
|
+
const n = new wt(e, t);
|
|
270
|
+
if (!n.isInvalid) {
|
|
271
|
+
if (n.isCompleted) return this.addToCompleted(n);
|
|
272
|
+
this.addToWaiting(n);
|
|
284
273
|
}
|
|
285
274
|
});
|
|
286
275
|
}
|
|
@@ -288,23 +277,23 @@ class Te {
|
|
|
288
277
|
* Gets the next waiting match for the given segment
|
|
289
278
|
* Uses value-specific index for dynamic segments, base index for static segments
|
|
290
279
|
*/
|
|
291
|
-
dequeueWaitingMatch(
|
|
292
|
-
const
|
|
293
|
-
if (
|
|
294
|
-
const r = this.pendingStates.get(
|
|
280
|
+
dequeueWaitingMatch(t) {
|
|
281
|
+
const e = t.captured ? Q(t.index, t.value) : t.index, n = this.completingStates.get(e);
|
|
282
|
+
if (n?.length) return n.pop();
|
|
283
|
+
const r = this.pendingStates.get(e);
|
|
295
284
|
if (r?.length) return r.pop();
|
|
296
285
|
}
|
|
297
286
|
/**
|
|
298
287
|
* Adds a state to the waiting list for the next expected segment
|
|
299
288
|
*/
|
|
300
|
-
addToWaiting(
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
303
|
-
const
|
|
304
|
-
|
|
289
|
+
addToWaiting(t) {
|
|
290
|
+
const e = t.nextSegment;
|
|
291
|
+
if (t.isAwaitingLastSegment) {
|
|
292
|
+
const n = this.completingStates.get(e) || [];
|
|
293
|
+
n.length === 0 && this.completingStates.set(e, n), n.push(t);
|
|
305
294
|
} else {
|
|
306
|
-
const
|
|
307
|
-
|
|
295
|
+
const n = this.pendingStates.get(e) || [];
|
|
296
|
+
n.length === 0 && this.pendingStates.set(e, n), n.push(t);
|
|
308
297
|
}
|
|
309
298
|
}
|
|
310
299
|
/**
|
|
@@ -312,62 +301,62 @@ class Te {
|
|
|
312
301
|
* Uses binary search to find insertion point and maintains sorted order
|
|
313
302
|
* Relies on processing order to determine which match to keep
|
|
314
303
|
*/
|
|
315
|
-
addToCompleted(
|
|
316
|
-
const
|
|
317
|
-
let
|
|
318
|
-
for (;
|
|
319
|
-
const o = Math.floor((
|
|
320
|
-
this.completedStates[o].position <
|
|
304
|
+
addToCompleted(t) {
|
|
305
|
+
const e = t.start;
|
|
306
|
+
let n = 0, r = this.completedStates.length;
|
|
307
|
+
for (; n < r; ) {
|
|
308
|
+
const o = Math.floor((n + r) / 2);
|
|
309
|
+
this.completedStates[o].position < e ? n = o + 1 : r = o;
|
|
321
310
|
}
|
|
322
|
-
|
|
311
|
+
n < this.completedStates.length && this.completedStates[n].position === e ? this.completedStates[n].match = t : this.completedStates.splice(n, 0, { position: e, match: t });
|
|
323
312
|
}
|
|
324
313
|
}
|
|
325
|
-
const b = (
|
|
326
|
-
function
|
|
327
|
-
const
|
|
328
|
-
return `${
|
|
314
|
+
const b = (s) => s.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
|
|
315
|
+
function Ct(s, t, e) {
|
|
316
|
+
const n = b(s), r = b(t), o = b(t + e);
|
|
317
|
+
return `${n}([^${o}]+?)${r}`;
|
|
329
318
|
}
|
|
330
|
-
class
|
|
319
|
+
class bt {
|
|
331
320
|
staticRegex;
|
|
332
321
|
staticToIndex;
|
|
333
322
|
dynamicRegex;
|
|
334
323
|
dynamicEntries;
|
|
335
324
|
dynamicIndices;
|
|
336
|
-
constructor(
|
|
337
|
-
this.initializeDual(
|
|
338
|
-
}
|
|
339
|
-
initializeDual(
|
|
340
|
-
const
|
|
341
|
-
if (
|
|
342
|
-
typeof o == "string" ? (
|
|
343
|
-
}),
|
|
344
|
-
const i = [...
|
|
325
|
+
constructor(t) {
|
|
326
|
+
this.initializeDual(t);
|
|
327
|
+
}
|
|
328
|
+
initializeDual(t) {
|
|
329
|
+
const e = [], n = [], r = /* @__PURE__ */ new Map();
|
|
330
|
+
if (t.forEach((o, i) => {
|
|
331
|
+
typeof o == "string" ? (e.push(o), r.set(o, i)) : n.push(o);
|
|
332
|
+
}), e.length > 0) {
|
|
333
|
+
const i = [...e].sort((a, l) => l.length - a.length).map(b);
|
|
345
334
|
this.staticRegex = new RegExp(`(?:${i.join("|")})`, "gu"), this.staticToIndex = r;
|
|
346
335
|
}
|
|
347
|
-
if (
|
|
336
|
+
if (n.length > 0) {
|
|
348
337
|
const o = /* @__PURE__ */ new Set(), i = [];
|
|
349
|
-
|
|
350
|
-
const
|
|
338
|
+
n.forEach((a) => {
|
|
339
|
+
const l = t.indexOf(a);
|
|
351
340
|
if (typeof a == "string")
|
|
352
|
-
i.push({ index:
|
|
341
|
+
i.push({ index: l, pattern: b(a), definition: a });
|
|
353
342
|
else {
|
|
354
|
-
const [
|
|
355
|
-
o.add(
|
|
356
|
-
const g =
|
|
357
|
-
i.push({ index:
|
|
343
|
+
const [c, d, u] = a;
|
|
344
|
+
o.add(l);
|
|
345
|
+
const g = Ct(c, d, u).replace("(", `(?<content${l}>`);
|
|
346
|
+
i.push({ index: l, pattern: g, definition: a });
|
|
358
347
|
}
|
|
359
|
-
}), i.sort((a,
|
|
360
|
-
const
|
|
361
|
-
return (typeof
|
|
362
|
-
}), this.dynamicEntries = i, this.dynamicIndices = o, this.dynamicRegex = new RegExp(i.map((a,
|
|
348
|
+
}), i.sort((a, l) => {
|
|
349
|
+
const c = typeof a.definition == "string" ? a.definition.length : a.pattern.length;
|
|
350
|
+
return (typeof l.definition == "string" ? l.definition.length : l.pattern.length) - c;
|
|
351
|
+
}), this.dynamicEntries = i, this.dynamicIndices = o, this.dynamicRegex = new RegExp(i.map((a, l) => `(?<seg${l}>${a.pattern})`).join("|"), "gu");
|
|
363
352
|
}
|
|
364
353
|
}
|
|
365
|
-
search(
|
|
366
|
-
const
|
|
354
|
+
search(t) {
|
|
355
|
+
const e = [], n = [];
|
|
367
356
|
if (this.staticRegex && this.staticToIndex)
|
|
368
|
-
for (const o of
|
|
357
|
+
for (const o of t.matchAll(this.staticRegex)) {
|
|
369
358
|
const i = this.staticToIndex.get(o[0]);
|
|
370
|
-
i !== void 0 &&
|
|
359
|
+
i !== void 0 && e.push({
|
|
371
360
|
index: i,
|
|
372
361
|
start: o.index,
|
|
373
362
|
end: o.index + o[0].length,
|
|
@@ -375,38 +364,38 @@ class be {
|
|
|
375
364
|
});
|
|
376
365
|
}
|
|
377
366
|
if (this.dynamicRegex && this.dynamicEntries && this.dynamicIndices)
|
|
378
|
-
for (const o of
|
|
367
|
+
for (const o of t.matchAll(this.dynamicRegex)) {
|
|
379
368
|
const i = o[0], a = o.index;
|
|
380
|
-
let
|
|
369
|
+
let l, c;
|
|
381
370
|
if (o.groups) {
|
|
382
|
-
for (let
|
|
383
|
-
if (o.groups[`seg${
|
|
384
|
-
|
|
371
|
+
for (let d = 0; d < this.dynamicEntries.length; d++)
|
|
372
|
+
if (o.groups[`seg${d}`] !== void 0) {
|
|
373
|
+
l = this.dynamicEntries[d].index, this.dynamicIndices.has(l) && (c = o.groups[`content${l}`]);
|
|
385
374
|
break;
|
|
386
375
|
}
|
|
387
376
|
}
|
|
388
|
-
|
|
389
|
-
index:
|
|
377
|
+
l !== void 0 && n.push({
|
|
378
|
+
index: l,
|
|
390
379
|
start: a,
|
|
391
380
|
end: a + i.length,
|
|
392
381
|
value: i,
|
|
393
|
-
captured:
|
|
382
|
+
captured: c
|
|
394
383
|
});
|
|
395
384
|
}
|
|
396
|
-
const r = [...
|
|
397
|
-
for (const o of
|
|
398
|
-
|
|
385
|
+
const r = [...n];
|
|
386
|
+
for (const o of e)
|
|
387
|
+
n.some(
|
|
399
388
|
(a) => o.start < a.end && o.end > a.start
|
|
400
389
|
) || r.push(o);
|
|
401
390
|
return r.sort((o, i) => o.start - i.start), r;
|
|
402
391
|
}
|
|
403
392
|
}
|
|
404
|
-
const
|
|
393
|
+
const K = (s, t = 0, e = s.length) => ({
|
|
405
394
|
type: "text",
|
|
406
|
-
content:
|
|
407
|
-
position: { start:
|
|
395
|
+
content: s.substring(t, e),
|
|
396
|
+
position: { start: t, end: e }
|
|
408
397
|
});
|
|
409
|
-
class
|
|
398
|
+
class Et {
|
|
410
399
|
// Instance fields - only what's needed for single pass
|
|
411
400
|
input;
|
|
412
401
|
// ===== PUBLIC API =====
|
|
@@ -426,8 +415,8 @@ class Ie {
|
|
|
426
415
|
* Complexity: O(M) where M is number of matches
|
|
427
416
|
* Memory: O(D) for active parents stack where D is nesting depth
|
|
428
417
|
*/
|
|
429
|
-
build(
|
|
430
|
-
return this.input =
|
|
418
|
+
build(t, e) {
|
|
419
|
+
return this.input = e, t.length === 0 ? [this.createTextToken(0, e.length)] : this.buildSinglePass(t);
|
|
431
420
|
}
|
|
432
421
|
// ===== SINGLE-PASS ALGORITHM =====
|
|
433
422
|
/**
|
|
@@ -436,66 +425,66 @@ class Ie {
|
|
|
436
425
|
* This is the core algorithm that processes matches sequentially,
|
|
437
426
|
* maintaining a stack of active parents and creating tokens directly.
|
|
438
427
|
*/
|
|
439
|
-
buildSinglePass(
|
|
440
|
-
const
|
|
428
|
+
buildSinglePass(t) {
|
|
429
|
+
const e = [], n = [];
|
|
441
430
|
let r = null, o = 0;
|
|
442
|
-
for (const i of
|
|
431
|
+
for (const i of t) {
|
|
443
432
|
if (r && i.conflictsWith(r))
|
|
444
433
|
continue;
|
|
445
|
-
for (r = i;
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
448
|
-
this.finalizeParent(
|
|
434
|
+
for (r = i; n.length > 0; ) {
|
|
435
|
+
const c = n[n.length - 1], d = this.getContentBounds(c.match);
|
|
436
|
+
if (d.end <= i.start)
|
|
437
|
+
this.finalizeParent(c, d.end), n.pop(), n.length > 0 ? n[n.length - 1].token.children.push(c.token) : e.push(c.token);
|
|
449
438
|
else
|
|
450
439
|
break;
|
|
451
440
|
}
|
|
452
|
-
const a =
|
|
441
|
+
const a = n.length > 0 ? n[n.length - 1] : null;
|
|
453
442
|
if (a) {
|
|
454
|
-
const
|
|
455
|
-
a.token.children.push(
|
|
443
|
+
const c = this.createTextToken(a.textPos, i.start);
|
|
444
|
+
a.token.children.push(c), a.textPos = i.end;
|
|
456
445
|
} else {
|
|
457
|
-
const
|
|
458
|
-
|
|
446
|
+
const c = this.createTextToken(o, i.start);
|
|
447
|
+
e.push(c), o = i.end;
|
|
459
448
|
}
|
|
460
|
-
const
|
|
449
|
+
const l = this.createMarkToken(i);
|
|
461
450
|
if (this.hasNestedContent(i)) {
|
|
462
|
-
const
|
|
463
|
-
|
|
451
|
+
const c = this.getContentBounds(i);
|
|
452
|
+
n.push({
|
|
464
453
|
match: i,
|
|
465
|
-
token:
|
|
466
|
-
textPos:
|
|
454
|
+
token: l,
|
|
455
|
+
textPos: c.start
|
|
467
456
|
});
|
|
468
457
|
} else
|
|
469
|
-
a ? a.token.children.push(
|
|
458
|
+
a ? a.token.children.push(l) : e.push(l);
|
|
470
459
|
}
|
|
471
|
-
for (;
|
|
472
|
-
const i =
|
|
473
|
-
this.finalizeParent(i, a.end),
|
|
460
|
+
for (; n.length > 0; ) {
|
|
461
|
+
const i = n.pop(), a = this.getContentBounds(i.match);
|
|
462
|
+
this.finalizeParent(i, a.end), n.length > 0 ? n[n.length - 1].token.children.push(i.token) : e.push(i.token);
|
|
474
463
|
}
|
|
475
|
-
return
|
|
464
|
+
return e.push(this.createTextToken(o, this.input.length)), e;
|
|
476
465
|
}
|
|
477
466
|
/**
|
|
478
467
|
* Finalizes a parent token by adding final text token if needed
|
|
479
468
|
*/
|
|
480
|
-
finalizeParent(
|
|
481
|
-
const
|
|
482
|
-
|
|
469
|
+
finalizeParent(t, e) {
|
|
470
|
+
const n = this.createTextToken(t.textPos, e);
|
|
471
|
+
t.token.children.push(n), t.token.children.some((o) => o.type === "mark") || (t.token.children = []);
|
|
483
472
|
}
|
|
484
473
|
/**
|
|
485
474
|
* Creates a mark token from a match (without children - those are added later)
|
|
486
475
|
*/
|
|
487
|
-
createMarkToken(
|
|
488
|
-
const
|
|
476
|
+
createMarkToken(t) {
|
|
477
|
+
const e = this.extractSubstring(t.gaps.value?.start, t.gaps.value?.end), n = this.extractSubstring(t.gaps.nested?.start, t.gaps.nested?.end), r = this.extractSubstring(t.gaps.meta?.start, t.gaps.meta?.end), o = n || void 0, i = t.gaps.meta !== void 0 ? r : void 0, a = e || o || "";
|
|
489
478
|
return {
|
|
490
479
|
type: "mark",
|
|
491
|
-
content: this.input.substring(
|
|
480
|
+
content: this.input.substring(t.start, t.end),
|
|
492
481
|
children: [],
|
|
493
482
|
// Will be populated if match has nested content
|
|
494
|
-
descriptor:
|
|
483
|
+
descriptor: t.descriptor,
|
|
495
484
|
value: a,
|
|
496
485
|
meta: i,
|
|
497
|
-
position: { start:
|
|
498
|
-
nested: this.createNestedInfo(
|
|
486
|
+
position: { start: t.start, end: t.end },
|
|
487
|
+
nested: this.createNestedInfo(t, o)
|
|
499
488
|
};
|
|
500
489
|
}
|
|
501
490
|
// ===== UTILITY METHODS =====
|
|
@@ -503,78 +492,78 @@ class Ie {
|
|
|
503
492
|
* Gets the content boundaries for a match
|
|
504
493
|
* Priority: nested content if present, otherwise value content
|
|
505
494
|
*/
|
|
506
|
-
getContentBounds(
|
|
507
|
-
return
|
|
508
|
-
start:
|
|
509
|
-
end:
|
|
495
|
+
getContentBounds(t) {
|
|
496
|
+
return t.gaps.nested ? t.gaps.nested : t.gaps.value ? t.gaps.value : {
|
|
497
|
+
start: t.start,
|
|
498
|
+
end: t.start
|
|
510
499
|
};
|
|
511
500
|
}
|
|
512
501
|
/**
|
|
513
502
|
* Checks if a match has nested content capability
|
|
514
503
|
*/
|
|
515
|
-
hasNestedContent(
|
|
516
|
-
return
|
|
504
|
+
hasNestedContent(t) {
|
|
505
|
+
return t.gaps.nested !== void 0;
|
|
517
506
|
}
|
|
518
507
|
/**
|
|
519
508
|
* Extracts substring safely, returns empty string if positions are undefined
|
|
520
509
|
*/
|
|
521
|
-
extractSubstring(
|
|
522
|
-
return
|
|
510
|
+
extractSubstring(t, e) {
|
|
511
|
+
return t !== void 0 && e !== void 0 ? this.input.substring(t, e) : "";
|
|
523
512
|
}
|
|
524
513
|
/**
|
|
525
514
|
* Creates a text token for a range in the input
|
|
526
515
|
*/
|
|
527
|
-
createTextToken(
|
|
528
|
-
return
|
|
516
|
+
createTextToken(t, e) {
|
|
517
|
+
return K(this.input, t, e);
|
|
529
518
|
}
|
|
530
519
|
/**
|
|
531
520
|
* Creates nested info object if nested content exists
|
|
532
521
|
*/
|
|
533
|
-
createNestedInfo(
|
|
534
|
-
if (!(!
|
|
522
|
+
createNestedInfo(t, e) {
|
|
523
|
+
if (!(!e || t.gaps.nested === void 0))
|
|
535
524
|
return {
|
|
536
|
-
content:
|
|
537
|
-
start:
|
|
538
|
-
end:
|
|
525
|
+
content: e,
|
|
526
|
+
start: t.gaps.nested.start,
|
|
527
|
+
end: t.gaps.nested.end
|
|
539
528
|
};
|
|
540
529
|
}
|
|
541
530
|
}
|
|
542
|
-
function $(
|
|
543
|
-
let
|
|
544
|
-
return
|
|
531
|
+
function $(s, t) {
|
|
532
|
+
let e = s;
|
|
533
|
+
return t.value !== void 0 && (e = e.replaceAll(p.Value, t.value)), t.meta !== void 0 && (e = e.replaceAll(p.Meta, t.meta)), t.nested !== void 0 && (e = e.replaceAll(p.Nested, t.nested)), e;
|
|
545
534
|
}
|
|
546
|
-
function
|
|
547
|
-
let
|
|
548
|
-
for (const
|
|
549
|
-
if (
|
|
550
|
-
|
|
535
|
+
function y(s) {
|
|
536
|
+
let t = "";
|
|
537
|
+
for (const e of s) {
|
|
538
|
+
if (e.type === "text") {
|
|
539
|
+
t += e.content;
|
|
551
540
|
continue;
|
|
552
541
|
}
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
value:
|
|
556
|
-
meta:
|
|
542
|
+
const n = e.descriptor.markup, r = n.includes(p.Nested) ? e.children.length > 0 ? y(e.children) : e.nested?.content : void 0;
|
|
543
|
+
t += $(n, {
|
|
544
|
+
value: e.value,
|
|
545
|
+
meta: e.meta,
|
|
557
546
|
nested: r
|
|
558
547
|
});
|
|
559
548
|
}
|
|
560
|
-
return
|
|
549
|
+
return t;
|
|
561
550
|
}
|
|
562
|
-
function
|
|
563
|
-
let
|
|
564
|
-
for (const
|
|
565
|
-
if (
|
|
566
|
-
|
|
567
|
-
else if (
|
|
568
|
-
const r =
|
|
569
|
-
...
|
|
551
|
+
function H(s, t) {
|
|
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 = H(n.children, t), o = {
|
|
558
|
+
...n,
|
|
570
559
|
value: r
|
|
571
560
|
};
|
|
572
|
-
|
|
561
|
+
e += t(o);
|
|
573
562
|
} else
|
|
574
|
-
|
|
575
|
-
return
|
|
563
|
+
e += t(n);
|
|
564
|
+
return e;
|
|
576
565
|
}
|
|
577
|
-
class
|
|
566
|
+
class A {
|
|
578
567
|
registry;
|
|
579
568
|
segmentMatcher;
|
|
580
569
|
patternMatcher;
|
|
@@ -598,8 +587,8 @@ class O {
|
|
|
598
587
|
* ])
|
|
599
588
|
* ```
|
|
600
589
|
*/
|
|
601
|
-
constructor(
|
|
602
|
-
this.registry = new
|
|
590
|
+
constructor(t) {
|
|
591
|
+
this.registry = new kt(t), this.segmentMatcher = new bt(this.registry.segments), this.patternMatcher = new St(this.registry), this.treeBuilder = new Et();
|
|
603
592
|
}
|
|
604
593
|
/**
|
|
605
594
|
* Parses text into tokens (static convenience method)
|
|
@@ -615,9 +604,9 @@ class O {
|
|
|
615
604
|
* })
|
|
616
605
|
* ```
|
|
617
606
|
*/
|
|
618
|
-
static parse(
|
|
619
|
-
const
|
|
620
|
-
return !
|
|
607
|
+
static parse(t, e) {
|
|
608
|
+
const n = e?.markup;
|
|
609
|
+
return !n || n.length === 0 ? [K(t)] : new A(n).parse(t);
|
|
621
610
|
}
|
|
622
611
|
/**
|
|
623
612
|
* Converts tokens back to text (static convenience method)
|
|
@@ -630,8 +619,8 @@ class O {
|
|
|
630
619
|
* const text = Parser.stringify(tokens)
|
|
631
620
|
* ```
|
|
632
621
|
*/
|
|
633
|
-
static stringify(
|
|
634
|
-
return
|
|
622
|
+
static stringify(t) {
|
|
623
|
+
return y(t);
|
|
635
624
|
}
|
|
636
625
|
/**
|
|
637
626
|
* Parses text into a nested token tree
|
|
@@ -656,9 +645,9 @@ class O {
|
|
|
656
645
|
* // ]
|
|
657
646
|
* ```
|
|
658
647
|
*/
|
|
659
|
-
parse(
|
|
660
|
-
const
|
|
661
|
-
return this.treeBuilder.build(
|
|
648
|
+
parse(t) {
|
|
649
|
+
const e = this.segmentMatcher.search(t), n = this.patternMatcher.process(e);
|
|
650
|
+
return this.treeBuilder.build(n, t);
|
|
662
651
|
}
|
|
663
652
|
/**
|
|
664
653
|
* Converts tokens back to the original text
|
|
@@ -677,8 +666,8 @@ class O {
|
|
|
677
666
|
* console.log(reconstructed === text) // true
|
|
678
667
|
* ```
|
|
679
668
|
*/
|
|
680
|
-
stringify(
|
|
681
|
-
return
|
|
669
|
+
stringify(t) {
|
|
670
|
+
return y(t);
|
|
682
671
|
}
|
|
683
672
|
/**
|
|
684
673
|
* Transforms annotated text by processing all mark tokens with a callback
|
|
@@ -705,9 +694,9 @@ class O {
|
|
|
705
694
|
* // Returns: 'Hello:world and tag'
|
|
706
695
|
* ```
|
|
707
696
|
*/
|
|
708
|
-
transform(
|
|
709
|
-
const
|
|
710
|
-
return
|
|
697
|
+
transform(t, e) {
|
|
698
|
+
const n = this.parse(t);
|
|
699
|
+
return H(n, e);
|
|
711
700
|
}
|
|
712
701
|
/**
|
|
713
702
|
* Escapes markup segments in the given text using backslash
|
|
@@ -726,8 +715,8 @@ class O {
|
|
|
726
715
|
* // Returns: 'Hello \*\*world\*\* and \@[user]'
|
|
727
716
|
* ```
|
|
728
717
|
*/
|
|
729
|
-
escape(
|
|
730
|
-
return this.registry.segments.filter((
|
|
718
|
+
escape(t) {
|
|
719
|
+
return this.registry.segments.filter((e) => typeof e == "string").sort((e, n) => n.length - e.length).reduce((e, n) => e.replaceAll(n, n.replace(/(.)/g, "\\$1")), t);
|
|
731
720
|
}
|
|
732
721
|
/**
|
|
733
722
|
* Unescapes markup patterns in the given text
|
|
@@ -745,101 +734,184 @@ class O {
|
|
|
745
734
|
* // Returns: 'Hello **world** and @[user]'
|
|
746
735
|
* ```
|
|
747
736
|
*/
|
|
748
|
-
unescape(
|
|
749
|
-
return
|
|
737
|
+
unescape(t) {
|
|
738
|
+
return t.replaceAll(/\\(.)/g, "$1");
|
|
750
739
|
}
|
|
751
740
|
}
|
|
752
|
-
function
|
|
753
|
-
if (!
|
|
754
|
-
const
|
|
755
|
-
return
|
|
741
|
+
function ve(s, t, e) {
|
|
742
|
+
if (!e.length) return s;
|
|
743
|
+
const n = new A(e).parse(s);
|
|
744
|
+
return H(n, t);
|
|
756
745
|
}
|
|
757
|
-
function
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
746
|
+
function V(s, t, e = 0, n) {
|
|
747
|
+
for (const r of s) {
|
|
748
|
+
if (r === t) return { depth: e, parent: n };
|
|
749
|
+
if (r.type === "mark") {
|
|
750
|
+
const o = V(r.children, t, e + 1, r);
|
|
751
|
+
if (o) return o;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function Tt(s = "", t = "") {
|
|
756
|
+
if (s === t) return {};
|
|
757
|
+
let e;
|
|
758
|
+
for (let r = 0; r < s.length; r++)
|
|
759
|
+
if (s[r] !== t[r]) {
|
|
760
|
+
e = r;
|
|
763
761
|
break;
|
|
764
762
|
}
|
|
765
|
-
let
|
|
766
|
-
for (let r = 1; r <=
|
|
767
|
-
if (
|
|
768
|
-
|
|
763
|
+
let n;
|
|
764
|
+
for (let r = 1; r <= s.length; r++)
|
|
765
|
+
if (s.at(-r) !== t.at(-r)) {
|
|
766
|
+
n = s.length - r + 1;
|
|
769
767
|
break;
|
|
770
768
|
}
|
|
771
|
-
return { left:
|
|
769
|
+
return { left: e, right: n };
|
|
772
770
|
}
|
|
773
|
-
function q(
|
|
774
|
-
let
|
|
775
|
-
for (;
|
|
776
|
-
const r = Math.round((
|
|
777
|
-
|
|
771
|
+
function q(s, t) {
|
|
772
|
+
let e = -1, n = s.length;
|
|
773
|
+
for (; n - e > 1; ) {
|
|
774
|
+
const r = Math.round((e + n) / 2);
|
|
775
|
+
s[r] <= t ? e = r : n = r;
|
|
778
776
|
}
|
|
779
|
-
return
|
|
777
|
+
return s[e] == t && (n = e), [e, n].filter((r) => s[r] !== void 0);
|
|
780
778
|
}
|
|
781
|
-
function
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
779
|
+
function It(s) {
|
|
780
|
+
const { focus: t } = s.nodes, e = s.state.parser.get(), n = s.state.tokens.get();
|
|
781
|
+
if (!e)
|
|
782
|
+
return n;
|
|
783
|
+
const r = e.parse(t.content);
|
|
784
|
+
return r.length === 1 ? n : n.toSpliced(t.index, 1, ...r);
|
|
785
|
+
}
|
|
786
|
+
function Mt(s) {
|
|
787
|
+
const t = s.state.value.get(), e = Nt(s), n = Tt(s.state.previousValue.get(), t);
|
|
788
|
+
if (!n.left && !n.right)
|
|
789
|
+
return s.state.previousValue.set(t), s.state.tokens.get();
|
|
790
|
+
s.state.previousValue.set(t);
|
|
791
|
+
const r = s.state.tokens.get();
|
|
792
|
+
switch (!0) {
|
|
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 = O(s, o - 1, o);
|
|
795
|
+
return r.toSpliced(o - 1, 2, ...i);
|
|
796
|
+
}
|
|
797
|
+
case n.left !== void 0: {
|
|
798
|
+
const [o] = q(e, n.left), i = O(s, o);
|
|
799
|
+
return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
|
|
800
|
+
}
|
|
801
|
+
case n.right !== void 0: {
|
|
802
|
+
const [o] = q(e, n.right), i = O(s, o);
|
|
803
|
+
return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
|
|
804
|
+
}
|
|
805
|
+
default:
|
|
806
|
+
return P(s, t ?? "");
|
|
807
|
+
}
|
|
793
808
|
}
|
|
794
|
-
function
|
|
795
|
-
|
|
809
|
+
function O(s, ...t) {
|
|
810
|
+
let e = "";
|
|
811
|
+
const n = s.state.tokens.get();
|
|
812
|
+
for (const r of t) {
|
|
813
|
+
const o = n[r];
|
|
814
|
+
e += o.content;
|
|
815
|
+
}
|
|
816
|
+
return P(s, e);
|
|
796
817
|
}
|
|
797
|
-
function
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
818
|
+
function Nt(s) {
|
|
819
|
+
let t = 0;
|
|
820
|
+
return s.state.tokens.get().map((n) => {
|
|
821
|
+
const r = n.content.length;
|
|
822
|
+
return t += r, t - r;
|
|
823
|
+
}) ?? [];
|
|
824
|
+
}
|
|
825
|
+
function P(s, t) {
|
|
826
|
+
const e = s.state.parser.get();
|
|
827
|
+
return e ? e.parse(t) : [
|
|
828
|
+
{
|
|
829
|
+
type: "text",
|
|
830
|
+
content: t,
|
|
831
|
+
position: { start: 0, end: t.length }
|
|
832
|
+
}
|
|
833
|
+
];
|
|
834
|
+
}
|
|
835
|
+
const Pt = (s, t) => s === t;
|
|
836
|
+
class I {
|
|
837
|
+
#t;
|
|
838
|
+
#e = /* @__PURE__ */ new Set();
|
|
839
|
+
#n;
|
|
840
|
+
constructor(t, e) {
|
|
841
|
+
this.#t = t, this.#n = e?.equals ?? Pt;
|
|
842
|
+
}
|
|
843
|
+
static event() {
|
|
844
|
+
return new I(void 0, { equals: !1 });
|
|
845
|
+
}
|
|
846
|
+
get value() {
|
|
847
|
+
return this.#t;
|
|
848
|
+
}
|
|
849
|
+
set value(t) {
|
|
850
|
+
(this.#n === !1 || !this.#n(this.#t, t)) && (this.#t = t, this.#e.forEach((e) => e(t)));
|
|
851
|
+
}
|
|
852
|
+
on(t) {
|
|
853
|
+
return this.#e.add(t), () => this.#e.delete(t);
|
|
854
|
+
}
|
|
855
|
+
emit(t) {
|
|
856
|
+
arguments.length > 0 && (this.#t = t), this.#e.forEach((e) => e(this.#t));
|
|
857
|
+
}
|
|
858
|
+
get() {
|
|
859
|
+
return this.#t;
|
|
860
|
+
}
|
|
861
|
+
set(t) {
|
|
862
|
+
this.value = t;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function Lt(s, t) {
|
|
866
|
+
const e = {};
|
|
867
|
+
return e.get = () => s.get(), e.set = (n) => s.set(n), e.on = (n) => s.on(n), e.use = t(e), e;
|
|
868
|
+
}
|
|
869
|
+
function At(s, t) {
|
|
870
|
+
const e = /* @__PURE__ */ new Map();
|
|
871
|
+
for (const n in s)
|
|
872
|
+
e.set(n, new I(s[n]));
|
|
873
|
+
return new Proxy(s, {
|
|
874
|
+
get(n, r) {
|
|
875
|
+
if (r === "set")
|
|
876
|
+
return (i) => {
|
|
877
|
+
for (const a in i)
|
|
878
|
+
e.get(a)?.set(i[a]);
|
|
879
|
+
};
|
|
880
|
+
const o = e.get(r);
|
|
881
|
+
if (o)
|
|
882
|
+
return Lt(o, t);
|
|
809
883
|
}
|
|
810
884
|
});
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
};
|
|
838
|
-
class S {
|
|
885
|
+
}
|
|
886
|
+
function Ot(s) {
|
|
887
|
+
const t = function(e) {
|
|
888
|
+
s.emit(e);
|
|
889
|
+
};
|
|
890
|
+
return t.on = (e) => s.on(e), t;
|
|
891
|
+
}
|
|
892
|
+
function _t(s) {
|
|
893
|
+
const t = [], e = /* @__PURE__ */ new Map();
|
|
894
|
+
for (const n of t)
|
|
895
|
+
e.set(n, I.event());
|
|
896
|
+
return new Proxy({}, {
|
|
897
|
+
get(n, r) {
|
|
898
|
+
let o = e.get(r);
|
|
899
|
+
return o || (o = I.event(), e.set(r, o)), Ot(o);
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
class $t {
|
|
904
|
+
#t = 1;
|
|
905
|
+
#e = /* @__PURE__ */ new WeakMap();
|
|
906
|
+
get(t) {
|
|
907
|
+
return this.#e.has(t) ? this.#e.get(t) : (this.#e.set(t, this.#t), this.#t++);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
class m {
|
|
839
911
|
static get isSelectedPosition() {
|
|
840
|
-
const
|
|
841
|
-
if (
|
|
842
|
-
return
|
|
912
|
+
const t = window.getSelection();
|
|
913
|
+
if (t)
|
|
914
|
+
return t.isCollapsed;
|
|
843
915
|
}
|
|
844
916
|
static getCurrentPosition() {
|
|
845
917
|
return window.getSelection()?.anchorOffset ?? 0;
|
|
@@ -849,61 +921,61 @@ class S {
|
|
|
849
921
|
return window.getSelection()?.anchorNode?.textContent ?? "";
|
|
850
922
|
}
|
|
851
923
|
static getSelectedNode() {
|
|
852
|
-
const
|
|
853
|
-
if (
|
|
924
|
+
const t = window.getSelection()?.anchorNode;
|
|
925
|
+
if (t) return t;
|
|
854
926
|
throw new Error("Anchor node of selection is not exists!");
|
|
855
927
|
}
|
|
856
928
|
//TODO add the returned type: "{left: CSSProperties["left"], top: CSSProperties["top"]}"?
|
|
857
929
|
static getAbsolutePosition() {
|
|
858
|
-
const
|
|
859
|
-
return
|
|
930
|
+
const t = window.getSelection()?.getRangeAt(0).getBoundingClientRect?.();
|
|
931
|
+
return t ? { left: t.left, top: t.top + t.height + 1 } : { left: 0, top: 0 };
|
|
860
932
|
}
|
|
861
|
-
static trySetIndex(
|
|
933
|
+
static trySetIndex(t, e) {
|
|
862
934
|
try {
|
|
863
|
-
this.setIndex(
|
|
864
|
-
} catch (
|
|
865
|
-
console.error(
|
|
935
|
+
this.setIndex(t, e);
|
|
936
|
+
} catch (n) {
|
|
937
|
+
console.error(n);
|
|
866
938
|
}
|
|
867
939
|
}
|
|
868
|
-
static setIndex(
|
|
869
|
-
const
|
|
870
|
-
if (!
|
|
871
|
-
const r =
|
|
872
|
-
r?.setStart(
|
|
940
|
+
static setIndex(t, e) {
|
|
941
|
+
const n = window.getSelection();
|
|
942
|
+
if (!n?.anchorNode || !n.rangeCount) return;
|
|
943
|
+
const r = n.getRangeAt(0);
|
|
944
|
+
r?.setStart(t.firstChild || t, e), r?.setEnd(t.firstChild || t, e);
|
|
873
945
|
}
|
|
874
|
-
static getCaretIndex(
|
|
875
|
-
let
|
|
876
|
-
const
|
|
877
|
-
if (!
|
|
878
|
-
const r =
|
|
879
|
-
return o.selectNodeContents(
|
|
946
|
+
static getCaretIndex(t) {
|
|
947
|
+
let e = 0;
|
|
948
|
+
const n = window.getSelection();
|
|
949
|
+
if (!n?.rangeCount) return e;
|
|
950
|
+
const r = n.getRangeAt(0), o = r.cloneRange();
|
|
951
|
+
return o.selectNodeContents(t), o.setEnd(r.endContainer, r.endOffset), e = o.toString().length, e;
|
|
880
952
|
}
|
|
881
|
-
static setCaretToEnd(
|
|
882
|
-
if (!
|
|
883
|
-
window.getSelection()?.setPosition(
|
|
953
|
+
static setCaretToEnd(t) {
|
|
954
|
+
if (!t) return;
|
|
955
|
+
window.getSelection()?.setPosition(t, 1);
|
|
884
956
|
}
|
|
885
957
|
static getIndex() {
|
|
886
958
|
return window.getSelection()?.anchorOffset ?? NaN;
|
|
887
959
|
}
|
|
888
|
-
static setIndex1(
|
|
889
|
-
const
|
|
890
|
-
if (!
|
|
891
|
-
const
|
|
892
|
-
|
|
960
|
+
static setIndex1(t) {
|
|
961
|
+
const e = window.getSelection();
|
|
962
|
+
if (!e?.anchorNode || !e.rangeCount) return;
|
|
963
|
+
const n = e.getRangeAt(0);
|
|
964
|
+
n?.setStart(n.startContainer.firstChild || n.startContainer, t), n?.setEnd(n.startContainer.firstChild || n.startContainer, t);
|
|
893
965
|
}
|
|
894
|
-
setCaretRightTo(
|
|
966
|
+
setCaretRightTo(t, e) {
|
|
895
967
|
const r = window.getSelection()?.getRangeAt(0);
|
|
896
|
-
r?.setStart(r.endContainer,
|
|
968
|
+
r?.setStart(r.endContainer, e), r?.setEnd(r.endContainer, e);
|
|
897
969
|
}
|
|
898
970
|
}
|
|
899
|
-
const
|
|
900
|
-
class
|
|
971
|
+
const Vt = new RegExp(/^\w*/);
|
|
972
|
+
class F {
|
|
901
973
|
span;
|
|
902
974
|
node;
|
|
903
975
|
dividedText;
|
|
904
976
|
constructor() {
|
|
905
|
-
const
|
|
906
|
-
this.node =
|
|
977
|
+
const t = m.getCurrentPosition();
|
|
978
|
+
this.node = m.getSelectedNode(), this.span = m.getFocusedSpan(), this.dividedText = this.getDividedTextBy(t);
|
|
907
979
|
}
|
|
908
980
|
/**
|
|
909
981
|
* Find overlay match in text using provided options and trigger extractor.
|
|
@@ -920,12 +992,12 @@ class U {
|
|
|
920
992
|
* // Other framework usage
|
|
921
993
|
* TriggerFinder.find(vueOptions, (opt) => opt.overlay?.trigger ?? '@')
|
|
922
994
|
*/
|
|
923
|
-
static find(
|
|
924
|
-
if (
|
|
925
|
-
return new
|
|
995
|
+
static find(t, e) {
|
|
996
|
+
if (t && m.isSelectedPosition)
|
|
997
|
+
return new F().find(t, e);
|
|
926
998
|
}
|
|
927
|
-
getDividedTextBy(
|
|
928
|
-
return { left: this.span.slice(0,
|
|
999
|
+
getDividedTextBy(t) {
|
|
1000
|
+
return { left: this.span.slice(0, t), right: this.span.slice(t) };
|
|
929
1001
|
}
|
|
930
1002
|
/**
|
|
931
1003
|
* Find overlay match in provided options.
|
|
@@ -933,9 +1005,9 @@ class U {
|
|
|
933
1005
|
* @param options - Array of options
|
|
934
1006
|
* @param getTrigger - Function to extract trigger from each option
|
|
935
1007
|
*/
|
|
936
|
-
find(
|
|
937
|
-
for (let
|
|
938
|
-
const r =
|
|
1008
|
+
find(t, e) {
|
|
1009
|
+
for (let n = 0; n < t.length; n++) {
|
|
1010
|
+
const r = t[n], o = e(r, n);
|
|
939
1011
|
if (!o) continue;
|
|
940
1012
|
const i = this.matchInTextVia(o);
|
|
941
1013
|
if (i)
|
|
@@ -949,29 +1021,29 @@ class U {
|
|
|
949
1021
|
};
|
|
950
1022
|
}
|
|
951
1023
|
}
|
|
952
|
-
matchInTextVia(
|
|
953
|
-
const
|
|
954
|
-
if (
|
|
1024
|
+
matchInTextVia(t = "@") {
|
|
1025
|
+
const e = this.matchRightPart(), n = this.matchLeftPart(t);
|
|
1026
|
+
if (n)
|
|
955
1027
|
return {
|
|
956
|
-
word:
|
|
957
|
-
annotation:
|
|
958
|
-
index:
|
|
1028
|
+
word: n.word + e.word,
|
|
1029
|
+
annotation: n.annotation + e.word,
|
|
1030
|
+
index: n.index
|
|
959
1031
|
};
|
|
960
1032
|
}
|
|
961
1033
|
matchRightPart() {
|
|
962
|
-
const { right:
|
|
963
|
-
return { word:
|
|
1034
|
+
const { right: t } = this.dividedText;
|
|
1035
|
+
return { word: t.match(Vt)?.[0] };
|
|
964
1036
|
}
|
|
965
|
-
matchLeftPart(
|
|
966
|
-
const
|
|
1037
|
+
matchLeftPart(t) {
|
|
1038
|
+
const e = this.makeTriggerRegex(t), { left: n } = this.dividedText, r = n.match(e);
|
|
967
1039
|
if (!r) return;
|
|
968
1040
|
const [o, i] = r;
|
|
969
1041
|
return { word: i, annotation: o, index: r.index ?? 0 };
|
|
970
1042
|
}
|
|
971
1043
|
//TODO new overlayMatch option if (isSpaceBeforeRequired) append space check for not first words '\\s'
|
|
972
|
-
makeTriggerRegex(
|
|
973
|
-
const
|
|
974
|
-
return new RegExp(
|
|
1044
|
+
makeTriggerRegex(t) {
|
|
1045
|
+
const e = b(t) + "(\\w*)$";
|
|
1046
|
+
return new RegExp(e);
|
|
975
1047
|
}
|
|
976
1048
|
}
|
|
977
1049
|
class M {
|
|
@@ -980,8 +1052,8 @@ class M {
|
|
|
980
1052
|
get target() {
|
|
981
1053
|
return this.#t;
|
|
982
1054
|
}
|
|
983
|
-
set target(
|
|
984
|
-
this.#t =
|
|
1055
|
+
set target(t) {
|
|
1056
|
+
this.#t = t;
|
|
985
1057
|
}
|
|
986
1058
|
get next() {
|
|
987
1059
|
return new M(this.target?.nextSibling, this.#e);
|
|
@@ -999,19 +1071,19 @@ class M {
|
|
|
999
1071
|
return this.target?.isContentEditable ?? !1;
|
|
1000
1072
|
}
|
|
1001
1073
|
get isCaretAtBeginning() {
|
|
1002
|
-
return this.target ?
|
|
1074
|
+
return this.target ? m.getCaretIndex(this.target) === 0 : void 0;
|
|
1003
1075
|
}
|
|
1004
1076
|
get isCaretAtEnd() {
|
|
1005
|
-
return this.target ?
|
|
1077
|
+
return this.target ? m.getCaretIndex(this.target) === this.target.textContent?.length : void 0;
|
|
1006
1078
|
}
|
|
1007
1079
|
get index() {
|
|
1008
1080
|
return this.target?.parentElement ? [...this.target.parentElement.children].indexOf(this.target) : -1;
|
|
1009
1081
|
}
|
|
1010
1082
|
get caret() {
|
|
1011
|
-
return this.target ?
|
|
1083
|
+
return this.target ? m.getCaretIndex(this.target) : -1;
|
|
1012
1084
|
}
|
|
1013
|
-
set caret(
|
|
1014
|
-
this.target &&
|
|
1085
|
+
set caret(t) {
|
|
1086
|
+
this.target && m.trySetIndex(this.target, t);
|
|
1015
1087
|
}
|
|
1016
1088
|
get length() {
|
|
1017
1089
|
return this.target?.textContent?.length ?? -1;
|
|
@@ -1019,8 +1091,8 @@ class M {
|
|
|
1019
1091
|
get content() {
|
|
1020
1092
|
return this.target?.textContent ?? "";
|
|
1021
1093
|
}
|
|
1022
|
-
set content(
|
|
1023
|
-
this.target && (this.target.textContent =
|
|
1094
|
+
set content(t) {
|
|
1095
|
+
this.target && (this.target.textContent = t ?? "");
|
|
1024
1096
|
}
|
|
1025
1097
|
get head() {
|
|
1026
1098
|
return this.#e.refs.container?.firstChild;
|
|
@@ -1031,11 +1103,11 @@ class M {
|
|
|
1031
1103
|
get isFocused() {
|
|
1032
1104
|
return this.target === document.activeElement;
|
|
1033
1105
|
}
|
|
1034
|
-
constructor(
|
|
1035
|
-
this.target =
|
|
1106
|
+
constructor(t, e) {
|
|
1107
|
+
this.target = t, this.#e = e;
|
|
1036
1108
|
}
|
|
1037
1109
|
setCaretToEnd() {
|
|
1038
|
-
|
|
1110
|
+
m.setCaretToEnd(this.target);
|
|
1039
1111
|
}
|
|
1040
1112
|
focus() {
|
|
1041
1113
|
this.target?.focus();
|
|
@@ -1044,712 +1116,748 @@ class M {
|
|
|
1044
1116
|
this.target = void 0;
|
|
1045
1117
|
}
|
|
1046
1118
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
nodes = {
|
|
1066
|
-
focus: new M(void 0, this),
|
|
1067
|
-
input: new M(void 0, this)
|
|
1068
|
-
};
|
|
1069
|
-
recovery;
|
|
1070
|
-
// UI domain
|
|
1071
|
-
refs = {
|
|
1072
|
-
container: null,
|
|
1073
|
-
overlay: null,
|
|
1074
|
-
setContainer: (e) => {
|
|
1075
|
-
this.refs.container = e;
|
|
1076
|
-
},
|
|
1077
|
-
setOverlay: (e) => {
|
|
1078
|
-
this.refs.overlay = e;
|
|
1079
|
-
}
|
|
1080
|
-
};
|
|
1081
|
-
selecting;
|
|
1082
|
-
// Overlay domain
|
|
1083
|
-
overlayMatch;
|
|
1084
|
-
constructor(e) {
|
|
1085
|
-
this.props = e;
|
|
1086
|
-
}
|
|
1087
|
-
static create = (e) => new Proxy(new B(e), { set: De });
|
|
1088
|
-
}
|
|
1089
|
-
const _e = /* @__PURE__ */ new Set(["bus", "refs", "nodes", "key"]);
|
|
1090
|
-
function De(t, e, n, s) {
|
|
1091
|
-
return _e.has(String(e)) ? !1 : (t[e] === n || (t[e] = n, t.bus.send(p.STORE_UPDATED, s)), !0);
|
|
1092
|
-
}
|
|
1093
|
-
const P = ce(void 0);
|
|
1094
|
-
P.displayName = "StoreContext";
|
|
1095
|
-
function v(t, e, n) {
|
|
1096
|
-
typeof t == "string" ? $e(t, e, n) : Re(t, e, n);
|
|
1097
|
-
}
|
|
1098
|
-
function Re(t, e, n) {
|
|
1099
|
-
const s = N(P);
|
|
1100
|
-
Q(s), x(() => s.bus.on(t, e), n);
|
|
1101
|
-
}
|
|
1102
|
-
function $e(t, e, n) {
|
|
1103
|
-
const s = N(P);
|
|
1104
|
-
x(() => (s?.refs.container?.addEventListener(t, e), () => s?.refs.container?.removeEventListener(t, e)), n);
|
|
1105
|
-
}
|
|
1106
|
-
function f(t, e) {
|
|
1107
|
-
const n = N(P);
|
|
1108
|
-
Q(n);
|
|
1109
|
-
const [s, r] = A(() => t?.(n));
|
|
1110
|
-
return v(
|
|
1111
|
-
p.STORE_UPDATED,
|
|
1112
|
-
() => {
|
|
1113
|
-
r((o) => {
|
|
1114
|
-
const i = t?.(n);
|
|
1115
|
-
return e && Pe(o, i) ? o : i;
|
|
1116
|
-
});
|
|
1117
|
-
},
|
|
1118
|
-
[]
|
|
1119
|
-
), t ? s : n;
|
|
1120
|
-
}
|
|
1121
|
-
const Ve = (t) => {
|
|
1122
|
-
const e = ae.createContext(void 0);
|
|
1123
|
-
e.displayName = t;
|
|
1124
|
-
const n = o(e), s = e.Provider;
|
|
1125
|
-
return [n, s, e];
|
|
1126
|
-
function o(i) {
|
|
1127
|
-
return () => {
|
|
1128
|
-
const a = N(i);
|
|
1129
|
-
if (a) return a;
|
|
1130
|
-
throw new Error(`The context ${i.displayName} didn't found!`);
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
}, [H, X] = Ve("NodeProvider");
|
|
1134
|
-
function ee(t, e, n, s) {
|
|
1135
|
-
const r = f((c) => t === "mark" ? c.props.Mark : c.props.Overlay), o = t === "mark" ? e?.mark : e?.overlay;
|
|
1136
|
-
let i;
|
|
1137
|
-
o !== void 0 ? typeof o == "function" ? i = o(n) : i = o : i = n ?? {};
|
|
1138
|
-
const a = i.slot || r || s;
|
|
1139
|
-
if (!a)
|
|
1140
|
-
throw new Error(
|
|
1141
|
-
`No ${t} component found. Provide either option.${t}.slot, global ${t === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
|
|
1142
|
-
);
|
|
1143
|
-
return [a, i];
|
|
1144
|
-
}
|
|
1145
|
-
function Fe() {
|
|
1146
|
-
const t = H(), { options: e, key: n } = f((c) => ({ options: c.props.options, key: c.key }), !0), s = e?.[t.descriptor.index], r = t.children.map((c) => /* @__PURE__ */ m(z, { mark: c, isNested: !0 }, n.get(c))), o = {
|
|
1147
|
-
value: t.value,
|
|
1148
|
-
meta: t.meta,
|
|
1149
|
-
nested: t.nested?.content,
|
|
1150
|
-
children: t.children.length > 0 ? r : void 0
|
|
1151
|
-
}, [i, a] = ee("mark", s, o);
|
|
1152
|
-
return /* @__PURE__ */ m(i, { ...a });
|
|
1153
|
-
}
|
|
1154
|
-
const We = () => {
|
|
1155
|
-
const t = H(), e = I(null), { readOnly: n, SpanComponent: s, spanProps: r } = f(
|
|
1156
|
-
(o) => ({
|
|
1157
|
-
readOnly: o.props.readOnly,
|
|
1158
|
-
SpanComponent: Z("span", o),
|
|
1159
|
-
spanProps: J("span", o)
|
|
1160
|
-
}),
|
|
1161
|
-
!0
|
|
1162
|
-
);
|
|
1163
|
-
if (t.type !== "text")
|
|
1164
|
-
throw new Error("TextSpan component expects a TextToken");
|
|
1165
|
-
return /* @__PURE__ */ m(
|
|
1166
|
-
s,
|
|
1167
|
-
{
|
|
1168
|
-
...r,
|
|
1169
|
-
ref: e,
|
|
1170
|
-
contentEditable: !n,
|
|
1171
|
-
onPaste: Ge,
|
|
1172
|
-
suppressContentEditableWarning: !0,
|
|
1173
|
-
children: t.content
|
|
1174
|
-
}
|
|
1175
|
-
);
|
|
1176
|
-
};
|
|
1177
|
-
function Ge(t) {
|
|
1178
|
-
t.preventDefault();
|
|
1179
|
-
const e = t.clipboardData.getData("text");
|
|
1180
|
-
document.execCommand("insertText", !1, e);
|
|
1181
|
-
}
|
|
1182
|
-
const z = W(({ mark: t, isNested: e = !1 }) => t.type === "mark" ? /* @__PURE__ */ m(X, { value: t, children: /* @__PURE__ */ m(Fe, {}) }) : e ? /* @__PURE__ */ m(oe, { children: t.content }) : /* @__PURE__ */ m(X, { value: t, children: /* @__PURE__ */ m(We, {}) }));
|
|
1183
|
-
z.displayName = "Token";
|
|
1184
|
-
const te = W(() => {
|
|
1185
|
-
const { className: t, style: e, tokens: n, bus: s, key: r, ContainerComponent: o, containerProps: i, refs: a } = f(
|
|
1186
|
-
(c) => ({
|
|
1187
|
-
className: c.props.className,
|
|
1188
|
-
style: c.props.style,
|
|
1189
|
-
tokens: c.tokens,
|
|
1190
|
-
bus: c.bus,
|
|
1191
|
-
key: c.key,
|
|
1192
|
-
refs: c.refs,
|
|
1193
|
-
ContainerComponent: Z("container", c),
|
|
1194
|
-
containerProps: J("container", c)
|
|
1195
|
-
}),
|
|
1196
|
-
!0
|
|
1197
|
-
);
|
|
1198
|
-
return v("input", () => s.send(p.Change), []), /* @__PURE__ */ m(o, { ref: a.setContainer, ...i, className: t, style: e, children: n.map((c) => /* @__PURE__ */ m(z, { mark: c }, r.get(c))) });
|
|
1199
|
-
});
|
|
1200
|
-
te.displayName = "Container";
|
|
1201
|
-
function Ue() {
|
|
1202
|
-
const { match: t, bus: e } = f(
|
|
1203
|
-
(n) => ({
|
|
1204
|
-
match: n.overlayMatch,
|
|
1205
|
-
bus: n.bus
|
|
1206
|
-
}),
|
|
1207
|
-
!0
|
|
1208
|
-
);
|
|
1209
|
-
x(() => {
|
|
1210
|
-
if (!t) return;
|
|
1211
|
-
const n = (s) => {
|
|
1212
|
-
s.key === k.ESC && e.send(p.ClearTrigger);
|
|
1213
|
-
};
|
|
1214
|
-
return window.addEventListener("keydown", n), () => window.removeEventListener("keydown", n);
|
|
1215
|
-
}, [t, e]);
|
|
1216
|
-
}
|
|
1217
|
-
function Be() {
|
|
1218
|
-
const t = f(), e = f((n) => n.overlayMatch);
|
|
1219
|
-
x(() => {
|
|
1220
|
-
if (!e) return;
|
|
1221
|
-
const n = (s) => {
|
|
1222
|
-
const r = s.target;
|
|
1223
|
-
t.refs.overlay?.contains(r) || t.refs.container?.contains(r) || t.bus.send(p.ClearTrigger);
|
|
1224
|
-
};
|
|
1225
|
-
return document.addEventListener("click", n), () => document.removeEventListener("click", n);
|
|
1226
|
-
}, [e]);
|
|
1227
|
-
}
|
|
1228
|
-
function C(t, e, n = []) {
|
|
1229
|
-
v(
|
|
1230
|
-
"keydown",
|
|
1231
|
-
(s) => {
|
|
1232
|
-
s.key === t && e(s);
|
|
1233
|
-
},
|
|
1234
|
-
n
|
|
1119
|
+
function Rt(s, t, e, n) {
|
|
1120
|
+
return s.slice(0, e) + t + s.slice(e + n.length);
|
|
1121
|
+
}
|
|
1122
|
+
function _(s, t) {
|
|
1123
|
+
const n = {
|
|
1124
|
+
prev: 2,
|
|
1125
|
+
self: 1,
|
|
1126
|
+
next: 0
|
|
1127
|
+
}[s], { focus: r } = t.nodes, o = t.state.tokens.get(), [i, , a] = o.splice(r.index - n, 3), l = (i.type === "text", i.content), c = (a.type === "text", a.content);
|
|
1128
|
+
t.state.tokens.set(
|
|
1129
|
+
o.toSpliced(r.index - n, 0, {
|
|
1130
|
+
type: "text",
|
|
1131
|
+
content: l + c,
|
|
1132
|
+
position: {
|
|
1133
|
+
start: i.position.start,
|
|
1134
|
+
end: a.position.end
|
|
1135
|
+
}
|
|
1136
|
+
})
|
|
1235
1137
|
);
|
|
1138
|
+
let d = r;
|
|
1139
|
+
for (let h = 0; h < n; h++)
|
|
1140
|
+
d = d.prev;
|
|
1141
|
+
const u = d.length;
|
|
1142
|
+
t.state.recovery.set({ anchor: d.prev, caret: u }), t.state.onChange.get()?.(y(t.state.tokens.get()));
|
|
1236
1143
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
const u = t.refs.container;
|
|
1241
|
-
if (!u) return;
|
|
1242
|
-
const d = (g) => {
|
|
1243
|
-
c(g);
|
|
1244
|
-
};
|
|
1245
|
-
return u.addEventListener("beforeinput", d, !0), () => u.removeEventListener("beforeinput", d, !0);
|
|
1246
|
-
}, []);
|
|
1247
|
-
function e(u) {
|
|
1248
|
-
const { focus: d } = t.nodes;
|
|
1249
|
-
if (d.isMark && !d.isEditable || d.isCaretAtBeginning) {
|
|
1250
|
-
const g = d.prev;
|
|
1251
|
-
g.focus(), g.isFocused || (g.prev.focus(), u.preventDefault()), d.setCaretToEnd();
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
function n(u) {
|
|
1255
|
-
const { focus: d } = t.nodes;
|
|
1256
|
-
if (d.isMark && !d.isEditable || d.isCaretAtEnd) {
|
|
1257
|
-
const g = d.next;
|
|
1258
|
-
g.focus(), g.isFocused || (g.next.focus(), u.preventDefault());
|
|
1259
|
-
}
|
|
1144
|
+
class Dt {
|
|
1145
|
+
constructor(t) {
|
|
1146
|
+
this.store = t;
|
|
1260
1147
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1148
|
+
#t;
|
|
1149
|
+
#e;
|
|
1150
|
+
#n;
|
|
1151
|
+
enable() {
|
|
1152
|
+
this.#t || (this.#t = this.store.events.change.on(() => {
|
|
1153
|
+
const t = this.store.state.onChange.get();
|
|
1154
|
+
if (!this.store.nodes.focus.target) return;
|
|
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?.(y(e)), this.store.events.parse();
|
|
1157
|
+
}), this.#e = this.store.events.delete.on((t) => {
|
|
1158
|
+
if (!t) return;
|
|
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?.(y(this.store.state.tokens.get()));
|
|
1161
|
+
}), this.#n = this.store.events.select.on((t) => {
|
|
1162
|
+
if (!t) return;
|
|
1163
|
+
const e = this.store.state.Mark.get(), n = this.store.state.onChange.get(), {
|
|
1164
|
+
mark: r,
|
|
1165
|
+
match: { option: o, span: i, index: a, source: l }
|
|
1166
|
+
} = t, c = r.type === "mark" ? $(o.markup, {
|
|
1167
|
+
value: r.value,
|
|
1168
|
+
meta: r.meta
|
|
1169
|
+
}) : $(o.markup, {
|
|
1170
|
+
value: r.content
|
|
1171
|
+
}), d = Rt(i, c, a, l);
|
|
1172
|
+
if (this.store.state.recovery.set(
|
|
1173
|
+
e ? {
|
|
1174
|
+
caret: 0,
|
|
1175
|
+
anchor: this.store.nodes.input.next,
|
|
1176
|
+
isNext: !0,
|
|
1177
|
+
childIndex: this.store.nodes.input.index
|
|
1178
|
+
} : { caret: a + c.length, anchor: this.store.nodes.input }
|
|
1179
|
+
), this.store.nodes.input.target) {
|
|
1180
|
+
this.store.nodes.input.content = d;
|
|
1181
|
+
const u = this.store.state.tokens.get(), h = u[this.store.nodes.input.index];
|
|
1182
|
+
h.type === "text" && (h.content = d), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(y(u)), this.store.events.parse();
|
|
1183
|
+
}
|
|
1184
|
+
}));
|
|
1263
1185
|
}
|
|
1264
|
-
|
|
1265
|
-
t
|
|
1186
|
+
disable() {
|
|
1187
|
+
this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0;
|
|
1266
1188
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1189
|
+
}
|
|
1190
|
+
class Ht {
|
|
1191
|
+
constructor(t) {
|
|
1192
|
+
this.store = t;
|
|
1269
1193
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
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 = F.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));
|
|
1277
1222
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
const
|
|
1283
|
-
|
|
1284
|
-
}
|
|
1285
|
-
return !1;
|
|
1286
|
-
}
|
|
1223
|
+
enableClose() {
|
|
1224
|
+
this.#i || (this.#i = (t) => {
|
|
1225
|
+
t.key === v.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));
|
|
1287
1230
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
t.selecting === "all" && (t.selecting = void 0);
|
|
1291
|
-
return;
|
|
1292
|
-
}
|
|
1293
|
-
if (u.inputType === "insertFromPaste") return;
|
|
1294
|
-
u.preventDefault();
|
|
1295
|
-
const d = u.inputType.startsWith("delete") ? "" : u.data ?? "";
|
|
1296
|
-
h(d);
|
|
1297
|
-
}
|
|
1298
|
-
function l(u) {
|
|
1299
|
-
if (t.selecting !== "all" || !a()) {
|
|
1300
|
-
t.selecting === "all" && (t.selecting = void 0);
|
|
1301
|
-
return;
|
|
1302
|
-
}
|
|
1303
|
-
u.preventDefault();
|
|
1304
|
-
const d = u.clipboardData?.getData("text/plain") ?? "";
|
|
1305
|
-
h(d);
|
|
1231
|
+
disableClose() {
|
|
1232
|
+
this.#i && (window.removeEventListener("keydown", this.#i), document.removeEventListener("click", this.#a, !0), this.#i = void 0, this.#a = void 0);
|
|
1306
1233
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
type: "text",
|
|
1311
|
-
content: u,
|
|
1312
|
-
position: { start: 0, end: u.length }
|
|
1313
|
-
}
|
|
1314
|
-
]), queueMicrotask(() => {
|
|
1315
|
-
const d = t.refs.container?.firstChild;
|
|
1316
|
-
d && (t.recovery = {
|
|
1317
|
-
anchor: t.nodes.focus,
|
|
1318
|
-
caret: u.length
|
|
1319
|
-
}, d.focus());
|
|
1320
|
-
});
|
|
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;
|
|
1321
1237
|
}
|
|
1322
1238
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
}) : $(o.markup, {
|
|
1351
|
-
value: r.content
|
|
1352
|
-
}), h = Ne(i, l, a, c);
|
|
1353
|
-
if (t.recovery = n ? { caret: 0, anchor: t.nodes.input.next, isNext: !0 } : { caret: a + l.length, anchor: t.nodes.input }, t.nodes.input.target) {
|
|
1354
|
-
t.nodes.input.content = h;
|
|
1355
|
-
const u = t.tokens[t.nodes.input.index];
|
|
1356
|
-
u.type === "text" && (u.content = h), t.nodes.focus.target = t.nodes.input.target, t.nodes.input.clear(), s?.(T(t.tokens)), t.bus.send(p.Parse);
|
|
1357
|
-
}
|
|
1358
|
-
},
|
|
1359
|
-
[]
|
|
1360
|
-
);
|
|
1361
|
-
}
|
|
1362
|
-
const je = () => {
|
|
1363
|
-
const t = f();
|
|
1364
|
-
v("focusin", (e) => t.nodes.focus.target = e.target, []), v("focusout", (e) => t.nodes.focus.target = void 0, []);
|
|
1365
|
-
}, qe = () => {
|
|
1366
|
-
const t = f(), e = f((n) => n.tokens);
|
|
1367
|
-
v(
|
|
1368
|
-
"click",
|
|
1369
|
-
() => {
|
|
1370
|
-
e.length === 1 && e[0].type === "text" && e[0].content === "" && t.refs.container?.firstElementChild?.focus();
|
|
1371
|
-
},
|
|
1372
|
-
[e]
|
|
1373
|
-
);
|
|
1374
|
-
}, Xe = () => {
|
|
1375
|
-
const t = f(), e = f((s) => s.tokens), n = t.props.Mark ? [e] : void 0;
|
|
1376
|
-
x(() => {
|
|
1377
|
-
if (!t.recovery) return;
|
|
1378
|
-
const { anchor: s, caret: r, isNext: o } = t.recovery;
|
|
1239
|
+
class Ft {
|
|
1240
|
+
constructor(t) {
|
|
1241
|
+
this.store = t;
|
|
1242
|
+
}
|
|
1243
|
+
#t;
|
|
1244
|
+
#e;
|
|
1245
|
+
#n;
|
|
1246
|
+
enable() {
|
|
1247
|
+
if (this.#t) return;
|
|
1248
|
+
const t = this.store.refs.container;
|
|
1249
|
+
t && (this.#t = (e) => {
|
|
1250
|
+
this.store.nodes.focus.target = e.target;
|
|
1251
|
+
}, this.#e = () => {
|
|
1252
|
+
this.store.nodes.focus.target = void 0;
|
|
1253
|
+
}, this.#n = () => {
|
|
1254
|
+
const e = this.store.state.tokens.get();
|
|
1255
|
+
e.length === 1 && e[0].type === "text" && e[0].content === "" && this.store.refs.container?.firstElementChild?.focus();
|
|
1256
|
+
}, t.addEventListener("focusin", this.#t), t.addEventListener("focusout", this.#e), t.addEventListener("click", this.#n));
|
|
1257
|
+
}
|
|
1258
|
+
disable() {
|
|
1259
|
+
const t = this.store.refs.container;
|
|
1260
|
+
!t || !this.#t || (t.removeEventListener("focusin", this.#t), t.removeEventListener("focusout", this.#e), t.removeEventListener("click", this.#n), this.#t = void 0, this.#e = void 0, this.#n = void 0);
|
|
1261
|
+
}
|
|
1262
|
+
recover() {
|
|
1263
|
+
const t = this.store.state.recovery.get();
|
|
1264
|
+
if (!t) return;
|
|
1265
|
+
const { anchor: e, caret: n, isNext: r } = t, o = !e.target || !e.target.isConnected;
|
|
1379
1266
|
switch (!0) {
|
|
1380
|
-
case (
|
|
1381
|
-
|
|
1267
|
+
case (r && o): {
|
|
1268
|
+
const i = this.store.refs.container, a = t.childIndex != null ? i?.children[t.childIndex + 2] : void 0;
|
|
1269
|
+
a ? a.focus() : this.store.nodes.focus.tail.focus();
|
|
1382
1270
|
break;
|
|
1383
|
-
|
|
1384
|
-
|
|
1271
|
+
}
|
|
1272
|
+
case r:
|
|
1273
|
+
e.prev.focus();
|
|
1385
1274
|
break;
|
|
1386
|
-
case
|
|
1387
|
-
|
|
1275
|
+
case o:
|
|
1276
|
+
this.store.nodes.focus.head.focus();
|
|
1388
1277
|
break;
|
|
1389
1278
|
default:
|
|
1390
|
-
|
|
1279
|
+
e.next.focus();
|
|
1391
1280
|
}
|
|
1392
|
-
|
|
1393
|
-
}
|
|
1394
|
-
};
|
|
1395
|
-
function Ze() {
|
|
1396
|
-
const t = f(), e = I(!1), n = I(null);
|
|
1397
|
-
x(() => {
|
|
1398
|
-
const s = (r) => {
|
|
1399
|
-
n.current = r.target, e.current = !0;
|
|
1400
|
-
};
|
|
1401
|
-
return document.addEventListener("mousedown", s), () => document.removeEventListener("mousedown", s);
|
|
1402
|
-
}, []), x(() => {
|
|
1403
|
-
const s = (r) => {
|
|
1404
|
-
const o = e.current, i = !t.refs.container?.contains(n.current) || n.current !== r.target, a = window.getSelection()?.containsNode(t.refs.container, !0);
|
|
1405
|
-
o && i && a && (t.selecting = "drag");
|
|
1406
|
-
};
|
|
1407
|
-
return document.addEventListener("mousemove", s), () => document.removeEventListener("mousemove", s);
|
|
1408
|
-
}, []), x(() => {
|
|
1409
|
-
const s = () => {
|
|
1410
|
-
e.current = !1, n.current = null, t.selecting = void 0;
|
|
1411
|
-
};
|
|
1412
|
-
return document.addEventListener("mouseup", s), () => document.removeEventListener("mouseup", s);
|
|
1413
|
-
}, []), Je();
|
|
1414
|
-
}
|
|
1415
|
-
function Je() {
|
|
1416
|
-
const t = f(), e = f((n) => n.selecting);
|
|
1417
|
-
x(() => {
|
|
1418
|
-
if (e !== "drag") return;
|
|
1419
|
-
const n = [...t.refs.container.children], s = n.map((r) => r.contentEditable);
|
|
1420
|
-
return n.forEach((r) => r.contentEditable = "false"), () => n.forEach((r, o) => r.contentEditable = s[o]);
|
|
1421
|
-
}, [e]);
|
|
1422
|
-
}
|
|
1423
|
-
function Qe() {
|
|
1424
|
-
const t = f(), e = R(() => {
|
|
1425
|
-
const n = t.props.showOverlayOn, s = "selectionChange";
|
|
1426
|
-
(n === s || n.includes(s)) && t.bus.send(p.CheckTrigger);
|
|
1427
|
-
}, []);
|
|
1428
|
-
v(
|
|
1429
|
-
"focusin",
|
|
1430
|
-
() => {
|
|
1431
|
-
document.addEventListener("selectionchange", e);
|
|
1432
|
-
},
|
|
1433
|
-
[]
|
|
1434
|
-
), v(
|
|
1435
|
-
"focusout",
|
|
1436
|
-
() => {
|
|
1437
|
-
document.removeEventListener("selectionchange", e);
|
|
1438
|
-
},
|
|
1439
|
-
[]
|
|
1440
|
-
), v(
|
|
1441
|
-
p.Change,
|
|
1442
|
-
() => {
|
|
1443
|
-
const n = t.props.showOverlayOn, s = "change";
|
|
1444
|
-
(n === s || n.includes(s)) && t.bus.send(p.CheckTrigger);
|
|
1445
|
-
},
|
|
1446
|
-
[]
|
|
1447
|
-
);
|
|
1281
|
+
this.store.nodes.focus.caret = n, this.store.state.recovery.set(void 0);
|
|
1282
|
+
}
|
|
1448
1283
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
return;
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1284
|
+
class Ut {
|
|
1285
|
+
constructor(t) {
|
|
1286
|
+
this.store = t;
|
|
1287
|
+
}
|
|
1288
|
+
#t;
|
|
1289
|
+
#e;
|
|
1290
|
+
#n;
|
|
1291
|
+
#s;
|
|
1292
|
+
#r = null;
|
|
1293
|
+
#o = !1;
|
|
1294
|
+
enable() {
|
|
1295
|
+
this.#t || (this.#t = (t) => {
|
|
1296
|
+
this.#r = t.target, this.#o = !0;
|
|
1297
|
+
}, this.#e = (t) => {
|
|
1298
|
+
const e = this.#o, n = !this.store.refs.container?.contains(this.#r) || this.#r !== t.target, r = window.getSelection()?.containsNode(this.store.refs.container, !0);
|
|
1299
|
+
e && n && r && this.store.state.selecting.set("drag");
|
|
1300
|
+
}, this.#n = () => {
|
|
1301
|
+
this.#o = !1, this.#r = null, this.store.state.selecting.set(void 0);
|
|
1302
|
+
}, this.#s = () => {
|
|
1303
|
+
if (this.store.state.selecting.get() !== "drag") return;
|
|
1304
|
+
const t = [...this.store.refs.container.children], e = t.map((n) => n.contentEditable);
|
|
1305
|
+
t.forEach((n) => n.contentEditable = "false"), t.forEach((n, r) => n.contentEditable = e[r]);
|
|
1306
|
+
}, document.addEventListener("mousedown", this.#t), document.addEventListener("mousemove", this.#e), document.addEventListener("mouseup", this.#n), document.addEventListener("selectionchange", this.#s));
|
|
1307
|
+
}
|
|
1308
|
+
disable() {
|
|
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
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function Wt(s, t) {
|
|
1313
|
+
if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
|
|
1314
|
+
t.preventDefault();
|
|
1315
|
+
const e = window.getSelection(), n = s.refs.container?.firstChild, r = s.refs.container?.lastChild;
|
|
1316
|
+
if (!e || !n || !r) return;
|
|
1317
|
+
e.setBaseAndExtent(n, 0, r, 1), s.state.selecting.set("all");
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
function Gt(s, t) {
|
|
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 Bt(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 jt {
|
|
1337
|
+
constructor(t) {
|
|
1338
|
+
this.store = t;
|
|
1339
|
+
}
|
|
1340
|
+
#t;
|
|
1341
|
+
#e;
|
|
1342
|
+
#n;
|
|
1343
|
+
enable() {
|
|
1344
|
+
if (this.#t) return;
|
|
1345
|
+
const t = this.store.refs.container;
|
|
1346
|
+
t && (this.#t = (e) => {
|
|
1347
|
+
e.key === v.LEFT ? Gt(this.store, e) : e.key === v.RIGHT && Bt(this.store, e), this.#s(e), Wt(this.store, e);
|
|
1348
|
+
}, this.#e = (e) => {
|
|
1349
|
+
zt(this.store, e);
|
|
1350
|
+
}, this.#n = (e) => {
|
|
1351
|
+
qt(this.store, e);
|
|
1352
|
+
}, t.addEventListener("keydown", this.#t), t.addEventListener("paste", this.#e), t.addEventListener("beforeinput", this.#n, !0));
|
|
1353
|
+
}
|
|
1354
|
+
disable() {
|
|
1355
|
+
const t = this.store.refs.container;
|
|
1356
|
+
!t || !this.#t || (t.removeEventListener("keydown", this.#t), t.removeEventListener("paste", this.#e), t.removeEventListener("beforeinput", this.#n, !0), this.#t = void 0, this.#e = void 0, this.#n = void 0);
|
|
1357
|
+
}
|
|
1358
|
+
#s(t) {
|
|
1359
|
+
const { focus: e } = this.store.nodes;
|
|
1360
|
+
if (t.key === v.DELETE || t.key === v.BACKSPACE) {
|
|
1361
|
+
if (e.isMark) {
|
|
1362
|
+
t.preventDefault(), _("self", this.store);
|
|
1363
|
+
return;
|
|
1476
1364
|
}
|
|
1477
|
-
|
|
1478
|
-
}, [n, s]), v(
|
|
1479
|
-
p.Parse,
|
|
1480
|
-
() => {
|
|
1481
|
-
t.tokens = t.nodes.focus.target ? et(t) : tt(t);
|
|
1482
|
-
},
|
|
1483
|
-
[]
|
|
1484
|
-
);
|
|
1485
|
-
};
|
|
1486
|
-
function et(t) {
|
|
1487
|
-
const { focus: e } = t.nodes;
|
|
1488
|
-
if (!t.parser)
|
|
1489
|
-
return t.tokens;
|
|
1490
|
-
const n = t.parser.parse(e.content);
|
|
1491
|
-
return n.length === 1 ? t.tokens : t.tokens.toSpliced(e.index, 1, ...n);
|
|
1492
|
-
}
|
|
1493
|
-
function tt(t) {
|
|
1494
|
-
const {
|
|
1495
|
-
props: { value: e }
|
|
1496
|
-
} = t, n = nt(t), s = Me(t.previousValue, e);
|
|
1497
|
-
switch (t.previousValue = e, !0) {
|
|
1498
|
-
//Mark removing happen
|
|
1499
|
-
case (s.left && n.includes(s.left) && s.right && Math.abs(s.left - s.right) > 1): {
|
|
1500
|
-
const r = n.indexOf(s.left), o = D(t, r - 1, r);
|
|
1501
|
-
return t.tokens.toSpliced(r - 1, 2, ...o);
|
|
1365
|
+
t.key === v.BACKSPACE && e.isSpan && e.isCaretAtBeginning && e.prev.target && (t.preventDefault(), _("prev", this.store)), t.key === v.DELETE && e.isSpan && e.isCaretAtEnd && e.next.target && (t.preventDefault(), _("next", this.store));
|
|
1502
1366
|
}
|
|
1503
|
-
//Changing in label
|
|
1504
|
-
case s.left !== void 0: {
|
|
1505
|
-
const [r] = q(n, s.left), o = D(t, r);
|
|
1506
|
-
return o.length === 1 ? t.tokens : t.tokens.toSpliced(r, 1, ...o);
|
|
1507
|
-
}
|
|
1508
|
-
case s.right !== void 0: {
|
|
1509
|
-
const [r] = q(n, s.right), o = D(t, r);
|
|
1510
|
-
return o.length === 1 ? t.tokens : t.tokens.toSpliced(r, 1, ...o);
|
|
1511
|
-
}
|
|
1512
|
-
default:
|
|
1513
|
-
return ne(t, e ?? "");
|
|
1514
1367
|
}
|
|
1515
1368
|
}
|
|
1516
|
-
function
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1369
|
+
function qt(s, t) {
|
|
1370
|
+
const e = s.state.selecting.get();
|
|
1371
|
+
if (e !== "all" || !Y(s)) {
|
|
1372
|
+
e === "all" && s.state.selecting.set(void 0);
|
|
1373
|
+
return;
|
|
1521
1374
|
}
|
|
1522
|
-
|
|
1375
|
+
if (t.inputType === "insertFromPaste") return;
|
|
1376
|
+
t.preventDefault();
|
|
1377
|
+
const n = t.inputType.startsWith("delete") ? "" : t.data ?? "";
|
|
1378
|
+
tt(s, n);
|
|
1523
1379
|
}
|
|
1524
|
-
function
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
return
|
|
1529
|
-
}
|
|
1380
|
+
function zt(s, t) {
|
|
1381
|
+
const e = s.state.selecting.get();
|
|
1382
|
+
if (e !== "all" || !Y(s)) {
|
|
1383
|
+
e === "all" && s.state.selecting.set(void 0);
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
t.preventDefault();
|
|
1387
|
+
const n = t.clipboardData?.getData("text/plain") ?? "";
|
|
1388
|
+
tt(s, n);
|
|
1530
1389
|
}
|
|
1531
|
-
function
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1390
|
+
function Y(s) {
|
|
1391
|
+
const t = window.getSelection(), e = s.refs.container;
|
|
1392
|
+
if (!t?.rangeCount || !e?.firstChild || !e?.lastChild) return !1;
|
|
1393
|
+
try {
|
|
1394
|
+
const n = t.getRangeAt(0);
|
|
1395
|
+
return e.contains(n.startContainer) && e.contains(n.endContainer) && n.toString().length > 0;
|
|
1396
|
+
} catch {
|
|
1397
|
+
return !1;
|
|
1398
|
+
}
|
|
1539
1399
|
}
|
|
1540
|
-
|
|
1541
|
-
get
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1400
|
+
function tt(s, t) {
|
|
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
|
+
s.state.parser.get()?.parse(t) ?? [
|
|
1403
|
+
{
|
|
1404
|
+
type: "text",
|
|
1405
|
+
content: t,
|
|
1406
|
+
position: { start: 0, end: t.length }
|
|
1407
|
+
}
|
|
1408
|
+
]
|
|
1409
|
+
), queueMicrotask(() => {
|
|
1410
|
+
const e = s.refs.container?.firstChild;
|
|
1411
|
+
e && (s.state.recovery.set({
|
|
1412
|
+
anchor: s.nodes.focus,
|
|
1413
|
+
caret: t.length
|
|
1414
|
+
}), e.focus());
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
class Xt {
|
|
1418
|
+
#t = [];
|
|
1419
|
+
#e = !1;
|
|
1420
|
+
register(t) {
|
|
1421
|
+
return this.#t.push(t), this;
|
|
1549
1422
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
const ot = ({ inRef: t }) => (rt(t), ze(), Ye(), je(), He(), qe(), Xe(), Ke(), Qe(), Ue(), Be(), Ze(), null), it = "_Container_1lmfr_1", at = "_Suggestions_1lmfr_10", ct = "_suggestionActive_1lmfr_38", V = {
|
|
1556
|
-
Container: it,
|
|
1557
|
-
Suggestions: at,
|
|
1558
|
-
suggestionActive: ct
|
|
1559
|
-
}, lt = [
|
|
1560
|
-
{
|
|
1561
|
-
markup: ve,
|
|
1562
|
-
overlay: {
|
|
1563
|
-
trigger: me,
|
|
1564
|
-
data: []
|
|
1565
|
-
}
|
|
1423
|
+
enableAll() {
|
|
1424
|
+
this.#e || (this.#e = !0, this.#t.forEach((t) => t.enable()));
|
|
1425
|
+
}
|
|
1426
|
+
disableAll() {
|
|
1427
|
+
this.#e && (this.#e = !1, this.#t.forEach((t) => t.disable()));
|
|
1566
1428
|
}
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1429
|
+
}
|
|
1430
|
+
const N = (s, t) => ({
|
|
1431
|
+
name: s,
|
|
1432
|
+
enable: () => t.enable(),
|
|
1433
|
+
disable: () => t.disable()
|
|
1434
|
+
}), Zt = (s) => {
|
|
1435
|
+
const t = new Xt();
|
|
1436
|
+
return t.register(N("keydown", s.controllers.keydown)).register(N("system", s.controllers.system)).register(N("focus", s.controllers.focus)).register(N("textSelection", s.controllers.textSelection)), t;
|
|
1572
1437
|
};
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1438
|
+
class Jt {
|
|
1439
|
+
constructor(t) {
|
|
1440
|
+
this.store = t;
|
|
1441
|
+
}
|
|
1442
|
+
#t = [];
|
|
1443
|
+
#e = !1;
|
|
1444
|
+
enable(t) {
|
|
1445
|
+
const { store: e } = this, n = Zt(e);
|
|
1446
|
+
n.enableAll(), this.#t.push(() => n.disableAll()), this.#s(), this.#n(), t?.getTrigger && this.#r(t.getTrigger);
|
|
1447
|
+
}
|
|
1448
|
+
disable() {
|
|
1449
|
+
for (const t of this.#t)
|
|
1450
|
+
t();
|
|
1451
|
+
this.#t = [], this.#e = !1;
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Synchronizes the parser with current options and handles parsing.
|
|
1455
|
+
* Must be called by the framework layer when value or options change,
|
|
1456
|
+
* since these are props set synchronously during render.
|
|
1457
|
+
*/
|
|
1458
|
+
syncParser(t, e) {
|
|
1459
|
+
const { store: n } = this, r = e?.map((i) => i.markup);
|
|
1460
|
+
if (r && r.some(Boolean) ? n.state.parser.set(new A(r)) : n.state.parser.set(void 0), this.#e) {
|
|
1461
|
+
n.state.recovery.get() || n.events.parse();
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
const o = t ?? n.state.defaultValue.get() ?? "";
|
|
1465
|
+
n.state.tokens.set(P(n, o)), this.#e = !0;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Recovers focus after tokens change.
|
|
1469
|
+
* Must be called by the framework layer after DOM updates,
|
|
1470
|
+
* since focus recovery requires the new DOM to be committed.
|
|
1471
|
+
*/
|
|
1472
|
+
recoverFocus() {
|
|
1473
|
+
this.store.state.Mark.get() && this.store.controllers.focus.recover();
|
|
1474
|
+
}
|
|
1475
|
+
#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
|
+
const { store: t } = this;
|
|
1483
|
+
this.#t.push(
|
|
1484
|
+
t.events.parse.on(() => {
|
|
1485
|
+
if (t.state.recovery.get()) {
|
|
1486
|
+
const e = y(t.state.tokens.get());
|
|
1487
|
+
t.state.tokens.set(P(t, e)), t.state.previousValue.set(e);
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
t.state.tokens.set(t.nodes.focus.target ? It(t) : Mt(t));
|
|
1491
|
+
})
|
|
1492
|
+
);
|
|
1493
|
+
}
|
|
1494
|
+
#r(t) {
|
|
1495
|
+
const { store: e } = this;
|
|
1496
|
+
e.controllers.overlay.enableTrigger(t, (n) => e.state.overlayMatch.set(n)), this.#t.push(() => e.controllers.overlay.disable()), this.#t.push(
|
|
1497
|
+
e.state.overlayMatch.on((n) => {
|
|
1498
|
+
n ? (e.nodes.input.target = e.nodes.focus.target, e.controllers.overlay.enableClose()) : e.controllers.overlay.disableClose();
|
|
1499
|
+
})
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1589
1502
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
return { match: e, style: n, select: r, close: s, ref: { current: t.refs.overlay } };
|
|
1613
|
-
}
|
|
1614
|
-
const ft = () => {
|
|
1615
|
-
const { match: t, select: e, style: n, ref: s } = ht(), [r, o] = A(NaN), i = t.option.overlay?.data || [], a = ue(
|
|
1616
|
-
() => i.filter((l) => l.toLowerCase().indexOf(t.value.toLowerCase()) > -1),
|
|
1617
|
-
[t.value, i]
|
|
1618
|
-
), c = a.length;
|
|
1619
|
-
return C(
|
|
1620
|
-
k.UP,
|
|
1621
|
-
(l) => {
|
|
1622
|
-
l.preventDefault(), o((h) => isNaN(h) ? 0 : (c + (h - 1) % c) % c);
|
|
1623
|
-
},
|
|
1624
|
-
[c]
|
|
1625
|
-
), C(
|
|
1626
|
-
k.DOWN,
|
|
1627
|
-
(l) => {
|
|
1628
|
-
l.preventDefault(), o((h) => isNaN(h) ? 0 : (h + 1) % c);
|
|
1629
|
-
},
|
|
1630
|
-
[c]
|
|
1631
|
-
), C(
|
|
1632
|
-
k.ENTER,
|
|
1633
|
-
(l) => {
|
|
1634
|
-
l.preventDefault();
|
|
1635
|
-
const h = a[r];
|
|
1636
|
-
e({ value: h, meta: r.toString() });
|
|
1637
|
-
},
|
|
1638
|
-
[a, r]
|
|
1639
|
-
), a.length ? /* @__PURE__ */ m("ul", { ref: s, className: V.Suggestions, style: n, children: a.map((l, h) => {
|
|
1640
|
-
const u = h === r ? V.suggestionActive : void 0;
|
|
1641
|
-
return /* @__PURE__ */ m(
|
|
1642
|
-
"li",
|
|
1503
|
+
class Qt {
|
|
1504
|
+
key = new $t();
|
|
1505
|
+
nodes = {
|
|
1506
|
+
focus: new M(void 0, this),
|
|
1507
|
+
input: new M(void 0, this)
|
|
1508
|
+
};
|
|
1509
|
+
state;
|
|
1510
|
+
events = _t();
|
|
1511
|
+
refs = {
|
|
1512
|
+
container: null,
|
|
1513
|
+
overlay: null
|
|
1514
|
+
};
|
|
1515
|
+
controllers = {
|
|
1516
|
+
overlay: new Ht(this),
|
|
1517
|
+
focus: new Ft(this),
|
|
1518
|
+
keydown: new jt(this),
|
|
1519
|
+
system: new Dt(this),
|
|
1520
|
+
textSelection: new Ut(this)
|
|
1521
|
+
};
|
|
1522
|
+
lifecycle = new Jt(this);
|
|
1523
|
+
constructor(t) {
|
|
1524
|
+
this.state = At(
|
|
1643
1525
|
{
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1526
|
+
tokens: [],
|
|
1527
|
+
parser: void 0,
|
|
1528
|
+
previousValue: void 0,
|
|
1529
|
+
recovery: void 0,
|
|
1530
|
+
selecting: void 0,
|
|
1531
|
+
overlayMatch: void 0,
|
|
1532
|
+
value: void 0,
|
|
1533
|
+
defaultValue: void 0,
|
|
1534
|
+
onChange: void 0,
|
|
1535
|
+
readOnly: !1,
|
|
1536
|
+
options: void 0,
|
|
1537
|
+
showOverlayOn: void 0,
|
|
1538
|
+
Mark: void 0,
|
|
1539
|
+
Overlay: void 0,
|
|
1540
|
+
className: void 0,
|
|
1541
|
+
style: void 0,
|
|
1542
|
+
slots: void 0,
|
|
1543
|
+
slotProps: void 0
|
|
1648
1544
|
},
|
|
1649
|
-
|
|
1545
|
+
t.createUseHook
|
|
1650
1546
|
);
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
for (const r of t) {
|
|
1666
|
-
if (r === e) return { depth: n, parent: s };
|
|
1667
|
-
if (r.type === "mark") {
|
|
1668
|
-
const o = F(r.children, e, n + 1, r);
|
|
1669
|
-
if (o) return o;
|
|
1670
|
-
}
|
|
1547
|
+
}
|
|
1548
|
+
createHandler() {
|
|
1549
|
+
const t = this;
|
|
1550
|
+
return {
|
|
1551
|
+
get container() {
|
|
1552
|
+
return t.refs.container;
|
|
1553
|
+
},
|
|
1554
|
+
get overlay() {
|
|
1555
|
+
return t.refs.overlay;
|
|
1556
|
+
},
|
|
1557
|
+
focus() {
|
|
1558
|
+
t.nodes.focus.head?.focus();
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1671
1561
|
}
|
|
1672
1562
|
}
|
|
1673
|
-
class
|
|
1563
|
+
class Kt {
|
|
1674
1564
|
ref;
|
|
1675
1565
|
#t;
|
|
1676
1566
|
#e;
|
|
1677
|
-
|
|
1678
|
-
constructor(
|
|
1679
|
-
this.ref =
|
|
1567
|
+
#n;
|
|
1568
|
+
constructor(t) {
|
|
1569
|
+
this.ref = t.ref, this.#t = t.store, this.#e = t.token;
|
|
1570
|
+
}
|
|
1571
|
+
get readOnly() {
|
|
1572
|
+
return this.#n;
|
|
1573
|
+
}
|
|
1574
|
+
set readOnly(t) {
|
|
1575
|
+
this.#n = t;
|
|
1680
1576
|
}
|
|
1681
|
-
// ─── Data Properties ─────────────────────────────────────────────────────────
|
|
1682
|
-
/** Displayed text of the mark */
|
|
1683
1577
|
get content() {
|
|
1684
1578
|
return this.#e.content;
|
|
1685
1579
|
}
|
|
1686
|
-
set content(
|
|
1687
|
-
this.#e.content =
|
|
1580
|
+
set content(t) {
|
|
1581
|
+
this.#e.content = t, this.#s();
|
|
1688
1582
|
}
|
|
1689
|
-
/** Data value associated with the mark */
|
|
1690
1583
|
get value() {
|
|
1691
1584
|
return this.#e.value;
|
|
1692
1585
|
}
|
|
1693
|
-
set value(
|
|
1694
|
-
this.#e.value =
|
|
1586
|
+
set value(t) {
|
|
1587
|
+
this.#e.value = t ?? "", this.#s();
|
|
1695
1588
|
}
|
|
1696
|
-
/** Optional metadata for the mark */
|
|
1697
1589
|
get meta() {
|
|
1698
1590
|
return this.#e.meta;
|
|
1699
1591
|
}
|
|
1700
|
-
set meta(
|
|
1701
|
-
this.#e.meta =
|
|
1592
|
+
set meta(t) {
|
|
1593
|
+
this.#e.meta = t, this.#s();
|
|
1702
1594
|
}
|
|
1703
|
-
// ─── Navigation Properties ───────────────────────────────────────────────────
|
|
1704
|
-
/** Nesting depth (0 for root-level marks) */
|
|
1705
1595
|
get depth() {
|
|
1706
|
-
return
|
|
1596
|
+
return V(this.#t.state.tokens.get(), this.#e).depth;
|
|
1707
1597
|
}
|
|
1708
|
-
/** Whether this mark has nested children */
|
|
1709
1598
|
get hasChildren() {
|
|
1710
1599
|
return this.#e.children.length > 0;
|
|
1711
1600
|
}
|
|
1712
|
-
/** Parent mark token (undefined for root-level marks) */
|
|
1713
1601
|
get parent() {
|
|
1714
|
-
return
|
|
1602
|
+
return V(this.#t.state.tokens.get(), this.#e)?.parent;
|
|
1715
1603
|
}
|
|
1716
|
-
/** Child tokens of this mark */
|
|
1717
1604
|
get tokens() {
|
|
1718
1605
|
return this.#e.children;
|
|
1719
1606
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
change = (e) => {
|
|
1723
|
-
this.#e.content = e.content, this.#e.value = e.value ?? "", e.meta !== void 0 && (this.#e.meta = e.meta), this.#n();
|
|
1607
|
+
change = (t) => {
|
|
1608
|
+
this.#e.content = t.content, this.#e.value = t.value ?? "", t.meta !== void 0 && (this.#e.meta = t.meta), this.#s();
|
|
1724
1609
|
};
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1610
|
+
remove = () => this.#t.events.delete({ token: this.#e });
|
|
1611
|
+
#s() {
|
|
1612
|
+
this.#t.events.change();
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
const Yt = {
|
|
1616
|
+
container: "div",
|
|
1617
|
+
span: "span"
|
|
1618
|
+
};
|
|
1619
|
+
function et(s, t) {
|
|
1620
|
+
return t?.[s] ? t[s] : Yt[s];
|
|
1621
|
+
}
|
|
1622
|
+
function nt(s, t) {
|
|
1623
|
+
const e = t?.[s];
|
|
1624
|
+
return e ? ht(e) : void 0;
|
|
1625
|
+
}
|
|
1626
|
+
const U = X(void 0);
|
|
1627
|
+
U.displayName = "StoreContext";
|
|
1628
|
+
function k() {
|
|
1629
|
+
const s = Z(U);
|
|
1630
|
+
return dt(s), s;
|
|
1631
|
+
}
|
|
1632
|
+
const te = (s) => {
|
|
1633
|
+
const t = X(void 0);
|
|
1634
|
+
return t.displayName = s, [() => {
|
|
1635
|
+
const n = Z(t);
|
|
1636
|
+
if (n === void 0)
|
|
1637
|
+
throw new Error(`Context "${s}" not found. Make sure to wrap component in its Provider.`);
|
|
1638
|
+
return n;
|
|
1639
|
+
}, t.Provider, t];
|
|
1640
|
+
}, [W, z] = te("NodeProvider");
|
|
1641
|
+
function st(s, t, e, n) {
|
|
1642
|
+
const r = k(), o = r.state.Mark.use(), i = r.state.Overlay.use(), a = s === "mark" ? o : i, l = s === "mark" ? t?.mark : t?.overlay;
|
|
1643
|
+
let c;
|
|
1644
|
+
l !== void 0 ? typeof l == "function" ? c = l(e) : c = l : c = e ?? {};
|
|
1645
|
+
const d = c.slot || a || n;
|
|
1646
|
+
if (!d)
|
|
1647
|
+
throw new Error(
|
|
1648
|
+
`No ${s} component found. Provide either option.${s}.slot, global ${s === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
|
|
1649
|
+
);
|
|
1650
|
+
return [d, c];
|
|
1651
|
+
}
|
|
1652
|
+
function ee() {
|
|
1653
|
+
const s = W(), t = k(), e = t.state.options.use(), n = t.key, r = e?.[s.descriptor.index], o = s.children.map((c) => /* @__PURE__ */ f(G, { mark: c, isNested: !0 }, n.get(c))), i = {
|
|
1654
|
+
value: s.value,
|
|
1655
|
+
meta: s.meta,
|
|
1656
|
+
nested: s.nested?.content,
|
|
1657
|
+
children: s.children.length > 0 ? o : void 0
|
|
1658
|
+
}, [a, l] = st("mark", r, i);
|
|
1659
|
+
return /* @__PURE__ */ f(a, { ...l });
|
|
1660
|
+
}
|
|
1661
|
+
const ne = () => {
|
|
1662
|
+
const s = W(), t = k(), e = J(null), n = t.state.readOnly.use(), r = t.state.slots.use(), o = t.state.slotProps.use(), i = C(() => et("span", r), [r]), a = C(() => nt("span", o), [o]);
|
|
1663
|
+
if (s.type !== "text")
|
|
1664
|
+
throw new Error("TextSpan component expects a TextToken");
|
|
1665
|
+
return ct(() => {
|
|
1666
|
+
e.current && e.current.textContent !== s.content && (e.current.textContent = s.content);
|
|
1667
|
+
}, [s.content]), /* @__PURE__ */ f(
|
|
1668
|
+
i,
|
|
1669
|
+
{
|
|
1670
|
+
...a,
|
|
1671
|
+
ref: e,
|
|
1672
|
+
contentEditable: !n,
|
|
1673
|
+
onPaste: se,
|
|
1674
|
+
suppressContentEditableWarning: !0
|
|
1675
|
+
}
|
|
1676
|
+
);
|
|
1677
|
+
};
|
|
1678
|
+
function se(s) {
|
|
1679
|
+
s.preventDefault();
|
|
1680
|
+
const t = s.clipboardData.getData("text");
|
|
1681
|
+
document.execCommand("insertText", !1, t);
|
|
1682
|
+
}
|
|
1683
|
+
const G = D(({ mark: s, isNested: t = !1 }) => s.type === "mark" ? /* @__PURE__ */ f(z, { value: s, children: /* @__PURE__ */ f(ee, {}) }) : t ? /* @__PURE__ */ f(it, { children: s.content }) : /* @__PURE__ */ f(z, { value: s, children: /* @__PURE__ */ f(ne, {}) }));
|
|
1684
|
+
G.displayName = "Token";
|
|
1685
|
+
const rt = D(() => {
|
|
1686
|
+
const s = k(), 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, l = C(() => et("container", e), [e]), c = C(() => nt("container", n), [n]);
|
|
1687
|
+
return /* @__PURE__ */ f(
|
|
1688
|
+
l,
|
|
1689
|
+
{
|
|
1690
|
+
ref: (d) => a.container = d,
|
|
1691
|
+
...c,
|
|
1692
|
+
className: r,
|
|
1693
|
+
style: o,
|
|
1694
|
+
children: t.map((d) => /* @__PURE__ */ f(G, { mark: d }, i.get(d)))
|
|
1695
|
+
}
|
|
1696
|
+
);
|
|
1697
|
+
});
|
|
1698
|
+
rt.displayName = "Container";
|
|
1699
|
+
function re() {
|
|
1700
|
+
const s = k(), t = s.state.overlayMatch.use(), e = m.getAbsolutePosition(), n = B(() => s.events.clearOverlay(), []), r = B(
|
|
1701
|
+
(i) => {
|
|
1702
|
+
const a = {
|
|
1703
|
+
type: "mark",
|
|
1704
|
+
value: i.value,
|
|
1705
|
+
meta: i.meta,
|
|
1706
|
+
content: "",
|
|
1707
|
+
position: { start: t.index, end: t.index + t.span.length },
|
|
1708
|
+
descriptor: {
|
|
1709
|
+
index: 0,
|
|
1710
|
+
markup: t.option.markup
|
|
1711
|
+
},
|
|
1712
|
+
children: [],
|
|
1713
|
+
nested: void 0
|
|
1714
|
+
};
|
|
1715
|
+
s.events.select({ mark: a, match: t }), s.events.clearOverlay();
|
|
1716
|
+
},
|
|
1717
|
+
[t]
|
|
1718
|
+
), o = C(
|
|
1719
|
+
() => ({
|
|
1720
|
+
get current() {
|
|
1721
|
+
return s.refs.overlay;
|
|
1722
|
+
},
|
|
1723
|
+
set current(i) {
|
|
1724
|
+
s.refs.overlay = i;
|
|
1725
|
+
}
|
|
1726
|
+
}),
|
|
1727
|
+
[]
|
|
1728
|
+
);
|
|
1729
|
+
return { match: t, style: e, select: r, close: n, ref: o };
|
|
1730
|
+
}
|
|
1731
|
+
const oe = "_Container_1lmfr_1", ie = "_Suggestions_1lmfr_10", ae = "_suggestionActive_1lmfr_38", R = {
|
|
1732
|
+
Container: oe,
|
|
1733
|
+
Suggestions: ie,
|
|
1734
|
+
suggestionActive: ae
|
|
1735
|
+
}, ce = () => {
|
|
1736
|
+
const s = k(), { match: t, select: e, style: n, ref: r } = re(), [o, i] = L(NaN), a = t.option.overlay?.data || [], l = C(
|
|
1737
|
+
() => a.filter((d) => d.toLowerCase().indexOf(t.value.toLowerCase()) > -1),
|
|
1738
|
+
[t.value, a]
|
|
1739
|
+
), c = l.length;
|
|
1740
|
+
return S(() => {
|
|
1741
|
+
const d = s.refs.container;
|
|
1742
|
+
if (!d) return;
|
|
1743
|
+
const u = (h) => {
|
|
1744
|
+
switch (h.key) {
|
|
1745
|
+
case v.UP:
|
|
1746
|
+
h.preventDefault(), i((g) => isNaN(g) ? 0 : (c + (g - 1) % c) % c);
|
|
1747
|
+
break;
|
|
1748
|
+
case v.DOWN:
|
|
1749
|
+
h.preventDefault(), i((g) => isNaN(g) ? 0 : (g + 1) % c);
|
|
1750
|
+
break;
|
|
1751
|
+
case v.ENTER:
|
|
1752
|
+
h.preventDefault(), i((g) => {
|
|
1753
|
+
if (isNaN(g)) return g;
|
|
1754
|
+
const w = l[g];
|
|
1755
|
+
return e({ value: w, meta: g.toString() }), g;
|
|
1756
|
+
});
|
|
1757
|
+
break;
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
return d.addEventListener("keydown", u), () => d.removeEventListener("keydown", u);
|
|
1761
|
+
}, [c, l]), l.length ? /* @__PURE__ */ f("ul", { ref: r, className: R.Suggestions, style: n, children: l.map((d, u) => {
|
|
1762
|
+
const h = u === o ? R.suggestionActive : void 0;
|
|
1763
|
+
return /* @__PURE__ */ f(
|
|
1764
|
+
"li",
|
|
1765
|
+
{
|
|
1766
|
+
ref: (g) => {
|
|
1767
|
+
h && g && g.scrollIntoView(!1);
|
|
1768
|
+
},
|
|
1769
|
+
className: h,
|
|
1770
|
+
onClick: (g) => e({ value: d, meta: u.toString() }),
|
|
1771
|
+
children: d
|
|
1772
|
+
},
|
|
1773
|
+
d
|
|
1774
|
+
);
|
|
1775
|
+
}) }) : null;
|
|
1776
|
+
}, ot = D(() => {
|
|
1777
|
+
const s = k(), t = s.state.overlayMatch.use(), e = C(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] = st("overlay", t?.option, void 0, ce);
|
|
1778
|
+
if (e) return /* @__PURE__ */ f(n, { ...r ?? {} }, e);
|
|
1779
|
+
});
|
|
1780
|
+
ot.displayName = "OverlayRenderer";
|
|
1781
|
+
function le(s, t) {
|
|
1782
|
+
lt(t, () => s.createHandler(), [s]), S(() => (s.lifecycle.enable({
|
|
1783
|
+
getTrigger: (a) => a.overlay?.trigger
|
|
1784
|
+
}), () => s.lifecycle.disable()), []);
|
|
1785
|
+
const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0;
|
|
1786
|
+
S(() => {
|
|
1787
|
+
s.lifecycle.syncParser(e, o);
|
|
1788
|
+
}, [e, o]);
|
|
1789
|
+
const i = s.state.tokens.use();
|
|
1790
|
+
S(() => {
|
|
1791
|
+
s.lifecycle.recoverFocus();
|
|
1792
|
+
}, [i]);
|
|
1793
|
+
}
|
|
1794
|
+
const de = (s) => () => {
|
|
1795
|
+
const [t, e] = L(() => s.get());
|
|
1796
|
+
return S(() => s.on(e), [s]), t;
|
|
1797
|
+
}, he = [
|
|
1798
|
+
{
|
|
1799
|
+
markup: pt,
|
|
1800
|
+
overlay: {
|
|
1801
|
+
trigger: ft,
|
|
1802
|
+
data: []
|
|
1803
|
+
}
|
|
1730
1804
|
}
|
|
1805
|
+
];
|
|
1806
|
+
function me(s) {
|
|
1807
|
+
const {
|
|
1808
|
+
ref: t,
|
|
1809
|
+
value: e,
|
|
1810
|
+
defaultValue: n,
|
|
1811
|
+
onChange: r,
|
|
1812
|
+
readOnly: o = !1,
|
|
1813
|
+
Mark: i,
|
|
1814
|
+
Overlay: a,
|
|
1815
|
+
slots: l,
|
|
1816
|
+
slotProps: c,
|
|
1817
|
+
options: d = he,
|
|
1818
|
+
showOverlayOn: u = "change",
|
|
1819
|
+
className: h,
|
|
1820
|
+
style: g
|
|
1821
|
+
} = s, w = ut(R.Container, h, c?.container?.className), E = gt(g, c?.container?.style), [T] = L(() => new Qt({ createUseHook: de }));
|
|
1822
|
+
return T.state.set({
|
|
1823
|
+
value: e,
|
|
1824
|
+
defaultValue: n,
|
|
1825
|
+
onChange: r,
|
|
1826
|
+
readOnly: o,
|
|
1827
|
+
options: d,
|
|
1828
|
+
showOverlayOn: u,
|
|
1829
|
+
Mark: i,
|
|
1830
|
+
Overlay: a,
|
|
1831
|
+
className: w,
|
|
1832
|
+
style: E,
|
|
1833
|
+
slots: l,
|
|
1834
|
+
slotProps: c
|
|
1835
|
+
}), le(T, t), /* @__PURE__ */ at(U.Provider, { value: T, children: [
|
|
1836
|
+
/* @__PURE__ */ f(rt, {}),
|
|
1837
|
+
/* @__PURE__ */ f(ot, {})
|
|
1838
|
+
] });
|
|
1731
1839
|
}
|
|
1732
|
-
const
|
|
1733
|
-
const
|
|
1734
|
-
if (
|
|
1840
|
+
const xe = (s = {}) => {
|
|
1841
|
+
const t = k(), e = W(), n = J(null);
|
|
1842
|
+
if (e.type !== "mark")
|
|
1735
1843
|
throw new Error("useMark can only be used with mark tokens");
|
|
1736
|
-
const [r] =
|
|
1737
|
-
|
|
1738
|
-
const o =
|
|
1739
|
-
return
|
|
1844
|
+
const [r] = L(() => new Kt({ ref: n, store: t, token: e }));
|
|
1845
|
+
ue(n, s, e);
|
|
1846
|
+
const o = t.state.readOnly.use();
|
|
1847
|
+
return S(() => {
|
|
1740
1848
|
r.readOnly = o;
|
|
1741
1849
|
}, [o]), r;
|
|
1742
1850
|
};
|
|
1743
|
-
function
|
|
1744
|
-
|
|
1745
|
-
|
|
1851
|
+
function ue(s, t, e) {
|
|
1852
|
+
S(() => {
|
|
1853
|
+
s.current && !t.controlled && (s.current.textContent = e.content);
|
|
1746
1854
|
}, []);
|
|
1747
1855
|
}
|
|
1748
1856
|
export {
|
|
1749
|
-
|
|
1857
|
+
Kt as MarkHandler,
|
|
1858
|
+
me as MarkedInput,
|
|
1750
1859
|
$ as annotate,
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
ht as useOverlay
|
|
1860
|
+
ve as denote,
|
|
1861
|
+
xe as useMark,
|
|
1862
|
+
re as useOverlay
|
|
1755
1863
|
};
|