editate 0.6.1 → 0.6.2
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/commands.d.ts +3 -3
- package/lib/editor.d.ts +11 -5
- package/lib/index.cjs +197 -192
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +216 -211
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -9,41 +9,34 @@ 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", y = "set_node_attr", h = t => "text" in t, g = t => "children" in t,
|
|
12
|
+
})), f = "delete", u = "insert_text", d = "insert_node", p = "set_attr", y = "set_node_attr", h = 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, b = ({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 += x(e), 0 !== o && g(e) && r++, o++;
|
|
20
20
|
}
|
|
21
21
|
return r;
|
|
22
|
-
},
|
|
22
|
+
}, x = t => {
|
|
23
23
|
if (g(t)) {
|
|
24
|
-
let e =
|
|
25
|
-
return null == e &&
|
|
24
|
+
let e = k.get(t);
|
|
25
|
+
return null == e && k.set(t, e = b(t)), e;
|
|
26
26
|
}
|
|
27
27
|
return h(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 += b(t, 0, n), 0 !== n && r++, t = t.children[n];
|
|
31
31
|
return r + n;
|
|
32
|
-
},
|
|
33
|
-
const n =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!r) break;
|
|
37
|
-
const o = r.t, c = r.o;
|
|
38
|
-
if (!g(c)) break;
|
|
39
|
-
e = r.i, n.push(o), t = c;
|
|
40
|
-
}
|
|
41
|
-
return [ n, e ];
|
|
42
|
-
}, v = (t, [e, n]) => [ m(t, e), m(t, n) ], M = (t, [e, n]) => [ w(t, e), w(t, n) ], E = (t, e = 0, n = t.length - 1) => {
|
|
32
|
+
}, v = (t, e) => {
|
|
33
|
+
const n = I(t, e);
|
|
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) ], S = (t, e = 0, n = t.length - 1) => {
|
|
43
36
|
let r = e + 1;
|
|
44
37
|
for (;r <= n; ) {
|
|
45
38
|
const e = t[r - 1], o = t[r];
|
|
46
|
-
h(e) && h(o) &&
|
|
39
|
+
h(e) && h(o) && _(e, o) ? (t[r - 1] = {
|
|
47
40
|
...e,
|
|
48
41
|
text: e.text + o.text
|
|
49
42
|
}, t.splice(r, 1), n--) : r++;
|
|
@@ -52,38 +45,52 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
52
45
|
const e = t[r];
|
|
53
46
|
h(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
|
|
54
47
|
}
|
|
55
|
-
},
|
|
48
|
+
}, D = (t, e = 0, n = t.length - 1) => {
|
|
56
49
|
let r = e + 1;
|
|
57
50
|
for (;r <= n; ) {
|
|
58
51
|
const e = t[r - 1], o = t[r];
|
|
59
52
|
t[r - 1] = O(e, o), t.splice(r, 1), n--;
|
|
60
53
|
}
|
|
61
|
-
},
|
|
54
|
+
}, E = (t, e, n) => {
|
|
62
55
|
if (e.length) {
|
|
63
56
|
const r = t.length;
|
|
64
57
|
t.push(...e), r && n(t, r - 1, r);
|
|
65
58
|
}
|
|
66
59
|
}, O = (...t) => ({
|
|
67
60
|
...t[0],
|
|
68
|
-
children: t.reduce((t, e) => (
|
|
61
|
+
children: t.reduce((t, e) => (E(t, e.children, S), t), [])
|
|
69
62
|
}), A = ({children: t}, e) => {
|
|
70
63
|
for (let n = 0; n < t.length; n++) {
|
|
71
64
|
const r = t[n];
|
|
72
|
-
let o =
|
|
65
|
+
let o = x(r);
|
|
73
66
|
if (g(r) && o++, o > e) return {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
i: r,
|
|
68
|
+
l: n,
|
|
69
|
+
o: e
|
|
77
70
|
};
|
|
78
71
|
e -= o;
|
|
79
72
|
}
|
|
80
73
|
return null;
|
|
81
74
|
}, I = (t, e) => {
|
|
75
|
+
const n = [];
|
|
76
|
+
for (;t; ) {
|
|
77
|
+
const r = A(t, e);
|
|
78
|
+
if (!r) break;
|
|
79
|
+
const o = r.i;
|
|
80
|
+
if (!g(o)) break;
|
|
81
|
+
e = r.o, t = o, n.push(r.l);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
i: t,
|
|
85
|
+
t: n,
|
|
86
|
+
o: e
|
|
87
|
+
};
|
|
88
|
+
}, P = (t, e) => {
|
|
82
89
|
const n = t.children, r = A(t, e);
|
|
83
90
|
if (r) {
|
|
84
|
-
const {
|
|
91
|
+
const {i: e, o, l: c} = r;
|
|
85
92
|
if (g(e)) {
|
|
86
|
-
const [r, s] =
|
|
93
|
+
const [r, s] = P(e, o), i = n.slice(0, c), a = n.slice(c + 1);
|
|
87
94
|
return i.push(r), a.unshift(s), [ {
|
|
88
95
|
...t,
|
|
89
96
|
children: i
|
|
@@ -117,9 +124,6 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
117
124
|
...t,
|
|
118
125
|
children: []
|
|
119
126
|
} ];
|
|
120
|
-
}, P = (t, e) => {
|
|
121
|
-
for (let n = 0; n < e.length; n++) t = t.children[e[n]];
|
|
122
|
-
return t;
|
|
123
127
|
}, C = (t, e, n, r = 0) => {
|
|
124
128
|
if (r < e.length) {
|
|
125
129
|
const o = e[r];
|
|
@@ -133,12 +137,12 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
133
137
|
}
|
|
134
138
|
return n;
|
|
135
139
|
}, H = (t, e, n, r) => {
|
|
136
|
-
const [o, c] =
|
|
137
|
-
return
|
|
140
|
+
const [o, c] = P(t, e), s = e < n ? P(t, n)[1] : c, i = o.children.slice();
|
|
141
|
+
return E(i, r, D), E(i, s.children, D), {
|
|
138
142
|
...t,
|
|
139
143
|
children: i
|
|
140
144
|
};
|
|
141
|
-
}, R = (t, e, n) => e >= n ? [] :
|
|
145
|
+
}, R = (t, e, n) => e >= n ? [] : P(P(t, n)[0], e)[1].children, B = (t, e) => e >= 0 && e <= x(t), N = (t, e) => e.reduce((t, e) => V(t, e), t), V = (t, e) => {
|
|
142
146
|
switch (e.type) {
|
|
143
147
|
case f:
|
|
144
148
|
{
|
|
@@ -157,7 +161,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
157
161
|
case d:
|
|
158
162
|
{
|
|
159
163
|
const {at: n, fragment: r} = e;
|
|
160
|
-
if (t >= n) return t +
|
|
164
|
+
if (t >= n) return t + x({
|
|
161
165
|
children: r
|
|
162
166
|
});
|
|
163
167
|
break;
|
|
@@ -181,7 +185,7 @@ function T(t, e, n = t.selection[0]) {
|
|
|
181
185
|
});
|
|
182
186
|
}
|
|
183
187
|
|
|
184
|
-
function
|
|
188
|
+
function W(t, e, n = t.selection[0]) {
|
|
185
189
|
t.apply({
|
|
186
190
|
type: "insert_node",
|
|
187
191
|
at: n,
|
|
@@ -191,7 +195,7 @@ function q(t, e, n = t.selection[0]) {
|
|
|
191
195
|
});
|
|
192
196
|
}
|
|
193
197
|
|
|
194
|
-
function
|
|
198
|
+
function q(e, n) {
|
|
195
199
|
const r = t(e.selection);
|
|
196
200
|
e.apply({
|
|
197
201
|
type: "delete",
|
|
@@ -203,10 +207,10 @@ function J(e, n) {
|
|
|
203
207
|
});
|
|
204
208
|
}
|
|
205
209
|
|
|
206
|
-
function
|
|
210
|
+
function J(t, e) {
|
|
207
211
|
t.apply({
|
|
208
212
|
type: "delete",
|
|
209
|
-
range: [ 0,
|
|
213
|
+
range: [ 0, x(t.doc) ]
|
|
210
214
|
}).apply({
|
|
211
215
|
type: "insert_node",
|
|
212
216
|
at: 0,
|
|
@@ -214,7 +218,7 @@ function U(t, e) {
|
|
|
214
218
|
});
|
|
215
219
|
}
|
|
216
220
|
|
|
217
|
-
function
|
|
221
|
+
function U(e, n, r, o = t(e.selection)) {
|
|
218
222
|
e.apply({
|
|
219
223
|
type: "set_attr",
|
|
220
224
|
range: o,
|
|
@@ -233,20 +237,21 @@ function G(e, n, r = t(e.selection)) {
|
|
|
233
237
|
});
|
|
234
238
|
}
|
|
235
239
|
|
|
236
|
-
function Z(t, e, n, r =
|
|
240
|
+
function Z(t, e, n, r = t.selection[0]) {
|
|
241
|
+
const {t: o} = I(t.doc, r);
|
|
237
242
|
t.apply({
|
|
238
243
|
type: "set_node_attr",
|
|
239
|
-
path:
|
|
244
|
+
path: o,
|
|
240
245
|
key: e,
|
|
241
246
|
value: n
|
|
242
247
|
});
|
|
243
248
|
}
|
|
244
249
|
|
|
245
|
-
function j(t, e, n, r, o =
|
|
246
|
-
const c =
|
|
250
|
+
function j(t, e, n, r, o = t.selection[0]) {
|
|
251
|
+
const {i: c, t: s} = I(t.doc, o);
|
|
247
252
|
t.apply({
|
|
248
253
|
type: "set_node_attr",
|
|
249
|
-
path:
|
|
254
|
+
path: s,
|
|
250
255
|
key: e,
|
|
251
256
|
value: c[e] === n ? r : n
|
|
252
257
|
});
|
|
@@ -264,8 +269,8 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
264
269
|
if (t) return Y = "\n" === t ? it() ? 3 : 6 : 1;
|
|
265
270
|
} else if ($(X)) {
|
|
266
271
|
if ("BR" === X.tagName) return Y = it() ? 3 : 5;
|
|
267
|
-
if (K.
|
|
268
|
-
if (K.
|
|
272
|
+
if (K.u(X)) return Y = 2;
|
|
273
|
+
if (K.p(X)) return Y = 4;
|
|
269
274
|
}
|
|
270
275
|
return Y = 0;
|
|
271
276
|
}, ot = () => (Y = null, X = z.nextNode()), ct = () => {
|
|
@@ -296,24 +301,24 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
296
301
|
const n = t.getRangeAt(0);
|
|
297
302
|
if (e.contains(n.commonAncestorContainer)) return n;
|
|
298
303
|
}
|
|
299
|
-
},
|
|
304
|
+
}, _t = (t, e, n, r) => {
|
|
300
305
|
const o = ht(t);
|
|
301
306
|
(n || gt(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
|
|
302
307
|
o.extend(e.startContainer, e.startOffset)));
|
|
303
|
-
},
|
|
308
|
+
}, kt = (t, e, [n, r], o, c, s) => {
|
|
304
309
|
const i = 0 === o, a = o > 0, l = a ? r : n, f = a ? n : r;
|
|
305
310
|
if (0 === l[0].length && 0 === l[1] && i && !e.hasChildNodes()) {
|
|
306
311
|
const n = t.createRange();
|
|
307
|
-
return n.setStart(e, 0), n.setEnd(e, 0),
|
|
312
|
+
return n.setStart(e, 0), n.setEnd(e, 0), _t(e, n, s);
|
|
308
313
|
}
|
|
309
|
-
const u =
|
|
314
|
+
const u = bt(e, l, c);
|
|
310
315
|
if (!u) return;
|
|
311
|
-
const d = i ? u :
|
|
316
|
+
const d = i ? u : bt(e, f, c);
|
|
312
317
|
if (!d) return;
|
|
313
|
-
const p = t.createRange(), [y, h] = u, [g,
|
|
314
|
-
$(y) ? h < 1 ? p.setStartBefore(y) : p.setStartAfter(y) : p.setStart(y, h), $(g) ?
|
|
315
|
-
|
|
316
|
-
},
|
|
318
|
+
const p = t.createRange(), [y, h] = u, [g, _] = d;
|
|
319
|
+
$(y) ? h < 1 ? p.setStartBefore(y) : p.setStartAfter(y) : p.setStart(y, h), $(g) ? _ < 1 ? p.setEndBefore(g) : p.setEndAfter(g) : p.setEnd(g, _),
|
|
320
|
+
_t(e, p, s, a);
|
|
321
|
+
}, bt = (t, [e, n], r) => r(() => {
|
|
317
322
|
let t, r = 0;
|
|
318
323
|
for (;t = at(); ) if (4 === t) {
|
|
319
324
|
if (r < e.length) for (let t = e[r++]; t > 0; t--) ct();
|
|
@@ -322,7 +327,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
322
327
|
if (n <= t) return [ et(), n ];
|
|
323
328
|
n -= t;
|
|
324
329
|
}
|
|
325
|
-
}, t),
|
|
330
|
+
}, t), xt = (t, e, r, o) => {
|
|
326
331
|
let c = !0;
|
|
327
332
|
if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
|
|
328
333
|
if ($(e) && e.hasChildNodes()) {
|
|
@@ -351,9 +356,9 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
351
356
|
return [ n, s + r ];
|
|
352
357
|
}, t, e);
|
|
353
358
|
}, mt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
|
|
354
|
-
const s =
|
|
355
|
-
return [ s, r === c && n === o ? s :
|
|
356
|
-
},
|
|
359
|
+
const s = xt(t, r, n, e);
|
|
360
|
+
return [ s, r === c && n === o ? s : xt(t, c, o, e) ];
|
|
361
|
+
}, vt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), wt = (t, e) => {
|
|
357
362
|
const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
|
|
358
363
|
let s = !1, i = !1, a = !1, l = !1;
|
|
359
364
|
return r.forEach(t => {
|
|
@@ -367,7 +372,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
|
|
|
367
372
|
break;
|
|
368
373
|
|
|
369
374
|
case "Mod":
|
|
370
|
-
|
|
375
|
+
vt ? a = !0 : i = !0;
|
|
371
376
|
break;
|
|
372
377
|
|
|
373
378
|
case "Alt":
|
|
@@ -390,13 +395,13 @@ function Mt(t) {
|
|
|
390
395
|
const n = i()[1];
|
|
391
396
|
e--;
|
|
392
397
|
const c = t.doc;
|
|
393
|
-
r = !0, t.exec(
|
|
398
|
+
r = !0, t.exec(J, i()[0].children), r = !1, o(c, t.doc) || (t.selection = n);
|
|
394
399
|
}
|
|
395
400
|
}, u = () => {
|
|
396
401
|
if (l()) {
|
|
397
402
|
e++;
|
|
398
403
|
const [n, c, s] = i(), a = t.doc;
|
|
399
|
-
r = !0, t.exec(
|
|
404
|
+
r = !0, t.exec(J, n.children), r = !1, o(a, t.doc) || (t.selection = [ N(c[0], s), N(c[1], s) ]);
|
|
400
405
|
}
|
|
401
406
|
};
|
|
402
407
|
t.hook("apply", (i, a) => {
|
|
@@ -413,7 +418,7 @@ function Mt(t) {
|
|
|
413
418
|
}
|
|
414
419
|
n = t, s[e][0] = u, s[e][2].push(i), s.splice(e + 1), e > 500 && (e--, s.shift());
|
|
415
420
|
}
|
|
416
|
-
}), t.hook("keyboard",
|
|
421
|
+
}), t.hook("keyboard", wt("Mod+Z", f)), t.hook("keyboard", wt("Shift+Mod+Z", u)),
|
|
417
422
|
t.set(Mt, {
|
|
418
423
|
undo: f,
|
|
419
424
|
redo: u,
|
|
@@ -422,15 +427,15 @@ function Mt(t) {
|
|
|
422
427
|
});
|
|
423
428
|
}
|
|
424
429
|
|
|
425
|
-
function
|
|
430
|
+
function St(t) {
|
|
426
431
|
t.get(Mt).undo();
|
|
427
432
|
}
|
|
428
433
|
|
|
429
|
-
function
|
|
434
|
+
function Dt(t) {
|
|
430
435
|
t.get(Mt).redo();
|
|
431
436
|
}
|
|
432
437
|
|
|
433
|
-
function
|
|
438
|
+
function Et(t) {
|
|
434
439
|
return t.get(Mt).undoable();
|
|
435
440
|
}
|
|
436
441
|
|
|
@@ -438,33 +443,32 @@ function Ot(t) {
|
|
|
438
443
|
return t.get(Mt).redoable();
|
|
439
444
|
}
|
|
440
445
|
|
|
441
|
-
const At = [], It = () => {}, Pt =
|
|
446
|
+
const At = [], It = () => {}, Pt = t => {
|
|
447
|
+
throw Error(t);
|
|
448
|
+
}, Ct = ({doc: n, readonly: r = !1, schema: a, isBlock: g = ft, onWarn: _ = console.warn, onError: k = Pt}) => {
|
|
442
449
|
let b = [ 0, 0 ];
|
|
443
|
-
const x =
|
|
444
|
-
if (!a) return
|
|
450
|
+
const x = t => {
|
|
451
|
+
if (!a) return _("An unsafe operation was detected. We recommend using schema option."),
|
|
445
452
|
!0;
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
448
|
-
if (!
|
|
449
|
-
e
|
|
453
|
+
const e = a["~standard"].validate(t);
|
|
454
|
+
if (e instanceof Promise) k("async validate is not supported"); else {
|
|
455
|
+
if (!e.issues) return !0;
|
|
456
|
+
_(e.issues.map(t => t.message).join("\n"));
|
|
450
457
|
}
|
|
451
458
|
return !1;
|
|
452
459
|
};
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}) && _) throw Error(_);
|
|
457
|
-
const E = new Map, S = new WeakMap, D = t => E.get(t) || At, O = new Map, I = t => {
|
|
458
|
-
const e = O.get(t);
|
|
460
|
+
a && !x(n) && k("Invalid document");
|
|
461
|
+
const v = new Map, S = new WeakMap, D = t => v.get(t) || At, E = new Map, O = t => {
|
|
462
|
+
const e = E.get(t);
|
|
459
463
|
e && !e[1] && (e[1] = !0, i(() => {
|
|
460
464
|
e[1] = !1, e[0].forEach(t => {
|
|
461
465
|
t();
|
|
462
466
|
});
|
|
463
467
|
}));
|
|
468
|
+
}, P = t => {
|
|
469
|
+
if (!r) if (Array.isArray(t)) for (const e of t) V(e); else V(t);
|
|
470
|
+
return T;
|
|
464
471
|
}, V = t => {
|
|
465
|
-
if (!r) if (Array.isArray(t)) for (const e of t) L(e); else L(t);
|
|
466
|
-
return q;
|
|
467
|
-
}, L = t => {
|
|
468
472
|
const e = n, r = D("apply"), c = r.length;
|
|
469
473
|
let s = 0;
|
|
470
474
|
const i = () => {
|
|
@@ -487,13 +491,13 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
487
491
|
{
|
|
488
492
|
const {at: r, text: o} = n;
|
|
489
493
|
if (B(t, r) && o) {
|
|
490
|
-
const
|
|
491
|
-
let
|
|
492
|
-
if (
|
|
493
|
-
const t =
|
|
494
|
-
h(t) && (
|
|
494
|
+
const {i: c, o: s} = I(t, r), i = A(c, s - 1);
|
|
495
|
+
let a;
|
|
496
|
+
if (i) {
|
|
497
|
+
const t = i.i;
|
|
498
|
+
h(t) && (a = t);
|
|
495
499
|
}
|
|
496
|
-
t = H(t, r, r, l(o,
|
|
500
|
+
t = H(t, r, r, l(o, a, c)), e = F(e, n);
|
|
497
501
|
}
|
|
498
502
|
break;
|
|
499
503
|
}
|
|
@@ -520,7 +524,10 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
520
524
|
|
|
521
525
|
case y:
|
|
522
526
|
{
|
|
523
|
-
const {path: e, key: r, value: o} = n, c =
|
|
527
|
+
const {path: e, key: r, value: o} = n, c = ((t, e) => {
|
|
528
|
+
for (let n = 0; n < e.length; n++) t = t.children[e[n]];
|
|
529
|
+
return t;
|
|
530
|
+
})(t, e);
|
|
524
531
|
c && (t = C(t, e, {
|
|
525
532
|
...c,
|
|
526
533
|
[r]: o
|
|
@@ -530,19 +537,19 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
530
537
|
}
|
|
531
538
|
return [ t, e ];
|
|
532
539
|
})(n, b, t);
|
|
533
|
-
(({type: t}) => t === d || t === p || t === y)(t) && !x(e
|
|
540
|
+
(({type: t}) => t === d || t === p || t === y)(t) && !x(e) || (n = e, b = r);
|
|
534
541
|
} catch (t) {
|
|
535
|
-
|
|
542
|
+
_("rollback operation: " + t);
|
|
536
543
|
}
|
|
537
544
|
}
|
|
538
545
|
}, a = e => {
|
|
539
546
|
e && (t = e), s++, i();
|
|
540
547
|
};
|
|
541
|
-
i(), o(e, n) ||
|
|
542
|
-
},
|
|
548
|
+
i(), o(e, n) || O("change");
|
|
549
|
+
}, L = t => {
|
|
543
550
|
!((t, [e, n]) => B(t, e) && B(t, n))(n, t) || b[0] === t[0] && b[1] === t[1] || (b = t,
|
|
544
|
-
|
|
545
|
-
},
|
|
551
|
+
O("selectionchange"));
|
|
552
|
+
}, T = {
|
|
546
553
|
get doc() {
|
|
547
554
|
return n;
|
|
548
555
|
},
|
|
@@ -550,50 +557,47 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
550
557
|
return b;
|
|
551
558
|
},
|
|
552
559
|
set selection(t) {
|
|
553
|
-
|
|
560
|
+
L(t);
|
|
554
561
|
},
|
|
555
562
|
get readonly() {
|
|
556
563
|
return r;
|
|
557
564
|
},
|
|
558
565
|
set readonly(t) {
|
|
559
|
-
r = t,
|
|
566
|
+
r = t, O("readonly");
|
|
560
567
|
},
|
|
561
|
-
apply:
|
|
568
|
+
apply: P,
|
|
562
569
|
on: (t, e) => {
|
|
563
|
-
let n =
|
|
564
|
-
n ||
|
|
570
|
+
let n = E.get(t);
|
|
571
|
+
n || E.set(t, n = [ new Set, !1 ]);
|
|
565
572
|
const r = n[0];
|
|
566
573
|
return r.add(e), () => {
|
|
567
574
|
r.delete(e);
|
|
568
575
|
};
|
|
569
576
|
},
|
|
570
577
|
hook: (t, e) => {
|
|
571
|
-
let n =
|
|
572
|
-
return n ||
|
|
578
|
+
let n = v.get(t);
|
|
579
|
+
return n || v.set(t, n = []), n.push(e), () => {
|
|
573
580
|
const t = n.indexOf(e);
|
|
574
581
|
-1 !== t && n.splice(t, 1);
|
|
575
582
|
};
|
|
576
583
|
},
|
|
577
584
|
exec: (t, ...e) => {
|
|
578
|
-
const n = t(
|
|
579
|
-
return void 0 === n ?
|
|
580
|
-
},
|
|
581
|
-
get: t => {
|
|
582
|
-
if (!S.has(t)) throw Error("No value found for key");
|
|
583
|
-
return S.get(t);
|
|
585
|
+
const n = t(T, ...e);
|
|
586
|
+
return void 0 === n ? T : n;
|
|
584
587
|
},
|
|
585
|
-
|
|
588
|
+
get: t => (S.has(t) || k("No value found for key"), S.get(t)),
|
|
589
|
+
set: (t, e) => (S.set(t, e), T),
|
|
586
590
|
input: o => {
|
|
587
|
-
if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return
|
|
591
|
+
if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return _("beforeinput event is not supported."),
|
|
588
592
|
It;
|
|
589
593
|
const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
|
|
590
594
|
o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
|
|
591
|
-
let d = !1, p = null, y = !1, h = !1,
|
|
592
|
-
const
|
|
595
|
+
let d = !1, p = null, y = !1, h = !1, k = !1;
|
|
596
|
+
const x = yt(o), v = (t => {
|
|
593
597
|
const e = (n, r, o) => {
|
|
594
598
|
const c = K, s = Q, i = z, a = X, l = Y;
|
|
595
599
|
try {
|
|
596
|
-
return z || (K = t, Q = e, z = K.
|
|
600
|
+
return z || (K = t, Q = e, z = K.h.createTreeWalker(r, 5)), o && (z.currentNode = X = o),
|
|
597
601
|
n();
|
|
598
602
|
} finally {
|
|
599
603
|
K = c, Q = s, z = i, X = a, Y = l, z && a && (z.currentNode = a);
|
|
@@ -601,25 +605,25 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
601
605
|
};
|
|
602
606
|
return e;
|
|
603
607
|
})({
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}),
|
|
608
|
+
h: x,
|
|
609
|
+
p: g,
|
|
610
|
+
u: dt
|
|
611
|
+
}), S = () => {
|
|
608
612
|
o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
|
|
609
613
|
};
|
|
610
|
-
|
|
611
|
-
const
|
|
614
|
+
S();
|
|
615
|
+
const E = T.on("change", () => {
|
|
612
616
|
h || requestAnimationFrame(() => {
|
|
613
617
|
h || o.focus({
|
|
614
618
|
preventScroll: !0
|
|
615
619
|
});
|
|
616
620
|
});
|
|
617
|
-
}), O =
|
|
621
|
+
}), O = T.on("readonly", S), A = t => {
|
|
618
622
|
for (const e of D("paste")) {
|
|
619
|
-
const n = e(t,
|
|
623
|
+
const n = e(t, v);
|
|
620
624
|
if (n) return n;
|
|
621
625
|
}
|
|
622
|
-
|
|
626
|
+
_("failed to serialize pasted data");
|
|
623
627
|
}, I = ((t, e) => {
|
|
624
628
|
let n = !1;
|
|
625
629
|
const r = [], o = t => {
|
|
@@ -635,7 +639,7 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
635
639
|
childList: !0,
|
|
636
640
|
subtree: !0
|
|
637
641
|
}), {
|
|
638
|
-
|
|
642
|
+
_: t => {
|
|
639
643
|
let e;
|
|
640
644
|
for (;e = t.pop(); ) if ("childList" === e.type) {
|
|
641
645
|
const {target: t, removedNodes: n, addedNodes: r, nextSibling: o} = e;
|
|
@@ -647,37 +651,37 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
647
651
|
k: t => {
|
|
648
652
|
!n && t && s(), n = t;
|
|
649
653
|
},
|
|
650
|
-
|
|
651
|
-
|
|
654
|
+
m: i,
|
|
655
|
+
v: () => {
|
|
652
656
|
r.splice(0), c.disconnect();
|
|
653
657
|
}
|
|
654
658
|
};
|
|
655
659
|
})(o, () => {
|
|
656
|
-
|
|
657
|
-
}),
|
|
658
|
-
|
|
660
|
+
kt(x, o, M(n, b), b[0] - b[1], v);
|
|
661
|
+
}), C = () => {
|
|
662
|
+
L(w(n, ((t, e) => {
|
|
659
663
|
const n = ht(t), r = gt(n, t);
|
|
660
664
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
661
665
|
const o = mt(t, e, r), c = pt(n.anchorNode, n.focusNode);
|
|
662
666
|
return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
|
|
663
|
-
})(o,
|
|
664
|
-
},
|
|
665
|
-
const t = I.
|
|
666
|
-
I.k(!1), t.length && (I.
|
|
667
|
-
|
|
668
|
-
},
|
|
667
|
+
})(o, v)));
|
|
668
|
+
}, H = () => {
|
|
669
|
+
const t = I.m();
|
|
670
|
+
I.k(!1), t.length && (I._(t), x.removeEventListener("selectionchange", U), kt(x, o, M(n, b), b[0] - b[1], v, !0),
|
|
671
|
+
x.addEventListener("selectionchange", U)), p && (L(p[1]), P(p[0]), p = null), y = !1;
|
|
672
|
+
}, R = t => {
|
|
669
673
|
if (!y) for (const e of D("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
|
|
670
674
|
}, B = () => {
|
|
671
|
-
y ||
|
|
672
|
-
},
|
|
675
|
+
y || H();
|
|
676
|
+
}, V = t => {
|
|
673
677
|
t.preventDefault();
|
|
674
678
|
const r = t.inputType;
|
|
675
679
|
if (r.startsWith("format")) return;
|
|
676
680
|
if ("historyUndo" === r || "historyRedo" === r) return;
|
|
677
|
-
y ? I.k(!0) :
|
|
681
|
+
y ? I.k(!0) : C();
|
|
678
682
|
const c = t.getTargetRanges()[0];
|
|
679
683
|
if (c) {
|
|
680
|
-
const s =
|
|
684
|
+
const s = w(n, mt(o, v, c));
|
|
681
685
|
let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
|
|
682
686
|
if (null == a) {
|
|
683
687
|
const e = t.dataTransfer;
|
|
@@ -692,30 +696,27 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
692
696
|
text: a
|
|
693
697
|
});
|
|
694
698
|
}
|
|
695
|
-
y ||
|
|
696
|
-
},
|
|
697
|
-
y ||
|
|
698
|
-
}, J = () => {
|
|
699
|
-
C();
|
|
700
|
-
}, U = () => {
|
|
701
|
-
h = !0, P();
|
|
699
|
+
y || H();
|
|
700
|
+
}, F = () => {
|
|
701
|
+
y || C(), y = !0;
|
|
702
702
|
}, W = () => {
|
|
703
|
+
H();
|
|
704
|
+
}, q = () => {
|
|
705
|
+
h = !0, C();
|
|
706
|
+
}, J = () => {
|
|
703
707
|
h = !1;
|
|
704
|
-
},
|
|
705
|
-
!h || y ||
|
|
706
|
-
},
|
|
707
|
-
if (
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
t.preventDefault(), Z(t.clipboardData);
|
|
713
|
-
}, $ = e => {
|
|
714
|
-
e.preventDefault(), r || (Z(e.clipboardData), V({
|
|
708
|
+
}, U = () => {
|
|
709
|
+
!h || y || k || C();
|
|
710
|
+
}, G = t => {
|
|
711
|
+
if (C(), !e(b)) for (const e of D("copy")) e(t);
|
|
712
|
+
}, Z = t => {
|
|
713
|
+
t.preventDefault(), G(t.clipboardData);
|
|
714
|
+
}, j = e => {
|
|
715
|
+
e.preventDefault(), r || (G(e.clipboardData), P({
|
|
715
716
|
type: "delete",
|
|
716
717
|
range: t(b)
|
|
717
718
|
}));
|
|
718
|
-
},
|
|
719
|
+
}, $ = e => {
|
|
719
720
|
e.preventDefault();
|
|
720
721
|
const n = A(e.clipboardData);
|
|
721
722
|
if (n) {
|
|
@@ -731,23 +732,23 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
731
732
|
type: "insert_node",
|
|
732
733
|
at: r,
|
|
733
734
|
fragment: n
|
|
734
|
-
}),
|
|
735
|
+
}), P(o);
|
|
735
736
|
}
|
|
736
|
-
},
|
|
737
|
+
}, tt = e => {
|
|
737
738
|
e.preventDefault();
|
|
738
739
|
const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}, o) => {
|
|
739
740
|
if (t.caretPositionFromPoint) {
|
|
740
741
|
const c = t.caretPositionFromPoint(n, r);
|
|
741
|
-
if (c) return
|
|
742
|
+
if (c) return xt(e, c.offsetNode, c.offset, o);
|
|
742
743
|
} else if (t.caretRangeFromPoint) {
|
|
743
744
|
const c = t.caretRangeFromPoint(n, r);
|
|
744
|
-
if (c) return
|
|
745
|
+
if (c) return xt(e, c.startContainer, c.startOffset, o);
|
|
745
746
|
}
|
|
746
|
-
})(
|
|
747
|
+
})(x, o, e, v);
|
|
747
748
|
if (r && s) {
|
|
748
749
|
let e;
|
|
749
750
|
const o = [];
|
|
750
|
-
|
|
751
|
+
k && o.push({
|
|
751
752
|
type: "delete",
|
|
752
753
|
range: t(b)
|
|
753
754
|
});
|
|
@@ -764,37 +765,37 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
764
765
|
fragment: i
|
|
765
766
|
}), e = [ r, N(t, o) ];
|
|
766
767
|
}
|
|
767
|
-
|
|
768
|
+
P(o), e && L(e);
|
|
768
769
|
}
|
|
769
|
-
},
|
|
770
|
-
|
|
771
|
-
},
|
|
772
|
-
|
|
770
|
+
}, et = t => {
|
|
771
|
+
k = !0, G(t.dataTransfer);
|
|
772
|
+
}, nt = () => {
|
|
773
|
+
k = !1;
|
|
773
774
|
};
|
|
774
|
-
|
|
775
|
-
o.addEventListener("beforeinput",
|
|
776
|
-
o.addEventListener("compositionend",
|
|
777
|
-
o.addEventListener("copy",
|
|
778
|
-
o.addEventListener("drop",
|
|
779
|
-
const
|
|
775
|
+
x.addEventListener("selectionchange", U), o.addEventListener("keydown", R), o.addEventListener("input", B),
|
|
776
|
+
o.addEventListener("beforeinput", V), o.addEventListener("compositionstart", F),
|
|
777
|
+
o.addEventListener("compositionend", W), o.addEventListener("focus", q), o.addEventListener("blur", J),
|
|
778
|
+
o.addEventListener("copy", Z), o.addEventListener("cut", j), o.addEventListener("paste", $),
|
|
779
|
+
o.addEventListener("drop", tt), o.addEventListener("dragstart", et), o.addEventListener("dragend", nt);
|
|
780
|
+
const rt = [];
|
|
780
781
|
return D("mount").forEach(t => {
|
|
781
782
|
const e = t(o);
|
|
782
|
-
e &&
|
|
783
|
+
e && rt.push(e);
|
|
783
784
|
}), () => {
|
|
784
|
-
d || (d = !0,
|
|
785
|
-
o.ariaReadOnly = f, o.style.whiteSpace = u, I.
|
|
786
|
-
o.removeEventListener("keydown",
|
|
787
|
-
o.removeEventListener("compositionstart",
|
|
788
|
-
o.removeEventListener("focus",
|
|
789
|
-
o.removeEventListener("cut",
|
|
790
|
-
o.removeEventListener("dragstart",
|
|
785
|
+
d || (d = !0, E(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
|
|
786
|
+
o.ariaReadOnly = f, o.style.whiteSpace = u, I.v(), x.removeEventListener("selectionchange", U),
|
|
787
|
+
o.removeEventListener("keydown", R), o.removeEventListener("input", B), o.removeEventListener("beforeinput", V),
|
|
788
|
+
o.removeEventListener("compositionstart", F), o.removeEventListener("compositionend", W),
|
|
789
|
+
o.removeEventListener("focus", q), o.removeEventListener("blur", J), o.removeEventListener("copy", Z),
|
|
790
|
+
o.removeEventListener("cut", j), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
|
|
791
|
+
o.removeEventListener("dragstart", et), o.removeEventListener("dragend", nt), rt.forEach(t => {
|
|
791
792
|
t();
|
|
792
793
|
}));
|
|
793
794
|
};
|
|
794
795
|
}
|
|
795
796
|
};
|
|
796
|
-
return
|
|
797
|
-
},
|
|
797
|
+
return T.exec(Mt), T;
|
|
798
|
+
}, Ht = (t, e) => {
|
|
798
799
|
t.hook("paste", t => {
|
|
799
800
|
for (const n of t.items) if ("file" === n.kind) {
|
|
800
801
|
const t = e[n.type];
|
|
@@ -809,19 +810,23 @@ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
809
810
|
});
|
|
810
811
|
};
|
|
811
812
|
|
|
812
|
-
function
|
|
813
|
-
const
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
children: e
|
|
817
|
-
},
|
|
818
|
-
}),
|
|
813
|
+
function Rt(e, n) {
|
|
814
|
+
const r = n && n.serializer;
|
|
815
|
+
e.hook("copy", n => {
|
|
816
|
+
n.setData("text/plain", a({
|
|
817
|
+
children: R(e.doc, ...t(e.selection))
|
|
818
|
+
}, r));
|
|
819
|
+
}), e.hook("paste", t => t.getData("text/plain"));
|
|
819
820
|
}
|
|
820
821
|
|
|
821
|
-
function
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
822
|
+
function Bt(t, e) {
|
|
823
|
+
let n = null;
|
|
824
|
+
t.hook("mount", t => (n = t, () => {
|
|
825
|
+
n = null;
|
|
826
|
+
})), t.hook("copy", t => {
|
|
827
|
+
if (!n) return;
|
|
828
|
+
const e = document.createElement("div");
|
|
829
|
+
e.appendChild(gt(ht(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
|
|
825
830
|
}), t.hook("paste", ((t, e = []) => (n, r) => {
|
|
826
831
|
const o = n.getData("text/html");
|
|
827
832
|
if (o) {
|
|
@@ -856,21 +861,21 @@ function Rt(t, e) {
|
|
|
856
861
|
})(e.serializeText, e.serializers));
|
|
857
862
|
}
|
|
858
863
|
|
|
859
|
-
const
|
|
864
|
+
const Nt = "application/x-editate-editor";
|
|
860
865
|
|
|
861
|
-
function
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
}),
|
|
866
|
+
function Vt(e) {
|
|
867
|
+
e.hook("copy", n => {
|
|
868
|
+
n.setData(Nt, JSON.stringify(R(e.doc, ...t(e.selection))));
|
|
869
|
+
}), e.hook("paste", t => {
|
|
865
870
|
try {
|
|
866
|
-
return JSON.parse(t.getData(
|
|
871
|
+
return JSON.parse(t.getData(Nt));
|
|
867
872
|
} catch (t) {
|
|
868
873
|
return null;
|
|
869
874
|
}
|
|
870
875
|
});
|
|
871
876
|
}
|
|
872
877
|
|
|
873
|
-
function
|
|
878
|
+
function Ft(t) {
|
|
874
879
|
t.hook("apply", t => {
|
|
875
880
|
console.log("apply", t);
|
|
876
881
|
}), t.on("change", () => {
|
|
@@ -880,16 +885,16 @@ function Vt(t) {
|
|
|
880
885
|
});
|
|
881
886
|
}
|
|
882
887
|
|
|
883
|
-
function
|
|
888
|
+
function Lt(t, e) {
|
|
884
889
|
r(e).forEach(n => {
|
|
885
890
|
const r = e[n];
|
|
886
|
-
t.hook("keyboard",
|
|
891
|
+
t.hook("keyboard", wt(n, () => {
|
|
887
892
|
r();
|
|
888
893
|
}));
|
|
889
894
|
});
|
|
890
895
|
}
|
|
891
896
|
|
|
892
|
-
function
|
|
897
|
+
function Tt(t) {
|
|
893
898
|
t.hook("mount", t => {
|
|
894
899
|
t.ariaMultiLine = null;
|
|
895
900
|
}), t.hook("apply", (t, e) => {
|
|
@@ -903,17 +908,17 @@ function Lt(t) {
|
|
|
903
908
|
});
|
|
904
909
|
}
|
|
905
910
|
|
|
906
|
-
const
|
|
907
|
-
const o =
|
|
911
|
+
const Wt = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
912
|
+
const o = Ct({
|
|
908
913
|
...r,
|
|
909
914
|
doc: {
|
|
910
915
|
children: l(t)
|
|
911
916
|
}
|
|
912
|
-
}).exec(
|
|
917
|
+
}).exec(Rt);
|
|
913
918
|
return o.on("change", () => {
|
|
914
919
|
n(a(o.doc));
|
|
915
|
-
}), e && o.exec(
|
|
920
|
+
}), e && o.exec(Tt), o;
|
|
916
921
|
};
|
|
917
922
|
|
|
918
|
-
export { L as Delete,
|
|
923
|
+
export { L as Delete, U as Format, W as InsertNode, T as InsertText, Dt as Redo, Ot as Redoable, J as ReplaceDoc, q as ReplaceText, Z as SetBlockAttr, j as ToggleBlockAttr, G as ToggleFormat, St as Undo, Et as Undoable, Ct as createEditor, Wt as createPlainEditor, Ft as debugPlugin, Ht as fileTransferPlugin, Bt as htmlTransferPlugin, Vt as internalTranferPlugin, Lt as keymapPlugin, Rt as plainTransferPlugin, Tt as singlelinePlugin };
|
|
919
924
|
//# sourceMappingURL=index.js.map
|