@ctzhian/tiptap 1.13.8 → 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.
- package/dist/Editor/demo.js +3 -5
- package/dist/Editor/index.js +17 -0
- package/dist/component/CustomBubbleMenu/index.js +1 -1
- package/dist/component/CustomDragHandle/index.js +3 -59
- package/dist/component/Icons/delete-back-2-line-icon.d.ts +6 -0
- package/dist/component/Icons/delete-back-2-line-icon.js +13 -0
- package/dist/component/Menu/index.js +5 -1
- package/dist/contants/enums.d.ts +9 -0
- package/dist/contants/enums.js +61 -1
- package/dist/extension/component/Link/Insert.js +1 -1
- package/dist/extension/component/TableCellHandleMenu/index.d.ts +9 -0
- package/dist/extension/component/TableCellHandleMenu/index.js +443 -0
- package/dist/extension/component/TableExtendButton/TableExtendButton.css +30 -0
- package/dist/extension/component/TableExtendButton/index.d.ts +23 -0
- package/dist/extension/component/TableExtendButton/index.js +201 -0
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.d.ts +15 -0
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.js +87 -0
- package/dist/extension/component/TableHandle/TableHandleMenu.css +36 -0
- package/dist/extension/component/TableHandle/TableHandleMenu.d.ts +17 -0
- package/dist/extension/component/TableHandle/TableHandleMenu.js +685 -0
- package/dist/extension/component/TableHandle/index.d.ts +28 -0
- package/dist/extension/component/TableHandle/index.js +93 -0
- package/dist/extension/component/TableHandle/use-table-handle-positioning.d.ts +40 -0
- package/dist/extension/component/TableHandle/use-table-handle-positioning.js +193 -0
- package/dist/extension/component/TableHandle/use-table-handle-state.d.ts +22 -0
- package/dist/extension/component/TableHandle/use-table-handle-state.js +45 -0
- package/dist/extension/component/TableSelectionOverlay/index.d.ts +16 -0
- package/dist/extension/component/TableSelectionOverlay/index.js +460 -0
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/Link/index.js +4 -4
- package/dist/extension/node/Table.js +226 -43
- package/dist/extension/node/TableHandler/create-image.d.ts +9 -0
- package/dist/extension/node/TableHandler/create-image.js +235 -0
- package/dist/extension/node/TableHandler/index.d.ts +15 -0
- package/dist/extension/node/TableHandler/index.js +33 -0
- package/dist/extension/node/TableHandler/plugin.d.ts +49 -0
- package/dist/extension/node/TableHandler/plugin.js +1030 -0
- package/dist/index.css +29 -10
- package/dist/type/index.d.ts +2 -0
- package/dist/util/table-utils.d.ts +161 -0
- package/dist/util/table-utils.js +605 -0
- package/package.json +34 -33
- package/dist/extension/component/Table/ContextMenu.d.ts +0 -11
- package/dist/extension/component/Table/ContextMenu.js +0 -186
- package/dist/extension/component/Table/TableContextMenuPlugin.d.ts +0 -9
- package/dist/extension/component/Table/TableContextMenuPlugin.js +0 -336
- package/dist/extension/component/Table/index.d.ts +0 -2
- package/dist/extension/component/Table/index.js +0 -2
|
@@ -0,0 +1,460 @@
|
|
|
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
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."); }
|
|
4
|
+
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); }
|
|
5
|
+
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; }
|
|
6
|
+
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; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
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); }
|
|
13
|
+
import { FloatingPortal, useFloating } from '@floating-ui/react';
|
|
14
|
+
import { CellSelection, cellAround, columnResizingPluginKey } from '@tiptap/pm/tables';
|
|
15
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
16
|
+
import { domCellAround, getTable, rectEq } from "../../../util/table-utils";
|
|
17
|
+
|
|
18
|
+
// tl = top-left
|
|
19
|
+
// tr = top-right
|
|
20
|
+
// bl = bottom-left
|
|
21
|
+
// br = bottom-right
|
|
22
|
+
|
|
23
|
+
// if an element's edge is within 5px of the selection edge,
|
|
24
|
+
// it is treated as aligned.
|
|
25
|
+
var CORNER_DETECTION_TOLERANCE = 5;
|
|
26
|
+
var getCellAtCoordinates = function getCellAtCoordinates(state, view, x, y) {
|
|
27
|
+
var _view$posAtCoords;
|
|
28
|
+
var pos = (_view$posAtCoords = view.posAtCoords({
|
|
29
|
+
left: x,
|
|
30
|
+
top: y
|
|
31
|
+
})) === null || _view$posAtCoords === void 0 ? void 0 : _view$posAtCoords.pos;
|
|
32
|
+
if (pos == null) return null;
|
|
33
|
+
var $pos = state.doc.resolve(pos);
|
|
34
|
+
return cellAround($pos);
|
|
35
|
+
};
|
|
36
|
+
var getSelectionBoundingRect = function getSelectionBoundingRect(view, selection) {
|
|
37
|
+
var cells = [];
|
|
38
|
+
selection.forEachCell(function (_node, pos) {
|
|
39
|
+
var dom = view.nodeDOM(pos);
|
|
40
|
+
if (dom) cells.push(dom);
|
|
41
|
+
});
|
|
42
|
+
if (cells.length === 0) return null;
|
|
43
|
+
var bounds = {
|
|
44
|
+
left: Infinity,
|
|
45
|
+
top: Infinity,
|
|
46
|
+
right: -Infinity,
|
|
47
|
+
bottom: -Infinity
|
|
48
|
+
};
|
|
49
|
+
cells.forEach(function (cell) {
|
|
50
|
+
var rect = cell.getBoundingClientRect();
|
|
51
|
+
bounds.left = Math.min(bounds.left, rect.left);
|
|
52
|
+
bounds.top = Math.min(bounds.top, rect.top);
|
|
53
|
+
bounds.right = Math.max(bounds.right, rect.right);
|
|
54
|
+
bounds.bottom = Math.max(bounds.bottom, rect.bottom);
|
|
55
|
+
});
|
|
56
|
+
return new DOMRect(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
|
|
57
|
+
};
|
|
58
|
+
var getSingleCellBoundingRect = function getSingleCellBoundingRect(view, cellPos) {
|
|
59
|
+
var cellDom = view.nodeDOM(cellPos);
|
|
60
|
+
if (!cellDom) return null;
|
|
61
|
+
var rect = cellDom.getBoundingClientRect();
|
|
62
|
+
return new DOMRect(rect.left, rect.top, rect.width, rect.height);
|
|
63
|
+
};
|
|
64
|
+
var createVirtualReference = function createVirtualReference(rect) {
|
|
65
|
+
return {
|
|
66
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
67
|
+
return rect;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var findCornerCells = function findCornerCells(view, selection, selectionRect) {
|
|
72
|
+
var corners = {
|
|
73
|
+
topLeft: null,
|
|
74
|
+
topRight: null,
|
|
75
|
+
bottomLeft: null,
|
|
76
|
+
bottomRight: null
|
|
77
|
+
};
|
|
78
|
+
var isNearEdge = function isNearEdge(value1, value2) {
|
|
79
|
+
return Math.abs(value1 - value2) < CORNER_DETECTION_TOLERANCE;
|
|
80
|
+
};
|
|
81
|
+
selection.forEachCell(function (_node, pos) {
|
|
82
|
+
var dom = view.nodeDOM(pos);
|
|
83
|
+
if (!dom) return;
|
|
84
|
+
var cellRect = dom.getBoundingClientRect();
|
|
85
|
+
|
|
86
|
+
// Top-left corner
|
|
87
|
+
if (isNearEdge(cellRect.left, selectionRect.left) && isNearEdge(cellRect.top, selectionRect.top)) {
|
|
88
|
+
corners.topLeft = pos;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Top-right corner
|
|
92
|
+
if (isNearEdge(cellRect.right, selectionRect.right) && isNearEdge(cellRect.top, selectionRect.top)) {
|
|
93
|
+
corners.topRight = pos;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Bottom-left corner
|
|
97
|
+
if (isNearEdge(cellRect.left, selectionRect.left) && isNearEdge(cellRect.bottom, selectionRect.bottom)) {
|
|
98
|
+
corners.bottomLeft = pos;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Bottom-right corner
|
|
102
|
+
if (isNearEdge(cellRect.right, selectionRect.right) && isNearEdge(cellRect.bottom, selectionRect.bottom)) {
|
|
103
|
+
corners.bottomRight = pos;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return corners;
|
|
107
|
+
};
|
|
108
|
+
var getAnchorCellForHandle = function getAnchorCellForHandle(view, selection, selectionRect, handle) {
|
|
109
|
+
if (!handle) return null;
|
|
110
|
+
var corners = findCornerCells(view, selection, selectionRect);
|
|
111
|
+
var anchorMap = {
|
|
112
|
+
tl: 'bottomRight',
|
|
113
|
+
tr: 'bottomLeft',
|
|
114
|
+
bl: 'topRight',
|
|
115
|
+
br: 'topLeft'
|
|
116
|
+
};
|
|
117
|
+
var anchorPos = corners[anchorMap[handle]];
|
|
118
|
+
return anchorPos ? {
|
|
119
|
+
pos: anchorPos
|
|
120
|
+
} : null;
|
|
121
|
+
};
|
|
122
|
+
var createHandleStyles = function createHandleStyles() {
|
|
123
|
+
return {
|
|
124
|
+
position: 'absolute',
|
|
125
|
+
width: 15,
|
|
126
|
+
height: 15,
|
|
127
|
+
borderRadius: '50%',
|
|
128
|
+
display: 'flex',
|
|
129
|
+
alignItems: 'center',
|
|
130
|
+
justifyContent: 'center',
|
|
131
|
+
background: 'transparent',
|
|
132
|
+
pointerEvents: 'auto',
|
|
133
|
+
zIndex: 10
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
var createCornerHandleStyles = function createCornerHandleStyles(position, isActiveHandle) {
|
|
137
|
+
var isDisabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
138
|
+
var baseStyles = createHandleStyles();
|
|
139
|
+
var positionStyles = {
|
|
140
|
+
tl: {
|
|
141
|
+
top: -7.5,
|
|
142
|
+
left: -7.5,
|
|
143
|
+
cursor: isDisabled ? 'default' : 'nwse-resize'
|
|
144
|
+
},
|
|
145
|
+
tr: {
|
|
146
|
+
top: -7.5,
|
|
147
|
+
right: -7.5,
|
|
148
|
+
cursor: isDisabled ? 'default' : 'nesw-resize'
|
|
149
|
+
},
|
|
150
|
+
bl: {
|
|
151
|
+
bottom: -7.5,
|
|
152
|
+
left: -7.5,
|
|
153
|
+
cursor: isDisabled ? 'default' : 'nesw-resize'
|
|
154
|
+
},
|
|
155
|
+
br: {
|
|
156
|
+
bottom: -7.5,
|
|
157
|
+
right: -7.5,
|
|
158
|
+
cursor: isDisabled ? 'default' : 'nwse-resize'
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return _objectSpread(_objectSpread(_objectSpread({}, baseStyles), positionStyles[position]), {}, {
|
|
162
|
+
opacity: isDisabled ? 0.3 : isActiveHandle ? 1 : 0.5,
|
|
163
|
+
pointerEvents: isDisabled ? 'none' : 'auto'
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
export function useResizeOverlay(editor, updateSelectionRect) {
|
|
167
|
+
var rafId = useRef(null);
|
|
168
|
+
var stopLoop = useCallback(function () {
|
|
169
|
+
if (rafId.current != null) {
|
|
170
|
+
cancelAnimationFrame(rafId.current);
|
|
171
|
+
rafId.current = null;
|
|
172
|
+
}
|
|
173
|
+
}, []);
|
|
174
|
+
var startLoop = useCallback(function () {
|
|
175
|
+
if (rafId.current != null) return;
|
|
176
|
+
var tick = function tick() {
|
|
177
|
+
var st = columnResizingPluginKey.getState(editor.state);
|
|
178
|
+
var dragging = !!(st !== null && st !== void 0 && st.dragging);
|
|
179
|
+
updateSelectionRect();
|
|
180
|
+
if (dragging) {
|
|
181
|
+
rafId.current = requestAnimationFrame(tick);
|
|
182
|
+
} else {
|
|
183
|
+
stopLoop();
|
|
184
|
+
updateSelectionRect();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
rafId.current = requestAnimationFrame(tick);
|
|
188
|
+
}, [editor, updateSelectionRect, stopLoop]);
|
|
189
|
+
useEffect(function () {
|
|
190
|
+
if (!editor) return;
|
|
191
|
+
var onTx = function onTx(_ref) {
|
|
192
|
+
var transaction = _ref.transaction;
|
|
193
|
+
updateSelectionRect();
|
|
194
|
+
var meta = transaction.getMeta(columnResizingPluginKey);
|
|
195
|
+
if (!meta) return;
|
|
196
|
+
if (Object.prototype.hasOwnProperty.call(meta, 'setDragging') && meta.setDragging) {
|
|
197
|
+
startLoop();
|
|
198
|
+
}
|
|
199
|
+
if (Object.prototype.hasOwnProperty.call(meta, 'setDragging') && meta.setDragging == null) {
|
|
200
|
+
stopLoop();
|
|
201
|
+
updateSelectionRect();
|
|
202
|
+
}
|
|
203
|
+
if (Object.prototype.hasOwnProperty.call(meta, 'setHandle')) {
|
|
204
|
+
updateSelectionRect();
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
editor.on('transaction', onTx);
|
|
208
|
+
return function () {
|
|
209
|
+
editor.off('transaction', onTx);
|
|
210
|
+
stopLoop();
|
|
211
|
+
};
|
|
212
|
+
}, [editor, startLoop, stopLoop, updateSelectionRect]);
|
|
213
|
+
}
|
|
214
|
+
export var TableSelectionOverlay = function TableSelectionOverlay(_ref2) {
|
|
215
|
+
var providedEditor = _ref2.editor,
|
|
216
|
+
CellMenu = _ref2.cellMenu,
|
|
217
|
+
_ref2$showResizeHandl = _ref2.showResizeHandles,
|
|
218
|
+
showResizeHandles = _ref2$showResizeHandl === void 0 ? true : _ref2$showResizeHandl,
|
|
219
|
+
onMenuOpenChange = _ref2.onMenuOpenChange;
|
|
220
|
+
var editor = providedEditor;
|
|
221
|
+
var _useState = useState(false),
|
|
222
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
223
|
+
isVisible = _useState2[0],
|
|
224
|
+
setIsVisible = _useState2[1];
|
|
225
|
+
var _useState3 = useState(null),
|
|
226
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
227
|
+
selectionRect = _useState4[0],
|
|
228
|
+
setSelectionRect = _useState4[1];
|
|
229
|
+
var _useState5 = useState(null),
|
|
230
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
231
|
+
activeHandle = _useState6[0],
|
|
232
|
+
setActiveHandle = _useState6[1];
|
|
233
|
+
var _useState7 = useState(null),
|
|
234
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
235
|
+
tableDom = _useState8[0],
|
|
236
|
+
setTableDom = _useState8[1];
|
|
237
|
+
var _useState9 = useState(false),
|
|
238
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
239
|
+
isMenuOpen = _useState10[0],
|
|
240
|
+
setIsMenuOpen = _useState10[1];
|
|
241
|
+
var anchorCellRef = useRef(null);
|
|
242
|
+
var activeHandleRef = useRef(null);
|
|
243
|
+
var containerRef = useRef(null);
|
|
244
|
+
var _useFloating = useFloating({
|
|
245
|
+
placement: 'top-start',
|
|
246
|
+
strategy: 'absolute'
|
|
247
|
+
}),
|
|
248
|
+
refs = _useFloating.refs,
|
|
249
|
+
floatingStyles = _useFloating.floatingStyles,
|
|
250
|
+
update = _useFloating.update;
|
|
251
|
+
useEffect(function () {
|
|
252
|
+
if (selectionRect) {
|
|
253
|
+
var virtualReference = createVirtualReference(selectionRect);
|
|
254
|
+
refs.setPositionReference(virtualReference);
|
|
255
|
+
}
|
|
256
|
+
}, [selectionRect, refs]);
|
|
257
|
+
var updateSelectionRect = useCallback(function () {
|
|
258
|
+
if (!editor) return;
|
|
259
|
+
var selection = editor.state.selection;
|
|
260
|
+
if (selection instanceof CellSelection) {
|
|
261
|
+
var rect = getSelectionBoundingRect(editor.view, selection);
|
|
262
|
+
if (!rect) {
|
|
263
|
+
setIsVisible(false);
|
|
264
|
+
setSelectionRect(function (prev) {
|
|
265
|
+
return prev ? null : prev;
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
setSelectionRect(function (prev) {
|
|
270
|
+
return rectEq(prev, rect) ? prev : rect;
|
|
271
|
+
});
|
|
272
|
+
setIsVisible(true);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// single cell handling
|
|
277
|
+
var $anchor = selection.$anchor;
|
|
278
|
+
var cell = cellAround($anchor);
|
|
279
|
+
if (cell) {
|
|
280
|
+
var _rect = getSingleCellBoundingRect(editor.view, cell.pos);
|
|
281
|
+
if (_rect) {
|
|
282
|
+
setSelectionRect(function (prev) {
|
|
283
|
+
return rectEq(prev, _rect) ? prev : _rect;
|
|
284
|
+
});
|
|
285
|
+
setIsVisible(true);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
setIsVisible(false);
|
|
290
|
+
setSelectionRect(function (prev) {
|
|
291
|
+
return prev ? null : prev;
|
|
292
|
+
});
|
|
293
|
+
}, [editor]);
|
|
294
|
+
useResizeOverlay(editor !== null && editor !== void 0 ? editor : null, updateSelectionRect);
|
|
295
|
+
useEffect(function () {
|
|
296
|
+
if (update && selectionRect) {
|
|
297
|
+
update();
|
|
298
|
+
}
|
|
299
|
+
}, [update, selectionRect]);
|
|
300
|
+
var createResizeHandler = useCallback(function (handle) {
|
|
301
|
+
return function (event) {
|
|
302
|
+
if (!editor || !handle || !selectionRect || isMenuOpen || !showResizeHandles) return;
|
|
303
|
+
event.preventDefault();
|
|
304
|
+
event.stopPropagation();
|
|
305
|
+
var selection = editor.state.selection;
|
|
306
|
+
var cellSelection = null;
|
|
307
|
+
if (selection instanceof CellSelection) {
|
|
308
|
+
cellSelection = selection;
|
|
309
|
+
} else {
|
|
310
|
+
var $anchor = selection.$anchor;
|
|
311
|
+
var cell = cellAround($anchor);
|
|
312
|
+
if (cell) {
|
|
313
|
+
try {
|
|
314
|
+
cellSelection = CellSelection.create(editor.state.doc, cell.pos, cell.pos);
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.warn('Could not create single cell selection for resize:', error);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!cellSelection) return;
|
|
322
|
+
var anchorCell = getAnchorCellForHandle(editor.view, cellSelection, selectionRect, handle);
|
|
323
|
+
if (!anchorCell) return;
|
|
324
|
+
setActiveHandle(handle);
|
|
325
|
+
activeHandleRef.current = handle;
|
|
326
|
+
anchorCellRef.current = anchorCell.pos;
|
|
327
|
+
var handleMouseMove = function handleMouseMove(mouseEvent) {
|
|
328
|
+
if (!editor || anchorCellRef.current == null) return;
|
|
329
|
+
var target = domCellAround(mouseEvent.target);
|
|
330
|
+
if (!target || target.type !== 'cell') return;
|
|
331
|
+
var targetCell = getCellAtCoordinates(editor.state, editor.view, mouseEvent.clientX, mouseEvent.clientY);
|
|
332
|
+
if (!targetCell) return;
|
|
333
|
+
try {
|
|
334
|
+
var newSelection = CellSelection.create(editor.state.doc, anchorCellRef.current, targetCell.pos);
|
|
335
|
+
var transaction = editor.state.tr.setSelection(newSelection);
|
|
336
|
+
editor.view.dispatch(transaction);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
console.debug('Invalid cell selection during resize:', error);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
var handleMouseUp = function handleMouseUp() {
|
|
342
|
+
setActiveHandle(null);
|
|
343
|
+
activeHandleRef.current = null;
|
|
344
|
+
anchorCellRef.current = null;
|
|
345
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
346
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
347
|
+
};
|
|
348
|
+
window.addEventListener('mousemove', handleMouseMove);
|
|
349
|
+
window.addEventListener('mouseup', handleMouseUp);
|
|
350
|
+
};
|
|
351
|
+
}, [editor, selectionRect, isMenuOpen, showResizeHandles]);
|
|
352
|
+
var updateTableDom = useCallback(function () {
|
|
353
|
+
if (!editor) {
|
|
354
|
+
setTableDom(null);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
var table = getTable(editor);
|
|
358
|
+
if (!table) {
|
|
359
|
+
setTableDom(null);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
setTableDom(function (prev) {
|
|
363
|
+
var currentDom = prev;
|
|
364
|
+
var newDom = editor.view.nodeDOM(table.pos);
|
|
365
|
+
return currentDom === newDom ? currentDom : newDom;
|
|
366
|
+
});
|
|
367
|
+
}, [editor]);
|
|
368
|
+
var handleMenuOpenChange = useCallback(function (isOpen) {
|
|
369
|
+
setIsMenuOpen(isOpen);
|
|
370
|
+
onMenuOpenChange === null || onMenuOpenChange === void 0 || onMenuOpenChange(isOpen);
|
|
371
|
+
}, [onMenuOpenChange]);
|
|
372
|
+
useEffect(function () {
|
|
373
|
+
if (!editor) return;
|
|
374
|
+
var handleSelectionUpdate = function handleSelectionUpdate() {
|
|
375
|
+
updateSelectionRect();
|
|
376
|
+
updateTableDom();
|
|
377
|
+
};
|
|
378
|
+
editor.on('selectionUpdate', handleSelectionUpdate);
|
|
379
|
+
updateSelectionRect();
|
|
380
|
+
updateTableDom();
|
|
381
|
+
return function () {
|
|
382
|
+
editor.off('selectionUpdate', handleSelectionUpdate);
|
|
383
|
+
};
|
|
384
|
+
}, [editor, updateSelectionRect, updateTableDom]);
|
|
385
|
+
useEffect(function () {
|
|
386
|
+
var c = tableDom === null || tableDom === void 0 ? void 0 : tableDom.querySelector('.table-selection-overlay-container');
|
|
387
|
+
if (!c) {
|
|
388
|
+
// Try to find .table-controls as fallback
|
|
389
|
+
var wrapper = tableDom === null || tableDom === void 0 ? void 0 : tableDom.closest('.tableWrapper');
|
|
390
|
+
var controls = wrapper === null || wrapper === void 0 ? void 0 : wrapper.querySelector('.table-controls');
|
|
391
|
+
containerRef.current = controls !== null && controls !== void 0 ? controls : null;
|
|
392
|
+
} else {
|
|
393
|
+
containerRef.current = c;
|
|
394
|
+
}
|
|
395
|
+
}, [tableDom]);
|
|
396
|
+
if (!isVisible || !selectionRect) {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
if (!editor) return null;
|
|
400
|
+
var renderCellMenu = function renderCellMenu() {
|
|
401
|
+
if (!CellMenu) return null;
|
|
402
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
403
|
+
onMouseDown: function onMouseDown(e) {
|
|
404
|
+
return e.stopPropagation();
|
|
405
|
+
},
|
|
406
|
+
style: {
|
|
407
|
+
pointerEvents: 'auto'
|
|
408
|
+
}
|
|
409
|
+
}, /*#__PURE__*/React.createElement(CellMenu, {
|
|
410
|
+
onOpenChange: handleMenuOpenChange,
|
|
411
|
+
editor: editor,
|
|
412
|
+
onResizeStart: createResizeHandler
|
|
413
|
+
}));
|
|
414
|
+
};
|
|
415
|
+
var rootElement = containerRef.current || document.body;
|
|
416
|
+
return /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
417
|
+
root: rootElement
|
|
418
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
419
|
+
ref: refs.setFloating,
|
|
420
|
+
style: _objectSpread(_objectSpread({}, floatingStyles), {}, {
|
|
421
|
+
pointerEvents: 'none',
|
|
422
|
+
zIndex: 10
|
|
423
|
+
})
|
|
424
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
425
|
+
className: "tiptap-table-selection-overlay"
|
|
426
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
427
|
+
style: {
|
|
428
|
+
position: 'absolute',
|
|
429
|
+
width: selectionRect.width,
|
|
430
|
+
height: selectionRect.height,
|
|
431
|
+
zIndex: 2,
|
|
432
|
+
borderRadius: 2,
|
|
433
|
+
top: 0,
|
|
434
|
+
left: 0
|
|
435
|
+
}
|
|
436
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
437
|
+
style: {
|
|
438
|
+
position: 'absolute',
|
|
439
|
+
width: selectionRect.width,
|
|
440
|
+
height: selectionRect.height,
|
|
441
|
+
border: "2px solid var(--mui-palette-primary-main)",
|
|
442
|
+
borderRadius: 2,
|
|
443
|
+
zIndex: 3,
|
|
444
|
+
top: 0,
|
|
445
|
+
left: 0
|
|
446
|
+
}
|
|
447
|
+
}, renderCellMenu(), showResizeHandles && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
448
|
+
style: createCornerHandleStyles('tl', !activeHandle || activeHandle === 'tl', isMenuOpen),
|
|
449
|
+
onMouseDown: createResizeHandler('tl')
|
|
450
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
451
|
+
style: createCornerHandleStyles('tr', !activeHandle || activeHandle === 'tr', isMenuOpen),
|
|
452
|
+
onMouseDown: createResizeHandler('tr')
|
|
453
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
454
|
+
style: createCornerHandleStyles('bl', !activeHandle || activeHandle === 'bl', isMenuOpen),
|
|
455
|
+
onMouseDown: createResizeHandler('bl')
|
|
456
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
457
|
+
style: createCornerHandleStyles('br', !activeHandle || activeHandle === 'br', isMenuOpen),
|
|
458
|
+
onMouseDown: createResizeHandler('br')
|
|
459
|
+
}))))));
|
|
460
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UploadFunction } from "../../type";
|
|
2
2
|
export declare const FileHandlerExtension: (props: {
|
|
3
3
|
onUpload?: UploadFunction;
|
|
4
|
-
}) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "
|
|
4
|
+
}) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "key" | "editor">, any>;
|
|
@@ -372,15 +372,15 @@ export var InlineLinkExtension = Node.create({
|
|
|
372
372
|
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
373
373
|
return helpers.createNode('inlineLink', {
|
|
374
374
|
href: token.href || '',
|
|
375
|
-
title: token.
|
|
375
|
+
title: token.text || '',
|
|
376
376
|
type: 'icon',
|
|
377
377
|
target: '_blank'
|
|
378
378
|
}, [helpers.createTextNode(token.text || '')]);
|
|
379
379
|
},
|
|
380
|
-
renderMarkdown: function renderMarkdown(node
|
|
381
|
-
var _node$attrs;
|
|
380
|
+
renderMarkdown: function renderMarkdown(node) {
|
|
381
|
+
var _node$attrs, _node$attrs2, _node$attrs3;
|
|
382
382
|
var href = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.href) || '';
|
|
383
|
-
var text =
|
|
383
|
+
var text = ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.title) || ((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.href) || '';
|
|
384
384
|
return "[".concat(text, "](").concat(href, ")");
|
|
385
385
|
},
|
|
386
386
|
addNodeView: function addNodeView() {
|