quoin-editor 1.2.3 → 1.4.0

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.
Files changed (180) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/THIRD_PARTY_NOTICES.md +47 -0
  3. package/dist/ai.cjs +69 -70
  4. package/dist/ai.cjs.map +1 -1
  5. package/dist/ai.d.cts +4 -3
  6. package/dist/ai.d.ts +4 -3
  7. package/dist/ai.js +4 -5
  8. package/dist/ai.js.map +1 -1
  9. package/dist/catalogue.cjs +20 -20
  10. package/dist/catalogue.d.cts +10 -9
  11. package/dist/catalogue.d.ts +10 -9
  12. package/dist/catalogue.js +12 -12
  13. package/dist/{chunk-35CHEARK.cjs → chunk-3NVFHJFS.cjs} +42 -41
  14. package/dist/chunk-3NVFHJFS.cjs.map +1 -0
  15. package/dist/{chunk-BR25RE7U.js → chunk-3YA7FYEL.js} +9 -6
  16. package/dist/chunk-3YA7FYEL.js.map +1 -0
  17. package/dist/{chunk-CZ5ZXBWC.cjs → chunk-65WK575V.cjs} +762 -306
  18. package/dist/chunk-65WK575V.cjs.map +1 -0
  19. package/dist/{chunk-Y7UKOBSY.js → chunk-6LOYAC5N.js} +7 -6
  20. package/dist/chunk-6LOYAC5N.js.map +1 -0
  21. package/dist/{chunk-KMIWUFNM.cjs → chunk-7WSBPD6Z.cjs} +96 -93
  22. package/dist/chunk-7WSBPD6Z.cjs.map +1 -0
  23. package/dist/{chunk-TARBFPWC.js → chunk-AC4AFDTI.js} +6 -6
  24. package/dist/{chunk-TARBFPWC.js.map → chunk-AC4AFDTI.js.map} +1 -1
  25. package/dist/{chunk-SCFW4JFT.cjs → chunk-AZ2ZNSFN.cjs} +43 -44
  26. package/dist/chunk-AZ2ZNSFN.cjs.map +1 -0
  27. package/dist/{chunk-ZVCBTQA3.cjs → chunk-AZF7B2AE.cjs} +10 -10
  28. package/dist/{chunk-ZVCBTQA3.cjs.map → chunk-AZF7B2AE.cjs.map} +1 -1
  29. package/dist/{chunk-DQV37F7J.cjs → chunk-FQDNF7MF.cjs} +68 -69
  30. package/dist/chunk-FQDNF7MF.cjs.map +1 -0
  31. package/dist/{chunk-25HNTVEI.js → chunk-G25FMFEZ.js} +3 -3
  32. package/dist/{chunk-25HNTVEI.js.map → chunk-G25FMFEZ.js.map} +1 -1
  33. package/dist/{chunk-A5LIN7FO.cjs → chunk-H5FM6I5W.cjs} +26 -26
  34. package/dist/{chunk-A5LIN7FO.cjs.map → chunk-H5FM6I5W.cjs.map} +1 -1
  35. package/dist/{chunk-YCVNFRL3.js → chunk-IJKGF6SC.js} +4 -4
  36. package/dist/{chunk-YCVNFRL3.js.map → chunk-IJKGF6SC.js.map} +1 -1
  37. package/dist/{chunk-4HFE3YFF.js → chunk-KRLHGVJV.js} +8 -7
  38. package/dist/chunk-KRLHGVJV.js.map +1 -0
  39. package/dist/{chunk-J552D3A7.js → chunk-MQTLZTIM.js} +448 -25
  40. package/dist/chunk-MQTLZTIM.js.map +1 -0
  41. package/dist/{chunk-KXOAV7AT.js → chunk-OS2O6IKX.js} +135 -12
  42. package/dist/chunk-OS2O6IKX.js.map +1 -0
  43. package/dist/{chunk-OGBD74IR.cjs → chunk-QJ34MOFV.cjs} +187 -117
  44. package/dist/chunk-QJ34MOFV.cjs.map +1 -0
  45. package/dist/{chunk-SAPLIQF2.js → chunk-QOIVLYMW.js} +4 -4
  46. package/dist/{chunk-SAPLIQF2.js.map → chunk-QOIVLYMW.js.map} +1 -1
  47. package/dist/{chunk-IGEWAL2J.cjs → chunk-QPOUONJ7.cjs} +32 -31
  48. package/dist/chunk-QPOUONJ7.cjs.map +1 -0
  49. package/dist/{chunk-K7JEN3KT.cjs → chunk-QR2NIDUK.cjs} +4 -4
  50. package/dist/{chunk-K7JEN3KT.cjs.map → chunk-QR2NIDUK.cjs.map} +1 -1
  51. package/dist/{chunk-4D7HZRNC.js → chunk-R7MYG522.js} +3 -3
  52. package/dist/{chunk-4D7HZRNC.js.map → chunk-R7MYG522.js.map} +1 -1
  53. package/dist/{chunk-BNUQ647G.js → chunk-STCJWXP5.js} +5 -6
  54. package/dist/chunk-STCJWXP5.js.map +1 -0
  55. package/dist/{chunk-BJIWN7BQ.cjs → chunk-STKGRXSA.cjs} +10 -10
  56. package/dist/{chunk-BJIWN7BQ.cjs.map → chunk-STKGRXSA.cjs.map} +1 -1
  57. package/dist/{chunk-5ANJW76W.cjs → chunk-VUYJGFUA.cjs} +23 -22
  58. package/dist/chunk-VUYJGFUA.cjs.map +1 -0
  59. package/dist/{chunk-FOEEDJ5R.js → chunk-VVS6JJLI.js} +7 -6
  60. package/dist/chunk-VVS6JJLI.js.map +1 -0
  61. package/dist/{chunk-G37GQ5JE.cjs → chunk-VZZPCYA3.cjs} +135 -12
  62. package/dist/chunk-VZZPCYA3.cjs.map +1 -0
  63. package/dist/{chunk-JYKSWEXT.cjs → chunk-WN7BZDNH.cjs} +6 -6
  64. package/dist/{chunk-JYKSWEXT.cjs.map → chunk-WN7BZDNH.cjs.map} +1 -1
  65. package/dist/{chunk-CCOPHCXX.js → chunk-XFEDJEJF.js} +109 -39
  66. package/dist/chunk-XFEDJEJF.js.map +1 -0
  67. package/dist/{chunk-I7OOIEZZ.js → chunk-YEQEBJPM.js} +5 -6
  68. package/dist/chunk-YEQEBJPM.js.map +1 -0
  69. package/dist/comments.cjs +54 -54
  70. package/dist/comments.cjs.map +1 -1
  71. package/dist/comments.d.cts +4 -3
  72. package/dist/comments.d.ts +4 -3
  73. package/dist/comments.js +8 -8
  74. package/dist/comments.js.map +1 -1
  75. package/dist/diff.d.cts +7 -5
  76. package/dist/diff.d.ts +7 -5
  77. package/dist/docx.cjs +1 -1
  78. package/dist/docx.d.cts +3 -2
  79. package/dist/docx.d.ts +3 -2
  80. package/dist/docx.js +1 -1
  81. package/dist/embed.cjs +6 -6
  82. package/dist/embed.d.cts +5 -4
  83. package/dist/embed.d.ts +5 -4
  84. package/dist/embed.js +4 -4
  85. package/dist/emoji-data.cjs +272 -263
  86. package/dist/emoji-data.cjs.map +1 -1
  87. package/dist/emoji-data.js +272 -263
  88. package/dist/emoji-data.js.map +1 -1
  89. package/dist/{emoji-extension-CmPlRssm.d.ts → emoji-extension-C3o_Y5uC.d.cts} +3 -2
  90. package/dist/{emoji-extension-zJ6F7hW8.d.cts → emoji-extension-gRKnbW8G.d.ts} +3 -2
  91. package/dist/emoji.cjs +7 -7
  92. package/dist/emoji.d.cts +6 -5
  93. package/dist/emoji.d.ts +6 -5
  94. package/dist/emoji.js +4 -4
  95. package/dist/engine.cjs +43 -43
  96. package/dist/engine.d.cts +7 -6
  97. package/dist/engine.d.ts +7 -6
  98. package/dist/engine.js +1 -1
  99. package/dist/{find-extension-CmFehyul.d.ts → find-extension-BGGsJMu4.d.cts} +3 -2
  100. package/dist/{find-extension-BcRyE9K4.d.cts → find-extension-B_Ctrs6T.d.ts} +3 -2
  101. package/dist/find.cjs +8 -8
  102. package/dist/find.d.cts +5 -4
  103. package/dist/find.d.ts +5 -4
  104. package/dist/find.js +4 -4
  105. package/dist/headless.cjs +59 -59
  106. package/dist/headless.d.cts +10 -9
  107. package/dist/headless.d.ts +10 -9
  108. package/dist/headless.js +2 -2
  109. package/dist/{index-DiCGV60d.d.ts → index-CsG7OQoq.d.cts} +3 -2
  110. package/dist/{index-CFPmCee4.d.cts → index-h1llgZM-.d.ts} +3 -2
  111. package/dist/index.cjs +71 -71
  112. package/dist/index.d.cts +11 -10
  113. package/dist/index.d.ts +11 -10
  114. package/dist/index.js +3 -3
  115. package/dist/math.cjs +7 -7
  116. package/dist/math.d.cts +5 -4
  117. package/dist/math.d.ts +5 -4
  118. package/dist/math.js +5 -5
  119. package/dist/mention.cjs +7 -7
  120. package/dist/mention.d.cts +4 -3
  121. package/dist/mention.d.ts +4 -3
  122. package/dist/mention.js +5 -5
  123. package/dist/presence.cjs +33 -33
  124. package/dist/presence.d.cts +5 -4
  125. package/dist/presence.d.ts +5 -4
  126. package/dist/presence.js +5 -5
  127. package/dist/{registry-CXegaw5k.d.ts → registry-DdQaddP1.d.cts} +2 -1
  128. package/dist/{registry-CXegaw5k.d.cts → registry-DdQaddP1.d.ts} +2 -1
  129. package/dist/{stats-extension-DisOEbbI.d.ts → stats-extension-XqOTvRaq.d.cts} +3 -2
  130. package/dist/{stats-extension-Dt1lgP3m.d.cts → stats-extension-oD6D1cYy.d.ts} +3 -2
  131. package/dist/stats.cjs +7 -7
  132. package/dist/stats.d.cts +6 -5
  133. package/dist/stats.d.ts +6 -5
  134. package/dist/stats.js +4 -4
  135. package/dist/styles.css +1 -1
  136. package/dist/{table-extension-DxZz3jqp.d.cts → table-extension-BP47hHoz.d.cts} +3 -2
  137. package/dist/{table-extension-BTMJnT7J.d.ts → table-extension-v6VB59bF.d.ts} +3 -2
  138. package/dist/table.cjs +23 -23
  139. package/dist/table.d.cts +5 -4
  140. package/dist/table.d.ts +5 -4
  141. package/dist/table.js +4 -4
  142. package/dist/{to-html-CNCITCln.d.cts → to-html-1oD-CDle.d.cts} +3 -2
  143. package/dist/{to-html-C5t7xyaM.d.ts → to-html-CLRBCX0I.d.ts} +3 -2
  144. package/dist/{toc-extension-DGHywOBv.d.cts → toc-extension-CI6jNOYl.d.cts} +3 -2
  145. package/dist/{toc-extension-CR9U-l6j.d.ts → toc-extension-CTHWjNJC.d.ts} +3 -2
  146. package/dist/toc.cjs +7 -7
  147. package/dist/toc.d.cts +5 -4
  148. package/dist/toc.d.ts +5 -4
  149. package/dist/toc.js +4 -4
  150. package/dist/{types-C6_QkXzy.d.ts → types-BjLcmV00.d.ts} +3 -26
  151. package/dist/{types-DULc8wwg.d.ts → types-CQ8Vw_7N.d.cts} +27 -1
  152. package/dist/{types-DULc8wwg.d.cts → types-CQ8Vw_7N.d.ts} +27 -1
  153. package/dist/{types-CJ7Gq3GX.d.cts → types-DXF9p4qV.d.cts} +3 -26
  154. package/dist/{view-controller-zNqHm_Qg.d.ts → view-controller-BfVSNZYZ.d.cts} +4 -3
  155. package/dist/{view-controller-cxQJ5rQb.d.cts → view-controller-p-2x3J7Y.d.ts} +4 -3
  156. package/dist/view.d.cts +7 -5
  157. package/dist/view.d.ts +7 -5
  158. package/dist/yjs.cjs +99 -99
  159. package/dist/yjs.d.cts +4 -4
  160. package/dist/yjs.d.ts +4 -4
  161. package/dist/yjs.js +3 -3
  162. package/package.json +19 -18
  163. package/dist/chunk-35CHEARK.cjs.map +0 -1
  164. package/dist/chunk-4HFE3YFF.js.map +0 -1
  165. package/dist/chunk-5ANJW76W.cjs.map +0 -1
  166. package/dist/chunk-BNUQ647G.js.map +0 -1
  167. package/dist/chunk-BR25RE7U.js.map +0 -1
  168. package/dist/chunk-CCOPHCXX.js.map +0 -1
  169. package/dist/chunk-CZ5ZXBWC.cjs.map +0 -1
  170. package/dist/chunk-DQV37F7J.cjs.map +0 -1
  171. package/dist/chunk-FOEEDJ5R.js.map +0 -1
  172. package/dist/chunk-G37GQ5JE.cjs.map +0 -1
  173. package/dist/chunk-I7OOIEZZ.js.map +0 -1
  174. package/dist/chunk-IGEWAL2J.cjs.map +0 -1
  175. package/dist/chunk-J552D3A7.js.map +0 -1
  176. package/dist/chunk-KMIWUFNM.cjs.map +0 -1
  177. package/dist/chunk-KXOAV7AT.js.map +0 -1
  178. package/dist/chunk-OGBD74IR.cjs.map +0 -1
  179. package/dist/chunk-SCFW4JFT.cjs.map +0 -1
  180. package/dist/chunk-Y7UKOBSY.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkG37GQ5JE_cjs = require('./chunk-G37GQ5JE.cjs');
3
+ var chunkVZZPCYA3_cjs = require('./chunk-VZZPCYA3.cjs');
4
4
  var chunkWZA5S5EJ_cjs = require('./chunk-WZA5S5EJ.cjs');
5
5
  var react = require('react');
6
6
  var reactDom = require('react-dom');
@@ -34,7 +34,7 @@ function isCrossSelection(selection) {
34
34
  }
35
35
  function selectionDecorations(state, mode) {
36
36
  if (mode !== "decorations" || !isCrossSelection(state.selection)) return [];
37
- return chunkG37GQ5JE_cjs.markRanges(state).map(({ block, region, from, to }) => ({
37
+ return chunkVZZPCYA3_cjs.markRanges(state).map(({ block, region, from, to }) => ({
38
38
  kind: "inline",
39
39
  block,
40
40
  region,
@@ -339,8 +339,8 @@ function reconcileChildren(parent, specs) {
339
339
  // src/view/dom/text-diff.ts
340
340
  function textDiff(before, after, caretHint) {
341
341
  if (before === after) return null;
342
- const prefix = chunkG37GQ5JE_cjs.commonPrefix(before, after);
343
- const suffix = chunkG37GQ5JE_cjs.commonSuffix(before, after);
342
+ const prefix = chunkVZZPCYA3_cjs.commonPrefix(before, after);
343
+ const suffix = chunkVZZPCYA3_cjs.commonSuffix(before, after);
344
344
  const shared = Math.min(suffix, Math.min(before.length, after.length) - prefix);
345
345
  const removed = before.length - prefix - shared;
346
346
  const inserted = after.length - prefix - shared;
@@ -528,10 +528,10 @@ function readSelection(registry, domSelection, blockAt2 = () => void 0) {
528
528
  if (!domSelection || !anchorNode || !focusNode) return null;
529
529
  const anchor = domToPos(registry, anchorNode, domSelection.anchorOffset);
530
530
  const head = domToPos(registry, focusNode, domSelection.focusOffset);
531
- if (anchor && head) return chunkG37GQ5JE_cjs.textSelection(anchor, head);
531
+ if (anchor && head) return chunkVZZPCYA3_cjs.textSelection(anchor, head);
532
532
  if (anchor || head || registry.locate(anchorNode) || registry.locate(focusNode)) return null;
533
533
  const block = blockAt2(anchorNode);
534
- return block !== void 0 && block === blockAt2(focusNode) ? chunkG37GQ5JE_cjs.nodeSelection(block) : null;
534
+ return block !== void 0 && block === blockAt2(focusNode) ? chunkVZZPCYA3_cjs.nodeSelection(block) : null;
535
535
  }
536
536
  function selectBlock(domSelection, element) {
537
537
  if (!element) return false;
@@ -542,17 +542,38 @@ function selectBlock(domSelection, element) {
542
542
  }
543
543
  return true;
544
544
  }
545
+ var drawnUpstream = /* @__PURE__ */ new WeakMap();
546
+ function drawUpstream(registry, pos, domSelection, drawn) {
547
+ const caret = chunkVZZPCYA3_cjs.textSelection(pos);
548
+ const isAt = () => chunkVZZPCYA3_cjs.sameSelection(readSelection(registry, domSelection), caret);
549
+ if (drawn?.node === domSelection.focusNode && drawn.offset === domSelection.focusOffset && isAt()) {
550
+ drawnUpstream.set(domSelection, drawn);
551
+ return true;
552
+ }
553
+ const before = pos.offset > 0 && posToDom(registry, { ...pos, offset: pos.offset - 1 });
554
+ if (!before || typeof domSelection.modify !== "function") return false;
555
+ domSelection.collapse(before.node, before.offset);
556
+ domSelection.modify("move", "forward", "lineboundary");
557
+ drawnUpstream.set(domSelection, { node: domSelection.focusNode, offset: domSelection.focusOffset });
558
+ return isAt();
559
+ }
545
560
  function writeSelection(registry, selection, domSelection, blockElement) {
546
561
  if (!selection || !domSelection) return false;
547
562
  if (selection.kind === "node") return selectBlock(domSelection, blockElement(selection.block));
548
563
  if (selection.kind !== "text") return false;
549
564
  const { anchor, head } = selection;
550
565
  if (anchor.block !== head.block || anchor.region !== head.region) return false;
551
- if (chunkG37GQ5JE_cjs.sameSelection(readSelection(registry, domSelection), selection)) return true;
566
+ const drawn = drawnUpstream.get(domSelection);
567
+ drawnUpstream.delete(domSelection);
568
+ if (chunkVZZPCYA3_cjs.sameSelection(readSelection(registry, domSelection), selection)) return true;
569
+ if (selection.assoc === -1 && anchor.offset === head.offset && drawUpstream(registry, head, domSelection, drawn)) {
570
+ return true;
571
+ }
552
572
  const base = posToDom(registry, anchor, anchor.offset < head.offset ? 1 : -1);
553
573
  const extent = posToDom(registry, head, head.offset < anchor.offset ? 1 : -1);
554
574
  if (!base || !extent) return false;
555
575
  domSelection.setBaseAndExtent(base.node, base.offset, extent.node, extent.offset);
576
+ if (selection.assoc === -1) drawnUpstream.set(domSelection, extent);
556
577
  return true;
557
578
  }
558
579
 
@@ -565,6 +586,56 @@ function listen(target, handlers, options) {
565
586
  };
566
587
  }
567
588
 
589
+ // src/view/controller/dispatch-selection.ts
590
+ var dispatchSelection = (controller, selection) => controller.dispatch(controller.editor.createTransaction().setSelection(selection));
591
+
592
+ // src/view/navigation/glyph.ts
593
+ function glyphAt(registry, pos) {
594
+ const host = registry.get(pos.block, pos.region);
595
+ const map = host && domMapOf(host);
596
+ if (!host || !map || pos.offset < 0 || pos.offset >= map.length) return null;
597
+ const start = map.toDom(pos.offset, 1);
598
+ const end = map.toDom(pos.offset + 1, -1);
599
+ const range = host.ownerDocument.createRange();
600
+ range.setStart(start.node, start.offset);
601
+ range.setEnd(end.node, end.offset);
602
+ return range;
603
+ }
604
+ function upstreamCaret(registry, pos) {
605
+ const rect = glyphAt(registry, { ...pos, offset: pos.offset - 1 })?.getBoundingClientRect();
606
+ return rect ? new DOMRect(rect.right, rect.top, 0, rect.height) : null;
607
+ }
608
+ var glyphsAround = (registry, pos) => (offset) => {
609
+ const range = glyphAt(registry, { ...pos, offset });
610
+ return range && { rect: range.getBoundingClientRect(), text: range.toString() };
611
+ };
612
+
613
+ // src/view/navigation/stay-on-line.ts
614
+ var onLine = (glyph, y) => glyph !== null && glyph.rect.top <= y && y <= glyph.rect.bottom;
615
+ function wrapsAt(pos, y, glyphAt2) {
616
+ const before = pos.offset > 0 ? glyphAt2(pos.offset - 1) : null;
617
+ const after = glyphAt2(pos.offset);
618
+ return after !== null && !onLine(after, y) && onLine(before, y) ? before : null;
619
+ }
620
+ function stayOnLine(pos, y, glyphAt2) {
621
+ const caret = chunkVZZPCYA3_cjs.textSelection(pos);
622
+ const before = wrapsAt(pos, y, glyphAt2);
623
+ if (before === null) return caret;
624
+ return /\S/.test(before.text) ? { ...caret, assoc: -1 } : chunkVZZPCYA3_cjs.textSelection({ ...pos, offset: pos.offset - 1 });
625
+ }
626
+
627
+ // src/view/navigation/clicked-side.ts
628
+ function keepClickedSide(controller, y) {
629
+ controller.readSelectionFromDom();
630
+ const { selection } = controller.editor.state;
631
+ if (selection?.kind !== "text" || !chunkVZZPCYA3_cjs.isCollapsed(selection)) return;
632
+ const upstream = wrapsAt(selection.head, y, glyphsAround(controller.registry, selection.head)) !== null;
633
+ if (upstream !== (selection.assoc === -1)) {
634
+ const caret = chunkVZZPCYA3_cjs.textSelection(selection.head);
635
+ dispatchSelection(controller, upstream ? { ...caret, assoc: -1 } : caret);
636
+ }
637
+ }
638
+
568
639
  // src/view/navigation/node-entry.ts
569
640
  var NODE_ENTRY = "data-quoin-node-entry";
570
641
  var entersAsNode = (controller, block) => controller.blockElement(block)?.querySelector(`[${NODE_ENTRY}]`) != null;
@@ -610,8 +681,8 @@ var known = /* @__PURE__ */ new WeakMap();
610
681
  function hidersOf(doc) {
611
682
  let hiders = known.get(doc);
612
683
  if (hiders === void 0) {
613
- const first = doc.blocks.findIndex(chunkG37GQ5JE_cjs.isClosedToggle);
614
- hiders = doc.blocks.map((_, index) => first < 0 || index <= first ? null : chunkG37GQ5JE_cjs.hidingToggle(doc, index + 1));
684
+ const first = doc.blocks.findIndex(chunkVZZPCYA3_cjs.isClosedToggle);
685
+ hiders = doc.blocks.map((_, index) => first < 0 || index <= first ? null : chunkVZZPCYA3_cjs.hidingToggle(doc, index + 1));
615
686
  known.set(doc, hiders);
616
687
  }
617
688
  return hiders;
@@ -620,7 +691,7 @@ var hidingToggleAt = (doc, index) => hidersOf(doc)[index] ?? null;
620
691
  function isHiddenAt(doc, index, choices) {
621
692
  if (choices.size === 0) return hidingToggleAt(doc, index) !== null;
622
693
  const closed = (block) => block.type === "TOGGLE" && !shownOpen(block, choices);
623
- return chunkG37GQ5JE_cjs.hidingToggle(doc, index + 1, closed) !== null;
694
+ return chunkVZZPCYA3_cjs.hidingToggle(doc, index + 1, closed) !== null;
624
695
  }
625
696
  var visibleBlockIndexes = (doc) => hidersOf(doc).flatMap((hider, index) => hider === null ? [index] : []);
626
697
  function drawnBlockCount(doc, start = 0, end = doc.blocks.length) {
@@ -630,9 +701,6 @@ function drawnBlockCount(doc, start = 0, end = doc.blocks.length) {
630
701
  return drawn;
631
702
  }
632
703
 
633
- // src/view/controller/dispatch-selection.ts
634
- var dispatchSelection = (controller, selection) => controller.dispatch(controller.editor.createTransaction().setSelection(selection));
635
-
636
704
  // src/view/navigation/neighbour-block.ts
637
705
  var anyBlock = () => true;
638
706
  function neighbourBlock(doc, from, direction, accept = anyBlock) {
@@ -645,18 +713,18 @@ function neighbourBlock(doc, from, direction, accept = anyBlock) {
645
713
  }
646
714
  function entryEdge(controller, block, direction) {
647
715
  const { doc, schema } = controller.editor.state;
648
- const edge = direction < 0 ? chunkG37GQ5JE_cjs.endOf(doc, schema, block) : chunkG37GQ5JE_cjs.startOf(doc, schema, block);
716
+ const edge = direction < 0 ? chunkVZZPCYA3_cjs.endOf(doc, schema, block) : chunkVZZPCYA3_cjs.startOf(doc, schema, block);
649
717
  if (edge.kind !== "text") return edge;
650
718
  const drawn = controller.registry.get(edge.head.block, edge.head.region) !== void 0;
651
- return drawn && !entersAsNode(controller, block) ? edge : chunkG37GQ5JE_cjs.nodeSelection(block);
719
+ return drawn && !entersAsNode(controller, block) ? edge : chunkVZZPCYA3_cjs.nodeSelection(block);
652
720
  }
653
- var ownNode = (controller, block, direction) => direction < 0 && entersAsNode(controller, block) ? chunkG37GQ5JE_cjs.nodeSelection(block) : null;
721
+ var ownNode = (controller, block, direction) => direction < 0 && entersAsNode(controller, block) ? chunkVZZPCYA3_cjs.nodeSelection(block) : null;
654
722
  var canBeEntered = (controller) => (block) => {
655
723
  const { schema } = controller.editor.state;
656
- const region = chunkG37GQ5JE_cjs.isTextFlow(schema, block) ? chunkG37GQ5JE_cjs.primaryRegion(schema, block) : null;
724
+ const region = chunkVZZPCYA3_cjs.isTextFlow(schema, block) ? chunkVZZPCYA3_cjs.primaryRegion(schema, block) : null;
657
725
  return region === null || controller.registry.get(block.id, region) !== void 0 || entersAsNode(controller, block.id);
658
726
  };
659
- var holdsTextHead = (controller) => (block) => chunkG37GQ5JE_cjs.isTextFlow(controller.editor.state.schema, block) && entryEdge(controller, block.id, 1).kind === "text";
727
+ var holdsTextHead = (controller) => (block) => chunkVZZPCYA3_cjs.isTextFlow(controller.editor.state.schema, block) && entryEdge(controller, block.id, 1).kind === "text";
660
728
  function neighbourHead(controller, from, direction) {
661
729
  const target = neighbourBlock(controller.editor.state.doc, from, direction, holdsTextHead(controller));
662
730
  const edge = target && entryEdge(controller, target.id, direction);
@@ -795,7 +863,7 @@ function createCrossBlockPointer(controller) {
795
863
  let preventMouseDown = false;
796
864
  const scroll = createAutoScroll(root, () => follow(last.x, last.y));
797
865
  function select(selection) {
798
- if (chunkG37GQ5JE_cjs.sameSelection(selection, controller.editor.state.selection)) return;
866
+ if (chunkVZZPCYA3_cjs.sameSelection(selection, controller.editor.state.selection)) return;
799
867
  dispatchSelection(controller, selection);
800
868
  }
801
869
  function startDragging() {
@@ -811,14 +879,14 @@ function createCrossBlockPointer(controller) {
811
879
  if (current.anchor === null) return;
812
880
  startDragging();
813
881
  }
814
- select(chunkG37GQ5JE_cjs.textSelection(current.anchor, caretPosAt(controller, target, x, y)));
882
+ select(chunkVZZPCYA3_cjs.textSelection(current.anchor, caretPosAt(controller, target, x, y)));
815
883
  }
816
884
  function followBlocks(current, x, y) {
817
885
  if (!controller.dragging && Math.hypot(x - current.x, y - current.y) < DRAG_DISTANCE) return;
818
886
  const block = blockAt(controller, x, y);
819
887
  if (block === null) return;
820
888
  startDragging();
821
- select(chunkG37GQ5JE_cjs.blockRangeSelection(current.start, block));
889
+ select(chunkVZZPCYA3_cjs.blockRangeSelection(current.start, block));
822
890
  }
823
891
  function follow(x, y) {
824
892
  if (press?.kind === "text") followText(press, x, y);
@@ -836,6 +904,11 @@ function createCrossBlockPointer(controller) {
836
904
  function end() {
837
905
  if (release()) controller.focus();
838
906
  }
907
+ function onPointerUp(event) {
908
+ const clicked = press?.kind === "text" && !controller.dragging;
909
+ end();
910
+ if (clicked) keepClickedSide(controller, event.clientY);
911
+ }
839
912
  function onPointerMove(event) {
840
913
  if ((event.buttons & 1) === 0) return end();
841
914
  last = { x: event.clientX, y: event.clientY };
@@ -854,9 +927,9 @@ function createCrossBlockPointer(controller) {
854
927
  function pressWhole(block) {
855
928
  if (entryEdge(controller, block, 1).kind !== "node") return;
856
929
  const pressed = chunkWZA5S5EJ_cjs.blockById(controller.editor.state.doc, block);
857
- if (pressed !== void 0 && !canBeEntered(controller)(pressed)) return select(chunkG37GQ5JE_cjs.blockRangeSelection(block));
930
+ if (pressed !== void 0 && !canBeEntered(controller)(pressed)) return select(chunkVZZPCYA3_cjs.blockRangeSelection(block));
858
931
  controller.nodeReveal.pressed(block);
859
- select(chunkG37GQ5JE_cjs.nodeSelection(block));
932
+ select(chunkVZZPCYA3_cjs.nodeSelection(block));
860
933
  }
861
934
  function onPointerDown(event) {
862
935
  end();
@@ -875,7 +948,11 @@ function createCrossBlockPointer(controller) {
875
948
  } else {
876
949
  return;
877
950
  }
878
- const unfollowDocument = listen(doc, { pointermove: onPointerMove, pointerup: end, pointercancel: end });
951
+ const unfollowDocument = listen(doc, {
952
+ pointermove: onPointerMove,
953
+ pointerup: onPointerUp,
954
+ pointercancel: end
955
+ });
879
956
  const unfollowView = listen(view, { blur: end });
880
957
  unfollow = () => {
881
958
  unfollowDocument();
@@ -898,7 +975,7 @@ function createCrossBlockPointer(controller) {
898
975
  // src/view/selection/paint-selection.ts
899
976
  var NAME = "quoin-selection";
900
977
  function coveredRanges(controller) {
901
- return chunkG37GQ5JE_cjs.markRanges(controller.editor.state).flatMap(({ block, region, from, to }) => {
978
+ return chunkVZZPCYA3_cjs.markRanges(controller.editor.state).flatMap(({ block, region, from, to }) => {
902
979
  const host = controller.registry.get(block, region);
903
980
  const map = host && domMapOf(host);
904
981
  if (!host || !map) return [];
@@ -969,7 +1046,7 @@ function heldBySink(selection) {
969
1046
  }
970
1047
  var NO_TEXT = "\xA0";
971
1048
  function selectionText(state) {
972
- const text = chunkG37GQ5JE_cjs.markRanges(state).map((range) => chunkWZA5S5EJ_cjs.inlinePlainText(chunkG37GQ5JE_cjs.rangeContent(state, range), state.schema)).join("\n");
1049
+ const text = chunkVZZPCYA3_cjs.markRanges(state).map((range) => chunkWZA5S5EJ_cjs.inlinePlainText(chunkVZZPCYA3_cjs.rangeContent(state, range), state.schema)).join("\n");
973
1050
  return text === "" ? NO_TEXT : text;
974
1051
  }
975
1052
  var focusInPlace = (sink) => inPlace(sink, () => sink.focus({ preventScroll: true }));
@@ -1129,7 +1206,7 @@ function createElementSlot(changed) {
1129
1206
 
1130
1207
  // src/view/controller/selection-element.ts
1131
1208
  function elementFor({ doc }, selection, rendered) {
1132
- const id = chunkG37GQ5JE_cjs.headBlockId(selection);
1209
+ const id = chunkVZZPCYA3_cjs.headBlockId(selection);
1133
1210
  const index = id === null ? void 0 : doc.index.get(id);
1134
1211
  if (id === null || index === void 0) return void 0;
1135
1212
  const hiding = hidingToggleAt(doc, index);
@@ -1142,7 +1219,7 @@ function selectionElement(state, rendered) {
1142
1219
  if (doc.blocks.length === 0) return rendered.empty?.() ?? void 0;
1143
1220
  const sink = heldBySink(selection) ? rendered.sink?.() : null;
1144
1221
  if (sink) return sink;
1145
- return elementFor(state, selection, rendered) ?? elementFor(state, chunkG37GQ5JE_cjs.startOf(doc, schema, doc.blocks[0].id), rendered);
1222
+ return elementFor(state, selection, rendered) ?? elementFor(state, chunkVZZPCYA3_cjs.startOf(doc, schema, doc.blocks[0].id), rendered);
1146
1223
  }
1147
1224
 
1148
1225
  // src/view/controller/tab-stop.ts
@@ -1196,7 +1273,7 @@ function createDrawnElements(hosts, state) {
1196
1273
  }
1197
1274
 
1198
1275
  // src/view/controller/engagement.ts
1199
- var chosenHere = (tr) => tr !== null && tr.selectionSet && !chunkG37GQ5JE_cjs.foreignOrigins.includes(tr.origin);
1276
+ var chosenHere = (tr) => tr !== null && tr.selectionSet && !chunkVZZPCYA3_cjs.foreignOrigins.includes(tr.origin);
1200
1277
  function createEngagement(editor) {
1201
1278
  let engaged = false;
1202
1279
  const listeners = /* @__PURE__ */ new Set();
@@ -1234,9 +1311,9 @@ function ownsFocus(controller, doc) {
1234
1311
  function focusTarget(state, target) {
1235
1312
  const { doc, schema, selection } = state;
1236
1313
  if (doc.blocks.length === 0) return null;
1237
- if (target === "end") return chunkG37GQ5JE_cjs.endOf(doc, schema, doc.blocks[doc.blocks.length - 1].id);
1238
- if (target === "start" || target === void 0 && selection === null) return chunkG37GQ5JE_cjs.startOf(doc, schema, doc.blocks[0].id);
1239
- return target === void 0 ? selection : chunkG37GQ5JE_cjs.textSelection(target);
1314
+ if (target === "end") return chunkVZZPCYA3_cjs.endOf(doc, schema, doc.blocks[doc.blocks.length - 1].id);
1315
+ if (target === "start" || target === void 0 && selection === null) return chunkVZZPCYA3_cjs.startOf(doc, schema, doc.blocks[0].id);
1316
+ return target === void 0 ? selection : chunkVZZPCYA3_cjs.textSelection(target);
1240
1317
  }
1241
1318
 
1242
1319
  // src/view/controller/host-decorations.ts
@@ -1329,7 +1406,7 @@ function createOutsideChanges(editorHasFocus, movedFrom) {
1329
1406
  }
1330
1407
  const from = moved ?? (outside && !settled ? movedFrom(tr.before.selection) : null);
1331
1408
  settled ||= outside;
1332
- moved = from && chunkG37GQ5JE_cjs.mapSelection(from, (pos, assoc) => tr.mapPos(pos, assoc), tr.before.doc);
1409
+ moved = from && chunkVZZPCYA3_cjs.mapSelection(from, (pos, assoc) => tr.mapPos(pos, assoc), tr.before.doc);
1333
1410
  },
1334
1411
  takeFocused() {
1335
1412
  const value = focused;
@@ -1422,7 +1499,7 @@ function handleCopy(controller, event, cut) {
1422
1499
  clipboardData.setData("text/plain", copied.text);
1423
1500
  clipboardData.setData("text/html", wrapSliceHTML(copied.html, copied.json));
1424
1501
  clipboardData.setData(QUOIN_SLICE_TYPE, copied.json);
1425
- if (cut) controller.run(chunkG37GQ5JE_cjs.deleteSelection);
1502
+ if (cut) controller.run(chunkVZZPCYA3_cjs.deleteSelection);
1426
1503
  }
1427
1504
  function handlePaste(controller, event) {
1428
1505
  if (!event.clipboardData) return;
@@ -1454,7 +1531,7 @@ function handleDrop(controller, event) {
1454
1531
  return;
1455
1532
  }
1456
1533
  const pos = dropPos(controller, event.clientX, event.clientY);
1457
- if (pos) controller.dispatch(controller.editor.createTransaction().setSelection(chunkG37GQ5JE_cjs.textSelection(pos)).setOrigin("drop"));
1534
+ if (pos) controller.dispatch(controller.editor.createTransaction().setSelection(chunkVZZPCYA3_cjs.textSelection(pos)).setOrigin("drop"));
1458
1535
  pasteTransfer(controller, dataTransfer);
1459
1536
  }
1460
1537
  function handleDragOver(event) {
@@ -1584,29 +1661,29 @@ function createSinkComposition(controller, settled = () => {
1584
1661
  var LINE_BREAK = "\n";
1585
1662
  var transposeChars = (state, dispatch) => {
1586
1663
  const { selection } = state;
1587
- if (selection?.kind !== "text" || !chunkG37GQ5JE_cjs.isCollapsed(selection)) return false;
1664
+ if (selection?.kind !== "text" || !chunkVZZPCYA3_cjs.isCollapsed(selection)) return false;
1588
1665
  const { head } = selection;
1589
1666
  const inline = chunkWZA5S5EJ_cjs.blockById(state.doc, head.block)?.regions[head.region];
1590
1667
  if (inline === void 0) return false;
1591
1668
  const value = chunkWZA5S5EJ_cjs.inlineText(inline);
1592
1669
  const atLineEnd = head.offset === value.length || value[head.offset] === LINE_BREAK;
1593
- const end = atLineEnd ? head.offset : chunkG37GQ5JE_cjs.nextGraphemeOffset(value, head.offset);
1594
- const middle = chunkG37GQ5JE_cjs.prevGraphemeOffset(value, end);
1595
- const start = chunkG37GQ5JE_cjs.prevGraphemeOffset(value, middle);
1670
+ const end = atLineEnd ? head.offset : chunkVZZPCYA3_cjs.nextGraphemeOffset(value, head.offset);
1671
+ const middle = chunkVZZPCYA3_cjs.prevGraphemeOffset(value, end);
1672
+ const start = chunkVZZPCYA3_cjs.prevGraphemeOffset(value, middle);
1596
1673
  if (start === middle || value.slice(start, end).includes(LINE_BREAK)) return false;
1597
1674
  const swapped = [...chunkWZA5S5EJ_cjs.sliceInline(inline, middle, end), ...chunkWZA5S5EJ_cjs.sliceInline(inline, start, middle)];
1598
- const tr = new chunkG37GQ5JE_cjs.Transaction(state).setOrigin("input");
1599
- tr.step(chunkG37GQ5JE_cjs.replaceInlineStep(head.block, head.region, start, end, swapped));
1600
- dispatch?.(tr.setSelection(chunkG37GQ5JE_cjs.textSelection({ ...head, offset: end })));
1675
+ const tr = new chunkVZZPCYA3_cjs.Transaction(state).setOrigin("input");
1676
+ tr.step(chunkVZZPCYA3_cjs.replaceInlineStep(head.block, head.region, start, end, swapped));
1677
+ dispatch?.(tr.setSelection(chunkVZZPCYA3_cjs.textSelection({ ...head, offset: end })));
1601
1678
  return true;
1602
1679
  };
1603
1680
 
1604
1681
  // src/view/input/replace-range.ts
1605
1682
  function replaceRange(editor, range, text, withRules) {
1606
1683
  const dispatch = (tr) => editor.dispatch(tr);
1607
- dispatch(editor.createTransaction().setSelection(chunkG37GQ5JE_cjs.textSelection(range.from, range.to)).setOrigin("input"));
1608
- if (text === "") return chunkG37GQ5JE_cjs.deleteSelection(editor.state, (tr) => dispatch(tr.setOrigin("input")));
1609
- return withRules ? editor.insertText(text) : chunkG37GQ5JE_cjs.insertText(text, { origin: "input" })(editor.state, dispatch);
1684
+ dispatch(editor.createTransaction().setSelection(chunkVZZPCYA3_cjs.textSelection(range.from, range.to)).setOrigin("input"));
1685
+ if (text === "") return chunkVZZPCYA3_cjs.deleteSelection(editor.state, (tr) => dispatch(tr.setOrigin("input")));
1686
+ return withRules ? editor.insertText(text) : chunkVZZPCYA3_cjs.insertText(text, { origin: "input" })(editor.state, dispatch);
1610
1687
  }
1611
1688
 
1612
1689
  // src/view/input/target-range.ts
@@ -1617,13 +1694,13 @@ function targetRangeToModel(controller, event) {
1617
1694
  const to = domToPos(controller.registry, range.endContainer, range.endOffset);
1618
1695
  return from && to && { from, to };
1619
1696
  }
1620
- var isEmpty = ({ from, to }) => chunkG37GQ5JE_cjs.sameSelection(chunkG37GQ5JE_cjs.textSelection(from), chunkG37GQ5JE_cjs.textSelection(to));
1697
+ var isEmpty = ({ from, to }) => chunkVZZPCYA3_cjs.sameSelection(chunkVZZPCYA3_cjs.textSelection(from), chunkVZZPCYA3_cjs.textSelection(to));
1621
1698
  function targetBeyondSelection(controller, event) {
1622
1699
  const range = targetRangeToModel(controller, event);
1623
1700
  if (range === null || isEmpty(range)) return null;
1624
1701
  const { doc, selection } = controller.editor.state;
1625
- const selected = chunkG37GQ5JE_cjs.selectionRange(doc, selection);
1626
- const same = selected !== null && chunkG37GQ5JE_cjs.sameSelection(chunkG37GQ5JE_cjs.textSelection(selected.from, selected.to), chunkG37GQ5JE_cjs.textSelection(range.from, range.to));
1702
+ const selected = chunkVZZPCYA3_cjs.selectionRange(doc, selection);
1703
+ const same = selected !== null && chunkVZZPCYA3_cjs.sameSelection(chunkVZZPCYA3_cjs.textSelection(selected.from, selected.to), chunkVZZPCYA3_cjs.textSelection(range.from, range.to));
1627
1704
  return same ? null : range;
1628
1705
  }
1629
1706
 
@@ -1645,34 +1722,34 @@ function insertTypedText(controller, event) {
1645
1722
  else controller.edit(() => replaceRange(controller.editor, range, text, false));
1646
1723
  }
1647
1724
  function deleteContentBackward(controller, event) {
1648
- if (!controller.run(chunkG37GQ5JE_cjs.undoInputRule)) targetOr(chunkG37GQ5JE_cjs.deleteBackward)(controller, event);
1725
+ if (!controller.run(chunkVZZPCYA3_cjs.undoInputRule)) targetOr(chunkVZZPCYA3_cjs.deleteBackward)(controller, event);
1649
1726
  }
1650
1727
  function insertReplacementText(controller, event) {
1651
1728
  const text = event.dataTransfer?.getData("text/plain") || event.data;
1652
1729
  if (!text) return;
1653
1730
  const range = targetRangeToModel(controller, event);
1654
- if (range === null) controller.run(chunkG37GQ5JE_cjs.insertText(text, { origin: "input" }));
1731
+ if (range === null) controller.run(chunkVZZPCYA3_cjs.insertText(text, { origin: "input" }));
1655
1732
  else controller.edit(() => replaceRange(controller.editor, range, text, false));
1656
1733
  }
1657
1734
  var actions = {
1658
1735
  insertText: insertTypedText,
1659
1736
  insertReplacementText,
1660
1737
  insertParagraph: (controller) => void controller.edit(() => controller.editor.handleKey(ENTER)),
1661
- insertLineBreak: run(chunkG37GQ5JE_cjs.insertHardBreak),
1738
+ insertLineBreak: run(chunkVZZPCYA3_cjs.insertHardBreak),
1662
1739
  deleteContentBackward,
1663
- deleteContentForward: targetOr(chunkG37GQ5JE_cjs.deleteForward),
1664
- deleteWordBackward: targetOr(chunkG37GQ5JE_cjs.deleteWordBackward),
1665
- deleteWordForward: targetOr(chunkG37GQ5JE_cjs.deleteWordForward),
1666
- deleteSoftLineBackward: targetOr(chunkG37GQ5JE_cjs.deleteToLineStart),
1667
- deleteHardLineBackward: targetOr(chunkG37GQ5JE_cjs.deleteToLineStart),
1668
- deleteSoftLineForward: targetOr(chunkG37GQ5JE_cjs.deleteToLineEnd),
1669
- deleteHardLineForward: targetOr(chunkG37GQ5JE_cjs.deleteToLineEnd),
1670
- formatBold: run(chunkG37GQ5JE_cjs.toggleMark("bold")),
1671
- formatItalic: run(chunkG37GQ5JE_cjs.toggleMark("italic")),
1672
- formatUnderline: run(chunkG37GQ5JE_cjs.toggleMark("underline")),
1673
- formatStrikeThrough: run(chunkG37GQ5JE_cjs.toggleMark("strike")),
1674
- historyUndo: run(chunkG37GQ5JE_cjs.undo),
1675
- historyRedo: run(chunkG37GQ5JE_cjs.redo),
1740
+ deleteContentForward: targetOr(chunkVZZPCYA3_cjs.deleteForward),
1741
+ deleteWordBackward: targetOr(chunkVZZPCYA3_cjs.deleteWordBackward),
1742
+ deleteWordForward: targetOr(chunkVZZPCYA3_cjs.deleteWordForward),
1743
+ deleteSoftLineBackward: targetOr(chunkVZZPCYA3_cjs.deleteToLineStart),
1744
+ deleteHardLineBackward: targetOr(chunkVZZPCYA3_cjs.deleteToLineStart),
1745
+ deleteSoftLineForward: targetOr(chunkVZZPCYA3_cjs.deleteToLineEnd),
1746
+ deleteHardLineForward: targetOr(chunkVZZPCYA3_cjs.deleteToLineEnd),
1747
+ formatBold: run(chunkVZZPCYA3_cjs.toggleMark("bold")),
1748
+ formatItalic: run(chunkVZZPCYA3_cjs.toggleMark("italic")),
1749
+ formatUnderline: run(chunkVZZPCYA3_cjs.toggleMark("underline")),
1750
+ formatStrikeThrough: run(chunkVZZPCYA3_cjs.toggleMark("strike")),
1751
+ historyUndo: run(chunkVZZPCYA3_cjs.undo),
1752
+ historyRedo: run(chunkVZZPCYA3_cjs.redo),
1676
1753
  insertTranspose: run(transposeChars),
1677
1754
  insertFromPaste: leaveToHandlers,
1678
1755
  insertFromDrop: leaveToHandlers,
@@ -1953,7 +2030,7 @@ function createDomInputFallback(controller) {
1953
2030
 
1954
2031
  // src/view/navigation/cross-moves.ts
1955
2032
  function moveHead(controller, { anchor }, head) {
1956
- dispatchSelection(controller, chunkG37GQ5JE_cjs.textSelection(anchor, head));
2033
+ dispatchSelection(controller, chunkVZZPCYA3_cjs.textSelection(anchor, head));
1957
2034
  return true;
1958
2035
  }
1959
2036
  function blockOf(controller, { block }) {
@@ -1961,25 +2038,25 @@ function blockOf(controller, { block }) {
1961
2038
  return doc.blocks[chunkWZA5S5EJ_cjs.requireBlockIndex(doc, block)];
1962
2039
  }
1963
2040
  function collapseCross(controller, selection, direction) {
1964
- const { from, to } = chunkG37GQ5JE_cjs.selectionRange(controller.editor.state.doc, selection);
1965
- dispatchSelection(controller, chunkG37GQ5JE_cjs.textSelection(direction < 0 ? from : to));
2041
+ const { from, to } = chunkVZZPCYA3_cjs.selectionRange(controller.editor.state.doc, selection);
2042
+ dispatchSelection(controller, chunkVZZPCYA3_cjs.textSelection(direction < 0 ? from : to));
1966
2043
  return true;
1967
2044
  }
1968
2045
  function crossHeadVertically(controller, selection, direction) {
1969
2046
  const { head } = selection;
1970
2047
  const edge = neighbourHead(controller, head.block, direction);
1971
2048
  if (edge !== null) {
1972
- const end2 = chunkG37GQ5JE_cjs.regionLength(blockOf(controller, edge), edge.region);
2049
+ const end2 = chunkVZZPCYA3_cjs.regionLength(blockOf(controller, edge), edge.region);
1973
2050
  return moveHead(controller, selection, { ...edge, offset: Math.min(head.offset, end2) });
1974
2051
  }
1975
- const end = chunkG37GQ5JE_cjs.regionLength(blockOf(controller, head), head.region);
2052
+ const end = chunkVZZPCYA3_cjs.regionLength(blockOf(controller, head), head.region);
1976
2053
  return moveHead(controller, selection, { ...head, offset: direction < 0 ? 0 : end });
1977
2054
  }
1978
2055
  function crossHeadHorizontally(controller, selection, direction) {
1979
2056
  const { head } = selection;
1980
2057
  const text = chunkWZA5S5EJ_cjs.inlineText(blockOf(controller, head).regions[head.region] ?? []);
1981
2058
  if (direction < 0 ? head.offset > 0 : head.offset < text.length) {
1982
- const offset = direction < 0 ? chunkG37GQ5JE_cjs.prevGraphemeOffset(text, head.offset) : chunkG37GQ5JE_cjs.nextGraphemeOffset(text, head.offset);
2059
+ const offset = direction < 0 ? chunkVZZPCYA3_cjs.prevGraphemeOffset(text, head.offset) : chunkVZZPCYA3_cjs.nextGraphemeOffset(text, head.offset);
1983
2060
  return moveHead(controller, selection, { ...head, offset });
1984
2061
  }
1985
2062
  const edge = neighbourHead(controller, head.block, direction);
@@ -1998,9 +2075,9 @@ function moveHorizontally(controller, direction, extend) {
1998
2075
  const move = extend ? crossHeadHorizontally : collapseCross;
1999
2076
  return move(controller, selection, direction);
2000
2077
  }
2001
- if (!extend && !chunkG37GQ5JE_cjs.isCollapsed(selection)) return false;
2078
+ if (!extend && !chunkVZZPCYA3_cjs.isCollapsed(selection)) return false;
2002
2079
  const { head } = selection;
2003
- const length = chunkG37GQ5JE_cjs.regionLength(doc.blocks[chunkWZA5S5EJ_cjs.requireBlockIndex(doc, head.block)], head.region);
2080
+ const length = chunkVZZPCYA3_cjs.regionLength(doc.blocks[chunkWZA5S5EJ_cjs.requireBlockIndex(doc, head.block)], head.region);
2004
2081
  if (direction < 0 ? head.offset > 0 : head.offset < length) return false;
2005
2082
  const own2 = extend ? null : ownNode(controller, head.block, direction);
2006
2083
  if (own2 !== null) {
@@ -2051,18 +2128,17 @@ function lineEdgeRect(host, last) {
2051
2128
  if (!map || map.length === 0) return contentBox(host);
2052
2129
  return caretClientRect(map.toDom(last ? map.length : 0, last ? -1 : 1));
2053
2130
  }
2054
- function onEdgeLine(host, point, last) {
2131
+ function onEdgeLine(host, last, caret) {
2055
2132
  if (domMapOf(host)?.length === 0) return true;
2056
- const caret = caretClientRect(point);
2057
2133
  const edge = lineEdgeRect(host, last);
2058
2134
  if (!caret || !edge) return false;
2059
2135
  return Math.abs(caret.top - edge.top) < Math.max(caret.height, edge.height) / 2;
2060
2136
  }
2061
- function isOnFirstLine(host, point) {
2062
- return onEdgeLine(host, point, false);
2137
+ function isOnFirstLine(host, point, caret = caretClientRect(point)) {
2138
+ return onEdgeLine(host, false, caret);
2063
2139
  }
2064
- function isOnLastLine(host, point) {
2065
- return onEdgeLine(host, point, true);
2140
+ function isOnLastLine(host, point, caret = caretClientRect(point)) {
2141
+ return onEdgeLine(host, true, caret);
2066
2142
  }
2067
2143
  function adjacentLineMiddle(host, caret, direction) {
2068
2144
  const range = host.ownerDocument.createRange();
@@ -2077,14 +2153,6 @@ function adjacentLineMiddle(host, caret, direction) {
2077
2153
  return nearest2;
2078
2154
  }
2079
2155
 
2080
- // src/view/navigation/stay-on-line.ts
2081
- var onLine = (rect, y) => rect === null || rect.top <= y && y <= rect.bottom;
2082
- function stayOnLine(pos, y, rectAt) {
2083
- if (pos.offset === 0 || onLine(rectAt(pos), y)) return pos;
2084
- const before = { ...pos, offset: pos.offset - 1 };
2085
- return onLine(rectAt(before), y) ? before : pos;
2086
- }
2087
-
2088
2156
  // src/view/navigation/vertical.ts
2089
2157
  function lineInView(host, last) {
2090
2158
  const line = lineEdgeRect(host, last);
@@ -2097,40 +2165,41 @@ function caretAtGoal(controller, host, at, y) {
2097
2165
  const { goalX } = controller;
2098
2166
  const view = host.ownerDocument.defaultView;
2099
2167
  if (goalX === null || !view || y < 0 || y > view.innerHeight) return null;
2100
- const pos = caretInHost(controller.registry, host, host.getBoundingClientRect(), at, goalX, y);
2101
- if (!pos) return null;
2102
- return stayOnLine(pos, y, (p) => {
2103
- const dom = posToDom(controller.registry, p);
2104
- return dom && caretClientRect(dom);
2105
- });
2168
+ return caretInHost(controller.registry, host, host.getBoundingClientRect(), at, goalX, y);
2106
2169
  }
2170
+ var keepOnLine = ({ registry }, pos, y) => stayOnLine(pos, y, glyphsAround(registry, pos));
2107
2171
  function landAtGoal(controller, block, direction) {
2108
2172
  const { schema } = controller.editor.state;
2109
- const region = chunkG37GQ5JE_cjs.isTextFlow(schema, block) ? chunkG37GQ5JE_cjs.primaryRegion(schema, block) : null;
2173
+ const region = chunkVZZPCYA3_cjs.isTextFlow(schema, block) ? chunkVZZPCYA3_cjs.primaryRegion(schema, block) : null;
2110
2174
  const host = region === null ? void 0 : controller.registry.get(block.id, region);
2111
2175
  if (!host || region === null || controller.goalX === null) return null;
2112
2176
  const line = lineInView(host, direction < 0);
2113
- const pos = line && caretAtGoal(controller, host, { block: block.id, region }, line.top + line.height / 2);
2114
- return pos ? chunkG37GQ5JE_cjs.textSelection(pos) : null;
2177
+ if (!line) return null;
2178
+ const y = line.top + line.height / 2;
2179
+ const pos = caretAtGoal(controller, host, { block: block.id, region }, y);
2180
+ return pos && keepOnLine(controller, pos, y);
2115
2181
  }
2116
2182
  function moveInHost(controller, host, head, caret, direction) {
2117
2183
  const { goalX } = controller;
2118
- const native = !isCrossSelection(controller.editor.state.selection);
2119
- if (goalX === null || !caret || native && Math.abs(caret.left - goalX) < caret.height / 2) return null;
2184
+ if (goalX === null || !caret) return null;
2185
+ const atGoal = Math.abs(caret.left - goalX) < caret.height / 2;
2186
+ const native = atGoal && !isCrossSelection(controller.editor.state.selection);
2120
2187
  const y = adjacentLineMiddle(host, caret, direction);
2121
- const pos = y === null ? null : caretAtGoal(controller, host, head, y);
2122
- return pos && pos.offset !== head.offset ? pos : null;
2188
+ if (y === null) return null;
2189
+ const pos = caretAtGoal(controller, host, head, y);
2190
+ const next = pos && keepOnLine(controller, pos, y);
2191
+ if (!next || next.head.offset === head.offset) return null;
2192
+ return native && next.head === pos && next.assoc === void 0 ? null : next;
2123
2193
  }
2124
- function landing(controller, { head }, direction, extend) {
2194
+ function landing(controller, { head, assoc }, direction, extend) {
2125
2195
  const { registry } = controller;
2126
2196
  const host = registry.get(head.block, head.region);
2127
2197
  const point = posToDom(registry, head);
2128
2198
  if (!host || !point) return null;
2129
- const caret = caretClientRect(point);
2199
+ const caret = assoc === -1 && upstreamCaret(registry, head) || caretClientRect(point);
2130
2200
  controller.goalX ??= caret?.left ?? null;
2131
- if (!(direction < 0 ? isOnFirstLine(host, point) : isOnLastLine(host, point))) {
2132
- const pos = moveInHost(controller, host, head, caret, direction);
2133
- return pos && chunkG37GQ5JE_cjs.textSelection(pos);
2201
+ if (!(direction < 0 ? isOnFirstLine(host, point, caret) : isOnLastLine(host, point, caret))) {
2202
+ return moveInHost(controller, host, head, caret, direction);
2134
2203
  }
2135
2204
  const own2 = extend ? null : ownNode(controller, head.block, direction);
2136
2205
  if (own2 !== null) return own2;
@@ -2152,7 +2221,7 @@ function moveText(controller, selection, direction, extend) {
2152
2221
  function extendBlocks(controller, { anchor, head }, direction) {
2153
2222
  const next = neighbourBlock(controller.editor.state.doc, head, direction);
2154
2223
  if (next === null) return false;
2155
- dispatchSelection(controller, chunkG37GQ5JE_cjs.blockRangeSelection(anchor, next.id));
2224
+ dispatchSelection(controller, chunkVZZPCYA3_cjs.blockRangeSelection(anchor, next.id));
2156
2225
  return true;
2157
2226
  }
2158
2227
  function moveVertically(controller, direction, extend) {
@@ -2168,8 +2237,8 @@ function moveVertically(controller, direction, extend) {
2168
2237
  // src/view/input/flip-block.ts
2169
2238
  var isTask = ({ type, attrs }) => type === "MARKDOWN" && attrs.kind === "task";
2170
2239
  function flipCommand(block) {
2171
- if (isTask(block)) return chunkG37GQ5JE_cjs.toggleTask;
2172
- return block.type === "TOGGLE" ? chunkG37GQ5JE_cjs.setAttrs({ open: block.attrs.open !== true }) : null;
2240
+ if (isTask(block)) return chunkVZZPCYA3_cjs.toggleTask;
2241
+ return block.type === "TOGGLE" ? chunkVZZPCYA3_cjs.setAttrs({ open: block.attrs.open !== true }) : null;
2173
2242
  }
2174
2243
  var toggleState = (open) => open ? "expanded" : "collapsed";
2175
2244
  function stateName(block) {
@@ -2267,7 +2336,7 @@ function attachInput(controller, root) {
2267
2336
  const { editor } = controller;
2268
2337
  let { selection } = editor.state;
2269
2338
  const stop = editor.subscribe((_, tr) => {
2270
- if (tr && selection) selection = chunkG37GQ5JE_cjs.mapSelection(selection, (pos, assoc) => tr.mapPos(pos, assoc));
2339
+ if (tr && selection) selection = chunkVZZPCYA3_cjs.mapSelection(selection, (pos, assoc) => tr.mapPos(pos, assoc));
2271
2340
  });
2272
2341
  fallback.flush();
2273
2342
  stop();
@@ -2424,7 +2493,8 @@ function bindRoot(controller, root, cross, committed) {
2424
2493
  function movedSelection(controller, doc, model) {
2425
2494
  if (controller.composingKey !== null || controller.dragging || !doc || !ownsFocus(controller, doc)) return null;
2426
2495
  const selection = readSelection(controller.registry, doc.getSelection(), (node) => controller.blockAt(node));
2427
- return selection === null || chunkG37GQ5JE_cjs.sameSelection(selection, model) ? null : selection;
2496
+ const sided = selection?.kind === "text" && model?.kind === "text" ? { ...selection, assoc: model.assoc } : selection;
2497
+ return sided === null || chunkVZZPCYA3_cjs.sameSelection(sided, model) ? null : selection;
2428
2498
  }
2429
2499
  function writeModelSelection(controller, doc, moved, local) {
2430
2500
  const domSelection = doc?.getSelection();
@@ -2484,7 +2554,7 @@ var ViewController = class {
2484
2554
  this.engagement = createEngagement(options.editor);
2485
2555
  this.#flush = options.flush ?? runNow;
2486
2556
  this.onFiles = options.onFiles;
2487
- this.isMac = options.isMac ?? chunkG37GQ5JE_cjs.detectMac();
2557
+ this.isMac = options.isMac ?? chunkVZZPCYA3_cjs.detectMac();
2488
2558
  const decorationsOf = (block, region) => this.decorationsFor(block, region);
2489
2559
  const drain = (element) => this.#binding?.input.drain(element);
2490
2560
  this.#hosts = createHostRenderer(options.editor, options.render, decorationsOf, drain);
@@ -2637,7 +2707,7 @@ var ViewController = class {
2637
2707
  focus(target) {
2638
2708
  const { editor } = this;
2639
2709
  const selection = focusTarget(editor.state, target);
2640
- if (selection !== null && !chunkG37GQ5JE_cjs.sameSelection(selection, editor.state.selection)) dispatchSelection(this, selection);
2710
+ if (selection !== null && !chunkVZZPCYA3_cjs.sameSelection(selection, editor.state.selection)) dispatchSelection(this, selection);
2641
2711
  this.#takeFocus();
2642
2712
  this.syncSelectionToDom();
2643
2713
  }
@@ -2685,7 +2755,7 @@ function useQuoinEditor(options) {
2685
2755
  const { blocks, readOnly = false } = options;
2686
2756
  const callbacks = react.useRef(options);
2687
2757
  const [controller] = react.useState(() => {
2688
- const editor = chunkG37GQ5JE_cjs.createEditor({
2758
+ const editor = chunkVZZPCYA3_cjs.createEditor({
2689
2759
  blocks,
2690
2760
  extensions: options.extensions,
2691
2761
  onChange: (next) => callbacks.current.onChange(next),
@@ -2752,7 +2822,7 @@ var headingPlaceholder = (_state, { type, attrs }) => type === "MARKDOWN" && att
2752
2822
  var BlockPlaceholderContext = react.createContext(headingPlaceholder);
2753
2823
  function regionPlaceholder(state, blockId, region, placeholderOf) {
2754
2824
  const block = chunkWZA5S5EJ_cjs.blockById(state.doc, blockId);
2755
- return block !== void 0 && chunkG37GQ5JE_cjs.primaryRegion(state.schema, block) === region ? placeholderOf(state, block) : void 0;
2825
+ return block !== void 0 && chunkVZZPCYA3_cjs.primaryRegion(state.schema, block) === region ? placeholderOf(state, block) : void 0;
2756
2826
  }
2757
2827
  var samePainted = (a, b) => a.inline === b.inline && a.placeholder === b.placeholder && sameDecorations(a.decorations, b.decorations);
2758
2828
  function EditableRegion({ block, region, label, id, placeholder, className }) {
@@ -2808,7 +2878,7 @@ var CalloutBlock = ({ block }) => {
2808
2878
  // src/view/react/block-command.ts
2809
2879
  function onBlock(id, command) {
2810
2880
  return (state, dispatch) => {
2811
- const { ok, tr } = chunkG37GQ5JE_cjs.runCommands(state, [chunkG37GQ5JE_cjs.setSelection(chunkG37GQ5JE_cjs.blockRangeSelection(id)), command]);
2881
+ const { ok, tr } = chunkVZZPCYA3_cjs.runCommands(state, [chunkVZZPCYA3_cjs.setSelection(chunkVZZPCYA3_cjs.blockRangeSelection(id)), command]);
2812
2882
  if (!ok || tr === null) return false;
2813
2883
  dispatch?.(tr.setSelection(state.selection));
2814
2884
  return true;
@@ -3011,7 +3081,7 @@ function covers(state, id, index) {
3011
3081
  if (selection === null) return false;
3012
3082
  if (selection.kind === "node") return selection.block === id;
3013
3083
  if (selection.kind === "blocks") return within(state, index, [selection.anchor, selection.head]);
3014
- if (!isCrossSelection(selection) || chunkG37GQ5JE_cjs.isTextFlow(schema, doc.blocks[index])) return false;
3084
+ if (!isCrossSelection(selection) || chunkVZZPCYA3_cjs.isTextFlow(schema, doc.blocks[index])) return false;
3015
3085
  return within(state, index, [selection.anchor.block, selection.head.block]);
3016
3086
  }
3017
3087
  function blockStatus(state, id, choices = NO_CHOICES) {
@@ -3267,5 +3337,5 @@ exports.useToggleOpen = useToggleOpen;
3267
3337
  exports.useViewController = useViewController;
3268
3338
  exports.visibleBlockIndexes = visibleBlockIndexes;
3269
3339
  exports.wholeState = wholeState;
3270
- //# sourceMappingURL=chunk-OGBD74IR.cjs.map
3271
- //# sourceMappingURL=chunk-OGBD74IR.cjs.map
3340
+ //# sourceMappingURL=chunk-QJ34MOFV.cjs.map
3341
+ //# sourceMappingURL=chunk-QJ34MOFV.cjs.map