@blocklet/pages-kit 0.6.1 → 0.6.2

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.
@@ -29,6 +29,8 @@ const dayjs = __importStar(require("../builtin/dayjs"));
29
29
  const stream = __importStar(require("../builtin/stream"));
30
30
  const utils = __importStar(require("../builtin/utils"));
31
31
  exports.BuiltinModules = {
32
+ React: {},
33
+ ReactDOM: {},
32
34
  '@blocklet/pages-kit/builtin/pages-kit': {},
33
35
  '@blocklet/pages-kit/builtin/react': {},
34
36
  '@blocklet/pages-kit/builtin/react-dom': {},
@@ -79,6 +79,7 @@ function injectGlobalComponents() {
79
79
  // create module map
80
80
  const modules = {
81
81
  React: react,
82
+ ReactDOM: reactDOM,
82
83
  '@blocklet/pages-kit/builtin/pages-kit': { CustomComponentRenderer: CustomComponentRenderer_1.default },
83
84
  '@blocklet/pages-kit/builtin/dayjs': dayjs,
84
85
  '@blocklet/pages-kit/builtin/utils': utils,
@@ -21,31 +21,33 @@ function safeJSONStringify(obj) {
21
21
  return char;
22
22
  }
23
23
  });
24
+ // return JSON.stringify(obj);
24
25
  }
25
26
  function injectPreloadComponents(data) {
26
27
  if (!data)
27
28
  return null;
29
+ const injectScripts = [];
28
30
  const injectState = {
29
31
  config: data.config,
30
32
  components: Object.fromEntries(Object.entries(data.components).map(([componentId, { script, component }]) => {
31
33
  if (script.module !== types_1.PreloadComponentScriptModule.UMD_FN)
32
34
  throw new Error(`Only support inject script with module ${types_1.PreloadComponentScriptModule.UMD_FN}`);
35
+ injectScripts.push(`<script>
36
+ ${script.script}
37
+ </script>`);
38
+ // 在这里把 script 过滤掉了,不再有 umd 代码
33
39
  return [componentId, { componentModuleGlobalVariable: script.moduleName, component }];
34
40
  })),
35
41
  instances: Object.fromEntries(data.instances.map(({ id, ...instance }) => [id, instance])),
36
42
  };
37
43
  return {
38
44
  html: `\
39
- ${Object.values(data.components)
40
- .map(({ script: { script } }) => `\
45
+ ${injectScripts.join('\n')}
46
+
41
47
  <script>
42
- ${script}
43
- </script>
44
- `)
45
- .join('\n')}
46
-
47
- <script>
48
- var ${types_1.PreloadComponentsStateGlobalVariableName} = ${safeJSONStringify(injectState)}
48
+
49
+ window.${types_1.PreloadComponentsStateGlobalVariableName} = ${safeJSONStringify(injectState)}
50
+
49
51
  </script>
50
52
  `,
51
53
  };
@@ -358,7 +358,8 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
358
358
  .then((m) => {
359
359
  setComponent((prev) => ({ ...prev, EditComponent: m.default || m.EditComponent || undefined }));
360
360
  })
361
- .catch(() => {
361
+ .catch((e) => {
362
+ console.warn('transpile edit component error', e);
362
363
  // ignore error when transpile edit component
363
364
  });
364
365
  }