editate 0.6.3 → 0.6.5

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.js CHANGED
@@ -30,9 +30,9 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
30
30
  for (const n of e) r += x(t, 0, n), 0 !== n && r++, t = t.children[n];
31
31
  return r + n;
32
32
  }, v = (t, e) => {
33
- const n = I(t, e);
33
+ const n = A(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) ], E = (t, e = 0, n = t.length - 1) => {
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) => {
36
36
  let r = e + 1;
37
37
  for (;r <= n; ) {
38
38
  const e = t[r - 1], o = t[r];
@@ -45,21 +45,21 @@ 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
- }, S = (t, e = 0, n = t.length - 1) => {
48
+ }, E = (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] = O(e, o), t.splice(r, 1), n--;
52
+ t[r - 1] = D(e, o), t.splice(r, 1), n--;
53
53
  }
54
- }, D = (t, e, n) => {
54
+ }, O = (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
- }, O = (...t) => ({
59
+ }, D = (...t) => ({
60
60
  ...t[0],
61
- children: t.reduce((t, e) => (D(t, e.children, E), t), [])
62
- }), A = ({children: t}, e) => {
61
+ children: t.reduce((t, e) => (O(t, e.children, S), t), [])
62
+ }), P = ({children: t}, e) => {
63
63
  const n = t.length;
64
64
  for (let r = 0; r < n; r++) {
65
65
  const n = t[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
- }, I = (t, e) => {
75
+ }, A = (t, e) => {
76
76
  const n = [];
77
77
  for (;t; ) {
78
- const r = A(t, e);
78
+ const r = P(t, e);
79
79
  if (!r) break;
80
80
  const o = r.i;
81
81
  if (!g(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
- }, P = (t, e) => {
90
- const n = t.children, r = A(t, e);
89
+ }, I = (t, e) => {
90
+ const n = t.children, r = P(t, e);
91
91
  if (r) {
92
92
  const {i: e, o, l: c} = r;
93
93
  if (g(e)) {
94
- const [r, s] = P(e, o), i = n.slice(0, c), a = n.slice(c + 1);
94
+ const [r, s] = I(e, o), i = n.slice(0, c), a = n.slice(c + 1);
95
95
  return i.push(r), a.unshift(s), [ {
96
96
  ...t,
97
97
  children: i
@@ -141,13 +141,13 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
141
141
  })(t, o, o, [ C(t.children[o], e, n, r + 1) ]);
142
142
  }
143
143
  return n;
144
- }, H = (t, e, n, r) => {
145
- const [o, c] = P(t, e), s = e < n ? P(t, n)[1] : c, i = o.children.slice();
146
- return D(i, r, S), D(i, s.children, S), {
144
+ }, R = (t, e, n, r) => {
145
+ const [o, c] = I(t, e), s = e < n ? I(t, n)[1] : c, i = o.children.slice();
146
+ return O(i, r, E), O(i, s.children, E), {
147
147
  ...t,
148
148
  children: i
149
149
  };
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) => {
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) => {
151
151
  switch (e.type) {
152
152
  case f:
153
153
  {
@@ -173,7 +173,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
173
173
  }
174
174
  }
175
175
  return t;
176
- }, N = ([t, e], n) => [ L(t, n), L(e, n) ];
176
+ }, N = ([t, e], n) => [ B(t, n), B(e, n) ];
177
177
 
178
178
  function V(e, n = t(e.selection)) {
179
179
  e.apply({
@@ -190,7 +190,7 @@ function F(t, e, n = t.selection[0]) {
190
190
  });
191
191
  }
192
192
 
193
- function W(t, e, n = t.selection[0]) {
193
+ function U(t, e, n = t.selection[0]) {
194
194
  t.apply({
195
195
  type: "insert_node",
196
196
  at: n,
@@ -200,7 +200,7 @@ function W(t, e, n = t.selection[0]) {
200
200
  });
201
201
  }
202
202
 
203
- function q(e, n) {
203
+ function W(e, n) {
204
204
  const r = t(e.selection);
205
205
  e.apply({
206
206
  type: "delete",
@@ -212,18 +212,16 @@ function q(e, n) {
212
212
  });
213
213
  }
214
214
 
215
- function J(t, e) {
215
+ function q(t, e) {
216
216
  t.apply({
217
- type: "delete",
218
- range: [ 0, b(t.doc) ]
219
- }).apply({
220
- type: "insert_node",
221
- at: 0,
222
- fragment: e
217
+ type: "set_node_attr",
218
+ path: [],
219
+ key: "children",
220
+ value: e
223
221
  });
224
222
  }
225
223
 
226
- function U(e, n, r, o = t(e.selection)) {
224
+ function G(e, n, r, o = t(e.selection)) {
227
225
  e.apply({
228
226
  type: "set_attr",
229
227
  range: o,
@@ -232,16 +230,16 @@ function U(e, n, r, o = t(e.selection)) {
232
230
  });
233
231
  }
234
232
 
235
- function G(n, r, o = t(n.selection)) {
233
+ function J(n, r, o = t(n.selection)) {
236
234
  let c;
237
235
  if (e(o)) {
238
236
  const t = ((t, e) => {
239
- const n = I(t, e);
240
- return A(n.i, n.o);
237
+ const n = A(t, e);
238
+ return P(n.i, n.o);
241
239
  })(n.doc, o[0]);
242
240
  if (!t) return;
243
241
  c = [ t.i ];
244
- } else c = R(n.doc, ...o).flatMap(t => t.children);
242
+ } else c = T(n.doc, ...o).flatMap(t => t.children);
245
243
  const s = c.filter(y);
246
244
  s.length && n.apply({
247
245
  type: "set_attr",
@@ -251,8 +249,8 @@ function G(n, r, o = t(n.selection)) {
251
249
  });
252
250
  }
253
251
 
254
- function Z(t, e, n, r = t.selection[0]) {
255
- const {t: o} = I(t.doc, r);
252
+ function Y(t, e, n, r = t.selection[0]) {
253
+ const {t: o} = A(t.doc, r);
256
254
  t.apply({
257
255
  type: "set_node_attr",
258
256
  path: o,
@@ -261,8 +259,8 @@ function Z(t, e, n, r = t.selection[0]) {
261
259
  });
262
260
  }
263
261
 
264
- function j(t, e, n, r, o = t.selection[0]) {
265
- const {i: c, t: s} = I(t.doc, o);
262
+ function Z(t, e, n, r, o = t.selection[0]) {
263
+ const {i: c, t: s} = A(t.doc, o);
266
264
  t.apply({
267
265
  type: "set_node_attr",
268
266
  path: s,
@@ -271,78 +269,81 @@ function j(t, e, n, r, o = t.selection[0]) {
271
269
  });
272
270
  }
273
271
 
274
- let z = null, X = null, Y = null, K = null, Q = null;
272
+ let j = null, z = null, X = null, K = null, Q = null;
275
273
 
276
- const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt = () => {
274
+ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => z, nt = () => {
277
275
  const t = rt();
278
- return 1 === t ? X.data.length : 2 === t ? 1 : 0;
276
+ return 1 === t ? z.data.length : 2 === t ? 1 : 0;
279
277
  }, rt = () => {
280
- if (null != Y) return Y;
281
- if (X) if ((t => 3 === t.nodeType)(X)) {
282
- const t = X.data;
283
- if (t) return Y = "\n" === t ? at() ? 3 : 5 : 1;
284
- } else if ($(X)) {
285
- if ("BR" === X.tagName) return Y = at() ? 3 : 5;
286
- if (it(X)) return Y = 6;
287
- if (K.u(X)) return Y = 2;
288
- if (K.p(X)) return Y = 4;
278
+ if (null != X) return X;
279
+ if (z) if ((t => 3 === t.nodeType)(z)) {
280
+ const t = z.data;
281
+ if (t) return X = "\n" === t ? lt() ? 3 : 5 : 1;
282
+ } else if ($(z)) {
283
+ if ("BR" === z.tagName) return X = lt() ? 3 : 5;
284
+ if (at(z)) return X = 6;
285
+ if (K.u(z)) return X = 2;
286
+ if (K.p(z)) return X = 4;
287
+ }
288
+ return X = 0;
289
+ }, ot = () => {
290
+ const t = rt();
291
+ if (X = null, 2 === t || 6 === t) {
292
+ const t = z;
293
+ if (z = j.nextSibling(), !z) for (;(z = j.nextNode()) && t.contains(z); ) ;
294
+ return z;
289
295
  }
290
- return Y = 0;
291
- }, ot = () => (Y = null, X = z.nextNode()), ct = () => {
292
- for (;(Y = null) || (X = z.nextSibling()); ) if (4 === rt()) return;
296
+ return z = j.nextNode();
297
+ }, ct = () => {
298
+ for (;(X = null) || (z = j.nextSibling()); ) if (4 === rt()) return;
293
299
  }, st = () => {
294
- for (;(Y = null) || (X = z.parentNode()); ) if (4 === rt()) return;
295
- }, it = t => "TEMPLATE" === t.tagName, at = () => {
296
- const t = X.parentNode;
300
+ for (;(X = null) || (z = j.parentNode()); ) if (4 === rt()) return;
301
+ }, it = new Set([ "TEMPLATE", "STYLE", "SCRIPT", "COLGROUP" ]), at = t => it.has(t.tagName), lt = () => {
302
+ const t = z.parentNode;
297
303
  return Q(() => {
298
- for (;ot(); ) {
304
+ for (X = 0; ot(); ) {
299
305
  if (rt()) return !0;
300
- if (!t.contains(X)) break;
306
+ if (!t.contains(z)) break;
301
307
  }
302
308
  return !1;
303
309
  });
304
- }, lt = () => {
305
- for (;;) {
306
- if (2 === rt()) {
307
- const t = X;
308
- for (;ot() && t.contains(X); ) ;
309
- } else ot();
310
- if (!X) break;
310
+ }, ft = () => {
311
+ for (;ot(); ) {
311
312
  const t = rt();
312
313
  if (t && 6 !== t) return t;
313
314
  }
314
- }, ft = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), ut = t => ft.has(t.tagName), dt = new Set([ "EMBED", "IMG", "PICTURE", "AUDIO", "VIDEO", "SVG", "CANVAS", "MATH", "IFRAME", "OBJECT" ]), pt = t => "false" === t.contentEditable || dt.has(t.tagName), ht = (t, e) => t.compareDocumentPosition(e), yt = t => t.ownerDocument, gt = t => yt(t).getSelection(), _t = (t, e) => {
315
+ }, ut = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), dt = t => ut.has(t.tagName), pt = new Set([ "EMBED", "IMG", "PICTURE", "AUDIO", "VIDEO", "SVG", "CANVAS", "MATH", "IFRAME", "OBJECT" ]), ht = t => "false" === t.contentEditable || pt.has(t.tagName), yt = (t, e) => t.compareDocumentPosition(e), gt = t => t.ownerDocument, _t = t => gt(t).getSelection(), kt = (t, e) => {
315
316
  if (t.rangeCount) {
316
317
  const n = t.getRangeAt(0);
317
318
  if (e.contains(n.commonAncestorContainer)) return n;
318
319
  }
319
- }, kt = (t, e, n, r) => {
320
- const o = gt(t);
321
- (n || _t(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
320
+ }, xt = (t, e, n, r) => {
321
+ const o = _t(t);
322
+ (n || kt(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
322
323
  o.extend(e.startContainer, e.startOffset)));
323
- }, xt = (t, e, [n, r], o, c, s) => {
324
+ }, bt = (t, e, [n, r], o, c, s) => {
324
325
  const i = 0 === o, a = o > 0, l = a ? r : n, f = a ? n : r;
325
326
  if (0 === l[0].length && 0 === l[1] && i && !e.hasChildNodes()) {
326
327
  const n = t.createRange();
327
- return n.setStart(e, 0), n.setEnd(e, 0), kt(e, n, s);
328
+ return n.setStart(e, 0), n.setEnd(e, 0), xt(e, n, s);
328
329
  }
329
- const u = bt(e, l, c);
330
+ const u = mt(e, l, c);
330
331
  if (!u) return;
331
- const d = i ? u : bt(e, f, c);
332
+ const d = i ? u : mt(e, f, c);
332
333
  if (!d) return;
333
334
  const p = t.createRange(), [h, y] = u, [g, _] = d;
334
335
  $(h) ? y < 1 ? p.setStartBefore(h) : p.setStartAfter(h) : p.setStart(h, y), $(g) ? _ < 1 ? p.setEndBefore(g) : p.setEndAfter(g) : p.setEnd(g, _),
335
- kt(e, p, s, a);
336
- }, bt = (t, [e, n], r) => r(() => {
336
+ xt(e, p, s, a);
337
+ }, mt = (t, [e, n], r) => r(() => {
337
338
  let t, r = 0;
338
- for (;t = lt(); ) if (4 === t) {
339
+ for (;t = ft(); ) if (4 === t) {
339
340
  if (r < e.length) for (let t = e[r++]; t > 0; t--) ct();
340
341
  } else {
341
342
  const t = nt();
342
343
  if (n <= t) return [ et(), n ];
343
344
  n -= t;
344
345
  }
345
- }, t), mt = (t, e, r, o) => {
346
+ }, t), vt = (t, e, r, o) => {
346
347
  let c = !0;
347
348
  if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
348
349
  if ($(e) && e.hasChildNodes()) {
@@ -357,12 +358,12 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
357
358
  for (;(n = et()) && n !== t; ) e.unshift(n), st();
358
359
  if (!e.length) return [ 0 ];
359
360
  let r = 0, o = e[e.length - 1];
360
- for (;o = o.previousElementSibling; ) it(o) || r++;
361
+ for (;o = o.previousElementSibling; ) at(o) || r++;
361
362
  return [ r ];
362
363
  });
363
364
  let s = 0;
364
- for (;lt(); ) {
365
- const t = ht(e, et());
365
+ for (;ft(); ) {
366
+ const t = yt(e, et());
366
367
  if (0 === t || 16 & t) {
367
368
  if (c) break;
368
369
  } else if (4 & t) break;
@@ -370,10 +371,10 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
370
371
  }
371
372
  return [ n, s + r ];
372
373
  }, t, e);
373
- }, vt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
374
- const s = mt(t, r, n, e);
375
- return [ s, r === c && n === o ? s : mt(t, c, o, e) ];
376
- }, wt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), Mt = (t, e) => {
374
+ }, wt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
375
+ const s = vt(t, r, n, e);
376
+ return [ s, r === c && n === o ? s : vt(t, c, o, e) ];
377
+ }, Mt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), St = (t, e) => {
377
378
  const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
378
379
  let s = !1, i = !1, a = !1, l = !1;
379
380
  return r.forEach(t => {
@@ -387,7 +388,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
387
388
  break;
388
389
 
389
390
  case "Mod":
390
- wt ? a = !0 : i = !0;
391
+ Mt ? a = !0 : i = !0;
391
392
  break;
392
393
 
393
394
  case "Alt":
@@ -410,13 +411,13 @@ function Et(t) {
410
411
  const n = i()[1];
411
412
  e--;
412
413
  const c = t.doc;
413
- r = !0, t.exec(J, i()[0].children), r = !1, o(c, t.doc) || (t.selection = n);
414
+ r = !0, t.exec(q, i()[0].children), r = !1, o(c, t.doc) || (t.selection = n);
414
415
  }
415
416
  }, u = () => {
416
417
  if (l()) {
417
418
  e++;
418
419
  const [n, c, s] = i(), a = t.doc;
419
- r = !0, t.exec(J, n.children), r = !1, o(a, t.doc) || (t.selection = [ B(c[0], s), B(c[1], s) ]);
420
+ r = !0, t.exec(q, n.children), r = !1, o(a, t.doc) || (t.selection = [ H(c[0], s), H(c[1], s) ]);
420
421
  }
421
422
  };
422
423
  t.hook("apply", (i, a) => {
@@ -433,7 +434,7 @@ function Et(t) {
433
434
  }
434
435
  n = t, s[e][0] = u, s[e][2].push(i), s.splice(e + 1), e > 500 && (e--, s.shift());
435
436
  }
436
- }), t.hook("keyboard", Mt("Mod+Z", f)), t.hook("keyboard", Mt("Shift+Mod+Z", u)),
437
+ }), t.hook("keyboard", St("Mod+Z", f)), t.hook("keyboard", St("Shift+Mod+Z", u)),
437
438
  t.set(Et, {
438
439
  undo: f,
439
440
  redo: u,
@@ -442,7 +443,7 @@ function Et(t) {
442
443
  });
443
444
  }
444
445
 
445
- function St(t) {
446
+ function Ot(t) {
446
447
  t.get(Et).undo();
447
448
  }
448
449
 
@@ -450,7 +451,7 @@ function Dt(t) {
450
451
  t.get(Et).redo();
451
452
  }
452
453
 
453
- function Ot(t) {
454
+ function Pt(t) {
454
455
  return t.get(Et).undoable();
455
456
  }
456
457
 
@@ -458,9 +459,9 @@ function At(t) {
458
459
  return t.get(Et).redoable();
459
460
  }
460
461
 
461
- const It = [], Pt = () => {}, Ct = t => {
462
+ const It = [], Ct = () => {}, Rt = t => {
462
463
  throw Error(t);
463
- }, Ht = ({doc: n, readonly: r = !1, schema: a, isBlock: g = ut, onWarn: _ = console.warn, onError: k = Ct}) => {
464
+ }, Tt = ({doc: n, readonly: r = !1, schema: a, isBlock: g = dt, onWarn: _ = console.warn, onError: k = Rt}) => {
464
465
  let x = [ 0, 0 ];
465
466
  const b = t => {
466
467
  if (!a) return _("An unsafe operation was detected. We recommend using schema option."),
@@ -473,18 +474,18 @@ const It = [], Pt = () => {}, Ct = t => {
473
474
  return !1;
474
475
  };
475
476
  a && !b(n) && k("Invalid document");
476
- const v = new Map, E = new WeakMap, S = t => v.get(t) || It, D = new Map, O = t => {
477
- const e = D.get(t);
478
- e && !e[1] && (e[1] = !0, i(() => {
479
- e[1] = !1, e[0].forEach(t => {
477
+ const v = new Map, S = new WeakMap, E = t => v.get(t) || It, O = new Map, D = [], I = t => {
478
+ const e = O.get(t);
479
+ e && (D.length || i(() => {
480
+ D.forEach(t => {
480
481
  t();
481
- });
482
- }));
483
- }, P = t => {
484
- if (!r) if (Array.isArray(t)) for (const e of t) L(e); else L(t);
485
- return F;
486
- }, L = t => {
487
- const e = n, r = S("apply"), c = r.length;
482
+ }), D.splice(0);
483
+ }), D.push(...e));
484
+ }, B = t => {
485
+ if (!r) if (Array.isArray(t)) for (const e of t) V(e); else V(t);
486
+ return U;
487
+ }, V = t => {
488
+ const e = n, r = E("apply"), c = r.length;
488
489
  let s = 0;
489
490
  const i = () => {
490
491
  if (s < c) {
@@ -498,21 +499,21 @@ const It = [], Pt = () => {}, Ct = t => {
498
499
  case f:
499
500
  {
500
501
  const [r, o] = n.range;
501
- T(t, r) && T(t, o) && r < o && (t = H(t, r, o, []), e = N(e, n));
502
+ L(t, r) && L(t, o) && r < o && (t = R(t, r, o, []), e = N(e, n));
502
503
  break;
503
504
  }
504
505
 
505
506
  case u:
506
507
  {
507
508
  const {at: r, text: o} = n;
508
- if (T(t, r) && o) {
509
- const {i: c, o: s} = I(t, r), i = A(c, s - 1);
509
+ if (L(t, r) && o) {
510
+ const {i: c, o: s} = A(t, r), i = P(c, s - 1);
510
511
  let a;
511
512
  if (i) {
512
513
  const t = i.i;
513
514
  y(t) && (a = t);
514
515
  }
515
- t = H(t, r, r, l(o, a, c)), e = N(e, n);
516
+ t = R(t, r, r, l(o, a, c)), e = N(e, n);
516
517
  }
517
518
  break;
518
519
  }
@@ -520,15 +521,15 @@ const It = [], Pt = () => {}, Ct = t => {
520
521
  case d:
521
522
  {
522
523
  const {at: r, fragment: o} = n;
523
- T(t, r) && o.length && (t = H(t, r, r, o), e = N(e, n));
524
+ L(t, r) && o.length && (t = R(t, r, r, o), e = N(e, n));
524
525
  break;
525
526
  }
526
527
 
527
528
  case p:
528
529
  {
529
530
  const {range: [e, r], key: o, value: c} = n;
530
- if (T(t, e) && T(t, r) && e <= r) if (e === r) {
531
- const {i: {children: n}, t: r} = I(t, e);
531
+ if (L(t, e) && L(t, r) && e <= r) if (e === r) {
532
+ const {i: {children: n}, t: r} = A(t, e);
532
533
  if (1 === n.length) {
533
534
  const e = n[0];
534
535
  y(e) && !e.text && (t = C(t, [ ...r, 0 ], {
@@ -536,7 +537,7 @@ const It = [], Pt = () => {}, Ct = t => {
536
537
  [o]: c
537
538
  }));
538
539
  }
539
- } else t = H(t, e, r, R(t, e, r).map(t => ({
540
+ } else t = R(t, e, r, T(t, e, r).map(t => ({
540
541
  ...t,
541
542
  children: t.children.map(t => y(t) ? {
542
543
  ...t,
@@ -569,11 +570,11 @@ const It = [], Pt = () => {}, Ct = t => {
569
570
  }, a = e => {
570
571
  e && (t = e), s++, i();
571
572
  };
572
- i(), o(e, n) || O("change");
573
- }, V = t => {
574
- !((t, [e, n]) => T(t, e) && T(t, n))(n, t) || x[0] === t[0] && x[1] === t[1] || (x = t,
575
- O("selectionchange"));
576
- }, F = {
573
+ i(), o(e, n) || I("change");
574
+ }, F = t => {
575
+ !((t, [e, n]) => L(t, e) && L(t, n))(n, t) || x[0] === t[0] && x[1] === t[1] || (x = t,
576
+ I("selectionchange"));
577
+ }, U = {
577
578
  get doc() {
578
579
  return n;
579
580
  },
@@ -581,21 +582,19 @@ const It = [], Pt = () => {}, Ct = t => {
581
582
  return x;
582
583
  },
583
584
  set selection(t) {
584
- V(t);
585
+ F(t);
585
586
  },
586
587
  get readonly() {
587
588
  return r;
588
589
  },
589
590
  set readonly(t) {
590
- r = t, O("readonly");
591
+ r = t, I("readonly");
591
592
  },
592
- apply: P,
593
+ apply: B,
593
594
  on: (t, e) => {
594
- let n = D.get(t);
595
- n || D.set(t, n = [ new Set, !1 ]);
596
- const r = n[0];
597
- return r.add(e), () => {
598
- r.delete(e);
595
+ let n = O.get(t);
596
+ return n || O.set(t, n = new Set), n.add(e), () => {
597
+ n.delete(e);
599
598
  };
600
599
  },
601
600
  hook: (t, e) => {
@@ -606,49 +605,49 @@ const It = [], Pt = () => {}, Ct = t => {
606
605
  };
607
606
  },
608
607
  exec: (t, ...e) => {
609
- const n = t(F, ...e);
610
- return void 0 === n ? F : n;
608
+ const n = t(U, ...e);
609
+ return void 0 === n ? U : n;
611
610
  },
612
- get: t => (E.has(t) || k("No value found for key"), E.get(t)),
613
- set: (t, e) => (E.set(t, e), F),
611
+ get: t => (S.has(t) || k("No value found for key"), S.get(t)),
612
+ set: (t, e) => (S.set(t, e), U),
614
613
  input: o => {
615
614
  if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return _("beforeinput event is not supported."),
616
- Pt;
615
+ Ct;
617
616
  const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
618
617
  o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
619
618
  let d = !1, p = null, h = !1, y = !1, k = !1;
620
- const b = yt(o), v = (t => {
619
+ const b = gt(o), v = (t => {
621
620
  const e = (n, r, o) => {
622
- const c = K, s = Q, i = z, a = X, l = Y;
621
+ const c = K, s = Q, i = j, a = z, l = X;
623
622
  try {
624
- return z || (K = t, Q = e, z = K.h.createTreeWalker(r, 5)), o && (z.currentNode = X = o),
623
+ return j || (K = t, Q = e, j = K.h.createTreeWalker(r, 5)), o && (j.currentNode = z = o),
625
624
  n();
626
625
  } finally {
627
- K = c, Q = s, z = i, X = a, Y = l, z && a && (z.currentNode = a);
626
+ K = c, Q = s, j = i, z = a, X = l, j && a && (j.currentNode = a);
628
627
  }
629
628
  };
630
629
  return e;
631
630
  })({
632
631
  h: b,
633
632
  p: g,
634
- u: pt
635
- }), E = () => {
633
+ u: ht
634
+ }), S = () => {
636
635
  o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
637
636
  };
638
- E();
639
- const D = F.on("change", () => {
637
+ S();
638
+ const O = U.on("change", () => {
640
639
  y || requestAnimationFrame(() => {
641
640
  y || o.focus({
642
641
  preventScroll: !0
643
642
  });
644
643
  });
645
- }), O = F.on("readonly", E), A = t => {
646
- for (const e of S("paste")) {
644
+ }), D = U.on("readonly", S), P = t => {
645
+ for (const e of E("paste")) {
647
646
  const n = e(t, v);
648
647
  if (n) return n;
649
648
  }
650
649
  _("failed to serialize pasted data");
651
- }, I = ((t, e) => {
650
+ }, A = ((t, e) => {
652
651
  let n = !1;
653
652
  const r = [], o = t => {
654
653
  n && r.push(...t);
@@ -681,31 +680,31 @@ const It = [], Pt = () => {}, Ct = t => {
681
680
  }
682
681
  };
683
682
  })(o, () => {
684
- xt(b, o, M(n, x), x[0] - x[1], v);
685
- }), C = () => {
686
- V(w(n, ((t, e) => {
687
- const n = gt(t), r = _t(n, t);
683
+ bt(b, o, M(n, x), x[0] - x[1], v);
684
+ }), I = () => {
685
+ F(w(n, ((t, e) => {
686
+ const n = _t(t), r = kt(n, t);
688
687
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
689
- const o = vt(t, e, r), c = ht(n.anchorNode, n.focusNode);
688
+ const o = wt(t, e, r), c = yt(n.anchorNode, n.focusNode);
690
689
  return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
691
690
  })(o, v)));
692
- }, H = () => {
693
- const t = I.m();
694
- I.k(!1), t.length && (I._(t), b.removeEventListener("selectionchange", U), xt(b, o, M(n, x), x[0] - x[1], v, !0),
695
- b.addEventListener("selectionchange", U)), p && (V(p[1]), P(p[0]), p = null), h = !1;
691
+ }, C = () => {
692
+ const t = A.m();
693
+ A.k(!1), t.length && (A._(t), b.removeEventListener("selectionchange", G), bt(b, o, M(n, x), x[0] - x[1], v, !0),
694
+ b.addEventListener("selectionchange", G)), p && (F(p[1]), B(p[0]), p = null), h = !1;
696
695
  }, R = t => {
697
- if (!h) for (const e of S("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
696
+ if (!h) for (const e of E("keyboard")) if (e(t)) return t.preventDefault(), void A.k(!1);
698
697
  }, T = () => {
699
- h || H();
698
+ h || C();
700
699
  }, L = t => {
701
700
  t.preventDefault();
702
701
  const r = t.inputType;
703
702
  if (r.startsWith("format")) return;
704
703
  if ("historyUndo" === r || "historyRedo" === r) return;
705
- h ? I.k(!0) : C();
704
+ h ? A.k(!0) : I();
706
705
  const c = t.getTargetRanges()[0];
707
706
  if (c) {
708
- const s = w(n, vt(o, v, c));
707
+ const s = w(n, wt(o, v, c));
709
708
  let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
710
709
  if (null == a) {
711
710
  const e = t.dataTransfer;
@@ -720,29 +719,29 @@ const It = [], Pt = () => {}, Ct = t => {
720
719
  text: a
721
720
  });
722
721
  }
723
- h || H();
722
+ h || C();
724
723
  }, N = () => {
725
- h || C(), h = !0;
724
+ h || I(), h = !0;
725
+ }, V = () => {
726
+ C();
726
727
  }, W = () => {
727
- H();
728
+ y = !0, I();
728
729
  }, q = () => {
729
- y = !0, C();
730
- }, J = () => {
731
730
  y = !1;
732
- }, U = () => {
733
- !y || h || k || C();
734
- }, G = t => {
735
- if (C(), !e(x)) for (const e of S("copy")) e(t);
736
- }, Z = t => {
737
- t.preventDefault(), G(t.clipboardData);
738
- }, j = e => {
739
- e.preventDefault(), r || (G(e.clipboardData), P({
731
+ }, G = () => {
732
+ !y || h || k || I();
733
+ }, J = t => {
734
+ if (I(), !e(x)) for (const e of E("copy")) e(t);
735
+ }, Y = t => {
736
+ t.preventDefault(), J(t.clipboardData);
737
+ }, Z = e => {
738
+ e.preventDefault(), r || (J(e.clipboardData), B({
740
739
  type: "delete",
741
740
  range: t(x)
742
741
  }));
743
742
  }, $ = e => {
744
743
  e.preventDefault();
745
- const n = A(e.clipboardData);
744
+ const n = P(e.clipboardData);
746
745
  if (n) {
747
746
  const e = t(x), r = e[0], o = [ {
748
747
  type: "delete",
@@ -756,17 +755,17 @@ const It = [], Pt = () => {}, Ct = t => {
756
755
  type: "insert_node",
757
756
  at: r,
758
757
  fragment: n
759
- }), P(o);
758
+ }), B(o);
760
759
  }
761
760
  }, tt = e => {
762
761
  e.preventDefault();
763
762
  const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}, o) => {
764
763
  if (t.caretPositionFromPoint) {
765
764
  const c = t.caretPositionFromPoint(n, r);
766
- if (c) return mt(e, c.offsetNode, c.offset, o);
765
+ if (c) return vt(e, c.offsetNode, c.offset, o);
767
766
  } else if (t.caretRangeFromPoint) {
768
767
  const c = t.caretRangeFromPoint(n, r);
769
- if (c) return mt(e, c.startContainer, c.startOffset, o);
768
+ if (c) return vt(e, c.startContainer, c.startOffset, o);
770
769
  }
771
770
  })(b, o, e, v);
772
771
  if (r && s) {
@@ -776,9 +775,9 @@ const It = [], Pt = () => {}, Ct = t => {
776
775
  type: "delete",
777
776
  range: t(x)
778
777
  });
779
- const i = A(r);
778
+ const i = P(r);
780
779
  if (i) {
781
- const t = m(n, s), r = B(t, o);
780
+ const t = m(n, s), r = H(t, o);
782
781
  o.push(c(i) ? {
783
782
  type: "insert_text",
784
783
  at: r,
@@ -787,39 +786,39 @@ const It = [], Pt = () => {}, Ct = t => {
787
786
  type: "insert_node",
788
787
  at: r,
789
788
  fragment: i
790
- }), e = [ r, B(t, o) ];
789
+ }), e = [ r, H(t, o) ];
791
790
  }
792
- P(o), e && V(e);
791
+ B(o), e && F(e);
793
792
  }
794
793
  }, et = t => {
795
- k = !0, G(t.dataTransfer);
794
+ k = !0, J(t.dataTransfer);
796
795
  }, nt = () => {
797
796
  k = !1;
798
797
  };
799
- b.addEventListener("selectionchange", U), o.addEventListener("keydown", R), o.addEventListener("input", T),
798
+ b.addEventListener("selectionchange", G), o.addEventListener("keydown", R), o.addEventListener("input", T),
800
799
  o.addEventListener("beforeinput", L), o.addEventListener("compositionstart", N),
801
- o.addEventListener("compositionend", W), o.addEventListener("focus", q), o.addEventListener("blur", J),
802
- o.addEventListener("copy", Z), o.addEventListener("cut", j), o.addEventListener("paste", $),
800
+ o.addEventListener("compositionend", V), o.addEventListener("focus", W), o.addEventListener("blur", q),
801
+ o.addEventListener("copy", Y), o.addEventListener("cut", Z), o.addEventListener("paste", $),
803
802
  o.addEventListener("drop", tt), o.addEventListener("dragstart", et), o.addEventListener("dragend", nt);
804
803
  const rt = [];
805
- return S("mount").forEach(t => {
804
+ return E("mount").forEach(t => {
806
805
  const e = t(o);
807
806
  e && rt.push(e);
808
807
  }), () => {
809
- d || (d = !0, D(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
810
- o.ariaReadOnly = f, o.style.whiteSpace = u, I.v(), b.removeEventListener("selectionchange", U),
808
+ d || (d = !0, O(), D(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
809
+ o.ariaReadOnly = f, o.style.whiteSpace = u, A.v(), b.removeEventListener("selectionchange", G),
811
810
  o.removeEventListener("keydown", R), o.removeEventListener("input", T), o.removeEventListener("beforeinput", L),
812
- o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend", W),
813
- o.removeEventListener("focus", q), o.removeEventListener("blur", J), o.removeEventListener("copy", Z),
814
- o.removeEventListener("cut", j), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
811
+ o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend", V),
812
+ o.removeEventListener("focus", W), o.removeEventListener("blur", q), o.removeEventListener("copy", Y),
813
+ o.removeEventListener("cut", Z), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
815
814
  o.removeEventListener("dragstart", et), o.removeEventListener("dragend", nt), rt.forEach(t => {
816
815
  t();
817
816
  }));
818
817
  };
819
818
  }
820
819
  };
821
- return F.exec(Et), F;
822
- }, Rt = (t, e) => {
820
+ return U.exec(Et), U;
821
+ }, Lt = (t, e) => {
823
822
  t.hook("paste", t => {
824
823
  for (const n of t.items) if ("file" === n.kind) {
825
824
  const t = e[n.type];
@@ -834,11 +833,11 @@ const It = [], Pt = () => {}, Ct = t => {
834
833
  });
835
834
  };
836
835
 
837
- function Tt(e, n) {
836
+ function Ht(e, n) {
838
837
  const r = n && n.serializer;
839
838
  e.hook("copy", n => {
840
839
  n.setData("text/plain", a({
841
- children: R(e.doc, ...t(e.selection))
840
+ children: T(e.doc, ...t(e.selection))
842
841
  }, r));
843
842
  }), e.hook("paste", t => t.getData("text/plain"));
844
843
  }
@@ -850,7 +849,7 @@ function Bt(t, e) {
850
849
  })), t.hook("copy", t => {
851
850
  if (!n) return;
852
851
  const e = document.createElement("div");
853
- e.appendChild(_t(gt(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
852
+ e.appendChild(kt(_t(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
854
853
  }), t.hook("paste", ((t, e = []) => (n, r) => {
855
854
  const o = n.getData("text/html");
856
855
  if (o) {
@@ -866,7 +865,7 @@ function Bt(t, e) {
866
865
  children: e
867
866
  }), e = null, c = !1;
868
867
  };
869
- for (;t = lt(); ) if (4 === t) a(); else if (c = !0, 1 === t) o += et().data; else if (2 === t) {
868
+ for (;t = ft(); ) if (4 === t) a(); else if (c = !0, 1 === t) o += et().data; else if (2 === t) {
870
869
  i();
871
870
  const t = r(et());
872
871
  t && e.push(t);
@@ -885,21 +884,21 @@ function Bt(t, e) {
885
884
  })(e.serializeText, e.serializers));
886
885
  }
887
886
 
888
- const Lt = "application/x-editate-editor";
887
+ const Nt = "application/x-editate-editor";
889
888
 
890
- function Nt(e) {
889
+ function Vt(e) {
891
890
  e.hook("copy", n => {
892
- n.setData(Lt, JSON.stringify(R(e.doc, ...t(e.selection))));
891
+ n.setData(Nt, JSON.stringify(T(e.doc, ...t(e.selection))));
893
892
  }), e.hook("paste", t => {
894
893
  try {
895
- return JSON.parse(t.getData(Lt));
894
+ return JSON.parse(t.getData(Nt));
896
895
  } catch (t) {
897
896
  return null;
898
897
  }
899
898
  });
900
899
  }
901
900
 
902
- function Vt(t) {
901
+ function Ft(t) {
903
902
  t.hook("apply", t => {
904
903
  console.log("apply", t);
905
904
  }), t.on("change", () => {
@@ -909,10 +908,10 @@ function Vt(t) {
909
908
  });
910
909
  }
911
910
 
912
- function Ft(t, e) {
911
+ function Ut(t, e) {
913
912
  r(e).forEach(n => {
914
913
  const r = e[n];
915
- t.hook("keyboard", Mt(n, () => {
914
+ t.hook("keyboard", St(n, () => {
916
915
  r();
917
916
  }));
918
917
  });
@@ -927,22 +926,22 @@ function Wt(t) {
927
926
  text: t.text.replaceAll("\n", "")
928
927
  } : "insert_node" === t.type && (t = {
929
928
  ...t,
930
- fragment: [ O(...t.fragment) ]
929
+ fragment: [ D(...t.fragment) ]
931
930
  }), e(t);
932
931
  });
933
932
  }
934
933
 
935
934
  const qt = ({text: t, singleline: e, onChange: n, ...r}) => {
936
- const o = Ht({
935
+ const o = Tt({
937
936
  ...r,
938
937
  doc: {
939
938
  children: l(t)
940
939
  }
941
- }).exec(Tt);
942
- return o.on("change", () => {
940
+ }).exec(Ht);
941
+ return e && o.exec(Wt), o.on("change", () => {
943
942
  n(a(o.doc));
944
- }), e && o.exec(Wt), o;
943
+ }), o;
945
944
  };
946
945
 
947
- export { V as Delete, U as Format, W as InsertNode, F as InsertText, Dt as Redo, At as Redoable, J as ReplaceDoc, q as ReplaceText, Z as SetBlockAttr, j as ToggleBlockAttr, G as ToggleFormat, St as Undo, Ot as Undoable, Ht as createEditor, qt as createPlainEditor, Vt as debugPlugin, Rt as fileTransferPlugin, Bt as htmlTransferPlugin, Nt as internalTranferPlugin, Ft as keymapPlugin, Tt as plainTransferPlugin, Wt as singlelinePlugin };
946
+ export { V as Delete, G as Format, U as InsertNode, F as InsertText, Dt as Redo, At as Redoable, q as ReplaceDoc, W as ReplaceText, Y as SetBlockAttr, Z as ToggleBlockAttr, J as ToggleFormat, Ot as Undo, Pt as Undoable, Tt as createEditor, qt as createPlainEditor, Ft as debugPlugin, Lt as fileTransferPlugin, Bt as htmlTransferPlugin, Vt as internalTranferPlugin, Ut as keymapPlugin, Ht as plainTransferPlugin, Wt as singlelinePlugin };
948
947
  //# sourceMappingURL=index.js.map