@eox/itemfilter 1.17.5 → 1.19.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/dist/eox-itemfilter.js +2289 -2024
- package/dist/eox-itemfilter.umd.cjs +153 -120
- package/package.json +8 -8
- package/src/components/chips.js +3 -3
- package/src/components/expand-container.js +27 -4
- package/src/components/filters/range.js +8 -5
- package/src/components/filters/selector.js +10 -10
- package/src/components/filters/spatial.js +8 -8
- package/src/components/filters/text.js +18 -5
- package/src/components/itemfilter-container.js +70 -12
- package/src/components/results.js +5 -5
- package/src/enums/config.js +6 -0
- package/src/enums/index.js +6 -1
- package/src/helpers/chip-items.js +2 -2
- package/src/helpers/filter-client.js +6 -6
- package/src/helpers/filter-external.js +4 -4
- package/src/helpers/get-value.js +1 -1
- package/src/helpers/highlighting.js +2 -2
- package/src/helpers/is-date.js +1 -1
- package/src/helpers/is-filters-dirty.js +1 -1
- package/src/helpers/map-layers.js +2 -2
- package/src/helpers/merge-highlight-indices.js +1 -1
- package/src/helpers/reset-filter.js +2 -2
- package/src/helpers/spatial.js +4 -4
- package/src/helpers/toggle-accordion.js +1 -1
- package/src/main.js +57 -42
- package/src/methods/chips/handler.js +4 -7
- package/src/methods/container/handler.js +21 -5
- package/src/methods/container/index.js +6 -0
- package/src/methods/container/init-popver.js +2 -2
- package/src/methods/container/inline-search.js +54 -0
- package/src/methods/container/reset-filter.js +5 -2
- package/src/methods/container/reset-search.js +7 -4
- package/src/methods/container/search-filter.js +10 -1
- package/src/methods/filters/index.js +5 -1
- package/src/methods/filters/range.js +2 -2
- package/src/methods/filters/selector.js +26 -18
- package/src/methods/filters/spatial.js +5 -5
- package/src/methods/filters/text.js +15 -2
- package/src/methods/itemfilter/create-filter.js +6 -6
- package/src/methods/itemfilter/create-reset.js +3 -3
- package/src/methods/itemfilter/filter-apply.js +10 -3
- package/src/methods/itemfilter/reset-filter.js +4 -3
- package/src/methods/itemfilter/search.js +3 -3
- package/src/methods/itemfilter/sort-results.js +4 -4
- package/src/methods/results/aggregate-results.js +3 -3
- package/src/methods/results/create.js +2 -2
- package/types/components/chips.d.ts +3 -3
- package/types/components/expand-container.d.ts +3 -3
- package/types/components/expand-container.d.ts.map +1 -1
- package/types/components/filters/range.d.ts +3 -3
- package/types/components/filters/range.d.ts.map +1 -1
- package/types/components/filters/selector.d.ts +9 -9
- package/types/components/filters/spatial.d.ts +7 -7
- package/types/components/filters/spatial.d.ts.map +1 -1
- package/types/components/filters/text.d.ts +10 -4
- package/types/components/filters/text.d.ts.map +1 -1
- package/types/components/itemfilter-container.d.ts +14 -5
- package/types/components/itemfilter-container.d.ts.map +1 -1
- package/types/components/results.d.ts +5 -5
- package/types/enums/config.d.ts +5 -0
- package/types/enums/config.d.ts.map +1 -1
- package/types/enums/index.d.ts +1 -1
- package/types/helpers/chip-items.d.ts +3 -3
- package/types/helpers/chip-items.d.ts.map +1 -1
- package/types/helpers/filter-client.d.ts +2 -2
- package/types/helpers/filter-client.d.ts.map +1 -1
- package/types/helpers/filter-external.d.ts +5 -5
- package/types/helpers/filter-external.d.ts.map +1 -1
- package/types/helpers/get-value.d.ts +2 -2
- package/types/helpers/get-value.d.ts.map +1 -1
- package/types/helpers/highlighting.d.ts +3 -3
- package/types/helpers/highlighting.d.ts.map +1 -1
- package/types/helpers/is-date.d.ts +2 -2
- package/types/helpers/is-date.d.ts.map +1 -1
- package/types/helpers/is-filters-dirty.d.ts +2 -2
- package/types/helpers/is-filters-dirty.d.ts.map +1 -1
- package/types/helpers/map-layers.d.ts +3 -3
- package/types/helpers/map-layers.d.ts.map +1 -1
- package/types/helpers/merge-highlight-indices.d.ts +1 -1
- package/types/helpers/reset-filter.d.ts +3 -3
- package/types/helpers/reset-filter.d.ts.map +1 -1
- package/types/helpers/spatial.d.ts +2 -2
- package/types/helpers/spatial.d.ts.map +1 -1
- package/types/helpers/toggle-accordion.d.ts +2 -2
- package/types/helpers/toggle-accordion.d.ts.map +1 -1
- package/types/main.d.ts +17 -12
- package/types/main.d.ts.map +1 -1
- package/types/methods/chips/handler.d.ts +6 -6
- package/types/methods/chips/handler.d.ts.map +1 -1
- package/types/methods/container/handler.d.ts +18 -10
- package/types/methods/container/handler.d.ts.map +1 -1
- package/types/methods/container/index.d.ts +2 -1
- package/types/methods/container/init-popver.d.ts +3 -3
- package/types/methods/container/init-popver.d.ts.map +1 -1
- package/types/methods/container/inline-search.d.ts +22 -0
- package/types/methods/container/inline-search.d.ts.map +1 -0
- package/types/methods/container/reset-filter.d.ts +2 -2
- package/types/methods/container/reset-filter.d.ts.map +1 -1
- package/types/methods/container/reset-search.d.ts +2 -2
- package/types/methods/container/reset-search.d.ts.map +1 -1
- package/types/methods/container/search-filter.d.ts +2 -2
- package/types/methods/container/search-filter.d.ts.map +1 -1
- package/types/methods/filters/index.d.ts +1 -1
- package/types/methods/filters/range.d.ts +4 -4
- package/types/methods/filters/range.d.ts.map +1 -1
- package/types/methods/filters/selector.d.ts +15 -14
- package/types/methods/filters/selector.d.ts.map +1 -1
- package/types/methods/filters/spatial.d.ts +8 -8
- package/types/methods/filters/spatial.d.ts.map +1 -1
- package/types/methods/filters/text.d.ts +11 -4
- package/types/methods/filters/text.d.ts.map +1 -1
- package/types/methods/itemfilter/create-filter.d.ts +3 -3
- package/types/methods/itemfilter/create-filter.d.ts.map +1 -1
- package/types/methods/itemfilter/create-reset.d.ts +3 -3
- package/types/methods/itemfilter/create-reset.d.ts.map +1 -1
- package/types/methods/itemfilter/filter-apply.d.ts +4 -4
- package/types/methods/itemfilter/filter-apply.d.ts.map +1 -1
- package/types/methods/itemfilter/reset-filter.d.ts +3 -2
- package/types/methods/itemfilter/reset-filter.d.ts.map +1 -1
- package/types/methods/itemfilter/search.d.ts +4 -4
- package/types/methods/itemfilter/search.d.ts.map +1 -1
- package/types/methods/itemfilter/sort-results.d.ts +6 -6
- package/types/methods/itemfilter/sort-results.d.ts.map +1 -1
- package/types/methods/results/aggregate-results.d.ts +4 -4
- package/types/methods/results/aggregate-results.d.ts.map +1 -1
- package/types/methods/results/create.d.ts +4 -4
- package/types/methods/results/create.d.ts.map +1 -1
package/src/main.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LitElement, html, nothing } from "lit";
|
|
2
|
+
import { dispatchElementEvent } from "@eox/elements-utils";
|
|
2
3
|
import { map } from "lit/directives/map.js";
|
|
3
4
|
import { when } from "lit/directives/when.js";
|
|
4
5
|
import { style } from "./style";
|
|
@@ -53,6 +54,7 @@ import {
|
|
|
53
54
|
* @fires mouseenter:result - When a result is hovered
|
|
54
55
|
* @fires mouseleave:result - When a result is un-hovered
|
|
55
56
|
* @fires click:result-action - When a result action button is clicked
|
|
57
|
+
* @fires {CustomEvent<import("@eox/elements-utils").EOxActivityDetail>} eox:activity - Fires on genuine user interactions, wrapping the original event for analytics tracking.
|
|
56
58
|
*/
|
|
57
59
|
export class EOxItemFilter extends LitElement {
|
|
58
60
|
// Define properties with defaults and types
|
|
@@ -134,13 +136,18 @@ export class EOxItemFilter extends LitElement {
|
|
|
134
136
|
*/
|
|
135
137
|
this.selectedResult = null;
|
|
136
138
|
|
|
139
|
+
this._debouncedSearch = _debounce(this.searchHandler, 100, {
|
|
140
|
+
leading: true,
|
|
141
|
+
});
|
|
142
|
+
|
|
137
143
|
/**
|
|
138
144
|
* @type Function
|
|
139
145
|
* @private
|
|
140
146
|
*/
|
|
141
|
-
this.search =
|
|
142
|
-
|
|
143
|
-
|
|
147
|
+
this.search = (isUser = false) => {
|
|
148
|
+
if (isUser) this._isUserFilter = true;
|
|
149
|
+
this._debouncedSearch();
|
|
150
|
+
};
|
|
144
151
|
|
|
145
152
|
/**
|
|
146
153
|
* Aggregate results by a property key
|
|
@@ -178,7 +185,7 @@ export class EOxItemFilter extends LitElement {
|
|
|
178
185
|
|
|
179
186
|
/**
|
|
180
187
|
* The filter properties. Can be passed as a property or stringified JSON attribute.
|
|
181
|
-
* @type Array<{key?: String, keys?: Array<String>, title: String, type: String, placeholder?: String, format?: String, state?: Object}>
|
|
188
|
+
* @type Array<{key?: String, keys?: Array<String>, title: String, type: String, placeholder?: String, format?: String, state?: Object, inlineSearch?: Boolean}>
|
|
182
189
|
*/
|
|
183
190
|
this.filterProperties = [];
|
|
184
191
|
|
|
@@ -298,7 +305,7 @@ export class EOxItemFilter extends LitElement {
|
|
|
298
305
|
|
|
299
306
|
/** Overrides elements current CSS.
|
|
300
307
|
*
|
|
301
|
-
* @type {
|
|
308
|
+
* @type {string}
|
|
302
309
|
*/
|
|
303
310
|
this.styleOverride = "";
|
|
304
311
|
|
|
@@ -329,20 +336,20 @@ export class EOxItemFilter extends LitElement {
|
|
|
329
336
|
* Requests an update after the search completes.
|
|
330
337
|
*/
|
|
331
338
|
async searchHandler() {
|
|
339
|
+
const isUser = Boolean(this._isUserFilter);
|
|
340
|
+
this._isUserFilter = false;
|
|
332
341
|
await searchMethod(this.#config, this.#items, this);
|
|
333
342
|
/**
|
|
334
343
|
* Fires when the filters are changed; event detail includes `filters` and `results`
|
|
335
344
|
*/
|
|
336
|
-
this
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}),
|
|
345
|
-
);
|
|
345
|
+
dispatchElementEvent(this, "filter", {
|
|
346
|
+
detail: {
|
|
347
|
+
results: this.results,
|
|
348
|
+
filters: this.filters,
|
|
349
|
+
},
|
|
350
|
+
activity: isUser,
|
|
351
|
+
action: "filter",
|
|
352
|
+
});
|
|
346
353
|
if (this.inlineMode)
|
|
347
354
|
/** @type {import("./components/itemfilter-container").EOxItemFilterContainer} **/ (
|
|
348
355
|
this.renderRoot.querySelector("eox-itemfilter-container")
|
|
@@ -354,7 +361,7 @@ export class EOxItemFilter extends LitElement {
|
|
|
354
361
|
* Sorts the given items based on the current configuration.
|
|
355
362
|
*
|
|
356
363
|
* @param {Array<object>} items - The items to be sorted.
|
|
357
|
-
* @param {
|
|
364
|
+
* @param {object} [options] - Optional sorting parameters.
|
|
358
365
|
* @param {boolean} [options.isExternalResult] - Flag for results from external filter.
|
|
359
366
|
* @returns {Array<object>} - The sorted items.
|
|
360
367
|
*/
|
|
@@ -365,7 +372,7 @@ export class EOxItemFilter extends LitElement {
|
|
|
365
372
|
/**
|
|
366
373
|
* Creates a filter element based on the given filter object and tab index.
|
|
367
374
|
*
|
|
368
|
-
* @param {
|
|
375
|
+
* @param {object} filterObject - The filter object.
|
|
369
376
|
* @param {number} tabIndex - The tab index for the filter element.
|
|
370
377
|
* @returns {import("lit").HTMLTemplateResult} - The template result for the filter element.
|
|
371
378
|
*/
|
|
@@ -376,7 +383,7 @@ export class EOxItemFilter extends LitElement {
|
|
|
376
383
|
/**
|
|
377
384
|
* Creates a reset element for the given filter object and tab index.
|
|
378
385
|
*
|
|
379
|
-
* @param {
|
|
386
|
+
* @param {object} filterObject - The filter object.
|
|
380
387
|
* @param {number} tabIndex - The tab index for the reset element.
|
|
381
388
|
* @returns {import("lit").HTMLTemplateResult} - The template result for the filter element.
|
|
382
389
|
*/
|
|
@@ -386,9 +393,10 @@ export class EOxItemFilter extends LitElement {
|
|
|
386
393
|
|
|
387
394
|
/**
|
|
388
395
|
* Resets all applied filters.
|
|
396
|
+
* @param {boolean} [isUser=false]
|
|
389
397
|
*/
|
|
390
|
-
resetFilters() {
|
|
391
|
-
resetFilterMethod(this);
|
|
398
|
+
resetFilters(isUser = false) {
|
|
399
|
+
resetFilterMethod(this, isUser);
|
|
392
400
|
}
|
|
393
401
|
|
|
394
402
|
/**
|
|
@@ -458,27 +466,27 @@ export class EOxItemFilter extends LitElement {
|
|
|
458
466
|
/**
|
|
459
467
|
* Updates selected result when result component triggers the "result" event.
|
|
460
468
|
*
|
|
461
|
-
* @param {{detail:
|
|
469
|
+
* @param {{detail: object}} evt - "result" event triggered by result component
|
|
462
470
|
*/
|
|
463
471
|
updateResult(evt) {
|
|
464
472
|
this.selectedResult = evt.detail;
|
|
465
473
|
/**
|
|
466
474
|
* Fires when a result is selected; event detail is `selectedResult`
|
|
467
475
|
*/
|
|
468
|
-
this
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
);
|
|
476
|
+
dispatchElementEvent(this, "select", {
|
|
477
|
+
detail: this.selectedResult,
|
|
478
|
+
activity: true,
|
|
479
|
+
action: "select",
|
|
480
|
+
bubbles: true,
|
|
481
|
+
composed: true,
|
|
482
|
+
});
|
|
475
483
|
this.requestUpdate();
|
|
476
484
|
}
|
|
477
485
|
|
|
478
486
|
/**
|
|
479
487
|
* Dispatches an event when result component triggers the "mouseenter:result" event.
|
|
480
488
|
*
|
|
481
|
-
* @param {{detail:
|
|
489
|
+
* @param {{detail: object}} evt - "mouseenter:result" event triggered by result component
|
|
482
490
|
*/
|
|
483
491
|
mouseEnterResult(evt) {
|
|
484
492
|
/**
|
|
@@ -496,7 +504,7 @@ export class EOxItemFilter extends LitElement {
|
|
|
496
504
|
/**
|
|
497
505
|
* Dispatches an event when result component triggers the "mouseleave:result" event.
|
|
498
506
|
*
|
|
499
|
-
* @param {{detail:
|
|
507
|
+
* @param {{detail: object}} evt - "mouseleave:result" event triggered by result component
|
|
500
508
|
*/
|
|
501
509
|
mouseLeaveResult(evt) {
|
|
502
510
|
/**
|
|
@@ -514,19 +522,19 @@ export class EOxItemFilter extends LitElement {
|
|
|
514
522
|
/**
|
|
515
523
|
* Emits "click:result-action" event.
|
|
516
524
|
*
|
|
517
|
-
* @param {{detail:
|
|
525
|
+
* @param {{detail: object}} evt - "click:result-action" event triggered by result component
|
|
518
526
|
*/
|
|
519
527
|
emitResultAction(evt) {
|
|
520
528
|
/**
|
|
521
529
|
* Fires when a result-action is clicked; event detail is `result`
|
|
522
530
|
*/
|
|
523
|
-
this
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
);
|
|
531
|
+
dispatchElementEvent(this, "click:result-action", {
|
|
532
|
+
detail: evt.detail,
|
|
533
|
+
activity: true,
|
|
534
|
+
action: "click:result-action",
|
|
535
|
+
bubbles: true,
|
|
536
|
+
composed: true,
|
|
537
|
+
});
|
|
530
538
|
}
|
|
531
539
|
|
|
532
540
|
/**
|
|
@@ -559,8 +567,8 @@ export class EOxItemFilter extends LitElement {
|
|
|
559
567
|
.filters=${this.filters}
|
|
560
568
|
.filterProperties=${this.filterProperties}
|
|
561
569
|
.inlineMode=${this.inlineMode || false}
|
|
562
|
-
@reset=${() => this
|
|
563
|
-
@filter=${() => this.search()}
|
|
570
|
+
@reset=${() => resetFilterMethod(this, true)}
|
|
571
|
+
@filter=${() => this.search(true)}
|
|
564
572
|
>
|
|
565
573
|
<section
|
|
566
574
|
slot="section"
|
|
@@ -587,7 +595,7 @@ export class EOxItemFilter extends LitElement {
|
|
|
587
595
|
id="filter-reset"
|
|
588
596
|
class="reset-icon border small"
|
|
589
597
|
data-cy="filter-reset"
|
|
590
|
-
@click=${() => this.resetFilters()}
|
|
598
|
+
@click=${() => this.resetFilters(true)}
|
|
591
599
|
>
|
|
592
600
|
${this.unstyled
|
|
593
601
|
? nothing
|
|
@@ -616,7 +624,14 @@ export class EOxItemFilter extends LitElement {
|
|
|
616
624
|
${map(
|
|
617
625
|
Object.values(this.filters),
|
|
618
626
|
(filterObject, index) =>
|
|
619
|
-
html` <li
|
|
627
|
+
html` <li
|
|
628
|
+
class="no-padding"
|
|
629
|
+
style=${this.inlineMode &&
|
|
630
|
+
filterObject.inlineSearch &&
|
|
631
|
+
filterObject.type === "text"
|
|
632
|
+
? "display: none"
|
|
633
|
+
: nothing}
|
|
634
|
+
>
|
|
620
635
|
<eox-itemfilter-expandcontainer
|
|
621
636
|
.filterObject=${filterObject}
|
|
622
637
|
@details-toggled=${(e) =>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Handles the click event on a chip, highlighting the clicked chip and updating the component.
|
|
3
3
|
*
|
|
4
4
|
* @param {Event} evt - The click event.
|
|
5
|
-
* @param {
|
|
5
|
+
* @param {object} EOxItemFilterChips - The EOxItemFilterChips component instance.
|
|
6
6
|
*/
|
|
7
7
|
export function handleChipClickMethod(evt, EOxItemFilterChips) {
|
|
8
8
|
// Remove the 'highlighted' class from all chips
|
|
@@ -21,7 +21,7 @@ export function handleChipClickMethod(evt, EOxItemFilterChips) {
|
|
|
21
21
|
*
|
|
22
22
|
* @param {Event} event - The close event.
|
|
23
23
|
* @param {number} index - The index of the chip to be removed.
|
|
24
|
-
* @param {
|
|
24
|
+
* @param {object} EOxItemFilterChips - The EOxItemFilterChips component instance.
|
|
25
25
|
*/
|
|
26
26
|
export function handleCloseMethod(event, index, EOxItemFilterChips) {
|
|
27
27
|
// Remove the chip from the controller
|
|
@@ -32,7 +32,7 @@ export function handleCloseMethod(event, index, EOxItemFilterChips) {
|
|
|
32
32
|
* Handles keyboard events for the EOxItemFilterChips component.
|
|
33
33
|
*
|
|
34
34
|
* @param {KeyboardEvent} event - The keyboard event.
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {object} EOxItemFilterChips - The EOxItemFilterChips component instance.
|
|
36
36
|
*/
|
|
37
37
|
export function keyboardEventListenerMethod(event, EOxItemFilterChips) {
|
|
38
38
|
const { code, target } = event;
|
|
@@ -51,9 +51,6 @@ export function keyboardEventListenerMethod(event, EOxItemFilterChips) {
|
|
|
51
51
|
)
|
|
52
52
|
return;
|
|
53
53
|
|
|
54
|
-
// Prevent default action for the Space key
|
|
55
|
-
if (code === "Space") event.preventDefault();
|
|
56
|
-
|
|
57
54
|
// Stop propagation for keys other than Escape, Space, and Enter
|
|
58
55
|
if (!["Escape", "Space", "Enter"].includes(code)) event.stopPropagation();
|
|
59
56
|
|
|
@@ -71,7 +68,7 @@ export function keyboardEventListenerMethod(event, EOxItemFilterChips) {
|
|
|
71
68
|
*
|
|
72
69
|
* @param {string} key - The key pressed.
|
|
73
70
|
* @param {string} textValue - The current value of the input field.
|
|
74
|
-
* @param {
|
|
71
|
+
* @param {object} that - The EOxItemFilterChips component instance.
|
|
75
72
|
*/
|
|
76
73
|
function handleKeyboard(key, textValue, that) {
|
|
77
74
|
const highlightedChip = that.renderRoot.querySelector(".chip.highlighted");
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import resetSearchMethod from "./reset-search.js";
|
|
2
|
+
import searchFilterMethod from "./search-filter.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Handles the click event on the form, stopping propagation if in inline mode.
|
|
5
6
|
*
|
|
6
7
|
* @param {Event} event - The click event.
|
|
7
|
-
* @param {
|
|
8
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
8
9
|
*/
|
|
9
10
|
export function handleFormClickMethod(event, EOxItemFilterContainer) {
|
|
10
11
|
if (EOxItemFilterContainer.inlineMode) event.stopPropagation();
|
|
@@ -13,7 +14,7 @@ export function handleFormClickMethod(event, EOxItemFilterContainer) {
|
|
|
13
14
|
/**
|
|
14
15
|
* Shows the dropdown when the component is focused, if in inline mode.
|
|
15
16
|
*
|
|
16
|
-
* @param {
|
|
17
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
17
18
|
*/
|
|
18
19
|
export function handleShowDropdownOnFocusMethod(EOxItemFilterContainer) {
|
|
19
20
|
if (EOxItemFilterContainer.inlineMode) {
|
|
@@ -21,11 +22,26 @@ export function handleShowDropdownOnFocusMethod(EOxItemFilterContainer) {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Handles typing in the inline search box: shows the dropdown, filters the listed filters
|
|
27
|
+
* by title and keeps the text for the inline search action.
|
|
28
|
+
*
|
|
29
|
+
* @param {Event} event - The input event.
|
|
30
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
31
|
+
*/
|
|
32
|
+
export function handleSearchInputMethod(event, EOxItemFilterContainer) {
|
|
33
|
+
if (!(event.target instanceof HTMLInputElement)) return;
|
|
34
|
+
// A search closes the dropdown but keeps focus in the box, so typing has to open it again
|
|
35
|
+
EOxItemFilterContainer.showDropdown = true;
|
|
36
|
+
searchFilterMethod(event, EOxItemFilterContainer);
|
|
37
|
+
EOxItemFilterContainer.inlineSearchText = event.target.value.trim();
|
|
38
|
+
}
|
|
39
|
+
|
|
24
40
|
/**
|
|
25
41
|
* Toggles the dropdown visibility when an event occurs, stopping propagation if in inline mode.
|
|
26
42
|
*
|
|
27
43
|
* @param {Event} event - The event that triggers the toggle.
|
|
28
|
-
* @param {
|
|
44
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
29
45
|
*/
|
|
30
46
|
export function handleToggleDropdownMethod(event, EOxItemFilterContainer) {
|
|
31
47
|
if (EOxItemFilterContainer.inlineMode) {
|
|
@@ -38,7 +54,7 @@ export function handleToggleDropdownMethod(event, EOxItemFilterContainer) {
|
|
|
38
54
|
* Handles the keydown event, resetting the search and hiding the dropdown if Escape is pressed in inline mode.
|
|
39
55
|
*
|
|
40
56
|
* @param {KeyboardEvent} event - The keydown event.
|
|
41
|
-
* @param {
|
|
57
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
42
58
|
*/
|
|
43
59
|
export function handleKeyDownMethod(event, EOxItemFilterContainer) {
|
|
44
60
|
if (
|
|
@@ -55,7 +71,7 @@ export function handleKeyDownMethod(event, EOxItemFilterContainer) {
|
|
|
55
71
|
* Handles clicks outside the component, resetting the search and hiding the dropdown if in inline mode.
|
|
56
72
|
*
|
|
57
73
|
* @param {Event} event - The click event.
|
|
58
|
-
* @param {
|
|
74
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
59
75
|
*/
|
|
60
76
|
export function handleClickOutsideMethod(event, EOxItemFilterContainer) {
|
|
61
77
|
if (
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export { default as searchFilterMethod } from "./search-filter";
|
|
2
|
+
export {
|
|
3
|
+
getInlineSearchFilters,
|
|
4
|
+
applyInlineSearchMethod,
|
|
5
|
+
handleInlineSearchKeyDownMethod,
|
|
6
|
+
} from "./inline-search";
|
|
2
7
|
export { default as resetFilterMethod } from "./reset-filter";
|
|
3
8
|
export { default as initPopoverMethod } from "./init-popver";
|
|
4
9
|
export {
|
|
5
10
|
handleFormClickMethod,
|
|
6
11
|
handleShowDropdownOnFocusMethod,
|
|
12
|
+
handleSearchInputMethod,
|
|
7
13
|
handleToggleDropdownMethod,
|
|
8
14
|
handleKeyDownMethod,
|
|
9
15
|
handleClickOutsideMethod,
|
|
@@ -3,8 +3,8 @@ import { autoUpdate, computePosition } from "@floating-ui/dom";
|
|
|
3
3
|
/**
|
|
4
4
|
* Init popover autoUpdate and position
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @
|
|
6
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
7
|
+
* @returns {() => void}
|
|
8
8
|
*/
|
|
9
9
|
function initPopover(EOxItemFilterContainer) {
|
|
10
10
|
const trigger = EOxItemFilterContainer.renderRoot.querySelector(
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import resetSearchMethod from "./reset-search.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adds the inline search box text to every text filter with `inlineSearch` enabled,
|
|
5
|
+
* then clears the box and closes the dropdown.
|
|
6
|
+
*
|
|
7
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
8
|
+
*/
|
|
9
|
+
export function applyInlineSearchMethod(EOxItemFilterContainer) {
|
|
10
|
+
const input = EOxItemFilterContainer.renderRoot.querySelector(
|
|
11
|
+
"#eox-itemfilter-input-search",
|
|
12
|
+
);
|
|
13
|
+
const text = input.value.trim();
|
|
14
|
+
const inlineSearchFilters = getInlineSearchFilters(EOxItemFilterContainer);
|
|
15
|
+
if (!text || !inlineSearchFilters.length) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
inlineSearchFilters.forEach((filter) => {
|
|
20
|
+
// Filter ids only replace the first "|" (see create-filter.js), so they must be escaped
|
|
21
|
+
EOxItemFilterContainer.querySelector(
|
|
22
|
+
`#${CSS.escape(`filter-${filter.key}`.replace("|", "-"))}`,
|
|
23
|
+
)?.appendText(text);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
resetSearchMethod(EOxItemFilterContainer);
|
|
27
|
+
// Focusing the box opens the dropdown, so focus it before closing the dropdown
|
|
28
|
+
input.focus();
|
|
29
|
+
EOxItemFilterContainer.showDropdown = false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Handles the keydown event of the inline search box, applying the inline search on Enter.
|
|
34
|
+
*
|
|
35
|
+
* @param {KeyboardEvent} event - The keydown event.
|
|
36
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
37
|
+
*/
|
|
38
|
+
export function handleInlineSearchKeyDownMethod(event, EOxItemFilterContainer) {
|
|
39
|
+
// Enter that confirms an IME composition (e.g. Japanese input) is not a search
|
|
40
|
+
if (event.key !== "Enter" || event.isComposing) return;
|
|
41
|
+
applyInlineSearchMethod(EOxItemFilterContainer);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns the text filters that receive the text of the inline search box.
|
|
46
|
+
*
|
|
47
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
48
|
+
* @returns {Array<object>} The text filters with `inlineSearch` enabled.
|
|
49
|
+
*/
|
|
50
|
+
export function getInlineSearchFilters(EOxItemFilterContainer) {
|
|
51
|
+
return Object.values(EOxItemFilterContainer.filters).filter(
|
|
52
|
+
(filter) => filter.inlineSearch && filter.type === "text",
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
* Resets a specific filter in the EOxItemFilterContainer based on the event target.
|
|
3
3
|
*
|
|
4
4
|
* @param {Event} event - The event that triggers the filter reset.
|
|
5
|
-
* @param {
|
|
5
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
6
6
|
*/
|
|
7
7
|
function resetFilterMethod(event, EOxItemFilterContainer) {
|
|
8
8
|
if (!(event.target instanceof HTMLElement)) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
const filterKey = event.target.getAttribute("data-close").replace("|", "-");
|
|
12
|
-
|
|
12
|
+
// Filter ids only replace the first "|" (see create-filter.js), so they must be escaped
|
|
13
|
+
EOxItemFilterContainer.querySelector(
|
|
14
|
+
`#${CSS.escape(`filter-${filterKey}`)}`,
|
|
15
|
+
).reset();
|
|
13
16
|
EOxItemFilterContainer.dispatchEvent(new CustomEvent("filter"));
|
|
14
17
|
EOxItemFilterContainer.requestUpdate();
|
|
15
18
|
}
|
|
@@ -3,13 +3,16 @@ import searchFilterMethod from "./search-filter.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Resets the search input in the EOxItemFilterContainer and triggers a search filter update.
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
7
7
|
*/
|
|
8
8
|
function resetSearchMethod(EOxItemFilterContainer) {
|
|
9
|
-
EOxItemFilterContainer.renderRoot.querySelector(
|
|
9
|
+
const input = EOxItemFilterContainer.renderRoot.querySelector(
|
|
10
10
|
"#eox-itemfilter-input-search",
|
|
11
|
-
)
|
|
12
|
-
|
|
11
|
+
);
|
|
12
|
+
input.value = "";
|
|
13
|
+
EOxItemFilterContainer.inlineSearchText = "";
|
|
14
|
+
// searchFilterMethod only accepts events targeting a real input element
|
|
15
|
+
const event = { target: input };
|
|
13
16
|
searchFilterMethod(
|
|
14
17
|
/** @type {Event} **/ (/** @type {unknown} **/ (event)),
|
|
15
18
|
EOxItemFilterContainer,
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import Fuse from "fuse.js";
|
|
2
|
+
import { INLINE_SEARCH_TITLE_THRESHOLD } from "../../enums/index.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Filters the items in the EOxItemFilterContainer based on the search input.
|
|
5
6
|
*
|
|
6
7
|
* @param {Event} event - The input event that triggers the search.
|
|
7
|
-
* @param {
|
|
8
|
+
* @param {object} EOxItemFilterContainer - The EOxItemFilterContainer component instance.
|
|
8
9
|
*/
|
|
9
10
|
function searchFilterMethod(event, EOxItemFilterContainer) {
|
|
11
|
+
const isInlineSearch = (filter) =>
|
|
12
|
+
filter.inlineSearch && filter.type === "text";
|
|
10
13
|
// Create a Fuse instance for fuzzy searching with the filter properties
|
|
11
14
|
const fuse = new Fuse(EOxItemFilterContainer.filterProperties, {
|
|
12
15
|
keys: ["title"],
|
|
16
|
+
// Stricter title matching for inlineSearch
|
|
17
|
+
...(EOxItemFilterContainer.filterProperties.some(isInlineSearch) && {
|
|
18
|
+
threshold: INLINE_SEARCH_TITLE_THRESHOLD,
|
|
19
|
+
}),
|
|
13
20
|
});
|
|
14
21
|
if (!(event.target instanceof HTMLInputElement)) {
|
|
15
22
|
return;
|
|
@@ -20,6 +27,8 @@ function searchFilterMethod(event, EOxItemFilterContainer) {
|
|
|
20
27
|
|
|
21
28
|
// Update the display of filter elements based on the search results
|
|
22
29
|
Object.keys(EOxItemFilterContainer.filters).forEach((filter) => {
|
|
30
|
+
// Hidden in inline mode (see main.js), as the inline search box is its input
|
|
31
|
+
if (isInlineSearch(EOxItemFilterContainer.filters[filter])) return;
|
|
23
32
|
EOxItemFilterContainer.querySelector(
|
|
24
33
|
`[data-details="${filter}"]`,
|
|
25
34
|
).parentElement.style.display =
|
|
@@ -42,7 +42,7 @@ export function resetRangeMethod(EOxItemFilterRange) {
|
|
|
42
42
|
* Handles input changes for the range filter and updates the filter state accordingly.
|
|
43
43
|
*
|
|
44
44
|
* @param {CustomEvent} evt - The input event that triggers the update.
|
|
45
|
-
* @param {
|
|
45
|
+
* @param {object} EOxItemFilterRange - The EOxItemFilterRange component instance.
|
|
46
46
|
*/
|
|
47
47
|
export function rangeInputHandlerMethod(evt, EOxItemFilterRange) {
|
|
48
48
|
const parseVal = (val) => {
|
|
@@ -115,7 +115,7 @@ export function rangeInputHandlerMethod(evt, EOxItemFilterRange) {
|
|
|
115
115
|
*
|
|
116
116
|
* @param {number|string} val - The value of the range label.
|
|
117
117
|
* @param {string} pos - The position of the range label (e.g., "min" or "max").
|
|
118
|
-
* @param {
|
|
118
|
+
* @param {object} EOxItemFilterRange - The EOxItemFilterRange component instance.
|
|
119
119
|
* @returns {import("lit").HTMLTemplateResult}
|
|
120
120
|
*/
|
|
121
121
|
export function rangeLabelMethod(val, pos, EOxItemFilterRange) {
|
|
@@ -4,10 +4,10 @@ import Fuse from "fuse.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Resets the selector filter to its default state and updates the component.
|
|
6
6
|
*
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
8
8
|
*/
|
|
9
9
|
export function resetSelectorMethod(EOxItemFilterSelector) {
|
|
10
|
-
removeItemSelectorMethod(-1, EOxItemFilterSelector);
|
|
10
|
+
removeItemSelectorMethod(-1, EOxItemFilterSelector, false);
|
|
11
11
|
|
|
12
12
|
resetFilter(EOxItemFilterSelector.filterObject);
|
|
13
13
|
EOxItemFilterSelector.requestUpdate();
|
|
@@ -17,23 +17,28 @@ export function resetSelectorMethod(EOxItemFilterSelector) {
|
|
|
17
17
|
* Removes an item from the selected items list and updates suggestions and filter list.
|
|
18
18
|
*
|
|
19
19
|
* @param {number} index - The index of the item to remove, or -1 to remove all items.
|
|
20
|
-
* @param {
|
|
20
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
21
|
+
* @param {boolean} [emitEvent=true] - Whether to emit the filter event.
|
|
21
22
|
*/
|
|
22
|
-
export function removeItemSelectorMethod(
|
|
23
|
+
export function removeItemSelectorMethod(
|
|
24
|
+
index,
|
|
25
|
+
EOxItemFilterSelector,
|
|
26
|
+
emitEvent = true,
|
|
27
|
+
) {
|
|
23
28
|
EOxItemFilterSelector.selectedItems =
|
|
24
29
|
index === -1
|
|
25
30
|
? []
|
|
26
31
|
: EOxItemFilterSelector.selectedItems.filter((_, i) => i !== index);
|
|
27
32
|
|
|
28
33
|
updateSuggestions(EOxItemFilterSelector);
|
|
29
|
-
updateFilterList(EOxItemFilterSelector);
|
|
34
|
+
updateFilterList(EOxItemFilterSelector, emitEvent);
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
38
|
* Toggles the selection of an item and updates the component.
|
|
34
39
|
*
|
|
35
|
-
* @param {
|
|
36
|
-
* @param {
|
|
40
|
+
* @param {object} item - The item to toggle.
|
|
41
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
37
42
|
*/
|
|
38
43
|
export function toggleItemSelectorMethod(item, EOxItemFilterSelector) {
|
|
39
44
|
const itemIndex = EOxItemFilterSelector.selectedItems.indexOf(item);
|
|
@@ -64,7 +69,7 @@ export function toggleItemSelectorMethod(item, EOxItemFilterSelector) {
|
|
|
64
69
|
* Handles input changes for the selector and updates the query and suggestions.
|
|
65
70
|
*
|
|
66
71
|
* @param {Event} event - The input event.
|
|
67
|
-
* @param {
|
|
72
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
68
73
|
*/
|
|
69
74
|
export function handleInputSelectorMethod(event, EOxItemFilterSelector) {
|
|
70
75
|
if (!(event.target instanceof HTMLInputElement)) {
|
|
@@ -78,7 +83,7 @@ export function handleInputSelectorMethod(event, EOxItemFilterSelector) {
|
|
|
78
83
|
* Handles keydown events for the selector and navigates or selects items based on the key pressed.
|
|
79
84
|
*
|
|
80
85
|
* @param {KeyboardEvent} event - The keydown event.
|
|
81
|
-
* @param {
|
|
86
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
82
87
|
*/
|
|
83
88
|
export function handleKeyDownSelectorMethod(event, EOxItemFilterSelector) {
|
|
84
89
|
switch (event.key) {
|
|
@@ -119,8 +124,8 @@ export function handleKeyDownSelectorMethod(event, EOxItemFilterSelector) {
|
|
|
119
124
|
/**
|
|
120
125
|
* Updates the Fuse.js instance and suggestions when properties change.
|
|
121
126
|
*
|
|
122
|
-
* @param {
|
|
123
|
-
* @param {
|
|
127
|
+
* @param {object} changedProperties - The properties that changed.
|
|
128
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
124
129
|
*/
|
|
125
130
|
export function updatedSelectorMethod(
|
|
126
131
|
changedProperties,
|
|
@@ -134,9 +139,9 @@ export function updatedSelectorMethod(
|
|
|
134
139
|
/**
|
|
135
140
|
* Sorts and returns the suggestions based on the filter's sort method or default string comparison.
|
|
136
141
|
*
|
|
137
|
-
* @param {
|
|
138
|
-
* @param {Array<
|
|
139
|
-
* @returns {Array<
|
|
142
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
143
|
+
* @param {Array<object>} suggestion - The suggestions to sort.
|
|
144
|
+
* @returns {Array<object>} The sorted suggestions.
|
|
140
145
|
*/
|
|
141
146
|
function getSortedSuggestions(EOxItemFilterSelector, suggestion) {
|
|
142
147
|
const sortCallback =
|
|
@@ -150,7 +155,7 @@ function getSortedSuggestions(EOxItemFilterSelector, suggestion) {
|
|
|
150
155
|
/**
|
|
151
156
|
* Updates the filtered suggestions based on the current query.
|
|
152
157
|
*
|
|
153
|
-
* @param {
|
|
158
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
154
159
|
*/
|
|
155
160
|
function updateSuggestions(EOxItemFilterSelector) {
|
|
156
161
|
const items = (
|
|
@@ -190,9 +195,10 @@ function updateSuggestions(EOxItemFilterSelector) {
|
|
|
190
195
|
/**
|
|
191
196
|
* Updates the filter list based on the selected items.
|
|
192
197
|
*
|
|
193
|
-
* @param {
|
|
198
|
+
* @param {object} EOxItemFilterSelector - The EOxItemFilterSelector component instance.
|
|
199
|
+
* @param {boolean} [emitEvent=true] - Whether to dispatch the filter custom event.
|
|
194
200
|
*/
|
|
195
|
-
function updateFilterList(EOxItemFilterSelector) {
|
|
201
|
+
function updateFilterList(EOxItemFilterSelector, emitEvent = true) {
|
|
196
202
|
// Update the state of the filter object based on the selected items
|
|
197
203
|
Object.keys(EOxItemFilterSelector.filterObject.state).forEach((k) => {
|
|
198
204
|
EOxItemFilterSelector.filterObject.state[k] =
|
|
@@ -211,6 +217,8 @@ function updateFilterList(EOxItemFilterSelector) {
|
|
|
211
217
|
);
|
|
212
218
|
|
|
213
219
|
// Dispatch a custom event named "filter" and request an update
|
|
214
|
-
|
|
220
|
+
if (emitEvent) {
|
|
221
|
+
EOxItemFilterSelector.dispatchEvent(new CustomEvent("filter"));
|
|
222
|
+
}
|
|
215
223
|
EOxItemFilterSelector.requestUpdate();
|
|
216
224
|
}
|