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