@fluid-topics/ft-search-bar 0.2.9 → 0.2.13
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 +6 -0
- package/build/ft-search-bar.d.ts +4 -1
- package/build/ft-search-bar.inline-styles.js +152 -114
- package/build/ft-search-bar.js +56 -25
- package/build/ft-search-bar.light.js +184 -146
- package/build/ft-search-bar.min.js +169 -131
- package/package.json +14 -13
package/build/ft-search-bar.js
CHANGED
|
@@ -11,7 +11,7 @@ import { classMap } from "lit/directives/class-map.js";
|
|
|
11
11
|
import { Debouncer, FtLitElement, jsonProperty, ParametrizedLabelResolver } from "@fluid-topics/ft-wc-utils";
|
|
12
12
|
import { FtSizeCategory, FtSizeWatcher } from "@fluid-topics/ft-size-watcher";
|
|
13
13
|
import { FtTypography, FtTypographyBody2 } from "@fluid-topics/ft-typography";
|
|
14
|
-
import { facetToFilter, getBreadcrumbFromValue, getLabelFromValue, getSelectedValues, selectedValues, serializeRequest } from "./converters";
|
|
14
|
+
import { facetToFilter, getBreadcrumbFromValue, getLabelFromValue, getSelectedValues, selectedValues, serializeRequest, unquote } from "./converters";
|
|
15
15
|
import { FtFilter, FtFilterOption } from "@fluid-topics/ft-filter";
|
|
16
16
|
import { FtIcon, FtIcons, FtIconVariants, resolveFileFormatIcon, } from "@fluid-topics/ft-icon";
|
|
17
17
|
import { FtAccordion, FtAccordionItem } from "@fluid-topics/ft-accordion";
|
|
@@ -23,6 +23,7 @@ import { FtTooltip } from "@fluid-topics/ft-tooltip";
|
|
|
23
23
|
import { FtRipple } from "@fluid-topics/ft-ripple";
|
|
24
24
|
import { flatDeep } from "@fluid-topics/ft-filter/build/utils";
|
|
25
25
|
import { facetsCss, searchBarCss, selectedFiltersCss, suggestionsCss } from "./ft-search-bar.css";
|
|
26
|
+
import { FtSkeleton } from "@fluid-topics/ft-skeleton";
|
|
26
27
|
if (window.fluidtopics == null) {
|
|
27
28
|
console.warn("Fluid Topics public API was not found. You can find it here: https://www.npmjs.com/package/@fluid-topics/public-api");
|
|
28
29
|
}
|
|
@@ -63,6 +64,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
63
64
|
this.baseUrl = "";
|
|
64
65
|
this.apiIntegrationIdentifier = "ft-search-bar";
|
|
65
66
|
this.availableContentLocales = [];
|
|
67
|
+
this.availableContentLocalesInitialized = false;
|
|
66
68
|
this.labels = {};
|
|
67
69
|
this.labelResolver = new ParametrizedLabelResolver(DEFAULT_LABELS, {});
|
|
68
70
|
this.displayedFilters = [];
|
|
@@ -70,10 +72,11 @@ export class FtSearchBar extends FtLitElement {
|
|
|
70
72
|
this.priors = [];
|
|
71
73
|
this.searchRequestSerializer = (request) => serializeRequest(this.baseUrl, request);
|
|
72
74
|
this.searchFilters = [];
|
|
73
|
-
this.sizeCategory = FtSizeCategory.
|
|
75
|
+
this.sizeCategory = FtSizeCategory.M;
|
|
74
76
|
this.displayFacets = false;
|
|
75
77
|
this.mobileMenuOpen = false;
|
|
76
78
|
this.facets = [];
|
|
79
|
+
this.facetsInitialized = false;
|
|
77
80
|
this.knownFacetLabels = {};
|
|
78
81
|
this.query = "";
|
|
79
82
|
this.suggestions = [];
|
|
@@ -151,6 +154,12 @@ export class FtSearchBar extends FtLitElement {
|
|
|
151
154
|
this.displayFacets = false;
|
|
152
155
|
}
|
|
153
156
|
render() {
|
|
157
|
+
return html `
|
|
158
|
+
<ft-size-watcher @change=${this.updateSize}></ft-size-watcher>
|
|
159
|
+
${this.renderSearchBar()}
|
|
160
|
+
`;
|
|
161
|
+
}
|
|
162
|
+
renderSearchBar() {
|
|
154
163
|
const rootClasses = {
|
|
155
164
|
"ft-search-bar--container": true,
|
|
156
165
|
"ft-search-bar--dense": !this.isMobile && this.dense,
|
|
@@ -159,11 +168,12 @@ export class FtSearchBar extends FtLitElement {
|
|
|
159
168
|
"ft-search-bar--floating-panel-open": !this.isMobile && this.displayFacets,
|
|
160
169
|
"ft-search-bar--mobile-menu-open": this.mobileMenuOpen,
|
|
161
170
|
};
|
|
162
|
-
return html `
|
|
163
|
-
<ft-size-watcher @change=${this.updateSize}></ft-size-watcher>
|
|
171
|
+
return this.facetsInitialized && this.availableContentLocalesInitialized ? html `
|
|
164
172
|
<div class="${classMap(rootClasses)}" part="container" tabindex="-1">
|
|
165
173
|
${this.isMobile ? this.renderMobileSearchBar() : this.renderDesktopSearchBar()}
|
|
166
174
|
</div>
|
|
175
|
+
` : html `
|
|
176
|
+
<ft-skeleton class="ft-search-bar--skeleton"></ft-skeleton>
|
|
167
177
|
`;
|
|
168
178
|
}
|
|
169
179
|
renderMobileSearchBar() {
|
|
@@ -584,13 +594,11 @@ export class FtSearchBar extends FtLitElement {
|
|
|
584
594
|
}
|
|
585
595
|
}
|
|
586
596
|
async firstUpdated(props) {
|
|
587
|
-
var _a, _b;
|
|
588
597
|
super.firstUpdated(props);
|
|
589
598
|
this.initApi();
|
|
590
|
-
this.availableContentLocales = (_b = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.getAvailableSearchLocales().then(result => result.contentLocales).catch(() => []))) !== null && _b !== void 0 ? _b : [];
|
|
591
599
|
}
|
|
592
600
|
update(props) {
|
|
593
|
-
var _a, _b, _c, _d, _e;
|
|
601
|
+
var _a, _b, _c, _d, _e, _f;
|
|
594
602
|
if (props.has("labels")) {
|
|
595
603
|
this.labelResolver = new ParametrizedLabelResolver(DEFAULT_LABELS, this.labels);
|
|
596
604
|
}
|
|
@@ -611,17 +619,26 @@ export class FtSearchBar extends FtLitElement {
|
|
|
611
619
|
}
|
|
612
620
|
this.recentSearches = JSON.parse((_b = window.localStorage.getItem(this.recentSearchesStorageKey)) !== null && _b !== void 0 ? _b : "[]");
|
|
613
621
|
}
|
|
622
|
+
if (props.has("presets")) {
|
|
623
|
+
((_c = this.presets) !== null && _c !== void 0 ? _c : []).forEach(preset => preset.filters.forEach(filter => filter.values = filter.values.map(v => unquote(v))));
|
|
624
|
+
}
|
|
614
625
|
if (props.has("selectedPreset")) {
|
|
615
|
-
const currentPreset = ((
|
|
626
|
+
const currentPreset = ((_d = this.presets) !== null && _d !== void 0 ? _d : []).find(p => p.name === this.selectedPreset);
|
|
616
627
|
if (currentPreset && !this.compareRequests(this.request, currentPreset)) {
|
|
617
628
|
this.setFiltersFromPreset(currentPreset);
|
|
618
629
|
}
|
|
619
630
|
}
|
|
620
631
|
if (["contentLocale", "searchFilters"].some(p => props.has(p))) {
|
|
621
|
-
this.selectedPreset = (
|
|
632
|
+
this.selectedPreset = (_f = ((_e = this.presets) !== null && _e !== void 0 ? _e : []).find(p => this.compareRequests(p, this.request))) === null || _f === void 0 ? void 0 : _f.name;
|
|
622
633
|
}
|
|
623
634
|
if (["baseUrl", "apiIntegrationIdentifier"].some(p => props.has(p))) {
|
|
624
|
-
this.
|
|
635
|
+
this.api = undefined;
|
|
636
|
+
this.initApi();
|
|
637
|
+
this.availableContentLocalesInitialized = false;
|
|
638
|
+
this.facetsInitialized = false;
|
|
639
|
+
}
|
|
640
|
+
if (props.has("api")) {
|
|
641
|
+
this.updateAvailableContentLocales();
|
|
625
642
|
}
|
|
626
643
|
if (["uiLocale", "contentLocale", "searchFilters", "displayedFilters", "api"].some(p => props.has(p))) {
|
|
627
644
|
this.updateFacets();
|
|
@@ -633,6 +650,12 @@ export class FtSearchBar extends FtLitElement {
|
|
|
633
650
|
this.dispatchEvent(new SearchStateChangeEvent(this.request));
|
|
634
651
|
}
|
|
635
652
|
}
|
|
653
|
+
async updateAvailableContentLocales() {
|
|
654
|
+
if (this.api) {
|
|
655
|
+
this.availableContentLocales = await this.api.getAvailableSearchLocales().then(result => result.contentLocales).catch(() => []);
|
|
656
|
+
this.availableContentLocalesInitialized = true;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
636
659
|
contentAvailableCallback(props) {
|
|
637
660
|
var _a, _b, _c;
|
|
638
661
|
super.contentAvailableCallback(props);
|
|
@@ -650,25 +673,26 @@ export class FtSearchBar extends FtLitElement {
|
|
|
650
673
|
}
|
|
651
674
|
initApi() {
|
|
652
675
|
if (this.api == null) {
|
|
653
|
-
this.
|
|
676
|
+
this.api = window.fluidtopics ? new window.fluidtopics.FluidTopicsApi(this.baseUrl, this.apiIntegrationIdentifier, true) : undefined;
|
|
654
677
|
setTimeout(() => this.initApi(), 100);
|
|
655
678
|
}
|
|
656
679
|
}
|
|
657
|
-
setApi() {
|
|
658
|
-
this.api = window.fluidtopics ? new window.fluidtopics.FluidTopicsApi(this.baseUrl, this.apiIntegrationIdentifier, true) : undefined;
|
|
659
|
-
}
|
|
660
680
|
updateFacets() {
|
|
661
|
-
if (this.
|
|
662
|
-
this.
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
681
|
+
if (this.api) {
|
|
682
|
+
if (this.facetsRequest.length > 0) {
|
|
683
|
+
this.facetsLoaded = false;
|
|
684
|
+
this.updateFacetsDebouncer.run(async () => {
|
|
685
|
+
var _a, _b;
|
|
686
|
+
this.facets = (_b = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.search({ ...this.request, query: "" }).then(r => r.facets).catch(() => []))) !== null && _b !== void 0 ? _b : [];
|
|
687
|
+
this.facets.forEach(f => this.knownFacetLabels[f.key] = f.label);
|
|
688
|
+
this.facetsLoaded = true;
|
|
689
|
+
this.facetsInitialized = true;
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
this.facets = [];
|
|
694
|
+
this.facetsInitialized = true;
|
|
695
|
+
}
|
|
672
696
|
}
|
|
673
697
|
}
|
|
674
698
|
updateSuggestions() {
|
|
@@ -830,6 +854,7 @@ FtSearchBar.elementDefinitions = {
|
|
|
830
854
|
"ft-select": FtSelect,
|
|
831
855
|
"ft-select-option": FtSelectOption,
|
|
832
856
|
"ft-size-watcher": FtSizeWatcher,
|
|
857
|
+
"ft-skeleton": FtSkeleton,
|
|
833
858
|
"ft-snap-scroll": FtSnapScroll,
|
|
834
859
|
"ft-tooltip": FtTooltip,
|
|
835
860
|
"ft-typography": FtTypography,
|
|
@@ -856,6 +881,9 @@ __decorate([
|
|
|
856
881
|
__decorate([
|
|
857
882
|
state()
|
|
858
883
|
], FtSearchBar.prototype, "availableContentLocales", void 0);
|
|
884
|
+
__decorate([
|
|
885
|
+
state()
|
|
886
|
+
], FtSearchBar.prototype, "availableContentLocalesInitialized", void 0);
|
|
859
887
|
__decorate([
|
|
860
888
|
property({ type: String })
|
|
861
889
|
], FtSearchBar.prototype, "uiLocale", void 0);
|
|
@@ -892,6 +920,9 @@ __decorate([
|
|
|
892
920
|
__decorate([
|
|
893
921
|
state()
|
|
894
922
|
], FtSearchBar.prototype, "facets", void 0);
|
|
923
|
+
__decorate([
|
|
924
|
+
state()
|
|
925
|
+
], FtSearchBar.prototype, "facetsInitialized", void 0);
|
|
895
926
|
__decorate([
|
|
896
927
|
query(".ft-search-bar--container")
|
|
897
928
|
], FtSearchBar.prototype, "container", void 0);
|