editate 0.6.5 → 0.6.6

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