@blocklet/pages-kit 0.4.32 → 0.4.33

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.
Files changed (50) hide show
  1. package/lib/cjs/api/call.js +7 -18
  2. package/lib/cjs/api/pages-kit.js +5 -17
  3. package/lib/cjs/builtin/async/react-scroll-to-bottom.js +5 -1
  4. package/lib/cjs/builtin/components/LanguageField/index.js +6 -18
  5. package/lib/cjs/builtin/iconify/react.js +1 -1
  6. package/lib/cjs/builtin/page/header.js +8 -5
  7. package/lib/cjs/builtin/session.js +6 -0
  8. package/lib/cjs/builtin/stream.js +1 -1
  9. package/lib/cjs/builtin/utils.js +3 -5
  10. package/lib/cjs/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
  11. package/lib/cjs/components/CustomComponentRenderer/DevProvider.js +2 -14
  12. package/lib/cjs/components/CustomComponentRenderer/ErrorComponent.js +2 -14
  13. package/lib/cjs/components/CustomComponentRenderer/index.js +12 -27
  14. package/lib/cjs/components/CustomComponentRenderer/state.js +121 -151
  15. package/lib/cjs/components/ResponsiveImage/index.js +3 -16
  16. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  17. package/lib/cjs/utils/inject-es-module-shims-options.js +1 -2
  18. package/lib/cjs/utils/inject-global-components-dump-json.js +1 -1
  19. package/lib/cjs/utils/inject-global-components.js +29 -20
  20. package/lib/cjs/utils/preload.js +1 -15
  21. package/lib/cjs/utils/property.js +31 -25
  22. package/lib/cjs/utils/typescript/builtin-module-transformer.js +12 -9
  23. package/lib/esm/api/call.js +7 -18
  24. package/lib/esm/api/pages-kit.js +5 -17
  25. package/lib/esm/builtin/async/react-scroll-to-bottom.js +5 -1
  26. package/lib/esm/builtin/components/LanguageField/index.js +6 -18
  27. package/lib/esm/builtin/iconify/react.js +1 -1
  28. package/lib/esm/builtin/page/header.js +8 -5
  29. package/lib/esm/builtin/session.js +5 -0
  30. package/lib/esm/builtin/stream.js +1 -1
  31. package/lib/esm/builtin/utils.js +3 -5
  32. package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
  33. package/lib/esm/components/CustomComponentRenderer/DevProvider.js +2 -14
  34. package/lib/esm/components/CustomComponentRenderer/ErrorComponent.js +2 -14
  35. package/lib/esm/components/CustomComponentRenderer/index.js +12 -27
  36. package/lib/esm/components/CustomComponentRenderer/state.js +121 -151
  37. package/lib/esm/components/ResponsiveImage/index.js +3 -16
  38. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  39. package/lib/esm/utils/inject-es-module-shims-options.js +1 -2
  40. package/lib/esm/utils/inject-global-components-dump-json.js +1 -1
  41. package/lib/esm/utils/inject-global-components.js +29 -20
  42. package/lib/esm/utils/preload.js +1 -15
  43. package/lib/esm/utils/property.js +30 -25
  44. package/lib/esm/utils/typescript/builtin-module-transformer.js +10 -8
  45. package/lib/types/builtin/session.d.ts +13 -0
  46. package/lib/types/tsconfig.tsbuildinfo +1 -1
  47. package/lib/types/types/core.d.ts +11 -2
  48. package/lib/types/utils/property.d.ts +1 -0
  49. package/lib/types/utils/typescript/builtin-module-transformer.d.ts +1 -0
  50. package/package.json +1 -1
@@ -1,14 +1,3 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
1
  import { jsx as _jsx } from "react/jsx-runtime";
13
2
  import { ErrorBoundary } from 'react-error-boundary';
14
3
  import { RenderNestedComponent } from '../../utils/property';
@@ -20,40 +9,36 @@ import { useComponent } from './state';
20
9
  export * from './state';
21
10
  export * from './context';
22
11
  const MAXIMUM_RENDER_STACK_SIZE = 20;
23
- export default function CustomComponentRenderer(_a) {
24
- var _b;
25
- var { dev } = _a, props = __rest(_a, ["dev"]);
12
+ export default function CustomComponentRenderer({ dev, ...props }) {
26
13
  const inheritedDev = useDev();
27
14
  const BuiltinComponent = BuiltinComponents[props.componentId];
28
- return (_jsx(ErrorBoundary, { FallbackComponent: (props === null || props === void 0 ? void 0 : props.fallbackRender) || ComponentError, resetKeys: [Date.now()], children: _jsx(DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: BuiltinComponent ? (_jsx(BuiltinComponent, Object.assign({}, props))) : (_jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId, renderType: props.renderType }))) }) }));
15
+ return (_jsx(ErrorBoundary, { FallbackComponent: props?.fallbackRender || ComponentError, resetKeys: [Date.now()], children: _jsx(DevProvider, { dev: dev ?? inheritedDev, children: BuiltinComponent ? (_jsx(BuiltinComponent, { ...props })) : (_jsx(ComponentRenderer, { ...props, instanceId: props.instanceId ?? props.componentId, renderType: props.renderType })) }) }));
29
16
  }
30
17
  const BuiltinComponents = {
31
18
  'blocklet-react-component': BlockletReactComponentRenderer,
32
19
  };
33
- function ComponentRenderer(_a) {
34
- var _b;
35
- var { renderCount = 0, blockletId, blockletTitle, componentName, renderType = 'view' } = _a, props = __rest(_a, ["renderCount", "blockletId", "blockletTitle", "componentName", "renderType"]);
20
+ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, componentName, renderType = 'view', ...props }) {
36
21
  const dev = useDev();
37
22
  if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
38
23
  throw new Error('Maximum render stack size exceeded');
39
24
  }
40
- const component = useComponent(Object.assign(Object.assign({}, props), { dev }));
25
+ const component = useComponent({ ...props, dev });
41
26
  const ctx = useCustomComponentRenderer();
42
- if (component === null || component === void 0 ? void 0 : component.error) {
27
+ if (component?.error) {
43
28
  throw component.error;
44
29
  }
45
30
  const renderComponentChildren = (Component) => {
46
- const children = (_jsx(Renderer, Object.assign({ renderCount: renderCount + 1 }, props, { Component: Component, props: Object.assign(Object.assign({}, component === null || component === void 0 ? void 0 : component.props), props.props) })));
47
- return (ctx === null || ctx === void 0 ? void 0 : ctx.customRendererComponent) ? (_jsx(ctx.customRendererComponent, { Component: Component, children: children })) : (children);
31
+ const children = (_jsx(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: { ...component?.props, ...props.props } }));
32
+ return ctx?.customRendererComponent ? (_jsx(ctx.customRendererComponent, { Component: Component, children: children })) : (children);
48
33
  };
49
- if ((component === null || component === void 0 ? void 0 : component.Component) && renderType === 'view') {
34
+ if (component?.Component && renderType === 'view') {
50
35
  return renderComponentChildren(component.Component);
51
36
  }
52
- if ((component === null || component === void 0 ? void 0 : component.EditComponent) && renderType === 'setting') {
37
+ if (component?.EditComponent && renderType === 'setting') {
53
38
  return renderComponentChildren(component.EditComponent);
54
39
  }
55
40
  // if the component is not in the dev.components, it means the component is not loaded
56
- if ((dev === null || dev === void 0 ? void 0 : dev.mode) === 'draft' && dev && ((_b = dev.components) === null || _b === void 0 ? void 0 : _b[props.componentId]) === undefined) {
41
+ if (dev?.mode === 'draft' && dev && dev.components?.[props.componentId] === undefined) {
57
42
  return (_jsx(ComponentError, { componentId: props.componentId, componentName: componentName, blockletId: blockletId, blockletTitle: blockletTitle, message: "Component not found in available components", showHints: true }));
58
43
  }
59
44
  return null;
@@ -62,8 +47,8 @@ function Renderer({ renderCount, Component, locale, props, }) {
62
47
  const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
63
48
  return [
64
49
  key,
65
- (val === null || val === void 0 ? void 0 : val.type) === RenderNestedComponent ? (_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props })) : (val),
50
+ val?.type === RenderNestedComponent ? (_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props })) : (val),
66
51
  ];
67
52
  }));
68
- return _jsx(Component, Object.assign({ locale: locale }, componentProps));
53
+ return _jsx(Component, { locale: locale, ...componentProps });
69
54
  }
@@ -1,23 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
22
2
  import { cx } from '@emotion/css';
23
3
  import { Skeleton, Fade, Box } from '@mui/material';
@@ -46,9 +26,9 @@ function importCustomComponent(m, { componentId }) {
46
26
  // 只在组件首次加载时执行,避免重复加载
47
27
  useEffect(() => {
48
28
  let isMounted = true;
49
- const loadComponent = () => __awaiter(this, void 0, void 0, function* () {
29
+ const loadComponent = async () => {
50
30
  try {
51
- const result = yield m;
31
+ const result = await m;
52
32
  if (!isMounted)
53
33
  return;
54
34
  if (!result) {
@@ -76,7 +56,7 @@ function importCustomComponent(m, { componentId }) {
76
56
  setLoading(false);
77
57
  }
78
58
  }
79
- });
59
+ };
80
60
  loadComponent();
81
61
  return () => {
82
62
  isMounted = false;
@@ -92,7 +72,7 @@ function importCustomComponent(m, { componentId }) {
92
72
  }
93
73
  // 动态渲染组件,但允许props更新传递
94
74
  if (ResolvedComponent) {
95
- return _jsx(ResolvedComponent, Object.assign({}, props));
75
+ return _jsx(ResolvedComponent, { ...props });
96
76
  }
97
77
  return null;
98
78
  }, [loading, error, ResolvedComponent, props]);
@@ -131,7 +111,7 @@ function importCustomComponent(m, { componentId }) {
131
111
  // if a component is found and has CSS, wrap the component with styles
132
112
  if (Component && css) {
133
113
  const OriginalComponent = Component;
134
- Component = (props) => (_jsxs(_Fragment, { children: [_jsx(Helmet, { children: _jsx("style", { children: css }) }), _jsx(OriginalComponent, Object.assign({}, props, { className: cx(props.className, `CustomComponent_${componentId}`) }))] }));
114
+ Component = (props) => (_jsxs(_Fragment, { children: [_jsx(Helmet, { children: _jsx("style", { children: css }) }), _jsx(OriginalComponent, { ...props, className: cx(props.className, `CustomComponent_${componentId}`) })] }));
135
115
  }
136
116
  // keep aigneOutputValueSchema
137
117
  if (Component && m.aigneOutputValueSchema) {
@@ -141,17 +121,15 @@ function importCustomComponent(m, { componentId }) {
141
121
  }
142
122
  export function getPropertiesFromCode(m) {
143
123
  let propertiesFromCode = null;
144
- if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
124
+ if (typeof m?.PROPERTIES_SCHEMA === 'object' && m?.PROPERTIES_SCHEMA.length) {
145
125
  propertiesFromCode = {};
146
126
  m.PROPERTIES_SCHEMA.forEach((data, index) => {
147
- var _a, _b, _c;
148
127
  // @ts-ignore
149
- (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.blocklet) === null || _a === void 0 ? void 0 : _a.languages) === null || _b === void 0 ? void 0 : _b.forEach) === null || _c === void 0 ? void 0 : _c.call(_b, (item) => {
150
- var _a, _b;
128
+ window?.blocklet?.languages?.forEach?.((item) => {
151
129
  const { code: localKey } = item;
152
- if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
130
+ if (!data?.locales?.[localKey]) {
153
131
  // fallback to en
154
- set(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
132
+ set(data, `locales.${localKey}`, data.locales?.en);
155
133
  }
156
134
  });
157
135
  propertiesFromCode[data.id] = {
@@ -163,10 +141,10 @@ export function getPropertiesFromCode(m) {
163
141
  return propertiesFromCode;
164
142
  }
165
143
  export const customComponentStates = () => {
166
- states !== null && states !== void 0 ? states : (states = create()(immer((set, get) => ({
144
+ states ??= create()(immer((set, get) => ({
167
145
  state: {
168
- config: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config),
169
- components: Object.fromEntries(Object.entries(Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components))
146
+ config: { ...PRELOAD_COMPONENTS_STATE?.config },
147
+ components: Object.fromEntries(Object.entries({ ...PRELOAD_COMPONENTS_STATE?.components })
170
148
  .map(([componentId, preload]) => {
171
149
  let Component;
172
150
  if (preload.componentModuleGlobalVariable) {
@@ -186,15 +164,14 @@ export const customComponentStates = () => {
186
164
  console.warn(`Component global variable ${preload.componentModuleGlobalVariable} is not a function`);
187
165
  }
188
166
  }
189
- return [componentId, Object.assign(Object.assign({}, preload), { Component })];
167
+ return [componentId, { ...preload, Component }];
190
168
  })
191
169
  .filter((i) => !!i)),
192
- instances: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.instances),
170
+ instances: { ...PRELOAD_COMPONENTS_STATE?.instances },
193
171
  },
194
172
  getComponent({ instanceId, componentId, locale }) {
195
- var _a, _b, _c, _d;
196
173
  const { config: { supportedLocales }, components, instances, } = get().state;
197
- if (!(supportedLocales === null || supportedLocales === void 0 ? void 0 : supportedLocales.some((i) => i.locale === locale)))
174
+ if (!supportedLocales?.some((i) => i.locale === locale))
198
175
  return null;
199
176
  const c = components[componentId];
200
177
  if (!c)
@@ -203,92 +180,87 @@ export const customComponentStates = () => {
203
180
  if (!Component)
204
181
  return null;
205
182
  if (!instanceId) {
206
- return { component, Component, componentProperties: (_a = components[componentId]) === null || _a === void 0 ? void 0 : _a.component.properties };
183
+ return { component, Component, componentProperties: components[componentId]?.component.properties };
207
184
  }
208
185
  const instance = instances[instanceId];
209
186
  if (!instance)
210
187
  return null;
211
- const props = (_c = (_b = instance.locales) === null || _b === void 0 ? void 0 : _b[locale]) === null || _c === void 0 ? void 0 : _c.props;
188
+ const props = instance.locales?.[locale]?.props;
212
189
  if (!props)
213
190
  return null;
214
- return { component, Component, props, componentProperties: (_d = components[componentId]) === null || _d === void 0 ? void 0 : _d.component.properties };
191
+ return { component, Component, props, componentProperties: components[componentId]?.component.properties };
215
192
  },
216
- loadComponents(input) {
217
- return __awaiter(this, void 0, void 0, function* () {
218
- const result = yield loadComponents(input);
219
- if (result) {
220
- set((s) => {
221
- s.state.config = result.config;
222
- Object.assign(s.state.components, result.components);
223
- Object.entries(result.instances).forEach(([instanceId, instance]) => {
224
- var _a, _b;
225
- var _c, _d;
226
- (_a = (_c = s.state.instances)[instanceId]) !== null && _a !== void 0 ? _a : (_c[instanceId] = { componentId: instance.componentId });
227
- (_b = (_d = s.state.instances[instanceId]).locales) !== null && _b !== void 0 ? _b : (_d.locales = {});
228
- Object.assign(s.state.instances[instanceId].locales, instance.locales);
229
- });
193
+ async loadComponents(input) {
194
+ const result = await loadComponents(input);
195
+ if (result) {
196
+ set((s) => {
197
+ s.state.config = result.config;
198
+ Object.assign(s.state.components, result.components);
199
+ Object.entries(result.instances).forEach(([instanceId, instance]) => {
200
+ s.state.instances[instanceId] ??= { componentId: instance.componentId };
201
+ s.state.instances[instanceId].locales ??= {};
202
+ Object.assign(s.state.instances[instanceId].locales, instance.locales);
230
203
  });
231
- }
232
- });
204
+ });
205
+ }
233
206
  },
234
- }))));
207
+ })));
235
208
  return states;
236
209
  };
237
- function loadComponents(input) {
238
- return __awaiter(this, void 0, void 0, function* () {
239
- const result = yield preloadComponents(Object.assign(Object.assign({}, input), { module: PreloadComponentScriptModule.ESM }));
240
- if (!result)
241
- return null;
242
- const components = Object.fromEntries(yield Promise.all(Object.values(result.components).map((item) => __awaiter(this, void 0, void 0, function* () {
243
- if (item.script.module !== PreloadComponentScriptModule.ESM) {
244
- throw new Error('received non esm component script');
245
- }
246
- const url = URL.createObjectURL(new Blob([item.script.script], { type: 'application/javascript' }));
247
- const m = yield import(/* @vite-ignore */ url);
248
- if (typeof (m === null || m === void 0 ? void 0 : m.default) !== 'function') {
249
- throw new Error(`Invalid custom component module: ${typeof (m === null || m === void 0 ? void 0 : m.default)}`);
250
- }
251
- return [
252
- item.component.id,
253
- {
254
- component: item.component,
255
- Component: importCustomComponent(m, { componentId: item.component.id }),
256
- },
257
- ];
258
- }))));
259
- return Object.assign(Object.assign({}, result), { components, instances: Object.fromEntries(result.instances.map((_a) => {
260
- var { id } = _a, instance = __rest(_a, ["id"]);
261
- return [id, instance];
262
- })) });
263
- });
210
+ async function loadComponents(input) {
211
+ const result = await preloadComponents({ ...input, module: PreloadComponentScriptModule.ESM });
212
+ if (!result)
213
+ return null;
214
+ const components = Object.fromEntries(await Promise.all(Object.values(result.components).map(async (item) => {
215
+ if (item.script.module !== PreloadComponentScriptModule.ESM) {
216
+ throw new Error('received non esm component script');
217
+ }
218
+ const url = URL.createObjectURL(new Blob([item.script.script], { type: 'application/javascript' }));
219
+ const m = await import(/* @vite-ignore */ url);
220
+ if (typeof m?.default !== 'function') {
221
+ throw new Error(`Invalid custom component module: ${typeof m?.default}`);
222
+ }
223
+ return [
224
+ item.component.id,
225
+ {
226
+ component: item.component,
227
+ Component: importCustomComponent(m, { componentId: item.component.id }),
228
+ },
229
+ ];
230
+ })));
231
+ return {
232
+ ...result,
233
+ components,
234
+ instances: Object.fromEntries(result.instances.map(({ id, ...instance }) => [id, instance])),
235
+ };
264
236
  }
265
237
  export function useComponent({ instanceId, componentId, properties, locale, dev }) {
266
- var _a, _b, _c;
267
238
  const transpile = useTranspileComponent({ componentId, locale, properties, dev });
268
239
  const preload = usePreloadComponent({ instanceId, componentId, properties, locale, dev });
269
- const componentProperties = (_a = transpile === null || transpile === void 0 ? void 0 : transpile.componentProperties) !== null && _a !== void 0 ? _a : preload === null || preload === void 0 ? void 0 : preload.componentProperties;
240
+ const componentProperties = transpile?.componentProperties ?? preload?.componentProperties;
270
241
  return {
271
- Component: (_b = transpile === null || transpile === void 0 ? void 0 : transpile.Component) !== null && _b !== void 0 ? _b : preload === null || preload === void 0 ? void 0 : preload.Component,
272
- EditComponent: transpile === null || transpile === void 0 ? void 0 : transpile.EditComponent,
273
- props: Object.assign(Object.assign({}, ((_c = transpile === null || transpile === void 0 ? void 0 : transpile.props) !== null && _c !== void 0 ? _c : preload === null || preload === void 0 ? void 0 : preload.props)), Object.fromEntries(Object.entries(properties !== null && properties !== void 0 ? properties : {})
274
- .map(([key, { value }]) => {
275
- var _a;
276
- const property = (_a = componentProperties === null || componentProperties === void 0 ? void 0 : componentProperties[key]) === null || _a === void 0 ? void 0 : _a.data;
277
- if (!property)
278
- return undefined;
279
- const v = parsePropertyValue(property, value, { locale, defaultLocale: dev === null || dev === void 0 ? void 0 : dev.defaultLocale });
280
- // if key is undefined, use id
281
- return [property.key || property.id, v];
282
- })
283
- .filter((i) => !!i))),
284
- error: transpile === null || transpile === void 0 ? void 0 : transpile.error,
242
+ Component: transpile?.Component ?? preload?.Component,
243
+ EditComponent: transpile?.EditComponent,
244
+ props: {
245
+ ...(transpile?.props ?? preload?.props),
246
+ ...Object.fromEntries(Object.entries(properties ?? {})
247
+ .map(([key, { value }]) => {
248
+ const property = componentProperties?.[key]?.data;
249
+ if (!property)
250
+ return undefined;
251
+ const v = parsePropertyValue(property, value, { locale, defaultLocale: dev?.defaultLocale });
252
+ // if key is undefined, use id
253
+ return [property.key || property.id, v];
254
+ })
255
+ .filter((i) => !!i)),
256
+ },
257
+ error: transpile?.error,
285
258
  };
286
259
  }
287
260
  const COMPONENT_LOADER_MAP = {};
288
261
  function usePreloadComponent({ instanceId, componentId, properties, locale, dev }) {
289
- var _a, _b;
290
262
  const previousRef = useRef();
291
- const requestLocale = customComponentStates()((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
263
+ const requestLocale = customComponentStates()((s) => s.state.config.supportedLocales?.some((i) => i.locale === locale) ? locale : undefined);
292
264
  const defaultLocale = customComponentStates()((s) => s.state.config.defaultLocale);
293
265
  const realLocale = requestLocale || defaultLocale;
294
266
  const result = customComponentStates()((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
@@ -298,37 +270,38 @@ function usePreloadComponent({ instanceId, componentId, properties, locale, dev
298
270
  }
299
271
  if (instanceId) {
300
272
  const key = [instanceId, realLocale].join('-');
301
- (_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = customComponentStates()
273
+ COMPONENT_LOADER_MAP[key] ??= customComponentStates()
302
274
  .getState()
303
275
  .loadComponents({
304
- mode: dev === null || dev === void 0 ? void 0 : dev.mode,
305
- projectId: (_b = dev === null || dev === void 0 ? void 0 : dev.projectId) !== null && _b !== void 0 ? _b : window.__PROJECT_ID__,
276
+ mode: dev?.mode,
277
+ projectId: dev?.projectId ?? window.__PROJECT_ID__,
306
278
  locale: realLocale,
307
279
  instances: [{ id: instanceId, component: { id: componentId }, properties }],
308
- }));
280
+ });
309
281
  if (previousRef.current)
310
282
  return previousRef.current;
311
283
  }
312
284
  return null;
313
285
  }
314
286
  function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
315
- var _a, _b;
316
287
  const [{ error, Component, EditComponent, propertiesFromCode }, setComponent] = useState({});
317
288
  const component = mergeComponent({
318
289
  componentId,
319
290
  getComponent: (componentId) => {
320
- var _a, _b, _c, _d;
321
291
  // setting properties from code if it's not set from components props
322
- if (propertiesFromCode && isEmpty((_b = (_a = components === null || components === void 0 ? void 0 : components[componentId]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.properties)) {
323
- return Object.assign(Object.assign({}, (_c = components === null || components === void 0 ? void 0 : components[componentId]) === null || _c === void 0 ? void 0 : _c.data), { properties: propertiesFromCode });
292
+ if (propertiesFromCode && isEmpty(components?.[componentId]?.data?.properties)) {
293
+ return {
294
+ ...components?.[componentId]?.data,
295
+ properties: propertiesFromCode,
296
+ };
324
297
  }
325
- return (_d = components === null || components === void 0 ? void 0 : components[componentId]) === null || _d === void 0 ? void 0 : _d.data;
298
+ return components?.[componentId]?.data;
326
299
  },
327
300
  locale,
328
301
  defaultLocale,
329
302
  properties,
330
303
  });
331
- const script = useDeferredValue(component === null || component === void 0 ? void 0 : component.script);
304
+ const script = useDeferredValue(component?.script);
332
305
  useEffect(() => {
333
306
  if (script) {
334
307
  transpileAndLoadScript(script)
@@ -346,48 +319,45 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
346
319
  error,
347
320
  Component,
348
321
  EditComponent,
349
- props: component === null || component === void 0 ? void 0 : component.properties,
350
- componentProperties: (_b = (_a = components === null || components === void 0 ? void 0 : components[componentId]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.properties,
322
+ props: component?.properties,
323
+ componentProperties: components?.[componentId]?.data?.properties,
351
324
  };
352
325
  }
353
- export function transpileAndLoadScript(script) {
354
- return __awaiter(this, void 0, void 0, function* () {
355
- var _a, _b;
356
- // @ts-ignore
357
- if (import.meta.env.DEV && ((_a = window.__BLOCK_STUDIO__) === null || _a === void 0 ? void 0 : _a.getCodeImportPath)) {
358
- try {
359
- // @ts-ignore
360
- const filePath = joinURL((_b = window.__BLOCK_STUDIO__) === null || _b === void 0 ? void 0 : _b.getCodeImportPath(script));
361
- if (filePath) {
362
- // eslint-disable-next-line no-console
363
- console.info('get code import path from block studio:', filePath);
364
- const m = yield import(/* @vite-ignore */ filePath).catch(() => null);
365
- if (m) {
366
- return m;
367
- }
326
+ export async function transpileAndLoadScript(script) {
327
+ // @ts-ignore
328
+ if (import.meta.env.DEV && window.__BLOCK_STUDIO__?.getCodeImportPath) {
329
+ try {
330
+ // @ts-ignore
331
+ const filePath = joinURL(window.__BLOCK_STUDIO__?.getCodeImportPath(script));
332
+ if (filePath) {
333
+ // eslint-disable-next-line no-console
334
+ console.info('get code import path from block studio:', filePath);
335
+ const m = await import(/* @vite-ignore */ filePath).catch(() => null);
336
+ if (m) {
337
+ return m;
368
338
  }
369
339
  }
370
- catch (e) {
371
- // ignore error
372
- }
373
340
  }
374
- const [ts, { createBuiltinModuleTransformer }] = yield Promise.all([
375
- import('typescript').then((m) => m.default || m),
376
- import('../../utils/typescript/builtin-module-transformer'),
377
- ]);
378
- const compiled = ts.transpileModule(script, {
379
- compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
380
- transformers: {
381
- before: [createBuiltinModuleTransformer(ts)],
382
- },
383
- }).outputText;
384
- // fallback to the original handling
385
- const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
386
- try {
387
- return yield import(/* @vite-ignore */ url);
341
+ catch (e) {
342
+ // ignore error
388
343
  }
389
- finally {
390
- URL.revokeObjectURL(url);
391
- }
392
- });
344
+ }
345
+ const [ts, { createBuiltinModuleTransformer }] = await Promise.all([
346
+ import('typescript').then((m) => m.default || m),
347
+ import('../../utils/typescript/builtin-module-transformer'),
348
+ ]);
349
+ const compiled = ts.transpileModule(script, {
350
+ compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
351
+ transformers: {
352
+ before: [createBuiltinModuleTransformer(ts)],
353
+ },
354
+ }).outputText;
355
+ // fallback to the original handling
356
+ const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
357
+ try {
358
+ return await import(/* @vite-ignore */ url);
359
+ }
360
+ finally {
361
+ URL.revokeObjectURL(url);
362
+ }
393
363
  }
@@ -1,30 +1,17 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
1
  import { jsx as _jsx } from "react/jsx-runtime";
13
2
  import { useTheme } from '@arcblock/ux/lib/Theme';
14
3
  import { Box } from '@mui/material';
15
- export default function ResponsiveImage(_a) {
16
- var { src, sizesAttr, quality = 90, sx, alt } = _a, props = __rest(_a, ["src", "sizesAttr", "quality", "sx", "alt"]);
4
+ export default function ResponsiveImage({ src, sizesAttr, quality = 90, sx, alt, ...props }) {
17
5
  const theme = useTheme();
18
6
  const breakpoints = theme.breakpoints.values;
19
7
  // Generate srcset based on each breakpoint width
20
8
  const generateSrcSet = (baseUrl, breakpointWidths) => {
21
- var _a;
22
9
  // Check if URL already has query parameters
23
10
  if (baseUrl.includes('?')) {
24
11
  return '';
25
12
  }
26
13
  // Check file extension
27
- const fileExtension = (_a = baseUrl.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
14
+ const fileExtension = baseUrl.split('.').pop()?.toLowerCase();
28
15
  const supportedExtensions = ['png', 'jpg', 'jpeg', 'webp', 'gif'];
29
16
  if (!fileExtension || !supportedExtensions.includes(fileExtension)) {
30
17
  return '';
@@ -61,5 +48,5 @@ export default function ResponsiveImage(_a) {
61
48
  .filter((size) => size !== null)
62
49
  .join(', ');
63
50
  };
64
- return (_jsx(Box, Object.assign({ component: "img", src: src, srcSet: generateSrcSet(src, sizesAttr), sizes: generateSizes(sizesAttr), alt: alt !== null && alt !== void 0 ? alt : '', loading: "lazy", sx: sx }, props)));
51
+ return (_jsx(Box, { component: "img", src: src, srcSet: generateSrcSet(src, sizesAttr), sizes: generateSizes(sizesAttr), alt: alt ?? '', loading: "lazy", sx: sx, ...props }));
65
52
  }