@ant-design/agentic-ui 2.19.0 → 2.20.1

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.
@@ -416,7 +416,10 @@ var composeEditors = function(editor, plugins) {
416
416
  position: 'relative',
417
417
  gap: 24,
418
418
  outline: 'none'
419
- }, contentStyle),
419
+ }, (contentStyle === null || contentStyle === void 0 ? void 0 : contentStyle.padding) !== undefined ? {
420
+ '--content-padding': "".concat(typeof contentStyle.padding === 'number' ? "".concat(contentStyle.padding, "px") : contentStyle.padding),
421
+ padding: contentStyle.padding
422
+ } : {}, contentStyle),
420
423
  ref: function(dom) {
421
424
  markdownContainerRef.current = dom;
422
425
  setMountedStatus(true);
@@ -84,9 +84,11 @@ var genStyle = function(token) {
84
84
  outline: 'none !important'
85
85
  },
86
86
  '&-content': _define_property({
87
- padding: '4px 20px'
87
+ // 默认 padding,可以通过 contentStyle 覆盖
88
+ // 使用 CSS 变量,允许通过内联样式覆盖
89
+ padding: 'var(--content-padding, 4px 20px)'
88
90
  }, "@media (max-width: ".concat(MOBILE_BREAKPOINT, ")"), {
89
- padding: '4px 4px'
91
+ padding: 'var(--content-padding, 4px 4px)'
90
92
  })
91
93
  });
92
94
  };
@@ -22,11 +22,28 @@ export interface SchemaEditorProps {
22
22
  ALLOWED_TAGS?: string[];
23
23
  ALLOWED_ATTR?: string[];
24
24
  };
25
+ /** 自定义操作按钮,插入到 HTML 编辑器头部按钮区域 */
26
+ htmlActions?: React.ReactNode[];
25
27
  }
26
- /**
27
- * Schema编辑器组件
28
- *
29
- * 提供schema的实时编辑和预览功能,底层使用AceEditor编辑schema中的HTML内容
30
- */
31
- export declare function SchemaEditor({ initialSchema, initialValues, height, readonly, onChange, className, showPreview, previewConfig, }: SchemaEditorProps): React.JSX.Element;
28
+ export interface SchemaEditorRef {
29
+ /** 设置 Schema 数据 */
30
+ setSchema: (schema: LowCodeSchema) => void;
31
+ /** 设置 HTML 模板内容 */
32
+ setHtmlContent: (html: string) => void;
33
+ /** 设置 Schema JSON 字符串 */
34
+ setSchemaString: (jsonString: string) => void;
35
+ /** 获取当前 Schema 数据 */
36
+ getSchema: () => LowCodeSchema;
37
+ /** 获取当前 HTML 模板内容 */
38
+ getHtmlContent: () => string;
39
+ /** 获取当前 Schema JSON 字符串 */
40
+ getSchemaString: () => string;
41
+ /** 运行预览 */
42
+ run: () => void;
43
+ /** 复制 HTML 内容 */
44
+ copyHtml: () => void;
45
+ /** 复制 JSON 内容 */
46
+ copyJson: () => void;
47
+ }
48
+ export declare const SchemaEditor: React.ForwardRefExoticComponent<SchemaEditorProps & React.RefAttributes<SchemaEditorRef>>;
32
49
  export default SchemaEditor;
@@ -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, { useCallback, useContext, useEffect, useMemo, useState } from "react";
103
+ import React, { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useState } from "react";
104
104
  import { I18nContext } from "../../I18n";
105
105
  import { SchemaRenderer } from "../SchemaRenderer";
106
106
  import { mdDataSchemaValidator } from "../validator";
@@ -110,8 +110,8 @@ import { useStyle } from "./style";
110
110
  * Schema编辑器组件
111
111
  *
112
112
  * 提供schema的实时编辑和预览功能,底层使用AceEditor编辑schema中的HTML内容
113
- */ export function SchemaEditor(param) {
114
- var initialSchema = param.initialSchema, _param_initialValues = param.initialValues, initialValues = _param_initialValues === void 0 ? {} : _param_initialValues, _param_height = param.height, height = _param_height === void 0 ? 600 : _param_height, _param_readonly = param.readonly, readonly = _param_readonly === void 0 ? false : _param_readonly, onChange = param.onChange, _param_className = param.className, className = _param_className === void 0 ? '' : _param_className, _param_showPreview = param.showPreview, showPreview = _param_showPreview === void 0 ? true : _param_showPreview, previewConfig = param.previewConfig;
113
+ */ var SchemaEditorComponent = /*#__PURE__*/ forwardRef(function(param, ref) {
114
+ var initialSchema = param.initialSchema, _param_initialValues = param.initialValues, initialValues = _param_initialValues === void 0 ? {} : _param_initialValues, _param_height = param.height, height = _param_height === void 0 ? 600 : _param_height, _param_readonly = param.readonly, readonly = _param_readonly === void 0 ? false : _param_readonly, onChange = param.onChange, _param_className = param.className, className = _param_className === void 0 ? '' : _param_className, _param_showPreview = param.showPreview, showPreview = _param_showPreview === void 0 ? true : _param_showPreview, previewConfig = param.previewConfig, htmlActions = param.htmlActions;
115
115
  // 使用 ConfigProvider 获取前缀类名
116
116
  var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
117
117
  var prefixCls = getPrefixCls('schema-editor');
@@ -134,6 +134,26 @@ import { useStyle } from "./style";
134
134
  var _useState4 = _sliced_to_array(useState(''), 2), validationError = _useState4[0], setValidationError = _useState4[1];
135
135
  var _useState5 = _sliced_to_array(useState({}), 2), renderedSchema = _useState5[0], setRenderedSchema = _useState5[1];
136
136
  var _useState6 = _sliced_to_array(useState(false), 2), isSchemaRendered = _useState6[0], setIsSchemaRendered = _useState6[1];
137
+ // 使用 ref 存储最新值,确保 ref 方法能立即获取到最新状态
138
+ var schemaRef = React.useRef(schema);
139
+ var htmlContentRef = React.useRef(htmlContent);
140
+ var schemaStringRef = React.useRef(schemaString);
141
+ // 同步更新 ref 值
142
+ React.useEffect(function() {
143
+ schemaRef.current = schema;
144
+ }, [
145
+ schema
146
+ ]);
147
+ React.useEffect(function() {
148
+ htmlContentRef.current = htmlContent;
149
+ }, [
150
+ htmlContent
151
+ ]);
152
+ React.useEffect(function() {
153
+ schemaStringRef.current = schemaString;
154
+ }, [
155
+ schemaString
156
+ ]);
137
157
  // 将schema转换为JSON字符串
138
158
  var schemaToJson = useCallback(function(schemaData) {
139
159
  try {
@@ -159,8 +179,14 @@ import { useStyle } from "./style";
159
179
  // 初始化schema字符串
160
180
  useEffect(function() {
161
181
  var _schema_component;
162
- setSchemaString(schemaToJson(schema));
163
- setHtmlContent(((_schema_component = schema.component) === null || _schema_component === void 0 ? void 0 : _schema_component.schema) || '');
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;
164
190
  }, [
165
191
  schema,
166
192
  schemaToJson
@@ -195,24 +221,27 @@ import { useStyle } from "./style";
195
221
  // 处理HTML内容变更
196
222
  var handleHtmlChange = useCallback(function(newHtml) {
197
223
  setHtmlContent(newHtml);
198
- var newSchema = _object_spread_props(_object_spread({}, schema), {
199
- component: _object_spread_props(_object_spread({}, schema.component), {
224
+ htmlContentRef.current = newHtml;
225
+ var newSchema = _object_spread_props(_object_spread({}, schemaRef.current), {
226
+ component: _object_spread_props(_object_spread({}, schemaRef.current.component), {
200
227
  schema: newHtml
201
228
  })
202
229
  });
203
230
  handleSchemaChange(newSchema);
204
231
  }, [
205
- schema,
206
232
  handleSchemaChange
207
233
  ]);
208
234
  // 处理JSON编辑器变更
209
235
  var handleJsonChange = useCallback(function(newJsonString) {
210
236
  setSchemaString(newJsonString);
237
+ schemaStringRef.current = newJsonString;
211
238
  var newSchema = jsonToSchema(newJsonString);
212
239
  if (newSchema) {
213
240
  var _newSchema_component;
241
+ var html = ((_newSchema_component = newSchema.component) === null || _newSchema_component === void 0 ? void 0 : _newSchema_component.schema) || '';
214
242
  handleSchemaChange(newSchema);
215
- setHtmlContent(((_newSchema_component = newSchema.component) === null || _newSchema_component === void 0 ? void 0 : _newSchema_component.schema) || '');
243
+ setHtmlContent(html);
244
+ htmlContentRef.current = html;
216
245
  }
217
246
  }, [
218
247
  jsonToSchema,
@@ -220,18 +249,14 @@ import { useStyle } from "./style";
220
249
  ]);
221
250
  // 处理运行按钮点击
222
251
  var handleRunClick = useCallback(function() {
223
- setRenderedSchema(_object_spread({}, schema));
252
+ var currentSchema = schemaRef.current;
253
+ setRenderedSchema(_object_spread({}, currentSchema));
224
254
  // 更新values状态,使用schema中的initialValues
225
- if (schema.initialValues) {
226
- setValues(schema.initialValues);
255
+ if (currentSchema.initialValues) {
256
+ setValues(currentSchema.initialValues);
227
257
  }
228
258
  setIsSchemaRendered(true);
229
- }, [
230
- schema,
231
- setRenderedSchema,
232
- setValues,
233
- setIsSchemaRendered
234
- ]);
259
+ }, []);
235
260
  // 复制函数
236
261
  var handleCopyContent = useCallback(function(content, type) {
237
262
  if (!content || !content.trim()) {
@@ -266,6 +291,59 @@ import { useStyle } from "./style";
266
291
  schemaString,
267
292
  handleCopyContent
268
293
  ]);
294
+ // 暴露 ref 方法
295
+ useImperativeHandle(ref, function() {
296
+ return {
297
+ setSchema: function(newSchema) {
298
+ var _newSchema_component, _newSchema_component1;
299
+ 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
+ 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
+ },
308
+ setHtmlContent: function(newHtml) {
309
+ handleHtmlChange(newHtml);
310
+ // 立即更新 ref 值
311
+ htmlContentRef.current = newHtml;
312
+ },
313
+ 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
+ }
323
+ },
324
+ getSchema: function() {
325
+ return schemaRef.current;
326
+ },
327
+ getHtmlContent: function() {
328
+ return htmlContentRef.current;
329
+ },
330
+ getSchemaString: function() {
331
+ return schemaStringRef.current;
332
+ },
333
+ run: handleRunClick,
334
+ copyHtml: handleCopyHtml,
335
+ copyJson: handleCopyJson
336
+ };
337
+ }, [
338
+ handleSchemaChange,
339
+ handleHtmlChange,
340
+ handleJsonChange,
341
+ handleRunClick,
342
+ handleCopyHtml,
343
+ handleCopyJson,
344
+ schemaToJson,
345
+ jsonToSchema
346
+ ]);
269
347
  // 渲染预览区域
270
348
  var renderPreview = useMemo(function() {
271
349
  if (!showPreview) return null;
@@ -331,7 +409,7 @@ import { useStyle } from "./style";
331
409
  }
332
410
  }),
333
411
  onClick: handleCopyHtml
334
- }))), /*#__PURE__*/ React.createElement("div", {
412
+ }), htmlActions)), /*#__PURE__*/ React.createElement("div", {
335
413
  className: classNames("".concat(prefixCls, "-html-content"), hashId)
336
414
  }, /*#__PURE__*/ React.createElement(AceEditorWrapper, {
337
415
  value: htmlContent,
@@ -347,6 +425,7 @@ import { useStyle } from "./style";
347
425
  locale,
348
426
  handleRunClick,
349
427
  handleCopyHtml,
428
+ htmlActions,
350
429
  prefixCls
351
430
  ]);
352
431
  // 渲染JSON编辑器
@@ -397,5 +476,7 @@ import { useStyle } from "./style";
397
476
  }, renderPreview), /*#__PURE__*/ React.createElement("div", {
398
477
  className: classNames("".concat(prefixCls, "-right"), hashId)
399
478
  }, renderHtmlEditor, renderJsonEditor))));
400
- }
479
+ });
480
+ SchemaEditorComponent.displayName = 'SchemaEditor';
481
+ export var SchemaEditor = SchemaEditorComponent;
401
482
  export default SchemaEditor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/agentic-ui",
3
- "version": "2.19.0",
3
+ "version": "2.20.1",
4
4
  "description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
5
5
  "repository": "git@github.com:ant-design/agentic-ui.git",
6
6
  "license": "MIT",