@ant-design/agentic-ui 2.20.1 → 2.20.2

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.
@@ -100,7 +100,7 @@ import { CircleDashed, Copy, Play } from "@sofa-design/icons";
100
100
  import { Button, ConfigProvider, message } from "antd";
101
101
  import classNames from "classnames";
102
102
  import copy from "copy-to-clipboard";
103
- import React, { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useState } from "react";
103
+ import React, { forwardRef, useCallback, useContext, useImperativeHandle, useMemo, useState } from "react";
104
104
  import { I18nContext } from "../../I18n";
105
105
  import { SchemaRenderer } from "../SchemaRenderer";
106
106
  import { mdDataSchemaValidator } from "../validator";
@@ -129,31 +129,17 @@ import { useStyle } from "./style";
129
129
  };
130
130
  }), 2), schema = _useState[0], setSchema = _useState[1];
131
131
  var _useState1 = _sliced_to_array(useState(initialValues || {}), 2), values = _useState1[0], setValues = _useState1[1];
132
- var _useState2 = _sliced_to_array(useState(''), 2), schemaString = _useState2[0], setSchemaString = _useState2[1];
133
- var _useState3 = _sliced_to_array(useState(''), 2), htmlContent = _useState3[0], setHtmlContent = _useState3[1];
134
- var _useState4 = _sliced_to_array(useState(''), 2), validationError = _useState4[0], setValidationError = _useState4[1];
135
- var _useState5 = _sliced_to_array(useState({}), 2), renderedSchema = _useState5[0], setRenderedSchema = _useState5[1];
136
- var _useState6 = _sliced_to_array(useState(false), 2), isSchemaRendered = _useState6[0], setIsSchemaRendered = _useState6[1];
132
+ var _useState2 = _sliced_to_array(useState(''), 2), validationError = _useState2[0], setValidationError = _useState2[1];
133
+ var _useState3 = _sliced_to_array(useState({}), 2), renderedSchema = _useState3[0], setRenderedSchema = _useState3[1];
134
+ var _useState4 = _sliced_to_array(useState(false), 2), isSchemaRendered = _useState4[0], setIsSchemaRendered = _useState4[1];
137
135
  // 使用 ref 存储最新值,确保 ref 方法能立即获取到最新状态
138
136
  var schemaRef = React.useRef(schema);
139
- var htmlContentRef = React.useRef(htmlContent);
140
- var schemaStringRef = React.useRef(schemaString);
141
137
  // 同步更新 ref 值
142
138
  React.useEffect(function() {
143
139
  schemaRef.current = schema;
144
140
  }, [
145
141
  schema
146
142
  ]);
147
- React.useEffect(function() {
148
- htmlContentRef.current = htmlContent;
149
- }, [
150
- htmlContent
151
- ]);
152
- React.useEffect(function() {
153
- schemaStringRef.current = schemaString;
154
- }, [
155
- schemaString
156
- ]);
157
143
  // 将schema转换为JSON字符串
158
144
  var schemaToJson = useCallback(function(schemaData) {
159
145
  try {
@@ -176,17 +162,15 @@ import { useStyle } from "./style";
176
162
  }, [
177
163
  locale
178
164
  ]);
179
- // 初始化schema字符串
180
- useEffect(function() {
165
+ // schema 派生 htmlContent 和 schemaString
166
+ var htmlContent = useMemo(function() {
181
167
  var _schema_component;
182
- var jsonString = schemaToJson(schema);
183
- var html = ((_schema_component = schema.component) === null || _schema_component === void 0 ? void 0 : _schema_component.schema) || '';
184
- setSchemaString(jsonString);
185
- setHtmlContent(html);
186
- // 同步更新 ref
187
- schemaRef.current = schema;
188
- schemaStringRef.current = jsonString;
189
- htmlContentRef.current = html;
168
+ return ((_schema_component = schema.component) === null || _schema_component === void 0 ? void 0 : _schema_component.schema) || '';
169
+ }, [
170
+ schema
171
+ ]);
172
+ var schemaString = useMemo(function() {
173
+ return schemaToJson(schema);
190
174
  }, [
191
175
  schema,
192
176
  schemaToJson
@@ -220,8 +204,6 @@ import { useStyle } from "./style";
220
204
  ]);
221
205
  // 处理HTML内容变更
222
206
  var handleHtmlChange = useCallback(function(newHtml) {
223
- setHtmlContent(newHtml);
224
- htmlContentRef.current = newHtml;
225
207
  var newSchema = _object_spread_props(_object_spread({}, schemaRef.current), {
226
208
  component: _object_spread_props(_object_spread({}, schemaRef.current.component), {
227
209
  schema: newHtml
@@ -233,15 +215,9 @@ import { useStyle } from "./style";
233
215
  ]);
234
216
  // 处理JSON编辑器变更
235
217
  var handleJsonChange = useCallback(function(newJsonString) {
236
- setSchemaString(newJsonString);
237
- schemaStringRef.current = newJsonString;
238
218
  var newSchema = jsonToSchema(newJsonString);
239
219
  if (newSchema) {
240
- var _newSchema_component;
241
- var html = ((_newSchema_component = newSchema.component) === null || _newSchema_component === void 0 ? void 0 : _newSchema_component.schema) || '';
242
220
  handleSchemaChange(newSchema);
243
- setHtmlContent(html);
244
- htmlContentRef.current = html;
245
221
  }
246
222
  }, [
247
223
  jsonToSchema,
@@ -291,44 +267,39 @@ import { useStyle } from "./style";
291
267
  schemaString,
292
268
  handleCopyContent
293
269
  ]);
270
+ // 统一的设置内容方法,支持 HTML 或 JSON 字符串
271
+ var setContent = useCallback(function(content, type) {
272
+ if (type === 'html') {
273
+ handleHtmlChange(content);
274
+ } else {
275
+ handleJsonChange(content);
276
+ }
277
+ }, [
278
+ handleHtmlChange,
279
+ handleJsonChange
280
+ ]);
294
281
  // 暴露 ref 方法
295
282
  useImperativeHandle(ref, function() {
296
283
  return {
297
284
  setSchema: function(newSchema) {
298
- var _newSchema_component, _newSchema_component1;
299
285
  handleSchemaChange(newSchema);
300
- var newJsonString = schemaToJson(newSchema);
301
- setSchemaString(newJsonString);
302
- setHtmlContent(((_newSchema_component = newSchema.component) === null || _newSchema_component === void 0 ? void 0 : _newSchema_component.schema) || '');
303
- // 立即更新 ref 值,确保 get 方法能立即获取到最新值
304
286
  schemaRef.current = newSchema;
305
- schemaStringRef.current = newJsonString;
306
- htmlContentRef.current = ((_newSchema_component1 = newSchema.component) === null || _newSchema_component1 === void 0 ? void 0 : _newSchema_component1.schema) || '';
307
287
  },
308
288
  setHtmlContent: function(newHtml) {
309
- handleHtmlChange(newHtml);
310
- // 立即更新 ref 值
311
- htmlContentRef.current = newHtml;
289
+ setContent(newHtml, 'html');
312
290
  },
313
291
  setSchemaString: function(newJsonString) {
314
- handleJsonChange(newJsonString);
315
- // 立即更新 ref 值
316
- schemaStringRef.current = newJsonString;
317
- var newSchema = jsonToSchema(newJsonString);
318
- if (newSchema) {
319
- var _newSchema_component;
320
- schemaRef.current = newSchema;
321
- htmlContentRef.current = ((_newSchema_component = newSchema.component) === null || _newSchema_component === void 0 ? void 0 : _newSchema_component.schema) || '';
322
- }
292
+ setContent(newJsonString, 'json');
323
293
  },
324
294
  getSchema: function() {
325
295
  return schemaRef.current;
326
296
  },
327
297
  getHtmlContent: function() {
328
- return htmlContentRef.current;
298
+ var _schemaRef_current_component;
299
+ return ((_schemaRef_current_component = schemaRef.current.component) === null || _schemaRef_current_component === void 0 ? void 0 : _schemaRef_current_component.schema) || '';
329
300
  },
330
301
  getSchemaString: function() {
331
- return schemaStringRef.current;
302
+ return schemaToJson(schemaRef.current);
332
303
  },
333
304
  run: handleRunClick,
334
305
  copyHtml: handleCopyHtml,
@@ -336,13 +307,11 @@ import { useStyle } from "./style";
336
307
  };
337
308
  }, [
338
309
  handleSchemaChange,
339
- handleHtmlChange,
340
- handleJsonChange,
310
+ setContent,
341
311
  handleRunClick,
342
312
  handleCopyHtml,
343
313
  handleCopyJson,
344
- schemaToJson,
345
- jsonToSchema
314
+ schemaToJson
346
315
  ]);
347
316
  // 渲染预览区域
348
317
  var renderPreview = useMemo(function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/agentic-ui",
3
- "version": "2.20.1",
3
+ "version": "2.20.2",
4
4
  "description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
5
5
  "repository": "git@github.com:ant-design/agentic-ui.git",
6
6
  "license": "MIT",