@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.
- package/lib/cjs/api/call.js +7 -18
- package/lib/cjs/api/pages-kit.js +5 -17
- package/lib/cjs/builtin/async/react-scroll-to-bottom.js +5 -1
- package/lib/cjs/builtin/components/LanguageField/index.js +6 -18
- package/lib/cjs/builtin/iconify/react.js +1 -1
- package/lib/cjs/builtin/page/header.js +8 -5
- package/lib/cjs/builtin/session.js +6 -0
- package/lib/cjs/builtin/stream.js +1 -1
- package/lib/cjs/builtin/utils.js +3 -5
- package/lib/cjs/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
- package/lib/cjs/components/CustomComponentRenderer/DevProvider.js +2 -14
- package/lib/cjs/components/CustomComponentRenderer/ErrorComponent.js +2 -14
- package/lib/cjs/components/CustomComponentRenderer/index.js +12 -27
- package/lib/cjs/components/CustomComponentRenderer/state.js +121 -151
- package/lib/cjs/components/ResponsiveImage/index.js +3 -16
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/inject-es-module-shims-options.js +1 -2
- package/lib/cjs/utils/inject-global-components-dump-json.js +1 -1
- package/lib/cjs/utils/inject-global-components.js +29 -20
- package/lib/cjs/utils/preload.js +1 -15
- package/lib/cjs/utils/property.js +31 -25
- package/lib/cjs/utils/typescript/builtin-module-transformer.js +12 -9
- package/lib/esm/api/call.js +7 -18
- package/lib/esm/api/pages-kit.js +5 -17
- package/lib/esm/builtin/async/react-scroll-to-bottom.js +5 -1
- package/lib/esm/builtin/components/LanguageField/index.js +6 -18
- package/lib/esm/builtin/iconify/react.js +1 -1
- package/lib/esm/builtin/page/header.js +8 -5
- package/lib/esm/builtin/session.js +5 -0
- package/lib/esm/builtin/stream.js +1 -1
- package/lib/esm/builtin/utils.js +3 -5
- package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +5 -19
- package/lib/esm/components/CustomComponentRenderer/DevProvider.js +2 -14
- package/lib/esm/components/CustomComponentRenderer/ErrorComponent.js +2 -14
- package/lib/esm/components/CustomComponentRenderer/index.js +12 -27
- package/lib/esm/components/CustomComponentRenderer/state.js +121 -151
- package/lib/esm/components/ResponsiveImage/index.js +3 -16
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/inject-es-module-shims-options.js +1 -2
- package/lib/esm/utils/inject-global-components-dump-json.js +1 -1
- package/lib/esm/utils/inject-global-components.js +29 -20
- package/lib/esm/utils/preload.js +1 -15
- package/lib/esm/utils/property.js +30 -25
- package/lib/esm/utils/typescript/builtin-module-transformer.js +10 -8
- package/lib/types/builtin/session.d.ts +13 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/core.d.ts +11 -2
- package/lib/types/utils/property.d.ts +1 -0
- package/lib/types/utils/typescript/builtin-module-transformer.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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 = () =>
|
|
61
|
+
const loadComponent = async () => {
|
|
82
62
|
try {
|
|
83
|
-
const result =
|
|
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,
|
|
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,
|
|
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
|
|
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
|
-
|
|
182
|
-
var _a, _b;
|
|
160
|
+
window?.blocklet?.languages?.forEach?.((item) => {
|
|
183
161
|
const { code: localKey } = item;
|
|
184
|
-
if (!
|
|
162
|
+
if (!data?.locales?.[localKey]) {
|
|
185
163
|
// fallback to en
|
|
186
|
-
(0, set_1.default)(data, `locales.${localKey}`,
|
|
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
|
|
176
|
+
states ??= (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
199
177
|
state: {
|
|
200
|
-
config:
|
|
201
|
-
components: Object.fromEntries(Object.entries(
|
|
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,
|
|
199
|
+
return [componentId, { ...preload, Component }];
|
|
222
200
|
})
|
|
223
201
|
.filter((i) => !!i)),
|
|
224
|
-
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 (!
|
|
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:
|
|
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 =
|
|
220
|
+
const props = instance.locales?.[locale]?.props;
|
|
244
221
|
if (!props)
|
|
245
222
|
return null;
|
|
246
|
-
return { component, Component, props, componentProperties:
|
|
223
|
+
return { component, Component, props, componentProperties: components[componentId]?.component.properties };
|
|
247
224
|
},
|
|
248
|
-
loadComponents(input) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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 =
|
|
273
|
+
const componentProperties = transpile?.componentProperties ?? preload?.componentProperties;
|
|
303
274
|
return {
|
|
304
|
-
Component:
|
|
305
|
-
EditComponent: transpile
|
|
306
|
-
props:
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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) =>
|
|
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
|
-
|
|
306
|
+
COMPONENT_LOADER_MAP[key] ??= (0, exports.customComponentStates)()
|
|
335
307
|
.getState()
|
|
336
308
|
.loadComponents({
|
|
337
|
-
mode: dev
|
|
338
|
-
projectId:
|
|
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)(
|
|
356
|
-
return
|
|
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
|
|
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
|
|
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
|
|
383
|
-
componentProperties:
|
|
355
|
+
props: component?.properties,
|
|
356
|
+
componentProperties: components?.[componentId]?.data?.properties,
|
|
384
357
|
};
|
|
385
358
|
}
|
|
386
|
-
function transpileAndLoadScript(script) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
408
|
-
|
|
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
|
-
|
|
423
|
-
|
|
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(
|
|
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 =
|
|
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,
|
|
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
|
}
|