@blocklet/pages-kit 0.5.29 → 0.5.31
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/builtin/event-bus.js +0 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/data-source.js +14 -11
- package/lib/cjs/utils/page-model.js +24 -0
- package/lib/cjs/utils/property.js +1 -0
- package/lib/esm/builtin/event-bus.js +0 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/data-source.js +14 -11
- package/lib/esm/utils/page-model.js +19 -0
- package/lib/esm/utils/property.js +1 -0
- package/lib/types/builtin/event-bus.d.ts +0 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/state.d.ts +7 -0
- package/lib/types/utils/page-model.d.ts +4 -0
- package/package.json +6 -5
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setPageDataSource = setPageDataSource;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
+
const page_model_1 = require("./page-model");
|
|
5
6
|
function setPageDataSource(page, state, locale, pageData) {
|
|
6
7
|
try {
|
|
7
8
|
if (!page.locales) {
|
|
@@ -11,17 +12,21 @@ function setPageDataSource(page, state, locale, pageData) {
|
|
|
11
12
|
page.locales[locale].title = page.locales[locale].title || pageData.title;
|
|
12
13
|
page.locales[locale].image = page.locales[locale].image || pageData.image;
|
|
13
14
|
page.locales[locale].description = page.locales[locale].description || pageData.description;
|
|
15
|
+
if (!page.dataSource) {
|
|
16
|
+
page.dataSource = {};
|
|
17
|
+
}
|
|
18
|
+
const allSections = (0, page_model_1.getPageAllSections)(page);
|
|
14
19
|
// 遍历 pageData 的每个 key
|
|
15
20
|
Object.entries(pageData.sectionsData).forEach(([sectionKey, sectionData]) => {
|
|
16
21
|
try {
|
|
17
22
|
// 通过 id 或 name 找到对应的 section
|
|
18
|
-
const section =
|
|
23
|
+
const section = allSections.find((section) => section.id === sectionKey || section.name === sectionKey);
|
|
19
24
|
if (!section) {
|
|
20
25
|
return;
|
|
21
26
|
}
|
|
22
|
-
// 确保
|
|
23
|
-
section.
|
|
24
|
-
section.
|
|
27
|
+
// 确保 dataSource 存在
|
|
28
|
+
page.dataSource[section.id] = (0, lodash_1.cloneDeep)(page.dataSource[section.id] || {});
|
|
29
|
+
page.dataSource[section.id][locale] = (0, lodash_1.cloneDeep)(page.dataSource[section.id][locale] || {});
|
|
25
30
|
if (section.component === 'custom-component') {
|
|
26
31
|
// 处理自定义组件
|
|
27
32
|
const componentId = section.config?.componentId;
|
|
@@ -33,16 +38,14 @@ function setPageDataSource(page, state, locale, pageData) {
|
|
|
33
38
|
if (!componentDef) {
|
|
34
39
|
return;
|
|
35
40
|
}
|
|
36
|
-
|
|
37
|
-
section.locales[locale].properties = (0, lodash_1.cloneDeep)(section.locales[locale].properties || {});
|
|
41
|
+
page.dataSource[section.id][locale].properties = (0, lodash_1.cloneDeep)(page.dataSource[section.id][locale].properties || {});
|
|
38
42
|
// 遍历 sectionData,设置属性值
|
|
39
43
|
Object.entries(sectionData || {}).forEach(([propKey, propValue]) => {
|
|
40
44
|
// 尝试通过 key 或 id 找到属性定义
|
|
41
45
|
const property = componentDef?.properties?.[propKey] ||
|
|
42
46
|
Object.values(componentDef?.properties || {}).find((prop) => prop.data?.key === propKey);
|
|
43
|
-
if (property) {
|
|
44
|
-
|
|
45
|
-
section.locales[locale].properties[property.data?.id] = {
|
|
47
|
+
if (property && page.dataSource?.[section.id]?.[locale]?.properties) {
|
|
48
|
+
page.dataSource[section.id][locale].properties[property.data?.id] = {
|
|
46
49
|
value: propValue,
|
|
47
50
|
};
|
|
48
51
|
}
|
|
@@ -50,8 +53,8 @@ function setPageDataSource(page, state, locale, pageData) {
|
|
|
50
53
|
}
|
|
51
54
|
else {
|
|
52
55
|
// 普通组件直接设置 properties
|
|
53
|
-
section.
|
|
54
|
-
...(0, lodash_1.cloneDeep)(section.
|
|
56
|
+
page.dataSource[section.id][locale] = {
|
|
57
|
+
...(0, lodash_1.cloneDeep)(page.dataSource[section.id][locale] || {}),
|
|
55
58
|
...(sectionData || {}),
|
|
56
59
|
};
|
|
57
60
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPageAllSections = exports.getPageTemplateModel = void 0;
|
|
4
|
+
const pages_kit_core_1 = require("@blocklet/pages-kit-core");
|
|
5
|
+
const getPageTemplateModel = (page, isClone = true) => {
|
|
6
|
+
const templateModel = new pages_kit_core_1.TemplateModel({
|
|
7
|
+
childrenProperties: pages_kit_core_1.PAGES_KIT_CHILDREN_PROPERTIES,
|
|
8
|
+
});
|
|
9
|
+
templateModel.parse(page, {
|
|
10
|
+
isClone,
|
|
11
|
+
});
|
|
12
|
+
return templateModel;
|
|
13
|
+
};
|
|
14
|
+
exports.getPageTemplateModel = getPageTemplateModel;
|
|
15
|
+
const getPageAllSections = (page) => {
|
|
16
|
+
const templateModel = (0, exports.getPageTemplateModel)(page);
|
|
17
|
+
// @FIXME:这里没有去掉 layout block,现在是拉平处理
|
|
18
|
+
return (templateModel
|
|
19
|
+
.getRoot()
|
|
20
|
+
?.all()
|
|
21
|
+
?.filter((item) => item.model.id !== page.id)
|
|
22
|
+
?.map((item) => item.model) || []);
|
|
23
|
+
};
|
|
24
|
+
exports.getPageAllSections = getPageAllSections;
|
|
@@ -76,6 +76,7 @@ function mergeComponent({ componentId, getComponent, locale, defaultLocale, prop
|
|
|
76
76
|
const nextParameters = component.renderer.properties;
|
|
77
77
|
assignNullableFields(props, Object.fromEntries(Object.entries(next?.properties ?? {}).map(([id, { data }]) => {
|
|
78
78
|
const locales = nextParameters?.[id]?.locales;
|
|
79
|
+
// @FIXME: locales 需要从 dataSource 中获取,这是个内嵌组件,目前还没被额外处理,跟随父级组件的 locales,感觉需要废弃内嵌组件
|
|
79
80
|
return [
|
|
80
81
|
data.key,
|
|
81
82
|
parsePropertyValue(data, locales?.[locale]?.value ??
|