@blocklet/pages-kit 0.4.117 → 0.4.119
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/state.js +34 -4
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/agent.js +5 -0
- package/lib/cjs/utils/builtin.js +1 -0
- package/lib/cjs/utils/data-source.js +70 -0
- package/lib/cjs/utils/inject-global-components.js +2 -0
- package/lib/cjs/utils/property.js +3 -1
- package/lib/cjs/utils/typescript/builtin-module-transformer.js +39 -17
- package/lib/esm/components/CustomComponentRenderer/state.js +34 -4
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/agent.js +2 -0
- package/lib/esm/utils/builtin.js +1 -0
- package/lib/esm/utils/data-source.js +67 -0
- package/lib/esm/utils/inject-global-components.js +2 -0
- package/lib/esm/utils/property.js +3 -1
- package/lib/esm/utils/typescript/builtin-module-transformer.js +36 -16
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/core.d.ts +1 -0
- package/lib/types/types/state.d.ts +36 -1
- package/lib/types/utils/agent.d.ts +5 -0
- package/lib/types/utils/builtin.d.ts +1 -0
- package/lib/types/utils/data-source.d.ts +8 -0
- package/lib/types/utils/property.d.ts +1 -0
- package/lib/types/utils/typescript/builtin-module-transformer.d.ts +2 -0
- package/package.json +1 -1
|
@@ -187,9 +187,20 @@ const customComponentStates = () => {
|
|
|
187
187
|
// handle the global variable
|
|
188
188
|
if (typeof m === 'function') {
|
|
189
189
|
try {
|
|
190
|
-
// call m() to get the component module
|
|
191
190
|
const modulePromiseOrObject = m();
|
|
192
|
-
|
|
191
|
+
// if the module is a promise, we need to wait for it to resolve
|
|
192
|
+
if (modulePromiseOrObject instanceof Promise) {
|
|
193
|
+
modulePromiseOrObject
|
|
194
|
+
.then((m) => {
|
|
195
|
+
Component = importCustomComponent(m, { componentId });
|
|
196
|
+
})
|
|
197
|
+
.catch((err) => {
|
|
198
|
+
console.error(`Failed to initialize component ${componentId}:`, err);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
Component = importCustomComponent(modulePromiseOrObject, { componentId });
|
|
203
|
+
}
|
|
193
204
|
}
|
|
194
205
|
catch (err) {
|
|
195
206
|
console.error(`Failed to initialize component ${componentId}:`, err);
|
|
@@ -197,6 +208,7 @@ const customComponentStates = () => {
|
|
|
197
208
|
}
|
|
198
209
|
else {
|
|
199
210
|
console.warn(`Component global variable ${preload.componentModuleGlobalVariable} is not a function`);
|
|
211
|
+
return null;
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
214
|
return [componentId, { ...preload, Component }];
|
|
@@ -359,19 +371,37 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
|
|
|
359
371
|
properties,
|
|
360
372
|
});
|
|
361
373
|
const script = (0, react_1.useDeferredValue)(component?.script);
|
|
374
|
+
const editComponent = (0, react_1.useDeferredValue)(component?.editComponent);
|
|
362
375
|
(0, react_1.useEffect)(() => {
|
|
363
376
|
if (script) {
|
|
377
|
+
// transpile view component
|
|
364
378
|
transpileAndLoadScript(script)
|
|
365
379
|
.then((m) => {
|
|
366
380
|
// get properties from code
|
|
367
381
|
const propertiesFromCode = getPropertiesFromCode(m);
|
|
368
|
-
|
|
382
|
+
const extraComponentInfo = m.EditComponent && !editComponent ? { EditComponent: m.EditComponent } : {};
|
|
383
|
+
setComponent((prev) => ({
|
|
384
|
+
...prev,
|
|
385
|
+
...extraComponentInfo,
|
|
386
|
+
Component: m.default,
|
|
387
|
+
propertiesFromCode,
|
|
388
|
+
}));
|
|
369
389
|
})
|
|
370
390
|
.catch((error) => {
|
|
371
391
|
setComponent({ error });
|
|
372
392
|
});
|
|
373
393
|
}
|
|
374
|
-
|
|
394
|
+
// transpile edit component
|
|
395
|
+
if (editComponent) {
|
|
396
|
+
transpileAndLoadScript(editComponent)
|
|
397
|
+
.then((m) => {
|
|
398
|
+
setComponent((prev) => ({ ...prev, EditComponent: m.default || m.EditComponent || undefined }));
|
|
399
|
+
})
|
|
400
|
+
.catch(() => {
|
|
401
|
+
// ignore error when transpile edit component
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}, [script, editComponent]);
|
|
375
405
|
return {
|
|
376
406
|
error,
|
|
377
407
|
Component,
|