editate 0.6.0 → 0.6.1
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/editor.d.ts +9 -0
- package/lib/index.cjs +138 -119
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +172 -145
- package/lib/index.js.map +1 -1
- package/lib/plugins/history.d.ts +17 -1
- package/lib/plugins/index.d.ts +1 -0
- package/package.json +1 -1
package/lib/editor.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ type EditorEventMap = {
|
|
|
42
42
|
* Return `true` if you want to stop propagation.
|
|
43
43
|
*/
|
|
44
44
|
export type KeyboardHook = (keyboard: KeyboardEvent) => boolean | void;
|
|
45
|
+
export type EditorContext<_> = {};
|
|
45
46
|
/**
|
|
46
47
|
* Functions to handle copy events
|
|
47
48
|
*/
|
|
@@ -90,6 +91,14 @@ export interface Editor<T extends DocNode = DocNode> {
|
|
|
90
91
|
* @returns cleanup function
|
|
91
92
|
*/
|
|
92
93
|
hook<K extends keyof EditorHookMap>(key: K, callback: EditorHookMap[K]): () => void;
|
|
94
|
+
/**
|
|
95
|
+
* Get a value from the context.
|
|
96
|
+
*/
|
|
97
|
+
get<V>(key: EditorContext<V>): V;
|
|
98
|
+
/**
|
|
99
|
+
* Set a value for the context.
|
|
100
|
+
*/
|
|
101
|
+
set<V>(key: EditorContext<V>, value: V): this;
|
|
93
102
|
/**
|
|
94
103
|
* A function to make DOM editable.
|
|
95
104
|
* @returns A function to stop subscribing DOM changes and restores previous DOM state.
|
package/lib/index.cjs
CHANGED
|
@@ -12,22 +12,22 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
12
12
|
})), f = "delete", u = "insert_text", d = "insert_node", p = "set_attr", y = "set_node_attr", h = t => "text" in t, x = t => "children" in t, g = (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, b = ({children: t}, e = 0, n = t.length) => {
|
|
16
16
|
let r = 0, o = 0;
|
|
17
17
|
for (let s = e; s < n; s++) {
|
|
18
18
|
const e = t[s];
|
|
19
|
-
r +=
|
|
19
|
+
r += _(e), 0 !== o && x(e) && r++, o++;
|
|
20
20
|
}
|
|
21
21
|
return r;
|
|
22
|
-
},
|
|
22
|
+
}, _ = t => {
|
|
23
23
|
if (x(t)) {
|
|
24
24
|
let e = k.get(t);
|
|
25
|
-
return null == e && k.set(t, e =
|
|
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
32
|
}, w = (t, e) => {
|
|
33
33
|
const n = [];
|
|
@@ -39,7 +39,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
39
39
|
e = r.i, n.push(o), t = s;
|
|
40
40
|
}
|
|
41
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) ],
|
|
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) => {
|
|
43
43
|
let r = e + 1;
|
|
44
44
|
for (;r <= n; ) {
|
|
45
45
|
const e = t[r - 1], o = t[r];
|
|
@@ -52,24 +52,24 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
52
52
|
const e = t[r];
|
|
53
53
|
h(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
|
|
54
54
|
}
|
|
55
|
-
},
|
|
55
|
+
}, S = (t, e = 0, n = t.length - 1) => {
|
|
56
56
|
let r = e + 1;
|
|
57
57
|
for (;r <= n; ) {
|
|
58
58
|
const e = t[r - 1], o = t[r];
|
|
59
59
|
t[r - 1] = O(e, o), t.splice(r, 1), n--;
|
|
60
60
|
}
|
|
61
|
-
},
|
|
61
|
+
}, D = (t, e, n) => {
|
|
62
62
|
if (e.length) {
|
|
63
63
|
const r = t.length;
|
|
64
64
|
t.push(...e), r && n(t, r - 1, r);
|
|
65
65
|
}
|
|
66
66
|
}, O = (...t) => ({
|
|
67
67
|
...t[0],
|
|
68
|
-
children: t.reduce((t, e) => (
|
|
68
|
+
children: t.reduce((t, e) => (D(t, e.children, E), t), [])
|
|
69
69
|
}), A = ({children: t}, e) => {
|
|
70
70
|
for (let n = 0; n < t.length; n++) {
|
|
71
71
|
const r = t[n];
|
|
72
|
-
let o =
|
|
72
|
+
let o = _(r);
|
|
73
73
|
if (x(r) && o++, o > e) return {
|
|
74
74
|
o: r,
|
|
75
75
|
t: n,
|
|
@@ -134,11 +134,11 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
134
134
|
return n;
|
|
135
135
|
}, H = (t, e, n, r) => {
|
|
136
136
|
const [o, s] = I(t, e), c = e < n ? I(t, n)[1] : s, i = o.children.slice();
|
|
137
|
-
return
|
|
137
|
+
return D(i, r, S), D(i, c.children, S), {
|
|
138
138
|
...t,
|
|
139
139
|
children: i
|
|
140
140
|
};
|
|
141
|
-
}, R = (t, e, n) => e >= n ? [] : I(I(t, n)[0], e)[1].children, B = (t, e) => e >= 0 && e <=
|
|
141
|
+
}, R = (t, e, n) => e >= n ? [] : I(I(t, n)[0], e)[1].children, B = (t, e) => e >= 0 && e <= _(t), N = (t, e) => e.reduce((t, e) => V(t, e), t), V = (t, e) => {
|
|
142
142
|
switch (e.type) {
|
|
143
143
|
case f:
|
|
144
144
|
{
|
|
@@ -157,19 +157,19 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
157
157
|
case d:
|
|
158
158
|
{
|
|
159
159
|
const {at: n, fragment: r} = e;
|
|
160
|
-
if (t >= n) return t +
|
|
160
|
+
if (t >= n) return t + _({
|
|
161
161
|
children: r
|
|
162
162
|
});
|
|
163
163
|
break;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
return t;
|
|
167
|
-
},
|
|
167
|
+
}, F = ([t, e], n) => [ V(t, n), V(e, n) ];
|
|
168
168
|
|
|
169
|
-
function
|
|
169
|
+
function L(t, e) {
|
|
170
170
|
t.apply({
|
|
171
171
|
type: "delete",
|
|
172
|
-
range: [ 0,
|
|
172
|
+
range: [ 0, _(t.doc) ]
|
|
173
173
|
}).apply({
|
|
174
174
|
type: "insert_node",
|
|
175
175
|
at: 0,
|
|
@@ -177,9 +177,9 @@ function N(t, e) {
|
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
let T = null, q = null, J = null, U = null,
|
|
180
|
+
let T = null, q = null, J = null, U = null, W = null;
|
|
181
181
|
|
|
182
|
-
const
|
|
182
|
+
const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => q, z = () => {
|
|
183
183
|
const t = X();
|
|
184
184
|
return 1 === t ? q.data.length : 2 === t ? 1 : 0;
|
|
185
185
|
}, X = () => {
|
|
@@ -187,7 +187,7 @@ const W = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => q, z = ()
|
|
|
187
187
|
if (q) if ((t => 3 === t.nodeType)(q)) {
|
|
188
188
|
const t = q.data;
|
|
189
189
|
if (t) return J = "\n" === t ? $() ? 3 : 6 : 1;
|
|
190
|
-
} else if (
|
|
190
|
+
} else if (G(q)) {
|
|
191
191
|
if ("BR" === q.tagName) return J = $() ? 3 : 5;
|
|
192
192
|
if (U.l(q)) return J = 2;
|
|
193
193
|
if (U.u(q)) return J = 4;
|
|
@@ -199,7 +199,7 @@ const W = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => q, z = ()
|
|
|
199
199
|
for (;(J = null) || (q = T.parentNode()); ) if (4 === X()) return;
|
|
200
200
|
}, $ = () => {
|
|
201
201
|
const t = q.parentNode;
|
|
202
|
-
return
|
|
202
|
+
return W(() => {
|
|
203
203
|
for (;Y(); ) {
|
|
204
204
|
if (X()) return !0;
|
|
205
205
|
if (!t.contains(q)) break;
|
|
@@ -236,7 +236,7 @@ const W = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => q, z = ()
|
|
|
236
236
|
const d = i ? u : ut(e, f, s);
|
|
237
237
|
if (!d) return;
|
|
238
238
|
const p = t.createRange(), [y, h] = u, [x, g] = d;
|
|
239
|
-
|
|
239
|
+
G(y) ? h < 1 ? p.setStartBefore(y) : p.setStartAfter(y) : p.setStart(y, h), G(x) ? g < 1 ? p.setEndBefore(x) : p.setEndAfter(x) : p.setEnd(x, g),
|
|
240
240
|
lt(e, p, c, a);
|
|
241
241
|
}, ut = (t, [e, n], r) => r(() => {
|
|
242
242
|
let t, r = 0;
|
|
@@ -250,7 +250,7 @@ const W = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => q, z = ()
|
|
|
250
250
|
}, t), dt = (t, e, r, o) => {
|
|
251
251
|
let s = !0;
|
|
252
252
|
if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
|
|
253
|
-
if (
|
|
253
|
+
if (G(e) && e.hasChildNodes()) {
|
|
254
254
|
const t = n(r, e.childNodes.length - 1);
|
|
255
255
|
e = e.childNodes[t], s = t === r, r = 0;
|
|
256
256
|
}
|
|
@@ -310,7 +310,20 @@ const W = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => q, z = ()
|
|
|
310
310
|
|
|
311
311
|
function xt(t) {
|
|
312
312
|
let e = 0, n = 0, r = !1;
|
|
313
|
-
const s = Date.now, c = [ [ t.doc, t.selection, [] ] ], i = () => c[e]
|
|
313
|
+
const s = Date.now, c = [ [ t.doc, t.selection, [] ] ], i = () => c[e], a = () => e > 0, l = () => e < c.length - 1, f = () => {
|
|
314
|
+
if (a()) {
|
|
315
|
+
const n = i()[1];
|
|
316
|
+
e--;
|
|
317
|
+
const s = t.doc;
|
|
318
|
+
r = !0, t.exec(L, i()[0].children), r = !1, o(s, t.doc) || (t.selection = n);
|
|
319
|
+
}
|
|
320
|
+
}, u = () => {
|
|
321
|
+
if (l()) {
|
|
322
|
+
e++;
|
|
323
|
+
const [n, s, c] = i(), a = t.doc;
|
|
324
|
+
r = !0, t.exec(L, n.children), r = !1, o(a, t.doc) || (t.selection = [ N(s[0], c), N(s[1], c) ]);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
314
327
|
t.hook("apply", (i, a) => {
|
|
315
328
|
if (r) return;
|
|
316
329
|
const l = t.doc, f = t.selection;
|
|
@@ -325,25 +338,18 @@ function xt(t) {
|
|
|
325
338
|
}
|
|
326
339
|
n = t, c[e][0] = u, c[e][2].push(i), c.splice(e + 1), e > 500 && (e--, c.shift());
|
|
327
340
|
}
|
|
328
|
-
}), t.hook("keyboard", ht("Mod+Z", ()
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
})), t.hook("keyboard", ht("Shift+Mod+Z", () => {
|
|
336
|
-
if (e < c.length - 1) {
|
|
337
|
-
e++;
|
|
338
|
-
const [n, s, c] = i(), a = t.doc;
|
|
339
|
-
r = !0, t.exec(N, n.children), r = !1, o(a, t.doc) || (t.selection = [ V(s[0], c), V(s[1], c) ]);
|
|
340
|
-
}
|
|
341
|
-
}));
|
|
341
|
+
}), t.hook("keyboard", ht("Mod+Z", f)), t.hook("keyboard", ht("Shift+Mod+Z", u)),
|
|
342
|
+
t.set(xt, {
|
|
343
|
+
undo: f,
|
|
344
|
+
redo: u,
|
|
345
|
+
undoable: a,
|
|
346
|
+
redoable: l
|
|
347
|
+
});
|
|
342
348
|
}
|
|
343
349
|
|
|
344
|
-
const gt = [], kt = () => {},
|
|
350
|
+
const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBlock: x = nt, onError: g = console.error}) => {
|
|
345
351
|
let k = [ 0, 0 ];
|
|
346
|
-
const
|
|
352
|
+
const b = (t, e) => {
|
|
347
353
|
if (!a) return e("An unsafe operation was detected. We recommend using schema option."),
|
|
348
354
|
!0;
|
|
349
355
|
const n = a["~standard"].validate(t);
|
|
@@ -353,21 +359,21 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
353
359
|
}
|
|
354
360
|
return !1;
|
|
355
361
|
};
|
|
356
|
-
let
|
|
357
|
-
if (!
|
|
358
|
-
|
|
359
|
-
}) &&
|
|
360
|
-
const
|
|
361
|
-
const e =
|
|
362
|
+
let _;
|
|
363
|
+
if (!b(n, t => {
|
|
364
|
+
_ = t;
|
|
365
|
+
}) && _) throw Error(_);
|
|
366
|
+
const E = new Map, S = new WeakMap, D = t => E.get(t) || gt, O = new Map, I = t => {
|
|
367
|
+
const e = O.get(t);
|
|
362
368
|
e && !e[1] && (e[1] = !0, i(() => {
|
|
363
369
|
e[1] = !1, e[0].forEach(t => {
|
|
364
370
|
t();
|
|
365
371
|
});
|
|
366
372
|
}));
|
|
367
|
-
},
|
|
368
|
-
if (!r) if (Array.isArray(t)) for (const e of t)
|
|
369
|
-
return
|
|
370
|
-
},
|
|
373
|
+
}, V = t => {
|
|
374
|
+
if (!r) if (Array.isArray(t)) for (const e of t) L(e); else L(t);
|
|
375
|
+
return Z;
|
|
376
|
+
}, L = t => {
|
|
371
377
|
const e = n, r = D("apply"), s = r.length;
|
|
372
378
|
let c = 0;
|
|
373
379
|
const i = () => {
|
|
@@ -382,7 +388,7 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
382
388
|
case f:
|
|
383
389
|
{
|
|
384
390
|
const [r, o] = n.range;
|
|
385
|
-
B(t, r) && B(t, o) && r < o && (t = H(t, r, o, []), e =
|
|
391
|
+
B(t, r) && B(t, o) && r < o && (t = H(t, r, o, []), e = F(e, n));
|
|
386
392
|
break;
|
|
387
393
|
}
|
|
388
394
|
|
|
@@ -396,7 +402,7 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
396
402
|
const t = a.o;
|
|
397
403
|
h(t) && (f = t);
|
|
398
404
|
}
|
|
399
|
-
t = H(t, r, r, l(o, f, i)), e =
|
|
405
|
+
t = H(t, r, r, l(o, f, i)), e = F(e, n);
|
|
400
406
|
}
|
|
401
407
|
break;
|
|
402
408
|
}
|
|
@@ -404,7 +410,7 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
404
410
|
case d:
|
|
405
411
|
{
|
|
406
412
|
const {at: r, fragment: o} = n;
|
|
407
|
-
B(t, r) && o.length && (t = H(t, r, r, o), e =
|
|
413
|
+
B(t, r) && o.length && (t = H(t, r, r, o), e = F(e, n));
|
|
408
414
|
break;
|
|
409
415
|
}
|
|
410
416
|
|
|
@@ -433,7 +439,7 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
433
439
|
}
|
|
434
440
|
return [ t, e ];
|
|
435
441
|
})(n, k, t);
|
|
436
|
-
(({type: t}) => t === d || t === p || t === y)(t) && !
|
|
442
|
+
(({type: t}) => t === d || t === p || t === y)(t) && !b(e, g) || (n = e, k = r);
|
|
437
443
|
} catch (t) {
|
|
438
444
|
g("rollback operation: " + t);
|
|
439
445
|
}
|
|
@@ -441,11 +447,11 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
441
447
|
}, a = e => {
|
|
442
448
|
e && (t = e), c++, i();
|
|
443
449
|
};
|
|
444
|
-
i(), o(e, n) ||
|
|
445
|
-
},
|
|
450
|
+
i(), o(e, n) || I("change");
|
|
451
|
+
}, G = t => {
|
|
446
452
|
!((t, [e, n]) => B(t, e) && B(t, n))(n, t) || k[0] === t[0] && k[1] === t[1] || (k = t,
|
|
447
|
-
|
|
448
|
-
},
|
|
453
|
+
I("selectionchange"));
|
|
454
|
+
}, Z = {
|
|
449
455
|
get doc() {
|
|
450
456
|
return n;
|
|
451
457
|
},
|
|
@@ -453,72 +459,77 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
453
459
|
return k;
|
|
454
460
|
},
|
|
455
461
|
set selection(t) {
|
|
456
|
-
|
|
462
|
+
G(t);
|
|
457
463
|
},
|
|
458
464
|
get readonly() {
|
|
459
465
|
return r;
|
|
460
466
|
},
|
|
461
467
|
set readonly(t) {
|
|
462
|
-
r = t,
|
|
468
|
+
r = t, I("readonly");
|
|
463
469
|
},
|
|
464
|
-
apply:
|
|
470
|
+
apply: V,
|
|
465
471
|
on: (t, e) => {
|
|
466
|
-
let n =
|
|
467
|
-
n ||
|
|
472
|
+
let n = O.get(t);
|
|
473
|
+
n || O.set(t, n = [ new Set, !1 ]);
|
|
468
474
|
const r = n[0];
|
|
469
475
|
return r.add(e), () => {
|
|
470
476
|
r.delete(e);
|
|
471
477
|
};
|
|
472
478
|
},
|
|
473
479
|
hook: (t, e) => {
|
|
474
|
-
let n =
|
|
475
|
-
return n ||
|
|
480
|
+
let n = E.get(t);
|
|
481
|
+
return n || E.set(t, n = []), n.push(e), () => {
|
|
476
482
|
const t = n.indexOf(e);
|
|
477
483
|
-1 !== t && n.splice(t, 1);
|
|
478
484
|
};
|
|
479
485
|
},
|
|
480
486
|
exec: (t, ...e) => {
|
|
481
|
-
const n = t(
|
|
482
|
-
return void 0 === n ?
|
|
487
|
+
const n = t(Z, ...e);
|
|
488
|
+
return void 0 === n ? Z : n;
|
|
489
|
+
},
|
|
490
|
+
get: t => {
|
|
491
|
+
if (!S.has(t)) throw Error("No value found for key");
|
|
492
|
+
return S.get(t);
|
|
483
493
|
},
|
|
494
|
+
set: (t, e) => (S.set(t, e), Z),
|
|
484
495
|
input: o => {
|
|
485
496
|
if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return g("beforeinput event is not supported."),
|
|
486
497
|
kt;
|
|
487
498
|
const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
|
|
488
499
|
o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
|
|
489
|
-
let d = !1, p = null, y = !1, h = !1,
|
|
490
|
-
const
|
|
500
|
+
let d = !1, p = null, y = !1, h = !1, b = !1;
|
|
501
|
+
const _ = ct(o), w = (t => {
|
|
491
502
|
const e = (n, r, o) => {
|
|
492
|
-
const s = U, c =
|
|
503
|
+
const s = U, c = W, i = T, a = q, l = J;
|
|
493
504
|
try {
|
|
494
|
-
return T || (U = t,
|
|
505
|
+
return T || (U = t, W = e, T = U.p.createTreeWalker(r, 5)), o && (T.currentNode = q = o),
|
|
495
506
|
n();
|
|
496
507
|
} finally {
|
|
497
|
-
U = s,
|
|
508
|
+
U = s, W = c, T = i, q = a, J = l, T && a && (T.currentNode = a);
|
|
498
509
|
}
|
|
499
510
|
};
|
|
500
511
|
return e;
|
|
501
512
|
})({
|
|
502
|
-
p:
|
|
513
|
+
p: _,
|
|
503
514
|
u: x,
|
|
504
515
|
l: ot
|
|
505
|
-
}),
|
|
516
|
+
}), E = () => {
|
|
506
517
|
o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
|
|
507
518
|
};
|
|
508
|
-
|
|
509
|
-
const
|
|
519
|
+
E();
|
|
520
|
+
const S = Z.on("change", () => {
|
|
510
521
|
h || requestAnimationFrame(() => {
|
|
511
522
|
h || o.focus({
|
|
512
523
|
preventScroll: !0
|
|
513
524
|
});
|
|
514
525
|
});
|
|
515
|
-
}), O =
|
|
526
|
+
}), O = Z.on("readonly", E), A = t => {
|
|
516
527
|
for (const e of D("paste")) {
|
|
517
528
|
const n = e(t, w);
|
|
518
529
|
if (n) return n;
|
|
519
530
|
}
|
|
520
531
|
g("failed to serialize pasted data");
|
|
521
|
-
},
|
|
532
|
+
}, I = ((t, e) => {
|
|
522
533
|
let n = !1;
|
|
523
534
|
const r = [], o = t => {
|
|
524
535
|
n && r.push(...t);
|
|
@@ -551,28 +562,28 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
551
562
|
}
|
|
552
563
|
};
|
|
553
564
|
})(o, () => {
|
|
554
|
-
ft(
|
|
555
|
-
}),
|
|
556
|
-
|
|
565
|
+
ft(_, o, M(n, k), k[0] - k[1], w);
|
|
566
|
+
}), P = () => {
|
|
567
|
+
G(v(n, ((t, e) => {
|
|
557
568
|
const n = it(t), r = at(n, t);
|
|
558
569
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
559
570
|
const o = pt(t, e, r), s = st(n.anchorNode, n.focusNode);
|
|
560
571
|
return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
|
|
561
572
|
})(o, w)));
|
|
562
|
-
},
|
|
563
|
-
const t =
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
},
|
|
567
|
-
if (!y) for (const e of D("keyboard")) if (e(t)) return t.preventDefault(), void
|
|
568
|
-
},
|
|
569
|
-
y ||
|
|
570
|
-
},
|
|
573
|
+
}, C = () => {
|
|
574
|
+
const t = I._();
|
|
575
|
+
I.k(!1), t.length && (I.h(t), _.removeEventListener("selectionchange", Y), ft(_, o, M(n, k), k[0] - k[1], w, !0),
|
|
576
|
+
_.addEventListener("selectionchange", Y)), p && (G(p[1]), V(p[0]), p = null), y = !1;
|
|
577
|
+
}, H = t => {
|
|
578
|
+
if (!y) for (const e of D("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
|
|
579
|
+
}, B = () => {
|
|
580
|
+
y || C();
|
|
581
|
+
}, F = t => {
|
|
571
582
|
t.preventDefault();
|
|
572
583
|
const r = t.inputType;
|
|
573
584
|
if (r.startsWith("format")) return;
|
|
574
585
|
if ("historyUndo" === r || "historyRedo" === r) return;
|
|
575
|
-
y ?
|
|
586
|
+
y ? I.k(!0) : P();
|
|
576
587
|
const s = t.getTargetRanges()[0];
|
|
577
588
|
if (s) {
|
|
578
589
|
const c = v(n, pt(o, w, s));
|
|
@@ -590,26 +601,26 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
590
601
|
text: a
|
|
591
602
|
});
|
|
592
603
|
}
|
|
593
|
-
y ||
|
|
594
|
-
},
|
|
595
|
-
y ||
|
|
604
|
+
y || C();
|
|
605
|
+
}, L = () => {
|
|
606
|
+
y || P(), y = !0;
|
|
596
607
|
}, j = () => {
|
|
597
|
-
|
|
608
|
+
C();
|
|
598
609
|
}, z = () => {
|
|
599
|
-
h = !0,
|
|
610
|
+
h = !0, P();
|
|
600
611
|
}, X = () => {
|
|
601
612
|
h = !1;
|
|
602
613
|
}, Y = () => {
|
|
603
|
-
!h || y ||
|
|
614
|
+
!h || y || b || P();
|
|
604
615
|
}, K = r => {
|
|
605
|
-
if (
|
|
616
|
+
if (P(), !e(k)) {
|
|
606
617
|
const e = R(n, ...t(k));
|
|
607
618
|
for (const t of D("copy")) t(r, e, o);
|
|
608
619
|
}
|
|
609
620
|
}, Q = t => {
|
|
610
621
|
t.preventDefault(), K(t.clipboardData);
|
|
611
622
|
}, $ = e => {
|
|
612
|
-
e.preventDefault(), r || (K(e.clipboardData),
|
|
623
|
+
e.preventDefault(), r || (K(e.clipboardData), V({
|
|
613
624
|
type: "delete",
|
|
614
625
|
range: t(k)
|
|
615
626
|
}));
|
|
@@ -629,7 +640,7 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
629
640
|
type: "insert_node",
|
|
630
641
|
at: r,
|
|
631
642
|
fragment: n
|
|
632
|
-
}),
|
|
643
|
+
}), V(o);
|
|
633
644
|
}
|
|
634
645
|
}, et = e => {
|
|
635
646
|
e.preventDefault();
|
|
@@ -641,17 +652,17 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
641
652
|
const s = t.caretRangeFromPoint(n, r);
|
|
642
653
|
if (s) return dt(e, s.startContainer, s.startOffset, o);
|
|
643
654
|
}
|
|
644
|
-
})(
|
|
655
|
+
})(_, o, e, w);
|
|
645
656
|
if (r && c) {
|
|
646
657
|
let e;
|
|
647
658
|
const o = [];
|
|
648
|
-
|
|
659
|
+
b && o.push({
|
|
649
660
|
type: "delete",
|
|
650
661
|
range: t(k)
|
|
651
662
|
});
|
|
652
663
|
const i = A(r);
|
|
653
664
|
if (i) {
|
|
654
|
-
const t = m(n, c), r =
|
|
665
|
+
const t = m(n, c), r = N(t, o);
|
|
655
666
|
o.push(s(i) ? {
|
|
656
667
|
type: "insert_text",
|
|
657
668
|
at: r,
|
|
@@ -660,17 +671,17 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
660
671
|
type: "insert_node",
|
|
661
672
|
at: r,
|
|
662
673
|
fragment: i
|
|
663
|
-
}), e = [ r,
|
|
674
|
+
}), e = [ r, N(t, o) ];
|
|
664
675
|
}
|
|
665
|
-
|
|
676
|
+
V(o), e && G(e);
|
|
666
677
|
}
|
|
667
678
|
}, nt = t => {
|
|
668
|
-
|
|
679
|
+
b = !0, K(t.dataTransfer);
|
|
669
680
|
}, rt = () => {
|
|
670
|
-
|
|
681
|
+
b = !1;
|
|
671
682
|
};
|
|
672
|
-
|
|
673
|
-
o.addEventListener("beforeinput",
|
|
683
|
+
_.addEventListener("selectionchange", Y), o.addEventListener("keydown", H), o.addEventListener("input", B),
|
|
684
|
+
o.addEventListener("beforeinput", F), o.addEventListener("compositionstart", L),
|
|
674
685
|
o.addEventListener("compositionend", j), o.addEventListener("focus", z), o.addEventListener("blur", X),
|
|
675
686
|
o.addEventListener("copy", Q), o.addEventListener("cut", $), o.addEventListener("paste", tt),
|
|
676
687
|
o.addEventListener("drop", et), o.addEventListener("dragstart", nt), o.addEventListener("dragend", rt);
|
|
@@ -679,10 +690,10 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
679
690
|
const e = t(o);
|
|
680
691
|
e && lt.push(e);
|
|
681
692
|
}), () => {
|
|
682
|
-
d || (d = !0,
|
|
683
|
-
o.ariaReadOnly = f, o.style.whiteSpace = u,
|
|
684
|
-
o.removeEventListener("keydown",
|
|
685
|
-
o.removeEventListener("compositionstart",
|
|
693
|
+
d || (d = !0, S(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
|
|
694
|
+
o.ariaReadOnly = f, o.style.whiteSpace = u, I.m(), _.removeEventListener("selectionchange", Y),
|
|
695
|
+
o.removeEventListener("keydown", H), o.removeEventListener("input", B), o.removeEventListener("beforeinput", F),
|
|
696
|
+
o.removeEventListener("compositionstart", L), o.removeEventListener("compositionend", j),
|
|
686
697
|
o.removeEventListener("focus", z), o.removeEventListener("blur", X), o.removeEventListener("copy", Q),
|
|
687
698
|
o.removeEventListener("cut", $), o.removeEventListener("paste", tt), o.removeEventListener("drop", et),
|
|
688
699
|
o.removeEventListener("dragstart", nt), o.removeEventListener("dragend", rt), lt.forEach(t => {
|
|
@@ -691,10 +702,10 @@ const gt = [], kt = () => {}, _t = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
691
702
|
};
|
|
692
703
|
}
|
|
693
704
|
};
|
|
694
|
-
return
|
|
705
|
+
return Z.exec(xt), Z;
|
|
695
706
|
};
|
|
696
707
|
|
|
697
|
-
function
|
|
708
|
+
function _t(t, e) {
|
|
698
709
|
const n = e && e.serializer;
|
|
699
710
|
t.hook("copy", (t, e) => {
|
|
700
711
|
t.setData("text/plain", a({
|
|
@@ -745,7 +756,11 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
745
756
|
at: n,
|
|
746
757
|
text: e
|
|
747
758
|
});
|
|
748
|
-
}, exports.
|
|
759
|
+
}, exports.Redo = function(t) {
|
|
760
|
+
t.get(xt).redo();
|
|
761
|
+
}, exports.Redoable = function(t) {
|
|
762
|
+
return t.get(xt).redoable();
|
|
763
|
+
}, exports.ReplaceDoc = L, exports.ReplaceText = function(e, n) {
|
|
749
764
|
const r = t(e.selection);
|
|
750
765
|
e.apply({
|
|
751
766
|
type: "delete",
|
|
@@ -778,13 +793,17 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
778
793
|
key: n,
|
|
779
794
|
value: !!o.some(t => !t[n])
|
|
780
795
|
});
|
|
781
|
-
}, exports.
|
|
782
|
-
|
|
796
|
+
}, exports.Undo = function(t) {
|
|
797
|
+
t.get(xt).undo();
|
|
798
|
+
}, exports.Undoable = function(t) {
|
|
799
|
+
return t.get(xt).undoable();
|
|
800
|
+
}, exports.createEditor = bt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
801
|
+
const o = bt({
|
|
783
802
|
...r,
|
|
784
803
|
doc: {
|
|
785
804
|
children: l(t)
|
|
786
805
|
}
|
|
787
|
-
}).exec(
|
|
806
|
+
}).exec(_t);
|
|
788
807
|
return o.on("change", () => {
|
|
789
808
|
n(a(o.doc));
|
|
790
809
|
}), e && o.exec(wt), o;
|
|
@@ -862,5 +881,5 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
862
881
|
r();
|
|
863
882
|
}));
|
|
864
883
|
});
|
|
865
|
-
}, exports.plainTransferPlugin =
|
|
884
|
+
}, exports.plainTransferPlugin = _t, exports.singlelinePlugin = wt;
|
|
866
885
|
//# sourceMappingURL=index.cjs.map
|