editate 0.6.5 → 0.6.6
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/lib/doc/edit.d.ts +4 -4
- package/lib/dom/index.d.ts +1 -1
- package/lib/index.cjs +227 -218
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +253 -244
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -9,30 +9,30 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
9
9
|
...e,
|
|
10
10
|
text: t
|
|
11
11
|
} ]
|
|
12
|
-
})), f = "delete", u = "insert_text", d = "insert_node", p = "
|
|
12
|
+
})), f = "delete", u = "insert_text", d = "insert_node", p = "format", h = "set_node_attr", y = t => "text" in t, g = t => "children" in t, _ = (t, e) => {
|
|
13
13
|
const n = r(t);
|
|
14
14
|
return n.length === r(e).length && n.every(n => n in e && ("text" === n || o(t[n], e[n])));
|
|
15
15
|
}, k = new WeakMap, x = ({children: t}, e = 0, n = t.length) => {
|
|
16
16
|
let r = 0, o = 0;
|
|
17
17
|
for (let c = e; c < n; c++) {
|
|
18
18
|
const e = t[c];
|
|
19
|
-
r +=
|
|
19
|
+
r += m(e), 0 !== o && g(e) && r++, o++;
|
|
20
20
|
}
|
|
21
21
|
return r;
|
|
22
|
-
},
|
|
22
|
+
}, m = t => {
|
|
23
23
|
if (g(t)) {
|
|
24
24
|
let e = k.get(t);
|
|
25
25
|
return null == e && k.set(t, e = x(t)), e;
|
|
26
26
|
}
|
|
27
27
|
return y(t) ? t.text.length : 1;
|
|
28
|
-
},
|
|
28
|
+
}, b = (t, [e, n]) => {
|
|
29
29
|
let r = 0;
|
|
30
30
|
for (const n of e) r += x(t, 0, n), 0 !== n && r++, t = t.children[n];
|
|
31
31
|
return r + n;
|
|
32
|
-
},
|
|
33
|
-
const n =
|
|
32
|
+
}, E = (t, e) => {
|
|
33
|
+
const n = O(t, e);
|
|
34
34
|
return [ n.t, n.o ];
|
|
35
|
-
},
|
|
35
|
+
}, M = (t, [e, n]) => [ b(t, e), b(t, n) ], v = (t, [e, n]) => [ E(t, e), E(t, n) ], w = (t, e = 0, n = t.length - 1) => {
|
|
36
36
|
let r = e + 1;
|
|
37
37
|
for (;r <= n; ) {
|
|
38
38
|
const e = t[r - 1], o = t[r];
|
|
@@ -45,25 +45,25 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
45
45
|
const e = t[r];
|
|
46
46
|
y(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
|
|
47
47
|
}
|
|
48
|
-
},
|
|
48
|
+
}, T = (t, e = 0, n = t.length - 1) => {
|
|
49
49
|
let r = e + 1;
|
|
50
50
|
for (;r <= n; ) {
|
|
51
51
|
const e = t[r - 1], o = t[r];
|
|
52
|
-
t[r - 1] =
|
|
52
|
+
t[r - 1] = A(e, o), t.splice(r, 1), n--;
|
|
53
53
|
}
|
|
54
|
-
},
|
|
54
|
+
}, S = (t, e, n) => {
|
|
55
55
|
if (e.length) {
|
|
56
56
|
const r = t.length;
|
|
57
57
|
t.push(...e), r && n(t, r - 1, r);
|
|
58
58
|
}
|
|
59
|
-
},
|
|
59
|
+
}, A = (...t) => ({
|
|
60
60
|
...t[0],
|
|
61
|
-
children: t.reduce((t, e) => (
|
|
62
|
-
}),
|
|
61
|
+
children: t.reduce((t, e) => (S(t, e.children, w), t), [])
|
|
62
|
+
}), R = ({children: t}, e) => {
|
|
63
63
|
const n = t.length;
|
|
64
64
|
for (let r = 0; r < n; r++) {
|
|
65
65
|
const n = t[r];
|
|
66
|
-
let o =
|
|
66
|
+
let o = m(n);
|
|
67
67
|
if (g(n) && o++, o > e || o === e && y(n) && !n.text) return {
|
|
68
68
|
i: n,
|
|
69
69
|
l: r,
|
|
@@ -72,10 +72,10 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
72
72
|
e -= o;
|
|
73
73
|
}
|
|
74
74
|
return null;
|
|
75
|
-
},
|
|
75
|
+
}, O = (t, e) => {
|
|
76
76
|
const n = [];
|
|
77
77
|
for (;t; ) {
|
|
78
|
-
const r =
|
|
78
|
+
const r = R(t, e);
|
|
79
79
|
if (!r) break;
|
|
80
80
|
const o = r.i;
|
|
81
81
|
if (!g(o)) break;
|
|
@@ -86,12 +86,12 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
86
86
|
t: n,
|
|
87
87
|
o: e
|
|
88
88
|
};
|
|
89
|
-
},
|
|
90
|
-
const n = t.children, r =
|
|
89
|
+
}, D = (t, e) => {
|
|
90
|
+
const n = t.children, r = R(t, e);
|
|
91
91
|
if (r) {
|
|
92
92
|
const {i: e, o, l: c} = r;
|
|
93
93
|
if (g(e)) {
|
|
94
|
-
const [r, s] =
|
|
94
|
+
const [r, s] = D(e, o), i = n.slice(0, c), a = n.slice(c + 1);
|
|
95
95
|
return i.push(r), a.unshift(s), [ {
|
|
96
96
|
...t,
|
|
97
97
|
children: i
|
|
@@ -129,7 +129,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
129
129
|
text: ""
|
|
130
130
|
} ] : []
|
|
131
131
|
} ];
|
|
132
|
-
},
|
|
132
|
+
}, I = (t, e, n, r = 0) => {
|
|
133
133
|
if (r < e.length) {
|
|
134
134
|
const o = e[r];
|
|
135
135
|
return ((t, e, n, r) => {
|
|
@@ -138,16 +138,16 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
138
138
|
...t,
|
|
139
139
|
children: o
|
|
140
140
|
};
|
|
141
|
-
})(t, o, o, [
|
|
141
|
+
})(t, o, o, [ I(t.children[o], e, n, r + 1) ]);
|
|
142
142
|
}
|
|
143
143
|
return n;
|
|
144
|
-
},
|
|
145
|
-
const [o, c] =
|
|
146
|
-
return
|
|
144
|
+
}, P = (t, e, n, r) => {
|
|
145
|
+
const [o, c] = D(t, e), s = e < n ? D(t, n)[1] : c, i = o.children.slice();
|
|
146
|
+
return S(i, r, T), S(i, s.children, T), {
|
|
147
147
|
...t,
|
|
148
148
|
children: i
|
|
149
149
|
};
|
|
150
|
-
},
|
|
150
|
+
}, L = (t, e, n) => e >= n ? [] : D(D(t, n)[0], e)[1].children, C = (t, e) => e >= 0 && e <= m(t), B = (t, e) => e.reduce((t, e) => H(t, e), t), H = (t, e) => {
|
|
151
151
|
switch (e.type) {
|
|
152
152
|
case f:
|
|
153
153
|
{
|
|
@@ -166,16 +166,16 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
166
166
|
case d:
|
|
167
167
|
{
|
|
168
168
|
const {at: n, fragment: r} = e;
|
|
169
|
-
if (t >= n) return t +
|
|
169
|
+
if (t >= n) return t + m({
|
|
170
170
|
children: r
|
|
171
171
|
});
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
return t;
|
|
176
|
-
}, N = ([t, e], n) => [
|
|
176
|
+
}, N = ([t, e], n) => [ H(t, n), H(e, n) ];
|
|
177
177
|
|
|
178
|
-
function
|
|
178
|
+
function U(e, n = t(e.selection)) {
|
|
179
179
|
e.apply({
|
|
180
180
|
type: "delete",
|
|
181
181
|
range: n
|
|
@@ -190,7 +190,7 @@ function F(t, e, n = t.selection[0]) {
|
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
function
|
|
193
|
+
function V(t, e, n = t.selection[0]) {
|
|
194
194
|
t.apply({
|
|
195
195
|
type: "insert_node",
|
|
196
196
|
at: n,
|
|
@@ -212,7 +212,7 @@ function W(e, n) {
|
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
function
|
|
215
|
+
function G(t, e) {
|
|
216
216
|
t.apply({
|
|
217
217
|
type: "set_node_attr",
|
|
218
218
|
path: [],
|
|
@@ -221,9 +221,9 @@ function q(t, e) {
|
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
function
|
|
224
|
+
function q(e, n, r, o = t(e.selection)) {
|
|
225
225
|
e.apply({
|
|
226
|
-
type: "
|
|
226
|
+
type: "format",
|
|
227
227
|
range: o,
|
|
228
228
|
key: n,
|
|
229
229
|
value: r
|
|
@@ -234,23 +234,23 @@ function J(n, r, o = t(n.selection)) {
|
|
|
234
234
|
let c;
|
|
235
235
|
if (e(o)) {
|
|
236
236
|
const t = ((t, e) => {
|
|
237
|
-
const n =
|
|
238
|
-
return
|
|
237
|
+
const n = O(t, e);
|
|
238
|
+
return R(n.i, n.o);
|
|
239
239
|
})(n.doc, o[0]);
|
|
240
240
|
if (!t) return;
|
|
241
241
|
c = [ t.i ];
|
|
242
|
-
} else c =
|
|
242
|
+
} else c = L(n.doc, ...o).flatMap(t => t.children);
|
|
243
243
|
const s = c.filter(y);
|
|
244
244
|
s.length && n.apply({
|
|
245
|
-
type: "
|
|
245
|
+
type: "format",
|
|
246
246
|
range: o,
|
|
247
247
|
key: r,
|
|
248
248
|
value: !!s.some(t => !t[r])
|
|
249
249
|
});
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
function
|
|
253
|
-
const {t: o} =
|
|
252
|
+
function X(t, e, n, r = t.selection[0]) {
|
|
253
|
+
const {t: o} = O(t.doc, r);
|
|
254
254
|
t.apply({
|
|
255
255
|
type: "set_node_attr",
|
|
256
256
|
path: o,
|
|
@@ -259,8 +259,8 @@ function Y(t, e, n, r = t.selection[0]) {
|
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
function
|
|
263
|
-
const {i: c, t: s} =
|
|
262
|
+
function Y(t, e, n, r, o = t.selection[0]) {
|
|
263
|
+
const {i: c, t: s} = O(t.doc, o);
|
|
264
264
|
t.apply({
|
|
265
265
|
type: "set_node_attr",
|
|
266
266
|
path: s,
|
|
@@ -269,93 +269,96 @@ function Z(t, e, n, r, o = t.selection[0]) {
|
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
let
|
|
273
|
-
|
|
274
|
-
const $ = t => 1 === t.nodeType,
|
|
275
|
-
const t =
|
|
276
|
-
return 1 === t ?
|
|
277
|
-
}, rt = () => {
|
|
278
|
-
if (null != X) return X;
|
|
279
|
-
if (z) if ((t => 3 === t.nodeType)(z)) {
|
|
280
|
-
const t = z.data;
|
|
281
|
-
if (t) return X = "\n" === t ? lt() ? 3 : 5 : 1;
|
|
282
|
-
} else if ($(z)) {
|
|
283
|
-
if ("BR" === z.tagName) return X = lt() ? 3 : 5;
|
|
284
|
-
if (at(z)) return X = 6;
|
|
285
|
-
if (K.u(z)) return X = 2;
|
|
286
|
-
if (K.p(z)) return X = 4;
|
|
287
|
-
}
|
|
288
|
-
return X = 0;
|
|
272
|
+
let Z = null, j = null, z = null, K = null, Q = null;
|
|
273
|
+
|
|
274
|
+
const $ = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), tt = t => 1 === t.nodeType, et = t => 8 === t.nodeType, nt = () => j, rt = () => {
|
|
275
|
+
const t = ot();
|
|
276
|
+
return 1 === t ? j.data.length : 2 === t ? 1 : 0;
|
|
289
277
|
}, ot = () => {
|
|
290
|
-
|
|
291
|
-
if (
|
|
292
|
-
const t =
|
|
293
|
-
if (
|
|
294
|
-
|
|
278
|
+
if (null != z) return z;
|
|
279
|
+
if (j) if ((t => 3 === t.nodeType)(j)) {
|
|
280
|
+
const t = j.data;
|
|
281
|
+
if (t) return z = "\n" === t ? lt() ? 3 : 5 : 1;
|
|
282
|
+
} else {
|
|
283
|
+
if (!tt(j)) return z = 6;
|
|
284
|
+
if ("false" === j.contentEditable) return z = 2;
|
|
285
|
+
{
|
|
286
|
+
const t = $.get(j.tagName);
|
|
287
|
+
if (null != t) return z = 1 === t ? lt() ? 3 : 5 : 3 === t ? 2 : 6;
|
|
288
|
+
if (K.u(j)) return z = 4;
|
|
289
|
+
}
|
|
295
290
|
}
|
|
296
|
-
return z =
|
|
291
|
+
return z = 0;
|
|
297
292
|
}, ct = () => {
|
|
298
|
-
|
|
293
|
+
const t = ot();
|
|
294
|
+
if (z = null, 2 === t || 6 === t) {
|
|
295
|
+
const t = j;
|
|
296
|
+
if (j = Z.nextSibling(), !j) for (;(j = Z.nextNode()) && t.contains(j); ) ;
|
|
297
|
+
return j;
|
|
298
|
+
}
|
|
299
|
+
return j = Z.nextNode();
|
|
299
300
|
}, st = () => {
|
|
300
|
-
for (;(
|
|
301
|
-
}, it =
|
|
302
|
-
|
|
301
|
+
for (;(z = null) || (j = Z.nextSibling()); ) if (4 === ot()) return;
|
|
302
|
+
}, it = () => {
|
|
303
|
+
for (;(z = null) || (j = Z.parentNode()); ) if (4 === ot()) return;
|
|
304
|
+
}, at = t => 2 === $.get(t.tagName), lt = () => {
|
|
305
|
+
const t = j.parentNode;
|
|
303
306
|
return Q(() => {
|
|
304
|
-
for (
|
|
305
|
-
if (
|
|
306
|
-
if (!t.contains(
|
|
307
|
+
for (z = 0; ct(); ) {
|
|
308
|
+
if (ot()) return !0;
|
|
309
|
+
if (!t.contains(j)) break;
|
|
307
310
|
}
|
|
308
311
|
return !1;
|
|
309
312
|
});
|
|
310
313
|
}, ft = () => {
|
|
311
|
-
for (;
|
|
312
|
-
const t =
|
|
314
|
+
for (;ct(); ) {
|
|
315
|
+
const t = ot();
|
|
313
316
|
if (t && 6 !== t) return t;
|
|
314
317
|
}
|
|
315
|
-
}, ut = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), dt = t => ut.has(t.tagName), pt =
|
|
318
|
+
}, ut = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), dt = t => ut.has(t.tagName), pt = (t, e) => t.compareDocumentPosition(e), ht = t => t.ownerDocument, yt = t => ht(t).getSelection(), gt = (t, e) => {
|
|
316
319
|
if (t.rangeCount) {
|
|
317
320
|
const n = t.getRangeAt(0);
|
|
318
321
|
if (e.contains(n.commonAncestorContainer)) return n;
|
|
319
322
|
}
|
|
320
|
-
},
|
|
321
|
-
const o =
|
|
322
|
-
(n ||
|
|
323
|
+
}, _t = (t, e, n, r) => {
|
|
324
|
+
const o = yt(t);
|
|
325
|
+
(n || gt(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
|
|
323
326
|
o.extend(e.startContainer, e.startOffset)));
|
|
324
|
-
},
|
|
327
|
+
}, kt = (t, e, [n, r], o, c, s) => {
|
|
325
328
|
const i = 0 === o, a = o > 0, l = a ? r : n, f = a ? n : r;
|
|
326
329
|
if (0 === l[0].length && 0 === l[1] && i && !e.hasChildNodes()) {
|
|
327
330
|
const n = t.createRange();
|
|
328
|
-
return n.setStart(e, 0), n.setEnd(e, 0),
|
|
331
|
+
return n.setStart(e, 0), n.setEnd(e, 0), _t(e, n, s);
|
|
329
332
|
}
|
|
330
|
-
const u =
|
|
333
|
+
const u = xt(e, l, c);
|
|
331
334
|
if (!u) return;
|
|
332
|
-
const d = i ? u :
|
|
335
|
+
const d = i ? u : xt(e, f, c);
|
|
333
336
|
if (!d) return;
|
|
334
337
|
const p = t.createRange(), [h, y] = u, [g, _] = d;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
},
|
|
338
|
+
tt(h) ? y < 1 ? p.setStartBefore(h) : p.setStartAfter(h) : p.setStart(h, y), tt(g) ? _ < 1 ? p.setEndBefore(g) : p.setEndAfter(g) : p.setEnd(g, _),
|
|
339
|
+
_t(e, p, s, a);
|
|
340
|
+
}, xt = (t, [e, n], r) => r(() => {
|
|
338
341
|
let t, r = 0;
|
|
339
342
|
for (;t = ft(); ) if (4 === t) {
|
|
340
|
-
if (r < e.length) for (let t = e[r++]; t > 0; t--)
|
|
343
|
+
if (r < e.length) for (let t = e[r++]; t > 0; t--) st();
|
|
341
344
|
} else {
|
|
342
|
-
const t =
|
|
343
|
-
if (n <= t) return [
|
|
345
|
+
const t = rt();
|
|
346
|
+
if (n <= t) return [ nt(), n ];
|
|
344
347
|
n -= t;
|
|
345
348
|
}
|
|
346
|
-
}, t),
|
|
349
|
+
}, t), mt = (t, e, r, o) => {
|
|
347
350
|
let c = !0;
|
|
348
351
|
if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
|
|
349
|
-
if (
|
|
352
|
+
if (tt(e) && e.hasChildNodes()) {
|
|
350
353
|
const t = n(r, e.childNodes.length - 1);
|
|
351
354
|
e = e.childNodes[t], c = t === r, r = 0;
|
|
352
355
|
}
|
|
353
356
|
return o(() => {
|
|
354
|
-
4 !==
|
|
357
|
+
4 !== ot() && it();
|
|
355
358
|
const n = o(() => {
|
|
356
359
|
const e = [];
|
|
357
360
|
let n;
|
|
358
|
-
for (;(n =
|
|
361
|
+
for (;(n = nt()) && n !== t; ) e.unshift(n), it();
|
|
359
362
|
if (!e.length) return [ 0 ];
|
|
360
363
|
let r = 0, o = e[e.length - 1];
|
|
361
364
|
for (;o = o.previousElementSibling; ) at(o) || r++;
|
|
@@ -363,18 +366,18 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => z, nt =
|
|
|
363
366
|
});
|
|
364
367
|
let s = 0;
|
|
365
368
|
for (;ft(); ) {
|
|
366
|
-
const t =
|
|
369
|
+
const t = pt(e, nt());
|
|
367
370
|
if (0 === t || 16 & t) {
|
|
368
371
|
if (c) break;
|
|
369
372
|
} else if (4 & t) break;
|
|
370
|
-
s +=
|
|
373
|
+
s += rt();
|
|
371
374
|
}
|
|
372
375
|
return [ n, s + r ];
|
|
373
376
|
}, t, e);
|
|
374
|
-
},
|
|
375
|
-
const s =
|
|
376
|
-
return [ s, r === c && n === o ? s :
|
|
377
|
-
},
|
|
377
|
+
}, bt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
|
|
378
|
+
const s = mt(t, r, n, e);
|
|
379
|
+
return [ s, r === c && n === o ? s : mt(t, c, o, e) ];
|
|
380
|
+
}, Et = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), Mt = (t, e) => {
|
|
378
381
|
const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
|
|
379
382
|
let s = !1, i = !1, a = !1, l = !1;
|
|
380
383
|
return r.forEach(t => {
|
|
@@ -388,7 +391,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => z, nt =
|
|
|
388
391
|
break;
|
|
389
392
|
|
|
390
393
|
case "Mod":
|
|
391
|
-
|
|
394
|
+
Et ? a = !0 : i = !0;
|
|
392
395
|
break;
|
|
393
396
|
|
|
394
397
|
case "Alt":
|
|
@@ -404,20 +407,20 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => z, nt =
|
|
|
404
407
|
};
|
|
405
408
|
};
|
|
406
409
|
|
|
407
|
-
function
|
|
410
|
+
function vt(t) {
|
|
408
411
|
let e = 0, n = 0, r = !1;
|
|
409
412
|
const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e], a = () => e > 0, l = () => e < s.length - 1, f = () => {
|
|
410
413
|
if (a()) {
|
|
411
414
|
const n = i()[1];
|
|
412
415
|
e--;
|
|
413
416
|
const c = t.doc;
|
|
414
|
-
r = !0, t.exec(
|
|
417
|
+
r = !0, t.exec(G, i()[0].children), r = !1, o(c, t.doc) || (t.selection = n);
|
|
415
418
|
}
|
|
416
419
|
}, u = () => {
|
|
417
420
|
if (l()) {
|
|
418
421
|
e++;
|
|
419
422
|
const [n, c, s] = i(), a = t.doc;
|
|
420
|
-
r = !0, t.exec(
|
|
423
|
+
r = !0, t.exec(G, n.children), r = !1, o(a, t.doc) || (t.selection = [ B(c[0], s), B(c[1], s) ]);
|
|
421
424
|
}
|
|
422
425
|
};
|
|
423
426
|
t.hook("apply", (i, a) => {
|
|
@@ -432,10 +435,11 @@ function Et(t) {
|
|
|
432
435
|
const t = [ l, f, [] ];
|
|
433
436
|
e >= s.length ? s.push(t) : s[e] = t;
|
|
434
437
|
}
|
|
435
|
-
n = t, s[e][0] = u, s[e][2].push(i), s.
|
|
438
|
+
n = t, s[e][0] = u, s[e][2].push(i), s.length > e + 1 && (s.length = e + 1), e > 500 && (e--,
|
|
439
|
+
s.shift());
|
|
436
440
|
}
|
|
437
|
-
}), t.hook("keyboard",
|
|
438
|
-
t.set(
|
|
441
|
+
}), t.hook("keyboard", Mt("Mod+Z", f)), t.hook("keyboard", Mt("Shift+Mod+Z", u)),
|
|
442
|
+
t.set(vt, {
|
|
439
443
|
undo: f,
|
|
440
444
|
redo: u,
|
|
441
445
|
undoable: a,
|
|
@@ -443,27 +447,27 @@ function Et(t) {
|
|
|
443
447
|
});
|
|
444
448
|
}
|
|
445
449
|
|
|
446
|
-
function
|
|
447
|
-
t.get(
|
|
450
|
+
function wt(t) {
|
|
451
|
+
t.get(vt).undo();
|
|
448
452
|
}
|
|
449
453
|
|
|
450
|
-
function
|
|
451
|
-
t.get(
|
|
454
|
+
function Tt(t) {
|
|
455
|
+
t.get(vt).redo();
|
|
452
456
|
}
|
|
453
457
|
|
|
454
|
-
function
|
|
455
|
-
return t.get(
|
|
458
|
+
function St(t) {
|
|
459
|
+
return t.get(vt).undoable();
|
|
456
460
|
}
|
|
457
461
|
|
|
458
462
|
function At(t) {
|
|
459
|
-
return t.get(
|
|
463
|
+
return t.get(vt).redoable();
|
|
460
464
|
}
|
|
461
465
|
|
|
462
|
-
const
|
|
466
|
+
const Rt = [], Ot = () => {}, Dt = t => {
|
|
463
467
|
throw Error(t);
|
|
464
|
-
},
|
|
468
|
+
}, It = ({doc: n, readonly: r = !1, schema: a, isBlock: g = dt, onWarn: _ = console.warn, onError: k = Dt}) => {
|
|
465
469
|
let x = [ 0, 0 ];
|
|
466
|
-
const
|
|
470
|
+
const m = t => {
|
|
467
471
|
if (!a) return _("An unsafe operation was detected. We recommend using schema option."),
|
|
468
472
|
!0;
|
|
469
473
|
const e = a["~standard"].validate(t);
|
|
@@ -473,19 +477,21 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
473
477
|
}
|
|
474
478
|
return !1;
|
|
475
479
|
};
|
|
476
|
-
a && !
|
|
477
|
-
const
|
|
478
|
-
const e =
|
|
479
|
-
e && (
|
|
480
|
-
|
|
480
|
+
a && !m(n) && k("Invalid document");
|
|
481
|
+
const E = new Map, w = new WeakMap, T = t => E.get(t) || Rt, S = new Map, A = new Set, D = t => {
|
|
482
|
+
const e = S.get(t);
|
|
483
|
+
e && (A.size || i(() => {
|
|
484
|
+
A.forEach(t => {
|
|
481
485
|
t();
|
|
482
|
-
}),
|
|
483
|
-
}),
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
486
|
+
}), A.clear();
|
|
487
|
+
}), e.forEach(t => {
|
|
488
|
+
A.add(t);
|
|
489
|
+
}));
|
|
490
|
+
}, H = t => {
|
|
491
|
+
if (!r) if (Array.isArray(t)) for (const e of t) U(e); else U(t);
|
|
492
|
+
return V;
|
|
493
|
+
}, U = t => {
|
|
494
|
+
const e = n, r = T("apply"), c = r.length;
|
|
489
495
|
let s = 0;
|
|
490
496
|
const i = () => {
|
|
491
497
|
if (s < c) {
|
|
@@ -499,21 +505,21 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
499
505
|
case f:
|
|
500
506
|
{
|
|
501
507
|
const [r, o] = n.range;
|
|
502
|
-
|
|
508
|
+
C(t, r) && C(t, o) && r < o && (t = P(t, r, o, []), e = N(e, n));
|
|
503
509
|
break;
|
|
504
510
|
}
|
|
505
511
|
|
|
506
512
|
case u:
|
|
507
513
|
{
|
|
508
514
|
const {at: r, text: o} = n;
|
|
509
|
-
if (
|
|
510
|
-
const {i: c, o: s} =
|
|
515
|
+
if (C(t, r) && o) {
|
|
516
|
+
const {i: c, o: s} = O(t, r), i = R(c, s - 1);
|
|
511
517
|
let a;
|
|
512
518
|
if (i) {
|
|
513
519
|
const t = i.i;
|
|
514
520
|
y(t) && (a = t);
|
|
515
521
|
}
|
|
516
|
-
t =
|
|
522
|
+
t = P(t, r, r, l(o, a, c)), e = N(e, n);
|
|
517
523
|
}
|
|
518
524
|
break;
|
|
519
525
|
}
|
|
@@ -521,23 +527,23 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
521
527
|
case d:
|
|
522
528
|
{
|
|
523
529
|
const {at: r, fragment: o} = n;
|
|
524
|
-
|
|
530
|
+
C(t, r) && o.length && (t = P(t, r, r, o), e = N(e, n));
|
|
525
531
|
break;
|
|
526
532
|
}
|
|
527
533
|
|
|
528
534
|
case p:
|
|
529
535
|
{
|
|
530
536
|
const {range: [e, r], key: o, value: c} = n;
|
|
531
|
-
if (
|
|
532
|
-
const {i: {children: n}, t: r} =
|
|
537
|
+
if (C(t, e) && C(t, r) && e <= r) if (e === r) {
|
|
538
|
+
const {i: {children: n}, t: r} = O(t, e);
|
|
533
539
|
if (1 === n.length) {
|
|
534
540
|
const e = n[0];
|
|
535
|
-
y(e) && !e.text && (t =
|
|
541
|
+
y(e) && !e.text && (t = I(t, [ ...r, 0 ], {
|
|
536
542
|
...e,
|
|
537
543
|
[o]: c
|
|
538
544
|
}));
|
|
539
545
|
}
|
|
540
|
-
} else t =
|
|
546
|
+
} else t = P(t, e, r, L(t, e, r).map(t => ({
|
|
541
547
|
...t,
|
|
542
548
|
children: t.children.map(t => y(t) ? {
|
|
543
549
|
...t,
|
|
@@ -553,7 +559,7 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
553
559
|
for (let n = 0; n < e.length; n++) t = t.children[e[n]];
|
|
554
560
|
return t;
|
|
555
561
|
})(t, e);
|
|
556
|
-
c && (t =
|
|
562
|
+
c && (t = I(t, e, {
|
|
557
563
|
...c,
|
|
558
564
|
[r]: o
|
|
559
565
|
}));
|
|
@@ -562,7 +568,7 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
562
568
|
}
|
|
563
569
|
return [ t, e ];
|
|
564
570
|
})(n, x, t);
|
|
565
|
-
(({type: t}) => t === d || t === p || t === h)(t) && !
|
|
571
|
+
(({type: t}) => t === d || t === p || t === h)(t) && !m(e) || (n = e, x = r);
|
|
566
572
|
} catch (t) {
|
|
567
573
|
_("rollback operation: " + t);
|
|
568
574
|
}
|
|
@@ -570,11 +576,11 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
570
576
|
}, a = e => {
|
|
571
577
|
e && (t = e), s++, i();
|
|
572
578
|
};
|
|
573
|
-
i(), o(e, n) ||
|
|
579
|
+
i(), o(e, n) || D("change");
|
|
574
580
|
}, F = t => {
|
|
575
|
-
!((t, [e, n]) =>
|
|
576
|
-
|
|
577
|
-
},
|
|
581
|
+
!((t, [e, n]) => C(t, e) && C(t, n))(n, t) || x[0] === t[0] && x[1] === t[1] || (x = t,
|
|
582
|
+
D("selectionchange"));
|
|
583
|
+
}, V = {
|
|
578
584
|
get doc() {
|
|
579
585
|
return n;
|
|
580
586
|
},
|
|
@@ -588,81 +594,84 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
588
594
|
return r;
|
|
589
595
|
},
|
|
590
596
|
set readonly(t) {
|
|
591
|
-
r = t,
|
|
597
|
+
r = t, D("readonly");
|
|
592
598
|
},
|
|
593
|
-
apply:
|
|
599
|
+
apply: H,
|
|
594
600
|
on: (t, e) => {
|
|
595
|
-
let n =
|
|
596
|
-
return n ||
|
|
601
|
+
let n = S.get(t);
|
|
602
|
+
return n || S.set(t, n = new Set), n.add(e), () => {
|
|
597
603
|
n.delete(e);
|
|
598
604
|
};
|
|
599
605
|
},
|
|
600
606
|
hook: (t, e) => {
|
|
601
|
-
let n =
|
|
602
|
-
return n ||
|
|
607
|
+
let n = E.get(t);
|
|
608
|
+
return n || E.set(t, n = []), n.push(e), () => {
|
|
603
609
|
const t = n.indexOf(e);
|
|
604
610
|
-1 !== t && n.splice(t, 1);
|
|
605
611
|
};
|
|
606
612
|
},
|
|
607
613
|
exec: (t, ...e) => {
|
|
608
|
-
const n = t(
|
|
609
|
-
return void 0 === n ?
|
|
614
|
+
const n = t(V, ...e);
|
|
615
|
+
return void 0 === n ? V : n;
|
|
610
616
|
},
|
|
611
|
-
get: t => (
|
|
612
|
-
set: (t, e) => (
|
|
617
|
+
get: t => (w.has(t) || k("No value found for key"), w.get(t)),
|
|
618
|
+
set: (t, e) => (w.set(t, e), V),
|
|
613
619
|
input: o => {
|
|
614
620
|
if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return _("beforeinput event is not supported."),
|
|
615
|
-
|
|
621
|
+
Ot;
|
|
616
622
|
const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
|
|
617
623
|
o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
|
|
618
624
|
let d = !1, p = null, h = !1, y = !1, k = !1;
|
|
619
|
-
const
|
|
625
|
+
const m = ht(o), E = (t => {
|
|
620
626
|
const e = (n, r, o) => {
|
|
621
|
-
const c = K, s = Q, i =
|
|
627
|
+
const c = K, s = Q, i = Z, a = j, l = z;
|
|
622
628
|
try {
|
|
623
|
-
return
|
|
629
|
+
return Z || (K = t, Q = e, Z = K.p.createTreeWalker(r, 5)), o && (Z.currentNode = j = o),
|
|
624
630
|
n();
|
|
625
631
|
} finally {
|
|
626
|
-
K = c, Q = s,
|
|
632
|
+
K = c, Q = s, Z = i, j = a, z = l, Z && a && (Z.currentNode = a);
|
|
627
633
|
}
|
|
628
634
|
};
|
|
629
635
|
return e;
|
|
630
636
|
})({
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}), S = () => {
|
|
637
|
+
p: m,
|
|
638
|
+
u: g
|
|
639
|
+
}), w = () => {
|
|
635
640
|
o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
|
|
636
641
|
};
|
|
637
|
-
|
|
638
|
-
const
|
|
642
|
+
w();
|
|
643
|
+
const S = V.on("change", () => {
|
|
639
644
|
y || requestAnimationFrame(() => {
|
|
640
645
|
y || o.focus({
|
|
641
646
|
preventScroll: !0
|
|
642
647
|
});
|
|
643
648
|
});
|
|
644
|
-
}),
|
|
645
|
-
for (const e of
|
|
646
|
-
const n = e(t,
|
|
649
|
+
}), A = V.on("readonly", w), R = t => {
|
|
650
|
+
for (const e of T("paste")) {
|
|
651
|
+
const n = e(t, E);
|
|
647
652
|
if (n) return n;
|
|
648
653
|
}
|
|
649
654
|
_("failed to serialize pasted data");
|
|
650
|
-
},
|
|
651
|
-
let n = !1;
|
|
652
|
-
const
|
|
655
|
+
}, O = ((t, e) => {
|
|
656
|
+
let n = !1, r = [];
|
|
657
|
+
const o = t => {
|
|
653
658
|
n && r.push(...t);
|
|
654
659
|
}, c = new MutationObserver(t => {
|
|
655
660
|
o(t), n || e();
|
|
656
661
|
}), s = () => {
|
|
657
662
|
o(c.takeRecords());
|
|
658
|
-
}, i = () =>
|
|
663
|
+
}, i = () => {
|
|
664
|
+
s();
|
|
665
|
+
const t = r;
|
|
666
|
+
return r = [], t;
|
|
667
|
+
};
|
|
659
668
|
return c.observe(t, {
|
|
660
669
|
characterData: !0,
|
|
661
670
|
characterDataOldValue: !0,
|
|
662
671
|
childList: !0,
|
|
663
672
|
subtree: !0
|
|
664
673
|
}), {
|
|
665
|
-
|
|
674
|
+
h: t => {
|
|
666
675
|
let e;
|
|
667
676
|
for (;e = t.pop(); ) if ("childList" === e.type) {
|
|
668
677
|
const {target: t, removedNodes: n, addedNodes: r, nextSibling: o} = e;
|
|
@@ -671,40 +680,40 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
671
680
|
} else e.target.data = e.oldValue;
|
|
672
681
|
i();
|
|
673
682
|
},
|
|
674
|
-
|
|
683
|
+
_: t => {
|
|
675
684
|
!n && t && s(), n = t;
|
|
676
685
|
},
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
r.
|
|
686
|
+
k: i,
|
|
687
|
+
m: () => {
|
|
688
|
+
r.length = 0, c.disconnect();
|
|
680
689
|
}
|
|
681
690
|
};
|
|
682
691
|
})(o, () => {
|
|
683
|
-
|
|
684
|
-
}),
|
|
685
|
-
F(
|
|
686
|
-
const n =
|
|
692
|
+
kt(m, o, v(n, x), x[0] - x[1], E);
|
|
693
|
+
}), D = () => {
|
|
694
|
+
F(M(n, ((t, e) => {
|
|
695
|
+
const n = yt(t), r = gt(n, t);
|
|
687
696
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
688
|
-
const o =
|
|
697
|
+
const o = bt(t, e, r), c = pt(n.anchorNode, n.focusNode);
|
|
689
698
|
return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
|
|
690
|
-
})(o,
|
|
691
|
-
},
|
|
692
|
-
const t =
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
},
|
|
696
|
-
if (!h) for (const e of
|
|
697
|
-
},
|
|
698
|
-
h ||
|
|
699
|
-
},
|
|
699
|
+
})(o, E)));
|
|
700
|
+
}, I = () => {
|
|
701
|
+
const t = O.k();
|
|
702
|
+
O._(!1), t.length && (O.h(t), m.removeEventListener("selectionchange", q), kt(m, o, v(n, x), x[0] - x[1], E, !0),
|
|
703
|
+
m.addEventListener("selectionchange", q)), p && (F(p[1]), H(p[0]), p = null), h = !1;
|
|
704
|
+
}, P = t => {
|
|
705
|
+
if (!h) for (const e of T("keyboard")) if (e(t)) return t.preventDefault(), void O._(!1);
|
|
706
|
+
}, L = () => {
|
|
707
|
+
h || I();
|
|
708
|
+
}, C = t => {
|
|
700
709
|
t.preventDefault();
|
|
701
710
|
const r = t.inputType;
|
|
702
711
|
if (r.startsWith("format")) return;
|
|
703
712
|
if ("historyUndo" === r || "historyRedo" === r) return;
|
|
704
|
-
h ?
|
|
713
|
+
h ? O._(!0) : D();
|
|
705
714
|
const c = t.getTargetRanges()[0];
|
|
706
715
|
if (c) {
|
|
707
|
-
const s =
|
|
716
|
+
const s = M(n, bt(o, E, c));
|
|
708
717
|
let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
|
|
709
718
|
if (null == a) {
|
|
710
719
|
const e = t.dataTransfer;
|
|
@@ -719,29 +728,29 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
719
728
|
text: a
|
|
720
729
|
});
|
|
721
730
|
}
|
|
722
|
-
h ||
|
|
731
|
+
h || I();
|
|
723
732
|
}, N = () => {
|
|
724
|
-
h ||
|
|
725
|
-
},
|
|
726
|
-
|
|
733
|
+
h || D(), h = !0;
|
|
734
|
+
}, U = () => {
|
|
735
|
+
I();
|
|
727
736
|
}, W = () => {
|
|
728
|
-
y = !0,
|
|
729
|
-
}, q = () => {
|
|
730
|
-
y = !1;
|
|
737
|
+
y = !0, D();
|
|
731
738
|
}, G = () => {
|
|
732
|
-
|
|
739
|
+
y = !1;
|
|
740
|
+
}, q = () => {
|
|
741
|
+
!y || h || k || D();
|
|
733
742
|
}, J = t => {
|
|
734
|
-
if (
|
|
735
|
-
},
|
|
743
|
+
if (D(), !e(x)) for (const e of T("copy")) e(t);
|
|
744
|
+
}, X = t => {
|
|
736
745
|
t.preventDefault(), J(t.clipboardData);
|
|
737
|
-
},
|
|
738
|
-
e.preventDefault(), r || (J(e.clipboardData),
|
|
746
|
+
}, Y = e => {
|
|
747
|
+
e.preventDefault(), r || (J(e.clipboardData), H({
|
|
739
748
|
type: "delete",
|
|
740
749
|
range: t(x)
|
|
741
750
|
}));
|
|
742
751
|
}, $ = e => {
|
|
743
752
|
e.preventDefault();
|
|
744
|
-
const n =
|
|
753
|
+
const n = R(e.clipboardData);
|
|
745
754
|
if (n) {
|
|
746
755
|
const e = t(x), r = e[0], o = [ {
|
|
747
756
|
type: "delete",
|
|
@@ -755,19 +764,19 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
755
764
|
type: "insert_node",
|
|
756
765
|
at: r,
|
|
757
766
|
fragment: n
|
|
758
|
-
}),
|
|
767
|
+
}), H(o);
|
|
759
768
|
}
|
|
760
769
|
}, tt = e => {
|
|
761
770
|
e.preventDefault();
|
|
762
771
|
const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}, o) => {
|
|
763
772
|
if (t.caretPositionFromPoint) {
|
|
764
773
|
const c = t.caretPositionFromPoint(n, r);
|
|
765
|
-
if (c) return
|
|
774
|
+
if (c) return mt(e, c.offsetNode, c.offset, o);
|
|
766
775
|
} else if (t.caretRangeFromPoint) {
|
|
767
776
|
const c = t.caretRangeFromPoint(n, r);
|
|
768
|
-
if (c) return
|
|
777
|
+
if (c) return mt(e, c.startContainer, c.startOffset, o);
|
|
769
778
|
}
|
|
770
|
-
})(
|
|
779
|
+
})(m, o, e, E);
|
|
771
780
|
if (r && s) {
|
|
772
781
|
let e;
|
|
773
782
|
const o = [];
|
|
@@ -775,9 +784,9 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
775
784
|
type: "delete",
|
|
776
785
|
range: t(x)
|
|
777
786
|
});
|
|
778
|
-
const i =
|
|
787
|
+
const i = R(r);
|
|
779
788
|
if (i) {
|
|
780
|
-
const t =
|
|
789
|
+
const t = b(n, s), r = B(t, o);
|
|
781
790
|
o.push(c(i) ? {
|
|
782
791
|
type: "insert_text",
|
|
783
792
|
at: r,
|
|
@@ -786,39 +795,39 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
786
795
|
type: "insert_node",
|
|
787
796
|
at: r,
|
|
788
797
|
fragment: i
|
|
789
|
-
}), e = [ r,
|
|
798
|
+
}), e = [ r, B(t, o) ];
|
|
790
799
|
}
|
|
791
|
-
|
|
800
|
+
H(o), e && F(e);
|
|
792
801
|
}
|
|
793
802
|
}, et = t => {
|
|
794
803
|
k = !0, J(t.dataTransfer);
|
|
795
804
|
}, nt = () => {
|
|
796
805
|
k = !1;
|
|
797
806
|
};
|
|
798
|
-
|
|
799
|
-
o.addEventListener("beforeinput",
|
|
800
|
-
o.addEventListener("compositionend",
|
|
801
|
-
o.addEventListener("copy",
|
|
807
|
+
m.addEventListener("selectionchange", q), o.addEventListener("keydown", P), o.addEventListener("input", L),
|
|
808
|
+
o.addEventListener("beforeinput", C), o.addEventListener("compositionstart", N),
|
|
809
|
+
o.addEventListener("compositionend", U), o.addEventListener("focus", W), o.addEventListener("blur", G),
|
|
810
|
+
o.addEventListener("copy", X), o.addEventListener("cut", Y), o.addEventListener("paste", $),
|
|
802
811
|
o.addEventListener("drop", tt), o.addEventListener("dragstart", et), o.addEventListener("dragend", nt);
|
|
803
812
|
const rt = [];
|
|
804
|
-
return
|
|
813
|
+
return T("mount").forEach(t => {
|
|
805
814
|
const e = t(o);
|
|
806
815
|
e && rt.push(e);
|
|
807
816
|
}), () => {
|
|
808
|
-
d || (d = !0,
|
|
809
|
-
o.ariaReadOnly = f, o.style.whiteSpace = u,
|
|
810
|
-
o.removeEventListener("keydown",
|
|
811
|
-
o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend",
|
|
812
|
-
o.removeEventListener("focus", W), o.removeEventListener("blur",
|
|
813
|
-
o.removeEventListener("cut",
|
|
817
|
+
d || (d = !0, S(), A(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
|
|
818
|
+
o.ariaReadOnly = f, o.style.whiteSpace = u, O.m(), m.removeEventListener("selectionchange", q),
|
|
819
|
+
o.removeEventListener("keydown", P), o.removeEventListener("input", L), o.removeEventListener("beforeinput", C),
|
|
820
|
+
o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend", U),
|
|
821
|
+
o.removeEventListener("focus", W), o.removeEventListener("blur", G), o.removeEventListener("copy", X),
|
|
822
|
+
o.removeEventListener("cut", Y), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
|
|
814
823
|
o.removeEventListener("dragstart", et), o.removeEventListener("dragend", nt), rt.forEach(t => {
|
|
815
824
|
t();
|
|
816
825
|
}));
|
|
817
826
|
};
|
|
818
827
|
}
|
|
819
828
|
};
|
|
820
|
-
return
|
|
821
|
-
},
|
|
829
|
+
return V.exec(vt), V;
|
|
830
|
+
}, Pt = (t, e) => {
|
|
822
831
|
t.hook("paste", t => {
|
|
823
832
|
for (const n of t.items) if ("file" === n.kind) {
|
|
824
833
|
const t = e[n.type];
|
|
@@ -833,28 +842,28 @@ const It = [], Ct = () => {}, Rt = t => {
|
|
|
833
842
|
});
|
|
834
843
|
};
|
|
835
844
|
|
|
836
|
-
function
|
|
845
|
+
function Lt(e, n) {
|
|
837
846
|
const r = n && n.serializer;
|
|
838
847
|
e.hook("copy", n => {
|
|
839
848
|
n.setData("text/plain", a({
|
|
840
|
-
children:
|
|
849
|
+
children: L(e.doc, ...t(e.selection))
|
|
841
850
|
}, r));
|
|
842
851
|
}), e.hook("paste", t => t.getData("text/plain"));
|
|
843
852
|
}
|
|
844
853
|
|
|
845
|
-
function
|
|
854
|
+
function Ct(t, e) {
|
|
846
855
|
let n = null;
|
|
847
856
|
t.hook("mount", t => (n = t, () => {
|
|
848
857
|
n = null;
|
|
849
858
|
})), t.hook("copy", t => {
|
|
850
859
|
if (!n) return;
|
|
851
860
|
const e = document.createElement("div");
|
|
852
|
-
e.appendChild(
|
|
861
|
+
e.appendChild(gt(yt(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
|
|
853
862
|
}), t.hook("paste", ((t, e = []) => (n, r) => {
|
|
854
863
|
const o = n.getData("text/html");
|
|
855
864
|
if (o) {
|
|
856
865
|
let n = (new DOMParser).parseFromString(o, "text/html").body, c = !1;
|
|
857
|
-
for (const t of [ ...n.childNodes ])
|
|
866
|
+
for (const t of [ ...n.childNodes ]) et(t) ? "StartFragment" === t.data ? (c = !0,
|
|
858
867
|
n = new DocumentFragment) : "EndFragment" === t.data && (c = !1) : c && n.appendChild(t);
|
|
859
868
|
return ((t, e, n, r) => e(() => {
|
|
860
869
|
let t, e = null, o = "", c = !1;
|
|
@@ -865,9 +874,9 @@ function Bt(t, e) {
|
|
|
865
874
|
children: e
|
|
866
875
|
}), e = null, c = !1;
|
|
867
876
|
};
|
|
868
|
-
for (;t = ft(); ) if (4 === t) a(); else if (c = !0, 1 === t) o +=
|
|
877
|
+
for (;t = ft(); ) if (4 === t) a(); else if (c = !0, 1 === t) o += nt().data; else if (2 === t) {
|
|
869
878
|
i();
|
|
870
|
-
const t = r(
|
|
879
|
+
const t = r(nt());
|
|
871
880
|
t && e.push(t);
|
|
872
881
|
} else 3 === t && a();
|
|
873
882
|
return a(), s.length || s.push({
|
|
@@ -884,21 +893,21 @@ function Bt(t, e) {
|
|
|
884
893
|
})(e.serializeText, e.serializers));
|
|
885
894
|
}
|
|
886
895
|
|
|
887
|
-
const
|
|
896
|
+
const Bt = "application/x-editate-editor";
|
|
888
897
|
|
|
889
|
-
function
|
|
898
|
+
function Ht(e) {
|
|
890
899
|
e.hook("copy", n => {
|
|
891
|
-
n.setData(
|
|
900
|
+
n.setData(Bt, JSON.stringify(L(e.doc, ...t(e.selection))));
|
|
892
901
|
}), e.hook("paste", t => {
|
|
893
902
|
try {
|
|
894
|
-
return JSON.parse(t.getData(
|
|
903
|
+
return JSON.parse(t.getData(Bt));
|
|
895
904
|
} catch (t) {
|
|
896
905
|
return null;
|
|
897
906
|
}
|
|
898
907
|
});
|
|
899
908
|
}
|
|
900
909
|
|
|
901
|
-
function
|
|
910
|
+
function Nt(t) {
|
|
902
911
|
t.hook("apply", t => {
|
|
903
912
|
console.log("apply", t);
|
|
904
913
|
}), t.on("change", () => {
|
|
@@ -911,13 +920,13 @@ function Ft(t) {
|
|
|
911
920
|
function Ut(t, e) {
|
|
912
921
|
r(e).forEach(n => {
|
|
913
922
|
const r = e[n];
|
|
914
|
-
t.hook("keyboard",
|
|
923
|
+
t.hook("keyboard", Mt(n, () => {
|
|
915
924
|
r();
|
|
916
925
|
}));
|
|
917
926
|
});
|
|
918
927
|
}
|
|
919
928
|
|
|
920
|
-
function
|
|
929
|
+
function Ft(t) {
|
|
921
930
|
t.hook("mount", t => {
|
|
922
931
|
t.ariaMultiLine = null;
|
|
923
932
|
}), t.hook("apply", (t, e) => {
|
|
@@ -926,22 +935,22 @@ function Wt(t) {
|
|
|
926
935
|
text: t.text.replaceAll("\n", "")
|
|
927
936
|
} : "insert_node" === t.type && (t = {
|
|
928
937
|
...t,
|
|
929
|
-
fragment: [
|
|
938
|
+
fragment: [ A(...t.fragment) ]
|
|
930
939
|
}), e(t);
|
|
931
940
|
});
|
|
932
941
|
}
|
|
933
942
|
|
|
934
|
-
const
|
|
935
|
-
const o =
|
|
943
|
+
const Vt = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
944
|
+
const o = It({
|
|
936
945
|
...r,
|
|
937
946
|
doc: {
|
|
938
947
|
children: l(t)
|
|
939
948
|
}
|
|
940
|
-
}).exec(
|
|
941
|
-
return e && o.exec(
|
|
949
|
+
}).exec(Lt);
|
|
950
|
+
return e && o.exec(Ft), o.on("change", () => {
|
|
942
951
|
n(a(o.doc));
|
|
943
952
|
}), o;
|
|
944
953
|
};
|
|
945
954
|
|
|
946
|
-
export {
|
|
955
|
+
export { U as Delete, q as Format, V as InsertNode, F as InsertText, Tt as Redo, At as Redoable, G as ReplaceDoc, W as ReplaceText, X as SetBlockAttr, Y as ToggleBlockAttr, J as ToggleFormat, wt as Undo, St as Undoable, It as createEditor, Vt as createPlainEditor, Nt as debugPlugin, Pt as fileTransferPlugin, Ct as htmlTransferPlugin, Ht as internalTranferPlugin, Ut as keymapPlugin, Lt as plainTransferPlugin, Ft as singlelinePlugin };
|
|
947
956
|
//# sourceMappingURL=index.js.map
|