@usereactify/search 5.0.0-beta.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 (143) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/package.json +66 -0
  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/components/Filter/index.d.ts +2 -0
  30. package/dist/src/components/Filter/index.js +14 -0
  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/components/Result/ResultCardCallout.js +46 -0
  37. package/dist/src/components/Result/ResultCardProduct.d.ts +13 -0
  38. package/dist/src/components/Result/ResultCardProduct.js +63 -0
  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/components/Result/ResultStateProvider.js +10 -0
  49. package/dist/src/components/Result/index.d.ts +7 -0
  50. package/dist/src/components/Result/index.js +19 -0
  51. package/dist/src/components/Search/SearchInput.d.ts +8 -0
  52. package/dist/src/components/Search/SearchInput.js +17 -0
  53. package/dist/src/components/Search/index.d.ts +1 -0
  54. package/dist/src/components/Search/index.js +13 -0
  55. package/dist/src/components/Sensor/SensorCollection.d.ts +2 -0
  56. package/dist/src/components/Sensor/SensorCollection.js +44 -0
  57. package/dist/src/components/Sensor/SensorInventoryAvailable.d.ts +2 -0
  58. package/dist/src/components/Sensor/SensorInventoryAvailable.js +52 -0
  59. package/dist/src/components/Sensor/SensorPublished.d.ts +2 -0
  60. package/dist/src/components/Sensor/SensorPublished.js +16 -0
  61. package/dist/src/components/Sensor/SensorSearch.d.ts +2 -0
  62. package/dist/src/components/Sensor/SensorSearch.js +82 -0
  63. package/dist/src/components/Sensor/SensorSort.d.ts +2 -0
  64. package/dist/src/components/Sensor/SensorSort.js +204 -0
  65. package/dist/src/components/Sensor/SensorSortScore.d.ts +2 -0
  66. package/dist/src/components/Sensor/SensorSortScore.js +12 -0
  67. package/dist/src/components/Sensor/SensorStack.d.ts +3 -0
  68. package/dist/src/components/Sensor/SensorStack.js +31 -0
  69. package/dist/src/components/Sensor/index.d.ts +8 -0
  70. package/dist/src/components/Sensor/index.js +29 -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/components/Utility/UtilityAuthenticatedReactiveBase.d.ts +2 -0
  76. package/dist/src/components/Utility/UtilityAuthenticatedReactiveBase.js +14 -0
  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 +14 -0
  82. package/dist/src/hooks/index.js +26 -0
  83. package/dist/src/hooks/reactivesearch/index.d.ts +8 -0
  84. package/dist/src/hooks/reactivesearch/index.js +20 -0
  85. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.d.ts +7 -0
  86. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js +43 -0
  87. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +26 -0
  88. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js +70 -0
  89. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.d.ts +73 -0
  90. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js +21 -0
  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.d.ts +3 -0
  98. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +25 -0
  99. package/dist/src/hooks/reactivesearch/useReactiveResultStackProps.d.ts +17 -0
  100. package/dist/src/hooks/reactivesearch/useReactiveResultStackProps.js +31 -0
  101. package/dist/src/hooks/useAnalytics.d.ts +95 -0
  102. package/dist/src/hooks/useAnalytics.js +110 -0
  103. package/dist/src/hooks/useConfig.d.ts +4 -0
  104. package/dist/src/hooks/useConfig.js +81 -0
  105. package/dist/src/hooks/useCuration.d.ts +2 -0
  106. package/dist/src/hooks/useCuration.js +52 -0
  107. package/dist/src/hooks/useFilterCollapsedState.d.ts +8 -0
  108. package/dist/src/hooks/useFilterCollapsedState.js +27 -0
  109. package/dist/src/hooks/useFilterListProps.d.ts +12 -0
  110. package/dist/src/hooks/useFilterListProps.js +35 -0
  111. package/dist/src/hooks/useFilterStack.d.ts +2 -0
  112. package/dist/src/hooks/useFilterStack.js +46 -0
  113. package/dist/src/hooks/useFilters.d.ts +4 -0
  114. package/dist/src/hooks/useFilters.js +22 -0
  115. package/dist/src/hooks/usePagination.d.ts +14 -0
  116. package/dist/src/hooks/usePagination.js +97 -0
  117. package/dist/src/hooks/usePaginationLoadMore.d.ts +15 -0
  118. package/dist/src/hooks/usePaginationLoadMore.js +37 -0
  119. package/dist/src/hooks/useProductPrice.d.ts +10 -0
  120. package/dist/src/hooks/useProductPrice.js +63 -0
  121. package/dist/src/hooks/useReactifySearchContext.d.ts +78 -0
  122. package/dist/src/hooks/useReactifySearchContext.js +10 -0
  123. package/dist/src/hooks/useSearch.d.ts +8 -0
  124. package/dist/src/hooks/useSearch.js +36 -0
  125. package/dist/src/hooks/useSortby.d.ts +6 -0
  126. package/dist/src/hooks/useSortby.js +41 -0
  127. package/dist/src/index.d.ts +3 -0
  128. package/dist/src/index.js +18 -0
  129. package/dist/src/types/config.d.ts +26 -0
  130. package/dist/src/types/config.js +2 -0
  131. package/dist/src/types/elastic.d.ts +209 -0
  132. package/dist/src/types/elastic.js +18 -0
  133. package/dist/src/types/firestore.d.ts +280 -0
  134. package/dist/src/types/firestore.js +18 -0
  135. package/dist/src/types/graphql.d.ts +26545 -0
  136. package/dist/src/types/graphql.js +4687 -0
  137. package/dist/src/types/index.d.ts +3 -0
  138. package/dist/src/types/index.js +15 -0
  139. package/dist/src/types/reactivesearch.d.ts +73 -0
  140. package/dist/src/types/reactivesearch.js +2 -0
  141. package/dist/src/types/shopify.d.ts +21 -0
  142. package/dist/src/types/shopify.js +27 -0
  143. package/package.json +3 -2
@@ -0,0 +1,25 @@
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.useReactiveReactProp = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const hooks_1 = require("../../hooks");
9
+ const components_1 = require("../../components");
10
+ const useReactiveReactProp = (currentHandle) => {
11
+ const { options } = (0, hooks_1.useReactifySearchContext)();
12
+ const { filters } = (0, hooks_1.useFilters)();
13
+ return react_1.default.useMemo(() => {
14
+ var _a;
15
+ return {
16
+ and: [
17
+ "SearchInput",
18
+ ...components_1.SENSOR_IDS,
19
+ ...((_a = options.additionalComponentHandles) !== null && _a !== void 0 ? _a : []),
20
+ ...filters.map((filter) => filter.handle),
21
+ ].filter((handle) => handle !== currentHandle),
22
+ };
23
+ }, [filters, currentHandle, options.additionalComponentHandles]);
24
+ };
25
+ exports.useReactiveReactProp = useReactiveReactProp;
@@ -0,0 +1,17 @@
1
+ export declare const useReactiveResultStackProps: (options: {
2
+ pageSize?: number;
3
+ }) => {
4
+ size: number;
5
+ URLParams: boolean;
6
+ showLoader: boolean;
7
+ dataField: string;
8
+ showResultStats: boolean;
9
+ react: {
10
+ and: string[];
11
+ };
12
+ componentId: string;
13
+ scrollOnChange: boolean;
14
+ pagination: boolean;
15
+ infiniteScroll: boolean;
16
+ renderNoResults: () => null;
17
+ };
@@ -0,0 +1,31 @@
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.useReactiveResultStackProps = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const hooks_1 = require("../../hooks");
9
+ const useReactiveReactProp_1 = require("./useReactiveReactProp");
10
+ const useReactiveResultStackProps = (options) => {
11
+ const filterStack = (0, hooks_1.useFilterStack)();
12
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)();
13
+ const size = react_1.default.useMemo(() => {
14
+ var _a, _b;
15
+ return (_b = (_a = options.pageSize) !== null && _a !== void 0 ? _a : filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) !== null && _b !== void 0 ? _b : 20;
16
+ }, [options.pageSize, filterStack]);
17
+ return react_1.default.useMemo(() => ({
18
+ size,
19
+ URLParams: true,
20
+ showLoader: false,
21
+ dataField: "title",
22
+ showResultStats: false,
23
+ react: reactiveReactProp,
24
+ componentId: "page",
25
+ scrollOnChange: false,
26
+ pagination: (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) !== "infinite_scroll",
27
+ infiniteScroll: (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) === "infinite_scroll",
28
+ renderNoResults: () => null, // always use only render, otherwise both are shown
29
+ }), [filterStack, reactiveReactProp, options.pageSize]);
30
+ };
31
+ exports.useReactiveResultStackProps = useReactiveResultStackProps;
@@ -0,0 +1,95 @@
1
+ export declare const useAnalytics: () => {
2
+ track: (event: TrackEvent) => Promise<import("axios").AxiosResponse<any, any> | undefined>;
3
+ };
4
+ export declare type TrackEvent = TrackEvent.SearchEvent | TrackEvent.ZeroResultsEvent | TrackEvent.ViewProductEvent | TrackEvent.ClickProductEvent | TrackEvent.ViewPromotionEvent | TrackEvent.ClickPromotionEvent | TrackEvent.PaginationChangeEvent | TrackEvent.SortChangeEvent | TrackEvent.FilterChangeEvent;
5
+ export declare namespace TrackEvent {
6
+ interface SearchEvent {
7
+ eventName: "search";
8
+ payload: SearchEvent.Payload;
9
+ }
10
+ namespace SearchEvent {
11
+ interface Payload {
12
+ searchTerm: string;
13
+ }
14
+ }
15
+ interface ZeroResultsEvent {
16
+ eventName: "zeroResults";
17
+ payload: ZeroResultsEvent.Payload;
18
+ }
19
+ namespace ZeroResultsEvent {
20
+ interface Payload {
21
+ searchTerm: string;
22
+ }
23
+ }
24
+ interface ViewProductEvent {
25
+ eventName: "viewProduct";
26
+ payload: ViewProductEvent.Payload;
27
+ }
28
+ namespace ViewProductEvent {
29
+ interface Payload {
30
+ elasticProduct: ElasticProduct;
31
+ }
32
+ }
33
+ interface ClickProductEvent {
34
+ eventName: "clickProduct";
35
+ payload: ClickProductEvent.Payload;
36
+ }
37
+ namespace ClickProductEvent {
38
+ interface Payload {
39
+ elasticProduct: ElasticProduct;
40
+ }
41
+ }
42
+ interface ViewPromotionEvent {
43
+ eventName: "viewPromotion";
44
+ payload: ViewPromotionEvent.Payload;
45
+ }
46
+ namespace ViewPromotionEvent {
47
+ interface Payload {
48
+ link: string;
49
+ title: string;
50
+ }
51
+ }
52
+ interface ClickPromotionEvent {
53
+ eventName: "clickPromotion";
54
+ payload: ClickPromotionEvent.Payload;
55
+ }
56
+ namespace ClickPromotionEvent {
57
+ interface Payload {
58
+ link: string;
59
+ title: string;
60
+ }
61
+ }
62
+ interface PaginationChangeEvent {
63
+ eventName: "paginationChange";
64
+ payload: PaginationChangeEvent.Payload;
65
+ }
66
+ namespace PaginationChangeEvent {
67
+ interface Payload {
68
+ page: number;
69
+ source: "search" | "collection";
70
+ }
71
+ }
72
+ interface SortChangeEvent {
73
+ eventName: "sortChange";
74
+ payload: SortChangeEvent.Payload;
75
+ }
76
+ namespace SortChangeEvent {
77
+ interface Payload {
78
+ type: string;
79
+ }
80
+ }
81
+ interface FilterChangeEvent {
82
+ eventName: "filterChange";
83
+ payload: FilterChangeEvent.Payload;
84
+ }
85
+ namespace FilterChangeEvent {
86
+ interface Payload {
87
+ name: string;
88
+ value: string;
89
+ }
90
+ }
91
+ interface ElasticProduct {
92
+ id: number;
93
+ title: string;
94
+ }
95
+ }
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.useAnalytics = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const hooks_1 = require("../hooks");
18
+ const useAnalytics = () => {
19
+ const { options } = (0, hooks_1.useReactifySearchContext)();
20
+ const url = "https://analytics.search.reactify.app/record/";
21
+ const track = (event) => __awaiter(void 0, void 0, void 0, function* () {
22
+ if (!options.shopifyPermanentDomain) {
23
+ console.warn(new Error('Unable to send tracking event, missing value for "shopifyPermanentDomain".'));
24
+ return;
25
+ }
26
+ const events = getTrackEvents(event);
27
+ return axios_1.default.post(url, { events }, { headers: { "X-Reactify-Tenant": options.shopifyPermanentDomain } });
28
+ });
29
+ return { track };
30
+ };
31
+ exports.useAnalytics = useAnalytics;
32
+ function getTrackEvents(event) {
33
+ const { eventName } = event;
34
+ let events = [];
35
+ switch (eventName) {
36
+ case "search":
37
+ events = [
38
+ {
39
+ eventName,
40
+ payload: event.payload,
41
+ },
42
+ ];
43
+ break;
44
+ case "zeroResults":
45
+ events = [
46
+ {
47
+ eventName,
48
+ payload: event.payload,
49
+ },
50
+ ];
51
+ break;
52
+ case "viewProduct":
53
+ events = [
54
+ {
55
+ eventName,
56
+ payload: event.payload,
57
+ },
58
+ ];
59
+ break;
60
+ case "clickProduct":
61
+ events = [
62
+ {
63
+ eventName,
64
+ payload: event.payload,
65
+ },
66
+ ];
67
+ break;
68
+ case "viewPromotion":
69
+ events = [
70
+ {
71
+ eventName,
72
+ payload: event.payload,
73
+ },
74
+ ];
75
+ break;
76
+ case "clickPromotion":
77
+ events = [
78
+ {
79
+ eventName,
80
+ payload: event.payload,
81
+ },
82
+ ];
83
+ break;
84
+ case "paginationChange":
85
+ events = [
86
+ {
87
+ eventName,
88
+ payload: event.payload,
89
+ },
90
+ ];
91
+ break;
92
+ case "sortChange":
93
+ events = [
94
+ {
95
+ eventName,
96
+ payload: event.payload,
97
+ },
98
+ ];
99
+ break;
100
+ case "filterChange":
101
+ events = [
102
+ {
103
+ eventName,
104
+ payload: event.payload,
105
+ },
106
+ ];
107
+ break;
108
+ }
109
+ return events;
110
+ }
@@ -0,0 +1,4 @@
1
+ import { Config } from "../types/config";
2
+ export declare const useConfig: (shopifyPermanentDomain: string, configId?: string | undefined) => {
3
+ config: Config | undefined;
4
+ };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.useConfig = void 0;
16
+ const react_1 = __importDefault(require("react"));
17
+ const debug = require("debug")("reactify-search:useConfig");
18
+ // 5 minute cache expiry
19
+ const CACHE_EXPIRY = 5 * 60 * 1000;
20
+ const useConfig = (shopifyPermanentDomain, configId) => {
21
+ // synchronously returns cached and non-expired config from session storage
22
+ const cachedConfig = react_1.default.useMemo(() => {
23
+ var _a;
24
+ if (typeof window === "undefined") {
25
+ return;
26
+ }
27
+ debug("checking config cache");
28
+ // skip checking cache if url search param "nocache" is set
29
+ const skipCache = new URLSearchParams(window.location.href.split("?")[1]).get("nocache") !==
30
+ null;
31
+ if (skipCache) {
32
+ debug("config cache is disabled");
33
+ return;
34
+ }
35
+ const sessionConfig = JSON.parse((_a = window.sessionStorage.getItem("reactify-search:config")) !== null && _a !== void 0 ? _a : "null");
36
+ if (sessionConfig) {
37
+ const sessionConfigTtl = sessionConfig.expiresAt - Date.now();
38
+ if (sessionConfigTtl > 0) {
39
+ debug(`config cache valid, expires in ${(sessionConfigTtl / 1000).toFixed()} seconds`);
40
+ return sessionConfig.config;
41
+ }
42
+ else {
43
+ debug(`config cache invalid, expired ${((sessionConfigTtl * -1) / 1000).toFixed()} seconds ago`);
44
+ }
45
+ }
46
+ return;
47
+ }, []);
48
+ const [config, setConfig] = react_1.default.useState(cachedConfig);
49
+ react_1.default.useEffect(() => {
50
+ if (config) {
51
+ return;
52
+ }
53
+ (() => __awaiter(void 0, void 0, void 0, function* () {
54
+ debug("loading fresh config");
55
+ const searchParams = new URLSearchParams();
56
+ searchParams.set("shop", shopifyPermanentDomain);
57
+ if (configId) {
58
+ searchParams.set("id", configId);
59
+ }
60
+ const skipCache = new URLSearchParams(window.location.href.split("?")[1]).get("nocache") !== null;
61
+ if (skipCache) {
62
+ searchParams.set("nocache", "true");
63
+ }
64
+ const json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
65
+ setConfig(json.body);
66
+ debug("loaded fresh config");
67
+ window.sessionStorage.setItem("reactify-search:config", JSON.stringify({
68
+ expiresAt: new Date().getTime() + CACHE_EXPIRY,
69
+ noCache: skipCache,
70
+ config: json.body,
71
+ }));
72
+ }))();
73
+ }, [shopifyPermanentDomain, configId]);
74
+ react_1.default.useEffect(() => {
75
+ debug("variable[config]", config);
76
+ }, [config]);
77
+ return {
78
+ config,
79
+ };
80
+ };
81
+ exports.useConfig = useConfig;
@@ -0,0 +1,2 @@
1
+ import { ConfigCuration } from "../types";
2
+ export declare const useCuration: () => ConfigCuration | undefined;
@@ -0,0 +1,52 @@
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.useCuration = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const hooks_1 = require("../hooks");
9
+ const useCuration = () => {
10
+ const { options, config } = (0, hooks_1.useReactifySearchContext)();
11
+ const { searchQuery } = (0, hooks_1.useSearch)();
12
+ return react_1.default.useMemo(() => {
13
+ const handleOrSearchTerm = options.mode === "collection" ? options.collection ? options.collection.handle : searchQuery : "";
14
+ const normalisedHandleOrSearchTerm = handleOrSearchTerm
15
+ .toLowerCase()
16
+ .trim();
17
+ const globalCuration = config.curations.find((curation) => curation.id === "global" && curation.type === options.mode);
18
+ const curation = config.curations.find((curation) => {
19
+ var _a, _b;
20
+ const normalisedSearchTerm = (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
21
+ const normalisedCollectionHandle = (_b = curation.collectionHandle) === null || _b === void 0 ? void 0 : _b.toLowerCase().trim();
22
+ if ("search" === options.mode) {
23
+ return ("search" === curation.type &&
24
+ normalisedHandleOrSearchTerm === normalisedSearchTerm);
25
+ }
26
+ if ("collection" === options.mode) {
27
+ return ("collection" === curation.type &&
28
+ normalisedHandleOrSearchTerm === normalisedCollectionHandle);
29
+ }
30
+ return false;
31
+ });
32
+ const addGlobalBoosting = (curation) => {
33
+ const curationIsCollection = curation.type === "collection";
34
+ if (!curationIsCollection) {
35
+ return curation;
36
+ }
37
+ const curationHasRules = !!curation.boosting.groupings.length ||
38
+ !!curation.boosting.sortings.length;
39
+ if (curationHasRules || !globalCuration) {
40
+ return curation;
41
+ }
42
+ const curationWithGlobalBoosting = Object.assign(Object.assign({}, curation), { boosting: globalCuration.boosting });
43
+ return curationWithGlobalBoosting;
44
+ };
45
+ return curation
46
+ ? addGlobalBoosting(curation)
47
+ : globalCuration
48
+ ? globalCuration
49
+ : undefined;
50
+ }, [config, options.mode === "collection" ? options.collection : undefined, searchQuery]);
51
+ };
52
+ exports.useCuration = useCuration;
@@ -0,0 +1,8 @@
1
+ import { ConfigFilterOption } from "../types/config";
2
+ export declare const useFilterCollapsedState: (filter: ConfigFilterOption) => {
3
+ collapsed: boolean;
4
+ shouldRender: boolean;
5
+ collapsedShow: () => void;
6
+ collapsedHide: () => void;
7
+ collapsedToggle: () => void;
8
+ };
@@ -0,0 +1,27 @@
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.useFilterCollapsedState = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const useFilterCollapsedState = (filter) => {
9
+ // @todo use settingsCollapsedDesktop and settingsCollapsedMobile with device detection
10
+ const [collapsed, setCollapsed] = react_1.default.useState(filter.settingsCollapsedDesktop);
11
+ // when the filter is shown, it needs to stay rendered or when it's collapsed, the filter context
12
+ // will be lost which isn't expected behaviour
13
+ const [shouldRender, setShouldRender] = react_1.default.useState(!collapsed);
14
+ // enable render when filter is uncollapsed
15
+ react_1.default.useEffect(() => {
16
+ if (!collapsed)
17
+ setShouldRender(true);
18
+ }, [collapsed]);
19
+ return {
20
+ collapsed,
21
+ shouldRender,
22
+ collapsedShow: react_1.default.useCallback(() => setCollapsed(true), []),
23
+ collapsedHide: react_1.default.useCallback(() => setCollapsed(false), []),
24
+ collapsedToggle: react_1.default.useCallback(() => setCollapsed((collapsed) => !collapsed), []),
25
+ };
26
+ };
27
+ exports.useFilterCollapsedState = useFilterCollapsedState;
@@ -0,0 +1,12 @@
1
+ import { ConfigFilterOption } from "../types/config";
2
+ import { ReactivesearchFilterProps } from "../types/reactivesearch";
3
+ export declare const useFilterListProps: (filter: ConfigFilterOption, reactivesearchFilterProps: ReactivesearchFilterProps) => ReactivesearchFilterProps & {
4
+ filter: ConfigFilterOption;
5
+ options: Array<{
6
+ doc_count: number;
7
+ key: string;
8
+ checked: boolean;
9
+ }>;
10
+ hasSelected: boolean;
11
+ totalSelected: number;
12
+ };
@@ -0,0 +1,35 @@
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.useFilterListProps = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ // converts reactivesearch props returned in filters to a cleaned up/filtered version
9
+ const useFilterListProps = (filter, reactivesearchFilterProps) => {
10
+ return react_1.default.useMemo(() => {
11
+ const { data, value } = reactivesearchFilterProps;
12
+ // remove excluded options, sort alphabeticaly, map checked boolean
13
+ const options = data
14
+ .filter(({ key }) => {
15
+ var _a, _b;
16
+ if ((_a = filter.valuesExclude) === null || _a === void 0 ? void 0 : _a.includes(key))
17
+ return false;
18
+ if (!!((_b = filter.valuesManual) === null || _b === void 0 ? void 0 : _b.length) && !filter.valuesManual.includes(key))
19
+ return false;
20
+ return true;
21
+ })
22
+ .sort((a, b) => a.key.localeCompare(b.key))
23
+ .map((option) => (Object.assign(Object.assign({}, option), { checked: (typeof value === "object" && value[option.key]) ||
24
+ value === option.key })));
25
+ // work out if at least one option selected
26
+ const hasSelected = (typeof value === "object" && 0 < Object.keys(value).length) ||
27
+ (typeof value !== "object" && !!value);
28
+ const totalSelected = options.filter((option) => option.checked).length;
29
+ return Object.assign(Object.assign({}, reactivesearchFilterProps), { filter,
30
+ options,
31
+ hasSelected,
32
+ totalSelected });
33
+ }, [filter, reactivesearchFilterProps]);
34
+ };
35
+ exports.useFilterListProps = useFilterListProps;
@@ -0,0 +1,2 @@
1
+ import { ConfigFilter } from "../types";
2
+ export declare const useFilterStack: () => ConfigFilter | undefined;
@@ -0,0 +1,46 @@
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.useFilterStack = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const hooks_1 = require("../hooks");
9
+ const useFilterStack = () => {
10
+ const { options, config } = (0, hooks_1.useReactifySearchContext)();
11
+ return react_1.default.useMemo(() => {
12
+ if (options.mode === "instant-search") {
13
+ return undefined;
14
+ }
15
+ // select filters by type
16
+ const matchingFilterStacks = config.filters.filter((filter) => filter.type === options.mode);
17
+ // select filter stack by handle if provided
18
+ if (options.filterStackHandle) {
19
+ const matchingFilterStack = matchingFilterStacks.find((filterStack) => options.filterStackHandle === filterStack.handle);
20
+ if (matchingFilterStack) {
21
+ return matchingFilterStack;
22
+ }
23
+ }
24
+ // select filter stack by collection if provided
25
+ if (options.mode === "collection" && options.collection.handle) {
26
+ const matchingFilterStack = matchingFilterStacks.find((filterStack) => { var _a; return (_a = filterStack.collections) === null || _a === void 0 ? void 0 : _a.includes(options.collection.handle); });
27
+ if (matchingFilterStack) {
28
+ return matchingFilterStack;
29
+ }
30
+ }
31
+ // select filter with "default" handle
32
+ let matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStack.handle === "default");
33
+ if (matchingFilterStack) {
34
+ return matchingFilterStack;
35
+ }
36
+ // select any filter with "default" handle
37
+ matchingFilterStack = config.filters.find((filterStack) => filterStack.handle === "default");
38
+ if (matchingFilterStack) {
39
+ return matchingFilterStack;
40
+ }
41
+ // select any available filter as a last resort
42
+ matchingFilterStack = config.filters[0];
43
+ return matchingFilterStack;
44
+ }, [config, options.mode === "collection" ? options.collection : undefined]);
45
+ };
46
+ exports.useFilterStack = useFilterStack;
@@ -0,0 +1,4 @@
1
+ import { ConfigFilterOption } from "../types";
2
+ export declare const useFilters: () => {
3
+ filters: Array<ConfigFilterOption>;
4
+ };
@@ -0,0 +1,22 @@
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.useFilters = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const hooks_1 = require("../hooks");
9
+ const useFilters = () => {
10
+ const filterStack = (0, hooks_1.useFilterStack)();
11
+ return react_1.default.useMemo(() => {
12
+ if (!filterStack) {
13
+ return {
14
+ filters: [],
15
+ };
16
+ }
17
+ return {
18
+ filters: filterStack.options.sort((a, b) => a.position > b.position ? 1 : -1),
19
+ };
20
+ }, [filterStack]);
21
+ };
22
+ exports.useFilters = useFilters;
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import { ReactivesearchPaginationProps } from "../types/reactivesearch";
3
+ export declare const usePagination: (input: ReactivesearchPaginationProps) => {
4
+ currentPage: number;
5
+ totalPages: number;
6
+ pagesToShow: Array<number>;
7
+ hasNextPage: boolean;
8
+ hasPreviousPage: boolean;
9
+ actualCurrentPage: number;
10
+ buildPagePath: (page: number) => string;
11
+ handleNextPage: (event?: React.SyntheticEvent<Element, Event> | undefined) => void;
12
+ handlePreviousPage: (event?: React.SyntheticEvent<Element, Event> | undefined) => void;
13
+ handlePageChange: (pageNumber: number, event?: React.SyntheticEvent<Element, Event> | undefined) => void;
14
+ };