editate 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -12,22 +12,22 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
12
12
  })), f = "delete", u = "insert_text", d = "insert_node", p = "set_attr", y = "set_node_attr", h = t => "text" in t, g = t => "children" in t, k = (t, e) => {
13
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
- }, x = new WeakMap, _ = ({children: t}, e = 0, n = t.length) => {
15
+ }, b = new WeakMap, x = ({children: t}, e = 0, n = t.length) => {
16
16
  let r = 0, o = 0;
17
17
  for (let c = e; c < n; c++) {
18
18
  const e = t[c];
19
- r += b(e), 0 !== o && g(e) && r++, o++;
19
+ r += _(e), 0 !== o && g(e) && r++, o++;
20
20
  }
21
21
  return r;
22
- }, b = t => {
22
+ }, _ = t => {
23
23
  if (g(t)) {
24
- let e = x.get(t);
25
- return null == e && x.set(t, e = _(t)), e;
24
+ let e = b.get(t);
25
+ return null == e && b.set(t, e = x(t)), e;
26
26
  }
27
27
  return h(t) ? t.text.length : 1;
28
28
  }, m = (t, [e, n]) => {
29
29
  let r = 0;
30
- for (const n of e) r += _(t, 0, n), 0 !== n && r++, t = t.children[n];
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
  }, w = (t, e) => {
33
33
  const n = [];
@@ -39,7 +39,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
39
39
  e = r.i, n.push(o), t = c;
40
40
  }
41
41
  return [ n, e ];
42
- }, v = (t, [e, n]) => [ m(t, e), m(t, n) ], M = (t, [e, n]) => [ w(t, e), w(t, n) ], S = (t, e = 0, n = t.length - 1) => {
42
+ }, v = (t, [e, n]) => [ m(t, e), m(t, n) ], M = (t, [e, n]) => [ w(t, e), w(t, n) ], E = (t, e = 0, n = t.length - 1) => {
43
43
  let r = e + 1;
44
44
  for (;r <= n; ) {
45
45
  const e = t[r - 1], o = t[r];
@@ -52,24 +52,24 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
52
52
  const e = t[r];
53
53
  h(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
54
54
  }
55
- }, D = (t, e = 0, n = t.length - 1) => {
55
+ }, S = (t, e = 0, n = t.length - 1) => {
56
56
  let r = e + 1;
57
57
  for (;r <= n; ) {
58
58
  const e = t[r - 1], o = t[r];
59
59
  t[r - 1] = O(e, o), t.splice(r, 1), n--;
60
60
  }
61
- }, E = (t, e, n) => {
61
+ }, D = (t, e, n) => {
62
62
  if (e.length) {
63
63
  const r = t.length;
64
64
  t.push(...e), r && n(t, r - 1, r);
65
65
  }
66
66
  }, O = (...t) => ({
67
67
  ...t[0],
68
- children: t.reduce((t, e) => (E(t, e.children, S), t), [])
68
+ children: t.reduce((t, e) => (D(t, e.children, E), t), [])
69
69
  }), A = ({children: t}, e) => {
70
70
  for (let n = 0; n < t.length; n++) {
71
71
  const r = t[n];
72
- let o = b(r);
72
+ let o = _(r);
73
73
  if (g(r) && o++, o > e) return {
74
74
  o: r,
75
75
  t: n,
@@ -134,11 +134,11 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
134
134
  return n;
135
135
  }, H = (t, e, n, r) => {
136
136
  const [o, c] = I(t, e), s = e < n ? I(t, n)[1] : c, i = o.children.slice();
137
- return E(i, r, D), E(i, s.children, D), {
137
+ return D(i, r, S), D(i, s.children, S), {
138
138
  ...t,
139
139
  children: i
140
140
  };
141
- }, R = (t, e, n) => e >= n ? [] : I(I(t, n)[0], e)[1].children, B = (t, e) => e >= 0 && e <= b(t), V = (t, e) => e.reduce((t, e) => F(t, e), t), F = (t, e) => {
141
+ }, R = (t, e, n) => e >= n ? [] : I(I(t, n)[0], e)[1].children, B = (t, e) => e >= 0 && e <= _(t), N = (t, e) => e.reduce((t, e) => V(t, e), t), V = (t, e) => {
142
142
  switch (e.type) {
143
143
  case f:
144
144
  {
@@ -157,16 +157,16 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
157
157
  case d:
158
158
  {
159
159
  const {at: n, fragment: r} = e;
160
- if (t >= n) return t + b({
160
+ if (t >= n) return t + _({
161
161
  children: r
162
162
  });
163
163
  break;
164
164
  }
165
165
  }
166
166
  return t;
167
- }, L = ([t, e], n) => [ F(t, n), F(e, n) ];
167
+ }, F = ([t, e], n) => [ V(t, n), V(e, n) ];
168
168
 
169
- function N(e, n = t(e.selection)) {
169
+ function L(e, n = t(e.selection)) {
170
170
  e.apply({
171
171
  type: "delete",
172
172
  range: n
@@ -206,7 +206,7 @@ function J(e, n) {
206
206
  function U(t, e) {
207
207
  t.apply({
208
208
  type: "delete",
209
- range: [ 0, b(t.doc) ]
209
+ range: [ 0, _(t.doc) ]
210
210
  }).apply({
211
211
  type: "insert_node",
212
212
  at: 0,
@@ -214,7 +214,7 @@ function U(t, e) {
214
214
  });
215
215
  }
216
216
 
217
- function G(e, n, r, o = t(e.selection)) {
217
+ function W(e, n, r, o = t(e.selection)) {
218
218
  e.apply({
219
219
  type: "set_attr",
220
220
  range: o,
@@ -223,7 +223,7 @@ function G(e, n, r, o = t(e.selection)) {
223
223
  });
224
224
  }
225
225
 
226
- function W(e, n, r = t(e.selection)) {
226
+ function G(e, n, r = t(e.selection)) {
227
227
  const o = R(e.doc, ...r).flatMap(t => t.children.filter(h));
228
228
  o.length && e.apply({
229
229
  type: "set_attr",
@@ -300,20 +300,20 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
300
300
  const o = ht(t);
301
301
  (n || gt(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
302
302
  o.extend(e.startContainer, e.startOffset)));
303
- }, xt = (t, e, [n, r], o, c, s) => {
303
+ }, bt = (t, e, [n, r], o, c, s) => {
304
304
  const i = 0 === o, a = o > 0, l = a ? r : n, f = a ? n : r;
305
305
  if (0 === l[0].length && 0 === l[1] && i && !e.hasChildNodes()) {
306
306
  const n = t.createRange();
307
307
  return n.setStart(e, 0), n.setEnd(e, 0), kt(e, n, s);
308
308
  }
309
- const u = _t(e, l, c);
309
+ const u = xt(e, l, c);
310
310
  if (!u) return;
311
- const d = i ? u : _t(e, f, c);
311
+ const d = i ? u : xt(e, f, c);
312
312
  if (!d) return;
313
313
  const p = t.createRange(), [y, h] = u, [g, k] = d;
314
314
  $(y) ? h < 1 ? p.setStartBefore(y) : p.setStartAfter(y) : p.setStart(y, h), $(g) ? k < 1 ? p.setEndBefore(g) : p.setEndAfter(g) : p.setEnd(g, k),
315
315
  kt(e, p, s, a);
316
- }, _t = (t, [e, n], r) => r(() => {
316
+ }, xt = (t, [e, n], r) => r(() => {
317
317
  let t, r = 0;
318
318
  for (;t = at(); ) if (4 === t) {
319
319
  if (r < e.length) for (let t = e[r++]; t > 0; t--) ct();
@@ -322,7 +322,7 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
322
322
  if (n <= t) return [ et(), n ];
323
323
  n -= t;
324
324
  }
325
- }, t), bt = (t, e, r, o) => {
325
+ }, t), _t = (t, e, r, o) => {
326
326
  let c = !0;
327
327
  if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
328
328
  if ($(e) && e.hasChildNodes()) {
@@ -351,8 +351,8 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
351
351
  return [ n, s + r ];
352
352
  }, t, e);
353
353
  }, mt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
354
- const s = bt(t, r, n, e);
355
- return [ s, r === c && n === o ? s : bt(t, c, o, e) ];
354
+ const s = _t(t, r, n, e);
355
+ return [ s, r === c && n === o ? s : _t(t, c, o, e) ];
356
356
  }, wt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), vt = (t, e) => {
357
357
  const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
358
358
  let s = !1, i = !1, a = !1, l = !1;
@@ -385,7 +385,20 @@ const $ = t => 1 === t.nodeType, tt = t => 8 === t.nodeType, et = () => X, nt =
385
385
 
386
386
  function Mt(t) {
387
387
  let e = 0, n = 0, r = !1;
388
- const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e];
388
+ const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e], a = () => e > 0, l = () => e < s.length - 1, f = () => {
389
+ if (a()) {
390
+ const n = i()[1];
391
+ e--;
392
+ const c = t.doc;
393
+ r = !0, t.exec(U, i()[0].children), r = !1, o(c, t.doc) || (t.selection = n);
394
+ }
395
+ }, u = () => {
396
+ if (l()) {
397
+ e++;
398
+ const [n, c, s] = i(), a = t.doc;
399
+ r = !0, t.exec(U, n.children), r = !1, o(a, t.doc) || (t.selection = [ N(c[0], s), N(c[1], s) ]);
400
+ }
401
+ };
389
402
  t.hook("apply", (i, a) => {
390
403
  if (r) return;
391
404
  const l = t.doc, f = t.selection;
@@ -400,25 +413,34 @@ function Mt(t) {
400
413
  }
401
414
  n = t, s[e][0] = u, s[e][2].push(i), s.splice(e + 1), e > 500 && (e--, s.shift());
402
415
  }
403
- }), t.hook("keyboard", vt("Mod+Z", () => {
404
- if (e > 0) {
405
- const n = i()[1];
406
- e--;
407
- const c = t.doc;
408
- r = !0, t.exec(U, i()[0].children), r = !1, o(c, t.doc) || (t.selection = n);
409
- }
410
- })), t.hook("keyboard", vt("Shift+Mod+Z", () => {
411
- if (e < s.length - 1) {
412
- e++;
413
- const [n, c, s] = i(), a = t.doc;
414
- r = !0, t.exec(U, n.children), r = !1, o(a, t.doc) || (t.selection = [ V(c[0], s), V(c[1], s) ]);
415
- }
416
- }));
416
+ }), t.hook("keyboard", vt("Mod+Z", f)), t.hook("keyboard", vt("Shift+Mod+Z", u)),
417
+ t.set(Mt, {
418
+ undo: f,
419
+ redo: u,
420
+ undoable: a,
421
+ redoable: l
422
+ });
417
423
  }
418
424
 
419
- const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBlock: g = ft, onError: k = console.error}) => {
420
- let x = [ 0, 0 ];
421
- const _ = (t, e) => {
425
+ function Et(t) {
426
+ t.get(Mt).undo();
427
+ }
428
+
429
+ function St(t) {
430
+ t.get(Mt).redo();
431
+ }
432
+
433
+ function Dt(t) {
434
+ return t.get(Mt).undoable();
435
+ }
436
+
437
+ function Ot(t) {
438
+ return t.get(Mt).redoable();
439
+ }
440
+
441
+ const At = [], It = () => {}, Pt = ({doc: n, readonly: r = !1, schema: a, isBlock: g = ft, onError: k = console.error}) => {
442
+ let b = [ 0, 0 ];
443
+ const x = (t, e) => {
422
444
  if (!a) return e("An unsafe operation was detected. We recommend using schema option."),
423
445
  !0;
424
446
  const n = a["~standard"].validate(t);
@@ -428,21 +450,21 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
428
450
  }
429
451
  return !1;
430
452
  };
431
- let b;
432
- if (!_(n, t => {
433
- b = t;
434
- }) && b) throw Error(b);
435
- const S = new Map, D = t => S.get(t) || St, E = new Map, O = t => {
436
- const e = E.get(t);
453
+ let _;
454
+ if (!x(n, t => {
455
+ _ = t;
456
+ }) && _) throw Error(_);
457
+ const E = new Map, S = new WeakMap, D = t => E.get(t) || At, O = new Map, I = t => {
458
+ const e = O.get(t);
437
459
  e && !e[1] && (e[1] = !0, i(() => {
438
460
  e[1] = !1, e[0].forEach(t => {
439
461
  t();
440
462
  });
441
463
  }));
442
- }, I = t => {
443
- if (!r) if (Array.isArray(t)) for (const e of t) F(e); else F(t);
444
- return T;
445
- }, F = t => {
464
+ }, V = t => {
465
+ if (!r) if (Array.isArray(t)) for (const e of t) L(e); else L(t);
466
+ return q;
467
+ }, L = t => {
446
468
  const e = n, r = D("apply"), c = r.length;
447
469
  let s = 0;
448
470
  const i = () => {
@@ -457,7 +479,7 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
457
479
  case f:
458
480
  {
459
481
  const [r, o] = n.range;
460
- B(t, r) && B(t, o) && r < o && (t = H(t, r, o, []), e = L(e, n));
482
+ B(t, r) && B(t, o) && r < o && (t = H(t, r, o, []), e = F(e, n));
461
483
  break;
462
484
  }
463
485
 
@@ -471,7 +493,7 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
471
493
  const t = a.o;
472
494
  h(t) && (f = t);
473
495
  }
474
- t = H(t, r, r, l(o, f, i)), e = L(e, n);
496
+ t = H(t, r, r, l(o, f, i)), e = F(e, n);
475
497
  }
476
498
  break;
477
499
  }
@@ -479,7 +501,7 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
479
501
  case d:
480
502
  {
481
503
  const {at: r, fragment: o} = n;
482
- B(t, r) && o.length && (t = H(t, r, r, o), e = L(e, n));
504
+ B(t, r) && o.length && (t = H(t, r, r, o), e = F(e, n));
483
505
  break;
484
506
  }
485
507
 
@@ -507,8 +529,8 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
507
529
  }
508
530
  }
509
531
  return [ t, e ];
510
- })(n, x, t);
511
- (({type: t}) => t === d || t === p || t === y)(t) && !_(e, k) || (n = e, x = r);
532
+ })(n, b, t);
533
+ (({type: t}) => t === d || t === p || t === y)(t) && !x(e, k) || (n = e, b = r);
512
534
  } catch (t) {
513
535
  k("rollback operation: " + t);
514
536
  }
@@ -516,53 +538,58 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
516
538
  }, a = e => {
517
539
  e && (t = e), s++, i();
518
540
  };
519
- i(), o(e, n) || O("change");
520
- }, N = t => {
521
- !((t, [e, n]) => B(t, e) && B(t, n))(n, t) || x[0] === t[0] && x[1] === t[1] || (x = t,
522
- O("selectionchange"));
523
- }, T = {
541
+ i(), o(e, n) || I("change");
542
+ }, T = t => {
543
+ !((t, [e, n]) => B(t, e) && B(t, n))(n, t) || b[0] === t[0] && b[1] === t[1] || (b = t,
544
+ I("selectionchange"));
545
+ }, q = {
524
546
  get doc() {
525
547
  return n;
526
548
  },
527
549
  get selection() {
528
- return x;
550
+ return b;
529
551
  },
530
552
  set selection(t) {
531
- N(t);
553
+ T(t);
532
554
  },
533
555
  get readonly() {
534
556
  return r;
535
557
  },
536
558
  set readonly(t) {
537
- r = t, O("readonly");
559
+ r = t, I("readonly");
538
560
  },
539
- apply: I,
561
+ apply: V,
540
562
  on: (t, e) => {
541
- let n = E.get(t);
542
- n || E.set(t, n = [ new Set, !1 ]);
563
+ let n = O.get(t);
564
+ n || O.set(t, n = [ new Set, !1 ]);
543
565
  const r = n[0];
544
566
  return r.add(e), () => {
545
567
  r.delete(e);
546
568
  };
547
569
  },
548
570
  hook: (t, e) => {
549
- let n = S.get(t);
550
- return n || S.set(t, n = []), n.push(e), () => {
571
+ let n = E.get(t);
572
+ return n || E.set(t, n = []), n.push(e), () => {
551
573
  const t = n.indexOf(e);
552
574
  -1 !== t && n.splice(t, 1);
553
575
  };
554
576
  },
555
577
  exec: (t, ...e) => {
556
- const n = t(T, ...e);
557
- return void 0 === n ? T : n;
578
+ const n = t(q, ...e);
579
+ return void 0 === n ? q : n;
580
+ },
581
+ get: t => {
582
+ if (!S.has(t)) throw Error("No value found for key");
583
+ return S.get(t);
558
584
  },
585
+ set: (t, e) => (S.set(t, e), q),
559
586
  input: o => {
560
587
  if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return k("beforeinput event is not supported."),
561
- Dt;
588
+ It;
562
589
  const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
563
590
  o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
564
- let d = !1, p = null, y = !1, h = !1, _ = !1;
565
- const b = yt(o), w = (t => {
591
+ let d = !1, p = null, y = !1, h = !1, x = !1;
592
+ const _ = yt(o), w = (t => {
566
593
  const e = (n, r, o) => {
567
594
  const c = K, s = Q, i = z, a = X, l = Y;
568
595
  try {
@@ -574,26 +601,26 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
574
601
  };
575
602
  return e;
576
603
  })({
577
- p: b,
604
+ p: _,
578
605
  u: g,
579
606
  l: dt
580
- }), S = () => {
607
+ }), E = () => {
581
608
  o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
582
609
  };
583
- S();
584
- const E = T.on("change", () => {
610
+ E();
611
+ const S = q.on("change", () => {
585
612
  h || requestAnimationFrame(() => {
586
613
  h || o.focus({
587
614
  preventScroll: !0
588
615
  });
589
616
  });
590
- }), O = T.on("readonly", S), A = t => {
617
+ }), O = q.on("readonly", E), A = t => {
591
618
  for (const e of D("paste")) {
592
619
  const n = e(t, w);
593
620
  if (n) return n;
594
621
  }
595
622
  k("failed to serialize pasted data");
596
- }, P = ((t, e) => {
623
+ }, I = ((t, e) => {
597
624
  let n = !1;
598
625
  const r = [], o = t => {
599
626
  n && r.push(...t);
@@ -626,28 +653,28 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
626
653
  }
627
654
  };
628
655
  })(o, () => {
629
- xt(b, o, M(n, x), x[0] - x[1], w);
630
- }), C = () => {
631
- N(v(n, ((t, e) => {
656
+ bt(_, o, M(n, b), b[0] - b[1], w);
657
+ }), P = () => {
658
+ T(v(n, ((t, e) => {
632
659
  const n = ht(t), r = gt(n, t);
633
660
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
634
661
  const o = mt(t, e, r), c = pt(n.anchorNode, n.focusNode);
635
662
  return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
636
663
  })(o, w)));
637
- }, H = () => {
638
- const t = P._();
639
- P.k(!1), t.length && (P.h(t), b.removeEventListener("selectionchange", W), xt(b, o, M(n, x), x[0] - x[1], w, !0),
640
- b.addEventListener("selectionchange", W)), p && (N(p[1]), I(p[0]), p = null), y = !1;
641
- }, B = t => {
642
- if (!y) for (const e of D("keyboard")) if (e(t)) return t.preventDefault(), void P.k(!1);
643
- }, F = () => {
644
- y || H();
645
- }, L = t => {
664
+ }, C = () => {
665
+ const t = I._();
666
+ I.k(!1), t.length && (I.h(t), _.removeEventListener("selectionchange", G), bt(_, o, M(n, b), b[0] - b[1], w, !0),
667
+ _.addEventListener("selectionchange", G)), p && (T(p[1]), V(p[0]), p = null), y = !1;
668
+ }, H = t => {
669
+ if (!y) for (const e of D("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
670
+ }, B = () => {
671
+ y || C();
672
+ }, F = t => {
646
673
  t.preventDefault();
647
674
  const r = t.inputType;
648
675
  if (r.startsWith("format")) return;
649
676
  if ("historyUndo" === r || "historyRedo" === r) return;
650
- y ? P.k(!0) : C();
677
+ y ? I.k(!0) : P();
651
678
  const c = t.getTargetRanges()[0];
652
679
  if (c) {
653
680
  const s = v(n, mt(o, w, c));
@@ -656,7 +683,7 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
656
683
  const e = t.dataTransfer;
657
684
  e && (a = e.getData("text/plain"));
658
685
  }
659
- p || (p = [ [], x ]), i = p[0], e(s) || i.push({
686
+ p || (p = [ [], b ]), i = p[0], e(s) || i.push({
660
687
  type: "delete",
661
688
  range: s
662
689
  }), a && i.push({
@@ -665,34 +692,34 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
665
692
  text: a
666
693
  });
667
694
  }
668
- y || H();
669
- }, q = () => {
670
- y || C(), y = !0;
695
+ y || C();
696
+ }, L = () => {
697
+ y || P(), y = !0;
671
698
  }, J = () => {
672
- H();
699
+ C();
673
700
  }, U = () => {
674
- h = !0, C();
675
- }, G = () => {
676
- h = !1;
701
+ h = !0, P();
677
702
  }, W = () => {
678
- !h || y || _ || C();
703
+ h = !1;
704
+ }, G = () => {
705
+ !h || y || x || P();
679
706
  }, Z = r => {
680
- if (C(), !e(x)) {
681
- const e = R(n, ...t(x));
707
+ if (P(), !e(b)) {
708
+ const e = R(n, ...t(b));
682
709
  for (const t of D("copy")) t(r, e, o);
683
710
  }
684
711
  }, j = t => {
685
712
  t.preventDefault(), Z(t.clipboardData);
686
713
  }, $ = e => {
687
- e.preventDefault(), r || (Z(e.clipboardData), I({
714
+ e.preventDefault(), r || (Z(e.clipboardData), V({
688
715
  type: "delete",
689
- range: t(x)
716
+ range: t(b)
690
717
  }));
691
718
  }, tt = e => {
692
719
  e.preventDefault();
693
720
  const n = A(e.clipboardData);
694
721
  if (n) {
695
- const e = t(x), r = e[0], o = [ {
722
+ const e = t(b), r = e[0], o = [ {
696
723
  type: "delete",
697
724
  range: e
698
725
  } ];
@@ -704,29 +731,29 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
704
731
  type: "insert_node",
705
732
  at: r,
706
733
  fragment: n
707
- }), I(o);
734
+ }), V(o);
708
735
  }
709
736
  }, et = e => {
710
737
  e.preventDefault();
711
738
  const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}, o) => {
712
739
  if (t.caretPositionFromPoint) {
713
740
  const c = t.caretPositionFromPoint(n, r);
714
- if (c) return bt(e, c.offsetNode, c.offset, o);
741
+ if (c) return _t(e, c.offsetNode, c.offset, o);
715
742
  } else if (t.caretRangeFromPoint) {
716
743
  const c = t.caretRangeFromPoint(n, r);
717
- if (c) return bt(e, c.startContainer, c.startOffset, o);
744
+ if (c) return _t(e, c.startContainer, c.startOffset, o);
718
745
  }
719
- })(b, o, e, w);
746
+ })(_, o, e, w);
720
747
  if (r && s) {
721
748
  let e;
722
749
  const o = [];
723
- _ && o.push({
750
+ x && o.push({
724
751
  type: "delete",
725
- range: t(x)
752
+ range: t(b)
726
753
  });
727
754
  const i = A(r);
728
755
  if (i) {
729
- const t = m(n, s), r = V(t, o);
756
+ const t = m(n, s), r = N(t, o);
730
757
  o.push(c(i) ? {
731
758
  type: "insert_text",
732
759
  at: r,
@@ -735,18 +762,18 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
735
762
  type: "insert_node",
736
763
  at: r,
737
764
  fragment: i
738
- }), e = [ r, V(t, o) ];
765
+ }), e = [ r, N(t, o) ];
739
766
  }
740
- I(o), e && N(e);
767
+ V(o), e && T(e);
741
768
  }
742
769
  }, nt = t => {
743
- _ = !0, Z(t.dataTransfer);
770
+ x = !0, Z(t.dataTransfer);
744
771
  }, rt = () => {
745
- _ = !1;
772
+ x = !1;
746
773
  };
747
- b.addEventListener("selectionchange", W), o.addEventListener("keydown", B), o.addEventListener("input", F),
748
- o.addEventListener("beforeinput", L), o.addEventListener("compositionstart", q),
749
- o.addEventListener("compositionend", J), o.addEventListener("focus", U), o.addEventListener("blur", G),
774
+ _.addEventListener("selectionchange", G), o.addEventListener("keydown", H), o.addEventListener("input", B),
775
+ o.addEventListener("beforeinput", F), o.addEventListener("compositionstart", L),
776
+ o.addEventListener("compositionend", J), o.addEventListener("focus", U), o.addEventListener("blur", W),
750
777
  o.addEventListener("copy", j), o.addEventListener("cut", $), o.addEventListener("paste", tt),
751
778
  o.addEventListener("drop", et), o.addEventListener("dragstart", nt), o.addEventListener("dragend", rt);
752
779
  const ot = [];
@@ -754,11 +781,11 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
754
781
  const e = t(o);
755
782
  e && ot.push(e);
756
783
  }), () => {
757
- d || (d = !0, E(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
758
- o.ariaReadOnly = f, o.style.whiteSpace = u, P.m(), b.removeEventListener("selectionchange", W),
759
- o.removeEventListener("keydown", B), o.removeEventListener("input", F), o.removeEventListener("beforeinput", L),
760
- o.removeEventListener("compositionstart", q), o.removeEventListener("compositionend", J),
761
- o.removeEventListener("focus", U), o.removeEventListener("blur", G), o.removeEventListener("copy", j),
784
+ d || (d = !0, S(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
785
+ o.ariaReadOnly = f, o.style.whiteSpace = u, I.m(), _.removeEventListener("selectionchange", G),
786
+ o.removeEventListener("keydown", H), o.removeEventListener("input", B), o.removeEventListener("beforeinput", F),
787
+ o.removeEventListener("compositionstart", L), o.removeEventListener("compositionend", J),
788
+ o.removeEventListener("focus", U), o.removeEventListener("blur", W), o.removeEventListener("copy", j),
762
789
  o.removeEventListener("cut", $), o.removeEventListener("paste", tt), o.removeEventListener("drop", et),
763
790
  o.removeEventListener("dragstart", nt), o.removeEventListener("dragend", rt), ot.forEach(t => {
764
791
  t();
@@ -766,8 +793,8 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
766
793
  };
767
794
  }
768
795
  };
769
- return T.exec(Mt), T;
770
- }, Ot = (t, e) => {
796
+ return q.exec(Mt), q;
797
+ }, Ct = (t, e) => {
771
798
  t.hook("paste", t => {
772
799
  for (const n of t.items) if ("file" === n.kind) {
773
800
  const t = e[n.type];
@@ -782,7 +809,7 @@ const St = [], Dt = () => {}, Et = ({doc: n, readonly: r = !1, schema: a, isBloc
782
809
  });
783
810
  };
784
811
 
785
- function At(t, e) {
812
+ function Ht(t, e) {
786
813
  const n = e && e.serializer;
787
814
  t.hook("copy", (t, e) => {
788
815
  t.setData("text/plain", a({
@@ -791,7 +818,7 @@ function At(t, e) {
791
818
  }), t.hook("paste", t => t.getData("text/plain"));
792
819
  }
793
820
 
794
- function It(t, e) {
821
+ function Rt(t, e) {
795
822
  t.hook("copy", (t, e, n) => {
796
823
  const r = document.createElement("div");
797
824
  r.appendChild(gt(ht(n), n).cloneContents()), t.setData("text/html", r.innerHTML);
@@ -829,21 +856,21 @@ function It(t, e) {
829
856
  })(e.serializeText, e.serializers));
830
857
  }
831
858
 
832
- const Pt = "application/x-editate-editor";
859
+ const Bt = "application/x-editate-editor";
833
860
 
834
- function Ct(t) {
861
+ function Nt(t) {
835
862
  t.hook("copy", (t, e) => {
836
- t.setData(Pt, JSON.stringify(e));
863
+ t.setData(Bt, JSON.stringify(e));
837
864
  }), t.hook("paste", t => {
838
865
  try {
839
- return JSON.parse(t.getData(Pt));
866
+ return JSON.parse(t.getData(Bt));
840
867
  } catch (t) {
841
868
  return null;
842
869
  }
843
870
  });
844
871
  }
845
872
 
846
- function Ht(t) {
873
+ function Vt(t) {
847
874
  t.hook("apply", t => {
848
875
  console.log("apply", t);
849
876
  }), t.on("change", () => {
@@ -853,7 +880,7 @@ function Ht(t) {
853
880
  });
854
881
  }
855
882
 
856
- function Rt(t, e) {
883
+ function Ft(t, e) {
857
884
  r(e).forEach(n => {
858
885
  const r = e[n];
859
886
  t.hook("keyboard", vt(n, () => {
@@ -862,7 +889,7 @@ function Rt(t, e) {
862
889
  });
863
890
  }
864
891
 
865
- function Bt(t) {
892
+ function Lt(t) {
866
893
  t.hook("mount", t => {
867
894
  t.ariaMultiLine = null;
868
895
  }), t.hook("apply", (t, e) => {
@@ -876,17 +903,17 @@ function Bt(t) {
876
903
  });
877
904
  }
878
905
 
879
- const Vt = ({text: t, singleline: e, onChange: n, ...r}) => {
880
- const o = Et({
906
+ const Tt = ({text: t, singleline: e, onChange: n, ...r}) => {
907
+ const o = Pt({
881
908
  ...r,
882
909
  doc: {
883
910
  children: l(t)
884
911
  }
885
- }).exec(At);
912
+ }).exec(Ht);
886
913
  return o.on("change", () => {
887
914
  n(a(o.doc));
888
- }), e && o.exec(Bt), o;
915
+ }), e && o.exec(Lt), o;
889
916
  };
890
917
 
891
- export { N as Delete, G as Format, q as InsertNode, T as InsertText, U as ReplaceDoc, J as ReplaceText, Z as SetBlockAttr, j as ToggleBlockAttr, W as ToggleFormat, Et as createEditor, Vt as createPlainEditor, Ht as debugPlugin, Ot as fileTransferPlugin, It as htmlTransferPlugin, Ct as internalTranferPlugin, Rt as keymapPlugin, At as plainTransferPlugin, Bt as singlelinePlugin };
918
+ export { L as Delete, W as Format, q as InsertNode, T as InsertText, St as Redo, Ot as Redoable, U as ReplaceDoc, J as ReplaceText, Z as SetBlockAttr, j as ToggleBlockAttr, G as ToggleFormat, Et as Undo, Dt as Undoable, Pt as createEditor, Tt as createPlainEditor, Vt as debugPlugin, Ct as fileTransferPlugin, Rt as htmlTransferPlugin, Nt as internalTranferPlugin, Ft as keymapPlugin, Ht as plainTransferPlugin, Lt as singlelinePlugin };
892
919
  //# sourceMappingURL=index.js.map