@markput/react 0.7.0 → 0.9.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 +1131 -1122
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,64 +1,103 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
//#region ../../
|
|
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 ../../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
|
-
//#region ../../
|
|
10
|
-
function
|
|
14
|
+
//#region ../../core/src/shared/utils/cx.ts
|
|
15
|
+
function m(...e) {
|
|
11
16
|
return e.filter(Boolean).join(" ") || void 0;
|
|
12
17
|
}
|
|
13
18
|
//#endregion
|
|
14
|
-
//#region ../../
|
|
15
|
-
function
|
|
19
|
+
//#region ../../core/src/shared/utils/merge.ts
|
|
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
|
-
//#region ../../
|
|
21
|
-
function
|
|
25
|
+
//#region ../../core/src/shared/utils/resolveOptionSlot.ts
|
|
26
|
+
function g(e, t) {
|
|
22
27
|
return e === void 0 ? t : typeof e == "function" ? e(t) : e;
|
|
23
28
|
}
|
|
24
29
|
//#endregion
|
|
25
|
-
//#region ../../
|
|
26
|
-
|
|
30
|
+
//#region ../../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
|
|
35
|
+
//#region ../../core/src/shared/utils/resolveSlot.ts
|
|
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
|
-
//#region ../../
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
63
|
+
//#region ../../core/src/shared/constants.ts
|
|
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
|
-
//#region ../../
|
|
58
|
-
function
|
|
59
|
-
let { segments: n, gapTypes: r, counts: i, valueGapIndices: a } =
|
|
60
|
-
|
|
61
|
-
let o = i.value === 2, { segments: s, gapTypes: c } = o ?
|
|
96
|
+
//#region ../../core/src/features/parsing/parser/core/MarkupDescriptor.ts
|
|
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,
|
|
@@ -157,12 +196,12 @@ function k(e, t, n) {
|
|
|
157
196
|
];
|
|
158
197
|
}
|
|
159
198
|
//#endregion
|
|
160
|
-
//#region ../../
|
|
161
|
-
function
|
|
199
|
+
//#region ../../core/src/features/parsing/parser/core/MarkupRegistry.ts
|
|
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;
|
|
@@ -205,26 +243,34 @@ var j = class {
|
|
|
205
243
|
}
|
|
206
244
|
};
|
|
207
245
|
//#endregion
|
|
208
|
-
//#region ../../
|
|
209
|
-
function
|
|
246
|
+
//#region ../../core/src/features/parsing/parser/utils/getSegmentIndex.ts
|
|
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);
|
|
213
251
|
return n >>>= 0, e * 1e6 + (n & 1048575);
|
|
214
252
|
}
|
|
215
253
|
//#endregion
|
|
216
|
-
//#region ../../
|
|
217
|
-
var
|
|
254
|
+
//#region ../../core/src/features/parsing/parser/core/Match.ts
|
|
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
|
}
|
|
@@ -267,12 +313,12 @@ var te = class {
|
|
|
267
313
|
}
|
|
268
314
|
};
|
|
269
315
|
//#endregion
|
|
270
|
-
//#region ../../
|
|
271
|
-
function
|
|
316
|
+
//#region ../../core/src/features/parsing/parser/core/PatternMatcher.ts
|
|
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
|
-
//#region ../../
|
|
327
|
-
function
|
|
328
|
-
let r =
|
|
329
|
-
return `${r}([^${
|
|
395
|
+
//#region ../../core/src/features/parsing/parser/core/SegmentMatcher.ts
|
|
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
|
+
}, C = (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
|
+
}), ye = 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 C(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
|
-
//#region ../../
|
|
498
|
-
function
|
|
579
|
+
//#region ../../core/src/features/parsing/parser/utils/processTokens.ts
|
|
580
|
+
function w(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 = w(r.children, t), i = {
|
|
503
585
|
...r,
|
|
504
586
|
value: e
|
|
505
587
|
};
|
|
@@ -508,22 +590,22 @@ function L(e, t) {
|
|
|
508
590
|
return n;
|
|
509
591
|
}
|
|
510
592
|
//#endregion
|
|
511
|
-
//#region ../../
|
|
512
|
-
function
|
|
593
|
+
//#region ../../core/src/features/parsing/parser/utils/annotate.ts
|
|
594
|
+
function T(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
|
-
//#region ../../
|
|
518
|
-
function
|
|
599
|
+
//#region ../../core/src/features/parsing/parser/utils/toString.ts
|
|
600
|
+
function E(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 ? E(n.children) : n.slot?.content : void 0;
|
|
608
|
+
t += T(e, {
|
|
527
609
|
value: n.value,
|
|
528
610
|
meta: n.meta,
|
|
529
611
|
slot: i
|
|
@@ -532,31 +614,34 @@ function z(e) {
|
|
|
532
614
|
return t;
|
|
533
615
|
}
|
|
534
616
|
//#endregion
|
|
535
|
-
//#region ../../
|
|
536
|
-
var
|
|
617
|
+
//#region ../../core/src/features/parsing/parser/Parser.ts
|
|
618
|
+
var be = 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 ye(this.parseOptions);
|
|
543
626
|
}
|
|
544
627
|
static parse(t, n) {
|
|
545
628
|
let r = n?.markup;
|
|
546
|
-
|
|
629
|
+
if (!r || r.length === 0) return [C(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 E(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 E(e);
|
|
557
642
|
}
|
|
558
643
|
transform(e, t) {
|
|
559
|
-
return
|
|
644
|
+
return w(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);
|
|
@@ -566,27 +651,27 @@ var B = class e {
|
|
|
566
651
|
}
|
|
567
652
|
};
|
|
568
653
|
//#endregion
|
|
569
|
-
//#region ../../
|
|
570
|
-
function
|
|
571
|
-
return n.length ?
|
|
654
|
+
//#region ../../core/src/features/parsing/parser/utils/denote.ts
|
|
655
|
+
function xe(e, t, n) {
|
|
656
|
+
return n.length ? w(new be(n).parse(e), t) : e;
|
|
572
657
|
}
|
|
573
658
|
//#endregion
|
|
574
|
-
//#region ../../
|
|
575
|
-
function
|
|
659
|
+
//#region ../../core/src/features/parsing/utils/findToken.ts
|
|
660
|
+
function D(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 = D(i.children, t, n + 1, i);
|
|
583
668
|
if (e) return e;
|
|
584
669
|
}
|
|
585
670
|
}
|
|
586
671
|
}
|
|
587
672
|
//#endregion
|
|
588
|
-
//#region ../../
|
|
589
|
-
function
|
|
673
|
+
//#region ../../core/src/features/parsing/preparsing/utils/findGap.ts
|
|
674
|
+
function Se(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]) {
|
|
@@ -604,8 +689,8 @@ function oe(e = "", t = "") {
|
|
|
604
689
|
};
|
|
605
690
|
}
|
|
606
691
|
//#endregion
|
|
607
|
-
//#region ../../
|
|
608
|
-
function
|
|
692
|
+
//#region ../../core/src/features/parsing/preparsing/utils/getClosestIndexes.ts
|
|
693
|
+
function Ce(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);
|
|
@@ -614,50 +699,48 @@ function se(e, t) {
|
|
|
614
699
|
return e[n] == t && (r = n), [n, r].filter((t) => e[t] !== void 0);
|
|
615
700
|
}
|
|
616
701
|
//#endregion
|
|
617
|
-
//#region ../../
|
|
618
|
-
function
|
|
702
|
+
//#region ../../core/src/features/parsing/utils/valueParser.ts
|
|
703
|
+
function we(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 Te(e) {
|
|
710
|
+
let t = e.state.value.get(), n = Ee(e), r = Se(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
|
-
return i.toSpliced(t - 1, 2, ...a);
|
|
633
|
-
}
|
|
634
|
-
case r.left !== void 0: {
|
|
635
|
-
let [t] = se(n, r.left), a = ue(e, t);
|
|
636
|
-
return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
|
|
637
|
-
}
|
|
638
|
-
case r.right !== void 0: {
|
|
639
|
-
let [t] = se(n, r.right), a = ue(e, t);
|
|
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 = O(e, t - 1, t);
|
|
716
|
+
return i.toSpliced(t - 1, 2, ...a);
|
|
643
717
|
}
|
|
718
|
+
if (r.left !== void 0) {
|
|
719
|
+
let [t] = Ce(n, r.left), a = O(e, t);
|
|
720
|
+
return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
|
|
721
|
+
}
|
|
722
|
+
if (r.right !== void 0) {
|
|
723
|
+
let [t] = Ce(n, r.right), a = O(e, t);
|
|
724
|
+
return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
|
|
725
|
+
}
|
|
726
|
+
return k(e, t ?? "");
|
|
644
727
|
}
|
|
645
|
-
function
|
|
728
|
+
function O(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 k(e, n);
|
|
652
735
|
}
|
|
653
|
-
function
|
|
736
|
+
function Ee(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 k(e, t) {
|
|
661
744
|
let n = e.state.parser.get();
|
|
662
745
|
return n ? n.parse(t) : [{
|
|
663
746
|
type: "text",
|
|
@@ -669,13 +752,13 @@ function H(e, t) {
|
|
|
669
752
|
}];
|
|
670
753
|
}
|
|
671
754
|
//#endregion
|
|
672
|
-
//#region ../../
|
|
673
|
-
var
|
|
755
|
+
//#region ../../core/src/shared/classes/Reactive.ts
|
|
756
|
+
var De = (e, t) => e === t, A = 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 ?? De;
|
|
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
|
-
//#region ../../
|
|
704
|
-
function
|
|
792
|
+
//#region ../../core/src/shared/classes/defineState.ts
|
|
793
|
+
function Oe(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 ke(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 A(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 Oe(i, t);
|
|
717
814
|
} });
|
|
718
815
|
}
|
|
719
816
|
//#endregion
|
|
720
|
-
//#region ../../
|
|
721
|
-
function
|
|
722
|
-
|
|
817
|
+
//#region ../../core/src/shared/classes/defineEvents.ts
|
|
818
|
+
function Ae(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 je(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, A.event());
|
|
730
826
|
return new Proxy({}, { get(e, t) {
|
|
731
827
|
let r = n.get(t);
|
|
732
|
-
return r || (r =
|
|
828
|
+
return r || (r = A.event(), n.set(t, r)), Ae(r);
|
|
733
829
|
} });
|
|
734
830
|
}
|
|
735
831
|
//#endregion
|
|
736
|
-
//#region ../../
|
|
737
|
-
|
|
832
|
+
//#region ../../core/src/features/drag/eventHandlers.ts
|
|
833
|
+
function Me(e, t) {
|
|
834
|
+
return e < t.top + t.height / 2 ? "before" : "after";
|
|
835
|
+
}
|
|
836
|
+
function Ne(e) {
|
|
837
|
+
let t = parseInt(e.getData("text/plain"), 10);
|
|
838
|
+
return isNaN(t) ? null : t;
|
|
839
|
+
}
|
|
840
|
+
function Pe(e, t) {
|
|
841
|
+
return t === "before" ? e : e + 1;
|
|
842
|
+
}
|
|
843
|
+
//#endregion
|
|
844
|
+
//#region ../../core/src/shared/utils/menuUtils.ts
|
|
845
|
+
function Fe(e, t) {
|
|
846
|
+
return !!t && !t.contains(e instanceof Node ? e : null);
|
|
847
|
+
}
|
|
848
|
+
function Ie(e) {
|
|
849
|
+
return e.key === "Escape";
|
|
850
|
+
}
|
|
851
|
+
//#endregion
|
|
852
|
+
//#region ../../core/src/shared/classes/BlockStore.ts
|
|
853
|
+
var Le = 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 = ke({
|
|
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(Me(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 = Ne(e.dataTransfer);
|
|
884
|
+
if (t === null) return;
|
|
885
|
+
let r = Pe(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
|
+
Fe(t.target, e) && this.closeMenu();
|
|
914
|
+
}, n = (e) => {
|
|
915
|
+
Ie(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
|
+
}, Re = 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 Le(this.#t), this.#e.set(e, t)), t;
|
|
940
|
+
}
|
|
941
|
+
}, ze = 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 ../../core/src/shared/checkers/domGuards.ts
|
|
950
|
+
function j(e) {
|
|
951
|
+
return typeof HTMLElement < "u" && e instanceof HTMLElement;
|
|
952
|
+
}
|
|
953
|
+
function M(e) {
|
|
954
|
+
return e instanceof Text;
|
|
955
|
+
}
|
|
956
|
+
function N(e, t) {
|
|
957
|
+
let n = e?.children[t];
|
|
958
|
+
return n instanceof HTMLElement ? n : void 0;
|
|
959
|
+
}
|
|
960
|
+
function P(e) {
|
|
961
|
+
return e ? Array.from(e.children).filter((e) => e instanceof HTMLElement) : [];
|
|
962
|
+
}
|
|
963
|
+
function Be(e) {
|
|
964
|
+
let t = e?.firstElementChild;
|
|
965
|
+
return t instanceof HTMLElement ? t : null;
|
|
966
|
+
}
|
|
967
|
+
function Ve(e) {
|
|
968
|
+
let t = e?.lastElementChild;
|
|
969
|
+
return t instanceof HTMLElement ? t : null;
|
|
970
|
+
}
|
|
971
|
+
function He(e) {
|
|
972
|
+
let { target: t } = e;
|
|
973
|
+
return t instanceof Node ? t : null;
|
|
974
|
+
}
|
|
975
|
+
function F(e) {
|
|
976
|
+
let t = e.nextNode();
|
|
977
|
+
return t?.nodeType === 3 ? t : null;
|
|
978
|
+
}
|
|
979
|
+
//#endregion
|
|
980
|
+
//#region ../../core/src/features/caret/Caret.ts
|
|
981
|
+
var I = 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 = F(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 = F(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
|
+
}, Ue = /* @__PURE__ */ new RegExp(/^\w*/), We = class e {
|
|
849
1087
|
span;
|
|
850
1088
|
node;
|
|
851
1089
|
dividedText;
|
|
852
1090
|
constructor() {
|
|
853
|
-
let e =
|
|
854
|
-
this.node =
|
|
1091
|
+
let e = I.getCurrentPosition();
|
|
1092
|
+
this.node = I.getSelectedNode(), this.span = I.getFocusedSpan(), this.dividedText = this.getDividedTextBy(e);
|
|
855
1093
|
}
|
|
856
1094
|
static find(t, n) {
|
|
857
|
-
if (t &&
|
|
1095
|
+
if (t && I.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(Ue)?.[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
|
+
}, Ge = 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 = j(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 I.getCaretIndex(this.target) === 0;
|
|
936
1174
|
}
|
|
937
1175
|
get isCaretAtEnd() {
|
|
938
|
-
if (this.target) return
|
|
1176
|
+
if (this.target) return I.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 ? I.getCaretIndex(this.target) : -1;
|
|
945
1183
|
}
|
|
946
1184
|
set caret(e) {
|
|
947
|
-
this.target &&
|
|
1185
|
+
this.target && I.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 Be(this.#t.refs.container ?? void 0);
|
|
960
1198
|
}
|
|
961
1199
|
get tail() {
|
|
962
|
-
return this.#t.refs.container
|
|
1200
|
+
return Ve(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
|
+
I.setCaretToEnd(this.target);
|
|
972
1210
|
}
|
|
973
1211
|
focus() {
|
|
974
1212
|
this.target?.focus();
|
|
@@ -978,234 +1216,223 @@ var ve = class {
|
|
|
978
1216
|
}
|
|
979
1217
|
};
|
|
980
1218
|
//#endregion
|
|
981
|
-
//#region ../../
|
|
982
|
-
function
|
|
983
|
-
return e.
|
|
1219
|
+
//#region ../../core/src/features/drag/operations.ts
|
|
1220
|
+
function Ke(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;
|
|
1091
|
-
}
|
|
1092
|
-
//#endregion
|
|
1093
|
-
//#region ../../common/core/src/features/blocks/dragOperations.ts
|
|
1094
|
-
function K(e) {
|
|
1095
|
-
return e.tokens.length === 0 || e.tokens[0].type === "text";
|
|
1096
|
-
}
|
|
1097
|
-
function Oe(e, t) {
|
|
1098
|
-
return K(e) && K(t) ? "\n\n" : "";
|
|
1099
|
-
}
|
|
1100
|
-
function ke(e, t, n) {
|
|
1101
|
-
if (t.length === 0) return e + "\n\n";
|
|
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);
|
|
1223
|
+
function L(e) {
|
|
1224
|
+
return e.type === "mark" && e.descriptor.hasSlot && e.descriptor.segments.length === 1;
|
|
1105
1225
|
}
|
|
1106
|
-
function
|
|
1107
|
-
return
|
|
1108
|
-
}
|
|
1109
|
-
function
|
|
1110
|
-
|
|
1111
|
-
if (
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1226
|
+
function R(e, t) {
|
|
1227
|
+
return !!(e.type === "text" && t.type === "text" && t.position.start > e.position.end || L(e) && L(t) && e.descriptor === t.descriptor);
|
|
1228
|
+
}
|
|
1229
|
+
function qe(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);
|
|
1235
|
+
}
|
|
1236
|
+
function Je(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);
|
|
1238
|
+
}
|
|
1239
|
+
function Ye(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 = Ke(e, r, a);
|
|
1243
|
+
return e.slice(0, a.position.start) + i + o + e.slice(a.position.start);
|
|
1244
|
+
}
|
|
1245
|
+
function z(e, t) {
|
|
1246
|
+
if (t <= 0 || t >= e.length) return 0;
|
|
1247
|
+
let n = e[t - 1];
|
|
1248
|
+
return L(n) && n.slot ? n.slot.end : n.position.end;
|
|
1249
|
+
}
|
|
1250
|
+
function B(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 (L(r) && L(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 Xe(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) => Ke(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
|
|
1132
|
-
//#region ../../
|
|
1133
|
-
|
|
1270
|
+
//#region ../../core/src/features/drag/tokens.ts
|
|
1271
|
+
var Ze = {
|
|
1272
|
+
type: "text",
|
|
1273
|
+
content: "",
|
|
1274
|
+
position: {
|
|
1275
|
+
start: 0,
|
|
1276
|
+
end: 0
|
|
1277
|
+
}
|
|
1278
|
+
}, Qe = 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 = Xe(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 : [Ze], i = this.#e();
|
|
1294
|
+
this.store.applyValue(qe(t, r, e, i)), queueMicrotask(() => {
|
|
1295
|
+
let t = this.store.refs.container;
|
|
1296
|
+
t && N(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(Je(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(Ye(t, n, e));
|
|
1310
|
+
}
|
|
1311
|
+
#e() {
|
|
1312
|
+
let e = this.store.state.options.get()?.[0];
|
|
1313
|
+
return e?.markup ? T(e.markup, {
|
|
1314
|
+
value: "",
|
|
1315
|
+
slot: "",
|
|
1316
|
+
meta: ""
|
|
1317
|
+
}) : "\n";
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
//#endregion
|
|
1321
|
+
//#region ../../core/src/features/drag/config.ts
|
|
1322
|
+
function $e(e) {
|
|
1323
|
+
return typeof e == "object" && !!e.alwaysShowHandle;
|
|
1324
|
+
}
|
|
1325
|
+
//#endregion
|
|
1326
|
+
//#region ../../core/src/features/editable/ContentEditableController.ts
|
|
1327
|
+
function et(e) {
|
|
1134
1328
|
return e.tagName === "SPAN" && (e.attributes.length === 0 || e.attributes.length === 1 && e.hasAttribute("contenteditable"));
|
|
1135
1329
|
}
|
|
1136
|
-
var
|
|
1330
|
+
var tt = class {
|
|
1137
1331
|
#e;
|
|
1332
|
+
#t;
|
|
1138
1333
|
constructor(e) {
|
|
1139
1334
|
this.store = e;
|
|
1140
1335
|
}
|
|
1141
1336
|
enable() {
|
|
1142
|
-
this.#e || (this.#e = this.store.state.readOnly.on(() => this.sync()), this.
|
|
1337
|
+
this.#e || (this.#e = this.store.state.readOnly.on(() => this.sync()), this.#t = this.store.state.selecting.on((e) => {
|
|
1338
|
+
e === void 0 && this.sync();
|
|
1339
|
+
}), this.sync());
|
|
1143
1340
|
}
|
|
1144
1341
|
disable() {
|
|
1145
|
-
this.#e?.(), this.#e = void 0;
|
|
1342
|
+
this.#e?.(), this.#e = void 0, this.#t?.(), this.#t = void 0;
|
|
1146
1343
|
}
|
|
1147
1344
|
sync() {
|
|
1148
1345
|
let e = this.store.refs.container;
|
|
1149
1346
|
if (!e) return;
|
|
1150
1347
|
let t = this.store.state.readOnly.get(), n = t ? "false" : "true", r = e.children, i = !!this.store.state.drag.get();
|
|
1151
1348
|
if (i) {
|
|
1152
|
-
let
|
|
1153
|
-
for (let
|
|
1154
|
-
let
|
|
1155
|
-
|
|
1349
|
+
let i = this.store.state.tokens.get();
|
|
1350
|
+
for (let a = 0; a < i.length && a < r.length; a++) {
|
|
1351
|
+
let r = N(e, a);
|
|
1352
|
+
r && (i[a].type === "mark" ? t || (r.tabIndex = 0) : r.contentEditable = n);
|
|
1156
1353
|
}
|
|
1157
|
-
} else for (let
|
|
1354
|
+
} else for (let t = 0; t < r.length; t += 2) {
|
|
1355
|
+
let r = N(e, t);
|
|
1356
|
+
r && (r.contentEditable = n);
|
|
1357
|
+
}
|
|
1158
1358
|
let a = this.store.state.tokens.get();
|
|
1159
|
-
i ? this.#
|
|
1359
|
+
i ? this.#i(a, e, t) : this.#n(a, e);
|
|
1160
1360
|
}
|
|
1161
|
-
#
|
|
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));
|
|
1361
|
+
#n(e, t) {
|
|
1362
|
+
for (let n = 0; n < e.length; n++) {
|
|
1363
|
+
let r = e[n], i = N(t, n);
|
|
1364
|
+
i && (r.type === "text" ? i.textContent !== r.content && (i.textContent = r.content) : r.children.length > 0 && this.#r(r.children, i));
|
|
1166
1365
|
}
|
|
1167
1366
|
}
|
|
1168
|
-
#
|
|
1367
|
+
#r(e, t, n) {
|
|
1169
1368
|
let r = t.children, i = 0;
|
|
1170
|
-
for (let
|
|
1369
|
+
for (let a of e) if (a.type === "text") {
|
|
1171
1370
|
for (; i < r.length;) {
|
|
1172
|
-
let e =
|
|
1173
|
-
if (
|
|
1371
|
+
let e = N(t, i);
|
|
1372
|
+
if (e && et(e)) break;
|
|
1174
1373
|
i++;
|
|
1175
1374
|
}
|
|
1176
|
-
let e =
|
|
1177
|
-
e && (e.textContent !==
|
|
1178
|
-
} else if (
|
|
1375
|
+
let e = N(t, i);
|
|
1376
|
+
e && (e.textContent !== a.content && (e.textContent = a.content), n !== void 0 && (e.contentEditable = n), i++);
|
|
1377
|
+
} else if (a.children.length > 0) {
|
|
1179
1378
|
for (; i < r.length;) {
|
|
1180
|
-
let e =
|
|
1181
|
-
if (!
|
|
1379
|
+
let e = N(t, i);
|
|
1380
|
+
if (e && !et(e)) break;
|
|
1182
1381
|
i++;
|
|
1183
1382
|
}
|
|
1184
|
-
let e =
|
|
1185
|
-
e && (this.#
|
|
1383
|
+
let e = N(t, i);
|
|
1384
|
+
e && (this.#r(a.children, e, n), i++);
|
|
1186
1385
|
}
|
|
1187
1386
|
}
|
|
1188
|
-
#
|
|
1189
|
-
let r = n ? "false" : "true"
|
|
1190
|
-
for (let
|
|
1191
|
-
let a = i
|
|
1387
|
+
#i(e, t, n) {
|
|
1388
|
+
let r = n ? "false" : "true";
|
|
1389
|
+
for (let i = 0; i < e.length; i++) {
|
|
1390
|
+
let a = e[i], o = N(t, i);
|
|
1192
1391
|
if (!o) continue;
|
|
1193
|
-
if (a.
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
t && this.#n(e.children, t, r);
|
|
1392
|
+
if (a.type === "mark") {
|
|
1393
|
+
if (a.children.length > 0) {
|
|
1394
|
+
let e = o.hasAttribute("data-testid") ? N(o, n ? 0 : 1) : o;
|
|
1395
|
+
e && this.#r(a.children, e, r);
|
|
1198
1396
|
}
|
|
1199
1397
|
continue;
|
|
1200
1398
|
}
|
|
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
|
-
}
|
|
1399
|
+
let s = N(o, n ? 0 : 1);
|
|
1400
|
+
s && s.textContent !== a.content && (s.textContent = a.content);
|
|
1206
1401
|
}
|
|
1207
1402
|
}
|
|
1208
|
-
}
|
|
1403
|
+
};
|
|
1404
|
+
//#endregion
|
|
1405
|
+
//#region ../../core/src/features/editing/utils/createNewSpan.ts
|
|
1406
|
+
function nt(e, t, n, r) {
|
|
1407
|
+
return e.slice(0, n) + t + e.slice(n + r.length);
|
|
1408
|
+
}
|
|
1409
|
+
//#endregion
|
|
1410
|
+
//#region ../../core/src/features/editing/utils/deleteMark.ts
|
|
1411
|
+
function V(e, t) {
|
|
1412
|
+
let n = {
|
|
1413
|
+
prev: 2,
|
|
1414
|
+
self: 1,
|
|
1415
|
+
next: 0
|
|
1416
|
+
}[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 ?? "";
|
|
1417
|
+
t.state.tokens.set(i.toSpliced(r.index - n, 0, {
|
|
1418
|
+
type: "text",
|
|
1419
|
+
content: c + l,
|
|
1420
|
+
position: {
|
|
1421
|
+
start: o?.position.start ?? 0,
|
|
1422
|
+
end: s?.position.end ?? (c + l).length
|
|
1423
|
+
}
|
|
1424
|
+
}));
|
|
1425
|
+
let u = r;
|
|
1426
|
+
for (let e = 0; e < n; e++) u = u.prev;
|
|
1427
|
+
let d = u.length;
|
|
1428
|
+
t.state.recovery.set({
|
|
1429
|
+
anchor: u.prev,
|
|
1430
|
+
caret: d
|
|
1431
|
+
}), t.state.onChange.get()?.(E(t.state.tokens.get()));
|
|
1432
|
+
}
|
|
1433
|
+
//#endregion
|
|
1434
|
+
//#region ../../core/src/features/events/SystemListenerController.ts
|
|
1435
|
+
var rt = class {
|
|
1209
1436
|
#e;
|
|
1210
1437
|
#t;
|
|
1211
1438
|
#n;
|
|
@@ -1216,41 +1443,41 @@ var Ie = class {
|
|
|
1216
1443
|
this.#e || (this.#e = this.store.events.change.on(() => {
|
|
1217
1444
|
let e = this.store.state.onChange.get(), { focus: t } = this.store.nodes;
|
|
1218
1445
|
if (!t.target || !t.target.isContentEditable) {
|
|
1219
|
-
let t = this.store.state.tokens.get(), n =
|
|
1446
|
+
let t = this.store.state.tokens.get(), n = E(t);
|
|
1220
1447
|
e?.(n), this.store.state.previousValue.set(n), this.store.state.tokens.set([...t]);
|
|
1221
1448
|
return;
|
|
1222
1449
|
}
|
|
1223
1450
|
let n = this.store.state.tokens.get(), r = n[t.index];
|
|
1224
|
-
r.type === "text" ? r.content = t.content : r.
|
|
1451
|
+
r.type === "text" ? r.content = t.content : r.value = t.content, e?.(E(n)), this.store.events.parse();
|
|
1225
1452
|
}), this.#t = this.store.events.delete.on((e) => {
|
|
1226
|
-
if (!e) return;
|
|
1227
1453
|
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?.(
|
|
1454
|
+
this.store.state.tokens.set(r.toSpliced(i, 1)), n?.(E(this.store.state.tokens.get()));
|
|
1229
1455
|
}), this.#n = this.store.events.select.on((e) => {
|
|
1230
|
-
|
|
1231
|
-
|
|
1456
|
+
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;
|
|
1457
|
+
if (!c) return;
|
|
1458
|
+
let l = r.type === "mark" ? T(c, {
|
|
1232
1459
|
value: r.value,
|
|
1233
1460
|
meta: r.meta
|
|
1234
|
-
}) :
|
|
1461
|
+
}) : T(c, { value: r.content }), u = nt(a, l, o, s);
|
|
1235
1462
|
if (this.store.state.recovery.set(t ? {
|
|
1236
1463
|
caret: 0,
|
|
1237
1464
|
anchor: this.store.nodes.input.next,
|
|
1238
1465
|
isNext: !0,
|
|
1239
1466
|
childIndex: this.store.nodes.input.index
|
|
1240
1467
|
} : {
|
|
1241
|
-
caret: o +
|
|
1468
|
+
caret: o + l.length,
|
|
1242
1469
|
anchor: this.store.nodes.input
|
|
1243
1470
|
}), this.store.nodes.input.target) {
|
|
1244
|
-
this.store.nodes.input.content =
|
|
1471
|
+
this.store.nodes.input.content = u;
|
|
1245
1472
|
let e = this.store.state.tokens.get(), t = e[this.store.nodes.input.index];
|
|
1246
|
-
t.type === "text" && (t.content =
|
|
1473
|
+
t.type === "text" && (t.content = u), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(E(e)), this.store.events.parse();
|
|
1247
1474
|
}
|
|
1248
1475
|
}));
|
|
1249
1476
|
}
|
|
1250
1477
|
disable() {
|
|
1251
1478
|
this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = void 0, this.#n = void 0;
|
|
1252
1479
|
}
|
|
1253
|
-
},
|
|
1480
|
+
}, it = class {
|
|
1254
1481
|
#e;
|
|
1255
1482
|
#t;
|
|
1256
1483
|
#n;
|
|
@@ -1261,17 +1488,21 @@ var Ie = class {
|
|
|
1261
1488
|
if (this.#e) return;
|
|
1262
1489
|
let e = this.store.refs.container;
|
|
1263
1490
|
e && (this.#e = (e) => {
|
|
1264
|
-
|
|
1491
|
+
let t = j(e.target) ? e.target : void 0;
|
|
1492
|
+
this.store.nodes.focus.target = t;
|
|
1265
1493
|
}, this.#t = () => {
|
|
1266
1494
|
this.store.nodes.focus.target = void 0;
|
|
1267
1495
|
}, this.#n = () => {
|
|
1268
1496
|
let e = this.store.state.tokens.get();
|
|
1269
|
-
e.length === 1 && e[0].type === "text" && e[0].content === ""
|
|
1497
|
+
if (e.length === 1 && e[0].type === "text" && e[0].content === "") {
|
|
1498
|
+
let e = this.store.refs.container;
|
|
1499
|
+
(e ? Be(e) : null)?.focus();
|
|
1500
|
+
}
|
|
1270
1501
|
}, e.addEventListener("focusin", this.#e), e.addEventListener("focusout", this.#t), e.addEventListener("click", this.#n));
|
|
1271
1502
|
}
|
|
1272
1503
|
disable() {
|
|
1273
1504
|
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);
|
|
1505
|
+
!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
1506
|
}
|
|
1276
1507
|
recover() {
|
|
1277
1508
|
let e = this.store.state.recovery.get();
|
|
@@ -1279,15 +1510,15 @@ var Ie = class {
|
|
|
1279
1510
|
let { anchor: t, caret: n, isNext: r } = e, i = !t.target || !t.target.isConnected;
|
|
1280
1511
|
switch (!0) {
|
|
1281
1512
|
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
|
|
1513
|
+
let t = this.store.refs.container, n = e.childIndex == null ? void 0 : N(t, e.childIndex + 2);
|
|
1514
|
+
n ? n.focus() : this.store.nodes.focus.tail?.focus();
|
|
1284
1515
|
break;
|
|
1285
1516
|
}
|
|
1286
1517
|
case r:
|
|
1287
1518
|
t.prev.focus();
|
|
1288
1519
|
break;
|
|
1289
1520
|
case i:
|
|
1290
|
-
this.store.nodes.focus.head
|
|
1521
|
+
this.store.nodes.focus.head?.focus();
|
|
1291
1522
|
break;
|
|
1292
1523
|
default: t.next.focus();
|
|
1293
1524
|
}
|
|
@@ -1295,30 +1526,30 @@ var Ie = class {
|
|
|
1295
1526
|
}
|
|
1296
1527
|
};
|
|
1297
1528
|
//#endregion
|
|
1298
|
-
//#region ../../
|
|
1299
|
-
function
|
|
1529
|
+
//#region ../../core/src/features/navigation/navigation.ts
|
|
1530
|
+
function at(e, t) {
|
|
1300
1531
|
let { focus: n } = e.nodes;
|
|
1301
1532
|
if (n.isMark && !n.isEditable || n.isCaretAtBeginning) {
|
|
1302
1533
|
let e = n.prev;
|
|
1303
1534
|
for (; e.target && e.isMark && !e.isEditable;) e = e.prev;
|
|
1304
|
-
return e.target ? (t.preventDefault(), e.target.focus(),
|
|
1535
|
+
return e.target ? (t.preventDefault(), e.target.focus(), I.setCaretToEnd(e.target), !0) : !1;
|
|
1305
1536
|
}
|
|
1306
1537
|
return !1;
|
|
1307
1538
|
}
|
|
1308
|
-
function
|
|
1539
|
+
function ot(e, t) {
|
|
1309
1540
|
let { focus: n } = e.nodes;
|
|
1310
1541
|
if (n.isMark && !n.isEditable || n.isCaretAtEnd) {
|
|
1311
1542
|
let e = n.next;
|
|
1312
1543
|
for (; e.target && e.isMark && !e.isEditable;) e = e.next;
|
|
1313
|
-
return e.target ? (t.preventDefault(), e.target.focus(),
|
|
1544
|
+
return e.target ? (t.preventDefault(), e.target.focus(), I.trySetIndex(e.target, 0), !0) : !1;
|
|
1314
1545
|
}
|
|
1315
1546
|
return !1;
|
|
1316
1547
|
}
|
|
1317
1548
|
//#endregion
|
|
1318
|
-
//#region ../../
|
|
1319
|
-
function
|
|
1549
|
+
//#region ../../core/src/features/selection/selectionHelpers.ts
|
|
1550
|
+
function st(e) {
|
|
1320
1551
|
let t = window.getSelection(), n = e.refs.container;
|
|
1321
|
-
if (!t?.rangeCount || !n?.firstChild || !n
|
|
1552
|
+
if (!t?.rangeCount || !n?.firstChild || !n.lastChild) return !1;
|
|
1322
1553
|
try {
|
|
1323
1554
|
let e = t.getRangeAt(0);
|
|
1324
1555
|
return n.contains(e.startContainer) && n.contains(e.endContainer) && e.toString().length > 0;
|
|
@@ -1326,7 +1557,7 @@ function Ve(e) {
|
|
|
1326
1557
|
return !1;
|
|
1327
1558
|
}
|
|
1328
1559
|
}
|
|
1329
|
-
function
|
|
1560
|
+
function ct(e, t) {
|
|
1330
1561
|
if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
|
|
1331
1562
|
if (e.state.drag.get()) return;
|
|
1332
1563
|
t.preventDefault();
|
|
@@ -1336,249 +1567,294 @@ function He(e, t) {
|
|
|
1336
1567
|
}
|
|
1337
1568
|
}
|
|
1338
1569
|
//#endregion
|
|
1339
|
-
//#region ../../
|
|
1340
|
-
var
|
|
1570
|
+
//#region ../../core/src/features/selection/TextSelectionController.ts
|
|
1571
|
+
var lt = class {
|
|
1341
1572
|
#e;
|
|
1342
1573
|
#t;
|
|
1343
1574
|
#n;
|
|
1344
1575
|
#r;
|
|
1345
|
-
#i
|
|
1346
|
-
#a =
|
|
1576
|
+
#i;
|
|
1577
|
+
#a = null;
|
|
1578
|
+
#o = !1;
|
|
1347
1579
|
constructor(e) {
|
|
1348
1580
|
this.store = e;
|
|
1349
1581
|
}
|
|
1350
1582
|
enable() {
|
|
1351
1583
|
this.#e || (this.#e = (e) => {
|
|
1352
|
-
this.#
|
|
1584
|
+
this.#a = He(e), this.#o = !0;
|
|
1353
1585
|
}, this.#t = (e) => {
|
|
1354
|
-
let t = this
|
|
1355
|
-
|
|
1586
|
+
let t = this.store.refs.container;
|
|
1587
|
+
if (!t) return;
|
|
1588
|
+
let n = this.#o, r = !t.contains(this.#a) || this.#a !== e.target, i = window.getSelection()?.containsNode(t, !0);
|
|
1589
|
+
n && r && i && this.store.state.selecting.get() !== "drag" && this.store.state.selecting.set("drag");
|
|
1356
1590
|
}, this.#n = () => {
|
|
1357
|
-
this.#
|
|
1591
|
+
if (this.#o = !1, this.#a = null, this.store.state.selecting.get() === "drag") {
|
|
1592
|
+
let e = window.getSelection();
|
|
1593
|
+
(!e || e.isCollapsed) && this.store.state.selecting.set(void 0);
|
|
1594
|
+
}
|
|
1358
1595
|
}, this.#r = () => {
|
|
1359
1596
|
if (this.store.state.selecting.get() !== "drag") return;
|
|
1360
|
-
let e =
|
|
1361
|
-
|
|
1362
|
-
},
|
|
1597
|
+
let e = window.getSelection();
|
|
1598
|
+
(!e || e.isCollapsed) && this.store.state.selecting.set(void 0);
|
|
1599
|
+
}, this.#i = this.store.state.selecting.on((e) => {
|
|
1600
|
+
if (e !== "drag") return;
|
|
1601
|
+
let t = this.store.refs.container;
|
|
1602
|
+
t && t.querySelectorAll("[contenteditable=\"true\"]").forEach((e) => e.contentEditable = "false");
|
|
1603
|
+
}), document.addEventListener("mousedown", this.#e), document.addEventListener("mousemove", this.#t), document.addEventListener("mouseup", this.#n), document.addEventListener("selectionchange", this.#r));
|
|
1363
1604
|
}
|
|
1364
1605
|
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.#
|
|
1606
|
+
this.store.state.selecting.get() === "drag" && this.store.state.selecting.set(void 0), this.#i?.(), this.#i = void 0, 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.#a = null, this.#o = !1;
|
|
1366
1607
|
}
|
|
1367
|
-
}
|
|
1608
|
+
};
|
|
1609
|
+
//#endregion
|
|
1610
|
+
//#region ../../core/src/features/input/KeyDownController.ts
|
|
1611
|
+
function ut(e) {
|
|
1612
|
+
return e.type === "text" ? !0 : e.descriptor.hasSlot && e.descriptor.segments.length === 1;
|
|
1613
|
+
}
|
|
1614
|
+
var dt = class {
|
|
1368
1615
|
#e;
|
|
1369
1616
|
#t;
|
|
1370
1617
|
#n;
|
|
1371
1618
|
constructor(e) {
|
|
1372
1619
|
this.store = e;
|
|
1373
1620
|
}
|
|
1621
|
+
#r() {
|
|
1622
|
+
let e = this.store.state.options.get()?.[0];
|
|
1623
|
+
return e?.markup ? T(e.markup, {
|
|
1624
|
+
value: "",
|
|
1625
|
+
slot: "",
|
|
1626
|
+
meta: ""
|
|
1627
|
+
}) : "\n";
|
|
1628
|
+
}
|
|
1374
1629
|
enable() {
|
|
1375
1630
|
if (this.#e) return;
|
|
1376
1631
|
let e = this.store.refs.container;
|
|
1377
1632
|
e && (this.#e = (e) => {
|
|
1378
|
-
e.key ===
|
|
1633
|
+
e.key === y.LEFT ? this.#o(e, "left") || at(this.store, e) : e.key === y.RIGHT ? this.#o(e, "right") || ot(this.store, e) : (e.key === y.UP || e.key === y.DOWN) && this.#s(e), this.#i(e), this.#a(e), ct(this.store, e);
|
|
1379
1634
|
}, this.#t = (e) => {
|
|
1380
|
-
|
|
1635
|
+
mt(this.store, e);
|
|
1381
1636
|
}, this.#n = (e) => {
|
|
1382
|
-
|
|
1637
|
+
ft(this.store, e);
|
|
1383
1638
|
}, e.addEventListener("keydown", this.#e), e.addEventListener("paste", this.#t), e.addEventListener("beforeinput", this.#n, !0));
|
|
1384
1639
|
}
|
|
1385
1640
|
disable() {
|
|
1386
1641
|
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);
|
|
1642
|
+
!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
1643
|
}
|
|
1389
|
-
#
|
|
1644
|
+
#i(e) {
|
|
1390
1645
|
let { focus: t } = this.store.nodes, n = !!this.store.state.drag.get();
|
|
1391
|
-
if (!n && (e.key ===
|
|
1646
|
+
if (!n && (e.key === y.DELETE || e.key === y.BACKSPACE)) {
|
|
1392
1647
|
if (t.isMark) {
|
|
1393
|
-
if (t.isEditable && (e.key ===
|
|
1394
|
-
e.preventDefault(),
|
|
1648
|
+
if (t.isEditable && (e.key === y.BACKSPACE && !t.isCaretAtBeginning || e.key === y.DELETE && !t.isCaretAtEnd)) return;
|
|
1649
|
+
e.preventDefault(), V("self", this.store);
|
|
1395
1650
|
return;
|
|
1396
1651
|
}
|
|
1397
|
-
if (e.key ===
|
|
1398
|
-
e.preventDefault(),
|
|
1652
|
+
if (e.key === y.BACKSPACE && t.isSpan && t.isCaretAtBeginning && t.prev.target) {
|
|
1653
|
+
e.preventDefault(), V("prev", this.store);
|
|
1399
1654
|
return;
|
|
1400
1655
|
}
|
|
1401
|
-
if (e.key ===
|
|
1402
|
-
e.preventDefault(),
|
|
1656
|
+
if (e.key === y.DELETE && t.isSpan && t.isCaretAtEnd && t.next.target) {
|
|
1657
|
+
e.preventDefault(), V("next", this.store);
|
|
1403
1658
|
return;
|
|
1404
1659
|
}
|
|
1405
1660
|
}
|
|
1406
1661
|
if (!n) return;
|
|
1407
1662
|
let r = this.store.refs.container;
|
|
1408
1663
|
if (!r) return;
|
|
1409
|
-
let i =
|
|
1664
|
+
let i = P(r), a = i.findIndex((e) => e === document.activeElement || e.contains(document.activeElement));
|
|
1410
1665
|
if (a === -1) return;
|
|
1411
|
-
let o =
|
|
1666
|
+
let o = this.store.state.tokens.get();
|
|
1412
1667
|
if (a >= o.length) return;
|
|
1413
1668
|
let s = o[a], c = this.store.state.previousValue.get() ?? this.store.state.value.get() ?? "";
|
|
1414
1669
|
if (this.store.state.onChange.get()) {
|
|
1415
|
-
if (e.key ===
|
|
1416
|
-
let t = i[a], n =
|
|
1417
|
-
if (
|
|
1670
|
+
if (e.key === y.BACKSPACE) {
|
|
1671
|
+
let t = i[a], n = I.getCaretIndex(t) === 0;
|
|
1672
|
+
if (("content" in s ? s.content : "") === "") {
|
|
1418
1673
|
e.preventDefault();
|
|
1419
|
-
let t = o.length <= 1 ? "" : a >= o.length - 1 ? c.slice(0, o[a - 1].
|
|
1674
|
+
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
1675
|
this.store.applyValue(t), queueMicrotask(() => {
|
|
1421
|
-
let e = r
|
|
1422
|
-
e && (e.focus(),
|
|
1676
|
+
let e = N(r, Math.max(0, a - 1));
|
|
1677
|
+
e && (e.focus(), I.setCaretToEnd(e));
|
|
1423
1678
|
});
|
|
1424
1679
|
return;
|
|
1425
1680
|
}
|
|
1426
1681
|
if (n && a > 0) {
|
|
1427
|
-
let t = o[a - 1], n = o[a]
|
|
1428
|
-
if (
|
|
1682
|
+
let t = o[a - 1], n = o[a];
|
|
1683
|
+
if (R(t, n)) {
|
|
1429
1684
|
e.preventDefault();
|
|
1430
|
-
let t =
|
|
1685
|
+
let t = z(o, a), n = B(c, o, a);
|
|
1431
1686
|
this.store.applyValue(n), queueMicrotask(() => {
|
|
1432
|
-
let e = r
|
|
1687
|
+
let e = N(r, a - 1);
|
|
1433
1688
|
if (e) {
|
|
1434
1689
|
e.focus();
|
|
1435
|
-
let n =
|
|
1436
|
-
|
|
1690
|
+
let n = this.store.state.tokens.get()[a - 1];
|
|
1691
|
+
U(e, n, t);
|
|
1437
1692
|
}
|
|
1438
1693
|
});
|
|
1439
1694
|
return;
|
|
1440
1695
|
}
|
|
1441
1696
|
e.preventDefault(), queueMicrotask(() => {
|
|
1442
1697
|
let e = i[a - 1];
|
|
1443
|
-
e
|
|
1698
|
+
e.focus(), t.type !== "mark" && I.setCaretToEnd(e);
|
|
1444
1699
|
});
|
|
1445
1700
|
return;
|
|
1446
1701
|
}
|
|
1447
1702
|
}
|
|
1448
|
-
if (e.key ===
|
|
1449
|
-
let t = i[a], n =
|
|
1703
|
+
if (e.key === y.DELETE) {
|
|
1704
|
+
let t = i[a], n = I.getCaretIndex(t), s = n === t.textContent.length;
|
|
1450
1705
|
if (n === 0 && a > 0) {
|
|
1451
|
-
let t = o[a - 1], n = o[a]
|
|
1452
|
-
if (
|
|
1706
|
+
let t = o[a - 1], n = o[a];
|
|
1707
|
+
if (R(t, n)) {
|
|
1453
1708
|
e.preventDefault();
|
|
1454
|
-
let t =
|
|
1709
|
+
let t = z(o, a), n = B(c, o, a);
|
|
1455
1710
|
this.store.applyValue(n), queueMicrotask(() => {
|
|
1456
|
-
let e = r
|
|
1711
|
+
let e = N(r, a - 1);
|
|
1457
1712
|
if (e) {
|
|
1458
1713
|
e.focus();
|
|
1459
|
-
let n =
|
|
1460
|
-
|
|
1714
|
+
let n = this.store.state.tokens.get()[a - 1];
|
|
1715
|
+
U(e, n, t);
|
|
1461
1716
|
}
|
|
1462
1717
|
});
|
|
1463
1718
|
return;
|
|
1464
1719
|
}
|
|
1465
1720
|
e.preventDefault(), queueMicrotask(() => {
|
|
1466
1721
|
let e = i[a - 1];
|
|
1467
|
-
e
|
|
1722
|
+
e.focus(), t.type !== "mark" && I.setCaretToEnd(e);
|
|
1468
1723
|
});
|
|
1469
1724
|
return;
|
|
1470
1725
|
}
|
|
1471
1726
|
if (s && a < o.length - 1) {
|
|
1472
|
-
let t = o[a], n = o[a + 1]
|
|
1473
|
-
if (
|
|
1727
|
+
let t = o[a], n = o[a + 1];
|
|
1728
|
+
if (R(t, n)) {
|
|
1474
1729
|
e.preventDefault();
|
|
1475
|
-
let
|
|
1476
|
-
this.store.applyValue(
|
|
1477
|
-
let e = r
|
|
1730
|
+
let t = z(o, a + 1), n = B(c, o, a + 1);
|
|
1731
|
+
this.store.applyValue(n), queueMicrotask(() => {
|
|
1732
|
+
let e = N(r, a);
|
|
1478
1733
|
if (e) {
|
|
1479
1734
|
e.focus();
|
|
1480
|
-
let
|
|
1481
|
-
|
|
1735
|
+
let n = this.store.state.tokens.get()[a];
|
|
1736
|
+
U(e, n, t);
|
|
1482
1737
|
}
|
|
1483
1738
|
});
|
|
1484
1739
|
return;
|
|
1485
1740
|
}
|
|
1486
1741
|
e.preventDefault(), queueMicrotask(() => {
|
|
1487
1742
|
let e = i[a + 1];
|
|
1488
|
-
e
|
|
1743
|
+
e.focus(), I.trySetIndex(e, 0);
|
|
1489
1744
|
});
|
|
1490
1745
|
return;
|
|
1491
1746
|
}
|
|
1492
1747
|
}
|
|
1493
1748
|
}
|
|
1494
1749
|
}
|
|
1495
|
-
#
|
|
1496
|
-
if (!this.store.state.drag.get() || e.key !==
|
|
1750
|
+
#a(e) {
|
|
1751
|
+
if (!this.store.state.drag.get() || e.key !== y.ENTER || e.shiftKey) return;
|
|
1497
1752
|
let t = this.store.refs.container;
|
|
1498
1753
|
if (!t) return;
|
|
1499
1754
|
let n = document.activeElement;
|
|
1500
|
-
if (!n || !t.contains(n)) return;
|
|
1755
|
+
if (!j(n) || !t.contains(n)) return;
|
|
1501
1756
|
e.preventDefault();
|
|
1502
|
-
let r = t
|
|
1757
|
+
let r = P(t), i = -1;
|
|
1503
1758
|
for (let e = 0; e < r.length; e++) if (r[e] === n || r[e].contains(n)) {
|
|
1504
1759
|
i = e;
|
|
1505
1760
|
break;
|
|
1506
1761
|
}
|
|
1507
1762
|
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() ?? "";
|
|
1763
|
+
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
1764
|
if (!this.store.state.onChange.get()) return;
|
|
1512
|
-
|
|
1513
|
-
|
|
1765
|
+
let l = this.#r();
|
|
1766
|
+
if (!ut(o)) {
|
|
1767
|
+
let e = qe(c, a, i, l);
|
|
1514
1768
|
this.store.applyValue(e), queueMicrotask(() => {
|
|
1515
|
-
let e =
|
|
1516
|
-
if (
|
|
1517
|
-
let
|
|
1518
|
-
|
|
1769
|
+
let e = i + 1;
|
|
1770
|
+
if (e < t.children.length) {
|
|
1771
|
+
let n = N(t, e);
|
|
1772
|
+
n && (n.focus(), I.trySetIndex(n, 0));
|
|
1519
1773
|
}
|
|
1520
1774
|
});
|
|
1521
1775
|
return;
|
|
1522
1776
|
}
|
|
1523
|
-
let
|
|
1777
|
+
let u = H(s, o), d = c.slice(0, u) + l + c.slice(u);
|
|
1524
1778
|
this.store.applyValue(d), queueMicrotask(() => {
|
|
1525
|
-
let e =
|
|
1526
|
-
if (
|
|
1527
|
-
let
|
|
1528
|
-
|
|
1779
|
+
let e = i + 1;
|
|
1780
|
+
if (e < t.children.length) {
|
|
1781
|
+
let n = N(t, e);
|
|
1782
|
+
n && (n.focus(), I.trySetIndex(n, 0));
|
|
1529
1783
|
}
|
|
1530
1784
|
});
|
|
1531
1785
|
}
|
|
1532
|
-
#
|
|
1786
|
+
#o(e, t) {
|
|
1787
|
+
if (!this.store.state.drag.get()) return !1;
|
|
1788
|
+
let n = this.store.refs.container;
|
|
1789
|
+
if (!n) return !1;
|
|
1790
|
+
let r = document.activeElement;
|
|
1791
|
+
if (!j(r) || !n.contains(r)) return !1;
|
|
1792
|
+
let i = P(n), a = i.findIndex((e) => e === r || e.contains(r));
|
|
1793
|
+
if (a === -1) return !1;
|
|
1794
|
+
let o = i[a];
|
|
1795
|
+
if (t === "left") {
|
|
1796
|
+
if (I.getCaretIndex(o) !== 0) return !1;
|
|
1797
|
+
if (a === 0) return !0;
|
|
1798
|
+
e.preventDefault();
|
|
1799
|
+
let t = i[a - 1];
|
|
1800
|
+
return t.focus(), I.setCaretToEnd(t), !0;
|
|
1801
|
+
}
|
|
1802
|
+
if (I.getCaretIndex(o) !== o.textContent.length) return !1;
|
|
1803
|
+
if (a >= i.length - 1) return !0;
|
|
1804
|
+
e.preventDefault();
|
|
1805
|
+
let s = i[a + 1];
|
|
1806
|
+
return s.focus(), I.trySetIndex(s, 0), !0;
|
|
1807
|
+
}
|
|
1808
|
+
#s(e) {
|
|
1533
1809
|
if (!this.store.state.drag.get()) return;
|
|
1534
1810
|
let t = this.store.refs.container;
|
|
1535
1811
|
if (!t) return;
|
|
1536
1812
|
let n = document.activeElement;
|
|
1537
|
-
if (!n || !t.contains(n)) return;
|
|
1538
|
-
let r =
|
|
1813
|
+
if (!j(n) || !t.contains(n)) return;
|
|
1814
|
+
let r = P(t), i = r.findIndex((e) => e === n || e.contains(n));
|
|
1539
1815
|
if (i === -1) return;
|
|
1540
1816
|
let a = r[i];
|
|
1541
|
-
if (e.key ===
|
|
1542
|
-
if (!
|
|
1817
|
+
if (e.key === y.UP) {
|
|
1818
|
+
if (!I.isCaretOnFirstLine(a) || i === 0) return;
|
|
1543
1819
|
e.preventDefault();
|
|
1544
|
-
let t =
|
|
1820
|
+
let t = I.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i - 1];
|
|
1545
1821
|
n.focus();
|
|
1546
1822
|
let o = n.getBoundingClientRect();
|
|
1547
|
-
|
|
1548
|
-
} else if (e.key ===
|
|
1549
|
-
if (!
|
|
1823
|
+
I.setAtX(n, t, o.bottom - 4);
|
|
1824
|
+
} else if (e.key === y.DOWN) {
|
|
1825
|
+
if (!I.isCaretOnLastLine(a) || i >= r.length - 1) return;
|
|
1550
1826
|
e.preventDefault();
|
|
1551
|
-
let t =
|
|
1827
|
+
let t = I.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i + 1];
|
|
1552
1828
|
n.focus();
|
|
1553
1829
|
let o = n.getBoundingClientRect();
|
|
1554
|
-
|
|
1830
|
+
I.setAtX(n, t, o.top + 4);
|
|
1555
1831
|
}
|
|
1556
1832
|
}
|
|
1557
1833
|
};
|
|
1558
|
-
function
|
|
1834
|
+
function H(e, t) {
|
|
1559
1835
|
let n = window.getSelection();
|
|
1560
|
-
if (!n?.rangeCount) return t.
|
|
1836
|
+
if (!n?.rangeCount) return t.position.end;
|
|
1561
1837
|
let { focusNode: r, focusOffset: i } = n;
|
|
1562
|
-
return r ?
|
|
1838
|
+
return r ? W(r, i, e, t) : t.position.end;
|
|
1563
1839
|
}
|
|
1564
|
-
function
|
|
1840
|
+
function ft(e, t) {
|
|
1565
1841
|
let n = e.state.selecting.get();
|
|
1566
|
-
if (n === "all" &&
|
|
1842
|
+
if (n === "all" && st(e)) {
|
|
1567
1843
|
if (t.inputType === "insertFromPaste") {
|
|
1568
1844
|
t.preventDefault();
|
|
1569
1845
|
return;
|
|
1570
1846
|
}
|
|
1571
|
-
t.preventDefault(),
|
|
1847
|
+
t.preventDefault(), ht(e, t.inputType.startsWith("delete") ? "" : t.data ?? "");
|
|
1572
1848
|
return;
|
|
1573
1849
|
}
|
|
1574
1850
|
if (n === "all" && e.state.selecting.set(void 0), e.state.drag.get()) {
|
|
1575
|
-
|
|
1851
|
+
gt(e, t);
|
|
1576
1852
|
return;
|
|
1577
1853
|
}
|
|
1578
1854
|
let { focus: r } = e.nodes;
|
|
1579
|
-
!r.target || !r.isEditable ||
|
|
1855
|
+
!r.target || !r.isEditable || pt(r, t) && e.events.change();
|
|
1580
1856
|
}
|
|
1581
|
-
function
|
|
1857
|
+
function pt(e, t) {
|
|
1582
1858
|
let n = e.caret, r = e.content, i, a;
|
|
1583
1859
|
switch (t.inputType) {
|
|
1584
1860
|
case "insertText": {
|
|
@@ -1610,15 +1886,15 @@ function qe(e, t) {
|
|
|
1610
1886
|
}
|
|
1611
1887
|
return e.content = i, e.caret = a, !0;
|
|
1612
1888
|
}
|
|
1613
|
-
function
|
|
1889
|
+
function mt(e, t) {
|
|
1614
1890
|
let n = e.state.selecting.get();
|
|
1615
|
-
if (n !== "all" || !
|
|
1891
|
+
if (n !== "all" || !st(e)) {
|
|
1616
1892
|
n === "all" && e.state.selecting.set(void 0);
|
|
1617
1893
|
return;
|
|
1618
1894
|
}
|
|
1619
|
-
t.preventDefault(),
|
|
1895
|
+
t.preventDefault(), ht(e, t.clipboardData?.getData("text/plain") ?? "");
|
|
1620
1896
|
}
|
|
1621
|
-
function
|
|
1897
|
+
function ht(e, t) {
|
|
1622
1898
|
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
1899
|
type: "text",
|
|
1624
1900
|
content: t,
|
|
@@ -1627,29 +1903,29 @@ function Ye(e, t) {
|
|
|
1627
1903
|
end: t.length
|
|
1628
1904
|
}
|
|
1629
1905
|
}]), queueMicrotask(() => {
|
|
1630
|
-
let n = e.refs.container?.firstChild;
|
|
1631
|
-
|
|
1906
|
+
let n = e.refs.container?.firstChild, r = j(n) ? n : null;
|
|
1907
|
+
r && (e.state.recovery.set({
|
|
1632
1908
|
anchor: e.nodes.focus,
|
|
1633
1909
|
caret: t.length
|
|
1634
|
-
}),
|
|
1910
|
+
}), r.focus());
|
|
1635
1911
|
});
|
|
1636
1912
|
}
|
|
1637
|
-
function
|
|
1913
|
+
function gt(e, t) {
|
|
1638
1914
|
let n = e.refs.container;
|
|
1639
1915
|
if (!n) return;
|
|
1640
1916
|
let r = document.activeElement;
|
|
1641
|
-
if (!r || !n.contains(r)) return;
|
|
1642
|
-
let i =
|
|
1917
|
+
if (!j(r) || !n.contains(r)) return;
|
|
1918
|
+
let i = P(n), a = i.findIndex((e) => e === r || e.contains(r));
|
|
1643
1919
|
if (a === -1) return;
|
|
1644
|
-
let o = i[a], s =
|
|
1920
|
+
let o = i[a], s = e.state.tokens.get();
|
|
1645
1921
|
if (a >= s.length) return;
|
|
1646
1922
|
let c = s[a], l = e.state.previousValue.get() ?? e.state.value.get() ?? "", u = (t) => {
|
|
1647
1923
|
queueMicrotask(() => {
|
|
1648
|
-
let r = n
|
|
1924
|
+
let r = N(n, a);
|
|
1649
1925
|
if (!r) return;
|
|
1650
1926
|
r.focus();
|
|
1651
|
-
let i =
|
|
1652
|
-
|
|
1927
|
+
let i = e.state.tokens.get()[a];
|
|
1928
|
+
U(r, i, t);
|
|
1653
1929
|
});
|
|
1654
1930
|
};
|
|
1655
1931
|
switch (t.inputType) {
|
|
@@ -1657,9 +1933,9 @@ function Xe(e, t) {
|
|
|
1657
1933
|
t.preventDefault();
|
|
1658
1934
|
let n = t.data ?? "", r = t.getTargetRanges(), i, a;
|
|
1659
1935
|
if (r.length > 0) {
|
|
1660
|
-
let e =
|
|
1936
|
+
let e = W(r[0].startContainer, r[0].startOffset, o, c), t = W(r[0].endContainer, r[0].endOffset, o, c);
|
|
1661
1937
|
[i, a] = e <= t ? [e, t] : [t, e];
|
|
1662
|
-
} else i = a =
|
|
1938
|
+
} else i = a = H(o, c);
|
|
1663
1939
|
e.applyValue(l.slice(0, i) + n + l.slice(a)), u(i + n.length);
|
|
1664
1940
|
break;
|
|
1665
1941
|
}
|
|
@@ -1668,9 +1944,9 @@ function Xe(e, t) {
|
|
|
1668
1944
|
t.preventDefault();
|
|
1669
1945
|
let n = t.dataTransfer?.getData("text/plain") ?? "", r = t.getTargetRanges(), i, a;
|
|
1670
1946
|
if (r.length > 0) {
|
|
1671
|
-
let e =
|
|
1947
|
+
let e = W(r[0].startContainer, r[0].startOffset, o, c), t = W(r[0].endContainer, r[0].endOffset, o, c);
|
|
1672
1948
|
[i, a] = e <= t ? [e, t] : [t, e];
|
|
1673
|
-
} else i = a =
|
|
1949
|
+
} else i = a = H(o, c);
|
|
1674
1950
|
e.applyValue(l.slice(0, i) + n + l.slice(a)), u(i + n.length);
|
|
1675
1951
|
break;
|
|
1676
1952
|
}
|
|
@@ -1682,30 +1958,30 @@ function Xe(e, t) {
|
|
|
1682
1958
|
case "deleteSoftLineForward": {
|
|
1683
1959
|
let n = t.getTargetRanges();
|
|
1684
1960
|
if (!n.length) return;
|
|
1685
|
-
let r =
|
|
1961
|
+
let r = W(n[0].startContainer, n[0].startOffset, o, c), i = W(n[0].endContainer, n[0].endOffset, o, c), [a, s] = r <= i ? [r, i] : [i, r];
|
|
1686
1962
|
if (a === s) return;
|
|
1687
1963
|
t.preventDefault(), e.applyValue(l.slice(0, a) + l.slice(s)), u(a);
|
|
1688
1964
|
break;
|
|
1689
1965
|
}
|
|
1690
1966
|
}
|
|
1691
1967
|
}
|
|
1692
|
-
function
|
|
1968
|
+
function _t(e) {
|
|
1693
1969
|
return e.tagName === "SPAN" && (e.attributes.length === 0 || e.attributes.length === 1 && e.hasAttribute("contenteditable"));
|
|
1694
1970
|
}
|
|
1695
|
-
function
|
|
1971
|
+
function vt(e, t, n) {
|
|
1696
1972
|
let r = window.getSelection();
|
|
1697
1973
|
if (!r) return !1;
|
|
1698
1974
|
let i = 0;
|
|
1699
1975
|
for (let a of Array.from(e.childNodes)) {
|
|
1700
1976
|
if (i >= t.children.length) break;
|
|
1701
1977
|
let e = t.children[i];
|
|
1702
|
-
if (a
|
|
1703
|
-
if (!
|
|
1978
|
+
if (j(a) && e.type === "text") {
|
|
1979
|
+
if (!_t(a)) continue;
|
|
1704
1980
|
if (n >= e.position.start && n <= e.position.end) {
|
|
1705
|
-
let t = a.firstChild, i = n - e.position.start;
|
|
1706
|
-
if (
|
|
1981
|
+
let t = a.firstChild, i = M(t) ? t : null, o = n - e.position.start;
|
|
1982
|
+
if (i) {
|
|
1707
1983
|
let e = document.createRange();
|
|
1708
|
-
e.setStart(
|
|
1984
|
+
e.setStart(i, Math.min(o, i.length)), e.collapse(!0), r.removeAllRanges(), r.addRange(e);
|
|
1709
1985
|
} else {
|
|
1710
1986
|
let e = document.createRange();
|
|
1711
1987
|
e.setStart(a, 0), e.collapse(!0), r.removeAllRanges(), r.addRange(e);
|
|
@@ -1713,72 +1989,48 @@ function Qe(e, t, n) {
|
|
|
1713
1989
|
return !0;
|
|
1714
1990
|
}
|
|
1715
1991
|
i++;
|
|
1716
|
-
} else if (a
|
|
1992
|
+
} else if (M(a) && e.type === "text") {
|
|
1717
1993
|
if (n >= e.position.start && n <= e.position.end) {
|
|
1718
1994
|
let t = Math.min(n - e.position.start, a.length), i = document.createRange();
|
|
1719
1995
|
return i.setStart(a, t), i.collapse(!0), r.removeAllRanges(), r.addRange(i), !0;
|
|
1720
1996
|
}
|
|
1721
1997
|
i++;
|
|
1722
|
-
} else if (a
|
|
1998
|
+
} else if (j(a) && e.type === "mark") {
|
|
1723
1999
|
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
|
|
2000
|
+
if (!(n === e.position.end && r?.position.start === n) && n >= e.position.start && n <= e.position.end) return vt(a, e, n);
|
|
1725
2001
|
i++;
|
|
1726
2002
|
}
|
|
1727
2003
|
}
|
|
1728
2004
|
return !1;
|
|
1729
2005
|
}
|
|
1730
|
-
function
|
|
2006
|
+
function U(e, t, n) {
|
|
1731
2007
|
let r = window.getSelection();
|
|
1732
2008
|
if (!r) return;
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
U.setCaretToEnd(e);
|
|
2009
|
+
if (t.type === "mark") {
|
|
2010
|
+
if (vt(e, t, n)) return;
|
|
2011
|
+
I.setCaretToEnd(e);
|
|
1737
2012
|
return;
|
|
1738
2013
|
}
|
|
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
|
-
}
|
|
2014
|
+
let i = n - t.position.start, a = F(document.createTreeWalker(e, 4));
|
|
2015
|
+
if (a) {
|
|
2016
|
+
let e = Math.min(i, a.length), t = document.createRange();
|
|
2017
|
+
t.setStart(a, e), t.collapse(!0), r.removeAllRanges(), r.addRange(t);
|
|
2018
|
+
return;
|
|
1755
2019
|
}
|
|
1756
|
-
|
|
2020
|
+
I.setCaretToEnd(e);
|
|
1757
2021
|
}
|
|
1758
|
-
function
|
|
2022
|
+
function W(e, t, n, r) {
|
|
1759
2023
|
if (e === n) {
|
|
1760
2024
|
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;
|
|
2025
|
+
return e?.focusNode && e.focusNode !== n ? W(e.focusNode, e.focusOffset, n, r) : r.position.end;
|
|
1766
2026
|
}
|
|
2027
|
+
if (e.nodeType === Node.TEXT_NODE && e.parentElement === n) return r.type === "mark" ? G(e, t, n, r) : r.position.start + Math.min(t, r.content.length);
|
|
1767
2028
|
let i = e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement;
|
|
1768
2029
|
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) {
|
|
2030
|
+
return i ? r.type === "mark" ? G(e, t, n, r) : r.position.start + Math.min(t, r.content.length) : r.position.end;
|
|
2031
|
+
}
|
|
2032
|
+
function G(e, t, n, r) {
|
|
2033
|
+
if (r.children.length === 0) {
|
|
1782
2034
|
if (t === 0) return r.position.start;
|
|
1783
2035
|
let e = r.slot?.content.length ?? r.value.length;
|
|
1784
2036
|
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,27 +2039,27 @@ function Y(e, t, n, r) {
|
|
|
1787
2039
|
for (let a of Array.from(n.childNodes)) {
|
|
1788
2040
|
if (i >= r.children.length) break;
|
|
1789
2041
|
let n = r.children[i];
|
|
1790
|
-
if (a
|
|
1791
|
-
if (!
|
|
2042
|
+
if (j(a) && n.type === "text") {
|
|
2043
|
+
if (!_t(a)) continue;
|
|
1792
2044
|
if (e === a) {
|
|
1793
2045
|
let e = t === 0 ? 0 : n.content.length;
|
|
1794
2046
|
return n.position.start + Math.min(e, n.content.length);
|
|
1795
2047
|
}
|
|
1796
2048
|
if (a.contains(e)) return n.position.start + Math.min(t, n.content.length);
|
|
1797
2049
|
i++;
|
|
1798
|
-
} else if (a
|
|
2050
|
+
} else if (M(a) && n.type === "text") {
|
|
1799
2051
|
if (e === a) return n.position.start + Math.min(t, n.content.length);
|
|
1800
2052
|
i++;
|
|
1801
|
-
} else if (a
|
|
1802
|
-
if (a === e || a.contains(e)) return
|
|
2053
|
+
} else if (j(a) && n.type === "mark") {
|
|
2054
|
+
if (a === e || a.contains(e)) return G(e, t, a, n);
|
|
1803
2055
|
i++;
|
|
1804
2056
|
}
|
|
1805
2057
|
}
|
|
1806
2058
|
return r.slot?.end ?? r.position.end;
|
|
1807
2059
|
}
|
|
1808
2060
|
//#endregion
|
|
1809
|
-
//#region ../../
|
|
1810
|
-
var
|
|
2061
|
+
//#region ../../core/src/features/feature-manager/FeatureManager.ts
|
|
2062
|
+
var yt = class {
|
|
1811
2063
|
#e = [];
|
|
1812
2064
|
#t = !1;
|
|
1813
2065
|
register(e) {
|
|
@@ -1819,21 +2071,21 @@ var $e = class {
|
|
|
1819
2071
|
disableAll() {
|
|
1820
2072
|
this.#t && (this.#t = !1, this.#e.forEach((e) => e.disable()));
|
|
1821
2073
|
}
|
|
1822
|
-
},
|
|
2074
|
+
}, K = (e, t) => ({
|
|
1823
2075
|
name: e,
|
|
1824
2076
|
enable: () => t.enable(),
|
|
1825
2077
|
disable: () => t.disable()
|
|
1826
|
-
}),
|
|
1827
|
-
let t = new
|
|
1828
|
-
return t.register(
|
|
1829
|
-
},
|
|
2078
|
+
}), bt = (e) => {
|
|
2079
|
+
let t = new yt();
|
|
2080
|
+
return t.register(K("keydown", e.controllers.keydown)).register(K("system", e.controllers.system)).register(K("focus", e.controllers.focus)).register(K("textSelection", e.controllers.textSelection)).register(K("contentEditable", e.controllers.contentEditable)), t;
|
|
2081
|
+
}, xt = class {
|
|
1830
2082
|
#e = [];
|
|
1831
2083
|
#t = !1;
|
|
1832
2084
|
constructor(e) {
|
|
1833
2085
|
this.store = e;
|
|
1834
2086
|
}
|
|
1835
2087
|
enable(e) {
|
|
1836
|
-
let { store: t } = this, n =
|
|
2088
|
+
let { store: t } = this, n = bt(t);
|
|
1837
2089
|
n.enableAll(), this.#e.push(() => n.disableAll()), this.#n(), e?.getTrigger && this.#r(e.getTrigger);
|
|
1838
2090
|
}
|
|
1839
2091
|
disable() {
|
|
@@ -1842,12 +2094,16 @@ var $e = class {
|
|
|
1842
2094
|
}
|
|
1843
2095
|
syncParser(e, t) {
|
|
1844
2096
|
let { store: n } = this, r = t?.map((e) => e.markup);
|
|
1845
|
-
if (r
|
|
2097
|
+
if (r?.some(Boolean)) {
|
|
2098
|
+
let e = n.state.drag.get() ? { skipEmptyText: !0 } : void 0;
|
|
2099
|
+
n.state.parser.set(new be(r, e));
|
|
2100
|
+
} else n.state.parser.set(void 0);
|
|
2101
|
+
if (this.#t) {
|
|
1846
2102
|
n.state.recovery.get() || n.events.parse();
|
|
1847
2103
|
return;
|
|
1848
2104
|
}
|
|
1849
2105
|
let i = e ?? n.state.defaultValue.get() ?? "";
|
|
1850
|
-
n.state.tokens.set(
|
|
2106
|
+
n.state.tokens.set(k(n, i)), this.#t = !0;
|
|
1851
2107
|
}
|
|
1852
2108
|
recoverFocus() {
|
|
1853
2109
|
this.store.controllers.contentEditable.sync(), this.store.state.Mark.get() && this.store.controllers.focus.recover();
|
|
@@ -1856,11 +2112,11 @@ var $e = class {
|
|
|
1856
2112
|
let { store: e } = this;
|
|
1857
2113
|
this.#e.push(e.events.parse.on(() => {
|
|
1858
2114
|
if (e.state.recovery.get()) {
|
|
1859
|
-
let t =
|
|
1860
|
-
e.state.tokens.set(
|
|
2115
|
+
let t = E(e.state.tokens.get());
|
|
2116
|
+
e.state.tokens.set(k(e, t)), e.state.previousValue.set(t);
|
|
1861
2117
|
return;
|
|
1862
2118
|
}
|
|
1863
|
-
e.state.tokens.set(e.nodes.focus.target ?
|
|
2119
|
+
e.state.tokens.set(e.nodes.focus.target ? we(e) : Te(e));
|
|
1864
2120
|
}));
|
|
1865
2121
|
}
|
|
1866
2122
|
#r(e) {
|
|
@@ -1871,14 +2127,14 @@ var $e = class {
|
|
|
1871
2127
|
}
|
|
1872
2128
|
};
|
|
1873
2129
|
//#endregion
|
|
1874
|
-
//#region ../../
|
|
1875
|
-
function
|
|
2130
|
+
//#region ../../core/src/features/overlay/filterSuggestions.ts
|
|
2131
|
+
function St(e, t) {
|
|
1876
2132
|
let n = t.toLowerCase();
|
|
1877
2133
|
return e.filter((e) => e.toLowerCase().includes(n));
|
|
1878
2134
|
}
|
|
1879
2135
|
//#endregion
|
|
1880
|
-
//#region ../../
|
|
1881
|
-
function
|
|
2136
|
+
//#region ../../core/src/features/overlay/createMarkFromOverlay.ts
|
|
2137
|
+
function Ct(e, t, n) {
|
|
1882
2138
|
let r = e.option.markup;
|
|
1883
2139
|
if (!r) throw Error("createMarkFromOverlay: option.markup is required");
|
|
1884
2140
|
return {
|
|
@@ -1904,8 +2160,8 @@ function rt(e, t, n) {
|
|
|
1904
2160
|
};
|
|
1905
2161
|
}
|
|
1906
2162
|
//#endregion
|
|
1907
|
-
//#region ../../
|
|
1908
|
-
var
|
|
2163
|
+
//#region ../../core/src/features/overlay/OverlayController.ts
|
|
2164
|
+
var wt = class {
|
|
1909
2165
|
#e;
|
|
1910
2166
|
#t;
|
|
1911
2167
|
#n;
|
|
@@ -1922,55 +2178,61 @@ var it = class {
|
|
|
1922
2178
|
this.#e = this.store.events.clearOverlay.on(() => {
|
|
1923
2179
|
t(void 0);
|
|
1924
2180
|
}), this.#t = this.store.events.checkOverlay.on(() => {
|
|
1925
|
-
t(
|
|
2181
|
+
t(We.find(this.store.state.options.get(), e));
|
|
1926
2182
|
}), this.#n = this.store.events.change.on(() => {
|
|
1927
|
-
let e = this.store.state.showOverlayOn.get()
|
|
2183
|
+
let e = this.store.state.showOverlayOn.get();
|
|
2184
|
+
if (!e) return;
|
|
2185
|
+
let t = "change";
|
|
1928
2186
|
(e === t || Array.isArray(e) && e.includes(t)) && this.store.events.checkOverlay();
|
|
1929
|
-
})
|
|
1930
|
-
|
|
2187
|
+
});
|
|
2188
|
+
let n = () => {
|
|
2189
|
+
let e = this.store.state.showOverlayOn.get();
|
|
2190
|
+
if (!e) return;
|
|
2191
|
+
let t = "selectionChange";
|
|
1931
2192
|
(e === t || Array.isArray(e) && e.includes(t)) && this.store.events.checkOverlay();
|
|
1932
|
-
}
|
|
1933
|
-
|
|
2193
|
+
};
|
|
2194
|
+
this.#r = n, this.#i = () => {
|
|
2195
|
+
document.addEventListener("selectionchange", n);
|
|
1934
2196
|
}, this.#a = () => {
|
|
1935
|
-
document.removeEventListener("selectionchange",
|
|
2197
|
+
document.removeEventListener("selectionchange", n);
|
|
1936
2198
|
};
|
|
1937
|
-
let
|
|
1938
|
-
|
|
2199
|
+
let r = this.store.refs.container;
|
|
2200
|
+
r && (r.addEventListener("focusin", this.#i), r.addEventListener("focusout", this.#a));
|
|
1939
2201
|
}
|
|
1940
2202
|
enableClose() {
|
|
1941
2203
|
this.#o || (this.#o = (e) => {
|
|
1942
|
-
e.key ===
|
|
2204
|
+
e.key === y.ESC && this.store.events.clearOverlay();
|
|
1943
2205
|
}, this.#s = (e) => {
|
|
1944
|
-
let t = e.target;
|
|
2206
|
+
let t = e.target instanceof HTMLElement ? e.target : null;
|
|
1945
2207
|
this.store.refs.overlay?.contains(t) || this.store.refs.container?.contains(t) || this.store.events.clearOverlay();
|
|
1946
2208
|
}, window.addEventListener("keydown", this.#o), document.addEventListener("click", this.#s, !0));
|
|
1947
2209
|
}
|
|
1948
2210
|
disableClose() {
|
|
1949
|
-
this.#o && (window.removeEventListener("keydown", this.#o), document.removeEventListener("click", this.#s, !0), this.#o = void 0, this.#s = void 0);
|
|
2211
|
+
this.#o && (window.removeEventListener("keydown", this.#o), this.#s && document.removeEventListener("click", this.#s, !0), this.#o = void 0, this.#s = void 0);
|
|
1950
2212
|
}
|
|
1951
2213
|
disable() {
|
|
1952
2214
|
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;
|
|
2215
|
+
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
2216
|
}
|
|
1955
2217
|
};
|
|
1956
2218
|
//#endregion
|
|
1957
|
-
//#region ../../
|
|
1958
|
-
function
|
|
2219
|
+
//#region ../../core/src/features/overlay/suggestionNavigation.ts
|
|
2220
|
+
function Tt(e, t, n) {
|
|
1959
2221
|
if (n === 0) return {
|
|
1960
2222
|
action: "none",
|
|
1961
2223
|
index: t
|
|
1962
2224
|
};
|
|
1963
2225
|
let r = !isNaN(t);
|
|
1964
2226
|
switch (e) {
|
|
1965
|
-
case
|
|
2227
|
+
case y.UP: return {
|
|
1966
2228
|
action: "up",
|
|
1967
2229
|
index: r ? (n + (t - 1) % n) % n : 0
|
|
1968
2230
|
};
|
|
1969
|
-
case
|
|
2231
|
+
case y.DOWN: return {
|
|
1970
2232
|
action: "down",
|
|
1971
2233
|
index: r ? (t + 1) % n : 0
|
|
1972
2234
|
};
|
|
1973
|
-
case
|
|
2235
|
+
case y.ENTER: return r ? {
|
|
1974
2236
|
action: "select",
|
|
1975
2237
|
index: t
|
|
1976
2238
|
} : {
|
|
@@ -1984,30 +2246,34 @@ function at(e, t, n) {
|
|
|
1984
2246
|
}
|
|
1985
2247
|
}
|
|
1986
2248
|
//#endregion
|
|
1987
|
-
//#region ../../
|
|
1988
|
-
var
|
|
1989
|
-
key = new
|
|
2249
|
+
//#region ../../core/src/features/store/Store.ts
|
|
2250
|
+
var Et = class {
|
|
2251
|
+
key = new ze();
|
|
2252
|
+
blocks;
|
|
1990
2253
|
nodes = {
|
|
1991
|
-
focus: new
|
|
1992
|
-
input: new
|
|
2254
|
+
focus: new Ge(void 0, this),
|
|
2255
|
+
input: new Ge(void 0, this)
|
|
1993
2256
|
};
|
|
1994
2257
|
state;
|
|
1995
|
-
|
|
2258
|
+
slot;
|
|
2259
|
+
events = je();
|
|
1996
2260
|
refs = {
|
|
1997
2261
|
container: null,
|
|
1998
2262
|
overlay: null
|
|
1999
2263
|
};
|
|
2000
2264
|
controllers = {
|
|
2001
|
-
overlay: new
|
|
2002
|
-
focus: new
|
|
2003
|
-
keydown: new
|
|
2004
|
-
system: new
|
|
2005
|
-
textSelection: new
|
|
2006
|
-
contentEditable: new
|
|
2265
|
+
overlay: new wt(this),
|
|
2266
|
+
focus: new it(this),
|
|
2267
|
+
keydown: new dt(this),
|
|
2268
|
+
system: new rt(this),
|
|
2269
|
+
textSelection: new lt(this),
|
|
2270
|
+
contentEditable: new tt(this),
|
|
2271
|
+
drag: new Qe(this)
|
|
2007
2272
|
};
|
|
2008
|
-
lifecycle = new
|
|
2273
|
+
lifecycle = new xt(this);
|
|
2274
|
+
_defaultSpan;
|
|
2009
2275
|
constructor(e) {
|
|
2010
|
-
this.state =
|
|
2276
|
+
this._defaultSpan = e.defaultSpan, this.blocks = new Re(e.createUseHook), this.state = ke({
|
|
2011
2277
|
tokens: [],
|
|
2012
2278
|
parser: void 0,
|
|
2013
2279
|
previousValue: void 0,
|
|
@@ -2028,12 +2294,33 @@ var ot = class {
|
|
|
2028
2294
|
slots: void 0,
|
|
2029
2295
|
slotProps: void 0,
|
|
2030
2296
|
drag: !1
|
|
2031
|
-
}, e.createUseHook)
|
|
2297
|
+
}, e.createUseHook, { equals: { style: p } }), this.slot = {
|
|
2298
|
+
container: {
|
|
2299
|
+
use: () => [_("container", this.state.slots.use()), v("container", this.state.slotProps.use())],
|
|
2300
|
+
get: () => [_("container", this.state.slots.get()), v("container", this.state.slotProps.get())]
|
|
2301
|
+
},
|
|
2302
|
+
block: {
|
|
2303
|
+
use: () => [_("block", this.state.slots.use()), v("block", this.state.slotProps.use())],
|
|
2304
|
+
get: () => [_("block", this.state.slots.get()), v("block", this.state.slotProps.get())]
|
|
2305
|
+
},
|
|
2306
|
+
span: {
|
|
2307
|
+
use: () => [_("span", this.state.slots.use()), v("span", this.state.slotProps.use())],
|
|
2308
|
+
get: () => [_("span", this.state.slots.get()), v("span", this.state.slotProps.get())]
|
|
2309
|
+
},
|
|
2310
|
+
overlay: {
|
|
2311
|
+
use: (e, t) => ne(this.state.Overlay.use(), e, t),
|
|
2312
|
+
get: (e, t) => ne(this.state.Overlay.get(), e, t)
|
|
2313
|
+
},
|
|
2314
|
+
mark: {
|
|
2315
|
+
use: (e) => re(e, this.state.options.get(), this.state.Mark.use(), this.state.Span.use(), this._defaultSpan),
|
|
2316
|
+
get: (e) => re(e, this.state.options.get(), this.state.Mark.get(), this.state.Span.get(), this._defaultSpan)
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2032
2319
|
}
|
|
2033
2320
|
applyValue(e) {
|
|
2034
2321
|
let t = this.state.onChange.get();
|
|
2035
2322
|
if (!t) return;
|
|
2036
|
-
let n =
|
|
2323
|
+
let n = k(this, e);
|
|
2037
2324
|
this.state.tokens.set(n), this.state.previousValue.set(e), t(e);
|
|
2038
2325
|
}
|
|
2039
2326
|
createHandler() {
|
|
@@ -2050,7 +2337,7 @@ var ot = class {
|
|
|
2050
2337
|
}
|
|
2051
2338
|
};
|
|
2052
2339
|
}
|
|
2053
|
-
},
|
|
2340
|
+
}, Dt = class {
|
|
2054
2341
|
ref;
|
|
2055
2342
|
#e;
|
|
2056
2343
|
#t;
|
|
@@ -2086,13 +2373,13 @@ var ot = class {
|
|
|
2086
2373
|
return this.#t.slot?.content;
|
|
2087
2374
|
}
|
|
2088
2375
|
get depth() {
|
|
2089
|
-
return
|
|
2376
|
+
return D(this.#e.state.tokens.get(), this.#t)?.depth ?? 0;
|
|
2090
2377
|
}
|
|
2091
2378
|
get hasChildren() {
|
|
2092
2379
|
return this.#t.children.some((e) => e.type === "mark");
|
|
2093
2380
|
}
|
|
2094
2381
|
get parent() {
|
|
2095
|
-
return
|
|
2382
|
+
return D(this.#e.state.tokens.get(), this.#t)?.parent;
|
|
2096
2383
|
}
|
|
2097
2384
|
get tokens() {
|
|
2098
2385
|
return this.#t.children;
|
|
@@ -2104,486 +2391,206 @@ var ot = class {
|
|
|
2104
2391
|
#r() {
|
|
2105
2392
|
this.#e.events.change();
|
|
2106
2393
|
}
|
|
2107
|
-
},
|
|
2108
|
-
let
|
|
2109
|
-
return
|
|
2394
|
+
}, Ot = (e) => {
|
|
2395
|
+
let t = (t) => e.on(t), n = () => e.get();
|
|
2396
|
+
return () => u(t, n, n);
|
|
2110
2397
|
};
|
|
2111
2398
|
//#endregion
|
|
2112
2399
|
//#region src/lib/hooks/useCoreFeatures.ts
|
|
2113
|
-
function
|
|
2114
|
-
|
|
2115
|
-
let n = e.state.value.use(), r = e.state.Mark.use(),
|
|
2116
|
-
|
|
2400
|
+
function kt(e, t) {
|
|
2401
|
+
a(t, () => e.createHandler(), [e]), i(() => (e.lifecycle.enable({ getTrigger: (e) => e.overlay?.trigger }), () => e.lifecycle.disable()), []);
|
|
2402
|
+
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();
|
|
2403
|
+
i(() => {
|
|
2117
2404
|
e.lifecycle.syncParser(n, l);
|
|
2118
|
-
}, [n, l]),
|
|
2405
|
+
}, [n, l]), o(() => {
|
|
2119
2406
|
e.controllers.contentEditable.sync();
|
|
2120
|
-
}, [u]),
|
|
2407
|
+
}, [u]), i(() => {
|
|
2121
2408
|
e.lifecycle.recoverFocus();
|
|
2122
2409
|
}, [u]);
|
|
2123
2410
|
}
|
|
2124
2411
|
//#endregion
|
|
2125
2412
|
//#region src/lib/providers/StoreContext.ts
|
|
2126
|
-
var
|
|
2127
|
-
|
|
2128
|
-
function
|
|
2129
|
-
let e =
|
|
2413
|
+
var q = e(void 0);
|
|
2414
|
+
q.displayName = "StoreContext";
|
|
2415
|
+
function J() {
|
|
2416
|
+
let e = r(q);
|
|
2130
2417
|
if (e === void 0) throw Error("Store not found. Make sure to wrap component in StoreContext.");
|
|
2131
2418
|
return e;
|
|
2132
2419
|
}
|
|
2420
|
+
var Y = {
|
|
2421
|
+
Container: "_Container_jix5i_1",
|
|
2422
|
+
Icon: "_Icon_jix5i_5",
|
|
2423
|
+
IconGrip: "_IconGrip_jix5i_16",
|
|
2424
|
+
IconAdd: "_IconAdd_jix5i_20",
|
|
2425
|
+
IconDuplicate: "_IconDuplicate_jix5i_21",
|
|
2426
|
+
IconTrash: "_IconTrash_jix5i_22",
|
|
2427
|
+
Popup: "_Popup_jix5i_38",
|
|
2428
|
+
PopupList: "_PopupList_jix5i_52",
|
|
2429
|
+
PopupItem: "_PopupItem_jix5i_60",
|
|
2430
|
+
PopupItemActive: "_PopupItemActive_jix5i_71",
|
|
2431
|
+
Block: "_Block_jix5i_76",
|
|
2432
|
+
SidePanel: "_SidePanel_jix5i_86",
|
|
2433
|
+
SidePanelVisible: "_SidePanelVisible_jix5i_98",
|
|
2434
|
+
SidePanelAlways: "_SidePanelAlways_jix5i_103",
|
|
2435
|
+
GripButton: "_GripButton_jix5i_109",
|
|
2436
|
+
GripButtonDragging: "_GripButtonDragging_jix5i_128",
|
|
2437
|
+
DropIndicator: "_DropIndicator_jix5i_132"
|
|
2438
|
+
}, At = ({ children: e }) => /* @__PURE__ */ d("ul", {
|
|
2439
|
+
className: Y.PopupList,
|
|
2440
|
+
children: e
|
|
2441
|
+
}), X = ({ onClick: e, onMouseDown: t, active: n, children: r }) => {
|
|
2442
|
+
let a = c(null);
|
|
2443
|
+
return i(() => {
|
|
2444
|
+
n && a.current?.scrollIntoView(!1);
|
|
2445
|
+
}, [n]), /* @__PURE__ */ d("li", {
|
|
2446
|
+
ref: a,
|
|
2447
|
+
className: m(Y.PopupItem, n && Y.PopupItemActive),
|
|
2448
|
+
onClick: e,
|
|
2449
|
+
onMouseDown: t,
|
|
2450
|
+
children: r
|
|
2451
|
+
});
|
|
2452
|
+
}, jt = ({ ref: e, style: t, children: n }) => /* @__PURE__ */ d("div", {
|
|
2453
|
+
ref: e,
|
|
2454
|
+
className: Y.Popup,
|
|
2455
|
+
style: t,
|
|
2456
|
+
children: n
|
|
2457
|
+
}), Mt = t(({ token: e }) => {
|
|
2458
|
+
let t = J().blocks.get(e), n = t.state.menuOpen.use(), r = t.state.menuPosition.use();
|
|
2459
|
+
return n ? /* @__PURE__ */ d(jt, {
|
|
2460
|
+
ref: (e) => t.attachMenu(e),
|
|
2461
|
+
style: {
|
|
2462
|
+
top: r.top,
|
|
2463
|
+
left: r.left
|
|
2464
|
+
},
|
|
2465
|
+
children: /* @__PURE__ */ f(At, { children: [
|
|
2466
|
+
/* @__PURE__ */ f(X, {
|
|
2467
|
+
onClick: () => t.addBlock(),
|
|
2468
|
+
children: [/* @__PURE__ */ d("span", { className: m(Y.Icon, Y.IconAdd) }), /* @__PURE__ */ d("span", { children: "Add below" })]
|
|
2469
|
+
}),
|
|
2470
|
+
/* @__PURE__ */ f(X, {
|
|
2471
|
+
onClick: () => t.duplicateBlock(),
|
|
2472
|
+
children: [/* @__PURE__ */ d("span", { className: m(Y.Icon, Y.IconDuplicate) }), /* @__PURE__ */ d("span", { children: "Duplicate" })]
|
|
2473
|
+
}),
|
|
2474
|
+
/* @__PURE__ */ f(X, {
|
|
2475
|
+
onClick: () => t.deleteBlock(),
|
|
2476
|
+
children: [/* @__PURE__ */ d("span", { className: m(Y.Icon, Y.IconTrash) }), /* @__PURE__ */ d("span", { children: "Delete" })]
|
|
2477
|
+
})
|
|
2478
|
+
] })
|
|
2479
|
+
}) : null;
|
|
2480
|
+
});
|
|
2481
|
+
Mt.displayName = "BlockMenu";
|
|
2133
2482
|
//#endregion
|
|
2134
|
-
//#region src/components/
|
|
2135
|
-
var
|
|
2483
|
+
//#region src/components/DragHandle.tsx
|
|
2484
|
+
var Nt = `${Y.Icon} ${Y.IconGrip}`, Pt = t(({ token: e, blockIndex: t }) => {
|
|
2485
|
+
let n = J(), 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(() => $e(i), [i]);
|
|
2486
|
+
return r ? null : /* @__PURE__ */ d("div", {
|
|
2487
|
+
className: m(Y.SidePanel, l ? Y.SidePanelAlways : c && !o && Y.SidePanelVisible),
|
|
2488
|
+
children: /* @__PURE__ */ d("button", {
|
|
2489
|
+
ref: (e) => a.attachGrip(e, t, n.controllers.drag),
|
|
2490
|
+
type: "button",
|
|
2491
|
+
draggable: !0,
|
|
2492
|
+
className: m(Y.GripButton, o && Y.GripButtonDragging),
|
|
2493
|
+
"aria-label": "Drag to reorder or click for options",
|
|
2494
|
+
children: /* @__PURE__ */ d("span", { className: Nt })
|
|
2495
|
+
})
|
|
2496
|
+
});
|
|
2497
|
+
});
|
|
2498
|
+
Pt.displayName = "DragHandle";
|
|
2136
2499
|
//#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
|
-
}
|
|
2500
|
+
//#region src/components/DropIndicator.tsx
|
|
2501
|
+
var Z = t(({ token: e, position: t }) => J().blocks.get(e).state.dropPosition.use() === t ? /* @__PURE__ */ d("div", {
|
|
2502
|
+
className: Y.DropIndicator,
|
|
2503
|
+
style: t === "before" ? { top: -1 } : { bottom: -1 }
|
|
2504
|
+
}) : null);
|
|
2505
|
+
Z.displayName = "DropIndicator";
|
|
2158
2506
|
//#endregion
|
|
2159
2507
|
//#region src/lib/providers/TokenContext.ts
|
|
2160
|
-
var
|
|
2161
|
-
|
|
2162
|
-
function
|
|
2163
|
-
let e =
|
|
2508
|
+
var Q = e(void 0);
|
|
2509
|
+
Q.displayName = "TokenProvider";
|
|
2510
|
+
function Ft() {
|
|
2511
|
+
let e = r(Q);
|
|
2164
2512
|
if (e === void 0) throw Error("Token not found. Make sure to wrap component in TokenContext.Provider.");
|
|
2165
2513
|
return e;
|
|
2166
2514
|
}
|
|
2167
2515
|
//#endregion
|
|
2168
2516
|
//#region src/components/Token.tsx
|
|
2169
|
-
var
|
|
2170
|
-
let t =
|
|
2171
|
-
return /* @__PURE__ */
|
|
2517
|
+
var $ = t(({ mark: e }) => {
|
|
2518
|
+
let t = J(), [n, r] = t.slot.mark.use(e);
|
|
2519
|
+
return /* @__PURE__ */ d(Q, {
|
|
2172
2520
|
value: e,
|
|
2173
|
-
children: /* @__PURE__ */
|
|
2174
|
-
|
|
2175
|
-
|
|
2521
|
+
children: /* @__PURE__ */ d(n, {
|
|
2522
|
+
children: e.type === "mark" && e.children.length > 0 ? e.children.map((e) => /* @__PURE__ */ d($, { mark: e }, t.key.get(e))) : void 0,
|
|
2523
|
+
...r
|
|
2176
2524
|
})
|
|
2177
2525
|
});
|
|
2178
2526
|
});
|
|
2179
|
-
|
|
2527
|
+
$.displayName = "Token";
|
|
2180
2528
|
//#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,
|
|
2529
|
+
//#region src/components/Block.tsx
|
|
2530
|
+
var It = t(({ token: e, blockIndex: t }) => {
|
|
2531
|
+
let n = J(), [r, i] = n.slot.block.use(), a = n.blocks.get(e), o = a.state.isDragging.use();
|
|
2532
|
+
return /* @__PURE__ */ f(r, {
|
|
2533
|
+
ref: (e) => a.attachContainer(e, t, n.controllers.drag),
|
|
2275
2534
|
"data-testid": "block",
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
onDragOver: w,
|
|
2280
|
-
onDragLeave: T,
|
|
2281
|
-
onDrop: E,
|
|
2535
|
+
...i,
|
|
2536
|
+
className: Y.Block,
|
|
2537
|
+
style: { opacity: o ? .4 : 1 },
|
|
2282
2538
|
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
|
-
})
|
|
2539
|
+
/* @__PURE__ */ d(Z, {
|
|
2540
|
+
token: e,
|
|
2541
|
+
position: "before"
|
|
2303
2542
|
}),
|
|
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" })]
|
|
2543
|
+
/* @__PURE__ */ d(Pt, {
|
|
2544
|
+
token: e,
|
|
2545
|
+
blockIndex: t
|
|
2380
2546
|
}),
|
|
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" })]
|
|
2547
|
+
/* @__PURE__ */ d($, { mark: e }),
|
|
2548
|
+
/* @__PURE__ */ d(Z, {
|
|
2549
|
+
token: e,
|
|
2550
|
+
position: "after"
|
|
2389
2551
|
}),
|
|
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
|
-
})
|
|
2552
|
+
/* @__PURE__ */ d(Mt, { token: e })
|
|
2400
2553
|
]
|
|
2401
2554
|
});
|
|
2402
2555
|
});
|
|
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
|
-
] });
|
|
2556
|
+
It.displayName = "Block";
|
|
2557
|
+
//#endregion
|
|
2558
|
+
//#region src/components/Container.tsx
|
|
2559
|
+
var Lt = t(() => {
|
|
2560
|
+
let e = J(), 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();
|
|
2561
|
+
return /* @__PURE__ */ d(c, {
|
|
2562
|
+
ref: (e) => s.container = e,
|
|
2563
|
+
...l,
|
|
2564
|
+
className: r,
|
|
2565
|
+
style: t && !a ? {
|
|
2566
|
+
paddingLeft: 24,
|
|
2567
|
+
...i
|
|
2568
|
+
} : i,
|
|
2569
|
+
children: t ? n.map((e, t) => /* @__PURE__ */ d(It, {
|
|
2570
|
+
token: e,
|
|
2571
|
+
blockIndex: t
|
|
2572
|
+
}, o.get(e))) : n.map((e) => /* @__PURE__ */ d($, { mark: e }, o.get(e)))
|
|
2573
|
+
});
|
|
2569
2574
|
});
|
|
2570
|
-
|
|
2575
|
+
Lt.displayName = "Container";
|
|
2571
2576
|
//#endregion
|
|
2572
2577
|
//#region src/lib/hooks/useOverlay.tsx
|
|
2573
|
-
function
|
|
2574
|
-
let e =
|
|
2578
|
+
function Rt() {
|
|
2579
|
+
let e = J(), t = e.state.overlayMatch.use();
|
|
2580
|
+
if (!t) throw Error("useOverlay requires an active overlay match");
|
|
2581
|
+
let r = s(() => I.getAbsolutePosition(), [t]), i = n(() => e.events.clearOverlay(), []);
|
|
2575
2582
|
return {
|
|
2576
2583
|
match: t,
|
|
2577
|
-
style:
|
|
2578
|
-
select:
|
|
2579
|
-
let r =
|
|
2584
|
+
style: r,
|
|
2585
|
+
select: n((n) => {
|
|
2586
|
+
let r = Ct(t, n.value, n.meta);
|
|
2580
2587
|
e.events.select({
|
|
2581
2588
|
mark: r,
|
|
2582
2589
|
match: t
|
|
2583
2590
|
}), e.events.clearOverlay();
|
|
2584
2591
|
}, [t]),
|
|
2585
2592
|
close: i,
|
|
2586
|
-
ref:
|
|
2593
|
+
ref: s(() => ({
|
|
2587
2594
|
get current() {
|
|
2588
2595
|
return e.refs.overlay;
|
|
2589
2596
|
},
|
|
@@ -2595,19 +2602,19 @@ function Et() {
|
|
|
2595
2602
|
}
|
|
2596
2603
|
//#endregion
|
|
2597
2604
|
//#region src/components/Suggestions/Suggestions.tsx
|
|
2598
|
-
var
|
|
2599
|
-
let e =
|
|
2605
|
+
var zt = () => {
|
|
2606
|
+
let e = J(), { match: t, select: n, style: r, ref: a } = Rt(), [o, u] = l(NaN), f = t.option.overlay?.data ?? [], p = s(() => St(f, t.value), [t.value, f]), m = p.length, h = c(o);
|
|
2600
2607
|
h.current = o;
|
|
2601
|
-
let g =
|
|
2602
|
-
return g.current = p,
|
|
2608
|
+
let g = c(p);
|
|
2609
|
+
return g.current = p, i(() => {
|
|
2603
2610
|
let t = e.refs.container;
|
|
2604
2611
|
if (!t) return;
|
|
2605
2612
|
let r = (e) => {
|
|
2606
|
-
let t =
|
|
2613
|
+
let t = Tt(e.key, h.current, m);
|
|
2607
2614
|
switch (t.action) {
|
|
2608
2615
|
case "up":
|
|
2609
2616
|
case "down":
|
|
2610
|
-
e.preventDefault(),
|
|
2617
|
+
e.preventDefault(), u(t.index);
|
|
2611
2618
|
break;
|
|
2612
2619
|
case "select": {
|
|
2613
2620
|
e.preventDefault();
|
|
@@ -2618,75 +2625,77 @@ var Dt = () => {
|
|
|
2618
2625
|
});
|
|
2619
2626
|
break;
|
|
2620
2627
|
}
|
|
2628
|
+
case "none": break;
|
|
2621
2629
|
}
|
|
2622
2630
|
};
|
|
2623
2631
|
return t.addEventListener("keydown", r), () => t.removeEventListener("keydown", r);
|
|
2624
|
-
}, [m, n]), p.length ? /* @__PURE__ */
|
|
2625
|
-
ref:
|
|
2626
|
-
className: $.Suggestions,
|
|
2632
|
+
}, [m, n]), p.length ? /* @__PURE__ */ d(jt, {
|
|
2633
|
+
ref: a,
|
|
2627
2634
|
style: r,
|
|
2628
|
-
children: p.map((e, t) => {
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
value: e,
|
|
2637
|
-
meta: t.toString()
|
|
2638
|
-
}),
|
|
2639
|
-
children: e
|
|
2640
|
-
}, e);
|
|
2641
|
-
})
|
|
2635
|
+
children: /* @__PURE__ */ d(At, { children: p.map((e, t) => /* @__PURE__ */ d(X, {
|
|
2636
|
+
active: t === o,
|
|
2637
|
+
onClick: () => n({
|
|
2638
|
+
value: e,
|
|
2639
|
+
meta: t.toString()
|
|
2640
|
+
}),
|
|
2641
|
+
children: e
|
|
2642
|
+
}, e)) })
|
|
2642
2643
|
}) : null;
|
|
2643
|
-
},
|
|
2644
|
-
let e =
|
|
2645
|
-
if (n) return /* @__PURE__ */
|
|
2644
|
+
}, Bt = t(() => {
|
|
2645
|
+
let e = J(), t = e.state.overlayMatch.use(), n = s(() => t ? e.key.get(t.option) : void 0, [t]), [r, i] = e.slot.overlay.use(t?.option, zt);
|
|
2646
|
+
if (n) return /* @__PURE__ */ d(r, { ...i }, n);
|
|
2646
2647
|
});
|
|
2647
|
-
|
|
2648
|
+
Bt.displayName = "OverlayRenderer";
|
|
2649
|
+
//#endregion
|
|
2650
|
+
//#region src/components/Span.tsx
|
|
2651
|
+
var Vt = (e) => /* @__PURE__ */ d("span", {});
|
|
2648
2652
|
//#endregion
|
|
2649
2653
|
//#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
|
-
|
|
2654
|
+
function Ht(e) {
|
|
2655
|
+
let { ref: t } = e, n = m(Y.Container, e.className, e.slotProps?.container?.className), r = h(e.style, e.slotProps?.container?.style), [i] = l(() => new Et({
|
|
2656
|
+
createUseHook: Ot,
|
|
2657
|
+
defaultSpan: Vt
|
|
2658
|
+
}));
|
|
2659
|
+
return i.state.set({
|
|
2660
|
+
value: e.value,
|
|
2661
|
+
defaultValue: e.defaultValue,
|
|
2662
|
+
onChange: e.onChange,
|
|
2663
|
+
readOnly: e.readOnly ?? !1,
|
|
2664
|
+
drag: e.drag ?? !1,
|
|
2665
|
+
options: e.options ?? ie,
|
|
2666
|
+
showOverlayOn: e.showOverlayOn ?? "change",
|
|
2667
|
+
Span: e.Span,
|
|
2668
|
+
Mark: e.Mark,
|
|
2669
|
+
Overlay: e.Overlay,
|
|
2670
|
+
className: n,
|
|
2671
|
+
style: r,
|
|
2672
|
+
slots: e.slots,
|
|
2673
|
+
slotProps: e.slotProps
|
|
2674
|
+
}), kt(i, t), /* @__PURE__ */ f(q, {
|
|
2675
|
+
value: i,
|
|
2676
|
+
children: [/* @__PURE__ */ d(Lt, {}), /* @__PURE__ */ d(Bt, {})]
|
|
2670
2677
|
});
|
|
2671
2678
|
}
|
|
2672
2679
|
//#endregion
|
|
2673
2680
|
//#region src/lib/hooks/useMark.tsx
|
|
2674
|
-
var
|
|
2675
|
-
let t =
|
|
2681
|
+
var Ut = (e = {}) => {
|
|
2682
|
+
let t = J(), n = Ft();
|
|
2683
|
+
if (n.type !== "mark") throw Error("useMark must be called within a mark token context");
|
|
2684
|
+
let r = c(null), [a] = l(() => new Dt({
|
|
2676
2685
|
ref: r,
|
|
2677
2686
|
store: t,
|
|
2678
2687
|
token: n
|
|
2679
2688
|
}));
|
|
2680
|
-
|
|
2689
|
+
Wt(r, e, n);
|
|
2681
2690
|
let o = t.state.readOnly.use();
|
|
2682
|
-
return
|
|
2683
|
-
|
|
2684
|
-
}, [o]),
|
|
2691
|
+
return i(() => {
|
|
2692
|
+
a.readOnly = o;
|
|
2693
|
+
}, [o]), a;
|
|
2685
2694
|
};
|
|
2686
|
-
function
|
|
2687
|
-
|
|
2688
|
-
|
|
2695
|
+
function Wt(e, t, n) {
|
|
2696
|
+
i(() => {
|
|
2697
|
+
!t.controlled && e.current && (e.current.textContent = n.content);
|
|
2689
2698
|
}, []);
|
|
2690
2699
|
}
|
|
2691
2700
|
//#endregion
|
|
2692
|
-
export {
|
|
2701
|
+
export { Dt as MarkHandler, Ht as MarkedInput, Vt as Span, T as annotate, xe as denote, Ut as useMark, Rt as useOverlay };
|