@neovici/cosmoz-omnitable 12.15.0 → 12.17.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,138 @@ 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
|
-
emptyLabel: { type: String },
|
|
117
|
-
emptyValue: { type: Object }
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getString(column, item) {
|
|
122
|
-
return getString(column, item);
|
|
123
|
-
}
|
|
134
|
+
getConfig(column) {
|
|
135
|
+
return {
|
|
136
|
+
emptyProperty: column.emptyProperty,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
124
139
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
140
|
+
getString(column, item) {
|
|
141
|
+
return getString(column, item);
|
|
142
|
+
}
|
|
128
143
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
toXlsxValue(column, item) {
|
|
145
|
+
return toXlsxValue(column, item);
|
|
146
|
+
}
|
|
132
147
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (valueProperty == null) {
|
|
136
|
-
return value;
|
|
148
|
+
cellTitleFn(column, item) {
|
|
149
|
+
return getString(column, item);
|
|
137
150
|
}
|
|
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
151
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
getComparableValue({ valuePath, valueProperty }, item) {
|
|
153
|
+
const value = get(item, valuePath);
|
|
154
|
+
if (valueProperty == null) {
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
const subValues = array(value).reduce((acc, subItem) => {
|
|
158
|
+
acc.push(get(subItem, valueProperty));
|
|
159
|
+
return acc;
|
|
160
|
+
}, []);
|
|
161
|
+
return subValues.sort().join(' ');
|
|
148
162
|
}
|
|
149
163
|
|
|
150
|
-
|
|
151
|
-
|
|
164
|
+
getFilterFn(column, filters) {
|
|
165
|
+
if (!filters || !Array.isArray(filters) || filters.length === 0) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
152
168
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
169
|
+
return applyMultiFilter(column, filters);
|
|
170
|
+
}
|
|
156
171
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
172
|
+
serializeFilter(column, filter) {
|
|
173
|
+
return filter.length === 0 ? null : JSON.stringify(filter);
|
|
174
|
+
}
|
|
160
175
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
: computeSource(column, data);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
176
|
+
deserializeFilter(column, filter) {
|
|
177
|
+
return JSON.parse(decodeURIComponent(filter));
|
|
178
|
+
}
|
|
167
179
|
|
|
168
|
-
|
|
180
|
+
computeSource(column, data) {
|
|
181
|
+
return column.externalValues || typeof column.values === 'function'
|
|
182
|
+
? column.values
|
|
183
|
+
: computeSource(column, data);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export {
|
|
188
|
+
unique,
|
|
189
|
+
getTexts,
|
|
190
|
+
getString,
|
|
191
|
+
toXlsxValue,
|
|
192
|
+
applyMultiFilter,
|
|
193
|
+
onChange,
|
|
194
|
+
onFocus,
|
|
195
|
+
onText,
|
|
196
|
+
computeSource,
|
|
197
|
+
toAutocompleteSource,
|
|
198
|
+
listColumnMixin,
|
|
199
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.17.0",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|