@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.
@@ -1,4 +1,5 @@
1
1
  import { cloneDeep } from 'lodash';
2
+ import { getPageAllSections } from './page-model';
2
3
  export function setPageDataSource(page, state, locale, pageData) {
3
4
  try {
4
5
  if (!page.locales) {
@@ -8,17 +9,21 @@ export function setPageDataSource(page, state, locale, pageData) {
8
9
  page.locales[locale].title = page.locales[locale].title || pageData.title;
9
10
  page.locales[locale].image = page.locales[locale].image || pageData.image;
10
11
  page.locales[locale].description = page.locales[locale].description || pageData.description;
12
+ if (!page.dataSource) {
13
+ page.dataSource = {};
14
+ }
15
+ const allSections = getPageAllSections(page);
11
16
  // 遍历 pageData 的每个 key
12
17
  Object.entries(pageData.sectionsData).forEach(([sectionKey, sectionData]) => {
13
18
  try {
14
19
  // 通过 id 或 name 找到对应的 section
15
- const section = Object.values(page.sections).find((section) => section.id === sectionKey || section.name === sectionKey);
20
+ const section = allSections.find((section) => section.id === sectionKey || section.name === sectionKey);
16
21
  if (!section) {
17
22
  return;
18
23
  }
19
- // 确保 section.locales 存在
20
- section.locales = cloneDeep(section.locales || {});
21
- section.locales[locale] = cloneDeep(section.locales[locale] || {});
24
+ // 确保 dataSource 存在
25
+ page.dataSource[section.id] = cloneDeep(page.dataSource[section.id] || {});
26
+ page.dataSource[section.id][locale] = cloneDeep(page.dataSource[section.id][locale] || {});
22
27
  if (section.component === 'custom-component') {
23
28
  // 处理自定义组件
24
29
  const componentId = section.config?.componentId;
@@ -30,16 +35,14 @@ export function setPageDataSource(page, state, locale, pageData) {
30
35
  if (!componentDef) {
31
36
  return;
32
37
  }
33
- // 确保 properties 存在
34
- section.locales[locale].properties = cloneDeep(section.locales[locale].properties || {});
38
+ page.dataSource[section.id][locale].properties = cloneDeep(page.dataSource[section.id][locale].properties || {});
35
39
  // 遍历 sectionData,设置属性值
36
40
  Object.entries(sectionData || {}).forEach(([propKey, propValue]) => {
37
41
  // 尝试通过 key 或 id 找到属性定义
38
42
  const property = componentDef?.properties?.[propKey] ||
39
43
  Object.values(componentDef?.properties || {}).find((prop) => prop.data?.key === propKey);
40
- if (property) {
41
- // 设置属性值
42
- section.locales[locale].properties[property.data?.id] = {
44
+ if (property && page.dataSource?.[section.id]?.[locale]?.properties) {
45
+ page.dataSource[section.id][locale].properties[property.data?.id] = {
43
46
  value: propValue,
44
47
  };
45
48
  }
@@ -47,8 +50,8 @@ export function setPageDataSource(page, state, locale, pageData) {
47
50
  }
48
51
  else {
49
52
  // 普通组件直接设置 properties
50
- section.locales[locale] = {
51
- ...cloneDeep(section.locales[locale]),
53
+ page.dataSource[section.id][locale] = {
54
+ ...cloneDeep(page.dataSource[section.id][locale] || {}),
52
55
  ...(sectionData || {}),
53
56
  };
54
57
  }
@@ -0,0 +1,19 @@
1
+ import { TemplateModel, PAGES_KIT_CHILDREN_PROPERTIES } from '@blocklet/pages-kit-core';
2
+ export const getPageTemplateModel = (page, isClone = true) => {
3
+ const templateModel = new TemplateModel({
4
+ childrenProperties: PAGES_KIT_CHILDREN_PROPERTIES,
5
+ });
6
+ templateModel.parse(page, {
7
+ isClone,
8
+ });
9
+ return templateModel;
10
+ };
11
+ export const getPageAllSections = (page) => {
12
+ const templateModel = getPageTemplateModel(page);
13
+ // @FIXME:这里没有去掉 layout block,现在是拉平处理
14
+ return (templateModel
15
+ .getRoot()
16
+ ?.all()
17
+ ?.filter((item) => item.model.id !== page.id)
18
+ ?.map((item) => item.model) || []);
19
+ };
@@ -40,6 +40,7 @@ export function mergeComponent({ componentId, getComponent, locale, defaultLocal
40
40
  const nextParameters = component.renderer.properties;
41
41
  assignNullableFields(props, Object.fromEntries(Object.entries(next?.properties ?? {}).map(([id, { data }]) => {
42
42
  const locales = nextParameters?.[id]?.locales;
43
+ // @FIXME: locales 需要从 dataSource 中获取,这是个内嵌组件,目前还没被额外处理,跟随父级组件的 locales,感觉需要废弃内嵌组件
43
44
  return [
44
45
  data.key,
45
46
  parsePropertyValue(data, locales?.[locale]?.value ??
@@ -13,6 +13,5 @@ export declare const useEventBus: <T>(eventName?: string, eventCallBack?: EventC
13
13
  <Key extends string>(type: Key, handler: import("mitt").Handler<any>): void;
14
14
  (type: "*", handler: import("mitt").WildcardHandler<Record<string, any>>): void;
15
15
  };
16
- all: import("mitt").EventHandlerMap<Record<string, any>>;
17
16
  };
18
17
  export default useEventBus;