km-card-layout-core 0.1.25 → 0.1.27
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/README.md +1 -2
- package/bindings.ts +9 -20
- package/data.ts +1 -3
- package/dist/bindings.js +6 -14
- package/dist/data.js +1 -1
- package/dist/index.js +9 -18
- package/dist/interface/index.js +0 -1
- package/dist/layout.js +1 -17
- package/dist/ops/changeBackground.js +45 -97
- package/dist/render/helpers.js +41 -21
- package/dist/render/init.js +81 -0
- package/index.ts +7 -26
- package/interface/data/payload.ts +3 -3
- package/interface/elements.ts +2 -1
- package/interface/index.ts +0 -1
- package/interface/layout.ts +2 -1
- package/layout.ts +0 -18
- package/ops/changeBackground.ts +47 -130
- package/package.json +1 -1
- package/render/helpers.ts +72 -28
- package/render/init.ts +107 -0
- package/types.d.ts +35 -98
- package/dist/interface/context.js +0 -2
- package/dist/interface/render.js +0 -2
- package/dist/render/builder.js +0 -209
- package/dist/render/tool.js +0 -15
- package/dist/utils.js +0 -25
- package/interface/context.ts +0 -6
- package/render/tool.ts +0 -21
- package/utils.ts +0 -13
package/README.md
CHANGED
|
@@ -8,9 +8,8 @@ Utilities for working with card layout schemas: sanitize layouts, handle binding
|
|
|
8
8
|
- `resolveBindingValue(path, data, context?)`: read bound data with optional context.
|
|
9
9
|
- `styleObjectToString(style, unit?)`: convert a style object to a CSS string.
|
|
10
10
|
- `addUnit(value, unit)`: append px/rpx to numbers or numeric strings.
|
|
11
|
-
- Background
|
|
11
|
+
- Background helper: `backgroundChange` to apply template background colors.
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
Use the layout schema and card elements directly for rendering on web or mini-program targets—no extra RenderNode transformation layer is required. The core is platform-agnostic and can be imported via `require('km-card-layout-core')`.
|
|
16
|
-
|
package/bindings.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { CardElement, CardLayoutSchema } from './interface';
|
|
2
|
-
import type {
|
|
3
|
-
TemplateBackground,
|
|
4
|
-
TemplateItem,
|
|
5
|
-
} from './interface/data/payload';
|
|
2
|
+
import type { TemplateItem } from './interface/data/payload';
|
|
6
3
|
|
|
7
4
|
export function stripLayoutBindings(
|
|
8
5
|
layouts: CardLayoutSchema[] = []
|
|
@@ -29,6 +26,8 @@ export function applyItemCollectBindings(
|
|
|
29
26
|
layouts: CardLayoutSchema[] = [],
|
|
30
27
|
items: TemplateItem[] = []
|
|
31
28
|
): CardLayoutSchema[] {
|
|
29
|
+
console.log('applyItemCollectBindings', layouts, items);
|
|
30
|
+
|
|
32
31
|
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
33
32
|
const metaMap = new Map<string, TemplateItem>();
|
|
34
33
|
const metaList = Array.isArray(items) ? items : [];
|
|
@@ -47,15 +46,17 @@ export function applyItemCollectBindings(
|
|
|
47
46
|
const defaultValue =
|
|
48
47
|
meta && meta.default !== undefined ? meta.default : el.defaultValue;
|
|
49
48
|
const key = meta && meta.key !== undefined ? meta.key : el.key;
|
|
50
|
-
const base: any = { ...el };
|
|
49
|
+
const base: any = { ...el, label: meta?.name };
|
|
51
50
|
if (binding !== undefined) base.binding = binding;
|
|
52
51
|
else delete base.binding;
|
|
53
52
|
if (defaultValue !== undefined) base.defaultValue = defaultValue;
|
|
54
53
|
else delete base.defaultValue;
|
|
55
54
|
if (key !== undefined) base.key = key;
|
|
56
55
|
else delete base.key;
|
|
57
|
-
if (el.type === 'text'
|
|
58
|
-
|
|
56
|
+
if (el.type === 'text') {
|
|
57
|
+
// if (meta?.extra?.icon) {
|
|
58
|
+
// base.icon = { ...(base.icon || {}), name: meta.extra.icon };
|
|
59
|
+
// }
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
if (el.type === 'layout-panel') {
|
|
@@ -64,6 +65,7 @@ export function applyItemCollectBindings(
|
|
|
64
65
|
children: (el.children || []).map(assignBinding),
|
|
65
66
|
} as CardElement;
|
|
66
67
|
}
|
|
68
|
+
|
|
67
69
|
return base as CardElement;
|
|
68
70
|
};
|
|
69
71
|
|
|
@@ -72,16 +74,3 @@ export function applyItemCollectBindings(
|
|
|
72
74
|
children: (layout.children || []).map(assignBinding),
|
|
73
75
|
}));
|
|
74
76
|
}
|
|
75
|
-
|
|
76
|
-
export function getTemplateItems(ids: string, items: TemplateItem[]) {
|
|
77
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
78
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function getTemplateBackgrounds(
|
|
82
|
-
ids: string,
|
|
83
|
-
items: TemplateBackground[]
|
|
84
|
-
) {
|
|
85
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
86
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
87
|
-
}
|
package/data.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isObject } from './helpers';
|
|
2
|
-
import type { BindingContext } from './interface';
|
|
3
2
|
|
|
4
3
|
const pathToSegments = (path: string): string[] =>
|
|
5
4
|
`${path || ''}`
|
|
@@ -30,8 +29,7 @@ const readByPath = (data: any, path: string): any => {
|
|
|
30
29
|
|
|
31
30
|
export const resolveBindingValue = (
|
|
32
31
|
binding: string | undefined,
|
|
33
|
-
rootData: Record<string, any
|
|
34
|
-
context?: BindingContext
|
|
32
|
+
rootData: Record<string, any>
|
|
35
33
|
): any => {
|
|
36
34
|
if (!binding) return undefined;
|
|
37
35
|
const value = readByPath(rootData, binding);
|
package/dist/bindings.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stripLayoutBindings = stripLayoutBindings;
|
|
4
4
|
exports.applyItemCollectBindings = applyItemCollectBindings;
|
|
5
|
-
exports.getTemplateItems = getTemplateItems;
|
|
6
|
-
exports.getTemplateBackgrounds = getTemplateBackgrounds;
|
|
7
5
|
function stripLayoutBindings(layouts = []) {
|
|
8
6
|
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
9
7
|
const stripElement = (el) => {
|
|
@@ -22,6 +20,7 @@ function stripLayoutBindings(layouts = []) {
|
|
|
22
20
|
}));
|
|
23
21
|
}
|
|
24
22
|
function applyItemCollectBindings(layouts = [], items = []) {
|
|
23
|
+
console.log('applyItemCollectBindings', layouts, items);
|
|
25
24
|
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
26
25
|
const metaMap = new Map();
|
|
27
26
|
const metaList = Array.isArray(items) ? items : [];
|
|
@@ -31,14 +30,13 @@ function applyItemCollectBindings(layouts = [], items = []) {
|
|
|
31
30
|
}
|
|
32
31
|
});
|
|
33
32
|
const assignBinding = (el) => {
|
|
34
|
-
var _a;
|
|
35
33
|
const meta = metaMap.get(String(el.id));
|
|
36
34
|
const binding = meta && meta.bind !== undefined && meta.bind !== null
|
|
37
35
|
? meta.bind
|
|
38
36
|
: el.binding;
|
|
39
37
|
const defaultValue = meta && meta.default !== undefined ? meta.default : el.defaultValue;
|
|
40
38
|
const key = meta && meta.key !== undefined ? meta.key : el.key;
|
|
41
|
-
const base = { ...el };
|
|
39
|
+
const base = { ...el, label: meta === null || meta === void 0 ? void 0 : meta.name };
|
|
42
40
|
if (binding !== undefined)
|
|
43
41
|
base.binding = binding;
|
|
44
42
|
else
|
|
@@ -51,8 +49,10 @@ function applyItemCollectBindings(layouts = [], items = []) {
|
|
|
51
49
|
base.key = key;
|
|
52
50
|
else
|
|
53
51
|
delete base.key;
|
|
54
|
-
if (el.type === 'text'
|
|
55
|
-
|
|
52
|
+
if (el.type === 'text') {
|
|
53
|
+
// if (meta?.extra?.icon) {
|
|
54
|
+
// base.icon = { ...(base.icon || {}), name: meta.extra.icon };
|
|
55
|
+
// }
|
|
56
56
|
}
|
|
57
57
|
if (el.type === 'layout-panel') {
|
|
58
58
|
return {
|
|
@@ -67,11 +67,3 @@ function applyItemCollectBindings(layouts = [], items = []) {
|
|
|
67
67
|
children: (layout.children || []).map(assignBinding),
|
|
68
68
|
}));
|
|
69
69
|
}
|
|
70
|
-
function getTemplateItems(ids, items) {
|
|
71
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
72
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
73
|
-
}
|
|
74
|
-
function getTemplateBackgrounds(ids, items) {
|
|
75
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
76
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
77
|
-
}
|
package/dist/data.js
CHANGED
|
@@ -29,7 +29,7 @@ const readByPath = (data, path) => {
|
|
|
29
29
|
}
|
|
30
30
|
return cursor;
|
|
31
31
|
};
|
|
32
|
-
const resolveBindingValue = (binding, rootData
|
|
32
|
+
const resolveBindingValue = (binding, rootData) => {
|
|
33
33
|
if (!binding)
|
|
34
34
|
return undefined;
|
|
35
35
|
const value = readByPath(rootData, binding);
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* CardMaster 布局 JSON 渲染核心
|
|
4
|
-
*
|
|
5
|
-
* - 平台无关:不依赖 DOM/小程序 API,方便在 Web/小程序/Node 复用。
|
|
6
|
-
* - 职责:将布局 Schema 与业务数据合成可渲染树,外层只需将节点映射到各端组件。
|
|
7
|
-
*/
|
|
8
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
3
|
if (k2 === undefined) k2 = k;
|
|
10
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -20,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
15
|
};
|
|
22
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
17
|
+
exports.processCardLayout = exports.handleSpecialFields = exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextValueStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = exports.backgroundChange = exports.applyItemCollectBindings = exports.stripLayoutBindings = exports.resolveBindingValue = exports.parseLayout = exports.normalizeId = exports.getAbsLayout = exports.roundToInt = exports.sanitizeElement = exports.sanitizeLayout = exports.normalizeLayout = exports.isObject = exports.toNumber = exports.styleObjectToString = exports.addUnit = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Core exports for card layout helpers.
|
|
20
|
+
* Platform-agnostic utilities shared by web/mini-program renderers.
|
|
21
|
+
*/
|
|
24
22
|
__exportStar(require("./interface/index"), exports);
|
|
25
23
|
var helpers_1 = require("./helpers");
|
|
26
24
|
Object.defineProperty(exports, "addUnit", { enumerable: true, get: function () { return helpers_1.addUnit; } });
|
|
@@ -33,26 +31,15 @@ Object.defineProperty(exports, "sanitizeLayout", { enumerable: true, get: functi
|
|
|
33
31
|
Object.defineProperty(exports, "sanitizeElement", { enumerable: true, get: function () { return layout_1.sanitizeElement; } });
|
|
34
32
|
Object.defineProperty(exports, "roundToInt", { enumerable: true, get: function () { return layout_1.roundToInt; } });
|
|
35
33
|
Object.defineProperty(exports, "getAbsLayout", { enumerable: true, get: function () { return layout_1.getAbsLayout; } });
|
|
36
|
-
Object.defineProperty(exports, "collectBindings", { enumerable: true, get: function () { return layout_1.collectBindings; } });
|
|
37
34
|
Object.defineProperty(exports, "normalizeId", { enumerable: true, get: function () { return layout_1.normalizeId; } });
|
|
38
35
|
Object.defineProperty(exports, "parseLayout", { enumerable: true, get: function () { return layout_1.parseLayout; } });
|
|
39
|
-
Object.defineProperty(exports, "areChildrenEqual", { enumerable: true, get: function () { return layout_1.areChildrenEqual; } });
|
|
40
36
|
var data_1 = require("./data");
|
|
41
37
|
Object.defineProperty(exports, "resolveBindingValue", { enumerable: true, get: function () { return data_1.resolveBindingValue; } });
|
|
42
38
|
var bindings_1 = require("./bindings");
|
|
43
39
|
Object.defineProperty(exports, "stripLayoutBindings", { enumerable: true, get: function () { return bindings_1.stripLayoutBindings; } });
|
|
44
40
|
Object.defineProperty(exports, "applyItemCollectBindings", { enumerable: true, get: function () { return bindings_1.applyItemCollectBindings; } });
|
|
45
|
-
Object.defineProperty(exports, "getTemplateItems", { enumerable: true, get: function () { return bindings_1.getTemplateItems; } });
|
|
46
|
-
Object.defineProperty(exports, "getTemplateBackgrounds", { enumerable: true, get: function () { return bindings_1.getTemplateBackgrounds; } });
|
|
47
41
|
var changeBackground_1 = require("./ops/changeBackground");
|
|
48
42
|
Object.defineProperty(exports, "backgroundChange", { enumerable: true, get: function () { return changeBackground_1.backgroundChange; } });
|
|
49
|
-
Object.defineProperty(exports, "DEFAULT_DECOR_COLOR", { enumerable: true, get: function () { return changeBackground_1.DEFAULT_DECOR_COLOR; } });
|
|
50
|
-
Object.defineProperty(exports, "resolveSpecialStyle", { enumerable: true, get: function () { return changeBackground_1.resolveSpecialStyle; } });
|
|
51
|
-
Object.defineProperty(exports, "applySpecialStyle", { enumerable: true, get: function () { return changeBackground_1.applySpecialStyle; } });
|
|
52
|
-
Object.defineProperty(exports, "applyBackground", { enumerable: true, get: function () { return changeBackground_1.applyBackground; } });
|
|
53
|
-
Object.defineProperty(exports, "updateElementsStyle", { enumerable: true, get: function () { return changeBackground_1.updateElementsStyle; } });
|
|
54
|
-
var tool_1 = require("./render/tool");
|
|
55
|
-
Object.defineProperty(exports, "buildRenderData", { enumerable: true, get: function () { return tool_1.buildRenderData; } });
|
|
56
43
|
var helpers_2 = require("./render/helpers");
|
|
57
44
|
Object.defineProperty(exports, "buildWrapperStyle", { enumerable: true, get: function () { return helpers_2.buildWrapperStyle; } });
|
|
58
45
|
Object.defineProperty(exports, "buildCardStyle", { enumerable: true, get: function () { return helpers_2.buildCardStyle; } });
|
|
@@ -60,8 +47,12 @@ Object.defineProperty(exports, "buildBackgroundStyle", { enumerable: true, get:
|
|
|
60
47
|
Object.defineProperty(exports, "buildBaseContentStyle", { enumerable: true, get: function () { return helpers_2.buildBaseContentStyle; } });
|
|
61
48
|
Object.defineProperty(exports, "buildPanelContentStyle", { enumerable: true, get: function () { return helpers_2.buildPanelContentStyle; } });
|
|
62
49
|
Object.defineProperty(exports, "buildTextContentStyle", { enumerable: true, get: function () { return helpers_2.buildTextContentStyle; } });
|
|
50
|
+
Object.defineProperty(exports, "buildTextValueStyle", { enumerable: true, get: function () { return helpers_2.buildTextValueStyle; } });
|
|
63
51
|
Object.defineProperty(exports, "buildImageContentStyle", { enumerable: true, get: function () { return helpers_2.buildImageContentStyle; } });
|
|
64
52
|
Object.defineProperty(exports, "getTextValue", { enumerable: true, get: function () { return helpers_2.getTextValue; } });
|
|
65
53
|
Object.defineProperty(exports, "getImageSrc", { enumerable: true, get: function () { return helpers_2.getImageSrc; } });
|
|
66
54
|
Object.defineProperty(exports, "getIconName", { enumerable: true, get: function () { return helpers_2.getIconName; } });
|
|
67
55
|
Object.defineProperty(exports, "buildTextIconMeta", { enumerable: true, get: function () { return helpers_2.buildTextIconMeta; } });
|
|
56
|
+
var init_1 = require("./render/init");
|
|
57
|
+
Object.defineProperty(exports, "handleSpecialFields", { enumerable: true, get: function () { return init_1.handleSpecialFields; } });
|
|
58
|
+
Object.defineProperty(exports, "processCardLayout", { enumerable: true, get: function () { return init_1.processCardLayout; } });
|
package/dist/interface/index.js
CHANGED
package/dist/layout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.normalizeLayout = exports.parseLayout = exports.normalizeId = exports.sanitizeLayout = exports.sanitizeElement = exports.getAbsLayout = exports.roundToInt = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const DEFAULT_CARD_WIDTH = 343;
|
|
6
6
|
const DEFAULT_CARD_HEIGHT = 210;
|
|
@@ -40,18 +40,6 @@ const sanitizeLayout = (layout) => ({
|
|
|
40
40
|
children: (layout.children || []).map(child => (0, exports.sanitizeElement)(child)),
|
|
41
41
|
});
|
|
42
42
|
exports.sanitizeLayout = sanitizeLayout;
|
|
43
|
-
const collectBindings = (elements = []) => {
|
|
44
|
-
const result = [];
|
|
45
|
-
elements.forEach(el => {
|
|
46
|
-
if (el.binding)
|
|
47
|
-
result.push(el.binding);
|
|
48
|
-
if (el.type === 'layout-panel' && el.children) {
|
|
49
|
-
result.push(...(0, exports.collectBindings)(el.children));
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return Array.from(new Set(result));
|
|
53
|
-
};
|
|
54
|
-
exports.collectBindings = collectBindings;
|
|
55
43
|
const normalizeId = (id) => {
|
|
56
44
|
if (id === undefined || id === null)
|
|
57
45
|
return undefined;
|
|
@@ -111,7 +99,3 @@ const normalizeLayout = (layout) => {
|
|
|
111
99
|
.filter((value) => Boolean(value));
|
|
112
100
|
};
|
|
113
101
|
exports.normalizeLayout = normalizeLayout;
|
|
114
|
-
const areChildrenEqual = (a, b) => {
|
|
115
|
-
return JSON.stringify(a === null || a === void 0 ? void 0 : a.children) === JSON.stringify(b === null || b === void 0 ? void 0 : b.children);
|
|
116
|
-
};
|
|
117
|
-
exports.areChildrenEqual = areChildrenEqual;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setElementVisible = exports.updateElementsStyle = exports.applyBackground = exports.applySpecialStyle = exports.resolveSpecialStyle = exports.DEFAULT_DECOR_COLOR = void 0;
|
|
4
3
|
exports.backgroundChange = backgroundChange;
|
|
5
4
|
const toNameArray = (name) => {
|
|
6
5
|
if (Array.isArray(name))
|
|
@@ -13,10 +12,10 @@ const toNameArray = (name) => {
|
|
|
13
12
|
.filter(Boolean);
|
|
14
13
|
};
|
|
15
14
|
function backgroundChange(bg, layout) {
|
|
15
|
+
var _a;
|
|
16
|
+
const extras = bg.fontColorExtra || [];
|
|
17
|
+
const iconSpecialColor = (_a = extras.find(sc => toNameArray(sc.name).some(n => n === 'icon'))) === null || _a === void 0 ? void 0 : _a.color;
|
|
16
18
|
const applySpecialColor = (el) => {
|
|
17
|
-
const extras = bg.fontColorExtra || [];
|
|
18
|
-
if (!extras.length)
|
|
19
|
-
return el;
|
|
20
19
|
const keys = [];
|
|
21
20
|
if (el.binding)
|
|
22
21
|
keys.push(String(el.binding));
|
|
@@ -27,13 +26,48 @@ function backgroundChange(bg, layout) {
|
|
|
27
26
|
if (el.type === 'custom')
|
|
28
27
|
keys.push('decor');
|
|
29
28
|
const matched = extras.find(sc => toNameArray(sc.name).some(n => keys.some(k => k === null || k === void 0 ? void 0 : k.startsWith(n))));
|
|
30
|
-
if (!matched)
|
|
31
|
-
return el;
|
|
32
29
|
const baseStyle = { ...(el.style || {}) };
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
let nextEl = el;
|
|
31
|
+
if (matched) {
|
|
32
|
+
if (el.type === 'custom') {
|
|
33
|
+
nextEl = { ...el, style: { ...baseStyle, backgroundColor: matched.color } };
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
nextEl = { ...el, style: { ...baseStyle, color: matched.color } };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const nextStyle = { ...baseStyle };
|
|
41
|
+
let changed = false;
|
|
42
|
+
if (el.type === 'custom') {
|
|
43
|
+
if ('backgroundColor' in nextStyle) {
|
|
44
|
+
delete nextStyle.backgroundColor;
|
|
45
|
+
changed = true;
|
|
46
|
+
}
|
|
47
|
+
if ('background' in nextStyle) {
|
|
48
|
+
delete nextStyle.background;
|
|
49
|
+
changed = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if ('color' in nextStyle) {
|
|
53
|
+
delete nextStyle.color;
|
|
54
|
+
changed = true;
|
|
55
|
+
}
|
|
56
|
+
if (changed) {
|
|
57
|
+
nextEl = { ...el, style: nextStyle };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (nextEl.type === 'text' && nextEl.icon) {
|
|
61
|
+
const nextIcon = { ...nextEl.icon };
|
|
62
|
+
if (iconSpecialColor) {
|
|
63
|
+
nextIcon.color = iconSpecialColor;
|
|
64
|
+
}
|
|
65
|
+
else if ('color' in nextIcon) {
|
|
66
|
+
delete nextIcon.color;
|
|
67
|
+
}
|
|
68
|
+
nextEl = { ...nextEl, icon: nextIcon };
|
|
35
69
|
}
|
|
36
|
-
return
|
|
70
|
+
return nextEl;
|
|
37
71
|
};
|
|
38
72
|
const traverse = (children = []) => children.map(el => {
|
|
39
73
|
if (!el)
|
|
@@ -46,97 +80,11 @@ function backgroundChange(bg, layout) {
|
|
|
46
80
|
}
|
|
47
81
|
return applySpecialColor(el);
|
|
48
82
|
});
|
|
83
|
+
const nextChildren = traverse(layout.children || []);
|
|
49
84
|
return {
|
|
50
85
|
...layout,
|
|
51
86
|
backgroundImage: bg.imgUrl,
|
|
52
87
|
fontColor: bg.fontColor || layout.fontColor,
|
|
53
|
-
children:
|
|
88
|
+
children: nextChildren,
|
|
54
89
|
};
|
|
55
90
|
}
|
|
56
|
-
exports.DEFAULT_DECOR_COLOR = '#94a3b8';
|
|
57
|
-
const resolveSpecialStyle = (element, background) => {
|
|
58
|
-
var _a;
|
|
59
|
-
if (!background)
|
|
60
|
-
return {};
|
|
61
|
-
const keys = [];
|
|
62
|
-
if (element.binding)
|
|
63
|
-
keys.push(String(element.binding));
|
|
64
|
-
if (element.id)
|
|
65
|
-
keys.push(String(element.id));
|
|
66
|
-
if (element.type === 'icon')
|
|
67
|
-
keys.push('icon');
|
|
68
|
-
if (element.type === 'custom')
|
|
69
|
-
keys.push('decor');
|
|
70
|
-
const matched = (_a = background.specialColors) === null || _a === void 0 ? void 0 : _a.find(sc => {
|
|
71
|
-
const names = toNameArray(sc.name);
|
|
72
|
-
return names.some(n => keys.some(k => k === null || k === void 0 ? void 0 : k.startsWith(n)));
|
|
73
|
-
});
|
|
74
|
-
if (!matched)
|
|
75
|
-
return {};
|
|
76
|
-
if (element.type === 'custom') {
|
|
77
|
-
return { backgroundColor: matched.color };
|
|
78
|
-
}
|
|
79
|
-
return { color: matched.color };
|
|
80
|
-
};
|
|
81
|
-
exports.resolveSpecialStyle = resolveSpecialStyle;
|
|
82
|
-
const applySpecialStyle = (el, background = null, options = {}) => {
|
|
83
|
-
const specialStyle = (0, exports.resolveSpecialStyle)(el, background);
|
|
84
|
-
const baseStyle = { ...(el.style || {}) };
|
|
85
|
-
const isCustom = el.type === 'custom';
|
|
86
|
-
const hasExplicit = isCustom
|
|
87
|
-
? Boolean(baseStyle.backgroundColor || baseStyle.background)
|
|
88
|
-
: baseStyle.color !== undefined && baseStyle.color !== null;
|
|
89
|
-
const overrideExisting = options.overrideExisting === true;
|
|
90
|
-
const hasSpecial = Object.keys(specialStyle).length > 0;
|
|
91
|
-
const defaultDecorColor = options.defaultDecorColor || exports.DEFAULT_DECOR_COLOR;
|
|
92
|
-
if (hasSpecial) {
|
|
93
|
-
if (hasExplicit && !overrideExisting)
|
|
94
|
-
return el;
|
|
95
|
-
return { ...el, style: { ...baseStyle, ...specialStyle } };
|
|
96
|
-
}
|
|
97
|
-
if (overrideExisting && hasExplicit) {
|
|
98
|
-
const nextStyle = { ...baseStyle };
|
|
99
|
-
if (isCustom) {
|
|
100
|
-
nextStyle.backgroundColor = (background === null || background === void 0 ? void 0 : background.mainColor) || defaultDecorColor;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
delete nextStyle.color;
|
|
104
|
-
}
|
|
105
|
-
return { ...el, style: nextStyle };
|
|
106
|
-
}
|
|
107
|
-
return el;
|
|
108
|
-
};
|
|
109
|
-
exports.applySpecialStyle = applySpecialStyle;
|
|
110
|
-
const applyBackground = (layout, background, _options = {}) => {
|
|
111
|
-
var _a;
|
|
112
|
-
const bgId = Number(background.id);
|
|
113
|
-
const payload = {
|
|
114
|
-
id: Number.isFinite(bgId) ? bgId : 0,
|
|
115
|
-
name: background.name,
|
|
116
|
-
imgUrl: background.imageUrl,
|
|
117
|
-
fontColor: background.mainColor,
|
|
118
|
-
fontColorExtra: ((_a = background.specialColors) === null || _a === void 0 ? void 0 : _a.map(sc => ({
|
|
119
|
-
name: sc.name,
|
|
120
|
-
color: sc.color,
|
|
121
|
-
}))) || [],
|
|
122
|
-
};
|
|
123
|
-
return backgroundChange(payload, layout);
|
|
124
|
-
};
|
|
125
|
-
exports.applyBackground = applyBackground;
|
|
126
|
-
const updateElementsStyle = (layout, targetIds, updates) => {
|
|
127
|
-
const targets = new Set(targetIds);
|
|
128
|
-
return {
|
|
129
|
-
...layout,
|
|
130
|
-
children: layout.children.map(el => targets.has(el.id)
|
|
131
|
-
? { ...el, style: { ...(el.style || {}), ...updates } }
|
|
132
|
-
: el),
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
exports.updateElementsStyle = updateElementsStyle;
|
|
136
|
-
const setElementVisible = (layout, key, visible) => {
|
|
137
|
-
return layout.map(la => ({
|
|
138
|
-
...la,
|
|
139
|
-
children: la.children.map(el => (el.key === key ? { ...el, visible } : el)),
|
|
140
|
-
}));
|
|
141
|
-
};
|
|
142
|
-
exports.setElementVisible = setElementVisible;
|
package/dist/render/helpers.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = void 0;
|
|
3
|
+
exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextValueStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = void 0;
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
const layout_1 = require("../layout");
|
|
6
|
+
const data_1 = require("../data");
|
|
6
7
|
const buildWrapperStyle = (el, unit = 'px') => {
|
|
7
8
|
const abs = (0, layout_1.getAbsLayout)(el);
|
|
8
9
|
if (!abs)
|
|
@@ -22,9 +23,6 @@ const buildCardStyle = (layout, unit = 'px') => ({
|
|
|
22
23
|
width: (0, helpers_1.addUnit)(layout.width, unit),
|
|
23
24
|
height: (0, helpers_1.addUnit)(layout.height, unit),
|
|
24
25
|
color: layout.fontColor,
|
|
25
|
-
borderRadius: layout.borderRadius !== undefined
|
|
26
|
-
? (0, helpers_1.addUnit)(layout.borderRadius, unit)
|
|
27
|
-
: undefined,
|
|
28
26
|
padding: layout.padding !== undefined ? (0, helpers_1.addUnit)(layout.padding, unit) : undefined,
|
|
29
27
|
position: 'relative',
|
|
30
28
|
overflow: 'hidden',
|
|
@@ -34,11 +32,12 @@ const buildCardStyle = (layout, unit = 'px') => ({
|
|
|
34
32
|
exports.buildCardStyle = buildCardStyle;
|
|
35
33
|
const buildBackgroundStyle = (layout, unit = 'px') => ({
|
|
36
34
|
zIndex: layout.backgroundZIndex,
|
|
37
|
-
|
|
38
|
-
? (0, helpers_1.addUnit)(layout.
|
|
39
|
-
:
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
width: layout.backgroundWidth
|
|
36
|
+
? (0, helpers_1.addUnit)(layout.backgroundWidth, unit)
|
|
37
|
+
: '100%',
|
|
38
|
+
height: layout.backgroundHeight
|
|
39
|
+
? (0, helpers_1.addUnit)(layout.backgroundHeight, unit)
|
|
40
|
+
: '100%',
|
|
42
41
|
position: 'absolute',
|
|
43
42
|
left: 0,
|
|
44
43
|
top: 0,
|
|
@@ -75,23 +74,44 @@ const buildTextContentStyle = (el, unit = 'px') => {
|
|
|
75
74
|
return style;
|
|
76
75
|
};
|
|
77
76
|
exports.buildTextContentStyle = buildTextContentStyle;
|
|
78
|
-
const
|
|
77
|
+
const buildTextValueStyle = (el, unit = 'px') => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const style = {
|
|
80
|
+
letterSpacing: ((_a = el.style) === null || _a === void 0 ? void 0 : _a.letterSpacing) !== undefined && ((_b = el.style) === null || _b === void 0 ? void 0 : _b.letterSpacing) !== null
|
|
81
|
+
? (0, helpers_1.addUnit)(el.style.letterSpacing, unit)
|
|
82
|
+
: '0',
|
|
83
|
+
};
|
|
84
|
+
return style;
|
|
85
|
+
};
|
|
86
|
+
exports.buildTextValueStyle = buildTextValueStyle;
|
|
87
|
+
const buildImageContentStyle = (el, unit = 'px') => {
|
|
88
|
+
var _a, _b, _c, _d;
|
|
79
89
|
const style = { ...(el.style || {}) };
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
style.borderWidth =
|
|
91
|
+
((_a = el.style) === null || _a === void 0 ? void 0 : _a.borderWidth) !== undefined && ((_b = el.style) === null || _b === void 0 ? void 0 : _b.borderWidth) !== null
|
|
92
|
+
? (0, helpers_1.addUnit)(el.style.borderWidth, unit)
|
|
93
|
+
: '0';
|
|
94
|
+
style.borderRadius =
|
|
95
|
+
((_c = el.style) === null || _c === void 0 ? void 0 : _c.borderRadius) !== undefined && ((_d = el.style) === null || _d === void 0 ? void 0 : _d.borderRadius) !== null
|
|
96
|
+
? (0, helpers_1.addUnit)(el.style.borderRadius, unit)
|
|
97
|
+
: '0';
|
|
87
98
|
return style;
|
|
88
99
|
};
|
|
89
100
|
exports.buildImageContentStyle = buildImageContentStyle;
|
|
90
|
-
const getTextValue = (el) =>
|
|
91
|
-
?
|
|
92
|
-
|
|
101
|
+
const getTextValue = (el, data) => {
|
|
102
|
+
const bound = el.binding && data ? (0, data_1.resolveBindingValue)(el.binding, data) : undefined;
|
|
103
|
+
const val = bound !== undefined && bound !== null
|
|
104
|
+
? bound
|
|
105
|
+
: el.defaultValue !== undefined && el.defaultValue !== null
|
|
106
|
+
? el.defaultValue
|
|
107
|
+
: '';
|
|
108
|
+
return `${val !== null && val !== void 0 ? val : ''}`;
|
|
109
|
+
};
|
|
93
110
|
exports.getTextValue = getTextValue;
|
|
94
|
-
const getImageSrc = (el) =>
|
|
111
|
+
const getImageSrc = (el, data) => {
|
|
112
|
+
const bound = el.binding && data ? (0, data_1.resolveBindingValue)(el.binding, data) : undefined;
|
|
113
|
+
return bound || el.defaultUrl || el.defaultValue || '';
|
|
114
|
+
};
|
|
95
115
|
exports.getImageSrc = getImageSrc;
|
|
96
116
|
const getIconName = (el) => (el.name || el.defaultValue || '');
|
|
97
117
|
exports.getIconName = getIconName;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleSpecialFields = handleSpecialFields;
|
|
4
|
+
exports.processCardLayout = processCardLayout;
|
|
5
|
+
function handleSpecialFields(data) {
|
|
6
|
+
var _a;
|
|
7
|
+
const user = (_a = data.user) !== null && _a !== void 0 ? _a : {};
|
|
8
|
+
return {
|
|
9
|
+
...data,
|
|
10
|
+
user: {
|
|
11
|
+
...user,
|
|
12
|
+
// 1. 构造 baseCompanyDuty
|
|
13
|
+
baseCompanyDuty: user.company && user.duty
|
|
14
|
+
? `${user.company} ${user.duty}`
|
|
15
|
+
: user.baseCompanyDuty,
|
|
16
|
+
// 2. 构造 moreCardInfo.company
|
|
17
|
+
moreCardInfo: user.moreCardInfo
|
|
18
|
+
? {
|
|
19
|
+
...user.moreCardInfo,
|
|
20
|
+
company: Array.isArray(user.moreCardInfo.company)
|
|
21
|
+
? user.moreCardInfo.company.map(item => `${item.company} ${item.duty}`)
|
|
22
|
+
: user.moreCardInfo.company,
|
|
23
|
+
}
|
|
24
|
+
: user.moreCardInfo,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const SHOW_KEYS = new Set([
|
|
29
|
+
"company_duty_custom",
|
|
30
|
+
"company_duty_1",
|
|
31
|
+
"company_duty_2",
|
|
32
|
+
]);
|
|
33
|
+
const HIDE_KEYS = new Set(["company", "duty"]);
|
|
34
|
+
function getCompanyLen(data) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const company = (_b = (_a = data === null || data === void 0 ? void 0 : data.user) === null || _a === void 0 ? void 0 : _a.moreCardInfo) === null || _b === void 0 ? void 0 : _b.company;
|
|
37
|
+
return Array.isArray(company) ? company.length : 0;
|
|
38
|
+
}
|
|
39
|
+
function updateElementsVisible(elements, showMore) {
|
|
40
|
+
if (!elements)
|
|
41
|
+
return elements;
|
|
42
|
+
return elements.map((el) => {
|
|
43
|
+
// 先递归处理 layout-panel 的 children
|
|
44
|
+
let next = el;
|
|
45
|
+
if (el.type === "layout-panel") {
|
|
46
|
+
next = {
|
|
47
|
+
...el,
|
|
48
|
+
children: updateElementsVisible(el.children, showMore),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const key = next.key;
|
|
52
|
+
if (!key)
|
|
53
|
+
return next;
|
|
54
|
+
// showMore=true: 显示 company_duty_*,隐藏 company/duty
|
|
55
|
+
// showMore=false: 反过来
|
|
56
|
+
if (SHOW_KEYS.has(key)) {
|
|
57
|
+
return { ...next, visible: showMore };
|
|
58
|
+
}
|
|
59
|
+
if (HIDE_KEYS.has(key)) {
|
|
60
|
+
return { ...next, visible: !showMore };
|
|
61
|
+
}
|
|
62
|
+
return next;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 根据 user.moreCardInfo.company 数组长度切换元素 visible:
|
|
67
|
+
* - length > 0: key in [company_duty_custom, company_duty_1, company_duty_2] => visible=true
|
|
68
|
+
* key in [company, duty] => visible=false
|
|
69
|
+
* - length === 0: 反之
|
|
70
|
+
*/
|
|
71
|
+
function processCardLayout(layout, data) {
|
|
72
|
+
const companyLen = getCompanyLen(data);
|
|
73
|
+
const showMore = companyLen > 0;
|
|
74
|
+
return layout.map((card) => {
|
|
75
|
+
var _a;
|
|
76
|
+
return ({
|
|
77
|
+
...card,
|
|
78
|
+
children: ((_a = updateElementsVisible(card.children, showMore)) !== null && _a !== void 0 ? _a : card.children),
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|