@sonic-equipment/ui 219.0.0 → 221.0.0
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/dist/algolia/algolia-search-provider.js +7 -5
- package/dist/algolia/algolia-sonic-searchclient.js +2 -2
- package/dist/algolia/use-algolia-insights.d.ts +7 -0
- package/dist/algolia/use-algolia-insights.js +45 -7
- package/dist/algolia/use-algolia-search.d.ts +2 -1
- package/dist/buttons/favorite/connected-favorite-button.d.ts +1 -1
- package/dist/buttons/favorite/connected-favorite-button.js +0 -2
- package/dist/cards/product-card/product-card.js +5 -2
- package/dist/exports.d.ts +1 -0
- package/dist/global-search/plugins/categories-plugin.d.ts +1 -1
- package/dist/global-search/plugins/categories-plugin.js +1 -1
- package/dist/global-search/plugins/popular-categories-plugin.d.ts +1 -1
- package/dist/global-search/plugins/popular-categories-plugin.js +1 -1
- package/dist/global-search/plugins/popular-searches-plugin.d.ts +1 -1
- package/dist/global-search/plugins/popular-searches-plugin.js +1 -1
- package/dist/global-search/plugins/query-suggestions-plugin.d.ts +1 -1
- package/dist/global-search/plugins/query-suggestions-plugin.js +1 -1
- package/dist/global-search/plugins/quick-access-plugin.d.ts +1 -1
- package/dist/global-search/plugins/quick-access-plugin.js +1 -1
- package/dist/global-search/plugins/recent-searches-plugin.d.ts +1 -1
- package/dist/global-search/plugins/recent-searches-plugin.js +2 -1
- package/dist/global-search/search-highlight/highlight.d.ts +1 -1
- package/dist/global-search/search-highlight/highlight.js +1 -1
- package/dist/global-search/types.d.ts +3 -1
- package/dist/header/buttons/account/connected-account-button.js +1 -1
- package/dist/index.js +2 -1
- package/dist/intl/translation-id.d.ts +1 -1
- package/dist/navigation/quick-access-menu/quick-access-menu.d.ts +2 -1
- package/dist/navigation/quick-access-menu/quick-access-menu.js +2 -2
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/checkOptions.js +7 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/createAutocomplete.js +109 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/createStore.js +31 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/getAutocompleteSetters.js +51 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/getCompletion.js +12 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/getDefaultProps.js +135 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/getPropGetters.js +355 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/metadata.js +44 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/onInput.js +148 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/onKeyDown.js +202 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/reshape.js +48 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/resolve.js +119 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/stateReducer.js +149 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/createCancelablePromise.js +50 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/createCancelablePromiseList.js +42 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/createConcurrentSafePromise.js +38 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/getActiveItem.js +79 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/getAutocompleteElementId.js +12 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/getNativeEvent.js +5 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/getNextActiveItemId.js +31 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/getNormalizedSources.js +53 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/getPluginSubmitPromise.js +39 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/isOrContainsNode.js +5 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/isSamsung.js +6 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-core@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-core/dist/esm/utils/mapToAlgoliaResponse.js +25 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-js@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-js/dist/esm/requesters/createAlgoliaRequester.js +16 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-js@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-js/dist/esm/requesters/getAlgoliaResults.js +12 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-js@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0_search-insights@2.17.3/node_modules/@algolia/autocomplete-js/dist/esm/userAgents.js +8 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-algolia-insights@1.19.2_@algolia_client-search@4.24.0_algoliasea_57b3nqmtgbeobm4sw3iw2qdpxy/node_modules/@algolia/autocomplete-plugin-algolia-insights/dist/esm/createAlgoliaInsightsPlugin.js +252 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-algolia-insights@1.19.2_@algolia_client-search@4.24.0_algoliasea_57b3nqmtgbeobm4sw3iw2qdpxy/node_modules/@algolia/autocomplete-plugin-algolia-insights/dist/esm/createClickedEvent.js +16 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-algolia-insights@1.19.2_@algolia_client-search@4.24.0_algoliasea_57b3nqmtgbeobm4sw3iw2qdpxy/node_modules/@algolia/autocomplete-plugin-algolia-insights/dist/esm/createSearchInsightsApi.js +209 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-algolia-insights@1.19.2_@algolia_client-search@4.24.0_algoliasea_57b3nqmtgbeobm4sw3iw2qdpxy/node_modules/@algolia/autocomplete-plugin-algolia-insights/dist/esm/createViewedEvents.js +18 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-algolia-insights@1.19.2_@algolia_client-search@4.24.0_algoliasea_57b3nqmtgbeobm4sw3iw2qdpxy/node_modules/@algolia/autocomplete-plugin-algolia-insights/dist/esm/isAlgoliaInsightsHit.js +5 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-algolia-insights@1.19.2_@algolia_client-search@4.24.0_algoliasea_57b3nqmtgbeobm4sw3iw2qdpxy/node_modules/@algolia/autocomplete-plugin-algolia-insights/dist/esm/isModernInsightsClient.js +25 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-query-suggestions@1.19.2_@algolia_client-search@4.24.0_algoliase_q33j3oaxy2utuyscyksb32r6mu/node_modules/@algolia/autocomplete-plugin-query-suggestions/dist/esm/constants.js +7 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-query-suggestions@1.19.2_@algolia_client-search@4.24.0_algoliase_q33j3oaxy2utuyscyksb32r6mu/node_modules/@algolia/autocomplete-plugin-query-suggestions/dist/esm/createQuerySuggestionsPlugin.js +118 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-query-suggestions@1.19.2_@algolia_client-search@4.24.0_algoliase_q33j3oaxy2utuyscyksb32r6mu/node_modules/@algolia/autocomplete-plugin-query-suggestions/dist/esm/getTemplates.js +64 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/addHighlightedAttribute.js +21 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/constants.js +10 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/createLocalStorage.js +36 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/createLocalStorageRecentSearchesPlugin.js +49 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/createRecentSearchesPlugin.js +137 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/createStorageApi.js +16 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/getLocalStorage.js +33 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/getTemplates.js +72 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-plugin-recent-searches@1.19.2_@algolia_client-search@4.24.0_algoliasear_fyqsds3bt3rvcvjy7dxjzgxvaa/node_modules/@algolia/autocomplete-plugin-recent-searches/dist/esm/search.js +25 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/constants/index.js +4 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/highlight/parseAlgoliaHitHighlight.js +25 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/highlight/parseAttribute.js +51 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/requester/createAlgoliaRequester.js +6 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/requester/createRequester.js +37 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/requester/getAlgoliaResults.js +19 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/search/fetchAlgoliaResults.js +69 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-preset-algolia@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-preset-algolia/dist/esm/utils/getAppIdAndApiKey.js +16 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/createRef.js +7 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/debounce.js +16 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/decycle.js +34 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/flatten.js +7 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/generateAutocompleteId.js +6 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/getAttributeValueByPath.js +7 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/getItemsCount.js +10 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/invariant.js +15 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/isEqual.js +26 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/noop.js +3 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/safelyRunOnBrowser.js +13 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/userAgents.js +8 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/version.js +3 -0
- package/dist/node_modules/.pnpm/@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/warn.js +26 -0
- package/dist/pages/account/sign-in-page/sign-in-page.js +1 -1
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-page.d.ts +1 -1
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-page.js +1 -1
- package/dist/pages/my-sonic/pages/favorites/favorites-page.js +26 -1
- package/dist/shared/api/bff/hooks/use-fetch-favorites.d.ts +2 -0
- package/dist/shared/api/bff/hooks/use-fetch-favorites.js +29 -0
- package/dist/shared/api/storefront/hooks/wishlist/use-add-wishlist-item-to-current-wishlist.js +5 -12
- package/dist/shared/api/storefront/hooks/wishlist/use-add-wishlist-item-to-wishlist.js +6 -9
- package/dist/shared/api/storefront/hooks/wishlist/use-delete-wishlist-item-from-wishlist.js +4 -7
- package/dist/shared/api/storefront/hooks/wishlist/use-fetch-all-wishlists-items.js +10 -20
- package/dist/shared/api/storefront/services/wishlist-service.d.ts +4 -1
- package/dist/shared/api/storefront/services/wishlist-service.js +16 -1
- package/dist/shared/utils/uuid.js +1 -1
- package/dist/styles.css +6 -6
- package/package.json +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// We don't have access to the autocomplete source when we call `onKeyDown`
|
|
2
|
+
// or `onClick` because those are native browser events.
|
|
3
|
+
// However, we can get the source from the suggestion index.
|
|
4
|
+
function getCollectionFromActiveItemId(state) {
|
|
5
|
+
// Given 3 sources with respectively 1, 2 and 3 suggestions: [1, 2, 3]
|
|
6
|
+
// We want to get the accumulated counts:
|
|
7
|
+
// [1, 1 + 2, 1 + 2 + 3] = [1, 3, 3 + 3] = [1, 3, 6]
|
|
8
|
+
var accumulatedCollectionsCount = state.collections.map(function (collections) {
|
|
9
|
+
return collections.items.length;
|
|
10
|
+
}).reduce(function (acc, collectionsCount, index) {
|
|
11
|
+
var previousValue = acc[index - 1] || 0;
|
|
12
|
+
var nextValue = previousValue + collectionsCount;
|
|
13
|
+
acc.push(nextValue);
|
|
14
|
+
return acc;
|
|
15
|
+
}, []);
|
|
16
|
+
|
|
17
|
+
// Based on the accumulated counts, we can infer the index of the suggestion.
|
|
18
|
+
var collectionIndex = accumulatedCollectionsCount.reduce(function (acc, current) {
|
|
19
|
+
if (current <= state.activeItemId) {
|
|
20
|
+
return acc + 1;
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
}, 0);
|
|
24
|
+
return state.collections[collectionIndex];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Gets the highlighted index relative to a suggestion object (not the absolute
|
|
29
|
+
* highlighted index).
|
|
30
|
+
*
|
|
31
|
+
* Example:
|
|
32
|
+
* [['a', 'b'], ['c', 'd', 'e'], ['f']]
|
|
33
|
+
* ↑
|
|
34
|
+
* (absolute: 3, relative: 1)
|
|
35
|
+
*/
|
|
36
|
+
function getRelativeActiveItemId(_ref) {
|
|
37
|
+
var state = _ref.state,
|
|
38
|
+
collection = _ref.collection;
|
|
39
|
+
var isOffsetFound = false;
|
|
40
|
+
var counter = 0;
|
|
41
|
+
var previousItemsOffset = 0;
|
|
42
|
+
while (isOffsetFound === false) {
|
|
43
|
+
var currentCollection = state.collections[counter];
|
|
44
|
+
if (currentCollection === collection) {
|
|
45
|
+
isOffsetFound = true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
previousItemsOffset += currentCollection.items.length;
|
|
49
|
+
counter++;
|
|
50
|
+
}
|
|
51
|
+
return state.activeItemId - previousItemsOffset;
|
|
52
|
+
}
|
|
53
|
+
function getActiveItem(state) {
|
|
54
|
+
var collection = getCollectionFromActiveItemId(state);
|
|
55
|
+
if (!collection) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
var item = collection.items[getRelativeActiveItemId({
|
|
59
|
+
state: state,
|
|
60
|
+
collection: collection
|
|
61
|
+
})];
|
|
62
|
+
var source = collection.source;
|
|
63
|
+
var itemInputValue = source.getItemInputValue({
|
|
64
|
+
item: item,
|
|
65
|
+
state: state
|
|
66
|
+
});
|
|
67
|
+
var itemUrl = source.getItemUrl({
|
|
68
|
+
item: item,
|
|
69
|
+
state: state
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
item: item,
|
|
73
|
+
itemInputValue: itemInputValue,
|
|
74
|
+
itemUrl: itemUrl,
|
|
75
|
+
source: source
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { getActiveItem };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a full element id for an autocomplete element.
|
|
3
|
+
*
|
|
4
|
+
* @param autocompleteInstanceId The id of the autocomplete instance
|
|
5
|
+
* @param elementId The specific element id
|
|
6
|
+
* @param source The source of the element, when it needs to be scoped
|
|
7
|
+
*/
|
|
8
|
+
function getAutocompleteElementId(autocompleteInstanceId, elementId, source) {
|
|
9
|
+
return [autocompleteInstanceId, source === null || source === void 0 ? void 0 : source.sourceId, elementId].filter(Boolean).join('-').replace(/\s/g, '');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { getAutocompleteElementId };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the next active item ID from the current state.
|
|
3
|
+
*
|
|
4
|
+
* We allow circular keyboard navigation from the base index.
|
|
5
|
+
* The base index can either be `null` (nothing is highlighted) or `0`
|
|
6
|
+
* (the first item is highlighted).
|
|
7
|
+
* The base index is allowed to get assigned `null` only if
|
|
8
|
+
* `props.defaultActiveItemId` is `null`. This pattern allows to "stop"
|
|
9
|
+
* by the actual query before navigating to other suggestions as seen on
|
|
10
|
+
* Google or Amazon.
|
|
11
|
+
*
|
|
12
|
+
* @param moveAmount The offset to increment (or decrement) the last index
|
|
13
|
+
* @param baseIndex The current index to compute the next index from
|
|
14
|
+
* @param itemCount The number of items
|
|
15
|
+
* @param defaultActiveItemId The default active index to fallback to
|
|
16
|
+
*/
|
|
17
|
+
function getNextActiveItemId(moveAmount, baseIndex, itemCount, defaultActiveItemId) {
|
|
18
|
+
if (!itemCount) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (moveAmount < 0 && (baseIndex === null || defaultActiveItemId !== null && baseIndex === 0)) {
|
|
22
|
+
return itemCount + moveAmount;
|
|
23
|
+
}
|
|
24
|
+
var numericIndex = (baseIndex === null ? -1 : baseIndex) + moveAmount;
|
|
25
|
+
if (numericIndex <= -1 || numericIndex >= itemCount) {
|
|
26
|
+
return defaultActiveItemId === null ? null : 0;
|
|
27
|
+
}
|
|
28
|
+
return numericIndex;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { getNextActiveItemId };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { invariant } from '../../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/invariant.js';
|
|
2
|
+
import { decycle } from '../../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/decycle.js';
|
|
3
|
+
import { noop } from '../../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/noop.js';
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
+
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; }
|
|
8
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
+
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); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
+
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); }
|
|
11
|
+
function getNormalizedSources(getSources, params) {
|
|
12
|
+
var seenSourceIds = [];
|
|
13
|
+
return Promise.resolve(getSources(params)).then(function (sources) {
|
|
14
|
+
invariant(Array.isArray(sources), function () {
|
|
15
|
+
return "The `getSources` function must return an array of sources but returned type ".concat(JSON.stringify(_typeof(sources)), ":\n\n").concat(JSON.stringify(decycle(sources), null, 2));
|
|
16
|
+
});
|
|
17
|
+
return Promise.all(sources
|
|
18
|
+
// We allow `undefined` and `false` sources to allow users to use
|
|
19
|
+
// `Boolean(query) && source` (=> `false`).
|
|
20
|
+
// We need to remove these values at this point.
|
|
21
|
+
.filter(function (maybeSource) {
|
|
22
|
+
return Boolean(maybeSource);
|
|
23
|
+
}).map(function (source) {
|
|
24
|
+
invariant(typeof source.sourceId === 'string', 'A source must provide a `sourceId` string.');
|
|
25
|
+
if (seenSourceIds.includes(source.sourceId)) {
|
|
26
|
+
throw new Error("[Autocomplete] The `sourceId` ".concat(JSON.stringify(source.sourceId), " is not unique."));
|
|
27
|
+
}
|
|
28
|
+
seenSourceIds.push(source.sourceId);
|
|
29
|
+
var defaultSource = {
|
|
30
|
+
getItemInputValue: function getItemInputValue(_ref) {
|
|
31
|
+
var state = _ref.state;
|
|
32
|
+
return state.query;
|
|
33
|
+
},
|
|
34
|
+
getItemUrl: function getItemUrl() {
|
|
35
|
+
return undefined;
|
|
36
|
+
},
|
|
37
|
+
onSelect: function onSelect(_ref2) {
|
|
38
|
+
var setIsOpen = _ref2.setIsOpen;
|
|
39
|
+
setIsOpen(false);
|
|
40
|
+
},
|
|
41
|
+
onActive: noop,
|
|
42
|
+
onResolve: noop
|
|
43
|
+
};
|
|
44
|
+
Object.keys(defaultSource).forEach(function (key) {
|
|
45
|
+
defaultSource[key].__default = true;
|
|
46
|
+
});
|
|
47
|
+
var normalizedSource = _objectSpread(_objectSpread({}, defaultSource), source);
|
|
48
|
+
return Promise.resolve(normalizedSource);
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { getNormalizedSources };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike) { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
/**
|
|
5
|
+
* If a plugin is configured to await a submit event, this returns a promise
|
|
6
|
+
* for either the max timeout value found or until it completes.
|
|
7
|
+
* Otherwise, return undefined.
|
|
8
|
+
*/
|
|
9
|
+
var getPluginSubmitPromise = function getPluginSubmitPromise(plugins, pendingRequests) {
|
|
10
|
+
var waitUntilComplete = false;
|
|
11
|
+
var timeouts = [];
|
|
12
|
+
var _iterator = _createForOfIteratorHelper(plugins),
|
|
13
|
+
_step;
|
|
14
|
+
try {
|
|
15
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
16
|
+
var _plugin$__autocomplet, _plugin$__autocomplet2, _plugin$__autocomplet3;
|
|
17
|
+
var plugin = _step.value;
|
|
18
|
+
var value = (_plugin$__autocomplet = plugin.__autocomplete_pluginOptions) === null || _plugin$__autocomplet === void 0 ? void 0 : (_plugin$__autocomplet2 = (_plugin$__autocomplet3 = _plugin$__autocomplet).awaitSubmit) === null || _plugin$__autocomplet2 === void 0 ? void 0 : _plugin$__autocomplet2.call(_plugin$__autocomplet3);
|
|
19
|
+
if (typeof value === 'number') {
|
|
20
|
+
timeouts.push(value);
|
|
21
|
+
} else if (value === true) {
|
|
22
|
+
waitUntilComplete = true;
|
|
23
|
+
break; // break loop as bool overrides num array below
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} catch (err) {
|
|
27
|
+
_iterator.e(err);
|
|
28
|
+
} finally {
|
|
29
|
+
_iterator.f();
|
|
30
|
+
}
|
|
31
|
+
if (waitUntilComplete) {
|
|
32
|
+
return pendingRequests.wait();
|
|
33
|
+
} else if (timeouts.length > 0) {
|
|
34
|
+
return pendingRequests.wait(Math.max.apply(Math, timeouts));
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { getPluginSubmitPromise };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function mapToAlgoliaResponse(rawResults) {
|
|
2
|
+
return {
|
|
3
|
+
results: rawResults,
|
|
4
|
+
hits: rawResults.map(function (result) {
|
|
5
|
+
return result.hits;
|
|
6
|
+
}).filter(Boolean),
|
|
7
|
+
facetHits: rawResults.map(function (result) {
|
|
8
|
+
var _facetHits;
|
|
9
|
+
return (_facetHits = result.facetHits) === null || _facetHits === void 0 ? void 0 : _facetHits.map(function (facetHit) {
|
|
10
|
+
// Bring support for the highlighting components.
|
|
11
|
+
return {
|
|
12
|
+
label: facetHit.value,
|
|
13
|
+
count: facetHit.count,
|
|
14
|
+
_highlightResult: {
|
|
15
|
+
label: {
|
|
16
|
+
value: facetHit.highlighted
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}).filter(Boolean)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { mapToAlgoliaResponse };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRequester, fetchAlgoliaResults } from '@algolia/autocomplete-preset-algolia';
|
|
2
|
+
import { userAgents } from '../userAgents.js';
|
|
3
|
+
|
|
4
|
+
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); }
|
|
5
|
+
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; }
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
+
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; }
|
|
8
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
+
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); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
+
var createAlgoliaRequester = createRequester(function (params) {
|
|
11
|
+
return fetchAlgoliaResults(_objectSpread(_objectSpread({}, params), {}, {
|
|
12
|
+
userAgents: userAgents
|
|
13
|
+
}));
|
|
14
|
+
}, 'algolia');
|
|
15
|
+
|
|
16
|
+
export { createAlgoliaRequester };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createAlgoliaRequester } from './createAlgoliaRequester.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves Algolia results from multiple indices.
|
|
5
|
+
*/
|
|
6
|
+
var getAlgoliaResults = createAlgoliaRequester({
|
|
7
|
+
transformResponse: function transformResponse(response) {
|
|
8
|
+
return response.hits;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { getAlgoliaResults };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { version } from '../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/version.js';
|
|
2
|
+
|
|
3
|
+
var userAgents = [{
|
|
4
|
+
segment: 'autocomplete-js',
|
|
5
|
+
version: version
|
|
6
|
+
}];
|
|
7
|
+
|
|
8
|
+
export { userAgents };
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { createClickedEvent } from './createClickedEvent.js';
|
|
2
|
+
import { createSearchInsightsApi } from './createSearchInsightsApi.js';
|
|
3
|
+
import { createViewedEvents } from './createViewedEvents.js';
|
|
4
|
+
import { isAlgoliaInsightsHit } from './isAlgoliaInsightsHit.js';
|
|
5
|
+
import { safelyRunOnBrowser } from '../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/safelyRunOnBrowser.js';
|
|
6
|
+
import { debounce } from '../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/debounce.js';
|
|
7
|
+
import { isEqual } from '../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/isEqual.js';
|
|
8
|
+
import { createRef } from '../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/createRef.js';
|
|
9
|
+
import { noop } from '../../../../../../@algolia_autocomplete-shared@1.19.2_@algolia_client-search@4.24.0_algoliasearch@4.24.0/node_modules/@algolia/autocomplete-shared/dist/esm/noop.js';
|
|
10
|
+
|
|
11
|
+
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); }
|
|
12
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
13
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
16
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
18
|
+
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; }
|
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).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; }
|
|
20
|
+
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; }
|
|
21
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
22
|
+
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); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
23
|
+
var VIEW_EVENT_DELAY = 400;
|
|
24
|
+
var ALGOLIA_INSIGHTS_VERSION = '2.15.0';
|
|
25
|
+
var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
|
|
26
|
+
var sendViewedObjectIDs = debounce(function (_ref) {
|
|
27
|
+
var onItemsChange = _ref.onItemsChange,
|
|
28
|
+
items = _ref.items,
|
|
29
|
+
insights = _ref.insights,
|
|
30
|
+
state = _ref.state;
|
|
31
|
+
onItemsChange({
|
|
32
|
+
insights: insights,
|
|
33
|
+
insightsEvents: createViewedEvents({
|
|
34
|
+
items: items
|
|
35
|
+
}).map(function (event) {
|
|
36
|
+
return _objectSpread({
|
|
37
|
+
eventName: 'Items Viewed'
|
|
38
|
+
}, event);
|
|
39
|
+
}),
|
|
40
|
+
state: state
|
|
41
|
+
});
|
|
42
|
+
}, VIEW_EVENT_DELAY);
|
|
43
|
+
function createAlgoliaInsightsPlugin(options) {
|
|
44
|
+
var _getOptions = getOptions(options),
|
|
45
|
+
providedInsightsClient = _getOptions.insightsClient,
|
|
46
|
+
insightsInitParams = _getOptions.insightsInitParams,
|
|
47
|
+
onItemsChange = _getOptions.onItemsChange,
|
|
48
|
+
onSelectEvent = _getOptions.onSelect,
|
|
49
|
+
onActiveEvent = _getOptions.onActive,
|
|
50
|
+
__autocomplete_clickAnalytics = _getOptions.__autocomplete_clickAnalytics;
|
|
51
|
+
var insightsClient = providedInsightsClient;
|
|
52
|
+
if (!providedInsightsClient) {
|
|
53
|
+
safelyRunOnBrowser(function (_ref2) {
|
|
54
|
+
var window = _ref2.window;
|
|
55
|
+
var pointer = window.AlgoliaAnalyticsObject || 'aa';
|
|
56
|
+
if (typeof pointer === 'string') {
|
|
57
|
+
insightsClient = window[pointer];
|
|
58
|
+
}
|
|
59
|
+
if (!insightsClient) {
|
|
60
|
+
window.AlgoliaAnalyticsObject = pointer;
|
|
61
|
+
if (!window[pointer]) {
|
|
62
|
+
window[pointer] = function () {
|
|
63
|
+
if (!window[pointer].queue) {
|
|
64
|
+
window[pointer].queue = [];
|
|
65
|
+
}
|
|
66
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
67
|
+
args[_key] = arguments[_key];
|
|
68
|
+
}
|
|
69
|
+
window[pointer].queue.push(args);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
window[pointer].version = ALGOLIA_INSIGHTS_VERSION;
|
|
73
|
+
insightsClient = window[pointer];
|
|
74
|
+
loadInsights(window);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// We return an empty plugin if `insightsClient` is still undefined at
|
|
80
|
+
// this stage, which can happen in server environments.
|
|
81
|
+
if (!insightsClient) {
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
if (insightsInitParams) {
|
|
85
|
+
insightsClient('init', _objectSpread({
|
|
86
|
+
partial: true
|
|
87
|
+
}, insightsInitParams));
|
|
88
|
+
}
|
|
89
|
+
var insights = createSearchInsightsApi(insightsClient);
|
|
90
|
+
var previousItems = createRef([]);
|
|
91
|
+
var debouncedOnStateChange = debounce(function (_ref3) {
|
|
92
|
+
var state = _ref3.state;
|
|
93
|
+
if (!state.isOpen) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
var items = state.collections.reduce(function (acc, current) {
|
|
97
|
+
return [].concat(_toConsumableArray(acc), _toConsumableArray(current.items));
|
|
98
|
+
}, []).filter(isAlgoliaInsightsHit);
|
|
99
|
+
if (!isEqual(previousItems.current.map(function (x) {
|
|
100
|
+
return x.objectID;
|
|
101
|
+
}), items.map(function (x) {
|
|
102
|
+
return x.objectID;
|
|
103
|
+
}))) {
|
|
104
|
+
previousItems.current = items;
|
|
105
|
+
if (items.length > 0) {
|
|
106
|
+
sendViewedObjectIDs({
|
|
107
|
+
onItemsChange: onItemsChange,
|
|
108
|
+
items: items,
|
|
109
|
+
insights: insights,
|
|
110
|
+
state: state
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, 0);
|
|
115
|
+
return {
|
|
116
|
+
name: 'aa.algoliaInsightsPlugin',
|
|
117
|
+
subscribe: function subscribe(_ref4) {
|
|
118
|
+
var setContext = _ref4.setContext,
|
|
119
|
+
onSelect = _ref4.onSelect,
|
|
120
|
+
onActive = _ref4.onActive;
|
|
121
|
+
function setInsightsContext(userToken) {
|
|
122
|
+
setContext({
|
|
123
|
+
algoliaInsightsPlugin: {
|
|
124
|
+
__algoliaSearchParameters: _objectSpread(_objectSpread({}, __autocomplete_clickAnalytics ? {
|
|
125
|
+
clickAnalytics: true
|
|
126
|
+
} : {}), userToken ? {
|
|
127
|
+
userToken: normalizeUserToken(userToken)
|
|
128
|
+
} : {}),
|
|
129
|
+
insights: insights
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
insightsClient('addAlgoliaAgent', 'insights-plugin');
|
|
134
|
+
setInsightsContext();
|
|
135
|
+
|
|
136
|
+
// Handles user token changes
|
|
137
|
+
insightsClient('onUserTokenChange', function (userToken) {
|
|
138
|
+
setInsightsContext(userToken);
|
|
139
|
+
});
|
|
140
|
+
insightsClient('getUserToken', null, function (_error, userToken) {
|
|
141
|
+
setInsightsContext(userToken);
|
|
142
|
+
});
|
|
143
|
+
onSelect(function (_ref5) {
|
|
144
|
+
var item = _ref5.item,
|
|
145
|
+
state = _ref5.state,
|
|
146
|
+
event = _ref5.event,
|
|
147
|
+
source = _ref5.source;
|
|
148
|
+
if (!isAlgoliaInsightsHit(item)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
onSelectEvent({
|
|
152
|
+
state: state,
|
|
153
|
+
event: event,
|
|
154
|
+
insights: insights,
|
|
155
|
+
item: item,
|
|
156
|
+
insightsEvents: [_objectSpread({
|
|
157
|
+
eventName: 'Item Selected'
|
|
158
|
+
}, createClickedEvent({
|
|
159
|
+
item: item,
|
|
160
|
+
items: source.getItems().filter(isAlgoliaInsightsHit)
|
|
161
|
+
}))]
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
onActive(function (_ref6) {
|
|
165
|
+
var item = _ref6.item,
|
|
166
|
+
source = _ref6.source,
|
|
167
|
+
state = _ref6.state,
|
|
168
|
+
event = _ref6.event;
|
|
169
|
+
if (!isAlgoliaInsightsHit(item)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
onActiveEvent({
|
|
173
|
+
state: state,
|
|
174
|
+
event: event,
|
|
175
|
+
insights: insights,
|
|
176
|
+
item: item,
|
|
177
|
+
insightsEvents: [_objectSpread({
|
|
178
|
+
eventName: 'Item Active'
|
|
179
|
+
}, createClickedEvent({
|
|
180
|
+
item: item,
|
|
181
|
+
items: source.getItems().filter(isAlgoliaInsightsHit)
|
|
182
|
+
}))]
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
onStateChange: function onStateChange(_ref7) {
|
|
187
|
+
var state = _ref7.state;
|
|
188
|
+
debouncedOnStateChange({
|
|
189
|
+
state: state
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
__autocomplete_pluginOptions: options
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function getAlgoliaSources() {
|
|
196
|
+
var _context$algoliaInsig;
|
|
197
|
+
var algoliaSourceBase = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
198
|
+
var context = arguments.length > 1 ? arguments[1] : undefined;
|
|
199
|
+
return [].concat(_toConsumableArray(algoliaSourceBase), ['autocomplete-internal'], _toConsumableArray((_context$algoliaInsig = context.algoliaInsightsPlugin) !== null && _context$algoliaInsig !== void 0 && _context$algoliaInsig.__automaticInsights ? ['autocomplete-automatic'] : []));
|
|
200
|
+
}
|
|
201
|
+
function getOptions(options) {
|
|
202
|
+
return _objectSpread({
|
|
203
|
+
onItemsChange: function onItemsChange(_ref8) {
|
|
204
|
+
var insights = _ref8.insights,
|
|
205
|
+
insightsEvents = _ref8.insightsEvents,
|
|
206
|
+
state = _ref8.state;
|
|
207
|
+
insights.viewedObjectIDs.apply(insights, _toConsumableArray(insightsEvents.map(function (event) {
|
|
208
|
+
return _objectSpread(_objectSpread({}, event), {}, {
|
|
209
|
+
algoliaSource: getAlgoliaSources(event.algoliaSource, state.context)
|
|
210
|
+
});
|
|
211
|
+
})));
|
|
212
|
+
},
|
|
213
|
+
onSelect: function onSelect(_ref9) {
|
|
214
|
+
var insights = _ref9.insights,
|
|
215
|
+
insightsEvents = _ref9.insightsEvents,
|
|
216
|
+
state = _ref9.state;
|
|
217
|
+
insights.clickedObjectIDsAfterSearch.apply(insights, _toConsumableArray(insightsEvents.map(function (event) {
|
|
218
|
+
return _objectSpread(_objectSpread({}, event), {}, {
|
|
219
|
+
algoliaSource: getAlgoliaSources(event.algoliaSource, state.context)
|
|
220
|
+
});
|
|
221
|
+
})));
|
|
222
|
+
},
|
|
223
|
+
onActive: noop,
|
|
224
|
+
__autocomplete_clickAnalytics: true
|
|
225
|
+
}, options);
|
|
226
|
+
}
|
|
227
|
+
function loadInsights(environment) {
|
|
228
|
+
var errorMessage = "[Autocomplete]: Could not load search-insights.js. Please load it manually following https://alg.li/insights-autocomplete";
|
|
229
|
+
try {
|
|
230
|
+
var script = environment.document.createElement('script');
|
|
231
|
+
script.async = true;
|
|
232
|
+
script.src = ALGOLIA_INSIGHTS_SRC;
|
|
233
|
+
script.onerror = function () {
|
|
234
|
+
// eslint-disable-next-line no-console
|
|
235
|
+
console.error(errorMessage);
|
|
236
|
+
};
|
|
237
|
+
document.body.appendChild(script);
|
|
238
|
+
} catch (cause) {
|
|
239
|
+
// eslint-disable-next-line no-console
|
|
240
|
+
console.error(errorMessage);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* While `search-insights` supports both string and number user tokens,
|
|
246
|
+
* the Search API only accepts strings. This function normalizes the user token.
|
|
247
|
+
*/
|
|
248
|
+
function normalizeUserToken(userToken) {
|
|
249
|
+
return typeof userToken === 'number' ? userToken.toString() : userToken;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export { createAlgoliaInsightsPlugin };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function createClickedEvent(_ref) {
|
|
2
|
+
var item = _ref.item,
|
|
3
|
+
_ref$items = _ref.items,
|
|
4
|
+
items = _ref$items === void 0 ? [] : _ref$items;
|
|
5
|
+
return {
|
|
6
|
+
index: item.__autocomplete_indexName,
|
|
7
|
+
items: [item],
|
|
8
|
+
positions: [1 + items.findIndex(function (x) {
|
|
9
|
+
return x.objectID === item.objectID;
|
|
10
|
+
})],
|
|
11
|
+
queryID: item.__autocomplete_queryID,
|
|
12
|
+
algoliaSource: ['autocomplete']
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { createClickedEvent };
|