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