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.cjs
CHANGED
|
@@ -12,34 +12,27 @@ 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
|
-
},
|
|
15
|
+
}, _ = new WeakMap, k = ({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 += b(e), 0 !== o && x(e) && r++, o++;
|
|
20
20
|
}
|
|
21
21
|
return r;
|
|
22
|
-
},
|
|
22
|
+
}, b = t => {
|
|
23
23
|
if (x(t)) {
|
|
24
|
-
let e =
|
|
25
|
-
return null == e &&
|
|
24
|
+
let e = _.get(t);
|
|
25
|
+
return null == e && _.set(t, e = k(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 += k(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, s = r.o;
|
|
38
|
-
if (!x(s)) break;
|
|
39
|
-
e = r.i, n.push(o), t = s;
|
|
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];
|
|
@@ -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 = b(r);
|
|
73
66
|
if (x(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 (!x(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: s} = r;
|
|
85
92
|
if (x(e)) {
|
|
86
|
-
const [r, c] =
|
|
93
|
+
const [r, c] = P(e, o), i = n.slice(0, s), a = n.slice(s + 1);
|
|
87
94
|
return i.push(r), a.unshift(c), [ {
|
|
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, s] =
|
|
137
|
-
return
|
|
140
|
+
const [o, s] = P(t, e), c = e < n ? P(t, n)[1] : s, i = o.children.slice();
|
|
141
|
+
return E(i, r, D), E(i, c.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 <= b(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 + b({
|
|
161
165
|
children: r
|
|
162
166
|
});
|
|
163
167
|
break;
|
|
@@ -169,7 +173,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
169
173
|
function L(t, e) {
|
|
170
174
|
t.apply({
|
|
171
175
|
type: "delete",
|
|
172
|
-
range: [ 0,
|
|
176
|
+
range: [ 0, b(t.doc) ]
|
|
173
177
|
}).apply({
|
|
174
178
|
type: "insert_node",
|
|
175
179
|
at: 0,
|
|
@@ -177,42 +181,42 @@ function L(t, e) {
|
|
|
177
181
|
});
|
|
178
182
|
}
|
|
179
183
|
|
|
180
|
-
let T = null,
|
|
184
|
+
let T = null, W = null, q = null, J = null, U = null;
|
|
181
185
|
|
|
182
|
-
const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () =>
|
|
186
|
+
const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = () => {
|
|
183
187
|
const t = X();
|
|
184
|
-
return 1 === t ?
|
|
188
|
+
return 1 === t ? W.data.length : 2 === t ? 1 : 0;
|
|
185
189
|
}, X = () => {
|
|
186
|
-
if (null !=
|
|
187
|
-
if (
|
|
188
|
-
const t =
|
|
189
|
-
if (t) return
|
|
190
|
-
} else if (G(
|
|
191
|
-
if ("BR" ===
|
|
192
|
-
if (
|
|
193
|
-
if (
|
|
190
|
+
if (null != q) return q;
|
|
191
|
+
if (W) if ((t => 3 === t.nodeType)(W)) {
|
|
192
|
+
const t = W.data;
|
|
193
|
+
if (t) return q = "\n" === t ? $() ? 3 : 6 : 1;
|
|
194
|
+
} else if (G(W)) {
|
|
195
|
+
if ("BR" === W.tagName) return q = $() ? 3 : 5;
|
|
196
|
+
if (J.u(W)) return q = 2;
|
|
197
|
+
if (J.p(W)) return q = 4;
|
|
194
198
|
}
|
|
195
|
-
return
|
|
196
|
-
}, Y = () => (
|
|
197
|
-
for (;(
|
|
199
|
+
return q = 0;
|
|
200
|
+
}, Y = () => (q = null, W = T.nextNode()), K = () => {
|
|
201
|
+
for (;(q = null) || (W = T.nextSibling()); ) if (4 === X()) return;
|
|
198
202
|
}, Q = () => {
|
|
199
|
-
for (;(
|
|
203
|
+
for (;(q = null) || (W = T.parentNode()); ) if (4 === X()) return;
|
|
200
204
|
}, $ = () => {
|
|
201
|
-
const t =
|
|
202
|
-
return
|
|
205
|
+
const t = W.parentNode;
|
|
206
|
+
return U(() => {
|
|
203
207
|
for (;Y(); ) {
|
|
204
208
|
if (X()) return !0;
|
|
205
|
-
if (!t.contains(
|
|
209
|
+
if (!t.contains(W)) break;
|
|
206
210
|
}
|
|
207
211
|
return !1;
|
|
208
212
|
});
|
|
209
213
|
}, tt = () => {
|
|
210
214
|
for (;;) {
|
|
211
215
|
if (2 === X()) {
|
|
212
|
-
const t =
|
|
213
|
-
for (;Y() && t.contains(
|
|
216
|
+
const t = W;
|
|
217
|
+
for (;Y() && t.contains(W); ) ;
|
|
214
218
|
} else Y();
|
|
215
|
-
if (!
|
|
219
|
+
if (!W) break;
|
|
216
220
|
const t = X();
|
|
217
221
|
if (t) return t;
|
|
218
222
|
}
|
|
@@ -347,33 +351,32 @@ function xt(t) {
|
|
|
347
351
|
});
|
|
348
352
|
}
|
|
349
353
|
|
|
350
|
-
const gt = [],
|
|
354
|
+
const gt = [], _t = () => {}, kt = t => {
|
|
355
|
+
throw Error(t);
|
|
356
|
+
}, bt = ({doc: n, readonly: r = !1, schema: a, isBlock: x = nt, onWarn: g = console.warn, onError: _ = kt}) => {
|
|
351
357
|
let k = [ 0, 0 ];
|
|
352
|
-
const b =
|
|
353
|
-
if (!a) return
|
|
358
|
+
const b = t => {
|
|
359
|
+
if (!a) return g("An unsafe operation was detected. We recommend using schema option."),
|
|
354
360
|
!0;
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
357
|
-
if (!
|
|
358
|
-
e
|
|
361
|
+
const e = a["~standard"].validate(t);
|
|
362
|
+
if (e instanceof Promise) _("async validate is not supported"); else {
|
|
363
|
+
if (!e.issues) return !0;
|
|
364
|
+
g(e.issues.map(t => t.message).join("\n"));
|
|
359
365
|
}
|
|
360
366
|
return !1;
|
|
361
367
|
};
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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);
|
|
368
|
+
a && !b(n) && _("Invalid document");
|
|
369
|
+
const v = new Map, S = new WeakMap, D = t => v.get(t) || gt, E = new Map, O = t => {
|
|
370
|
+
const e = E.get(t);
|
|
368
371
|
e && !e[1] && (e[1] = !0, i(() => {
|
|
369
372
|
e[1] = !1, e[0].forEach(t => {
|
|
370
373
|
t();
|
|
371
374
|
});
|
|
372
375
|
}));
|
|
376
|
+
}, P = t => {
|
|
377
|
+
if (!r) if (Array.isArray(t)) for (const e of t) V(e); else V(t);
|
|
378
|
+
return G;
|
|
373
379
|
}, 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 => {
|
|
377
380
|
const e = n, r = D("apply"), s = r.length;
|
|
378
381
|
let c = 0;
|
|
379
382
|
const i = () => {
|
|
@@ -396,13 +399,13 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
396
399
|
{
|
|
397
400
|
const {at: r, text: o} = n;
|
|
398
401
|
if (B(t, r) && o) {
|
|
399
|
-
const
|
|
400
|
-
let
|
|
401
|
-
if (
|
|
402
|
-
const t =
|
|
403
|
-
h(t) && (
|
|
402
|
+
const {i: s, o: c} = I(t, r), i = A(s, c - 1);
|
|
403
|
+
let a;
|
|
404
|
+
if (i) {
|
|
405
|
+
const t = i.i;
|
|
406
|
+
h(t) && (a = t);
|
|
404
407
|
}
|
|
405
|
-
t = H(t, r, r, l(o,
|
|
408
|
+
t = H(t, r, r, l(o, a, s)), e = F(e, n);
|
|
406
409
|
}
|
|
407
410
|
break;
|
|
408
411
|
}
|
|
@@ -429,7 +432,10 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
429
432
|
|
|
430
433
|
case y:
|
|
431
434
|
{
|
|
432
|
-
const {path: e, key: r, value: o} = n, s =
|
|
435
|
+
const {path: e, key: r, value: o} = n, s = ((t, e) => {
|
|
436
|
+
for (let n = 0; n < e.length; n++) t = t.children[e[n]];
|
|
437
|
+
return t;
|
|
438
|
+
})(t, e);
|
|
433
439
|
s && (t = C(t, e, {
|
|
434
440
|
...s,
|
|
435
441
|
[r]: o
|
|
@@ -439,7 +445,7 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
439
445
|
}
|
|
440
446
|
return [ t, e ];
|
|
441
447
|
})(n, k, t);
|
|
442
|
-
(({type: t}) => t === d || t === p || t === y)(t) && !b(e
|
|
448
|
+
(({type: t}) => t === d || t === p || t === y)(t) && !b(e) || (n = e, k = r);
|
|
443
449
|
} catch (t) {
|
|
444
450
|
g("rollback operation: " + t);
|
|
445
451
|
}
|
|
@@ -447,11 +453,11 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
447
453
|
}, a = e => {
|
|
448
454
|
e && (t = e), c++, i();
|
|
449
455
|
};
|
|
450
|
-
i(), o(e, n) ||
|
|
451
|
-
},
|
|
456
|
+
i(), o(e, n) || O("change");
|
|
457
|
+
}, L = t => {
|
|
452
458
|
!((t, [e, n]) => B(t, e) && B(t, n))(n, t) || k[0] === t[0] && k[1] === t[1] || (k = t,
|
|
453
|
-
|
|
454
|
-
},
|
|
459
|
+
O("selectionchange"));
|
|
460
|
+
}, G = {
|
|
455
461
|
get doc() {
|
|
456
462
|
return n;
|
|
457
463
|
},
|
|
@@ -459,73 +465,70 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
459
465
|
return k;
|
|
460
466
|
},
|
|
461
467
|
set selection(t) {
|
|
462
|
-
|
|
468
|
+
L(t);
|
|
463
469
|
},
|
|
464
470
|
get readonly() {
|
|
465
471
|
return r;
|
|
466
472
|
},
|
|
467
473
|
set readonly(t) {
|
|
468
|
-
r = t,
|
|
474
|
+
r = t, O("readonly");
|
|
469
475
|
},
|
|
470
|
-
apply:
|
|
476
|
+
apply: P,
|
|
471
477
|
on: (t, e) => {
|
|
472
|
-
let n =
|
|
473
|
-
n ||
|
|
478
|
+
let n = E.get(t);
|
|
479
|
+
n || E.set(t, n = [ new Set, !1 ]);
|
|
474
480
|
const r = n[0];
|
|
475
481
|
return r.add(e), () => {
|
|
476
482
|
r.delete(e);
|
|
477
483
|
};
|
|
478
484
|
},
|
|
479
485
|
hook: (t, e) => {
|
|
480
|
-
let n =
|
|
481
|
-
return n ||
|
|
486
|
+
let n = v.get(t);
|
|
487
|
+
return n || v.set(t, n = []), n.push(e), () => {
|
|
482
488
|
const t = n.indexOf(e);
|
|
483
489
|
-1 !== t && n.splice(t, 1);
|
|
484
490
|
};
|
|
485
491
|
},
|
|
486
492
|
exec: (t, ...e) => {
|
|
487
|
-
const n = t(
|
|
488
|
-
return void 0 === n ?
|
|
493
|
+
const n = t(G, ...e);
|
|
494
|
+
return void 0 === n ? G : n;
|
|
489
495
|
},
|
|
490
|
-
get: t =>
|
|
491
|
-
|
|
492
|
-
return S.get(t);
|
|
493
|
-
},
|
|
494
|
-
set: (t, e) => (S.set(t, e), Z),
|
|
496
|
+
get: t => (S.has(t) || _("No value found for key"), S.get(t)),
|
|
497
|
+
set: (t, e) => (S.set(t, e), G),
|
|
495
498
|
input: o => {
|
|
496
499
|
if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return g("beforeinput event is not supported."),
|
|
497
|
-
|
|
500
|
+
_t;
|
|
498
501
|
const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
|
|
499
502
|
o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
|
|
500
|
-
let d = !1, p = null, y = !1, h = !1,
|
|
501
|
-
const
|
|
503
|
+
let d = !1, p = null, y = !1, h = !1, _ = !1;
|
|
504
|
+
const b = ct(o), v = (t => {
|
|
502
505
|
const e = (n, r, o) => {
|
|
503
|
-
const s =
|
|
506
|
+
const s = J, c = U, i = T, a = W, l = q;
|
|
504
507
|
try {
|
|
505
|
-
return T || (
|
|
508
|
+
return T || (J = t, U = e, T = J.h.createTreeWalker(r, 5)), o && (T.currentNode = W = o),
|
|
506
509
|
n();
|
|
507
510
|
} finally {
|
|
508
|
-
|
|
511
|
+
J = s, U = c, T = i, W = a, q = l, T && a && (T.currentNode = a);
|
|
509
512
|
}
|
|
510
513
|
};
|
|
511
514
|
return e;
|
|
512
515
|
})({
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}),
|
|
516
|
+
h: b,
|
|
517
|
+
p: x,
|
|
518
|
+
u: ot
|
|
519
|
+
}), S = () => {
|
|
517
520
|
o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
|
|
518
521
|
};
|
|
519
|
-
|
|
520
|
-
const
|
|
522
|
+
S();
|
|
523
|
+
const E = G.on("change", () => {
|
|
521
524
|
h || requestAnimationFrame(() => {
|
|
522
525
|
h || o.focus({
|
|
523
526
|
preventScroll: !0
|
|
524
527
|
});
|
|
525
528
|
});
|
|
526
|
-
}), O =
|
|
529
|
+
}), O = G.on("readonly", S), A = t => {
|
|
527
530
|
for (const e of D("paste")) {
|
|
528
|
-
const n = e(t,
|
|
531
|
+
const n = e(t, v);
|
|
529
532
|
if (n) return n;
|
|
530
533
|
}
|
|
531
534
|
g("failed to serialize pasted data");
|
|
@@ -544,7 +547,7 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
544
547
|
childList: !0,
|
|
545
548
|
subtree: !0
|
|
546
549
|
}), {
|
|
547
|
-
|
|
550
|
+
_: t => {
|
|
548
551
|
let e;
|
|
549
552
|
for (;e = t.pop(); ) if ("childList" === e.type) {
|
|
550
553
|
const {target: t, removedNodes: n, addedNodes: r, nextSibling: o} = e;
|
|
@@ -556,37 +559,37 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
556
559
|
k: t => {
|
|
557
560
|
!n && t && c(), n = t;
|
|
558
561
|
},
|
|
559
|
-
|
|
560
|
-
|
|
562
|
+
m: i,
|
|
563
|
+
v: () => {
|
|
561
564
|
r.splice(0), s.disconnect();
|
|
562
565
|
}
|
|
563
566
|
};
|
|
564
567
|
})(o, () => {
|
|
565
|
-
ft(
|
|
566
|
-
}),
|
|
567
|
-
|
|
568
|
+
ft(b, o, M(n, k), k[0] - k[1], v);
|
|
569
|
+
}), C = () => {
|
|
570
|
+
L(w(n, ((t, e) => {
|
|
568
571
|
const n = it(t), r = at(n, t);
|
|
569
572
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
570
573
|
const o = pt(t, e, r), s = st(n.anchorNode, n.focusNode);
|
|
571
574
|
return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
|
|
572
|
-
})(o,
|
|
573
|
-
},
|
|
574
|
-
const t = I.
|
|
575
|
-
I.k(!1), t.length && (I.
|
|
576
|
-
|
|
577
|
-
},
|
|
575
|
+
})(o, v)));
|
|
576
|
+
}, H = () => {
|
|
577
|
+
const t = I.m();
|
|
578
|
+
I.k(!1), t.length && (I._(t), b.removeEventListener("selectionchange", X), ft(b, o, M(n, k), k[0] - k[1], v, !0),
|
|
579
|
+
b.addEventListener("selectionchange", X)), p && (L(p[1]), P(p[0]), p = null), y = !1;
|
|
580
|
+
}, R = t => {
|
|
578
581
|
if (!y) for (const e of D("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
|
|
579
582
|
}, B = () => {
|
|
580
|
-
y ||
|
|
581
|
-
},
|
|
583
|
+
y || H();
|
|
584
|
+
}, V = t => {
|
|
582
585
|
t.preventDefault();
|
|
583
586
|
const r = t.inputType;
|
|
584
587
|
if (r.startsWith("format")) return;
|
|
585
588
|
if ("historyUndo" === r || "historyRedo" === r) return;
|
|
586
|
-
y ? I.k(!0) :
|
|
589
|
+
y ? I.k(!0) : C();
|
|
587
590
|
const s = t.getTargetRanges()[0];
|
|
588
591
|
if (s) {
|
|
589
|
-
const c =
|
|
592
|
+
const c = w(n, pt(o, v, s));
|
|
590
593
|
let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
|
|
591
594
|
if (null == a) {
|
|
592
595
|
const e = t.dataTransfer;
|
|
@@ -601,30 +604,27 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
601
604
|
text: a
|
|
602
605
|
});
|
|
603
606
|
}
|
|
604
|
-
y ||
|
|
605
|
-
},
|
|
606
|
-
y ||
|
|
607
|
+
y || H();
|
|
608
|
+
}, F = () => {
|
|
609
|
+
y || C(), y = !0;
|
|
610
|
+
}, Z = () => {
|
|
611
|
+
H();
|
|
607
612
|
}, j = () => {
|
|
608
|
-
C();
|
|
613
|
+
h = !0, C();
|
|
609
614
|
}, z = () => {
|
|
610
|
-
h = !0, P();
|
|
611
|
-
}, X = () => {
|
|
612
615
|
h = !1;
|
|
613
|
-
},
|
|
614
|
-
!h || y ||
|
|
615
|
-
},
|
|
616
|
-
if (
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
t.preventDefault(), K(t.clipboardData);
|
|
622
|
-
}, $ = e => {
|
|
623
|
-
e.preventDefault(), r || (K(e.clipboardData), V({
|
|
616
|
+
}, X = () => {
|
|
617
|
+
!h || y || _ || C();
|
|
618
|
+
}, Y = t => {
|
|
619
|
+
if (C(), !e(k)) for (const e of D("copy")) e(t);
|
|
620
|
+
}, K = t => {
|
|
621
|
+
t.preventDefault(), Y(t.clipboardData);
|
|
622
|
+
}, Q = e => {
|
|
623
|
+
e.preventDefault(), r || (Y(e.clipboardData), P({
|
|
624
624
|
type: "delete",
|
|
625
625
|
range: t(k)
|
|
626
626
|
}));
|
|
627
|
-
},
|
|
627
|
+
}, $ = e => {
|
|
628
628
|
e.preventDefault();
|
|
629
629
|
const n = A(e.clipboardData);
|
|
630
630
|
if (n) {
|
|
@@ -640,9 +640,9 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
640
640
|
type: "insert_node",
|
|
641
641
|
at: r,
|
|
642
642
|
fragment: n
|
|
643
|
-
}),
|
|
643
|
+
}), P(o);
|
|
644
644
|
}
|
|
645
|
-
},
|
|
645
|
+
}, tt = e => {
|
|
646
646
|
e.preventDefault();
|
|
647
647
|
const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}, o) => {
|
|
648
648
|
if (t.caretPositionFromPoint) {
|
|
@@ -652,11 +652,11 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
652
652
|
const s = t.caretRangeFromPoint(n, r);
|
|
653
653
|
if (s) return dt(e, s.startContainer, s.startOffset, o);
|
|
654
654
|
}
|
|
655
|
-
})(
|
|
655
|
+
})(b, o, e, v);
|
|
656
656
|
if (r && c) {
|
|
657
657
|
let e;
|
|
658
658
|
const o = [];
|
|
659
|
-
|
|
659
|
+
_ && o.push({
|
|
660
660
|
type: "delete",
|
|
661
661
|
range: t(k)
|
|
662
662
|
});
|
|
@@ -673,48 +673,48 @@ const gt = [], kt = () => {}, bt = ({doc: n, readonly: r = !1, schema: a, isBloc
|
|
|
673
673
|
fragment: i
|
|
674
674
|
}), e = [ r, N(t, o) ];
|
|
675
675
|
}
|
|
676
|
-
|
|
676
|
+
P(o), e && L(e);
|
|
677
677
|
}
|
|
678
|
-
},
|
|
679
|
-
|
|
680
|
-
},
|
|
681
|
-
|
|
678
|
+
}, et = t => {
|
|
679
|
+
_ = !0, Y(t.dataTransfer);
|
|
680
|
+
}, nt = () => {
|
|
681
|
+
_ = !1;
|
|
682
682
|
};
|
|
683
|
-
|
|
684
|
-
o.addEventListener("beforeinput",
|
|
685
|
-
o.addEventListener("compositionend",
|
|
686
|
-
o.addEventListener("copy",
|
|
687
|
-
o.addEventListener("drop",
|
|
688
|
-
const
|
|
683
|
+
b.addEventListener("selectionchange", X), o.addEventListener("keydown", R), o.addEventListener("input", B),
|
|
684
|
+
o.addEventListener("beforeinput", V), o.addEventListener("compositionstart", F),
|
|
685
|
+
o.addEventListener("compositionend", Z), o.addEventListener("focus", j), o.addEventListener("blur", z),
|
|
686
|
+
o.addEventListener("copy", K), o.addEventListener("cut", Q), o.addEventListener("paste", $),
|
|
687
|
+
o.addEventListener("drop", tt), o.addEventListener("dragstart", et), o.addEventListener("dragend", nt);
|
|
688
|
+
const rt = [];
|
|
689
689
|
return D("mount").forEach(t => {
|
|
690
690
|
const e = t(o);
|
|
691
|
-
e &&
|
|
691
|
+
e && rt.push(e);
|
|
692
692
|
}), () => {
|
|
693
|
-
d || (d = !0,
|
|
694
|
-
o.ariaReadOnly = f, o.style.whiteSpace = u, I.
|
|
695
|
-
o.removeEventListener("keydown",
|
|
696
|
-
o.removeEventListener("compositionstart",
|
|
697
|
-
o.removeEventListener("focus",
|
|
698
|
-
o.removeEventListener("cut",
|
|
699
|
-
o.removeEventListener("dragstart",
|
|
693
|
+
d || (d = !0, E(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
|
|
694
|
+
o.ariaReadOnly = f, o.style.whiteSpace = u, I.v(), b.removeEventListener("selectionchange", X),
|
|
695
|
+
o.removeEventListener("keydown", R), o.removeEventListener("input", B), o.removeEventListener("beforeinput", V),
|
|
696
|
+
o.removeEventListener("compositionstart", F), o.removeEventListener("compositionend", Z),
|
|
697
|
+
o.removeEventListener("focus", j), o.removeEventListener("blur", z), o.removeEventListener("copy", K),
|
|
698
|
+
o.removeEventListener("cut", Q), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
|
|
699
|
+
o.removeEventListener("dragstart", et), o.removeEventListener("dragend", nt), rt.forEach(t => {
|
|
700
700
|
t();
|
|
701
701
|
}));
|
|
702
702
|
};
|
|
703
703
|
}
|
|
704
704
|
};
|
|
705
|
-
return
|
|
705
|
+
return G.exec(xt), G;
|
|
706
706
|
};
|
|
707
707
|
|
|
708
|
-
function
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
children: e
|
|
713
|
-
},
|
|
714
|
-
}),
|
|
708
|
+
function mt(e, n) {
|
|
709
|
+
const r = n && n.serializer;
|
|
710
|
+
e.hook("copy", n => {
|
|
711
|
+
n.setData("text/plain", a({
|
|
712
|
+
children: R(e.doc, ...t(e.selection))
|
|
713
|
+
}, r));
|
|
714
|
+
}), e.hook("paste", t => t.getData("text/plain"));
|
|
715
715
|
}
|
|
716
716
|
|
|
717
|
-
const
|
|
717
|
+
const vt = "application/x-editate-editor";
|
|
718
718
|
|
|
719
719
|
function wt(t) {
|
|
720
720
|
t.hook("mount", t => {
|
|
@@ -770,18 +770,19 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
770
770
|
at: r[0],
|
|
771
771
|
text: n
|
|
772
772
|
});
|
|
773
|
-
}, exports.SetBlockAttr = function(t, e, n, r =
|
|
773
|
+
}, exports.SetBlockAttr = function(t, e, n, r = t.selection[0]) {
|
|
774
|
+
const {t: o} = I(t.doc, r);
|
|
774
775
|
t.apply({
|
|
775
776
|
type: "set_node_attr",
|
|
776
|
-
path:
|
|
777
|
+
path: o,
|
|
777
778
|
key: e,
|
|
778
779
|
value: n
|
|
779
780
|
});
|
|
780
|
-
}, exports.ToggleBlockAttr = function(t, e, n, r, o =
|
|
781
|
-
const s =
|
|
781
|
+
}, exports.ToggleBlockAttr = function(t, e, n, r, o = t.selection[0]) {
|
|
782
|
+
const {i: s, t: c} = I(t.doc, o);
|
|
782
783
|
t.apply({
|
|
783
784
|
type: "set_node_attr",
|
|
784
|
-
path:
|
|
785
|
+
path: c,
|
|
785
786
|
key: e,
|
|
786
787
|
value: s[e] === n ? r : n
|
|
787
788
|
});
|
|
@@ -803,7 +804,7 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
803
804
|
doc: {
|
|
804
805
|
children: l(t)
|
|
805
806
|
}
|
|
806
|
-
}).exec(
|
|
807
|
+
}).exec(mt);
|
|
807
808
|
return o.on("change", () => {
|
|
808
809
|
n(a(o.doc));
|
|
809
810
|
}), e && o.exec(wt), o;
|
|
@@ -829,9 +830,13 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
829
830
|
return null;
|
|
830
831
|
});
|
|
831
832
|
}, exports.htmlTransferPlugin = function(t, e) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
833
|
+
let n = null;
|
|
834
|
+
t.hook("mount", t => (n = t, () => {
|
|
835
|
+
n = null;
|
|
836
|
+
})), t.hook("copy", t => {
|
|
837
|
+
if (!n) return;
|
|
838
|
+
const e = document.createElement("div");
|
|
839
|
+
e.appendChild(at(it(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
|
|
835
840
|
}), t.hook("paste", ((t, e = []) => (n, r) => {
|
|
836
841
|
const o = n.getData("text/html");
|
|
837
842
|
if (o) {
|
|
@@ -864,12 +869,12 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
864
869
|
}
|
|
865
870
|
return null;
|
|
866
871
|
})(e.serializeText, e.serializers));
|
|
867
|
-
}, exports.internalTranferPlugin = function(
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
}),
|
|
872
|
+
}, exports.internalTranferPlugin = function(e) {
|
|
873
|
+
e.hook("copy", n => {
|
|
874
|
+
n.setData(vt, JSON.stringify(R(e.doc, ...t(e.selection))));
|
|
875
|
+
}), e.hook("paste", t => {
|
|
871
876
|
try {
|
|
872
|
-
return JSON.parse(t.getData(
|
|
877
|
+
return JSON.parse(t.getData(vt));
|
|
873
878
|
} catch (t) {
|
|
874
879
|
return null;
|
|
875
880
|
}
|
|
@@ -881,5 +886,5 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
881
886
|
r();
|
|
882
887
|
}));
|
|
883
888
|
});
|
|
884
|
-
}, exports.plainTransferPlugin =
|
|
889
|
+
}, exports.plainTransferPlugin = mt, exports.singlelinePlugin = wt;
|
|
885
890
|
//# sourceMappingURL=index.cjs.map
|