@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.
@@ -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
- Component = importCustomComponent(modulePromiseOrObject, { componentId });
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
- setComponent({ Component: m.default, EditComponent: m.EditComponent || undefined, propertiesFromCode });
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
- }, [script]);
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,