editate 0.6.23 → 0.6.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -217,6 +217,7 @@ export const App = () => {
217
217
  - Preact ([Demo](https://inokawa.github.io/editate/preact), [Source](./examples/preact))
218
218
  - Alpine ([Demo](https://inokawa.github.io/editate/alpine), [Source](./examples/alpine))
219
219
  - Marko ([Demo](https://inokawa.github.io/editate/marko), [Source](./examples/marko))
220
+ - Octane ([Demo](https://inokawa.github.io/editate/octane), [Source](./examples/octane))
220
221
  - Vanilla ([Demo](https://inokawa.github.io/editate/vanilla), [Source](./examples/vanilla))
221
222
 
222
223
  ...and more! Contribution welcome!
package/lib/editor.d.ts CHANGED
@@ -54,9 +54,11 @@ export type KeyboardHook = (keyboard: KeyboardEvent) => boolean | void;
54
54
  */
55
55
  export type CopyHook = (dataTransfer: DataTransfer) => void;
56
56
  /**
57
- * Functions to handle paste / drop events
57
+ * Functions to handle paste / drop events.
58
+ *
59
+ * Return `true` if you want to stop propagation.
58
60
  */
59
- export type PasteHook = (dataTransfer: DataTransfer) => string | Fragment | null;
61
+ export type PasteHook = (dataTransfer: DataTransfer) => string | Fragment | true | null;
60
62
  type EditorHookMap = {
61
63
  /**
62
64
  * Call `next(op)` to continue applying the operation, or `next()` with a nullish value to cancel it.
package/lib/index.cjs CHANGED
@@ -37,16 +37,16 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
37
37
  e = r[1], t = o, n.push(r[2]);
38
38
  }
39
39
  return [ t, e, n ];
40
- }, x = (t, e, n) => {
40
+ }, y = (t, e, n) => {
41
41
  const [r, o, c] = h(t, e), s = d(r, o, n);
42
42
  return s ? (c.push(s[2]), [ s[0], s[1], c ]) : null;
43
- }, y = (t, e) => {
43
+ }, x = (t, e) => {
44
44
  let n = 0, r = 0;
45
45
  for (const o of t.children) {
46
46
  const t = l(o);
47
47
  if (t && 0 !== r && n++, o === e) return n;
48
48
  if (t) {
49
- const t = y(o, e);
49
+ const t = x(o, e);
50
50
  if (null != t) return n + t;
51
51
  }
52
52
  n += p(o), r++;
@@ -143,13 +143,13 @@ var E = (n, r = 0, o = 1 / 0, c) => {
143
143
  }
144
144
  for (let e = t(o, p(n)) - l; e > 0; e--) s += "\n";
145
145
  return s;
146
- }, M = (t, e, n) => e >= n ? [] : k(k(t, n)[0], e)[1].children, S = (t, e, n) => t.split("\n").map(t => ({
146
+ }, w = (t, e, n) => e >= n ? [] : k(k(t, n)[0], e)[1].children, M = (t, e, n) => t.split("\n").map(t => ({
147
147
  ...n,
148
148
  children: [ {
149
149
  ...e,
150
150
  text: t
151
151
  } ]
152
- })), w = "delete", A = "insert_text", O = "insert_node", R = (t, e) => {
152
+ })), S = "delete", A = "insert_text", O = "insert_node", R = (t, e) => {
153
153
  const o = n(t);
154
154
  return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
155
155
  }, D = (t, e) => {
@@ -206,7 +206,7 @@ var E = (n, r = 0, o = 1 / 0, c) => {
206
206
  };
207
207
  }, P = (t, e) => e >= 0 && e <= p(t), H = (t, e) => e.reduce((t, e) => N(t, e), t), N = (t, e, n) => {
208
208
  switch (e.type) {
209
- case w:
209
+ case S:
210
210
  {
211
211
  const [n, r] = e.range;
212
212
  if (t >= n) return r >= t ? n : t + n - r;
@@ -234,7 +234,7 @@ var E = (n, r = 0, o = 1 / 0, c) => {
234
234
 
235
235
  function* V(t, e = W(t.selection)) {
236
236
  if (F(e)) {
237
- const n = x(t.doc, e[0])?.[0];
237
+ const n = y(t.doc, e[0])?.[0];
238
238
  n && (yield n);
239
239
  } else for (const [n, r] of T(t.doc, e)) U(e, [ r, r + p(n) ]) && (yield n);
240
240
  }
@@ -248,15 +248,15 @@ function q(t, e) {
248
248
  });
249
249
  }
250
250
 
251
- var z = t => 1 === t.nodeType, G = t => 8 === t.nodeType, J = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), Y = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), j = t => Y.has(t.tagName), X = (t, e) => t.compareDocumentPosition(e), Z = t => t.ownerDocument, K = t => Z(t).getSelection(), Q = (t, e) => {
251
+ var z = t => 1 === t.nodeType, G = t => 8 === t.nodeType, J = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), X = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), Y = t => X.has(t.tagName), j = (t, e) => t.compareDocumentPosition(e), Z = t => t.ownerDocument, K = t => Z(t).getSelection(), Q = (t, e) => {
252
252
  if (t.rangeCount) {
253
253
  const n = t.getRangeAt(0);
254
254
  if (e.contains(n.commonAncestorContainer)) return n;
255
255
  }
256
256
  }, $ = (t, e, n, r) => {
257
- const [o, c] = ((t, [e, n]) => [ g(t, e), g(t, n) ])(n, r), s = Z(t), i = F(r), l = r[0] - r[1] > 0, a = l ? o : c, u = et(t, e, l ? c : o), f = i ? u : et(t, e, a), p = s.createRange(), [d, h] = u, [x, y] = f;
257
+ const [o, c] = ((t, [e, n]) => [ g(t, e), g(t, n) ])(n, r), s = Z(t), i = F(r), l = r[0] - r[1] > 0, a = l ? o : c, u = et(t, e, l ? c : o), f = i ? u : et(t, e, a), p = s.createRange(), [d, h] = u, [y, x] = f;
258
258
  return z(d) && t !== d ? h < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, h),
259
- z(x) && t !== x ? y < 1 ? p.setEndBefore(x) : p.setEndAfter(x) : p.setEnd(x, y),
259
+ z(y) && t !== y ? x < 1 ? p.setEndBefore(y) : p.setEndAfter(y) : p.setEnd(y, x),
260
260
  p;
261
261
  }, tt = (t, e, n, r, o) => {
262
262
  const c = K(t);
@@ -294,7 +294,7 @@ var z = t => 1 === t.nodeType, G = t => 8 === t.nodeType, J = new Map([ [ "BR",
294
294
  });
295
295
  let d = 0;
296
296
  for (;t(); ) {
297
- const t = X(r, a());
297
+ const t = j(r, a());
298
298
  if (0 === t || 16 & t) {
299
299
  if (c) break;
300
300
  } else if (4 & t) break;
@@ -385,13 +385,16 @@ function st(t) {
385
385
  undo: f,
386
386
  redo: p,
387
387
  undoable: l,
388
- redoable: a
388
+ redoable: a,
389
+ clear: () => {
390
+ s.length = 0, s.push([ t.doc, t.selection, [] ]), e = 0, r = 0;
391
+ }
389
392
  });
390
393
  }
391
394
 
392
395
  var it = [], lt = () => {}, at = t => {
393
396
  throw Error(t);
394
- }, ut = ({doc: t, readonly: e = !1, schema: n, isBlock: r = j, onWarn: a = console.warn, onError: u = at}) => {
397
+ }, ut = ({doc: t, readonly: e = !1, schema: n, isBlock: r = Y, onWarn: a = console.warn, onError: u = at}) => {
395
398
  let f = [ 0, 0 ];
396
399
  const p = t => {
397
400
  if (!n) return a("An unsafe operation was detected. We recommend using schema option."),
@@ -404,7 +407,7 @@ var it = [], lt = () => {}, at = t => {
404
407
  return !1;
405
408
  };
406
409
  n && !p(t) && u("Invalid document");
407
- const x = new Map, y = new WeakMap, k = t => x.get(t) || it, g = new Map, b = new Set, v = t => {
410
+ const y = new Map, x = new WeakMap, k = t => y.get(t) || it, g = new Map, b = new Set, v = t => {
408
411
  const e = g.get(t);
409
412
  e && (b.size || s(() => {
410
413
  b.forEach(t => {
@@ -428,7 +431,7 @@ var it = [], lt = () => {}, at = t => {
428
431
  try {
429
432
  const [n, r] = ((t, e, n) => {
430
433
  switch (n.type) {
431
- case w:
434
+ case S:
432
435
  {
433
436
  const [r, o] = n.range;
434
437
  P(t, r) && P(t, o) && r < o && (t = L(t, r, o, []), e = C(e, n));
@@ -445,7 +448,7 @@ var it = [], lt = () => {}, at = t => {
445
448
  const t = l[0];
446
449
  i(t) && (a = t);
447
450
  }
448
- t = L(t, r, r, S(o, a, c)), e = C(e, n);
451
+ t = L(t, r, r, M(o, a, c)), e = C(e, n);
449
452
  }
450
453
  break;
451
454
  }
@@ -477,7 +480,7 @@ var it = [], lt = () => {}, at = t => {
477
480
  ...t,
478
481
  [o]: c
479
482
  } : t;
480
- t = L(t, e, r, M(t, e, r).map(n));
483
+ t = L(t, e, r, w(t, e, r).map(n));
481
484
  }
482
485
  break;
483
486
  }
@@ -497,7 +500,7 @@ var it = [], lt = () => {}, at = t => {
497
500
  }
498
501
  return [ t, e ];
499
502
  })(t, f, e);
500
- (({type: t}) => t !== A && t !== w)(e) && !p(n) || (t = n, R(r));
503
+ (({type: t}) => t !== A && t !== S)(e) && !p(n) || (t = n, R(r));
501
504
  } catch (n) {
502
505
  a("rollback operation: " + n);
503
506
  }
@@ -533,8 +536,8 @@ var it = [], lt = () => {}, at = t => {
533
536
  };
534
537
  },
535
538
  hook: (t, e) => {
536
- let n = x.get(t);
537
- return n || x.set(t, n = []), n.push(e), () => {
539
+ let n = y.get(t);
540
+ return n || y.set(t, n = []), n.push(e), () => {
538
541
  const t = n.indexOf(e);
539
542
  -1 !== t && n.splice(t, 1);
540
543
  };
@@ -543,15 +546,15 @@ var it = [], lt = () => {}, at = t => {
543
546
  const n = t(D, ...e);
544
547
  return void 0 === n ? D : n;
545
548
  },
546
- get: t => (y.has(t) || u("No value found for key"), y.get(t)),
547
- set: (t, e) => (y.set(t, e), D),
549
+ get: t => (x.has(t) || u("No value found for key"), x.get(t)),
550
+ set: (t, e) => (x.set(t, e), D),
548
551
  input: n => {
549
552
  if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return a("beforeinput event is not supported."),
550
553
  lt;
551
554
  const {contentEditable: s, role: i, ariaMultiLine: l, ariaReadOnly: u} = n, p = n.style.whiteSpace;
552
555
  n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
553
- let d = !1, h = null, x = !1, y = !1, g = !1, b = f, v = null;
554
- const E = Z(n), M = ((t, e) => {
556
+ let d = !1, h = null, y = !1, x = !1, g = !1, b = f, v = null;
557
+ const E = Z(n), w = ((t, e) => {
555
558
  let n = null, r = null, o = null;
556
559
  const c = () => {
557
560
  if (null != o) return o;
@@ -618,26 +621,29 @@ var it = [], lt = () => {}, at = t => {
618
621
  }
619
622
  };
620
623
  return a;
621
- })(E, r), S = () => {
624
+ })(E, r), M = () => {
622
625
  n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
623
626
  };
624
- S();
625
- const w = () => {
626
- y || n.focus({
627
+ M();
628
+ const S = () => {
629
+ x || n.focus({
627
630
  preventScroll: !0
628
631
  });
629
632
  }, A = () => {
630
- v = null, f[0] === b[0] && f[1] === b[1] || (tt(n, M, t, f), b = f);
633
+ v = null, f[0] === b[0] && f[1] === b[1] || (tt(n, w, t, f), b = f);
631
634
  }, O = () => {
632
635
  null != v && clearTimeout(v);
633
636
  }, B = D.on("change", () => {
634
- y || requestAnimationFrame(w);
637
+ x || requestAnimationFrame(S);
635
638
  }), I = D.on("selectionchange", () => {
636
639
  f[0] === b[0] && f[1] === b[1] || (O(), v = setTimeout(A, 50));
637
- }), L = D.on("readonly", S), P = t => {
640
+ }), L = D.on("readonly", M), P = t => {
638
641
  for (const e of k("paste")) {
639
642
  const n = e(t);
640
- if (n) return n;
643
+ if (n) {
644
+ if (!0 === n) return;
645
+ return n;
646
+ }
641
647
  }
642
648
  a("failed to serialize pasted data");
643
649
  }, N = ((t, e) => {
@@ -677,28 +683,28 @@ var it = [], lt = () => {}, at = t => {
677
683
  }
678
684
  };
679
685
  })(n, () => {
680
- O(), tt(n, M, t, f);
686
+ O(), tt(n, w, t, f);
681
687
  }), C = () => {
682
688
  R(b = _(t, ((t, e) => {
683
689
  const n = K(t), r = Q(n, t);
684
690
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
685
- const o = rt(t, e, r), c = X(n.anchorNode, n.focusNode);
691
+ const o = rt(t, e, r), c = j(n.anchorNode, n.focusNode);
686
692
  return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
687
- })(n, M)));
693
+ })(n, w)));
688
694
  }, U = () => {
689
695
  const e = N.v();
690
- N._(!1), e.length && (N.m(e), E.removeEventListener("selectionchange", ot), tt(n, M, t, f, !0),
691
- E.addEventListener("selectionchange", ot)), h && (R(h[1]), T(h[0]), h = null), x = !1;
696
+ N._(!1), e.length && (N.m(e), E.removeEventListener("selectionchange", ot), tt(n, w, t, f, !0),
697
+ E.addEventListener("selectionchange", ot)), h && (R(h[1]), T(h[0]), h = null), y = !1;
692
698
  }, V = t => {
693
- if (!x) for (const e of k("keyboard")) if (e(t)) return t.preventDefault(), void N._(!1);
699
+ if (!y) for (const e of k("keyboard")) if (e(t)) return t.preventDefault(), void N._(!1);
694
700
  }, q = () => {
695
- x || U();
701
+ y || U();
696
702
  }, G = e => {
697
703
  e.preventDefault();
698
704
  const r = e.inputType;
699
705
  if (r.startsWith("format")) return;
700
706
  if ("historyUndo" === r || "historyRedo" === r) return;
701
- x ? N._(!0) : C();
707
+ y ? N._(!0) : C();
702
708
  const o = e.getTargetRanges()[0];
703
709
  if (o) {
704
710
  let c = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
@@ -707,7 +713,7 @@ var it = [], lt = () => {}, at = t => {
707
713
  t && (c = t.getData("text/plain"));
708
714
  }
709
715
  h || (h = [ [], f ]);
710
- const s = h[0], i = _(t, rt(n, M, o));
716
+ const s = h[0], i = _(t, rt(n, w, o));
711
717
  F(i) || s.push({
712
718
  type: "delete",
713
719
  range: i
@@ -717,17 +723,17 @@ var it = [], lt = () => {}, at = t => {
717
723
  text: c
718
724
  });
719
725
  }
720
- x || U();
726
+ y || U();
727
+ }, X = () => {
728
+ y || C(), y = !0;
721
729
  }, Y = () => {
722
- x || C(), x = !0;
723
- }, j = () => {
724
730
  U();
725
731
  }, $ = () => {
726
- y = !0, C();
732
+ x = !0, C();
727
733
  }, et = () => {
728
- y = !1;
734
+ x = !1;
729
735
  }, ot = () => {
730
- !y || x || g || C();
736
+ !x || y || g || C();
731
737
  }, ct = t => {
732
738
  if (C(), !F(f)) for (const e of k("copy")) e(t);
733
739
  }, st = t => {
@@ -766,7 +772,7 @@ var it = [], lt = () => {}, at = t => {
766
772
  const c = o.caretRangeFromPoint(n, r);
767
773
  if (c) return nt(t, e, c.startContainer, c.startOffset);
768
774
  }
769
- })(n, M, e);
775
+ })(n, w, e);
770
776
  if (r && c) {
771
777
  let e;
772
778
  const n = [];
@@ -796,19 +802,19 @@ var it = [], lt = () => {}, at = t => {
796
802
  g = !1;
797
803
  };
798
804
  E.addEventListener("selectionchange", ot), n.addEventListener("keydown", V), n.addEventListener("input", q),
799
- n.addEventListener("beforeinput", G), n.addEventListener("compositionstart", Y),
800
- n.addEventListener("compositionend", j), n.addEventListener("focus", $), n.addEventListener("blur", et),
805
+ n.addEventListener("beforeinput", G), n.addEventListener("compositionstart", X),
806
+ n.addEventListener("compositionend", Y), n.addEventListener("focus", $), n.addEventListener("blur", et),
801
807
  n.addEventListener("copy", st), n.addEventListener("cut", it), n.addEventListener("paste", at),
802
808
  n.addEventListener("drop", ut), n.addEventListener("dragstart", ft), n.addEventListener("dragend", pt);
803
809
  const dt = [];
804
810
  return k("mount").forEach(t => {
805
- const e = t(n, M);
811
+ const e = t(n, w);
806
812
  e && dt.push(e);
807
813
  }), () => {
808
814
  d || (d = !0, B(), I(), L(), n.contentEditable = s, n.role = i, n.ariaMultiLine = l,
809
815
  n.ariaReadOnly = u, n.style.whiteSpace = p, N.T(), E.removeEventListener("selectionchange", ot),
810
816
  n.removeEventListener("keydown", V), n.removeEventListener("input", q), n.removeEventListener("beforeinput", G),
811
- n.removeEventListener("compositionstart", Y), n.removeEventListener("compositionend", j),
817
+ n.removeEventListener("compositionstart", X), n.removeEventListener("compositionend", Y),
812
818
  n.removeEventListener("focus", $), n.removeEventListener("blur", et), n.removeEventListener("copy", st),
813
819
  n.removeEventListener("cut", it), n.removeEventListener("paste", at), n.removeEventListener("drop", ut),
814
820
  n.removeEventListener("dragstart", ft), n.removeEventListener("dragend", pt), dt.forEach(t => {
@@ -827,9 +833,7 @@ function ft(t, e) {
827
833
  }), t.hook("paste", t => t.getData("text/plain"));
828
834
  }
829
835
 
830
- var pt = "application/x-editate-editor";
831
-
832
- function dt(t, e) {
836
+ function pt(t, e) {
833
837
  const n = e.isLocked, r = e => n(h(t.doc, e)[0]), o = (e, r) => {
834
838
  const [o, c] = e;
835
839
  for (const [s, i] of v(t.doc, e)) {
@@ -877,17 +881,26 @@ function dt(t, e) {
877
881
  }
878
882
  }
879
883
  i(e);
880
- }), t.set(dt, {
884
+ }), t.set(pt, {
881
885
  locked: t => F(t) ? r(t[0]) : o(t, !0)
882
886
  });
883
887
  }
884
888
 
885
- var ht = (t, e) => {
889
+ var dt = (t, e) => {
886
890
  const n = parseFloat(t);
887
891
  return n ? t.endsWith("%") ? n / 100 * e : n : 0;
888
- }, xt = (t, e, n, r) => [ t + ht(n, e), t + e - ht(r, e) ], yt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, kt = (t, e, n) => Math.max(-e, Math.min(t, n - e));
892
+ }, ht = (t, e, n, r) => [ t + dt(n, e), t + e - dt(r, e) ], yt = t => "auto" === t || "scroll" === t || "overlay" === t, xt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, kt = (t, e, n, r) => {
893
+ const o = r ? -n : 0;
894
+ return Math.max(o - e, Math.min(t, o + n - e));
895
+ }, mt = (t, [e, n], r) => {
896
+ (n || e) && t.scrollBy({
897
+ top: n,
898
+ left: e,
899
+ behavior: r
900
+ });
901
+ };
889
902
 
890
- function mt(t) {
903
+ function gt(t) {
891
904
  t.hook("mount", t => {
892
905
  t.ariaMultiLine = null;
893
906
  }), t.hook("apply", (t, e) => {
@@ -905,7 +918,9 @@ function mt(t) {
905
918
  });
906
919
  }
907
920
 
908
- exports.Delete = function(t, e = W(t.selection)) {
921
+ exports.ClearHistory = function(t) {
922
+ t.get(st).clear();
923
+ }, exports.Delete = function(t, e = W(t.selection)) {
909
924
  t.apply({
910
925
  type: "delete",
911
926
  range: e
@@ -932,7 +947,7 @@ exports.Delete = function(t, e = W(t.selection)) {
932
947
  text: e
933
948
  });
934
949
  }, exports.LeavesInRange = V, exports.LockedInRange = function(t, e = W(t.selection)) {
935
- return t.get(dt).locked(e);
950
+ return t.get(pt).locked(e);
936
951
  }, exports.Redo = function(t) {
937
952
  t.get(st).redo();
938
953
  }, exports.Redoable = function(t) {
@@ -955,7 +970,7 @@ exports.Delete = function(t, e = W(t.selection)) {
955
970
  value: n
956
971
  });
957
972
  }, exports.SetVoidAttr = function(t, e, n, r = t.selection[0]) {
958
- const o = x(t.doc, r, !0);
973
+ const o = y(t.doc, r, !0);
959
974
  o && !i(o[0]) && t.apply({
960
975
  type: "patch_node",
961
976
  path: o[2],
@@ -986,14 +1001,14 @@ exports.Delete = function(t, e = W(t.selection)) {
986
1001
  t.get(st).undo();
987
1002
  }, exports.Undoable = function(t) {
988
1003
  return t.get(st).undoable();
989
- }, exports.blockLockPlugin = dt, exports.createEditor = ut, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
1004
+ }, exports.blockLockPlugin = pt, exports.createEditor = ut, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
990
1005
  const o = ut({
991
1006
  ...r,
992
1007
  doc: {
993
- children: S(t)
1008
+ children: M(t)
994
1009
  }
995
1010
  }).exec(ft);
996
- return e && o.exec(mt), o.on("change", () => {
1011
+ return e && o.exec(gt), o.on("change", () => {
997
1012
  n(E(o.doc));
998
1013
  }), o;
999
1014
  }, exports.debugPlugin = function(t) {
@@ -1017,7 +1032,7 @@ exports.Delete = function(t, e = W(t.selection)) {
1017
1032
  }
1018
1033
  return null;
1019
1034
  });
1020
- }, exports.getChildAt = d, exports.getLeafAt = x, exports.getLeafBlockAt = h, exports.getNodeOffset = y,
1035
+ }, exports.getChildAt = d, exports.getLeafAt = y, exports.getLeafBlockAt = h, exports.getNodeOffset = x,
1021
1036
  exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1022
1037
  t.hook("mount", (n, r) => {
1023
1038
  const o = t.hook("copy", t => {
@@ -1060,12 +1075,13 @@ exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1060
1075
  o(), c();
1061
1076
  };
1062
1077
  });
1063
- }, exports.internalTransferPlugin = function(t) {
1078
+ }, exports.internalTransferPlugin = function(t, e) {
1079
+ const n = e && e.mime || "application/x-editate-editor";
1064
1080
  t.hook("copy", e => {
1065
- e.setData(pt, JSON.stringify(M(t.doc, ...W(t.selection))));
1081
+ e.setData(n, JSON.stringify(w(t.doc, ...W(t.selection))));
1066
1082
  }), t.hook("paste", t => {
1067
1083
  try {
1068
- return JSON.parse(t.getData(pt));
1084
+ return JSON.parse(t.getData(n));
1069
1085
  } catch (e) {
1070
1086
  return null;
1071
1087
  }
@@ -1078,46 +1094,54 @@ exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1078
1094
  }, exports.mapPosition = N, exports.plainTransferPlugin = ft, exports.scrollToSelectionPlugin = t => {
1079
1095
  const e = "auto";
1080
1096
  t.hook("mount", (n, r) => {
1081
- const o = Z(n), c = o.defaultView, s = ((t, e, n) => {
1097
+ const o = Z(n), c = o.defaultView, {documentElement: s} = o, i = ((t, e, n) => {
1082
1098
  const {body: r, documentElement: o} = e;
1083
1099
  let c = t;
1084
1100
  for (;c && c !== r && c !== o; ) {
1085
- const {overflowY: t} = n.getComputedStyle(c);
1086
- if ("auto" === t || "scroll" === t || "overlay" === t) return c;
1101
+ const {overflowX: t, overflowY: e} = n.getComputedStyle(c);
1102
+ if (yt(t) || yt(e)) return c;
1087
1103
  c = c.parentElement;
1088
1104
  }
1089
1105
  return null;
1090
- })(n, o, c);
1091
- let i = null;
1092
- const l = t.on("change", () => {
1093
- null == i && (i = setTimeout(() => {
1094
- i = null;
1106
+ })(n, o, c), l = i && c.getComputedStyle(i), a = c.getComputedStyle(s);
1107
+ let u = null;
1108
+ const f = t.on("change", () => {
1109
+ null == u && (u = setTimeout(() => {
1110
+ u = null;
1095
1111
  const o = $(n, r, t.doc, t.selection);
1096
- let l = o.getBoundingClientRect();
1097
- if (!l.height) {
1112
+ let f = o.getBoundingClientRect();
1113
+ if (!f.width && !f.height) {
1098
1114
  const t = o.startContainer, e = z(t) ? t : t.parentElement;
1099
- e && (l = e.getBoundingClientRect());
1115
+ e && (f = e.getBoundingClientRect());
1100
1116
  }
1101
- const a = s ? ((t, e, n, r) => {
1102
- const {scrollLeft: o, scrollTop: c, scrollWidth: s, scrollHeight: i, clientLeft: l, clientTop: a, clientWidth: u, clientHeight: f} = e, p = e.getBoundingClientRect(), d = t.getComputedStyle(e), h = kt(yt(n.top, n.bottom, xt(p.top + a, f, d.scrollPaddingTop, d.scrollPaddingBottom)), c, i - f), x = kt(yt(n.left, n.right, xt(p.left + l, u, d.scrollPaddingLeft, d.scrollPaddingRight)), o, s - u);
1103
- return (h || x) && e.scrollBy({
1104
- top: h,
1105
- left: x,
1106
- behavior: r
1107
- }), [ x, h ];
1108
- })(c, s, l, e) : [ 0, 0 ];
1109
- ((t, e, [n, r], o) => {
1110
- const {documentElement: c} = t.document, {clientWidth: s, clientHeight: i} = c, l = t.getComputedStyle(c), a = yt(e.top - r, e.bottom - r, xt(0, i, l.scrollPaddingTop, l.scrollPaddingBottom)), u = yt(e.left - n, e.right - n, xt(0, s, l.scrollPaddingLeft, l.scrollPaddingRight));
1111
- (a || u) && t.scrollBy({
1112
- top: a,
1113
- left: u,
1114
- behavior: o
1115
- });
1116
- })(c, l, a, e);
1117
+ const p = i && l ? ((t, e, n) => {
1118
+ const {scrollLeft: r, scrollTop: o, scrollWidth: c, scrollHeight: s, clientLeft: i, clientTop: l, clientWidth: a, clientHeight: u} = t, f = t.getBoundingClientRect(), [p, d] = (t => {
1119
+ const e = "rtl" === t.direction;
1120
+ switch (t.writingMode) {
1121
+ case "vertical-rl":
1122
+ case "sideways-rl":
1123
+ return [ !0, e ];
1124
+
1125
+ case "vertical-lr":
1126
+ return [ !1, e ];
1127
+
1128
+ case "sideways-lr":
1129
+ return [ !1, !e ];
1130
+
1131
+ default:
1132
+ return [ e, !1 ];
1133
+ }
1134
+ })(e), h = kt(xt(n.top, n.bottom, ht(f.top + l, u, e.scrollPaddingTop, e.scrollPaddingBottom)), o, s - u, d);
1135
+ return [ kt(xt(n.left, n.right, ht(f.left + i, a, e.scrollPaddingLeft, e.scrollPaddingRight)), r, c - a, p), h ];
1136
+ })(i, l, f) : [ 0, 0 ], d = ((t, e, n, [r, o]) => {
1137
+ const {clientWidth: c, clientHeight: s} = t, i = xt(n.top - o, n.bottom - o, ht(0, s, e.scrollPaddingTop, e.scrollPaddingBottom));
1138
+ return [ xt(n.left - r, n.right - r, ht(0, c, e.scrollPaddingLeft, e.scrollPaddingRight)), i ];
1139
+ })(s, a, f, p);
1140
+ i && mt(i, p, e), mt(c, d, e);
1117
1141
  }, 50));
1118
1142
  });
1119
1143
  return () => {
1120
- null != i && clearTimeout(i), l();
1144
+ null != u && clearTimeout(u), f();
1121
1145
  };
1122
1146
  });
1123
1147
  }, exports.selectionRectPlugin = function(t, e) {
@@ -1135,5 +1159,5 @@ exports.getNodeSize = p, exports.htmlTransferPlugin = function(t, e) {
1135
1159
  o = !1, s();
1136
1160
  };
1137
1161
  });
1138
- }, exports.singlelinePlugin = mt, exports.sliceText = E;
1162
+ }, exports.singlelinePlugin = gt, exports.sliceText = E;
1139
1163
  //# sourceMappingURL=index.cjs.map