@usereactify/search 4.4.0-beta.0 → 5.0.0-beta.1

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 (104) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/package.json +8 -10
  3. package/dist/filter/Filter.d.ts +0 -12
  4. package/dist/filter/Filter.js +0 -71
  5. package/dist/filter/FilterList.d.ts +0 -4
  6. package/dist/filter/FilterList.js +0 -15
  7. package/dist/filter/FilterStack.d.ts +0 -11
  8. package/dist/filter/FilterStack.js +0 -25
  9. package/dist/filter/index.d.ts +0 -3
  10. package/dist/filter/index.js +0 -15
  11. package/dist/hooks/index.d.ts +0 -14
  12. package/dist/hooks/index.js +0 -26
  13. package/dist/hooks/reactivesearch/index.d.ts +0 -5
  14. package/dist/hooks/reactivesearch/index.js +0 -17
  15. package/dist/hooks/reactivesearch/useReactiveBaseProps.d.ts +0 -7
  16. package/dist/hooks/reactivesearch/useReactiveBaseProps.js +0 -43
  17. package/dist/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +0 -28
  18. package/dist/hooks/reactivesearch/useReactiveDataSearchProps.js +0 -71
  19. package/dist/hooks/reactivesearch/useReactiveFilterListProps.d.ts +0 -68
  20. package/dist/hooks/reactivesearch/useReactiveFilterListProps.js +0 -106
  21. package/dist/hooks/reactivesearch/useReactiveReactProp.d.ts +0 -3
  22. package/dist/hooks/reactivesearch/useReactiveReactProp.js +0 -25
  23. package/dist/hooks/reactivesearch/useReactiveResultListProps.d.ts +0 -19
  24. package/dist/hooks/reactivesearch/useReactiveResultListProps.js +0 -32
  25. package/dist/hooks/useAnalytics.d.ts +0 -95
  26. package/dist/hooks/useAnalytics.js +0 -110
  27. package/dist/hooks/useCollection.d.ts +0 -1
  28. package/dist/hooks/useCollection.js +0 -6
  29. package/dist/hooks/useConfig.d.ts +0 -1
  30. package/dist/hooks/useConfig.js +0 -6
  31. package/dist/hooks/useCuration.d.ts +0 -1
  32. package/dist/hooks/useCuration.js +0 -6
  33. package/dist/hooks/useFilterCollapsedState.d.ts +0 -8
  34. package/dist/hooks/useFilterCollapsedState.js +0 -27
  35. package/dist/hooks/useFilterListProps.d.ts +0 -22
  36. package/dist/hooks/useFilterListProps.js +0 -35
  37. package/dist/hooks/useFilterStack.d.ts +0 -1
  38. package/dist/hooks/useFilterStack.js +0 -6
  39. package/dist/hooks/useFilters.d.ts +0 -1
  40. package/dist/hooks/useFilters.js +0 -17
  41. package/dist/hooks/useLiveConfig.d.ts +0 -4
  42. package/dist/hooks/useLiveConfig.js +0 -74
  43. package/dist/hooks/usePages.d.ts +0 -10
  44. package/dist/hooks/usePages.js +0 -97
  45. package/dist/hooks/useProductPrice.d.ts +0 -12
  46. package/dist/hooks/useProductPrice.js +0 -61
  47. package/dist/hooks/useSearch.d.ts +0 -8
  48. package/dist/hooks/useSearch.js +0 -16
  49. package/dist/hooks/useSort.d.ts +0 -5
  50. package/dist/hooks/useSort.js +0 -24
  51. package/dist/index.d.ts +0 -9
  52. package/dist/index.js +0 -24
  53. package/dist/provider.d.ts +0 -78
  54. package/dist/provider.js +0 -287
  55. package/dist/result/ResultCard.d.ts +0 -14
  56. package/dist/result/ResultCard.js +0 -66
  57. package/dist/result/ResultCardCallout.d.ts +0 -13
  58. package/dist/result/ResultCardCallout.js +0 -53
  59. package/dist/result/ResultList.d.ts +0 -34
  60. package/dist/result/ResultList.js +0 -93
  61. package/dist/result/ResultLoadMoreButton.d.ts +0 -10
  62. package/dist/result/ResultLoadMoreButton.js +0 -61
  63. package/dist/result/ResultPagination.d.ts +0 -10
  64. package/dist/result/ResultPagination.js +0 -60
  65. package/dist/result/ResultPaginationNextPrev.d.ts +0 -8
  66. package/dist/result/ResultPaginationNextPrev.js +0 -30
  67. package/dist/result/ResultStateProvider.d.ts +0 -7
  68. package/dist/result/ResultStateProvider.js +0 -10
  69. package/dist/result/index.d.ts +0 -6
  70. package/dist/result/index.js +0 -18
  71. package/dist/search/SearchInput.d.ts +0 -9
  72. package/dist/search/SearchInput.js +0 -17
  73. package/dist/search/index.d.ts +0 -1
  74. package/dist/search/index.js +0 -13
  75. package/dist/sensor/SensorCollection.d.ts +0 -2
  76. package/dist/sensor/SensorCollection.js +0 -41
  77. package/dist/sensor/SensorInventoryAvailable.d.ts +0 -2
  78. package/dist/sensor/SensorInventoryAvailable.js +0 -52
  79. package/dist/sensor/SensorPublished.d.ts +0 -2
  80. package/dist/sensor/SensorPublished.js +0 -16
  81. package/dist/sensor/SensorSearch.d.ts +0 -2
  82. package/dist/sensor/SensorSearch.js +0 -82
  83. package/dist/sensor/SensorSort.d.ts +0 -2
  84. package/dist/sensor/SensorSort.js +0 -205
  85. package/dist/sensor/SensorSortScore.d.ts +0 -2
  86. package/dist/sensor/SensorSortScore.js +0 -12
  87. package/dist/sensor/SensorStack.d.ts +0 -2
  88. package/dist/sensor/SensorStack.js +0 -31
  89. package/dist/sensor/index.d.ts +0 -8
  90. package/dist/sensor/index.js +0 -29
  91. package/dist/types/config.d.ts +0 -25
  92. package/dist/types/config.js +0 -2
  93. package/dist/types/elastic.d.ts +0 -209
  94. package/dist/types/elastic.js +0 -18
  95. package/dist/types/firestore.d.ts +0 -280
  96. package/dist/types/firestore.js +0 -18
  97. package/dist/types/graphql.d.ts +0 -26545
  98. package/dist/types/graphql.js +0 -4687
  99. package/dist/types/reactivesearch.d.ts +0 -73
  100. package/dist/types/reactivesearch.js +0 -2
  101. package/dist/types/shopify.d.ts +0 -21
  102. package/dist/types/shopify.js +0 -27
  103. package/dist/utility/UtilityAuthenticatedReactiveBase.d.ts +0 -2
  104. package/dist/utility/UtilityAuthenticatedReactiveBase.js +0 -14
@@ -1,97 +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.usePages = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const hooks_1 = require("../hooks");
9
- const usePages = (props) => {
10
- const { pages, setPage, totalPages, currentPage } = props;
11
- const { track } = (0, hooks_1.useAnalytics)();
12
- const buildPagePath = react_1.default.useCallback((page) => {
13
- const currentPath = window.location.pathname;
14
- return currentPath.includes("page=")
15
- ? currentPath.replace(/page=\d+/g, `page=${page}`)
16
- : `${currentPath}${currentPath.includes("?") ? "&" : "?"}page=${page}`;
17
- }, []);
18
- const pagesToShow = react_1.default.useMemo(() => getPages(pages, totalPages, currentPage), [pages, totalPages, currentPage]);
19
- // default currentPage is zero-indexed, actualCurrentPage is one-indexed
20
- const actualCurrentPage = react_1.default.useMemo(() => currentPage + 1, [currentPage]);
21
- const hasNextPage = react_1.default.useMemo(() => actualCurrentPage < totalPages, [actualCurrentPage, totalPages]);
22
- const handleNextPage = react_1.default.useCallback((event) => {
23
- event === null || event === void 0 ? void 0 : event.preventDefault();
24
- if (!hasNextPage)
25
- return;
26
- setPage(currentPage + 1);
27
- track({
28
- eventName: "paginationChange",
29
- payload: {
30
- page: currentPage + 1,
31
- source: window.location.pathname.includes("/search")
32
- ? "search"
33
- : "collection",
34
- },
35
- });
36
- }, [hasNextPage, currentPage, setPage]);
37
- const hasPreviousPage = react_1.default.useMemo(() => actualCurrentPage > 1, [actualCurrentPage]);
38
- const handlePreviousPage = react_1.default.useCallback((event) => {
39
- event === null || event === void 0 ? void 0 : event.preventDefault();
40
- if (!hasPreviousPage)
41
- return;
42
- setPage(currentPage - 1);
43
- track({
44
- eventName: "paginationChange",
45
- payload: {
46
- page: currentPage - 1,
47
- source: window.location.pathname.includes("/search")
48
- ? "search"
49
- : "collection",
50
- },
51
- });
52
- }, [hasPreviousPage, currentPage, setPage]);
53
- return react_1.default.useMemo(() => ({
54
- pagesToShow,
55
- hasNextPage,
56
- buildPagePath,
57
- handleNextPage,
58
- hasPreviousPage,
59
- actualCurrentPage,
60
- handlePreviousPage,
61
- }), [
62
- pagesToShow,
63
- hasNextPage,
64
- buildPagePath,
65
- handleNextPage,
66
- hasPreviousPage,
67
- actualCurrentPage,
68
- handlePreviousPage,
69
- ]);
70
- };
71
- exports.usePages = usePages;
72
- // get a list of pages to display buttons for
73
- // @todo this is super hacky and needs to be cleaned up
74
- const getPages = (pages, totalPages, currentPage) => {
75
- const pagesToShow = pages > totalPages ? totalPages : pages;
76
- const buffer = Math.floor(pagesToShow / 2);
77
- let list = [];
78
- let start = 0;
79
- if (totalPages <= 5 || currentPage < buffer + 1) {
80
- start = 0;
81
- }
82
- else {
83
- if (totalPages - buffer <= currentPage) {
84
- start =
85
- currentPage + 1 === totalPages
86
- ? currentPage - (pagesToShow - 1)
87
- : currentPage - (buffer + buffer / 2);
88
- }
89
- else {
90
- start = currentPage - buffer;
91
- }
92
- }
93
- Array.apply(null, Array(pagesToShow)).map((item, index) => {
94
- list.push(start + index);
95
- });
96
- return list;
97
- };
@@ -1,12 +0,0 @@
1
- import currency from "currency.js";
2
- import { ElasticProduct } from "../types/elastic";
3
- declare type PriceResponse = {
4
- onSale: boolean;
5
- price?: currency;
6
- currencyCode: string;
7
- formattedPrice?: string;
8
- compareAtPrice?: currency;
9
- formattedCompareAtPrice?: string;
10
- };
11
- export declare const useProductPrice: (product: ElasticProduct) => PriceResponse;
12
- export {};
@@ -1,61 +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.useProductPrice = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const currency_js_1 = __importDefault(require("currency.js"));
9
- const useProductPrice = (product) => react_1.default.useMemo(() => {
10
- var _a, _b, _c, _d;
11
- const variant = (_a = product.variants) === null || _a === void 0 ? void 0 : _a[0];
12
- if (!variant) {
13
- return {
14
- onSale: false,
15
- price: undefined,
16
- currencyCode: "AUD",
17
- compareAtPrice: undefined,
18
- };
19
- }
20
- // @todo select the appropriate currency
21
- const priceSet = (_b = variant.presentment_prices) === null || _b === void 0 ? void 0 : _b[0];
22
- if (!priceSet || !priceSet.price) {
23
- return {
24
- onSale: false,
25
- price: undefined,
26
- currencyCode: "AUD",
27
- compareAtPrice: undefined,
28
- };
29
- }
30
- const currencyCode = (_c = priceSet.price.currency_code) !== null && _c !== void 0 ? _c : "AUD";
31
- const price = priceSet.price.amount
32
- ? (0, currency_js_1.default)(priceSet.price.amount)
33
- : undefined;
34
- const formattedPrice = price ? formatPrice(price, currencyCode) : undefined;
35
- const compareAtPrice = ((_d = priceSet.compare_at_price) === null || _d === void 0 ? void 0 : _d.amount)
36
- ? (0, currency_js_1.default)(priceSet.compare_at_price.amount)
37
- : undefined;
38
- const formattedCompareAtPrice = compareAtPrice
39
- ? formatPrice(compareAtPrice, currencyCode)
40
- : undefined;
41
- const onSale = !!compareAtPrice && !!price && compareAtPrice.intValue > price.intValue;
42
- return {
43
- price,
44
- onSale,
45
- currencyCode,
46
- compareAtPrice,
47
- formattedPrice,
48
- formattedCompareAtPrice,
49
- };
50
- }, [product]);
51
- exports.useProductPrice = useProductPrice;
52
- const formatPrice = (price, currencyCode) => {
53
- let priceString = new Intl.NumberFormat("en-AU", {
54
- style: "currency",
55
- currency: currencyCode,
56
- }).format(price.value);
57
- if ("AUD" === currencyCode) {
58
- priceString = `AU ${priceString}`;
59
- }
60
- return priceString;
61
- };
@@ -1,8 +0,0 @@
1
- export declare const useSearch: () => {
2
- searchQuery: string | undefined;
3
- submitSearch: (localSearchQuery?: string | undefined) => void;
4
- instantSearch: boolean;
5
- setSearchQuery: (searchQuery: string) => void;
6
- showInstantSearchResults: boolean;
7
- setShowInstantSearchResults: (showInstantSearchResults: boolean) => void;
8
- };
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSearch = void 0;
4
- const provider_1 = require("../provider");
5
- const useSearch = () => {
6
- const { searchQuery, submitSearch, setSearchQuery, instantSearch, showInstantSearchResults, setShowInstantSearchResults, } = (0, provider_1.useContext)();
7
- return {
8
- searchQuery,
9
- submitSearch,
10
- instantSearch,
11
- setSearchQuery,
12
- showInstantSearchResults,
13
- setShowInstantSearchResults,
14
- };
15
- };
16
- exports.useSearch = useSearch;
@@ -1,5 +0,0 @@
1
- export declare const useSort: () => {
2
- sortOption: import("..").ConfigSort | undefined;
3
- sortOptions: import("..").ConfigSort[];
4
- setSortOption: (sortOptionHandle: string) => void;
5
- };
@@ -1,24 +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.useSort = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const provider_1 = require("../provider");
9
- const hooks_1 = require("../hooks");
10
- const useSort = () => {
11
- const { track } = (0, hooks_1.useAnalytics)();
12
- const { sortOption, sortOptions, setSortOption } = (0, provider_1.useContext)();
13
- const handleSortChange = react_1.default.useCallback((sortOptionHandle) => {
14
- setSortOption(sortOptionHandle);
15
- track({
16
- eventName: "sortChange",
17
- payload: {
18
- type: sortOptionHandle,
19
- },
20
- });
21
- }, [track, setSortOption]);
22
- return { sortOption, sortOptions, setSortOption: handleSortChange };
23
- };
24
- exports.useSort = useSort;
package/dist/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export * from "./hooks";
2
- export * from "./filter";
3
- export * from "./sensor";
4
- export * from "./result";
5
- export * from "./search";
6
- export * from "./provider";
7
- export * from "./types/config";
8
- export * from "./types/elastic";
9
- export * from "./types/reactivesearch";
package/dist/index.js DELETED
@@ -1,24 +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 __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("./hooks"), exports);
14
- __exportStar(require("./filter"), exports);
15
- __exportStar(require("./sensor"), exports);
16
- __exportStar(require("./result"), exports);
17
- __exportStar(require("./search"), exports);
18
- __exportStar(require("./provider"), exports);
19
- __exportStar(require("./types/config"), exports);
20
- __exportStar(require("./types/elastic"), exports);
21
- __exportStar(require("./types/reactivesearch"), exports);
22
- const package_json_1 = require("../package.json");
23
- const debug = require("debug")("reactify-search:");
24
- debug(`${package_json_1.name} v${package_json_1.version}`);
@@ -1,78 +0,0 @@
1
- import React from "react";
2
- import type { Config, ConfigSort, ConfigFilter, ConfigCuration } from "./types/config";
3
- declare type Context = {
4
- index: string;
5
- config: Config;
6
- shopifyPermanentDomain: string;
7
- sortOption: ConfigSort | undefined;
8
- sortOptions: ConfigSort[];
9
- searchQuery?: string;
10
- filterStack?: ConfigFilter;
11
- collection?: Collection;
12
- instantSearch: boolean;
13
- credentials: Credentials;
14
- onRedirect?: (type: "redirect" | "search", url: string) => void;
15
- submitSearch: (localSearchQuery?: string) => void;
16
- setSearchQuery: (searchQuery: string) => void;
17
- setSortOption: (sortOptionHandle: string) => void;
18
- showInstantSearchResults: boolean;
19
- setShowInstantSearchResults: (showInstantSearchResults: boolean) => void;
20
- theme?: Theme;
21
- curation?: ConfigCuration;
22
- /** Array of additional component IDs managed outside of Reactify Search */
23
- additionalComponentHandles?: string[];
24
- };
25
- declare const Context: React.Context<Context | undefined>;
26
- declare type Props = {
27
- index: string;
28
- shopifyPermanentDomain: string;
29
- configId?: string;
30
- filterStackHandle?: string;
31
- collection?: Collection;
32
- noReactiveBase?: boolean;
33
- instantSearch?: boolean;
34
- onRedirect?: (type: "redirect" | "search", url: string) => void;
35
- credentials?: Credentials;
36
- theme?: Theme;
37
- /** Array of additional component IDs managed outside of Reactify Search */
38
- additionalComponentHandles?: string[];
39
- /**
40
- * Optional render function to display a component when the config is loading.
41
- */
42
- renderBooting?: () => JSX.Element | null;
43
- };
44
- export declare const Provider: React.FC<Props>;
45
- export declare const ConfiguredProvider: React.FC<Omit<Props, "renderBooting"> & {
46
- config: Config;
47
- }>;
48
- export declare const useContext: () => Context;
49
- export interface Collection {
50
- id: number;
51
- handle: string;
52
- title: string;
53
- }
54
- export interface Credentials {
55
- username: string;
56
- password: string;
57
- endpoint: string;
58
- }
59
- export interface Theme {
60
- component?: any;
61
- colors?: ThemeColors;
62
- typography?: ThemeTypography;
63
- }
64
- export interface ThemeTypography {
65
- fontFamily?: string;
66
- fontSize?: string;
67
- }
68
- export interface ThemeColors {
69
- alertColor?: string;
70
- backgroundColor?: string;
71
- borderColor?: string;
72
- extColor?: string;
73
- primaryTextColor?: string;
74
- primaryColor?: string;
75
- textColor?: string;
76
- titleColor?: string;
77
- }
78
- export {};
package/dist/provider.js DELETED
@@ -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 {};