@kopexa/extension-table 17.0.46 → 17.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2NBDRVYL.mjs +428 -0
- package/dist/chunk-3SWV7BGP.mjs +638 -0
- package/dist/chunk-4JC7NB5Y.mjs +96 -0
- package/dist/{chunk-2L3HZWWG.mjs → chunk-4XRAUUXQ.mjs} +7 -8
- package/dist/chunk-5B5XIL2G.mjs +457 -0
- package/dist/chunk-6FHFDGJO.mjs +251 -0
- package/dist/chunk-CD62W5C3.mjs +165 -0
- package/dist/chunk-CN73TYHV.mjs +190 -0
- package/dist/chunk-CPDSPBS6.mjs +276 -0
- package/dist/chunk-E7W2KRZG.mjs +49 -0
- package/dist/chunk-G6GHC2WO.mjs +276 -0
- package/dist/chunk-GBTQVIN5.mjs +174 -0
- package/dist/chunk-GDEXPEW5.mjs +52 -0
- package/dist/chunk-GQLZBIWF.mjs +198 -0
- package/dist/chunk-J4VOSZCZ.mjs +59 -0
- package/dist/chunk-JQEUL3LT.mjs +276 -0
- package/dist/chunk-JSUVBKCI.mjs +116 -0
- package/dist/chunk-KIYFW7MP.mjs +122 -0
- package/dist/chunk-KTRZVXJC.mjs +306 -0
- package/dist/chunk-LUA32VH4.mjs +35 -0
- package/dist/chunk-LULO6UOC.mjs +603 -0
- package/dist/chunk-PTX5UYV6.mjs +10 -0
- package/dist/chunk-QI7CA4YV.mjs +149 -0
- package/dist/chunk-VIBVRWS4.mjs +197 -0
- package/dist/chunk-VQV757EG.mjs +113 -0
- package/dist/chunk-ZVPJDJBO.mjs +134 -0
- package/dist/{kit.d.mts → extensions/kit.d.mts} +1 -3
- package/dist/{kit.d.ts → extensions/kit.d.ts} +1 -3
- package/dist/extensions/kit.js +1041 -0
- package/dist/extensions/kit.mjs +15 -0
- package/dist/extensions/table-cell.d.mts +6 -0
- package/dist/extensions/table-cell.d.ts +6 -0
- package/dist/extensions/table-cell.js +70 -0
- package/dist/extensions/table-cell.mjs +8 -0
- package/dist/extensions/table-handle-plugin.d.mts +46 -0
- package/dist/extensions/table-handle-plugin.d.ts +46 -0
- package/dist/extensions/table-handle-plugin.js +1100 -0
- package/dist/extensions/table-handle-plugin.mjs +18 -0
- package/dist/extensions/table-handle.d.mts +19 -0
- package/dist/extensions/table-handle.d.ts +19 -0
- package/dist/extensions/table-handle.js +865 -0
- package/dist/extensions/table-handle.mjs +11 -0
- package/dist/{table → extensions}/table.d.mts +2 -2
- package/dist/{table → extensions}/table.d.ts +2 -2
- package/dist/extensions/table.js +138 -0
- package/dist/extensions/table.mjs +9 -0
- package/dist/hooks/use-resize-overlay.d.mts +5 -0
- package/dist/hooks/use-resize-overlay.d.ts +5 -0
- package/dist/hooks/use-resize-overlay.js +83 -0
- package/dist/hooks/use-resize-overlay.mjs +9 -0
- package/dist/hooks/use-table-add-row-column.d.mts +57 -0
- package/dist/hooks/use-table-add-row-column.d.ts +57 -0
- package/dist/hooks/use-table-add-row-column.js +551 -0
- package/dist/hooks/use-table-add-row-column.mjs +11 -0
- package/dist/hooks/use-table-align-cell.d.mts +148 -0
- package/dist/hooks/use-table-align-cell.d.ts +148 -0
- package/dist/hooks/use-table-align-cell.js +655 -0
- package/dist/hooks/use-table-align-cell.mjs +13 -0
- package/dist/hooks/use-table-clear-row-column-content.d.mts +103 -0
- package/dist/hooks/use-table-clear-row-column-content.d.ts +103 -0
- package/dist/hooks/use-table-clear-row-column-content.js +681 -0
- package/dist/hooks/use-table-clear-row-column-content.mjs +11 -0
- package/dist/hooks/use-table-delete-row-column.d.mts +87 -0
- package/dist/hooks/use-table-delete-row-column.d.ts +87 -0
- package/dist/hooks/use-table-delete-row-column.js +459 -0
- package/dist/hooks/use-table-delete-row-column.mjs +11 -0
- package/dist/hooks/use-table-duplicate-row-column.d.mts +49 -0
- package/dist/hooks/use-table-duplicate-row-column.d.ts +49 -0
- package/dist/hooks/use-table-duplicate-row-column.js +758 -0
- package/dist/hooks/use-table-duplicate-row-column.mjs +11 -0
- package/dist/hooks/use-table-handle-positioning.d.mts +42 -0
- package/dist/hooks/use-table-handle-positioning.d.ts +42 -0
- package/dist/hooks/use-table-handle-positioning.js +190 -0
- package/dist/hooks/use-table-handle-positioning.mjs +10 -0
- package/dist/hooks/use-table-handle-state.d.mts +28 -0
- package/dist/hooks/use-table-handle-state.d.ts +28 -0
- package/dist/hooks/use-table-handle-state.js +76 -0
- package/dist/hooks/use-table-handle-state.mjs +9 -0
- package/dist/hooks/use-table-header-row-column.d.mts +58 -0
- package/dist/hooks/use-table-header-row-column.d.ts +58 -0
- package/dist/hooks/use-table-header-row-column.js +603 -0
- package/dist/hooks/use-table-header-row-column.mjs +13 -0
- package/dist/hooks/use-table-merge-split-cell.d.mts +123 -0
- package/dist/hooks/use-table-merge-split-cell.d.ts +123 -0
- package/dist/hooks/use-table-merge-split-cell.js +331 -0
- package/dist/hooks/use-table-merge-split-cell.mjs +12 -0
- package/dist/hooks/use-table-move-row-column.d.mts +101 -0
- package/dist/hooks/use-table-move-row-column.d.ts +101 -0
- package/dist/hooks/use-table-move-row-column.js +621 -0
- package/dist/hooks/use-table-move-row-column.mjs +13 -0
- package/dist/hooks/use-table-sort-row-column.d.mts +118 -0
- package/dist/hooks/use-table-sort-row-column.d.ts +118 -0
- package/dist/hooks/use-table-sort-row-column.js +623 -0
- package/dist/hooks/use-table-sort-row-column.mjs +13 -0
- package/dist/index.d.mts +17 -6
- package/dist/index.d.ts +17 -6
- package/dist/index.js +4947 -660
- package/dist/index.mjs +43 -21
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/{table/lib/is-cell-selection.js → lib/constants.js} +10 -10
- package/dist/lib/constants.mjs +10 -0
- package/dist/lib/create-image.d.mts +12 -0
- package/dist/lib/create-image.d.ts +12 -0
- package/dist/lib/create-image.js +221 -0
- package/dist/lib/create-image.mjs +8 -0
- package/dist/lib/table-utils.d.mts +263 -0
- package/dist/lib/table-utils.d.ts +263 -0
- package/dist/lib/table-utils.js +488 -0
- package/dist/lib/table-utils.mjs +40 -0
- package/dist/messages.d.mts +174 -0
- package/dist/messages.d.ts +174 -0
- package/dist/messages.js +213 -0
- package/dist/{table-row.mjs → messages.mjs} +3 -3
- package/dist/ui/table-alignment-menu.d.mts +25 -0
- package/dist/ui/table-alignment-menu.d.ts +25 -0
- package/dist/ui/table-alignment-menu.js +758 -0
- package/dist/ui/table-alignment-menu.mjs +14 -0
- package/dist/ui/table-cell-handle-menu.d.mts +12 -0
- package/dist/ui/table-cell-handle-menu.d.ts +12 -0
- package/dist/ui/table-cell-handle-menu.js +1317 -0
- package/dist/ui/table-cell-handle-menu.mjs +17 -0
- package/dist/ui/table-handle-menu.d.mts +23 -0
- package/dist/ui/table-handle-menu.d.ts +23 -0
- package/dist/ui/table-handle-menu.js +2598 -0
- package/dist/ui/table-handle-menu.mjs +21 -0
- package/dist/ui/table-handle.d.mts +48 -0
- package/dist/ui/table-handle.d.ts +48 -0
- package/dist/ui/table-handle.js +3126 -0
- package/dist/ui/table-handle.mjs +22 -0
- package/dist/ui/table-selection-overlay.d.mts +14 -0
- package/dist/ui/table-selection-overlay.d.ts +14 -0
- package/dist/ui/table-selection-overlay.js +553 -0
- package/dist/ui/table-selection-overlay.mjs +11 -0
- package/package.json +12 -7
- package/dist/chunk-3XEOCAHB.mjs +0 -41
- package/dist/chunk-5W5ARI64.mjs +0 -11
- package/dist/chunk-BTJ3DCGC.mjs +0 -113
- package/dist/chunk-DR2GZJH6.mjs +0 -70
- package/dist/chunk-GHOJLOCF.mjs +0 -247
- package/dist/chunk-HWVA6DOK.mjs +0 -20
- package/dist/chunk-KLUH6EZS.mjs +0 -40
- package/dist/chunk-KNOMCS6F.mjs +0 -57
- package/dist/chunk-LPHCE6EI.mjs +0 -92
- package/dist/chunk-POJFNXG7.mjs +0 -44
- package/dist/chunk-QHD3QTD2.mjs +0 -61
- package/dist/chunk-RPPUD4R5.mjs +0 -1
- package/dist/kit.js +0 -764
- package/dist/kit.mjs +0 -19
- package/dist/table/index.d.mts +0 -6
- package/dist/table/index.d.ts +0 -6
- package/dist/table/index.js +0 -625
- package/dist/table/index.mjs +0 -18
- package/dist/table/lib/col-style.d.mts +0 -3
- package/dist/table/lib/col-style.d.ts +0 -3
- package/dist/table/lib/col-style.js +0 -36
- package/dist/table/lib/col-style.mjs +0 -13
- package/dist/table/lib/delete-table-when-all-cells-selected.d.mts +0 -5
- package/dist/table/lib/delete-table-when-all-cells-selected.d.ts +0 -5
- package/dist/table/lib/delete-table-when-all-cells-selected.js +0 -66
- package/dist/table/lib/delete-table-when-all-cells-selected.mjs +0 -40
- package/dist/table/lib/get-table-node-types.d.mts +0 -7
- package/dist/table/lib/get-table-node-types.d.ts +0 -7
- package/dist/table/lib/get-table-node-types.js +0 -44
- package/dist/table/lib/get-table-node-types.mjs +0 -21
- package/dist/table/lib/icons.d.mts +0 -13
- package/dist/table/lib/icons.d.ts +0 -13
- package/dist/table/lib/icons.js +0 -81
- package/dist/table/lib/icons.mjs +0 -58
- package/dist/table/lib/insert-line-above-table-action.d.mts +0 -5
- package/dist/table/lib/insert-line-above-table-action.d.ts +0 -5
- package/dist/table/lib/insert-line-above-table-action.js +0 -64
- package/dist/table/lib/insert-line-above-table-action.mjs +0 -8
- package/dist/table/lib/insert-line-below-table-action.d.mts +0 -5
- package/dist/table/lib/insert-line-below-table-action.d.ts +0 -5
- package/dist/table/lib/insert-line-below-table-action.js +0 -63
- package/dist/table/lib/insert-line-below-table-action.mjs +0 -8
- package/dist/table/lib/is-cell-selection.d.mts +0 -5
- package/dist/table/lib/is-cell-selection.d.ts +0 -5
- package/dist/table/lib/is-cell-selection.mjs +0 -8
- package/dist/table/lib/table-controls.d.mts +0 -15
- package/dist/table/lib/table-controls.d.ts +0 -15
- package/dist/table/lib/table-controls.js +0 -131
- package/dist/table/lib/table-controls.mjs +0 -8
- package/dist/table/table.js +0 -621
- package/dist/table/table.mjs +0 -14
- package/dist/table/views/table-column-menu.d.mts +0 -11
- package/dist/table/views/table-column-menu.d.ts +0 -11
- package/dist/table/views/table-column-menu.js +0 -84
- package/dist/table/views/table-column-menu.mjs +0 -8
- package/dist/table/views/table-node-view.d.mts +0 -25
- package/dist/table/views/table-node-view.d.ts +0 -25
- package/dist/table/views/table-node-view.js +0 -370
- package/dist/table/views/table-node-view.mjs +0 -10
- package/dist/table/views/table-row-menu.d.mts +0 -11
- package/dist/table/views/table-row-menu.d.ts +0 -11
- package/dist/table/views/table-row-menu.js +0 -80
- package/dist/table/views/table-row-menu.mjs +0 -8
- package/dist/table-cell.d.mts +0 -8
- package/dist/table-cell.d.ts +0 -8
- package/dist/table-cell.js +0 -93
- package/dist/table-cell.mjs +0 -8
- package/dist/table-header.d.mts +0 -6
- package/dist/table-header.d.ts +0 -6
- package/dist/table-header.js +0 -67
- package/dist/table-header.mjs +0 -8
- package/dist/table-row.d.mts +0 -6
- package/dist/table-row.d.ts +0 -6
- package/dist/table-row.js +0 -43
|
@@ -0,0 +1,1100 @@
|
|
|
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/table-handle-plugin.ts
|
|
24
|
+
var table_handle_plugin_exports = {};
|
|
25
|
+
__export(table_handle_plugin_exports, {
|
|
26
|
+
TableHandlePlugin: () => TableHandlePlugin,
|
|
27
|
+
colDragStart: () => colDragStart,
|
|
28
|
+
dragEnd: () => dragEnd,
|
|
29
|
+
rowDragStart: () => rowDragStart,
|
|
30
|
+
tableHandlePluginKey: () => tableHandlePluginKey
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(table_handle_plugin_exports);
|
|
33
|
+
var import_editor_utils = require("@kopexa/editor-utils");
|
|
34
|
+
var import_shared_utils2 = require("@kopexa/shared-utils");
|
|
35
|
+
var import_state = require("@tiptap/pm/state");
|
|
36
|
+
var import_tables2 = require("@tiptap/pm/tables");
|
|
37
|
+
var import_view = require("@tiptap/pm/view");
|
|
38
|
+
|
|
39
|
+
// src/lib/create-image.ts
|
|
40
|
+
var STYLE_PROPS = [
|
|
41
|
+
// Box & border
|
|
42
|
+
"boxSizing",
|
|
43
|
+
"backgroundColor",
|
|
44
|
+
"borderTopColor",
|
|
45
|
+
"borderRightColor",
|
|
46
|
+
"borderBottomColor",
|
|
47
|
+
"borderLeftColor",
|
|
48
|
+
"borderTopStyle",
|
|
49
|
+
"borderRightStyle",
|
|
50
|
+
"borderBottomStyle",
|
|
51
|
+
"borderLeftStyle",
|
|
52
|
+
"borderTopWidth",
|
|
53
|
+
"borderRightWidth",
|
|
54
|
+
"borderBottomWidth",
|
|
55
|
+
"borderLeftWidth",
|
|
56
|
+
"borderRadius",
|
|
57
|
+
// Spacing
|
|
58
|
+
"paddingTop",
|
|
59
|
+
"paddingRight",
|
|
60
|
+
"paddingBottom",
|
|
61
|
+
"paddingLeft",
|
|
62
|
+
// Typography
|
|
63
|
+
"color",
|
|
64
|
+
"font",
|
|
65
|
+
"fontFamily",
|
|
66
|
+
"fontSize",
|
|
67
|
+
"fontWeight",
|
|
68
|
+
"fontStyle",
|
|
69
|
+
"lineHeight",
|
|
70
|
+
"letterSpacing",
|
|
71
|
+
"textTransform",
|
|
72
|
+
"textDecoration",
|
|
73
|
+
"textAlign",
|
|
74
|
+
"verticalAlign",
|
|
75
|
+
"whiteSpace",
|
|
76
|
+
// Sizing
|
|
77
|
+
"width",
|
|
78
|
+
"minWidth",
|
|
79
|
+
"maxWidth",
|
|
80
|
+
"height",
|
|
81
|
+
"minHeight",
|
|
82
|
+
"maxHeight",
|
|
83
|
+
// Table specifics
|
|
84
|
+
"backgroundClip"
|
|
85
|
+
];
|
|
86
|
+
var toDash = (p) => p.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
87
|
+
function copyComputedStyles(source, target) {
|
|
88
|
+
const cs = getComputedStyle(source);
|
|
89
|
+
for (const p of STYLE_PROPS) {
|
|
90
|
+
const prop = String(p);
|
|
91
|
+
const val = cs.getPropertyValue(toDash(prop));
|
|
92
|
+
if (val) target.style[prop] = val;
|
|
93
|
+
}
|
|
94
|
+
target.style.overflow = "hidden";
|
|
95
|
+
target.style.textOverflow = "ellipsis";
|
|
96
|
+
if (cs.whiteSpace === "" || cs.whiteSpace === "normal") {
|
|
97
|
+
target.style.whiteSpace = "nowrap";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function cloneWithStyles(root) {
|
|
101
|
+
const clone = root.cloneNode(true);
|
|
102
|
+
const q = [{ src: root, dst: clone }];
|
|
103
|
+
while (q.length) {
|
|
104
|
+
const { src, dst } = q.shift();
|
|
105
|
+
if (src instanceof HTMLElement && dst instanceof HTMLElement) {
|
|
106
|
+
copyComputedStyles(src, dst);
|
|
107
|
+
}
|
|
108
|
+
const srcChildren = Array.from(src.children);
|
|
109
|
+
const dstChildren = Array.from(dst.children);
|
|
110
|
+
const len = Math.min(srcChildren.length, dstChildren.length);
|
|
111
|
+
for (let i = 0; i < len; i++) {
|
|
112
|
+
const srcChild = srcChildren[i];
|
|
113
|
+
const dstChild = dstChildren[i];
|
|
114
|
+
if (srcChild && dstChild) {
|
|
115
|
+
q.push({ src: srcChild, dst: dstChild });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return clone;
|
|
120
|
+
}
|
|
121
|
+
function styleDragWrapper(el, maxWidth) {
|
|
122
|
+
Object.assign(el.style, {
|
|
123
|
+
position: "fixed",
|
|
124
|
+
top: "-10000px",
|
|
125
|
+
left: "-10000px",
|
|
126
|
+
pointerEvents: "none",
|
|
127
|
+
zIndex: "2147483647",
|
|
128
|
+
maxWidth: `${maxWidth}px`,
|
|
129
|
+
borderRadius: "12px",
|
|
130
|
+
background: "transparent",
|
|
131
|
+
filter: "drop-shadow(0 8px 24px rgba(0,0,0,0.18)) drop-shadow(0 2px 8px rgba(0,0,0,0.10))",
|
|
132
|
+
overflow: "hidden"
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function scaleToFit(el, maxWidth) {
|
|
136
|
+
if (!el.isConnected) document.body.appendChild(el);
|
|
137
|
+
const rect = el.getBoundingClientRect();
|
|
138
|
+
if (rect.width > maxWidth && rect.width > 0) {
|
|
139
|
+
const scale = maxWidth / rect.width;
|
|
140
|
+
el.style.transformOrigin = "top left";
|
|
141
|
+
el.style.transform = `scale(${scale})`;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function applyTableBoxStyles(srcTable, dstTable) {
|
|
145
|
+
const tcs = getComputedStyle(srcTable);
|
|
146
|
+
dstTable.style.borderCollapse = tcs.borderCollapse;
|
|
147
|
+
dstTable.style.borderSpacing = tcs.borderSpacing;
|
|
148
|
+
dstTable.style.tableLayout = "fixed";
|
|
149
|
+
dstTable.className = srcTable.className;
|
|
150
|
+
}
|
|
151
|
+
function lockCellWidth(fromCell, toCell) {
|
|
152
|
+
const rect = fromCell.getBoundingClientRect();
|
|
153
|
+
if (rect.width > 0) {
|
|
154
|
+
toCell.style.width = `${rect.width}px`;
|
|
155
|
+
toCell.style.maxWidth = `${rect.width}px`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function buildRowPreview(tableEl, rowIndex) {
|
|
159
|
+
var _a, _b, _c;
|
|
160
|
+
const body = (_b = (_a = tableEl.tBodies) == null ? void 0 : _a[0]) != null ? _b : tableEl.querySelector("tbody");
|
|
161
|
+
if (!body) return null;
|
|
162
|
+
const row = (_c = body.rows) == null ? void 0 : _c[rowIndex];
|
|
163
|
+
if (!row) return null;
|
|
164
|
+
const tableClone = document.createElement("table");
|
|
165
|
+
const tbodyClone = document.createElement("tbody");
|
|
166
|
+
const rowClone = cloneWithStyles(row);
|
|
167
|
+
applyTableBoxStyles(tableEl, tableClone);
|
|
168
|
+
for (let i = 0; i < row.cells.length; i++) {
|
|
169
|
+
const src = row.cells[i];
|
|
170
|
+
const dst = rowClone.cells[i];
|
|
171
|
+
if (dst) lockCellWidth(src, dst);
|
|
172
|
+
}
|
|
173
|
+
tbodyClone.appendChild(rowClone);
|
|
174
|
+
tableClone.appendChild(tbodyClone);
|
|
175
|
+
return tableClone;
|
|
176
|
+
}
|
|
177
|
+
function buildColumnPreview(tableEl, colIndex) {
|
|
178
|
+
var _a, _b, _c;
|
|
179
|
+
const body = (_b = (_a = tableEl.tBodies) == null ? void 0 : _a[0]) != null ? _b : tableEl.querySelector("tbody");
|
|
180
|
+
if (!body) return null;
|
|
181
|
+
const tableClone = document.createElement("table");
|
|
182
|
+
const tbodyClone = document.createElement("tbody");
|
|
183
|
+
applyTableBoxStyles(tableEl, tableClone);
|
|
184
|
+
let firstCellWidth = 0;
|
|
185
|
+
for (let r = 0; r < body.rows.length; r++) {
|
|
186
|
+
const srcRow = body.rows[r];
|
|
187
|
+
if (!srcRow) continue;
|
|
188
|
+
const srcCell = (_c = srcRow.cells) == null ? void 0 : _c[colIndex];
|
|
189
|
+
if (!srcCell) continue;
|
|
190
|
+
const tr = document.createElement("tr");
|
|
191
|
+
const cellClone = cloneWithStyles(srcCell);
|
|
192
|
+
const rect = srcCell.getBoundingClientRect();
|
|
193
|
+
if (!firstCellWidth && rect.width > 0) firstCellWidth = rect.width;
|
|
194
|
+
lockCellWidth(srcCell, cellClone);
|
|
195
|
+
tr.appendChild(cellClone);
|
|
196
|
+
tbodyClone.appendChild(tr);
|
|
197
|
+
}
|
|
198
|
+
if (firstCellWidth > 0) {
|
|
199
|
+
tableClone.style.width = `${firstCellWidth}px`;
|
|
200
|
+
tableClone.style.maxWidth = `${firstCellWidth}px`;
|
|
201
|
+
}
|
|
202
|
+
tableClone.appendChild(tbodyClone);
|
|
203
|
+
return tableClone;
|
|
204
|
+
}
|
|
205
|
+
function createTableDragImage(editor, orientation, index, tablePos) {
|
|
206
|
+
const editorRect = editor.view.dom.getBoundingClientRect();
|
|
207
|
+
const maxWidth = Math.max(0, editorRect.width);
|
|
208
|
+
const wrapper = document.createElement("div");
|
|
209
|
+
styleDragWrapper(wrapper, maxWidth);
|
|
210
|
+
const tableEl = editor.view.nodeDOM(tablePos);
|
|
211
|
+
if (!tableEl) {
|
|
212
|
+
document.body.appendChild(wrapper);
|
|
213
|
+
return wrapper;
|
|
214
|
+
}
|
|
215
|
+
const tableRect = tableEl.getBoundingClientRect();
|
|
216
|
+
const dragWidth = Math.min(tableRect.width, editorRect.width);
|
|
217
|
+
wrapper.style.width = `${dragWidth}px`;
|
|
218
|
+
const preview = orientation === "row" ? buildRowPreview(tableEl, index) : buildColumnPreview(tableEl, index);
|
|
219
|
+
if (preview) {
|
|
220
|
+
const card = document.createElement("div");
|
|
221
|
+
Object.assign(card.style, {
|
|
222
|
+
background: "var(--drag-image-bg, transparent)",
|
|
223
|
+
overflow: "hidden"
|
|
224
|
+
});
|
|
225
|
+
card.appendChild(preview);
|
|
226
|
+
wrapper.appendChild(card);
|
|
227
|
+
}
|
|
228
|
+
scaleToFit(wrapper, maxWidth);
|
|
229
|
+
return wrapper;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/lib/table-utils.ts
|
|
233
|
+
var import_shared_utils = require("@kopexa/shared-utils");
|
|
234
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
235
|
+
var EMPTY_CELLS_RESULT = { cells: [], mergedCells: [] };
|
|
236
|
+
function domCellAround(target) {
|
|
237
|
+
let current = target;
|
|
238
|
+
while (current && current.tagName !== "TD" && current.tagName !== "TH" && !current.classList.contains("tableWrapper")) {
|
|
239
|
+
if (current.classList.contains("ProseMirror")) return void 0;
|
|
240
|
+
current = (0, import_shared_utils.isHTMLElement)(current.parentNode) ? current.parentNode : null;
|
|
241
|
+
}
|
|
242
|
+
if (!current) return void 0;
|
|
243
|
+
if (current.tagName === "TD" || current.tagName === "TH") {
|
|
244
|
+
return {
|
|
245
|
+
type: "cell",
|
|
246
|
+
domNode: current,
|
|
247
|
+
tbodyNode: (0, import_shared_utils.safeClosest)(current, "tbody")
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
type: "wrapper",
|
|
252
|
+
domNode: current,
|
|
253
|
+
tbodyNode: current.querySelector("tbody")
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function getCellIndicesFromDOM(cell, tableNode, editor) {
|
|
257
|
+
if (!tableNode) return null;
|
|
258
|
+
try {
|
|
259
|
+
const cellPos = editor.view.posAtDOM(cell, 0);
|
|
260
|
+
const $cellPos = editor.view.state.doc.resolve(cellPos);
|
|
261
|
+
for (let d = $cellPos.depth; d > 0; d--) {
|
|
262
|
+
const node = $cellPos.node(d);
|
|
263
|
+
if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
|
|
264
|
+
const tableMap = import_tables.TableMap.get(tableNode);
|
|
265
|
+
const cellNodePos = $cellPos.before(d);
|
|
266
|
+
const tableStart = $cellPos.start(d - 2);
|
|
267
|
+
const cellOffset = cellNodePos - tableStart;
|
|
268
|
+
const cellIndex = tableMap.map.indexOf(cellOffset);
|
|
269
|
+
return {
|
|
270
|
+
rowIndex: Math.floor(cellIndex / tableMap.width),
|
|
271
|
+
colIndex: cellIndex % tableMap.width
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.warn("Could not get cell position:", error);
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
function collectCells(editor, orientation, index, tablePos) {
|
|
281
|
+
if (!editor) return EMPTY_CELLS_RESULT;
|
|
282
|
+
const { state } = editor;
|
|
283
|
+
const table = getTable(editor, tablePos);
|
|
284
|
+
if (!table) return EMPTY_CELLS_RESULT;
|
|
285
|
+
const tableStart = table.start;
|
|
286
|
+
const tableNode = table.node;
|
|
287
|
+
const map = table.map;
|
|
288
|
+
const resolvedIndex = resolveOrientationIndex(
|
|
289
|
+
state,
|
|
290
|
+
table,
|
|
291
|
+
orientation,
|
|
292
|
+
index
|
|
293
|
+
);
|
|
294
|
+
if (resolvedIndex === null) return EMPTY_CELLS_RESULT;
|
|
295
|
+
const maxIndex = orientation === "row" ? map.height : map.width;
|
|
296
|
+
if (resolvedIndex < 0 || resolvedIndex >= maxIndex) {
|
|
297
|
+
return EMPTY_CELLS_RESULT;
|
|
298
|
+
}
|
|
299
|
+
const cells = [];
|
|
300
|
+
const mergedCells = [];
|
|
301
|
+
const seenMerged = /* @__PURE__ */ new Set();
|
|
302
|
+
const iterationCount = orientation === "row" ? map.width : map.height;
|
|
303
|
+
for (let i = 0; i < iterationCount; i++) {
|
|
304
|
+
const row = orientation === "row" ? resolvedIndex : i;
|
|
305
|
+
const col = orientation === "row" ? i : resolvedIndex;
|
|
306
|
+
const cellIndex = row * map.width + col;
|
|
307
|
+
const mapCell = map.map[cellIndex];
|
|
308
|
+
if (mapCell === void 0) continue;
|
|
309
|
+
const cellPos = tableStart + mapCell;
|
|
310
|
+
const cellNode = tableNode.nodeAt(mapCell);
|
|
311
|
+
if (!cellNode) continue;
|
|
312
|
+
const cell = createCellInfo(row, col, cellPos, cellNode);
|
|
313
|
+
if (isCellMerged(cellNode)) {
|
|
314
|
+
if (!seenMerged.has(cellPos)) {
|
|
315
|
+
mergedCells.push(cell);
|
|
316
|
+
seenMerged.add(cellPos);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
cells.push(cell);
|
|
320
|
+
}
|
|
321
|
+
return { cells, mergedCells };
|
|
322
|
+
}
|
|
323
|
+
function isCellMerged(node) {
|
|
324
|
+
var _a, _b;
|
|
325
|
+
if (!node) return false;
|
|
326
|
+
const colspan = (_a = node.attrs.colspan) != null ? _a : 1;
|
|
327
|
+
const rowspan = (_b = node.attrs.rowspan) != null ? _b : 1;
|
|
328
|
+
return colspan > 1 || rowspan > 1;
|
|
329
|
+
}
|
|
330
|
+
function getColumnCells(editor, columnIndex, tablePos) {
|
|
331
|
+
return collectCells(editor, "column", columnIndex, tablePos);
|
|
332
|
+
}
|
|
333
|
+
function getTable(editor, tablePos) {
|
|
334
|
+
if (!editor) return null;
|
|
335
|
+
let table = null;
|
|
336
|
+
if (typeof tablePos === "number") {
|
|
337
|
+
const tableNode = editor.state.doc.nodeAt(tablePos);
|
|
338
|
+
if ((tableNode == null ? void 0 : tableNode.type.name) === "table") {
|
|
339
|
+
table = {
|
|
340
|
+
node: tableNode,
|
|
341
|
+
pos: tablePos,
|
|
342
|
+
start: tablePos + 1,
|
|
343
|
+
depth: editor.state.doc.resolve(tablePos).depth
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (!table) {
|
|
348
|
+
const { state } = editor;
|
|
349
|
+
const $from = state.doc.resolve(state.selection.from);
|
|
350
|
+
table = (0, import_tables.findTable)($from);
|
|
351
|
+
}
|
|
352
|
+
if (!table) return null;
|
|
353
|
+
const tableMap = import_tables.TableMap.get(table.node);
|
|
354
|
+
if (!tableMap) return null;
|
|
355
|
+
return { ...table, map: tableMap };
|
|
356
|
+
}
|
|
357
|
+
function createCellInfo(row, column, cellPos, cellNode) {
|
|
358
|
+
return {
|
|
359
|
+
row,
|
|
360
|
+
column,
|
|
361
|
+
pos: cellPos,
|
|
362
|
+
node: cellNode,
|
|
363
|
+
start: cellPos + 1,
|
|
364
|
+
depth: cellNode ? cellNode.content.size : 0
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function resolveOrientationIndex(state, table, orientation, providedIndex) {
|
|
368
|
+
var _a;
|
|
369
|
+
if (typeof providedIndex === "number") {
|
|
370
|
+
return providedIndex;
|
|
371
|
+
}
|
|
372
|
+
if (state.selection instanceof import_tables.CellSelection) {
|
|
373
|
+
const rect2 = (0, import_tables.selectedRect)(state);
|
|
374
|
+
return orientation === "row" ? rect2.top : rect2.left;
|
|
375
|
+
}
|
|
376
|
+
const $cell = (_a = (0, import_tables.cellAround)(state.selection.$anchor)) != null ? _a : (0, import_tables.selectionCell)(state);
|
|
377
|
+
if (!$cell) return null;
|
|
378
|
+
const rel = $cell.pos - table.start;
|
|
379
|
+
const rect = table.map.findCell(rel);
|
|
380
|
+
return orientation === "row" ? rect.top : rect.left;
|
|
381
|
+
}
|
|
382
|
+
function getIndexCoordinates({
|
|
383
|
+
editor,
|
|
384
|
+
index,
|
|
385
|
+
orientation,
|
|
386
|
+
tablePos
|
|
387
|
+
}) {
|
|
388
|
+
if (!editor) return null;
|
|
389
|
+
const table = getTable(editor, tablePos);
|
|
390
|
+
if (!table) return null;
|
|
391
|
+
const { map } = table;
|
|
392
|
+
const { width, height } = map;
|
|
393
|
+
if (index < 0) return null;
|
|
394
|
+
if (orientation === "row" && index >= height) return null;
|
|
395
|
+
if (orientation === "column" && index >= width) return null;
|
|
396
|
+
return orientation === "row" ? Array.from({ length: map.width }, (_, col) => ({ row: index, col })) : Array.from({ length: map.height }, (_, row) => ({ row, col: index }));
|
|
397
|
+
}
|
|
398
|
+
function getRowCells(editor, rowIndex, tablePos) {
|
|
399
|
+
return collectCells(editor, "row", rowIndex, tablePos);
|
|
400
|
+
}
|
|
401
|
+
function getTableFromDOM(tableElement, editor) {
|
|
402
|
+
try {
|
|
403
|
+
const pos = editor.view.posAtDOM(tableElement, 0);
|
|
404
|
+
const $pos = editor.view.state.doc.resolve(pos);
|
|
405
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
406
|
+
const node = $pos.node(d);
|
|
407
|
+
if (isTableNode(node)) {
|
|
408
|
+
return { node, pos: d === 0 ? 0 : $pos.before(d) };
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
} catch (error) {
|
|
412
|
+
console.warn("Could not get table from DOM:", error);
|
|
413
|
+
}
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
function isTableNode(node) {
|
|
417
|
+
return !!node && (node.type.name === "table" || node.type.spec.tableRole === "table");
|
|
418
|
+
}
|
|
419
|
+
function selectCellsByCoords(editor, tablePos, coords, options = { mode: "state" }) {
|
|
420
|
+
if (!editor) return;
|
|
421
|
+
const table = getTable(editor, tablePos);
|
|
422
|
+
if (!table) return;
|
|
423
|
+
const { state } = editor;
|
|
424
|
+
const tableMap = table.map;
|
|
425
|
+
const cleanedCoords = coords.map((coord) => ({
|
|
426
|
+
row: (0, import_shared_utils.clamp)(coord.row, 0, tableMap.height - 1),
|
|
427
|
+
col: (0, import_shared_utils.clamp)(coord.col, 0, tableMap.width - 1)
|
|
428
|
+
})).filter((coord) => isWithinBounds(coord.row, coord.col, tableMap));
|
|
429
|
+
if (cleanedCoords.length === 0) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const allRows = cleanedCoords.map((coord) => coord.row);
|
|
433
|
+
const topRow = Math.min(...allRows);
|
|
434
|
+
const bottomRow = Math.max(...allRows);
|
|
435
|
+
const allCols = cleanedCoords.map((coord) => coord.col);
|
|
436
|
+
const leftCol = Math.min(...allCols);
|
|
437
|
+
const rightCol = Math.max(...allCols);
|
|
438
|
+
const getCellPositionFromMap = (row, col) => {
|
|
439
|
+
const cellOffset = tableMap.map[row * tableMap.width + col];
|
|
440
|
+
if (cellOffset === void 0) return null;
|
|
441
|
+
return tablePos + 1 + cellOffset;
|
|
442
|
+
};
|
|
443
|
+
const anchorPosition = getCellPositionFromMap(topRow, leftCol);
|
|
444
|
+
if (anchorPosition === null) return;
|
|
445
|
+
let headPosition = getCellPositionFromMap(bottomRow, rightCol);
|
|
446
|
+
if (headPosition === null) return;
|
|
447
|
+
if (headPosition === anchorPosition) {
|
|
448
|
+
let foundDifferentCell = false;
|
|
449
|
+
for (let row = bottomRow; row >= topRow && !foundDifferentCell; row--) {
|
|
450
|
+
for (let col = rightCol; col >= leftCol && !foundDifferentCell; col--) {
|
|
451
|
+
const candidatePosition = getCellPositionFromMap(row, col);
|
|
452
|
+
if (candidatePosition !== null && candidatePosition !== anchorPosition) {
|
|
453
|
+
headPosition = candidatePosition;
|
|
454
|
+
foundDifferentCell = true;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
const anchorRef = state.doc.resolve(anchorPosition);
|
|
461
|
+
const headRef = state.doc.resolve(headPosition);
|
|
462
|
+
const cellSelection = new import_tables.CellSelection(anchorRef, headRef);
|
|
463
|
+
const transaction = state.tr.setSelection(cellSelection);
|
|
464
|
+
return applySelectionWithMode(state, transaction, options);
|
|
465
|
+
} catch (error) {
|
|
466
|
+
console.error("Failed to create cell selection:", error);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function isWithinBounds(row, col, map) {
|
|
471
|
+
return row >= 0 && row < map.height && col >= 0 && col < map.width;
|
|
472
|
+
}
|
|
473
|
+
function applySelectionWithMode(state, transaction, options) {
|
|
474
|
+
var _a;
|
|
475
|
+
const mode = (_a = options.mode) != null ? _a : "state";
|
|
476
|
+
switch (mode) {
|
|
477
|
+
case "dispatch": {
|
|
478
|
+
const dispatchOptions = options;
|
|
479
|
+
if (typeof dispatchOptions.dispatch === "function") {
|
|
480
|
+
dispatchOptions.dispatch(transaction);
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
case "transaction":
|
|
485
|
+
return transaction;
|
|
486
|
+
default:
|
|
487
|
+
return state.apply(transaction);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// src/extensions/table-handle-plugin.ts
|
|
492
|
+
function hideElements(selector, rootEl) {
|
|
493
|
+
rootEl.querySelectorAll(selector).forEach((el) => {
|
|
494
|
+
el.style.visibility = "hidden";
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
var tableHandlePluginKey = new import_state.PluginKey("tableHandlePlugin");
|
|
498
|
+
var viewRegistry = /* @__PURE__ */ new WeakMap();
|
|
499
|
+
var TableHandleView = class {
|
|
500
|
+
constructor(editor, editorView, emitUpdate) {
|
|
501
|
+
__publicField(this, "editor");
|
|
502
|
+
__publicField(this, "editorView");
|
|
503
|
+
__publicField(this, "state");
|
|
504
|
+
__publicField(this, "menuFrozen", false);
|
|
505
|
+
__publicField(this, "mouseState", "up");
|
|
506
|
+
__publicField(this, "tableId");
|
|
507
|
+
__publicField(this, "tablePos");
|
|
508
|
+
__publicField(this, "tableElement");
|
|
509
|
+
__publicField(this, "hideTimeout", null);
|
|
510
|
+
__publicField(this, "emitUpdate");
|
|
511
|
+
__publicField(this, "viewMousedownHandler", (event) => {
|
|
512
|
+
this.mouseState = "down";
|
|
513
|
+
const { state, view } = this.editor;
|
|
514
|
+
if (!(state.selection instanceof import_tables2.CellSelection) || this.editor.isFocused)
|
|
515
|
+
return;
|
|
516
|
+
const posInfo = view.posAtCoords({
|
|
517
|
+
left: event.clientX,
|
|
518
|
+
top: event.clientY
|
|
519
|
+
});
|
|
520
|
+
if (!posInfo) return;
|
|
521
|
+
const $pos = state.doc.resolve(posInfo.pos);
|
|
522
|
+
const { nodes } = state.schema;
|
|
523
|
+
let paraDepth = -1;
|
|
524
|
+
let inTableCell = false;
|
|
525
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
526
|
+
const node = $pos.node(d);
|
|
527
|
+
if (!inTableCell && (node.type === nodes.tableCell || node.type === nodes.tableHeader)) {
|
|
528
|
+
inTableCell = true;
|
|
529
|
+
}
|
|
530
|
+
if (paraDepth === -1 && node.type === nodes.paragraph) {
|
|
531
|
+
paraDepth = d;
|
|
532
|
+
}
|
|
533
|
+
if (inTableCell && paraDepth !== -1) break;
|
|
534
|
+
}
|
|
535
|
+
if (!inTableCell || paraDepth === -1) return;
|
|
536
|
+
const from = $pos.start(paraDepth);
|
|
537
|
+
const to = $pos.end(paraDepth);
|
|
538
|
+
const nextSel = import_state.TextSelection.create(state.doc, from, to);
|
|
539
|
+
if (state.selection.eq(nextSel)) return;
|
|
540
|
+
view.dispatch(state.tr.setSelection(nextSel));
|
|
541
|
+
view.focus();
|
|
542
|
+
});
|
|
543
|
+
__publicField(this, "mouseUpHandler", (event) => {
|
|
544
|
+
this.mouseState = "up";
|
|
545
|
+
this.mouseMoveHandler(event);
|
|
546
|
+
});
|
|
547
|
+
__publicField(this, "mouseMoveHandler", (event) => {
|
|
548
|
+
if (this.menuFrozen || this.mouseState === "selecting") return;
|
|
549
|
+
const target = event.target;
|
|
550
|
+
if (!(0, import_shared_utils2.isHTMLElement)(target) || !this.editorView.dom.contains(target)) return;
|
|
551
|
+
this._handleMouseMoveNow(event);
|
|
552
|
+
});
|
|
553
|
+
__publicField(this, "dragOverHandler", (event) => {
|
|
554
|
+
var _a;
|
|
555
|
+
if (((_a = this.state) == null ? void 0 : _a.draggingState) === void 0) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
event.preventDefault();
|
|
559
|
+
event.dataTransfer.dropEffect = "move";
|
|
560
|
+
hideElements(
|
|
561
|
+
".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",
|
|
562
|
+
this.editorView.root
|
|
563
|
+
);
|
|
564
|
+
const {
|
|
565
|
+
left: tableLeft,
|
|
566
|
+
right: tableRight,
|
|
567
|
+
top: tableTop,
|
|
568
|
+
bottom: tableBottom
|
|
569
|
+
} = this.state.referencePosTable;
|
|
570
|
+
const boundedMouseCoords = {
|
|
571
|
+
left: (0, import_shared_utils2.clamp)(event.clientX, tableLeft + 1, tableRight - 1),
|
|
572
|
+
top: (0, import_shared_utils2.clamp)(event.clientY, tableTop + 1, tableBottom - 1)
|
|
573
|
+
};
|
|
574
|
+
const tableCellElements = this.editorView.root.elementsFromPoint(boundedMouseCoords.left, boundedMouseCoords.top).filter(
|
|
575
|
+
(element) => element.tagName === "TD" || element.tagName === "TH"
|
|
576
|
+
);
|
|
577
|
+
if (tableCellElements.length === 0) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const tableCellElement = tableCellElements[0];
|
|
581
|
+
if (!(0, import_shared_utils2.isHTMLElement)(tableCellElement)) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const cellPosition = getCellIndicesFromDOM(
|
|
585
|
+
tableCellElement,
|
|
586
|
+
this.state.block,
|
|
587
|
+
this.editor
|
|
588
|
+
);
|
|
589
|
+
if (!cellPosition) return;
|
|
590
|
+
const { rowIndex, colIndex } = cellPosition;
|
|
591
|
+
const oldIndex = this.state.draggingState.draggedCellOrientation === "row" ? this.state.rowIndex : this.state.colIndex;
|
|
592
|
+
const newIndex = this.state.draggingState.draggedCellOrientation === "row" ? rowIndex : colIndex;
|
|
593
|
+
const dispatchDecorationsTransaction = newIndex !== oldIndex;
|
|
594
|
+
const mousePos = this.state.draggingState.draggedCellOrientation === "row" ? boundedMouseCoords.top : boundedMouseCoords.left;
|
|
595
|
+
const cellChanged = this.state.rowIndex !== rowIndex || this.state.colIndex !== colIndex;
|
|
596
|
+
const mousePosChanged = this.state.draggingState.mousePos !== mousePos;
|
|
597
|
+
if (cellChanged || mousePosChanged) {
|
|
598
|
+
this.state = {
|
|
599
|
+
...this.state,
|
|
600
|
+
rowIndex,
|
|
601
|
+
colIndex,
|
|
602
|
+
referencePosCell: tableCellElement.getBoundingClientRect(),
|
|
603
|
+
draggingState: {
|
|
604
|
+
...this.state.draggingState,
|
|
605
|
+
mousePos
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
this.emitUpdate();
|
|
609
|
+
}
|
|
610
|
+
if (dispatchDecorationsTransaction) {
|
|
611
|
+
this.editor.view.dispatch(
|
|
612
|
+
this.editor.state.tr.setMeta(tableHandlePluginKey, true)
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
__publicField(this, "dropHandler", () => {
|
|
617
|
+
this.mouseState = "up";
|
|
618
|
+
const st = this.state;
|
|
619
|
+
if (!(st == null ? void 0 : st.draggingState)) return false;
|
|
620
|
+
const { draggingState, rowIndex, colIndex, blockPos } = st;
|
|
621
|
+
if (!(0, import_editor_utils.isValidPosition)(blockPos)) return false;
|
|
622
|
+
if (draggingState.draggedCellOrientation === "row" && rowIndex === void 0 || draggingState.draggedCellOrientation === "col" && colIndex === void 0) {
|
|
623
|
+
console.warn(
|
|
624
|
+
"Attempted to drop table row or column, but no table block was hovered prior."
|
|
625
|
+
);
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
const isRow = draggingState.draggedCellOrientation === "row";
|
|
629
|
+
const orientation = isRow ? "row" : "column";
|
|
630
|
+
const destIndex = isRow ? rowIndex : colIndex;
|
|
631
|
+
const cellCoords = getIndexCoordinates({
|
|
632
|
+
editor: this.editor,
|
|
633
|
+
index: draggingState.originalIndex,
|
|
634
|
+
orientation,
|
|
635
|
+
tablePos: blockPos
|
|
636
|
+
});
|
|
637
|
+
if (!cellCoords) return false;
|
|
638
|
+
const stateWithCellSel = selectCellsByCoords(
|
|
639
|
+
this.editor,
|
|
640
|
+
blockPos,
|
|
641
|
+
cellCoords,
|
|
642
|
+
{ mode: "state" }
|
|
643
|
+
);
|
|
644
|
+
if (!stateWithCellSel) return false;
|
|
645
|
+
const dispatch = (tr) => this.editor.view.dispatch(tr);
|
|
646
|
+
if (isRow) {
|
|
647
|
+
(0, import_tables2.moveTableRow)({
|
|
648
|
+
from: draggingState.originalIndex,
|
|
649
|
+
to: destIndex,
|
|
650
|
+
select: true,
|
|
651
|
+
pos: blockPos + 1
|
|
652
|
+
})(stateWithCellSel, dispatch);
|
|
653
|
+
} else {
|
|
654
|
+
(0, import_tables2.moveTableColumn)({
|
|
655
|
+
from: draggingState.originalIndex,
|
|
656
|
+
to: destIndex,
|
|
657
|
+
select: true,
|
|
658
|
+
pos: blockPos + 1
|
|
659
|
+
})(stateWithCellSel, dispatch);
|
|
660
|
+
}
|
|
661
|
+
this.state = { ...st, draggingState: void 0 };
|
|
662
|
+
this.emitUpdate();
|
|
663
|
+
this.editor.view.dispatch(
|
|
664
|
+
this.editor.state.tr.setMeta(tableHandlePluginKey, null)
|
|
665
|
+
);
|
|
666
|
+
return true;
|
|
667
|
+
});
|
|
668
|
+
this.editor = editor;
|
|
669
|
+
this.editorView = editorView;
|
|
670
|
+
this.emitUpdate = () => this.state && emitUpdate(this.state);
|
|
671
|
+
viewRegistry.set(editor, this);
|
|
672
|
+
this.editorView.dom.addEventListener("mousemove", this.mouseMoveHandler);
|
|
673
|
+
this.editorView.dom.addEventListener(
|
|
674
|
+
"mousedown",
|
|
675
|
+
this.viewMousedownHandler
|
|
676
|
+
);
|
|
677
|
+
window.addEventListener("mouseup", this.mouseUpHandler);
|
|
678
|
+
this.editorView.root.addEventListener(
|
|
679
|
+
"dragover",
|
|
680
|
+
this.dragOverHandler
|
|
681
|
+
);
|
|
682
|
+
this.editorView.root.addEventListener(
|
|
683
|
+
"drop",
|
|
684
|
+
this.dropHandler
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Schedule a delayed hide of handles. This allows the user to cross
|
|
689
|
+
* gaps between table cells and floating handles without the handles
|
|
690
|
+
* disappearing prematurely.
|
|
691
|
+
*/
|
|
692
|
+
scheduleHide() {
|
|
693
|
+
if (this.hideTimeout) return;
|
|
694
|
+
this.hideTimeout = setTimeout(() => {
|
|
695
|
+
this.hideTimeout = null;
|
|
696
|
+
if (!this.menuFrozen) {
|
|
697
|
+
this.hideHandles();
|
|
698
|
+
}
|
|
699
|
+
}, 200);
|
|
700
|
+
}
|
|
701
|
+
cancelScheduledHide() {
|
|
702
|
+
if (this.hideTimeout) {
|
|
703
|
+
clearTimeout(this.hideTimeout);
|
|
704
|
+
this.hideTimeout = null;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
hideHandles() {
|
|
708
|
+
var _a;
|
|
709
|
+
this.cancelScheduledHide();
|
|
710
|
+
if (!((_a = this.state) == null ? void 0 : _a.show)) return;
|
|
711
|
+
this.state = {
|
|
712
|
+
...this.state,
|
|
713
|
+
show: false,
|
|
714
|
+
showAddOrRemoveRowsButton: false,
|
|
715
|
+
showAddOrRemoveColumnsButton: false,
|
|
716
|
+
colIndex: void 0,
|
|
717
|
+
rowIndex: void 0,
|
|
718
|
+
referencePosCell: void 0
|
|
719
|
+
};
|
|
720
|
+
this.emitUpdate();
|
|
721
|
+
}
|
|
722
|
+
_handleMouseMoveNow(event) {
|
|
723
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
724
|
+
const around = domCellAround(event.target);
|
|
725
|
+
if ((around == null ? void 0 : around.type) === "cell" && this.mouseState === "down" && !((_a = this.state) == null ? void 0 : _a.draggingState)) {
|
|
726
|
+
this.mouseState = "selecting";
|
|
727
|
+
this.cancelScheduledHide();
|
|
728
|
+
this.hideHandles();
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
if (!around || !this.editor.isEditable) {
|
|
732
|
+
this.scheduleHide();
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
this.cancelScheduledHide();
|
|
736
|
+
const tbody = around.tbodyNode;
|
|
737
|
+
if (!tbody) return;
|
|
738
|
+
let tableRect = tbody.getBoundingClientRect();
|
|
739
|
+
if (tableRect.width === 0 && tableRect.height === 0) {
|
|
740
|
+
const fallback = (_b = tbody.closest(".table-container")) != null ? _b : tbody.closest(".tableWrapper");
|
|
741
|
+
if (!fallback) return;
|
|
742
|
+
tableRect = fallback.getBoundingClientRect();
|
|
743
|
+
}
|
|
744
|
+
const coords = this.editor.view.posAtCoords({
|
|
745
|
+
left: event.clientX,
|
|
746
|
+
top: event.clientY
|
|
747
|
+
});
|
|
748
|
+
if (!coords) return;
|
|
749
|
+
const $pos = this.editor.view.state.doc.resolve(coords.pos);
|
|
750
|
+
let blockInfo;
|
|
751
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
752
|
+
const node = $pos.node(d);
|
|
753
|
+
if (isTableNode(node)) {
|
|
754
|
+
blockInfo = { node, pos: d === 0 ? 0 : $pos.before(d) };
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (!blockInfo || blockInfo.node.type.name !== "table") return;
|
|
759
|
+
this.tableElement = this.editor.view.nodeDOM(blockInfo.pos);
|
|
760
|
+
this.tablePos = blockInfo.pos;
|
|
761
|
+
this.tableId = blockInfo.node.attrs.id;
|
|
762
|
+
const widgetContainer = (_c = this.tableElement) == null ? void 0 : _c.querySelector(
|
|
763
|
+
".table-controls"
|
|
764
|
+
);
|
|
765
|
+
if (around.type === "wrapper") {
|
|
766
|
+
const below = event.clientY >= tableRect.bottom - 1 && event.clientY < tableRect.bottom + 20;
|
|
767
|
+
const right = event.clientX >= tableRect.right - 1 && event.clientX < tableRect.right + 20;
|
|
768
|
+
const cursorBeyondRightOrBottom = event.clientX > tableRect.right || event.clientY > tableRect.bottom;
|
|
769
|
+
this.state = {
|
|
770
|
+
...this.state,
|
|
771
|
+
show: true,
|
|
772
|
+
showAddOrRemoveRowsButton: below,
|
|
773
|
+
showAddOrRemoveColumnsButton: right,
|
|
774
|
+
referencePosTable: tableRect,
|
|
775
|
+
block: blockInfo.node,
|
|
776
|
+
blockPos: blockInfo.pos,
|
|
777
|
+
widgetContainer,
|
|
778
|
+
colIndex: cursorBeyondRightOrBottom ? void 0 : (_d = this.state) == null ? void 0 : _d.colIndex,
|
|
779
|
+
rowIndex: cursorBeyondRightOrBottom ? void 0 : (_e = this.state) == null ? void 0 : _e.rowIndex,
|
|
780
|
+
referencePosCell: cursorBeyondRightOrBottom ? void 0 : (_f = this.state) == null ? void 0 : _f.referencePosCell
|
|
781
|
+
};
|
|
782
|
+
} else {
|
|
783
|
+
const cellPosition = getCellIndicesFromDOM(
|
|
784
|
+
around.domNode,
|
|
785
|
+
blockInfo.node,
|
|
786
|
+
this.editor
|
|
787
|
+
);
|
|
788
|
+
if (!cellPosition) return;
|
|
789
|
+
const { rowIndex, colIndex } = cellPosition;
|
|
790
|
+
const cellRect = around.domNode.getBoundingClientRect();
|
|
791
|
+
const lastRowIndex = blockInfo.node.content.childCount - 1;
|
|
792
|
+
const lastColIndex = ((_h = (_g = blockInfo.node.content.firstChild) == null ? void 0 : _g.content.childCount) != null ? _h : 0) - 1;
|
|
793
|
+
if (((_i = this.state) == null ? void 0 : _i.show) && this.tableId === blockInfo.node.attrs.id && this.state.rowIndex === rowIndex && this.state.colIndex === colIndex) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
this.state = {
|
|
797
|
+
show: true,
|
|
798
|
+
showAddOrRemoveColumnsButton: colIndex === lastColIndex,
|
|
799
|
+
showAddOrRemoveRowsButton: rowIndex === lastRowIndex,
|
|
800
|
+
referencePosTable: tableRect,
|
|
801
|
+
block: blockInfo.node,
|
|
802
|
+
blockPos: blockInfo.pos,
|
|
803
|
+
draggingState: void 0,
|
|
804
|
+
referencePosCell: cellRect,
|
|
805
|
+
colIndex,
|
|
806
|
+
rowIndex,
|
|
807
|
+
widgetContainer
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
this.emitUpdate();
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
update(view) {
|
|
814
|
+
var _a, _b, _c, _d;
|
|
815
|
+
const pluginState = tableHandlePluginKey.getState(view.state);
|
|
816
|
+
if (pluginState !== void 0 && pluginState !== this.menuFrozen) {
|
|
817
|
+
this.menuFrozen = pluginState;
|
|
818
|
+
if (this.menuFrozen) {
|
|
819
|
+
this.cancelScheduledHide();
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (!((_a = this.state) == null ? void 0 : _a.show)) return;
|
|
823
|
+
if (!((_b = this.tableElement) == null ? void 0 : _b.isConnected)) {
|
|
824
|
+
this.hideHandles();
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
const tableInfo = getTableFromDOM(this.tableElement, this.editor);
|
|
828
|
+
if (!tableInfo) {
|
|
829
|
+
this.hideHandles();
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
const blockChanged = this.state.block !== tableInfo.node || this.state.blockPos !== tableInfo.pos;
|
|
833
|
+
if (!tableInfo.node || tableInfo.node.type.name !== "table" || !((_c = this.tableElement) == null ? void 0 : _c.isConnected)) {
|
|
834
|
+
this.hideHandles();
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
const { height: rowCount, width: colCount } = import_tables2.TableMap.get(tableInfo.node);
|
|
838
|
+
let newRowIndex = this.state.rowIndex;
|
|
839
|
+
let newColIndex = this.state.colIndex;
|
|
840
|
+
if (newRowIndex !== void 0 && newRowIndex >= rowCount) {
|
|
841
|
+
newRowIndex = rowCount ? rowCount - 1 : void 0;
|
|
842
|
+
}
|
|
843
|
+
if (newColIndex !== void 0 && newColIndex >= colCount) {
|
|
844
|
+
newColIndex = colCount ? colCount - 1 : void 0;
|
|
845
|
+
}
|
|
846
|
+
const tableBody = this.tableElement.querySelector("tbody");
|
|
847
|
+
if (!tableBody) {
|
|
848
|
+
throw new Error(
|
|
849
|
+
"Table block does not contain a 'tbody' HTML element. This should never happen."
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
let newReferencePosCell = this.state.referencePosCell;
|
|
853
|
+
if (newRowIndex !== void 0 && newColIndex !== void 0) {
|
|
854
|
+
const rowEl = tableBody.children[newRowIndex];
|
|
855
|
+
const cellEl = rowEl == null ? void 0 : rowEl.children[newColIndex];
|
|
856
|
+
if (cellEl) {
|
|
857
|
+
newReferencePosCell = cellEl.getBoundingClientRect();
|
|
858
|
+
} else {
|
|
859
|
+
newRowIndex = void 0;
|
|
860
|
+
newColIndex = void 0;
|
|
861
|
+
newReferencePosCell = void 0;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
let newReferencePosTable = tableBody.getBoundingClientRect();
|
|
865
|
+
if (newReferencePosTable.width === 0 && newReferencePosTable.height === 0) {
|
|
866
|
+
const fallback = (_d = tableBody.closest(".table-container")) != null ? _d : tableBody.closest(".tableWrapper");
|
|
867
|
+
if (fallback) {
|
|
868
|
+
newReferencePosTable = fallback.getBoundingClientRect();
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
const indicesChanged = newRowIndex !== this.state.rowIndex || newColIndex !== this.state.colIndex;
|
|
872
|
+
const refPosChanged = newReferencePosCell !== this.state.referencePosCell || newReferencePosTable !== this.state.referencePosTable;
|
|
873
|
+
if (blockChanged || indicesChanged || refPosChanged) {
|
|
874
|
+
this.state = {
|
|
875
|
+
...this.state,
|
|
876
|
+
block: tableInfo.node,
|
|
877
|
+
blockPos: tableInfo.pos,
|
|
878
|
+
rowIndex: newRowIndex,
|
|
879
|
+
colIndex: newColIndex,
|
|
880
|
+
referencePosCell: newReferencePosCell,
|
|
881
|
+
referencePosTable: newReferencePosTable
|
|
882
|
+
};
|
|
883
|
+
this.emitUpdate();
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
destroy() {
|
|
887
|
+
this.cancelScheduledHide();
|
|
888
|
+
viewRegistry.delete(this.editor);
|
|
889
|
+
this.editorView.dom.removeEventListener(
|
|
890
|
+
"mousemove",
|
|
891
|
+
this.mouseMoveHandler
|
|
892
|
+
);
|
|
893
|
+
window.removeEventListener("mouseup", this.mouseUpHandler);
|
|
894
|
+
this.editorView.dom.removeEventListener(
|
|
895
|
+
"mousedown",
|
|
896
|
+
this.viewMousedownHandler
|
|
897
|
+
);
|
|
898
|
+
this.editorView.root.removeEventListener(
|
|
899
|
+
"dragover",
|
|
900
|
+
this.dragOverHandler
|
|
901
|
+
);
|
|
902
|
+
this.editorView.root.removeEventListener(
|
|
903
|
+
"drop",
|
|
904
|
+
this.dropHandler
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
function TableHandlePlugin(editor, emitUpdate) {
|
|
909
|
+
let viewInstance = null;
|
|
910
|
+
return new import_state.Plugin({
|
|
911
|
+
key: tableHandlePluginKey,
|
|
912
|
+
state: {
|
|
913
|
+
init: () => false,
|
|
914
|
+
apply: (tr, frozen) => {
|
|
915
|
+
const meta = tr.getMeta(tableHandlePluginKey);
|
|
916
|
+
return meta !== void 0 ? meta : frozen;
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
view: (editorView) => {
|
|
920
|
+
viewInstance = new TableHandleView(editor, editorView, emitUpdate);
|
|
921
|
+
return viewInstance;
|
|
922
|
+
},
|
|
923
|
+
props: {
|
|
924
|
+
decorations: (state) => {
|
|
925
|
+
if (!viewInstance || viewInstance.state === void 0 || viewInstance.state.draggingState === void 0 || viewInstance.tablePos === void 0) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
const newIndex = viewInstance.state.draggingState.draggedCellOrientation === "row" ? viewInstance.state.rowIndex : viewInstance.state.colIndex;
|
|
929
|
+
if (newIndex === void 0) {
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const decorations = [];
|
|
933
|
+
const { draggingState } = viewInstance.state;
|
|
934
|
+
const { originalIndex } = draggingState;
|
|
935
|
+
if (viewInstance.state.draggingState.draggedCellOrientation === "row") {
|
|
936
|
+
const originalCells = getRowCells(
|
|
937
|
+
editor,
|
|
938
|
+
originalIndex,
|
|
939
|
+
viewInstance.state.blockPos
|
|
940
|
+
);
|
|
941
|
+
originalCells.cells.forEach((cell) => {
|
|
942
|
+
if (cell.node) {
|
|
943
|
+
decorations.push(
|
|
944
|
+
import_view.Decoration.node(cell.pos, cell.pos + cell.node.nodeSize, {
|
|
945
|
+
class: "table-cell-dragging-source"
|
|
946
|
+
})
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
} else {
|
|
951
|
+
const originalCells = getColumnCells(
|
|
952
|
+
editor,
|
|
953
|
+
originalIndex,
|
|
954
|
+
viewInstance.state.blockPos
|
|
955
|
+
);
|
|
956
|
+
originalCells.cells.forEach((cell) => {
|
|
957
|
+
if (cell.node) {
|
|
958
|
+
decorations.push(
|
|
959
|
+
import_view.Decoration.node(cell.pos, cell.pos + cell.node.nodeSize, {
|
|
960
|
+
class: "table-cell-dragging-source"
|
|
961
|
+
})
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
if (newIndex === originalIndex || !editor) {
|
|
967
|
+
return import_view.DecorationSet.create(state.doc, decorations);
|
|
968
|
+
}
|
|
969
|
+
if (viewInstance.state.draggingState.draggedCellOrientation === "row") {
|
|
970
|
+
const cellsInRow = getRowCells(
|
|
971
|
+
editor,
|
|
972
|
+
newIndex,
|
|
973
|
+
viewInstance.state.blockPos
|
|
974
|
+
);
|
|
975
|
+
cellsInRow.cells.forEach((cell) => {
|
|
976
|
+
const cellNode = cell.node;
|
|
977
|
+
if (!cellNode) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
const decorationPos = cell.pos + (newIndex > originalIndex ? cellNode.nodeSize - 2 : 2);
|
|
981
|
+
decorations.push(
|
|
982
|
+
import_view.Decoration.widget(decorationPos, () => {
|
|
983
|
+
const widget = document.createElement("div");
|
|
984
|
+
widget.className = "tiptap-table-dropcursor";
|
|
985
|
+
widget.style.left = "0";
|
|
986
|
+
widget.style.right = "0";
|
|
987
|
+
if (newIndex > originalIndex) {
|
|
988
|
+
widget.style.bottom = "-1px";
|
|
989
|
+
} else {
|
|
990
|
+
widget.style.top = "-1px";
|
|
991
|
+
}
|
|
992
|
+
widget.style.height = "3px";
|
|
993
|
+
return widget;
|
|
994
|
+
})
|
|
995
|
+
);
|
|
996
|
+
});
|
|
997
|
+
} else {
|
|
998
|
+
const cellsInColumn = getColumnCells(
|
|
999
|
+
editor,
|
|
1000
|
+
newIndex,
|
|
1001
|
+
viewInstance.state.blockPos
|
|
1002
|
+
);
|
|
1003
|
+
cellsInColumn.cells.forEach((cell) => {
|
|
1004
|
+
const cellNode = cell.node;
|
|
1005
|
+
if (!cellNode) {
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
const decorationPos = cell.pos + (newIndex > originalIndex ? cellNode.nodeSize - 2 : 2);
|
|
1009
|
+
decorations.push(
|
|
1010
|
+
import_view.Decoration.widget(decorationPos, () => {
|
|
1011
|
+
const widget = document.createElement("div");
|
|
1012
|
+
widget.className = "tiptap-table-dropcursor";
|
|
1013
|
+
widget.style.top = "0";
|
|
1014
|
+
widget.style.bottom = "0";
|
|
1015
|
+
if (newIndex > originalIndex) {
|
|
1016
|
+
widget.style.right = "-1px";
|
|
1017
|
+
} else {
|
|
1018
|
+
widget.style.left = "-1px";
|
|
1019
|
+
}
|
|
1020
|
+
widget.style.width = "3px";
|
|
1021
|
+
return widget;
|
|
1022
|
+
})
|
|
1023
|
+
);
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
return import_view.DecorationSet.create(state.doc, decorations);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
var tableDragStart = (editor, orientation, event) => {
|
|
1032
|
+
const viewInstance = viewRegistry.get(editor);
|
|
1033
|
+
if (!(viewInstance == null ? void 0 : viewInstance.state)) {
|
|
1034
|
+
console.warn(
|
|
1035
|
+
`Attempted to drag table ${orientation}, but no table block was hovered prior.`
|
|
1036
|
+
);
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
const { state } = viewInstance;
|
|
1040
|
+
const index = orientation === "col" ? state.colIndex : state.rowIndex;
|
|
1041
|
+
if (index === void 0) {
|
|
1042
|
+
console.warn(
|
|
1043
|
+
`Attempted to drag table ${orientation}, but no valid index found.`
|
|
1044
|
+
);
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
const { blockPos, referencePosCell } = state;
|
|
1048
|
+
const mousePos = orientation === "col" ? event.clientX : event.clientY;
|
|
1049
|
+
if (editor.state.selection instanceof import_tables2.CellSelection) {
|
|
1050
|
+
const safeSel = import_state.TextSelection.near(editor.state.doc.resolve(blockPos), 1);
|
|
1051
|
+
editor.view.dispatch(editor.state.tr.setSelection(safeSel));
|
|
1052
|
+
}
|
|
1053
|
+
const dragImage = createTableDragImage(editor, orientation, index, blockPos);
|
|
1054
|
+
if (event.dataTransfer) {
|
|
1055
|
+
const handleRect = event.currentTarget.getBoundingClientRect();
|
|
1056
|
+
const offset = orientation === "col" ? { x: handleRect.width / 2, y: 0 } : { x: 0, y: handleRect.height / 2 };
|
|
1057
|
+
event.dataTransfer.effectAllowed = orientation === "col" ? "move" : "copyMove";
|
|
1058
|
+
event.dataTransfer.setDragImage(dragImage, offset.x, offset.y);
|
|
1059
|
+
}
|
|
1060
|
+
const cleanup = () => {
|
|
1061
|
+
var _a;
|
|
1062
|
+
return (_a = dragImage.parentNode) == null ? void 0 : _a.removeChild(dragImage);
|
|
1063
|
+
};
|
|
1064
|
+
document.addEventListener("drop", cleanup, { once: true });
|
|
1065
|
+
document.addEventListener("dragend", cleanup, { once: true });
|
|
1066
|
+
const initialOffset = referencePosCell ? (orientation === "col" ? referencePosCell.left : referencePosCell.top) - mousePos : 0;
|
|
1067
|
+
viewInstance.state = {
|
|
1068
|
+
...state,
|
|
1069
|
+
draggingState: {
|
|
1070
|
+
draggedCellOrientation: orientation,
|
|
1071
|
+
originalIndex: index,
|
|
1072
|
+
mousePos,
|
|
1073
|
+
initialOffset
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
viewInstance.emitUpdate();
|
|
1077
|
+
editor.view.dispatch(editor.state.tr.setMeta(tableHandlePluginKey, true));
|
|
1078
|
+
};
|
|
1079
|
+
var colDragStart = (editor, event) => tableDragStart(editor, "col", { ...event, clientY: 0 });
|
|
1080
|
+
var rowDragStart = (editor, event) => tableDragStart(editor, "row", { ...event, clientX: 0 });
|
|
1081
|
+
var dragEnd = (editor) => {
|
|
1082
|
+
const viewInstance = viewRegistry.get(editor);
|
|
1083
|
+
if (!viewInstance || viewInstance.state === void 0) {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
viewInstance.state = {
|
|
1087
|
+
...viewInstance.state,
|
|
1088
|
+
draggingState: void 0
|
|
1089
|
+
};
|
|
1090
|
+
viewInstance.emitUpdate();
|
|
1091
|
+
editor.view.dispatch(editor.state.tr.setMeta(tableHandlePluginKey, null));
|
|
1092
|
+
};
|
|
1093
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1094
|
+
0 && (module.exports = {
|
|
1095
|
+
TableHandlePlugin,
|
|
1096
|
+
colDragStart,
|
|
1097
|
+
dragEnd,
|
|
1098
|
+
rowDragStart,
|
|
1099
|
+
tableHandlePluginKey
|
|
1100
|
+
});
|