react-ai-renderer 0.1.17 → 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.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
- onRenderFinished?: (item: ComponentData$1, scope: any) => void;
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
@@ -763,7 +763,8 @@ var MDXStreamingParser = /** @class */function () {
763
763
  return "\"".concat(inner, "\"");
764
764
  });
765
765
  // 2. 为对象键名添加引号(如果还没有引号)
766
- jsonValue = jsonValue.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)\s*:/g, '$1"$2":');
766
+ // 修复:使用 \p{L} 匹配 Unicode 字母(包括中文),使用 u 标志
767
+ jsonValue = jsonValue.replace(/([{,]\s*)([\p{L}_$][\p{L}\p{N}_$]*)\s*:/gu, '$1"$2":');
767
768
  // 3. 处理属性值中的模板字符串
768
769
  jsonValue = jsonValue.replace(/`([^`]*)`/g, function (match, p1) {
769
770
  return JSON.stringify(p1);
@@ -58375,6 +58376,12 @@ function formatProps(props) {
58375
58376
  key = _b[0],
58376
58377
  value = _b[1];
58377
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
+ }
58378
58385
  return "".concat(key, "=\"").concat(value, "\"");
58379
58386
  }
58380
58387
  try {
@@ -58458,6 +58465,9 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
58458
58465
  componentHandler = allComponentHandlers.find(function (c) {
58459
58466
  return c.name === item.value;
58460
58467
  });
58468
+ if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderStart) {
58469
+ componentHandler.onRenderStart(item, scope);
58470
+ }
58461
58471
  props = __assign({}, item.props);
58462
58472
  propsString = formatProps(props);
58463
58473
  propsString += " scope={props.scope}";
@@ -58480,16 +58490,13 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
58480
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');
58481
58491
  // 调用组件的渲染钩子
58482
58492
  if (isComplete) {
58483
- // 渲染完成后的钩子
58484
58493
  if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderFinished) {
58485
58494
  componentHandler.onRenderFinished(item, scope);
58486
58495
  }
58487
58496
  } else {
58488
- // 渲染过程中的钩子
58489
58497
  if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderProcess) {
58490
58498
  componentHandler.onRenderProcess(item, scope);
58491
58499
  } else if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRender) {
58492
- // 向后兼容:如果存在旧的 onRender,也调用它
58493
58500
  componentHandler.onRender(item, scope);
58494
58501
  }
58495
58502
  }
@@ -59296,14 +59303,14 @@ function convertComponentsToHandlers(components, componentHandlers) {
59296
59303
  name = _b[0],
59297
59304
  componentValue = _b[1];
59298
59305
  if (isEnhancedComponentConfig(componentValue)) {
59299
- // 增强模式:从配置对象中提取信息
59300
59306
  var config = componentValue;
59301
59307
  return {
59302
59308
  component: config.value,
59303
59309
  name: name,
59304
59310
  selfClosing: config.selfClosing !== undefined ? config.selfClosing : isSelfClosingComponent(config.value),
59305
- onRenderFinished: config.onRenderFinished,
59311
+ onRenderStart: config.onRenderStart,
59306
59312
  onRenderProcess: config.onRenderProcess,
59313
+ onRenderFinished: config.onRenderFinished,
59307
59314
  loader: config.loader,
59308
59315
  label: config.label
59309
59316
  };
@@ -59389,6 +59396,7 @@ function ReactAIRenderer(_a) {
59389
59396
  if (!resultContent) return [3 /*break*/, 8];
59390
59397
  resultContent = fixMDXContent(resultContent);
59391
59398
  parsedData = parser.parse('magic', resultContent);
59399
+ console.log('parsedData', parsedData);
59392
59400
  return [4 /*yield*/, Promise.all(parsedData.map(function (item) {
59393
59401
  return parseComponentRecursively(allComponentHandlers, item, scope);
59394
59402
  }))];