instantsearch.js 4.49.0 → 4.49.2

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 (376) hide show
  1. package/README.md +3 -3
  2. package/cjs/components/Answers/Answers.js +6 -16
  3. package/cjs/components/Breadcrumb/Breadcrumb.js +5 -12
  4. package/cjs/components/ClearRefinements/ClearRefinements.js +4 -11
  5. package/cjs/components/CurrentRefinements/CurrentRefinements.js +5 -12
  6. package/cjs/components/GeoSearchControls/GeoSearchButton.js +4 -6
  7. package/cjs/components/GeoSearchControls/GeoSearchControls.js +11 -20
  8. package/cjs/components/GeoSearchControls/GeoSearchToggle.js +4 -6
  9. package/cjs/components/Highlight/Highlight.js +3 -11
  10. package/cjs/components/Hits/Hits.js +8 -20
  11. package/cjs/components/InfiniteHits/InfiniteHits.js +13 -25
  12. package/cjs/components/InternalHighlight/InternalHighlight.js +0 -3
  13. package/cjs/components/MenuSelect/MenuSelect.js +9 -19
  14. package/cjs/components/Pagination/Pagination.js +10 -17
  15. package/cjs/components/Panel/Panel.js +7 -26
  16. package/cjs/components/PoweredBy/PoweredBy.js +4 -5
  17. package/cjs/components/QueryRuleCustomData/QueryRuleCustomData.js +2 -6
  18. package/cjs/components/RangeInput/RangeInput.js +16 -48
  19. package/cjs/components/RefinementList/RefinementList.js +19 -73
  20. package/cjs/components/RefinementList/RefinementListItem.js +8 -14
  21. package/cjs/components/RelevantSort/RelevantSort.js +4 -8
  22. package/cjs/components/ReverseHighlight/ReverseHighlight.js +3 -11
  23. package/cjs/components/ReverseSnippet/ReverseSnippet.js +3 -11
  24. package/cjs/components/SearchBox/SearchBox.js +25 -69
  25. package/cjs/components/Selector/Selector.js +3 -6
  26. package/cjs/components/Slider/Pit.js +3 -10
  27. package/cjs/components/Slider/Rheostat.js +63 -131
  28. package/cjs/components/Slider/Slider.js +28 -65
  29. package/cjs/components/Snippet/Snippet.js +3 -11
  30. package/cjs/components/Stats/Stats.js +7 -20
  31. package/cjs/components/Template/Template.js +8 -37
  32. package/cjs/components/ToggleRefinement/ToggleRefinement.js +4 -10
  33. package/cjs/components/VoiceSearch/VoiceSearch.js +8 -15
  34. package/cjs/connectors/answers/connectAnswers.js +21 -36
  35. package/cjs/connectors/autocomplete/connectAutocomplete.js +8 -25
  36. package/cjs/connectors/breadcrumb/connectBreadcrumb.js +17 -48
  37. package/cjs/connectors/clear-refinements/connectClearRefinements.js +27 -45
  38. package/cjs/connectors/configure/connectConfigure.js +6 -20
  39. package/cjs/connectors/configure-related-items/connectConfigureRelatedItems.js +11 -36
  40. package/cjs/connectors/current-refinements/connectCurrentRefinements.js +18 -57
  41. package/cjs/connectors/dynamic-widgets/connectDynamicWidgets.js +17 -37
  42. package/cjs/connectors/geo-search/connectGeoSearch.js +17 -47
  43. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +38 -74
  44. package/cjs/connectors/hits/connectHits.js +10 -26
  45. package/cjs/connectors/hits/connectHitsWithInsights.js +0 -4
  46. package/cjs/connectors/hits-per-page/connectHitsPerPage.js +15 -38
  47. package/cjs/connectors/index.js +62 -96
  48. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +26 -62
  49. package/cjs/connectors/infinite-hits/connectInfiniteHitsWithInsights.js +0 -4
  50. package/cjs/connectors/menu/connectMenu.js +28 -66
  51. package/cjs/connectors/numeric-menu/connectNumericMenu.js +24 -78
  52. package/cjs/connectors/pagination/Paginator.js +3 -20
  53. package/cjs/connectors/pagination/connectPagination.js +8 -25
  54. package/cjs/connectors/powered-by/connectPoweredBy.js +4 -13
  55. package/cjs/connectors/query-rules/connectQueryRules.js +32 -56
  56. package/cjs/connectors/range/connectRange.js +41 -101
  57. package/cjs/connectors/rating-menu/connectRatingMenu.js +23 -79
  58. package/cjs/connectors/refinement-list/connectRefinementList.js +37 -70
  59. package/cjs/connectors/relevant-sort/connectRelevantSort.js +4 -14
  60. package/cjs/connectors/search-box/connectSearchBox.js +7 -23
  61. package/cjs/connectors/sort-by/connectSortBy.js +11 -21
  62. package/cjs/connectors/stats/connectStats.js +4 -11
  63. package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +29 -63
  64. package/cjs/connectors/voice-search/connectVoiceSearch.js +13 -35
  65. package/cjs/helpers/components/Highlight.js +4 -12
  66. package/cjs/helpers/components/ReverseHighlight.js +7 -19
  67. package/cjs/helpers/components/ReverseSnippet.js +7 -19
  68. package/cjs/helpers/components/Snippet.js +4 -12
  69. package/cjs/helpers/components/index.js +0 -8
  70. package/cjs/helpers/get-insights-anonymous-user-token.js +7 -12
  71. package/cjs/helpers/highlight.js +10 -16
  72. package/cjs/helpers/index.js +17 -31
  73. package/cjs/helpers/insights.js +5 -17
  74. package/cjs/helpers/reverseHighlight.js +10 -16
  75. package/cjs/helpers/reverseSnippet.js +10 -16
  76. package/cjs/helpers/snippet.js +10 -16
  77. package/cjs/index.js +3 -18
  78. package/cjs/lib/InstantSearch.js +79 -180
  79. package/cjs/lib/createHelpers.js +4 -11
  80. package/cjs/lib/formatNumber.js +0 -1
  81. package/cjs/lib/infiniteHitsCache/index.js +0 -2
  82. package/cjs/lib/infiniteHitsCache/sessionStorage.js +9 -18
  83. package/cjs/lib/insights/client.js +8 -34
  84. package/cjs/lib/insights/index.js +7 -13
  85. package/cjs/lib/insights/listener.js +4 -20
  86. package/cjs/lib/routers/history.js +63 -102
  87. package/cjs/lib/routers/index.js +0 -2
  88. package/cjs/lib/stateMappings/index.js +0 -3
  89. package/cjs/lib/stateMappings/simple.js +6 -13
  90. package/cjs/lib/stateMappings/singleIndex.js +1 -7
  91. package/cjs/lib/suit.js +2 -5
  92. package/cjs/lib/templating/index.js +0 -4
  93. package/cjs/lib/templating/prepareTemplateProps.js +8 -19
  94. package/cjs/lib/templating/renderTemplate.js +9 -24
  95. package/cjs/lib/utils/capitalize.js +0 -1
  96. package/cjs/lib/utils/checkIndexUiState.js +15 -43
  97. package/cjs/lib/utils/checkRendering.js +0 -2
  98. package/cjs/lib/utils/clearRefinements.js +2 -9
  99. package/cjs/lib/utils/concatHighlightedParts.js +1 -3
  100. package/cjs/lib/utils/createConcurrentSafePromise.js +0 -3
  101. package/cjs/lib/utils/createSendEventForFacet.js +7 -14
  102. package/cjs/lib/utils/createSendEventForHits.js +9 -33
  103. package/cjs/lib/utils/debounce.js +0 -3
  104. package/cjs/lib/utils/defer.js +0 -11
  105. package/cjs/lib/utils/detect-insights-client.js +0 -2
  106. package/cjs/lib/utils/documentation.js +2 -5
  107. package/cjs/lib/utils/escape-highlight.js +5 -22
  108. package/cjs/lib/utils/escape-html.js +9 -7
  109. package/cjs/lib/utils/escapeFacetValue.js +1 -5
  110. package/cjs/lib/utils/find.js +2 -5
  111. package/cjs/lib/utils/findIndex.js +0 -3
  112. package/cjs/lib/utils/geo-search.js +14 -34
  113. package/cjs/lib/utils/getAppIdAndApiKey.js +2 -3
  114. package/cjs/lib/utils/getContainerNode.js +0 -6
  115. package/cjs/lib/utils/getHighlightFromSiblings.js +0 -6
  116. package/cjs/lib/utils/getHighlightedParts.js +1 -4
  117. package/cjs/lib/utils/getObjectType.js +0 -1
  118. package/cjs/lib/utils/getPropertyByPath.js +0 -1
  119. package/cjs/lib/utils/getRefinements.js +13 -26
  120. package/cjs/lib/utils/getWidgetAttribute.js +0 -6
  121. package/cjs/lib/utils/hits-absolute-position.js +2 -6
  122. package/cjs/lib/utils/hits-query-id.js +2 -7
  123. package/cjs/lib/utils/index.js +0 -92
  124. package/cjs/lib/utils/isDomElement.js +0 -1
  125. package/cjs/lib/utils/isEqual.js +0 -8
  126. package/cjs/lib/utils/isFacetRefined.js +0 -1
  127. package/cjs/lib/utils/isFiniteNumber.js +0 -1
  128. package/cjs/lib/utils/isIndexWidget.js +0 -1
  129. package/cjs/lib/utils/isPlainObject.js +3 -11
  130. package/cjs/lib/utils/isSpecialClick.js +0 -1
  131. package/cjs/lib/utils/logger.js +3 -13
  132. package/cjs/lib/utils/mergeSearchParameters.js +16 -40
  133. package/cjs/lib/utils/noop.js +0 -1
  134. package/cjs/lib/utils/range.js +8 -14
  135. package/cjs/lib/utils/render-args.js +0 -2
  136. package/cjs/lib/utils/resolveSearchParameters.js +0 -3
  137. package/cjs/lib/utils/reverseHighlightedParts.js +2 -8
  138. package/cjs/lib/utils/safelyRunOnBrowser.js +7 -9
  139. package/cjs/lib/utils/serializer.js +1 -3
  140. package/cjs/lib/utils/setIndexHelperState.js +0 -5
  141. package/cjs/lib/utils/toArray.js +0 -1
  142. package/cjs/lib/utils/typedObject.js +0 -1
  143. package/cjs/lib/utils/uniq.js +0 -1
  144. package/cjs/lib/version.js +1 -1
  145. package/cjs/lib/voiceSearchHelper/index.js +8 -36
  146. package/cjs/middlewares/createInsightsMiddleware.js +15 -44
  147. package/cjs/middlewares/createMetadataMiddleware.js +4 -12
  148. package/cjs/middlewares/createRouterMiddleware.js +8 -19
  149. package/cjs/middlewares/index.js +0 -6
  150. package/cjs/types/algoliasearch.js +0 -2
  151. package/cjs/types/index.js +0 -28
  152. package/cjs/widgets/analytics/analytics.js +12 -47
  153. package/cjs/widgets/answers/answers.js +19 -39
  154. package/cjs/widgets/breadcrumb/breadcrumb.js +18 -38
  155. package/cjs/widgets/clear-refinements/clear-refinements.js +15 -35
  156. package/cjs/widgets/configure/configure.js +2 -10
  157. package/cjs/widgets/configure-related-items/configure-related-items.js +2 -10
  158. package/cjs/widgets/current-refinements/current-refinements.js +12 -30
  159. package/cjs/widgets/dynamic-widgets/dynamic-widgets.js +6 -25
  160. package/cjs/widgets/geo-search/GeoSearchRenderer.js +41 -68
  161. package/cjs/widgets/geo-search/createHTMLMarker.js +30 -60
  162. package/cjs/widgets/geo-search/defaultTemplates.js +0 -3
  163. package/cjs/widgets/geo-search/geo-search.js +27 -59
  164. package/cjs/widgets/hierarchical-menu/defaultTemplates.js +4 -7
  165. package/cjs/widgets/hierarchical-menu/hierarchical-menu.js +28 -47
  166. package/cjs/widgets/hits/hits.js +16 -37
  167. package/cjs/widgets/hits-per-page/hits-per-page.js +13 -31
  168. package/cjs/widgets/index/index.js +49 -95
  169. package/cjs/widgets/index.js +12 -50
  170. package/cjs/widgets/infinite-hits/infinite-hits.js +23 -44
  171. package/cjs/widgets/menu/defaultTemplates.js +3 -6
  172. package/cjs/widgets/menu/menu.js +23 -43
  173. package/cjs/widgets/menu-select/defaultTemplates.js +1 -3
  174. package/cjs/widgets/menu-select/menu-select.js +18 -38
  175. package/cjs/widgets/numeric-menu/defaultTemplates.js +3 -4
  176. package/cjs/widgets/numeric-menu/numeric-menu.js +17 -37
  177. package/cjs/widgets/pagination/pagination.js +32 -53
  178. package/cjs/widgets/panel/panel.js +20 -48
  179. package/cjs/widgets/places/places.js +16 -33
  180. package/cjs/widgets/powered-by/powered-by.js +10 -27
  181. package/cjs/widgets/query-rule-context/query-rule-context.js +2 -13
  182. package/cjs/widgets/query-rule-custom-data/query-rule-custom-data.js +14 -32
  183. package/cjs/widgets/range-input/range-input.js +23 -50
  184. package/cjs/widgets/range-slider/range-slider.js +28 -53
  185. package/cjs/widgets/rating-menu/defaultTemplates.js +8 -14
  186. package/cjs/widgets/rating-menu/rating-menu.js +17 -38
  187. package/cjs/widgets/refinement-list/defaultTemplates.js +5 -8
  188. package/cjs/widgets/refinement-list/refinement-list.js +39 -60
  189. package/cjs/widgets/relevant-sort/relevant-sort.js +10 -29
  190. package/cjs/widgets/search-box/defaultTemplates.js +0 -5
  191. package/cjs/widgets/search-box/search-box.js +31 -49
  192. package/cjs/widgets/sort-by/sort-by.js +11 -29
  193. package/cjs/widgets/stats/defaultTemplates.js +0 -1
  194. package/cjs/widgets/stats/stats.js +27 -57
  195. package/cjs/widgets/toggle-refinement/toggle-refinement.js +16 -36
  196. package/cjs/widgets/voice-search/defaultTemplates.js +4 -14
  197. package/cjs/widgets/voice-search/voice-search.js +17 -36
  198. package/dist/instantsearch.development.d.ts +8 -6
  199. package/dist/instantsearch.development.js +1725 -3087
  200. package/dist/instantsearch.development.js.map +1 -1
  201. package/dist/instantsearch.production.d.ts +8 -6
  202. package/dist/instantsearch.production.min.d.ts +8 -6
  203. package/dist/instantsearch.production.min.js +2 -2
  204. package/dist/instantsearch.production.min.js.map +1 -1
  205. package/es/components/Answers/Answers.js +6 -11
  206. package/es/components/Breadcrumb/Breadcrumb.js +5 -7
  207. package/es/components/ClearRefinements/ClearRefinements.js +4 -6
  208. package/es/components/CurrentRefinements/CurrentRefinements.js +7 -10
  209. package/es/components/GeoSearchControls/GeoSearchButton.js +6 -6
  210. package/es/components/GeoSearchControls/GeoSearchControls.js +11 -13
  211. package/es/components/GeoSearchControls/GeoSearchToggle.js +6 -6
  212. package/es/components/Highlight/Highlight.js +3 -7
  213. package/es/components/Hits/Hits.js +8 -15
  214. package/es/components/InfiniteHits/InfiniteHits.js +13 -20
  215. package/es/components/MenuSelect/MenuSelect.js +9 -13
  216. package/es/components/Pagination/Pagination.js +12 -15
  217. package/es/components/Panel/Panel.js +7 -20
  218. package/es/components/PoweredBy/PoweredBy.js +6 -5
  219. package/es/components/QueryRuleCustomData/QueryRuleCustomData.js +4 -4
  220. package/es/components/RangeInput/RangeInput.js +16 -43
  221. package/es/components/RefinementList/RefinementList.js +19 -64
  222. package/es/components/RefinementList/RefinementListItem.js +8 -10
  223. package/es/components/RelevantSort/RelevantSort.js +6 -6
  224. package/es/components/ReverseHighlight/ReverseHighlight.js +3 -7
  225. package/es/components/ReverseSnippet/ReverseSnippet.js +3 -7
  226. package/es/components/SearchBox/SearchBox.js +25 -63
  227. package/es/components/Selector/Selector.js +5 -5
  228. package/es/components/Slider/Pit.js +3 -7
  229. package/es/components/Slider/Rheostat.js +64 -129
  230. package/es/components/Slider/Slider.js +28 -58
  231. package/es/components/Snippet/Snippet.js +3 -7
  232. package/es/components/Stats/Stats.js +7 -15
  233. package/es/components/Template/Template.js +8 -32
  234. package/es/components/ToggleRefinement/ToggleRefinement.js +4 -6
  235. package/es/components/VoiceSearch/VoiceSearch.js +10 -13
  236. package/es/connectors/answers/connectAnswers.js +21 -35
  237. package/es/connectors/autocomplete/connectAutocomplete.js +8 -23
  238. package/es/connectors/breadcrumb/connectBreadcrumb.js +17 -46
  239. package/es/connectors/clear-refinements/connectClearRefinements.js +27 -43
  240. package/es/connectors/configure/connectConfigure.js +7 -16
  241. package/es/connectors/configure-related-items/connectConfigureRelatedItems.js +11 -31
  242. package/es/connectors/current-refinements/connectCurrentRefinements.js +18 -55
  243. package/es/connectors/dynamic-widgets/connectDynamicWidgets.js +17 -35
  244. package/es/connectors/geo-search/connectGeoSearch.js +17 -45
  245. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +38 -72
  246. package/es/connectors/hits/connectHits.js +10 -24
  247. package/es/connectors/hits-per-page/connectHitsPerPage.js +15 -36
  248. package/es/connectors/index.d.ts +2 -1
  249. package/es/connectors/index.js +6 -3
  250. package/es/connectors/infinite-hits/connectInfiniteHits.js +26 -60
  251. package/es/connectors/menu/connectMenu.js +28 -64
  252. package/es/connectors/numeric-menu/connectNumericMenu.js +24 -76
  253. package/es/connectors/pagination/Paginator.js +3 -19
  254. package/es/connectors/pagination/connectPagination.js +8 -21
  255. package/es/connectors/powered-by/connectPoweredBy.js +4 -11
  256. package/es/connectors/query-rules/connectQueryRules.js +32 -54
  257. package/es/connectors/range/connectRange.js +41 -99
  258. package/es/connectors/rating-menu/connectRatingMenu.js +23 -77
  259. package/es/connectors/refinement-list/connectRefinementList.js +37 -68
  260. package/es/connectors/relevant-sort/connectRelevantSort.js +4 -13
  261. package/es/connectors/search-box/connectSearchBox.js +7 -21
  262. package/es/connectors/sort-by/connectSortBy.js +11 -19
  263. package/es/connectors/stats/connectStats.js +4 -9
  264. package/es/connectors/toggle-refinement/connectToggleRefinement.js +29 -61
  265. package/es/connectors/voice-search/connectVoiceSearch.js +13 -31
  266. package/es/helpers/components/Highlight.js +4 -8
  267. package/es/helpers/components/ReverseHighlight.js +7 -15
  268. package/es/helpers/components/ReverseSnippet.js +7 -15
  269. package/es/helpers/components/Snippet.js +4 -8
  270. package/es/helpers/get-insights-anonymous-user-token.js +5 -7
  271. package/es/helpers/highlight.js +9 -11
  272. package/es/helpers/insights.js +3 -10
  273. package/es/helpers/reverseHighlight.js +9 -11
  274. package/es/helpers/reverseSnippet.js +9 -11
  275. package/es/helpers/snippet.js +9 -11
  276. package/es/index.js +0 -2
  277. package/es/lib/InstantSearch.js +79 -170
  278. package/es/lib/createHelpers.js +4 -8
  279. package/es/lib/infiniteHitsCache/sessionStorage.js +9 -16
  280. package/es/lib/insights/client.js +8 -32
  281. package/es/lib/insights/listener.js +6 -18
  282. package/es/lib/routers/history.js +63 -99
  283. package/es/lib/stateMappings/simple.js +6 -12
  284. package/es/lib/stateMappings/singleIndex.js +1 -6
  285. package/es/lib/suit.js +2 -3
  286. package/es/lib/templating/prepareTemplateProps.js +8 -18
  287. package/es/lib/templating/renderTemplate.js +9 -20
  288. package/es/lib/utils/checkIndexUiState.js +18 -40
  289. package/es/lib/utils/clearRefinements.js +2 -8
  290. package/es/lib/utils/concatHighlightedParts.js +1 -1
  291. package/es/lib/utils/createConcurrentSafePromise.js +0 -2
  292. package/es/lib/utils/createSendEventForFacet.js +7 -12
  293. package/es/lib/utils/createSendEventForHits.js +8 -30
  294. package/es/lib/utils/debounce.js +0 -2
  295. package/es/lib/utils/defer.js +0 -10
  296. package/es/lib/utils/documentation.js +2 -3
  297. package/es/lib/utils/escape-highlight.js +3 -16
  298. package/es/lib/utils/escape-html.js +9 -5
  299. package/es/lib/utils/escapeFacetValue.js +0 -2
  300. package/es/lib/utils/find.js +2 -4
  301. package/es/lib/utils/findIndex.js +0 -2
  302. package/es/lib/utils/geo-search.js +14 -32
  303. package/es/lib/utils/getAppIdAndApiKey.js +2 -2
  304. package/es/lib/utils/getContainerNode.js +1 -5
  305. package/es/lib/utils/getHighlightFromSiblings.js +0 -3
  306. package/es/lib/utils/getHighlightedParts.js +1 -2
  307. package/es/lib/utils/getRefinements.js +13 -24
  308. package/es/lib/utils/getWidgetAttribute.js +0 -5
  309. package/es/lib/utils/hits-absolute-position.js +2 -5
  310. package/es/lib/utils/hits-query-id.js +2 -6
  311. package/es/lib/utils/isEqual.js +0 -7
  312. package/es/lib/utils/isPlainObject.js +3 -10
  313. package/es/lib/utils/logger.js +2 -12
  314. package/es/lib/utils/mergeSearchParameters.js +16 -37
  315. package/es/lib/utils/range.js +8 -13
  316. package/es/lib/utils/resolveSearchParameters.js +0 -2
  317. package/es/lib/utils/reverseHighlightedParts.js +2 -6
  318. package/es/lib/utils/safelyRunOnBrowser.js +7 -8
  319. package/es/lib/utils/setIndexHelperState.js +0 -2
  320. package/es/lib/version.d.ts +1 -1
  321. package/es/lib/version.js +1 -1
  322. package/es/lib/voiceSearchHelper/index.js +8 -35
  323. package/es/middlewares/createInsightsMiddleware.js +15 -41
  324. package/es/middlewares/createMetadataMiddleware.js +3 -9
  325. package/es/middlewares/createRouterMiddleware.js +8 -13
  326. package/es/types/index.js +9 -5
  327. package/es/widgets/analytics/analytics.js +12 -45
  328. package/es/widgets/answers/answers.js +19 -28
  329. package/es/widgets/breadcrumb/breadcrumb.js +18 -27
  330. package/es/widgets/clear-refinements/clear-refinements.js +15 -24
  331. package/es/widgets/configure/configure.js +3 -6
  332. package/es/widgets/configure-related-items/configure-related-items.js +2 -7
  333. package/es/widgets/current-refinements/current-refinements.js +12 -21
  334. package/es/widgets/dynamic-widgets/dynamic-widgets.js +6 -20
  335. package/es/widgets/geo-search/GeoSearchRenderer.js +41 -63
  336. package/es/widgets/geo-search/createHTMLMarker.js +30 -59
  337. package/es/widgets/geo-search/defaultTemplates.js +2 -2
  338. package/es/widgets/geo-search/geo-search.js +27 -49
  339. package/es/widgets/hierarchical-menu/defaultTemplates.js +5 -4
  340. package/es/widgets/hierarchical-menu/hierarchical-menu.js +28 -36
  341. package/es/widgets/hits/hits.js +16 -25
  342. package/es/widgets/hits-per-page/hits-per-page.js +13 -22
  343. package/es/widgets/index/index.js +49 -91
  344. package/es/widgets/index.d.ts +2 -1
  345. package/es/widgets/index.js +4 -3
  346. package/es/widgets/infinite-hits/infinite-hits.js +23 -32
  347. package/es/widgets/menu/defaultTemplates.js +4 -3
  348. package/es/widgets/menu/menu.js +23 -32
  349. package/es/widgets/menu-select/defaultTemplates.js +1 -1
  350. package/es/widgets/menu-select/menu-select.js +18 -27
  351. package/es/widgets/numeric-menu/defaultTemplates.js +4 -3
  352. package/es/widgets/numeric-menu/numeric-menu.js +17 -26
  353. package/es/widgets/pagination/pagination.js +32 -44
  354. package/es/widgets/panel/panel.js +20 -40
  355. package/es/widgets/places/places.js +16 -32
  356. package/es/widgets/powered-by/powered-by.js +10 -18
  357. package/es/widgets/query-rule-context/query-rule-context.js +2 -9
  358. package/es/widgets/query-rule-custom-data/query-rule-custom-data.js +13 -22
  359. package/es/widgets/range-input/range-input.js +23 -40
  360. package/es/widgets/range-slider/range-slider.js +28 -44
  361. package/es/widgets/rating-menu/defaultTemplates.js +9 -12
  362. package/es/widgets/rating-menu/rating-menu.js +17 -27
  363. package/es/widgets/refinement-list/defaultTemplates.js +6 -5
  364. package/es/widgets/refinement-list/refinement-list.js +39 -48
  365. package/es/widgets/relevant-sort/relevant-sort.js +10 -19
  366. package/es/widgets/search-box/defaultTemplates.js +1 -4
  367. package/es/widgets/search-box/search-box.js +31 -39
  368. package/es/widgets/sort-by/sort-by.js +11 -20
  369. package/es/widgets/stats/stats.js +26 -45
  370. package/es/widgets/toggle-refinement/toggle-refinement.js +16 -25
  371. package/es/widgets/voice-search/defaultTemplates.js +5 -13
  372. package/es/widgets/voice-search/voice-search.js +17 -26
  373. package/package.json +20 -119
  374. package/scripts/transforms/__testfixtures__/addWidget-to-addWidgets/imported.input.js +0 -1
  375. package/scripts/transforms/__testfixtures__/addWidget-to-addWidgets/imported.output.js +0 -1
  376. package/CHANGELOG.md +0 -3684
@@ -1,31 +1,17 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
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; }
7
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
5
  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, descriptor.key, descriptor); } }
10
-
11
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
12
-
13
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
-
15
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
-
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ 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); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
17
9
  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); }; }
18
-
19
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
20
-
10
+ 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); }
21
11
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
22
-
23
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
24
-
25
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
-
12
+ 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; } }
13
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
27
14
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
-
29
15
  import algoliasearchHelper from 'algoliasearch-helper';
30
16
  import EventEmitter from '@algolia/events';
31
17
  import index from "../widgets/index/index.js";
@@ -37,14 +23,13 @@ import { createMetadataMiddleware, isMetadataEnabled } from "../middlewares/crea
37
23
  var withUsage = createDocumentationMessageGenerator({
38
24
  name: 'instantsearch'
39
25
  });
40
-
41
26
  function defaultCreateURL() {
42
27
  return '#';
43
- } // this purposely breaks typescript's type inference to ensure it's not used
28
+ }
29
+
30
+ // this purposely breaks typescript's type inference to ensure it's not used
44
31
  // as it's used for a default parameter for example
45
32
  // source: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546
46
-
47
-
48
33
  /**
49
34
  * The actual implementation of the InstantSearch. This is
50
35
  * created using the `instantsearch` factory function.
@@ -52,87 +37,56 @@ function defaultCreateURL() {
52
37
  */
53
38
  var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
54
39
  _inherits(InstantSearch, _EventEmitter);
55
-
56
40
  var _super = _createSuper(InstantSearch);
57
-
58
41
  function InstantSearch(options) {
59
42
  var _this;
60
-
61
43
  _classCallCheck(this, InstantSearch);
44
+ _this = _super.call(this);
62
45
 
63
- _this = _super.call(this); // prevent `render` event listening from causing a warning
64
-
46
+ // prevent `render` event listening from causing a warning
65
47
  _defineProperty(_assertThisInitialized(_this), "client", void 0);
66
-
67
48
  _defineProperty(_assertThisInitialized(_this), "indexName", void 0);
68
-
69
49
  _defineProperty(_assertThisInitialized(_this), "insightsClient", void 0);
70
-
71
50
  _defineProperty(_assertThisInitialized(_this), "onStateChange", null);
72
-
73
51
  _defineProperty(_assertThisInitialized(_this), "helper", void 0);
74
-
75
52
  _defineProperty(_assertThisInitialized(_this), "mainHelper", void 0);
76
-
77
53
  _defineProperty(_assertThisInitialized(_this), "mainIndex", void 0);
78
-
79
54
  _defineProperty(_assertThisInitialized(_this), "started", void 0);
80
-
81
55
  _defineProperty(_assertThisInitialized(_this), "templatesConfig", void 0);
82
-
83
56
  _defineProperty(_assertThisInitialized(_this), "renderState", {});
84
-
85
57
  _defineProperty(_assertThisInitialized(_this), "_stalledSearchDelay", void 0);
86
-
87
58
  _defineProperty(_assertThisInitialized(_this), "_searchStalledTimer", void 0);
88
-
89
59
  _defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
90
-
91
60
  _defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
92
-
93
61
  _defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
94
-
95
62
  _defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
96
-
97
63
  _defineProperty(_assertThisInitialized(_this), "_mainHelperSearch", void 0);
98
-
99
64
  _defineProperty(_assertThisInitialized(_this), "middleware", []);
100
-
101
65
  _defineProperty(_assertThisInitialized(_this), "sendEventToInsights", void 0);
102
-
103
66
  _defineProperty(_assertThisInitialized(_this), "status", 'idle');
104
-
105
67
  _defineProperty(_assertThisInitialized(_this), "error", undefined);
106
-
107
68
  _defineProperty(_assertThisInitialized(_this), "scheduleSearch", defer(function () {
108
69
  if (_this.started) {
109
70
  _this.mainHelper.search();
110
71
  }
111
72
  }));
112
-
113
73
  _defineProperty(_assertThisInitialized(_this), "scheduleRender", defer(function () {
114
74
  var shouldResetStatus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
115
-
116
75
  if (!_this.mainHelper.hasPendingRequests()) {
117
76
  clearTimeout(_this._searchStalledTimer);
118
77
  _this._searchStalledTimer = null;
119
-
120
78
  if (shouldResetStatus) {
121
79
  _this.status = 'idle';
122
80
  _this.error = undefined;
123
81
  }
124
82
  }
125
-
126
83
  _this.mainIndex.render({
127
84
  instantSearchInstance: _assertThisInitialized(_this)
128
85
  });
129
-
130
86
  _this.emit('render');
131
87
  }));
132
-
133
88
  _defineProperty(_assertThisInitialized(_this), "onInternalStateChange", defer(function () {
134
89
  var nextUiState = _this.mainIndex.getWidgetUiState({});
135
-
136
90
  _this.middleware.forEach(function (_ref) {
137
91
  var instance = _ref.instance;
138
92
  instance.onStateChange({
@@ -140,48 +94,39 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
140
94
  });
141
95
  });
142
96
  }));
143
-
144
97
  _this.setMaxListeners(100);
145
-
146
98
  var _options$indexName = options.indexName,
147
- indexName = _options$indexName === void 0 ? null : _options$indexName,
148
- numberLocale = options.numberLocale,
149
- _options$initialUiSta = options.initialUiState,
150
- initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
151
- _options$routing = options.routing,
152
- routing = _options$routing === void 0 ? null : _options$routing,
153
- searchFunction = options.searchFunction,
154
- _options$stalledSearc = options.stalledSearchDelay,
155
- stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
156
- _options$searchClient = options.searchClient,
157
- searchClient = _options$searchClient === void 0 ? null : _options$searchClient,
158
- _options$insightsClie = options.insightsClient,
159
- insightsClient = _options$insightsClie === void 0 ? null : _options$insightsClie,
160
- _options$onStateChang = options.onStateChange,
161
- onStateChange = _options$onStateChang === void 0 ? null : _options$onStateChang;
162
-
99
+ indexName = _options$indexName === void 0 ? null : _options$indexName,
100
+ numberLocale = options.numberLocale,
101
+ _options$initialUiSta = options.initialUiState,
102
+ initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
103
+ _options$routing = options.routing,
104
+ routing = _options$routing === void 0 ? null : _options$routing,
105
+ searchFunction = options.searchFunction,
106
+ _options$stalledSearc = options.stalledSearchDelay,
107
+ stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
108
+ _options$searchClient = options.searchClient,
109
+ searchClient = _options$searchClient === void 0 ? null : _options$searchClient,
110
+ _options$insightsClie = options.insightsClient,
111
+ insightsClient = _options$insightsClie === void 0 ? null : _options$insightsClie,
112
+ _options$onStateChang = options.onStateChange,
113
+ onStateChange = _options$onStateChang === void 0 ? null : _options$onStateChang;
163
114
  if (indexName === null) {
164
115
  throw new Error(withUsage('The `indexName` option is required.'));
165
116
  }
166
-
167
117
  if (searchClient === null) {
168
118
  throw new Error(withUsage('The `searchClient` option is required.'));
169
119
  }
170
-
171
120
  if (typeof searchClient.search !== 'function') {
172
121
  throw new Error("The `searchClient` must implement a `search` method.\n\nSee: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend-search/in-depth/backend-instantsearch/js/");
173
122
  }
174
-
175
123
  if (typeof searchClient.addAlgoliaAgent === 'function') {
176
124
  searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
177
125
  }
178
-
179
126
  process.env.NODE_ENV === 'development' ? warning(insightsClient === null, "`insightsClient` property has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the `insights` middleware.\n\nFor more information, visit https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/how-to/send-click-and-conversion-events-with-instantsearch/js/") : void 0;
180
-
181
127
  if (insightsClient && typeof insightsClient !== 'function') {
182
128
  throw new Error(withUsage('The `insightsClient` option should be a function.'));
183
129
  }
184
-
185
130
  process.env.NODE_ENV === 'development' ? warning(!options.searchParameters, "The `searchParameters` option is deprecated and will not be supported in InstantSearch.js 4.x.\n\nYou can replace it with the `configure` widget:\n\n```\nsearch.addWidgets([\n configure(".concat(JSON.stringify(options.searchParameters, null, 2), ")\n]);\n```\n\nSee ").concat(createDocumentationLink({
186
131
  name: 'configure'
187
132
  }))) : void 0;
@@ -206,30 +151,23 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
206
151
  _this._createURL = defaultCreateURL;
207
152
  _this._initialUiState = initialUiState;
208
153
  _this._initialResults = null;
209
-
210
154
  if (searchFunction) {
211
155
  _this._searchFunction = searchFunction;
212
156
  }
213
-
214
157
  _this.sendEventToInsights = noop;
215
-
216
158
  if (routing) {
217
159
  var routerOptions = typeof routing === 'boolean' ? undefined : routing;
218
-
219
160
  _this.use(createRouterMiddleware(routerOptions));
220
161
  }
221
-
222
162
  if (isMetadataEnabled()) {
223
163
  _this.use(createMetadataMiddleware());
224
164
  }
225
-
226
165
  return _this;
227
166
  }
167
+
228
168
  /**
229
169
  * Hooks a middleware into the InstantSearch lifecycle.
230
170
  */
231
-
232
-
233
171
  _createClass(InstantSearch, [{
234
172
  key: "_isSearchStalled",
235
173
  get:
@@ -253,11 +191,9 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
253
191
  key: "use",
254
192
  value: function use() {
255
193
  var _this2 = this;
256
-
257
194
  for (var _len = arguments.length, middleware = new Array(_len), _key = 0; _key < _len; _key++) {
258
195
  middleware[_key] = arguments[_key];
259
196
  }
260
-
261
197
  var newMiddlewareList = middleware.map(function (fn) {
262
198
  var newMiddleware = _objectSpread({
263
199
  subscribe: noop,
@@ -267,36 +203,33 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
267
203
  }, fn({
268
204
  instantSearchInstance: _this2
269
205
  }));
270
-
271
206
  _this2.middleware.push({
272
207
  creator: fn,
273
208
  instance: newMiddleware
274
209
  });
275
-
276
210
  return newMiddleware;
277
- }); // If the instance has already started, we directly subscribe the
278
- // middleware so they're notified of changes.
211
+ });
279
212
 
213
+ // If the instance has already started, we directly subscribe the
214
+ // middleware so they're notified of changes.
280
215
  if (this.started) {
281
216
  newMiddlewareList.forEach(function (m) {
282
217
  m.subscribe();
283
218
  m.started();
284
219
  });
285
220
  }
286
-
287
221
  return this;
288
222
  }
223
+
289
224
  /**
290
225
  * Removes a middleware from the InstantSearch lifecycle.
291
226
  */
292
-
293
227
  }, {
294
228
  key: "unuse",
295
229
  value: function unuse() {
296
230
  for (var _len2 = arguments.length, middlewareToUnuse = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
297
231
  middlewareToUnuse[_key2] = arguments[_key2];
298
232
  }
299
-
300
233
  this.middleware.filter(function (m) {
301
234
  return middlewareToUnuse.includes(m.creator);
302
235
  }).forEach(function (m) {
@@ -306,14 +239,16 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
306
239
  return !middlewareToUnuse.includes(m.creator);
307
240
  });
308
241
  return this;
309
- } // @major we shipped with EXPERIMENTAL_use, but have changed that to just `use` now
242
+ }
310
243
 
244
+ // @major we shipped with EXPERIMENTAL_use, but have changed that to just `use` now
311
245
  }, {
312
246
  key: "EXPERIMENTAL_use",
313
247
  value: function EXPERIMENTAL_use() {
314
248
  process.env.NODE_ENV === 'development' ? warning(false, 'The middleware API is now considered stable, so we recommend replacing `EXPERIMENTAL_use` with `use` before upgrading to the next major version.') : void 0;
315
249
  return this.use.apply(this, arguments);
316
250
  }
251
+
317
252
  /**
318
253
  * Adds a widget to the search instance.
319
254
  * A widget can be added either before or after InstantSearch has started.
@@ -321,35 +256,33 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
321
256
  *
322
257
  * @deprecated This method will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`.
323
258
  */
324
-
325
259
  }, {
326
260
  key: "addWidget",
327
261
  value: function addWidget(widget) {
328
262
  process.env.NODE_ENV === 'development' ? warning(false, 'addWidget will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`') : void 0;
329
263
  return this.addWidgets([widget]);
330
264
  }
265
+
331
266
  /**
332
267
  * Adds multiple widgets to the search instance.
333
268
  * Widgets can be added either before or after InstantSearch has started.
334
269
  * @param widgets The array of widgets to add to InstantSearch.
335
270
  */
336
-
337
271
  }, {
338
272
  key: "addWidgets",
339
273
  value: function addWidgets(widgets) {
340
274
  if (!Array.isArray(widgets)) {
341
275
  throw new Error(withUsage('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
342
276
  }
343
-
344
277
  if (widgets.some(function (widget) {
345
278
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
346
279
  })) {
347
280
  throw new Error(withUsage('The widget definition expects a `render` and/or an `init` method.'));
348
281
  }
349
-
350
282
  this.mainIndex.addWidgets(widgets);
351
283
  return this;
352
284
  }
285
+
353
286
  /**
354
287
  * Removes a widget from the search instance.
355
288
  * @deprecated This method will still be supported in 4.x releases, but not further. It is replaced by `removeWidgets([widget])`
@@ -357,75 +290,69 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
357
290
  *
358
291
  * The widget must implement a `dispose()` method to clear its state.
359
292
  */
360
-
361
293
  }, {
362
294
  key: "removeWidget",
363
295
  value: function removeWidget(widget) {
364
296
  process.env.NODE_ENV === 'development' ? warning(false, 'removeWidget will still be supported in 4.x releases, but not further. It is replaced by `removeWidgets([widget])`') : void 0;
365
297
  return this.removeWidgets([widget]);
366
298
  }
299
+
367
300
  /**
368
301
  * Removes multiple widgets from the search instance.
369
302
  * @param widgets Array of widgets instances to remove from InstantSearch.
370
303
  *
371
304
  * The widgets must implement a `dispose()` method to clear their states.
372
305
  */
373
-
374
306
  }, {
375
307
  key: "removeWidgets",
376
308
  value: function removeWidgets(widgets) {
377
309
  if (!Array.isArray(widgets)) {
378
310
  throw new Error(withUsage('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
379
311
  }
380
-
381
312
  if (widgets.some(function (widget) {
382
313
  return typeof widget.dispose !== 'function';
383
314
  })) {
384
315
  throw new Error(withUsage('The widget definition expects a `dispose` method.'));
385
316
  }
386
-
387
317
  this.mainIndex.removeWidgets(widgets);
388
318
  return this;
389
319
  }
320
+
390
321
  /**
391
322
  * Ends the initialization of InstantSearch.js and triggers the
392
323
  * first search. This method should be called after all widgets have been added
393
324
  * to the instance of InstantSearch.js. InstantSearch.js also supports adding and removing
394
325
  * widgets after the start as an **EXPERIMENTAL** feature.
395
326
  */
396
-
397
327
  }, {
398
328
  key: "start",
399
329
  value: function start() {
400
330
  var _this3 = this;
401
-
402
331
  if (this.started) {
403
332
  throw new Error(withUsage('The `start` method has already been called once.'));
404
- } // This Helper is used for the queries, we don't care about its state. The
333
+ }
334
+
335
+ // This Helper is used for the queries, we don't care about its state. The
405
336
  // states are managed at the `index` level. We use this Helper to create
406
337
  // DerivedHelper scoped into the `index` widgets.
407
338
  // In Vue InstantSearch' hydrate, a main helper gets set before start, so
408
339
  // we need to respect this helper as a way to keep all listeners correct.
409
-
410
-
411
340
  var mainHelper = this.mainHelper || algoliasearchHelper(this.client, this.indexName);
412
-
413
341
  mainHelper.search = function () {
414
- _this3.status = 'loading'; // @MAJOR: use scheduleRender here
342
+ _this3.status = 'loading';
343
+ // @MAJOR: use scheduleRender here
415
344
  // For now, widgets don't expect to be rendered at the start of `loading`,
416
345
  // so it would be a breaking change to add an extra render. We don't have
417
346
  // these guarantees about the render event, thus emitting it once more
418
347
  // isn't a breaking change.
348
+ _this3.emit('render');
419
349
 
420
- _this3.emit('render'); // This solution allows us to keep the exact same API for the users but
350
+ // This solution allows us to keep the exact same API for the users but
421
351
  // under the hood, we have a different implementation. It should be
422
352
  // completely transparent for the rest of the codebase. Only this module
423
353
  // is impacted.
424
-
425
-
426
354
  return mainHelper.searchOnlyWithDerivedHelpers();
427
355
  };
428
-
429
356
  if (this._searchFunction) {
430
357
  // this client isn't used to actually search, but required for the helper
431
358
  // to not throw errors
@@ -435,34 +362,28 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
435
362
  }
436
363
  };
437
364
  this._mainHelperSearch = mainHelper.search.bind(mainHelper);
438
-
439
365
  mainHelper.search = function () {
440
366
  var mainIndexHelper = _this3.mainIndex.getHelper();
441
-
442
367
  var searchFunctionHelper = algoliasearchHelper(fakeClient, mainIndexHelper.state.index, mainIndexHelper.state);
443
368
  searchFunctionHelper.once('search', function (_ref2) {
444
369
  var state = _ref2.state;
445
370
  mainIndexHelper.overrideStateWithoutTriggeringChangeEvent(state);
446
-
447
371
  _this3._mainHelperSearch();
448
- }); // Forward state changes from `searchFunctionHelper` to `mainIndexHelper`
449
-
372
+ });
373
+ // Forward state changes from `searchFunctionHelper` to `mainIndexHelper`
450
374
  searchFunctionHelper.on('change', function (_ref3) {
451
375
  var state = _ref3.state;
452
376
  mainIndexHelper.setState(state);
453
377
  });
454
-
455
378
  _this3._searchFunction(searchFunctionHelper);
456
-
457
379
  return mainHelper;
458
380
  };
459
- } // Only the "main" Helper emits the `error` event vs the one for `search`
460
- // and `results` that are also emitted on the derived one.
461
-
381
+ }
462
382
 
383
+ // Only the "main" Helper emits the `error` event vs the one for `search`
384
+ // and `results` that are also emitted on the derived one.
463
385
  mainHelper.on('error', function (_ref4) {
464
386
  var error = _ref4.error;
465
-
466
387
  if (!(error instanceof Error)) {
467
388
  // typescript lies here, error is in some cases { name: string, message: string }
468
389
  var err = error;
@@ -470,21 +391,19 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
470
391
  acc[key] = err[key];
471
392
  return acc;
472
393
  }, new Error(err.message));
473
- } // If an error is emitted, it is re-thrown by events. In previous versions
394
+ }
395
+ // If an error is emitted, it is re-thrown by events. In previous versions
474
396
  // we emitted {error}, which is thrown as:
475
397
  // "Uncaught, unspecified \"error\" event. ([object Object])"
476
398
  // To avoid breaking changes, we make the error available in both
477
399
  // `error` and `error.error`
478
400
  // @MAJOR emit only error
479
-
480
-
481
401
  error.error = error;
482
402
  _this3.error = error;
483
403
  _this3.status = 'error';
404
+ _this3.scheduleRender(false);
484
405
 
485
- _this3.scheduleRender(false); // This needs to execute last because it throws the error.
486
-
487
-
406
+ // This needs to execute last because it throws the error.
488
407
  _this3.emit('error', error);
489
408
  });
490
409
  this.mainHelper = mainHelper;
@@ -497,22 +416,22 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
497
416
  parent: null,
498
417
  uiState: this._initialUiState
499
418
  });
500
-
501
419
  if (this._initialResults) {
502
- var originalScheduleSearch = this.scheduleSearch; // We don't schedule a first search when initial results are provided
420
+ var originalScheduleSearch = this.scheduleSearch;
421
+ // We don't schedule a first search when initial results are provided
503
422
  // because we already have the results to render. This skips the initial
504
423
  // network request on the browser on `start`.
505
-
506
- this.scheduleSearch = defer(noop); // We also skip the initial network request when widgets are dynamically
424
+ this.scheduleSearch = defer(noop);
425
+ // We also skip the initial network request when widgets are dynamically
507
426
  // added in the first tick (that's the case in all the framework-based flavors).
508
427
  // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
509
428
  // on our `defer` util to restore the original `scheduleSearch` value once
510
429
  // widgets are added to hook back to the regular lifecycle.
511
-
512
430
  defer(function () {
513
431
  _this3.scheduleSearch = originalScheduleSearch;
514
432
  })();
515
- } // We only schedule a search when widgets have been added before `start()`
433
+ }
434
+ // We only schedule a search when widgets have been added before `start()`
516
435
  // because there are listeners that can use these results.
517
436
  // This is especially useful in framework-based flavors that wait for
518
437
  // dynamically-added widgets to trigger a network request. It avoids
@@ -521,27 +440,28 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
521
440
  // Later, we could also skip `index()` widgets and widgets that don't read
522
441
  // the results, but this is an optimization that has a very low impact for now.
523
442
  else if (this.mainIndex.getWidgets().length > 0) {
524
- this.scheduleSearch();
525
- } // Keep the previous reference for legacy purpose, some pattern use
526
- // the direct Helper access `search.helper` (e.g multi-index).
443
+ this.scheduleSearch();
444
+ }
527
445
 
446
+ // Keep the previous reference for legacy purpose, some pattern use
447
+ // the direct Helper access `search.helper` (e.g multi-index).
448
+ this.helper = this.mainIndex.getHelper();
528
449
 
529
- this.helper = this.mainIndex.getHelper(); // track we started the search if we add more widgets,
450
+ // track we started the search if we add more widgets,
530
451
  // to init them directly after add
531
-
532
452
  this.started = true;
533
453
  this.middleware.forEach(function (_ref6) {
534
454
  var instance = _ref6.instance;
535
455
  instance.started();
536
456
  });
537
457
  }
458
+
538
459
  /**
539
460
  * Removes all widgets without triggering a search afterwards. This is an **EXPERIMENTAL** feature,
540
461
  * if you find an issue with it, please
541
462
  * [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20dispose).
542
463
  * @return {undefined} This method does not return anything
543
464
  */
544
-
545
465
  }, {
546
466
  key: "dispose",
547
467
  value: function dispose() {
@@ -549,13 +469,15 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
549
469
  this.scheduleRender.cancel();
550
470
  clearTimeout(this._searchStalledTimer);
551
471
  this.removeWidgets(this.mainIndex.getWidgets());
552
- this.mainIndex.dispose(); // You can not start an instance two times, therefore a disposed instance
472
+ this.mainIndex.dispose();
473
+
474
+ // You can not start an instance two times, therefore a disposed instance
553
475
  // needs to set started as false otherwise this can not be restarted at a
554
476
  // later point.
477
+ this.started = false;
555
478
 
556
- this.started = false; // The helper needs to be reset to perform the next search from a fresh state.
479
+ // The helper needs to be reset to perform the next search from a fresh state.
557
480
  // If not reset, it would use the state stored before calling `dispose()`.
558
-
559
481
  this.removeAllListeners();
560
482
  this.mainHelper.removeAllListeners();
561
483
  this.mainHelper = null;
@@ -569,45 +491,38 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
569
491
  key: "scheduleStalledRender",
570
492
  value: function scheduleStalledRender() {
571
493
  var _this4 = this;
572
-
573
494
  if (!this._searchStalledTimer) {
574
495
  this._searchStalledTimer = setTimeout(function () {
575
496
  _this4.status = 'stalled';
576
-
577
497
  _this4.scheduleRender();
578
498
  }, this._stalledSearchDelay);
579
499
  }
580
500
  }
501
+
581
502
  /**
582
503
  * Set the UI state and trigger a search.
583
504
  * @param uiState The next UI state or a function computing it from the current state
584
505
  * @param callOnStateChange private parameter used to know if the method is called from a state change
585
506
  */
586
-
587
507
  }, {
588
508
  key: "setUiState",
589
509
  value: function setUiState(uiState) {
590
510
  var _this5 = this;
591
-
592
511
  var callOnStateChange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
593
-
594
512
  if (!this.mainHelper) {
595
513
  throw new Error(withUsage('The `start` method needs to be called before `setUiState`.'));
596
- } // We refresh the index UI state to update the local UI state that the
597
- // main index passes to the function form of `setUiState`.
598
-
514
+ }
599
515
 
516
+ // We refresh the index UI state to update the local UI state that the
517
+ // main index passes to the function form of `setUiState`.
600
518
  this.mainIndex.refreshUiState();
601
519
  var nextUiState = typeof uiState === 'function' ? uiState(this.mainIndex.getWidgetUiState({})) : uiState;
602
-
603
520
  if (this.onStateChange && callOnStateChange) {
604
521
  this.onStateChange({
605
522
  uiState: nextUiState,
606
523
  setUiState: function setUiState(finalUiState) {
607
524
  setIndexHelperState(typeof finalUiState === 'function' ? finalUiState(nextUiState) : finalUiState, _this5.mainIndex);
608
-
609
525
  _this5.scheduleSearch();
610
-
611
526
  _this5.onInternalStateChange();
612
527
  }
613
528
  });
@@ -624,18 +539,15 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
624
539
  // We refresh the index UI state to make sure changes from `refine` are taken in account
625
540
  this.mainIndex.refreshUiState();
626
541
  }
627
-
628
542
  return this.mainIndex.getWidgetUiState({});
629
543
  }
630
544
  }, {
631
545
  key: "createURL",
632
546
  value: function createURL() {
633
547
  var nextState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
634
-
635
548
  if (!this.started) {
636
549
  throw new Error(withUsage('The `start` method needs to be called before `createURL`.'));
637
550
  }
638
-
639
551
  return this._createURL(nextState);
640
552
  }
641
553
  }, {
@@ -644,12 +556,9 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
644
556
  if (!this.mainHelper) {
645
557
  throw new Error(withUsage('The `start` method needs to be called before `refresh`.'));
646
558
  }
647
-
648
559
  this.mainHelper.clearCache().search();
649
560
  }
650
561
  }]);
651
-
652
562
  return InstantSearch;
653
563
  }(EventEmitter);
654
-
655
564
  export default InstantSearch;