@fluid-topics/ft-search-bar 0.0.88
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/README.md +29 -0
- package/build/converters.d.ts +10 -0
- package/build/converters.js +57 -0
- package/build/ft-search-bar.d.ts +132 -0
- package/build/ft-search-bar.js +1126 -0
- package/build/ft-search-bar.min.js +481 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Search bar component using Fluid Topics public API
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-search-bar
|
|
7
|
+
yarn add @fluid-topics/ft-search-bar
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
The search bar requires the [Fluid Topics public API](https://www.npmjs.com/package/@fluid-topics/public-api) to be imported independently.
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { html } from "lit"
|
|
16
|
+
import "@fluid-topics/ft-search-bar"
|
|
17
|
+
import "@fluid-topics/public-api/dist/fluidtopics.min.js"
|
|
18
|
+
|
|
19
|
+
function render() {
|
|
20
|
+
return html`
|
|
21
|
+
<ft-search-bar
|
|
22
|
+
baseUrl="http://doc.fluidtopics.com"
|
|
23
|
+
.displayedFilters=${["Version_FT", "Category", "Platform", "audience"]}
|
|
24
|
+
@change=${ (e: SearchStateChangeEvent) => console.log("Search state change:", e.detail) }
|
|
25
|
+
@launch-search=${ (e: LaunchSearchEvent) => console.log("Launch search:", e.detail) }
|
|
26
|
+
></ft-search-bar>
|
|
27
|
+
`
|
|
28
|
+
}
|
|
29
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FtSearchFacet, FtSearchRequest } from "@fluid-topics/public-api";
|
|
2
|
+
import { FtFilterProperties } from "@fluid-topics/ft-filter";
|
|
3
|
+
export declare function serializeRequest(baseUrl: string, request: FtSearchRequest): string;
|
|
4
|
+
export declare function quote(value: string): string;
|
|
5
|
+
export declare function unquote(value: string): string;
|
|
6
|
+
export declare function getLabelFromValue(value: string): string | undefined;
|
|
7
|
+
export declare function getBreadcrumbFromValue(value: string): string;
|
|
8
|
+
export declare function selectedValues(facet: FtFilterProperties): Array<string>;
|
|
9
|
+
export declare function facetToFilter(facet: FtSearchFacet): FtFilterProperties;
|
|
10
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { flatDeep } from "@fluid-topics/ft-filter/build/utils";
|
|
2
|
+
export function serializeRequest(baseUrl, request) {
|
|
3
|
+
var _a;
|
|
4
|
+
const params = new URLSearchParams({
|
|
5
|
+
"content-lang": (_a = request.contentLocale) !== null && _a !== void 0 ? _a : "all",
|
|
6
|
+
"query": request.query
|
|
7
|
+
});
|
|
8
|
+
if (request.filters.length > 0) {
|
|
9
|
+
const filters = request.filters.map(filter => {
|
|
10
|
+
const values = filter.values
|
|
11
|
+
.map(value => value.replace(/_/g, "\\\\\\\\_")
|
|
12
|
+
.replace(/~/g, "\\\\~")
|
|
13
|
+
.replace(/\*/g, "\\*"))
|
|
14
|
+
.map(value => encodeURIComponent(quote(value)))
|
|
15
|
+
.join("_");
|
|
16
|
+
return `${filter.key}~${values}`;
|
|
17
|
+
}).join("*");
|
|
18
|
+
params.append("filters", filters);
|
|
19
|
+
}
|
|
20
|
+
const url = new URL(`${baseUrl}/search/all?${params.toString()}`);
|
|
21
|
+
return url.href;
|
|
22
|
+
}
|
|
23
|
+
export function quote(value) {
|
|
24
|
+
return `"${value}"`;
|
|
25
|
+
}
|
|
26
|
+
export function unquote(value) {
|
|
27
|
+
if (value.startsWith("\"") && value.endsWith("\"")) {
|
|
28
|
+
return value.replace(/(^"+)|("+$)/g, "");
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
export function getLabelFromValue(value) {
|
|
33
|
+
return unquote(value).split("|").pop();
|
|
34
|
+
}
|
|
35
|
+
export function getBreadcrumbFromValue(value) {
|
|
36
|
+
return unquote(value).split("|").join(" > ");
|
|
37
|
+
}
|
|
38
|
+
function facetEntryToOption(entry, forceUnselected) {
|
|
39
|
+
return {
|
|
40
|
+
label: entry.label,
|
|
41
|
+
selected: !forceUnselected && entry.selected,
|
|
42
|
+
subOptions: entry.childNodes.map(n => facetEntryToOption(n, entry.selected)),
|
|
43
|
+
value: entry.value
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function selectedValues(facet) {
|
|
47
|
+
return flatDeep(facet.options, n => { var _a; return (_a = n.subOptions) !== null && _a !== void 0 ? _a : []; }).filter(n => n.selected).map(n => n.label);
|
|
48
|
+
}
|
|
49
|
+
export function facetToFilter(facet) {
|
|
50
|
+
return {
|
|
51
|
+
id: facet.key,
|
|
52
|
+
label: facet.label,
|
|
53
|
+
multivalued: facet.multiSelectionable,
|
|
54
|
+
options: facet.rootNodes.map(n => facetEntryToOption(n, false))
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { PropertyValues } from "lit";
|
|
2
|
+
import { ElementDefinitionsMap, FtLitElement, ParametrizedLabels } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { FluidTopicsApi, FtSearchRequest, FtSuggestRequest } from "@fluid-topics/public-api";
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
fluidtopics?: {
|
|
7
|
+
FluidTopicsApi: new (tenantBaseUrl: string, integrationIdentifier: string) => FluidTopicsApi;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export interface FtSearchBarLabels extends ParametrizedLabels {
|
|
12
|
+
clearFilters?: string;
|
|
13
|
+
filtersButton?: string;
|
|
14
|
+
oneFilterEnabled?: string;
|
|
15
|
+
nFiltersEnabled?: string;
|
|
16
|
+
inputPlaceHolder?: string;
|
|
17
|
+
filterInputPlaceHolder?: string;
|
|
18
|
+
clearInputButton?: string;
|
|
19
|
+
clearFilterButton?: string;
|
|
20
|
+
displayMoreFilterValuesButton?: string;
|
|
21
|
+
searchButton?: string;
|
|
22
|
+
noSuggestions?: string;
|
|
23
|
+
contentLocaleSelector?: string;
|
|
24
|
+
removeRecentSearch?: string;
|
|
25
|
+
back?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const DEFAULT_LABELS: FtSearchBarLabels;
|
|
28
|
+
export interface FtSearchBarProperties {
|
|
29
|
+
labels?: FtSearchBarLabels;
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
apiIntegrationIdentifier?: string;
|
|
32
|
+
contentLocale?: string;
|
|
33
|
+
uiLocale?: string;
|
|
34
|
+
displayedFilters?: Array<string>;
|
|
35
|
+
}
|
|
36
|
+
export interface FtSearchBarCssVariables {
|
|
37
|
+
"--ft-search-bar-height"?: string;
|
|
38
|
+
"--ft-search-bar-border-radius"?: string;
|
|
39
|
+
"--ft-search-bar-mobile-open-position"?: string;
|
|
40
|
+
"--ft-search-bar-mobile-open-top"?: string;
|
|
41
|
+
"--ft-search-bar-mobile-open-bottom"?: string;
|
|
42
|
+
"--ft-search-bar-mobile-open-left"?: string;
|
|
43
|
+
"--ft-search-bar-mobile-open-right"?: string;
|
|
44
|
+
"--ft-search-bar-floating-components-z-index"?: string;
|
|
45
|
+
}
|
|
46
|
+
export declare class LaunchSearchEvent extends CustomEvent<FtSearchRequest> {
|
|
47
|
+
constructor(request: FtSearchRequest);
|
|
48
|
+
}
|
|
49
|
+
export declare class SearchStateChangeEvent extends CustomEvent<FtSearchRequest> {
|
|
50
|
+
constructor(request: FtSearchRequest);
|
|
51
|
+
}
|
|
52
|
+
export declare class FtSearchBar extends FtLitElement implements FtSearchBarProperties {
|
|
53
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
54
|
+
protected getStyles(): import("lit").CSSResult[];
|
|
55
|
+
baseUrl: string;
|
|
56
|
+
apiIntegrationIdentifier: string;
|
|
57
|
+
contentLocale?: string;
|
|
58
|
+
private availableContentLocales;
|
|
59
|
+
uiLocale?: string;
|
|
60
|
+
labels: FtSearchBarLabels;
|
|
61
|
+
private labelResolver;
|
|
62
|
+
displayedFilters: Array<string>;
|
|
63
|
+
searchRequestSerializer: (request: FtSearchRequest) => string;
|
|
64
|
+
private searchFilters;
|
|
65
|
+
private sizeCategory;
|
|
66
|
+
private displayFacets;
|
|
67
|
+
private mobileMenuOpen;
|
|
68
|
+
private facets;
|
|
69
|
+
private container?;
|
|
70
|
+
private filtersOpener?;
|
|
71
|
+
private floatingContainer?;
|
|
72
|
+
private scrollingFiltersContainer?;
|
|
73
|
+
private input?;
|
|
74
|
+
private query;
|
|
75
|
+
private suggestions;
|
|
76
|
+
private suggestionsLoaded;
|
|
77
|
+
private recentSearches;
|
|
78
|
+
private scrollToFacet?;
|
|
79
|
+
private firstSuggestion?;
|
|
80
|
+
private focusedSuggestion?;
|
|
81
|
+
private lastSuggestion?;
|
|
82
|
+
private updateFacetsDebouncer;
|
|
83
|
+
private suggestDebouncer;
|
|
84
|
+
private get recentSearchesStorageKey();
|
|
85
|
+
private api?;
|
|
86
|
+
get request(): FtSearchRequest;
|
|
87
|
+
get suggestRequest(): FtSuggestRequest;
|
|
88
|
+
private get hasFacets();
|
|
89
|
+
private get hasLocaleSelector();
|
|
90
|
+
focus(): void;
|
|
91
|
+
clear(): void;
|
|
92
|
+
protected getTemplate(): import("lit-html").TemplateResult<1>;
|
|
93
|
+
private renderDesktopSearchBar;
|
|
94
|
+
private renderSearchBarLeftAction;
|
|
95
|
+
private renderDesktopSearchBarButtons;
|
|
96
|
+
private renderMobileSearchBar;
|
|
97
|
+
private renderMobileSearchBarButtons;
|
|
98
|
+
private renderMobileFacetsActions;
|
|
99
|
+
private renderMobileFacets;
|
|
100
|
+
private renderSuggestions;
|
|
101
|
+
private getIcon;
|
|
102
|
+
private renderDesktopFacetsActions;
|
|
103
|
+
private renderDesktopFacets;
|
|
104
|
+
private renderSelectedFacets;
|
|
105
|
+
protected firstUpdated(props: PropertyValues): Promise<void>;
|
|
106
|
+
protected update(props: PropertyValues): void;
|
|
107
|
+
protected contentAvailableCallback(props: PropertyValues): void;
|
|
108
|
+
private initApi;
|
|
109
|
+
private setApi;
|
|
110
|
+
private facetsLoaded;
|
|
111
|
+
private updateFacets;
|
|
112
|
+
private updateSuggestions;
|
|
113
|
+
private onSearchBarKeyUp;
|
|
114
|
+
private onSearchBarKeyDown;
|
|
115
|
+
private onFloatingContainerKeyUp;
|
|
116
|
+
private setQuery;
|
|
117
|
+
private onSuggestClick;
|
|
118
|
+
private onSuggestKeyUp;
|
|
119
|
+
private onSuggestSelected;
|
|
120
|
+
private launchSearch;
|
|
121
|
+
private saveRecentSearches;
|
|
122
|
+
private closeFloatingContainer;
|
|
123
|
+
connectedCallback(): void;
|
|
124
|
+
disconnectedCallback(): void;
|
|
125
|
+
private updateSize;
|
|
126
|
+
private getLocaleLabel;
|
|
127
|
+
private setFilter;
|
|
128
|
+
private clearFilters;
|
|
129
|
+
private removeRecentSearch;
|
|
130
|
+
private onSuggestKeyDown;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=ft-search-bar.d.ts.map
|