@ant-design/agentic-ui 2.30.22 → 2.30.23

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 (53) 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/useKeyboard.js +46 -44
  17. package/dist/MarkdownEditor/editor/plugins/withCodeTagPlugin.js +1 -13
  18. package/dist/MarkdownEditor/editor/store.d.ts +3 -1
  19. package/dist/MarkdownEditor/editor/store.js +15 -29
  20. package/dist/MarkdownEditor/editor/utils/editorCommands.js +98 -17
  21. package/dist/MarkdownEditor/editor/utils/editorUtils.d.ts +11 -0
  22. package/dist/MarkdownEditor/editor/utils/editorUtils.js +43 -6
  23. package/dist/MarkdownEditor/editor/utils/keyboard.js +14 -12
  24. package/dist/MarkdownEditor/types.d.ts +36 -414
  25. package/dist/MarkdownEditor/types.js +1 -4
  26. package/dist/MarkdownInputField/MarkdownInputField.js +2 -0
  27. package/dist/MarkdownInputField/SendActions/index.js +7 -4
  28. package/dist/MarkdownInputField/SendButton/index.d.ts +6 -0
  29. package/dist/MarkdownInputField/SendButton/index.js +6 -0
  30. package/dist/MarkdownInputField/hooks/useMarkdownInputFieldHandlers.d.ts +2 -1
  31. package/dist/MarkdownInputField/hooks/useMarkdownInputFieldHandlers.js +6 -1
  32. package/dist/MarkdownRenderer/AnimationText.d.ts +1 -5
  33. package/dist/MarkdownRenderer/AnimationText.js +2 -8
  34. package/dist/MarkdownRenderer/CharacterQueue.d.ts +0 -2
  35. package/dist/MarkdownRenderer/CharacterQueue.js +2 -2
  36. package/dist/MarkdownRenderer/MarkdownRenderer.d.ts +1 -9
  37. package/dist/MarkdownRenderer/MarkdownRenderer.js +1 -9
  38. package/dist/MarkdownRenderer/StreamingCursor.d.ts +4 -0
  39. package/dist/MarkdownRenderer/StreamingCursor.js +20 -0
  40. package/dist/MarkdownRenderer/markdownReactShared.d.ts +8 -38
  41. package/dist/MarkdownRenderer/markdownReactShared.js +9 -45
  42. package/dist/MarkdownRenderer/renderers/ChartRenderer.js +9 -1
  43. package/dist/MarkdownRenderer/streaming/MarkdownBlockPiece.d.ts +1 -3
  44. package/dist/MarkdownRenderer/streaming/MarkdownBlockPiece.js +16 -28
  45. package/dist/MarkdownRenderer/style.js +18 -0
  46. package/dist/MarkdownRenderer/types.d.ts +14 -86
  47. package/dist/MarkdownRenderer/useStreaming.d.ts +1 -10
  48. package/dist/MarkdownRenderer/useStreaming.js +5 -13
  49. package/dist/ThoughtChainList/MarkdownEditor.d.ts +1 -35
  50. package/dist/ThoughtChainList/MarkdownEditor.js +5 -44
  51. package/dist/Workspace/RealtimeFollow/index.d.ts +3 -0
  52. package/dist/Workspace/RealtimeFollow/index.js +5 -3
  53. 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
  }
@@ -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'
@@ -11,6 +11,17 @@ export declare class EditorUtils {
11
11
  readonly text: "";
12
12
  }];
13
13
  };
14
+ /**
15
+ * 通过 Slate Transforms API 安全替换编辑器全部内容。
16
+ * 避免直接赋值 editor.children,确保 Operation/History/Normalizer 管线正常运行。
17
+ *
18
+ * @param editor - 编辑器实例
19
+ * @param nodes - 新的节点列表
20
+ * @param options.withoutHistory - 是否跳过 History 记录(默认 true,适用于外部数据同步场景)
21
+ */
22
+ static replaceEditorContent(editor: Editor, nodes: Node[], options?: {
23
+ withoutHistory?: boolean;
24
+ }): void;
14
25
  static hasPath(editor: Editor, path: Path): boolean;
15
26
  static focus(editor: Editor): void;
16
27
  static blur(editor: Editor): void;
@@ -135,6 +135,7 @@ function _unsupported_iterable_to_array(o, minLen) {
135
135
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
136
136
  }
137
137
  /* eslint-disable no-param-reassign */ import { Editor, Element, Node, Path, Point, Range, Text, Transforms } from "slate";
138
+ import { HistoryEditor } from "slate-history";
138
139
  import { ReactEditor } from "slate-react";
139
140
  import { getMediaType } from "./dom";
140
141
  export var EditorUtils = /*#__PURE__*/ function() {
@@ -156,6 +157,44 @@ export var EditorUtils = /*#__PURE__*/ function() {
156
157
  };
157
158
  }
158
159
  },
160
+ {
161
+ key: "replaceEditorContent",
162
+ value: /**
163
+ * 通过 Slate Transforms API 安全替换编辑器全部内容。
164
+ * 避免直接赋值 editor.children,确保 Operation/History/Normalizer 管线正常运行。
165
+ *
166
+ * @param editor - 编辑器实例
167
+ * @param nodes - 新的节点列表
168
+ * @param options.withoutHistory - 是否跳过 History 记录(默认 true,适用于外部数据同步场景)
169
+ */ function replaceEditorContent(editor, nodes, options) {
170
+ var _ref = options || {}, _ref_withoutHistory = _ref.withoutHistory, withoutHistory = _ref_withoutHistory === void 0 ? true : _ref_withoutHistory;
171
+ var doReplace = function doReplace() {
172
+ Editor.withoutNormalizing(editor, function() {
173
+ if (editor.selection) {
174
+ Transforms.deselect(editor);
175
+ }
176
+ var totalChildren = editor.children.length;
177
+ for(var i = totalChildren - 1; i >= 0; i--){
178
+ Transforms.removeNodes(editor, {
179
+ at: [
180
+ i
181
+ ]
182
+ });
183
+ }
184
+ Transforms.insertNodes(editor, nodes, {
185
+ at: [
186
+ 0
187
+ ]
188
+ });
189
+ });
190
+ };
191
+ if (withoutHistory && HistoryEditor.isHistoryEditor(editor)) {
192
+ HistoryEditor.withoutSaving(editor, doReplace);
193
+ } else {
194
+ doReplace();
195
+ }
196
+ }
197
+ },
159
198
  {
160
199
  key: "hasPath",
161
200
  value: function hasPath(editor, path) {
@@ -485,18 +524,16 @@ export var EditorUtils = /*#__PURE__*/ function() {
485
524
  * @param insertNodes - 可选的插入节点数组。如果未提供,则使用默认段落节点
486
525
  * @param force - 可选的布尔值或历史记录对象。如果为布尔值,则强制重置历史记录;如果为历史记录对象,则使用提供的历史记录
487
526
  */ function reset(editor, insertNodes, force) {
488
- var nodesToInsert = insertNodes || [
527
+ var nodesToInsert = JSON.parse(JSON.stringify(insertNodes || [
489
528
  EditorUtils.p
490
- ];
491
- // 深克隆节点以避免引用问题
492
- editor.children = JSON.parse(JSON.stringify(nodesToInsert));
493
- if (force) {
529
+ ]));
530
+ EditorUtils.replaceEditorContent(editor, nodesToInsert);
531
+ if (force && HistoryEditor.isHistoryEditor(editor)) {
494
532
  editor.history = typeof force === 'boolean' ? {
495
533
  redos: [],
496
534
  undos: []
497
535
  } : force;
498
536
  }
499
- editor.onChange();
500
537
  }
501
538
  },
502
539
  {
@@ -884,11 +884,11 @@ export var useSystemKeyboard = function useSystemKeyboard(keyTask$, store, props
884
884
  try {
885
885
  copy(url);
886
886
  } catch (error) {}
887
- if (isHotkey('mod+x', e)) {
888
- Transforms.delete(store === null || store === void 0 ? void 0 : store.editor, {
887
+ if (isHotkey('mod+x', e) && (store === null || store === void 0 ? void 0 : store.editor)) {
888
+ Transforms.delete(store.editor, {
889
889
  at: node[1]
890
890
  });
891
- ReactEditor.focus(store === null || store === void 0 ? void 0 : store.editor);
891
+ ReactEditor.focus(store.editor);
892
892
  }
893
893
  }
894
894
  if ((node === null || node === void 0 ? void 0 : (_node_2 = node[0]) === null || _node_2 === void 0 ? void 0 : _node_2.type) === 'attach') {
@@ -897,11 +897,11 @@ export var useSystemKeyboard = function useSystemKeyboard(keyTask$, store, props
897
897
  try {
898
898
  copy(url1);
899
899
  } catch (error) {}
900
- if (isHotkey('mod+x', e)) {
901
- Transforms.delete(store === null || store === void 0 ? void 0 : store.editor, {
900
+ if (isHotkey('mod+x', e) && (store === null || store === void 0 ? void 0 : store.editor)) {
901
+ Transforms.delete(store.editor, {
902
902
  at: node[1]
903
903
  });
904
- ReactEditor.focus(store === null || store === void 0 ? void 0 : store.editor);
904
+ ReactEditor.focus(store.editor);
905
905
  }
906
906
  }
907
907
  }
@@ -909,12 +909,14 @@ export var useSystemKeyboard = function useSystemKeyboard(keyTask$, store, props
909
909
  var _task_curNodes = _sliced_to_array(task.curNodes, 1), node1 = _task_curNodes[0];
910
910
  if ((node1 === null || node1 === void 0 ? void 0 : node1[0].type) === 'media') {
911
911
  e.preventDefault();
912
- Transforms.removeNodes(task.editor, {
913
- at: node1[1]
914
- });
915
- Transforms.insertNodes(task.editor, EditorUtils.p, {
916
- at: node1[1],
917
- select: true
912
+ Editor.withoutNormalizing(task.editor, function() {
913
+ Transforms.removeNodes(task.editor, {
914
+ at: node1[1]
915
+ });
916
+ Transforms.insertNodes(task.editor, EditorUtils.p, {
917
+ at: node1[1],
918
+ select: true
919
+ });
918
920
  });
919
921
  ReactEditor.focus(task.editor);
920
922
  }