@blocklet/pages-kit 0.5.47 → 0.5.48

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,3 +1,4 @@
1
+ import { customAlphabet } from 'nanoid';
1
2
  export const COLOR_CONVERT_FUNCTION_NAME = 'colorConvert';
2
3
  export const isBrowserEnv = () => {
3
4
  return typeof globalThis.window !== 'undefined' && typeof globalThis.document !== 'undefined';
@@ -12,3 +13,4 @@ export function isMuiColorKey(value) {
12
13
  }
13
14
  return /^(primary|secondary|error|warning|info|success|grey|background|text|action)\.[a-z0-9]+$/.test(value);
14
15
  }
16
+ export const nextId = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 16);
@@ -1,4 +1,5 @@
1
1
  import { TemplateModel, PAGES_KIT_CHILDREN_PROPERTIES } from '@blocklet/pages-kit-core';
2
+ import cloneDeep from 'lodash/cloneDeep';
2
3
  export const getPageTemplateModel = (page, isClone = true) => {
3
4
  const templateModel = new TemplateModel({
4
5
  childrenProperties: PAGES_KIT_CHILDREN_PROPERTIES,
@@ -9,11 +10,43 @@ export const getPageTemplateModel = (page, isClone = true) => {
9
10
  return templateModel;
10
11
  };
11
12
  export const getPageAllSections = (page) => {
12
- const templateModel = getPageTemplateModel(page);
13
- // @FIXME:这里没有去掉 layout block,现在是拉平处理
13
+ const clonePage = cloneDeep(page);
14
+ // 如果 page 不包含 page.sectionIds 并且 page.sections 为数组,那么需要转换为对应的格式
15
+ if (!clonePage.sectionIds && Array.isArray(clonePage.sections)) {
16
+ const sections = clonePage.sections.map(unzipSection);
17
+ clonePage.sections = Object.fromEntries(sections.map((i) => [i.id, i]));
18
+ clonePage.sectionIds = sections.map((i) => i.id);
19
+ }
20
+ const templateModel = getPageTemplateModel(clonePage);
21
+ // @FIXME:现在是拉平处理
14
22
  return (templateModel
15
23
  .getRoot()
16
24
  ?.all()
17
- ?.filter((item) => item.model.id !== page.id)
25
+ ?.filter((item) => item.model.id !== page.id && item.model.component !== 'layout-block')
18
26
  ?.map((item) => item.model) || []);
19
27
  };
28
+ export const unzipSection = (section) => {
29
+ // 如果 section 已经有 sectionIds 和 sections,那么直接返回
30
+ if (section.sectionIds && section.sections) {
31
+ return section;
32
+ }
33
+ const sectionId = section.id;
34
+ const hasChildSections = section.sections && Object.keys(section.sections).length > 0;
35
+ const extraProps = {};
36
+ if (hasChildSections) {
37
+ // Recursively process child sections
38
+ extraProps.sections = Object.fromEntries(section.sections?.map?.((s) => [s.id, unzipSection(s)]) ?? []) || {};
39
+ extraProps.sectionIds = section.sections?.map?.((s) => s.id) ?? [];
40
+ }
41
+ return {
42
+ id: sectionId,
43
+ component: section.component,
44
+ config: section.config,
45
+ name: section.name,
46
+ isTemplateSection: section.isTemplateSection ?? false,
47
+ templateDescription: section.templateDescription,
48
+ llmConfig: section.llmConfig,
49
+ visibility: section.visibility,
50
+ ...extraProps,
51
+ };
52
+ };