@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,122 @@
1
+ "use client";
2
+ import {
3
+ messages
4
+ } from "./chunk-CN73TYHV.mjs";
5
+
6
+ // src/hooks/use-table-merge-split-cell.ts
7
+ import { isExtensionAvailable, useTiptapEditor } from "@kopexa/editor-utils";
8
+ import { useSafeIntl } from "@kopexa/i18n";
9
+ import { TableCellMergeIcon, TableCellSplitIcon } from "@kopexa/icons";
10
+ import { mergeCells, splitCell } from "@tiptap/pm/tables";
11
+ import { useCallback } from "react";
12
+ var REQUIRED_EXTENSIONS = ["table"];
13
+ var mergeSplitMessageKeys = {
14
+ merge: messages.merge_cells,
15
+ split: messages.split_cell
16
+ };
17
+ var tableMergeSplitCellIcons = {
18
+ merge: TableCellMergeIcon,
19
+ split: TableCellSplitIcon
20
+ };
21
+ function canMergeCells(editor) {
22
+ if (!editor || !editor.isEditable || !isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) {
23
+ return false;
24
+ }
25
+ try {
26
+ return mergeCells(editor.state, void 0);
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+ function canSplitCell(editor) {
32
+ if (!editor || !editor.isEditable || !isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) {
33
+ return false;
34
+ }
35
+ try {
36
+ return splitCell(editor.state, void 0);
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+ function tableMergeCells(editor) {
42
+ if (!canMergeCells(editor) || !editor) return false;
43
+ try {
44
+ const { state, view } = editor;
45
+ return mergeCells(state, view.dispatch.bind(view));
46
+ } catch (error) {
47
+ console.error("Error merging table cells:", error);
48
+ return false;
49
+ }
50
+ }
51
+ function tableSplitCell(editor) {
52
+ if (!canSplitCell(editor) || !editor) return false;
53
+ try {
54
+ const { state, view } = editor;
55
+ return splitCell(state, view.dispatch.bind(view));
56
+ } catch (error) {
57
+ console.error("Error splitting table cell:", error);
58
+ return false;
59
+ }
60
+ }
61
+ function tableMergeSplitCell({
62
+ editor,
63
+ action
64
+ }) {
65
+ if (!editor) return false;
66
+ try {
67
+ return action === "merge" ? tableMergeCells(editor) : tableSplitCell(editor);
68
+ } catch (error) {
69
+ console.error(`Error ${action}ing table cell:`, error);
70
+ return false;
71
+ }
72
+ }
73
+ function shouldShowButton({
74
+ editor,
75
+ action,
76
+ hideWhenUnavailable
77
+ }) {
78
+ if (!editor || !editor.isEditable) return false;
79
+ if (!isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) return false;
80
+ if (hideWhenUnavailable) {
81
+ return action === "merge" ? canMergeCells(editor) : canSplitCell(editor);
82
+ }
83
+ return true;
84
+ }
85
+ function useTableMergeSplitCell(config) {
86
+ const {
87
+ editor: providedEditor,
88
+ action,
89
+ hideWhenUnavailable = false,
90
+ onExecuted
91
+ } = config;
92
+ const { editor } = useTiptapEditor(providedEditor);
93
+ const intl = useSafeIntl();
94
+ const isVisible = shouldShowButton({
95
+ editor,
96
+ action,
97
+ hideWhenUnavailable
98
+ });
99
+ const canPerformAction = action === "merge" ? canMergeCells(editor) : canSplitCell(editor);
100
+ const handleExecute = useCallback(() => {
101
+ const success = tableMergeSplitCell({
102
+ editor,
103
+ action
104
+ });
105
+ if (success) {
106
+ onExecuted == null ? void 0 : onExecuted(action);
107
+ }
108
+ return success;
109
+ }, [editor, action, onExecuted]);
110
+ return {
111
+ isVisible,
112
+ canExecute: canPerformAction,
113
+ handleExecute,
114
+ label: intl.formatMessage(mergeSplitMessageKeys[action]),
115
+ Icon: tableMergeSplitCellIcons[action]
116
+ };
117
+ }
118
+
119
+ export {
120
+ tableMergeSplitCellIcons,
121
+ useTableMergeSplitCell
122
+ };
@@ -0,0 +1,306 @@
1
+ "use client";
2
+ import {
3
+ messages
4
+ } from "./chunk-CN73TYHV.mjs";
5
+ import {
6
+ getRowOrColumnCells,
7
+ getTable
8
+ } from "./chunk-5B5XIL2G.mjs";
9
+
10
+ // src/hooks/use-table-align-cell.ts
11
+ import { isExtensionAvailable, useTiptapEditor } from "@kopexa/editor-utils";
12
+ import { useSafeIntl } from "@kopexa/i18n";
13
+ import {
14
+ AlignBottomIcon,
15
+ AlignCenterIcon,
16
+ AlignJustifyIcon,
17
+ AlignLeftIcon,
18
+ AlignMiddleIcon,
19
+ AlignRightIcon,
20
+ AlignTopIcon
21
+ } from "@kopexa/icons";
22
+ import { useCallback, useMemo } from "react";
23
+ var REQUIRED_EXTENSIONS = ["table"];
24
+ var textAlignmentMessageKeys = {
25
+ left: messages.align_left,
26
+ center: messages.align_center,
27
+ right: messages.align_right,
28
+ justify: messages.justify
29
+ };
30
+ var verticalAlignmentMessageKeys = {
31
+ top: messages.align_top,
32
+ middle: messages.align_middle,
33
+ bottom: messages.align_bottom
34
+ };
35
+ var tableAlignCellIcons = {
36
+ text: {
37
+ left: AlignLeftIcon,
38
+ center: AlignCenterIcon,
39
+ right: AlignRightIcon,
40
+ justify: AlignJustifyIcon
41
+ },
42
+ vertical: {
43
+ top: AlignTopIcon,
44
+ middle: AlignMiddleIcon,
45
+ bottom: AlignBottomIcon
46
+ }
47
+ };
48
+ function canAlignCell(editor) {
49
+ if (!editor || !editor.isEditable || !isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) {
50
+ return false;
51
+ }
52
+ try {
53
+ return editor.isActive("tableCell") || editor.isActive("tableHeader");
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+ function canAlignRowColumn({
59
+ editor,
60
+ index,
61
+ orientation
62
+ }) {
63
+ if (!editor || !editor.isEditable || !isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) {
64
+ return false;
65
+ }
66
+ try {
67
+ const table = getTable(editor);
68
+ if (!table) return false;
69
+ const cellData = getRowOrColumnCells(editor, index, orientation);
70
+ if (cellData.cells.length === 0) return false;
71
+ return true;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+ function getCurrentAlignment(editor, alignmentType) {
77
+ if (!canAlignCell(editor) || !editor) return null;
78
+ try {
79
+ const { selection } = editor.state;
80
+ const $anchor = selection.$anchor;
81
+ let cellNode = null;
82
+ for (let depth = $anchor.depth; depth >= 0; depth--) {
83
+ const node = $anchor.node(depth);
84
+ if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
85
+ cellNode = node;
86
+ break;
87
+ }
88
+ }
89
+ if (!cellNode) return null;
90
+ const attrs = cellNode.attrs || {};
91
+ if (alignmentType === "text") {
92
+ return attrs.nodeTextAlign || "left";
93
+ } else {
94
+ return attrs.nodeVerticalAlign || "top";
95
+ }
96
+ } catch {
97
+ return null;
98
+ }
99
+ }
100
+ function getCurrentRowColumnAlignment(editor, alignmentType, index, orientation) {
101
+ if (!editor) return null;
102
+ try {
103
+ const cellData = getRowOrColumnCells(editor, index, orientation);
104
+ if (cellData.cells.length === 0) return null;
105
+ const firstCell = cellData.cells[0];
106
+ if (!(firstCell == null ? void 0 : firstCell.node)) return null;
107
+ const attrs = firstCell.node.attrs || {};
108
+ if (alignmentType === "text") {
109
+ return attrs.nodeTextAlign || "left";
110
+ } else {
111
+ return attrs.nodeVerticalAlign || "top";
112
+ }
113
+ } catch {
114
+ return null;
115
+ }
116
+ }
117
+ function setTableCellAlignment(editor, alignmentType, alignment) {
118
+ if (!canAlignCell(editor) || !editor) return false;
119
+ try {
120
+ if (alignmentType === "text") {
121
+ return editor.commands.setCellAttribute("nodeTextAlign", alignment);
122
+ } else {
123
+ return editor.commands.setCellAttribute("nodeVerticalAlign", alignment);
124
+ }
125
+ } catch (error) {
126
+ console.error("Error setting table cell alignment:", error);
127
+ return false;
128
+ }
129
+ }
130
+ function setRowColumnAlignment({
131
+ editor,
132
+ alignmentType,
133
+ alignment,
134
+ index,
135
+ orientation
136
+ }) {
137
+ if (!canAlignRowColumn({ editor, index, orientation }) || !editor) {
138
+ return false;
139
+ }
140
+ try {
141
+ const { state, view } = editor;
142
+ const tr = state.tr;
143
+ const cellData = getRowOrColumnCells(editor, index, orientation);
144
+ if (cellData.cells.length === 0) {
145
+ return false;
146
+ }
147
+ const uniqueCells = /* @__PURE__ */ new Map();
148
+ cellData.cells.forEach((cellInfo) => {
149
+ if (cellInfo.node && cellInfo.pos !== void 0) {
150
+ uniqueCells.set(cellInfo.pos, cellInfo);
151
+ }
152
+ });
153
+ if (uniqueCells.size === 0) {
154
+ return false;
155
+ }
156
+ const cellsToProcess = Array.from(uniqueCells.values()).sort(
157
+ (a, b) => b.pos - a.pos
158
+ );
159
+ const attributeName = alignmentType === "text" ? "nodeTextAlign" : "nodeVerticalAlign";
160
+ cellsToProcess.forEach((cellInfo) => {
161
+ if (cellInfo.node && cellInfo.pos !== void 0) {
162
+ const cellType = cellInfo.node.type;
163
+ const newCellNode = cellType.create(
164
+ {
165
+ ...cellInfo.node.attrs,
166
+ [attributeName]: alignment
167
+ },
168
+ cellInfo.node.content,
169
+ cellInfo.node.marks
170
+ );
171
+ const cellEnd = cellInfo.pos + cellInfo.node.nodeSize;
172
+ tr.replaceWith(cellInfo.pos, cellEnd, newCellNode);
173
+ }
174
+ });
175
+ if (tr.docChanged) {
176
+ view.dispatch(tr);
177
+ return true;
178
+ }
179
+ return false;
180
+ } catch (error) {
181
+ console.error(`Error aligning table ${orientation}:`, error);
182
+ return false;
183
+ }
184
+ }
185
+ function tableAlignCell({
186
+ editor,
187
+ alignmentType,
188
+ alignment,
189
+ index,
190
+ orientation
191
+ }) {
192
+ if (!editor) return false;
193
+ try {
194
+ if (typeof index === "number" && orientation) {
195
+ return setRowColumnAlignment({
196
+ editor,
197
+ alignmentType,
198
+ alignment,
199
+ index,
200
+ orientation
201
+ });
202
+ } else {
203
+ return setTableCellAlignment(editor, alignmentType, alignment);
204
+ }
205
+ } catch (error) {
206
+ console.error("Error aligning table cell:", error);
207
+ return false;
208
+ }
209
+ }
210
+ function shouldShowButton({
211
+ editor,
212
+ hideWhenUnavailable,
213
+ index,
214
+ orientation
215
+ }) {
216
+ if (!editor || !editor.isEditable) return false;
217
+ if (!isExtensionAvailable(editor, REQUIRED_EXTENSIONS)) return false;
218
+ if (hideWhenUnavailable) {
219
+ if (typeof index === "number" && orientation) {
220
+ return canAlignRowColumn({ editor, index, orientation });
221
+ }
222
+ return canAlignCell(editor);
223
+ }
224
+ return true;
225
+ }
226
+ function useTableAlignCell(config) {
227
+ const {
228
+ editor: providedEditor,
229
+ alignmentType,
230
+ alignment,
231
+ index,
232
+ orientation,
233
+ hideWhenUnavailable = false,
234
+ onAligned
235
+ } = config;
236
+ const { editor } = useTiptapEditor(providedEditor);
237
+ const intl = useSafeIntl();
238
+ const isVisible = shouldShowButton({
239
+ editor,
240
+ hideWhenUnavailable,
241
+ index,
242
+ orientation
243
+ });
244
+ const canPerformAlign = useCallback(() => {
245
+ if (typeof index === "number" && orientation) {
246
+ return canAlignRowColumn({ editor, index, orientation });
247
+ }
248
+ return canAlignCell(editor);
249
+ }, [editor, index, orientation]);
250
+ const currentAlignmentValue = useMemo(() => {
251
+ if (typeof index === "number" && orientation) {
252
+ return getCurrentRowColumnAlignment(
253
+ editor,
254
+ alignmentType,
255
+ index,
256
+ orientation
257
+ );
258
+ }
259
+ return getCurrentAlignment(editor, alignmentType);
260
+ }, [editor, alignmentType, index, orientation]);
261
+ const isActive = currentAlignmentValue === alignment;
262
+ const handleAlign = useCallback(() => {
263
+ const success = tableAlignCell({
264
+ editor,
265
+ alignmentType,
266
+ alignment,
267
+ index,
268
+ orientation
269
+ });
270
+ if (success) {
271
+ onAligned == null ? void 0 : onAligned(alignment);
272
+ }
273
+ return success;
274
+ }, [editor, alignmentType, alignment, index, orientation, onAligned]);
275
+ const label = useMemo(() => {
276
+ if (alignmentType === "text") {
277
+ return intl.formatMessage(
278
+ textAlignmentMessageKeys[alignment]
279
+ );
280
+ }
281
+ return intl.formatMessage(
282
+ verticalAlignmentMessageKeys[alignment]
283
+ );
284
+ }, [intl, alignmentType, alignment]);
285
+ const Icon = useMemo(() => {
286
+ if (alignmentType === "text") {
287
+ return tableAlignCellIcons.text[alignment];
288
+ } else {
289
+ return tableAlignCellIcons.vertical[alignment];
290
+ }
291
+ }, [alignmentType, alignment]);
292
+ return {
293
+ isVisible,
294
+ canAlignCell: canPerformAlign,
295
+ handleAlign,
296
+ label,
297
+ Icon,
298
+ isActive,
299
+ currentAlignment: currentAlignmentValue
300
+ };
301
+ }
302
+
303
+ export {
304
+ tableAlignCellIcons,
305
+ useTableAlignCell
306
+ };
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import {
3
+ TableHandlePlugin,
4
+ tableHandlePluginKey
5
+ } from "./chunk-3SWV7BGP.mjs";
6
+
7
+ // src/extensions/table-handle.ts
8
+ import { Extension } from "@tiptap/core";
9
+ var TableHandleExtension = Extension.create({
10
+ name: "tableHandleExtension",
11
+ addCommands() {
12
+ return {
13
+ freezeHandles: () => ({ tr, dispatch }) => {
14
+ if (dispatch) tr.setMeta(tableHandlePluginKey, true);
15
+ return true;
16
+ },
17
+ unfreezeHandles: () => ({ tr, dispatch }) => {
18
+ if (dispatch) tr.setMeta(tableHandlePluginKey, false);
19
+ return true;
20
+ }
21
+ };
22
+ },
23
+ addProseMirrorPlugins() {
24
+ const { editor } = this;
25
+ return [
26
+ TableHandlePlugin(editor, (state) => {
27
+ this.editor.emit("tableHandleState", state);
28
+ })
29
+ ];
30
+ }
31
+ });
32
+
33
+ export {
34
+ TableHandleExtension
35
+ };
@@ -1,24 +1,23 @@
1
1
  "use client";
2
2
  import {
3
3
  TableCell
4
- } from "./chunk-DR2GZJH6.mjs";
4
+ } from "./chunk-E7W2KRZG.mjs";
5
5
  import {
6
- TableHeader
7
- } from "./chunk-POJFNXG7.mjs";
8
- import {
9
- TableRow
10
- } from "./chunk-HWVA6DOK.mjs";
6
+ TableHandleExtension
7
+ } from "./chunk-LUA32VH4.mjs";
11
8
  import {
12
9
  Table
13
- } from "./chunk-LPHCE6EI.mjs";
10
+ } from "./chunk-IRJ6RAVQ.mjs";
14
11
 
15
- // src/kit.ts
12
+ // src/extensions/kit.ts
13
+ import { TableHeader, TableRow } from "@tiptap/extension-table";
16
14
  import { Extension } from "@tiptap/react";
17
15
  var TableKit = Extension.create({
18
16
  name: "tableKit",
19
17
  addExtensions() {
20
18
  const extensions = [];
21
19
  if (this.options.table !== false) {
20
+ extensions.push(TableHandleExtension);
22
21
  extensions.push(Table.configure(this.options.table));
23
22
  }
24
23
  if (this.options.tableCell !== false) {
@@ -0,0 +1,10 @@
1
+ "use client";
2
+
3
+ // src/lib/constants.ts
4
+ var EMPTY_CELL_WIDTH = 120;
5
+ var RESIZE_MIN_WIDTH = 35;
6
+
7
+ export {
8
+ EMPTY_CELL_WIDTH,
9
+ RESIZE_MIN_WIDTH
10
+ };
@@ -0,0 +1,96 @@
1
+ "use client";
2
+ import {
3
+ TableHandleMenu
4
+ } from "./chunk-62B2LU2Q.mjs";
5
+ import {
6
+ useTableHandlePositioning
7
+ } from "./chunk-GBTQVIN5.mjs";
8
+ import {
9
+ useTableHandleState
10
+ } from "./chunk-GDEXPEW5.mjs";
11
+ import {
12
+ colDragStart,
13
+ rowDragStart
14
+ } from "./chunk-3SWV7BGP.mjs";
15
+
16
+ // src/ui/table-handle.tsx
17
+ import { FloatingPortal } from "@floating-ui/react";
18
+ import { useTiptapEditor } from "@kopexa/editor-utils";
19
+ import { useCallback, useMemo, useState } from "react";
20
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+ function TableHandle({
22
+ editor: providedEditor,
23
+ rowButton: CustomRowButton,
24
+ columnButton: CustomColumnButton
25
+ }) {
26
+ const { editor } = useTiptapEditor(providedEditor);
27
+ const state = useTableHandleState({ editor });
28
+ const [isRowVisible, setIsRowVisible] = useState(true);
29
+ const [isColumnVisible, setIsColumnVisible] = useState(true);
30
+ const [menuOpen, setMenuOpen] = useState(null);
31
+ const draggingState = useMemo(() => {
32
+ if (!(state == null ? void 0 : state.draggingState)) return void 0;
33
+ return {
34
+ draggedCellOrientation: state.draggingState.draggedCellOrientation,
35
+ mousePos: state.draggingState.mousePos,
36
+ initialOffset: state.draggingState.initialOffset
37
+ };
38
+ }, [state == null ? void 0 : state.draggingState]);
39
+ const { rowHandle, colHandle } = useTableHandlePositioning(
40
+ (state == null ? void 0 : state.show) || false,
41
+ (state == null ? void 0 : state.referencePosCell) || null,
42
+ (state == null ? void 0 : state.referencePosTable) || null,
43
+ draggingState
44
+ );
45
+ const toggleRowVisibility = useCallback((visible) => {
46
+ setIsRowVisible(visible);
47
+ }, []);
48
+ const toggleColumnVisibility = useCallback((visible) => {
49
+ setIsColumnVisible(visible);
50
+ }, []);
51
+ const handleMenuOpenChange = useCallback(
52
+ (type, open) => {
53
+ setMenuOpen(open ? type : null);
54
+ },
55
+ []
56
+ );
57
+ if (!editor || !state) return null;
58
+ const hasValidRowIndex = typeof state.rowIndex === "number";
59
+ const hasValidColIndex = typeof state.colIndex === "number";
60
+ const shouldShowRow = isRowVisible && rowHandle.isMounted && hasValidRowIndex || menuOpen === "row";
61
+ const shouldShowColumn = isColumnVisible && colHandle.isMounted && hasValidColIndex || menuOpen === "column";
62
+ const RowButton = CustomRowButton || TableHandleMenu;
63
+ const ColumnButton = CustomColumnButton || TableHandleMenu;
64
+ return /* @__PURE__ */ jsxs(FloatingPortal, { root: state.widgetContainer, children: [
65
+ shouldShowRow && /* @__PURE__ */ jsx("div", { ref: rowHandle.ref, style: rowHandle.style, children: /* @__PURE__ */ jsx(
66
+ RowButton,
67
+ {
68
+ editor,
69
+ orientation: "row",
70
+ index: state.rowIndex,
71
+ tablePos: state.blockPos,
72
+ tableNode: state.block,
73
+ onToggleOtherHandle: toggleColumnVisibility,
74
+ dragStart: (e) => rowDragStart(editor, e),
75
+ onOpenChange: (open) => handleMenuOpenChange("row", open)
76
+ }
77
+ ) }),
78
+ shouldShowColumn && /* @__PURE__ */ jsx("div", { ref: colHandle.ref, style: colHandle.style, children: /* @__PURE__ */ jsx(
79
+ ColumnButton,
80
+ {
81
+ editor,
82
+ orientation: "column",
83
+ index: state.colIndex,
84
+ tablePos: state.blockPos,
85
+ tableNode: state.block,
86
+ onToggleOtherHandle: toggleRowVisibility,
87
+ dragStart: (e) => colDragStart(editor, e),
88
+ onOpenChange: (open) => handleMenuOpenChange("column", open)
89
+ }
90
+ ) })
91
+ ] });
92
+ }
93
+
94
+ export {
95
+ TableHandle
96
+ };