@blocklet/pages-kit-runtime 0.4.32 → 0.4.34
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 +38 -61
- package/lib/cjs/components/create-resource.js +2 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/client.js +38 -61
- package/lib/esm/components/create-resource.js +2 -2
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/lib/esm/client.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
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;
|
|
11
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
2
|
import Result from '@arcblock/ux/lib/Result';
|
|
13
3
|
import Spinner from '@arcblock/ux/lib/Spinner';
|
|
@@ -20,19 +10,18 @@ import React, { useImperativeHandle, useEffect, useRef } from 'react';
|
|
|
20
10
|
import { joinURL } from 'ufo';
|
|
21
11
|
const CenteredContainer = ({ children }) => (_jsx(Box, { display: "flex", justifyContent: "center", alignItems: "center", minHeight: "100vh", children: children }));
|
|
22
12
|
const api = createAxios({
|
|
23
|
-
baseURL: joinURL(
|
|
13
|
+
baseURL: joinURL(window?.blocklet?.prefix || ''),
|
|
24
14
|
});
|
|
25
15
|
// convert page data to page init data, use for AIGNE
|
|
26
16
|
function convertPageData(state, page, locale) {
|
|
27
|
-
var _a, _b, _c;
|
|
28
17
|
// 如果页面不存在,返回 null
|
|
29
18
|
if (!page) {
|
|
30
19
|
return null;
|
|
31
20
|
}
|
|
32
21
|
// 获取默认语言
|
|
33
|
-
const defaultLocale =
|
|
22
|
+
const defaultLocale = state.config?.defaultLocale;
|
|
34
23
|
// 获取页面在指定语言下的数据,如果不存在则使用默认语言的数据
|
|
35
|
-
const pageLocaleData =
|
|
24
|
+
const pageLocaleData = page.locales?.[locale] || page.locales?.[defaultLocale] || {};
|
|
36
25
|
// 初始化基础页面数据
|
|
37
26
|
const result = {
|
|
38
27
|
title: pageLocaleData.title,
|
|
@@ -42,26 +31,24 @@ function convertPageData(state, page, locale) {
|
|
|
42
31
|
};
|
|
43
32
|
// 处理每个 section 的数据
|
|
44
33
|
page.sectionIds.forEach((sectionId) => {
|
|
45
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
46
34
|
const section = page.sections[sectionId];
|
|
47
35
|
if (!section)
|
|
48
36
|
return;
|
|
49
37
|
// 获取 section 在指定语言下的配置,如果不存在则使用默认语言的配置
|
|
50
38
|
const sectionConfig = section.config || {};
|
|
51
|
-
const sectionData =
|
|
39
|
+
const sectionData = section.locales?.[locale] || section.locales?.[defaultLocale];
|
|
52
40
|
const sectionName = section.name || section.id;
|
|
53
41
|
if (section.component === 'custom-component') {
|
|
54
42
|
// 处理自定义组件
|
|
55
|
-
const componentId =
|
|
56
|
-
const component =
|
|
43
|
+
const componentId = sectionConfig?.componentId || section.config?.componentId;
|
|
44
|
+
const component = state.components[componentId]?.data || state.resources?.components?.[componentId]?.component;
|
|
57
45
|
if (component) {
|
|
58
46
|
result.sectionsData[sectionName] = {};
|
|
59
47
|
// 遍历组件的属性定义
|
|
60
48
|
Object.entries(component.properties || {}).forEach(([, prop]) => {
|
|
61
|
-
|
|
62
|
-
const key = ((_a = prop.data) === null || _a === void 0 ? void 0 : _a.key) || ((_b = prop.data) === null || _b === void 0 ? void 0 : _b.id);
|
|
49
|
+
const key = prop.data?.key || prop.data?.id;
|
|
63
50
|
if (key) {
|
|
64
|
-
result.sectionsData[sectionName][key] =
|
|
51
|
+
result.sectionsData[sectionName][key] = sectionData?.properties?.[prop.data?.id]?.value;
|
|
65
52
|
}
|
|
66
53
|
});
|
|
67
54
|
}
|
|
@@ -69,33 +56,33 @@ function convertPageData(state, page, locale) {
|
|
|
69
56
|
else if (section.component === 'iframe') {
|
|
70
57
|
// 处理 iframe 组件
|
|
71
58
|
result.sectionsData[sectionName] = {
|
|
72
|
-
src: sectionData
|
|
73
|
-
title: sectionData
|
|
74
|
-
description: sectionData
|
|
59
|
+
src: sectionData?.src,
|
|
60
|
+
title: sectionData?.title,
|
|
61
|
+
description: sectionData?.description,
|
|
75
62
|
};
|
|
76
63
|
}
|
|
77
64
|
else if (section.component === 'section') {
|
|
78
65
|
// 处理普通 section 组件
|
|
79
66
|
result.sectionsData[sectionName] = {
|
|
80
|
-
title: sectionData
|
|
81
|
-
description: sectionData
|
|
82
|
-
image: sectionData
|
|
83
|
-
imageMeta: sectionData
|
|
67
|
+
title: sectionData?.title,
|
|
68
|
+
description: sectionData?.description,
|
|
69
|
+
image: sectionData?.image,
|
|
70
|
+
imageMeta: sectionData?.imageMeta,
|
|
84
71
|
};
|
|
85
72
|
}
|
|
86
73
|
else if (section.component === 'section-card-list') {
|
|
87
74
|
// 处理卡片列表组件
|
|
88
75
|
result.sectionsData[sectionName] = {
|
|
89
|
-
title: sectionData
|
|
90
|
-
description: sectionData
|
|
91
|
-
list:
|
|
76
|
+
title: sectionData?.title,
|
|
77
|
+
description: sectionData?.description,
|
|
78
|
+
list: sectionData?.list || [],
|
|
92
79
|
};
|
|
93
80
|
}
|
|
94
81
|
else if (section.component === 'toc') {
|
|
95
82
|
// 处理目录组件
|
|
96
83
|
result.sectionsData[sectionName] = {
|
|
97
|
-
title: sectionData
|
|
98
|
-
description: sectionData
|
|
84
|
+
title: sectionData?.title,
|
|
85
|
+
description: sectionData?.description,
|
|
99
86
|
};
|
|
100
87
|
}
|
|
101
88
|
else {
|
|
@@ -139,17 +126,16 @@ export const RuntimeComponent = (props) => {
|
|
|
139
126
|
resolve(null);
|
|
140
127
|
return;
|
|
141
128
|
}
|
|
142
|
-
const getPageInitData = () =>
|
|
143
|
-
var _a;
|
|
129
|
+
const getPageInitData = async () => {
|
|
144
130
|
let pageInitData = {};
|
|
145
131
|
if (proxyState.rawState.pages) {
|
|
146
|
-
const page = Object.values(proxyState.rawState.pages).find((page) =>
|
|
132
|
+
const page = Object.values(proxyState.rawState.pages).find((page) => page?.slug === props.path);
|
|
147
133
|
if (page) {
|
|
148
|
-
pageInitData = convertPageData(proxyState.rawState, page, locale ||
|
|
134
|
+
pageInitData = convertPageData(proxyState.rawState, page, locale || proxyState.rawState.config?.defaultLocale);
|
|
149
135
|
}
|
|
150
136
|
}
|
|
151
137
|
resolve(pageInitData);
|
|
152
|
-
}
|
|
138
|
+
};
|
|
153
139
|
// get init data, check if state is ready
|
|
154
140
|
if (proxyState.rawState) {
|
|
155
141
|
getPageInitData();
|
|
@@ -169,17 +155,16 @@ export const RuntimeComponent = (props) => {
|
|
|
169
155
|
});
|
|
170
156
|
// 当状态更新时通知所有监听器
|
|
171
157
|
useEffect(() => {
|
|
172
|
-
|
|
173
|
-
if ((_a = props.stateRef) === null || _a === void 0 ? void 0 : _a.current) {
|
|
158
|
+
if (props.stateRef?.current) {
|
|
174
159
|
listeners.current.forEach((listener) => listener(proxyState.rawState));
|
|
175
160
|
}
|
|
176
161
|
}, [proxyState.rawState]);
|
|
177
|
-
const { loading } = useRequest(() =>
|
|
162
|
+
const { loading } = useRequest(async () => {
|
|
178
163
|
if (props.state) {
|
|
179
164
|
return null;
|
|
180
165
|
}
|
|
181
166
|
// 统一使用 /api/pages 接口
|
|
182
|
-
const { data } =
|
|
167
|
+
const { data } = await api.get('/api/pages', {
|
|
183
168
|
params: {
|
|
184
169
|
did: props.did,
|
|
185
170
|
projectId: props.projectId,
|
|
@@ -188,7 +173,7 @@ export const RuntimeComponent = (props) => {
|
|
|
188
173
|
});
|
|
189
174
|
proxyState.rawState = data.state || data;
|
|
190
175
|
return data;
|
|
191
|
-
}
|
|
176
|
+
}, {
|
|
192
177
|
refreshDeps: [props.did, props.state, props.projectId],
|
|
193
178
|
});
|
|
194
179
|
if (loading) {
|
|
@@ -203,35 +188,27 @@ export const RuntimeComponent = (props) => {
|
|
|
203
188
|
return _jsx(PageRoutes, { mode: "production", state: proxyState.rawState });
|
|
204
189
|
};
|
|
205
190
|
export default class Runtime {
|
|
191
|
+
stateRef = React.createRef();
|
|
192
|
+
props;
|
|
206
193
|
constructor(props) {
|
|
207
|
-
this.stateRef = React.createRef();
|
|
208
194
|
this.props = props;
|
|
209
195
|
}
|
|
210
196
|
get rawState() {
|
|
211
|
-
|
|
212
|
-
return (_a = this.stateRef.current) === null || _a === void 0 ? void 0 : _a.getState();
|
|
197
|
+
return this.stateRef.current?.getState();
|
|
213
198
|
}
|
|
214
199
|
set pageData(data) {
|
|
215
|
-
|
|
216
|
-
(_a = this.stateRef.current) === null || _a === void 0 ? void 0 : _a.setPageData(data);
|
|
200
|
+
this.stateRef.current?.setPageData(data);
|
|
217
201
|
}
|
|
218
202
|
get pageData() {
|
|
219
|
-
|
|
220
|
-
return (_a = this.stateRef.current) === null || _a === void 0 ? void 0 : _a.getPageData();
|
|
203
|
+
return this.stateRef.current?.getPageData();
|
|
221
204
|
}
|
|
222
|
-
getPageInitData(
|
|
223
|
-
return
|
|
224
|
-
var _b;
|
|
225
|
-
return (_b = this.stateRef.current) === null || _b === void 0 ? void 0 : _b.getPageInitData({ locale });
|
|
226
|
-
});
|
|
205
|
+
async getPageInitData({ locale }) {
|
|
206
|
+
return this.stateRef.current?.getPageInitData({ locale });
|
|
227
207
|
}
|
|
228
|
-
waitForState() {
|
|
229
|
-
return
|
|
230
|
-
var _a;
|
|
231
|
-
return (_a = this.stateRef.current) === null || _a === void 0 ? void 0 : _a.waitForState();
|
|
232
|
-
});
|
|
208
|
+
async waitForState() {
|
|
209
|
+
return this.stateRef.current?.waitForState();
|
|
233
210
|
}
|
|
234
211
|
render() {
|
|
235
|
-
return _jsx(RuntimeComponent,
|
|
212
|
+
return _jsx(RuntimeComponent, { ...this.props, stateRef: this.stateRef });
|
|
236
213
|
}
|
|
237
214
|
}
|
|
@@ -19,11 +19,11 @@ export function CreateResource({ open, onClose, blockletDid, mode, }) {
|
|
|
19
19
|
},
|
|
20
20
|
}
|
|
21
21
|
: {};
|
|
22
|
-
return (_jsx(Box,
|
|
22
|
+
return (_jsx(Box, { ...boxProps, children: _jsx(Suspense, { children: _jsx(BlockletStudio, { mode: mode, tenantScope: tenantScope, title: "Pages Kit Blocks", description: "", note: "", introduction: "", logo: "", componentDid: blockletDid,
|
|
23
23
|
// 透传到 get blocklet resource 的参数
|
|
24
24
|
resourcesParams: {}, dependentComponentsMode: "readonly", open: true, setOpen: () => onClose(), onConnected: () => { }, onUploaded: () => { }, onReleased: () => { },
|
|
25
25
|
// onOpened={() => onOpened?.()}
|
|
26
26
|
// 默认选中的资源
|
|
27
|
-
resources: {} }) }) }))
|
|
27
|
+
resources: {} }) }) }));
|
|
28
28
|
}
|
|
29
29
|
export default CreateResource;
|