@ctzhian/tiptap 2.3.2-beta.4 → 2.3.2-beta.5
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.
|
@@ -19,7 +19,33 @@ export var TableOfContentsExtension = function TableOfContentsExtension(_ref) {
|
|
|
19
19
|
tableOfContentsOptions = _ref.tableOfContentsOptions;
|
|
20
20
|
return TableOfContents.extend({
|
|
21
21
|
onCreate: function onCreate() {
|
|
22
|
-
|
|
22
|
+
var _lastChild$content$fi,
|
|
23
|
+
_this = this;
|
|
24
|
+
// 检查文档结构,避免在特定结构下触发错误
|
|
25
|
+
var doc = this.editor.state.doc;
|
|
26
|
+
var lastChild = doc.lastChild;
|
|
27
|
+
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';
|
|
28
|
+
|
|
29
|
+
// 如果有问题的结构,跳过父类的 onCreate,避免触发 contentMatchAt 错误
|
|
30
|
+
if (hasProblematicStructure) {
|
|
31
|
+
console.warn('TableOfContents: 检测到文档结构问题(图片单独成段),跳过 onCreate 以避免 contentMatchAt 错误');
|
|
32
|
+
// 仍然需要初始化 storage 和 scroll handler
|
|
33
|
+
this.storage.scrollHandler = function () {
|
|
34
|
+
if (!_this.options.scrollParent) return;
|
|
35
|
+
var scrollParent = typeof _this.options.scrollParent === 'function' ? _this.options.scrollParent() : _this.options.scrollParent;
|
|
36
|
+
var scrollPosition = scrollParent instanceof HTMLElement ? scrollParent.scrollTop : scrollParent.scrollY;
|
|
37
|
+
_this.storage.scrollPosition = scrollPosition || 0;
|
|
38
|
+
};
|
|
39
|
+
if (this.options.scrollParent) {
|
|
40
|
+
var scrollParent = typeof this.options.scrollParent === 'function' ? this.options.scrollParent() : this.options.scrollParent;
|
|
41
|
+
if (scrollParent) {
|
|
42
|
+
scrollParent.addEventListener('scroll', this.storage.scrollHandler);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 正常结构,调用父类的 onCreate,使用 try-catch 包装
|
|
23
49
|
try {
|
|
24
50
|
if (this.parent) {
|
|
25
51
|
this.parent();
|
|
@@ -28,11 +54,17 @@ export var TableOfContentsExtension = function TableOfContentsExtension(_ref) {
|
|
|
28
54
|
// 捕获 onCreate 中的错误,特别是 contentMatchAt 错误
|
|
29
55
|
if (error instanceof Error && error.message.includes('contentMatchAt')) {
|
|
30
56
|
console.warn('TableOfContents: onCreate 中检测到 contentMatchAt 错误,已跳过', error);
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
// 即使出错,也初始化必要的部分
|
|
58
|
+
this.storage.scrollHandler = function () {
|
|
59
|
+
if (!_this.options.scrollParent) return;
|
|
60
|
+
var scrollParent = typeof _this.options.scrollParent === 'function' ? _this.options.scrollParent() : _this.options.scrollParent;
|
|
61
|
+
var scrollPosition = scrollParent instanceof HTMLElement ? scrollParent.scrollTop : scrollParent.scrollY;
|
|
62
|
+
_this.storage.scrollPosition = scrollPosition || 0;
|
|
63
|
+
};
|
|
64
|
+
return;
|
|
35
65
|
}
|
|
66
|
+
// 其他错误继续抛出
|
|
67
|
+
throw error;
|
|
36
68
|
}
|
|
37
69
|
},
|
|
38
70
|
addProseMirrorPlugins: function addProseMirrorPlugins() {
|
|
@@ -40,59 +72,32 @@ export var TableOfContentsExtension = function TableOfContentsExtension(_ref) {
|
|
|
40
72
|
var imeCompositionPluginKey = new PluginKey('imeComposition');
|
|
41
73
|
var parentPlugins = ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this)) || [];
|
|
42
74
|
|
|
43
|
-
//
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
75
|
+
// 添加一个保护性插件,包装所有 appendTransaction,捕获可能的错误
|
|
76
|
+
var protectionPlugin = new Plugin({
|
|
77
|
+
key: new PluginKey('tableOfContentsProtection'),
|
|
78
|
+
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
79
|
+
try {
|
|
80
|
+
var _lastChild$content$fi2;
|
|
81
|
+
// 检查文档结构
|
|
82
|
+
var doc = newState.doc;
|
|
83
|
+
var lastChild = doc.lastChild;
|
|
84
|
+
var hasProblematicStructure = lastChild && lastChild.type.name === 'paragraph' && lastChild.content.childCount === 1 && ((_lastChild$content$fi2 = lastChild.content.firstChild) === null || _lastChild$content$fi2 === void 0 ? void 0 : _lastChild$content$fi2.type.name) === 'image';
|
|
59
85
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
}
|
|
86
|
+
// 如果有问题的结构,不执行任何操作
|
|
87
|
+
if (hasProblematicStructure) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
// 捕获任何错误,避免崩溃
|
|
92
|
+
if (error instanceof Error && error.message.includes('contentMatchAt')) {
|
|
93
|
+
console.warn('TableOfContents: 保护插件中检测到 contentMatchAt 错误', error);
|
|
94
|
+
return null;
|
|
90
95
|
}
|
|
91
|
-
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
92
98
|
}
|
|
93
|
-
return plugin;
|
|
94
99
|
});
|
|
95
|
-
return [].concat(_toConsumableArray(
|
|
100
|
+
return [protectionPlugin].concat(_toConsumableArray(parentPlugins), [new Plugin({
|
|
96
101
|
key: new PluginKey('tableOfContentImeFix'),
|
|
97
102
|
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
98
103
|
if (transactions.some(function (tr) {
|