@ant-design/agentic-ui 2.29.30 → 2.29.31

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.
@@ -171,7 +171,6 @@ export var BackspaceKey = /*#__PURE__*/ function() {
171
171
  var listItem = parent1[0];
172
172
  var firstChild = Element.isElement(listItem) && listItem.children.length > 0 ? listItem.children[0] : null;
173
173
  var isEmptyListItem = firstChild && Element.isElement(firstChild) && firstChild.type === 'paragraph' && Node.string(firstChild).trim() === '' && listItem.children.length === 1; // 只有第一个段落,没有嵌套列表
174
- console.log('isEmptyListItem', isEmptyListItem);
175
174
  // 如果 list-item 为空,优先执行删除逻辑
176
175
  if (isEmptyListItem) {
177
176
  // 使用新的拆分逻辑处理空的list-item
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
2
  import { Editor } from 'slate';
3
3
  export declare class MatchKey {
4
- private readonly editor;
5
- constructor(editor: Editor);
4
+ private readonly editorRef;
5
+ constructor(editorRef: React.MutableRefObject<Editor | null>);
6
6
  private createParams;
7
7
  run(e: React.KeyboardEvent): boolean;
8
8
  }
@@ -84,20 +84,20 @@ import { Editor, Element, Node, Range } from "slate";
84
84
  import { TextMatchNodes } from "../elements";
85
85
  export var MatchKey = /*#__PURE__*/ function() {
86
86
  "use strict";
87
- function MatchKey(editor) {
87
+ function MatchKey(editorRef) {
88
88
  _class_call_check(this, MatchKey);
89
- _define_property(this, "editor", void 0);
90
- this.editor = editor;
89
+ _define_property(this, "editorRef", void 0);
90
+ this.editorRef = editorRef;
91
91
  }
92
92
  _create_class(MatchKey, [
93
93
  {
94
94
  key: "createParams",
95
- value: function createParams(node, match) {
95
+ value: function createParams(editor, node, match) {
96
96
  return {
97
97
  el: node[0],
98
98
  path: node[1],
99
- editor: this.editor,
100
- sel: this.editor.selection,
99
+ editor: editor,
100
+ sel: editor.selection,
101
101
  match: match,
102
102
  startText: match[0]
103
103
  };
@@ -107,7 +107,9 @@ export var MatchKey = /*#__PURE__*/ function() {
107
107
  key: "run",
108
108
  value: function run(e) {
109
109
  var _node_;
110
- var _Editor_nodes = _sliced_to_array(Editor.nodes(this.editor, {
110
+ var editor = this.editorRef.current;
111
+ if (!editor) return false;
112
+ var _Editor_nodes = _sliced_to_array(Editor.nodes(editor, {
111
113
  match: function match(n) {
112
114
  return Element.isElement(n);
113
115
  },
@@ -116,7 +118,7 @@ export var MatchKey = /*#__PURE__*/ function() {
116
118
  if (!node || [
117
119
  'code'
118
120
  ].includes(node === null || node === void 0 ? void 0 : (_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.type)) return false;
119
- var sel = this.editor.selection;
121
+ var sel = editor.selection;
120
122
  if (!sel || !Range.isCollapsed(sel)) return false;
121
123
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
122
124
  try {
@@ -124,14 +126,14 @@ export var MatchKey = /*#__PURE__*/ function() {
124
126
  var n = _step.value;
125
127
  if (_type_of(n.matchKey) === 'object' ? n.matchKey.test(e.key) : n.matchKey === e.key) {
126
128
  if (n.checkAllow && !n.checkAllow({
127
- editor: this.editor,
129
+ editor: editor,
128
130
  node: node,
129
131
  sel: sel
130
132
  })) continue;
131
- var str = Node.string(Node.leaf(this.editor, sel.anchor.path)).slice(0, sel.anchor.offset) + e.key;
133
+ var str = Node.string(Node.leaf(editor, sel.anchor.path)).slice(0, sel.anchor.offset) + e.key;
132
134
  var m = str.match(n.reg);
133
135
  if (m) {
134
- if (n.run(this.createParams(node, m))) {
136
+ if (n.run(this.createParams(editor, node, m))) {
135
137
  e.preventDefault();
136
138
  return true;
137
139
  }
@@ -49,7 +49,7 @@ function _unsupported_iterable_to_array(o, minLen) {
49
49
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
50
50
  }
51
51
  import isHotkey from "is-hotkey";
52
- import { useMemo } from "react";
52
+ import { useRef, useMemo } from "react";
53
53
  import { Editor, Element, Node, Path, Range, Transforms } from "slate";
54
54
  import { EditorUtils } from "../utils/editorUtils";
55
55
  import { BackspaceKey } from "./hotKeyCommands/backspace";
@@ -98,17 +98,21 @@ import { useEditorStore } from "../store";
98
98
  * - 与编辑器状态深度集成,实现上下文相关的行为
99
99
  * - 提供良好的用户体验和 Markdown 编辑效率
100
100
  */ export var useKeyboard = function useKeyboard(store, markdownEditorRef, props) {
101
+ var _props_markdown;
101
102
  var _useEditorStore = useEditorStore(), openInsertCompletion = _useEditorStore.openInsertCompletion, insertCompletionText$ = _useEditorStore.insertCompletionText$, setOpenInsertCompletion = _useEditorStore.setOpenInsertCompletion, openJinjaTemplate = _useEditorStore.openJinjaTemplate, setOpenJinjaTemplate = _useEditorStore.setOpenJinjaTemplate, setJinjaAnchorPath = _useEditorStore.setJinjaAnchorPath, jinjaTemplatePanelEnabled = _useEditorStore.jinjaTemplatePanelEnabled, editorProps = _useEditorStore.editorProps;
102
103
  // 从 editorProps.jinja 读取(BaseMarkdownEditor 已写入 effectiveJinja),支持插件配置的 trigger
103
104
  var effectiveJinja = editorProps === null || editorProps === void 0 ? void 0 : editorProps.jinja;
104
105
  var jinjaTrigger = (effectiveJinja === null || effectiveJinja === void 0 ? void 0 : effectiveJinja.templatePanel) && _type_of(effectiveJinja.templatePanel) === 'object' && effectiveJinja.templatePanel.trigger || '{}';
106
+ var matchKeyRef = useRef(null);
107
+ if (matchKeyRef.current === null) {
108
+ matchKeyRef.current = new MatchKey(markdownEditorRef);
109
+ }
105
110
  return useMemo(function() {
106
111
  var tab = new TabKey(markdownEditorRef.current);
107
112
  var backspace = new BackspaceKey(markdownEditorRef.current);
108
113
  var enter = new EnterKey(store, backspace);
109
- var match = new MatchKey(markdownEditorRef.current);
110
114
  return function(e) {
111
- var _props_markdown, _node_;
115
+ var _props_markdown, _e_nativeEvent, _node_;
112
116
  // 只读模式下跳过所有键盘处理,提升性能
113
117
  if (props.readonly) return;
114
118
  // 处理表格键盘事件
@@ -156,8 +160,10 @@ import { useEditorStore } from "../store";
156
160
  if (isHotkey('mod+shift+s', e)) {
157
161
  e.preventDefault();
158
162
  }
159
- if (props === null || props === void 0 ? void 0 : (_props_markdown = props.markdown) === null || _props_markdown === void 0 ? void 0 : _props_markdown.matchInputToNode) {
160
- if (match.run(e)) return;
163
+ // 仅当显式开启 matchInputToNode 时才执行输入转节点(如 "- " 转列表),默认关闭
164
+ // IME 输入法组合期间不触发,避免输入「-」后按空格选字时误转为列表
165
+ 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)) {
166
+ if (matchKeyRef.current.run(e)) return;
161
167
  }
162
168
  if (e.key.toLowerCase().startsWith('arrow')) {
163
169
  if ([
@@ -273,6 +279,7 @@ import { useEditorStore } from "../store";
273
279
  }, [
274
280
  markdownEditorRef.current,
275
281
  props === null || props === void 0 ? void 0 : props.readonly,
282
+ props === null || props === void 0 ? void 0 : (_props_markdown = props.markdown) === null || _props_markdown === void 0 ? void 0 : _props_markdown.matchInputToNode,
276
283
  openInsertCompletion,
277
284
  insertCompletionText$,
278
285
  setOpenInsertCompletion,
@@ -151,10 +151,12 @@ import { Editor, Element, Node, Transforms } from "slate";
151
151
  var child1 = node.children[i];
152
152
  if (Element.isElement(child1)) {
153
153
  if (!isListType(child1)) {
154
- // 如果不是列表类型,且不是第一个块级元素,需要处理
155
- // 如果它是块级元素,应该移到前面或转换为列表
156
154
  if (Editor.isBlock(editor, child1)) {
157
- // 将块级元素包裹为新的 list-item,并创建新的列表
155
+ // paragraph 不处理,直接返回,避免 "-" 等被误转为嵌套列表
156
+ if (child1.type === 'paragraph') return;
157
+ var childPath1 = _to_consumable_array(path).concat([
158
+ i
159
+ ]);
158
160
  var listType = getListType();
159
161
  Transforms.wrapNodes(editor, {
160
162
  type: 'list-item',
@@ -163,17 +165,13 @@ import { Editor, Element, Node, Transforms } from "slate";
163
165
  id: '',
164
166
  children: []
165
167
  }, {
166
- at: _to_consumable_array(path).concat([
167
- i
168
- ])
168
+ at: childPath1
169
169
  });
170
170
  Transforms.wrapNodes(editor, {
171
171
  type: listType,
172
172
  children: []
173
173
  }, {
174
- at: _to_consumable_array(path).concat([
175
- i
176
- ])
174
+ at: childPath1
177
175
  });
178
176
  return;
179
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/agentic-ui",
3
- "version": "2.29.30",
3
+ "version": "2.29.31",
4
4
  "description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
5
5
  "repository": "git@github.com:ant-design/agentic-ui.git",
6
6
  "license": "MIT",