react-ai-renderer 0.1.15 → 0.1.17
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 +699 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +49 -5
- package/dist/index.js +699 -68
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10,7 +10,6 @@ var RemarkGfm = require('remark-gfm');
|
|
|
10
10
|
var mdx = require('@mdx-js/mdx');
|
|
11
11
|
var RehypeKatex = require('rehype-katex');
|
|
12
12
|
var RehypeHighlight = require('rehype-highlight');
|
|
13
|
-
var RehypeRaw = require('rehype-raw');
|
|
14
13
|
|
|
15
14
|
function _interopNamespaceDefault(e) {
|
|
16
15
|
var n = Object.create(null);
|
|
@@ -776,7 +775,6 @@ var MDXStreamingParser = /** @class */function () {
|
|
|
776
775
|
// 这比手动转换 JavaScript 对象字面量为 JSON 更可靠
|
|
777
776
|
props[propName] = new Function('return ' + rawValue)();
|
|
778
777
|
} catch (e) {
|
|
779
|
-
console.warn("Failed to parse prop value for ".concat(propName, ":"), value, e);
|
|
780
778
|
// 如果 Function 构造器失败,尝试手动转换并解析为 JSON
|
|
781
779
|
try {
|
|
782
780
|
// 将 JavaScript 对象字面量转换为有效的 JSON
|
|
@@ -58360,13 +58358,13 @@ function renderText(textContent, scope, registeredComponents) {
|
|
|
58360
58358
|
children: textContent,
|
|
58361
58359
|
components: registeredComponents,
|
|
58362
58360
|
remarkPlugins: [RemarkMath, RemarkGfm, RemarkBreaks],
|
|
58363
|
-
rehypePlugins: [
|
|
58361
|
+
rehypePlugins: [RehypeKatex, [RehypeHighlight, {
|
|
58364
58362
|
detect: false,
|
|
58365
58363
|
ignoreMissing: true,
|
|
58366
58364
|
plainText: ['mermaid'] // 将mermaid作为纯文本处理,避免被错误高亮
|
|
58367
58365
|
}]],
|
|
58368
58366
|
remarkRehypeOptions: {
|
|
58369
|
-
allowDangerousHtml:
|
|
58367
|
+
allowDangerousHtml: false // 允许处理 HTML 标签
|
|
58370
58368
|
}
|
|
58371
58369
|
})];
|
|
58372
58370
|
});
|
|
@@ -58467,7 +58465,7 @@ function renderMdx(mdxContent, scope, registeredComponents) {
|
|
|
58467
58465
|
// 递归解析组件的函数 - 返回结构化对象
|
|
58468
58466
|
function parseComponentRecursively(allComponentHandlers, item, scope) {
|
|
58469
58467
|
return __awaiter(this, void 0, void 0, function () {
|
|
58470
|
-
var componentHandler, props, propsString, childrenContent_1, parsedChildren_1, componentString
|
|
58468
|
+
var isComplete, componentHandler, props, propsString, childrenContent_1, parsedChildren_1, componentString;
|
|
58471
58469
|
return __generator(this, function (_a) {
|
|
58472
58470
|
switch (_a.label) {
|
|
58473
58471
|
case 0:
|
|
@@ -58478,6 +58476,7 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
|
|
|
58478
58476
|
}];
|
|
58479
58477
|
}
|
|
58480
58478
|
if (!(item.type === 'component')) return [3 /*break*/, 3];
|
|
58479
|
+
isComplete = item.isComplete === true;
|
|
58481
58480
|
componentHandler = allComponentHandlers.find(function (c) {
|
|
58482
58481
|
return c.name === item.value;
|
|
58483
58482
|
});
|
|
@@ -58501,7 +58500,7 @@ function parseComponentRecursively(allComponentHandlers, item, scope) {
|
|
|
58501
58500
|
_a.label = 2;
|
|
58502
58501
|
case 2:
|
|
58503
58502
|
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
|
-
|
|
58503
|
+
// 调用组件的渲染钩子
|
|
58505
58504
|
if (isComplete) {
|
|
58506
58505
|
// 渲染完成后的钩子
|
|
58507
58506
|
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.onRenderFinished) {
|
|
@@ -58625,18 +58624,533 @@ function MdxLayout(_a) {
|
|
|
58625
58624
|
});
|
|
58626
58625
|
}
|
|
58627
58626
|
|
|
58627
|
+
function generateSkeletonByComponentName(componentName, props, style) {
|
|
58628
|
+
var _a, _b;
|
|
58629
|
+
var baseStyle = __assign({
|
|
58630
|
+
borderRadius: '8px',
|
|
58631
|
+
backgroundColor: '#f3f4f6'
|
|
58632
|
+
}, style);
|
|
58633
|
+
// 根据组件名称模式匹配生成不同的骨架图
|
|
58634
|
+
var name = componentName.toLowerCase();
|
|
58635
|
+
// 图表类组件
|
|
58636
|
+
if (name.includes('chart') || name.includes('graph') || name.includes('plot')) {
|
|
58637
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58638
|
+
style: __assign(__assign({}, baseStyle), {
|
|
58639
|
+
padding: '24px',
|
|
58640
|
+
minHeight: (props === null || props === void 0 ? void 0 : props.height) ? "".concat(props.height, "px") : '300px',
|
|
58641
|
+
display: 'flex',
|
|
58642
|
+
flexDirection: 'column',
|
|
58643
|
+
gap: '12px'
|
|
58644
|
+
}),
|
|
58645
|
+
children: [/*#__PURE__*/runtime.jsxs("div", {
|
|
58646
|
+
style: {
|
|
58647
|
+
display: 'flex',
|
|
58648
|
+
justifyContent: 'space-between',
|
|
58649
|
+
alignItems: 'center',
|
|
58650
|
+
marginBottom: '8px'
|
|
58651
|
+
},
|
|
58652
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58653
|
+
style: {
|
|
58654
|
+
width: '120px',
|
|
58655
|
+
height: '20px',
|
|
58656
|
+
backgroundColor: '#e5e7eb',
|
|
58657
|
+
borderRadius: '4px'
|
|
58658
|
+
}
|
|
58659
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58660
|
+
style: {
|
|
58661
|
+
width: '80px',
|
|
58662
|
+
height: '16px',
|
|
58663
|
+
backgroundColor: '#e5e7eb',
|
|
58664
|
+
borderRadius: '4px'
|
|
58665
|
+
}
|
|
58666
|
+
})]
|
|
58667
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58668
|
+
style: {
|
|
58669
|
+
flex: 1,
|
|
58670
|
+
display: 'flex',
|
|
58671
|
+
alignItems: 'flex-end',
|
|
58672
|
+
gap: '8px',
|
|
58673
|
+
height: '200px'
|
|
58674
|
+
},
|
|
58675
|
+
children: Array.from({
|
|
58676
|
+
length: 8
|
|
58677
|
+
}).map(function (_, i) {
|
|
58678
|
+
return /*#__PURE__*/runtime.jsx("div", {
|
|
58679
|
+
style: {
|
|
58680
|
+
flex: 1,
|
|
58681
|
+
height: "".concat(Math.random() * 60 + 40, "%"),
|
|
58682
|
+
backgroundColor: '#d1d5db',
|
|
58683
|
+
borderRadius: '4px 4px 0 0',
|
|
58684
|
+
animation: 'pulse 1.5s ease-in-out infinite',
|
|
58685
|
+
animationDelay: "".concat(i * 0.1, "s")
|
|
58686
|
+
}
|
|
58687
|
+
}, i);
|
|
58688
|
+
})
|
|
58689
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58690
|
+
style: {
|
|
58691
|
+
display: 'flex',
|
|
58692
|
+
gap: '12px',
|
|
58693
|
+
marginTop: '8px'
|
|
58694
|
+
},
|
|
58695
|
+
children: Array.from({
|
|
58696
|
+
length: 3
|
|
58697
|
+
}).map(function (_, i) {
|
|
58698
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58699
|
+
style: {
|
|
58700
|
+
display: 'flex',
|
|
58701
|
+
alignItems: 'center',
|
|
58702
|
+
gap: '6px'
|
|
58703
|
+
},
|
|
58704
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58705
|
+
style: {
|
|
58706
|
+
width: '12px',
|
|
58707
|
+
height: '12px',
|
|
58708
|
+
backgroundColor: '#d1d5db',
|
|
58709
|
+
borderRadius: '2px'
|
|
58710
|
+
}
|
|
58711
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58712
|
+
style: {
|
|
58713
|
+
width: '60px',
|
|
58714
|
+
height: '12px',
|
|
58715
|
+
backgroundColor: '#e5e7eb',
|
|
58716
|
+
borderRadius: '2px'
|
|
58717
|
+
}
|
|
58718
|
+
})]
|
|
58719
|
+
}, i);
|
|
58720
|
+
})
|
|
58721
|
+
}), /*#__PURE__*/runtime.jsx("style", {
|
|
58722
|
+
children: "\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n "
|
|
58723
|
+
})]
|
|
58724
|
+
});
|
|
58725
|
+
}
|
|
58726
|
+
// 表格类组件
|
|
58727
|
+
if (name.includes('table') || name.includes('grid')) {
|
|
58728
|
+
var rowCount_1 = (props === null || props === void 0 ? void 0 : props.rows) || 5;
|
|
58729
|
+
var colCount_1 = (props === null || props === void 0 ? void 0 : props.columns) || 4;
|
|
58730
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58731
|
+
style: __assign(__assign({}, baseStyle), {
|
|
58732
|
+
padding: '16px',
|
|
58733
|
+
overflow: 'hidden'
|
|
58734
|
+
}),
|
|
58735
|
+
children: [/*#__PURE__*/runtime.jsxs("div", {
|
|
58736
|
+
style: {
|
|
58737
|
+
marginBottom: '12px'
|
|
58738
|
+
},
|
|
58739
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58740
|
+
style: {
|
|
58741
|
+
width: '150px',
|
|
58742
|
+
height: '20px',
|
|
58743
|
+
backgroundColor: '#e5e7eb',
|
|
58744
|
+
borderRadius: '4px',
|
|
58745
|
+
marginBottom: '8px'
|
|
58746
|
+
}
|
|
58747
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58748
|
+
style: {
|
|
58749
|
+
width: '200px',
|
|
58750
|
+
height: '16px',
|
|
58751
|
+
backgroundColor: '#e5e7eb',
|
|
58752
|
+
borderRadius: '4px'
|
|
58753
|
+
}
|
|
58754
|
+
})]
|
|
58755
|
+
}), /*#__PURE__*/runtime.jsxs("div", {
|
|
58756
|
+
style: {
|
|
58757
|
+
border: '1px solid #e5e7eb',
|
|
58758
|
+
borderRadius: '4px',
|
|
58759
|
+
overflow: 'hidden'
|
|
58760
|
+
},
|
|
58761
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58762
|
+
style: {
|
|
58763
|
+
display: 'grid',
|
|
58764
|
+
gridTemplateColumns: "repeat(".concat(colCount_1, ", 1fr)"),
|
|
58765
|
+
backgroundColor: '#f9fafb',
|
|
58766
|
+
borderBottom: '1px solid #e5e7eb'
|
|
58767
|
+
},
|
|
58768
|
+
children: Array.from({
|
|
58769
|
+
length: colCount_1
|
|
58770
|
+
}).map(function (_, i) {
|
|
58771
|
+
return /*#__PURE__*/runtime.jsx("div", {
|
|
58772
|
+
style: {
|
|
58773
|
+
padding: '12px',
|
|
58774
|
+
borderRight: i < colCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
|
|
58775
|
+
},
|
|
58776
|
+
children: /*#__PURE__*/runtime.jsx("div", {
|
|
58777
|
+
style: {
|
|
58778
|
+
width: '80%',
|
|
58779
|
+
height: '16px',
|
|
58780
|
+
backgroundColor: '#d1d5db',
|
|
58781
|
+
borderRadius: '2px'
|
|
58782
|
+
}
|
|
58783
|
+
})
|
|
58784
|
+
}, i);
|
|
58785
|
+
})
|
|
58786
|
+
}), Array.from({
|
|
58787
|
+
length: rowCount_1
|
|
58788
|
+
}).map(function (_, rowIndex) {
|
|
58789
|
+
return /*#__PURE__*/runtime.jsx("div", {
|
|
58790
|
+
style: {
|
|
58791
|
+
display: 'grid',
|
|
58792
|
+
gridTemplateColumns: "repeat(".concat(colCount_1, ", 1fr)"),
|
|
58793
|
+
borderBottom: rowIndex < rowCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
|
|
58794
|
+
},
|
|
58795
|
+
children: Array.from({
|
|
58796
|
+
length: colCount_1
|
|
58797
|
+
}).map(function (_, colIndex) {
|
|
58798
|
+
return /*#__PURE__*/runtime.jsx("div", {
|
|
58799
|
+
style: {
|
|
58800
|
+
padding: '12px',
|
|
58801
|
+
borderRight: colIndex < colCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
|
|
58802
|
+
},
|
|
58803
|
+
children: /*#__PURE__*/runtime.jsx("div", {
|
|
58804
|
+
style: {
|
|
58805
|
+
width: "".concat(Math.random() * 40 + 60, "%"),
|
|
58806
|
+
height: '14px',
|
|
58807
|
+
backgroundColor: '#e5e7eb',
|
|
58808
|
+
borderRadius: '2px'
|
|
58809
|
+
}
|
|
58810
|
+
})
|
|
58811
|
+
}, colIndex);
|
|
58812
|
+
})
|
|
58813
|
+
}, rowIndex);
|
|
58814
|
+
})]
|
|
58815
|
+
})]
|
|
58816
|
+
});
|
|
58817
|
+
}
|
|
58818
|
+
// 卡片类组件
|
|
58819
|
+
if (name.includes('card')) {
|
|
58820
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58821
|
+
style: __assign(__assign({}, baseStyle), {
|
|
58822
|
+
padding: '20px',
|
|
58823
|
+
minHeight: '200px'
|
|
58824
|
+
}),
|
|
58825
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58826
|
+
style: {
|
|
58827
|
+
width: '60%',
|
|
58828
|
+
height: '24px',
|
|
58829
|
+
backgroundColor: '#e5e7eb',
|
|
58830
|
+
borderRadius: '4px',
|
|
58831
|
+
marginBottom: '16px'
|
|
58832
|
+
}
|
|
58833
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58834
|
+
style: {
|
|
58835
|
+
width: '100%',
|
|
58836
|
+
height: '16px',
|
|
58837
|
+
backgroundColor: '#e5e7eb',
|
|
58838
|
+
borderRadius: '4px',
|
|
58839
|
+
marginBottom: '8px'
|
|
58840
|
+
}
|
|
58841
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58842
|
+
style: {
|
|
58843
|
+
width: '90%',
|
|
58844
|
+
height: '16px',
|
|
58845
|
+
backgroundColor: '#e5e7eb',
|
|
58846
|
+
borderRadius: '4px',
|
|
58847
|
+
marginBottom: '8px'
|
|
58848
|
+
}
|
|
58849
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58850
|
+
style: {
|
|
58851
|
+
width: '70%',
|
|
58852
|
+
height: '16px',
|
|
58853
|
+
backgroundColor: '#e5e7eb',
|
|
58854
|
+
borderRadius: '4px',
|
|
58855
|
+
marginBottom: '16px'
|
|
58856
|
+
}
|
|
58857
|
+
}), /*#__PURE__*/runtime.jsxs("div", {
|
|
58858
|
+
style: {
|
|
58859
|
+
display: 'flex',
|
|
58860
|
+
gap: '8px',
|
|
58861
|
+
marginTop: '16px'
|
|
58862
|
+
},
|
|
58863
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58864
|
+
style: {
|
|
58865
|
+
width: '80px',
|
|
58866
|
+
height: '32px',
|
|
58867
|
+
backgroundColor: '#d1d5db',
|
|
58868
|
+
borderRadius: '4px'
|
|
58869
|
+
}
|
|
58870
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58871
|
+
style: {
|
|
58872
|
+
width: '80px',
|
|
58873
|
+
height: '32px',
|
|
58874
|
+
backgroundColor: '#d1d5db',
|
|
58875
|
+
borderRadius: '4px'
|
|
58876
|
+
}
|
|
58877
|
+
})]
|
|
58878
|
+
})]
|
|
58879
|
+
});
|
|
58880
|
+
}
|
|
58881
|
+
// 列表类组件
|
|
58882
|
+
if (name.includes('list') || name.includes('todo')) {
|
|
58883
|
+
var itemCount_1 = ((_a = props === null || props === void 0 ? void 0 : props.items) === null || _a === void 0 ? void 0 : _a.length) || (props === null || props === void 0 ? void 0 : props.count) || 3;
|
|
58884
|
+
return /*#__PURE__*/runtime.jsx("div", {
|
|
58885
|
+
style: __assign(__assign({}, baseStyle), {
|
|
58886
|
+
padding: '16px'
|
|
58887
|
+
}),
|
|
58888
|
+
children: Array.from({
|
|
58889
|
+
length: itemCount_1
|
|
58890
|
+
}).map(function (_, i) {
|
|
58891
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58892
|
+
style: {
|
|
58893
|
+
display: 'flex',
|
|
58894
|
+
alignItems: 'center',
|
|
58895
|
+
gap: '12px',
|
|
58896
|
+
marginBottom: i < itemCount_1 - 1 ? '12px' : '0',
|
|
58897
|
+
paddingBottom: i < itemCount_1 - 1 ? '12px' : '0',
|
|
58898
|
+
borderBottom: i < itemCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
|
|
58899
|
+
},
|
|
58900
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58901
|
+
style: {
|
|
58902
|
+
width: '20px',
|
|
58903
|
+
height: '20px',
|
|
58904
|
+
backgroundColor: '#d1d5db',
|
|
58905
|
+
borderRadius: '4px',
|
|
58906
|
+
flexShrink: 0
|
|
58907
|
+
}
|
|
58908
|
+
}), /*#__PURE__*/runtime.jsxs("div", {
|
|
58909
|
+
style: {
|
|
58910
|
+
flex: 1
|
|
58911
|
+
},
|
|
58912
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58913
|
+
style: {
|
|
58914
|
+
width: "".concat(Math.random() * 30 + 60, "%"),
|
|
58915
|
+
height: '16px',
|
|
58916
|
+
backgroundColor: '#e5e7eb',
|
|
58917
|
+
borderRadius: '4px',
|
|
58918
|
+
marginBottom: '6px'
|
|
58919
|
+
}
|
|
58920
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58921
|
+
style: {
|
|
58922
|
+
width: "".concat(Math.random() * 40 + 40, "%"),
|
|
58923
|
+
height: '14px',
|
|
58924
|
+
backgroundColor: '#e5e7eb',
|
|
58925
|
+
borderRadius: '4px'
|
|
58926
|
+
}
|
|
58927
|
+
})]
|
|
58928
|
+
})]
|
|
58929
|
+
}, i);
|
|
58930
|
+
})
|
|
58931
|
+
});
|
|
58932
|
+
}
|
|
58933
|
+
// 表单类组件
|
|
58934
|
+
if (name.includes('form') || name.includes('input') || name.includes('select')) {
|
|
58935
|
+
var fieldCount_1 = ((_b = props === null || props === void 0 ? void 0 : props.fields) === null || _b === void 0 ? void 0 : _b.length) || 3;
|
|
58936
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58937
|
+
style: __assign(__assign({}, baseStyle), {
|
|
58938
|
+
padding: '20px'
|
|
58939
|
+
}),
|
|
58940
|
+
children: [Array.from({
|
|
58941
|
+
length: fieldCount_1
|
|
58942
|
+
}).map(function (_, i) {
|
|
58943
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58944
|
+
style: {
|
|
58945
|
+
marginBottom: i < fieldCount_1 - 1 ? '20px' : '0'
|
|
58946
|
+
},
|
|
58947
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58948
|
+
style: {
|
|
58949
|
+
width: '100px',
|
|
58950
|
+
height: '14px',
|
|
58951
|
+
backgroundColor: '#e5e7eb',
|
|
58952
|
+
borderRadius: '2px',
|
|
58953
|
+
marginBottom: '8px'
|
|
58954
|
+
}
|
|
58955
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58956
|
+
style: {
|
|
58957
|
+
width: '100%',
|
|
58958
|
+
height: '40px',
|
|
58959
|
+
backgroundColor: '#f3f4f6',
|
|
58960
|
+
border: '1px solid #e5e7eb',
|
|
58961
|
+
borderRadius: '4px'
|
|
58962
|
+
}
|
|
58963
|
+
})]
|
|
58964
|
+
}, i);
|
|
58965
|
+
}), /*#__PURE__*/runtime.jsxs("div", {
|
|
58966
|
+
style: {
|
|
58967
|
+
display: 'flex',
|
|
58968
|
+
gap: '12px',
|
|
58969
|
+
marginTop: '20px'
|
|
58970
|
+
},
|
|
58971
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
58972
|
+
style: {
|
|
58973
|
+
width: '100px',
|
|
58974
|
+
height: '36px',
|
|
58975
|
+
backgroundColor: '#d1d5db',
|
|
58976
|
+
borderRadius: '4px'
|
|
58977
|
+
}
|
|
58978
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
58979
|
+
style: {
|
|
58980
|
+
width: '100px',
|
|
58981
|
+
height: '36px',
|
|
58982
|
+
backgroundColor: '#e5e7eb',
|
|
58983
|
+
borderRadius: '4px'
|
|
58984
|
+
}
|
|
58985
|
+
})]
|
|
58986
|
+
})]
|
|
58987
|
+
});
|
|
58988
|
+
}
|
|
58989
|
+
// 图片/媒体类组件
|
|
58990
|
+
if (name.includes('image') || name.includes('img') || name.includes('video') || name.includes('media')) {
|
|
58991
|
+
return /*#__PURE__*/runtime.jsx("div", {
|
|
58992
|
+
style: __assign(__assign({}, baseStyle), {
|
|
58993
|
+
padding: '16px',
|
|
58994
|
+
display: 'flex',
|
|
58995
|
+
alignItems: 'center',
|
|
58996
|
+
justifyContent: 'center',
|
|
58997
|
+
minHeight: (props === null || props === void 0 ? void 0 : props.height) ? "".concat(props.height, "px") : '200px'
|
|
58998
|
+
}),
|
|
58999
|
+
children: /*#__PURE__*/runtime.jsx("div", {
|
|
59000
|
+
style: {
|
|
59001
|
+
width: '100%',
|
|
59002
|
+
height: '100%',
|
|
59003
|
+
backgroundColor: '#e5e7eb',
|
|
59004
|
+
borderRadius: '8px',
|
|
59005
|
+
display: 'flex',
|
|
59006
|
+
alignItems: 'center',
|
|
59007
|
+
justifyContent: 'center'
|
|
59008
|
+
},
|
|
59009
|
+
children: /*#__PURE__*/runtime.jsx("div", {
|
|
59010
|
+
style: {
|
|
59011
|
+
width: '48px',
|
|
59012
|
+
height: '48px',
|
|
59013
|
+
backgroundColor: '#d1d5db',
|
|
59014
|
+
borderRadius: '50%',
|
|
59015
|
+
display: 'flex',
|
|
59016
|
+
alignItems: 'center',
|
|
59017
|
+
justifyContent: 'center'
|
|
59018
|
+
},
|
|
59019
|
+
children: /*#__PURE__*/runtime.jsx("div", {
|
|
59020
|
+
style: {
|
|
59021
|
+
width: '24px',
|
|
59022
|
+
height: '24px',
|
|
59023
|
+
backgroundColor: '#9ca3af',
|
|
59024
|
+
borderRadius: '4px'
|
|
59025
|
+
}
|
|
59026
|
+
})
|
|
59027
|
+
})
|
|
59028
|
+
})
|
|
59029
|
+
});
|
|
59030
|
+
}
|
|
59031
|
+
// 默认骨架图
|
|
59032
|
+
return /*#__PURE__*/runtime.jsxs("div", {
|
|
59033
|
+
style: __assign(__assign({}, baseStyle), {
|
|
59034
|
+
padding: '24px',
|
|
59035
|
+
minHeight: '120px',
|
|
59036
|
+
display: 'flex',
|
|
59037
|
+
flexDirection: 'column',
|
|
59038
|
+
gap: '12px',
|
|
59039
|
+
alignItems: 'center',
|
|
59040
|
+
justifyContent: 'center'
|
|
59041
|
+
}),
|
|
59042
|
+
children: [/*#__PURE__*/runtime.jsxs("div", {
|
|
59043
|
+
style: {
|
|
59044
|
+
width: '100%',
|
|
59045
|
+
maxWidth: '400px'
|
|
59046
|
+
},
|
|
59047
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
59048
|
+
style: {
|
|
59049
|
+
width: '60%',
|
|
59050
|
+
height: '20px',
|
|
59051
|
+
backgroundColor: '#e5e7eb',
|
|
59052
|
+
borderRadius: '4px',
|
|
59053
|
+
marginBottom: '12px'
|
|
59054
|
+
}
|
|
59055
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
59056
|
+
style: {
|
|
59057
|
+
width: '100%',
|
|
59058
|
+
height: '16px',
|
|
59059
|
+
backgroundColor: '#e5e7eb',
|
|
59060
|
+
borderRadius: '4px',
|
|
59061
|
+
marginBottom: '8px'
|
|
59062
|
+
}
|
|
59063
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
59064
|
+
style: {
|
|
59065
|
+
width: '90%',
|
|
59066
|
+
height: '16px',
|
|
59067
|
+
backgroundColor: '#e5e7eb',
|
|
59068
|
+
borderRadius: '4px',
|
|
59069
|
+
marginBottom: '8px'
|
|
59070
|
+
}
|
|
59071
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
59072
|
+
style: {
|
|
59073
|
+
width: '75%',
|
|
59074
|
+
height: '16px',
|
|
59075
|
+
backgroundColor: '#e5e7eb',
|
|
59076
|
+
borderRadius: '4px'
|
|
59077
|
+
}
|
|
59078
|
+
})]
|
|
59079
|
+
}), /*#__PURE__*/runtime.jsxs("div", {
|
|
59080
|
+
style: {
|
|
59081
|
+
display: 'flex',
|
|
59082
|
+
gap: '8px',
|
|
59083
|
+
marginTop: '12px'
|
|
59084
|
+
},
|
|
59085
|
+
children: [/*#__PURE__*/runtime.jsx("div", {
|
|
59086
|
+
style: {
|
|
59087
|
+
width: '60px',
|
|
59088
|
+
height: '32px',
|
|
59089
|
+
backgroundColor: '#d1d5db',
|
|
59090
|
+
borderRadius: '4px'
|
|
59091
|
+
}
|
|
59092
|
+
}), /*#__PURE__*/runtime.jsx("div", {
|
|
59093
|
+
style: {
|
|
59094
|
+
width: '60px',
|
|
59095
|
+
height: '32px',
|
|
59096
|
+
backgroundColor: '#d1d5db',
|
|
59097
|
+
borderRadius: '4px'
|
|
59098
|
+
}
|
|
59099
|
+
})]
|
|
59100
|
+
})]
|
|
59101
|
+
});
|
|
59102
|
+
}
|
|
59103
|
+
/**
|
|
59104
|
+
* 创建骨架图组件
|
|
59105
|
+
*/
|
|
59106
|
+
function createSkeletonComponent(componentName, componentData, skeletonConfig, style) {
|
|
59107
|
+
// 如果提供了自定义骨架图组件
|
|
59108
|
+
if (skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.component) {
|
|
59109
|
+
var SkeletonComponent = skeletonConfig.component;
|
|
59110
|
+
return /*#__PURE__*/runtime.jsx(SkeletonComponent, {
|
|
59111
|
+
componentName: componentName,
|
|
59112
|
+
componentData: componentData,
|
|
59113
|
+
props: componentData === null || componentData === void 0 ? void 0 : componentData.props,
|
|
59114
|
+
style: style
|
|
59115
|
+
});
|
|
59116
|
+
}
|
|
59117
|
+
// 如果提供了自定义骨架图元素
|
|
59118
|
+
if (skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.element) {
|
|
59119
|
+
return skeletonConfig.element;
|
|
59120
|
+
}
|
|
59121
|
+
// 如果提供了自定义生成函数
|
|
59122
|
+
if (skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.generator) {
|
|
59123
|
+
return skeletonConfig.generator({
|
|
59124
|
+
componentName: componentName,
|
|
59125
|
+
componentData: componentData,
|
|
59126
|
+
props: componentData === null || componentData === void 0 ? void 0 : componentData.props,
|
|
59127
|
+
style: style
|
|
59128
|
+
});
|
|
59129
|
+
}
|
|
59130
|
+
// 如果启用了自动生成,或者没有提供任何配置
|
|
59131
|
+
if ((skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.autoGenerate) !== false) {
|
|
59132
|
+
return generateSkeletonByComponentName(componentName, componentData === null || componentData === void 0 ? void 0 : componentData.props, style);
|
|
59133
|
+
}
|
|
59134
|
+
// 默认返回空
|
|
59135
|
+
return /*#__PURE__*/runtime.jsx(React.Fragment, {});
|
|
59136
|
+
}
|
|
59137
|
+
|
|
58628
59138
|
var ComponentPlaceholder = function (_a) {
|
|
58629
59139
|
var componentName = _a.componentName,
|
|
58630
59140
|
style = _a.style,
|
|
58631
|
-
|
|
58632
|
-
|
|
58633
|
-
|
|
59141
|
+
loader = _a.loader,
|
|
59142
|
+
skeleton = _a.skeleton,
|
|
59143
|
+
componentData = _a.componentData;
|
|
59144
|
+
// 如果有自定义加载内容,优先使用
|
|
59145
|
+
if (loader) {
|
|
59146
|
+
// 如果是布尔值 true,使用默认样式
|
|
59147
|
+
if (typeof loader === 'boolean') ;
|
|
58634
59148
|
// 如果是 React 元素,直接返回
|
|
58635
|
-
if (/*#__PURE__*/React.isValidElement(
|
|
58636
|
-
return
|
|
59149
|
+
else if (/*#__PURE__*/React.isValidElement(loader)) {
|
|
59150
|
+
return loader;
|
|
58637
59151
|
}
|
|
58638
59152
|
// 如果是字符串,显示字符串
|
|
58639
|
-
if (typeof
|
|
59153
|
+
else if (typeof loader === 'string') {
|
|
58640
59154
|
return /*#__PURE__*/runtime.jsx("div", {
|
|
58641
59155
|
style: __assign({
|
|
58642
59156
|
border: '1px dashed #d1d5db',
|
|
@@ -58650,34 +59164,47 @@ var ComponentPlaceholder = function (_a) {
|
|
|
58650
59164
|
justifyContent: 'center',
|
|
58651
59165
|
minHeight: '60px'
|
|
58652
59166
|
}, style),
|
|
58653
|
-
children:
|
|
59167
|
+
children: loader
|
|
58654
59168
|
});
|
|
58655
59169
|
}
|
|
58656
59170
|
// 如果是函数,调用它
|
|
58657
|
-
if (typeof
|
|
59171
|
+
else if (typeof loader === 'function') {
|
|
58658
59172
|
try {
|
|
58659
59173
|
// 检查是否是 React 组件构造函数
|
|
58660
|
-
var proto =
|
|
59174
|
+
var proto = loader.prototype;
|
|
58661
59175
|
if (proto && (proto instanceof React.Component || proto.isReactComponent)) {
|
|
58662
59176
|
// 是 React 组件类,创建元素
|
|
58663
|
-
var Component =
|
|
59177
|
+
var Component = loader;
|
|
58664
59178
|
return /*#__PURE__*/runtime.jsx(Component, {
|
|
58665
59179
|
componentName: componentName
|
|
58666
59180
|
});
|
|
58667
59181
|
} else {
|
|
58668
59182
|
// 是普通函数,调用它(类型断言为函数)
|
|
58669
|
-
var func =
|
|
59183
|
+
var func = loader;
|
|
58670
59184
|
return func(componentName);
|
|
58671
59185
|
}
|
|
58672
59186
|
} catch (e) {
|
|
58673
59187
|
// 如果出错,尝试作为组件使用
|
|
58674
|
-
var Component =
|
|
59188
|
+
var Component = loader;
|
|
58675
59189
|
return /*#__PURE__*/runtime.jsx(Component, {
|
|
58676
59190
|
componentName: componentName
|
|
58677
59191
|
});
|
|
58678
59192
|
}
|
|
58679
59193
|
}
|
|
58680
59194
|
}
|
|
59195
|
+
// 如果没有 loader,尝试使用骨架图
|
|
59196
|
+
if (skeleton || !loader) {
|
|
59197
|
+
try {
|
|
59198
|
+
var skeletonElement = createSkeletonComponent(componentName, componentData, skeleton, style);
|
|
59199
|
+
// 如果骨架图生成成功且不是空元素,使用骨架图
|
|
59200
|
+
if (skeletonElement && /*#__PURE__*/React.isValidElement(skeletonElement)) {
|
|
59201
|
+
return skeletonElement;
|
|
59202
|
+
}
|
|
59203
|
+
} catch (e) {
|
|
59204
|
+
// 如果骨架图生成失败,继续使用默认占位内容
|
|
59205
|
+
console.warn('Failed to generate skeleton:', e);
|
|
59206
|
+
}
|
|
59207
|
+
}
|
|
58681
59208
|
// 默认占位内容
|
|
58682
59209
|
return /*#__PURE__*/runtime.jsxs("div", {
|
|
58683
59210
|
style: __assign({
|
|
@@ -58767,6 +59294,51 @@ var FallbackView = /** @class */function (_super) {
|
|
|
58767
59294
|
return FallbackView;
|
|
58768
59295
|
}(React.Component);
|
|
58769
59296
|
|
|
59297
|
+
function isEnhancedComponentConfig(value) {
|
|
59298
|
+
return typeof value === 'object' && value !== null && 'value' in value && typeof value.value !== 'undefined';
|
|
59299
|
+
}
|
|
59300
|
+
/**
|
|
59301
|
+
* 从组件值中提取实际的组件
|
|
59302
|
+
*/
|
|
59303
|
+
function extractComponent(value) {
|
|
59304
|
+
return isEnhancedComponentConfig(value) ? value.value : value;
|
|
59305
|
+
}
|
|
59306
|
+
/**
|
|
59307
|
+
* 将 components 转换为 ComponentHandler 数组
|
|
59308
|
+
*/
|
|
59309
|
+
function convertComponentsToHandlers(components, componentHandlers) {
|
|
59310
|
+
return Object.entries(components).filter(function (_a) {
|
|
59311
|
+
var _b = __read(_a, 1),
|
|
59312
|
+
name = _b[0];
|
|
59313
|
+
return !componentHandlers.some(function (handler) {
|
|
59314
|
+
return handler.name === name;
|
|
59315
|
+
});
|
|
59316
|
+
}).map(function (_a) {
|
|
59317
|
+
var _b = __read(_a, 2),
|
|
59318
|
+
name = _b[0],
|
|
59319
|
+
componentValue = _b[1];
|
|
59320
|
+
if (isEnhancedComponentConfig(componentValue)) {
|
|
59321
|
+
// 增强模式:从配置对象中提取信息
|
|
59322
|
+
var config = componentValue;
|
|
59323
|
+
return {
|
|
59324
|
+
component: config.value,
|
|
59325
|
+
name: name,
|
|
59326
|
+
selfClosing: config.selfClosing !== undefined ? config.selfClosing : isSelfClosingComponent(config.value),
|
|
59327
|
+
onRenderFinished: config.onRenderFinished,
|
|
59328
|
+
onRenderProcess: config.onRenderProcess,
|
|
59329
|
+
loader: config.loader,
|
|
59330
|
+
label: config.label
|
|
59331
|
+
};
|
|
59332
|
+
} else {
|
|
59333
|
+
// 普通模式:直接使用组件
|
|
59334
|
+
return {
|
|
59335
|
+
component: componentValue,
|
|
59336
|
+
name: name,
|
|
59337
|
+
selfClosing: isSelfClosingComponent(componentValue)
|
|
59338
|
+
};
|
|
59339
|
+
}
|
|
59340
|
+
});
|
|
59341
|
+
}
|
|
58770
59342
|
function ReactAIRenderer(_a) {
|
|
58771
59343
|
var _this = this;
|
|
58772
59344
|
var content = _a.content,
|
|
@@ -58789,24 +59361,16 @@ function ReactAIRenderer(_a) {
|
|
|
58789
59361
|
});
|
|
58790
59362
|
}
|
|
58791
59363
|
content = content || children || '';
|
|
58792
|
-
|
|
58793
|
-
var
|
|
58794
|
-
var _b = __read(_a, 1),
|
|
58795
|
-
name = _b[0];
|
|
58796
|
-
return !componentHandlers.some(function (handler) {
|
|
58797
|
-
return handler.name === name;
|
|
58798
|
-
});
|
|
58799
|
-
}).map(function (_a) {
|
|
59364
|
+
// 构建 allComponents:从增强配置中提取实际的组件
|
|
59365
|
+
var normalizedComponents = components ? Object.fromEntries(Object.entries(components).map(function (_a) {
|
|
58800
59366
|
var _b = __read(_a, 2),
|
|
58801
59367
|
name = _b[0],
|
|
58802
|
-
|
|
58803
|
-
|
|
58804
|
-
|
|
58805
|
-
|
|
58806
|
-
|
|
58807
|
-
|
|
58808
|
-
};
|
|
58809
|
-
}) : []), false), __read(componentHandlers), false);
|
|
59368
|
+
value = _b[1];
|
|
59369
|
+
return [name, extractComponent(value)];
|
|
59370
|
+
})) : {};
|
|
59371
|
+
var allComponents = __assign(__assign({}, BuiltInComponents), normalizedComponents);
|
|
59372
|
+
// 构建 allComponentHandlers:支持增强模式
|
|
59373
|
+
var allComponentHandlers = __spreadArray(__spreadArray([], __read(components ? convertComponentsToHandlers(components, componentHandlers) : []), false), __read(componentHandlers), false);
|
|
58810
59374
|
var _e = __read(React.useState(null), 2),
|
|
58811
59375
|
component = _e[0],
|
|
58812
59376
|
setComponent = _e[1];
|
|
@@ -58814,6 +59378,8 @@ function ReactAIRenderer(_a) {
|
|
|
58814
59378
|
var fallbackErrorRef = React.useRef({
|
|
58815
59379
|
hasError: false
|
|
58816
59380
|
});
|
|
59381
|
+
// 用于缓存已完成的组件,避免重复渲染
|
|
59382
|
+
var completedComponentsCacheRef = React.useRef(new Map());
|
|
58817
59383
|
var parser = new MDXStreamingParser(allComponentHandlers);
|
|
58818
59384
|
var mdxContent = content || '';
|
|
58819
59385
|
// FallbackView 错误状态变化时的回调
|
|
@@ -58826,9 +59392,10 @@ function ReactAIRenderer(_a) {
|
|
|
58826
59392
|
React.useEffect(function () {
|
|
58827
59393
|
var parseMDX = function () {
|
|
58828
59394
|
return __awaiter(_this, void 0, void 0, function () {
|
|
58829
|
-
var ThinkComponent, ResultComponent, protectedContent, _a, thinkContent, resultContent, parsedData, parsedComponents, finalComponent, fallbackComponent, _loop_1, i, MDXComponent, parsedDataLength, lastItem;
|
|
58830
|
-
|
|
58831
|
-
|
|
59395
|
+
var ThinkComponent, ResultComponent, protectedContent, _a, thinkContent, resultContent, parsedData, parsedComponents, currentComponentCount, cacheKeys, cacheKeys_1, cacheKeys_1_1, key, indexMatch, index, finalComponent, fallbackComponent, _loop_1, i, MDXComponent, parsedDataLength, lastItem;
|
|
59396
|
+
var e_1, _b;
|
|
59397
|
+
return __generator(this, function (_c) {
|
|
59398
|
+
switch (_c.label) {
|
|
58832
59399
|
case 0:
|
|
58833
59400
|
ThinkComponent = null;
|
|
58834
59401
|
ResultComponent = null;
|
|
@@ -58837,8 +59404,8 @@ function ReactAIRenderer(_a) {
|
|
|
58837
59404
|
if (!thinkContent) return [3 /*break*/, 2];
|
|
58838
59405
|
return [4 /*yield*/, renderMdx(thinkContent, scope, allComponents)];
|
|
58839
59406
|
case 1:
|
|
58840
|
-
ThinkComponent =
|
|
58841
|
-
|
|
59407
|
+
ThinkComponent = _c.sent();
|
|
59408
|
+
_c.label = 2;
|
|
58842
59409
|
case 2:
|
|
58843
59410
|
parsedData = [];
|
|
58844
59411
|
if (!resultContent) return [3 /*break*/, 8];
|
|
@@ -58848,46 +59415,110 @@ function ReactAIRenderer(_a) {
|
|
|
58848
59415
|
return parseComponentRecursively(allComponentHandlers, item, scope);
|
|
58849
59416
|
}))];
|
|
58850
59417
|
case 3:
|
|
58851
|
-
parsedComponents =
|
|
59418
|
+
parsedComponents = _c.sent();
|
|
59419
|
+
currentComponentCount = parsedData.length;
|
|
59420
|
+
cacheKeys = Array.from(completedComponentsCacheRef.current.keys());
|
|
59421
|
+
try {
|
|
59422
|
+
for (cacheKeys_1 = __values(cacheKeys), cacheKeys_1_1 = cacheKeys_1.next(); !cacheKeys_1_1.done; cacheKeys_1_1 = cacheKeys_1.next()) {
|
|
59423
|
+
key = cacheKeys_1_1.value;
|
|
59424
|
+
indexMatch = key.match(/-(\d+)$/);
|
|
59425
|
+
if (indexMatch) {
|
|
59426
|
+
index = parseInt(indexMatch[1], 10);
|
|
59427
|
+
if (index >= currentComponentCount) {
|
|
59428
|
+
// 如果索引超出当前组件数量,删除缓存
|
|
59429
|
+
completedComponentsCacheRef.current.delete(key);
|
|
59430
|
+
}
|
|
59431
|
+
}
|
|
59432
|
+
}
|
|
59433
|
+
} catch (e_1_1) {
|
|
59434
|
+
e_1 = {
|
|
59435
|
+
error: e_1_1
|
|
59436
|
+
};
|
|
59437
|
+
} finally {
|
|
59438
|
+
try {
|
|
59439
|
+
if (cacheKeys_1_1 && !cacheKeys_1_1.done && (_b = cacheKeys_1.return)) _b.call(cacheKeys_1);
|
|
59440
|
+
} finally {
|
|
59441
|
+
if (e_1) throw e_1.error;
|
|
59442
|
+
}
|
|
59443
|
+
}
|
|
58852
59444
|
finalComponent = [];
|
|
58853
59445
|
fallbackComponent = [];
|
|
58854
59446
|
_loop_1 = function (i) {
|
|
58855
|
-
var item, _result, placeholderForFallback, componentNameMatch, componentName_1, componentHandler, displayName;
|
|
58856
|
-
return __generator(this, function (
|
|
58857
|
-
switch (
|
|
59447
|
+
var item, currentParsedItem, _result, placeholderForFallback, componentNameMatch, componentName_1, componentHandler, displayName, cacheKey;
|
|
59448
|
+
return __generator(this, function (_d) {
|
|
59449
|
+
switch (_d.label) {
|
|
58858
59450
|
case 0:
|
|
58859
59451
|
item = parsedComponents[i];
|
|
59452
|
+
currentParsedItem = parsedData[i];
|
|
58860
59453
|
_result = void 0;
|
|
58861
59454
|
placeholderForFallback = null;
|
|
58862
59455
|
if (!(item.type === 'text')) return [3 /*break*/, 2];
|
|
58863
59456
|
return [4 /*yield*/, renderText(item.value, scope, allComponents)];
|
|
58864
59457
|
case 1:
|
|
58865
|
-
_result =
|
|
58866
|
-
|
|
59458
|
+
_result = _d.sent();
|
|
59459
|
+
finalComponent.push(_result);
|
|
59460
|
+
return [3 /*break*/, 11];
|
|
58867
59461
|
case 2:
|
|
58868
|
-
return [4 /*yield*/, renderMdx(item.value, scope, allComponents)];
|
|
58869
|
-
case 3:
|
|
58870
|
-
_result = _c.sent();
|
|
58871
59462
|
componentNameMatch = item.value.match(/<([A-Z][A-Za-z0-9]*)/);
|
|
58872
|
-
if (componentNameMatch)
|
|
58873
|
-
|
|
58874
|
-
|
|
58875
|
-
|
|
58876
|
-
|
|
58877
|
-
|
|
58878
|
-
|
|
58879
|
-
|
|
58880
|
-
}
|
|
58881
|
-
placeholderForFallback = /*#__PURE__*/React.createElement(ComponentPlaceholder, {
|
|
58882
|
-
componentName: displayName,
|
|
58883
|
-
customPlaceholder: componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.placeholder,
|
|
58884
|
-
key: "fallback-placeholder-".concat(i)
|
|
58885
|
-
});
|
|
59463
|
+
if (!componentNameMatch) return [3 /*break*/, 9];
|
|
59464
|
+
componentName_1 = componentNameMatch[1];
|
|
59465
|
+
componentHandler = allComponentHandlers.find(function (c) {
|
|
59466
|
+
return c.name === componentName_1;
|
|
59467
|
+
});
|
|
59468
|
+
displayName = componentName_1;
|
|
59469
|
+
if (componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.label) {
|
|
59470
|
+
displayName = componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.label;
|
|
58886
59471
|
}
|
|
58887
|
-
|
|
59472
|
+
placeholderForFallback = /*#__PURE__*/React.createElement(ComponentPlaceholder, {
|
|
59473
|
+
componentName: displayName,
|
|
59474
|
+
loader: componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.loader,
|
|
59475
|
+
key: "fallback-loader-".concat(componentName_1)
|
|
59476
|
+
});
|
|
59477
|
+
if (!(currentParsedItem.isComplete === true || !(componentHandler === null || componentHandler === void 0 ? void 0 : componentHandler.loader))) return [3 /*break*/, 6];
|
|
59478
|
+
cacheKey = "mdx-component-".concat(componentName_1, "-").concat(i);
|
|
59479
|
+
if (!completedComponentsCacheRef.current.has(cacheKey)) return [3 /*break*/, 3];
|
|
59480
|
+
// 使用缓存的组件
|
|
59481
|
+
_result = completedComponentsCacheRef.current.get(cacheKey);
|
|
59482
|
+
return [3 /*break*/, 5];
|
|
59483
|
+
case 3:
|
|
59484
|
+
return [4 /*yield*/, renderMdx(item.value, scope, allComponents)];
|
|
58888
59485
|
case 4:
|
|
59486
|
+
// 缓存不存在,调用 renderMdx 并存入缓存
|
|
59487
|
+
_result = _d.sent();
|
|
59488
|
+
// 为组件设置 key,确保 React 能正确识别
|
|
59489
|
+
if (/*#__PURE__*/React.isValidElement(_result)) {
|
|
59490
|
+
_result = /*#__PURE__*/React.cloneElement(_result, {
|
|
59491
|
+
key: cacheKey
|
|
59492
|
+
});
|
|
59493
|
+
} else {
|
|
59494
|
+
_result = /*#__PURE__*/React.createElement(React.Fragment, {
|
|
59495
|
+
key: cacheKey
|
|
59496
|
+
}, _result);
|
|
59497
|
+
}
|
|
59498
|
+
// 存入缓存
|
|
59499
|
+
completedComponentsCacheRef.current.set(cacheKey, _result);
|
|
59500
|
+
_d.label = 5;
|
|
59501
|
+
case 5:
|
|
59502
|
+
finalComponent.push(_result);
|
|
59503
|
+
return [3 /*break*/, 8];
|
|
59504
|
+
case 6:
|
|
59505
|
+
return [4 /*yield*/, renderMdx(item.value, scope, allComponents)];
|
|
59506
|
+
case 7:
|
|
59507
|
+
// 组件未完成,正常渲染
|
|
59508
|
+
_result = _d.sent();
|
|
59509
|
+
finalComponent.push(placeholderForFallback);
|
|
59510
|
+
_d.label = 8;
|
|
59511
|
+
case 8:
|
|
59512
|
+
return [3 /*break*/, 11];
|
|
59513
|
+
case 9:
|
|
59514
|
+
return [4 /*yield*/, renderMdx(item.value, scope, allComponents)];
|
|
59515
|
+
case 10:
|
|
59516
|
+
// 没有匹配到组件名,正常渲染
|
|
59517
|
+
_result = _d.sent();
|
|
58889
59518
|
finalComponent.push(_result);
|
|
58890
|
-
|
|
59519
|
+
_d.label = 11;
|
|
59520
|
+
case 11:
|
|
59521
|
+
// fallbackComponent 应该是 finalComponent 的前 i 个元素 + 当前 item 的 loader
|
|
58891
59522
|
fallbackComponent.length = 0;
|
|
58892
59523
|
fallbackComponent.push.apply(fallbackComponent, __spreadArray([], __read(finalComponent.slice(0, i)), false));
|
|
58893
59524
|
if (placeholderForFallback) {
|
|
@@ -58898,13 +59529,13 @@ function ReactAIRenderer(_a) {
|
|
|
58898
59529
|
});
|
|
58899
59530
|
};
|
|
58900
59531
|
i = 0;
|
|
58901
|
-
|
|
59532
|
+
_c.label = 4;
|
|
58902
59533
|
case 4:
|
|
58903
59534
|
if (!(i < parsedComponents.length)) return [3 /*break*/, 7];
|
|
58904
59535
|
return [5 /*yield**/, _loop_1(i)];
|
|
58905
59536
|
case 5:
|
|
58906
|
-
|
|
58907
|
-
|
|
59537
|
+
_c.sent();
|
|
59538
|
+
_c.label = 6;
|
|
58908
59539
|
case 6:
|
|
58909
59540
|
i++;
|
|
58910
59541
|
return [3 /*break*/, 4];
|
|
@@ -58919,7 +59550,7 @@ function ReactAIRenderer(_a) {
|
|
|
58919
59550
|
children: finalComponent
|
|
58920
59551
|
})
|
|
58921
59552
|
});
|
|
58922
|
-
|
|
59553
|
+
_c.label = 8;
|
|
58923
59554
|
case 8:
|
|
58924
59555
|
MDXComponent = /*#__PURE__*/runtime.jsxs(React.Fragment, {
|
|
58925
59556
|
children: [ThinkComponent, ResultComponent]
|