@ant-design/agentic-ui 2.30.24 → 2.30.25
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/withListsPlugin.js +5 -4
- package/dist/MarkdownEditor/editor/plugins/withSanitizeInvalidChildren.d.ts +2 -1
- package/dist/MarkdownEditor/editor/plugins/withSanitizeInvalidChildren.js +138 -25
- package/dist/MarkdownEditor/editor/store.d.ts +1 -3
- package/dist/MarkdownEditor/editor/store.js +4 -0
- package/dist/MarkdownInputField/MarkdownInputField.js +1 -1
- package/dist/MarkdownInputField/hooks/useMarkdownInputFieldRefs.js +3 -0
- package/package.json +1 -1
|
@@ -115,8 +115,9 @@ import { Editor, Element, Node, Transforms } from "slate";
|
|
|
115
115
|
}
|
|
116
116
|
// 规则 2: list-item 的子节点结构规范化
|
|
117
117
|
if (Element.isElement(node) && node.type === 'list-item') {
|
|
118
|
+
var listItemChildren = Array.isArray(node.children) ? node.children : [];
|
|
118
119
|
// 确保 list-item 至少有一个子节点
|
|
119
|
-
if (
|
|
120
|
+
if (listItemChildren.length === 0) {
|
|
120
121
|
Transforms.insertNodes(editor, {
|
|
121
122
|
type: 'paragraph',
|
|
122
123
|
children: [
|
|
@@ -132,7 +133,7 @@ import { Editor, Element, Node, Transforms } from "slate";
|
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
135
|
// 确保第一个子节点是块级元素(paragraph 或其他块级元素)
|
|
135
|
-
var firstChild =
|
|
136
|
+
var firstChild = listItemChildren[0];
|
|
136
137
|
if (Element.isElement(firstChild) && !Editor.isBlock(editor, firstChild) && firstChild.type !== 'paragraph') {
|
|
137
138
|
// 如果不是块级元素,包裹为 paragraph
|
|
138
139
|
Transforms.wrapNodes(editor, {
|
|
@@ -147,8 +148,8 @@ import { Editor, Element, Node, Transforms } from "slate";
|
|
|
147
148
|
}
|
|
148
149
|
// 确保 list-item 的子节点中,除了第一个块级元素外,其他都是列表类型
|
|
149
150
|
// 允许的结构: [paragraph, bulleted-list?, numbered-list?]
|
|
150
|
-
for(var i = 1; i <
|
|
151
|
-
var child1 =
|
|
151
|
+
for(var i = 1; i < listItemChildren.length; i++){
|
|
152
|
+
var child1 = listItemChildren[i];
|
|
152
153
|
if (Element.isElement(child1)) {
|
|
153
154
|
if (!isListType(child1)) {
|
|
154
155
|
if (Editor.isBlock(editor, child1)) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Editor } from 'slate';
|
|
2
|
+
import { HistoryEditor } from 'slate-history';
|
|
2
3
|
/**
|
|
3
4
|
* 外部或合并后的 value 可能在 `children` 中混入 `undefined` / `null`;
|
|
4
5
|
* Slate 的 `Node.string` 会对每个子节点调用 `Text.isText`,遇 `undefined` 即抛错。
|
|
5
6
|
* 在 normalize 最外层剔除非法子节点,避免编辑器与 toMarkdown 崩溃。
|
|
6
7
|
*/
|
|
7
|
-
export declare const withSanitizeInvalidChildren: (editor: Editor) => import("slate").BaseEditor & import("slate-react").ReactEditor &
|
|
8
|
+
export declare const withSanitizeInvalidChildren: (editor: Editor) => import("slate").BaseEditor & import("slate-react").ReactEditor & HistoryEditor;
|
|
@@ -124,6 +124,10 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
124
124
|
function _sliced_to_array(arr, i) {
|
|
125
125
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
126
126
|
}
|
|
127
|
+
function _type_of(obj) {
|
|
128
|
+
"@swc/helpers - typeof";
|
|
129
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
130
|
+
}
|
|
127
131
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
128
132
|
if (!o) return;
|
|
129
133
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -133,9 +137,18 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
133
137
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
134
138
|
}
|
|
135
139
|
import { Editor, Node, Transforms } from "slate";
|
|
140
|
+
import { HistoryEditor } from "slate-history";
|
|
141
|
+
import { EditorUtils } from "../utils/editorUtils";
|
|
136
142
|
var isValidChild = function isValidChild(child) {
|
|
137
143
|
return child !== undefined && child !== null && Node.isNode(child);
|
|
138
144
|
};
|
|
145
|
+
var getChildList = function getChildList(node) {
|
|
146
|
+
if (!('children' in node)) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
var children = node.children;
|
|
150
|
+
return Array.isArray(children) ? children : [];
|
|
151
|
+
};
|
|
139
152
|
var createDefaultBlock = function createDefaultBlock() {
|
|
140
153
|
return {
|
|
141
154
|
type: 'paragraph',
|
|
@@ -147,7 +160,7 @@ var createDefaultBlock = function createDefaultBlock() {
|
|
|
147
160
|
};
|
|
148
161
|
};
|
|
149
162
|
var rebuildElement = function rebuildElement(node) {
|
|
150
|
-
var children = node.
|
|
163
|
+
var children = getChildList(node).filter(isValidChild);
|
|
151
164
|
if (children.length === 0 && 'type' in node && node.type) {
|
|
152
165
|
children = [
|
|
153
166
|
{
|
|
@@ -162,52 +175,152 @@ var rebuildElement = function rebuildElement(node) {
|
|
|
162
175
|
children: children
|
|
163
176
|
});
|
|
164
177
|
};
|
|
178
|
+
var runWithoutHistory = function runWithoutHistory(editor, fn) {
|
|
179
|
+
if (HistoryEditor.isHistoryEditor(editor)) {
|
|
180
|
+
HistoryEditor.withoutSaving(editor, fn);
|
|
181
|
+
} else {
|
|
182
|
+
fn();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Slate 的 `Node.nodes` / `Editor.normalize` 在遍历时假定非文本节点必有数组型 `children`。
|
|
187
|
+
* 若仅有 `type` 而缺少 `children`,会在进入自定义 `normalizeNode` 之前就抛错,必须先修树。
|
|
188
|
+
*/ var rebuildOrDefaultBlock = function rebuildOrDefaultBlock(raw) {
|
|
189
|
+
if (raw && (typeof raw === "undefined" ? "undefined" : _type_of(raw)) === 'object' && //@ts-ignore
|
|
190
|
+
!(Node === null || Node === void 0 ? void 0 : Node.isText(raw)) && typeof raw.type === 'string') {
|
|
191
|
+
return rebuildElement(raw);
|
|
192
|
+
}
|
|
193
|
+
return createDefaultBlock();
|
|
194
|
+
};
|
|
195
|
+
var repairBrokenChildArrays = function repairBrokenChildArrays(editor) {
|
|
196
|
+
if (!Array.isArray(editor.children)) {
|
|
197
|
+
/* eslint-disable no-param-reassign */ editor.children = [
|
|
198
|
+
createDefaultBlock()
|
|
199
|
+
];
|
|
200
|
+
/* eslint-enable no-param-reassign */ return true;
|
|
201
|
+
}
|
|
202
|
+
if (editor.children.length === 0) {
|
|
203
|
+
EditorUtils.replaceEditorContent(editor, [
|
|
204
|
+
createDefaultBlock()
|
|
205
|
+
]);
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
for(var i = 0; i < editor.children.length; i++){
|
|
209
|
+
var child = editor.children[i];
|
|
210
|
+
if (!isValidChild(child)) {
|
|
211
|
+
/* eslint-disable no-param-reassign */ editor.children[i] = rebuildOrDefaultBlock(child);
|
|
212
|
+
/* eslint-enable no-param-reassign */ return true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
var fixBranch = function fixBranch1(node) {
|
|
216
|
+
var _Node_isText;
|
|
217
|
+
if (!node || (typeof node === "undefined" ? "undefined" : _type_of(node)) !== 'object') {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
//@ts-ignore
|
|
221
|
+
if (Node === null || Node === void 0 ? void 0 : (_Node_isText = Node.isText) === null || _Node_isText === void 0 ? void 0 : _Node_isText.call(Node, node)) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
var rawChildren = node.children;
|
|
225
|
+
if (!Array.isArray(rawChildren)) {
|
|
226
|
+
Object.assign(node, rebuildElement(node));
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
if (rawChildren === null || rawChildren === void 0 ? void 0 : rawChildren.some(function(c) {
|
|
230
|
+
return !isValidChild(c);
|
|
231
|
+
})) {
|
|
232
|
+
var fixedChildren = rawChildren.filter(isValidChild);
|
|
233
|
+
node.children = fixedChildren.length === 0 ? [
|
|
234
|
+
{
|
|
235
|
+
text: ''
|
|
236
|
+
}
|
|
237
|
+
] : fixedChildren;
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
for(var i = 0; i < rawChildren.length; i++){
|
|
241
|
+
if (fixBranch(rawChildren[i])) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
};
|
|
247
|
+
for(var i1 = 0; i1 < editor.children.length; i1++){
|
|
248
|
+
if (fixBranch(editor.children[i1])) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return false;
|
|
253
|
+
};
|
|
165
254
|
/**
|
|
166
255
|
* 外部或合并后的 value 可能在 `children` 中混入 `undefined` / `null`;
|
|
167
256
|
* Slate 的 `Node.string` 会对每个子节点调用 `Text.isText`,遇 `undefined` 即抛错。
|
|
168
257
|
* 在 normalize 最外层剔除非法子节点,避免编辑器与 toMarkdown 崩溃。
|
|
169
258
|
*/ export var withSanitizeInvalidChildren = function withSanitizeInvalidChildren(editor) {
|
|
170
|
-
var normalizeNode = editor.normalizeNode;
|
|
259
|
+
var normalizeNode = editor.normalizeNode, normalize = editor.normalize;
|
|
260
|
+
editor.normalize = function(options) {
|
|
261
|
+
var guard = 0;
|
|
262
|
+
while(guard < 100 && repairBrokenChildArrays(editor)){
|
|
263
|
+
guard += 1;
|
|
264
|
+
}
|
|
265
|
+
return normalize.call(editor, options);
|
|
266
|
+
};
|
|
171
267
|
editor.normalizeNode = function(entry) {
|
|
268
|
+
var _Node_isText;
|
|
172
269
|
var _entry = _sliced_to_array(entry, 2), node = _entry[0], path = _entry[1];
|
|
270
|
+
// `Node.isNode` is true for text leaves, but they have no `children`; never call `.some` on them.
|
|
271
|
+
//@ts-ignore
|
|
272
|
+
if (Node === null || Node === void 0 ? void 0 : (_Node_isText = Node.isText) === null || _Node_isText === void 0 ? void 0 : _Node_isText.call(Node, node)) {
|
|
273
|
+
normalizeNode(entry);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
173
276
|
if (Editor.isEditor(node) && path.length === 0) {
|
|
174
|
-
var
|
|
277
|
+
var childList = getChildList(node);
|
|
278
|
+
var hasInvalid = childList.some(function(c) {
|
|
175
279
|
return !isValidChild(c);
|
|
176
280
|
});
|
|
177
|
-
if (hasInvalid) {
|
|
178
|
-
var
|
|
179
|
-
editor.children = clean.length === 0 ? [
|
|
281
|
+
if (hasInvalid || childList.length === 0) {
|
|
282
|
+
var nextNodes = childList.length === 0 ? [
|
|
180
283
|
createDefaultBlock()
|
|
181
|
-
] :
|
|
284
|
+
] : childList.map(function(c) {
|
|
285
|
+
return isValidChild(c) ? c : rebuildOrDefaultBlock(c);
|
|
286
|
+
});
|
|
287
|
+
EditorUtils.replaceEditorContent(editor, nextNodes);
|
|
182
288
|
normalizeNode(entry);
|
|
183
289
|
return;
|
|
184
290
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
291
|
+
normalizeNode(entry);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
//@ts-ignore
|
|
295
|
+
if (!Editor.isEditor(node) && !Node.isText(node)) {
|
|
296
|
+
var rawChildren = node.children;
|
|
297
|
+
if (!Array.isArray(rawChildren)) {
|
|
298
|
+
Object.assign(node, rebuildElement(node));
|
|
189
299
|
normalizeNode(entry);
|
|
190
300
|
return;
|
|
191
301
|
}
|
|
192
|
-
normalizeNode(entry);
|
|
193
|
-
return;
|
|
194
302
|
}
|
|
195
|
-
|
|
196
|
-
|
|
303
|
+
//@ts-ignore
|
|
304
|
+
if (Node.isElement(node)) {
|
|
305
|
+
var childList1 = getChildList(node);
|
|
306
|
+
var hasInvalid1 = childList1.some(function(c) {
|
|
197
307
|
return !isValidChild(c);
|
|
198
308
|
});
|
|
199
309
|
if (hasInvalid1) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
310
|
+
var applyRebuild = function applyRebuild() {
|
|
311
|
+
Editor.withoutNormalizing(editor, function() {
|
|
312
|
+
var rebuilt = rebuildElement(node);
|
|
313
|
+
Transforms.removeNodes(editor, {
|
|
314
|
+
at: path,
|
|
315
|
+
voids: true
|
|
316
|
+
});
|
|
317
|
+
Transforms.insertNodes(editor, rebuilt, {
|
|
318
|
+
at: path,
|
|
319
|
+
voids: true
|
|
320
|
+
});
|
|
205
321
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
voids: true
|
|
209
|
-
});
|
|
210
|
-
});
|
|
322
|
+
};
|
|
323
|
+
runWithoutHistory(editor, applyRebuild);
|
|
211
324
|
return;
|
|
212
325
|
}
|
|
213
326
|
}
|
|
@@ -435,6 +435,10 @@ export var EditorStoreContext = createContext(null);
|
|
|
435
435
|
value: function setMDContent(md, plugins, options) {
|
|
436
436
|
var _ref, _ref1, _ref2, _ref3;
|
|
437
437
|
if (md === undefined) return;
|
|
438
|
+
if (!md) {
|
|
439
|
+
this.clearContent();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
438
442
|
if (this._shouldSkipSetContent(md)) return;
|
|
439
443
|
this.cancelSetMDContent();
|
|
440
444
|
var chunkSize = (_ref = options === null || options === void 0 ? void 0 : options.chunkSize) !== null && _ref !== void 0 ? _ref : 5000;
|
|
@@ -140,7 +140,6 @@ import { useLocale } from "../I18n";
|
|
|
140
140
|
import { BaseMarkdownEditor } from "../MarkdownEditor";
|
|
141
141
|
import { BorderBeamAnimation } from "./BorderBeamAnimation";
|
|
142
142
|
import { useFileUploadManager } from "./FileUploadManager";
|
|
143
|
-
import { resolveSendDisabled } from "./SendButton";
|
|
144
143
|
import { useMarkdownInputFieldActions } from "./hooks/useMarkdownInputFieldActions";
|
|
145
144
|
import { useMarkdownInputFieldHandlers } from "./hooks/useMarkdownInputFieldHandlers";
|
|
146
145
|
import { useMarkdownInputFieldLayout } from "./hooks/useMarkdownInputFieldLayout";
|
|
@@ -148,6 +147,7 @@ import { useMarkdownInputFieldRefs } from "./hooks/useMarkdownInputFieldRefs";
|
|
|
148
147
|
import { useMarkdownInputFieldState } from "./hooks/useMarkdownInputFieldState";
|
|
149
148
|
import { useMarkdownInputFieldStyles } from "./hooks/useMarkdownInputFieldStyles";
|
|
150
149
|
import { QuickActions } from "./QuickActions";
|
|
150
|
+
import { resolveSendDisabled } from "./SendButton";
|
|
151
151
|
import { SkillModeBar } from "./SkillModeBar";
|
|
152
152
|
import { useStyle } from "./style";
|
|
153
153
|
import { Suggestion } from "./Suggestion";
|
|
@@ -94,6 +94,9 @@ import { ReactEditor } from "slate-react";
|
|
|
94
94
|
// ReactEditor.isFocused can throw if the editor is being torn down
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
if (props.value === undefined || props.value === '') {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
97
100
|
(_markdownEditorRef_current1 = markdownEditorRef.current) === null || _markdownEditorRef_current1 === void 0 ? void 0 : (_markdownEditorRef_current_store = _markdownEditorRef_current1.store) === null || _markdownEditorRef_current_store === void 0 ? void 0 : _markdownEditorRef_current_store.setMDContent((_props_value = props.value) !== null && _props_value !== void 0 ? _props_value : '');
|
|
98
101
|
}, [
|
|
99
102
|
props.value
|