editate 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/index.cjs +173 -149
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +192 -168
- package/lib/index.js.map +1 -1
- package/package.json +3 -2
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n = Math.min, {keys: r, is: o} = Object, c = t => "string" == typeof t, s = t => "function" == typeof t, i = s(queueMicrotask) ? queueMicrotask : t => {
|
|
2
2
|
Promise.resolve().then(t);
|
|
3
|
-
}, a = (t, e = t =>
|
|
3
|
+
}, a = (t, e = t => y(t) ? t.text : "") => t.children.reduce((t, n, r) => {
|
|
4
4
|
const o = g(n);
|
|
5
5
|
return 0 !== r && o && (t += "\n"), t + (o ? n.children.reduce((t, n) => t + e(n), "") : "");
|
|
6
6
|
}, ""), l = (t, e, n) => t.split("\n").map(t => ({
|
|
@@ -9,63 +9,64 @@ 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 = "set_attr",
|
|
12
|
+
})), f = "delete", u = "insert_text", d = "insert_node", p = "set_attr", 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
|
-
}, k = new WeakMap,
|
|
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 += b(e), 0 !== o && g(e) && r++, o++;
|
|
20
20
|
}
|
|
21
21
|
return r;
|
|
22
|
-
},
|
|
22
|
+
}, b = t => {
|
|
23
23
|
if (g(t)) {
|
|
24
24
|
let e = k.get(t);
|
|
25
|
-
return null == e && k.set(t, e =
|
|
25
|
+
return null == e && k.set(t, e = x(t)), e;
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return y(t) ? t.text.length : 1;
|
|
28
28
|
}, m = (t, [e, n]) => {
|
|
29
29
|
let r = 0;
|
|
30
|
-
for (const n of e) r +=
|
|
30
|
+
for (const n of e) r += x(t, 0, n), 0 !== n && r++, t = t.children[n];
|
|
31
31
|
return r + n;
|
|
32
32
|
}, v = (t, e) => {
|
|
33
33
|
const n = I(t, e);
|
|
34
34
|
return [ n.t, n.o ];
|
|
35
|
-
}, w = (t, [e, n]) => [ m(t, e), m(t, n) ], M = (t, [e, n]) => [ v(t, e), v(t, n) ],
|
|
35
|
+
}, w = (t, [e, n]) => [ m(t, e), m(t, n) ], M = (t, [e, n]) => [ v(t, e), v(t, n) ], E = (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];
|
|
39
|
-
|
|
39
|
+
y(e) && y(o) && _(e, o) ? (t[r - 1] = {
|
|
40
40
|
...e,
|
|
41
41
|
text: e.text + o.text
|
|
42
42
|
}, t.splice(r, 1), n--) : r++;
|
|
43
43
|
}
|
|
44
44
|
for (r = e; r <= 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
|
+
}, S = (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
52
|
t[r - 1] = O(e, o), t.splice(r, 1), n--;
|
|
53
53
|
}
|
|
54
|
-
},
|
|
54
|
+
}, D = (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
|
}, O = (...t) => ({
|
|
60
60
|
...t[0],
|
|
61
|
-
children: t.reduce((t, e) => (
|
|
61
|
+
children: t.reduce((t, e) => (D(t, e.children, E), t), [])
|
|
62
62
|
}), A = ({children: t}, e) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
const n = t.length;
|
|
64
|
+
for (let r = 0; r < n; r++) {
|
|
65
|
+
const n = t[r];
|
|
66
|
+
let o = b(n);
|
|
67
|
+
if (g(n) && o++, o > e || o === e && y(n) && !n.text) return {
|
|
68
|
+
i: n,
|
|
69
|
+
l: r,
|
|
69
70
|
o: e
|
|
70
71
|
};
|
|
71
72
|
e -= o;
|
|
@@ -101,7 +102,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
101
102
|
}
|
|
102
103
|
{
|
|
103
104
|
const r = n.slice(0, c), s = n.slice(c + 1);
|
|
104
|
-
if (
|
|
105
|
+
if (y(e)) {
|
|
105
106
|
const t = e.text.slice(0, o), n = e.text.slice(o);
|
|
106
107
|
!t && r.length || r.push({
|
|
107
108
|
...e,
|
|
@@ -120,9 +121,13 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
120
121
|
} ];
|
|
121
122
|
}
|
|
122
123
|
}
|
|
124
|
+
const o = n[n.length - 1];
|
|
123
125
|
return [ t, {
|
|
124
126
|
...t,
|
|
125
|
-
children: [
|
|
127
|
+
children: y(o) ? [ {
|
|
128
|
+
...o,
|
|
129
|
+
text: ""
|
|
130
|
+
} ] : []
|
|
126
131
|
} ];
|
|
127
132
|
}, C = (t, e, n, r = 0) => {
|
|
128
133
|
if (r < e.length) {
|
|
@@ -138,11 +143,11 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
138
143
|
return n;
|
|
139
144
|
}, H = (t, e, n, r) => {
|
|
140
145
|
const [o, c] = P(t, e), s = e < n ? P(t, n)[1] : c, i = o.children.slice();
|
|
141
|
-
return
|
|
146
|
+
return D(i, r, S), D(i, s.children, S), {
|
|
142
147
|
...t,
|
|
143
148
|
children: i
|
|
144
149
|
};
|
|
145
|
-
}, R = (t, e, n) => e >= n ? [] : P(P(t, n)[0], e)[1].children,
|
|
150
|
+
}, R = (t, e, n) => e >= n ? [] : P(P(t, n)[0], e)[1].children, T = (t, e) => e >= 0 && e <= b(t), B = (t, e) => e.reduce((t, e) => L(t, e), t), L = (t, e) => {
|
|
146
151
|
switch (e.type) {
|
|
147
152
|
case f:
|
|
148
153
|
{
|
|
@@ -161,23 +166,23 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
161
166
|
case d:
|
|
162
167
|
{
|
|
163
168
|
const {at: n, fragment: r} = e;
|
|
164
|
-
if (t >= n) return t +
|
|
169
|
+
if (t >= n) return t + b({
|
|
165
170
|
children: r
|
|
166
171
|
});
|
|
167
172
|
break;
|
|
168
173
|
}
|
|
169
174
|
}
|
|
170
175
|
return t;
|
|
171
|
-
},
|
|
176
|
+
}, N = ([t, e], n) => [ L(t, n), L(e, n) ];
|
|
172
177
|
|
|
173
|
-
function
|
|
178
|
+
function V(e, n = t(e.selection)) {
|
|
174
179
|
e.apply({
|
|
175
180
|
type: "delete",
|
|
176
181
|
range: n
|
|
177
182
|
});
|
|
178
183
|
}
|
|
179
184
|
|
|
180
|
-
function
|
|
185
|
+
function F(t, e, n = t.selection[0]) {
|
|
181
186
|
t.apply({
|
|
182
187
|
type: "insert_text",
|
|
183
188
|
at: n,
|
|
@@ -210,7 +215,7 @@ function q(e, n) {
|
|
|
210
215
|
function J(t, e) {
|
|
211
216
|
t.apply({
|
|
212
217
|
type: "delete",
|
|
213
|
-
range: [ 0,
|
|
218
|
+
range: [ 0, b(t.doc) ]
|
|
214
219
|
}).apply({
|
|
215
220
|
type: "insert_node",
|
|
216
221
|
at: 0,
|
|
@@ -227,13 +232,22 @@ function U(e, n, r, o = t(e.selection)) {
|
|
|
227
232
|
});
|
|
228
233
|
}
|
|
229
234
|
|
|
230
|
-
function G(
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
function G(n, r, o = t(n.selection)) {
|
|
236
|
+
let c;
|
|
237
|
+
if (e(o)) {
|
|
238
|
+
const t = ((t, e) => {
|
|
239
|
+
const n = I(t, e);
|
|
240
|
+
return A(n.i, n.o);
|
|
241
|
+
})(n.doc, o[0]);
|
|
242
|
+
if (!t) return;
|
|
243
|
+
c = [ t.i ];
|
|
244
|
+
} else c = R(n.doc, ...o).flatMap(t => t.children);
|
|
245
|
+
const s = c.filter(y);
|
|
246
|
+
s.length && n.apply({
|
|
233
247
|
type: "set_attr",
|
|
234
|
-
range:
|
|
235
|
-
key:
|
|
236
|
-
value: !!
|
|
248
|
+
range: o,
|
|
249
|
+
key: r,
|
|
250
|
+
value: !!s.some(t => !t[r])
|
|
237
251
|
});
|
|
238
252
|
}
|
|
239
253
|
|
|
@@ -266,9 +280,10 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
266
280
|
if (null != Y) return Y;
|
|
267
281
|
if (X) if ((t => 3 === t.nodeType)(X)) {
|
|
268
282
|
const t = X.data;
|
|
269
|
-
if (t) return Y = "\n" === t ?
|
|
283
|
+
if (t) return Y = "\n" === t ? at() ? 3 : 5 : 1;
|
|
270
284
|
} else if ($(X)) {
|
|
271
|
-
if ("BR" === X.tagName) return Y =
|
|
285
|
+
if ("BR" === X.tagName) return Y = at() ? 3 : 5;
|
|
286
|
+
if (it(X)) return Y = 6;
|
|
272
287
|
if (K.u(X)) return Y = 2;
|
|
273
288
|
if (K.p(X)) return Y = 4;
|
|
274
289
|
}
|
|
@@ -277,7 +292,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
277
292
|
for (;(Y = null) || (X = z.nextSibling()); ) if (4 === rt()) return;
|
|
278
293
|
}, st = () => {
|
|
279
294
|
for (;(Y = null) || (X = z.parentNode()); ) if (4 === rt()) return;
|
|
280
|
-
}, it = () => {
|
|
295
|
+
}, it = t => "TEMPLATE" === t.tagName, at = () => {
|
|
281
296
|
const t = X.parentNode;
|
|
282
297
|
return Q(() => {
|
|
283
298
|
for (;ot(); ) {
|
|
@@ -286,7 +301,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
286
301
|
}
|
|
287
302
|
return !1;
|
|
288
303
|
});
|
|
289
|
-
},
|
|
304
|
+
}, lt = () => {
|
|
290
305
|
for (;;) {
|
|
291
306
|
if (2 === rt()) {
|
|
292
307
|
const t = X;
|
|
@@ -294,40 +309,40 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
294
309
|
} else ot();
|
|
295
310
|
if (!X) break;
|
|
296
311
|
const t = rt();
|
|
297
|
-
if (t) return t;
|
|
312
|
+
if (t && 6 !== t) return t;
|
|
298
313
|
}
|
|
299
|
-
},
|
|
314
|
+
}, ft = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), ut = t => ft.has(t.tagName), dt = new Set([ "EMBED", "IMG", "PICTURE", "AUDIO", "VIDEO", "SVG", "CANVAS", "MATH", "IFRAME", "OBJECT" ]), pt = t => "false" === t.contentEditable || dt.has(t.tagName), ht = (t, e) => t.compareDocumentPosition(e), yt = t => t.ownerDocument, gt = t => yt(t).getSelection(), _t = (t, e) => {
|
|
300
315
|
if (t.rangeCount) {
|
|
301
316
|
const n = t.getRangeAt(0);
|
|
302
317
|
if (e.contains(n.commonAncestorContainer)) return n;
|
|
303
318
|
}
|
|
304
|
-
},
|
|
305
|
-
const o =
|
|
306
|
-
(n ||
|
|
319
|
+
}, kt = (t, e, n, r) => {
|
|
320
|
+
const o = gt(t);
|
|
321
|
+
(n || _t(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
|
|
307
322
|
o.extend(e.startContainer, e.startOffset)));
|
|
308
|
-
},
|
|
323
|
+
}, xt = (t, e, [n, r], o, c, s) => {
|
|
309
324
|
const i = 0 === o, a = o > 0, l = a ? r : n, f = a ? n : r;
|
|
310
325
|
if (0 === l[0].length && 0 === l[1] && i && !e.hasChildNodes()) {
|
|
311
326
|
const n = t.createRange();
|
|
312
|
-
return n.setStart(e, 0), n.setEnd(e, 0),
|
|
327
|
+
return n.setStart(e, 0), n.setEnd(e, 0), kt(e, n, s);
|
|
313
328
|
}
|
|
314
329
|
const u = bt(e, l, c);
|
|
315
330
|
if (!u) return;
|
|
316
331
|
const d = i ? u : bt(e, f, c);
|
|
317
332
|
if (!d) return;
|
|
318
|
-
const p = t.createRange(), [
|
|
319
|
-
$(
|
|
320
|
-
|
|
333
|
+
const p = t.createRange(), [h, y] = u, [g, _] = d;
|
|
334
|
+
$(h) ? y < 1 ? p.setStartBefore(h) : p.setStartAfter(h) : p.setStart(h, y), $(g) ? _ < 1 ? p.setEndBefore(g) : p.setEndAfter(g) : p.setEnd(g, _),
|
|
335
|
+
kt(e, p, s, a);
|
|
321
336
|
}, bt = (t, [e, n], r) => r(() => {
|
|
322
337
|
let t, r = 0;
|
|
323
|
-
for (;t =
|
|
338
|
+
for (;t = lt(); ) if (4 === t) {
|
|
324
339
|
if (r < e.length) for (let t = e[r++]; t > 0; t--) ct();
|
|
325
340
|
} else {
|
|
326
341
|
const t = nt();
|
|
327
342
|
if (n <= t) return [ et(), n ];
|
|
328
343
|
n -= t;
|
|
329
344
|
}
|
|
330
|
-
}, t),
|
|
345
|
+
}, t), mt = (t, e, r, o) => {
|
|
331
346
|
let c = !0;
|
|
332
347
|
if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
|
|
333
348
|
if ($(e) && e.hasChildNodes()) {
|
|
@@ -342,12 +357,12 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
342
357
|
for (;(n = et()) && n !== t; ) e.unshift(n), st();
|
|
343
358
|
if (!e.length) return [ 0 ];
|
|
344
359
|
let r = 0, o = e[e.length - 1];
|
|
345
|
-
for (;o = o.previousElementSibling; ) r++;
|
|
360
|
+
for (;o = o.previousElementSibling; ) it(o) || r++;
|
|
346
361
|
return [ r ];
|
|
347
362
|
});
|
|
348
363
|
let s = 0;
|
|
349
|
-
for (;
|
|
350
|
-
const t =
|
|
364
|
+
for (;lt(); ) {
|
|
365
|
+
const t = ht(e, et());
|
|
351
366
|
if (0 === t || 16 & t) {
|
|
352
367
|
if (c) break;
|
|
353
368
|
} else if (4 & t) break;
|
|
@@ -355,10 +370,10 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
355
370
|
}
|
|
356
371
|
return [ n, s + r ];
|
|
357
372
|
}, t, e);
|
|
358
|
-
},
|
|
359
|
-
const s =
|
|
360
|
-
return [ s, r === c && n === o ? s :
|
|
361
|
-
},
|
|
373
|
+
}, vt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
|
|
374
|
+
const s = mt(t, r, n, e);
|
|
375
|
+
return [ s, r === c && n === o ? s : mt(t, c, o, e) ];
|
|
376
|
+
}, wt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), Mt = (t, e) => {
|
|
362
377
|
const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
|
|
363
378
|
let s = !1, i = !1, a = !1, l = !1;
|
|
364
379
|
return r.forEach(t => {
|
|
@@ -372,7 +387,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
372
387
|
break;
|
|
373
388
|
|
|
374
389
|
case "Mod":
|
|
375
|
-
|
|
390
|
+
wt ? a = !0 : i = !0;
|
|
376
391
|
break;
|
|
377
392
|
|
|
378
393
|
case "Alt":
|
|
@@ -388,7 +403,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
388
403
|
};
|
|
389
404
|
};
|
|
390
405
|
|
|
391
|
-
function
|
|
406
|
+
function Et(t) {
|
|
392
407
|
let e = 0, n = 0, r = !1;
|
|
393
408
|
const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e], a = () => e > 0, l = () => e < s.length - 1, f = () => {
|
|
394
409
|
if (a()) {
|
|
@@ -401,7 +416,7 @@ function Mt(t) {
|
|
|
401
416
|
if (l()) {
|
|
402
417
|
e++;
|
|
403
418
|
const [n, c, s] = i(), a = t.doc;
|
|
404
|
-
r = !0, t.exec(J, n.children), r = !1, o(a, t.doc) || (t.selection = [
|
|
419
|
+
r = !0, t.exec(J, n.children), r = !1, o(a, t.doc) || (t.selection = [ B(c[0], s), B(c[1], s) ]);
|
|
405
420
|
}
|
|
406
421
|
};
|
|
407
422
|
t.hook("apply", (i, a) => {
|
|
@@ -418,8 +433,8 @@ function Mt(t) {
|
|
|
418
433
|
}
|
|
419
434
|
n = t, s[e][0] = u, s[e][2].push(i), s.splice(e + 1), e > 500 && (e--, s.shift());
|
|
420
435
|
}
|
|
421
|
-
}), t.hook("keyboard",
|
|
422
|
-
t.set(
|
|
436
|
+
}), t.hook("keyboard", Mt("Mod+Z", f)), t.hook("keyboard", Mt("Shift+Mod+Z", u)),
|
|
437
|
+
t.set(Et, {
|
|
423
438
|
undo: f,
|
|
424
439
|
redo: u,
|
|
425
440
|
undoable: a,
|
|
@@ -428,26 +443,26 @@ function Mt(t) {
|
|
|
428
443
|
}
|
|
429
444
|
|
|
430
445
|
function St(t) {
|
|
431
|
-
t.get(
|
|
446
|
+
t.get(Et).undo();
|
|
432
447
|
}
|
|
433
448
|
|
|
434
449
|
function Dt(t) {
|
|
435
|
-
t.get(
|
|
450
|
+
t.get(Et).redo();
|
|
436
451
|
}
|
|
437
452
|
|
|
438
|
-
function
|
|
439
|
-
return t.get(
|
|
453
|
+
function Ot(t) {
|
|
454
|
+
return t.get(Et).undoable();
|
|
440
455
|
}
|
|
441
456
|
|
|
442
|
-
function
|
|
443
|
-
return t.get(
|
|
457
|
+
function At(t) {
|
|
458
|
+
return t.get(Et).redoable();
|
|
444
459
|
}
|
|
445
460
|
|
|
446
|
-
const
|
|
461
|
+
const It = [], Pt = () => {}, Ct = t => {
|
|
447
462
|
throw Error(t);
|
|
448
|
-
},
|
|
449
|
-
let
|
|
450
|
-
const
|
|
463
|
+
}, Ht = ({doc: n, readonly: r = !1, schema: a, isBlock: g = ut, onWarn: _ = console.warn, onError: k = Ct}) => {
|
|
464
|
+
let x = [ 0, 0 ];
|
|
465
|
+
const b = t => {
|
|
451
466
|
if (!a) return _("An unsafe operation was detected. We recommend using schema option."),
|
|
452
467
|
!0;
|
|
453
468
|
const e = a["~standard"].validate(t);
|
|
@@ -457,19 +472,19 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
457
472
|
}
|
|
458
473
|
return !1;
|
|
459
474
|
};
|
|
460
|
-
a && !
|
|
461
|
-
const v = new Map,
|
|
462
|
-
const e =
|
|
475
|
+
a && !b(n) && k("Invalid document");
|
|
476
|
+
const v = new Map, E = new WeakMap, S = t => v.get(t) || It, D = new Map, O = t => {
|
|
477
|
+
const e = D.get(t);
|
|
463
478
|
e && !e[1] && (e[1] = !0, i(() => {
|
|
464
479
|
e[1] = !1, e[0].forEach(t => {
|
|
465
480
|
t();
|
|
466
481
|
});
|
|
467
482
|
}));
|
|
468
483
|
}, P = t => {
|
|
469
|
-
if (!r) if (Array.isArray(t)) for (const e of t)
|
|
470
|
-
return
|
|
471
|
-
},
|
|
472
|
-
const e = n, r =
|
|
484
|
+
if (!r) if (Array.isArray(t)) for (const e of t) L(e); else L(t);
|
|
485
|
+
return F;
|
|
486
|
+
}, L = t => {
|
|
487
|
+
const e = n, r = S("apply"), c = r.length;
|
|
473
488
|
let s = 0;
|
|
474
489
|
const i = () => {
|
|
475
490
|
if (s < c) {
|
|
@@ -483,21 +498,21 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
483
498
|
case f:
|
|
484
499
|
{
|
|
485
500
|
const [r, o] = n.range;
|
|
486
|
-
|
|
501
|
+
T(t, r) && T(t, o) && r < o && (t = H(t, r, o, []), e = N(e, n));
|
|
487
502
|
break;
|
|
488
503
|
}
|
|
489
504
|
|
|
490
505
|
case u:
|
|
491
506
|
{
|
|
492
507
|
const {at: r, text: o} = n;
|
|
493
|
-
if (
|
|
508
|
+
if (T(t, r) && o) {
|
|
494
509
|
const {i: c, o: s} = I(t, r), i = A(c, s - 1);
|
|
495
510
|
let a;
|
|
496
511
|
if (i) {
|
|
497
512
|
const t = i.i;
|
|
498
|
-
|
|
513
|
+
y(t) && (a = t);
|
|
499
514
|
}
|
|
500
|
-
t = H(t, r, r, l(o, a, c)), e =
|
|
515
|
+
t = H(t, r, r, l(o, a, c)), e = N(e, n);
|
|
501
516
|
}
|
|
502
517
|
break;
|
|
503
518
|
}
|
|
@@ -505,24 +520,33 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
505
520
|
case d:
|
|
506
521
|
{
|
|
507
522
|
const {at: r, fragment: o} = n;
|
|
508
|
-
|
|
523
|
+
T(t, r) && o.length && (t = H(t, r, r, o), e = N(e, n));
|
|
509
524
|
break;
|
|
510
525
|
}
|
|
511
526
|
|
|
512
527
|
case p:
|
|
513
528
|
{
|
|
514
529
|
const {range: [e, r], key: o, value: c} = n;
|
|
515
|
-
|
|
530
|
+
if (T(t, e) && T(t, r) && e <= r) if (e === r) {
|
|
531
|
+
const {i: {children: n}, t: r} = I(t, e);
|
|
532
|
+
if (1 === n.length) {
|
|
533
|
+
const e = n[0];
|
|
534
|
+
y(e) && !e.text && (t = C(t, [ ...r, 0 ], {
|
|
535
|
+
...e,
|
|
536
|
+
[o]: c
|
|
537
|
+
}));
|
|
538
|
+
}
|
|
539
|
+
} else t = H(t, e, r, R(t, e, r).map(t => ({
|
|
516
540
|
...t,
|
|
517
|
-
children: t.children.map(t =>
|
|
541
|
+
children: t.children.map(t => y(t) ? {
|
|
518
542
|
...t,
|
|
519
543
|
[o]: c
|
|
520
544
|
} : t)
|
|
521
|
-
})))
|
|
545
|
+
})));
|
|
522
546
|
break;
|
|
523
547
|
}
|
|
524
548
|
|
|
525
|
-
case
|
|
549
|
+
case h:
|
|
526
550
|
{
|
|
527
551
|
const {path: e, key: r, value: o} = n, c = ((t, e) => {
|
|
528
552
|
for (let n = 0; n < e.length; n++) t = t.children[e[n]];
|
|
@@ -536,8 +560,8 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
536
560
|
}
|
|
537
561
|
}
|
|
538
562
|
return [ t, e ];
|
|
539
|
-
})(n,
|
|
540
|
-
(({type: t}) => t === d || t === p || t ===
|
|
563
|
+
})(n, x, t);
|
|
564
|
+
(({type: t}) => t === d || t === p || t === h)(t) && !b(e) || (n = e, x = r);
|
|
541
565
|
} catch (t) {
|
|
542
566
|
_("rollback operation: " + t);
|
|
543
567
|
}
|
|
@@ -546,18 +570,18 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
546
570
|
e && (t = e), s++, i();
|
|
547
571
|
};
|
|
548
572
|
i(), o(e, n) || O("change");
|
|
549
|
-
},
|
|
550
|
-
!((t, [e, n]) =>
|
|
573
|
+
}, V = t => {
|
|
574
|
+
!((t, [e, n]) => T(t, e) && T(t, n))(n, t) || x[0] === t[0] && x[1] === t[1] || (x = t,
|
|
551
575
|
O("selectionchange"));
|
|
552
|
-
},
|
|
576
|
+
}, F = {
|
|
553
577
|
get doc() {
|
|
554
578
|
return n;
|
|
555
579
|
},
|
|
556
580
|
get selection() {
|
|
557
|
-
return
|
|
581
|
+
return x;
|
|
558
582
|
},
|
|
559
583
|
set selection(t) {
|
|
560
|
-
|
|
584
|
+
V(t);
|
|
561
585
|
},
|
|
562
586
|
get readonly() {
|
|
563
587
|
return r;
|
|
@@ -567,8 +591,8 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
567
591
|
},
|
|
568
592
|
apply: P,
|
|
569
593
|
on: (t, e) => {
|
|
570
|
-
let n =
|
|
571
|
-
n ||
|
|
594
|
+
let n = D.get(t);
|
|
595
|
+
n || D.set(t, n = [ new Set, !1 ]);
|
|
572
596
|
const r = n[0];
|
|
573
597
|
return r.add(e), () => {
|
|
574
598
|
r.delete(e);
|
|
@@ -582,18 +606,18 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
582
606
|
};
|
|
583
607
|
},
|
|
584
608
|
exec: (t, ...e) => {
|
|
585
|
-
const n = t(
|
|
586
|
-
return void 0 === n ?
|
|
609
|
+
const n = t(F, ...e);
|
|
610
|
+
return void 0 === n ? F : n;
|
|
587
611
|
},
|
|
588
|
-
get: t => (
|
|
589
|
-
set: (t, e) => (
|
|
612
|
+
get: t => (E.has(t) || k("No value found for key"), E.get(t)),
|
|
613
|
+
set: (t, e) => (E.set(t, e), F),
|
|
590
614
|
input: o => {
|
|
591
615
|
if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return _("beforeinput event is not supported."),
|
|
592
|
-
|
|
616
|
+
Pt;
|
|
593
617
|
const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
|
|
594
618
|
o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
|
|
595
|
-
let d = !1, p = null,
|
|
596
|
-
const
|
|
619
|
+
let d = !1, p = null, h = !1, y = !1, k = !1;
|
|
620
|
+
const b = yt(o), v = (t => {
|
|
597
621
|
const e = (n, r, o) => {
|
|
598
622
|
const c = K, s = Q, i = z, a = X, l = Y;
|
|
599
623
|
try {
|
|
@@ -605,21 +629,21 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
605
629
|
};
|
|
606
630
|
return e;
|
|
607
631
|
})({
|
|
608
|
-
h:
|
|
632
|
+
h: b,
|
|
609
633
|
p: g,
|
|
610
|
-
u:
|
|
611
|
-
}),
|
|
634
|
+
u: pt
|
|
635
|
+
}), E = () => {
|
|
612
636
|
o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
|
|
613
637
|
};
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
638
|
+
E();
|
|
639
|
+
const D = F.on("change", () => {
|
|
640
|
+
y || requestAnimationFrame(() => {
|
|
641
|
+
y || o.focus({
|
|
618
642
|
preventScroll: !0
|
|
619
643
|
});
|
|
620
644
|
});
|
|
621
|
-
}), O =
|
|
622
|
-
for (const e of
|
|
645
|
+
}), O = F.on("readonly", E), A = t => {
|
|
646
|
+
for (const e of S("paste")) {
|
|
623
647
|
const n = e(t, v);
|
|
624
648
|
if (n) return n;
|
|
625
649
|
}
|
|
@@ -657,37 +681,37 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
657
681
|
}
|
|
658
682
|
};
|
|
659
683
|
})(o, () => {
|
|
660
|
-
|
|
684
|
+
xt(b, o, M(n, x), x[0] - x[1], v);
|
|
661
685
|
}), C = () => {
|
|
662
|
-
|
|
663
|
-
const n =
|
|
686
|
+
V(w(n, ((t, e) => {
|
|
687
|
+
const n = gt(t), r = _t(n, t);
|
|
664
688
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
665
|
-
const o =
|
|
689
|
+
const o = vt(t, e, r), c = ht(n.anchorNode, n.focusNode);
|
|
666
690
|
return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
|
|
667
691
|
})(o, v)));
|
|
668
692
|
}, H = () => {
|
|
669
693
|
const t = I.m();
|
|
670
|
-
I.k(!1), t.length && (I._(t),
|
|
671
|
-
|
|
694
|
+
I.k(!1), t.length && (I._(t), b.removeEventListener("selectionchange", U), xt(b, o, M(n, x), x[0] - x[1], v, !0),
|
|
695
|
+
b.addEventListener("selectionchange", U)), p && (V(p[1]), P(p[0]), p = null), h = !1;
|
|
672
696
|
}, R = t => {
|
|
673
|
-
if (!
|
|
674
|
-
},
|
|
675
|
-
|
|
676
|
-
},
|
|
697
|
+
if (!h) for (const e of S("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
|
|
698
|
+
}, T = () => {
|
|
699
|
+
h || H();
|
|
700
|
+
}, L = t => {
|
|
677
701
|
t.preventDefault();
|
|
678
702
|
const r = t.inputType;
|
|
679
703
|
if (r.startsWith("format")) return;
|
|
680
704
|
if ("historyUndo" === r || "historyRedo" === r) return;
|
|
681
|
-
|
|
705
|
+
h ? I.k(!0) : C();
|
|
682
706
|
const c = t.getTargetRanges()[0];
|
|
683
707
|
if (c) {
|
|
684
|
-
const s = w(n,
|
|
708
|
+
const s = w(n, vt(o, v, c));
|
|
685
709
|
let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
|
|
686
710
|
if (null == a) {
|
|
687
711
|
const e = t.dataTransfer;
|
|
688
712
|
e && (a = e.getData("text/plain"));
|
|
689
713
|
}
|
|
690
|
-
p || (p = [ [],
|
|
714
|
+
p || (p = [ [], x ]), i = p[0], e(s) || i.push({
|
|
691
715
|
type: "delete",
|
|
692
716
|
range: s
|
|
693
717
|
}), a && i.push({
|
|
@@ -696,31 +720,31 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
696
720
|
text: a
|
|
697
721
|
});
|
|
698
722
|
}
|
|
699
|
-
|
|
700
|
-
},
|
|
701
|
-
|
|
723
|
+
h || H();
|
|
724
|
+
}, N = () => {
|
|
725
|
+
h || C(), h = !0;
|
|
702
726
|
}, W = () => {
|
|
703
727
|
H();
|
|
704
728
|
}, q = () => {
|
|
705
|
-
|
|
729
|
+
y = !0, C();
|
|
706
730
|
}, J = () => {
|
|
707
|
-
|
|
731
|
+
y = !1;
|
|
708
732
|
}, U = () => {
|
|
709
|
-
!
|
|
733
|
+
!y || h || k || C();
|
|
710
734
|
}, G = t => {
|
|
711
|
-
if (C(), !e(
|
|
735
|
+
if (C(), !e(x)) for (const e of S("copy")) e(t);
|
|
712
736
|
}, Z = t => {
|
|
713
737
|
t.preventDefault(), G(t.clipboardData);
|
|
714
738
|
}, j = e => {
|
|
715
739
|
e.preventDefault(), r || (G(e.clipboardData), P({
|
|
716
740
|
type: "delete",
|
|
717
|
-
range: t(
|
|
741
|
+
range: t(x)
|
|
718
742
|
}));
|
|
719
743
|
}, $ = e => {
|
|
720
744
|
e.preventDefault();
|
|
721
745
|
const n = A(e.clipboardData);
|
|
722
746
|
if (n) {
|
|
723
|
-
const e = t(
|
|
747
|
+
const e = t(x), r = e[0], o = [ {
|
|
724
748
|
type: "delete",
|
|
725
749
|
range: e
|
|
726
750
|
} ];
|
|
@@ -739,22 +763,22 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
739
763
|
const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}, o) => {
|
|
740
764
|
if (t.caretPositionFromPoint) {
|
|
741
765
|
const c = t.caretPositionFromPoint(n, r);
|
|
742
|
-
if (c) return
|
|
766
|
+
if (c) return mt(e, c.offsetNode, c.offset, o);
|
|
743
767
|
} else if (t.caretRangeFromPoint) {
|
|
744
768
|
const c = t.caretRangeFromPoint(n, r);
|
|
745
|
-
if (c) return
|
|
769
|
+
if (c) return mt(e, c.startContainer, c.startOffset, o);
|
|
746
770
|
}
|
|
747
|
-
})(
|
|
771
|
+
})(b, o, e, v);
|
|
748
772
|
if (r && s) {
|
|
749
773
|
let e;
|
|
750
774
|
const o = [];
|
|
751
775
|
k && o.push({
|
|
752
776
|
type: "delete",
|
|
753
|
-
range: t(
|
|
777
|
+
range: t(x)
|
|
754
778
|
});
|
|
755
779
|
const i = A(r);
|
|
756
780
|
if (i) {
|
|
757
|
-
const t = m(n, s), r =
|
|
781
|
+
const t = m(n, s), r = B(t, o);
|
|
758
782
|
o.push(c(i) ? {
|
|
759
783
|
type: "insert_text",
|
|
760
784
|
at: r,
|
|
@@ -763,29 +787,29 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
763
787
|
type: "insert_node",
|
|
764
788
|
at: r,
|
|
765
789
|
fragment: i
|
|
766
|
-
}), e = [ r,
|
|
790
|
+
}), e = [ r, B(t, o) ];
|
|
767
791
|
}
|
|
768
|
-
P(o), e &&
|
|
792
|
+
P(o), e && V(e);
|
|
769
793
|
}
|
|
770
794
|
}, et = t => {
|
|
771
795
|
k = !0, G(t.dataTransfer);
|
|
772
796
|
}, nt = () => {
|
|
773
797
|
k = !1;
|
|
774
798
|
};
|
|
775
|
-
|
|
776
|
-
o.addEventListener("beforeinput",
|
|
799
|
+
b.addEventListener("selectionchange", U), o.addEventListener("keydown", R), o.addEventListener("input", T),
|
|
800
|
+
o.addEventListener("beforeinput", L), o.addEventListener("compositionstart", N),
|
|
777
801
|
o.addEventListener("compositionend", W), o.addEventListener("focus", q), o.addEventListener("blur", J),
|
|
778
802
|
o.addEventListener("copy", Z), o.addEventListener("cut", j), o.addEventListener("paste", $),
|
|
779
803
|
o.addEventListener("drop", tt), o.addEventListener("dragstart", et), o.addEventListener("dragend", nt);
|
|
780
804
|
const rt = [];
|
|
781
|
-
return
|
|
805
|
+
return S("mount").forEach(t => {
|
|
782
806
|
const e = t(o);
|
|
783
807
|
e && rt.push(e);
|
|
784
808
|
}), () => {
|
|
785
|
-
d || (d = !0,
|
|
786
|
-
o.ariaReadOnly = f, o.style.whiteSpace = u, I.v(),
|
|
787
|
-
o.removeEventListener("keydown", R), o.removeEventListener("input",
|
|
788
|
-
o.removeEventListener("compositionstart",
|
|
809
|
+
d || (d = !0, D(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
|
|
810
|
+
o.ariaReadOnly = f, o.style.whiteSpace = u, I.v(), b.removeEventListener("selectionchange", U),
|
|
811
|
+
o.removeEventListener("keydown", R), o.removeEventListener("input", T), o.removeEventListener("beforeinput", L),
|
|
812
|
+
o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend", W),
|
|
789
813
|
o.removeEventListener("focus", q), o.removeEventListener("blur", J), o.removeEventListener("copy", Z),
|
|
790
814
|
o.removeEventListener("cut", j), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
|
|
791
815
|
o.removeEventListener("dragstart", et), o.removeEventListener("dragend", nt), rt.forEach(t => {
|
|
@@ -794,8 +818,8 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
794
818
|
};
|
|
795
819
|
}
|
|
796
820
|
};
|
|
797
|
-
return
|
|
798
|
-
},
|
|
821
|
+
return F.exec(Et), F;
|
|
822
|
+
}, Rt = (t, e) => {
|
|
799
823
|
t.hook("paste", t => {
|
|
800
824
|
for (const n of t.items) if ("file" === n.kind) {
|
|
801
825
|
const t = e[n.type];
|
|
@@ -810,7 +834,7 @@ const At = [], It = () => {}, Pt = t => {
|
|
|
810
834
|
});
|
|
811
835
|
};
|
|
812
836
|
|
|
813
|
-
function
|
|
837
|
+
function Tt(e, n) {
|
|
814
838
|
const r = n && n.serializer;
|
|
815
839
|
e.hook("copy", n => {
|
|
816
840
|
n.setData("text/plain", a({
|
|
@@ -826,7 +850,7 @@ function Bt(t, e) {
|
|
|
826
850
|
})), t.hook("copy", t => {
|
|
827
851
|
if (!n) return;
|
|
828
852
|
const e = document.createElement("div");
|
|
829
|
-
e.appendChild(gt(
|
|
853
|
+
e.appendChild(_t(gt(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
|
|
830
854
|
}), t.hook("paste", ((t, e = []) => (n, r) => {
|
|
831
855
|
const o = n.getData("text/html");
|
|
832
856
|
if (o) {
|
|
@@ -842,7 +866,7 @@ function Bt(t, e) {
|
|
|
842
866
|
children: e
|
|
843
867
|
}), e = null, c = !1;
|
|
844
868
|
};
|
|
845
|
-
for (;t =
|
|
869
|
+
for (;t = lt(); ) if (4 === t) a(); else if (c = !0, 1 === t) o += et().data; else if (2 === t) {
|
|
846
870
|
i();
|
|
847
871
|
const t = r(et());
|
|
848
872
|
t && e.push(t);
|
|
@@ -861,21 +885,21 @@ function Bt(t, e) {
|
|
|
861
885
|
})(e.serializeText, e.serializers));
|
|
862
886
|
}
|
|
863
887
|
|
|
864
|
-
const
|
|
888
|
+
const Lt = "application/x-editate-editor";
|
|
865
889
|
|
|
866
|
-
function
|
|
890
|
+
function Nt(e) {
|
|
867
891
|
e.hook("copy", n => {
|
|
868
|
-
n.setData(
|
|
892
|
+
n.setData(Lt, JSON.stringify(R(e.doc, ...t(e.selection))));
|
|
869
893
|
}), e.hook("paste", t => {
|
|
870
894
|
try {
|
|
871
|
-
return JSON.parse(t.getData(
|
|
895
|
+
return JSON.parse(t.getData(Lt));
|
|
872
896
|
} catch (t) {
|
|
873
897
|
return null;
|
|
874
898
|
}
|
|
875
899
|
});
|
|
876
900
|
}
|
|
877
901
|
|
|
878
|
-
function
|
|
902
|
+
function Vt(t) {
|
|
879
903
|
t.hook("apply", t => {
|
|
880
904
|
console.log("apply", t);
|
|
881
905
|
}), t.on("change", () => {
|
|
@@ -885,16 +909,16 @@ function Ft(t) {
|
|
|
885
909
|
});
|
|
886
910
|
}
|
|
887
911
|
|
|
888
|
-
function
|
|
912
|
+
function Ft(t, e) {
|
|
889
913
|
r(e).forEach(n => {
|
|
890
914
|
const r = e[n];
|
|
891
|
-
t.hook("keyboard",
|
|
915
|
+
t.hook("keyboard", Mt(n, () => {
|
|
892
916
|
r();
|
|
893
917
|
}));
|
|
894
918
|
});
|
|
895
919
|
}
|
|
896
920
|
|
|
897
|
-
function
|
|
921
|
+
function Wt(t) {
|
|
898
922
|
t.hook("mount", t => {
|
|
899
923
|
t.ariaMultiLine = null;
|
|
900
924
|
}), t.hook("apply", (t, e) => {
|
|
@@ -908,17 +932,17 @@ function Tt(t) {
|
|
|
908
932
|
});
|
|
909
933
|
}
|
|
910
934
|
|
|
911
|
-
const
|
|
912
|
-
const o =
|
|
935
|
+
const qt = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
936
|
+
const o = Ht({
|
|
913
937
|
...r,
|
|
914
938
|
doc: {
|
|
915
939
|
children: l(t)
|
|
916
940
|
}
|
|
917
|
-
}).exec(
|
|
941
|
+
}).exec(Tt);
|
|
918
942
|
return o.on("change", () => {
|
|
919
943
|
n(a(o.doc));
|
|
920
|
-
}), e && o.exec(
|
|
944
|
+
}), e && o.exec(Wt), o;
|
|
921
945
|
};
|
|
922
946
|
|
|
923
|
-
export {
|
|
947
|
+
export { V as Delete, U as Format, W as InsertNode, F as InsertText, Dt as Redo, At as Redoable, J as ReplaceDoc, q as ReplaceText, Z as SetBlockAttr, j as ToggleBlockAttr, G as ToggleFormat, St as Undo, Ot as Undoable, Ht as createEditor, qt as createPlainEditor, Vt as debugPlugin, Rt as fileTransferPlugin, Bt as htmlTransferPlugin, Nt as internalTranferPlugin, Ft as keymapPlugin, Tt as plainTransferPlugin, Wt as singlelinePlugin };
|
|
924
948
|
//# sourceMappingURL=index.js.map
|