instantsearch.js 4.37.3 → 4.39.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/cjs/connectors/breadcrumb/connectBreadcrumb.js +3 -1
  3. package/cjs/connectors/clear-refinements/connectClearRefinements.js +11 -6
  4. package/cjs/connectors/current-refinements/connectCurrentRefinements.js +6 -2
  5. package/cjs/connectors/geo-search/connectGeoSearch.js +3 -1
  6. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
  7. package/cjs/connectors/hits/connectHits.js +3 -1
  8. package/cjs/connectors/hits-per-page/connectHitsPerPage.js +3 -1
  9. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +5 -2
  10. package/cjs/connectors/menu/connectMenu.js +3 -1
  11. package/cjs/connectors/numeric-menu/connectNumericMenu.js +5 -3
  12. package/cjs/connectors/query-rules/connectQueryRules.js +3 -1
  13. package/cjs/connectors/refinement-list/connectRefinementList.js +8 -3
  14. package/cjs/connectors/sort-by/connectSortBy.js +3 -1
  15. package/cjs/lib/routers/history.js +44 -29
  16. package/cjs/lib/version.js +1 -1
  17. package/cjs/middlewares/createMetadataMiddleware.js +3 -1
  18. package/dist/instantsearch.development.d.ts +60 -43
  19. package/dist/instantsearch.development.js +108 -56
  20. package/dist/instantsearch.development.js.map +1 -1
  21. package/dist/instantsearch.production.d.ts +60 -43
  22. package/dist/instantsearch.production.min.d.ts +60 -43
  23. package/dist/instantsearch.production.min.js +2 -2
  24. package/dist/instantsearch.production.min.js.map +1 -1
  25. package/es/components/ToggleRefinement/ToggleRefinement.d.ts +3 -0
  26. package/es/components/ToggleRefinement/ToggleRefinement.js +4 -0
  27. package/es/connectors/breadcrumb/connectBreadcrumb.js +3 -1
  28. package/es/connectors/clear-refinements/connectClearRefinements.js +11 -6
  29. package/es/connectors/current-refinements/connectCurrentRefinements.js +6 -2
  30. package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +4 -5
  31. package/es/connectors/geo-search/connectGeoSearch.js +3 -1
  32. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
  33. package/es/connectors/hits/connectHits.d.ts +10 -10
  34. package/es/connectors/hits/connectHits.js +3 -1
  35. package/es/connectors/hits/connectHitsWithInsights.d.ts +1 -1
  36. package/es/connectors/hits-per-page/connectHitsPerPage.js +3 -1
  37. package/es/connectors/infinite-hits/connectInfiniteHits.d.ts +21 -21
  38. package/es/connectors/infinite-hits/connectInfiniteHits.js +5 -2
  39. package/es/connectors/infinite-hits/connectInfiniteHitsWithInsights.d.ts +1 -1
  40. package/es/connectors/menu/connectMenu.js +3 -1
  41. package/es/connectors/numeric-menu/connectNumericMenu.js +5 -3
  42. package/es/connectors/query-rules/connectQueryRules.d.ts +1 -2
  43. package/es/connectors/query-rules/connectQueryRules.js +3 -1
  44. package/es/connectors/refinement-list/connectRefinementList.js +8 -3
  45. package/es/connectors/sort-by/connectSortBy.js +3 -1
  46. package/es/lib/routers/history.d.ts +11 -0
  47. package/es/lib/routers/history.js +44 -29
  48. package/es/lib/utils/createSendEventForHits.d.ts +3 -0
  49. package/es/lib/utils/createSendEventForHits.js +3 -0
  50. package/es/lib/version.d.ts +1 -1
  51. package/es/lib/version.js +1 -1
  52. package/es/middlewares/createMetadataMiddleware.js +3 -1
  53. package/es/types/results.d.ts +8 -5
  54. package/es/types/widget.d.ts +4 -1
  55. package/package.json +4 -4
  56. package/dist/instantsearch.development.min.d.ts +0 -5246
@@ -12,8 +12,7 @@ import { default as qs_2 } from 'qs';
12
12
  import type { SearchParameters } from 'algoliasearch-helper';
13
13
  import type { SearchResults } from 'algoliasearch-helper';
14
14
 
15
- declare type AlgoliaHit = {
16
- [attribute: string]: any;
15
+ declare type AlgoliaHit<THit extends BaseHit = Record<string, any>> = {
17
16
  objectID: string;
18
17
  _highlightResult?: HitHighlightResult;
19
18
  _snippetResult?: HitSnippetResult;
@@ -36,7 +35,7 @@ declare type AlgoliaHit = {
36
35
  };
37
36
  _distinctSeqID?: number;
38
37
  _geoLoc?: GeoLoc;
39
- };
38
+ } & THit;
40
39
 
41
40
  declare const analytics: AnalyticsWidget;
42
41
 
@@ -292,6 +291,8 @@ declare type AutocompleteWidgetDescription = {
292
291
  };
293
292
  };
294
293
 
294
+ declare type BaseHit = Record<string, unknown>;
295
+
295
296
  declare type BindEventForHits = BuiltInBindEventForHits & CustomBindEventForHits;
296
297
 
297
298
  declare type Bounds = {
@@ -466,6 +467,17 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
466
467
  * It needs to avoid pushing state to history in case of back/forward in browser
467
468
  */
468
469
  private shouldPushState;
470
+ /**
471
+ * Indicates whether the history router is disposed or not.
472
+ */
473
+ private isDisposed;
474
+ /**
475
+ * Indicates the window.history.length before the last call to
476
+ * window.history.pushState (called in `write`).
477
+ * It allows to determine if a `pushState` has been triggered elsewhere,
478
+ * and thus to prevent the `write` method from calling `pushState`.
479
+ */
480
+ private latestAcknowledgedHistory;
469
481
  /**
470
482
  * Initializes a new storage provider that syncs the search state to the URL
471
483
  * using web APIs (`window.location.pushState` and `onpopstate` event).
@@ -723,11 +735,11 @@ declare const connectHits: HitsConnector;
723
735
 
724
736
  declare const connectHitsPerPage: HitsPerPageConnector;
725
737
 
726
- declare const connectHitsWithInsights: HitsConnector;
738
+ declare const connectHitsWithInsights: HitsConnector<BaseHit>;
727
739
 
728
740
  declare const connectInfiniteHits: InfiniteHitsConnector;
729
741
 
730
- declare const connectInfiniteHitsWithInsights: InfiniteHitsConnector;
742
+ declare const connectInfiniteHitsWithInsights: InfiniteHitsConnector<BaseHit>;
731
743
 
732
744
  /**
733
745
  * **Menu** connector provides the logic to build a widget that will give the user the ability to choose a single value for a specific facet. The typical usage of menu is for navigation in categories.
@@ -1098,9 +1110,9 @@ declare type DynamicWidgetsConnectorParams = {
1098
1110
  * Function to transform the items to render.
1099
1111
  * The function also exposes the full search response.
1100
1112
  */
1101
- transformItems?(items: string[], metadata: {
1102
- results: SearchResults;
1103
- }): string[];
1113
+ transformItems?: TransformItems<string, Omit<TransformItemsMetadata, 'results'> & {
1114
+ results: NonNullable<TransformItemsMetadata['results']>;
1115
+ }>;
1104
1116
  /**
1105
1117
  * To prevent unneeded extra network requests when widgets mount or unmount,
1106
1118
  * we request all facet values.
@@ -1749,10 +1761,10 @@ declare type HighlightOptions = {
1749
1761
 
1750
1762
  declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1751
1763
 
1752
- declare type Hit = {
1764
+ declare type Hit<THit extends BaseHit = Record<string, any>> = {
1753
1765
  __position: number;
1754
1766
  __queryID?: string;
1755
- } & AlgoliaHit;
1767
+ } & AlgoliaHit<THit>;
1756
1768
 
1757
1769
  declare type HitAttributeHighlightResult = {
1758
1770
  value: string;
@@ -1767,13 +1779,16 @@ declare type HitHighlightResult = {
1767
1779
  [attribute: string]: HitAttributeHighlightResult | HitAttributeHighlightResult[] | HitHighlightResult[] | HitHighlightResult;
1768
1780
  };
1769
1781
 
1782
+ /**
1783
+ * @deprecated use Hit[] directly instead
1784
+ */
1770
1785
  declare type Hits = Hit[];
1771
1786
 
1772
1787
  declare const hits: HitsWidget;
1773
1788
 
1774
- declare type HitsConnector = Connector<HitsWidgetDescription, HitsConnectorParams>;
1789
+ declare type HitsConnector<THit extends BaseHit = BaseHit> = Connector<HitsWidgetDescription<THit>, HitsConnectorParams<THit>>;
1775
1790
 
1776
- declare type HitsConnectorParams = {
1791
+ declare type HitsConnectorParams<THit extends BaseHit = BaseHit> = {
1777
1792
  /**
1778
1793
  * Whether to escape HTML tags from hits string values.
1779
1794
  *
@@ -1783,7 +1798,7 @@ declare type HitsConnectorParams = {
1783
1798
  /**
1784
1799
  * Function to transform the items passed to the templates.
1785
1800
  */
1786
- transformItems?: TransformItems<Hit>;
1801
+ transformItems?: TransformItems<Hit<THit>>;
1787
1802
  };
1788
1803
 
1789
1804
  declare type HitsCSSClasses = Partial<{
@@ -1912,15 +1927,15 @@ declare type HitsPerPageWidgetParams = {
1912
1927
  cssClasses?: HitsPerPageCSSClasses;
1913
1928
  };
1914
1929
 
1915
- declare type HitsRenderState = {
1930
+ declare type HitsRenderState<THit extends BaseHit = BaseHit> = {
1916
1931
  /**
1917
1932
  * The matched hits from Algolia API.
1918
1933
  */
1919
- hits: Hits;
1934
+ hits: Array<Hit<THit>>;
1920
1935
  /**
1921
1936
  * The response from the Algolia API.
1922
1937
  */
1923
- results?: SearchResults<Hit>;
1938
+ results?: SearchResults<Hit<THit>>;
1924
1939
  /**
1925
1940
  * Sends an event to the Insights middleware.
1926
1941
  */
@@ -1952,11 +1967,11 @@ declare type HitsWidget = WidgetFactory<HitsWidgetDescription & {
1952
1967
  $$widgetType: 'ais.hits';
1953
1968
  }, HitsConnectorParams, HitsWidgetParams>;
1954
1969
 
1955
- declare type HitsWidgetDescription = {
1970
+ declare type HitsWidgetDescription<THit extends BaseHit = BaseHit> = {
1956
1971
  $$type: 'ais.hits';
1957
- renderState: HitsRenderState;
1972
+ renderState: HitsRenderState<THit>;
1958
1973
  indexRenderState: {
1959
- hits: WidgetRenderState<HitsRenderState, HitsConnectorParams>;
1974
+ hits: WidgetRenderState<HitsRenderState<THit>, HitsConnectorParams<THit>>;
1960
1975
  };
1961
1976
  };
1962
1977
 
@@ -2037,18 +2052,18 @@ declare type IndexWidgetParams = {
2037
2052
 
2038
2053
  declare const infiniteHits: InfiniteHitsWidget;
2039
2054
 
2040
- declare type InfiniteHitsCache = {
2041
- read: Read;
2042
- write: Write;
2055
+ declare type InfiniteHitsCache<THit extends BaseHit = BaseHit> = {
2056
+ read: Read<THit>;
2057
+ write: Write<THit>;
2043
2058
  };
2044
2059
 
2045
- declare type InfiniteHitsCachedHits = {
2046
- [page: number]: Hits;
2060
+ declare type InfiniteHitsCachedHits<THit extends BaseHit> = {
2061
+ [page: number]: Array<Hit<THit>>;
2047
2062
  };
2048
2063
 
2049
- declare type InfiniteHitsConnector = Connector<InfiniteHitsWidgetDescription, InfiniteHitsConnectorParams>;
2064
+ declare type InfiniteHitsConnector<THit extends BaseHit = BaseHit> = Connector<InfiniteHitsWidgetDescription<THit>, InfiniteHitsConnectorParams<THit>>;
2050
2065
 
2051
- declare type InfiniteHitsConnectorParams = {
2066
+ declare type InfiniteHitsConnectorParams<THit extends BaseHit = BaseHit> = {
2052
2067
  /**
2053
2068
  * Escapes HTML entities from hits string values.
2054
2069
  *
@@ -2065,13 +2080,13 @@ declare type InfiniteHitsConnectorParams = {
2065
2080
  * Receives the items, and is called before displaying them.
2066
2081
  * Useful for mapping over the items to transform, and remove or reorder them.
2067
2082
  */
2068
- transformItems?: TransformItems<Hit>;
2083
+ transformItems?: TransformItems<Hit<THit>>;
2069
2084
  /**
2070
2085
  * Reads and writes hits from/to cache.
2071
2086
  * When user comes back to the search page after leaving for product page,
2072
2087
  * this helps restore InfiniteHits and its scroll position.
2073
2088
  */
2074
- cache?: InfiniteHitsCache;
2089
+ cache?: InfiniteHitsCache<THit>;
2075
2090
  };
2076
2091
 
2077
2092
  declare type InfiniteHitsCSSClasses = Partial<{
@@ -2109,7 +2124,7 @@ declare type InfiniteHitsCSSClasses = Partial<{
2109
2124
  disabledLoadMore: string | string[];
2110
2125
  }>;
2111
2126
 
2112
- declare type InfiniteHitsRenderState = {
2127
+ declare type InfiniteHitsRenderState<THit extends BaseHit = BaseHit> = {
2113
2128
  /**
2114
2129
  * Loads the previous results.
2115
2130
  */
@@ -2137,15 +2152,15 @@ declare type InfiniteHitsRenderState = {
2137
2152
  /**
2138
2153
  * Hits for the current page
2139
2154
  */
2140
- currentPageHits: Hits;
2155
+ currentPageHits: Array<Hit<THit>>;
2141
2156
  /**
2142
2157
  * Hits for current and cached pages
2143
2158
  */
2144
- hits: Hits;
2159
+ hits: Array<Hit<THit>>;
2145
2160
  /**
2146
2161
  * The response from the Algolia API.
2147
2162
  */
2148
- results?: SearchResults<Hit>;
2163
+ results?: SearchResults<Hit<THit>>;
2149
2164
  };
2150
2165
 
2151
2166
  declare type InfiniteHitsTemplates = Partial<{
@@ -2175,11 +2190,11 @@ declare type InfiniteHitsWidget = WidgetFactory<InfiniteHitsWidgetDescription &
2175
2190
  $$widgetType: 'ais.infiniteHits';
2176
2191
  }, InfiniteHitsConnectorParams, InfiniteHitsWidgetParams>;
2177
2192
 
2178
- declare type InfiniteHitsWidgetDescription = {
2193
+ declare type InfiniteHitsWidgetDescription<THit extends BaseHit = BaseHit> = {
2179
2194
  $$type: 'ais.infiniteHits';
2180
- renderState: InfiniteHitsRenderState;
2195
+ renderState: InfiniteHitsRenderState<THit>;
2181
2196
  indexRenderState: {
2182
- infiniteHits: WidgetRenderState<InfiniteHitsRenderState, InfiniteHitsConnectorParams>;
2197
+ infiniteHits: WidgetRenderState<InfiniteHitsRenderState<THit>, InfiniteHitsConnectorParams<THit>>;
2183
2198
  };
2184
2199
  indexUiState: {
2185
2200
  page: number;
@@ -3203,8 +3218,6 @@ declare type ParamTrackedFilters = {
3203
3218
  [facetName: string]: (facetValues: TrackedFilterRefinement[]) => TrackedFilterRefinement[];
3204
3219
  };
3205
3220
 
3206
- declare type ParamTransformItems = TransformItems<any>;
3207
-
3208
3221
  declare type ParamTransformRuleContexts = (ruleContexts: string[]) => string[];
3209
3222
 
3210
3223
  declare type ParseURL<TRouteState> = (args: {
@@ -3345,7 +3358,7 @@ declare type QueryRulesConnector = Connector<QueryRulesWidgetDescription, QueryR
3345
3358
  declare type QueryRulesConnectorParams = {
3346
3359
  trackedFilters?: ParamTrackedFilters;
3347
3360
  transformRuleContexts?: ParamTransformRuleContexts;
3348
- transformItems?: ParamTransformItems;
3361
+ transformItems?: TransformItems<any>;
3349
3362
  };
3350
3363
 
3351
3364
  declare type QueryRulesRenderState = {
@@ -3798,9 +3811,9 @@ declare type RatingMenuWidgetParams = {
3798
3811
  cssClasses?: RatingMenuCSSClasses;
3799
3812
  };
3800
3813
 
3801
- declare type Read = ({ state, }: {
3814
+ declare type Read<THit extends BaseHit> = ({ state, }: {
3802
3815
  state: PlainSearchParameters;
3803
- }) => InfiniteHitsCachedHits | null;
3816
+ }) => InfiniteHitsCachedHits<THit> | null;
3804
3817
 
3805
3818
  declare type ReconfigurableOptions = Places.ReconfigurableOptions;
3806
3819
 
@@ -5050,7 +5063,11 @@ declare type TrackedFilterRefinement = string | number | boolean;
5050
5063
  /**
5051
5064
  * Transforms the given items.
5052
5065
  */
5053
- declare type TransformItems<TItem> = (items: TItem[]) => TItem[];
5066
+ declare type TransformItems<TItem, TMetadata = TransformItemsMetadata> = (items: TItem[], metadata: TMetadata) => TItem[];
5067
+
5068
+ declare type TransformItemsMetadata = {
5069
+ results?: SearchResults;
5070
+ };
5054
5071
 
5055
5072
  declare type TransformSearchParameters = (searchParameters: SearchParameters) => PlainSearchParameters;
5056
5073
 
@@ -5238,9 +5255,9 @@ declare type WidgetType<TWidgetDescription extends WidgetDescription> = TWidgetD
5238
5255
 
5239
5256
  declare type WidgetUiStates = PlacesWidgetDescription['indexUiState'];
5240
5257
 
5241
- declare type Write = ({ state, hits, }: {
5258
+ declare type Write<THit extends BaseHit> = ({ state, hits, }: {
5242
5259
  state: PlainSearchParameters;
5243
- hits: InfiniteHitsCachedHits;
5260
+ hits: InfiniteHitsCachedHits<THit>;
5244
5261
  }) => void;
5245
5262
 
5246
5263
  export { }
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.37.3 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.39.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -8483,7 +8483,7 @@
8483
8483
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8484
8484
  }
8485
8485
 
8486
- var version$1 = '4.37.3';
8486
+ var version$1 = '4.39.0';
8487
8487
 
8488
8488
  var NAMESPACE = 'ais';
8489
8489
  var component = function component(componentName) {
@@ -9600,16 +9600,23 @@
9600
9600
 
9601
9601
  _defineProperty(this, "shouldPushState", true);
9602
9602
 
9603
+ _defineProperty(this, "isDisposed", false);
9604
+
9605
+ _defineProperty(this, "latestAcknowledgedHistory", 0);
9606
+
9603
9607
  this.windowTitle = windowTitle;
9604
9608
  this.writeTimer = undefined;
9605
9609
  this.writeDelay = writeDelay;
9606
9610
  this._createURL = createURL;
9607
9611
  this.parseURL = parseURL;
9608
9612
  this.getLocation = getLocation;
9609
- safelyRunOnBrowser(function () {
9613
+ safelyRunOnBrowser(function (_ref2) {
9614
+ var window = _ref2.window;
9615
+
9610
9616
  var title = _this.windowTitle && _this.windowTitle(_this.read());
9611
9617
 
9612
9618
  setWindowTitle(title);
9619
+ _this.latestAcknowledgedHistory = window.history.length;
9613
9620
  });
9614
9621
  }
9615
9622
  /**
@@ -9634,8 +9641,8 @@
9634
9641
  value: function write(routeState) {
9635
9642
  var _this2 = this;
9636
9643
 
9637
- safelyRunOnBrowser(function (_ref2) {
9638
- var window = _ref2.window;
9644
+ safelyRunOnBrowser(function (_ref3) {
9645
+ var window = _ref3.window;
9639
9646
 
9640
9647
  var url = _this2.createURL(routeState);
9641
9648
 
@@ -9646,10 +9653,17 @@
9646
9653
  }
9647
9654
 
9648
9655
  _this2.writeTimer = setTimeout(function () {
9649
- setWindowTitle(title);
9656
+ setWindowTitle(title); // We do want to `pushState` if:
9657
+ // - the router is not disposed, IS.js needs to update the URL
9658
+ // OR
9659
+ // - the last write was from InstantSearch.js
9660
+ // (unlike a SPA, where it would have last written)
9661
+
9662
+ var lastPushWasByISAfterDispose = !_this2.isDisposed || _this2.latestAcknowledgedHistory === window.history.length;
9650
9663
 
9651
- if (_this2.shouldPushState) {
9664
+ if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
9652
9665
  window.history.pushState(routeState, title || '', url);
9666
+ _this2.latestAcknowledgedHistory = window.history.length;
9653
9667
  }
9654
9668
 
9655
9669
  _this2.shouldPushState = true;
@@ -9685,8 +9699,8 @@
9685
9699
  }
9686
9700
  };
9687
9701
 
9688
- safelyRunOnBrowser(function (_ref3) {
9689
- var window = _ref3.window;
9702
+ safelyRunOnBrowser(function (_ref4) {
9703
+ var window = _ref4.window;
9690
9704
  window.addEventListener('popstate', _this3._onPopState);
9691
9705
  });
9692
9706
  }
@@ -9716,8 +9730,9 @@
9716
9730
  value: function dispose() {
9717
9731
  var _this4 = this;
9718
9732
 
9719
- safelyRunOnBrowser(function (_ref4) {
9720
- var window = _ref4.window;
9733
+ this.isDisposed = true;
9734
+ safelyRunOnBrowser(function (_ref5) {
9735
+ var window = _ref5.window;
9721
9736
 
9722
9737
  if (_this4._onPopState) {
9723
9738
  window.removeEventListener('popstate', _this4._onPopState);
@@ -9736,12 +9751,12 @@
9736
9751
  }();
9737
9752
 
9738
9753
  function historyRouter() {
9739
- var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9740
- _ref5$createURL = _ref5.createURL,
9741
- createURL = _ref5$createURL === void 0 ? function (_ref6) {
9742
- var qsModule = _ref6.qsModule,
9743
- routeState = _ref6.routeState,
9744
- location = _ref6.location;
9754
+ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9755
+ _ref6$createURL = _ref6.createURL,
9756
+ createURL = _ref6$createURL === void 0 ? function (_ref7) {
9757
+ var qsModule = _ref7.qsModule,
9758
+ routeState = _ref7.routeState,
9759
+ location = _ref7.location;
9745
9760
  var protocol = location.protocol,
9746
9761
  hostname = location.hostname,
9747
9762
  _location$port = location.port,
@@ -9757,11 +9772,11 @@
9757
9772
  }
9758
9773
 
9759
9774
  return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
9760
- } : _ref5$createURL,
9761
- _ref5$parseURL = _ref5.parseURL,
9762
- parseURL = _ref5$parseURL === void 0 ? function (_ref7) {
9763
- var qsModule = _ref7.qsModule,
9764
- location = _ref7.location;
9775
+ } : _ref6$createURL,
9776
+ _ref6$parseURL = _ref6.parseURL,
9777
+ parseURL = _ref6$parseURL === void 0 ? function (_ref8) {
9778
+ var qsModule = _ref8.qsModule,
9779
+ location = _ref8.location;
9765
9780
  // `qs` by default converts arrays with more than 20 items to an object.
9766
9781
  // We want to avoid this because the data structure manipulated can therefore vary.
9767
9782
  // Setting the limit to `100` seems a good number because the engine's default is 100
@@ -9775,21 +9790,21 @@
9775
9790
  return qsModule.parse(location.search.slice(1), {
9776
9791
  arrayLimit: 99
9777
9792
  });
9778
- } : _ref5$parseURL,
9779
- _ref5$writeDelay = _ref5.writeDelay,
9780
- writeDelay = _ref5$writeDelay === void 0 ? 400 : _ref5$writeDelay,
9781
- windowTitle = _ref5.windowTitle,
9782
- _ref5$getLocation = _ref5.getLocation,
9783
- getLocation = _ref5$getLocation === void 0 ? function () {
9784
- return safelyRunOnBrowser(function (_ref8) {
9785
- var window = _ref8.window;
9793
+ } : _ref6$parseURL,
9794
+ _ref6$writeDelay = _ref6.writeDelay,
9795
+ writeDelay = _ref6$writeDelay === void 0 ? 400 : _ref6$writeDelay,
9796
+ windowTitle = _ref6.windowTitle,
9797
+ _ref6$getLocation = _ref6.getLocation,
9798
+ getLocation = _ref6$getLocation === void 0 ? function () {
9799
+ return safelyRunOnBrowser(function (_ref9) {
9800
+ var window = _ref9.window;
9786
9801
  return window.location;
9787
9802
  }, {
9788
9803
  fallback: function fallback() {
9789
9804
  throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
9790
9805
  }
9791
9806
  });
9792
- } : _ref5$getLocation;
9807
+ } : _ref6$getLocation;
9793
9808
 
9794
9809
  return new BrowserHistory({
9795
9810
  createURL: createURL,
@@ -9891,8 +9906,10 @@
9891
9906
 
9892
9907
  function isMetadataEnabled() {
9893
9908
  return safelyRunOnBrowser(function (_ref) {
9909
+ var _window$navigator, _window$navigator$use;
9910
+
9894
9911
  var window = _ref.window;
9895
- return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
9912
+ return ((_window$navigator = window.navigator) === null || _window$navigator === void 0 ? void 0 : (_window$navigator$use = _window$navigator.userAgent) === null || _window$navigator$use === void 0 ? void 0 : _window$navigator$use.indexOf('Algolia Crawler')) > -1;
9896
9913
  }, {
9897
9914
  fallback: function fallback() {
9898
9915
  return false;
@@ -10545,13 +10562,15 @@
10545
10562
  },
10546
10563
  getWidgetRenderState: function getWidgetRenderState(_ref2) {
10547
10564
  var createURL = _ref2.createURL,
10548
- scopedResults = _ref2.scopedResults;
10549
- connectorState.attributesToClear = scopedResults.reduce(function (results, scopedResult) {
10550
- return results.concat(getAttributesToClear({
10565
+ scopedResults = _ref2.scopedResults,
10566
+ results = _ref2.results;
10567
+ connectorState.attributesToClear = scopedResults.reduce(function (attributesToClear, scopedResult) {
10568
+ return attributesToClear.concat(getAttributesToClear({
10551
10569
  scopedResult: scopedResult,
10552
10570
  includedAttributes: includedAttributes,
10553
10571
  excludedAttributes: excludedAttributes,
10554
- transformItems: transformItems
10572
+ transformItems: transformItems,
10573
+ results: results
10555
10574
  }));
10556
10575
  }, []);
10557
10576
 
@@ -10596,7 +10615,8 @@
10596
10615
  var scopedResult = _ref5.scopedResult,
10597
10616
  includedAttributes = _ref5.includedAttributes,
10598
10617
  excludedAttributes = _ref5.excludedAttributes,
10599
- transformItems = _ref5.transformItems;
10618
+ transformItems = _ref5.transformItems,
10619
+ results = _ref5.results;
10600
10620
  var includesQuery = includedAttributes.indexOf('query') !== -1 || excludedAttributes.indexOf('query') === -1;
10601
10621
  return {
10602
10622
  helper: scopedResult.helper,
@@ -10612,7 +10632,9 @@
10612
10632
  attribute === 'query' && includesQuery || // Otherwise, ignore the excluded attributes
10613
10633
  excludedAttributes.indexOf(attribute) === -1
10614
10634
  );
10615
- })))
10635
+ })), {
10636
+ results: results
10637
+ })
10616
10638
  };
10617
10639
  }
10618
10640
 
@@ -10673,7 +10695,9 @@
10673
10695
  helper: helper,
10674
10696
  includedAttributes: includedAttributes,
10675
10697
  excludedAttributes: excludedAttributes
10676
- }));
10698
+ }), {
10699
+ results: results
10700
+ });
10677
10701
  }
10678
10702
 
10679
10703
  return scopedResults.reduce(function (accResults, scopedResult) {
@@ -10682,7 +10706,9 @@
10682
10706
  helper: scopedResult.helper,
10683
10707
  includedAttributes: includedAttributes,
10684
10708
  excludedAttributes: excludedAttributes
10685
- })));
10709
+ }), {
10710
+ results: results
10711
+ }));
10686
10712
  }, []);
10687
10713
  }
10688
10714
 
@@ -10977,7 +11003,9 @@
10977
11003
 
10978
11004
  var hasExhaustiveItems = (state.maxValuesPerFacet || 0) > getLimit() ? facetItems.length <= getLimit() : facetItems.length < getLimit();
10979
11005
  canToggleShowMore = showMore && (isShowingMore || !hasExhaustiveItems);
10980
- items = transformItems(_prepareFacetValues(facetItems));
11006
+ items = transformItems(_prepareFacetValues(facetItems), {
11007
+ results: results
11008
+ });
10981
11009
  }
10982
11010
 
10983
11011
  return {
@@ -11110,7 +11138,9 @@
11110
11138
 
11111
11139
  var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
11112
11140
  var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
11113
- var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID);
11141
+ var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
11142
+ results: results
11143
+ });
11114
11144
  return {
11115
11145
  hits: transformedHits,
11116
11146
  results: results,
@@ -11443,7 +11473,9 @@
11443
11473
  createURL = _ref5.createURL,
11444
11474
  helper = _ref5.helper;
11445
11475
  return {
11446
- items: transformItems(normalizeItems(state)),
11476
+ items: transformItems(normalizeItems(state), {
11477
+ results: results
11478
+ }),
11447
11479
  refine: connectorState.getRefine(helper),
11448
11480
  createURL: connectorState.createURLFactory({
11449
11481
  state: state,
@@ -11515,7 +11547,8 @@
11515
11547
 
11516
11548
  var connectInfiniteHits = function connectInfiniteHits(renderFn) {
11517
11549
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
11518
- checkRendering(renderFn, withUsage$7());
11550
+ checkRendering(renderFn, withUsage$7()); // @TODO: this should be a generic, but a Connector can not yet be generic itself
11551
+
11519
11552
  return function (widgetParams) {
11520
11553
  var _ref4 = widgetParams || {},
11521
11554
  _ref4$escapeHTML = _ref4.escapeHTML,
@@ -11630,7 +11663,9 @@
11630
11663
 
11631
11664
  var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
11632
11665
  var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
11633
- var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID);
11666
+ var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
11667
+ results: results
11668
+ });
11634
11669
 
11635
11670
  if (cachedHits[_page] === undefined) {
11636
11671
  cachedHits[_page] = transformedHits;
@@ -11854,7 +11889,9 @@
11854
11889
  label: label,
11855
11890
  value: value
11856
11891
  });
11857
- }));
11892
+ }), {
11893
+ results: results
11894
+ });
11858
11895
  }
11859
11896
 
11860
11897
  return {
@@ -11968,8 +12005,8 @@
11968
12005
  _ref2$items = _ref2.items,
11969
12006
  items = _ref2$items === void 0 ? [] : _ref2$items,
11970
12007
  _ref2$transformItems = _ref2.transformItems,
11971
- transformItems = _ref2$transformItems === void 0 ? function (x) {
11972
- return x;
12008
+ transformItems = _ref2$transformItems === void 0 ? function (item) {
12009
+ return item;
11973
12010
  } : _ref2$transformItems;
11974
12011
 
11975
12012
  if (attribute === '') {
@@ -12106,7 +12143,9 @@
12106
12143
 
12107
12144
  return {
12108
12145
  createURL: connectorState.createURL(state),
12109
- items: transformItems(prepareItems(state)),
12146
+ items: transformItems(prepareItems(state), {
12147
+ results: results
12148
+ }),
12110
12149
  hasNoResults: results ? results.nbHits === 0 : true,
12111
12150
  refine: connectorState.refine,
12112
12151
  sendEvent: connectorState.sendEvent,
@@ -12848,7 +12887,8 @@
12848
12887
  var createSearchForFacetValues = function createSearchForFacetValues(helper, widget) {
12849
12888
  return function (renderOptions) {
12850
12889
  return function (query) {
12851
- var instantSearchInstance = renderOptions.instantSearchInstance;
12890
+ var instantSearchInstance = renderOptions.instantSearchInstance,
12891
+ searchResults = renderOptions.results;
12852
12892
 
12853
12893
  if (query === '' && lastItemsFromMainSearch) {
12854
12894
  // render with previous data from the helper.
@@ -12875,7 +12915,9 @@
12875
12915
  value: value,
12876
12916
  label: value
12877
12917
  });
12878
- }));
12918
+ }), {
12919
+ results: searchResults
12920
+ });
12879
12921
  renderFn(_objectSpread2(_objectSpread2({}, widget.getWidgetRenderState(_objectSpread2(_objectSpread2({}, renderOptions), {}, {
12880
12922
  results: lastResultsFromMainSearch
12881
12923
  }))), {}, {
@@ -12939,7 +12981,9 @@
12939
12981
  facetOrdering: sortBy === DEFAULT_SORT$2
12940
12982
  });
12941
12983
  facetValues = values && Array.isArray(values) ? values : [];
12942
- items = transformItems(facetValues.slice(0, getLimit()).map(formatItems));
12984
+ items = transformItems(facetValues.slice(0, getLimit()).map(formatItems), {
12985
+ results: results
12986
+ });
12943
12987
  var maxValuesPerFacetConfig = state.maxValuesPerFacet;
12944
12988
  var currentLimit = getLimit(); // If the limit is the max number of facet retrieved it is impossible to know
12945
12989
  // if the facets are exhaustive. The only moment we are sure it is exhaustive
@@ -13197,7 +13241,9 @@
13197
13241
 
13198
13242
  return {
13199
13243
  currentRefinement: state.index,
13200
- options: transformItems(items),
13244
+ options: transformItems(items, {
13245
+ results: results
13246
+ }),
13201
13247
  refine: connectorState.setIndex,
13202
13248
  hasNoResults: results ? results.nbHits === 0 : true,
13203
13249
  widgetParams: widgetParams
@@ -13955,7 +14001,9 @@
13955
14001
 
13956
14002
  var facetValues = results.getFacetValues(facetName, {});
13957
14003
  var data = Array.isArray(facetValues.data) ? facetValues.data : [];
13958
- var items = transformItems(shiftItemsValues(prepareItems(data)));
14004
+ var items = transformItems(shiftItemsValues(prepareItems(data)), {
14005
+ results: results
14006
+ });
13959
14007
  return items;
13960
14008
  }
13961
14009
 
@@ -14181,7 +14229,9 @@
14181
14229
  var state = helper.state;
14182
14230
  var items = results ? transformItems(results.hits.filter(function (hit) {
14183
14231
  return hit._geoloc;
14184
- })) : [];
14232
+ }), {
14233
+ results: results
14234
+ }) : [];
14185
14235
 
14186
14236
  if (!sendEvent) {
14187
14237
  sendEvent = createSendEventForHits({
@@ -14727,7 +14777,9 @@
14727
14777
  _ref4$userData = _ref4.userData,
14728
14778
  userData = _ref4$userData === void 0 ? [] : _ref4$userData;
14729
14779
 
14730
- var items = transformItems(userData);
14780
+ var items = transformItems(userData, {
14781
+ results: results
14782
+ });
14731
14783
  return {
14732
14784
  items: items,
14733
14785
  widgetParams: widgetParams