quoin-editor 2.0.5 → 2.1.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 (215) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/MIGRATION.md +1 -1
  3. package/README.md +4 -3
  4. package/dist/ai.cjs +124 -94
  5. package/dist/ai.d.cts +7 -0
  6. package/dist/ai.d.ts +7 -0
  7. package/dist/ai.js +50 -20
  8. package/dist/ai.js.map +1 -1
  9. package/dist/catalogue.cjs +28 -26
  10. package/dist/catalogue.js +19 -17
  11. package/dist/catalogue.js.map +1 -1
  12. package/dist/{chunk-JGEDJYIV.cjs → chunk-2FUWXPPC.cjs} +92 -98
  13. package/dist/{chunk-NHNW5DK3.js → chunk-3F76QQ65.js} +6 -6
  14. package/dist/{chunk-NHNW5DK3.js.map → chunk-3F76QQ65.js.map} +1 -1
  15. package/dist/{chunk-DBOZFNWU.js → chunk-3QYFAAQR.js} +3 -3
  16. package/dist/{chunk-DBOZFNWU.js.map → chunk-3QYFAAQR.js.map} +1 -1
  17. package/dist/{chunk-I7X7B3WD.cjs → chunk-4JDRDPLC.cjs} +17 -8
  18. package/dist/{chunk-EBSDPHPS.cjs → chunk-4UFWFV43.cjs} +1060 -719
  19. package/dist/{chunk-LM3DHROX.cjs → chunk-5AUIA4B3.cjs} +2 -2
  20. package/dist/{chunk-3INFNIGN.cjs → chunk-5H3BB5VJ.cjs} +131 -78
  21. package/dist/{chunk-DJU25PFC.cjs → chunk-5L2NSIHZ.cjs} +11 -11
  22. package/dist/{chunk-W376L2GM.js → chunk-6Y7JAWYY.js} +8 -8
  23. package/dist/chunk-6Y7JAWYY.js.map +1 -0
  24. package/dist/{chunk-UDBLZILE.js → chunk-ATKDXQEY.js} +12 -7
  25. package/dist/{chunk-UDBLZILE.js.map → chunk-ATKDXQEY.js.map} +1 -1
  26. package/dist/{chunk-A2IQHMIH.js → chunk-BE2SYPK5.js} +49 -54
  27. package/dist/chunk-BE2SYPK5.js.map +1 -0
  28. package/dist/{chunk-PURYVDC3.cjs → chunk-CFICD2JP.cjs} +21 -16
  29. package/dist/{chunk-3HW3WRYC.cjs → chunk-CSIUXYRU.cjs} +2 -2
  30. package/dist/{chunk-N7BSFDDM.cjs → chunk-DBKL524I.cjs} +23 -23
  31. package/dist/{chunk-XE3IYW5B.js → chunk-DEFYFIWW.js} +90 -37
  32. package/dist/chunk-DEFYFIWW.js.map +1 -0
  33. package/dist/{chunk-7E43TURF.cjs → chunk-ECI3PSMS.cjs} +7 -7
  34. package/dist/{chunk-4G645EYO.js → chunk-F73QEF7E.js} +5 -5
  35. package/dist/{chunk-4G645EYO.js.map → chunk-F73QEF7E.js.map} +1 -1
  36. package/dist/{chunk-KHRVCTQQ.cjs → chunk-FUT7XLMP.cjs} +61 -74
  37. package/dist/{chunk-7J63427U.cjs → chunk-GQSBOBOM.cjs} +375 -320
  38. package/dist/{chunk-LU3T3JB4.js → chunk-HPNSQWRD.js} +15 -28
  39. package/dist/chunk-HPNSQWRD.js.map +1 -0
  40. package/dist/{chunk-7Y4B7NHO.js → chunk-I34BFOLL.js} +18 -11
  41. package/dist/chunk-I34BFOLL.js.map +1 -0
  42. package/dist/{chunk-AJT54OMZ.js → chunk-IFRXEFQH.js} +9 -15
  43. package/dist/chunk-IFRXEFQH.js.map +1 -0
  44. package/dist/{chunk-YYW33WUL.cjs → chunk-K3XWVRL4.cjs} +8 -8
  45. package/dist/{chunk-LSI4RMTY.js → chunk-L5L6YNLT.js} +3 -3
  46. package/dist/{chunk-LSI4RMTY.js.map → chunk-L5L6YNLT.js.map} +1 -1
  47. package/dist/{chunk-2BPXVQBP.js → chunk-MO4UMXMT.js} +238 -86
  48. package/dist/chunk-MO4UMXMT.js.map +1 -0
  49. package/dist/{chunk-2QKFRKOP.cjs → chunk-N25EH2GZ.cjs} +351 -205
  50. package/dist/{chunk-CSPCDVCT.js → chunk-NCV2ML25.js} +3 -3
  51. package/dist/{chunk-CSPCDVCT.js.map → chunk-NCV2ML25.js.map} +1 -1
  52. package/dist/{chunk-NUQ64S5B.cjs → chunk-OJSKSQTL.cjs} +26 -26
  53. package/dist/chunk-PIWMU4BV.js +9 -0
  54. package/dist/chunk-PIWMU4BV.js.map +1 -0
  55. package/dist/chunk-QFGWSFOI.cjs +10 -0
  56. package/dist/{chunk-GPTJYWGS.js → chunk-RNBLVGWY.js} +3 -3
  57. package/dist/{chunk-GPTJYWGS.js.map → chunk-RNBLVGWY.js.map} +1 -1
  58. package/dist/{chunk-5RBMZGKV.js → chunk-TL2MJOWM.js} +325 -57
  59. package/dist/chunk-TL2MJOWM.js.map +1 -0
  60. package/dist/{chunk-YEDPBYO5.cjs → chunk-UDQ52EEC.cjs} +4 -4
  61. package/dist/{chunk-EIWPJWY3.js → chunk-UE2NQPNG.js} +5 -5
  62. package/dist/{chunk-EIWPJWY3.js.map → chunk-UE2NQPNG.js.map} +1 -1
  63. package/dist/{chunk-BE2YHZXA.cjs → chunk-ULV3SCYP.cjs} +26 -15
  64. package/dist/{chunk-WDBFGX3U.cjs → chunk-VTTMJGWP.cjs} +72 -77
  65. package/dist/{chunk-556PFYES.js → chunk-WK4UGDZN.js} +290 -235
  66. package/dist/chunk-WK4UGDZN.js.map +1 -0
  67. package/dist/{chunk-JZF6UQH5.cjs → chunk-WMKA37NJ.cjs} +12 -12
  68. package/dist/{chunk-F2ZK6Z52.js → chunk-Y26F2X4E.js} +3 -3
  69. package/dist/{chunk-F2ZK6Z52.js.map → chunk-Y26F2X4E.js.map} +1 -1
  70. package/dist/{chunk-FK7EBZPX.cjs → chunk-Z5EEDCRI.cjs} +549 -276
  71. package/dist/{chunk-G6NBQYMM.js → chunk-ZGFZRVQA.js} +817 -478
  72. package/dist/chunk-ZGFZRVQA.js.map +1 -0
  73. package/dist/{chunk-QLVX7MPS.js → chunk-ZQF45LA4.js} +19 -8
  74. package/dist/chunk-ZQF45LA4.js.map +1 -0
  75. package/dist/comments.cjs +127 -65
  76. package/dist/comments.d.cts +35 -2
  77. package/dist/comments.d.ts +35 -2
  78. package/dist/comments.js +73 -12
  79. package/dist/comments.js.map +1 -1
  80. package/dist/{diagram-extension-22x_njXB.d.ts → diagram-extension-BMlh8GCw.d.ts} +1 -1
  81. package/dist/{diagram-extension-C_FSkoj9.d.cts → diagram-extension-gmndUpti.d.cts} +1 -1
  82. package/dist/diagram.cjs +10 -9
  83. package/dist/diagram.d.cts +2 -2
  84. package/dist/diagram.d.ts +2 -2
  85. package/dist/diagram.js +7 -6
  86. package/dist/diff.cjs +25 -25
  87. package/dist/diff.js +3 -3
  88. package/dist/docx.cjs +31 -30
  89. package/dist/docx.js +5 -4
  90. package/dist/docx.js.map +1 -1
  91. package/dist/embed.cjs +10 -9
  92. package/dist/embed.js +8 -7
  93. package/dist/{emoji-extension-Dk5IQLZf.d.cts → emoji-extension-DD9CQTQj.d.cts} +1 -1
  94. package/dist/{emoji-extension-C832oGeT.d.ts → emoji-extension-U_PWZ2fX.d.ts} +1 -1
  95. package/dist/emoji.cjs +10 -9
  96. package/dist/emoji.d.cts +2 -2
  97. package/dist/emoji.d.ts +2 -2
  98. package/dist/emoji.js +7 -6
  99. package/dist/engine.cjs +58 -58
  100. package/dist/engine.d.cts +3 -3
  101. package/dist/engine.d.ts +3 -3
  102. package/dist/engine.js +3 -3
  103. package/dist/{find-extension-DmK9_N81.d.ts → find-extension-BGlqooZi.d.ts} +1 -1
  104. package/dist/{find-extension-BfruAPLi.d.cts → find-extension-BPnAJ8bY.d.cts} +1 -1
  105. package/dist/find.cjs +11 -10
  106. package/dist/find.d.cts +1 -1
  107. package/dist/find.d.ts +1 -1
  108. package/dist/find.js +7 -6
  109. package/dist/headless.cjs +70 -69
  110. package/dist/headless.d.cts +33 -10
  111. package/dist/headless.d.ts +33 -10
  112. package/dist/headless.js +5 -4
  113. package/dist/highlight.cjs +7 -6
  114. package/dist/highlight.js +6 -5
  115. package/dist/highlight.js.map +1 -1
  116. package/dist/{index-3fYvwqUZ.d.cts → index-DN7vRKFw.d.cts} +1 -1
  117. package/dist/{index-CgxnzCO5.d.ts → index-DyIYI3PM.d.ts} +1 -1
  118. package/dist/index.cjs +82 -81
  119. package/dist/index.d.cts +19 -12
  120. package/dist/index.d.ts +19 -12
  121. package/dist/index.js +6 -5
  122. package/dist/{labels-CiCxj2jP.d.cts → labels-BJORhN93.d.ts} +10 -5
  123. package/dist/{labels-BhRJYo46.d.ts → labels-CVYJ2-1X.d.cts} +10 -5
  124. package/dist/locale-ar.cjs +10 -0
  125. package/dist/locale-ar.d.cts +1 -1
  126. package/dist/locale-ar.d.ts +1 -1
  127. package/dist/locale-ar.js +10 -0
  128. package/dist/locale-ar.js.map +1 -1
  129. package/dist/locale-de.cjs +4 -0
  130. package/dist/locale-de.d.cts +1 -1
  131. package/dist/locale-de.d.ts +1 -1
  132. package/dist/locale-de.js +4 -0
  133. package/dist/locale-de.js.map +1 -1
  134. package/dist/locale-es.cjs +4 -0
  135. package/dist/locale-es.d.cts +1 -1
  136. package/dist/locale-es.d.ts +1 -1
  137. package/dist/locale-es.js +4 -0
  138. package/dist/locale-es.js.map +1 -1
  139. package/dist/locale-fr.cjs +4 -0
  140. package/dist/locale-fr.d.cts +1 -1
  141. package/dist/locale-fr.d.ts +1 -1
  142. package/dist/locale-fr.js +4 -0
  143. package/dist/locale-fr.js.map +1 -1
  144. package/dist/locale-ja.cjs +4 -0
  145. package/dist/locale-ja.d.cts +1 -1
  146. package/dist/locale-ja.d.ts +1 -1
  147. package/dist/locale-ja.js +4 -0
  148. package/dist/locale-ja.js.map +1 -1
  149. package/dist/locale-pt.cjs +4 -0
  150. package/dist/locale-pt.d.cts +1 -1
  151. package/dist/locale-pt.d.ts +1 -1
  152. package/dist/locale-pt.js +4 -0
  153. package/dist/locale-pt.js.map +1 -1
  154. package/dist/locale-zh.cjs +4 -0
  155. package/dist/locale-zh.d.cts +1 -1
  156. package/dist/locale-zh.d.ts +1 -1
  157. package/dist/locale-zh.js +4 -0
  158. package/dist/locale-zh.js.map +1 -1
  159. package/dist/math.cjs +11 -10
  160. package/dist/math.js +9 -8
  161. package/dist/mention.cjs +11 -10
  162. package/dist/mention.js +9 -8
  163. package/dist/{node-reveal-DY6bimv3.d.cts → node-reveal-Be7Xa0BL.d.cts} +1 -1
  164. package/dist/{node-reveal-BnFcnHhz.d.ts → node-reveal-CftIEqF_.d.ts} +1 -1
  165. package/dist/palette-DuIFHYHc.d.cts +10 -0
  166. package/dist/palette-DuIFHYHc.d.ts +10 -0
  167. package/dist/presence.cjs +39 -38
  168. package/dist/presence.js +8 -7
  169. package/dist/presence.js.map +1 -1
  170. package/dist/source.cjs +10 -9
  171. package/dist/source.d.cts +1 -1
  172. package/dist/source.d.ts +1 -1
  173. package/dist/source.js +6 -5
  174. package/dist/source.js.map +1 -1
  175. package/dist/{stats-extension-Dmw0Ujxe.d.ts → stats-extension-Bbpr593p.d.ts} +1 -1
  176. package/dist/{stats-extension-D5HySF0a.d.cts → stats-extension-D7FaeydW.d.cts} +1 -1
  177. package/dist/stats.cjs +12 -10
  178. package/dist/stats.d.cts +2 -2
  179. package/dist/stats.d.ts +2 -2
  180. package/dist/stats.js +9 -7
  181. package/dist/styles.css +1 -1
  182. package/dist/{table-extension-7LkLNK6Q.d.cts → table-extension-DNijjmxV.d.cts} +1 -1
  183. package/dist/{table-extension-DEpV0DnP.d.ts → table-extension-Dp6FYGPh.d.ts} +1 -1
  184. package/dist/table.cjs +26 -25
  185. package/dist/table.d.cts +4 -3
  186. package/dist/table.d.ts +4 -3
  187. package/dist/table.js +7 -6
  188. package/dist/{toc-extension-Dvh37bWQ.d.cts → toc-extension-BGEVAmSY.d.cts} +1 -1
  189. package/dist/{toc-extension-SVckrFmb.d.ts → toc-extension-DZIe40eV.d.ts} +1 -1
  190. package/dist/toc.cjs +10 -9
  191. package/dist/toc.d.cts +2 -2
  192. package/dist/toc.d.ts +2 -2
  193. package/dist/toc.js +7 -6
  194. package/dist/{types-DMuuDBVh.d.ts → types-Byu2a9qk.d.ts} +6 -1
  195. package/dist/{types-Bzhq5AXj.d.cts → types-DdDlCyyZ.d.cts} +6 -1
  196. package/dist/view.cjs +4 -4
  197. package/dist/view.js +2 -2
  198. package/dist/yjs.cjs +121 -121
  199. package/dist/yjs.d.cts +2 -2
  200. package/dist/yjs.d.ts +2 -2
  201. package/dist/yjs.js +5 -5
  202. package/package.json +4 -3
  203. package/dist/chunk-2BPXVQBP.js.map +0 -1
  204. package/dist/chunk-556PFYES.js.map +0 -1
  205. package/dist/chunk-5RBMZGKV.js.map +0 -1
  206. package/dist/chunk-7Y4B7NHO.js.map +0 -1
  207. package/dist/chunk-A2IQHMIH.js.map +0 -1
  208. package/dist/chunk-AJT54OMZ.js.map +0 -1
  209. package/dist/chunk-G6NBQYMM.js.map +0 -1
  210. package/dist/chunk-LU3T3JB4.js.map +0 -1
  211. package/dist/chunk-QLVX7MPS.js.map +0 -1
  212. package/dist/chunk-W376L2GM.js.map +0 -1
  213. package/dist/chunk-XE3IYW5B.js.map +0 -1
  214. package/dist/palette-BrX-hEd-.d.cts +0 -4
  215. package/dist/palette-BrX-hEd-.d.ts +0 -4
@@ -1,33 +1,27 @@
1
1
  'use strict';
2
2
 
3
- var chunkEBSDPHPS_cjs = require('./chunk-EBSDPHPS.cjs');
4
- var chunk2QKFRKOP_cjs = require('./chunk-2QKFRKOP.cjs');
3
+ var chunk4UFWFV43_cjs = require('./chunk-4UFWFV43.cjs');
4
+ var chunkN25EH2GZ_cjs = require('./chunk-N25EH2GZ.cjs');
5
5
  var chunkZWTIRGY5_cjs = require('./chunk-ZWTIRGY5.cjs');
6
- var chunkFK7EBZPX_cjs = require('./chunk-FK7EBZPX.cjs');
7
- var chunkI7X7B3WD_cjs = require('./chunk-I7X7B3WD.cjs');
6
+ var chunkZ5EEDCRI_cjs = require('./chunk-Z5EEDCRI.cjs');
7
+ var chunk4JDRDPLC_cjs = require('./chunk-4JDRDPLC.cjs');
8
8
  var react = require('react');
9
9
  var jsxRuntime = require('react/jsx-runtime');
10
10
  var reactDom = require('react-dom');
11
11
 
12
12
  // src/engine/commands/table-shape.ts
13
- var CELL = /^cell:(\d+):(\d+)$/;
14
13
  var tableShape = (block) => ({
15
- rows: chunkI7X7B3WD_cjs.countOf(block.attrs.rows),
16
- cols: chunkI7X7B3WD_cjs.countOf(block.attrs.cols)
14
+ rows: chunk4JDRDPLC_cjs.countOf(block.attrs.rows),
15
+ cols: chunk4JDRDPLC_cjs.countOf(block.attrs.cols)
17
16
  });
18
17
  var ALIGNS = ["left", "center", "right"];
19
18
  var columnAligns = (block, cols) => Array.from({ length: cols }, (_, col) => {
20
19
  const align = Array.isArray(block.attrs.align) ? block.attrs.align[col] : null;
21
20
  return ALIGNS.includes(align) ? align : null;
22
21
  });
23
- var validWidths = (value, cols) => Array.isArray(value) && value.length === cols && value.every((width) => typeof width === "number" && width > 0) ? value : null;
24
- var storedWidths = (block, cols) => validWidths(block.attrs.widths, cols);
25
- function cellOf(region) {
26
- const match = CELL.exec(region);
27
- return match === null ? null : [Number(match[1]), Number(match[2])];
28
- }
22
+ var storedWidths = (block, cols) => chunk4JDRDPLC_cjs.validWidths(block.attrs.widths, cols);
29
23
  function tableBlock(doc, id) {
30
- const block = chunkI7X7B3WD_cjs.blockById(doc, id);
24
+ const block = chunk4JDRDPLC_cjs.blockById(doc, id);
31
25
  return block?.type === "TABLE" ? block : null;
32
26
  }
33
27
  var isIndex = (index, length) => Number.isInteger(index) && index >= 0 && index < length;
@@ -41,32 +35,32 @@ function rebuiltTable(block, plan) {
41
35
  for (let row = 0; row < plan.rows; row++) {
42
36
  for (let col = 0; col < plan.cols; col++) {
43
37
  const from = plan.source(row, col);
44
- regions[chunkI7X7B3WD_cjs.cellKey(row, col)] = from === null ? [] : block.regions[chunkI7X7B3WD_cjs.cellKey(...from)] ?? [];
38
+ regions[chunk4JDRDPLC_cjs.cellKey(row, col)] = from === null ? [] : block.regions[chunk4JDRDPLC_cjs.cellKey(...from)] ?? [];
45
39
  }
46
40
  }
47
41
  return { ...block, attrs: { ...block.attrs, ...plan.attrs, rows: plan.rows, cols: plan.cols }, regions };
48
42
  }
49
43
  function followedPos(pos, blockId, plan) {
50
- const cell = pos.block === blockId ? cellOf(pos.region) : null;
44
+ const cell = pos.block === blockId ? chunkZ5EEDCRI_cjs.cellOf(pos.region) : null;
51
45
  if (cell === null) return pos;
52
46
  const moved = plan.target(cell);
53
- return moved === null ? { block: blockId, region: chunkI7X7B3WD_cjs.cellKey(...plan.landing(cell)), offset: 0 } : { ...pos, region: chunkI7X7B3WD_cjs.cellKey(...moved) };
47
+ return moved === null ? { block: blockId, region: chunk4JDRDPLC_cjs.cellKey(...plan.landing(cell)), offset: 0 } : { ...pos, region: chunk4JDRDPLC_cjs.cellKey(...moved) };
54
48
  }
55
49
  function followedSelection(selection, blockId, plan) {
56
50
  if (selection?.kind !== "text") return selection;
57
51
  const anchor = followedPos(selection.anchor, blockId, plan);
58
52
  const head = followedPos(selection.head, blockId, plan);
59
- return anchor === selection.anchor && head === selection.head ? selection : chunkFK7EBZPX_cjs.textSelection(anchor, head);
53
+ return anchor === selection.anchor && head === selection.head ? selection : chunkZ5EEDCRI_cjs.textSelection(anchor, head);
60
54
  }
61
55
 
62
56
  // src/engine/state/cell-selection.ts
63
- var cellSelectionKey = chunkFK7EBZPX_cjs.createPluginKey("cellSelection");
57
+ var cellSelectionKey = chunkZ5EEDCRI_cjs.createPluginKey("cellSelection");
64
58
  function rangeOfSelection({ doc, selection }) {
65
59
  if (selection?.kind !== "text") return null;
66
60
  const { anchor, head } = selection;
67
61
  if (anchor.block !== head.block || anchor.region === head.region || tableBlock(doc, anchor.block) === null) return null;
68
- const from = cellOf(anchor.region);
69
- const to = cellOf(head.region);
62
+ const from = chunkZ5EEDCRI_cjs.cellOf(anchor.region);
63
+ const to = chunkZ5EEDCRI_cjs.cellOf(head.region);
70
64
  return from && to ? { block: anchor.block, anchor: from, head: to } : null;
71
65
  }
72
66
  var sameCell = (a, b) => a[0] === b[0] && a[1] === b[1];
@@ -85,81 +79,19 @@ function cellSelection(state) {
85
79
  }
86
80
  var between = (value, a, b) => value >= Math.min(a, b) && value <= Math.max(a, b);
87
81
  var rangeHasCell = ({ anchor, head }, [row, col]) => between(row, anchor[0], head[0]) && between(col, anchor[1], head[1]);
88
- function cellsInRange({ anchor, head }) {
89
- const cells = [];
90
- for (let row = Math.min(anchor[0], head[0]); row <= Math.max(anchor[0], head[0]); row++) {
91
- for (let col = Math.min(anchor[1], head[1]); col <= Math.max(anchor[1], head[1]); col++) cells.push([row, col]);
92
- }
93
- return cells;
94
- }
82
+ var cellsInRange = ({ anchor, head }) => chunkZ5EEDCRI_cjs.cellsBetween(anchor, head);
95
83
  function selectCells(blockId, anchor, head) {
96
84
  return (state, dispatch) => {
97
85
  const block = tableBlock(state.doc, blockId);
98
86
  const { rows, cols } = block === null ? { rows: 0, cols: 0 } : tableShape(block);
99
87
  const inside = ([row, col]) => isIndex(row, rows) && isIndex(col, cols);
100
88
  if (block === null || !inside(anchor) || !inside(head)) return false;
101
- const end2 = chunkI7X7B3WD_cjs.cellKey(...head);
102
- const selection = chunkFK7EBZPX_cjs.textSelection(
103
- { block: blockId, region: chunkI7X7B3WD_cjs.cellKey(...anchor), offset: 0 },
104
- { block: blockId, region: end2, offset: chunkI7X7B3WD_cjs.inlineLength(block.regions[end2] ?? []) }
89
+ const end = chunk4JDRDPLC_cjs.cellKey(...head);
90
+ const selection = chunkZ5EEDCRI_cjs.textSelection(
91
+ { block: blockId, region: chunk4JDRDPLC_cjs.cellKey(...anchor), offset: 0 },
92
+ { block: blockId, region: end, offset: chunk4JDRDPLC_cjs.inlineLength(block.regions[end] ?? []) }
105
93
  );
106
- dispatch?.(new chunkFK7EBZPX_cjs.Transaction(state).setSelection(selection));
107
- return true;
108
- };
109
- }
110
-
111
- // src/engine/commands/cell-commands.ts
112
- function filledCells(doc, range) {
113
- const regions = chunkI7X7B3WD_cjs.blockById(doc, range.block)?.regions ?? {};
114
- return cellsInRange(range).flatMap((cell) => {
115
- const region = chunkI7X7B3WD_cjs.cellKey(...cell);
116
- const length = chunkI7X7B3WD_cjs.inlineLength(regions[region] ?? []);
117
- return length > 0 ? [{ region, length }] : [];
118
- });
119
- }
120
- function firstCell({ block, anchor, head }) {
121
- return { block, region: chunkI7X7B3WD_cjs.cellKey(Math.min(anchor[0], head[0]), Math.min(anchor[1], head[1])), offset: 0 };
122
- }
123
- function emptied(state, range) {
124
- const tr = new chunkFK7EBZPX_cjs.Transaction(state);
125
- for (const { region, length } of filledCells(state.doc, range)) {
126
- tr.step(chunkFK7EBZPX_cjs.replaceInlineStep(range.block, region, 0, length, []));
127
- }
128
- return tr;
129
- }
130
- var deleteCellContents = (state, dispatch) => {
131
- const range = cellSelection(state);
132
- if (range === null) return false;
133
- dispatch?.(emptied(state, range).setSelection(chunkFK7EBZPX_cjs.textSelection(firstCell(range))));
134
- return true;
135
- };
136
- function typeOverCells(text) {
137
- return (state, dispatch) => {
138
- const range = cellSelection(state);
139
- if (range === null || text === "") return false;
140
- const tr = emptied(state, range);
141
- dispatch?.(tr.setSelection(chunkFK7EBZPX_cjs.textSelection(chunkFK7EBZPX_cjs.insertTextAt(tr, state.schema, firstCell(range), text))));
142
- return true;
143
- };
144
- }
145
- function setCellsMark(type, attrs) {
146
- return (state, dispatch) => {
147
- const range = cellSelection(state);
148
- const cells = range === null ? [] : filledCells(state.doc, range);
149
- const regions = range === null ? void 0 : chunkI7X7B3WD_cjs.blockById(state.doc, range.block)?.regions;
150
- if (range === null || regions === void 0 || cells.length === 0) return false;
151
- const carried = cells.every(({ region }) => chunkFK7EBZPX_cjs.markCoverage(regions[region], type, attrs).every);
152
- const mark = carried ? chunkFK7EBZPX_cjs.toggleMark(type, attrs) : chunkFK7EBZPX_cjs.setMark(type, attrs);
153
- const tr = new chunkFK7EBZPX_cjs.Transaction(state);
154
- for (const { region, length } of cells) {
155
- const start = { block: range.block, region, offset: 0 };
156
- const whole = chunkFK7EBZPX_cjs.textSelection(start, { ...start, offset: length });
157
- mark({ ...state, doc: tr.doc, selection: whole, storedMarks: null }, (cell) => {
158
- for (const step of cell.steps) tr.step(step);
159
- });
160
- }
161
- if (!tr.docChanged) return false;
162
- dispatch?.(tr);
94
+ dispatch?.(new chunkZ5EEDCRI_cjs.Transaction(state).setSelection(selection));
163
95
  return true;
164
96
  };
165
97
  }
@@ -168,7 +100,7 @@ function setCellsMark(type, attrs) {
168
100
  var CONTROLS_SLOT = "data-quoin-table-controls";
169
101
  var controlsSlot = (controller, blockId) => controller.blockElement(blockId)?.querySelector(`[${CONTROLS_SLOT}]`) ?? null;
170
102
  var TableCell = react.memo(function TableCell2({ controller, blockId, row, col, header, align, label }) {
171
- const inRange = chunk2QKFRKOP_cjs.useEditorState(
103
+ const inRange = chunkN25EH2GZ_cjs.useEditorState(
172
104
  controller,
173
105
  react.useCallback(
174
106
  (state) => {
@@ -187,7 +119,7 @@ var TableCell = react.memo(function TableCell2({ controller, blockId, row, col,
187
119
  "data-col": col,
188
120
  "data-in-range": inRange ? "" : void 0,
189
121
  style: align === null ? void 0 : { textAlign: align },
190
- children: /* @__PURE__ */ jsxRuntime.jsx(chunk2QKFRKOP_cjs.EditableRegion, { block: blockId, region: chunkI7X7B3WD_cjs.cellKey(row, col), label, className: "quoin-table-text" })
122
+ children: /* @__PURE__ */ jsxRuntime.jsx(chunkN25EH2GZ_cjs.EditableRegion, { block: blockId, region: chunk4JDRDPLC_cjs.cellKey(row, col), label, className: "quoin-table-text" })
191
123
  }
192
124
  );
193
125
  });
@@ -224,13 +156,67 @@ function useWidthPreview(controller, blockId) {
224
156
  return react.useSyncExternalStore(store.subscribe, read, read);
225
157
  }
226
158
 
159
+ // src/engine/commands/cell-commands.ts
160
+ function filledCells(doc, range) {
161
+ const regions = chunk4JDRDPLC_cjs.blockById(doc, range.block)?.regions ?? {};
162
+ return cellsInRange(range).flatMap((cell) => {
163
+ const region = chunk4JDRDPLC_cjs.cellKey(...cell);
164
+ const length = chunk4JDRDPLC_cjs.inlineLength(regions[region] ?? []);
165
+ return length > 0 ? [{ region, length }] : [];
166
+ });
167
+ }
168
+ function overCells(state, write) {
169
+ const { selection } = state;
170
+ if (cellSelection(state) === null || selection?.kind !== "text") return null;
171
+ const tr = new chunkZ5EEDCRI_cjs.Transaction(state);
172
+ return tr.setSelection(chunkZ5EEDCRI_cjs.textSelection(write(tr, chunkZ5EEDCRI_cjs.deleteRange(tr, state.schema, selection.anchor, selection.head))));
173
+ }
174
+ var deleteCellContents = (state, dispatch) => {
175
+ const tr = overCells(state, (_, caret) => caret);
176
+ if (tr !== null) dispatch?.(tr);
177
+ return tr !== null;
178
+ };
179
+ function typeOverCells(content) {
180
+ return (state, dispatch) => {
181
+ if (content.length === 0) return false;
182
+ const tr = overCells(state, (into, caret) => {
183
+ if (typeof content === "string") return chunkZ5EEDCRI_cjs.insertTextAt(into, state.schema, caret, content);
184
+ into.step(chunkZ5EEDCRI_cjs.replaceInlineStep(caret.block, caret.region, caret.offset, caret.offset, content));
185
+ return { ...caret, offset: caret.offset + chunk4JDRDPLC_cjs.inlineLength(content) };
186
+ });
187
+ if (tr !== null) dispatch?.(tr);
188
+ return tr !== null;
189
+ };
190
+ }
191
+ function setCellsMark(type, attrs) {
192
+ return (state, dispatch) => {
193
+ const range = cellSelection(state);
194
+ const cells = range === null ? [] : filledCells(state.doc, range);
195
+ const regions = range === null ? void 0 : chunk4JDRDPLC_cjs.blockById(state.doc, range.block)?.regions;
196
+ if (range === null || regions === void 0 || cells.length === 0) return false;
197
+ const carried = cells.every(({ region }) => chunkZ5EEDCRI_cjs.markCoverage(regions[region], type, attrs).every);
198
+ const mark = carried ? chunkZ5EEDCRI_cjs.toggleMark(type, attrs) : chunkZ5EEDCRI_cjs.setMark(type, attrs);
199
+ const tr = new chunkZ5EEDCRI_cjs.Transaction(state);
200
+ for (const { region, length } of cells) {
201
+ const start = { block: range.block, region, offset: 0 };
202
+ const whole = chunkZ5EEDCRI_cjs.textSelection(start, { ...start, offset: length });
203
+ mark({ ...state, doc: tr.doc, selection: whole, storedMarks: null }, (cell) => {
204
+ for (const step of cell.steps) tr.step(step);
205
+ });
206
+ }
207
+ if (!tr.docChanged) return false;
208
+ dispatch?.(tr);
209
+ return true;
210
+ };
211
+ }
212
+
227
213
  // src/engine/commands/table-commands.ts
228
214
  function changeTable(blockId, change, plan) {
229
215
  return (state, dispatch) => {
230
216
  const block = tableBlock(state.doc, blockId);
231
217
  const next = block && change(block);
232
218
  if (!next) return false;
233
- const tr = new chunkFK7EBZPX_cjs.Transaction(state).step(chunkFK7EBZPX_cjs.replaceBlockStep(next));
219
+ const tr = new chunkZ5EEDCRI_cjs.Transaction(state).step(chunkZ5EEDCRI_cjs.replaceBlockStep(next));
234
220
  dispatch?.(plan ? tr.setSelection(followedSelection(state.selection, blockId, plan)) : tr);
235
221
  return true;
236
222
  };
@@ -334,35 +320,35 @@ var setColumnWidth = (blockId, col, px, drawn) => changeTable(blockId, (block) =
334
320
  if (!isIndex(col, cols) || !(width > 0)) return null;
335
321
  const stored = storedWidths(block, cols);
336
322
  if (stored?.[col] === width) return null;
337
- const measured = drawn && validWidths(drawn.map(Math.round), cols);
323
+ const measured = drawn && chunk4JDRDPLC_cjs.validWidths(drawn.map(Math.round), cols);
338
324
  const widths = stored ?? measured ?? Array(cols).fill(DEFAULT_COLUMN_WIDTH);
339
325
  return withAttrs(block, { widths: spliced(widths, col, 1, width) });
340
326
  });
341
327
  var isCount = (value) => Number.isInteger(value) && value > 0;
342
328
  function emptyCells({ rows, cols }) {
343
329
  const regions = {};
344
- for (let row = 0; row < rows; row++) for (let col = 0; col < cols; col++) regions[chunkI7X7B3WD_cjs.cellKey(row, col)] = [];
330
+ for (let row = 0; row < rows; row++) for (let col = 0; col < cols; col++) regions[chunk4JDRDPLC_cjs.cellKey(row, col)] = [];
345
331
  return regions;
346
332
  }
347
333
  function insertTable(rows, cols, options = {}) {
348
334
  return (state, dispatch) => {
349
335
  const { doc, schema } = state;
350
- const id = chunkFK7EBZPX_cjs.headBlockId(state.selection);
336
+ const id = chunkZ5EEDCRI_cjs.headBlockId(state.selection);
351
337
  if (id === null || !isCount(rows) || !isCount(cols)) return false;
352
- const index = chunkI7X7B3WD_cjs.requireBlockIndex(doc, id);
338
+ const index = chunk4JDRDPLC_cjs.requireBlockIndex(doc, id);
353
339
  const current = doc.blocks[index];
354
- const fills = chunkFK7EBZPX_cjs.isParagraph(current) && chunkFK7EBZPX_cjs.regionLength(current, chunkFK7EBZPX_cjs.primaryRegion(schema, current) ?? "") === 0;
340
+ const fills = chunkZ5EEDCRI_cjs.isParagraph(current) && chunkZ5EEDCRI_cjs.regionLength(current, chunkZ5EEDCRI_cjs.primaryRegion(schema, current) ?? "") === 0;
355
341
  const table = {
356
- id: fills ? current.id : (options.newId ?? chunkI7X7B3WD_cjs.newId)(),
342
+ id: fills ? current.id : (options.newId ?? chunk4JDRDPLC_cjs.newId)(),
357
343
  type: "TABLE",
358
344
  indent: current.indent,
359
345
  attrs: { header: true, align: Array.from({ length: cols }, () => null), rows, cols },
360
346
  regions: emptyCells({ rows, cols })
361
347
  };
362
- const tr = new chunkFK7EBZPX_cjs.Transaction(state).step(
363
- fills ? chunkFK7EBZPX_cjs.replaceBlockStep(table) : chunkFK7EBZPX_cjs.insertBlocksStep(chunkFK7EBZPX_cjs.descendantsEnd(doc, index), [table])
348
+ const tr = new chunkZ5EEDCRI_cjs.Transaction(state).step(
349
+ fills ? chunkZ5EEDCRI_cjs.replaceBlockStep(table) : chunkZ5EEDCRI_cjs.insertBlocksStep(chunkZ5EEDCRI_cjs.descendantsEnd(doc, index), [table])
364
350
  );
365
- dispatch?.(tr.setSelection(chunkFK7EBZPX_cjs.textSelection({ block: table.id, region: chunkI7X7B3WD_cjs.cellKey(0, 0), offset: 0 })));
351
+ dispatch?.(tr.setSelection(chunkZ5EEDCRI_cjs.textSelection({ block: table.id, region: chunk4JDRDPLC_cjs.cellKey(0, 0), offset: 0 })));
366
352
  return true;
367
353
  };
368
354
  }
@@ -372,18 +358,18 @@ function headCell({ doc, selection }) {
372
358
  if (selection?.kind !== "text") return null;
373
359
  const { head } = selection;
374
360
  const block = tableBlock(doc, head.block);
375
- const cell = block && cellOf(head.region);
361
+ const cell = block && chunkZ5EEDCRI_cjs.cellOf(head.region);
376
362
  return block && cell ? { block, cell, head, shape: tableShape(block) } : null;
377
363
  }
378
- var cellLength = (block, [row, col]) => chunkI7X7B3WD_cjs.inlineLength(block.regions[chunkI7X7B3WD_cjs.cellKey(row, col)] ?? []);
364
+ var cellLength = (block, [row, col]) => chunk4JDRDPLC_cjs.inlineLength(block.regions[chunk4JDRDPLC_cjs.cellKey(row, col)] ?? []);
379
365
  var cellPos = (block, cell, atEnd = false) => ({
380
366
  block: block.id,
381
- region: chunkI7X7B3WD_cjs.cellKey(...cell),
367
+ region: chunk4JDRDPLC_cjs.cellKey(...cell),
382
368
  offset: atEnd ? cellLength(block, cell) : 0
383
369
  });
384
- var moveTo = (state, pos) => new chunkFK7EBZPX_cjs.Transaction(state).setSelection(chunkFK7EBZPX_cjs.textSelection(pos));
370
+ var moveTo = (state, pos) => new chunkZ5EEDCRI_cjs.Transaction(state).setSelection(chunkZ5EEDCRI_cjs.textSelection(pos));
385
371
  var thenCaretIn = (command, blockId, at) => (state, dispatch) => {
386
- const caret = chunkFK7EBZPX_cjs.textSelection({ block: blockId, region: chunkI7X7B3WD_cjs.cellKey(...at), offset: 0 });
372
+ const caret = chunkZ5EEDCRI_cjs.textSelection({ block: blockId, region: chunk4JDRDPLC_cjs.cellKey(...at), offset: 0 });
387
373
  return command(state, dispatch && ((tr) => dispatch(tr.setSelection(caret))));
388
374
  };
389
375
  var cellAtIndex = (index, { cols }) => [Math.floor(index / cols), index % cols];
@@ -416,11 +402,11 @@ var enterInCell = (state, dispatch) => {
416
402
  if (row === shape.rows - 1 && cellLength(block, cell) === 0) {
417
403
  return thenCaretIn(addRow(block.id, shape.rows), block.id, [shape.rows, col])(state, dispatch);
418
404
  }
419
- return chunkFK7EBZPX_cjs.insertHardBreak(state, dispatch);
405
+ return chunkZ5EEDCRI_cjs.insertHardBreak(state, dispatch);
420
406
  };
421
407
  var stopAtCellEdge = (atEnd) => (state) => {
422
408
  const caret = headCell(state);
423
- if (caret === null || !chunkFK7EBZPX_cjs.isCollapsed(state.selection)) return false;
409
+ if (caret === null || !chunkZ5EEDCRI_cjs.isCollapsed(state.selection)) return false;
424
410
  return caret.head.offset === (atEnd ? cellLength(caret.block, caret.cell) : 0);
425
411
  };
426
412
  var firstThatApplies = (...commands) => (state, dispatch) => commands.some((command) => command(state, dispatch));
@@ -442,7 +428,7 @@ var tableKeymap = {
442
428
  };
443
429
 
444
430
  // src/extensions/table/use-cell-press.ts
445
- function cellOf2(element) {
431
+ function pressedCell(element) {
446
432
  const row = element.getAttribute("data-row");
447
433
  const col = element.getAttribute("data-col");
448
434
  return element.matches("td, th") && row !== null && col !== null ? [Number(row), Number(col)] : null;
@@ -452,8 +438,8 @@ function useCellPress(controller, blockId, table, editable) {
452
438
  const element = table.current;
453
439
  if (!editable || element === null) return;
454
440
  const onPointerDown = (event) => {
455
- const cell = event.button === 0 && event.pointerType !== "touch" ? cellOf2(event.target) : null;
456
- const block = cell && chunkI7X7B3WD_cjs.blockById(controller.editor.state.doc, blockId);
441
+ const cell = event.button === 0 && event.pointerType !== "touch" ? pressedCell(event.target) : null;
442
+ const block = cell && chunk4JDRDPLC_cjs.blockById(controller.editor.state.doc, blockId);
457
443
  if (!cell || !block) return;
458
444
  event.preventDefault();
459
445
  event.stopPropagation();
@@ -464,7 +450,7 @@ function useCellPress(controller, blockId, table, editable) {
464
450
  }, [controller, blockId, table, editable]);
465
451
  }
466
452
  function useRevealCell(controller, blockId) {
467
- const region = chunk2QKFRKOP_cjs.useEditorState(
453
+ const region = chunkN25EH2GZ_cjs.useEditorState(
468
454
  controller,
469
455
  react.useCallback(
470
456
  (state) => {
@@ -481,97 +467,15 @@ function useRevealCell(controller, blockId) {
481
467
  host.closest("td, th")?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
482
468
  }, [controller, blockId, region]);
483
469
  }
484
-
485
- // src/extensions/table/vertical-cell-move.ts
486
- var VERTICAL = { ArrowUp: -1, ArrowDown: 1 };
487
- function caretAtGoal(controller, blockId, cell, direction) {
488
- const region = chunkI7X7B3WD_cjs.cellKey(...cell);
489
- const host = controller.registry.get(blockId, region);
490
- const { goalX } = controller;
491
- const line = host && chunk2QKFRKOP_cjs.lineEdgeRect(host, direction < 0);
492
- if (!host || !line || goalX === null) return null;
493
- const box = host.getBoundingClientRect();
494
- const x = Math.min(Math.max(goalX, box.left), box.right - 1);
495
- const point = chunk2QKFRKOP_cjs.caretFromPoint(host.ownerDocument, x, line.top + line.height / 2);
496
- const pos = point && chunk2QKFRKOP_cjs.domToPos(controller.registry, point.node, point.offset);
497
- return pos && pos.block === blockId && pos.region === region ? pos : null;
498
- }
499
- var plainArrow = (event) => event.altKey || event.ctrlKey || event.metaKey ? void 0 : VERTICAL[event.key];
500
- function caretOnEdgeLine(controller, head, direction) {
501
- const host = controller.registry.get(head.block, head.region);
502
- const point = chunk2QKFRKOP_cjs.posToDom(controller.registry, head);
503
- if (!host || !point || !(direction < 0 ? chunk2QKFRKOP_cjs.isOnFirstLine(host, point) : chunk2QKFRKOP_cjs.isOnLastLine(host, point))) return null;
504
- return { left: chunk2QKFRKOP_cjs.caretClientRect(point)?.left ?? null };
505
- }
506
- function columnAt(controller, blockId, row, x) {
507
- const cells = Array.from(controller.blockElement(blockId)?.querySelector("table")?.rows[row]?.cells ?? []);
508
- const index = cells.findIndex((cell) => x < cell.getBoundingClientRect().right);
509
- return index === -1 ? Math.max(cells.length - 1, 0) : index;
510
- }
511
- function enterTable(controller, blockId, event) {
512
- const direction = plainArrow(event);
513
- const { state } = controller.editor;
514
- const { selection } = state;
515
- const block = tableBlock(state.doc, blockId);
516
- if (direction === void 0 || event.shiftKey || block === null || selection?.kind !== "text") return false;
517
- if (!chunkFK7EBZPX_cjs.isCollapsed(selection) || chunk2QKFRKOP_cjs.neighbourBlock(state.doc, selection.head.block, direction)?.id !== blockId) return false;
518
- const caret = caretOnEdgeLine(controller, selection.head, direction);
519
- if (caret === null) return false;
520
- controller.goalX ??= caret.left;
521
- const { rows, cols } = tableShape(block);
522
- const row = direction > 0 ? 0 : rows - 1;
523
- const { goalX } = controller;
524
- const cell = [row, goalX === null ? direction > 0 ? 0 : cols - 1 : columnAt(controller, blockId, row, goalX)];
525
- const pos = caretAtGoal(controller, blockId, cell, direction) ?? cellPos(block, cell, direction < 0);
526
- controller.dispatch(controller.editor.createTransaction().setSelection(chunkFK7EBZPX_cjs.textSelection(pos)));
527
- return true;
528
- }
529
- function moveBetweenRows(controller, blockId, event) {
530
- const direction = plainArrow(event);
531
- const { state } = controller.editor;
532
- const caret = headCell(state);
533
- if (direction === void 0 || caret === null || caret.block.id !== blockId || state.selection?.kind !== "text") {
534
- return false;
535
- }
536
- const target = [caret.cell[0] + direction, caret.cell[1]];
537
- if (target[0] < 0 || target[0] >= caret.shape.rows) return false;
538
- const edge = caretOnEdgeLine(controller, caret.head, direction);
539
- if (edge === null) return false;
540
- controller.goalX ??= edge.left;
541
- const pos = caretAtGoal(controller, blockId, target, direction) ?? cellPos(caret.block, target, direction < 0);
542
- const selection = event.shiftKey ? chunkFK7EBZPX_cjs.textSelection(state.selection.anchor, pos) : chunkFK7EBZPX_cjs.textSelection(pos);
543
- controller.dispatch(controller.editor.createTransaction().setSelection(selection));
544
- return true;
545
- }
546
-
547
- // src/extensions/table/use-table-keys.ts
548
- var printable = (event) => [...event.key].length === 1 && !event.ctrlKey && !event.metaKey;
549
- function typeOver(controller, blockId, event) {
550
- if (cellSelection(controller.editor.state)?.block !== blockId || !printable(event)) return false;
551
- return controller.run(typeOverCells(event.key));
552
- }
553
- function useTableKeys(controller, blockId, editable) {
554
- react.useEffect(() => {
555
- if (!editable) return;
556
- const intercept = (event) => {
557
- if (chunk2QKFRKOP_cjs.isComposingKey(controller, event)) return false;
558
- const handled = typeOver(controller, blockId, event) || moveBetweenRows(controller, blockId, event) || enterTable(controller, blockId, event);
559
- if (handled) event.preventDefault();
560
- return handled;
561
- };
562
- return chunkEBSDPHPS_cjs.interceptKeys(controller, intercept);
563
- }, [controller, blockId, editable]);
564
- }
565
470
  var indexes = (from, to) => Array.from({ length: Math.max(to - from, 0) }, (_, i) => from + i);
566
471
  function TableBlock({ block, controller, labels }) {
567
- const readOnly = chunk2QKFRKOP_cjs.useReadOnly(controller);
472
+ const readOnly = chunkN25EH2GZ_cjs.useReadOnly(controller);
568
473
  const table = react.useRef(null);
569
474
  const { rows, cols } = tableShape(block);
570
475
  const header = block.attrs.header !== false && rows > 0;
571
476
  const aligns = columnAligns(block, cols);
572
477
  const preview = useWidthPreview(controller, block.id);
573
478
  const widths = preview?.length === cols ? preview : storedWidths(block, cols);
574
- useTableKeys(controller, block.id, !readOnly);
575
479
  useCellPress(controller, block.id, table, !readOnly);
576
480
  useRevealCell(controller, block.id);
577
481
  const row = (index) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: indexes(0, cols).map((col) => /* @__PURE__ */ jsxRuntime.jsx(
@@ -588,7 +492,7 @@ function TableBlock({ block, controller, labels }) {
588
492
  col
589
493
  )) }, index);
590
494
  const scroller = readOnly ? { role: "region", "aria-label": labels.table, tabIndex: 0 } : void 0;
591
- return /* @__PURE__ */ jsxRuntime.jsx("div", { contentEditable: false, className: "quoin-table", "data-readonly": readOnly ? "" : void 0, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `quoin-table-scroll ${readOnly ? chunkEBSDPHPS_cjs.FOCUS_RING : ""}`, ...scroller, children: [
495
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { contentEditable: false, className: "quoin-table", "data-readonly": readOnly ? "" : void 0, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `quoin-table-scroll ${readOnly ? chunk4UFWFV43_cjs.FOCUS_RING : ""}`, ...scroller, children: [
592
496
  /* @__PURE__ */ jsxRuntime.jsxs(
593
497
  "table",
594
498
  {
@@ -612,10 +516,10 @@ function lineCells(block, index, axis) {
612
516
  const { rows, cols } = tableShape(block);
613
517
  return Array.from(
614
518
  { length: axis === "row" ? cols : rows },
615
- (_, other) => axis === "row" ? block.regions[chunkI7X7B3WD_cjs.cellKey(index, other)] ?? EMPTY : block.regions[chunkI7X7B3WD_cjs.cellKey(other, index)] ?? EMPTY
519
+ (_, other) => axis === "row" ? block.regions[chunk4JDRDPLC_cjs.cellKey(index, other)] ?? EMPTY : block.regions[chunk4JDRDPLC_cjs.cellKey(other, index)] ?? EMPTY
616
520
  );
617
521
  }
618
- var sameLine = (before, after, index, axis) => chunkI7X7B3WD_cjs.sameItems(lineCells(before, index, axis), lineCells(after, index, axis), chunkI7X7B3WD_cjs.equalInline);
522
+ var sameLine = (before, after, index, axis) => chunk4JDRDPLC_cjs.sameItems(lineCells(before, index, axis), lineCells(after, index, axis), chunk4JDRDPLC_cjs.equalInline);
619
523
  function sameMenuCells(opened, current, target, axis) {
620
524
  const shape = tableShape(opened);
621
525
  const lines = axis === "row" ? shape.rows : shape.cols;
@@ -632,7 +536,7 @@ var STEP = 10;
632
536
  var LARGE_STEP = 50;
633
537
  var clampWidth = (px) => Math.min(MAX_COLUMN_WIDTH, Math.max(MIN_COLUMN_WIDTH, Math.round(px)));
634
538
  function ColumnResizer(props) {
635
- const { controller, labels, blockId, col, drawn, style, resizerRef, onHold, onBack } = props;
539
+ const { controller, labels, blockId, col, drawn, direction, style, resizerRef, onHold, onBack } = props;
636
540
  const drag = react.useRef(null);
637
541
  const width = Math.round(drawn[col] ?? 0);
638
542
  const store = tableUiStore(controller);
@@ -640,11 +544,12 @@ function ColumnResizer(props) {
640
544
  if (!controller.readOnly) controller.run(setColumnWidth(blockId, col, px, widths));
641
545
  };
642
546
  const onKeyDown = (event) => {
643
- if (chunk2QKFRKOP_cjs.isComposingKey(controller, event.nativeEvent)) return;
547
+ if (chunkN25EH2GZ_cjs.isComposingKey(controller, event.nativeEvent)) return;
644
548
  const step = event.shiftKey ? LARGE_STEP : STEP;
645
549
  const tab = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
646
- if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
647
- const next = clampWidth(width + (event.key === "ArrowLeft" ? -step : step));
550
+ const arrow = chunkN25EH2GZ_cjs.arrowAsWritten(event.key, direction);
551
+ if (arrow === "ArrowLeft" || arrow === "ArrowRight") {
552
+ const next = clampWidth(width + (arrow === "ArrowLeft" ? -step : step));
648
553
  if (next !== width) write(next, drawn);
649
554
  } else if (tab && event.shiftKey) onBack();
650
555
  else if (tab || event.key === "Escape") controller.focus();
@@ -660,7 +565,8 @@ function ColumnResizer(props) {
660
565
  const onPointerMove = (event) => {
661
566
  const current = drag.current;
662
567
  if (current === null) return;
663
- current.to = clampWidth(current.widths[col] + event.clientX - current.x);
568
+ const moved = event.clientX - current.x;
569
+ current.to = clampWidth(current.widths[col] + (direction === "rtl" ? -moved : moved));
664
570
  const widths = current.widths.map((px, i) => i === col ? current.to ?? px : px);
665
571
  store.set({ preview: { block: blockId, widths } });
666
572
  };
@@ -677,7 +583,7 @@ function ColumnResizer(props) {
677
583
  },
678
584
  [store]
679
585
  );
680
- const end2 = () => {
586
+ const end = () => {
681
587
  const ended = stop();
682
588
  if (ended?.to != null && ended.to !== Math.round(ended.widths[col])) write(ended.to, ended.widths);
683
589
  };
@@ -695,11 +601,11 @@ function ColumnResizer(props) {
695
601
  "aria-valuetext": labels.columnWidth(width),
696
602
  className: "quoin-table-resizer",
697
603
  style,
698
- ...{ [chunk2QKFRKOP_cjs.NATIVE_INTERACTION]: "" },
604
+ ...{ [chunkN25EH2GZ_cjs.NATIVE_INTERACTION]: "" },
699
605
  onKeyDown,
700
606
  onPointerDown,
701
607
  onPointerMove,
702
- onPointerUp: end2,
608
+ onPointerUp: end,
703
609
  onPointerCancel: stop
704
610
  }
705
611
  );
@@ -710,20 +616,20 @@ function HandleMenu({ controller, axis, label, style, items, open, onOpenChange,
710
616
  if (controller.run(item3.command)) controller.announce(item3.done);
711
617
  };
712
618
  const item2 = (entry) => /* @__PURE__ */ jsxRuntime.jsxs(
713
- chunkEBSDPHPS_cjs.DropdownMenuItem,
619
+ chunk4UFWFV43_cjs.DropdownMenuItem,
714
620
  {
715
621
  disabled: entry.disabled,
716
622
  className: entry.destructive ? DESTRUCTIVE : void 0,
717
623
  onSelect: () => run(entry),
718
624
  children: [
719
- /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.MenuIcon, { icon: entry.icon }),
625
+ /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.MenuIcon, { icon: entry.icon }),
720
626
  entry.label
721
627
  ]
722
628
  },
723
629
  entry.id
724
630
  );
725
- return /* @__PURE__ */ jsxRuntime.jsxs(chunkEBSDPHPS_cjs.DropdownMenu, { open, onOpenChange, children: [
726
- /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
631
+ return /* @__PURE__ */ jsxRuntime.jsxs(chunk4UFWFV43_cjs.DropdownMenu, { open, onOpenChange, children: [
632
+ /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
727
633
  "button",
728
634
  {
729
635
  ref: buttonRef,
@@ -733,22 +639,22 @@ function HandleMenu({ controller, axis, label, style, items, open, onOpenChange,
733
639
  "data-axis": axis,
734
640
  className: "quoin-table-handle",
735
641
  style,
736
- children: axis === "row" ? /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.GripVertical, { "aria-hidden": "true" }) : /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.GripHorizontal, { "aria-hidden": "true" })
642
+ children: axis === "row" ? /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.GripVertical, { "aria-hidden": "true" }) : /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.GripHorizontal, { "aria-hidden": "true" })
737
643
  }
738
644
  ) }),
739
645
  open && /* @__PURE__ */ jsxRuntime.jsxs(
740
- chunkEBSDPHPS_cjs.DropdownMenuContent,
646
+ chunk4UFWFV43_cjs.DropdownMenuContent,
741
647
  {
742
648
  align: "start",
743
649
  "aria-label": label,
744
650
  "aria-labelledby": void 0,
745
- onCloseAutoFocus: chunkEBSDPHPS_cjs.returnFocusToText(controller),
746
- ...chunkEBSDPHPS_cjs.bubblePart(controller),
651
+ onCloseAutoFocus: chunk4UFWFV43_cjs.returnFocusToText(controller),
652
+ ...chunk4UFWFV43_cjs.bubblePart(controller),
747
653
  children: [
748
654
  items.filter((entry) => !entry.destructive).map(item2),
749
655
  children,
750
656
  items.filter((entry) => entry.destructive).map((entry) => /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
751
- /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.DropdownMenuSeparator, {}),
657
+ /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.DropdownMenuSeparator, {}),
752
658
  item2(entry)
753
659
  ] }, entry.id))
754
660
  ]
@@ -757,16 +663,59 @@ function HandleMenu({ controller, axis, label, style, items, open, onOpenChange,
757
663
  ] });
758
664
  }
759
665
 
666
+ // src/extensions/table/table-geometry.ts
667
+ function measureTable(table, origin) {
668
+ const box = table.getBoundingClientRect();
669
+ const first = table.rows[0];
670
+ return {
671
+ left: box.left - origin.left,
672
+ top: box.top - origin.top,
673
+ width: box.width,
674
+ height: box.height,
675
+ rows: Array.from(table.rows, (row) => {
676
+ const rect = row.getBoundingClientRect();
677
+ return { start: rect.top - origin.top, size: rect.height };
678
+ }),
679
+ cols: Array.from(first?.cells ?? [], (cell) => {
680
+ const rect = cell.getBoundingClientRect();
681
+ return { start: rect.left - origin.left, size: rect.width };
682
+ }),
683
+ direction: chunkN25EH2GZ_cjs.inlineDirection(table)
684
+ };
685
+ }
686
+ var sameSpans = (a, b) => a.length === b.length && a.every((span, i) => span.start === b[i].start && span.size === b[i].size);
687
+ var sameGeometry = (a, b) => a === b || a !== null && b !== null && a.left === b.left && a.top === b.top && a.width === b.width && a.height === b.height && a.direction === b.direction && sameSpans(a.rows, b.rows) && sameSpans(a.cols, b.cols);
688
+ var spanEnd = (span) => span.start + span.size;
689
+ var leadingEdge = (span, direction) => direction === "rtl" ? spanEnd(span) : span.start;
690
+ var trailingEdge = (span, direction) => direction === "rtl" ? span.start : spanEnd(span);
691
+ function spanAt(spans, at) {
692
+ const inside = spans.findIndex((span) => span.start <= at && at < spanEnd(span));
693
+ if (inside !== -1) return inside;
694
+ const distances = spans.map((span) => Math.min(Math.abs(span.start - at), Math.abs(spanEnd(span) - at)));
695
+ return distances.indexOf(Math.min(...distances));
696
+ }
697
+ function edgeNear(spans, at, reach, direction = "ltr") {
698
+ if (spans.length === 0) return null;
699
+ const last = trailingEdge(spans[spans.length - 1], direction);
700
+ const edges = [...spans.map((span) => leadingEdge(span, direction)), last];
701
+ const index = edges.findIndex((edge) => Math.abs(edge - at) <= reach);
702
+ return index === -1 ? null : index;
703
+ }
704
+ function edgeAt(spans, edge, direction = "ltr") {
705
+ if (edge === null || !Number.isInteger(edge) || edge < 0 || edge > spans.length || spans.length === 0) return null;
706
+ return edge === spans.length ? trailingEdge(spans[edge - 1], direction) : leadingEdge(spans[edge], direction);
707
+ }
708
+
760
709
  // src/extensions/table/table-menu-items.ts
761
710
  var item = (id, label, icon, command, done, options = {}) => ({ id, label, icon, command, done, ...options });
762
711
  function rowMenuItems(labels, blockId, row, { rows }) {
763
712
  const { rowInserted, rowMoved, rowDeleted } = labels;
764
713
  return [
765
- item("above", labels.insertRowAbove, chunkEBSDPHPS_cjs.ArrowUpToLine, addRow(blockId, row), rowInserted),
766
- item("below", labels.insertRowBelow, chunkEBSDPHPS_cjs.ArrowDownToLine, addRow(blockId, row + 1), rowInserted),
767
- item("up", labels.moveRowUp, chunkEBSDPHPS_cjs.ArrowUp, moveRow(blockId, row, row - 1), rowMoved, { disabled: row === 0 }),
768
- item("down", labels.moveRowDown, chunkEBSDPHPS_cjs.ArrowDown, moveRow(blockId, row, row + 1), rowMoved, { disabled: row === rows - 1 }),
769
- item("delete", labels.deleteRow, chunkEBSDPHPS_cjs.Trash, removeRow(blockId, row), rowDeleted, { disabled: rows === 1, destructive: true })
714
+ item("above", labels.insertRowAbove, chunk4UFWFV43_cjs.ArrowUpToLine, addRow(blockId, row), rowInserted),
715
+ item("below", labels.insertRowBelow, chunk4UFWFV43_cjs.ArrowDownToLine, addRow(blockId, row + 1), rowInserted),
716
+ item("up", labels.moveRowUp, chunk4UFWFV43_cjs.ArrowUp, moveRow(blockId, row, row - 1), rowMoved, { disabled: row === 0 }),
717
+ item("down", labels.moveRowDown, chunk4UFWFV43_cjs.ArrowDown, moveRow(blockId, row, row + 1), rowMoved, { disabled: row === rows - 1 }),
718
+ item("delete", labels.deleteRow, chunk4UFWFV43_cjs.Trash, removeRow(blockId, row), rowDeleted, { disabled: rows === 1, destructive: true })
770
719
  ];
771
720
  }
772
721
  function columnMenuItems(labels, blockId, col, { cols }, direction = "ltr") {
@@ -777,32 +726,28 @@ function columnMenuItems(labels, blockId, col, { cols }, direction = "ltr") {
777
726
  const last = col === cols - 1;
778
727
  const [leftEdge, rightEdge] = direction === "rtl" ? [last, first] : [first, last];
779
728
  return [
780
- item("left", labels.insertColumnLeft, chunkEBSDPHPS_cjs.ArrowLeftToLine, addColumn(blockId, direction === "rtl" ? col + 1 : col), columnInserted),
781
- item("right", labels.insertColumnRight, chunkEBSDPHPS_cjs.ArrowRightToLine, addColumn(blockId, direction === "rtl" ? col : col + 1), columnInserted),
782
- item("move-left", labels.moveColumnLeft, chunkEBSDPHPS_cjs.ArrowLeft, moveColumn(blockId, col, onTheLeft), columnMoved, { disabled: leftEdge }),
783
- item("move-right", labels.moveColumnRight, chunkEBSDPHPS_cjs.ArrowRight, moveColumn(blockId, col, onTheRight), columnMoved, { disabled: rightEdge }),
784
- item("delete", labels.deleteColumn, chunkEBSDPHPS_cjs.Trash, removeColumn(blockId, col), columnDeleted, {
729
+ item("left", labels.insertColumnLeft, chunk4UFWFV43_cjs.ArrowLeftToLine, addColumn(blockId, direction === "rtl" ? col + 1 : col), columnInserted),
730
+ item("right", labels.insertColumnRight, chunk4UFWFV43_cjs.ArrowRightToLine, addColumn(blockId, direction === "rtl" ? col : col + 1), columnInserted),
731
+ item("move-left", labels.moveColumnLeft, chunk4UFWFV43_cjs.ArrowLeft, moveColumn(blockId, col, onTheLeft), columnMoved, { disabled: leftEdge }),
732
+ item("move-right", labels.moveColumnRight, chunk4UFWFV43_cjs.ArrowRight, moveColumn(blockId, col, onTheRight), columnMoved, { disabled: rightEdge }),
733
+ item("delete", labels.deleteColumn, chunk4UFWFV43_cjs.Trash, removeColumn(blockId, col), columnDeleted, {
785
734
  disabled: cols === 1,
786
735
  destructive: true
787
736
  })
788
737
  ];
789
738
  }
790
739
  var alignItems = (labels) => [
791
- { value: "left", label: labels.alignLeft, icon: chunkEBSDPHPS_cjs.AlignLeft, done: labels.alignedLeft },
792
- { value: "center", label: labels.alignCenter, icon: chunkEBSDPHPS_cjs.AlignCenter, done: labels.alignedCenter },
793
- { value: "right", label: labels.alignRight, icon: chunkEBSDPHPS_cjs.AlignRight, done: labels.alignedRight }
740
+ { value: "left", label: labels.alignLeft, icon: chunk4UFWFV43_cjs.AlignLeft, done: labels.alignedLeft },
741
+ { value: "center", label: labels.alignCenter, icon: chunk4UFWFV43_cjs.AlignCenter, done: labels.alignedCenter },
742
+ { value: "right", label: labels.alignRight, icon: chunk4UFWFV43_cjs.AlignRight, done: labels.alignedRight }
794
743
  ];
795
744
  var BESIDE = 4;
796
- var end = (span) => span.start + span.size;
797
- function edgeOf(spans, edge) {
798
- if (edge === null || !Number.isInteger(edge) || edge < 0 || edge > spans.length || spans.length === 0) return null;
799
- return edge === spans.length ? end(spans[edge - 1]) : spans[edge].start;
800
- }
745
+ var besideRows = ({ left, width, direction }) => direction === "rtl" ? left + width + BESIDE : left - BESIDE;
801
746
  var middle = (span) => span.start + span.size / 2;
802
747
  var isTab = (event) => event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
803
748
  function TableHandles(props) {
804
749
  const { controller, labels, block, target, geometry, menu, onMenu, onHold, focusRequested, onFocused } = props;
805
- const direction = controller.root === null ? "ltr" : chunk2QKFRKOP_cjs.inlineDirection(controller.root);
750
+ const { direction } = geometry;
806
751
  const rowHandle = react.useRef(null);
807
752
  const columnHandle = react.useRef(null);
808
753
  const resizer = react.useRef(null);
@@ -812,9 +757,9 @@ function TableHandles(props) {
812
757
  const align = columnAligns(block, shape.cols)[col];
813
758
  const drawn = geometry.cols.map((span) => span.size);
814
759
  const { rowEdge, colEdge } = target;
815
- const rowInsertAt = edgeOf(geometry.rows, rowEdge);
816
- const columnInsertAt = edgeOf(geometry.cols, colEdge);
817
- chunk2QKFRKOP_cjs.useIsomorphicLayoutEffect(() => {
760
+ const rowInsertAt = edgeAt(geometry.rows, rowEdge);
761
+ const columnInsertAt = edgeAt(geometry.cols, colEdge, direction);
762
+ chunkN25EH2GZ_cjs.useIsomorphicLayoutEffect(() => {
818
763
  if (!focusRequested) return;
819
764
  (columnHandle.current ?? rowHandle.current)?.focus();
820
765
  onFocused();
@@ -825,7 +770,7 @@ function TableHandles(props) {
825
770
  const onKeyDown = (event) => {
826
771
  const handles = [rowHandle.current, columnHandle.current].filter((handle) => handle !== null);
827
772
  const index = handles.indexOf(event.target);
828
- if (index === -1 || chunk2QKFRKOP_cjs.isComposingKey(controller, event.nativeEvent)) return;
773
+ if (index === -1 || chunkN25EH2GZ_cjs.isComposingKey(controller, event.nativeEvent)) return;
829
774
  if (event.key === "ArrowLeft" || event.key === "ArrowRight") handles[(index + 1) % handles.length].focus();
830
775
  else if (isTab(event) && !event.shiftKey && resizer.current !== null) resizer.current.focus();
831
776
  else if (isTab(event) || event.key === "Escape") controller.focus();
@@ -843,7 +788,8 @@ function TableHandles(props) {
843
788
  blockId: block.id,
844
789
  col: index,
845
790
  drawn,
846
- style: { left: end(span), top: geometry.top, height: geometry.height },
791
+ direction,
792
+ style: { left: trailingEdge(span, direction), top: geometry.top, height: geometry.height },
847
793
  resizerRef: index === col ? resizer : void 0,
848
794
  onHold,
849
795
  onBack: () => (columnHandle.current ?? rowHandle.current)?.focus()
@@ -857,13 +803,13 @@ function TableHandles(props) {
857
803
  controller,
858
804
  axis: "row",
859
805
  label: labels.rowOptions(row + 1),
860
- style: place(geometry.left - BESIDE, middle(geometry.rows[row])),
806
+ style: place(besideRows(geometry), middle(geometry.rows[row])),
861
807
  items: rowMenuItems(labels, block.id, row, shape),
862
808
  open: menu === "row",
863
809
  onOpenChange: opener("row"),
864
810
  buttonRef: rowHandle,
865
811
  children: row === 0 && /* @__PURE__ */ jsxRuntime.jsx(
866
- chunkEBSDPHPS_cjs.DropdownMenuCheckboxItem,
812
+ chunk4UFWFV43_cjs.DropdownMenuCheckboxItem,
867
813
  {
868
814
  checked: block.attrs.header !== false,
869
815
  onCheckedChange: (on) => run(toggleHeaderRow(block.id), on ? labels.headerRowOn : labels.headerRowOff),
@@ -884,14 +830,14 @@ function TableHandles(props) {
884
830
  onOpenChange: opener("column"),
885
831
  buttonRef: columnHandle,
886
832
  children: [
887
- /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.DropdownMenuSeparator, {}),
888
- /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.DropdownMenuRadioGroup, { value: align ?? "", children: alignItems(labels).map(({ value, label, icon, done }) => /* @__PURE__ */ jsxRuntime.jsxs(
889
- chunkEBSDPHPS_cjs.DropdownMenuRadioItem,
833
+ /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.DropdownMenuSeparator, {}),
834
+ /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.DropdownMenuRadioGroup, { value: align ?? "", children: alignItems(labels).map(({ value, label, icon, done }) => /* @__PURE__ */ jsxRuntime.jsxs(
835
+ chunk4UFWFV43_cjs.DropdownMenuRadioItem,
890
836
  {
891
837
  value,
892
838
  onSelect: () => align === value ? run(setColumnAlign(block.id, col, null), labels.alignmentCleared) : run(setColumnAlign(block.id, col, value), done),
893
839
  children: [
894
- /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.MenuIcon, { icon }),
840
+ /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.MenuIcon, { icon }),
895
841
  label
896
842
  ]
897
843
  },
@@ -909,11 +855,11 @@ function TableHandles(props) {
909
855
  "aria-label": labels.insertRowAt(rowEdge + 1),
910
856
  "data-axis": "row",
911
857
  className: "quoin-table-insert",
912
- style: place(geometry.left - BESIDE, rowInsertAt),
913
- onPointerDown: chunkEBSDPHPS_cjs.keepFocus,
914
- onMouseDown: chunkEBSDPHPS_cjs.keepFocus,
858
+ style: place(besideRows(geometry), rowInsertAt),
859
+ onPointerDown: chunk4UFWFV43_cjs.keepFocus,
860
+ onMouseDown: chunk4UFWFV43_cjs.keepFocus,
915
861
  onClick: () => run(addRow(block.id, rowEdge), labels.rowInserted),
916
- children: /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.Plus, { "aria-hidden": "true" })
862
+ children: /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.Plus, { "aria-hidden": "true" })
917
863
  }
918
864
  ),
919
865
  colEdge !== null && columnInsertAt !== null && /* @__PURE__ */ jsxRuntime.jsx(
@@ -925,51 +871,17 @@ function TableHandles(props) {
925
871
  "data-axis": "column",
926
872
  className: "quoin-table-insert",
927
873
  style: place(columnInsertAt, geometry.top),
928
- onPointerDown: chunkEBSDPHPS_cjs.keepFocus,
929
- onMouseDown: chunkEBSDPHPS_cjs.keepFocus,
874
+ onPointerDown: chunk4UFWFV43_cjs.keepFocus,
875
+ onMouseDown: chunk4UFWFV43_cjs.keepFocus,
930
876
  onClick: () => run(addColumn(block.id, colEdge), labels.columnInserted),
931
- children: /* @__PURE__ */ jsxRuntime.jsx(chunkEBSDPHPS_cjs.Plus, { "aria-hidden": "true" })
877
+ children: /* @__PURE__ */ jsxRuntime.jsx(chunk4UFWFV43_cjs.Plus, { "aria-hidden": "true" })
932
878
  }
933
879
  )
934
880
  ] });
935
881
  }
936
-
937
- // src/extensions/table/table-geometry.ts
938
- function measureTable(table, origin) {
939
- const box = table.getBoundingClientRect();
940
- const first = table.rows[0];
941
- return {
942
- left: box.left - origin.left,
943
- top: box.top - origin.top,
944
- width: box.width,
945
- height: box.height,
946
- rows: Array.from(table.rows, (row) => {
947
- const rect = row.getBoundingClientRect();
948
- return { start: rect.top - origin.top, size: rect.height };
949
- }),
950
- cols: Array.from(first?.cells ?? [], (cell) => {
951
- const rect = cell.getBoundingClientRect();
952
- return { start: rect.left - origin.left, size: rect.width };
953
- })
954
- };
955
- }
956
- var sameSpans = (a, b) => a.length === b.length && a.every((span, i) => span.start === b[i].start && span.size === b[i].size);
957
- var sameGeometry = (a, b) => a === b || a !== null && b !== null && a.left === b.left && a.top === b.top && a.width === b.width && a.height === b.height && sameSpans(a.rows, b.rows) && sameSpans(a.cols, b.cols);
958
- function spanAt(spans, at) {
959
- const inside = spans.findIndex((span) => at < span.start + span.size);
960
- return inside === -1 ? spans.length - 1 : inside;
961
- }
962
- function edgeNear(spans, at, reach) {
963
- if (spans.length === 0) return null;
964
- const edges = [spans[0].start, ...spans.map((span) => span.start + span.size)];
965
- const index = edges.findIndex((edge) => Math.abs(edge - at) <= reach);
966
- return index === -1 ? null : index;
967
- }
968
-
969
- // src/extensions/table/use-table-geometry.ts
970
882
  function useTableGeometry(controller, blockId, slot) {
971
883
  const [geometry, setGeometry] = react.useState(null);
972
- chunk2QKFRKOP_cjs.useIsomorphicLayoutEffect(() => {
884
+ chunkN25EH2GZ_cjs.useIsomorphicLayoutEffect(() => {
973
885
  const table = controller.blockElement(blockId)?.querySelector("table");
974
886
  const view = slot.ownerDocument.defaultView;
975
887
  if (!table || !view) return;
@@ -984,31 +896,103 @@ function useTableGeometry(controller, blockId, slot) {
984
896
  frame = view.requestAnimationFrame(measure);
985
897
  };
986
898
  const unsubscribe = controller.editor.subscribe(later);
899
+ const unwatch = chunk4UFWFV43_cjs.watchDirection(table, later);
987
900
  const observer = new ResizeObserver(later);
988
901
  observer.observe(table);
989
902
  view.addEventListener("resize", later);
990
903
  return () => {
991
904
  view.cancelAnimationFrame(frame);
992
905
  unsubscribe();
906
+ unwatch();
993
907
  observer.disconnect();
994
908
  view.removeEventListener("resize", later);
995
909
  };
996
910
  }, [controller, blockId, slot]);
997
911
  return geometry;
998
912
  }
999
- function useCutCells(controller) {
913
+
914
+ // src/extensions/table/vertical-cell-move.ts
915
+ var VERTICAL = { ArrowUp: -1, ArrowDown: 1 };
916
+ function caretAtGoal(controller, blockId, cell, direction) {
917
+ const region = chunk4JDRDPLC_cjs.cellKey(...cell);
918
+ const host = controller.registry.get(blockId, region);
919
+ const { goalX } = controller;
920
+ const line = host && chunkN25EH2GZ_cjs.lineEdgeRect(host, direction < 0);
921
+ if (!host || !line || goalX === null) return null;
922
+ const box = host.getBoundingClientRect();
923
+ const x = Math.min(Math.max(goalX, box.left), box.right - 1);
924
+ const point = chunkN25EH2GZ_cjs.caretFromPoint(host.ownerDocument, x, line.top + line.height / 2);
925
+ const pos = point && chunkN25EH2GZ_cjs.domToPos(controller.registry, point.node, point.offset);
926
+ return pos && pos.block === blockId && pos.region === region ? pos : null;
927
+ }
928
+ var plainArrow = (event) => event.altKey || event.ctrlKey || event.metaKey ? void 0 : VERTICAL[event.key];
929
+ function caretOnEdgeLine(controller, head, direction) {
930
+ const host = controller.registry.get(head.block, head.region);
931
+ const point = chunkN25EH2GZ_cjs.posToDom(controller.registry, head);
932
+ if (!host || !point || !(direction < 0 ? chunkN25EH2GZ_cjs.isOnFirstLine(host, point) : chunkN25EH2GZ_cjs.isOnLastLine(host, point))) return null;
933
+ return { left: chunkN25EH2GZ_cjs.caretClientRect(point)?.left ?? null };
934
+ }
935
+ function columnAt(controller, blockId, row, x) {
936
+ const cells = Array.from(controller.blockElement(blockId)?.querySelector("table")?.rows[row]?.cells ?? []);
937
+ const spans = cells.map((cell) => {
938
+ const { left, width } = cell.getBoundingClientRect();
939
+ return { start: left, size: width };
940
+ });
941
+ return Math.max(spanAt(spans, x), 0);
942
+ }
943
+ function enterTable(controller, event) {
944
+ const direction = plainArrow(event);
945
+ const { state } = controller.editor;
946
+ const { selection } = state;
947
+ if (direction === void 0 || event.shiftKey || selection?.kind !== "text" || !chunkZ5EEDCRI_cjs.isCollapsed(selection)) return false;
948
+ const block = chunkN25EH2GZ_cjs.neighbourBlock(state.doc, selection.head.block, direction);
949
+ if (block?.type !== "TABLE") return false;
950
+ const blockId = block.id;
951
+ const caret = caretOnEdgeLine(controller, selection.head, direction);
952
+ if (caret === null) return false;
953
+ controller.goalX ??= caret.left;
954
+ const { rows, cols } = tableShape(block);
955
+ const row = direction > 0 ? 0 : rows - 1;
956
+ const { goalX } = controller;
957
+ const cell = [row, goalX === null ? direction > 0 ? 0 : cols - 1 : columnAt(controller, blockId, row, goalX)];
958
+ const pos = caretAtGoal(controller, blockId, cell, direction) ?? cellPos(block, cell, direction < 0);
959
+ controller.dispatch(controller.editor.createTransaction().setSelection(chunkZ5EEDCRI_cjs.textSelection(pos)));
960
+ return true;
961
+ }
962
+ function moveBetweenRows(controller, event) {
963
+ const direction = plainArrow(event);
964
+ const { state } = controller.editor;
965
+ const caret = headCell(state);
966
+ if (direction === void 0 || caret === null || state.selection?.kind !== "text") return false;
967
+ const blockId = caret.block.id;
968
+ const target = [caret.cell[0] + direction, caret.cell[1]];
969
+ if (target[0] < 0 || target[0] >= caret.shape.rows) return false;
970
+ const edge = caretOnEdgeLine(controller, caret.head, direction);
971
+ if (edge === null) return false;
972
+ controller.goalX ??= edge.left;
973
+ const pos = caretAtGoal(controller, blockId, target, direction) ?? cellPos(caret.block, target, direction < 0);
974
+ const selection = event.shiftKey ? chunkZ5EEDCRI_cjs.textSelection(state.selection.anchor, pos) : chunkZ5EEDCRI_cjs.textSelection(pos);
975
+ controller.dispatch(controller.editor.createTransaction().setSelection(selection));
976
+ return true;
977
+ }
978
+
979
+ // src/extensions/table/use-table-keys.ts
980
+ var printable = (event) => [...event.key].length === 1 && !event.ctrlKey && !event.metaKey;
981
+ function typeOver(controller, event) {
982
+ if (cellSelection(controller.editor.state) === null || !printable(event)) return false;
983
+ return controller.run(typeOverCells(event.key));
984
+ }
985
+ function useTableKeys(controller, editable) {
1000
986
  react.useEffect(() => {
1001
- const root = controller.root;
1002
- if (root === null) return;
1003
- const onCut = (event) => {
1004
- if (controller.readOnly || cellSelection(controller.editor.state) === null) return;
1005
- event.stopPropagation();
1006
- chunk2QKFRKOP_cjs.handleCopy(controller, event, false);
1007
- controller.run(deleteCellContents);
987
+ if (!editable) return;
988
+ const intercept = (event) => {
989
+ if (chunkN25EH2GZ_cjs.isComposingKey(controller, event)) return false;
990
+ const handled = typeOver(controller, event) || moveBetweenRows(controller, event) || enterTable(controller, event);
991
+ if (handled) event.preventDefault();
992
+ return handled;
1008
993
  };
1009
- root.addEventListener("cut", onCut, true);
1010
- return () => root.removeEventListener("cut", onCut, true);
1011
- }, [controller]);
994
+ return chunk4UFWFV43_cjs.interceptKeys(controller, intercept);
995
+ }, [controller, editable]);
1012
996
  }
1013
997
  var EDGE_ZONE = 24;
1014
998
  var EDGE_REACH = 8;
@@ -1019,6 +1003,7 @@ function caretTarget(state) {
1019
1003
  const caret = headCell(state);
1020
1004
  return caret && { block: caret.block.id, row: caret.cell[0], col: caret.cell[1], rowEdge: null, colEdge: null };
1021
1005
  }
1006
+ var nearRowStarts = ({ left, width, direction }, x) => direction === "rtl" ? x > left + width - EDGE_ZONE : x < left + EDGE_ZONE;
1022
1007
  function pointerTarget(controller, event) {
1023
1008
  const blockId = controller.blockAt(event.target);
1024
1009
  const block = blockId === void 0 ? null : tableBlock(controller.editor.state.doc, blockId);
@@ -1029,8 +1014,8 @@ function pointerTarget(controller, event) {
1029
1014
  const row = spanAt(geometry.rows, y);
1030
1015
  const col = spanAt(geometry.cols, x);
1031
1016
  if (row < 0 || col < 0) return null;
1032
- const rowEdge = x < geometry.left + EDGE_ZONE ? edgeNear(geometry.rows, y, EDGE_REACH) : null;
1033
- const colEdge = y < geometry.top + EDGE_ZONE ? edgeNear(geometry.cols, x, EDGE_REACH) : null;
1017
+ const rowEdge = nearRowStarts(geometry, x) ? edgeNear(geometry.rows, y, EDGE_REACH) : null;
1018
+ const colEdge = y < geometry.top + EDGE_ZONE ? edgeNear(geometry.cols, x, EDGE_REACH, geometry.direction) : null;
1034
1019
  return { block: block.id, row, col, rowEdge, colEdge };
1035
1020
  }
1036
1021
  function shapeOf(state, blockId) {
@@ -1047,9 +1032,9 @@ function focusOf(root) {
1047
1032
  function useTableTarget(controller, held) {
1048
1033
  const [hovered, setHovered] = react.useState(null);
1049
1034
  const [focus, setFocus] = react.useState("none");
1050
- const caret = chunk2QKFRKOP_cjs.useEditorState(controller, caretTarget, sameTarget);
1035
+ const caret = chunkN25EH2GZ_cjs.useEditorState(controller, caretTarget, sameTarget);
1051
1036
  const hoveredBlock = hovered?.target.block ?? null;
1052
- const shape = chunk2QKFRKOP_cjs.useEditorState(
1037
+ const shape = chunkN25EH2GZ_cjs.useEditorState(
1053
1038
  controller,
1054
1039
  react.useCallback((state) => hoveredBlock === null ? null : shapeOf(state, hoveredBlock), [hoveredBlock])
1055
1040
  );
@@ -1088,16 +1073,16 @@ function useTableTarget(controller, held) {
1088
1073
  return pointed ?? (focus === "editor" ? caret : null);
1089
1074
  }
1090
1075
  var isFocusKey = (event) => event.key === "F10" && event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey;
1091
- var takesFocusKey = (state) => chunkFK7EBZPX_cjs.isCollapsed(state.selection) || cellSelection(state) !== null;
1076
+ var takesFocusKey = (state) => chunkZ5EEDCRI_cjs.isCollapsed(state.selection) || cellSelection(state) !== null;
1092
1077
  function TableControls({ controller, labels }) {
1093
- const readOnly = chunk2QKFRKOP_cjs.useReadOnly(controller);
1078
+ const readOnly = chunkN25EH2GZ_cjs.useReadOnly(controller);
1094
1079
  const [held, setHeld] = react.useState(null);
1095
1080
  const [focusFor, setFocusFor] = react.useState(null);
1096
1081
  const [slot, setSlot] = react.useState(null);
1097
1082
  const target = useTableTarget(controller, held?.target ?? null);
1098
- useCutCells(controller);
1083
+ useTableKeys(controller, !readOnly);
1099
1084
  const blockId = target?.block ?? null;
1100
- const block = chunk2QKFRKOP_cjs.useEditorState(
1085
+ const block = chunkN25EH2GZ_cjs.useEditorState(
1101
1086
  controller,
1102
1087
  react.useCallback((state) => blockId === null ? null : tableBlock(state.doc, blockId), [blockId])
1103
1088
  );
@@ -1114,13 +1099,13 @@ function TableControls({ controller, labels }) {
1114
1099
  const intercept = (event) => {
1115
1100
  const { state } = controller.editor;
1116
1101
  const caret = caretTarget(state);
1117
- if (!isFocusKey(event) || chunk2QKFRKOP_cjs.isComposingKey(controller, event) || caret === null || !takesFocusKey(state)) return false;
1102
+ if (!isFocusKey(event) || chunkN25EH2GZ_cjs.isComposingKey(controller, event) || caret === null || !takesFocusKey(state)) return false;
1118
1103
  event.preventDefault();
1119
1104
  setHeld({ target: caret, menu: null });
1120
1105
  setFocusFor(caret.block);
1121
1106
  return true;
1122
1107
  };
1123
- return chunkEBSDPHPS_cjs.interceptKeys(controller, intercept);
1108
+ return chunk4UFWFV43_cjs.interceptKeys(controller, intercept);
1124
1109
  }, [controller, readOnly]);
1125
1110
  const onMenu = react.useCallback(
1126
1111
  (menu) => setHeld(menu === null || target === null || block === null ? null : { target, menu, opened: block }),
@@ -1131,11 +1116,13 @@ function TableControls({ controller, labels }) {
1131
1116
  setFocusFor(null);
1132
1117
  setHeld((current) => current?.menu === null ? null : current);
1133
1118
  }, []);
1134
- chunk2QKFRKOP_cjs.useIsomorphicLayoutEffect(() => {
1135
- const drawn = block === null || readOnly ? null : controlsSlot(controller, block.id);
1136
- setSlot((current) => current === drawn ? current : drawn);
1119
+ chunkN25EH2GZ_cjs.useIsomorphicLayoutEffect(() => {
1120
+ const element = block === null || readOnly ? null : controlsSlot(controller, block.id);
1121
+ const drawn = element && block && { block: block.id, element };
1122
+ setSlot((current) => current?.element === drawn?.element && current?.block === drawn?.block ? current : drawn);
1137
1123
  });
1138
- if (target === null || block === null || readOnly || slot === null || !slot.isConnected) return null;
1124
+ const placed = slot !== null && slot.block === block?.id && slot.element.isConnected ? slot.element : null;
1125
+ if (target === null || block === null || readOnly || placed === null) return null;
1139
1126
  return reactDom.createPortal(
1140
1127
  /* @__PURE__ */ jsxRuntime.jsx(
1141
1128
  PlacedHandles,
@@ -1144,7 +1131,7 @@ function TableControls({ controller, labels }) {
1144
1131
  labels,
1145
1132
  block,
1146
1133
  target,
1147
- slot,
1134
+ slot: placed,
1148
1135
  menu: held?.menu ?? null,
1149
1136
  onMenu,
1150
1137
  onHold,
@@ -1153,7 +1140,7 @@ function TableControls({ controller, labels }) {
1153
1140
  },
1154
1141
  block.id
1155
1142
  ),
1156
- slot
1143
+ placed
1157
1144
  );
1158
1145
  }
1159
1146
  function PlacedHandles({ slot, ...props }) {
@@ -1161,6 +1148,78 @@ function PlacedHandles({ slot, ...props }) {
1161
1148
  return geometry === null ? null : /* @__PURE__ */ jsxRuntime.jsx(TableHandles, { ...props, geometry });
1162
1149
  }
1163
1150
 
1151
+ // src/engine/commands/paste-cells.ts
1152
+ var unmoved = (cell) => cell;
1153
+ function grown(block, rows, cols) {
1154
+ const shape = tableShape(block);
1155
+ if (rows <= shape.rows && cols <= shape.cols) return null;
1156
+ const added = Math.max(cols - shape.cols, 0);
1157
+ const widths = storedWidths(block, shape.cols);
1158
+ return rebuiltTable(block, {
1159
+ rows: Math.max(rows, shape.rows),
1160
+ cols: shape.cols + added,
1161
+ source: (row, col) => row < shape.rows && col < shape.cols ? [row, col] : null,
1162
+ target: unmoved,
1163
+ landing: unmoved,
1164
+ attrs: {
1165
+ align: [...columnAligns(block, shape.cols), ...Array(added).fill(null)],
1166
+ ...widths && { widths: [...widths, ...Array(added).fill(widths[shape.cols - 1])] }
1167
+ }
1168
+ });
1169
+ }
1170
+ function pasteCells(source) {
1171
+ return (state, dispatch) => {
1172
+ const { doc, schema, selection } = state;
1173
+ const { rows, cols } = tableShape(source);
1174
+ if (selection?.kind !== "text" || rows === 0 || cols === 0) return false;
1175
+ const { anchor, head } = selection;
1176
+ const inCells = anchor.block === head.block && chunkZ5EEDCRI_cjs.cellOf(anchor.region) !== null && chunkZ5EEDCRI_cjs.cellOf(head.region) !== null;
1177
+ if (!inCells || tableBlock(doc, head.block) === null) return false;
1178
+ const tr = new chunkZ5EEDCRI_cjs.Transaction(state).setOrigin("paste");
1179
+ const { from, to } = chunkZ5EEDCRI_cjs.orderedRange(doc, anchor, head);
1180
+ const [top, left] = chunkZ5EEDCRI_cjs.cellOf(chunkZ5EEDCRI_cjs.deleteRange(tr, schema, from, to).region);
1181
+ const larger = grown(tableBlock(tr.doc, head.block), top + rows, left + cols);
1182
+ if (larger !== null) tr.step(chunkZ5EEDCRI_cjs.replaceBlockStep(larger));
1183
+ const block = tableBlock(tr.doc, head.block);
1184
+ let caret = head;
1185
+ for (const [row, col] of chunkZ5EEDCRI_cjs.cellsBetween([0, 0], [rows - 1, cols - 1])) {
1186
+ const region = chunk4JDRDPLC_cjs.cellKey(top + row, left + col);
1187
+ const content = source.regions[chunk4JDRDPLC_cjs.cellKey(row, col)] ?? [];
1188
+ const length = chunkZ5EEDCRI_cjs.regionLength(block, region);
1189
+ if (length > 0 || content.length > 0) tr.step(chunkZ5EEDCRI_cjs.replaceInlineStep(block.id, region, 0, length, content));
1190
+ caret = { block: block.id, region, offset: chunk4JDRDPLC_cjs.inlineLength(content) };
1191
+ }
1192
+ dispatch?.(tr.setSelection(chunkZ5EEDCRI_cjs.textSelection(caret)));
1193
+ return true;
1194
+ };
1195
+ }
1196
+
1197
+ // src/extensions/table/paste-over-cells.ts
1198
+ function richBlocks(state, pasted) {
1199
+ const slice = pasted?.json || pasted?.html ? chunkZ5EEDCRI_cjs.sliceFromClipboard({ json: pasted.json, html: pasted.html }) : null;
1200
+ if (slice === null) return null;
1201
+ const codec = chunk4JDRDPLC_cjs.createBlockCodec(state.schema);
1202
+ const blocks = slice.blocks.flatMap((block) => codec.toEngineBlocks(block));
1203
+ return { blocks, open: slice.openStart && slice.openEnd };
1204
+ }
1205
+ function lineOf(state, rich) {
1206
+ const [only] = rich?.blocks ?? [];
1207
+ if (!rich?.open || rich.blocks.length !== 1 || !chunkZ5EEDCRI_cjs.isTextFlow(state.schema, only)) return void 0;
1208
+ return only.regions[chunkZ5EEDCRI_cjs.primaryRegion(state.schema, only) ?? ""];
1209
+ }
1210
+ var pasteOverCells = {
1211
+ name: "table-cells",
1212
+ match(text, state, pasted) {
1213
+ const { doc, selection } = state;
1214
+ if (selection?.kind !== "text" || tableBlock(doc, selection.head.block) === null) return null;
1215
+ const rich = richBlocks(state, pasted);
1216
+ const [only] = rich?.blocks.length === 1 ? rich.blocks : [];
1217
+ if (only?.type === "TABLE") return pasteCells(only);
1218
+ if (cellSelection(state) === null) return null;
1219
+ return typeOverCells(lineOf(state, rich) ?? text.replace(/\r\n?/g, "\n"));
1220
+ }
1221
+ };
1222
+
1164
1223
  // src/extensions/table/table-labels.ts
1165
1224
  var englishTableLabels = {
1166
1225
  table: "Table",
@@ -1209,15 +1268,11 @@ var tableSlashItem = (labels) => ({
1209
1268
  title: labels.table,
1210
1269
  description: labels.tableDescription,
1211
1270
  group: "advanced",
1212
- icon: chunkEBSDPHPS_cjs.Table,
1271
+ icon: chunk4UFWFV43_cjs.Table,
1213
1272
  keywords: ["grid", "rows", "columns", "spreadsheet", "|"],
1214
1273
  command: () => insertTable(NEW_TABLE.rows, NEW_TABLE.cols)
1215
1274
  });
1216
1275
  var ABOVE_CORE_KEYS = 200;
1217
- var pasteOverCells = {
1218
- name: "table-cells",
1219
- match: (text, state) => cellSelection(state) === null ? null : typeOverCells(text.replace(/\r\n?/g, "\n"))
1220
- };
1221
1276
  function tableExtension(options = {}) {
1222
1277
  const labels = resolveTableLabels(options.labels);
1223
1278
  const TableRenderer = (props) => /* @__PURE__ */ jsxRuntime.jsx(TableBlock, { ...props, labels });
@@ -1228,7 +1283,7 @@ function tableExtension(options = {}) {
1228
1283
  blockNames: { TABLE: labels.table },
1229
1284
  overlays: [TableOverlay]
1230
1285
  };
1231
- return chunkFK7EBZPX_cjs.defineExtension({
1286
+ return chunkZ5EEDCRI_cjs.defineExtension({
1232
1287
  name: "table",
1233
1288
  priority: ABOVE_CORE_KEYS,
1234
1289
  plugins: [cellSelectionPlugin],