@usereactify/search 4.4.1 → 5.0.0-beta.2

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/package.json +8 -9
  3. package/dist/src/components/Example/ExampleFilterList.d.ts +4 -0
  4. package/dist/src/components/Example/ExampleFilterList.js +19 -0
  5. package/dist/src/components/Example/ExampleFilterRange.d.ts +4 -0
  6. package/dist/src/components/Example/ExampleFilterRange.js +21 -0
  7. package/dist/src/components/Example/ExampleFilterSlider.d.ts +4 -0
  8. package/dist/src/components/Example/ExampleFilterSlider.js +20 -0
  9. package/dist/src/components/Example/ExampleFilterStack.d.ts +4 -0
  10. package/dist/src/components/Example/ExampleFilterStack.js +12 -0
  11. package/dist/src/components/Example/ExampleResultCardCallout.d.ts +4 -0
  12. package/dist/src/components/Example/ExampleResultCardCallout.js +21 -0
  13. package/dist/src/components/Example/ExampleResultCardProduct.d.ts +4 -0
  14. package/dist/src/components/Example/ExampleResultCardProduct.js +18 -0
  15. package/dist/src/components/Example/ExampleResultPaginationLoadMore.d.ts +4 -0
  16. package/dist/src/components/Example/ExampleResultPaginationLoadMore.js +11 -0
  17. package/dist/src/components/Example/ExampleResultPaginationNextPrev.d.ts +4 -0
  18. package/dist/src/components/Example/ExampleResultPaginationNextPrev.js +13 -0
  19. package/dist/src/components/Example/ExampleResultPaginationNumbered.d.ts +4 -0
  20. package/dist/src/components/Example/ExampleResultPaginationNumbered.js +26 -0
  21. package/dist/src/components/Example/ExampleSortby.d.ts +4 -0
  22. package/dist/src/components/Example/ExampleSortby.js +12 -0
  23. package/dist/src/components/Example/index.d.ts +10 -0
  24. package/dist/src/components/Example/index.js +22 -0
  25. package/dist/src/components/Filter/Filter.d.ts +20 -0
  26. package/dist/src/components/Filter/Filter.js +89 -0
  27. package/dist/src/components/Filter/FilterStack.d.ts +7 -0
  28. package/dist/src/components/Filter/FilterStack.js +16 -0
  29. package/dist/src/{filter → components/Filter}/index.d.ts +0 -1
  30. package/dist/src/{filter → components/Filter}/index.js +0 -1
  31. package/dist/src/components/ReactifySearchBase/ReactifySearchBase.d.ts +42 -0
  32. package/dist/src/components/ReactifySearchBase/ReactifySearchBase.js +140 -0
  33. package/dist/src/components/ReactifySearchBase/index.d.ts +1 -0
  34. package/dist/src/components/ReactifySearchBase/index.js +13 -0
  35. package/dist/src/components/Result/ResultCardCallout.d.ts +12 -0
  36. package/dist/src/{result → components/Result}/ResultCardCallout.js +15 -22
  37. package/dist/src/components/Result/ResultCardProduct.d.ts +13 -0
  38. package/dist/src/{result/ResultCard.js → components/Result/ResultCardProduct.js} +19 -22
  39. package/dist/src/components/Result/ResultPaginationLoadMore.d.ts +7 -0
  40. package/dist/src/components/Result/ResultPaginationLoadMore.js +16 -0
  41. package/dist/src/components/Result/ResultPaginationNextPrev.d.ts +7 -0
  42. package/dist/src/components/Result/ResultPaginationNextPrev.js +16 -0
  43. package/dist/src/components/Result/ResultPaginationNumbered.d.ts +7 -0
  44. package/dist/src/components/Result/ResultPaginationNumbered.js +19 -0
  45. package/dist/src/components/Result/ResultStack.d.ts +40 -0
  46. package/dist/src/components/Result/ResultStack.js +107 -0
  47. package/dist/src/components/Result/ResultStateProvider.d.ts +6 -0
  48. package/dist/src/{result → components/Result}/ResultStateProvider.js +0 -0
  49. package/dist/src/components/Result/index.d.ts +7 -0
  50. package/dist/src/{result → components/Result}/index.js +5 -4
  51. package/dist/src/components/Search/SearchInput.d.ts +8 -0
  52. package/dist/src/{search → components/Search}/SearchInput.js +2 -2
  53. package/dist/src/{search → components/Search}/index.d.ts +0 -0
  54. package/dist/src/{search → components/Search}/index.js +0 -0
  55. package/dist/src/{sensor → components/Sensor}/SensorCollection.d.ts +0 -0
  56. package/dist/src/{sensor → components/Sensor}/SensorCollection.js +8 -5
  57. package/dist/src/{sensor → components/Sensor}/SensorInventoryAvailable.d.ts +0 -0
  58. package/dist/src/{sensor → components/Sensor}/SensorInventoryAvailable.js +1 -1
  59. package/dist/src/{sensor → components/Sensor}/SensorPublished.d.ts +0 -0
  60. package/dist/src/{sensor → components/Sensor}/SensorPublished.js +0 -0
  61. package/dist/src/{sensor → components/Sensor}/SensorSearch.d.ts +0 -0
  62. package/dist/src/{sensor → components/Sensor}/SensorSearch.js +3 -3
  63. package/dist/src/{sensor → components/Sensor}/SensorSort.d.ts +0 -0
  64. package/dist/src/{sensor → components/Sensor}/SensorSort.js +4 -5
  65. package/dist/src/{sensor → components/Sensor}/SensorSortScore.d.ts +0 -0
  66. package/dist/src/{sensor → components/Sensor}/SensorSortScore.js +0 -0
  67. package/dist/src/components/Sensor/SensorStack.d.ts +3 -0
  68. package/dist/src/{sensor → components/Sensor}/SensorStack.js +3 -3
  69. package/dist/src/{sensor → components/Sensor}/index.d.ts +0 -0
  70. package/dist/src/{sensor → components/Sensor}/index.js +0 -0
  71. package/dist/src/components/Sortby/Sortby.d.ts +7 -0
  72. package/dist/src/components/Sortby/Sortby.js +16 -0
  73. package/dist/src/components/Sortby/index.d.ts +1 -0
  74. package/dist/src/components/Sortby/index.js +13 -0
  75. package/dist/src/{utility → components/Utility}/UtilityAuthenticatedReactiveBase.d.ts +0 -0
  76. package/dist/src/{utility → components/Utility}/UtilityAuthenticatedReactiveBase.js +2 -2
  77. package/dist/src/components/Utility/index.d.ts +1 -0
  78. package/dist/src/components/Utility/index.js +13 -0
  79. package/dist/src/components/index.d.ts +8 -0
  80. package/dist/src/components/index.js +20 -0
  81. package/dist/src/hooks/index.d.ts +5 -5
  82. package/dist/src/hooks/index.js +5 -5
  83. package/dist/src/hooks/reactivesearch/index.d.ts +4 -1
  84. package/dist/src/hooks/reactivesearch/index.js +4 -1
  85. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.d.ts +1 -1
  86. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js +7 -7
  87. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +5 -7
  88. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js +29 -30
  89. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.d.ts +9 -4
  90. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js +9 -94
  91. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.d.ts +70 -0
  92. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js +21 -0
  93. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.d.ts +67 -0
  94. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js +105 -0
  95. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.d.ts +68 -0
  96. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js +21 -0
  97. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +8 -8
  98. package/dist/src/hooks/reactivesearch/{useReactiveResultListProps.d.ts → useReactiveResultStackProps.d.ts} +2 -4
  99. package/dist/src/hooks/reactivesearch/{useReactiveResultListProps.js → useReactiveResultStackProps.js} +7 -8
  100. package/dist/src/hooks/useAnalytics.js +4 -4
  101. package/dist/src/hooks/useConfig.d.ts +4 -1
  102. package/dist/src/hooks/useConfig.js +77 -2
  103. package/dist/src/hooks/useCuration.d.ts +2 -1
  104. package/dist/src/hooks/useCuration.js +48 -2
  105. package/dist/src/hooks/useFilterListProps.d.ts +4 -14
  106. package/dist/src/hooks/useFilterStack.d.ts +2 -1
  107. package/dist/src/hooks/useFilterStack.js +42 -2
  108. package/dist/src/hooks/useFilters.d.ts +4 -1
  109. package/dist/src/hooks/useFilters.js +10 -5
  110. package/dist/src/hooks/usePagination.d.ts +14 -0
  111. package/dist/src/hooks/{usePages.js → usePagination.js} +30 -30
  112. package/dist/src/hooks/usePaginationLoadMore.d.ts +15 -0
  113. package/dist/src/hooks/usePaginationLoadMore.js +37 -0
  114. package/dist/src/hooks/useProductPrice.d.ts +3 -5
  115. package/dist/src/hooks/useProductPrice.js +42 -40
  116. package/dist/src/hooks/useReactifySearchContext.d.ts +78 -0
  117. package/dist/src/hooks/useReactifySearchContext.js +10 -0
  118. package/dist/src/hooks/useSearch.d.ts +4 -4
  119. package/dist/src/hooks/useSearch.js +28 -8
  120. package/dist/src/hooks/useSortby.d.ts +6 -0
  121. package/dist/src/hooks/useSortby.js +41 -0
  122. package/dist/src/index.d.ts +2 -8
  123. package/dist/src/index.js +2 -8
  124. package/dist/src/types/config.d.ts +1 -0
  125. package/dist/src/types/index.d.ts +3 -0
  126. package/dist/src/types/index.js +15 -0
  127. package/package.json +8 -9
  128. package/dist/src/filter/Filter.d.ts +0 -12
  129. package/dist/src/filter/Filter.js +0 -71
  130. package/dist/src/filter/FilterList.d.ts +0 -4
  131. package/dist/src/filter/FilterList.js +0 -15
  132. package/dist/src/filter/FilterStack.d.ts +0 -11
  133. package/dist/src/filter/FilterStack.js +0 -25
  134. package/dist/src/hooks/useCollection.d.ts +0 -1
  135. package/dist/src/hooks/useCollection.js +0 -6
  136. package/dist/src/hooks/useLiveConfig.d.ts +0 -4
  137. package/dist/src/hooks/useLiveConfig.js +0 -74
  138. package/dist/src/hooks/usePages.d.ts +0 -10
  139. package/dist/src/hooks/useSort.d.ts +0 -5
  140. package/dist/src/hooks/useSort.js +0 -24
  141. package/dist/src/provider.d.ts +0 -78
  142. package/dist/src/provider.js +0 -287
  143. package/dist/src/result/ResultCard.d.ts +0 -14
  144. package/dist/src/result/ResultCardCallout.d.ts +0 -13
  145. package/dist/src/result/ResultList.d.ts +0 -34
  146. package/dist/src/result/ResultList.js +0 -93
  147. package/dist/src/result/ResultLoadMoreButton.d.ts +0 -10
  148. package/dist/src/result/ResultLoadMoreButton.js +0 -61
  149. package/dist/src/result/ResultPagination.d.ts +0 -10
  150. package/dist/src/result/ResultPagination.js +0 -60
  151. package/dist/src/result/ResultPaginationNextPrev.d.ts +0 -8
  152. package/dist/src/result/ResultPaginationNextPrev.js +0 -30
  153. package/dist/src/result/ResultStateProvider.d.ts +0 -7
  154. package/dist/src/result/index.d.ts +0 -6
  155. package/dist/src/search/SearchInput.d.ts +0 -9
  156. package/dist/src/sensor/SensorStack.d.ts +0 -2
@@ -1,287 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __rest = (this && this.__rest) || function (s, e) {
22
- var t = {};
23
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
- t[p] = s[p];
25
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
- t[p[i]] = s[p[i]];
29
- }
30
- return t;
31
- };
32
- var __importDefault = (this && this.__importDefault) || function (mod) {
33
- return (mod && mod.__esModule) ? mod : { "default": mod };
34
- };
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.useContext = exports.ConfiguredProvider = exports.Provider = void 0;
37
- const react_1 = __importDefault(require("react"));
38
- const Sentry = __importStar(require("@sentry/react"));
39
- const hooks_1 = require("./hooks");
40
- const UtilityAuthenticatedReactiveBase_1 = require("./utility/UtilityAuthenticatedReactiveBase");
41
- const debug = require("debug")("reactify-search:Provider");
42
- const Context = react_1.default.createContext(undefined);
43
- const defaultCredentials = {
44
- username: "guest",
45
- password: "password",
46
- endpoint: "https://api.search.reactify.app",
47
- };
48
- Sentry.init({
49
- dsn: "https://f591e13196ad4d6bbcd8abbeb2e023db@o1280055.ingest.sentry.io/6482743",
50
- });
51
- const Provider = (_a) => {
52
- var { renderBooting } = _a, props = __rest(_a, ["renderBooting"]);
53
- const { config } = (0, hooks_1.useLiveConfig)(props.shopifyPermanentDomain, props.configId);
54
- if (!config) {
55
- if (renderBooting)
56
- return renderBooting();
57
- return null;
58
- }
59
- return (react_1.default.createElement(Sentry.ErrorBoundary, { fallback: react_1.default.createElement("p", null, "An error has occurred"), beforeCapture: (scope) => {
60
- scope.setTag("index", props.index);
61
- scope.setTag("shop", props.shopifyPermanentDomain);
62
- if (!!props.collection)
63
- scope.setTag("collection", props.collection.handle);
64
- if (!!props.filterStackHandle)
65
- scope.setTag("filter", props.filterStackHandle);
66
- if (!!props.instantSearch)
67
- scope.setTag("search", true);
68
- } },
69
- react_1.default.createElement(exports.ConfiguredProvider, Object.assign({}, props, { config: config }))));
70
- };
71
- exports.Provider = Provider;
72
- const ConfiguredProvider = (props) => {
73
- var _a, _b;
74
- const { index, config, children, collection, instantSearch, filterStackHandle, noReactiveBase, shopifyPermanentDomain, additionalComponentHandles, onRedirect, } = props;
75
- const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : defaultCredentials;
76
- const theme = (_b = props.theme) !== null && _b !== void 0 ? _b : {
77
- typography: {
78
- fontFamily: "inherit",
79
- fontSize: "inherit",
80
- },
81
- };
82
- react_1.default.useEffect(() => {
83
- debug("props", props);
84
- }, [props]);
85
- const searchQueryFromURL = react_1.default.useMemo(() => {
86
- var _a;
87
- if (typeof window === "undefined")
88
- return undefined;
89
- const urlParams = new URLSearchParams(window.location.search);
90
- return (_a = urlParams.get("q")) !== null && _a !== void 0 ? _a : undefined;
91
- }, [window.location.search]);
92
- const searchSortFromURL = react_1.default.useMemo(() => {
93
- var _a;
94
- if (typeof window === "undefined")
95
- return undefined;
96
- const urlParams = new URLSearchParams(window.location.search);
97
- return (_a = urlParams.get("sort")) !== null && _a !== void 0 ? _a : undefined;
98
- }, [window.location.search]);
99
- const [searchQuery, setSearchQuery] = react_1.default.useState(searchQueryFromURL);
100
- const { sortOption, sortOptions, setSortOption } = useSortState(config, collection);
101
- react_1.default.useEffect(() => {
102
- if (searchQueryFromURL && searchQuery !== searchQueryFromURL)
103
- setSearchQuery(searchQueryFromURL);
104
- }, [searchQueryFromURL]);
105
- react_1.default.useEffect(() => {
106
- if (searchSortFromURL && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.handle) !== searchSortFromURL) {
107
- setSortOption(searchSortFromURL, true);
108
- }
109
- }, [searchSortFromURL]);
110
- react_1.default.useEffect(() => {
111
- if (window.location.search === "" && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.handle)) {
112
- setSortOption(sortOption.handle, true);
113
- }
114
- }, [window.location.href]);
115
- const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
116
- const submitSearch = react_1.default.useCallback((localSearchQuery) => {
117
- const actualSearchQuery = localSearchQuery !== null && localSearchQuery !== void 0 ? localSearchQuery : searchQuery;
118
- if (!actualSearchQuery)
119
- return;
120
- const redirect = config.redirects.find((redirect) => redirect.query.trim().toLowerCase() ===
121
- actualSearchQuery.trim().toLowerCase());
122
- setShowInstantSearchResults(false);
123
- if (onRedirect) {
124
- onRedirect(redirect ? "redirect" : "search", redirect ? redirect.url : `/search?q=${actualSearchQuery}`);
125
- }
126
- else if (redirect) {
127
- window.location.href = redirect.url;
128
- }
129
- else {
130
- window.location.href = `/search?q=${actualSearchQuery}`;
131
- }
132
- }, [searchQuery]);
133
- // do not attempt to resolve a filter stack if in instantSearch mode
134
- const filterStack = instantSearch
135
- ? undefined
136
- : useFilterStack(config, collection, filterStackHandle);
137
- const curation = useCuration(config, collection, searchQuery);
138
- const contextValue = react_1.default.useMemo(() => ({
139
- index,
140
- config,
141
- shopifyPermanentDomain,
142
- collection,
143
- credentials,
144
- searchQuery,
145
- filterStack,
146
- sortOption,
147
- sortOptions,
148
- onRedirect,
149
- submitSearch,
150
- setSortOption,
151
- setSearchQuery,
152
- setShowInstantSearchResults,
153
- theme,
154
- curation,
155
- additionalComponentHandles,
156
- instantSearch: !!instantSearch,
157
- showInstantSearchResults: !!showInstantSearchResults && !!searchQuery,
158
- }), [
159
- index,
160
- config,
161
- curation,
162
- shopifyPermanentDomain,
163
- collection,
164
- credentials,
165
- searchQuery,
166
- filterStack,
167
- sortOption,
168
- sortOptions,
169
- onRedirect,
170
- submitSearch,
171
- instantSearch,
172
- additionalComponentHandles,
173
- showInstantSearchResults,
174
- theme,
175
- ]);
176
- react_1.default.useEffect(() => {
177
- debug("contextValue", contextValue);
178
- }, [contextValue]);
179
- if (noReactiveBase) {
180
- return react_1.default.createElement(Context.Provider, { value: contextValue }, children);
181
- }
182
- return (react_1.default.createElement(Context.Provider, { value: contextValue },
183
- react_1.default.createElement(UtilityAuthenticatedReactiveBase_1.UtilityAuthenticatedReactiveBase, null, children)));
184
- };
185
- exports.ConfiguredProvider = ConfiguredProvider;
186
- const useContext = () => react_1.default.useContext(Context);
187
- exports.useContext = useContext;
188
- const useSortState = (config, collection) => {
189
- var _a;
190
- const sortOptions = react_1.default.useMemo(() => {
191
- const type = !!collection ? "collection" : "search";
192
- return config.sort
193
- .sort((a, b) => `${a.position}`.localeCompare(`${b.position}`))
194
- .filter(({ visibility }) => ["all", type].includes(visibility));
195
- }, [config, collection]);
196
- const [sortOptionState, setSortOptionState] = react_1.default.useState((_a = sortOptions[0]) === null || _a === void 0 ? void 0 : _a.handle);
197
- const sortOption = react_1.default.useMemo(() => sortOptions.find(({ handle }) => handle === sortOptionState) ||
198
- sortOptions[0], [sortOptions, sortOptionState]);
199
- const setSortOption = react_1.default.useCallback((sortOptionHandle, ignoreHistoryState = false) => {
200
- setSortOptionState(sortOptionHandle);
201
- if (!ignoreHistoryState) {
202
- const url = new URL(window.location.href);
203
- url.searchParams.has("sort")
204
- ? url.searchParams.set("sort", sortOptionHandle)
205
- : url.searchParams.append("sort", sortOptionHandle);
206
- window.history.pushState({}, "", url.toString());
207
- }
208
- }, [window.location.href]);
209
- return react_1.default.useMemo(() => ({ sortOptions, sortOption, setSortOption }), [sortOption, sortOptions, setSortOption]);
210
- };
211
- // resolve the "filter" in use for this view
212
- // Reactify Search confusingly refers to the entire list of filters as a "filter"
213
- // and each filter within that list is called a "Filter Option"
214
- // @todo we need a better name for the overall page like "Filter Stack" or something,
215
- // each block is then called a filter so like Size would be a "Filter" and then each
216
- // value within it is a "Filter Option"
217
- const useFilterStack = (config, collection, filterStackHandle) => react_1.default.useMemo(() => {
218
- const type = !!collection ? "collection" : "search";
219
- // select filters by type
220
- const matchingFilterStacks = config.filters.filter((filter) => filter.type === type);
221
- // select filter stack by handle if provided
222
- if (filterStackHandle) {
223
- const matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStackHandle === filterStack.handle);
224
- if (matchingFilterStack) {
225
- return matchingFilterStack;
226
- }
227
- }
228
- // select filter stack by collection if provided
229
- if (collection === null || collection === void 0 ? void 0 : collection.handle) {
230
- const matchingFilterStack = matchingFilterStacks.find((filterStack) => { var _a; return (_a = filterStack.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
231
- if (matchingFilterStack) {
232
- return matchingFilterStack;
233
- }
234
- }
235
- // select filter with "default" handle
236
- let matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStack.handle === "default");
237
- if (matchingFilterStack) {
238
- return matchingFilterStack;
239
- }
240
- // select any filter with "default" handle
241
- matchingFilterStack = config.filters.find((filterStack) => filterStack.handle === "default");
242
- if (matchingFilterStack) {
243
- return matchingFilterStack;
244
- }
245
- // select any available filter as a last resort
246
- matchingFilterStack = config.filters[0];
247
- return matchingFilterStack;
248
- }, [config, collection]);
249
- const useCuration = (config, collection, searchQuery) => react_1.default.useMemo(() => {
250
- debug("resolveCuration.start", { config, collection, searchQuery });
251
- const type = collection ? "collection" : "search";
252
- const handleOrSearchTerm = collection
253
- ? collection.handle
254
- : searchQuery !== null && searchQuery !== void 0 ? searchQuery : "";
255
- const normalisedHandleOrSearchTerm = handleOrSearchTerm
256
- .toLowerCase()
257
- .trim();
258
- const globalCuration = config.curations.find((curation) => curation.id === "global" && curation.type === type);
259
- const curation = config.curations.find((curation) => {
260
- var _a, _b;
261
- const normalisedSearchTerm = (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
262
- const normalisedCollectionHandle = (_b = curation.collectionHandle) === null || _b === void 0 ? void 0 : _b.toLowerCase().trim();
263
- if ("search" === type)
264
- return ("search" === curation.type &&
265
- normalisedHandleOrSearchTerm === normalisedSearchTerm);
266
- if ("collection" === type)
267
- return ("collection" === curation.type &&
268
- normalisedHandleOrSearchTerm === normalisedCollectionHandle);
269
- return false;
270
- });
271
- const addGlobalBoosting = (curation) => {
272
- const curationIsCollection = curation.type === "collection";
273
- if (!curationIsCollection)
274
- return curation;
275
- const curationHasRules = !!curation.boosting.groupings.length ||
276
- !!curation.boosting.sortings.length;
277
- if (curationHasRules || !globalCuration)
278
- return curation;
279
- const curationWithGlobalBoosting = Object.assign(Object.assign({}, curation), { boosting: globalCuration.boosting });
280
- return curationWithGlobalBoosting;
281
- };
282
- return curation
283
- ? addGlobalBoosting(curation)
284
- : globalCuration
285
- ? globalCuration
286
- : undefined;
287
- }, [config, collection, searchQuery]);
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import type { ElasticProduct } from "../types/elastic";
3
- import { useProductPrice } from "../hooks";
4
- declare type Props = {
5
- pagePosition: number;
6
- product: ElasticProduct;
7
- document: ElasticProduct;
8
- render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice> & {
9
- itemRef: (node?: Element | null) => void;
10
- handleClick: () => void;
11
- }) => JSX.Element;
12
- };
13
- export declare const ResultCard: React.FC<Props>;
14
- export {};
@@ -1,13 +0,0 @@
1
- import React from "react";
2
- import { ElasticCallout } from "../types/elastic";
3
- declare type Props = {
4
- pagePosition: number;
5
- document: ElasticCallout;
6
- callout: ElasticCallout["callout"];
7
- render?: (props: Omit<Props, "render"> & {
8
- itemRef: (node?: Element | null) => void;
9
- handleClick: () => void;
10
- }) => JSX.Element;
11
- };
12
- export declare const ResultCardCallout: React.FC<Props>;
13
- export {};
@@ -1,34 +0,0 @@
1
- import React from "react";
2
- import { ResultCard } from "./ResultCard";
3
- import { ResultPagination } from "./ResultPagination";
4
- import { ResultCardCallout } from "./ResultCardCallout";
5
- import { ResultLoadMoreButton } from "./ResultLoadMoreButton";
6
- import { ResultPaginationNextPrev } from "./ResultPaginationNextPrev";
7
- import { ReactivesearchError, ReactivesearchResultProps } from "../types/reactivesearch";
8
- import { ElasticCallout, ElasticProduct } from "../types/elastic";
9
- declare type ResultProps = ReactivesearchResultProps & {
10
- callouts: ElasticCallout[];
11
- products: ElasticProduct[];
12
- };
13
- declare type Props = {
14
- pageSize?: number;
15
- gridGap?: number;
16
- gridColumns?: number;
17
- gridStyle?: React.HTMLAttributes<HTMLElement>["style"];
18
- listClassName?: string;
19
- renderLoading?: () => JSX.Element | null;
20
- renderNoResults?: () => JSX.Element | null;
21
- renderResultCard?: Parameters<typeof ResultCard>[0]["render"];
22
- renderPagination?: Parameters<typeof ResultPagination>[0]["render"];
23
- renderResultCardCallout?: Parameters<typeof ResultCardCallout>[0]["render"];
24
- renderAfter?: (props: ResultProps) => JSX.Element | null;
25
- renderBefore?: (props: ResultProps) => JSX.Element | null;
26
- renderResults?: (props: ResultProps) => JSX.Element | null;
27
- renderError?: (props: {
28
- error: ReactivesearchError;
29
- }) => JSX.Element | null;
30
- renderLoadMoreButton?: Parameters<typeof ResultLoadMoreButton>[0]["render"];
31
- renderPaginationNextPrev?: Parameters<typeof ResultPaginationNextPrev>[0]["render"];
32
- };
33
- export declare const ResultList: React.FC<Props>;
34
- export {};
@@ -1,93 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ResultList = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const ReactiveList_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/result/ReactiveList"));
9
- const ResultCard_1 = require("./ResultCard");
10
- const ResultPagination_1 = require("./ResultPagination");
11
- const ResultCardCallout_1 = require("./ResultCardCallout");
12
- const ResultLoadMoreButton_1 = require("./ResultLoadMoreButton");
13
- const ResultPaginationNextPrev_1 = require("./ResultPaginationNextPrev");
14
- const __1 = require("../");
15
- const hooks_1 = require("../hooks");
16
- const elastic_1 = require("../types/elastic");
17
- const ResultList = (props) => {
18
- const { pageSize } = props;
19
- const reactiveResultListProps = (0, hooks_1.useReactiveResultListProps)({
20
- pageSize,
21
- });
22
- return (react_1.default.createElement(ReactiveList_1.default, Object.assign({}, reactiveResultListProps, { renderPagination: (reactivesearchPaginationProps) => (react_1.default.createElement(ResultPaginationInner, Object.assign({}, props, reactivesearchPaginationProps))), render: (reactivesearchResultProps) => (react_1.default.createElement(ResultListInner, Object.assign({}, props, { reactivesearchResultProps: reactivesearchResultProps }))) })));
23
- };
24
- exports.ResultList = ResultList;
25
- const ResultListInner = (props) => {
26
- const { gridGap, gridColumns, gridStyle, renderError, renderAfter, renderBefore, renderLoading, listClassName, renderResults, renderNoResults, renderResultCard, renderLoadMoreButton, renderResultCardCallout, reactivesearchResultProps, } = props;
27
- const filterStack = (0, hooks_1.useFilterStack)();
28
- const { instantSearch, searchQuery } = (0, hooks_1.useSearch)();
29
- const { track } = (0, __1.useAnalytics)();
30
- const initialSearchHasRun = react_1.default.useMemo(() => "undefined" !==
31
- typeof reactivesearchResultProps.resultStats.numberOfResults, [reactivesearchResultProps]);
32
- const styleProp = react_1.default.useMemo(() => gridStyle !== null && gridStyle !== void 0 ? gridStyle : {
33
- display: "grid",
34
- gap: `${gridGap !== null && gridGap !== void 0 ? gridGap : "0px"}`,
35
- gridTemplateColumns: `repeat(${gridColumns !== null && gridColumns !== void 0 ? gridColumns : 4}, minmax(0, 1fr))`,
36
- }, [gridGap, gridColumns, gridStyle]);
37
- const resultProps = react_1.default.useMemo(() => (Object.assign(Object.assign({}, reactivesearchResultProps), { products: reactivesearchResultProps.data.filter((document) => elastic_1.ElasticDocumentType.Product === document.type || !document.type), callouts: reactivesearchResultProps.data.filter((document) => elastic_1.ElasticDocumentType.Callout === document.type) })), [reactivesearchResultProps]);
38
- if (reactivesearchResultProps.error) {
39
- if (renderError)
40
- return renderError({ error: reactivesearchResultProps.error });
41
- return react_1.default.createElement("div", null,
42
- "Error: ",
43
- reactivesearchResultProps.error.statusText);
44
- }
45
- if (!initialSearchHasRun) {
46
- if (renderLoading)
47
- return renderLoading();
48
- return react_1.default.createElement("div", null, "Loading...");
49
- }
50
- if (!reactivesearchResultProps.resultStats.numberOfResults) {
51
- if (searchQuery)
52
- track({
53
- eventName: "zeroResults",
54
- payload: { searchTerm: searchQuery },
55
- });
56
- if (renderNoResults)
57
- return renderNoResults();
58
- return react_1.default.createElement("div", null, "No results");
59
- }
60
- if (renderResults) {
61
- return renderResults(resultProps);
62
- }
63
- return (react_1.default.createElement(react_1.default.Fragment, null,
64
- renderBefore && renderBefore(resultProps),
65
- react_1.default.createElement("section", { className: listClassName, style: styleProp }, reactivesearchResultProps.data.map((document, key) => {
66
- // @todo result.type is missing in v1 indexes, this check ensures that they are assumed to be products
67
- if (elastic_1.ElasticDocumentType.Product === document.type || !document.type) {
68
- return (react_1.default.createElement(ResultCard_1.ResultCard, { key: document._id, product: document, document: document, pagePosition: key + 1, render: renderResultCard }));
69
- }
70
- if (elastic_1.ElasticDocumentType.Callout === document.type) {
71
- return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { key: document._id, document: document, pagePosition: key + 1, callout: document.callout, render: renderResultCardCallout }));
72
- }
73
- return null;
74
- })),
75
- !instantSearch && "load_more" === (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) && (react_1.default.createElement(ResultLoadMoreButton_1.ResultLoadMoreButton, Object.assign({}, reactivesearchResultProps, { render: renderLoadMoreButton }))),
76
- renderAfter && renderAfter(resultProps)));
77
- };
78
- const ResultPaginationInner = (props) => {
79
- const { renderPagination, renderPaginationNextPrev } = props;
80
- const filterStack = (0, hooks_1.useFilterStack)();
81
- const { instantSearch } = (0, hooks_1.useSearch)();
82
- // do not show pagination in instant search mode
83
- if (instantSearch)
84
- return null;
85
- // load more button is rendered inside the main render prop, as the loadMore prop is not available in renderPagination
86
- if ("load_more" === (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType)) {
87
- return null;
88
- }
89
- if ("next_prev" === (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType)) {
90
- return (react_1.default.createElement(ResultPaginationNextPrev_1.ResultPaginationNextPrev, Object.assign({}, props, { render: renderPaginationNextPrev })));
91
- }
92
- return react_1.default.createElement(ResultPagination_1.ResultPagination, Object.assign({}, props, { render: renderPagination }));
93
- };
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- import { ReactivesearchResultProps } from "../types/reactivesearch";
3
- declare type Props = ReactivesearchResultProps & {
4
- render?: (props: Omit<Props, "render"> & {
5
- hasMore: boolean;
6
- handleLoadMore: () => void;
7
- }) => JSX.Element;
8
- };
9
- export declare const ResultLoadMoreButton: React.FC<Props>;
10
- export {};
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __rest = (this && this.__rest) || function (s, e) {
22
- var t = {};
23
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
- t[p] = s[p];
25
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
- t[p[i]] = s[p[i]];
29
- }
30
- return t;
31
- };
32
- Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.ResultLoadMoreButton = void 0;
34
- const react_1 = __importStar(require("react"));
35
- const hooks_1 = require("../hooks");
36
- const hooks_2 = require("../hooks");
37
- const ResultLoadMoreButton = (_a) => {
38
- var { render, loadMore } = _a, props = __rest(_a, ["render", "loadMore"]);
39
- const { track } = (0, hooks_1.useAnalytics)();
40
- const filterStack = (0, hooks_2.useFilterStack)();
41
- const { resultStats } = props;
42
- const hasMore = react_1.default.useMemo(() => resultStats.displayedResults !== resultStats.numberOfResults, [resultStats]);
43
- const handleLoadMore = (0, react_1.useCallback)(() => {
44
- loadMore();
45
- track({
46
- eventName: "paginationChange",
47
- payload: {
48
- page: Math.ceil(resultStats.displayedResults / ((filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) || 20)) + 1,
49
- source: window.location.pathname.includes("/search")
50
- ? "search"
51
- : "collection",
52
- },
53
- });
54
- }, [loadMore, track, resultStats, filterStack]);
55
- if (render)
56
- return render(Object.assign(Object.assign({}, props), { hasMore,
57
- // @todo: remove legacy loadMore prop in future versions
58
- loadMore: handleLoadMore, handleLoadMore }));
59
- return react_1.default.createElement("button", { onClick: () => loadMore() }, "Load more");
60
- };
61
- exports.ResultLoadMoreButton = ResultLoadMoreButton;
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- import { usePages } from "../hooks";
3
- import { ReactivesearchPaginationProps } from "../types/reactivesearch";
4
- declare type Props = ReactivesearchPaginationProps & {
5
- render?: (props: Omit<Props, "render"> & ReturnType<typeof usePages> & {
6
- handlePageChange: (event: any, page: number) => void;
7
- }) => JSX.Element;
8
- };
9
- export declare const ResultPagination: React.FC<Props>;
10
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ResultPagination = void 0;
18
- const react_1 = __importDefault(require("react"));
19
- const hooks_1 = require("../hooks");
20
- const ResultPagination = (_a) => {
21
- var { render } = _a, props = __rest(_a, ["render"]);
22
- const { track } = (0, hooks_1.useAnalytics)();
23
- const pageProps = (0, hooks_1.usePages)(props);
24
- const { pagesToShow, buildPagePath } = pageProps;
25
- const { currentPage, totalPages, setPage } = props;
26
- const handlePageChange = react_1.default.useCallback((event, newPage) => {
27
- event.preventDefault();
28
- setPage(newPage);
29
- track({
30
- eventName: "paginationChange",
31
- payload: {
32
- page: newPage + 1,
33
- source: window.location.pathname.includes("/search")
34
- ? "search"
35
- : "collection",
36
- },
37
- });
38
- }, [setPage, track]);
39
- if (render)
40
- return render(Object.assign(Object.assign(Object.assign({}, props), pageProps), { handlePageChange }));
41
- if (!totalPages)
42
- return null;
43
- return (react_1.default.createElement("nav", null,
44
- currentPage > 0 && (react_1.default.createElement("a", { rel: "prev", href: buildPagePath(currentPage), onClick: (event) => handlePageChange(event, currentPage - 1) }, "Prev")),
45
- !pagesToShow.includes(0) && (react_1.default.createElement("a", { href: buildPagePath(1), onClick: (event) => handlePageChange(event, 0), rel: 0 === currentPage - 1 ? `prev` : undefined }, "1")),
46
- !pagesToShow.includes(1) && react_1.default.createElement("span", null, "..."),
47
- pagesToShow.map((page) => page === currentPage ? (react_1.default.createElement("span", { key: page + 1 }, page + 1)) : (react_1.default.createElement("a", { key: page + 1, href: buildPagePath(page + 1), onClick: (event) => handlePageChange(event, page), rel: page === currentPage + 1
48
- ? `next`
49
- : page === currentPage - 1
50
- ? `prev`
51
- : undefined }, page + 1))),
52
- !pagesToShow.includes(totalPages - 2) && react_1.default.createElement("span", null, "..."),
53
- !pagesToShow.includes(totalPages - 1) && (react_1.default.createElement("a", { href: buildPagePath(totalPages), onClick: (event) => handlePageChange(event, totalPages - 1), rel: totalPages - 1 === currentPage + 1
54
- ? `next`
55
- : totalPages - 1 === currentPage - 1
56
- ? `prev`
57
- : undefined }, totalPages)),
58
- currentPage + 1 < totalPages && (react_1.default.createElement("a", { rel: "next", href: buildPagePath(currentPage + 2), onClick: (event) => handlePageChange(event, currentPage + 1) }, "Next"))));
59
- };
60
- exports.ResultPagination = ResultPagination;
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- import { usePages } from "../hooks";
3
- import { ReactivesearchPaginationProps } from "../types/reactivesearch";
4
- declare type Props = ReactivesearchPaginationProps & {
5
- render?: (props: Omit<Props, "render"> & ReturnType<typeof usePages>) => JSX.Element;
6
- };
7
- export declare const ResultPaginationNextPrev: React.FC<Props>;
8
- export {};
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ResultPaginationNextPrev = void 0;
18
- const react_1 = __importDefault(require("react"));
19
- const hooks_1 = require("../hooks");
20
- const ResultPaginationNextPrev = (_a) => {
21
- var { render } = _a, props = __rest(_a, ["render"]);
22
- const pageProps = (0, hooks_1.usePages)(props);
23
- if (render)
24
- return render(Object.assign(Object.assign({}, props), pageProps));
25
- const { hasNextPage, buildPagePath, handleNextPage, hasPreviousPage, actualCurrentPage, handlePreviousPage, } = pageProps;
26
- return (react_1.default.createElement("nav", null,
27
- hasPreviousPage && (react_1.default.createElement("a", { rel: "prev", onClick: handlePreviousPage, href: buildPagePath(actualCurrentPage - 1) }, "Prev")),
28
- hasNextPage && (react_1.default.createElement("a", { rel: "next", onClick: handleNextPage, href: buildPagePath(actualCurrentPage + 1) }, "Next"))));
29
- };
30
- exports.ResultPaginationNextPrev = ResultPaginationNextPrev;
@@ -1,7 +0,0 @@
1
- import React from "react";
2
- import { ReactivesearchSearchStatePage } from "../types/reactivesearch";
3
- declare type Props = {
4
- render: (props: ReactivesearchSearchStatePage) => JSX.Element | null;
5
- };
6
- export declare const ResultStateProvider: React.FC<Props>;
7
- export {};
@@ -1,6 +0,0 @@
1
- export * from "./ResultList";
2
- export * from "./ResultCard";
3
- export * from "./ResultPagination";
4
- export * from "./ResultStateProvider";
5
- export * from "./ResultLoadMoreButton";
6
- export * from "./ResultPaginationNextPrev";
@@ -1,9 +0,0 @@
1
- import React from "react";
2
- declare type Props = {
3
- [key: string]: any;
4
- debounce?: number;
5
- placeholder?: string;
6
- inputClassName?: string;
7
- };
8
- export declare const SearchInput: React.FC<Props>;
9
- export {};