@ctzhian/tiptap 1.6.11 → 1.6.13

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.
@@ -23,7 +23,7 @@ import { Box, Divider, Stack, Typography, useTheme } from '@mui/material';
23
23
  import DragHandle from '@tiptap/extension-drag-handle-react';
24
24
  import { Fragment, Slice } from '@tiptap/pm/model';
25
25
  import { NodeSelection } from '@tiptap/pm/state';
26
- import React, { useCallback, useEffect, useRef, useState } from 'react';
26
+ import React, { useCallback, useState } from 'react';
27
27
  import { convertNodeAt, downloadFiles, filterResourcesByType, getAllResources, getShortcutKeyText } from "../../util";
28
28
  import Menu from "../Menu";
29
29
  import { ToolbarItem } from "../Toolbar";
@@ -122,114 +122,6 @@ var CustomDragHandle = function CustomDragHandle(_ref3) {
122
122
  _useState8 = _slicedToArray(_useState7, 2),
123
123
  currentNode = _useState8[0],
124
124
  setCurrentNode = _useState8[1];
125
-
126
- // 利用插件支持的元信息,在捕获阶段锁定/解锁拖拽句柄,避免在行内/无效区域触发内部 posAtDOM 计算
127
- var lockedRef = useRef(true);
128
- useEffect(function () {
129
- if (!editor || editor !== null && editor !== void 0 && editor.isDestroyed) return;
130
- var disposed = false;
131
- var cleanup = null;
132
- var onMouseMoveCapture = function onMouseMoveCapture(e) {
133
- if (!editor.isEditable) return;
134
- var viewAny;
135
- var root;
136
- try {
137
- var _viewAny;
138
- viewAny = editor.view;
139
- root = (_viewAny = viewAny) === null || _viewAny === void 0 ? void 0 : _viewAny.dom;
140
- } catch (_unused) {
141
- return;
142
- }
143
- if (!root) return;
144
- var el = document.elementFromPoint(e.clientX, e.clientY);
145
- if (!el) return;
146
- var cur = el;
147
- var allowed = false;
148
- while (cur && root.contains(cur)) {
149
- var _desc$node;
150
- var desc = cur.pmViewDesc;
151
- if (desc !== null && desc !== void 0 && (_desc$node = desc.node) !== null && _desc$node !== void 0 && _desc$node.isBlock) {
152
- allowed = true;
153
- break;
154
- }
155
- if (cur.hasAttribute && cur.hasAttribute('data-drag-handle')) {
156
- allowed = true;
157
- break;
158
- }
159
- cur = cur.parentElement;
160
- }
161
- var shouldLock = !allowed;
162
- if (shouldLock !== lockedRef.current) {
163
- lockedRef.current = shouldLock;
164
- try {
165
- var _viewAny2, _viewAny2$dispatch;
166
- var tr = editor.state.tr.setMeta('lockDragHandle', shouldLock);
167
- if (shouldLock) tr.setMeta('hideDragHandle', true);
168
- (_viewAny2 = viewAny) === null || _viewAny2 === void 0 || (_viewAny2$dispatch = _viewAny2.dispatch) === null || _viewAny2$dispatch === void 0 || _viewAny2$dispatch.call(_viewAny2, tr);
169
- } catch (_unused2) {}
170
- }
171
-
172
- // 不允许区域时,阻止事件冒泡到 ProseMirror handleDOMEvents,避免内部 posAtDOM 调用
173
- if (shouldLock) {
174
- try {
175
- var _stopImmediatePropaga, _ref4;
176
- (_stopImmediatePropaga = (_ref4 = e).stopImmediatePropagation) === null || _stopImmediatePropaga === void 0 || _stopImmediatePropaga.call(_ref4);
177
- } catch (_unused3) {}
178
- e.stopPropagation();
179
- }
180
- };
181
- var bind = function bind() {
182
- if (disposed) return false;
183
- var viewAny;
184
- var root;
185
- try {
186
- var _viewAny3;
187
- viewAny = editor.view;
188
- root = (_viewAny3 = viewAny) === null || _viewAny3 === void 0 ? void 0 : _viewAny3.dom;
189
- } catch (_unused4) {
190
- return false;
191
- }
192
- if (!root) return false;
193
- try {
194
- var _viewAny4, _viewAny4$dispatch;
195
- lockedRef.current = true;
196
- var tr0 = editor.state.tr.setMeta('lockDragHandle', true).setMeta('hideDragHandle', true);
197
- (_viewAny4 = viewAny) === null || _viewAny4 === void 0 || (_viewAny4$dispatch = _viewAny4.dispatch) === null || _viewAny4$dispatch === void 0 || _viewAny4$dispatch.call(_viewAny4, tr0);
198
- } catch (_unused5) {}
199
- root.addEventListener('mousemove', onMouseMoveCapture, {
200
- capture: true
201
- });
202
- cleanup = function cleanup() {
203
- root && root.removeEventListener('mousemove', onMouseMoveCapture, {
204
- capture: true
205
- });
206
- };
207
- return true;
208
- };
209
- if (!bind()) {
210
- var onCreate = function onCreate() {
211
- bind();
212
- };
213
- try {
214
- var _on, _ref5;
215
- (_on = (_ref5 = editor).on) === null || _on === void 0 || _on.call(_ref5, 'create', onCreate);
216
- } catch (_unused6) {}
217
- return function () {
218
- var _cleanup;
219
- disposed = true;
220
- try {
221
- var _off, _ref6;
222
- (_off = (_ref6 = editor).off) === null || _off === void 0 || _off.call(_ref6, 'create', onCreate);
223
- } catch (_unused7) {}
224
- (_cleanup = cleanup) === null || _cleanup === void 0 || _cleanup();
225
- };
226
- }
227
- return function () {
228
- var _cleanup2;
229
- disposed = true;
230
- (_cleanup2 = cleanup) === null || _cleanup2 === void 0 || _cleanup2();
231
- };
232
- }, [editor]);
233
125
  var THEME_TEXT_COLOR = [{
234
126
  label: '默认色',
235
127
  value: theme.palette.text.primary
@@ -348,9 +240,9 @@ var CustomDragHandle = function CustomDragHandle(_ref3) {
348
240
  var attrs = current.editor.getAttributes(node.type.name);
349
241
  return Number(attrs.indent) || 0;
350
242
  };
351
- var shouldShowButton = function shouldShowButton(_ref7) {
352
- var editor = _ref7.editor,
353
- data = _ref7.data;
243
+ var shouldShowButton = function shouldShowButton(_ref4) {
244
+ var editor = _ref4.editor,
245
+ data = _ref4.data;
354
246
  if (!editor || !editor.isEditable) return false;
355
247
  var currentNode = data.node;
356
248
  var empty = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.textContent) === '';
@@ -4,7 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { mergeAttributes, Node } from '@tiptap/core';
7
+ import { InputRule, mergeAttributes, Node } from '@tiptap/core';
8
8
  import { ReactNodeViewRenderer } from '@tiptap/react';
9
9
  import AudioViewWrapper from "../component/Audio";
10
10
  export var AudioExtension = function AudioExtension(props) {
@@ -164,22 +164,26 @@ export var AudioExtension = function AudioExtension(props) {
164
164
  },
165
165
  addInputRules: function addInputRules() {
166
166
  var _this3 = this;
167
- return [
168
- // Auto-embed audio URLs
169
- {
167
+ return [new InputRule({
170
168
  find: /^https?:\/\/.*\.(mp3|wav|ogg|m4a|flac|aac|wma|webm)$/,
171
169
  handler: function handler(_ref3) {
172
- var state = _ref3.state,
173
- range = _ref3.range,
174
- match = _ref3.match;
170
+ var range = _ref3.range,
171
+ match = _ref3.match,
172
+ commands = _ref3.commands;
175
173
  var from = range.from,
176
174
  to = range.to;
177
175
  var audioUrl = match[0];
178
- state.tr.replaceWith(from, to, _this3.type.create({
179
- src: audioUrl
180
- }));
176
+ commands.insertContentAt({
177
+ from: from,
178
+ to: to
179
+ }, {
180
+ type: _this3.name,
181
+ attrs: {
182
+ src: audioUrl
183
+ }
184
+ });
181
185
  }
182
- }];
186
+ })];
183
187
  },
184
188
  addNodeView: function addNodeView() {
185
189
  return ReactNodeViewRenderer(function (renderProps) {
@@ -9,7 +9,6 @@ import { ReactNodeViewRenderer } from "@tiptap/react";
9
9
  import ImageViewWrapper from "../component/Image";
10
10
  var customImage = function customImage(props) {
11
11
  return Image.extend({
12
- marks: '',
13
12
  addKeyboardShortcuts: function addKeyboardShortcuts() {
14
13
  var _this = this;
15
14
  return {
@@ -1,5 +1,5 @@
1
1
  import { Extension } from '@tiptap/core';
2
2
  export declare const TableExtension: ({ editable }: {
3
3
  editable: boolean;
4
- }) => (Extension<any, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>)[];
4
+ }) => (import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any> | Extension<any, any>)[];
5
5
  export default TableExtension;
@@ -4,7 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { mergeAttributes, Node } from '@tiptap/core';
7
+ import { InputRule, mergeAttributes, Node } from '@tiptap/core';
8
8
  import { ReactNodeViewRenderer } from '@tiptap/react';
9
9
  import VideoViewWrapper from "../component/Video";
10
10
  export var VideoExtension = function VideoExtension(props) {
@@ -165,22 +165,26 @@ export var VideoExtension = function VideoExtension(props) {
165
165
  },
166
166
  addInputRules: function addInputRules() {
167
167
  var _this3 = this;
168
- return [
169
- // Auto-embed video URLs
170
- {
168
+ return [new InputRule({
171
169
  find: /^https?:\/\/.*\.(mp4|webm|ogg|mov|m4v|avi|wmv|flv|mkv|mpg|mpeg|m4p|m4v|m4b|m4r|m4a)$/,
172
170
  handler: function handler(_ref3) {
173
- var state = _ref3.state,
174
- range = _ref3.range,
175
- match = _ref3.match;
171
+ var range = _ref3.range,
172
+ match = _ref3.match,
173
+ commands = _ref3.commands;
176
174
  var from = range.from,
177
175
  to = range.to;
178
176
  var videoUrl = match[0];
179
- state.tr.replaceWith(from, to, _this3.type.create({
180
- src: videoUrl
181
- }));
177
+ commands.insertContentAt({
178
+ from: from,
179
+ to: to
180
+ }, {
181
+ type: _this3.name,
182
+ attrs: {
183
+ src: videoUrl
184
+ }
185
+ });
182
186
  }
183
- }];
187
+ })];
184
188
  },
185
189
  addNodeView: function addNodeView() {
186
190
  return ReactNodeViewRenderer(function (renderProps) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.6.11",
3
+ "version": "1.6.13",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -81,36 +81,36 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@floating-ui/dom": "^1.7.2",
84
- "@tiptap/core": "^3.4.4",
85
- "@tiptap/extension-bubble-menu": "^3.4.4",
86
- "@tiptap/extension-code": "^3.4.3",
87
- "@tiptap/extension-code-block-lowlight": "^3.4.4",
88
- "@tiptap/extension-details": "^3.4.4",
89
- "@tiptap/extension-drag-handle-react": "^3.4.4",
90
- "@tiptap/extension-emoji": "^3.4.4",
91
- "@tiptap/extension-file-handler": "^3.4.4",
92
- "@tiptap/extension-highlight": "^3.4.4",
93
- "@tiptap/extension-image": "^3.4.4",
94
- "@tiptap/extension-invisible-characters": "^3.4.4",
95
- "@tiptap/extension-link": "^3.4.4",
96
- "@tiptap/extension-list": "^3.4.4",
97
- "@tiptap/extension-mathematics": "^3.4.4",
98
- "@tiptap/extension-mention": "^3.4.4",
99
- "@tiptap/extension-subscript": "^3.4.4",
100
- "@tiptap/extension-superscript": "^3.4.4",
101
- "@tiptap/extension-table": "^3.4.4",
102
- "@tiptap/extension-table-of-contents": "^3.4.4",
103
- "@tiptap/extension-text-align": "^3.4.4",
104
- "@tiptap/extension-text-style": "^3.4.4",
105
- "@tiptap/extension-unique-id": "^3.4.4",
106
- "@tiptap/extension-youtube": "^3.4.4",
107
- "@tiptap/extensions": "^3.4.4",
108
- "@tiptap/html": "^3.4.4",
109
- "@tiptap/pm": "^3.4.4",
110
- "@tiptap/react": "^3.4.4",
111
- "@tiptap/starter-kit": "^3.4.4",
112
- "@tiptap/static-renderer": "^3.4.4",
113
- "@tiptap/suggestion": "^3.4.4",
84
+ "@tiptap/core": "^3.5.3",
85
+ "@tiptap/extension-bubble-menu": "^3.5.3",
86
+ "@tiptap/extension-code": "^3.5.3",
87
+ "@tiptap/extension-code-block-lowlight": "^3.5.3",
88
+ "@tiptap/extension-details": "^3.5.3",
89
+ "@tiptap/extension-drag-handle-react": "^3.5.3",
90
+ "@tiptap/extension-emoji": "^3.5.3",
91
+ "@tiptap/extension-file-handler": "^3.5.3",
92
+ "@tiptap/extension-highlight": "^3.5.3",
93
+ "@tiptap/extension-image": "^3.5.3",
94
+ "@tiptap/extension-invisible-characters": "^3.5.3",
95
+ "@tiptap/extension-link": "^3.5.3",
96
+ "@tiptap/extension-list": "^3.5.3",
97
+ "@tiptap/extension-mathematics": "^3.5.3",
98
+ "@tiptap/extension-mention": "^3.5.3",
99
+ "@tiptap/extension-subscript": "^3.5.3",
100
+ "@tiptap/extension-superscript": "^3.5.3",
101
+ "@tiptap/extension-table": "^3.5.3",
102
+ "@tiptap/extension-table-of-contents": "^3.5.3",
103
+ "@tiptap/extension-text-align": "^3.5.3",
104
+ "@tiptap/extension-text-style": "^3.5.3",
105
+ "@tiptap/extension-unique-id": "^3.5.3",
106
+ "@tiptap/extension-youtube": "^3.5.3",
107
+ "@tiptap/extensions": "^3.5.3",
108
+ "@tiptap/html": "^3.5.3",
109
+ "@tiptap/pm": "^3.5.3",
110
+ "@tiptap/react": "^3.5.3",
111
+ "@tiptap/starter-kit": "^3.5.3",
112
+ "@tiptap/static-renderer": "^3.5.3",
113
+ "@tiptap/suggestion": "^3.5.3",
114
114
  "diff-match-patch": "^1.0.5",
115
115
  "highlight.js": "^11.11.1",
116
116
  "jszip": "^3.10.1",