@usereactify/search 3.12.0-beta.4 → 4.1.0-beta.0
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/dist/hooks/reactivesearch/useReactiveFilterListProps.js +2 -2
- package/dist/hooks/reactivesearch/useReactiveReactProp.d.ts +1 -1
- package/dist/hooks/reactivesearch/useReactiveReactProp.js +6 -6
- package/dist/hooks/useLiveConfig.d.ts +1 -1
- package/dist/hooks/useLiveConfig.js +3 -8
- package/dist/provider.d.ts +3 -4
- package/dist/provider.js +56 -38
- package/dist/types/firestore.d.ts +0 -3
- package/package.json +4 -2
|
@@ -7,7 +7,7 @@ exports.useReactiveFilterListProps = void 0;
|
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const useReactiveReactProp_1 = require("./useReactiveReactProp");
|
|
9
9
|
const useReactiveFilterListProps = (filter) => {
|
|
10
|
-
const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.
|
|
10
|
+
const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.id);
|
|
11
11
|
const nestedField = react_1.default.useMemo(() => {
|
|
12
12
|
const nestedFields = ["variants"];
|
|
13
13
|
const topField = filter.field.split(".")[0];
|
|
@@ -93,7 +93,7 @@ const useReactiveFilterListProps = (filter) => {
|
|
|
93
93
|
customQuery,
|
|
94
94
|
defaultQuery,
|
|
95
95
|
URLParams: true,
|
|
96
|
-
componentId: filter.
|
|
96
|
+
componentId: filter.id,
|
|
97
97
|
dataField: filter.field,
|
|
98
98
|
filterLabel: filter.name,
|
|
99
99
|
react: reactiveReactProp,
|
|
@@ -8,18 +8,18 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const sensor_1 = require("../../sensor");
|
|
9
9
|
const useFilters_1 = require("../useFilters");
|
|
10
10
|
const provider_1 = require("../../provider");
|
|
11
|
-
const useReactiveReactProp = (
|
|
11
|
+
const useReactiveReactProp = (currentId) => {
|
|
12
12
|
const filters = (0, useFilters_1.useFilters)();
|
|
13
|
-
const {
|
|
13
|
+
const { additionalComponentIds } = (0, provider_1.useContext)();
|
|
14
14
|
return react_1.default.useMemo(() => {
|
|
15
15
|
return {
|
|
16
16
|
and: [
|
|
17
17
|
"SearchInput",
|
|
18
18
|
...sensor_1.SENSOR_IDS,
|
|
19
|
-
...(
|
|
20
|
-
...filters.map((filter) => filter.
|
|
21
|
-
].filter((
|
|
19
|
+
...(additionalComponentIds !== null && additionalComponentIds !== void 0 ? additionalComponentIds : []),
|
|
20
|
+
...filters.map((filter) => filter.id),
|
|
21
|
+
].filter((id) => id !== currentId),
|
|
22
22
|
};
|
|
23
|
-
}, [filters,
|
|
23
|
+
}, [filters, currentId]);
|
|
24
24
|
};
|
|
25
25
|
exports.useReactiveReactProp = useReactiveReactProp;
|
|
@@ -41,7 +41,7 @@ function getCachedConfig() {
|
|
|
41
41
|
}
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
const useLiveConfig = (shopifyPermanentDomain
|
|
44
|
+
const useLiveConfig = (shopifyPermanentDomain) => {
|
|
45
45
|
const [config, setConfig] = react_1.default.useState(getCachedConfig());
|
|
46
46
|
react_1.default.useEffect(() => {
|
|
47
47
|
const cachedConfig = getCachedConfig();
|
|
@@ -49,19 +49,14 @@ const useLiveConfig = (shopifyPermanentDomain, configId) => {
|
|
|
49
49
|
return;
|
|
50
50
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
51
|
debug("fetching fresh config");
|
|
52
|
-
const
|
|
53
|
-
searchParams.set("shop", shopifyPermanentDomain);
|
|
54
|
-
if (configId) {
|
|
55
|
-
searchParams.set("id", configId);
|
|
56
|
-
}
|
|
57
|
-
const json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
|
|
52
|
+
const json = yield fetch(`https://config.search.reactify.app/?shop=${shopifyPermanentDomain}`).then((response) => response.json());
|
|
58
53
|
setConfig(json.body);
|
|
59
54
|
window.sessionStorage.setItem("reactify-search:config", JSON.stringify({
|
|
60
55
|
expiresAt: new Date().getTime() + CACHE_EXPIRY,
|
|
61
56
|
config: json.body,
|
|
62
57
|
}));
|
|
63
58
|
}))();
|
|
64
|
-
}, [shopifyPermanentDomain
|
|
59
|
+
}, [shopifyPermanentDomain]);
|
|
65
60
|
return {
|
|
66
61
|
config,
|
|
67
62
|
};
|
package/dist/provider.d.ts
CHANGED
|
@@ -20,14 +20,13 @@ declare type Context = {
|
|
|
20
20
|
theme?: Theme;
|
|
21
21
|
curation?: ConfigCuration;
|
|
22
22
|
/** Array of additional component IDs managed outside of Reactify Search */
|
|
23
|
-
|
|
23
|
+
additionalComponentIds?: string[];
|
|
24
24
|
};
|
|
25
25
|
declare const Context: React.Context<Context | undefined>;
|
|
26
26
|
declare type Props = {
|
|
27
27
|
index: string;
|
|
28
28
|
shopifyPermanentDomain: string;
|
|
29
|
-
|
|
30
|
-
filterStackHandle?: string;
|
|
29
|
+
filterStackId?: string;
|
|
31
30
|
collection?: Collection;
|
|
32
31
|
noReactiveBase?: boolean;
|
|
33
32
|
instantSearch?: boolean;
|
|
@@ -35,7 +34,7 @@ declare type Props = {
|
|
|
35
34
|
credentials?: Credentials;
|
|
36
35
|
theme?: Theme;
|
|
37
36
|
/** Array of additional component IDs managed outside of Reactify Search */
|
|
38
|
-
|
|
37
|
+
additionalComponentIds?: string[];
|
|
39
38
|
/**
|
|
40
39
|
* Optional render function to display a component when the config is loading.
|
|
41
40
|
*/
|
package/dist/provider.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
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
|
+
};
|
|
2
21
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
22
|
var t = {};
|
|
4
23
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -16,6 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
36
|
exports.useContext = exports.ConfiguredProvider = exports.Provider = void 0;
|
|
18
37
|
const react_1 = __importDefault(require("react"));
|
|
38
|
+
const Sentry = __importStar(require("@sentry/react"));
|
|
19
39
|
const hooks_1 = require("./hooks");
|
|
20
40
|
const UtilityAuthenticatedReactiveBase_1 = require("./utility/UtilityAuthenticatedReactiveBase");
|
|
21
41
|
const debug = require("debug")("reactify-search:Provider");
|
|
@@ -25,20 +45,33 @@ const defaultCredentials = {
|
|
|
25
45
|
password: "password",
|
|
26
46
|
endpoint: "https://api.search.reactify.app",
|
|
27
47
|
};
|
|
48
|
+
Sentry.init({
|
|
49
|
+
dsn: "https://f591e13196ad4d6bbcd8abbeb2e023db@o1280055.ingest.sentry.io/6482743",
|
|
50
|
+
});
|
|
28
51
|
const Provider = (_a) => {
|
|
29
52
|
var { renderBooting } = _a, props = __rest(_a, ["renderBooting"]);
|
|
30
|
-
const { config } = (0, hooks_1.useLiveConfig)(props.shopifyPermanentDomain
|
|
53
|
+
const { config } = (0, hooks_1.useLiveConfig)(props.shopifyPermanentDomain);
|
|
31
54
|
if (!config) {
|
|
32
55
|
if (renderBooting)
|
|
33
56
|
return renderBooting();
|
|
34
57
|
return null;
|
|
35
58
|
}
|
|
36
|
-
return react_1.default.createElement(
|
|
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.filterStackId)
|
|
65
|
+
scope.setTag("filterStackId", props.filterStackId);
|
|
66
|
+
if (!!props.instantSearch)
|
|
67
|
+
scope.setTag("instantSearch", true);
|
|
68
|
+
} },
|
|
69
|
+
react_1.default.createElement(exports.ConfiguredProvider, Object.assign({}, props, { config: config }))));
|
|
37
70
|
};
|
|
38
71
|
exports.Provider = Provider;
|
|
39
72
|
const ConfiguredProvider = (props) => {
|
|
40
73
|
var _a, _b;
|
|
41
|
-
const { index, config, children, collection, instantSearch,
|
|
74
|
+
const { index, config, children, collection, instantSearch, filterStackId, noReactiveBase, shopifyPermanentDomain, additionalComponentIds, onRedirect, } = props;
|
|
42
75
|
const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : defaultCredentials;
|
|
43
76
|
const theme = (_b = props.theme) !== null && _b !== void 0 ? _b : {
|
|
44
77
|
typography: {
|
|
@@ -77,13 +110,13 @@ const ConfiguredProvider = (props) => {
|
|
|
77
110
|
setSearchQuery(searchQueryFromURL);
|
|
78
111
|
}, [searchQueryFromURL]);
|
|
79
112
|
react_1.default.useEffect(() => {
|
|
80
|
-
if (searchSortFromURL && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.
|
|
113
|
+
if (searchSortFromURL && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.id) !== searchSortFromURL) {
|
|
81
114
|
setSortOption(searchSortFromURL, true);
|
|
82
115
|
}
|
|
83
116
|
}, [searchSortFromURL]);
|
|
84
117
|
react_1.default.useEffect(() => {
|
|
85
|
-
if (window.location.search === "" && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.
|
|
86
|
-
setSortOption(
|
|
118
|
+
if (window.location.search === "" && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.id)) {
|
|
119
|
+
setSortOption(sortOptions[0].id, true);
|
|
87
120
|
}
|
|
88
121
|
}, [window.location.href]);
|
|
89
122
|
const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
|
|
@@ -107,7 +140,7 @@ const ConfiguredProvider = (props) => {
|
|
|
107
140
|
// do not attempt to resolve a filter stack if in instantSearch mode
|
|
108
141
|
const filterStack = instantSearch
|
|
109
142
|
? undefined
|
|
110
|
-
: useFilterStack(config, collection,
|
|
143
|
+
: useFilterStack(config, collection, filterStackId);
|
|
111
144
|
const curation = useCuration(config, collection, searchQuery);
|
|
112
145
|
const contextValue = react_1.default.useMemo(() => ({
|
|
113
146
|
index,
|
|
@@ -126,7 +159,7 @@ const ConfiguredProvider = (props) => {
|
|
|
126
159
|
setShowInstantSearchResults,
|
|
127
160
|
theme,
|
|
128
161
|
curation,
|
|
129
|
-
|
|
162
|
+
additionalComponentIds,
|
|
130
163
|
instantSearch: !!instantSearch,
|
|
131
164
|
showInstantSearchResults: !!showInstantSearchResults && !!searchQuery,
|
|
132
165
|
}), [
|
|
@@ -143,7 +176,7 @@ const ConfiguredProvider = (props) => {
|
|
|
143
176
|
onRedirect,
|
|
144
177
|
submitSearch,
|
|
145
178
|
instantSearch,
|
|
146
|
-
|
|
179
|
+
additionalComponentIds,
|
|
147
180
|
showInstantSearchResults,
|
|
148
181
|
theme,
|
|
149
182
|
]);
|
|
@@ -167,7 +200,7 @@ const useSortState = (config, collection) => {
|
|
|
167
200
|
.sort((a, b) => `${a.position}`.localeCompare(`${b.position}`))
|
|
168
201
|
.filter(({ visibility }) => ["all", type].includes(visibility));
|
|
169
202
|
}, [config, collection]);
|
|
170
|
-
const [sortOptionState, setSortOptionState] = react_1.default.useState((_a = sortOptions[0]) === null || _a === void 0 ? void 0 : _a.
|
|
203
|
+
const [sortOptionState, setSortOptionState] = react_1.default.useState((_a = sortOptions[0]) === null || _a === void 0 ? void 0 : _a.id);
|
|
171
204
|
const sortOption = react_1.default.useMemo(() => sortOptions.find(({ id }) => id === sortOptionState) || sortOptions[0], [sortOptions, sortOptionState]);
|
|
172
205
|
const setSortOption = react_1.default.useCallback((sortOptionId, ignoreHistoryState = false) => {
|
|
173
206
|
setSortOptionState(sortOptionId);
|
|
@@ -187,37 +220,22 @@ const useSortState = (config, collection) => {
|
|
|
187
220
|
// @todo we need a better name for the overall page like "Filter Stack" or something,
|
|
188
221
|
// each block is then called a filter so like Size would be a "Filter" and then each
|
|
189
222
|
// value within it is a "Filter Option"
|
|
190
|
-
const useFilterStack = (config, collection,
|
|
191
|
-
|
|
192
|
-
// select
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (matchingFilterStack) {
|
|
198
|
-
return matchingFilterStack;
|
|
199
|
-
}
|
|
223
|
+
const useFilterStack = (config, collection, filterStackId) => react_1.default.useMemo(() => {
|
|
224
|
+
var _a;
|
|
225
|
+
// manually select filter stack by ID if provided
|
|
226
|
+
if (filterStackId) {
|
|
227
|
+
const filterStack = config.filters.find((filter) => filterStackId === filter.id);
|
|
228
|
+
if (filterStack)
|
|
229
|
+
return filterStack;
|
|
200
230
|
}
|
|
201
|
-
// select filter stack by collection if provided
|
|
231
|
+
// automatically select filter stack by collection if provided
|
|
202
232
|
if (collection === null || collection === void 0 ? void 0 : collection.handle) {
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
// select filter with "default" handle
|
|
209
|
-
let matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStack.handle === "default");
|
|
210
|
-
if (matchingFilterStack) {
|
|
211
|
-
return matchingFilterStack;
|
|
233
|
+
const filterStack = config.filters.find((filter) => { var _a; return (_a = filter.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
|
|
234
|
+
if (filterStack)
|
|
235
|
+
return filterStack;
|
|
212
236
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (matchingFilterStack) {
|
|
216
|
-
return matchingFilterStack;
|
|
217
|
-
}
|
|
218
|
-
// select any available filter as a last resort
|
|
219
|
-
matchingFilterStack = config.filters[0];
|
|
220
|
-
return matchingFilterStack;
|
|
237
|
+
const type = !!collection ? "collection" : "search";
|
|
238
|
+
return ((_a = config.filters.find((filter) => type === filter.type)) !== null && _a !== void 0 ? _a : config.filters[0]);
|
|
221
239
|
}, [config, collection]);
|
|
222
240
|
const useCuration = (config, collection, searchQuery) => react_1.default.useMemo(() => {
|
|
223
241
|
debug("resolveCuration.start", { config, collection, searchQuery });
|
|
@@ -107,7 +107,6 @@ export interface DefinedField {
|
|
|
107
107
|
export interface Sort {
|
|
108
108
|
id: string;
|
|
109
109
|
name: string;
|
|
110
|
-
handle: string;
|
|
111
110
|
field: string;
|
|
112
111
|
position: number;
|
|
113
112
|
enabled: boolean;
|
|
@@ -117,7 +116,6 @@ export interface Sort {
|
|
|
117
116
|
export interface Filter {
|
|
118
117
|
id: string;
|
|
119
118
|
name: string;
|
|
120
|
-
handle: string;
|
|
121
119
|
enabled: boolean;
|
|
122
120
|
pageSize: number;
|
|
123
121
|
keywords: string[];
|
|
@@ -137,7 +135,6 @@ export interface FilterOption {
|
|
|
137
135
|
field: string;
|
|
138
136
|
id: string;
|
|
139
137
|
name: string;
|
|
140
|
-
handle: string;
|
|
141
138
|
position: number;
|
|
142
139
|
settingsCollapsedDesktop: boolean;
|
|
143
140
|
settingsCollapsedMobile: boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usereactify/search",
|
|
3
3
|
"description": "React UI library for Reactify Search",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.1.0-beta.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"watch": "tsc --watch",
|
|
14
14
|
"release": "standard-version",
|
|
15
|
-
"patch": "standard-version -
|
|
15
|
+
"release:patch": "standard-version --release-as patch",
|
|
16
|
+
"release:beta": "standard-version --release-as minor --prerelease beta",
|
|
16
17
|
"build": "rimraf dist && tsc",
|
|
17
18
|
"prettier": "prettier --write .",
|
|
18
19
|
"storybook": "start-storybook -p 6006",
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
]
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
34
|
+
"@sentry/react": "7.1.1",
|
|
33
35
|
"ahooks": "2.10.11",
|
|
34
36
|
"axios": "0.26.1",
|
|
35
37
|
"currency.js": "2.0.4",
|