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