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