@eox/itemfilter 1.3.0 → 1.4.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.
- package/README.md +4 -0
- package/dist/eox-itemfilter.js +1156 -1276
- package/dist/eox-itemfilter.umd.cjs +110 -112
- package/package.json +8 -13
- package/src/components/chips.js +131 -0
- package/src/components/expand-container.js +94 -0
- package/src/components/filters/range.js +114 -0
- package/src/components/filters/selector.js +245 -0
- package/src/components/filters/spatial.js +192 -0
- package/src/components/filters/text.js +114 -0
- package/src/components/itemfilter-container.js +289 -0
- package/src/components/results.js +156 -0
- package/src/enums/config.js +104 -0
- package/src/enums/index.js +1 -0
- package/src/helpers/chip-items.js +19 -0
- package/src/helpers/filter-client.js +179 -0
- package/src/helpers/filter-external.js +18 -0
- package/src/helpers/get-value.js +12 -0
- package/src/helpers/highlighting.js +79 -0
- package/src/helpers/index.js +11 -0
- package/src/helpers/is-filters-dirty.js +13 -0
- package/src/helpers/map-layers.js +42 -0
- package/src/helpers/reset-filter.js +60 -0
- package/src/helpers/spatial.js +35 -0
- package/src/helpers/tab-index.js +13 -0
- package/src/helpers/toggle-accordion.js +39 -0
- package/src/main.js +466 -0
- package/src/methods/chips/handler.js +129 -0
- package/src/methods/chips/index.js +5 -0
- package/src/methods/container/handler.js +70 -0
- package/src/methods/container/index.js +10 -0
- package/src/methods/container/init-popver.js +34 -0
- package/src/methods/container/reset-filter.js +14 -0
- package/src/methods/container/reset-search.js +16 -0
- package/src/methods/container/search-filter.js +27 -0
- package/src/methods/filters/index.js +20 -0
- package/src/methods/filters/range.js +78 -0
- package/src/methods/filters/selector.js +209 -0
- package/src/methods/filters/spatial.js +114 -0
- package/src/methods/filters/text.js +32 -0
- package/src/methods/itemfilter/create-filter.js +83 -0
- package/src/methods/itemfilter/create-reset.js +39 -0
- package/src/methods/itemfilter/filter-apply.js +140 -0
- package/src/methods/itemfilter/index.js +6 -0
- package/src/methods/itemfilter/reset-filter.js +13 -0
- package/src/methods/itemfilter/search.js +23 -0
- package/src/methods/itemfilter/sort-results.js +14 -0
- package/src/methods/results/aggregate-results.js +43 -0
- package/src/methods/results/create.js +111 -0
- package/src/methods/results/index.js +2 -0
- package/src/style.eox.js +457 -0
- package/src/style.js +26 -0
- package/test/_mockMap.js +0 -20
- package/test/cases/filters/filter-keys.js +0 -22
- package/test/cases/filters/index.js +0 -3
- package/test/cases/general/accordion.js +0 -60
- package/test/cases/general/disable-highlight.js +0 -21
- package/test/cases/general/external-filter.js +0 -35
- package/test/cases/general/highlight-result.js +0 -16
- package/test/cases/general/index.js +0 -13
- package/test/cases/general/multiple-filters.js +0 -21
- package/test/cases/general/nested-property.js +0 -25
- package/test/cases/general/search-bar.js +0 -12
- package/test/cases/general/search-result.js +0 -14
- package/test/cases/general/spatial-filter.js +0 -22
- package/test/cases/general/subtitle.js +0 -15
- package/test/cases/general/validation.js +0 -22
- package/test/cases/state/custom-order.js +0 -24
- package/test/cases/state/index.js +0 -6
- package/test/cases/state/render-checkbox.js +0 -17
- package/test/cases/state/result-pre-checked.js +0 -20
- package/test/cases/state/results-with-pre-set-filters.js +0 -30
- package/test/filters.cy.js +0 -54
- package/test/general.cy.js +0 -110
- package/test/state.cy.js +0 -74
- package/test/testItems.json +0 -440
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eox/itemfilter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@eox/eslint-config": "^1.0.0",
|
|
7
6
|
"@types/geojson": "^7946.0.14",
|
|
8
7
|
"@types/lodash.debounce": "^4.0.7",
|
|
9
|
-
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
10
|
-
"@typescript-eslint/parser": "^7.0.1",
|
|
11
|
-
"eslint-plugin-typescript": "^0.14.0",
|
|
12
|
-
"typescript": "^5.2.2",
|
|
13
8
|
"vite": "^5.0.2"
|
|
14
9
|
},
|
|
15
10
|
"engines": {
|
|
@@ -18,18 +13,15 @@
|
|
|
18
13
|
},
|
|
19
14
|
"files": [
|
|
20
15
|
"dist",
|
|
21
|
-
"
|
|
16
|
+
"src"
|
|
22
17
|
],
|
|
23
|
-
"main": "./
|
|
18
|
+
"main": "./src/main.js",
|
|
24
19
|
"scripts": {
|
|
25
20
|
"build": "vite build",
|
|
26
|
-
"watch": "vite build --watch"
|
|
27
|
-
"format": "prettier --write .",
|
|
28
|
-
"lint": "eslint --ext .js,.ts .",
|
|
29
|
-
"lint:fix": "eslint --ext .js,.ts . --fix",
|
|
30
|
-
"typecheck": "tsc"
|
|
21
|
+
"watch": "vite build --watch"
|
|
31
22
|
},
|
|
32
23
|
"dependencies": {
|
|
24
|
+
"@eox/elements-utils": "^0.0.1",
|
|
33
25
|
"@floating-ui/dom": "^1.6.8",
|
|
34
26
|
"@turf/boolean-intersects": "^7.0.0",
|
|
35
27
|
"@turf/boolean-within": "^7.0.0",
|
|
@@ -39,5 +31,8 @@
|
|
|
39
31
|
"lodash.flatmap": "^4.5.0",
|
|
40
32
|
"lodash.uniq": "^4.5.0",
|
|
41
33
|
"toolcool-range-slider": "^4.0.27"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@eox/map": "^1.15.0"
|
|
42
37
|
}
|
|
43
38
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { LitElement, html } from "lit";
|
|
2
|
+
import { map } from "lit/directives/map.js";
|
|
3
|
+
import { styleEOX } from "../style.eox";
|
|
4
|
+
import {
|
|
5
|
+
handleChipClickMethod,
|
|
6
|
+
keyboardEventListenerMethod,
|
|
7
|
+
} from "../methods/chips";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* EOxItemFilterChipsV2 is a custom web component that provides a chip-style item selector.
|
|
11
|
+
* It uses the LitElement base class and integrates with external methods for handling chip clicks,
|
|
12
|
+
* close events, and keyboard events.
|
|
13
|
+
*
|
|
14
|
+
* @module EOxItemFilterChips
|
|
15
|
+
* @extends LitElement
|
|
16
|
+
* @property {Object} items - The items to be displayed as chips.
|
|
17
|
+
* @property {Object} controller - The controller object to manage chip actions.
|
|
18
|
+
*/
|
|
19
|
+
export class EOxItemFilterChipsV2 extends LitElement {
|
|
20
|
+
// Define properties with defaults and types
|
|
21
|
+
static get properties() {
|
|
22
|
+
return {
|
|
23
|
+
items: { attribute: false, type: Object },
|
|
24
|
+
controller: { attribute: false, type: Object },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @type Object
|
|
33
|
+
*/
|
|
34
|
+
this.items = {};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @type Object
|
|
38
|
+
*/
|
|
39
|
+
this.controller = {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Lifecycle method called when the element is connected to the DOM.
|
|
44
|
+
* Adds a keyboard event listener.
|
|
45
|
+
*/
|
|
46
|
+
connectedCallback() {
|
|
47
|
+
super.connectedCallback();
|
|
48
|
+
this.getRootNode().addEventListener(
|
|
49
|
+
"keydown",
|
|
50
|
+
this.#keyboardEventListener.bind(this),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Lifecycle method called when the element is disconnected from the DOM.
|
|
56
|
+
* Removes the keyboard event listener.
|
|
57
|
+
*/
|
|
58
|
+
disconnectedCallback() {
|
|
59
|
+
super.disconnectedCallback();
|
|
60
|
+
this.getRootNode().removeEventListener(
|
|
61
|
+
"keydown",
|
|
62
|
+
this.#keyboardEventListener.bind(this),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Dispatches a custom event with the selected items.
|
|
68
|
+
*
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
_dispatchEvent() {
|
|
72
|
+
this.dispatchEvent(
|
|
73
|
+
new CustomEvent("items-selected", {
|
|
74
|
+
detail: this.items,
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Handles keyboard events for the component.
|
|
81
|
+
*
|
|
82
|
+
* @param {Event} event - The keyboard event.
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
#keyboardEventListener(event) {
|
|
86
|
+
keyboardEventListenerMethod(event, this);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Handles click events for the chips.
|
|
91
|
+
*
|
|
92
|
+
* @param {Event} evt - The click event.
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
95
|
+
#handleChipClick(evt) {
|
|
96
|
+
handleChipClickMethod(evt, this);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Renders the HTML template for the component.
|
|
101
|
+
*/
|
|
102
|
+
render() {
|
|
103
|
+
return html`
|
|
104
|
+
<style>
|
|
105
|
+
${styleEOX}
|
|
106
|
+
</style>
|
|
107
|
+
<span class="chip-container">
|
|
108
|
+
${map(
|
|
109
|
+
this.items,
|
|
110
|
+
(item) => html`
|
|
111
|
+
<span class="chip" @click=${this.#handleChipClick.bind(this)}>
|
|
112
|
+
<span class="chip-title">${item.title}</span>
|
|
113
|
+
<span
|
|
114
|
+
class="chip-item-close hidden"
|
|
115
|
+
data-close=${item.key}
|
|
116
|
+
@click=${(evt) => {
|
|
117
|
+
evt.stopPropagation();
|
|
118
|
+
this.controller.remove(evt);
|
|
119
|
+
this.requestUpdate();
|
|
120
|
+
}}
|
|
121
|
+
></span>
|
|
122
|
+
</span>
|
|
123
|
+
</span>
|
|
124
|
+
`,
|
|
125
|
+
)}
|
|
126
|
+
</span>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
customElements.define("eox-itemfilter-chips", EOxItemFilterChipsV2);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { LitElement, html, nothing } from "lit";
|
|
2
|
+
import { styleEOX } from "../style.eox";
|
|
3
|
+
import { when } from "lit/directives/when.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* EOxItemFilterExpandContainer is a custom web component that provides an expandable container for item filters.
|
|
7
|
+
* The component supports a featured view and an expandable details view.
|
|
8
|
+
*
|
|
9
|
+
* @module EOxItemFilterExpandContainer
|
|
10
|
+
* @extends LitElement
|
|
11
|
+
* @property {Object} filterObject - The filter object containing state and properties such as title and expanded state.
|
|
12
|
+
* @property {Boolean} unstyled - Flag to determine if default styles should be applied.
|
|
13
|
+
*/
|
|
14
|
+
export class EOxItemFilterExpandContainer extends LitElement {
|
|
15
|
+
// Define properties with defaults and types
|
|
16
|
+
static get properties() {
|
|
17
|
+
return {
|
|
18
|
+
filterObject: { attribute: false, type: Object },
|
|
19
|
+
unstyled: { type: Boolean },
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @type Object
|
|
28
|
+
*/
|
|
29
|
+
this.filterObject = {};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @type Boolean
|
|
33
|
+
*/
|
|
34
|
+
this.unstyled = false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Handles the toggle event for the details element.
|
|
39
|
+
* Dispatches a custom event "details-toggled" with the event details.
|
|
40
|
+
*
|
|
41
|
+
* @param {Event} event - The toggle event.
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
#handleDetailsToggle(event) {
|
|
45
|
+
this.dispatchEvent(
|
|
46
|
+
new CustomEvent("details-toggled", {
|
|
47
|
+
detail: event,
|
|
48
|
+
bubbles: true,
|
|
49
|
+
composed: true,
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Renders the HTML template for the component.
|
|
56
|
+
*/
|
|
57
|
+
render() {
|
|
58
|
+
return html`
|
|
59
|
+
<style>
|
|
60
|
+
${!this.unstyled && styleEOX}
|
|
61
|
+
</style>
|
|
62
|
+
|
|
63
|
+
${when(
|
|
64
|
+
this.filterObject.featured,
|
|
65
|
+
() => html`<slot name="filter"></slot>`,
|
|
66
|
+
() =>
|
|
67
|
+
html`<details
|
|
68
|
+
@toggle="${this.#handleDetailsToggle}"
|
|
69
|
+
class="details-filter"
|
|
70
|
+
?open=${this.filterObject.expanded || nothing}
|
|
71
|
+
>
|
|
72
|
+
<summary>
|
|
73
|
+
<span
|
|
74
|
+
class="title"
|
|
75
|
+
style="${!this.filterObject.title &&
|
|
76
|
+
"text-transform: var(--text-transform)"}"
|
|
77
|
+
>
|
|
78
|
+
${this.filterObject.title || this.filterObject.key || "Filter"}
|
|
79
|
+
<slot name="reset-button"></slot>
|
|
80
|
+
</span>
|
|
81
|
+
</summary>
|
|
82
|
+
<div>
|
|
83
|
+
<slot name="filter"></slot>
|
|
84
|
+
</div>
|
|
85
|
+
</details>`,
|
|
86
|
+
)}
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
customElements.define(
|
|
92
|
+
"eox-itemfilter-expandcontainer",
|
|
93
|
+
EOxItemFilterExpandContainer,
|
|
94
|
+
);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { LitElement, html } from "lit";
|
|
2
|
+
import { when } from "lit/directives/when.js";
|
|
3
|
+
import _debounce from "lodash.debounce";
|
|
4
|
+
import "toolcool-range-slider";
|
|
5
|
+
import {
|
|
6
|
+
rangeInputHandlerMethod,
|
|
7
|
+
rangeLabelMethod,
|
|
8
|
+
resetRangeMethod,
|
|
9
|
+
} from "../../methods/filters/index.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* EOxItemFilterRange is a custom web component that provides a range slider for filtering items.
|
|
13
|
+
* It uses the LitElement base class and integrates with external methods for handling input events,
|
|
14
|
+
* generating labels, and resetting the range filter.
|
|
15
|
+
*
|
|
16
|
+
* @module EOxItemFilterRange
|
|
17
|
+
* @extends LitElement
|
|
18
|
+
* @property {Object} filterObject - The filter object containing state and range limits.
|
|
19
|
+
* @property {Number} tabIndex - The tab index for the input elements.
|
|
20
|
+
*/
|
|
21
|
+
export class EOxItemFilterRange extends LitElement {
|
|
22
|
+
// Define properties with defaults and types
|
|
23
|
+
static properties = {
|
|
24
|
+
filterObject: { attribute: false, type: Object },
|
|
25
|
+
tabIndex: { attribute: false, type: Number },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @type Object
|
|
33
|
+
*/
|
|
34
|
+
this.filterObject = {};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @type Boolean
|
|
38
|
+
*/
|
|
39
|
+
this.tabIndex = 0;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @type Function
|
|
43
|
+
*/
|
|
44
|
+
this.inputHandler = this.#inputHandler.bind(this);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @type Function
|
|
48
|
+
*/
|
|
49
|
+
this.debouncedInputHandler = _debounce(this.inputHandler, 0, {
|
|
50
|
+
leading: true,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Handles the input event for the range slider.
|
|
56
|
+
*
|
|
57
|
+
* @param {Event} evt - The input event.
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
#inputHandler(evt) {
|
|
61
|
+
rangeInputHandlerMethod(evt, this);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Generates labels for the range slider.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} val - The value of the label.
|
|
68
|
+
* @param {string} pos - The position of the label (before or after).
|
|
69
|
+
* @returns {string} - The generated label.
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
#label(val, pos) {
|
|
73
|
+
return rangeLabelMethod(val, pos, this);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Resets the range filter using the resetRangeMethod.
|
|
78
|
+
*/
|
|
79
|
+
reset() {
|
|
80
|
+
resetRangeMethod(this);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Overrides the default createRenderRoot method to render in the light DOM.
|
|
85
|
+
*
|
|
86
|
+
* @returns {this} - The current instance to render in the light DOM.
|
|
87
|
+
*/
|
|
88
|
+
createRenderRoot() {
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Renders the HTML template for the component.
|
|
94
|
+
*/
|
|
95
|
+
render() {
|
|
96
|
+
return when(
|
|
97
|
+
this.filterObject,
|
|
98
|
+
() => html`
|
|
99
|
+
${this.#label("min", "before")}
|
|
100
|
+
<tc-range-slider
|
|
101
|
+
min="${this.filterObject.min}"
|
|
102
|
+
max="${this.filterObject.max}"
|
|
103
|
+
value1="${this.filterObject.min || this.filterObject.state.min}"
|
|
104
|
+
value2="${this.filterObject.max || this.filterObject.state.max}"
|
|
105
|
+
step="${this.filterObject.step || 1}"
|
|
106
|
+
@change=${this.debouncedInputHandler}
|
|
107
|
+
></tc-range-slider>
|
|
108
|
+
${this.#label("max", "after")}
|
|
109
|
+
`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
customElements.define("eox-itemfilter-range", EOxItemFilterRange);
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { LitElement, html, nothing } from "lit";
|
|
2
|
+
import { styleEOX } from "../../style.eox.js";
|
|
3
|
+
import { when } from "lit/directives/when.js";
|
|
4
|
+
import _debounce from "lodash.debounce";
|
|
5
|
+
import checkboxStyle from "@eox/elements-utils/styles/dist/checkbox.style.js";
|
|
6
|
+
import radioStyle from "@eox/elements-utils/styles/dist/radio.style.js";
|
|
7
|
+
import {
|
|
8
|
+
resetSelectorMethod,
|
|
9
|
+
toggleItemSelectorMethod,
|
|
10
|
+
handleInputSelectorMethod,
|
|
11
|
+
handleKeyDownSelectorMethod,
|
|
12
|
+
updatedSelectorMethod,
|
|
13
|
+
} from "../../methods/filters";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* EOxSelector is a custom web component that provides a flexible selector interface for filtering items.
|
|
17
|
+
* It supports both autocomplete and select modes and integrates with external methods for handling input,
|
|
18
|
+
* key events, and selection updates.
|
|
19
|
+
*
|
|
20
|
+
* @module EOxSelector
|
|
21
|
+
* @extends LitElement
|
|
22
|
+
* @property {Object} filterObject - The filter object containing state and placeholder.
|
|
23
|
+
* @property {Array} suggestions - The list of suggestions for the selector.
|
|
24
|
+
* @property {Array} selectedItems - The list of currently selected items.
|
|
25
|
+
* @property {String} query - The current input query for autocomplete.
|
|
26
|
+
* @property {Boolean} showSuggestions - Flag to control the display of suggestions in autocomplete mode.
|
|
27
|
+
* @property {Number} highlightedIndex - The index of the currently highlighted suggestion.
|
|
28
|
+
* @property {Array} filteredSuggestions - The list of suggestions filtered based on the query.
|
|
29
|
+
* @property {String} type - The type of selector ("select", "multi-select", etc.).
|
|
30
|
+
* @property {Boolean} unstyled - Flag to determine if default styles should be applied.
|
|
31
|
+
* @property {Number} tabIndex - The tab index for the input elements.
|
|
32
|
+
* @property {Boolean} inlineMode - State whether to enable or disable inline mode
|
|
33
|
+
*/
|
|
34
|
+
export class EOxSelector extends LitElement {
|
|
35
|
+
// Define properties with defaults and types
|
|
36
|
+
static properties = {
|
|
37
|
+
filterObject: { attribute: false, type: Object },
|
|
38
|
+
suggestions: { attribute: false, type: Array },
|
|
39
|
+
selectedItems: { state: true, type: Array },
|
|
40
|
+
query: { state: true, type: String },
|
|
41
|
+
showSuggestions: { state: true, type: Boolean },
|
|
42
|
+
highlightedIndex: { state: true, type: Number },
|
|
43
|
+
filteredSuggestions: { state: true, type: Array },
|
|
44
|
+
type: { attribute: true, type: String },
|
|
45
|
+
unstyled: { type: Boolean },
|
|
46
|
+
tabIndex: { attribute: false, type: Number },
|
|
47
|
+
inlineMode: { attribute: "inline-mode", type: Boolean },
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
constructor() {
|
|
51
|
+
super();
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @type Object
|
|
55
|
+
*/
|
|
56
|
+
this.filterObject = {};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @type Array
|
|
60
|
+
*/
|
|
61
|
+
this.suggestions = [];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @type Array
|
|
65
|
+
*/
|
|
66
|
+
this.selectedItems = [];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @type String
|
|
70
|
+
*/
|
|
71
|
+
this.query = "";
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @type Boolean
|
|
75
|
+
*/
|
|
76
|
+
this.showSuggestions = false;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @type Number
|
|
80
|
+
*/
|
|
81
|
+
this.highlightedIndex = -1;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @type Array
|
|
85
|
+
*/
|
|
86
|
+
this.filteredSuggestions = [];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @type String
|
|
90
|
+
*/
|
|
91
|
+
this.type = "select";
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @type Boolean
|
|
95
|
+
*/
|
|
96
|
+
this.unstyled = false;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @type Number
|
|
100
|
+
*/
|
|
101
|
+
this.tabIndex = 0;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @type Boolean
|
|
105
|
+
*/
|
|
106
|
+
this.inlineMode = false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Called when the element is updated. Triggers the updatedSelectorMethod.
|
|
111
|
+
*
|
|
112
|
+
* @param {Map} changedProperties - The properties that have changed.
|
|
113
|
+
*/
|
|
114
|
+
updated(changedProperties) {
|
|
115
|
+
updatedSelectorMethod(changedProperties, this);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Handles input events on the autocomplete input element.
|
|
120
|
+
*
|
|
121
|
+
* @param {Event} event - The input event.
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
#handleInput(event) {
|
|
125
|
+
handleInputSelectorMethod(event, this);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Handles keydown events on the autocomplete input element.
|
|
130
|
+
*
|
|
131
|
+
* @param {Event} event - The keydown event.
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
#handleKeyDown(event) {
|
|
135
|
+
handleKeyDownSelectorMethod(event, this);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Toggles the selection of an item.
|
|
140
|
+
*
|
|
141
|
+
* @param {Object} item - The item to toggle.
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
#toggleItem(item) {
|
|
145
|
+
toggleItemSelectorMethod(item, this);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Resets the selector using the resetSelectorMethod.
|
|
150
|
+
*/
|
|
151
|
+
reset() {
|
|
152
|
+
resetSelectorMethod(this);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Debounced version of the toggleItem method to improve performance by limiting the rate at which the method is called.
|
|
157
|
+
*
|
|
158
|
+
* @function debouncedInputHandler
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
debouncedInputHandler = _debounce(this.#toggleItem, 500, {
|
|
162
|
+
leading: true,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Initialise pre-defined selected items using `state`
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
firstUpdated() {
|
|
170
|
+
if (this.filterObject.state) {
|
|
171
|
+
this.selectedItems = Object.keys(this.filterObject.state)
|
|
172
|
+
.map((item) => (this.filterObject.state[item] ? item : null))
|
|
173
|
+
.filter((item) => Boolean(item));
|
|
174
|
+
|
|
175
|
+
this.filterObject.stringifiedState = this.selectedItems.join(", ") || "";
|
|
176
|
+
|
|
177
|
+
this.requestUpdate();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Renders the HTML template for the component.
|
|
183
|
+
*/
|
|
184
|
+
render() {
|
|
185
|
+
const type = this.type.includes("multi") ? "checkbox" : "radio";
|
|
186
|
+
const selectOverflowClass =
|
|
187
|
+
this.filteredSuggestions.length > 5 ? "select-overflow" : nothing;
|
|
188
|
+
return html`
|
|
189
|
+
<style>
|
|
190
|
+
${!this.unstyled && styleEOX}
|
|
191
|
+
${!this.unstyled && checkboxStyle}
|
|
192
|
+
${!this.unstyled && radioStyle}
|
|
193
|
+
</style>
|
|
194
|
+
${when(
|
|
195
|
+
this.suggestions.length > 10,
|
|
196
|
+
() =>
|
|
197
|
+
html`<div class="autocomplete-container">
|
|
198
|
+
<div class="autocomplete-container-wrapper">
|
|
199
|
+
<input
|
|
200
|
+
autocomplete="off"
|
|
201
|
+
tabindex=${this.tabIndex}
|
|
202
|
+
class="autocomplete-input"
|
|
203
|
+
type="text"
|
|
204
|
+
.value=${this.query}
|
|
205
|
+
placeholder="${this.filterObject.placeholder || ""}"
|
|
206
|
+
@input=${this.#handleInput}
|
|
207
|
+
@keydown=${this.#handleKeyDown}
|
|
208
|
+
@blur=${() => (this.showSuggestions = false)}
|
|
209
|
+
@focus=${() => (this.showSuggestions = true)}
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
</div>`,
|
|
213
|
+
)}
|
|
214
|
+
<div class="select-container ${selectOverflowClass}">
|
|
215
|
+
<ul class="${this.type}">
|
|
216
|
+
${this.filteredSuggestions.map(
|
|
217
|
+
(suggestion) => html`
|
|
218
|
+
<li
|
|
219
|
+
data-identifier="${suggestion.toString().toLowerCase()}"
|
|
220
|
+
data-title="${suggestion}"
|
|
221
|
+
>
|
|
222
|
+
<label>
|
|
223
|
+
<input
|
|
224
|
+
type="${type}"
|
|
225
|
+
name=${suggestion}
|
|
226
|
+
.checked=${this.selectedItems.includes(suggestion)}
|
|
227
|
+
@change=${() => this.debouncedInputHandler(suggestion)}
|
|
228
|
+
@keydown=${(e) => {
|
|
229
|
+
if (e.key === " " && this.inlineMode)
|
|
230
|
+
this.debouncedInputHandler(suggestion);
|
|
231
|
+
}}
|
|
232
|
+
tabindex=${this.tabIndex + 1}
|
|
233
|
+
/>
|
|
234
|
+
<span class="title">${suggestion}</span>
|
|
235
|
+
</label>
|
|
236
|
+
</li>
|
|
237
|
+
`,
|
|
238
|
+
)}
|
|
239
|
+
</ul>
|
|
240
|
+
</div>
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
customElements.define("eox-itemfilter-select", EOxSelector);
|