@usereactify/search 5.26.1 → 5.26.5

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 (131) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/package.json +10 -11
  3. package/dist/src/components/ClearAll/ClearAll.js +31 -3
  4. package/dist/src/components/ClearAll/ClearAll.js.map +1 -1
  5. package/dist/src/components/Example/ExampleFilterRange.js +3 -1
  6. package/dist/src/components/Example/ExampleFilterRange.js.map +1 -1
  7. package/dist/src/components/Example/ExampleFilterSlider.js +24 -7
  8. package/dist/src/components/Example/ExampleFilterSlider.js.map +1 -1
  9. package/dist/src/components/Example/ExampleFilters.d.ts +1 -3
  10. package/dist/src/components/Example/ExampleFilters.js +8 -4
  11. package/dist/src/components/Example/ExampleFilters.js.map +1 -1
  12. package/dist/src/components/Example/ExampleFiltersSelected.js +24 -10
  13. package/dist/src/components/Example/ExampleFiltersSelected.js.map +1 -1
  14. package/dist/src/components/Example/ExampleHookUseResults.d.ts +2 -0
  15. package/dist/src/components/Example/ExampleHookUseResults.js +25 -0
  16. package/dist/src/components/Example/ExampleHookUseResults.js.map +1 -0
  17. package/dist/src/components/Example/ExampleSuggestions.d.ts +4 -0
  18. package/dist/src/components/Example/ExampleSuggestions.js +16 -0
  19. package/dist/src/components/Example/ExampleSuggestions.js.map +1 -0
  20. package/dist/src/components/Example/index.d.ts +3 -0
  21. package/dist/src/components/Example/index.js +3 -0
  22. package/dist/src/components/Example/index.js.map +1 -1
  23. package/dist/src/components/Filter/Filter.d.ts +2 -2
  24. package/dist/src/components/Filter/Filter.js +91 -18
  25. package/dist/src/components/Filter/Filter.js.map +1 -1
  26. package/dist/src/components/Filter/Filters.d.ts +17 -3
  27. package/dist/src/components/Filter/Filters.js +1 -2
  28. package/dist/src/components/Filter/Filters.js.map +1 -1
  29. package/dist/src/components/Filter/FiltersSelected.d.ts +7 -2
  30. package/dist/src/components/Filter/FiltersSelected.js +45 -2
  31. package/dist/src/components/Filter/FiltersSelected.js.map +1 -1
  32. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.d.ts +5 -7
  33. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js +42 -24
  34. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -1
  35. package/dist/src/components/Result/Results.js +24 -9
  36. package/dist/src/components/Result/Results.js.map +1 -1
  37. package/dist/src/components/Sensor/SensorCollection.js +4 -0
  38. package/dist/src/components/Sensor/SensorCollection.js.map +1 -1
  39. package/dist/src/components/Sensor/SensorInventoryAvailable.js +17 -7
  40. package/dist/src/components/Sensor/SensorInventoryAvailable.js.map +1 -1
  41. package/dist/src/components/Sensor/SensorPublished.js +13 -6
  42. package/dist/src/components/Sensor/SensorPublished.js.map +1 -1
  43. package/dist/src/components/Sensor/SensorSearchTerm.js +92 -66
  44. package/dist/src/components/Sensor/SensorSearchTerm.js.map +1 -1
  45. package/dist/src/components/Sensor/SensorSort.js +75 -65
  46. package/dist/src/components/Sensor/SensorSort.js.map +1 -1
  47. package/dist/src/components/Sensor/Sensors.js +1 -7
  48. package/dist/src/components/Sensor/Sensors.js.map +1 -1
  49. package/dist/src/components/Sensor/index.d.ts +0 -1
  50. package/dist/src/components/Sensor/index.js +0 -2
  51. package/dist/src/components/Sensor/index.js.map +1 -1
  52. package/dist/src/components/Suggestions/Suggestions.d.ts +12 -0
  53. package/dist/src/components/Suggestions/Suggestions.js +44 -0
  54. package/dist/src/components/Suggestions/Suggestions.js.map +1 -0
  55. package/dist/src/components/Suggestions/index.d.ts +1 -0
  56. package/dist/src/components/Suggestions/index.js +14 -0
  57. package/dist/src/components/Suggestions/index.js.map +1 -0
  58. package/dist/src/components/index.d.ts +1 -0
  59. package/dist/src/components/index.js +1 -0
  60. package/dist/src/components/index.js.map +1 -1
  61. package/dist/src/hooks/index.d.ts +3 -0
  62. package/dist/src/hooks/index.js +3 -0
  63. package/dist/src/hooks/index.js.map +1 -1
  64. package/dist/src/hooks/react-slider/useReactSliderProps.d.ts +4 -0
  65. package/dist/src/hooks/react-slider/useReactSliderProps.js +28 -0
  66. package/dist/src/hooks/react-slider/useReactSliderProps.js.map +1 -0
  67. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.d.ts +2 -7
  68. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js +10 -3
  69. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js.map +1 -1
  70. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.d.ts +1 -0
  71. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js +3 -5
  72. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js.map +1 -1
  73. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.d.ts +1 -0
  74. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js +3 -5
  75. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js.map +1 -1
  76. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js +1 -1
  77. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js.map +1 -1
  78. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js +1 -3
  79. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js.map +1 -1
  80. package/dist/src/hooks/reactivesearch/useReactiveReactProp.d.ts +2 -1
  81. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +8 -3
  82. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js.map +1 -1
  83. package/dist/src/hooks/useAnalytics.js +23 -3
  84. package/dist/src/hooks/useAnalytics.js.map +1 -1
  85. package/dist/src/hooks/useConfig.js +9 -27
  86. package/dist/src/hooks/useConfig.js.map +1 -1
  87. package/dist/src/hooks/useCuration.js +12 -1
  88. package/dist/src/hooks/useCuration.js.map +1 -1
  89. package/dist/src/hooks/useFilterListProps.js +15 -2
  90. package/dist/src/hooks/useFilterListProps.js.map +1 -1
  91. package/dist/src/hooks/useFilterRangeProps.d.ts +1 -10
  92. package/dist/src/hooks/useFilterRangeProps.js +36 -47
  93. package/dist/src/hooks/useFilterRangeProps.js.map +1 -1
  94. package/dist/src/hooks/useFilterSliderProps.d.ts +6 -8
  95. package/dist/src/hooks/useFilterSliderProps.js +31 -10
  96. package/dist/src/hooks/useFilterSliderProps.js.map +1 -1
  97. package/dist/src/hooks/useFilters.js +0 -3
  98. package/dist/src/hooks/useFilters.js.map +1 -1
  99. package/dist/src/hooks/useFlags.d.ts +21 -0
  100. package/dist/src/hooks/useFlags.js +49 -0
  101. package/dist/src/hooks/useFlags.js.map +1 -0
  102. package/dist/src/hooks/useIndices.d.ts +5 -0
  103. package/dist/src/hooks/useIndices.js +49 -0
  104. package/dist/src/hooks/useIndices.js.map +1 -0
  105. package/dist/src/hooks/useReactifySearchContext.d.ts +19 -11
  106. package/dist/src/hooks/useReactifySearchContext.js.map +1 -1
  107. package/dist/src/hooks/useResults.d.ts +21 -0
  108. package/dist/src/hooks/useResults.js +19 -0
  109. package/dist/src/hooks/useResults.js.map +1 -0
  110. package/dist/src/hooks/useSearch.js +4 -2
  111. package/dist/src/hooks/useSearch.js.map +1 -1
  112. package/dist/src/hooks/useSortBy.js +5 -1
  113. package/dist/src/hooks/useSortBy.js.map +1 -1
  114. package/dist/src/types/config.d.ts +11 -5
  115. package/dist/src/types/config.js.map +1 -1
  116. package/dist/src/types/elastic.d.ts +53 -17
  117. package/dist/src/types/elastic.js.map +1 -1
  118. package/dist/src/types/firestore.d.ts +3 -0
  119. package/dist/src/types/firestore.js.map +1 -1
  120. package/dist/src/types/reactivesearch.d.ts +1 -1
  121. package/dist/src/types/reactivesearch.js.map +1 -1
  122. package/package.json +1 -1
  123. package/dist/src/components/Sensor/SensorSortScore.d.ts +0 -2
  124. package/dist/src/components/Sensor/SensorSortScore.js +0 -13
  125. package/dist/src/components/Sensor/SensorSortScore.js.map +0 -1
  126. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +0 -27
  127. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js +0 -71
  128. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js.map +0 -1
  129. package/dist/src/hooks/usePaginationLoadMore.d.ts +0 -15
  130. package/dist/src/hooks/usePaginationLoadMore.js +0 -38
  131. package/dist/src/hooks/usePaginationLoadMore.js.map +0 -1
@@ -16,9 +16,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Filter = void 0;
18
18
  const react_1 = __importDefault(require("react"));
19
+ const ReactiveComponent_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent"));
19
20
  const MultiList_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/list/MultiList"));
20
21
  const SingleList_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/list/SingleList"));
21
- const DynamicRangeSlider_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/range/DynamicRangeSlider"));
22
22
  const SingleRange_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/range/SingleRange"));
23
23
  const MultiRange_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/range/MultiRange"));
24
24
  const hooks_1 = require("../../hooks");
@@ -43,7 +43,7 @@ const Filter = (props) => {
43
43
  if ("range" === props.filter.displayType) {
44
44
  return react_1.default.createElement(FilterRangeSingle, Object.assign({}, props));
45
45
  }
46
- console.log(`filter with display type "${props.filter.displayType}" not yet supported`);
46
+ console.warn(`filter with display type "${props.filter.displayType}" not yet supported`);
47
47
  return null;
48
48
  };
49
49
  exports.Filter = Filter;
@@ -64,35 +64,108 @@ const FilterRangeSingle = (props) => {
64
64
  react_1.default.createElement("div", { style: {
65
65
  display: "none",
66
66
  } },
67
- react_1.default.createElement(SingleRange_1.default, Object.assign({}, reactiveFilterRangeProps, { value: filterRangeProps.value, onChange: filterRangeProps.handleChange }))),
67
+ react_1.default.createElement(SingleRange_1.default, Object.assign({}, reactiveFilterRangeProps, { value: filterRangeProps.values[0], onChange: filterRangeProps.handleChange }))),
68
68
  react_1.default.createElement(RenderRangeComponent, { filterRangeProps: filterRangeProps, filter: props.filter })));
69
69
  };
70
70
  const FilterRangeMulti = (props) => {
71
71
  var _a;
72
72
  const reactiveFilterRangeProps = (0, hooks_1.useReactiveFilterRangeProps)(props.filter);
73
- const filterRangeProps = (0, hooks_1.useFilterRangeMultiProps)(props.filter);
73
+ const filterRangeProps = (0, hooks_1.useFilterRangeProps)(props.filter);
74
74
  const RenderRangeComponent = (_a = props.renderFilterRange) !== null && _a !== void 0 ? _a : components_1.ExampleFilterRange;
75
75
  return (react_1.default.createElement(react_1.default.Fragment, null,
76
76
  react_1.default.createElement("div", { style: {
77
77
  display: "none",
78
78
  } },
79
- react_1.default.createElement(MultiRange_1.default, Object.assign({}, reactiveFilterRangeProps, { value: filterRangeProps.values, onChange: filterRangeProps.handleChange }))),
79
+ react_1.default.createElement(MultiRange_1.default, Object.assign({}, reactiveFilterRangeProps, { value: filterRangeProps.values,
80
+ // @note: onChange handler must be defined for controlled component to work correctly
81
+ onChange: () => { }, onValueChange: (values) => {
82
+ if (values.length === 0) {
83
+ filterRangeProps.handleClear();
84
+ }
85
+ } }))),
80
86
  react_1.default.createElement(RenderRangeComponent, { filterRangeProps: filterRangeProps, filter: props.filter })));
81
87
  };
82
88
  const FilterSlider = (props) => {
83
- var _a;
84
- const reactiveFilterSliderProps = (0, hooks_1.useReactiveFilterSliderProps)(props.filter);
85
- const filterSliderProps = (0, hooks_1.useFilterSliderProps)(props.filter);
86
- const RenderSliderComponent = (_a = props.renderFilterSlider) !== null && _a !== void 0 ? _a : components_1.ExampleFilterSlider;
87
- return (react_1.default.createElement(react_1.default.Fragment, null,
88
- props.renderFilterSlider ? (react_1.default.createElement("div", { style: {
89
- display: "none",
90
- } },
91
- react_1.default.createElement(DynamicRangeSlider_1.default, Object.assign({}, reactiveFilterSliderProps, { value: () => filterSliderProps.value, onChange: (value) => filterSliderProps.handleChange({
92
- start: value[0],
93
- end: value[1],
94
- }) })))) : null,
95
- react_1.default.createElement(RenderSliderComponent, { filterSliderProps: filterSliderProps, filter: props.filter })));
89
+ const reactiveFilterSharedProps = (0, hooks_1.useReactiveFilterSharedProps)(props.filter);
90
+ return (react_1.default.createElement(ReactiveComponent_1.default, Object.assign({}, reactiveFilterSharedProps, { defaultQuery: () => ({
91
+ aggs: {
92
+ min: {
93
+ min: {
94
+ field: props.filter.field,
95
+ },
96
+ },
97
+ max: {
98
+ max: {
99
+ field: props.filter.field,
100
+ },
101
+ },
102
+ },
103
+ }), render: (reactivesearchFilterProps) => {
104
+ var _a, _b, _c, _d;
105
+ if (((_b = (_a = reactivesearchFilterProps === null || reactivesearchFilterProps === void 0 ? void 0 : reactivesearchFilterProps.aggregations) === null || _a === void 0 ? void 0 : _a.min) === null || _b === void 0 ? void 0 : _b.value) ===
106
+ ((_d = (_c = reactivesearchFilterProps === null || reactivesearchFilterProps === void 0 ? void 0 : reactivesearchFilterProps.aggregations) === null || _c === void 0 ? void 0 : _c.max) === null || _d === void 0 ? void 0 : _d.value)) {
107
+ return null;
108
+ }
109
+ return (react_1.default.createElement(FilterSliderInner, Object.assign({}, props, { reactivesearchFilterProps: reactivesearchFilterProps })));
110
+ } })));
111
+ };
112
+ // inner component exists only so we can use memos in reactivesearch render functions
113
+ const FilterSliderInner = (props) => {
114
+ var _a, _b;
115
+ const { filter, renderFilterSlider, reactivesearchFilterProps } = props, otherProps = __rest(props, ["filter", "renderFilterSlider", "reactivesearchFilterProps"]);
116
+ const filterSliderProps = (0, hooks_1.useFilterSliderProps)(filter);
117
+ react_1.default.useEffect(() => {
118
+ if (reactivesearchFilterProps.aggregations) {
119
+ filterSliderProps.handleRange([
120
+ reactivesearchFilterProps.aggregations.min.value,
121
+ reactivesearchFilterProps.aggregations.max.value,
122
+ ]);
123
+ }
124
+ }, [
125
+ (_a = reactivesearchFilterProps.aggregations) === null || _a === void 0 ? void 0 : _a.min.value,
126
+ (_b = reactivesearchFilterProps.aggregations) === null || _b === void 0 ? void 0 : _b.max.value,
127
+ ]);
128
+ react_1.default.useEffect(() => {
129
+ if (filterSliderProps.value[0] === 0 && filterSliderProps.value[1] === 0) {
130
+ return;
131
+ }
132
+ props.reactivesearchFilterProps.setQuery({
133
+ query: {
134
+ query: {
135
+ bool: {
136
+ must: [
137
+ {
138
+ bool: {
139
+ must: [
140
+ {
141
+ match: {
142
+ published: true,
143
+ },
144
+ },
145
+ {
146
+ range: {
147
+ [props.filter.field]: {
148
+ gte: filterSliderProps.value[0],
149
+ lte: filterSliderProps.value[1],
150
+ boost: 2,
151
+ },
152
+ },
153
+ },
154
+ ],
155
+ },
156
+ },
157
+ ],
158
+ },
159
+ },
160
+ },
161
+ value: filterSliderProps.value,
162
+ });
163
+ }, [filterSliderProps.value]);
164
+ if (renderFilterSlider) {
165
+ const Component = renderFilterSlider;
166
+ return (react_1.default.createElement(Component, Object.assign({ filterSliderProps: filterSliderProps, filter: filter }, otherProps)));
167
+ }
168
+ return (react_1.default.createElement(components_1.ExampleFilterSlider, Object.assign({ filterSliderProps: filterSliderProps, filter: filter }, otherProps)));
96
169
  };
97
170
  // inner component exists only so we can use memos in reactivesearch render functions
98
171
  const FilterListInner = (props) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Filter.js","sourceRoot":"","sources":["../../../../src/components/Filter/Filter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,wGAAgF;AAChF,0GAAkF;AAClF,2HAAmG;AACnG,6GAAqF;AACrF,2GAAmF;AAMnF,uCAQqB;AACrB,iDAI0B;AAwBnB,MAAM,MAAM,GAA0B,CAAC,KAAK,EAAE,EAAE;IACrD,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;QACzC,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;YACxC,OAAO,8BAAC,iBAAiB,oBAAK,KAAK,EAAI,CAAC;SACzC;QACD,OAAO,8BAAC,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,CAAC,MAAM,EAAE;QACxC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,gBAAgB,EAAE;QACpB,MAAM,SAAS,GAAG,gBAAgB,CAAC;QACnC,OAAO,CACL,8BAAC,SAAS,kBACR,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;KACH;IAED,OAAO,CACL,8BAAC,8BAAiB,kBAChB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport MultiList from \"@appbaseio/reactivesearch/lib/components/list/MultiList\";\nimport SingleList from \"@appbaseio/reactivesearch/lib/components/list/SingleList\";\nimport DynamicRangeSlider from \"@appbaseio/reactivesearch/lib/components/range/DynamicRangeSlider\";\nimport SingleRange from \"@appbaseio/reactivesearch/lib/components/range/SingleRange\";\nimport MultiRange from \"@appbaseio/reactivesearch/lib/components/range/MultiRange\";\n\nimport type {\n ConfigFilterOption,\n ReactivesearchFilterListProps,\n} from \"../../types\";\nimport {\n useFilterListProps,\n useFilterRangeProps,\n useFilterSliderProps,\n useFilterRangeMultiProps,\n useReactiveFilterListProps,\n useReactiveFilterRangeProps,\n useReactiveFilterSliderProps,\n} from \"../../hooks\";\nimport {\n ExampleFilterList,\n ExampleFilterRange,\n ExampleFilterSlider,\n} from \"../../components\";\n\nexport type FilterProps = {\n /** The filter option being rendered */\n filter: ConfigFilterOption;\n /** Render method for List filters */\n renderFilterList?: React.FC<{\n filter: ConfigFilterOption;\n filterListProps: ReturnType<typeof useFilterListProps>;\n }>;\n /** Render method for Range filters */\n renderFilterRange?: React.FC<{\n filter: ConfigFilterOption;\n filterRangeProps:\n | ReturnType<typeof useFilterRangeProps>\n | ReturnType<typeof useFilterRangeMultiProps>;\n }>;\n /** Render method for Slider filters */\n renderFilterSlider?: React.FC<{\n filter: ConfigFilterOption;\n filterSliderProps: ReturnType<typeof useFilterSliderProps>;\n }>;\n};\n\nexport const Filter: React.FC<FilterProps> = (props) => {\n if (\"single\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeSingle {...props} />;\n }\n return <FilterSingleList {...props} />;\n }\n\n if (\"multi\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeMulti {...props} />;\n }\n return <FilterMultiList {...props} />;\n }\n\n if (\"slider\" === props.filter.displayType) {\n return <FilterSlider {...props} />;\n }\n\n // TODO: Legacy range filter, migrate to new single and multi ranges\n if (\"range\" === props.filter.displayType) {\n return <FilterRangeSingle {...props} />;\n }\n\n console.log(\n `filter with display type \"${props.filter.displayType}\" not yet supported`\n );\n\n return null;\n};\n\nconst FilterSingleList: React.FC<FilterProps> = (props) => {\n const reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <SingleList\n {...reactiveFilterListProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterMultiList: React.FC<FilterProps> = (props) => {\n const reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <MultiList\n {...reactiveFilterListProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterRangeSingle: React.FC<FilterProps> = (props) => {\n const reactiveFilterRangeProps = useReactiveFilterRangeProps(props.filter);\n\n const filterRangeProps = useFilterRangeProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <SingleRange\n {...reactiveFilterRangeProps}\n value={filterRangeProps.value}\n onChange={filterRangeProps.handleChange}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterRangeMulti: React.FC<FilterProps> = (props) => {\n const reactiveFilterRangeProps = useReactiveFilterRangeProps(props.filter);\n\n const filterRangeProps = useFilterRangeMultiProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <MultiRange\n {...reactiveFilterRangeProps}\n value={filterRangeProps.values}\n onChange={filterRangeProps.handleChange}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterSlider: React.FC<FilterProps> = (props) => {\n const reactiveFilterSliderProps = useReactiveFilterSliderProps(props.filter);\n\n const filterSliderProps = useFilterSliderProps(props.filter);\n\n const RenderSliderComponent = props.renderFilterSlider ?? ExampleFilterSlider;\n\n return (\n <>\n {props.renderFilterSlider ? (\n <div\n style={{\n display: \"none\",\n }}\n >\n <DynamicRangeSlider\n {...reactiveFilterSliderProps}\n value={() => filterSliderProps.value}\n onChange={(value) =>\n filterSliderProps.handleChange({\n start: value[0],\n end: value[1],\n })\n }\n />\n </div>\n ) : null}\n <RenderSliderComponent\n filterSliderProps={filterSliderProps}\n filter={props.filter}\n />\n </>\n );\n};\n\n// inner component exists only so we can use memos in reactivesearch render functions\nconst FilterListInner: React.FC<\n FilterProps & { reactivesearchFilterProps: ReactivesearchFilterListProps }\n> = (props) => {\n const { filter, renderFilterList, reactivesearchFilterProps, ...otherProps } =\n props;\n\n const filterListProps = useFilterListProps(filter, reactivesearchFilterProps);\n\n // hide entire filter when no options available\n if (0 === filterListProps.options.length) {\n return null;\n }\n\n if (renderFilterList) {\n const Component = renderFilterList;\n return (\n <Component\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n }\n\n return (\n <ExampleFilterList\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n"]}
1
+ {"version":3,"file":"Filter.js","sourceRoot":"","sources":["../../../../src/components/Filter/Filter.tsx"],"names":[],"mappings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SAAS,GAAG,gBAAgB,CAAC;QACnC,OAAO,CACL,8BAAC,SAAS,kBACR,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;KACH;IAED,OAAO,CACL,8BAAC,8BAAiB,kBAChB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\nimport MultiList from \"@appbaseio/reactivesearch/lib/components/list/MultiList\";\nimport SingleList from \"@appbaseio/reactivesearch/lib/components/list/SingleList\";\nimport SingleRange from \"@appbaseio/reactivesearch/lib/components/range/SingleRange\";\nimport MultiRange from \"@appbaseio/reactivesearch/lib/components/range/MultiRange\";\n\nimport type {\n ConfigFilterOption,\n ReactivesearchFilterListProps,\n} from \"../../types\";\nimport {\n useFilterListProps,\n useFilterRangeProps,\n useFilterSliderProps,\n useReactiveFilterListProps,\n useReactiveFilterRangeProps,\n useReactiveFilterSharedProps,\n useReactiveFilterSliderProps,\n} from \"../../hooks\";\nimport {\n ExampleFilterList,\n ExampleFilterRange,\n ExampleFilterSlider,\n} from \"../../components\";\n\nexport type FilterProps = {\n /** The filter option being rendered */\n filter: ConfigFilterOption;\n /** Render method for List filters */\n renderFilterList?: React.FC<{\n filter: ConfigFilterOption;\n filterListProps: ReturnType<typeof useFilterListProps>;\n }>;\n /** Render method for Range filters */\n renderFilterRange?: React.FC<{\n filter: ConfigFilterOption;\n filterRangeProps: ReturnType<typeof useFilterRangeProps>;\n }>;\n /** Render method for Slider filters */\n renderFilterSlider?: React.FC<{\n filter: ConfigFilterOption;\n filterSliderProps: ReturnType<typeof useFilterSliderProps>;\n // reactSliderProps: ReturnType<typeof useReactSliderProps>;\n }>;\n};\n\nexport const Filter: React.FC<FilterProps> = (props) => {\n if (\"single\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeSingle {...props} />;\n }\n return <FilterSingleList {...props} />;\n }\n\n if (\"multi\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeMulti {...props} />;\n }\n return <FilterMultiList {...props} />;\n }\n\n if (\"slider\" === props.filter.displayType) {\n return <FilterSlider {...props} />;\n }\n\n // TODO: Legacy range filter, migrate to new single and multi ranges\n if (\"range\" === props.filter.displayType) {\n return <FilterRangeSingle {...props} />;\n }\n\n console.warn(\n `filter with display type \"${props.filter.displayType}\" not yet supported`\n );\n\n return null;\n};\n\nconst FilterSingleList: React.FC<FilterProps> = (props) => {\n const reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <SingleList\n {...reactiveFilterListProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterMultiList: React.FC<FilterProps> = (props) => {\n const reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <MultiList\n {...reactiveFilterListProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterRangeSingle: React.FC<FilterProps> = (props) => {\n const reactiveFilterRangeProps = useReactiveFilterRangeProps(props.filter);\n\n const filterRangeProps = useFilterRangeProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <SingleRange\n {...reactiveFilterRangeProps}\n value={filterRangeProps.values[0]}\n onChange={filterRangeProps.handleChange}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterRangeMulti: React.FC<FilterProps> = (props) => {\n const reactiveFilterRangeProps = useReactiveFilterRangeProps(props.filter);\n\n const filterRangeProps = useFilterRangeProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <MultiRange\n {...reactiveFilterRangeProps}\n value={filterRangeProps.values}\n // @note: onChange handler must be defined for controlled component to work correctly\n onChange={() => {}}\n onValueChange={(values) => {\n if (values.length === 0) {\n filterRangeProps.handleClear();\n }\n }}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterSlider: React.FC<FilterProps> = (props) => {\n const reactiveFilterSharedProps = useReactiveFilterSharedProps(props.filter);\n\n return (\n <ReactiveComponent\n {...reactiveFilterSharedProps}\n defaultQuery={() => ({\n aggs: {\n min: {\n min: {\n field: props.filter.field,\n },\n },\n max: {\n max: {\n field: props.filter.field,\n },\n },\n },\n })}\n render={(reactivesearchFilterProps) => {\n if (\n reactivesearchFilterProps?.aggregations?.min?.value ===\n reactivesearchFilterProps?.aggregations?.max?.value\n ) {\n return null;\n }\n\n return (\n <FilterSliderInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n );\n }}\n />\n );\n};\n\n// inner component exists only so we can use memos in reactivesearch render functions\nconst FilterSliderInner: React.FC<\n FilterProps & { reactivesearchFilterProps: any }\n> = (props) => {\n const {\n filter,\n renderFilterSlider,\n reactivesearchFilterProps,\n ...otherProps\n } = props;\n\n const filterSliderProps = useFilterSliderProps(filter);\n\n React.useEffect(() => {\n if (reactivesearchFilterProps.aggregations) {\n filterSliderProps.handleRange([\n reactivesearchFilterProps.aggregations.min.value,\n reactivesearchFilterProps.aggregations.max.value,\n ]);\n }\n }, [\n reactivesearchFilterProps.aggregations?.min.value,\n reactivesearchFilterProps.aggregations?.max.value,\n ]);\n\n React.useEffect(() => {\n if (filterSliderProps.value[0] === 0 && filterSliderProps.value[1] === 0) {\n return;\n }\n\n props.reactivesearchFilterProps.setQuery({\n query: {\n query: {\n bool: {\n must: [\n {\n bool: {\n must: [\n {\n match: {\n published: true,\n },\n },\n {\n range: {\n [props.filter.field]: {\n gte: filterSliderProps.value[0],\n lte: filterSliderProps.value[1],\n boost: 2,\n },\n },\n },\n ],\n },\n },\n ],\n },\n },\n },\n value: filterSliderProps.value,\n });\n }, [filterSliderProps.value]);\n\n if (renderFilterSlider) {\n const Component = renderFilterSlider;\n return (\n <Component\n filterSliderProps={filterSliderProps}\n filter={filter}\n {...otherProps}\n />\n );\n }\n\n return (\n <ExampleFilterSlider\n filterSliderProps={filterSliderProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n\n// inner component exists only so we can use memos in reactivesearch render functions\nconst FilterListInner: React.FC<\n FilterProps & { reactivesearchFilterProps: ReactivesearchFilterListProps }\n> = (props) => {\n const { filter, renderFilterList, reactivesearchFilterProps, ...otherProps } =\n props;\n\n const filterListProps = useFilterListProps(filter, reactivesearchFilterProps);\n\n // hide entire filter when no options available\n if (0 === filterListProps.options.length) {\n return null;\n }\n\n if (renderFilterList) {\n const Component = renderFilterList;\n return (\n <Component\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n }\n\n return (\n <ExampleFilterList\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n"]}
@@ -1,7 +1,21 @@
1
1
  import React from "react";
2
- import { useFilters } from "../../hooks";
2
+ import { useFilterListProps, useFilterRangeProps, useFilterSliderProps } from "../../hooks";
3
+ import { ConfigFilterOption } from "../../types";
3
4
  export declare type FiltersProps = {
4
- /** Render method called once for all filters */
5
- render?: React.FC<ReturnType<typeof useFilters>>;
5
+ /** Render method for List filters */
6
+ renderFilterList?: React.FC<{
7
+ filter: ConfigFilterOption;
8
+ filterListProps: ReturnType<typeof useFilterListProps>;
9
+ }>;
10
+ /** Render method for Range filters */
11
+ renderFilterRange?: React.FC<{
12
+ filter: ConfigFilterOption;
13
+ filterRangeProps: ReturnType<typeof useFilterRangeProps>;
14
+ }>;
15
+ /** Render method for Slider filters */
16
+ renderFilterSlider?: React.FC<{
17
+ filter: ConfigFilterOption;
18
+ filterSliderProps: ReturnType<typeof useFilterSliderProps>;
19
+ }>;
6
20
  };
7
21
  export declare const Filters: React.FC<FiltersProps>;
@@ -10,8 +10,7 @@ const components_1 = require("../../components");
10
10
  const Filters = (props) => {
11
11
  var _a;
12
12
  const filterStackHook = (0, hooks_1.useFilters)();
13
- const RenderComponent = (_a = props.render) !== null && _a !== void 0 ? _a : components_1.ExampleFilters;
14
- return react_1.default.createElement(RenderComponent, Object.assign({}, filterStackHook));
13
+ return (react_1.default.createElement(react_1.default.Fragment, null, (_a = filterStackHook.filters) === null || _a === void 0 ? void 0 : _a.map((filter) => (react_1.default.createElement(components_1.Filter, { key: filter.id, filter: filter, renderFilterList: props.renderFilterList, renderFilterSlider: props.renderFilterSlider, renderFilterRange: props.renderFilterRange })))));
15
14
  };
16
15
  exports.Filters = Filters;
17
16
  //# sourceMappingURL=Filters.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Filters.js","sourceRoot":"","sources":["../../../../src/components/Filter/Filters.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAyC;AACzC,iDAAkD;AAO3C,MAAM,OAAO,GAA2B,CAAC,KAAK,EAAE,EAAE;;IACvD,MAAM,eAAe,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,MAAM,eAAe,GAAG,MAAA,KAAK,CAAC,MAAM,mCAAI,2BAAc,CAAC;IAEvD,OAAO,8BAAC,eAAe,oBAAK,eAAe,EAAI,CAAC;AAClD,CAAC,CAAC;AANW,QAAA,OAAO,WAMlB","sourcesContent":["import React from \"react\";\n\nimport { useFilters } from \"../../hooks\";\nimport { ExampleFilters } from \"../../components\";\n\nexport type FiltersProps = {\n /** Render method called once for all filters */\n render?: React.FC<ReturnType<typeof useFilters>>;\n};\n\nexport const Filters: React.FC<FiltersProps> = (props) => {\n const filterStackHook = useFilters();\n\n const RenderComponent = props.render ?? ExampleFilters;\n\n return <RenderComponent {...filterStackHook} />;\n};\n"]}
1
+ {"version":3,"file":"Filters.js","sourceRoot":"","sources":["../../../../src/components/Filter/Filters.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAKqB;AACrB,iDAA0C;AAqBnC,MAAM,OAAO,GAA2B,CAAC,KAAK,EAAE,EAAE;;IACvD,MAAM,eAAe,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,OAAO,CACL,8DACG,MAAA,eAAe,CAAC,OAAO,0CAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACxC,8BAAC,mBAAM,IACL,GAAG,EAAE,MAAM,CAAC,EAAE,EACd,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EACxC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAC5C,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,GAC1C,CACH,CAAC,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,OAAO,WAgBlB","sourcesContent":["import React from \"react\";\n\nimport {\n useFilterListProps,\n useFilterRangeProps,\n useFilters,\n useFilterSliderProps,\n} from \"../../hooks\";\nimport { Filter } from \"../../components\";\nimport { ConfigFilterOption } from \"../../types\";\n\nexport type FiltersProps = {\n /** Render method for List filters */\n renderFilterList?: React.FC<{\n filter: ConfigFilterOption;\n filterListProps: ReturnType<typeof useFilterListProps>;\n }>;\n /** Render method for Range filters */\n renderFilterRange?: React.FC<{\n filter: ConfigFilterOption;\n filterRangeProps: ReturnType<typeof useFilterRangeProps>;\n }>;\n /** Render method for Slider filters */\n renderFilterSlider?: React.FC<{\n filter: ConfigFilterOption;\n filterSliderProps: ReturnType<typeof useFilterSliderProps>;\n }>;\n};\n\nexport const Filters: React.FC<FiltersProps> = (props) => {\n const filterStackHook = useFilters();\n\n return (\n <>\n {filterStackHook.filters?.map((filter) => (\n <Filter\n key={filter.id}\n filter={filter}\n renderFilterList={props.renderFilterList}\n renderFilterSlider={props.renderFilterSlider}\n renderFilterRange={props.renderFilterRange}\n />\n ))}\n </>\n );\n};\n"]}
@@ -6,11 +6,16 @@ export declare type FiltersSelectedProps = {
6
6
  key: string;
7
7
  label: string;
8
8
  value: Array<string> | string | {
9
+ label: string;
9
10
  start: number;
10
11
  end: number;
11
- };
12
+ } | Array<{
13
+ label: string;
14
+ start: number;
15
+ end: number;
16
+ }>;
12
17
  }>;
13
- handleRemove: (filterKey: string) => void;
18
+ handleRemove: (filterKey: string, filterValues?: Array<string | number>) => void;
14
19
  }>;
15
20
  };
16
21
  export declare const FiltersSelected: React.FC<FiltersSelectedProps>;
@@ -7,8 +7,10 @@ exports.FiltersSelected = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const SelectedFilters_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/basic/SelectedFilters"));
9
9
  const components_1 = require("../../components");
10
+ const hooks_1 = require("../../hooks");
10
11
  const FiltersSelected = (props) => {
11
12
  var _a;
13
+ const filtersHook = (0, hooks_1.useFilters)();
12
14
  const RenderComponent = (_a = props.render) !== null && _a !== void 0 ? _a : components_1.ExampleFiltersSelected;
13
15
  return (react_1.default.createElement(SelectedFilters_1.default, { render: ({ selectedValues, setValue }) => {
14
16
  const selectedFilters = Object.entries(selectedValues)
@@ -23,8 +25,49 @@ const FiltersSelected = (props) => {
23
25
  label: item.label,
24
26
  value: item.value,
25
27
  }));
26
- const handleRemove = (selectedFilterKey) => {
27
- setValue(selectedFilterKey, null);
28
+ const handleRemove = (selectedFilterKey, selectedFilterValues = []) => {
29
+ var _a;
30
+ const filter = (_a = filtersHook.filters) === null || _a === void 0 ? void 0 : _a.find((filter) => filter.handle === selectedFilterKey);
31
+ if (!filter) {
32
+ return;
33
+ }
34
+ if (filter.displayType === "slider") {
35
+ const event = new CustomEvent(`@usereactify/search:filter:${filter.handle}:update`, {
36
+ detail: {
37
+ handle: filter.handle,
38
+ value: [],
39
+ },
40
+ });
41
+ window.dispatchEvent(event);
42
+ return;
43
+ }
44
+ if (selectedFilterValues.length === 0) {
45
+ setValue(selectedFilterKey, null);
46
+ return;
47
+ }
48
+ if (selectedFilterValues.length > 0) {
49
+ if (filter.displayType === "single") {
50
+ setValue(selectedFilterKey, null);
51
+ }
52
+ if (filter.displayType === "multi") {
53
+ if (filter.displayView === "range") {
54
+ const values = selectedValues[selectedFilterKey].value
55
+ .filter((value) => !selectedFilterValues.includes(value.label))
56
+ .map((value) => value.label);
57
+ const event = new CustomEvent(`@usereactify/search:filter:${filter.handle}:update`, {
58
+ detail: {
59
+ handle: filter.handle,
60
+ value: values,
61
+ },
62
+ });
63
+ window.dispatchEvent(event);
64
+ }
65
+ if (filter.displayView !== "range") {
66
+ const values = selectedValues[selectedFilterKey].value.filter((value) => !selectedFilterValues.includes(value));
67
+ setValue(selectedFilterKey, values);
68
+ }
69
+ }
70
+ }
28
71
  };
29
72
  if (!selectedFilters.length) {
30
73
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"FiltersSelected.js","sourceRoot":"","sources":["../../../../src/components/Filter/FiltersSelected.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,qHAA6F;AAE7F,iDAA0D;AAcnD,MAAM,eAAe,GAAmC,CAAC,KAAK,EAAE,EAAE;;IACvE,MAAM,eAAe,GAAG,MAAA,KAAK,CAAC,MAAM,mCAAI,mCAAsB,CAAC;IAE/D,OAAO,CACL,8BAAC,yBAAe,IACd,MAAM,EAAE,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,EAAE;YACvC,MAAM,eAAe,GACnB,MAAM,CAAC,OAAO,CAAC,cAAc,CAC9B;iBACE,MAAM,CACL,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;;gBACd,OAAA,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS;qBACf,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,CAAA;oBAChB,CAAC,CAAC,CAAC,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,MAAM,CAAA,IAAI,CAAC,CAAC,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,KAAK,CAAA,CAAC,CAAA;aAAA,CAClD;iBACA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;gBACrB,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC,CAAC,CAAC;YAEN,MAAM,YAAY,GAAG,CAAC,iBAAyB,EAAE,EAAE;gBACjD,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;YACpC,CAAC,CAAC;YAEF,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE;gBAC3B,OAAO,IAAI,CAAC;aACb;YAED,OAAO,CACL,8BAAC,eAAe,IACd,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,GAC1B,CACH,CAAC;QACJ,CAAC,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AAtCW,QAAA,eAAe,mBAsC1B","sourcesContent":["import React from \"react\";\nimport SelectedFilters from \"@appbaseio/reactivesearch/lib/components/basic/SelectedFilters\";\n\nimport { ExampleFiltersSelected } from \"../../components\";\n\nexport type FiltersSelectedProps = {\n /** Render method called once for all active filters */\n render?: React.FC<{\n selectedFilters: Array<{\n key: string;\n label: string;\n value: Array<string> | string | { start: number; end: number };\n }>;\n handleRemove: (filterKey: string) => void;\n }>;\n};\n\nexport const FiltersSelected: React.FC<FiltersSelectedProps> = (props) => {\n const RenderComponent = props.render ?? ExampleFiltersSelected;\n\n return (\n <SelectedFilters\n render={({ selectedValues, setValue }) => {\n const selectedFilters = (\n Object.entries(selectedValues) as Array<[string, any]>\n )\n .filter(\n ([key, item]) =>\n item?.URLParams &&\n item?.showFilter &&\n (!!item?.value?.length || !!item?.value?.label)\n )\n .map(([key, item]) => ({\n key: key,\n label: item.label,\n value: item.value,\n }));\n\n const handleRemove = (selectedFilterKey: string) => {\n setValue(selectedFilterKey, null);\n };\n\n if (!selectedFilters.length) {\n return null;\n }\n\n return (\n <RenderComponent\n selectedFilters={selectedFilters}\n handleRemove={handleRemove}\n />\n );\n }}\n />\n );\n};\n"]}
1
+ {"version":3,"file":"FiltersSelected.js","sourceRoot":"","sources":["../../../../src/components/Filter/FiltersSelected.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,qHAA6F;AAE7F,iDAA0D;AAC1D,uCAAyC;AAqBlC,MAAM,eAAe,GAAmC,CAAC,KAAK,EAAE,EAAE;;IACvE,MAAM,WAAW,GAAG,IAAA,kBAAU,GAAE,CAAC;IAEjC,MAAM,eAAe,GAAG,MAAA,KAAK,CAAC,MAAM,mCAAI,mCAAsB,CAAC;IAE/D,OAAO,CACL,8BAAC,yBAAe,IACd,MAAM,EAAE,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,EAAE;YACvC,MAAM,eAAe,GACnB,MAAM,CAAC,OAAO,CAAC,cAAc,CAC9B;iBACE,MAAM,CACL,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;;gBACd,OAAA,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS;qBACf,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,CAAA;oBAChB,CAAC,CAAC,CAAC,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,MAAM,CAAA,IAAI,CAAC,CAAC,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,KAAK,CAAA,CAAC,CAAA;aAAA,CAClD;iBACA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;gBACrB,GAAG,EAAE,GA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ACA,GAAG,CAAC,CAAC,KAAwB,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;4BAElD,MAAM,KAAK,GAAG,IAAI,WAAW,CAG1B,8BAA8B,MAAM,CAAC,MAAM,SAAS,EAAE;gCACvD,MAAM,EAAE;oCACN,MAAM,EAAE,MAAM,CAAC,MAAM;oCACrB,KAAK,EAAE,MAAM;iCACd;6BACF,CAAC,CAAC;4BACH,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;yBAC7B;wBACD,IAAI,MAAM,CAAC,WAAW,KAAK,OAAO,EAAE;4BAClC,MAAM,MAAM,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,MAAM,CAC3D,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzD,CAAC;4BACF,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;yBACrC;qBACF;iBACF;YACH,CAAC,CAAC;YAEF,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE;gBAC3B,OAAO,IAAI,CAAC;aACb;YAED,OAAO,CACL,8BAAC,eAAe,IACd,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,GAC1B,CACH,CAAC;QACJ,CAAC,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AAtGW,QAAA,eAAe,mBAsG1B","sourcesContent":["import React from \"react\";\nimport SelectedFilters from \"@appbaseio/reactivesearch/lib/components/basic/SelectedFilters\";\n\nimport { ExampleFiltersSelected } from \"../../components\";\nimport { useFilters } from \"../../hooks\";\n\nexport type FiltersSelectedProps = {\n /** Render method called once for all active filters */\n render?: React.FC<{\n selectedFilters: Array<{\n key: string;\n label: string;\n value:\n | Array<string>\n | string\n | { label: string; start: number; end: number }\n | Array<{ label: string; start: number; end: number }>;\n }>;\n handleRemove: (\n filterKey: string,\n filterValues?: Array<string | number>\n ) => void;\n }>;\n};\n\nexport const FiltersSelected: React.FC<FiltersSelectedProps> = (props) => {\n const filtersHook = useFilters();\n\n const RenderComponent = props.render ?? ExampleFiltersSelected;\n\n return (\n <SelectedFilters\n render={({ selectedValues, setValue }) => {\n const selectedFilters = (\n Object.entries(selectedValues) as Array<[string, any]>\n )\n .filter(\n ([key, item]) =>\n item?.URLParams &&\n item?.showFilter &&\n (!!item?.value?.length || !!item?.value?.label)\n )\n .map(([key, item]) => ({\n key: key,\n label: item.label,\n value: item.value,\n }));\n\n const handleRemove = (\n selectedFilterKey: string,\n selectedFilterValues: Array<string | number> = []\n ) => {\n const filter = filtersHook.filters?.find(\n (filter) => filter.handle === selectedFilterKey\n );\n if (!filter) {\n return;\n }\n\n if (filter.displayType === \"slider\") {\n const event = new CustomEvent<{\n handle: string;\n value: [];\n }>(`@usereactify/search:filter:${filter.handle}:update`, {\n detail: {\n handle: filter.handle,\n value: [],\n },\n });\n window.dispatchEvent(event);\n\n return;\n }\n\n if (selectedFilterValues.length === 0) {\n setValue(selectedFilterKey, null);\n\n return;\n }\n\n if (selectedFilterValues.length > 0) {\n if (filter.displayType === \"single\") {\n setValue(selectedFilterKey, null);\n }\n if (filter.displayType === \"multi\") {\n if (filter.displayView === \"range\") {\n const values = selectedValues[selectedFilterKey].value\n .filter(\n (value: { label: string }) =>\n !selectedFilterValues.includes(value.label)\n )\n .map((value: { label: string }) => value.label);\n\n const event = new CustomEvent<{\n handle: string;\n value: Array<string>;\n }>(`@usereactify/search:filter:${filter.handle}:update`, {\n detail: {\n handle: filter.handle,\n value: values,\n },\n });\n window.dispatchEvent(event);\n }\n if (filter.displayView !== \"range\") {\n const values = selectedValues[selectedFilterKey].value.filter(\n (value: string) => !selectedFilterValues.includes(value)\n );\n setValue(selectedFilterKey, values);\n }\n }\n }\n };\n\n if (!selectedFilters.length) {\n return null;\n }\n\n return (\n <RenderComponent\n selectedFilters={selectedFilters}\n handleRemove={handleRemove}\n />\n );\n }}\n />\n );\n};\n"]}
@@ -10,10 +10,10 @@ export declare type ReactifySearchProviderProps = {
10
10
  onRedirect?: (type: "redirect" | "search", url: string) => void;
11
11
  /** Render method to display a component when the config is loading */
12
12
  renderBooting?: () => JSX.Element | null;
13
+ /** Advanced usage: Override the default Reactify Search id (for telemetry) */
14
+ clientId?: string;
13
15
  /** Advanced usage: Override the default Filters selection logic */
14
16
  filtersHandle?: string;
15
- /** Advanced usage: Allows you to wrap the ReactifySearchProvider in your own ReactiveBase component */
16
- noReactiveBase?: boolean;
17
17
  /** Advanced usage: Array of additional component IDs managed outside of Reactify Search */
18
18
  additionalComponentIds?: string[];
19
19
  /** Advanced usage: Override the default Elasticsearch index */
@@ -21,11 +21,9 @@ export declare type ReactifySearchProviderProps = {
21
21
  /** Advanced usage: Override the default Reactify Search config (for multi-instance stores) */
22
22
  configId?: string;
23
23
  /** Advanced usage: Override the default Elasticsearch credentials */
24
- credentials?: {
25
- username: string;
26
- password: string;
27
- endpoint: string;
28
- };
24
+ credentials?: string;
25
+ /** Advanced usage: Override the default Elasticsearch endpoint */
26
+ endpoint?: string;
29
27
  /** Advanced usage: Override the default ReactiveBase theme */
30
28
  theme?: Record<string, unknown>;
31
29
  /** Advanced usage: Fields to include in the Elasticsearch response e.g. ["title"] */
@@ -25,6 +25,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.ReactifySearchProvider = void 0;
26
26
  const react_1 = __importDefault(require("react"));
27
27
  const Sentry = __importStar(require("@sentry/react"));
28
+ // @ts-expect-error missing types
29
+ const GaGtag = __importStar(require("ga-gtag"));
30
+ const package_json_1 = __importDefault(require("../../../package.json"));
28
31
  const hooks_1 = require("../../hooks");
29
32
  const components_1 = require("../../components");
30
33
  const utility_1 = require("../../utility");
@@ -38,23 +41,22 @@ const ReactifySearchProvider = (props) => {
38
41
  "reactifysearch.collection": props.mode === "collection" ? props.collectionHandle : undefined,
39
42
  "reactifysearch.filter": props.filtersHandle,
40
43
  });
44
+ GaGtag.install("G-DV00Z0X5VP", {
45
+ cookie_prefix: "_rs",
46
+ user_properties: {
47
+ shop: props.shopifyPermanentDomain,
48
+ version: package_json_1.default.version,
49
+ },
50
+ });
41
51
  }, [props]);
42
52
  return (react_1.default.createElement(Sentry.ErrorBoundary, { fallback: react_1.default.createElement("p", null, "An error has occurred") },
43
53
  react_1.default.createElement(ReactifySearchInner, Object.assign({}, props))));
44
54
  };
45
55
  exports.ReactifySearchProvider = ReactifySearchProvider;
46
56
  const ReactifySearchInner = (props) => {
47
- var _a, _b;
57
+ var _a;
48
58
  const { config } = (0, hooks_1.useConfig)(props.shopifyPermanentDomain, props.configId);
49
- const [searchTerm, setSearchTerm] = react_1.default.useState("");
50
- const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
51
- const [sortOption, setSortOption] = react_1.default.useState("");
52
- const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : {
53
- username: "guest",
54
- password: "password",
55
- endpoint: "https://api.search.reactify.app",
56
- };
57
- const theme = (_b = props.theme) !== null && _b !== void 0 ? _b : {
59
+ const theme = (_a = props.theme) !== null && _a !== void 0 ? _a : {
58
60
  typography: {
59
61
  fontFamily: "inherit",
60
62
  fontSize: "inherit",
@@ -76,6 +78,19 @@ const ReactifySearchInner = (props) => {
76
78
  const urlParams = new URLSearchParams(window.location.search);
77
79
  return (_a = urlParams.get("sort")) !== null && _a !== void 0 ? _a : undefined;
78
80
  }, [typeof window !== "undefined" && window.location.search]);
81
+ const indexFromURL = react_1.default.useMemo(() => {
82
+ var _a;
83
+ if (typeof window === "undefined") {
84
+ return;
85
+ }
86
+ const urlParams = new URLSearchParams(window.location.search);
87
+ return (_a = urlParams.get("index")) !== null && _a !== void 0 ? _a : undefined;
88
+ }, [typeof window !== "undefined" && window.location.search]);
89
+ const [searchTerm, setSearchTerm] = react_1.default.useState(searchTermFromURL !== null && searchTermFromURL !== void 0 ? searchTermFromURL : "");
90
+ const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
91
+ const [sortOption, setSortOption] = react_1.default.useState(searchSortFromURL !== null && searchSortFromURL !== void 0 ? searchSortFromURL : "");
92
+ const [results, setResults] = react_1.default.useState([]);
93
+ const [resultStats, setResultStats] = react_1.default.useState();
79
94
  react_1.default.useEffect(() => {
80
95
  if (searchTermFromURL && searchTerm !== searchTermFromURL) {
81
96
  setSearchTerm(searchTermFromURL);
@@ -86,22 +101,14 @@ const ReactifySearchInner = (props) => {
86
101
  setSortOption(searchSortFromURL);
87
102
  }
88
103
  }, [searchSortFromURL]);
89
- react_1.default.useEffect(() => {
90
- if (typeof window == "undefined") {
91
- return;
92
- }
93
- if (window.location.search === "" && sortOption) {
94
- setSortOption(sortOption);
95
- }
96
- }, [typeof window !== "undefined" && window.location.search]);
97
104
  const contextValue = react_1.default.useMemo(() => {
98
- var _a;
105
+ var _a, _b, _c, _d;
99
106
  if (!config) {
100
107
  return;
101
108
  }
102
109
  return {
103
110
  config: config,
104
- options: Object.assign(Object.assign({}, props), { index: (_a = props.index) !== null && _a !== void 0 ? _a : config.index, filtersHandle: props.filtersHandle, credentials: credentials, theme: theme }),
111
+ options: Object.assign(Object.assign({}, props), { clientId: (_a = props.clientId) !== null && _a !== void 0 ? _a : "theme", index: (_c = (_b = props.index) !== null && _b !== void 0 ? _b : indexFromURL) !== null && _c !== void 0 ? _c : config.index, filtersHandle: props.filtersHandle, credentials: props.credentials, endpoint: (_d = props.endpoint) !== null && _d !== void 0 ? _d : "https://api.search.reactify.app", theme: theme }),
105
112
  search: {
106
113
  searchTerm: searchTerm,
107
114
  setSearchTerm: setSearchTerm,
@@ -112,8 +119,22 @@ const ReactifySearchInner = (props) => {
112
119
  sortOption: sortOption,
113
120
  setSortOption: setSortOption,
114
121
  },
122
+ results: {
123
+ results: results,
124
+ setResults: setResults,
125
+ resultStats: resultStats,
126
+ setResultStats: setResultStats,
127
+ },
115
128
  };
116
- }, [config, props, searchTerm, showInstantSearchResults, sortOption]);
129
+ }, [
130
+ config,
131
+ props,
132
+ searchTerm,
133
+ showInstantSearchResults,
134
+ sortOption,
135
+ results,
136
+ resultStats,
137
+ ]);
117
138
  utility_1.debug.hook("ReactifySearchProvider", "context", contextValue);
118
139
  if (!contextValue) {
119
140
  if (props.renderBooting) {
@@ -121,9 +142,6 @@ const ReactifySearchInner = (props) => {
121
142
  }
122
143
  return null;
123
144
  }
124
- if (props.noReactiveBase) {
125
- return (react_1.default.createElement(hooks_1.ReactifySearchContext.Provider, { value: contextValue }, props.children));
126
- }
127
145
  return (react_1.default.createElement(hooks_1.ReactifySearchContext.Provider, { value: contextValue },
128
146
  react_1.default.createElement(components_1.UtilityAuthenticatedReactiveBase, null, props.children)));
129
147
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ReactifySearchProvider.js","sourceRoot":"","sources":["../../../../src/components/ReactifySearchProvider/ReactifySearchProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,sDAAwC;AAExC,uCAA+D;AAC/D,iDAAoE;AACpE,2CAAsC;AAiD/B,MAAM,sBAAsB,GAA0C,CAC3E,KAAK,EACL,EAAE;IACF,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,wBAAwB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAEpD,MAAM,CAAC,OAAO,CAAC;YACb,sBAAsB,EAAE,KAAK,CAAC,KAAK;YACnC,qBAAqB,EAAE,KAAK,CAAC,sBAAsB;YACnD,qBAAqB,EAAE,KAAK,CAAC,IAAI;YACjC,2BAA2B,EACzB,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;YAClE,uBAAuB,EAAE,KAAK,CAAC,aAAa;SAC7C,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,CACL,8BAAC,MAAM,CAAC,aAAa,IAAC,QAAQ,EAAE,iEAA4B;QAC1D,8BAAC,mBAA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KACR,KAAK,EAAE,MAAA,KAAK,CAAC,KAAK,mCAAI,MAAM,CAAC,KAAK,EAClC,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,GACb;YACD,MAAM,EAAE;gBACN,UAAU,EAAE,UAAU;gBACtB,aAAa,EAAE,aAAa;gBAC5B,wBAAwB,EAAE,wBAAwB;gBAClD,2BAA2B,EAAE,2BAA2B;aACzD;YACD,MAAM,EAAE;gBACN,UAAU,EAAE,UAAU;gBACtB,aAAa,EAAE,aAAa;aAC7B;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,wBAAwB,EAAE,UAAU,CAAC,CAAC,CAAC;IAEtE,eAAK,CAAC,IAAI,CAAC,wBAAwB,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IAE9D,IAAI,CAAC,YAAY,EAAE;QACjB,IAAI,KAAK,CAAC,aAAa,EAAE;YACvB,OAAO,KAAK,CAAC,aAAa,EAAE,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC;KACb;IAED,IAAI,KAAK,CAAC,cAAc,EAAE;QACxB,OAAO,CACL,8BAAC,6BAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAChD,KAAK,CAAC,QAAQ,CACgB,CAClC,CAAC;KACH;IAED,OAAO,CACL,8BAAC,6BAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY;QACjD,8BAAC,6CAAgC,QAC9B,KAAK,CAAC,QAAQ,CACkB,CACJ,CAClC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport * as Sentry from \"@sentry/react\";\n\nimport { ReactifySearchContext, useConfig } from \"../../hooks\";\nimport { UtilityAuthenticatedReactiveBase } from \"../../components\";\nimport { debug } from \"../../utility\";\n\nexport type ReactifySearchProviderProps = {\n /** Standard react children */\n children?: React.ReactNode | undefined;\n /** The search area the provider will be used in */\n mode: \"search\" | \"collection\" | \"instant-search\";\n /** Shopify store domain used to resolve the site configuration */\n shopifyPermanentDomain: string;\n /** Callback function for redirects, suitable for headless sites to avoid full page refresh */\n onRedirect?: (type: \"redirect\" | \"search\", url: string) => void;\n /** Render method to display a component when the config is loading */\n renderBooting?: () => JSX.Element | null;\n /** Advanced usage: Override the default Filters selection logic */\n filtersHandle?: string;\n /** Advanced usage: Allows you to wrap the ReactifySearchProvider in your own ReactiveBase component */\n noReactiveBase?: boolean;\n /** Advanced usage: Array of additional component IDs managed outside of Reactify Search */\n additionalComponentIds?: string[];\n /** Advanced usage: Override the default Elasticsearch index */\n index?: string;\n /** Advanced usage: Override the default Reactify Search config (for multi-instance stores) */\n configId?: string;\n /** Advanced usage: Override the default Elasticsearch credentials */\n credentials?: {\n username: string;\n password: string;\n endpoint: string;\n };\n /** Advanced usage: Override the default ReactiveBase theme */\n theme?: Record<string, unknown>;\n /** Advanced usage: Fields to include in the Elasticsearch response e.g. [\"title\"] */\n includeFields?: string[];\n /** Advanced usage: Fields to exclude from the Elasticsearch response e.g. [\"variant_skus\", \"*price*\"] */\n excludeFields?: string[];\n} & (\n | {\n mode: \"search\";\n }\n | {\n mode: \"collection\";\n /** Collection object that includes the handle, used to find curations */\n collectionHandle: string;\n }\n | {\n mode: \"instant-search\";\n }\n);\n\nexport const ReactifySearchProvider: React.FC<ReactifySearchProviderProps> = (\n props\n) => {\n React.useEffect(() => {\n debug.log(\"ReactifySearchProvider\", \"props\", props);\n\n Sentry.setTags({\n \"reactifysearch.index\": props.index,\n \"reactifysearch.shop\": props.shopifyPermanentDomain,\n \"reactifysearch.mode\": props.mode,\n \"reactifysearch.collection\":\n props.mode === \"collection\" ? props.collectionHandle : undefined,\n \"reactifysearch.filter\": props.filtersHandle,\n });\n }, [props]);\n\n return (\n <Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>\n <ReactifySearchInner {...props} />\n </Sentry.ErrorBoundary>\n );\n};\n\nconst ReactifySearchInner: React.FC<ReactifySearchProviderProps> = (props) => {\n const { config } = useConfig(props.shopifyPermanentDomain, props.configId);\n\n const [searchTerm, setSearchTerm] = React.useState<string>(\"\");\n const [showInstantSearchResults, setShowInstantSearchResults] =\n React.useState<boolean>(false);\n const [sortOption, setSortOption] = React.useState<string>(\"\");\n\n const credentials = props.credentials ?? {\n username: \"guest\",\n password: \"password\",\n endpoint: \"https://api.search.reactify.app\",\n };\n\n const theme = props.theme ?? {\n typography: {\n fontFamily: \"inherit\",\n fontSize: \"inherit\",\n },\n };\n\n const searchTermFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"q\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const searchSortFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"sort\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n React.useEffect(() => {\n if (searchTermFromURL && searchTerm !== searchTermFromURL) {\n setSearchTerm(searchTermFromURL);\n }\n }, [searchTermFromURL]);\n\n React.useEffect(() => {\n if (searchSortFromURL && sortOption !== searchSortFromURL) {\n setSortOption(searchSortFromURL);\n }\n }, [searchSortFromURL]);\n\n React.useEffect(() => {\n if (typeof window == \"undefined\") {\n return;\n }\n\n if (window.location.search === \"\" && sortOption) {\n setSortOption(sortOption);\n }\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const contextValue = React.useMemo(() => {\n if (!config) {\n return;\n }\n\n return {\n config: config,\n options: {\n ...props,\n index: props.index ?? config.index,\n filtersHandle: props.filtersHandle,\n credentials: credentials,\n theme: theme,\n },\n search: {\n searchTerm: searchTerm,\n setSearchTerm: setSearchTerm,\n showInstantSearchResults: showInstantSearchResults,\n setShowInstantSearchResults: setShowInstantSearchResults,\n },\n sortby: {\n sortOption: sortOption,\n setSortOption: setSortOption,\n },\n };\n }, [config, props, searchTerm, showInstantSearchResults, sortOption]);\n\n debug.hook(\"ReactifySearchProvider\", \"context\", contextValue);\n\n if (!contextValue) {\n if (props.renderBooting) {\n return props.renderBooting();\n }\n return null;\n }\n\n if (props.noReactiveBase) {\n return (\n <ReactifySearchContext.Provider value={contextValue}>\n {props.children}\n </ReactifySearchContext.Provider>\n );\n }\n\n return (\n <ReactifySearchContext.Provider value={contextValue}>\n <UtilityAuthenticatedReactiveBase>\n {props.children}\n </UtilityAuthenticatedReactiveBase>\n </ReactifySearchContext.Provider>\n );\n};\n"]}
1
+ {"version":3,"file":"ReactifySearchProvider.js","sourceRoot":"","sources":["../../../../src/components/ReactifySearchProvider/ReactifySearchProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,sDAAwC;AACxC,iCAAiC;AACjC,gDAAkC;AAElC,yEAAwC;AAExC,uCAA+D;AAC/D,iDAAoE;AACpE,2CAAsC;AAgD/B,MAAM,sBAAsB,GAA0C,CAC3E,KAAK,EACL,EAAE;IACF,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,wBAAwB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAEpD,MAAM,CAAC,OAAO,CAAC;YACb,sBAAsB,EAAE,KAAK,CAAC,KAAK;YACnC,qBAAqB,EAAE,KAAK,CAAC,sBAAsB;YACnD,qBAAqB,EAAE,KAAK,CAAC,IAAI;YACjC,2BAA2B,EACzB,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;YAClE,uBAAuB,EAAE,KAAK,CAAC,aAAa;SAC7C,CAAC,CAAC;QAEH,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE;YAC7B,aAAa,EAAE,KAAK;YACpB,eAAe,EAAE;gBACf,IAAI,EAAE,KAAK,CAAC,sBAAsB;gBAClC,OAAO,EAAE,sBAAG,CAAC,OAAO;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,aAAa,EAAE;YACvB,OAAO,KAAK,CAAC,aAAa,EAAE,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,8BAAC,6BAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY;QACjD,8BAAC,6CAAgC,QAC9B,KAAK,CAAC,QAAQ,CACkB,CACJ,CAClC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport * as Sentry from \"@sentry/react\";\n// @ts-expect-error missing types\nimport * as GaGtag from \"ga-gtag\";\n\nimport pkg from \"../../../package.json\";\n\nimport { ReactifySearchContext, useConfig } from \"../../hooks\";\nimport { UtilityAuthenticatedReactiveBase } from \"../../components\";\nimport { debug } from \"../../utility\";\nimport { ReactivesearchResultProps } from \"../../types\";\n\nexport type ReactifySearchProviderProps = {\n /** Standard react children */\n children?: React.ReactNode | undefined;\n /** The search area the provider will be used in */\n mode: \"search\" | \"collection\" | \"instant-search\";\n /** Shopify store domain used to resolve the site configuration */\n shopifyPermanentDomain: string;\n /** Callback function for redirects, suitable for headless sites to avoid full page refresh */\n onRedirect?: (type: \"redirect\" | \"search\", url: string) => void;\n /** Render method to display a component when the config is loading */\n renderBooting?: () => JSX.Element | null;\n /** Advanced usage: Override the default Reactify Search id (for telemetry) */\n clientId?: string;\n /** Advanced usage: Override the default Filters selection logic */\n filtersHandle?: string;\n /** Advanced usage: Array of additional component IDs managed outside of Reactify Search */\n additionalComponentIds?: string[];\n /** Advanced usage: Override the default Elasticsearch index */\n index?: string;\n /** Advanced usage: Override the default Reactify Search config (for multi-instance stores) */\n configId?: string;\n /** Advanced usage: Override the default Elasticsearch credentials */\n credentials?: string;\n /** Advanced usage: Override the default Elasticsearch endpoint */\n endpoint?: string;\n /** Advanced usage: Override the default ReactiveBase theme */\n theme?: Record<string, unknown>;\n /** Advanced usage: Fields to include in the Elasticsearch response e.g. [\"title\"] */\n includeFields?: string[];\n /** Advanced usage: Fields to exclude from the Elasticsearch response e.g. [\"variant_skus\", \"*price*\"] */\n excludeFields?: string[];\n} & (\n | {\n mode: \"search\";\n }\n | {\n mode: \"collection\";\n /** Collection object that includes the handle, used to find curations */\n collectionHandle: string;\n }\n | {\n mode: \"instant-search\";\n }\n);\n\nexport const ReactifySearchProvider: React.FC<ReactifySearchProviderProps> = (\n props\n) => {\n React.useEffect(() => {\n debug.log(\"ReactifySearchProvider\", \"props\", props);\n\n Sentry.setTags({\n \"reactifysearch.index\": props.index,\n \"reactifysearch.shop\": props.shopifyPermanentDomain,\n \"reactifysearch.mode\": props.mode,\n \"reactifysearch.collection\":\n props.mode === \"collection\" ? props.collectionHandle : undefined,\n \"reactifysearch.filter\": props.filtersHandle,\n });\n\n GaGtag.install(\"G-DV00Z0X5VP\", {\n cookie_prefix: \"_rs\",\n user_properties: {\n shop: props.shopifyPermanentDomain,\n version: pkg.version,\n },\n });\n }, [props]);\n\n return (\n <Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>\n <ReactifySearchInner {...props} />\n </Sentry.ErrorBoundary>\n );\n};\n\nconst ReactifySearchInner: React.FC<ReactifySearchProviderProps> = (props) => {\n const { config } = useConfig(props.shopifyPermanentDomain, props.configId);\n\n const theme = props.theme ?? {\n typography: {\n fontFamily: \"inherit\",\n fontSize: \"inherit\",\n },\n };\n\n const searchTermFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"q\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const searchSortFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"sort\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const indexFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"index\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const [searchTerm, setSearchTerm] = React.useState<string>(\n searchTermFromURL ?? \"\"\n );\n const [showInstantSearchResults, setShowInstantSearchResults] =\n React.useState<boolean>(false);\n const [sortOption, setSortOption] = React.useState<string>(\n searchSortFromURL ?? \"\"\n );\n\n const [results, setResults] = React.useState<\n ReactivesearchResultProps[\"data\"]\n >([]);\n const [resultStats, setResultStats] =\n React.useState<ReactivesearchResultProps[\"resultStats\"]>();\n\n React.useEffect(() => {\n if (searchTermFromURL && searchTerm !== searchTermFromURL) {\n setSearchTerm(searchTermFromURL);\n }\n }, [searchTermFromURL]);\n\n React.useEffect(() => {\n if (searchSortFromURL && sortOption !== searchSortFromURL) {\n setSortOption(searchSortFromURL);\n }\n }, [searchSortFromURL]);\n\n const contextValue = React.useMemo(() => {\n if (!config) {\n return;\n }\n\n return {\n config: config,\n options: {\n ...props,\n clientId: props.clientId ?? \"theme\",\n index: props.index ?? indexFromURL ?? config.index,\n filtersHandle: props.filtersHandle,\n credentials: props.credentials,\n endpoint: props.endpoint ?? \"https://api.search.reactify.app\",\n theme: theme,\n },\n search: {\n searchTerm: searchTerm,\n setSearchTerm: setSearchTerm,\n showInstantSearchResults: showInstantSearchResults,\n setShowInstantSearchResults: setShowInstantSearchResults,\n },\n sortby: {\n sortOption: sortOption,\n setSortOption: setSortOption,\n },\n results: {\n results: results,\n setResults: setResults,\n resultStats: resultStats,\n setResultStats: setResultStats,\n },\n };\n }, [\n config,\n props,\n searchTerm,\n showInstantSearchResults,\n sortOption,\n results,\n resultStats,\n ]);\n\n debug.hook(\"ReactifySearchProvider\", \"context\", contextValue);\n\n if (!contextValue) {\n if (props.renderBooting) {\n return props.renderBooting();\n }\n return null;\n }\n\n return (\n <ReactifySearchContext.Provider value={contextValue}>\n <UtilityAuthenticatedReactiveBase>\n {props.children}\n </UtilityAuthenticatedReactiveBase>\n </ReactifySearchContext.Provider>\n );\n};\n"]}