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,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 {
|
package/src/utils/card-schema.ts
CHANGED
|
@@ -3,14 +3,21 @@ export type {
|
|
|
3
3
|
CardElementType,
|
|
4
4
|
CardLayoutInput,
|
|
5
5
|
CardLayoutSchema,
|
|
6
|
-
RenderNode,
|
|
7
|
-
RenderResult
|
|
8
6
|
} from '../vendor/km-card-layout-core/index'
|
|
9
7
|
|
|
10
8
|
export {
|
|
11
9
|
addUnit,
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
buildWrapperStyle,
|
|
11
|
+
buildCardStyle,
|
|
12
|
+
buildBackgroundStyle,
|
|
13
|
+
buildBaseContentStyle,
|
|
14
|
+
buildPanelContentStyle,
|
|
15
|
+
buildTextContentStyle,
|
|
16
|
+
buildImageContentStyle,
|
|
17
|
+
buildTextIconMeta,
|
|
18
|
+
getTextValue,
|
|
19
|
+
getImageSrc,
|
|
20
|
+
getIconName,
|
|
14
21
|
normalizeLayout,
|
|
15
22
|
resolveBindingValue,
|
|
16
23
|
styleObjectToString
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { CardElement, CardLayoutSchema } from './interface';
|
|
2
|
+
import type {
|
|
3
|
+
TemplateBackground,
|
|
4
|
+
TemplateItem,
|
|
5
|
+
} from './interface/data/payload';
|
|
6
|
+
|
|
7
|
+
export function stripLayoutBindings(
|
|
8
|
+
layouts: CardLayoutSchema[] = []
|
|
9
|
+
): CardLayoutSchema[] {
|
|
10
|
+
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
11
|
+
const stripElement = (el: CardElement): CardElement => {
|
|
12
|
+
const { binding: _b, defaultValue: _d, ...rest } = el as any;
|
|
13
|
+
if (el.type === 'layout-panel') {
|
|
14
|
+
return {
|
|
15
|
+
...rest,
|
|
16
|
+
children: (el.children || []).map(stripElement),
|
|
17
|
+
} as CardElement;
|
|
18
|
+
}
|
|
19
|
+
return rest as CardElement;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return targetLayouts.map(layout => ({
|
|
23
|
+
...layout,
|
|
24
|
+
children: (layout.children || []).map(stripElement),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function applyItemCollectBindings(
|
|
29
|
+
layouts: CardLayoutSchema[] = [],
|
|
30
|
+
items: TemplateItem[] = []
|
|
31
|
+
): CardLayoutSchema[] {
|
|
32
|
+
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
33
|
+
const metaMap = new Map<string, TemplateItem>();
|
|
34
|
+
const metaList = Array.isArray(items) ? items : [];
|
|
35
|
+
metaList.forEach(item => {
|
|
36
|
+
if (item && item.id !== undefined && item.id !== null) {
|
|
37
|
+
metaMap.set(String(item.id), item);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const assignBinding = (el: CardElement): CardElement => {
|
|
42
|
+
const meta = metaMap.get(String(el.id));
|
|
43
|
+
const binding =
|
|
44
|
+
meta && meta.bind !== undefined && meta.bind !== null
|
|
45
|
+
? meta.bind
|
|
46
|
+
: el.binding;
|
|
47
|
+
const defaultValue =
|
|
48
|
+
meta && meta.default !== undefined ? meta.default : el.defaultValue;
|
|
49
|
+
const key = meta && meta.key !== undefined ? meta.key : el.key;
|
|
50
|
+
const base: any = { ...el };
|
|
51
|
+
if (binding !== undefined) base.binding = binding;
|
|
52
|
+
else delete base.binding;
|
|
53
|
+
if (defaultValue !== undefined) base.defaultValue = defaultValue;
|
|
54
|
+
else delete base.defaultValue;
|
|
55
|
+
if (key !== undefined) base.key = key;
|
|
56
|
+
else delete base.key;
|
|
57
|
+
if (el.type === 'text' && meta?.extra?.icon) {
|
|
58
|
+
base.icon = { ...(base.icon || {}), name: meta.extra.icon };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (el.type === 'layout-panel') {
|
|
62
|
+
return {
|
|
63
|
+
...base,
|
|
64
|
+
children: (el.children || []).map(assignBinding),
|
|
65
|
+
} as CardElement;
|
|
66
|
+
}
|
|
67
|
+
return base as CardElement;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return targetLayouts.map(layout => ({
|
|
71
|
+
...layout,
|
|
72
|
+
children: (layout.children || []).map(assignBinding),
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isObject } from './helpers';
|
|
2
|
+
import type { BindingContext } from './interface';
|
|
3
|
+
|
|
4
|
+
const pathToSegments = (path: string): string[] =>
|
|
5
|
+
`${path || ''}`
|
|
6
|
+
.replace(/\[(\d+)\]/g, '.$1')
|
|
7
|
+
.split('.')
|
|
8
|
+
.map(p => p.trim())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
|
|
11
|
+
const readByPath = (data: any, path: string): any => {
|
|
12
|
+
if (path === undefined || path === null || path === '') return data;
|
|
13
|
+
const segments = pathToSegments(path);
|
|
14
|
+
let cursor: any = data;
|
|
15
|
+
for (let i = 0; i < segments.length; i += 1) {
|
|
16
|
+
if (!isObject(cursor) && !Array.isArray(cursor)) return undefined;
|
|
17
|
+
const key = segments[i];
|
|
18
|
+
if (Array.isArray(cursor)) {
|
|
19
|
+
const idx = Number(key);
|
|
20
|
+
cursor = Number.isNaN(idx) ? undefined : cursor[idx];
|
|
21
|
+
} else {
|
|
22
|
+
cursor = (cursor as Record<string, any>)[key];
|
|
23
|
+
}
|
|
24
|
+
if (cursor === undefined || cursor === null) {
|
|
25
|
+
return cursor;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return cursor;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const resolveBindingValue = (
|
|
32
|
+
binding: string | undefined,
|
|
33
|
+
rootData: Record<string, any>,
|
|
34
|
+
context?: BindingContext
|
|
35
|
+
): any => {
|
|
36
|
+
if (!binding) return undefined;
|
|
37
|
+
const value = readByPath(rootData, binding);
|
|
38
|
+
return value === undefined ? undefined : value;
|
|
39
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const DIMENSION_PROPS = new Set([
|
|
2
|
+
'width',
|
|
3
|
+
'height',
|
|
4
|
+
'top',
|
|
5
|
+
'right',
|
|
6
|
+
'bottom',
|
|
7
|
+
'left',
|
|
8
|
+
'padding',
|
|
9
|
+
'paddingTop',
|
|
10
|
+
'paddingBottom',
|
|
11
|
+
'paddingLeft',
|
|
12
|
+
'paddingRight',
|
|
13
|
+
'margin',
|
|
14
|
+
'marginTop',
|
|
15
|
+
'marginBottom',
|
|
16
|
+
'marginLeft',
|
|
17
|
+
'marginRight',
|
|
18
|
+
'fontSize',
|
|
19
|
+
'lineHeight',
|
|
20
|
+
'borderRadius',
|
|
21
|
+
'borderWidth',
|
|
22
|
+
'letterSpacing',
|
|
23
|
+
'gap',
|
|
24
|
+
'rowGap',
|
|
25
|
+
'columnGap',
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
export const toNumber = (value: unknown): number | undefined => {
|
|
29
|
+
const num = Number(value);
|
|
30
|
+
return Number.isFinite(num) ? num : undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const toKebab = (key: string): string =>
|
|
34
|
+
key.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
35
|
+
|
|
36
|
+
export const addUnit = (
|
|
37
|
+
value: string | number | undefined | null,
|
|
38
|
+
unit: 'px' | 'rpx'
|
|
39
|
+
): string | undefined => {
|
|
40
|
+
if (value === undefined || value === null || value === '') return undefined;
|
|
41
|
+
if (typeof value === 'number') {
|
|
42
|
+
const ratio = unit === 'rpx' ? 2 : 1;
|
|
43
|
+
return `${value * ratio}${unit}`;
|
|
44
|
+
}
|
|
45
|
+
if (typeof value === 'string') {
|
|
46
|
+
const parsed = Number(value);
|
|
47
|
+
if (Number.isFinite(parsed)) {
|
|
48
|
+
const ratio = unit === 'rpx' ? 2 : 1;
|
|
49
|
+
return `${parsed * ratio}${unit}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return `${value}`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const styleObjectToString = (
|
|
56
|
+
style?: Record<string, any>,
|
|
57
|
+
unit: 'px' | 'rpx' = 'px'
|
|
58
|
+
): string => {
|
|
59
|
+
if (!style) return '';
|
|
60
|
+
const pairs: string[] = [];
|
|
61
|
+
Object.keys(style).forEach(key => {
|
|
62
|
+
const value = style[key];
|
|
63
|
+
if (value === undefined || value === null || value === '') return;
|
|
64
|
+
const useUnit = DIMENSION_PROPS.has(key)
|
|
65
|
+
? addUnit(value as any, unit)
|
|
66
|
+
: value;
|
|
67
|
+
if (useUnit === undefined || useUnit === null || useUnit === '') return;
|
|
68
|
+
pairs.push(`${toKebab(key)}:${useUnit}`);
|
|
69
|
+
});
|
|
70
|
+
return pairs.join(';');
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const isObject = (
|
|
74
|
+
val: unknown
|
|
75
|
+
): val is Record<string, any> | any[] =>
|
|
76
|
+
Boolean(val) && typeof val === 'object';
|