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