@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.
- 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-SNJF4UW6.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/{table/icons.mjs → extensions/table-cell.mjs} +3 -3
- 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 +18 -5
- package/dist/index.d.ts +18 -5
- package/dist/index.js +4939 -910
- package/dist/index.mjs +43 -18
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/{table-row.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 +16 -12
- package/dist/chunk-6NY5XWR7.mjs +0 -11
- package/dist/chunk-74O2ORPO.mjs +0 -81
- package/dist/chunk-7NEAULTF.mjs +0 -58
- package/dist/chunk-ARSGMUXM.mjs +0 -116
- package/dist/chunk-BAQU2YT5.mjs +0 -41
- package/dist/chunk-DF6ZMJLL.mjs +0 -40
- package/dist/chunk-FKOIW52J.mjs +0 -11
- package/dist/chunk-GMNNSVR3.mjs +0 -540
- package/dist/chunk-IMRHHVEF.mjs +0 -113
- package/dist/chunk-NTWXQSW6.mjs +0 -13
- package/dist/chunk-OPDSKEZR.mjs +0 -93
- package/dist/chunk-YSUOVRY4.mjs +0 -1
- package/dist/kit.js +0 -1024
- package/dist/kit.mjs +0 -19
- package/dist/table/icons.d.mts +0 -13
- package/dist/table/icons.d.ts +0 -13
- package/dist/table/icons.js +0 -81
- package/dist/table/index.d.mts +0 -3
- package/dist/table/index.d.ts +0 -3
- package/dist/table/index.js +0 -809
- package/dist/table/index.mjs +0 -15
- package/dist/table/table-controls.d.mts +0 -15
- package/dist/table/table-controls.d.ts +0 -15
- package/dist/table/table-controls.js +0 -131
- package/dist/table/table-controls.mjs +0 -8
- package/dist/table/table-view.d.mts +0 -43
- package/dist/table/table-view.d.ts +0 -43
- package/dist/table/table-view.js +0 -610
- package/dist/table/table-view.mjs +0 -12
- package/dist/table/table.js +0 -807
- package/dist/table/table.mjs +0 -14
- package/dist/table/utilities/col-style.d.mts +0 -3
- package/dist/table/utilities/col-style.d.ts +0 -3
- package/dist/table/utilities/col-style.js +0 -36
- package/dist/table/utilities/col-style.mjs +0 -8
- package/dist/table/utilities/delete-table-when-all-cells-selected.d.mts +0 -5
- package/dist/table/utilities/delete-table-when-all-cells-selected.d.ts +0 -5
- package/dist/table/utilities/delete-table-when-all-cells-selected.js +0 -66
- package/dist/table/utilities/delete-table-when-all-cells-selected.mjs +0 -40
- package/dist/table/utilities/get-table-node-types.d.mts +0 -7
- package/dist/table/utilities/get-table-node-types.d.ts +0 -7
- package/dist/table/utilities/get-table-node-types.js +0 -44
- package/dist/table/utilities/get-table-node-types.mjs +0 -21
- package/dist/table/utilities/insert-line-above-table-action.d.mts +0 -5
- package/dist/table/utilities/insert-line-above-table-action.d.ts +0 -5
- package/dist/table/utilities/insert-line-above-table-action.js +0 -64
- package/dist/table/utilities/insert-line-above-table-action.mjs +0 -8
- package/dist/table/utilities/insert-line-below-table-action.d.mts +0 -5
- package/dist/table/utilities/insert-line-below-table-action.d.ts +0 -5
- package/dist/table/utilities/insert-line-below-table-action.js +0 -63
- package/dist/table/utilities/insert-line-below-table-action.mjs +0 -8
- package/dist/table/utilities/is-cell-selection.d.mts +0 -5
- package/dist/table/utilities/is-cell-selection.d.ts +0 -5
- package/dist/table/utilities/is-cell-selection.js +0 -34
- package/dist/table/utilities/is-cell-selection.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 -139
- 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 -104
- package/dist/table-header.mjs +0 -8
- package/dist/table-row.d.mts +0 -6
- package/dist/table-row.d.ts +0 -6
|
@@ -0,0 +1,1317 @@
|
|
|
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/ui/table-cell-handle-menu.tsx
|
|
23
|
+
var table_cell_handle_menu_exports = {};
|
|
24
|
+
__export(table_cell_handle_menu_exports, {
|
|
25
|
+
TableActionMenu: () => TableActionMenu,
|
|
26
|
+
TableCellHandleMenu: () => TableCellHandleMenu
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(table_cell_handle_menu_exports);
|
|
29
|
+
var import_dropdown_menu2 = require("@kopexa/dropdown-menu");
|
|
30
|
+
var import_editor_utils4 = require("@kopexa/editor-utils");
|
|
31
|
+
var import_i18n6 = require("@kopexa/i18n");
|
|
32
|
+
var import_icons5 = require("@kopexa/icons");
|
|
33
|
+
var import_shared_utils3 = require("@kopexa/shared-utils");
|
|
34
|
+
var import_theme = require("@kopexa/theme");
|
|
35
|
+
var import_react4 = require("react");
|
|
36
|
+
|
|
37
|
+
// src/hooks/use-table-clear-row-column-content.ts
|
|
38
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
39
|
+
var import_i18n2 = require("@kopexa/i18n");
|
|
40
|
+
var import_icons = require("@kopexa/icons");
|
|
41
|
+
var import_tables2 = require("@tiptap/pm/tables");
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
|
|
44
|
+
// src/lib/table-utils.ts
|
|
45
|
+
var import_shared_utils = require("@kopexa/shared-utils");
|
|
46
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
47
|
+
var EMPTY_CELLS_RESULT = { cells: [], mergedCells: [] };
|
|
48
|
+
function collectCells(editor, orientation, index, tablePos) {
|
|
49
|
+
if (!editor) return EMPTY_CELLS_RESULT;
|
|
50
|
+
const { state } = editor;
|
|
51
|
+
const table = getTable(editor, tablePos);
|
|
52
|
+
if (!table) return EMPTY_CELLS_RESULT;
|
|
53
|
+
const tableStart = table.start;
|
|
54
|
+
const tableNode = table.node;
|
|
55
|
+
const map = table.map;
|
|
56
|
+
const resolvedIndex = resolveOrientationIndex(
|
|
57
|
+
state,
|
|
58
|
+
table,
|
|
59
|
+
orientation,
|
|
60
|
+
index
|
|
61
|
+
);
|
|
62
|
+
if (resolvedIndex === null) return EMPTY_CELLS_RESULT;
|
|
63
|
+
const maxIndex = orientation === "row" ? map.height : map.width;
|
|
64
|
+
if (resolvedIndex < 0 || resolvedIndex >= maxIndex) {
|
|
65
|
+
return EMPTY_CELLS_RESULT;
|
|
66
|
+
}
|
|
67
|
+
const cells = [];
|
|
68
|
+
const mergedCells = [];
|
|
69
|
+
const seenMerged = /* @__PURE__ */ new Set();
|
|
70
|
+
const iterationCount = orientation === "row" ? map.width : map.height;
|
|
71
|
+
for (let i = 0; i < iterationCount; i++) {
|
|
72
|
+
const row = orientation === "row" ? resolvedIndex : i;
|
|
73
|
+
const col = orientation === "row" ? i : resolvedIndex;
|
|
74
|
+
const cellIndex = row * map.width + col;
|
|
75
|
+
const mapCell = map.map[cellIndex];
|
|
76
|
+
if (mapCell === void 0) continue;
|
|
77
|
+
const cellPos = tableStart + mapCell;
|
|
78
|
+
const cellNode = tableNode.nodeAt(mapCell);
|
|
79
|
+
if (!cellNode) continue;
|
|
80
|
+
const cell = createCellInfo(row, col, cellPos, cellNode);
|
|
81
|
+
if (isCellMerged(cellNode)) {
|
|
82
|
+
if (!seenMerged.has(cellPos)) {
|
|
83
|
+
mergedCells.push(cell);
|
|
84
|
+
seenMerged.add(cellPos);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
cells.push(cell);
|
|
88
|
+
}
|
|
89
|
+
return { cells, mergedCells };
|
|
90
|
+
}
|
|
91
|
+
function isCellMerged(node) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
if (!node) return false;
|
|
94
|
+
const colspan = (_a = node.attrs.colspan) != null ? _a : 1;
|
|
95
|
+
const rowspan = (_b = node.attrs.rowspan) != null ? _b : 1;
|
|
96
|
+
return colspan > 1 || rowspan > 1;
|
|
97
|
+
}
|
|
98
|
+
function getTable(editor, tablePos) {
|
|
99
|
+
if (!editor) return null;
|
|
100
|
+
let table = null;
|
|
101
|
+
if (typeof tablePos === "number") {
|
|
102
|
+
const tableNode = editor.state.doc.nodeAt(tablePos);
|
|
103
|
+
if ((tableNode == null ? void 0 : tableNode.type.name) === "table") {
|
|
104
|
+
table = {
|
|
105
|
+
node: tableNode,
|
|
106
|
+
pos: tablePos,
|
|
107
|
+
start: tablePos + 1,
|
|
108
|
+
depth: editor.state.doc.resolve(tablePos).depth
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!table) {
|
|
113
|
+
const { state } = editor;
|
|
114
|
+
const $from = state.doc.resolve(state.selection.from);
|
|
115
|
+
table = (0, import_tables.findTable)($from);
|
|
116
|
+
}
|
|
117
|
+
if (!table) return null;
|
|
118
|
+
const tableMap = import_tables.TableMap.get(table.node);
|
|
119
|
+
if (!tableMap) return null;
|
|
120
|
+
return { ...table, map: tableMap };
|
|
121
|
+
}
|
|
122
|
+
function createCellInfo(row, column, cellPos, cellNode) {
|
|
123
|
+
return {
|
|
124
|
+
row,
|
|
125
|
+
column,
|
|
126
|
+
pos: cellPos,
|
|
127
|
+
node: cellNode,
|
|
128
|
+
start: cellPos + 1,
|
|
129
|
+
depth: cellNode ? cellNode.content.size : 0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function resolveOrientationIndex(state, table, orientation, providedIndex) {
|
|
133
|
+
var _a;
|
|
134
|
+
if (typeof providedIndex === "number") {
|
|
135
|
+
return providedIndex;
|
|
136
|
+
}
|
|
137
|
+
if (state.selection instanceof import_tables.CellSelection) {
|
|
138
|
+
const rect2 = (0, import_tables.selectedRect)(state);
|
|
139
|
+
return orientation === "row" ? rect2.top : rect2.left;
|
|
140
|
+
}
|
|
141
|
+
const $cell = (_a = (0, import_tables.cellAround)(state.selection.$anchor)) != null ? _a : (0, import_tables.selectionCell)(state);
|
|
142
|
+
if (!$cell) return null;
|
|
143
|
+
const rel = $cell.pos - table.start;
|
|
144
|
+
const rect = table.map.findCell(rel);
|
|
145
|
+
return orientation === "row" ? rect.top : rect.left;
|
|
146
|
+
}
|
|
147
|
+
function getTableSelectionType(editor, index, orientation, tablePos) {
|
|
148
|
+
if (typeof index === "number" && orientation) {
|
|
149
|
+
return { orientation, index };
|
|
150
|
+
}
|
|
151
|
+
if (!editor) return null;
|
|
152
|
+
const { state } = editor;
|
|
153
|
+
const table = getTable(editor, tablePos);
|
|
154
|
+
if (!table) return null;
|
|
155
|
+
if (state.selection instanceof import_tables.CellSelection) {
|
|
156
|
+
const rect = (0, import_tables.selectedRect)(state);
|
|
157
|
+
const map = import_tables.TableMap.get(table.node);
|
|
158
|
+
const width = rect.right - rect.left;
|
|
159
|
+
const height = rect.bottom - rect.top;
|
|
160
|
+
if (height === 1 && width === map.width) {
|
|
161
|
+
return { orientation: "row", index: rect.top };
|
|
162
|
+
}
|
|
163
|
+
if (width === 1 && height === map.height) {
|
|
164
|
+
return { orientation: "column", index: rect.left };
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function getRowOrColumnCells(editor, index, orientation, tablePos) {
|
|
171
|
+
const emptyResult = {
|
|
172
|
+
cells: [],
|
|
173
|
+
mergedCells: [],
|
|
174
|
+
index: void 0,
|
|
175
|
+
orientation: void 0,
|
|
176
|
+
tablePos: void 0
|
|
177
|
+
};
|
|
178
|
+
if (!editor) {
|
|
179
|
+
return emptyResult;
|
|
180
|
+
}
|
|
181
|
+
if (typeof index !== "number" && !(editor.state.selection instanceof import_tables.CellSelection)) {
|
|
182
|
+
return emptyResult;
|
|
183
|
+
}
|
|
184
|
+
let finalIndex = index;
|
|
185
|
+
let finalOrientation = orientation;
|
|
186
|
+
if (typeof finalIndex !== "number" || !finalOrientation || !["row", "column"].includes(finalOrientation)) {
|
|
187
|
+
const selectionType = getTableSelectionType(editor);
|
|
188
|
+
if (!selectionType) return emptyResult;
|
|
189
|
+
finalIndex = selectionType.index;
|
|
190
|
+
finalOrientation = selectionType.orientation;
|
|
191
|
+
}
|
|
192
|
+
const result = collectCells(editor, finalOrientation, finalIndex, tablePos);
|
|
193
|
+
return { ...result, index: finalIndex, orientation: finalOrientation };
|
|
194
|
+
}
|
|
195
|
+
function isCellEmpty(cellNode) {
|
|
196
|
+
if (cellNode.childCount === 0) return true;
|
|
197
|
+
let isEmpty = true;
|
|
198
|
+
cellNode.descendants((n) => {
|
|
199
|
+
var _a;
|
|
200
|
+
if (n.isText && ((_a = n.text) == null ? void 0 : _a.trim())) {
|
|
201
|
+
isEmpty = false;
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
if (n.isLeaf && !n.isText) {
|
|
205
|
+
isEmpty = false;
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
});
|
|
210
|
+
return isEmpty;
|
|
211
|
+
}
|
|
212
|
+
function setCellAttr(nameOrAttrs, value) {
|
|
213
|
+
return (state, dispatch) => {
|
|
214
|
+
var _a;
|
|
215
|
+
if (!(0, import_tables.isInTable)(state)) return false;
|
|
216
|
+
const $cell = (0, import_tables.selectionCell)(state);
|
|
217
|
+
const attrs = typeof nameOrAttrs === "string" ? { [nameOrAttrs]: value } : nameOrAttrs;
|
|
218
|
+
if (dispatch) {
|
|
219
|
+
const tr = state.tr;
|
|
220
|
+
if (state.selection instanceof import_tables.CellSelection) {
|
|
221
|
+
state.selection.forEachCell((node, pos) => {
|
|
222
|
+
const needsUpdate = Object.entries(attrs).some(
|
|
223
|
+
([name, val]) => node.attrs[name] !== val
|
|
224
|
+
);
|
|
225
|
+
if (needsUpdate) {
|
|
226
|
+
tr.setNodeMarkup(pos, null, {
|
|
227
|
+
...node.attrs,
|
|
228
|
+
...attrs
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
const needsUpdate = Object.entries(attrs).some(
|
|
234
|
+
([name, val]) => {
|
|
235
|
+
var _a2;
|
|
236
|
+
return ((_a2 = $cell.nodeAfter) == null ? void 0 : _a2.attrs[name]) !== val;
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
if (needsUpdate) {
|
|
240
|
+
tr.setNodeMarkup($cell.pos, null, {
|
|
241
|
+
...(_a = $cell.nodeAfter) == null ? void 0 : _a.attrs,
|
|
242
|
+
...attrs
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
dispatch(tr);
|
|
247
|
+
}
|
|
248
|
+
return true;
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/messages.ts
|
|
253
|
+
var import_i18n = require("@kopexa/i18n");
|
|
254
|
+
var messages = (0, import_i18n.defineMessages)({
|
|
255
|
+
// Row/Column actions (aria labels)
|
|
256
|
+
row_actions: {
|
|
257
|
+
id: "editor.table.row_actions",
|
|
258
|
+
defaultMessage: "Row actions",
|
|
259
|
+
description: "ARIA label for row actions menu button"
|
|
260
|
+
},
|
|
261
|
+
column_actions: {
|
|
262
|
+
id: "editor.table.column_actions",
|
|
263
|
+
defaultMessage: "Column actions",
|
|
264
|
+
description: "ARIA label for column actions menu button"
|
|
265
|
+
},
|
|
266
|
+
cell_options: {
|
|
267
|
+
id: "editor.table.cell_options",
|
|
268
|
+
defaultMessage: "Table cells option",
|
|
269
|
+
description: "ARIA label for cell options menu button"
|
|
270
|
+
},
|
|
271
|
+
// Alignment
|
|
272
|
+
alignment: {
|
|
273
|
+
id: "editor.table.alignment",
|
|
274
|
+
defaultMessage: "Alignment",
|
|
275
|
+
description: "Label for alignment submenu"
|
|
276
|
+
},
|
|
277
|
+
align_left: {
|
|
278
|
+
id: "editor.table.align_left",
|
|
279
|
+
defaultMessage: "Align left",
|
|
280
|
+
description: "Label for align left action"
|
|
281
|
+
},
|
|
282
|
+
align_center: {
|
|
283
|
+
id: "editor.table.align_center",
|
|
284
|
+
defaultMessage: "Align center",
|
|
285
|
+
description: "Label for align center action"
|
|
286
|
+
},
|
|
287
|
+
align_right: {
|
|
288
|
+
id: "editor.table.align_right",
|
|
289
|
+
defaultMessage: "Align right",
|
|
290
|
+
description: "Label for align right action"
|
|
291
|
+
},
|
|
292
|
+
justify: {
|
|
293
|
+
id: "editor.table.justify",
|
|
294
|
+
defaultMessage: "Justify",
|
|
295
|
+
description: "Label for justify action"
|
|
296
|
+
},
|
|
297
|
+
align_top: {
|
|
298
|
+
id: "editor.table.align_top",
|
|
299
|
+
defaultMessage: "Align top",
|
|
300
|
+
description: "Label for vertical align top action"
|
|
301
|
+
},
|
|
302
|
+
align_middle: {
|
|
303
|
+
id: "editor.table.align_middle",
|
|
304
|
+
defaultMessage: "Align middle",
|
|
305
|
+
description: "Label for vertical align middle action"
|
|
306
|
+
},
|
|
307
|
+
align_bottom: {
|
|
308
|
+
id: "editor.table.align_bottom",
|
|
309
|
+
defaultMessage: "Align bottom",
|
|
310
|
+
description: "Label for vertical align bottom action"
|
|
311
|
+
},
|
|
312
|
+
// Add row/column
|
|
313
|
+
insert_row_above: {
|
|
314
|
+
id: "editor.table.insert_row_above",
|
|
315
|
+
defaultMessage: "Insert row above",
|
|
316
|
+
description: "Label for insert row above action"
|
|
317
|
+
},
|
|
318
|
+
insert_row_below: {
|
|
319
|
+
id: "editor.table.insert_row_below",
|
|
320
|
+
defaultMessage: "Insert row below",
|
|
321
|
+
description: "Label for insert row below action"
|
|
322
|
+
},
|
|
323
|
+
insert_column_left: {
|
|
324
|
+
id: "editor.table.insert_column_left",
|
|
325
|
+
defaultMessage: "Insert column left",
|
|
326
|
+
description: "Label for insert column left action"
|
|
327
|
+
},
|
|
328
|
+
insert_column_right: {
|
|
329
|
+
id: "editor.table.insert_column_right",
|
|
330
|
+
defaultMessage: "Insert column right",
|
|
331
|
+
description: "Label for insert column right action"
|
|
332
|
+
},
|
|
333
|
+
// Delete row/column
|
|
334
|
+
delete_row: {
|
|
335
|
+
id: "editor.table.delete_row",
|
|
336
|
+
defaultMessage: "Delete row",
|
|
337
|
+
description: "Label for delete row action"
|
|
338
|
+
},
|
|
339
|
+
delete_column: {
|
|
340
|
+
id: "editor.table.delete_column",
|
|
341
|
+
defaultMessage: "Delete column",
|
|
342
|
+
description: "Label for delete column action"
|
|
343
|
+
},
|
|
344
|
+
// Move row/column
|
|
345
|
+
move_row_up: {
|
|
346
|
+
id: "editor.table.move_row_up",
|
|
347
|
+
defaultMessage: "Move row up",
|
|
348
|
+
description: "Label for move row up action"
|
|
349
|
+
},
|
|
350
|
+
move_row_down: {
|
|
351
|
+
id: "editor.table.move_row_down",
|
|
352
|
+
defaultMessage: "Move row down",
|
|
353
|
+
description: "Label for move row down action"
|
|
354
|
+
},
|
|
355
|
+
move_column_left: {
|
|
356
|
+
id: "editor.table.move_column_left",
|
|
357
|
+
defaultMessage: "Move column left",
|
|
358
|
+
description: "Label for move column left action"
|
|
359
|
+
},
|
|
360
|
+
move_column_right: {
|
|
361
|
+
id: "editor.table.move_column_right",
|
|
362
|
+
defaultMessage: "Move column right",
|
|
363
|
+
description: "Label for move column right action"
|
|
364
|
+
},
|
|
365
|
+
// Sort
|
|
366
|
+
sort_row_asc: {
|
|
367
|
+
id: "editor.table.sort_row_asc",
|
|
368
|
+
defaultMessage: "Sort row A-Z",
|
|
369
|
+
description: "Label for sort row ascending action"
|
|
370
|
+
},
|
|
371
|
+
sort_row_desc: {
|
|
372
|
+
id: "editor.table.sort_row_desc",
|
|
373
|
+
defaultMessage: "Sort row Z-A",
|
|
374
|
+
description: "Label for sort row descending action"
|
|
375
|
+
},
|
|
376
|
+
sort_column_asc: {
|
|
377
|
+
id: "editor.table.sort_column_asc",
|
|
378
|
+
defaultMessage: "Sort column A-Z",
|
|
379
|
+
description: "Label for sort column ascending action"
|
|
380
|
+
},
|
|
381
|
+
sort_column_desc: {
|
|
382
|
+
id: "editor.table.sort_column_desc",
|
|
383
|
+
defaultMessage: "Sort column Z-A",
|
|
384
|
+
description: "Label for sort column descending action"
|
|
385
|
+
},
|
|
386
|
+
// Duplicate
|
|
387
|
+
duplicate_row: {
|
|
388
|
+
id: "editor.table.duplicate_row",
|
|
389
|
+
defaultMessage: "Duplicate row",
|
|
390
|
+
description: "Label for duplicate row action"
|
|
391
|
+
},
|
|
392
|
+
duplicate_column: {
|
|
393
|
+
id: "editor.table.duplicate_column",
|
|
394
|
+
defaultMessage: "Duplicate column",
|
|
395
|
+
description: "Label for duplicate column action"
|
|
396
|
+
},
|
|
397
|
+
// Header
|
|
398
|
+
header_row: {
|
|
399
|
+
id: "editor.table.header_row",
|
|
400
|
+
defaultMessage: "Header row",
|
|
401
|
+
description: "Label for toggle header row action"
|
|
402
|
+
},
|
|
403
|
+
header_column: {
|
|
404
|
+
id: "editor.table.header_column",
|
|
405
|
+
defaultMessage: "Header column",
|
|
406
|
+
description: "Label for toggle header column action"
|
|
407
|
+
},
|
|
408
|
+
// Merge/Split
|
|
409
|
+
merge_cells: {
|
|
410
|
+
id: "editor.table.merge_cells",
|
|
411
|
+
defaultMessage: "Merge cells",
|
|
412
|
+
description: "Label for merge cells action"
|
|
413
|
+
},
|
|
414
|
+
split_cell: {
|
|
415
|
+
id: "editor.table.split_cell",
|
|
416
|
+
defaultMessage: "Split cell",
|
|
417
|
+
description: "Label for split cell action"
|
|
418
|
+
},
|
|
419
|
+
// Clear contents
|
|
420
|
+
clear_row_contents: {
|
|
421
|
+
id: "editor.table.clear_row_contents",
|
|
422
|
+
defaultMessage: "Clear row contents",
|
|
423
|
+
description: "Label for clear row contents action"
|
|
424
|
+
},
|
|
425
|
+
clear_column_contents: {
|
|
426
|
+
id: "editor.table.clear_column_contents",
|
|
427
|
+
defaultMessage: "Clear column contents",
|
|
428
|
+
description: "Label for clear column contents action"
|
|
429
|
+
},
|
|
430
|
+
clear_contents: {
|
|
431
|
+
id: "editor.table.clear_contents",
|
|
432
|
+
defaultMessage: "Clear contents",
|
|
433
|
+
description: "Label for clear contents action (generic)"
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// src/hooks/use-table-clear-row-column-content.ts
|
|
438
|
+
var REQUIRED_EXTENSIONS = ["table"];
|
|
439
|
+
var clearMessageKeys = {
|
|
440
|
+
row: messages.clear_row_contents,
|
|
441
|
+
column: messages.clear_column_contents
|
|
442
|
+
};
|
|
443
|
+
var DEFAULT_CELL_ATTRS = {
|
|
444
|
+
backgroundColor: null,
|
|
445
|
+
nodeVerticalAlign: null,
|
|
446
|
+
nodeTextAlign: null
|
|
447
|
+
};
|
|
448
|
+
function canClearRowColumnContent({
|
|
449
|
+
editor,
|
|
450
|
+
index,
|
|
451
|
+
orientation,
|
|
452
|
+
tablePos
|
|
453
|
+
}) {
|
|
454
|
+
if (!editor || !editor.isEditable || !(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
try {
|
|
458
|
+
const table = getTable(editor, tablePos);
|
|
459
|
+
if (!table) return false;
|
|
460
|
+
const selectionType = getTableSelectionType(
|
|
461
|
+
editor,
|
|
462
|
+
index,
|
|
463
|
+
orientation,
|
|
464
|
+
tablePos
|
|
465
|
+
);
|
|
466
|
+
if (selectionType) {
|
|
467
|
+
const cellData = getRowOrColumnCells(
|
|
468
|
+
editor,
|
|
469
|
+
selectionType.index,
|
|
470
|
+
selectionType.orientation,
|
|
471
|
+
tablePos
|
|
472
|
+
);
|
|
473
|
+
if (cellData.cells.length === 0) return false;
|
|
474
|
+
return cellData.cells.some(
|
|
475
|
+
(cellInfo) => cellInfo.node && !isCellEmpty(cellInfo.node)
|
|
476
|
+
);
|
|
477
|
+
} else {
|
|
478
|
+
const { selection } = editor.state;
|
|
479
|
+
if (selection instanceof import_tables2.CellSelection) {
|
|
480
|
+
let hasContent = false;
|
|
481
|
+
selection.forEachCell((cell2) => {
|
|
482
|
+
if (!isCellEmpty(cell2)) {
|
|
483
|
+
hasContent = true;
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
return hasContent;
|
|
487
|
+
}
|
|
488
|
+
const { $anchor } = selection;
|
|
489
|
+
const cell = (0, import_tables2.cellAround)($anchor);
|
|
490
|
+
if (!cell) return false;
|
|
491
|
+
const cellNode = editor.state.doc.nodeAt(cell.pos);
|
|
492
|
+
return cellNode ? !isCellEmpty(cellNode) : false;
|
|
493
|
+
}
|
|
494
|
+
} catch {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function clearSelectedCells(editor, resetAttrs = false) {
|
|
499
|
+
try {
|
|
500
|
+
const { state, view } = editor;
|
|
501
|
+
const { selection } = state;
|
|
502
|
+
if (selection instanceof import_tables2.CellSelection) {
|
|
503
|
+
if (resetAttrs) {
|
|
504
|
+
const attrSuccess = setCellAttr(DEFAULT_CELL_ATTRS)(
|
|
505
|
+
state,
|
|
506
|
+
view.dispatch
|
|
507
|
+
);
|
|
508
|
+
(0, import_tables2.deleteCellSelection)(editor.state, view.dispatch);
|
|
509
|
+
return attrSuccess;
|
|
510
|
+
}
|
|
511
|
+
(0, import_tables2.deleteCellSelection)(state, view.dispatch);
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
const { $anchor } = selection;
|
|
515
|
+
const cell = (0, import_tables2.cellAround)($anchor);
|
|
516
|
+
if (!cell) return false;
|
|
517
|
+
const cellNode = state.doc.nodeAt(cell.pos);
|
|
518
|
+
if (!cellNode) return false;
|
|
519
|
+
const from = cell.pos + 1;
|
|
520
|
+
const to = cell.pos + cellNode.nodeSize - 1;
|
|
521
|
+
if (from >= to) return false;
|
|
522
|
+
const tr = state.tr.delete(from, to);
|
|
523
|
+
if (resetAttrs) {
|
|
524
|
+
tr.setNodeMarkup(cell.pos, null, {
|
|
525
|
+
...cellNode.attrs,
|
|
526
|
+
...DEFAULT_CELL_ATTRS
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
view.dispatch(tr);
|
|
530
|
+
return true;
|
|
531
|
+
} catch (error) {
|
|
532
|
+
console.error("Error clearing selected cells:", error);
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function clearRowColumnCells({
|
|
537
|
+
editor,
|
|
538
|
+
index,
|
|
539
|
+
orientation,
|
|
540
|
+
tablePos,
|
|
541
|
+
resetAttrs = false
|
|
542
|
+
}) {
|
|
543
|
+
try {
|
|
544
|
+
const { state, view } = editor;
|
|
545
|
+
const tr = state.tr;
|
|
546
|
+
const cellData = getRowOrColumnCells(editor, index, orientation, tablePos);
|
|
547
|
+
if (cellData.cells.length === 0) {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
const cellsToProcess = [...cellData.cells].reverse();
|
|
551
|
+
cellsToProcess.forEach((cellInfo) => {
|
|
552
|
+
if (cellInfo.node && !isCellEmpty(cellInfo.node)) {
|
|
553
|
+
const from = cellInfo.pos + 1;
|
|
554
|
+
const to = cellInfo.pos + cellInfo.node.nodeSize - 1;
|
|
555
|
+
if (from < to) {
|
|
556
|
+
tr.delete(from, to);
|
|
557
|
+
}
|
|
558
|
+
if (resetAttrs) {
|
|
559
|
+
tr.setNodeMarkup(cellInfo.pos, null, {
|
|
560
|
+
...cellInfo.node.attrs,
|
|
561
|
+
...DEFAULT_CELL_ATTRS
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
if (tr.docChanged) {
|
|
567
|
+
view.dispatch(tr);
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
return false;
|
|
571
|
+
} catch (error) {
|
|
572
|
+
console.error(`Error clearing ${orientation} content:`, error);
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
function tableClearRowColumnContent({
|
|
577
|
+
editor,
|
|
578
|
+
index,
|
|
579
|
+
orientation,
|
|
580
|
+
tablePos,
|
|
581
|
+
resetAttrs = false
|
|
582
|
+
}) {
|
|
583
|
+
if (!canClearRowColumnContent({ editor, index, orientation, tablePos }) || !editor) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
try {
|
|
587
|
+
const selectionType = getTableSelectionType(
|
|
588
|
+
editor,
|
|
589
|
+
index,
|
|
590
|
+
orientation,
|
|
591
|
+
tablePos
|
|
592
|
+
);
|
|
593
|
+
if (selectionType) {
|
|
594
|
+
return clearRowColumnCells({
|
|
595
|
+
editor,
|
|
596
|
+
index: selectionType.index,
|
|
597
|
+
orientation: selectionType.orientation,
|
|
598
|
+
resetAttrs,
|
|
599
|
+
tablePos
|
|
600
|
+
});
|
|
601
|
+
} else {
|
|
602
|
+
return clearSelectedCells(editor, resetAttrs);
|
|
603
|
+
}
|
|
604
|
+
} catch (error) {
|
|
605
|
+
console.error("Error clearing table content:", error);
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function shouldShowButton({
|
|
610
|
+
editor,
|
|
611
|
+
index,
|
|
612
|
+
orientation,
|
|
613
|
+
tablePos,
|
|
614
|
+
hideWhenUnavailable
|
|
615
|
+
}) {
|
|
616
|
+
if (!editor || !editor.isEditable) return false;
|
|
617
|
+
if (!(0, import_editor_utils.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS)) return false;
|
|
618
|
+
const table = getTable(editor, tablePos);
|
|
619
|
+
if (!table) return false;
|
|
620
|
+
const selectionType = getTableSelectionType(
|
|
621
|
+
editor,
|
|
622
|
+
index,
|
|
623
|
+
orientation,
|
|
624
|
+
tablePos
|
|
625
|
+
);
|
|
626
|
+
const { selection } = editor.state;
|
|
627
|
+
const isInTableCell = selection instanceof import_tables2.CellSelection || (0, import_tables2.cellAround)(selection.$anchor);
|
|
628
|
+
if (!selectionType && !isInTableCell) return false;
|
|
629
|
+
return hideWhenUnavailable ? canClearRowColumnContent({ editor, index, orientation, tablePos }) : true;
|
|
630
|
+
}
|
|
631
|
+
function useTableClearRowColumnContent(config = {}) {
|
|
632
|
+
const {
|
|
633
|
+
editor: providedEditor,
|
|
634
|
+
index,
|
|
635
|
+
orientation,
|
|
636
|
+
tablePos,
|
|
637
|
+
hideWhenUnavailable = false,
|
|
638
|
+
resetAttrs = false,
|
|
639
|
+
onCleared
|
|
640
|
+
} = config;
|
|
641
|
+
const { editor } = (0, import_editor_utils.useTiptapEditor)(providedEditor);
|
|
642
|
+
const intl = (0, import_i18n2.useSafeIntl)();
|
|
643
|
+
const selectionType = getTableSelectionType(
|
|
644
|
+
editor,
|
|
645
|
+
index,
|
|
646
|
+
orientation,
|
|
647
|
+
tablePos
|
|
648
|
+
);
|
|
649
|
+
const isVisible = shouldShowButton({
|
|
650
|
+
editor,
|
|
651
|
+
index,
|
|
652
|
+
orientation,
|
|
653
|
+
tablePos,
|
|
654
|
+
hideWhenUnavailable
|
|
655
|
+
});
|
|
656
|
+
const canPerformClear = canClearRowColumnContent({
|
|
657
|
+
editor,
|
|
658
|
+
index,
|
|
659
|
+
orientation,
|
|
660
|
+
tablePos
|
|
661
|
+
});
|
|
662
|
+
const handleClear = (0, import_react.useCallback)(() => {
|
|
663
|
+
const success = tableClearRowColumnContent({
|
|
664
|
+
editor,
|
|
665
|
+
index,
|
|
666
|
+
orientation,
|
|
667
|
+
tablePos,
|
|
668
|
+
resetAttrs
|
|
669
|
+
});
|
|
670
|
+
if (success) onCleared == null ? void 0 : onCleared();
|
|
671
|
+
return success;
|
|
672
|
+
}, [editor, index, orientation, tablePos, resetAttrs, onCleared]);
|
|
673
|
+
const label = (0, import_react.useMemo)(() => {
|
|
674
|
+
if (selectionType) {
|
|
675
|
+
return intl.formatMessage(clearMessageKeys[selectionType.orientation]);
|
|
676
|
+
}
|
|
677
|
+
return intl.formatMessage(messages.clear_contents);
|
|
678
|
+
}, [intl, selectionType]);
|
|
679
|
+
const Icon = import_icons.SquareXIcon;
|
|
680
|
+
return {
|
|
681
|
+
isVisible,
|
|
682
|
+
canClearRowColumnContent: canPerformClear,
|
|
683
|
+
handleClear,
|
|
684
|
+
label,
|
|
685
|
+
Icon
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// src/hooks/use-table-merge-split-cell.ts
|
|
690
|
+
var import_editor_utils2 = require("@kopexa/editor-utils");
|
|
691
|
+
var import_i18n3 = require("@kopexa/i18n");
|
|
692
|
+
var import_icons2 = require("@kopexa/icons");
|
|
693
|
+
var import_tables3 = require("@tiptap/pm/tables");
|
|
694
|
+
var import_react2 = require("react");
|
|
695
|
+
var REQUIRED_EXTENSIONS2 = ["table"];
|
|
696
|
+
var mergeSplitMessageKeys = {
|
|
697
|
+
merge: messages.merge_cells,
|
|
698
|
+
split: messages.split_cell
|
|
699
|
+
};
|
|
700
|
+
var tableMergeSplitCellIcons = {
|
|
701
|
+
merge: import_icons2.TableCellMergeIcon,
|
|
702
|
+
split: import_icons2.TableCellSplitIcon
|
|
703
|
+
};
|
|
704
|
+
function canMergeCells(editor) {
|
|
705
|
+
if (!editor || !editor.isEditable || !(0, import_editor_utils2.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS2)) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
try {
|
|
709
|
+
return (0, import_tables3.mergeCells)(editor.state, void 0);
|
|
710
|
+
} catch {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
function canSplitCell(editor) {
|
|
715
|
+
if (!editor || !editor.isEditable || !(0, import_editor_utils2.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS2)) {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
try {
|
|
719
|
+
return (0, import_tables3.splitCell)(editor.state, void 0);
|
|
720
|
+
} catch {
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function tableMergeCells(editor) {
|
|
725
|
+
if (!canMergeCells(editor) || !editor) return false;
|
|
726
|
+
try {
|
|
727
|
+
const { state, view } = editor;
|
|
728
|
+
return (0, import_tables3.mergeCells)(state, view.dispatch.bind(view));
|
|
729
|
+
} catch (error) {
|
|
730
|
+
console.error("Error merging table cells:", error);
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
function tableSplitCell(editor) {
|
|
735
|
+
if (!canSplitCell(editor) || !editor) return false;
|
|
736
|
+
try {
|
|
737
|
+
const { state, view } = editor;
|
|
738
|
+
return (0, import_tables3.splitCell)(state, view.dispatch.bind(view));
|
|
739
|
+
} catch (error) {
|
|
740
|
+
console.error("Error splitting table cell:", error);
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
function tableMergeSplitCell({
|
|
745
|
+
editor,
|
|
746
|
+
action
|
|
747
|
+
}) {
|
|
748
|
+
if (!editor) return false;
|
|
749
|
+
try {
|
|
750
|
+
return action === "merge" ? tableMergeCells(editor) : tableSplitCell(editor);
|
|
751
|
+
} catch (error) {
|
|
752
|
+
console.error(`Error ${action}ing table cell:`, error);
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function shouldShowButton2({
|
|
757
|
+
editor,
|
|
758
|
+
action,
|
|
759
|
+
hideWhenUnavailable
|
|
760
|
+
}) {
|
|
761
|
+
if (!editor || !editor.isEditable) return false;
|
|
762
|
+
if (!(0, import_editor_utils2.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS2)) return false;
|
|
763
|
+
if (hideWhenUnavailable) {
|
|
764
|
+
return action === "merge" ? canMergeCells(editor) : canSplitCell(editor);
|
|
765
|
+
}
|
|
766
|
+
return true;
|
|
767
|
+
}
|
|
768
|
+
function useTableMergeSplitCell(config) {
|
|
769
|
+
const {
|
|
770
|
+
editor: providedEditor,
|
|
771
|
+
action,
|
|
772
|
+
hideWhenUnavailable = false,
|
|
773
|
+
onExecuted
|
|
774
|
+
} = config;
|
|
775
|
+
const { editor } = (0, import_editor_utils2.useTiptapEditor)(providedEditor);
|
|
776
|
+
const intl = (0, import_i18n3.useSafeIntl)();
|
|
777
|
+
const isVisible = shouldShowButton2({
|
|
778
|
+
editor,
|
|
779
|
+
action,
|
|
780
|
+
hideWhenUnavailable
|
|
781
|
+
});
|
|
782
|
+
const canPerformAction = action === "merge" ? canMergeCells(editor) : canSplitCell(editor);
|
|
783
|
+
const handleExecute = (0, import_react2.useCallback)(() => {
|
|
784
|
+
const success = tableMergeSplitCell({
|
|
785
|
+
editor,
|
|
786
|
+
action
|
|
787
|
+
});
|
|
788
|
+
if (success) {
|
|
789
|
+
onExecuted == null ? void 0 : onExecuted(action);
|
|
790
|
+
}
|
|
791
|
+
return success;
|
|
792
|
+
}, [editor, action, onExecuted]);
|
|
793
|
+
return {
|
|
794
|
+
isVisible,
|
|
795
|
+
canExecute: canPerformAction,
|
|
796
|
+
handleExecute,
|
|
797
|
+
label: intl.formatMessage(mergeSplitMessageKeys[action]),
|
|
798
|
+
Icon: tableMergeSplitCellIcons[action]
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/ui/table-alignment-menu.tsx
|
|
803
|
+
var import_dropdown_menu = require("@kopexa/dropdown-menu");
|
|
804
|
+
var import_i18n5 = require("@kopexa/i18n");
|
|
805
|
+
var import_icons4 = require("@kopexa/icons");
|
|
806
|
+
var import_shared_utils2 = require("@kopexa/shared-utils");
|
|
807
|
+
|
|
808
|
+
// src/hooks/use-table-align-cell.ts
|
|
809
|
+
var import_editor_utils3 = require("@kopexa/editor-utils");
|
|
810
|
+
var import_i18n4 = require("@kopexa/i18n");
|
|
811
|
+
var import_icons3 = require("@kopexa/icons");
|
|
812
|
+
var import_react3 = require("react");
|
|
813
|
+
var REQUIRED_EXTENSIONS3 = ["table"];
|
|
814
|
+
var textAlignmentMessageKeys = {
|
|
815
|
+
left: messages.align_left,
|
|
816
|
+
center: messages.align_center,
|
|
817
|
+
right: messages.align_right,
|
|
818
|
+
justify: messages.justify
|
|
819
|
+
};
|
|
820
|
+
var verticalAlignmentMessageKeys = {
|
|
821
|
+
top: messages.align_top,
|
|
822
|
+
middle: messages.align_middle,
|
|
823
|
+
bottom: messages.align_bottom
|
|
824
|
+
};
|
|
825
|
+
var tableAlignCellIcons = {
|
|
826
|
+
text: {
|
|
827
|
+
left: import_icons3.AlignLeftIcon,
|
|
828
|
+
center: import_icons3.AlignCenterIcon,
|
|
829
|
+
right: import_icons3.AlignRightIcon,
|
|
830
|
+
justify: import_icons3.AlignJustifyIcon
|
|
831
|
+
},
|
|
832
|
+
vertical: {
|
|
833
|
+
top: import_icons3.AlignTopIcon,
|
|
834
|
+
middle: import_icons3.AlignMiddleIcon,
|
|
835
|
+
bottom: import_icons3.AlignBottomIcon
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
function canAlignCell(editor) {
|
|
839
|
+
if (!editor || !editor.isEditable || !(0, import_editor_utils3.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS3)) {
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
try {
|
|
843
|
+
return editor.isActive("tableCell") || editor.isActive("tableHeader");
|
|
844
|
+
} catch {
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function canAlignRowColumn({
|
|
849
|
+
editor,
|
|
850
|
+
index,
|
|
851
|
+
orientation
|
|
852
|
+
}) {
|
|
853
|
+
if (!editor || !editor.isEditable || !(0, import_editor_utils3.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS3)) {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
try {
|
|
857
|
+
const table = getTable(editor);
|
|
858
|
+
if (!table) return false;
|
|
859
|
+
const cellData = getRowOrColumnCells(editor, index, orientation);
|
|
860
|
+
if (cellData.cells.length === 0) return false;
|
|
861
|
+
return true;
|
|
862
|
+
} catch {
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function getCurrentAlignment(editor, alignmentType) {
|
|
867
|
+
if (!canAlignCell(editor) || !editor) return null;
|
|
868
|
+
try {
|
|
869
|
+
const { selection } = editor.state;
|
|
870
|
+
const $anchor = selection.$anchor;
|
|
871
|
+
let cellNode = null;
|
|
872
|
+
for (let depth = $anchor.depth; depth >= 0; depth--) {
|
|
873
|
+
const node = $anchor.node(depth);
|
|
874
|
+
if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
|
|
875
|
+
cellNode = node;
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
if (!cellNode) return null;
|
|
880
|
+
const attrs = cellNode.attrs || {};
|
|
881
|
+
if (alignmentType === "text") {
|
|
882
|
+
return attrs.nodeTextAlign || "left";
|
|
883
|
+
} else {
|
|
884
|
+
return attrs.nodeVerticalAlign || "top";
|
|
885
|
+
}
|
|
886
|
+
} catch {
|
|
887
|
+
return null;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
function getCurrentRowColumnAlignment(editor, alignmentType, index, orientation) {
|
|
891
|
+
if (!editor) return null;
|
|
892
|
+
try {
|
|
893
|
+
const cellData = getRowOrColumnCells(editor, index, orientation);
|
|
894
|
+
if (cellData.cells.length === 0) return null;
|
|
895
|
+
const firstCell = cellData.cells[0];
|
|
896
|
+
if (!(firstCell == null ? void 0 : firstCell.node)) return null;
|
|
897
|
+
const attrs = firstCell.node.attrs || {};
|
|
898
|
+
if (alignmentType === "text") {
|
|
899
|
+
return attrs.nodeTextAlign || "left";
|
|
900
|
+
} else {
|
|
901
|
+
return attrs.nodeVerticalAlign || "top";
|
|
902
|
+
}
|
|
903
|
+
} catch {
|
|
904
|
+
return null;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
function setTableCellAlignment(editor, alignmentType, alignment) {
|
|
908
|
+
if (!canAlignCell(editor) || !editor) return false;
|
|
909
|
+
try {
|
|
910
|
+
if (alignmentType === "text") {
|
|
911
|
+
return editor.commands.setCellAttribute("nodeTextAlign", alignment);
|
|
912
|
+
} else {
|
|
913
|
+
return editor.commands.setCellAttribute("nodeVerticalAlign", alignment);
|
|
914
|
+
}
|
|
915
|
+
} catch (error) {
|
|
916
|
+
console.error("Error setting table cell alignment:", error);
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
function setRowColumnAlignment({
|
|
921
|
+
editor,
|
|
922
|
+
alignmentType,
|
|
923
|
+
alignment,
|
|
924
|
+
index,
|
|
925
|
+
orientation
|
|
926
|
+
}) {
|
|
927
|
+
if (!canAlignRowColumn({ editor, index, orientation }) || !editor) {
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
930
|
+
try {
|
|
931
|
+
const { state, view } = editor;
|
|
932
|
+
const tr = state.tr;
|
|
933
|
+
const cellData = getRowOrColumnCells(editor, index, orientation);
|
|
934
|
+
if (cellData.cells.length === 0) {
|
|
935
|
+
return false;
|
|
936
|
+
}
|
|
937
|
+
const uniqueCells = /* @__PURE__ */ new Map();
|
|
938
|
+
cellData.cells.forEach((cellInfo) => {
|
|
939
|
+
if (cellInfo.node && cellInfo.pos !== void 0) {
|
|
940
|
+
uniqueCells.set(cellInfo.pos, cellInfo);
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
if (uniqueCells.size === 0) {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
const cellsToProcess = Array.from(uniqueCells.values()).sort(
|
|
947
|
+
(a, b) => b.pos - a.pos
|
|
948
|
+
);
|
|
949
|
+
const attributeName = alignmentType === "text" ? "nodeTextAlign" : "nodeVerticalAlign";
|
|
950
|
+
cellsToProcess.forEach((cellInfo) => {
|
|
951
|
+
if (cellInfo.node && cellInfo.pos !== void 0) {
|
|
952
|
+
const cellType = cellInfo.node.type;
|
|
953
|
+
const newCellNode = cellType.create(
|
|
954
|
+
{
|
|
955
|
+
...cellInfo.node.attrs,
|
|
956
|
+
[attributeName]: alignment
|
|
957
|
+
},
|
|
958
|
+
cellInfo.node.content,
|
|
959
|
+
cellInfo.node.marks
|
|
960
|
+
);
|
|
961
|
+
const cellEnd = cellInfo.pos + cellInfo.node.nodeSize;
|
|
962
|
+
tr.replaceWith(cellInfo.pos, cellEnd, newCellNode);
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
if (tr.docChanged) {
|
|
966
|
+
view.dispatch(tr);
|
|
967
|
+
return true;
|
|
968
|
+
}
|
|
969
|
+
return false;
|
|
970
|
+
} catch (error) {
|
|
971
|
+
console.error(`Error aligning table ${orientation}:`, error);
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function tableAlignCell({
|
|
976
|
+
editor,
|
|
977
|
+
alignmentType,
|
|
978
|
+
alignment,
|
|
979
|
+
index,
|
|
980
|
+
orientation
|
|
981
|
+
}) {
|
|
982
|
+
if (!editor) return false;
|
|
983
|
+
try {
|
|
984
|
+
if (typeof index === "number" && orientation) {
|
|
985
|
+
return setRowColumnAlignment({
|
|
986
|
+
editor,
|
|
987
|
+
alignmentType,
|
|
988
|
+
alignment,
|
|
989
|
+
index,
|
|
990
|
+
orientation
|
|
991
|
+
});
|
|
992
|
+
} else {
|
|
993
|
+
return setTableCellAlignment(editor, alignmentType, alignment);
|
|
994
|
+
}
|
|
995
|
+
} catch (error) {
|
|
996
|
+
console.error("Error aligning table cell:", error);
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function shouldShowButton3({
|
|
1001
|
+
editor,
|
|
1002
|
+
hideWhenUnavailable,
|
|
1003
|
+
index,
|
|
1004
|
+
orientation
|
|
1005
|
+
}) {
|
|
1006
|
+
if (!editor || !editor.isEditable) return false;
|
|
1007
|
+
if (!(0, import_editor_utils3.isExtensionAvailable)(editor, REQUIRED_EXTENSIONS3)) return false;
|
|
1008
|
+
if (hideWhenUnavailable) {
|
|
1009
|
+
if (typeof index === "number" && orientation) {
|
|
1010
|
+
return canAlignRowColumn({ editor, index, orientation });
|
|
1011
|
+
}
|
|
1012
|
+
return canAlignCell(editor);
|
|
1013
|
+
}
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
function useTableAlignCell(config) {
|
|
1017
|
+
const {
|
|
1018
|
+
editor: providedEditor,
|
|
1019
|
+
alignmentType,
|
|
1020
|
+
alignment,
|
|
1021
|
+
index,
|
|
1022
|
+
orientation,
|
|
1023
|
+
hideWhenUnavailable = false,
|
|
1024
|
+
onAligned
|
|
1025
|
+
} = config;
|
|
1026
|
+
const { editor } = (0, import_editor_utils3.useTiptapEditor)(providedEditor);
|
|
1027
|
+
const intl = (0, import_i18n4.useSafeIntl)();
|
|
1028
|
+
const isVisible = shouldShowButton3({
|
|
1029
|
+
editor,
|
|
1030
|
+
hideWhenUnavailable,
|
|
1031
|
+
index,
|
|
1032
|
+
orientation
|
|
1033
|
+
});
|
|
1034
|
+
const canPerformAlign = (0, import_react3.useCallback)(() => {
|
|
1035
|
+
if (typeof index === "number" && orientation) {
|
|
1036
|
+
return canAlignRowColumn({ editor, index, orientation });
|
|
1037
|
+
}
|
|
1038
|
+
return canAlignCell(editor);
|
|
1039
|
+
}, [editor, index, orientation]);
|
|
1040
|
+
const currentAlignmentValue = (0, import_react3.useMemo)(() => {
|
|
1041
|
+
if (typeof index === "number" && orientation) {
|
|
1042
|
+
return getCurrentRowColumnAlignment(
|
|
1043
|
+
editor,
|
|
1044
|
+
alignmentType,
|
|
1045
|
+
index,
|
|
1046
|
+
orientation
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
1049
|
+
return getCurrentAlignment(editor, alignmentType);
|
|
1050
|
+
}, [editor, alignmentType, index, orientation]);
|
|
1051
|
+
const isActive = currentAlignmentValue === alignment;
|
|
1052
|
+
const handleAlign = (0, import_react3.useCallback)(() => {
|
|
1053
|
+
const success = tableAlignCell({
|
|
1054
|
+
editor,
|
|
1055
|
+
alignmentType,
|
|
1056
|
+
alignment,
|
|
1057
|
+
index,
|
|
1058
|
+
orientation
|
|
1059
|
+
});
|
|
1060
|
+
if (success) {
|
|
1061
|
+
onAligned == null ? void 0 : onAligned(alignment);
|
|
1062
|
+
}
|
|
1063
|
+
return success;
|
|
1064
|
+
}, [editor, alignmentType, alignment, index, orientation, onAligned]);
|
|
1065
|
+
const label = (0, import_react3.useMemo)(() => {
|
|
1066
|
+
if (alignmentType === "text") {
|
|
1067
|
+
return intl.formatMessage(
|
|
1068
|
+
textAlignmentMessageKeys[alignment]
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
return intl.formatMessage(
|
|
1072
|
+
verticalAlignmentMessageKeys[alignment]
|
|
1073
|
+
);
|
|
1074
|
+
}, [intl, alignmentType, alignment]);
|
|
1075
|
+
const Icon = (0, import_react3.useMemo)(() => {
|
|
1076
|
+
if (alignmentType === "text") {
|
|
1077
|
+
return tableAlignCellIcons.text[alignment];
|
|
1078
|
+
} else {
|
|
1079
|
+
return tableAlignCellIcons.vertical[alignment];
|
|
1080
|
+
}
|
|
1081
|
+
}, [alignmentType, alignment]);
|
|
1082
|
+
return {
|
|
1083
|
+
isVisible,
|
|
1084
|
+
canAlignCell: canPerformAlign,
|
|
1085
|
+
handleAlign,
|
|
1086
|
+
label,
|
|
1087
|
+
Icon,
|
|
1088
|
+
isActive,
|
|
1089
|
+
currentAlignment: currentAlignmentValue
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/ui/table-alignment-menu.tsx
|
|
1094
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1095
|
+
var TableAlignMenuItems = ({
|
|
1096
|
+
index,
|
|
1097
|
+
orientation
|
|
1098
|
+
}) => {
|
|
1099
|
+
const textLeft = useTableAlignCell({
|
|
1100
|
+
alignmentType: "text",
|
|
1101
|
+
alignment: "left",
|
|
1102
|
+
index,
|
|
1103
|
+
orientation
|
|
1104
|
+
});
|
|
1105
|
+
const textCenter = useTableAlignCell({
|
|
1106
|
+
alignmentType: "text",
|
|
1107
|
+
alignment: "center",
|
|
1108
|
+
index,
|
|
1109
|
+
orientation
|
|
1110
|
+
});
|
|
1111
|
+
const textRight = useTableAlignCell({
|
|
1112
|
+
alignmentType: "text",
|
|
1113
|
+
alignment: "right",
|
|
1114
|
+
index,
|
|
1115
|
+
orientation
|
|
1116
|
+
});
|
|
1117
|
+
const verticalTop = useTableAlignCell({
|
|
1118
|
+
alignmentType: "vertical",
|
|
1119
|
+
alignment: "top",
|
|
1120
|
+
index,
|
|
1121
|
+
orientation
|
|
1122
|
+
});
|
|
1123
|
+
const verticalMiddle = useTableAlignCell({
|
|
1124
|
+
alignmentType: "vertical",
|
|
1125
|
+
alignment: "middle",
|
|
1126
|
+
index,
|
|
1127
|
+
orientation
|
|
1128
|
+
});
|
|
1129
|
+
const verticalBottom = useTableAlignCell({
|
|
1130
|
+
alignmentType: "vertical",
|
|
1131
|
+
alignment: "bottom",
|
|
1132
|
+
index,
|
|
1133
|
+
orientation
|
|
1134
|
+
});
|
|
1135
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1136
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dropdown_menu.DropdownMenu.Group, { children: [
|
|
1137
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignMenuItem, { align: textLeft }),
|
|
1138
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignMenuItem, { align: textCenter }),
|
|
1139
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignMenuItem, { align: textRight })
|
|
1140
|
+
] }),
|
|
1141
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.Separator, {}),
|
|
1142
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dropdown_menu.DropdownMenu.Group, { children: [
|
|
1143
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignMenuItem, { align: verticalTop }),
|
|
1144
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignMenuItem, { align: verticalMiddle }),
|
|
1145
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignMenuItem, { align: verticalBottom })
|
|
1146
|
+
] })
|
|
1147
|
+
] });
|
|
1148
|
+
};
|
|
1149
|
+
var TableAlignSubMenu = ({
|
|
1150
|
+
index,
|
|
1151
|
+
orientation
|
|
1152
|
+
}) => {
|
|
1153
|
+
const probe = useTableAlignCell({
|
|
1154
|
+
alignmentType: "text",
|
|
1155
|
+
alignment: "left",
|
|
1156
|
+
index,
|
|
1157
|
+
orientation
|
|
1158
|
+
});
|
|
1159
|
+
const intl = (0, import_i18n5.useSafeIntl)();
|
|
1160
|
+
if (!probe.canAlignCell()) return null;
|
|
1161
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dropdown_menu.DropdownMenu.Sub, { children: [
|
|
1162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dropdown_menu.DropdownMenu.SubTrigger, { children: [
|
|
1163
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons4.AlignLeftIcon, {}),
|
|
1164
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: intl.formatMessage(messages.alignment) })
|
|
1165
|
+
] }),
|
|
1166
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dropdown_menu.DropdownMenu.SubContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableAlignMenuItems, { index, orientation }) })
|
|
1167
|
+
] });
|
|
1168
|
+
};
|
|
1169
|
+
var AlignMenuItem = ({
|
|
1170
|
+
align
|
|
1171
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1172
|
+
import_dropdown_menu.DropdownMenu.Item,
|
|
1173
|
+
{
|
|
1174
|
+
disabled: !align.canAlignCell(),
|
|
1175
|
+
onSelect: align.handleAlign,
|
|
1176
|
+
children: [
|
|
1177
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(align.Icon, {}),
|
|
1178
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: align.label }),
|
|
1179
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1180
|
+
"span",
|
|
1181
|
+
{
|
|
1182
|
+
className: (0, import_shared_utils2.cn)("ml-auto", align.isActive ? "opacity-100" : "opacity-0"),
|
|
1183
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons4.CheckIcon, {})
|
|
1184
|
+
}
|
|
1185
|
+
)
|
|
1186
|
+
]
|
|
1187
|
+
}
|
|
1188
|
+
);
|
|
1189
|
+
|
|
1190
|
+
// src/ui/table-cell-handle-menu.tsx
|
|
1191
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1192
|
+
function useTableActions() {
|
|
1193
|
+
const mergeCellAction = useTableMergeSplitCell({ action: "merge" });
|
|
1194
|
+
const splitCellAction = useTableMergeSplitCell({ action: "split" });
|
|
1195
|
+
const clearContentAction = useTableClearRowColumnContent({
|
|
1196
|
+
resetAttrs: true
|
|
1197
|
+
});
|
|
1198
|
+
const mergeAction = {
|
|
1199
|
+
icon: mergeCellAction.Icon,
|
|
1200
|
+
label: mergeCellAction.label,
|
|
1201
|
+
onClick: mergeCellAction.handleExecute,
|
|
1202
|
+
isAvailable: mergeCellAction.canExecute
|
|
1203
|
+
};
|
|
1204
|
+
const splitAction = {
|
|
1205
|
+
icon: splitCellAction.Icon,
|
|
1206
|
+
label: splitCellAction.label,
|
|
1207
|
+
onClick: splitCellAction.handleExecute,
|
|
1208
|
+
isAvailable: splitCellAction.canExecute
|
|
1209
|
+
};
|
|
1210
|
+
const clearAction = {
|
|
1211
|
+
icon: clearContentAction.Icon,
|
|
1212
|
+
label: clearContentAction.label,
|
|
1213
|
+
onClick: clearContentAction.handleClear,
|
|
1214
|
+
isAvailable: clearContentAction.canClearRowColumnContent
|
|
1215
|
+
};
|
|
1216
|
+
return {
|
|
1217
|
+
mergeAction,
|
|
1218
|
+
splitAction,
|
|
1219
|
+
clearAction
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
function useTableCellHandleMenu({ editor }) {
|
|
1223
|
+
const [isMenuOpen, setIsMenuOpen] = (0, import_react4.useState)(false);
|
|
1224
|
+
const closeMenu = (0, import_react4.useCallback)(() => {
|
|
1225
|
+
setIsMenuOpen(false);
|
|
1226
|
+
editor == null ? void 0 : editor.commands.unfreezeHandles();
|
|
1227
|
+
}, [editor]);
|
|
1228
|
+
const handleMenuToggle = (0, import_react4.useCallback)(
|
|
1229
|
+
(isOpen) => {
|
|
1230
|
+
setIsMenuOpen(isOpen);
|
|
1231
|
+
if (!editor) return;
|
|
1232
|
+
if (isOpen) {
|
|
1233
|
+
editor.commands.freezeHandles();
|
|
1234
|
+
} else {
|
|
1235
|
+
editor.commands.unfreezeHandles();
|
|
1236
|
+
}
|
|
1237
|
+
},
|
|
1238
|
+
[editor]
|
|
1239
|
+
);
|
|
1240
|
+
return {
|
|
1241
|
+
isMenuOpen,
|
|
1242
|
+
handleMenuToggle,
|
|
1243
|
+
closeMenu
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
var TableActionItem = ({ action }) => {
|
|
1247
|
+
const {
|
|
1248
|
+
icon: Icon,
|
|
1249
|
+
label,
|
|
1250
|
+
onClick,
|
|
1251
|
+
isActive = false,
|
|
1252
|
+
shortcutBadge
|
|
1253
|
+
} = action;
|
|
1254
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1255
|
+
import_dropdown_menu2.DropdownMenu.Item,
|
|
1256
|
+
{
|
|
1257
|
+
onClick,
|
|
1258
|
+
"data-state": isActive ? "active" : "inactive",
|
|
1259
|
+
children: [
|
|
1260
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { className: "tiptap-button-icon" }),
|
|
1261
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "tiptap-button-text", children: label }),
|
|
1262
|
+
shortcutBadge
|
|
1263
|
+
]
|
|
1264
|
+
}
|
|
1265
|
+
);
|
|
1266
|
+
};
|
|
1267
|
+
var TableActionMenu = () => {
|
|
1268
|
+
const { mergeAction, splitAction, clearAction } = useTableActions();
|
|
1269
|
+
const hasMergeOrSplit = mergeAction.isAvailable || splitAction.isAvailable;
|
|
1270
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_dropdown_menu2.DropdownMenu.Content, { children: [
|
|
1271
|
+
hasMergeOrSplit && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1272
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_dropdown_menu2.DropdownMenu.Group, { children: [
|
|
1273
|
+
mergeAction.isAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableActionItem, { action: mergeAction }),
|
|
1274
|
+
splitAction.isAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableActionItem, { action: splitAction })
|
|
1275
|
+
] }),
|
|
1276
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Separator, {})
|
|
1277
|
+
] }),
|
|
1278
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableAlignSubMenu, {}),
|
|
1279
|
+
clearAction.isAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1280
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Separator, {}),
|
|
1281
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableActionItem, { action: clearAction }) })
|
|
1282
|
+
] })
|
|
1283
|
+
] });
|
|
1284
|
+
};
|
|
1285
|
+
var TableCellHandleMenu = (0, import_react4.forwardRef)(({ editor: providedEditor, onOpenChange, className, ...props }, ref) => {
|
|
1286
|
+
const { editor } = (0, import_editor_utils4.useTiptapEditor)(providedEditor);
|
|
1287
|
+
const intl = (0, import_i18n6.useSafeIntl)();
|
|
1288
|
+
const { isMenuOpen, handleMenuToggle } = useTableCellHandleMenu({
|
|
1289
|
+
editor
|
|
1290
|
+
});
|
|
1291
|
+
const styles = (0, import_theme.tableCellHandleMenu)();
|
|
1292
|
+
(0, import_react4.useEffect)(() => {
|
|
1293
|
+
onOpenChange == null ? void 0 : onOpenChange(isMenuOpen);
|
|
1294
|
+
}, [isMenuOpen, onOpenChange]);
|
|
1295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_dropdown_menu2.DropdownMenu.Root, { open: isMenuOpen, onOpenChange: handleMenuToggle, children: [
|
|
1296
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dropdown_menu2.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1297
|
+
"button",
|
|
1298
|
+
{
|
|
1299
|
+
ref,
|
|
1300
|
+
"data-open": isMenuOpen,
|
|
1301
|
+
className: (0, import_shared_utils3.cn)(styles.trigger(), className),
|
|
1302
|
+
"aria-label": intl.formatMessage(messages.cell_options),
|
|
1303
|
+
"aria-haspopup": "menu",
|
|
1304
|
+
"aria-expanded": isMenuOpen,
|
|
1305
|
+
...props,
|
|
1306
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons5.Grip4Icon, { className: styles.icon() })
|
|
1307
|
+
}
|
|
1308
|
+
) }),
|
|
1309
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableActionMenu, {})
|
|
1310
|
+
] });
|
|
1311
|
+
});
|
|
1312
|
+
TableCellHandleMenu.displayName = "TableCellHandleMenu";
|
|
1313
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1314
|
+
0 && (module.exports = {
|
|
1315
|
+
TableActionMenu,
|
|
1316
|
+
TableCellHandleMenu
|
|
1317
|
+
});
|