react-ai-renderer 0.1.18 → 0.1.19
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.
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ interface BaseComponentHandler {
|
|
|
37
37
|
}
|
|
38
38
|
interface ComponentHandler extends BaseComponentHandler {
|
|
39
39
|
selfClosing: boolean;
|
|
40
|
+
/** 组件开始渲染时的钩子(组件进入渲染流程时立即调用) */
|
|
41
|
+
onRenderStart?: (item: ComponentData$1, scope: any) => void;
|
|
40
42
|
/** 组件渲染过程中的钩子(当 isComplete 为 false 时调用) */
|
|
41
43
|
onRenderProcess?: (item: ComponentData$1, scope: any) => void;
|
|
42
44
|
/** 组件渲染完成后的钩子(当 isComplete 为 true 时调用) */
|
|
@@ -60,10 +62,12 @@ interface EnhancedComponentConfig {
|
|
|
60
62
|
loader?: React.ComponentType<any> | React.ReactElement | string | boolean | ((componentName: string) => React.ReactElement);
|
|
61
63
|
/** 骨架图配置,用于在加载时显示骨架图。如果未提供且 loader 也未提供,将自动根据组件名称生成骨架图 */
|
|
62
64
|
skeleton?: SkeletonConfig;
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
+
/** 组件开始渲染时的钩子 */
|
|
66
|
+
onRenderStart?: (item: ComponentData$1, scope: any) => void;
|
|
65
67
|
/** 组件渲染过程中的钩子 */
|
|
66
68
|
onRenderProcess?: (item: ComponentData$1, scope: any) => void;
|
|
69
|
+
/** 组件渲染完成后的钩子 */
|
|
70
|
+
onRenderFinished?: (item: ComponentData$1, scope: any) => void;
|
|
67
71
|
/** 是否自闭合 */
|
|
68
72
|
selfClosing?: boolean;
|
|
69
73
|
}
|
package/dist/index.js
CHANGED
|
@@ -58376,6 +58376,12 @@ function formatProps(props) {
|
|
|
58376
58376
|
key = _b[0],
|
|
58377
58377
|
value = _b[1];
|
|
58378
58378
|
if (typeof value === 'string') {
|
|
58379
|
+
var trimmedValue = value.trim();
|
|
58380
|
+
var isArrowFunction = trimmedValue.includes('=>');
|
|
58381
|
+
var isRegularFunction = trimmedValue.startsWith('function');
|
|
58382
|
+
if (isArrowFunction || isRegularFunction) {
|
|
58383
|
+
return "".concat(key, "={").concat(value, "}");
|
|
58384
|
+
}
|
|
58379
58385
|
return "".concat(key, "=\"").concat(value, "\"");
|
|
58380
58386
|
}
|
|
58381
58387
|
try {
|
|
@@ -58459,6 +58465,9 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
|
|
|
58459
58465
|
componentHandler = allComponentHandlers.find(function (c) {
|
|
58460
58466
|
return c.name === item.value;
|
|
58461
58467
|
});
|
|
58468
|
+
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderStart) {
|
|
58469
|
+
componentHandler.onRenderStart(item, scope);
|
|
58470
|
+
}
|
|
58462
58471
|
props = __assign({}, item.props);
|
|
58463
58472
|
propsString = formatProps(props);
|
|
58464
58473
|
propsString += " scope={props.scope}";
|
|
@@ -58481,16 +58490,13 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
|
|
|
58481
58490
|
componentString = (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.selfClosing) ? "<".concat(item.value, " ").concat(propsString, " />") : ["<".concat(item.value, " ").concat(propsString, ">"), childrenContent_1, "</".concat(item.value, ">")].join('\n');
|
|
58482
58491
|
// 调用组件的渲染钩子
|
|
58483
58492
|
if (isComplete) {
|
|
58484
|
-
// 渲染完成后的钩子
|
|
58485
58493
|
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderFinished) {
|
|
58486
58494
|
componentHandler.onRenderFinished(item, scope);
|
|
58487
58495
|
}
|
|
58488
58496
|
} else {
|
|
58489
|
-
// 渲染过程中的钩子
|
|
58490
58497
|
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderProcess) {
|
|
58491
58498
|
componentHandler.onRenderProcess(item, scope);
|
|
58492
58499
|
} else if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRender) {
|
|
58493
|
-
// 向后兼容:如果存在旧的 onRender,也调用它
|
|
58494
58500
|
componentHandler.onRender(item, scope);
|
|
58495
58501
|
}
|
|
58496
58502
|
}
|
|
@@ -59297,14 +59303,14 @@ function convertComponentsToHandlers(components, componentHandlers) {
|
|
|
59297
59303
|
name = _b[0],
|
|
59298
59304
|
componentValue = _b[1];
|
|
59299
59305
|
if (isEnhancedComponentConfig(componentValue)) {
|
|
59300
|
-
// 增强模式:从配置对象中提取信息
|
|
59301
59306
|
var config = componentValue;
|
|
59302
59307
|
return {
|
|
59303
59308
|
component: config.value,
|
|
59304
59309
|
name: name,
|
|
59305
59310
|
selfClosing: config.selfClosing !== undefined ? config.selfClosing : isSelfClosingComponent(config.value),
|
|
59306
|
-
|
|
59311
|
+
onRenderStart: config.onRenderStart,
|
|
59307
59312
|
onRenderProcess: config.onRenderProcess,
|
|
59313
|
+
onRenderFinished: config.onRenderFinished,
|
|
59308
59314
|
loader: config.loader,
|
|
59309
59315
|
label: config.label
|
|
59310
59316
|
};
|
|
@@ -59390,6 +59396,7 @@ function ReactAIRenderer(_a) {
|
|
|
59390
59396
|
if (!resultContent) return [3 /*break*/, 8];
|
|
59391
59397
|
resultContent = fixMDXContent(resultContent);
|
|
59392
59398
|
parsedData = parser.parse('magic', resultContent);
|
|
59399
|
+
console.log('parsedData', parsedData);
|
|
59393
59400
|
return [4 /*yield*/, Promise.all(parsedData.map(function (item) {
|
|
59394
59401
|
return parseComponentRecursively(allComponentHandlers, item, scope);
|
|
59395
59402
|
}))];
|