@kopexa/extension-table 17.0.45 → 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 (200) 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-SNJF4UW6.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/{table/icons.mjs → extensions/table-cell.mjs} +3 -3
  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 +18 -5
  96. package/dist/index.d.ts +18 -5
  97. package/dist/index.js +4939 -910
  98. package/dist/index.mjs +43 -18
  99. package/dist/lib/constants.d.mts +4 -0
  100. package/dist/lib/constants.d.ts +4 -0
  101. package/dist/{table-row.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 +16 -12
  136. package/dist/chunk-6NY5XWR7.mjs +0 -11
  137. package/dist/chunk-74O2ORPO.mjs +0 -81
  138. package/dist/chunk-7NEAULTF.mjs +0 -58
  139. package/dist/chunk-ARSGMUXM.mjs +0 -116
  140. package/dist/chunk-BAQU2YT5.mjs +0 -41
  141. package/dist/chunk-DF6ZMJLL.mjs +0 -40
  142. package/dist/chunk-FKOIW52J.mjs +0 -11
  143. package/dist/chunk-GMNNSVR3.mjs +0 -540
  144. package/dist/chunk-IMRHHVEF.mjs +0 -113
  145. package/dist/chunk-NTWXQSW6.mjs +0 -13
  146. package/dist/chunk-OPDSKEZR.mjs +0 -93
  147. package/dist/chunk-YSUOVRY4.mjs +0 -1
  148. package/dist/kit.js +0 -1024
  149. package/dist/kit.mjs +0 -19
  150. package/dist/table/icons.d.mts +0 -13
  151. package/dist/table/icons.d.ts +0 -13
  152. package/dist/table/icons.js +0 -81
  153. package/dist/table/index.d.mts +0 -3
  154. package/dist/table/index.d.ts +0 -3
  155. package/dist/table/index.js +0 -809
  156. package/dist/table/index.mjs +0 -15
  157. package/dist/table/table-controls.d.mts +0 -15
  158. package/dist/table/table-controls.d.ts +0 -15
  159. package/dist/table/table-controls.js +0 -131
  160. package/dist/table/table-controls.mjs +0 -8
  161. package/dist/table/table-view.d.mts +0 -43
  162. package/dist/table/table-view.d.ts +0 -43
  163. package/dist/table/table-view.js +0 -610
  164. package/dist/table/table-view.mjs +0 -12
  165. package/dist/table/table.js +0 -807
  166. package/dist/table/table.mjs +0 -14
  167. package/dist/table/utilities/col-style.d.mts +0 -3
  168. package/dist/table/utilities/col-style.d.ts +0 -3
  169. package/dist/table/utilities/col-style.js +0 -36
  170. package/dist/table/utilities/col-style.mjs +0 -8
  171. package/dist/table/utilities/delete-table-when-all-cells-selected.d.mts +0 -5
  172. package/dist/table/utilities/delete-table-when-all-cells-selected.d.ts +0 -5
  173. package/dist/table/utilities/delete-table-when-all-cells-selected.js +0 -66
  174. package/dist/table/utilities/delete-table-when-all-cells-selected.mjs +0 -40
  175. package/dist/table/utilities/get-table-node-types.d.mts +0 -7
  176. package/dist/table/utilities/get-table-node-types.d.ts +0 -7
  177. package/dist/table/utilities/get-table-node-types.js +0 -44
  178. package/dist/table/utilities/get-table-node-types.mjs +0 -21
  179. package/dist/table/utilities/insert-line-above-table-action.d.mts +0 -5
  180. package/dist/table/utilities/insert-line-above-table-action.d.ts +0 -5
  181. package/dist/table/utilities/insert-line-above-table-action.js +0 -64
  182. package/dist/table/utilities/insert-line-above-table-action.mjs +0 -8
  183. package/dist/table/utilities/insert-line-below-table-action.d.mts +0 -5
  184. package/dist/table/utilities/insert-line-below-table-action.d.ts +0 -5
  185. package/dist/table/utilities/insert-line-below-table-action.js +0 -63
  186. package/dist/table/utilities/insert-line-below-table-action.mjs +0 -8
  187. package/dist/table/utilities/is-cell-selection.d.mts +0 -5
  188. package/dist/table/utilities/is-cell-selection.d.ts +0 -5
  189. package/dist/table/utilities/is-cell-selection.js +0 -34
  190. package/dist/table/utilities/is-cell-selection.mjs +0 -8
  191. package/dist/table-cell.d.mts +0 -8
  192. package/dist/table-cell.d.ts +0 -8
  193. package/dist/table-cell.js +0 -139
  194. package/dist/table-cell.mjs +0 -8
  195. package/dist/table-header.d.mts +0 -6
  196. package/dist/table-header.d.ts +0 -6
  197. package/dist/table-header.js +0 -104
  198. package/dist/table-header.mjs +0 -8
  199. package/dist/table-row.d.mts +0 -6
  200. package/dist/table-row.d.ts +0 -6
@@ -0,0 +1,623 @@
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-sort-row-column.ts
23
+ var use_table_sort_row_column_exports = {};
24
+ __export(use_table_sort_row_column_exports, {
25
+ tableSortRowColumnIcons: () => tableSortRowColumnIcons,
26
+ useTableSortRowColumn: () => useTableSortRowColumn
27
+ });
28
+ module.exports = __toCommonJS(use_table_sort_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_react = require("react");
33
+
34
+ // src/lib/table-utils.ts
35
+ var import_shared_utils = require("@kopexa/shared-utils");
36
+ var import_tables = require("@tiptap/pm/tables");
37
+ var EMPTY_CELLS_RESULT = { cells: [], mergedCells: [] };
38
+ function collectCells(editor, orientation, index, tablePos) {
39
+ if (!editor) return EMPTY_CELLS_RESULT;
40
+ const { state } = editor;
41
+ const table = getTable(editor, tablePos);
42
+ if (!table) return EMPTY_CELLS_RESULT;
43
+ const tableStart = table.start;
44
+ const tableNode = table.node;
45
+ const map = table.map;
46
+ const resolvedIndex = resolveOrientationIndex(
47
+ state,
48
+ table,
49
+ orientation,
50
+ index
51
+ );
52
+ if (resolvedIndex === null) return EMPTY_CELLS_RESULT;
53
+ const maxIndex = orientation === "row" ? map.height : map.width;
54
+ if (resolvedIndex < 0 || resolvedIndex >= maxIndex) {
55
+ return EMPTY_CELLS_RESULT;
56
+ }
57
+ const cells = [];
58
+ const mergedCells = [];
59
+ const seenMerged = /* @__PURE__ */ new Set();
60
+ const iterationCount = orientation === "row" ? map.width : map.height;
61
+ for (let i = 0; i < iterationCount; i++) {
62
+ const row = orientation === "row" ? resolvedIndex : i;
63
+ const col = orientation === "row" ? i : resolvedIndex;
64
+ const cellIndex = row * map.width + col;
65
+ const mapCell = map.map[cellIndex];
66
+ if (mapCell === void 0) continue;
67
+ const cellPos = tableStart + mapCell;
68
+ const cellNode = tableNode.nodeAt(mapCell);
69
+ if (!cellNode) continue;
70
+ const cell = createCellInfo(row, col, cellPos, cellNode);
71
+ if (isCellMerged(cellNode)) {
72
+ if (!seenMerged.has(cellPos)) {
73
+ mergedCells.push(cell);
74
+ seenMerged.add(cellPos);
75
+ }
76
+ }
77
+ cells.push(cell);
78
+ }
79
+ return { cells, mergedCells };
80
+ }
81
+ function isCellMerged(node) {
82
+ var _a, _b;
83
+ if (!node) return false;
84
+ const colspan = (_a = node.attrs.colspan) != null ? _a : 1;
85
+ const rowspan = (_b = node.attrs.rowspan) != null ? _b : 1;
86
+ return colspan > 1 || rowspan > 1;
87
+ }
88
+ function getTable(editor, tablePos) {
89
+ if (!editor) return null;
90
+ let table = null;
91
+ if (typeof tablePos === "number") {
92
+ const tableNode = editor.state.doc.nodeAt(tablePos);
93
+ if ((tableNode == null ? void 0 : tableNode.type.name) === "table") {
94
+ table = {
95
+ node: tableNode,
96
+ pos: tablePos,
97
+ start: tablePos + 1,
98
+ depth: editor.state.doc.resolve(tablePos).depth
99
+ };
100
+ }
101
+ }
102
+ if (!table) {
103
+ const { state } = editor;
104
+ const $from = state.doc.resolve(state.selection.from);
105
+ table = (0, import_tables.findTable)($from);
106
+ }
107
+ if (!table) return null;
108
+ const tableMap = import_tables.TableMap.get(table.node);
109
+ if (!tableMap) return null;
110
+ return { ...table, map: tableMap };
111
+ }
112
+ function createCellInfo(row, column, cellPos, cellNode) {
113
+ return {
114
+ row,
115
+ column,
116
+ pos: cellPos,
117
+ node: cellNode,
118
+ start: cellPos + 1,
119
+ depth: cellNode ? cellNode.content.size : 0
120
+ };
121
+ }
122
+ function resolveOrientationIndex(state, table, orientation, providedIndex) {
123
+ var _a;
124
+ if (typeof providedIndex === "number") {
125
+ return providedIndex;
126
+ }
127
+ if (state.selection instanceof import_tables.CellSelection) {
128
+ const rect2 = (0, import_tables.selectedRect)(state);
129
+ return orientation === "row" ? rect2.top : rect2.left;
130
+ }
131
+ const $cell = (_a = (0, import_tables.cellAround)(state.selection.$anchor)) != null ? _a : (0, import_tables.selectionCell)(state);
132
+ if (!$cell) return null;
133
+ const rel = $cell.pos - table.start;
134
+ const rect = table.map.findCell(rel);
135
+ return orientation === "row" ? rect.top : rect.left;
136
+ }
137
+ function getTableSelectionType(editor, index, orientation, tablePos) {
138
+ if (typeof index === "number" && orientation) {
139
+ return { orientation, index };
140
+ }
141
+ if (!editor) return null;
142
+ const { state } = editor;
143
+ const table = getTable(editor, tablePos);
144
+ if (!table) return null;
145
+ if (state.selection instanceof import_tables.CellSelection) {
146
+ const rect = (0, import_tables.selectedRect)(state);
147
+ const map = import_tables.TableMap.get(table.node);
148
+ const width = rect.right - rect.left;
149
+ const height = rect.bottom - rect.top;
150
+ if (height === 1 && width === map.width) {
151
+ return { orientation: "row", index: rect.top };
152
+ }
153
+ if (width === 1 && height === map.height) {
154
+ return { orientation: "column", index: rect.left };
155
+ }
156
+ return null;
157
+ }
158
+ return null;
159
+ }
160
+ function getRowOrColumnCells(editor, index, orientation, tablePos) {
161
+ const emptyResult = {
162
+ cells: [],
163
+ mergedCells: [],
164
+ index: void 0,
165
+ orientation: void 0,
166
+ tablePos: void 0
167
+ };
168
+ if (!editor) {
169
+ return emptyResult;
170
+ }
171
+ if (typeof index !== "number" && !(editor.state.selection instanceof import_tables.CellSelection)) {
172
+ return emptyResult;
173
+ }
174
+ let finalIndex = index;
175
+ let finalOrientation = orientation;
176
+ if (typeof finalIndex !== "number" || !finalOrientation || !["row", "column"].includes(finalOrientation)) {
177
+ const selectionType = getTableSelectionType(editor);
178
+ if (!selectionType) return emptyResult;
179
+ finalIndex = selectionType.index;
180
+ finalOrientation = selectionType.orientation;
181
+ }
182
+ const result = collectCells(editor, finalOrientation, finalIndex, tablePos);
183
+ return { ...result, index: finalIndex, orientation: finalOrientation };
184
+ }
185
+ function isCellEmpty(cellNode) {
186
+ if (cellNode.childCount === 0) return true;
187
+ let isEmpty = true;
188
+ cellNode.descendants((n) => {
189
+ var _a;
190
+ if (n.isText && ((_a = n.text) == null ? void 0 : _a.trim())) {
191
+ isEmpty = false;
192
+ return false;
193
+ }
194
+ if (n.isLeaf && !n.isText) {
195
+ isEmpty = false;
196
+ return false;
197
+ }
198
+ return true;
199
+ });
200
+ return isEmpty;
201
+ }
202
+
203
+ // src/messages.ts
204
+ var import_i18n = require("@kopexa/i18n");
205
+ var messages = (0, import_i18n.defineMessages)({
206
+ // Row/Column actions (aria labels)
207
+ row_actions: {
208
+ id: "editor.table.row_actions",
209
+ defaultMessage: "Row actions",
210
+ description: "ARIA label for row actions menu button"
211
+ },
212
+ column_actions: {
213
+ id: "editor.table.column_actions",
214
+ defaultMessage: "Column actions",
215
+ description: "ARIA label for column actions menu button"
216
+ },
217
+ cell_options: {
218
+ id: "editor.table.cell_options",
219
+ defaultMessage: "Table cells option",
220
+ description: "ARIA label for cell options menu button"
221
+ },
222
+ // Alignment
223
+ alignment: {
224
+ id: "editor.table.alignment",
225
+ defaultMessage: "Alignment",
226
+ description: "Label for alignment submenu"
227
+ },
228
+ align_left: {
229
+ id: "editor.table.align_left",
230
+ defaultMessage: "Align left",
231
+ description: "Label for align left action"
232
+ },
233
+ align_center: {
234
+ id: "editor.table.align_center",
235
+ defaultMessage: "Align center",
236
+ description: "Label for align center action"
237
+ },
238
+ align_right: {
239
+ id: "editor.table.align_right",
240
+ defaultMessage: "Align right",
241
+ description: "Label for align right action"
242
+ },
243
+ justify: {
244
+ id: "editor.table.justify",
245
+ defaultMessage: "Justify",
246
+ description: "Label for justify action"
247
+ },
248
+ align_top: {
249
+ id: "editor.table.align_top",
250
+ defaultMessage: "Align top",
251
+ description: "Label for vertical align top action"
252
+ },
253
+ align_middle: {
254
+ id: "editor.table.align_middle",
255
+ defaultMessage: "Align middle",
256
+ description: "Label for vertical align middle action"
257
+ },
258
+ align_bottom: {
259
+ id: "editor.table.align_bottom",
260
+ defaultMessage: "Align bottom",
261
+ description: "Label for vertical align bottom action"
262
+ },
263
+ // Add row/column
264
+ insert_row_above: {
265
+ id: "editor.table.insert_row_above",
266
+ defaultMessage: "Insert row above",
267
+ description: "Label for insert row above action"
268
+ },
269
+ insert_row_below: {
270
+ id: "editor.table.insert_row_below",
271
+ defaultMessage: "Insert row below",
272
+ description: "Label for insert row below action"
273
+ },
274
+ insert_column_left: {
275
+ id: "editor.table.insert_column_left",
276
+ defaultMessage: "Insert column left",
277
+ description: "Label for insert column left action"
278
+ },
279
+ insert_column_right: {
280
+ id: "editor.table.insert_column_right",
281
+ defaultMessage: "Insert column right",
282
+ description: "Label for insert column right action"
283
+ },
284
+ // Delete row/column
285
+ delete_row: {
286
+ id: "editor.table.delete_row",
287
+ defaultMessage: "Delete row",
288
+ description: "Label for delete row action"
289
+ },
290
+ delete_column: {
291
+ id: "editor.table.delete_column",
292
+ defaultMessage: "Delete column",
293
+ description: "Label for delete column action"
294
+ },
295
+ // Move row/column
296
+ move_row_up: {
297
+ id: "editor.table.move_row_up",
298
+ defaultMessage: "Move row up",
299
+ description: "Label for move row up action"
300
+ },
301
+ move_row_down: {
302
+ id: "editor.table.move_row_down",
303
+ defaultMessage: "Move row down",
304
+ description: "Label for move row down action"
305
+ },
306
+ move_column_left: {
307
+ id: "editor.table.move_column_left",
308
+ defaultMessage: "Move column left",
309
+ description: "Label for move column left action"
310
+ },
311
+ move_column_right: {
312
+ id: "editor.table.move_column_right",
313
+ defaultMessage: "Move column right",
314
+ description: "Label for move column right action"
315
+ },
316
+ // Sort
317
+ sort_row_asc: {
318
+ id: "editor.table.sort_row_asc",
319
+ defaultMessage: "Sort row A-Z",
320
+ description: "Label for sort row ascending action"
321
+ },
322
+ sort_row_desc: {
323
+ id: "editor.table.sort_row_desc",
324
+ defaultMessage: "Sort row Z-A",
325
+ description: "Label for sort row descending action"
326
+ },
327
+ sort_column_asc: {
328
+ id: "editor.table.sort_column_asc",
329
+ defaultMessage: "Sort column A-Z",
330
+ description: "Label for sort column ascending action"
331
+ },
332
+ sort_column_desc: {
333
+ id: "editor.table.sort_column_desc",
334
+ defaultMessage: "Sort column Z-A",
335
+ description: "Label for sort column descending action"
336
+ },
337
+ // Duplicate
338
+ duplicate_row: {
339
+ id: "editor.table.duplicate_row",
340
+ defaultMessage: "Duplicate row",
341
+ description: "Label for duplicate row action"
342
+ },
343
+ duplicate_column: {
344
+ id: "editor.table.duplicate_column",
345
+ defaultMessage: "Duplicate column",
346
+ description: "Label for duplicate column action"
347
+ },
348
+ // Header
349
+ header_row: {
350
+ id: "editor.table.header_row",
351
+ defaultMessage: "Header row",
352
+ description: "Label for toggle header row action"
353
+ },
354
+ header_column: {
355
+ id: "editor.table.header_column",
356
+ defaultMessage: "Header column",
357
+ description: "Label for toggle header column action"
358
+ },
359
+ // Merge/Split
360
+ merge_cells: {
361
+ id: "editor.table.merge_cells",
362
+ defaultMessage: "Merge cells",
363
+ description: "Label for merge cells action"
364
+ },
365
+ split_cell: {
366
+ id: "editor.table.split_cell",
367
+ defaultMessage: "Split cell",
368
+ description: "Label for split cell action"
369
+ },
370
+ // Clear contents
371
+ clear_row_contents: {
372
+ id: "editor.table.clear_row_contents",
373
+ defaultMessage: "Clear row contents",
374
+ description: "Label for clear row contents action"
375
+ },
376
+ clear_column_contents: {
377
+ id: "editor.table.clear_column_contents",
378
+ defaultMessage: "Clear column contents",
379
+ description: "Label for clear column contents action"
380
+ },
381
+ clear_contents: {
382
+ id: "editor.table.clear_contents",
383
+ defaultMessage: "Clear contents",
384
+ description: "Label for clear contents action (generic)"
385
+ }
386
+ });
387
+
388
+ // src/hooks/use-table-sort-row-column.ts
389
+ var REQUIRED_EXTENSIONS = ["tableHandleExtension"];
390
+ var sortMessageKeys = {
391
+ row: {
392
+ asc: messages.sort_row_asc,
393
+ desc: messages.sort_row_desc
394
+ },
395
+ column: {
396
+ asc: messages.sort_column_asc,
397
+ desc: messages.sort_column_desc
398
+ }
399
+ };
400
+ var tableSortRowColumnIcons = {
401
+ asc: import_icons.ArrowDownAZIcon,
402
+ desc: import_icons.ArrowDownZAIcon
403
+ };
404
+ function isCellHeader(cellNode) {
405
+ var _a;
406
+ if (!cellNode) return false;
407
+ return cellNode.type.name === "tableHeader" || cellNode.type.name === "table_header" || ((_a = cellNode.attrs) == null ? void 0 : _a.header) === true;
408
+ }
409
+ function getCellSortText(cellNode) {
410
+ if (!cellNode) return "";
411
+ let text = "";
412
+ cellNode.descendants((node) => {
413
+ if (node.isText) {
414
+ text += node.text || "";
415
+ }
416
+ return true;
417
+ });
418
+ return text.trim().toLowerCase();
419
+ }
420
+ function canSortRowColumn({
421
+ editor,
422
+ index,
423
+ orientation,
424
+ tablePos
425
+ }) {
426
+ if (!editor || !editor.isEditable || !(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) {
427
+ return false;
428
+ }
429
+ try {
430
+ const table = getTable(editor, tablePos);
431
+ if (!table) return false;
432
+ const cellData = getRowOrColumnCells(editor, index, orientation, tablePos);
433
+ if (cellData.orientation === "row") {
434
+ if (table.map.width < 2) return false;
435
+ } else {
436
+ if (table.map.height < 2) return false;
437
+ }
438
+ if (cellData.mergedCells.length > 0) {
439
+ return false;
440
+ }
441
+ const hasContent = cellData.cells.some(
442
+ (cellInfo) => cellInfo.node && !isCellHeader(cellInfo.node) && !isCellEmpty(cellInfo.node)
443
+ );
444
+ if (!hasContent) {
445
+ return false;
446
+ }
447
+ return true;
448
+ } catch {
449
+ return false;
450
+ }
451
+ }
452
+ function tableSortRowColumn({
453
+ editor,
454
+ index,
455
+ orientation,
456
+ direction,
457
+ tablePos
458
+ }) {
459
+ if (!canSortRowColumn({ editor, index, orientation, tablePos }) || !editor)
460
+ return false;
461
+ try {
462
+ const { state, view } = editor;
463
+ const tr = state.tr;
464
+ const cellData = getRowOrColumnCells(editor, index, orientation, tablePos);
465
+ if (cellData.mergedCells.length > 0) {
466
+ console.warn(
467
+ `Cannot sort ${orientation} ${index}: contains merged cells`
468
+ );
469
+ return false;
470
+ }
471
+ if (cellData.cells.length < 2) {
472
+ return false;
473
+ }
474
+ const allItems = cellData.cells.map(
475
+ (cellInfo, originalIndex) => {
476
+ const isHeader = isCellHeader(cellInfo.node);
477
+ const isEmpty = cellInfo.node ? isCellEmpty(cellInfo.node) : true;
478
+ return {
479
+ sortText: getCellSortText(cellInfo.node),
480
+ originalNode: cellInfo.node,
481
+ cellInfo,
482
+ originalIndex,
483
+ isHeader,
484
+ isEmpty
485
+ };
486
+ }
487
+ );
488
+ const dataItems = allItems.filter((item) => !item.isHeader);
489
+ if (dataItems.length < 2) {
490
+ console.log("No sortable data cells found (excluding headers)");
491
+ return false;
492
+ }
493
+ dataItems.sort((a, b) => {
494
+ if (a.isEmpty && !b.isEmpty) return 1;
495
+ if (!a.isEmpty && b.isEmpty) return -1;
496
+ if (a.isEmpty && b.isEmpty) return 0;
497
+ const comparison = a.sortText.localeCompare(b.sortText, void 0, {
498
+ sensitivity: "base"
499
+ });
500
+ return direction === "asc" ? comparison : -comparison;
501
+ });
502
+ const newCellNodes = [];
503
+ let dataIndex = 0;
504
+ for (let i = 0; i < allItems.length; i++) {
505
+ const originalItem = allItems[i];
506
+ const targetCell = cellData.cells[i];
507
+ if (!targetCell || !originalItem) continue;
508
+ let nodeToPlace = null;
509
+ if (originalItem.isHeader) {
510
+ nodeToPlace = originalItem.originalNode;
511
+ } else {
512
+ const sortedDataItem = dataItems[dataIndex];
513
+ nodeToPlace = (sortedDataItem == null ? void 0 : sortedDataItem.originalNode) || null;
514
+ dataIndex++;
515
+ }
516
+ if (nodeToPlace && targetCell.node) {
517
+ const cellType = targetCell.node.type;
518
+ const newCellNode = cellType.create(
519
+ nodeToPlace.attrs,
520
+ nodeToPlace.content,
521
+ nodeToPlace.marks
522
+ );
523
+ newCellNodes.push(newCellNode);
524
+ } else {
525
+ newCellNodes.push(targetCell.node);
526
+ }
527
+ }
528
+ const cellsToReplace = [...cellData.cells].reverse();
529
+ const newNodesToPlace = [...newCellNodes].reverse();
530
+ cellsToReplace.forEach((targetCell, reverseIndex) => {
531
+ const newNode = newNodesToPlace[reverseIndex];
532
+ if (newNode && targetCell.node) {
533
+ const cellEnd = targetCell.pos + targetCell.node.nodeSize;
534
+ tr.replaceWith(targetCell.pos, cellEnd, newNode);
535
+ }
536
+ });
537
+ if (tr.docChanged) {
538
+ view.dispatch(tr);
539
+ return true;
540
+ }
541
+ return false;
542
+ } catch (error) {
543
+ console.error(`Error sorting table ${orientation}:`, error);
544
+ return false;
545
+ }
546
+ }
547
+ function shouldShowButton({
548
+ editor,
549
+ index,
550
+ orientation,
551
+ hideWhenUnavailable,
552
+ tablePos
553
+ }) {
554
+ if (!editor || !editor.isEditable) return false;
555
+ if (!(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) return false;
556
+ const table = getTable(editor, tablePos);
557
+ if (!table) return false;
558
+ const selectionType = getTableSelectionType(
559
+ editor,
560
+ index,
561
+ orientation,
562
+ tablePos
563
+ );
564
+ if (!selectionType) return false;
565
+ return hideWhenUnavailable ? canSortRowColumn({ editor, index, orientation, tablePos }) : true;
566
+ }
567
+ function useTableSortRowColumn(config = { direction: "asc" }) {
568
+ const {
569
+ editor: providedEditor,
570
+ index,
571
+ orientation,
572
+ tablePos,
573
+ direction,
574
+ hideWhenUnavailable = false,
575
+ onSorted
576
+ } = config;
577
+ const { editor } = (0, import_editor_utils.useTiptapEditor)(providedEditor);
578
+ const intl = (0, import_i18n2.useSafeIntl)();
579
+ const selectionType = getTableSelectionType(editor, index, orientation);
580
+ const isVisible = shouldShowButton({
581
+ editor,
582
+ index,
583
+ orientation,
584
+ hideWhenUnavailable,
585
+ tablePos
586
+ });
587
+ const canPerformSort = canSortRowColumn({
588
+ editor,
589
+ index,
590
+ orientation,
591
+ tablePos
592
+ });
593
+ const handleSort = (0, import_react.useCallback)(() => {
594
+ const success = tableSortRowColumn({
595
+ editor,
596
+ index,
597
+ orientation,
598
+ direction,
599
+ tablePos
600
+ });
601
+ if (success) onSorted == null ? void 0 : onSorted();
602
+ return success;
603
+ }, [editor, index, orientation, direction, tablePos, onSorted]);
604
+ const label = (0, import_react.useMemo)(() => {
605
+ const orient = (selectionType == null ? void 0 : selectionType.orientation) || "row";
606
+ return intl.formatMessage(sortMessageKeys[orient][direction]);
607
+ }, [intl, selectionType, direction]);
608
+ const Icon = (0, import_react.useMemo)(() => {
609
+ return tableSortRowColumnIcons[direction] || import_icons.ArrowDownAZIcon;
610
+ }, [direction]);
611
+ return {
612
+ isVisible,
613
+ canSortRowColumn: canPerformSort,
614
+ handleSort,
615
+ label,
616
+ Icon
617
+ };
618
+ }
619
+ // Annotate the CommonJS export names for ESM import in node:
620
+ 0 && (module.exports = {
621
+ tableSortRowColumnIcons,
622
+ useTableSortRowColumn
623
+ });
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ tableSortRowColumnIcons,
5
+ useTableSortRowColumn
6
+ } from "../chunk-6FHFDGJO.mjs";
7
+ import "../chunk-CN73TYHV.mjs";
8
+ import "../chunk-5B5XIL2G.mjs";
9
+ import "../chunk-WKV76XOR.mjs";
10
+ export {
11
+ tableSortRowColumnIcons,
12
+ useTableSortRowColumn
13
+ };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,21 @@
1
- export { TableKit, TableKitOptions } from './kit.mjs';
2
- export { Table } from './table/table.mjs';
3
- export { TableCell, TableCellOptions } from './table-cell.mjs';
4
- export { TableHeader } from './table-header.mjs';
5
- export { TableRow } from './table-row.mjs';
1
+ export { TableKit, TableKitOptions } from './extensions/kit.mjs';
2
+ export { Table } from './extensions/table.mjs';
3
+ export { TableCell } from './extensions/table-cell.mjs';
4
+ export { messages as tableMessages } from './messages.mjs';
5
+ export { TableAlignMenuItems, TableAlignSubMenu } from './ui/table-alignment-menu.mjs';
6
+ export { TableCellHandleMenu } from './ui/table-cell-handle-menu.mjs';
7
+ export { TableHandle } from './ui/table-handle.mjs';
8
+ export { TableSelectionOverlay } from './ui/table-selection-overlay.mjs';
6
9
  import '@tiptap/extension-table';
7
10
  import '@tiptap/react';
8
11
  import '@tiptap/core';
12
+ import '@tiptap/extension-table/cell';
13
+ import 'react/jsx-runtime';
14
+ import './lib/table-utils.mjs';
15
+ import '@tiptap/pm/model';
16
+ import '@tiptap/pm/state';
17
+ import '@tiptap/pm/tables';
18
+ import 'react';
19
+ import './hooks/use-table-handle-positioning.mjs';
20
+ import './hooks/use-table-handle-state.mjs';
21
+ import './extensions/table-handle-plugin.mjs';
package/dist/index.d.ts CHANGED
@@ -1,8 +1,21 @@
1
- export { TableKit, TableKitOptions } from './kit.js';
2
- export { Table } from './table/table.js';
3
- export { TableCell, TableCellOptions } from './table-cell.js';
4
- export { TableHeader } from './table-header.js';
5
- export { TableRow } from './table-row.js';
1
+ export { TableKit, TableKitOptions } from './extensions/kit.js';
2
+ export { Table } from './extensions/table.js';
3
+ export { TableCell } from './extensions/table-cell.js';
4
+ export { messages as tableMessages } from './messages.js';
5
+ export { TableAlignMenuItems, TableAlignSubMenu } from './ui/table-alignment-menu.js';
6
+ export { TableCellHandleMenu } from './ui/table-cell-handle-menu.js';
7
+ export { TableHandle } from './ui/table-handle.js';
8
+ export { TableSelectionOverlay } from './ui/table-selection-overlay.js';
6
9
  import '@tiptap/extension-table';
7
10
  import '@tiptap/react';
8
11
  import '@tiptap/core';
12
+ import '@tiptap/extension-table/cell';
13
+ import 'react/jsx-runtime';
14
+ import './lib/table-utils.js';
15
+ import '@tiptap/pm/model';
16
+ import '@tiptap/pm/state';
17
+ import '@tiptap/pm/tables';
18
+ import 'react';
19
+ import './hooks/use-table-handle-positioning.js';
20
+ import './hooks/use-table-handle-state.js';
21
+ import './extensions/table-handle-plugin.js';