@fluid-topics/ft-search-bar 0.2.7 → 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 +7 -3
- package/build/ft-search-bar.inline-styles.js +156 -116
- package/build/ft-search-bar.js +52 -21
- package/build/ft-search-bar.light.js +143 -103
- package/build/ft-search-bar.min.js +173 -133
- 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 = [];
|
|
@@ -104,7 +107,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
104
107
|
contentLocale: this.contentLocale,
|
|
105
108
|
query: this.query,
|
|
106
109
|
facets: this.facetsRequest,
|
|
107
|
-
priors: this.
|
|
110
|
+
priors: this.hasPriors ? this.priors : undefined,
|
|
108
111
|
filters: this.searchFilters,
|
|
109
112
|
paging: { perPage: 0, page: 1 },
|
|
110
113
|
sort: [],
|
|
@@ -119,7 +122,6 @@ export class FtSearchBar extends FtLitElement {
|
|
|
119
122
|
contentLocale: this.contentLocale,
|
|
120
123
|
input: this.query,
|
|
121
124
|
filters: this.searchFilters,
|
|
122
|
-
priors: this.priors.length > 0 ? this.priors : undefined,
|
|
123
125
|
sort: []
|
|
124
126
|
};
|
|
125
127
|
}
|
|
@@ -130,7 +132,10 @@ export class FtSearchBar extends FtLitElement {
|
|
|
130
132
|
return this.facetsRequest.length > 0;
|
|
131
133
|
}
|
|
132
134
|
get hasPresets() {
|
|
133
|
-
return this.presets.length > 0;
|
|
135
|
+
return this.presets != null && this.presets.length > 0;
|
|
136
|
+
}
|
|
137
|
+
get hasPriors() {
|
|
138
|
+
return this.priors != null && this.priors.length > 0;
|
|
134
139
|
}
|
|
135
140
|
get hasLocaleSelector() {
|
|
136
141
|
return this.availableContentLocales.length > 1;
|
|
@@ -149,6 +154,12 @@ export class FtSearchBar extends FtLitElement {
|
|
|
149
154
|
this.displayFacets = false;
|
|
150
155
|
}
|
|
151
156
|
render() {
|
|
157
|
+
return html `
|
|
158
|
+
<ft-size-watcher @change=${this.updateSize}></ft-size-watcher>
|
|
159
|
+
${this.renderSearchBar()}
|
|
160
|
+
`;
|
|
161
|
+
}
|
|
162
|
+
renderSearchBar() {
|
|
152
163
|
const rootClasses = {
|
|
153
164
|
"ft-search-bar--container": true,
|
|
154
165
|
"ft-search-bar--dense": !this.isMobile && this.dense,
|
|
@@ -157,11 +168,12 @@ export class FtSearchBar extends FtLitElement {
|
|
|
157
168
|
"ft-search-bar--floating-panel-open": !this.isMobile && this.displayFacets,
|
|
158
169
|
"ft-search-bar--mobile-menu-open": this.mobileMenuOpen,
|
|
159
170
|
};
|
|
160
|
-
return html `
|
|
161
|
-
<ft-size-watcher @change=${this.updateSize}></ft-size-watcher>
|
|
171
|
+
return this.facetsInitialized && this.availableContentLocalesInitialized ? html `
|
|
162
172
|
<div class="${classMap(rootClasses)}" part="container" tabindex="-1">
|
|
163
173
|
${this.isMobile ? this.renderMobileSearchBar() : this.renderDesktopSearchBar()}
|
|
164
174
|
</div>
|
|
175
|
+
` : html `
|
|
176
|
+
<ft-skeleton class="ft-search-bar--skeleton"></ft-skeleton>
|
|
165
177
|
`;
|
|
166
178
|
}
|
|
167
179
|
renderMobileSearchBar() {
|
|
@@ -377,6 +389,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
377
389
|
`;
|
|
378
390
|
}
|
|
379
391
|
renderFacetsActions() {
|
|
392
|
+
var _a;
|
|
380
393
|
return html `
|
|
381
394
|
<div class="ft-search-bar--facets-actions">
|
|
382
395
|
${this.hasPresets ? html `
|
|
@@ -386,7 +399,7 @@ export class FtSearchBar extends FtLitElement {
|
|
|
386
399
|
label="${this.labelResolver.resolve("presetsSelector")}"
|
|
387
400
|
outlined
|
|
388
401
|
@change=${(e) => this.selectedPreset = e.detail}>
|
|
389
|
-
${repeat(this.presets, p => p.name, p => html `
|
|
402
|
+
${repeat((_a = this.presets) !== null && _a !== void 0 ? _a : [], p => p.name, p => html `
|
|
390
403
|
<ft-select-option value="${p.name}"
|
|
391
404
|
label="${p.name}"
|
|
392
405
|
?selected=${p.name === this.selectedPreset}>
|
|
@@ -581,13 +594,11 @@ export class FtSearchBar extends FtLitElement {
|
|
|
581
594
|
}
|
|
582
595
|
}
|
|
583
596
|
async firstUpdated(props) {
|
|
584
|
-
var _a, _b;
|
|
585
597
|
super.firstUpdated(props);
|
|
586
598
|
this.initApi();
|
|
587
|
-
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 : [];
|
|
588
599
|
}
|
|
589
600
|
update(props) {
|
|
590
|
-
var _a, _b, _c;
|
|
601
|
+
var _a, _b, _c, _d, _e, _f;
|
|
591
602
|
if (props.has("labels")) {
|
|
592
603
|
this.labelResolver = new ParametrizedLabelResolver(DEFAULT_LABELS, this.labels);
|
|
593
604
|
}
|
|
@@ -608,17 +619,26 @@ export class FtSearchBar extends FtLitElement {
|
|
|
608
619
|
}
|
|
609
620
|
this.recentSearches = JSON.parse((_b = window.localStorage.getItem(this.recentSearchesStorageKey)) !== null && _b !== void 0 ? _b : "[]");
|
|
610
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
|
+
}
|
|
611
625
|
if (props.has("selectedPreset")) {
|
|
612
|
-
const currentPreset = this.presets.find(p => p.name === this.selectedPreset);
|
|
626
|
+
const currentPreset = ((_d = this.presets) !== null && _d !== void 0 ? _d : []).find(p => p.name === this.selectedPreset);
|
|
613
627
|
if (currentPreset && !this.compareRequests(this.request, currentPreset)) {
|
|
614
628
|
this.setFiltersFromPreset(currentPreset);
|
|
615
629
|
}
|
|
616
630
|
}
|
|
617
631
|
if (["contentLocale", "searchFilters"].some(p => props.has(p))) {
|
|
618
|
-
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;
|
|
619
633
|
}
|
|
620
634
|
if (["baseUrl", "apiIntegrationIdentifier"].some(p => props.has(p))) {
|
|
621
|
-
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();
|
|
622
642
|
}
|
|
623
643
|
if (["uiLocale", "contentLocale", "searchFilters", "displayedFilters", "api"].some(p => props.has(p))) {
|
|
624
644
|
this.updateFacets();
|
|
@@ -630,6 +650,11 @@ export class FtSearchBar extends FtLitElement {
|
|
|
630
650
|
this.dispatchEvent(new SearchStateChangeEvent(this.request));
|
|
631
651
|
}
|
|
632
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
|
+
}
|
|
633
658
|
contentAvailableCallback(props) {
|
|
634
659
|
var _a, _b, _c;
|
|
635
660
|
super.contentAvailableCallback(props);
|
|
@@ -647,13 +672,10 @@ export class FtSearchBar extends FtLitElement {
|
|
|
647
672
|
}
|
|
648
673
|
initApi() {
|
|
649
674
|
if (this.api == null) {
|
|
650
|
-
this.
|
|
675
|
+
this.api = window.fluidtopics ? new window.fluidtopics.FluidTopicsApi(this.baseUrl, this.apiIntegrationIdentifier, true) : undefined;
|
|
651
676
|
setTimeout(() => this.initApi(), 100);
|
|
652
677
|
}
|
|
653
678
|
}
|
|
654
|
-
setApi() {
|
|
655
|
-
this.api = window.fluidtopics ? new window.fluidtopics.FluidTopicsApi(this.baseUrl, this.apiIntegrationIdentifier, true) : undefined;
|
|
656
|
-
}
|
|
657
679
|
updateFacets() {
|
|
658
680
|
if (this.facetsRequest.length > 0) {
|
|
659
681
|
this.facetsLoaded = false;
|
|
@@ -662,10 +684,12 @@ export class FtSearchBar extends FtLitElement {
|
|
|
662
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 : [];
|
|
663
685
|
this.facets.forEach(f => this.knownFacetLabels[f.key] = f.label);
|
|
664
686
|
this.facetsLoaded = true;
|
|
687
|
+
this.facetsInitialized = true;
|
|
665
688
|
});
|
|
666
689
|
}
|
|
667
690
|
else {
|
|
668
691
|
this.facets = [];
|
|
692
|
+
this.facetsInitialized = true;
|
|
669
693
|
}
|
|
670
694
|
}
|
|
671
695
|
updateSuggestions() {
|
|
@@ -827,6 +851,7 @@ FtSearchBar.elementDefinitions = {
|
|
|
827
851
|
"ft-select": FtSelect,
|
|
828
852
|
"ft-select-option": FtSelectOption,
|
|
829
853
|
"ft-size-watcher": FtSizeWatcher,
|
|
854
|
+
"ft-skeleton": FtSkeleton,
|
|
830
855
|
"ft-snap-scroll": FtSnapScroll,
|
|
831
856
|
"ft-tooltip": FtTooltip,
|
|
832
857
|
"ft-typography": FtTypography,
|
|
@@ -853,6 +878,9 @@ __decorate([
|
|
|
853
878
|
__decorate([
|
|
854
879
|
state()
|
|
855
880
|
], FtSearchBar.prototype, "availableContentLocales", void 0);
|
|
881
|
+
__decorate([
|
|
882
|
+
state()
|
|
883
|
+
], FtSearchBar.prototype, "availableContentLocalesInitialized", void 0);
|
|
856
884
|
__decorate([
|
|
857
885
|
property({ type: String })
|
|
858
886
|
], FtSearchBar.prototype, "uiLocale", void 0);
|
|
@@ -865,12 +893,12 @@ __decorate([
|
|
|
865
893
|
__decorate([
|
|
866
894
|
jsonProperty([])
|
|
867
895
|
], FtSearchBar.prototype, "presets", void 0);
|
|
868
|
-
__decorate([
|
|
869
|
-
jsonProperty([])
|
|
870
|
-
], FtSearchBar.prototype, "priors", void 0);
|
|
871
896
|
__decorate([
|
|
872
897
|
property({ type: String, reflect: true })
|
|
873
898
|
], FtSearchBar.prototype, "selectedPreset", void 0);
|
|
899
|
+
__decorate([
|
|
900
|
+
jsonProperty([])
|
|
901
|
+
], FtSearchBar.prototype, "priors", void 0);
|
|
874
902
|
__decorate([
|
|
875
903
|
property()
|
|
876
904
|
], FtSearchBar.prototype, "searchRequestSerializer", void 0);
|
|
@@ -889,6 +917,9 @@ __decorate([
|
|
|
889
917
|
__decorate([
|
|
890
918
|
state()
|
|
891
919
|
], FtSearchBar.prototype, "facets", void 0);
|
|
920
|
+
__decorate([
|
|
921
|
+
state()
|
|
922
|
+
], FtSearchBar.prototype, "facetsInitialized", void 0);
|
|
892
923
|
__decorate([
|
|
893
924
|
query(".ft-search-bar--container")
|
|
894
925
|
], FtSearchBar.prototype, "container", void 0);
|