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