react-instantsearch-core 6.40.4 → 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 -87
  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 +14071 -7955
  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 +23 -8
  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,116 +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, getIndexId } from "../core/indexUtils.js";
10
- function getId() {
11
- return 'query';
12
- }
13
- function getAdditionalId() {
14
- return 'additionalVoiceParameters';
15
- }
16
- function getCurrentRefinementQuery(props, searchState, context) {
17
- var id = getId();
18
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, '');
19
- if (currentRefinement) {
20
- return currentRefinement;
21
- }
22
- return '';
23
- }
24
- function getCurrentRefinementAdditional(props, searchState, context) {
25
- var id = getAdditionalId();
26
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, '');
27
- if (currentRefinement) {
28
- return currentRefinement;
29
- }
30
- return {};
31
- }
32
- function _refine(props, searchState, nextRefinement, context) {
33
- var _nextValue;
34
- var id = getId();
35
- var voiceParams = getAdditionalId();
36
- var queryLanguages = props.language ? {
37
- queryLanguages: [props.language.split('-')[0]]
38
- } : {};
39
- var additionalQueryParameters = typeof props.additionalQueryParameters === 'function' ? _objectSpread({
40
- ignorePlurals: true,
41
- removeStopWords: true,
42
- optionalWords: nextRefinement
43
- }, props.additionalQueryParameters({
44
- query: nextRefinement
45
- })) : {};
46
- var nextValue = (_nextValue = {}, _defineProperty(_nextValue, id, nextRefinement), _defineProperty(_nextValue, voiceParams, _objectSpread(_objectSpread({}, queryLanguages), additionalQueryParameters)), _nextValue);
47
- var resetPage = true;
48
- return refineValue(searchState, nextValue, context, resetPage);
49
- }
50
- function _cleanUp(props, searchState, context) {
51
- var interimState = cleanUpValue(searchState, context, getId());
52
- return cleanUpValue(interimState, context, getAdditionalId());
53
- }
54
- export default createConnector({
55
- displayName: 'AlgoliaVoiceSearch',
56
- $$type: 'ais.voiceSearch',
57
- propTypes: {
58
- defaultRefinement: PropTypes.string
59
- },
60
- getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
61
- return {
62
- currentRefinement: getCurrentRefinementQuery(props, searchState, {
63
- ais: props.contextValue,
64
- multiIndexContext: props.indexContextValue
65
- }),
66
- isSearchStalled: searchResults.isSearchStalled
67
- };
68
- },
69
- refine: function refine(props, searchState, nextRefinement) {
70
- return _refine(props, searchState, nextRefinement, {
71
- ais: props.contextValue,
72
- multiIndexContext: props.indexContextValue
73
- });
74
- },
75
- cleanUp: function cleanUp(props, searchState) {
76
- return _cleanUp(props, searchState, {
77
- ais: props.contextValue,
78
- multiIndexContext: props.indexContextValue
79
- });
80
- },
81
- getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
82
- var query = getCurrentRefinementQuery(props, searchState, {
83
- ais: props.contextValue,
84
- multiIndexContext: props.indexContextValue
85
- });
86
- var additionalParams = getCurrentRefinementAdditional(props, searchState, {
87
- ais: props.contextValue,
88
- multiIndexContext: props.indexContextValue
89
- });
90
- return searchParameters.setQuery(query).setQueryParameters(additionalParams);
91
- },
92
- getMetadata: function getMetadata(props, searchState) {
93
- var id = getId();
94
- var currentRefinement = getCurrentRefinementQuery(props, searchState, {
95
- ais: props.contextValue,
96
- multiIndexContext: props.indexContextValue
97
- });
98
- return {
99
- id: id,
100
- index: getIndexId({
101
- ais: props.contextValue,
102
- multiIndexContext: props.indexContextValue
103
- }),
104
- items: currentRefinement === null ? [] : [{
105
- label: "".concat(id, ": ").concat(currentRefinement),
106
- value: function value(nextState) {
107
- return _refine(props, nextState, '', {
108
- ais: props.contextValue,
109
- multiIndexContext: props.indexContextValue
110
- });
111
- },
112
- currentRefinement: currentRefinement
113
- }]
114
- };
115
- }
116
- });
@@ -1,28 +0,0 @@
1
- import { createContext } from 'react';
2
- export var instantSearchContext = /*#__PURE__*/createContext({
3
- onInternalStateUpdate: function onInternalStateUpdate() {
4
- return undefined;
5
- },
6
- createHrefForState: function createHrefForState() {
7
- return '#';
8
- },
9
- onSearchForFacetValues: function onSearchForFacetValues() {
10
- return undefined;
11
- },
12
- onSearchStateChange: function onSearchStateChange() {
13
- return undefined;
14
- },
15
- onSearchParameters: function onSearchParameters() {
16
- return undefined;
17
- },
18
- store: {},
19
- widgetsManager: {},
20
- mainTargetedIndex: ''
21
- });
22
- var InstantSearchConsumer = instantSearchContext.Consumer,
23
- InstantSearchProvider = instantSearchContext.Provider;
24
- export { InstantSearchConsumer, InstantSearchProvider };
25
- var _createContext = /*#__PURE__*/createContext(undefined),
26
- IndexConsumer = _createContext.Consumer,
27
- IndexProvider = _createContext.Provider;
28
- export { IndexConsumer, IndexProvider };
@@ -1,257 +0,0 @@
1
- var _excluded = ["contextValue"];
2
- 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); }
3
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
5
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
- 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; }
7
- 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; }
8
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
12
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
13
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
15
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
16
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
17
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
18
- 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; }
19
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
- 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); }
21
- import React, { Component } from 'react';
22
- import isEqual from 'react-fast-compare';
23
- import { InstantSearchConsumer, IndexConsumer } from "./context.js";
24
- import { shallowEqual, getDisplayName, removeEmptyKey } from "./utils.js";
25
- /**
26
- * Connectors are the HOC used to transform React components
27
- * into InstantSearch widgets.
28
- * In order to simplify the construction of such connectors
29
- * `createConnector` takes a description and transform it into
30
- * a connector.
31
- * @param {ConnectorDescription} connectorDesc the description of the connector
32
- * @return {Connector} a function that wraps a component into
33
- * an instantsearch connected one.
34
- */
35
- export function createConnectorWithoutContext(connectorDesc) {
36
- if (!connectorDesc.displayName) {
37
- throw new Error('`createConnector` requires you to provide a `displayName` property.');
38
- }
39
- var isWidget = typeof connectorDesc.getSearchParameters === 'function' || typeof connectorDesc.getMetadata === 'function' || typeof connectorDesc.transitionState === 'function';
40
- return function (Composed) {
41
- var additionalWidgetProperties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
42
- var Connector = /*#__PURE__*/function (_Component) {
43
- _inherits(Connector, _Component);
44
- var _super = _createSuper(Connector);
45
- function Connector(props) {
46
- var _this;
47
- _classCallCheck(this, Connector);
48
- _this = _super.call(this, props);
49
- _defineProperty(_assertThisInitialized(_this), "unsubscribe", void 0);
50
- _defineProperty(_assertThisInitialized(_this), "unregisterWidget", void 0);
51
- _defineProperty(_assertThisInitialized(_this), "cleanupTimerRef", null);
52
- _defineProperty(_assertThisInitialized(_this), "isUnmounting", false);
53
- _defineProperty(_assertThisInitialized(_this), "state", {
54
- providedProps: _this.getProvidedProps(_this.props)
55
- });
56
- _defineProperty(_assertThisInitialized(_this), "refine", function () {
57
- var _ref;
58
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
59
- args[_key] = arguments[_key];
60
- }
61
- _this.props.contextValue.onInternalStateUpdate(
62
- // refine will always be defined here because the prop is only given conditionally
63
- (_ref = connectorDesc.refine).call.apply(_ref, [_assertThisInitialized(_this), _this.props, _this.props.contextValue.store.getState().widgets].concat(args)));
64
- });
65
- _defineProperty(_assertThisInitialized(_this), "createURL", function () {
66
- var _ref2;
67
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
68
- args[_key2] = arguments[_key2];
69
- }
70
- return _this.props.contextValue.createHrefForState(
71
- // refine will always be defined here because the prop is only given conditionally
72
- (_ref2 = connectorDesc.refine).call.apply(_ref2, [_assertThisInitialized(_this), _this.props, _this.props.contextValue.store.getState().widgets].concat(args)));
73
- });
74
- _defineProperty(_assertThisInitialized(_this), "searchForFacetValues", function () {
75
- var _ref3;
76
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
77
- args[_key3] = arguments[_key3];
78
- }
79
- _this.props.contextValue.onSearchForFacetValues(
80
- // searchForFacetValues will always be defined here because the prop is only given conditionally
81
- (_ref3 = connectorDesc.searchForFacetValues).call.apply(_ref3, [_assertThisInitialized(_this), _this.props, _this.props.contextValue.store.getState().widgets].concat(args)));
82
- });
83
- if (connectorDesc.getSearchParameters) {
84
- _this.props.contextValue.onSearchParameters(connectorDesc.getSearchParameters.bind(_assertThisInitialized(_this)), {
85
- ais: _this.props.contextValue,
86
- multiIndexContext: _this.props.indexContextValue
87
- }, _this.props, connectorDesc.getMetadata && connectorDesc.getMetadata.bind(_assertThisInitialized(_this)), connectorDesc.displayName);
88
- }
89
- return _this;
90
- }
91
- _createClass(Connector, [{
92
- key: "componentDidMount",
93
- value: function componentDidMount() {
94
- var _this2 = this;
95
- if (this.cleanupTimerRef) {
96
- clearTimeout(this.cleanupTimerRef);
97
- this.cleanupTimerRef = null;
98
- }
99
- this.unsubscribe = this.props.contextValue.store.subscribe(function () {
100
- if (!_this2.isUnmounting) {
101
- _this2.setState({
102
- providedProps: _this2.getProvidedProps(_this2.props)
103
- });
104
- }
105
- });
106
- if (isWidget) {
107
- this.unregisterWidget = this.props.contextValue.widgetsManager.registerWidget(this);
108
- }
109
- }
110
- }, {
111
- key: "shouldComponentUpdate",
112
- value: function shouldComponentUpdate(nextProps, nextState) {
113
- if (typeof connectorDesc.shouldComponentUpdate === 'function') {
114
- return connectorDesc.shouldComponentUpdate.call(this, this.props, nextProps, this.state, nextState);
115
- }
116
- var propsEqual = shallowEqual(this.props, nextProps);
117
- if (this.state.providedProps === null || nextState.providedProps === null) {
118
- if (this.state.providedProps === nextState.providedProps) {
119
- return !propsEqual;
120
- }
121
- return true;
122
- }
123
- return !propsEqual || !shallowEqual(this.state.providedProps, nextState.providedProps);
124
- }
125
- }, {
126
- key: "componentDidUpdate",
127
- value: function componentDidUpdate(prevProps) {
128
- if (!isEqual(prevProps, this.props)) {
129
- this.setState({
130
- providedProps: this.getProvidedProps(this.props)
131
- });
132
- if (isWidget) {
133
- this.props.contextValue.widgetsManager.update();
134
- if (typeof connectorDesc.transitionState === 'function') {
135
- this.props.contextValue.onSearchStateChange(connectorDesc.transitionState.call(this, this.props, this.props.contextValue.store.getState().widgets, this.props.contextValue.store.getState().widgets));
136
- }
137
- }
138
- }
139
- }
140
- }, {
141
- key: "componentWillUnmount",
142
- value: function componentWillUnmount() {
143
- var _this3 = this;
144
- this.cleanupTimerRef = setTimeout(function () {
145
- _this3.isUnmounting = true;
146
- if (_this3.unsubscribe) {
147
- _this3.unsubscribe();
148
- }
149
- if (_this3.unregisterWidget) {
150
- _this3.unregisterWidget();
151
- if (typeof connectorDesc.cleanUp === 'function') {
152
- var nextState = connectorDesc.cleanUp.call(_this3, _this3.props, _this3.props.contextValue.store.getState().widgets);
153
- _this3.props.contextValue.store.setState(_objectSpread(_objectSpread({}, _this3.props.contextValue.store.getState()), {}, {
154
- widgets: nextState
155
- }));
156
- _this3.props.contextValue.onSearchStateChange(removeEmptyKey(nextState));
157
- }
158
- }
159
- });
160
- }
161
- }, {
162
- key: "getProvidedProps",
163
- value: function getProvidedProps(props) {
164
- var _this$props$contextVa = this.props.contextValue.store.getState(),
165
- widgets = _this$props$contextVa.widgets,
166
- results = _this$props$contextVa.results,
167
- resultsFacetValues = _this$props$contextVa.resultsFacetValues,
168
- searching = _this$props$contextVa.searching,
169
- searchingForFacetValues = _this$props$contextVa.searchingForFacetValues,
170
- isSearchStalled = _this$props$contextVa.isSearchStalled,
171
- metadata = _this$props$contextVa.metadata,
172
- error = _this$props$contextVa.error;
173
- var searchResults = {
174
- results: results,
175
- searching: searching,
176
- searchingForFacetValues: searchingForFacetValues,
177
- isSearchStalled: isSearchStalled,
178
- error: error
179
- };
180
- return connectorDesc.getProvidedProps.call(this, props, widgets, searchResults, metadata,
181
- // @MAJOR: move this attribute on the `searchResults` it doesn't
182
- // makes sense to have it into a separate argument. The search
183
- // flags are on the object why not the results?
184
- resultsFacetValues);
185
- }
186
- }, {
187
- key: "getSearchParameters",
188
- value: function getSearchParameters(searchParameters) {
189
- if (typeof connectorDesc.getSearchParameters === 'function') {
190
- return connectorDesc.getSearchParameters.call(this, searchParameters, this.props, this.props.contextValue.store.getState().widgets);
191
- }
192
- return null;
193
- }
194
- }, {
195
- key: "getMetadata",
196
- value: function getMetadata(nextWidgetsState) {
197
- if (typeof connectorDesc.getMetadata === 'function') {
198
- return connectorDesc.getMetadata.call(this, this.props, nextWidgetsState);
199
- }
200
- return {};
201
- }
202
- }, {
203
- key: "transitionState",
204
- value: function transitionState(prevWidgetsState, nextWidgetsState) {
205
- if (typeof connectorDesc.transitionState === 'function') {
206
- return connectorDesc.transitionState.call(this, this.props, prevWidgetsState, nextWidgetsState);
207
- }
208
- return nextWidgetsState;
209
- }
210
- }, {
211
- key: "render",
212
- value: function render() {
213
- var _this$props = this.props,
214
- contextValue = _this$props.contextValue,
215
- props = _objectWithoutProperties(_this$props, _excluded);
216
- var providedProps = this.state.providedProps;
217
- if (providedProps === null) {
218
- return null;
219
- }
220
- var refineProps = typeof connectorDesc.refine === 'function' ? {
221
- refine: this.refine,
222
- createURL: this.createURL
223
- } : {};
224
- var searchForFacetValuesProps = typeof connectorDesc.searchForFacetValues === 'function' ? {
225
- searchForItems: this.searchForFacetValues
226
- } : {};
227
- return /*#__PURE__*/React.createElement(Composed, _extends({}, props, providedProps, refineProps, searchForFacetValuesProps));
228
- }
229
- }]);
230
- return Connector;
231
- }(Component);
232
- _defineProperty(Connector, "displayName", "".concat(connectorDesc.displayName, "(").concat(getDisplayName(Composed), ")"));
233
- _defineProperty(Connector, "$$type", connectorDesc.$$type);
234
- _defineProperty(Connector, "$$widgetType", additionalWidgetProperties.$$widgetType);
235
- _defineProperty(Connector, "propTypes", connectorDesc.propTypes);
236
- _defineProperty(Connector, "defaultProps", connectorDesc.defaultProps);
237
- _defineProperty(Connector, "_connectorDesc", connectorDesc);
238
- return Connector;
239
- };
240
- }
241
- var createConnectorWithContext = function createConnectorWithContext(connectorDesc) {
242
- return function (Composed, additionalWidgetProperties) {
243
- var Connector = createConnectorWithoutContext(connectorDesc)(Composed, additionalWidgetProperties);
244
- var ConnectorWrapper = function ConnectorWrapper(props) {
245
- return /*#__PURE__*/React.createElement(InstantSearchConsumer, null, function (contextValue) {
246
- return /*#__PURE__*/React.createElement(IndexConsumer, null, function (indexContextValue) {
247
- return /*#__PURE__*/React.createElement(Connector, _extends({
248
- contextValue: contextValue,
249
- indexContextValue: indexContextValue
250
- }, props));
251
- });
252
- });
253
- };
254
- return ConnectorWrapper;
255
- };
256
- };
257
- export default createConnectorWithContext;
File without changes