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/es/lib/InstantSearch.js
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
2
|
-
|
|
3
|
-
function
|
|
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
|
-
function
|
|
10
|
-
|
|
11
|
-
function
|
|
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
|
-
|
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
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
|
|
24
|
-
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
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
|
-
|
|
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); }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
29
17
|
import algoliasearchHelper from 'algoliasearch-helper';
|
|
30
18
|
import EventEmitter from '@algolia/events';
|
|
31
19
|
import index from "../widgets/index/index.js";
|
|
@@ -37,14 +25,13 @@ import { createMetadataMiddleware, isMetadataEnabled } from "../middlewares/crea
|
|
|
37
25
|
var withUsage = createDocumentationMessageGenerator({
|
|
38
26
|
name: 'instantsearch'
|
|
39
27
|
});
|
|
40
|
-
|
|
41
28
|
function defaultCreateURL() {
|
|
42
29
|
return '#';
|
|
43
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// this purposely breaks typescript's type inference to ensure it's not used
|
|
44
33
|
// as it's used for a default parameter for example
|
|
45
34
|
// source: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546
|
|
46
|
-
|
|
47
|
-
|
|
48
35
|
/**
|
|
49
36
|
* The actual implementation of the InstantSearch. This is
|
|
50
37
|
* created using the `instantsearch` factory function.
|
|
@@ -52,87 +39,56 @@ function defaultCreateURL() {
|
|
|
52
39
|
*/
|
|
53
40
|
var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
54
41
|
_inherits(InstantSearch, _EventEmitter);
|
|
55
|
-
|
|
56
42
|
var _super = _createSuper(InstantSearch);
|
|
57
|
-
|
|
58
43
|
function InstantSearch(options) {
|
|
59
44
|
var _this;
|
|
60
|
-
|
|
61
45
|
_classCallCheck(this, InstantSearch);
|
|
46
|
+
_this = _super.call(this);
|
|
62
47
|
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
// prevent `render` event listening from causing a warning
|
|
65
49
|
_defineProperty(_assertThisInitialized(_this), "client", void 0);
|
|
66
|
-
|
|
67
50
|
_defineProperty(_assertThisInitialized(_this), "indexName", void 0);
|
|
68
|
-
|
|
69
51
|
_defineProperty(_assertThisInitialized(_this), "insightsClient", void 0);
|
|
70
|
-
|
|
71
52
|
_defineProperty(_assertThisInitialized(_this), "onStateChange", null);
|
|
72
|
-
|
|
73
53
|
_defineProperty(_assertThisInitialized(_this), "helper", void 0);
|
|
74
|
-
|
|
75
54
|
_defineProperty(_assertThisInitialized(_this), "mainHelper", void 0);
|
|
76
|
-
|
|
77
55
|
_defineProperty(_assertThisInitialized(_this), "mainIndex", void 0);
|
|
78
|
-
|
|
79
56
|
_defineProperty(_assertThisInitialized(_this), "started", void 0);
|
|
80
|
-
|
|
81
57
|
_defineProperty(_assertThisInitialized(_this), "templatesConfig", void 0);
|
|
82
|
-
|
|
83
58
|
_defineProperty(_assertThisInitialized(_this), "renderState", {});
|
|
84
|
-
|
|
85
59
|
_defineProperty(_assertThisInitialized(_this), "_stalledSearchDelay", void 0);
|
|
86
|
-
|
|
87
60
|
_defineProperty(_assertThisInitialized(_this), "_searchStalledTimer", void 0);
|
|
88
|
-
|
|
89
61
|
_defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
|
|
90
|
-
|
|
91
62
|
_defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
|
|
92
|
-
|
|
93
63
|
_defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
|
|
94
|
-
|
|
95
64
|
_defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
|
|
96
|
-
|
|
97
65
|
_defineProperty(_assertThisInitialized(_this), "_mainHelperSearch", void 0);
|
|
98
|
-
|
|
99
66
|
_defineProperty(_assertThisInitialized(_this), "middleware", []);
|
|
100
|
-
|
|
101
67
|
_defineProperty(_assertThisInitialized(_this), "sendEventToInsights", void 0);
|
|
102
|
-
|
|
103
68
|
_defineProperty(_assertThisInitialized(_this), "status", 'idle');
|
|
104
|
-
|
|
105
69
|
_defineProperty(_assertThisInitialized(_this), "error", undefined);
|
|
106
|
-
|
|
107
70
|
_defineProperty(_assertThisInitialized(_this), "scheduleSearch", defer(function () {
|
|
108
71
|
if (_this.started) {
|
|
109
72
|
_this.mainHelper.search();
|
|
110
73
|
}
|
|
111
74
|
}));
|
|
112
|
-
|
|
113
75
|
_defineProperty(_assertThisInitialized(_this), "scheduleRender", defer(function () {
|
|
114
76
|
var shouldResetStatus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
115
|
-
|
|
116
77
|
if (!_this.mainHelper.hasPendingRequests()) {
|
|
117
78
|
clearTimeout(_this._searchStalledTimer);
|
|
118
79
|
_this._searchStalledTimer = null;
|
|
119
|
-
|
|
120
80
|
if (shouldResetStatus) {
|
|
121
81
|
_this.status = 'idle';
|
|
122
82
|
_this.error = undefined;
|
|
123
83
|
}
|
|
124
84
|
}
|
|
125
|
-
|
|
126
85
|
_this.mainIndex.render({
|
|
127
86
|
instantSearchInstance: _assertThisInitialized(_this)
|
|
128
87
|
});
|
|
129
|
-
|
|
130
88
|
_this.emit('render');
|
|
131
89
|
}));
|
|
132
|
-
|
|
133
90
|
_defineProperty(_assertThisInitialized(_this), "onInternalStateChange", defer(function () {
|
|
134
91
|
var nextUiState = _this.mainIndex.getWidgetUiState({});
|
|
135
|
-
|
|
136
92
|
_this.middleware.forEach(function (_ref) {
|
|
137
93
|
var instance = _ref.instance;
|
|
138
94
|
instance.onStateChange({
|
|
@@ -140,48 +96,39 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
140
96
|
});
|
|
141
97
|
});
|
|
142
98
|
}));
|
|
143
|
-
|
|
144
99
|
_this.setMaxListeners(100);
|
|
145
|
-
|
|
146
100
|
var _options$indexName = options.indexName,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
101
|
+
indexName = _options$indexName === void 0 ? null : _options$indexName,
|
|
102
|
+
numberLocale = options.numberLocale,
|
|
103
|
+
_options$initialUiSta = options.initialUiState,
|
|
104
|
+
initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
|
|
105
|
+
_options$routing = options.routing,
|
|
106
|
+
routing = _options$routing === void 0 ? null : _options$routing,
|
|
107
|
+
searchFunction = options.searchFunction,
|
|
108
|
+
_options$stalledSearc = options.stalledSearchDelay,
|
|
109
|
+
stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
|
|
110
|
+
_options$searchClient = options.searchClient,
|
|
111
|
+
searchClient = _options$searchClient === void 0 ? null : _options$searchClient,
|
|
112
|
+
_options$insightsClie = options.insightsClient,
|
|
113
|
+
insightsClient = _options$insightsClie === void 0 ? null : _options$insightsClie,
|
|
114
|
+
_options$onStateChang = options.onStateChange,
|
|
115
|
+
onStateChange = _options$onStateChang === void 0 ? null : _options$onStateChang;
|
|
163
116
|
if (indexName === null) {
|
|
164
117
|
throw new Error(withUsage('The `indexName` option is required.'));
|
|
165
118
|
}
|
|
166
|
-
|
|
167
119
|
if (searchClient === null) {
|
|
168
120
|
throw new Error(withUsage('The `searchClient` option is required.'));
|
|
169
121
|
}
|
|
170
|
-
|
|
171
122
|
if (typeof searchClient.search !== 'function') {
|
|
172
123
|
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
124
|
}
|
|
174
|
-
|
|
175
125
|
if (typeof searchClient.addAlgoliaAgent === 'function') {
|
|
176
126
|
searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
|
|
177
127
|
}
|
|
178
|
-
|
|
179
128
|
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
129
|
if (insightsClient && typeof insightsClient !== 'function') {
|
|
182
130
|
throw new Error(withUsage('The `insightsClient` option should be a function.'));
|
|
183
131
|
}
|
|
184
|
-
|
|
185
132
|
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
133
|
name: 'configure'
|
|
187
134
|
}))) : void 0;
|
|
@@ -206,30 +153,23 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
206
153
|
_this._createURL = defaultCreateURL;
|
|
207
154
|
_this._initialUiState = initialUiState;
|
|
208
155
|
_this._initialResults = null;
|
|
209
|
-
|
|
210
156
|
if (searchFunction) {
|
|
211
157
|
_this._searchFunction = searchFunction;
|
|
212
158
|
}
|
|
213
|
-
|
|
214
159
|
_this.sendEventToInsights = noop;
|
|
215
|
-
|
|
216
160
|
if (routing) {
|
|
217
161
|
var routerOptions = typeof routing === 'boolean' ? undefined : routing;
|
|
218
|
-
|
|
219
162
|
_this.use(createRouterMiddleware(routerOptions));
|
|
220
163
|
}
|
|
221
|
-
|
|
222
164
|
if (isMetadataEnabled()) {
|
|
223
165
|
_this.use(createMetadataMiddleware());
|
|
224
166
|
}
|
|
225
|
-
|
|
226
167
|
return _this;
|
|
227
168
|
}
|
|
169
|
+
|
|
228
170
|
/**
|
|
229
171
|
* Hooks a middleware into the InstantSearch lifecycle.
|
|
230
172
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
173
|
_createClass(InstantSearch, [{
|
|
234
174
|
key: "_isSearchStalled",
|
|
235
175
|
get:
|
|
@@ -253,11 +193,9 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
253
193
|
key: "use",
|
|
254
194
|
value: function use() {
|
|
255
195
|
var _this2 = this;
|
|
256
|
-
|
|
257
196
|
for (var _len = arguments.length, middleware = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
258
197
|
middleware[_key] = arguments[_key];
|
|
259
198
|
}
|
|
260
|
-
|
|
261
199
|
var newMiddlewareList = middleware.map(function (fn) {
|
|
262
200
|
var newMiddleware = _objectSpread({
|
|
263
201
|
subscribe: noop,
|
|
@@ -267,36 +205,33 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
267
205
|
}, fn({
|
|
268
206
|
instantSearchInstance: _this2
|
|
269
207
|
}));
|
|
270
|
-
|
|
271
208
|
_this2.middleware.push({
|
|
272
209
|
creator: fn,
|
|
273
210
|
instance: newMiddleware
|
|
274
211
|
});
|
|
275
|
-
|
|
276
212
|
return newMiddleware;
|
|
277
|
-
});
|
|
278
|
-
// middleware so they're notified of changes.
|
|
213
|
+
});
|
|
279
214
|
|
|
215
|
+
// If the instance has already started, we directly subscribe the
|
|
216
|
+
// middleware so they're notified of changes.
|
|
280
217
|
if (this.started) {
|
|
281
218
|
newMiddlewareList.forEach(function (m) {
|
|
282
219
|
m.subscribe();
|
|
283
220
|
m.started();
|
|
284
221
|
});
|
|
285
222
|
}
|
|
286
|
-
|
|
287
223
|
return this;
|
|
288
224
|
}
|
|
225
|
+
|
|
289
226
|
/**
|
|
290
227
|
* Removes a middleware from the InstantSearch lifecycle.
|
|
291
228
|
*/
|
|
292
|
-
|
|
293
229
|
}, {
|
|
294
230
|
key: "unuse",
|
|
295
231
|
value: function unuse() {
|
|
296
232
|
for (var _len2 = arguments.length, middlewareToUnuse = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
297
233
|
middlewareToUnuse[_key2] = arguments[_key2];
|
|
298
234
|
}
|
|
299
|
-
|
|
300
235
|
this.middleware.filter(function (m) {
|
|
301
236
|
return middlewareToUnuse.includes(m.creator);
|
|
302
237
|
}).forEach(function (m) {
|
|
@@ -306,14 +241,16 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
306
241
|
return !middlewareToUnuse.includes(m.creator);
|
|
307
242
|
});
|
|
308
243
|
return this;
|
|
309
|
-
}
|
|
244
|
+
}
|
|
310
245
|
|
|
246
|
+
// @major we shipped with EXPERIMENTAL_use, but have changed that to just `use` now
|
|
311
247
|
}, {
|
|
312
248
|
key: "EXPERIMENTAL_use",
|
|
313
249
|
value: function EXPERIMENTAL_use() {
|
|
314
250
|
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
251
|
return this.use.apply(this, arguments);
|
|
316
252
|
}
|
|
253
|
+
|
|
317
254
|
/**
|
|
318
255
|
* Adds a widget to the search instance.
|
|
319
256
|
* A widget can be added either before or after InstantSearch has started.
|
|
@@ -321,35 +258,33 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
321
258
|
*
|
|
322
259
|
* @deprecated This method will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`.
|
|
323
260
|
*/
|
|
324
|
-
|
|
325
261
|
}, {
|
|
326
262
|
key: "addWidget",
|
|
327
263
|
value: function addWidget(widget) {
|
|
328
264
|
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
265
|
return this.addWidgets([widget]);
|
|
330
266
|
}
|
|
267
|
+
|
|
331
268
|
/**
|
|
332
269
|
* Adds multiple widgets to the search instance.
|
|
333
270
|
* Widgets can be added either before or after InstantSearch has started.
|
|
334
271
|
* @param widgets The array of widgets to add to InstantSearch.
|
|
335
272
|
*/
|
|
336
|
-
|
|
337
273
|
}, {
|
|
338
274
|
key: "addWidgets",
|
|
339
275
|
value: function addWidgets(widgets) {
|
|
340
276
|
if (!Array.isArray(widgets)) {
|
|
341
277
|
throw new Error(withUsage('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
|
|
342
278
|
}
|
|
343
|
-
|
|
344
279
|
if (widgets.some(function (widget) {
|
|
345
280
|
return typeof widget.init !== 'function' && typeof widget.render !== 'function';
|
|
346
281
|
})) {
|
|
347
282
|
throw new Error(withUsage('The widget definition expects a `render` and/or an `init` method.'));
|
|
348
283
|
}
|
|
349
|
-
|
|
350
284
|
this.mainIndex.addWidgets(widgets);
|
|
351
285
|
return this;
|
|
352
286
|
}
|
|
287
|
+
|
|
353
288
|
/**
|
|
354
289
|
* Removes a widget from the search instance.
|
|
355
290
|
* @deprecated This method will still be supported in 4.x releases, but not further. It is replaced by `removeWidgets([widget])`
|
|
@@ -357,75 +292,69 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
357
292
|
*
|
|
358
293
|
* The widget must implement a `dispose()` method to clear its state.
|
|
359
294
|
*/
|
|
360
|
-
|
|
361
295
|
}, {
|
|
362
296
|
key: "removeWidget",
|
|
363
297
|
value: function removeWidget(widget) {
|
|
364
298
|
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
299
|
return this.removeWidgets([widget]);
|
|
366
300
|
}
|
|
301
|
+
|
|
367
302
|
/**
|
|
368
303
|
* Removes multiple widgets from the search instance.
|
|
369
304
|
* @param widgets Array of widgets instances to remove from InstantSearch.
|
|
370
305
|
*
|
|
371
306
|
* The widgets must implement a `dispose()` method to clear their states.
|
|
372
307
|
*/
|
|
373
|
-
|
|
374
308
|
}, {
|
|
375
309
|
key: "removeWidgets",
|
|
376
310
|
value: function removeWidgets(widgets) {
|
|
377
311
|
if (!Array.isArray(widgets)) {
|
|
378
312
|
throw new Error(withUsage('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
|
|
379
313
|
}
|
|
380
|
-
|
|
381
314
|
if (widgets.some(function (widget) {
|
|
382
315
|
return typeof widget.dispose !== 'function';
|
|
383
316
|
})) {
|
|
384
317
|
throw new Error(withUsage('The widget definition expects a `dispose` method.'));
|
|
385
318
|
}
|
|
386
|
-
|
|
387
319
|
this.mainIndex.removeWidgets(widgets);
|
|
388
320
|
return this;
|
|
389
321
|
}
|
|
322
|
+
|
|
390
323
|
/**
|
|
391
324
|
* Ends the initialization of InstantSearch.js and triggers the
|
|
392
325
|
* first search. This method should be called after all widgets have been added
|
|
393
326
|
* to the instance of InstantSearch.js. InstantSearch.js also supports adding and removing
|
|
394
327
|
* widgets after the start as an **EXPERIMENTAL** feature.
|
|
395
328
|
*/
|
|
396
|
-
|
|
397
329
|
}, {
|
|
398
330
|
key: "start",
|
|
399
331
|
value: function start() {
|
|
400
332
|
var _this3 = this;
|
|
401
|
-
|
|
402
333
|
if (this.started) {
|
|
403
334
|
throw new Error(withUsage('The `start` method has already been called once.'));
|
|
404
|
-
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// This Helper is used for the queries, we don't care about its state. The
|
|
405
338
|
// states are managed at the `index` level. We use this Helper to create
|
|
406
339
|
// DerivedHelper scoped into the `index` widgets.
|
|
407
340
|
// In Vue InstantSearch' hydrate, a main helper gets set before start, so
|
|
408
341
|
// we need to respect this helper as a way to keep all listeners correct.
|
|
409
|
-
|
|
410
|
-
|
|
411
342
|
var mainHelper = this.mainHelper || algoliasearchHelper(this.client, this.indexName);
|
|
412
|
-
|
|
413
343
|
mainHelper.search = function () {
|
|
414
|
-
_this3.status = 'loading';
|
|
344
|
+
_this3.status = 'loading';
|
|
345
|
+
// @MAJOR: use scheduleRender here
|
|
415
346
|
// For now, widgets don't expect to be rendered at the start of `loading`,
|
|
416
347
|
// so it would be a breaking change to add an extra render. We don't have
|
|
417
348
|
// these guarantees about the render event, thus emitting it once more
|
|
418
349
|
// isn't a breaking change.
|
|
350
|
+
_this3.emit('render');
|
|
419
351
|
|
|
420
|
-
|
|
352
|
+
// This solution allows us to keep the exact same API for the users but
|
|
421
353
|
// under the hood, we have a different implementation. It should be
|
|
422
354
|
// completely transparent for the rest of the codebase. Only this module
|
|
423
355
|
// is impacted.
|
|
424
|
-
|
|
425
|
-
|
|
426
356
|
return mainHelper.searchOnlyWithDerivedHelpers();
|
|
427
357
|
};
|
|
428
|
-
|
|
429
358
|
if (this._searchFunction) {
|
|
430
359
|
// this client isn't used to actually search, but required for the helper
|
|
431
360
|
// to not throw errors
|
|
@@ -435,34 +364,28 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
435
364
|
}
|
|
436
365
|
};
|
|
437
366
|
this._mainHelperSearch = mainHelper.search.bind(mainHelper);
|
|
438
|
-
|
|
439
367
|
mainHelper.search = function () {
|
|
440
368
|
var mainIndexHelper = _this3.mainIndex.getHelper();
|
|
441
|
-
|
|
442
369
|
var searchFunctionHelper = algoliasearchHelper(fakeClient, mainIndexHelper.state.index, mainIndexHelper.state);
|
|
443
370
|
searchFunctionHelper.once('search', function (_ref2) {
|
|
444
371
|
var state = _ref2.state;
|
|
445
372
|
mainIndexHelper.overrideStateWithoutTriggeringChangeEvent(state);
|
|
446
|
-
|
|
447
373
|
_this3._mainHelperSearch();
|
|
448
|
-
});
|
|
449
|
-
|
|
374
|
+
});
|
|
375
|
+
// Forward state changes from `searchFunctionHelper` to `mainIndexHelper`
|
|
450
376
|
searchFunctionHelper.on('change', function (_ref3) {
|
|
451
377
|
var state = _ref3.state;
|
|
452
378
|
mainIndexHelper.setState(state);
|
|
453
379
|
});
|
|
454
|
-
|
|
455
380
|
_this3._searchFunction(searchFunctionHelper);
|
|
456
|
-
|
|
457
381
|
return mainHelper;
|
|
458
382
|
};
|
|
459
|
-
}
|
|
460
|
-
// and `results` that are also emitted on the derived one.
|
|
461
|
-
|
|
383
|
+
}
|
|
462
384
|
|
|
385
|
+
// Only the "main" Helper emits the `error` event vs the one for `search`
|
|
386
|
+
// and `results` that are also emitted on the derived one.
|
|
463
387
|
mainHelper.on('error', function (_ref4) {
|
|
464
388
|
var error = _ref4.error;
|
|
465
|
-
|
|
466
389
|
if (!(error instanceof Error)) {
|
|
467
390
|
// typescript lies here, error is in some cases { name: string, message: string }
|
|
468
391
|
var err = error;
|
|
@@ -470,21 +393,19 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
470
393
|
acc[key] = err[key];
|
|
471
394
|
return acc;
|
|
472
395
|
}, new Error(err.message));
|
|
473
|
-
}
|
|
396
|
+
}
|
|
397
|
+
// If an error is emitted, it is re-thrown by events. In previous versions
|
|
474
398
|
// we emitted {error}, which is thrown as:
|
|
475
399
|
// "Uncaught, unspecified \"error\" event. ([object Object])"
|
|
476
400
|
// To avoid breaking changes, we make the error available in both
|
|
477
401
|
// `error` and `error.error`
|
|
478
402
|
// @MAJOR emit only error
|
|
479
|
-
|
|
480
|
-
|
|
481
403
|
error.error = error;
|
|
482
404
|
_this3.error = error;
|
|
483
405
|
_this3.status = 'error';
|
|
406
|
+
_this3.scheduleRender(false);
|
|
484
407
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
408
|
+
// This needs to execute last because it throws the error.
|
|
488
409
|
_this3.emit('error', error);
|
|
489
410
|
});
|
|
490
411
|
this.mainHelper = mainHelper;
|
|
@@ -497,22 +418,22 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
497
418
|
parent: null,
|
|
498
419
|
uiState: this._initialUiState
|
|
499
420
|
});
|
|
500
|
-
|
|
501
421
|
if (this._initialResults) {
|
|
502
|
-
var originalScheduleSearch = this.scheduleSearch;
|
|
422
|
+
var originalScheduleSearch = this.scheduleSearch;
|
|
423
|
+
// We don't schedule a first search when initial results are provided
|
|
503
424
|
// because we already have the results to render. This skips the initial
|
|
504
425
|
// network request on the browser on `start`.
|
|
505
|
-
|
|
506
|
-
|
|
426
|
+
this.scheduleSearch = defer(noop);
|
|
427
|
+
// We also skip the initial network request when widgets are dynamically
|
|
507
428
|
// added in the first tick (that's the case in all the framework-based flavors).
|
|
508
429
|
// When we add a widget to `index`, it calls `scheduleSearch`. We can rely
|
|
509
430
|
// on our `defer` util to restore the original `scheduleSearch` value once
|
|
510
431
|
// widgets are added to hook back to the regular lifecycle.
|
|
511
|
-
|
|
512
432
|
defer(function () {
|
|
513
433
|
_this3.scheduleSearch = originalScheduleSearch;
|
|
514
434
|
})();
|
|
515
|
-
}
|
|
435
|
+
}
|
|
436
|
+
// We only schedule a search when widgets have been added before `start()`
|
|
516
437
|
// because there are listeners that can use these results.
|
|
517
438
|
// This is especially useful in framework-based flavors that wait for
|
|
518
439
|
// dynamically-added widgets to trigger a network request. It avoids
|
|
@@ -521,27 +442,28 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
521
442
|
// Later, we could also skip `index()` widgets and widgets that don't read
|
|
522
443
|
// the results, but this is an optimization that has a very low impact for now.
|
|
523
444
|
else if (this.mainIndex.getWidgets().length > 0) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
// the direct Helper access `search.helper` (e.g multi-index).
|
|
445
|
+
this.scheduleSearch();
|
|
446
|
+
}
|
|
527
447
|
|
|
448
|
+
// Keep the previous reference for legacy purpose, some pattern use
|
|
449
|
+
// the direct Helper access `search.helper` (e.g multi-index).
|
|
450
|
+
this.helper = this.mainIndex.getHelper();
|
|
528
451
|
|
|
529
|
-
|
|
452
|
+
// track we started the search if we add more widgets,
|
|
530
453
|
// to init them directly after add
|
|
531
|
-
|
|
532
454
|
this.started = true;
|
|
533
455
|
this.middleware.forEach(function (_ref6) {
|
|
534
456
|
var instance = _ref6.instance;
|
|
535
457
|
instance.started();
|
|
536
458
|
});
|
|
537
459
|
}
|
|
460
|
+
|
|
538
461
|
/**
|
|
539
462
|
* Removes all widgets without triggering a search afterwards. This is an **EXPERIMENTAL** feature,
|
|
540
463
|
* if you find an issue with it, please
|
|
541
464
|
* [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20dispose).
|
|
542
465
|
* @return {undefined} This method does not return anything
|
|
543
466
|
*/
|
|
544
|
-
|
|
545
467
|
}, {
|
|
546
468
|
key: "dispose",
|
|
547
469
|
value: function dispose() {
|
|
@@ -549,13 +471,15 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
549
471
|
this.scheduleRender.cancel();
|
|
550
472
|
clearTimeout(this._searchStalledTimer);
|
|
551
473
|
this.removeWidgets(this.mainIndex.getWidgets());
|
|
552
|
-
this.mainIndex.dispose();
|
|
474
|
+
this.mainIndex.dispose();
|
|
475
|
+
|
|
476
|
+
// You can not start an instance two times, therefore a disposed instance
|
|
553
477
|
// needs to set started as false otherwise this can not be restarted at a
|
|
554
478
|
// later point.
|
|
479
|
+
this.started = false;
|
|
555
480
|
|
|
556
|
-
|
|
481
|
+
// The helper needs to be reset to perform the next search from a fresh state.
|
|
557
482
|
// If not reset, it would use the state stored before calling `dispose()`.
|
|
558
|
-
|
|
559
483
|
this.removeAllListeners();
|
|
560
484
|
this.mainHelper.removeAllListeners();
|
|
561
485
|
this.mainHelper = null;
|
|
@@ -569,45 +493,38 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
569
493
|
key: "scheduleStalledRender",
|
|
570
494
|
value: function scheduleStalledRender() {
|
|
571
495
|
var _this4 = this;
|
|
572
|
-
|
|
573
496
|
if (!this._searchStalledTimer) {
|
|
574
497
|
this._searchStalledTimer = setTimeout(function () {
|
|
575
498
|
_this4.status = 'stalled';
|
|
576
|
-
|
|
577
499
|
_this4.scheduleRender();
|
|
578
500
|
}, this._stalledSearchDelay);
|
|
579
501
|
}
|
|
580
502
|
}
|
|
503
|
+
|
|
581
504
|
/**
|
|
582
505
|
* Set the UI state and trigger a search.
|
|
583
506
|
* @param uiState The next UI state or a function computing it from the current state
|
|
584
507
|
* @param callOnStateChange private parameter used to know if the method is called from a state change
|
|
585
508
|
*/
|
|
586
|
-
|
|
587
509
|
}, {
|
|
588
510
|
key: "setUiState",
|
|
589
511
|
value: function setUiState(uiState) {
|
|
590
512
|
var _this5 = this;
|
|
591
|
-
|
|
592
513
|
var callOnStateChange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
593
|
-
|
|
594
514
|
if (!this.mainHelper) {
|
|
595
515
|
throw new Error(withUsage('The `start` method needs to be called before `setUiState`.'));
|
|
596
|
-
}
|
|
597
|
-
// main index passes to the function form of `setUiState`.
|
|
598
|
-
|
|
516
|
+
}
|
|
599
517
|
|
|
518
|
+
// We refresh the index UI state to update the local UI state that the
|
|
519
|
+
// main index passes to the function form of `setUiState`.
|
|
600
520
|
this.mainIndex.refreshUiState();
|
|
601
521
|
var nextUiState = typeof uiState === 'function' ? uiState(this.mainIndex.getWidgetUiState({})) : uiState;
|
|
602
|
-
|
|
603
522
|
if (this.onStateChange && callOnStateChange) {
|
|
604
523
|
this.onStateChange({
|
|
605
524
|
uiState: nextUiState,
|
|
606
525
|
setUiState: function setUiState(finalUiState) {
|
|
607
526
|
setIndexHelperState(typeof finalUiState === 'function' ? finalUiState(nextUiState) : finalUiState, _this5.mainIndex);
|
|
608
|
-
|
|
609
527
|
_this5.scheduleSearch();
|
|
610
|
-
|
|
611
528
|
_this5.onInternalStateChange();
|
|
612
529
|
}
|
|
613
530
|
});
|
|
@@ -624,18 +541,15 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
624
541
|
// We refresh the index UI state to make sure changes from `refine` are taken in account
|
|
625
542
|
this.mainIndex.refreshUiState();
|
|
626
543
|
}
|
|
627
|
-
|
|
628
544
|
return this.mainIndex.getWidgetUiState({});
|
|
629
545
|
}
|
|
630
546
|
}, {
|
|
631
547
|
key: "createURL",
|
|
632
548
|
value: function createURL() {
|
|
633
549
|
var nextState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
634
|
-
|
|
635
550
|
if (!this.started) {
|
|
636
551
|
throw new Error(withUsage('The `start` method needs to be called before `createURL`.'));
|
|
637
552
|
}
|
|
638
|
-
|
|
639
553
|
return this._createURL(nextState);
|
|
640
554
|
}
|
|
641
555
|
}, {
|
|
@@ -644,12 +558,9 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
644
558
|
if (!this.mainHelper) {
|
|
645
559
|
throw new Error(withUsage('The `start` method needs to be called before `refresh`.'));
|
|
646
560
|
}
|
|
647
|
-
|
|
648
561
|
this.mainHelper.clearCache().search();
|
|
649
562
|
}
|
|
650
563
|
}]);
|
|
651
|
-
|
|
652
564
|
return InstantSearch;
|
|
653
565
|
}(EventEmitter);
|
|
654
|
-
|
|
655
566
|
export default InstantSearch;
|