@ctzhian/tiptap 1.6.26 → 1.6.28

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.
@@ -102,7 +102,7 @@ var Reader = function Reader() {
102
102
  }
103
103
  return onUpload;
104
104
  }(),
105
- content: "<p></p><blockquote><p></p></blockquote><p></p>"
105
+ content: "<div class=\"tableWrapper\"><table style=\"min-width: 423px;\"><colgroup><col style=\"width: 100px;\"><col style=\"width: 123px;\"><col style=\"min-width: 100px;\"><col style=\"min-width: 100px;\"></colgroup><tbody><tr class=\"table-row\"><th class=\"table-header\" colspan=\"1\" rowspan=\"1\" colwidth=\"100\"><p>fasdfklj</p></th><th class=\"table-header\" colspan=\"1\" rowspan=\"1\" colwidth=\"123\"><p>fjkldsajflk</p></th><th class=\"table-header\" colspan=\"1\" rowspan=\"1\"><p>jlfjdlskajfl</p></th><th class=\"table-header\" colspan=\"1\" rowspan=\"1\"><p>kflasdjflk</p></th></tr><tr class=\"table-row\"><td colspan=\"1\" rowspan=\"1\" colwidth=\"100\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>flfjladsjflkf</p></td><td colspan=\"1\" rowspan=\"1\" colwidth=\"123\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>lfjlaskdjfkl</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>lkasdjfkl</p></td><td colspan=\"1\" rowspan=\"2\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>jklfjalsdfjl</p></td></tr><tr class=\"table-row\"><td colspan=\"1\" rowspan=\"1\" colwidth=\"100\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>fflkasdlfj</p></td><td colspan=\"1\" rowspan=\"1\" colwidth=\"123\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>lfjldksajfl</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>flajdslfkj</p></td></tr><tr class=\"table-row\"><td colspan=\"1\" rowspan=\"1\" colwidth=\"100\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>lfjadsjflds</p></td><td colspan=\"1\" rowspan=\"1\" colwidth=\"123\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>dfjlajflsk</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>lkfdjajkdls</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>flasjflk</p></td></tr></tbody></table></div><p></p>"
106
106
  }),
107
107
  editor = _useTiptap.editor;
108
108
  return /*#__PURE__*/React.createElement(EditorThemeProvider, {
@@ -1,4 +1,5 @@
1
1
  import { EditorProps } from "../type";
2
2
  import React from 'react';
3
+ import 'core-js/actual/array/find-last';
3
4
  declare const Editor: ({ editor, menuInDragHandle, menuInBubbleMenu, onTip }: EditorProps) => React.JSX.Element;
4
5
  export default Editor;
@@ -1,8 +1,12 @@
1
+ import "core-js/modules/es.array.find-last.js";
1
2
  import { EditorContent } from '@tiptap/react';
2
3
  import React from 'react';
3
4
  import { PhotoProvider } from 'react-photo-view';
4
5
  import SelectionText from "../component/CustomBubbleMenu/SelectionText";
5
6
  import CustomDragHandle from "../component/CustomDragHandle";
7
+
8
+ // fix: https://github.com/ueberdosis/tiptap/issues/6785
9
+
6
10
  var Editor = function Editor(_ref) {
7
11
  var editor = _ref.editor,
8
12
  menuInDragHandle = _ref.menuInDragHandle,
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import 'core-js/actual/array/find-last';
2
3
  interface EditorDiffProps {
3
4
  oldHtml: string;
4
5
  newHtml: string;
@@ -1,7 +1,11 @@
1
+ import "core-js/modules/es.array.find-last.js";
1
2
  import { EditorContent } from "@tiptap/react";
2
3
  import React, { useEffect } from "react";
3
4
  import { PhotoProvider } from "react-photo-view";
4
5
  import useTiptap from "../hook";
6
+
7
+ // fix: https://github.com/ueberdosis/tiptap/issues/6785
8
+
5
9
  var EditorDiff = function EditorDiff(_ref) {
6
10
  var oldHtml = _ref.oldHtml,
7
11
  newHtml = _ref.newHtml;
@@ -61,6 +61,16 @@ var SelectionText = function SelectionText(_ref) {
61
61
  },
62
62
  shouldShow: function shouldShow(_ref2) {
63
63
  var editorProps = _ref2.editor;
64
+ // 表格多选单元格时禁止弹出气泡菜单
65
+ if (editorProps.state.selection.constructor.name === '_CellSelection') {
66
+ var cellSelection = editorProps.state.selection;
67
+ if (cellSelection.ranges.length > 1) {
68
+ return false;
69
+ }
70
+ if (cellSelection.$anchorCell && cellSelection.$headCell) {
71
+ return cellSelection.$anchorCell.pos !== cellSelection.$headCell.pos;
72
+ }
73
+ }
64
74
  if (editorProps.state.selection.empty || editorProps.isActive('image') || editorProps.isActive('video') || editorProps.isActive('audio') || editorProps.isActive('emoji') || editorProps.isActive('codeBlock') || editorProps.isActive('blockMath') || editorProps.isActive('inlineMath') || editorProps.isActive('blockLink') || editorProps.isActive('inlineLink') || editorProps.isActive('blockAttachment') || editorProps.isActive('inlineAttachment') || editorProps.isActive('horizontalRule') || editorProps.isActive('iframe')) {
65
75
  return false;
66
76
  }
@@ -105,7 +105,10 @@ var NestedList = function NestedList(_ref) {
105
105
  sx: {
106
106
  pointerEvents: 'none'
107
107
  },
108
- disableScrollLock: true
108
+ disableScrollLock: true,
109
+ disableAutoFocus: true,
110
+ disableEnforceFocus: true,
111
+ disableRestoreFocus: true
109
112
  }, childrenProps), /*#__PURE__*/React.createElement(Box, {
110
113
  className: "menu-select-sub-list",
111
114
  sx: _objectSpread(_objectSpread(_objectSpread({
@@ -69,7 +69,10 @@ var Menu = function Menu(_ref) {
69
69
  onClose: handleClose,
70
70
  anchorOrigin: anchorOrigin,
71
71
  transformOrigin: transformOrigin,
72
- disableScrollLock: true
72
+ disableScrollLock: true,
73
+ disableAutoFocus: true,
74
+ disableEnforceFocus: true,
75
+ disableRestoreFocus: true
73
76
  }, /*#__PURE__*/React.createElement(Box, {
74
77
  sx: {
75
78
  p: 0.5
@@ -1,7 +1,6 @@
1
- import { ToolbarItem } from "../../../component/Toolbar";
2
- import { Box, Divider, MenuItem, MenuList, Stack } from '@mui/material';
1
+ import { Box, MenuItem, MenuList, Stack } from '@mui/material';
3
2
  import React from 'react';
4
- import { BoldIcon, DeleteColumnIcon, DeleteLineIcon, DeleteRowIcon, InsertColumnLeftIcon, InsertColumnRightIcon, InsertRowBottomIcon, InsertRowTopIcon, ItalicIcon, LayoutLeft2LineIcon, LayoutTop2LineIcon, MergeCellsHorizontalIcon, SplitCellsHorizontalIcon, StrikethroughIcon, UnderlineIcon } from "../../../component/Icons";
3
+ import { DeleteColumnIcon, DeleteLineIcon, DeleteRowIcon, InsertColumnLeftIcon, InsertColumnRightIcon, InsertRowBottomIcon, InsertRowTopIcon, LayoutLeft2LineIcon, LayoutTop2LineIcon, MergeCellsHorizontalIcon, SplitCellsHorizontalIcon } from "../../../component/Icons";
5
4
  var TableContextMenu = function TableContextMenu(_ref) {
6
5
  var editor = _ref.editor,
7
6
  onClose = _ref.onClose,
@@ -159,49 +158,7 @@ var TableContextMenu = function TableContextMenu(_ref) {
159
158
  },
160
159
  show: true
161
160
  }];
162
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Stack, {
163
- direction: 'row',
164
- alignItems: 'center',
165
- sx: {
166
- p: 0.5
167
- }
168
- }, /*#__PURE__*/React.createElement(ToolbarItem, {
169
- onClick: function onClick() {
170
- return editor.chain().focus().toggleBold().run();
171
- },
172
- icon: /*#__PURE__*/React.createElement(BoldIcon, {
173
- sx: {
174
- fontSize: '1rem'
175
- }
176
- })
177
- }), /*#__PURE__*/React.createElement(ToolbarItem, {
178
- onClick: function onClick() {
179
- return editor.chain().focus().toggleItalic().run();
180
- },
181
- icon: /*#__PURE__*/React.createElement(ItalicIcon, {
182
- sx: {
183
- fontSize: '1rem'
184
- }
185
- })
186
- }), /*#__PURE__*/React.createElement(ToolbarItem, {
187
- onClick: function onClick() {
188
- return editor.chain().focus().toggleStrike().run();
189
- },
190
- icon: /*#__PURE__*/React.createElement(StrikethroughIcon, {
191
- sx: {
192
- fontSize: '1rem'
193
- }
194
- })
195
- }), /*#__PURE__*/React.createElement(ToolbarItem, {
196
- onClick: function onClick() {
197
- return editor.chain().focus().toggleUnderline().run();
198
- },
199
- icon: /*#__PURE__*/React.createElement(UnderlineIcon, {
200
- sx: {
201
- fontSize: '1rem'
202
- }
203
- })
204
- })), /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement(MenuList, {
161
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MenuList, {
205
162
  sx: {
206
163
  p: 0.5
207
164
  }
@@ -5,7 +5,7 @@ import { FloatingPopover } from "../../../component/FloatingPopover";
5
5
  import TableContextMenu from "./ContextMenu";
6
6
  var hasMultipleCellSelection = function hasMultipleCellSelection(editor) {
7
7
  var selection = editor.state.selection;
8
- if (selection.constructor.name === 'CellSelection') {
8
+ if (selection.constructor.name === '_CellSelection') {
9
9
  var cellSelection = selection;
10
10
  if (cellSelection.ranges && cellSelection.ranges.length > 1) {
11
11
  return true;
@@ -117,12 +117,23 @@ export var createTableContextMenuPlugin = function createTableContextMenuPlugin(
117
117
  };
118
118
  var destroyMenuContainer = function destroyMenuContainer() {
119
119
  if (root) {
120
- root.unmount();
120
+ // 保存当前的 root 引用,避免异步执行时访问 null
121
+ var currentRoot = root;
121
122
  root = null;
123
+ // 异步卸载以避免在 React 渲染期间卸载根节点
124
+ queueMicrotask(function () {
125
+ currentRoot.unmount();
126
+ });
122
127
  }
123
128
  if (menuContainer) {
124
- document.body.removeChild(menuContainer);
129
+ // 保存当前的 menuContainer 引用
130
+ var currentContainer = menuContainer;
125
131
  menuContainer = null;
132
+ queueMicrotask(function () {
133
+ if (currentContainer && currentContainer.parentNode) {
134
+ document.body.removeChild(currentContainer);
135
+ }
136
+ });
126
137
  }
127
138
  };
128
139
  var hideContextMenu = function hideContextMenu() {
@@ -193,7 +204,7 @@ export var createTableContextMenuPlugin = function createTableContextMenuPlugin(
193
204
  restoreSelection(editor, savedSelection);
194
205
  setTimeout(function () {
195
206
  var selectedCells = document.querySelectorAll('.tiptap .selectedCell');
196
- console.log('✅ Selected cells after restore:', selectedCells.length);
207
+ console.info('✅ Selected cells after restore:', selectedCells.length);
197
208
  }, 50);
198
209
  }
199
210
  var hasMultipleSelection = savedSelection ? true : hasMultipleCellSelection(editor);
@@ -217,7 +228,7 @@ export var createTableContextMenuPlugin = function createTableContextMenuPlugin(
217
228
  event.stopPropagation();
218
229
  return true;
219
230
  } else {
220
- console.log('❌ Right-click outside selection, allowing normal behavior');
231
+ console.info('❌ Right-click outside selection, allowing normal behavior');
221
232
  }
222
233
  }
223
234
  }
@@ -230,6 +241,17 @@ export var createTableContextMenuPlugin = function createTableContextMenuPlugin(
230
241
  return false;
231
242
  },
232
243
  mouseup: function mouseup(view, event) {
244
+ var target = event.target;
245
+ if (isInTableCell(target)) {
246
+ var cellElement = getTableCell(target);
247
+ if (cellElement) {
248
+ var currentHasMultipleSelection = hasMultipleCellSelection(editor);
249
+ if (currentHasMultipleSelection) {
250
+ var _window$getSelection;
251
+ (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 || _window$getSelection.removeAllRanges();
252
+ }
253
+ }
254
+ }
233
255
  if (event.button === 2 && preventSelectionLoss) {
234
256
  setTimeout(function () {
235
257
  if (preventSelectionLoss) {
@@ -56,11 +56,11 @@ export var TableExtension = function TableExtension(_ref) {
56
56
  var _this = this;
57
57
  return {
58
58
  'Mod-9': function Mod9() {
59
- return _this.editor.commands.insertTable({
59
+ return _this.editor.chain().insertTable({
60
60
  rows: 3,
61
61
  cols: 4,
62
62
  withHeaderRow: true
63
- });
63
+ }).focus().run();
64
64
  }
65
65
  };
66
66
  },
@@ -152,7 +152,7 @@ export var TableExtension = function TableExtension(_ref) {
152
152
  var _this2 = this;
153
153
  return {
154
154
  Tab: function Tab() {
155
- if (_this2.editor.commands.goToNextCell()) {
155
+ if (_this2.editor.chain().goToNextCell().focus().run()) {
156
156
  return _this2.editor.chain().cancelSelection().run();
157
157
  } else if (!_this2.editor.can().addRowAfter()) {
158
158
  return false;
package/dist/index.css CHANGED
@@ -361,8 +361,7 @@
361
361
  overflow: hidden;
362
362
  background-color: var(--mui-palette-background-paper);
363
363
  caption-side: top;
364
- border-left: 1px solid transparent;
365
- border-right: 1px solid transparent;
364
+ border-left: 1px dotted var(--mui-palette-divider);
366
365
  }
367
366
 
368
367
  .tiptap.ProseMirror table p {
@@ -375,7 +374,7 @@
375
374
  .tiptap.ProseMirror table th {
376
375
  border: none;
377
376
  border-bottom: 1px solid var(--mui-palette-divider);
378
- border-right: 1px solid transparent;
377
+ border-right: 1px dotted var(--mui-palette-divider);
379
378
  box-sizing: border-box;
380
379
  padding: 12px 16px;
381
380
  position: relative;
@@ -406,24 +405,9 @@
406
405
  background-color: var(--mui-palette-background-default);
407
406
  }
408
407
 
409
- .tiptap.ProseMirror table {
410
- border-left: 1px dotted var(--mui-palette-divider);
411
- border-right: 1px dotted var(--mui-palette-divider);
412
- }
413
-
414
- .tiptap.ProseMirror table td,
415
- .tiptap.ProseMirror table th {
416
- border-right-color: var(--mui-palette-divider);
417
- border-right-style: dotted;
418
- }
419
-
420
- .tiptap.ProseMirror table td:last-child,
421
- .tiptap.ProseMirror table th:last-child {
422
- border-right-color: transparent;
423
- }
424
-
425
408
  .tiptap.ProseMirror[contenteditable="true"] table .selectedCell * {
426
409
  pointer-events: none;
410
+ user-select: none;
427
411
  }
428
412
 
429
413
  /* 表格选择状态 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.6.26",
3
+ "version": "1.6.28",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -111,6 +111,7 @@
111
111
  "@tiptap/starter-kit": "3.5.3",
112
112
  "@tiptap/static-renderer": "3.5.3",
113
113
  "@tiptap/suggestion": "3.5.3",
114
+ "core-js": "^3.46.0",
114
115
  "diff-match-patch": "^1.0.5",
115
116
  "highlight.js": "^11.11.1",
116
117
  "jszip": "^3.10.1",