@ant-design/agentic-ui 2.20.0 → 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.
|
@@ -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
|
|
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
|
};
|
|
@@ -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,
|
|
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),
|
|
133
|
-
var _useState3 = _sliced_to_array(useState(
|
|
134
|
-
var _useState4 = _sliced_to_array(useState(
|
|
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
|
-
//
|
|
180
|
-
|
|
165
|
+
// 从 schema 派生 htmlContent 和 schemaString
|
|
166
|
+
var htmlContent = useMemo(function() {
|
|
181
167
|
var _schema_component;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
310
|
-
// 立即更新 ref 值
|
|
311
|
-
htmlContentRef.current = newHtml;
|
|
289
|
+
setContent(newHtml, 'html');
|
|
312
290
|
},
|
|
313
291
|
setSchemaString: function(newJsonString) {
|
|
314
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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() {
|