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