@blocklet/pages-kit 0.5.45 → 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.
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/common.js +3 -1
- package/lib/cjs/utils/page-model.js +41 -4
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/common.js +2 -0
- package/lib/esm/utils/page-model.js +36 -3
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/core.d.ts +11 -11
- package/lib/types/utils/common.d.ts +1 -0
- package/lib/types/utils/page-model.d.ts +1 -0
- package/package.json +4 -4
package/lib/cjs/utils/common.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBrowserEnv = exports.COLOR_CONVERT_FUNCTION_NAME = void 0;
|
|
3
|
+
exports.nextId = exports.isBrowserEnv = exports.COLOR_CONVERT_FUNCTION_NAME = void 0;
|
|
4
4
|
exports.isMuiColorKey = isMuiColorKey;
|
|
5
|
+
const nanoid_1 = require("nanoid");
|
|
5
6
|
exports.COLOR_CONVERT_FUNCTION_NAME = 'colorConvert';
|
|
6
7
|
const isBrowserEnv = () => {
|
|
7
8
|
return typeof globalThis.window !== 'undefined' && typeof globalThis.document !== 'undefined';
|
|
@@ -17,3 +18,4 @@ function isMuiColorKey(value) {
|
|
|
17
18
|
}
|
|
18
19
|
return /^(primary|secondary|error|warning|info|success|grey|background|text|action)\.[a-z0-9]+$/.test(value);
|
|
19
20
|
}
|
|
21
|
+
exports.nextId = (0, nanoid_1.customAlphabet)('abcdefghijklmnopqrstuvwxyz0123456789', 16);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPageAllSections = exports.getPageTemplateModel = void 0;
|
|
6
|
+
exports.unzipSection = exports.getPageAllSections = exports.getPageTemplateModel = void 0;
|
|
4
7
|
const pages_kit_core_1 = require("@blocklet/pages-kit-core");
|
|
8
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
5
9
|
const getPageTemplateModel = (page, isClone = true) => {
|
|
6
10
|
const templateModel = new pages_kit_core_1.TemplateModel({
|
|
7
11
|
childrenProperties: pages_kit_core_1.PAGES_KIT_CHILDREN_PROPERTIES,
|
|
@@ -13,12 +17,45 @@ const getPageTemplateModel = (page, isClone = true) => {
|
|
|
13
17
|
};
|
|
14
18
|
exports.getPageTemplateModel = getPageTemplateModel;
|
|
15
19
|
const getPageAllSections = (page) => {
|
|
16
|
-
const
|
|
17
|
-
//
|
|
20
|
+
const clonePage = (0, cloneDeep_1.default)(page);
|
|
21
|
+
// 如果 page 不包含 page.sectionIds 并且 page.sections 为数组,那么需要转换为对应的格式
|
|
22
|
+
if (!clonePage.sectionIds && Array.isArray(clonePage.sections)) {
|
|
23
|
+
const sections = clonePage.sections.map(exports.unzipSection);
|
|
24
|
+
clonePage.sections = Object.fromEntries(sections.map((i) => [i.id, i]));
|
|
25
|
+
clonePage.sectionIds = sections.map((i) => i.id);
|
|
26
|
+
}
|
|
27
|
+
const templateModel = (0, exports.getPageTemplateModel)(clonePage);
|
|
28
|
+
// @FIXME:现在是拉平处理
|
|
18
29
|
return (templateModel
|
|
19
30
|
.getRoot()
|
|
20
31
|
?.all()
|
|
21
|
-
?.filter((item) => item.model.id !== page.id)
|
|
32
|
+
?.filter((item) => item.model.id !== page.id && item.model.component !== 'layout-block')
|
|
22
33
|
?.map((item) => item.model) || []);
|
|
23
34
|
};
|
|
24
35
|
exports.getPageAllSections = getPageAllSections;
|
|
36
|
+
const unzipSection = (section) => {
|
|
37
|
+
// 如果 section 已经有 sectionIds 和 sections,那么直接返回
|
|
38
|
+
if (section.sectionIds && section.sections) {
|
|
39
|
+
return section;
|
|
40
|
+
}
|
|
41
|
+
const sectionId = section.id;
|
|
42
|
+
const hasChildSections = section.sections && Object.keys(section.sections).length > 0;
|
|
43
|
+
const extraProps = {};
|
|
44
|
+
if (hasChildSections) {
|
|
45
|
+
// Recursively process child sections
|
|
46
|
+
extraProps.sections = Object.fromEntries(section.sections?.map?.((s) => [s.id, (0, exports.unzipSection)(s)]) ?? []) || {};
|
|
47
|
+
extraProps.sectionIds = section.sections?.map?.((s) => s.id) ?? [];
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
id: sectionId,
|
|
51
|
+
component: section.component,
|
|
52
|
+
config: section.config,
|
|
53
|
+
name: section.name,
|
|
54
|
+
isTemplateSection: section.isTemplateSection ?? false,
|
|
55
|
+
templateDescription: section.templateDescription,
|
|
56
|
+
llmConfig: section.llmConfig,
|
|
57
|
+
visibility: section.visibility,
|
|
58
|
+
...extraProps,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.unzipSection = unzipSection;
|