@kopexa/extension-table 17.0.46 → 17.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2NBDRVYL.mjs +428 -0
- package/dist/chunk-3SWV7BGP.mjs +638 -0
- package/dist/chunk-4QSZXHZO.mjs +276 -0
- package/dist/chunk-5B5XIL2G.mjs +457 -0
- package/dist/chunk-62B2LU2Q.mjs +603 -0
- package/dist/chunk-6FHFDGJO.mjs +251 -0
- package/dist/chunk-CD62W5C3.mjs +165 -0
- package/dist/chunk-CN73TYHV.mjs +190 -0
- package/dist/chunk-CPDSPBS6.mjs +276 -0
- package/dist/chunk-E7W2KRZG.mjs +49 -0
- package/dist/chunk-G6GHC2WO.mjs +276 -0
- package/dist/chunk-GBTQVIN5.mjs +174 -0
- package/dist/chunk-GDEXPEW5.mjs +52 -0
- package/dist/chunk-GQLZBIWF.mjs +198 -0
- package/dist/chunk-IRJ6RAVQ.mjs +116 -0
- package/dist/chunk-J4VOSZCZ.mjs +59 -0
- package/dist/chunk-KIYFW7MP.mjs +122 -0
- package/dist/chunk-KTRZVXJC.mjs +306 -0
- package/dist/chunk-LUA32VH4.mjs +35 -0
- package/dist/{chunk-2L3HZWWG.mjs → chunk-MB52MZQ4.mjs} +7 -8
- package/dist/chunk-PTX5UYV6.mjs +10 -0
- package/dist/chunk-TEGO6KUS.mjs +96 -0
- package/dist/chunk-VIBVRWS4.mjs +197 -0
- package/dist/chunk-VQV757EG.mjs +113 -0
- package/dist/chunk-XRNQXADK.mjs +149 -0
- package/dist/chunk-ZVPJDJBO.mjs +134 -0
- package/dist/{kit.d.mts → extensions/kit.d.mts} +1 -3
- package/dist/{kit.d.ts → extensions/kit.d.ts} +1 -3
- package/dist/extensions/kit.js +1041 -0
- package/dist/extensions/kit.mjs +15 -0
- package/dist/extensions/table-cell.d.mts +6 -0
- package/dist/extensions/table-cell.d.ts +6 -0
- package/dist/extensions/table-cell.js +70 -0
- package/dist/extensions/table-cell.mjs +8 -0
- package/dist/extensions/table-handle-plugin.d.mts +46 -0
- package/dist/extensions/table-handle-plugin.d.ts +46 -0
- package/dist/extensions/table-handle-plugin.js +1100 -0
- package/dist/extensions/table-handle-plugin.mjs +18 -0
- package/dist/extensions/table-handle.d.mts +19 -0
- package/dist/extensions/table-handle.d.ts +19 -0
- package/dist/extensions/table-handle.js +865 -0
- package/dist/extensions/table-handle.mjs +11 -0
- package/dist/{table → extensions}/table.d.mts +2 -2
- package/dist/{table → extensions}/table.d.ts +2 -2
- package/dist/extensions/table.js +138 -0
- package/dist/extensions/table.mjs +9 -0
- package/dist/hooks/use-resize-overlay.d.mts +5 -0
- package/dist/hooks/use-resize-overlay.d.ts +5 -0
- package/dist/hooks/use-resize-overlay.js +83 -0
- package/dist/hooks/use-resize-overlay.mjs +9 -0
- package/dist/hooks/use-table-add-row-column.d.mts +57 -0
- package/dist/hooks/use-table-add-row-column.d.ts +57 -0
- package/dist/hooks/use-table-add-row-column.js +551 -0
- package/dist/hooks/use-table-add-row-column.mjs +11 -0
- package/dist/hooks/use-table-align-cell.d.mts +148 -0
- package/dist/hooks/use-table-align-cell.d.ts +148 -0
- package/dist/hooks/use-table-align-cell.js +655 -0
- package/dist/hooks/use-table-align-cell.mjs +13 -0
- package/dist/hooks/use-table-clear-row-column-content.d.mts +103 -0
- package/dist/hooks/use-table-clear-row-column-content.d.ts +103 -0
- package/dist/hooks/use-table-clear-row-column-content.js +681 -0
- package/dist/hooks/use-table-clear-row-column-content.mjs +11 -0
- package/dist/hooks/use-table-delete-row-column.d.mts +87 -0
- package/dist/hooks/use-table-delete-row-column.d.ts +87 -0
- package/dist/hooks/use-table-delete-row-column.js +459 -0
- package/dist/hooks/use-table-delete-row-column.mjs +11 -0
- package/dist/hooks/use-table-duplicate-row-column.d.mts +49 -0
- package/dist/hooks/use-table-duplicate-row-column.d.ts +49 -0
- package/dist/hooks/use-table-duplicate-row-column.js +758 -0
- package/dist/hooks/use-table-duplicate-row-column.mjs +11 -0
- package/dist/hooks/use-table-handle-positioning.d.mts +42 -0
- package/dist/hooks/use-table-handle-positioning.d.ts +42 -0
- package/dist/hooks/use-table-handle-positioning.js +190 -0
- package/dist/hooks/use-table-handle-positioning.mjs +10 -0
- package/dist/hooks/use-table-handle-state.d.mts +28 -0
- package/dist/hooks/use-table-handle-state.d.ts +28 -0
- package/dist/hooks/use-table-handle-state.js +76 -0
- package/dist/hooks/use-table-handle-state.mjs +9 -0
- package/dist/hooks/use-table-header-row-column.d.mts +58 -0
- package/dist/hooks/use-table-header-row-column.d.ts +58 -0
- package/dist/hooks/use-table-header-row-column.js +603 -0
- package/dist/hooks/use-table-header-row-column.mjs +13 -0
- package/dist/hooks/use-table-merge-split-cell.d.mts +123 -0
- package/dist/hooks/use-table-merge-split-cell.d.ts +123 -0
- package/dist/hooks/use-table-merge-split-cell.js +331 -0
- package/dist/hooks/use-table-merge-split-cell.mjs +12 -0
- package/dist/hooks/use-table-move-row-column.d.mts +101 -0
- package/dist/hooks/use-table-move-row-column.d.ts +101 -0
- package/dist/hooks/use-table-move-row-column.js +621 -0
- package/dist/hooks/use-table-move-row-column.mjs +13 -0
- package/dist/hooks/use-table-sort-row-column.d.mts +118 -0
- package/dist/hooks/use-table-sort-row-column.d.ts +118 -0
- package/dist/hooks/use-table-sort-row-column.js +623 -0
- package/dist/hooks/use-table-sort-row-column.mjs +13 -0
- package/dist/index.d.mts +17 -6
- package/dist/index.d.ts +17 -6
- package/dist/index.js +4947 -660
- package/dist/index.mjs +43 -21
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/{table/lib/is-cell-selection.js → lib/constants.js} +10 -10
- package/dist/lib/constants.mjs +10 -0
- package/dist/lib/create-image.d.mts +12 -0
- package/dist/lib/create-image.d.ts +12 -0
- package/dist/lib/create-image.js +221 -0
- package/dist/lib/create-image.mjs +8 -0
- package/dist/lib/table-utils.d.mts +263 -0
- package/dist/lib/table-utils.d.ts +263 -0
- package/dist/lib/table-utils.js +488 -0
- package/dist/lib/table-utils.mjs +40 -0
- package/dist/messages.d.mts +174 -0
- package/dist/messages.d.ts +174 -0
- package/dist/messages.js +213 -0
- package/dist/{table-row.mjs → messages.mjs} +3 -3
- package/dist/ui/table-alignment-menu.d.mts +25 -0
- package/dist/ui/table-alignment-menu.d.ts +25 -0
- package/dist/ui/table-alignment-menu.js +758 -0
- package/dist/ui/table-alignment-menu.mjs +14 -0
- package/dist/ui/table-cell-handle-menu.d.mts +12 -0
- package/dist/ui/table-cell-handle-menu.d.ts +12 -0
- package/dist/ui/table-cell-handle-menu.js +1317 -0
- package/dist/ui/table-cell-handle-menu.mjs +17 -0
- package/dist/ui/table-handle-menu.d.mts +23 -0
- package/dist/ui/table-handle-menu.d.ts +23 -0
- package/dist/ui/table-handle-menu.js +2598 -0
- package/dist/ui/table-handle-menu.mjs +21 -0
- package/dist/ui/table-handle.d.mts +48 -0
- package/dist/ui/table-handle.d.ts +48 -0
- package/dist/ui/table-handle.js +3126 -0
- package/dist/ui/table-handle.mjs +22 -0
- package/dist/ui/table-selection-overlay.d.mts +14 -0
- package/dist/ui/table-selection-overlay.d.ts +14 -0
- package/dist/ui/table-selection-overlay.js +553 -0
- package/dist/ui/table-selection-overlay.mjs +11 -0
- package/package.json +12 -7
- package/dist/chunk-3XEOCAHB.mjs +0 -41
- package/dist/chunk-5W5ARI64.mjs +0 -11
- package/dist/chunk-BTJ3DCGC.mjs +0 -113
- package/dist/chunk-DR2GZJH6.mjs +0 -70
- package/dist/chunk-GHOJLOCF.mjs +0 -247
- package/dist/chunk-HWVA6DOK.mjs +0 -20
- package/dist/chunk-KLUH6EZS.mjs +0 -40
- package/dist/chunk-KNOMCS6F.mjs +0 -57
- package/dist/chunk-LPHCE6EI.mjs +0 -92
- package/dist/chunk-POJFNXG7.mjs +0 -44
- package/dist/chunk-QHD3QTD2.mjs +0 -61
- package/dist/chunk-RPPUD4R5.mjs +0 -1
- package/dist/kit.js +0 -764
- package/dist/kit.mjs +0 -19
- package/dist/table/index.d.mts +0 -6
- package/dist/table/index.d.ts +0 -6
- package/dist/table/index.js +0 -625
- package/dist/table/index.mjs +0 -18
- package/dist/table/lib/col-style.d.mts +0 -3
- package/dist/table/lib/col-style.d.ts +0 -3
- package/dist/table/lib/col-style.js +0 -36
- package/dist/table/lib/col-style.mjs +0 -13
- package/dist/table/lib/delete-table-when-all-cells-selected.d.mts +0 -5
- package/dist/table/lib/delete-table-when-all-cells-selected.d.ts +0 -5
- package/dist/table/lib/delete-table-when-all-cells-selected.js +0 -66
- package/dist/table/lib/delete-table-when-all-cells-selected.mjs +0 -40
- package/dist/table/lib/get-table-node-types.d.mts +0 -7
- package/dist/table/lib/get-table-node-types.d.ts +0 -7
- package/dist/table/lib/get-table-node-types.js +0 -44
- package/dist/table/lib/get-table-node-types.mjs +0 -21
- package/dist/table/lib/icons.d.mts +0 -13
- package/dist/table/lib/icons.d.ts +0 -13
- package/dist/table/lib/icons.js +0 -81
- package/dist/table/lib/icons.mjs +0 -58
- package/dist/table/lib/insert-line-above-table-action.d.mts +0 -5
- package/dist/table/lib/insert-line-above-table-action.d.ts +0 -5
- package/dist/table/lib/insert-line-above-table-action.js +0 -64
- package/dist/table/lib/insert-line-above-table-action.mjs +0 -8
- package/dist/table/lib/insert-line-below-table-action.d.mts +0 -5
- package/dist/table/lib/insert-line-below-table-action.d.ts +0 -5
- package/dist/table/lib/insert-line-below-table-action.js +0 -63
- package/dist/table/lib/insert-line-below-table-action.mjs +0 -8
- package/dist/table/lib/is-cell-selection.d.mts +0 -5
- package/dist/table/lib/is-cell-selection.d.ts +0 -5
- package/dist/table/lib/is-cell-selection.mjs +0 -8
- package/dist/table/lib/table-controls.d.mts +0 -15
- package/dist/table/lib/table-controls.d.ts +0 -15
- package/dist/table/lib/table-controls.js +0 -131
- package/dist/table/lib/table-controls.mjs +0 -8
- package/dist/table/table.js +0 -621
- package/dist/table/table.mjs +0 -14
- package/dist/table/views/table-column-menu.d.mts +0 -11
- package/dist/table/views/table-column-menu.d.ts +0 -11
- package/dist/table/views/table-column-menu.js +0 -84
- package/dist/table/views/table-column-menu.mjs +0 -8
- package/dist/table/views/table-node-view.d.mts +0 -25
- package/dist/table/views/table-node-view.d.ts +0 -25
- package/dist/table/views/table-node-view.js +0 -370
- package/dist/table/views/table-node-view.mjs +0 -10
- package/dist/table/views/table-row-menu.d.mts +0 -11
- package/dist/table/views/table-row-menu.d.ts +0 -11
- package/dist/table/views/table-row-menu.js +0 -80
- package/dist/table/views/table-row-menu.mjs +0 -8
- package/dist/table-cell.d.mts +0 -8
- package/dist/table-cell.d.ts +0 -8
- package/dist/table-cell.js +0 -93
- package/dist/table-cell.mjs +0 -8
- package/dist/table-header.d.mts +0 -6
- package/dist/table-header.d.ts +0 -6
- package/dist/table-header.js +0 -67
- package/dist/table-header.mjs +0 -8
- package/dist/table-row.d.mts +0 -6
- package/dist/table-row.d.ts +0 -6
- package/dist/table-row.js +0 -43
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
domCellAround,
|
|
4
|
+
getTable,
|
|
5
|
+
rectEq
|
|
6
|
+
} from "./chunk-5B5XIL2G.mjs";
|
|
7
|
+
import {
|
|
8
|
+
useResizeOverlay
|
|
9
|
+
} from "./chunk-J4VOSZCZ.mjs";
|
|
10
|
+
|
|
11
|
+
// src/ui/table-selection-overlay.tsx
|
|
12
|
+
import { FloatingPortal, useFloating } from "@floating-ui/react";
|
|
13
|
+
import { useTiptapEditor } from "@kopexa/editor-utils";
|
|
14
|
+
import { CellSelection, cellAround } from "@tiptap/pm/tables";
|
|
15
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
16
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
var CORNER_DETECTION_TOLERANCE = 5;
|
|
18
|
+
var getCellAtCoordinates = (state, view, x, y) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const pos = (_a = view.posAtCoords({ left: x, top: y })) == null ? void 0 : _a.pos;
|
|
21
|
+
if (pos == null) return null;
|
|
22
|
+
const $pos = state.doc.resolve(pos);
|
|
23
|
+
return cellAround($pos);
|
|
24
|
+
};
|
|
25
|
+
var getSelectionBoundingRect = (view, selection) => {
|
|
26
|
+
if (!(selection instanceof CellSelection)) return null;
|
|
27
|
+
const cells = [];
|
|
28
|
+
selection.forEachCell((_node, pos) => {
|
|
29
|
+
const dom = view.nodeDOM(pos);
|
|
30
|
+
if (dom) cells.push(dom);
|
|
31
|
+
});
|
|
32
|
+
if (cells.length === 0) return null;
|
|
33
|
+
const bounds = {
|
|
34
|
+
left: Infinity,
|
|
35
|
+
top: Infinity,
|
|
36
|
+
right: -Infinity,
|
|
37
|
+
bottom: -Infinity
|
|
38
|
+
};
|
|
39
|
+
cells.forEach((cell) => {
|
|
40
|
+
const rect = cell.getBoundingClientRect();
|
|
41
|
+
bounds.left = Math.min(bounds.left, rect.left);
|
|
42
|
+
bounds.top = Math.min(bounds.top, rect.top);
|
|
43
|
+
bounds.right = Math.max(bounds.right, rect.right);
|
|
44
|
+
bounds.bottom = Math.max(bounds.bottom, rect.bottom);
|
|
45
|
+
});
|
|
46
|
+
return new DOMRect(
|
|
47
|
+
bounds.left,
|
|
48
|
+
bounds.top,
|
|
49
|
+
bounds.right - bounds.left,
|
|
50
|
+
bounds.bottom - bounds.top
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
var getSingleCellBoundingRect = (view, cellPos) => {
|
|
54
|
+
const cellDom = view.nodeDOM(cellPos);
|
|
55
|
+
if (!cellDom) return null;
|
|
56
|
+
const rect = cellDom.getBoundingClientRect();
|
|
57
|
+
return new DOMRect(rect.left, rect.top, rect.width, rect.height);
|
|
58
|
+
};
|
|
59
|
+
var createVirtualReference = (rect) => ({
|
|
60
|
+
getBoundingClientRect: () => rect
|
|
61
|
+
});
|
|
62
|
+
var findCornerCells = (view, selection, selectionRect) => {
|
|
63
|
+
const corners = {
|
|
64
|
+
topLeft: null,
|
|
65
|
+
topRight: null,
|
|
66
|
+
bottomLeft: null,
|
|
67
|
+
bottomRight: null
|
|
68
|
+
};
|
|
69
|
+
const isNearEdge = (value1, value2) => Math.abs(value1 - value2) < CORNER_DETECTION_TOLERANCE;
|
|
70
|
+
selection.forEachCell((_node, pos) => {
|
|
71
|
+
const dom = view.nodeDOM(pos);
|
|
72
|
+
if (!dom) return;
|
|
73
|
+
const cellRect = dom.getBoundingClientRect();
|
|
74
|
+
if (isNearEdge(cellRect.left, selectionRect.left) && isNearEdge(cellRect.top, selectionRect.top)) {
|
|
75
|
+
corners.topLeft = pos;
|
|
76
|
+
}
|
|
77
|
+
if (isNearEdge(cellRect.right, selectionRect.right) && isNearEdge(cellRect.top, selectionRect.top)) {
|
|
78
|
+
corners.topRight = pos;
|
|
79
|
+
}
|
|
80
|
+
if (isNearEdge(cellRect.left, selectionRect.left) && isNearEdge(cellRect.bottom, selectionRect.bottom)) {
|
|
81
|
+
corners.bottomLeft = pos;
|
|
82
|
+
}
|
|
83
|
+
if (isNearEdge(cellRect.right, selectionRect.right) && isNearEdge(cellRect.bottom, selectionRect.bottom)) {
|
|
84
|
+
corners.bottomRight = pos;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return corners;
|
|
88
|
+
};
|
|
89
|
+
var getAnchorCellForHandle = (view, selection, selectionRect, handle) => {
|
|
90
|
+
if (!handle) return null;
|
|
91
|
+
const corners = findCornerCells(view, selection, selectionRect);
|
|
92
|
+
const anchorMap = {
|
|
93
|
+
tl: "bottomRight",
|
|
94
|
+
tr: "bottomLeft",
|
|
95
|
+
bl: "topRight",
|
|
96
|
+
br: "topLeft"
|
|
97
|
+
};
|
|
98
|
+
const anchorPos = corners[anchorMap[handle]];
|
|
99
|
+
return anchorPos ? { pos: anchorPos } : null;
|
|
100
|
+
};
|
|
101
|
+
var createHandleStyles = () => ({
|
|
102
|
+
position: "absolute",
|
|
103
|
+
width: 15,
|
|
104
|
+
height: 15,
|
|
105
|
+
borderRadius: "50%",
|
|
106
|
+
display: "flex",
|
|
107
|
+
alignItems: "center",
|
|
108
|
+
justifyContent: "center",
|
|
109
|
+
background: "transparent",
|
|
110
|
+
pointerEvents: "auto",
|
|
111
|
+
zIndex: 10
|
|
112
|
+
});
|
|
113
|
+
var createCornerHandleStyles = (position, isActiveHandle, isDisabled = false) => {
|
|
114
|
+
const baseStyles = createHandleStyles();
|
|
115
|
+
const positionStyles = {
|
|
116
|
+
tl: {
|
|
117
|
+
top: -7.5,
|
|
118
|
+
left: -7.5,
|
|
119
|
+
cursor: isDisabled ? "default" : "nwse-resize"
|
|
120
|
+
},
|
|
121
|
+
tr: {
|
|
122
|
+
top: -7.5,
|
|
123
|
+
right: -7.5,
|
|
124
|
+
cursor: isDisabled ? "default" : "nesw-resize"
|
|
125
|
+
},
|
|
126
|
+
bl: {
|
|
127
|
+
bottom: -7.5,
|
|
128
|
+
left: -7.5,
|
|
129
|
+
cursor: isDisabled ? "default" : "nesw-resize"
|
|
130
|
+
},
|
|
131
|
+
br: {
|
|
132
|
+
bottom: -7.5,
|
|
133
|
+
right: -7.5,
|
|
134
|
+
cursor: isDisabled ? "default" : "nwse-resize"
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
...baseStyles,
|
|
139
|
+
...positionStyles[position],
|
|
140
|
+
opacity: isDisabled ? 0.3 : isActiveHandle ? 1 : 0.5,
|
|
141
|
+
pointerEvents: isDisabled ? "none" : "auto"
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
var TableSelectionOverlay = ({
|
|
145
|
+
editor: providedEditor,
|
|
146
|
+
cellMenu: CellMenu,
|
|
147
|
+
showResizeHandles = true,
|
|
148
|
+
onMenuOpenChange
|
|
149
|
+
}) => {
|
|
150
|
+
const { editor } = useTiptapEditor(providedEditor);
|
|
151
|
+
const [isVisible, setIsVisible] = useState(true);
|
|
152
|
+
const [selectionRect, setSelectionRect] = useState(null);
|
|
153
|
+
const [activeHandle, setActiveHandle] = useState(null);
|
|
154
|
+
const [tableDom, setTableDom] = useState(null);
|
|
155
|
+
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
156
|
+
const anchorCellRef = useRef(null);
|
|
157
|
+
const activeHandleRef = useRef(null);
|
|
158
|
+
const containerRef = useRef(null);
|
|
159
|
+
const { refs, floatingStyles, update } = useFloating({
|
|
160
|
+
placement: "top-start"
|
|
161
|
+
});
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (selectionRect) {
|
|
164
|
+
const virtualReference = createVirtualReference(selectionRect);
|
|
165
|
+
refs.setPositionReference(virtualReference);
|
|
166
|
+
}
|
|
167
|
+
}, [selectionRect, refs]);
|
|
168
|
+
const updateSelectionRect = useCallback(() => {
|
|
169
|
+
if (!editor) return;
|
|
170
|
+
const { selection } = editor.state;
|
|
171
|
+
if (selection instanceof CellSelection) {
|
|
172
|
+
const rect = getSelectionBoundingRect(editor.view, selection);
|
|
173
|
+
if (!rect) {
|
|
174
|
+
setIsVisible(false);
|
|
175
|
+
setSelectionRect((prev) => prev ? null : prev);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
setSelectionRect((prev) => rectEq(prev, rect) ? prev : rect);
|
|
179
|
+
setIsVisible(true);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const { $anchor } = selection;
|
|
183
|
+
const cell = cellAround($anchor);
|
|
184
|
+
if (cell) {
|
|
185
|
+
const rect = getSingleCellBoundingRect(editor.view, cell.pos);
|
|
186
|
+
if (rect) {
|
|
187
|
+
setSelectionRect((prev) => rectEq(prev, rect) ? prev : rect);
|
|
188
|
+
setIsVisible(true);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
setIsVisible(false);
|
|
193
|
+
setSelectionRect((prev) => prev ? null : prev);
|
|
194
|
+
}, [editor]);
|
|
195
|
+
useResizeOverlay(editor, updateSelectionRect);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (update && selectionRect) {
|
|
198
|
+
update();
|
|
199
|
+
}
|
|
200
|
+
}, [update, selectionRect]);
|
|
201
|
+
const createResizeHandler = useCallback(
|
|
202
|
+
(handle) => (event) => {
|
|
203
|
+
if (!editor || !handle || !selectionRect || isMenuOpen || !showResizeHandles)
|
|
204
|
+
return;
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
event.stopPropagation();
|
|
207
|
+
const { selection } = editor.state;
|
|
208
|
+
let cellSelection = null;
|
|
209
|
+
if (selection instanceof CellSelection) {
|
|
210
|
+
cellSelection = selection;
|
|
211
|
+
} else {
|
|
212
|
+
const { $anchor } = selection;
|
|
213
|
+
const cell = cellAround($anchor);
|
|
214
|
+
if (cell) {
|
|
215
|
+
try {
|
|
216
|
+
cellSelection = CellSelection.create(
|
|
217
|
+
editor.state.doc,
|
|
218
|
+
cell.pos,
|
|
219
|
+
cell.pos
|
|
220
|
+
);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
console.warn(
|
|
223
|
+
"Could not create single cell selection for resize:",
|
|
224
|
+
error
|
|
225
|
+
);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!cellSelection) return;
|
|
231
|
+
const anchorCell = getAnchorCellForHandle(
|
|
232
|
+
editor.view,
|
|
233
|
+
cellSelection,
|
|
234
|
+
selectionRect,
|
|
235
|
+
handle
|
|
236
|
+
);
|
|
237
|
+
if (!anchorCell) return;
|
|
238
|
+
setActiveHandle(handle);
|
|
239
|
+
activeHandleRef.current = handle;
|
|
240
|
+
anchorCellRef.current = anchorCell.pos;
|
|
241
|
+
const handleMouseMove = (mouseEvent) => {
|
|
242
|
+
if (!editor || anchorCellRef.current == null) return;
|
|
243
|
+
const target = domCellAround(mouseEvent.target);
|
|
244
|
+
if (!target || target.type !== "cell") return;
|
|
245
|
+
const targetCell = getCellAtCoordinates(
|
|
246
|
+
editor.state,
|
|
247
|
+
editor.view,
|
|
248
|
+
mouseEvent.clientX,
|
|
249
|
+
mouseEvent.clientY
|
|
250
|
+
);
|
|
251
|
+
if (!targetCell) return;
|
|
252
|
+
try {
|
|
253
|
+
const newSelection = CellSelection.create(
|
|
254
|
+
editor.state.doc,
|
|
255
|
+
anchorCellRef.current,
|
|
256
|
+
targetCell.pos
|
|
257
|
+
);
|
|
258
|
+
const transaction = editor.state.tr.setSelection(newSelection);
|
|
259
|
+
editor.view.dispatch(transaction);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.debug("Invalid cell selection during resize:", error);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const handleMouseUp = () => {
|
|
265
|
+
setActiveHandle(null);
|
|
266
|
+
activeHandleRef.current = null;
|
|
267
|
+
anchorCellRef.current = null;
|
|
268
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
269
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
270
|
+
};
|
|
271
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
272
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
273
|
+
},
|
|
274
|
+
[editor, selectionRect, isMenuOpen, showResizeHandles]
|
|
275
|
+
);
|
|
276
|
+
const updateTableDom = useCallback(() => {
|
|
277
|
+
if (!editor) {
|
|
278
|
+
setTableDom(null);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const table = getTable(editor);
|
|
282
|
+
if (!table) {
|
|
283
|
+
setTableDom(null);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
setTableDom((prev) => {
|
|
287
|
+
const currentDom = prev;
|
|
288
|
+
const newDom = editor.view.nodeDOM(table.pos);
|
|
289
|
+
return currentDom === newDom ? currentDom : newDom;
|
|
290
|
+
});
|
|
291
|
+
}, [editor]);
|
|
292
|
+
const handleMenuOpenChange = useCallback(
|
|
293
|
+
(isOpen) => {
|
|
294
|
+
setIsMenuOpen(isOpen);
|
|
295
|
+
onMenuOpenChange == null ? void 0 : onMenuOpenChange(isOpen);
|
|
296
|
+
},
|
|
297
|
+
[onMenuOpenChange]
|
|
298
|
+
);
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
if (!editor) return;
|
|
301
|
+
const handleSelectionUpdate = () => {
|
|
302
|
+
updateSelectionRect();
|
|
303
|
+
updateTableDom();
|
|
304
|
+
};
|
|
305
|
+
editor.on("selectionUpdate", handleSelectionUpdate);
|
|
306
|
+
updateSelectionRect();
|
|
307
|
+
updateTableDom();
|
|
308
|
+
return () => {
|
|
309
|
+
editor.off("selectionUpdate", handleSelectionUpdate);
|
|
310
|
+
};
|
|
311
|
+
}, [editor, updateSelectionRect, updateTableDom]);
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
const c = tableDom == null ? void 0 : tableDom.querySelector(
|
|
314
|
+
".table-selection-overlay-container"
|
|
315
|
+
);
|
|
316
|
+
containerRef.current = c != null ? c : null;
|
|
317
|
+
}, [tableDom]);
|
|
318
|
+
if (!isVisible || !selectionRect) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
if (!editor) return null;
|
|
322
|
+
const renderCellMenu = () => {
|
|
323
|
+
if (!CellMenu) return null;
|
|
324
|
+
return /* @__PURE__ */ jsx(
|
|
325
|
+
"span",
|
|
326
|
+
{
|
|
327
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
328
|
+
style: { pointerEvents: "auto" },
|
|
329
|
+
children: /* @__PURE__ */ jsx(CellMenu, { onOpenChange: handleMenuOpenChange, editor })
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
};
|
|
333
|
+
return /* @__PURE__ */ jsx(FloatingPortal, { root: containerRef.current, children: /* @__PURE__ */ jsx(
|
|
334
|
+
"div",
|
|
335
|
+
{
|
|
336
|
+
ref: refs.setFloating,
|
|
337
|
+
style: {
|
|
338
|
+
...floatingStyles,
|
|
339
|
+
pointerEvents: "none",
|
|
340
|
+
zIndex: 10
|
|
341
|
+
},
|
|
342
|
+
children: /* @__PURE__ */ jsxs("div", { className: "tiptap-table-selection-overlay", children: [
|
|
343
|
+
/* @__PURE__ */ jsx(
|
|
344
|
+
"div",
|
|
345
|
+
{
|
|
346
|
+
style: {
|
|
347
|
+
position: "absolute",
|
|
348
|
+
width: selectionRect.width,
|
|
349
|
+
height: selectionRect.height,
|
|
350
|
+
zIndex: 2,
|
|
351
|
+
borderRadius: 2,
|
|
352
|
+
top: 0,
|
|
353
|
+
left: 0
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
),
|
|
357
|
+
/* @__PURE__ */ jsxs(
|
|
358
|
+
"div",
|
|
359
|
+
{
|
|
360
|
+
style: {
|
|
361
|
+
position: "absolute",
|
|
362
|
+
width: selectionRect.width,
|
|
363
|
+
height: selectionRect.height,
|
|
364
|
+
border: `2px solid var(--color-primary-400)`,
|
|
365
|
+
borderRadius: 2,
|
|
366
|
+
zIndex: 3,
|
|
367
|
+
top: 0,
|
|
368
|
+
left: 0
|
|
369
|
+
},
|
|
370
|
+
children: [
|
|
371
|
+
renderCellMenu(),
|
|
372
|
+
showResizeHandles && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
373
|
+
/* @__PURE__ */ jsx(
|
|
374
|
+
"div",
|
|
375
|
+
{
|
|
376
|
+
style: createCornerHandleStyles(
|
|
377
|
+
"tl",
|
|
378
|
+
!activeHandle || activeHandle === "tl",
|
|
379
|
+
isMenuOpen
|
|
380
|
+
),
|
|
381
|
+
onMouseDown: createResizeHandler("tl")
|
|
382
|
+
}
|
|
383
|
+
),
|
|
384
|
+
/* @__PURE__ */ jsx(
|
|
385
|
+
"div",
|
|
386
|
+
{
|
|
387
|
+
style: createCornerHandleStyles(
|
|
388
|
+
"tr",
|
|
389
|
+
!activeHandle || activeHandle === "tr",
|
|
390
|
+
isMenuOpen
|
|
391
|
+
),
|
|
392
|
+
onMouseDown: createResizeHandler("tr")
|
|
393
|
+
}
|
|
394
|
+
),
|
|
395
|
+
/* @__PURE__ */ jsx(
|
|
396
|
+
"div",
|
|
397
|
+
{
|
|
398
|
+
style: createCornerHandleStyles(
|
|
399
|
+
"bl",
|
|
400
|
+
!activeHandle || activeHandle === "bl",
|
|
401
|
+
isMenuOpen
|
|
402
|
+
),
|
|
403
|
+
onMouseDown: createResizeHandler("bl")
|
|
404
|
+
}
|
|
405
|
+
),
|
|
406
|
+
/* @__PURE__ */ jsx(
|
|
407
|
+
"div",
|
|
408
|
+
{
|
|
409
|
+
style: createCornerHandleStyles(
|
|
410
|
+
"br",
|
|
411
|
+
!activeHandle || activeHandle === "br",
|
|
412
|
+
isMenuOpen
|
|
413
|
+
),
|
|
414
|
+
onMouseDown: createResizeHandler("br")
|
|
415
|
+
}
|
|
416
|
+
)
|
|
417
|
+
] })
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
)
|
|
421
|
+
] })
|
|
422
|
+
}
|
|
423
|
+
) });
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
export {
|
|
427
|
+
TableSelectionOverlay
|
|
428
|
+
};
|