@uniformdev/search 0.0.1 → 0.0.3
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/LICENSE +1 -1
- package/README.md +129 -0
- package/dist/{chunk-ZABEFR2D.mjs → chunk-RMUYFKZO.mjs} +11 -4
- package/dist/chunk-RMUYFKZO.mjs.map +1 -0
- package/dist/client-DOew5kqb.d.mts +99 -0
- package/dist/client-DOew5kqb.d.ts +99 -0
- package/dist/index.d.mts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +66 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -6
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +49 -13
- package/dist/react.d.ts +49 -13
- package/dist/react.js +198 -122
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +184 -127
- package/dist/react.mjs.map +1 -1
- package/package.json +23 -2
- package/dist/chunk-ZABEFR2D.mjs.map +0 -1
- package/dist/client-DrL-8TfY.d.mts +0 -71
- package/dist/client-DrL-8TfY.d.ts +0 -71
package/dist/react.js
CHANGED
|
@@ -21,10 +21,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var react_exports = {};
|
|
22
22
|
__export(react_exports, {
|
|
23
23
|
DOTS: () => DOTS,
|
|
24
|
+
SearchContext: () => SearchContext,
|
|
25
|
+
SearchItemDefaultUrlResolverProvider: () => SearchItemDefaultUrlResolverProvider,
|
|
26
|
+
SearchItemUrlResolverProvider: () => SearchItemUrlResolverProvider,
|
|
24
27
|
SearchProvider: () => SearchProvider,
|
|
28
|
+
createDefaultUrlResolver: () => createDefaultUrlResolver,
|
|
25
29
|
usePagination: () => usePagination,
|
|
26
30
|
useSearch: () => useSearch,
|
|
27
|
-
useSearchPagination: () => useSearchPagination
|
|
31
|
+
useSearchPagination: () => useSearchPagination,
|
|
32
|
+
useUrlResolver: () => useUrlResolver
|
|
28
33
|
});
|
|
29
34
|
module.exports = __toCommonJS(react_exports);
|
|
30
35
|
|
|
@@ -41,7 +46,14 @@ var DEFAULT_PAGE_SIZE = 10;
|
|
|
41
46
|
|
|
42
47
|
// src/utils.ts
|
|
43
48
|
var buildOrderByQuery = (orderBy) => {
|
|
44
|
-
|
|
49
|
+
var _a;
|
|
50
|
+
const field = orderBy.field;
|
|
51
|
+
if (field && typeof field === "object" && "field" in field) {
|
|
52
|
+
const sv = field;
|
|
53
|
+
return `${sv.field}_${sv.direction.toUpperCase()}`;
|
|
54
|
+
}
|
|
55
|
+
if (!field || field === "relevance") return "";
|
|
56
|
+
return `${field}_${(_a = orderBy.direction) != null ? _a : "ASC"}`;
|
|
45
57
|
};
|
|
46
58
|
var getSearchParamsFromUrl = (urlString) => {
|
|
47
59
|
if (!urlString) {
|
|
@@ -61,13 +73,13 @@ var getSearchParamsFromUrl = (urlString) => {
|
|
|
61
73
|
|
|
62
74
|
// src/flattenBlockParams.ts
|
|
63
75
|
function resolveFieldValue(field, locale = "en-us") {
|
|
64
|
-
var _a
|
|
76
|
+
var _a;
|
|
65
77
|
if (!field || typeof field !== "object") return field;
|
|
66
78
|
if (field.type === "$block" && Array.isArray(field.value)) {
|
|
67
79
|
return flattenBlockParams(field.value, locale);
|
|
68
80
|
}
|
|
69
81
|
if (field.locales && typeof field.locales === "object") {
|
|
70
|
-
return (
|
|
82
|
+
return (_a = field.locales[locale]) != null ? _a : field.value;
|
|
71
83
|
}
|
|
72
84
|
return field.value;
|
|
73
85
|
}
|
|
@@ -87,67 +99,71 @@ function flattenBlockParams(items, locale = "en-us") {
|
|
|
87
99
|
|
|
88
100
|
// src/react/SearchProvider.tsx
|
|
89
101
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
90
|
-
var ALL_COLLECTIONS = ["entries", "compositions", "assets"];
|
|
91
102
|
var SearchContext = (0, import_react.createContext)(null);
|
|
92
103
|
var SearchProvider = ({
|
|
93
104
|
children,
|
|
94
105
|
performSearch,
|
|
95
|
-
contentType,
|
|
96
|
-
filterBy: filterByRaw,
|
|
97
106
|
orderBy: orderByRaw,
|
|
98
|
-
|
|
107
|
+
baseFilterString,
|
|
99
108
|
pageSizes: pageSizesRaw,
|
|
100
|
-
|
|
101
|
-
searchDebounceMs = 300
|
|
109
|
+
queryBy,
|
|
110
|
+
searchDebounceMs = 300,
|
|
111
|
+
locale,
|
|
112
|
+
maxFacetValues = 100
|
|
102
113
|
}) => {
|
|
103
|
-
var _a;
|
|
104
|
-
const filterBy = (0, import_react.
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
)
|
|
114
|
+
var _a, _b;
|
|
115
|
+
const [filterBy, setFilterOptions] = (0, import_react.useState)([]);
|
|
116
|
+
const registerFilterOption = (0, import_react.useCallback)((filter) => {
|
|
117
|
+
if (!(filter == null ? void 0 : filter.fieldKey)) return;
|
|
118
|
+
setFilterOptions((prev) => [...prev.filter((f) => f.fieldKey !== filter.fieldKey), filter]);
|
|
119
|
+
}, []);
|
|
120
|
+
const unregisterFilterOption = (0, import_react.useCallback)((fieldKey) => {
|
|
121
|
+
setFilterOptions((prev) => prev.filter((f) => f.fieldKey !== fieldKey));
|
|
122
|
+
}, []);
|
|
123
|
+
const [orderByRegistry, setOrderByRegistry] = (0, import_react.useState)([]);
|
|
124
|
+
const registerOrderBy = (0, import_react.useCallback)((id, raw) => {
|
|
125
|
+
if (!id) return;
|
|
126
|
+
const options = flattenBlockParams(raw);
|
|
127
|
+
setOrderByRegistry((prev) => [...prev.filter((e) => e.id !== id), { id, options }]);
|
|
128
|
+
}, []);
|
|
129
|
+
const unregisterOrderBy = (0, import_react.useCallback)((id) => {
|
|
130
|
+
setOrderByRegistry((prev) => prev.filter((e) => e.id !== id));
|
|
131
|
+
}, []);
|
|
132
|
+
const propOrderByFlat = (0, import_react.useMemo)(() => flattenBlockParams(orderByRaw), [orderByRaw]);
|
|
133
|
+
const lastRegisteredOrderBy = [...orderByRegistry].reverse().find((e) => e.options.length > 0);
|
|
134
|
+
const orderByFlat = lastRegisteredOrderBy ? lastRegisteredOrderBy.options : propOrderByFlat;
|
|
135
|
+
const [pageSizesRegistry, setPageSizesRegistry] = (0, import_react.useState)([]);
|
|
136
|
+
const registerPageSizes = (0, import_react.useCallback)((id, raw) => {
|
|
137
|
+
if (!id) return;
|
|
138
|
+
const sizes = flattenBlockParams(raw);
|
|
139
|
+
setPageSizesRegistry((prev) => [...prev.filter((e) => e.id !== id), { id, sizes }]);
|
|
140
|
+
}, []);
|
|
141
|
+
const unregisterPageSizes = (0, import_react.useCallback)((id) => {
|
|
142
|
+
setPageSizesRegistry((prev) => prev.filter((e) => e.id !== id));
|
|
143
|
+
}, []);
|
|
144
|
+
const propPageSizesFlat = (0, import_react.useMemo)(() => flattenBlockParams(pageSizesRaw), [pageSizesRaw]);
|
|
145
|
+
const lastRegisteredPageSizes = [...pageSizesRegistry].reverse().find((e) => e.sizes.length > 0);
|
|
146
|
+
const pageSizesFlat = lastRegisteredPageSizes ? lastRegisteredPageSizes.sizes : propPageSizesFlat;
|
|
126
147
|
const facetBy = (0, import_react.useMemo)(
|
|
127
|
-
() => filterBy.filter((f) =>
|
|
148
|
+
() => filterBy.filter((f) => f == null ? void 0 : f.fieldKey).map((f) => f.fieldKey).join(","),
|
|
128
149
|
[filterBy]
|
|
129
150
|
);
|
|
130
151
|
const defaultOrderByQuery = (0, import_react.useMemo)(
|
|
131
|
-
() => orderByFlat[0] ? buildOrderByQuery(orderByFlat[0]) :
|
|
152
|
+
() => orderByFlat[0] ? buildOrderByQuery(orderByFlat[0]) : void 0,
|
|
132
153
|
[orderByFlat]
|
|
133
154
|
);
|
|
134
155
|
const orderByOptions = (0, import_react.useMemo)(
|
|
135
156
|
() => orderByFlat.map((o) => ({ title: o.title, value: buildOrderByQuery(o) })),
|
|
136
157
|
[orderByFlat]
|
|
137
158
|
);
|
|
138
|
-
const initPerPage = ((_a = pageSizesFlat[0]) == null ? void 0 :
|
|
139
|
-
const hasFetchedInitial = (0, import_react.useRef)(false);
|
|
159
|
+
const initPerPage = ((_a = pageSizesFlat.find((ps) => ps.default)) == null ? void 0 : _a.size) || ((_b = pageSizesFlat[0]) == null ? void 0 : _b.size) || DEFAULT_PAGE_SIZE;
|
|
140
160
|
const searchDebounceRef = (0, import_react.useRef)(null);
|
|
141
|
-
const
|
|
142
|
-
initCollections || ALL_COLLECTIONS
|
|
143
|
-
);
|
|
161
|
+
const searchRequestIdRef = (0, import_react.useRef)(0);
|
|
144
162
|
const [urlParams, setUrlParams] = (0, import_react.useState)(() => {
|
|
145
163
|
if (typeof window === "undefined") return {};
|
|
146
164
|
return getSearchParamsFromUrl(window.location.href);
|
|
147
165
|
});
|
|
148
|
-
const [searchBoxValue, setSearchBoxValue] = (0, import_react.useState)(
|
|
149
|
-
(urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_QUERY_KEY]) || ""
|
|
150
|
-
);
|
|
166
|
+
const [searchBoxValue, setSearchBoxValue] = (0, import_react.useState)((urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_QUERY_KEY]) || "");
|
|
151
167
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
152
168
|
const [entries, setEntries] = (0, import_react.useState)({
|
|
153
169
|
items: [],
|
|
@@ -157,17 +173,16 @@ var SearchProvider = ({
|
|
|
157
173
|
totalPages: 0
|
|
158
174
|
});
|
|
159
175
|
const [facets, setFacets] = (0, import_react.useState)({});
|
|
160
|
-
const [collectionResults, setCollectionResults] = (0, import_react.useState)({});
|
|
161
176
|
const pathname = (0, import_react.useMemo)(() => {
|
|
162
177
|
if (typeof window === "undefined") return "/";
|
|
163
178
|
return window.location.pathname;
|
|
164
179
|
}, []);
|
|
165
|
-
const page = Number(urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_PAGE_KEY]) - 1
|
|
180
|
+
const page = Number(urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_PAGE_KEY]) - 1 > 0 ? Number(urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_PAGE_KEY]) - 1 : FIRST_PAGE;
|
|
166
181
|
const search = (urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_QUERY_KEY]) || "";
|
|
167
182
|
const perPage = Number(urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_PAGE_SIZE_KEY]) || initPerPage;
|
|
168
183
|
const selectedFilters = (0, import_react.useMemo)(
|
|
169
184
|
() => filterBy.reduce((acc, filter) => {
|
|
170
|
-
const value2 = urlParams == null ? void 0 : urlParams[filter.
|
|
185
|
+
const value2 = urlParams == null ? void 0 : urlParams[filter.fieldKey];
|
|
171
186
|
if (value2) {
|
|
172
187
|
acc[filter.fieldKey] = Array.isArray(value2) ? value2 : [value2];
|
|
173
188
|
}
|
|
@@ -176,10 +191,13 @@ var SearchProvider = ({
|
|
|
176
191
|
[filterBy, urlParams]
|
|
177
192
|
);
|
|
178
193
|
(0, import_react.useEffect)(() => {
|
|
194
|
+
const requestId = ++searchRequestIdRef.current;
|
|
179
195
|
const doFetch = async () => {
|
|
180
|
-
var _a2;
|
|
181
|
-
const
|
|
196
|
+
var _a2, _b2;
|
|
197
|
+
const currentOrderByQuery = (urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_ORDER_BY_KEY]) || defaultOrderByQuery;
|
|
198
|
+
const buildFilters = (excludeField) => Object.entries(selectedFilters).reduce((acc, [fieldKey, values]) => {
|
|
182
199
|
var _a3;
|
|
200
|
+
if (excludeField && fieldKey === excludeField) return acc;
|
|
183
201
|
if (!values || values.length === 0) return acc;
|
|
184
202
|
const filterType = (_a3 = filterBy.find((f) => f.fieldKey === fieldKey)) == null ? void 0 : _a3.type;
|
|
185
203
|
if (filterType === "range") {
|
|
@@ -188,65 +206,69 @@ var SearchProvider = ({
|
|
|
188
206
|
}
|
|
189
207
|
return { ...acc, [`${fieldKey}[in]`]: values };
|
|
190
208
|
}, {});
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
...filterQuery
|
|
195
|
-
};
|
|
196
|
-
if (contentType) {
|
|
197
|
-
filters["contentType[eq]"] = contentType;
|
|
198
|
-
}
|
|
199
|
-
const { results } = await performSearch({
|
|
200
|
-
page,
|
|
201
|
-
perPage,
|
|
202
|
-
filters,
|
|
203
|
-
facetBy,
|
|
204
|
-
search,
|
|
205
|
-
orderBy: currentOrderByQuery,
|
|
206
|
-
collections: selectedCollections
|
|
209
|
+
const selectedFacetFields = Object.keys(selectedFilters).filter((k) => {
|
|
210
|
+
var _a3;
|
|
211
|
+
return ((_a3 = selectedFilters[k]) == null ? void 0 : _a3.length) > 0;
|
|
207
212
|
});
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
213
|
+
const queryByString = (queryBy == null ? void 0 : queryBy.length) ? queryBy.join(",") : void 0;
|
|
214
|
+
const [mainResult, ...disjunctiveResults] = await Promise.all([
|
|
215
|
+
performSearch({
|
|
216
|
+
page,
|
|
217
|
+
perPage,
|
|
218
|
+
filters: buildFilters(),
|
|
219
|
+
baseFilterBy: baseFilterString,
|
|
220
|
+
facetBy,
|
|
221
|
+
queryBy: queryByString,
|
|
222
|
+
search,
|
|
223
|
+
orderBy: currentOrderByQuery,
|
|
224
|
+
locale,
|
|
225
|
+
maxFacetValues
|
|
226
|
+
}),
|
|
227
|
+
...selectedFacetFields.map(
|
|
228
|
+
(field) => performSearch({
|
|
229
|
+
page: 0,
|
|
230
|
+
perPage: 0,
|
|
231
|
+
filters: buildFilters(field),
|
|
232
|
+
baseFilterBy: baseFilterString,
|
|
233
|
+
facetBy: field,
|
|
234
|
+
queryBy: queryByString,
|
|
235
|
+
search,
|
|
236
|
+
orderBy: currentOrderByQuery,
|
|
237
|
+
locale,
|
|
238
|
+
maxFacetValues
|
|
239
|
+
})
|
|
240
|
+
)
|
|
241
|
+
]);
|
|
242
|
+
if (requestId !== searchRequestIdRef.current) return;
|
|
243
|
+
const mergedFacets = { ...(_a2 = mainResult.facets) != null ? _a2 : {} };
|
|
244
|
+
selectedFacetFields.forEach((field, i) => {
|
|
245
|
+
var _a3, _b3;
|
|
246
|
+
const counts = (_b3 = (_a3 = disjunctiveResults[i]) == null ? void 0 : _a3.facets) == null ? void 0 : _b3[field];
|
|
247
|
+
if (counts) mergedFacets[field] = counts;
|
|
228
248
|
});
|
|
249
|
+
setEntries((_b2 = mainResult.data) != null ? _b2 : { items: [], total: 0, page, perPage, totalPages: 0 });
|
|
229
250
|
setFacets(mergedFacets);
|
|
230
251
|
};
|
|
231
252
|
setIsLoading(true);
|
|
232
|
-
doFetch().catch((error) => console.error("
|
|
233
|
-
setIsLoading(false);
|
|
234
|
-
hasFetchedInitial.current = true;
|
|
235
|
-
});
|
|
253
|
+
doFetch().catch((error) => console.error("Search fetch error:", error)).finally(() => setIsLoading(false));
|
|
236
254
|
}, [
|
|
237
|
-
|
|
238
|
-
contentType,
|
|
255
|
+
baseFilterString,
|
|
239
256
|
defaultOrderByQuery,
|
|
240
257
|
facetBy,
|
|
241
258
|
filterBy,
|
|
259
|
+
locale,
|
|
242
260
|
urlParams,
|
|
243
261
|
page,
|
|
244
262
|
perPage,
|
|
245
263
|
performSearch,
|
|
246
264
|
search,
|
|
247
|
-
selectedCollections,
|
|
248
265
|
selectedFilters
|
|
249
266
|
]);
|
|
267
|
+
(0, import_react.useEffect)(() => {
|
|
268
|
+
return () => {
|
|
269
|
+
if (searchDebounceRef.current) clearTimeout(searchDebounceRef.current);
|
|
270
|
+
};
|
|
271
|
+
}, []);
|
|
250
272
|
const updateUrl = (0, import_react.useCallback)(
|
|
251
273
|
(params, { replace = false } = {}) => {
|
|
252
274
|
const qs = params.toString();
|
|
@@ -276,26 +298,15 @@ var SearchProvider = ({
|
|
|
276
298
|
const setSearchQuery = (0, import_react.useCallback)(
|
|
277
299
|
(value2) => {
|
|
278
300
|
setSearchBoxValue(value2);
|
|
279
|
-
if (searchDebounceRef.current)
|
|
280
|
-
clearTimeout(searchDebounceRef.current);
|
|
281
|
-
}
|
|
301
|
+
if (searchDebounceRef.current) clearTimeout(searchDebounceRef.current);
|
|
282
302
|
if (!value2) {
|
|
283
303
|
commitSearchToUrl(value2);
|
|
284
304
|
} else {
|
|
285
|
-
searchDebounceRef.current = setTimeout(() =>
|
|
286
|
-
commitSearchToUrl(value2);
|
|
287
|
-
}, searchDebounceMs);
|
|
305
|
+
searchDebounceRef.current = setTimeout(() => commitSearchToUrl(value2), searchDebounceMs);
|
|
288
306
|
}
|
|
289
307
|
},
|
|
290
308
|
[commitSearchToUrl, searchDebounceMs]
|
|
291
309
|
);
|
|
292
|
-
(0, import_react.useEffect)(() => {
|
|
293
|
-
return () => {
|
|
294
|
-
if (searchDebounceRef.current) {
|
|
295
|
-
clearTimeout(searchDebounceRef.current);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
}, []);
|
|
299
310
|
const setPage = (0, import_react.useCallback)(
|
|
300
311
|
(p) => {
|
|
301
312
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -328,28 +339,22 @@ var SearchProvider = ({
|
|
|
328
339
|
);
|
|
329
340
|
const setSelectedFilters = (0, import_react.useCallback)(
|
|
330
341
|
(nextSelected) => {
|
|
331
|
-
const params = new URLSearchParams();
|
|
342
|
+
const params = new URLSearchParams(window.location.search);
|
|
332
343
|
params.delete(UNIFORM_SEARCH_PAGE_KEY);
|
|
333
|
-
|
|
334
|
-
params.set(UNIFORM_SEARCH_QUERY_KEY, search);
|
|
335
|
-
}
|
|
344
|
+
filterBy.forEach((f) => params.delete(f.fieldKey));
|
|
336
345
|
Object.entries(nextSelected).forEach(([key, value2]) => {
|
|
337
346
|
const filter = filterBy.find((f) => f.fieldKey === key);
|
|
338
347
|
if (!filter) return;
|
|
339
|
-
value2.forEach((v) =>
|
|
340
|
-
params.append(filter.fieldId, v);
|
|
341
|
-
});
|
|
348
|
+
value2.forEach((v) => params.append(key, v));
|
|
342
349
|
});
|
|
343
350
|
updateUrl(params);
|
|
344
351
|
},
|
|
345
|
-
[filterBy,
|
|
352
|
+
[filterBy, updateUrl]
|
|
346
353
|
);
|
|
347
354
|
const clearFilters = (0, import_react.useCallback)(() => {
|
|
348
355
|
setIsLoading(true);
|
|
349
356
|
setSearchBoxValue("");
|
|
350
|
-
if (searchDebounceRef.current)
|
|
351
|
-
clearTimeout(searchDebounceRef.current);
|
|
352
|
-
}
|
|
357
|
+
if (searchDebounceRef.current) clearTimeout(searchDebounceRef.current);
|
|
353
358
|
window.history.pushState({}, "", pathname);
|
|
354
359
|
setUrlParams(getSearchParamsFromUrl(window.location.href));
|
|
355
360
|
}, [pathname]);
|
|
@@ -374,7 +379,6 @@ var SearchProvider = ({
|
|
|
374
379
|
results: entries,
|
|
375
380
|
facets,
|
|
376
381
|
isLoading,
|
|
377
|
-
collectionResults,
|
|
378
382
|
searchBoxValue,
|
|
379
383
|
setSearchQuery,
|
|
380
384
|
page,
|
|
@@ -382,32 +386,42 @@ var SearchProvider = ({
|
|
|
382
386
|
pageSize: perPage,
|
|
383
387
|
setPageSize,
|
|
384
388
|
pageSizes: pageSizesFlat,
|
|
389
|
+
registerPageSizes,
|
|
390
|
+
unregisterPageSizes,
|
|
385
391
|
orderByOptions,
|
|
386
|
-
selectedOrderBy: (urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_ORDER_BY_KEY]) || defaultOrderByQuery,
|
|
392
|
+
selectedOrderBy: (urlParams == null ? void 0 : urlParams[UNIFORM_SEARCH_ORDER_BY_KEY]) || defaultOrderByQuery || "",
|
|
387
393
|
setOrderBy,
|
|
394
|
+
registerOrderBy,
|
|
395
|
+
unregisterOrderBy,
|
|
388
396
|
filterOptions: filterBy,
|
|
397
|
+
setFilterOptions,
|
|
398
|
+
registerFilterOption,
|
|
399
|
+
unregisterFilterOption,
|
|
389
400
|
selectedFilters,
|
|
390
401
|
setSelectedFilters,
|
|
391
402
|
clearFilters,
|
|
392
|
-
selectedCollections,
|
|
393
|
-
setSelectedCollections,
|
|
394
403
|
formatResultsSummary
|
|
395
404
|
}),
|
|
396
405
|
[
|
|
397
406
|
clearFilters,
|
|
398
|
-
collectionResults,
|
|
399
407
|
defaultOrderByQuery,
|
|
400
408
|
entries,
|
|
401
409
|
facets,
|
|
402
410
|
filterBy,
|
|
411
|
+
setFilterOptions,
|
|
412
|
+
registerFilterOption,
|
|
413
|
+
unregisterFilterOption,
|
|
403
414
|
formatResultsSummary,
|
|
404
415
|
isLoading,
|
|
405
416
|
orderByOptions,
|
|
417
|
+
registerOrderBy,
|
|
418
|
+
unregisterOrderBy,
|
|
406
419
|
page,
|
|
407
420
|
pageSizesFlat,
|
|
421
|
+
registerPageSizes,
|
|
422
|
+
unregisterPageSizes,
|
|
408
423
|
perPage,
|
|
409
424
|
searchBoxValue,
|
|
410
|
-
selectedCollections,
|
|
411
425
|
selectedFilters,
|
|
412
426
|
setOrderBy,
|
|
413
427
|
setPage,
|
|
@@ -508,12 +522,74 @@ function useSearchPagination(siblingCount) {
|
|
|
508
522
|
isLoading
|
|
509
523
|
};
|
|
510
524
|
}
|
|
525
|
+
|
|
526
|
+
// src/react/SearchItemUrlResolver.tsx
|
|
527
|
+
var import_react5 = require("react");
|
|
528
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
529
|
+
var NOOP_RESOLVER = () => void 0;
|
|
530
|
+
var UserUrlResolverContext = (0, import_react5.createContext)(null);
|
|
531
|
+
var DefaultUrlResolverContext = (0, import_react5.createContext)(NOOP_RESOLVER);
|
|
532
|
+
var SearchItemUrlResolverProvider = ({
|
|
533
|
+
resolver,
|
|
534
|
+
children
|
|
535
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UserUrlResolverContext.Provider, { value: resolver, children });
|
|
536
|
+
var SearchItemDefaultUrlResolverProvider = ({
|
|
537
|
+
resolver,
|
|
538
|
+
children
|
|
539
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DefaultUrlResolverContext.Provider, { value: resolver, children });
|
|
540
|
+
function useUrlResolver() {
|
|
541
|
+
const user = (0, import_react5.useContext)(UserUrlResolverContext);
|
|
542
|
+
const def = (0, import_react5.useContext)(DefaultUrlResolverContext);
|
|
543
|
+
return user != null ? user : def;
|
|
544
|
+
}
|
|
545
|
+
function resolveField(obj, path) {
|
|
546
|
+
return path.split(".").reduce((current, key) => {
|
|
547
|
+
if (current == null) {
|
|
548
|
+
return void 0;
|
|
549
|
+
}
|
|
550
|
+
if (Array.isArray(current)) {
|
|
551
|
+
current = current[0];
|
|
552
|
+
}
|
|
553
|
+
return current == null ? void 0 : current[key];
|
|
554
|
+
}, obj);
|
|
555
|
+
}
|
|
556
|
+
function createDefaultUrlResolver(configs, options = {}) {
|
|
557
|
+
const { pathsByNodeId = {}, locale } = options;
|
|
558
|
+
return (hit) => {
|
|
559
|
+
var _a;
|
|
560
|
+
const hitSource = typeof hit.source === "string" ? hit.source : "";
|
|
561
|
+
const hitType = typeof hit.type === "string" ? hit.type : "";
|
|
562
|
+
const config = configs.find((c) => c.source === hitSource && c.type === hitType);
|
|
563
|
+
if (config) {
|
|
564
|
+
const template = (_a = config.nodeId ? pathsByNodeId[config.nodeId] : void 0) != null ? _a : config.urlTemplate;
|
|
565
|
+
if (template) {
|
|
566
|
+
return template.replace(/:([a-zA-Z0-9_-]+)/g, (_, token) => {
|
|
567
|
+
var _a2, _b;
|
|
568
|
+
if (token === "locale") return locale != null ? locale : "";
|
|
569
|
+
const fieldKey = (_a2 = config.tokenMapping) == null ? void 0 : _a2[token];
|
|
570
|
+
if (!fieldKey) return "";
|
|
571
|
+
const val = resolveField(hit, fieldKey);
|
|
572
|
+
return Array.isArray(val) ? String((_b = val[0]) != null ? _b : "") : String(val != null ? val : "");
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (hitSource === "composition" && typeof hit.path === "string") {
|
|
577
|
+
return hit.path;
|
|
578
|
+
}
|
|
579
|
+
return void 0;
|
|
580
|
+
};
|
|
581
|
+
}
|
|
511
582
|
// Annotate the CommonJS export names for ESM import in node:
|
|
512
583
|
0 && (module.exports = {
|
|
513
584
|
DOTS,
|
|
585
|
+
SearchContext,
|
|
586
|
+
SearchItemDefaultUrlResolverProvider,
|
|
587
|
+
SearchItemUrlResolverProvider,
|
|
514
588
|
SearchProvider,
|
|
589
|
+
createDefaultUrlResolver,
|
|
515
590
|
usePagination,
|
|
516
591
|
useSearch,
|
|
517
|
-
useSearchPagination
|
|
592
|
+
useSearchPagination,
|
|
593
|
+
useUrlResolver
|
|
518
594
|
});
|
|
519
595
|
//# sourceMappingURL=react.js.map
|