instantsearch.js 4.49.1 → 4.49.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/cjs/components/Answers/Answers.js +6 -16
- package/cjs/components/Breadcrumb/Breadcrumb.js +5 -12
- package/cjs/components/ClearRefinements/ClearRefinements.js +4 -11
- package/cjs/components/CurrentRefinements/CurrentRefinements.js +5 -12
- package/cjs/components/GeoSearchControls/GeoSearchButton.js +4 -6
- package/cjs/components/GeoSearchControls/GeoSearchControls.js +11 -20
- package/cjs/components/GeoSearchControls/GeoSearchToggle.js +4 -6
- package/cjs/components/Highlight/Highlight.js +3 -11
- package/cjs/components/Hits/Hits.js +8 -20
- package/cjs/components/InfiniteHits/InfiniteHits.js +13 -25
- package/cjs/components/InternalHighlight/InternalHighlight.js +0 -3
- package/cjs/components/MenuSelect/MenuSelect.js +9 -19
- package/cjs/components/Pagination/Pagination.js +10 -17
- package/cjs/components/Panel/Panel.js +7 -26
- package/cjs/components/PoweredBy/PoweredBy.js +4 -5
- package/cjs/components/QueryRuleCustomData/QueryRuleCustomData.js +2 -6
- package/cjs/components/RangeInput/RangeInput.js +16 -48
- package/cjs/components/RefinementList/RefinementList.js +19 -73
- package/cjs/components/RefinementList/RefinementListItem.js +8 -14
- package/cjs/components/RelevantSort/RelevantSort.js +4 -8
- package/cjs/components/ReverseHighlight/ReverseHighlight.js +3 -11
- package/cjs/components/ReverseSnippet/ReverseSnippet.js +3 -11
- package/cjs/components/SearchBox/SearchBox.js +25 -69
- package/cjs/components/Selector/Selector.js +3 -6
- package/cjs/components/Slider/Pit.js +3 -10
- package/cjs/components/Slider/Rheostat.js +63 -131
- package/cjs/components/Slider/Slider.js +28 -65
- package/cjs/components/Snippet/Snippet.js +3 -11
- package/cjs/components/Stats/Stats.js +7 -20
- package/cjs/components/Template/Template.js +8 -37
- package/cjs/components/ToggleRefinement/ToggleRefinement.js +4 -10
- package/cjs/components/VoiceSearch/VoiceSearch.js +8 -15
- package/cjs/connectors/answers/connectAnswers.js +21 -36
- package/cjs/connectors/autocomplete/connectAutocomplete.js +8 -25
- package/cjs/connectors/breadcrumb/connectBreadcrumb.js +17 -48
- package/cjs/connectors/clear-refinements/connectClearRefinements.js +27 -45
- package/cjs/connectors/configure/connectConfigure.js +6 -20
- package/cjs/connectors/configure-related-items/connectConfigureRelatedItems.js +11 -36
- package/cjs/connectors/current-refinements/connectCurrentRefinements.js +18 -57
- package/cjs/connectors/dynamic-widgets/connectDynamicWidgets.js +17 -37
- package/cjs/connectors/geo-search/connectGeoSearch.js +17 -47
- package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +38 -74
- package/cjs/connectors/hits/connectHits.js +10 -26
- package/cjs/connectors/hits/connectHitsWithInsights.js +0 -4
- package/cjs/connectors/hits-per-page/connectHitsPerPage.js +15 -38
- package/cjs/connectors/index.js +62 -96
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +26 -62
- package/cjs/connectors/infinite-hits/connectInfiniteHitsWithInsights.js +0 -4
- package/cjs/connectors/menu/connectMenu.js +28 -66
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +24 -78
- package/cjs/connectors/pagination/Paginator.js +3 -20
- package/cjs/connectors/pagination/connectPagination.js +8 -25
- package/cjs/connectors/powered-by/connectPoweredBy.js +4 -13
- package/cjs/connectors/query-rules/connectQueryRules.js +32 -56
- package/cjs/connectors/range/connectRange.js +41 -101
- package/cjs/connectors/rating-menu/connectRatingMenu.js +23 -79
- package/cjs/connectors/refinement-list/connectRefinementList.js +37 -70
- package/cjs/connectors/relevant-sort/connectRelevantSort.js +4 -14
- package/cjs/connectors/search-box/connectSearchBox.js +7 -23
- package/cjs/connectors/sort-by/connectSortBy.js +11 -21
- package/cjs/connectors/stats/connectStats.js +4 -11
- package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +29 -63
- package/cjs/connectors/voice-search/connectVoiceSearch.js +13 -35
- package/cjs/helpers/components/Highlight.js +4 -12
- package/cjs/helpers/components/ReverseHighlight.js +7 -19
- package/cjs/helpers/components/ReverseSnippet.js +7 -19
- package/cjs/helpers/components/Snippet.js +4 -12
- package/cjs/helpers/components/index.js +0 -8
- package/cjs/helpers/get-insights-anonymous-user-token.js +4 -15
- package/cjs/helpers/highlight.js +10 -16
- package/cjs/helpers/index.js +17 -31
- package/cjs/helpers/insights.js +5 -17
- package/cjs/helpers/reverseHighlight.js +10 -16
- package/cjs/helpers/reverseSnippet.js +10 -16
- package/cjs/helpers/snippet.js +10 -16
- package/cjs/index.js +3 -18
- package/cjs/lib/InstantSearch.js +79 -180
- package/cjs/lib/createHelpers.js +4 -11
- package/cjs/lib/formatNumber.js +0 -1
- package/cjs/lib/infiniteHitsCache/index.js +0 -2
- package/cjs/lib/infiniteHitsCache/sessionStorage.js +9 -18
- package/cjs/lib/insights/client.js +8 -34
- package/cjs/lib/insights/index.js +7 -13
- package/cjs/lib/insights/listener.js +4 -20
- package/cjs/lib/routers/history.js +63 -102
- package/cjs/lib/routers/index.js +0 -2
- package/cjs/lib/stateMappings/index.js +0 -3
- package/cjs/lib/stateMappings/simple.js +6 -13
- package/cjs/lib/stateMappings/singleIndex.js +1 -7
- package/cjs/lib/suit.js +2 -5
- package/cjs/lib/templating/index.js +0 -4
- package/cjs/lib/templating/prepareTemplateProps.js +8 -19
- package/cjs/lib/templating/renderTemplate.js +9 -24
- package/cjs/lib/utils/capitalize.js +0 -1
- package/cjs/lib/utils/checkIndexUiState.js +15 -43
- package/cjs/lib/utils/checkRendering.js +0 -2
- package/cjs/lib/utils/clearRefinements.js +2 -9
- package/cjs/lib/utils/concatHighlightedParts.js +1 -3
- package/cjs/lib/utils/createConcurrentSafePromise.js +0 -3
- package/cjs/lib/utils/createSendEventForFacet.js +7 -14
- package/cjs/lib/utils/createSendEventForHits.js +9 -33
- package/cjs/lib/utils/debounce.js +0 -3
- package/cjs/lib/utils/defer.js +0 -11
- package/cjs/lib/utils/detect-insights-client.js +0 -2
- package/cjs/lib/utils/documentation.js +2 -5
- package/cjs/lib/utils/escape-highlight.js +5 -22
- 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 +14 -34
- package/cjs/lib/utils/getAppIdAndApiKey.js +2 -3
- package/cjs/lib/utils/getContainerNode.js +0 -6
- package/cjs/lib/utils/getHighlightFromSiblings.js +0 -6
- package/cjs/lib/utils/getHighlightedParts.js +1 -4
- package/cjs/lib/utils/getObjectType.js +0 -1
- package/cjs/lib/utils/getPropertyByPath.js +0 -1
- package/cjs/lib/utils/getRefinements.js +13 -26
- package/cjs/lib/utils/getWidgetAttribute.js +0 -6
- package/cjs/lib/utils/hits-absolute-position.js +2 -6
- package/cjs/lib/utils/hits-query-id.js +2 -7
- package/cjs/lib/utils/index.js +0 -92
- package/cjs/lib/utils/isDomElement.js +0 -1
- package/cjs/lib/utils/isEqual.js +0 -8
- 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 +3 -13
- package/cjs/lib/utils/mergeSearchParameters.js +16 -40
- package/cjs/lib/utils/noop.js +0 -1
- package/cjs/lib/utils/range.js +8 -14
- package/cjs/lib/utils/render-args.js +0 -2
- package/cjs/lib/utils/resolveSearchParameters.js +0 -3
- package/cjs/lib/utils/reverseHighlightedParts.js +2 -8
- package/cjs/lib/utils/safelyRunOnBrowser.js +7 -9
- package/cjs/lib/utils/serializer.js +1 -3
- package/cjs/lib/utils/setIndexHelperState.js +0 -5
- 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 +8 -36
- package/cjs/middlewares/createInsightsMiddleware.js +15 -44
- package/cjs/middlewares/createMetadataMiddleware.js +4 -12
- package/cjs/middlewares/createRouterMiddleware.js +8 -19
- package/cjs/middlewares/index.js +0 -6
- package/cjs/types/algoliasearch.js +0 -2
- package/cjs/types/index.js +0 -28
- package/cjs/widgets/analytics/analytics.js +12 -47
- package/cjs/widgets/answers/answers.js +19 -39
- package/cjs/widgets/breadcrumb/breadcrumb.js +18 -38
- package/cjs/widgets/clear-refinements/clear-refinements.js +15 -35
- package/cjs/widgets/configure/configure.js +2 -10
- package/cjs/widgets/configure-related-items/configure-related-items.js +2 -10
- package/cjs/widgets/current-refinements/current-refinements.js +12 -30
- package/cjs/widgets/dynamic-widgets/dynamic-widgets.js +6 -25
- package/cjs/widgets/geo-search/GeoSearchRenderer.js +41 -68
- package/cjs/widgets/geo-search/createHTMLMarker.js +30 -60
- package/cjs/widgets/geo-search/defaultTemplates.js +0 -3
- package/cjs/widgets/geo-search/geo-search.js +27 -59
- package/cjs/widgets/hierarchical-menu/defaultTemplates.js +4 -7
- package/cjs/widgets/hierarchical-menu/hierarchical-menu.js +28 -47
- package/cjs/widgets/hits/hits.js +16 -37
- package/cjs/widgets/hits-per-page/hits-per-page.js +13 -31
- package/cjs/widgets/index/index.js +49 -95
- package/cjs/widgets/index.js +12 -50
- package/cjs/widgets/infinite-hits/infinite-hits.js +23 -44
- package/cjs/widgets/menu/defaultTemplates.js +3 -6
- package/cjs/widgets/menu/menu.js +23 -43
- package/cjs/widgets/menu-select/defaultTemplates.js +1 -3
- package/cjs/widgets/menu-select/menu-select.js +18 -38
- package/cjs/widgets/numeric-menu/defaultTemplates.js +3 -4
- package/cjs/widgets/numeric-menu/numeric-menu.js +17 -37
- package/cjs/widgets/pagination/pagination.js +32 -53
- package/cjs/widgets/panel/panel.js +20 -48
- package/cjs/widgets/places/places.js +16 -33
- package/cjs/widgets/powered-by/powered-by.js +10 -27
- package/cjs/widgets/query-rule-context/query-rule-context.js +2 -13
- package/cjs/widgets/query-rule-custom-data/query-rule-custom-data.js +14 -32
- package/cjs/widgets/range-input/range-input.js +23 -50
- package/cjs/widgets/range-slider/range-slider.js +28 -53
- package/cjs/widgets/rating-menu/defaultTemplates.js +8 -14
- package/cjs/widgets/rating-menu/rating-menu.js +17 -38
- package/cjs/widgets/refinement-list/defaultTemplates.js +5 -8
- package/cjs/widgets/refinement-list/refinement-list.js +39 -60
- package/cjs/widgets/relevant-sort/relevant-sort.js +10 -29
- package/cjs/widgets/search-box/defaultTemplates.js +0 -5
- package/cjs/widgets/search-box/search-box.js +31 -49
- package/cjs/widgets/sort-by/sort-by.js +11 -29
- package/cjs/widgets/stats/defaultTemplates.js +0 -1
- package/cjs/widgets/stats/stats.js +27 -57
- package/cjs/widgets/toggle-refinement/toggle-refinement.js +16 -36
- package/cjs/widgets/voice-search/defaultTemplates.js +4 -14
- package/cjs/widgets/voice-search/voice-search.js +17 -36
- package/dist/instantsearch.development.d.ts +8 -6
- package/dist/instantsearch.development.js +1722 -3088
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +8 -6
- package/dist/instantsearch.production.min.d.ts +8 -6
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Answers/Answers.js +6 -11
- package/es/components/Breadcrumb/Breadcrumb.js +5 -7
- package/es/components/ClearRefinements/ClearRefinements.js +4 -6
- package/es/components/CurrentRefinements/CurrentRefinements.js +7 -10
- package/es/components/GeoSearchControls/GeoSearchButton.js +6 -6
- package/es/components/GeoSearchControls/GeoSearchControls.js +11 -13
- package/es/components/GeoSearchControls/GeoSearchToggle.js +6 -6
- package/es/components/Highlight/Highlight.js +3 -7
- package/es/components/Hits/Hits.js +8 -15
- package/es/components/InfiniteHits/InfiniteHits.js +13 -20
- package/es/components/MenuSelect/MenuSelect.js +9 -13
- package/es/components/Pagination/Pagination.js +12 -15
- package/es/components/Panel/Panel.js +7 -20
- package/es/components/PoweredBy/PoweredBy.js +6 -5
- package/es/components/QueryRuleCustomData/QueryRuleCustomData.js +4 -4
- package/es/components/RangeInput/RangeInput.js +16 -43
- package/es/components/RefinementList/RefinementList.js +19 -64
- package/es/components/RefinementList/RefinementListItem.js +8 -10
- package/es/components/RelevantSort/RelevantSort.js +6 -6
- package/es/components/ReverseHighlight/ReverseHighlight.js +3 -7
- package/es/components/ReverseSnippet/ReverseSnippet.js +3 -7
- package/es/components/SearchBox/SearchBox.js +25 -63
- package/es/components/Selector/Selector.js +5 -5
- package/es/components/Slider/Pit.js +3 -7
- package/es/components/Slider/Rheostat.js +64 -129
- package/es/components/Slider/Slider.js +28 -58
- package/es/components/Snippet/Snippet.js +3 -7
- package/es/components/Stats/Stats.js +7 -15
- package/es/components/Template/Template.js +8 -32
- package/es/components/ToggleRefinement/ToggleRefinement.js +4 -6
- package/es/components/VoiceSearch/VoiceSearch.js +10 -13
- package/es/connectors/answers/connectAnswers.js +21 -35
- package/es/connectors/autocomplete/connectAutocomplete.js +8 -23
- package/es/connectors/breadcrumb/connectBreadcrumb.js +17 -46
- package/es/connectors/clear-refinements/connectClearRefinements.js +27 -43
- package/es/connectors/configure/connectConfigure.js +7 -16
- package/es/connectors/configure-related-items/connectConfigureRelatedItems.js +11 -31
- package/es/connectors/current-refinements/connectCurrentRefinements.js +18 -55
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.js +17 -35
- package/es/connectors/geo-search/connectGeoSearch.js +17 -45
- package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +38 -72
- package/es/connectors/hits/connectHits.js +10 -24
- package/es/connectors/hits-per-page/connectHitsPerPage.js +15 -36
- package/es/connectors/index.d.ts +2 -1
- package/es/connectors/index.js +6 -3
- package/es/connectors/infinite-hits/connectInfiniteHits.js +26 -60
- package/es/connectors/menu/connectMenu.js +28 -64
- package/es/connectors/numeric-menu/connectNumericMenu.js +24 -76
- package/es/connectors/pagination/Paginator.js +3 -19
- package/es/connectors/pagination/connectPagination.js +8 -21
- package/es/connectors/powered-by/connectPoweredBy.js +4 -11
- package/es/connectors/query-rules/connectQueryRules.js +32 -54
- package/es/connectors/range/connectRange.js +41 -99
- package/es/connectors/rating-menu/connectRatingMenu.js +23 -77
- package/es/connectors/refinement-list/connectRefinementList.js +37 -68
- package/es/connectors/relevant-sort/connectRelevantSort.js +4 -13
- package/es/connectors/search-box/connectSearchBox.js +7 -21
- package/es/connectors/sort-by/connectSortBy.js +11 -19
- package/es/connectors/stats/connectStats.js +4 -9
- package/es/connectors/toggle-refinement/connectToggleRefinement.js +29 -61
- package/es/connectors/voice-search/connectVoiceSearch.js +13 -31
- package/es/helpers/components/Highlight.js +4 -8
- package/es/helpers/components/ReverseHighlight.js +7 -15
- package/es/helpers/components/ReverseSnippet.js +7 -15
- package/es/helpers/components/Snippet.js +4 -8
- package/es/helpers/get-insights-anonymous-user-token.js +2 -10
- package/es/helpers/highlight.js +9 -11
- package/es/helpers/insights.js +3 -10
- package/es/helpers/reverseHighlight.js +9 -11
- package/es/helpers/reverseSnippet.js +9 -11
- package/es/helpers/snippet.js +9 -11
- package/es/index.js +0 -2
- package/es/lib/InstantSearch.js +79 -170
- package/es/lib/createHelpers.js +4 -8
- package/es/lib/infiniteHitsCache/sessionStorage.js +9 -16
- package/es/lib/insights/client.js +8 -32
- package/es/lib/insights/listener.js +6 -18
- package/es/lib/routers/history.js +63 -99
- package/es/lib/stateMappings/simple.js +6 -12
- package/es/lib/stateMappings/singleIndex.js +1 -6
- package/es/lib/suit.js +2 -3
- package/es/lib/templating/prepareTemplateProps.js +8 -18
- package/es/lib/templating/renderTemplate.js +9 -20
- package/es/lib/utils/checkIndexUiState.js +18 -40
- 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 +3 -16
- 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 +14 -32
- 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 +13 -24
- package/es/lib/utils/getWidgetAttribute.js +0 -5
- package/es/lib/utils/hits-absolute-position.js +2 -5
- package/es/lib/utils/hits-query-id.js +2 -6
- package/es/lib/utils/isEqual.js +0 -7
- package/es/lib/utils/isPlainObject.js +3 -10
- package/es/lib/utils/logger.js +2 -12
- package/es/lib/utils/mergeSearchParameters.js +16 -37
- package/es/lib/utils/range.js +8 -13
- package/es/lib/utils/resolveSearchParameters.js +0 -2
- package/es/lib/utils/reverseHighlightedParts.js +2 -6
- 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 +8 -35
- package/es/middlewares/createInsightsMiddleware.js +15 -41
- package/es/middlewares/createMetadataMiddleware.js +3 -9
- package/es/middlewares/createRouterMiddleware.js +8 -13
- package/es/types/index.js +9 -5
- package/es/widgets/analytics/analytics.js +12 -45
- package/es/widgets/answers/answers.js +19 -28
- package/es/widgets/breadcrumb/breadcrumb.js +18 -27
- package/es/widgets/clear-refinements/clear-refinements.js +15 -24
- package/es/widgets/configure/configure.js +3 -6
- package/es/widgets/configure-related-items/configure-related-items.js +2 -7
- package/es/widgets/current-refinements/current-refinements.js +12 -21
- package/es/widgets/dynamic-widgets/dynamic-widgets.js +6 -20
- package/es/widgets/geo-search/GeoSearchRenderer.js +41 -63
- package/es/widgets/geo-search/createHTMLMarker.js +30 -59
- package/es/widgets/geo-search/defaultTemplates.js +2 -2
- package/es/widgets/geo-search/geo-search.js +27 -49
- package/es/widgets/hierarchical-menu/defaultTemplates.js +5 -4
- package/es/widgets/hierarchical-menu/hierarchical-menu.js +28 -36
- package/es/widgets/hits/hits.js +16 -25
- package/es/widgets/hits-per-page/hits-per-page.js +13 -22
- package/es/widgets/index/index.js +49 -91
- package/es/widgets/index.d.ts +2 -1
- package/es/widgets/index.js +4 -3
- package/es/widgets/infinite-hits/infinite-hits.js +23 -32
- package/es/widgets/menu/defaultTemplates.js +4 -3
- package/es/widgets/menu/menu.js +23 -32
- package/es/widgets/menu-select/defaultTemplates.js +1 -1
- package/es/widgets/menu-select/menu-select.js +18 -27
- package/es/widgets/numeric-menu/defaultTemplates.js +4 -3
- package/es/widgets/numeric-menu/numeric-menu.js +17 -26
- package/es/widgets/pagination/pagination.js +32 -44
- package/es/widgets/panel/panel.js +20 -40
- package/es/widgets/places/places.js +16 -32
- package/es/widgets/powered-by/powered-by.js +10 -18
- package/es/widgets/query-rule-context/query-rule-context.js +2 -9
- package/es/widgets/query-rule-custom-data/query-rule-custom-data.js +13 -22
- package/es/widgets/range-input/range-input.js +23 -40
- package/es/widgets/range-slider/range-slider.js +28 -44
- package/es/widgets/rating-menu/defaultTemplates.js +9 -12
- package/es/widgets/rating-menu/rating-menu.js +17 -27
- package/es/widgets/refinement-list/defaultTemplates.js +6 -5
- package/es/widgets/refinement-list/refinement-list.js +39 -48
- package/es/widgets/relevant-sort/relevant-sort.js +10 -19
- package/es/widgets/search-box/defaultTemplates.js +1 -4
- package/es/widgets/search-box/search-box.js +31 -39
- package/es/widgets/sort-by/sort-by.js +11 -20
- package/es/widgets/stats/stats.js +26 -45
- package/es/widgets/toggle-refinement/toggle-refinement.js +16 -25
- package/es/widgets/voice-search/defaultTemplates.js +5 -13
- package/es/widgets/voice-search/voice-search.js +17 -26
- 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/CHANGELOG.md +0 -3693
package/es/lib/createHelpers.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
1
|
+
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; }
|
|
2
|
+
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; }
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
import { highlight as _highlight, reverseHighlight as _reverseHighlight, snippet as _snippet, reverseSnippet as _reverseSnippet, insights as _insights } from "../helpers/index.js";
|
|
8
5
|
import { formatNumber as _formatNumber } from "./formatNumber.js";
|
|
9
6
|
export default function hoganHelpers(_ref) {
|
|
@@ -55,9 +52,8 @@ export default function hoganHelpers(_ref) {
|
|
|
55
52
|
insights: function insights(options, render) {
|
|
56
53
|
try {
|
|
57
54
|
var _JSON$parse = JSON.parse(options),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
method = _JSON$parse.method,
|
|
56
|
+
payload = _JSON$parse.payload;
|
|
61
57
|
return render(_insights(method, _objectSpread({
|
|
62
58
|
objectIDs: [this.objectID]
|
|
63
59
|
}, payload)));
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
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
2
|
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
3
|
import { isEqual, safelyRunOnBrowser } from "../utils/index.js";
|
|
6
|
-
|
|
7
4
|
function getStateWithoutPage(state) {
|
|
8
5
|
var _ref = state || {},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
page = _ref.page,
|
|
7
|
+
rest = _objectWithoutProperties(_ref, ["page"]);
|
|
12
8
|
return rest;
|
|
13
9
|
}
|
|
14
|
-
|
|
15
10
|
var KEY = 'ais.infiniteHits';
|
|
16
11
|
export default function createInfiniteHitsSessionStorageCache() {
|
|
17
12
|
return {
|
|
@@ -21,44 +16,42 @@ export default function createInfiniteHitsSessionStorageCache() {
|
|
|
21
16
|
var window = _ref3.window;
|
|
22
17
|
return window.sessionStorage;
|
|
23
18
|
});
|
|
24
|
-
|
|
25
19
|
if (!sessionStorage) {
|
|
26
20
|
return null;
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
try {
|
|
30
|
-
var cache = JSON.parse(
|
|
23
|
+
var cache = JSON.parse(
|
|
24
|
+
// @ts-expect-error JSON.parse() requires a string, but it actually accepts null, too.
|
|
31
25
|
sessionStorage.getItem(KEY));
|
|
32
26
|
return cache && isEqual(cache.state, getStateWithoutPage(state)) ? cache.hits : null;
|
|
33
27
|
} catch (error) {
|
|
34
28
|
if (error instanceof SyntaxError) {
|
|
35
29
|
try {
|
|
36
30
|
sessionStorage.removeItem(KEY);
|
|
37
|
-
} catch (err) {
|
|
31
|
+
} catch (err) {
|
|
32
|
+
// do nothing
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
|
-
|
|
41
35
|
return null;
|
|
42
36
|
}
|
|
43
37
|
},
|
|
44
38
|
write: function write(_ref4) {
|
|
45
39
|
var state = _ref4.state,
|
|
46
|
-
|
|
40
|
+
hits = _ref4.hits;
|
|
47
41
|
var sessionStorage = safelyRunOnBrowser(function (_ref5) {
|
|
48
42
|
var window = _ref5.window;
|
|
49
43
|
return window.sessionStorage;
|
|
50
44
|
});
|
|
51
|
-
|
|
52
45
|
if (!sessionStorage) {
|
|
53
46
|
return;
|
|
54
47
|
}
|
|
55
|
-
|
|
56
48
|
try {
|
|
57
49
|
sessionStorage.setItem(KEY, JSON.stringify({
|
|
58
50
|
state: getStateWithoutPage(state),
|
|
59
51
|
hits: hits
|
|
60
52
|
}));
|
|
61
|
-
} catch (error) {
|
|
53
|
+
} catch (error) {
|
|
54
|
+
// do nothing
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
};
|
|
@@ -1,58 +1,44 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
1
|
+
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; }
|
|
2
|
+
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; }
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
import { uniq, find, createDocumentationMessageGenerator, warning } from "../utils/index.js";
|
|
8
|
-
|
|
9
5
|
var getSelectedHits = function getSelectedHits(hits, selectedObjectIDs) {
|
|
10
6
|
return selectedObjectIDs.map(function (objectID) {
|
|
11
7
|
var hit = find(hits, function (h) {
|
|
12
8
|
return h.objectID === objectID;
|
|
13
9
|
});
|
|
14
|
-
|
|
15
10
|
if (typeof hit === 'undefined') {
|
|
16
11
|
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
12
|
}
|
|
18
|
-
|
|
19
13
|
return hit;
|
|
20
14
|
});
|
|
21
15
|
};
|
|
22
|
-
|
|
23
16
|
var getQueryID = function getQueryID(selectedHits) {
|
|
24
17
|
var queryIDs = uniq(selectedHits.map(function (hit) {
|
|
25
18
|
return hit.__queryID;
|
|
26
19
|
}));
|
|
27
|
-
|
|
28
20
|
if (queryIDs.length > 1) {
|
|
29
21
|
throw new Error('Insights currently allows a single `queryID`. The `objectIDs` provided map to multiple `queryID`s.');
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
var queryID = queryIDs[0];
|
|
33
|
-
|
|
34
24
|
if (typeof queryID !== 'string') {
|
|
35
25
|
throw new Error("Could not infer `queryID`. Ensure InstantSearch `clickAnalytics: true` was added with the Configure widget.\n\nSee: https://alg.li/lNiZZ7");
|
|
36
26
|
}
|
|
37
|
-
|
|
38
27
|
return queryID;
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
var getPositions = function getPositions(selectedHits) {
|
|
42
30
|
return selectedHits.map(function (hit) {
|
|
43
31
|
return hit.__position;
|
|
44
32
|
});
|
|
45
33
|
};
|
|
46
|
-
|
|
47
34
|
export var inferPayload = function inferPayload(_ref) {
|
|
48
35
|
var method = _ref.method,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
results = _ref.results,
|
|
37
|
+
hits = _ref.hits,
|
|
38
|
+
objectIDs = _ref.objectIDs;
|
|
52
39
|
var index = results.index;
|
|
53
40
|
var selectedHits = getSelectedHits(hits, objectIDs);
|
|
54
41
|
var queryID = getQueryID(selectedHits);
|
|
55
|
-
|
|
56
42
|
switch (method) {
|
|
57
43
|
case 'clickedObjectIDsAfterSearch':
|
|
58
44
|
{
|
|
@@ -64,39 +50,32 @@ export var inferPayload = function inferPayload(_ref) {
|
|
|
64
50
|
positions: positions
|
|
65
51
|
};
|
|
66
52
|
}
|
|
67
|
-
|
|
68
53
|
case 'convertedObjectIDsAfterSearch':
|
|
69
54
|
return {
|
|
70
55
|
index: index,
|
|
71
56
|
queryID: queryID,
|
|
72
57
|
objectIDs: objectIDs
|
|
73
58
|
};
|
|
74
|
-
|
|
75
59
|
default:
|
|
76
60
|
throw new Error("Unsupported method passed to insights: \"".concat(method, "\"."));
|
|
77
61
|
}
|
|
78
62
|
};
|
|
79
|
-
|
|
80
63
|
var wrapInsightsClient = function wrapInsightsClient(aa, results, hits) {
|
|
81
64
|
return function (method) {
|
|
82
65
|
for (var _len = arguments.length, payloads = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
83
66
|
payloads[_key - 1] = arguments[_key];
|
|
84
67
|
}
|
|
85
|
-
|
|
86
68
|
var payload = payloads[0];
|
|
87
69
|
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
70
|
if (!aa) {
|
|
90
71
|
var withInstantSearchUsage = createDocumentationMessageGenerator({
|
|
91
72
|
name: 'instantsearch'
|
|
92
73
|
});
|
|
93
74
|
throw new Error(withInstantSearchUsage('The `insightsClient` option has not been provided to `instantsearch`.'));
|
|
94
75
|
}
|
|
95
|
-
|
|
96
76
|
if (!Array.isArray(payload.objectIDs)) {
|
|
97
77
|
throw new TypeError('Expected `objectIDs` to be an array.');
|
|
98
78
|
}
|
|
99
|
-
|
|
100
79
|
var inferredPayload = inferPayload({
|
|
101
80
|
method: method,
|
|
102
81
|
results: results,
|
|
@@ -106,26 +85,23 @@ var wrapInsightsClient = function wrapInsightsClient(aa, results, hits) {
|
|
|
106
85
|
aa(method, _objectSpread(_objectSpread({}, inferredPayload), payload));
|
|
107
86
|
};
|
|
108
87
|
};
|
|
88
|
+
|
|
109
89
|
/**
|
|
110
90
|
* @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
91
|
* It passes `insights` to `HitsWithInsightsListener` and `InfiniteHitsWithInsightsListener`.
|
|
112
92
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
93
|
export default function withInsights(connector) {
|
|
116
94
|
return function (renderFn, unmountFn) {
|
|
117
95
|
return connector(function (renderOptions, isFirstRender) {
|
|
118
96
|
var results = renderOptions.results,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
97
|
+
hits = renderOptions.hits,
|
|
98
|
+
instantSearchInstance = renderOptions.instantSearchInstance;
|
|
122
99
|
if (results && hits && instantSearchInstance) {
|
|
123
100
|
var insights = wrapInsightsClient(instantSearchInstance.insightsClient, results, hits);
|
|
124
101
|
return renderFn(_objectSpread(_objectSpread({}, renderOptions), {}, {
|
|
125
102
|
insights: insights
|
|
126
103
|
}), isFirstRender);
|
|
127
104
|
}
|
|
128
|
-
|
|
129
105
|
return renderFn(renderOptions, isFirstRender);
|
|
130
106
|
}, unmountFn);
|
|
131
107
|
};
|
|
@@ -1,35 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import { h } from 'preact';
|
|
2
4
|
import { deserializePayload } from "../utils/index.js";
|
|
3
5
|
import { readDataAttributes, hasDataAttributes } from "../../helpers/insights.js";
|
|
4
|
-
|
|
5
6
|
var findInsightsTarget = function findInsightsTarget(startElement, endElement, validator) {
|
|
6
7
|
var element = startElement;
|
|
7
|
-
|
|
8
8
|
while (element && !validator(element)) {
|
|
9
9
|
if (element === endElement) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
element = element.parentElement;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
return element;
|
|
17
15
|
};
|
|
18
|
-
|
|
19
16
|
var parseInsightsEvent = function parseInsightsEvent(element) {
|
|
20
17
|
var serializedPayload = element.getAttribute('data-insights-event');
|
|
21
|
-
|
|
22
18
|
if (typeof serializedPayload !== 'string') {
|
|
23
19
|
throw new Error('The insights middleware expects `data-insights-event` to be a base64-encoded JSON string.');
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
try {
|
|
27
22
|
return deserializePayload(serializedPayload);
|
|
28
23
|
} catch (error) {
|
|
29
24
|
throw new Error('The insights middleware was unable to parse `data-insights-event`.');
|
|
30
25
|
}
|
|
31
26
|
};
|
|
32
|
-
|
|
33
27
|
var insightsListener = function insightsListener(BaseComponent) {
|
|
34
28
|
function WithInsightsListener(props) {
|
|
35
29
|
var handleClick = function handleClick(event) {
|
|
@@ -38,35 +32,29 @@ var insightsListener = function insightsListener(BaseComponent) {
|
|
|
38
32
|
var targetWithEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
39
33
|
return element.hasAttribute('data-insights-event');
|
|
40
34
|
});
|
|
41
|
-
|
|
42
35
|
if (targetWithEvent) {
|
|
43
36
|
var payload = parseInsightsEvent(targetWithEvent);
|
|
44
37
|
payload.forEach(function (single) {
|
|
45
38
|
return props.sendEvent(single);
|
|
46
39
|
});
|
|
47
40
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
41
|
+
}
|
|
50
42
|
|
|
43
|
+
// old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
|
|
51
44
|
var insightsTarget = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
52
45
|
return hasDataAttributes(element);
|
|
53
46
|
});
|
|
54
|
-
|
|
55
47
|
if (insightsTarget) {
|
|
56
48
|
var _readDataAttributes = readDataAttributes(insightsTarget),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
method = _readDataAttributes.method,
|
|
50
|
+
_payload = _readDataAttributes.payload;
|
|
60
51
|
props.insights(method, _payload);
|
|
61
52
|
}
|
|
62
53
|
};
|
|
63
|
-
|
|
64
54
|
return h("div", {
|
|
65
55
|
onClick: handleClick
|
|
66
56
|
}, h(BaseComponent, props));
|
|
67
57
|
}
|
|
68
|
-
|
|
69
58
|
return WithInsightsListener;
|
|
70
59
|
};
|
|
71
|
-
|
|
72
60
|
export default insightsListener;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
-
|
|
3
2
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4
|
-
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
6
|
-
|
|
3
|
+
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
4
|
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
|
-
|
|
9
5
|
import qs from 'qs';
|
|
10
6
|
import { safelyRunOnBrowser } from "../utils/index.js";
|
|
11
|
-
|
|
12
7
|
var setWindowTitle = function setWindowTitle(title) {
|
|
13
8
|
if (title) {
|
|
14
9
|
// This function is only executed on browsers so we can disable this check.
|
|
@@ -16,7 +11,6 @@ var setWindowTitle = function setWindowTitle(title) {
|
|
|
16
11
|
window.document.title = title;
|
|
17
12
|
}
|
|
18
13
|
};
|
|
19
|
-
|
|
20
14
|
var BrowserHistory = /*#__PURE__*/function () {
|
|
21
15
|
/**
|
|
22
16
|
* Initializes a new storage provider that syncs the search state to the URL
|
|
@@ -24,34 +18,22 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
24
18
|
*/
|
|
25
19
|
function BrowserHistory(_ref) {
|
|
26
20
|
var _this = this;
|
|
27
|
-
|
|
28
21
|
var windowTitle = _ref.windowTitle,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
_ref$writeDelay = _ref.writeDelay,
|
|
23
|
+
writeDelay = _ref$writeDelay === void 0 ? 400 : _ref$writeDelay,
|
|
24
|
+
createURL = _ref.createURL,
|
|
25
|
+
parseURL = _ref.parseURL,
|
|
26
|
+
getLocation = _ref.getLocation;
|
|
35
27
|
_classCallCheck(this, BrowserHistory);
|
|
36
|
-
|
|
37
28
|
_defineProperty(this, "windowTitle", void 0);
|
|
38
|
-
|
|
39
29
|
_defineProperty(this, "writeDelay", void 0);
|
|
40
|
-
|
|
41
30
|
_defineProperty(this, "_createURL", void 0);
|
|
42
|
-
|
|
43
31
|
_defineProperty(this, "parseURL", void 0);
|
|
44
|
-
|
|
45
32
|
_defineProperty(this, "getLocation", void 0);
|
|
46
|
-
|
|
47
33
|
_defineProperty(this, "writeTimer", void 0);
|
|
48
|
-
|
|
49
34
|
_defineProperty(this, "inPopState", false);
|
|
50
|
-
|
|
51
35
|
_defineProperty(this, "isDisposed", false);
|
|
52
|
-
|
|
53
36
|
_defineProperty(this, "latestAcknowledgedHistory", 0);
|
|
54
|
-
|
|
55
37
|
this.windowTitle = windowTitle;
|
|
56
38
|
this.writeTimer = undefined;
|
|
57
39
|
this.writeDelay = writeDelay;
|
|
@@ -60,18 +42,15 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
60
42
|
this.getLocation = getLocation;
|
|
61
43
|
safelyRunOnBrowser(function (_ref2) {
|
|
62
44
|
var window = _ref2.window;
|
|
63
|
-
|
|
64
45
|
var title = _this.windowTitle && _this.windowTitle(_this.read());
|
|
65
|
-
|
|
66
46
|
setWindowTitle(title);
|
|
67
47
|
_this.latestAcknowledgedHistory = window.history.length;
|
|
68
48
|
});
|
|
69
49
|
}
|
|
50
|
+
|
|
70
51
|
/**
|
|
71
52
|
* Reads the URL and returns a syncable UI search state.
|
|
72
53
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
54
|
_createClass(BrowserHistory, [{
|
|
76
55
|
key: "read",
|
|
77
56
|
value: function read() {
|
|
@@ -80,72 +59,64 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
80
59
|
location: this.getLocation()
|
|
81
60
|
});
|
|
82
61
|
}
|
|
62
|
+
|
|
83
63
|
/**
|
|
84
64
|
* Pushes a search state into the URL.
|
|
85
65
|
*/
|
|
86
|
-
|
|
87
66
|
}, {
|
|
88
67
|
key: "write",
|
|
89
68
|
value: function write(routeState) {
|
|
90
69
|
var _this2 = this;
|
|
91
|
-
|
|
92
70
|
safelyRunOnBrowser(function (_ref3) {
|
|
93
71
|
var window = _ref3.window;
|
|
94
|
-
|
|
95
72
|
var url = _this2.createURL(routeState);
|
|
96
|
-
|
|
97
73
|
var title = _this2.windowTitle && _this2.windowTitle(routeState);
|
|
98
|
-
|
|
99
74
|
if (_this2.writeTimer) {
|
|
100
75
|
clearTimeout(_this2.writeTimer);
|
|
101
76
|
}
|
|
102
|
-
|
|
103
77
|
_this2.writeTimer = setTimeout(function () {
|
|
104
78
|
setWindowTitle(title);
|
|
105
|
-
|
|
106
79
|
if (_this2.shouldWrite(url)) {
|
|
107
80
|
window.history.pushState(routeState, title || '', url);
|
|
108
81
|
_this2.latestAcknowledgedHistory = window.history.length;
|
|
109
82
|
}
|
|
110
|
-
|
|
111
83
|
_this2.inPopState = false;
|
|
112
84
|
_this2.writeTimer = undefined;
|
|
113
85
|
}, _this2.writeDelay);
|
|
114
86
|
});
|
|
115
87
|
}
|
|
88
|
+
|
|
116
89
|
/**
|
|
117
90
|
* Sets a callback on the `onpopstate` event of the history API of the current page.
|
|
118
91
|
* It enables the URL sync to keep track of the changes.
|
|
119
92
|
*/
|
|
120
|
-
|
|
121
93
|
}, {
|
|
122
94
|
key: "onUpdate",
|
|
123
95
|
value: function onUpdate(callback) {
|
|
124
96
|
var _this3 = this;
|
|
125
|
-
|
|
126
97
|
this._onPopState = function (event) {
|
|
127
98
|
if (_this3.writeTimer) {
|
|
128
99
|
clearTimeout(_this3.writeTimer);
|
|
129
100
|
_this3.writeTimer = undefined;
|
|
130
101
|
}
|
|
131
|
-
|
|
132
102
|
_this3.inPopState = true;
|
|
133
|
-
var routeState = event.state;
|
|
103
|
+
var routeState = event.state;
|
|
104
|
+
|
|
105
|
+
// At initial load, the state is read from the URL without update.
|
|
134
106
|
// Therefore the state object is not available.
|
|
135
107
|
// In this case, we fallback and read the URL.
|
|
136
|
-
|
|
137
108
|
if (!routeState) {
|
|
138
109
|
callback(_this3.read());
|
|
139
110
|
} else {
|
|
140
111
|
callback(routeState);
|
|
141
112
|
}
|
|
142
113
|
};
|
|
143
|
-
|
|
144
114
|
safelyRunOnBrowser(function (_ref4) {
|
|
145
115
|
var window = _ref4.window;
|
|
146
116
|
window.addEventListener('popstate', _this3._onPopState);
|
|
147
117
|
});
|
|
148
118
|
}
|
|
119
|
+
|
|
149
120
|
/**
|
|
150
121
|
* Creates a complete URL from a given syncable UI state.
|
|
151
122
|
*
|
|
@@ -153,7 +124,6 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
153
124
|
* This allows to handle cases like using a <base href>.
|
|
154
125
|
* See: https://github.com/algolia/instantsearch.js/issues/790
|
|
155
126
|
*/
|
|
156
|
-
|
|
157
127
|
}, {
|
|
158
128
|
key: "createURL",
|
|
159
129
|
value: function createURL(routeState) {
|
|
@@ -163,35 +133,30 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
163
133
|
location: this.getLocation()
|
|
164
134
|
});
|
|
165
135
|
}
|
|
136
|
+
|
|
166
137
|
/**
|
|
167
138
|
* Removes the event listener and cleans up the URL.
|
|
168
139
|
*/
|
|
169
|
-
|
|
170
140
|
}, {
|
|
171
141
|
key: "dispose",
|
|
172
142
|
value: function dispose() {
|
|
173
143
|
var _this4 = this;
|
|
174
|
-
|
|
175
144
|
this.isDisposed = true;
|
|
176
145
|
safelyRunOnBrowser(function (_ref5) {
|
|
177
146
|
var window = _ref5.window;
|
|
178
|
-
|
|
179
147
|
if (_this4._onPopState) {
|
|
180
148
|
window.removeEventListener('popstate', _this4._onPopState);
|
|
181
149
|
}
|
|
182
150
|
});
|
|
183
|
-
|
|
184
151
|
if (this.writeTimer) {
|
|
185
152
|
clearTimeout(this.writeTimer);
|
|
186
153
|
}
|
|
187
|
-
|
|
188
154
|
this.write({});
|
|
189
155
|
}
|
|
190
156
|
}, {
|
|
191
157
|
key: "shouldWrite",
|
|
192
158
|
value: function shouldWrite(url) {
|
|
193
159
|
var _this5 = this;
|
|
194
|
-
|
|
195
160
|
return safelyRunOnBrowser(function (_ref6) {
|
|
196
161
|
var window = _ref6.window;
|
|
197
162
|
// We do want to `pushState` if:
|
|
@@ -200,75 +165,74 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
200
165
|
// - the last write was from InstantSearch.js
|
|
201
166
|
// (unlike a SPA, where it would have last written)
|
|
202
167
|
var lastPushWasByISAfterDispose = !(_this5.isDisposed && _this5.latestAcknowledgedHistory !== window.history.length);
|
|
203
|
-
return (
|
|
168
|
+
return (
|
|
169
|
+
// When the last state change was through popstate, the IS.js state changes,
|
|
204
170
|
// but that should not write the URL.
|
|
205
|
-
!_this5.inPopState &&
|
|
206
|
-
|
|
171
|
+
!_this5.inPopState &&
|
|
172
|
+
// When the previous pushState after dispose was by IS.js, we want to write the URL.
|
|
173
|
+
lastPushWasByISAfterDispose &&
|
|
174
|
+
// When the URL is the same as the current one, we do not want to write it.
|
|
207
175
|
url !== window.location.href
|
|
208
176
|
);
|
|
209
177
|
});
|
|
210
178
|
}
|
|
211
179
|
}]);
|
|
212
|
-
|
|
213
180
|
return BrowserHistory;
|
|
214
181
|
}();
|
|
215
|
-
|
|
216
182
|
export default function historyRouter() {
|
|
217
183
|
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
184
|
+
_ref7$createURL = _ref7.createURL,
|
|
185
|
+
createURL = _ref7$createURL === void 0 ? function (_ref8) {
|
|
186
|
+
var qsModule = _ref8.qsModule,
|
|
221
187
|
routeState = _ref8.routeState,
|
|
222
188
|
location = _ref8.location;
|
|
223
|
-
|
|
189
|
+
var protocol = location.protocol,
|
|
224
190
|
hostname = location.hostname,
|
|
225
191
|
_location$port = location.port,
|
|
226
192
|
port = _location$port === void 0 ? '' : _location$port,
|
|
227
193
|
pathname = location.pathname,
|
|
228
194
|
hash = location.hash;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// IE <= 11 has no proper `location.origin` so we cannot rely on it.
|
|
233
|
-
if (!queryString) {
|
|
234
|
-
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname).concat(hash);
|
|
235
|
-
}
|
|
195
|
+
var queryString = qsModule.stringify(routeState);
|
|
196
|
+
var portWithPrefix = port === '' ? '' : ":".concat(port);
|
|
236
197
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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.');
|
|
198
|
+
// IE <= 11 has no proper `location.origin` so we cannot rely on it.
|
|
199
|
+
if (!queryString) {
|
|
200
|
+
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname).concat(hash);
|
|
268
201
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
202
|
+
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
|
|
203
|
+
} : _ref7$createURL,
|
|
204
|
+
_ref7$parseURL = _ref7.parseURL,
|
|
205
|
+
parseURL = _ref7$parseURL === void 0 ? function (_ref9) {
|
|
206
|
+
var qsModule = _ref9.qsModule,
|
|
207
|
+
location = _ref9.location;
|
|
208
|
+
// `qs` by default converts arrays with more than 20 items to an object.
|
|
209
|
+
// We want to avoid this because the data structure manipulated can therefore vary.
|
|
210
|
+
// Setting the limit to `100` seems a good number because the engine's default is 100
|
|
211
|
+
// (it can go up to 1000 but it is very unlikely to select more than 100 items in the UI).
|
|
212
|
+
//
|
|
213
|
+
// Using an `arrayLimit` of `n` allows `n + 1` items.
|
|
214
|
+
//
|
|
215
|
+
// See:
|
|
216
|
+
// - https://github.com/ljharb/qs#parsing-arrays
|
|
217
|
+
// - https://www.algolia.com/doc/api-reference/api-parameters/maxValuesPerFacet/
|
|
218
|
+
return qsModule.parse(location.search.slice(1), {
|
|
219
|
+
arrayLimit: 99
|
|
220
|
+
});
|
|
221
|
+
} : _ref7$parseURL,
|
|
222
|
+
_ref7$writeDelay = _ref7.writeDelay,
|
|
223
|
+
writeDelay = _ref7$writeDelay === void 0 ? 400 : _ref7$writeDelay,
|
|
224
|
+
windowTitle = _ref7.windowTitle,
|
|
225
|
+
_ref7$getLocation = _ref7.getLocation,
|
|
226
|
+
getLocation = _ref7$getLocation === void 0 ? function () {
|
|
227
|
+
return safelyRunOnBrowser(function (_ref10) {
|
|
228
|
+
var window = _ref10.window;
|
|
229
|
+
return window.location;
|
|
230
|
+
}, {
|
|
231
|
+
fallback: function fallback() {
|
|
232
|
+
throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
} : _ref7$getLocation;
|
|
272
236
|
return new BrowserHistory({
|
|
273
237
|
createURL: createURL,
|
|
274
238
|
parseURL: parseURL,
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
1
|
+
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; }
|
|
2
|
+
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; }
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
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; }
|
|
8
|
-
|
|
9
5
|
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; }
|
|
10
|
-
|
|
11
6
|
function getIndexStateWithoutConfigure(uiState) {
|
|
12
7
|
var configure = uiState.configure,
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
trackedUiState = _objectWithoutProperties(uiState, ["configure"]);
|
|
15
9
|
return trackedUiState;
|
|
16
|
-
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// technically a URL could contain any key, since users provide it,
|
|
17
13
|
// which is why the input to this function is UiState, not something
|
|
18
14
|
// which excludes "configure" as this function does.
|
|
19
|
-
|
|
20
|
-
|
|
21
15
|
export default function simpleStateMapping() {
|
|
22
16
|
return {
|
|
23
17
|
stateToRoute: function stateToRoute(uiState) {
|