km-card-layout-component-miniprogram 0.1.8 → 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 +19 -36
- 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 -65
- package/miniprogram_dist/utils/card-schema.js +12 -3
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +4 -0
- package/miniprogram_dist/vendor/km-card-layout-core/index.js +37 -6
- package/miniprogram_dist/vendor/km-card-layout-core/interface/index.js +1 -1
- package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +8 -1
- 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/package.json +1 -1
- package/script/sync-core.js +3 -0
- 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 +36 -45
- package/src/components/card-layout/index.wxml +15 -63
- package/src/components/card-layout/index.wxss +0 -65
- package/src/utils/card-schema.ts +11 -4
- package/src/vendor/km-card-layout-core/bindings.ts +3 -0
- package/src/vendor/km-card-layout-core/data.ts +2 -1
- package/src/vendor/km-card-layout-core/index.ts +37 -5
- 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/ops/changeBackground.ts +14 -4
- 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 +71 -12
- package/src/vendor/km-card-layout-core/utils.ts +4 -0
- package/miniprogram_dist/vendor/km-card-layout-core/render/builder.js +0 -210
- package/src/vendor/km-card-layout-core/interface/render.ts +0 -53
- package/src/vendor/km-card-layout-core/render/builder.ts +0 -288
- /package/miniprogram_dist/vendor/km-card-layout-core/interface/{render.js → context.js} +0 -0
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CardElement,
|
|
3
|
-
IconElement,
|
|
4
|
-
ImageElement,
|
|
5
|
-
LayoutPanelElement,
|
|
6
|
-
TextElement,
|
|
7
|
-
} from '../interface/elements';
|
|
8
|
-
import type { CardLayoutSchema, CardLayoutInput } from '../interface/layout';
|
|
9
|
-
import type {
|
|
10
|
-
BindingContext,
|
|
11
|
-
RenderNode,
|
|
12
|
-
RenderResult,
|
|
13
|
-
} from '../interface/render';
|
|
14
|
-
import { addUnit, styleObjectToString } from '../helpers';
|
|
15
|
-
import { getAbsLayout, normalizeLayout } from '../layout';
|
|
16
|
-
import { resolveBindingValue } from '../data';
|
|
17
|
-
|
|
18
|
-
const buildCardStyle = (layout: CardLayoutSchema, unit: 'px' | 'rpx') =>
|
|
19
|
-
styleObjectToString(
|
|
20
|
-
{
|
|
21
|
-
width: addUnit(layout.width, unit),
|
|
22
|
-
height: addUnit(layout.height, unit),
|
|
23
|
-
color: layout.fontColor,
|
|
24
|
-
borderRadius:
|
|
25
|
-
layout.borderRadius !== undefined
|
|
26
|
-
? addUnit(layout.borderRadius, unit)
|
|
27
|
-
: undefined,
|
|
28
|
-
padding:
|
|
29
|
-
layout.padding !== undefined ? addUnit(layout.padding, unit) : undefined,
|
|
30
|
-
position: 'relative',
|
|
31
|
-
overflow: 'hidden',
|
|
32
|
-
boxSizing: 'border-box',
|
|
33
|
-
backgroundColor: 'transparent',
|
|
34
|
-
},
|
|
35
|
-
unit
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const buildBackgroundStyle = (layout: CardLayoutSchema, unit: 'px' | 'rpx') =>
|
|
39
|
-
styleObjectToString(
|
|
40
|
-
{
|
|
41
|
-
zIndex: layout.backgroundZIndex,
|
|
42
|
-
borderRadius:
|
|
43
|
-
layout.borderRadius !== undefined
|
|
44
|
-
? addUnit(layout.borderRadius, unit)
|
|
45
|
-
: undefined,
|
|
46
|
-
width: '100%',
|
|
47
|
-
height: '100%',
|
|
48
|
-
position: 'absolute',
|
|
49
|
-
left: 0,
|
|
50
|
-
top: 0,
|
|
51
|
-
},
|
|
52
|
-
unit
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const buildWrapperStyle = (el: CardElement, unit: 'px' | 'rpx'): string => {
|
|
56
|
-
const abs = getAbsLayout(el);
|
|
57
|
-
if (!abs) return '';
|
|
58
|
-
return styleObjectToString(
|
|
59
|
-
{
|
|
60
|
-
position: 'absolute',
|
|
61
|
-
left: addUnit(abs.x, unit),
|
|
62
|
-
top: addUnit(abs.y, unit),
|
|
63
|
-
width: addUnit(abs.width, unit),
|
|
64
|
-
height: addUnit(abs.height, unit),
|
|
65
|
-
zIndex: abs.zIndex,
|
|
66
|
-
boxSizing: 'border-box',
|
|
67
|
-
},
|
|
68
|
-
unit
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const buildPanelContentStyle = (
|
|
73
|
-
el: LayoutPanelElement,
|
|
74
|
-
unit: 'px' | 'rpx'
|
|
75
|
-
) =>
|
|
76
|
-
styleObjectToString(
|
|
77
|
-
{
|
|
78
|
-
position: 'relative',
|
|
79
|
-
width: '100%',
|
|
80
|
-
height: '100%',
|
|
81
|
-
display: 'block',
|
|
82
|
-
boxSizing: 'border-box',
|
|
83
|
-
...(el.style || {}),
|
|
84
|
-
},
|
|
85
|
-
unit
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
const buildTextContentStyle = (el: TextElement, unit: 'px' | 'rpx') => {
|
|
89
|
-
const textAlign =
|
|
90
|
-
(el.style?.textAlign as string | undefined) || el.align || undefined;
|
|
91
|
-
const style: Record<string, any> = {
|
|
92
|
-
...(el.style || {}),
|
|
93
|
-
whiteSpace: 'pre-wrap',
|
|
94
|
-
wordBreak: 'break-word',
|
|
95
|
-
lineHeight:
|
|
96
|
-
el.style?.lineHeight !== undefined && el.style?.lineHeight !== null
|
|
97
|
-
? el.style.lineHeight
|
|
98
|
-
: '1',
|
|
99
|
-
};
|
|
100
|
-
if (textAlign) style.textAlign = textAlign;
|
|
101
|
-
return styleObjectToString(style, unit);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const buildBaseContentStyle = (el: CardElement, unit: 'px' | 'rpx') =>
|
|
105
|
-
styleObjectToString(
|
|
106
|
-
{
|
|
107
|
-
...(el.style || {}),
|
|
108
|
-
boxSizing: 'border-box',
|
|
109
|
-
},
|
|
110
|
-
unit
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const buildImageContentStyle = (el: ImageElement, unit: 'px' | 'rpx') => {
|
|
114
|
-
const style: Record<string, any> = { ...(el.style || {}) };
|
|
115
|
-
const borderWidth = Number(style.borderWidth);
|
|
116
|
-
if (Number.isFinite(borderWidth) && borderWidth > 0) {
|
|
117
|
-
if (!style.borderStyle) style.borderStyle = 'solid';
|
|
118
|
-
if (!style.borderColor) style.borderColor = '#000000';
|
|
119
|
-
}
|
|
120
|
-
return styleObjectToString(style, unit);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const buildTextIcon = (
|
|
124
|
-
el: TextElement,
|
|
125
|
-
unit: 'px' | 'rpx'
|
|
126
|
-
): RenderNode['icon'] | undefined => {
|
|
127
|
-
const icon = el.icon;
|
|
128
|
-
if (!icon || icon.enable === false) return undefined;
|
|
129
|
-
|
|
130
|
-
const style = icon.style || 'fill';
|
|
131
|
-
const baseName = el.key || el.binding || el.id;
|
|
132
|
-
let name: string | undefined;
|
|
133
|
-
if (style === 'dot') name = 'round';
|
|
134
|
-
else if (style === 'line') name = baseName ? `${baseName}-line` : undefined;
|
|
135
|
-
else name = baseName || undefined;
|
|
136
|
-
if (!name) return undefined;
|
|
137
|
-
|
|
138
|
-
const size =
|
|
139
|
-
icon.size !== undefined && icon.size !== null
|
|
140
|
-
? icon.size
|
|
141
|
-
: (el.style?.fontSize as any);
|
|
142
|
-
const gap = icon.gap !== undefined && icon.gap !== null ? icon.gap : 4;
|
|
143
|
-
const color =
|
|
144
|
-
icon.color ??
|
|
145
|
-
((typeof el.style?.color === 'string' ? el.style.color : undefined) as
|
|
146
|
-
| string
|
|
147
|
-
| undefined);
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
name: `${name}`,
|
|
151
|
-
text: `${name}`,
|
|
152
|
-
size: addUnit(size as any, unit),
|
|
153
|
-
gap: addUnit(gap as any, unit),
|
|
154
|
-
color: color as any,
|
|
155
|
-
align: icon.align || 'left',
|
|
156
|
-
wrapperStyle: styleObjectToString(
|
|
157
|
-
{
|
|
158
|
-
display: 'inline-flex',
|
|
159
|
-
alignItems: 'center',
|
|
160
|
-
height: el.style?.lineHeight || '1',
|
|
161
|
-
},
|
|
162
|
-
unit
|
|
163
|
-
),
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const buildNode = (
|
|
168
|
-
el: CardElement,
|
|
169
|
-
rootData: Record<string, any>,
|
|
170
|
-
unit: 'px' | 'rpx',
|
|
171
|
-
context: BindingContext
|
|
172
|
-
): RenderNode | null => {
|
|
173
|
-
if (!el || el.visible === false) return null;
|
|
174
|
-
const wrapperStyle = buildWrapperStyle(el, unit);
|
|
175
|
-
|
|
176
|
-
if (el.type === 'layout-panel') {
|
|
177
|
-
return {
|
|
178
|
-
id: el.id,
|
|
179
|
-
type: el.type,
|
|
180
|
-
visible: el.visible,
|
|
181
|
-
wrapperStyle,
|
|
182
|
-
contentStyle: buildPanelContentStyle(el as LayoutPanelElement, unit),
|
|
183
|
-
children: buildRenderNodes(el.children || [], rootData, unit, context),
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const baseStyle = buildBaseContentStyle(el, unit);
|
|
188
|
-
if (el.type === 'text') {
|
|
189
|
-
const value =
|
|
190
|
-
resolveBindingValue(el.binding, rootData, context) ??
|
|
191
|
-
el.defaultValue ??
|
|
192
|
-
'';
|
|
193
|
-
return {
|
|
194
|
-
id: el.id,
|
|
195
|
-
type: el.type,
|
|
196
|
-
wrapperStyle,
|
|
197
|
-
contentStyle: buildTextContentStyle(el as TextElement, unit),
|
|
198
|
-
text: `${value}`,
|
|
199
|
-
visible: el.visible,
|
|
200
|
-
icon: buildTextIcon(el as TextElement, unit),
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (el.type === 'image') {
|
|
205
|
-
const src =
|
|
206
|
-
resolveBindingValue(el.binding, rootData, context) ??
|
|
207
|
-
(el as ImageElement).defaultUrl ??
|
|
208
|
-
el.defaultValue ??
|
|
209
|
-
'';
|
|
210
|
-
const mode =
|
|
211
|
-
(el as ImageElement).fit === 'contain' ? 'aspectFit' : 'aspectFill';
|
|
212
|
-
return {
|
|
213
|
-
id: el.id,
|
|
214
|
-
type: el.type,
|
|
215
|
-
wrapperStyle,
|
|
216
|
-
contentStyle: buildImageContentStyle(el as ImageElement, unit),
|
|
217
|
-
src,
|
|
218
|
-
mode,
|
|
219
|
-
visible: el.visible,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (el.type === 'icon') {
|
|
224
|
-
const name =
|
|
225
|
-
resolveBindingValue(el.binding, rootData, context) ??
|
|
226
|
-
(el as IconElement).name ??
|
|
227
|
-
el.defaultValue ??
|
|
228
|
-
'';
|
|
229
|
-
return {
|
|
230
|
-
id: el.id,
|
|
231
|
-
type: el.type,
|
|
232
|
-
wrapperStyle,
|
|
233
|
-
contentStyle: baseStyle,
|
|
234
|
-
name: `${name}`,
|
|
235
|
-
text: `${name}`,
|
|
236
|
-
visible: el.visible,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (el.type === 'custom') {
|
|
241
|
-
return {
|
|
242
|
-
id: el.id,
|
|
243
|
-
type: el.type,
|
|
244
|
-
wrapperStyle,
|
|
245
|
-
contentStyle: baseStyle,
|
|
246
|
-
visible: el.visible,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return null;
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
export const buildRenderNodes = (
|
|
254
|
-
children: CardElement[],
|
|
255
|
-
rootData: Record<string, any>,
|
|
256
|
-
unit: 'px' | 'rpx' = 'px',
|
|
257
|
-
context: BindingContext = {}
|
|
258
|
-
): RenderNode[] => {
|
|
259
|
-
if (!Array.isArray(children)) return [];
|
|
260
|
-
|
|
261
|
-
const nodes: RenderNode[] = [];
|
|
262
|
-
children.forEach(el => {
|
|
263
|
-
if (!el || el.visible === false) return;
|
|
264
|
-
const node = buildNode(el, rootData, unit, context);
|
|
265
|
-
if (node) nodes.push(node);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
return nodes;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
export const buildRenderResult = (
|
|
272
|
-
layoutInput: CardLayoutInput,
|
|
273
|
-
dataInput: Record<string, any>,
|
|
274
|
-
unit: 'px' | 'rpx' = 'px'
|
|
275
|
-
): RenderResult => {
|
|
276
|
-
const layouts = normalizeLayout(layoutInput);
|
|
277
|
-
return layouts.map(layout => {
|
|
278
|
-
const cardStyle = buildCardStyle(layout, unit);
|
|
279
|
-
const bgStyle = buildBackgroundStyle(layout, unit);
|
|
280
|
-
const renderTree = buildRenderNodes(layout.children || [], dataInput || {}, unit);
|
|
281
|
-
return {
|
|
282
|
-
renderTree,
|
|
283
|
-
cardStyle,
|
|
284
|
-
backgroundImage: layout.backgroundImage || '',
|
|
285
|
-
backgroundStyle: bgStyle,
|
|
286
|
-
};
|
|
287
|
-
});
|
|
288
|
-
};
|
|
File without changes
|