@blocklet/pages-kit 0.4.31 → 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 +3 -3
@@ -22,26 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __rest = (this && this.__rest) || function (s, e) {
35
- var t = {};
36
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
- t[p] = s[p];
38
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
- t[p[i]] = s[p[i]];
42
- }
43
- return t;
44
- };
45
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
47
27
  };
@@ -78,9 +58,9 @@ function importCustomComponent(m, { componentId }) {
78
58
  // 只在组件首次加载时执行,避免重复加载
79
59
  (0, react_1.useEffect)(() => {
80
60
  let isMounted = true;
81
- const loadComponent = () => __awaiter(this, void 0, void 0, function* () {
61
+ const loadComponent = async () => {
82
62
  try {
83
- const result = yield m;
63
+ const result = await m;
84
64
  if (!isMounted)
85
65
  return;
86
66
  if (!result) {
@@ -108,7 +88,7 @@ function importCustomComponent(m, { componentId }) {
108
88
  setLoading(false);
109
89
  }
110
90
  }
111
- });
91
+ };
112
92
  loadComponent();
113
93
  return () => {
114
94
  isMounted = false;
@@ -124,7 +104,7 @@ function importCustomComponent(m, { componentId }) {
124
104
  }
125
105
  // 动态渲染组件,但允许props更新传递
126
106
  if (ResolvedComponent) {
127
- return (0, jsx_runtime_1.jsx)(ResolvedComponent, Object.assign({}, props));
107
+ return (0, jsx_runtime_1.jsx)(ResolvedComponent, { ...props });
128
108
  }
129
109
  return null;
130
110
  }, [loading, error, ResolvedComponent, props]);
@@ -163,7 +143,7 @@ function importCustomComponent(m, { componentId }) {
163
143
  // if a component is found and has CSS, wrap the component with styles
164
144
  if (Component && css) {
165
145
  const OriginalComponent = Component;
166
- Component = (props) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_helmet_1.Helmet, { children: (0, jsx_runtime_1.jsx)("style", { children: css }) }), (0, jsx_runtime_1.jsx)(OriginalComponent, Object.assign({}, props, { className: (0, css_1.cx)(props.className, `CustomComponent_${componentId}`) }))] }));
146
+ Component = (props) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_helmet_1.Helmet, { children: (0, jsx_runtime_1.jsx)("style", { children: css }) }), (0, jsx_runtime_1.jsx)(OriginalComponent, { ...props, className: (0, css_1.cx)(props.className, `CustomComponent_${componentId}`) })] }));
167
147
  }
168
148
  // keep aigneOutputValueSchema
169
149
  if (Component && m.aigneOutputValueSchema) {
@@ -173,17 +153,15 @@ function importCustomComponent(m, { componentId }) {
173
153
  }
174
154
  function getPropertiesFromCode(m) {
175
155
  let propertiesFromCode = null;
176
- if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
156
+ if (typeof m?.PROPERTIES_SCHEMA === 'object' && m?.PROPERTIES_SCHEMA.length) {
177
157
  propertiesFromCode = {};
178
158
  m.PROPERTIES_SCHEMA.forEach((data, index) => {
179
- var _a, _b, _c;
180
159
  // @ts-ignore
181
- (_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) => {
182
- var _a, _b;
160
+ window?.blocklet?.languages?.forEach?.((item) => {
183
161
  const { code: localKey } = item;
184
- if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
162
+ if (!data?.locales?.[localKey]) {
185
163
  // fallback to en
186
- (0, set_1.default)(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
164
+ (0, set_1.default)(data, `locales.${localKey}`, data.locales?.en);
187
165
  }
188
166
  });
189
167
  propertiesFromCode[data.id] = {
@@ -195,10 +173,10 @@ function getPropertiesFromCode(m) {
195
173
  return propertiesFromCode;
196
174
  }
197
175
  const customComponentStates = () => {
198
- states !== null && states !== void 0 ? states : (states = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
176
+ states ??= (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
199
177
  state: {
200
- config: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config),
201
- components: Object.fromEntries(Object.entries(Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components))
178
+ config: { ...PRELOAD_COMPONENTS_STATE?.config },
179
+ components: Object.fromEntries(Object.entries({ ...PRELOAD_COMPONENTS_STATE?.components })
202
180
  .map(([componentId, preload]) => {
203
181
  let Component;
204
182
  if (preload.componentModuleGlobalVariable) {
@@ -218,15 +196,14 @@ const customComponentStates = () => {
218
196
  console.warn(`Component global variable ${preload.componentModuleGlobalVariable} is not a function`);
219
197
  }
220
198
  }
221
- return [componentId, Object.assign(Object.assign({}, preload), { Component })];
199
+ return [componentId, { ...preload, Component }];
222
200
  })
223
201
  .filter((i) => !!i)),
224
- instances: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.instances),
202
+ instances: { ...PRELOAD_COMPONENTS_STATE?.instances },
225
203
  },
226
204
  getComponent({ instanceId, componentId, locale }) {
227
- var _a, _b, _c, _d;
228
205
  const { config: { supportedLocales }, components, instances, } = get().state;
229
- if (!(supportedLocales === null || supportedLocales === void 0 ? void 0 : supportedLocales.some((i) => i.locale === locale)))
206
+ if (!supportedLocales?.some((i) => i.locale === locale))
230
207
  return null;
231
208
  const c = components[componentId];
232
209
  if (!c)
@@ -235,93 +212,88 @@ const customComponentStates = () => {
235
212
  if (!Component)
236
213
  return null;
237
214
  if (!instanceId) {
238
- return { component, Component, componentProperties: (_a = components[componentId]) === null || _a === void 0 ? void 0 : _a.component.properties };
215
+ return { component, Component, componentProperties: components[componentId]?.component.properties };
239
216
  }
240
217
  const instance = instances[instanceId];
241
218
  if (!instance)
242
219
  return null;
243
- const props = (_c = (_b = instance.locales) === null || _b === void 0 ? void 0 : _b[locale]) === null || _c === void 0 ? void 0 : _c.props;
220
+ const props = instance.locales?.[locale]?.props;
244
221
  if (!props)
245
222
  return null;
246
- return { component, Component, props, componentProperties: (_d = components[componentId]) === null || _d === void 0 ? void 0 : _d.component.properties };
223
+ return { component, Component, props, componentProperties: components[componentId]?.component.properties };
247
224
  },
248
- loadComponents(input) {
249
- return __awaiter(this, void 0, void 0, function* () {
250
- const result = yield loadComponents(input);
251
- if (result) {
252
- set((s) => {
253
- s.state.config = result.config;
254
- Object.assign(s.state.components, result.components);
255
- Object.entries(result.instances).forEach(([instanceId, instance]) => {
256
- var _a, _b;
257
- var _c, _d;
258
- (_a = (_c = s.state.instances)[instanceId]) !== null && _a !== void 0 ? _a : (_c[instanceId] = { componentId: instance.componentId });
259
- (_b = (_d = s.state.instances[instanceId]).locales) !== null && _b !== void 0 ? _b : (_d.locales = {});
260
- Object.assign(s.state.instances[instanceId].locales, instance.locales);
261
- });
225
+ async loadComponents(input) {
226
+ const result = await loadComponents(input);
227
+ if (result) {
228
+ set((s) => {
229
+ s.state.config = result.config;
230
+ Object.assign(s.state.components, result.components);
231
+ Object.entries(result.instances).forEach(([instanceId, instance]) => {
232
+ s.state.instances[instanceId] ??= { componentId: instance.componentId };
233
+ s.state.instances[instanceId].locales ??= {};
234
+ Object.assign(s.state.instances[instanceId].locales, instance.locales);
262
235
  });
263
- }
264
- });
236
+ });
237
+ }
265
238
  },
266
- }))));
239
+ })));
267
240
  return states;
268
241
  };
269
242
  exports.customComponentStates = customComponentStates;
270
- function loadComponents(input) {
271
- return __awaiter(this, void 0, void 0, function* () {
272
- const result = yield (0, api_1.preloadComponents)(Object.assign(Object.assign({}, input), { module: types_1.PreloadComponentScriptModule.ESM }));
273
- if (!result)
274
- return null;
275
- const components = Object.fromEntries(yield Promise.all(Object.values(result.components).map((item) => __awaiter(this, void 0, void 0, function* () {
276
- if (item.script.module !== types_1.PreloadComponentScriptModule.ESM) {
277
- throw new Error('received non esm component script');
278
- }
279
- const url = URL.createObjectURL(new Blob([item.script.script], { type: 'application/javascript' }));
280
- const m = yield Promise.resolve(`${url}`).then(s => __importStar(require(s)));
281
- if (typeof (m === null || m === void 0 ? void 0 : m.default) !== 'function') {
282
- throw new Error(`Invalid custom component module: ${typeof (m === null || m === void 0 ? void 0 : m.default)}`);
283
- }
284
- return [
285
- item.component.id,
286
- {
287
- component: item.component,
288
- Component: importCustomComponent(m, { componentId: item.component.id }),
289
- },
290
- ];
291
- }))));
292
- return Object.assign(Object.assign({}, result), { components, instances: Object.fromEntries(result.instances.map((_a) => {
293
- var { id } = _a, instance = __rest(_a, ["id"]);
294
- return [id, instance];
295
- })) });
296
- });
243
+ async function loadComponents(input) {
244
+ const result = await (0, api_1.preloadComponents)({ ...input, module: types_1.PreloadComponentScriptModule.ESM });
245
+ if (!result)
246
+ return null;
247
+ const components = Object.fromEntries(await Promise.all(Object.values(result.components).map(async (item) => {
248
+ if (item.script.module !== types_1.PreloadComponentScriptModule.ESM) {
249
+ throw new Error('received non esm component script');
250
+ }
251
+ const url = URL.createObjectURL(new Blob([item.script.script], { type: 'application/javascript' }));
252
+ const m = await Promise.resolve(`${url}`).then(s => __importStar(require(s)));
253
+ if (typeof m?.default !== 'function') {
254
+ throw new Error(`Invalid custom component module: ${typeof m?.default}`);
255
+ }
256
+ return [
257
+ item.component.id,
258
+ {
259
+ component: item.component,
260
+ Component: importCustomComponent(m, { componentId: item.component.id }),
261
+ },
262
+ ];
263
+ })));
264
+ return {
265
+ ...result,
266
+ components,
267
+ instances: Object.fromEntries(result.instances.map(({ id, ...instance }) => [id, instance])),
268
+ };
297
269
  }
298
270
  function useComponent({ instanceId, componentId, properties, locale, dev }) {
299
- var _a, _b, _c;
300
271
  const transpile = useTranspileComponent({ componentId, locale, properties, dev });
301
272
  const preload = usePreloadComponent({ instanceId, componentId, properties, locale, dev });
302
- 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;
273
+ const componentProperties = transpile?.componentProperties ?? preload?.componentProperties;
303
274
  return {
304
- 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,
305
- EditComponent: transpile === null || transpile === void 0 ? void 0 : transpile.EditComponent,
306
- 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 : {})
307
- .map(([key, { value }]) => {
308
- var _a;
309
- const property = (_a = componentProperties === null || componentProperties === void 0 ? void 0 : componentProperties[key]) === null || _a === void 0 ? void 0 : _a.data;
310
- if (!property)
311
- return undefined;
312
- const v = (0, property_1.parsePropertyValue)(property, value, { locale, defaultLocale: dev === null || dev === void 0 ? void 0 : dev.defaultLocale });
313
- // if key is undefined, use id
314
- return [property.key || property.id, v];
315
- })
316
- .filter((i) => !!i))),
317
- error: transpile === null || transpile === void 0 ? void 0 : transpile.error,
275
+ Component: transpile?.Component ?? preload?.Component,
276
+ EditComponent: transpile?.EditComponent,
277
+ props: {
278
+ ...(transpile?.props ?? preload?.props),
279
+ ...Object.fromEntries(Object.entries(properties ?? {})
280
+ .map(([key, { value }]) => {
281
+ const property = componentProperties?.[key]?.data;
282
+ if (!property)
283
+ return undefined;
284
+ const v = (0, property_1.parsePropertyValue)(property, value, { locale, defaultLocale: dev?.defaultLocale });
285
+ // if key is undefined, use id
286
+ return [property.key || property.id, v];
287
+ })
288
+ .filter((i) => !!i)),
289
+ },
290
+ error: transpile?.error,
318
291
  };
319
292
  }
320
293
  const COMPONENT_LOADER_MAP = {};
321
294
  function usePreloadComponent({ instanceId, componentId, properties, locale, dev }) {
322
- var _a, _b;
323
295
  const previousRef = (0, react_1.useRef)();
324
- const requestLocale = (0, exports.customComponentStates)()((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
296
+ const requestLocale = (0, exports.customComponentStates)()((s) => s.state.config.supportedLocales?.some((i) => i.locale === locale) ? locale : undefined);
325
297
  const defaultLocale = (0, exports.customComponentStates)()((s) => s.state.config.defaultLocale);
326
298
  const realLocale = requestLocale || defaultLocale;
327
299
  const result = (0, exports.customComponentStates)()((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
@@ -331,37 +303,38 @@ function usePreloadComponent({ instanceId, componentId, properties, locale, dev
331
303
  }
332
304
  if (instanceId) {
333
305
  const key = [instanceId, realLocale].join('-');
334
- (_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = (0, exports.customComponentStates)()
306
+ COMPONENT_LOADER_MAP[key] ??= (0, exports.customComponentStates)()
335
307
  .getState()
336
308
  .loadComponents({
337
- mode: dev === null || dev === void 0 ? void 0 : dev.mode,
338
- projectId: (_b = dev === null || dev === void 0 ? void 0 : dev.projectId) !== null && _b !== void 0 ? _b : window.__PROJECT_ID__,
309
+ mode: dev?.mode,
310
+ projectId: dev?.projectId ?? window.__PROJECT_ID__,
339
311
  locale: realLocale,
340
312
  instances: [{ id: instanceId, component: { id: componentId }, properties }],
341
- }));
313
+ });
342
314
  if (previousRef.current)
343
315
  return previousRef.current;
344
316
  }
345
317
  return null;
346
318
  }
347
319
  function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
348
- var _a, _b;
349
320
  const [{ error, Component, EditComponent, propertiesFromCode }, setComponent] = (0, react_1.useState)({});
350
321
  const component = (0, property_1.mergeComponent)({
351
322
  componentId,
352
323
  getComponent: (componentId) => {
353
- var _a, _b, _c, _d;
354
324
  // setting properties from code if it's not set from components props
355
- if (propertiesFromCode && (0, lodash_1.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)) {
356
- 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 });
325
+ if (propertiesFromCode && (0, lodash_1.isEmpty)(components?.[componentId]?.data?.properties)) {
326
+ return {
327
+ ...components?.[componentId]?.data,
328
+ properties: propertiesFromCode,
329
+ };
357
330
  }
358
- return (_d = components === null || components === void 0 ? void 0 : components[componentId]) === null || _d === void 0 ? void 0 : _d.data;
331
+ return components?.[componentId]?.data;
359
332
  },
360
333
  locale,
361
334
  defaultLocale,
362
335
  properties,
363
336
  });
364
- const script = (0, react_1.useDeferredValue)(component === null || component === void 0 ? void 0 : component.script);
337
+ const script = (0, react_1.useDeferredValue)(component?.script);
365
338
  (0, react_1.useEffect)(() => {
366
339
  if (script) {
367
340
  transpileAndLoadScript(script)
@@ -379,48 +352,45 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
379
352
  error,
380
353
  Component,
381
354
  EditComponent,
382
- props: component === null || component === void 0 ? void 0 : component.properties,
383
- 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,
355
+ props: component?.properties,
356
+ componentProperties: components?.[componentId]?.data?.properties,
384
357
  };
385
358
  }
386
- function transpileAndLoadScript(script) {
387
- return __awaiter(this, void 0, void 0, function* () {
388
- var _a, _b;
389
- // @ts-ignore
390
- if (import.meta.env.DEV && ((_a = window.__BLOCK_STUDIO__) === null || _a === void 0 ? void 0 : _a.getCodeImportPath)) {
391
- try {
392
- // @ts-ignore
393
- const filePath = (0, ufo_1.joinURL)((_b = window.__BLOCK_STUDIO__) === null || _b === void 0 ? void 0 : _b.getCodeImportPath(script));
394
- if (filePath) {
395
- // eslint-disable-next-line no-console
396
- console.info('get code import path from block studio:', filePath);
397
- const m = yield Promise.resolve(`${filePath}`).then(s => __importStar(require(s))).catch(() => null);
398
- if (m) {
399
- return m;
400
- }
359
+ async function transpileAndLoadScript(script) {
360
+ // @ts-ignore
361
+ if (import.meta.env.DEV && window.__BLOCK_STUDIO__?.getCodeImportPath) {
362
+ try {
363
+ // @ts-ignore
364
+ const filePath = (0, ufo_1.joinURL)(window.__BLOCK_STUDIO__?.getCodeImportPath(script));
365
+ if (filePath) {
366
+ // eslint-disable-next-line no-console
367
+ console.info('get code import path from block studio:', filePath);
368
+ const m = await Promise.resolve(`${filePath}`).then(s => __importStar(require(s))).catch(() => null);
369
+ if (m) {
370
+ return m;
401
371
  }
402
372
  }
403
- catch (e) {
404
- // ignore error
405
- }
406
373
  }
407
- const [ts, { createBuiltinModuleTransformer }] = yield Promise.all([
408
- Promise.resolve().then(() => __importStar(require('typescript'))).then((m) => m.default || m),
409
- Promise.resolve().then(() => __importStar(require('../../utils/typescript/builtin-module-transformer'))),
410
- ]);
411
- const compiled = ts.transpileModule(script, {
412
- compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
413
- transformers: {
414
- before: [createBuiltinModuleTransformer(ts)],
415
- },
416
- }).outputText;
417
- // fallback to the original handling
418
- const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
419
- try {
420
- return yield Promise.resolve(`${url}`).then(s => __importStar(require(s)));
374
+ catch (e) {
375
+ // ignore error
421
376
  }
422
- finally {
423
- URL.revokeObjectURL(url);
424
- }
425
- });
377
+ }
378
+ const [ts, { createBuiltinModuleTransformer }] = await Promise.all([
379
+ Promise.resolve().then(() => __importStar(require('typescript'))).then((m) => m.default || m),
380
+ Promise.resolve().then(() => __importStar(require('../../utils/typescript/builtin-module-transformer'))),
381
+ ]);
382
+ const compiled = ts.transpileModule(script, {
383
+ compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
384
+ transformers: {
385
+ before: [createBuiltinModuleTransformer(ts)],
386
+ },
387
+ }).outputText;
388
+ // fallback to the original handling
389
+ const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
390
+ try {
391
+ return await Promise.resolve(`${url}`).then(s => __importStar(require(s)));
392
+ }
393
+ finally {
394
+ URL.revokeObjectURL(url);
395
+ }
426
396
  }
@@ -1,33 +1,20 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.default = ResponsiveImage;
15
4
  const jsx_runtime_1 = require("react/jsx-runtime");
16
5
  const Theme_1 = require("@arcblock/ux/lib/Theme");
17
6
  const material_1 = require("@mui/material");
18
- function ResponsiveImage(_a) {
19
- var { src, sizesAttr, quality = 90, sx, alt } = _a, props = __rest(_a, ["src", "sizesAttr", "quality", "sx", "alt"]);
7
+ function ResponsiveImage({ src, sizesAttr, quality = 90, sx, alt, ...props }) {
20
8
  const theme = (0, Theme_1.useTheme)();
21
9
  const breakpoints = theme.breakpoints.values;
22
10
  // Generate srcset based on each breakpoint width
23
11
  const generateSrcSet = (baseUrl, breakpointWidths) => {
24
- var _a;
25
12
  // Check if URL already has query parameters
26
13
  if (baseUrl.includes('?')) {
27
14
  return '';
28
15
  }
29
16
  // Check file extension
30
- const fileExtension = (_a = baseUrl.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
17
+ const fileExtension = baseUrl.split('.').pop()?.toLowerCase();
31
18
  const supportedExtensions = ['png', 'jpg', 'jpeg', 'webp', 'gif'];
32
19
  if (!fileExtension || !supportedExtensions.includes(fileExtension)) {
33
20
  return '';
@@ -64,5 +51,5 @@ function ResponsiveImage(_a) {
64
51
  .filter((size) => size !== null)
65
52
  .join(', ');
66
53
  };
67
- return ((0, jsx_runtime_1.jsx)(material_1.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)));
54
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: src, srcSet: generateSrcSet(src, sizesAttr), sizes: generateSizes(sizesAttr), alt: alt ?? '', loading: "lazy", sx: sx, ...props }));
68
55
  }