km-card-layout-core 0.1.25 → 0.1.26
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/data.ts +1 -3
- package/dist/data.js +1 -1
- package/dist/interface/index.js +0 -1
- package/dist/render/helpers.js +14 -4
- package/interface/index.ts +0 -1
- package/package.json +1 -1
- package/render/helpers.ts +21 -6
- package/types.d.ts +5 -5
- package/interface/context.ts +0 -6
package/data.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isObject } from './helpers';
|
|
2
|
-
import type { BindingContext } from './interface';
|
|
3
2
|
|
|
4
3
|
const pathToSegments = (path: string): string[] =>
|
|
5
4
|
`${path || ''}`
|
|
@@ -30,8 +29,7 @@ const readByPath = (data: any, path: string): any => {
|
|
|
30
29
|
|
|
31
30
|
export const resolveBindingValue = (
|
|
32
31
|
binding: string | undefined,
|
|
33
|
-
rootData: Record<string, any
|
|
34
|
-
context?: BindingContext
|
|
32
|
+
rootData: Record<string, any>
|
|
35
33
|
): any => {
|
|
36
34
|
if (!binding) return undefined;
|
|
37
35
|
const value = readByPath(rootData, binding);
|
package/dist/data.js
CHANGED
|
@@ -29,7 +29,7 @@ const readByPath = (data, path) => {
|
|
|
29
29
|
}
|
|
30
30
|
return cursor;
|
|
31
31
|
};
|
|
32
|
-
const resolveBindingValue = (binding, rootData
|
|
32
|
+
const resolveBindingValue = (binding, rootData) => {
|
|
33
33
|
if (!binding)
|
|
34
34
|
return undefined;
|
|
35
35
|
const value = readByPath(rootData, binding);
|
package/dist/interface/index.js
CHANGED
package/dist/render/helpers.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = void 0;
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
const layout_1 = require("../layout");
|
|
6
|
+
const data_1 = require("../data");
|
|
6
7
|
const buildWrapperStyle = (el, unit = 'px') => {
|
|
7
8
|
const abs = (0, layout_1.getAbsLayout)(el);
|
|
8
9
|
if (!abs)
|
|
@@ -87,11 +88,20 @@ const buildImageContentStyle = (el) => {
|
|
|
87
88
|
return style;
|
|
88
89
|
};
|
|
89
90
|
exports.buildImageContentStyle = buildImageContentStyle;
|
|
90
|
-
const getTextValue = (el) =>
|
|
91
|
-
?
|
|
92
|
-
|
|
91
|
+
const getTextValue = (el, data) => {
|
|
92
|
+
const bound = el.binding && data ? (0, data_1.resolveBindingValue)(el.binding, data) : undefined;
|
|
93
|
+
const val = bound !== undefined && bound !== null
|
|
94
|
+
? bound
|
|
95
|
+
: el.defaultValue !== undefined && el.defaultValue !== null
|
|
96
|
+
? el.defaultValue
|
|
97
|
+
: '';
|
|
98
|
+
return `${val !== null && val !== void 0 ? val : ''}`;
|
|
99
|
+
};
|
|
93
100
|
exports.getTextValue = getTextValue;
|
|
94
|
-
const getImageSrc = (el) =>
|
|
101
|
+
const getImageSrc = (el, data) => {
|
|
102
|
+
const bound = el.binding && data ? (0, data_1.resolveBindingValue)(el.binding, data) : undefined;
|
|
103
|
+
return bound || el.defaultUrl || el.defaultValue || '';
|
|
104
|
+
};
|
|
95
105
|
exports.getImageSrc = getImageSrc;
|
|
96
106
|
const getIconName = (el) => (el.name || el.defaultValue || '');
|
|
97
107
|
exports.getIconName = getIconName;
|
package/interface/index.ts
CHANGED
package/package.json
CHANGED
package/render/helpers.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { addUnit } from '../helpers';
|
|
2
2
|
import { getAbsLayout } from '../layout';
|
|
3
|
+
import { resolveBindingValue } from '../data';
|
|
3
4
|
import type {
|
|
4
5
|
CardElement,
|
|
5
6
|
CardLayoutSchema,
|
|
@@ -93,13 +94,27 @@ export const buildImageContentStyle = (el: ImageElement) => {
|
|
|
93
94
|
return style;
|
|
94
95
|
};
|
|
95
96
|
|
|
96
|
-
export const getTextValue = (
|
|
97
|
-
el
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
export const getTextValue = (
|
|
98
|
+
el: TextElement,
|
|
99
|
+
data?: Record<string, any>
|
|
100
|
+
) => {
|
|
101
|
+
const bound = el.binding && data ? resolveBindingValue(el.binding, data) : undefined;
|
|
102
|
+
const val =
|
|
103
|
+
bound !== undefined && bound !== null
|
|
104
|
+
? bound
|
|
105
|
+
: el.defaultValue !== undefined && el.defaultValue !== null
|
|
106
|
+
? el.defaultValue
|
|
107
|
+
: '';
|
|
108
|
+
return `${val ?? ''}`;
|
|
109
|
+
};
|
|
100
110
|
|
|
101
|
-
export const getImageSrc = (
|
|
102
|
-
el
|
|
111
|
+
export const getImageSrc = (
|
|
112
|
+
el: ImageElement,
|
|
113
|
+
data?: Record<string, any>
|
|
114
|
+
) => {
|
|
115
|
+
const bound = el.binding && data ? resolveBindingValue(el.binding, data) : undefined;
|
|
116
|
+
return (bound as any) || el.defaultUrl || el.defaultValue || '';
|
|
117
|
+
};
|
|
103
118
|
|
|
104
119
|
export const getIconName = (el: IconElement) =>
|
|
105
120
|
(el.name || el.defaultValue || '') as string;
|
package/types.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
export * from './interface';
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
|
-
BindingContext,
|
|
10
9
|
CardElement,
|
|
11
10
|
CardLayoutInput,
|
|
12
11
|
CardLayoutSchema,
|
|
@@ -66,8 +65,7 @@ export function areChildrenEqual(
|
|
|
66
65
|
|
|
67
66
|
export function resolveBindingValue(
|
|
68
67
|
binding: string | undefined,
|
|
69
|
-
rootData: Record<string, any
|
|
70
|
-
context?: BindingContext
|
|
68
|
+
rootData: Record<string, any>
|
|
71
69
|
): any;
|
|
72
70
|
|
|
73
71
|
export function stripLayoutBindings(
|
|
@@ -180,11 +178,13 @@ export function buildImageContentStyle(
|
|
|
180
178
|
): Record<string, any>;
|
|
181
179
|
|
|
182
180
|
export function getTextValue(
|
|
183
|
-
el: import('./interface/elements').TextElement
|
|
181
|
+
el: import('./interface/elements').TextElement,
|
|
182
|
+
data?: Record<string, any>
|
|
184
183
|
): string;
|
|
185
184
|
|
|
186
185
|
export function getImageSrc(
|
|
187
|
-
el: import('./interface/elements').ImageElement
|
|
186
|
+
el: import('./interface/elements').ImageElement,
|
|
187
|
+
data?: Record<string, any>
|
|
188
188
|
): string;
|
|
189
189
|
|
|
190
190
|
export function getIconName(
|