km-card-layout-component-miniprogram 0.1.7 → 0.1.9
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/example/pages/home/index.js +107 -16
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.js +27 -0
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.wxml +5 -0
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.wxss +14 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.js +39 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.wxml +5 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.wxss +37 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.js +31 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.wxml +8 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.wxss +10 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.js +47 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.wxml +29 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.wxss +59 -0
- package/miniprogram_dist/components/card-layout/index.js +16 -201
- package/miniprogram_dist/components/card-layout/index.json +7 -1
- package/miniprogram_dist/components/card-layout/index.wxml +15 -63
- package/miniprogram_dist/components/card-layout/index.wxss +0 -63
- package/miniprogram_dist/utils/card-schema.js +12 -3
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +78 -0
- package/miniprogram_dist/vendor/km-card-layout-core/data.js +38 -0
- package/miniprogram_dist/vendor/km-card-layout-core/helpers.js +72 -0
- package/miniprogram_dist/vendor/km-card-layout-core/index.js +46 -367
- package/miniprogram_dist/vendor/km-card-layout-core/interface/index.js +1 -1
- package/miniprogram_dist/vendor/km-card-layout-core/layout.js +117 -0
- package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +142 -0
- package/miniprogram_dist/vendor/km-card-layout-core/render/helpers.js +133 -0
- package/miniprogram_dist/vendor/km-card-layout-core/render/tool.js +16 -0
- package/miniprogram_dist/vendor/km-card-layout-core/utils.js +23 -130
- package/package.json +1 -1
- package/script/sync-core.js +13 -2
- package/src/components/card-layout/elements/custom-element/index.json +3 -0
- package/src/components/card-layout/elements/custom-element/index.ts +30 -0
- package/src/components/card-layout/elements/custom-element/index.wxml +5 -0
- package/src/components/card-layout/elements/custom-element/index.wxss +14 -0
- package/src/components/card-layout/elements/icon-element/index.json +3 -0
- package/src/components/card-layout/elements/icon-element/index.ts +42 -0
- package/src/components/card-layout/elements/icon-element/index.wxml +5 -0
- package/src/components/card-layout/elements/icon-element/index.wxss +37 -0
- package/src/components/card-layout/elements/image-element/index.json +3 -0
- package/src/components/card-layout/elements/image-element/index.ts +35 -0
- package/src/components/card-layout/elements/image-element/index.wxml +8 -0
- package/src/components/card-layout/elements/image-element/index.wxss +10 -0
- package/src/components/card-layout/elements/text-element/index.json +3 -0
- package/src/components/card-layout/elements/text-element/index.ts +52 -0
- package/src/components/card-layout/elements/text-element/index.wxml +29 -0
- package/src/components/card-layout/elements/text-element/index.wxss +59 -0
- package/src/components/card-layout/index.json +7 -1
- package/src/components/card-layout/index.ts +30 -296
- package/src/components/card-layout/index.wxml +15 -63
- package/src/components/card-layout/index.wxss +0 -63
- package/src/utils/card-schema.ts +11 -4
- package/src/vendor/km-card-layout-core/bindings.ts +87 -0
- package/src/vendor/km-card-layout-core/data.ts +39 -0
- package/src/vendor/km-card-layout-core/helpers.ts +76 -0
- package/src/vendor/km-card-layout-core/index.ts +53 -460
- package/src/vendor/km-card-layout-core/interface/context.ts +6 -0
- package/src/vendor/km-card-layout-core/interface/data/payload.ts +1 -0
- package/src/vendor/km-card-layout-core/interface/index.ts +2 -2
- package/src/vendor/km-card-layout-core/layout.ts +129 -0
- package/src/vendor/km-card-layout-core/ops/changeBackground.ts +179 -0
- package/src/vendor/km-card-layout-core/render/helpers.ts +144 -0
- package/src/vendor/km-card-layout-core/render/tool.ts +21 -0
- package/src/vendor/km-card-layout-core/types.d.ts +166 -15
- package/src/vendor/km-card-layout-core/utils.ts +13 -141
- package/src/vendor/km-card-layout-core/interface/render.ts +0 -52
- /package/miniprogram_dist/vendor/km-card-layout-core/interface/{render.js → context.js} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const index_1 = require("../../vendor/km-card-layout-core/index");
|
|
4
|
-
const icon_map_1 = require("./icon-map");
|
|
5
4
|
const ensureArray = (input) => {
|
|
6
5
|
if (!input)
|
|
7
6
|
return [];
|
|
@@ -12,207 +11,27 @@ const pickCardId = (layout, idx) => {
|
|
|
12
11
|
return layout.name || layout.id;
|
|
13
12
|
return `card-${idx}`;
|
|
14
13
|
};
|
|
15
|
-
const
|
|
16
|
-
const buildCardStyle = (layout, unit) => (0, index_1.styleObjectToString)({
|
|
17
|
-
width: withUnit(layout.width, unit),
|
|
18
|
-
height: withUnit(layout.height, unit),
|
|
19
|
-
color: layout.fontColor,
|
|
20
|
-
borderRadius: layout.borderRadius !== undefined
|
|
21
|
-
? withUnit(layout.borderRadius, unit)
|
|
22
|
-
: undefined,
|
|
23
|
-
padding: layout.padding !== undefined ? withUnit(layout.padding, unit) : undefined,
|
|
24
|
-
position: 'relative',
|
|
25
|
-
overflow: 'hidden',
|
|
26
|
-
boxSizing: 'border-box',
|
|
27
|
-
backgroundColor: 'transparent',
|
|
28
|
-
}, unit);
|
|
29
|
-
const buildBackgroundStyle = (layout, unit) => (0, index_1.styleObjectToString)({
|
|
30
|
-
zIndex: layout.backgroundZIndex,
|
|
31
|
-
borderRadius: layout.borderRadius !== undefined
|
|
32
|
-
? withUnit(layout.borderRadius, unit)
|
|
33
|
-
: undefined,
|
|
34
|
-
width: '100%',
|
|
35
|
-
height: '100%',
|
|
36
|
-
position: 'absolute',
|
|
37
|
-
left: 0,
|
|
38
|
-
top: 0,
|
|
39
|
-
}, unit);
|
|
40
|
-
const buildWrapperStyle = (el, unit) => {
|
|
41
|
-
if (!el.layout || el.layout.mode !== 'absolute')
|
|
42
|
-
return '';
|
|
43
|
-
return (0, index_1.styleObjectToString)({
|
|
44
|
-
position: 'absolute',
|
|
45
|
-
left: withUnit(el.layout.x, unit),
|
|
46
|
-
top: withUnit(el.layout.y, unit),
|
|
47
|
-
width: withUnit(el.layout.width, unit),
|
|
48
|
-
height: withUnit(el.layout.height, unit),
|
|
49
|
-
zIndex: el.layout.zIndex,
|
|
50
|
-
boxSizing: 'border-box',
|
|
51
|
-
display: 'flex',
|
|
52
|
-
alignItems: 'center',
|
|
53
|
-
}, unit);
|
|
54
|
-
};
|
|
55
|
-
const buildPanelContentStyle = (el, unit) => (0, index_1.styleObjectToString)({
|
|
56
|
-
position: 'relative',
|
|
57
|
-
width: '100%',
|
|
58
|
-
height: '100%',
|
|
59
|
-
display: 'block',
|
|
60
|
-
boxSizing: 'border-box',
|
|
61
|
-
...(el.style || {}),
|
|
62
|
-
}, unit);
|
|
63
|
-
const buildTextContentStyle = (el, unit) => {
|
|
64
|
-
var _a, _b, _c;
|
|
65
|
-
const textAlign = ((_a = el.style) === null || _a === void 0 ? void 0 : _a.textAlign) || el.align || undefined;
|
|
66
|
-
const style = {
|
|
67
|
-
...el.style,
|
|
68
|
-
whiteSpace: 'pre-wrap',
|
|
69
|
-
wordBreak: 'break-word',
|
|
70
|
-
lineHeight: ((_b = el.style) === null || _b === void 0 ? void 0 : _b.lineHeight) !== undefined && ((_c = el.style) === null || _c === void 0 ? void 0 : _c.lineHeight) !== null
|
|
71
|
-
? el.style.lineHeight
|
|
72
|
-
: '1.2',
|
|
73
|
-
display: 'inline-flex',
|
|
74
|
-
alignItems: 'center',
|
|
75
|
-
};
|
|
76
|
-
if (textAlign)
|
|
77
|
-
style.textAlign = textAlign;
|
|
78
|
-
return (0, index_1.styleObjectToString)(style, unit);
|
|
79
|
-
};
|
|
80
|
-
const buildBaseContentStyle = (el, unit) => (0, index_1.styleObjectToString)({
|
|
81
|
-
...(el.style || {}),
|
|
82
|
-
boxSizing: 'border-box',
|
|
83
|
-
}, unit);
|
|
84
|
-
const mapIconGlyph = (name, fallback) => {
|
|
85
|
-
if (!name)
|
|
86
|
-
return fallback;
|
|
87
|
-
const glyph = icon_map_1.ICON_CODE_MAP[name];
|
|
88
|
-
if (glyph)
|
|
89
|
-
return String.fromCharCode(parseInt(glyph, 16));
|
|
90
|
-
return fallback || name;
|
|
91
|
-
};
|
|
92
|
-
const buildTextIcon = (el, unit) => {
|
|
93
|
-
var _a, _b, _c, _d, _e;
|
|
94
|
-
const icon = el.icon;
|
|
95
|
-
if (!icon || icon.enable === false)
|
|
96
|
-
return undefined;
|
|
97
|
-
const style = icon.style || 'fill';
|
|
98
|
-
const baseName = el.key || el.binding || el.id;
|
|
99
|
-
let name;
|
|
100
|
-
if (style === 'dot')
|
|
101
|
-
name = 'round';
|
|
102
|
-
else if (style === 'line')
|
|
103
|
-
name = baseName ? `${baseName}-line` : undefined;
|
|
104
|
-
else
|
|
105
|
-
name = baseName || undefined;
|
|
106
|
-
if (!name)
|
|
107
|
-
return undefined;
|
|
108
|
-
const size = icon.size !== undefined && icon.size !== null
|
|
109
|
-
? icon.size
|
|
110
|
-
: (_a = el.style) === null || _a === void 0 ? void 0 : _a.fontSize;
|
|
111
|
-
const gap = icon.gap !== undefined && icon.gap !== null ? icon.gap : 4;
|
|
112
|
-
const color = (_d = (_b = icon.color) !== null && _b !== void 0 ? _b : (_c = el.style) === null || _c === void 0 ? void 0 : _c.color) !== null && _d !== void 0 ? _d : undefined;
|
|
113
|
-
const text = mapIconGlyph(name, name);
|
|
114
|
-
return {
|
|
115
|
-
name,
|
|
116
|
-
text,
|
|
117
|
-
size: size !== undefined ? withUnit(size, unit) : undefined,
|
|
118
|
-
gap: gap !== undefined ? withUnit(gap, unit) : undefined,
|
|
119
|
-
wrapperStyle: (0, index_1.styleObjectToString)({
|
|
120
|
-
display: 'inline-flex',
|
|
121
|
-
alignItems: 'center',
|
|
122
|
-
height: ((_e = el.style) === null || _e === void 0 ? void 0 : _e.lineHeight) || 'auto',
|
|
123
|
-
}, unit),
|
|
124
|
-
color,
|
|
125
|
-
align: icon.align || 'left',
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
const buildRenderNode = (el, data, unit) => {
|
|
129
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
130
|
-
if (!el || el.visible === false)
|
|
131
|
-
return null;
|
|
132
|
-
const wrapperStyle = buildWrapperStyle(el, unit);
|
|
14
|
+
const decorateElements = (children = []) => (children || []).map(el => {
|
|
133
15
|
if (el.type === 'layout-panel') {
|
|
134
16
|
const panel = el;
|
|
135
17
|
return {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
children: buildRenderNodes(panel.children || [], data, unit),
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
if (el.type === 'text') {
|
|
144
|
-
const textValue = (_b = (_a = (0, index_1.resolveBindingValue)(el.binding, data)) !== null && _a !== void 0 ? _a : el.defaultValue) !== null && _b !== void 0 ? _b : '';
|
|
145
|
-
return {
|
|
146
|
-
id: el.id,
|
|
147
|
-
type: el.type,
|
|
148
|
-
wrapperStyle,
|
|
149
|
-
contentStyle: buildTextContentStyle(el, unit),
|
|
150
|
-
text: `${textValue}`,
|
|
151
|
-
icon: buildTextIcon(el, unit),
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
if (el.type === 'image') {
|
|
155
|
-
const style = { ...(el.style || {}) };
|
|
156
|
-
const borderWidth = Number(style.borderWidth);
|
|
157
|
-
if (Number.isFinite(borderWidth) && borderWidth > 0) {
|
|
158
|
-
if (!style.borderStyle)
|
|
159
|
-
style.borderStyle = 'solid';
|
|
160
|
-
if (!style.borderColor)
|
|
161
|
-
style.borderColor = '#000000';
|
|
162
|
-
}
|
|
163
|
-
const src = (_e = (_d = (_c = (0, index_1.resolveBindingValue)(el.binding, data)) !== null && _c !== void 0 ? _c : el.defaultUrl) !== null && _d !== void 0 ? _d : el.defaultValue) !== null && _e !== void 0 ? _e : '';
|
|
164
|
-
const mode = el.fit === 'contain' ? 'aspectFit' : 'aspectFill';
|
|
165
|
-
return {
|
|
166
|
-
id: el.id,
|
|
167
|
-
type: el.type,
|
|
168
|
-
wrapperStyle,
|
|
169
|
-
contentStyle: (0, index_1.styleObjectToString)(style, unit),
|
|
170
|
-
src,
|
|
171
|
-
mode,
|
|
18
|
+
...panel,
|
|
19
|
+
wrapperStyle: (0, index_1.styleObjectToString)((0, index_1.buildWrapperStyle)(panel, 'rpx'), 'rpx'),
|
|
20
|
+
contentStyle: (0, index_1.styleObjectToString)((0, index_1.buildPanelContentStyle)(panel, 'rpx'), 'rpx'),
|
|
21
|
+
children: decorateElements(panel.children || []),
|
|
172
22
|
};
|
|
173
23
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
if (el.type === 'custom') {
|
|
187
|
-
return {
|
|
188
|
-
id: el.id,
|
|
189
|
-
type: el.type,
|
|
190
|
-
wrapperStyle,
|
|
191
|
-
contentStyle: buildBaseContentStyle(el, unit),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
195
|
-
};
|
|
196
|
-
const buildRenderNodes = (children, data, unit) => {
|
|
197
|
-
if (!Array.isArray(children))
|
|
198
|
-
return [];
|
|
199
|
-
const nodes = [];
|
|
200
|
-
children.forEach(el => {
|
|
201
|
-
if (!el || el.visible === false)
|
|
202
|
-
return;
|
|
203
|
-
const node = buildRenderNode(el, data, unit);
|
|
204
|
-
if (node)
|
|
205
|
-
nodes.push(node);
|
|
206
|
-
});
|
|
207
|
-
return nodes;
|
|
24
|
+
return el;
|
|
25
|
+
});
|
|
26
|
+
const buildCards = (layouts) => {
|
|
27
|
+
return layouts.map((layout, idx) => ({
|
|
28
|
+
id: pickCardId(layouts[idx], idx),
|
|
29
|
+
cardStyle: (0, index_1.styleObjectToString)((0, index_1.buildCardStyle)(layout, 'rpx'), 'rpx'),
|
|
30
|
+
backgroundImage: layout.backgroundImage || '',
|
|
31
|
+
backgroundStyle: (0, index_1.styleObjectToString)((0, index_1.buildBackgroundStyle)(layout, 'rpx'), 'rpx'),
|
|
32
|
+
elements: decorateElements(layout.children || []),
|
|
33
|
+
}));
|
|
208
34
|
};
|
|
209
|
-
const buildCards = (layouts, data, unit) => layouts.map(layout => ({
|
|
210
|
-
id: layout.name || layout.id || '',
|
|
211
|
-
cardStyle: buildCardStyle(layout, unit),
|
|
212
|
-
backgroundImage: layout.backgroundImage || '',
|
|
213
|
-
backgroundStyle: buildBackgroundStyle(layout, unit),
|
|
214
|
-
nodes: buildRenderNodes(layout.children || [], data, unit),
|
|
215
|
-
}));
|
|
216
35
|
Component({
|
|
217
36
|
options: {
|
|
218
37
|
styleIsolation: 'apply-shared',
|
|
@@ -249,16 +68,12 @@ Component({
|
|
|
249
68
|
methods: {
|
|
250
69
|
rebuild() {
|
|
251
70
|
const layoutInput = ensureArray(this.data.layout);
|
|
252
|
-
const dataInput = (this.data.data || {});
|
|
253
71
|
if (!layoutInput.length) {
|
|
254
72
|
this.setData({ cards: [] });
|
|
255
73
|
return;
|
|
256
74
|
}
|
|
257
75
|
const normalizedLayouts = (0, index_1.normalizeLayout)(layoutInput);
|
|
258
|
-
const cards = buildCards(normalizedLayouts
|
|
259
|
-
...card,
|
|
260
|
-
id: pickCardId(layoutInput[idx], idx),
|
|
261
|
-
}));
|
|
76
|
+
const cards = buildCards(normalizedLayouts);
|
|
262
77
|
this.setData({ cards });
|
|
263
78
|
},
|
|
264
79
|
},
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"component": true
|
|
2
|
+
"component": true,
|
|
3
|
+
"usingComponents": {
|
|
4
|
+
"text-element": "./elements/text-element/index",
|
|
5
|
+
"image-element": "./elements/image-element/index",
|
|
6
|
+
"icon-element": "./elements/icon-element/index",
|
|
7
|
+
"custom-element": "./elements/custom-element/index"
|
|
8
|
+
}
|
|
3
9
|
}
|
|
@@ -9,82 +9,34 @@
|
|
|
9
9
|
src="{{item.backgroundImage}}"
|
|
10
10
|
mode="aspectFill"
|
|
11
11
|
/>
|
|
12
|
-
<block wx:for="{{item.
|
|
13
|
-
<template is="render-
|
|
12
|
+
<block wx:for="{{item.elements}}" wx:key="id">
|
|
13
|
+
<template is="render-element" data="{{el:item}}" />
|
|
14
14
|
</block>
|
|
15
15
|
</view>
|
|
16
16
|
</view>
|
|
17
17
|
</block>
|
|
18
18
|
</view>
|
|
19
19
|
|
|
20
|
-
<template name="render-
|
|
21
|
-
<block wx:if="{{
|
|
22
|
-
<
|
|
23
|
-
<image
|
|
24
|
-
class="km-node__image"
|
|
25
|
-
style="{{node.contentStyle}}"
|
|
26
|
-
src="{{node.src}}"
|
|
27
|
-
mode="{{node.mode || 'aspectFill'}}"
|
|
28
|
-
/>
|
|
29
|
-
</view>
|
|
20
|
+
<template name="render-element">
|
|
21
|
+
<block wx:if="{{el.type === 'image'}}">
|
|
22
|
+
<image-element element="{{el}}" />
|
|
30
23
|
</block>
|
|
31
|
-
<block wx:elif="{{
|
|
32
|
-
<
|
|
33
|
-
<view
|
|
34
|
-
wx:if="{{node.name === 'dot' || node.name === 'round'}}"
|
|
35
|
-
class="km-node__icon-dot"
|
|
36
|
-
style="{{node.contentStyle}}"
|
|
37
|
-
/>
|
|
38
|
-
<view
|
|
39
|
-
wx:else
|
|
40
|
-
class="km-node__icon icon"
|
|
41
|
-
style="{{node.contentStyle}}"
|
|
42
|
-
>{{node.text || ''}}</view>
|
|
43
|
-
</view>
|
|
24
|
+
<block wx:elif="{{el.type === 'icon'}}">
|
|
25
|
+
<icon-element element="{{el}}" />
|
|
44
26
|
</block>
|
|
45
|
-
<block wx:elif="{{
|
|
46
|
-
<view class="km-node" style="{{
|
|
47
|
-
<view class="km-node__panel" style="{{
|
|
48
|
-
<block wx:for="{{
|
|
49
|
-
<template is="render-
|
|
27
|
+
<block wx:elif="{{el.type === 'layout-panel'}}">
|
|
28
|
+
<view class="km-node" style="{{el.wrapperStyle}}">
|
|
29
|
+
<view class="km-node__panel" style="{{el.contentStyle}}">
|
|
30
|
+
<block wx:for="{{el.children}}" wx:key="id">
|
|
31
|
+
<template is="render-element" data="{{el:item}}" />
|
|
50
32
|
</block>
|
|
51
33
|
</view>
|
|
52
34
|
</view>
|
|
53
35
|
</block>
|
|
54
|
-
<block wx:elif="{{
|
|
55
|
-
<
|
|
56
|
-
<view class="km-node__custom" style="{{node.contentStyle}}">
|
|
57
|
-
<slot name="{{node.id}}"></slot>
|
|
58
|
-
</view>
|
|
59
|
-
</view>
|
|
36
|
+
<block wx:elif="{{el.type === 'custom'}}">
|
|
37
|
+
<custom-element element="{{el}}" />
|
|
60
38
|
</block>
|
|
61
39
|
<block wx:else>
|
|
62
|
-
<
|
|
63
|
-
<view class="km-node__text" style="{{node.contentStyle}}">
|
|
64
|
-
<block wx:if="{{node.icon && node.icon.name}}">
|
|
65
|
-
<view class="km-node__text-content">
|
|
66
|
-
<block wx:if="{{node.icon.align === 'right'}}">
|
|
67
|
-
<text class="km-node__text-value">{{node.text || ''}}</text>
|
|
68
|
-
<view style="{{node.icon.wrapperStyle}}">
|
|
69
|
-
<text
|
|
70
|
-
class="km-node__text-icon icon"
|
|
71
|
-
style="font-size: {{node.icon.size || '16px'}}; color: {{node.icon.color || ''}}; margin-right: {{node.icon.gap || ''}};">{{node.icon.text || node.icon.name || ''}}</text>
|
|
72
|
-
</view>
|
|
73
|
-
</block>
|
|
74
|
-
<block wx:else>
|
|
75
|
-
<view style="{{node.icon.wrapperStyle}}">
|
|
76
|
-
<text
|
|
77
|
-
class="km-node__text-icon icon"
|
|
78
|
-
style="font-size: {{node.icon.size || '16px'}}; color: {{node.icon.color || ''}}; margin-right: {{node.icon.gap || ''}};">{{node.icon.text || node.icon.name || ''}}</text>
|
|
79
|
-
</view>
|
|
80
|
-
<text class="km-node__text-value">{{node.text || ''}}</text>
|
|
81
|
-
</block>
|
|
82
|
-
</view>
|
|
83
|
-
</block>
|
|
84
|
-
<block wx:else>
|
|
85
|
-
<text class="km-node__text-value">{{node.text || ''}}</text>
|
|
86
|
-
</block>
|
|
87
|
-
</view>
|
|
88
|
-
</view>
|
|
40
|
+
<text-element element="{{el}}" />
|
|
89
41
|
</block>
|
|
90
42
|
</template>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
.km-card-layout {
|
|
4
2
|
display: flex;
|
|
5
3
|
flex-direction: column;
|
|
6
|
-
gap: 16rpx;
|
|
7
4
|
}
|
|
8
5
|
|
|
9
6
|
.km-card-layout__item {
|
|
@@ -33,74 +30,14 @@
|
|
|
33
30
|
color: inherit;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
.km-node--icon {
|
|
37
|
-
display: flex;
|
|
38
|
-
align-items: center;
|
|
39
|
-
justify-content: center;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.km-node__image {
|
|
43
|
-
width: 100%;
|
|
44
|
-
height: 100%;
|
|
45
|
-
display: block;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.km-node__icon {
|
|
49
|
-
display: inline-flex;
|
|
50
|
-
align-items: center;
|
|
51
|
-
justify-content: center;
|
|
52
|
-
width: 100%;
|
|
53
|
-
height: 100%;
|
|
54
|
-
font-family: 'km-icon', 'PingFang SC', 'Microsoft Yahei', sans-serif;
|
|
55
|
-
font-style: normal;
|
|
56
|
-
font-weight: normal;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.km-node__icon-dot {
|
|
60
|
-
width: 100%;
|
|
61
|
-
height: 100%;
|
|
62
|
-
border-radius: 50%;
|
|
63
|
-
background-color: #999;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
33
|
.km-node__panel {
|
|
67
34
|
width: 100%;
|
|
68
35
|
height: 100%;
|
|
69
36
|
box-sizing: border-box;
|
|
70
37
|
}
|
|
71
38
|
|
|
72
|
-
.km-node__custom {
|
|
73
|
-
width: 100%;
|
|
74
|
-
height: 100%;
|
|
75
|
-
box-sizing: border-box;
|
|
76
|
-
}
|
|
77
39
|
|
|
78
|
-
.km-node__text {
|
|
79
|
-
width: 100%;
|
|
80
|
-
height: 100%;
|
|
81
|
-
display: block;
|
|
82
|
-
box-sizing: border-box;
|
|
83
|
-
text-align: inherit;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.km-node__text-content {
|
|
87
|
-
display: inline-block;
|
|
88
|
-
vertical-align: middle;
|
|
89
|
-
height: 100%;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.km-node__text-value {
|
|
93
|
-
display: inline-block;
|
|
94
|
-
white-space: pre-wrap;
|
|
95
|
-
word-break: break-word;
|
|
96
|
-
vertical-align: middle;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.km-node--text text {
|
|
100
|
-
display: inline;
|
|
101
|
-
}
|
|
102
40
|
|
|
103
|
-
/* ICON */
|
|
104
41
|
|
|
105
42
|
|
|
106
43
|
@font-face {
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.styleObjectToString = exports.resolveBindingValue = exports.normalizeLayout = exports.
|
|
3
|
+
exports.styleObjectToString = exports.resolveBindingValue = exports.normalizeLayout = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildTextIconMeta = exports.buildImageContentStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = exports.addUnit = void 0;
|
|
4
4
|
var index_1 = require("../vendor/km-card-layout-core/index");
|
|
5
5
|
Object.defineProperty(exports, "addUnit", { enumerable: true, get: function () { return index_1.addUnit; } });
|
|
6
|
-
Object.defineProperty(exports, "
|
|
7
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "buildWrapperStyle", { enumerable: true, get: function () { return index_1.buildWrapperStyle; } });
|
|
7
|
+
Object.defineProperty(exports, "buildCardStyle", { enumerable: true, get: function () { return index_1.buildCardStyle; } });
|
|
8
|
+
Object.defineProperty(exports, "buildBackgroundStyle", { enumerable: true, get: function () { return index_1.buildBackgroundStyle; } });
|
|
9
|
+
Object.defineProperty(exports, "buildBaseContentStyle", { enumerable: true, get: function () { return index_1.buildBaseContentStyle; } });
|
|
10
|
+
Object.defineProperty(exports, "buildPanelContentStyle", { enumerable: true, get: function () { return index_1.buildPanelContentStyle; } });
|
|
11
|
+
Object.defineProperty(exports, "buildTextContentStyle", { enumerable: true, get: function () { return index_1.buildTextContentStyle; } });
|
|
12
|
+
Object.defineProperty(exports, "buildImageContentStyle", { enumerable: true, get: function () { return index_1.buildImageContentStyle; } });
|
|
13
|
+
Object.defineProperty(exports, "buildTextIconMeta", { enumerable: true, get: function () { return index_1.buildTextIconMeta; } });
|
|
14
|
+
Object.defineProperty(exports, "getTextValue", { enumerable: true, get: function () { return index_1.getTextValue; } });
|
|
15
|
+
Object.defineProperty(exports, "getImageSrc", { enumerable: true, get: function () { return index_1.getImageSrc; } });
|
|
16
|
+
Object.defineProperty(exports, "getIconName", { enumerable: true, get: function () { return index_1.getIconName; } });
|
|
8
17
|
Object.defineProperty(exports, "normalizeLayout", { enumerable: true, get: function () { return index_1.normalizeLayout; } });
|
|
9
18
|
Object.defineProperty(exports, "resolveBindingValue", { enumerable: true, get: function () { return index_1.resolveBindingValue; } });
|
|
10
19
|
Object.defineProperty(exports, "styleObjectToString", { enumerable: true, get: function () { return index_1.styleObjectToString; } });
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTemplateBackgrounds = exports.getTemplateItems = exports.applyItemCollectBindings = exports.stripLayoutBindings = void 0;
|
|
4
|
+
function stripLayoutBindings(layouts = []) {
|
|
5
|
+
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
6
|
+
const stripElement = (el) => {
|
|
7
|
+
const { binding: _b, defaultValue: _d, ...rest } = el;
|
|
8
|
+
if (el.type === 'layout-panel') {
|
|
9
|
+
return {
|
|
10
|
+
...rest,
|
|
11
|
+
children: (el.children || []).map(stripElement),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return rest;
|
|
15
|
+
};
|
|
16
|
+
return targetLayouts.map(layout => ({
|
|
17
|
+
...layout,
|
|
18
|
+
children: (layout.children || []).map(stripElement),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
exports.stripLayoutBindings = stripLayoutBindings;
|
|
22
|
+
function applyItemCollectBindings(layouts = [], items = []) {
|
|
23
|
+
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
24
|
+
const metaMap = new Map();
|
|
25
|
+
const metaList = Array.isArray(items) ? items : [];
|
|
26
|
+
metaList.forEach(item => {
|
|
27
|
+
if (item && item.id !== undefined && item.id !== null) {
|
|
28
|
+
metaMap.set(String(item.id), item);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const assignBinding = (el) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const meta = metaMap.get(String(el.id));
|
|
34
|
+
const binding = meta && meta.bind !== undefined && meta.bind !== null
|
|
35
|
+
? meta.bind
|
|
36
|
+
: el.binding;
|
|
37
|
+
const defaultValue = meta && meta.default !== undefined ? meta.default : el.defaultValue;
|
|
38
|
+
const key = meta && meta.key !== undefined ? meta.key : el.key;
|
|
39
|
+
const base = { ...el };
|
|
40
|
+
if (binding !== undefined)
|
|
41
|
+
base.binding = binding;
|
|
42
|
+
else
|
|
43
|
+
delete base.binding;
|
|
44
|
+
if (defaultValue !== undefined)
|
|
45
|
+
base.defaultValue = defaultValue;
|
|
46
|
+
else
|
|
47
|
+
delete base.defaultValue;
|
|
48
|
+
if (key !== undefined)
|
|
49
|
+
base.key = key;
|
|
50
|
+
else
|
|
51
|
+
delete base.key;
|
|
52
|
+
if (el.type === 'text' && ((_a = meta === null || meta === void 0 ? void 0 : meta.extra) === null || _a === void 0 ? void 0 : _a.icon)) {
|
|
53
|
+
base.icon = { ...(base.icon || {}), name: meta.extra.icon };
|
|
54
|
+
}
|
|
55
|
+
if (el.type === 'layout-panel') {
|
|
56
|
+
return {
|
|
57
|
+
...base,
|
|
58
|
+
children: (el.children || []).map(assignBinding),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return base;
|
|
62
|
+
};
|
|
63
|
+
return targetLayouts.map(layout => ({
|
|
64
|
+
...layout,
|
|
65
|
+
children: (layout.children || []).map(assignBinding),
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
exports.applyItemCollectBindings = applyItemCollectBindings;
|
|
69
|
+
function getTemplateItems(ids, items) {
|
|
70
|
+
const idArray = ids.split(',').map(id => id.trim());
|
|
71
|
+
return items.filter(item => idArray.includes(String(item.id)));
|
|
72
|
+
}
|
|
73
|
+
exports.getTemplateItems = getTemplateItems;
|
|
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
|
+
}
|
|
78
|
+
exports.getTemplateBackgrounds = getTemplateBackgrounds;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveBindingValue = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const pathToSegments = (path) => `${path || ''}`
|
|
6
|
+
.replace(/\[(\d+)\]/g, '.$1')
|
|
7
|
+
.split('.')
|
|
8
|
+
.map(p => p.trim())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
const readByPath = (data, path) => {
|
|
11
|
+
if (path === undefined || path === null || path === '')
|
|
12
|
+
return data;
|
|
13
|
+
const segments = pathToSegments(path);
|
|
14
|
+
let cursor = data;
|
|
15
|
+
for (let i = 0; i < segments.length; i += 1) {
|
|
16
|
+
if (!(0, helpers_1.isObject)(cursor) && !Array.isArray(cursor))
|
|
17
|
+
return undefined;
|
|
18
|
+
const key = segments[i];
|
|
19
|
+
if (Array.isArray(cursor)) {
|
|
20
|
+
const idx = Number(key);
|
|
21
|
+
cursor = Number.isNaN(idx) ? undefined : cursor[idx];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
cursor = cursor[key];
|
|
25
|
+
}
|
|
26
|
+
if (cursor === undefined || cursor === null) {
|
|
27
|
+
return cursor;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return cursor;
|
|
31
|
+
};
|
|
32
|
+
const resolveBindingValue = (binding, rootData, context) => {
|
|
33
|
+
if (!binding)
|
|
34
|
+
return undefined;
|
|
35
|
+
const value = readByPath(rootData, binding);
|
|
36
|
+
return value === undefined ? undefined : value;
|
|
37
|
+
};
|
|
38
|
+
exports.resolveBindingValue = resolveBindingValue;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isObject = exports.styleObjectToString = exports.addUnit = exports.toNumber = void 0;
|
|
4
|
+
const DIMENSION_PROPS = new Set([
|
|
5
|
+
'width',
|
|
6
|
+
'height',
|
|
7
|
+
'top',
|
|
8
|
+
'right',
|
|
9
|
+
'bottom',
|
|
10
|
+
'left',
|
|
11
|
+
'padding',
|
|
12
|
+
'paddingTop',
|
|
13
|
+
'paddingBottom',
|
|
14
|
+
'paddingLeft',
|
|
15
|
+
'paddingRight',
|
|
16
|
+
'margin',
|
|
17
|
+
'marginTop',
|
|
18
|
+
'marginBottom',
|
|
19
|
+
'marginLeft',
|
|
20
|
+
'marginRight',
|
|
21
|
+
'fontSize',
|
|
22
|
+
'lineHeight',
|
|
23
|
+
'borderRadius',
|
|
24
|
+
'borderWidth',
|
|
25
|
+
'letterSpacing',
|
|
26
|
+
'gap',
|
|
27
|
+
'rowGap',
|
|
28
|
+
'columnGap',
|
|
29
|
+
]);
|
|
30
|
+
const toNumber = (value) => {
|
|
31
|
+
const num = Number(value);
|
|
32
|
+
return Number.isFinite(num) ? num : undefined;
|
|
33
|
+
};
|
|
34
|
+
exports.toNumber = toNumber;
|
|
35
|
+
const toKebab = (key) => key.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
36
|
+
const addUnit = (value, unit) => {
|
|
37
|
+
if (value === undefined || value === null || value === '')
|
|
38
|
+
return undefined;
|
|
39
|
+
if (typeof value === 'number') {
|
|
40
|
+
const ratio = unit === 'rpx' ? 2 : 1;
|
|
41
|
+
return `${value * ratio}${unit}`;
|
|
42
|
+
}
|
|
43
|
+
if (typeof value === 'string') {
|
|
44
|
+
const parsed = Number(value);
|
|
45
|
+
if (Number.isFinite(parsed)) {
|
|
46
|
+
const ratio = unit === 'rpx' ? 2 : 1;
|
|
47
|
+
return `${parsed * ratio}${unit}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return `${value}`;
|
|
51
|
+
};
|
|
52
|
+
exports.addUnit = addUnit;
|
|
53
|
+
const styleObjectToString = (style, unit = 'px') => {
|
|
54
|
+
if (!style)
|
|
55
|
+
return '';
|
|
56
|
+
const pairs = [];
|
|
57
|
+
Object.keys(style).forEach(key => {
|
|
58
|
+
const value = style[key];
|
|
59
|
+
if (value === undefined || value === null || value === '')
|
|
60
|
+
return;
|
|
61
|
+
const useUnit = DIMENSION_PROPS.has(key)
|
|
62
|
+
? (0, exports.addUnit)(value, unit)
|
|
63
|
+
: value;
|
|
64
|
+
if (useUnit === undefined || useUnit === null || useUnit === '')
|
|
65
|
+
return;
|
|
66
|
+
pairs.push(`${toKebab(key)}:${useUnit}`);
|
|
67
|
+
});
|
|
68
|
+
return pairs.join(';');
|
|
69
|
+
};
|
|
70
|
+
exports.styleObjectToString = styleObjectToString;
|
|
71
|
+
const isObject = (val) => Boolean(val) && typeof val === 'object';
|
|
72
|
+
exports.isObject = isObject;
|