@eox/itemfilter 1.16.0 → 1.17.1
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/dist/eox-itemfilter.js +1673 -1596
- package/dist/eox-itemfilter.umd.cjs +79 -42
- package/package.json +4 -3
- package/src/components/filters/range.js +83 -14
- package/src/components/filters/selector.js +6 -1
- package/src/components/filters/spatial.js +1 -1
- package/src/components/filters/text.js +4 -2
- package/src/enums/config.js +2 -0
- package/src/enums/index.js +1 -1
- package/src/helpers/filter-client.js +1 -1
- package/src/helpers/index.js +1 -0
- package/src/helpers/is-date.js +9 -0
- package/src/main.js +30 -4
- package/src/methods/filters/range.js +73 -31
- package/src/methods/itemfilter/create-filter.js +4 -0
- package/src/methods/itemfilter/filter-apply.js +58 -4
- package/src/style.eox.js +16 -0
- package/types/components/filters/range.d.ts +17 -0
- package/types/components/filters/range.d.ts.map +1 -1
- package/types/components/filters/selector.d.ts.map +1 -1
- package/types/components/filters/text.d.ts.map +1 -1
- package/types/enums/config.d.ts +1 -0
- package/types/enums/config.d.ts.map +1 -1
- package/types/enums/index.d.ts +1 -1
- package/types/helpers/index.d.ts +1 -0
- package/types/helpers/is-date.d.ts +8 -0
- package/types/helpers/is-date.d.ts.map +1 -0
- package/types/main.d.ts.map +1 -1
- package/types/methods/filters/range.d.ts.map +1 -1
- package/types/methods/itemfilter/create-filter.d.ts.map +1 -1
- package/types/methods/itemfilter/filter-apply.d.ts.map +1 -1
- package/types/style.eox.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eox/itemfilter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/geojson": "^7946.0.14",
|
|
11
11
|
"@types/lodash.debounce": "^4.0.7",
|
|
12
|
-
"vite": "^8.0.
|
|
12
|
+
"vite": "^8.0.12"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"npm": ">=8.0.0",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@eox/layout": "*",
|
|
57
|
-
"@eox/map": ">=2.0.0 || >=2.1.0-dev.1"
|
|
57
|
+
"@eox/map": ">=2.0.0 || >=2.1.0-dev.1",
|
|
58
|
+
"@eox/timecontrol": ">=2.0.0"
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -2,11 +2,14 @@ import { LitElement, html } from "lit";
|
|
|
2
2
|
import { when } from "lit/directives/when.js";
|
|
3
3
|
import _debounce from "lodash.debounce";
|
|
4
4
|
import "toolcool-range-slider";
|
|
5
|
+
import dayjs from "dayjs";
|
|
6
|
+
import { DATE_TIME_FORMAT } from "../../enums/index.js";
|
|
5
7
|
import {
|
|
6
8
|
rangeInputHandlerMethod,
|
|
7
9
|
rangeLabelMethod,
|
|
8
10
|
resetRangeMethod,
|
|
9
11
|
} from "../../methods/filters/index.js";
|
|
12
|
+
import { isDate } from "../../helpers/index.js";
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* EOxItemFilterRange is a custom web component that provides a range slider for filtering items.
|
|
@@ -16,13 +19,16 @@ import {
|
|
|
16
19
|
* @module EOxItemFilterRange
|
|
17
20
|
* @extends LitElement
|
|
18
21
|
* @property {Object} filterObject - The filter object containing state and range limits.
|
|
22
|
+
* @property {Array} suggestions - The list of suggestions for the selector.
|
|
19
23
|
* @property {Number} tabIndex - The tab index for the input elements.
|
|
20
24
|
*/
|
|
21
25
|
export class EOxItemFilterRange extends LitElement {
|
|
22
26
|
// Define properties with defaults and types
|
|
23
27
|
static properties = {
|
|
24
28
|
filterObject: { attribute: false, type: Object },
|
|
29
|
+
suggestions: { attribute: false, type: Array },
|
|
25
30
|
tabIndex: { attribute: false, type: Number },
|
|
31
|
+
inlineMode: { attribute: "inline-mode", type: Boolean },
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
constructor() {
|
|
@@ -33,11 +39,21 @@ export class EOxItemFilterRange extends LitElement {
|
|
|
33
39
|
*/
|
|
34
40
|
this.filterObject = {};
|
|
35
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @type Array
|
|
44
|
+
*/
|
|
45
|
+
this.suggestions = [];
|
|
46
|
+
|
|
36
47
|
/**
|
|
37
48
|
* @type Boolean
|
|
38
49
|
*/
|
|
39
50
|
this.tabIndex = 0;
|
|
40
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @type Boolean
|
|
54
|
+
*/
|
|
55
|
+
this.inlineMode = false;
|
|
56
|
+
|
|
41
57
|
/**
|
|
42
58
|
* @type {(evt: CustomEvent<any>) => void}
|
|
43
59
|
*/
|
|
@@ -94,20 +110,73 @@ export class EOxItemFilterRange extends LitElement {
|
|
|
94
110
|
return when(
|
|
95
111
|
this.filterObject,
|
|
96
112
|
() => html`
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
${when(
|
|
114
|
+
isDate(this.filterObject),
|
|
115
|
+
() => html`
|
|
116
|
+
<eox-timecontrol
|
|
117
|
+
.controlValues=${[
|
|
118
|
+
{
|
|
119
|
+
id: this.filterObject.key,
|
|
120
|
+
title: this.filterObject.title || "Filter",
|
|
121
|
+
timeControlValues: (
|
|
122
|
+
this.filterObject.filterKeys ||
|
|
123
|
+
this.suggestions ||
|
|
124
|
+
[]
|
|
125
|
+
).map((item) =>
|
|
126
|
+
typeof item === "object" ? item : { date: item },
|
|
127
|
+
),
|
|
128
|
+
},
|
|
129
|
+
]}
|
|
130
|
+
.initDate=${[
|
|
131
|
+
dayjs(
|
|
132
|
+
this.filterObject.state.min || this.filterObject.min,
|
|
133
|
+
).format(),
|
|
134
|
+
dayjs(
|
|
135
|
+
this.filterObject.state.max || this.filterObject.max,
|
|
136
|
+
).format(),
|
|
137
|
+
]}
|
|
138
|
+
@select=${(e) =>
|
|
139
|
+
rangeInputHandlerMethod(
|
|
140
|
+
new CustomEvent("values", {
|
|
141
|
+
detail: {
|
|
142
|
+
values: [
|
|
143
|
+
dayjs(e.detail.date[0]).valueOf(),
|
|
144
|
+
dayjs(e.detail.date[1]).valueOf(),
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
this,
|
|
149
|
+
)}
|
|
150
|
+
>
|
|
151
|
+
<eox-timecontrol-date
|
|
152
|
+
.format=${DATE_TIME_FORMAT}
|
|
153
|
+
></eox-timecontrol-date>
|
|
154
|
+
<eox-timecontrol-picker
|
|
155
|
+
style="${this.inlineMode
|
|
156
|
+
? "margin-bottom: 1rem; display: block;"
|
|
157
|
+
: ""}"
|
|
158
|
+
?popup=${!this.inlineMode}
|
|
159
|
+
range
|
|
160
|
+
show-dots
|
|
161
|
+
.position=${["bottom", "left"]}
|
|
162
|
+
></eox-timecontrol-picker>
|
|
163
|
+
</eox-timecontrol>
|
|
164
|
+
`,
|
|
165
|
+
() => html`
|
|
166
|
+
<div style="display: flex; gap: .5rem; align-items: center;">
|
|
167
|
+
${this.#label("min", "before")}
|
|
168
|
+
<tc-range-slider
|
|
169
|
+
min="${this.filterObject.min}"
|
|
170
|
+
max="${this.filterObject.max}"
|
|
171
|
+
value1="${this.filterObject.state.min || this.filterObject.min}"
|
|
172
|
+
value2="${this.filterObject.state.max || this.filterObject.max}"
|
|
173
|
+
step="${this.filterObject.step || 1}"
|
|
174
|
+
@change=${this.debouncedInputHandler}
|
|
175
|
+
></tc-range-slider>
|
|
176
|
+
${this.#label("max", "after")}
|
|
177
|
+
</div>
|
|
178
|
+
`,
|
|
179
|
+
)}
|
|
111
180
|
`,
|
|
112
181
|
);
|
|
113
182
|
}
|
|
@@ -109,6 +109,11 @@ export class EOxSelector extends LitElement {
|
|
|
109
109
|
* @param {Map} changedProperties - The properties that have changed.
|
|
110
110
|
*/
|
|
111
111
|
updated(changedProperties) {
|
|
112
|
+
if (changedProperties.has("filterObject") && this.filterObject.state) {
|
|
113
|
+
this.selectedItems = Object.keys(this.filterObject.state)
|
|
114
|
+
.map((item) => (this.filterObject.state[item] ? item : null))
|
|
115
|
+
.filter((item) => Boolean(item));
|
|
116
|
+
}
|
|
112
117
|
updatedSelectorMethod(changedProperties, this);
|
|
113
118
|
}
|
|
114
119
|
|
|
@@ -201,7 +206,7 @@ export class EOxSelector extends LitElement {
|
|
|
201
206
|
html`<div class="autocomplete-container">
|
|
202
207
|
<div
|
|
203
208
|
class="autocomplete-container-wrapper field small no-round"
|
|
204
|
-
style="margin-left: var(--
|
|
209
|
+
style="margin-left: var(--_list-padding)"
|
|
205
210
|
>
|
|
206
211
|
<input
|
|
207
212
|
autocomplete="off"
|
|
@@ -88,7 +88,7 @@ class EOxItemFilterSpatial extends LitElement {
|
|
|
88
88
|
this.filterObject,
|
|
89
89
|
() => html`
|
|
90
90
|
<div
|
|
91
|
-
style="margin-left: var(--
|
|
91
|
+
style="margin-left: var(--_list-padding); padding-right: var(--_padding)"
|
|
92
92
|
>
|
|
93
93
|
<nav class="no-margin wrap">
|
|
94
94
|
${map(
|
|
@@ -114,7 +114,7 @@ export class EOxItemFilterText extends LitElement {
|
|
|
114
114
|
<div class="text-container">
|
|
115
115
|
<div
|
|
116
116
|
class="text-container-wrapper field small"
|
|
117
|
-
style="margin-left: var(--
|
|
117
|
+
style="margin-left: var(--_list-padding)"
|
|
118
118
|
>
|
|
119
119
|
<input
|
|
120
120
|
type="text"
|
|
@@ -131,7 +131,9 @@ export class EOxItemFilterText extends LitElement {
|
|
|
131
131
|
/>
|
|
132
132
|
</div>
|
|
133
133
|
</div>
|
|
134
|
-
<small
|
|
134
|
+
<small
|
|
135
|
+
class="error-validation"
|
|
136
|
+
style="margin-left: var(--_list-padding)"
|
|
135
137
|
>${this.filterObject.validation && this.isValid === false
|
|
136
138
|
? this.filterObject.validation.message
|
|
137
139
|
: ""}</small
|
package/src/enums/config.js
CHANGED
package/src/enums/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ELEMENT_CONFIG, ELEMENT_PROPERTIES } from "./config";
|
|
1
|
+
export { ELEMENT_CONFIG, ELEMENT_PROPERTIES, DATE_TIME_FORMAT } from "./config";
|
|
@@ -100,7 +100,7 @@ export const filter = async (items, filters, config) => {
|
|
|
100
100
|
for (const [key, value] of Object.entries(rangeFilters)) {
|
|
101
101
|
// Function to parse value based on format
|
|
102
102
|
const parseValue = (input) => {
|
|
103
|
-
return value.format === "date" ? dayjs(input).
|
|
103
|
+
return value.format === "date" ? dayjs(input).valueOf() : input;
|
|
104
104
|
};
|
|
105
105
|
const rangeValue = getValue(key, results[i]);
|
|
106
106
|
if (rangeValue) {
|
package/src/helpers/index.js
CHANGED
|
@@ -11,3 +11,4 @@ export { default as toggleAccordion } from "./toggle-accordion";
|
|
|
11
11
|
export { default as getValue } from "./get-value";
|
|
12
12
|
export { default as capitalize } from "./capitalize";
|
|
13
13
|
export { default as mergeHighlightIndices } from "./merge-highlight-indices";
|
|
14
|
+
export { default as isDate } from "./is-date";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the filterObject format is date-like.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} filterObject - The filter object.
|
|
5
|
+
* @returns {boolean} True if it is a date, otherwise false.
|
|
6
|
+
*/
|
|
7
|
+
export default function isDate(filterObject) {
|
|
8
|
+
return Boolean(filterObject.format === "date");
|
|
9
|
+
}
|
package/src/main.js
CHANGED
|
@@ -420,13 +420,39 @@ export class EOxItemFilter extends LitElement {
|
|
|
420
420
|
* @param {Map} changedProperties - The properties that have changed.
|
|
421
421
|
*/
|
|
422
422
|
updated(changedProperties) {
|
|
423
|
-
|
|
423
|
+
let shouldReapply = false;
|
|
424
|
+
let shouldSearch = false;
|
|
425
|
+
|
|
426
|
+
ELEMENT_PROPERTIES.forEach((property) => {
|
|
424
427
|
if (changedProperties.has(property)) {
|
|
425
|
-
this
|
|
426
|
-
|
|
428
|
+
this.#config[property] = this[property];
|
|
429
|
+
if (
|
|
430
|
+
[
|
|
431
|
+
"items",
|
|
432
|
+
"filterProperties",
|
|
433
|
+
"idProperty",
|
|
434
|
+
"aggregateResults",
|
|
435
|
+
"fuseConfig",
|
|
436
|
+
"matchAllWhenEmpty",
|
|
437
|
+
"externalFilter",
|
|
438
|
+
].includes(property)
|
|
439
|
+
) {
|
|
440
|
+
shouldReapply = true;
|
|
441
|
+
} else if (property === "resultSorting") {
|
|
442
|
+
shouldSearch = true;
|
|
443
|
+
}
|
|
427
444
|
}
|
|
428
|
-
return false;
|
|
429
445
|
});
|
|
446
|
+
|
|
447
|
+
if (shouldReapply) {
|
|
448
|
+
this.#items =
|
|
449
|
+
this.items?.map((i, index) =>
|
|
450
|
+
Object.assign({ id: i[this.idProperty] || `item-${index}` }, i),
|
|
451
|
+
) || [];
|
|
452
|
+
this.apply();
|
|
453
|
+
} else if (shouldSearch) {
|
|
454
|
+
this.search();
|
|
455
|
+
}
|
|
430
456
|
}
|
|
431
457
|
|
|
432
458
|
/**
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { resetFilter } from "../../helpers/index.js";
|
|
1
|
+
import { resetFilter, isDate } from "../../helpers/index.js";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
3
|
import { html } from "lit";
|
|
4
|
-
|
|
5
|
-
const DATE_TIME_FORMAT = "ddd, D MMM YYYY HH:mm:ss";
|
|
4
|
+
import { DATE_TIME_FORMAT } from "../../enums/index.js";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Resets the range filter to its default state and requests an update.
|
|
@@ -10,19 +9,31 @@ const DATE_TIME_FORMAT = "ddd, D MMM YYYY HH:mm:ss";
|
|
|
10
9
|
* @param {import("../../components/filters/range.js").EOxItemFilterRange} EOxItemFilterRange - The EOxItemFilterRange component instance.
|
|
11
10
|
*/
|
|
12
11
|
export function resetRangeMethod(EOxItemFilterRange) {
|
|
13
|
-
EOxItemFilterRange.filterObject
|
|
14
|
-
EOxItemFilterRange.filterObject,
|
|
15
|
-
);
|
|
12
|
+
resetFilter(EOxItemFilterRange.filterObject);
|
|
16
13
|
if (EOxItemFilterRange.filterObject) {
|
|
14
|
+
const min = EOxItemFilterRange.filterObject.min;
|
|
15
|
+
const max = EOxItemFilterRange.filterObject.max;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {import("@eox/timecontrol").EOxTimeControl}
|
|
19
|
+
*/
|
|
20
|
+
const eleTimeControl = EOxItemFilterRange.querySelector("eox-timecontrol");
|
|
21
|
+
if (eleTimeControl) {
|
|
22
|
+
eleTimeControl.dateChange(
|
|
23
|
+
[dayjs(min).format(), dayjs(max).format()],
|
|
24
|
+
eleTimeControl,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
/**
|
|
18
29
|
* @type {import("toolcool-range-slider").RangeSlider}
|
|
19
30
|
*/
|
|
20
31
|
const eleTCRangeSlider =
|
|
21
32
|
EOxItemFilterRange.querySelector("tc-range-slider");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
if (eleTCRangeSlider) {
|
|
34
|
+
if (eleTCRangeSlider.value1 !== min) eleTCRangeSlider.value1 = min;
|
|
35
|
+
if (eleTCRangeSlider.value2 !== max) eleTCRangeSlider.value2 = max;
|
|
36
|
+
}
|
|
26
37
|
}
|
|
27
38
|
EOxItemFilterRange.requestUpdate();
|
|
28
39
|
}
|
|
@@ -34,37 +45,69 @@ export function resetRangeMethod(EOxItemFilterRange) {
|
|
|
34
45
|
* @param {Object} EOxItemFilterRange - The EOxItemFilterRange component instance.
|
|
35
46
|
*/
|
|
36
47
|
export function rangeInputHandlerMethod(evt, EOxItemFilterRange) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const parseVal = (val) => {
|
|
49
|
+
return isDate(EOxItemFilterRange.filterObject)
|
|
50
|
+
? dayjs(val).valueOf()
|
|
51
|
+
: parseFloat(val);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const min = parseVal(evt.detail.values[0]);
|
|
55
|
+
const max = parseVal(evt.detail.values[1]);
|
|
56
|
+
|
|
57
|
+
const currentMin = parseVal(EOxItemFilterRange.filterObject.state.min);
|
|
58
|
+
const currentMax = parseVal(EOxItemFilterRange.filterObject.state.max);
|
|
59
|
+
|
|
60
|
+
const filterMin = parseVal(EOxItemFilterRange.filterObject.min);
|
|
61
|
+
const filterMax = parseVal(EOxItemFilterRange.filterObject.max);
|
|
62
|
+
|
|
63
|
+
let isEqualMin, isEqualMax;
|
|
64
|
+
let isEqualCurrentMin, isEqualCurrentMax;
|
|
65
|
+
|
|
66
|
+
if (isDate(EOxItemFilterRange.filterObject)) {
|
|
67
|
+
isEqualMin = dayjs(min).isSame(dayjs(filterMin), "day");
|
|
68
|
+
isEqualMax = dayjs(max).isSame(dayjs(filterMax), "day");
|
|
69
|
+
isEqualCurrentMin = dayjs(min).isSame(dayjs(currentMin), "day");
|
|
70
|
+
isEqualCurrentMax = dayjs(max).isSame(dayjs(currentMax), "day");
|
|
71
|
+
} else {
|
|
72
|
+
isEqualMin = min === filterMin;
|
|
73
|
+
isEqualMax = max === filterMax;
|
|
74
|
+
isEqualCurrentMin = min === currentMin;
|
|
75
|
+
isEqualCurrentMax = max === currentMax;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// If the new values are the same as the current state, do nothing
|
|
79
|
+
if (isEqualCurrentMin && isEqualCurrentMax) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Update the state with the new min and max values
|
|
84
|
+
[
|
|
85
|
+
EOxItemFilterRange.filterObject.state.min,
|
|
86
|
+
EOxItemFilterRange.filterObject.state.max,
|
|
87
|
+
] = [min, max];
|
|
88
|
+
|
|
89
|
+
if (isEqualMin && isEqualMax) {
|
|
90
|
+
delete EOxItemFilterRange.filterObject.dirty;
|
|
91
|
+
delete EOxItemFilterRange.filterObject.stringifiedState;
|
|
92
|
+
} else {
|
|
49
93
|
EOxItemFilterRange.filterObject.dirty = true;
|
|
50
94
|
}
|
|
51
95
|
|
|
52
96
|
if (EOxItemFilterRange.filterObject.dirty) {
|
|
53
97
|
EOxItemFilterRange.filterObject.stringifiedState =
|
|
54
98
|
EOxItemFilterRange.filterObject.format === "date"
|
|
55
|
-
? `${dayjs
|
|
99
|
+
? `${dayjs(min).format(DATE_TIME_FORMAT)} - ${dayjs(max).format(DATE_TIME_FORMAT)}`
|
|
56
100
|
: `${min} - ${max}`;
|
|
57
101
|
}
|
|
58
102
|
|
|
59
103
|
EOxItemFilterRange.dispatchEvent(new CustomEvent("filter"));
|
|
60
104
|
|
|
61
105
|
// Reset the component if the state matches the original min and max values, otherwise request an update
|
|
62
|
-
if (
|
|
63
|
-
min === EOxItemFilterRange.filterObject.min &&
|
|
64
|
-
max === EOxItemFilterRange.filterObject.max
|
|
65
|
-
)
|
|
106
|
+
if (isEqualMin && isEqualMax) {
|
|
66
107
|
EOxItemFilterRange.reset();
|
|
67
|
-
else
|
|
108
|
+
} else {
|
|
109
|
+
EOxItemFilterRange.requestUpdate();
|
|
110
|
+
}
|
|
68
111
|
}
|
|
69
112
|
|
|
70
113
|
/**
|
|
@@ -76,10 +119,9 @@ export function rangeInputHandlerMethod(evt, EOxItemFilterRange) {
|
|
|
76
119
|
* @returns {import("lit").HTMLTemplateResult}
|
|
77
120
|
*/
|
|
78
121
|
export function rangeLabelMethod(val, pos, EOxItemFilterRange) {
|
|
79
|
-
const isDate = Boolean(EOxItemFilterRange.filterObject.format === "date");
|
|
80
122
|
const filteredVal = EOxItemFilterRange.filterObject.state[val];
|
|
81
|
-
const label = isDate
|
|
82
|
-
? dayjs
|
|
123
|
+
const label = isDate(EOxItemFilterRange.filterObject)
|
|
124
|
+
? dayjs(filteredVal).format(DATE_TIME_FORMAT)
|
|
83
125
|
: filteredVal;
|
|
84
126
|
return html`<div class="range-${pos}">${label}</div>`;
|
|
85
127
|
}
|
|
@@ -54,11 +54,15 @@ function createFilterMethod(filterObject, tabIndex, EOxItemFilter) {
|
|
|
54
54
|
// Return a range filter element
|
|
55
55
|
return html`
|
|
56
56
|
<eox-itemfilter-range
|
|
57
|
+
.inlineMode=${EOxItemFilter.inlineMode || false}
|
|
57
58
|
id="${filterId}"
|
|
58
59
|
data-type="filter"
|
|
59
60
|
.tabIndex=${tabIndex}
|
|
60
61
|
.filterObject=${filterObject}
|
|
61
62
|
slot="filter"
|
|
63
|
+
.suggestions="${uniq(
|
|
64
|
+
flatMap(EOxItemFilter.items, filterObject.key),
|
|
65
|
+
).filter((i) => i)}"
|
|
62
66
|
.unstyled=${EOxItemFilter.unstyled}
|
|
63
67
|
@filter=${() => EOxItemFilter.search()}
|
|
64
68
|
></eox-itemfilter-range>
|
|
@@ -2,6 +2,7 @@ import dayjs from "dayjs";
|
|
|
2
2
|
import { getValue, indexItems } from "../../helpers";
|
|
3
3
|
import uniq from "lodash.uniq";
|
|
4
4
|
import flatMap from "lodash.flatmap";
|
|
5
|
+
import { DATE_TIME_FORMAT } from "../../enums/index.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Applies filters to the provided items based on the given configuration and updates the EOxItemFilter instance.
|
|
@@ -22,7 +23,7 @@ function filterApplyMethod(config, items, EOxItemFilter) {
|
|
|
22
23
|
// Function to parse values based on their format
|
|
23
24
|
const parseValue = (value) => {
|
|
24
25
|
return filterProperty.format === "date"
|
|
25
|
-
? dayjs(value).
|
|
26
|
+
? dayjs(value).valueOf()
|
|
26
27
|
: parseFloat(value);
|
|
27
28
|
};
|
|
28
29
|
|
|
@@ -77,12 +78,40 @@ function filterApplyMethod(config, items, EOxItemFilter) {
|
|
|
77
78
|
|
|
78
79
|
// Combine filter properties into the filter object
|
|
79
80
|
const filterKey = filterProperty.key || filterProperty.keys.join("|");
|
|
81
|
+
const existingFilter = EOxItemFilter.filters[filterKey];
|
|
82
|
+
let isDirty = undefined;
|
|
83
|
+
if (filterProperty.state) {
|
|
84
|
+
if (filterProperty.type === "range") {
|
|
85
|
+
const parseVal = (val) => {
|
|
86
|
+
return filterProperty.format === "date"
|
|
87
|
+
? dayjs(val).valueOf()
|
|
88
|
+
: parseFloat(val);
|
|
89
|
+
};
|
|
90
|
+
const stateMin = parseVal(filterProperty.state.min);
|
|
91
|
+
const stateMax = parseVal(filterProperty.state.max);
|
|
92
|
+
const filterMin = parseVal(filterProperty.min ?? filterKeys.min);
|
|
93
|
+
const filterMax = parseVal(filterProperty.max ?? filterKeys.max);
|
|
94
|
+
|
|
95
|
+
if (filterProperty.format === "date") {
|
|
96
|
+
isDirty =
|
|
97
|
+
!dayjs(stateMin).isSame(dayjs(filterMin), "day") ||
|
|
98
|
+
!dayjs(stateMax).isSame(dayjs(filterMax), "day") ||
|
|
99
|
+
undefined;
|
|
100
|
+
} else {
|
|
101
|
+
isDirty =
|
|
102
|
+
stateMin !== filterMin || stateMax !== filterMax || undefined;
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
isDirty =
|
|
106
|
+
Object.values(filterProperty.state).some((value) => value) ||
|
|
107
|
+
undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
80
111
|
EOxItemFilter.filters[filterKey] = Object.assign(
|
|
81
112
|
{
|
|
82
113
|
type: filterProperty.type || "multiselect",
|
|
83
|
-
dirty:
|
|
84
|
-
? Object.values(filterProperty.state).some((value) => value)
|
|
85
|
-
: undefined,
|
|
114
|
+
dirty: isDirty || existingFilter?.dirty,
|
|
86
115
|
key: filterKey,
|
|
87
116
|
},
|
|
88
117
|
filterProperty.type === "range"
|
|
@@ -94,9 +123,34 @@ function filterApplyMethod(config, items, EOxItemFilter) {
|
|
|
94
123
|
: {},
|
|
95
124
|
filterProperty,
|
|
96
125
|
);
|
|
126
|
+
if (
|
|
127
|
+
filterProperty.type === "range" &&
|
|
128
|
+
EOxItemFilter.filters[filterKey].dirty
|
|
129
|
+
) {
|
|
130
|
+
const parseVal = (val) => {
|
|
131
|
+
return filterProperty.format === "date"
|
|
132
|
+
? dayjs(val).valueOf()
|
|
133
|
+
: parseFloat(val);
|
|
134
|
+
};
|
|
135
|
+
const min = parseVal(
|
|
136
|
+
filterProperty.state?.min !== undefined
|
|
137
|
+
? filterProperty.state.min
|
|
138
|
+
: existingFilter?.state?.min,
|
|
139
|
+
);
|
|
140
|
+
const max = parseVal(
|
|
141
|
+
filterProperty.state?.max !== undefined
|
|
142
|
+
? filterProperty.state.max
|
|
143
|
+
: existingFilter?.state?.max,
|
|
144
|
+
);
|
|
145
|
+
EOxItemFilter.filters[filterKey].stringifiedState =
|
|
146
|
+
filterProperty.format === "date"
|
|
147
|
+
? `${dayjs(min).format(DATE_TIME_FORMAT)} - ${dayjs(max).format(DATE_TIME_FORMAT)}`
|
|
148
|
+
: `${min} - ${max}`;
|
|
149
|
+
}
|
|
97
150
|
EOxItemFilter.filters[filterKey].state = Object.assign(
|
|
98
151
|
{},
|
|
99
152
|
filterKeys,
|
|
153
|
+
existingFilter?.state || {},
|
|
100
154
|
filterProperty.state,
|
|
101
155
|
);
|
|
102
156
|
});
|
package/src/style.eox.js
CHANGED
|
@@ -109,6 +109,13 @@ eox-itemfilter-expandcontainer > [data-type=filter] {
|
|
|
109
109
|
overflow-x: hidden;
|
|
110
110
|
max-width: 100%;
|
|
111
111
|
}
|
|
112
|
+
form#itemfilter.inline eox-itemfilter-expandcontainer {
|
|
113
|
+
max-height: none;
|
|
114
|
+
}
|
|
115
|
+
form#itemfilter.inline eox-itemfilter-expandcontainer > [data-type=filter] {
|
|
116
|
+
height: auto;
|
|
117
|
+
overflow: visible;
|
|
118
|
+
}
|
|
112
119
|
[data-type=filter] .title,
|
|
113
120
|
details summary {
|
|
114
121
|
text-transform: var(--_text-transform);
|
|
@@ -228,6 +235,8 @@ nav.title-nav {
|
|
|
228
235
|
}
|
|
229
236
|
eox-itemfilter-range {
|
|
230
237
|
display: block;
|
|
238
|
+
margin-left: var(--_list-padding);
|
|
239
|
+
padding-right: var(--_padding);
|
|
231
240
|
}
|
|
232
241
|
.range-wrapper {
|
|
233
242
|
margin-left: var(--_list-padding);
|
|
@@ -350,6 +359,13 @@ form#itemfilter > div::-webkit-scrollbar-thumb {
|
|
|
350
359
|
justify-content: space-between;
|
|
351
360
|
cursor: text;
|
|
352
361
|
}
|
|
362
|
+
.autocomplete-container .field input,
|
|
363
|
+
.text-container .field input {
|
|
364
|
+
background: none !important;
|
|
365
|
+
border-block-end-color: var(--outline);
|
|
366
|
+
border-radius: 0 !important;
|
|
367
|
+
box-shadow: none !important;
|
|
368
|
+
}
|
|
353
369
|
.autocomplete-container-wrapper,
|
|
354
370
|
.text-container-wrapper {
|
|
355
371
|
position: relative;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @module EOxItemFilterRange
|
|
7
7
|
* @extends LitElement
|
|
8
8
|
* @property {Object} filterObject - The filter object containing state and range limits.
|
|
9
|
+
* @property {Array} suggestions - The list of suggestions for the selector.
|
|
9
10
|
* @property {Number} tabIndex - The tab index for the input elements.
|
|
10
11
|
*/
|
|
11
12
|
export class EOxItemFilterRange extends LitElement {
|
|
@@ -14,15 +15,31 @@ export class EOxItemFilterRange extends LitElement {
|
|
|
14
15
|
attribute: boolean;
|
|
15
16
|
type: ObjectConstructor;
|
|
16
17
|
};
|
|
18
|
+
suggestions: {
|
|
19
|
+
attribute: boolean;
|
|
20
|
+
type: ArrayConstructor;
|
|
21
|
+
};
|
|
17
22
|
tabIndex: {
|
|
18
23
|
attribute: boolean;
|
|
19
24
|
type: NumberConstructor;
|
|
20
25
|
};
|
|
26
|
+
inlineMode: {
|
|
27
|
+
attribute: string;
|
|
28
|
+
type: BooleanConstructor;
|
|
29
|
+
};
|
|
21
30
|
};
|
|
22
31
|
/**
|
|
23
32
|
* @type Object
|
|
24
33
|
*/
|
|
25
34
|
filterObject: any;
|
|
35
|
+
/**
|
|
36
|
+
* @type Array
|
|
37
|
+
*/
|
|
38
|
+
suggestions: any[];
|
|
39
|
+
/**
|
|
40
|
+
* @type Boolean
|
|
41
|
+
*/
|
|
42
|
+
inlineMode: boolean;
|
|
26
43
|
/**
|
|
27
44
|
* @type {(evt: CustomEvent<any>) => void}
|
|
28
45
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/components/filters/range.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/components/filters/range.js"],"names":[],"mappings":"AAaA;;;;;;;;;;GAUG;AACH;IAEE;;;;;;;;;;;;;;;;;MAKE;IAKA;;OAEG;IACH,kBAAsB;IAEtB;;OAEG;IACH,mBAAqB;IAOrB;;OAEG;IACH,oBAAuB;IAEvB;;OAEG;IACH,cAFU,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,IAAI,CAEQ;IAEjD;;OAEG;IACH,gCAEE;IAuBJ;;OAEG;IACH,cAEC;IAED;;;;OAIG;IACH,oBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,oBAyEC;;CACF;2BAtLgC,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../../src/components/filters/selector.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;GAkBG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAYE;IAKA;;OAEG;IACH,kBAAsB;IAEtB;;OAEG;IACH,mBAAqB;IAErB;;OAEG;IACH,qBAAuB;IAEvB;;OAEG;IACH,cAAe;IAEf;;OAEG;IACH,yBAA4B;IAE5B;;OAEG;IACH,yBAA0B;IAE1B;;OAEG;IACH,2BAA6B;IAE7B;;OAEG;IACH,aAAoB;IAEpB;;OAEG;IACH,kBAAqB;IAOrB;;OAEG;IACH,oBAAuB;IAGzB;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../../src/components/filters/selector.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;GAkBG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAYE;IAKA;;OAEG;IACH,kBAAsB;IAEtB;;OAEG;IACH,mBAAqB;IAErB;;OAEG;IACH,qBAAuB;IAEvB;;OAEG;IACH,cAAe;IAEf;;OAEG;IACH,yBAA4B;IAE5B;;OAEG;IACH,yBAA0B;IAE1B;;OAEG;IACH,2BAA6B;IAE7B;;OAEG;IACH,aAAoB;IAEpB;;OAEG;IACH,kBAAqB;IAOrB;;OAEG;IACH,oBAAuB;IAGzB;;;;OAIG;IACH,gDAOC;IA6BD;;OAEG;IACH,cAEC;IAED;;;;;OAKG;IACH,8BAEG;IAEH;;;OAGG;IACH,qBAUC;IAED;;;;OAIG;IACH,oBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,+CA8DC;;CACF;2BA9PyC,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/components/filters/text.js"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;MAQC;IAKC;;OAEG;IACH,kBAAsB;IAEtB;;OAEG;IACH,eAAmB;IAEnB;;OAEG;IACH,kBAAqB;IAOrB;;OAEG;IACH,iBAAoB;IAgCtB;;OAEG;IACH,cAEC;IAED;;OAEG;IACH,yEAEG;IAEH;;;;OAIG;IACH,oBAFa,IAAI,CAIhB;IAGD,
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/components/filters/text.js"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;MAQC;IAKC;;OAEG;IACH,kBAAsB;IAEtB;;OAEG;IACH,eAAmB;IAEnB;;OAEG;IACH,kBAAqB;IAOrB;;OAEG;IACH,iBAAoB;IAgCtB;;OAEG;IACH,cAEC;IAED;;OAEG;IACH,yEAEG;IAEH;;;;OAIG;IACH,oBAFa,IAAI,CAIhB;IAGD,oBAkCC;;CACF;2BA/IgC,KAAK"}
|