@ant-design/agentic-ui 2.30.23 → 2.30.24
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/MarkdownEditor/editor/plugins/index.d.ts +1 -0
- package/dist/MarkdownEditor/editor/plugins/index.js +1 -0
- package/dist/MarkdownEditor/editor/plugins/withMarkdown.js +2 -1
- package/dist/MarkdownEditor/editor/plugins/withSanitizeInvalidChildren.d.ts +7 -0
- package/dist/MarkdownEditor/editor/plugins/withSanitizeInvalidChildren.js +217 -0
- package/package.json +1 -1
|
@@ -5,5 +5,6 @@ export * from './withInlineNodes';
|
|
|
5
5
|
export * from './withLinkAndMediaPlugin';
|
|
6
6
|
export * from './withListsPlugin';
|
|
7
7
|
export * from './withMarkdown';
|
|
8
|
+
export * from './withSanitizeInvalidChildren';
|
|
8
9
|
export * from './withSchemaPlugin';
|
|
9
10
|
export * from './withVoidNodes';
|
|
@@ -5,5 +5,6 @@ export * from "./withInlineNodes";
|
|
|
5
5
|
export * from "./withLinkAndMediaPlugin";
|
|
6
6
|
export * from "./withListsPlugin";
|
|
7
7
|
export * from "./withMarkdown";
|
|
8
|
+
export * from "./withSanitizeInvalidChildren";
|
|
8
9
|
export * from "./withSchemaPlugin";
|
|
9
10
|
export * from "./withVoidNodes";
|
|
@@ -4,6 +4,7 @@ import { withInlineNodes } from "./withInlineNodes";
|
|
|
4
4
|
import { withLinkAndMediaPlugin } from "./withLinkAndMediaPlugin";
|
|
5
5
|
import { withListsPlugin } from "./withListsPlugin";
|
|
6
6
|
import { withSchemaPlugin } from "./withSchemaPlugin";
|
|
7
|
+
import { withSanitizeInvalidChildren } from "./withSanitizeInvalidChildren";
|
|
7
8
|
import { withVoidNodes } from "./withVoidNodes";
|
|
8
9
|
/**
|
|
9
10
|
* 为Slate编辑器添加Markdown支持的插件函数
|
|
@@ -22,5 +23,5 @@ import { withVoidNodes } from "./withVoidNodes";
|
|
|
22
23
|
*
|
|
23
24
|
* 插件按顺序应用,每个插件都会增强编辑器的特定功能。
|
|
24
25
|
*/ export var withMarkdown = function withMarkdown(editor) {
|
|
25
|
-
return withCodeTagPlugin(withSchemaPlugin(withLinkAndMediaPlugin(withCardPlugin(withListsPlugin(withVoidNodes(withInlineNodes(editor)))))));
|
|
26
|
+
return withSanitizeInvalidChildren(withCodeTagPlugin(withSchemaPlugin(withLinkAndMediaPlugin(withCardPlugin(withListsPlugin(withVoidNodes(withInlineNodes(editor))))))));
|
|
26
27
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Editor } from 'slate';
|
|
2
|
+
/**
|
|
3
|
+
* 外部或合并后的 value 可能在 `children` 中混入 `undefined` / `null`;
|
|
4
|
+
* Slate 的 `Node.string` 会对每个子节点调用 `Text.isText`,遇 `undefined` 即抛错。
|
|
5
|
+
* 在 normalize 最外层剔除非法子节点,避免编辑器与 toMarkdown 崩溃。
|
|
6
|
+
*/
|
|
7
|
+
export declare const withSanitizeInvalidChildren: (editor: Editor) => import("slate").BaseEditor & import("slate-react").ReactEditor & import("slate-history").HistoryEditor;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _define_property(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
function _iterable_to_array_limit(arr, i) {
|
|
23
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
24
|
+
if (_i == null) return;
|
|
25
|
+
var _arr = [];
|
|
26
|
+
var _n = true;
|
|
27
|
+
var _d = false;
|
|
28
|
+
var _s, _e;
|
|
29
|
+
try {
|
|
30
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
31
|
+
_arr.push(_s.value);
|
|
32
|
+
if (i && _arr.length === i) break;
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
_d = true;
|
|
36
|
+
_e = err;
|
|
37
|
+
} finally{
|
|
38
|
+
try {
|
|
39
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
40
|
+
} finally{
|
|
41
|
+
if (_d) throw _e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return _arr;
|
|
45
|
+
}
|
|
46
|
+
function _non_iterable_rest() {
|
|
47
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
48
|
+
}
|
|
49
|
+
function _object_spread(target) {
|
|
50
|
+
for(var i = 1; i < arguments.length; i++){
|
|
51
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
52
|
+
var ownKeys = Object.keys(source);
|
|
53
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
54
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
ownKeys.forEach(function(key) {
|
|
59
|
+
_define_property(target, key, source[key]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
function ownKeys(object, enumerableOnly) {
|
|
65
|
+
var keys = Object.keys(object);
|
|
66
|
+
if (Object.getOwnPropertySymbols) {
|
|
67
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
68
|
+
if (enumerableOnly) {
|
|
69
|
+
symbols = symbols.filter(function(sym) {
|
|
70
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
keys.push.apply(keys, symbols);
|
|
74
|
+
}
|
|
75
|
+
return keys;
|
|
76
|
+
}
|
|
77
|
+
function _object_spread_props(target, source) {
|
|
78
|
+
source = source != null ? source : {};
|
|
79
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
80
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
81
|
+
} else {
|
|
82
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
83
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return target;
|
|
87
|
+
}
|
|
88
|
+
function _object_without_properties(source, excluded) {
|
|
89
|
+
if (source == null) return {};
|
|
90
|
+
var target = {}, sourceKeys, key, i;
|
|
91
|
+
if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
|
|
92
|
+
sourceKeys = Reflect.ownKeys(source);
|
|
93
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
94
|
+
key = sourceKeys[i];
|
|
95
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
96
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
97
|
+
target[key] = source[key];
|
|
98
|
+
}
|
|
99
|
+
return target;
|
|
100
|
+
}
|
|
101
|
+
target = _object_without_properties_loose(source, excluded);
|
|
102
|
+
if (Object.getOwnPropertySymbols) {
|
|
103
|
+
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
104
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
105
|
+
key = sourceKeys[i];
|
|
106
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
107
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
108
|
+
target[key] = source[key];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return target;
|
|
112
|
+
}
|
|
113
|
+
function _object_without_properties_loose(source, excluded) {
|
|
114
|
+
if (source == null) return {};
|
|
115
|
+
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
|
116
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
117
|
+
key = sourceKeys[i];
|
|
118
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
119
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
120
|
+
target[key] = source[key];
|
|
121
|
+
}
|
|
122
|
+
return target;
|
|
123
|
+
}
|
|
124
|
+
function _sliced_to_array(arr, i) {
|
|
125
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
126
|
+
}
|
|
127
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
128
|
+
if (!o) return;
|
|
129
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
130
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
131
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
132
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
133
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
134
|
+
}
|
|
135
|
+
import { Editor, Node, Transforms } from "slate";
|
|
136
|
+
var isValidChild = function isValidChild(child) {
|
|
137
|
+
return child !== undefined && child !== null && Node.isNode(child);
|
|
138
|
+
};
|
|
139
|
+
var createDefaultBlock = function createDefaultBlock() {
|
|
140
|
+
return {
|
|
141
|
+
type: 'paragraph',
|
|
142
|
+
children: [
|
|
143
|
+
{
|
|
144
|
+
text: ''
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
var rebuildElement = function rebuildElement(node) {
|
|
150
|
+
var children = node.children.filter(isValidChild);
|
|
151
|
+
if (children.length === 0 && 'type' in node && node.type) {
|
|
152
|
+
children = [
|
|
153
|
+
{
|
|
154
|
+
text: ''
|
|
155
|
+
}
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
var _drop = node.children, rest = _object_without_properties(node, [
|
|
159
|
+
"children"
|
|
160
|
+
]);
|
|
161
|
+
return _object_spread_props(_object_spread({}, rest), {
|
|
162
|
+
children: children
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* 外部或合并后的 value 可能在 `children` 中混入 `undefined` / `null`;
|
|
167
|
+
* Slate 的 `Node.string` 会对每个子节点调用 `Text.isText`,遇 `undefined` 即抛错。
|
|
168
|
+
* 在 normalize 最外层剔除非法子节点,避免编辑器与 toMarkdown 崩溃。
|
|
169
|
+
*/ export var withSanitizeInvalidChildren = function withSanitizeInvalidChildren(editor) {
|
|
170
|
+
var normalizeNode = editor.normalizeNode;
|
|
171
|
+
editor.normalizeNode = function(entry) {
|
|
172
|
+
var _entry = _sliced_to_array(entry, 2), node = _entry[0], path = _entry[1];
|
|
173
|
+
if (Editor.isEditor(node) && path.length === 0) {
|
|
174
|
+
var hasInvalid = node.children.some(function(c) {
|
|
175
|
+
return !isValidChild(c);
|
|
176
|
+
});
|
|
177
|
+
if (hasInvalid) {
|
|
178
|
+
var clean = node.children.filter(isValidChild);
|
|
179
|
+
editor.children = clean.length === 0 ? [
|
|
180
|
+
createDefaultBlock()
|
|
181
|
+
] : clean;
|
|
182
|
+
normalizeNode(entry);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (node.children.length === 0) {
|
|
186
|
+
editor.children = [
|
|
187
|
+
createDefaultBlock()
|
|
188
|
+
];
|
|
189
|
+
normalizeNode(entry);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
normalizeNode(entry);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (Node.isNode(node)) {
|
|
196
|
+
var hasInvalid1 = node.children.some(function(c) {
|
|
197
|
+
return !isValidChild(c);
|
|
198
|
+
});
|
|
199
|
+
if (hasInvalid1) {
|
|
200
|
+
Editor.withoutNormalizing(editor, function() {
|
|
201
|
+
var rebuilt = rebuildElement(node);
|
|
202
|
+
Transforms.removeNodes(editor, {
|
|
203
|
+
at: path,
|
|
204
|
+
voids: true
|
|
205
|
+
});
|
|
206
|
+
Transforms.insertNodes(editor, rebuilt, {
|
|
207
|
+
at: path,
|
|
208
|
+
voids: true
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
normalizeNode(entry);
|
|
215
|
+
};
|
|
216
|
+
return editor;
|
|
217
|
+
};
|