@ctzhian/tiptap 1.13.9 → 2.0.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.
Files changed (47) hide show
  1. package/dist/Editor/demo.js +1 -1
  2. package/dist/Editor/index.js +17 -0
  3. package/dist/component/CustomBubbleMenu/index.js +1 -1
  4. package/dist/component/CustomDragHandle/index.js +3 -59
  5. package/dist/component/Icons/delete-back-2-line-icon.d.ts +6 -0
  6. package/dist/component/Icons/delete-back-2-line-icon.js +13 -0
  7. package/dist/component/Menu/index.js +5 -1
  8. package/dist/contants/enums.d.ts +9 -0
  9. package/dist/contants/enums.js +61 -1
  10. package/dist/extension/component/TableCellHandleMenu/index.d.ts +9 -0
  11. package/dist/extension/component/TableCellHandleMenu/index.js +443 -0
  12. package/dist/extension/component/TableExtendButton/TableExtendButton.css +30 -0
  13. package/dist/extension/component/TableExtendButton/index.d.ts +23 -0
  14. package/dist/extension/component/TableExtendButton/index.js +201 -0
  15. package/dist/extension/component/TableExtendButton/use-table-extend-row-column.d.ts +15 -0
  16. package/dist/extension/component/TableExtendButton/use-table-extend-row-column.js +87 -0
  17. package/dist/extension/component/TableHandle/TableHandleMenu.css +36 -0
  18. package/dist/extension/component/TableHandle/TableHandleMenu.d.ts +17 -0
  19. package/dist/extension/component/TableHandle/TableHandleMenu.js +685 -0
  20. package/dist/extension/component/TableHandle/index.d.ts +28 -0
  21. package/dist/extension/component/TableHandle/index.js +93 -0
  22. package/dist/extension/component/TableHandle/use-table-handle-positioning.d.ts +40 -0
  23. package/dist/extension/component/TableHandle/use-table-handle-positioning.js +193 -0
  24. package/dist/extension/component/TableHandle/use-table-handle-state.d.ts +22 -0
  25. package/dist/extension/component/TableHandle/use-table-handle-state.js +45 -0
  26. package/dist/extension/component/TableSelectionOverlay/index.d.ts +16 -0
  27. package/dist/extension/component/TableSelectionOverlay/index.js +460 -0
  28. package/dist/extension/component/UploadProgress/index.d.ts +1 -1
  29. package/dist/extension/node/FileHandler.d.ts +1 -1
  30. package/dist/extension/node/Table.js +226 -43
  31. package/dist/extension/node/TableHandler/create-image.d.ts +9 -0
  32. package/dist/extension/node/TableHandler/create-image.js +235 -0
  33. package/dist/extension/node/TableHandler/index.d.ts +15 -0
  34. package/dist/extension/node/TableHandler/index.js +33 -0
  35. package/dist/extension/node/TableHandler/plugin.d.ts +49 -0
  36. package/dist/extension/node/TableHandler/plugin.js +1030 -0
  37. package/dist/index.css +29 -10
  38. package/dist/type/index.d.ts +2 -0
  39. package/dist/util/table-utils.d.ts +161 -0
  40. package/dist/util/table-utils.js +605 -0
  41. package/package.json +2 -1
  42. package/dist/extension/component/Table/ContextMenu.d.ts +0 -11
  43. package/dist/extension/component/Table/ContextMenu.js +0 -186
  44. package/dist/extension/component/Table/TableContextMenuPlugin.d.ts +0 -9
  45. package/dist/extension/component/Table/TableContextMenuPlugin.js +0 -336
  46. package/dist/extension/component/Table/index.d.ts +0 -2
  47. package/dist/extension/component/Table/index.js +0 -2
@@ -0,0 +1,28 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import type { Editor } from '@tiptap/react';
3
+ import React from 'react';
4
+ import type { Orientation } from '../../../util/table-utils';
5
+ export interface TableHandleButtonProps {
6
+ editor: Editor;
7
+ orientation: Orientation;
8
+ index?: number;
9
+ tablePos?: number;
10
+ tableNode?: Node;
11
+ onToggleOtherHandle?: (visible: boolean) => void;
12
+ onOpenChange?: (open: boolean) => void;
13
+ dragStart?: (e: React.DragEvent) => void;
14
+ }
15
+ export interface TableHandleProps {
16
+ /**
17
+ * The Tiptap editor instance.
18
+ */
19
+ editor?: Editor | null;
20
+ }
21
+ /**
22
+ * Main table handle component that manages the positioning and rendering
23
+ * of table row/column handles, extend buttons, and context menus.
24
+ */
25
+ export declare function TableHandle({ editor: providedEditor, }: TableHandleProps): React.JSX.Element | null;
26
+ export declare namespace TableHandle {
27
+ var displayName: string;
28
+ }
@@ -0,0 +1,93 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { FloatingPortal } from '@floating-ui/react';
8
+ import React, { useCallback, useMemo, useState } from 'react';
9
+ import { colDragStart, rowDragStart } from "../../node/TableHandler/plugin";
10
+ import { TableHandleMenu } from "./TableHandleMenu";
11
+ import { useTableHandlePositioning } from "./use-table-handle-positioning";
12
+ import { useTableHandleState } from "./use-table-handle-state";
13
+ /**
14
+ * Main table handle component that manages the positioning and rendering
15
+ * of table row/column handles, extend buttons, and context menus.
16
+ */
17
+ export function TableHandle(_ref) {
18
+ var providedEditor = _ref.editor;
19
+ var editor = providedEditor;
20
+ var state = useTableHandleState({
21
+ editor: editor
22
+ });
23
+ var _useState = useState(true),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ isRowVisible = _useState2[0],
26
+ setIsRowVisible = _useState2[1];
27
+ var _useState3 = useState(true),
28
+ _useState4 = _slicedToArray(_useState3, 2),
29
+ isColumnVisible = _useState4[0],
30
+ setIsColumnVisible = _useState4[1];
31
+ var _useState5 = useState(null),
32
+ _useState6 = _slicedToArray(_useState5, 2),
33
+ menuOpen = _useState6[0],
34
+ setMenuOpen = _useState6[1];
35
+ var draggingState = useMemo(function () {
36
+ if (!(state !== null && state !== void 0 && state.draggingState)) return undefined;
37
+ return {
38
+ draggedCellOrientation: state.draggingState.draggedCellOrientation,
39
+ mousePos: state.draggingState.mousePos,
40
+ initialOffset: state.draggingState.initialOffset
41
+ };
42
+ }, [state === null || state === void 0 ? void 0 : state.draggingState]);
43
+ var _useTableHandlePositi = useTableHandlePositioning((state === null || state === void 0 ? void 0 : state.show) || false, (state === null || state === void 0 ? void 0 : state.referencePosCell) || null, (state === null || state === void 0 ? void 0 : state.referencePosTable) || null, draggingState),
44
+ rowHandle = _useTableHandlePositi.rowHandle,
45
+ colHandle = _useTableHandlePositi.colHandle;
46
+ var toggleRowVisibility = useCallback(function (visible) {
47
+ setIsRowVisible(visible);
48
+ }, []);
49
+ var toggleColumnVisibility = useCallback(function (visible) {
50
+ setIsColumnVisible(visible);
51
+ }, []);
52
+ var handleMenuOpenChange = useCallback(function (type, open) {
53
+ setMenuOpen(open ? type : null);
54
+ }, []);
55
+ if (!editor || !state) return null;
56
+ var hasValidRowIndex = typeof state.rowIndex === 'number';
57
+ var hasValidColIndex = typeof state.colIndex === 'number';
58
+ var shouldShowRow = isRowVisible && rowHandle.isMounted && hasValidRowIndex || menuOpen === 'row';
59
+ var shouldShowColumn = isColumnVisible && colHandle.isMounted && hasValidColIndex || menuOpen === 'column';
60
+ var rootElement = state.widgetContainer || document.body;
61
+ return /*#__PURE__*/React.createElement(FloatingPortal, {
62
+ root: rootElement
63
+ }, shouldShowRow && /*#__PURE__*/React.createElement("div", {
64
+ ref: rowHandle.ref,
65
+ style: rowHandle.style
66
+ }, /*#__PURE__*/React.createElement(TableHandleMenu, {
67
+ editor: editor,
68
+ orientation: "row",
69
+ index: state.rowIndex,
70
+ tablePos: state.blockPos,
71
+ tableNode: state.block,
72
+ onToggleOtherHandle: toggleColumnVisibility,
73
+ dragStart: rowDragStart,
74
+ onOpenChange: function onOpenChange(open) {
75
+ return handleMenuOpenChange('row', open);
76
+ }
77
+ })), shouldShowColumn && /*#__PURE__*/React.createElement("div", {
78
+ ref: colHandle.ref,
79
+ style: colHandle.style
80
+ }, /*#__PURE__*/React.createElement(TableHandleMenu, {
81
+ editor: editor,
82
+ orientation: "column",
83
+ index: state.colIndex,
84
+ tablePos: state.blockPos,
85
+ tableNode: state.block,
86
+ onToggleOtherHandle: toggleRowVisibility,
87
+ dragStart: colDragStart,
88
+ onOpenChange: function onOpenChange(open) {
89
+ return handleMenuOpenChange('column', open);
90
+ }
91
+ })));
92
+ }
93
+ TableHandle.displayName = 'TableHandle';
@@ -0,0 +1,40 @@
1
+ /// <reference types="react" />
2
+ type Orientation = 'row' | 'col' | 'cell';
3
+ type DraggingState = {
4
+ draggedCellOrientation: Exclude<Orientation, 'cell'>;
5
+ mousePos: number;
6
+ initialOffset?: number;
7
+ originalCellSize?: {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ };
12
+ /**
13
+ * Hook for positioning individual table handles using Floating UI React
14
+ */
15
+ export declare function useTableHandlePosition(orientation: Orientation, show: boolean, referencePosCell: DOMRect | null, referencePosTable: DOMRect | null, draggingState?: DraggingState): {
16
+ isMounted: boolean;
17
+ ref: (node: HTMLElement | null) => void;
18
+ style: React.CSSProperties;
19
+ };
20
+ /**
21
+ * Hook for managing positioning of all table handles (row, column, and cell)
22
+ */
23
+ export declare function useTableHandlePositioning(show: boolean, referencePosCell: DOMRect | null, referencePosTable: DOMRect | null, draggingState?: DraggingState): {
24
+ rowHandle: {
25
+ isMounted: boolean;
26
+ ref: (node: HTMLElement | null) => void;
27
+ style: import("react").CSSProperties;
28
+ };
29
+ colHandle: {
30
+ isMounted: boolean;
31
+ ref: (node: HTMLElement | null) => void;
32
+ style: import("react").CSSProperties;
33
+ };
34
+ cellHandle: {
35
+ isMounted: boolean;
36
+ ref: (node: HTMLElement | null) => void;
37
+ style: import("react").CSSProperties;
38
+ };
39
+ };
40
+ export {};
@@ -0,0 +1,193 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import { offset, size, useFloating, useTransitionStyles } from '@floating-ui/react';
8
+ import { useEffect, useMemo } from 'react';
9
+ import { clamp } from "../../../util/table-utils";
10
+ /**
11
+ * Creates a DOMRect for row handle positioning
12
+ * Reference is positioned at table edge, aligned with cell
13
+ */
14
+ function makeRowRect(cell, table, dragging) {
15
+ if ((dragging === null || dragging === void 0 ? void 0 : dragging.draggedCellOrientation) === 'row') {
16
+ var _dragging$initialOffs;
17
+ // Apply the initial offset to maintain handle position
18
+ var adjustedY = dragging.mousePos + ((_dragging$initialOffs = dragging.initialOffset) !== null && _dragging$initialOffs !== void 0 ? _dragging$initialOffs : 0);
19
+ var clampedY = clamp(adjustedY, table.y, table.bottom - cell.height);
20
+ return new DOMRect(table.x, clampedY, table.width, cell.height);
21
+ }
22
+ return new DOMRect(table.x, cell.y, table.width, cell.height);
23
+ }
24
+
25
+ /**
26
+ * Creates a DOMRect for column handle positioning
27
+ * Reference is positioned at table edge, aligned with cell
28
+ */
29
+ function makeColRect(cell, table, dragging) {
30
+ if ((dragging === null || dragging === void 0 ? void 0 : dragging.draggedCellOrientation) === 'col') {
31
+ var _dragging$initialOffs2;
32
+ // Apply the initial offset to maintain handle position
33
+ var adjustedX = dragging.mousePos + ((_dragging$initialOffs2 = dragging.initialOffset) !== null && _dragging$initialOffs2 !== void 0 ? _dragging$initialOffs2 : 0);
34
+ var clampedX = clamp(adjustedX, table.x, table.right - cell.width);
35
+ return new DOMRect(clampedX, table.y, cell.width, table.height);
36
+ }
37
+ return new DOMRect(cell.x, table.y, cell.width, table.height);
38
+ }
39
+
40
+ /**
41
+ * Creates a DOMRect for cell handle positioning
42
+ */
43
+ function makeCellRect(cell) {
44
+ return new DOMRect(cell.x, cell.y, cell.width, 0);
45
+ }
46
+
47
+ /**
48
+ * Gets the placement configuration for different handle orientations
49
+ */
50
+ function getPlacement(orientation) {
51
+ switch (orientation) {
52
+ case 'row':
53
+ return 'left';
54
+ case 'col':
55
+ return 'top';
56
+ case 'cell':
57
+ default:
58
+ return 'bottom-end';
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Gets the offset configuration for different handle orientations
64
+ */
65
+ function getOffset(orientation) {
66
+ switch (orientation) {
67
+ case 'row':
68
+ return 4;
69
+ case 'col':
70
+ return 4;
71
+ case 'cell':
72
+ default:
73
+ return {
74
+ mainAxis: 1,
75
+ crossAxis: -1
76
+ };
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Factory function to create DOMRect based on orientation
82
+ */
83
+ function rectFactory(orientation, cell, table, dragging) {
84
+ switch (orientation) {
85
+ case 'row':
86
+ return makeRowRect(cell, table, dragging);
87
+ case 'col':
88
+ return makeColRect(cell, table, dragging);
89
+ case 'cell':
90
+ default:
91
+ return makeCellRect(cell);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Hook for positioning individual table handles using Floating UI React
97
+ */
98
+ export function useTableHandlePosition(orientation, show, referencePosCell, referencePosTable, draggingState) {
99
+ var placement = useMemo(function () {
100
+ return getPlacement(orientation);
101
+ }, [orientation]);
102
+ var offsetValue = useMemo(function () {
103
+ return getOffset(orientation);
104
+ }, [orientation]);
105
+ var _useFloating = useFloating({
106
+ open: show,
107
+ placement: placement,
108
+ middleware: [offset(offsetValue), size({
109
+ apply: function apply(_ref) {
110
+ var _ref2, _referencePosCell$wid, _ref3, _referencePosCell$hei;
111
+ var rects = _ref.rects,
112
+ elements = _ref.elements;
113
+ if (!elements.floating) return;
114
+ var refWidth = (_ref2 = orientation === 'col' ? (_referencePosCell$wid = referencePosCell === null || referencePosCell === void 0 ? void 0 : referencePosCell.width) !== null && _referencePosCell$wid !== void 0 ? _referencePosCell$wid : referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.width : referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.width) !== null && _ref2 !== void 0 ? _ref2 : rects.reference.width;
115
+ var refHeight = (_ref3 = orientation === 'row' ? (_referencePosCell$hei = referencePosCell === null || referencePosCell === void 0 ? void 0 : referencePosCell.height) !== null && _referencePosCell$hei !== void 0 ? _referencePosCell$hei : referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.height : referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.height) !== null && _ref3 !== void 0 ? _ref3 : rects.reference.height;
116
+
117
+ // Set CSS custom properties for styling
118
+ elements.floating.style.setProperty('--table-handle-ref-width', "".concat(refWidth, "px"));
119
+ elements.floating.style.setProperty('--table-handle-ref-height', "".concat(refHeight, "px"));
120
+
121
+ // Set the main size dimension based on orientation
122
+ var mainSize = orientation === 'row' ? refHeight : refWidth;
123
+ elements.floating.style.setProperty('--table-handle-available-size', "".concat(mainSize, "px"));
124
+ }
125
+ })]
126
+ }),
127
+ refs = _useFloating.refs,
128
+ update = _useFloating.update,
129
+ context = _useFloating.context,
130
+ floatingStyles = _useFloating.floatingStyles;
131
+ var _useTransitionStyles = useTransitionStyles(context),
132
+ isMounted = _useTransitionStyles.isMounted,
133
+ styles = _useTransitionStyles.styles;
134
+
135
+ // Provide a virtual reference rect to Floating UI
136
+ // Use a function that always returns the latest values to ensure autoUpdate works correctly
137
+ useEffect(function () {
138
+ // Nothing to reference yet
139
+ if (!referencePosCell || !referencePosTable) {
140
+ refs.setReference(null);
141
+ return;
142
+ }
143
+
144
+ // Ignore cell handle while dragging (matches original behavior)
145
+ if (draggingState && orientation === 'cell') {
146
+ refs.setReference(null);
147
+ return;
148
+ }
149
+
150
+ // Create a virtual element that always returns the latest rect values
151
+ // This ensures autoUpdate can detect changes when scrolling
152
+ refs.setReference({
153
+ getBoundingClientRect: function getBoundingClientRect() {
154
+ // Always use the latest values from closure
155
+ if (!referencePosCell || !referencePosTable) {
156
+ return new DOMRect();
157
+ }
158
+ return rectFactory(orientation, referencePosCell, referencePosTable, draggingState);
159
+ }
160
+ });
161
+ }, [refs, orientation, referencePosCell, referencePosTable, draggingState]);
162
+
163
+ // Update position when reference positions change
164
+ useEffect(function () {
165
+ if (!show || !referencePosCell || !referencePosTable) return;
166
+ update();
167
+ }, [update, show, orientation, referencePosCell, referencePosTable, draggingState]);
168
+ return useMemo(function () {
169
+ return {
170
+ isMounted: isMounted,
171
+ ref: refs.setFloating,
172
+ style: _objectSpread(_objectSpread({
173
+ display: 'flex'
174
+ }, styles), floatingStyles)
175
+ };
176
+ }, [isMounted, refs.setFloating, styles, floatingStyles]);
177
+ }
178
+
179
+ /**
180
+ * Hook for managing positioning of all table handles (row, column, and cell)
181
+ */
182
+ export function useTableHandlePositioning(show, referencePosCell, referencePosTable, draggingState) {
183
+ var rowHandle = useTableHandlePosition('row', show, referencePosCell, referencePosTable, draggingState);
184
+ var colHandle = useTableHandlePosition('col', show, referencePosCell, referencePosTable, draggingState);
185
+ var cellHandle = useTableHandlePosition('cell', show, referencePosCell, referencePosTable, draggingState);
186
+ return useMemo(function () {
187
+ return {
188
+ rowHandle: rowHandle,
189
+ colHandle: colHandle,
190
+ cellHandle: cellHandle
191
+ };
192
+ }, [rowHandle, colHandle, cellHandle]);
193
+ }
@@ -0,0 +1,22 @@
1
+ import type { Editor } from '@tiptap/react';
2
+ import type { TableHandlesState } from '../../node/TableHandler/plugin';
3
+ export interface UseTableHandleStateConfig {
4
+ /**
5
+ * The Tiptap editor instance. If omitted, the hook will use
6
+ * the context/editor from `useTiptapEditor`.
7
+ */
8
+ editor?: Editor | null;
9
+ /**
10
+ * Initial state of the table handles
11
+ */
12
+ initialState?: TableHandlesState | null;
13
+ /**
14
+ * Only update state when specific fields change
15
+ */
16
+ watchFields?: (keyof TableHandlesState)[];
17
+ /**
18
+ * Callback when state changes
19
+ */
20
+ onStateChange?: (state: TableHandlesState | null) => void;
21
+ }
22
+ export declare function useTableHandleState(config?: UseTableHandleStateConfig): TableHandlesState | null;
@@ -0,0 +1,45 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useState, useCallback, useRef } from 'react';
8
+ export function useTableHandleState() {
9
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10
+ var providedEditor = config.editor,
11
+ _config$initialState = config.initialState,
12
+ initialState = _config$initialState === void 0 ? null : _config$initialState,
13
+ watchFields = config.watchFields,
14
+ onStateChange = config.onStateChange;
15
+ var editor = providedEditor;
16
+ var _useState = useState(initialState),
17
+ _useState2 = _slicedToArray(_useState, 2),
18
+ state = _useState2[0],
19
+ setState = _useState2[1];
20
+ var prevStateRef = useRef(initialState);
21
+ var updateState = useCallback(function (newState) {
22
+ if (watchFields && prevStateRef.current) {
23
+ var shouldUpdate = watchFields.some(function (field) {
24
+ return prevStateRef.current[field] !== newState[field];
25
+ });
26
+ if (!shouldUpdate) return;
27
+ }
28
+ setState(newState);
29
+ prevStateRef.current = newState;
30
+ onStateChange === null || onStateChange === void 0 || onStateChange(newState);
31
+ }, [watchFields, onStateChange]);
32
+ useEffect(function () {
33
+ if (!editor) {
34
+ setState(null);
35
+ prevStateRef.current = null;
36
+ onStateChange === null || onStateChange === void 0 || onStateChange(null);
37
+ return;
38
+ }
39
+ editor.on('tableHandleState', updateState);
40
+ return function () {
41
+ editor.off('tableHandleState', updateState);
42
+ };
43
+ }, [editor, onStateChange, updateState]);
44
+ return state;
45
+ }
@@ -0,0 +1,16 @@
1
+ import type { Editor } from '@tiptap/react';
2
+ import React from 'react';
3
+ export interface TableSelectionOverlayProps {
4
+ editor?: Editor | null;
5
+ cellMenu?: React.ComponentType<{
6
+ onOpenChange?: (isOpen: boolean) => void;
7
+ editor?: Editor | null;
8
+ onResizeStart?: (handle: ResizeHandle) => (event: React.MouseEvent) => void;
9
+ }>;
10
+ showResizeHandles?: boolean;
11
+ onMenuOpenChange?: (isOpen: boolean) => void;
12
+ }
13
+ type ResizeHandle = 'tl' | 'tr' | 'bl' | 'br' | null;
14
+ export declare function useResizeOverlay(editor: Editor | null, updateSelectionRect: () => void): void;
15
+ export declare const TableSelectionOverlay: React.FC<TableSelectionOverlayProps>;
16
+ export {};