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