@usereactify/search 2.1.0-beta.2 → 2.1.0-beta.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/README.md +5 -0
- package/dist/filter/Filter.d.ts +12 -0
- package/dist/filter/Filter.js +58 -0
- package/dist/filter/FilterList.d.ts +4 -0
- package/dist/filter/FilterList.js +15 -0
- package/dist/filter/FilterStack.d.ts +11 -0
- package/dist/filter/FilterStack.js +25 -0
- package/dist/filter/index.d.ts +3 -0
- package/dist/filter/index.js +15 -0
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/index.js +26 -0
- package/dist/hooks/reactivesearch/index.d.ts +5 -0
- package/dist/hooks/reactivesearch/index.js +17 -0
- package/dist/hooks/reactivesearch/useReactiveBaseProps.d.ts +7 -0
- package/dist/hooks/reactivesearch/useReactiveBaseProps.js +43 -0
- package/dist/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +24 -0
- package/dist/hooks/reactivesearch/useReactiveDataSearchProps.js +87 -0
- package/dist/hooks/reactivesearch/useReactiveFilterListProps.d.ts +68 -0
- package/dist/hooks/reactivesearch/useReactiveFilterListProps.js +106 -0
- package/dist/hooks/reactivesearch/useReactiveReactProp.d.ts +3 -0
- package/dist/hooks/reactivesearch/useReactiveReactProp.js +25 -0
- package/dist/hooks/reactivesearch/useReactiveResultListProps.d.ts +20 -0
- package/dist/hooks/reactivesearch/useReactiveResultListProps.js +32 -0
- package/dist/hooks/useAnalytics.d.ts +14 -0
- package/dist/hooks/useAnalytics.js +47 -0
- package/dist/hooks/useCollection.d.ts +1 -0
- package/dist/hooks/useCollection.js +6 -0
- package/dist/hooks/useCombinedResults.d.ts +7 -0
- package/dist/hooks/useCombinedResults.js +25 -0
- package/dist/hooks/useConfig.d.ts +1 -0
- package/dist/hooks/useConfig.js +6 -0
- package/dist/hooks/useCuration.d.ts +1 -0
- package/dist/hooks/useCuration.js +6 -0
- package/dist/hooks/useFilterCollapsedState.d.ts +8 -0
- package/dist/hooks/useFilterCollapsedState.js +27 -0
- package/dist/hooks/useFilterListProps.d.ts +21 -0
- package/dist/hooks/useFilterListProps.js +35 -0
- package/dist/hooks/useFilterStack.d.ts +1 -0
- package/dist/hooks/useFilterStack.js +6 -0
- package/dist/hooks/useFilters.d.ts +1 -0
- package/dist/hooks/useFilters.js +17 -0
- package/dist/hooks/usePages.d.ts +10 -0
- package/dist/hooks/usePages.js +82 -0
- package/dist/hooks/useProductPrice.d.ts +12 -0
- package/dist/hooks/useProductPrice.js +61 -0
- package/dist/hooks/useSearch.d.ts +8 -0
- package/dist/hooks/useSearch.js +16 -0
- package/dist/hooks/useSort.d.ts +5 -0
- package/dist/hooks/useSort.js +9 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +19 -0
- package/dist/provider.d.ts +44 -0
- package/dist/provider.js +165 -0
- package/dist/result/ResultCard.d.ts +10 -0
- package/dist/result/ResultCard.js +45 -0
- package/dist/result/ResultCardCallout.d.ts +9 -0
- package/dist/result/ResultCardCallout.js +38 -0
- package/dist/result/ResultList.d.ts +30 -0
- package/dist/result/ResultList.js +99 -0
- package/dist/result/ResultLoadMoreButton.d.ts +9 -0
- package/dist/result/ResultLoadMoreButton.js +27 -0
- package/dist/result/ResultPagination.d.ts +8 -0
- package/dist/result/ResultPagination.js +50 -0
- package/dist/result/ResultPaginationNextPrev.d.ts +8 -0
- package/dist/result/ResultPaginationNextPrev.js +30 -0
- package/dist/result/ResultStateProvider.d.ts +7 -0
- package/dist/result/ResultStateProvider.js +10 -0
- package/dist/result/index.d.ts +5 -0
- package/dist/result/index.js +17 -0
- package/dist/search/SearchInput.d.ts +8 -0
- package/dist/search/SearchInput.js +19 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/index.js +13 -0
- package/dist/sensor/SensorCollection.d.ts +2 -0
- package/dist/sensor/SensorCollection.js +41 -0
- package/dist/sensor/SensorInventoryAvailable.d.ts +2 -0
- package/dist/sensor/SensorInventoryAvailable.js +25 -0
- package/dist/sensor/SensorPublished.d.ts +2 -0
- package/dist/sensor/SensorPublished.js +16 -0
- package/dist/sensor/SensorSearch.d.ts +2 -0
- package/dist/sensor/SensorSearch.js +81 -0
- package/dist/sensor/SensorSort.d.ts +2 -0
- package/dist/sensor/SensorSort.js +144 -0
- package/dist/sensor/SensorSortScore.d.ts +2 -0
- package/dist/sensor/SensorSortScore.js +12 -0
- package/dist/sensor/SensorStack.d.ts +2 -0
- package/dist/sensor/SensorStack.js +31 -0
- package/dist/sensor/index.d.ts +8 -0
- package/dist/sensor/index.js +29 -0
- package/dist/types/config.d.ts +130 -0
- package/dist/types/config.js +2 -0
- package/dist/types/index.d.ts +79 -0
- package/dist/types/index.js +14 -0
- package/dist/types/results.d.ts +48 -0
- package/dist/types/results.js +2 -0
- package/dist/utility/UtilityAuthenticatedReactiveBase.d.ts +2 -0
- package/dist/utility/UtilityAuthenticatedReactiveBase.js +14 -0
- package/package.json +1 -1
package/dist/provider.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
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.useContext = exports.Provider = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const UtilityAuthenticatedReactiveBase_1 = require("./utility/UtilityAuthenticatedReactiveBase");
|
|
9
|
+
const debug = require("debug")("reactify-search:Provider");
|
|
10
|
+
const Context = react_1.default.createContext(undefined);
|
|
11
|
+
const defaultCredentials = {
|
|
12
|
+
username: "guest",
|
|
13
|
+
password: "password",
|
|
14
|
+
endpoint: "https://api.search.reactify.app",
|
|
15
|
+
};
|
|
16
|
+
const Provider = (props) => {
|
|
17
|
+
var _a;
|
|
18
|
+
const { index, config, shopName, children, collection, instantSearch, filterStackId, noReactiveBase, enableCallouts, additionalComponentIds, } = props;
|
|
19
|
+
const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : defaultCredentials;
|
|
20
|
+
const theme = props.theme || {
|
|
21
|
+
typography: {
|
|
22
|
+
fontFamily: "inherit",
|
|
23
|
+
fontSize: "inherit",
|
|
24
|
+
},
|
|
25
|
+
colors: {
|
|
26
|
+
textColor: "inherit",
|
|
27
|
+
primaryTextColor: "inherit",
|
|
28
|
+
primaryColor: "inherit",
|
|
29
|
+
titleColor: "inherit",
|
|
30
|
+
alertColor: "inherit",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
react_1.default.useEffect(() => {
|
|
34
|
+
debug("props", props);
|
|
35
|
+
}, [props]);
|
|
36
|
+
// @todo make this hackable with a prop
|
|
37
|
+
// https://gitlab.com/reactifyapps/reactify-search-frontend/-/issues/1
|
|
38
|
+
const searchQueryFromURL = react_1.default.useMemo(() => {
|
|
39
|
+
var _a;
|
|
40
|
+
if (typeof window === "undefined")
|
|
41
|
+
return undefined;
|
|
42
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
43
|
+
return (_a = urlParams.get("q")) !== null && _a !== void 0 ? _a : undefined;
|
|
44
|
+
}, []);
|
|
45
|
+
const [searchQuery, setSearchQuery] = react_1.default.useState(searchQueryFromURL);
|
|
46
|
+
const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
|
|
47
|
+
const submitSearch = react_1.default.useCallback((localSearchQuery) => {
|
|
48
|
+
const actualSearchQuery = localSearchQuery !== null && localSearchQuery !== void 0 ? localSearchQuery : searchQuery;
|
|
49
|
+
if (!actualSearchQuery)
|
|
50
|
+
return;
|
|
51
|
+
const redirect = config.redirects.find((redirect) => redirect.query.trim().toLowerCase() ===
|
|
52
|
+
actualSearchQuery.trim().toLowerCase());
|
|
53
|
+
if (redirect)
|
|
54
|
+
window.location.href = redirect.url;
|
|
55
|
+
else
|
|
56
|
+
window.location.href = `/search?q=${actualSearchQuery}`;
|
|
57
|
+
}, [searchQuery]);
|
|
58
|
+
const { sortOption, sortOptions, setSortOption } = useSortState(config, collection);
|
|
59
|
+
// do not attempt to resolve a filter stack if in instantSearch mode
|
|
60
|
+
const filterStack = instantSearch
|
|
61
|
+
? undefined
|
|
62
|
+
: useFilterStack(config, collection, filterStackId);
|
|
63
|
+
const curation = useCuration(config, collection, searchQuery);
|
|
64
|
+
const contextValue = react_1.default.useMemo(() => ({
|
|
65
|
+
index,
|
|
66
|
+
config,
|
|
67
|
+
shopName,
|
|
68
|
+
collection,
|
|
69
|
+
credentials,
|
|
70
|
+
searchQuery,
|
|
71
|
+
filterStack,
|
|
72
|
+
sortOption,
|
|
73
|
+
sortOptions,
|
|
74
|
+
submitSearch,
|
|
75
|
+
setSortOption,
|
|
76
|
+
setSearchQuery,
|
|
77
|
+
setShowInstantSearchResults,
|
|
78
|
+
theme,
|
|
79
|
+
curation,
|
|
80
|
+
enableCallouts,
|
|
81
|
+
additionalComponentIds,
|
|
82
|
+
instantSearch: !!instantSearch,
|
|
83
|
+
showInstantSearchResults: !!showInstantSearchResults && !!searchQuery,
|
|
84
|
+
}), [
|
|
85
|
+
index,
|
|
86
|
+
config,
|
|
87
|
+
curation,
|
|
88
|
+
shopName,
|
|
89
|
+
collection,
|
|
90
|
+
credentials,
|
|
91
|
+
searchQuery,
|
|
92
|
+
filterStack,
|
|
93
|
+
sortOption,
|
|
94
|
+
sortOptions,
|
|
95
|
+
submitSearch,
|
|
96
|
+
instantSearch,
|
|
97
|
+
enableCallouts,
|
|
98
|
+
additionalComponentIds,
|
|
99
|
+
showInstantSearchResults,
|
|
100
|
+
theme,
|
|
101
|
+
]);
|
|
102
|
+
react_1.default.useEffect(() => {
|
|
103
|
+
debug("contextValue", contextValue);
|
|
104
|
+
}, [contextValue]);
|
|
105
|
+
if (noReactiveBase) {
|
|
106
|
+
return react_1.default.createElement(Context.Provider, { value: contextValue }, children);
|
|
107
|
+
}
|
|
108
|
+
return (react_1.default.createElement(Context.Provider, { value: contextValue },
|
|
109
|
+
react_1.default.createElement(UtilityAuthenticatedReactiveBase_1.UtilityAuthenticatedReactiveBase, null, children)));
|
|
110
|
+
};
|
|
111
|
+
exports.Provider = Provider;
|
|
112
|
+
const useContext = () => react_1.default.useContext(Context);
|
|
113
|
+
exports.useContext = useContext;
|
|
114
|
+
const useSortState = (config, collection) => {
|
|
115
|
+
const sortOptions = react_1.default.useMemo(() => {
|
|
116
|
+
const type = !!collection ? "collection" : "search";
|
|
117
|
+
return config.sort
|
|
118
|
+
.sort((a, b) => `${a.position}`.localeCompare(`${b.position}`))
|
|
119
|
+
.filter(({ visibility }) => ["all", type].includes(visibility));
|
|
120
|
+
}, [config, collection]);
|
|
121
|
+
const [sortOptionState, setSortOptionState] = react_1.default.useState(sortOptions[0].id);
|
|
122
|
+
const sortOption = react_1.default.useMemo(() => sortOptions.find(({ id }) => id === sortOptionState) || sortOptions[0], [sortOptions, sortOptionState]);
|
|
123
|
+
const setSortOption = react_1.default.useCallback((sortOptionId) => setSortOptionState(sortOptionId), []);
|
|
124
|
+
return react_1.default.useMemo(() => ({ sortOptions, sortOption, setSortOption }), [sortOption, sortOptions, setSortOption]);
|
|
125
|
+
};
|
|
126
|
+
// resolve the "filter" in use for this view
|
|
127
|
+
// Reactify Search confusingly refers to the entire list of filters as a "filter"
|
|
128
|
+
// and each filter within that list is called a "Filter Option"
|
|
129
|
+
// @todo we need a better name for the overall page like "Filter Stack" or something,
|
|
130
|
+
// each block is then called a filter so like Size would be a "Filter" and then each
|
|
131
|
+
// value within it is a "Filter Option"
|
|
132
|
+
const useFilterStack = (config, collection, filterStackId) => react_1.default.useMemo(() => {
|
|
133
|
+
var _a;
|
|
134
|
+
// manually select filter stack by ID if provided
|
|
135
|
+
if (filterStackId) {
|
|
136
|
+
const filterStack = config.filters.find((filter) => filterStackId === filter.id);
|
|
137
|
+
if (filterStack)
|
|
138
|
+
return filterStack;
|
|
139
|
+
}
|
|
140
|
+
const type = !!collection ? "collection" : "search";
|
|
141
|
+
return ((_a = config.filters.find((filter) => type === filter.type)) !== null && _a !== void 0 ? _a : config.filters[0]);
|
|
142
|
+
}, [config, collection]);
|
|
143
|
+
const useCuration = (config, collection, searchQuery) => react_1.default.useMemo(() => {
|
|
144
|
+
debug("resolveCuration.start", { config, collection, searchQuery });
|
|
145
|
+
const type = collection ? "collection" : "search";
|
|
146
|
+
const handleOrSearchTerm = collection
|
|
147
|
+
? collection.handle
|
|
148
|
+
: searchQuery !== null && searchQuery !== void 0 ? searchQuery : "";
|
|
149
|
+
const normalisedHandleOrSearchTerm = handleOrSearchTerm
|
|
150
|
+
.toLowerCase()
|
|
151
|
+
.trim();
|
|
152
|
+
const curation = config.curations.find((curation) => {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
const normalisedSearchTerm = (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
|
|
155
|
+
const normalisedCollectionHandle = (_b = curation.collectionHandle) === null || _b === void 0 ? void 0 : _b.toLowerCase().trim();
|
|
156
|
+
if ("search" === type)
|
|
157
|
+
return ("search" === curation.type &&
|
|
158
|
+
normalisedHandleOrSearchTerm === normalisedSearchTerm);
|
|
159
|
+
if ("collection" === type)
|
|
160
|
+
return ("collection" === curation.type &&
|
|
161
|
+
normalisedHandleOrSearchTerm === normalisedCollectionHandle);
|
|
162
|
+
return false;
|
|
163
|
+
});
|
|
164
|
+
return curation ? curation : undefined;
|
|
165
|
+
}, [config, collection, searchQuery]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Product } from "../types";
|
|
3
|
+
import { useProductPrice } from "../hooks";
|
|
4
|
+
declare type Props = {
|
|
5
|
+
product: Product;
|
|
6
|
+
pagePosition: number;
|
|
7
|
+
render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice>) => JSX.Element;
|
|
8
|
+
};
|
|
9
|
+
export declare const ResultCard: React.FC<Props>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
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.ResultCard = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const hooks_1 = require("../hooks");
|
|
20
|
+
const ResultCard = (_a) => {
|
|
21
|
+
var { render } = _a, props = __rest(_a, ["render"]);
|
|
22
|
+
const { product } = props;
|
|
23
|
+
const productPrice = (0, hooks_1.useProductPrice)(product);
|
|
24
|
+
if (render)
|
|
25
|
+
return render(Object.assign(Object.assign({}, props), productPrice));
|
|
26
|
+
const { formattedPrice, formattedCompareAtPrice, onSale } = productPrice;
|
|
27
|
+
const { track } = (0, hooks_1.useAnalytics)();
|
|
28
|
+
const handleClick = react_1.default.useCallback((e) => {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
const { id } = product;
|
|
31
|
+
console.log("tracking click product event");
|
|
32
|
+
track({
|
|
33
|
+
eventName: "select_item",
|
|
34
|
+
id,
|
|
35
|
+
}).then(() => {
|
|
36
|
+
console.log("tracking click product event finished");
|
|
37
|
+
window.location.href = `/products/${product.handle}`;
|
|
38
|
+
});
|
|
39
|
+
}, [track, product]);
|
|
40
|
+
return (react_1.default.createElement("article", null,
|
|
41
|
+
react_1.default.createElement("a", { onClick: handleClick }, product.title),
|
|
42
|
+
react_1.default.createElement("span", null, formattedPrice),
|
|
43
|
+
onSale && (react_1.default.createElement("span", { style: { textDecoration: "line-through" } }, formattedCompareAtPrice))));
|
|
44
|
+
};
|
|
45
|
+
exports.ResultCard = ResultCard;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ConfigCallout } from "../types";
|
|
3
|
+
declare type Props = {
|
|
4
|
+
callout: ConfigCallout;
|
|
5
|
+
pagePosition: number;
|
|
6
|
+
render?: (props: Omit<Props, "render">) => JSX.Element;
|
|
7
|
+
};
|
|
8
|
+
export declare const ResultCardCallout: React.FC<Props>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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.ResultCardCallout = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const ResultCardCallout = (props) => {
|
|
20
|
+
const { callout } = props;
|
|
21
|
+
const styleProp = react_1.default.useMemo(() => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return ({
|
|
24
|
+
gridRow: `span ${(_a = callout.displayRows) !== null && _a !== void 0 ? _a : 1}`,
|
|
25
|
+
gridColumn: `span ${(_b = callout.displayColumns) !== null && _b !== void 0 ? _b : 1}`,
|
|
26
|
+
});
|
|
27
|
+
}, [callout]);
|
|
28
|
+
return (react_1.default.createElement("article", { style: styleProp },
|
|
29
|
+
react_1.default.createElement(ResultCardCalloutInner, Object.assign({}, props))));
|
|
30
|
+
};
|
|
31
|
+
exports.ResultCardCallout = ResultCardCallout;
|
|
32
|
+
const ResultCardCalloutInner = (_a) => {
|
|
33
|
+
var { render } = _a, props = __rest(_a, ["render"]);
|
|
34
|
+
const { callout } = props;
|
|
35
|
+
if (render)
|
|
36
|
+
return render(props);
|
|
37
|
+
return react_1.default.createElement("p", null, callout.title);
|
|
38
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { ResultCombined, ReactivesearchError, ReactivesearchResultProps } from "../types";
|
|
8
|
+
declare type ResultProps = ReactivesearchResultProps & {
|
|
9
|
+
results: ResultCombined[];
|
|
10
|
+
};
|
|
11
|
+
declare type Props = {
|
|
12
|
+
pageSize?: number;
|
|
13
|
+
gridColumns?: number;
|
|
14
|
+
listClassName?: string;
|
|
15
|
+
renderLoading?: () => JSX.Element | null;
|
|
16
|
+
renderNoResults?: () => JSX.Element | null;
|
|
17
|
+
renderResultCard?: Parameters<typeof ResultCard>[0]["render"];
|
|
18
|
+
renderPagination?: Parameters<typeof ResultPagination>[0]["render"];
|
|
19
|
+
renderResultCardCallout?: Parameters<typeof ResultCardCallout>[0]["render"];
|
|
20
|
+
renderAfter?: (props: ResultProps) => JSX.Element | null;
|
|
21
|
+
renderBefore?: (props: ResultProps) => JSX.Element | null;
|
|
22
|
+
renderResults?: (props: ResultProps) => JSX.Element | null;
|
|
23
|
+
renderError?: (props: {
|
|
24
|
+
error: ReactivesearchError;
|
|
25
|
+
}) => JSX.Element | null;
|
|
26
|
+
renderLoadMoreButton?: Parameters<typeof ResultLoadMoreButton>[0]["render"];
|
|
27
|
+
renderPaginationNextPrev?: Parameters<typeof ResultPaginationNextPrev>[0]["render"];
|
|
28
|
+
};
|
|
29
|
+
export declare const ResultList: React.FC<Props>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
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 provider_1 = require("../provider");
|
|
15
|
+
const hooks_1 = require("../hooks");
|
|
16
|
+
const ResultList = (props) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const { pageSize } = props;
|
|
19
|
+
const curation = (0, hooks_1.useCuration)();
|
|
20
|
+
const { enableCallouts } = (0, provider_1.useContext)();
|
|
21
|
+
const reactiveResultListProps = (0, hooks_1.useReactiveResultListProps)({
|
|
22
|
+
pageSize,
|
|
23
|
+
pageSizeAdjust: enableCallouts ? (_b = (_a = curation === null || curation === void 0 ? void 0 : curation.callouts) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0,
|
|
24
|
+
});
|
|
25
|
+
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 }))) })));
|
|
26
|
+
};
|
|
27
|
+
exports.ResultList = ResultList;
|
|
28
|
+
const ResultListInner = (props) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const { gridColumns, renderError, renderAfter, renderBefore, renderLoading, listClassName, renderResults, renderNoResults, renderResultCard, renderLoadMoreButton, renderResultCardCallout, reactivesearchResultProps, } = props;
|
|
31
|
+
const curation = (0, hooks_1.useCuration)();
|
|
32
|
+
const filterStack = (0, hooks_1.useFilterStack)();
|
|
33
|
+
const { instantSearch } = (0, hooks_1.useSearch)();
|
|
34
|
+
const { enableCallouts } = (0, provider_1.useContext)();
|
|
35
|
+
const initialSearchHasRun = react_1.default.useMemo(() => "undefined" !==
|
|
36
|
+
typeof reactivesearchResultProps.resultStats.numberOfResults, [reactivesearchResultProps]);
|
|
37
|
+
const combinedResults = (0, hooks_1.useCombinedResults)({
|
|
38
|
+
callouts: (_a = curation === null || curation === void 0 ? void 0 : curation.callouts) !== null && _a !== void 0 ? _a : [],
|
|
39
|
+
products: reactivesearchResultProps.data,
|
|
40
|
+
});
|
|
41
|
+
const resultProps = react_1.default.useMemo(() => {
|
|
42
|
+
return Object.assign(Object.assign({}, reactivesearchResultProps), { results: combinedResults });
|
|
43
|
+
}, [combinedResults, reactivesearchResultProps]);
|
|
44
|
+
const styleProp = react_1.default.useMemo(() => !!enableCallouts
|
|
45
|
+
? {
|
|
46
|
+
display: "grid",
|
|
47
|
+
gridTemplateColumns: `repeat(${gridColumns !== null && gridColumns !== void 0 ? gridColumns : 4}, minmax(0, 1fr))`,
|
|
48
|
+
}
|
|
49
|
+
: {}, [curation]);
|
|
50
|
+
if (reactivesearchResultProps.error) {
|
|
51
|
+
if (renderError)
|
|
52
|
+
return renderError({ error: reactivesearchResultProps.error });
|
|
53
|
+
return react_1.default.createElement("div", null,
|
|
54
|
+
"Error: ",
|
|
55
|
+
reactivesearchResultProps.error.statusText);
|
|
56
|
+
}
|
|
57
|
+
if (!initialSearchHasRun) {
|
|
58
|
+
if (renderLoading)
|
|
59
|
+
return renderLoading();
|
|
60
|
+
return react_1.default.createElement("div", null, "Loading...");
|
|
61
|
+
}
|
|
62
|
+
if (!reactivesearchResultProps.resultStats.numberOfResults) {
|
|
63
|
+
if (renderNoResults)
|
|
64
|
+
return renderNoResults();
|
|
65
|
+
return react_1.default.createElement("div", null, "No results");
|
|
66
|
+
}
|
|
67
|
+
if (renderResults) {
|
|
68
|
+
return renderResults(resultProps);
|
|
69
|
+
}
|
|
70
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
71
|
+
renderBefore && renderBefore(resultProps),
|
|
72
|
+
react_1.default.createElement("section", { className: listClassName, style: styleProp }, combinedResults.map((result, key) => {
|
|
73
|
+
if ("product" === result.type) {
|
|
74
|
+
return (react_1.default.createElement(ResultCard_1.ResultCard, { product: result.data, pagePosition: key + 1, render: renderResultCard, key: `product-${result.data._id}` }));
|
|
75
|
+
}
|
|
76
|
+
if (!!enableCallouts && "callout" === result.type) {
|
|
77
|
+
return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { callout: result.data, pagePosition: key + 1, render: renderResultCardCallout, key: `callout-${result.data.id}` }));
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
})),
|
|
81
|
+
!instantSearch && "load_more" === (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) && (react_1.default.createElement(ResultLoadMoreButton_1.ResultLoadMoreButton, Object.assign({}, reactivesearchResultProps, { render: renderLoadMoreButton }))),
|
|
82
|
+
renderAfter && renderAfter(resultProps)));
|
|
83
|
+
};
|
|
84
|
+
const ResultPaginationInner = (props) => {
|
|
85
|
+
const { renderPagination, renderPaginationNextPrev } = props;
|
|
86
|
+
const filterStack = (0, hooks_1.useFilterStack)();
|
|
87
|
+
const { instantSearch } = (0, hooks_1.useSearch)();
|
|
88
|
+
// do not show pagination in instant search mode
|
|
89
|
+
if (instantSearch)
|
|
90
|
+
return null;
|
|
91
|
+
// load more button is rendered inside the main render prop, as the loadMore prop is not available in renderPagination
|
|
92
|
+
if ("load_more" === (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType)) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if ("next_prev" === (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType)) {
|
|
96
|
+
return (react_1.default.createElement(ResultPaginationNextPrev_1.ResultPaginationNextPrev, Object.assign({}, props, { render: renderPaginationNextPrev })));
|
|
97
|
+
}
|
|
98
|
+
return react_1.default.createElement(ResultPagination_1.ResultPagination, Object.assign({}, props, { render: renderPagination }));
|
|
99
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ReactivesearchResultProps } from "../types";
|
|
3
|
+
declare type Props = ReactivesearchResultProps & {
|
|
4
|
+
render?: (props: Omit<Props, "render"> & {
|
|
5
|
+
hasMore: boolean;
|
|
6
|
+
}) => JSX.Element;
|
|
7
|
+
};
|
|
8
|
+
export declare const ResultLoadMoreButton: React.FC<Props>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
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.ResultLoadMoreButton = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const ResultLoadMoreButton = (_a) => {
|
|
20
|
+
var { render } = _a, props = __rest(_a, ["render"]);
|
|
21
|
+
const { resultStats, loadMore } = props;
|
|
22
|
+
const hasMore = react_1.default.useMemo(() => resultStats.displayedResults !== resultStats.numberOfResults, [resultStats]);
|
|
23
|
+
if (render)
|
|
24
|
+
return render(Object.assign(Object.assign({}, props), { hasMore }));
|
|
25
|
+
return react_1.default.createElement("button", { onClick: () => loadMore() }, "Load more");
|
|
26
|
+
};
|
|
27
|
+
exports.ResultLoadMoreButton = ResultLoadMoreButton;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { usePages } from "../hooks";
|
|
3
|
+
import { ReactivesearchPaginationProps } from "../types";
|
|
4
|
+
declare type Props = ReactivesearchPaginationProps & {
|
|
5
|
+
render?: (props: Omit<Props, "render"> & ReturnType<typeof usePages>) => JSX.Element;
|
|
6
|
+
};
|
|
7
|
+
export declare const ResultPagination: React.FC<Props>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
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 pageProps = (0, hooks_1.usePages)(props);
|
|
23
|
+
if (render)
|
|
24
|
+
return render(Object.assign(Object.assign({}, props), pageProps));
|
|
25
|
+
const { pagesToShow, buildPagePath } = pageProps;
|
|
26
|
+
const { currentPage, totalPages, setPage } = props;
|
|
27
|
+
const handlePageChange = react_1.default.useCallback((event, newPage) => {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
setPage(newPage);
|
|
30
|
+
}, [setPage]);
|
|
31
|
+
if (!totalPages)
|
|
32
|
+
return null;
|
|
33
|
+
return (react_1.default.createElement("nav", null,
|
|
34
|
+
currentPage > 0 && (react_1.default.createElement("a", { rel: "prev", href: buildPagePath(currentPage), onClick: (event) => handlePageChange(event, currentPage - 1) }, "Prev")),
|
|
35
|
+
!pagesToShow.includes(0) && (react_1.default.createElement("a", { href: buildPagePath(1), onClick: (event) => handlePageChange(event, 0), rel: 0 === currentPage - 1 ? `prev` : undefined }, "1")),
|
|
36
|
+
!pagesToShow.includes(1) && react_1.default.createElement("span", null, "..."),
|
|
37
|
+
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
|
|
38
|
+
? `next`
|
|
39
|
+
: page === currentPage - 1
|
|
40
|
+
? `prev`
|
|
41
|
+
: undefined }, page + 1))),
|
|
42
|
+
!pagesToShow.includes(totalPages - 2) && react_1.default.createElement("span", null, "..."),
|
|
43
|
+
!pagesToShow.includes(totalPages - 1) && (react_1.default.createElement("a", { href: buildPagePath(totalPages), onClick: (event) => handlePageChange(event, totalPages - 1), rel: totalPages - 1 === currentPage + 1
|
|
44
|
+
? `next`
|
|
45
|
+
: totalPages - 1 === currentPage - 1
|
|
46
|
+
? `prev`
|
|
47
|
+
: undefined }, totalPages)),
|
|
48
|
+
currentPage + 1 < totalPages && (react_1.default.createElement("a", { rel: "next", href: buildPagePath(currentPage + 2), onClick: (event) => handlePageChange(event, currentPage + 1) }, "Next"))));
|
|
49
|
+
};
|
|
50
|
+
exports.ResultPagination = ResultPagination;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { usePages } from "../hooks";
|
|
3
|
+
import { ReactivesearchPaginationProps } from "../types";
|
|
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 {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
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.ResultStateProvider = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const StateProvider_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/basic/StateProvider"));
|
|
9
|
+
const ResultStateProvider = ({ render }) => (react_1.default.createElement(StateProvider_1.default, { componentIds: ["page"], includeKeys: ["isLoading", "hits", "resultStats", "error"], render: (state) => render(state.searchState.page) }));
|
|
10
|
+
exports.ResultStateProvider = ResultStateProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./ResultList"), exports);
|
|
14
|
+
__exportStar(require("./ResultCard"), exports);
|
|
15
|
+
__exportStar(require("./ResultPagination"), exports);
|
|
16
|
+
__exportStar(require("./ResultStateProvider"), exports);
|
|
17
|
+
__exportStar(require("./ResultLoadMoreButton"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
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.SearchInput = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const DataSearch_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/search/DataSearch"));
|
|
9
|
+
const hooks_1 = require("../hooks");
|
|
10
|
+
const SearchInput = (props) => {
|
|
11
|
+
const { debounce, placeholder, inputClassName } = props;
|
|
12
|
+
const reactiveDataSearchProps = (0, hooks_1.useReactiveDataSearchProps)({
|
|
13
|
+
debounce,
|
|
14
|
+
placeholder,
|
|
15
|
+
inputClassName,
|
|
16
|
+
});
|
|
17
|
+
return react_1.default.createElement(DataSearch_1.default, Object.assign({}, reactiveDataSearchProps));
|
|
18
|
+
};
|
|
19
|
+
exports.SearchInput = SearchInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./SearchInput";
|
|
@@ -0,0 +1,13 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./SearchInput"), exports);
|