@fluid-topics/ft-search-bar 0.2.18 → 0.2.21
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.css.js +0 -6
- package/build/ft-search-bar.d.ts +3 -2
- package/build/ft-search-bar.js +53 -29
- package/build/ft-search-bar.light.js +129 -132
- package/build/ft-search-bar.min.js +136 -139
- package/package.json +14 -14
|
@@ -390,12 +390,6 @@ export const suggestionsCss = css `
|
|
|
390
390
|
display: block;
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
.ft-search-bar--no-suggestions {
|
|
394
|
-
text-align: center;
|
|
395
|
-
padding: 8px;
|
|
396
|
-
color: ${FtSearchBarCssVariables.colorOnSurface};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
393
|
.ft-search-bar--suggestion {
|
|
400
394
|
text-decoration: none;
|
|
401
395
|
position: relative;
|
package/build/ft-search-bar.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ export interface FtSearchBarLabels extends ParametrizedLabels {
|
|
|
18
18
|
displayMoreFilterValuesButton?: string;
|
|
19
19
|
noFilterValuesAvailable?: string;
|
|
20
20
|
searchButton?: string;
|
|
21
|
-
noSuggestions?: string;
|
|
22
21
|
contentLocaleSelector?: string;
|
|
23
22
|
presetsSelector?: string;
|
|
24
23
|
removeRecentSearch?: string;
|
|
@@ -90,7 +89,6 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
|
|
|
90
89
|
private lastSuggestion?;
|
|
91
90
|
private updateFacetsDebouncer;
|
|
92
91
|
private suggestDebouncer;
|
|
93
|
-
private get recentSearchesStorageKey();
|
|
94
92
|
private api?;
|
|
95
93
|
get request(): FtSearchRequest;
|
|
96
94
|
get facetsRequest(): Array<FtSearchFacetConf>;
|
|
@@ -101,6 +99,7 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
|
|
|
101
99
|
private get hasPriors();
|
|
102
100
|
private get hasLocaleSelector();
|
|
103
101
|
focus(): void;
|
|
102
|
+
focusInput(): void;
|
|
104
103
|
clear(): void;
|
|
105
104
|
protected render(): import("lit-html").TemplateResult<1>;
|
|
106
105
|
protected renderSearchBar(): import("lit-html").TemplateResult<1>;
|
|
@@ -135,6 +134,8 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
|
|
|
135
134
|
private onSuggestKeyUp;
|
|
136
135
|
private onSuggestSelected;
|
|
137
136
|
private launchSearch;
|
|
137
|
+
private get recentSearchesStorageKey();
|
|
138
|
+
private initRecentSearches;
|
|
138
139
|
private saveRecentSearches;
|
|
139
140
|
private closeFloatingContainer;
|
|
140
141
|
connectedCallback(): void;
|
package/build/ft-search-bar.js
CHANGED
|
@@ -36,7 +36,6 @@ export const DEFAULT_LABELS = {
|
|
|
36
36
|
displayMoreFilterValuesButton: "More",
|
|
37
37
|
noFilterValuesAvailable: "No values available",
|
|
38
38
|
searchButton: "Search",
|
|
39
|
-
noSuggestions: "No results found…",
|
|
40
39
|
clearFilters: "Clear filters",
|
|
41
40
|
contentLocaleSelector: "Lang",
|
|
42
41
|
presetsSelector: "Preset",
|
|
@@ -107,9 +106,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
107
106
|
get isMobileMenuOpen() {
|
|
108
107
|
return this.isMobile && (this.forceMobileMenuOpen || this.forceMenuOpen || this.mobileMenuOpen);
|
|
109
108
|
}
|
|
110
|
-
get recentSearchesStorageKey() {
|
|
111
|
-
return this.baseUrl + ":ft:recent-search-queries";
|
|
112
|
-
}
|
|
113
109
|
get request() {
|
|
114
110
|
return {
|
|
115
111
|
uiLocale: this.uiLocale,
|
|
@@ -161,6 +157,14 @@ export class FtSearchBar extends FtLitElement {
|
|
|
161
157
|
var _a;
|
|
162
158
|
(_a = this.container) === null || _a === void 0 ? void 0 : _a.focus();
|
|
163
159
|
}
|
|
160
|
+
focusInput() {
|
|
161
|
+
if (this.input) {
|
|
162
|
+
this.input.focus();
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
setTimeout(() => this.focusInput(), 50);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
164
168
|
clear() {
|
|
165
169
|
this.query = "";
|
|
166
170
|
this.searchFilters = [];
|
|
@@ -191,7 +195,8 @@ export class FtSearchBar extends FtLitElement {
|
|
|
191
195
|
${this.isMobile ? this.renderMobileSearchBar() : this.renderDesktopSearchBar()}
|
|
192
196
|
</div>
|
|
193
197
|
` : html `
|
|
194
|
-
<ft-skeleton class="ft-search-bar--skeleton" part="loader"
|
|
198
|
+
<ft-skeleton class="ft-search-bar--container ft-search-bar--skeleton" part="loader"
|
|
199
|
+
tabindex="-1"></ft-skeleton>
|
|
195
200
|
`;
|
|
196
201
|
}
|
|
197
202
|
renderMobileSearchBar() {
|
|
@@ -273,6 +278,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
273
278
|
</ft-typography>
|
|
274
279
|
</div>
|
|
275
280
|
<ft-filter
|
|
281
|
+
id="ft:locale"
|
|
276
282
|
part="filters filter-ft-locale"
|
|
277
283
|
.exportpartsPrefixes=${["filter", "filter-ft-locale"]}
|
|
278
284
|
class="ft-search-bar--content-locale"
|
|
@@ -324,7 +330,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
324
330
|
return html `
|
|
325
331
|
<div class="ft-search-bar" part="search-bar">
|
|
326
332
|
${(this.renderSearchBarLeftAction())}
|
|
327
|
-
<div class="ft-search-bar--input-container" part="input-container">
|
|
333
|
+
<div class="ft-search-bar--input-container" part="input-container" tabindex="-1">
|
|
328
334
|
<div class="ft-search-bar--input-outline" part="input-outline">
|
|
329
335
|
${this.dense ? this.renderSelectedFacets() : nothing}
|
|
330
336
|
<input class="ft-search-bar--input ft-typography--body2"
|
|
@@ -465,13 +471,15 @@ export class FtSearchBar extends FtLitElement {
|
|
|
465
471
|
part="filters-container"
|
|
466
472
|
exportpartsPrefix="filters-container">
|
|
467
473
|
${this.hasLocaleSelector ? html `
|
|
468
|
-
<ft-filter
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
474
|
+
<ft-filter
|
|
475
|
+
id="ft:locale"
|
|
476
|
+
class="ft-search-bar--content-locale"
|
|
477
|
+
part="filters filter-ft-locale"
|
|
478
|
+
.exportpartsPrefixes=${["filter", "filter-ft-locale"]}
|
|
479
|
+
label="${this.labelResolver.resolve("contentLocaleSelector")}"
|
|
480
|
+
filterPlaceHolder="${this.labelResolver.resolve("filterInputPlaceHolder", this.labelResolver.resolve("contentLocaleSelector"))}"
|
|
481
|
+
.options=${(this.contentLocalesAsFilterOptions())}
|
|
482
|
+
@change=${(e) => this.contentLocale = e.detail[0]}
|
|
475
483
|
></ft-filter>
|
|
476
484
|
` : nothing}
|
|
477
485
|
${repeat(this.facets, facet => facet.key, facet => {
|
|
@@ -510,7 +518,9 @@ export class FtSearchBar extends FtLitElement {
|
|
|
510
518
|
<ft-chip part="selected-filters selected-filter-ft-locale"
|
|
511
519
|
?dense=${this.dense && !this.isMobile}
|
|
512
520
|
?clickable=${this.isMobile}
|
|
513
|
-
@click=${() => this.openMobileFilters("ft:contentLocale")}
|
|
521
|
+
@click=${() => this.openMobileFilters("ft:contentLocale")}
|
|
522
|
+
data-key="ft:locale"
|
|
523
|
+
data-value="${this.contentLocale}">
|
|
514
524
|
${(this.getLocaleLabel(this.contentLocale))}
|
|
515
525
|
</ft-chip>
|
|
516
526
|
` : null}
|
|
@@ -529,7 +539,9 @@ export class FtSearchBar extends FtLitElement {
|
|
|
529
539
|
label="${label}"
|
|
530
540
|
title=${useSnapScroll ? label : nothing}
|
|
531
541
|
@click=${() => this.openMobileFilters(facet.key)}
|
|
532
|
-
@icon-click=${() => this.setFilter(facet.key, values.filter(v => v !== value))}
|
|
542
|
+
@icon-click=${() => this.setFilter(facet.key, values.filter(v => v !== value))}
|
|
543
|
+
data-key="${facet.key}"
|
|
544
|
+
data-value="${value}">
|
|
533
545
|
${getLabelFromValue(value)}
|
|
534
546
|
</ft-chip>
|
|
535
547
|
`;
|
|
@@ -569,7 +581,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
569
581
|
}
|
|
570
582
|
renderSuggestions() {
|
|
571
583
|
const filteredRecentSearches = this.recentSearches.filter(q => q.toLowerCase().includes(this.query.toLowerCase()));
|
|
572
|
-
const shouldDisplaySuggestions = this.
|
|
584
|
+
const shouldDisplaySuggestions = this.suggestions.length > 0 || filteredRecentSearches.length > 0;
|
|
573
585
|
return html `
|
|
574
586
|
<div class="ft-search-bar--suggestions ${shouldDisplaySuggestions ? "ft-search-bar--suggestions-not-empty" : ""}"
|
|
575
587
|
part="suggestions-container"
|
|
@@ -603,13 +615,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
603
615
|
<ft-typography variant="body1">${suggest.value}</ft-typography>
|
|
604
616
|
</a>
|
|
605
617
|
`)}
|
|
606
|
-
${filteredRecentSearches.length === 0 && this.suggestions.length === 0 && this.query.length > 2 && this.suggestionsLoaded
|
|
607
|
-
? html `
|
|
608
|
-
<ft-typography class="ft-search-bar--no-suggestions" element="p"
|
|
609
|
-
variant="body2">
|
|
610
|
-
${this.labelResolver.resolve("noSuggestions")}
|
|
611
|
-
</ft-typography>
|
|
612
|
-
` : null}
|
|
613
618
|
</div>
|
|
614
619
|
`;
|
|
615
620
|
}
|
|
@@ -643,9 +648,14 @@ export class FtSearchBar extends FtLitElement {
|
|
|
643
648
|
async firstUpdated(props) {
|
|
644
649
|
super.firstUpdated(props);
|
|
645
650
|
this.initApi();
|
|
651
|
+
window.addEventListener("storage", (e) => {
|
|
652
|
+
if (e.key === this.recentSearchesStorageKey) {
|
|
653
|
+
this.initRecentSearches();
|
|
654
|
+
}
|
|
655
|
+
});
|
|
646
656
|
}
|
|
647
657
|
update(props) {
|
|
648
|
-
var _a, _b, _c, _d, _e
|
|
658
|
+
var _a, _b, _c, _d, _e;
|
|
649
659
|
if (props.has("labels")) {
|
|
650
660
|
this.labelResolver = new ParametrizedLabelResolver(DEFAULT_LABELS, this.labels);
|
|
651
661
|
}
|
|
@@ -664,13 +674,13 @@ export class FtSearchBar extends FtLitElement {
|
|
|
664
674
|
if (this.baseUrl.endsWith("/")) {
|
|
665
675
|
this.baseUrl = this.baseUrl.replace(/\/$/, "");
|
|
666
676
|
}
|
|
667
|
-
this.
|
|
677
|
+
this.initRecentSearches();
|
|
668
678
|
}
|
|
669
679
|
if (props.has("presets")) {
|
|
670
|
-
((
|
|
680
|
+
((_b = this.presets) !== null && _b !== void 0 ? _b : []).forEach(preset => preset.filters.forEach(filter => filter.values = filter.values.map(v => unquote(v))));
|
|
671
681
|
}
|
|
672
682
|
if (props.has("selectedPreset")) {
|
|
673
|
-
const currentPreset = ((
|
|
683
|
+
const currentPreset = ((_c = this.presets) !== null && _c !== void 0 ? _c : []).find(p => p.name === this.selectedPreset);
|
|
674
684
|
if (currentPreset && !this.compareRequests(this.request, currentPreset)) {
|
|
675
685
|
this.setFiltersFromPreset(currentPreset);
|
|
676
686
|
}
|
|
@@ -679,7 +689,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
679
689
|
this.knownFacetLabels = new Map();
|
|
680
690
|
}
|
|
681
691
|
if (["contentLocale", "searchFilters"].some(p => props.has(p))) {
|
|
682
|
-
this.selectedPreset = (
|
|
692
|
+
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;
|
|
683
693
|
}
|
|
684
694
|
if (["baseUrl", "apiIntegrationIdentifier"].some(p => props.has(p))) {
|
|
685
695
|
this.api = undefined;
|
|
@@ -832,8 +842,22 @@ export class FtSearchBar extends FtLitElement {
|
|
|
832
842
|
this.displayFacets = false;
|
|
833
843
|
this.focus();
|
|
834
844
|
}
|
|
845
|
+
get recentSearchesStorageKey() {
|
|
846
|
+
return this.baseUrl + ":ft:recent-search-queries";
|
|
847
|
+
}
|
|
848
|
+
initRecentSearches() {
|
|
849
|
+
var _a;
|
|
850
|
+
this.recentSearches = JSON.parse((_a = window.localStorage.getItem(this.recentSearchesStorageKey)) !== null && _a !== void 0 ? _a : "[]");
|
|
851
|
+
}
|
|
835
852
|
saveRecentSearches() {
|
|
836
|
-
|
|
853
|
+
const newValue = JSON.stringify(this.recentSearches);
|
|
854
|
+
window.localStorage.setItem(this.recentSearchesStorageKey, newValue);
|
|
855
|
+
window.dispatchEvent(new StorageEvent("storage", {
|
|
856
|
+
key: this.recentSearchesStorageKey,
|
|
857
|
+
newValue,
|
|
858
|
+
storageArea: window.localStorage,
|
|
859
|
+
url: window.location.href
|
|
860
|
+
}));
|
|
837
861
|
}
|
|
838
862
|
connectedCallback() {
|
|
839
863
|
super.connectedCallback();
|