editate 0.6.3 → 0.6.4

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