@kopexa/extension-table 17.0.46 → 17.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/chunk-2NBDRVYL.mjs +428 -0
  2. package/dist/chunk-3SWV7BGP.mjs +638 -0
  3. package/dist/chunk-4QSZXHZO.mjs +276 -0
  4. package/dist/chunk-5B5XIL2G.mjs +457 -0
  5. package/dist/chunk-62B2LU2Q.mjs +603 -0
  6. package/dist/chunk-6FHFDGJO.mjs +251 -0
  7. package/dist/chunk-CD62W5C3.mjs +165 -0
  8. package/dist/chunk-CN73TYHV.mjs +190 -0
  9. package/dist/chunk-CPDSPBS6.mjs +276 -0
  10. package/dist/chunk-E7W2KRZG.mjs +49 -0
  11. package/dist/chunk-G6GHC2WO.mjs +276 -0
  12. package/dist/chunk-GBTQVIN5.mjs +174 -0
  13. package/dist/chunk-GDEXPEW5.mjs +52 -0
  14. package/dist/chunk-GQLZBIWF.mjs +198 -0
  15. package/dist/chunk-IRJ6RAVQ.mjs +116 -0
  16. package/dist/chunk-J4VOSZCZ.mjs +59 -0
  17. package/dist/chunk-KIYFW7MP.mjs +122 -0
  18. package/dist/chunk-KTRZVXJC.mjs +306 -0
  19. package/dist/chunk-LUA32VH4.mjs +35 -0
  20. package/dist/{chunk-2L3HZWWG.mjs → chunk-MB52MZQ4.mjs} +7 -8
  21. package/dist/chunk-PTX5UYV6.mjs +10 -0
  22. package/dist/chunk-TEGO6KUS.mjs +96 -0
  23. package/dist/chunk-VIBVRWS4.mjs +197 -0
  24. package/dist/chunk-VQV757EG.mjs +113 -0
  25. package/dist/chunk-XRNQXADK.mjs +149 -0
  26. package/dist/chunk-ZVPJDJBO.mjs +134 -0
  27. package/dist/{kit.d.mts → extensions/kit.d.mts} +1 -3
  28. package/dist/{kit.d.ts → extensions/kit.d.ts} +1 -3
  29. package/dist/extensions/kit.js +1041 -0
  30. package/dist/extensions/kit.mjs +15 -0
  31. package/dist/extensions/table-cell.d.mts +6 -0
  32. package/dist/extensions/table-cell.d.ts +6 -0
  33. package/dist/extensions/table-cell.js +70 -0
  34. package/dist/extensions/table-cell.mjs +8 -0
  35. package/dist/extensions/table-handle-plugin.d.mts +46 -0
  36. package/dist/extensions/table-handle-plugin.d.ts +46 -0
  37. package/dist/extensions/table-handle-plugin.js +1100 -0
  38. package/dist/extensions/table-handle-plugin.mjs +18 -0
  39. package/dist/extensions/table-handle.d.mts +19 -0
  40. package/dist/extensions/table-handle.d.ts +19 -0
  41. package/dist/extensions/table-handle.js +865 -0
  42. package/dist/extensions/table-handle.mjs +11 -0
  43. package/dist/{table → extensions}/table.d.mts +2 -2
  44. package/dist/{table → extensions}/table.d.ts +2 -2
  45. package/dist/extensions/table.js +138 -0
  46. package/dist/extensions/table.mjs +9 -0
  47. package/dist/hooks/use-resize-overlay.d.mts +5 -0
  48. package/dist/hooks/use-resize-overlay.d.ts +5 -0
  49. package/dist/hooks/use-resize-overlay.js +83 -0
  50. package/dist/hooks/use-resize-overlay.mjs +9 -0
  51. package/dist/hooks/use-table-add-row-column.d.mts +57 -0
  52. package/dist/hooks/use-table-add-row-column.d.ts +57 -0
  53. package/dist/hooks/use-table-add-row-column.js +551 -0
  54. package/dist/hooks/use-table-add-row-column.mjs +11 -0
  55. package/dist/hooks/use-table-align-cell.d.mts +148 -0
  56. package/dist/hooks/use-table-align-cell.d.ts +148 -0
  57. package/dist/hooks/use-table-align-cell.js +655 -0
  58. package/dist/hooks/use-table-align-cell.mjs +13 -0
  59. package/dist/hooks/use-table-clear-row-column-content.d.mts +103 -0
  60. package/dist/hooks/use-table-clear-row-column-content.d.ts +103 -0
  61. package/dist/hooks/use-table-clear-row-column-content.js +681 -0
  62. package/dist/hooks/use-table-clear-row-column-content.mjs +11 -0
  63. package/dist/hooks/use-table-delete-row-column.d.mts +87 -0
  64. package/dist/hooks/use-table-delete-row-column.d.ts +87 -0
  65. package/dist/hooks/use-table-delete-row-column.js +459 -0
  66. package/dist/hooks/use-table-delete-row-column.mjs +11 -0
  67. package/dist/hooks/use-table-duplicate-row-column.d.mts +49 -0
  68. package/dist/hooks/use-table-duplicate-row-column.d.ts +49 -0
  69. package/dist/hooks/use-table-duplicate-row-column.js +758 -0
  70. package/dist/hooks/use-table-duplicate-row-column.mjs +11 -0
  71. package/dist/hooks/use-table-handle-positioning.d.mts +42 -0
  72. package/dist/hooks/use-table-handle-positioning.d.ts +42 -0
  73. package/dist/hooks/use-table-handle-positioning.js +190 -0
  74. package/dist/hooks/use-table-handle-positioning.mjs +10 -0
  75. package/dist/hooks/use-table-handle-state.d.mts +28 -0
  76. package/dist/hooks/use-table-handle-state.d.ts +28 -0
  77. package/dist/hooks/use-table-handle-state.js +76 -0
  78. package/dist/hooks/use-table-handle-state.mjs +9 -0
  79. package/dist/hooks/use-table-header-row-column.d.mts +58 -0
  80. package/dist/hooks/use-table-header-row-column.d.ts +58 -0
  81. package/dist/hooks/use-table-header-row-column.js +603 -0
  82. package/dist/hooks/use-table-header-row-column.mjs +13 -0
  83. package/dist/hooks/use-table-merge-split-cell.d.mts +123 -0
  84. package/dist/hooks/use-table-merge-split-cell.d.ts +123 -0
  85. package/dist/hooks/use-table-merge-split-cell.js +331 -0
  86. package/dist/hooks/use-table-merge-split-cell.mjs +12 -0
  87. package/dist/hooks/use-table-move-row-column.d.mts +101 -0
  88. package/dist/hooks/use-table-move-row-column.d.ts +101 -0
  89. package/dist/hooks/use-table-move-row-column.js +621 -0
  90. package/dist/hooks/use-table-move-row-column.mjs +13 -0
  91. package/dist/hooks/use-table-sort-row-column.d.mts +118 -0
  92. package/dist/hooks/use-table-sort-row-column.d.ts +118 -0
  93. package/dist/hooks/use-table-sort-row-column.js +623 -0
  94. package/dist/hooks/use-table-sort-row-column.mjs +13 -0
  95. package/dist/index.d.mts +17 -6
  96. package/dist/index.d.ts +17 -6
  97. package/dist/index.js +4947 -660
  98. package/dist/index.mjs +43 -21
  99. package/dist/lib/constants.d.mts +4 -0
  100. package/dist/lib/constants.d.ts +4 -0
  101. package/dist/{table/lib/is-cell-selection.js → lib/constants.js} +10 -10
  102. package/dist/lib/constants.mjs +10 -0
  103. package/dist/lib/create-image.d.mts +12 -0
  104. package/dist/lib/create-image.d.ts +12 -0
  105. package/dist/lib/create-image.js +221 -0
  106. package/dist/lib/create-image.mjs +8 -0
  107. package/dist/lib/table-utils.d.mts +263 -0
  108. package/dist/lib/table-utils.d.ts +263 -0
  109. package/dist/lib/table-utils.js +488 -0
  110. package/dist/lib/table-utils.mjs +40 -0
  111. package/dist/messages.d.mts +174 -0
  112. package/dist/messages.d.ts +174 -0
  113. package/dist/messages.js +213 -0
  114. package/dist/{table-row.mjs → messages.mjs} +3 -3
  115. package/dist/ui/table-alignment-menu.d.mts +25 -0
  116. package/dist/ui/table-alignment-menu.d.ts +25 -0
  117. package/dist/ui/table-alignment-menu.js +758 -0
  118. package/dist/ui/table-alignment-menu.mjs +14 -0
  119. package/dist/ui/table-cell-handle-menu.d.mts +12 -0
  120. package/dist/ui/table-cell-handle-menu.d.ts +12 -0
  121. package/dist/ui/table-cell-handle-menu.js +1317 -0
  122. package/dist/ui/table-cell-handle-menu.mjs +17 -0
  123. package/dist/ui/table-handle-menu.d.mts +23 -0
  124. package/dist/ui/table-handle-menu.d.ts +23 -0
  125. package/dist/ui/table-handle-menu.js +2598 -0
  126. package/dist/ui/table-handle-menu.mjs +21 -0
  127. package/dist/ui/table-handle.d.mts +48 -0
  128. package/dist/ui/table-handle.d.ts +48 -0
  129. package/dist/ui/table-handle.js +3126 -0
  130. package/dist/ui/table-handle.mjs +22 -0
  131. package/dist/ui/table-selection-overlay.d.mts +14 -0
  132. package/dist/ui/table-selection-overlay.d.ts +14 -0
  133. package/dist/ui/table-selection-overlay.js +553 -0
  134. package/dist/ui/table-selection-overlay.mjs +11 -0
  135. package/package.json +12 -7
  136. package/dist/chunk-3XEOCAHB.mjs +0 -41
  137. package/dist/chunk-5W5ARI64.mjs +0 -11
  138. package/dist/chunk-BTJ3DCGC.mjs +0 -113
  139. package/dist/chunk-DR2GZJH6.mjs +0 -70
  140. package/dist/chunk-GHOJLOCF.mjs +0 -247
  141. package/dist/chunk-HWVA6DOK.mjs +0 -20
  142. package/dist/chunk-KLUH6EZS.mjs +0 -40
  143. package/dist/chunk-KNOMCS6F.mjs +0 -57
  144. package/dist/chunk-LPHCE6EI.mjs +0 -92
  145. package/dist/chunk-POJFNXG7.mjs +0 -44
  146. package/dist/chunk-QHD3QTD2.mjs +0 -61
  147. package/dist/chunk-RPPUD4R5.mjs +0 -1
  148. package/dist/kit.js +0 -764
  149. package/dist/kit.mjs +0 -19
  150. package/dist/table/index.d.mts +0 -6
  151. package/dist/table/index.d.ts +0 -6
  152. package/dist/table/index.js +0 -625
  153. package/dist/table/index.mjs +0 -18
  154. package/dist/table/lib/col-style.d.mts +0 -3
  155. package/dist/table/lib/col-style.d.ts +0 -3
  156. package/dist/table/lib/col-style.js +0 -36
  157. package/dist/table/lib/col-style.mjs +0 -13
  158. package/dist/table/lib/delete-table-when-all-cells-selected.d.mts +0 -5
  159. package/dist/table/lib/delete-table-when-all-cells-selected.d.ts +0 -5
  160. package/dist/table/lib/delete-table-when-all-cells-selected.js +0 -66
  161. package/dist/table/lib/delete-table-when-all-cells-selected.mjs +0 -40
  162. package/dist/table/lib/get-table-node-types.d.mts +0 -7
  163. package/dist/table/lib/get-table-node-types.d.ts +0 -7
  164. package/dist/table/lib/get-table-node-types.js +0 -44
  165. package/dist/table/lib/get-table-node-types.mjs +0 -21
  166. package/dist/table/lib/icons.d.mts +0 -13
  167. package/dist/table/lib/icons.d.ts +0 -13
  168. package/dist/table/lib/icons.js +0 -81
  169. package/dist/table/lib/icons.mjs +0 -58
  170. package/dist/table/lib/insert-line-above-table-action.d.mts +0 -5
  171. package/dist/table/lib/insert-line-above-table-action.d.ts +0 -5
  172. package/dist/table/lib/insert-line-above-table-action.js +0 -64
  173. package/dist/table/lib/insert-line-above-table-action.mjs +0 -8
  174. package/dist/table/lib/insert-line-below-table-action.d.mts +0 -5
  175. package/dist/table/lib/insert-line-below-table-action.d.ts +0 -5
  176. package/dist/table/lib/insert-line-below-table-action.js +0 -63
  177. package/dist/table/lib/insert-line-below-table-action.mjs +0 -8
  178. package/dist/table/lib/is-cell-selection.d.mts +0 -5
  179. package/dist/table/lib/is-cell-selection.d.ts +0 -5
  180. package/dist/table/lib/is-cell-selection.mjs +0 -8
  181. package/dist/table/lib/table-controls.d.mts +0 -15
  182. package/dist/table/lib/table-controls.d.ts +0 -15
  183. package/dist/table/lib/table-controls.js +0 -131
  184. package/dist/table/lib/table-controls.mjs +0 -8
  185. package/dist/table/table.js +0 -621
  186. package/dist/table/table.mjs +0 -14
  187. package/dist/table/views/table-column-menu.d.mts +0 -11
  188. package/dist/table/views/table-column-menu.d.ts +0 -11
  189. package/dist/table/views/table-column-menu.js +0 -84
  190. package/dist/table/views/table-column-menu.mjs +0 -8
  191. package/dist/table/views/table-node-view.d.mts +0 -25
  192. package/dist/table/views/table-node-view.d.ts +0 -25
  193. package/dist/table/views/table-node-view.js +0 -370
  194. package/dist/table/views/table-node-view.mjs +0 -10
  195. package/dist/table/views/table-row-menu.d.mts +0 -11
  196. package/dist/table/views/table-row-menu.d.ts +0 -11
  197. package/dist/table/views/table-row-menu.js +0 -80
  198. package/dist/table/views/table-row-menu.mjs +0 -8
  199. package/dist/table-cell.d.mts +0 -8
  200. package/dist/table-cell.d.ts +0 -8
  201. package/dist/table-cell.js +0 -93
  202. package/dist/table-cell.mjs +0 -8
  203. package/dist/table-header.d.mts +0 -6
  204. package/dist/table-header.d.ts +0 -6
  205. package/dist/table-header.js +0 -67
  206. package/dist/table-header.mjs +0 -8
  207. package/dist/table-row.d.mts +0 -6
  208. package/dist/table-row.d.ts +0 -6
  209. package/dist/table-row.js +0 -43
@@ -0,0 +1,197 @@
1
+ "use client";
2
+ import {
3
+ messages
4
+ } from "./chunk-CN73TYHV.mjs";
5
+ import {
6
+ getTable,
7
+ getTableSelectionType,
8
+ selectCellsByCoords,
9
+ updateSelectionAfterAction
10
+ } from "./chunk-5B5XIL2G.mjs";
11
+
12
+ // src/hooks/use-table-add-row-column.ts
13
+ import { isExtensionAvailable, useTiptapEditor } from "@kopexa/editor-utils";
14
+ import { useSafeIntl } from "@kopexa/i18n";
15
+ import {
16
+ AddColLeftIcon,
17
+ AddColRightIcon,
18
+ AddRowBottomIcon,
19
+ AddRowTopIcon
20
+ } from "@kopexa/icons";
21
+ import {
22
+ addColumnAfter,
23
+ addColumnBefore,
24
+ addRowAfter,
25
+ addRowBefore,
26
+ CellSelection,
27
+ columnIsHeader,
28
+ rowIsHeader
29
+ } from "@tiptap/pm/tables";
30
+ import { useCallback } from "react";
31
+ var REQUIRED_EXTENSIONS = ["table"];
32
+ var addRowMessageKeys = {
33
+ above: messages.insert_row_above,
34
+ below: messages.insert_row_below
35
+ };
36
+ var addColumnMessageKeys = {
37
+ left: messages.insert_column_left,
38
+ right: messages.insert_column_right
39
+ };
40
+ function safeColumnIsHeader(map, node, index) {
41
+ try {
42
+ return columnIsHeader(map, node, index);
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+ function safeRowIsHeader(map, node, index) {
48
+ try {
49
+ return rowIsHeader(map, node, index);
50
+ } catch {
51
+ return false;
52
+ }
53
+ }
54
+ function canAddRowColumn({
55
+ editor,
56
+ index,
57
+ orientation,
58
+ tablePos,
59
+ side
60
+ }) {
61
+ if (!editor || !editor.isEditable || !isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) {
62
+ return false;
63
+ }
64
+ const table = getTable(editor, tablePos);
65
+ if (!table) return false;
66
+ const selectionType = getTableSelectionType(editor, index, orientation);
67
+ if (!selectionType) return false;
68
+ const { map, node } = table;
69
+ const selIndex = selectionType.index;
70
+ const selOrient = selectionType.orientation;
71
+ if (typeof selIndex !== "number" || selIndex < 0) return false;
72
+ if (selOrient === "column" && selIndex >= map.width) return false;
73
+ if (selOrient === "row" && selIndex >= map.height) return false;
74
+ if (side === "left" && selOrient === "column") {
75
+ if (safeColumnIsHeader(map, node, selIndex)) return false;
76
+ }
77
+ if (side === "above" && selOrient === "row") {
78
+ if (safeRowIsHeader(map, node, selIndex)) return false;
79
+ }
80
+ return true;
81
+ }
82
+ function calculateNewIndex(index, orientation, side) {
83
+ if (orientation === "row") {
84
+ return side === "above" ? index : index + 1;
85
+ } else {
86
+ return side === "left" ? index : index + 1;
87
+ }
88
+ }
89
+ function tableAddRowColumn({
90
+ editor,
91
+ index,
92
+ orientation,
93
+ side,
94
+ tablePos
95
+ }) {
96
+ if (!canAddRowColumn({ editor, index, orientation, tablePos, side }) || !editor) {
97
+ return false;
98
+ }
99
+ const selectionType = getTableSelectionType(editor, index, orientation);
100
+ if (!selectionType) return false;
101
+ const { orientation: finalOrientation, index: finalIndex } = selectionType;
102
+ const isRow = finalOrientation === "row";
103
+ const dispatch = (tr) => editor.view.dispatch(tr);
104
+ const addOperation = isRow ? side === "above" ? addRowBefore : addRowAfter : side === "left" ? addColumnBefore : addColumnAfter;
105
+ try {
106
+ let success = false;
107
+ if (editor.state.selection instanceof CellSelection) {
108
+ success = addOperation(editor.state, dispatch);
109
+ } else {
110
+ const table = getTable(editor, tablePos);
111
+ if (!table) return false;
112
+ const cellCoords = finalOrientation === "row" ? { row: finalIndex, col: 0 } : { row: 0, col: finalIndex };
113
+ const cellState = selectCellsByCoords(editor, table.pos, [cellCoords], {
114
+ mode: "state"
115
+ });
116
+ if (!cellState) return false;
117
+ success = addOperation(cellState, dispatch);
118
+ }
119
+ if (success) {
120
+ const newIndex = calculateNewIndex(finalIndex, finalOrientation, side);
121
+ updateSelectionAfterAction(editor, finalOrientation, newIndex, tablePos);
122
+ }
123
+ return success;
124
+ } catch (error) {
125
+ console.error("Error adding row/column:", error);
126
+ return false;
127
+ }
128
+ }
129
+ function shouldShowButton({
130
+ editor,
131
+ index,
132
+ orientation,
133
+ tablePos,
134
+ side,
135
+ hideWhenUnavailable
136
+ }) {
137
+ if (!editor || !editor.isEditable) return false;
138
+ if (!isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) return false;
139
+ if (hideWhenUnavailable) {
140
+ return canAddRowColumn({ editor, index, orientation, tablePos, side });
141
+ }
142
+ const selectionType = getTableSelectionType(editor, index, orientation);
143
+ return Boolean(selectionType);
144
+ }
145
+ function useTableAddRowColumn(config) {
146
+ const {
147
+ editor: providedEditor,
148
+ index,
149
+ orientation,
150
+ side,
151
+ tablePos,
152
+ hideWhenUnavailable = false,
153
+ onAdded
154
+ } = config;
155
+ const { editor } = useTiptapEditor(providedEditor);
156
+ const intl = useSafeIntl();
157
+ const selectionType = getTableSelectionType(editor, index, orientation);
158
+ const isVisible = shouldShowButton({
159
+ editor,
160
+ index,
161
+ orientation,
162
+ tablePos,
163
+ side,
164
+ hideWhenUnavailable
165
+ });
166
+ const canPerformAdd = canAddRowColumn({
167
+ editor,
168
+ index,
169
+ orientation,
170
+ tablePos,
171
+ side
172
+ });
173
+ const handleAdd = useCallback(() => {
174
+ const success = tableAddRowColumn({
175
+ editor,
176
+ index,
177
+ orientation,
178
+ tablePos,
179
+ side
180
+ });
181
+ if (success) onAdded == null ? void 0 : onAdded();
182
+ return success;
183
+ }, [editor, index, orientation, tablePos, side, onAdded]);
184
+ const label = (selectionType == null ? void 0 : selectionType.orientation) === "row" ? intl.formatMessage(addRowMessageKeys[side]) : intl.formatMessage(addColumnMessageKeys[side]);
185
+ const Icon = (selectionType == null ? void 0 : selectionType.orientation) === "row" ? side === "above" ? AddRowTopIcon : AddRowBottomIcon : side === "left" ? AddColLeftIcon : AddColRightIcon;
186
+ return {
187
+ isVisible,
188
+ canAddRowColumn: canPerformAdd,
189
+ handleAdd,
190
+ label,
191
+ Icon
192
+ };
193
+ }
194
+
195
+ export {
196
+ useTableAddRowColumn
197
+ };
@@ -0,0 +1,113 @@
1
+ "use client";
2
+ import {
3
+ useTableAlignCell
4
+ } from "./chunk-KTRZVXJC.mjs";
5
+ import {
6
+ messages
7
+ } from "./chunk-CN73TYHV.mjs";
8
+
9
+ // src/ui/table-alignment-menu.tsx
10
+ import { DropdownMenu } from "@kopexa/dropdown-menu";
11
+ import { useSafeIntl } from "@kopexa/i18n";
12
+ import { AlignLeftIcon, CheckIcon } from "@kopexa/icons";
13
+ import { cn } from "@kopexa/shared-utils";
14
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
+ var TableAlignMenuItems = ({
16
+ index,
17
+ orientation
18
+ }) => {
19
+ const textLeft = useTableAlignCell({
20
+ alignmentType: "text",
21
+ alignment: "left",
22
+ index,
23
+ orientation
24
+ });
25
+ const textCenter = useTableAlignCell({
26
+ alignmentType: "text",
27
+ alignment: "center",
28
+ index,
29
+ orientation
30
+ });
31
+ const textRight = useTableAlignCell({
32
+ alignmentType: "text",
33
+ alignment: "right",
34
+ index,
35
+ orientation
36
+ });
37
+ const verticalTop = useTableAlignCell({
38
+ alignmentType: "vertical",
39
+ alignment: "top",
40
+ index,
41
+ orientation
42
+ });
43
+ const verticalMiddle = useTableAlignCell({
44
+ alignmentType: "vertical",
45
+ alignment: "middle",
46
+ index,
47
+ orientation
48
+ });
49
+ const verticalBottom = useTableAlignCell({
50
+ alignmentType: "vertical",
51
+ alignment: "bottom",
52
+ index,
53
+ orientation
54
+ });
55
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
56
+ /* @__PURE__ */ jsxs(DropdownMenu.Group, { children: [
57
+ /* @__PURE__ */ jsx(AlignMenuItem, { align: textLeft }),
58
+ /* @__PURE__ */ jsx(AlignMenuItem, { align: textCenter }),
59
+ /* @__PURE__ */ jsx(AlignMenuItem, { align: textRight })
60
+ ] }),
61
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
62
+ /* @__PURE__ */ jsxs(DropdownMenu.Group, { children: [
63
+ /* @__PURE__ */ jsx(AlignMenuItem, { align: verticalTop }),
64
+ /* @__PURE__ */ jsx(AlignMenuItem, { align: verticalMiddle }),
65
+ /* @__PURE__ */ jsx(AlignMenuItem, { align: verticalBottom })
66
+ ] })
67
+ ] });
68
+ };
69
+ var TableAlignSubMenu = ({
70
+ index,
71
+ orientation
72
+ }) => {
73
+ const probe = useTableAlignCell({
74
+ alignmentType: "text",
75
+ alignment: "left",
76
+ index,
77
+ orientation
78
+ });
79
+ const intl = useSafeIntl();
80
+ if (!probe.canAlignCell()) return null;
81
+ return /* @__PURE__ */ jsxs(DropdownMenu.Sub, { children: [
82
+ /* @__PURE__ */ jsxs(DropdownMenu.SubTrigger, { children: [
83
+ /* @__PURE__ */ jsx(AlignLeftIcon, {}),
84
+ /* @__PURE__ */ jsx("span", { children: intl.formatMessage(messages.alignment) })
85
+ ] }),
86
+ /* @__PURE__ */ jsx(DropdownMenu.SubContent, { children: /* @__PURE__ */ jsx(TableAlignMenuItems, { index, orientation }) })
87
+ ] });
88
+ };
89
+ var AlignMenuItem = ({
90
+ align
91
+ }) => /* @__PURE__ */ jsxs(
92
+ DropdownMenu.Item,
93
+ {
94
+ disabled: !align.canAlignCell(),
95
+ onSelect: align.handleAlign,
96
+ children: [
97
+ /* @__PURE__ */ jsx(align.Icon, {}),
98
+ /* @__PURE__ */ jsx("span", { children: align.label }),
99
+ /* @__PURE__ */ jsx(
100
+ "span",
101
+ {
102
+ className: cn("ml-auto", align.isActive ? "opacity-100" : "opacity-0"),
103
+ children: /* @__PURE__ */ jsx(CheckIcon, {})
104
+ }
105
+ )
106
+ ]
107
+ }
108
+ );
109
+
110
+ export {
111
+ TableAlignMenuItems,
112
+ TableAlignSubMenu
113
+ };
@@ -0,0 +1,149 @@
1
+ "use client";
2
+ import {
3
+ useTableMergeSplitCell
4
+ } from "./chunk-KIYFW7MP.mjs";
5
+ import {
6
+ TableAlignSubMenu
7
+ } from "./chunk-VQV757EG.mjs";
8
+ import {
9
+ useTableClearRowColumnContent
10
+ } from "./chunk-4QSZXHZO.mjs";
11
+ import {
12
+ messages
13
+ } from "./chunk-CN73TYHV.mjs";
14
+
15
+ // src/ui/table-cell-handle-menu.tsx
16
+ import { DropdownMenu } from "@kopexa/dropdown-menu";
17
+ import { useTiptapEditor } from "@kopexa/editor-utils";
18
+ import { useSafeIntl } from "@kopexa/i18n";
19
+ import { Grip4Icon } from "@kopexa/icons";
20
+ import { cn } from "@kopexa/shared-utils";
21
+ import { tableCellHandleMenu } from "@kopexa/theme";
22
+ import { forwardRef, useCallback, useEffect, useState } from "react";
23
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
24
+ function useTableActions() {
25
+ const mergeCellAction = useTableMergeSplitCell({ action: "merge" });
26
+ const splitCellAction = useTableMergeSplitCell({ action: "split" });
27
+ const clearContentAction = useTableClearRowColumnContent({
28
+ resetAttrs: true
29
+ });
30
+ const mergeAction = {
31
+ icon: mergeCellAction.Icon,
32
+ label: mergeCellAction.label,
33
+ onClick: mergeCellAction.handleExecute,
34
+ isAvailable: mergeCellAction.canExecute
35
+ };
36
+ const splitAction = {
37
+ icon: splitCellAction.Icon,
38
+ label: splitCellAction.label,
39
+ onClick: splitCellAction.handleExecute,
40
+ isAvailable: splitCellAction.canExecute
41
+ };
42
+ const clearAction = {
43
+ icon: clearContentAction.Icon,
44
+ label: clearContentAction.label,
45
+ onClick: clearContentAction.handleClear,
46
+ isAvailable: clearContentAction.canClearRowColumnContent
47
+ };
48
+ return {
49
+ mergeAction,
50
+ splitAction,
51
+ clearAction
52
+ };
53
+ }
54
+ function useTableCellHandleMenu({ editor }) {
55
+ const [isMenuOpen, setIsMenuOpen] = useState(false);
56
+ const closeMenu = useCallback(() => {
57
+ setIsMenuOpen(false);
58
+ editor == null ? void 0 : editor.commands.unfreezeHandles();
59
+ }, [editor]);
60
+ const handleMenuToggle = useCallback(
61
+ (isOpen) => {
62
+ setIsMenuOpen(isOpen);
63
+ if (!editor) return;
64
+ if (isOpen) {
65
+ editor.commands.freezeHandles();
66
+ } else {
67
+ editor.commands.unfreezeHandles();
68
+ }
69
+ },
70
+ [editor]
71
+ );
72
+ return {
73
+ isMenuOpen,
74
+ handleMenuToggle,
75
+ closeMenu
76
+ };
77
+ }
78
+ var TableActionItem = ({ action }) => {
79
+ const {
80
+ icon: Icon,
81
+ label,
82
+ onClick,
83
+ isActive = false,
84
+ shortcutBadge
85
+ } = action;
86
+ return /* @__PURE__ */ jsxs(
87
+ DropdownMenu.Item,
88
+ {
89
+ onClick,
90
+ "data-state": isActive ? "active" : "inactive",
91
+ children: [
92
+ /* @__PURE__ */ jsx(Icon, { className: "tiptap-button-icon" }),
93
+ /* @__PURE__ */ jsx("span", { className: "tiptap-button-text", children: label }),
94
+ shortcutBadge
95
+ ]
96
+ }
97
+ );
98
+ };
99
+ var TableActionMenu = () => {
100
+ const { mergeAction, splitAction, clearAction } = useTableActions();
101
+ const hasMergeOrSplit = mergeAction.isAvailable || splitAction.isAvailable;
102
+ return /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
103
+ hasMergeOrSplit && /* @__PURE__ */ jsxs(Fragment, { children: [
104
+ /* @__PURE__ */ jsxs(DropdownMenu.Group, { children: [
105
+ mergeAction.isAvailable && /* @__PURE__ */ jsx(TableActionItem, { action: mergeAction }),
106
+ splitAction.isAvailable && /* @__PURE__ */ jsx(TableActionItem, { action: splitAction })
107
+ ] }),
108
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {})
109
+ ] }),
110
+ /* @__PURE__ */ jsx(TableAlignSubMenu, {}),
111
+ clearAction.isAvailable && /* @__PURE__ */ jsxs(Fragment, { children: [
112
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
113
+ /* @__PURE__ */ jsx(DropdownMenu.Group, { children: /* @__PURE__ */ jsx(TableActionItem, { action: clearAction }) })
114
+ ] })
115
+ ] });
116
+ };
117
+ var TableCellHandleMenu = forwardRef(({ editor: providedEditor, onOpenChange, className, ...props }, ref) => {
118
+ const { editor } = useTiptapEditor(providedEditor);
119
+ const intl = useSafeIntl();
120
+ const { isMenuOpen, handleMenuToggle } = useTableCellHandleMenu({
121
+ editor
122
+ });
123
+ const styles = tableCellHandleMenu();
124
+ useEffect(() => {
125
+ onOpenChange == null ? void 0 : onOpenChange(isMenuOpen);
126
+ }, [isMenuOpen, onOpenChange]);
127
+ return /* @__PURE__ */ jsxs(DropdownMenu.Root, { open: isMenuOpen, onOpenChange: handleMenuToggle, children: [
128
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
129
+ "button",
130
+ {
131
+ ref,
132
+ "data-open": isMenuOpen,
133
+ className: cn(styles.trigger(), className),
134
+ "aria-label": intl.formatMessage(messages.cell_options),
135
+ "aria-haspopup": "menu",
136
+ "aria-expanded": isMenuOpen,
137
+ ...props,
138
+ children: /* @__PURE__ */ jsx(Grip4Icon, { className: styles.icon() })
139
+ }
140
+ ) }),
141
+ /* @__PURE__ */ jsx(TableActionMenu, {})
142
+ ] });
143
+ });
144
+ TableCellHandleMenu.displayName = "TableCellHandleMenu";
145
+
146
+ export {
147
+ TableActionMenu,
148
+ TableCellHandleMenu
149
+ };
@@ -0,0 +1,134 @@
1
+ "use client";
2
+ import {
3
+ messages
4
+ } from "./chunk-CN73TYHV.mjs";
5
+ import {
6
+ getTable,
7
+ getTableSelectionType,
8
+ selectCellsByCoords
9
+ } from "./chunk-5B5XIL2G.mjs";
10
+
11
+ // src/hooks/use-table-delete-row-column.ts
12
+ import { isExtensionAvailable, useTiptapEditor } from "@kopexa/editor-utils";
13
+ import { useSafeIntl } from "@kopexa/i18n";
14
+ import { TrashIcon } from "@kopexa/icons";
15
+ import { CellSelection, deleteColumn, deleteRow } from "@tiptap/pm/tables";
16
+ import { useCallback, useMemo } from "react";
17
+ var REQUIRED_EXTENSIONS = ["table"];
18
+ var deleteMessageKeys = {
19
+ row: messages.delete_row,
20
+ column: messages.delete_column
21
+ };
22
+ function canDeleteRowColumn({
23
+ editor,
24
+ index,
25
+ orientation,
26
+ tablePos
27
+ }) {
28
+ if (!editor || !editor.isEditable || !isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) {
29
+ return false;
30
+ }
31
+ try {
32
+ const table = getTable(editor, tablePos);
33
+ if (!table) return false;
34
+ const selectionType = getTableSelectionType(editor, index, orientation);
35
+ if (!selectionType) return false;
36
+ return true;
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+ function tableDeleteRowColumn({
42
+ editor,
43
+ index,
44
+ orientation,
45
+ tablePos
46
+ }) {
47
+ if (!canDeleteRowColumn({ editor, index, orientation, tablePos }) || !editor) {
48
+ return false;
49
+ }
50
+ try {
51
+ const selectionType = getTableSelectionType(editor, index, orientation);
52
+ if (!selectionType) return false;
53
+ const { orientation: finalOrientation, index: finalIndex } = selectionType;
54
+ const isRow = finalOrientation === "row";
55
+ const dispatch = (tr) => editor.view.dispatch(tr);
56
+ const deleteOperation = isRow ? deleteRow : deleteColumn;
57
+ if (editor.state.selection instanceof CellSelection) {
58
+ return deleteOperation(editor.state, dispatch);
59
+ }
60
+ const table = getTable(editor, tablePos);
61
+ if (!table) return false;
62
+ const cellCoords = isRow ? { row: finalIndex, col: 0 } : { row: 0, col: finalIndex };
63
+ const cellState = selectCellsByCoords(editor, table.pos, [cellCoords], {
64
+ mode: "state"
65
+ });
66
+ if (!cellState) return false;
67
+ return deleteOperation(cellState, dispatch);
68
+ } catch (error) {
69
+ console.error(`Error deleting table row/column:`, error);
70
+ return false;
71
+ }
72
+ }
73
+ function shouldShowButton({
74
+ editor,
75
+ index,
76
+ orientation,
77
+ hideWhenUnavailable,
78
+ tablePos
79
+ }) {
80
+ if (!editor || !editor.isEditable) return false;
81
+ if (!isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) return false;
82
+ return hideWhenUnavailable ? canDeleteRowColumn({ editor, index, orientation, tablePos }) : true;
83
+ }
84
+ function useTableDeleteRowColumn(config) {
85
+ const {
86
+ editor: providedEditor,
87
+ index,
88
+ orientation,
89
+ tablePos,
90
+ hideWhenUnavailable = false,
91
+ onDeleted
92
+ } = config;
93
+ const { editor } = useTiptapEditor(providedEditor);
94
+ const intl = useSafeIntl();
95
+ const selectionType = getTableSelectionType(editor, index, orientation);
96
+ const isVisible = shouldShowButton({
97
+ editor,
98
+ index,
99
+ orientation,
100
+ hideWhenUnavailable
101
+ });
102
+ const canPerformDelete = canDeleteRowColumn({
103
+ editor,
104
+ index,
105
+ orientation,
106
+ tablePos
107
+ });
108
+ const handleDelete = useCallback(() => {
109
+ const success = tableDeleteRowColumn({
110
+ editor,
111
+ index,
112
+ orientation,
113
+ tablePos
114
+ });
115
+ if (success) onDeleted == null ? void 0 : onDeleted();
116
+ return success;
117
+ }, [editor, index, orientation, tablePos, onDeleted]);
118
+ const label = useMemo(() => {
119
+ return intl.formatMessage(
120
+ deleteMessageKeys[(selectionType == null ? void 0 : selectionType.orientation) || "row"]
121
+ );
122
+ }, [intl, selectionType]);
123
+ return {
124
+ isVisible,
125
+ canDeleteRowColumn: canPerformDelete,
126
+ handleDelete,
127
+ label,
128
+ Icon: TrashIcon
129
+ };
130
+ }
131
+
132
+ export {
133
+ useTableDeleteRowColumn
134
+ };
@@ -1,7 +1,5 @@
1
- import { TableOptions, TableHeaderOptions, TableRowOptions } from '@tiptap/extension-table';
1
+ import { TableOptions, TableCellOptions, TableHeaderOptions, TableRowOptions } from '@tiptap/extension-table';
2
2
  import { Extension } from '@tiptap/react';
3
- import { TableCellOptions } from './table-cell.mjs';
4
- import '@tiptap/core';
5
3
 
6
4
  interface TableKitOptions {
7
5
  /**
@@ -1,7 +1,5 @@
1
- import { TableOptions, TableHeaderOptions, TableRowOptions } from '@tiptap/extension-table';
1
+ import { TableOptions, TableCellOptions, TableHeaderOptions, TableRowOptions } from '@tiptap/extension-table';
2
2
  import { Extension } from '@tiptap/react';
3
- import { TableCellOptions } from './table-cell.js';
4
- import '@tiptap/core';
5
3
 
6
4
  interface TableKitOptions {
7
5
  /**