@ctzhian/tiptap 2.3.2-beta.3 → 2.3.2-beta.4
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.
|
@@ -18,10 +18,81 @@ export var TableOfContentsExtension = function TableOfContentsExtension(_ref) {
|
|
|
18
18
|
var onTocUpdate = _ref.onTocUpdate,
|
|
19
19
|
tableOfContentsOptions = _ref.tableOfContentsOptions;
|
|
20
20
|
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
|
+
},
|
|
21
38
|
addProseMirrorPlugins: function addProseMirrorPlugins() {
|
|
22
39
|
var _this$parent;
|
|
23
40
|
var imeCompositionPluginKey = new PluginKey('imeComposition');
|
|
24
|
-
|
|
41
|
+
var parentPlugins = ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this)) || [];
|
|
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({
|
|
25
96
|
key: new PluginKey('tableOfContentImeFix'),
|
|
26
97
|
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
27
98
|
if (transactions.some(function (tr) {
|