@blocklet/pages-kit 0.2.219 → 0.2.221

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.
@@ -56,8 +56,8 @@ const property_1 = require("../../utils/property");
56
56
  const MAXIMUM_RENDER_STACK_SIZE = 20;
57
57
  function CustomComponentRenderer(_a) {
58
58
  var _b;
59
- var props = __rest(_a, []);
60
- return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: (0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
59
+ var { defaultLocale = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config.defaultLocale } = _a, props = __rest(_a, ["defaultLocale"]);
60
+ return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: (0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { defaultLocale: defaultLocale, instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
61
61
  }
62
62
  exports.default = CustomComponentRenderer;
63
63
  function ComponentRenderer(_a) {
@@ -157,13 +157,14 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
157
157
  const preloadComponent = (0, react_1.useMemo)(() => getScriptComponent(componentId), [componentId, PRELOAD_COMPONENTS_STATE_KEY]);
158
158
  const preloadState = (0, react_1.useMemo)(() => {
159
159
  var _a, _b;
160
- return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale || defaultLocale];
161
- }, [instanceId, locale, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
160
+ return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale];
161
+ }, [instanceId, locale, PRELOAD_COMPONENTS_STATE_KEY]);
162
162
  const preloadDefaultState = (0, react_1.useMemo)(() => {
163
163
  var _a, _b;
164
164
  return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[defaultLocale];
165
- }, [instanceId, locale, PRELOAD_COMPONENTS_STATE_KEY]);
165
+ }, [instanceId, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
166
166
  const previousPreload = (0, react_1.useRef)();
167
+ const [, update] = (0, react_1.useState)(0);
167
168
  if ((props || preloadState) && preloadComponent) {
168
169
  previousPreload.current = {
169
170
  Component: preloadComponent.Component,
@@ -172,7 +173,9 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
172
173
  return previousPreload.current;
173
174
  }
174
175
  if (!(components === null || components === void 0 ? void 0 : components.length) && preloadComponent) {
175
- loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale });
176
+ loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale }).then(() => {
177
+ update(PRELOAD_COMPONENTS_STATE_KEY);
178
+ });
176
179
  if (previousPreload.current) {
177
180
  return previousPreload.current;
178
181
  }
@@ -30,8 +30,8 @@ import { RenderNestedComponent, mergeComponent } from '../../utils/property';
30
30
  const MAXIMUM_RENDER_STACK_SIZE = 20;
31
31
  export default function CustomComponentRenderer(_a) {
32
32
  var _b;
33
- var props = __rest(_a, []);
34
- return (_jsx(ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: _jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
33
+ var { defaultLocale = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config.defaultLocale } = _a, props = __rest(_a, ["defaultLocale"]);
34
+ return (_jsx(ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: _jsx(ComponentRenderer, Object.assign({}, props, { defaultLocale: defaultLocale, instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
35
35
  }
36
36
  function ComponentRenderer(_a) {
37
37
  var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
@@ -130,13 +130,14 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
130
130
  const preloadComponent = useMemo(() => getScriptComponent(componentId), [componentId, PRELOAD_COMPONENTS_STATE_KEY]);
131
131
  const preloadState = useMemo(() => {
132
132
  var _a, _b;
133
- return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale || defaultLocale];
134
- }, [instanceId, locale, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
133
+ return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale];
134
+ }, [instanceId, locale, PRELOAD_COMPONENTS_STATE_KEY]);
135
135
  const preloadDefaultState = useMemo(() => {
136
136
  var _a, _b;
137
137
  return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[defaultLocale];
138
- }, [instanceId, locale, PRELOAD_COMPONENTS_STATE_KEY]);
138
+ }, [instanceId, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
139
139
  const previousPreload = useRef();
140
+ const [, update] = useState(0);
140
141
  if ((props || preloadState) && preloadComponent) {
141
142
  previousPreload.current = {
142
143
  Component: preloadComponent.Component,
@@ -145,7 +146,9 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
145
146
  return previousPreload.current;
146
147
  }
147
148
  if (!(components === null || components === void 0 ? void 0 : components.length) && preloadComponent) {
148
- loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale });
149
+ loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale }).then(() => {
150
+ update(PRELOAD_COMPONENTS_STATE_KEY);
151
+ });
149
152
  if (previousPreload.current) {
150
153
  return previousPreload.current;
151
154
  }
@@ -17,5 +17,5 @@ export interface CustomComponentRendererProps {
17
17
  [key: string]: any;
18
18
  };
19
19
  }
20
- export default function CustomComponentRenderer({ ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
20
+ export default function CustomComponentRenderer({ defaultLocale, ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
21
21
  export declare function transpileAndLoadScript(script: string): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.219",
3
+ "version": "0.2.221",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"