@ctzhian/tiptap 1.13.9 → 2.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/Editor/demo.js +133 -123
- package/dist/Editor/index.js +17 -0
- package/dist/EditorToolbar/index.js +11 -9
- package/dist/asset/css/index.css +5 -7
- package/dist/component/ActionDropdown/index.d.ts +5 -0
- package/dist/component/ActionDropdown/index.js +8 -3
- package/dist/component/CustomBubbleMenu/index.js +1 -1
- package/dist/component/CustomDragHandle/index.js +3 -59
- package/dist/component/FloatingPopover/index.d.ts +2 -2
- package/dist/component/HoverPopover/index.d.ts +2 -0
- package/dist/component/HoverPopover/index.js +22 -3
- 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/Icons/{expand-horizontal-line.js → expand-horizontal-line-icon.js} +1 -1
- package/dist/component/Icons/index.d.ts +3 -2
- package/dist/component/Icons/index.js +4 -3
- 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/Alert/index.js +141 -137
- package/dist/extension/component/Flow/Edit.d.ts +1 -1
- package/dist/extension/component/Flow/Edit.js +3 -31
- package/dist/extension/component/Flow/index.js +20 -19
- package/dist/extension/component/Image/index.d.ts +1 -0
- package/dist/extension/component/Image/index.js +16 -2
- package/dist/extension/component/Link/index.js +1 -1
- package/dist/extension/component/TableCellHandleMenu/index.d.ts +9 -0
- package/dist/extension/component/TableCellHandleMenu/index.js +500 -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 +452 -0
- package/dist/extension/component/Video/Insert.js +4 -2
- package/dist/extension/component/Video/Readonly.js +4 -11
- package/dist/extension/component/Video/index.d.ts +2 -1
- package/dist/extension/component/Video/index.js +447 -65
- package/dist/extension/extension/ImeComposition.d.ts +2 -0
- package/dist/extension/extension/ImeComposition.js +145 -0
- package/dist/extension/extension/index.d.ts +1 -0
- package/dist/extension/extension/index.js +1 -0
- package/dist/extension/index.js +2 -2
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/Flow/index.d.ts +0 -3
- package/dist/extension/node/Flow/index.js +7 -4
- package/dist/extension/node/Link/index.js +4 -3
- package/dist/extension/node/Table.js +236 -117
- 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/extension/node/TableOfContents/index.d.ts +5 -3
- package/dist/extension/node/TableOfContents/index.js +22 -2
- package/dist/extension/node/Video.d.ts +1 -0
- package/dist/extension/node/Video.js +38 -6
- package/dist/hook/index.js +1 -1
- package/dist/index.css +45 -29
- package/dist/type/index.d.ts +2 -0
- package/dist/util/index.d.ts +9 -0
- package/dist/util/index.js +26 -0
- package/dist/util/table-utils.d.ts +161 -0
- package/dist/util/table-utils.js +605 -0
- package/package.json +2 -1
- 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
- /package/dist/component/Icons/{expand-horizontal-line.d.ts → expand-horizontal-line-icon.d.ts} +0 -0
|
@@ -35,26 +35,26 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
35
35
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
36
36
|
isDragging = _useState6[0],
|
|
37
37
|
setIsDragging = _useState6[1];
|
|
38
|
-
var _useState7 = useState(
|
|
38
|
+
var _useState7 = useState(false),
|
|
39
39
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
keepHoverPopoverOpen = _useState8[0],
|
|
41
|
+
setKeepHoverPopoverOpen = _useState8[1];
|
|
42
|
+
var _useState9 = useState(null),
|
|
43
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
44
|
+
dragCorner = _useState10[0],
|
|
45
|
+
setDragCorner = _useState10[1];
|
|
42
46
|
var dragStartXRef = useRef(0);
|
|
43
47
|
var dragStartWidthRef = useRef(0);
|
|
44
48
|
var flowWrapperRef = useRef(null);
|
|
45
49
|
var flowContentRef = useRef(null);
|
|
46
|
-
|
|
47
|
-
// 获取当前实际显示的流程图宽度
|
|
50
|
+
var editButtonRef = useRef(null);
|
|
48
51
|
var getCurrentDisplayWidth = function getCurrentDisplayWidth() {
|
|
49
52
|
if (flowWrapperRef.current) {
|
|
50
53
|
return flowWrapperRef.current.offsetWidth;
|
|
51
54
|
}
|
|
52
|
-
// 如果 ref 不存在,使用容器宽度计算
|
|
53
55
|
var containerWidth = 800;
|
|
54
56
|
return getPixelValue(attrs.width, containerWidth);
|
|
55
57
|
};
|
|
56
|
-
|
|
57
|
-
// 将 width 转换为像素值
|
|
58
58
|
var getPixelValue = function getPixelValue(value, containerSize) {
|
|
59
59
|
var defaultPercent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
|
|
60
60
|
if (!value) return containerSize * (defaultPercent / 100);
|
|
@@ -81,7 +81,7 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
81
81
|
var percent = Math.round(pixels / containerWidth * 100);
|
|
82
82
|
return "".concat(percent, "%");
|
|
83
83
|
}
|
|
84
|
-
return Math.round(pixels);
|
|
84
|
+
return "".concat(Math.round(pixels), "px");
|
|
85
85
|
};
|
|
86
86
|
var handleMouseDown = function handleMouseDown(e, corner) {
|
|
87
87
|
e.preventDefault();
|
|
@@ -95,13 +95,9 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
95
95
|
if (!isDragging || !dragCorner) return;
|
|
96
96
|
var deltaX = e.clientX - dragStartXRef.current;
|
|
97
97
|
var newWidth;
|
|
98
|
-
|
|
99
|
-
// 根据不同的角计算宽度变化
|
|
100
98
|
if (dragCorner === 'top-right' || dragCorner === 'bottom-right') {
|
|
101
|
-
// 右侧角:向右拉伸,宽度增加
|
|
102
99
|
newWidth = dragStartWidthRef.current + deltaX;
|
|
103
100
|
} else {
|
|
104
|
-
// 左侧角:向左拉伸,宽度增加(deltaX 为负时宽度增加)
|
|
105
101
|
newWidth = dragStartWidthRef.current - deltaX;
|
|
106
102
|
}
|
|
107
103
|
newWidth = Math.max(200, Math.min(1920, newWidth));
|
|
@@ -125,7 +121,12 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
125
121
|
}
|
|
126
122
|
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
127
123
|
var handleShowPopover = function handleShowPopover() {
|
|
128
|
-
|
|
124
|
+
setKeepHoverPopoverOpen(true);
|
|
125
|
+
setIsEditing(true);
|
|
126
|
+
};
|
|
127
|
+
var handleEditCancel = function handleEditCancel() {
|
|
128
|
+
setIsEditing(false);
|
|
129
|
+
setKeepHoverPopoverOpen(false);
|
|
129
130
|
};
|
|
130
131
|
if (!editor.isEditable) {
|
|
131
132
|
return /*#__PURE__*/React.createElement(ReadonlyFlow, {
|
|
@@ -167,6 +168,7 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
167
168
|
style: {
|
|
168
169
|
width: '100%'
|
|
169
170
|
},
|
|
171
|
+
keepOpen: keepHoverPopoverOpen,
|
|
170
172
|
actions: /*#__PURE__*/React.createElement(Stack, {
|
|
171
173
|
direction: 'row',
|
|
172
174
|
alignItems: 'center',
|
|
@@ -174,6 +176,7 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
174
176
|
p: 0.5
|
|
175
177
|
}
|
|
176
178
|
}, /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
179
|
+
ref: editButtonRef,
|
|
177
180
|
icon: /*#__PURE__*/React.createElement(EditLineIcon, {
|
|
178
181
|
sx: {
|
|
179
182
|
fontSize: '1rem'
|
|
@@ -292,15 +295,13 @@ var FlowViewWrapper = function FlowViewWrapper(_ref) {
|
|
|
292
295
|
zIndex: 10
|
|
293
296
|
}
|
|
294
297
|
}))))), isEditing && /*#__PURE__*/React.createElement(EditFlow, {
|
|
295
|
-
anchorEl:
|
|
298
|
+
anchorEl: editButtonRef.current,
|
|
296
299
|
attrs: attrs,
|
|
297
300
|
updateAttributes: function updateAttributes(newAttrs) {
|
|
298
301
|
_updateAttributes(newAttrs);
|
|
299
|
-
|
|
302
|
+
handleEditCancel();
|
|
300
303
|
},
|
|
301
|
-
onCancel:
|
|
302
|
-
return setIsEditing(false);
|
|
303
|
-
}
|
|
304
|
+
onCancel: handleEditCancel
|
|
304
305
|
}));
|
|
305
306
|
};
|
|
306
307
|
var FlowDiagram = function FlowDiagram(_ref2) {
|
|
@@ -14,6 +14,8 @@ import { ToolbarItem } from "../../../component/Toolbar";
|
|
|
14
14
|
import { alpha, Box, Button, Divider, Stack, TextField, useTheme } from "@mui/material";
|
|
15
15
|
import { NodeViewWrapper } from "@tiptap/react";
|
|
16
16
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
17
|
+
import { PhotoView } from "react-photo-view";
|
|
18
|
+
import 'react-photo-view/dist/react-photo-view.css';
|
|
17
19
|
import { HoverPopover } from "../../../component/HoverPopover";
|
|
18
20
|
import CropImage from "./Crop";
|
|
19
21
|
import InsertImage from "./Insert";
|
|
@@ -157,6 +159,15 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
157
159
|
dragStartXRef.current = e.clientX;
|
|
158
160
|
dragStartWidthRef.current = getCurrentDisplayWidth();
|
|
159
161
|
};
|
|
162
|
+
var handleImageClick = function handleImageClick(e) {
|
|
163
|
+
// 如果正在拖拽调整大小,阻止预览
|
|
164
|
+
if (isDragging || dragCorner) {
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
e.stopPropagation();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// 允许 PhotoView 处理点击事件进行预览
|
|
170
|
+
};
|
|
160
171
|
var handleMouseMove = useCallback(function (e) {
|
|
161
172
|
if (!isDragging || !dragCorner) return;
|
|
162
173
|
var deltaX = e.clientX - dragStartXRef.current;
|
|
@@ -383,6 +394,8 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
383
394
|
onMouseLeave: function onMouseLeave() {
|
|
384
395
|
return setIsHovering(false);
|
|
385
396
|
}
|
|
397
|
+
}, /*#__PURE__*/React.createElement(PhotoView, {
|
|
398
|
+
src: attrs.src
|
|
386
399
|
}, /*#__PURE__*/React.createElement("img", {
|
|
387
400
|
ref: imageRef,
|
|
388
401
|
src: attrs.src,
|
|
@@ -390,14 +403,15 @@ var ImageViewWrapper = function ImageViewWrapper(_ref) {
|
|
|
390
403
|
style: {
|
|
391
404
|
maxWidth: '100%',
|
|
392
405
|
height: 'auto',
|
|
393
|
-
cursor: 'default',
|
|
406
|
+
cursor: isDragging ? 'default' : 'pointer',
|
|
394
407
|
border: '2px solid',
|
|
395
408
|
borderColor: isHovering || isDragging ? alpha(theme.palette.primary.main, 0.3) : 'transparent'
|
|
396
409
|
},
|
|
410
|
+
onClick: handleImageClick,
|
|
397
411
|
onError: function onError(e) {
|
|
398
412
|
_onError === null || _onError === void 0 || _onError(e);
|
|
399
413
|
}
|
|
400
|
-
}), (isHovering || isDragging) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
|
|
414
|
+
})), (isHovering || isDragging) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
|
|
401
415
|
onMouseDown: function onMouseDown(e) {
|
|
402
416
|
return handleMouseDown(e, 'top-left');
|
|
403
417
|
},
|
|
@@ -114,7 +114,7 @@ var LinkViewWrapper = function LinkViewWrapper(_ref) {
|
|
|
114
114
|
fontSize: '1rem'
|
|
115
115
|
}
|
|
116
116
|
}),
|
|
117
|
-
tip: "\u590D\u5236",
|
|
117
|
+
tip: "\u590D\u5236\u94FE\u63A5",
|
|
118
118
|
onClick: handleCopyLink
|
|
119
119
|
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
120
120
|
icon: /*#__PURE__*/React.createElement(LinkUnlinkIcon, {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface TableCellHandleMenuProps extends React.ComponentPropsWithoutRef<'button'> {
|
|
4
|
+
editor?: Editor | null;
|
|
5
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
6
|
+
onResizeStart?: (handle: 'br') => (event: React.MouseEvent) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const TableCellHandleMenu: React.ForwardRefExoticComponent<TableCellHandleMenuProps & React.RefAttributes<HTMLButtonElement>>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
var _excluded = ["editor", "onOpenChange", "className", "onResizeStart"];
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
14
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
15
|
+
import { Menu } from "../../../component";
|
|
16
|
+
import { AlignBottomIcon, AlignCenterIcon, AlignJustifyIcon, AlignLeftIcon, AlignRightIcon, AlignTopIcon, ArrowDownSLineIcon, BrushLineIcon, MergeCellsVerticalIcon, MoreLineIcon, SplitCellsVerticalIcon } from "../../../component/Icons";
|
|
17
|
+
import { DeleteBack2LineIcon } from "../../../component/Icons/delete-back-2-line-icon";
|
|
18
|
+
import { getThemeTextBgColor, getThemeTextColor } from "../../../contants/enums";
|
|
19
|
+
import { Box, Divider, Typography } from '@mui/material';
|
|
20
|
+
import { useTheme } from '@mui/material/styles';
|
|
21
|
+
import { TextSelection } from '@tiptap/pm/state';
|
|
22
|
+
import { CellSelection, cellAround, deleteCellSelection, mergeCells, splitCell } from '@tiptap/pm/tables';
|
|
23
|
+
import { useEditorState } from '@tiptap/react';
|
|
24
|
+
import React, { forwardRef, useCallback, useEffect, useState } from 'react';
|
|
25
|
+
export var TableCellHandleMenu = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
26
|
+
var editor = _ref.editor,
|
|
27
|
+
onOpenChange = _ref.onOpenChange,
|
|
28
|
+
className = _ref.className,
|
|
29
|
+
onResizeStart = _ref.onResizeStart,
|
|
30
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
+
var _useState = useState(false),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
isMenuOpen = _useState2[0],
|
|
34
|
+
setIsMenuOpen = _useState2[1];
|
|
35
|
+
var theme = useTheme();
|
|
36
|
+
var editorState = useEditorState({
|
|
37
|
+
editor: editor,
|
|
38
|
+
selector: function selector(context) {
|
|
39
|
+
if (!context.editor) return null;
|
|
40
|
+
return {
|
|
41
|
+
selection: context.editor.state.selection,
|
|
42
|
+
isEditable: context.editor.isEditable
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
var handleMenuToggle = useCallback(function (isOpen) {
|
|
47
|
+
setIsMenuOpen(isOpen);
|
|
48
|
+
if (!editor) return;
|
|
49
|
+
if (isOpen) {
|
|
50
|
+
editor.commands.freezeHandles();
|
|
51
|
+
} else {
|
|
52
|
+
editor.commands.unfreezeHandles();
|
|
53
|
+
}
|
|
54
|
+
}, [editor]);
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
onOpenChange === null || onOpenChange === void 0 || onOpenChange(isMenuOpen);
|
|
57
|
+
}, [isMenuOpen, onOpenChange]);
|
|
58
|
+
var menuList = React.useMemo(function () {
|
|
59
|
+
if (!editor || !editor.isEditable) return [];
|
|
60
|
+
var canMerge = function () {
|
|
61
|
+
try {
|
|
62
|
+
return mergeCells(editor.state, undefined);
|
|
63
|
+
} catch (_unused) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}();
|
|
67
|
+
var canSplit = function () {
|
|
68
|
+
try {
|
|
69
|
+
return splitCell(editor.state, undefined);
|
|
70
|
+
} catch (_unused2) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}();
|
|
74
|
+
var menuItems = [];
|
|
75
|
+
if (canMerge || canSplit) {
|
|
76
|
+
if (canMerge) {
|
|
77
|
+
menuItems.push({
|
|
78
|
+
key: 'merge-cells',
|
|
79
|
+
label: '合并单元格',
|
|
80
|
+
icon: /*#__PURE__*/React.createElement(MergeCellsVerticalIcon, {
|
|
81
|
+
sx: {
|
|
82
|
+
fontSize: '1rem'
|
|
83
|
+
}
|
|
84
|
+
}),
|
|
85
|
+
onClick: function onClick() {
|
|
86
|
+
var state = editor.state,
|
|
87
|
+
view = editor.view;
|
|
88
|
+
mergeCells(state, view.dispatch.bind(view));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (canSplit) {
|
|
93
|
+
menuItems.push({
|
|
94
|
+
key: 'split-cell',
|
|
95
|
+
label: '拆分单元格',
|
|
96
|
+
icon: /*#__PURE__*/React.createElement(SplitCellsVerticalIcon, {
|
|
97
|
+
sx: {
|
|
98
|
+
fontSize: '1rem'
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
onClick: function onClick() {
|
|
102
|
+
var state = editor.state,
|
|
103
|
+
view = editor.view;
|
|
104
|
+
splitCell(state, view.dispatch.bind(view));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
menuItems.push({
|
|
109
|
+
customLabel: /*#__PURE__*/React.createElement(Divider, {
|
|
110
|
+
sx: {
|
|
111
|
+
my: 0.5
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
key: 'divider1'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
menuItems.push({
|
|
118
|
+
key: 'color',
|
|
119
|
+
label: '颜色',
|
|
120
|
+
icon: /*#__PURE__*/React.createElement(BrushLineIcon, {
|
|
121
|
+
sx: {
|
|
122
|
+
fontSize: '1rem'
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
children: [{
|
|
126
|
+
customLabel: /*#__PURE__*/React.createElement(Typography, {
|
|
127
|
+
sx: {
|
|
128
|
+
p: 1,
|
|
129
|
+
fontSize: '0.75rem',
|
|
130
|
+
color: 'text.secondary',
|
|
131
|
+
fontWeight: 'bold'
|
|
132
|
+
}
|
|
133
|
+
}, "\u6587\u5B57\u989C\u8272"),
|
|
134
|
+
key: 'text-color'
|
|
135
|
+
}].concat(_toConsumableArray(getThemeTextColor(theme).map(function (it) {
|
|
136
|
+
return {
|
|
137
|
+
label: it.label,
|
|
138
|
+
key: it.value,
|
|
139
|
+
icon: /*#__PURE__*/React.createElement(Box, {
|
|
140
|
+
sx: {
|
|
141
|
+
color: it.value,
|
|
142
|
+
width: '1rem',
|
|
143
|
+
height: '1rem',
|
|
144
|
+
borderRadius: '50%',
|
|
145
|
+
bgcolor: it.value,
|
|
146
|
+
border: '1px solid',
|
|
147
|
+
borderColor: it.value === theme.palette.common.white ? 'divider' : 'transparent'
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
onClick: function onClick() {
|
|
151
|
+
if (!editor) return;
|
|
152
|
+
if (editor.state.storedMarks) {
|
|
153
|
+
var textStyleMarkType = editor.schema.marks.textStyle;
|
|
154
|
+
if (textStyleMarkType) {
|
|
155
|
+
editor.view.dispatch(editor.state.tr.removeStoredMark(textStyleMarkType));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
setTimeout(function () {
|
|
159
|
+
var _editor$state = editor.state,
|
|
160
|
+
selection = _editor$state.selection,
|
|
161
|
+
doc = _editor$state.doc;
|
|
162
|
+
var textStyleMark = editor.schema.marks.textStyle;
|
|
163
|
+
if (!textStyleMark) return;
|
|
164
|
+
if (selection instanceof CellSelection) {
|
|
165
|
+
var tr = editor.state.tr;
|
|
166
|
+
var hasContent = false;
|
|
167
|
+
selection.forEachCell(function (cellNode, cellPos) {
|
|
168
|
+
if (cellNode.content.size > 0) {
|
|
169
|
+
hasContent = true;
|
|
170
|
+
var from = cellPos + 1;
|
|
171
|
+
var to = cellPos + cellNode.nodeSize - 1;
|
|
172
|
+
if (from < to) {
|
|
173
|
+
var $from = doc.resolve(from);
|
|
174
|
+
var $to = doc.resolve(to);
|
|
175
|
+
var cellTextSelection = TextSelection.between($from, $to, 1);
|
|
176
|
+
if (cellTextSelection) {
|
|
177
|
+
var mark = textStyleMark.create({
|
|
178
|
+
color: it.value
|
|
179
|
+
});
|
|
180
|
+
tr.addMark(from, to, mark);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
if (hasContent) {
|
|
186
|
+
editor.view.dispatch(tr);
|
|
187
|
+
editor.commands.focus();
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
var $anchor = selection.$anchor;
|
|
191
|
+
var cell = cellAround($anchor);
|
|
192
|
+
if (cell) {
|
|
193
|
+
var cellNode = doc.nodeAt(cell.pos);
|
|
194
|
+
if (cellNode && cellNode.content.size > 0) {
|
|
195
|
+
var from = cell.pos + 1;
|
|
196
|
+
var to = cell.pos + cellNode.nodeSize - 1;
|
|
197
|
+
if (from < to) {
|
|
198
|
+
var $from = doc.resolve(from);
|
|
199
|
+
var $to = doc.resolve(to);
|
|
200
|
+
var newSelection = TextSelection.between($from, $to, 1);
|
|
201
|
+
if (newSelection) {
|
|
202
|
+
editor.view.dispatch(editor.state.tr.setSelection(newSelection));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
editor.chain().focus().toggleMark('textStyle', {
|
|
208
|
+
color: it.value
|
|
209
|
+
}).run();
|
|
210
|
+
}
|
|
211
|
+
}, 0);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
})), [{
|
|
215
|
+
customLabel: /*#__PURE__*/React.createElement(Typography, {
|
|
216
|
+
sx: {
|
|
217
|
+
p: 1,
|
|
218
|
+
fontSize: '0.75rem',
|
|
219
|
+
color: 'text.secondary',
|
|
220
|
+
fontWeight: 'bold'
|
|
221
|
+
}
|
|
222
|
+
}, "\u80CC\u666F\u989C\u8272"),
|
|
223
|
+
key: 'background-color'
|
|
224
|
+
}], _toConsumableArray(getThemeTextBgColor(theme).map(function (it) {
|
|
225
|
+
return {
|
|
226
|
+
label: it.label,
|
|
227
|
+
key: it.value,
|
|
228
|
+
icon: /*#__PURE__*/React.createElement(Box, {
|
|
229
|
+
sx: {
|
|
230
|
+
width: '1rem',
|
|
231
|
+
height: '1rem',
|
|
232
|
+
borderRadius: '50%',
|
|
233
|
+
bgcolor: it.value,
|
|
234
|
+
border: '1px solid',
|
|
235
|
+
borderColor: 'divider'
|
|
236
|
+
}
|
|
237
|
+
}),
|
|
238
|
+
onClick: function onClick() {
|
|
239
|
+
var bgColor = it.value === 'transparent' || it.value === 'var(--mui-palette-background-paper)' ? 'transparent' : it.value;
|
|
240
|
+
setTimeout(function () {
|
|
241
|
+
editor.chain().focus().setCellAttribute('bgcolor', bgColor).run();
|
|
242
|
+
}, 0);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
})))
|
|
246
|
+
}, {
|
|
247
|
+
key: 'align',
|
|
248
|
+
label: '对齐方式',
|
|
249
|
+
icon: /*#__PURE__*/React.createElement(AlignLeftIcon, {
|
|
250
|
+
sx: {
|
|
251
|
+
fontSize: '1rem'
|
|
252
|
+
}
|
|
253
|
+
}),
|
|
254
|
+
children: [{
|
|
255
|
+
customLabel: /*#__PURE__*/React.createElement(Typography, {
|
|
256
|
+
sx: {
|
|
257
|
+
p: 1,
|
|
258
|
+
fontSize: '0.75rem',
|
|
259
|
+
color: 'text.secondary',
|
|
260
|
+
fontWeight: 'bold'
|
|
261
|
+
}
|
|
262
|
+
}, "\u6C34\u5E73\u5BF9\u9F50\u65B9\u5F0F"),
|
|
263
|
+
key: 'align-horizontal'
|
|
264
|
+
}, {
|
|
265
|
+
label: '左侧对齐',
|
|
266
|
+
key: 'align-horizontal-left',
|
|
267
|
+
icon: /*#__PURE__*/React.createElement(AlignLeftIcon, {
|
|
268
|
+
sx: {
|
|
269
|
+
fontSize: '1rem'
|
|
270
|
+
}
|
|
271
|
+
}),
|
|
272
|
+
onClick: function onClick() {
|
|
273
|
+
if (!editor) return;
|
|
274
|
+
setTimeout(function () {
|
|
275
|
+
editor.chain().focus().setCellAttribute('textAlign', 'left').run();
|
|
276
|
+
}, 0);
|
|
277
|
+
}
|
|
278
|
+
}, {
|
|
279
|
+
label: '居中对齐',
|
|
280
|
+
key: 'align-horizontal-center',
|
|
281
|
+
icon: /*#__PURE__*/React.createElement(AlignCenterIcon, {
|
|
282
|
+
sx: {
|
|
283
|
+
fontSize: '1rem'
|
|
284
|
+
}
|
|
285
|
+
}),
|
|
286
|
+
onClick: function onClick() {
|
|
287
|
+
if (!editor) return;
|
|
288
|
+
setTimeout(function () {
|
|
289
|
+
editor.chain().focus().setCellAttribute('textAlign', 'center').run();
|
|
290
|
+
}, 0);
|
|
291
|
+
}
|
|
292
|
+
}, {
|
|
293
|
+
label: '右侧对齐',
|
|
294
|
+
key: 'align-horizontal-right',
|
|
295
|
+
icon: /*#__PURE__*/React.createElement(AlignRightIcon, {
|
|
296
|
+
sx: {
|
|
297
|
+
fontSize: '1rem'
|
|
298
|
+
}
|
|
299
|
+
}),
|
|
300
|
+
onClick: function onClick() {
|
|
301
|
+
if (!editor) return;
|
|
302
|
+
setTimeout(function () {
|
|
303
|
+
editor.chain().focus().setCellAttribute('textAlign', 'right').run();
|
|
304
|
+
}, 0);
|
|
305
|
+
}
|
|
306
|
+
}, {
|
|
307
|
+
label: '两端对齐',
|
|
308
|
+
key: 'align-horizontal-justify',
|
|
309
|
+
icon: /*#__PURE__*/React.createElement(AlignJustifyIcon, {
|
|
310
|
+
sx: {
|
|
311
|
+
fontSize: '1rem'
|
|
312
|
+
}
|
|
313
|
+
}),
|
|
314
|
+
onClick: function onClick() {
|
|
315
|
+
if (!editor) return;
|
|
316
|
+
setTimeout(function () {
|
|
317
|
+
editor.chain().focus().setCellAttribute('textAlign', 'justify').run();
|
|
318
|
+
}, 0);
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
customLabel: /*#__PURE__*/React.createElement(Typography, {
|
|
322
|
+
sx: {
|
|
323
|
+
p: 1,
|
|
324
|
+
fontSize: '0.75rem',
|
|
325
|
+
color: 'text.secondary',
|
|
326
|
+
fontWeight: 'bold'
|
|
327
|
+
}
|
|
328
|
+
}, "\u5782\u76F4\u5BF9\u9F50\u65B9\u5F0F"),
|
|
329
|
+
key: 'align-vertical'
|
|
330
|
+
}, {
|
|
331
|
+
label: '顶部对齐',
|
|
332
|
+
key: 'align-vertical-top',
|
|
333
|
+
icon: /*#__PURE__*/React.createElement(AlignTopIcon, {
|
|
334
|
+
sx: {
|
|
335
|
+
fontSize: '1rem'
|
|
336
|
+
}
|
|
337
|
+
}),
|
|
338
|
+
onClick: function onClick() {
|
|
339
|
+
if (!editor) return;
|
|
340
|
+
setTimeout(function () {
|
|
341
|
+
editor.chain().focus().setCellAttribute('verticalAlign', 'top').run();
|
|
342
|
+
}, 0);
|
|
343
|
+
}
|
|
344
|
+
}, {
|
|
345
|
+
label: '居中对齐',
|
|
346
|
+
key: 'align-vertical-center',
|
|
347
|
+
icon: /*#__PURE__*/React.createElement(AlignCenterIcon, {
|
|
348
|
+
sx: {
|
|
349
|
+
fontSize: '1rem'
|
|
350
|
+
}
|
|
351
|
+
}),
|
|
352
|
+
onClick: function onClick() {
|
|
353
|
+
if (!editor) return;
|
|
354
|
+
setTimeout(function () {
|
|
355
|
+
editor.chain().focus().setCellAttribute('verticalAlign', 'middle').run();
|
|
356
|
+
}, 0);
|
|
357
|
+
}
|
|
358
|
+
}, {
|
|
359
|
+
label: '底部对齐',
|
|
360
|
+
key: 'align-vertical-bottom',
|
|
361
|
+
icon: /*#__PURE__*/React.createElement(AlignBottomIcon, {
|
|
362
|
+
sx: {
|
|
363
|
+
fontSize: '1rem'
|
|
364
|
+
}
|
|
365
|
+
}),
|
|
366
|
+
onClick: function onClick() {
|
|
367
|
+
if (!editor) return;
|
|
368
|
+
setTimeout(function () {
|
|
369
|
+
editor.chain().focus().setCellAttribute('verticalAlign', 'bottom').run();
|
|
370
|
+
}, 0);
|
|
371
|
+
}
|
|
372
|
+
}]
|
|
373
|
+
});
|
|
374
|
+
menuItems.push({
|
|
375
|
+
key: 'clear-content',
|
|
376
|
+
label: '清空单元格内容',
|
|
377
|
+
icon: /*#__PURE__*/React.createElement(DeleteBack2LineIcon, {
|
|
378
|
+
sx: {
|
|
379
|
+
fontSize: '1rem'
|
|
380
|
+
}
|
|
381
|
+
}),
|
|
382
|
+
onClick: function onClick() {
|
|
383
|
+
if (!editor) return;
|
|
384
|
+
var state = editor.state,
|
|
385
|
+
view = editor.view;
|
|
386
|
+
if (state.selection instanceof CellSelection) {
|
|
387
|
+
deleteCellSelection(state, view.dispatch.bind(view));
|
|
388
|
+
} else {
|
|
389
|
+
var $anchor = state.selection.$anchor;
|
|
390
|
+
var cell = cellAround($anchor);
|
|
391
|
+
if (cell) {
|
|
392
|
+
var cellNode = state.doc.nodeAt(cell.pos);
|
|
393
|
+
if (cellNode) {
|
|
394
|
+
var from = cell.pos + 1;
|
|
395
|
+
var to = cell.pos + cellNode.nodeSize - 1;
|
|
396
|
+
if (from < to) {
|
|
397
|
+
view.dispatch(state.tr.delete(from, to));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
attrs: function () {
|
|
404
|
+
if (!editor) return {
|
|
405
|
+
disabled: true
|
|
406
|
+
};
|
|
407
|
+
var selection = editor.state.selection;
|
|
408
|
+
if (selection instanceof CellSelection) {
|
|
409
|
+
var hasContent = false;
|
|
410
|
+
selection.forEachCell(function (cell) {
|
|
411
|
+
if (cell.content.size > 0) {
|
|
412
|
+
hasContent = true;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
return hasContent ? {} : {
|
|
416
|
+
disabled: true
|
|
417
|
+
};
|
|
418
|
+
} else {
|
|
419
|
+
var $anchor = selection.$anchor;
|
|
420
|
+
var cell = cellAround($anchor);
|
|
421
|
+
if (cell) {
|
|
422
|
+
var cellNode = editor.state.doc.nodeAt(cell.pos);
|
|
423
|
+
return cellNode && cellNode.content.size > 0 ? {} : {
|
|
424
|
+
disabled: true
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
disabled: true
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}()
|
|
432
|
+
});
|
|
433
|
+
return menuItems;
|
|
434
|
+
}, [editor, theme, editorState]);
|
|
435
|
+
var handleButton = /*#__PURE__*/React.createElement(Box, _extends({
|
|
436
|
+
component: "button",
|
|
437
|
+
ref: ref,
|
|
438
|
+
className: className,
|
|
439
|
+
"aria-label": "Table cells option",
|
|
440
|
+
"aria-haspopup": "menu",
|
|
441
|
+
"aria-expanded": isMenuOpen,
|
|
442
|
+
onMouseDown: function onMouseDown(e) {
|
|
443
|
+
e.stopPropagation();
|
|
444
|
+
if (onResizeStart) {
|
|
445
|
+
onResizeStart('br')(e);
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
sx: {
|
|
449
|
+
position: 'absolute',
|
|
450
|
+
top: '50%',
|
|
451
|
+
right: '-8px',
|
|
452
|
+
transform: 'translateY(-50%)',
|
|
453
|
+
border: 'none',
|
|
454
|
+
display: 'flex',
|
|
455
|
+
alignItems: 'center',
|
|
456
|
+
justifyContent: 'center',
|
|
457
|
+
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
458
|
+
cursor: 'pointer',
|
|
459
|
+
padding: '4px',
|
|
460
|
+
width: '14px',
|
|
461
|
+
height: '14px',
|
|
462
|
+
zIndex: 4,
|
|
463
|
+
backgroundColor: 'var(--mui-palette-primary-main)',
|
|
464
|
+
'& .MuiSvgIcon-root': {
|
|
465
|
+
color: 'var(--mui-palette-common-white)'
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}, props), /*#__PURE__*/React.createElement(MoreLineIcon, {
|
|
469
|
+
sx: {
|
|
470
|
+
width: '0.75rem',
|
|
471
|
+
height: '0.75rem'
|
|
472
|
+
}
|
|
473
|
+
}));
|
|
474
|
+
return /*#__PURE__*/React.createElement(Menu, {
|
|
475
|
+
width: 216,
|
|
476
|
+
context: handleButton,
|
|
477
|
+
list: menuList,
|
|
478
|
+
anchorOrigin: {
|
|
479
|
+
vertical: 'bottom',
|
|
480
|
+
horizontal: 'left'
|
|
481
|
+
},
|
|
482
|
+
transformOrigin: {
|
|
483
|
+
vertical: 'top',
|
|
484
|
+
horizontal: 'left'
|
|
485
|
+
},
|
|
486
|
+
onOpen: function onOpen() {
|
|
487
|
+
return handleMenuToggle(true);
|
|
488
|
+
},
|
|
489
|
+
onClose: function onClose() {
|
|
490
|
+
return handleMenuToggle(false);
|
|
491
|
+
},
|
|
492
|
+
arrowIcon: /*#__PURE__*/React.createElement(ArrowDownSLineIcon, {
|
|
493
|
+
sx: {
|
|
494
|
+
fontSize: '1rem',
|
|
495
|
+
transform: 'rotate(-90deg)'
|
|
496
|
+
}
|
|
497
|
+
})
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
TableCellHandleMenu.displayName = 'TableCellHandleMenu';
|