@fluid-topics/ft-search-bar 1.1.107 → 1.1.111
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/build/ft-search-bar.d.ts +5 -1
- package/build/ft-search-bar.js +44 -22
- package/build/ft-search-bar.light.js +96 -96
- package/build/ft-search-bar.min.js +187 -187
- package/package.json +16 -16
package/build/ft-search-bar.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
|
|
|
41
41
|
priors?: Array<FtSearchPrior>;
|
|
42
42
|
searchRequestSerializer: (request: FtSearchRequest) => string;
|
|
43
43
|
focusOnDisplay: boolean;
|
|
44
|
-
private
|
|
44
|
+
private metadataFilters;
|
|
45
45
|
private sizeCategory;
|
|
46
46
|
displayFacets: boolean;
|
|
47
47
|
mobileMenuOpen: boolean;
|
|
@@ -106,6 +106,10 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
|
|
|
106
106
|
disconnectedCallback(): void;
|
|
107
107
|
private updateSize;
|
|
108
108
|
setFilter(key: string, selectedValues: Array<string>): void;
|
|
109
|
+
private compareUnknownFilters;
|
|
110
|
+
private compareValueFilters;
|
|
111
|
+
private compareDateFilters;
|
|
112
|
+
private compareRangeFilters;
|
|
109
113
|
private compareFilters;
|
|
110
114
|
private compareRequests;
|
|
111
115
|
private setFiltersFromPreset;
|
package/build/ft-search-bar.js
CHANGED
|
@@ -81,7 +81,7 @@ class FtSearchBar extends FtLitElement {
|
|
|
81
81
|
this.priors = [];
|
|
82
82
|
this.searchRequestSerializer = (request) => serializeRequest(this.baseUrl, request);
|
|
83
83
|
this.focusOnDisplay = false;
|
|
84
|
-
this.
|
|
84
|
+
this.metadataFilters = [];
|
|
85
85
|
this.sizeCategory = FtSizeCategory.M;
|
|
86
86
|
this.displayFacets = false;
|
|
87
87
|
this.mobileMenuOpen = false;
|
|
@@ -124,13 +124,29 @@ class FtSearchBar extends FtLitElement {
|
|
|
124
124
|
this.displayFacets = this.displayFacets && e.composedPath().some(element => element === this.floatingContainer);
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
this.
|
|
128
|
-
|
|
127
|
+
this.compareUnknownFilters = (a, b) => {
|
|
128
|
+
if (a.valueFilter && b.valueFilter) {
|
|
129
|
+
return this.compareValueFilters(a.valueFilter, b.valueFilter);
|
|
130
|
+
}
|
|
131
|
+
if (a.dateFilter && b.dateFilter) {
|
|
132
|
+
return this.compareDateFilters(a.dateFilter, b.dateFilter);
|
|
133
|
+
}
|
|
134
|
+
if (a.rangeFilter && b.rangeFilter) {
|
|
135
|
+
return this.compareRangeFilters(a.rangeFilter, b.rangeFilter);
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
139
|
+
this.compareValueFilters = (a, b) => a.negative == b.negative
|
|
129
140
|
&& a.values.length === b.values.length
|
|
130
141
|
&& a.values.every(value => b.values.includes(value));
|
|
142
|
+
this.compareDateFilters = (a, b) => a.type === b.type;
|
|
143
|
+
this.compareRangeFilters = (a, b) => a.from === b.from
|
|
144
|
+
&& a.to === b.to;
|
|
145
|
+
this.compareFilters = (a, b) => a.key === b.key
|
|
146
|
+
&& this.compareUnknownFilters(a, b);
|
|
131
147
|
this.compareRequests = (a, b) => (a.contentLocale == null || b.contentLocale == null || a.contentLocale === b.contentLocale)
|
|
132
|
-
&& a.
|
|
133
|
-
&& a.
|
|
148
|
+
&& a.metadataFilters.length === b.metadataFilters.length
|
|
149
|
+
&& a.metadataFilters.every(fa => b.metadataFilters.some(fb => this.compareFilters(fa, fb)));
|
|
134
150
|
this.enableFocusReactionCallback = () => this.enableFocusReaction();
|
|
135
151
|
}
|
|
136
152
|
isMobileMenuOpen() {
|
|
@@ -143,13 +159,13 @@ class FtSearchBar extends FtLitElement {
|
|
|
143
159
|
query: this.query,
|
|
144
160
|
facets: this.facetsRequest,
|
|
145
161
|
priors: this.hasPriors ? this.priors : undefined,
|
|
146
|
-
|
|
162
|
+
metadataFilters: this.metadataFilters,
|
|
147
163
|
paging: { perPage: 0, page: 1 },
|
|
148
164
|
sort: [],
|
|
149
165
|
};
|
|
150
166
|
}
|
|
151
167
|
get facetsRequest() {
|
|
152
|
-
const fromFilters = this.
|
|
168
|
+
const fromFilters = this.metadataFilters.filter(f => { var _a, _b; return ((_b = (_a = f.valueFilter) === null || _a === void 0 ? void 0 : _a.values.length) !== null && _b !== void 0 ? _b : 0) > 0 && !this.displayedFilters.includes(f.key); })
|
|
153
169
|
.map(f => ({ id: f.key }));
|
|
154
170
|
return [...this.displayedFilters.map(id => ({ id })), ...fromFilters];
|
|
155
171
|
}
|
|
@@ -157,7 +173,7 @@ class FtSearchBar extends FtLitElement {
|
|
|
157
173
|
return {
|
|
158
174
|
contentLocale: this.contentLocale,
|
|
159
175
|
input: this.query,
|
|
160
|
-
|
|
176
|
+
metadataFilters: this.metadataFilters,
|
|
161
177
|
sort: []
|
|
162
178
|
};
|
|
163
179
|
}
|
|
@@ -197,7 +213,7 @@ class FtSearchBar extends FtLitElement {
|
|
|
197
213
|
}
|
|
198
214
|
clear() {
|
|
199
215
|
this.query = "";
|
|
200
|
-
this.
|
|
216
|
+
this.metadataFilters = [];
|
|
201
217
|
if (this.input) {
|
|
202
218
|
this.input.value = "";
|
|
203
219
|
}
|
|
@@ -336,7 +352,7 @@ class FtSearchBar extends FtLitElement {
|
|
|
336
352
|
`;
|
|
337
353
|
}
|
|
338
354
|
renderDesktopClearFilters() {
|
|
339
|
-
return this.
|
|
355
|
+
return this.metadataFilters.length > 0 ? html `
|
|
340
356
|
<ft-button part="facets-actions"
|
|
341
357
|
@click=${this.clearFilters}>
|
|
342
358
|
${this.labelResolver.resolve("clearFilters")}
|
|
@@ -423,7 +439,11 @@ class FtSearchBar extends FtLitElement {
|
|
|
423
439
|
this.initRecentSearches();
|
|
424
440
|
}
|
|
425
441
|
if (props.has("presets")) {
|
|
426
|
-
((_b = this.presets) !== null && _b !== void 0 ? _b : []).forEach(preset => preset.
|
|
442
|
+
((_b = this.presets) !== null && _b !== void 0 ? _b : []).forEach(preset => preset.metadataFilters.forEach(filter => {
|
|
443
|
+
if (filter.valueFilter) {
|
|
444
|
+
filter.valueFilter.values = filter.valueFilter.values.map(v => unquote(v));
|
|
445
|
+
}
|
|
446
|
+
}));
|
|
427
447
|
}
|
|
428
448
|
if (props.has("presets") || props.has("selectedPreset")) {
|
|
429
449
|
const currentPreset = ((_c = this.presets) !== null && _c !== void 0 ? _c : []).find(p => p.name === this.selectedPreset);
|
|
@@ -434,7 +454,7 @@ class FtSearchBar extends FtLitElement {
|
|
|
434
454
|
if (props.has("contentLocale") && this.contentLocale != null) {
|
|
435
455
|
this.knownFacetLabels = new Map();
|
|
436
456
|
}
|
|
437
|
-
if (["contentLocale", "
|
|
457
|
+
if (["contentLocale", "metadataFilters"].some(p => props.has(p))) {
|
|
438
458
|
this.selectedPreset = (_e = ((_d = this.presets) !== null && _d !== void 0 ? _d : []).find(p => this.compareRequests(p, this.request))) === null || _e === void 0 ? void 0 : _e.name;
|
|
439
459
|
}
|
|
440
460
|
if (["baseUrl", "apiIntegrationIdentifier"].some(p => props.has(p))) {
|
|
@@ -444,13 +464,13 @@ class FtSearchBar extends FtLitElement {
|
|
|
444
464
|
if (props.has("api") && this.api) {
|
|
445
465
|
this.initSearchData();
|
|
446
466
|
}
|
|
447
|
-
if (["uiLocale", "contentLocale", "
|
|
467
|
+
if (["uiLocale", "contentLocale", "metadataFilters", "displayedFilters"].some(p => props.has(p))) {
|
|
448
468
|
this.updateFacets();
|
|
449
469
|
}
|
|
450
|
-
if (["query", "uiLocale", "contentLocale", "
|
|
470
|
+
if (["query", "uiLocale", "contentLocale", "metadataFilters", "displayedFilters", "api"].some(p => props.has(p))) {
|
|
451
471
|
this.suggestManager.update();
|
|
452
472
|
}
|
|
453
|
-
if (["query", "uiLocale", "contentLocale", "
|
|
473
|
+
if (["query", "uiLocale", "contentLocale", "metadataFilters"].some(p => props.has(p))) {
|
|
454
474
|
this.dispatchStateChangeEvent();
|
|
455
475
|
}
|
|
456
476
|
}
|
|
@@ -581,7 +601,7 @@ class FtSearchBar extends FtLitElement {
|
|
|
581
601
|
this.sizeCategory = e.detail.category;
|
|
582
602
|
}
|
|
583
603
|
setFilter(key, selectedValues) {
|
|
584
|
-
let newFilters = this.
|
|
604
|
+
let newFilters = this.metadataFilters.filter(f => !f.valueFilter || f.key !== key);
|
|
585
605
|
this.facets.forEach(facet => {
|
|
586
606
|
if (facet.key === key) {
|
|
587
607
|
flatDeep(facet.rootNodes, n => n.childNodes).forEach(n => n.selected = selectedValues.includes(n.value));
|
|
@@ -590,11 +610,13 @@ class FtSearchBar extends FtLitElement {
|
|
|
590
610
|
if (selectedValues.length) {
|
|
591
611
|
newFilters.push({
|
|
592
612
|
key: key,
|
|
593
|
-
|
|
594
|
-
|
|
613
|
+
valueFilter: {
|
|
614
|
+
negative: false,
|
|
615
|
+
values: selectedValues
|
|
616
|
+
}
|
|
595
617
|
});
|
|
596
618
|
}
|
|
597
|
-
this.
|
|
619
|
+
this.metadataFilters = newFilters;
|
|
598
620
|
this.scrollToFacet = key;
|
|
599
621
|
}
|
|
600
622
|
setFiltersFromPreset(request) {
|
|
@@ -602,12 +624,12 @@ class FtSearchBar extends FtLitElement {
|
|
|
602
624
|
if (request.contentLocale != null) {
|
|
603
625
|
this.contentLocale = request.contentLocale;
|
|
604
626
|
}
|
|
605
|
-
this.
|
|
627
|
+
this.metadataFilters = request.metadataFilters;
|
|
606
628
|
}
|
|
607
629
|
}
|
|
608
630
|
clearFilters() {
|
|
609
631
|
this.facets.forEach(facet => flatDeep(facet.rootNodes, n => n.childNodes).forEach(n => n.selected = false));
|
|
610
|
-
this.
|
|
632
|
+
this.metadataFilters = [];
|
|
611
633
|
const firstFacet = this.facets[0];
|
|
612
634
|
this.scrollToFacet = firstFacet === null || firstFacet === void 0 ? void 0 : firstFacet.key;
|
|
613
635
|
}
|
|
@@ -719,7 +741,7 @@ __decorate([
|
|
|
719
741
|
], FtSearchBar.prototype, "focusOnDisplay", void 0);
|
|
720
742
|
__decorate([
|
|
721
743
|
state()
|
|
722
|
-
], FtSearchBar.prototype, "
|
|
744
|
+
], FtSearchBar.prototype, "metadataFilters", void 0);
|
|
723
745
|
__decorate([
|
|
724
746
|
state()
|
|
725
747
|
], FtSearchBar.prototype, "sizeCategory", void 0);
|