@blocklet/pages-kit-runtime 0.1.19 → 0.1.21
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/client.js +51 -8
- package/lib/cjs/components/custom-component/settings.js +15 -4
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/client.js +52 -9
- package/lib/esm/components/custom-component/settings.js +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/client.d.ts +12 -2
- package/lib/types/components/custom-component/settings.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/lib/esm/client.js
CHANGED
|
@@ -13,11 +13,12 @@ import Result from '@arcblock/ux/lib/Result';
|
|
|
13
13
|
import Spinner from '@arcblock/ux/lib/Spinner';
|
|
14
14
|
import { createAxios } from '@blocklet/js-sdk';
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
import { PageRoutes } from '@blocklet/pages-kit-inner-components/home';
|
|
16
|
+
import { PageRoutes, PageViewByPath } from '@blocklet/pages-kit-inner-components/home';
|
|
17
17
|
import Box from '@mui/material/Box';
|
|
18
18
|
import { useRequest, useReactive } from 'ahooks';
|
|
19
19
|
import React, { useImperativeHandle, useEffect, useRef } from 'react';
|
|
20
20
|
import { joinURL } from 'ufo';
|
|
21
|
+
const PAGES_KIT_BLOCKLET_DID = 'z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o';
|
|
21
22
|
const CenteredContainer = ({ children }) => (_jsx(Box, { display: "flex", justifyContent: "center", alignItems: "center", minHeight: "100vh", children: children }));
|
|
22
23
|
const api = createAxios({
|
|
23
24
|
baseURL: joinURL(((_a = window === null || window === void 0 ? void 0 : window.blocklet) === null || _a === void 0 ? void 0 : _a.prefix) || ''),
|
|
@@ -25,12 +26,17 @@ const api = createAxios({
|
|
|
25
26
|
export const RuntimeComponent = (props) => {
|
|
26
27
|
const proxyState = useReactive({
|
|
27
28
|
rawState: props.state,
|
|
29
|
+
pageData: props.pageData,
|
|
28
30
|
});
|
|
29
31
|
const listeners = useRef(new Set());
|
|
30
32
|
// 暴露 proxyState 和 waitForState 给父组件
|
|
31
33
|
useImperativeHandle(props.stateRef, () => {
|
|
32
34
|
return {
|
|
33
35
|
getState: () => proxyState.rawState,
|
|
36
|
+
getPageData: () => proxyState.pageData,
|
|
37
|
+
setPageData: (data) => {
|
|
38
|
+
proxyState.pageData = data;
|
|
39
|
+
},
|
|
34
40
|
waitForState: () => {
|
|
35
41
|
if (proxyState.rawState) {
|
|
36
42
|
return Promise.resolve(proxyState.rawState);
|
|
@@ -55,25 +61,54 @@ export const RuntimeComponent = (props) => {
|
|
|
55
61
|
}
|
|
56
62
|
}, [proxyState.rawState]);
|
|
57
63
|
const { loading } = useRequest(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
|
|
64
|
+
var _a;
|
|
65
|
+
if (props.state) {
|
|
59
66
|
return null;
|
|
60
67
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
if (!props.did && !props.projectId) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let stateData;
|
|
72
|
+
if (props.did) {
|
|
73
|
+
// get state from resource blocklet by did
|
|
74
|
+
const { data } = yield api.get('/api/pages', {
|
|
75
|
+
params: {
|
|
76
|
+
did: props.did,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
proxyState.rawState = data.state;
|
|
80
|
+
stateData = data;
|
|
81
|
+
}
|
|
82
|
+
else if (props.projectId) {
|
|
83
|
+
let pagesKitBaseUrl = props.siteFrom;
|
|
84
|
+
if (!pagesKitBaseUrl) {
|
|
85
|
+
pagesKitBaseUrl = window.location.origin;
|
|
86
|
+
// find pages kit prefix from window.blocklet
|
|
87
|
+
const pagesKitMountPoint = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.did === PAGES_KIT_BLOCKLET_DID);
|
|
88
|
+
if (pagesKitMountPoint) {
|
|
89
|
+
pagesKitBaseUrl = joinURL(pagesKitBaseUrl, pagesKitMountPoint.mountPoint);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const apiUrl = joinURL(pagesKitBaseUrl, 'api/projects', props.projectId, 'pages');
|
|
93
|
+
// get state from project by projectId
|
|
94
|
+
const { data } = yield api.get(apiUrl);
|
|
95
|
+
proxyState.rawState = data;
|
|
96
|
+
stateData = data;
|
|
97
|
+
}
|
|
98
|
+
return stateData;
|
|
68
99
|
}), {
|
|
69
100
|
refreshDeps: [props.did, props.state],
|
|
70
101
|
});
|
|
102
|
+
useEffect(() => { }, [proxyState.pageData]);
|
|
71
103
|
if (loading) {
|
|
72
104
|
return (_jsx(CenteredContainer, { children: _jsx(Spinner, {}) }));
|
|
73
105
|
}
|
|
74
106
|
if (!proxyState.rawState) {
|
|
75
107
|
return (_jsx(CenteredContainer, { children: _jsx(Result, { status: 404 }) }));
|
|
76
108
|
}
|
|
109
|
+
if (props.path) {
|
|
110
|
+
return (_jsx(PageViewByPath, { mode: "production", state: proxyState.rawState, path: props.path, pageData: proxyState.pageData }));
|
|
111
|
+
}
|
|
77
112
|
return _jsx(PageRoutes, { mode: "production", state: proxyState.rawState });
|
|
78
113
|
};
|
|
79
114
|
export default class Runtime {
|
|
@@ -85,6 +120,14 @@ export default class Runtime {
|
|
|
85
120
|
var _a;
|
|
86
121
|
return (_a = this.stateRef.current) === null || _a === void 0 ? void 0 : _a.getState();
|
|
87
122
|
}
|
|
123
|
+
set pageData(data) {
|
|
124
|
+
var _a;
|
|
125
|
+
(_a = this.stateRef.current) === null || _a === void 0 ? void 0 : _a.setPageData(data);
|
|
126
|
+
}
|
|
127
|
+
get pageData() {
|
|
128
|
+
var _a;
|
|
129
|
+
return (_a = this.stateRef.current) === null || _a === void 0 ? void 0 : _a.getPageData();
|
|
130
|
+
}
|
|
88
131
|
waitForState() {
|
|
89
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
133
|
var _a;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
|
-
export
|
|
2
|
+
export * from '@blocklet/pages-kit-inner-components/setting';
|