km-card-layout-component-miniprogram 0.1.12 → 0.1.13

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.
@@ -1,10 +1,10 @@
1
1
  <view class="km-node km-node--text" style="{{wrapperStyle}}">
2
2
  <view class="km-node__text" style="{{contentStyle}}">
3
- <block wx:if="{{iconMeta && iconMeta.name}}">
3
+ <block wx:if="{{(iconMeta && (iconMeta.name || iconMeta.text)) || element.icon?.style!=='text'}}">
4
4
  <view class="km-node__text-content">
5
5
  <block wx:if="{{iconMeta.align === 'right'}}">
6
- <text class="km-node__text-value">{{textValue || ''}}</text>
7
- <view style="{{iconMeta.wrapperStyle}}" class="km-node__text-icon--wrapper" >
6
+ <text class="km-node__text-value">{{element.icon?.style==='text'&& element.icon.enable?`${element.label}:`:''}}{{textValue || ''}}</text>
7
+ <view style="{{iconMeta.wrapperStyle}}" class="km-node__text-icon--wrapper" >
8
8
  <text
9
9
  class="km-node__text-icon icon"
10
10
  style="font-size: {{iconMeta.size || '16px'}}; color: {{iconMeta.color || ''}}; margin-right: {{iconMeta.gap || ''}};"
@@ -23,7 +23,7 @@
23
23
  </view>
24
24
  </block>
25
25
  <block wx:else>
26
- <text class="km-node__text-value">{{textValue || ''}}</text>
26
+ <text class="km-node__text-value">{{element.icon?.style==='text'&& element.icon.enable?`${element.label}:`:''}}{{textValue || ''}}</text>
27
27
  </block>
28
28
  </view>
29
29
  </view>
@@ -20,6 +20,7 @@ function stripLayoutBindings(layouts = []) {
20
20
  }
21
21
  exports.stripLayoutBindings = stripLayoutBindings;
22
22
  function applyItemCollectBindings(layouts = [], items = []) {
23
+ console.log('applyItemCollectBindings', layouts, items);
23
24
  const targetLayouts = Array.isArray(layouts) ? layouts : [];
24
25
  const metaMap = new Map();
25
26
  const metaList = Array.isArray(items) ? items : [];
@@ -29,14 +30,13 @@ function applyItemCollectBindings(layouts = [], items = []) {
29
30
  }
30
31
  });
31
32
  const assignBinding = (el) => {
32
- var _a;
33
33
  const meta = metaMap.get(String(el.id));
34
34
  const binding = meta && meta.bind !== undefined && meta.bind !== null
35
35
  ? meta.bind
36
36
  : el.binding;
37
37
  const defaultValue = meta && meta.default !== undefined ? meta.default : el.defaultValue;
38
38
  const key = meta && meta.key !== undefined ? meta.key : el.key;
39
- const base = { ...el };
39
+ const base = { ...el, label: meta === null || meta === void 0 ? void 0 : meta.name };
40
40
  if (binding !== undefined)
41
41
  base.binding = binding;
42
42
  else
@@ -49,8 +49,10 @@ function applyItemCollectBindings(layouts = [], items = []) {
49
49
  base.key = key;
50
50
  else
51
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 };
52
+ if (el.type === 'text') {
53
+ // if (meta?.extra?.icon) {
54
+ // base.icon = { ...(base.icon || {}), name: meta.extra.icon };
55
+ // }
54
56
  }
55
57
  if (el.type === 'layout-panel') {
56
58
  return {
@@ -32,8 +32,12 @@ const buildCardStyle = (layout, unit = 'px') => ({
32
32
  exports.buildCardStyle = buildCardStyle;
33
33
  const buildBackgroundStyle = (layout, unit = 'px') => ({
34
34
  zIndex: layout.backgroundZIndex,
35
- width: '100%',
36
- height: '100%',
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%',
37
41
  position: 'absolute',
38
42
  left: 0,
39
43
  top: 0,
@@ -91,7 +95,6 @@ const buildImageContentStyle = (el, unit = 'px') => {
91
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
92
96
  ? (0, helpers_1.addUnit)(el.style.borderRadius, unit)
93
97
  : '0';
94
- console.log(style);
95
98
  return style;
96
99
  };
97
100
  exports.buildImageContentStyle = buildImageContentStyle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "km-card-layout-component-miniprogram",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "miniprogram": "miniprogram_dist",
@@ -1,10 +1,10 @@
1
1
  <view class="km-node km-node--text" style="{{wrapperStyle}}">
2
2
  <view class="km-node__text" style="{{contentStyle}}">
3
- <block wx:if="{{iconMeta && iconMeta.name}}">
3
+ <block wx:if="{{(iconMeta && (iconMeta.name || iconMeta.text)) || element.icon?.style!=='text'}}">
4
4
  <view class="km-node__text-content">
5
5
  <block wx:if="{{iconMeta.align === 'right'}}">
6
- <text class="km-node__text-value">{{textValue || ''}}</text>
7
- <view style="{{iconMeta.wrapperStyle}}" class="km-node__text-icon--wrapper" >
6
+ <text class="km-node__text-value">{{element.icon?.style==='text'&& element.icon.enable?`${element.label}:`:''}}{{textValue || ''}}</text>
7
+ <view style="{{iconMeta.wrapperStyle}}" class="km-node__text-icon--wrapper" >
8
8
  <text
9
9
  class="km-node__text-icon icon"
10
10
  style="font-size: {{iconMeta.size || '16px'}}; color: {{iconMeta.color || ''}}; margin-right: {{iconMeta.gap || ''}};"
@@ -23,7 +23,7 @@
23
23
  </view>
24
24
  </block>
25
25
  <block wx:else>
26
- <text class="km-node__text-value">{{textValue || ''}}</text>
26
+ <text class="km-node__text-value">{{element.icon?.style==='text'&& element.icon.enable?`${element.label}:`:''}}{{textValue || ''}}</text>
27
27
  </block>
28
28
  </view>
29
29
  </view>
@@ -26,6 +26,8 @@ export function applyItemCollectBindings(
26
26
  layouts: CardLayoutSchema[] = [],
27
27
  items: TemplateItem[] = []
28
28
  ): CardLayoutSchema[] {
29
+ console.log('applyItemCollectBindings', layouts, items);
30
+
29
31
  const targetLayouts = Array.isArray(layouts) ? layouts : [];
30
32
  const metaMap = new Map<string, TemplateItem>();
31
33
  const metaList = Array.isArray(items) ? items : [];
@@ -44,15 +46,17 @@ export function applyItemCollectBindings(
44
46
  const defaultValue =
45
47
  meta && meta.default !== undefined ? meta.default : el.defaultValue;
46
48
  const key = meta && meta.key !== undefined ? meta.key : el.key;
47
- const base: any = { ...el };
49
+ const base: any = { ...el, label: meta?.name };
48
50
  if (binding !== undefined) base.binding = binding;
49
51
  else delete base.binding;
50
52
  if (defaultValue !== undefined) base.defaultValue = defaultValue;
51
53
  else delete base.defaultValue;
52
54
  if (key !== undefined) base.key = key;
53
55
  else delete base.key;
54
- if (el.type === 'text' && meta?.extra?.icon) {
55
- base.icon = { ...(base.icon || {}), name: meta.extra.icon };
56
+ if (el.type === 'text') {
57
+ // if (meta?.extra?.icon) {
58
+ // base.icon = { ...(base.icon || {}), name: meta.extra.icon };
59
+ // }
56
60
  }
57
61
 
58
62
  if (el.type === 'layout-panel') {
@@ -61,6 +65,7 @@ export function applyItemCollectBindings(
61
65
  children: (el.children || []).map(assignBinding),
62
66
  } as CardElement;
63
67
  }
68
+
64
69
  return base as CardElement;
65
70
  };
66
71
 
@@ -32,7 +32,7 @@ export interface TextIconConfig {
32
32
  gap?: number;
33
33
  align?: 'left' | 'right';
34
34
  enable?: boolean;
35
- style?: 'fill' | 'dot' | 'line';
35
+ style?: 'fill' | 'dot' | 'line' | 'text';
36
36
  }
37
37
 
38
38
  export interface TextElement extends CardElementBase {
@@ -13,6 +13,8 @@ export interface CardLayoutSchema {
13
13
  padding?: number;
14
14
  children: CardElement[];
15
15
  thumbnail?: string;
16
+ backgroundWidth?: number;
17
+ backgroundHeight?: number;
16
18
  }
17
19
 
18
20
  export type CardLayoutInput = CardLayoutSchema[];
@@ -47,8 +47,12 @@ export const buildBackgroundStyle = (
47
47
  unit: 'px' | 'rpx' = 'px'
48
48
  ) => ({
49
49
  zIndex: layout.backgroundZIndex,
50
- width: '100%',
51
- height: '100%',
50
+ width: layout.backgroundWidth
51
+ ? addUnit(layout.backgroundWidth, unit)
52
+ : '100%',
53
+ height: layout.backgroundHeight
54
+ ? addUnit(layout.backgroundHeight, unit)
55
+ : '100%',
52
56
  position: 'absolute',
53
57
  left: 0,
54
58
  top: 0,
@@ -104,7 +108,10 @@ export const buildTextValueStyle = (
104
108
  return style;
105
109
  };
106
110
 
107
- export const buildImageContentStyle = (el: ImageElement, unit: 'px' | 'rpx' = 'px') => {
111
+ export const buildImageContentStyle = (
112
+ el: ImageElement,
113
+ unit: 'px' | 'rpx' = 'px'
114
+ ) => {
108
115
  const style: Record<string, any> = { ...(el.style || {}) };
109
116
  style.borderWidth =
110
117
  el.style?.borderWidth !== undefined && el.style?.borderWidth !== null
@@ -114,7 +121,6 @@ export const buildImageContentStyle = (el: ImageElement, unit: 'px' | 'rpx' = 'p
114
121
  el.style?.borderRadius !== undefined && el.style?.borderRadius !== null
115
122
  ? addUnit(el.style.borderRadius as any, unit)
116
123
  : '0';
117
- console.log(style);
118
124
  return style;
119
125
  };
120
126