@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,1041 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
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
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
|
|
23
|
+
// src/extensions/kit.ts
|
|
24
|
+
var kit_exports = {};
|
|
25
|
+
__export(kit_exports, {
|
|
26
|
+
TableKit: () => TableKit
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(kit_exports);
|
|
29
|
+
var import_extension_table2 = require("@tiptap/extension-table");
|
|
30
|
+
var import_react = require("@tiptap/react");
|
|
31
|
+
|
|
32
|
+
// src/extensions/table.ts
|
|
33
|
+
var import_extension_table = require("@tiptap/extension-table");
|
|
34
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
35
|
+
|
|
36
|
+
// src/lib/constants.ts
|
|
37
|
+
var EMPTY_CELL_WIDTH = 120;
|
|
38
|
+
var RESIZE_MIN_WIDTH = 35;
|
|
39
|
+
|
|
40
|
+
// src/extensions/table.ts
|
|
41
|
+
var Table = import_extension_table.Table.configure({
|
|
42
|
+
resizable: true
|
|
43
|
+
}).extend({
|
|
44
|
+
addProseMirrorPlugins() {
|
|
45
|
+
const isResizable = this.options.resizable && this.editor.isEditable;
|
|
46
|
+
const defaultCellMinWidth = this.options.cellMinWidth < EMPTY_CELL_WIDTH ? EMPTY_CELL_WIDTH : this.options.cellMinWidth;
|
|
47
|
+
return [
|
|
48
|
+
...isResizable ? [
|
|
49
|
+
(0, import_tables.columnResizing)({
|
|
50
|
+
handleWidth: this.options.handleWidth,
|
|
51
|
+
cellMinWidth: RESIZE_MIN_WIDTH,
|
|
52
|
+
defaultCellMinWidth,
|
|
53
|
+
View: null,
|
|
54
|
+
lastColumnResizable: this.options.lastColumnResizable
|
|
55
|
+
})
|
|
56
|
+
] : [],
|
|
57
|
+
(0, import_tables.tableEditing)({
|
|
58
|
+
allowTableNodeSelection: this.options.allowTableNodeSelection
|
|
59
|
+
})
|
|
60
|
+
];
|
|
61
|
+
},
|
|
62
|
+
addNodeView() {
|
|
63
|
+
return ({ node, HTMLAttributes }) => {
|
|
64
|
+
class TiptapTableView extends import_tables.TableView {
|
|
65
|
+
constructor(node2, minCellWidth, containerAttributes) {
|
|
66
|
+
super(node2, minCellWidth);
|
|
67
|
+
__publicField(this, "blockContainer");
|
|
68
|
+
__publicField(this, "innerTableContainer");
|
|
69
|
+
__publicField(this, "widgetsContainer");
|
|
70
|
+
__publicField(this, "overlayContainer");
|
|
71
|
+
__publicField(this, "containerAttributes");
|
|
72
|
+
this.containerAttributes = containerAttributes != null ? containerAttributes : {};
|
|
73
|
+
this.blockContainer = this.createBlockContainer();
|
|
74
|
+
this.innerTableContainer = this.createInnerTableContainer();
|
|
75
|
+
this.widgetsContainer = this.createWidgetsContainer();
|
|
76
|
+
this.overlayContainer = this.createOverlayContainer();
|
|
77
|
+
this.setupDOMStructure();
|
|
78
|
+
}
|
|
79
|
+
createBlockContainer() {
|
|
80
|
+
const container = document.createElement("div");
|
|
81
|
+
container.setAttribute("data-content-type", "table");
|
|
82
|
+
container.style.position = "relative";
|
|
83
|
+
this.applyContainerAttributes(container);
|
|
84
|
+
return container;
|
|
85
|
+
}
|
|
86
|
+
createInnerTableContainer() {
|
|
87
|
+
const container = document.createElement("div");
|
|
88
|
+
container.className = "table-container";
|
|
89
|
+
return container;
|
|
90
|
+
}
|
|
91
|
+
createWidgetsContainer() {
|
|
92
|
+
const container = document.createElement("div");
|
|
93
|
+
container.className = "table-controls";
|
|
94
|
+
container.style.position = "absolute";
|
|
95
|
+
container.style.inset = "0";
|
|
96
|
+
container.style.pointerEvents = "none";
|
|
97
|
+
return container;
|
|
98
|
+
}
|
|
99
|
+
createOverlayContainer() {
|
|
100
|
+
const container = document.createElement("div");
|
|
101
|
+
container.className = "table-selection-overlay-container";
|
|
102
|
+
container.style.position = "absolute";
|
|
103
|
+
container.style.inset = "0";
|
|
104
|
+
container.style.pointerEvents = "none";
|
|
105
|
+
return container;
|
|
106
|
+
}
|
|
107
|
+
applyContainerAttributes(element) {
|
|
108
|
+
Object.entries(this.containerAttributes).forEach(([key, value]) => {
|
|
109
|
+
if (key !== "class") {
|
|
110
|
+
element.setAttribute(key, value);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
setupDOMStructure() {
|
|
115
|
+
const originalTable = this.dom;
|
|
116
|
+
const tableElement = originalTable.firstChild;
|
|
117
|
+
if (tableElement) {
|
|
118
|
+
this.innerTableContainer.appendChild(tableElement);
|
|
119
|
+
}
|
|
120
|
+
originalTable.appendChild(this.innerTableContainer);
|
|
121
|
+
this.blockContainer.appendChild(originalTable);
|
|
122
|
+
this.blockContainer.appendChild(this.widgetsContainer);
|
|
123
|
+
this.blockContainer.appendChild(this.overlayContainer);
|
|
124
|
+
this.dom = this.blockContainer;
|
|
125
|
+
}
|
|
126
|
+
ignoreMutation(mutation) {
|
|
127
|
+
const target = mutation.target;
|
|
128
|
+
if (!target.closest(".table-container")) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return super.ignoreMutation(mutation);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const cellMinWidth = this.options.cellMinWidth < EMPTY_CELL_WIDTH ? EMPTY_CELL_WIDTH : this.options.cellMinWidth;
|
|
135
|
+
return new TiptapTableView(node, cellMinWidth, HTMLAttributes);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// src/extensions/table-cell.ts
|
|
141
|
+
var import_cell = require("@tiptap/extension-table/cell");
|
|
142
|
+
var import_state = require("@tiptap/pm/state");
|
|
143
|
+
var import_tables2 = require("@tiptap/pm/tables");
|
|
144
|
+
var TableCell = import_cell.TableCell.extend({
|
|
145
|
+
addKeyboardShortcuts() {
|
|
146
|
+
var _a;
|
|
147
|
+
return {
|
|
148
|
+
...(_a = this.parent) == null ? void 0 : _a.call(this),
|
|
149
|
+
"Mod-a": () => {
|
|
150
|
+
const { state, view } = this.editor;
|
|
151
|
+
const { selection, doc } = state;
|
|
152
|
+
const $anchor = selection.$anchor;
|
|
153
|
+
const cellPos = (0, import_tables2.cellAround)($anchor);
|
|
154
|
+
if (!cellPos) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const cellNode = doc.nodeAt(cellPos.pos);
|
|
158
|
+
if (!cellNode || !cellNode.textContent) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
const from = cellPos.pos + 1;
|
|
162
|
+
const to = cellPos.pos + cellNode.nodeSize - 1;
|
|
163
|
+
if (from >= to) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
const $from = doc.resolve(from);
|
|
167
|
+
const $to = doc.resolve(to);
|
|
168
|
+
const nextSel = import_state.TextSelection.between($from, $to, 1);
|
|
169
|
+
if (!nextSel) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
if (state.selection.eq(nextSel)) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
view.dispatch(state.tr.setSelection(nextSel));
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// src/extensions/table-handle.ts
|
|
183
|
+
var import_core = require("@tiptap/core");
|
|
184
|
+
|
|
185
|
+
// src/extensions/table-handle-plugin.ts
|
|
186
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
187
|
+
var import_shared_utils2 = require("@kopexa/shared-utils");
|
|
188
|
+
var import_state2 = require("@tiptap/pm/state");
|
|
189
|
+
var import_tables4 = require("@tiptap/pm/tables");
|
|
190
|
+
var import_view = require("@tiptap/pm/view");
|
|
191
|
+
|
|
192
|
+
// src/lib/table-utils.ts
|
|
193
|
+
var import_shared_utils = require("@kopexa/shared-utils");
|
|
194
|
+
var import_tables3 = require("@tiptap/pm/tables");
|
|
195
|
+
var EMPTY_CELLS_RESULT = { cells: [], mergedCells: [] };
|
|
196
|
+
function domCellAround(target) {
|
|
197
|
+
let current = target;
|
|
198
|
+
while (current && current.tagName !== "TD" && current.tagName !== "TH" && !current.classList.contains("tableWrapper")) {
|
|
199
|
+
if (current.classList.contains("ProseMirror")) return void 0;
|
|
200
|
+
current = (0, import_shared_utils.isHTMLElement)(current.parentNode) ? current.parentNode : null;
|
|
201
|
+
}
|
|
202
|
+
if (!current) return void 0;
|
|
203
|
+
if (current.tagName === "TD" || current.tagName === "TH") {
|
|
204
|
+
return {
|
|
205
|
+
type: "cell",
|
|
206
|
+
domNode: current,
|
|
207
|
+
tbodyNode: (0, import_shared_utils.safeClosest)(current, "tbody")
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
type: "wrapper",
|
|
212
|
+
domNode: current,
|
|
213
|
+
tbodyNode: current.querySelector("tbody")
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function getCellIndicesFromDOM(cell, tableNode, editor) {
|
|
217
|
+
if (!tableNode) return null;
|
|
218
|
+
try {
|
|
219
|
+
const cellPos = editor.view.posAtDOM(cell, 0);
|
|
220
|
+
const $cellPos = editor.view.state.doc.resolve(cellPos);
|
|
221
|
+
for (let d = $cellPos.depth; d > 0; d--) {
|
|
222
|
+
const node = $cellPos.node(d);
|
|
223
|
+
if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
|
|
224
|
+
const tableMap = import_tables3.TableMap.get(tableNode);
|
|
225
|
+
const cellNodePos = $cellPos.before(d);
|
|
226
|
+
const tableStart = $cellPos.start(d - 2);
|
|
227
|
+
const cellOffset = cellNodePos - tableStart;
|
|
228
|
+
const cellIndex = tableMap.map.indexOf(cellOffset);
|
|
229
|
+
return {
|
|
230
|
+
rowIndex: Math.floor(cellIndex / tableMap.width),
|
|
231
|
+
colIndex: cellIndex % tableMap.width
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
} catch (error) {
|
|
236
|
+
console.warn("Could not get cell position:", error);
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
function collectCells(editor, orientation, index, tablePos) {
|
|
241
|
+
if (!editor) return EMPTY_CELLS_RESULT;
|
|
242
|
+
const { state } = editor;
|
|
243
|
+
const table = getTable(editor, tablePos);
|
|
244
|
+
if (!table) return EMPTY_CELLS_RESULT;
|
|
245
|
+
const tableStart = table.start;
|
|
246
|
+
const tableNode = table.node;
|
|
247
|
+
const map = table.map;
|
|
248
|
+
const resolvedIndex = resolveOrientationIndex(
|
|
249
|
+
state,
|
|
250
|
+
table,
|
|
251
|
+
orientation,
|
|
252
|
+
index
|
|
253
|
+
);
|
|
254
|
+
if (resolvedIndex === null) return EMPTY_CELLS_RESULT;
|
|
255
|
+
const maxIndex = orientation === "row" ? map.height : map.width;
|
|
256
|
+
if (resolvedIndex < 0 || resolvedIndex >= maxIndex) {
|
|
257
|
+
return EMPTY_CELLS_RESULT;
|
|
258
|
+
}
|
|
259
|
+
const cells = [];
|
|
260
|
+
const mergedCells = [];
|
|
261
|
+
const seenMerged = /* @__PURE__ */ new Set();
|
|
262
|
+
const iterationCount = orientation === "row" ? map.width : map.height;
|
|
263
|
+
for (let i = 0; i < iterationCount; i++) {
|
|
264
|
+
const row = orientation === "row" ? resolvedIndex : i;
|
|
265
|
+
const col = orientation === "row" ? i : resolvedIndex;
|
|
266
|
+
const cellIndex = row * map.width + col;
|
|
267
|
+
const mapCell = map.map[cellIndex];
|
|
268
|
+
if (mapCell === void 0) continue;
|
|
269
|
+
const cellPos = tableStart + mapCell;
|
|
270
|
+
const cellNode = tableNode.nodeAt(mapCell);
|
|
271
|
+
if (!cellNode) continue;
|
|
272
|
+
const cell = createCellInfo(row, col, cellPos, cellNode);
|
|
273
|
+
if (isCellMerged(cellNode)) {
|
|
274
|
+
if (!seenMerged.has(cellPos)) {
|
|
275
|
+
mergedCells.push(cell);
|
|
276
|
+
seenMerged.add(cellPos);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
cells.push(cell);
|
|
280
|
+
}
|
|
281
|
+
return { cells, mergedCells };
|
|
282
|
+
}
|
|
283
|
+
function isCellMerged(node) {
|
|
284
|
+
var _a, _b;
|
|
285
|
+
if (!node) return false;
|
|
286
|
+
const colspan = (_a = node.attrs.colspan) != null ? _a : 1;
|
|
287
|
+
const rowspan = (_b = node.attrs.rowspan) != null ? _b : 1;
|
|
288
|
+
return colspan > 1 || rowspan > 1;
|
|
289
|
+
}
|
|
290
|
+
function getColumnCells(editor, columnIndex, tablePos) {
|
|
291
|
+
return collectCells(editor, "column", columnIndex, tablePos);
|
|
292
|
+
}
|
|
293
|
+
function getTable(editor, tablePos) {
|
|
294
|
+
if (!editor) return null;
|
|
295
|
+
let table = null;
|
|
296
|
+
if (typeof tablePos === "number") {
|
|
297
|
+
const tableNode = editor.state.doc.nodeAt(tablePos);
|
|
298
|
+
if ((tableNode == null ? void 0 : tableNode.type.name) === "table") {
|
|
299
|
+
table = {
|
|
300
|
+
node: tableNode,
|
|
301
|
+
pos: tablePos,
|
|
302
|
+
start: tablePos + 1,
|
|
303
|
+
depth: editor.state.doc.resolve(tablePos).depth
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (!table) {
|
|
308
|
+
const { state } = editor;
|
|
309
|
+
const $from = state.doc.resolve(state.selection.from);
|
|
310
|
+
table = (0, import_tables3.findTable)($from);
|
|
311
|
+
}
|
|
312
|
+
if (!table) return null;
|
|
313
|
+
const tableMap = import_tables3.TableMap.get(table.node);
|
|
314
|
+
if (!tableMap) return null;
|
|
315
|
+
return { ...table, map: tableMap };
|
|
316
|
+
}
|
|
317
|
+
function createCellInfo(row, column, cellPos, cellNode) {
|
|
318
|
+
return {
|
|
319
|
+
row,
|
|
320
|
+
column,
|
|
321
|
+
pos: cellPos,
|
|
322
|
+
node: cellNode,
|
|
323
|
+
start: cellPos + 1,
|
|
324
|
+
depth: cellNode ? cellNode.content.size : 0
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function resolveOrientationIndex(state, table, orientation, providedIndex) {
|
|
328
|
+
var _a;
|
|
329
|
+
if (typeof providedIndex === "number") {
|
|
330
|
+
return providedIndex;
|
|
331
|
+
}
|
|
332
|
+
if (state.selection instanceof import_tables3.CellSelection) {
|
|
333
|
+
const rect2 = (0, import_tables3.selectedRect)(state);
|
|
334
|
+
return orientation === "row" ? rect2.top : rect2.left;
|
|
335
|
+
}
|
|
336
|
+
const $cell = (_a = (0, import_tables3.cellAround)(state.selection.$anchor)) != null ? _a : (0, import_tables3.selectionCell)(state);
|
|
337
|
+
if (!$cell) return null;
|
|
338
|
+
const rel = $cell.pos - table.start;
|
|
339
|
+
const rect = table.map.findCell(rel);
|
|
340
|
+
return orientation === "row" ? rect.top : rect.left;
|
|
341
|
+
}
|
|
342
|
+
function getIndexCoordinates({
|
|
343
|
+
editor,
|
|
344
|
+
index,
|
|
345
|
+
orientation,
|
|
346
|
+
tablePos
|
|
347
|
+
}) {
|
|
348
|
+
if (!editor) return null;
|
|
349
|
+
const table = getTable(editor, tablePos);
|
|
350
|
+
if (!table) return null;
|
|
351
|
+
const { map } = table;
|
|
352
|
+
const { width, height } = map;
|
|
353
|
+
if (index < 0) return null;
|
|
354
|
+
if (orientation === "row" && index >= height) return null;
|
|
355
|
+
if (orientation === "column" && index >= width) return null;
|
|
356
|
+
return orientation === "row" ? Array.from({ length: map.width }, (_, col) => ({ row: index, col })) : Array.from({ length: map.height }, (_, row) => ({ row, col: index }));
|
|
357
|
+
}
|
|
358
|
+
function getRowCells(editor, rowIndex, tablePos) {
|
|
359
|
+
return collectCells(editor, "row", rowIndex, tablePos);
|
|
360
|
+
}
|
|
361
|
+
function getTableFromDOM(tableElement, editor) {
|
|
362
|
+
try {
|
|
363
|
+
const pos = editor.view.posAtDOM(tableElement, 0);
|
|
364
|
+
const $pos = editor.view.state.doc.resolve(pos);
|
|
365
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
366
|
+
const node = $pos.node(d);
|
|
367
|
+
if (isTableNode(node)) {
|
|
368
|
+
return { node, pos: d === 0 ? 0 : $pos.before(d) };
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.warn("Could not get table from DOM:", error);
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
function isTableNode(node) {
|
|
377
|
+
return !!node && (node.type.name === "table" || node.type.spec.tableRole === "table");
|
|
378
|
+
}
|
|
379
|
+
function selectCellsByCoords(editor, tablePos, coords, options = { mode: "state" }) {
|
|
380
|
+
if (!editor) return;
|
|
381
|
+
const table = getTable(editor, tablePos);
|
|
382
|
+
if (!table) return;
|
|
383
|
+
const { state } = editor;
|
|
384
|
+
const tableMap = table.map;
|
|
385
|
+
const cleanedCoords = coords.map((coord) => ({
|
|
386
|
+
row: (0, import_shared_utils.clamp)(coord.row, 0, tableMap.height - 1),
|
|
387
|
+
col: (0, import_shared_utils.clamp)(coord.col, 0, tableMap.width - 1)
|
|
388
|
+
})).filter((coord) => isWithinBounds(coord.row, coord.col, tableMap));
|
|
389
|
+
if (cleanedCoords.length === 0) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const allRows = cleanedCoords.map((coord) => coord.row);
|
|
393
|
+
const topRow = Math.min(...allRows);
|
|
394
|
+
const bottomRow = Math.max(...allRows);
|
|
395
|
+
const allCols = cleanedCoords.map((coord) => coord.col);
|
|
396
|
+
const leftCol = Math.min(...allCols);
|
|
397
|
+
const rightCol = Math.max(...allCols);
|
|
398
|
+
const getCellPositionFromMap = (row, col) => {
|
|
399
|
+
const cellOffset = tableMap.map[row * tableMap.width + col];
|
|
400
|
+
if (cellOffset === void 0) return null;
|
|
401
|
+
return tablePos + 1 + cellOffset;
|
|
402
|
+
};
|
|
403
|
+
const anchorPosition = getCellPositionFromMap(topRow, leftCol);
|
|
404
|
+
if (anchorPosition === null) return;
|
|
405
|
+
let headPosition = getCellPositionFromMap(bottomRow, rightCol);
|
|
406
|
+
if (headPosition === null) return;
|
|
407
|
+
if (headPosition === anchorPosition) {
|
|
408
|
+
let foundDifferentCell = false;
|
|
409
|
+
for (let row = bottomRow; row >= topRow && !foundDifferentCell; row--) {
|
|
410
|
+
for (let col = rightCol; col >= leftCol && !foundDifferentCell; col--) {
|
|
411
|
+
const candidatePosition = getCellPositionFromMap(row, col);
|
|
412
|
+
if (candidatePosition !== null && candidatePosition !== anchorPosition) {
|
|
413
|
+
headPosition = candidatePosition;
|
|
414
|
+
foundDifferentCell = true;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
const anchorRef = state.doc.resolve(anchorPosition);
|
|
421
|
+
const headRef = state.doc.resolve(headPosition);
|
|
422
|
+
const cellSelection = new import_tables3.CellSelection(anchorRef, headRef);
|
|
423
|
+
const transaction = state.tr.setSelection(cellSelection);
|
|
424
|
+
return applySelectionWithMode(state, transaction, options);
|
|
425
|
+
} catch (error) {
|
|
426
|
+
console.error("Failed to create cell selection:", error);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function isWithinBounds(row, col, map) {
|
|
431
|
+
return row >= 0 && row < map.height && col >= 0 && col < map.width;
|
|
432
|
+
}
|
|
433
|
+
function applySelectionWithMode(state, transaction, options) {
|
|
434
|
+
var _a;
|
|
435
|
+
const mode = (_a = options.mode) != null ? _a : "state";
|
|
436
|
+
switch (mode) {
|
|
437
|
+
case "dispatch": {
|
|
438
|
+
const dispatchOptions = options;
|
|
439
|
+
if (typeof dispatchOptions.dispatch === "function") {
|
|
440
|
+
dispatchOptions.dispatch(transaction);
|
|
441
|
+
}
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
case "transaction":
|
|
445
|
+
return transaction;
|
|
446
|
+
default:
|
|
447
|
+
return state.apply(transaction);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// src/extensions/table-handle-plugin.ts
|
|
452
|
+
function hideElements(selector, rootEl) {
|
|
453
|
+
rootEl.querySelectorAll(selector).forEach((el) => {
|
|
454
|
+
el.style.visibility = "hidden";
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
var tableHandlePluginKey = new import_state2.PluginKey("tableHandlePlugin");
|
|
458
|
+
var viewRegistry = /* @__PURE__ */ new WeakMap();
|
|
459
|
+
var TableHandleView = class {
|
|
460
|
+
constructor(editor, editorView, emitUpdate) {
|
|
461
|
+
__publicField(this, "editor");
|
|
462
|
+
__publicField(this, "editorView");
|
|
463
|
+
__publicField(this, "state");
|
|
464
|
+
__publicField(this, "menuFrozen", false);
|
|
465
|
+
__publicField(this, "mouseState", "up");
|
|
466
|
+
__publicField(this, "tableId");
|
|
467
|
+
__publicField(this, "tablePos");
|
|
468
|
+
__publicField(this, "tableElement");
|
|
469
|
+
__publicField(this, "hideTimeout", null);
|
|
470
|
+
__publicField(this, "emitUpdate");
|
|
471
|
+
__publicField(this, "viewMousedownHandler", (event) => {
|
|
472
|
+
this.mouseState = "down";
|
|
473
|
+
const { state, view } = this.editor;
|
|
474
|
+
if (!(state.selection instanceof import_tables4.CellSelection) || this.editor.isFocused)
|
|
475
|
+
return;
|
|
476
|
+
const posInfo = view.posAtCoords({
|
|
477
|
+
left: event.clientX,
|
|
478
|
+
top: event.clientY
|
|
479
|
+
});
|
|
480
|
+
if (!posInfo) return;
|
|
481
|
+
const $pos = state.doc.resolve(posInfo.pos);
|
|
482
|
+
const { nodes } = state.schema;
|
|
483
|
+
let paraDepth = -1;
|
|
484
|
+
let inTableCell = false;
|
|
485
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
486
|
+
const node = $pos.node(d);
|
|
487
|
+
if (!inTableCell && (node.type === nodes.tableCell || node.type === nodes.tableHeader)) {
|
|
488
|
+
inTableCell = true;
|
|
489
|
+
}
|
|
490
|
+
if (paraDepth === -1 && node.type === nodes.paragraph) {
|
|
491
|
+
paraDepth = d;
|
|
492
|
+
}
|
|
493
|
+
if (inTableCell && paraDepth !== -1) break;
|
|
494
|
+
}
|
|
495
|
+
if (!inTableCell || paraDepth === -1) return;
|
|
496
|
+
const from = $pos.start(paraDepth);
|
|
497
|
+
const to = $pos.end(paraDepth);
|
|
498
|
+
const nextSel = import_state2.TextSelection.create(state.doc, from, to);
|
|
499
|
+
if (state.selection.eq(nextSel)) return;
|
|
500
|
+
view.dispatch(state.tr.setSelection(nextSel));
|
|
501
|
+
view.focus();
|
|
502
|
+
});
|
|
503
|
+
__publicField(this, "mouseUpHandler", (event) => {
|
|
504
|
+
this.mouseState = "up";
|
|
505
|
+
this.mouseMoveHandler(event);
|
|
506
|
+
});
|
|
507
|
+
__publicField(this, "mouseMoveHandler", (event) => {
|
|
508
|
+
if (this.menuFrozen || this.mouseState === "selecting") return;
|
|
509
|
+
const target = event.target;
|
|
510
|
+
if (!(0, import_shared_utils2.isHTMLElement)(target) || !this.editorView.dom.contains(target)) return;
|
|
511
|
+
this._handleMouseMoveNow(event);
|
|
512
|
+
});
|
|
513
|
+
__publicField(this, "dragOverHandler", (event) => {
|
|
514
|
+
var _a;
|
|
515
|
+
if (((_a = this.state) == null ? void 0 : _a.draggingState) === void 0) {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
event.preventDefault();
|
|
519
|
+
event.dataTransfer.dropEffect = "move";
|
|
520
|
+
hideElements(
|
|
521
|
+
".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",
|
|
522
|
+
this.editorView.root
|
|
523
|
+
);
|
|
524
|
+
const {
|
|
525
|
+
left: tableLeft,
|
|
526
|
+
right: tableRight,
|
|
527
|
+
top: tableTop,
|
|
528
|
+
bottom: tableBottom
|
|
529
|
+
} = this.state.referencePosTable;
|
|
530
|
+
const boundedMouseCoords = {
|
|
531
|
+
left: (0, import_shared_utils2.clamp)(event.clientX, tableLeft + 1, tableRight - 1),
|
|
532
|
+
top: (0, import_shared_utils2.clamp)(event.clientY, tableTop + 1, tableBottom - 1)
|
|
533
|
+
};
|
|
534
|
+
const tableCellElements = this.editorView.root.elementsFromPoint(boundedMouseCoords.left, boundedMouseCoords.top).filter(
|
|
535
|
+
(element) => element.tagName === "TD" || element.tagName === "TH"
|
|
536
|
+
);
|
|
537
|
+
if (tableCellElements.length === 0) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const tableCellElement = tableCellElements[0];
|
|
541
|
+
if (!(0, import_shared_utils2.isHTMLElement)(tableCellElement)) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const cellPosition = getCellIndicesFromDOM(
|
|
545
|
+
tableCellElement,
|
|
546
|
+
this.state.block,
|
|
547
|
+
this.editor
|
|
548
|
+
);
|
|
549
|
+
if (!cellPosition) return;
|
|
550
|
+
const { rowIndex, colIndex } = cellPosition;
|
|
551
|
+
const oldIndex = this.state.draggingState.draggedCellOrientation === "row" ? this.state.rowIndex : this.state.colIndex;
|
|
552
|
+
const newIndex = this.state.draggingState.draggedCellOrientation === "row" ? rowIndex : colIndex;
|
|
553
|
+
const dispatchDecorationsTransaction = newIndex !== oldIndex;
|
|
554
|
+
const mousePos = this.state.draggingState.draggedCellOrientation === "row" ? boundedMouseCoords.top : boundedMouseCoords.left;
|
|
555
|
+
const cellChanged = this.state.rowIndex !== rowIndex || this.state.colIndex !== colIndex;
|
|
556
|
+
const mousePosChanged = this.state.draggingState.mousePos !== mousePos;
|
|
557
|
+
if (cellChanged || mousePosChanged) {
|
|
558
|
+
this.state = {
|
|
559
|
+
...this.state,
|
|
560
|
+
rowIndex,
|
|
561
|
+
colIndex,
|
|
562
|
+
referencePosCell: tableCellElement.getBoundingClientRect(),
|
|
563
|
+
draggingState: {
|
|
564
|
+
...this.state.draggingState,
|
|
565
|
+
mousePos
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
this.emitUpdate();
|
|
569
|
+
}
|
|
570
|
+
if (dispatchDecorationsTransaction) {
|
|
571
|
+
this.editor.view.dispatch(
|
|
572
|
+
this.editor.state.tr.setMeta(tableHandlePluginKey, true)
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
__publicField(this, "dropHandler", () => {
|
|
577
|
+
this.mouseState = "up";
|
|
578
|
+
const st = this.state;
|
|
579
|
+
if (!(st == null ? void 0 : st.draggingState)) return false;
|
|
580
|
+
const { draggingState, rowIndex, colIndex, blockPos } = st;
|
|
581
|
+
if (!(0, import_editor_utils.isValidPosition)(blockPos)) return false;
|
|
582
|
+
if (draggingState.draggedCellOrientation === "row" && rowIndex === void 0 || draggingState.draggedCellOrientation === "col" && colIndex === void 0) {
|
|
583
|
+
console.warn(
|
|
584
|
+
"Attempted to drop table row or column, but no table block was hovered prior."
|
|
585
|
+
);
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
const isRow = draggingState.draggedCellOrientation === "row";
|
|
589
|
+
const orientation = isRow ? "row" : "column";
|
|
590
|
+
const destIndex = isRow ? rowIndex : colIndex;
|
|
591
|
+
const cellCoords = getIndexCoordinates({
|
|
592
|
+
editor: this.editor,
|
|
593
|
+
index: draggingState.originalIndex,
|
|
594
|
+
orientation,
|
|
595
|
+
tablePos: blockPos
|
|
596
|
+
});
|
|
597
|
+
if (!cellCoords) return false;
|
|
598
|
+
const stateWithCellSel = selectCellsByCoords(
|
|
599
|
+
this.editor,
|
|
600
|
+
blockPos,
|
|
601
|
+
cellCoords,
|
|
602
|
+
{ mode: "state" }
|
|
603
|
+
);
|
|
604
|
+
if (!stateWithCellSel) return false;
|
|
605
|
+
const dispatch = (tr) => this.editor.view.dispatch(tr);
|
|
606
|
+
if (isRow) {
|
|
607
|
+
(0, import_tables4.moveTableRow)({
|
|
608
|
+
from: draggingState.originalIndex,
|
|
609
|
+
to: destIndex,
|
|
610
|
+
select: true,
|
|
611
|
+
pos: blockPos + 1
|
|
612
|
+
})(stateWithCellSel, dispatch);
|
|
613
|
+
} else {
|
|
614
|
+
(0, import_tables4.moveTableColumn)({
|
|
615
|
+
from: draggingState.originalIndex,
|
|
616
|
+
to: destIndex,
|
|
617
|
+
select: true,
|
|
618
|
+
pos: blockPos + 1
|
|
619
|
+
})(stateWithCellSel, dispatch);
|
|
620
|
+
}
|
|
621
|
+
this.state = { ...st, draggingState: void 0 };
|
|
622
|
+
this.emitUpdate();
|
|
623
|
+
this.editor.view.dispatch(
|
|
624
|
+
this.editor.state.tr.setMeta(tableHandlePluginKey, null)
|
|
625
|
+
);
|
|
626
|
+
return true;
|
|
627
|
+
});
|
|
628
|
+
this.editor = editor;
|
|
629
|
+
this.editorView = editorView;
|
|
630
|
+
this.emitUpdate = () => this.state && emitUpdate(this.state);
|
|
631
|
+
viewRegistry.set(editor, this);
|
|
632
|
+
this.editorView.dom.addEventListener("mousemove", this.mouseMoveHandler);
|
|
633
|
+
this.editorView.dom.addEventListener(
|
|
634
|
+
"mousedown",
|
|
635
|
+
this.viewMousedownHandler
|
|
636
|
+
);
|
|
637
|
+
window.addEventListener("mouseup", this.mouseUpHandler);
|
|
638
|
+
this.editorView.root.addEventListener(
|
|
639
|
+
"dragover",
|
|
640
|
+
this.dragOverHandler
|
|
641
|
+
);
|
|
642
|
+
this.editorView.root.addEventListener(
|
|
643
|
+
"drop",
|
|
644
|
+
this.dropHandler
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Schedule a delayed hide of handles. This allows the user to cross
|
|
649
|
+
* gaps between table cells and floating handles without the handles
|
|
650
|
+
* disappearing prematurely.
|
|
651
|
+
*/
|
|
652
|
+
scheduleHide() {
|
|
653
|
+
if (this.hideTimeout) return;
|
|
654
|
+
this.hideTimeout = setTimeout(() => {
|
|
655
|
+
this.hideTimeout = null;
|
|
656
|
+
if (!this.menuFrozen) {
|
|
657
|
+
this.hideHandles();
|
|
658
|
+
}
|
|
659
|
+
}, 200);
|
|
660
|
+
}
|
|
661
|
+
cancelScheduledHide() {
|
|
662
|
+
if (this.hideTimeout) {
|
|
663
|
+
clearTimeout(this.hideTimeout);
|
|
664
|
+
this.hideTimeout = null;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
hideHandles() {
|
|
668
|
+
var _a;
|
|
669
|
+
this.cancelScheduledHide();
|
|
670
|
+
if (!((_a = this.state) == null ? void 0 : _a.show)) return;
|
|
671
|
+
this.state = {
|
|
672
|
+
...this.state,
|
|
673
|
+
show: false,
|
|
674
|
+
showAddOrRemoveRowsButton: false,
|
|
675
|
+
showAddOrRemoveColumnsButton: false,
|
|
676
|
+
colIndex: void 0,
|
|
677
|
+
rowIndex: void 0,
|
|
678
|
+
referencePosCell: void 0
|
|
679
|
+
};
|
|
680
|
+
this.emitUpdate();
|
|
681
|
+
}
|
|
682
|
+
_handleMouseMoveNow(event) {
|
|
683
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
684
|
+
const around = domCellAround(event.target);
|
|
685
|
+
if ((around == null ? void 0 : around.type) === "cell" && this.mouseState === "down" && !((_a = this.state) == null ? void 0 : _a.draggingState)) {
|
|
686
|
+
this.mouseState = "selecting";
|
|
687
|
+
this.cancelScheduledHide();
|
|
688
|
+
this.hideHandles();
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (!around || !this.editor.isEditable) {
|
|
692
|
+
this.scheduleHide();
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
this.cancelScheduledHide();
|
|
696
|
+
const tbody = around.tbodyNode;
|
|
697
|
+
if (!tbody) return;
|
|
698
|
+
let tableRect = tbody.getBoundingClientRect();
|
|
699
|
+
if (tableRect.width === 0 && tableRect.height === 0) {
|
|
700
|
+
const fallback = (_b = tbody.closest(".table-container")) != null ? _b : tbody.closest(".tableWrapper");
|
|
701
|
+
if (!fallback) return;
|
|
702
|
+
tableRect = fallback.getBoundingClientRect();
|
|
703
|
+
}
|
|
704
|
+
const coords = this.editor.view.posAtCoords({
|
|
705
|
+
left: event.clientX,
|
|
706
|
+
top: event.clientY
|
|
707
|
+
});
|
|
708
|
+
if (!coords) return;
|
|
709
|
+
const $pos = this.editor.view.state.doc.resolve(coords.pos);
|
|
710
|
+
let blockInfo;
|
|
711
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
712
|
+
const node = $pos.node(d);
|
|
713
|
+
if (isTableNode(node)) {
|
|
714
|
+
blockInfo = { node, pos: d === 0 ? 0 : $pos.before(d) };
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (!blockInfo || blockInfo.node.type.name !== "table") return;
|
|
719
|
+
this.tableElement = this.editor.view.nodeDOM(blockInfo.pos);
|
|
720
|
+
this.tablePos = blockInfo.pos;
|
|
721
|
+
this.tableId = blockInfo.node.attrs.id;
|
|
722
|
+
const widgetContainer = (_c = this.tableElement) == null ? void 0 : _c.querySelector(
|
|
723
|
+
".table-controls"
|
|
724
|
+
);
|
|
725
|
+
if (around.type === "wrapper") {
|
|
726
|
+
const below = event.clientY >= tableRect.bottom - 1 && event.clientY < tableRect.bottom + 20;
|
|
727
|
+
const right = event.clientX >= tableRect.right - 1 && event.clientX < tableRect.right + 20;
|
|
728
|
+
const cursorBeyondRightOrBottom = event.clientX > tableRect.right || event.clientY > tableRect.bottom;
|
|
729
|
+
this.state = {
|
|
730
|
+
...this.state,
|
|
731
|
+
show: true,
|
|
732
|
+
showAddOrRemoveRowsButton: below,
|
|
733
|
+
showAddOrRemoveColumnsButton: right,
|
|
734
|
+
referencePosTable: tableRect,
|
|
735
|
+
block: blockInfo.node,
|
|
736
|
+
blockPos: blockInfo.pos,
|
|
737
|
+
widgetContainer,
|
|
738
|
+
colIndex: cursorBeyondRightOrBottom ? void 0 : (_d = this.state) == null ? void 0 : _d.colIndex,
|
|
739
|
+
rowIndex: cursorBeyondRightOrBottom ? void 0 : (_e = this.state) == null ? void 0 : _e.rowIndex,
|
|
740
|
+
referencePosCell: cursorBeyondRightOrBottom ? void 0 : (_f = this.state) == null ? void 0 : _f.referencePosCell
|
|
741
|
+
};
|
|
742
|
+
} else {
|
|
743
|
+
const cellPosition = getCellIndicesFromDOM(
|
|
744
|
+
around.domNode,
|
|
745
|
+
blockInfo.node,
|
|
746
|
+
this.editor
|
|
747
|
+
);
|
|
748
|
+
if (!cellPosition) return;
|
|
749
|
+
const { rowIndex, colIndex } = cellPosition;
|
|
750
|
+
const cellRect = around.domNode.getBoundingClientRect();
|
|
751
|
+
const lastRowIndex = blockInfo.node.content.childCount - 1;
|
|
752
|
+
const lastColIndex = ((_h = (_g = blockInfo.node.content.firstChild) == null ? void 0 : _g.content.childCount) != null ? _h : 0) - 1;
|
|
753
|
+
if (((_i = this.state) == null ? void 0 : _i.show) && this.tableId === blockInfo.node.attrs.id && this.state.rowIndex === rowIndex && this.state.colIndex === colIndex) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
this.state = {
|
|
757
|
+
show: true,
|
|
758
|
+
showAddOrRemoveColumnsButton: colIndex === lastColIndex,
|
|
759
|
+
showAddOrRemoveRowsButton: rowIndex === lastRowIndex,
|
|
760
|
+
referencePosTable: tableRect,
|
|
761
|
+
block: blockInfo.node,
|
|
762
|
+
blockPos: blockInfo.pos,
|
|
763
|
+
draggingState: void 0,
|
|
764
|
+
referencePosCell: cellRect,
|
|
765
|
+
colIndex,
|
|
766
|
+
rowIndex,
|
|
767
|
+
widgetContainer
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
this.emitUpdate();
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
update(view) {
|
|
774
|
+
var _a, _b, _c, _d;
|
|
775
|
+
const pluginState = tableHandlePluginKey.getState(view.state);
|
|
776
|
+
if (pluginState !== void 0 && pluginState !== this.menuFrozen) {
|
|
777
|
+
this.menuFrozen = pluginState;
|
|
778
|
+
if (this.menuFrozen) {
|
|
779
|
+
this.cancelScheduledHide();
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (!((_a = this.state) == null ? void 0 : _a.show)) return;
|
|
783
|
+
if (!((_b = this.tableElement) == null ? void 0 : _b.isConnected)) {
|
|
784
|
+
this.hideHandles();
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
const tableInfo = getTableFromDOM(this.tableElement, this.editor);
|
|
788
|
+
if (!tableInfo) {
|
|
789
|
+
this.hideHandles();
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const blockChanged = this.state.block !== tableInfo.node || this.state.blockPos !== tableInfo.pos;
|
|
793
|
+
if (!tableInfo.node || tableInfo.node.type.name !== "table" || !((_c = this.tableElement) == null ? void 0 : _c.isConnected)) {
|
|
794
|
+
this.hideHandles();
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const { height: rowCount, width: colCount } = import_tables4.TableMap.get(tableInfo.node);
|
|
798
|
+
let newRowIndex = this.state.rowIndex;
|
|
799
|
+
let newColIndex = this.state.colIndex;
|
|
800
|
+
if (newRowIndex !== void 0 && newRowIndex >= rowCount) {
|
|
801
|
+
newRowIndex = rowCount ? rowCount - 1 : void 0;
|
|
802
|
+
}
|
|
803
|
+
if (newColIndex !== void 0 && newColIndex >= colCount) {
|
|
804
|
+
newColIndex = colCount ? colCount - 1 : void 0;
|
|
805
|
+
}
|
|
806
|
+
const tableBody = this.tableElement.querySelector("tbody");
|
|
807
|
+
if (!tableBody) {
|
|
808
|
+
throw new Error(
|
|
809
|
+
"Table block does not contain a 'tbody' HTML element. This should never happen."
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
let newReferencePosCell = this.state.referencePosCell;
|
|
813
|
+
if (newRowIndex !== void 0 && newColIndex !== void 0) {
|
|
814
|
+
const rowEl = tableBody.children[newRowIndex];
|
|
815
|
+
const cellEl = rowEl == null ? void 0 : rowEl.children[newColIndex];
|
|
816
|
+
if (cellEl) {
|
|
817
|
+
newReferencePosCell = cellEl.getBoundingClientRect();
|
|
818
|
+
} else {
|
|
819
|
+
newRowIndex = void 0;
|
|
820
|
+
newColIndex = void 0;
|
|
821
|
+
newReferencePosCell = void 0;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
let newReferencePosTable = tableBody.getBoundingClientRect();
|
|
825
|
+
if (newReferencePosTable.width === 0 && newReferencePosTable.height === 0) {
|
|
826
|
+
const fallback = (_d = tableBody.closest(".table-container")) != null ? _d : tableBody.closest(".tableWrapper");
|
|
827
|
+
if (fallback) {
|
|
828
|
+
newReferencePosTable = fallback.getBoundingClientRect();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
const indicesChanged = newRowIndex !== this.state.rowIndex || newColIndex !== this.state.colIndex;
|
|
832
|
+
const refPosChanged = newReferencePosCell !== this.state.referencePosCell || newReferencePosTable !== this.state.referencePosTable;
|
|
833
|
+
if (blockChanged || indicesChanged || refPosChanged) {
|
|
834
|
+
this.state = {
|
|
835
|
+
...this.state,
|
|
836
|
+
block: tableInfo.node,
|
|
837
|
+
blockPos: tableInfo.pos,
|
|
838
|
+
rowIndex: newRowIndex,
|
|
839
|
+
colIndex: newColIndex,
|
|
840
|
+
referencePosCell: newReferencePosCell,
|
|
841
|
+
referencePosTable: newReferencePosTable
|
|
842
|
+
};
|
|
843
|
+
this.emitUpdate();
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
destroy() {
|
|
847
|
+
this.cancelScheduledHide();
|
|
848
|
+
viewRegistry.delete(this.editor);
|
|
849
|
+
this.editorView.dom.removeEventListener(
|
|
850
|
+
"mousemove",
|
|
851
|
+
this.mouseMoveHandler
|
|
852
|
+
);
|
|
853
|
+
window.removeEventListener("mouseup", this.mouseUpHandler);
|
|
854
|
+
this.editorView.dom.removeEventListener(
|
|
855
|
+
"mousedown",
|
|
856
|
+
this.viewMousedownHandler
|
|
857
|
+
);
|
|
858
|
+
this.editorView.root.removeEventListener(
|
|
859
|
+
"dragover",
|
|
860
|
+
this.dragOverHandler
|
|
861
|
+
);
|
|
862
|
+
this.editorView.root.removeEventListener(
|
|
863
|
+
"drop",
|
|
864
|
+
this.dropHandler
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
function TableHandlePlugin(editor, emitUpdate) {
|
|
869
|
+
let viewInstance = null;
|
|
870
|
+
return new import_state2.Plugin({
|
|
871
|
+
key: tableHandlePluginKey,
|
|
872
|
+
state: {
|
|
873
|
+
init: () => false,
|
|
874
|
+
apply: (tr, frozen) => {
|
|
875
|
+
const meta = tr.getMeta(tableHandlePluginKey);
|
|
876
|
+
return meta !== void 0 ? meta : frozen;
|
|
877
|
+
}
|
|
878
|
+
},
|
|
879
|
+
view: (editorView) => {
|
|
880
|
+
viewInstance = new TableHandleView(editor, editorView, emitUpdate);
|
|
881
|
+
return viewInstance;
|
|
882
|
+
},
|
|
883
|
+
props: {
|
|
884
|
+
decorations: (state) => {
|
|
885
|
+
if (!viewInstance || viewInstance.state === void 0 || viewInstance.state.draggingState === void 0 || viewInstance.tablePos === void 0) {
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
const newIndex = viewInstance.state.draggingState.draggedCellOrientation === "row" ? viewInstance.state.rowIndex : viewInstance.state.colIndex;
|
|
889
|
+
if (newIndex === void 0) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
const decorations = [];
|
|
893
|
+
const { draggingState } = viewInstance.state;
|
|
894
|
+
const { originalIndex } = draggingState;
|
|
895
|
+
if (viewInstance.state.draggingState.draggedCellOrientation === "row") {
|
|
896
|
+
const originalCells = getRowCells(
|
|
897
|
+
editor,
|
|
898
|
+
originalIndex,
|
|
899
|
+
viewInstance.state.blockPos
|
|
900
|
+
);
|
|
901
|
+
originalCells.cells.forEach((cell) => {
|
|
902
|
+
if (cell.node) {
|
|
903
|
+
decorations.push(
|
|
904
|
+
import_view.Decoration.node(cell.pos, cell.pos + cell.node.nodeSize, {
|
|
905
|
+
class: "table-cell-dragging-source"
|
|
906
|
+
})
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
} else {
|
|
911
|
+
const originalCells = getColumnCells(
|
|
912
|
+
editor,
|
|
913
|
+
originalIndex,
|
|
914
|
+
viewInstance.state.blockPos
|
|
915
|
+
);
|
|
916
|
+
originalCells.cells.forEach((cell) => {
|
|
917
|
+
if (cell.node) {
|
|
918
|
+
decorations.push(
|
|
919
|
+
import_view.Decoration.node(cell.pos, cell.pos + cell.node.nodeSize, {
|
|
920
|
+
class: "table-cell-dragging-source"
|
|
921
|
+
})
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
if (newIndex === originalIndex || !editor) {
|
|
927
|
+
return import_view.DecorationSet.create(state.doc, decorations);
|
|
928
|
+
}
|
|
929
|
+
if (viewInstance.state.draggingState.draggedCellOrientation === "row") {
|
|
930
|
+
const cellsInRow = getRowCells(
|
|
931
|
+
editor,
|
|
932
|
+
newIndex,
|
|
933
|
+
viewInstance.state.blockPos
|
|
934
|
+
);
|
|
935
|
+
cellsInRow.cells.forEach((cell) => {
|
|
936
|
+
const cellNode = cell.node;
|
|
937
|
+
if (!cellNode) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const decorationPos = cell.pos + (newIndex > originalIndex ? cellNode.nodeSize - 2 : 2);
|
|
941
|
+
decorations.push(
|
|
942
|
+
import_view.Decoration.widget(decorationPos, () => {
|
|
943
|
+
const widget = document.createElement("div");
|
|
944
|
+
widget.className = "tiptap-table-dropcursor";
|
|
945
|
+
widget.style.left = "0";
|
|
946
|
+
widget.style.right = "0";
|
|
947
|
+
if (newIndex > originalIndex) {
|
|
948
|
+
widget.style.bottom = "-1px";
|
|
949
|
+
} else {
|
|
950
|
+
widget.style.top = "-1px";
|
|
951
|
+
}
|
|
952
|
+
widget.style.height = "3px";
|
|
953
|
+
return widget;
|
|
954
|
+
})
|
|
955
|
+
);
|
|
956
|
+
});
|
|
957
|
+
} else {
|
|
958
|
+
const cellsInColumn = getColumnCells(
|
|
959
|
+
editor,
|
|
960
|
+
newIndex,
|
|
961
|
+
viewInstance.state.blockPos
|
|
962
|
+
);
|
|
963
|
+
cellsInColumn.cells.forEach((cell) => {
|
|
964
|
+
const cellNode = cell.node;
|
|
965
|
+
if (!cellNode) {
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
const decorationPos = cell.pos + (newIndex > originalIndex ? cellNode.nodeSize - 2 : 2);
|
|
969
|
+
decorations.push(
|
|
970
|
+
import_view.Decoration.widget(decorationPos, () => {
|
|
971
|
+
const widget = document.createElement("div");
|
|
972
|
+
widget.className = "tiptap-table-dropcursor";
|
|
973
|
+
widget.style.top = "0";
|
|
974
|
+
widget.style.bottom = "0";
|
|
975
|
+
if (newIndex > originalIndex) {
|
|
976
|
+
widget.style.right = "-1px";
|
|
977
|
+
} else {
|
|
978
|
+
widget.style.left = "-1px";
|
|
979
|
+
}
|
|
980
|
+
widget.style.width = "3px";
|
|
981
|
+
return widget;
|
|
982
|
+
})
|
|
983
|
+
);
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
return import_view.DecorationSet.create(state.doc, decorations);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// src/extensions/table-handle.ts
|
|
993
|
+
var TableHandleExtension = import_core.Extension.create({
|
|
994
|
+
name: "tableHandleExtension",
|
|
995
|
+
addCommands() {
|
|
996
|
+
return {
|
|
997
|
+
freezeHandles: () => ({ tr, dispatch }) => {
|
|
998
|
+
if (dispatch) tr.setMeta(tableHandlePluginKey, true);
|
|
999
|
+
return true;
|
|
1000
|
+
},
|
|
1001
|
+
unfreezeHandles: () => ({ tr, dispatch }) => {
|
|
1002
|
+
if (dispatch) tr.setMeta(tableHandlePluginKey, false);
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
},
|
|
1007
|
+
addProseMirrorPlugins() {
|
|
1008
|
+
const { editor } = this;
|
|
1009
|
+
return [
|
|
1010
|
+
TableHandlePlugin(editor, (state) => {
|
|
1011
|
+
this.editor.emit("tableHandleState", state);
|
|
1012
|
+
})
|
|
1013
|
+
];
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
// src/extensions/kit.ts
|
|
1018
|
+
var TableKit = import_react.Extension.create({
|
|
1019
|
+
name: "tableKit",
|
|
1020
|
+
addExtensions() {
|
|
1021
|
+
const extensions = [];
|
|
1022
|
+
if (this.options.table !== false) {
|
|
1023
|
+
extensions.push(TableHandleExtension);
|
|
1024
|
+
extensions.push(Table.configure(this.options.table));
|
|
1025
|
+
}
|
|
1026
|
+
if (this.options.tableCell !== false) {
|
|
1027
|
+
extensions.push(TableCell.configure(this.options.tableCell));
|
|
1028
|
+
}
|
|
1029
|
+
if (this.options.tableHeader !== false) {
|
|
1030
|
+
extensions.push(import_extension_table2.TableHeader.configure(this.options.tableHeader));
|
|
1031
|
+
}
|
|
1032
|
+
if (this.options.tableRow !== false) {
|
|
1033
|
+
extensions.push(import_extension_table2.TableRow.configure(this.options.tableRow));
|
|
1034
|
+
}
|
|
1035
|
+
return extensions;
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1039
|
+
0 && (module.exports = {
|
|
1040
|
+
TableKit
|
|
1041
|
+
});
|