@fluid-topics/ft-search-bar 0.2.9 → 0.2.10
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 +42 -14
- package/build/ft-search-bar.light.js +167 -129
- 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("selectedPreset")) {
|
|
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,11 @@ export class FtSearchBar extends FtLitElement {
|
|
|
633
650
|
this.dispatchEvent(new SearchStateChangeEvent(this.request));
|
|
634
651
|
}
|
|
635
652
|
}
|
|
653
|
+
async updateAvailableContentLocales() {
|
|
654
|
+
var _a, _b;
|
|
655
|
+
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 : [];
|
|
656
|
+
this.availableContentLocalesInitialized = true;
|
|
657
|
+
}
|
|
636
658
|
contentAvailableCallback(props) {
|
|
637
659
|
var _a, _b, _c;
|
|
638
660
|
super.contentAvailableCallback(props);
|
|
@@ -650,13 +672,10 @@ export class FtSearchBar extends FtLitElement {
|
|
|
650
672
|
}
|
|
651
673
|
initApi() {
|
|
652
674
|
if (this.api == null) {
|
|
653
|
-
this.
|
|
675
|
+
this.api = window.fluidtopics ? new window.fluidtopics.FluidTopicsApi(this.baseUrl, this.apiIntegrationIdentifier, true) : undefined;
|
|
654
676
|
setTimeout(() => this.initApi(), 100);
|
|
655
677
|
}
|
|
656
678
|
}
|
|
657
|
-
setApi() {
|
|
658
|
-
this.api = window.fluidtopics ? new window.fluidtopics.FluidTopicsApi(this.baseUrl, this.apiIntegrationIdentifier, true) : undefined;
|
|
659
|
-
}
|
|
660
679
|
updateFacets() {
|
|
661
680
|
if (this.facetsRequest.length > 0) {
|
|
662
681
|
this.facetsLoaded = false;
|
|
@@ -665,10 +684,12 @@ export class FtSearchBar extends FtLitElement {
|
|
|
665
684
|
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 : [];
|
|
666
685
|
this.facets.forEach(f => this.knownFacetLabels[f.key] = f.label);
|
|
667
686
|
this.facetsLoaded = true;
|
|
687
|
+
this.facetsInitialized = true;
|
|
668
688
|
});
|
|
669
689
|
}
|
|
670
690
|
else {
|
|
671
691
|
this.facets = [];
|
|
692
|
+
this.facetsInitialized = true;
|
|
672
693
|
}
|
|
673
694
|
}
|
|
674
695
|
updateSuggestions() {
|
|
@@ -830,6 +851,7 @@ FtSearchBar.elementDefinitions = {
|
|
|
830
851
|
"ft-select": FtSelect,
|
|
831
852
|
"ft-select-option": FtSelectOption,
|
|
832
853
|
"ft-size-watcher": FtSizeWatcher,
|
|
854
|
+
"ft-skeleton": FtSkeleton,
|
|
833
855
|
"ft-snap-scroll": FtSnapScroll,
|
|
834
856
|
"ft-tooltip": FtTooltip,
|
|
835
857
|
"ft-typography": FtTypography,
|
|
@@ -856,6 +878,9 @@ __decorate([
|
|
|
856
878
|
__decorate([
|
|
857
879
|
state()
|
|
858
880
|
], FtSearchBar.prototype, "availableContentLocales", void 0);
|
|
881
|
+
__decorate([
|
|
882
|
+
state()
|
|
883
|
+
], FtSearchBar.prototype, "availableContentLocalesInitialized", void 0);
|
|
859
884
|
__decorate([
|
|
860
885
|
property({ type: String })
|
|
861
886
|
], FtSearchBar.prototype, "uiLocale", void 0);
|
|
@@ -892,6 +917,9 @@ __decorate([
|
|
|
892
917
|
__decorate([
|
|
893
918
|
state()
|
|
894
919
|
], FtSearchBar.prototype, "facets", void 0);
|
|
920
|
+
__decorate([
|
|
921
|
+
state()
|
|
922
|
+
], FtSearchBar.prototype, "facetsInitialized", void 0);
|
|
895
923
|
__decorate([
|
|
896
924
|
query(".ft-search-bar--container")
|
|
897
925
|
], FtSearchBar.prototype, "container", void 0);
|