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/createHelpers.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
4
|
-
|
|
5
|
-
function
|
|
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; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
7
|
import { highlight as _highlight, reverseHighlight as _reverseHighlight, snippet as _snippet, reverseSnippet as _reverseSnippet, insights as _insights } from "../helpers/index.js";
|
|
8
8
|
import { formatNumber as _formatNumber } from "./formatNumber.js";
|
|
9
9
|
export default function hoganHelpers(_ref) {
|
|
@@ -55,9 +55,8 @@ export default function hoganHelpers(_ref) {
|
|
|
55
55
|
insights: function insights(options, render) {
|
|
56
56
|
try {
|
|
57
57
|
var _JSON$parse = JSON.parse(options),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
method = _JSON$parse.method,
|
|
59
|
+
payload = _JSON$parse.payload;
|
|
61
60
|
return render(_insights(method, _objectSpread({
|
|
62
61
|
objectIDs: [this.objectID]
|
|
63
62
|
}, payload)));
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
+
var _excluded = ["page"];
|
|
1
2
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
2
|
-
|
|
3
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
-
|
|
5
4
|
import { isEqual, safelyRunOnBrowser } from "../utils/index.js";
|
|
6
|
-
|
|
7
5
|
function getStateWithoutPage(state) {
|
|
8
6
|
var _ref = state || {},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
page = _ref.page,
|
|
8
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
12
9
|
return rest;
|
|
13
10
|
}
|
|
14
|
-
|
|
15
11
|
var KEY = 'ais.infiniteHits';
|
|
16
12
|
export default function createInfiniteHitsSessionStorageCache() {
|
|
17
13
|
return {
|
|
@@ -21,44 +17,42 @@ export default function createInfiniteHitsSessionStorageCache() {
|
|
|
21
17
|
var window = _ref3.window;
|
|
22
18
|
return window.sessionStorage;
|
|
23
19
|
});
|
|
24
|
-
|
|
25
20
|
if (!sessionStorage) {
|
|
26
21
|
return null;
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
try {
|
|
30
|
-
var cache = JSON.parse(
|
|
24
|
+
var cache = JSON.parse(
|
|
25
|
+
// @ts-expect-error JSON.parse() requires a string, but it actually accepts null, too.
|
|
31
26
|
sessionStorage.getItem(KEY));
|
|
32
27
|
return cache && isEqual(cache.state, getStateWithoutPage(state)) ? cache.hits : null;
|
|
33
28
|
} catch (error) {
|
|
34
29
|
if (error instanceof SyntaxError) {
|
|
35
30
|
try {
|
|
36
31
|
sessionStorage.removeItem(KEY);
|
|
37
|
-
} catch (err) {
|
|
32
|
+
} catch (err) {
|
|
33
|
+
// do nothing
|
|
38
34
|
}
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return null;
|
|
42
37
|
}
|
|
43
38
|
},
|
|
44
39
|
write: function write(_ref4) {
|
|
45
40
|
var state = _ref4.state,
|
|
46
|
-
|
|
41
|
+
hits = _ref4.hits;
|
|
47
42
|
var sessionStorage = safelyRunOnBrowser(function (_ref5) {
|
|
48
43
|
var window = _ref5.window;
|
|
49
44
|
return window.sessionStorage;
|
|
50
45
|
});
|
|
51
|
-
|
|
52
46
|
if (!sessionStorage) {
|
|
53
47
|
return;
|
|
54
48
|
}
|
|
55
|
-
|
|
56
49
|
try {
|
|
57
50
|
sessionStorage.setItem(KEY, JSON.stringify({
|
|
58
51
|
state: getStateWithoutPage(state),
|
|
59
52
|
hits: hits
|
|
60
53
|
}));
|
|
61
|
-
} catch (error) {
|
|
54
|
+
} catch (error) {
|
|
55
|
+
// do nothing
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
};
|
|
@@ -1,58 +1,47 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
4
|
-
|
|
5
|
-
function
|
|
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; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
7
|
import { uniq, find, createDocumentationMessageGenerator, warning } from "../utils/index.js";
|
|
8
|
-
|
|
9
8
|
var getSelectedHits = function getSelectedHits(hits, selectedObjectIDs) {
|
|
10
9
|
return selectedObjectIDs.map(function (objectID) {
|
|
11
10
|
var hit = find(hits, function (h) {
|
|
12
11
|
return h.objectID === objectID;
|
|
13
12
|
});
|
|
14
|
-
|
|
15
13
|
if (typeof hit === 'undefined') {
|
|
16
14
|
throw new Error("Could not find objectID \"".concat(objectID, "\" passed to `clickedObjectIDsAfterSearch` in the returned hits. This is necessary to infer the absolute position and the query ID."));
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
return hit;
|
|
20
17
|
});
|
|
21
18
|
};
|
|
22
|
-
|
|
23
19
|
var getQueryID = function getQueryID(selectedHits) {
|
|
24
20
|
var queryIDs = uniq(selectedHits.map(function (hit) {
|
|
25
21
|
return hit.__queryID;
|
|
26
22
|
}));
|
|
27
|
-
|
|
28
23
|
if (queryIDs.length > 1) {
|
|
29
24
|
throw new Error('Insights currently allows a single `queryID`. The `objectIDs` provided map to multiple `queryID`s.');
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
var queryID = queryIDs[0];
|
|
33
|
-
|
|
34
27
|
if (typeof queryID !== 'string') {
|
|
35
28
|
throw new Error("Could not infer `queryID`. Ensure InstantSearch `clickAnalytics: true` was added with the Configure widget.\n\nSee: https://alg.li/lNiZZ7");
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
return queryID;
|
|
39
31
|
};
|
|
40
|
-
|
|
41
32
|
var getPositions = function getPositions(selectedHits) {
|
|
42
33
|
return selectedHits.map(function (hit) {
|
|
43
34
|
return hit.__position;
|
|
44
35
|
});
|
|
45
36
|
};
|
|
46
|
-
|
|
47
37
|
export var inferPayload = function inferPayload(_ref) {
|
|
48
38
|
var method = _ref.method,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
results = _ref.results,
|
|
40
|
+
hits = _ref.hits,
|
|
41
|
+
objectIDs = _ref.objectIDs;
|
|
52
42
|
var index = results.index;
|
|
53
43
|
var selectedHits = getSelectedHits(hits, objectIDs);
|
|
54
44
|
var queryID = getQueryID(selectedHits);
|
|
55
|
-
|
|
56
45
|
switch (method) {
|
|
57
46
|
case 'clickedObjectIDsAfterSearch':
|
|
58
47
|
{
|
|
@@ -64,39 +53,32 @@ export var inferPayload = function inferPayload(_ref) {
|
|
|
64
53
|
positions: positions
|
|
65
54
|
};
|
|
66
55
|
}
|
|
67
|
-
|
|
68
56
|
case 'convertedObjectIDsAfterSearch':
|
|
69
57
|
return {
|
|
70
58
|
index: index,
|
|
71
59
|
queryID: queryID,
|
|
72
60
|
objectIDs: objectIDs
|
|
73
61
|
};
|
|
74
|
-
|
|
75
62
|
default:
|
|
76
63
|
throw new Error("Unsupported method passed to insights: \"".concat(method, "\"."));
|
|
77
64
|
}
|
|
78
65
|
};
|
|
79
|
-
|
|
80
66
|
var wrapInsightsClient = function wrapInsightsClient(aa, results, hits) {
|
|
81
67
|
return function (method) {
|
|
82
68
|
for (var _len = arguments.length, payloads = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
83
69
|
payloads[_key - 1] = arguments[_key];
|
|
84
70
|
}
|
|
85
|
-
|
|
86
71
|
var payload = payloads[0];
|
|
87
72
|
process.env.NODE_ENV === 'development' ? warning(false, "`insights` function 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;
|
|
88
|
-
|
|
89
73
|
if (!aa) {
|
|
90
74
|
var withInstantSearchUsage = createDocumentationMessageGenerator({
|
|
91
75
|
name: 'instantsearch'
|
|
92
76
|
});
|
|
93
77
|
throw new Error(withInstantSearchUsage('The `insightsClient` option has not been provided to `instantsearch`.'));
|
|
94
78
|
}
|
|
95
|
-
|
|
96
79
|
if (!Array.isArray(payload.objectIDs)) {
|
|
97
80
|
throw new TypeError('Expected `objectIDs` to be an array.');
|
|
98
81
|
}
|
|
99
|
-
|
|
100
82
|
var inferredPayload = inferPayload({
|
|
101
83
|
method: method,
|
|
102
84
|
results: results,
|
|
@@ -106,26 +88,23 @@ var wrapInsightsClient = function wrapInsightsClient(aa, results, hits) {
|
|
|
106
88
|
aa(method, _objectSpread(_objectSpread({}, inferredPayload), payload));
|
|
107
89
|
};
|
|
108
90
|
};
|
|
91
|
+
|
|
109
92
|
/**
|
|
110
93
|
* @deprecated This function will be still supported in 4.x releases, but not further. It is replaced by the `insights` middleware. For 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/
|
|
111
94
|
* It passes `insights` to `HitsWithInsightsListener` and `InfiniteHitsWithInsightsListener`.
|
|
112
95
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
96
|
export default function withInsights(connector) {
|
|
116
97
|
return function (renderFn, unmountFn) {
|
|
117
98
|
return connector(function (renderOptions, isFirstRender) {
|
|
118
99
|
var results = renderOptions.results,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
100
|
+
hits = renderOptions.hits,
|
|
101
|
+
instantSearchInstance = renderOptions.instantSearchInstance;
|
|
122
102
|
if (results && hits && instantSearchInstance) {
|
|
123
103
|
var insights = wrapInsightsClient(instantSearchInstance.insightsClient, results, hits);
|
|
124
104
|
return renderFn(_objectSpread(_objectSpread({}, renderOptions), {}, {
|
|
125
105
|
insights: insights
|
|
126
106
|
}), isFirstRender);
|
|
127
107
|
}
|
|
128
|
-
|
|
129
108
|
return renderFn(renderOptions, isFirstRender);
|
|
130
109
|
}, unmountFn);
|
|
131
110
|
};
|
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
import { h } from 'preact';
|
|
2
2
|
import { deserializePayload } from "../utils/index.js";
|
|
3
3
|
import { readDataAttributes, hasDataAttributes } from "../../helpers/insights.js";
|
|
4
|
-
|
|
5
4
|
var findInsightsTarget = function findInsightsTarget(startElement, endElement, validator) {
|
|
6
5
|
var element = startElement;
|
|
7
|
-
|
|
8
6
|
while (element && !validator(element)) {
|
|
9
7
|
if (element === endElement) {
|
|
10
8
|
return null;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
element = element.parentElement;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
return element;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
var parseInsightsEvent = function parseInsightsEvent(element) {
|
|
20
15
|
var serializedPayload = element.getAttribute('data-insights-event');
|
|
21
|
-
|
|
22
16
|
if (typeof serializedPayload !== 'string') {
|
|
23
17
|
throw new Error('The insights middleware expects `data-insights-event` to be a base64-encoded JSON string.');
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
try {
|
|
27
20
|
return deserializePayload(serializedPayload);
|
|
28
21
|
} catch (error) {
|
|
29
22
|
throw new Error('The insights middleware was unable to parse `data-insights-event`.');
|
|
30
23
|
}
|
|
31
24
|
};
|
|
32
|
-
|
|
33
25
|
var insightsListener = function insightsListener(BaseComponent) {
|
|
34
26
|
function WithInsightsListener(props) {
|
|
35
27
|
var handleClick = function handleClick(event) {
|
|
@@ -38,35 +30,29 @@ var insightsListener = function insightsListener(BaseComponent) {
|
|
|
38
30
|
var targetWithEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
39
31
|
return element.hasAttribute('data-insights-event');
|
|
40
32
|
});
|
|
41
|
-
|
|
42
33
|
if (targetWithEvent) {
|
|
43
34
|
var payload = parseInsightsEvent(targetWithEvent);
|
|
44
35
|
payload.forEach(function (single) {
|
|
45
36
|
return props.sendEvent(single);
|
|
46
37
|
});
|
|
47
38
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
39
|
+
}
|
|
50
40
|
|
|
41
|
+
// old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
|
|
51
42
|
var insightsTarget = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
52
43
|
return hasDataAttributes(element);
|
|
53
44
|
});
|
|
54
|
-
|
|
55
45
|
if (insightsTarget) {
|
|
56
46
|
var _readDataAttributes = readDataAttributes(insightsTarget),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
method = _readDataAttributes.method,
|
|
48
|
+
_payload = _readDataAttributes.payload;
|
|
60
49
|
props.insights(method, _payload);
|
|
61
50
|
}
|
|
62
51
|
};
|
|
63
|
-
|
|
64
52
|
return h("div", {
|
|
65
53
|
onClick: handleClick
|
|
66
54
|
}, h(BaseComponent, props));
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
return WithInsightsListener;
|
|
70
57
|
};
|
|
71
|
-
|
|
72
58
|
export default insightsListener;
|
|
@@ -1,14 +1,12 @@
|
|
|
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); }
|
|
1
2
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
3
|
+
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); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
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); }
|
|
9
8
|
import qs from 'qs';
|
|
10
9
|
import { safelyRunOnBrowser } from "../utils/index.js";
|
|
11
|
-
|
|
12
10
|
var setWindowTitle = function setWindowTitle(title) {
|
|
13
11
|
if (title) {
|
|
14
12
|
// This function is only executed on browsers so we can disable this check.
|
|
@@ -16,7 +14,6 @@ var setWindowTitle = function setWindowTitle(title) {
|
|
|
16
14
|
window.document.title = title;
|
|
17
15
|
}
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
var BrowserHistory = /*#__PURE__*/function () {
|
|
21
18
|
/**
|
|
22
19
|
* Initializes a new storage provider that syncs the search state to the URL
|
|
@@ -24,34 +21,22 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
24
21
|
*/
|
|
25
22
|
function BrowserHistory(_ref) {
|
|
26
23
|
var _this = this;
|
|
27
|
-
|
|
28
24
|
var windowTitle = _ref.windowTitle,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
_ref$writeDelay = _ref.writeDelay,
|
|
26
|
+
writeDelay = _ref$writeDelay === void 0 ? 400 : _ref$writeDelay,
|
|
27
|
+
createURL = _ref.createURL,
|
|
28
|
+
parseURL = _ref.parseURL,
|
|
29
|
+
getLocation = _ref.getLocation;
|
|
35
30
|
_classCallCheck(this, BrowserHistory);
|
|
36
|
-
|
|
37
31
|
_defineProperty(this, "windowTitle", void 0);
|
|
38
|
-
|
|
39
32
|
_defineProperty(this, "writeDelay", void 0);
|
|
40
|
-
|
|
41
33
|
_defineProperty(this, "_createURL", void 0);
|
|
42
|
-
|
|
43
34
|
_defineProperty(this, "parseURL", void 0);
|
|
44
|
-
|
|
45
35
|
_defineProperty(this, "getLocation", void 0);
|
|
46
|
-
|
|
47
36
|
_defineProperty(this, "writeTimer", void 0);
|
|
48
|
-
|
|
49
37
|
_defineProperty(this, "inPopState", false);
|
|
50
|
-
|
|
51
38
|
_defineProperty(this, "isDisposed", false);
|
|
52
|
-
|
|
53
39
|
_defineProperty(this, "latestAcknowledgedHistory", 0);
|
|
54
|
-
|
|
55
40
|
this.windowTitle = windowTitle;
|
|
56
41
|
this.writeTimer = undefined;
|
|
57
42
|
this.writeDelay = writeDelay;
|
|
@@ -60,18 +45,15 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
60
45
|
this.getLocation = getLocation;
|
|
61
46
|
safelyRunOnBrowser(function (_ref2) {
|
|
62
47
|
var window = _ref2.window;
|
|
63
|
-
|
|
64
48
|
var title = _this.windowTitle && _this.windowTitle(_this.read());
|
|
65
|
-
|
|
66
49
|
setWindowTitle(title);
|
|
67
50
|
_this.latestAcknowledgedHistory = window.history.length;
|
|
68
51
|
});
|
|
69
52
|
}
|
|
53
|
+
|
|
70
54
|
/**
|
|
71
55
|
* Reads the URL and returns a syncable UI search state.
|
|
72
56
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
57
|
_createClass(BrowserHistory, [{
|
|
76
58
|
key: "read",
|
|
77
59
|
value: function read() {
|
|
@@ -80,72 +62,58 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
80
62
|
location: this.getLocation()
|
|
81
63
|
});
|
|
82
64
|
}
|
|
65
|
+
|
|
83
66
|
/**
|
|
84
67
|
* Pushes a search state into the URL.
|
|
85
68
|
*/
|
|
86
|
-
|
|
87
69
|
}, {
|
|
88
70
|
key: "write",
|
|
89
71
|
value: function write(routeState) {
|
|
90
72
|
var _this2 = this;
|
|
91
|
-
|
|
92
73
|
safelyRunOnBrowser(function (_ref3) {
|
|
93
74
|
var window = _ref3.window;
|
|
94
|
-
|
|
95
75
|
var url = _this2.createURL(routeState);
|
|
96
|
-
|
|
97
76
|
var title = _this2.windowTitle && _this2.windowTitle(routeState);
|
|
98
|
-
|
|
99
77
|
if (_this2.writeTimer) {
|
|
100
78
|
clearTimeout(_this2.writeTimer);
|
|
101
79
|
}
|
|
102
|
-
|
|
103
80
|
_this2.writeTimer = setTimeout(function () {
|
|
104
81
|
setWindowTitle(title);
|
|
105
|
-
|
|
106
82
|
if (_this2.shouldWrite(url)) {
|
|
107
83
|
window.history.pushState(routeState, title || '', url);
|
|
108
84
|
_this2.latestAcknowledgedHistory = window.history.length;
|
|
109
85
|
}
|
|
110
|
-
|
|
111
86
|
_this2.inPopState = false;
|
|
112
87
|
_this2.writeTimer = undefined;
|
|
113
88
|
}, _this2.writeDelay);
|
|
114
89
|
});
|
|
115
90
|
}
|
|
91
|
+
|
|
116
92
|
/**
|
|
117
93
|
* Sets a callback on the `onpopstate` event of the history API of the current page.
|
|
118
94
|
* It enables the URL sync to keep track of the changes.
|
|
119
95
|
*/
|
|
120
|
-
|
|
121
96
|
}, {
|
|
122
97
|
key: "onUpdate",
|
|
123
98
|
value: function onUpdate(callback) {
|
|
124
99
|
var _this3 = this;
|
|
125
|
-
|
|
126
|
-
this._onPopState = function (event) {
|
|
100
|
+
this._onPopState = function () {
|
|
127
101
|
if (_this3.writeTimer) {
|
|
128
102
|
clearTimeout(_this3.writeTimer);
|
|
129
103
|
_this3.writeTimer = undefined;
|
|
130
104
|
}
|
|
131
|
-
|
|
132
105
|
_this3.inPopState = true;
|
|
133
|
-
var routeState = event.state; // At initial load, the state is read from the URL without update.
|
|
134
|
-
// Therefore the state object is not available.
|
|
135
|
-
// In this case, we fallback and read the URL.
|
|
136
106
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
callback(routeState);
|
|
141
|
-
}
|
|
107
|
+
// We always read the state from the URL because the state of the history
|
|
108
|
+
// can be incorect in some cases (e.g. using React Router).
|
|
109
|
+
callback(_this3.read());
|
|
142
110
|
};
|
|
143
|
-
|
|
144
111
|
safelyRunOnBrowser(function (_ref4) {
|
|
145
112
|
var window = _ref4.window;
|
|
146
113
|
window.addEventListener('popstate', _this3._onPopState);
|
|
147
114
|
});
|
|
148
115
|
}
|
|
116
|
+
|
|
149
117
|
/**
|
|
150
118
|
* Creates a complete URL from a given syncable UI state.
|
|
151
119
|
*
|
|
@@ -153,7 +121,6 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
153
121
|
* This allows to handle cases like using a <base href>.
|
|
154
122
|
* See: https://github.com/algolia/instantsearch.js/issues/790
|
|
155
123
|
*/
|
|
156
|
-
|
|
157
124
|
}, {
|
|
158
125
|
key: "createURL",
|
|
159
126
|
value: function createURL(routeState) {
|
|
@@ -163,35 +130,30 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
163
130
|
location: this.getLocation()
|
|
164
131
|
});
|
|
165
132
|
}
|
|
133
|
+
|
|
166
134
|
/**
|
|
167
135
|
* Removes the event listener and cleans up the URL.
|
|
168
136
|
*/
|
|
169
|
-
|
|
170
137
|
}, {
|
|
171
138
|
key: "dispose",
|
|
172
139
|
value: function dispose() {
|
|
173
140
|
var _this4 = this;
|
|
174
|
-
|
|
175
141
|
this.isDisposed = true;
|
|
176
142
|
safelyRunOnBrowser(function (_ref5) {
|
|
177
143
|
var window = _ref5.window;
|
|
178
|
-
|
|
179
144
|
if (_this4._onPopState) {
|
|
180
145
|
window.removeEventListener('popstate', _this4._onPopState);
|
|
181
146
|
}
|
|
182
147
|
});
|
|
183
|
-
|
|
184
148
|
if (this.writeTimer) {
|
|
185
149
|
clearTimeout(this.writeTimer);
|
|
186
150
|
}
|
|
187
|
-
|
|
188
151
|
this.write({});
|
|
189
152
|
}
|
|
190
153
|
}, {
|
|
191
154
|
key: "shouldWrite",
|
|
192
155
|
value: function shouldWrite(url) {
|
|
193
156
|
var _this5 = this;
|
|
194
|
-
|
|
195
157
|
return safelyRunOnBrowser(function (_ref6) {
|
|
196
158
|
var window = _ref6.window;
|
|
197
159
|
// We do want to `pushState` if:
|
|
@@ -200,75 +162,74 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
200
162
|
// - the last write was from InstantSearch.js
|
|
201
163
|
// (unlike a SPA, where it would have last written)
|
|
202
164
|
var lastPushWasByISAfterDispose = !(_this5.isDisposed && _this5.latestAcknowledgedHistory !== window.history.length);
|
|
203
|
-
return (
|
|
165
|
+
return (
|
|
166
|
+
// When the last state change was through popstate, the IS.js state changes,
|
|
204
167
|
// but that should not write the URL.
|
|
205
|
-
!_this5.inPopState &&
|
|
206
|
-
|
|
168
|
+
!_this5.inPopState &&
|
|
169
|
+
// When the previous pushState after dispose was by IS.js, we want to write the URL.
|
|
170
|
+
lastPushWasByISAfterDispose &&
|
|
171
|
+
// When the URL is the same as the current one, we do not want to write it.
|
|
207
172
|
url !== window.location.href
|
|
208
173
|
);
|
|
209
174
|
});
|
|
210
175
|
}
|
|
211
176
|
}]);
|
|
212
|
-
|
|
213
177
|
return BrowserHistory;
|
|
214
178
|
}();
|
|
215
|
-
|
|
216
179
|
export default function historyRouter() {
|
|
217
180
|
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
181
|
+
_ref7$createURL = _ref7.createURL,
|
|
182
|
+
createURL = _ref7$createURL === void 0 ? function (_ref8) {
|
|
183
|
+
var qsModule = _ref8.qsModule,
|
|
221
184
|
routeState = _ref8.routeState,
|
|
222
185
|
location = _ref8.location;
|
|
223
|
-
|
|
186
|
+
var protocol = location.protocol,
|
|
224
187
|
hostname = location.hostname,
|
|
225
188
|
_location$port = location.port,
|
|
226
189
|
port = _location$port === void 0 ? '' : _location$port,
|
|
227
190
|
pathname = location.pathname,
|
|
228
191
|
hash = location.hash;
|
|
229
|
-
|
|
230
|
-
|
|
192
|
+
var queryString = qsModule.stringify(routeState);
|
|
193
|
+
var portWithPrefix = port === '' ? '' : ":".concat(port);
|
|
231
194
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
|
|
238
|
-
} : _ref7$createURL,
|
|
239
|
-
_ref7$parseURL = _ref7.parseURL,
|
|
240
|
-
parseURL = _ref7$parseURL === void 0 ? function (_ref9) {
|
|
241
|
-
var qsModule = _ref9.qsModule,
|
|
242
|
-
location = _ref9.location;
|
|
243
|
-
// `qs` by default converts arrays with more than 20 items to an object.
|
|
244
|
-
// We want to avoid this because the data structure manipulated can therefore vary.
|
|
245
|
-
// Setting the limit to `100` seems a good number because the engine's default is 100
|
|
246
|
-
// (it can go up to 1000 but it is very unlikely to select more than 100 items in the UI).
|
|
247
|
-
//
|
|
248
|
-
// Using an `arrayLimit` of `n` allows `n + 1` items.
|
|
249
|
-
//
|
|
250
|
-
// See:
|
|
251
|
-
// - https://github.com/ljharb/qs#parsing-arrays
|
|
252
|
-
// - https://www.algolia.com/doc/api-reference/api-parameters/maxValuesPerFacet/
|
|
253
|
-
return qsModule.parse(location.search.slice(1), {
|
|
254
|
-
arrayLimit: 99
|
|
255
|
-
});
|
|
256
|
-
} : _ref7$parseURL,
|
|
257
|
-
_ref7$writeDelay = _ref7.writeDelay,
|
|
258
|
-
writeDelay = _ref7$writeDelay === void 0 ? 400 : _ref7$writeDelay,
|
|
259
|
-
windowTitle = _ref7.windowTitle,
|
|
260
|
-
_ref7$getLocation = _ref7.getLocation,
|
|
261
|
-
getLocation = _ref7$getLocation === void 0 ? function () {
|
|
262
|
-
return safelyRunOnBrowser(function (_ref10) {
|
|
263
|
-
var window = _ref10.window;
|
|
264
|
-
return window.location;
|
|
265
|
-
}, {
|
|
266
|
-
fallback: function fallback() {
|
|
267
|
-
throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
|
|
195
|
+
// IE <= 11 has no proper `location.origin` so we cannot rely on it.
|
|
196
|
+
if (!queryString) {
|
|
197
|
+
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname).concat(hash);
|
|
268
198
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
199
|
+
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
|
|
200
|
+
} : _ref7$createURL,
|
|
201
|
+
_ref7$parseURL = _ref7.parseURL,
|
|
202
|
+
parseURL = _ref7$parseURL === void 0 ? function (_ref9) {
|
|
203
|
+
var qsModule = _ref9.qsModule,
|
|
204
|
+
location = _ref9.location;
|
|
205
|
+
// `qs` by default converts arrays with more than 20 items to an object.
|
|
206
|
+
// We want to avoid this because the data structure manipulated can therefore vary.
|
|
207
|
+
// Setting the limit to `100` seems a good number because the engine's default is 100
|
|
208
|
+
// (it can go up to 1000 but it is very unlikely to select more than 100 items in the UI).
|
|
209
|
+
//
|
|
210
|
+
// Using an `arrayLimit` of `n` allows `n + 1` items.
|
|
211
|
+
//
|
|
212
|
+
// See:
|
|
213
|
+
// - https://github.com/ljharb/qs#parsing-arrays
|
|
214
|
+
// - https://www.algolia.com/doc/api-reference/api-parameters/maxValuesPerFacet/
|
|
215
|
+
return qsModule.parse(location.search.slice(1), {
|
|
216
|
+
arrayLimit: 99
|
|
217
|
+
});
|
|
218
|
+
} : _ref7$parseURL,
|
|
219
|
+
_ref7$writeDelay = _ref7.writeDelay,
|
|
220
|
+
writeDelay = _ref7$writeDelay === void 0 ? 400 : _ref7$writeDelay,
|
|
221
|
+
windowTitle = _ref7.windowTitle,
|
|
222
|
+
_ref7$getLocation = _ref7.getLocation,
|
|
223
|
+
getLocation = _ref7$getLocation === void 0 ? function () {
|
|
224
|
+
return safelyRunOnBrowser(function (_ref10) {
|
|
225
|
+
var window = _ref10.window;
|
|
226
|
+
return window.location;
|
|
227
|
+
}, {
|
|
228
|
+
fallback: function fallback() {
|
|
229
|
+
throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
} : _ref7$getLocation;
|
|
272
233
|
return new BrowserHistory({
|
|
273
234
|
createURL: createURL,
|
|
274
235
|
parseURL: parseURL,
|