@ant-design/agentic-ui 2.30.22 → 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.
Files changed (58) hide show
  1. package/dist/Bubble/MessagesContent/MarkdownPreview.d.ts +0 -58
  2. package/dist/Bubble/MessagesContent/MarkdownPreview.js +79 -156
  3. package/dist/Hooks/useAutoScroll.js +6 -4
  4. package/dist/MarkdownEditor/BaseMarkdownEditor.d.ts +1 -50
  5. package/dist/MarkdownEditor/BaseMarkdownEditor.js +11 -55
  6. package/dist/MarkdownEditor/editor/Editor.js +11 -9
  7. package/dist/MarkdownEditor/editor/elements/Code/index.js +1 -0
  8. package/dist/MarkdownEditor/editor/plugins/elements.d.ts +2 -0
  9. package/dist/MarkdownEditor/editor/plugins/elements.js +4 -2
  10. package/dist/MarkdownEditor/editor/plugins/handlePaste.js +46 -35
  11. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/backspace.js +133 -133
  12. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/enter.js +156 -140
  13. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/match.d.ts +2 -1
  14. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/match.js +23 -4
  15. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/tab.js +40 -36
  16. package/dist/MarkdownEditor/editor/plugins/index.d.ts +1 -0
  17. package/dist/MarkdownEditor/editor/plugins/index.js +1 -0
  18. package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +46 -44
  19. package/dist/MarkdownEditor/editor/plugins/withCodeTagPlugin.js +1 -13
  20. package/dist/MarkdownEditor/editor/plugins/withMarkdown.js +2 -1
  21. package/dist/MarkdownEditor/editor/plugins/withSanitizeInvalidChildren.d.ts +7 -0
  22. package/dist/MarkdownEditor/editor/plugins/withSanitizeInvalidChildren.js +217 -0
  23. package/dist/MarkdownEditor/editor/store.d.ts +3 -1
  24. package/dist/MarkdownEditor/editor/store.js +15 -29
  25. package/dist/MarkdownEditor/editor/utils/editorCommands.js +98 -17
  26. package/dist/MarkdownEditor/editor/utils/editorUtils.d.ts +11 -0
  27. package/dist/MarkdownEditor/editor/utils/editorUtils.js +43 -6
  28. package/dist/MarkdownEditor/editor/utils/keyboard.js +14 -12
  29. package/dist/MarkdownEditor/types.d.ts +36 -414
  30. package/dist/MarkdownEditor/types.js +1 -4
  31. package/dist/MarkdownInputField/MarkdownInputField.js +2 -0
  32. package/dist/MarkdownInputField/SendActions/index.js +7 -4
  33. package/dist/MarkdownInputField/SendButton/index.d.ts +6 -0
  34. package/dist/MarkdownInputField/SendButton/index.js +6 -0
  35. package/dist/MarkdownInputField/hooks/useMarkdownInputFieldHandlers.d.ts +2 -1
  36. package/dist/MarkdownInputField/hooks/useMarkdownInputFieldHandlers.js +6 -1
  37. package/dist/MarkdownRenderer/AnimationText.d.ts +1 -5
  38. package/dist/MarkdownRenderer/AnimationText.js +2 -8
  39. package/dist/MarkdownRenderer/CharacterQueue.d.ts +0 -2
  40. package/dist/MarkdownRenderer/CharacterQueue.js +2 -2
  41. package/dist/MarkdownRenderer/MarkdownRenderer.d.ts +1 -9
  42. package/dist/MarkdownRenderer/MarkdownRenderer.js +1 -9
  43. package/dist/MarkdownRenderer/StreamingCursor.d.ts +4 -0
  44. package/dist/MarkdownRenderer/StreamingCursor.js +20 -0
  45. package/dist/MarkdownRenderer/markdownReactShared.d.ts +8 -38
  46. package/dist/MarkdownRenderer/markdownReactShared.js +9 -45
  47. package/dist/MarkdownRenderer/renderers/ChartRenderer.js +9 -1
  48. package/dist/MarkdownRenderer/streaming/MarkdownBlockPiece.d.ts +1 -3
  49. package/dist/MarkdownRenderer/streaming/MarkdownBlockPiece.js +16 -28
  50. package/dist/MarkdownRenderer/style.js +18 -0
  51. package/dist/MarkdownRenderer/types.d.ts +14 -86
  52. package/dist/MarkdownRenderer/useStreaming.d.ts +1 -10
  53. package/dist/MarkdownRenderer/useStreaming.js +5 -13
  54. package/dist/ThoughtChainList/MarkdownEditor.d.ts +1 -35
  55. package/dist/ThoughtChainList/MarkdownEditor.js +5 -44
  56. package/dist/Workspace/RealtimeFollow/index.d.ts +3 -0
  57. package/dist/Workspace/RealtimeFollow/index.js +5 -3
  58. package/package.json +2 -2
@@ -116,16 +116,20 @@ var SPECIAL_ENTER_BLOCK_TYPES = new Set([
116
116
  // 从 editorProps.jinja 读取(BaseMarkdownEditor 已写入 effectiveJinja),支持插件配置的 trigger
117
117
  var effectiveJinja = editorProps === null || editorProps === void 0 ? void 0 : editorProps.jinja;
118
118
  var jinjaTrigger = (effectiveJinja === null || effectiveJinja === void 0 ? void 0 : effectiveJinja.templatePanel) && _type_of(effectiveJinja.templatePanel) === 'object' && effectiveJinja.templatePanel.trigger || '{}';
119
+ var matchInputToNodeRef = useRef(false);
120
+ matchInputToNodeRef.current = (props === null || props === void 0 ? void 0 : (_props_markdown = props.markdown) === null || _props_markdown === void 0 ? void 0 : _props_markdown.matchInputToNode) === true;
119
121
  var matchKeyRef = useRef(null);
120
122
  if (matchKeyRef.current === null) {
121
- matchKeyRef.current = new MatchKey(markdownEditorRef);
123
+ matchKeyRef.current = new MatchKey(markdownEditorRef, function() {
124
+ return matchInputToNodeRef.current;
125
+ });
122
126
  }
123
127
  return useMemo(function() {
124
128
  var tab = new TabKey(markdownEditorRef.current);
125
129
  var backspace = new BackspaceKey(markdownEditorRef.current);
126
130
  var enter = new EnterKey(store, backspace);
127
131
  return function(e) {
128
- var _props_markdown, _e_nativeEvent, _node_;
132
+ var _e_nativeEvent, _node_, _e_nativeEvent1;
129
133
  // 只读模式下跳过所有键盘处理,提升性能
130
134
  if (props.readonly) return;
131
135
  // 处理表格键盘事件
@@ -173,10 +177,10 @@ var SPECIAL_ENTER_BLOCK_TYPES = new Set([
173
177
  if (isHotkey('mod+shift+s', e)) {
174
178
  e.preventDefault();
175
179
  }
176
- // 仅当显式开启 matchInputToNode 时才执行输入转节点(如 "- " 转列表),默认关闭
177
- // IME 输入法组合期间不触发,避免输入「-」后按空格选字时误转为列表
178
- if ((props === null || props === void 0 ? void 0 : (_props_markdown = props.markdown) === null || _props_markdown === void 0 ? void 0 : _props_markdown.matchInputToNode) === true && !((_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.isComposing)) {
179
- if (matchKeyRef.current.run(e)) return;
180
+ // Markdown 短语法转节点(``` / --- / 列表等)由 MatchKey 处理
181
+ // IME 组合期间不触发,避免选字时误转
182
+ if (!((_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.isComposing) && matchKeyRef.current.run(e)) {
183
+ return;
180
184
  }
181
185
  if (e.key.toLowerCase().startsWith('arrow')) {
182
186
  if ([
@@ -250,48 +254,47 @@ var SPECIAL_ENTER_BLOCK_TYPES = new Set([
250
254
  // 不在特殊块中,让 MarkdownInputField 处理发送
251
255
  return;
252
256
  }
253
- var _Editor_nodes2 = _sliced_to_array(Editor.nodes(markdownEditorRef.current, {
257
+ var sel = markdownEditorRef.current.selection;
258
+ if (!sel || !Range.isCollapsed(sel)) {
259
+ return;
260
+ }
261
+ var blockIter = Editor.nodes(markdownEditorRef.current, {
262
+ at: sel.anchor,
254
263
  match: function match(n) {
255
264
  return Element.isElement(n);
256
265
  },
257
266
  mode: 'lowest'
258
- }), 1), node2 = _Editor_nodes2[0];
259
- if (!node2) return;
260
- if ((node2 === null || node2 === void 0 ? void 0 : (_node_ = node2[0]) === null || _node_ === void 0 ? void 0 : _node_.type) === 'paragraph') {
261
- var _Editor_nodes3 = _sliced_to_array(Editor.nodes(markdownEditorRef.current, {
262
- match: function match(n) {
263
- return Element.isElement(n) && n.type === 'paragraph';
264
- },
265
- mode: 'lowest'
266
- }), 1), paraNode = _Editor_nodes3[0];
267
- var node3 = paraNode;
268
- if (node3) {
269
- var _e_nativeEvent1;
270
- var sel = markdownEditorRef.current.selection;
271
- // Jinja 触发:基于光标位置检测,支持在任意位置输入 {}(含两个模板中间)
272
- if (jinjaTemplatePanelEnabled && e.key.length === 1 && !((_e_nativeEvent1 = e.nativeEvent) === null || _e_nativeEvent1 === void 0 ? void 0 : _e_nativeEvent1.isComposing) && sel && Range.isCollapsed(sel) && Path.isAncestor(node3[1], sel.anchor.path) && setOpenJinjaTemplate && setJinjaAnchorPath) {
273
- var strBeforeCursor = Editor.string(markdownEditorRef.current, Editor.range(markdownEditorRef.current, Editor.start(markdownEditorRef.current, node3[1]), sel.anchor));
274
- var strAfterKeyAtCursor = strBeforeCursor + (e.key.length === 1 ? e.key : '');
275
- if (strAfterKeyAtCursor.endsWith(jinjaTrigger)) {
276
- setJinjaAnchorPath(node3[1]);
277
- setTimeout(function() {
278
- return setOpenJinjaTemplate(true);
279
- });
280
- return;
281
- }
282
- }
267
+ });
268
+ var blockFirst = blockIter.next();
269
+ if (blockFirst.done) {
270
+ return;
271
+ }
272
+ var node2 = blockFirst.value;
273
+ if ((node2 === null || node2 === void 0 ? void 0 : (_node_ = node2[0]) === null || _node_ === void 0 ? void 0 : _node_.type) !== 'paragraph') {
274
+ return;
275
+ }
276
+ // Jinja 触发:基于光标位置检测,支持在任意位置输入 {}(含两个模板中间)
277
+ if (jinjaTemplatePanelEnabled && e.key.length === 1 && !((_e_nativeEvent1 = e.nativeEvent) === null || _e_nativeEvent1 === void 0 ? void 0 : _e_nativeEvent1.isComposing) && Path.isAncestor(node2[1], sel.anchor.path) && setOpenJinjaTemplate && setJinjaAnchorPath) {
278
+ var strBeforeCursor = Editor.string(markdownEditorRef.current, Editor.range(markdownEditorRef.current, Editor.start(markdownEditorRef.current, node2[1]), sel.anchor));
279
+ var strAfterKeyAtCursor = strBeforeCursor + (e.key.length === 1 ? e.key : '');
280
+ if (strAfterKeyAtCursor.endsWith(jinjaTrigger)) {
281
+ setJinjaAnchorPath(node2[1]);
282
+ setTimeout(function() {
283
+ return setOpenJinjaTemplate(true);
284
+ });
285
+ return;
283
286
  }
284
- if (node3 && node3[0].children.length === 1 && !EditorUtils.isDirtLeaf(node3[0].children[0]) && (e.key === 'Backspace' || /^[^\n]$/.test(e.key))) {
285
- var str = Node.string(node3[0]) || '';
286
- var codeMatch = str.match(/^```([\w+\-#]+)$/i);
287
- if (codeMatch) {} else {
288
- var insertMatch = str.match(/^\/([^\n]+)?$/i);
289
- if (insertMatch && !(!Path.hasPrevious(node3[1]) && Node.parent(markdownEditorRef.current, node3[1]).type === 'list-item')) {
290
- setOpenInsertCompletion === null || setOpenInsertCompletion === void 0 ? void 0 : setOpenInsertCompletion(true);
291
- setTimeout(function() {
292
- insertCompletionText$.next(insertMatch[1]);
293
- });
294
- }
287
+ }
288
+ if (node2[0].children.length === 1 && !EditorUtils.isDirtLeaf(node2[0].children[0]) && (e.key === 'Backspace' || /^[^\n]$/.test(e.key))) {
289
+ var str = Node.string(node2[0]) || '';
290
+ var codeMatch = str.match(/^```([\w+\-#]+)$/i);
291
+ if (!codeMatch) {
292
+ var insertMatch = str.match(/^\/([^\n]+)?$/i);
293
+ if (insertMatch && !(!Path.hasPrevious(node2[1]) && Node.parent(markdownEditorRef.current, node2[1]).type === 'list-item')) {
294
+ setOpenInsertCompletion === null || setOpenInsertCompletion === void 0 ? void 0 : setOpenInsertCompletion(true);
295
+ setTimeout(function() {
296
+ insertCompletionText$.next(insertMatch[1]);
297
+ });
295
298
  }
296
299
  }
297
300
  }
@@ -299,7 +302,6 @@ var SPECIAL_ENTER_BLOCK_TYPES = new Set([
299
302
  }, [
300
303
  markdownEditorRef.current,
301
304
  props === null || props === void 0 ? void 0 : props.readonly,
302
- props === null || props === void 0 ? void 0 : (_props_markdown = props.markdown) === null || _props_markdown === void 0 ? void 0 : _props_markdown.matchInputToNode,
303
305
  openInsertCompletion,
304
306
  insertCompletionText$,
305
307
  setOpenInsertCompletion,
@@ -168,19 +168,7 @@ import { hasRange } from "./utils";
168
168
  }
169
169
  }
170
170
  if ((currentNode1 === null || currentNode1 === void 0 ? void 0 : currentNode1.tag) && operation.text.trim().length > 0 && currentNode1.text.trim().length === 0) {
171
- Editor.withoutNormalizing(editor, function() {
172
- Transforms.removeNodes(editor, {
173
- at: operation.path
174
- });
175
- Transforms.insertNodes(editor, _object_spread_props(_object_spread({}, currentNode1), {
176
- tag: true,
177
- code: true,
178
- text: operation.text
179
- }), {
180
- at: operation.path,
181
- select: true
182
- });
183
- });
171
+ apply(operation);
184
172
  return true;
185
173
  }
186
174
  }
@@ -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
+ };
@@ -662,7 +662,9 @@ export declare class EditorStore {
662
662
  maxResults?: number;
663
663
  }): {
664
664
  path: Path;
665
- range: import("slate").BaseRange;
665
+ range: import("slate").BaseRange; /**
666
+ * 更新结构不同的表格
667
+ */
666
668
  node: any;
667
669
  matchedText: string;
668
670
  offset: {
@@ -404,8 +404,7 @@ export var EditorStoreContext = createContext(null);
404
404
  * Clears all content from the editor, replacing it with an empty paragraph.
405
405
  */ key: "clearContent",
406
406
  value: function clearContent() {
407
- this._editor.current.selection = null;
408
- this._editor.current.children = [
407
+ EditorUtils.replaceEditorContent(this._editor.current, [
409
408
  {
410
409
  type: 'paragraph',
411
410
  children: [
@@ -414,7 +413,7 @@ export var EditorStoreContext = createContext(null);
414
413
  }
415
414
  ]
416
415
  }
417
- ];
416
+ ]);
418
417
  }
419
418
  },
420
419
  {
@@ -478,8 +477,8 @@ export var EditorStoreContext = createContext(null);
478
477
  */ function _setShortContent(md, plugins, onProgress) {
479
478
  try {
480
479
  var nodeList = parserMdToSchema(md, plugins).schema;
480
+ this._editor.current.selection = null;
481
481
  this.setContent(nodeList);
482
- this._editor.current.children = nodeList;
483
482
  this._safeDeselect();
484
483
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(1);
485
484
  } catch (error) {
@@ -496,8 +495,8 @@ export var EditorStoreContext = createContext(null);
496
495
  try {
497
496
  var allNodes = this._parseChunksToNodes(chunks, plugins);
498
497
  if (allNodes.length > 0) {
498
+ this._editor.current.selection = null;
499
499
  this.setContent(allNodes);
500
- this._editor.current.children = allNodes;
501
500
  this._safeDeselect();
502
501
  }
503
502
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(1);
@@ -624,9 +623,7 @@ export var EditorStoreContext = createContext(null);
624
623
  var schema = parserMdToSchema(chunk, plugins).schema;
625
624
  if (schema.length > 0) {
626
625
  if (isFirstBatch) {
627
- // 第一批:清空并插入
628
- _this._editor.current.children = schema;
629
- _this._editor.current.onChange();
626
+ EditorUtils.replaceEditorContent(_this._editor.current, schema);
630
627
  isFirstBatch = false;
631
628
  } else {
632
629
  // 后续批次:追加节点
@@ -910,11 +907,14 @@ export var EditorStoreContext = createContext(null);
910
907
  * @param newNode - 新节点
911
908
  * @private
912
909
  */ function _replaceNodeAt(path, newNode) {
913
- Transforms.removeNodes(this._editor.current, {
914
- at: path
915
- });
916
- Transforms.insertNodes(this._editor.current, newNode, {
917
- at: path
910
+ var _this = this;
911
+ Editor.withoutNormalizing(this._editor.current, function() {
912
+ Transforms.removeNodes(_this._editor.current, {
913
+ at: path
914
+ });
915
+ Transforms.insertNodes(_this._editor.current, newNode, {
916
+ at: path
917
+ });
918
918
  });
919
919
  }
920
920
  },
@@ -925,21 +925,7 @@ export var EditorStoreContext = createContext(null);
925
925
  * @param nodeList - 要设置为编辑器内容的节点列表
926
926
  */ key: "setContent",
927
927
  value: function setContent(nodeList) {
928
- var currentChildren = this._editor.current.children;
929
- this._editor.current.children = nodeList;
930
- this._editor.current.onChange();
931
- // 检查最后一个节点是否以换行符结尾
932
- var lastNode = currentChildren[currentChildren.length - 1];
933
- if (lastNode && Text.isText(lastNode)) {
934
- var text = Node.string(lastNode);
935
- if (!text.endsWith('\n')) {
936
- this._editor.current.insertText('\n', {
937
- at: [
938
- currentChildren.length - 1
939
- ]
940
- });
941
- }
942
- }
928
+ EditorUtils.replaceEditorContent(this._editor.current, nodeList);
943
929
  }
944
930
  },
945
931
  {
@@ -979,7 +965,7 @@ export var EditorStoreContext = createContext(null);
979
965
  }
980
966
  } catch (error) {
981
967
  console.error('Failed to update nodes with optimized method:', error);
982
- this._editor.current.children = nodeList;
968
+ EditorUtils.replaceEditorContent(this._editor.current, nodeList);
983
969
  }
984
970
  }
985
971
  },
@@ -98,6 +98,73 @@ import { EditorUtils } from "./editorUtils";
98
98
  }
99
99
  });
100
100
  }
101
+ /** 光标所在段落/标题;避免 getCurrentNodes 取到 list-item 等子块导致插入路径错误 */ function resolveParagraphOrHead(editor, preferred) {
102
+ if ((preferred === null || preferred === void 0 ? void 0 : preferred[0]) && [
103
+ 'paragraph',
104
+ 'head'
105
+ ].includes(preferred[0].type)) {
106
+ return preferred;
107
+ }
108
+ var selection = editor.selection;
109
+ if (selection) {
110
+ var above = Editor.above(editor, {
111
+ at: selection.anchor,
112
+ match: function match(n) {
113
+ return Element.isElement(n) && [
114
+ 'paragraph',
115
+ 'head'
116
+ ].includes(n.type);
117
+ }
118
+ });
119
+ if (above) {
120
+ return above;
121
+ }
122
+ }
123
+ var nodesResult = Editor.nodes(editor, {
124
+ at: [],
125
+ match: function match(n) {
126
+ return Element.isElement(n) && [
127
+ 'paragraph',
128
+ 'head'
129
+ ].includes(n.type);
130
+ },
131
+ mode: 'lowest'
132
+ });
133
+ if (Array.isArray(nodesResult) && nodesResult.length > 0) {
134
+ var entry = nodesResult[0];
135
+ if ((entry === null || entry === void 0 ? void 0 : entry[0]) && [
136
+ 'paragraph',
137
+ 'head'
138
+ ].includes(entry[0].type)) {
139
+ return entry;
140
+ }
141
+ return undefined;
142
+ }
143
+ var iter = nodesResult;
144
+ if (iter && typeof iter.next === 'function') {
145
+ var first = iter.next();
146
+ return first.done ? undefined : first.value;
147
+ }
148
+ return undefined;
149
+ }
150
+ function firstLowestElement(editor) {
151
+ var nodesResult = Editor.nodes(editor, {
152
+ at: [],
153
+ match: function match(n) {
154
+ return Element.isElement(n);
155
+ },
156
+ mode: 'lowest'
157
+ });
158
+ if (Array.isArray(nodesResult) && nodesResult.length > 0) {
159
+ return nodesResult[0];
160
+ }
161
+ var iter = nodesResult;
162
+ if (iter && typeof iter.next === 'function') {
163
+ var first = iter.next();
164
+ return first.done ? undefined : first.value;
165
+ }
166
+ return undefined;
167
+ }
101
168
  /**
102
169
  * 插入表格
103
170
  *
@@ -108,38 +175,44 @@ import { EditorUtils } from "./editorUtils";
108
175
  * @param editor Slate 编辑器实例
109
176
  * @param node 可选的节点,如果不提供则从编辑器获取
110
177
  */ export function insertTable(editor, node) {
111
- var _currentNode_, _currentNode_1;
112
- var currentNode = node || Array.from(getCurrentNodes(editor))[0];
178
+ var _resolveParagraphOrHead;
179
+ var _node_, _node_1, _currentNode_;
180
+ if ((node === null || node === void 0 ? void 0 : (_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.type) === 'column-cell') {
181
+ NativeTableEditor.insertTable(editor, {
182
+ rows: 3,
183
+ cols: 3,
184
+ at: _to_consumable_array(node[1]).concat([
185
+ 0
186
+ ])
187
+ });
188
+ return;
189
+ }
190
+ if (node !== undefined && ![
191
+ 'paragraph',
192
+ 'head'
193
+ ].includes((_node_1 = node[0]) === null || _node_1 === void 0 ? void 0 : _node_1.type)) {
194
+ return;
195
+ }
196
+ var currentNode = node === undefined ? (_resolveParagraphOrHead = resolveParagraphOrHead(editor)) !== null && _resolveParagraphOrHead !== void 0 ? _resolveParagraphOrHead : firstLowestElement(editor) : resolveParagraphOrHead(editor, node);
113
197
  if (currentNode && [
114
198
  'paragraph',
115
199
  'head'
116
200
  ].includes(currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_ = currentNode[0]) === null || _currentNode_ === void 0 ? void 0 : _currentNode_.type)) {
117
- var _currentNode_2, _currentNode_3;
118
- var path = (currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_2 = currentNode[0]) === null || _currentNode_2 === void 0 ? void 0 : _currentNode_2.type) === 'paragraph' && !Node.string(currentNode[0]) ? currentNode[1] : Path.next(currentNode[1]);
201
+ var _currentNode_1, _currentNode_2;
202
+ var path = (currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_1 = currentNode[0]) === null || _currentNode_1 === void 0 ? void 0 : _currentNode_1.type) === 'paragraph' && !Node.string(currentNode[0]) ? currentNode[1] : Path.next(currentNode[1]);
119
203
  // 使用原生表格编辑器插入表格
120
204
  NativeTableEditor.insertTable(editor, {
121
205
  rows: 3,
122
206
  cols: 3,
123
207
  at: path
124
208
  });
125
- if ((currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_3 = currentNode[0]) === null || _currentNode_3 === void 0 ? void 0 : _currentNode_3.type) === 'paragraph' && !Node.string(currentNode[0])) {
209
+ if ((currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_2 = currentNode[0]) === null || _currentNode_2 === void 0 ? void 0 : _currentNode_2.type) === 'paragraph' && !Node.string(currentNode[0])) {
126
210
  Transforms.delete(editor, {
127
211
  at: Path.next(path)
128
212
  });
129
213
  }
130
214
  Transforms.select(editor, Editor.start(editor, path));
131
215
  }
132
- if (currentNode && [
133
- 'column-cell'
134
- ].includes(currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_1 = currentNode[0]) === null || _currentNode_1 === void 0 ? void 0 : _currentNode_1.type)) {
135
- NativeTableEditor.insertTable(editor, {
136
- rows: 3,
137
- cols: 3,
138
- at: _to_consumable_array(currentNode[1]).concat([
139
- 0
140
- ])
141
- });
142
- }
143
216
  }
144
217
  /**
145
218
  * 插入代码块
@@ -151,7 +224,15 @@ import { EditorUtils } from "./editorUtils";
151
224
  * @param type 可选的代码块类型,'mermaid'表示流程图,'html'表示HTML渲染
152
225
  * @param node 可选的节点,如果不提供则从编辑器获取
153
226
  */ export function insertCodeBlock(editor, type, node) {
154
- var currentNode = node || Array.from(getCurrentNodes(editor))[0];
227
+ var _resolveParagraphOrHead;
228
+ var _node_;
229
+ if (node !== undefined && ![
230
+ 'paragraph',
231
+ 'head'
232
+ ].includes((_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.type)) {
233
+ return;
234
+ }
235
+ var currentNode = node === undefined ? (_resolveParagraphOrHead = resolveParagraphOrHead(editor)) !== null && _resolveParagraphOrHead !== void 0 ? _resolveParagraphOrHead : firstLowestElement(editor) : resolveParagraphOrHead(editor, node);
155
236
  if (currentNode && currentNode[0] && [
156
237
  'paragraph',
157
238
  'head'