km-card-layout-core 0.1.5 → 0.1.7

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/utils.js CHANGED
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.backgroundChange = backgroundChange;
4
4
  exports.stripLayoutBindings = stripLayoutBindings;
5
5
  exports.applyItemCollectBindings = applyItemCollectBindings;
6
+ exports.getTemplateItems = getTemplateItems;
7
+ exports.getTemplateBackgrounds = getTemplateBackgrounds;
6
8
  function backgroundChange(bg, layout) {
7
9
  const toNameArray = (name) => {
8
10
  if (Array.isArray(name))
@@ -119,3 +121,11 @@ function applyItemCollectBindings(layouts = [], items = []) {
119
121
  children: (layout.children || []).map(assignBinding),
120
122
  }));
121
123
  }
124
+ function getTemplateItems(ids, items) {
125
+ const idArray = ids.split(',').map(id => id.trim());
126
+ return items.filter(item => idArray.includes(String(item.id)));
127
+ }
128
+ function getTemplateBackgrounds(ids, items) {
129
+ const idArray = ids.split(',').map(id => id.trim());
130
+ return items.filter(item => idArray.includes(String(item.id)));
131
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "km-card-layout-core",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Shared render helpers for CardMaster layout JSON (binding resolution, layout normalization).",
5
5
  "main": "dist/index.js",
6
6
  "types": "types.d.ts",
package/types.d.ts CHANGED
@@ -14,13 +14,6 @@ import type {
14
14
  RenderResult,
15
15
  } from './interface';
16
16
 
17
- export type ItemCollectMeta = {
18
- id: string | number;
19
- bind?: string | null;
20
- default?: string | null;
21
- key?: string | null;
22
- };
23
-
24
17
  export function addUnit(
25
18
  value: string | number | undefined | null,
26
19
  unit: 'px' | 'rpx'
@@ -45,7 +38,7 @@ export function stripLayoutBindings(
45
38
 
46
39
  export function applyItemCollectBindings(
47
40
  layouts: CardLayoutSchema[],
48
- items?: ItemCollectMeta[]
41
+ items?: TemplateItem[]
49
42
  ): CardLayoutSchema[];
50
43
 
51
44
  export function buildRenderNodes(
@@ -60,3 +53,7 @@ export function buildRenderResult(
60
53
  data: Record<string, any>,
61
54
  unit?: 'px' | 'rpx'
62
55
  ): RenderResult;
56
+
57
+ export function getTemplateItems(ids: string, items: TemplateItem[]): TemplateItem[];
58
+
59
+ export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]) : TemplateBackground[];
package/utils.ts CHANGED
@@ -1,12 +1,6 @@
1
- import type { CardElement, CardLayoutSchema } from './interface';
1
+ import type { CardElement, CardLayoutSchema, TemplateItem } from './interface';
2
2
  import { TemplateBackground } from './interface/data/payload';
3
3
 
4
- export type ItemCollectMeta = {
5
- id: string | number;
6
- bind?: string | null;
7
- default?: string | null;
8
- key?: string | null;
9
- };
10
4
 
11
5
  export function backgroundChange(
12
6
  bg: TemplateBackground,
@@ -88,14 +82,14 @@ export function stripLayoutBindings(
88
82
  * 应用元素数据绑定字段
89
83
  * @param layouts 布局
90
84
  * @param items 绑定元素数据
91
- * @returns
85
+ * @returns
92
86
  */
93
87
  export function applyItemCollectBindings(
94
88
  layouts: CardLayoutSchema[] = [],
95
- items: ItemCollectMeta[] = []
89
+ items: TemplateItem[] = []
96
90
  ): CardLayoutSchema[] {
97
91
  const targetLayouts = Array.isArray(layouts) ? layouts : [];
98
- const metaMap = new Map<string, ItemCollectMeta>();
92
+ const metaMap = new Map<string, TemplateItem>();
99
93
  const metaList = Array.isArray(items) ? items : [];
100
94
  metaList.forEach(item => {
101
95
  if (item && item.id !== undefined && item.id !== null) {
@@ -103,7 +97,7 @@ export function applyItemCollectBindings(
103
97
  }
104
98
  });
105
99
 
106
- const assignBinding = (el: CardElement): CardElement => {
100
+ const assignBinding = (el: CardElement): CardElement => {
107
101
  const meta = metaMap.get(String(el.id));
108
102
  const binding =
109
103
  meta && meta.bind !== undefined && meta.bind !== null
@@ -134,3 +128,14 @@ export function applyItemCollectBindings(
134
128
  children: (layout.children || []).map(assignBinding),
135
129
  }));
136
130
  }
131
+
132
+ export function getTemplateItems(ids: string, items: TemplateItem[]) {
133
+ const idArray = ids.split(',').map(id => id.trim());
134
+ return items.filter(item => idArray.includes(String(item.id)));
135
+ }
136
+
137
+
138
+ export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]){
139
+ const idArray = ids.split(',').map(id => id.trim());
140
+ return items.filter(item => idArray.includes(String(item.id)));
141
+ }