@blocklet/pages-kit 0.4.106 → 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.
@@ -22,9 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.initDynamicParsePropertyValueHandlers = exports.RenderNestedComponent = void 0;
30
27
  exports.componentUMDName = componentUMDName;
@@ -34,7 +31,6 @@ exports.safeYamlParse = safeYamlParse;
34
31
  exports.parsePropertyValue = parsePropertyValue;
35
32
  exports.assignNullableFields = assignNullableFields;
36
33
  exports.getComponentDependencies = getComponentDependencies;
37
- const isNil_1 = __importDefault(require("lodash/isNil"));
38
34
  const yaml = __importStar(require("yaml"));
39
35
  const common_1 = require("./common");
40
36
  function componentUMDName({ componentId }) {
@@ -134,11 +130,15 @@ function parsePropertyValue(property, value, { locale, defaultLocale, propertyHa
134
130
  ...(propertyHandlers ?? {}),
135
131
  };
136
132
  if (mixedPropertyHandlers && property.type && typeof mixedPropertyHandlers[property.type] === 'function') {
137
- const handler = mixedPropertyHandlers[property.type];
138
- const result = handler?.(value);
139
- if (!(0, isNil_1.default)(result)) {
133
+ try {
134
+ const handler = mixedPropertyHandlers[property.type];
135
+ const result = handler?.(value);
140
136
  return result;
141
137
  }
138
+ catch (error) {
139
+ console.error('parse property value in handler error', error);
140
+ return undefined;
141
+ }
142
142
  }
143
143
  if (property.type === 'json') {
144
144
  if (!value)
@@ -28,7 +28,7 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
28
28
  throw component.error;
29
29
  }
30
30
  const renderComponentChildren = (Component) => {
31
- const children = (_jsx(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: { ...component?.props, ...props.props } }));
31
+ const children = (_jsx(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: { ...component?.props } }));
32
32
  return ctx?.customRendererComponent ? (_jsx(ctx.customRendererComponent, { Component: Component, children: children })) : (children);
33
33
  };
34
34
  if (component?.Component && renderType === 'view') {
@@ -45,10 +45,14 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
45
45
  }
46
46
  function Renderer({ renderCount, Component, locale, props, }) {
47
47
  const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
48
- return [
49
- key,
50
- val?.type === RenderNestedComponent ? (_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props })) : (val),
51
- ];
48
+ // if is NestedComponent, render it
49
+ if (val?.type === RenderNestedComponent) {
50
+ return [
51
+ key,
52
+ _jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props }),
53
+ ];
54
+ }
55
+ return [key, val];
52
56
  }));
53
57
  return _jsx(Component, { locale: locale, ...componentProps });
54
58
  }
@@ -76,7 +76,10 @@ function importCustomComponent(m, { componentId }) {
76
76
  }
77
77
  return null;
78
78
  }, [loading, error, ResolvedComponent, props]);
79
- return (_jsx(Fade, { in: !loading, timeout: 500, children: _jsx(Box, { className: "CustomComponent-root", children: content }) }));
79
+ return (_jsx(Fade, { in: !loading, timeout: 500, children: _jsx(Box, { className: "CustomComponent-root", sx: {
80
+ // 使用 display: contents 避免外层包裹的 div 样式影响组件内部样式
81
+ display: 'contents',
82
+ }, children: content }) }));
80
83
  };
81
84
  }
82
85
  // non-Promise case
@@ -234,7 +237,7 @@ async function loadComponents(input) {
234
237
  instances: Object.fromEntries(result.instances.map(({ id, ...instance }) => [id, instance])),
235
238
  };
236
239
  }
237
- export function useComponent({ instanceId, componentId, properties, locale, dev }) {
240
+ export function useComponent({ instanceId, componentId, properties, locale, dev, props, }) {
238
241
  const transpile = useTranspileComponent({ componentId, locale, properties, dev });
239
242
  const preload = usePreloadComponent({ instanceId, componentId, properties, locale, dev });
240
243
  const componentProperties = transpile?.componentProperties ?? preload?.componentProperties;
@@ -248,8 +251,12 @@ export function useComponent({ instanceId, componentId, properties, locale, dev
248
251
  const property = componentProperties?.[key]?.data;
249
252
  if (!property)
250
253
  return undefined;
254
+ // 如果提供了 key 优先使用 key
255
+ const propKey = property.key ?? property.id;
256
+ // 如果提供了 props 优先使用 props 中的值
257
+ const propValue = props?.[propKey] ?? value;
251
258
  // keep preload props
252
- let v = parsePropertyValue(property, value, {
259
+ let v = parsePropertyValue(property, propValue, {
253
260
  locale,
254
261
  defaultLocale: dev?.defaultLocale,
255
262
  });
@@ -263,7 +270,7 @@ export function useComponent({ instanceId, componentId, properties, locale, dev
263
270
  };
264
271
  }
265
272
  // if key is undefined, use id
266
- return [property.key || property.id, v];
273
+ return [propKey, v];
267
274
  })
268
275
  .filter((i) => !!i)),
269
276
  },