@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,87 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as _kopexa_icons from '@kopexa/icons';
3
+ import { Editor } from '@tiptap/react';
4
+ import { Orientation } from '../lib/table-utils.mjs';
5
+ import '@tiptap/pm/model';
6
+ import '@tiptap/pm/state';
7
+ import '@tiptap/pm/tables';
8
+
9
+ interface UseTableDeleteRowColumnConfig {
10
+ /**
11
+ * The Tiptap editor instance. If omitted, the hook will use
12
+ * the context/editor from `useTiptapEditor`.
13
+ */
14
+ editor?: Editor | null;
15
+ /**
16
+ * The index of the row or column to delete.
17
+ */
18
+ index?: number;
19
+ /**
20
+ * Whether you're deleting a row or a column.
21
+ */
22
+ orientation?: Orientation;
23
+ /**
24
+ * The position of the table in the document.
25
+ */
26
+ tablePos?: number;
27
+ /**
28
+ * Hide the button when deletion isn't currently possible.
29
+ * @default false
30
+ */
31
+ hideWhenUnavailable?: boolean;
32
+ /**
33
+ * Callback function called after a successful delete.
34
+ */
35
+ onDeleted?: () => void;
36
+ }
37
+ /**
38
+ * Custom hook that provides **table row/column deletion**
39
+ * functionality for the Tiptap editor.
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * // Simple usage with default editor context
44
+ * function DeleteRowButton() {
45
+ * const { isVisible, handleDelete } = useTableDeleteRowColumn({
46
+ * index: 0,
47
+ * orientation: "row",
48
+ * })
49
+ *
50
+ * if (!isVisible) return null
51
+ *
52
+ * return <button onClick={handleDelete}>Delete Row</button>
53
+ * }
54
+ *
55
+ * // Advanced usage with custom editor instance
56
+ * function DeleteColumnButton({ editor }: { editor: Editor }) {
57
+ * const { isVisible, handleDelete, label, canDeleteRowColumn, Icon } = useTableDeleteRowColumn({
58
+ * editor,
59
+ * index: 1,
60
+ * orientation: "column",
61
+ * hideWhenUnavailable: true,
62
+ * onDeleted: () => console.log("Column deleted!"),
63
+ * })
64
+ *
65
+ * if (!isVisible) return null
66
+ *
67
+ * return (
68
+ * <button
69
+ * onClick={handleDelete}
70
+ * aria-disabled={!canDeleteRowColumn}
71
+ * aria-label={label}
72
+ * >
73
+ * <Icon /> Delete Column
74
+ * </button>
75
+ * )
76
+ * }
77
+ * ```
78
+ */
79
+ declare function useTableDeleteRowColumn(config: UseTableDeleteRowColumnConfig): {
80
+ isVisible: boolean;
81
+ canDeleteRowColumn: boolean;
82
+ handleDelete: () => boolean;
83
+ label: string;
84
+ Icon: ({ size, ...props }: _kopexa_icons.IconSvgProps) => react_jsx_runtime.JSX.Element;
85
+ };
86
+
87
+ export { type UseTableDeleteRowColumnConfig, useTableDeleteRowColumn };
@@ -0,0 +1,87 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as _kopexa_icons from '@kopexa/icons';
3
+ import { Editor } from '@tiptap/react';
4
+ import { Orientation } from '../lib/table-utils.js';
5
+ import '@tiptap/pm/model';
6
+ import '@tiptap/pm/state';
7
+ import '@tiptap/pm/tables';
8
+
9
+ interface UseTableDeleteRowColumnConfig {
10
+ /**
11
+ * The Tiptap editor instance. If omitted, the hook will use
12
+ * the context/editor from `useTiptapEditor`.
13
+ */
14
+ editor?: Editor | null;
15
+ /**
16
+ * The index of the row or column to delete.
17
+ */
18
+ index?: number;
19
+ /**
20
+ * Whether you're deleting a row or a column.
21
+ */
22
+ orientation?: Orientation;
23
+ /**
24
+ * The position of the table in the document.
25
+ */
26
+ tablePos?: number;
27
+ /**
28
+ * Hide the button when deletion isn't currently possible.
29
+ * @default false
30
+ */
31
+ hideWhenUnavailable?: boolean;
32
+ /**
33
+ * Callback function called after a successful delete.
34
+ */
35
+ onDeleted?: () => void;
36
+ }
37
+ /**
38
+ * Custom hook that provides **table row/column deletion**
39
+ * functionality for the Tiptap editor.
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * // Simple usage with default editor context
44
+ * function DeleteRowButton() {
45
+ * const { isVisible, handleDelete } = useTableDeleteRowColumn({
46
+ * index: 0,
47
+ * orientation: "row",
48
+ * })
49
+ *
50
+ * if (!isVisible) return null
51
+ *
52
+ * return <button onClick={handleDelete}>Delete Row</button>
53
+ * }
54
+ *
55
+ * // Advanced usage with custom editor instance
56
+ * function DeleteColumnButton({ editor }: { editor: Editor }) {
57
+ * const { isVisible, handleDelete, label, canDeleteRowColumn, Icon } = useTableDeleteRowColumn({
58
+ * editor,
59
+ * index: 1,
60
+ * orientation: "column",
61
+ * hideWhenUnavailable: true,
62
+ * onDeleted: () => console.log("Column deleted!"),
63
+ * })
64
+ *
65
+ * if (!isVisible) return null
66
+ *
67
+ * return (
68
+ * <button
69
+ * onClick={handleDelete}
70
+ * aria-disabled={!canDeleteRowColumn}
71
+ * aria-label={label}
72
+ * >
73
+ * <Icon /> Delete Column
74
+ * </button>
75
+ * )
76
+ * }
77
+ * ```
78
+ */
79
+ declare function useTableDeleteRowColumn(config: UseTableDeleteRowColumnConfig): {
80
+ isVisible: boolean;
81
+ canDeleteRowColumn: boolean;
82
+ handleDelete: () => boolean;
83
+ label: string;
84
+ Icon: ({ size, ...props }: _kopexa_icons.IconSvgProps) => react_jsx_runtime.JSX.Element;
85
+ };
86
+
87
+ export { type UseTableDeleteRowColumnConfig, useTableDeleteRowColumn };
@@ -0,0 +1,459 @@
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-delete-row-column.ts
23
+ var use_table_delete_row_column_exports = {};
24
+ __export(use_table_delete_row_column_exports, {
25
+ useTableDeleteRowColumn: () => useTableDeleteRowColumn
26
+ });
27
+ module.exports = __toCommonJS(use_table_delete_row_column_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
+ function getTable(editor, tablePos) {
38
+ if (!editor) return null;
39
+ let table = null;
40
+ if (typeof tablePos === "number") {
41
+ const tableNode = editor.state.doc.nodeAt(tablePos);
42
+ if ((tableNode == null ? void 0 : tableNode.type.name) === "table") {
43
+ table = {
44
+ node: tableNode,
45
+ pos: tablePos,
46
+ start: tablePos + 1,
47
+ depth: editor.state.doc.resolve(tablePos).depth
48
+ };
49
+ }
50
+ }
51
+ if (!table) {
52
+ const { state } = editor;
53
+ const $from = state.doc.resolve(state.selection.from);
54
+ table = (0, import_tables.findTable)($from);
55
+ }
56
+ if (!table) return null;
57
+ const tableMap = import_tables.TableMap.get(table.node);
58
+ if (!tableMap) return null;
59
+ return { ...table, map: tableMap };
60
+ }
61
+ function selectCellsByCoords(editor, tablePos, coords, options = { mode: "state" }) {
62
+ if (!editor) return;
63
+ const table = getTable(editor, tablePos);
64
+ if (!table) return;
65
+ const { state } = editor;
66
+ const tableMap = table.map;
67
+ const cleanedCoords = coords.map((coord) => ({
68
+ row: (0, import_shared_utils.clamp)(coord.row, 0, tableMap.height - 1),
69
+ col: (0, import_shared_utils.clamp)(coord.col, 0, tableMap.width - 1)
70
+ })).filter((coord) => isWithinBounds(coord.row, coord.col, tableMap));
71
+ if (cleanedCoords.length === 0) {
72
+ return;
73
+ }
74
+ const allRows = cleanedCoords.map((coord) => coord.row);
75
+ const topRow = Math.min(...allRows);
76
+ const bottomRow = Math.max(...allRows);
77
+ const allCols = cleanedCoords.map((coord) => coord.col);
78
+ const leftCol = Math.min(...allCols);
79
+ const rightCol = Math.max(...allCols);
80
+ const getCellPositionFromMap = (row, col) => {
81
+ const cellOffset = tableMap.map[row * tableMap.width + col];
82
+ if (cellOffset === void 0) return null;
83
+ return tablePos + 1 + cellOffset;
84
+ };
85
+ const anchorPosition = getCellPositionFromMap(topRow, leftCol);
86
+ if (anchorPosition === null) return;
87
+ let headPosition = getCellPositionFromMap(bottomRow, rightCol);
88
+ if (headPosition === null) return;
89
+ if (headPosition === anchorPosition) {
90
+ let foundDifferentCell = false;
91
+ for (let row = bottomRow; row >= topRow && !foundDifferentCell; row--) {
92
+ for (let col = rightCol; col >= leftCol && !foundDifferentCell; col--) {
93
+ const candidatePosition = getCellPositionFromMap(row, col);
94
+ if (candidatePosition !== null && candidatePosition !== anchorPosition) {
95
+ headPosition = candidatePosition;
96
+ foundDifferentCell = true;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ try {
102
+ const anchorRef = state.doc.resolve(anchorPosition);
103
+ const headRef = state.doc.resolve(headPosition);
104
+ const cellSelection = new import_tables.CellSelection(anchorRef, headRef);
105
+ const transaction = state.tr.setSelection(cellSelection);
106
+ return applySelectionWithMode(state, transaction, options);
107
+ } catch (error) {
108
+ console.error("Failed to create cell selection:", error);
109
+ return;
110
+ }
111
+ }
112
+ function isWithinBounds(row, col, map) {
113
+ return row >= 0 && row < map.height && col >= 0 && col < map.width;
114
+ }
115
+ function applySelectionWithMode(state, transaction, options) {
116
+ var _a;
117
+ const mode = (_a = options.mode) != null ? _a : "state";
118
+ switch (mode) {
119
+ case "dispatch": {
120
+ const dispatchOptions = options;
121
+ if (typeof dispatchOptions.dispatch === "function") {
122
+ dispatchOptions.dispatch(transaction);
123
+ }
124
+ return;
125
+ }
126
+ case "transaction":
127
+ return transaction;
128
+ default:
129
+ return state.apply(transaction);
130
+ }
131
+ }
132
+ function getTableSelectionType(editor, index, orientation, tablePos) {
133
+ if (typeof index === "number" && orientation) {
134
+ return { orientation, index };
135
+ }
136
+ if (!editor) return null;
137
+ const { state } = editor;
138
+ const table = getTable(editor, tablePos);
139
+ if (!table) return null;
140
+ if (state.selection instanceof import_tables.CellSelection) {
141
+ const rect = (0, import_tables.selectedRect)(state);
142
+ const map = import_tables.TableMap.get(table.node);
143
+ const width = rect.right - rect.left;
144
+ const height = rect.bottom - rect.top;
145
+ if (height === 1 && width === map.width) {
146
+ return { orientation: "row", index: rect.top };
147
+ }
148
+ if (width === 1 && height === map.height) {
149
+ return { orientation: "column", index: rect.left };
150
+ }
151
+ return null;
152
+ }
153
+ return null;
154
+ }
155
+
156
+ // src/messages.ts
157
+ var import_i18n = require("@kopexa/i18n");
158
+ var messages = (0, import_i18n.defineMessages)({
159
+ // Row/Column actions (aria labels)
160
+ row_actions: {
161
+ id: "editor.table.row_actions",
162
+ defaultMessage: "Row actions",
163
+ description: "ARIA label for row actions menu button"
164
+ },
165
+ column_actions: {
166
+ id: "editor.table.column_actions",
167
+ defaultMessage: "Column actions",
168
+ description: "ARIA label for column actions menu button"
169
+ },
170
+ cell_options: {
171
+ id: "editor.table.cell_options",
172
+ defaultMessage: "Table cells option",
173
+ description: "ARIA label for cell options menu button"
174
+ },
175
+ // Alignment
176
+ alignment: {
177
+ id: "editor.table.alignment",
178
+ defaultMessage: "Alignment",
179
+ description: "Label for alignment submenu"
180
+ },
181
+ align_left: {
182
+ id: "editor.table.align_left",
183
+ defaultMessage: "Align left",
184
+ description: "Label for align left action"
185
+ },
186
+ align_center: {
187
+ id: "editor.table.align_center",
188
+ defaultMessage: "Align center",
189
+ description: "Label for align center action"
190
+ },
191
+ align_right: {
192
+ id: "editor.table.align_right",
193
+ defaultMessage: "Align right",
194
+ description: "Label for align right action"
195
+ },
196
+ justify: {
197
+ id: "editor.table.justify",
198
+ defaultMessage: "Justify",
199
+ description: "Label for justify action"
200
+ },
201
+ align_top: {
202
+ id: "editor.table.align_top",
203
+ defaultMessage: "Align top",
204
+ description: "Label for vertical align top action"
205
+ },
206
+ align_middle: {
207
+ id: "editor.table.align_middle",
208
+ defaultMessage: "Align middle",
209
+ description: "Label for vertical align middle action"
210
+ },
211
+ align_bottom: {
212
+ id: "editor.table.align_bottom",
213
+ defaultMessage: "Align bottom",
214
+ description: "Label for vertical align bottom action"
215
+ },
216
+ // Add row/column
217
+ insert_row_above: {
218
+ id: "editor.table.insert_row_above",
219
+ defaultMessage: "Insert row above",
220
+ description: "Label for insert row above action"
221
+ },
222
+ insert_row_below: {
223
+ id: "editor.table.insert_row_below",
224
+ defaultMessage: "Insert row below",
225
+ description: "Label for insert row below action"
226
+ },
227
+ insert_column_left: {
228
+ id: "editor.table.insert_column_left",
229
+ defaultMessage: "Insert column left",
230
+ description: "Label for insert column left action"
231
+ },
232
+ insert_column_right: {
233
+ id: "editor.table.insert_column_right",
234
+ defaultMessage: "Insert column right",
235
+ description: "Label for insert column right action"
236
+ },
237
+ // Delete row/column
238
+ delete_row: {
239
+ id: "editor.table.delete_row",
240
+ defaultMessage: "Delete row",
241
+ description: "Label for delete row action"
242
+ },
243
+ delete_column: {
244
+ id: "editor.table.delete_column",
245
+ defaultMessage: "Delete column",
246
+ description: "Label for delete column action"
247
+ },
248
+ // Move row/column
249
+ move_row_up: {
250
+ id: "editor.table.move_row_up",
251
+ defaultMessage: "Move row up",
252
+ description: "Label for move row up action"
253
+ },
254
+ move_row_down: {
255
+ id: "editor.table.move_row_down",
256
+ defaultMessage: "Move row down",
257
+ description: "Label for move row down action"
258
+ },
259
+ move_column_left: {
260
+ id: "editor.table.move_column_left",
261
+ defaultMessage: "Move column left",
262
+ description: "Label for move column left action"
263
+ },
264
+ move_column_right: {
265
+ id: "editor.table.move_column_right",
266
+ defaultMessage: "Move column right",
267
+ description: "Label for move column right action"
268
+ },
269
+ // Sort
270
+ sort_row_asc: {
271
+ id: "editor.table.sort_row_asc",
272
+ defaultMessage: "Sort row A-Z",
273
+ description: "Label for sort row ascending action"
274
+ },
275
+ sort_row_desc: {
276
+ id: "editor.table.sort_row_desc",
277
+ defaultMessage: "Sort row Z-A",
278
+ description: "Label for sort row descending action"
279
+ },
280
+ sort_column_asc: {
281
+ id: "editor.table.sort_column_asc",
282
+ defaultMessage: "Sort column A-Z",
283
+ description: "Label for sort column ascending action"
284
+ },
285
+ sort_column_desc: {
286
+ id: "editor.table.sort_column_desc",
287
+ defaultMessage: "Sort column Z-A",
288
+ description: "Label for sort column descending action"
289
+ },
290
+ // Duplicate
291
+ duplicate_row: {
292
+ id: "editor.table.duplicate_row",
293
+ defaultMessage: "Duplicate row",
294
+ description: "Label for duplicate row action"
295
+ },
296
+ duplicate_column: {
297
+ id: "editor.table.duplicate_column",
298
+ defaultMessage: "Duplicate column",
299
+ description: "Label for duplicate column action"
300
+ },
301
+ // Header
302
+ header_row: {
303
+ id: "editor.table.header_row",
304
+ defaultMessage: "Header row",
305
+ description: "Label for toggle header row action"
306
+ },
307
+ header_column: {
308
+ id: "editor.table.header_column",
309
+ defaultMessage: "Header column",
310
+ description: "Label for toggle header column action"
311
+ },
312
+ // Merge/Split
313
+ merge_cells: {
314
+ id: "editor.table.merge_cells",
315
+ defaultMessage: "Merge cells",
316
+ description: "Label for merge cells action"
317
+ },
318
+ split_cell: {
319
+ id: "editor.table.split_cell",
320
+ defaultMessage: "Split cell",
321
+ description: "Label for split cell action"
322
+ },
323
+ // Clear contents
324
+ clear_row_contents: {
325
+ id: "editor.table.clear_row_contents",
326
+ defaultMessage: "Clear row contents",
327
+ description: "Label for clear row contents action"
328
+ },
329
+ clear_column_contents: {
330
+ id: "editor.table.clear_column_contents",
331
+ defaultMessage: "Clear column contents",
332
+ description: "Label for clear column contents action"
333
+ },
334
+ clear_contents: {
335
+ id: "editor.table.clear_contents",
336
+ defaultMessage: "Clear contents",
337
+ description: "Label for clear contents action (generic)"
338
+ }
339
+ });
340
+
341
+ // src/hooks/use-table-delete-row-column.ts
342
+ var REQUIRED_EXTENSIONS = ["table"];
343
+ var deleteMessageKeys = {
344
+ row: messages.delete_row,
345
+ column: messages.delete_column
346
+ };
347
+ function canDeleteRowColumn({
348
+ editor,
349
+ index,
350
+ orientation,
351
+ tablePos
352
+ }) {
353
+ if (!editor || !editor.isEditable || !(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) {
354
+ return false;
355
+ }
356
+ try {
357
+ const table = getTable(editor, tablePos);
358
+ if (!table) return false;
359
+ const selectionType = getTableSelectionType(editor, index, orientation);
360
+ if (!selectionType) return false;
361
+ return true;
362
+ } catch {
363
+ return false;
364
+ }
365
+ }
366
+ function tableDeleteRowColumn({
367
+ editor,
368
+ index,
369
+ orientation,
370
+ tablePos
371
+ }) {
372
+ if (!canDeleteRowColumn({ editor, index, orientation, tablePos }) || !editor) {
373
+ return false;
374
+ }
375
+ try {
376
+ const selectionType = getTableSelectionType(editor, index, orientation);
377
+ if (!selectionType) return false;
378
+ const { orientation: finalOrientation, index: finalIndex } = selectionType;
379
+ const isRow = finalOrientation === "row";
380
+ const dispatch = (tr) => editor.view.dispatch(tr);
381
+ const deleteOperation = isRow ? import_tables2.deleteRow : import_tables2.deleteColumn;
382
+ if (editor.state.selection instanceof import_tables2.CellSelection) {
383
+ return deleteOperation(editor.state, dispatch);
384
+ }
385
+ const table = getTable(editor, tablePos);
386
+ if (!table) return false;
387
+ const cellCoords = isRow ? { row: finalIndex, col: 0 } : { row: 0, col: finalIndex };
388
+ const cellState = selectCellsByCoords(editor, table.pos, [cellCoords], {
389
+ mode: "state"
390
+ });
391
+ if (!cellState) return false;
392
+ return deleteOperation(cellState, dispatch);
393
+ } catch (error) {
394
+ console.error(`Error deleting table row/column:`, error);
395
+ return false;
396
+ }
397
+ }
398
+ function shouldShowButton({
399
+ editor,
400
+ index,
401
+ orientation,
402
+ hideWhenUnavailable,
403
+ tablePos
404
+ }) {
405
+ if (!editor || !editor.isEditable) return false;
406
+ if (!(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) return false;
407
+ return hideWhenUnavailable ? canDeleteRowColumn({ editor, index, orientation, tablePos }) : true;
408
+ }
409
+ function useTableDeleteRowColumn(config) {
410
+ const {
411
+ editor: providedEditor,
412
+ index,
413
+ orientation,
414
+ tablePos,
415
+ hideWhenUnavailable = false,
416
+ onDeleted
417
+ } = config;
418
+ const { editor } = (0, import_editor_utils.useTiptapEditor)(providedEditor);
419
+ const intl = (0, import_i18n2.useSafeIntl)();
420
+ const selectionType = getTableSelectionType(editor, index, orientation);
421
+ const isVisible = shouldShowButton({
422
+ editor,
423
+ index,
424
+ orientation,
425
+ hideWhenUnavailable
426
+ });
427
+ const canPerformDelete = canDeleteRowColumn({
428
+ editor,
429
+ index,
430
+ orientation,
431
+ tablePos
432
+ });
433
+ const handleDelete = (0, import_react.useCallback)(() => {
434
+ const success = tableDeleteRowColumn({
435
+ editor,
436
+ index,
437
+ orientation,
438
+ tablePos
439
+ });
440
+ if (success) onDeleted == null ? void 0 : onDeleted();
441
+ return success;
442
+ }, [editor, index, orientation, tablePos, onDeleted]);
443
+ const label = (0, import_react.useMemo)(() => {
444
+ return intl.formatMessage(
445
+ deleteMessageKeys[(selectionType == null ? void 0 : selectionType.orientation) || "row"]
446
+ );
447
+ }, [intl, selectionType]);
448
+ return {
449
+ isVisible,
450
+ canDeleteRowColumn: canPerformDelete,
451
+ handleDelete,
452
+ label,
453
+ Icon: import_icons.TrashIcon
454
+ };
455
+ }
456
+ // Annotate the CommonJS export names for ESM import in node:
457
+ 0 && (module.exports = {
458
+ useTableDeleteRowColumn
459
+ });
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ useTableDeleteRowColumn
5
+ } from "../chunk-ZVPJDJBO.mjs";
6
+ import "../chunk-CN73TYHV.mjs";
7
+ import "../chunk-5B5XIL2G.mjs";
8
+ import "../chunk-WKV76XOR.mjs";
9
+ export {
10
+ useTableDeleteRowColumn
11
+ };
@@ -0,0 +1,49 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as _kopexa_icons from '@kopexa/icons';
3
+ import { Editor } from '@tiptap/react';
4
+ import { Orientation } from '../lib/table-utils.mjs';
5
+ import '@tiptap/pm/model';
6
+ import '@tiptap/pm/state';
7
+ import '@tiptap/pm/tables';
8
+
9
+ interface UseTableDuplicateRowColumnConfig {
10
+ /**
11
+ * The Tiptap editor instance. If omitted, the hook will use
12
+ * the context/editor from `useTiptapEditor`.
13
+ */
14
+ editor?: Editor | null;
15
+ /**
16
+ * The index of the row or column to duplicate.
17
+ */
18
+ index?: number;
19
+ /**
20
+ * Whether you're duplicating a row or a column.
21
+ */
22
+ orientation?: Orientation;
23
+ /**
24
+ * The position of the table in the document.
25
+ */
26
+ tablePos?: number;
27
+ /**
28
+ * Hide the button when duplication isn't currently possible.
29
+ * @default false
30
+ */
31
+ hideWhenUnavailable?: boolean;
32
+ /**
33
+ * Callback function called after a successful duplication.
34
+ */
35
+ onDuplicated?: () => void;
36
+ }
37
+ /**
38
+ * Custom hook that provides **table row/column duplication**
39
+ * functionality for the Tiptap editor.
40
+ */
41
+ declare function useTableDuplicateRowColumn(config: UseTableDuplicateRowColumnConfig): {
42
+ isVisible: boolean;
43
+ canDuplicateRowColumn: boolean;
44
+ handleDuplicate: () => boolean;
45
+ label: string;
46
+ Icon: ({ size, ...props }: _kopexa_icons.IconSvgProps) => react_jsx_runtime.JSX.Element;
47
+ };
48
+
49
+ export { type UseTableDuplicateRowColumnConfig, useTableDuplicateRowColumn };