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.cjs
CHANGED
|
@@ -58398,6 +58398,12 @@ function formatProps(props) {
|
|
|
58398
58398
|
key = _b[0],
|
|
58399
58399
|
value = _b[1];
|
|
58400
58400
|
if (typeof value === 'string') {
|
|
58401
|
+
var trimmedValue = value.trim();
|
|
58402
|
+
var isArrowFunction = trimmedValue.includes('=>');
|
|
58403
|
+
var isRegularFunction = trimmedValue.startsWith('function');
|
|
58404
|
+
if (isArrowFunction || isRegularFunction) {
|
|
58405
|
+
return "".concat(key, "={").concat(value, "}");
|
|
58406
|
+
}
|
|
58401
58407
|
return "".concat(key, "=\"").concat(value, "\"");
|
|
58402
58408
|
}
|
|
58403
58409
|
try {
|
|
@@ -58481,6 +58487,9 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
|
|
|
58481
58487
|
componentHandler = allComponentHandlers.find(function (c) {
|
|
58482
58488
|
return c.name === item.value;
|
|
58483
58489
|
});
|
|
58490
|
+
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderStart) {
|
|
58491
|
+
componentHandler.onRenderStart(item, scope);
|
|
58492
|
+
}
|
|
58484
58493
|
props = __assign({}, item.props);
|
|
58485
58494
|
propsString = formatProps(props);
|
|
58486
58495
|
propsString += " scope={props.scope}";
|
|
@@ -58503,16 +58512,13 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
|
|
|
58503
58512
|
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');
|
|
58504
58513
|
// 调用组件的渲染钩子
|
|
58505
58514
|
if (isComplete) {
|
|
58506
|
-
// 渲染完成后的钩子
|
|
58507
58515
|
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderFinished) {
|
|
58508
58516
|
componentHandler.onRenderFinished(item, scope);
|
|
58509
58517
|
}
|
|
58510
58518
|
} else {
|
|
58511
|
-
// 渲染过程中的钩子
|
|
58512
58519
|
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderProcess) {
|
|
58513
58520
|
componentHandler.onRenderProcess(item, scope);
|
|
58514
58521
|
} else if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRender) {
|
|
58515
|
-
// 向后兼容:如果存在旧的 onRender,也调用它
|
|
58516
58522
|
componentHandler.onRender(item, scope);
|
|
58517
58523
|
}
|
|
58518
58524
|
}
|
|
@@ -59319,14 +59325,14 @@ function convertComponentsToHandlers(components, componentHandlers) {
|
|
|
59319
59325
|
name = _b[0],
|
|
59320
59326
|
componentValue = _b[1];
|
|
59321
59327
|
if (isEnhancedComponentConfig(componentValue)) {
|
|
59322
|
-
// 增强模式:从配置对象中提取信息
|
|
59323
59328
|
var config = componentValue;
|
|
59324
59329
|
return {
|
|
59325
59330
|
component: config.value,
|
|
59326
59331
|
name: name,
|
|
59327
59332
|
selfClosing: config.selfClosing !== undefined ? config.selfClosing : isSelfClosingComponent(config.value),
|
|
59328
|
-
|
|
59333
|
+
onRenderStart: config.onRenderStart,
|
|
59329
59334
|
onRenderProcess: config.onRenderProcess,
|
|
59335
|
+
onRenderFinished: config.onRenderFinished,
|
|
59330
59336
|
loader: config.loader,
|
|
59331
59337
|
label: config.label
|
|
59332
59338
|
};
|
|
@@ -59412,6 +59418,7 @@ function ReactAIRenderer(_a) {
|
|
|
59412
59418
|
if (!resultContent) return [3 /*break*/, 8];
|
|
59413
59419
|
resultContent = fixMDXContent(resultContent);
|
|
59414
59420
|
parsedData = parser.parse('magic', resultContent);
|
|
59421
|
+
console.log('parsedData', parsedData);
|
|
59415
59422
|
return [4 /*yield*/, Promise.all(parsedData.map(function (item) {
|
|
59416
59423
|
return parseComponentRecursively(allComponentHandlers, item, scope);
|
|
59417
59424
|
}))];
|