@usereactify/search 4.4.1 → 5.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/package.json +8 -9
  3. package/dist/src/components/Example/ExampleFilterList.d.ts +4 -0
  4. package/dist/src/components/Example/ExampleFilterList.js +19 -0
  5. package/dist/src/components/Example/ExampleFilterRange.d.ts +4 -0
  6. package/dist/src/components/Example/ExampleFilterRange.js +21 -0
  7. package/dist/src/components/Example/ExampleFilterSlider.d.ts +4 -0
  8. package/dist/src/components/Example/ExampleFilterSlider.js +20 -0
  9. package/dist/src/components/Example/ExampleFilterStack.d.ts +4 -0
  10. package/dist/src/components/Example/ExampleFilterStack.js +12 -0
  11. package/dist/src/components/Example/ExampleResultCardCallout.d.ts +4 -0
  12. package/dist/src/components/Example/ExampleResultCardCallout.js +21 -0
  13. package/dist/src/components/Example/ExampleResultCardProduct.d.ts +4 -0
  14. package/dist/src/components/Example/ExampleResultCardProduct.js +18 -0
  15. package/dist/src/components/Example/ExampleResultPaginationLoadMore.d.ts +4 -0
  16. package/dist/src/components/Example/ExampleResultPaginationLoadMore.js +11 -0
  17. package/dist/src/components/Example/ExampleResultPaginationNextPrev.d.ts +4 -0
  18. package/dist/src/components/Example/ExampleResultPaginationNextPrev.js +13 -0
  19. package/dist/src/components/Example/ExampleResultPaginationNumbered.d.ts +4 -0
  20. package/dist/src/components/Example/ExampleResultPaginationNumbered.js +26 -0
  21. package/dist/src/components/Example/ExampleSortby.d.ts +4 -0
  22. package/dist/src/components/Example/ExampleSortby.js +12 -0
  23. package/dist/src/components/Example/index.d.ts +10 -0
  24. package/dist/src/components/Example/index.js +22 -0
  25. package/dist/src/components/Filter/Filter.d.ts +20 -0
  26. package/dist/src/components/Filter/Filter.js +89 -0
  27. package/dist/src/components/Filter/FilterStack.d.ts +7 -0
  28. package/dist/src/components/Filter/FilterStack.js +16 -0
  29. package/dist/src/{filter → components/Filter}/index.d.ts +0 -1
  30. package/dist/src/{filter → components/Filter}/index.js +0 -1
  31. package/dist/src/components/ReactifySearchBase/ReactifySearchBase.d.ts +42 -0
  32. package/dist/src/components/ReactifySearchBase/ReactifySearchBase.js +140 -0
  33. package/dist/src/components/ReactifySearchBase/index.d.ts +1 -0
  34. package/dist/src/components/ReactifySearchBase/index.js +13 -0
  35. package/dist/src/components/Result/ResultCardCallout.d.ts +12 -0
  36. package/dist/src/{result → components/Result}/ResultCardCallout.js +15 -22
  37. package/dist/src/components/Result/ResultCardProduct.d.ts +13 -0
  38. package/dist/src/{result/ResultCard.js → components/Result/ResultCardProduct.js} +19 -22
  39. package/dist/src/components/Result/ResultPaginationLoadMore.d.ts +7 -0
  40. package/dist/src/components/Result/ResultPaginationLoadMore.js +16 -0
  41. package/dist/src/components/Result/ResultPaginationNextPrev.d.ts +7 -0
  42. package/dist/src/components/Result/ResultPaginationNextPrev.js +16 -0
  43. package/dist/src/components/Result/ResultPaginationNumbered.d.ts +7 -0
  44. package/dist/src/components/Result/ResultPaginationNumbered.js +19 -0
  45. package/dist/src/components/Result/ResultStack.d.ts +40 -0
  46. package/dist/src/components/Result/ResultStack.js +107 -0
  47. package/dist/src/components/Result/ResultStateProvider.d.ts +6 -0
  48. package/dist/src/{result → components/Result}/ResultStateProvider.js +0 -0
  49. package/dist/src/components/Result/index.d.ts +7 -0
  50. package/dist/src/{result → components/Result}/index.js +5 -4
  51. package/dist/src/components/Search/SearchInput.d.ts +8 -0
  52. package/dist/src/{search → components/Search}/SearchInput.js +2 -2
  53. package/dist/src/{search → components/Search}/index.d.ts +0 -0
  54. package/dist/src/{search → components/Search}/index.js +0 -0
  55. package/dist/src/{sensor → components/Sensor}/SensorCollection.d.ts +0 -0
  56. package/dist/src/{sensor → components/Sensor}/SensorCollection.js +8 -5
  57. package/dist/src/{sensor → components/Sensor}/SensorInventoryAvailable.d.ts +0 -0
  58. package/dist/src/{sensor → components/Sensor}/SensorInventoryAvailable.js +1 -1
  59. package/dist/src/{sensor → components/Sensor}/SensorPublished.d.ts +0 -0
  60. package/dist/src/{sensor → components/Sensor}/SensorPublished.js +0 -0
  61. package/dist/src/{sensor → components/Sensor}/SensorSearch.d.ts +0 -0
  62. package/dist/src/{sensor → components/Sensor}/SensorSearch.js +3 -3
  63. package/dist/src/{sensor → components/Sensor}/SensorSort.d.ts +0 -0
  64. package/dist/src/{sensor → components/Sensor}/SensorSort.js +4 -5
  65. package/dist/src/{sensor → components/Sensor}/SensorSortScore.d.ts +0 -0
  66. package/dist/src/{sensor → components/Sensor}/SensorSortScore.js +0 -0
  67. package/dist/src/components/Sensor/SensorStack.d.ts +3 -0
  68. package/dist/src/{sensor → components/Sensor}/SensorStack.js +3 -3
  69. package/dist/src/{sensor → components/Sensor}/index.d.ts +0 -0
  70. package/dist/src/{sensor → components/Sensor}/index.js +0 -0
  71. package/dist/src/components/Sortby/Sortby.d.ts +7 -0
  72. package/dist/src/components/Sortby/Sortby.js +16 -0
  73. package/dist/src/components/Sortby/index.d.ts +1 -0
  74. package/dist/src/components/Sortby/index.js +13 -0
  75. package/dist/src/{utility → components/Utility}/UtilityAuthenticatedReactiveBase.d.ts +0 -0
  76. package/dist/src/{utility → components/Utility}/UtilityAuthenticatedReactiveBase.js +2 -2
  77. package/dist/src/components/Utility/index.d.ts +1 -0
  78. package/dist/src/components/Utility/index.js +13 -0
  79. package/dist/src/components/index.d.ts +8 -0
  80. package/dist/src/components/index.js +20 -0
  81. package/dist/src/hooks/index.d.ts +5 -5
  82. package/dist/src/hooks/index.js +5 -5
  83. package/dist/src/hooks/reactivesearch/index.d.ts +4 -1
  84. package/dist/src/hooks/reactivesearch/index.js +4 -1
  85. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.d.ts +1 -1
  86. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js +7 -7
  87. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +5 -7
  88. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js +29 -30
  89. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.d.ts +9 -4
  90. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js +9 -94
  91. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.d.ts +70 -0
  92. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js +21 -0
  93. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.d.ts +67 -0
  94. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js +105 -0
  95. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.d.ts +68 -0
  96. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js +21 -0
  97. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +8 -8
  98. package/dist/src/hooks/reactivesearch/{useReactiveResultListProps.d.ts → useReactiveResultStackProps.d.ts} +2 -4
  99. package/dist/src/hooks/reactivesearch/{useReactiveResultListProps.js → useReactiveResultStackProps.js} +7 -8
  100. package/dist/src/hooks/useAnalytics.js +4 -4
  101. package/dist/src/hooks/useConfig.d.ts +4 -1
  102. package/dist/src/hooks/useConfig.js +77 -2
  103. package/dist/src/hooks/useCuration.d.ts +2 -1
  104. package/dist/src/hooks/useCuration.js +48 -2
  105. package/dist/src/hooks/useFilterListProps.d.ts +4 -14
  106. package/dist/src/hooks/useFilterStack.d.ts +2 -1
  107. package/dist/src/hooks/useFilterStack.js +42 -2
  108. package/dist/src/hooks/useFilters.d.ts +4 -1
  109. package/dist/src/hooks/useFilters.js +10 -5
  110. package/dist/src/hooks/usePagination.d.ts +14 -0
  111. package/dist/src/hooks/{usePages.js → usePagination.js} +30 -30
  112. package/dist/src/hooks/usePaginationLoadMore.d.ts +15 -0
  113. package/dist/src/hooks/usePaginationLoadMore.js +37 -0
  114. package/dist/src/hooks/useProductPrice.d.ts +3 -5
  115. package/dist/src/hooks/useProductPrice.js +42 -40
  116. package/dist/src/hooks/useReactifySearchContext.d.ts +78 -0
  117. package/dist/src/hooks/useReactifySearchContext.js +10 -0
  118. package/dist/src/hooks/useSearch.d.ts +4 -4
  119. package/dist/src/hooks/useSearch.js +28 -8
  120. package/dist/src/hooks/useSortby.d.ts +6 -0
  121. package/dist/src/hooks/useSortby.js +41 -0
  122. package/dist/src/index.d.ts +2 -8
  123. package/dist/src/index.js +2 -8
  124. package/dist/src/types/config.d.ts +1 -0
  125. package/dist/src/types/index.d.ts +3 -0
  126. package/dist/src/types/index.js +15 -0
  127. package/package.json +8 -9
  128. package/dist/src/filter/Filter.d.ts +0 -12
  129. package/dist/src/filter/Filter.js +0 -71
  130. package/dist/src/filter/FilterList.d.ts +0 -4
  131. package/dist/src/filter/FilterList.js +0 -15
  132. package/dist/src/filter/FilterStack.d.ts +0 -11
  133. package/dist/src/filter/FilterStack.js +0 -25
  134. package/dist/src/hooks/useCollection.d.ts +0 -1
  135. package/dist/src/hooks/useCollection.js +0 -6
  136. package/dist/src/hooks/useLiveConfig.d.ts +0 -4
  137. package/dist/src/hooks/useLiveConfig.js +0 -74
  138. package/dist/src/hooks/usePages.d.ts +0 -10
  139. package/dist/src/hooks/useSort.d.ts +0 -5
  140. package/dist/src/hooks/useSort.js +0 -24
  141. package/dist/src/provider.d.ts +0 -78
  142. package/dist/src/provider.js +0 -287
  143. package/dist/src/result/ResultCard.d.ts +0 -14
  144. package/dist/src/result/ResultCardCallout.d.ts +0 -13
  145. package/dist/src/result/ResultList.d.ts +0 -34
  146. package/dist/src/result/ResultList.js +0 -93
  147. package/dist/src/result/ResultLoadMoreButton.d.ts +0 -10
  148. package/dist/src/result/ResultLoadMoreButton.js +0 -61
  149. package/dist/src/result/ResultPagination.d.ts +0 -10
  150. package/dist/src/result/ResultPagination.js +0 -60
  151. package/dist/src/result/ResultPaginationNextPrev.d.ts +0 -8
  152. package/dist/src/result/ResultPaginationNextPrev.js +0 -30
  153. package/dist/src/result/ResultStateProvider.d.ts +0 -7
  154. package/dist/src/result/index.d.ts +0 -6
  155. package/dist/src/search/SearchInput.d.ts +0 -9
  156. package/dist/src/sensor/SensorStack.d.ts +0 -2
@@ -0,0 +1,70 @@
1
+ import type { ConfigFilterOption } from "../../types/config";
2
+ /**
3
+ * For use with @appbaseio/reactivesearch SingleRange and MultiRange components
4
+ */
5
+ export declare const useReactiveFilterRangeProps: (filter: ConfigFilterOption) => {
6
+ showFilter: boolean;
7
+ showRadio: boolean;
8
+ showCheckbox: boolean;
9
+ nestedField: string | undefined;
10
+ customQuery: ((value?: string | string[] | undefined) => {
11
+ query?: undefined;
12
+ } | {
13
+ query: {
14
+ nested: {
15
+ path: string;
16
+ query: {
17
+ bool: {
18
+ must: ({
19
+ match: {
20
+ "variants.available": string;
21
+ };
22
+ terms?: undefined;
23
+ } | {
24
+ terms: {
25
+ [x: string]: string[];
26
+ };
27
+ match?: undefined;
28
+ })[];
29
+ };
30
+ };
31
+ };
32
+ };
33
+ }) | undefined;
34
+ defaultQuery: (() => {
35
+ aggs: {
36
+ reactivesearch_nested: {
37
+ nested: {
38
+ path: string;
39
+ };
40
+ aggs: {
41
+ reactify_nested_outer: {
42
+ filter: {
43
+ match: {
44
+ "variants.available": string;
45
+ };
46
+ };
47
+ aggs: {
48
+ [x: string]: {
49
+ terms: {
50
+ field: string;
51
+ size: number;
52
+ order: {
53
+ _count: string;
54
+ };
55
+ };
56
+ };
57
+ };
58
+ };
59
+ };
60
+ };
61
+ };
62
+ }) | undefined;
63
+ URLParams: boolean;
64
+ componentId: string;
65
+ dataField: string;
66
+ filterLabel: string;
67
+ react: {
68
+ and: string[];
69
+ };
70
+ };
@@ -0,0 +1,21 @@
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.useReactiveFilterRangeProps = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const useReactiveFilterSharedProps_1 = require("./useReactiveFilterSharedProps");
9
+ const useReactiveReactProp_1 = require("./useReactiveReactProp");
10
+ /**
11
+ * For use with @appbaseio/reactivesearch SingleRange and MultiRange components
12
+ */
13
+ const useReactiveFilterRangeProps = (filter) => {
14
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
15
+ const reactiveFilterSharedProps = (0, useReactiveFilterSharedProps_1.useReactiveFilterSharedProps)(filter);
16
+ return react_1.default.useMemo(() => {
17
+ var _a;
18
+ return (Object.assign(Object.assign({}, reactiveFilterSharedProps), { showFilter: (_a = filter.settingsShowFilter) !== null && _a !== void 0 ? _a : true, showRadio: false, showCheckbox: false }));
19
+ }, [filter, reactiveReactProp]);
20
+ };
21
+ exports.useReactiveFilterRangeProps = useReactiveFilterRangeProps;
@@ -0,0 +1,67 @@
1
+ import type { ConfigFilterOption } from "../../types/config";
2
+ /**
3
+ * For use with all @appbaseio/reactivesearch filter components
4
+ */
5
+ export declare const useReactiveFilterSharedProps: (filter: ConfigFilterOption) => {
6
+ nestedField: string | undefined;
7
+ customQuery: ((value?: string | string[] | undefined) => {
8
+ query?: undefined;
9
+ } | {
10
+ query: {
11
+ nested: {
12
+ path: string;
13
+ query: {
14
+ bool: {
15
+ must: ({
16
+ match: {
17
+ "variants.available": string;
18
+ };
19
+ terms?: undefined;
20
+ } | {
21
+ terms: {
22
+ [x: string]: string[];
23
+ };
24
+ match?: undefined;
25
+ })[];
26
+ };
27
+ };
28
+ };
29
+ };
30
+ }) | undefined;
31
+ defaultQuery: (() => {
32
+ aggs: {
33
+ reactivesearch_nested: {
34
+ nested: {
35
+ path: string;
36
+ };
37
+ aggs: {
38
+ reactify_nested_outer: {
39
+ filter: {
40
+ match: {
41
+ "variants.available": string;
42
+ };
43
+ };
44
+ aggs: {
45
+ [x: string]: {
46
+ terms: {
47
+ field: string;
48
+ size: number;
49
+ order: {
50
+ _count: string;
51
+ };
52
+ };
53
+ };
54
+ };
55
+ };
56
+ };
57
+ };
58
+ };
59
+ }) | undefined;
60
+ URLParams: boolean;
61
+ componentId: string;
62
+ dataField: string;
63
+ filterLabel: string;
64
+ react: {
65
+ and: string[];
66
+ };
67
+ };
@@ -0,0 +1,105 @@
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.useReactiveFilterSharedProps = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const useReactiveReactProp_1 = require("./useReactiveReactProp");
9
+ /**
10
+ * For use with all @appbaseio/reactivesearch filter components
11
+ */
12
+ const useReactiveFilterSharedProps = (filter) => {
13
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
14
+ const nestedField = react_1.default.useMemo(() => {
15
+ const nestedFields = ["variants"];
16
+ const topField = filter.field.split(".")[0];
17
+ if (nestedFields.includes(topField))
18
+ return topField;
19
+ return undefined;
20
+ }, [filter]);
21
+ // define a custom query for when settingsHideUnavailable is enabled and the target field is inside variants
22
+ // customQuery defines how this filter affects *other* components like the results component
23
+ const customQuery = react_1.default.useMemo(() => {
24
+ if (!filter.settingsHideUnavailable ||
25
+ !filter.field.startsWith("variants."))
26
+ return undefined;
27
+ return (value) => {
28
+ if (!value)
29
+ return {};
30
+ // reactivesearch sometimes returns string, sometimes string[]
31
+ const valueArray = "string" === typeof value ? [value] : value;
32
+ if (0 === valueArray.length)
33
+ return {};
34
+ return {
35
+ query: {
36
+ nested: {
37
+ path: "variants",
38
+ query: {
39
+ bool: {
40
+ must: [
41
+ {
42
+ match: {
43
+ "variants.available": "true",
44
+ },
45
+ },
46
+ {
47
+ terms: {
48
+ [filter.field]: valueArray,
49
+ },
50
+ },
51
+ ],
52
+ },
53
+ },
54
+ },
55
+ },
56
+ };
57
+ };
58
+ }, [filter]);
59
+ // define a default query for when settingsHideUnavailable is enabled and the target field is inside variants
60
+ // defaultQuery defines how this filter affects itself i.e. the options displayed
61
+ const defaultQuery = react_1.default.useMemo(() => {
62
+ if (!filter.settingsHideUnavailable ||
63
+ !filter.field.startsWith("variants."))
64
+ return undefined;
65
+ // override the aggregation query to filter the results by the variants.available attribute
66
+ return () => {
67
+ return {
68
+ aggs: {
69
+ reactivesearch_nested: {
70
+ nested: { path: "variants" },
71
+ aggs: {
72
+ reactify_nested_outer: {
73
+ filter: {
74
+ match: {
75
+ "variants.available": "true",
76
+ },
77
+ },
78
+ aggs: {
79
+ [filter.field]: {
80
+ terms: {
81
+ field: filter.field,
82
+ size: 100,
83
+ order: { _count: "desc" },
84
+ },
85
+ },
86
+ },
87
+ },
88
+ },
89
+ },
90
+ },
91
+ };
92
+ };
93
+ }, [filter]);
94
+ return react_1.default.useMemo(() => ({
95
+ nestedField,
96
+ customQuery,
97
+ defaultQuery,
98
+ URLParams: true,
99
+ componentId: filter.handle,
100
+ dataField: filter.field,
101
+ filterLabel: filter.name,
102
+ react: reactiveReactProp,
103
+ }), [filter, reactiveReactProp]);
104
+ };
105
+ exports.useReactiveFilterSharedProps = useReactiveFilterSharedProps;
@@ -0,0 +1,68 @@
1
+ import type { ConfigFilterOption } from "../../types/config";
2
+ /**
3
+ * For use with @appbaseio/reactivesearch RangeSlider component
4
+ */
5
+ export declare const useReactiveFilterSliderProps: (filter: ConfigFilterOption) => {
6
+ showFilter: boolean;
7
+ nestedField: string | undefined;
8
+ customQuery: ((value?: string | string[] | undefined) => {
9
+ query?: undefined;
10
+ } | {
11
+ query: {
12
+ nested: {
13
+ path: string;
14
+ query: {
15
+ bool: {
16
+ must: ({
17
+ match: {
18
+ "variants.available": string;
19
+ };
20
+ terms?: undefined;
21
+ } | {
22
+ terms: {
23
+ [x: string]: string[];
24
+ };
25
+ match?: undefined;
26
+ })[];
27
+ };
28
+ };
29
+ };
30
+ };
31
+ }) | undefined;
32
+ defaultQuery: (() => {
33
+ aggs: {
34
+ reactivesearch_nested: {
35
+ nested: {
36
+ path: string;
37
+ };
38
+ aggs: {
39
+ reactify_nested_outer: {
40
+ filter: {
41
+ match: {
42
+ "variants.available": string;
43
+ };
44
+ };
45
+ aggs: {
46
+ [x: string]: {
47
+ terms: {
48
+ field: string;
49
+ size: number;
50
+ order: {
51
+ _count: string;
52
+ };
53
+ };
54
+ };
55
+ };
56
+ };
57
+ };
58
+ };
59
+ };
60
+ }) | undefined;
61
+ URLParams: boolean;
62
+ componentId: string;
63
+ dataField: string;
64
+ filterLabel: string;
65
+ react: {
66
+ and: string[];
67
+ };
68
+ };
@@ -0,0 +1,21 @@
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.useReactiveFilterSliderProps = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const useReactiveFilterSharedProps_1 = require("./useReactiveFilterSharedProps");
9
+ const useReactiveReactProp_1 = require("./useReactiveReactProp");
10
+ /**
11
+ * For use with @appbaseio/reactivesearch RangeSlider component
12
+ */
13
+ const useReactiveFilterSliderProps = (filter) => {
14
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
15
+ const reactiveFilterSharedProps = (0, useReactiveFilterSharedProps_1.useReactiveFilterSharedProps)(filter);
16
+ return react_1.default.useMemo(() => {
17
+ var _a;
18
+ return (Object.assign(Object.assign({}, reactiveFilterSharedProps), { showFilter: (_a = filter.settingsShowFilter) !== null && _a !== void 0 ? _a : true }));
19
+ }, [filter, reactiveReactProp]);
20
+ };
21
+ exports.useReactiveFilterSliderProps = useReactiveFilterSliderProps;
@@ -5,21 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useReactiveReactProp = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
- const sensor_1 = require("../../sensor");
9
- const useFilters_1 = require("../useFilters");
10
- const provider_1 = require("../../provider");
8
+ const hooks_1 = require("../../hooks");
9
+ const components_1 = require("../../components");
11
10
  const useReactiveReactProp = (currentHandle) => {
12
- const filters = (0, useFilters_1.useFilters)();
13
- const { additionalComponentHandles } = (0, provider_1.useContext)();
11
+ const { options } = (0, hooks_1.useReactifySearchContext)();
12
+ const { filters } = (0, hooks_1.useFilters)();
14
13
  return react_1.default.useMemo(() => {
14
+ var _a;
15
15
  return {
16
16
  and: [
17
17
  "SearchInput",
18
- ...sensor_1.SENSOR_IDS,
19
- ...(additionalComponentHandles !== null && additionalComponentHandles !== void 0 ? additionalComponentHandles : []),
18
+ ...components_1.SENSOR_IDS,
19
+ ...((_a = options.additionalComponentHandles) !== null && _a !== void 0 ? _a : []),
20
20
  ...filters.map((filter) => filter.handle),
21
21
  ].filter((handle) => handle !== currentHandle),
22
22
  };
23
- }, [filters, currentHandle]);
23
+ }, [filters, currentHandle, options.additionalComponentHandles]);
24
24
  };
25
25
  exports.useReactiveReactProp = useReactiveReactProp;
@@ -1,7 +1,6 @@
1
- declare type Props = {
1
+ export declare const useReactiveResultStackProps: (options: {
2
2
  pageSize?: number;
3
- };
4
- export declare const useReactiveResultListProps: (props?: Props) => {
3
+ }) => {
5
4
  size: number;
6
5
  URLParams: boolean;
7
6
  showLoader: boolean;
@@ -16,4 +15,3 @@ export declare const useReactiveResultListProps: (props?: Props) => {
16
15
  infiniteScroll: boolean;
17
16
  renderNoResults: () => null;
18
17
  };
19
- export {};
@@ -3,18 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useReactiveResultListProps = void 0;
6
+ exports.useReactiveResultStackProps = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const hooks_1 = require("../../hooks");
9
9
  const useReactiveReactProp_1 = require("./useReactiveReactProp");
10
- const useReactiveResultListProps = (props = {}) => {
11
- const { pageSize } = props;
10
+ const useReactiveResultStackProps = (options) => {
12
11
  const filterStack = (0, hooks_1.useFilterStack)();
13
12
  const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)();
14
13
  const size = react_1.default.useMemo(() => {
15
- var _a;
16
- return (_a = pageSize !== null && pageSize !== void 0 ? pageSize : filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) !== null && _a !== void 0 ? _a : 20;
17
- }, [pageSize, filterStack]);
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]);
18
17
  return react_1.default.useMemo(() => ({
19
18
  size,
20
19
  URLParams: true,
@@ -27,6 +26,6 @@ const useReactiveResultListProps = (props = {}) => {
27
26
  pagination: (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) !== "infinite_scroll",
28
27
  infiniteScroll: (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) === "infinite_scroll",
29
28
  renderNoResults: () => null, // always use only render, otherwise both are shown
30
- }), [filterStack, reactiveReactProp, pageSize]);
29
+ }), [filterStack, reactiveReactProp, options.pageSize]);
31
30
  };
32
- exports.useReactiveResultListProps = useReactiveResultListProps;
31
+ exports.useReactiveResultStackProps = useReactiveResultStackProps;
@@ -14,17 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.useAnalytics = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
- const provider_1 = require("../provider");
17
+ const hooks_1 = require("../hooks");
18
18
  const useAnalytics = () => {
19
- const { shopifyPermanentDomain } = (0, provider_1.useContext)();
19
+ const { options } = (0, hooks_1.useReactifySearchContext)();
20
20
  const url = "https://analytics.search.reactify.app/record/";
21
21
  const track = (event) => __awaiter(void 0, void 0, void 0, function* () {
22
- if (!shopifyPermanentDomain) {
22
+ if (!options.shopifyPermanentDomain) {
23
23
  console.warn(new Error('Unable to send tracking event, missing value for "shopifyPermanentDomain".'));
24
24
  return;
25
25
  }
26
26
  const events = getTrackEvents(event);
27
- return axios_1.default.post(url, { events }, { headers: { "X-Reactify-Tenant": shopifyPermanentDomain } });
27
+ return axios_1.default.post(url, { events }, { headers: { "X-Reactify-Tenant": options.shopifyPermanentDomain } });
28
28
  });
29
29
  return { track };
30
30
  };
@@ -1 +1,4 @@
1
- export declare const useConfig: () => import("..").Config;
1
+ import { Config } from "../types/config";
2
+ export declare const useConfig: (shopifyPermanentDomain: string, configId?: string | undefined) => {
3
+ config: Config | undefined;
4
+ };
@@ -1,6 +1,81 @@
1
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
+ };
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.useConfig = void 0;
4
- const provider_1 = require("../provider");
5
- const useConfig = () => (0, provider_1.useContext)().config;
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
+ };
6
81
  exports.useConfig = useConfig;
@@ -1 +1,2 @@
1
- export declare const useCuration: () => import("..").ConfigCuration | undefined;
1
+ import { ConfigCuration } from "../types";
2
+ export declare const useCuration: () => ConfigCuration | undefined;
@@ -1,6 +1,52 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.useCuration = void 0;
4
- const provider_1 = require("../provider");
5
- const useCuration = () => (0, provider_1.useContext)().curation;
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
+ };
6
52
  exports.useCuration = useCuration;
@@ -1,22 +1,12 @@
1
1
  import { ConfigFilterOption } from "../types/config";
2
2
  import { ReactivesearchFilterProps } from "../types/reactivesearch";
3
- export declare const useFilterListProps: (filter: ConfigFilterOption, reactivesearchFilterProps: ReactivesearchFilterProps) => {
3
+ export declare const useFilterListProps: (filter: ConfigFilterOption, reactivesearchFilterProps: ReactivesearchFilterProps) => ReactivesearchFilterProps & {
4
4
  filter: ConfigFilterOption;
5
- options: {
6
- checked: boolean;
5
+ options: Array<{
7
6
  doc_count: number;
8
7
  key: string;
9
- }[];
8
+ checked: boolean;
9
+ }>;
10
10
  hasSelected: boolean;
11
11
  totalSelected: number;
12
- loading: boolean;
13
- error: Error | null;
14
- handleChange: (value: string) => void;
15
- data: {
16
- doc_count: number;
17
- key: string;
18
- }[];
19
- value: string | {
20
- [key: string]: boolean;
21
- };
22
12
  };
@@ -1 +1,2 @@
1
- export declare const useFilterStack: () => import("..").ConfigFilter | undefined;
1
+ import { ConfigFilter } from "../types";
2
+ export declare const useFilterStack: () => ConfigFilter | undefined;