@fluid-topics/ft-wc-utils 1.3.15 → 1.3.17
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FtSearchRequest
|
|
1
|
+
import { FtSearchRequest } from "@fluid-topics/public-api";
|
|
2
2
|
export interface EnrichedFtSearchRequest extends FtSearchRequest {
|
|
3
3
|
otherQueryParams?: Record<string, string>;
|
|
4
4
|
}
|
|
@@ -20,12 +20,11 @@ export declare enum SearchPlaceQueryParams {
|
|
|
20
20
|
export declare function isSearchPlaceQueryParams(param: string): param is SearchPlaceQueryParams;
|
|
21
21
|
export declare class SearchPlaceConverter {
|
|
22
22
|
private readonly baseUrl;
|
|
23
|
-
private readonly predefinedSorts;
|
|
24
23
|
private readonly defaultPerPage;
|
|
25
24
|
private readonly allLanguagesAllowed;
|
|
26
25
|
private readonly defaultContentLocale;
|
|
27
26
|
private readonly scopeMapping;
|
|
28
|
-
constructor(baseUrl: string,
|
|
27
|
+
constructor(baseUrl: string, defaultPerPage?: number, allLanguagesAllowed?: boolean, defaultContentLocale?: string);
|
|
29
28
|
serialize(request: EnrichedFtSearchRequest, searchPage?: string): string;
|
|
30
29
|
serializeToCurrentPageIfPossible(request: EnrichedFtSearchRequest, searchPage?: string): string;
|
|
31
30
|
toURLSearchParams(request: EnrichedFtSearchRequest, omitContentLocaleIfDefault?: boolean): string;
|
|
@@ -32,15 +32,14 @@ export function isSearchPlaceQueryParams(param) {
|
|
|
32
32
|
return SearchPlaceQueryParamsValues.has(param);
|
|
33
33
|
}
|
|
34
34
|
export class SearchPlaceConverter {
|
|
35
|
-
constructor(baseUrl,
|
|
35
|
+
constructor(baseUrl, defaultPerPage = 20, allLanguagesAllowed = false, defaultContentLocale = "en-US") {
|
|
36
36
|
this.baseUrl = baseUrl;
|
|
37
|
-
this.predefinedSorts = predefinedSorts;
|
|
38
37
|
this.defaultPerPage = defaultPerPage;
|
|
39
38
|
this.allLanguagesAllowed = allLanguagesAllowed;
|
|
40
39
|
this.defaultContentLocale = defaultContentLocale;
|
|
41
40
|
this.scopeMapping = {
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
documents: "DOCUMENTS",
|
|
42
|
+
topics: "ALL_TOPICS",
|
|
44
43
|
};
|
|
45
44
|
this.filtersEscapeMapping = [
|
|
46
45
|
["*", "\\*", "[ft-escaped-star-character]"],
|
|
@@ -58,7 +57,7 @@ export class SearchPlaceConverter {
|
|
|
58
57
|
return url.toString();
|
|
59
58
|
}
|
|
60
59
|
toURLSearchParams(request, omitContentLocaleIfDefault = false) {
|
|
61
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l
|
|
60
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
62
61
|
const params = new URLSearchParams();
|
|
63
62
|
if (request.contentLocale) {
|
|
64
63
|
if (!omitContentLocaleIfDefault || request.contentLocale !== this.defaultContentLocale) {
|
|
@@ -72,27 +71,27 @@ export class SearchPlaceConverter {
|
|
|
72
71
|
params.append(SearchPlaceQueryParams.QUERY, request.query);
|
|
73
72
|
}
|
|
74
73
|
// Only extract non-negative valueFilter since they are not supported by URLSearchParams
|
|
75
|
-
const valueFilters = (_c = (_b = request.metadataFilters) === null || _b === void 0 ? void 0 : _b.filter(f => f.valueFilter && !f.valueFilter.negative)) !== null && _c !== void 0 ? _c : [];
|
|
74
|
+
const valueFilters = (_c = (_b = request.metadataFilters) === null || _b === void 0 ? void 0 : _b.filter((f) => f.valueFilter && !f.valueFilter.negative)) !== null && _c !== void 0 ? _c : [];
|
|
76
75
|
if (valueFilters.length > 0) {
|
|
77
|
-
const serializedValues = valueFilters.map(f => {
|
|
76
|
+
const serializedValues = valueFilters.map((f) => {
|
|
78
77
|
var _a, _b;
|
|
79
78
|
const values = ((_b = (_a = f.valueFilter) === null || _a === void 0 ? void 0 : _a.values) !== null && _b !== void 0 ? _b : [])
|
|
80
|
-
.map(value => this.escapeFilters(value))
|
|
81
|
-
.map(value => quote(unquote(value)))
|
|
79
|
+
.map((value) => this.escapeFilters(value))
|
|
80
|
+
.map((value) => quote(unquote(value)))
|
|
82
81
|
.join("_");
|
|
83
82
|
return `${f.key}~${values}`;
|
|
84
83
|
}).join("*");
|
|
85
84
|
params.append(SearchPlaceQueryParams.VALUE_FILTERS, serializedValues);
|
|
86
85
|
}
|
|
87
|
-
const dateFilters = (_e = (_d = request.metadataFilters) === null || _d === void 0 ? void 0 : _d.filter(f => f.dateFilter)) !== null && _e !== void 0 ? _e : [];
|
|
86
|
+
const dateFilters = (_e = (_d = request.metadataFilters) === null || _d === void 0 ? void 0 : _d.filter((f) => f.dateFilter)) !== null && _e !== void 0 ? _e : [];
|
|
88
87
|
if (dateFilters.length > 0) {
|
|
89
|
-
const serializedDates = dateFilters.map(f => { var _a; return `${f.key}~${(_a = f.dateFilter) === null || _a === void 0 ? void 0 : _a.type.toLowerCase()}`; })
|
|
88
|
+
const serializedDates = dateFilters.map((f) => { var _a; return `${f.key}~${(_a = f.dateFilter) === null || _a === void 0 ? void 0 : _a.type.toLowerCase()}`; })
|
|
90
89
|
.join("*");
|
|
91
90
|
params.append(SearchPlaceQueryParams.DATE_FILTERS, serializedDates);
|
|
92
91
|
}
|
|
93
|
-
const rangeFilters = (_g = (_f = request.metadataFilters) === null || _f === void 0 ? void 0 : _f.filter(f => f.rangeFilter)) !== null && _g !== void 0 ? _g : [];
|
|
92
|
+
const rangeFilters = (_g = (_f = request.metadataFilters) === null || _f === void 0 ? void 0 : _f.filter((f) => f.rangeFilter)) !== null && _g !== void 0 ? _g : [];
|
|
94
93
|
if (rangeFilters.length > 0) {
|
|
95
|
-
const serializedRanges = rangeFilters.map(f => { var _a, _b; return `${f.key}~${(_a = f.rangeFilter) === null || _a === void 0 ? void 0 : _a.from}_${(_b = f.rangeFilter) === null || _b === void 0 ? void 0 : _b.to}`; })
|
|
94
|
+
const serializedRanges = rangeFilters.map((f) => { var _a, _b; return `${f.key}~${(_a = f.rangeFilter) === null || _a === void 0 ? void 0 : _a.from}_${(_b = f.rangeFilter) === null || _b === void 0 ? void 0 : _b.to}`; })
|
|
96
95
|
.join("*");
|
|
97
96
|
params.append(SearchPlaceQueryParams.RANGE_FILTERS, serializedRanges);
|
|
98
97
|
}
|
|
@@ -102,13 +101,13 @@ export class SearchPlaceConverter {
|
|
|
102
101
|
if (request.scope && request.scope !== "DEFAULT") {
|
|
103
102
|
params.append(SearchPlaceQueryParams.SCOPE, request.scope.toLowerCase());
|
|
104
103
|
}
|
|
105
|
-
if (
|
|
106
|
-
params.append(SearchPlaceQueryParams.SORT,
|
|
104
|
+
if (request.sortId != undefined) {
|
|
105
|
+
params.append(SearchPlaceQueryParams.SORT, request.sortId);
|
|
107
106
|
}
|
|
108
|
-
if (((
|
|
107
|
+
if (((_h = request.paging) === null || _h === void 0 ? void 0 : _h.perPage) && ((_k = (_j = request.paging) === null || _j === void 0 ? void 0 : _j.perPage) !== null && _k !== void 0 ? _k : this.defaultPerPage) != this.defaultPerPage) {
|
|
109
108
|
params.append(SearchPlaceQueryParams.PER_PAGE, String(request.paging.perPage));
|
|
110
109
|
}
|
|
111
|
-
const otherQueryParams = (
|
|
110
|
+
const otherQueryParams = (_l = request.otherQueryParams) !== null && _l !== void 0 ? _l : {};
|
|
112
111
|
for (const key in otherQueryParams) {
|
|
113
112
|
params.append(key, otherQueryParams[key]);
|
|
114
113
|
}
|
|
@@ -134,7 +133,7 @@ export class SearchPlaceConverter {
|
|
|
134
133
|
return maybeScopeFromPath == null ? fromParams : { ...fromParams, scope: (_a = this.scopeMapping[maybeScopeFromPath]) !== null && _a !== void 0 ? _a : fromParams.scope };
|
|
135
134
|
}
|
|
136
135
|
fromURLSearchParams(strParams) {
|
|
137
|
-
var _a, _b, _c, _d, _e, _f
|
|
136
|
+
var _a, _b, _c, _d, _e, _f;
|
|
138
137
|
try {
|
|
139
138
|
strParams = decodeURI(strParams).replace(/%23/g, "#");
|
|
140
139
|
}
|
|
@@ -144,7 +143,7 @@ export class SearchPlaceConverter {
|
|
|
144
143
|
const params = new URLSearchParams(strParams);
|
|
145
144
|
const contentLocale = params.get(SearchPlaceQueryParams.LOCALE) === "all" ? undefined : params.get(SearchPlaceQueryParams.LOCALE);
|
|
146
145
|
const virtualField = ((_a = params.get(SearchPlaceQueryParams.VIRTUAL_FIELD)) !== null && _a !== void 0 ? _a : "EVERYWHERE").toUpperCase();
|
|
147
|
-
const
|
|
146
|
+
const sortId = (_b = params.get(SearchPlaceQueryParams.SORT)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
148
147
|
const scope = (_c = params.get(SearchPlaceQueryParams.SCOPE)) !== null && _c !== void 0 ? _c : "default";
|
|
149
148
|
const perPage = +((_d = params.get(SearchPlaceQueryParams.PER_PAGE)) !== null && _d !== void 0 ? _d : this.defaultPerPage);
|
|
150
149
|
const otherQueryParams = {};
|
|
@@ -158,7 +157,7 @@ export class SearchPlaceConverter {
|
|
|
158
157
|
query: (_e = params.get(SearchPlaceQueryParams.QUERY)) !== null && _e !== void 0 ? _e : "",
|
|
159
158
|
scope: (_f = this.scopeMapping[scope]) !== null && _f !== void 0 ? _f : "DEFAULT",
|
|
160
159
|
virtualField: isFtVirtualField(virtualField) ? virtualField : "EVERYWHERE",
|
|
161
|
-
|
|
160
|
+
sortId: sortId,
|
|
162
161
|
metadataFilters: this.parseCompatFilters(params),
|
|
163
162
|
facets: [],
|
|
164
163
|
paging: {
|
|
@@ -190,19 +189,19 @@ export class SearchPlaceConverter {
|
|
|
190
189
|
splitUnknownFilter(s) {
|
|
191
190
|
return this.superEscapeFilters(s)
|
|
192
191
|
.split("*")
|
|
193
|
-
.map(oneFilter => oneFilter.split("~"));
|
|
192
|
+
.map((oneFilter) => oneFilter.split("~"));
|
|
194
193
|
}
|
|
195
194
|
parseValueFilters(s) {
|
|
196
195
|
if (s.length === 0) {
|
|
197
196
|
return [];
|
|
198
197
|
}
|
|
199
198
|
return this.splitUnknownFilter(s)
|
|
200
|
-
.map(oneFilterSplit => ({
|
|
199
|
+
.map((oneFilterSplit) => ({
|
|
201
200
|
key: oneFilterSplit[0],
|
|
202
201
|
valueFilter: {
|
|
203
202
|
values: oneFilterSplit[1].split("_")
|
|
204
203
|
.map(unquote)
|
|
205
|
-
.map(value => this.unescapeFilterValue(value)),
|
|
204
|
+
.map((value) => this.unescapeFilterValue(value)),
|
|
206
205
|
negative: false,
|
|
207
206
|
},
|
|
208
207
|
}));
|
|
@@ -212,7 +211,7 @@ export class SearchPlaceConverter {
|
|
|
212
211
|
return [];
|
|
213
212
|
}
|
|
214
213
|
return this.splitUnknownFilter(s)
|
|
215
|
-
.map(oneFilterSplit => ({
|
|
214
|
+
.map((oneFilterSplit) => ({
|
|
216
215
|
key: oneFilterSplit[0],
|
|
217
216
|
dateFilter: {
|
|
218
217
|
type: FtDateFilterType[oneFilterSplit[1].toUpperCase()],
|
|
@@ -224,7 +223,7 @@ export class SearchPlaceConverter {
|
|
|
224
223
|
return [];
|
|
225
224
|
}
|
|
226
225
|
return this.splitUnknownFilter(s)
|
|
227
|
-
.map(oneFilterSplit => ({
|
|
226
|
+
.map((oneFilterSplit) => ({
|
|
228
227
|
key: oneFilterSplit[0],
|
|
229
228
|
rangeFilter: {
|
|
230
229
|
from: oneFilterSplit[1].split("_")[0],
|
|
@@ -54,10 +54,10 @@ export const designSystemVariables = {
|
|
|
54
54
|
elevation12: FtCssVariableFactory.create("--ft-elevation-12", "", "UNKNOWN", "0px 22px 40px 0px rgba(0, 0, 0, 0.06), 0px 12px 23px 0px rgba(0, 0, 0, 0.14), 0px 10px 11px 0px rgba(0, 0, 0, 0.06)"),
|
|
55
55
|
elevation16: FtCssVariableFactory.create("--ft-elevation-16", "", "UNKNOWN", "0px 28px 52px 0px rgba(0, 0, 0, 0.06), 0px 16px 29px 0px rgba(0, 0, 0, 0.14), 0px 14px 15px 0px rgba(0, 0, 0, 0.06)"),
|
|
56
56
|
elevation24: FtCssVariableFactory.create("--ft-elevation-24", "", "UNKNOWN", "0px 40px 76px 0px rgba(0, 0, 0, 0.06), 0px 24px 41px 0px rgba(0, 0, 0, 0.14), 0px 22px 23px 0px rgba(0, 0, 0, 0.06)"),
|
|
57
|
-
borderRadiusS: FtCssVariableFactory.create("--ft-border-radius-
|
|
58
|
-
borderRadiusM: FtCssVariableFactory.create("--ft-border-radius-
|
|
59
|
-
borderRadiusL: FtCssVariableFactory.create("--ft-border-radius-
|
|
60
|
-
borderRadiusXL: FtCssVariableFactory.create("--ft-border-radius-
|
|
57
|
+
borderRadiusS: FtCssVariableFactory.create("--ft-border-radius-s", "", "SIZE", "4px"),
|
|
58
|
+
borderRadiusM: FtCssVariableFactory.create("--ft-border-radius-m", "", "SIZE", "8px"),
|
|
59
|
+
borderRadiusL: FtCssVariableFactory.create("--ft-border-radius-l", "", "SIZE", "12px"),
|
|
60
|
+
borderRadiusXL: FtCssVariableFactory.create("--ft-border-radius-xl", "", "SIZE", "16px"),
|
|
61
61
|
titleFont: FtCssVariableFactory.create("--ft-title-font", "", "UNKNOWN", "Ubuntu, system-ui, sans-serif"),
|
|
62
62
|
contentFont: FtCssVariableFactory.create("--ft-content-font", "", "UNKNOWN", "'Open Sans', system-ui, sans-serif"),
|
|
63
63
|
transitionDuration: FtCssVariableFactory.create("--ft-transition-duration", "", "UNKNOWN", "250ms"),
|