@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,681 @@
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-clear-row-column-content.ts
23
+ var use_table_clear_row_column_content_exports = {};
24
+ __export(use_table_clear_row_column_content_exports, {
25
+ useTableClearRowColumnContent: () => useTableClearRowColumnContent
26
+ });
27
+ module.exports = __toCommonJS(use_table_clear_row_column_content_exports);
28
+ var import_editor_utils = require("@kopexa/editor-utils");
29
+ var import_i18n2 = require("@kopexa/i18n");
30
+ var import_icons = require("@kopexa/icons");
31
+ var import_tables2 = require("@tiptap/pm/tables");
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
+ function setCellAttr(nameOrAttrs, value) {
203
+ return (state, dispatch) => {
204
+ var _a;
205
+ if (!(0, import_tables.isInTable)(state)) return false;
206
+ const $cell = (0, import_tables.selectionCell)(state);
207
+ const attrs = typeof nameOrAttrs === "string" ? { [nameOrAttrs]: value } : nameOrAttrs;
208
+ if (dispatch) {
209
+ const tr = state.tr;
210
+ if (state.selection instanceof import_tables.CellSelection) {
211
+ state.selection.forEachCell((node, pos) => {
212
+ const needsUpdate = Object.entries(attrs).some(
213
+ ([name, val]) => node.attrs[name] !== val
214
+ );
215
+ if (needsUpdate) {
216
+ tr.setNodeMarkup(pos, null, {
217
+ ...node.attrs,
218
+ ...attrs
219
+ });
220
+ }
221
+ });
222
+ } else {
223
+ const needsUpdate = Object.entries(attrs).some(
224
+ ([name, val]) => {
225
+ var _a2;
226
+ return ((_a2 = $cell.nodeAfter) == null ? void 0 : _a2.attrs[name]) !== val;
227
+ }
228
+ );
229
+ if (needsUpdate) {
230
+ tr.setNodeMarkup($cell.pos, null, {
231
+ ...(_a = $cell.nodeAfter) == null ? void 0 : _a.attrs,
232
+ ...attrs
233
+ });
234
+ }
235
+ }
236
+ dispatch(tr);
237
+ }
238
+ return true;
239
+ };
240
+ }
241
+
242
+ // src/messages.ts
243
+ var import_i18n = require("@kopexa/i18n");
244
+ var messages = (0, import_i18n.defineMessages)({
245
+ // Row/Column actions (aria labels)
246
+ row_actions: {
247
+ id: "editor.table.row_actions",
248
+ defaultMessage: "Row actions",
249
+ description: "ARIA label for row actions menu button"
250
+ },
251
+ column_actions: {
252
+ id: "editor.table.column_actions",
253
+ defaultMessage: "Column actions",
254
+ description: "ARIA label for column actions menu button"
255
+ },
256
+ cell_options: {
257
+ id: "editor.table.cell_options",
258
+ defaultMessage: "Table cells option",
259
+ description: "ARIA label for cell options menu button"
260
+ },
261
+ // Alignment
262
+ alignment: {
263
+ id: "editor.table.alignment",
264
+ defaultMessage: "Alignment",
265
+ description: "Label for alignment submenu"
266
+ },
267
+ align_left: {
268
+ id: "editor.table.align_left",
269
+ defaultMessage: "Align left",
270
+ description: "Label for align left action"
271
+ },
272
+ align_center: {
273
+ id: "editor.table.align_center",
274
+ defaultMessage: "Align center",
275
+ description: "Label for align center action"
276
+ },
277
+ align_right: {
278
+ id: "editor.table.align_right",
279
+ defaultMessage: "Align right",
280
+ description: "Label for align right action"
281
+ },
282
+ justify: {
283
+ id: "editor.table.justify",
284
+ defaultMessage: "Justify",
285
+ description: "Label for justify action"
286
+ },
287
+ align_top: {
288
+ id: "editor.table.align_top",
289
+ defaultMessage: "Align top",
290
+ description: "Label for vertical align top action"
291
+ },
292
+ align_middle: {
293
+ id: "editor.table.align_middle",
294
+ defaultMessage: "Align middle",
295
+ description: "Label for vertical align middle action"
296
+ },
297
+ align_bottom: {
298
+ id: "editor.table.align_bottom",
299
+ defaultMessage: "Align bottom",
300
+ description: "Label for vertical align bottom action"
301
+ },
302
+ // Add row/column
303
+ insert_row_above: {
304
+ id: "editor.table.insert_row_above",
305
+ defaultMessage: "Insert row above",
306
+ description: "Label for insert row above action"
307
+ },
308
+ insert_row_below: {
309
+ id: "editor.table.insert_row_below",
310
+ defaultMessage: "Insert row below",
311
+ description: "Label for insert row below action"
312
+ },
313
+ insert_column_left: {
314
+ id: "editor.table.insert_column_left",
315
+ defaultMessage: "Insert column left",
316
+ description: "Label for insert column left action"
317
+ },
318
+ insert_column_right: {
319
+ id: "editor.table.insert_column_right",
320
+ defaultMessage: "Insert column right",
321
+ description: "Label for insert column right action"
322
+ },
323
+ // Delete row/column
324
+ delete_row: {
325
+ id: "editor.table.delete_row",
326
+ defaultMessage: "Delete row",
327
+ description: "Label for delete row action"
328
+ },
329
+ delete_column: {
330
+ id: "editor.table.delete_column",
331
+ defaultMessage: "Delete column",
332
+ description: "Label for delete column action"
333
+ },
334
+ // Move row/column
335
+ move_row_up: {
336
+ id: "editor.table.move_row_up",
337
+ defaultMessage: "Move row up",
338
+ description: "Label for move row up action"
339
+ },
340
+ move_row_down: {
341
+ id: "editor.table.move_row_down",
342
+ defaultMessage: "Move row down",
343
+ description: "Label for move row down action"
344
+ },
345
+ move_column_left: {
346
+ id: "editor.table.move_column_left",
347
+ defaultMessage: "Move column left",
348
+ description: "Label for move column left action"
349
+ },
350
+ move_column_right: {
351
+ id: "editor.table.move_column_right",
352
+ defaultMessage: "Move column right",
353
+ description: "Label for move column right action"
354
+ },
355
+ // Sort
356
+ sort_row_asc: {
357
+ id: "editor.table.sort_row_asc",
358
+ defaultMessage: "Sort row A-Z",
359
+ description: "Label for sort row ascending action"
360
+ },
361
+ sort_row_desc: {
362
+ id: "editor.table.sort_row_desc",
363
+ defaultMessage: "Sort row Z-A",
364
+ description: "Label for sort row descending action"
365
+ },
366
+ sort_column_asc: {
367
+ id: "editor.table.sort_column_asc",
368
+ defaultMessage: "Sort column A-Z",
369
+ description: "Label for sort column ascending action"
370
+ },
371
+ sort_column_desc: {
372
+ id: "editor.table.sort_column_desc",
373
+ defaultMessage: "Sort column Z-A",
374
+ description: "Label for sort column descending action"
375
+ },
376
+ // Duplicate
377
+ duplicate_row: {
378
+ id: "editor.table.duplicate_row",
379
+ defaultMessage: "Duplicate row",
380
+ description: "Label for duplicate row action"
381
+ },
382
+ duplicate_column: {
383
+ id: "editor.table.duplicate_column",
384
+ defaultMessage: "Duplicate column",
385
+ description: "Label for duplicate column action"
386
+ },
387
+ // Header
388
+ header_row: {
389
+ id: "editor.table.header_row",
390
+ defaultMessage: "Header row",
391
+ description: "Label for toggle header row action"
392
+ },
393
+ header_column: {
394
+ id: "editor.table.header_column",
395
+ defaultMessage: "Header column",
396
+ description: "Label for toggle header column action"
397
+ },
398
+ // Merge/Split
399
+ merge_cells: {
400
+ id: "editor.table.merge_cells",
401
+ defaultMessage: "Merge cells",
402
+ description: "Label for merge cells action"
403
+ },
404
+ split_cell: {
405
+ id: "editor.table.split_cell",
406
+ defaultMessage: "Split cell",
407
+ description: "Label for split cell action"
408
+ },
409
+ // Clear contents
410
+ clear_row_contents: {
411
+ id: "editor.table.clear_row_contents",
412
+ defaultMessage: "Clear row contents",
413
+ description: "Label for clear row contents action"
414
+ },
415
+ clear_column_contents: {
416
+ id: "editor.table.clear_column_contents",
417
+ defaultMessage: "Clear column contents",
418
+ description: "Label for clear column contents action"
419
+ },
420
+ clear_contents: {
421
+ id: "editor.table.clear_contents",
422
+ defaultMessage: "Clear contents",
423
+ description: "Label for clear contents action (generic)"
424
+ }
425
+ });
426
+
427
+ // src/hooks/use-table-clear-row-column-content.ts
428
+ var REQUIRED_EXTENSIONS = ["table"];
429
+ var clearMessageKeys = {
430
+ row: messages.clear_row_contents,
431
+ column: messages.clear_column_contents
432
+ };
433
+ var DEFAULT_CELL_ATTRS = {
434
+ backgroundColor: null,
435
+ nodeVerticalAlign: null,
436
+ nodeTextAlign: null
437
+ };
438
+ function canClearRowColumnContent({
439
+ editor,
440
+ index,
441
+ orientation,
442
+ tablePos
443
+ }) {
444
+ if (!editor || !editor.isEditable || !(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) {
445
+ return false;
446
+ }
447
+ try {
448
+ const table = getTable(editor, tablePos);
449
+ if (!table) return false;
450
+ const selectionType = getTableSelectionType(
451
+ editor,
452
+ index,
453
+ orientation,
454
+ tablePos
455
+ );
456
+ if (selectionType) {
457
+ const cellData = getRowOrColumnCells(
458
+ editor,
459
+ selectionType.index,
460
+ selectionType.orientation,
461
+ tablePos
462
+ );
463
+ if (cellData.cells.length === 0) return false;
464
+ return cellData.cells.some(
465
+ (cellInfo) => cellInfo.node && !isCellEmpty(cellInfo.node)
466
+ );
467
+ } else {
468
+ const { selection } = editor.state;
469
+ if (selection instanceof import_tables2.CellSelection) {
470
+ let hasContent = false;
471
+ selection.forEachCell((cell2) => {
472
+ if (!isCellEmpty(cell2)) {
473
+ hasContent = true;
474
+ }
475
+ });
476
+ return hasContent;
477
+ }
478
+ const { $anchor } = selection;
479
+ const cell = (0, import_tables2.cellAround)($anchor);
480
+ if (!cell) return false;
481
+ const cellNode = editor.state.doc.nodeAt(cell.pos);
482
+ return cellNode ? !isCellEmpty(cellNode) : false;
483
+ }
484
+ } catch {
485
+ return false;
486
+ }
487
+ }
488
+ function clearSelectedCells(editor, resetAttrs = false) {
489
+ try {
490
+ const { state, view } = editor;
491
+ const { selection } = state;
492
+ if (selection instanceof import_tables2.CellSelection) {
493
+ if (resetAttrs) {
494
+ const attrSuccess = setCellAttr(DEFAULT_CELL_ATTRS)(
495
+ state,
496
+ view.dispatch
497
+ );
498
+ (0, import_tables2.deleteCellSelection)(editor.state, view.dispatch);
499
+ return attrSuccess;
500
+ }
501
+ (0, import_tables2.deleteCellSelection)(state, view.dispatch);
502
+ return true;
503
+ }
504
+ const { $anchor } = selection;
505
+ const cell = (0, import_tables2.cellAround)($anchor);
506
+ if (!cell) return false;
507
+ const cellNode = state.doc.nodeAt(cell.pos);
508
+ if (!cellNode) return false;
509
+ const from = cell.pos + 1;
510
+ const to = cell.pos + cellNode.nodeSize - 1;
511
+ if (from >= to) return false;
512
+ const tr = state.tr.delete(from, to);
513
+ if (resetAttrs) {
514
+ tr.setNodeMarkup(cell.pos, null, {
515
+ ...cellNode.attrs,
516
+ ...DEFAULT_CELL_ATTRS
517
+ });
518
+ }
519
+ view.dispatch(tr);
520
+ return true;
521
+ } catch (error) {
522
+ console.error("Error clearing selected cells:", error);
523
+ return false;
524
+ }
525
+ }
526
+ function clearRowColumnCells({
527
+ editor,
528
+ index,
529
+ orientation,
530
+ tablePos,
531
+ resetAttrs = false
532
+ }) {
533
+ try {
534
+ const { state, view } = editor;
535
+ const tr = state.tr;
536
+ const cellData = getRowOrColumnCells(editor, index, orientation, tablePos);
537
+ if (cellData.cells.length === 0) {
538
+ return false;
539
+ }
540
+ const cellsToProcess = [...cellData.cells].reverse();
541
+ cellsToProcess.forEach((cellInfo) => {
542
+ if (cellInfo.node && !isCellEmpty(cellInfo.node)) {
543
+ const from = cellInfo.pos + 1;
544
+ const to = cellInfo.pos + cellInfo.node.nodeSize - 1;
545
+ if (from < to) {
546
+ tr.delete(from, to);
547
+ }
548
+ if (resetAttrs) {
549
+ tr.setNodeMarkup(cellInfo.pos, null, {
550
+ ...cellInfo.node.attrs,
551
+ ...DEFAULT_CELL_ATTRS
552
+ });
553
+ }
554
+ }
555
+ });
556
+ if (tr.docChanged) {
557
+ view.dispatch(tr);
558
+ return true;
559
+ }
560
+ return false;
561
+ } catch (error) {
562
+ console.error(`Error clearing ${orientation} content:`, error);
563
+ return false;
564
+ }
565
+ }
566
+ function tableClearRowColumnContent({
567
+ editor,
568
+ index,
569
+ orientation,
570
+ tablePos,
571
+ resetAttrs = false
572
+ }) {
573
+ if (!canClearRowColumnContent({ editor, index, orientation, tablePos }) || !editor) {
574
+ return false;
575
+ }
576
+ try {
577
+ const selectionType = getTableSelectionType(
578
+ editor,
579
+ index,
580
+ orientation,
581
+ tablePos
582
+ );
583
+ if (selectionType) {
584
+ return clearRowColumnCells({
585
+ editor,
586
+ index: selectionType.index,
587
+ orientation: selectionType.orientation,
588
+ resetAttrs,
589
+ tablePos
590
+ });
591
+ } else {
592
+ return clearSelectedCells(editor, resetAttrs);
593
+ }
594
+ } catch (error) {
595
+ console.error("Error clearing table content:", error);
596
+ return false;
597
+ }
598
+ }
599
+ function shouldShowButton({
600
+ editor,
601
+ index,
602
+ orientation,
603
+ tablePos,
604
+ hideWhenUnavailable
605
+ }) {
606
+ if (!editor || !editor.isEditable) return false;
607
+ if (!(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) return false;
608
+ const table = getTable(editor, tablePos);
609
+ if (!table) return false;
610
+ const selectionType = getTableSelectionType(
611
+ editor,
612
+ index,
613
+ orientation,
614
+ tablePos
615
+ );
616
+ const { selection } = editor.state;
617
+ const isInTableCell = selection instanceof import_tables2.CellSelection || (0, import_tables2.cellAround)(selection.$anchor);
618
+ if (!selectionType && !isInTableCell) return false;
619
+ return hideWhenUnavailable ? canClearRowColumnContent({ editor, index, orientation, tablePos }) : true;
620
+ }
621
+ function useTableClearRowColumnContent(config = {}) {
622
+ const {
623
+ editor: providedEditor,
624
+ index,
625
+ orientation,
626
+ tablePos,
627
+ hideWhenUnavailable = false,
628
+ resetAttrs = false,
629
+ onCleared
630
+ } = config;
631
+ const { editor } = (0, import_editor_utils.useTiptapEditor)(providedEditor);
632
+ const intl = (0, import_i18n2.useSafeIntl)();
633
+ const selectionType = getTableSelectionType(
634
+ editor,
635
+ index,
636
+ orientation,
637
+ tablePos
638
+ );
639
+ const isVisible = shouldShowButton({
640
+ editor,
641
+ index,
642
+ orientation,
643
+ tablePos,
644
+ hideWhenUnavailable
645
+ });
646
+ const canPerformClear = canClearRowColumnContent({
647
+ editor,
648
+ index,
649
+ orientation,
650
+ tablePos
651
+ });
652
+ const handleClear = (0, import_react.useCallback)(() => {
653
+ const success = tableClearRowColumnContent({
654
+ editor,
655
+ index,
656
+ orientation,
657
+ tablePos,
658
+ resetAttrs
659
+ });
660
+ if (success) onCleared == null ? void 0 : onCleared();
661
+ return success;
662
+ }, [editor, index, orientation, tablePos, resetAttrs, onCleared]);
663
+ const label = (0, import_react.useMemo)(() => {
664
+ if (selectionType) {
665
+ return intl.formatMessage(clearMessageKeys[selectionType.orientation]);
666
+ }
667
+ return intl.formatMessage(messages.clear_contents);
668
+ }, [intl, selectionType]);
669
+ const Icon = import_icons.SquareXIcon;
670
+ return {
671
+ isVisible,
672
+ canClearRowColumnContent: canPerformClear,
673
+ handleClear,
674
+ label,
675
+ Icon
676
+ };
677
+ }
678
+ // Annotate the CommonJS export names for ESM import in node:
679
+ 0 && (module.exports = {
680
+ useTableClearRowColumnContent
681
+ });
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ useTableClearRowColumnContent
5
+ } from "../chunk-4QSZXHZO.mjs";
6
+ import "../chunk-CN73TYHV.mjs";
7
+ import "../chunk-5B5XIL2G.mjs";
8
+ import "../chunk-WKV76XOR.mjs";
9
+ export {
10
+ useTableClearRowColumnContent
11
+ };