@blocklet/pages-kit 0.4.111 → 0.4.113
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 +22 -2
- package/lib/cjs/components/CustomComponentRenderer/state.js +1 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/components/CustomComponentRenderer/index.js +23 -3
- package/lib/esm/components/CustomComponentRenderer/state.js +1 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
3
|
-
import { RenderNestedComponent } from '../../utils/property';
|
|
4
|
+
import { RenderNestedComponent, parsePropertyValue } from '../../utils/property';
|
|
4
5
|
import BlockletReactComponentRenderer from './BlockletReactComponentRenderer';
|
|
5
6
|
import { DevProvider, useDev } from './DevProvider';
|
|
6
7
|
import { ComponentError } from './ErrorComponent';
|
|
@@ -24,11 +25,30 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
|
|
|
24
25
|
}
|
|
25
26
|
const component = useComponent({ ...props, dev });
|
|
26
27
|
const ctx = useCustomComponentRenderer();
|
|
28
|
+
// 传递过来的参数,需要确保经过前端 parsePropertyValue 处理,并且补全不存在的参数
|
|
29
|
+
const parsedProps = useMemo(() => {
|
|
30
|
+
const result = {
|
|
31
|
+
...component?.props,
|
|
32
|
+
...props?.props,
|
|
33
|
+
};
|
|
34
|
+
Object.entries(component?.properties ?? {}).forEach(([id, value]) => {
|
|
35
|
+
const { data: property } = value;
|
|
36
|
+
const key = property.key ?? property.id ?? id;
|
|
37
|
+
const defaultLocale = dev?.defaultLocale ?? 'en';
|
|
38
|
+
const locale = props?.locale;
|
|
39
|
+
const defaultValue = property.locales?.[locale]?.defaultValue ?? property.locales?.[defaultLocale]?.defaultValue;
|
|
40
|
+
result[key] = parsePropertyValue(property, result[key] ?? defaultValue, {
|
|
41
|
+
locale: props?.locale,
|
|
42
|
+
defaultLocale,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
}, [props?.props, component?.properties, component?.props]);
|
|
27
47
|
if (component?.error) {
|
|
28
48
|
throw component.error;
|
|
29
49
|
}
|
|
30
50
|
const renderComponentChildren = (Component) => {
|
|
31
|
-
const children =
|
|
51
|
+
const children = _jsx(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: parsedProps });
|
|
32
52
|
return ctx?.customRendererComponent ? (_jsx(ctx.customRendererComponent, { Component: Component, children: children })) : (children);
|
|
33
53
|
};
|
|
34
54
|
if (component?.Component && renderType === 'view') {
|
|
@@ -49,7 +69,7 @@ function Renderer({ renderCount, Component, locale, props, }) {
|
|
|
49
69
|
if (val?.type === RenderNestedComponent) {
|
|
50
70
|
return [
|
|
51
71
|
key,
|
|
52
|
-
_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties }),
|
|
72
|
+
_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props }),
|
|
53
73
|
];
|
|
54
74
|
}
|
|
55
75
|
return [key, val];
|