@ctzhian/tiptap 2.3.2-beta.4 → 2.3.2-beta.6
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/extension/index.js
CHANGED
|
@@ -44,7 +44,8 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
44
44
|
dropcursor: {
|
|
45
45
|
color: 'var(--mui-palette-primary-main)',
|
|
46
46
|
width: 2
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
|
+
trailingNode: false
|
|
48
49
|
}), TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension, YamlFormat, InlineLinkExtension, BlockLinkExtension, CustomHorizontalRule, IframeExtension({
|
|
49
50
|
onError: onError,
|
|
50
51
|
onValidateUrl: onValidateUrl
|
|
@@ -4,95 +4,15 @@ 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
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
-
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."); }
|
|
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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
-
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; }
|
|
13
|
-
// @ts-nocheck
|
|
14
|
-
|
|
15
7
|
import { getHierarchicalIndexes, TableOfContents } from '@tiptap/extension-table-of-contents';
|
|
16
8
|
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
17
9
|
export var TableOfContentsExtension = function TableOfContentsExtension(_ref) {
|
|
18
10
|
var onTocUpdate = _ref.onTocUpdate,
|
|
19
11
|
tableOfContentsOptions = _ref.tableOfContentsOptions;
|
|
20
12
|
return TableOfContents.extend({
|
|
21
|
-
onCreate: function onCreate() {
|
|
22
|
-
// 调用父类的 onCreate,使用 try-catch 包装以避免 contentMatchAt 错误
|
|
23
|
-
try {
|
|
24
|
-
if (this.parent) {
|
|
25
|
-
this.parent();
|
|
26
|
-
}
|
|
27
|
-
} catch (error) {
|
|
28
|
-
// 捕获 onCreate 中的错误,特别是 contentMatchAt 错误
|
|
29
|
-
if (error instanceof Error && error.message.includes('contentMatchAt')) {
|
|
30
|
-
console.warn('TableOfContents: onCreate 中检测到 contentMatchAt 错误,已跳过', error);
|
|
31
|
-
// 即使出错,也继续执行后续逻辑,确保编辑器能正常初始化
|
|
32
|
-
} else {
|
|
33
|
-
// 其他错误继续抛出
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
13
|
addProseMirrorPlugins: function addProseMirrorPlugins() {
|
|
39
|
-
var _this$parent;
|
|
40
14
|
var imeCompositionPluginKey = new PluginKey('imeComposition');
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// 包装所有有 appendTransaction 的插件,添加防御性检查
|
|
44
|
-
var wrappedPlugins = parentPlugins.map(function (plugin) {
|
|
45
|
-
// 如果插件有 appendTransaction,包装它以添加防御性检查
|
|
46
|
-
if (plugin.spec.appendTransaction) {
|
|
47
|
-
var pluginKey = plugin.key;
|
|
48
|
-
return new Plugin({
|
|
49
|
-
key: pluginKey || new PluginKey('wrapped-plugin'),
|
|
50
|
-
state: plugin.spec.state,
|
|
51
|
-
props: plugin.spec.props,
|
|
52
|
-
view: plugin.spec.view,
|
|
53
|
-
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
54
|
-
try {
|
|
55
|
-
var _lastChild$content$fi;
|
|
56
|
-
// 检查文档结构是否可能导致 contentMatchAt 错误
|
|
57
|
-
var doc = newState.doc;
|
|
58
|
-
var lastChild = doc.lastChild;
|
|
59
|
-
|
|
60
|
-
// 如果最后一个节点是段落且只包含图片,可能会导致问题
|
|
61
|
-
var hasProblematicStructure = lastChild && lastChild.type.name === 'paragraph' && lastChild.content.childCount === 1 && ((_lastChild$content$fi = lastChild.content.firstChild) === null || _lastChild$content$fi === void 0 ? void 0 : _lastChild$content$fi.type.name) === 'image';
|
|
62
|
-
|
|
63
|
-
// 如果有问题的结构,先尝试调用原始方法,但捕获可能的错误
|
|
64
|
-
if (hasProblematicStructure && plugin.spec.appendTransaction) {
|
|
65
|
-
try {
|
|
66
|
-
return plugin.spec.appendTransaction(transactions, oldState, newState);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
if (error instanceof Error && error.message.includes('contentMatchAt')) {
|
|
69
|
-
console.warn('TableOfContents: appendTransaction 中检测到 contentMatchAt 错误,已跳过', error);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 正常情况,调用原始的 appendTransaction
|
|
77
|
-
if (plugin.spec.appendTransaction) {
|
|
78
|
-
return plugin.spec.appendTransaction(transactions, oldState, newState);
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
} catch (error) {
|
|
82
|
-
// 如果出现 contentMatchAt 错误,静默处理,避免崩溃
|
|
83
|
-
if (error instanceof Error && error.message.includes('contentMatchAt')) {
|
|
84
|
-
console.warn('TableOfContents: appendTransaction 中检测到 contentMatchAt 错误', error);
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
// 其他错误继续抛出
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return plugin;
|
|
94
|
-
});
|
|
95
|
-
return [].concat(_toConsumableArray(wrappedPlugins), [new Plugin({
|
|
15
|
+
return [new Plugin({
|
|
96
16
|
key: new PluginKey('tableOfContentImeFix'),
|
|
97
17
|
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
98
18
|
if (transactions.some(function (tr) {
|
|
@@ -106,7 +26,7 @@ export var TableOfContentsExtension = function TableOfContentsExtension(_ref) {
|
|
|
106
26
|
}
|
|
107
27
|
return null;
|
|
108
28
|
}
|
|
109
|
-
})]
|
|
29
|
+
})];
|
|
110
30
|
}
|
|
111
31
|
}).configure(_objectSpread(_objectSpread({
|
|
112
32
|
getIndex: getHierarchicalIndexes
|