@blocklet/pages-kit 0.4.105 → 0.4.107
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/lib/cjs/components/CustomComponentRenderer/index.js +9 -5
- package/lib/cjs/components/CustomComponentRenderer/state.js +11 -4
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/property.js +7 -7
- package/lib/esm/components/CustomComponentRenderer/index.js +9 -5
- package/lib/esm/components/CustomComponentRenderer/state.js +11 -4
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/property.js +7 -4
- package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -48,7 +48,7 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
|
|
|
48
48
|
throw component.error;
|
|
49
49
|
}
|
|
50
50
|
const renderComponentChildren = (Component) => {
|
|
51
|
-
const children = ((0, jsx_runtime_1.jsx)(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: { ...component?.props
|
|
51
|
+
const children = ((0, jsx_runtime_1.jsx)(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: { ...component?.props } }));
|
|
52
52
|
return ctx?.customRendererComponent ? ((0, jsx_runtime_1.jsx)(ctx.customRendererComponent, { Component: Component, children: children })) : (children);
|
|
53
53
|
};
|
|
54
54
|
if (component?.Component && renderType === 'view') {
|
|
@@ -65,10 +65,14 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
|
|
|
65
65
|
}
|
|
66
66
|
function Renderer({ renderCount, Component, locale, props, }) {
|
|
67
67
|
const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
// if is NestedComponent, render it
|
|
69
|
+
if (val?.type === property_1.RenderNestedComponent) {
|
|
70
|
+
return [
|
|
71
|
+
key,
|
|
72
|
+
(0, jsx_runtime_1.jsx)(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props }),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
return [key, val];
|
|
72
76
|
}));
|
|
73
77
|
return (0, jsx_runtime_1.jsx)(Component, { locale: locale, ...componentProps });
|
|
74
78
|
}
|
|
@@ -108,7 +108,10 @@ function importCustomComponent(m, { componentId }) {
|
|
|
108
108
|
}
|
|
109
109
|
return null;
|
|
110
110
|
}, [loading, error, ResolvedComponent, props]);
|
|
111
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Fade, { in: !loading, timeout: 500, children: (0, jsx_runtime_1.jsx)(material_1.Box, { className: "CustomComponent-root",
|
|
111
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Fade, { in: !loading, timeout: 500, children: (0, jsx_runtime_1.jsx)(material_1.Box, { className: "CustomComponent-root", sx: {
|
|
112
|
+
// 使用 display: contents 避免外层包裹的 div 样式影响组件内部样式
|
|
113
|
+
display: 'contents',
|
|
114
|
+
}, children: content }) }));
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
// non-Promise case
|
|
@@ -267,7 +270,7 @@ async function loadComponents(input) {
|
|
|
267
270
|
instances: Object.fromEntries(result.instances.map(({ id, ...instance }) => [id, instance])),
|
|
268
271
|
};
|
|
269
272
|
}
|
|
270
|
-
function useComponent({ instanceId, componentId, properties, locale, dev }) {
|
|
273
|
+
function useComponent({ instanceId, componentId, properties, locale, dev, props, }) {
|
|
271
274
|
const transpile = useTranspileComponent({ componentId, locale, properties, dev });
|
|
272
275
|
const preload = usePreloadComponent({ instanceId, componentId, properties, locale, dev });
|
|
273
276
|
const componentProperties = transpile?.componentProperties ?? preload?.componentProperties;
|
|
@@ -281,8 +284,12 @@ function useComponent({ instanceId, componentId, properties, locale, dev }) {
|
|
|
281
284
|
const property = componentProperties?.[key]?.data;
|
|
282
285
|
if (!property)
|
|
283
286
|
return undefined;
|
|
287
|
+
// 如果提供了 key 优先使用 key
|
|
288
|
+
const propKey = property.key ?? property.id;
|
|
289
|
+
// 如果提供了 props 优先使用 props 中的值
|
|
290
|
+
const propValue = props?.[propKey] ?? value;
|
|
284
291
|
// keep preload props
|
|
285
|
-
let v = (0, property_1.parsePropertyValue)(property,
|
|
292
|
+
let v = (0, property_1.parsePropertyValue)(property, propValue, {
|
|
286
293
|
locale,
|
|
287
294
|
defaultLocale: dev?.defaultLocale,
|
|
288
295
|
});
|
|
@@ -296,7 +303,7 @@ function useComponent({ instanceId, componentId, properties, locale, dev }) {
|
|
|
296
303
|
};
|
|
297
304
|
}
|
|
298
305
|
// if key is undefined, use id
|
|
299
|
-
return [
|
|
306
|
+
return [propKey, v];
|
|
300
307
|
})
|
|
301
308
|
.filter((i) => !!i)),
|
|
302
309
|
},
|