@kopexa/extension-table 17.0.46 → 17.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2NBDRVYL.mjs +428 -0
- package/dist/chunk-3SWV7BGP.mjs +638 -0
- package/dist/chunk-4QSZXHZO.mjs +276 -0
- package/dist/chunk-5B5XIL2G.mjs +457 -0
- package/dist/chunk-62B2LU2Q.mjs +603 -0
- package/dist/chunk-6FHFDGJO.mjs +251 -0
- package/dist/chunk-CD62W5C3.mjs +165 -0
- package/dist/chunk-CN73TYHV.mjs +190 -0
- package/dist/chunk-CPDSPBS6.mjs +276 -0
- package/dist/chunk-E7W2KRZG.mjs +49 -0
- package/dist/chunk-G6GHC2WO.mjs +276 -0
- package/dist/chunk-GBTQVIN5.mjs +174 -0
- package/dist/chunk-GDEXPEW5.mjs +52 -0
- package/dist/chunk-GQLZBIWF.mjs +198 -0
- package/dist/chunk-IRJ6RAVQ.mjs +116 -0
- package/dist/chunk-J4VOSZCZ.mjs +59 -0
- package/dist/chunk-KIYFW7MP.mjs +122 -0
- package/dist/chunk-KTRZVXJC.mjs +306 -0
- package/dist/chunk-LUA32VH4.mjs +35 -0
- package/dist/{chunk-2L3HZWWG.mjs → chunk-MB52MZQ4.mjs} +7 -8
- package/dist/chunk-PTX5UYV6.mjs +10 -0
- package/dist/chunk-TEGO6KUS.mjs +96 -0
- package/dist/chunk-VIBVRWS4.mjs +197 -0
- package/dist/chunk-VQV757EG.mjs +113 -0
- package/dist/chunk-XRNQXADK.mjs +149 -0
- package/dist/chunk-ZVPJDJBO.mjs +134 -0
- package/dist/{kit.d.mts → extensions/kit.d.mts} +1 -3
- package/dist/{kit.d.ts → extensions/kit.d.ts} +1 -3
- package/dist/extensions/kit.js +1041 -0
- package/dist/extensions/kit.mjs +15 -0
- package/dist/extensions/table-cell.d.mts +6 -0
- package/dist/extensions/table-cell.d.ts +6 -0
- package/dist/extensions/table-cell.js +70 -0
- package/dist/extensions/table-cell.mjs +8 -0
- package/dist/extensions/table-handle-plugin.d.mts +46 -0
- package/dist/extensions/table-handle-plugin.d.ts +46 -0
- package/dist/extensions/table-handle-plugin.js +1100 -0
- package/dist/extensions/table-handle-plugin.mjs +18 -0
- package/dist/extensions/table-handle.d.mts +19 -0
- package/dist/extensions/table-handle.d.ts +19 -0
- package/dist/extensions/table-handle.js +865 -0
- package/dist/extensions/table-handle.mjs +11 -0
- package/dist/{table → extensions}/table.d.mts +2 -2
- package/dist/{table → extensions}/table.d.ts +2 -2
- package/dist/extensions/table.js +138 -0
- package/dist/extensions/table.mjs +9 -0
- package/dist/hooks/use-resize-overlay.d.mts +5 -0
- package/dist/hooks/use-resize-overlay.d.ts +5 -0
- package/dist/hooks/use-resize-overlay.js +83 -0
- package/dist/hooks/use-resize-overlay.mjs +9 -0
- package/dist/hooks/use-table-add-row-column.d.mts +57 -0
- package/dist/hooks/use-table-add-row-column.d.ts +57 -0
- package/dist/hooks/use-table-add-row-column.js +551 -0
- package/dist/hooks/use-table-add-row-column.mjs +11 -0
- package/dist/hooks/use-table-align-cell.d.mts +148 -0
- package/dist/hooks/use-table-align-cell.d.ts +148 -0
- package/dist/hooks/use-table-align-cell.js +655 -0
- package/dist/hooks/use-table-align-cell.mjs +13 -0
- package/dist/hooks/use-table-clear-row-column-content.d.mts +103 -0
- package/dist/hooks/use-table-clear-row-column-content.d.ts +103 -0
- package/dist/hooks/use-table-clear-row-column-content.js +681 -0
- package/dist/hooks/use-table-clear-row-column-content.mjs +11 -0
- package/dist/hooks/use-table-delete-row-column.d.mts +87 -0
- package/dist/hooks/use-table-delete-row-column.d.ts +87 -0
- package/dist/hooks/use-table-delete-row-column.js +459 -0
- package/dist/hooks/use-table-delete-row-column.mjs +11 -0
- package/dist/hooks/use-table-duplicate-row-column.d.mts +49 -0
- package/dist/hooks/use-table-duplicate-row-column.d.ts +49 -0
- package/dist/hooks/use-table-duplicate-row-column.js +758 -0
- package/dist/hooks/use-table-duplicate-row-column.mjs +11 -0
- package/dist/hooks/use-table-handle-positioning.d.mts +42 -0
- package/dist/hooks/use-table-handle-positioning.d.ts +42 -0
- package/dist/hooks/use-table-handle-positioning.js +190 -0
- package/dist/hooks/use-table-handle-positioning.mjs +10 -0
- package/dist/hooks/use-table-handle-state.d.mts +28 -0
- package/dist/hooks/use-table-handle-state.d.ts +28 -0
- package/dist/hooks/use-table-handle-state.js +76 -0
- package/dist/hooks/use-table-handle-state.mjs +9 -0
- package/dist/hooks/use-table-header-row-column.d.mts +58 -0
- package/dist/hooks/use-table-header-row-column.d.ts +58 -0
- package/dist/hooks/use-table-header-row-column.js +603 -0
- package/dist/hooks/use-table-header-row-column.mjs +13 -0
- package/dist/hooks/use-table-merge-split-cell.d.mts +123 -0
- package/dist/hooks/use-table-merge-split-cell.d.ts +123 -0
- package/dist/hooks/use-table-merge-split-cell.js +331 -0
- package/dist/hooks/use-table-merge-split-cell.mjs +12 -0
- package/dist/hooks/use-table-move-row-column.d.mts +101 -0
- package/dist/hooks/use-table-move-row-column.d.ts +101 -0
- package/dist/hooks/use-table-move-row-column.js +621 -0
- package/dist/hooks/use-table-move-row-column.mjs +13 -0
- package/dist/hooks/use-table-sort-row-column.d.mts +118 -0
- package/dist/hooks/use-table-sort-row-column.d.ts +118 -0
- package/dist/hooks/use-table-sort-row-column.js +623 -0
- package/dist/hooks/use-table-sort-row-column.mjs +13 -0
- package/dist/index.d.mts +17 -6
- package/dist/index.d.ts +17 -6
- package/dist/index.js +4947 -660
- package/dist/index.mjs +43 -21
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/{table/lib/is-cell-selection.js → lib/constants.js} +10 -10
- package/dist/lib/constants.mjs +10 -0
- package/dist/lib/create-image.d.mts +12 -0
- package/dist/lib/create-image.d.ts +12 -0
- package/dist/lib/create-image.js +221 -0
- package/dist/lib/create-image.mjs +8 -0
- package/dist/lib/table-utils.d.mts +263 -0
- package/dist/lib/table-utils.d.ts +263 -0
- package/dist/lib/table-utils.js +488 -0
- package/dist/lib/table-utils.mjs +40 -0
- package/dist/messages.d.mts +174 -0
- package/dist/messages.d.ts +174 -0
- package/dist/messages.js +213 -0
- package/dist/{table-row.mjs → messages.mjs} +3 -3
- package/dist/ui/table-alignment-menu.d.mts +25 -0
- package/dist/ui/table-alignment-menu.d.ts +25 -0
- package/dist/ui/table-alignment-menu.js +758 -0
- package/dist/ui/table-alignment-menu.mjs +14 -0
- package/dist/ui/table-cell-handle-menu.d.mts +12 -0
- package/dist/ui/table-cell-handle-menu.d.ts +12 -0
- package/dist/ui/table-cell-handle-menu.js +1317 -0
- package/dist/ui/table-cell-handle-menu.mjs +17 -0
- package/dist/ui/table-handle-menu.d.mts +23 -0
- package/dist/ui/table-handle-menu.d.ts +23 -0
- package/dist/ui/table-handle-menu.js +2598 -0
- package/dist/ui/table-handle-menu.mjs +21 -0
- package/dist/ui/table-handle.d.mts +48 -0
- package/dist/ui/table-handle.d.ts +48 -0
- package/dist/ui/table-handle.js +3126 -0
- package/dist/ui/table-handle.mjs +22 -0
- package/dist/ui/table-selection-overlay.d.mts +14 -0
- package/dist/ui/table-selection-overlay.d.ts +14 -0
- package/dist/ui/table-selection-overlay.js +553 -0
- package/dist/ui/table-selection-overlay.mjs +11 -0
- package/package.json +12 -7
- package/dist/chunk-3XEOCAHB.mjs +0 -41
- package/dist/chunk-5W5ARI64.mjs +0 -11
- package/dist/chunk-BTJ3DCGC.mjs +0 -113
- package/dist/chunk-DR2GZJH6.mjs +0 -70
- package/dist/chunk-GHOJLOCF.mjs +0 -247
- package/dist/chunk-HWVA6DOK.mjs +0 -20
- package/dist/chunk-KLUH6EZS.mjs +0 -40
- package/dist/chunk-KNOMCS6F.mjs +0 -57
- package/dist/chunk-LPHCE6EI.mjs +0 -92
- package/dist/chunk-POJFNXG7.mjs +0 -44
- package/dist/chunk-QHD3QTD2.mjs +0 -61
- package/dist/chunk-RPPUD4R5.mjs +0 -1
- package/dist/kit.js +0 -764
- package/dist/kit.mjs +0 -19
- package/dist/table/index.d.mts +0 -6
- package/dist/table/index.d.ts +0 -6
- package/dist/table/index.js +0 -625
- package/dist/table/index.mjs +0 -18
- package/dist/table/lib/col-style.d.mts +0 -3
- package/dist/table/lib/col-style.d.ts +0 -3
- package/dist/table/lib/col-style.js +0 -36
- package/dist/table/lib/col-style.mjs +0 -13
- package/dist/table/lib/delete-table-when-all-cells-selected.d.mts +0 -5
- package/dist/table/lib/delete-table-when-all-cells-selected.d.ts +0 -5
- package/dist/table/lib/delete-table-when-all-cells-selected.js +0 -66
- package/dist/table/lib/delete-table-when-all-cells-selected.mjs +0 -40
- package/dist/table/lib/get-table-node-types.d.mts +0 -7
- package/dist/table/lib/get-table-node-types.d.ts +0 -7
- package/dist/table/lib/get-table-node-types.js +0 -44
- package/dist/table/lib/get-table-node-types.mjs +0 -21
- package/dist/table/lib/icons.d.mts +0 -13
- package/dist/table/lib/icons.d.ts +0 -13
- package/dist/table/lib/icons.js +0 -81
- package/dist/table/lib/icons.mjs +0 -58
- package/dist/table/lib/insert-line-above-table-action.d.mts +0 -5
- package/dist/table/lib/insert-line-above-table-action.d.ts +0 -5
- package/dist/table/lib/insert-line-above-table-action.js +0 -64
- package/dist/table/lib/insert-line-above-table-action.mjs +0 -8
- package/dist/table/lib/insert-line-below-table-action.d.mts +0 -5
- package/dist/table/lib/insert-line-below-table-action.d.ts +0 -5
- package/dist/table/lib/insert-line-below-table-action.js +0 -63
- package/dist/table/lib/insert-line-below-table-action.mjs +0 -8
- package/dist/table/lib/is-cell-selection.d.mts +0 -5
- package/dist/table/lib/is-cell-selection.d.ts +0 -5
- package/dist/table/lib/is-cell-selection.mjs +0 -8
- package/dist/table/lib/table-controls.d.mts +0 -15
- package/dist/table/lib/table-controls.d.ts +0 -15
- package/dist/table/lib/table-controls.js +0 -131
- package/dist/table/lib/table-controls.mjs +0 -8
- package/dist/table/table.js +0 -621
- package/dist/table/table.mjs +0 -14
- package/dist/table/views/table-column-menu.d.mts +0 -11
- package/dist/table/views/table-column-menu.d.ts +0 -11
- package/dist/table/views/table-column-menu.js +0 -84
- package/dist/table/views/table-column-menu.mjs +0 -8
- package/dist/table/views/table-node-view.d.mts +0 -25
- package/dist/table/views/table-node-view.d.ts +0 -25
- package/dist/table/views/table-node-view.js +0 -370
- package/dist/table/views/table-node-view.mjs +0 -10
- package/dist/table/views/table-row-menu.d.mts +0 -11
- package/dist/table/views/table-row-menu.d.ts +0 -11
- package/dist/table/views/table-row-menu.js +0 -80
- package/dist/table/views/table-row-menu.mjs +0 -8
- package/dist/table-cell.d.mts +0 -8
- package/dist/table-cell.d.ts +0 -8
- package/dist/table-cell.js +0 -93
- package/dist/table-cell.mjs +0 -8
- package/dist/table-header.d.mts +0 -6
- package/dist/table-header.d.ts +0 -6
- package/dist/table-header.js +0 -67
- package/dist/table-header.mjs +0 -8
- package/dist/table-row.d.mts +0 -6
- package/dist/table-row.d.ts +0 -6
- package/dist/table-row.js +0 -43
|
@@ -0,0 +1,758 @@
|
|
|
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-duplicate-row-column.ts
|
|
23
|
+
var use_table_duplicate_row_column_exports = {};
|
|
24
|
+
__export(use_table_duplicate_row_column_exports, {
|
|
25
|
+
useTableDuplicateRowColumn: () => useTableDuplicateRowColumn
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(use_table_duplicate_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
|
+
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 getIndexCoordinates({
|
|
138
|
+
editor,
|
|
139
|
+
index,
|
|
140
|
+
orientation,
|
|
141
|
+
tablePos
|
|
142
|
+
}) {
|
|
143
|
+
if (!editor) return null;
|
|
144
|
+
const table = getTable(editor, tablePos);
|
|
145
|
+
if (!table) return null;
|
|
146
|
+
const { map } = table;
|
|
147
|
+
const { width, height } = map;
|
|
148
|
+
if (index < 0) return null;
|
|
149
|
+
if (orientation === "row" && index >= height) return null;
|
|
150
|
+
if (orientation === "column" && index >= width) return null;
|
|
151
|
+
return orientation === "row" ? Array.from({ length: map.width }, (_, col) => ({ row: index, col })) : Array.from({ length: map.height }, (_, row) => ({ row, col: index }));
|
|
152
|
+
}
|
|
153
|
+
function selectCellsByCoords(editor, tablePos, coords, options = { mode: "state" }) {
|
|
154
|
+
if (!editor) return;
|
|
155
|
+
const table = getTable(editor, tablePos);
|
|
156
|
+
if (!table) return;
|
|
157
|
+
const { state } = editor;
|
|
158
|
+
const tableMap = table.map;
|
|
159
|
+
const cleanedCoords = coords.map((coord) => ({
|
|
160
|
+
row: (0, import_shared_utils.clamp)(coord.row, 0, tableMap.height - 1),
|
|
161
|
+
col: (0, import_shared_utils.clamp)(coord.col, 0, tableMap.width - 1)
|
|
162
|
+
})).filter((coord) => isWithinBounds(coord.row, coord.col, tableMap));
|
|
163
|
+
if (cleanedCoords.length === 0) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const allRows = cleanedCoords.map((coord) => coord.row);
|
|
167
|
+
const topRow = Math.min(...allRows);
|
|
168
|
+
const bottomRow = Math.max(...allRows);
|
|
169
|
+
const allCols = cleanedCoords.map((coord) => coord.col);
|
|
170
|
+
const leftCol = Math.min(...allCols);
|
|
171
|
+
const rightCol = Math.max(...allCols);
|
|
172
|
+
const getCellPositionFromMap = (row, col) => {
|
|
173
|
+
const cellOffset = tableMap.map[row * tableMap.width + col];
|
|
174
|
+
if (cellOffset === void 0) return null;
|
|
175
|
+
return tablePos + 1 + cellOffset;
|
|
176
|
+
};
|
|
177
|
+
const anchorPosition = getCellPositionFromMap(topRow, leftCol);
|
|
178
|
+
if (anchorPosition === null) return;
|
|
179
|
+
let headPosition = getCellPositionFromMap(bottomRow, rightCol);
|
|
180
|
+
if (headPosition === null) return;
|
|
181
|
+
if (headPosition === anchorPosition) {
|
|
182
|
+
let foundDifferentCell = false;
|
|
183
|
+
for (let row = bottomRow; row >= topRow && !foundDifferentCell; row--) {
|
|
184
|
+
for (let col = rightCol; col >= leftCol && !foundDifferentCell; col--) {
|
|
185
|
+
const candidatePosition = getCellPositionFromMap(row, col);
|
|
186
|
+
if (candidatePosition !== null && candidatePosition !== anchorPosition) {
|
|
187
|
+
headPosition = candidatePosition;
|
|
188
|
+
foundDifferentCell = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const anchorRef = state.doc.resolve(anchorPosition);
|
|
195
|
+
const headRef = state.doc.resolve(headPosition);
|
|
196
|
+
const cellSelection = new import_tables.CellSelection(anchorRef, headRef);
|
|
197
|
+
const transaction = state.tr.setSelection(cellSelection);
|
|
198
|
+
return applySelectionWithMode(state, transaction, options);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error("Failed to create cell selection:", error);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function isWithinBounds(row, col, map) {
|
|
205
|
+
return row >= 0 && row < map.height && col >= 0 && col < map.width;
|
|
206
|
+
}
|
|
207
|
+
function applySelectionWithMode(state, transaction, options) {
|
|
208
|
+
var _a;
|
|
209
|
+
const mode = (_a = options.mode) != null ? _a : "state";
|
|
210
|
+
switch (mode) {
|
|
211
|
+
case "dispatch": {
|
|
212
|
+
const dispatchOptions = options;
|
|
213
|
+
if (typeof dispatchOptions.dispatch === "function") {
|
|
214
|
+
dispatchOptions.dispatch(transaction);
|
|
215
|
+
}
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
case "transaction":
|
|
219
|
+
return transaction;
|
|
220
|
+
default:
|
|
221
|
+
return state.apply(transaction);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function getTableSelectionType(editor, index, orientation, tablePos) {
|
|
225
|
+
if (typeof index === "number" && orientation) {
|
|
226
|
+
return { orientation, index };
|
|
227
|
+
}
|
|
228
|
+
if (!editor) return null;
|
|
229
|
+
const { state } = editor;
|
|
230
|
+
const table = getTable(editor, tablePos);
|
|
231
|
+
if (!table) return null;
|
|
232
|
+
if (state.selection instanceof import_tables.CellSelection) {
|
|
233
|
+
const rect = (0, import_tables.selectedRect)(state);
|
|
234
|
+
const map = import_tables.TableMap.get(table.node);
|
|
235
|
+
const width = rect.right - rect.left;
|
|
236
|
+
const height = rect.bottom - rect.top;
|
|
237
|
+
if (height === 1 && width === map.width) {
|
|
238
|
+
return { orientation: "row", index: rect.top };
|
|
239
|
+
}
|
|
240
|
+
if (width === 1 && height === map.height) {
|
|
241
|
+
return { orientation: "column", index: rect.left };
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
function getRowOrColumnCells(editor, index, orientation, tablePos) {
|
|
248
|
+
const emptyResult = {
|
|
249
|
+
cells: [],
|
|
250
|
+
mergedCells: [],
|
|
251
|
+
index: void 0,
|
|
252
|
+
orientation: void 0,
|
|
253
|
+
tablePos: void 0
|
|
254
|
+
};
|
|
255
|
+
if (!editor) {
|
|
256
|
+
return emptyResult;
|
|
257
|
+
}
|
|
258
|
+
if (typeof index !== "number" && !(editor.state.selection instanceof import_tables.CellSelection)) {
|
|
259
|
+
return emptyResult;
|
|
260
|
+
}
|
|
261
|
+
let finalIndex = index;
|
|
262
|
+
let finalOrientation = orientation;
|
|
263
|
+
if (typeof finalIndex !== "number" || !finalOrientation || !["row", "column"].includes(finalOrientation)) {
|
|
264
|
+
const selectionType = getTableSelectionType(editor);
|
|
265
|
+
if (!selectionType) return emptyResult;
|
|
266
|
+
finalIndex = selectionType.index;
|
|
267
|
+
finalOrientation = selectionType.orientation;
|
|
268
|
+
}
|
|
269
|
+
const result = collectCells(editor, finalOrientation, finalIndex, tablePos);
|
|
270
|
+
return { ...result, index: finalIndex, orientation: finalOrientation };
|
|
271
|
+
}
|
|
272
|
+
function updateSelectionAfterAction(editor, orientation, newIndex, tablePos) {
|
|
273
|
+
try {
|
|
274
|
+
const table = getTable(editor, tablePos);
|
|
275
|
+
if (!table) return;
|
|
276
|
+
const { state } = editor;
|
|
277
|
+
const { map } = table;
|
|
278
|
+
if (orientation === "row") {
|
|
279
|
+
if (newIndex >= 0 && newIndex < map.height) {
|
|
280
|
+
const startCol = 0;
|
|
281
|
+
const endCol = map.width - 1;
|
|
282
|
+
const startCellPos = table.start + map.positionAt(newIndex, startCol, table.node);
|
|
283
|
+
const endCellPos = table.start + map.positionAt(newIndex, endCol, table.node);
|
|
284
|
+
const $start = state.doc.resolve(startCellPos);
|
|
285
|
+
const $end = state.doc.resolve(endCellPos);
|
|
286
|
+
const newSelection = import_tables.CellSelection.create(
|
|
287
|
+
state.doc,
|
|
288
|
+
$start.pos,
|
|
289
|
+
$end.pos
|
|
290
|
+
);
|
|
291
|
+
const tr = state.tr.setSelection(newSelection);
|
|
292
|
+
editor.view.dispatch(tr);
|
|
293
|
+
}
|
|
294
|
+
} else if (orientation === "column") {
|
|
295
|
+
if (newIndex >= 0 && newIndex < map.width) {
|
|
296
|
+
const startRow = 0;
|
|
297
|
+
const endRow = map.height - 1;
|
|
298
|
+
const startCellPos = table.start + map.positionAt(startRow, newIndex, table.node);
|
|
299
|
+
const endCellPos = table.start + map.positionAt(endRow, newIndex, table.node);
|
|
300
|
+
const $start = state.doc.resolve(startCellPos);
|
|
301
|
+
const $end = state.doc.resolve(endCellPos);
|
|
302
|
+
const newSelection = import_tables.CellSelection.create(
|
|
303
|
+
state.doc,
|
|
304
|
+
$start.pos,
|
|
305
|
+
$end.pos
|
|
306
|
+
);
|
|
307
|
+
const tr = state.tr.setSelection(newSelection);
|
|
308
|
+
editor.view.dispatch(tr);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
} catch (error) {
|
|
312
|
+
console.warn("Failed to update selection after move:", error);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/messages.ts
|
|
317
|
+
var import_i18n = require("@kopexa/i18n");
|
|
318
|
+
var messages = (0, import_i18n.defineMessages)({
|
|
319
|
+
// Row/Column actions (aria labels)
|
|
320
|
+
row_actions: {
|
|
321
|
+
id: "editor.table.row_actions",
|
|
322
|
+
defaultMessage: "Row actions",
|
|
323
|
+
description: "ARIA label for row actions menu button"
|
|
324
|
+
},
|
|
325
|
+
column_actions: {
|
|
326
|
+
id: "editor.table.column_actions",
|
|
327
|
+
defaultMessage: "Column actions",
|
|
328
|
+
description: "ARIA label for column actions menu button"
|
|
329
|
+
},
|
|
330
|
+
cell_options: {
|
|
331
|
+
id: "editor.table.cell_options",
|
|
332
|
+
defaultMessage: "Table cells option",
|
|
333
|
+
description: "ARIA label for cell options menu button"
|
|
334
|
+
},
|
|
335
|
+
// Alignment
|
|
336
|
+
alignment: {
|
|
337
|
+
id: "editor.table.alignment",
|
|
338
|
+
defaultMessage: "Alignment",
|
|
339
|
+
description: "Label for alignment submenu"
|
|
340
|
+
},
|
|
341
|
+
align_left: {
|
|
342
|
+
id: "editor.table.align_left",
|
|
343
|
+
defaultMessage: "Align left",
|
|
344
|
+
description: "Label for align left action"
|
|
345
|
+
},
|
|
346
|
+
align_center: {
|
|
347
|
+
id: "editor.table.align_center",
|
|
348
|
+
defaultMessage: "Align center",
|
|
349
|
+
description: "Label for align center action"
|
|
350
|
+
},
|
|
351
|
+
align_right: {
|
|
352
|
+
id: "editor.table.align_right",
|
|
353
|
+
defaultMessage: "Align right",
|
|
354
|
+
description: "Label for align right action"
|
|
355
|
+
},
|
|
356
|
+
justify: {
|
|
357
|
+
id: "editor.table.justify",
|
|
358
|
+
defaultMessage: "Justify",
|
|
359
|
+
description: "Label for justify action"
|
|
360
|
+
},
|
|
361
|
+
align_top: {
|
|
362
|
+
id: "editor.table.align_top",
|
|
363
|
+
defaultMessage: "Align top",
|
|
364
|
+
description: "Label for vertical align top action"
|
|
365
|
+
},
|
|
366
|
+
align_middle: {
|
|
367
|
+
id: "editor.table.align_middle",
|
|
368
|
+
defaultMessage: "Align middle",
|
|
369
|
+
description: "Label for vertical align middle action"
|
|
370
|
+
},
|
|
371
|
+
align_bottom: {
|
|
372
|
+
id: "editor.table.align_bottom",
|
|
373
|
+
defaultMessage: "Align bottom",
|
|
374
|
+
description: "Label for vertical align bottom action"
|
|
375
|
+
},
|
|
376
|
+
// Add row/column
|
|
377
|
+
insert_row_above: {
|
|
378
|
+
id: "editor.table.insert_row_above",
|
|
379
|
+
defaultMessage: "Insert row above",
|
|
380
|
+
description: "Label for insert row above action"
|
|
381
|
+
},
|
|
382
|
+
insert_row_below: {
|
|
383
|
+
id: "editor.table.insert_row_below",
|
|
384
|
+
defaultMessage: "Insert row below",
|
|
385
|
+
description: "Label for insert row below action"
|
|
386
|
+
},
|
|
387
|
+
insert_column_left: {
|
|
388
|
+
id: "editor.table.insert_column_left",
|
|
389
|
+
defaultMessage: "Insert column left",
|
|
390
|
+
description: "Label for insert column left action"
|
|
391
|
+
},
|
|
392
|
+
insert_column_right: {
|
|
393
|
+
id: "editor.table.insert_column_right",
|
|
394
|
+
defaultMessage: "Insert column right",
|
|
395
|
+
description: "Label for insert column right action"
|
|
396
|
+
},
|
|
397
|
+
// Delete row/column
|
|
398
|
+
delete_row: {
|
|
399
|
+
id: "editor.table.delete_row",
|
|
400
|
+
defaultMessage: "Delete row",
|
|
401
|
+
description: "Label for delete row action"
|
|
402
|
+
},
|
|
403
|
+
delete_column: {
|
|
404
|
+
id: "editor.table.delete_column",
|
|
405
|
+
defaultMessage: "Delete column",
|
|
406
|
+
description: "Label for delete column action"
|
|
407
|
+
},
|
|
408
|
+
// Move row/column
|
|
409
|
+
move_row_up: {
|
|
410
|
+
id: "editor.table.move_row_up",
|
|
411
|
+
defaultMessage: "Move row up",
|
|
412
|
+
description: "Label for move row up action"
|
|
413
|
+
},
|
|
414
|
+
move_row_down: {
|
|
415
|
+
id: "editor.table.move_row_down",
|
|
416
|
+
defaultMessage: "Move row down",
|
|
417
|
+
description: "Label for move row down action"
|
|
418
|
+
},
|
|
419
|
+
move_column_left: {
|
|
420
|
+
id: "editor.table.move_column_left",
|
|
421
|
+
defaultMessage: "Move column left",
|
|
422
|
+
description: "Label for move column left action"
|
|
423
|
+
},
|
|
424
|
+
move_column_right: {
|
|
425
|
+
id: "editor.table.move_column_right",
|
|
426
|
+
defaultMessage: "Move column right",
|
|
427
|
+
description: "Label for move column right action"
|
|
428
|
+
},
|
|
429
|
+
// Sort
|
|
430
|
+
sort_row_asc: {
|
|
431
|
+
id: "editor.table.sort_row_asc",
|
|
432
|
+
defaultMessage: "Sort row A-Z",
|
|
433
|
+
description: "Label for sort row ascending action"
|
|
434
|
+
},
|
|
435
|
+
sort_row_desc: {
|
|
436
|
+
id: "editor.table.sort_row_desc",
|
|
437
|
+
defaultMessage: "Sort row Z-A",
|
|
438
|
+
description: "Label for sort row descending action"
|
|
439
|
+
},
|
|
440
|
+
sort_column_asc: {
|
|
441
|
+
id: "editor.table.sort_column_asc",
|
|
442
|
+
defaultMessage: "Sort column A-Z",
|
|
443
|
+
description: "Label for sort column ascending action"
|
|
444
|
+
},
|
|
445
|
+
sort_column_desc: {
|
|
446
|
+
id: "editor.table.sort_column_desc",
|
|
447
|
+
defaultMessage: "Sort column Z-A",
|
|
448
|
+
description: "Label for sort column descending action"
|
|
449
|
+
},
|
|
450
|
+
// Duplicate
|
|
451
|
+
duplicate_row: {
|
|
452
|
+
id: "editor.table.duplicate_row",
|
|
453
|
+
defaultMessage: "Duplicate row",
|
|
454
|
+
description: "Label for duplicate row action"
|
|
455
|
+
},
|
|
456
|
+
duplicate_column: {
|
|
457
|
+
id: "editor.table.duplicate_column",
|
|
458
|
+
defaultMessage: "Duplicate column",
|
|
459
|
+
description: "Label for duplicate column action"
|
|
460
|
+
},
|
|
461
|
+
// Header
|
|
462
|
+
header_row: {
|
|
463
|
+
id: "editor.table.header_row",
|
|
464
|
+
defaultMessage: "Header row",
|
|
465
|
+
description: "Label for toggle header row action"
|
|
466
|
+
},
|
|
467
|
+
header_column: {
|
|
468
|
+
id: "editor.table.header_column",
|
|
469
|
+
defaultMessage: "Header column",
|
|
470
|
+
description: "Label for toggle header column action"
|
|
471
|
+
},
|
|
472
|
+
// Merge/Split
|
|
473
|
+
merge_cells: {
|
|
474
|
+
id: "editor.table.merge_cells",
|
|
475
|
+
defaultMessage: "Merge cells",
|
|
476
|
+
description: "Label for merge cells action"
|
|
477
|
+
},
|
|
478
|
+
split_cell: {
|
|
479
|
+
id: "editor.table.split_cell",
|
|
480
|
+
defaultMessage: "Split cell",
|
|
481
|
+
description: "Label for split cell action"
|
|
482
|
+
},
|
|
483
|
+
// Clear contents
|
|
484
|
+
clear_row_contents: {
|
|
485
|
+
id: "editor.table.clear_row_contents",
|
|
486
|
+
defaultMessage: "Clear row contents",
|
|
487
|
+
description: "Label for clear row contents action"
|
|
488
|
+
},
|
|
489
|
+
clear_column_contents: {
|
|
490
|
+
id: "editor.table.clear_column_contents",
|
|
491
|
+
defaultMessage: "Clear column contents",
|
|
492
|
+
description: "Label for clear column contents action"
|
|
493
|
+
},
|
|
494
|
+
clear_contents: {
|
|
495
|
+
id: "editor.table.clear_contents",
|
|
496
|
+
defaultMessage: "Clear contents",
|
|
497
|
+
description: "Label for clear contents action (generic)"
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// src/hooks/use-table-duplicate-row-column.ts
|
|
502
|
+
var REQUIRED_EXTENSIONS = ["tableHandleExtension"];
|
|
503
|
+
var duplicateMessageKeys = {
|
|
504
|
+
row: messages.duplicate_row,
|
|
505
|
+
column: messages.duplicate_column
|
|
506
|
+
};
|
|
507
|
+
function canDuplicateRowColumn({
|
|
508
|
+
editor,
|
|
509
|
+
index,
|
|
510
|
+
orientation,
|
|
511
|
+
tablePos
|
|
512
|
+
}) {
|
|
513
|
+
if (!editor || !editor.isEditable || !(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
try {
|
|
517
|
+
const table = getTable(editor, tablePos);
|
|
518
|
+
if (!table) return false;
|
|
519
|
+
const cellData = getRowOrColumnCells(editor, index, orientation, tablePos);
|
|
520
|
+
if (cellData.mergedCells.length > 0) {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
return cellData.cells.length > 0;
|
|
524
|
+
} catch {
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function duplicateRow({
|
|
529
|
+
editor,
|
|
530
|
+
index,
|
|
531
|
+
tablePos
|
|
532
|
+
}) {
|
|
533
|
+
try {
|
|
534
|
+
const originalRowCells = getRowOrColumnCells(
|
|
535
|
+
editor,
|
|
536
|
+
index,
|
|
537
|
+
"row",
|
|
538
|
+
tablePos
|
|
539
|
+
);
|
|
540
|
+
if (originalRowCells.cells.length === 0) {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
let addSuccess = false;
|
|
544
|
+
if (editor.state.selection instanceof import_tables2.CellSelection) {
|
|
545
|
+
addSuccess = editor.chain().focus().addRowAfter().run();
|
|
546
|
+
} else {
|
|
547
|
+
if (!tablePos) return false;
|
|
548
|
+
const sourceCoords = getIndexCoordinates({
|
|
549
|
+
editor,
|
|
550
|
+
index,
|
|
551
|
+
orientation: "row",
|
|
552
|
+
tablePos
|
|
553
|
+
});
|
|
554
|
+
if (!sourceCoords) return false;
|
|
555
|
+
const state2 = selectCellsByCoords(editor, tablePos, sourceCoords, {
|
|
556
|
+
mode: "state"
|
|
557
|
+
});
|
|
558
|
+
addSuccess = (0, import_tables2.addRowAfter)(state2, editor.view.dispatch);
|
|
559
|
+
}
|
|
560
|
+
if (!addSuccess) return false;
|
|
561
|
+
const newRowCells = getRowOrColumnCells(editor, index + 1, "row", tablePos);
|
|
562
|
+
if (newRowCells.cells.length === 0) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
const { state, view } = editor;
|
|
566
|
+
const tr = state.tr;
|
|
567
|
+
const cellsToReplace = [...newRowCells.cells].reverse();
|
|
568
|
+
const originalCells = [...originalRowCells.cells].reverse();
|
|
569
|
+
cellsToReplace.forEach((newCell, reverseIndex) => {
|
|
570
|
+
const originalCell = originalCells[reverseIndex];
|
|
571
|
+
if (newCell.node && (originalCell == null ? void 0 : originalCell.node)) {
|
|
572
|
+
const duplicatedCell = newCell.node.type.create(
|
|
573
|
+
{ ...originalCell.node.attrs },
|
|
574
|
+
originalCell.node.content,
|
|
575
|
+
originalCell.node.marks
|
|
576
|
+
);
|
|
577
|
+
const cellEnd = newCell.pos + newCell.node.nodeSize;
|
|
578
|
+
tr.replaceWith(newCell.pos, cellEnd, duplicatedCell);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
if (tr.docChanged) {
|
|
582
|
+
view.dispatch(tr);
|
|
583
|
+
updateSelectionAfterAction(editor, "row", index + 1, tablePos);
|
|
584
|
+
return true;
|
|
585
|
+
}
|
|
586
|
+
return false;
|
|
587
|
+
} catch (error) {
|
|
588
|
+
console.error("Error duplicating row:", error);
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function duplicateColumn({
|
|
593
|
+
editor,
|
|
594
|
+
index,
|
|
595
|
+
tablePos
|
|
596
|
+
}) {
|
|
597
|
+
try {
|
|
598
|
+
const originalColumnCells = getRowOrColumnCells(
|
|
599
|
+
editor,
|
|
600
|
+
index,
|
|
601
|
+
"column",
|
|
602
|
+
tablePos
|
|
603
|
+
);
|
|
604
|
+
if (originalColumnCells.cells.length === 0) return false;
|
|
605
|
+
let addSuccess = false;
|
|
606
|
+
if (editor.state.selection instanceof import_tables2.CellSelection) {
|
|
607
|
+
addSuccess = editor.chain().focus().addColumnAfter().run();
|
|
608
|
+
} else {
|
|
609
|
+
if (!tablePos) return false;
|
|
610
|
+
const sourceCoords = getIndexCoordinates({
|
|
611
|
+
editor,
|
|
612
|
+
index,
|
|
613
|
+
orientation: "column",
|
|
614
|
+
tablePos
|
|
615
|
+
});
|
|
616
|
+
if (!sourceCoords) return false;
|
|
617
|
+
const state2 = selectCellsByCoords(editor, tablePos, sourceCoords, {
|
|
618
|
+
mode: "state"
|
|
619
|
+
});
|
|
620
|
+
addSuccess = (0, import_tables2.addColumnAfter)(state2, editor.view.dispatch);
|
|
621
|
+
}
|
|
622
|
+
if (!addSuccess) return false;
|
|
623
|
+
const newColumnCells = getRowOrColumnCells(
|
|
624
|
+
editor,
|
|
625
|
+
index + 1,
|
|
626
|
+
"column",
|
|
627
|
+
tablePos
|
|
628
|
+
);
|
|
629
|
+
if (newColumnCells.cells.length === 0) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
const { state, view } = editor;
|
|
633
|
+
const tr = state.tr;
|
|
634
|
+
const cellsToReplace = [...newColumnCells.cells].reverse();
|
|
635
|
+
const originalCells = [...originalColumnCells.cells].reverse();
|
|
636
|
+
cellsToReplace.forEach((newCell, reverseIndex) => {
|
|
637
|
+
const originalCell = originalCells[reverseIndex];
|
|
638
|
+
if (newCell.node && (originalCell == null ? void 0 : originalCell.node)) {
|
|
639
|
+
const duplicatedCell = newCell.node.type.create(
|
|
640
|
+
{ ...originalCell.node.attrs },
|
|
641
|
+
originalCell.node.content,
|
|
642
|
+
originalCell.node.marks
|
|
643
|
+
);
|
|
644
|
+
const cellEnd = newCell.pos + newCell.node.nodeSize;
|
|
645
|
+
tr.replaceWith(newCell.pos, cellEnd, duplicatedCell);
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
if (tr.docChanged) {
|
|
649
|
+
view.dispatch(tr);
|
|
650
|
+
updateSelectionAfterAction(editor, "column", index + 1, tablePos);
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
return false;
|
|
654
|
+
} catch (error) {
|
|
655
|
+
console.error("Error duplicating column:", error);
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function tableDuplicateRowColumn({
|
|
660
|
+
editor,
|
|
661
|
+
index,
|
|
662
|
+
orientation,
|
|
663
|
+
tablePos
|
|
664
|
+
}) {
|
|
665
|
+
if (!canDuplicateRowColumn({ editor, index, orientation, tablePos }) || !editor) {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
const table = getTable(editor, tablePos);
|
|
669
|
+
if (!table) return false;
|
|
670
|
+
const selectionType = getTableSelectionType(
|
|
671
|
+
editor,
|
|
672
|
+
index,
|
|
673
|
+
orientation,
|
|
674
|
+
tablePos
|
|
675
|
+
);
|
|
676
|
+
if (!selectionType) return false;
|
|
677
|
+
try {
|
|
678
|
+
if (selectionType.orientation === "row") {
|
|
679
|
+
return duplicateRow({
|
|
680
|
+
editor,
|
|
681
|
+
index: selectionType.index,
|
|
682
|
+
tablePos
|
|
683
|
+
});
|
|
684
|
+
} else if (selectionType.orientation === "column") {
|
|
685
|
+
return duplicateColumn({
|
|
686
|
+
editor,
|
|
687
|
+
index: selectionType.index,
|
|
688
|
+
tablePos
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
return false;
|
|
692
|
+
} catch (error) {
|
|
693
|
+
console.error("Error duplicating row/column:", error);
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function shouldShowButton({
|
|
698
|
+
editor,
|
|
699
|
+
index,
|
|
700
|
+
orientation,
|
|
701
|
+
hideWhenUnavailable
|
|
702
|
+
}) {
|
|
703
|
+
if (!editor || !editor.isEditable) return false;
|
|
704
|
+
if (!(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) return false;
|
|
705
|
+
return hideWhenUnavailable ? canDuplicateRowColumn({ editor, index, orientation }) : true;
|
|
706
|
+
}
|
|
707
|
+
function useTableDuplicateRowColumn(config) {
|
|
708
|
+
const {
|
|
709
|
+
editor: providedEditor,
|
|
710
|
+
index,
|
|
711
|
+
orientation,
|
|
712
|
+
tablePos,
|
|
713
|
+
hideWhenUnavailable = false,
|
|
714
|
+
onDuplicated
|
|
715
|
+
} = config;
|
|
716
|
+
const { editor } = (0, import_editor_utils.useTiptapEditor)(providedEditor);
|
|
717
|
+
const intl = (0, import_i18n2.useSafeIntl)();
|
|
718
|
+
const selectionType = getTableSelectionType(editor, index, orientation);
|
|
719
|
+
const isVisible = shouldShowButton({
|
|
720
|
+
editor,
|
|
721
|
+
index,
|
|
722
|
+
orientation,
|
|
723
|
+
hideWhenUnavailable
|
|
724
|
+
});
|
|
725
|
+
const canPerformDuplicate = canDuplicateRowColumn({
|
|
726
|
+
editor,
|
|
727
|
+
index,
|
|
728
|
+
tablePos,
|
|
729
|
+
orientation
|
|
730
|
+
});
|
|
731
|
+
const handleDuplicate = (0, import_react.useCallback)(() => {
|
|
732
|
+
const success = tableDuplicateRowColumn({
|
|
733
|
+
editor,
|
|
734
|
+
index,
|
|
735
|
+
orientation,
|
|
736
|
+
tablePos
|
|
737
|
+
});
|
|
738
|
+
if (success) onDuplicated == null ? void 0 : onDuplicated();
|
|
739
|
+
return success;
|
|
740
|
+
}, [editor, index, orientation, tablePos, onDuplicated]);
|
|
741
|
+
const label = (0, import_react.useMemo)(() => {
|
|
742
|
+
return intl.formatMessage(
|
|
743
|
+
duplicateMessageKeys[(selectionType == null ? void 0 : selectionType.orientation) || "row"]
|
|
744
|
+
);
|
|
745
|
+
}, [intl, selectionType]);
|
|
746
|
+
const Icon = import_icons.CopyIcon;
|
|
747
|
+
return {
|
|
748
|
+
isVisible,
|
|
749
|
+
canDuplicateRowColumn: canPerformDuplicate,
|
|
750
|
+
handleDuplicate,
|
|
751
|
+
label,
|
|
752
|
+
Icon
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
756
|
+
0 && (module.exports = {
|
|
757
|
+
useTableDuplicateRowColumn
|
|
758
|
+
});
|