@usereactify/search 5.26.0 → 5.26.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 (125) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/package.json +11 -10
  3. package/dist/src/components/ClearAll/ClearAll.js +3 -31
  4. package/dist/src/components/ClearAll/ClearAll.js.map +1 -1
  5. package/dist/src/components/Example/ExampleFilterRange.js +1 -3
  6. package/dist/src/components/Example/ExampleFilterRange.js.map +1 -1
  7. package/dist/src/components/Example/ExampleFilterSlider.js +7 -24
  8. package/dist/src/components/Example/ExampleFilterSlider.js.map +1 -1
  9. package/dist/src/components/Example/ExampleFilters.d.ts +3 -1
  10. package/dist/src/components/Example/ExampleFilters.js +4 -8
  11. package/dist/src/components/Example/ExampleFilters.js.map +1 -1
  12. package/dist/src/components/Example/ExampleFiltersSelected.js +10 -24
  13. package/dist/src/components/Example/ExampleFiltersSelected.js.map +1 -1
  14. package/dist/src/components/Example/index.d.ts +0 -3
  15. package/dist/src/components/Example/index.js +0 -3
  16. package/dist/src/components/Example/index.js.map +1 -1
  17. package/dist/src/components/Filter/Filter.d.ts +2 -2
  18. package/dist/src/components/Filter/Filter.js +18 -91
  19. package/dist/src/components/Filter/Filter.js.map +1 -1
  20. package/dist/src/components/Filter/Filters.d.ts +3 -17
  21. package/dist/src/components/Filter/Filters.js +2 -1
  22. package/dist/src/components/Filter/Filters.js.map +1 -1
  23. package/dist/src/components/Filter/FiltersSelected.d.ts +2 -7
  24. package/dist/src/components/Filter/FiltersSelected.js +2 -45
  25. package/dist/src/components/Filter/FiltersSelected.js.map +1 -1
  26. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.d.ts +7 -5
  27. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js +24 -42
  28. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -1
  29. package/dist/src/components/Result/Results.js +9 -24
  30. package/dist/src/components/Result/Results.js.map +1 -1
  31. package/dist/src/components/Sensor/SensorCollection.js +0 -4
  32. package/dist/src/components/Sensor/SensorCollection.js.map +1 -1
  33. package/dist/src/components/Sensor/SensorInventoryAvailable.js +1 -6
  34. package/dist/src/components/Sensor/SensorInventoryAvailable.js.map +1 -1
  35. package/dist/src/components/Sensor/SensorPublished.js +6 -13
  36. package/dist/src/components/Sensor/SensorPublished.js.map +1 -1
  37. package/dist/src/components/Sensor/SensorSearchTerm.js +66 -92
  38. package/dist/src/components/Sensor/SensorSearchTerm.js.map +1 -1
  39. package/dist/src/components/Sensor/SensorSort.js +65 -75
  40. package/dist/src/components/Sensor/SensorSort.js.map +1 -1
  41. package/dist/src/components/Sensor/SensorSortScore.d.ts +2 -0
  42. package/dist/src/components/Sensor/SensorSortScore.js +13 -0
  43. package/dist/src/components/Sensor/SensorSortScore.js.map +1 -0
  44. package/dist/src/components/Sensor/index.d.ts +1 -0
  45. package/dist/src/components/Sensor/index.js +2 -0
  46. package/dist/src/components/Sensor/index.js.map +1 -1
  47. package/dist/src/components/index.d.ts +0 -1
  48. package/dist/src/components/index.js +0 -1
  49. package/dist/src/components/index.js.map +1 -1
  50. package/dist/src/hooks/index.d.ts +0 -3
  51. package/dist/src/hooks/index.js +0 -3
  52. package/dist/src/hooks/index.js.map +1 -1
  53. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.d.ts +7 -2
  54. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js +3 -10
  55. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js.map +1 -1
  56. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +27 -0
  57. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js +71 -0
  58. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js.map +1 -0
  59. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.d.ts +0 -1
  60. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js +5 -3
  61. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js.map +1 -1
  62. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.d.ts +0 -1
  63. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js +5 -3
  64. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js.map +1 -1
  65. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js +1 -1
  66. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js.map +1 -1
  67. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js +3 -1
  68. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js.map +1 -1
  69. package/dist/src/hooks/reactivesearch/useReactiveReactProp.d.ts +1 -2
  70. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +3 -8
  71. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js.map +1 -1
  72. package/dist/src/hooks/useAnalytics.js +3 -23
  73. package/dist/src/hooks/useAnalytics.js.map +1 -1
  74. package/dist/src/hooks/useConfig.js +27 -9
  75. package/dist/src/hooks/useConfig.js.map +1 -1
  76. package/dist/src/hooks/useCuration.js +1 -12
  77. package/dist/src/hooks/useCuration.js.map +1 -1
  78. package/dist/src/hooks/useFilterListProps.js +2 -15
  79. package/dist/src/hooks/useFilterListProps.js.map +1 -1
  80. package/dist/src/hooks/useFilterRangeProps.d.ts +10 -1
  81. package/dist/src/hooks/useFilterRangeProps.js +47 -36
  82. package/dist/src/hooks/useFilterRangeProps.js.map +1 -1
  83. package/dist/src/hooks/useFilterSliderProps.d.ts +8 -6
  84. package/dist/src/hooks/useFilterSliderProps.js +10 -31
  85. package/dist/src/hooks/useFilterSliderProps.js.map +1 -1
  86. package/dist/src/hooks/usePaginationLoadMore.d.ts +15 -0
  87. package/dist/src/hooks/usePaginationLoadMore.js +38 -0
  88. package/dist/src/hooks/usePaginationLoadMore.js.map +1 -0
  89. package/dist/src/hooks/useReactifySearchContext.d.ts +11 -19
  90. package/dist/src/hooks/useReactifySearchContext.js.map +1 -1
  91. package/dist/src/hooks/useSearch.js +2 -4
  92. package/dist/src/hooks/useSearch.js.map +1 -1
  93. package/dist/src/types/config.d.ts +5 -11
  94. package/dist/src/types/config.js.map +1 -1
  95. package/dist/src/types/elastic.d.ts +17 -53
  96. package/dist/src/types/elastic.js.map +1 -1
  97. package/dist/src/types/firestore.d.ts +0 -3
  98. package/dist/src/types/firestore.js.map +1 -1
  99. package/dist/src/types/reactivesearch.d.ts +1 -1
  100. package/dist/src/types/reactivesearch.js.map +1 -1
  101. package/package.json +1 -1
  102. package/dist/src/components/Example/ExampleHookUseResults.d.ts +0 -2
  103. package/dist/src/components/Example/ExampleHookUseResults.js +0 -25
  104. package/dist/src/components/Example/ExampleHookUseResults.js.map +0 -1
  105. package/dist/src/components/Example/ExampleSuggestions.d.ts +0 -4
  106. package/dist/src/components/Example/ExampleSuggestions.js +0 -16
  107. package/dist/src/components/Example/ExampleSuggestions.js.map +0 -1
  108. package/dist/src/components/Suggestions/Suggestions.d.ts +0 -12
  109. package/dist/src/components/Suggestions/Suggestions.js +0 -44
  110. package/dist/src/components/Suggestions/Suggestions.js.map +0 -1
  111. package/dist/src/components/Suggestions/index.d.ts +0 -1
  112. package/dist/src/components/Suggestions/index.js +0 -14
  113. package/dist/src/components/Suggestions/index.js.map +0 -1
  114. package/dist/src/hooks/react-slider/useReactSliderProps.d.ts +0 -4
  115. package/dist/src/hooks/react-slider/useReactSliderProps.js +0 -28
  116. package/dist/src/hooks/react-slider/useReactSliderProps.js.map +0 -1
  117. package/dist/src/hooks/useFlags.d.ts +0 -21
  118. package/dist/src/hooks/useFlags.js +0 -49
  119. package/dist/src/hooks/useFlags.js.map +0 -1
  120. package/dist/src/hooks/useIndices.d.ts +0 -5
  121. package/dist/src/hooks/useIndices.js +0 -49
  122. package/dist/src/hooks/useIndices.js.map +0 -1
  123. package/dist/src/hooks/useResults.d.ts +0 -21
  124. package/dist/src/hooks/useResults.js +0 -19
  125. package/dist/src/hooks/useResults.js.map +0 -1
@@ -8,5 +8,4 @@ export * from "./Search";
8
8
  export * from "./Sensor";
9
9
  export * from "./SortBy";
10
10
  export * from "./Stats";
11
- export * from "./Suggestions";
12
11
  export * from "./Utility";
@@ -20,6 +20,5 @@ __exportStar(require("./Search"), exports);
20
20
  __exportStar(require("./Sensor"), exports);
21
21
  __exportStar(require("./SortBy"), exports);
22
22
  __exportStar(require("./Stats"), exports);
23
- __exportStar(require("./Suggestions"), exports);
24
23
  __exportStar(require("./Utility"), exports);
25
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,oDAAkC;AAClC,6CAA2B;AAC3B,2CAAyB;AACzB,2DAAyC;AACzC,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,gDAA8B;AAC9B,4CAA0B","sourcesContent":["export * from \"./Example\";\nexport * from \"./CustomComponent\";\nexport * from \"./ClearAll\";\nexport * from \"./Filter\";\nexport * from \"./ReactifySearchProvider\";\nexport * from \"./Result\";\nexport * from \"./Search\";\nexport * from \"./Sensor\";\nexport * from \"./SortBy\";\nexport * from \"./Stats\";\nexport * from \"./Suggestions\";\nexport * from \"./Utility\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,oDAAkC;AAClC,6CAA2B;AAC3B,2CAAyB;AACzB,2DAAyC;AACzC,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B","sourcesContent":["export * from \"./Example\";\nexport * from \"./CustomComponent\";\nexport * from \"./ClearAll\";\nexport * from \"./Filter\";\nexport * from \"./ReactifySearchProvider\";\nexport * from \"./Result\";\nexport * from \"./Search\";\nexport * from \"./Sensor\";\nexport * from \"./SortBy\";\nexport * from \"./Stats\";\nexport * from \"./Utility\";\n"]}
@@ -14,6 +14,3 @@ export * from "./useFilterSliderProps";
14
14
  export * from "./useFilterCollapsedState";
15
15
  export * from "./useConfig";
16
16
  export * from "./useReactifySearchContext";
17
- export * from "./useResults";
18
- export * from "./useFlags";
19
- export * from "./useIndices";
@@ -26,7 +26,4 @@ __exportStar(require("./useFilterSliderProps"), exports);
26
26
  __exportStar(require("./useFilterCollapsedState"), exports);
27
27
  __exportStar(require("./useConfig"), exports);
28
28
  __exportStar(require("./useReactifySearchContext"), exports);
29
- __exportStar(require("./useResults"), exports);
30
- __exportStar(require("./useFlags"), exports);
31
- __exportStar(require("./useIndices"), exports);
32
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AAEjC,gDAA8B;AAC9B,8CAA4B;AAC5B,kDAAgC;AAChC,0DAAwC;AACxC,8CAA4B;AAC5B,gDAA8B;AAC9B,iDAA+B;AAC/B,+CAA6B;AAC7B,oDAAkC;AAClC,uDAAqC;AACrC,wDAAsC;AACtC,yDAAuC;AACvC,4DAA0C;AAC1C,8CAA4B;AAC5B,6DAA2C;AAC3C,+CAA6B;AAC7B,6CAA2B;AAC3B,+CAA6B","sourcesContent":["export * from \"./reactivesearch\";\n\nexport * from \"./useDebugger\";\nexport * from \"./useSortBy\";\nexport * from \"./usePagination\";\nexport * from \"./usePaginationLoadable\";\nexport * from \"./useSearch\";\nexport * from \"./useCuration\";\nexport * from \"./useAnalytics\";\nexport * from \"./useFilters\";\nexport * from \"./useProductPrice\";\nexport * from \"./useFilterListProps\";\nexport * from \"./useFilterRangeProps\";\nexport * from \"./useFilterSliderProps\";\nexport * from \"./useFilterCollapsedState\";\nexport * from \"./useConfig\";\nexport * from \"./useReactifySearchContext\";\nexport * from \"./useResults\";\nexport * from \"./useFlags\";\nexport * from \"./useIndices\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AAEjC,gDAA8B;AAC9B,8CAA4B;AAC5B,kDAAgC;AAChC,0DAAwC;AACxC,8CAA4B;AAC5B,gDAA8B;AAC9B,iDAA+B;AAC/B,+CAA6B;AAC7B,oDAAkC;AAClC,uDAAqC;AACrC,wDAAsC;AACtC,yDAAuC;AACvC,4DAA0C;AAC1C,8CAA4B;AAC5B,6DAA2C","sourcesContent":["export * from \"./reactivesearch\";\n\nexport * from \"./useDebugger\";\nexport * from \"./useSortBy\";\nexport * from \"./usePagination\";\nexport * from \"./usePaginationLoadable\";\nexport * from \"./useSearch\";\nexport * from \"./useCuration\";\nexport * from \"./useAnalytics\";\nexport * from \"./useFilters\";\nexport * from \"./useProductPrice\";\nexport * from \"./useFilterListProps\";\nexport * from \"./useFilterRangeProps\";\nexport * from \"./useFilterSliderProps\";\nexport * from \"./useFilterCollapsedState\";\nexport * from \"./useConfig\";\nexport * from \"./useReactifySearchContext\";\n"]}
@@ -1,2 +1,7 @@
1
- import { ReactiveBaseProps } from "@appbaseio/reactivesearch/lib/components/basic/ReactiveBase";
2
- export declare const useReactiveBaseProps: () => ReactiveBaseProps;
1
+ export declare const useReactiveBaseProps: () => {
2
+ app: string;
3
+ url: string;
4
+ credentials: string;
5
+ theme: Record<string, unknown>;
6
+ transformResponse: (response: any) => Promise<any>;
7
+ };
@@ -15,13 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.useReactiveBaseProps = void 0;
16
16
  const react_1 = __importDefault(require("react"));
17
17
  const hooks_1 = require("../../hooks");
18
- const package_json_1 = __importDefault(require("../../../package.json"));
19
18
  const useReactiveBaseProps = () => {
20
19
  const { options } = (0, hooks_1.useReactifySearchContext)();
21
20
  const reactiveBaseProps = react_1.default.useMemo(() => ({
22
21
  app: options.index,
23
- url: options.endpoint,
24
- credentials: options.credentials,
22
+ url: options.credentials.endpoint,
23
+ credentials: `${options.credentials.username}:${options.credentials.password}`,
25
24
  theme: options.theme,
26
25
  transformResponse: (response) => __awaiter(void 0, void 0, void 0, function* () {
27
26
  var _a, _b, _c, _d;
@@ -39,13 +38,7 @@ const useReactiveBaseProps = () => {
39
38
  }
40
39
  return response;
41
40
  }),
42
- headers: {
43
- "x-reactify-shop": options.shopifyPermanentDomain,
44
- "x-reactify-mode": options.mode,
45
- "x-reactify-client-id": options.clientId,
46
- "x-reactify-client-version": package_json_1.default.version,
47
- },
48
- }), [options.index, options.endpoint, options.credentials, options.theme]);
41
+ }), [options.credentials, options.theme]);
49
42
  return reactiveBaseProps;
50
43
  };
51
44
  exports.useReactiveBaseProps = useReactiveBaseProps;
@@ -1 +1 @@
1
- {"version":3,"file":"useReactiveBaseProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveBaseProps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,uCAAuD;AAEvD,yEAAwC;AAEjC,MAAM,oBAAoB,GAAG,GAAsB,EAAE;IAC1D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,MAAM,iBAAiB,GAAG,eAAK,CAAC,OAAO,CACrC,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,EAAE,OAAO,CAAC,KAAK;QAClB,GAAG,EAAE,OAAO,CAAC,QAAQ;QACrB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,iBAAiB,EAAE,CAAO,QAAa,EAAE,EAAE;;YACzC,+EAA+E;YAC/E,uDAAuD;YACvD,EAAE;YACF,qFAAqF;YACrF,qFAAqF;YACrF,kEAAkE;YAClE,EAAE;YACF,0DAA0D;YAC1D,IACE,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,0CAAE,qBAAqB,0CAAE,qBAAqB,EACpE;gBACA,QAAQ,CAAC,YAAY,CAAC,qBAAqB;oBACzC,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,0CAAE,qBAAqB,0CAAE,qBAAqB,CAAC;aACxE;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA;QACD,OAAO,EAAE;YACP,iBAAiB,EAAE,OAAO,CAAC,sBAAsB;YACjD,iBAAiB,EAAE,OAAO,CAAC,IAAI;YAC/B,sBAAsB,EAAE,OAAO,CAAC,QAAQ;YACxC,2BAA2B,EAAE,sBAAG,CAAC,OAAO;SACzC;KACF,CAAC,EACF,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CACtE,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAtCW,QAAA,oBAAoB,wBAsC/B","sourcesContent":["import React from \"react\";\nimport { ReactiveBaseProps } from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveBase\";\n\nimport { useReactifySearchContext } from \"../../hooks\";\n\nimport pkg from \"../../../package.json\";\n\nexport const useReactiveBaseProps = (): ReactiveBaseProps => {\n const { options } = useReactifySearchContext();\n\n const reactiveBaseProps = React.useMemo<ReactiveBaseProps>(\n () => ({\n app: options.index,\n url: options.endpoint,\n credentials: options.credentials,\n theme: options.theme,\n transformResponse: async (response: any) => {\n // support filtering inside nested aggregations by moving the inner aggregation\n // up one level such that reactivesearch understands it\n //\n // see useReactiveFilterListProps > defaultQuery to see how a filter is being applied\n // to variant aggregations to ensure that only in stock sizes are displayed as filter\n // options, this involves a nested filter, which requires this fix\n //\n // https://github.com/appbaseio/reactivesearch/issues/1530\n if (\n response?.aggregations?.reactivesearch_nested?.reactify_nested_outer\n ) {\n response.aggregations.reactivesearch_nested =\n response?.aggregations?.reactivesearch_nested?.reactify_nested_outer;\n }\n\n return response;\n },\n headers: {\n \"x-reactify-shop\": options.shopifyPermanentDomain,\n \"x-reactify-mode\": options.mode,\n \"x-reactify-client-id\": options.clientId,\n \"x-reactify-client-version\": pkg.version,\n },\n }),\n [options.index, options.endpoint, options.credentials, options.theme]\n );\n\n return reactiveBaseProps;\n};\n"]}
1
+ {"version":3,"file":"useReactiveBaseProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveBaseProps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,uCAAuD;AAEhD,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,MAAM,iBAAiB,GAAG,eAAK,CAAC,OAAO,CACrC,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,EAAE,OAAO,CAAC,KAAK;QAClB,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,QAAQ;QACjC,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE;QAC9E,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,iBAAiB,EAAE,CAAO,QAAa,EAAE,EAAE;;YACzC,+EAA+E;YAC/E,uDAAuD;YACvD,EAAE;YACF,qFAAqF;YACrF,qFAAqF;YACrF,kEAAkE;YAClE,EAAE;YACF,0DAA0D;YAC1D,IACE,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,0CAAE,qBAAqB,0CAAE,qBAAqB,EACpE;gBACA,QAAQ,CAAC,YAAY,CAAC,qBAAqB;oBACzC,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,0CAAE,qBAAqB,0CAAE,qBAAqB,CAAC;aACxE;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA;KACF,CAAC,EACF,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CACrC,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAhCW,QAAA,oBAAoB,wBAgC/B","sourcesContent":["import React from \"react\";\nimport { useReactifySearchContext } from \"../../hooks\";\n\nexport const useReactiveBaseProps = () => {\n const { options } = useReactifySearchContext();\n\n const reactiveBaseProps = React.useMemo(\n () => ({\n app: options.index,\n url: options.credentials.endpoint,\n credentials: `${options.credentials.username}:${options.credentials.password}`,\n theme: options.theme,\n transformResponse: async (response: any) => {\n // support filtering inside nested aggregations by moving the inner aggregation\n // up one level such that reactivesearch understands it\n //\n // see useReactiveFilterListProps > defaultQuery to see how a filter is being applied\n // to variant aggregations to ensure that only in stock sizes are displayed as filter\n // options, this involves a nested filter, which requires this fix\n //\n // https://github.com/appbaseio/reactivesearch/issues/1530\n if (\n response?.aggregations?.reactivesearch_nested?.reactify_nested_outer\n ) {\n response.aggregations.reactivesearch_nested =\n response?.aggregations?.reactivesearch_nested?.reactify_nested_outer;\n }\n\n return response;\n },\n }),\n [options.credentials, options.theme]\n );\n\n return reactiveBaseProps;\n};\n"]}
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ export declare const useReactiveDataSearchProps: (options: {
3
+ [key: string]: any;
4
+ debounce?: number | undefined;
5
+ placeholder?: string | undefined;
6
+ inputClassName?: string | undefined;
7
+ }) => {
8
+ debounce?: number | undefined;
9
+ placeholder: string;
10
+ inputClassName?: string | undefined;
11
+ type: string;
12
+ showIcon: boolean;
13
+ fuzziness: 0 | 2 | 1 | "AUTO";
14
+ queryFormat: "and" | "or";
15
+ autosuggest: boolean;
16
+ value: string;
17
+ onKeyUp: (event: React.KeyboardEvent) => void;
18
+ componentId: string;
19
+ dataField: string[];
20
+ fieldWeights: number[];
21
+ onChange: (value: string, triggerQuery: () => {}) => void;
22
+ onBlur: () => void;
23
+ onFocus: () => void;
24
+ innerClass: {
25
+ input: string | undefined;
26
+ };
27
+ };
@@ -0,0 +1,71 @@
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.useReactiveDataSearchProps = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const ahooks_1 = require("ahooks");
9
+ const hooks_1 = require("../../hooks");
10
+ // default field for when zero search fields have been configured in Reactify
11
+ const defaultSearchField = {
12
+ id: "title",
13
+ field: "title",
14
+ importance: 0,
15
+ searchType: "instant_search",
16
+ };
17
+ const useReactiveDataSearchProps = (options) => {
18
+ var _a;
19
+ const { config } = (0, hooks_1.useReactifySearchContext)();
20
+ const { searchTerm, submitSearchTerm, setSearchTerm, setShowInstantSearchResults, } = (0, hooks_1.useSearch)();
21
+ const searchFields = react_1.default.useMemo(() => 0 < config.fields.length
22
+ ? config.fields.filter((field) => ["always_search", "instant_search"].includes(field.searchType))
23
+ : [defaultSearchField], []);
24
+ const handleKeyPress = react_1.default.useCallback((event) => {
25
+ if ("Enter" !== event.key)
26
+ return;
27
+ submitSearchTerm();
28
+ }, [submitSearchTerm]);
29
+ const { track } = (0, hooks_1.useAnalytics)();
30
+ const trackQuery = react_1.default.useCallback(() => {
31
+ if (!searchTerm || (searchTerm && searchTerm.length < 3))
32
+ return;
33
+ track({ eventName: "search", payload: { searchTerm: searchTerm } });
34
+ }, [searchTerm, track]);
35
+ const { run: runDebouncedTriggerQuery, cancel: cancelDebouncedTriggerQuery } = (0, ahooks_1.useDebounceFn)((triggerQuery) => {
36
+ triggerQuery();
37
+ trackQuery();
38
+ }, {
39
+ wait: (_a = options.debounce) !== null && _a !== void 0 ? _a : 300,
40
+ });
41
+ const reactiveDataSearchProps = react_1.default.useMemo(() => {
42
+ var _a;
43
+ return (Object.assign({ type: "search", showIcon: false, fuzziness: 1, queryFormat: "and", autosuggest: false, value: searchTerm !== null && searchTerm !== void 0 ? searchTerm : "", onKeyUp: handleKeyPress, componentId: "SearchInput", placeholder: (_a = options.placeholder) !== null && _a !== void 0 ? _a : "Search for a product...", dataField: searchFields.map((field) => field.field), fieldWeights: searchFields.map((field) => field.importance), onChange: (value, triggerQuery) => {
44
+ setSearchTerm(value);
45
+ if (!!value) {
46
+ runDebouncedTriggerQuery(triggerQuery);
47
+ }
48
+ else {
49
+ cancelDebouncedTriggerQuery();
50
+ }
51
+ }, onBlur: () => {
52
+ // setTimeout ensures that results are still clickable before close
53
+ setTimeout(() => setShowInstantSearchResults(false), 300);
54
+ }, onFocus: () => {
55
+ setShowInstantSearchResults(true);
56
+ }, innerClass: {
57
+ input: options.inputClassName,
58
+ } }, options));
59
+ }, [
60
+ searchTerm,
61
+ handleKeyPress,
62
+ options.placeholder,
63
+ searchFields,
64
+ setSearchTerm,
65
+ runDebouncedTriggerQuery,
66
+ cancelDebouncedTriggerQuery,
67
+ ]);
68
+ return reactiveDataSearchProps;
69
+ };
70
+ exports.useReactiveDataSearchProps = useReactiveDataSearchProps;
71
+ //# sourceMappingURL=useReactiveDataSearchProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReactiveDataSearchProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveDataSearchProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAuC;AAIvC,uCAAgF;AAEhF,6EAA6E;AAC7E,MAAM,kBAAkB,GAAgB;IACtC,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,gBAAgB;CAC7B,CAAC;AAEK,MAAM,0BAA0B,GAAG,CAAC,OAK1C,EAAE,EAAE;;IACH,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC9C,MAAM,EACJ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,2BAA2B,GAC5B,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEhB,MAAM,YAAY,GAAG,eAAK,CAAC,OAAO,CAChC,GAAG,EAAE,CACH,CAAC,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";\n\nimport type { ConfigField } from \"../../types/config\";\n\nimport { useReactifySearchContext, useSearch, useAnalytics } from \"../../hooks\";\n\n// default field for when zero search fields have been configured in Reactify\nconst defaultSearchField: ConfigField = {\n id: \"title\",\n field: \"title\",\n importance: 0,\n searchType: \"instant_search\",\n};\n\nexport const useReactiveDataSearchProps = (options: {\n [key: string]: any;\n debounce?: number;\n placeholder?: string;\n inputClassName?: string;\n}) => {\n const { config } = useReactifySearchContext();\n const {\n searchTerm,\n submitSearchTerm,\n setSearchTerm,\n setShowInstantSearchResults,\n } = useSearch();\n\n const searchFields = React.useMemo(\n () =>\n 0 < config.fields.length\n ? config.fields.filter((field) =>\n [\"always_search\", \"instant_search\"].includes(field.searchType)\n )\n : [defaultSearchField],\n []\n );\n\n const handleKeyPress = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (\"Enter\" !== event.key) return;\n submitSearchTerm();\n },\n [submitSearchTerm]\n );\n\n const { track } = useAnalytics();\n\n const trackQuery = React.useCallback(() => {\n if (!searchTerm || (searchTerm && searchTerm.length < 3)) return;\n track({ eventName: \"search\", payload: { searchTerm: searchTerm } });\n }, [searchTerm, track]);\n\n const { run: runDebouncedTriggerQuery, cancel: cancelDebouncedTriggerQuery } =\n useDebounceFn(\n (triggerQuery: () => void) => {\n triggerQuery();\n trackQuery();\n },\n {\n wait: options.debounce ?? 300,\n }\n );\n\n const reactiveDataSearchProps = React.useMemo(\n () => ({\n type: \"search\",\n showIcon: false,\n fuzziness: 1 as 0 | 1 | 2 | \"AUTO\",\n queryFormat: \"and\" as \"and\" | \"or\",\n autosuggest: false,\n value: searchTerm ?? \"\",\n onKeyUp: handleKeyPress,\n componentId: \"SearchInput\",\n placeholder: options.placeholder ?? \"Search for a product...\",\n dataField: searchFields.map((field) => field.field),\n fieldWeights: searchFields.map((field) => field.importance),\n onChange: (value: string, triggerQuery: () => {}) => {\n setSearchTerm(value);\n if (!!value) {\n runDebouncedTriggerQuery(triggerQuery);\n } else {\n cancelDebouncedTriggerQuery();\n }\n },\n onBlur: () => {\n // setTimeout ensures that results are still clickable before close\n setTimeout(() => setShowInstantSearchResults(false), 300);\n },\n onFocus: () => {\n setShowInstantSearchResults(true);\n },\n innerClass: {\n input: options.inputClassName,\n },\n ...options,\n }),\n [\n searchTerm,\n handleKeyPress,\n options.placeholder,\n searchFields,\n setSearchTerm,\n runDebouncedTriggerQuery,\n cancelDebouncedTriggerQuery,\n ]\n );\n\n return reactiveDataSearchProps;\n};\n"]}
@@ -4,7 +4,6 @@ import type { ConfigFilterOption } from "../../types/config";
4
4
  */
5
5
  export declare const useReactiveFilterListProps: (filter: ConfigFilterOption) => {
6
6
  size: number | undefined;
7
- queryFormat: "and" | "or";
8
7
  showFilter: boolean;
9
8
  showLoadMore: boolean;
10
9
  showSearch: boolean;
@@ -6,15 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useReactiveFilterListProps = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const useReactiveFilterSharedProps_1 = require("./useReactiveFilterSharedProps");
9
+ const useReactiveReactProp_1 = require("./useReactiveReactProp");
9
10
  /**
10
11
  * For use with @appbaseio/reactivesearch SingleList and MultiList components
11
12
  */
12
13
  const useReactiveFilterListProps = (filter) => {
14
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
13
15
  const reactiveFilterSharedProps = (0, useReactiveFilterSharedProps_1.useReactiveFilterSharedProps)(filter);
14
16
  const reactiveFilterListProps = react_1.default.useMemo(() => {
15
- var _a, _b, _c, _d;
16
- return (Object.assign(Object.assign({}, reactiveFilterSharedProps), { size: parseInt(filter.displaySize) || undefined, queryFormat: (_a = filter.settingsFilterLogic) !== null && _a !== void 0 ? _a : "or", showFilter: (_b = filter.settingsShowFilter) !== null && _b !== void 0 ? _b : true, showLoadMore: (_c = filter.settingsShowMore) !== null && _c !== void 0 ? _c : false, showSearch: (_d = filter.settingsShowSearch) !== null && _d !== void 0 ? _d : false, showRadio: false, showCheckbox: false }));
17
- }, [filter, reactiveFilterSharedProps]);
17
+ var _a, _b, _c;
18
+ return (Object.assign(Object.assign({}, reactiveFilterSharedProps), { size: parseInt(filter.displaySize) || undefined, showFilter: (_a = filter.settingsShowFilter) !== null && _a !== void 0 ? _a : true, showLoadMore: (_b = filter.settingsShowMore) !== null && _b !== void 0 ? _b : false, showSearch: (_c = filter.settingsShowSearch) !== null && _c !== void 0 ? _c : false, showRadio: false, showCheckbox: false }));
19
+ }, [filter, reactiveReactProp]);
18
20
  return reactiveFilterListProps;
19
21
  };
20
22
  exports.useReactiveFilterListProps = useReactiveFilterListProps;
@@ -1 +1 @@
1
- {"version":3,"file":"useReactiveFilterListProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterListProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,iFAA8E;AAE9E;;GAEG;AACI,MAAM,0BAA0B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACvE,MAAM,yBAAyB,GAAG,IAAA,2DAA4B,EAAC,MAAM,CAAC,CAAC;IAEvE,MAAM,uBAAuB,GAAG,eAAK,CAAC,OAAO,CAC3C,GAAG,EAAE;;QAAC,OAAA,iCACD,yBAAyB,KAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,EAC/C,WAAW,EAAE,MAAA,MAAM,CAAC,mBAAmB,mCAAI,IAAI,EAC/C,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,IAAI,EAC7C,YAAY,EAAE,MAAA,MAAM,CAAC,gBAAgB,mCAAI,KAAK,EAC9C,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,KAAK,EAC9C,SAAS,EAAE,KAAK,EAChB,YAAY,EAAE,KAAK,IACnB,CAAA;KAAA,EACF,CAAC,MAAM,EAAE,yBAAyB,CAAC,CACpC,CAAC;IAEF,OAAO,uBAAuB,CAAC;AACjC,CAAC,CAAC;AAlBW,QAAA,0BAA0B,8BAkBrC","sourcesContent":["import React from \"react\";\n\nimport type { ConfigFilterOption } from \"../../types/config\";\nimport { useReactiveFilterSharedProps } from \"./useReactiveFilterSharedProps\";\n\n/**\n * For use with @appbaseio/reactivesearch SingleList and MultiList components\n */\nexport const useReactiveFilterListProps = (filter: ConfigFilterOption) => {\n const reactiveFilterSharedProps = useReactiveFilterSharedProps(filter);\n\n const reactiveFilterListProps = React.useMemo(\n () => ({\n ...reactiveFilterSharedProps,\n size: parseInt(filter.displaySize) || undefined,\n queryFormat: filter.settingsFilterLogic ?? \"or\",\n showFilter: filter.settingsShowFilter ?? true,\n showLoadMore: filter.settingsShowMore ?? false,\n showSearch: filter.settingsShowSearch ?? false,\n showRadio: false,\n showCheckbox: false,\n }),\n [filter, reactiveFilterSharedProps]\n );\n\n return reactiveFilterListProps;\n};\n"]}
1
+ {"version":3,"file":"useReactiveFilterListProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterListProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,iFAA8E;AAE9E,iEAA8D;AAE9D;;GAEG;AACI,MAAM,0BAA0B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACvE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9D,MAAM,yBAAyB,GAAG,IAAA,2DAA4B,EAAC,MAAM,CAAC,CAAC;IAEvE,MAAM,uBAAuB,GAAG,eAAK,CAAC,OAAO,CAC3C,GAAG,EAAE;;QAAC,OAAA,iCACD,yBAAyB,KAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,EAC/C,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,IAAI,EAC7C,YAAY,EAAE,MAAA,MAAM,CAAC,gBAAgB,mCAAI,KAAK,EAC9C,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,KAAK,EAC9C,SAAS,EAAE,KAAK,EAChB,YAAY,EAAE,KAAK,IACnB,CAAA;KAAA,EACF,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAC;IAEF,OAAO,uBAAuB,CAAC;AACjC,CAAC,CAAC;AAlBW,QAAA,0BAA0B,8BAkBrC","sourcesContent":["import React from \"react\";\n\nimport type { ConfigFilterOption } from \"../../types/config\";\nimport { useReactiveFilterSharedProps } from \"./useReactiveFilterSharedProps\";\n\nimport { useReactiveReactProp } from \"./useReactiveReactProp\";\n\n/**\n * For use with @appbaseio/reactivesearch SingleList and MultiList components\n */\nexport const useReactiveFilterListProps = (filter: ConfigFilterOption) => {\n const reactiveReactProp = useReactiveReactProp(filter.handle);\n const reactiveFilterSharedProps = useReactiveFilterSharedProps(filter);\n\n const reactiveFilterListProps = React.useMemo(\n () => ({\n ...reactiveFilterSharedProps,\n size: parseInt(filter.displaySize) || undefined,\n showFilter: filter.settingsShowFilter ?? true,\n showLoadMore: filter.settingsShowMore ?? false,\n showSearch: filter.settingsShowSearch ?? false,\n showRadio: false,\n showCheckbox: false,\n }),\n [filter, reactiveReactProp]\n );\n\n return reactiveFilterListProps;\n};\n"]}
@@ -3,7 +3,6 @@ import { ConfigFilterOption } from "../../types";
3
3
  * For use with @appbaseio/reactivesearch SingleRange and MultiRange components
4
4
  */
5
5
  export declare const useReactiveFilterRangeProps: (filter: ConfigFilterOption) => {
6
- queryFormat: "and" | "or";
7
6
  showFilter: boolean;
8
7
  showRadio: boolean;
9
8
  showCheckbox: boolean;
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useReactiveFilterRangeProps = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const useReactiveFilterSharedProps_1 = require("./useReactiveFilterSharedProps");
9
+ const useReactiveReactProp_1 = require("./useReactiveReactProp");
9
10
  /**
10
11
  * For use with @appbaseio/reactivesearch SingleRange and MultiRange components
11
12
  */
12
13
  const useReactiveFilterRangeProps = (filter) => {
14
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
13
15
  const reactiveFilterSharedProps = (0, useReactiveFilterSharedProps_1.useReactiveFilterSharedProps)(filter);
14
16
  const data = react_1.default.useMemo(() => {
15
17
  var _a, _b;
@@ -23,9 +25,9 @@ const useReactiveFilterRangeProps = (filter) => {
23
25
  })) !== null && _b !== void 0 ? _b : []);
24
26
  }, []);
25
27
  const reactiveFilterRangeProps = react_1.default.useMemo(() => {
26
- var _a, _b;
27
- return (Object.assign(Object.assign({}, reactiveFilterSharedProps), { queryFormat: (_a = filter.settingsFilterLogic) !== null && _a !== void 0 ? _a : "or", showFilter: (_b = filter.settingsShowFilter) !== null && _b !== void 0 ? _b : true, showRadio: false, showCheckbox: false, data: data }));
28
- }, [filter, reactiveFilterSharedProps]);
28
+ var _a;
29
+ return (Object.assign(Object.assign({}, reactiveFilterSharedProps), { showFilter: (_a = filter.settingsShowFilter) !== null && _a !== void 0 ? _a : true, showRadio: false, showCheckbox: false, data: data }));
30
+ }, [filter, reactiveReactProp]);
29
31
  return reactiveFilterRangeProps;
30
32
  };
31
33
  exports.useReactiveFilterRangeProps = useReactiveFilterRangeProps;
@@ -1 +1 @@
1
- {"version":3,"file":"useReactiveFilterRangeProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterRangeProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAI1B,iFAA8E;AAE9E;;GAEG;AACI,MAAM,2BAA2B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACxE,MAAM,yBAAyB,GAAG,IAAA,2DAA4B,EAAC,MAAM,CAAC,CAAC;IAEvE,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QAC9B,OAAO,CACL,MAAA,MAAA,MAAM,CAAC,mBAAmB,0CAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACzC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9C,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB;aACnD,CAAC;QACJ,CAAC,CAAC,mCAAI,EAAE,CACT,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,wBAAwB,GAAG,eAAK,CAAC,OAAO,CAC5C,GAAG,EAAE;;QAAC,OAAA,iCACD,yBAAyB,KAC5B,WAAW,EAAE,MAAA,MAAM,CAAC,mBAAmB,mCAAI,IAAI,EAC/C,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,IAAI,EAC7C,SAAS,EAAE,KAAK,EAChB,YAAY,EAAE,KAAK,EACnB,IAAI,EAAE,IAAI,IACV,CAAA;KAAA,EACF,CAAC,MAAM,EAAE,yBAAyB,CAAC,CACpC,CAAC;IAEF,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AA7BW,QAAA,2BAA2B,+BA6BtC","sourcesContent":["import React from \"react\";\n\nimport { ConfigFilterOption } from \"../../types\";\n\nimport { useReactiveFilterSharedProps } from \"./useReactiveFilterSharedProps\";\n\n/**\n * For use with @appbaseio/reactivesearch SingleRange and MultiRange components\n */\nexport const useReactiveFilterRangeProps = (filter: ConfigFilterOption) => {\n const reactiveFilterSharedProps = useReactiveFilterSharedProps(filter);\n\n const data = React.useMemo(() => {\n return (\n filter.displayRangeOptions?.map((option) => {\n const [label, start, end] = option.split(\":\");\n return {\n label: label,\n start: start ? parseInt(start) : 0,\n end: end ? parseInt(end) : Number.MAX_SAFE_INTEGER,\n };\n }) ?? []\n );\n }, []);\n\n const reactiveFilterRangeProps = React.useMemo(\n () => ({\n ...reactiveFilterSharedProps,\n queryFormat: filter.settingsFilterLogic ?? \"or\",\n showFilter: filter.settingsShowFilter ?? true,\n showRadio: false,\n showCheckbox: false,\n data: data,\n }),\n [filter, reactiveFilterSharedProps]\n );\n\n return reactiveFilterRangeProps;\n};\n"]}
1
+ {"version":3,"file":"useReactiveFilterRangeProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterRangeProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAI1B,iFAA8E;AAC9E,iEAA8D;AAE9D;;GAEG;AACI,MAAM,2BAA2B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACxE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9D,MAAM,yBAAyB,GAAG,IAAA,2DAA4B,EAAC,MAAM,CAAC,CAAC;IAEvE,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QAC9B,OAAO,CACL,MAAA,MAAA,MAAM,CAAC,mBAAmB,0CAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACzC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9C,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB;aACnD,CAAC;QACJ,CAAC,CAAC,mCAAI,EAAE,CACT,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,wBAAwB,GAAG,eAAK,CAAC,OAAO,CAC5C,GAAG,EAAE;;QAAC,OAAA,iCACD,yBAAyB,KAC5B,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,IAAI,EAC7C,SAAS,EAAE,KAAK,EAChB,YAAY,EAAE,KAAK,EACnB,IAAI,EAAE,IAAI,IACV,CAAA;KAAA,EACF,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAC;IAEF,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AA7BW,QAAA,2BAA2B,+BA6BtC","sourcesContent":["import React from \"react\";\n\nimport { ConfigFilterOption } from \"../../types\";\n\nimport { useReactiveFilterSharedProps } from \"./useReactiveFilterSharedProps\";\nimport { useReactiveReactProp } from \"./useReactiveReactProp\";\n\n/**\n * For use with @appbaseio/reactivesearch SingleRange and MultiRange components\n */\nexport const useReactiveFilterRangeProps = (filter: ConfigFilterOption) => {\n const reactiveReactProp = useReactiveReactProp(filter.handle);\n const reactiveFilterSharedProps = useReactiveFilterSharedProps(filter);\n\n const data = React.useMemo(() => {\n return (\n filter.displayRangeOptions?.map((option) => {\n const [label, start, end] = option.split(\":\");\n return {\n label: label,\n start: start ? parseInt(start) : 0,\n end: end ? parseInt(end) : Number.MAX_SAFE_INTEGER,\n };\n }) ?? []\n );\n }, []);\n\n const reactiveFilterRangeProps = React.useMemo(\n () => ({\n ...reactiveFilterSharedProps,\n showFilter: filter.settingsShowFilter ?? true,\n showRadio: false,\n showCheckbox: false,\n data: data,\n }),\n [filter, reactiveReactProp]\n );\n\n return reactiveFilterRangeProps;\n};\n"]}
@@ -10,7 +10,7 @@ const useReactiveReactProp_1 = require("./useReactiveReactProp");
10
10
  * For use with all @appbaseio/reactivesearch filter components
11
11
  */
12
12
  const useReactiveFilterSharedProps = (filter) => {
13
- const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle, filter);
13
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
14
14
  const nestedField = react_1.default.useMemo(() => {
15
15
  const nestedFields = ["variants"];
16
16
  const topField = filter.field.split(".")[0];
@@ -1 +1 @@
1
- {"version":3,"file":"useReactiveFilterSharedProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterSharedProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAI1B,iEAA8D;AAE9D;;GAEG;AACI,MAAM,4BAA4B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACzE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEtE,MAAM,WAAW,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,MAAM,YAAY,GAAG,CAAC,UAAU,CAAC,CAAC;QAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,QAAQ,CAAC;QACrD,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,4GAA4G;IAC5G,4FAA4F;IAC5F,MAAM,WAAW,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,IACE,CAAC,MAAM,CAAC,uBAAuB;YAC/B,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;YAErC,OAAO,SAAS,CAAC;QAEnB,OAAO,CAAC,KAAyB,EAAE,EAAE;YACnC,IAAI,CAAC,KAAK;gBAAE,OAAO,EAAE,CAAC;YAEtB,8DAA8D;YAC9D,MAAM,UAAU,GAAG,QAAQ,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAE/D,IAAI,CAAC,KAAK,UAAU,CAAC,MAAM;gBAAE,OAAO,EAAE,CAAC;YAEvC,OAAO;gBACL,KAAK,EAAE;oBACL,MAAM,EAAE;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;QACZ,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,MAAM,CAAC,MAAM;QAC1B,SAAS,EAAE,MAAM,CAAC,KAAK;QACvB,WAAW,EAAE,MAAM,CAAC,IAAI;QACxB,KAAK,EAAE,iBAAiB;KACzB,CAAC,EACF,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAC;IAEF,OAAO,yBAAyB,CAAC;AACnC,CAAC,CAAC;AA3GW,QAAA,4BAA4B,gCA2GvC","sourcesContent":["import React from \"react\";\n\nimport type { ConfigFilterOption } from \"../../types/config\";\n\nimport { useReactiveReactProp } from \"./useReactiveReactProp\";\n\n/**\n * For use with all @appbaseio/reactivesearch filter components\n */\nexport const useReactiveFilterSharedProps = (filter: ConfigFilterOption) => {\n const reactiveReactProp = useReactiveReactProp(filter.handle, filter);\n\n const nestedField = React.useMemo(() => {\n const nestedFields = [\"variants\"];\n const topField = filter.field.split(\".\")[0];\n if (nestedFields.includes(topField)) return topField;\n return undefined;\n }, [filter]);\n\n // define a custom query for when settingsHideUnavailable is enabled and the target field is inside variants\n // customQuery defines how this filter affects *other* components like the results component\n const customQuery = React.useMemo(() => {\n if (\n !filter.settingsHideUnavailable ||\n !filter.field.startsWith(\"variants.\")\n )\n return undefined;\n\n return (value?: string | string[]) => {\n if (!value) return {};\n\n // reactivesearch sometimes returns string, sometimes string[]\n const valueArray = \"string\" === typeof value ? [value] : value;\n\n if (0 === valueArray.length) return {};\n\n return {\n query: {\n nested: {\n path: \"variants\",\n query: {\n bool: {\n must: [\n {\n match: {\n \"variants.available\": \"true\",\n },\n },\n {\n terms: {\n [filter.field]: valueArray,\n },\n },\n ],\n },\n },\n },\n },\n };\n };\n }, [filter]);\n\n // define a default query for when settingsHideUnavailable is enabled and the target field is inside variants\n // defaultQuery defines how this filter affects itself i.e. the options displayed\n const defaultQuery = React.useMemo(() => {\n if (\n !filter.settingsHideUnavailable ||\n !filter.field.startsWith(\"variants.\")\n )\n return undefined;\n\n // override the aggregation query to filter the results by the variants.available attribute\n return () => {\n return {\n aggs: {\n reactivesearch_nested: {\n nested: { path: \"variants\" },\n aggs: {\n reactify_nested_outer: {\n filter: {\n match: {\n \"variants.available\": \"true\",\n },\n },\n aggs: {\n [filter.field]: {\n terms: {\n field: filter.field,\n size: 100,\n order: { _count: \"desc\" },\n },\n },\n },\n },\n },\n },\n },\n };\n };\n }, [filter]);\n\n const reactiveFilterSharedProps = React.useMemo(\n () => ({\n nestedField,\n customQuery,\n defaultQuery,\n URLParams: true,\n componentId: filter.handle,\n dataField: filter.field,\n filterLabel: filter.name,\n react: reactiveReactProp,\n }),\n [filter, reactiveReactProp]\n );\n\n return reactiveFilterSharedProps;\n};\n"]}
1
+ {"version":3,"file":"useReactiveFilterSharedProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterSharedProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAI1B,iEAA8D;AAE9D;;GAEG;AACI,MAAM,4BAA4B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACzE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE9D,MAAM,WAAW,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,MAAM,YAAY,GAAG,CAAC,UAAU,CAAC,CAAC;QAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,QAAQ,CAAC;QACrD,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,4GAA4G;IAC5G,4FAA4F;IAC5F,MAAM,WAAW,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,IACE,CAAC,MAAM,CAAC,uBAAuB;YAC/B,CAAC,MAAM,CAAC,KAAK,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CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;wCACd,KAAK,EAAE;4CACL,KAAK,EAAE,MAAM,CAAC,KAAK;4CACnB,IAAI,EAAE,GAAG;4CACT,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;yCAC1B;qCACF;iCACF;6BACF;yBACF;qBACF;iBACF;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,MAAM,yBAAyB,GAAG,eAAK,CAAC,OAAO,CAC7C,GAAG,EAAE,CAAC,CAAC;QACL,WAAW;QACX,WAAW;QACX,YAAY;QACZ,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,MAAM,CAAC,MAAM;QAC1B,SAAS,EAAE,MAAM,CAAC,KAAK;QACvB,WAAW,EAAE,MAAM,CAAC,IAAI;QACxB,KAAK,EAAE,iBAAiB;KACzB,CAAC,EACF,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAC;IAEF,OAAO,yBAAyB,CAAC;AACnC,CAAC,CAAC;AA3GW,QAAA,4BAA4B,gCA2GvC","sourcesContent":["import React from \"react\";\n\nimport type { ConfigFilterOption } from \"../../types/config\";\n\nimport { useReactiveReactProp } from \"./useReactiveReactProp\";\n\n/**\n * For use with all @appbaseio/reactivesearch filter components\n */\nexport const useReactiveFilterSharedProps = (filter: ConfigFilterOption) => {\n const reactiveReactProp = useReactiveReactProp(filter.handle);\n\n const nestedField = React.useMemo(() => {\n const nestedFields = [\"variants\"];\n const topField = filter.field.split(\".\")[0];\n if (nestedFields.includes(topField)) return topField;\n return undefined;\n }, [filter]);\n\n // define a custom query for when settingsHideUnavailable is enabled and the target field is inside variants\n // customQuery defines how this filter affects *other* components like the results component\n const customQuery = React.useMemo(() => {\n if (\n !filter.settingsHideUnavailable ||\n !filter.field.startsWith(\"variants.\")\n )\n return undefined;\n\n return (value?: string | string[]) => {\n if (!value) return {};\n\n // reactivesearch sometimes returns string, sometimes string[]\n const valueArray = \"string\" === typeof value ? [value] : value;\n\n if (0 === valueArray.length) return {};\n\n return {\n query: {\n nested: {\n path: \"variants\",\n query: {\n bool: {\n must: [\n {\n match: {\n \"variants.available\": \"true\",\n },\n },\n {\n terms: {\n [filter.field]: valueArray,\n },\n },\n ],\n },\n },\n },\n },\n };\n };\n }, [filter]);\n\n // define a default query for when settingsHideUnavailable is enabled and the target field is inside variants\n // defaultQuery defines how this filter affects itself i.e. the options displayed\n const defaultQuery = React.useMemo(() => {\n if (\n !filter.settingsHideUnavailable ||\n !filter.field.startsWith(\"variants.\")\n )\n return undefined;\n\n // override the aggregation query to filter the results by the variants.available attribute\n return () => {\n return {\n aggs: {\n reactivesearch_nested: {\n nested: { path: \"variants\" },\n aggs: {\n reactify_nested_outer: {\n filter: {\n match: {\n \"variants.available\": \"true\",\n },\n },\n aggs: {\n [filter.field]: {\n terms: {\n field: filter.field,\n size: 100,\n order: { _count: \"desc\" },\n },\n },\n },\n },\n },\n },\n },\n };\n };\n }, [filter]);\n\n const reactiveFilterSharedProps = React.useMemo(\n () => ({\n nestedField,\n customQuery,\n defaultQuery,\n URLParams: true,\n componentId: filter.handle,\n dataField: filter.field,\n filterLabel: filter.name,\n react: reactiveReactProp,\n }),\n [filter, reactiveReactProp]\n );\n\n return reactiveFilterSharedProps;\n};\n"]}
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useReactiveFilterSliderProps = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const useReactiveFilterSharedProps_1 = require("./useReactiveFilterSharedProps");
9
+ const useReactiveReactProp_1 = require("./useReactiveReactProp");
9
10
  /**
10
11
  * For use with @appbaseio/reactivesearch RangeSlider component
11
12
  */
12
13
  const useReactiveFilterSliderProps = (filter) => {
14
+ const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
13
15
  const reactiveFilterSharedProps = (0, useReactiveFilterSharedProps_1.useReactiveFilterSharedProps)(filter);
14
16
  const rangeLabelsFn = react_1.default.useCallback((min, max) => {
15
17
  var _a, _b, _c, _d;
@@ -21,7 +23,7 @@ const useReactiveFilterSliderProps = (filter) => {
21
23
  const reactiveFilterSliderProps = react_1.default.useMemo(() => {
22
24
  var _a, _b;
23
25
  return (Object.assign(Object.assign({}, reactiveFilterSharedProps), { showFilter: (_a = filter.settingsShowFilter) !== null && _a !== void 0 ? _a : true, rangeLabels: rangeLabelsFn, stepValue: (_b = parseInt(filter.displaySliderStep)) !== null && _b !== void 0 ? _b : undefined }));
24
- }, [filter, reactiveFilterSharedProps]);
26
+ }, [filter, reactiveReactProp]);
25
27
  return reactiveFilterSliderProps;
26
28
  };
27
29
  exports.useReactiveFilterSliderProps = useReactiveFilterSliderProps;
@@ -1 +1 @@
1
- {"version":3,"file":"useReactiveFilterSliderProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterSliderProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,iFAA8E;AAE9E;;GAEG;AACI,MAAM,4BAA4B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACzE,MAAM,yBAAyB,GAAG,IAAA,2DAA4B,EAAC,MAAM,CAAC,CAAC;IAEvE,MAAM,aAAa,GAAG,eAAK,CAAC,WAAW,CACrC,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;;QAAC,OAAA,CAAC;YAC7B,KAAK,EAAE,GAAG,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAAE,GAAG,GAAG,GAC9C,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAChC,EAAE;YACF,GAAG,EAAE,GAAG,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAAE,GAAG,GAAG,GAC5C,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAChC,EAAE;SACH,CAAC,CAAA;KAAA,EACF,EAAE,CACH,CAAC;IAEF,MAAM,yBAAyB,GAAG,eAAK,CAAC,OAAO,CAC7C,GAAG,EAAE;;QAAC,OAAA,iCACD,yBAAyB,KAC5B,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,IAAI,EAC7C,WAAW,EAAE,aAAa,EAC1B,SAAS,EAAE,MAAA,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,mCAAI,SAAS,IAC1D,CAAA;KAAA,EACF,CAAC,MAAM,EAAE,yBAAyB,CAAC,CACpC,CAAC;IAEF,OAAO,yBAAyB,CAAC;AACnC,CAAC,CAAC;AA1BW,QAAA,4BAA4B,gCA0BvC","sourcesContent":["import React from \"react\";\n\nimport type { ConfigFilterOption } from \"../../types/config\";\nimport { useReactiveFilterSharedProps } from \"./useReactiveFilterSharedProps\";\n\n/**\n * For use with @appbaseio/reactivesearch RangeSlider component\n */\nexport const useReactiveFilterSliderProps = (filter: ConfigFilterOption) => {\n const reactiveFilterSharedProps = useReactiveFilterSharedProps(filter);\n\n const rangeLabelsFn = React.useCallback(\n (min: number, max: number) => ({\n start: `${filter.displaySliderPrefix ?? \"\"}${min}${\n filter.displaySliderSuffix ?? \"\"\n }`,\n end: `${filter.displaySliderPrefix ?? \"\"}${max}${\n filter.displaySliderSuffix ?? \"\"\n }`,\n }),\n []\n );\n\n const reactiveFilterSliderProps = React.useMemo(\n () => ({\n ...reactiveFilterSharedProps,\n showFilter: filter.settingsShowFilter ?? true,\n rangeLabels: rangeLabelsFn,\n stepValue: parseInt(filter.displaySliderStep) ?? undefined,\n }),\n [filter, reactiveFilterSharedProps]\n );\n\n return reactiveFilterSliderProps;\n};\n"]}
1
+ {"version":3,"file":"useReactiveFilterSliderProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveFilterSliderProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,iFAA8E;AAE9E,iEAA8D;AAE9D;;GAEG;AACI,MAAM,4BAA4B,GAAG,CAAC,MAA0B,EAAE,EAAE;IACzE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9D,MAAM,yBAAyB,GAAG,IAAA,2DAA4B,EAAC,MAAM,CAAC,CAAC;IAEvE,MAAM,aAAa,GAAG,eAAK,CAAC,WAAW,CACrC,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;;QAAC,OAAA,CAAC;YAC7B,KAAK,EAAE,GAAG,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAAE,GAAG,GAAG,GAC9C,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAChC,EAAE;YACF,GAAG,EAAE,GAAG,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAAE,GAAG,GAAG,GAC5C,MAAA,MAAM,CAAC,mBAAmB,mCAAI,EAChC,EAAE;SACH,CAAC,CAAA;KAAA,EACF,EAAE,CACH,CAAC;IAEF,MAAM,yBAAyB,GAAG,eAAK,CAAC,OAAO,CAC7C,GAAG,EAAE;;QAAC,OAAA,iCACD,yBAAyB,KAC5B,UAAU,EAAE,MAAA,MAAM,CAAC,kBAAkB,mCAAI,IAAI,EAC7C,WAAW,EAAE,aAAa,EAC1B,SAAS,EAAE,MAAA,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,mCAAI,SAAS,IAC1D,CAAA;KAAA,EACF,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAC;IAEF,OAAO,yBAAyB,CAAC;AACnC,CAAC,CAAC;AA3BW,QAAA,4BAA4B,gCA2BvC","sourcesContent":["import React from \"react\";\n\nimport type { ConfigFilterOption } from \"../../types/config\";\nimport { useReactiveFilterSharedProps } from \"./useReactiveFilterSharedProps\";\n\nimport { useReactiveReactProp } from \"./useReactiveReactProp\";\n\n/**\n * For use with @appbaseio/reactivesearch RangeSlider component\n */\nexport const useReactiveFilterSliderProps = (filter: ConfigFilterOption) => {\n const reactiveReactProp = useReactiveReactProp(filter.handle);\n const reactiveFilterSharedProps = useReactiveFilterSharedProps(filter);\n\n const rangeLabelsFn = React.useCallback(\n (min: number, max: number) => ({\n start: `${filter.displaySliderPrefix ?? \"\"}${min}${\n filter.displaySliderSuffix ?? \"\"\n }`,\n end: `${filter.displaySliderPrefix ?? \"\"}${max}${\n filter.displaySliderSuffix ?? \"\"\n }`,\n }),\n []\n );\n\n const reactiveFilterSliderProps = React.useMemo(\n () => ({\n ...reactiveFilterSharedProps,\n showFilter: filter.settingsShowFilter ?? true,\n rangeLabels: rangeLabelsFn,\n stepValue: parseInt(filter.displaySliderStep) ?? undefined,\n }),\n [filter, reactiveReactProp]\n );\n\n return reactiveFilterSliderProps;\n};\n"]}
@@ -1,4 +1,3 @@
1
- import { ConfigFilterOption } from "../../types";
2
- export declare const useReactiveReactProp: (currentHandle?: string | undefined, filter?: ConfigFilterOption | undefined) => {
1
+ export declare const useReactiveReactProp: (currentHandle?: string | undefined) => {
3
2
  and: string[];
4
3
  };
@@ -7,25 +7,20 @@ exports.useReactiveReactProp = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const hooks_1 = require("../../hooks");
9
9
  const components_1 = require("../../components");
10
- const useReactiveReactProp = (currentHandle, filter) => {
10
+ const useReactiveReactProp = (currentHandle) => {
11
11
  const { options } = (0, hooks_1.useReactifySearchContext)();
12
12
  const { filterStack } = (0, hooks_1.useFilters)();
13
- const reactProp = react_1.default.useMemo(() => {
13
+ return react_1.default.useMemo(() => {
14
14
  var _a, _b;
15
- if (filter && filter.settingsShowEmptyValues) {
16
- return {
17
- and: components_1.SENSOR_IDS,
18
- };
19
- }
20
15
  return {
21
16
  and: [
17
+ "SearchInput",
22
18
  ...components_1.SENSOR_IDS,
23
19
  ...((_a = options.additionalComponentIds) !== null && _a !== void 0 ? _a : []),
24
20
  ...((_b = filterStack === null || filterStack === void 0 ? void 0 : filterStack.options.map((filter) => filter.handle)) !== null && _b !== void 0 ? _b : []),
25
21
  ].filter((handle) => handle !== currentHandle),
26
22
  };
27
23
  }, [filterStack, currentHandle, options.additionalComponentIds]);
28
- return reactProp;
29
24
  };
30
25
  exports.useReactiveReactProp = useReactiveReactProp;
31
26
  //# sourceMappingURL=useReactiveReactProp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useReactiveReactProp.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveReactProp.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAmE;AACnE,iDAA8C;AAGvC,MAAM,oBAAoB,GAAG,CAClC,aAAsB,EACtB,MAA2B,EAC3B,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC/C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,MAAM,SAAS,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACnC,IAAI,MAAM,IAAI,MAAM,CAAC,uBAAuB,EAAE;YAC5C,OAAO;gBACL,GAAG,EAAE,uBAAU;aAChB,CAAC;SACH;QAED,OAAO;YACL,GAAG,EAAE;gBACH,GAAG,uBAAU;gBACb,GAAG,CAAC,MAAA,OAAO,CAAC,sBAAsB,mCAAI,EAAE,CAAC;gBACzC,GAAG,CAAC,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,mCAAI,EAAE,CAAC;aAC/D,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,aAAa,CAAC;SAC/C,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAEjE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAxBW,QAAA,oBAAoB,wBAwB/B","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext, useFilters } from \"../../hooks\";\nimport { SENSOR_IDS } from \"../../components\";\nimport { ConfigFilterOption } from \"../../types\";\n\nexport const useReactiveReactProp = (\n currentHandle?: string,\n filter?: ConfigFilterOption\n) => {\n const { options } = useReactifySearchContext();\n const { filterStack } = useFilters();\n\n const reactProp = React.useMemo(() => {\n if (filter && filter.settingsShowEmptyValues) {\n return {\n and: SENSOR_IDS,\n };\n }\n\n return {\n and: [\n ...SENSOR_IDS,\n ...(options.additionalComponentIds ?? []),\n ...(filterStack?.options.map((filter) => filter.handle) ?? []),\n ].filter((handle) => handle !== currentHandle),\n };\n }, [filterStack, currentHandle, options.additionalComponentIds]);\n\n return reactProp;\n};\n"]}
1
+ {"version":3,"file":"useReactiveReactProp.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveReactProp.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAmE;AACnE,iDAA8C;AAEvC,MAAM,oBAAoB,GAAG,CAAC,aAAsB,EAAE,EAAE;IAC7D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC/C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,OAAO,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACxB,OAAO;YACL,GAAG,EAAE;gBACH,aAAa;gBACb,GAAG,uBAAU;gBACb,GAAG,CAAC,MAAA,OAAO,CAAC,sBAAsB,mCAAI,EAAE,CAAC;gBACzC,GAAG,CAAC,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,mCAAI,EAAE,CAAC;aAC/D,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,aAAa,CAAC;SAC/C,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext, useFilters } from \"../../hooks\";\nimport { SENSOR_IDS } from \"../../components\";\n\nexport const useReactiveReactProp = (currentHandle?: string) => {\n const { options } = useReactifySearchContext();\n const { filterStack } = useFilters();\n\n return React.useMemo(() => {\n return {\n and: [\n \"SearchInput\",\n ...SENSOR_IDS,\n ...(options.additionalComponentIds ?? []),\n ...(filterStack?.options.map((filter) => filter.handle) ?? []),\n ].filter((handle) => handle !== currentHandle),\n };\n }, [filterStack, currentHandle, options.additionalComponentIds]);\n};\n"]}
@@ -14,22 +14,8 @@ 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 package_json_1 = __importDefault(require("../../package.json"));
18
17
  const hooks_1 = require("../hooks");
19
18
  const utility_1 = require("../utility");
20
- function getCookie(name) {
21
- var _a, _b;
22
- try {
23
- const cookie = `; ${document.cookie}`.split(`; ${name}=`);
24
- if (cookie.length === 2) {
25
- return (_b = (_a = cookie.pop()) === null || _a === void 0 ? void 0 : _a.split(";").shift()) !== null && _b !== void 0 ? _b : "";
26
- }
27
- }
28
- catch (error) {
29
- console.error(error);
30
- }
31
- return "";
32
- }
33
19
  const useAnalytics = () => {
34
20
  const { options } = (0, hooks_1.useReactifySearchContext)();
35
21
  const url = "https://analytics.search.reactify.app/record/";
@@ -40,13 +26,7 @@ const useAnalytics = () => {
40
26
  }
41
27
  utility_1.debug.log("useAnalytics", "track", event);
42
28
  const events = getTrackEvents(event);
43
- return axios_1.default.post(url, { events }, {
44
- headers: {
45
- "X-Reactify-Tenant": options.shopifyPermanentDomain,
46
- "X-Reactify-Client": getCookie("_rs_ga"),
47
- "X-Reactify-Version": package_json_1.default.version,
48
- },
49
- });
29
+ return axios_1.default.post(url, { events }, { headers: { "X-Reactify-Tenant": options.shopifyPermanentDomain } });
50
30
  });
51
31
  return { track };
52
32
  };
@@ -59,7 +39,7 @@ function getTrackEvents(event) {
59
39
  events = [
60
40
  {
61
41
  eventName,
62
- payload: Object.assign(Object.assign({}, event.payload), { searchTerm: event.payload.searchTerm.trim() }),
42
+ payload: event.payload,
63
43
  },
64
44
  ];
65
45
  break;
@@ -67,7 +47,7 @@ function getTrackEvents(event) {
67
47
  events = [
68
48
  {
69
49
  eventName,
70
- payload: Object.assign(Object.assign({}, event.payload), { searchTerm: event.payload.searchTerm.trim() }),
50
+ payload: event.payload,
71
51
  },
72
52
  ];
73
53
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"useAnalytics.js","sourceRoot":"","sources":["../../../src/hooks/useAnalytics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,sEAAqC;AAErC,oCAAoD;AACpD,wCAAmC;AAEnC,SAAS,SAAS,CAAC,IAAY;;IAC7B,IAAI;QACF,MAAM,MAAM,GAAG,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;QAC1D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,OAAO,MAAA,MAAA,MAAM,CAAC,GAAG,EAAE,0CAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,mCAAI,EAAE,CAAC;SAC/C;KACF;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACtB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAEM,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC/C,MAAM,GAAG,GAAG,+CAA+C,CAAC;IAC5D,MAAM,KAAK,GAAG,CAAO,KAAiB,EAAE,EAAE;QACxC,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE;YACnC,OAAO,CAAC,IAAI,CACV,IAAI,KAAK,CACP,4EAA4E,CAC7E,CACF,CAAC;YAEF,OA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YAEF,MAAM;QAER,KAAK,eAAe;YAClB,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,gBAAgB;YACnB,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,kBAAkB;YACrB,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,YAAY;YACf,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,cAAc;YACjB,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;KACT;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import axios from \"axios\";\n\nimport pkg from \"../../package.json\";\n\nimport { useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nfunction getCookie(name: string): string {\n try {\n const cookie = `; ${document.cookie}`.split(`; ${name}=`);\n if (cookie.length === 2) {\n return cookie.pop()?.split(\";\").shift() ?? \"\";\n }\n } catch (error) {\n console.error(error);\n }\n\n return \"\";\n}\n\nexport const useAnalytics = () => {\n const { options } = useReactifySearchContext();\n const url = \"https://analytics.search.reactify.app/record/\";\n const track = async (event: TrackEvent) => {\n if (!options.shopifyPermanentDomain) {\n console.warn(\n new Error(\n 'Unable to send tracking event, missing value for \"shopifyPermanentDomain\".'\n )\n );\n\n return;\n }\n\n debug.log(\"useAnalytics\", \"track\", event);\n\n const events = getTrackEvents(event);\n return axios.post(\n url,\n { events },\n {\n headers: {\n \"X-Reactify-Tenant\": options.shopifyPermanentDomain,\n \"X-Reactify-Client\": getCookie(\"_rs_ga\"),\n \"X-Reactify-Version\": pkg.version,\n },\n }\n );\n };\n\n return { track };\n};\n\nfunction getTrackEvents(event: TrackEvent): TrackEvent[] {\n const { eventName } = event;\n let events: TrackEvent[] = [];\n\n switch (eventName) {\n case \"search\":\n events = [\n {\n eventName,\n payload: {\n ...event.payload,\n searchTerm: event.payload.searchTerm.trim(),\n },\n },\n ];\n\n break;\n\n case \"zeroResults\":\n events = [\n {\n eventName,\n payload: {\n ...event.payload,\n searchTerm: event.payload.searchTerm.trim(),\n },\n },\n ];\n\n break;\n\n case \"viewProduct\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"clickProduct\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"viewPromotion\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"clickPromotion\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"paginationChange\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"sortChange\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"filterChange\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n }\n\n return events;\n}\n\nexport type TrackEvent =\n | TrackEvent.SearchEvent\n | TrackEvent.ZeroResultsEvent\n | TrackEvent.ViewProductEvent\n | TrackEvent.ClickProductEvent\n | TrackEvent.ViewPromotionEvent\n | TrackEvent.ClickPromotionEvent\n | TrackEvent.PaginationChangeEvent\n | TrackEvent.SortChangeEvent\n | TrackEvent.FilterChangeEvent;\n\nexport namespace TrackEvent {\n export interface SearchEvent {\n eventName: \"search\";\n payload: SearchEvent.Payload;\n }\n\n export namespace SearchEvent {\n export interface Payload {\n searchTerm: string;\n }\n }\n\n export interface ZeroResultsEvent {\n eventName: \"zeroResults\";\n payload: ZeroResultsEvent.Payload;\n }\n\n export namespace ZeroResultsEvent {\n export interface Payload {\n searchTerm: string;\n }\n }\n\n export interface ViewProductEvent {\n eventName: \"viewProduct\";\n payload: ViewProductEvent.Payload;\n }\n\n export namespace ViewProductEvent {\n export interface Payload {\n elasticProduct: ElasticProduct;\n }\n }\n\n export interface ClickProductEvent {\n eventName: \"clickProduct\";\n payload: ClickProductEvent.Payload;\n }\n\n export namespace ClickProductEvent {\n export interface Payload {\n elasticProduct: ElasticProduct;\n }\n }\n\n export interface ViewPromotionEvent {\n eventName: \"viewPromotion\";\n payload: ViewPromotionEvent.Payload;\n }\n\n export namespace ViewPromotionEvent {\n export interface Payload {\n link: string;\n title: string;\n }\n }\n\n export interface ClickPromotionEvent {\n eventName: \"clickPromotion\";\n payload: ClickPromotionEvent.Payload;\n }\n\n export namespace ClickPromotionEvent {\n export interface Payload {\n link: string;\n title: string;\n }\n }\n\n export interface PaginationChangeEvent {\n eventName: \"paginationChange\";\n payload: PaginationChangeEvent.Payload;\n }\n\n export namespace PaginationChangeEvent {\n export interface Payload {\n page: number;\n source: \"search\" | \"collection\";\n }\n }\n\n export interface SortChangeEvent {\n eventName: \"sortChange\";\n payload: SortChangeEvent.Payload;\n }\n\n export namespace SortChangeEvent {\n export interface Payload {\n type: string;\n }\n }\n\n export interface FilterChangeEvent {\n eventName: \"filterChange\";\n payload: FilterChangeEvent.Payload;\n }\n\n export namespace FilterChangeEvent {\n export interface Payload {\n name: string;\n value: string;\n }\n }\n\n export interface ElasticProduct {\n id: number;\n title: string;\n }\n}\n"]}
1
+ {"version":3,"file":"useAnalytics.js","sourceRoot":"","sources":["../../../src/hooks/useAnalytics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,oCAAoD;AACpD,wCAAmC;AAE5B,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC/C,MAAM,GAAG,GAAG,+CAA+C,CAAC;IAC5D,MAAM,KAAK,GAAG,CAAO,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AAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,gBAAgB;YACnB,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,kBAAkB;YACrB,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,YAAY;YACf,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;QAER,KAAK,cAAc;YACjB,MAAM,GAAG;gBACP;oBACE,SAAS;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;YAEF,MAAM;KACT;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import axios from \"axios\";\n\nimport { useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useAnalytics = () => {\n const { options } = useReactifySearchContext();\n const url = \"https://analytics.search.reactify.app/record/\";\n const track = async (event: TrackEvent) => {\n if (!options.shopifyPermanentDomain) {\n console.warn(\n new Error(\n 'Unable to send tracking event, missing value for \"shopifyPermanentDomain\".'\n )\n );\n\n return;\n }\n\n debug.log(\"useAnalytics\", \"track\", event);\n\n const events = getTrackEvents(event);\n return axios.post(\n url,\n { events },\n { headers: { \"X-Reactify-Tenant\": options.shopifyPermanentDomain } }\n );\n };\n\n return { track };\n};\n\nfunction getTrackEvents(event: TrackEvent): TrackEvent[] {\n const { eventName } = event;\n let events: TrackEvent[] = [];\n\n switch (eventName) {\n case \"search\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"zeroResults\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"viewProduct\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"clickProduct\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"viewPromotion\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"clickPromotion\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"paginationChange\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"sortChange\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n\n case \"filterChange\":\n events = [\n {\n eventName,\n payload: event.payload,\n },\n ];\n\n break;\n }\n\n return events;\n}\n\nexport type TrackEvent =\n | TrackEvent.SearchEvent\n | TrackEvent.ZeroResultsEvent\n | TrackEvent.ViewProductEvent\n | TrackEvent.ClickProductEvent\n | TrackEvent.ViewPromotionEvent\n | TrackEvent.ClickPromotionEvent\n | TrackEvent.PaginationChangeEvent\n | TrackEvent.SortChangeEvent\n | TrackEvent.FilterChangeEvent;\n\nexport namespace TrackEvent {\n export interface SearchEvent {\n eventName: \"search\";\n payload: SearchEvent.Payload;\n }\n\n export namespace SearchEvent {\n export interface Payload {\n searchTerm: string;\n }\n }\n\n export interface ZeroResultsEvent {\n eventName: \"zeroResults\";\n payload: ZeroResultsEvent.Payload;\n }\n\n export namespace ZeroResultsEvent {\n export interface Payload {\n searchTerm: string;\n }\n }\n\n export interface ViewProductEvent {\n eventName: \"viewProduct\";\n payload: ViewProductEvent.Payload;\n }\n\n export namespace ViewProductEvent {\n export interface Payload {\n elasticProduct: ElasticProduct;\n }\n }\n\n export interface ClickProductEvent {\n eventName: \"clickProduct\";\n payload: ClickProductEvent.Payload;\n }\n\n export namespace ClickProductEvent {\n export interface Payload {\n elasticProduct: ElasticProduct;\n }\n }\n\n export interface ViewPromotionEvent {\n eventName: \"viewPromotion\";\n payload: ViewPromotionEvent.Payload;\n }\n\n export namespace ViewPromotionEvent {\n export interface Payload {\n link: string;\n title: string;\n }\n }\n\n export interface ClickPromotionEvent {\n eventName: \"clickPromotion\";\n payload: ClickPromotionEvent.Payload;\n }\n\n export namespace ClickPromotionEvent {\n export interface Payload {\n link: string;\n title: string;\n }\n }\n\n export interface PaginationChangeEvent {\n eventName: \"paginationChange\";\n payload: PaginationChangeEvent.Payload;\n }\n\n export namespace PaginationChangeEvent {\n export interface Payload {\n page: number;\n source: \"search\" | \"collection\";\n }\n }\n\n export interface SortChangeEvent {\n eventName: \"sortChange\";\n payload: SortChangeEvent.Payload;\n }\n\n export namespace SortChangeEvent {\n export interface Payload {\n type: string;\n }\n }\n\n export interface FilterChangeEvent {\n eventName: \"filterChange\";\n payload: FilterChangeEvent.Payload;\n }\n\n export namespace FilterChangeEvent {\n export interface Payload {\n name: string;\n value: string;\n }\n }\n\n export interface ElasticProduct {\n id: number;\n title: string;\n }\n}\n"]}