@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.
- package/lib/cjs/components/CustomComponentRenderer/state.js +2 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/builtin.js +2 -0
- package/lib/cjs/utils/inject-global-components.js +1 -0
- package/lib/cjs/utils/preload.js +11 -9
- package/lib/esm/components/CustomComponentRenderer/state.js +2 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/builtin.js +2 -0
- package/lib/esm/utils/inject-global-components.js +1 -0
- package/lib/esm/utils/preload.js +11 -9
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/core.d.ts +4 -0
- package/lib/types/utils/builtin.d.ts +2 -0
- package/package.json +9 -9
package/lib/esm/utils/builtin.js
CHANGED
|
@@ -3,6 +3,8 @@ import * as dayjs from '../builtin/dayjs';
|
|
|
3
3
|
import * as stream from '../builtin/stream';
|
|
4
4
|
import * as utils from '../builtin/utils';
|
|
5
5
|
export const BuiltinModules = {
|
|
6
|
+
React: {},
|
|
7
|
+
ReactDOM: {},
|
|
6
8
|
'@blocklet/pages-kit/builtin/pages-kit': {},
|
|
7
9
|
'@blocklet/pages-kit/builtin/react': {},
|
|
8
10
|
'@blocklet/pages-kit/builtin/react-dom': {},
|
|
@@ -50,6 +50,7 @@ export function injectGlobalComponents() {
|
|
|
50
50
|
// create module map
|
|
51
51
|
const modules = {
|
|
52
52
|
React: react,
|
|
53
|
+
ReactDOM: reactDOM,
|
|
53
54
|
'@blocklet/pages-kit/builtin/pages-kit': { CustomComponentRenderer },
|
|
54
55
|
'@blocklet/pages-kit/builtin/dayjs': dayjs,
|
|
55
56
|
'@blocklet/pages-kit/builtin/utils': utils,
|
package/lib/esm/utils/preload.js
CHANGED
|
@@ -17,31 +17,33 @@ export function safeJSONStringify(obj) {
|
|
|
17
17
|
return char;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
+
// return JSON.stringify(obj);
|
|
20
21
|
}
|
|
21
22
|
export function injectPreloadComponents(data) {
|
|
22
23
|
if (!data)
|
|
23
24
|
return null;
|
|
25
|
+
const injectScripts = [];
|
|
24
26
|
const injectState = {
|
|
25
27
|
config: data.config,
|
|
26
28
|
components: Object.fromEntries(Object.entries(data.components).map(([componentId, { script, component }]) => {
|
|
27
29
|
if (script.module !== PreloadComponentScriptModule.UMD_FN)
|
|
28
30
|
throw new Error(`Only support inject script with module ${PreloadComponentScriptModule.UMD_FN}`);
|
|
31
|
+
injectScripts.push(`<script>
|
|
32
|
+
${script.script}
|
|
33
|
+
</script>`);
|
|
34
|
+
// 在这里把 script 过滤掉了,不再有 umd 代码
|
|
29
35
|
return [componentId, { componentModuleGlobalVariable: script.moduleName, component }];
|
|
30
36
|
})),
|
|
31
37
|
instances: Object.fromEntries(data.instances.map(({ id, ...instance }) => [id, instance])),
|
|
32
38
|
};
|
|
33
39
|
return {
|
|
34
40
|
html: `\
|
|
35
|
-
${
|
|
36
|
-
|
|
41
|
+
${injectScripts.join('\n')}
|
|
42
|
+
|
|
37
43
|
<script>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.join('\n')}
|
|
42
|
-
|
|
43
|
-
<script>
|
|
44
|
-
var ${PreloadComponentsStateGlobalVariableName} = ${safeJSONStringify(injectState)}
|
|
44
|
+
|
|
45
|
+
window.${PreloadComponentsStateGlobalVariableName} = ${safeJSONStringify(injectState)}
|
|
46
|
+
|
|
45
47
|
</script>
|
|
46
48
|
`,
|
|
47
49
|
};
|