react-instantsearch-core 6.40.4 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,264 +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 algoliasearchHelper from 'algoliasearch-helper';
8
- import PropTypes from 'prop-types';
9
- import createConnector from "../core/createConnector.js";
10
- import { cleanUpValue, getIndexId, refineValue, getCurrentRefinementValue, getResults } from "../core/indexUtils.js";
11
- import { unescapeFacetValue } from "../core/utils.js";
12
- export var getId = function getId(props) {
13
- return props.attributes[0];
14
- };
15
- var namespace = 'hierarchicalMenu';
16
- function getCurrentRefinement(props, searchState, context) {
17
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, "".concat(namespace, ".").concat(getId(props)), null);
18
- if (currentRefinement === '') {
19
- return null;
20
- }
21
- return currentRefinement;
22
- }
23
- function getValue(value, props, searchState, context) {
24
- var id = props.id,
25
- attributes = props.attributes,
26
- separator = props.separator,
27
- rootPath = props.rootPath,
28
- showParentLevel = props.showParentLevel;
29
- var currentRefinement = getCurrentRefinement(props, searchState, context);
30
- var nextRefinement;
31
- if (currentRefinement === null) {
32
- nextRefinement = value;
33
- } else {
34
- var tmpSearchParameters = new algoliasearchHelper.SearchParameters({
35
- hierarchicalFacets: [{
36
- name: id,
37
- attributes: attributes,
38
- separator: separator,
39
- rootPath: rootPath,
40
- showParentLevel: showParentLevel
41
- }]
42
- });
43
- nextRefinement = tmpSearchParameters.toggleHierarchicalFacetRefinement(id, currentRefinement).toggleHierarchicalFacetRefinement(id, value).getHierarchicalRefinement(id)[0];
44
- }
45
- return nextRefinement;
46
- }
47
- function transformValue(value, props, searchState, context) {
48
- return value.map(function (v) {
49
- return {
50
- label: v.name,
51
- value: getValue(v.escapedValue, props, searchState, context),
52
- count: v.count,
53
- isRefined: v.isRefined,
54
- items: v.data && transformValue(v.data, props, searchState, context)
55
- };
56
- });
57
- }
58
- var truncate = function truncate() {
59
- var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
60
- var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
61
- return items.slice(0, limit).map(function () {
62
- var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
63
- return Array.isArray(item.items) ? _objectSpread(_objectSpread({}, item), {}, {
64
- items: truncate(item.items, limit)
65
- }) : item;
66
- });
67
- };
68
- function _refine(props, searchState, nextRefinement, context) {
69
- var id = getId(props);
70
- var nextValue = _defineProperty({}, id, nextRefinement || '');
71
- var resetPage = true;
72
- return refineValue(searchState, nextValue, context, resetPage, namespace);
73
- }
74
- function _cleanUp(props, searchState, context) {
75
- return cleanUpValue(searchState, context, "".concat(namespace, ".").concat(getId(props)));
76
- }
77
- var sortBy = ['name:asc'];
78
-
79
- /**
80
- * connectHierarchicalMenu connector provides the logic to build a widget that will
81
- * give the user the ability to explore a tree-like structure.
82
- * This is commonly used for multi-level categorization of products on e-commerce
83
- * websites. From a UX point of view, we suggest not displaying more than two levels deep.
84
- * @name connectHierarchicalMenu
85
- * @requirements To use this widget, your attributes must be formatted in a specific way.
86
- * If you want for example to have a hierarchical menu of categories, objects in your index
87
- * should be formatted this way:
88
- *
89
- * ```json
90
- * {
91
- * "categories.lvl0": "products",
92
- * "categories.lvl1": "products > fruits",
93
- * "categories.lvl2": "products > fruits > citrus"
94
- * }
95
- * ```
96
- *
97
- * It's also possible to provide more than one path for each level:
98
- *
99
- * ```json
100
- * {
101
- * "categories.lvl0": ["products", "goods"],
102
- * "categories.lvl1": ["products > fruits", "goods > to eat"]
103
- * }
104
- * ```
105
- *
106
- * All attributes passed to the `attributes` prop must be present in "attributes for faceting"
107
- * on the Algolia dashboard or configured as `attributesForFaceting` via a set settings call to the Algolia API.
108
- *
109
- * @kind connector
110
- * @propType {array.<string>} attributes - List of attributes to use to generate the hierarchy of the menu. See the example for the convention to follow.
111
- * @propType {string} [defaultRefinement] - the item value selected by default
112
- * @propType {boolean} [showMore=false] - Flag to activate the show more button, for toggling the number of items between limit and showMoreLimit.
113
- * @propType {number} [limit=10] - The maximum number of items displayed.
114
- * @propType {number} [showMoreLimit=20] - The maximum number of items displayed when the user triggers the show more. Not considered if `showMore` is false.
115
- * @propType {string} [separator='>'] - Specifies the level separator used in the data.
116
- * @propType {string} [rootPath=null] - The path to use if the first level is not the root level.
117
- * @propType {boolean} [showParentLevel=true] - Flag to set if the parent level should be displayed.
118
- * @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.
119
- * @providedPropType {function} refine - a function to toggle a refinement
120
- * @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
121
- * @providedPropType {string} currentRefinement - the refinement currently applied
122
- * @providedPropType {array.<{items: object, count: number, isRefined: boolean, label: string, value: string}>} items - the list of items the HierarchicalMenu can display. items has the same shape as parent items.
123
- */
124
- export default createConnector({
125
- displayName: 'AlgoliaHierarchicalMenu',
126
- $$type: 'ais.hierarchicalMenu',
127
- propTypes: {
128
- attributes: function attributes(props, propName, componentName) {
129
- var isNotString = function isNotString(val) {
130
- return typeof val !== 'string';
131
- };
132
- if (!Array.isArray(props[propName]) || props[propName].some(isNotString) || props[propName].length < 1) {
133
- return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Expected an Array of Strings"));
134
- }
135
- return undefined;
136
- },
137
- separator: PropTypes.string,
138
- rootPath: PropTypes.string,
139
- showParentLevel: PropTypes.bool,
140
- defaultRefinement: PropTypes.string,
141
- showMore: PropTypes.bool,
142
- limit: PropTypes.number,
143
- showMoreLimit: PropTypes.number,
144
- transformItems: PropTypes.func,
145
- facetOrdering: PropTypes.bool
146
- },
147
- defaultProps: {
148
- showMore: false,
149
- limit: 10,
150
- showMoreLimit: 20,
151
- separator: ' > ',
152
- rootPath: null,
153
- showParentLevel: true,
154
- facetOrdering: true
155
- },
156
- getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
157
- var showMore = props.showMore,
158
- limit = props.limit,
159
- showMoreLimit = props.showMoreLimit,
160
- facetOrdering = props.facetOrdering;
161
- var id = getId(props);
162
- var results = getResults(searchResults, {
163
- ais: props.contextValue,
164
- multiIndexContext: props.indexContextValue
165
- });
166
- var isFacetPresent = Boolean(results) && Boolean(results.getFacetByName(id));
167
- if (!isFacetPresent) {
168
- return {
169
- items: [],
170
- currentRefinement: getCurrentRefinement(props, searchState, {
171
- ais: props.contextValue,
172
- multiIndexContext: props.indexContextValue
173
- }),
174
- canRefine: false
175
- };
176
- }
177
- var itemsLimit = showMore ? showMoreLimit : limit;
178
- var value = results.getFacetValues(id, {
179
- sortBy: sortBy,
180
- facetOrdering: facetOrdering
181
- });
182
- var items = value.data ? transformValue(value.data, props, searchState, {
183
- ais: props.contextValue,
184
- multiIndexContext: props.indexContextValue
185
- }) : [];
186
- var transformedItems = props.transformItems ? props.transformItems(items) : items;
187
- return {
188
- items: truncate(transformedItems, itemsLimit),
189
- currentRefinement: getCurrentRefinement(props, searchState, {
190
- ais: props.contextValue,
191
- multiIndexContext: props.indexContextValue
192
- }),
193
- canRefine: transformedItems.length > 0
194
- };
195
- },
196
- refine: function refine(props, searchState, nextRefinement) {
197
- return _refine(props, searchState, nextRefinement, {
198
- ais: props.contextValue,
199
- multiIndexContext: props.indexContextValue
200
- });
201
- },
202
- cleanUp: function cleanUp(props, searchState) {
203
- return _cleanUp(props, searchState, {
204
- ais: props.contextValue,
205
- multiIndexContext: props.indexContextValue
206
- });
207
- },
208
- getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
209
- var attributes = props.attributes,
210
- separator = props.separator,
211
- rootPath = props.rootPath,
212
- showParentLevel = props.showParentLevel,
213
- showMore = props.showMore,
214
- limit = props.limit,
215
- showMoreLimit = props.showMoreLimit,
216
- contextValue = props.contextValue;
217
- var id = getId(props);
218
- var itemsLimit = showMore ? showMoreLimit : limit;
219
- searchParameters = searchParameters.addHierarchicalFacet({
220
- name: id,
221
- attributes: attributes,
222
- separator: separator,
223
- rootPath: rootPath,
224
- showParentLevel: showParentLevel
225
- }).setQueryParameters({
226
- maxValuesPerFacet: Math.max(searchParameters.maxValuesPerFacet || 0, itemsLimit)
227
- });
228
- var currentRefinement = getCurrentRefinement(props, searchState, {
229
- ais: contextValue,
230
- multiIndexContext: props.indexContextValue
231
- });
232
- if (currentRefinement !== null) {
233
- searchParameters = searchParameters.toggleHierarchicalFacetRefinement(id, currentRefinement);
234
- }
235
- return searchParameters;
236
- },
237
- getMetadata: function getMetadata(props, searchState) {
238
- var rootAttribute = props.attributes[0];
239
- var id = getId(props);
240
- var currentRefinement = getCurrentRefinement(props, searchState, {
241
- ais: props.contextValue,
242
- multiIndexContext: props.indexContextValue
243
- });
244
- var items = !currentRefinement ? [] : [{
245
- label: "".concat(rootAttribute, ": ").concat(unescapeFacetValue(currentRefinement)),
246
- attribute: rootAttribute,
247
- value: function value(nextState) {
248
- return _refine(props, nextState, '', {
249
- ais: props.contextValue,
250
- multiIndexContext: props.indexContextValue
251
- });
252
- },
253
- currentRefinement: currentRefinement
254
- }];
255
- return {
256
- id: id,
257
- index: getIndexId({
258
- ais: props.contextValue,
259
- multiIndexContext: props.indexContextValue
260
- }),
261
- items: items
262
- };
263
- }
264
- });
@@ -1,79 +0,0 @@
1
- import createConnector from "../core/createConnector.js";
2
- import { HIGHLIGHT_TAGS, parseAlgoliaHit } from "../core/highlight.js";
3
- var highlight = function highlight(_ref) {
4
- var attribute = _ref.attribute,
5
- hit = _ref.hit,
6
- highlightProperty = _ref.highlightProperty,
7
- _ref$preTag = _ref.preTag,
8
- preTag = _ref$preTag === void 0 ? HIGHLIGHT_TAGS.highlightPreTag : _ref$preTag,
9
- _ref$postTag = _ref.postTag,
10
- postTag = _ref$postTag === void 0 ? HIGHLIGHT_TAGS.highlightPostTag : _ref$postTag;
11
- return parseAlgoliaHit({
12
- attribute: attribute,
13
- highlightProperty: highlightProperty,
14
- hit: hit,
15
- preTag: preTag,
16
- postTag: postTag
17
- });
18
- };
19
-
20
- /**
21
- * connectHighlight connector provides the logic to create an highlighter
22
- * component that will retrieve, parse and render an highlighted attribute
23
- * from an Algolia hit.
24
- * @name connectHighlight
25
- * @kind connector
26
- * @category connector
27
- * @providedPropType {function} highlight - function to retrieve and parse an attribute from a hit. It takes a configuration object with 3 attributes: `highlightProperty` which is the property that contains the highlight structure from the records, `attribute` which is the name of the attribute (it can be either a string or an array of strings) to look for and `hit` which is the hit from Algolia. It returns an array of objects `{value: string, isHighlighted: boolean}`. If the element that corresponds to the attribute is an array of strings, it will return a nested array of objects.
28
- * @example
29
- * import React from 'react';
30
- * import algoliasearch from 'algoliasearch/lite';
31
- * import { InstantSearch, SearchBox, Hits, connectHighlight } from 'react-instantsearch-dom';
32
- *
33
- * const searchClient = algoliasearch(
34
- * 'latency',
35
- * '6be0576ff61c053d5f9a3225e2a90f76'
36
- * );
37
- *
38
- * const CustomHighlight = connectHighlight(
39
- * ({ highlight, attribute, hit, highlightProperty }) => {
40
- * const highlights = highlight({
41
- * highlightProperty: '_highlightResult',
42
- * attribute,
43
- * hit
44
- * });
45
- *
46
- * return highlights.map(part => part.isHighlighted ? (
47
- * <mark>{part.value}</mark>
48
- * ) : (
49
- * <span>{part.value}</span>
50
- * ));
51
- * }
52
- * );
53
- *
54
- * const Hit = ({ hit }) => (
55
- * <p>
56
- * <CustomHighlight attribute="name" hit={hit} />
57
- * </p>
58
- * );
59
- *
60
- * const App = () => (
61
- * <InstantSearch
62
- * searchClient={searchClient}
63
- * indexName="instant_search"
64
- * >
65
- * <SearchBox defaultRefinement="pho" />
66
- * <Hits hitComponent={Hit} />
67
- * </InstantSearch>
68
- * );
69
- */
70
- export default createConnector({
71
- displayName: 'AlgoliaHighlighter',
72
- $$type: 'ais.highlighter',
73
- propTypes: {},
74
- getProvidedProps: function getProvidedProps() {
75
- return {
76
- highlight: highlight
77
- };
78
- }
79
- });
@@ -1,69 +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 createConnector from "../core/createConnector.js";
8
- // @ts-ignore
9
- import { getResults } from "../core/indexUtils.js";
10
- function inferPayload(_ref) {
11
- var method = _ref.method,
12
- results = _ref.results,
13
- currentHit = _ref.currentHit;
14
- var index = results.index;
15
- var queryID = currentHit.__queryID;
16
- var objectIDs = [currentHit.objectID];
17
- if (!queryID) {
18
- throw new Error("Could not infer `queryID`. Ensure `clickAnalytics: true` was added with the Configure widget.\nSee: https://alg.li/VpPpLt");
19
- }
20
- switch (method) {
21
- case 'clickedObjectIDsAfterSearch':
22
- {
23
- var positions = [currentHit.__position];
24
- return {
25
- index: index,
26
- queryID: queryID,
27
- objectIDs: objectIDs,
28
- positions: positions
29
- };
30
- }
31
- case 'convertedObjectIDsAfterSearch':
32
- return {
33
- index: index,
34
- queryID: queryID,
35
- objectIDs: objectIDs
36
- };
37
- default:
38
- throw new Error("Unsupported method \"".concat(method, "\" passed to the insights function. The supported methods are: \"clickedObjectIDsAfterSearch\", \"convertedObjectIDsAfterSearch\"."));
39
- }
40
- }
41
- var wrapInsightsClient = function wrapInsightsClient(aa, results, currentHit) {
42
- return function (method, payload) {
43
- if (typeof aa !== 'function') {
44
- throw new TypeError("Expected insightsClient to be a Function");
45
- }
46
- var inferredPayload = inferPayload({
47
- method: method,
48
- results: results,
49
- currentHit: currentHit
50
- });
51
- aa(method, _objectSpread(_objectSpread({}, inferredPayload), payload));
52
- };
53
- };
54
- export default (function (insightsClient) {
55
- return createConnector({
56
- displayName: 'AlgoliaInsights',
57
- $$type: 'ais.insights',
58
- getProvidedProps: function getProvidedProps(props, _, searchResults) {
59
- var results = getResults(searchResults, {
60
- ais: props.contextValue,
61
- multiIndexContext: props.indexContextValue
62
- });
63
- var insights = wrapInsightsClient(insightsClient, results, props.hit);
64
- return {
65
- insights: insights
66
- };
67
- }
68
- });
69
- });
@@ -1,81 +0,0 @@
1
- import createConnector from "../core/createConnector.js";
2
- import { getResults } from "../core/indexUtils.js";
3
- import { addAbsolutePositions, addQueryID } from "../core/utils.js";
4
-
5
- /**
6
- * connectHits connector provides the logic to create connected
7
- * components that will render the results retrieved from
8
- * Algolia.
9
- *
10
- * To configure the number of hits retrieved, use [HitsPerPage widget](widgets/HitsPerPage.html),
11
- * [connectHitsPerPage connector](connectors/connectHitsPerPage.html) or pass the hitsPerPage
12
- * prop to a [Configure](guide/Search_parameters.html) widget.
13
- *
14
- * **Warning:** you will need to use the **objectID** property available on every hit as a key
15
- * when iterating over them. This will ensure you have the best possible UI experience
16
- * especially on slow networks.
17
- * @name connectHits
18
- * @kind connector
19
- * @providedPropType {array.<object>} hits - the records that matched the search state
20
- * @example
21
- * import React from 'react';
22
- * import algoliasearch from 'algoliasearch/lite';
23
- * import { InstantSearch, Highlight, connectHits } from 'react-instantsearch-dom';
24
- *
25
- * const searchClient = algoliasearch(
26
- * 'latency',
27
- * '6be0576ff61c053d5f9a3225e2a90f76'
28
- * );
29
- * const CustomHits = connectHits(({ hits }) => (
30
- * <div>
31
- * {hits.map(hit =>
32
- * <p key={hit.objectID}>
33
- * <Highlight attribute="name" hit={hit} />
34
- * </p>
35
- * )}
36
- * </div>
37
- * ));
38
- *
39
- * const App = () => (
40
- * <InstantSearch
41
- * searchClient={searchClient}
42
- * indexName="instant_search"
43
- * >
44
- * <CustomHits />
45
- * </InstantSearch>
46
- * );
47
- */
48
- export default createConnector({
49
- displayName: 'AlgoliaHits',
50
- $$type: 'ais.hits',
51
- getProvidedProps: function getProvidedProps(props, searchState, searchResults) {
52
- var results = getResults(searchResults, {
53
- ais: props.contextValue,
54
- multiIndexContext: props.indexContextValue
55
- });
56
- if (!results) {
57
- return {
58
- hits: []
59
- };
60
- }
61
- var hitsWithPositions = addAbsolutePositions(results.hits, results.hitsPerPage, results.page);
62
- var hitsWithPositionsAndQueryID = addQueryID(hitsWithPositions, results.queryID);
63
- return {
64
- hits: hitsWithPositionsAndQueryID
65
- };
66
- },
67
- /*
68
- * Hits needs to be considered as a widget to trigger a search,
69
- * even if no other widgets are used.
70
- *
71
- * To be considered as a widget you need either:
72
- * - getSearchParameters
73
- * - getMetadata
74
- * - transitionState
75
- *
76
- * See: createConnector.tsx
77
- */
78
- getSearchParameters: function getSearchParameters(searchParameters) {
79
- return searchParameters;
80
- }
81
- });
@@ -1,89 +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 'hitsPerPage';
12
- }
13
- function getCurrentRefinement(props, searchState, context) {
14
- var id = getId();
15
- var currentRefinement = getCurrentRefinementValue(props, searchState, context, id, null);
16
- if (typeof currentRefinement === 'string') {
17
- return parseInt(currentRefinement, 10);
18
- }
19
- return currentRefinement;
20
- }
21
-
22
- /**
23
- * connectHitsPerPage connector provides the logic to create connected
24
- * components that will allow a user to choose to display more or less results from Algolia.
25
- * @name connectHitsPerPage
26
- * @kind connector
27
- * @propType {number} defaultRefinement - The number of items selected by default
28
- * @propType {{value: number, label: string}[]} items - List of hits per page options.
29
- * @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.
30
- * @providedPropType {function} refine - a function to remove a single filter
31
- * @providedPropType {function} createURL - a function to generate a URL for the corresponding search state
32
- * @providedPropType {string} currentRefinement - the refinement currently applied
33
- * @providedPropType {array.<{isRefined: boolean, label?: string, value: number}>} items - the list of items the HitsPerPage can display. If no label provided, the value will be displayed.
34
- */
35
- export default createConnector({
36
- displayName: 'AlgoliaHitsPerPage',
37
- $$type: 'ais.hitsPerPage',
38
- propTypes: {
39
- defaultRefinement: PropTypes.number.isRequired,
40
- items: PropTypes.arrayOf(PropTypes.shape({
41
- label: PropTypes.string,
42
- value: PropTypes.number.isRequired
43
- })).isRequired,
44
- transformItems: PropTypes.func
45
- },
46
- getProvidedProps: function getProvidedProps(props, searchState) {
47
- var currentRefinement = getCurrentRefinement(props, searchState, {
48
- ais: props.contextValue,
49
- multiIndexContext: props.indexContextValue
50
- });
51
- var items = props.items.map(function (item) {
52
- return item.value === currentRefinement ? _objectSpread(_objectSpread({}, item), {}, {
53
- isRefined: true
54
- }) : _objectSpread(_objectSpread({}, item), {}, {
55
- isRefined: false
56
- });
57
- });
58
- return {
59
- items: props.transformItems ? props.transformItems(items) : items,
60
- currentRefinement: currentRefinement
61
- };
62
- },
63
- refine: function refine(props, searchState, nextRefinement) {
64
- var id = getId();
65
- var nextValue = _defineProperty({}, id, nextRefinement);
66
- var resetPage = true;
67
- return refineValue(searchState, nextValue, {
68
- ais: props.contextValue,
69
- multiIndexContext: props.indexContextValue
70
- }, resetPage);
71
- },
72
- cleanUp: function cleanUp(props, searchState) {
73
- return cleanUpValue(searchState, {
74
- ais: props.contextValue,
75
- multiIndexContext: props.indexContextValue
76
- }, getId());
77
- },
78
- getSearchParameters: function getSearchParameters(searchParameters, props, searchState) {
79
- return searchParameters.setHitsPerPage(getCurrentRefinement(props, searchState, {
80
- ais: props.contextValue,
81
- multiIndexContext: props.indexContextValue
82
- }));
83
- },
84
- getMetadata: function getMetadata() {
85
- return {
86
- id: getId()
87
- };
88
- }
89
- });