@markput/react 0.7.0 → 0.8.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/index.css +1 -1
- package/index.d.ts +3 -5
- package/index.js +1067 -1061
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,64 +1,103 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
//#region ../../common/core/src/shared/utils/
|
|
5
|
-
function
|
|
6
|
-
|
|
2
|
+
import { createContext as e, memo as t, useCallback as n, useContext as r, useEffect as i, useImperativeHandle as a, useLayoutEffect as o, useMemo as s, useRef as c, useState as l, useSyncExternalStore as u } from "react";
|
|
3
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
4
|
+
//#region ../../common/core/src/shared/utils/shallow.ts
|
|
5
|
+
function p(e, t) {
|
|
6
|
+
if (Object.is(e, t)) return !0;
|
|
7
|
+
if (typeof e != "object" || !e || typeof t != "object" || !t) return !1;
|
|
8
|
+
let n = Object.keys(e);
|
|
9
|
+
if (n.length !== Object.keys(t).length) return !1;
|
|
10
|
+
for (let r of n) if (!Object.prototype.hasOwnProperty.call(t, r) || !Object.is(Reflect.get(e, r), Reflect.get(t, r))) return !1;
|
|
11
|
+
return !0;
|
|
7
12
|
}
|
|
8
13
|
//#endregion
|
|
9
14
|
//#region ../../common/core/src/shared/utils/cx.ts
|
|
10
|
-
function
|
|
15
|
+
function m(...e) {
|
|
11
16
|
return e.filter(Boolean).join(" ") || void 0;
|
|
12
17
|
}
|
|
13
18
|
//#endregion
|
|
14
19
|
//#region ../../common/core/src/shared/utils/merge.ts
|
|
15
|
-
function
|
|
20
|
+
function h(...e) {
|
|
16
21
|
let t = Object.assign({}, ...e.filter(Boolean));
|
|
17
22
|
return Object.keys(t).length > 0 ? t : void 0;
|
|
18
23
|
}
|
|
19
24
|
//#endregion
|
|
20
25
|
//#region ../../common/core/src/shared/utils/resolveOptionSlot.ts
|
|
21
|
-
function
|
|
26
|
+
function g(e, t) {
|
|
22
27
|
return e === void 0 ? t : typeof e == "function" ? e(t) : e;
|
|
23
28
|
}
|
|
24
29
|
//#endregion
|
|
30
|
+
//#region ../../common/core/src/shared/utils/dataAttributes.ts
|
|
31
|
+
function ee(e) {
|
|
32
|
+
return e ? Object.fromEntries(Object.entries(e).map(([e, t]) => 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()}`, t] : [e, t])) : {};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
25
35
|
//#region ../../common/core/src/shared/utils/resolveSlot.ts
|
|
26
|
-
var
|
|
36
|
+
var te = {
|
|
27
37
|
container: "div",
|
|
38
|
+
block: "div",
|
|
28
39
|
span: "span"
|
|
29
40
|
};
|
|
30
|
-
function
|
|
31
|
-
return t?.[e] ??
|
|
41
|
+
function _(e, t) {
|
|
42
|
+
return t?.[e] ?? te[e];
|
|
32
43
|
}
|
|
33
|
-
function
|
|
44
|
+
function v(e, t) {
|
|
34
45
|
let n = t?.[e];
|
|
35
|
-
return n ?
|
|
46
|
+
return n ? ee(n) : void 0;
|
|
47
|
+
}
|
|
48
|
+
function ne(e, t, n) {
|
|
49
|
+
let r = t?.Overlay ?? e ?? n;
|
|
50
|
+
if (!r) throw Error("No overlay component found. Provide either option.Overlay, global Overlay, or a defaultComponent.");
|
|
51
|
+
return [r, g(t?.overlay, {})];
|
|
52
|
+
}
|
|
53
|
+
function re(e, t, n, r, i) {
|
|
54
|
+
if (e.type === "text") return [r ?? i, { value: e.content }];
|
|
55
|
+
let a = t?.[e.descriptor.index], o = {
|
|
56
|
+
value: e.value,
|
|
57
|
+
meta: e.meta
|
|
58
|
+
}, s = g(a?.mark, o), c = a?.Mark ?? n;
|
|
59
|
+
if (!c) throw Error("No mark component found. Provide either option.Mark or global Mark.");
|
|
60
|
+
return [c, s];
|
|
36
61
|
}
|
|
37
62
|
//#endregion
|
|
38
63
|
//#region ../../common/core/src/shared/constants.ts
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
64
|
+
var y = {
|
|
65
|
+
UP: "ArrowUp",
|
|
66
|
+
DOWN: "ArrowDown",
|
|
67
|
+
LEFT: "ArrowLeft",
|
|
68
|
+
RIGHT: "ArrowRight",
|
|
69
|
+
END: "End",
|
|
70
|
+
HOME: "Home",
|
|
71
|
+
PAGE_DOWN: "PageDown",
|
|
72
|
+
PAGE_UP: "PageUp",
|
|
73
|
+
ENTER: "Enter",
|
|
74
|
+
TAB: "Tab",
|
|
75
|
+
SPACE: " ",
|
|
76
|
+
BACKSPACE: "Backspace",
|
|
77
|
+
DELETE: "Delete",
|
|
78
|
+
COMMA: ",",
|
|
79
|
+
ESC: "Escape"
|
|
80
|
+
}, ie = [{
|
|
42
81
|
markup: "@[__value__](__meta__)",
|
|
43
82
|
overlay: {
|
|
44
83
|
trigger: "@",
|
|
45
84
|
data: []
|
|
46
85
|
}
|
|
47
|
-
}],
|
|
86
|
+
}], b = {
|
|
48
87
|
Value: "__value__",
|
|
49
88
|
Meta: "__meta__",
|
|
50
89
|
Slot: "__slot__"
|
|
51
|
-
},
|
|
90
|
+
}, x = {
|
|
52
91
|
Value: "value",
|
|
53
92
|
Meta: "meta",
|
|
54
93
|
Slot: "slot"
|
|
55
94
|
};
|
|
56
95
|
//#endregion
|
|
57
96
|
//#region ../../common/core/src/features/parsing/parser/core/MarkupDescriptor.ts
|
|
58
|
-
function
|
|
59
|
-
let { segments: n, gapTypes: r, counts: i, valueGapIndices: a } =
|
|
60
|
-
|
|
61
|
-
let o = i.value === 2, { segments: s, gapTypes: c } = o ?
|
|
97
|
+
function ae(e, t) {
|
|
98
|
+
let { segments: n, gapTypes: r, counts: i, valueGapIndices: a } = se(e);
|
|
99
|
+
ce(i, e);
|
|
100
|
+
let o = i.value === 2, { segments: s, gapTypes: c } = o ? le(n, r, a) : {
|
|
62
101
|
segments: n,
|
|
63
102
|
gapTypes: r
|
|
64
103
|
};
|
|
@@ -72,23 +111,23 @@ function T(e, t) {
|
|
|
72
111
|
segmentGlobalIndices: Array.from({ length: s.length })
|
|
73
112
|
};
|
|
74
113
|
}
|
|
75
|
-
var
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
114
|
+
var oe = {
|
|
115
|
+
[x.Value]: b.Value,
|
|
116
|
+
[x.Meta]: b.Meta,
|
|
117
|
+
[x.Slot]: b.Slot
|
|
79
118
|
};
|
|
80
|
-
function
|
|
119
|
+
function se(e) {
|
|
81
120
|
let t = [], n = [], r = [], i = {
|
|
82
121
|
value: 0,
|
|
83
122
|
meta: 0,
|
|
84
123
|
slot: 0
|
|
85
124
|
}, a = [], o = [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
125
|
+
x.Value,
|
|
126
|
+
x.Meta,
|
|
127
|
+
x.Slot
|
|
89
128
|
];
|
|
90
129
|
for (let t of o) {
|
|
91
|
-
let n =
|
|
130
|
+
let n = oe[t], r = e.indexOf(n);
|
|
92
131
|
for (; r !== -1;) a.push({
|
|
93
132
|
type: t,
|
|
94
133
|
position: r
|
|
@@ -98,7 +137,7 @@ function D(e) {
|
|
|
98
137
|
let s = 0;
|
|
99
138
|
for (let o of a) {
|
|
100
139
|
let a = e.substring(s, o.position);
|
|
101
|
-
a.length > 0 && t.push(a), n.push(o.type), i[o.type]++, o.type ===
|
|
140
|
+
a.length > 0 && t.push(a), n.push(o.type), i[o.type]++, o.type === x.Value && r.push(n.length - 1), s = o.position + oe[o.type].length;
|
|
102
141
|
}
|
|
103
142
|
let c = e.substring(s);
|
|
104
143
|
return c.length > 0 && t.push(c), {
|
|
@@ -108,42 +147,42 @@ function D(e) {
|
|
|
108
147
|
valueGapIndices: r
|
|
109
148
|
};
|
|
110
149
|
}
|
|
111
|
-
function
|
|
150
|
+
function ce(e, t) {
|
|
112
151
|
let n = [
|
|
113
152
|
{
|
|
114
153
|
count: e.value,
|
|
115
154
|
max: 2,
|
|
116
|
-
name:
|
|
155
|
+
name: b.Value
|
|
117
156
|
},
|
|
118
157
|
{
|
|
119
158
|
count: e.meta,
|
|
120
159
|
max: 1,
|
|
121
|
-
name:
|
|
160
|
+
name: b.Meta
|
|
122
161
|
},
|
|
123
162
|
{
|
|
124
163
|
count: e.slot,
|
|
125
164
|
max: 1,
|
|
126
|
-
name:
|
|
165
|
+
name: b.Slot
|
|
127
166
|
}
|
|
128
167
|
];
|
|
129
168
|
for (let { count: e, max: r, name: i } of n) if (e > r) throw Error(`Invalid markup: "${t}". Max ${r} "${i}" placeholders, got ${e}`);
|
|
130
|
-
if (e.value === 0 && e.slot === 0) throw Error(`Invalid markup: "${t}". Need at least one "${
|
|
169
|
+
if (e.value === 0 && e.slot === 0) throw Error(`Invalid markup: "${t}". Need at least one "${b.Value}" or "${b.Slot}"`);
|
|
131
170
|
}
|
|
132
|
-
function
|
|
171
|
+
function le(e, t, n) {
|
|
133
172
|
if (n.length !== 2) return {
|
|
134
173
|
segments: e,
|
|
135
174
|
gapTypes: t
|
|
136
175
|
};
|
|
137
176
|
let [r, i] = n, a = [], o = e[r], s = e[r + 1];
|
|
138
|
-
o && s && a.push(
|
|
177
|
+
o && s && a.push(ue(o, s, e[r + 2]));
|
|
139
178
|
for (let t = r + 2; t < i; t++) a.push(e[t]);
|
|
140
179
|
let c = e[i], l = e[i + 1];
|
|
141
|
-
return c && l && a.push(
|
|
180
|
+
return c && l && a.push(ue(c, l, e[i + 2])), {
|
|
142
181
|
segments: a,
|
|
143
|
-
gapTypes: t.filter((e) => e !==
|
|
182
|
+
gapTypes: t.filter((e) => e !== x.Value)
|
|
144
183
|
};
|
|
145
184
|
}
|
|
146
|
-
function
|
|
185
|
+
function ue(e, t, n) {
|
|
147
186
|
if (!n) return [
|
|
148
187
|
e,
|
|
149
188
|
t,
|
|
@@ -158,11 +197,11 @@ function k(e, t, n) {
|
|
|
158
197
|
}
|
|
159
198
|
//#endregion
|
|
160
199
|
//#region ../../common/core/src/features/parsing/parser/core/MarkupRegistry.ts
|
|
161
|
-
function
|
|
200
|
+
function de(e, t) {
|
|
162
201
|
let n = e.get(t);
|
|
163
202
|
return n || (n = [], e.set(t, n)), n;
|
|
164
203
|
}
|
|
165
|
-
var
|
|
204
|
+
var fe = class {
|
|
166
205
|
markups;
|
|
167
206
|
descriptors;
|
|
168
207
|
segments = [];
|
|
@@ -172,7 +211,7 @@ var j = class {
|
|
|
172
211
|
let t = /* @__PURE__ */ new Map();
|
|
173
212
|
this.descriptors = e.map((e, n) => {
|
|
174
213
|
if (e === void 0) return null;
|
|
175
|
-
let r =
|
|
214
|
+
let r = ae(e, n);
|
|
176
215
|
return r.segments.forEach((e, n) => {
|
|
177
216
|
this.processSegment(r, e, n, t);
|
|
178
217
|
}), this.addToFirstSegmentIndexMap(r), r;
|
|
@@ -180,23 +219,22 @@ var j = class {
|
|
|
180
219
|
}
|
|
181
220
|
addToFirstSegmentIndexMap(e) {
|
|
182
221
|
let t = e.segmentGlobalIndices[0];
|
|
183
|
-
|
|
222
|
+
de(this.firstSegmentIndexMap, t).push(e);
|
|
184
223
|
}
|
|
185
224
|
processSegment(e, t, n, r) {
|
|
186
225
|
let i = this.getSegmentKey(t);
|
|
187
226
|
if (!i) return;
|
|
188
|
-
this.registerSegment(t, i, r);
|
|
189
|
-
let a = r.get(i);
|
|
227
|
+
let a = this.registerSegment(t, i, r);
|
|
190
228
|
if (e.segmentGlobalIndices[n] = a, typeof t != "string") {
|
|
191
229
|
let [e, n] = t;
|
|
192
230
|
e && this.registerSegment(e, e, r), n && this.registerSegment(n, n, r);
|
|
193
231
|
}
|
|
194
232
|
}
|
|
195
233
|
registerSegment(e, t, n) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
234
|
+
let r = n.get(t);
|
|
235
|
+
if (r !== void 0) return r;
|
|
236
|
+
let i = this.segments.length;
|
|
237
|
+
return this.segments.push(e), n.set(t, i), i;
|
|
200
238
|
}
|
|
201
239
|
getSegmentKey(e) {
|
|
202
240
|
if (typeof e == "string") return e;
|
|
@@ -206,7 +244,7 @@ var j = class {
|
|
|
206
244
|
};
|
|
207
245
|
//#endregion
|
|
208
246
|
//#region ../../common/core/src/features/parsing/parser/utils/getSegmentIndex.ts
|
|
209
|
-
function
|
|
247
|
+
function pe(e, t) {
|
|
210
248
|
if (!t) return e;
|
|
211
249
|
let n = 5381;
|
|
212
250
|
for (let e = 0; e < t.length; e++) n = n * 33 ^ t.charCodeAt(e);
|
|
@@ -214,17 +252,25 @@ function M(e, t) {
|
|
|
214
252
|
}
|
|
215
253
|
//#endregion
|
|
216
254
|
//#region ../../common/core/src/features/parsing/parser/core/Match.ts
|
|
217
|
-
var
|
|
255
|
+
var me = class {
|
|
218
256
|
gaps = {};
|
|
219
257
|
captured;
|
|
220
258
|
expectedSegmentIndex;
|
|
221
259
|
start;
|
|
222
260
|
end;
|
|
223
261
|
constructor(e, t) {
|
|
224
|
-
if (this.descriptor = e, this.expectedSegmentIndex = 1, this.start = t.start, this.end = t.end, e.segments.length === 1
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
262
|
+
if (this.descriptor = e, this.expectedSegmentIndex = 1, this.start = t.start, this.end = t.end, e.segments.length === 1) {
|
|
263
|
+
this.expectedSegmentIndex = NaN;
|
|
264
|
+
let t = e.gapTypes[0] ?? "value";
|
|
265
|
+
t === "slot" ? this.gaps.slot = {
|
|
266
|
+
start: this.start,
|
|
267
|
+
end: this.start
|
|
268
|
+
} : this.gaps[t] = {
|
|
269
|
+
start: this.start,
|
|
270
|
+
end: this.end
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
if (e.hasTwoValues && t.captured) {
|
|
228
274
|
this.captured = t.captured;
|
|
229
275
|
let e = t.start + t.value.indexOf(t.captured), n = e + t.captured.length;
|
|
230
276
|
this.gaps.value = {
|
|
@@ -247,7 +293,7 @@ var te = class {
|
|
|
247
293
|
let e = this.descriptor.segmentGlobalIndices[this.expectedSegmentIndex], t = this.descriptor.segments[this.expectedSegmentIndex];
|
|
248
294
|
if (typeof t == "object" && this.descriptor.hasTwoValues && this.captured && this.isAwaitingLastSegment) {
|
|
249
295
|
let [n, r] = t;
|
|
250
|
-
return
|
|
296
|
+
return pe(e, n + this.captured + r);
|
|
251
297
|
}
|
|
252
298
|
return e;
|
|
253
299
|
}
|
|
@@ -268,11 +314,11 @@ var te = class {
|
|
|
268
314
|
};
|
|
269
315
|
//#endregion
|
|
270
316
|
//#region ../../common/core/src/features/parsing/parser/core/PatternMatcher.ts
|
|
271
|
-
function
|
|
317
|
+
function he(e, t) {
|
|
272
318
|
let n = e.get(t);
|
|
273
319
|
return n || (n = [], e.set(t, n)), n;
|
|
274
320
|
}
|
|
275
|
-
var
|
|
321
|
+
var ge = class {
|
|
276
322
|
pendingStates = /* @__PURE__ */ new Map();
|
|
277
323
|
completingStates = /* @__PURE__ */ new Map();
|
|
278
324
|
completedStates = [];
|
|
@@ -282,7 +328,7 @@ var re = class {
|
|
|
282
328
|
process(e) {
|
|
283
329
|
this.pendingStates.clear(), this.completingStates.clear(), this.completedStates.length = 0;
|
|
284
330
|
for (let t of e) this.processWaitingStates(t), this.tryStartNewStates(t);
|
|
285
|
-
return this.completedStates.map((e) => e.match);
|
|
331
|
+
return this.resolveSlotLeadingMatches(), this.completedStates.map((e) => e.match);
|
|
286
332
|
}
|
|
287
333
|
processWaitingStates(e) {
|
|
288
334
|
let t = this.dequeueWaitingMatch(e);
|
|
@@ -293,7 +339,7 @@ var re = class {
|
|
|
293
339
|
}
|
|
294
340
|
tryStartNewStates(e) {
|
|
295
341
|
this.registry.firstSegmentIndexMap.get(e.index)?.forEach((t) => {
|
|
296
|
-
let n = new
|
|
342
|
+
let n = new me(t, e);
|
|
297
343
|
if (!n.isInvalid) {
|
|
298
344
|
if (n.isCompleted) return this.addToCompleted(n);
|
|
299
345
|
this.addToWaiting(n);
|
|
@@ -301,14 +347,37 @@ var re = class {
|
|
|
301
347
|
});
|
|
302
348
|
}
|
|
303
349
|
dequeueWaitingMatch(e) {
|
|
304
|
-
let t = e.captured ?
|
|
350
|
+
let t = e.captured ? pe(e.index, e.value) : e.index, n = this.completingStates.get(t);
|
|
305
351
|
if (n?.length) return n.pop();
|
|
306
352
|
let r = this.pendingStates.get(t);
|
|
307
353
|
if (r?.length) return r.pop();
|
|
308
354
|
}
|
|
309
355
|
addToWaiting(e) {
|
|
310
356
|
let t = e.nextSegment;
|
|
311
|
-
|
|
357
|
+
t !== void 0 && he(e.isAwaitingLastSegment ? this.completingStates : this.pendingStates, t).push(e);
|
|
358
|
+
}
|
|
359
|
+
resolveSlotLeadingMatches() {
|
|
360
|
+
let e = !1;
|
|
361
|
+
for (let t of this.completedStates) if (this.isSlotLeading(t.match)) {
|
|
362
|
+
e = !0;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
if (!e) return;
|
|
366
|
+
let t = 0;
|
|
367
|
+
for (let e of this.completedStates) {
|
|
368
|
+
let { match: n } = e;
|
|
369
|
+
if (this.isSlotLeading(n)) {
|
|
370
|
+
let r = n.start;
|
|
371
|
+
n.start = t, e.position = t, n.gaps.slot = {
|
|
372
|
+
start: t,
|
|
373
|
+
end: r
|
|
374
|
+
}, t = n.end;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
this.completedStates.sort((e, t) => e.position - t.position);
|
|
378
|
+
}
|
|
379
|
+
isSlotLeading(e) {
|
|
380
|
+
return e.descriptor.segments.length === 1 && e.descriptor.hasSlot;
|
|
312
381
|
}
|
|
313
382
|
addToCompleted(e) {
|
|
314
383
|
let t = e.start, n = 0, r = this.completedStates.length;
|
|
@@ -321,14 +390,14 @@ var re = class {
|
|
|
321
390
|
match: e
|
|
322
391
|
});
|
|
323
392
|
}
|
|
324
|
-
},
|
|
393
|
+
}, S = (e) => e.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
|
|
325
394
|
//#endregion
|
|
326
395
|
//#region ../../common/core/src/features/parsing/parser/core/SegmentMatcher.ts
|
|
327
|
-
function
|
|
328
|
-
let r =
|
|
329
|
-
return `${r}([^${
|
|
396
|
+
function _e(e, t, n) {
|
|
397
|
+
let r = S(e), i = S(t);
|
|
398
|
+
return `${r}([^${S(t + n)}]+?)${i}`;
|
|
330
399
|
}
|
|
331
|
-
var
|
|
400
|
+
var ve = class {
|
|
332
401
|
static;
|
|
333
402
|
dynamic;
|
|
334
403
|
constructor(e) {
|
|
@@ -342,7 +411,7 @@ var F = class {
|
|
|
342
411
|
index: i
|
|
343
412
|
});
|
|
344
413
|
}), t.length > 0) {
|
|
345
|
-
let e = [...t].toSorted((e, t) => t.length - e.length).map(
|
|
414
|
+
let e = [...t].toSorted((e, t) => t.length - e.length).map(S);
|
|
346
415
|
this.static = {
|
|
347
416
|
regex: RegExp(`(?:${e.join("|")})`, "gu"),
|
|
348
417
|
toIndex: r
|
|
@@ -351,9 +420,10 @@ var F = class {
|
|
|
351
420
|
if (n.length > 0) {
|
|
352
421
|
let e = /* @__PURE__ */ new Set(), t = [];
|
|
353
422
|
n.forEach(({ segment: n, index: r }) => {
|
|
423
|
+
if (typeof n == "string") return;
|
|
354
424
|
let [i, a, o] = n;
|
|
355
425
|
e.add(r);
|
|
356
|
-
let s =
|
|
426
|
+
let s = _e(i, a, o).replace("(", `(?<content${r}>`);
|
|
357
427
|
t.push({
|
|
358
428
|
index: r,
|
|
359
429
|
pattern: s,
|
|
@@ -406,17 +476,23 @@ var F = class {
|
|
|
406
476
|
for (let e of t) n.some((t) => e.start < t.end && e.end > t.start) || r.push(e);
|
|
407
477
|
return r.sort((e, t) => e.start - t.start), r;
|
|
408
478
|
}
|
|
409
|
-
},
|
|
479
|
+
}, ye = (e, t = 0, n = e.length) => ({
|
|
410
480
|
type: "text",
|
|
411
481
|
content: e.substring(t, n),
|
|
412
482
|
position: {
|
|
413
483
|
start: t,
|
|
414
484
|
end: n
|
|
415
485
|
}
|
|
416
|
-
}),
|
|
486
|
+
}), be = class {
|
|
417
487
|
input;
|
|
488
|
+
options;
|
|
489
|
+
constructor(e) {
|
|
490
|
+
this.options = e ?? {};
|
|
491
|
+
}
|
|
418
492
|
build(e, t) {
|
|
419
|
-
|
|
493
|
+
if (this.input = t, e.length === 0) return this.filterTokens([this.createTextToken(0, t.length)]);
|
|
494
|
+
let n = this.buildSinglePass(e);
|
|
495
|
+
return this.filterTokens(n);
|
|
420
496
|
}
|
|
421
497
|
buildSinglePass(e) {
|
|
422
498
|
let t = [], n = [], r = null, i = 0;
|
|
@@ -446,7 +522,9 @@ var F = class {
|
|
|
446
522
|
} else e ? e.token.children.push(o) : t.push(o);
|
|
447
523
|
}
|
|
448
524
|
for (; n.length > 0;) {
|
|
449
|
-
let e = n.
|
|
525
|
+
let e = n[n.length - 1];
|
|
526
|
+
n.pop();
|
|
527
|
+
let r = this.getContentBounds(e.match);
|
|
450
528
|
this.finalizeParent(e, r.end), n.length > 0 ? n[n.length - 1].token.children.push(e.token) : t.push(e.token);
|
|
451
529
|
}
|
|
452
530
|
return t.push(this.createTextToken(i, this.input.length)), t;
|
|
@@ -455,13 +533,13 @@ var F = class {
|
|
|
455
533
|
e.token.children.push(this.createTextToken(e.textPos, t));
|
|
456
534
|
}
|
|
457
535
|
createMarkToken(e) {
|
|
458
|
-
let t = this.extractSubstring(e.gaps.value?.start, e.gaps.value?.end), n = this.extractSubstring(e.gaps.slot?.start, e.gaps.slot?.end), r = this.extractSubstring(e.gaps.meta?.start, e.gaps.meta?.end), i = n || void 0, a = e.gaps.meta === void 0 ? void 0 : r
|
|
536
|
+
let t = this.extractSubstring(e.gaps.value?.start, e.gaps.value?.end), n = this.extractSubstring(e.gaps.slot?.start, e.gaps.slot?.end), r = this.extractSubstring(e.gaps.meta?.start, e.gaps.meta?.end), i = n || void 0, a = e.gaps.meta === void 0 ? void 0 : r;
|
|
459
537
|
return {
|
|
460
538
|
type: "mark",
|
|
461
539
|
content: this.input.substring(e.start, e.end),
|
|
462
540
|
children: [],
|
|
463
541
|
descriptor: e.descriptor,
|
|
464
|
-
value:
|
|
542
|
+
value: t,
|
|
465
543
|
meta: a,
|
|
466
544
|
position: {
|
|
467
545
|
start: e.start,
|
|
@@ -483,7 +561,7 @@ var F = class {
|
|
|
483
561
|
return e !== void 0 && t !== void 0 ? this.input.substring(e, t) : "";
|
|
484
562
|
}
|
|
485
563
|
createTextToken(e, t) {
|
|
486
|
-
return
|
|
564
|
+
return ye(this.input, e, t);
|
|
487
565
|
}
|
|
488
566
|
createSlotSourceInfo(e, t) {
|
|
489
567
|
if (!(!t || e.gaps.slot === void 0)) return {
|
|
@@ -492,14 +570,18 @@ var F = class {
|
|
|
492
570
|
end: e.gaps.slot.end
|
|
493
571
|
};
|
|
494
572
|
}
|
|
573
|
+
filterTokens(e) {
|
|
574
|
+
let { marksOnly: t, skipEmptyText: n } = this.options;
|
|
575
|
+
return !t && !n ? e : e.filter((e) => e.type === "text" ? !(t || n && e.position.start === e.position.end) : !0);
|
|
576
|
+
}
|
|
495
577
|
};
|
|
496
578
|
//#endregion
|
|
497
579
|
//#region ../../common/core/src/features/parsing/parser/utils/processTokens.ts
|
|
498
|
-
function
|
|
580
|
+
function C(e, t) {
|
|
499
581
|
let n = "";
|
|
500
582
|
for (let r of e) if (r.type === "text") n += r.content;
|
|
501
583
|
else if (r.children.length > 0) {
|
|
502
|
-
let e =
|
|
584
|
+
let e = C(r.children, t), i = {
|
|
503
585
|
...r,
|
|
504
586
|
value: e
|
|
505
587
|
};
|
|
@@ -509,21 +591,21 @@ function L(e, t) {
|
|
|
509
591
|
}
|
|
510
592
|
//#endregion
|
|
511
593
|
//#region ../../common/core/src/features/parsing/parser/utils/annotate.ts
|
|
512
|
-
function
|
|
594
|
+
function w(e, t) {
|
|
513
595
|
let n = e;
|
|
514
|
-
return t.value !== void 0 && (n = n.replaceAll(
|
|
596
|
+
return t.value !== void 0 && (n = n.replaceAll(b.Value, t.value)), t.meta !== void 0 && (n = n.replaceAll(b.Meta, t.meta)), t.slot !== void 0 && (n = n.replaceAll(b.Slot, t.slot)), n;
|
|
515
597
|
}
|
|
516
598
|
//#endregion
|
|
517
599
|
//#region ../../common/core/src/features/parsing/parser/utils/toString.ts
|
|
518
|
-
function
|
|
600
|
+
function T(e) {
|
|
519
601
|
let t = "";
|
|
520
602
|
for (let n of e) {
|
|
521
603
|
if (n.type === "text") {
|
|
522
604
|
t += n.content;
|
|
523
605
|
continue;
|
|
524
606
|
}
|
|
525
|
-
let { markup: e, hasSlot: r } = n.descriptor, i = r ? n.children.length > 0 ?
|
|
526
|
-
t +=
|
|
607
|
+
let { markup: e, hasSlot: r } = n.descriptor, i = r ? n.children.length > 0 ? T(n.children) : n.slot?.content : void 0;
|
|
608
|
+
t += w(e, {
|
|
527
609
|
value: n.value,
|
|
528
610
|
meta: n.meta,
|
|
529
611
|
slot: i
|
|
@@ -533,30 +615,33 @@ function z(e) {
|
|
|
533
615
|
}
|
|
534
616
|
//#endregion
|
|
535
617
|
//#region ../../common/core/src/features/parsing/parser/Parser.ts
|
|
536
|
-
var
|
|
618
|
+
var xe = class e {
|
|
537
619
|
registry;
|
|
538
620
|
segmentMatcher;
|
|
539
621
|
patternMatcher;
|
|
540
622
|
treeBuilder;
|
|
541
|
-
|
|
542
|
-
|
|
623
|
+
parseOptions;
|
|
624
|
+
constructor(e, t) {
|
|
625
|
+
this.registry = new fe(e), this.segmentMatcher = new ve(this.registry.segments), this.patternMatcher = new ge(this.registry), this.parseOptions = t ?? {}, this.treeBuilder = new be(this.parseOptions);
|
|
543
626
|
}
|
|
544
627
|
static parse(t, n) {
|
|
545
628
|
let r = n?.markup;
|
|
546
|
-
|
|
629
|
+
if (!r || r.length === 0) return [ye(t)];
|
|
630
|
+
let { markup: i, ...a } = n;
|
|
631
|
+
return new e(r, a).parse(t);
|
|
547
632
|
}
|
|
548
633
|
static stringify(e) {
|
|
549
|
-
return
|
|
634
|
+
return T(e);
|
|
550
635
|
}
|
|
551
636
|
parse(e) {
|
|
552
637
|
let t = this.segmentMatcher.search(e), n = this.patternMatcher.process(t);
|
|
553
638
|
return this.treeBuilder.build(n, e);
|
|
554
639
|
}
|
|
555
640
|
stringify(e) {
|
|
556
|
-
return
|
|
641
|
+
return T(e);
|
|
557
642
|
}
|
|
558
643
|
transform(e, t) {
|
|
559
|
-
return
|
|
644
|
+
return C(this.parse(e), t);
|
|
560
645
|
}
|
|
561
646
|
escape(e) {
|
|
562
647
|
return this.registry.segments.filter((e) => typeof e == "string").toSorted((e, t) => t.length - e.length).reduce((e, t) => e.replaceAll(t, t.replace(/(.)/g, "\\$1")), e);
|
|
@@ -567,26 +652,26 @@ var B = class e {
|
|
|
567
652
|
};
|
|
568
653
|
//#endregion
|
|
569
654
|
//#region ../../common/core/src/features/parsing/parser/utils/denote.ts
|
|
570
|
-
function
|
|
571
|
-
return n.length ?
|
|
655
|
+
function Se(e, t, n) {
|
|
656
|
+
return n.length ? C(new xe(n).parse(e), t) : e;
|
|
572
657
|
}
|
|
573
658
|
//#endregion
|
|
574
659
|
//#region ../../common/core/src/features/parsing/utils/findToken.ts
|
|
575
|
-
function
|
|
660
|
+
function E(e, t, n = 0, r) {
|
|
576
661
|
for (let i of e) {
|
|
577
662
|
if (i === t) return {
|
|
578
663
|
depth: n,
|
|
579
664
|
parent: r
|
|
580
665
|
};
|
|
581
666
|
if (i.type === "mark") {
|
|
582
|
-
let e =
|
|
667
|
+
let e = E(i.children, t, n + 1, i);
|
|
583
668
|
if (e) return e;
|
|
584
669
|
}
|
|
585
670
|
}
|
|
586
671
|
}
|
|
587
672
|
//#endregion
|
|
588
673
|
//#region ../../common/core/src/features/parsing/preparsing/utils/findGap.ts
|
|
589
|
-
function
|
|
674
|
+
function Ce(e = "", t = "") {
|
|
590
675
|
if (e === t) return {};
|
|
591
676
|
let n;
|
|
592
677
|
for (let r = 0; r < e.length; r++) if (e[r] !== t[r]) {
|
|
@@ -605,7 +690,7 @@ function oe(e = "", t = "") {
|
|
|
605
690
|
}
|
|
606
691
|
//#endregion
|
|
607
692
|
//#region ../../common/core/src/features/parsing/preparsing/utils/getClosestIndexes.ts
|
|
608
|
-
function
|
|
693
|
+
function we(e, t) {
|
|
609
694
|
let n = -1, r = e.length;
|
|
610
695
|
for (; r - n > 1;) {
|
|
611
696
|
let i = Math.round((n + r) / 2);
|
|
@@ -615,49 +700,47 @@ function se(e, t) {
|
|
|
615
700
|
}
|
|
616
701
|
//#endregion
|
|
617
702
|
//#region ../../common/core/src/features/parsing/utils/valueParser.ts
|
|
618
|
-
function
|
|
703
|
+
function Te(e) {
|
|
619
704
|
let { focus: t } = e.nodes, n = e.state.parser.get(), r = e.state.tokens.get();
|
|
620
705
|
if (!n) return r;
|
|
621
706
|
let i = n.parse(t.content);
|
|
622
707
|
return i.length === 1 ? r : r.toSpliced(t.index, 1, ...i);
|
|
623
708
|
}
|
|
624
|
-
function
|
|
625
|
-
let t = e.state.value.get(), n =
|
|
709
|
+
function Ee(e) {
|
|
710
|
+
let t = e.state.value.get(), n = De(e), r = Ce(e.state.previousValue.get(), t);
|
|
626
711
|
if (!r.left && !r.right) return e.state.previousValue.set(t), e.state.tokens.get();
|
|
627
712
|
e.state.previousValue.set(t);
|
|
628
713
|
let i = e.state.tokens.get();
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
|
|
641
|
-
}
|
|
642
|
-
default: return H(e, t ?? "");
|
|
714
|
+
if (r.left !== void 0 && n.includes(r.left) && r.right !== void 0 && Math.abs(r.left - r.right) > 1) {
|
|
715
|
+
let t = n.indexOf(r.left), a = D(e, t - 1, t);
|
|
716
|
+
return i.toSpliced(t - 1, 2, ...a);
|
|
717
|
+
}
|
|
718
|
+
if (r.left !== void 0) {
|
|
719
|
+
let [t] = we(n, r.left), a = D(e, t);
|
|
720
|
+
return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
|
|
721
|
+
}
|
|
722
|
+
if (r.right !== void 0) {
|
|
723
|
+
let [t] = we(n, r.right), a = D(e, t);
|
|
724
|
+
return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
|
|
643
725
|
}
|
|
726
|
+
return O(e, t ?? "");
|
|
644
727
|
}
|
|
645
|
-
function
|
|
728
|
+
function D(e, ...t) {
|
|
646
729
|
let n = "", r = e.state.tokens.get();
|
|
647
730
|
for (let e of t) {
|
|
648
731
|
let t = r[e];
|
|
649
732
|
n += t.content;
|
|
650
733
|
}
|
|
651
|
-
return
|
|
734
|
+
return O(e, n);
|
|
652
735
|
}
|
|
653
|
-
function
|
|
736
|
+
function De(e) {
|
|
654
737
|
let t = 0;
|
|
655
738
|
return e.state.tokens.get().map((e) => {
|
|
656
739
|
let n = e.content.length;
|
|
657
740
|
return t += n, t - n;
|
|
658
|
-
})
|
|
741
|
+
});
|
|
659
742
|
}
|
|
660
|
-
function
|
|
743
|
+
function O(e, t) {
|
|
661
744
|
let n = e.state.parser.get();
|
|
662
745
|
return n ? n.parse(t) : [{
|
|
663
746
|
type: "text",
|
|
@@ -670,12 +753,12 @@ function H(e, t) {
|
|
|
670
753
|
}
|
|
671
754
|
//#endregion
|
|
672
755
|
//#region ../../common/core/src/shared/classes/Reactive.ts
|
|
673
|
-
var
|
|
756
|
+
var Oe = (e, t) => e === t, k = class e {
|
|
674
757
|
#e;
|
|
675
758
|
#t = /* @__PURE__ */ new Set();
|
|
676
759
|
#n;
|
|
677
760
|
constructor(e, t) {
|
|
678
|
-
this.#e = e, this.#n = t?.equals ??
|
|
761
|
+
this.#e = e, this.#n = t?.equals ?? Oe;
|
|
679
762
|
}
|
|
680
763
|
static event() {
|
|
681
764
|
return new e(void 0, { equals: !1 });
|
|
@@ -684,13 +767,13 @@ var fe = (e, t) => e === t, pe = class e {
|
|
|
684
767
|
return this.#e;
|
|
685
768
|
}
|
|
686
769
|
set value(e) {
|
|
687
|
-
|
|
770
|
+
this.setSilent(e) && this.notify();
|
|
688
771
|
}
|
|
689
772
|
on(e) {
|
|
690
773
|
return this.#t.add(e), () => this.#t.delete(e);
|
|
691
774
|
}
|
|
692
775
|
emit(e) {
|
|
693
|
-
|
|
776
|
+
e !== void 0 && (this.#e = e), this.#t.forEach((e) => e(this.#e));
|
|
694
777
|
}
|
|
695
778
|
get() {
|
|
696
779
|
return this.#e;
|
|
@@ -698,49 +781,204 @@ var fe = (e, t) => e === t, pe = class e {
|
|
|
698
781
|
set(e) {
|
|
699
782
|
this.value = e;
|
|
700
783
|
}
|
|
784
|
+
setSilent(e) {
|
|
785
|
+
return this.#n === !1 || !this.#n(this.#e, e) ? (this.#e = e, !0) : !1;
|
|
786
|
+
}
|
|
787
|
+
notify() {
|
|
788
|
+
this.#t.forEach((e) => e(this.#e));
|
|
789
|
+
}
|
|
701
790
|
};
|
|
702
791
|
//#endregion
|
|
703
792
|
//#region ../../common/core/src/shared/classes/defineState.ts
|
|
704
|
-
function
|
|
793
|
+
function ke(e, t) {
|
|
705
794
|
let n = {};
|
|
706
795
|
return n.get = () => e.get(), n.set = (t) => e.set(t), n.on = (t) => e.on(t), n.use = t(n), n;
|
|
707
796
|
}
|
|
708
|
-
function
|
|
709
|
-
let
|
|
710
|
-
for (let t in e)
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
797
|
+
function Ae(e, t, n) {
|
|
798
|
+
let r = /* @__PURE__ */ new Map();
|
|
799
|
+
for (let t in e) {
|
|
800
|
+
let i = n?.equals?.[t];
|
|
801
|
+
r.set(t, new k(e[t], i == null ? void 0 : { equals: i }));
|
|
802
|
+
}
|
|
803
|
+
return new Proxy(e, { get(e, n) {
|
|
804
|
+
if (n === "set") return (e) => {
|
|
805
|
+
let t = [];
|
|
806
|
+
for (let n in e) {
|
|
807
|
+
let i = r.get(n);
|
|
808
|
+
i?.setSilent(e[n]) && t.push(i);
|
|
809
|
+
}
|
|
810
|
+
for (let e of t) e.notify();
|
|
714
811
|
};
|
|
715
|
-
let i =
|
|
716
|
-
if (i) return
|
|
812
|
+
let i = r.get(n);
|
|
813
|
+
if (i) return ke(i, t);
|
|
717
814
|
} });
|
|
718
815
|
}
|
|
719
816
|
//#endregion
|
|
720
817
|
//#region ../../common/core/src/shared/classes/defineEvents.ts
|
|
721
|
-
function
|
|
722
|
-
|
|
818
|
+
function je(e) {
|
|
819
|
+
return Object.assign((t) => {
|
|
723
820
|
e.emit(t);
|
|
724
|
-
};
|
|
725
|
-
return t.on = (t) => e.on(t), t;
|
|
821
|
+
}, { on: (t) => e.on(t) });
|
|
726
822
|
}
|
|
727
|
-
function
|
|
823
|
+
function Me(e) {
|
|
728
824
|
let t = e ? Object.keys(e) : [], n = /* @__PURE__ */ new Map();
|
|
729
|
-
for (let e of t) n.set(e,
|
|
825
|
+
for (let e of t) n.set(e, k.event());
|
|
730
826
|
return new Proxy({}, { get(e, t) {
|
|
731
827
|
let r = n.get(t);
|
|
732
|
-
return r || (r =
|
|
828
|
+
return r || (r = k.event(), n.set(t, r)), je(r);
|
|
733
829
|
} });
|
|
734
830
|
}
|
|
735
831
|
//#endregion
|
|
736
|
-
//#region ../../common/core/src/
|
|
737
|
-
|
|
832
|
+
//#region ../../common/core/src/features/drag/eventHandlers.ts
|
|
833
|
+
function Ne(e, t) {
|
|
834
|
+
return e < t.top + t.height / 2 ? "before" : "after";
|
|
835
|
+
}
|
|
836
|
+
function Pe(e) {
|
|
837
|
+
let t = parseInt(e.getData("text/plain"), 10);
|
|
838
|
+
return isNaN(t) ? null : t;
|
|
839
|
+
}
|
|
840
|
+
function Fe(e, t) {
|
|
841
|
+
return t === "before" ? e : e + 1;
|
|
842
|
+
}
|
|
843
|
+
//#endregion
|
|
844
|
+
//#region ../../common/core/src/shared/utils/menuUtils.ts
|
|
845
|
+
function Ie(e, t) {
|
|
846
|
+
return !!t && !t.contains(e instanceof Node ? e : null);
|
|
847
|
+
}
|
|
848
|
+
function Le(e) {
|
|
849
|
+
return e.key === "Escape";
|
|
850
|
+
}
|
|
851
|
+
//#endregion
|
|
852
|
+
//#region ../../common/core/src/shared/classes/BlockStore.ts
|
|
853
|
+
var Re = class {
|
|
854
|
+
refs = { container: null };
|
|
855
|
+
state;
|
|
856
|
+
#e = 0;
|
|
857
|
+
#t = null;
|
|
858
|
+
#n;
|
|
859
|
+
#r;
|
|
860
|
+
#i;
|
|
861
|
+
constructor(e) {
|
|
862
|
+
this.state = Ae({
|
|
863
|
+
isHovered: !1,
|
|
864
|
+
isDragging: !1,
|
|
865
|
+
dropPosition: null,
|
|
866
|
+
menuOpen: !1,
|
|
867
|
+
menuPosition: {
|
|
868
|
+
top: 0,
|
|
869
|
+
left: 0
|
|
870
|
+
}
|
|
871
|
+
}, e);
|
|
872
|
+
}
|
|
873
|
+
attachContainer(e, t, n) {
|
|
874
|
+
if (this.#e = t, this.#t = n, e === this.refs.container || (this.#n?.(), this.refs.container = e, !e)) return;
|
|
875
|
+
let r = () => this.state.isHovered.set(!0), i = () => this.state.isHovered.set(!1), a = (t) => {
|
|
876
|
+
t.dataTransfer && (t.preventDefault(), t.dataTransfer.dropEffect = "move", this.state.dropPosition.set(Ne(t.clientY, e.getBoundingClientRect())));
|
|
877
|
+
}, o = (e) => {
|
|
878
|
+
let t = e.currentTarget;
|
|
879
|
+
t instanceof Node && t.contains(e.relatedTarget instanceof Node ? e.relatedTarget : null) || this.state.dropPosition.set(null);
|
|
880
|
+
}, s = (e) => {
|
|
881
|
+
if (!e.dataTransfer) return;
|
|
882
|
+
e.preventDefault();
|
|
883
|
+
let t = Pe(e.dataTransfer);
|
|
884
|
+
if (t === null) return;
|
|
885
|
+
let r = Fe(this.#e, this.state.dropPosition.get() ?? "after");
|
|
886
|
+
this.state.dropPosition.set(null), n.reorder(t, r);
|
|
887
|
+
};
|
|
888
|
+
e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", i), e.addEventListener("dragover", a), e.addEventListener("dragleave", o), e.addEventListener("drop", s), this.#n = () => {
|
|
889
|
+
e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", i), e.removeEventListener("dragover", a), e.removeEventListener("dragleave", o), e.removeEventListener("drop", s);
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
attachGrip(e, t, n) {
|
|
893
|
+
if (this.#e = t, this.#t = n, this.#r?.(), !e) return;
|
|
894
|
+
let r = (e) => {
|
|
895
|
+
e.dataTransfer && (e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", String(this.#e)), this.state.isDragging.set(!0), this.refs.container && e.dataTransfer.setDragImage(this.refs.container, 0, 0));
|
|
896
|
+
}, i = () => {
|
|
897
|
+
this.state.isDragging.set(!1), this.state.dropPosition.set(null);
|
|
898
|
+
}, a = (t) => {
|
|
899
|
+
t.preventDefault();
|
|
900
|
+
let n = e.getBoundingClientRect();
|
|
901
|
+
this.state.menuPosition.set({
|
|
902
|
+
top: n.bottom + 4,
|
|
903
|
+
left: n.left
|
|
904
|
+
}), this.state.menuOpen.set(!0);
|
|
905
|
+
};
|
|
906
|
+
e.addEventListener("dragstart", r), e.addEventListener("dragend", i), e.addEventListener("click", a), this.#r = () => {
|
|
907
|
+
e.removeEventListener("dragstart", r), e.removeEventListener("dragend", i), e.removeEventListener("click", a);
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
attachMenu(e) {
|
|
911
|
+
if (this.#i?.(), !e) return;
|
|
912
|
+
let t = (t) => {
|
|
913
|
+
Ie(t.target, e) && this.closeMenu();
|
|
914
|
+
}, n = (e) => {
|
|
915
|
+
Le(e) && this.closeMenu();
|
|
916
|
+
};
|
|
917
|
+
document.addEventListener("mousedown", t), document.addEventListener("keydown", n), this.#i = () => {
|
|
918
|
+
document.removeEventListener("mousedown", t), document.removeEventListener("keydown", n);
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
closeMenu = () => this.state.menuOpen.set(!1);
|
|
922
|
+
addBlock = () => {
|
|
923
|
+
this.#t && (this.#t.add(this.#e), this.closeMenu());
|
|
924
|
+
};
|
|
925
|
+
deleteBlock = () => {
|
|
926
|
+
this.#t && (this.#t.delete(this.#e), this.closeMenu());
|
|
927
|
+
};
|
|
928
|
+
duplicateBlock = () => {
|
|
929
|
+
this.#t && (this.#t.duplicate(this.#e), this.closeMenu());
|
|
930
|
+
};
|
|
931
|
+
}, ze = class {
|
|
932
|
+
#e = /* @__PURE__ */ new WeakMap();
|
|
933
|
+
#t;
|
|
934
|
+
constructor(e) {
|
|
935
|
+
this.#t = e;
|
|
936
|
+
}
|
|
937
|
+
get(e) {
|
|
938
|
+
let t = this.#e.get(e);
|
|
939
|
+
return t || (t = new Re(this.#t), this.#e.set(e, t)), t;
|
|
940
|
+
}
|
|
941
|
+
}, Be = class {
|
|
738
942
|
#e = 1;
|
|
739
943
|
#t = /* @__PURE__ */ new WeakMap();
|
|
740
944
|
get(e) {
|
|
741
945
|
return this.#t.has(e) ? this.#t.get(e) : (this.#t.set(e, this.#e), this.#e++);
|
|
742
946
|
}
|
|
743
|
-
}
|
|
947
|
+
};
|
|
948
|
+
//#endregion
|
|
949
|
+
//#region ../../common/core/src/shared/checkers/domGuards.ts
|
|
950
|
+
function A(e) {
|
|
951
|
+
return typeof HTMLElement < "u" && e instanceof HTMLElement;
|
|
952
|
+
}
|
|
953
|
+
function j(e) {
|
|
954
|
+
return e instanceof Text;
|
|
955
|
+
}
|
|
956
|
+
function M(e, t) {
|
|
957
|
+
let n = e?.children[t];
|
|
958
|
+
return n instanceof HTMLElement ? n : void 0;
|
|
959
|
+
}
|
|
960
|
+
function N(e) {
|
|
961
|
+
return e ? Array.from(e.children).filter((e) => e instanceof HTMLElement) : [];
|
|
962
|
+
}
|
|
963
|
+
function Ve(e) {
|
|
964
|
+
let t = e?.firstElementChild;
|
|
965
|
+
return t instanceof HTMLElement ? t : null;
|
|
966
|
+
}
|
|
967
|
+
function He(e) {
|
|
968
|
+
let t = e?.lastElementChild;
|
|
969
|
+
return t instanceof HTMLElement ? t : null;
|
|
970
|
+
}
|
|
971
|
+
function Ue(e) {
|
|
972
|
+
let { target: t } = e;
|
|
973
|
+
return t instanceof Node ? t : null;
|
|
974
|
+
}
|
|
975
|
+
function P(e) {
|
|
976
|
+
let t = e.nextNode();
|
|
977
|
+
return t?.nodeType === 3 ? t : null;
|
|
978
|
+
}
|
|
979
|
+
//#endregion
|
|
980
|
+
//#region ../../common/core/src/features/caret/Caret.ts
|
|
981
|
+
var F = class {
|
|
744
982
|
static get isSelectedPosition() {
|
|
745
983
|
let e = window.getSelection();
|
|
746
984
|
if (e) return e.isCollapsed;
|
|
@@ -757,7 +995,7 @@ var ve = class {
|
|
|
757
995
|
throw Error("Anchor node of selection is not exists!");
|
|
758
996
|
}
|
|
759
997
|
static getAbsolutePosition() {
|
|
760
|
-
let e = window.getSelection()?.getRangeAt(0).getBoundingClientRect
|
|
998
|
+
let e = window.getSelection()?.getRangeAt(0).getBoundingClientRect();
|
|
761
999
|
return e ? {
|
|
762
1000
|
left: e.left,
|
|
763
1001
|
top: e.top + e.height + 1
|
|
@@ -786,19 +1024,19 @@ var ve = class {
|
|
|
786
1024
|
return t.bottom > n.bottom - t.height - 2;
|
|
787
1025
|
}
|
|
788
1026
|
static setAtX(e, t, n) {
|
|
789
|
-
let r = e.getBoundingClientRect(), i = n ?? r.top + r.height / 2, a = document.caretRangeFromPoint?.(t, i) ??
|
|
790
|
-
if (!a) return;
|
|
791
|
-
let o = window.getSelection();
|
|
1027
|
+
let r = e.getBoundingClientRect(), i = n ?? r.top + r.height / 2, a = document, o = a.caretRangeFromPoint?.(t, i) ?? a.caretPositionFromPoint?.(t, i);
|
|
792
1028
|
if (!o) return;
|
|
793
|
-
let s;
|
|
794
|
-
if (
|
|
795
|
-
|
|
1029
|
+
let s = window.getSelection();
|
|
1030
|
+
if (!s) return;
|
|
1031
|
+
let c;
|
|
1032
|
+
if (o instanceof Range) c = o;
|
|
1033
|
+
else if ("offsetNode" in o) c = document.createRange(), c.setStart(o.offsetNode, o.offset), c.collapse(!0);
|
|
796
1034
|
else return;
|
|
797
|
-
if (!e.contains(
|
|
1035
|
+
if (!e.contains(c.startContainer)) {
|
|
798
1036
|
this.setIndex(e, Infinity);
|
|
799
1037
|
return;
|
|
800
1038
|
}
|
|
801
|
-
|
|
1039
|
+
s.removeAllRanges(), s.addRange(c);
|
|
802
1040
|
}
|
|
803
1041
|
static trySetIndex(e, t) {
|
|
804
1042
|
try {
|
|
@@ -810,11 +1048,11 @@ var ve = class {
|
|
|
810
1048
|
static setIndex(e, t) {
|
|
811
1049
|
let n = window.getSelection();
|
|
812
1050
|
if (!n) return;
|
|
813
|
-
let r = document.createTreeWalker(e, 4), i = r
|
|
1051
|
+
let r = document.createTreeWalker(e, 4), i = P(r);
|
|
814
1052
|
if (!i) return;
|
|
815
1053
|
let a = isFinite(t) ? Math.max(0, t) : Infinity;
|
|
816
|
-
for (
|
|
817
|
-
let e = r
|
|
1054
|
+
for (;;) {
|
|
1055
|
+
let e = P(r);
|
|
818
1056
|
if (!e || a <= i.length) {
|
|
819
1057
|
let e = isFinite(a) ? Math.min(a, i.length) : i.length, t = document.createRange();
|
|
820
1058
|
t.setStart(i, e), t.collapse(!0), n.removeAllRanges(), n.addRange(t);
|
|
@@ -839,22 +1077,22 @@ var ve = class {
|
|
|
839
1077
|
let t = window.getSelection();
|
|
840
1078
|
if (!t?.anchorNode || !t.rangeCount) return;
|
|
841
1079
|
let n = t.getRangeAt(0);
|
|
842
|
-
n
|
|
1080
|
+
n.setStart(n.startContainer.firstChild ?? n.startContainer, e), n.setEnd(n.startContainer.firstChild ?? n.startContainer, e);
|
|
843
1081
|
}
|
|
844
1082
|
setCaretRightTo(e, t) {
|
|
845
1083
|
let n = window.getSelection()?.getRangeAt(0);
|
|
846
1084
|
n?.setStart(n.endContainer, t), n?.setEnd(n.endContainer, t);
|
|
847
1085
|
}
|
|
848
|
-
},
|
|
1086
|
+
}, We = /* @__PURE__ */ new RegExp(/^\w*/), Ge = class e {
|
|
849
1087
|
span;
|
|
850
1088
|
node;
|
|
851
1089
|
dividedText;
|
|
852
1090
|
constructor() {
|
|
853
|
-
let e =
|
|
854
|
-
this.node =
|
|
1091
|
+
let e = F.getCurrentPosition();
|
|
1092
|
+
this.node = F.getSelectedNode(), this.span = F.getFocusedSpan(), this.dividedText = this.getDividedTextBy(e);
|
|
855
1093
|
}
|
|
856
1094
|
static find(t, n) {
|
|
857
|
-
if (t &&
|
|
1095
|
+
if (t && F.isSelectedPosition) try {
|
|
858
1096
|
return new e().find(t, n);
|
|
859
1097
|
} catch {
|
|
860
1098
|
return;
|
|
@@ -891,7 +1129,7 @@ var ve = class {
|
|
|
891
1129
|
}
|
|
892
1130
|
matchRightPart() {
|
|
893
1131
|
let { right: e } = this.dividedText;
|
|
894
|
-
return { word: e.match(
|
|
1132
|
+
return { word: e.match(We)?.[0] };
|
|
895
1133
|
}
|
|
896
1134
|
matchLeftPart(e) {
|
|
897
1135
|
let t = this.makeTriggerRegex(e), { left: n } = this.dividedText, r = n.match(t);
|
|
@@ -904,17 +1142,17 @@ var ve = class {
|
|
|
904
1142
|
};
|
|
905
1143
|
}
|
|
906
1144
|
makeTriggerRegex(e) {
|
|
907
|
-
let t =
|
|
1145
|
+
let t = S(e) + "(\\w*)$";
|
|
908
1146
|
return new RegExp(t);
|
|
909
1147
|
}
|
|
910
|
-
},
|
|
1148
|
+
}, Ke = class e {
|
|
911
1149
|
#e;
|
|
912
1150
|
#t;
|
|
913
1151
|
get target() {
|
|
914
1152
|
return this.#e;
|
|
915
1153
|
}
|
|
916
1154
|
set target(e) {
|
|
917
|
-
this.#e = e;
|
|
1155
|
+
this.#e = A(e) ? e : void 0;
|
|
918
1156
|
}
|
|
919
1157
|
get next() {
|
|
920
1158
|
return new e(this.target?.nextSibling, this.#t);
|
|
@@ -932,22 +1170,22 @@ var ve = class {
|
|
|
932
1170
|
return this.target?.isContentEditable ?? !1;
|
|
933
1171
|
}
|
|
934
1172
|
get isCaretAtBeginning() {
|
|
935
|
-
if (this.target) return
|
|
1173
|
+
if (this.target) return F.getCaretIndex(this.target) === 0;
|
|
936
1174
|
}
|
|
937
1175
|
get isCaretAtEnd() {
|
|
938
|
-
if (this.target) return
|
|
1176
|
+
if (this.target) return F.getCaretIndex(this.target) === this.target.textContent.length;
|
|
939
1177
|
}
|
|
940
1178
|
get index() {
|
|
941
1179
|
return this.target?.parentElement ? [...this.target.parentElement.children].indexOf(this.target) : -1;
|
|
942
1180
|
}
|
|
943
1181
|
get caret() {
|
|
944
|
-
return this.target ?
|
|
1182
|
+
return this.target ? F.getCaretIndex(this.target) : -1;
|
|
945
1183
|
}
|
|
946
1184
|
set caret(e) {
|
|
947
|
-
this.target &&
|
|
1185
|
+
this.target && F.trySetIndex(this.target, e);
|
|
948
1186
|
}
|
|
949
1187
|
get length() {
|
|
950
|
-
return this.target?.textContent
|
|
1188
|
+
return this.target?.textContent.length ?? -1;
|
|
951
1189
|
}
|
|
952
1190
|
get content() {
|
|
953
1191
|
return this.target?.textContent ?? "";
|
|
@@ -956,10 +1194,10 @@ var ve = class {
|
|
|
956
1194
|
this.target && (this.target.textContent = e ?? "");
|
|
957
1195
|
}
|
|
958
1196
|
get head() {
|
|
959
|
-
return this.#t.refs.container
|
|
1197
|
+
return Ve(this.#t.refs.container ?? void 0);
|
|
960
1198
|
}
|
|
961
1199
|
get tail() {
|
|
962
|
-
return this.#t.refs.container
|
|
1200
|
+
return He(this.#t.refs.container ?? void 0);
|
|
963
1201
|
}
|
|
964
1202
|
get isFocused() {
|
|
965
1203
|
return this.target === document.activeElement;
|
|
@@ -968,7 +1206,7 @@ var ve = class {
|
|
|
968
1206
|
this.target = e, this.#t = t;
|
|
969
1207
|
}
|
|
970
1208
|
setCaretToEnd() {
|
|
971
|
-
|
|
1209
|
+
F.setCaretToEnd(this.target);
|
|
972
1210
|
}
|
|
973
1211
|
focus() {
|
|
974
1212
|
this.target?.focus();
|
|
@@ -978,162 +1216,118 @@ var ve = class {
|
|
|
978
1216
|
}
|
|
979
1217
|
};
|
|
980
1218
|
//#endregion
|
|
981
|
-
//#region ../../common/core/src/features/
|
|
982
|
-
function
|
|
983
|
-
return e.
|
|
1219
|
+
//#region ../../common/core/src/features/drag/operations.ts
|
|
1220
|
+
function qe(e, t, n) {
|
|
1221
|
+
return e.substring(t.position.end, n.position.start);
|
|
984
1222
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
function Ce(e, t) {
|
|
988
|
-
let n = {
|
|
989
|
-
prev: 2,
|
|
990
|
-
self: 1,
|
|
991
|
-
next: 0
|
|
992
|
-
}[e], { focus: r } = t.nodes, i = t.state.tokens.get(), [a, , o] = i.splice(r.index - n, 3), s = (a.type, a.content), c = (o.type, o.content);
|
|
993
|
-
t.state.tokens.set(i.toSpliced(r.index - n, 0, {
|
|
994
|
-
type: "text",
|
|
995
|
-
content: s + c,
|
|
996
|
-
position: {
|
|
997
|
-
start: a.position.start,
|
|
998
|
-
end: o.position.end
|
|
999
|
-
}
|
|
1000
|
-
}));
|
|
1001
|
-
let l = r;
|
|
1002
|
-
for (let e = 0; e < n; e++) l = l.prev;
|
|
1003
|
-
let u = l.length;
|
|
1004
|
-
t.state.recovery.set({
|
|
1005
|
-
anchor: l.prev,
|
|
1006
|
-
caret: u
|
|
1007
|
-
}), t.state.onChange.get()?.(z(t.state.tokens.get()));
|
|
1008
|
-
}
|
|
1009
|
-
//#endregion
|
|
1010
|
-
//#region ../../common/core/src/features/blocks/config.ts
|
|
1011
|
-
function we(e) {
|
|
1012
|
-
return typeof e == "object" && !!e.alwaysShowHandle;
|
|
1013
|
-
}
|
|
1014
|
-
//#endregion
|
|
1015
|
-
//#region ../../common/core/src/features/blocks/splitTokensIntoDragRows.ts
|
|
1016
|
-
function Te(e) {
|
|
1017
|
-
let t = [], { content: n, position: r } = e, i = r.start, a = [], o = () => {
|
|
1018
|
-
if (a.length > 0) {
|
|
1019
|
-
let e = a.join("");
|
|
1020
|
-
t.push({
|
|
1021
|
-
content: e,
|
|
1022
|
-
position: {
|
|
1023
|
-
start: i,
|
|
1024
|
-
end: i + e.length
|
|
1025
|
-
},
|
|
1026
|
-
isBlockSeparator: !1
|
|
1027
|
-
}), i += e.length, a.length = 0;
|
|
1028
|
-
}
|
|
1029
|
-
};
|
|
1030
|
-
for (let e = 0; e < n.length; e++) {
|
|
1031
|
-
let r = n[e];
|
|
1032
|
-
r === "\n" ? e + 1 < n.length && n[e + 1] === "\n" ? (o(), t.push({
|
|
1033
|
-
content: "\n\n",
|
|
1034
|
-
position: {
|
|
1035
|
-
start: i,
|
|
1036
|
-
end: i + 2
|
|
1037
|
-
},
|
|
1038
|
-
isBlockSeparator: !0
|
|
1039
|
-
}), i += 2, e++) : (a.push(r), i++) : r === "\r" ? e + 1 < n.length && n[e + 1] === "\n" ? e + 2 < n.length && n[e + 2] === "\r" && e + 3 < n.length && n[e + 3] === "\n" ? (o(), t.push({
|
|
1040
|
-
content: "\n\n",
|
|
1041
|
-
position: {
|
|
1042
|
-
start: i,
|
|
1043
|
-
end: i + 4
|
|
1044
|
-
},
|
|
1045
|
-
isBlockSeparator: !0
|
|
1046
|
-
}), i += 4, e += 3) : (a.push("\n"), i += 2, e++) : (a.push("\n"), i++) : a.push(r);
|
|
1047
|
-
}
|
|
1048
|
-
return o(), t;
|
|
1049
|
-
}
|
|
1050
|
-
var Ee = 0;
|
|
1051
|
-
function W(e) {
|
|
1052
|
-
return `drag-${Ee++}-${e}`;
|
|
1053
|
-
}
|
|
1054
|
-
function De() {
|
|
1055
|
-
Ee = 0;
|
|
1056
|
-
}
|
|
1057
|
-
function G(e) {
|
|
1058
|
-
if (e.length === 0) return [];
|
|
1059
|
-
De();
|
|
1060
|
-
let t = [], n = null;
|
|
1061
|
-
for (let r of e) if (r.type === "mark") n = null, t.push({
|
|
1062
|
-
id: W(r.position.start),
|
|
1063
|
-
tokens: [r],
|
|
1064
|
-
startPos: r.position.start,
|
|
1065
|
-
endPos: r.position.end
|
|
1066
|
-
});
|
|
1067
|
-
else if (r.type === "text") {
|
|
1068
|
-
let e = Te(r);
|
|
1069
|
-
for (let r of e) r.isBlockSeparator ? (n !== null && t.push({
|
|
1070
|
-
id: W(n),
|
|
1071
|
-
tokens: [],
|
|
1072
|
-
startPos: n,
|
|
1073
|
-
endPos: n
|
|
1074
|
-
}), n = r.position.end) : r.content.trim().length > 0 && (n = null, t.push({
|
|
1075
|
-
id: W(r.position.start),
|
|
1076
|
-
tokens: [{
|
|
1077
|
-
type: "text",
|
|
1078
|
-
content: r.content,
|
|
1079
|
-
position: r.position
|
|
1080
|
-
}],
|
|
1081
|
-
startPos: r.position.start,
|
|
1082
|
-
endPos: r.position.end
|
|
1083
|
-
}));
|
|
1084
|
-
}
|
|
1085
|
-
return n !== null && t.push({
|
|
1086
|
-
id: W(n),
|
|
1087
|
-
tokens: [],
|
|
1088
|
-
startPos: n,
|
|
1089
|
-
endPos: n
|
|
1090
|
-
}), t;
|
|
1223
|
+
function I(e) {
|
|
1224
|
+
return e.type === "mark" && e.descriptor.hasSlot && e.descriptor.segments.length === 1;
|
|
1091
1225
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
function K(e) {
|
|
1095
|
-
return e.tokens.length === 0 || e.tokens[0].type === "text";
|
|
1226
|
+
function L(e, t) {
|
|
1227
|
+
return !!(e.type === "text" && t.type === "text" && t.position.start > e.position.end || I(e) && I(t) && e.descriptor === t.descriptor);
|
|
1096
1228
|
}
|
|
1097
|
-
function
|
|
1098
|
-
|
|
1229
|
+
function Je(e, t, n, r) {
|
|
1230
|
+
if (t.length === 0) return e + r;
|
|
1231
|
+
if (e === "" || t.length === 1 && t[0].type === "text" && t[0].content === "") return r + r;
|
|
1232
|
+
if (n >= t.length - 1) return e + r;
|
|
1233
|
+
let i = t[n + 1].position.start;
|
|
1234
|
+
return e.slice(0, i) + r + e.slice(i);
|
|
1099
1235
|
}
|
|
1100
|
-
function
|
|
1101
|
-
|
|
1102
|
-
if (n >= t.length - 1) return e === "" ? "\n\n\n\n" : e + "\n\n";
|
|
1103
|
-
let r = t[n], i = t[n + 1];
|
|
1104
|
-
return i.startPos - r.endPos === 0 ? e.slice(0, r.endPos) + "\n\n\n\n" + e.slice(i.startPos) : e.slice(0, i.startPos) + "\n\n" + e.slice(i.startPos);
|
|
1236
|
+
function Ye(e, t, n) {
|
|
1237
|
+
return t.length <= 1 ? "" : n >= t.length - 1 ? e.slice(0, t[n - 1].position.end) : e.slice(0, t[n].position.start) + e.slice(t[n + 1].position.start);
|
|
1105
1238
|
}
|
|
1106
|
-
function
|
|
1107
|
-
|
|
1239
|
+
function Xe(e, t, n) {
|
|
1240
|
+
let r = t[n], i = e.substring(r.position.start, r.position.end);
|
|
1241
|
+
if (n >= t.length - 1) return e + i;
|
|
1242
|
+
let a = t[n + 1], o = qe(e, r, a);
|
|
1243
|
+
return e.slice(0, a.position.start) + i + o + e.slice(a.position.start);
|
|
1108
1244
|
}
|
|
1109
|
-
function
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
return e.slice(0, a.startPos) + i + o + e.slice(a.startPos);
|
|
1114
|
-
}
|
|
1115
|
-
function Me(e, t) {
|
|
1116
|
-
return t <= 0 || t >= e.length ? 0 : e[t - 1].endPos;
|
|
1245
|
+
function R(e, t) {
|
|
1246
|
+
if (t <= 0 || t >= e.length) return 0;
|
|
1247
|
+
let n = e[t - 1];
|
|
1248
|
+
return I(n) && n.slot ? n.slot.end : n.position.end;
|
|
1117
1249
|
}
|
|
1118
|
-
function
|
|
1250
|
+
function z(e, t, n) {
|
|
1119
1251
|
if (n <= 0 || n >= t.length) return e;
|
|
1120
1252
|
let r = t[n - 1], i = t[n];
|
|
1121
|
-
|
|
1253
|
+
if (I(r) && I(i)) {
|
|
1254
|
+
let t = r.slot ? r.slot.end : r.position.end;
|
|
1255
|
+
return e.slice(0, t) + e.slice(i.position.start);
|
|
1256
|
+
}
|
|
1257
|
+
return e.slice(0, r.position.end) + e.slice(i.position.start);
|
|
1122
1258
|
}
|
|
1123
|
-
function
|
|
1259
|
+
function Ze(e, t, n, r) {
|
|
1124
1260
|
if (n === r || n === r - 1 || t.length < 2 || n < 0 || n >= t.length || r < 0 || r > t.length) return e;
|
|
1125
|
-
let i = t.map((t) => e.substring(t.
|
|
1126
|
-
a.splice(
|
|
1261
|
+
let i = t.map((t) => e.substring(t.position.start, t.position.end)), a = t.slice(0, -1).map((n, r) => qe(e, n, t[r + 1])), [o] = i.splice(n, 1), s = n < a.length ? n : n - 1;
|
|
1262
|
+
a.splice(s, 1);
|
|
1263
|
+
let c = r > n ? r - 1 : r;
|
|
1264
|
+
i.splice(c, 0, o), c < i.length - 1 && a.splice(c, 0, "");
|
|
1127
1265
|
let l = [];
|
|
1128
|
-
for (let e = 0; e < i.length; e++) l.push(i[e]), e <
|
|
1266
|
+
for (let e = 0; e < i.length; e++) l.push(i[e]), e < a.length && l.push(a[e]);
|
|
1129
1267
|
return l.join("");
|
|
1130
1268
|
}
|
|
1131
1269
|
//#endregion
|
|
1270
|
+
//#region ../../common/core/src/features/drag/tokens.ts
|
|
1271
|
+
var Qe = {
|
|
1272
|
+
type: "text",
|
|
1273
|
+
content: "",
|
|
1274
|
+
position: {
|
|
1275
|
+
start: 0,
|
|
1276
|
+
end: 0
|
|
1277
|
+
}
|
|
1278
|
+
}, $e = class {
|
|
1279
|
+
constructor(e) {
|
|
1280
|
+
this.store = e;
|
|
1281
|
+
}
|
|
1282
|
+
enable() {}
|
|
1283
|
+
disable() {}
|
|
1284
|
+
reorder(e, t) {
|
|
1285
|
+
let n = this.store.state.value.get();
|
|
1286
|
+
if (n == null || !this.store.state.onChange.get()) return;
|
|
1287
|
+
let r = Ze(n, this.store.state.tokens.get(), e, t);
|
|
1288
|
+
r !== n && this.store.applyValue(r);
|
|
1289
|
+
}
|
|
1290
|
+
add(e) {
|
|
1291
|
+
let t = this.store.state.value.get();
|
|
1292
|
+
if (t == null || !this.store.state.onChange.get()) return;
|
|
1293
|
+
let n = this.store.state.tokens.get(), r = n.length > 0 ? n : [Qe], i = this.#e();
|
|
1294
|
+
this.store.applyValue(Je(t, r, e, i)), queueMicrotask(() => {
|
|
1295
|
+
let t = this.store.refs.container;
|
|
1296
|
+
t && M(t, e + 1)?.focus();
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
delete(e) {
|
|
1300
|
+
let t = this.store.state.value.get();
|
|
1301
|
+
if (t == null || !this.store.state.onChange.get()) return;
|
|
1302
|
+
let n = this.store.state.tokens.get();
|
|
1303
|
+
this.store.applyValue(Ye(t, n, e));
|
|
1304
|
+
}
|
|
1305
|
+
duplicate(e) {
|
|
1306
|
+
let t = this.store.state.value.get();
|
|
1307
|
+
if (t == null || !this.store.state.onChange.get()) return;
|
|
1308
|
+
let n = this.store.state.tokens.get();
|
|
1309
|
+
this.store.applyValue(Xe(t, n, e));
|
|
1310
|
+
}
|
|
1311
|
+
#e() {
|
|
1312
|
+
let e = this.store.state.options.get()?.[0];
|
|
1313
|
+
return e?.markup ? w(e.markup, {
|
|
1314
|
+
value: "",
|
|
1315
|
+
slot: "",
|
|
1316
|
+
meta: ""
|
|
1317
|
+
}) : "\n";
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
//#endregion
|
|
1321
|
+
//#region ../../common/core/src/features/drag/config.ts
|
|
1322
|
+
function et(e) {
|
|
1323
|
+
return typeof e == "object" && !!e.alwaysShowHandle;
|
|
1324
|
+
}
|
|
1325
|
+
//#endregion
|
|
1132
1326
|
//#region ../../common/core/src/features/editable/ContentEditableController.ts
|
|
1133
|
-
function
|
|
1327
|
+
function tt(e) {
|
|
1134
1328
|
return e.tagName === "SPAN" && (e.attributes.length === 0 || e.attributes.length === 1 && e.hasAttribute("contenteditable"));
|
|
1135
1329
|
}
|
|
1136
|
-
var
|
|
1330
|
+
var nt = class {
|
|
1137
1331
|
#e;
|
|
1138
1332
|
constructor(e) {
|
|
1139
1333
|
this.store = e;
|
|
@@ -1149,63 +1343,93 @@ var Ie = class {
|
|
|
1149
1343
|
if (!e) return;
|
|
1150
1344
|
let t = this.store.state.readOnly.get(), n = t ? "false" : "true", r = e.children, i = !!this.store.state.drag.get();
|
|
1151
1345
|
if (i) {
|
|
1152
|
-
let
|
|
1153
|
-
for (let
|
|
1154
|
-
let
|
|
1155
|
-
|
|
1346
|
+
let i = this.store.state.tokens.get();
|
|
1347
|
+
for (let a = 0; a < i.length && a < r.length; a++) {
|
|
1348
|
+
let r = M(e, a);
|
|
1349
|
+
r && (i[a].type === "mark" ? t || (r.tabIndex = 0) : r.contentEditable = n);
|
|
1156
1350
|
}
|
|
1157
|
-
} else for (let
|
|
1351
|
+
} else for (let t = 0; t < r.length; t += 2) {
|
|
1352
|
+
let r = M(e, t);
|
|
1353
|
+
r && (r.contentEditable = n);
|
|
1354
|
+
}
|
|
1158
1355
|
let a = this.store.state.tokens.get();
|
|
1159
1356
|
i ? this.#r(a, e, t) : this.#t(a, e);
|
|
1160
1357
|
}
|
|
1161
1358
|
#t(e, t) {
|
|
1162
|
-
let n =
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
i && (r.type === "text" ? i.textContent !== r.content && (i.textContent = r.content) : r.type === "mark" && r.children.length > 0 && this.#n(r.children, i));
|
|
1359
|
+
for (let n = 0; n < e.length; n++) {
|
|
1360
|
+
let r = e[n], i = M(t, n);
|
|
1361
|
+
i && (r.type === "text" ? i.textContent !== r.content && (i.textContent = r.content) : r.children.length > 0 && this.#n(r.children, i));
|
|
1166
1362
|
}
|
|
1167
1363
|
}
|
|
1168
1364
|
#n(e, t, n) {
|
|
1169
1365
|
let r = t.children, i = 0;
|
|
1170
|
-
for (let
|
|
1366
|
+
for (let a of e) if (a.type === "text") {
|
|
1171
1367
|
for (; i < r.length;) {
|
|
1172
|
-
let e =
|
|
1173
|
-
if (
|
|
1368
|
+
let e = M(t, i);
|
|
1369
|
+
if (e && tt(e)) break;
|
|
1174
1370
|
i++;
|
|
1175
1371
|
}
|
|
1176
|
-
let e =
|
|
1177
|
-
e && (e.textContent !==
|
|
1178
|
-
} else if (
|
|
1372
|
+
let e = M(t, i);
|
|
1373
|
+
e && (e.textContent !== a.content && (e.textContent = a.content), n !== void 0 && (e.contentEditable = n), i++);
|
|
1374
|
+
} else if (a.children.length > 0) {
|
|
1179
1375
|
for (; i < r.length;) {
|
|
1180
|
-
let e =
|
|
1181
|
-
if (!
|
|
1376
|
+
let e = M(t, i);
|
|
1377
|
+
if (e && !tt(e)) break;
|
|
1182
1378
|
i++;
|
|
1183
1379
|
}
|
|
1184
|
-
let e =
|
|
1185
|
-
e && (this.#n(
|
|
1380
|
+
let e = M(t, i);
|
|
1381
|
+
e && (this.#n(a.children, e, n), i++);
|
|
1186
1382
|
}
|
|
1187
1383
|
}
|
|
1188
1384
|
#r(e, t, n) {
|
|
1189
|
-
let r = n ? "false" : "true"
|
|
1190
|
-
for (let
|
|
1191
|
-
let a = i
|
|
1385
|
+
let r = n ? "false" : "true";
|
|
1386
|
+
for (let i = 0; i < e.length; i++) {
|
|
1387
|
+
let a = e[i], o = M(t, i);
|
|
1192
1388
|
if (!o) continue;
|
|
1193
|
-
if (a.
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
t && this.#n(e.children, t, r);
|
|
1389
|
+
if (a.type === "mark") {
|
|
1390
|
+
if (a.children.length > 0) {
|
|
1391
|
+
let e = o.hasAttribute("data-testid") ? M(o, n ? 0 : 1) : o;
|
|
1392
|
+
e && this.#n(a.children, e, r);
|
|
1198
1393
|
}
|
|
1199
1394
|
continue;
|
|
1200
1395
|
}
|
|
1201
|
-
let s = n ? 0 : 1;
|
|
1202
|
-
|
|
1203
|
-
let t = a.tokens[e], n = o.children[e + s];
|
|
1204
|
-
n && t.type === "text" && n.textContent !== t.content && (n.textContent = t.content);
|
|
1205
|
-
}
|
|
1396
|
+
let s = M(o, n ? 0 : 1);
|
|
1397
|
+
s && s.textContent !== a.content && (s.textContent = a.content);
|
|
1206
1398
|
}
|
|
1207
1399
|
}
|
|
1208
|
-
}
|
|
1400
|
+
};
|
|
1401
|
+
//#endregion
|
|
1402
|
+
//#region ../../common/core/src/features/editing/utils/createNewSpan.ts
|
|
1403
|
+
function rt(e, t, n, r) {
|
|
1404
|
+
return e.slice(0, n) + t + e.slice(n + r.length);
|
|
1405
|
+
}
|
|
1406
|
+
//#endregion
|
|
1407
|
+
//#region ../../common/core/src/features/editing/utils/deleteMark.ts
|
|
1408
|
+
function B(e, t) {
|
|
1409
|
+
let n = {
|
|
1410
|
+
prev: 2,
|
|
1411
|
+
self: 1,
|
|
1412
|
+
next: 0
|
|
1413
|
+
}[e], { focus: r } = t.nodes, i = t.state.tokens.get(), a = i.splice(r.index - n, 3), o = a.at(0), s = a.at(2), c = o?.content ?? "", l = s?.content ?? "";
|
|
1414
|
+
t.state.tokens.set(i.toSpliced(r.index - n, 0, {
|
|
1415
|
+
type: "text",
|
|
1416
|
+
content: c + l,
|
|
1417
|
+
position: {
|
|
1418
|
+
start: o?.position.start ?? 0,
|
|
1419
|
+
end: s?.position.end ?? (c + l).length
|
|
1420
|
+
}
|
|
1421
|
+
}));
|
|
1422
|
+
let u = r;
|
|
1423
|
+
for (let e = 0; e < n; e++) u = u.prev;
|
|
1424
|
+
let d = u.length;
|
|
1425
|
+
t.state.recovery.set({
|
|
1426
|
+
anchor: u.prev,
|
|
1427
|
+
caret: d
|
|
1428
|
+
}), t.state.onChange.get()?.(T(t.state.tokens.get()));
|
|
1429
|
+
}
|
|
1430
|
+
//#endregion
|
|
1431
|
+
//#region ../../common/core/src/features/events/SystemListenerController.ts
|
|
1432
|
+
var it = class {
|
|
1209
1433
|
#e;
|
|
1210
1434
|
#t;
|
|
1211
1435
|
#n;
|
|
@@ -1216,41 +1440,41 @@ var Ie = class {
|
|
|
1216
1440
|
this.#e || (this.#e = this.store.events.change.on(() => {
|
|
1217
1441
|
let e = this.store.state.onChange.get(), { focus: t } = this.store.nodes;
|
|
1218
1442
|
if (!t.target || !t.target.isContentEditable) {
|
|
1219
|
-
let t = this.store.state.tokens.get(), n =
|
|
1443
|
+
let t = this.store.state.tokens.get(), n = T(t);
|
|
1220
1444
|
e?.(n), this.store.state.previousValue.set(n), this.store.state.tokens.set([...t]);
|
|
1221
1445
|
return;
|
|
1222
1446
|
}
|
|
1223
1447
|
let n = this.store.state.tokens.get(), r = n[t.index];
|
|
1224
|
-
r.type === "text" ? r.content = t.content : r.
|
|
1448
|
+
r.type === "text" ? r.content = t.content : r.value = t.content, e?.(T(n)), this.store.events.parse();
|
|
1225
1449
|
}), this.#t = this.store.events.delete.on((e) => {
|
|
1226
|
-
if (!e) return;
|
|
1227
1450
|
let { token: t } = e, n = this.store.state.onChange.get(), r = this.store.state.tokens.get(), i = r.indexOf(t);
|
|
1228
|
-
this.store.state.tokens.set(r.toSpliced(i, 1)), n?.(
|
|
1451
|
+
this.store.state.tokens.set(r.toSpliced(i, 1)), n?.(T(this.store.state.tokens.get()));
|
|
1229
1452
|
}), this.#n = this.store.events.select.on((e) => {
|
|
1230
|
-
|
|
1231
|
-
|
|
1453
|
+
let t = this.store.state.Mark.get(), n = this.store.state.onChange.get(), { mark: r, match: { option: i, span: a, index: o, source: s } } = e, c = i.markup;
|
|
1454
|
+
if (!c) return;
|
|
1455
|
+
let l = r.type === "mark" ? w(c, {
|
|
1232
1456
|
value: r.value,
|
|
1233
1457
|
meta: r.meta
|
|
1234
|
-
}) :
|
|
1458
|
+
}) : w(c, { value: r.content }), u = rt(a, l, o, s);
|
|
1235
1459
|
if (this.store.state.recovery.set(t ? {
|
|
1236
1460
|
caret: 0,
|
|
1237
1461
|
anchor: this.store.nodes.input.next,
|
|
1238
1462
|
isNext: !0,
|
|
1239
1463
|
childIndex: this.store.nodes.input.index
|
|
1240
1464
|
} : {
|
|
1241
|
-
caret: o +
|
|
1465
|
+
caret: o + l.length,
|
|
1242
1466
|
anchor: this.store.nodes.input
|
|
1243
1467
|
}), this.store.nodes.input.target) {
|
|
1244
|
-
this.store.nodes.input.content =
|
|
1468
|
+
this.store.nodes.input.content = u;
|
|
1245
1469
|
let e = this.store.state.tokens.get(), t = e[this.store.nodes.input.index];
|
|
1246
|
-
t.type === "text" && (t.content =
|
|
1470
|
+
t.type === "text" && (t.content = u), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(T(e)), this.store.events.parse();
|
|
1247
1471
|
}
|
|
1248
1472
|
}));
|
|
1249
1473
|
}
|
|
1250
1474
|
disable() {
|
|
1251
1475
|
this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = void 0, this.#n = void 0;
|
|
1252
1476
|
}
|
|
1253
|
-
},
|
|
1477
|
+
}, at = class {
|
|
1254
1478
|
#e;
|
|
1255
1479
|
#t;
|
|
1256
1480
|
#n;
|
|
@@ -1261,17 +1485,21 @@ var Ie = class {
|
|
|
1261
1485
|
if (this.#e) return;
|
|
1262
1486
|
let e = this.store.refs.container;
|
|
1263
1487
|
e && (this.#e = (e) => {
|
|
1264
|
-
|
|
1488
|
+
let t = A(e.target) ? e.target : void 0;
|
|
1489
|
+
this.store.nodes.focus.target = t;
|
|
1265
1490
|
}, this.#t = () => {
|
|
1266
1491
|
this.store.nodes.focus.target = void 0;
|
|
1267
1492
|
}, this.#n = () => {
|
|
1268
1493
|
let e = this.store.state.tokens.get();
|
|
1269
|
-
e.length === 1 && e[0].type === "text" && e[0].content === ""
|
|
1494
|
+
if (e.length === 1 && e[0].type === "text" && e[0].content === "") {
|
|
1495
|
+
let e = this.store.refs.container;
|
|
1496
|
+
(e ? Ve(e) : null)?.focus();
|
|
1497
|
+
}
|
|
1270
1498
|
}, e.addEventListener("focusin", this.#e), e.addEventListener("focusout", this.#t), e.addEventListener("click", this.#n));
|
|
1271
1499
|
}
|
|
1272
1500
|
disable() {
|
|
1273
1501
|
let e = this.store.refs.container;
|
|
1274
|
-
!e || !this.#e || (e.removeEventListener("focusin", this.#e), e.removeEventListener("focusout", this.#t), e.removeEventListener("click", this.#n), this.#e = void 0, this.#t = void 0, this.#n = void 0);
|
|
1502
|
+
!e || !this.#e || (e.removeEventListener("focusin", this.#e), this.#t && e.removeEventListener("focusout", this.#t), this.#n && e.removeEventListener("click", this.#n), this.#e = void 0, this.#t = void 0, this.#n = void 0);
|
|
1275
1503
|
}
|
|
1276
1504
|
recover() {
|
|
1277
1505
|
let e = this.store.state.recovery.get();
|
|
@@ -1279,15 +1507,15 @@ var Ie = class {
|
|
|
1279
1507
|
let { anchor: t, caret: n, isNext: r } = e, i = !t.target || !t.target.isConnected;
|
|
1280
1508
|
switch (!0) {
|
|
1281
1509
|
case r && i: {
|
|
1282
|
-
let t = this.store.refs.container, n = e.childIndex == null ? void 0 : t
|
|
1283
|
-
n ? n.focus() : this.store.nodes.focus.tail
|
|
1510
|
+
let t = this.store.refs.container, n = e.childIndex == null ? void 0 : M(t, e.childIndex + 2);
|
|
1511
|
+
n ? n.focus() : this.store.nodes.focus.tail?.focus();
|
|
1284
1512
|
break;
|
|
1285
1513
|
}
|
|
1286
1514
|
case r:
|
|
1287
1515
|
t.prev.focus();
|
|
1288
1516
|
break;
|
|
1289
1517
|
case i:
|
|
1290
|
-
this.store.nodes.focus.head
|
|
1518
|
+
this.store.nodes.focus.head?.focus();
|
|
1291
1519
|
break;
|
|
1292
1520
|
default: t.next.focus();
|
|
1293
1521
|
}
|
|
@@ -1296,29 +1524,29 @@ var Ie = class {
|
|
|
1296
1524
|
};
|
|
1297
1525
|
//#endregion
|
|
1298
1526
|
//#region ../../common/core/src/features/navigation/navigation.ts
|
|
1299
|
-
function
|
|
1527
|
+
function ot(e, t) {
|
|
1300
1528
|
let { focus: n } = e.nodes;
|
|
1301
1529
|
if (n.isMark && !n.isEditable || n.isCaretAtBeginning) {
|
|
1302
1530
|
let e = n.prev;
|
|
1303
1531
|
for (; e.target && e.isMark && !e.isEditable;) e = e.prev;
|
|
1304
|
-
return e.target ? (t.preventDefault(), e.target.focus(),
|
|
1532
|
+
return e.target ? (t.preventDefault(), e.target.focus(), F.setCaretToEnd(e.target), !0) : !1;
|
|
1305
1533
|
}
|
|
1306
1534
|
return !1;
|
|
1307
1535
|
}
|
|
1308
|
-
function
|
|
1536
|
+
function st(e, t) {
|
|
1309
1537
|
let { focus: n } = e.nodes;
|
|
1310
1538
|
if (n.isMark && !n.isEditable || n.isCaretAtEnd) {
|
|
1311
1539
|
let e = n.next;
|
|
1312
1540
|
for (; e.target && e.isMark && !e.isEditable;) e = e.next;
|
|
1313
|
-
return e.target ? (t.preventDefault(), e.target.focus(),
|
|
1541
|
+
return e.target ? (t.preventDefault(), e.target.focus(), F.trySetIndex(e.target, 0), !0) : !1;
|
|
1314
1542
|
}
|
|
1315
1543
|
return !1;
|
|
1316
1544
|
}
|
|
1317
1545
|
//#endregion
|
|
1318
1546
|
//#region ../../common/core/src/features/selection/selectionHelpers.ts
|
|
1319
|
-
function
|
|
1547
|
+
function ct(e) {
|
|
1320
1548
|
let t = window.getSelection(), n = e.refs.container;
|
|
1321
|
-
if (!t?.rangeCount || !n?.firstChild || !n
|
|
1549
|
+
if (!t?.rangeCount || !n?.firstChild || !n.lastChild) return !1;
|
|
1322
1550
|
try {
|
|
1323
1551
|
let e = t.getRangeAt(0);
|
|
1324
1552
|
return n.contains(e.startContainer) && n.contains(e.endContainer) && e.toString().length > 0;
|
|
@@ -1326,7 +1554,7 @@ function Ve(e) {
|
|
|
1326
1554
|
return !1;
|
|
1327
1555
|
}
|
|
1328
1556
|
}
|
|
1329
|
-
function
|
|
1557
|
+
function lt(e, t) {
|
|
1330
1558
|
if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
|
|
1331
1559
|
if (e.state.drag.get()) return;
|
|
1332
1560
|
t.preventDefault();
|
|
@@ -1337,7 +1565,7 @@ function He(e, t) {
|
|
|
1337
1565
|
}
|
|
1338
1566
|
//#endregion
|
|
1339
1567
|
//#region ../../common/core/src/features/selection/TextSelectionController.ts
|
|
1340
|
-
var
|
|
1568
|
+
var ut = class {
|
|
1341
1569
|
#e;
|
|
1342
1570
|
#t;
|
|
1343
1571
|
#n;
|
|
@@ -1349,236 +1577,275 @@ var Ue = class {
|
|
|
1349
1577
|
}
|
|
1350
1578
|
enable() {
|
|
1351
1579
|
this.#e || (this.#e = (e) => {
|
|
1352
|
-
this.#i = e
|
|
1580
|
+
this.#i = Ue(e), this.#a = !0;
|
|
1353
1581
|
}, this.#t = (e) => {
|
|
1354
|
-
let t = this
|
|
1355
|
-
|
|
1582
|
+
let t = this.store.refs.container;
|
|
1583
|
+
if (!t) return;
|
|
1584
|
+
let n = this.#a, r = !t.contains(this.#i) || this.#i !== e.target, i = window.getSelection()?.containsNode(t, !0);
|
|
1585
|
+
n && r && i && this.store.state.selecting.set("drag");
|
|
1356
1586
|
}, this.#n = () => {
|
|
1357
1587
|
this.#a = !1, this.#i = null, this.store.state.selecting.set(void 0);
|
|
1358
1588
|
}, this.#r = () => {
|
|
1359
1589
|
if (this.store.state.selecting.get() !== "drag") return;
|
|
1360
|
-
let e =
|
|
1361
|
-
|
|
1590
|
+
let e = this.store.refs.container;
|
|
1591
|
+
if (!e) return;
|
|
1592
|
+
let t = N(e), n = t.map((e) => e.contentEditable);
|
|
1593
|
+
t.forEach((e) => e.contentEditable = "false"), t.forEach((e, t) => e.contentEditable = n[t]);
|
|
1362
1594
|
}, document.addEventListener("mousedown", this.#e), document.addEventListener("mousemove", this.#t), document.addEventListener("mouseup", this.#n), document.addEventListener("selectionchange", this.#r));
|
|
1363
1595
|
}
|
|
1364
1596
|
disable() {
|
|
1365
|
-
this.#e && (document.removeEventListener("mousedown", this.#e), document.removeEventListener("mousemove", this.#t), document.removeEventListener("mouseup", this.#n), document.removeEventListener("selectionchange", this.#r), this.#e = void 0, this.#t = void 0, this.#n = void 0, this.#r = void 0), this.#i = null, this.#a = !1;
|
|
1597
|
+
this.#e && (document.removeEventListener("mousedown", this.#e), this.#t && document.removeEventListener("mousemove", this.#t), this.#n && document.removeEventListener("mouseup", this.#n), this.#r && document.removeEventListener("selectionchange", this.#r), this.#e = void 0, this.#t = void 0, this.#n = void 0, this.#r = void 0), this.#i = null, this.#a = !1;
|
|
1366
1598
|
}
|
|
1367
|
-
}
|
|
1599
|
+
};
|
|
1600
|
+
//#endregion
|
|
1601
|
+
//#region ../../common/core/src/features/input/KeyDownController.ts
|
|
1602
|
+
function dt(e) {
|
|
1603
|
+
return e.type === "text" ? !0 : e.descriptor.hasSlot && e.descriptor.segments.length === 1;
|
|
1604
|
+
}
|
|
1605
|
+
var ft = class {
|
|
1368
1606
|
#e;
|
|
1369
1607
|
#t;
|
|
1370
1608
|
#n;
|
|
1371
1609
|
constructor(e) {
|
|
1372
1610
|
this.store = e;
|
|
1373
1611
|
}
|
|
1612
|
+
#r() {
|
|
1613
|
+
let e = this.store.state.options.get()?.[0];
|
|
1614
|
+
return e?.markup ? w(e.markup, {
|
|
1615
|
+
value: "",
|
|
1616
|
+
slot: "",
|
|
1617
|
+
meta: ""
|
|
1618
|
+
}) : "\n";
|
|
1619
|
+
}
|
|
1374
1620
|
enable() {
|
|
1375
1621
|
if (this.#e) return;
|
|
1376
1622
|
let e = this.store.refs.container;
|
|
1377
1623
|
e && (this.#e = (e) => {
|
|
1378
|
-
e.key ===
|
|
1624
|
+
e.key === y.LEFT ? this.#o(e, "left") || ot(this.store, e) : e.key === y.RIGHT ? this.#o(e, "right") || st(this.store, e) : (e.key === y.UP || e.key === y.DOWN) && this.#s(e), this.#i(e), this.#a(e), lt(this.store, e);
|
|
1379
1625
|
}, this.#t = (e) => {
|
|
1380
|
-
|
|
1626
|
+
ht(this.store, e);
|
|
1381
1627
|
}, this.#n = (e) => {
|
|
1382
|
-
|
|
1628
|
+
pt(this.store, e);
|
|
1383
1629
|
}, e.addEventListener("keydown", this.#e), e.addEventListener("paste", this.#t), e.addEventListener("beforeinput", this.#n, !0));
|
|
1384
1630
|
}
|
|
1385
1631
|
disable() {
|
|
1386
1632
|
let e = this.store.refs.container;
|
|
1387
|
-
!e || !this.#e || (e.removeEventListener("keydown", this.#e), e.removeEventListener("paste", this.#t), e.removeEventListener("beforeinput", this.#n, !0), this.#e = void 0, this.#t = void 0, this.#n = void 0);
|
|
1633
|
+
!e || !this.#e || (e.removeEventListener("keydown", this.#e), this.#t && e.removeEventListener("paste", this.#t), this.#n && e.removeEventListener("beforeinput", this.#n, !0), this.#e = void 0, this.#t = void 0, this.#n = void 0);
|
|
1388
1634
|
}
|
|
1389
|
-
#
|
|
1635
|
+
#i(e) {
|
|
1390
1636
|
let { focus: t } = this.store.nodes, n = !!this.store.state.drag.get();
|
|
1391
|
-
if (!n && (e.key ===
|
|
1637
|
+
if (!n && (e.key === y.DELETE || e.key === y.BACKSPACE)) {
|
|
1392
1638
|
if (t.isMark) {
|
|
1393
|
-
if (t.isEditable && (e.key ===
|
|
1394
|
-
e.preventDefault(),
|
|
1639
|
+
if (t.isEditable && (e.key === y.BACKSPACE && !t.isCaretAtBeginning || e.key === y.DELETE && !t.isCaretAtEnd)) return;
|
|
1640
|
+
e.preventDefault(), B("self", this.store);
|
|
1395
1641
|
return;
|
|
1396
1642
|
}
|
|
1397
|
-
if (e.key ===
|
|
1398
|
-
e.preventDefault(),
|
|
1643
|
+
if (e.key === y.BACKSPACE && t.isSpan && t.isCaretAtBeginning && t.prev.target) {
|
|
1644
|
+
e.preventDefault(), B("prev", this.store);
|
|
1399
1645
|
return;
|
|
1400
1646
|
}
|
|
1401
|
-
if (e.key ===
|
|
1402
|
-
e.preventDefault(),
|
|
1647
|
+
if (e.key === y.DELETE && t.isSpan && t.isCaretAtEnd && t.next.target) {
|
|
1648
|
+
e.preventDefault(), B("next", this.store);
|
|
1403
1649
|
return;
|
|
1404
1650
|
}
|
|
1405
1651
|
}
|
|
1406
1652
|
if (!n) return;
|
|
1407
1653
|
let r = this.store.refs.container;
|
|
1408
1654
|
if (!r) return;
|
|
1409
|
-
let i =
|
|
1655
|
+
let i = N(r), a = i.findIndex((e) => e === document.activeElement || e.contains(document.activeElement));
|
|
1410
1656
|
if (a === -1) return;
|
|
1411
|
-
let o =
|
|
1657
|
+
let o = this.store.state.tokens.get();
|
|
1412
1658
|
if (a >= o.length) return;
|
|
1413
1659
|
let s = o[a], c = this.store.state.previousValue.get() ?? this.store.state.value.get() ?? "";
|
|
1414
1660
|
if (this.store.state.onChange.get()) {
|
|
1415
|
-
if (e.key ===
|
|
1416
|
-
let t = i[a], n =
|
|
1417
|
-
if (
|
|
1661
|
+
if (e.key === y.BACKSPACE) {
|
|
1662
|
+
let t = i[a], n = F.getCaretIndex(t) === 0;
|
|
1663
|
+
if (("content" in s ? s.content : "") === "") {
|
|
1418
1664
|
e.preventDefault();
|
|
1419
|
-
let t = o.length <= 1 ? "" : a >= o.length - 1 ? c.slice(0, o[a - 1].
|
|
1665
|
+
let t = o.length <= 1 ? "" : a >= o.length - 1 ? c.slice(0, o[a - 1].position.end) : c.slice(0, o[a].position.start) + c.slice(o[a + 1].position.start);
|
|
1420
1666
|
this.store.applyValue(t), queueMicrotask(() => {
|
|
1421
|
-
let e = r
|
|
1422
|
-
e && (e.focus(),
|
|
1667
|
+
let e = M(r, Math.max(0, a - 1));
|
|
1668
|
+
e && (e.focus(), F.setCaretToEnd(e));
|
|
1423
1669
|
});
|
|
1424
1670
|
return;
|
|
1425
1671
|
}
|
|
1426
1672
|
if (n && a > 0) {
|
|
1427
|
-
let t = o[a - 1], n = o[a]
|
|
1428
|
-
if (
|
|
1673
|
+
let t = o[a - 1], n = o[a];
|
|
1674
|
+
if (L(t, n)) {
|
|
1429
1675
|
e.preventDefault();
|
|
1430
|
-
let t =
|
|
1676
|
+
let t = R(o, a), n = z(c, o, a);
|
|
1431
1677
|
this.store.applyValue(n), queueMicrotask(() => {
|
|
1432
|
-
let e = r
|
|
1678
|
+
let e = M(r, a - 1);
|
|
1433
1679
|
if (e) {
|
|
1434
1680
|
e.focus();
|
|
1435
|
-
let n =
|
|
1436
|
-
|
|
1681
|
+
let n = this.store.state.tokens.get()[a - 1];
|
|
1682
|
+
H(e, n, t);
|
|
1437
1683
|
}
|
|
1438
1684
|
});
|
|
1439
1685
|
return;
|
|
1440
1686
|
}
|
|
1441
1687
|
e.preventDefault(), queueMicrotask(() => {
|
|
1442
1688
|
let e = i[a - 1];
|
|
1443
|
-
e
|
|
1689
|
+
e.focus(), t.type !== "mark" && F.setCaretToEnd(e);
|
|
1444
1690
|
});
|
|
1445
1691
|
return;
|
|
1446
1692
|
}
|
|
1447
1693
|
}
|
|
1448
|
-
if (e.key ===
|
|
1449
|
-
let t = i[a], n =
|
|
1694
|
+
if (e.key === y.DELETE) {
|
|
1695
|
+
let t = i[a], n = F.getCaretIndex(t), s = n === t.textContent.length;
|
|
1450
1696
|
if (n === 0 && a > 0) {
|
|
1451
|
-
let t = o[a - 1], n = o[a]
|
|
1452
|
-
if (
|
|
1697
|
+
let t = o[a - 1], n = o[a];
|
|
1698
|
+
if (L(t, n)) {
|
|
1453
1699
|
e.preventDefault();
|
|
1454
|
-
let t =
|
|
1700
|
+
let t = R(o, a), n = z(c, o, a);
|
|
1455
1701
|
this.store.applyValue(n), queueMicrotask(() => {
|
|
1456
|
-
let e = r
|
|
1702
|
+
let e = M(r, a - 1);
|
|
1457
1703
|
if (e) {
|
|
1458
1704
|
e.focus();
|
|
1459
|
-
let n =
|
|
1460
|
-
|
|
1705
|
+
let n = this.store.state.tokens.get()[a - 1];
|
|
1706
|
+
H(e, n, t);
|
|
1461
1707
|
}
|
|
1462
1708
|
});
|
|
1463
1709
|
return;
|
|
1464
1710
|
}
|
|
1465
1711
|
e.preventDefault(), queueMicrotask(() => {
|
|
1466
1712
|
let e = i[a - 1];
|
|
1467
|
-
e
|
|
1713
|
+
e.focus(), t.type !== "mark" && F.setCaretToEnd(e);
|
|
1468
1714
|
});
|
|
1469
1715
|
return;
|
|
1470
1716
|
}
|
|
1471
1717
|
if (s && a < o.length - 1) {
|
|
1472
|
-
let t = o[a], n = o[a + 1]
|
|
1473
|
-
if (
|
|
1718
|
+
let t = o[a], n = o[a + 1];
|
|
1719
|
+
if (L(t, n)) {
|
|
1474
1720
|
e.preventDefault();
|
|
1475
|
-
let
|
|
1476
|
-
this.store.applyValue(
|
|
1477
|
-
let e = r
|
|
1721
|
+
let t = R(o, a + 1), n = z(c, o, a + 1);
|
|
1722
|
+
this.store.applyValue(n), queueMicrotask(() => {
|
|
1723
|
+
let e = M(r, a);
|
|
1478
1724
|
if (e) {
|
|
1479
1725
|
e.focus();
|
|
1480
|
-
let
|
|
1481
|
-
|
|
1726
|
+
let n = this.store.state.tokens.get()[a];
|
|
1727
|
+
H(e, n, t);
|
|
1482
1728
|
}
|
|
1483
1729
|
});
|
|
1484
1730
|
return;
|
|
1485
1731
|
}
|
|
1486
1732
|
e.preventDefault(), queueMicrotask(() => {
|
|
1487
1733
|
let e = i[a + 1];
|
|
1488
|
-
e
|
|
1734
|
+
e.focus(), F.trySetIndex(e, 0);
|
|
1489
1735
|
});
|
|
1490
1736
|
return;
|
|
1491
1737
|
}
|
|
1492
1738
|
}
|
|
1493
1739
|
}
|
|
1494
1740
|
}
|
|
1495
|
-
#
|
|
1496
|
-
if (!this.store.state.drag.get() || e.key !==
|
|
1741
|
+
#a(e) {
|
|
1742
|
+
if (!this.store.state.drag.get() || e.key !== y.ENTER || e.shiftKey) return;
|
|
1497
1743
|
let t = this.store.refs.container;
|
|
1498
1744
|
if (!t) return;
|
|
1499
1745
|
let n = document.activeElement;
|
|
1500
|
-
if (!n || !t.contains(n)) return;
|
|
1746
|
+
if (!A(n) || !t.contains(n)) return;
|
|
1501
1747
|
e.preventDefault();
|
|
1502
|
-
let r = t
|
|
1748
|
+
let r = N(t), i = -1;
|
|
1503
1749
|
for (let e = 0; e < r.length; e++) if (r[e] === n || r[e].contains(n)) {
|
|
1504
1750
|
i = e;
|
|
1505
1751
|
break;
|
|
1506
1752
|
}
|
|
1507
1753
|
if (i === -1) return;
|
|
1508
|
-
let a =
|
|
1509
|
-
if (!o) return;
|
|
1510
|
-
let s = r[i], c = this.store.state.previousValue.get() ?? this.store.state.value.get() ?? "";
|
|
1754
|
+
let a = this.store.state.tokens.get(), o = a[i], s = r[i], c = this.store.state.previousValue.get() ?? this.store.state.value.get() ?? "";
|
|
1511
1755
|
if (!this.store.state.onChange.get()) return;
|
|
1512
|
-
|
|
1513
|
-
|
|
1756
|
+
let l = this.#r();
|
|
1757
|
+
if (!dt(o)) {
|
|
1758
|
+
let e = Je(c, a, i, l);
|
|
1514
1759
|
this.store.applyValue(e), queueMicrotask(() => {
|
|
1515
|
-
let e =
|
|
1516
|
-
if (
|
|
1517
|
-
let
|
|
1518
|
-
|
|
1760
|
+
let e = i + 1;
|
|
1761
|
+
if (e < t.children.length) {
|
|
1762
|
+
let n = M(t, e);
|
|
1763
|
+
n && (n.focus(), F.trySetIndex(n, 0));
|
|
1519
1764
|
}
|
|
1520
1765
|
});
|
|
1521
1766
|
return;
|
|
1522
1767
|
}
|
|
1523
|
-
let
|
|
1768
|
+
let u = V(s, o), d = c.slice(0, u) + l + c.slice(u);
|
|
1524
1769
|
this.store.applyValue(d), queueMicrotask(() => {
|
|
1525
|
-
let e =
|
|
1526
|
-
if (
|
|
1527
|
-
let
|
|
1528
|
-
|
|
1770
|
+
let e = i + 1;
|
|
1771
|
+
if (e < t.children.length) {
|
|
1772
|
+
let n = M(t, e);
|
|
1773
|
+
n && (n.focus(), F.trySetIndex(n, 0));
|
|
1529
1774
|
}
|
|
1530
1775
|
});
|
|
1531
1776
|
}
|
|
1532
|
-
#
|
|
1777
|
+
#o(e, t) {
|
|
1778
|
+
if (!this.store.state.drag.get()) return !1;
|
|
1779
|
+
let n = this.store.refs.container;
|
|
1780
|
+
if (!n) return !1;
|
|
1781
|
+
let r = document.activeElement;
|
|
1782
|
+
if (!A(r) || !n.contains(r)) return !1;
|
|
1783
|
+
let i = N(n), a = i.findIndex((e) => e === r || e.contains(r));
|
|
1784
|
+
if (a === -1) return !1;
|
|
1785
|
+
let o = i[a];
|
|
1786
|
+
if (t === "left") {
|
|
1787
|
+
if (F.getCaretIndex(o) !== 0) return !1;
|
|
1788
|
+
if (a === 0) return !0;
|
|
1789
|
+
e.preventDefault();
|
|
1790
|
+
let t = i[a - 1];
|
|
1791
|
+
return t.focus(), F.setCaretToEnd(t), !0;
|
|
1792
|
+
}
|
|
1793
|
+
if (F.getCaretIndex(o) !== o.textContent.length) return !1;
|
|
1794
|
+
if (a >= i.length - 1) return !0;
|
|
1795
|
+
e.preventDefault();
|
|
1796
|
+
let s = i[a + 1];
|
|
1797
|
+
return s.focus(), F.trySetIndex(s, 0), !0;
|
|
1798
|
+
}
|
|
1799
|
+
#s(e) {
|
|
1533
1800
|
if (!this.store.state.drag.get()) return;
|
|
1534
1801
|
let t = this.store.refs.container;
|
|
1535
1802
|
if (!t) return;
|
|
1536
1803
|
let n = document.activeElement;
|
|
1537
|
-
if (!n || !t.contains(n)) return;
|
|
1538
|
-
let r =
|
|
1804
|
+
if (!A(n) || !t.contains(n)) return;
|
|
1805
|
+
let r = N(t), i = r.findIndex((e) => e === n || e.contains(n));
|
|
1539
1806
|
if (i === -1) return;
|
|
1540
1807
|
let a = r[i];
|
|
1541
|
-
if (e.key ===
|
|
1542
|
-
if (!
|
|
1808
|
+
if (e.key === y.UP) {
|
|
1809
|
+
if (!F.isCaretOnFirstLine(a) || i === 0) return;
|
|
1543
1810
|
e.preventDefault();
|
|
1544
|
-
let t =
|
|
1811
|
+
let t = F.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i - 1];
|
|
1545
1812
|
n.focus();
|
|
1546
1813
|
let o = n.getBoundingClientRect();
|
|
1547
|
-
|
|
1548
|
-
} else if (e.key ===
|
|
1549
|
-
if (!
|
|
1814
|
+
F.setAtX(n, t, o.bottom - 4);
|
|
1815
|
+
} else if (e.key === y.DOWN) {
|
|
1816
|
+
if (!F.isCaretOnLastLine(a) || i >= r.length - 1) return;
|
|
1550
1817
|
e.preventDefault();
|
|
1551
|
-
let t =
|
|
1818
|
+
let t = F.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i + 1];
|
|
1552
1819
|
n.focus();
|
|
1553
1820
|
let o = n.getBoundingClientRect();
|
|
1554
|
-
|
|
1821
|
+
F.setAtX(n, t, o.top + 4);
|
|
1555
1822
|
}
|
|
1556
1823
|
}
|
|
1557
1824
|
};
|
|
1558
|
-
function
|
|
1825
|
+
function V(e, t) {
|
|
1559
1826
|
let n = window.getSelection();
|
|
1560
|
-
if (!n?.rangeCount) return t.
|
|
1827
|
+
if (!n?.rangeCount) return t.position.end;
|
|
1561
1828
|
let { focusNode: r, focusOffset: i } = n;
|
|
1562
|
-
return r ?
|
|
1829
|
+
return r ? U(r, i, e, t) : t.position.end;
|
|
1563
1830
|
}
|
|
1564
|
-
function
|
|
1831
|
+
function pt(e, t) {
|
|
1565
1832
|
let n = e.state.selecting.get();
|
|
1566
|
-
if (n === "all" &&
|
|
1833
|
+
if (n === "all" && ct(e)) {
|
|
1567
1834
|
if (t.inputType === "insertFromPaste") {
|
|
1568
1835
|
t.preventDefault();
|
|
1569
1836
|
return;
|
|
1570
1837
|
}
|
|
1571
|
-
t.preventDefault(),
|
|
1838
|
+
t.preventDefault(), gt(e, t.inputType.startsWith("delete") ? "" : t.data ?? "");
|
|
1572
1839
|
return;
|
|
1573
1840
|
}
|
|
1574
1841
|
if (n === "all" && e.state.selecting.set(void 0), e.state.drag.get()) {
|
|
1575
|
-
|
|
1842
|
+
_t(e, t);
|
|
1576
1843
|
return;
|
|
1577
1844
|
}
|
|
1578
1845
|
let { focus: r } = e.nodes;
|
|
1579
|
-
!r.target || !r.isEditable ||
|
|
1846
|
+
!r.target || !r.isEditable || mt(r, t) && e.events.change();
|
|
1580
1847
|
}
|
|
1581
|
-
function
|
|
1848
|
+
function mt(e, t) {
|
|
1582
1849
|
let n = e.caret, r = e.content, i, a;
|
|
1583
1850
|
switch (t.inputType) {
|
|
1584
1851
|
case "insertText": {
|
|
@@ -1610,15 +1877,15 @@ function qe(e, t) {
|
|
|
1610
1877
|
}
|
|
1611
1878
|
return e.content = i, e.caret = a, !0;
|
|
1612
1879
|
}
|
|
1613
|
-
function
|
|
1880
|
+
function ht(e, t) {
|
|
1614
1881
|
let n = e.state.selecting.get();
|
|
1615
|
-
if (n !== "all" || !
|
|
1882
|
+
if (n !== "all" || !ct(e)) {
|
|
1616
1883
|
n === "all" && e.state.selecting.set(void 0);
|
|
1617
1884
|
return;
|
|
1618
1885
|
}
|
|
1619
|
-
t.preventDefault(),
|
|
1886
|
+
t.preventDefault(), gt(e, t.clipboardData?.getData("text/plain") ?? "");
|
|
1620
1887
|
}
|
|
1621
|
-
function
|
|
1888
|
+
function gt(e, t) {
|
|
1622
1889
|
e.nodes.focus.target = null, e.state.selecting.set(void 0), e.state.onChange.get()?.(t), e.state.value.get() === void 0 && e.state.tokens.set(e.state.parser.get()?.parse(t) ?? [{
|
|
1623
1890
|
type: "text",
|
|
1624
1891
|
content: t,
|
|
@@ -1627,29 +1894,29 @@ function Ye(e, t) {
|
|
|
1627
1894
|
end: t.length
|
|
1628
1895
|
}
|
|
1629
1896
|
}]), queueMicrotask(() => {
|
|
1630
|
-
let n = e.refs.container?.firstChild;
|
|
1631
|
-
|
|
1897
|
+
let n = e.refs.container?.firstChild, r = A(n) ? n : null;
|
|
1898
|
+
r && (e.state.recovery.set({
|
|
1632
1899
|
anchor: e.nodes.focus,
|
|
1633
1900
|
caret: t.length
|
|
1634
|
-
}),
|
|
1901
|
+
}), r.focus());
|
|
1635
1902
|
});
|
|
1636
1903
|
}
|
|
1637
|
-
function
|
|
1904
|
+
function _t(e, t) {
|
|
1638
1905
|
let n = e.refs.container;
|
|
1639
1906
|
if (!n) return;
|
|
1640
1907
|
let r = document.activeElement;
|
|
1641
|
-
if (!r || !n.contains(r)) return;
|
|
1642
|
-
let i =
|
|
1908
|
+
if (!A(r) || !n.contains(r)) return;
|
|
1909
|
+
let i = N(n), a = i.findIndex((e) => e === r || e.contains(r));
|
|
1643
1910
|
if (a === -1) return;
|
|
1644
|
-
let o = i[a], s =
|
|
1911
|
+
let o = i[a], s = e.state.tokens.get();
|
|
1645
1912
|
if (a >= s.length) return;
|
|
1646
1913
|
let c = s[a], l = e.state.previousValue.get() ?? e.state.value.get() ?? "", u = (t) => {
|
|
1647
1914
|
queueMicrotask(() => {
|
|
1648
|
-
let r = n
|
|
1915
|
+
let r = M(n, a);
|
|
1649
1916
|
if (!r) return;
|
|
1650
1917
|
r.focus();
|
|
1651
|
-
let i =
|
|
1652
|
-
|
|
1918
|
+
let i = e.state.tokens.get()[a];
|
|
1919
|
+
H(r, i, t);
|
|
1653
1920
|
});
|
|
1654
1921
|
};
|
|
1655
1922
|
switch (t.inputType) {
|
|
@@ -1657,9 +1924,9 @@ function Xe(e, t) {
|
|
|
1657
1924
|
t.preventDefault();
|
|
1658
1925
|
let n = t.data ?? "", r = t.getTargetRanges(), i, a;
|
|
1659
1926
|
if (r.length > 0) {
|
|
1660
|
-
let e =
|
|
1927
|
+
let e = U(r[0].startContainer, r[0].startOffset, o, c), t = U(r[0].endContainer, r[0].endOffset, o, c);
|
|
1661
1928
|
[i, a] = e <= t ? [e, t] : [t, e];
|
|
1662
|
-
} else i = a =
|
|
1929
|
+
} else i = a = V(o, c);
|
|
1663
1930
|
e.applyValue(l.slice(0, i) + n + l.slice(a)), u(i + n.length);
|
|
1664
1931
|
break;
|
|
1665
1932
|
}
|
|
@@ -1668,9 +1935,9 @@ function Xe(e, t) {
|
|
|
1668
1935
|
t.preventDefault();
|
|
1669
1936
|
let n = t.dataTransfer?.getData("text/plain") ?? "", r = t.getTargetRanges(), i, a;
|
|
1670
1937
|
if (r.length > 0) {
|
|
1671
|
-
let e =
|
|
1938
|
+
let e = U(r[0].startContainer, r[0].startOffset, o, c), t = U(r[0].endContainer, r[0].endOffset, o, c);
|
|
1672
1939
|
[i, a] = e <= t ? [e, t] : [t, e];
|
|
1673
|
-
} else i = a =
|
|
1940
|
+
} else i = a = V(o, c);
|
|
1674
1941
|
e.applyValue(l.slice(0, i) + n + l.slice(a)), u(i + n.length);
|
|
1675
1942
|
break;
|
|
1676
1943
|
}
|
|
@@ -1682,30 +1949,30 @@ function Xe(e, t) {
|
|
|
1682
1949
|
case "deleteSoftLineForward": {
|
|
1683
1950
|
let n = t.getTargetRanges();
|
|
1684
1951
|
if (!n.length) return;
|
|
1685
|
-
let r =
|
|
1952
|
+
let r = U(n[0].startContainer, n[0].startOffset, o, c), i = U(n[0].endContainer, n[0].endOffset, o, c), [a, s] = r <= i ? [r, i] : [i, r];
|
|
1686
1953
|
if (a === s) return;
|
|
1687
1954
|
t.preventDefault(), e.applyValue(l.slice(0, a) + l.slice(s)), u(a);
|
|
1688
1955
|
break;
|
|
1689
1956
|
}
|
|
1690
1957
|
}
|
|
1691
1958
|
}
|
|
1692
|
-
function
|
|
1959
|
+
function vt(e) {
|
|
1693
1960
|
return e.tagName === "SPAN" && (e.attributes.length === 0 || e.attributes.length === 1 && e.hasAttribute("contenteditable"));
|
|
1694
1961
|
}
|
|
1695
|
-
function
|
|
1962
|
+
function yt(e, t, n) {
|
|
1696
1963
|
let r = window.getSelection();
|
|
1697
1964
|
if (!r) return !1;
|
|
1698
1965
|
let i = 0;
|
|
1699
1966
|
for (let a of Array.from(e.childNodes)) {
|
|
1700
1967
|
if (i >= t.children.length) break;
|
|
1701
1968
|
let e = t.children[i];
|
|
1702
|
-
if (a
|
|
1703
|
-
if (!
|
|
1969
|
+
if (A(a) && e.type === "text") {
|
|
1970
|
+
if (!vt(a)) continue;
|
|
1704
1971
|
if (n >= e.position.start && n <= e.position.end) {
|
|
1705
|
-
let t = a.firstChild, i = n - e.position.start;
|
|
1706
|
-
if (
|
|
1972
|
+
let t = a.firstChild, i = j(t) ? t : null, o = n - e.position.start;
|
|
1973
|
+
if (i) {
|
|
1707
1974
|
let e = document.createRange();
|
|
1708
|
-
e.setStart(
|
|
1975
|
+
e.setStart(i, Math.min(o, i.length)), e.collapse(!0), r.removeAllRanges(), r.addRange(e);
|
|
1709
1976
|
} else {
|
|
1710
1977
|
let e = document.createRange();
|
|
1711
1978
|
e.setStart(a, 0), e.collapse(!0), r.removeAllRanges(), r.addRange(e);
|
|
@@ -1713,72 +1980,48 @@ function Qe(e, t, n) {
|
|
|
1713
1980
|
return !0;
|
|
1714
1981
|
}
|
|
1715
1982
|
i++;
|
|
1716
|
-
} else if (a
|
|
1983
|
+
} else if (j(a) && e.type === "text") {
|
|
1717
1984
|
if (n >= e.position.start && n <= e.position.end) {
|
|
1718
1985
|
let t = Math.min(n - e.position.start, a.length), i = document.createRange();
|
|
1719
1986
|
return i.setStart(a, t), i.collapse(!0), r.removeAllRanges(), r.addRange(i), !0;
|
|
1720
1987
|
}
|
|
1721
1988
|
i++;
|
|
1722
|
-
} else if (a
|
|
1989
|
+
} else if (A(a) && e.type === "mark") {
|
|
1723
1990
|
let r = i + 1 < t.children.length ? t.children[i + 1] : null;
|
|
1724
|
-
if (!(n === e.position.end && r?.position.start === n) && n >= e.position.start && n <= e.position.end) return
|
|
1991
|
+
if (!(n === e.position.end && r?.position.start === n) && n >= e.position.start && n <= e.position.end) return yt(a, e, n);
|
|
1725
1992
|
i++;
|
|
1726
1993
|
}
|
|
1727
1994
|
}
|
|
1728
1995
|
return !1;
|
|
1729
1996
|
}
|
|
1730
|
-
function
|
|
1997
|
+
function H(e, t, n) {
|
|
1731
1998
|
let r = window.getSelection();
|
|
1732
1999
|
if (!r) return;
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
U.setCaretToEnd(e);
|
|
2000
|
+
if (t.type === "mark") {
|
|
2001
|
+
if (yt(e, t, n)) return;
|
|
2002
|
+
F.setCaretToEnd(e);
|
|
1737
2003
|
return;
|
|
1738
2004
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
if (o.type === "text") {
|
|
1745
|
-
let e = n - o.position.start, t = document.createTreeWalker(s, 4).nextNode();
|
|
1746
|
-
if (t) {
|
|
1747
|
-
let n = Math.min(e, t.length), i = document.createRange();
|
|
1748
|
-
i.setStart(t, n), i.collapse(!0), r.removeAllRanges(), r.addRange(i);
|
|
1749
|
-
return;
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
if (Qe(s, o, n)) return;
|
|
1753
|
-
break;
|
|
1754
|
-
}
|
|
2005
|
+
let i = n - t.position.start, a = P(document.createTreeWalker(e, 4));
|
|
2006
|
+
if (a) {
|
|
2007
|
+
let e = Math.min(i, a.length), t = document.createRange();
|
|
2008
|
+
t.setStart(a, e), t.collapse(!0), r.removeAllRanges(), r.addRange(t);
|
|
2009
|
+
return;
|
|
1755
2010
|
}
|
|
1756
|
-
|
|
2011
|
+
F.setCaretToEnd(e);
|
|
1757
2012
|
}
|
|
1758
|
-
function
|
|
2013
|
+
function U(e, t, n, r) {
|
|
1759
2014
|
if (e === n) {
|
|
1760
2015
|
let e = window.getSelection();
|
|
1761
|
-
return e?.focusNode && e.focusNode !== n ?
|
|
1762
|
-
}
|
|
1763
|
-
if (e.nodeType === Node.TEXT_NODE && e.parentElement === n) {
|
|
1764
|
-
let i = r.tokens[0];
|
|
1765
|
-
return i?.type === "mark" ? Y(e, t, n, i) : i?.type === "text" ? i.position.start + Math.min(t, i.content.length) : r.endPos;
|
|
2016
|
+
return e?.focusNode && e.focusNode !== n ? U(e.focusNode, e.focusOffset, n, r) : r.position.end;
|
|
1766
2017
|
}
|
|
2018
|
+
if (e.nodeType === Node.TEXT_NODE && e.parentElement === n) return r.type === "mark" ? W(e, t, n, r) : r.position.start + Math.min(t, r.content.length);
|
|
1767
2019
|
let i = e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement;
|
|
1768
2020
|
for (; i && i.parentElement !== n;) i = i.parentElement;
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
if (!o && r.tokens.length === 1 && r.tokens[0].type === "mark") return Y(e, t, n, r.tokens[0]);
|
|
1774
|
-
let s = a - (o ? 1 : 0);
|
|
1775
|
-
if (s < 0) return r.startPos;
|
|
1776
|
-
if (s >= r.tokens.length) return r.endPos;
|
|
1777
|
-
let c = r.tokens[s];
|
|
1778
|
-
return c.type === "text" ? c.position.start + Math.min(t, c.content.length) : Y(e, t, i, c);
|
|
1779
|
-
}
|
|
1780
|
-
function Y(e, t, n, r) {
|
|
1781
|
-
if (!r.children || r.children.length === 0) {
|
|
2021
|
+
return i ? r.type === "mark" ? W(e, t, n, r) : r.position.start + Math.min(t, r.content.length) : r.position.end;
|
|
2022
|
+
}
|
|
2023
|
+
function W(e, t, n, r) {
|
|
2024
|
+
if (r.children.length === 0) {
|
|
1782
2025
|
if (t === 0) return r.position.start;
|
|
1783
2026
|
let e = r.slot?.content.length ?? r.value.length;
|
|
1784
2027
|
return e > 0 && t >= e ? r.content.endsWith("\n\n") && r.slot ? r.slot.end : r.position.end : (r.slot?.start ?? r.position.start) + Math.min(t, e);
|
|
@@ -1787,19 +2030,19 @@ function Y(e, t, n, r) {
|
|
|
1787
2030
|
for (let a of Array.from(n.childNodes)) {
|
|
1788
2031
|
if (i >= r.children.length) break;
|
|
1789
2032
|
let n = r.children[i];
|
|
1790
|
-
if (a
|
|
1791
|
-
if (!
|
|
2033
|
+
if (A(a) && n.type === "text") {
|
|
2034
|
+
if (!vt(a)) continue;
|
|
1792
2035
|
if (e === a) {
|
|
1793
2036
|
let e = t === 0 ? 0 : n.content.length;
|
|
1794
2037
|
return n.position.start + Math.min(e, n.content.length);
|
|
1795
2038
|
}
|
|
1796
2039
|
if (a.contains(e)) return n.position.start + Math.min(t, n.content.length);
|
|
1797
2040
|
i++;
|
|
1798
|
-
} else if (a
|
|
2041
|
+
} else if (j(a) && n.type === "text") {
|
|
1799
2042
|
if (e === a) return n.position.start + Math.min(t, n.content.length);
|
|
1800
2043
|
i++;
|
|
1801
|
-
} else if (a
|
|
1802
|
-
if (a === e || a.contains(e)) return
|
|
2044
|
+
} else if (A(a) && n.type === "mark") {
|
|
2045
|
+
if (a === e || a.contains(e)) return W(e, t, a, n);
|
|
1803
2046
|
i++;
|
|
1804
2047
|
}
|
|
1805
2048
|
}
|
|
@@ -1807,7 +2050,7 @@ function Y(e, t, n, r) {
|
|
|
1807
2050
|
}
|
|
1808
2051
|
//#endregion
|
|
1809
2052
|
//#region ../../common/core/src/features/feature-manager/FeatureManager.ts
|
|
1810
|
-
var
|
|
2053
|
+
var bt = class {
|
|
1811
2054
|
#e = [];
|
|
1812
2055
|
#t = !1;
|
|
1813
2056
|
register(e) {
|
|
@@ -1819,21 +2062,21 @@ var $e = class {
|
|
|
1819
2062
|
disableAll() {
|
|
1820
2063
|
this.#t && (this.#t = !1, this.#e.forEach((e) => e.disable()));
|
|
1821
2064
|
}
|
|
1822
|
-
},
|
|
2065
|
+
}, G = (e, t) => ({
|
|
1823
2066
|
name: e,
|
|
1824
2067
|
enable: () => t.enable(),
|
|
1825
2068
|
disable: () => t.disable()
|
|
1826
|
-
}),
|
|
1827
|
-
let t = new
|
|
1828
|
-
return t.register(
|
|
1829
|
-
},
|
|
2069
|
+
}), xt = (e) => {
|
|
2070
|
+
let t = new bt();
|
|
2071
|
+
return t.register(G("keydown", e.controllers.keydown)).register(G("system", e.controllers.system)).register(G("focus", e.controllers.focus)).register(G("textSelection", e.controllers.textSelection)).register(G("contentEditable", e.controllers.contentEditable)), t;
|
|
2072
|
+
}, St = class {
|
|
1830
2073
|
#e = [];
|
|
1831
2074
|
#t = !1;
|
|
1832
2075
|
constructor(e) {
|
|
1833
2076
|
this.store = e;
|
|
1834
2077
|
}
|
|
1835
2078
|
enable(e) {
|
|
1836
|
-
let { store: t } = this, n =
|
|
2079
|
+
let { store: t } = this, n = xt(t);
|
|
1837
2080
|
n.enableAll(), this.#e.push(() => n.disableAll()), this.#n(), e?.getTrigger && this.#r(e.getTrigger);
|
|
1838
2081
|
}
|
|
1839
2082
|
disable() {
|
|
@@ -1842,12 +2085,16 @@ var $e = class {
|
|
|
1842
2085
|
}
|
|
1843
2086
|
syncParser(e, t) {
|
|
1844
2087
|
let { store: n } = this, r = t?.map((e) => e.markup);
|
|
1845
|
-
if (r
|
|
2088
|
+
if (r?.some(Boolean)) {
|
|
2089
|
+
let e = n.state.drag.get() ? { skipEmptyText: !0 } : void 0;
|
|
2090
|
+
n.state.parser.set(new xe(r, e));
|
|
2091
|
+
} else n.state.parser.set(void 0);
|
|
2092
|
+
if (this.#t) {
|
|
1846
2093
|
n.state.recovery.get() || n.events.parse();
|
|
1847
2094
|
return;
|
|
1848
2095
|
}
|
|
1849
2096
|
let i = e ?? n.state.defaultValue.get() ?? "";
|
|
1850
|
-
n.state.tokens.set(
|
|
2097
|
+
n.state.tokens.set(O(n, i)), this.#t = !0;
|
|
1851
2098
|
}
|
|
1852
2099
|
recoverFocus() {
|
|
1853
2100
|
this.store.controllers.contentEditable.sync(), this.store.state.Mark.get() && this.store.controllers.focus.recover();
|
|
@@ -1856,11 +2103,11 @@ var $e = class {
|
|
|
1856
2103
|
let { store: e } = this;
|
|
1857
2104
|
this.#e.push(e.events.parse.on(() => {
|
|
1858
2105
|
if (e.state.recovery.get()) {
|
|
1859
|
-
let t =
|
|
1860
|
-
e.state.tokens.set(
|
|
2106
|
+
let t = T(e.state.tokens.get());
|
|
2107
|
+
e.state.tokens.set(O(e, t)), e.state.previousValue.set(t);
|
|
1861
2108
|
return;
|
|
1862
2109
|
}
|
|
1863
|
-
e.state.tokens.set(e.nodes.focus.target ?
|
|
2110
|
+
e.state.tokens.set(e.nodes.focus.target ? Te(e) : Ee(e));
|
|
1864
2111
|
}));
|
|
1865
2112
|
}
|
|
1866
2113
|
#r(e) {
|
|
@@ -1872,13 +2119,13 @@ var $e = class {
|
|
|
1872
2119
|
};
|
|
1873
2120
|
//#endregion
|
|
1874
2121
|
//#region ../../common/core/src/features/overlay/filterSuggestions.ts
|
|
1875
|
-
function
|
|
2122
|
+
function Ct(e, t) {
|
|
1876
2123
|
let n = t.toLowerCase();
|
|
1877
2124
|
return e.filter((e) => e.toLowerCase().includes(n));
|
|
1878
2125
|
}
|
|
1879
2126
|
//#endregion
|
|
1880
2127
|
//#region ../../common/core/src/features/overlay/createMarkFromOverlay.ts
|
|
1881
|
-
function
|
|
2128
|
+
function wt(e, t, n) {
|
|
1882
2129
|
let r = e.option.markup;
|
|
1883
2130
|
if (!r) throw Error("createMarkFromOverlay: option.markup is required");
|
|
1884
2131
|
return {
|
|
@@ -1905,7 +2152,7 @@ function rt(e, t, n) {
|
|
|
1905
2152
|
}
|
|
1906
2153
|
//#endregion
|
|
1907
2154
|
//#region ../../common/core/src/features/overlay/OverlayController.ts
|
|
1908
|
-
var
|
|
2155
|
+
var Tt = class {
|
|
1909
2156
|
#e;
|
|
1910
2157
|
#t;
|
|
1911
2158
|
#n;
|
|
@@ -1922,55 +2169,61 @@ var it = class {
|
|
|
1922
2169
|
this.#e = this.store.events.clearOverlay.on(() => {
|
|
1923
2170
|
t(void 0);
|
|
1924
2171
|
}), this.#t = this.store.events.checkOverlay.on(() => {
|
|
1925
|
-
t(
|
|
2172
|
+
t(Ge.find(this.store.state.options.get(), e));
|
|
1926
2173
|
}), this.#n = this.store.events.change.on(() => {
|
|
1927
|
-
let e = this.store.state.showOverlayOn.get()
|
|
2174
|
+
let e = this.store.state.showOverlayOn.get();
|
|
2175
|
+
if (!e) return;
|
|
2176
|
+
let t = "change";
|
|
1928
2177
|
(e === t || Array.isArray(e) && e.includes(t)) && this.store.events.checkOverlay();
|
|
1929
|
-
})
|
|
1930
|
-
|
|
2178
|
+
});
|
|
2179
|
+
let n = () => {
|
|
2180
|
+
let e = this.store.state.showOverlayOn.get();
|
|
2181
|
+
if (!e) return;
|
|
2182
|
+
let t = "selectionChange";
|
|
1931
2183
|
(e === t || Array.isArray(e) && e.includes(t)) && this.store.events.checkOverlay();
|
|
1932
|
-
}
|
|
1933
|
-
|
|
2184
|
+
};
|
|
2185
|
+
this.#r = n, this.#i = () => {
|
|
2186
|
+
document.addEventListener("selectionchange", n);
|
|
1934
2187
|
}, this.#a = () => {
|
|
1935
|
-
document.removeEventListener("selectionchange",
|
|
2188
|
+
document.removeEventListener("selectionchange", n);
|
|
1936
2189
|
};
|
|
1937
|
-
let
|
|
1938
|
-
|
|
2190
|
+
let r = this.store.refs.container;
|
|
2191
|
+
r && (r.addEventListener("focusin", this.#i), r.addEventListener("focusout", this.#a));
|
|
1939
2192
|
}
|
|
1940
2193
|
enableClose() {
|
|
1941
2194
|
this.#o || (this.#o = (e) => {
|
|
1942
|
-
e.key ===
|
|
2195
|
+
e.key === y.ESC && this.store.events.clearOverlay();
|
|
1943
2196
|
}, this.#s = (e) => {
|
|
1944
|
-
let t = e.target;
|
|
2197
|
+
let t = e.target instanceof HTMLElement ? e.target : null;
|
|
1945
2198
|
this.store.refs.overlay?.contains(t) || this.store.refs.container?.contains(t) || this.store.events.clearOverlay();
|
|
1946
2199
|
}, window.addEventListener("keydown", this.#o), document.addEventListener("click", this.#s, !0));
|
|
1947
2200
|
}
|
|
1948
2201
|
disableClose() {
|
|
1949
|
-
this.#o && (window.removeEventListener("keydown", this.#o), document.removeEventListener("click", this.#s, !0), this.#o = void 0, this.#s = void 0);
|
|
2202
|
+
this.#o && (window.removeEventListener("keydown", this.#o), this.#s && document.removeEventListener("click", this.#s, !0), this.#o = void 0, this.#s = void 0);
|
|
1950
2203
|
}
|
|
1951
2204
|
disable() {
|
|
1952
2205
|
let e = this.store.refs.container;
|
|
1953
|
-
e && this.#i && (e.removeEventListener("focusin", this.#i), e.removeEventListener("focusout", this.#a)), this.#r && document.removeEventListener("selectionchange", this.#r), this.disableClose(), this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = void 0, this.#n = void 0, this.#r = void 0, this.#i = void 0, this.#a = void 0;
|
|
2206
|
+
e && this.#i && (e.removeEventListener("focusin", this.#i), this.#a && e.removeEventListener("focusout", this.#a)), this.#r && document.removeEventListener("selectionchange", this.#r), this.disableClose(), this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = void 0, this.#n = void 0, this.#r = void 0, this.#i = void 0, this.#a = void 0;
|
|
1954
2207
|
}
|
|
1955
2208
|
};
|
|
1956
2209
|
//#endregion
|
|
1957
2210
|
//#region ../../common/core/src/features/overlay/suggestionNavigation.ts
|
|
1958
|
-
function
|
|
2211
|
+
function Et(e, t, n) {
|
|
1959
2212
|
if (n === 0) return {
|
|
1960
2213
|
action: "none",
|
|
1961
2214
|
index: t
|
|
1962
2215
|
};
|
|
1963
2216
|
let r = !isNaN(t);
|
|
1964
2217
|
switch (e) {
|
|
1965
|
-
case
|
|
2218
|
+
case y.UP: return {
|
|
1966
2219
|
action: "up",
|
|
1967
2220
|
index: r ? (n + (t - 1) % n) % n : 0
|
|
1968
2221
|
};
|
|
1969
|
-
case
|
|
2222
|
+
case y.DOWN: return {
|
|
1970
2223
|
action: "down",
|
|
1971
2224
|
index: r ? (t + 1) % n : 0
|
|
1972
2225
|
};
|
|
1973
|
-
case
|
|
2226
|
+
case y.ENTER: return r ? {
|
|
1974
2227
|
action: "select",
|
|
1975
2228
|
index: t
|
|
1976
2229
|
} : {
|
|
@@ -1985,29 +2238,33 @@ function at(e, t, n) {
|
|
|
1985
2238
|
}
|
|
1986
2239
|
//#endregion
|
|
1987
2240
|
//#region ../../common/core/src/features/store/Store.ts
|
|
1988
|
-
var
|
|
1989
|
-
key = new
|
|
2241
|
+
var Dt = class {
|
|
2242
|
+
key = new Be();
|
|
2243
|
+
blocks;
|
|
1990
2244
|
nodes = {
|
|
1991
|
-
focus: new
|
|
1992
|
-
input: new
|
|
2245
|
+
focus: new Ke(void 0, this),
|
|
2246
|
+
input: new Ke(void 0, this)
|
|
1993
2247
|
};
|
|
1994
2248
|
state;
|
|
1995
|
-
|
|
2249
|
+
slot;
|
|
2250
|
+
events = Me();
|
|
1996
2251
|
refs = {
|
|
1997
2252
|
container: null,
|
|
1998
2253
|
overlay: null
|
|
1999
2254
|
};
|
|
2000
2255
|
controllers = {
|
|
2001
|
-
overlay: new
|
|
2002
|
-
focus: new
|
|
2003
|
-
keydown: new
|
|
2004
|
-
system: new
|
|
2005
|
-
textSelection: new
|
|
2006
|
-
contentEditable: new
|
|
2256
|
+
overlay: new Tt(this),
|
|
2257
|
+
focus: new at(this),
|
|
2258
|
+
keydown: new ft(this),
|
|
2259
|
+
system: new it(this),
|
|
2260
|
+
textSelection: new ut(this),
|
|
2261
|
+
contentEditable: new nt(this),
|
|
2262
|
+
drag: new $e(this)
|
|
2007
2263
|
};
|
|
2008
|
-
lifecycle = new
|
|
2264
|
+
lifecycle = new St(this);
|
|
2265
|
+
_defaultSpan;
|
|
2009
2266
|
constructor(e) {
|
|
2010
|
-
this.state =
|
|
2267
|
+
this._defaultSpan = e.defaultSpan, this.blocks = new ze(e.createUseHook), this.state = Ae({
|
|
2011
2268
|
tokens: [],
|
|
2012
2269
|
parser: void 0,
|
|
2013
2270
|
previousValue: void 0,
|
|
@@ -2028,12 +2285,33 @@ var ot = class {
|
|
|
2028
2285
|
slots: void 0,
|
|
2029
2286
|
slotProps: void 0,
|
|
2030
2287
|
drag: !1
|
|
2031
|
-
}, e.createUseHook)
|
|
2288
|
+
}, e.createUseHook, { equals: { style: p } }), this.slot = {
|
|
2289
|
+
container: {
|
|
2290
|
+
use: () => [_("container", this.state.slots.use()), v("container", this.state.slotProps.use())],
|
|
2291
|
+
get: () => [_("container", this.state.slots.get()), v("container", this.state.slotProps.get())]
|
|
2292
|
+
},
|
|
2293
|
+
block: {
|
|
2294
|
+
use: () => [_("block", this.state.slots.use()), v("block", this.state.slotProps.use())],
|
|
2295
|
+
get: () => [_("block", this.state.slots.get()), v("block", this.state.slotProps.get())]
|
|
2296
|
+
},
|
|
2297
|
+
span: {
|
|
2298
|
+
use: () => [_("span", this.state.slots.use()), v("span", this.state.slotProps.use())],
|
|
2299
|
+
get: () => [_("span", this.state.slots.get()), v("span", this.state.slotProps.get())]
|
|
2300
|
+
},
|
|
2301
|
+
overlay: {
|
|
2302
|
+
use: (e, t) => ne(this.state.Overlay.use(), e, t),
|
|
2303
|
+
get: (e, t) => ne(this.state.Overlay.get(), e, t)
|
|
2304
|
+
},
|
|
2305
|
+
mark: {
|
|
2306
|
+
use: (e) => re(e, this.state.options.get(), this.state.Mark.use(), this.state.Span.use(), this._defaultSpan),
|
|
2307
|
+
get: (e) => re(e, this.state.options.get(), this.state.Mark.get(), this.state.Span.get(), this._defaultSpan)
|
|
2308
|
+
}
|
|
2309
|
+
};
|
|
2032
2310
|
}
|
|
2033
2311
|
applyValue(e) {
|
|
2034
2312
|
let t = this.state.onChange.get();
|
|
2035
2313
|
if (!t) return;
|
|
2036
|
-
let n =
|
|
2314
|
+
let n = O(this, e);
|
|
2037
2315
|
this.state.tokens.set(n), this.state.previousValue.set(e), t(e);
|
|
2038
2316
|
}
|
|
2039
2317
|
createHandler() {
|
|
@@ -2050,7 +2328,7 @@ var ot = class {
|
|
|
2050
2328
|
}
|
|
2051
2329
|
};
|
|
2052
2330
|
}
|
|
2053
|
-
},
|
|
2331
|
+
}, Ot = class {
|
|
2054
2332
|
ref;
|
|
2055
2333
|
#e;
|
|
2056
2334
|
#t;
|
|
@@ -2086,13 +2364,13 @@ var ot = class {
|
|
|
2086
2364
|
return this.#t.slot?.content;
|
|
2087
2365
|
}
|
|
2088
2366
|
get depth() {
|
|
2089
|
-
return
|
|
2367
|
+
return E(this.#e.state.tokens.get(), this.#t)?.depth ?? 0;
|
|
2090
2368
|
}
|
|
2091
2369
|
get hasChildren() {
|
|
2092
2370
|
return this.#t.children.some((e) => e.type === "mark");
|
|
2093
2371
|
}
|
|
2094
2372
|
get parent() {
|
|
2095
|
-
return
|
|
2373
|
+
return E(this.#e.state.tokens.get(), this.#t)?.parent;
|
|
2096
2374
|
}
|
|
2097
2375
|
get tokens() {
|
|
2098
2376
|
return this.#t.children;
|
|
@@ -2104,486 +2382,203 @@ var ot = class {
|
|
|
2104
2382
|
#r() {
|
|
2105
2383
|
this.#e.events.change();
|
|
2106
2384
|
}
|
|
2107
|
-
},
|
|
2108
|
-
let
|
|
2109
|
-
return
|
|
2385
|
+
}, kt = (e) => {
|
|
2386
|
+
let t = (t) => e.on(t), n = () => e.get();
|
|
2387
|
+
return () => u(t, n, n);
|
|
2110
2388
|
};
|
|
2111
2389
|
//#endregion
|
|
2112
2390
|
//#region src/lib/hooks/useCoreFeatures.ts
|
|
2113
|
-
function
|
|
2114
|
-
|
|
2115
|
-
let n = e.state.value.use(), r = e.state.Mark.use(),
|
|
2116
|
-
|
|
2391
|
+
function At(e, t) {
|
|
2392
|
+
a(t, () => e.createHandler(), [e]), i(() => (e.lifecycle.enable({ getTrigger: (e) => e.overlay?.trigger }), () => e.lifecycle.disable()), []);
|
|
2393
|
+
let n = e.state.value.use(), r = e.state.Mark.use(), s = e.state.options.use(), c = s?.some((e) => e.Mark != null), l = r || c ? s : void 0, u = e.state.tokens.use();
|
|
2394
|
+
i(() => {
|
|
2117
2395
|
e.lifecycle.syncParser(n, l);
|
|
2118
|
-
}, [n, l]),
|
|
2396
|
+
}, [n, l]), o(() => {
|
|
2119
2397
|
e.controllers.contentEditable.sync();
|
|
2120
|
-
}, [u]),
|
|
2398
|
+
}, [u]), i(() => {
|
|
2121
2399
|
e.lifecycle.recoverFocus();
|
|
2122
2400
|
}, [u]);
|
|
2123
2401
|
}
|
|
2124
2402
|
//#endregion
|
|
2125
2403
|
//#region src/lib/providers/StoreContext.ts
|
|
2126
|
-
var
|
|
2127
|
-
|
|
2128
|
-
function
|
|
2129
|
-
let e =
|
|
2404
|
+
var K = e(void 0);
|
|
2405
|
+
K.displayName = "StoreContext";
|
|
2406
|
+
function q() {
|
|
2407
|
+
let e = r(K);
|
|
2130
2408
|
if (e === void 0) throw Error("Store not found. Make sure to wrap component in StoreContext.");
|
|
2131
2409
|
return e;
|
|
2132
2410
|
}
|
|
2411
|
+
var J = {
|
|
2412
|
+
Container: "_Container_5gsai_1",
|
|
2413
|
+
Icon: "_Icon_5gsai_5",
|
|
2414
|
+
IconGrip: "_IconGrip_5gsai_16",
|
|
2415
|
+
IconAdd: "_IconAdd_5gsai_20",
|
|
2416
|
+
IconDuplicate: "_IconDuplicate_5gsai_21",
|
|
2417
|
+
IconTrash: "_IconTrash_5gsai_22",
|
|
2418
|
+
Block: "_Block_5gsai_38",
|
|
2419
|
+
SidePanel: "_SidePanel_5gsai_48",
|
|
2420
|
+
SidePanelVisible: "_SidePanelVisible_5gsai_60",
|
|
2421
|
+
SidePanelAlways: "_SidePanelAlways_5gsai_65",
|
|
2422
|
+
GripButton: "_GripButton_5gsai_71",
|
|
2423
|
+
GripButtonDragging: "_GripButtonDragging_5gsai_90",
|
|
2424
|
+
BlockMenu: "_BlockMenu_5gsai_94",
|
|
2425
|
+
BlockMenuItem: "_BlockMenuItem_5gsai_106",
|
|
2426
|
+
BlockMenuItemDelete: "_BlockMenuItemDelete_5gsai_123",
|
|
2427
|
+
BlockMenuSeparator: "_BlockMenuSeparator_5gsai_131",
|
|
2428
|
+
DropIndicator: "_DropIndicator_5gsai_137",
|
|
2429
|
+
Suggestions: "_Suggestions_5gsai_153",
|
|
2430
|
+
suggestionActive: "_suggestionActive_5gsai_181"
|
|
2431
|
+
}, Y = t(({ token: e }) => {
|
|
2432
|
+
let t = q().blocks.get(e), n = t.state.menuOpen.use(), r = t.state.menuPosition.use();
|
|
2433
|
+
return n ? /* @__PURE__ */ f("div", {
|
|
2434
|
+
ref: (e) => t.attachMenu(e),
|
|
2435
|
+
className: J.BlockMenu,
|
|
2436
|
+
style: {
|
|
2437
|
+
top: r.top,
|
|
2438
|
+
left: r.left
|
|
2439
|
+
},
|
|
2440
|
+
children: [
|
|
2441
|
+
/* @__PURE__ */ f("button", {
|
|
2442
|
+
type: "button",
|
|
2443
|
+
className: J.BlockMenuItem,
|
|
2444
|
+
onMouseDown: (e) => {
|
|
2445
|
+
e.preventDefault(), t.addBlock();
|
|
2446
|
+
},
|
|
2447
|
+
children: [/* @__PURE__ */ d("span", { className: m(J.Icon, J.IconAdd) }), /* @__PURE__ */ d("span", { children: "Add below" })]
|
|
2448
|
+
}),
|
|
2449
|
+
/* @__PURE__ */ f("button", {
|
|
2450
|
+
type: "button",
|
|
2451
|
+
className: J.BlockMenuItem,
|
|
2452
|
+
onMouseDown: (e) => {
|
|
2453
|
+
e.preventDefault(), t.duplicateBlock();
|
|
2454
|
+
},
|
|
2455
|
+
children: [/* @__PURE__ */ d("span", { className: m(J.Icon, J.IconDuplicate) }), /* @__PURE__ */ d("span", { children: "Duplicate" })]
|
|
2456
|
+
}),
|
|
2457
|
+
/* @__PURE__ */ d("div", { className: J.BlockMenuSeparator }),
|
|
2458
|
+
/* @__PURE__ */ f("button", {
|
|
2459
|
+
type: "button",
|
|
2460
|
+
className: m(J.BlockMenuItem, J.BlockMenuItemDelete),
|
|
2461
|
+
onMouseDown: (e) => {
|
|
2462
|
+
e.preventDefault(), t.deleteBlock();
|
|
2463
|
+
},
|
|
2464
|
+
children: [/* @__PURE__ */ d("span", { className: m(J.Icon, J.IconTrash) }), /* @__PURE__ */ d("span", { children: "Delete" })]
|
|
2465
|
+
})
|
|
2466
|
+
]
|
|
2467
|
+
}) : null;
|
|
2468
|
+
});
|
|
2469
|
+
Y.displayName = "BlockMenu";
|
|
2133
2470
|
//#endregion
|
|
2134
|
-
//#region src/components/
|
|
2135
|
-
var
|
|
2471
|
+
//#region src/components/DragHandle.tsx
|
|
2472
|
+
var jt = `${J.Icon} ${J.IconGrip}`, Mt = t(({ token: e, blockIndex: t }) => {
|
|
2473
|
+
let n = q(), r = n.state.readOnly.use(), i = n.state.drag.use(), a = n.blocks.get(e), o = a.state.isDragging.use(), c = a.state.isHovered.use(), l = s(() => et(i), [i]);
|
|
2474
|
+
return r ? null : /* @__PURE__ */ d("div", {
|
|
2475
|
+
className: m(J.SidePanel, l ? J.SidePanelAlways : c && !o && J.SidePanelVisible),
|
|
2476
|
+
children: /* @__PURE__ */ d("button", {
|
|
2477
|
+
ref: (e) => a.attachGrip(e, t, n.controllers.drag),
|
|
2478
|
+
type: "button",
|
|
2479
|
+
draggable: !0,
|
|
2480
|
+
className: m(J.GripButton, o && J.GripButtonDragging),
|
|
2481
|
+
"aria-label": "Drag to reorder or click for options",
|
|
2482
|
+
children: /* @__PURE__ */ d("span", { className: jt })
|
|
2483
|
+
})
|
|
2484
|
+
});
|
|
2485
|
+
});
|
|
2486
|
+
Mt.displayName = "DragHandle";
|
|
2136
2487
|
//#endregion
|
|
2137
|
-
//#region src/
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
}
|
|
2144
|
-
let a = i.state.Mark.use(), o = i.state.Overlay.use(), s = e === "mark" ? a : o, c = _(e === "mark" ? t?.mark : t?.overlay, n ?? {}), l = (e === "mark" ? t?.Mark : t?.Overlay) || s || r;
|
|
2145
|
-
if (!l) throw Error(`No ${e} component found. Provide either option.${e === "mark" ? "Mark" : "Overlay"}, global ${e === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`);
|
|
2146
|
-
return [l, c];
|
|
2147
|
-
}
|
|
2148
|
-
function pt(e) {
|
|
2149
|
-
let t = Z(), n = t.state.options.use(), r = t.state.Mark.use(), i = t.state.Span.use();
|
|
2150
|
-
if (e.type === "text") return [i ?? dt, { value: e.content }];
|
|
2151
|
-
let a = n?.[e.descriptor.index], o = {
|
|
2152
|
-
value: e.value,
|
|
2153
|
-
meta: e.meta
|
|
2154
|
-
}, s = _(a?.mark, o), c = a?.Mark || r;
|
|
2155
|
-
if (!c) throw Error("No mark component found. Provide either option.Mark or global Mark.");
|
|
2156
|
-
return [c, s];
|
|
2157
|
-
}
|
|
2488
|
+
//#region src/components/DropIndicator.tsx
|
|
2489
|
+
var X = t(({ token: e, position: t }) => q().blocks.get(e).state.dropPosition.use() === t ? /* @__PURE__ */ d("div", {
|
|
2490
|
+
className: J.DropIndicator,
|
|
2491
|
+
style: t === "before" ? { top: -1 } : { bottom: -1 }
|
|
2492
|
+
}) : null);
|
|
2493
|
+
X.displayName = "DropIndicator";
|
|
2158
2494
|
//#endregion
|
|
2159
2495
|
//#region src/lib/providers/TokenContext.ts
|
|
2160
|
-
var
|
|
2161
|
-
|
|
2162
|
-
function
|
|
2163
|
-
let e =
|
|
2496
|
+
var Z = e(void 0);
|
|
2497
|
+
Z.displayName = "TokenProvider";
|
|
2498
|
+
function Nt() {
|
|
2499
|
+
let e = r(Z);
|
|
2164
2500
|
if (e === void 0) throw Error("Token not found. Make sure to wrap component in TokenContext.Provider.");
|
|
2165
2501
|
return e;
|
|
2166
2502
|
}
|
|
2167
2503
|
//#endregion
|
|
2168
2504
|
//#region src/components/Token.tsx
|
|
2169
|
-
var Q =
|
|
2170
|
-
let t =
|
|
2171
|
-
return /* @__PURE__ */
|
|
2505
|
+
var Q = t(({ mark: e }) => {
|
|
2506
|
+
let t = q(), [n, r] = t.slot.mark.use(e);
|
|
2507
|
+
return /* @__PURE__ */ d(Z, {
|
|
2172
2508
|
value: e,
|
|
2173
|
-
children: /* @__PURE__ */
|
|
2174
|
-
|
|
2175
|
-
|
|
2509
|
+
children: /* @__PURE__ */ d(n, {
|
|
2510
|
+
children: e.type === "mark" && e.children.length > 0 ? e.children.map((e) => /* @__PURE__ */ d(Q, { mark: e }, t.key.get(e))) : void 0,
|
|
2511
|
+
...r
|
|
2176
2512
|
})
|
|
2177
2513
|
});
|
|
2178
2514
|
});
|
|
2179
2515
|
Q.displayName = "Token";
|
|
2180
2516
|
//#endregion
|
|
2181
|
-
//#region src/components/
|
|
2182
|
-
var
|
|
2183
|
-
let
|
|
2184
|
-
return /* @__PURE__ */ f(
|
|
2185
|
-
ref: (e) =>
|
|
2186
|
-
...c(() => b("container", r), [r]),
|
|
2187
|
-
className: i,
|
|
2188
|
-
style: a,
|
|
2189
|
-
children: t.map((e) => /* @__PURE__ */ f(Q, { mark: e }, o.get(e)))
|
|
2190
|
-
});
|
|
2191
|
-
});
|
|
2192
|
-
gt.displayName = "Container";
|
|
2193
|
-
var $ = {
|
|
2194
|
-
Container: "_Container_1526r_1",
|
|
2195
|
-
Icon: "_Icon_1526r_5",
|
|
2196
|
-
IconGrip: "_IconGrip_1526r_16",
|
|
2197
|
-
IconAdd: "_IconAdd_1526r_20",
|
|
2198
|
-
IconDuplicate: "_IconDuplicate_1526r_21",
|
|
2199
|
-
IconTrash: "_IconTrash_1526r_22",
|
|
2200
|
-
Suggestions: "_Suggestions_1526r_43",
|
|
2201
|
-
suggestionActive: "_suggestionActive_1526r_71"
|
|
2202
|
-
}, _t = `${$.Icon} ${$.IconGrip}`, vt = n(({ blockIndex: t, children: n, readOnly: i, alwaysShowHandle: a, onReorder: o, onRequestMenu: s }) => {
|
|
2203
|
-
let [c, d] = u(!1), [m, h] = u(!1), [g, _] = u(null), v = l(null), y = l(null), b = r(() => d(!0), []), x = r(() => d(!1), []), S = r((e) => {
|
|
2204
|
-
e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", String(t)), h(!0), v.current && e.dataTransfer.setDragImage(v.current, 0, 0);
|
|
2205
|
-
}, [t]), C = r(() => {
|
|
2206
|
-
h(!1), _(null);
|
|
2207
|
-
}, []), w = r((e) => {
|
|
2208
|
-
if (e.preventDefault(), e.dataTransfer.dropEffect = "move", !v.current) return;
|
|
2209
|
-
let t = v.current.getBoundingClientRect(), n = t.top + t.height / 2;
|
|
2210
|
-
_(e.clientY < n ? "before" : "after");
|
|
2211
|
-
}, []), T = r((e) => {
|
|
2212
|
-
e.currentTarget.contains(e.relatedTarget) || _(null);
|
|
2213
|
-
}, []), E = r((e) => {
|
|
2214
|
-
e.preventDefault();
|
|
2215
|
-
let n = parseInt(e.dataTransfer.getData("text/plain"), 10);
|
|
2216
|
-
if (isNaN(n)) return;
|
|
2217
|
-
let r = g === "before" ? t : t + 1;
|
|
2218
|
-
_(null), o(n, r);
|
|
2219
|
-
}, [
|
|
2220
|
-
t,
|
|
2221
|
-
g,
|
|
2222
|
-
o
|
|
2223
|
-
]), D = r((e) => {
|
|
2224
|
-
e.preventDefault(), y.current && s?.(t, y.current.getBoundingClientRect());
|
|
2225
|
-
}, [t, s]), O = {
|
|
2226
|
-
position: "relative",
|
|
2227
|
-
marginLeft: 0,
|
|
2228
|
-
transition: "opacity 0.2s ease",
|
|
2229
|
-
opacity: m ? .4 : 1,
|
|
2230
|
-
background: "transparent",
|
|
2231
|
-
borderRadius: 3,
|
|
2232
|
-
minHeight: "1.2em",
|
|
2233
|
-
userSelect: "none",
|
|
2234
|
-
outline: "none"
|
|
2235
|
-
}, ee = {
|
|
2236
|
-
position: "absolute",
|
|
2237
|
-
left: i ? 0 : -24,
|
|
2238
|
-
top: 0,
|
|
2239
|
-
bottom: 0,
|
|
2240
|
-
width: 24,
|
|
2241
|
-
display: "flex",
|
|
2242
|
-
alignItems: "center",
|
|
2243
|
-
opacity: a || c && !m ? 1 : 0,
|
|
2244
|
-
transition: a ? void 0 : "opacity 0.15s ease",
|
|
2245
|
-
pointerEvents: a || c ? "auto" : "none"
|
|
2246
|
-
}, k = {
|
|
2247
|
-
width: 24,
|
|
2248
|
-
height: 24,
|
|
2249
|
-
display: "flex",
|
|
2250
|
-
alignItems: "center",
|
|
2251
|
-
justifyContent: "center",
|
|
2252
|
-
cursor: "pointer",
|
|
2253
|
-
borderRadius: 4,
|
|
2254
|
-
color: "#9ca3af",
|
|
2255
|
-
background: "none",
|
|
2256
|
-
border: "none",
|
|
2257
|
-
padding: 0,
|
|
2258
|
-
margin: 0,
|
|
2259
|
-
font: "inherit",
|
|
2260
|
-
lineHeight: 1,
|
|
2261
|
-
flexShrink: 0,
|
|
2262
|
-
userSelect: "none"
|
|
2263
|
-
}, A = {
|
|
2264
|
-
position: "absolute",
|
|
2265
|
-
left: 0,
|
|
2266
|
-
right: 0,
|
|
2267
|
-
height: 2,
|
|
2268
|
-
backgroundColor: "#3b82f6",
|
|
2269
|
-
borderRadius: 1,
|
|
2270
|
-
pointerEvents: "none",
|
|
2271
|
-
zIndex: 10
|
|
2272
|
-
};
|
|
2273
|
-
return /* @__PURE__ */ p("div", {
|
|
2274
|
-
ref: v,
|
|
2517
|
+
//#region src/components/Block.tsx
|
|
2518
|
+
var Pt = t(({ token: e, blockIndex: t }) => {
|
|
2519
|
+
let n = q(), [r, i] = n.slot.block.use(), a = n.blocks.get(e), o = a.state.isDragging.use();
|
|
2520
|
+
return /* @__PURE__ */ f(r, {
|
|
2521
|
+
ref: (e) => a.attachContainer(e, t, n.controllers.drag),
|
|
2275
2522
|
"data-testid": "block",
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
onDragOver: w,
|
|
2280
|
-
onDragLeave: T,
|
|
2281
|
-
onDrop: E,
|
|
2523
|
+
...i,
|
|
2524
|
+
className: J.Block,
|
|
2525
|
+
style: { opacity: o ? .4 : 1 },
|
|
2282
2526
|
children: [
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
} }),
|
|
2287
|
-
!i && /* @__PURE__ */ f("div", {
|
|
2288
|
-
style: ee,
|
|
2289
|
-
children: /* @__PURE__ */ f("button", {
|
|
2290
|
-
ref: y,
|
|
2291
|
-
type: "button",
|
|
2292
|
-
draggable: !0,
|
|
2293
|
-
onDragStart: S,
|
|
2294
|
-
onDragEnd: C,
|
|
2295
|
-
onClick: D,
|
|
2296
|
-
style: {
|
|
2297
|
-
...k,
|
|
2298
|
-
cursor: m ? "grabbing" : "grab"
|
|
2299
|
-
},
|
|
2300
|
-
"aria-label": "Drag to reorder or click for options",
|
|
2301
|
-
children: /* @__PURE__ */ f("span", { className: _t })
|
|
2302
|
-
})
|
|
2527
|
+
/* @__PURE__ */ d(X, {
|
|
2528
|
+
token: e,
|
|
2529
|
+
position: "before"
|
|
2303
2530
|
}),
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
bottom: -1
|
|
2308
|
-
} })
|
|
2309
|
-
]
|
|
2310
|
-
});
|
|
2311
|
-
});
|
|
2312
|
-
vt.displayName = "DragMark";
|
|
2313
|
-
//#endregion
|
|
2314
|
-
//#region src/components/DragContainer.tsx
|
|
2315
|
-
var yt = `${$.Icon} ${$.IconGrip}`, bt = {
|
|
2316
|
-
id: "block-empty",
|
|
2317
|
-
tokens: [],
|
|
2318
|
-
startPos: 0,
|
|
2319
|
-
endPos: 0
|
|
2320
|
-
}, xt = (e) => e.tokens.length === 1 && e.tokens[0].type === "mark";
|
|
2321
|
-
function St(e, t) {
|
|
2322
|
-
if (!t || !(t instanceof Node)) return -1;
|
|
2323
|
-
let n = t;
|
|
2324
|
-
for (; n && n.parentNode !== e;) n = n.parentNode;
|
|
2325
|
-
return n ? Array.from(e.children).indexOf(n) : -1;
|
|
2326
|
-
}
|
|
2327
|
-
var Ct = {
|
|
2328
|
-
height: 1,
|
|
2329
|
-
background: "rgba(55, 53, 47, 0.09)",
|
|
2330
|
-
margin: "4px 0"
|
|
2331
|
-
}, wt = n(({ position: e, onAdd: t, onDelete: n, onDuplicate: r, onClose: i }) => {
|
|
2332
|
-
let o = l(null), [s, c] = u(null), d = l(i);
|
|
2333
|
-
d.current = i, a(() => {
|
|
2334
|
-
let e = (e) => {
|
|
2335
|
-
o.current && !o.current.contains(e.target) && d.current();
|
|
2336
|
-
}, t = (e) => {
|
|
2337
|
-
e.key === "Escape" && d.current();
|
|
2338
|
-
};
|
|
2339
|
-
return document.addEventListener("mousedown", e), document.addEventListener("keydown", t), () => {
|
|
2340
|
-
document.removeEventListener("mousedown", e), document.removeEventListener("keydown", t);
|
|
2341
|
-
};
|
|
2342
|
-
}, []);
|
|
2343
|
-
let m = {
|
|
2344
|
-
position: "fixed",
|
|
2345
|
-
top: e.top,
|
|
2346
|
-
left: e.left,
|
|
2347
|
-
background: "white",
|
|
2348
|
-
border: "1px solid rgba(55, 53, 47, 0.16)",
|
|
2349
|
-
borderRadius: 6,
|
|
2350
|
-
boxShadow: "0 4px 16px rgba(15, 15, 15, 0.12)",
|
|
2351
|
-
padding: 4,
|
|
2352
|
-
zIndex: 9999,
|
|
2353
|
-
minWidth: 160,
|
|
2354
|
-
fontSize: 14
|
|
2355
|
-
}, g = (e) => ({
|
|
2356
|
-
display: "flex",
|
|
2357
|
-
alignItems: "center",
|
|
2358
|
-
gap: 8,
|
|
2359
|
-
padding: "6px 10px",
|
|
2360
|
-
borderRadius: 4,
|
|
2361
|
-
cursor: "pointer",
|
|
2362
|
-
color: e === "delete" ? "#eb5757" : "rgba(55, 53, 47, 0.85)",
|
|
2363
|
-
background: s === e ? e === "delete" ? "rgba(235, 87, 87, 0.06)" : "rgba(55, 53, 47, 0.06)" : "transparent",
|
|
2364
|
-
transition: "background 0.1s ease",
|
|
2365
|
-
userSelect: "none",
|
|
2366
|
-
lineHeight: 1
|
|
2367
|
-
});
|
|
2368
|
-
return /* @__PURE__ */ p("div", {
|
|
2369
|
-
ref: o,
|
|
2370
|
-
style: m,
|
|
2371
|
-
children: [
|
|
2372
|
-
/* @__PURE__ */ p("div", {
|
|
2373
|
-
style: g("add"),
|
|
2374
|
-
onMouseEnter: () => c("add"),
|
|
2375
|
-
onMouseLeave: () => c(null),
|
|
2376
|
-
onMouseDown: (e) => {
|
|
2377
|
-
e.preventDefault(), t(), i();
|
|
2378
|
-
},
|
|
2379
|
-
children: [/* @__PURE__ */ f("span", { className: h($.Icon, $.IconAdd) }), /* @__PURE__ */ f("span", { children: "Add below" })]
|
|
2531
|
+
/* @__PURE__ */ d(Mt, {
|
|
2532
|
+
token: e,
|
|
2533
|
+
blockIndex: t
|
|
2380
2534
|
}),
|
|
2381
|
-
/* @__PURE__ */
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
onMouseDown: (e) => {
|
|
2386
|
-
e.preventDefault(), r(), i();
|
|
2387
|
-
},
|
|
2388
|
-
children: [/* @__PURE__ */ f("span", { className: h($.Icon, $.IconDuplicate) }), /* @__PURE__ */ f("span", { children: "Duplicate" })]
|
|
2535
|
+
/* @__PURE__ */ d(Q, { mark: e }),
|
|
2536
|
+
/* @__PURE__ */ d(X, {
|
|
2537
|
+
token: e,
|
|
2538
|
+
position: "after"
|
|
2389
2539
|
}),
|
|
2390
|
-
/* @__PURE__ */
|
|
2391
|
-
/* @__PURE__ */ p("div", {
|
|
2392
|
-
style: g("delete"),
|
|
2393
|
-
onMouseEnter: () => c("delete"),
|
|
2394
|
-
onMouseLeave: () => c(null),
|
|
2395
|
-
onMouseDown: (e) => {
|
|
2396
|
-
e.preventDefault(), n(), i();
|
|
2397
|
-
},
|
|
2398
|
-
children: [/* @__PURE__ */ f("span", { className: h($.Icon, $.IconTrash) }), /* @__PURE__ */ f("span", { children: "Delete" })]
|
|
2399
|
-
})
|
|
2540
|
+
/* @__PURE__ */ d(Y, { token: e })
|
|
2400
2541
|
]
|
|
2401
2542
|
});
|
|
2402
2543
|
});
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
n.children[r]?.focus();
|
|
2422
|
-
}));
|
|
2423
|
-
}, [e]), ne = r((t) => {
|
|
2424
|
-
let n = e.state.value.get();
|
|
2425
|
-
n == null || !e.state.onChange.get() || e.applyValue(Ae(n, j.current, t));
|
|
2426
|
-
}, [e]), re = r((t) => {
|
|
2427
|
-
let n = e.state.value.get();
|
|
2428
|
-
n == null || !e.state.onChange.get() || e.applyValue(je(n, j.current, t));
|
|
2429
|
-
}, [e]), N = r((e, t) => {
|
|
2430
|
-
v({
|
|
2431
|
-
index: e,
|
|
2432
|
-
position: {
|
|
2433
|
-
top: t.bottom + 4,
|
|
2434
|
-
left: t.left
|
|
2435
|
-
}
|
|
2436
|
-
});
|
|
2437
|
-
}, []), P = r(() => v(null), []), F = r(() => {
|
|
2438
|
-
O.current && clearTimeout(O.current), O.current = setTimeout(() => S(null), 120);
|
|
2439
|
-
}, []), I = r(() => {
|
|
2440
|
-
O.current && clearTimeout(O.current);
|
|
2441
|
-
}, []), ie = r((e) => {
|
|
2442
|
-
let t = g.container;
|
|
2443
|
-
if (!t) return;
|
|
2444
|
-
let n = St(t, e.target);
|
|
2445
|
-
if (n === -1 || !xt(j.current[n])) {
|
|
2446
|
-
F();
|
|
2447
|
-
return;
|
|
2448
|
-
}
|
|
2449
|
-
I(), S(n);
|
|
2450
|
-
}, [
|
|
2451
|
-
g,
|
|
2452
|
-
F,
|
|
2453
|
-
I
|
|
2454
|
-
]), L = r(() => F(), [F]), R = r((e) => {
|
|
2455
|
-
let t = g.container;
|
|
2456
|
-
if (!t) return;
|
|
2457
|
-
let n = St(t, e.target);
|
|
2458
|
-
if (n === -1 || !xt(j.current[n])) return;
|
|
2459
|
-
e.preventDefault();
|
|
2460
|
-
let r = t.children[n].getBoundingClientRect(), i = r.left + r.width / 2;
|
|
2461
|
-
E({
|
|
2462
|
-
index: n,
|
|
2463
|
-
position: e.clientX < i ? "before" : "after"
|
|
2464
|
-
});
|
|
2465
|
-
}, [g]), z = r((e) => {
|
|
2466
|
-
g.container && (g.container.contains(e.relatedTarget) || E(null));
|
|
2467
|
-
}, [g]), B = r((e) => {
|
|
2468
|
-
if (!T) return;
|
|
2469
|
-
e.preventDefault();
|
|
2470
|
-
let t = parseInt(e.dataTransfer.getData("text/plain"), 10);
|
|
2471
|
-
if (isNaN(t)) return;
|
|
2472
|
-
let n = T.position === "before" ? T.index : T.index + 1;
|
|
2473
|
-
E(null), M(t, n);
|
|
2474
|
-
}, [T, M]), ae = r((e) => {
|
|
2475
|
-
if (x === null || !g.container) return;
|
|
2476
|
-
e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", String(x)), w(x);
|
|
2477
|
-
let t = g.container.children[x];
|
|
2478
|
-
t && e.dataTransfer.setDragImage(t, 0, 0);
|
|
2479
|
-
}, [x, g]), V = r(() => {
|
|
2480
|
-
w(null), E(null);
|
|
2481
|
-
}, []);
|
|
2482
|
-
return /* @__PURE__ */ p(d, { children: [
|
|
2483
|
-
/* @__PURE__ */ f(ee, {
|
|
2484
|
-
ref: (e) => g.container = e,
|
|
2485
|
-
...k,
|
|
2486
|
-
className: a,
|
|
2487
|
-
style: s ? o : {
|
|
2488
|
-
paddingLeft: 24,
|
|
2489
|
-
...o
|
|
2490
|
-
},
|
|
2491
|
-
onMouseOver: ie,
|
|
2492
|
-
onMouseLeave: L,
|
|
2493
|
-
onDragOver: R,
|
|
2494
|
-
onDragLeave: z,
|
|
2495
|
-
onDrop: B,
|
|
2496
|
-
children: A.map((e, t) => xt(e) ? /* @__PURE__ */ f(Q, { mark: e.tokens[0] }, h.get(e.tokens[0])) : /* @__PURE__ */ f(vt, {
|
|
2497
|
-
blockIndex: t,
|
|
2498
|
-
readOnly: s,
|
|
2499
|
-
alwaysShowHandle: m,
|
|
2500
|
-
onReorder: M,
|
|
2501
|
-
onRequestMenu: N,
|
|
2502
|
-
children: e.tokens.map((e) => /* @__PURE__ */ f(Q, { mark: e }, h.get(e)))
|
|
2503
|
-
}, e.id))
|
|
2504
|
-
}),
|
|
2505
|
-
x !== null && !s && (() => {
|
|
2506
|
-
let e = (g.container?.children[x])?.getBoundingClientRect();
|
|
2507
|
-
return e ? /* @__PURE__ */ f("button", {
|
|
2508
|
-
ref: D,
|
|
2509
|
-
type: "button",
|
|
2510
|
-
draggable: !0,
|
|
2511
|
-
onDragStart: ae,
|
|
2512
|
-
onDragEnd: V,
|
|
2513
|
-
onMouseEnter: I,
|
|
2514
|
-
onMouseLeave: F,
|
|
2515
|
-
onClick: (e) => {
|
|
2516
|
-
e.preventDefault(), D.current && N(x, D.current.getBoundingClientRect());
|
|
2517
|
-
},
|
|
2518
|
-
style: {
|
|
2519
|
-
position: "fixed",
|
|
2520
|
-
top: e.top + e.height / 2 - 12,
|
|
2521
|
-
left: e.left - 24,
|
|
2522
|
-
width: 24,
|
|
2523
|
-
height: 24,
|
|
2524
|
-
display: "flex",
|
|
2525
|
-
alignItems: "center",
|
|
2526
|
-
justifyContent: "center",
|
|
2527
|
-
cursor: C === null ? "grab" : "grabbing",
|
|
2528
|
-
borderRadius: 4,
|
|
2529
|
-
color: "#9ca3af",
|
|
2530
|
-
background: "none",
|
|
2531
|
-
border: "none",
|
|
2532
|
-
padding: 0,
|
|
2533
|
-
zIndex: 100,
|
|
2534
|
-
pointerEvents: "auto",
|
|
2535
|
-
userSelect: "none"
|
|
2536
|
-
},
|
|
2537
|
-
"aria-label": "Drag to reorder or click for options",
|
|
2538
|
-
children: /* @__PURE__ */ f("span", { className: yt })
|
|
2539
|
-
}) : null;
|
|
2540
|
-
})(),
|
|
2541
|
-
T !== null && (() => {
|
|
2542
|
-
let e = (g.container?.children[T.index])?.getBoundingClientRect();
|
|
2543
|
-
return e ? /* @__PURE__ */ f("div", { style: {
|
|
2544
|
-
position: "fixed",
|
|
2545
|
-
left: T.position === "before" ? e.left - 1 : e.right - 1,
|
|
2546
|
-
top: e.top,
|
|
2547
|
-
width: 2,
|
|
2548
|
-
height: e.height,
|
|
2549
|
-
backgroundColor: "#3b82f6",
|
|
2550
|
-
borderRadius: 1,
|
|
2551
|
-
pointerEvents: "none",
|
|
2552
|
-
zIndex: 10
|
|
2553
|
-
} }) : null;
|
|
2554
|
-
})(),
|
|
2555
|
-
_ && /* @__PURE__ */ f(wt, {
|
|
2556
|
-
position: _.position,
|
|
2557
|
-
onAdd: () => {
|
|
2558
|
-
te(_.index), P();
|
|
2559
|
-
},
|
|
2560
|
-
onDelete: () => {
|
|
2561
|
-
ne(_.index), P();
|
|
2562
|
-
},
|
|
2563
|
-
onDuplicate: () => {
|
|
2564
|
-
re(_.index), P();
|
|
2565
|
-
},
|
|
2566
|
-
onClose: P
|
|
2567
|
-
})
|
|
2568
|
-
] });
|
|
2544
|
+
Pt.displayName = "Block";
|
|
2545
|
+
//#endregion
|
|
2546
|
+
//#region src/components/Container.tsx
|
|
2547
|
+
var Ft = t(() => {
|
|
2548
|
+
let e = q(), t = e.state.drag.use(), n = e.state.tokens.use(), r = e.state.className.use(), i = e.state.style.use(), a = e.state.readOnly.use(), o = e.key, s = e.refs, [c, l] = e.slot.container.use();
|
|
2549
|
+
return /* @__PURE__ */ d(c, {
|
|
2550
|
+
ref: (e) => s.container = e,
|
|
2551
|
+
...l,
|
|
2552
|
+
className: r,
|
|
2553
|
+
style: t && !a ? {
|
|
2554
|
+
paddingLeft: 24,
|
|
2555
|
+
...i
|
|
2556
|
+
} : i,
|
|
2557
|
+
children: t ? n.map((e, t) => /* @__PURE__ */ d(Pt, {
|
|
2558
|
+
token: e,
|
|
2559
|
+
blockIndex: t
|
|
2560
|
+
}, o.get(e))) : n.map((e) => /* @__PURE__ */ d(Q, { mark: e }, o.get(e)))
|
|
2561
|
+
});
|
|
2569
2562
|
});
|
|
2570
|
-
|
|
2563
|
+
Ft.displayName = "Container";
|
|
2571
2564
|
//#endregion
|
|
2572
2565
|
//#region src/lib/hooks/useOverlay.tsx
|
|
2573
|
-
function
|
|
2574
|
-
let e =
|
|
2566
|
+
function It() {
|
|
2567
|
+
let e = q(), t = e.state.overlayMatch.use();
|
|
2568
|
+
if (!t) throw Error("useOverlay requires an active overlay match");
|
|
2569
|
+
let r = s(() => F.getAbsolutePosition(), [t]), i = n(() => e.events.clearOverlay(), []);
|
|
2575
2570
|
return {
|
|
2576
2571
|
match: t,
|
|
2577
|
-
style:
|
|
2578
|
-
select:
|
|
2579
|
-
let r =
|
|
2572
|
+
style: r,
|
|
2573
|
+
select: n((n) => {
|
|
2574
|
+
let r = wt(t, n.value, n.meta);
|
|
2580
2575
|
e.events.select({
|
|
2581
2576
|
mark: r,
|
|
2582
2577
|
match: t
|
|
2583
2578
|
}), e.events.clearOverlay();
|
|
2584
2579
|
}, [t]),
|
|
2585
2580
|
close: i,
|
|
2586
|
-
ref:
|
|
2581
|
+
ref: s(() => ({
|
|
2587
2582
|
get current() {
|
|
2588
2583
|
return e.refs.overlay;
|
|
2589
2584
|
},
|
|
@@ -2595,19 +2590,19 @@ function Et() {
|
|
|
2595
2590
|
}
|
|
2596
2591
|
//#endregion
|
|
2597
2592
|
//#region src/components/Suggestions/Suggestions.tsx
|
|
2598
|
-
var
|
|
2599
|
-
let e =
|
|
2593
|
+
var Lt = () => {
|
|
2594
|
+
let e = q(), { match: t, select: n, style: r, ref: a } = It(), [o, u] = l(NaN), f = t.option.overlay?.data ?? [], p = s(() => Ct(f, t.value), [t.value, f]), m = p.length, h = c(o);
|
|
2600
2595
|
h.current = o;
|
|
2601
|
-
let g =
|
|
2602
|
-
return g.current = p,
|
|
2596
|
+
let g = c(p);
|
|
2597
|
+
return g.current = p, i(() => {
|
|
2603
2598
|
let t = e.refs.container;
|
|
2604
2599
|
if (!t) return;
|
|
2605
2600
|
let r = (e) => {
|
|
2606
|
-
let t =
|
|
2601
|
+
let t = Et(e.key, h.current, m);
|
|
2607
2602
|
switch (t.action) {
|
|
2608
2603
|
case "up":
|
|
2609
2604
|
case "down":
|
|
2610
|
-
e.preventDefault(),
|
|
2605
|
+
e.preventDefault(), u(t.index);
|
|
2611
2606
|
break;
|
|
2612
2607
|
case "select": {
|
|
2613
2608
|
e.preventDefault();
|
|
@@ -2618,16 +2613,19 @@ var Dt = () => {
|
|
|
2618
2613
|
});
|
|
2619
2614
|
break;
|
|
2620
2615
|
}
|
|
2616
|
+
case "none": break;
|
|
2621
2617
|
}
|
|
2622
2618
|
};
|
|
2623
2619
|
return t.addEventListener("keydown", r), () => t.removeEventListener("keydown", r);
|
|
2624
|
-
}, [m, n]), p.length ? /* @__PURE__ */
|
|
2625
|
-
ref:
|
|
2626
|
-
|
|
2620
|
+
}, [m, n]), p.length ? /* @__PURE__ */ d("ul", {
|
|
2621
|
+
ref: (e) => {
|
|
2622
|
+
a.current = e;
|
|
2623
|
+
},
|
|
2624
|
+
className: J.Suggestions,
|
|
2627
2625
|
style: r,
|
|
2628
2626
|
children: p.map((e, t) => {
|
|
2629
|
-
let r = t === o ?
|
|
2630
|
-
return /* @__PURE__ */
|
|
2627
|
+
let r = t === o ? J.suggestionActive : void 0;
|
|
2628
|
+
return /* @__PURE__ */ d("li", {
|
|
2631
2629
|
ref: (e) => {
|
|
2632
2630
|
r && e && e.scrollIntoView(!1);
|
|
2633
2631
|
},
|
|
@@ -2640,53 +2638,61 @@ var Dt = () => {
|
|
|
2640
2638
|
}, e);
|
|
2641
2639
|
})
|
|
2642
2640
|
}) : null;
|
|
2643
|
-
},
|
|
2644
|
-
let e =
|
|
2645
|
-
if (n) return /* @__PURE__ */
|
|
2641
|
+
}, Rt = t(() => {
|
|
2642
|
+
let e = q(), t = e.state.overlayMatch.use(), n = s(() => t ? e.key.get(t.option) : void 0, [t]), [r, i] = e.slot.overlay.use(t?.option, Lt);
|
|
2643
|
+
if (n) return /* @__PURE__ */ d(r, { ...i }, n);
|
|
2646
2644
|
});
|
|
2647
|
-
|
|
2645
|
+
Rt.displayName = "OverlayRenderer";
|
|
2646
|
+
//#endregion
|
|
2647
|
+
//#region src/components/Span.tsx
|
|
2648
|
+
var $ = (e) => /* @__PURE__ */ d("span", {});
|
|
2648
2649
|
//#endregion
|
|
2649
2650
|
//#region src/components/MarkedInput.tsx
|
|
2650
|
-
function
|
|
2651
|
-
let { ref: t
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2651
|
+
function zt(e) {
|
|
2652
|
+
let { ref: t } = e, n = m(J.Container, e.className, e.slotProps?.container?.className), r = h(e.style, e.slotProps?.container?.style), [i] = l(() => new Dt({
|
|
2653
|
+
createUseHook: kt,
|
|
2654
|
+
defaultSpan: $
|
|
2655
|
+
}));
|
|
2656
|
+
return i.state.set({
|
|
2657
|
+
value: e.value,
|
|
2658
|
+
defaultValue: e.defaultValue,
|
|
2659
|
+
onChange: e.onChange,
|
|
2660
|
+
readOnly: e.readOnly ?? !1,
|
|
2661
|
+
drag: e.drag ?? !1,
|
|
2662
|
+
options: e.options ?? ie,
|
|
2663
|
+
showOverlayOn: e.showOverlayOn ?? "change",
|
|
2664
|
+
Span: e.Span,
|
|
2665
|
+
Mark: e.Mark,
|
|
2666
|
+
Overlay: e.Overlay,
|
|
2667
|
+
className: n,
|
|
2668
|
+
style: r,
|
|
2669
|
+
slots: e.slots,
|
|
2670
|
+
slotProps: e.slotProps
|
|
2671
|
+
}), At(i, t), /* @__PURE__ */ f(K, {
|
|
2672
|
+
value: i,
|
|
2673
|
+
children: [/* @__PURE__ */ d(Ft, {}), /* @__PURE__ */ d(Rt, {})]
|
|
2670
2674
|
});
|
|
2671
2675
|
}
|
|
2672
2676
|
//#endregion
|
|
2673
2677
|
//#region src/lib/hooks/useMark.tsx
|
|
2674
|
-
var
|
|
2675
|
-
let t =
|
|
2678
|
+
var Bt = (e = {}) => {
|
|
2679
|
+
let t = q(), n = Nt();
|
|
2680
|
+
if (n.type !== "mark") throw Error("useMark must be called within a mark token context");
|
|
2681
|
+
let r = c(null), [a] = l(() => new Ot({
|
|
2676
2682
|
ref: r,
|
|
2677
2683
|
store: t,
|
|
2678
2684
|
token: n
|
|
2679
2685
|
}));
|
|
2680
|
-
|
|
2686
|
+
Vt(r, e, n);
|
|
2681
2687
|
let o = t.state.readOnly.use();
|
|
2682
|
-
return
|
|
2683
|
-
|
|
2684
|
-
}, [o]),
|
|
2688
|
+
return i(() => {
|
|
2689
|
+
a.readOnly = o;
|
|
2690
|
+
}, [o]), a;
|
|
2685
2691
|
};
|
|
2686
|
-
function
|
|
2687
|
-
|
|
2688
|
-
|
|
2692
|
+
function Vt(e, t, n) {
|
|
2693
|
+
i(() => {
|
|
2694
|
+
!t.controlled && e.current && (e.current.textContent = n.content);
|
|
2689
2695
|
}, []);
|
|
2690
2696
|
}
|
|
2691
2697
|
//#endregion
|
|
2692
|
-
export {
|
|
2698
|
+
export { Ot as MarkHandler, zt as MarkedInput, $ as Span, w as annotate, Se as denote, Bt as useMark, It as useOverlay };
|