@neovici/cosmoz-omnitable 12.14.0 → 12.16.0
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,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
prop, array
|
|
3
|
-
} from '@neovici/cosmoz-autocomplete/lib/utils';
|
|
1
|
+
import { prop, array } from '@neovici/cosmoz-autocomplete/lib/utils';
|
|
4
2
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
5
3
|
import { valuesFrom } from './lib/utils-data';
|
|
6
4
|
|
|
7
|
-
const
|
|
8
|
-
unique = (values, valueProperty) => {
|
|
5
|
+
const unique = (values, valueProperty) => {
|
|
9
6
|
if (!Array.isArray(values)) {
|
|
10
7
|
return;
|
|
11
8
|
}
|
|
@@ -13,7 +10,7 @@ const
|
|
|
13
10
|
return values
|
|
14
11
|
.reduce((acc, cur) => {
|
|
15
12
|
if (Array.isArray(cur)) {
|
|
16
|
-
cur.forEach(subcur => {
|
|
13
|
+
cur.forEach((subcur) => {
|
|
17
14
|
acc.push(subcur);
|
|
18
15
|
});
|
|
19
16
|
return acc;
|
|
@@ -35,7 +32,6 @@ const
|
|
|
35
32
|
return true;
|
|
36
33
|
});
|
|
37
34
|
},
|
|
38
|
-
|
|
39
35
|
toAutocompleteSource = (values, valueProperty, textProperty) => {
|
|
40
36
|
if (values == null) {
|
|
41
37
|
return [];
|
|
@@ -46,14 +42,12 @@ const
|
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
if (typeof values === 'object') {
|
|
49
|
-
const
|
|
50
|
-
valProp = valueProperty ?? 'id',
|
|
45
|
+
const valProp = valueProperty ?? 'id',
|
|
51
46
|
textProp = textProperty ?? 'label';
|
|
52
|
-
return Object
|
|
53
|
-
.entries(values)
|
|
47
|
+
return Object.entries(values)
|
|
54
48
|
.map(([id, label]) => ({
|
|
55
49
|
[valProp]: id,
|
|
56
|
-
[textProp]: label
|
|
50
|
+
[textProp]: label,
|
|
57
51
|
}))
|
|
58
52
|
.sort((a, b) => {
|
|
59
53
|
if (a[textProp] < b[textProp]) {
|
|
@@ -68,101 +62,142 @@ const
|
|
|
68
62
|
|
|
69
63
|
return [];
|
|
70
64
|
},
|
|
71
|
-
|
|
72
65
|
getTexts = (item, valuePath, textProperty) =>
|
|
73
66
|
array(valuePath && get(item, valuePath)).map(prop(textProperty)),
|
|
74
|
-
|
|
75
67
|
getString = ({ valuePath, textProperty }, item) => {
|
|
76
68
|
return getTexts(item, valuePath, textProperty)
|
|
77
|
-
.filter(i => i != null)
|
|
69
|
+
.filter((i) => i != null)
|
|
78
70
|
.join(', ');
|
|
79
71
|
},
|
|
80
|
-
|
|
81
72
|
toXlsxValue = getString,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
applyMultiFilter =
|
|
74
|
+
({ valueProperty, valuePath, emptyValue, emptyProperty }, filters) =>
|
|
75
|
+
(item) => {
|
|
76
|
+
const val = prop(valueProperty),
|
|
77
|
+
values = array(get(item, valuePath));
|
|
78
|
+
return filters.some(
|
|
79
|
+
(filter) =>
|
|
80
|
+
(values.length === 0 &&
|
|
81
|
+
prop(emptyProperty || valueProperty)(filter) === emptyValue) ||
|
|
82
|
+
values.some((value) => val(value) === val(filter))
|
|
83
|
+
);
|
|
84
|
+
},
|
|
85
|
+
onChange = (setState) => (value) =>
|
|
86
|
+
setState((state) => ({ ...state, filter: value })),
|
|
87
|
+
onFocus = (setState) => (focused) =>
|
|
88
|
+
setState((state) => ({ ...state, headerFocused: focused })),
|
|
89
|
+
onText = (setState) => (text) =>
|
|
90
|
+
setState((state) => ({ ...state, query: text })),
|
|
95
91
|
computeSource = (
|
|
96
|
-
{
|
|
92
|
+
{
|
|
93
|
+
valuePath,
|
|
94
|
+
valueProperty,
|
|
95
|
+
textProperty,
|
|
96
|
+
emptyLabel,
|
|
97
|
+
emptyValue,
|
|
98
|
+
emptyProperty,
|
|
99
|
+
},
|
|
97
100
|
data
|
|
98
101
|
) => {
|
|
99
102
|
const values = valuesFrom(data, valuePath),
|
|
100
103
|
source = toAutocompleteSource(values, valueProperty, textProperty);
|
|
101
104
|
|
|
102
|
-
if (
|
|
105
|
+
if (
|
|
106
|
+
!emptyLabel ||
|
|
107
|
+
emptyValue === undefined ||
|
|
108
|
+
!textProperty ||
|
|
109
|
+
!(emptyProperty || valueProperty) ||
|
|
110
|
+
source.length < 0
|
|
111
|
+
) {
|
|
103
112
|
return source;
|
|
104
113
|
}
|
|
105
|
-
return [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
return [
|
|
115
|
+
{
|
|
116
|
+
[textProperty]: emptyLabel,
|
|
117
|
+
[emptyProperty || valueProperty]: emptyValue,
|
|
118
|
+
},
|
|
119
|
+
...source,
|
|
120
|
+
];
|
|
109
121
|
},
|
|
122
|
+
listColumnMixin = (base) =>
|
|
123
|
+
class extends base {
|
|
124
|
+
static get properties() {
|
|
125
|
+
return {
|
|
126
|
+
textProperty: { type: String },
|
|
127
|
+
valueProperty: { type: String },
|
|
128
|
+
emptyLabel: { type: String },
|
|
129
|
+
emptyValue: { type: Object },
|
|
130
|
+
emptyProperty: { type: String },
|
|
131
|
+
};
|
|
132
|
+
}
|
|
110
133
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
getString(column, item) {
|
|
122
|
-
return getString(column, item);
|
|
123
|
-
}
|
|
134
|
+
getConfig(column) {
|
|
135
|
+
return {
|
|
136
|
+
valueProperty: column.valueProperty,
|
|
137
|
+
textProperty: column.textProperty,
|
|
138
|
+
emptyLabel: column.emptyLabel,
|
|
139
|
+
emptyValue: column.emptyValue,
|
|
140
|
+
emptyProperty: { type: String },
|
|
141
|
+
};
|
|
142
|
+
}
|
|
124
143
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
144
|
+
getString(column, item) {
|
|
145
|
+
return getString(column, item);
|
|
146
|
+
}
|
|
128
147
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
148
|
+
toXlsxValue(column, item) {
|
|
149
|
+
return toXlsxValue(column, item);
|
|
150
|
+
}
|
|
132
151
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (valueProperty == null) {
|
|
136
|
-
return value;
|
|
152
|
+
cellTitleFn(column, item) {
|
|
153
|
+
return getString(column, item);
|
|
137
154
|
}
|
|
138
|
-
const subValues = array(value).reduce((acc, subItem) => {
|
|
139
|
-
acc.push(get(subItem, valueProperty));
|
|
140
|
-
return acc;
|
|
141
|
-
}, []);
|
|
142
|
-
return subValues.sort().join(' ');
|
|
143
|
-
}
|
|
144
155
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
156
|
+
getComparableValue({ valuePath, valueProperty }, item) {
|
|
157
|
+
const value = get(item, valuePath);
|
|
158
|
+
if (valueProperty == null) {
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
const subValues = array(value).reduce((acc, subItem) => {
|
|
162
|
+
acc.push(get(subItem, valueProperty));
|
|
163
|
+
return acc;
|
|
164
|
+
}, []);
|
|
165
|
+
return subValues.sort().join(' ');
|
|
148
166
|
}
|
|
149
167
|
|
|
150
|
-
|
|
151
|
-
|
|
168
|
+
getFilterFn(column, filters) {
|
|
169
|
+
if (!filters || !Array.isArray(filters) || filters.length === 0) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
152
172
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
173
|
+
return applyMultiFilter(column, filters);
|
|
174
|
+
}
|
|
156
175
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
serializeFilter(column, filter) {
|
|
177
|
+
return filter.length === 0 ? null : JSON.stringify(filter);
|
|
178
|
+
}
|
|
160
179
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
: computeSource(column, data);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
180
|
+
deserializeFilter(column, filter) {
|
|
181
|
+
return JSON.parse(decodeURIComponent(filter));
|
|
182
|
+
}
|
|
167
183
|
|
|
168
|
-
|
|
184
|
+
computeSource(column, data) {
|
|
185
|
+
return column.externalValues || typeof column.values === 'function'
|
|
186
|
+
? column.values
|
|
187
|
+
: computeSource(column, data);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export {
|
|
192
|
+
unique,
|
|
193
|
+
getTexts,
|
|
194
|
+
getString,
|
|
195
|
+
toXlsxValue,
|
|
196
|
+
applyMultiFilter,
|
|
197
|
+
onChange,
|
|
198
|
+
onFocus,
|
|
199
|
+
onText,
|
|
200
|
+
computeSource,
|
|
201
|
+
toAutocompleteSource,
|
|
202
|
+
listColumnMixin,
|
|
203
|
+
};
|
|
@@ -32,6 +32,7 @@ export const getString = ({ valuePath }, item) => get(item, valuePath),
|
|
|
32
32
|
valuePath: { type: String, notify: true },
|
|
33
33
|
values: { type: Array, notify: true },
|
|
34
34
|
filter: { type: Object },
|
|
35
|
+
noLocalFilter: { type: Boolean },
|
|
35
36
|
/**
|
|
36
37
|
* If the column should be disabled until enabled with enabledColumns
|
|
37
38
|
*/
|
package/lib/use-dom-columns.js
CHANGED
|
@@ -83,6 +83,8 @@ const columnSymbol = Symbol('column'),
|
|
|
83
83
|
values: column.values,
|
|
84
84
|
source: memooize(column.computeSource),
|
|
85
85
|
|
|
86
|
+
noLocalFilter: column.noLocalFilter,
|
|
87
|
+
|
|
86
88
|
// @deprecated
|
|
87
89
|
loading: column.loading,
|
|
88
90
|
externalValues: column.externalValues,
|
|
@@ -92,12 +94,6 @@ const columnSymbol = Symbol('column'),
|
|
|
92
94
|
trueLabel: column.trueLabel,
|
|
93
95
|
falseLabel: column.falseLabel,
|
|
94
96
|
|
|
95
|
-
// list columns
|
|
96
|
-
valueProperty: column.valueProperty,
|
|
97
|
-
textProperty: column.textProperty,
|
|
98
|
-
emptyLabel: column.emptyLabel,
|
|
99
|
-
emptyValue: column.emptyValue,
|
|
100
|
-
|
|
101
97
|
// range columns
|
|
102
98
|
min: column.min,
|
|
103
99
|
max: column.max,
|
|
@@ -102,9 +102,10 @@ export const useProcessedItems = ({
|
|
|
102
102
|
columns
|
|
103
103
|
.map((col) => [
|
|
104
104
|
col.name,
|
|
105
|
-
col.
|
|
105
|
+
!col.noLocalFilter &&
|
|
106
|
+
col.getFilterFn(col, filters[col.name]?.filter),
|
|
106
107
|
])
|
|
107
|
-
.filter(([, fn]) => fn
|
|
108
|
+
.filter(([, fn]) => !!fn)
|
|
108
109
|
);
|
|
109
110
|
}, [columns, ...filterValues]),
|
|
110
111
|
filteredItems = useMemo(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.16.0",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|