react-ai-renderer 0.1.18 → 0.1.20
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 +11 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -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
|
}
|
|
@@ -59181,7 +59187,6 @@ var ComponentPlaceholder = function (_a) {
|
|
|
59181
59187
|
}
|
|
59182
59188
|
} catch (e) {
|
|
59183
59189
|
// 如果骨架图生成失败,继续使用默认占位内容
|
|
59184
|
-
console.warn('Failed to generate skeleton:', e);
|
|
59185
59190
|
}
|
|
59186
59191
|
}
|
|
59187
59192
|
// 默认占位内容
|
|
@@ -59297,14 +59302,14 @@ function convertComponentsToHandlers(components, componentHandlers) {
|
|
|
59297
59302
|
name = _b[0],
|
|
59298
59303
|
componentValue = _b[1];
|
|
59299
59304
|
if (isEnhancedComponentConfig(componentValue)) {
|
|
59300
|
-
// 增强模式:从配置对象中提取信息
|
|
59301
59305
|
var config = componentValue;
|
|
59302
59306
|
return {
|
|
59303
59307
|
component: config.value,
|
|
59304
59308
|
name: name,
|
|
59305
59309
|
selfClosing: config.selfClosing !== undefined ? config.selfClosing : isSelfClosingComponent(config.value),
|
|
59306
|
-
|
|
59310
|
+
onRenderStart: config.onRenderStart,
|
|
59307
59311
|
onRenderProcess: config.onRenderProcess,
|
|
59312
|
+
onRenderFinished: config.onRenderFinished,
|
|
59308
59313
|
loader: config.loader,
|
|
59309
59314
|
label: config.label
|
|
59310
59315
|
};
|
|
@@ -59741,7 +59746,6 @@ var getMermaid = function () {
|
|
|
59741
59746
|
mermaidPromise = import('mermaid').then(function (module) {
|
|
59742
59747
|
return module.default || module;
|
|
59743
59748
|
}).catch(function (error) {
|
|
59744
|
-
console.warn('Mermaid is not available. Install it to enable chart rendering.');
|
|
59745
59749
|
return null;
|
|
59746
59750
|
});
|
|
59747
59751
|
return mermaidPromise;
|
|
@@ -59792,7 +59796,6 @@ function MermaidRenderer(_a) {
|
|
|
59792
59796
|
if (!!mermaid.initialized) return [3 /*break*/, 4];
|
|
59793
59797
|
// 设置全局错误处理函数
|
|
59794
59798
|
mermaid.parseError = function (err) {
|
|
59795
|
-
console.warn('Mermaid parse error:', err.message);
|
|
59796
59799
|
};
|
|
59797
59800
|
return [4 /*yield*/, mermaid.initialize({
|
|
59798
59801
|
startOnLoad: false,
|