@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,603 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/hooks/use-table-header-row-column.ts
23
+ var use_table_header_row_column_exports = {};
24
+ __export(use_table_header_row_column_exports, {
25
+ tableHeaderRowColumnIcons: () => tableHeaderRowColumnIcons,
26
+ useTableHeaderRowColumn: () => useTableHeaderRowColumn
27
+ });
28
+ module.exports = __toCommonJS(use_table_header_row_column_exports);
29
+ var import_editor_utils = require("@kopexa/editor-utils");
30
+ var import_i18n2 = require("@kopexa/i18n");
31
+ var import_icons = require("@kopexa/icons");
32
+ var import_tables2 = require("@tiptap/pm/tables");
33
+ var import_react = require("react");
34
+
35
+ // src/lib/table-utils.ts
36
+ var import_shared_utils = require("@kopexa/shared-utils");
37
+ var import_tables = require("@tiptap/pm/tables");
38
+ var EMPTY_CELLS_RESULT = { cells: [], mergedCells: [] };
39
+ function collectCells(editor, orientation, index, tablePos) {
40
+ if (!editor) return EMPTY_CELLS_RESULT;
41
+ const { state } = editor;
42
+ const table = getTable(editor, tablePos);
43
+ if (!table) return EMPTY_CELLS_RESULT;
44
+ const tableStart = table.start;
45
+ const tableNode = table.node;
46
+ const map = table.map;
47
+ const resolvedIndex = resolveOrientationIndex(
48
+ state,
49
+ table,
50
+ orientation,
51
+ index
52
+ );
53
+ if (resolvedIndex === null) return EMPTY_CELLS_RESULT;
54
+ const maxIndex = orientation === "row" ? map.height : map.width;
55
+ if (resolvedIndex < 0 || resolvedIndex >= maxIndex) {
56
+ return EMPTY_CELLS_RESULT;
57
+ }
58
+ const cells = [];
59
+ const mergedCells = [];
60
+ const seenMerged = /* @__PURE__ */ new Set();
61
+ const iterationCount = orientation === "row" ? map.width : map.height;
62
+ for (let i = 0; i < iterationCount; i++) {
63
+ const row = orientation === "row" ? resolvedIndex : i;
64
+ const col = orientation === "row" ? i : resolvedIndex;
65
+ const cellIndex = row * map.width + col;
66
+ const mapCell = map.map[cellIndex];
67
+ if (mapCell === void 0) continue;
68
+ const cellPos = tableStart + mapCell;
69
+ const cellNode = tableNode.nodeAt(mapCell);
70
+ if (!cellNode) continue;
71
+ const cell = createCellInfo(row, col, cellPos, cellNode);
72
+ if (isCellMerged(cellNode)) {
73
+ if (!seenMerged.has(cellPos)) {
74
+ mergedCells.push(cell);
75
+ seenMerged.add(cellPos);
76
+ }
77
+ }
78
+ cells.push(cell);
79
+ }
80
+ return { cells, mergedCells };
81
+ }
82
+ function isCellMerged(node) {
83
+ var _a, _b;
84
+ if (!node) return false;
85
+ const colspan = (_a = node.attrs.colspan) != null ? _a : 1;
86
+ const rowspan = (_b = node.attrs.rowspan) != null ? _b : 1;
87
+ return colspan > 1 || rowspan > 1;
88
+ }
89
+ function getTable(editor, tablePos) {
90
+ if (!editor) return null;
91
+ let table = null;
92
+ if (typeof tablePos === "number") {
93
+ const tableNode = editor.state.doc.nodeAt(tablePos);
94
+ if ((tableNode == null ? void 0 : tableNode.type.name) === "table") {
95
+ table = {
96
+ node: tableNode,
97
+ pos: tablePos,
98
+ start: tablePos + 1,
99
+ depth: editor.state.doc.resolve(tablePos).depth
100
+ };
101
+ }
102
+ }
103
+ if (!table) {
104
+ const { state } = editor;
105
+ const $from = state.doc.resolve(state.selection.from);
106
+ table = (0, import_tables.findTable)($from);
107
+ }
108
+ if (!table) return null;
109
+ const tableMap = import_tables.TableMap.get(table.node);
110
+ if (!tableMap) return null;
111
+ return { ...table, map: tableMap };
112
+ }
113
+ function createCellInfo(row, column, cellPos, cellNode) {
114
+ return {
115
+ row,
116
+ column,
117
+ pos: cellPos,
118
+ node: cellNode,
119
+ start: cellPos + 1,
120
+ depth: cellNode ? cellNode.content.size : 0
121
+ };
122
+ }
123
+ function resolveOrientationIndex(state, table, orientation, providedIndex) {
124
+ var _a;
125
+ if (typeof providedIndex === "number") {
126
+ return providedIndex;
127
+ }
128
+ if (state.selection instanceof import_tables.CellSelection) {
129
+ const rect2 = (0, import_tables.selectedRect)(state);
130
+ return orientation === "row" ? rect2.top : rect2.left;
131
+ }
132
+ const $cell = (_a = (0, import_tables.cellAround)(state.selection.$anchor)) != null ? _a : (0, import_tables.selectionCell)(state);
133
+ if (!$cell) return null;
134
+ const rel = $cell.pos - table.start;
135
+ const rect = table.map.findCell(rel);
136
+ return orientation === "row" ? rect.top : rect.left;
137
+ }
138
+ function getIndexCoordinates({
139
+ editor,
140
+ index,
141
+ orientation,
142
+ tablePos
143
+ }) {
144
+ if (!editor) return null;
145
+ const table = getTable(editor, tablePos);
146
+ if (!table) return null;
147
+ const { map } = table;
148
+ const { width, height } = map;
149
+ if (index < 0) return null;
150
+ if (orientation === "row" && index >= height) return null;
151
+ if (orientation === "column" && index >= width) return null;
152
+ return orientation === "row" ? Array.from({ length: map.width }, (_, col) => ({ row: index, col })) : Array.from({ length: map.height }, (_, row) => ({ row, col: index }));
153
+ }
154
+ function selectCellsByCoords(editor, tablePos, coords, options = { mode: "state" }) {
155
+ if (!editor) return;
156
+ const table = getTable(editor, tablePos);
157
+ if (!table) return;
158
+ const { state } = editor;
159
+ const tableMap = table.map;
160
+ const cleanedCoords = coords.map((coord) => ({
161
+ row: (0, import_shared_utils.clamp)(coord.row, 0, tableMap.height - 1),
162
+ col: (0, import_shared_utils.clamp)(coord.col, 0, tableMap.width - 1)
163
+ })).filter((coord) => isWithinBounds(coord.row, coord.col, tableMap));
164
+ if (cleanedCoords.length === 0) {
165
+ return;
166
+ }
167
+ const allRows = cleanedCoords.map((coord) => coord.row);
168
+ const topRow = Math.min(...allRows);
169
+ const bottomRow = Math.max(...allRows);
170
+ const allCols = cleanedCoords.map((coord) => coord.col);
171
+ const leftCol = Math.min(...allCols);
172
+ const rightCol = Math.max(...allCols);
173
+ const getCellPositionFromMap = (row, col) => {
174
+ const cellOffset = tableMap.map[row * tableMap.width + col];
175
+ if (cellOffset === void 0) return null;
176
+ return tablePos + 1 + cellOffset;
177
+ };
178
+ const anchorPosition = getCellPositionFromMap(topRow, leftCol);
179
+ if (anchorPosition === null) return;
180
+ let headPosition = getCellPositionFromMap(bottomRow, rightCol);
181
+ if (headPosition === null) return;
182
+ if (headPosition === anchorPosition) {
183
+ let foundDifferentCell = false;
184
+ for (let row = bottomRow; row >= topRow && !foundDifferentCell; row--) {
185
+ for (let col = rightCol; col >= leftCol && !foundDifferentCell; col--) {
186
+ const candidatePosition = getCellPositionFromMap(row, col);
187
+ if (candidatePosition !== null && candidatePosition !== anchorPosition) {
188
+ headPosition = candidatePosition;
189
+ foundDifferentCell = true;
190
+ }
191
+ }
192
+ }
193
+ }
194
+ try {
195
+ const anchorRef = state.doc.resolve(anchorPosition);
196
+ const headRef = state.doc.resolve(headPosition);
197
+ const cellSelection = new import_tables.CellSelection(anchorRef, headRef);
198
+ const transaction = state.tr.setSelection(cellSelection);
199
+ return applySelectionWithMode(state, transaction, options);
200
+ } catch (error) {
201
+ console.error("Failed to create cell selection:", error);
202
+ return;
203
+ }
204
+ }
205
+ function isWithinBounds(row, col, map) {
206
+ return row >= 0 && row < map.height && col >= 0 && col < map.width;
207
+ }
208
+ function applySelectionWithMode(state, transaction, options) {
209
+ var _a;
210
+ const mode = (_a = options.mode) != null ? _a : "state";
211
+ switch (mode) {
212
+ case "dispatch": {
213
+ const dispatchOptions = options;
214
+ if (typeof dispatchOptions.dispatch === "function") {
215
+ dispatchOptions.dispatch(transaction);
216
+ }
217
+ return;
218
+ }
219
+ case "transaction":
220
+ return transaction;
221
+ default:
222
+ return state.apply(transaction);
223
+ }
224
+ }
225
+ function getTableSelectionType(editor, index, orientation, tablePos) {
226
+ if (typeof index === "number" && orientation) {
227
+ return { orientation, index };
228
+ }
229
+ if (!editor) return null;
230
+ const { state } = editor;
231
+ const table = getTable(editor, tablePos);
232
+ if (!table) return null;
233
+ if (state.selection instanceof import_tables.CellSelection) {
234
+ const rect = (0, import_tables.selectedRect)(state);
235
+ const map = import_tables.TableMap.get(table.node);
236
+ const width = rect.right - rect.left;
237
+ const height = rect.bottom - rect.top;
238
+ if (height === 1 && width === map.width) {
239
+ return { orientation: "row", index: rect.top };
240
+ }
241
+ if (width === 1 && height === map.height) {
242
+ return { orientation: "column", index: rect.left };
243
+ }
244
+ return null;
245
+ }
246
+ return null;
247
+ }
248
+ function getRowOrColumnCells(editor, index, orientation, tablePos) {
249
+ const emptyResult = {
250
+ cells: [],
251
+ mergedCells: [],
252
+ index: void 0,
253
+ orientation: void 0,
254
+ tablePos: void 0
255
+ };
256
+ if (!editor) {
257
+ return emptyResult;
258
+ }
259
+ if (typeof index !== "number" && !(editor.state.selection instanceof import_tables.CellSelection)) {
260
+ return emptyResult;
261
+ }
262
+ let finalIndex = index;
263
+ let finalOrientation = orientation;
264
+ if (typeof finalIndex !== "number" || !finalOrientation || !["row", "column"].includes(finalOrientation)) {
265
+ const selectionType = getTableSelectionType(editor);
266
+ if (!selectionType) return emptyResult;
267
+ finalIndex = selectionType.index;
268
+ finalOrientation = selectionType.orientation;
269
+ }
270
+ const result = collectCells(editor, finalOrientation, finalIndex, tablePos);
271
+ return { ...result, index: finalIndex, orientation: finalOrientation };
272
+ }
273
+
274
+ // src/messages.ts
275
+ var import_i18n = require("@kopexa/i18n");
276
+ var messages = (0, import_i18n.defineMessages)({
277
+ // Row/Column actions (aria labels)
278
+ row_actions: {
279
+ id: "editor.table.row_actions",
280
+ defaultMessage: "Row actions",
281
+ description: "ARIA label for row actions menu button"
282
+ },
283
+ column_actions: {
284
+ id: "editor.table.column_actions",
285
+ defaultMessage: "Column actions",
286
+ description: "ARIA label for column actions menu button"
287
+ },
288
+ cell_options: {
289
+ id: "editor.table.cell_options",
290
+ defaultMessage: "Table cells option",
291
+ description: "ARIA label for cell options menu button"
292
+ },
293
+ // Alignment
294
+ alignment: {
295
+ id: "editor.table.alignment",
296
+ defaultMessage: "Alignment",
297
+ description: "Label for alignment submenu"
298
+ },
299
+ align_left: {
300
+ id: "editor.table.align_left",
301
+ defaultMessage: "Align left",
302
+ description: "Label for align left action"
303
+ },
304
+ align_center: {
305
+ id: "editor.table.align_center",
306
+ defaultMessage: "Align center",
307
+ description: "Label for align center action"
308
+ },
309
+ align_right: {
310
+ id: "editor.table.align_right",
311
+ defaultMessage: "Align right",
312
+ description: "Label for align right action"
313
+ },
314
+ justify: {
315
+ id: "editor.table.justify",
316
+ defaultMessage: "Justify",
317
+ description: "Label for justify action"
318
+ },
319
+ align_top: {
320
+ id: "editor.table.align_top",
321
+ defaultMessage: "Align top",
322
+ description: "Label for vertical align top action"
323
+ },
324
+ align_middle: {
325
+ id: "editor.table.align_middle",
326
+ defaultMessage: "Align middle",
327
+ description: "Label for vertical align middle action"
328
+ },
329
+ align_bottom: {
330
+ id: "editor.table.align_bottom",
331
+ defaultMessage: "Align bottom",
332
+ description: "Label for vertical align bottom action"
333
+ },
334
+ // Add row/column
335
+ insert_row_above: {
336
+ id: "editor.table.insert_row_above",
337
+ defaultMessage: "Insert row above",
338
+ description: "Label for insert row above action"
339
+ },
340
+ insert_row_below: {
341
+ id: "editor.table.insert_row_below",
342
+ defaultMessage: "Insert row below",
343
+ description: "Label for insert row below action"
344
+ },
345
+ insert_column_left: {
346
+ id: "editor.table.insert_column_left",
347
+ defaultMessage: "Insert column left",
348
+ description: "Label for insert column left action"
349
+ },
350
+ insert_column_right: {
351
+ id: "editor.table.insert_column_right",
352
+ defaultMessage: "Insert column right",
353
+ description: "Label for insert column right action"
354
+ },
355
+ // Delete row/column
356
+ delete_row: {
357
+ id: "editor.table.delete_row",
358
+ defaultMessage: "Delete row",
359
+ description: "Label for delete row action"
360
+ },
361
+ delete_column: {
362
+ id: "editor.table.delete_column",
363
+ defaultMessage: "Delete column",
364
+ description: "Label for delete column action"
365
+ },
366
+ // Move row/column
367
+ move_row_up: {
368
+ id: "editor.table.move_row_up",
369
+ defaultMessage: "Move row up",
370
+ description: "Label for move row up action"
371
+ },
372
+ move_row_down: {
373
+ id: "editor.table.move_row_down",
374
+ defaultMessage: "Move row down",
375
+ description: "Label for move row down action"
376
+ },
377
+ move_column_left: {
378
+ id: "editor.table.move_column_left",
379
+ defaultMessage: "Move column left",
380
+ description: "Label for move column left action"
381
+ },
382
+ move_column_right: {
383
+ id: "editor.table.move_column_right",
384
+ defaultMessage: "Move column right",
385
+ description: "Label for move column right action"
386
+ },
387
+ // Sort
388
+ sort_row_asc: {
389
+ id: "editor.table.sort_row_asc",
390
+ defaultMessage: "Sort row A-Z",
391
+ description: "Label for sort row ascending action"
392
+ },
393
+ sort_row_desc: {
394
+ id: "editor.table.sort_row_desc",
395
+ defaultMessage: "Sort row Z-A",
396
+ description: "Label for sort row descending action"
397
+ },
398
+ sort_column_asc: {
399
+ id: "editor.table.sort_column_asc",
400
+ defaultMessage: "Sort column A-Z",
401
+ description: "Label for sort column ascending action"
402
+ },
403
+ sort_column_desc: {
404
+ id: "editor.table.sort_column_desc",
405
+ defaultMessage: "Sort column Z-A",
406
+ description: "Label for sort column descending action"
407
+ },
408
+ // Duplicate
409
+ duplicate_row: {
410
+ id: "editor.table.duplicate_row",
411
+ defaultMessage: "Duplicate row",
412
+ description: "Label for duplicate row action"
413
+ },
414
+ duplicate_column: {
415
+ id: "editor.table.duplicate_column",
416
+ defaultMessage: "Duplicate column",
417
+ description: "Label for duplicate column action"
418
+ },
419
+ // Header
420
+ header_row: {
421
+ id: "editor.table.header_row",
422
+ defaultMessage: "Header row",
423
+ description: "Label for toggle header row action"
424
+ },
425
+ header_column: {
426
+ id: "editor.table.header_column",
427
+ defaultMessage: "Header column",
428
+ description: "Label for toggle header column action"
429
+ },
430
+ // Merge/Split
431
+ merge_cells: {
432
+ id: "editor.table.merge_cells",
433
+ defaultMessage: "Merge cells",
434
+ description: "Label for merge cells action"
435
+ },
436
+ split_cell: {
437
+ id: "editor.table.split_cell",
438
+ defaultMessage: "Split cell",
439
+ description: "Label for split cell action"
440
+ },
441
+ // Clear contents
442
+ clear_row_contents: {
443
+ id: "editor.table.clear_row_contents",
444
+ defaultMessage: "Clear row contents",
445
+ description: "Label for clear row contents action"
446
+ },
447
+ clear_column_contents: {
448
+ id: "editor.table.clear_column_contents",
449
+ defaultMessage: "Clear column contents",
450
+ description: "Label for clear column contents action"
451
+ },
452
+ clear_contents: {
453
+ id: "editor.table.clear_contents",
454
+ defaultMessage: "Clear contents",
455
+ description: "Label for clear contents action (generic)"
456
+ }
457
+ });
458
+
459
+ // src/hooks/use-table-header-row-column.ts
460
+ var REQUIRED_EXTENSIONS = ["table"];
461
+ var headerMessageKeys = {
462
+ row: messages.header_row,
463
+ column: messages.header_column
464
+ };
465
+ var tableHeaderRowColumnIcons = {
466
+ row: import_icons.TableHeaderRowIcon,
467
+ column: import_icons.TableHeaderColumnIcon
468
+ };
469
+ function canToggleHeader({
470
+ editor,
471
+ index,
472
+ orientation,
473
+ tablePos
474
+ }) {
475
+ if (!editor || !editor.isEditable || !(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) {
476
+ return false;
477
+ }
478
+ const selectionType = getTableSelectionType(
479
+ editor,
480
+ index,
481
+ orientation,
482
+ tablePos
483
+ );
484
+ if (!selectionType) return false;
485
+ return selectionType.index === 0;
486
+ }
487
+ function toggleTableHeader({
488
+ editor,
489
+ index,
490
+ orientation,
491
+ tablePos
492
+ }) {
493
+ if (!editor) return false;
494
+ if (!canToggleHeader({ editor, index, orientation, tablePos })) return false;
495
+ try {
496
+ const selectionType = getTableSelectionType(
497
+ editor,
498
+ index,
499
+ orientation,
500
+ tablePos
501
+ );
502
+ if (!selectionType) return false;
503
+ const isRow = selectionType.orientation === "row";
504
+ if (editor.state.selection instanceof import_tables2.CellSelection) {
505
+ return isRow ? editor.commands.toggleHeaderRow() : editor.commands.toggleHeaderColumn();
506
+ }
507
+ if (!(0, import_editor_utils.isValidPosition)(tablePos)) return false;
508
+ const cellCoords = getIndexCoordinates({
509
+ editor,
510
+ index: selectionType.index,
511
+ orientation: selectionType.orientation,
512
+ tablePos
513
+ });
514
+ if (!cellCoords) return false;
515
+ const stateWithCellSel = selectCellsByCoords(editor, tablePos, cellCoords, {
516
+ mode: "state"
517
+ });
518
+ if (!stateWithCellSel) return false;
519
+ const dispatch = (tr) => editor.view.dispatch(tr);
520
+ return isRow ? (0, import_tables2.toggleHeader)("row")(stateWithCellSel, dispatch) : (0, import_tables2.toggleHeader)("column")(stateWithCellSel, dispatch);
521
+ } catch {
522
+ return false;
523
+ }
524
+ }
525
+ function shouldShowButton({
526
+ editor,
527
+ index,
528
+ orientation,
529
+ hideWhenUnavailable,
530
+ tablePos
531
+ }) {
532
+ if (!editor || !editor.isEditable) return false;
533
+ if (!(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) return false;
534
+ if (hideWhenUnavailable) {
535
+ return canToggleHeader({ editor, index, orientation, tablePos });
536
+ }
537
+ const selectionType = getTableSelectionType(editor, index, orientation);
538
+ return Boolean(selectionType);
539
+ }
540
+ function useTableHeaderRowColumn(config) {
541
+ var _a, _b;
542
+ const {
543
+ editor: providedEditor,
544
+ index,
545
+ orientation,
546
+ tablePos,
547
+ hideWhenUnavailable = false,
548
+ onToggled
549
+ } = config;
550
+ const { editor } = (0, import_editor_utils.useTiptapEditor)(providedEditor);
551
+ const intl = (0, import_i18n2.useSafeIntl)();
552
+ const selectionType = getTableSelectionType(editor, index, orientation);
553
+ const isVisible = shouldShowButton({
554
+ editor,
555
+ index,
556
+ orientation,
557
+ hideWhenUnavailable,
558
+ tablePos
559
+ });
560
+ const canPerformToggle = canToggleHeader({
561
+ editor,
562
+ index,
563
+ orientation,
564
+ tablePos
565
+ });
566
+ let isActive = false;
567
+ if ((editor == null ? void 0 : editor.state.selection) instanceof import_tables2.CellSelection) {
568
+ isActive = (editor == null ? void 0 : editor.isActive("tableHeader")) || false;
569
+ } else {
570
+ const rowsOrCols = getRowOrColumnCells(
571
+ editor,
572
+ index,
573
+ selectionType == null ? void 0 : selectionType.orientation,
574
+ tablePos
575
+ );
576
+ if (rowsOrCols) {
577
+ const secondIndex = rowsOrCols.cells.length > 1 ? 1 : 0;
578
+ isActive = ((_b = (_a = rowsOrCols.cells[secondIndex]) == null ? void 0 : _a.node) == null ? void 0 : _b.type.name) === "tableHeader" || false;
579
+ }
580
+ }
581
+ const handleToggle = (0, import_react.useCallback)(() => {
582
+ const success = toggleTableHeader({ editor, index, orientation, tablePos });
583
+ if (success) onToggled == null ? void 0 : onToggled();
584
+ return success;
585
+ }, [editor, index, orientation, tablePos, onToggled]);
586
+ const label = intl.formatMessage(
587
+ headerMessageKeys[(selectionType == null ? void 0 : selectionType.orientation) || "row"]
588
+ );
589
+ const Icon = tableHeaderRowColumnIcons[(selectionType == null ? void 0 : selectionType.orientation) || "row"];
590
+ return {
591
+ isVisible,
592
+ canToggleHeader: canPerformToggle,
593
+ handleToggle,
594
+ label,
595
+ Icon,
596
+ isActive
597
+ };
598
+ }
599
+ // Annotate the CommonJS export names for ESM import in node:
600
+ 0 && (module.exports = {
601
+ tableHeaderRowColumnIcons,
602
+ useTableHeaderRowColumn
603
+ });
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ tableHeaderRowColumnIcons,
5
+ useTableHeaderRowColumn
6
+ } from "../chunk-CD62W5C3.mjs";
7
+ import "../chunk-CN73TYHV.mjs";
8
+ import "../chunk-5B5XIL2G.mjs";
9
+ import "../chunk-WKV76XOR.mjs";
10
+ export {
11
+ tableHeaderRowColumnIcons,
12
+ useTableHeaderRowColumn
13
+ };