editate 0.6.20 → 0.6.22
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/doc/operation.d.ts +5 -1
- package/lib/editor.d.ts +5 -1
- package/lib/index.cjs +530 -411
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +433 -314
- package/lib/index.js.map +1 -1
- package/lib/plugins/blockLock.d.ts +19 -0
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/scrollToSelection.d.ts +5 -0
- package/package.json +10 -3
package/lib/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
|
|
|
23
23
|
e -= s;
|
|
24
24
|
}
|
|
25
25
|
return null;
|
|
26
|
-
},
|
|
26
|
+
}, h = (t, e) => {
|
|
27
27
|
const n = [];
|
|
28
28
|
for (;t; ) {
|
|
29
29
|
const r = p(t, e);
|
|
@@ -33,8 +33,8 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
|
|
|
33
33
|
e = r[1], t = o, n.push(r[2]);
|
|
34
34
|
}
|
|
35
35
|
return [ t, e, n ];
|
|
36
|
-
},
|
|
37
|
-
const [r, o, c] =
|
|
36
|
+
}, y = (t, e, n) => {
|
|
37
|
+
const [r, o, c] = h(t, e), s = p(r, o, n);
|
|
38
38
|
return s ? (c.push(s[2]), [ s[0], s[1], c ]) : null;
|
|
39
39
|
}, k = (t, e) => {
|
|
40
40
|
const n = t.children, r = p(t, e);
|
|
@@ -79,16 +79,16 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
|
|
|
79
79
|
text: ""
|
|
80
80
|
} ] : []
|
|
81
81
|
} ];
|
|
82
|
-
},
|
|
82
|
+
}, m = (t, [e, n]) => {
|
|
83
83
|
let r = 0;
|
|
84
84
|
for (const o of e) r += u(t, 0, o), 0 !== o && r++, t = t.children[o];
|
|
85
85
|
return r + n;
|
|
86
|
-
},
|
|
87
|
-
const [, n, r] =
|
|
86
|
+
}, g = (t, e) => {
|
|
87
|
+
const [, n, r] = h(t, e);
|
|
88
88
|
return [ r, n ];
|
|
89
|
-
},
|
|
89
|
+
}, _ = (t, [e, n]) => [ m(t, e), m(t, n) ];
|
|
90
90
|
|
|
91
|
-
function*
|
|
91
|
+
function* b(t, [e, n]) {
|
|
92
92
|
if (e >= n) return;
|
|
93
93
|
if (!l(t)) return;
|
|
94
94
|
const r = p(t, e);
|
|
@@ -102,15 +102,15 @@ function* _(t, [e, n]) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
function*
|
|
106
|
-
if (!l(t) || a(t.children)) for (const n of
|
|
105
|
+
function* x(t, e) {
|
|
106
|
+
if (!l(t) || a(t.children)) for (const n of b(t, e)) {
|
|
107
107
|
const [t, e] = n;
|
|
108
|
-
for (const n of
|
|
108
|
+
for (const n of x(t, [ 0, d(t) ])) n[1] += e, yield n;
|
|
109
109
|
} else yield [ t, 0 ];
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function* v(t, e) {
|
|
113
|
-
if (l(t)) for (const [n, r] of
|
|
113
|
+
if (l(t)) for (const [n, r] of b(t, e)) for (const t of v(n, [ 0, d(n) ])) t[1] += r,
|
|
114
114
|
yield t; else yield [ t, 0 ];
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -127,23 +127,110 @@ var T = (n, r = 0, o = 1 / 0, c) => {
|
|
|
127
127
|
}
|
|
128
128
|
for (let e = t(o, d(n)) - l; e > 0; e--) s += "\n";
|
|
129
129
|
return s;
|
|
130
|
-
}, E = (t, e, n) => e >= n ? [] : k(k(t, n)[0], e)[1].children, M = (
|
|
130
|
+
}, E = (t, e, n) => e >= n ? [] : k(k(t, n)[0], e)[1].children, M = (t, e, n) => t.split("\n").map(t => ({
|
|
131
|
+
...n,
|
|
132
|
+
children: [ {
|
|
133
|
+
...e,
|
|
134
|
+
text: t
|
|
135
|
+
} ]
|
|
136
|
+
})), w = "delete", S = "insert_text", A = "insert_node", O = (t, e) => {
|
|
137
|
+
const o = n(t);
|
|
138
|
+
return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
|
|
139
|
+
}, R = (t, e) => {
|
|
140
|
+
if (e.length) {
|
|
141
|
+
const n = t.length;
|
|
142
|
+
if (t.push(...e), n) {
|
|
143
|
+
const e = t[n - 1], r = t[n], o = l(e), c = l(r);
|
|
144
|
+
o ? c && ((t, e = 0, n = t.length - 1) => {
|
|
145
|
+
let r = e + 1;
|
|
146
|
+
for (;r <= n; ) {
|
|
147
|
+
const e = t[r - 1], o = t[r];
|
|
148
|
+
t[r - 1] = D(e, o), t.splice(r, 1), n--;
|
|
149
|
+
}
|
|
150
|
+
})(t, n - 1, n) : o || c || ((t, e = 0, n = t.length - 1) => {
|
|
151
|
+
let r = e + 1;
|
|
152
|
+
for (;r <= n; ) {
|
|
153
|
+
const e = t[r - 1], o = t[r];
|
|
154
|
+
i(e) && i(o) && O(e, o) ? (t[r - 1] = {
|
|
155
|
+
...e,
|
|
156
|
+
text: e.text + o.text
|
|
157
|
+
}, t.splice(r, 1), n--) : r++;
|
|
158
|
+
}
|
|
159
|
+
for (r = e; r <= n; ) {
|
|
160
|
+
const e = t[r];
|
|
161
|
+
i(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
|
|
162
|
+
}
|
|
163
|
+
})(t, n - 1, n);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
t.length || t.push({
|
|
167
|
+
text: ""
|
|
168
|
+
});
|
|
169
|
+
}, D = (...t) => ({
|
|
170
|
+
...t[0],
|
|
171
|
+
children: t.reduce((t, e) => (R(t, e.children), t), [])
|
|
172
|
+
}), B = (t, e, n, r = 0) => {
|
|
173
|
+
if (r < e.length) {
|
|
174
|
+
const o = e[r], c = t.children, s = c.slice();
|
|
175
|
+
return s.splice(o, 1, B(c[o], e, n, r + 1)), {
|
|
176
|
+
...t,
|
|
177
|
+
children: s
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return n;
|
|
181
|
+
}, I = (t, e, n, r) => {
|
|
182
|
+
const [o, c] = k(t, e), s = e < n ? k(t, n)[1] : c, i = a(t.children);
|
|
183
|
+
a(r) ? i || (r = D(...r).children) : i && (r = [ {
|
|
184
|
+
children: r
|
|
185
|
+
} ]);
|
|
186
|
+
const l = o.children.slice();
|
|
187
|
+
return R(l, r), R(l, s.children), {
|
|
188
|
+
...t,
|
|
189
|
+
children: l
|
|
190
|
+
};
|
|
191
|
+
}, L = (t, e) => e >= 0 && e <= d(t), P = (t, e) => e.reduce((t, e) => H(t, e), t), H = (t, e, n) => {
|
|
192
|
+
switch (e.type) {
|
|
193
|
+
case w:
|
|
194
|
+
{
|
|
195
|
+
const [n, r] = e.range;
|
|
196
|
+
if (t >= n) return r >= t ? n : t + n - r;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
case S:
|
|
201
|
+
{
|
|
202
|
+
const {at: r, text: o} = e;
|
|
203
|
+
if (n ? t > r : t >= r) return t + o.length;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
131
206
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
207
|
+
case A:
|
|
208
|
+
{
|
|
209
|
+
const {at: r, fragment: o} = e;
|
|
210
|
+
if (n ? t > r : t >= r) return t + d({
|
|
211
|
+
children: o
|
|
212
|
+
});
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return t;
|
|
217
|
+
}, N = ([t, e], n) => [ H(t, n), H(e, n) ], C = ([t, e]) => t > e ? [ e, t ] : [ t, e ], W = ([t, e]) => t === e, F = ([t, e], [n, r]) => t < r && n < e;
|
|
218
|
+
|
|
219
|
+
function* U(t, e = C(t.selection)) {
|
|
220
|
+
if (W(e)) {
|
|
221
|
+
const n = y(t.doc, e[0])?.[0];
|
|
135
222
|
n && (yield n);
|
|
136
|
-
} else for (const [n, r] of v(t.doc, e))
|
|
223
|
+
} else for (const [n, r] of v(t.doc, e)) F(e, [ r, r + d(n) ]) && (yield n);
|
|
137
224
|
}
|
|
138
225
|
|
|
139
|
-
function
|
|
226
|
+
function V(t, e = C(t.selection)) {
|
|
140
227
|
t.apply({
|
|
141
228
|
type: "delete",
|
|
142
229
|
range: e
|
|
143
230
|
});
|
|
144
231
|
}
|
|
145
232
|
|
|
146
|
-
function
|
|
233
|
+
function q(t, e, n = t.selection[0]) {
|
|
147
234
|
t.apply({
|
|
148
235
|
type: "insert_text",
|
|
149
236
|
at: n,
|
|
@@ -151,7 +238,7 @@ function R(t, e, n = t.selection[0]) {
|
|
|
151
238
|
});
|
|
152
239
|
}
|
|
153
240
|
|
|
154
|
-
function
|
|
241
|
+
function z(t, e, n = t.selection[0]) {
|
|
155
242
|
t.apply({
|
|
156
243
|
type: "insert_node",
|
|
157
244
|
at: n,
|
|
@@ -161,7 +248,7 @@ function D(t, e, n = t.selection[0]) {
|
|
|
161
248
|
});
|
|
162
249
|
}
|
|
163
250
|
|
|
164
|
-
function
|
|
251
|
+
function G(t, e, n = C(t.selection)) {
|
|
165
252
|
t.apply({
|
|
166
253
|
type: "delete",
|
|
167
254
|
range: n
|
|
@@ -172,7 +259,7 @@ function B(t, e, n = M(t.selection)) {
|
|
|
172
259
|
});
|
|
173
260
|
}
|
|
174
261
|
|
|
175
|
-
function
|
|
262
|
+
function J(t, e) {
|
|
176
263
|
t.apply({
|
|
177
264
|
type: "patch_node",
|
|
178
265
|
path: [],
|
|
@@ -181,7 +268,7 @@ function I(t, e) {
|
|
|
181
268
|
});
|
|
182
269
|
}
|
|
183
270
|
|
|
184
|
-
function
|
|
271
|
+
function Y(t, e, n, r = C(t.selection)) {
|
|
185
272
|
t.apply({
|
|
186
273
|
type: "format",
|
|
187
274
|
range: r,
|
|
@@ -190,9 +277,9 @@ function P(t, e, n, r = M(t.selection)) {
|
|
|
190
277
|
});
|
|
191
278
|
}
|
|
192
279
|
|
|
193
|
-
function
|
|
280
|
+
function X(t, e, n = C(t.selection)) {
|
|
194
281
|
let r = !1, o = !1;
|
|
195
|
-
for (const c of t.exec(
|
|
282
|
+
for (const c of t.exec(U, n)) if (i(c) && (o = !0, !c[e])) {
|
|
196
283
|
r = !0;
|
|
197
284
|
break;
|
|
198
285
|
}
|
|
@@ -204,8 +291,8 @@ function N(t, e, n = M(t.selection)) {
|
|
|
204
291
|
});
|
|
205
292
|
}
|
|
206
293
|
|
|
207
|
-
function
|
|
208
|
-
const o =
|
|
294
|
+
function Z(t, e, n, r = t.selection[0]) {
|
|
295
|
+
const o = h(t.doc, r)[2];
|
|
209
296
|
t.apply({
|
|
210
297
|
type: "patch_node",
|
|
211
298
|
path: o,
|
|
@@ -214,8 +301,8 @@ function L(t, e, n, r = t.selection[0]) {
|
|
|
214
301
|
});
|
|
215
302
|
}
|
|
216
303
|
|
|
217
|
-
function
|
|
218
|
-
const [c, , s] =
|
|
304
|
+
function j(t, e, n, r, o = t.selection[0]) {
|
|
305
|
+
const [c, , s] = h(t.doc, o);
|
|
219
306
|
t.apply({
|
|
220
307
|
type: "patch_node",
|
|
221
308
|
path: s,
|
|
@@ -224,8 +311,8 @@ function C(t, e, n, r, o = t.selection[0]) {
|
|
|
224
311
|
});
|
|
225
312
|
}
|
|
226
313
|
|
|
227
|
-
function
|
|
228
|
-
const o =
|
|
314
|
+
function K(t, e, n, r = t.selection[0]) {
|
|
315
|
+
const o = y(t.doc, r, !0);
|
|
229
316
|
o && !i(o[0]) && t.apply({
|
|
230
317
|
type: "patch_node",
|
|
231
318
|
path: o[2],
|
|
@@ -234,23 +321,23 @@ function H(t, e, n, r = t.selection[0]) {
|
|
|
234
321
|
});
|
|
235
322
|
}
|
|
236
323
|
|
|
237
|
-
var
|
|
324
|
+
var Q = t => 1 === t.nodeType, $ = t => 8 === t.nodeType, tt = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), et = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), nt = t => et.has(t.tagName), rt = (t, e) => t.compareDocumentPosition(e), ot = t => t.ownerDocument, ct = t => ot(t).getSelection(), st = (t, e) => {
|
|
238
325
|
if (t.rangeCount) {
|
|
239
326
|
const n = t.getRangeAt(0);
|
|
240
327
|
if (e.contains(n.commonAncestorContainer)) return n;
|
|
241
328
|
}
|
|
242
|
-
},
|
|
243
|
-
const [o, c] = ((t, [e, n]) => [
|
|
244
|
-
return
|
|
245
|
-
|
|
329
|
+
}, it = (t, e, n, r) => {
|
|
330
|
+
const [o, c] = ((t, [e, n]) => [ g(t, e), g(t, n) ])(n, r), s = ot(t), i = W(r), l = r[0] - r[1] > 0, a = l ? o : c, f = at(t, e, l ? c : o), u = i ? f : at(t, e, a), d = s.createRange(), [p, h] = f, [y, k] = u;
|
|
331
|
+
return Q(p) && t !== p ? h < 1 ? d.setStartBefore(p) : d.setStartAfter(p) : d.setStart(p, h),
|
|
332
|
+
Q(y) && t !== y ? k < 1 ? d.setEndBefore(y) : d.setEndAfter(y) : d.setEnd(y, k),
|
|
246
333
|
d;
|
|
247
|
-
},
|
|
248
|
-
const c =
|
|
249
|
-
if (o ||
|
|
250
|
-
const o =
|
|
334
|
+
}, lt = (t, e, n, r, o) => {
|
|
335
|
+
const c = ct(t);
|
|
336
|
+
if (o || st(c, t)) {
|
|
337
|
+
const o = it(t, e, n, r), s = r[0] - r[1] > 0;
|
|
251
338
|
c.removeAllRanges(), c.addRange(o), s && (c.collapseToEnd(), c.extend(o.startContainer, o.startOffset));
|
|
252
339
|
}
|
|
253
|
-
},
|
|
340
|
+
}, at = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
|
|
254
341
|
let i, l = 0;
|
|
255
342
|
for (;i = e(); ) if (4 === i) {
|
|
256
343
|
if (l < n.length) for (let t = n[l++]; t > 0; t--) o();
|
|
@@ -260,10 +347,10 @@ var F = t => 1 === t.nodeType, U = t => 8 === t.nodeType, V = new Map([ [ "BR",
|
|
|
260
347
|
r -= t;
|
|
261
348
|
}
|
|
262
349
|
return [ t, 0 ];
|
|
263
|
-
}, t),
|
|
350
|
+
}, t), ft = (e, n, r, o) => {
|
|
264
351
|
let c = !0;
|
|
265
352
|
if (e === r && !r.hasChildNodes()) return [ [], 0 ];
|
|
266
|
-
if (
|
|
353
|
+
if (Q(r) && r.hasChildNodes()) {
|
|
267
354
|
const e = t(o, r.childNodes.length - 1);
|
|
268
355
|
r = r.childNodes[e], c = e === o, o = 0;
|
|
269
356
|
}
|
|
@@ -280,7 +367,7 @@ var F = t => 1 === t.nodeType, U = t => 8 === t.nodeType, V = new Map([ [ "BR",
|
|
|
280
367
|
});
|
|
281
368
|
let p = 0;
|
|
282
369
|
for (;t(); ) {
|
|
283
|
-
const t =
|
|
370
|
+
const t = rt(r, a());
|
|
284
371
|
if (0 === t || 16 & t) {
|
|
285
372
|
if (c) break;
|
|
286
373
|
} else if (4 & t) break;
|
|
@@ -288,100 +375,10 @@ var F = t => 1 === t.nodeType, U = t => 8 === t.nodeType, V = new Map([ [ "BR",
|
|
|
288
375
|
}
|
|
289
376
|
return [ d, p + o ];
|
|
290
377
|
}, e);
|
|
291
|
-
},
|
|
292
|
-
const s =
|
|
293
|
-
return [ s, r === c && n === o ? s :
|
|
294
|
-
},
|
|
295
|
-
...n,
|
|
296
|
-
children: [ {
|
|
297
|
-
...e,
|
|
298
|
-
text: t
|
|
299
|
-
} ]
|
|
300
|
-
})), tt = "delete", et = "insert_text", nt = "insert_node", rt = (t, e) => {
|
|
301
|
-
const o = n(t);
|
|
302
|
-
return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
|
|
303
|
-
}, ot = (t, e) => {
|
|
304
|
-
if (e.length) {
|
|
305
|
-
const n = t.length;
|
|
306
|
-
if (t.push(...e), n) {
|
|
307
|
-
const e = t[n - 1], r = t[n], o = l(e), c = l(r);
|
|
308
|
-
o ? c && ((t, e = 0, n = t.length - 1) => {
|
|
309
|
-
let r = e + 1;
|
|
310
|
-
for (;r <= n; ) {
|
|
311
|
-
const e = t[r - 1], o = t[r];
|
|
312
|
-
t[r - 1] = ct(e, o), t.splice(r, 1), n--;
|
|
313
|
-
}
|
|
314
|
-
})(t, n - 1, n) : o || c || ((t, e = 0, n = t.length - 1) => {
|
|
315
|
-
let r = e + 1;
|
|
316
|
-
for (;r <= n; ) {
|
|
317
|
-
const e = t[r - 1], o = t[r];
|
|
318
|
-
i(e) && i(o) && rt(e, o) ? (t[r - 1] = {
|
|
319
|
-
...e,
|
|
320
|
-
text: e.text + o.text
|
|
321
|
-
}, t.splice(r, 1), n--) : r++;
|
|
322
|
-
}
|
|
323
|
-
for (r = e; r <= n; ) {
|
|
324
|
-
const e = t[r];
|
|
325
|
-
i(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
|
|
326
|
-
}
|
|
327
|
-
})(t, n - 1, n);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
t.length || t.push({
|
|
331
|
-
text: ""
|
|
332
|
-
});
|
|
333
|
-
}, ct = (...t) => ({
|
|
334
|
-
...t[0],
|
|
335
|
-
children: t.reduce((t, e) => (ot(t, e.children), t), [])
|
|
336
|
-
}), st = (t, e, n, r = 0) => {
|
|
337
|
-
if (r < e.length) {
|
|
338
|
-
const o = e[r];
|
|
339
|
-
return ((t, e, n, r) => {
|
|
340
|
-
const o = t.children.slice();
|
|
341
|
-
return o.splice(e, n - e + 1, ...r), {
|
|
342
|
-
...t,
|
|
343
|
-
children: o
|
|
344
|
-
};
|
|
345
|
-
})(t, o, o, [ st(t.children[o], e, n, r + 1) ]);
|
|
346
|
-
}
|
|
347
|
-
return n;
|
|
348
|
-
}, it = (t, e, n, r) => {
|
|
349
|
-
const [o, c] = k(t, e), s = e < n ? k(t, n)[1] : c, i = a(t.children);
|
|
350
|
-
a(r) ? i || (r = ct(...r).children) : i && (r = [ {
|
|
351
|
-
children: r
|
|
352
|
-
} ]);
|
|
353
|
-
const l = o.children.slice();
|
|
354
|
-
return ot(l, r), ot(l, s.children), {
|
|
355
|
-
...t,
|
|
356
|
-
children: l
|
|
357
|
-
};
|
|
358
|
-
}, lt = (t, e) => e >= 0 && e <= d(t), at = (t, e) => e.reduce((t, e) => ft(t, e), t), ft = (t, e) => {
|
|
359
|
-
switch (e.type) {
|
|
360
|
-
case tt:
|
|
361
|
-
{
|
|
362
|
-
const [n, r] = e.range;
|
|
363
|
-
if (t >= n) return r >= t ? n : t + n - r;
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
case et:
|
|
368
|
-
{
|
|
369
|
-
const {at: n, text: r} = e;
|
|
370
|
-
if (t >= n) return t + r.length;
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
case nt:
|
|
375
|
-
{
|
|
376
|
-
const {at: n, fragment: r} = e;
|
|
377
|
-
if (t >= n) return t + d({
|
|
378
|
-
children: r
|
|
379
|
-
});
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
return t;
|
|
384
|
-
}, ut = ([t, e], n) => [ ft(t, n), ft(e, n) ], dt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), pt = (t, e) => {
|
|
378
|
+
}, ut = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
|
|
379
|
+
const s = ft(t, e, r, n);
|
|
380
|
+
return [ s, r === c && n === o ? s : ft(t, e, c, o) ];
|
|
381
|
+
}, dt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), pt = (t, e) => {
|
|
385
382
|
const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
|
|
386
383
|
let s = !1, i = !1, l = !1, a = !1;
|
|
387
384
|
return r.forEach(t => {
|
|
@@ -410,65 +407,80 @@ var F = t => 1 === t.nodeType, U = t => 8 === t.nodeType, V = new Map([ [ "BR",
|
|
|
410
407
|
};
|
|
411
408
|
};
|
|
412
409
|
|
|
413
|
-
function
|
|
414
|
-
let e = 0,
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
410
|
+
function ht(t) {
|
|
411
|
+
let e = 0, r = 0, o = !1;
|
|
412
|
+
const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e], l = () => e > 0, a = () => e < s.length - 1, f = e => {
|
|
413
|
+
t.exec(J, e.children);
|
|
414
|
+
const r = e, o = t.doc;
|
|
415
|
+
for (const c of n(r)) "children" !== c && o[c] !== r[c] && t.apply({
|
|
416
|
+
type: "patch_node",
|
|
417
|
+
path: [],
|
|
418
|
+
key: c,
|
|
419
|
+
value: r[c]
|
|
420
|
+
});
|
|
421
|
+
for (const c of n(o)) "children" === c || c in r || t.apply({
|
|
422
|
+
type: "patch_node",
|
|
423
|
+
path: [],
|
|
424
|
+
key: c,
|
|
425
|
+
value: void 0
|
|
426
|
+
});
|
|
427
|
+
}, u = () => {
|
|
428
|
+
if (l()) {
|
|
429
|
+
const n = i()[1];
|
|
418
430
|
e--;
|
|
419
|
-
const
|
|
420
|
-
|
|
431
|
+
const r = t.doc;
|
|
432
|
+
o = !0, f(i()[0]), o = !1, r !== t.doc && (t.selection = n);
|
|
421
433
|
}
|
|
422
|
-
},
|
|
423
|
-
if (
|
|
434
|
+
}, d = () => {
|
|
435
|
+
if (a()) {
|
|
424
436
|
e++;
|
|
425
|
-
const [n,
|
|
426
|
-
|
|
437
|
+
const [n, r, c] = i(), s = t.doc;
|
|
438
|
+
o = !0, f(n), o = !1, s !== t.doc && (t.selection = [ P(r[0], c), P(r[1], c) ]);
|
|
427
439
|
}
|
|
428
440
|
};
|
|
429
|
-
t.hook("apply", (
|
|
430
|
-
if (
|
|
441
|
+
t.hook("apply", (n, i) => {
|
|
442
|
+
if (o) return;
|
|
431
443
|
const l = t.doc, a = t.selection;
|
|
432
|
-
i(
|
|
444
|
+
i(n);
|
|
433
445
|
const f = t.doc;
|
|
434
446
|
if (l !== f) {
|
|
435
|
-
const t =
|
|
436
|
-
if (0 === e || t -
|
|
447
|
+
const t = c();
|
|
448
|
+
if (0 === e || t - r >= 500) {
|
|
437
449
|
e++;
|
|
438
450
|
const t = [ l, a, [] ];
|
|
439
|
-
e >=
|
|
451
|
+
e >= s.length ? s.push(t) : s[e] = t;
|
|
440
452
|
}
|
|
441
|
-
|
|
442
|
-
|
|
453
|
+
r = t, s[e][0] = f, s[e][2].push(n), s.length > e + 1 && (s.length = e + 1), e > 500 && (e--,
|
|
454
|
+
s.shift());
|
|
443
455
|
}
|
|
444
|
-
}), t.hook("keyboard", pt("Mod+Z",
|
|
445
|
-
t.set(
|
|
446
|
-
undo:
|
|
447
|
-
redo:
|
|
448
|
-
undoable:
|
|
449
|
-
redoable:
|
|
456
|
+
}), t.hook("keyboard", pt("Mod+Z", u)), t.hook("keyboard", pt("Shift+Mod+Z", d)),
|
|
457
|
+
t.set(ht, {
|
|
458
|
+
undo: u,
|
|
459
|
+
redo: d,
|
|
460
|
+
undoable: l,
|
|
461
|
+
redoable: a
|
|
450
462
|
});
|
|
451
463
|
}
|
|
452
464
|
|
|
453
|
-
function
|
|
454
|
-
t.get(
|
|
465
|
+
function yt(t) {
|
|
466
|
+
t.get(ht).undo();
|
|
455
467
|
}
|
|
456
468
|
|
|
457
469
|
function kt(t) {
|
|
458
|
-
t.get(
|
|
470
|
+
t.get(ht).redo();
|
|
459
471
|
}
|
|
460
472
|
|
|
461
|
-
function
|
|
462
|
-
return t.get(
|
|
473
|
+
function mt(t) {
|
|
474
|
+
return t.get(ht).undoable();
|
|
463
475
|
}
|
|
464
476
|
|
|
465
|
-
function
|
|
466
|
-
return t.get(
|
|
477
|
+
function gt(t) {
|
|
478
|
+
return t.get(ht).redoable();
|
|
467
479
|
}
|
|
468
480
|
|
|
469
|
-
var
|
|
481
|
+
var _t = [], bt = () => {}, xt = t => {
|
|
470
482
|
throw Error(t);
|
|
471
|
-
}, vt = ({doc: t, readonly: e = !1, schema: n, isBlock: r =
|
|
483
|
+
}, vt = ({doc: t, readonly: e = !1, schema: n, isBlock: r = nt, onWarn: a = console.warn, onError: f = xt}) => {
|
|
472
484
|
let u = [ 0, 0 ];
|
|
473
485
|
const d = t => {
|
|
474
486
|
if (!n) return a("An unsafe operation was detected. We recommend using schema option."),
|
|
@@ -481,67 +493,67 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
481
493
|
return !1;
|
|
482
494
|
};
|
|
483
495
|
n && !d(t) && f("Invalid document");
|
|
484
|
-
const
|
|
485
|
-
const e =
|
|
486
|
-
e && (
|
|
487
|
-
|
|
496
|
+
const y = /* @__PURE__ */ new Map, k = /* @__PURE__ */ new WeakMap, g = t => y.get(t) || _t, b = /* @__PURE__ */ new Map, x = /* @__PURE__ */ new Set, v = t => {
|
|
497
|
+
const e = b.get(t);
|
|
498
|
+
e && (x.size || s(() => {
|
|
499
|
+
x.forEach(t => {
|
|
488
500
|
t();
|
|
489
|
-
}),
|
|
501
|
+
}), x.clear();
|
|
490
502
|
}), e.forEach(t => {
|
|
491
|
-
|
|
503
|
+
x.add(t);
|
|
492
504
|
}));
|
|
493
505
|
}, T = t => {
|
|
494
|
-
if (!e) if (Array.isArray(t)) for (const e of t)
|
|
495
|
-
return
|
|
496
|
-
},
|
|
497
|
-
const n = t, r =
|
|
506
|
+
if (!e) if (Array.isArray(t)) for (const e of t) O(e); else O(t);
|
|
507
|
+
return D;
|
|
508
|
+
}, O = e => {
|
|
509
|
+
const n = t, r = g("apply"), o = r.length;
|
|
498
510
|
let c = 0;
|
|
499
511
|
const s = () => {
|
|
500
512
|
if (c < o) {
|
|
501
513
|
const t = c;
|
|
502
|
-
r[c](e, f), t === c && f();
|
|
514
|
+
r[c](e, f), t === c && f(e);
|
|
503
515
|
} else if (c === o) {
|
|
504
516
|
c++;
|
|
505
517
|
try {
|
|
506
518
|
const [n, r] = ((t, e, n) => {
|
|
507
519
|
switch (n.type) {
|
|
508
|
-
case
|
|
520
|
+
case w:
|
|
509
521
|
{
|
|
510
522
|
const [r, o] = n.range;
|
|
511
|
-
|
|
523
|
+
L(t, r) && L(t, o) && r < o && (t = I(t, r, o, []), e = N(e, n));
|
|
512
524
|
break;
|
|
513
525
|
}
|
|
514
526
|
|
|
515
|
-
case
|
|
527
|
+
case S:
|
|
516
528
|
{
|
|
517
529
|
const {at: r, text: o} = n;
|
|
518
|
-
if (
|
|
519
|
-
const [c, s] =
|
|
530
|
+
if (L(t, r) && o) {
|
|
531
|
+
const [c, s] = h(t, r), l = p(c, s, !0);
|
|
520
532
|
let a;
|
|
521
533
|
if (l) {
|
|
522
534
|
const t = l[0];
|
|
523
535
|
i(t) && (a = t);
|
|
524
536
|
}
|
|
525
|
-
t =
|
|
537
|
+
t = I(t, r, r, M(o, a, c)), e = N(e, n);
|
|
526
538
|
}
|
|
527
539
|
break;
|
|
528
540
|
}
|
|
529
541
|
|
|
530
|
-
case
|
|
542
|
+
case A:
|
|
531
543
|
{
|
|
532
544
|
const {at: r, fragment: o} = n;
|
|
533
|
-
|
|
545
|
+
L(t, r) && o.length && (t = I(t, r, r, o), e = N(e, n));
|
|
534
546
|
break;
|
|
535
547
|
}
|
|
536
548
|
|
|
537
549
|
case "format":
|
|
538
550
|
{
|
|
539
551
|
const {range: [e, r], key: o, value: c} = n;
|
|
540
|
-
if (
|
|
541
|
-
const [{children: n}, , r] =
|
|
552
|
+
if (L(t, e) && L(t, r) && e <= r) if (e === r) {
|
|
553
|
+
const [{children: n}, , r] = h(t, e);
|
|
542
554
|
if (1 === n.length) {
|
|
543
555
|
const e = n[0];
|
|
544
|
-
i(e) && !e.text && (t =
|
|
556
|
+
i(e) && !e.text && (t = B(t, [ ...r, 0 ], {
|
|
545
557
|
...e,
|
|
546
558
|
[o]: c
|
|
547
559
|
}));
|
|
@@ -554,7 +566,7 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
554
566
|
...t,
|
|
555
567
|
[o]: c
|
|
556
568
|
} : t;
|
|
557
|
-
t =
|
|
569
|
+
t = I(t, e, r, E(t, e, r).map(n));
|
|
558
570
|
}
|
|
559
571
|
break;
|
|
560
572
|
}
|
|
@@ -565,7 +577,7 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
565
577
|
for (let n = 0; n < e.length; n++) t = t.children[e[n]];
|
|
566
578
|
return t;
|
|
567
579
|
})(t, e);
|
|
568
|
-
c && (t =
|
|
580
|
+
c && (t = B(t, e, {
|
|
569
581
|
...c,
|
|
570
582
|
[r]: o
|
|
571
583
|
}));
|
|
@@ -574,19 +586,19 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
574
586
|
}
|
|
575
587
|
return [ t, e ];
|
|
576
588
|
})(t, u, e);
|
|
577
|
-
(({type: t}) => t !==
|
|
589
|
+
(({type: t}) => t !== S && t !== w)(e) && !d(n) || (t = n, R(r));
|
|
578
590
|
} catch (n) {
|
|
579
591
|
a("rollback operation: " + n);
|
|
580
592
|
}
|
|
581
593
|
}
|
|
582
594
|
}, f = t => {
|
|
583
|
-
t
|
|
595
|
+
null != t ? (e = t, c++, s()) : c = o + 1;
|
|
584
596
|
};
|
|
585
597
|
s(), n !== t && v("change");
|
|
586
|
-
},
|
|
587
|
-
!((t, [e, n]) =>
|
|
598
|
+
}, R = e => {
|
|
599
|
+
!((t, [e, n]) => L(t, e) && L(t, n))(t, e) || u[0] === e[0] && u[1] === e[1] || (u = e,
|
|
588
600
|
v("selectionchange"));
|
|
589
|
-
},
|
|
601
|
+
}, D = {
|
|
590
602
|
get doc() {
|
|
591
603
|
return t;
|
|
592
604
|
},
|
|
@@ -594,7 +606,7 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
594
606
|
return u;
|
|
595
607
|
},
|
|
596
608
|
set selection(t) {
|
|
597
|
-
|
|
609
|
+
R(t);
|
|
598
610
|
},
|
|
599
611
|
get readonly() {
|
|
600
612
|
return e;
|
|
@@ -604,41 +616,41 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
604
616
|
},
|
|
605
617
|
apply: T,
|
|
606
618
|
on: (t, e) => {
|
|
607
|
-
let n =
|
|
608
|
-
return n ||
|
|
619
|
+
let n = b.get(t);
|
|
620
|
+
return n || b.set(t, n = /* @__PURE__ */ new Set), n.add(e), () => {
|
|
609
621
|
n.delete(e);
|
|
610
622
|
};
|
|
611
623
|
},
|
|
612
624
|
hook: (t, e) => {
|
|
613
|
-
let n =
|
|
614
|
-
return n ||
|
|
625
|
+
let n = y.get(t);
|
|
626
|
+
return n || y.set(t, n = []), n.push(e), () => {
|
|
615
627
|
const t = n.indexOf(e);
|
|
616
628
|
-1 !== t && n.splice(t, 1);
|
|
617
629
|
};
|
|
618
630
|
},
|
|
619
631
|
exec: (t, ...e) => {
|
|
620
|
-
const n = t(
|
|
621
|
-
return void 0 === n ?
|
|
632
|
+
const n = t(D, ...e);
|
|
633
|
+
return void 0 === n ? D : n;
|
|
622
634
|
},
|
|
623
635
|
get: t => (k.has(t) || f("No value found for key"), k.get(t)),
|
|
624
|
-
set: (t, e) => (k.set(t, e),
|
|
636
|
+
set: (t, e) => (k.set(t, e), D),
|
|
625
637
|
input: n => {
|
|
626
638
|
if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return a("beforeinput event is not supported."),
|
|
627
|
-
|
|
639
|
+
bt;
|
|
628
640
|
const {contentEditable: s, role: i, ariaMultiLine: l, ariaReadOnly: f} = n, d = n.style.whiteSpace;
|
|
629
641
|
n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
|
|
630
|
-
let p = !1,
|
|
631
|
-
const E =
|
|
642
|
+
let p = !1, h = null, y = !1, k = !1, b = !1, x = u, v = null;
|
|
643
|
+
const E = ot(n), M = ((t, e) => {
|
|
632
644
|
let n = null, r = null, o = null;
|
|
633
645
|
const c = () => {
|
|
634
646
|
if (null != o) return o;
|
|
635
647
|
if (r) if ((t => 3 === t.nodeType)(r)) {
|
|
636
648
|
const t = r.data;
|
|
637
649
|
if (t) return o = "\n" === t ? i() ? 3 : 5 : 1;
|
|
638
|
-
} else if (
|
|
650
|
+
} else if (Q(r)) {
|
|
639
651
|
if ("false" === r.contentEditable) return o = 2;
|
|
640
652
|
{
|
|
641
|
-
const t =
|
|
653
|
+
const t = tt.get(r.tagName);
|
|
642
654
|
if (null != t) return o = 1 === t ? i() ? 3 : 5 : 3 === t ? 2 : 6;
|
|
643
655
|
if (e(r)) return o = 4;
|
|
644
656
|
}
|
|
@@ -695,29 +707,29 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
695
707
|
}
|
|
696
708
|
};
|
|
697
709
|
return a;
|
|
698
|
-
})(E, r),
|
|
710
|
+
})(E, r), w = () => {
|
|
699
711
|
n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
|
|
700
712
|
};
|
|
701
|
-
|
|
702
|
-
const
|
|
713
|
+
w();
|
|
714
|
+
const S = () => {
|
|
703
715
|
k || n.focus({
|
|
704
716
|
preventScroll: !0
|
|
705
717
|
});
|
|
706
|
-
},
|
|
707
|
-
v = null, u[0] ===
|
|
708
|
-
},
|
|
718
|
+
}, A = () => {
|
|
719
|
+
v = null, u[0] === x[0] && u[1] === x[1] || (lt(n, M, t, u), x = u);
|
|
720
|
+
}, O = () => {
|
|
709
721
|
null != v && clearTimeout(v);
|
|
710
|
-
},
|
|
711
|
-
k || requestAnimationFrame(
|
|
712
|
-
}),
|
|
713
|
-
u[0] ===
|
|
714
|
-
}), L =
|
|
715
|
-
for (const e of
|
|
722
|
+
}, B = D.on("change", () => {
|
|
723
|
+
k || requestAnimationFrame(S);
|
|
724
|
+
}), I = D.on("selectionchange", () => {
|
|
725
|
+
u[0] === x[0] && u[1] === x[1] || (O(), v = setTimeout(A, 50));
|
|
726
|
+
}), L = D.on("readonly", w), H = t => {
|
|
727
|
+
for (const e of g("paste")) {
|
|
716
728
|
const n = e(t);
|
|
717
729
|
if (n) return n;
|
|
718
730
|
}
|
|
719
731
|
a("failed to serialize pasted data");
|
|
720
|
-
},
|
|
732
|
+
}, N = ((t, e) => {
|
|
721
733
|
let n = !1, r = [];
|
|
722
734
|
const o = t => {
|
|
723
735
|
n && r.push(...t);
|
|
@@ -754,28 +766,28 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
754
766
|
}
|
|
755
767
|
};
|
|
756
768
|
})(n, () => {
|
|
757
|
-
|
|
758
|
-
}),
|
|
759
|
-
|
|
760
|
-
const n =
|
|
769
|
+
O(), lt(n, M, t, u);
|
|
770
|
+
}), F = () => {
|
|
771
|
+
R(x = _(t, ((t, e) => {
|
|
772
|
+
const n = ct(t), r = st(n, t);
|
|
761
773
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
762
|
-
const o =
|
|
774
|
+
const o = ut(t, e, r), c = rt(n.anchorNode, n.focusNode);
|
|
763
775
|
return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
|
|
764
|
-
})(n,
|
|
765
|
-
},
|
|
766
|
-
const e =
|
|
767
|
-
|
|
768
|
-
E.addEventListener("selectionchange",
|
|
769
|
-
},
|
|
770
|
-
if (!
|
|
771
|
-
},
|
|
772
|
-
|
|
773
|
-
},
|
|
776
|
+
})(n, M)));
|
|
777
|
+
}, U = () => {
|
|
778
|
+
const e = N.v();
|
|
779
|
+
N._(!1), e.length && (N.m(e), E.removeEventListener("selectionchange", Z), lt(n, M, t, u, !0),
|
|
780
|
+
E.addEventListener("selectionchange", Z)), h && (R(h[1]), T(h[0]), h = null), y = !1;
|
|
781
|
+
}, V = t => {
|
|
782
|
+
if (!y) for (const e of g("keyboard")) if (e(t)) return t.preventDefault(), void N._(!1);
|
|
783
|
+
}, q = () => {
|
|
784
|
+
y || U();
|
|
785
|
+
}, z = e => {
|
|
774
786
|
e.preventDefault();
|
|
775
787
|
const r = e.inputType;
|
|
776
788
|
if (r.startsWith("format")) return;
|
|
777
789
|
if ("historyUndo" === r || "historyRedo" === r) return;
|
|
778
|
-
|
|
790
|
+
y ? N._(!0) : F();
|
|
779
791
|
const o = e.getTargetRanges()[0];
|
|
780
792
|
if (o) {
|
|
781
793
|
let c = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
|
|
@@ -783,9 +795,9 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
783
795
|
const t = e.dataTransfer;
|
|
784
796
|
t && (c = t.getData("text/plain"));
|
|
785
797
|
}
|
|
786
|
-
|
|
787
|
-
const s =
|
|
788
|
-
|
|
798
|
+
h || (h = [ [], u ]);
|
|
799
|
+
const s = h[0], i = _(t, ut(n, M, o));
|
|
800
|
+
W(i) || s.push({
|
|
789
801
|
type: "delete",
|
|
790
802
|
range: i
|
|
791
803
|
}), c && s.push({
|
|
@@ -794,31 +806,31 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
794
806
|
text: c
|
|
795
807
|
});
|
|
796
808
|
}
|
|
797
|
-
|
|
798
|
-
},
|
|
799
|
-
|
|
800
|
-
},
|
|
801
|
-
|
|
802
|
-
},
|
|
803
|
-
k = !0,
|
|
804
|
-
},
|
|
809
|
+
y || U();
|
|
810
|
+
}, G = () => {
|
|
811
|
+
y || F(), y = !0;
|
|
812
|
+
}, J = () => {
|
|
813
|
+
U();
|
|
814
|
+
}, Y = () => {
|
|
815
|
+
k = !0, F();
|
|
816
|
+
}, X = () => {
|
|
805
817
|
k = !1;
|
|
806
|
-
},
|
|
807
|
-
!k ||
|
|
808
|
-
},
|
|
809
|
-
if (
|
|
810
|
-
},
|
|
811
|
-
t.preventDefault(),
|
|
812
|
-
},
|
|
813
|
-
t.preventDefault(), e || (
|
|
818
|
+
}, Z = () => {
|
|
819
|
+
!k || y || b || F();
|
|
820
|
+
}, j = t => {
|
|
821
|
+
if (F(), !W(u)) for (const e of g("copy")) e(t);
|
|
822
|
+
}, K = t => {
|
|
823
|
+
t.preventDefault(), j(t.clipboardData);
|
|
824
|
+
}, $ = t => {
|
|
825
|
+
t.preventDefault(), e || (j(t.clipboardData), T({
|
|
814
826
|
type: "delete",
|
|
815
|
-
range:
|
|
827
|
+
range: C(u)
|
|
816
828
|
}));
|
|
817
|
-
},
|
|
829
|
+
}, et = t => {
|
|
818
830
|
t.preventDefault();
|
|
819
|
-
const e =
|
|
831
|
+
const e = H(t.clipboardData);
|
|
820
832
|
if (e) {
|
|
821
|
-
const t =
|
|
833
|
+
const t = C(u), n = t[0], r = [ {
|
|
822
834
|
type: "delete",
|
|
823
835
|
range: t
|
|
824
836
|
} ];
|
|
@@ -832,28 +844,28 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
832
844
|
fragment: e
|
|
833
845
|
}), T(r);
|
|
834
846
|
}
|
|
835
|
-
},
|
|
847
|
+
}, nt = e => {
|
|
836
848
|
e.preventDefault();
|
|
837
849
|
const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}) => {
|
|
838
|
-
const o =
|
|
850
|
+
const o = ot(t);
|
|
839
851
|
if (o.caretPositionFromPoint) {
|
|
840
852
|
const c = o.caretPositionFromPoint(n, r);
|
|
841
|
-
if (c) return
|
|
853
|
+
if (c) return ft(t, e, c.offsetNode, c.offset);
|
|
842
854
|
} else if (o.caretRangeFromPoint) {
|
|
843
855
|
const c = o.caretRangeFromPoint(n, r);
|
|
844
|
-
if (c) return
|
|
856
|
+
if (c) return ft(t, e, c.startContainer, c.startOffset);
|
|
845
857
|
}
|
|
846
|
-
})(n,
|
|
858
|
+
})(n, M, e);
|
|
847
859
|
if (r && c) {
|
|
848
860
|
let e;
|
|
849
861
|
const n = [];
|
|
850
|
-
|
|
862
|
+
b && n.push({
|
|
851
863
|
type: "delete",
|
|
852
|
-
range:
|
|
864
|
+
range: C(u)
|
|
853
865
|
});
|
|
854
|
-
const s =
|
|
866
|
+
const s = H(r);
|
|
855
867
|
if (s) {
|
|
856
|
-
const r =
|
|
868
|
+
const r = m(t, c), i = P(r, n);
|
|
857
869
|
n.push(o(s) ? {
|
|
858
870
|
type: "insert_text",
|
|
859
871
|
at: i,
|
|
@@ -862,39 +874,39 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
862
874
|
type: "insert_node",
|
|
863
875
|
at: i,
|
|
864
876
|
fragment: s
|
|
865
|
-
}), e = [ i,
|
|
877
|
+
}), e = [ i, P(r, n) ];
|
|
866
878
|
}
|
|
867
|
-
T(n), e &&
|
|
879
|
+
T(n), e && R(e);
|
|
868
880
|
}
|
|
869
|
-
|
|
870
|
-
},
|
|
871
|
-
|
|
872
|
-
},
|
|
873
|
-
|
|
881
|
+
b = !1;
|
|
882
|
+
}, it = t => {
|
|
883
|
+
b = !0, j(t.dataTransfer);
|
|
884
|
+
}, at = () => {
|
|
885
|
+
b = !1;
|
|
874
886
|
};
|
|
875
|
-
E.addEventListener("selectionchange",
|
|
876
|
-
n.addEventListener("beforeinput",
|
|
877
|
-
n.addEventListener("compositionend",
|
|
878
|
-
n.addEventListener("copy",
|
|
879
|
-
n.addEventListener("drop",
|
|
887
|
+
E.addEventListener("selectionchange", Z), n.addEventListener("keydown", V), n.addEventListener("input", q),
|
|
888
|
+
n.addEventListener("beforeinput", z), n.addEventListener("compositionstart", G),
|
|
889
|
+
n.addEventListener("compositionend", J), n.addEventListener("focus", Y), n.addEventListener("blur", X),
|
|
890
|
+
n.addEventListener("copy", K), n.addEventListener("cut", $), n.addEventListener("paste", et),
|
|
891
|
+
n.addEventListener("drop", nt), n.addEventListener("dragstart", it), n.addEventListener("dragend", at);
|
|
880
892
|
const dt = [];
|
|
881
|
-
return
|
|
882
|
-
const e = t(n,
|
|
893
|
+
return g("mount").forEach(t => {
|
|
894
|
+
const e = t(n, M);
|
|
883
895
|
e && dt.push(e);
|
|
884
896
|
}), () => {
|
|
885
|
-
p || (p = !0,
|
|
886
|
-
n.ariaReadOnly = f, n.style.whiteSpace = d,
|
|
887
|
-
n.removeEventListener("keydown",
|
|
888
|
-
n.removeEventListener("compositionstart",
|
|
889
|
-
n.removeEventListener("focus",
|
|
890
|
-
n.removeEventListener("cut",
|
|
891
|
-
n.removeEventListener("dragstart",
|
|
897
|
+
p || (p = !0, B(), I(), L(), n.contentEditable = s, n.role = i, n.ariaMultiLine = l,
|
|
898
|
+
n.ariaReadOnly = f, n.style.whiteSpace = d, N.T(), E.removeEventListener("selectionchange", Z),
|
|
899
|
+
n.removeEventListener("keydown", V), n.removeEventListener("input", q), n.removeEventListener("beforeinput", z),
|
|
900
|
+
n.removeEventListener("compositionstart", G), n.removeEventListener("compositionend", J),
|
|
901
|
+
n.removeEventListener("focus", Y), n.removeEventListener("blur", X), n.removeEventListener("copy", K),
|
|
902
|
+
n.removeEventListener("cut", $), n.removeEventListener("paste", et), n.removeEventListener("drop", nt),
|
|
903
|
+
n.removeEventListener("dragstart", it), n.removeEventListener("dragend", at), dt.forEach(t => {
|
|
892
904
|
t();
|
|
893
905
|
}));
|
|
894
906
|
};
|
|
895
907
|
}
|
|
896
908
|
};
|
|
897
|
-
return
|
|
909
|
+
return D.exec(ht), D;
|
|
898
910
|
}, Tt = (t, e) => {
|
|
899
911
|
t.hook("paste", t => {
|
|
900
912
|
for (const n of t.items) if ("file" === n.kind) {
|
|
@@ -913,7 +925,7 @@ var xt = [], _t = () => {}, bt = t => {
|
|
|
913
925
|
function Et(t, e) {
|
|
914
926
|
const n = e && e.voidToString;
|
|
915
927
|
t.hook("copy", e => {
|
|
916
|
-
e.setData("text/plain", T(t.doc, ...
|
|
928
|
+
e.setData("text/plain", T(t.doc, ...C(t.selection), n));
|
|
917
929
|
}), t.hook("paste", t => t.getData("text/plain"));
|
|
918
930
|
}
|
|
919
931
|
|
|
@@ -921,7 +933,7 @@ function Mt(t, e) {
|
|
|
921
933
|
t.hook("mount", (n, r) => {
|
|
922
934
|
const o = t.hook("copy", t => {
|
|
923
935
|
const e = document.createElement("div");
|
|
924
|
-
e.appendChild(
|
|
936
|
+
e.appendChild(st(ct(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
|
|
925
937
|
}), c = t.hook("paste", t => {
|
|
926
938
|
const n = t.getData("text/html");
|
|
927
939
|
return n ? ((t, e, n) => {
|
|
@@ -933,7 +945,7 @@ function Mt(t, e) {
|
|
|
933
945
|
}
|
|
934
946
|
};
|
|
935
947
|
let c = (new DOMParser).parseFromString(t, "text/html").body, s = !1;
|
|
936
|
-
for (const i of [ ...c.childNodes ])
|
|
948
|
+
for (const i of [ ...c.childNodes ]) $(i) ? "StartFragment" === i.data ? (s = !0,
|
|
937
949
|
c = new DocumentFragment) : "EndFragment" === i.data && (s = !1) : s && c.appendChild(i);
|
|
938
950
|
return e(({t, i: e}) => {
|
|
939
951
|
let n, c = null, s = "", i = !1;
|
|
@@ -961,21 +973,78 @@ function Mt(t, e) {
|
|
|
961
973
|
});
|
|
962
974
|
}
|
|
963
975
|
|
|
964
|
-
var
|
|
976
|
+
var wt = "application/x-editate-editor";
|
|
965
977
|
|
|
966
|
-
function
|
|
978
|
+
function St(t) {
|
|
967
979
|
t.hook("copy", e => {
|
|
968
|
-
e.setData(
|
|
980
|
+
e.setData(wt, JSON.stringify(E(t.doc, ...C(t.selection))));
|
|
969
981
|
}), t.hook("paste", t => {
|
|
970
982
|
try {
|
|
971
|
-
return JSON.parse(t.getData(
|
|
983
|
+
return JSON.parse(t.getData(wt));
|
|
972
984
|
} catch (e) {
|
|
973
985
|
return null;
|
|
974
986
|
}
|
|
975
987
|
});
|
|
976
988
|
}
|
|
977
989
|
|
|
978
|
-
function At(t) {
|
|
990
|
+
function At(t, e) {
|
|
991
|
+
const n = e.isLocked, r = e => n(h(t.doc, e)[0]), o = (e, r) => {
|
|
992
|
+
const [o, c] = e;
|
|
993
|
+
for (const [s, i] of x(t.doc, e)) {
|
|
994
|
+
const t = i + d(s);
|
|
995
|
+
if ((r ? c >= i && o <= t : c > i && o < t) && n(s)) return !0;
|
|
996
|
+
}
|
|
997
|
+
return !1;
|
|
998
|
+
};
|
|
999
|
+
let c = !1;
|
|
1000
|
+
t.hook("apply", (e, i) => {
|
|
1001
|
+
const a = c;
|
|
1002
|
+
switch (c = !1, e.type) {
|
|
1003
|
+
case "delete":
|
|
1004
|
+
if (o(C(e.range), !0)) return c = !0, s(() => {
|
|
1005
|
+
c = !1;
|
|
1006
|
+
}), i(null);
|
|
1007
|
+
break;
|
|
1008
|
+
|
|
1009
|
+
case "insert_text":
|
|
1010
|
+
case "insert_node":
|
|
1011
|
+
if (a || r(e.at)) return i(null);
|
|
1012
|
+
break;
|
|
1013
|
+
|
|
1014
|
+
case "format":
|
|
1015
|
+
{
|
|
1016
|
+
const t = C(e.range);
|
|
1017
|
+
if (W(t) ? r(t[0]) : o(t, !1)) return i(null);
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
case "patch_node":
|
|
1022
|
+
{
|
|
1023
|
+
const r = e.path;
|
|
1024
|
+
let o = t.doc;
|
|
1025
|
+
for (let t = 0; t < r.length; t++) {
|
|
1026
|
+
const e = o.children?.[r[t]];
|
|
1027
|
+
if (!e) break;
|
|
1028
|
+
if (o = e, t < r.length - 1 && l(o) && n(o)) return i(null);
|
|
1029
|
+
}
|
|
1030
|
+
if (o !== t.doc && l(o) && n(o) && n({
|
|
1031
|
+
...o,
|
|
1032
|
+
[e.key]: e.value
|
|
1033
|
+
})) return i(null);
|
|
1034
|
+
break;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
i(e);
|
|
1038
|
+
}), t.set(At, {
|
|
1039
|
+
locked: t => W(t) ? r(t[0]) : o(t, !0)
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function Ot(t, e = C(t.selection)) {
|
|
1044
|
+
return t.get(At).locked(e);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function Rt(t) {
|
|
979
1048
|
t.hook("apply", t => {
|
|
980
1049
|
console.log("apply", t);
|
|
981
1050
|
}), t.on("change", () => {
|
|
@@ -985,21 +1054,71 @@ function At(t) {
|
|
|
985
1054
|
});
|
|
986
1055
|
}
|
|
987
1056
|
|
|
988
|
-
function
|
|
1057
|
+
function Dt(t, e) {
|
|
989
1058
|
n(e).forEach(n => {
|
|
990
1059
|
const r = e[n];
|
|
991
1060
|
t.hook("keyboard", pt(n, r));
|
|
992
1061
|
});
|
|
993
1062
|
}
|
|
994
1063
|
|
|
995
|
-
|
|
1064
|
+
var Bt = (t, e) => {
|
|
1065
|
+
const n = parseFloat(t);
|
|
1066
|
+
return n ? t.endsWith("%") ? n / 100 * e : n : 0;
|
|
1067
|
+
}, It = (t, e, n, r) => [ t + Bt(n, e), t + e - Bt(r, e) ], Lt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, Pt = (t, e, n) => Math.max(-e, Math.min(t, n - e)), Ht = t => {
|
|
1068
|
+
const e = "auto";
|
|
1069
|
+
t.hook("mount", (n, r) => {
|
|
1070
|
+
const o = ot(n), c = o.defaultView, s = ((t, e, n) => {
|
|
1071
|
+
const {body: r, documentElement: o} = e;
|
|
1072
|
+
let c = t;
|
|
1073
|
+
for (;c && c !== r && c !== o; ) {
|
|
1074
|
+
const {overflowY: t} = n.getComputedStyle(c);
|
|
1075
|
+
if ("auto" === t || "scroll" === t || "overlay" === t) return c;
|
|
1076
|
+
c = c.parentElement;
|
|
1077
|
+
}
|
|
1078
|
+
return null;
|
|
1079
|
+
})(n, o, c);
|
|
1080
|
+
let i = null;
|
|
1081
|
+
const l = t.on("change", () => {
|
|
1082
|
+
null == i && (i = setTimeout(() => {
|
|
1083
|
+
i = null;
|
|
1084
|
+
const o = it(n, r, t.doc, t.selection);
|
|
1085
|
+
let l = o.getBoundingClientRect();
|
|
1086
|
+
if (!l.height) {
|
|
1087
|
+
const t = o.startContainer, e = Q(t) ? t : t.parentElement;
|
|
1088
|
+
e && (l = e.getBoundingClientRect());
|
|
1089
|
+
}
|
|
1090
|
+
const a = s ? ((t, e, n, r) => {
|
|
1091
|
+
const {scrollLeft: o, scrollTop: c, scrollWidth: s, scrollHeight: i, clientLeft: l, clientTop: a, clientWidth: f, clientHeight: u} = e, d = e.getBoundingClientRect(), p = t.getComputedStyle(e), h = Pt(Lt(n.top, n.bottom, It(d.top + a, u, p.scrollPaddingTop, p.scrollPaddingBottom)), c, i - u), y = Pt(Lt(n.left, n.right, It(d.left + l, f, p.scrollPaddingLeft, p.scrollPaddingRight)), o, s - f);
|
|
1092
|
+
return (h || y) && e.scrollBy({
|
|
1093
|
+
top: h,
|
|
1094
|
+
left: y,
|
|
1095
|
+
behavior: r
|
|
1096
|
+
}), [ y, h ];
|
|
1097
|
+
})(c, s, l, e) : [ 0, 0 ];
|
|
1098
|
+
((t, e, [n, r], o) => {
|
|
1099
|
+
const {documentElement: c} = t.document, {clientWidth: s, clientHeight: i} = c, l = t.getComputedStyle(c), a = Lt(e.top - r, e.bottom - r, It(0, i, l.scrollPaddingTop, l.scrollPaddingBottom)), f = Lt(e.left - n, e.right - n, It(0, s, l.scrollPaddingLeft, l.scrollPaddingRight));
|
|
1100
|
+
(a || f) && t.scrollBy({
|
|
1101
|
+
top: a,
|
|
1102
|
+
left: f,
|
|
1103
|
+
behavior: o
|
|
1104
|
+
});
|
|
1105
|
+
})(c, l, a, e);
|
|
1106
|
+
}, 50));
|
|
1107
|
+
});
|
|
1108
|
+
return () => {
|
|
1109
|
+
null != i && clearTimeout(i), l();
|
|
1110
|
+
};
|
|
1111
|
+
});
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
function Nt(t, e) {
|
|
996
1115
|
t.hook("mount", (n, r) => {
|
|
997
1116
|
let o = !0, c = !1;
|
|
998
1117
|
const s = t.on("selectionchange", () => {
|
|
999
1118
|
c || (c = !0, requestAnimationFrame(() => {
|
|
1000
1119
|
c = !1, o && e(() => {
|
|
1001
1120
|
const e = t.selection;
|
|
1002
|
-
return
|
|
1121
|
+
return it(n, r, t.doc, e).getBoundingClientRect();
|
|
1003
1122
|
});
|
|
1004
1123
|
}));
|
|
1005
1124
|
});
|
|
@@ -1009,7 +1128,7 @@ function Rt(t, e) {
|
|
|
1009
1128
|
});
|
|
1010
1129
|
}
|
|
1011
1130
|
|
|
1012
|
-
function
|
|
1131
|
+
function Ct(t) {
|
|
1013
1132
|
t.hook("mount", t => {
|
|
1014
1133
|
t.ariaMultiLine = null;
|
|
1015
1134
|
}), t.hook("apply", (t, e) => {
|
|
@@ -1020,24 +1139,24 @@ function Dt(t) {
|
|
|
1020
1139
|
const e = t.fragment;
|
|
1021
1140
|
t = {
|
|
1022
1141
|
...t,
|
|
1023
|
-
fragment: a(e) ? [
|
|
1142
|
+
fragment: a(e) ? [ D(...e) ] : e
|
|
1024
1143
|
};
|
|
1025
1144
|
}
|
|
1026
1145
|
e(t);
|
|
1027
1146
|
});
|
|
1028
1147
|
}
|
|
1029
1148
|
|
|
1030
|
-
var
|
|
1149
|
+
var Wt = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
1031
1150
|
const o = vt({
|
|
1032
1151
|
...r,
|
|
1033
1152
|
doc: {
|
|
1034
|
-
children:
|
|
1153
|
+
children: M(t)
|
|
1035
1154
|
}
|
|
1036
1155
|
}).exec(Et);
|
|
1037
|
-
return e && o.exec(
|
|
1156
|
+
return e && o.exec(Ct), o.on("change", () => {
|
|
1038
1157
|
n(T(o.doc));
|
|
1039
1158
|
}), o;
|
|
1040
1159
|
};
|
|
1041
1160
|
|
|
1042
|
-
export {
|
|
1161
|
+
export { V as Delete, Y as Format, z as InsertNode, q as InsertText, U as LeavesInRange, Ot as LockedInRange, kt as Redo, gt as Redoable, J as ReplaceDoc, G as ReplaceText, Z as SetBlockAttr, K as SetVoidAttr, j as ToggleBlockAttr, X as ToggleFormat, yt as Undo, mt as Undoable, At as blockLockPlugin, vt as createEditor, Wt as createPlainEditor, Rt as debugPlugin, Tt as fileTransferPlugin, p as getChildAt, y as getLeafAt, h as getLeafBlockAt, d as getNodeSize, Mt as htmlTransferPlugin, St as internalTranferPlugin, x as iterLeafBlocks, v as iterLeaves, Dt as keymapPlugin, H as mapPosition, Et as plainTransferPlugin, Ht as scrollToSelectionPlugin, Nt as selectionRectPlugin, Ct as singlelinePlugin, T as sliceText };
|
|
1043
1162
|
//# sourceMappingURL=index.js.map
|