commonUtil.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
export function toArray(value) {
if (Array.isArray(value)) {
return value;
}
return value !== undefined ? [value] : [];
}
/**
* Convert outer props value into internal value
*/
export function toInnerValue(value, _ref) {
var labelInValue = _ref.labelInValue,
combobox = _ref.combobox;
if (value === undefined || value === '' && combobox) {
return [];
}
var values = Array.isArray(value) ? value : [value];
if (labelInValue) {
return values.map(function (_ref2) {
var key = _ref2.key,
val = _ref2.value;
return val !== undefined ? val : key;
});
}
return values;
}
/**
* Convert internal value into out event value
*/
export function toOuterValues(valueList, _ref3) {
var optionLabelProp = _ref3.optionLabelProp,
labelInValue = _ref3.labelInValue,
prevValue = _ref3.prevValue,
options = _ref3.options,
getLabeledValue = _ref3.getLabeledValue;
var values = valueList;
if (labelInValue) {
values = values.map(function (val) {
return getLabeledValue(val, {
options: options,
prevValue: prevValue,
labelInValue: labelInValue,
optionLabelProp: optionLabelProp
});
});
}
return values;
}
export function removeLastEnabledValue(measureValues, values) {
var newValues = _toConsumableArray(values);
var removeIndex;
for (removeIndex = measureValues.length - 1; removeIndex >= 0; removeIndex -= 1) {
if (!measureValues[removeIndex].disabled) {
break;
}
}
var removedValue = null;
if (removeIndex !== -1) {
removedValue = newValues[removeIndex];
newValues.splice(removeIndex, 1);
}
return {
values: newValues,
removedValue: removedValue
};
}
export var isClient = typeof window !== 'undefined' && window.document && window.document.documentElement;
/** Is client side and not jsdom */
export var isBrowserClient = process.env.NODE_ENV !== 'test' && isClient;
var uuid = 0;
/** Get unique id for accessibility usage */
export function getUUID() {
var retId; // Test never reach
/* istanbul ignore if */
if (isBrowserClient) {
retId = uuid;
uuid += 1;
} else {
retId = 'TEST_OR_SSR';
}
return retId;
}