@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.
@@ -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, ...props.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
- return [
69
- key,
70
- val?.type === property_1.RenderNestedComponent ? ((0, jsx_runtime_1.jsx)(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props })) : (val),
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", children: content }) }));
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, value, {
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 [property.key || property.id, v];
306
+ return [propKey, v];
300
307
  })
301
308
  .filter((i) => !!i)),
302
309
  },