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