@blocklet/pages-kit-runtime 0.1.7 → 0.1.9

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/esm/client.js CHANGED
@@ -1,19 +1,44 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var _a;
1
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+ import Result from '@arcblock/ux/lib/components/result';
13
+ import Spinner from '@arcblock/ux/lib/components/spinner';
14
+ import { createAxios } from '@blocklet/js-sdk';
2
15
  // @ts-ignore
3
- import Home from '@blocklet/pages-kit-inner-components/home';
4
- export const ProjectRuntimeView = () => {
5
- return _jsx(Home, {});
6
- };
7
- export class ProjectRuntime {
8
- constructor({ state, projectId }) {
9
- this.state = state;
10
- this.projectId = projectId;
16
+ import HomeComponent from '@blocklet/pages-kit-inner-components/home';
17
+ import Box from '@mui/material/Box';
18
+ import { useRequest } from 'ahooks';
19
+ import { joinURL } from 'ufo';
20
+ const CenteredContainer = ({ children }) => (_jsx(Box, { display: "flex", justifyContent: "center", alignItems: "center", minHeight: "100vh", children: children }));
21
+ const api = createAxios({
22
+ baseURL: joinURL(((_a = window === null || window === void 0 ? void 0 : window.blocklet) === null || _a === void 0 ? void 0 : _a.prefix) || ''),
23
+ });
24
+ export default (props) => {
25
+ const { loading } = useRequest(() => __awaiter(void 0, void 0, void 0, function* () {
26
+ const { data } = yield api.get('/api/pages', { params: props });
27
+ const dataResult = props.handleData ? props.handleData(data) : data;
28
+ // @ts-ignore
29
+ window.__PAGE_STATE__ = dataResult.state;
30
+ // @ts-ignore
31
+ window.__PROJECT_ID__ = dataResult.did;
32
+ return data;
33
+ }), {
34
+ refreshDeps: [props.did],
35
+ });
36
+ if (loading) {
37
+ return (_jsx(CenteredContainer, { children: _jsx(Spinner, {}) }));
11
38
  }
12
- render() {
13
- // eslint-disable-next-line no-console
14
- console.log('ProjectRuntime', this.state, this.projectId);
15
- return _jsx(ProjectRuntimeView, {});
39
+ // @ts-ignore
40
+ if (!window.__PAGE_STATE__) {
41
+ return (_jsx(CenteredContainer, { children: _jsx(Result, { status: "404", title: "404", subTitle: "Sorry, the page you visited does not exist." }) }));
16
42
  }
17
- }
18
- // export Home
19
- export { Home };
43
+ return _jsx(HomeComponent, {});
44
+ };