@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.
- package/dist/Editor/demo.js +1 -1
- 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/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/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/node/FileHandler.d.ts +1 -1
- 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 +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
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { Box, MenuItem, MenuList, Stack } from '@mui/material';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { DeleteColumnIcon, DeleteLineIcon, DeleteRowIcon, InsertColumnLeftIcon, InsertColumnRightIcon, InsertRowBottomIcon, InsertRowTopIcon, LayoutLeft2LineIcon, LayoutTop2LineIcon, MergeCellsHorizontalIcon, SplitCellsHorizontalIcon } from "../../../component/Icons";
|
|
4
|
-
var TableContextMenu = function TableContextMenu(_ref) {
|
|
5
|
-
var editor = _ref.editor,
|
|
6
|
-
onClose = _ref.onClose,
|
|
7
|
-
hasMultipleSelection = _ref.hasMultipleSelection,
|
|
8
|
-
hasMultipleCellElements = _ref.hasMultipleCellElements,
|
|
9
|
-
onCommandExecute = _ref.onCommandExecute;
|
|
10
|
-
var handleCommand = function handleCommand(command) {
|
|
11
|
-
command();
|
|
12
|
-
onCommandExecute === null || onCommandExecute === void 0 || onCommandExecute();
|
|
13
|
-
onClose();
|
|
14
|
-
};
|
|
15
|
-
var menuItems = [{
|
|
16
|
-
label: '在左侧插入列',
|
|
17
|
-
icon: /*#__PURE__*/React.createElement(InsertColumnLeftIcon, {
|
|
18
|
-
sx: {
|
|
19
|
-
fontSize: '1rem'
|
|
20
|
-
}
|
|
21
|
-
}),
|
|
22
|
-
action: function action() {
|
|
23
|
-
return handleCommand(function () {
|
|
24
|
-
return editor.chain().focus().addColumnBefore().run();
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
show: true
|
|
28
|
-
}, {
|
|
29
|
-
label: '在右侧插入列',
|
|
30
|
-
icon: /*#__PURE__*/React.createElement(InsertColumnRightIcon, {
|
|
31
|
-
sx: {
|
|
32
|
-
fontSize: '1rem'
|
|
33
|
-
}
|
|
34
|
-
}),
|
|
35
|
-
action: function action() {
|
|
36
|
-
return handleCommand(function () {
|
|
37
|
-
return editor.chain().focus().addColumnAfter().run();
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
show: true
|
|
41
|
-
}, {
|
|
42
|
-
label: '在上方插入行',
|
|
43
|
-
icon: /*#__PURE__*/React.createElement(InsertRowTopIcon, {
|
|
44
|
-
sx: {
|
|
45
|
-
fontSize: '1rem'
|
|
46
|
-
}
|
|
47
|
-
}),
|
|
48
|
-
action: function action() {
|
|
49
|
-
return handleCommand(function () {
|
|
50
|
-
return editor.chain().focus().addRowBefore().run();
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
show: true
|
|
54
|
-
}, {
|
|
55
|
-
label: '在下方插入行',
|
|
56
|
-
icon: /*#__PURE__*/React.createElement(InsertRowBottomIcon, {
|
|
57
|
-
sx: {
|
|
58
|
-
fontSize: '1rem'
|
|
59
|
-
}
|
|
60
|
-
}),
|
|
61
|
-
action: function action() {
|
|
62
|
-
return handleCommand(function () {
|
|
63
|
-
return editor.chain().focus().addRowAfter().run();
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
show: true
|
|
67
|
-
}, {
|
|
68
|
-
label: '合并单元格',
|
|
69
|
-
icon: /*#__PURE__*/React.createElement(MergeCellsHorizontalIcon, {
|
|
70
|
-
sx: {
|
|
71
|
-
fontSize: '1rem'
|
|
72
|
-
}
|
|
73
|
-
}),
|
|
74
|
-
action: function action() {
|
|
75
|
-
return handleCommand(function () {
|
|
76
|
-
return editor.chain().focus().mergeCells().run();
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
show: hasMultipleSelection
|
|
80
|
-
}, {
|
|
81
|
-
label: '拆分单元格',
|
|
82
|
-
icon: /*#__PURE__*/React.createElement(SplitCellsHorizontalIcon, {
|
|
83
|
-
sx: {
|
|
84
|
-
fontSize: '1rem'
|
|
85
|
-
}
|
|
86
|
-
}),
|
|
87
|
-
action: function action() {
|
|
88
|
-
return handleCommand(function () {
|
|
89
|
-
return editor.chain().focus().splitCell().run();
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
show: !hasMultipleSelection && hasMultipleCellElements
|
|
93
|
-
}, {
|
|
94
|
-
label: '切换表头行',
|
|
95
|
-
icon: /*#__PURE__*/React.createElement(LayoutTop2LineIcon, {
|
|
96
|
-
sx: {
|
|
97
|
-
fontSize: '1rem'
|
|
98
|
-
}
|
|
99
|
-
}),
|
|
100
|
-
action: function action() {
|
|
101
|
-
return handleCommand(function () {
|
|
102
|
-
return editor.chain().focus().toggleHeaderRow().run();
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
show: true
|
|
106
|
-
}, {
|
|
107
|
-
label: '切换表头列',
|
|
108
|
-
icon: /*#__PURE__*/React.createElement(LayoutLeft2LineIcon, {
|
|
109
|
-
sx: {
|
|
110
|
-
fontSize: '1rem'
|
|
111
|
-
}
|
|
112
|
-
}),
|
|
113
|
-
action: function action() {
|
|
114
|
-
return handleCommand(function () {
|
|
115
|
-
return editor.chain().focus().toggleHeaderColumn().run();
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
show: true
|
|
119
|
-
}, {
|
|
120
|
-
label: '删除当前列',
|
|
121
|
-
icon: /*#__PURE__*/React.createElement(DeleteColumnIcon, {
|
|
122
|
-
sx: {
|
|
123
|
-
fontSize: '1rem',
|
|
124
|
-
color: 'error.main'
|
|
125
|
-
}
|
|
126
|
-
}),
|
|
127
|
-
action: function action() {
|
|
128
|
-
return handleCommand(function () {
|
|
129
|
-
return editor.chain().focus().deleteColumn().run();
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
show: true
|
|
133
|
-
}, {
|
|
134
|
-
label: '删除当前行',
|
|
135
|
-
icon: /*#__PURE__*/React.createElement(DeleteRowIcon, {
|
|
136
|
-
sx: {
|
|
137
|
-
fontSize: '1rem',
|
|
138
|
-
color: 'error.main'
|
|
139
|
-
}
|
|
140
|
-
}),
|
|
141
|
-
action: function action() {
|
|
142
|
-
return handleCommand(function () {
|
|
143
|
-
return editor.chain().focus().deleteRow().run();
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
show: true
|
|
147
|
-
}, {
|
|
148
|
-
label: '删除表格',
|
|
149
|
-
icon: /*#__PURE__*/React.createElement(DeleteLineIcon, {
|
|
150
|
-
sx: {
|
|
151
|
-
fontSize: '1rem',
|
|
152
|
-
color: 'error.main'
|
|
153
|
-
}
|
|
154
|
-
}),
|
|
155
|
-
action: function action() {
|
|
156
|
-
return handleCommand(function () {
|
|
157
|
-
return editor.chain().focus().deleteTable().run();
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
show: true
|
|
161
|
-
}];
|
|
162
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MenuList, {
|
|
163
|
-
sx: {
|
|
164
|
-
p: 0.5
|
|
165
|
-
}
|
|
166
|
-
}, menuItems.map(function (item, index) {
|
|
167
|
-
return item.show ? /*#__PURE__*/React.createElement(MenuItem, {
|
|
168
|
-
key: index,
|
|
169
|
-
onClick: item.action,
|
|
170
|
-
sx: {
|
|
171
|
-
py: 1,
|
|
172
|
-
px: 2,
|
|
173
|
-
fontSize: '0.875rem',
|
|
174
|
-
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
175
|
-
'&:hover': {
|
|
176
|
-
backgroundColor: 'action.hover'
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}, /*#__PURE__*/React.createElement(Stack, {
|
|
180
|
-
direction: "row",
|
|
181
|
-
alignItems: "center",
|
|
182
|
-
gap: 1.5
|
|
183
|
-
}, item.icon, /*#__PURE__*/React.createElement(Box, null, item.label))) : null;
|
|
184
|
-
})));
|
|
185
|
-
};
|
|
186
|
-
export default TableContextMenu;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Editor } from '@tiptap/core';
|
|
2
|
-
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
3
|
-
export interface TableContextMenuPluginState {
|
|
4
|
-
show: boolean;
|
|
5
|
-
anchorEl: HTMLElement | null;
|
|
6
|
-
hasMultipleSelection: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare const TableContextMenuPluginKey: PluginKey<TableContextMenuPluginState>;
|
|
9
|
-
export declare const createTableContextMenuPlugin: (editor: Editor) => Plugin<TableContextMenuPluginState>;
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { createRoot } from 'react-dom/client';
|
|
4
|
-
import { FloatingPopover } from "../../../component/FloatingPopover";
|
|
5
|
-
import TableContextMenu from "./ContextMenu";
|
|
6
|
-
var hasMultipleCellSelection = function hasMultipleCellSelection(editor) {
|
|
7
|
-
var selection = editor.state.selection;
|
|
8
|
-
// console.log('1️⃣ selection', selection)
|
|
9
|
-
// console.log('2️⃣ cellSelection.constructor.name', selection.constructor.name)
|
|
10
|
-
// console.log('2️⃣ cellSelection.ranges', selection.ranges)
|
|
11
|
-
if (selection.constructor.name === '_CellSelection') {
|
|
12
|
-
var cellSelection = selection;
|
|
13
|
-
// console.log('2️⃣ cellSelection.$anchorCell', cellSelection.$anchorCell)
|
|
14
|
-
// console.log('2️⃣ cellSelection.$headCell', cellSelection.$headCell)
|
|
15
|
-
if (cellSelection.ranges && cellSelection.ranges.length > 1) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
if (cellSelection.$anchorCell && cellSelection.$headCell) {
|
|
19
|
-
return cellSelection.$anchorCell.pos !== cellSelection.$headCell.pos;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
// const selectionAny = selection as any;
|
|
24
|
-
// const isColSelection = selectionAny.isColSelection;
|
|
25
|
-
// const isRowSelection = selectionAny.isRowSelection;
|
|
26
|
-
// // console.log('3️⃣ selectionAny.isColSelection', isColSelection)
|
|
27
|
-
// // console.log('3️⃣ selectionAny.isRowSelection', isRowSelection)
|
|
28
|
-
// if (isColSelection || isRowSelection) {
|
|
29
|
-
// return true;
|
|
30
|
-
// }
|
|
31
|
-
// console.log('3️⃣ selection.from', selection.from)
|
|
32
|
-
// console.log('3️⃣ selection.to', selection.to)
|
|
33
|
-
// if (selection.from !== selection.to) {
|
|
34
|
-
// const resolvedFrom = editor.state.doc.resolve(selection.from);
|
|
35
|
-
// const resolvedTo = editor.state.doc.resolve(selection.to);
|
|
36
|
-
// console.log('4️⃣ resolvedFrom.nodeAfter', resolvedFrom.nodeAfter)
|
|
37
|
-
// console.log('4️⃣ resolvedTo.nodeBefore', resolvedTo.nodeBefore)
|
|
38
|
-
// if (resolvedFrom.nodeAfter && resolvedTo.nodeBefore) {
|
|
39
|
-
// const fromCell = resolvedFrom.node();
|
|
40
|
-
// const toCell = resolvedTo.node();
|
|
41
|
-
// console.log('5️⃣ fromCell', fromCell)
|
|
42
|
-
// console.log('5️⃣ toCell', toCell)
|
|
43
|
-
// if (fromCell !== toCell && (fromCell.type.name === 'tableCell' || fromCell.type.name === 'tableHeader')) {
|
|
44
|
-
// return true;
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// }
|
|
48
|
-
// return false;
|
|
49
|
-
};
|
|
50
|
-
var isClickedCellInSelection = function isClickedCellInSelection(editor, clickedElement) {
|
|
51
|
-
var selection = editor.state.selection;
|
|
52
|
-
// console.log('6️⃣ selection', selection)
|
|
53
|
-
// console.log('6️⃣ selection.constructor.name', selection.constructor.name)
|
|
54
|
-
if (selection.constructor.name !== '_CellSelection') {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
var editorView = editor.view;
|
|
59
|
-
var domPosition = null;
|
|
60
|
-
// console.log('7️⃣ clickedElement', clickedElement)
|
|
61
|
-
if (clickedElement.tagName === 'TD' || clickedElement.tagName === 'TH') {
|
|
62
|
-
domPosition = editorView.posAtDOM(clickedElement, 0);
|
|
63
|
-
// console.log('7️⃣ domPosition - 1', domPosition)
|
|
64
|
-
} else {
|
|
65
|
-
var parentCell = clickedElement.closest('td, th');
|
|
66
|
-
// console.log('7️⃣ parentCell', parentCell)
|
|
67
|
-
if (parentCell) {
|
|
68
|
-
domPosition = editorView.posAtDOM(parentCell, 0);
|
|
69
|
-
// console.log('7️⃣ domPosition - 2', domPosition)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (domPosition === null || domPosition === undefined || domPosition < 0) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
var cellSelection = selection;
|
|
76
|
-
// console.log('8️⃣ cellSelection.ranges', cellSelection.ranges)
|
|
77
|
-
var ranges = cellSelection.ranges.map(function (it) {
|
|
78
|
-
return it.$from.pos;
|
|
79
|
-
});
|
|
80
|
-
// console.log('8️⃣ ranges', ranges)
|
|
81
|
-
return ranges.includes(domPosition);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.warn('Error checking if clicked cell is in selection:', error);
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
var saveCurrentSelection = function saveCurrentSelection(editor) {
|
|
88
|
-
// console.log('9️⃣ selection', editor.state.selection, 'doc', editor.state.doc)
|
|
89
|
-
return {
|
|
90
|
-
selection: editor.state.selection,
|
|
91
|
-
doc: editor.state.doc
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
var restoreSelection = function restoreSelection(editor, savedState) {
|
|
95
|
-
// console.log('0️⃣ savedState', savedState)
|
|
96
|
-
if (savedState && savedState.selection) {
|
|
97
|
-
try {
|
|
98
|
-
var tr = editor.state.tr.setSelection(savedState.selection);
|
|
99
|
-
editor.view.dispatch(tr);
|
|
100
|
-
editor.view.updateState(editor.view.state);
|
|
101
|
-
requestAnimationFrame(function () {
|
|
102
|
-
editor.view.dom.dispatchEvent(new Event('selectionchange', {
|
|
103
|
-
bubbles: true
|
|
104
|
-
}));
|
|
105
|
-
});
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.warn('Failed to restore table cell selection:', error);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var isInTableCell = function isInTableCell(element) {
|
|
112
|
-
var cell = element.closest('td, th');
|
|
113
|
-
// console.log('🍎 isInTableCell cell', cell)
|
|
114
|
-
if (!cell) return false;
|
|
115
|
-
var editorElement = cell.closest('.tiptap');
|
|
116
|
-
// console.log('🍎 isInTableCell editorElement', editorElement)
|
|
117
|
-
return !!editorElement;
|
|
118
|
-
};
|
|
119
|
-
var getTableCell = function getTableCell(element) {
|
|
120
|
-
var cell = element.closest('td, th');
|
|
121
|
-
// console.log('🍎 getTableCell cell', cell)
|
|
122
|
-
if (!cell) return null;
|
|
123
|
-
var editorElement = cell.closest('.tiptap');
|
|
124
|
-
// console.log('🍎 getTableCell editorElement', editorElement)
|
|
125
|
-
return editorElement ? cell : null;
|
|
126
|
-
};
|
|
127
|
-
export var TableContextMenuPluginKey = new PluginKey('tableContextMenu');
|
|
128
|
-
export var createTableContextMenuPlugin = function createTableContextMenuPlugin(editor) {
|
|
129
|
-
var menuContainer = null;
|
|
130
|
-
var root = null;
|
|
131
|
-
var savedSelection = null;
|
|
132
|
-
var commandExecuted = false;
|
|
133
|
-
var preventSelectionLoss = false;
|
|
134
|
-
var createMenuContainer = function createMenuContainer() {
|
|
135
|
-
// console.log('🍊 createMenuContainer')
|
|
136
|
-
if (!menuContainer) {
|
|
137
|
-
menuContainer = document.createElement('div');
|
|
138
|
-
menuContainer.style.position = 'fixed';
|
|
139
|
-
menuContainer.style.zIndex = '9999';
|
|
140
|
-
menuContainer.style.pointerEvents = 'auto';
|
|
141
|
-
document.body.appendChild(menuContainer);
|
|
142
|
-
root = createRoot(menuContainer);
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
menuContainer: menuContainer,
|
|
146
|
-
root: root
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
var destroyMenuContainer = function destroyMenuContainer() {
|
|
150
|
-
// console.log('🍊 destroyMenuContainer', root, 'menuContainer', menuContainer)
|
|
151
|
-
if (root) {
|
|
152
|
-
// 保存当前的 root 引用,避免异步执行时访问 null
|
|
153
|
-
var currentRoot = root;
|
|
154
|
-
root = null;
|
|
155
|
-
// 异步卸载以避免在 React 渲染期间卸载根节点
|
|
156
|
-
queueMicrotask(function () {
|
|
157
|
-
currentRoot.unmount();
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (menuContainer) {
|
|
161
|
-
// 保存当前的 menuContainer 引用
|
|
162
|
-
var currentContainer = menuContainer;
|
|
163
|
-
menuContainer = null;
|
|
164
|
-
queueMicrotask(function () {
|
|
165
|
-
if (currentContainer && currentContainer.parentNode) {
|
|
166
|
-
document.body.removeChild(currentContainer);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
var hideContextMenu = function hideContextMenu() {
|
|
172
|
-
// console.log('🍊 hideContextMenu', root, 'savedSelection', savedSelection, 'commandExecuted', commandExecuted, 'preventSelectionLoss', preventSelectionLoss)
|
|
173
|
-
if (root) {
|
|
174
|
-
root.render(null);
|
|
175
|
-
}
|
|
176
|
-
if (savedSelection && !commandExecuted && !preventSelectionLoss) {
|
|
177
|
-
restoreSelection(editor, savedSelection);
|
|
178
|
-
}
|
|
179
|
-
savedSelection = null;
|
|
180
|
-
commandExecuted = false;
|
|
181
|
-
preventSelectionLoss = false;
|
|
182
|
-
};
|
|
183
|
-
var showContextMenu = function showContextMenu(anchorEl, hasMultipleSelection, hasMultipleCellElements) {
|
|
184
|
-
// console.log('🍊 showContextMenu', anchorEl, 'hasMultipleSelection', hasMultipleSelection)
|
|
185
|
-
var _createMenuContainer = createMenuContainer(),
|
|
186
|
-
root = _createMenuContainer.root;
|
|
187
|
-
commandExecuted = false;
|
|
188
|
-
var handleClose = function handleClose() {
|
|
189
|
-
hideContextMenu();
|
|
190
|
-
};
|
|
191
|
-
var handleCommandExecute = function handleCommandExecute() {
|
|
192
|
-
commandExecuted = true;
|
|
193
|
-
savedSelection = null;
|
|
194
|
-
};
|
|
195
|
-
root.render( /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
196
|
-
open: !!anchorEl,
|
|
197
|
-
anchorEl: anchorEl,
|
|
198
|
-
onClose: handleClose,
|
|
199
|
-
placement: "bottom"
|
|
200
|
-
}, /*#__PURE__*/React.createElement(TableContextMenu, {
|
|
201
|
-
editor: editor,
|
|
202
|
-
hasMultipleSelection: hasMultipleSelection,
|
|
203
|
-
hasMultipleCellElements: hasMultipleCellElements,
|
|
204
|
-
onClose: handleClose,
|
|
205
|
-
onCommandExecute: handleCommandExecute
|
|
206
|
-
})));
|
|
207
|
-
};
|
|
208
|
-
return new Plugin({
|
|
209
|
-
key: TableContextMenuPluginKey,
|
|
210
|
-
state: {
|
|
211
|
-
init: function init() {
|
|
212
|
-
// console.log('🍊 init')
|
|
213
|
-
return {
|
|
214
|
-
show: false,
|
|
215
|
-
anchorEl: null,
|
|
216
|
-
hasMultipleSelection: false
|
|
217
|
-
};
|
|
218
|
-
},
|
|
219
|
-
apply: function apply(tr, oldState) {
|
|
220
|
-
// console.log('🍊 apply', oldState)
|
|
221
|
-
return oldState;
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
props: {
|
|
225
|
-
handleDOMEvents: {
|
|
226
|
-
contextmenu: function contextmenu(view, event) {
|
|
227
|
-
var target = event.target;
|
|
228
|
-
// console.log('🍊 contextmenu', target)
|
|
229
|
-
if (!isInTableCell(target)) {
|
|
230
|
-
// console.log('🍊 contextmenu not in table cell')
|
|
231
|
-
hideContextMenu();
|
|
232
|
-
preventSelectionLoss = false;
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
event.preventDefault();
|
|
236
|
-
event.stopPropagation();
|
|
237
|
-
var cellElement = getTableCell(target);
|
|
238
|
-
console.log('🍊 cellElement', cellElement === null || cellElement === void 0 ? void 0 : cellElement.getAttribute('colspan'), cellElement === null || cellElement === void 0 ? void 0 : cellElement.getAttribute('rowspan'));
|
|
239
|
-
if (!cellElement) {
|
|
240
|
-
preventSelectionLoss = false;
|
|
241
|
-
return false;
|
|
242
|
-
}
|
|
243
|
-
if (preventSelectionLoss && savedSelection) {
|
|
244
|
-
// console.log('🍊 contextmenu preventSelectionLoss and savedSelection', preventSelectionLoss, savedSelection)
|
|
245
|
-
restoreSelection(editor, savedSelection);
|
|
246
|
-
setTimeout(function () {
|
|
247
|
-
var selectedCells = document.querySelectorAll('.tiptap .selectedCell');
|
|
248
|
-
console.info('✅ Selected cells after restore:', selectedCells.length);
|
|
249
|
-
}, 50);
|
|
250
|
-
}
|
|
251
|
-
var hasMultipleSelection = savedSelection ? true : hasMultipleCellSelection(editor);
|
|
252
|
-
var hasMultipleCellElements = (cellElement === null || cellElement === void 0 ? void 0 : cellElement.getAttribute('colspan')) && parseInt(cellElement.getAttribute('colspan') || '1') > 1 || (cellElement === null || cellElement === void 0 ? void 0 : cellElement.getAttribute('rowspan')) && parseInt(cellElement.getAttribute('rowspan') || '1') > 1 || false;
|
|
253
|
-
// console.log('🍊 contextmenu hasMultipleSelection', hasMultipleSelection)
|
|
254
|
-
showContextMenu(cellElement, hasMultipleSelection, hasMultipleCellElements);
|
|
255
|
-
preventSelectionLoss = false;
|
|
256
|
-
return true;
|
|
257
|
-
},
|
|
258
|
-
mousedown: function mousedown(view, event) {
|
|
259
|
-
// console.log('🍊 mousedown')
|
|
260
|
-
var target = event.target;
|
|
261
|
-
// console.log('🍊 mousedown target', target)
|
|
262
|
-
if (event.button === 2) {
|
|
263
|
-
if (isInTableCell(target)) {
|
|
264
|
-
var cellElement = getTableCell(target);
|
|
265
|
-
if (cellElement) {
|
|
266
|
-
var currentHasMultipleSelection = hasMultipleCellSelection(editor);
|
|
267
|
-
if (currentHasMultipleSelection) {
|
|
268
|
-
var isInSelection = isClickedCellInSelection(editor, cellElement);
|
|
269
|
-
if (isInSelection) {
|
|
270
|
-
savedSelection = saveCurrentSelection(editor);
|
|
271
|
-
preventSelectionLoss = true;
|
|
272
|
-
event.preventDefault();
|
|
273
|
-
event.stopPropagation();
|
|
274
|
-
return true;
|
|
275
|
-
} else {
|
|
276
|
-
console.info('❌ Right-click outside selection, allowing normal behavior');
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
if (!target.closest('[role="menu"]') && !target.closest('.MuiPaper-root')) {
|
|
283
|
-
hideContextMenu();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return false;
|
|
287
|
-
},
|
|
288
|
-
mouseup: function mouseup(view, event) {
|
|
289
|
-
// console.log('🍊 mouseup')
|
|
290
|
-
var target = event.target;
|
|
291
|
-
if (isInTableCell(target)) {
|
|
292
|
-
var cellElement = getTableCell(target);
|
|
293
|
-
if (cellElement) {
|
|
294
|
-
var currentHasMultipleSelection = hasMultipleCellSelection(editor);
|
|
295
|
-
if (currentHasMultipleSelection) {
|
|
296
|
-
var _window$getSelection;
|
|
297
|
-
// console.log('🍊🍊 mouseup current selection', window.getSelection()?.toString().length, window.getSelection()?.toString())
|
|
298
|
-
(_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 || _window$getSelection.removeAllRanges();
|
|
299
|
-
// console.log('🍊🍊 mouseup current selection', window.getSelection()?.toString().length, window.getSelection()?.toString())
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (event.button === 2 && preventSelectionLoss) {
|
|
304
|
-
// console.log('🍊 mouseup preventSelectionLoss', preventSelectionLoss)
|
|
305
|
-
setTimeout(function () {
|
|
306
|
-
if (preventSelectionLoss) {
|
|
307
|
-
preventSelectionLoss = false;
|
|
308
|
-
if (savedSelection && !commandExecuted) {
|
|
309
|
-
restoreSelection(editor, savedSelection);
|
|
310
|
-
savedSelection = null;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}, 10);
|
|
314
|
-
}
|
|
315
|
-
return false;
|
|
316
|
-
},
|
|
317
|
-
keydown: function keydown(view, event) {
|
|
318
|
-
// console.log('🍊 keydown')
|
|
319
|
-
if (event.key === 'Escape') {
|
|
320
|
-
hideContextMenu();
|
|
321
|
-
return true;
|
|
322
|
-
}
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
view: function view() {
|
|
328
|
-
return {
|
|
329
|
-
destroy: function destroy() {
|
|
330
|
-
// console.log('🍊 destroy')
|
|
331
|
-
destroyMenuContainer();
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
};
|