react-instantsearch-core 6.40.3 → 7.0.0

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 (263) hide show
  1. package/README.md +70 -2
  2. package/dist/cjs/components/Configure.js +13 -0
  3. package/dist/cjs/components/DynamicWidgets.js +63 -0
  4. package/dist/cjs/components/Index.js +24 -0
  5. package/dist/cjs/components/InstantSearch.js +27 -0
  6. package/dist/cjs/{connectors/connectConfigure.js → components/InstantSearchSSRProvider.js} +27 -63
  7. package/dist/cjs/components/InstantSearchServerContext.js +12 -0
  8. package/dist/cjs/connectors/useBreadcrumb.js +12 -0
  9. package/dist/cjs/connectors/useClearRefinements.js +12 -0
  10. package/dist/cjs/connectors/useConfigure.js +14 -0
  11. package/dist/cjs/connectors/useCurrentRefinements.js +12 -0
  12. package/dist/cjs/connectors/useDynamicWidgets.js +22 -0
  13. package/dist/cjs/connectors/useGeoSearch.js +12 -0
  14. package/dist/cjs/connectors/useHierarchicalMenu.js +12 -0
  15. package/dist/cjs/connectors/useHits.js +12 -0
  16. package/dist/cjs/connectors/useHitsPerPage.js +12 -0
  17. package/dist/cjs/connectors/useInfiniteHits.js +12 -0
  18. package/dist/cjs/connectors/useMenu.js +12 -0
  19. package/dist/cjs/connectors/useNumericMenu.js +12 -0
  20. package/dist/cjs/connectors/usePagination.js +12 -0
  21. package/dist/cjs/connectors/usePoweredBy.js +21 -0
  22. package/dist/cjs/connectors/useQueryRules.js +12 -0
  23. package/dist/cjs/connectors/useRange.js +12 -0
  24. package/dist/cjs/connectors/useRefinementList.js +12 -0
  25. package/dist/cjs/connectors/useSearchBox.js +12 -0
  26. package/dist/cjs/connectors/useSortBy.js +12 -0
  27. package/dist/cjs/connectors/useStats.js +12 -0
  28. package/dist/cjs/connectors/useToggleRefinement.js +12 -0
  29. package/dist/cjs/hooks/useConnector.js +136 -0
  30. package/dist/cjs/hooks/useInstantSearch.js +58 -0
  31. package/dist/cjs/index.js +328 -320
  32. package/dist/cjs/lib/IndexContext.js +12 -0
  33. package/dist/cjs/lib/InstantSearchContext.js +12 -0
  34. package/dist/cjs/lib/InstantSearchSSRContext.js +12 -0
  35. package/dist/cjs/lib/createSearchResults.js +27 -0
  36. package/dist/cjs/lib/dequal.js +53 -0
  37. package/dist/cjs/lib/getIndexSearchResults.js +32 -0
  38. package/dist/cjs/lib/invariant.js +25 -0
  39. package/dist/cjs/lib/noop.js +8 -0
  40. package/dist/cjs/lib/useForceUpdate.js +25 -0
  41. package/dist/cjs/lib/useIndex.js +38 -0
  42. package/dist/cjs/lib/useIndexContext.js +14 -0
  43. package/dist/cjs/lib/useInstantSearchApi.js +191 -0
  44. package/dist/cjs/lib/useInstantSearchContext.js +14 -0
  45. package/dist/cjs/lib/useInstantSearchSSRContext.js +11 -0
  46. package/dist/cjs/lib/useInstantSearchServerContext.js +11 -0
  47. package/dist/cjs/lib/useIsomorphicLayoutEffect.js +14 -0
  48. package/dist/cjs/lib/useSearchResults.js +46 -0
  49. package/dist/cjs/lib/useSearchState.js +48 -0
  50. package/dist/cjs/lib/useStableValue.js +26 -0
  51. package/dist/cjs/lib/useWidget.js +78 -0
  52. package/dist/cjs/lib/warn.js +41 -0
  53. package/dist/cjs/package.json +1 -0
  54. package/dist/cjs/server/getServerState.js +93 -0
  55. package/dist/cjs/{types → server}/index.js +4 -4
  56. package/dist/cjs/{core/version.js → version.js} +1 -1
  57. package/dist/es/components/Configure.d.ts +3 -0
  58. package/dist/es/components/Configure.js +7 -0
  59. package/dist/es/components/DynamicWidgets.d.ts +13 -0
  60. package/dist/es/components/DynamicWidgets.js +55 -0
  61. package/dist/es/components/Index.d.ts +6 -0
  62. package/dist/es/components/Index.js +17 -0
  63. package/dist/es/components/InstantSearch.d.ts +7 -0
  64. package/dist/es/components/InstantSearch.js +20 -0
  65. package/dist/es/components/InstantSearchSSRProvider.d.ts +13 -0
  66. package/dist/es/{connectors/connectConfigure.js → components/InstantSearchSSRProvider.js} +26 -61
  67. package/dist/es/components/InstantSearchServerContext.d.ts +12 -0
  68. package/dist/es/components/InstantSearchServerContext.js +5 -0
  69. package/dist/es/connectors/useBreadcrumb.d.ts +4 -0
  70. package/dist/es/connectors/useBreadcrumb.js +5 -0
  71. package/dist/es/connectors/useClearRefinements.d.ts +4 -0
  72. package/dist/es/connectors/useClearRefinements.js +5 -0
  73. package/dist/es/connectors/useConfigure.d.ts +4 -0
  74. package/dist/es/connectors/useConfigure.js +7 -0
  75. package/dist/es/connectors/useCurrentRefinements.d.ts +4 -0
  76. package/dist/es/connectors/useCurrentRefinements.js +5 -0
  77. package/dist/es/connectors/useDynamicWidgets.d.ts +4 -0
  78. package/dist/es/connectors/useDynamicWidgets.js +15 -0
  79. package/dist/es/connectors/useGeoSearch.d.ts +6 -0
  80. package/dist/es/connectors/useGeoSearch.js +5 -0
  81. package/dist/es/connectors/useHierarchicalMenu.d.ts +4 -0
  82. package/dist/es/connectors/useHierarchicalMenu.js +5 -0
  83. package/dist/es/connectors/useHits.d.ts +5 -0
  84. package/dist/es/connectors/useHits.js +5 -0
  85. package/dist/es/connectors/useHitsPerPage.d.ts +4 -0
  86. package/dist/es/connectors/useHitsPerPage.js +5 -0
  87. package/dist/es/connectors/useInfiniteHits.d.ts +5 -0
  88. package/dist/es/connectors/useInfiniteHits.js +5 -0
  89. package/dist/es/connectors/useMenu.d.ts +4 -0
  90. package/dist/es/connectors/useMenu.js +5 -0
  91. package/dist/es/connectors/useNumericMenu.d.ts +4 -0
  92. package/dist/es/connectors/useNumericMenu.js +5 -0
  93. package/dist/es/connectors/usePagination.d.ts +4 -0
  94. package/dist/es/connectors/usePagination.js +5 -0
  95. package/dist/es/connectors/usePoweredBy.d.ts +2 -0
  96. package/dist/es/connectors/usePoweredBy.js +15 -0
  97. package/dist/es/connectors/useQueryRules.d.ts +4 -0
  98. package/dist/es/connectors/useQueryRules.js +5 -0
  99. package/dist/es/connectors/useRange.d.ts +4 -0
  100. package/dist/es/connectors/useRange.js +5 -0
  101. package/dist/es/connectors/useRefinementList.d.ts +4 -0
  102. package/dist/es/connectors/useRefinementList.js +5 -0
  103. package/dist/es/connectors/useSearchBox.d.ts +4 -0
  104. package/dist/es/connectors/useSearchBox.js +5 -0
  105. package/dist/es/connectors/useSortBy.d.ts +4 -0
  106. package/dist/es/connectors/useSortBy.js +5 -0
  107. package/dist/es/connectors/useStats.d.ts +4 -0
  108. package/dist/es/connectors/useStats.js +5 -0
  109. package/dist/es/connectors/useToggleRefinement.d.ts +4 -0
  110. package/dist/es/connectors/useToggleRefinement.js +5 -0
  111. package/dist/es/hooks/useConnector.d.ts +3 -0
  112. package/dist/es/hooks/useConnector.js +130 -0
  113. package/dist/es/hooks/useInstantSearch.d.ts +32 -0
  114. package/dist/es/hooks/useInstantSearch.js +52 -0
  115. package/dist/es/index.d.ts +31 -0
  116. package/dist/es/index.js +31 -86
  117. package/dist/es/lib/IndexContext.d.ts +3 -0
  118. package/dist/es/lib/IndexContext.js +5 -0
  119. package/dist/es/lib/InstantSearchContext.d.ts +3 -0
  120. package/dist/es/lib/InstantSearchContext.js +5 -0
  121. package/dist/es/lib/InstantSearchSSRContext.d.ts +8 -0
  122. package/dist/es/lib/InstantSearchSSRContext.js +5 -0
  123. package/dist/es/lib/createSearchResults.d.ts +3 -0
  124. package/dist/es/lib/createSearchResults.js +20 -0
  125. package/dist/es/lib/dequal.d.ts +1 -0
  126. package/dist/es/lib/dequal.js +47 -0
  127. package/dist/es/lib/getIndexSearchResults.d.ts +9 -0
  128. package/dist/es/lib/getIndexSearchResults.js +26 -0
  129. package/dist/es/lib/invariant.d.ts +9 -0
  130. package/dist/es/lib/invariant.js +19 -0
  131. package/dist/es/lib/noop.d.ts +1 -0
  132. package/dist/es/lib/noop.js +1 -0
  133. package/dist/es/lib/useForceUpdate.d.ts +6 -0
  134. package/dist/es/lib/useForceUpdate.js +20 -0
  135. package/dist/es/lib/useIndex.d.ts +3 -0
  136. package/dist/es/lib/useIndex.js +31 -0
  137. package/dist/es/lib/useIndexContext.d.ts +2 -0
  138. package/dist/es/lib/useIndexContext.js +8 -0
  139. package/dist/es/lib/useInstantSearchApi.d.ts +21 -0
  140. package/dist/es/lib/useInstantSearchApi.js +184 -0
  141. package/dist/es/lib/useInstantSearchContext.d.ts +3 -0
  142. package/dist/es/lib/useInstantSearchContext.js +8 -0
  143. package/dist/es/lib/useInstantSearchSSRContext.d.ts +3 -0
  144. package/dist/es/lib/useInstantSearchSSRContext.js +5 -0
  145. package/dist/es/lib/useInstantSearchServerContext.d.ts +3 -0
  146. package/dist/es/lib/useInstantSearchServerContext.js +5 -0
  147. package/dist/es/lib/useIsomorphicLayoutEffect.d.ts +7 -0
  148. package/dist/es/lib/useIsomorphicLayoutEffect.js +8 -0
  149. package/dist/es/lib/useSearchResults.d.ts +7 -0
  150. package/dist/es/lib/useSearchResults.js +40 -0
  151. package/dist/es/lib/useSearchState.d.ts +8 -0
  152. package/dist/es/lib/useSearchState.js +42 -0
  153. package/dist/es/lib/useStableValue.d.ts +1 -0
  154. package/dist/es/lib/useStableValue.js +20 -0
  155. package/dist/es/lib/useWidget.d.ts +8 -0
  156. package/dist/es/lib/useWidget.js +72 -0
  157. package/dist/es/lib/warn.d.ts +10 -0
  158. package/dist/es/lib/warn.js +33 -0
  159. package/dist/es/server/getServerState.d.ts +10 -0
  160. package/dist/es/server/getServerState.js +86 -0
  161. package/dist/es/server/index.d.ts +1 -0
  162. package/dist/es/server/index.js +1 -0
  163. package/dist/es/version.d.ts +2 -0
  164. package/dist/es/version.js +1 -0
  165. package/dist/umd/ReactInstantSearchCore.js +16316 -10183
  166. package/dist/umd/ReactInstantSearchCore.js.map +1 -1
  167. package/dist/umd/ReactInstantSearchCore.min.js +1 -1
  168. package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
  169. package/package.json +24 -9
  170. package/dist/cjs/connectors/connectAutoComplete.js +0 -104
  171. package/dist/cjs/connectors/connectBreadcrumb.js +0 -123
  172. package/dist/cjs/connectors/connectConfigureRelatedItems.js +0 -127
  173. package/dist/cjs/connectors/connectCurrentRefinements.js +0 -69
  174. package/dist/cjs/connectors/connectDynamicWidgets.js +0 -65
  175. package/dist/cjs/connectors/connectGeoSearch.js +0 -189
  176. package/dist/cjs/connectors/connectHierarchicalMenu.js +0 -273
  177. package/dist/cjs/connectors/connectHighlight.js +0 -87
  178. package/dist/cjs/connectors/connectHitInsights.js +0 -76
  179. package/dist/cjs/connectors/connectHits.js +0 -88
  180. package/dist/cjs/connectors/connectHitsPerPage.js +0 -97
  181. package/dist/cjs/connectors/connectInfiniteHits.js +0 -154
  182. package/dist/cjs/connectors/connectMenu.js +0 -221
  183. package/dist/cjs/connectors/connectNumericMenu.js +0 -215
  184. package/dist/cjs/connectors/connectPagination.js +0 -94
  185. package/dist/cjs/connectors/connectPoweredBy.js +0 -27
  186. package/dist/cjs/connectors/connectQueryRules.js +0 -129
  187. package/dist/cjs/connectors/connectRange.js +0 -287
  188. package/dist/cjs/connectors/connectRefinementList.js +0 -243
  189. package/dist/cjs/connectors/connectRelevantSort.js +0 -56
  190. package/dist/cjs/connectors/connectScrollTo.js +0 -70
  191. package/dist/cjs/connectors/connectSearchBox.js +0 -104
  192. package/dist/cjs/connectors/connectSortBy.js +0 -100
  193. package/dist/cjs/connectors/connectStateResults.js +0 -79
  194. package/dist/cjs/connectors/connectStats.js +0 -39
  195. package/dist/cjs/connectors/connectToggleRefinement.js +0 -163
  196. package/dist/cjs/connectors/connectVoiceSearch.js +0 -124
  197. package/dist/cjs/core/context.js +0 -37
  198. package/dist/cjs/core/createConnector.js +0 -268
  199. package/dist/cjs/core/createInstantSearchManager.d.js +0 -1
  200. package/dist/cjs/core/createInstantSearchManager.js +0 -541
  201. package/dist/cjs/core/createStore.js +0 -27
  202. package/dist/cjs/core/createWidgetsManager.js +0 -39
  203. package/dist/cjs/core/highlight.js +0 -102
  204. package/dist/cjs/core/indexUtils.js +0 -214
  205. package/dist/cjs/core/metadata.js +0 -46
  206. package/dist/cjs/core/translatable.js +0 -82
  207. package/dist/cjs/core/utils.js +0 -161
  208. package/dist/cjs/types/algoliasearch.js +0 -1
  209. package/dist/cjs/types/translatable.js +0 -1
  210. package/dist/cjs/widgets/Configure.js +0 -48
  211. package/dist/cjs/widgets/ConfigureRelatedItems.js +0 -21
  212. package/dist/cjs/widgets/DynamicWidgets.js +0 -61
  213. package/dist/cjs/widgets/Index.js +0 -149
  214. package/dist/cjs/widgets/InstantSearch.js +0 -251
  215. package/dist/cjs/widgets/QueryRuleContext.js +0 -14
  216. package/dist/es/connectors/connectAutoComplete.js +0 -96
  217. package/dist/es/connectors/connectBreadcrumb.js +0 -115
  218. package/dist/es/connectors/connectConfigureRelatedItems.js +0 -121
  219. package/dist/es/connectors/connectCurrentRefinements.js +0 -62
  220. package/dist/es/connectors/connectDynamicWidgets.js +0 -56
  221. package/dist/es/connectors/connectGeoSearch.js +0 -182
  222. package/dist/es/connectors/connectHierarchicalMenu.js +0 -264
  223. package/dist/es/connectors/connectHighlight.js +0 -79
  224. package/dist/es/connectors/connectHitInsights.js +0 -69
  225. package/dist/es/connectors/connectHits.js +0 -81
  226. package/dist/es/connectors/connectHitsPerPage.js +0 -89
  227. package/dist/es/connectors/connectInfiniteHits.js +0 -146
  228. package/dist/es/connectors/connectMenu.js +0 -213
  229. package/dist/es/connectors/connectNumericMenu.js +0 -207
  230. package/dist/es/connectors/connectPagination.js +0 -86
  231. package/dist/es/connectors/connectPoweredBy.js +0 -20
  232. package/dist/es/connectors/connectQueryRules.js +0 -122
  233. package/dist/es/connectors/connectRange.js +0 -280
  234. package/dist/es/connectors/connectRefinementList.js +0 -235
  235. package/dist/es/connectors/connectRelevantSort.js +0 -50
  236. package/dist/es/connectors/connectScrollTo.js +0 -63
  237. package/dist/es/connectors/connectSearchBox.js +0 -96
  238. package/dist/es/connectors/connectSortBy.js +0 -92
  239. package/dist/es/connectors/connectStateResults.js +0 -72
  240. package/dist/es/connectors/connectStats.js +0 -32
  241. package/dist/es/connectors/connectToggleRefinement.js +0 -155
  242. package/dist/es/connectors/connectVoiceSearch.js +0 -116
  243. package/dist/es/core/context.js +0 -28
  244. package/dist/es/core/createConnector.js +0 -257
  245. package/dist/es/core/createInstantSearchManager.d.js +0 -0
  246. package/dist/es/core/createInstantSearchManager.js +0 -534
  247. package/dist/es/core/createStore.js +0 -21
  248. package/dist/es/core/createWidgetsManager.js +0 -33
  249. package/dist/es/core/highlight.js +0 -94
  250. package/dist/es/core/indexUtils.js +0 -203
  251. package/dist/es/core/metadata.js +0 -38
  252. package/dist/es/core/translatable.js +0 -74
  253. package/dist/es/core/utils.js +0 -139
  254. package/dist/es/core/version.js +0 -1
  255. package/dist/es/types/algoliasearch.js +0 -1
  256. package/dist/es/types/index.js +0 -1
  257. package/dist/es/types/translatable.js +0 -1
  258. package/dist/es/widgets/Configure.js +0 -42
  259. package/dist/es/widgets/ConfigureRelatedItems.js +0 -13
  260. package/dist/es/widgets/DynamicWidgets.js +0 -51
  261. package/dist/es/widgets/Index.js +0 -138
  262. package/dist/es/widgets/InstantSearch.js +0 -241
  263. package/dist/es/widgets/QueryRuleContext.js +0 -6
@@ -1,50 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
- import createConnector from "../core/createConnector.js";
6
- import { refineValue, getCurrentRefinementValue, getResults
7
- // @ts-ignore
8
- } from "../core/indexUtils.js";
9
- function getId() {
10
- return 'relevancyStrictness';
11
- }
12
- function getCurrentRefinement(props, searchState, context) {
13
- var id = getId();
14
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, id);
15
- return currentRefinement;
16
- }
17
- export default createConnector({
18
- displayName: 'AlgoliaRelevantSort',
19
- $$type: 'ais.relevantSort',
20
- getProvidedProps: function getProvidedProps(props, _searchState, searchResults) {
21
- var results = getResults(searchResults, {
22
- ais: props.contextValue,
23
- multiIndexContext: props.indexContextValue
24
- });
25
- if (!results) {
26
- return {
27
- isVirtualReplica: false,
28
- isRelevantSorted: false
29
- };
30
- }
31
- return {
32
- isVirtualReplica: results.appliedRelevancyStrictness !== undefined,
33
- isRelevantSorted: results.appliedRelevancyStrictness !== undefined && results.appliedRelevancyStrictness > 0
34
- };
35
- },
36
- getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
37
- return searchParameters.setQueryParameter('relevancyStrictness', getCurrentRefinement(props, searchState, {
38
- ais: props.contextValue,
39
- multiIndexContext: props.indexContextValue
40
- }));
41
- },
42
- refine: function refine(props, searchState, nextRefinement) {
43
- var nextValue = _defineProperty({}, getId(), nextRefinement);
44
- var resetPage = true;
45
- return refineValue(searchState, nextValue, {
46
- ais: props.contextValue,
47
- multiIndexContext: props.indexContextValue
48
- }, resetPage);
49
- }
50
- });
@@ -1,63 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import createConnector from "../core/createConnector.js";
3
- import { getCurrentRefinementValue, hasMultipleIndices, getIndexId } from "../core/indexUtils.js";
4
- import { shallowEqual, omit } from "../core/utils.js";
5
-
6
- /**
7
- * connectScrollTo connector provides the logic to build a widget that will
8
- * let the page scroll to a certain point.
9
- * @name connectScrollTo
10
- * @kind connector
11
- * @propType {string} [scrollOn="page"] - Widget searchState key on which to listen for changes, default to the pagination widget.
12
- * @providedPropType {any} value - the current refinement applied to the widget listened by scrollTo
13
- * @providedPropType {boolean} hasNotChanged - indicates whether the refinement came from the scrollOn argument (for instance page by default)
14
- */
15
- export default createConnector({
16
- displayName: 'AlgoliaScrollTo',
17
- $$type: 'ais.scrollTo',
18
- propTypes: {
19
- scrollOn: PropTypes.string
20
- },
21
- defaultProps: {
22
- scrollOn: 'page'
23
- },
24
- getProvidedProps: function getProvidedProps(props, searchState) {
25
- var id = props.scrollOn;
26
- var value = getCurrentRefinementValue(props, searchState, {
27
- ais: props.contextValue,
28
- multiIndexContext: props.indexContextValue
29
- }, id, null);
30
- if (!this._prevSearchState) {
31
- this._prevSearchState = {};
32
- }
33
-
34
- // Get the subpart of the state that interest us
35
- if (hasMultipleIndices({
36
- ais: props.contextValue,
37
- multiIndexContext: props.indexContextValue
38
- })) {
39
- searchState = searchState.indices ? searchState.indices[getIndexId({
40
- ais: props.contextValue,
41
- multiIndexContext: props.indexContextValue
42
- })] : {};
43
- }
44
-
45
- // if there is a change in the app that has been triggered by another element
46
- // than "props.scrollOn (id) or the Configure widget, we need to keep track of
47
- // the search state to know if there's a change in the app that was not triggered
48
- // by the props.scrollOn (id) or the Configure widget. This is useful when
49
- // using ScrollTo in combination of Pagination. As pagination can be change
50
- // by every widget, we want to scroll only if it cames from the pagination
51
- // widget itself. We also remove the configure key from the search state to
52
- // do this comparison because for now configure values are not present in the
53
- // search state before a first refinement has been made and will false the results.
54
- // See: https://github.com/algolia/react-instantsearch/issues/164
55
- var cleanedSearchState = omit(searchState, ['configure', id]);
56
- var hasNotChanged = shallowEqual(this._prevSearchState, cleanedSearchState);
57
- this._prevSearchState = cleanedSearchState;
58
- return {
59
- value: value,
60
- hasNotChanged: hasNotChanged
61
- };
62
- }
63
- });
@@ -1,96 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
- import PropTypes from 'prop-types';
6
- import createConnector from "../core/createConnector.js";
7
- import { cleanUpValue, refineValue, getCurrentRefinementValue, getIndexId } from "../core/indexUtils.js";
8
- function getId() {
9
- return 'query';
10
- }
11
- function getCurrentRefinement(props, searchState, context) {
12
- var id = getId(props);
13
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, '');
14
- if (currentRefinement) {
15
- return currentRefinement;
16
- }
17
- return '';
18
- }
19
- function _refine(props, searchState, nextRefinement, context) {
20
- var id = getId();
21
- var nextValue = _defineProperty({}, id, nextRefinement);
22
- var resetPage = true;
23
- return refineValue(searchState, nextValue, context, resetPage);
24
- }
25
- function _cleanUp(props, searchState, context) {
26
- return cleanUpValue(searchState, context, getId());
27
- }
28
-
29
- /**
30
- * connectSearchBox connector provides the logic to build a widget that will
31
- * let the user search for a query
32
- * @name connectSearchBox
33
- * @kind connector
34
- * @propType {string} [defaultRefinement] - Provide a default value for the query
35
- * @providedPropType {function} refine - a function to change the current query
36
- * @providedPropType {string} currentRefinement - the current query used
37
- * @providedPropType {boolean} isSearchStalled - a flag that indicates if InstantSearch has detected that searches are stalled
38
- */
39
- export default createConnector({
40
- displayName: 'AlgoliaSearchBox',
41
- $$type: 'ais.searchBox',
42
- propTypes: {
43
- defaultRefinement: PropTypes.string
44
- },
45
- getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
46
- return {
47
- currentRefinement: getCurrentRefinement(props, searchState, {
48
- ais: props.contextValue,
49
- multiIndexContext: props.indexContextValue
50
- }),
51
- isSearchStalled: searchResults.isSearchStalled
52
- };
53
- },
54
- refine: function refine(props, searchState, nextRefinement) {
55
- return _refine(props, searchState, nextRefinement, {
56
- ais: props.contextValue,
57
- multiIndexContext: props.indexContextValue
58
- });
59
- },
60
- cleanUp: function cleanUp(props, searchState) {
61
- return _cleanUp(props, searchState, {
62
- ais: props.contextValue,
63
- multiIndexContext: props.indexContextValue
64
- });
65
- },
66
- getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
67
- return searchParameters.setQuery(getCurrentRefinement(props, searchState, {
68
- ais: props.contextValue,
69
- multiIndexContext: props.indexContextValue
70
- }));
71
- },
72
- getMetadata: function getMetadata(props, searchState) {
73
- var id = getId(props);
74
- var currentRefinement = getCurrentRefinement(props, searchState, {
75
- ais: props.contextValue,
76
- multiIndexContext: props.indexContextValue
77
- });
78
- return {
79
- id: id,
80
- index: getIndexId({
81
- ais: props.contextValue,
82
- multiIndexContext: props.indexContextValue
83
- }),
84
- items: currentRefinement === null ? [] : [{
85
- label: "".concat(id, ": ").concat(currentRefinement),
86
- value: function value(nextState) {
87
- return _refine(props, nextState, '', {
88
- ais: props.contextValue,
89
- multiIndexContext: props.indexContextValue
90
- });
91
- },
92
- currentRefinement: currentRefinement
93
- }]
94
- };
95
- }
96
- });
@@ -1,92 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
- import PropTypes from 'prop-types';
8
- import createConnector from "../core/createConnector.js";
9
- import { cleanUpValue, refineValue, getCurrentRefinementValue } from "../core/indexUtils.js";
10
- function getId() {
11
- return 'sortBy';
12
- }
13
- function getCurrentRefinement(props, searchState, context) {
14
- var id = getId(props);
15
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, null);
16
- if (currentRefinement) {
17
- return currentRefinement;
18
- }
19
- return null;
20
- }
21
-
22
- /**
23
- * The connectSortBy connector provides the logic to build a widget that will
24
- * display a list of indices. This allows a user to change how the hits are being sorted.
25
- * @name connectSortBy
26
- * @requirements Algolia handles sorting by creating replica indices. [Read more about sorting](https://www.algolia.com/doc/guides/relevance/sorting/) on
27
- * the Algolia website.
28
- * @kind connector
29
- * @propType {string} defaultRefinement - The default selected index.
30
- * @propType {{value: string, label: string}[]} items - The list of indexes to search in.
31
- * @propType {function} [transformItems] - Function to modify the items being displayed, e.g. for filtering or sorting them. Takes an items as parameter and expects it back in return.
32
- * @providedPropType {function} refine - a function to remove a single filter
33
- * @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
34
- * @providedPropType {string[]} currentRefinement - the refinement currently applied
35
- * @providedPropType {array.<{isRefined: boolean, label?: string, value: string}>} items - the list of items the HitsPerPage can display. If no label provided, the value will be displayed.
36
- */
37
- export default createConnector({
38
- displayName: 'AlgoliaSortBy',
39
- $$type: 'ais.sortBy',
40
- propTypes: {
41
- defaultRefinement: PropTypes.string,
42
- items: PropTypes.arrayOf(PropTypes.shape({
43
- label: PropTypes.string,
44
- value: PropTypes.string.isRequired
45
- })).isRequired,
46
- transformItems: PropTypes.func
47
- },
48
- getProvidedProps: function getProvidedProps(props, searchState) {
49
- var currentRefinement = getCurrentRefinement(props, searchState, {
50
- ais: props.contextValue,
51
- multiIndexContext: props.indexContextValue
52
- });
53
- var items = props.items.map(function (item) {
54
- return item.value === currentRefinement ? _objectSpread(_objectSpread({}, item), {}, {
55
- isRefined: true
56
- }) : _objectSpread(_objectSpread({}, item), {}, {
57
- isRefined: false
58
- });
59
- });
60
- return {
61
- items: props.transformItems ? props.transformItems(items) : items,
62
- currentRefinement: currentRefinement
63
- };
64
- },
65
- refine: function refine(props, searchState, nextRefinement) {
66
- var id = getId();
67
- var nextValue = _defineProperty({}, id, nextRefinement);
68
- var resetPage = true;
69
- return refineValue(searchState, nextValue, {
70
- ais: props.contextValue,
71
- multiIndexContext: props.indexContextValue
72
- }, resetPage);
73
- },
74
- cleanUp: function cleanUp(props, searchState) {
75
- return cleanUpValue(searchState, {
76
- ais: props.contextValue,
77
- multiIndexContext: props.indexContextValue
78
- }, getId());
79
- },
80
- getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
81
- var selectedIndex = getCurrentRefinement(props, searchState, {
82
- ais: props.contextValue,
83
- multiIndexContext: props.indexContextValue
84
- });
85
- return searchParameters.setIndex(selectedIndex);
86
- },
87
- getMetadata: function getMetadata() {
88
- return {
89
- id: getId()
90
- };
91
- }
92
- });
@@ -1,72 +0,0 @@
1
- import createConnector from "../core/createConnector.js";
2
- import { getResults } from "../core/indexUtils.js";
3
-
4
- /**
5
- * The `connectStateResults` connector provides a way to access the `searchState` and the `searchResults`
6
- * of InstantSearch.
7
- * For instance this connector allows you to create results/noResults or query/noQuery pages.
8
- * @name connectStateResults
9
- * @kind connector
10
- * @providedPropType {object} searchState - The search state of the instant search component. <br/><br/> See: [Search state structure](https://community.algolia.com/react-instantsearch/guide/Search_state.html)
11
- * @providedPropType {object} searchResults - The search results. <br/><br/> In case of multiple indices: if used under `<Index>`, results will be those of the corresponding index otherwise it'll be those of the root index See: [Search results structure](https://community.algolia.com/algoliasearch-helper-js/reference.html#searchresults)
12
- * @providedPropType {object} allSearchResults - In case of multiple indices you can retrieve all the results
13
- * @providedPropType {string} error - If the search failed, the error will be logged here.
14
- * @providedPropType {boolean} searching - If there is a search in progress.
15
- * @providedPropType {boolean} isSearchStalled - Flag that indicates if React InstantSearch has detected that searches are stalled.
16
- * @providedPropType {boolean} searchingForFacetValues - If there is a search in a list in progress.
17
- * @providedPropType {object} props - component props.
18
- * @example
19
- * import React from 'react';
20
- * import algoliasearch from 'algoliasearch/lite';
21
- * import { InstantSearch, SearchBox, Hits, connectStateResults } from 'react-instantsearch-dom';
22
- *
23
- * const searchClient = algoliasearch(
24
- * 'latency',
25
- * '6be0576ff61c053d5f9a3225e2a90f76'
26
- * );
27
- *
28
- * const Content = connectStateResults(({ searchState, searchResults }) => {
29
- * const hasResults = searchResults && searchResults.nbHits !== 0;
30
- *
31
- * return (
32
- * <div>
33
- * <div hidden={!hasResults}>
34
- * <Hits />
35
- * </div>
36
- * <div hidden={hasResults}>
37
- * <div>No results has been found for {searchState.query}</div>
38
- * </div>
39
- * </div>
40
- * );
41
- * });
42
- *
43
- * const App = () => (
44
- * <InstantSearch
45
- * searchClient={searchClient}
46
- * indexName="instant_search"
47
- * >
48
- * <SearchBox />
49
- * <Content />
50
- * </InstantSearch>
51
- * );
52
- */
53
- export default createConnector({
54
- displayName: 'AlgoliaStateResults',
55
- $$type: 'ais.stateResults',
56
- getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
57
- var results = getResults(searchResults, {
58
- ais: props.contextValue,
59
- multiIndexContext: props.indexContextValue
60
- });
61
- return {
62
- searchState: searchState,
63
- searchResults: results,
64
- allSearchResults: searchResults.results,
65
- searching: searchResults.searching,
66
- isSearchStalled: searchResults.isSearchStalled,
67
- error: searchResults.error,
68
- searchingForFacetValues: searchResults.searchingForFacetValues,
69
- props: props
70
- };
71
- }
72
- });
@@ -1,32 +0,0 @@
1
- import createConnector from "../core/createConnector.js";
2
- // @ts-ignore
3
- import { getResults } from "../core/indexUtils.js";
4
-
5
- /**
6
- * connectStats connector provides the logic to build a widget that will
7
- * displays algolia search statistics (hits number and processing time).
8
- * @name connectStats
9
- * @kind connector
10
- * @providedPropType {number} nbHits - number of hits returned by Algolia.
11
- * @providedPropType {number} nbSortedHits - number of sorted hits returned by Algolia.
12
- * @providedPropType {number} processingTimeMS - the time in ms took by Algolia to search for results.
13
- */
14
- export default createConnector({
15
- displayName: 'AlgoliaStats',
16
- $$type: 'ais.stats',
17
- getProvidedProps: function getProvidedProps(props, _searchState, searchResults) {
18
- var results = getResults(searchResults, {
19
- ais: props.contextValue,
20
- multiIndexContext: props.indexContextValue
21
- });
22
- if (!results) {
23
- return null;
24
- }
25
- return {
26
- areHitsSorted: results.appliedRelevancyStrictness !== undefined && results.appliedRelevancyStrictness > 0 && results.nbHits !== results.nbSortedHits,
27
- nbHits: results.nbHits,
28
- nbSortedHits: results.nbSortedHits,
29
- processingTimeMS: results.processingTimeMS
30
- };
31
- }
32
- });
@@ -1,155 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
- import PropTypes from 'prop-types';
6
- import { find } from "../core/utils.js";
7
- import createConnector from "../core/createConnector.js";
8
- import { cleanUpValue, getIndexId, getResults, refineValue, getCurrentRefinementValue } from "../core/indexUtils.js";
9
- function getId(props) {
10
- return props.attribute;
11
- }
12
- var namespace = 'toggle';
13
- var falsyStrings = ['0', 'false', 'null', 'undefined'];
14
- function getCurrentRefinement(props, searchState, context) {
15
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), false);
16
- if (falsyStrings.indexOf(currentRefinement) !== -1) {
17
- return false;
18
- }
19
- return Boolean(currentRefinement);
20
- }
21
- function _refine(props, searchState, nextRefinement, context) {
22
- var id = getId(props);
23
- var nextValue = _defineProperty({}, id, nextRefinement ? nextRefinement : false);
24
- var resetPage = true;
25
- return refineValue(searchState, nextValue, context, resetPage, namespace);
26
- }
27
- function _cleanUp(props, searchState, context) {
28
- return cleanUpValue(searchState, context, "".concat(namespace, ".").concat(getId(props)));
29
- }
30
-
31
- /**
32
- * connectToggleRefinement connector provides the logic to build a widget that will
33
- * provides an on/off filtering feature based on an attribute value.
34
- * @name connectToggleRefinement
35
- * @kind connector
36
- * @requirements To use this widget, you'll need an attribute to toggle on.
37
- *
38
- * You can't toggle on null or not-null values. If you want to address this particular use-case you'll need to compute an
39
- * extra boolean attribute saying if the value exists or not. See this [thread](https://discourse.algolia.com/t/how-to-create-a-toggle-for-the-absence-of-a-string-attribute/2460) for more details.
40
- *
41
- * @propType {string} attribute - Name of the attribute on which to apply the `value` refinement. Required when `value` is present.
42
- * @propType {string} label - Label for the toggle.
43
- * @propType {string} value - Value of the refinement to apply on `attribute`.
44
- * @propType {boolean} [defaultRefinement=false] - Default searchState of the widget. Should the toggle be checked by default?
45
- * @providedPropType {boolean} currentRefinement - `true` when the refinement is applied, `false` otherwise
46
- * @providedPropType {object} count - an object that contains the count for `checked` and `unchecked` state
47
- * @providedPropType {function} refine - a function to toggle a refinement
48
- * @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
49
- */
50
- export default createConnector({
51
- displayName: 'AlgoliaToggle',
52
- $$type: 'ais.toggle',
53
- propTypes: {
54
- label: PropTypes.string.isRequired,
55
- attribute: PropTypes.string.isRequired,
56
- value: PropTypes.any.isRequired,
57
- filter: PropTypes.func,
58
- defaultRefinement: PropTypes.bool
59
- },
60
- getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
61
- var attribute = props.attribute,
62
- value = props.value;
63
- var results = getResults(searchResults, {
64
- ais: props.contextValue,
65
- multiIndexContext: props.indexContextValue
66
- });
67
- var currentRefinement = getCurrentRefinement(props, searchState, {
68
- ais: props.contextValue,
69
- multiIndexContext: props.indexContextValue
70
- });
71
- var allFacetValues = results && results.getFacetByName(attribute) ? results.getFacetValues(attribute) : null;
72
- var facetValue =
73
- // Use null to always be consistent with type of the value
74
- // count: number | null
75
- allFacetValues && allFacetValues.length ? find(allFacetValues, function (item) {
76
- return item.name === value.toString();
77
- }) : null;
78
- var facetValueCount = facetValue && facetValue.count;
79
- var allFacetValuesCount =
80
- // Use null to always be consistent with type of the value
81
- // count: number | null
82
- allFacetValues && allFacetValues.length ? allFacetValues.reduce(function (acc, item) {
83
- return acc + item.count;
84
- }, 0) : null;
85
- var canRefine = currentRefinement ? allFacetValuesCount !== null && allFacetValuesCount > 0 : facetValueCount !== null && facetValueCount > 0;
86
- var count = {
87
- checked: allFacetValuesCount,
88
- unchecked: facetValueCount
89
- };
90
- return {
91
- currentRefinement: currentRefinement,
92
- canRefine: canRefine,
93
- count: count
94
- };
95
- },
96
- refine: function refine(props, searchState, nextRefinement) {
97
- return _refine(props, searchState, nextRefinement, {
98
- ais: props.contextValue,
99
- multiIndexContext: props.indexContextValue
100
- });
101
- },
102
- cleanUp: function cleanUp(props, searchState) {
103
- return _cleanUp(props, searchState, {
104
- ais: props.contextValue,
105
- multiIndexContext: props.indexContextValue
106
- });
107
- },
108
- getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
109
- var attribute = props.attribute,
110
- value = props.value,
111
- filter = props.filter;
112
- var checked = getCurrentRefinement(props, searchState, {
113
- ais: props.contextValue,
114
- multiIndexContext: props.indexContextValue
115
- });
116
- var nextSearchParameters = searchParameters.addDisjunctiveFacet(attribute);
117
- if (checked) {
118
- nextSearchParameters = nextSearchParameters.addDisjunctiveFacetRefinement(attribute, value);
119
- if (filter) {
120
- nextSearchParameters = filter(nextSearchParameters);
121
- }
122
- }
123
- return nextSearchParameters;
124
- },
125
- getMetadata: function getMetadata(props, searchState) {
126
- var id = getId(props);
127
- var checked = getCurrentRefinement(props, searchState, {
128
- ais: props.contextValue,
129
- multiIndexContext: props.indexContextValue
130
- });
131
- var items = [];
132
- var index = getIndexId({
133
- ais: props.contextValue,
134
- multiIndexContext: props.indexContextValue
135
- });
136
- if (checked) {
137
- items.push({
138
- label: props.label,
139
- currentRefinement: checked,
140
- attribute: props.attribute,
141
- value: function value(nextState) {
142
- return _refine(props, nextState, false, {
143
- ais: props.contextValue,
144
- multiIndexContext: props.indexContextValue
145
- });
146
- }
147
- });
148
- }
149
- return {
150
- id: id,
151
- index: index,
152
- items: items
153
- };
154
- }
155
- });