km-card-layout-core 0.1.27 → 0.1.30
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/dist/index.js +4 -1
- package/dist/render/helpers.js +14 -2
- package/dist/render/tool.js +23 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/render/helpers.ts +24 -2
- package/render/tool.ts +34 -0
- package/types.d.ts +16 -1
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
17
|
+
exports.processCardLayout = exports.handleSpecialFields = exports.setElementVisible = exports.buildRenderData = 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
18
|
/**
|
|
19
19
|
* Core exports for card layout helpers.
|
|
20
20
|
* Platform-agnostic utilities shared by web/mini-program renderers.
|
|
@@ -53,6 +53,9 @@ Object.defineProperty(exports, "getTextValue", { enumerable: true, get: function
|
|
|
53
53
|
Object.defineProperty(exports, "getImageSrc", { enumerable: true, get: function () { return helpers_2.getImageSrc; } });
|
|
54
54
|
Object.defineProperty(exports, "getIconName", { enumerable: true, get: function () { return helpers_2.getIconName; } });
|
|
55
55
|
Object.defineProperty(exports, "buildTextIconMeta", { enumerable: true, get: function () { return helpers_2.buildTextIconMeta; } });
|
|
56
|
+
var tool_1 = require("./render/tool");
|
|
57
|
+
Object.defineProperty(exports, "buildRenderData", { enumerable: true, get: function () { return tool_1.buildRenderData; } });
|
|
58
|
+
Object.defineProperty(exports, "setElementVisible", { enumerable: true, get: function () { return tool_1.setElementVisible; } });
|
|
56
59
|
var init_1 = require("./render/init");
|
|
57
60
|
Object.defineProperty(exports, "handleSpecialFields", { enumerable: true, get: function () { return init_1.handleSpecialFields; } });
|
|
58
61
|
Object.defineProperty(exports, "processCardLayout", { enumerable: true, get: function () { return init_1.processCardLayout; } });
|
package/dist/render/helpers.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
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 = exports.mockBaseCompanyDutyTemplateItem = void 0;
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
const layout_1 = require("../layout");
|
|
6
6
|
const data_1 = require("../data");
|
|
7
|
+
exports.mockBaseCompanyDutyTemplateItem = {
|
|
8
|
+
id: -1,
|
|
9
|
+
name: 'company_duty_custom',
|
|
10
|
+
bind: 'user.baseCompanyDuty',
|
|
11
|
+
key: 'company_duty_custom',
|
|
12
|
+
type: 'text',
|
|
13
|
+
cate: 0,
|
|
14
|
+
};
|
|
7
15
|
const buildWrapperStyle = (el, unit = 'px') => {
|
|
8
16
|
const abs = (0, layout_1.getAbsLayout)(el);
|
|
9
17
|
if (!abs)
|
|
@@ -99,7 +107,11 @@ const buildImageContentStyle = (el, unit = 'px') => {
|
|
|
99
107
|
};
|
|
100
108
|
exports.buildImageContentStyle = buildImageContentStyle;
|
|
101
109
|
const getTextValue = (el, data) => {
|
|
102
|
-
|
|
110
|
+
// 如果 id 匹配,则使用 mock 的 binding,否则用原来的
|
|
111
|
+
const binding = el.id === String(exports.mockBaseCompanyDutyTemplateItem.id)
|
|
112
|
+
? exports.mockBaseCompanyDutyTemplateItem.bind
|
|
113
|
+
: el.binding;
|
|
114
|
+
const bound = binding && data ? (0, data_1.resolveBindingValue)(binding, data) : undefined;
|
|
103
115
|
const val = bound !== undefined && bound !== null
|
|
104
116
|
? bound
|
|
105
117
|
: el.defaultValue !== undefined && el.defaultValue !== null
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setElementVisible = void 0;
|
|
4
|
+
exports.buildRenderData = buildRenderData;
|
|
5
|
+
const bindings_1 = require("../bindings");
|
|
6
|
+
const changeBackground_1 = require("../ops/changeBackground");
|
|
7
|
+
const setElementVisible = (layout, key, visible) => {
|
|
8
|
+
return layout.map(la => ({
|
|
9
|
+
...la,
|
|
10
|
+
children: la.children.map(el => (el.key === key ? { ...el, visible } : el)),
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
exports.setElementVisible = setElementVisible;
|
|
14
|
+
function buildRenderData(layout, items, config) {
|
|
15
|
+
// 绑定数据
|
|
16
|
+
let renderLayout = (0, bindings_1.applyItemCollectBindings)(layout, items);
|
|
17
|
+
// 设置显示逻辑
|
|
18
|
+
renderLayout = (0, exports.setElementVisible)(renderLayout, 'image', config.showAvatar);
|
|
19
|
+
renderLayout = (0, exports.setElementVisible)(renderLayout, 'logo', config.showLogo);
|
|
20
|
+
// 设置背景
|
|
21
|
+
renderLayout = renderLayout.map((la, index) => config.currentBg[index] ? (0, changeBackground_1.backgroundChange)(config.currentBg[index], la) : la);
|
|
22
|
+
return renderLayout;
|
|
23
|
+
}
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/render/helpers.ts
CHANGED
|
@@ -7,9 +7,19 @@ import type {
|
|
|
7
7
|
IconElement,
|
|
8
8
|
ImageElement,
|
|
9
9
|
LayoutPanelElement,
|
|
10
|
+
TemplateItem,
|
|
10
11
|
TextElement,
|
|
11
12
|
} from '../interface';
|
|
12
13
|
|
|
14
|
+
export const mockBaseCompanyDutyTemplateItem: TemplateItem = {
|
|
15
|
+
id: -1,
|
|
16
|
+
name: 'company_duty_custom',
|
|
17
|
+
bind: 'user.baseCompanyDuty',
|
|
18
|
+
key: 'company_duty_custom',
|
|
19
|
+
type: 'text',
|
|
20
|
+
cate: 0,
|
|
21
|
+
};
|
|
22
|
+
|
|
13
23
|
export const buildWrapperStyle = (
|
|
14
24
|
el: CardElement,
|
|
15
25
|
unit: 'px' | 'rpx' = 'px'
|
|
@@ -124,18 +134,30 @@ export const buildImageContentStyle = (
|
|
|
124
134
|
return style;
|
|
125
135
|
};
|
|
126
136
|
|
|
127
|
-
export const getTextValue = (
|
|
137
|
+
export const getTextValue = (
|
|
138
|
+
el: TextElement,
|
|
139
|
+
data?: Record<string, any>
|
|
140
|
+
) => {
|
|
141
|
+
// 如果 id 匹配,则使用 mock 的 binding,否则用原来的
|
|
142
|
+
const binding =
|
|
143
|
+
el.id === String(mockBaseCompanyDutyTemplateItem.id)
|
|
144
|
+
? mockBaseCompanyDutyTemplateItem.bind
|
|
145
|
+
: el.binding;
|
|
146
|
+
|
|
128
147
|
const bound =
|
|
129
|
-
|
|
148
|
+
binding && data ? resolveBindingValue(binding, data) : undefined;
|
|
149
|
+
|
|
130
150
|
const val =
|
|
131
151
|
bound !== undefined && bound !== null
|
|
132
152
|
? bound
|
|
133
153
|
: el.defaultValue !== undefined && el.defaultValue !== null
|
|
134
154
|
? el.defaultValue
|
|
135
155
|
: '';
|
|
156
|
+
|
|
136
157
|
return `${val ?? ''}`;
|
|
137
158
|
};
|
|
138
159
|
|
|
160
|
+
|
|
139
161
|
export const getImageSrc = (el: ImageElement, data?: Record<string, any>) => {
|
|
140
162
|
const bound =
|
|
141
163
|
el.binding && data ? resolveBindingValue(el.binding, data) : undefined;
|
package/render/tool.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { applyItemCollectBindings } from '../bindings';
|
|
2
|
+
import { CardLayoutSchema, TemplateItem } from '../interface';
|
|
3
|
+
import { backgroundChange } from '../ops/changeBackground';
|
|
4
|
+
import { Config } from '../types';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const setElementVisible = (
|
|
8
|
+
layout: CardLayoutSchema[],
|
|
9
|
+
key: string,
|
|
10
|
+
visible: boolean
|
|
11
|
+
): CardLayoutSchema[] => {
|
|
12
|
+
return layout.map(la => ({
|
|
13
|
+
...la,
|
|
14
|
+
children: la.children.map(el => (el.key === key ? { ...el, visible } : el)),
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export function buildRenderData(
|
|
20
|
+
layout: CardLayoutSchema[],
|
|
21
|
+
items: TemplateItem[],
|
|
22
|
+
config: Config
|
|
23
|
+
): CardLayoutSchema[] {
|
|
24
|
+
// 绑定数据
|
|
25
|
+
let renderLayout = applyItemCollectBindings(layout, items);
|
|
26
|
+
// 设置显示逻辑
|
|
27
|
+
renderLayout = setElementVisible(renderLayout, 'image', config.showAvatar);
|
|
28
|
+
renderLayout = setElementVisible(renderLayout, 'logo', config.showLogo);
|
|
29
|
+
// 设置背景
|
|
30
|
+
renderLayout = renderLayout.map((la, index) =>
|
|
31
|
+
config.currentBg[index] ? backgroundChange(config.currentBg[index], la) : la
|
|
32
|
+
);
|
|
33
|
+
return renderLayout;
|
|
34
|
+
}
|
package/types.d.ts
CHANGED
|
@@ -143,5 +143,20 @@ export function handleSpecialFields(data: { user: Record<string, any> }): {
|
|
|
143
143
|
|
|
144
144
|
export function processCardLayout(
|
|
145
145
|
layout: CardLayoutSchema[],
|
|
146
|
-
data:
|
|
146
|
+
data: any
|
|
147
|
+
): CardLayoutSchema[];
|
|
148
|
+
|
|
149
|
+
export type Config = {
|
|
150
|
+
showAvatar: boolean;
|
|
151
|
+
showLogo: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* 当前背景 (0 为正面背景 1 为背面背景)
|
|
154
|
+
*/
|
|
155
|
+
currentBg: TemplateBackground[];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export function buildRenderData(
|
|
159
|
+
layout: CardLayoutSchema[],
|
|
160
|
+
items: TemplateItem[],
|
|
161
|
+
config: Config
|
|
147
162
|
): CardLayoutSchema[];
|