@milkdown/crepe 7.5.0 → 7.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/lib/cjs/{index--tnUmqZ_.js → index--2zEz40J.js} +8 -23
  2. package/lib/cjs/{index--tnUmqZ_.js.map → index--2zEz40J.js.map} +1 -1
  3. package/lib/cjs/{index-92bwto5V.js → index-5n9R-QCl.js} +5 -20
  4. package/lib/cjs/{index-92bwto5V.js.map → index-5n9R-QCl.js.map} +1 -1
  5. package/lib/cjs/{index-HH5lPgpj.js → index-HEdBw63r.js} +8 -23
  6. package/lib/cjs/{index-HH5lPgpj.js.map → index-HEdBw63r.js.map} +1 -1
  7. package/lib/cjs/{index-J1-yHn7v.js → index-Hlt9dRH5.js} +5 -20
  8. package/lib/cjs/{index-J1-yHn7v.js.map → index-Hlt9dRH5.js.map} +1 -1
  9. package/lib/cjs/{index-cb-5m0vG.js → index-KCW2CzRk.js} +8 -23
  10. package/lib/cjs/index-KCW2CzRk.js.map +1 -0
  11. package/lib/cjs/{index-VYwHTL3F.js → index-KSZhahYb.js} +6 -21
  12. package/lib/cjs/{index-VYwHTL3F.js.map → index-KSZhahYb.js.map} +1 -1
  13. package/lib/cjs/index-N1cRxqdw.js +39 -0
  14. package/lib/cjs/index-N1cRxqdw.js.map +1 -0
  15. package/lib/cjs/{index-c_OzudR7.js → index-NNo_VSEA.js} +5 -20
  16. package/lib/{esm/index-DS7Z4Ach.js.map → cjs/index-NNo_VSEA.js.map} +1 -1
  17. package/lib/cjs/{index-Tjg8KyK7.js → index-O1bDbloo.js} +5 -20
  18. package/lib/{esm/index-eqd5wtjX.js.map → cjs/index-O1bDbloo.js.map} +1 -1
  19. package/lib/cjs/{index-55VIM-52.js → index-OPh9naof.js} +8 -23
  20. package/lib/cjs/{index-55VIM-52.js.map → index-OPh9naof.js.map} +1 -1
  21. package/lib/cjs/{index-E4Ist86Z.js → index-PAhfZtcH.js} +5 -20
  22. package/lib/cjs/{index-E4Ist86Z.js.map → index-PAhfZtcH.js.map} +1 -1
  23. package/lib/cjs/{index-vfzLCXfi.js → index-PeRHVz4A.js} +5 -20
  24. package/lib/{esm/index-3bDzhU6z.js.map → cjs/index-PeRHVz4A.js.map} +1 -1
  25. package/lib/cjs/{index-Jztk6JlP.js → index-U7GWrg-w.js} +9 -456
  26. package/lib/cjs/index-U7GWrg-w.js.map +1 -0
  27. package/lib/cjs/{index-zXSAHvAj.js → index-UTb0Az5e.js} +2 -2
  28. package/lib/cjs/{index-zXSAHvAj.js.map → index-UTb0Az5e.js.map} +1 -1
  29. package/lib/cjs/{index-lBumFRUQ.js → index-UnEAyH8X.js} +5 -20
  30. package/lib/cjs/{index-lBumFRUQ.js.map → index-UnEAyH8X.js.map} +1 -1
  31. package/lib/cjs/{index-1vHyMXH8.js → index-VCkq0ru1.js} +5 -20
  32. package/lib/{esm/index-g_3dzLYU.js.map → cjs/index-VCkq0ru1.js.map} +1 -1
  33. package/lib/cjs/{index-FbNqlZU8.js → index-WQl7Du53.js} +4 -19
  34. package/lib/cjs/index-WQl7Du53.js.map +1 -0
  35. package/lib/cjs/{index-nTfDKYYi.js → index-ahL5MvrQ.js} +28 -43
  36. package/lib/cjs/{index-nTfDKYYi.js.map → index-ahL5MvrQ.js.map} +1 -1
  37. package/lib/cjs/{index--sa4NMpW.js → index-bpgWLeRY.js} +5 -20
  38. package/lib/cjs/{index--sa4NMpW.js.map → index-bpgWLeRY.js.map} +1 -1
  39. package/lib/cjs/index-dEVmN_aj.js +26 -0
  40. package/lib/cjs/index-dEVmN_aj.js.map +1 -0
  41. package/lib/cjs/{index-von4W2LG.js → index-fZupvR_f.js} +8 -23
  42. package/lib/{esm/index-NZ5-xr5_.js.map → cjs/index-fZupvR_f.js.map} +1 -1
  43. package/lib/cjs/{index-mcxgNBq9.js → index-gSM-jgti.js} +5 -20
  44. package/lib/cjs/{index-mcxgNBq9.js.map → index-gSM-jgti.js.map} +1 -1
  45. package/lib/cjs/{index-lUNj3xuC.js → index-jlPr_A_N.js} +5 -20
  46. package/lib/cjs/{index-lUNj3xuC.js.map → index-jlPr_A_N.js.map} +1 -1
  47. package/lib/cjs/index-ocxd4A-M.js +675 -0
  48. package/lib/cjs/index-ocxd4A-M.js.map +1 -0
  49. package/lib/cjs/{index-J3XY9IPt.js → index-rFFAL9YA.js} +9 -17
  50. package/lib/cjs/{index-J3XY9IPt.js.map → index-rFFAL9YA.js.map} +1 -1
  51. package/lib/cjs/index-tlx25I_m.js +36 -0
  52. package/lib/cjs/index-tlx25I_m.js.map +1 -0
  53. package/lib/cjs/index-tqAbVyds.js +28 -0
  54. package/lib/cjs/index-tqAbVyds.js.map +1 -0
  55. package/lib/cjs/{index-cpC-j5Nt.js → index-udZSknd8.js} +30 -39
  56. package/lib/cjs/{index-cpC-j5Nt.js.map → index-udZSknd8.js.map} +1 -1
  57. package/lib/cjs/index-uleaJDBC.js +19 -0
  58. package/lib/cjs/index-uleaJDBC.js.map +1 -0
  59. package/lib/cjs/{index-jn036wuh.js → index-urB-WDqA.js} +7 -22
  60. package/lib/{esm/index-VoX_n1l_.js.map → cjs/index-urB-WDqA.js.map} +1 -1
  61. package/lib/cjs/{index-jlfsu92T.js → index-xWgWtxUR.js} +6 -21
  62. package/lib/cjs/{index-jlfsu92T.js.map → index-xWgWtxUR.js.map} +1 -1
  63. package/lib/cjs/index.js +150 -14
  64. package/lib/cjs/index.js.map +1 -1
  65. package/lib/cjs/{todoList-Ze4FLMlx.js → todoList-YYRQo7wG.js} +1 -12
  66. package/lib/cjs/todoList-YYRQo7wG.js.map +1 -0
  67. package/lib/esm/{index-Yuj7sNhQ.js → index-1NetiFdJ.js} +8 -23
  68. package/lib/esm/{index-Yuj7sNhQ.js.map → index-1NetiFdJ.js.map} +1 -1
  69. package/lib/esm/{index-6GrVnloh.js → index-2I_xbjAZ.js} +28 -43
  70. package/lib/esm/{index-6GrVnloh.js.map → index-2I_xbjAZ.js.map} +1 -1
  71. package/lib/esm/{index-bexsWrgs.js → index-2huXYfuJ.js} +8 -23
  72. package/lib/esm/{index-bexsWrgs.js.map → index-2huXYfuJ.js.map} +1 -1
  73. package/lib/esm/{index-zrQXXSXm.js → index-4x6_TVZv.js} +5 -20
  74. package/lib/esm/{index-zrQXXSXm.js.map → index-4x6_TVZv.js.map} +1 -1
  75. package/lib/esm/index-6JoGWH2I.js +17 -0
  76. package/lib/esm/index-6JoGWH2I.js.map +1 -0
  77. package/lib/esm/{index-OpUb5xP6.js → index-A-dNwMMf.js} +2 -2
  78. package/lib/esm/{index-OpUb5xP6.js.map → index-A-dNwMMf.js.map} +1 -1
  79. package/lib/esm/{index-SDPCpsD5.js → index-AV99ipmP.js} +5 -20
  80. package/lib/esm/{index-SDPCpsD5.js.map → index-AV99ipmP.js.map} +1 -1
  81. package/lib/esm/{index-MB6wQe1U.js → index-CMGDOz11.js} +5 -13
  82. package/lib/esm/{index-MB6wQe1U.js.map → index-CMGDOz11.js.map} +1 -1
  83. package/lib/esm/index-HlPKwzLC.js +34 -0
  84. package/lib/esm/index-HlPKwzLC.js.map +1 -0
  85. package/lib/esm/{index-MxgqkRtj.js → index-PC2bahtq.js} +5 -20
  86. package/lib/esm/{index-MxgqkRtj.js.map → index-PC2bahtq.js.map} +1 -1
  87. package/lib/esm/{index-eqd5wtjX.js → index-QBYz82jZ.js} +5 -20
  88. package/lib/{cjs/index-Tjg8KyK7.js.map → esm/index-QBYz82jZ.js.map} +1 -1
  89. package/lib/esm/{index-VP76m4nW.js → index-W1pAMr_8.js} +6 -21
  90. package/lib/esm/{index-VP76m4nW.js.map → index-W1pAMr_8.js.map} +1 -1
  91. package/lib/esm/{index-i79QMXpJ.js → index-Xzdc2jbA.js} +7 -454
  92. package/lib/esm/index-Xzdc2jbA.js.map +1 -0
  93. package/lib/esm/{index-_4fWmRbN.js → index-ZAtZWqJQ.js} +5 -20
  94. package/lib/esm/{index-_4fWmRbN.js.map → index-ZAtZWqJQ.js.map} +1 -1
  95. package/lib/esm/index-_A9vu1ED.js +673 -0
  96. package/lib/esm/index-_A9vu1ED.js.map +1 -0
  97. package/lib/esm/{index-x8SyiPMC.js → index-bnSKBrbD.js} +5 -20
  98. package/lib/esm/{index-x8SyiPMC.js.map → index-bnSKBrbD.js.map} +1 -1
  99. package/lib/esm/index-fVrfHXda.js +24 -0
  100. package/lib/esm/index-fVrfHXda.js.map +1 -0
  101. package/lib/esm/{index-Vl0W0S3h.js → index-ftnOhuRS.js} +4 -19
  102. package/lib/esm/index-ftnOhuRS.js.map +1 -0
  103. package/lib/esm/{index-1l-61HI-.js → index-iQPB0Rdl.js} +6 -21
  104. package/lib/esm/{index-1l-61HI-.js.map → index-iQPB0Rdl.js.map} +1 -1
  105. package/lib/esm/{index-grT-Kuf2.js → index-kPj3-TKp.js} +5 -20
  106. package/lib/esm/{index-grT-Kuf2.js.map → index-kPj3-TKp.js.map} +1 -1
  107. package/lib/esm/{index-NZ5-xr5_.js → index-kgOR7SZ6.js} +8 -23
  108. package/lib/{cjs/index-von4W2LG.js.map → esm/index-kgOR7SZ6.js.map} +1 -1
  109. package/lib/esm/{index-A83StUe6.js → index-lm00PM0y.js} +8 -17
  110. package/lib/esm/{index-A83StUe6.js.map → index-lm00PM0y.js.map} +1 -1
  111. package/lib/esm/{index-g_3dzLYU.js → index-m49Bj3q7.js} +5 -20
  112. package/lib/{cjs/index-1vHyMXH8.js.map → esm/index-m49Bj3q7.js.map} +1 -1
  113. package/lib/esm/index-ohmbt6Ys.js +37 -0
  114. package/lib/esm/index-ohmbt6Ys.js.map +1 -0
  115. package/lib/esm/{index-rvOBAXap.js → index-sWVjGw-3.js} +8 -23
  116. package/lib/esm/index-sWVjGw-3.js.map +1 -0
  117. package/lib/esm/{index-DS7Z4Ach.js → index-twh8lL5o.js} +5 -20
  118. package/lib/{cjs/index-c_OzudR7.js.map → esm/index-twh8lL5o.js.map} +1 -1
  119. package/lib/esm/{index-3bDzhU6z.js → index-v02MCz4_.js} +5 -20
  120. package/lib/{cjs/index-vfzLCXfi.js.map → esm/index-v02MCz4_.js.map} +1 -1
  121. package/lib/esm/index-v3rvbocl.js +26 -0
  122. package/lib/esm/index-v3rvbocl.js.map +1 -0
  123. package/lib/esm/{index-XH7OnwZl.js → index-wEXT8mbN.js} +5 -20
  124. package/lib/esm/{index-XH7OnwZl.js.map → index-wEXT8mbN.js.map} +1 -1
  125. package/lib/esm/{index-VoX_n1l_.js → index-wFIac5Kw.js} +7 -22
  126. package/lib/{cjs/index-jn036wuh.js.map → esm/index-wFIac5Kw.js.map} +1 -1
  127. package/lib/esm/{index-3HeWs5rX.js → index-wg94ewRo.js} +8 -23
  128. package/lib/esm/{index-3HeWs5rX.js.map → index-wg94ewRo.js.map} +1 -1
  129. package/lib/esm/index.js +152 -12
  130. package/lib/esm/index.js.map +1 -1
  131. package/lib/esm/{todoList-M-PGJKde.js → todoList-9QsDDcmB.js} +2 -12
  132. package/lib/esm/todoList-9QsDDcmB.js.map +1 -0
  133. package/package.json +1 -1
  134. package/lib/cjs/_view-N32ied53.js +0 -27
  135. package/lib/cjs/_view-N32ied53.js.map +0 -1
  136. package/lib/cjs/floating-ui.dom-2cjBpir5.js +0 -1134
  137. package/lib/cjs/floating-ui.dom-2cjBpir5.js.map +0 -1
  138. package/lib/cjs/helper-1aludV1Z.js +0 -15
  139. package/lib/cjs/helper-1aludV1Z.js.map +0 -1
  140. package/lib/cjs/index-28q261C7.js +0 -448
  141. package/lib/cjs/index-28q261C7.js.map +0 -1
  142. package/lib/cjs/index-Buu2tD9O.js +0 -534
  143. package/lib/cjs/index-Buu2tD9O.js.map +0 -1
  144. package/lib/cjs/index-FbNqlZU8.js.map +0 -1
  145. package/lib/cjs/index-Jztk6JlP.js.map +0 -1
  146. package/lib/cjs/index-N6pPZY61.js +0 -191
  147. package/lib/cjs/index-N6pPZY61.js.map +0 -1
  148. package/lib/cjs/index-TUJs6KKL.js +0 -472
  149. package/lib/cjs/index-TUJs6KKL.js.map +0 -1
  150. package/lib/cjs/index-_GOdKqUK.js +0 -1147
  151. package/lib/cjs/index-_GOdKqUK.js.map +0 -1
  152. package/lib/cjs/index-cKQcw-eu.js +0 -386
  153. package/lib/cjs/index-cKQcw-eu.js.map +0 -1
  154. package/lib/cjs/index-cb-5m0vG.js.map +0 -1
  155. package/lib/cjs/index-crv_k6dv.js +0 -1353
  156. package/lib/cjs/index-crv_k6dv.js.map +0 -1
  157. package/lib/cjs/index-kqz-P6o6.js +0 -55
  158. package/lib/cjs/index-kqz-P6o6.js.map +0 -1
  159. package/lib/cjs/index-tBw4NmwY.js +0 -33852
  160. package/lib/cjs/index-tBw4NmwY.js.map +0 -1
  161. package/lib/cjs/schema-RVrwDDcq.js +0 -74
  162. package/lib/cjs/schema-RVrwDDcq.js.map +0 -1
  163. package/lib/cjs/todoList-Ze4FLMlx.js.map +0 -1
  164. package/lib/cjs/tooltip-plugin--lhebztC.js +0 -191
  165. package/lib/cjs/tooltip-plugin--lhebztC.js.map +0 -1
  166. package/lib/esm/_view-IlZC8FA6.js +0 -25
  167. package/lib/esm/_view-IlZC8FA6.js.map +0 -1
  168. package/lib/esm/floating-ui.dom-CAYjY8Gv.js +0 -1130
  169. package/lib/esm/floating-ui.dom-CAYjY8Gv.js.map +0 -1
  170. package/lib/esm/helper-wZAtC67x.js +0 -13
  171. package/lib/esm/helper-wZAtC67x.js.map +0 -1
  172. package/lib/esm/index-0-j8Icms.js +0 -384
  173. package/lib/esm/index-0-j8Icms.js.map +0 -1
  174. package/lib/esm/index-8QJbxTYk.js +0 -1145
  175. package/lib/esm/index-8QJbxTYk.js.map +0 -1
  176. package/lib/esm/index-9w_hdnvb.js +0 -532
  177. package/lib/esm/index-9w_hdnvb.js.map +0 -1
  178. package/lib/esm/index-AOoFzBaK.js +0 -53
  179. package/lib/esm/index-AOoFzBaK.js.map +0 -1
  180. package/lib/esm/index-LAdX6LsO.js +0 -33805
  181. package/lib/esm/index-LAdX6LsO.js.map +0 -1
  182. package/lib/esm/index-Vl0W0S3h.js.map +0 -1
  183. package/lib/esm/index-chrnjY1D.js +0 -470
  184. package/lib/esm/index-chrnjY1D.js.map +0 -1
  185. package/lib/esm/index-hF04phbf.js +0 -189
  186. package/lib/esm/index-hF04phbf.js.map +0 -1
  187. package/lib/esm/index-i79QMXpJ.js.map +0 -1
  188. package/lib/esm/index-rvOBAXap.js.map +0 -1
  189. package/lib/esm/index-uP9BKsTM.js +0 -446
  190. package/lib/esm/index-uP9BKsTM.js.map +0 -1
  191. package/lib/esm/index-ueQQMSgm.js +0 -1351
  192. package/lib/esm/index-ueQQMSgm.js.map +0 -1
  193. package/lib/esm/schema-JWJqD9qa.js +0 -71
  194. package/lib/esm/schema-JWJqD9qa.js.map +0 -1
  195. package/lib/esm/todoList-M-PGJKde.js.map +0 -1
  196. package/lib/esm/tooltip-plugin-iw2EQWIG.js +0 -185
  197. package/lib/esm/tooltip-plugin-iw2EQWIG.js.map +0 -1
@@ -1,1145 +0,0 @@
1
- import { w as withMeta, G as dragHandleIcon, H as alignRightIcon, I as alignCenterIcon, J as alignLeftIcon, r as removeIcon, B as plusIcon } from './todoList-M-PGJKde.js';
2
- import { $ as $ctx, e as editorViewCtx, C as findTable, u as commandsCtx, D as selectColCommand, E as moveColCommand, F as selectRowCommand, G as moveRowCommand, H as addRowAfterCommand, I as addRowBeforeCommand, J as addColAfterCommand, K as addColBeforeCommand, L as deleteSelectedCellsCommand, M as setAlignCommand, N as tableSchema } from './index-LAdX6LsO.js';
3
- import { NodeSelection } from '@milkdown/prose/state';
4
- import { findParent } from '@milkdown/prose';
5
- import { CellSelection } from '@milkdown/prose/tables';
6
- import { d as defIfNotExists } from './helper-wZAtC67x.js';
7
- import { useHost, useMemo, useEffect, useCallback, c, useRef, useLayoutEffect, html } from 'atomico';
8
- import { c as clsx } from './clsx-RxCLxYpD.js';
9
- import { t as throttle } from './index-uP9BKsTM.js';
10
- import { c as computePosition, o as offset } from './floating-ui.dom-CAYjY8Gv.js';
11
- import { $ as $view } from './_view-IlZC8FA6.js';
12
- import '@milkdown/prose/model';
13
- import '@milkdown/prose/commands';
14
- import '@milkdown/prose/inputrules';
15
- import '@milkdown/prose/keymap';
16
- import '@milkdown/prose/view';
17
- import '@milkdown/prose/schema-list';
18
- import '@milkdown/prose/transform';
19
- import '@milkdown/prose/history';
20
-
21
- const defaultTableBlockConfig = {
22
- renderButton: (renderType) => {
23
- switch (renderType) {
24
- case "add_row":
25
- return "+";
26
- case "add_col":
27
- return "+";
28
- case "delete_row":
29
- return "-";
30
- case "delete_col":
31
- return "-";
32
- case "align_col_left":
33
- return "left";
34
- case "align_col_center":
35
- return "center";
36
- case "align_col_right":
37
- return "right";
38
- case "col_drag_handle":
39
- return "=";
40
- case "row_drag_handle":
41
- return "=";
42
- }
43
- }
44
- };
45
- const tableBlockConfig = $ctx({ ...defaultTableBlockConfig }, "tableBlockConfigCtx");
46
- withMeta(tableBlockConfig, {
47
- displayName: "Config<table-block>",
48
- group: "TableBlock"
49
- });
50
-
51
- function findNodeIndex(parent, child) {
52
- for (let i = 0; i < parent.childCount; i++) {
53
- if (parent.child(i) === child)
54
- return i;
55
- }
56
- return -1;
57
- }
58
- function findPointerIndex(event, view) {
59
- var _a, _b, _c;
60
- if (!view)
61
- return;
62
- const posAtCoords = view.posAtCoords({ left: event.clientX, top: event.clientY });
63
- if (!posAtCoords)
64
- return;
65
- const pos = posAtCoords == null ? void 0 : posAtCoords.inside;
66
- if (pos == null || pos < 0)
67
- return;
68
- const $pos = view.state.doc.resolve(pos);
69
- const node = view.state.doc.nodeAt(pos);
70
- if (!node)
71
- return;
72
- const cellType = ["table_cell", "table_header"];
73
- const rowType = ["table_row", "table_header_row"];
74
- const cell = cellType.includes(node.type.name) ? node : (_a = findParent((node2) => cellType.includes(node2.type.name))($pos)) == null ? void 0 : _a.node;
75
- const row = (_b = findParent((node2) => rowType.includes(node2.type.name))($pos)) == null ? void 0 : _b.node;
76
- const table = (_c = findParent((node2) => node2.type.name === "table")($pos)) == null ? void 0 : _c.node;
77
- if (!cell || !row || !table)
78
- return;
79
- const columnIndex = findNodeIndex(row, cell);
80
- const rowIndex = findNodeIndex(table, row);
81
- return [rowIndex, columnIndex];
82
- }
83
- function getRelatedDOM(contentWrapperRef, [rowIndex, columnIndex]) {
84
- const content = contentWrapperRef.current;
85
- if (!content)
86
- return;
87
- const rows = content.querySelectorAll("tr");
88
- const row = rows[rowIndex];
89
- if (!row)
90
- return;
91
- const firstRow = rows[0];
92
- if (!firstRow)
93
- return;
94
- const headerCol = firstRow.children[columnIndex];
95
- if (!headerCol)
96
- return;
97
- const col = row.children[columnIndex];
98
- if (!col)
99
- return;
100
- return {
101
- row,
102
- col,
103
- headerCol
104
- };
105
- }
106
- function recoveryStateBetweenUpdate(refs, ctx, node) {
107
- if (!ctx)
108
- return;
109
- if (!node)
110
- return;
111
- const { selection } = ctx.get(editorViewCtx).state;
112
- if (!(selection instanceof CellSelection))
113
- return;
114
- const { $from } = selection;
115
- const table = findTable($from);
116
- if (!table || table.node !== node)
117
- return;
118
- if (selection.isColSelection()) {
119
- const { $head } = selection;
120
- const colIndex = $head.index($head.depth - 1);
121
- computeColHandlePositionByIndex({
122
- refs,
123
- index: [0, colIndex],
124
- before: (handleDOM) => {
125
- var _a;
126
- (_a = handleDOM.querySelector(".button-group")) == null ? void 0 : _a.setAttribute("data-show", "true");
127
- }
128
- });
129
- return;
130
- }
131
- if (selection.isRowSelection()) {
132
- const { $head } = selection;
133
- const rowNode = findParent((node2) => node2.type.name === "table_row" || node2.type.name === "table_header_row")($head);
134
- if (!rowNode)
135
- return;
136
- const rowIndex = findNodeIndex(table.node, rowNode.node);
137
- computeRowHandlePositionByIndex({
138
- refs,
139
- index: [rowIndex, 0],
140
- before: (handleDOM) => {
141
- var _a;
142
- if (rowIndex > 0)
143
- (_a = handleDOM.querySelector(".button-group")) == null ? void 0 : _a.setAttribute("data-show", "true");
144
- }
145
- });
146
- }
147
- }
148
- function computeColHandlePositionByIndex({
149
- refs,
150
- index,
151
- before,
152
- after
153
- }) {
154
- const {
155
- contentWrapperRef,
156
- colHandleRef,
157
- hoverIndex
158
- } = refs;
159
- const colHandle = colHandleRef.current;
160
- if (!colHandle)
161
- return;
162
- hoverIndex.current = index;
163
- const dom = getRelatedDOM(contentWrapperRef, index);
164
- if (!dom)
165
- return;
166
- const { headerCol: col } = dom;
167
- colHandle.dataset.show = "true";
168
- if (before)
169
- before(colHandle);
170
- computePosition(col, colHandle, { placement: "top" }).then(({ x, y }) => {
171
- Object.assign(colHandle.style, {
172
- left: `${x}px`,
173
- top: `${y}px`
174
- });
175
- if (after)
176
- after(colHandle);
177
- });
178
- }
179
- function computeRowHandlePositionByIndex({
180
- refs,
181
- index,
182
- before,
183
- after
184
- }) {
185
- const {
186
- contentWrapperRef,
187
- rowHandleRef,
188
- hoverIndex
189
- } = refs;
190
- const rowHandle = rowHandleRef.current;
191
- if (!rowHandle)
192
- return;
193
- hoverIndex.current = index;
194
- const dom = getRelatedDOM(contentWrapperRef, index);
195
- if (!dom)
196
- return;
197
- const { row } = dom;
198
- rowHandle.dataset.show = "true";
199
- if (before)
200
- before(rowHandle);
201
- computePosition(row, rowHandle, { placement: "left" }).then(({ x, y }) => {
202
- Object.assign(rowHandle.style, {
203
- left: `${x}px`,
204
- top: `${y}px`
205
- });
206
- if (after)
207
- after(rowHandle);
208
- });
209
- }
210
-
211
- function prepareDndContext(refs) {
212
- const {
213
- dragPreviewRef,
214
- tableWrapperRef,
215
- contentWrapperRef,
216
- yLineHandleRef,
217
- xLineHandleRef,
218
- colHandleRef,
219
- rowHandleRef
220
- } = refs;
221
- const preview = dragPreviewRef.current;
222
- if (!preview)
223
- return;
224
- const wrapper = tableWrapperRef.current;
225
- if (!wrapper)
226
- return;
227
- const content = contentWrapperRef.current;
228
- if (!content)
229
- return;
230
- const contentRoot = content.querySelector("tbody");
231
- if (!contentRoot)
232
- return;
233
- const previewRoot = preview.querySelector("tbody");
234
- if (!previewRoot)
235
- return;
236
- const yHandle = yLineHandleRef.current;
237
- if (!yHandle)
238
- return;
239
- const xHandle = xLineHandleRef.current;
240
- if (!xHandle)
241
- return;
242
- const colHandle = colHandleRef.current;
243
- if (!colHandle)
244
- return;
245
- const rowHandle = rowHandleRef.current;
246
- if (!rowHandle)
247
- return;
248
- const context = {
249
- preview,
250
- wrapper,
251
- content,
252
- contentRoot,
253
- previewRoot,
254
- yHandle,
255
- xHandle,
256
- colHandle,
257
- rowHandle
258
- };
259
- return context;
260
- }
261
- function handleDrag(refs, event, ctx, fn) {
262
- const view = ctx == null ? void 0 : ctx.get(editorViewCtx);
263
- if (!(view == null ? void 0 : view.editable))
264
- return;
265
- event.stopPropagation();
266
- if (event.dataTransfer)
267
- event.dataTransfer.effectAllowed = "move";
268
- const context = prepareDndContext(refs);
269
- if (!context)
270
- return;
271
- requestAnimationFrame(() => {
272
- fn(context);
273
- });
274
- }
275
- function createDragRowHandler(refs, ctx) {
276
- return (event) => {
277
- handleDrag(refs, event, ctx, ({
278
- preview,
279
- content,
280
- previewRoot,
281
- yHandle,
282
- xHandle,
283
- colHandle,
284
- rowHandle
285
- }) => {
286
- var _a;
287
- const { hoverIndex, dragInfo } = refs;
288
- xHandle.dataset.displayType = "indicator";
289
- yHandle.dataset.show = "false";
290
- colHandle.dataset.show = "false";
291
- (_a = rowHandle.querySelector(".button-group")) == null ? void 0 : _a.setAttribute("data-show", "false");
292
- const [rowIndex] = hoverIndex.current;
293
- dragInfo.current = {
294
- startCoords: [event.clientX, event.clientY],
295
- startIndex: rowIndex,
296
- endIndex: rowIndex,
297
- type: "row"
298
- };
299
- preview.dataset.direction = "vertical";
300
- const rows = content.querySelectorAll("tr");
301
- while (previewRoot.firstChild)
302
- previewRoot.removeChild(previewRoot.firstChild);
303
- const row = rows[rowIndex];
304
- if (!row)
305
- return;
306
- previewRoot.appendChild(row.cloneNode(true));
307
- const height = row.getBoundingClientRect().height;
308
- const { width } = content.querySelector("tbody").getBoundingClientRect();
309
- Object.assign(preview.style, {
310
- width: `${width}px`,
311
- height: `${height}px`
312
- });
313
- preview.dataset.show = "true";
314
- });
315
- };
316
- }
317
- function createDragColHandler(refs, ctx) {
318
- return (event) => {
319
- handleDrag(refs, event, ctx, ({
320
- preview,
321
- content,
322
- previewRoot,
323
- yHandle,
324
- xHandle,
325
- colHandle,
326
- rowHandle
327
- }) => {
328
- var _a;
329
- const { hoverIndex, dragInfo } = refs;
330
- xHandle.dataset.show = "false";
331
- yHandle.dataset.displayType = "indicator";
332
- rowHandle.dataset.show = "false";
333
- (_a = colHandle.querySelector(".button-group")) == null ? void 0 : _a.setAttribute("data-show", "false");
334
- const [_, colIndex] = hoverIndex.current;
335
- dragInfo.current = {
336
- startCoords: [event.clientX, event.clientY],
337
- startIndex: colIndex,
338
- endIndex: colIndex,
339
- type: "col"
340
- };
341
- preview.dataset.direction = "horizontal";
342
- const rows = content.querySelectorAll("tr");
343
- while (previewRoot.firstChild)
344
- previewRoot.removeChild(previewRoot.firstChild);
345
- let width;
346
- Array.from(rows).forEach((row) => {
347
- const col = row.children[colIndex];
348
- if (!col)
349
- return;
350
- if (width === void 0)
351
- width = col.getBoundingClientRect().width;
352
- const tr = col.parentElement.cloneNode(false);
353
- const clone = col.cloneNode(true);
354
- tr.appendChild(clone);
355
- previewRoot.appendChild(tr);
356
- });
357
- const { height } = content.querySelector("tbody").getBoundingClientRect();
358
- Object.assign(preview.style, {
359
- width: `${width}px`,
360
- height: `${height}px`
361
- });
362
- preview.dataset.show = "true";
363
- });
364
- };
365
- }
366
- function createDragOverHandler(refs) {
367
- return throttle((e) => {
368
- const context = prepareDndContext(refs);
369
- if (!context)
370
- return;
371
- const {
372
- preview,
373
- content,
374
- contentRoot,
375
- xHandle,
376
- yHandle
377
- } = context;
378
- const {
379
- dragInfo,
380
- hoverIndex
381
- } = refs;
382
- if (preview.dataset.show === "false")
383
- return;
384
- const dom = getRelatedDOM(refs.contentWrapperRef, hoverIndex.current);
385
- if (!dom)
386
- return;
387
- const firstRow = contentRoot.querySelector("tr");
388
- if (!firstRow)
389
- return;
390
- const info = dragInfo.current;
391
- if (!info)
392
- return;
393
- const wrapperOffsetTop = contentRoot.offsetParent.offsetTop;
394
- const wrapperOffsetLeft = contentRoot.offsetParent.offsetLeft;
395
- if (info.type === "col") {
396
- const width = dom.col.getBoundingClientRect().width;
397
- const { left, width: fullWidth } = contentRoot.getBoundingClientRect();
398
- const leftGap = wrapperOffsetLeft - left;
399
- const previewLeft = e.clientX + leftGap - width / 2;
400
- const previewRight = e.clientX + leftGap + width / 2;
401
- const [startX] = info.startCoords;
402
- const direction = startX < e.clientX ? "right" : "left";
403
- preview.style.top = `${wrapperOffsetTop}px`;
404
- const previewLeftOffset = previewLeft < left + leftGap - 20 ? left + leftGap - 20 : previewLeft > left + fullWidth + leftGap - width + 20 ? left + fullWidth + leftGap - width + 20 : previewLeft;
405
- preview.style.left = `${previewLeftOffset}px`;
406
- const children = Array.from(firstRow.children);
407
- const col = children.find((col2, index) => {
408
- const boundary = col2.getBoundingClientRect();
409
- const boundaryLeft = boundary.left + wrapperOffsetLeft - left;
410
- const boundaryRight = boundary.right + wrapperOffsetLeft - left;
411
- if (direction === "right") {
412
- if (boundaryLeft <= previewRight && boundaryRight >= previewRight)
413
- return true;
414
- if (index === firstRow.children.length - 1 && previewRight > boundaryRight)
415
- return true;
416
- } else {
417
- if (boundaryLeft <= previewLeft && boundaryRight >= previewLeft)
418
- return true;
419
- if (index === 0 && previewLeft < boundaryLeft)
420
- return true;
421
- }
422
- return false;
423
- });
424
- if (col) {
425
- const yHandleWidth = yHandle.getBoundingClientRect().width;
426
- const contentBoundary = content.getBoundingClientRect();
427
- const index = children.indexOf(col);
428
- info.endIndex = index;
429
- computePosition(col, yHandle, {
430
- placement: direction === "left" ? "left" : "right",
431
- middleware: [offset(direction === "left" ? -1 * yHandleWidth : 0)]
432
- }).then(({ x }) => {
433
- yHandle.dataset.show = "true";
434
- Object.assign(yHandle.style, {
435
- height: `${contentBoundary.height}px`,
436
- left: `${x}px`,
437
- top: `${wrapperOffsetTop}px`
438
- });
439
- });
440
- }
441
- } else if (info.type === "row") {
442
- const height = dom.row.getBoundingClientRect().height;
443
- const { top, height: fullHeight } = contentRoot.getBoundingClientRect();
444
- const topGap = wrapperOffsetTop - top;
445
- const previewTop = e.clientY + topGap - height / 2;
446
- const previewBottom = e.clientY + topGap + height / 2;
447
- const [_, startY] = info.startCoords;
448
- const direction = startY < e.clientY ? "down" : "up";
449
- const previewTopOffset = previewTop < top + topGap - 20 ? top + topGap - 20 : previewTop > top + fullHeight + topGap - height + 20 ? top + fullHeight + topGap - height + 20 : previewTop;
450
- preview.style.top = `${previewTopOffset}px`;
451
- preview.style.left = `${wrapperOffsetLeft}px`;
452
- const rows = Array.from(contentRoot.querySelectorAll("tr"));
453
- const row = rows.find((row2, index) => {
454
- const boundary = row2.getBoundingClientRect();
455
- const boundaryTop = boundary.top + wrapperOffsetTop - top;
456
- const boundaryBottom = boundary.bottom + wrapperOffsetTop - top;
457
- if (direction === "down") {
458
- if (boundaryTop <= previewBottom && boundaryBottom >= previewBottom)
459
- return true;
460
- if (index === rows.length - 1 && previewBottom > boundaryBottom)
461
- return true;
462
- } else {
463
- if (boundaryTop <= previewTop && boundaryBottom >= previewTop)
464
- return true;
465
- if (index === 0 && previewTop < boundaryTop)
466
- return true;
467
- }
468
- return false;
469
- });
470
- if (row) {
471
- const xHandleHeight = xHandle.getBoundingClientRect().height;
472
- const contentBoundary = content.getBoundingClientRect();
473
- const index = rows.indexOf(row);
474
- info.endIndex = index;
475
- computePosition(row, xHandle, {
476
- placement: direction === "up" ? "top" : "bottom",
477
- middleware: [offset(direction === "up" ? -1 * xHandleHeight : 0)]
478
- }).then(({ y }) => {
479
- xHandle.dataset.show = "true";
480
- Object.assign(xHandle.style, {
481
- width: `${contentBoundary.width}px`,
482
- top: `${y}px`
483
- });
484
- });
485
- }
486
- }
487
- }, 20);
488
- }
489
- function useDragHandlers(refs, ctx, getPos) {
490
- const {
491
- dragPreviewRef,
492
- yLineHandleRef,
493
- xLineHandleRef,
494
- dragInfo
495
- } = refs;
496
- const host = useHost();
497
- const root = useMemo(() => host.current.getRootNode(), [host]);
498
- const dragRow = useMemo(() => createDragRowHandler(refs, ctx), [refs]);
499
- const dragCol = useMemo(() => createDragColHandler(refs, ctx), [refs]);
500
- useEffect(() => {
501
- const onDragEnd = () => {
502
- const preview = dragPreviewRef.current;
503
- if (!preview)
504
- return;
505
- if (preview.dataset.show === "false")
506
- return;
507
- const previewRoot = preview == null ? void 0 : preview.querySelector("tbody");
508
- while (previewRoot == null ? void 0 : previewRoot.firstChild)
509
- previewRoot == null ? void 0 : previewRoot.removeChild(previewRoot.firstChild);
510
- if (preview)
511
- preview.dataset.show = "false";
512
- };
513
- const onDrop = () => {
514
- var _a;
515
- const preview = dragPreviewRef.current;
516
- if (!preview)
517
- return;
518
- const yHandle = yLineHandleRef.current;
519
- if (!yHandle)
520
- return;
521
- const xHandle = xLineHandleRef.current;
522
- if (!xHandle)
523
- return;
524
- const info = dragInfo.current;
525
- if (!info)
526
- return;
527
- if (!ctx)
528
- return;
529
- if (preview.dataset.show === "false")
530
- return;
531
- const colHandle = refs.colHandleRef.current;
532
- if (!colHandle)
533
- return;
534
- const rowHandle = refs.rowHandleRef.current;
535
- if (!rowHandle)
536
- return;
537
- yHandle.dataset.show = "false";
538
- xHandle.dataset.show = "false";
539
- if (info.startIndex === info.endIndex)
540
- return;
541
- const commands = ctx.get(commandsCtx);
542
- const payload = {
543
- from: info.startIndex,
544
- to: info.endIndex,
545
- pos: ((_a = getPos == null ? void 0 : getPos()) != null ? _a : 0) + 1
546
- };
547
- if (info.type === "col") {
548
- commands.call(selectColCommand.key, {
549
- pos: payload.pos,
550
- index: info.startIndex
551
- });
552
- commands.call(moveColCommand.key, payload);
553
- const index = [0, info.endIndex];
554
- computeColHandlePositionByIndex({
555
- refs,
556
- index
557
- });
558
- } else {
559
- commands.call(selectRowCommand.key, {
560
- pos: payload.pos,
561
- index: info.startIndex
562
- });
563
- commands.call(moveRowCommand.key, payload);
564
- const index = [info.endIndex, 0];
565
- computeRowHandlePositionByIndex({
566
- refs,
567
- index
568
- });
569
- }
570
- };
571
- const onDragOver = createDragOverHandler(refs);
572
- root.addEventListener("dragover", onDragOver);
573
- root.addEventListener("dragend", onDragEnd);
574
- root.addEventListener("drop", onDrop);
575
- return () => {
576
- root.removeEventListener("dragover", onDragOver);
577
- root.removeEventListener("dragend", onDragEnd);
578
- root.removeEventListener("drop", onDrop);
579
- };
580
- }, []);
581
- return {
582
- dragRow,
583
- dragCol
584
- };
585
- }
586
-
587
- function createPointerMoveHandler(refs, view) {
588
- return throttle((e) => {
589
- if (!(view == null ? void 0 : view.editable))
590
- return;
591
- const {
592
- contentWrapperRef,
593
- yLineHandleRef,
594
- xLineHandleRef,
595
- colHandleRef,
596
- rowHandleRef,
597
- hoverIndex,
598
- lineHoverIndex
599
- } = refs;
600
- const yHandle = yLineHandleRef.current;
601
- if (!yHandle)
602
- return;
603
- const xHandle = xLineHandleRef.current;
604
- if (!xHandle)
605
- return;
606
- const content = contentWrapperRef.current;
607
- if (!content)
608
- return;
609
- const rowHandle = rowHandleRef.current;
610
- if (!rowHandle)
611
- return;
612
- const colHandle = colHandleRef.current;
613
- if (!colHandle)
614
- return;
615
- const index = findPointerIndex(e, view);
616
- if (!index)
617
- return;
618
- const dom = getRelatedDOM(contentWrapperRef, index);
619
- if (!dom)
620
- return;
621
- const [rowIndex, colIndex] = index;
622
- const boundary = dom.col.getBoundingClientRect();
623
- const closeToBoundaryLeft = Math.abs(e.clientX - boundary.left) < 8;
624
- const closeToBoundaryRight = Math.abs(boundary.right - e.clientX) < 8;
625
- const closeToBoundaryTop = Math.abs(e.clientY - boundary.top) < 8;
626
- const closeToBoundaryBottom = Math.abs(boundary.bottom - e.clientY) < 8;
627
- const closeToBoundary = closeToBoundaryLeft || closeToBoundaryRight || closeToBoundaryTop || closeToBoundaryBottom;
628
- const rowButtonGroup = rowHandle.querySelector(".button-group");
629
- const colButtonGroup = colHandle.querySelector(".button-group");
630
- if (rowButtonGroup)
631
- rowButtonGroup.dataset.show = "false";
632
- if (colButtonGroup)
633
- colButtonGroup.dataset.show = "false";
634
- if (closeToBoundary) {
635
- const contentBoundary = content.getBoundingClientRect();
636
- rowHandle.dataset.show = "false";
637
- colHandle.dataset.show = "false";
638
- xHandle.dataset.displayType = "tool";
639
- yHandle.dataset.displayType = "tool";
640
- const yHandleWidth = yHandle.getBoundingClientRect().width;
641
- const xHandleHeight = xHandle.getBoundingClientRect().height;
642
- if (closeToBoundaryLeft || closeToBoundaryRight) {
643
- lineHoverIndex.current[1] = closeToBoundaryLeft ? colIndex : colIndex + 1;
644
- computePosition(dom.col, yHandle, {
645
- placement: closeToBoundaryLeft ? "left" : "right",
646
- middleware: [offset(closeToBoundaryLeft ? -1 * yHandleWidth : 0)]
647
- }).then(({ x }) => {
648
- yHandle.dataset.show = "true";
649
- Object.assign(yHandle.style, {
650
- height: `${contentBoundary.height}px`,
651
- left: `${x}px`
652
- });
653
- });
654
- } else {
655
- yHandle.dataset.show = "false";
656
- }
657
- if (index[0] !== 0 && (closeToBoundaryTop || closeToBoundaryBottom)) {
658
- lineHoverIndex.current[0] = closeToBoundaryTop ? rowIndex : rowIndex + 1;
659
- computePosition(dom.row, xHandle, {
660
- placement: closeToBoundaryTop ? "top" : "bottom",
661
- middleware: [offset(closeToBoundaryTop ? -1 * xHandleHeight : 0)]
662
- }).then(({ y }) => {
663
- xHandle.dataset.show = "true";
664
- Object.assign(xHandle.style, {
665
- width: `${contentBoundary.width}px`,
666
- top: `${y}px`
667
- });
668
- });
669
- } else {
670
- xHandle.dataset.show = "false";
671
- }
672
- return;
673
- }
674
- lineHoverIndex.current = [-1, -1];
675
- yHandle.dataset.show = "false";
676
- xHandle.dataset.show = "false";
677
- rowHandle.dataset.show = "true";
678
- colHandle.dataset.show = "true";
679
- computeRowHandlePositionByIndex({
680
- refs,
681
- index
682
- });
683
- computeColHandlePositionByIndex({
684
- refs,
685
- index
686
- });
687
- hoverIndex.current = index;
688
- }, 20);
689
- }
690
- function createPointerLeaveHandler(refs) {
691
- return () => {
692
- const {
693
- rowHandleRef,
694
- colHandleRef,
695
- yLineHandleRef,
696
- xLineHandleRef
697
- } = refs;
698
- setTimeout(() => {
699
- const rowHandle = rowHandleRef.current;
700
- if (!rowHandle)
701
- return;
702
- const colHandle = colHandleRef.current;
703
- if (!colHandle)
704
- return;
705
- const yHandle = yLineHandleRef.current;
706
- if (!yHandle)
707
- return;
708
- const xHandle = xLineHandleRef.current;
709
- if (!xHandle)
710
- return;
711
- rowHandle.dataset.show = "false";
712
- colHandle.dataset.show = "false";
713
- yHandle.dataset.show = "false";
714
- xHandle.dataset.show = "false";
715
- }, 200);
716
- };
717
- }
718
- function usePointerHandlers(refs, view) {
719
- const pointerMove = useMemo(() => createPointerMoveHandler(refs, view), []);
720
- const pointerLeave = useMemo(() => createPointerLeaveHandler(refs), []);
721
- return {
722
- pointerMove,
723
- pointerLeave
724
- };
725
- }
726
-
727
- function useOperation(refs, ctx, getPos) {
728
- const {
729
- xLineHandleRef,
730
- contentWrapperRef,
731
- colHandleRef,
732
- rowHandleRef,
733
- hoverIndex,
734
- lineHoverIndex
735
- } = refs;
736
- const onAddRow = useCallback(() => {
737
- var _a, _b, _c;
738
- if (!ctx)
739
- return;
740
- const xHandle = xLineHandleRef.current;
741
- if (!xHandle)
742
- return;
743
- const [rowIndex] = lineHoverIndex.current;
744
- if (rowIndex < 0)
745
- return;
746
- if (!ctx.get(editorViewCtx).editable)
747
- return;
748
- const rows = Array.from((_b = (_a = contentWrapperRef.current) == null ? void 0 : _a.querySelectorAll("tr")) != null ? _b : []);
749
- const commands = ctx.get(commandsCtx);
750
- const pos = ((_c = getPos == null ? void 0 : getPos()) != null ? _c : 0) + 1;
751
- if (rows.length === rowIndex) {
752
- commands.call(selectRowCommand.key, { pos, index: rowIndex - 1 });
753
- commands.call(addRowAfterCommand.key);
754
- } else {
755
- commands.call(selectRowCommand.key, { pos, index: rowIndex });
756
- commands.call(addRowBeforeCommand.key);
757
- }
758
- commands.call(selectRowCommand.key, { pos, index: rowIndex });
759
- xHandle.dataset.show = "false";
760
- }, []);
761
- const onAddCol = useCallback(() => {
762
- var _a, _b, _c, _d;
763
- if (!ctx)
764
- return;
765
- const xHandle = xLineHandleRef.current;
766
- if (!xHandle)
767
- return;
768
- const [_, colIndex] = lineHoverIndex.current;
769
- if (colIndex < 0)
770
- return;
771
- if (!ctx.get(editorViewCtx).editable)
772
- return;
773
- const cols = Array.from((_c = (_b = (_a = contentWrapperRef.current) == null ? void 0 : _a.querySelector("tr")) == null ? void 0 : _b.children) != null ? _c : []);
774
- const commands = ctx.get(commandsCtx);
775
- const pos = ((_d = getPos == null ? void 0 : getPos()) != null ? _d : 0) + 1;
776
- if (cols.length === colIndex) {
777
- commands.call(selectColCommand.key, { pos, index: colIndex - 1 });
778
- commands.call(addColAfterCommand.key);
779
- } else {
780
- commands.call(selectColCommand.key, { pos, index: colIndex });
781
- commands.call(addColBeforeCommand.key);
782
- }
783
- commands.call(selectColCommand.key, { pos, index: colIndex });
784
- }, []);
785
- const selectCol = useCallback(() => {
786
- var _a, _b;
787
- if (!ctx)
788
- return;
789
- const [_, colIndex] = hoverIndex.current;
790
- const commands = ctx.get(commandsCtx);
791
- const pos = ((_a = getPos == null ? void 0 : getPos()) != null ? _a : 0) + 1;
792
- commands.call(selectColCommand.key, { pos, index: colIndex });
793
- const buttonGroup = (_b = colHandleRef.current) == null ? void 0 : _b.querySelector(".button-group");
794
- if (buttonGroup)
795
- buttonGroup.dataset.show = buttonGroup.dataset.show === "true" ? "false" : "true";
796
- }, []);
797
- const selectRow = useCallback(() => {
798
- var _a, _b;
799
- if (!ctx)
800
- return;
801
- const [rowIndex, _] = hoverIndex.current;
802
- const commands = ctx.get(commandsCtx);
803
- const pos = ((_a = getPos == null ? void 0 : getPos()) != null ? _a : 0) + 1;
804
- commands.call(selectRowCommand.key, { pos, index: rowIndex });
805
- const buttonGroup = (_b = rowHandleRef.current) == null ? void 0 : _b.querySelector(".button-group");
806
- if (buttonGroup && rowIndex > 0)
807
- buttonGroup.dataset.show = buttonGroup.dataset.show === "true" ? "false" : "true";
808
- }, []);
809
- const deleteSelected = useCallback((e) => {
810
- if (!ctx)
811
- return;
812
- if (!ctx.get(editorViewCtx).editable)
813
- return;
814
- e.preventDefault();
815
- e.stopPropagation();
816
- const commands = ctx.get(commandsCtx);
817
- commands.call(deleteSelectedCellsCommand.key);
818
- }, []);
819
- const onAlign = useCallback((direction) => (e) => {
820
- if (!ctx)
821
- return;
822
- if (!ctx.get(editorViewCtx).editable)
823
- return;
824
- e.preventDefault();
825
- e.stopPropagation();
826
- const commands = ctx.get(commandsCtx);
827
- commands.call(setAlignCommand.key, direction);
828
- }, []);
829
- return {
830
- onAddRow,
831
- onAddCol,
832
- selectCol,
833
- selectRow,
834
- deleteSelected,
835
- onAlign
836
- };
837
- }
838
-
839
- const tableComponent = ({
840
- view,
841
- ctx,
842
- getPos,
843
- node,
844
- config
845
- }) => {
846
- const host = useHost();
847
- const contentWrapperRef = useRef();
848
- const colHandleRef = useRef();
849
- const rowHandleRef = useRef();
850
- const xLineHandleRef = useRef();
851
- const yLineHandleRef = useRef();
852
- const tableWrapperRef = useRef();
853
- const dragPreviewRef = useRef();
854
- const hoverIndex = useRef([0, 0]);
855
- const lineHoverIndex = useRef([-1, -1]);
856
- const dragInfo = useRef();
857
- const refs = useMemo(() => {
858
- return {
859
- dragPreviewRef,
860
- tableWrapperRef,
861
- contentWrapperRef,
862
- yLineHandleRef,
863
- xLineHandleRef,
864
- colHandleRef,
865
- rowHandleRef,
866
- hoverIndex,
867
- lineHoverIndex,
868
- dragInfo
869
- };
870
- }, []);
871
- useLayoutEffect(() => {
872
- const current = contentWrapperRef.current;
873
- if (!current)
874
- return;
875
- const contentDOM = host.current.querySelector("[data-content-dom]");
876
- if (contentDOM)
877
- current.appendChild(contentDOM);
878
- if (view == null ? void 0 : view.editable)
879
- recoveryStateBetweenUpdate(refs, ctx, node);
880
- }, []);
881
- const { pointerLeave, pointerMove } = usePointerHandlers(refs, view);
882
- const { dragRow, dragCol } = useDragHandlers(refs, ctx, getPos);
883
- const {
884
- onAddRow,
885
- onAddCol,
886
- selectCol,
887
- selectRow,
888
- deleteSelected,
889
- onAlign
890
- } = useOperation(refs, ctx, getPos);
891
- return html`
892
- <host
893
- class=${clsx(!(view == null ? void 0 : view.editable) && "readonly")}
894
- ondragstart=${(e) => e.preventDefault()}
895
- ondragover=${(e) => e.preventDefault()}
896
- ondragleave=${(e) => e.preventDefault()}
897
- onpointermove=${pointerMove}
898
- onpointerleave=${pointerLeave}
899
- >
900
- <button
901
- data-show="false"
902
- contenteditable="false"
903
- draggable="true"
904
- data-role="col-drag-handle"
905
- class="handle cell-handle"
906
- ondragstart=${dragCol}
907
- onclick=${selectCol}
908
- onpointerdown=${(e) => e.stopPropagation()}
909
- onpointermove=${(e) => e.stopPropagation()}
910
- ref=${colHandleRef}
911
- >
912
- ${config == null ? void 0 : config.renderButton("col_drag_handle")}
913
- <div
914
- data-show="false"
915
- class="button-group"
916
- onpointermove=${(e) => e.stopPropagation}
917
- >
918
- <button onpointerdown=${onAlign("left")}>
919
- ${config == null ? void 0 : config.renderButton("align_col_left")}
920
- </button>
921
- <button onpointerdown=${onAlign("center")}>
922
- ${config == null ? void 0 : config.renderButton("align_col_center")}
923
- </button>
924
- <button onpointerdown=${onAlign("right")}>
925
- ${config == null ? void 0 : config.renderButton("align_col_right")}
926
- </button>
927
- <button onpointerdown=${deleteSelected}>
928
- ${config == null ? void 0 : config.renderButton("delete_col")}
929
- </button>
930
- </div>
931
- </button>
932
- <button
933
- data-show="false"
934
- contenteditable="false"
935
- draggable="true"
936
- data-role="row-drag-handle"
937
- class="handle cell-handle"
938
- ondragstart=${dragRow}
939
- onclick=${selectRow}
940
- onpointerdown=${(e) => e.stopPropagation()}
941
- onpointermove=${(e) => e.stopPropagation()}
942
- ref=${rowHandleRef}
943
- >
944
- ${config == null ? void 0 : config.renderButton("row_drag_handle")}
945
- <div
946
- data-show="false"
947
- class="button-group"
948
- onpointermove=${(e) => e.stopPropagation}
949
- >
950
- <button onpointerdown=${deleteSelected}>
951
- ${config == null ? void 0 : config.renderButton("delete_row")}
952
- </button>
953
- </div>
954
- </button>
955
- <div class="table-wrapper" ref=${tableWrapperRef}>
956
- <div
957
- data-show="false"
958
- class="drag-preview"
959
- data-direction="vertical"
960
- ref=${dragPreviewRef}
961
- >
962
- <table>
963
- <tbody>
964
- </tbody>
965
- </table>
966
- </div>
967
- <div
968
- data-show="false"
969
- contenteditable="false"
970
- data-display-type="tool"
971
- data-role="x-line-drag-handle"
972
- class="handle line-handle"
973
- onpointermove=${(e) => e.stopPropagation}
974
- ref=${xLineHandleRef}
975
- >
976
- <button onclick=${onAddRow} class="add-button">
977
- ${config == null ? void 0 : config.renderButton("add_row")}
978
- </button>
979
- </div>
980
- <div
981
- data-show="false"
982
- contenteditable="false"
983
- data-display-type="tool"
984
- data-role="y-line-drag-handle"
985
- class="handle line-handle"
986
- onpointermove=${(e) => e.stopPropagation}
987
- ref=${yLineHandleRef}
988
- >
989
- <button onclick=${onAddCol} class="add-button">
990
- ${config == null ? void 0 : config.renderButton("add_col")}
991
- </button>
992
- </div>
993
- <table ref=${contentWrapperRef} class="children"></table>
994
- </div>
995
- </host>
996
- `;
997
- };
998
- tableComponent.props = {
999
- getPos: Function,
1000
- view: Object,
1001
- ctx: Object,
1002
- node: Object,
1003
- config: Object
1004
- };
1005
- const TableElement = c(tableComponent);
1006
-
1007
- var __typeError = (msg) => {
1008
- throw TypeError(msg);
1009
- };
1010
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
1011
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1012
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
1013
- var _TableNodeView_instances, handleClick_fn;
1014
- class TableNodeView {
1015
- constructor(ctx, node, view, getPos) {
1016
- this.ctx = ctx;
1017
- this.node = node;
1018
- this.view = view;
1019
- this.getPos = getPos;
1020
- __privateAdd(this, _TableNodeView_instances);
1021
- const dom = document.createElement("milkdown-table-block");
1022
- this.dom = dom;
1023
- dom.view = view;
1024
- dom.ctx = ctx;
1025
- dom.getPos = getPos;
1026
- dom.node = node;
1027
- dom.config = ctx.get(tableBlockConfig.key);
1028
- const contentDOM = document.createElement("tbody");
1029
- this.contentDOM = contentDOM;
1030
- contentDOM.setAttribute("data-content-dom", "true");
1031
- contentDOM.classList.add("content-dom");
1032
- dom.appendChild(contentDOM);
1033
- }
1034
- update(node) {
1035
- if (node.type !== this.node.type)
1036
- return false;
1037
- if (node.sameMarkup(this.node) && node.content.eq(this.node.content))
1038
- return false;
1039
- this.node = node;
1040
- this.dom.node = node;
1041
- return true;
1042
- }
1043
- stopEvent(e) {
1044
- if (e.type === "drop" || e.type.startsWith("drag"))
1045
- return true;
1046
- if (e.type === "mousedown") {
1047
- if (e.target instanceof HTMLButtonElement)
1048
- return true;
1049
- const target = e.target;
1050
- if (target instanceof HTMLElement && (target.closest("th") || target.closest("td"))) {
1051
- const event = e;
1052
- return __privateMethod(this, _TableNodeView_instances, handleClick_fn).call(this, event);
1053
- }
1054
- }
1055
- return false;
1056
- }
1057
- ignoreMutation(mutation) {
1058
- if (!this.dom || !this.contentDOM)
1059
- return true;
1060
- if (mutation.type === "selection")
1061
- return false;
1062
- if (this.contentDOM === mutation.target && mutation.type === "attributes")
1063
- return true;
1064
- if (this.contentDOM.contains(mutation.target))
1065
- return false;
1066
- return true;
1067
- }
1068
- }
1069
- _TableNodeView_instances = new WeakSet();
1070
- handleClick_fn = function(event) {
1071
- const view = this.view;
1072
- if (!view.editable)
1073
- return false;
1074
- const { state, dispatch } = view;
1075
- const pos = view.posAtCoords({ left: event.clientX, top: event.clientY });
1076
- if (!pos)
1077
- return false;
1078
- const $pos = state.doc.resolve(pos.inside);
1079
- const node = findParent((node2) => node2.type.name === "table_cell" || node2.type.name === "table_header")($pos);
1080
- if (!node)
1081
- return false;
1082
- const { from } = node;
1083
- const selection = NodeSelection.create(state.doc, from + 1);
1084
- if (state.selection.eq(selection))
1085
- return false;
1086
- if (state.selection instanceof CellSelection) {
1087
- setTimeout(() => {
1088
- dispatch(state.tr.setSelection(selection).scrollIntoView());
1089
- }, 20);
1090
- } else {
1091
- requestAnimationFrame(() => {
1092
- dispatch(state.tr.setSelection(selection).scrollIntoView());
1093
- });
1094
- }
1095
- return true;
1096
- };
1097
- defIfNotExists("milkdown-table-block", TableElement);
1098
- const tableBlockView = $view(tableSchema.node, (ctx) => {
1099
- return (initialNode, view, getPos) => {
1100
- return new TableNodeView(ctx, initialNode, view, getPos);
1101
- };
1102
- });
1103
- withMeta(tableBlockView, {
1104
- displayName: "NodeView<table-block>",
1105
- group: "TableBlock"
1106
- });
1107
-
1108
- const tableBlock = [
1109
- tableBlockConfig,
1110
- tableBlockView
1111
- ];
1112
-
1113
- const defineFeature = (editor, config) => {
1114
- editor.config((ctx) => {
1115
- ctx.update(tableBlockConfig.key, (defaultConfig) => ({
1116
- ...defaultConfig,
1117
- renderButton: (renderType) => {
1118
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1119
- switch (renderType) {
1120
- case "add_row":
1121
- return (_b = (_a = config == null ? void 0 : config.addRowIcon) == null ? void 0 : _a.call(config)) != null ? _b : plusIcon;
1122
- case "add_col":
1123
- return (_d = (_c = config == null ? void 0 : config.addColIcon) == null ? void 0 : _c.call(config)) != null ? _d : plusIcon;
1124
- case "delete_row":
1125
- return (_f = (_e = config == null ? void 0 : config.deleteRowIcon) == null ? void 0 : _e.call(config)) != null ? _f : removeIcon;
1126
- case "delete_col":
1127
- return (_h = (_g = config == null ? void 0 : config.deleteColIcon) == null ? void 0 : _g.call(config)) != null ? _h : removeIcon;
1128
- case "align_col_left":
1129
- return (_j = (_i = config == null ? void 0 : config.alignLeftIcon) == null ? void 0 : _i.call(config)) != null ? _j : alignLeftIcon;
1130
- case "align_col_center":
1131
- return (_l = (_k = config == null ? void 0 : config.alignCenterIcon) == null ? void 0 : _k.call(config)) != null ? _l : alignCenterIcon;
1132
- case "align_col_right":
1133
- return (_n = (_m = config == null ? void 0 : config.alignRightIcon) == null ? void 0 : _m.call(config)) != null ? _n : alignRightIcon;
1134
- case "col_drag_handle":
1135
- return (_p = (_o = config == null ? void 0 : config.colDragHandleIcon) == null ? void 0 : _o.call(config)) != null ? _p : dragHandleIcon;
1136
- case "row_drag_handle":
1137
- return (_r = (_q = config == null ? void 0 : config.rowDragHandleIcon) == null ? void 0 : _q.call(config)) != null ? _r : dragHandleIcon;
1138
- }
1139
- }
1140
- }));
1141
- }).use(tableBlock);
1142
- };
1143
-
1144
- export { defineFeature };
1145
- //# sourceMappingURL=index-8QJbxTYk.js.map