@fluid-topics/ft-search-bar 0.2.21 → 0.3.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/build/ft-search-bar.css.d.ts +17 -20
- package/build/ft-search-bar.css.js +18 -126
- package/build/ft-search-bar.d.ts +36 -49
- package/build/ft-search-bar.js +46 -410
- package/build/ft-search-bar.light.js +396 -393
- package/build/ft-search-bar.min.js +509 -500
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/managers/DesktopSearchBarManager.d.ts +16 -0
- package/build/managers/DesktopSearchBarManager.js +131 -0
- package/build/managers/FacetsChipsManager.d.ts +10 -0
- package/build/managers/FacetsChipsManager.js +129 -0
- package/build/managers/MobileSearchBarManager.d.ts +14 -0
- package/build/managers/MobileSearchBarManager.js +92 -0
- package/build/managers/SuggestManager.d.ts +20 -0
- package/build/managers/SuggestManager.js +215 -0
- package/package.json +17 -17
package/build/ft-search-bar.js
CHANGED
|
@@ -7,13 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { html, nothing } from "lit";
|
|
8
8
|
import { property, query, state } from "lit/decorators.js";
|
|
9
9
|
import { repeat } from "lit/directives/repeat.js";
|
|
10
|
-
import { classMap } from "lit/directives/class-map.js";
|
|
11
10
|
import { Debouncer, FtLitElement, jsonProperty, ParametrizedLabelResolver } from "@fluid-topics/ft-wc-utils";
|
|
12
11
|
import { FtSizeCategory, FtSizeWatcher } from "@fluid-topics/ft-size-watcher";
|
|
13
12
|
import { FtTypography, FtTypographyBody2 } from "@fluid-topics/ft-typography";
|
|
14
|
-
import { facetToFilter,
|
|
13
|
+
import { facetToFilter, selectedValues, serializeRequest, unquote } from "./converters";
|
|
15
14
|
import { FtFilter, FtFilterOption } from "@fluid-topics/ft-filter";
|
|
16
|
-
import { FtIcon,
|
|
15
|
+
import { FtIcon, } from "@fluid-topics/ft-icon";
|
|
17
16
|
import { FtAccordion, FtAccordionItem } from "@fluid-topics/ft-accordion";
|
|
18
17
|
import { FtButton } from "@fluid-topics/ft-button";
|
|
19
18
|
import { FtChip } from "@fluid-topics/ft-chip";
|
|
@@ -22,8 +21,12 @@ import { FtSnapScroll } from "@fluid-topics/ft-snap-scroll";
|
|
|
22
21
|
import { FtTooltip } from "@fluid-topics/ft-tooltip";
|
|
23
22
|
import { FtRipple } from "@fluid-topics/ft-ripple";
|
|
24
23
|
import { flatDeep } from "@fluid-topics/ft-filter/build/utils";
|
|
25
|
-
import { facetsCss, searchBarCss
|
|
24
|
+
import { facetsCss, searchBarCss } from "./ft-search-bar.css";
|
|
26
25
|
import { FtSkeleton } from "@fluid-topics/ft-skeleton";
|
|
26
|
+
import { SuggestManager } from "./managers/SuggestManager";
|
|
27
|
+
import { FacetsChipsManager } from "./managers/FacetsChipsManager";
|
|
28
|
+
import { MobileSearchBarManager } from "./managers/MobileSearchBarManager";
|
|
29
|
+
import { DesktopSearchBarManager } from "./managers/DesktopSearchBarManager";
|
|
27
30
|
if (window.fluidtopics == null) {
|
|
28
31
|
console.warn("Fluid Topics public API was not found. You can find it here: https://www.npmjs.com/package/@fluid-topics/public-api");
|
|
29
32
|
}
|
|
@@ -42,7 +45,6 @@ export const DEFAULT_LABELS = {
|
|
|
42
45
|
removeRecentSearch: "Remove",
|
|
43
46
|
back: "Back",
|
|
44
47
|
};
|
|
45
|
-
export { FtSearchBarCssVariables } from "./ft-search-bar.css";
|
|
46
48
|
export class LaunchSearchEvent extends CustomEvent {
|
|
47
49
|
constructor(request) {
|
|
48
50
|
super("launch-search", {
|
|
@@ -85,13 +87,15 @@ export class FtSearchBar extends FtLitElement {
|
|
|
85
87
|
this.knownFacetLabels = new Map();
|
|
86
88
|
this.query = "";
|
|
87
89
|
this.suggestions = [];
|
|
88
|
-
this.suggestionsLoaded = true;
|
|
89
90
|
this.recentSearches = [];
|
|
90
91
|
this.updateFacetsDebouncer = new Debouncer(500);
|
|
91
|
-
this.
|
|
92
|
+
this.suggestManager = new SuggestManager(this);
|
|
93
|
+
this.selectedFacetsManager = new FacetsChipsManager(this);
|
|
94
|
+
this.desktopSearchBarManager = new DesktopSearchBarManager(this);
|
|
95
|
+
this.mobileSearchBarManager = new MobileSearchBarManager(this);
|
|
92
96
|
this.facetsLoaded = false;
|
|
93
97
|
this.closeFloatingContainer = (e) => {
|
|
94
|
-
if (!this.isMobile) {
|
|
98
|
+
if (!this.isMobile()) {
|
|
95
99
|
this.displayFacets = this.displayFacets && e.composedPath().some(element => element === this.floatingContainer);
|
|
96
100
|
}
|
|
97
101
|
};
|
|
@@ -103,8 +107,8 @@ export class FtSearchBar extends FtLitElement {
|
|
|
103
107
|
&& a.filters.length === b.filters.length
|
|
104
108
|
&& a.filters.every(fa => b.filters.some(fb => this.compareFilters(fa, fb)));
|
|
105
109
|
}
|
|
106
|
-
|
|
107
|
-
return this.isMobile && (this.forceMobileMenuOpen || this.forceMenuOpen || this.mobileMenuOpen);
|
|
110
|
+
isMobileMenuOpen() {
|
|
111
|
+
return this.isMobile() && (this.forceMobileMenuOpen || this.forceMenuOpen || this.mobileMenuOpen);
|
|
108
112
|
}
|
|
109
113
|
get request() {
|
|
110
114
|
return {
|
|
@@ -131,7 +135,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
131
135
|
sort: []
|
|
132
136
|
};
|
|
133
137
|
}
|
|
134
|
-
|
|
138
|
+
isMobile() {
|
|
135
139
|
switch (this.mode) {
|
|
136
140
|
case "mobile":
|
|
137
141
|
return true;
|
|
@@ -141,7 +145,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
141
145
|
return this.sizeCategory === FtSizeCategory.S;
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
|
-
|
|
148
|
+
hasFacets() {
|
|
145
149
|
return this.facetsRequest.length > 0;
|
|
146
150
|
}
|
|
147
151
|
get hasPresets() {
|
|
@@ -150,7 +154,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
150
154
|
get hasPriors() {
|
|
151
155
|
return this.priors != null && this.priors.length > 0;
|
|
152
156
|
}
|
|
153
|
-
|
|
157
|
+
hasLocaleSelector() {
|
|
154
158
|
return this.availableContentLocales.length > 1;
|
|
155
159
|
}
|
|
156
160
|
focus() {
|
|
@@ -181,95 +185,20 @@ export class FtSearchBar extends FtLitElement {
|
|
|
181
185
|
`;
|
|
182
186
|
}
|
|
183
187
|
renderSearchBar() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
"ft-search-bar--mobile-menu-open": this.isMobileMenuOpen,
|
|
191
|
-
"ft-search-bar--forced-open": this.forceMenuOpen || this.forceMobileMenuOpen,
|
|
192
|
-
};
|
|
193
|
-
return this.facetsInitialized && this.availableContentLocalesInitialized ? html `
|
|
194
|
-
<div class="${classMap(rootClasses)}" part="container" tabindex="-1">
|
|
195
|
-
${this.isMobile ? this.renderMobileSearchBar() : this.renderDesktopSearchBar()}
|
|
196
|
-
</div>
|
|
197
|
-
` : html `
|
|
198
|
-
<ft-skeleton class="ft-search-bar--container ft-search-bar--skeleton" part="loader"
|
|
199
|
-
tabindex="-1"></ft-skeleton>
|
|
200
|
-
`;
|
|
201
|
-
}
|
|
202
|
-
renderMobileSearchBar() {
|
|
203
|
-
return html `
|
|
204
|
-
<div class="ft-search-bar">
|
|
205
|
-
<div class="ft-search-bar--input-container" part="input-container">
|
|
206
|
-
<div class="ft-search-bar--input-outline" part="input-outline">
|
|
207
|
-
<input class="ft-search-bar--input ft-typography--body2"
|
|
208
|
-
part="input"
|
|
209
|
-
type="text"
|
|
210
|
-
placeholder="${this.labelResolver.resolve("inputPlaceHolder")}"
|
|
211
|
-
value="${this.query}"
|
|
212
|
-
@keyup=${this.onSearchBarKeyUp}
|
|
213
|
-
@focus=${() => {
|
|
214
|
-
this.mobileMenuOpen = true;
|
|
215
|
-
this.displayFacets = false;
|
|
216
|
-
}}>
|
|
217
|
-
</div>
|
|
218
|
-
</div>
|
|
219
|
-
${this.renderMobileSearchBarButtons()}
|
|
220
|
-
</div>
|
|
221
|
-
${this.displayFacets ? this.renderFacetsActions() : this.renderSelectedFacets()}
|
|
222
|
-
${this.displayFacets ? this.renderMobileFacets() : this.renderSuggestions()}
|
|
223
|
-
${this.isMobileMenuOpen || this.displayFacets ? html `
|
|
224
|
-
<ft-button class="ft-search-bar--launch-search"
|
|
225
|
-
part="launch-search-in-panel"
|
|
226
|
-
icon="search"
|
|
227
|
-
@click=${this.launchSearch}>
|
|
228
|
-
${this.labelResolver.resolve("searchButton")}
|
|
229
|
-
</ft-button>
|
|
230
|
-
` : nothing}
|
|
231
|
-
`;
|
|
232
|
-
}
|
|
233
|
-
renderMobileSearchBarButtons() {
|
|
234
|
-
const displayClearButton = this.query || (this.isMobileMenuOpen && !this.forceMobileMenuOpen);
|
|
235
|
-
return html `
|
|
236
|
-
${displayClearButton ? html `
|
|
237
|
-
<div class="ft-search-bar--actions"
|
|
238
|
-
part="search-bar-actions">
|
|
239
|
-
<ft-button class="ft-search-bar--clear-query"
|
|
240
|
-
part="clear-query"
|
|
241
|
-
icon="close"
|
|
242
|
-
round
|
|
243
|
-
label="${this.labelResolver.resolve("clearInputButton")}"
|
|
244
|
-
tooltipPosition="left"
|
|
245
|
-
@click=${() => {
|
|
246
|
-
this.setQuery("");
|
|
247
|
-
this.mobileMenuOpen = false;
|
|
248
|
-
this.displayFacets = false;
|
|
249
|
-
}}
|
|
250
|
-
></ft-button>
|
|
251
|
-
</div>
|
|
252
|
-
` : nothing}
|
|
253
|
-
<div class="ft-search-bar--actions"
|
|
254
|
-
part="search-bar-actions">
|
|
255
|
-
<ft-button class="ft-search-bar--launch-search"
|
|
256
|
-
part="launch-search-in-bar"
|
|
257
|
-
icon="search"
|
|
258
|
-
round
|
|
259
|
-
label="${this.labelResolver.resolve("searchButton")}"
|
|
260
|
-
tooltipPosition="left"
|
|
261
|
-
@click=${() => { var _a; return this.isMobileMenuOpen ? this.launchSearch() : (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus(); }}
|
|
262
|
-
></ft-button>
|
|
263
|
-
</div>
|
|
264
|
-
`;
|
|
188
|
+
return this.facetsInitialized && this.availableContentLocalesInitialized
|
|
189
|
+
? this.isMobile() ? this.mobileSearchBarManager.render() : this.desktopSearchBarManager.render()
|
|
190
|
+
: html `
|
|
191
|
+
<ft-skeleton class="ft-search-bar--container ft-search-bar--skeleton" part="loader"
|
|
192
|
+
tabindex="-1"></ft-skeleton>
|
|
193
|
+
`;
|
|
265
194
|
}
|
|
266
195
|
renderMobileFacets() {
|
|
267
196
|
var _a;
|
|
268
197
|
const currentLocale = this.availableContentLocales.filter(l => l.lang === this.contentLocale).pop();
|
|
269
198
|
return html `
|
|
270
199
|
<ft-accordion class="ft-search-bar--filters-container">
|
|
271
|
-
${this.hasLocaleSelector ? html `
|
|
272
|
-
<ft-accordion-item data-facet-key="ft:
|
|
200
|
+
${this.hasLocaleSelector() ? html `
|
|
201
|
+
<ft-accordion-item data-facet-key="ft:locale">
|
|
273
202
|
<div class="ft-search-bar--filter-label" slot="toggle">
|
|
274
203
|
<ft-typography variant="button">${this.labelResolver.resolve("contentLocaleSelector")}
|
|
275
204
|
</ft-typography>
|
|
@@ -326,36 +255,8 @@ export class FtSearchBar extends FtLitElement {
|
|
|
326
255
|
selected: l.lang == this.contentLocale
|
|
327
256
|
}));
|
|
328
257
|
}
|
|
329
|
-
renderDesktopSearchBar() {
|
|
330
|
-
return html `
|
|
331
|
-
<div class="ft-search-bar" part="search-bar">
|
|
332
|
-
${(this.renderSearchBarLeftAction())}
|
|
333
|
-
<div class="ft-search-bar--input-container" part="input-container" tabindex="-1">
|
|
334
|
-
<div class="ft-search-bar--input-outline" part="input-outline">
|
|
335
|
-
${this.dense ? this.renderSelectedFacets() : nothing}
|
|
336
|
-
<input class="ft-search-bar--input ft-typography--body2"
|
|
337
|
-
part="input"
|
|
338
|
-
type="text"
|
|
339
|
-
placeholder="${this.labelResolver.resolve("inputPlaceHolder")}"
|
|
340
|
-
value="${this.query}"
|
|
341
|
-
@keydown=${this.onSearchBarKeyDown}
|
|
342
|
-
@keyup=${this.onSearchBarKeyUp}>
|
|
343
|
-
</div>
|
|
344
|
-
${this.renderSuggestions()}
|
|
345
|
-
</div>
|
|
346
|
-
${this.renderDesktopSearchBarButtons()}
|
|
347
|
-
${this.forceMenuOpen ? nothing : html `
|
|
348
|
-
<div class="ft-search-bar--floating-panel" @keyup=${this.onFloatingContainerKeyUp}
|
|
349
|
-
part="floating-panel"
|
|
350
|
-
tabindex="-1">
|
|
351
|
-
${this.renderDesktopMenu()}
|
|
352
|
-
</div>`}
|
|
353
|
-
</div>
|
|
354
|
-
${this.dense || this.forceMenuOpen ? (this.forceMenuOpen ? this.renderDesktopMenu() : nothing) : this.renderSelectedFacets()}
|
|
355
|
-
`;
|
|
356
|
-
}
|
|
357
258
|
renderDesktopMenu() {
|
|
358
|
-
return this.hasFacets ? html `
|
|
259
|
+
return this.hasFacets() ? html `
|
|
359
260
|
<div class="ft-search-bar--desktop-menu">
|
|
360
261
|
${this.renderFacetsActions()}
|
|
361
262
|
${this.renderDesktopFacets()}
|
|
@@ -371,64 +272,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
371
272
|
</div>
|
|
372
273
|
` : nothing;
|
|
373
274
|
}
|
|
374
|
-
renderSearchBarLeftAction() {
|
|
375
|
-
if (this.hasFacets) {
|
|
376
|
-
return this.forceMenuOpen ? nothing : html `
|
|
377
|
-
<ft-button class="ft-search-bar--filters-opener ft-search-bar--left-action"
|
|
378
|
-
part="filters-opener"
|
|
379
|
-
trailingIcon
|
|
380
|
-
icon="${this.displayFacets ? "expand_less" : "expand_more"}"
|
|
381
|
-
@click=${(e) => {
|
|
382
|
-
e.stopPropagation();
|
|
383
|
-
this.displayFacets = !this.displayFacets;
|
|
384
|
-
}}
|
|
385
|
-
@focusin=${(e) => e.stopPropagation()}>
|
|
386
|
-
${this.labelResolver.resolve("filtersButton")}
|
|
387
|
-
</ft-button>
|
|
388
|
-
`;
|
|
389
|
-
}
|
|
390
|
-
else if (this.hasLocaleSelector) {
|
|
391
|
-
return html `
|
|
392
|
-
<ft-select outlined
|
|
393
|
-
class="ft-search-bar--content-locale ft-search-bar--left-action"
|
|
394
|
-
part="content-locale select-ft-locale"
|
|
395
|
-
.exportpartsPrefixes=${["content-locale", "select-ft-locale"]}
|
|
396
|
-
@change=${(e) => this.contentLocale = e.detail == null ? undefined : e.detail}>
|
|
397
|
-
${repeat(this.availableContentLocales, l => l.lang, l => html `
|
|
398
|
-
<ft-select-option .value=${l.lang}
|
|
399
|
-
label="${l.label}"
|
|
400
|
-
?selected=${l.lang === this.contentLocale}>
|
|
401
|
-
</ft-select-option>
|
|
402
|
-
`)}
|
|
403
|
-
</ft-select>
|
|
404
|
-
`;
|
|
405
|
-
}
|
|
406
|
-
return nothing;
|
|
407
|
-
}
|
|
408
|
-
renderDesktopSearchBarButtons() {
|
|
409
|
-
return html `
|
|
410
|
-
<div class="ft-search-bar--actions"
|
|
411
|
-
part="search-bar-actions">
|
|
412
|
-
${this.query ? html `
|
|
413
|
-
<ft-button class="ft-search-bar--clear-query"
|
|
414
|
-
part="clear-query"
|
|
415
|
-
icon="close"
|
|
416
|
-
round dense
|
|
417
|
-
label="${this.labelResolver.resolve("clearInputButton")}"
|
|
418
|
-
@click=${() => this.setQuery("")}
|
|
419
|
-
></ft-button>
|
|
420
|
-
<div class="ft-search-bar--separator"></div>
|
|
421
|
-
` : null}
|
|
422
|
-
<ft-button class="ft-search-bar--launch-search"
|
|
423
|
-
part="launch-search-in-bar"
|
|
424
|
-
icon="search"
|
|
425
|
-
round dense
|
|
426
|
-
label="${this.labelResolver.resolve("searchButton")}"
|
|
427
|
-
@click=${this.launchSearch}
|
|
428
|
-
></ft-button>
|
|
429
|
-
</div>
|
|
430
|
-
`;
|
|
431
|
-
}
|
|
432
275
|
renderFacetsActions() {
|
|
433
276
|
var _a;
|
|
434
277
|
return html `
|
|
@@ -449,7 +292,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
449
292
|
</ft-select>
|
|
450
293
|
` : nothing}
|
|
451
294
|
<slot name="facets-actions"></slot>
|
|
452
|
-
${this.forceMenuOpen && !this.isMobile ? nothing : this.renderDesktopClearFilters()}
|
|
295
|
+
${this.forceMenuOpen && !this.isMobile() ? nothing : this.renderDesktopClearFilters()}
|
|
453
296
|
</div>
|
|
454
297
|
`;
|
|
455
298
|
}
|
|
@@ -462,7 +305,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
462
305
|
` : nothing;
|
|
463
306
|
}
|
|
464
307
|
renderDesktopFacets() {
|
|
465
|
-
if (!this.hasFacets) {
|
|
308
|
+
if (!this.hasFacets()) {
|
|
466
309
|
return nothing;
|
|
467
310
|
}
|
|
468
311
|
return html `
|
|
@@ -470,7 +313,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
470
313
|
class="ft-search-bar--filters-container"
|
|
471
314
|
part="filters-container"
|
|
472
315
|
exportpartsPrefix="filters-container">
|
|
473
|
-
${this.hasLocaleSelector ? html `
|
|
316
|
+
${this.hasLocaleSelector() ? html `
|
|
474
317
|
<ft-filter
|
|
475
318
|
id="ft:locale"
|
|
476
319
|
class="ft-search-bar--content-locale"
|
|
@@ -508,143 +351,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
508
351
|
</ft-snap-scroll>
|
|
509
352
|
`;
|
|
510
353
|
}
|
|
511
|
-
renderSelectedFacets() {
|
|
512
|
-
if (!this.hasLocaleSelector && !this.hasFacets) {
|
|
513
|
-
return null;
|
|
514
|
-
}
|
|
515
|
-
const useSnapScroll = (!this.isMobile && this.dense) || (this.isMobile && this.isMobileMenuOpen);
|
|
516
|
-
const filters = html `
|
|
517
|
-
${this.hasLocaleSelector && (this.hasFacets || this.isMobile) ? html `
|
|
518
|
-
<ft-chip part="selected-filters selected-filter-ft-locale"
|
|
519
|
-
?dense=${this.dense && !this.isMobile}
|
|
520
|
-
?clickable=${this.isMobile}
|
|
521
|
-
@click=${() => this.openMobileFilters("ft:contentLocale")}
|
|
522
|
-
data-key="ft:locale"
|
|
523
|
-
data-value="${this.contentLocale}">
|
|
524
|
-
${(this.getLocaleLabel(this.contentLocale))}
|
|
525
|
-
</ft-chip>
|
|
526
|
-
` : null}
|
|
527
|
-
${repeat(this.facets, facet => facet.key, facet => {
|
|
528
|
-
const values = getSelectedValues(facet);
|
|
529
|
-
return repeat(values, value => {
|
|
530
|
-
let label = facet.label + ": " + getBreadcrumbFromValue(value);
|
|
531
|
-
const keyWithNoColumn = facet.key.replace(":", "-");
|
|
532
|
-
const chip = html `
|
|
533
|
-
<ft-chip
|
|
534
|
-
part="selected-filters selected-filter-${keyWithNoColumn}"
|
|
535
|
-
?dense=${this.dense && !this.isMobile}
|
|
536
|
-
?clickable=${this.isMobile}
|
|
537
|
-
?removable=${!this.isMobile}
|
|
538
|
-
icon=${this.isMobile ? nothing : "close"}
|
|
539
|
-
label="${label}"
|
|
540
|
-
title=${useSnapScroll ? label : nothing}
|
|
541
|
-
@click=${() => this.openMobileFilters(facet.key)}
|
|
542
|
-
@icon-click=${() => this.setFilter(facet.key, values.filter(v => v !== value))}
|
|
543
|
-
data-key="${facet.key}"
|
|
544
|
-
data-value="${value}">
|
|
545
|
-
${getLabelFromValue(value)}
|
|
546
|
-
</ft-chip>
|
|
547
|
-
`;
|
|
548
|
-
return useSnapScroll ? chip : html `
|
|
549
|
-
<ft-tooltip inline text="${label}">
|
|
550
|
-
${chip}
|
|
551
|
-
</ft-tooltip>
|
|
552
|
-
`;
|
|
553
|
-
});
|
|
554
|
-
})}
|
|
555
|
-
${this.isMobile ? html `
|
|
556
|
-
<ft-chip part="selected-filters mobile-filters-opener"
|
|
557
|
-
icon="add"
|
|
558
|
-
clickable
|
|
559
|
-
@click=${() => {
|
|
560
|
-
this.mobileMenuOpen = true;
|
|
561
|
-
this.displayFacets = true;
|
|
562
|
-
}}>
|
|
563
|
-
${this.labelResolver.resolve("filtersButton")}
|
|
564
|
-
</ft-chip>
|
|
565
|
-
` : nothing}
|
|
566
|
-
`;
|
|
567
|
-
return useSnapScroll
|
|
568
|
-
? html `
|
|
569
|
-
<ft-snap-scroll horizontal controls hideScrollbar limitSize
|
|
570
|
-
class="ft-search-bar--selected-filters"
|
|
571
|
-
part="selected-filters-container"
|
|
572
|
-
exportpartsPrefix="selected-filters-container">
|
|
573
|
-
${filters}
|
|
574
|
-
</ft-snap-scroll>
|
|
575
|
-
`
|
|
576
|
-
: html `
|
|
577
|
-
<div class="ft-search-bar--selected-filters" part="selected-filters-container">
|
|
578
|
-
${filters}
|
|
579
|
-
</div>
|
|
580
|
-
`;
|
|
581
|
-
}
|
|
582
|
-
renderSuggestions() {
|
|
583
|
-
const filteredRecentSearches = this.recentSearches.filter(q => q.toLowerCase().includes(this.query.toLowerCase()));
|
|
584
|
-
const shouldDisplaySuggestions = this.suggestions.length > 0 || filteredRecentSearches.length > 0;
|
|
585
|
-
return html `
|
|
586
|
-
<div class="ft-search-bar--suggestions ${shouldDisplaySuggestions ? "ft-search-bar--suggestions-not-empty" : ""}"
|
|
587
|
-
part="suggestions-container"
|
|
588
|
-
@keydown=${this.onSuggestKeyDown}>
|
|
589
|
-
${repeat(filteredRecentSearches.slice(0, 5), query => query, query => html `
|
|
590
|
-
<a href="${this.searchRequestSerializer({ ...this.request, query: query })}"
|
|
591
|
-
part="suggestions"
|
|
592
|
-
class="ft-search-bar--suggestion ft-search-bar--recent-search"
|
|
593
|
-
@keyup=${(e) => this.onSuggestKeyUp(e, query)}
|
|
594
|
-
@click=${(e) => this.onSuggestClick(e, query)}>
|
|
595
|
-
<ft-ripple></ft-ripple>
|
|
596
|
-
<ft-icon variant="material" part="suggestion-icon">history</ft-icon>
|
|
597
|
-
<ft-typography variant="body1">${query}</ft-typography>
|
|
598
|
-
<ft-button icon="close"
|
|
599
|
-
round
|
|
600
|
-
part="remove-suggestion"
|
|
601
|
-
?dense=${!this.isMobile}
|
|
602
|
-
label="${this.labelResolver.resolve("removeRecentSearch")}"
|
|
603
|
-
tooltipPosition="left"
|
|
604
|
-
@click=${(e) => this.removeRecentSearch(e, query)}></ft-button>
|
|
605
|
-
</a>
|
|
606
|
-
`)}
|
|
607
|
-
${repeat(this.suggestions, suggest => suggest.value, suggest => html `
|
|
608
|
-
<a href="${this.searchRequestSerializer({ ...this.request, query: suggest.value })}"
|
|
609
|
-
part="suggestions"
|
|
610
|
-
class="ft-search-bar--suggestion"
|
|
611
|
-
@keyup=${(e) => this.onSuggestKeyUp(e, suggest.value)}
|
|
612
|
-
@click=${(e) => this.onSuggestClick(e, suggest.value)}>
|
|
613
|
-
<ft-ripple></ft-ripple>
|
|
614
|
-
${this.getIcon(suggest)}
|
|
615
|
-
<ft-typography variant="body1">${suggest.value}</ft-typography>
|
|
616
|
-
</a>
|
|
617
|
-
`)}
|
|
618
|
-
</div>
|
|
619
|
-
`;
|
|
620
|
-
}
|
|
621
|
-
getIcon(suggest) {
|
|
622
|
-
const iconVariant = suggest.type === "DOCUMENT" ? FtIconVariants.file_format : FtIconVariants.fluid_topics;
|
|
623
|
-
let icon;
|
|
624
|
-
switch (suggest.type) {
|
|
625
|
-
case "MAP":
|
|
626
|
-
icon = suggest.editorialType === "BOOK" ? FtIcons.BOOK : FtIcons.ARTICLE;
|
|
627
|
-
break;
|
|
628
|
-
case "DOCUMENT":
|
|
629
|
-
icon = resolveFileFormatIcon(suggest.mimeType, suggest.filenameExtension);
|
|
630
|
-
break;
|
|
631
|
-
case "TOPIC":
|
|
632
|
-
icon = FtIcons.TOPICS;
|
|
633
|
-
break;
|
|
634
|
-
}
|
|
635
|
-
return html `
|
|
636
|
-
<ft-icon variant="${iconVariant}" part="suggestion-icon">
|
|
637
|
-
${icon}
|
|
638
|
-
</ft-icon>
|
|
639
|
-
`;
|
|
640
|
-
}
|
|
641
|
-
openMobileFilters(filterKey) {
|
|
642
|
-
if (this.isMobile) {
|
|
643
|
-
this.mobileMenuOpen = true;
|
|
644
|
-
this.displayFacets = true;
|
|
645
|
-
this.scrollToFacet = filterKey;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
354
|
async firstUpdated(props) {
|
|
649
355
|
super.firstUpdated(props);
|
|
650
356
|
this.initApi();
|
|
@@ -661,7 +367,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
661
367
|
}
|
|
662
368
|
if (props.has("sizeCategory")) {
|
|
663
369
|
this.mobileMenuOpen = false;
|
|
664
|
-
this.displayFacets = this.displayFacets && !this.isMobile;
|
|
370
|
+
this.displayFacets = this.displayFacets && !this.isMobile();
|
|
665
371
|
}
|
|
666
372
|
super.update(props);
|
|
667
373
|
if ((props.has("availableContentLocales") || props.has("contentLocale")) && this.availableContentLocales.length > 0) {
|
|
@@ -704,7 +410,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
704
410
|
this.updateFacets();
|
|
705
411
|
}
|
|
706
412
|
if (["query", "uiLocale", "contentLocale", "searchFilters", "displayedFilters", "api"].some(p => props.has(p))) {
|
|
707
|
-
this.
|
|
413
|
+
this.suggestManager.update();
|
|
708
414
|
}
|
|
709
415
|
if (["query", "uiLocale", "contentLocale", "searchFilters"].some(p => props.has(p))) {
|
|
710
416
|
this.dispatchEvent(new SearchStateChangeEvent(this.request));
|
|
@@ -773,34 +479,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
773
479
|
}
|
|
774
480
|
}
|
|
775
481
|
}
|
|
776
|
-
updateSuggestions() {
|
|
777
|
-
this.suggestionsLoaded = false;
|
|
778
|
-
this.suggestDebouncer.run(async () => {
|
|
779
|
-
this.suggestions = this.api && this.query.length > 2 ? await this.api.getSuggestions(this.suggestRequest).then(r => r.suggestions).catch(() => []) : [];
|
|
780
|
-
this.suggestionsLoaded = true;
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
onSearchBarKeyUp(e) {
|
|
784
|
-
const input = e.composedPath()[0];
|
|
785
|
-
this.query = input.value;
|
|
786
|
-
if (e.key === "Enter") {
|
|
787
|
-
this.launchSearch();
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
onSearchBarKeyDown(e) {
|
|
791
|
-
var _a, _b;
|
|
792
|
-
switch (e.key) {
|
|
793
|
-
case "Escape":
|
|
794
|
-
this.mobileMenuOpen = false;
|
|
795
|
-
(_a = this.input) === null || _a === void 0 ? void 0 : _a.blur();
|
|
796
|
-
break;
|
|
797
|
-
case "ArrowDown":
|
|
798
|
-
e.stopPropagation();
|
|
799
|
-
e.preventDefault();
|
|
800
|
-
(_b = this.firstSuggestion) === null || _b === void 0 ? void 0 : _b.focus();
|
|
801
|
-
break;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
482
|
onFloatingContainerKeyUp(e) {
|
|
805
483
|
var _a;
|
|
806
484
|
if (e.key === "Escape") {
|
|
@@ -814,21 +492,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
814
492
|
}
|
|
815
493
|
this.query = query;
|
|
816
494
|
}
|
|
817
|
-
onSuggestClick(e, suggest) {
|
|
818
|
-
if (!e.ctrlKey && !e.metaKey) {
|
|
819
|
-
this.onSuggestSelected(e, suggest);
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
onSuggestKeyUp(e, suggest) {
|
|
823
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
824
|
-
this.onSuggestSelected(e, suggest);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
onSuggestSelected(e, suggest) {
|
|
828
|
-
e.preventDefault();
|
|
829
|
-
this.setQuery(suggest);
|
|
830
|
-
this.launchSearch();
|
|
831
|
-
}
|
|
832
495
|
launchSearch() {
|
|
833
496
|
if (this.query) {
|
|
834
497
|
let filteredRecentSearches = this.recentSearches
|
|
@@ -872,12 +535,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
872
535
|
updateSize(e) {
|
|
873
536
|
this.sizeCategory = e.detail.category;
|
|
874
537
|
}
|
|
875
|
-
getLocaleLabel(locale) {
|
|
876
|
-
var _a;
|
|
877
|
-
return (_a = this.availableContentLocales.filter(l => { var _a; return ((_a = l.lang) !== null && _a !== void 0 ? _a : "").toLowerCase() === (locale !== null && locale !== void 0 ? locale : "").toLowerCase(); })
|
|
878
|
-
.map(l => l.label)
|
|
879
|
-
.pop()) !== null && _a !== void 0 ? _a : locale;
|
|
880
|
-
}
|
|
881
538
|
setFilter(key, selectedValues) {
|
|
882
539
|
let newFilters = this.searchFilters.filter(f => f.key !== key);
|
|
883
540
|
this.facets.forEach(facet => {
|
|
@@ -909,29 +566,20 @@ export class FtSearchBar extends FtLitElement {
|
|
|
909
566
|
const firstFacet = this.facets[0];
|
|
910
567
|
this.scrollToFacet = firstFacet === null || firstFacet === void 0 ? void 0 : firstFacet.key;
|
|
911
568
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
e.preventDefault();
|
|
915
|
-
e.stopPropagation();
|
|
916
|
-
const thingToFocus = (_d = (_b = (_a = this.focusedSuggestion) === null || _a === void 0 ? void 0 : _a.previousElementSibling) !== null && _b !== void 0 ? _b : (_c = this.focusedSuggestion) === null || _c === void 0 ? void 0 : _c.nextElementSibling) !== null && _d !== void 0 ? _d : this.input;
|
|
917
|
-
thingToFocus === null || thingToFocus === void 0 ? void 0 : thingToFocus.focus();
|
|
918
|
-
this.recentSearches = this.recentSearches.filter(q => q.toLowerCase() !== query.toLowerCase());
|
|
919
|
-
this.saveRecentSearches();
|
|
569
|
+
querySelector(selectors) {
|
|
570
|
+
return this.shadowRoot.querySelector(selectors);
|
|
920
571
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
e.stopPropagation();
|
|
933
|
-
break;
|
|
934
|
-
}
|
|
572
|
+
querySelectorAll(selectors) {
|
|
573
|
+
return this.shadowRoot.querySelectorAll(selectors);
|
|
574
|
+
}
|
|
575
|
+
renderDesktopFloatingMenu() {
|
|
576
|
+
return this.forceMenuOpen ? nothing : html `
|
|
577
|
+
<div class="ft-search-bar--floating-panel"
|
|
578
|
+
@keyup=${this.onFloatingContainerKeyUp}
|
|
579
|
+
part="floating-panel"
|
|
580
|
+
tabindex="-1">
|
|
581
|
+
${this.renderDesktopMenu()}
|
|
582
|
+
</div>`;
|
|
935
583
|
}
|
|
936
584
|
}
|
|
937
585
|
FtSearchBar.elementDefinitions = {
|
|
@@ -955,8 +603,8 @@ FtSearchBar.styles = [
|
|
|
955
603
|
FtTypographyBody2,
|
|
956
604
|
searchBarCss,
|
|
957
605
|
facetsCss,
|
|
958
|
-
|
|
959
|
-
|
|
606
|
+
FacetsChipsManager.styles,
|
|
607
|
+
SuggestManager.styles
|
|
960
608
|
];
|
|
961
609
|
__decorate([
|
|
962
610
|
property({ type: Boolean })
|
|
@@ -1045,24 +693,12 @@ __decorate([
|
|
|
1045
693
|
__decorate([
|
|
1046
694
|
state()
|
|
1047
695
|
], FtSearchBar.prototype, "suggestions", void 0);
|
|
1048
|
-
__decorate([
|
|
1049
|
-
state()
|
|
1050
|
-
], FtSearchBar.prototype, "suggestionsLoaded", void 0);
|
|
1051
696
|
__decorate([
|
|
1052
697
|
state()
|
|
1053
698
|
], FtSearchBar.prototype, "recentSearches", void 0);
|
|
1054
699
|
__decorate([
|
|
1055
700
|
state()
|
|
1056
701
|
], FtSearchBar.prototype, "scrollToFacet", void 0);
|
|
1057
|
-
__decorate([
|
|
1058
|
-
query(".ft-search-bar--suggestion:first-child")
|
|
1059
|
-
], FtSearchBar.prototype, "firstSuggestion", void 0);
|
|
1060
|
-
__decorate([
|
|
1061
|
-
query(".ft-search-bar--suggestion:focus-within")
|
|
1062
|
-
], FtSearchBar.prototype, "focusedSuggestion", void 0);
|
|
1063
|
-
__decorate([
|
|
1064
|
-
query(".ft-search-bar--suggestion:last-child")
|
|
1065
|
-
], FtSearchBar.prototype, "lastSuggestion", void 0);
|
|
1066
702
|
__decorate([
|
|
1067
703
|
state()
|
|
1068
704
|
], FtSearchBar.prototype, "api", void 0);
|