@neovici/cosmoz-omnitable 14.12.1 → 14.12.3
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/README.md +1 -2
- package/cosmoz-omnitable-column-amount.js +1 -5
- package/cosmoz-omnitable-column-boolean.js +82 -63
- package/cosmoz-omnitable-column-date.js +1 -5
- package/cosmoz-omnitable-column-datetime.js +1 -6
- package/cosmoz-omnitable-column-list-data.js +57 -49
- package/cosmoz-omnitable-column-list-horizontal.js +42 -26
- package/cosmoz-omnitable-column-mixin.js +0 -1
- package/cosmoz-omnitable-column-time.js +1 -5
- package/cosmoz-omnitable-column.js +0 -1
- package/cosmoz-omnitable-group-row.js +10 -2
- package/cosmoz-omnitable-header-row.js +38 -49
- package/cosmoz-omnitable-item-expand-line.js +1 -1
- package/grouped-list/cosmoz-grouped-list-row.js +1 -1
- package/grouped-list/use-cosmoz-grouped-list.js +15 -28
- package/grouped-list/use-selected-items.js +25 -26
- package/grouped-list/use-weak-state.js +2 -2
- package/grouped-list/utils.js +11 -9
- package/lib/compute-layout.js +2 -1
- package/lib/cosmoz-omnitable-amount-range-input.js +102 -107
- package/lib/cosmoz-omnitable-date-input-mixin.js +20 -21
- package/lib/cosmoz-omnitable-date-range-input.js +85 -79
- package/lib/cosmoz-omnitable-datetime-range-input.js +85 -79
- package/lib/cosmoz-omnitable-number-range-input.js +35 -32
- package/lib/cosmoz-omnitable-range-input-mixin.js +19 -58
- package/lib/cosmoz-omnitable-time-range-input.js +54 -31
- package/lib/icons.js +0 -1
- package/lib/layout.js +12 -15
- package/lib/polymer-haunted-render-mixin.js +14 -13
- package/lib/save-as-csv-action.js +31 -27
- package/lib/save-as-xlsx-action.js +13 -11
- package/lib/settings/cosmoz-omnitable-settings.js +0 -1
- package/lib/settings/cosmoz-omnitable-sort-group.js +1 -1
- package/lib/settings/drivers/context.js +1 -1
- package/lib/settings/normalize.js +0 -1
- package/lib/settings/style.css.js +3 -2
- package/lib/settings/use-saved-settings.js +0 -1
- package/lib/settings/use-settings-ui.js +1 -6
- package/lib/use-dom-columns.js +0 -1
- package/lib/use-hash-state.js +1 -1
- package/lib/use-processed-items.js +23 -34
- package/lib/use-public-interface.js +0 -1
- package/lib/use-sort-and-group-options.js +2 -11
- package/lib/use-tween-array.js +0 -1
- package/lib/utils-amount.js +16 -32
- package/lib/utils-data.js +24 -24
- package/lib/utils-date.js +17 -34
- package/lib/utils-datetime.js +10 -15
- package/lib/utils-number.js +28 -29
- package/lib/utils-time.js +21 -24
- package/lib/utils.js +1 -1
- package/package.json +9 -3
package/lib/utils-amount.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
2
2
|
import { toNumber } from './utils-number';
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
/**
|
|
4
|
+
export const /**
|
|
6
5
|
* Converts a value to an amount object optionaly limiting it.
|
|
7
6
|
*
|
|
8
7
|
* @param {Object} rates The rates
|
|
@@ -11,12 +10,16 @@ export const
|
|
|
11
10
|
* @param {Function} limitFunc The function used to limit the number (Math.min|Math.max)
|
|
12
11
|
* @returns {Object|void} Value converted to Number or void
|
|
13
12
|
*/
|
|
14
|
-
toAmount = (rates = {}, value, limit, limitFunc) => {
|
|
13
|
+
toAmount = (rates = {}, value, limit, limitFunc) => {
|
|
15
14
|
if (value == null || value === '') {
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
if (
|
|
18
|
+
if (
|
|
19
|
+
typeof value !== 'object' ||
|
|
20
|
+
value.currency == null ||
|
|
21
|
+
value.currency === ''
|
|
22
|
+
) {
|
|
20
23
|
return null;
|
|
21
24
|
}
|
|
22
25
|
|
|
@@ -24,10 +27,7 @@ export const
|
|
|
24
27
|
if (number == null || Number.isNaN(number)) {
|
|
25
28
|
return null;
|
|
26
29
|
}
|
|
27
|
-
const amount = {
|
|
28
|
-
currency: value.currency,
|
|
29
|
-
amount: number
|
|
30
|
-
};
|
|
30
|
+
const amount = { currency: value.currency, amount: number };
|
|
31
31
|
|
|
32
32
|
if (limitFunc == null || limit == null) {
|
|
33
33
|
return amount;
|
|
@@ -38,13 +38,11 @@ export const
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// calculate value and limit amounts with rates
|
|
41
|
-
const
|
|
42
|
-
valAmount = amount.amount * (rates[amount.currency] || 1),
|
|
41
|
+
const valAmount = amount.amount * (rates[amount.currency] || 1),
|
|
43
42
|
limAmount = lAmount.amount * (rates[lAmount.currency] || 1),
|
|
44
43
|
lNumber = toNumber(valAmount, limAmount, limitFunc);
|
|
45
44
|
return lNumber === valAmount ? amount : lAmount;
|
|
46
45
|
},
|
|
47
|
-
|
|
48
46
|
getComparableValue = ({ valuePath, rates }, item) => {
|
|
49
47
|
if (item == null) {
|
|
50
48
|
return;
|
|
@@ -68,21 +66,18 @@ export const
|
|
|
68
66
|
|
|
69
67
|
return amount * (rates[value.currency] || 1);
|
|
70
68
|
},
|
|
71
|
-
|
|
72
|
-
applySingleFilter = (column, filter) => item => {
|
|
69
|
+
applySingleFilter = (column, filter) => (item) => {
|
|
73
70
|
const value = getComparableValue(column, item);
|
|
74
71
|
|
|
75
72
|
if (value == null) {
|
|
76
73
|
return false;
|
|
77
74
|
}
|
|
78
75
|
|
|
79
|
-
const
|
|
80
|
-
min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
76
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
81
77
|
max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
82
78
|
|
|
83
79
|
return !(value < min || value > max);
|
|
84
80
|
},
|
|
85
|
-
|
|
86
81
|
formatters = {},
|
|
87
82
|
getFormatter = (currency, locale) => {
|
|
88
83
|
const id = locale ? locale : '',
|
|
@@ -94,22 +89,18 @@ export const
|
|
|
94
89
|
|
|
95
90
|
formatters[key] = new Intl.NumberFormat(locale || undefined, {
|
|
96
91
|
style: 'currency',
|
|
97
|
-
currency
|
|
92
|
+
currency,
|
|
98
93
|
});
|
|
99
94
|
|
|
100
95
|
return formatters[key];
|
|
101
96
|
},
|
|
102
|
-
|
|
103
97
|
renderValue = (rates, value, locale) => {
|
|
104
98
|
const amount = toAmount(rates, value);
|
|
105
99
|
if (amount == null) {
|
|
106
100
|
return '';
|
|
107
101
|
}
|
|
108
|
-
return getFormatter(amount.currency, locale)
|
|
109
|
-
.format(amount.amount);
|
|
102
|
+
return getFormatter(amount.currency, locale).format(amount.amount);
|
|
110
103
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
104
|
getString = ({ valuePath, rates, locale }, item) => {
|
|
114
105
|
const value = toAmount(rates, get(item, valuePath));
|
|
115
106
|
if (value === undefined) {
|
|
@@ -120,15 +111,13 @@ export const
|
|
|
120
111
|
}
|
|
121
112
|
return renderValue(rates, value, locale);
|
|
122
113
|
},
|
|
123
|
-
|
|
124
|
-
toHashString = value => {
|
|
114
|
+
toHashString = (value) => {
|
|
125
115
|
if (!value) {
|
|
126
116
|
return '';
|
|
127
117
|
}
|
|
128
118
|
return value.amount + value.currency;
|
|
129
119
|
},
|
|
130
|
-
|
|
131
|
-
fromHashString = value => {
|
|
120
|
+
fromHashString = (value) => {
|
|
132
121
|
if (value == null || value === '') {
|
|
133
122
|
return;
|
|
134
123
|
}
|
|
@@ -136,12 +125,7 @@ export const
|
|
|
136
125
|
if (!Array.isArray(params) || params.length < 0) {
|
|
137
126
|
return null;
|
|
138
127
|
}
|
|
139
|
-
return {
|
|
140
|
-
amount: params[1],
|
|
141
|
-
currency: params[2]
|
|
142
|
-
};
|
|
128
|
+
return { amount: params[1], currency: params[2] };
|
|
143
129
|
},
|
|
144
|
-
|
|
145
130
|
getCurrency = ({ valuePath }, item) => get(item, valuePath)?.currency,
|
|
146
|
-
|
|
147
131
|
getInputString = ({ valuePath }, item) => get(item, valuePath)?.amount;
|
package/lib/utils-data.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { get, set } from '@polymer/polymer/lib/utils/path';
|
|
2
2
|
import { columnSymbol } from './use-dom-columns';
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
export const valuesFrom = (data, valuePath) =>
|
|
5
|
+
Array.isArray(data)
|
|
6
|
+
? data
|
|
7
|
+
.map((item) => get(item, valuePath))
|
|
8
|
+
.filter(
|
|
9
|
+
(value, index, self) =>
|
|
10
|
+
value != null && self.indexOf(value) === index,
|
|
11
|
+
)
|
|
12
|
+
: undefined,
|
|
12
13
|
defaultComputeSource = ({ externalValues, values, valuePath }, data) =>
|
|
13
14
|
externalValues || typeof values === 'function'
|
|
14
15
|
? values
|
|
15
16
|
: valuesFrom(data, valuePath),
|
|
16
|
-
|
|
17
17
|
onItemChange = (host, column, item, value) => {
|
|
18
|
-
const
|
|
19
|
-
{ valuePath } = column,
|
|
18
|
+
const { valuePath } = column,
|
|
20
19
|
oldValue = get(item, valuePath);
|
|
21
20
|
|
|
22
21
|
if (value === oldValue) {
|
|
@@ -25,18 +24,19 @@ export const
|
|
|
25
24
|
|
|
26
25
|
set(item, valuePath, value);
|
|
27
26
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
27
|
+
const change = {
|
|
28
|
+
item,
|
|
29
|
+
valuePath,
|
|
30
|
+
value,
|
|
31
|
+
oldValue,
|
|
32
|
+
column: column[columnSymbol],
|
|
33
|
+
};
|
|
36
34
|
|
|
37
|
-
host.dispatchEvent(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
host.dispatchEvent(
|
|
36
|
+
new CustomEvent('column-item-changed', {
|
|
37
|
+
bubbles: true,
|
|
38
|
+
composed: true,
|
|
39
|
+
detail: change,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
42
|
};
|
package/lib/utils-date.js
CHANGED
|
@@ -2,25 +2,23 @@ import { toLocalISOString, ensureDate } from '@neovici/cosmoz-utils/date';
|
|
|
2
2
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
3
|
import { toNumber } from './utils-number';
|
|
4
4
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
5
|
+
export const /**
|
|
9
6
|
* Calculates the local timezone offset and formats it to ISO Timezone string.
|
|
10
7
|
* @param {String} localISOString an ISO date string
|
|
11
8
|
* @return {String} the ISO timezone
|
|
12
9
|
*/
|
|
13
|
-
getTimezoneString = localISOString => {
|
|
10
|
+
getTimezoneString = (localISOString) => {
|
|
14
11
|
const off = -new Date(localISOString).getTimezoneOffset() / 60;
|
|
15
|
-
return (
|
|
12
|
+
return (
|
|
13
|
+
(off < 0 ? '-' : '+') + ['0', Math.abs(off)].join('').substr(-2) + ':00'
|
|
14
|
+
);
|
|
16
15
|
},
|
|
17
|
-
|
|
18
16
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
getAbsoluteISOString = localISOString => {
|
|
17
|
+
* Computes the local timezone and adds it to a local ISO string
|
|
18
|
+
* @param {String} localISOString an ISO date string, without timezone info
|
|
19
|
+
* @return {String} an ISO date string, with timezone info
|
|
20
|
+
*/
|
|
21
|
+
getAbsoluteISOString = (localISOString) => {
|
|
24
22
|
// Most browsers use local timezone when no timezone is specified
|
|
25
23
|
// but Safari uses UTC, so we set it implicitly
|
|
26
24
|
// TODO: Consider removing this when/if Safari handles local timezone correctly
|
|
@@ -29,8 +27,7 @@ export const
|
|
|
29
27
|
}
|
|
30
28
|
return localISOString;
|
|
31
29
|
},
|
|
32
|
-
|
|
33
|
-
parseDate = value => {
|
|
30
|
+
parseDate = (value) => {
|
|
34
31
|
if (value == null || value === '') {
|
|
35
32
|
return;
|
|
36
33
|
}
|
|
@@ -56,7 +53,6 @@ export const
|
|
|
56
53
|
|
|
57
54
|
return date;
|
|
58
55
|
},
|
|
59
|
-
|
|
60
56
|
/**
|
|
61
57
|
* Get comparable number from date
|
|
62
58
|
*
|
|
@@ -79,7 +75,6 @@ export const
|
|
|
79
75
|
}
|
|
80
76
|
return toNumber(value.getTime());
|
|
81
77
|
},
|
|
82
|
-
|
|
83
78
|
/**
|
|
84
79
|
* Converts an value to date optionaly limiting it.
|
|
85
80
|
*
|
|
@@ -88,7 +83,7 @@ export const
|
|
|
88
83
|
* @param {Function} limitFunc Function used to limit the date (Math.min|Math.max)
|
|
89
84
|
* @returns {Date|void} Value converted to date optionaly limitated
|
|
90
85
|
*/
|
|
91
|
-
toDate = (value, limit, limitFunc) => {
|
|
86
|
+
toDate = (value, limit, limitFunc) => {
|
|
92
87
|
const date = parseDate(value);
|
|
93
88
|
|
|
94
89
|
if (date == null) {
|
|
@@ -109,7 +104,6 @@ export const
|
|
|
109
104
|
limitedValue = limitFunc(comparableDate, comparableLDate);
|
|
110
105
|
return limitedValue === comparableDate ? date : lDate;
|
|
111
106
|
},
|
|
112
|
-
|
|
113
107
|
renderValue = (value, formatter) => {
|
|
114
108
|
if (formatter == null) {
|
|
115
109
|
return;
|
|
@@ -120,9 +114,8 @@ export const
|
|
|
120
114
|
}
|
|
121
115
|
return formatter.format(date);
|
|
122
116
|
},
|
|
123
|
-
|
|
124
117
|
formatters = {},
|
|
125
|
-
getFormatter = locale => {
|
|
118
|
+
getFormatter = (locale) => {
|
|
126
119
|
const key = locale || '';
|
|
127
120
|
|
|
128
121
|
if (formatters[key]) {
|
|
@@ -133,7 +126,6 @@ export const
|
|
|
133
126
|
|
|
134
127
|
return formatters[key];
|
|
135
128
|
},
|
|
136
|
-
|
|
137
129
|
getString = ({ valuePath, locale }, item) => {
|
|
138
130
|
let value = get(item, valuePath);
|
|
139
131
|
if (value === undefined) {
|
|
@@ -145,17 +137,14 @@ export const
|
|
|
145
137
|
}
|
|
146
138
|
return renderValue(value, getFormatter(locale));
|
|
147
139
|
},
|
|
148
|
-
|
|
149
|
-
toInputString = value => {
|
|
140
|
+
toInputString = (value) => {
|
|
150
141
|
const date = toDate(value);
|
|
151
142
|
if (date == null) {
|
|
152
143
|
return null;
|
|
153
144
|
}
|
|
154
145
|
return toLocalISOString(date).slice(0, 10);
|
|
155
146
|
},
|
|
156
|
-
|
|
157
147
|
getInputString = ({ valuePath }, item) => toInputString(get(item, valuePath)),
|
|
158
|
-
|
|
159
148
|
fromInputString = (value, property) => {
|
|
160
149
|
const date = toDate(value);
|
|
161
150
|
if (date == null) {
|
|
@@ -169,15 +158,13 @@ export const
|
|
|
169
158
|
}
|
|
170
159
|
return date;
|
|
171
160
|
},
|
|
172
|
-
|
|
173
|
-
toHashString = value => {
|
|
161
|
+
toHashString = (value) => {
|
|
174
162
|
const string = toInputString(value);
|
|
175
163
|
if (string == null) {
|
|
176
164
|
return '';
|
|
177
165
|
}
|
|
178
166
|
return string;
|
|
179
167
|
},
|
|
180
|
-
|
|
181
168
|
toXlsxValue = ({ valuePath }, item) => {
|
|
182
169
|
if (!valuePath) {
|
|
183
170
|
return '';
|
|
@@ -193,19 +180,15 @@ export const
|
|
|
193
180
|
localDate.setHours(0, 0, 0, 0);
|
|
194
181
|
return localDate;
|
|
195
182
|
},
|
|
196
|
-
|
|
197
|
-
applySingleFilter = (column, filter) => item => {
|
|
183
|
+
applySingleFilter = (column, filter) => (item) => {
|
|
198
184
|
const value = getComparableValue(column, item);
|
|
199
185
|
|
|
200
186
|
if (value == null) {
|
|
201
187
|
return false;
|
|
202
188
|
}
|
|
203
189
|
|
|
204
|
-
const
|
|
205
|
-
min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
190
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
206
191
|
max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
207
192
|
|
|
208
193
|
return !(value < min || value > max);
|
|
209
194
|
};
|
|
210
|
-
|
|
211
|
-
|
package/lib/utils-datetime.js
CHANGED
|
@@ -2,10 +2,8 @@ import { toLocalISOString } from '@neovici/cosmoz-utils/date';
|
|
|
2
2
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
3
|
import { renderValue, toDate } from './utils-date';
|
|
4
4
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
formatters = {},
|
|
8
|
-
getFormatter = locale => {
|
|
5
|
+
export const formatters = {},
|
|
6
|
+
getFormatter = (locale) => {
|
|
9
7
|
const key = locale || '';
|
|
10
8
|
|
|
11
9
|
if (formatters[key]) {
|
|
@@ -17,14 +15,16 @@ export const
|
|
|
17
15
|
month: 'numeric',
|
|
18
16
|
day: 'numeric',
|
|
19
17
|
hour: 'numeric',
|
|
20
|
-
minute: 'numeric'
|
|
18
|
+
minute: 'numeric',
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
formatters[key] = new Intl.DateTimeFormat(
|
|
21
|
+
formatters[key] = new Intl.DateTimeFormat(
|
|
22
|
+
locale || undefined,
|
|
23
|
+
timeFormatOption,
|
|
24
|
+
);
|
|
24
25
|
|
|
25
26
|
return formatters[key];
|
|
26
27
|
},
|
|
27
|
-
|
|
28
28
|
getString = ({ valuePath, locale }, item) => {
|
|
29
29
|
const value = toDate(get(item, valuePath));
|
|
30
30
|
if (value === undefined) {
|
|
@@ -35,15 +35,13 @@ export const
|
|
|
35
35
|
}
|
|
36
36
|
return renderValue(value, getFormatter(locale));
|
|
37
37
|
},
|
|
38
|
-
|
|
39
38
|
toXlsxValue = ({ valuePath }, item) => {
|
|
40
39
|
if (!valuePath) {
|
|
41
40
|
return '';
|
|
42
41
|
}
|
|
43
42
|
return get(item, valuePath);
|
|
44
43
|
},
|
|
45
|
-
|
|
46
|
-
toHashString = value => {
|
|
44
|
+
toHashString = (value) => {
|
|
47
45
|
const date = toDate(value);
|
|
48
46
|
if (date == null) {
|
|
49
47
|
return '';
|
|
@@ -51,21 +49,18 @@ export const
|
|
|
51
49
|
//Use utc in hash
|
|
52
50
|
return date.toISOString().slice(0, 19).replace(/:/gu, '.');
|
|
53
51
|
},
|
|
54
|
-
|
|
55
|
-
fromHashString = value => {
|
|
52
|
+
fromHashString = (value) => {
|
|
56
53
|
if (value == null || value === '') {
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
56
|
//Parse utc from hash string
|
|
60
57
|
return toDate(value.replace(/\./gu, ':') + 'Z');
|
|
61
58
|
},
|
|
62
|
-
|
|
63
|
-
toInputString = value => {
|
|
59
|
+
toInputString = (value) => {
|
|
64
60
|
const date = toDate(value);
|
|
65
61
|
if (date == null) {
|
|
66
62
|
return null;
|
|
67
63
|
}
|
|
68
64
|
return toLocalISOString(date).slice(0, 19);
|
|
69
65
|
},
|
|
70
|
-
|
|
71
66
|
getInputString = ({ valuePath }, item) => toInputString(get(item, valuePath));
|
package/lib/utils-number.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
2
|
import { memoooize } from '@neovici/cosmoz-utils/memoize';
|
|
4
3
|
|
|
5
|
-
export const
|
|
6
|
-
/**
|
|
4
|
+
export const /**
|
|
7
5
|
* Converts a value to number optionaly limiting it.
|
|
8
6
|
*
|
|
9
7
|
* @param {Number|*} value The value to convert to number
|
|
@@ -28,28 +26,24 @@ export const
|
|
|
28
26
|
}
|
|
29
27
|
return limitFunc(number, lNumber);
|
|
30
28
|
},
|
|
31
|
-
|
|
32
|
-
toInputString = value => {
|
|
29
|
+
toInputString = (value) => {
|
|
33
30
|
const val = toNumber(value);
|
|
34
31
|
if (val == null) {
|
|
35
32
|
return null;
|
|
36
33
|
}
|
|
37
34
|
return val.toString();
|
|
38
35
|
},
|
|
39
|
-
|
|
40
36
|
getInputString = ({ valuePath }, item) => {
|
|
41
37
|
const value = toNumber(get(item, valuePath));
|
|
42
38
|
return toInputString(value);
|
|
43
39
|
},
|
|
44
|
-
|
|
45
|
-
toHashString = value => {
|
|
40
|
+
toHashString = (value) => {
|
|
46
41
|
const string = toInputString(value);
|
|
47
42
|
if (string == null) {
|
|
48
43
|
return '';
|
|
49
44
|
}
|
|
50
45
|
return string;
|
|
51
46
|
},
|
|
52
|
-
|
|
53
47
|
getComparableValue = ({ valuePath, maximumFractionDigits }, item) => {
|
|
54
48
|
if (item == null) {
|
|
55
49
|
return;
|
|
@@ -68,21 +62,24 @@ export const
|
|
|
68
62
|
}
|
|
69
63
|
return value;
|
|
70
64
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
getString = (
|
|
65
|
+
makeFormatter = memoooize(
|
|
66
|
+
(locale, minimumFractionDigits, maximumFractionDigits) => {
|
|
67
|
+
const options = {
|
|
68
|
+
localeMatcher: 'best fit', // chrome expects this when using custom options
|
|
69
|
+
};
|
|
70
|
+
if (minimumFractionDigits !== null) {
|
|
71
|
+
options.minimumFractionDigits = minimumFractionDigits;
|
|
72
|
+
}
|
|
73
|
+
if (maximumFractionDigits !== null) {
|
|
74
|
+
options.maximumFractionDigits = maximumFractionDigits;
|
|
75
|
+
}
|
|
76
|
+
return new Intl.NumberFormat(locale || undefined, options);
|
|
77
|
+
},
|
|
78
|
+
),
|
|
79
|
+
getString = (
|
|
80
|
+
{ valuePath, locale, minimumFractionDigits, maximumFractionDigits },
|
|
81
|
+
item,
|
|
82
|
+
) => {
|
|
86
83
|
const value = get(item, valuePath);
|
|
87
84
|
|
|
88
85
|
if (value == null) {
|
|
@@ -93,19 +90,21 @@ export const
|
|
|
93
90
|
if (number == null) {
|
|
94
91
|
return;
|
|
95
92
|
}
|
|
96
|
-
const formatter = makeFormatter(
|
|
93
|
+
const formatter = makeFormatter(
|
|
94
|
+
locale,
|
|
95
|
+
minimumFractionDigits,
|
|
96
|
+
maximumFractionDigits,
|
|
97
|
+
);
|
|
97
98
|
return formatter.format(number);
|
|
98
99
|
},
|
|
99
|
-
|
|
100
|
-
applySingleFilter = (column, filter) => item => {
|
|
100
|
+
applySingleFilter = (column, filter) => (item) => {
|
|
101
101
|
const value = getComparableValue(column, item);
|
|
102
102
|
|
|
103
103
|
if (value == null) {
|
|
104
104
|
return false;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const
|
|
108
|
-
min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
107
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
109
108
|
max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
110
109
|
|
|
111
110
|
return !(value < min || value > max);
|
package/lib/utils-time.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { toLocalISOString } from '@neovici/cosmoz-utils/date';
|
|
2
2
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getAbsoluteISOString,
|
|
5
|
+
renderValue,
|
|
6
|
+
toDate as superToDate,
|
|
7
|
+
} from './utils-date';
|
|
4
8
|
import { toNumber } from './utils-number';
|
|
5
9
|
|
|
6
|
-
export const
|
|
7
|
-
|
|
8
|
-
_fixedDate = '1970-01-01',
|
|
9
|
-
|
|
10
|
+
export const _fixedDate = '1970-01-01',
|
|
10
11
|
/**
|
|
11
12
|
* Converts time to date optionaly limiting it.
|
|
12
13
|
*
|
|
@@ -19,14 +20,14 @@ export const
|
|
|
19
20
|
// Most browsers use local timezone when no timezone is specified
|
|
20
21
|
// but Safari uses UTC, so we set it implicitly
|
|
21
22
|
// TODO: Consider removing this when/if Safari handles local timezone correctly
|
|
22
|
-
const date =
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const date =
|
|
24
|
+
typeof value === 'string' && value.length > 3 && value.length <= 9
|
|
25
|
+
? getAbsoluteISOString(_fixedDate + 'T' + value)
|
|
26
|
+
: value;
|
|
25
27
|
return superToDate(date, limit, limitFunc);
|
|
26
28
|
},
|
|
27
|
-
|
|
28
29
|
formatters = {},
|
|
29
|
-
getFormatter = locale => {
|
|
30
|
+
getFormatter = (locale) => {
|
|
30
31
|
const key = locale || '';
|
|
31
32
|
|
|
32
33
|
if (formatters[key]) {
|
|
@@ -36,9 +37,12 @@ export const
|
|
|
36
37
|
const timeFormatOption = {
|
|
37
38
|
hour: 'numeric',
|
|
38
39
|
minute: 'numeric',
|
|
39
|
-
second: 'numeric'
|
|
40
|
+
second: 'numeric',
|
|
40
41
|
};
|
|
41
|
-
formatters[key] = new Intl.DateTimeFormat(
|
|
42
|
+
formatters[key] = new Intl.DateTimeFormat(
|
|
43
|
+
locale || undefined,
|
|
44
|
+
timeFormatOption,
|
|
45
|
+
);
|
|
42
46
|
|
|
43
47
|
return formatters[key];
|
|
44
48
|
},
|
|
@@ -52,21 +56,19 @@ export const
|
|
|
52
56
|
}
|
|
53
57
|
return renderValue(value, getFormatter(locale));
|
|
54
58
|
},
|
|
55
|
-
|
|
56
59
|
toXlsxValue = (column, item) => {
|
|
57
60
|
if (!column.valuePath) {
|
|
58
61
|
return '';
|
|
59
62
|
}
|
|
60
63
|
return getString(column, item);
|
|
61
64
|
},
|
|
62
|
-
toInputString = value => {
|
|
65
|
+
toInputString = (value) => {
|
|
63
66
|
const date = toDate(value);
|
|
64
67
|
if (date == null) {
|
|
65
68
|
return null;
|
|
66
69
|
}
|
|
67
70
|
return toLocalISOString(date).slice(11, 19);
|
|
68
71
|
},
|
|
69
|
-
|
|
70
72
|
getComparableValue = ({ valuePath }, item) => {
|
|
71
73
|
if (item == null) {
|
|
72
74
|
return;
|
|
@@ -81,22 +83,19 @@ export const
|
|
|
81
83
|
}
|
|
82
84
|
return toNumber(value.getTime());
|
|
83
85
|
},
|
|
84
|
-
|
|
85
|
-
applySingleFilter = (column, filter) => item => {
|
|
86
|
+
applySingleFilter = (column, filter) => (item) => {
|
|
86
87
|
const value = getComparableValue(column, item);
|
|
87
88
|
|
|
88
89
|
if (value == null) {
|
|
89
90
|
return false;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
const
|
|
93
|
-
min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
93
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
94
94
|
max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
95
95
|
|
|
96
96
|
return !(value < min || value > max);
|
|
97
97
|
},
|
|
98
|
-
|
|
99
|
-
toHashString = value => {
|
|
98
|
+
toHashString = (value) => {
|
|
100
99
|
const date = toDate(value);
|
|
101
100
|
if (date == null) {
|
|
102
101
|
return '';
|
|
@@ -104,12 +103,10 @@ export const
|
|
|
104
103
|
//Use utc in hash
|
|
105
104
|
return date.toISOString().slice(11, 19).replace(/:/gu, '.');
|
|
106
105
|
},
|
|
107
|
-
|
|
108
|
-
fromHashString = value => {
|
|
106
|
+
fromHashString = (value) => {
|
|
109
107
|
if (value == null || value === '') {
|
|
110
108
|
return;
|
|
111
109
|
}
|
|
112
110
|
//Parse utc from hash string
|
|
113
111
|
return toDate(value.replace(/\./gu, ':') + 'Z');
|
|
114
112
|
};
|
|
115
|
-
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "14.12.
|
|
3
|
+
"version": "14.12.3",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"start": "wds",
|
|
31
31
|
"test": "wtr --coverage",
|
|
32
32
|
"test:watch": "wtr --watch",
|
|
33
|
+
"storybook:start": "storybook dev -p 8000",
|
|
34
|
+
"storybook:build": "storybook build",
|
|
35
|
+
"storybook:deploy": "storybook-to-ghpages",
|
|
36
|
+
"storybook:preview": "npm run storybook:build && web-dev-server --root-dir ./storybook-static/ --open",
|
|
33
37
|
"prepare": "husky"
|
|
34
38
|
},
|
|
35
39
|
"release": {
|
|
@@ -82,7 +86,7 @@
|
|
|
82
86
|
"devDependencies": {
|
|
83
87
|
"@commitlint/cli": "^19.0.0",
|
|
84
88
|
"@commitlint/config-conventional": "^19.0.0",
|
|
85
|
-
"@neovici/cfg": "^
|
|
89
|
+
"@neovici/cfg": "^2.5.1",
|
|
86
90
|
"@neovici/cosmoz-viewinfo": "^4.0.0",
|
|
87
91
|
"@open-wc/testing": "^4.0.0",
|
|
88
92
|
"@polymer/iron-test-helpers": "^3.0.0",
|
|
@@ -92,8 +96,10 @@
|
|
|
92
96
|
"@polymer/paper-toggle-button": "^3.0.0",
|
|
93
97
|
"@semantic-release/changelog": "^6.0.0",
|
|
94
98
|
"@semantic-release/git": "^10.0.0",
|
|
99
|
+
"@storybook/web-components-vite": "^9.1.3",
|
|
95
100
|
"husky": "^9.0.0",
|
|
96
101
|
"semantic-release": "^24.0.0",
|
|
97
|
-
"sinon": "^20.0.0"
|
|
102
|
+
"sinon": "^20.0.0",
|
|
103
|
+
"storybook": "^9.1.3"
|
|
98
104
|
}
|
|
99
105
|
}
|