instantsearch.js 4.37.1 → 4.38.1

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 (67) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/cjs/components/Hits/Hits.js +0 -6
  3. package/cjs/components/Pagination/Pagination.js +60 -41
  4. package/cjs/connectors/breadcrumb/connectBreadcrumb.js +6 -1
  5. package/cjs/connectors/clear-refinements/connectClearRefinements.js +11 -6
  6. package/cjs/connectors/current-refinements/connectCurrentRefinements.js +6 -2
  7. package/cjs/connectors/geo-search/connectGeoSearch.js +3 -1
  8. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
  9. package/cjs/connectors/hits/connectHits.js +3 -1
  10. package/cjs/connectors/hits-per-page/connectHitsPerPage.js +3 -1
  11. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +3 -1
  12. package/cjs/connectors/menu/connectMenu.js +3 -1
  13. package/cjs/connectors/numeric-menu/connectNumericMenu.js +5 -3
  14. package/cjs/connectors/query-rules/connectQueryRules.js +3 -1
  15. package/cjs/connectors/refinement-list/connectRefinementList.js +8 -3
  16. package/cjs/connectors/search-box/connectSearchBox.js +15 -25
  17. package/cjs/connectors/sort-by/connectSortBy.js +3 -1
  18. package/cjs/helpers/highlight.js +4 -1
  19. package/cjs/helpers/reverseHighlight.js +4 -1
  20. package/cjs/helpers/reverseSnippet.js +4 -1
  21. package/cjs/helpers/snippet.js +4 -1
  22. package/cjs/lib/routers/history.js +44 -29
  23. package/cjs/lib/version.js +1 -1
  24. package/cjs/middlewares/createMetadataMiddleware.js +3 -1
  25. package/dist/instantsearch.development.d.ts +56 -14
  26. package/dist/instantsearch.development.js +194 -171
  27. package/dist/instantsearch.development.js.map +1 -1
  28. package/dist/instantsearch.production.d.ts +56 -14
  29. package/dist/instantsearch.production.min.d.ts +56 -14
  30. package/dist/instantsearch.production.min.js +2 -2
  31. package/dist/instantsearch.production.min.js.map +1 -1
  32. package/es/components/Hits/Hits.d.ts +1 -9
  33. package/es/components/Hits/Hits.js +0 -6
  34. package/es/components/Pagination/Pagination.d.ts +3 -10
  35. package/es/components/Pagination/Pagination.js +55 -34
  36. package/es/connectors/breadcrumb/connectBreadcrumb.js +6 -1
  37. package/es/connectors/clear-refinements/connectClearRefinements.js +11 -6
  38. package/es/connectors/current-refinements/connectCurrentRefinements.js +6 -2
  39. package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +4 -5
  40. package/es/connectors/geo-search/connectGeoSearch.js +3 -1
  41. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
  42. package/es/connectors/hits/connectHits.js +3 -1
  43. package/es/connectors/hits-per-page/connectHitsPerPage.js +3 -1
  44. package/es/connectors/infinite-hits/connectInfiniteHits.js +3 -1
  45. package/es/connectors/menu/connectMenu.js +3 -1
  46. package/es/connectors/numeric-menu/connectNumericMenu.js +5 -3
  47. package/es/connectors/query-rules/connectQueryRules.d.ts +1 -2
  48. package/es/connectors/query-rules/connectQueryRules.js +3 -1
  49. package/es/connectors/refinement-list/connectRefinementList.js +8 -3
  50. package/es/connectors/search-box/connectSearchBox.js +15 -25
  51. package/es/connectors/sort-by/connectSortBy.js +3 -1
  52. package/es/connectors/toggle-refinement/connectToggleRefinement.d.ts +36 -7
  53. package/es/helpers/highlight.js +5 -2
  54. package/es/helpers/reverseHighlight.js +5 -2
  55. package/es/helpers/reverseSnippet.js +5 -2
  56. package/es/helpers/snippet.js +5 -2
  57. package/es/lib/routers/history.d.ts +11 -0
  58. package/es/lib/routers/history.js +44 -29
  59. package/es/lib/version.d.ts +1 -1
  60. package/es/lib/version.js +1 -1
  61. package/es/middlewares/createMetadataMiddleware.js +3 -1
  62. package/es/types/widget.d.ts +4 -1
  63. package/package.json +3 -3
  64. package/cjs/components/Pagination/PaginationLink.js +0 -60
  65. package/dist/instantsearch.development.min.d.ts +0 -5217
  66. package/es/components/Pagination/PaginationLink.d.ts +0 -16
  67. package/es/components/Pagination/PaginationLink.js +0 -49
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.37.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.38.1 | © 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.1';
8486
+ var version$1 = '4.38.1';
8487
8487
 
8488
8488
  var NAMESPACE = 'ais';
8489
8489
  var component = function component(componentName) {
@@ -8506,8 +8506,11 @@
8506
8506
  hit = _ref.hit,
8507
8507
  _ref$cssClasses = _ref.cssClasses,
8508
8508
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
8509
+ var highlightAttributeResult = getPropertyByPath(hit._highlightResult, attribute); // @MAJOR fallback to attribute value if highlight is not found
8509
8510
 
8510
- var _ref2 = getPropertyByPath(hit._highlightResult, attribute) || {},
8511
+ _warning(highlightAttributeResult, "Could not enable highlight for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is either searchable or specified in `attributesToHighlight`.\n\nSee: https://alg.li/highlighting\n")) ;
8512
+
8513
+ var _ref2 = highlightAttributeResult || {},
8511
8514
  _ref2$value = _ref2.value,
8512
8515
  attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
8513
8516
 
@@ -8526,8 +8529,11 @@
8526
8529
  hit = _ref.hit,
8527
8530
  _ref$cssClasses = _ref.cssClasses,
8528
8531
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
8532
+ var highlightAttributeResult = getPropertyByPath(hit._highlightResult, attribute); // @MAJOR fallback to attribute value if highlight is not found
8533
+
8534
+ _warning(highlightAttributeResult, "Could not enable reverse highlight for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is either searchable or specified in `attributesToHighlight`.\n\nSee: https://alg.li/highlighting\n")) ;
8529
8535
 
8530
- var _ref2 = getPropertyByPath(hit._highlightResult, attribute) || {},
8536
+ var _ref2 = highlightAttributeResult || {},
8531
8537
  _ref2$value = _ref2.value,
8532
8538
  attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
8533
8539
 
@@ -8547,8 +8553,11 @@
8547
8553
  hit = _ref.hit,
8548
8554
  _ref$cssClasses = _ref.cssClasses,
8549
8555
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
8556
+ var snippetAttributeResult = getPropertyByPath(hit._snippetResult, attribute); // @MAJOR fallback to attribute value if snippet is not found
8557
+
8558
+ _warning(snippetAttributeResult, "Could not enable snippet for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is specified in `attributesToSnippet`.\n\nSee: https://alg.li/highlighting\n")) ;
8550
8559
 
8551
- var _ref2 = getPropertyByPath(hit._snippetResult, attribute) || {},
8560
+ var _ref2 = snippetAttributeResult || {},
8552
8561
  _ref2$value = _ref2.value,
8553
8562
  attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
8554
8563
 
@@ -8567,8 +8576,11 @@
8567
8576
  hit = _ref.hit,
8568
8577
  _ref$cssClasses = _ref.cssClasses,
8569
8578
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
8579
+ var snippetAttributeResult = getPropertyByPath(hit._snippetResult, attribute); // @MAJOR fallback to attribute value if snippet is not found
8570
8580
 
8571
- var _ref2 = getPropertyByPath(hit._snippetResult, attribute) || {},
8581
+ _warning(snippetAttributeResult, "Could not enable reverse snippet for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is specified in `attributesToSnippet`.\n\nSee: https://alg.li/highlighting\n")) ;
8582
+
8583
+ var _ref2 = snippetAttributeResult || {},
8572
8584
  _ref2$value = _ref2.value,
8573
8585
  attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
8574
8586
 
@@ -9588,16 +9600,23 @@
9588
9600
 
9589
9601
  _defineProperty(this, "shouldPushState", true);
9590
9602
 
9603
+ _defineProperty(this, "isDisposed", false);
9604
+
9605
+ _defineProperty(this, "latestAcknowledgedHistory", 0);
9606
+
9591
9607
  this.windowTitle = windowTitle;
9592
9608
  this.writeTimer = undefined;
9593
9609
  this.writeDelay = writeDelay;
9594
9610
  this._createURL = createURL;
9595
9611
  this.parseURL = parseURL;
9596
9612
  this.getLocation = getLocation;
9597
- safelyRunOnBrowser(function () {
9613
+ safelyRunOnBrowser(function (_ref2) {
9614
+ var window = _ref2.window;
9615
+
9598
9616
  var title = _this.windowTitle && _this.windowTitle(_this.read());
9599
9617
 
9600
9618
  setWindowTitle(title);
9619
+ _this.latestAcknowledgedHistory = window.history.length;
9601
9620
  });
9602
9621
  }
9603
9622
  /**
@@ -9622,8 +9641,8 @@
9622
9641
  value: function write(routeState) {
9623
9642
  var _this2 = this;
9624
9643
 
9625
- safelyRunOnBrowser(function (_ref2) {
9626
- var window = _ref2.window;
9644
+ safelyRunOnBrowser(function (_ref3) {
9645
+ var window = _ref3.window;
9627
9646
 
9628
9647
  var url = _this2.createURL(routeState);
9629
9648
 
@@ -9634,10 +9653,17 @@
9634
9653
  }
9635
9654
 
9636
9655
  _this2.writeTimer = setTimeout(function () {
9637
- 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)
9638
9661
 
9639
- if (_this2.shouldPushState) {
9662
+ var lastPushWasByISAfterDispose = !_this2.isDisposed || _this2.latestAcknowledgedHistory === window.history.length;
9663
+
9664
+ if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
9640
9665
  window.history.pushState(routeState, title || '', url);
9666
+ _this2.latestAcknowledgedHistory = window.history.length;
9641
9667
  }
9642
9668
 
9643
9669
  _this2.shouldPushState = true;
@@ -9673,8 +9699,8 @@
9673
9699
  }
9674
9700
  };
9675
9701
 
9676
- safelyRunOnBrowser(function (_ref3) {
9677
- var window = _ref3.window;
9702
+ safelyRunOnBrowser(function (_ref4) {
9703
+ var window = _ref4.window;
9678
9704
  window.addEventListener('popstate', _this3._onPopState);
9679
9705
  });
9680
9706
  }
@@ -9704,8 +9730,9 @@
9704
9730
  value: function dispose() {
9705
9731
  var _this4 = this;
9706
9732
 
9707
- safelyRunOnBrowser(function (_ref4) {
9708
- var window = _ref4.window;
9733
+ this.isDisposed = true;
9734
+ safelyRunOnBrowser(function (_ref5) {
9735
+ var window = _ref5.window;
9709
9736
 
9710
9737
  if (_this4._onPopState) {
9711
9738
  window.removeEventListener('popstate', _this4._onPopState);
@@ -9724,12 +9751,12 @@
9724
9751
  }();
9725
9752
 
9726
9753
  function historyRouter() {
9727
- var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9728
- _ref5$createURL = _ref5.createURL,
9729
- createURL = _ref5$createURL === void 0 ? function (_ref6) {
9730
- var qsModule = _ref6.qsModule,
9731
- routeState = _ref6.routeState,
9732
- 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;
9733
9760
  var protocol = location.protocol,
9734
9761
  hostname = location.hostname,
9735
9762
  _location$port = location.port,
@@ -9745,11 +9772,11 @@
9745
9772
  }
9746
9773
 
9747
9774
  return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
9748
- } : _ref5$createURL,
9749
- _ref5$parseURL = _ref5.parseURL,
9750
- parseURL = _ref5$parseURL === void 0 ? function (_ref7) {
9751
- var qsModule = _ref7.qsModule,
9752
- 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;
9753
9780
  // `qs` by default converts arrays with more than 20 items to an object.
9754
9781
  // We want to avoid this because the data structure manipulated can therefore vary.
9755
9782
  // Setting the limit to `100` seems a good number because the engine's default is 100
@@ -9763,21 +9790,21 @@
9763
9790
  return qsModule.parse(location.search.slice(1), {
9764
9791
  arrayLimit: 99
9765
9792
  });
9766
- } : _ref5$parseURL,
9767
- _ref5$writeDelay = _ref5.writeDelay,
9768
- writeDelay = _ref5$writeDelay === void 0 ? 400 : _ref5$writeDelay,
9769
- windowTitle = _ref5.windowTitle,
9770
- _ref5$getLocation = _ref5.getLocation,
9771
- getLocation = _ref5$getLocation === void 0 ? function () {
9772
- return safelyRunOnBrowser(function (_ref8) {
9773
- 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;
9774
9801
  return window.location;
9775
9802
  }, {
9776
9803
  fallback: function fallback() {
9777
9804
  throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
9778
9805
  }
9779
9806
  });
9780
- } : _ref5$getLocation;
9807
+ } : _ref6$getLocation;
9781
9808
 
9782
9809
  return new BrowserHistory({
9783
9810
  createURL: createURL,
@@ -9879,8 +9906,10 @@
9879
9906
 
9880
9907
  function isMetadataEnabled() {
9881
9908
  return safelyRunOnBrowser(function (_ref) {
9909
+ var _window$navigator, _window$navigator$use;
9910
+
9882
9911
  var window = _ref.window;
9883
- 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;
9884
9913
  }, {
9885
9914
  fallback: function fallback() {
9886
9915
  return false;
@@ -10533,13 +10562,15 @@
10533
10562
  },
10534
10563
  getWidgetRenderState: function getWidgetRenderState(_ref2) {
10535
10564
  var createURL = _ref2.createURL,
10536
- scopedResults = _ref2.scopedResults;
10537
- connectorState.attributesToClear = scopedResults.reduce(function (results, scopedResult) {
10538
- 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({
10539
10569
  scopedResult: scopedResult,
10540
10570
  includedAttributes: includedAttributes,
10541
10571
  excludedAttributes: excludedAttributes,
10542
- transformItems: transformItems
10572
+ transformItems: transformItems,
10573
+ results: results
10543
10574
  }));
10544
10575
  }, []);
10545
10576
 
@@ -10584,7 +10615,8 @@
10584
10615
  var scopedResult = _ref5.scopedResult,
10585
10616
  includedAttributes = _ref5.includedAttributes,
10586
10617
  excludedAttributes = _ref5.excludedAttributes,
10587
- transformItems = _ref5.transformItems;
10618
+ transformItems = _ref5.transformItems,
10619
+ results = _ref5.results;
10588
10620
  var includesQuery = includedAttributes.indexOf('query') !== -1 || excludedAttributes.indexOf('query') === -1;
10589
10621
  return {
10590
10622
  helper: scopedResult.helper,
@@ -10600,7 +10632,9 @@
10600
10632
  attribute === 'query' && includesQuery || // Otherwise, ignore the excluded attributes
10601
10633
  excludedAttributes.indexOf(attribute) === -1
10602
10634
  );
10603
- })))
10635
+ })), {
10636
+ results: results
10637
+ })
10604
10638
  };
10605
10639
  }
10606
10640
 
@@ -10661,7 +10695,9 @@
10661
10695
  helper: helper,
10662
10696
  includedAttributes: includedAttributes,
10663
10697
  excludedAttributes: excludedAttributes
10664
- }));
10698
+ }), {
10699
+ results: results
10700
+ });
10665
10701
  }
10666
10702
 
10667
10703
  return scopedResults.reduce(function (accResults, scopedResult) {
@@ -10670,7 +10706,9 @@
10670
10706
  helper: scopedResult.helper,
10671
10707
  includedAttributes: includedAttributes,
10672
10708
  excludedAttributes: excludedAttributes
10673
- })));
10709
+ }), {
10710
+ results: results
10711
+ }));
10674
10712
  }, []);
10675
10713
  }
10676
10714
 
@@ -10965,7 +11003,9 @@
10965
11003
 
10966
11004
  var hasExhaustiveItems = (state.maxValuesPerFacet || 0) > getLimit() ? facetItems.length <= getLimit() : facetItems.length < getLimit();
10967
11005
  canToggleShowMore = showMore && (isShowingMore || !hasExhaustiveItems);
10968
- items = transformItems(_prepareFacetValues(facetItems));
11006
+ items = transformItems(_prepareFacetValues(facetItems), {
11007
+ results: results
11008
+ });
10969
11009
  }
10970
11010
 
10971
11011
  return {
@@ -11098,7 +11138,9 @@
11098
11138
 
11099
11139
  var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
11100
11140
  var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
11101
- var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID);
11141
+ var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
11142
+ results: results
11143
+ });
11102
11144
  return {
11103
11145
  hits: transformedHits,
11104
11146
  results: results,
@@ -11431,7 +11473,9 @@
11431
11473
  createURL = _ref5.createURL,
11432
11474
  helper = _ref5.helper;
11433
11475
  return {
11434
- items: transformItems(normalizeItems(state)),
11476
+ items: transformItems(normalizeItems(state), {
11477
+ results: results
11478
+ }),
11435
11479
  refine: connectorState.getRefine(helper),
11436
11480
  createURL: connectorState.createURLFactory({
11437
11481
  state: state,
@@ -11618,7 +11662,9 @@
11618
11662
 
11619
11663
  var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
11620
11664
  var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
11621
- var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID);
11665
+ var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
11666
+ results: results
11667
+ });
11622
11668
 
11623
11669
  if (cachedHits[_page] === undefined) {
11624
11670
  cachedHits[_page] = transformedHits;
@@ -11842,7 +11888,9 @@
11842
11888
  label: label,
11843
11889
  value: value
11844
11890
  });
11845
- }));
11891
+ }), {
11892
+ results: results
11893
+ });
11846
11894
  }
11847
11895
 
11848
11896
  return {
@@ -11956,8 +12004,8 @@
11956
12004
  _ref2$items = _ref2.items,
11957
12005
  items = _ref2$items === void 0 ? [] : _ref2$items,
11958
12006
  _ref2$transformItems = _ref2.transformItems,
11959
- transformItems = _ref2$transformItems === void 0 ? function (x) {
11960
- return x;
12007
+ transformItems = _ref2$transformItems === void 0 ? function (item) {
12008
+ return item;
11961
12009
  } : _ref2$transformItems;
11962
12010
 
11963
12011
  if (attribute === '') {
@@ -12094,7 +12142,9 @@
12094
12142
 
12095
12143
  return {
12096
12144
  createURL: connectorState.createURL(state),
12097
- items: transformItems(prepareItems(state)),
12145
+ items: transformItems(prepareItems(state), {
12146
+ results: results
12147
+ }),
12098
12148
  hasNoResults: results ? results.nbHits === 0 : true,
12099
12149
  refine: connectorState.refine,
12100
12150
  sendEvent: connectorState.sendEvent,
@@ -12836,7 +12886,8 @@
12836
12886
  var createSearchForFacetValues = function createSearchForFacetValues(helper, widget) {
12837
12887
  return function (renderOptions) {
12838
12888
  return function (query) {
12839
- var instantSearchInstance = renderOptions.instantSearchInstance;
12889
+ var instantSearchInstance = renderOptions.instantSearchInstance,
12890
+ searchResults = renderOptions.results;
12840
12891
 
12841
12892
  if (query === '' && lastItemsFromMainSearch) {
12842
12893
  // render with previous data from the helper.
@@ -12863,7 +12914,9 @@
12863
12914
  value: value,
12864
12915
  label: value
12865
12916
  });
12866
- }));
12917
+ }), {
12918
+ results: searchResults
12919
+ });
12867
12920
  renderFn(_objectSpread2(_objectSpread2({}, widget.getWidgetRenderState(_objectSpread2(_objectSpread2({}, renderOptions), {}, {
12868
12921
  results: lastResultsFromMainSearch
12869
12922
  }))), {}, {
@@ -12927,7 +12980,9 @@
12927
12980
  facetOrdering: sortBy === DEFAULT_SORT$2
12928
12981
  });
12929
12982
  facetValues = values && Array.isArray(values) ? values : [];
12930
- items = transformItems(facetValues.slice(0, getLimit()).map(formatItems));
12983
+ items = transformItems(facetValues.slice(0, getLimit()).map(formatItems), {
12984
+ results: results
12985
+ });
12931
12986
  var maxValuesPerFacetConfig = state.maxValuesPerFacet;
12932
12987
  var currentLimit = getLimit(); // If the limit is the max number of facet retrieved it is impossible to know
12933
12988
  // if the facets are exhaustive. The only moment we are sure it is exhaustive
@@ -13019,32 +13074,28 @@
13019
13074
  connector: true
13020
13075
  });
13021
13076
 
13077
+ var defaultQueryHook = function defaultQueryHook(query, hook) {
13078
+ return hook(query);
13079
+ };
13022
13080
  /**
13023
13081
  * **SearchBox** connector provides the logic to build a widget that will let the user search for a query.
13024
13082
  *
13025
13083
  * The connector provides to the rendering: `refine()` to set the query. The behaviour of this function
13026
13084
  * may be impacted by the `queryHook` widget parameter.
13027
13085
  */
13086
+
13087
+
13028
13088
  var connectSearchBox = function connectSearchBox(renderFn) {
13029
13089
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
13030
13090
  checkRendering(renderFn, withUsage$d());
13031
13091
  return function (widgetParams) {
13032
13092
  var _ref = widgetParams || {},
13033
- queryHook = _ref.queryHook;
13034
-
13035
- function clear(helper) {
13036
- return function () {
13037
- helper.setQuery('').search();
13038
- };
13039
- }
13093
+ _ref$queryHook = _ref.queryHook,
13094
+ queryHook = _ref$queryHook === void 0 ? defaultQueryHook : _ref$queryHook;
13040
13095
 
13041
13096
  var _refine;
13042
13097
 
13043
- var _clear = function _clear() {};
13044
-
13045
- function _cachedClear() {
13046
- _clear();
13047
- }
13098
+ var _clear;
13048
13099
 
13049
13100
  return {
13050
13101
  $$type: 'ais.searchBox',
@@ -13076,27 +13127,21 @@
13076
13127
  state = _ref3.state;
13077
13128
 
13078
13129
  if (!_refine) {
13079
- var setQueryAndSearch = function setQueryAndSearch(query) {
13080
- if (query !== state.query) {
13081
- helper.setQuery(query).search();
13082
- }
13083
- };
13084
-
13085
13130
  _refine = function _refine(query) {
13086
- if (queryHook) {
13087
- queryHook(query, setQueryAndSearch);
13088
- return;
13089
- }
13131
+ queryHook(query, function (q) {
13132
+ return helper.setQuery(q).search();
13133
+ });
13134
+ };
13090
13135
 
13091
- setQueryAndSearch(query);
13136
+ _clear = function _clear() {
13137
+ helper.setQuery('').search();
13092
13138
  };
13093
13139
  }
13094
13140
 
13095
- _clear = clear(helper);
13096
13141
  return {
13097
13142
  query: state.query || '',
13098
13143
  refine: _refine,
13099
- clear: _cachedClear,
13144
+ clear: _clear,
13100
13145
  widgetParams: widgetParams,
13101
13146
  isSearchStalled: searchMetadata.isSearchStalled
13102
13147
  };
@@ -13195,7 +13240,9 @@
13195
13240
 
13196
13241
  return {
13197
13242
  currentRefinement: state.index,
13198
- options: transformItems(items),
13243
+ options: transformItems(items, {
13244
+ results: results
13245
+ }),
13199
13246
  refine: connectorState.setIndex,
13200
13247
  hasNoResults: results ? results.nbHits === 0 : true,
13201
13248
  widgetParams: widgetParams
@@ -13941,6 +13988,9 @@
13941
13988
  state = _ref2.state;
13942
13989
 
13943
13990
  function getItems() {
13991
+ // The hierarchicalFacets condition is required for flavors
13992
+ // that render immediately with empty results, without relying
13993
+ // on init() (like React InstantSearch Hooks).
13944
13994
  if (!results || state.hierarchicalFacets.length === 0) {
13945
13995
  return [];
13946
13996
  }
@@ -13950,7 +14000,9 @@
13950
14000
 
13951
14001
  var facetValues = results.getFacetValues(facetName, {});
13952
14002
  var data = Array.isArray(facetValues.data) ? facetValues.data : [];
13953
- var items = transformItems(shiftItemsValues(prepareItems(data)));
14003
+ var items = transformItems(shiftItemsValues(prepareItems(data)), {
14004
+ results: results
14005
+ });
13954
14006
  return items;
13955
14007
  }
13956
14008
 
@@ -14176,7 +14228,9 @@
14176
14228
  var state = helper.state;
14177
14229
  var items = results ? transformItems(results.hits.filter(function (hit) {
14178
14230
  return hit._geoloc;
14179
- })) : [];
14231
+ }), {
14232
+ results: results
14233
+ }) : [];
14180
14234
 
14181
14235
  if (!sendEvent) {
14182
14236
  sendEvent = createSendEventForHits({
@@ -14722,7 +14776,9 @@
14722
14776
  _ref4$userData = _ref4.userData,
14723
14777
  userData = _ref4$userData === void 0 ? [] : _ref4$userData;
14724
14778
 
14725
- var items = transformItems(userData);
14779
+ var items = transformItems(userData, {
14780
+ results: results
14781
+ });
14726
14782
  return {
14727
14783
  items: items,
14728
14784
  widgetParams: widgetParams
@@ -17576,13 +17632,6 @@
17576
17632
  })));
17577
17633
  };
17578
17634
 
17579
- Hits.defaultProps = {
17580
- results: {
17581
- hits: []
17582
- },
17583
- hits: []
17584
- };
17585
-
17586
17635
  var defaultTemplates$5 = {
17587
17636
  empty: 'No results',
17588
17637
  item: function item(data) {
@@ -18302,130 +18351,104 @@
18302
18351
  });
18303
18352
  };
18304
18353
 
18305
- /** @jsx h */
18306
-
18307
- function PaginationLink(_ref) {
18308
- var label = _ref.label,
18309
- ariaLabel = _ref.ariaLabel,
18310
- pageNumber = _ref.pageNumber,
18311
- _ref$additionalClassN = _ref.additionalClassName,
18312
- additionalClassName = _ref$additionalClassN === void 0 ? null : _ref$additionalClassN,
18313
- _ref$isDisabled = _ref.isDisabled,
18314
- isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
18315
- _ref$isSelected = _ref.isSelected,
18316
- isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
18317
- cssClasses = _ref.cssClasses,
18318
- createURL = _ref.createURL,
18319
- handleClick = _ref.handleClick;
18320
- var classes = {
18321
- item: classnames(cssClasses.item, additionalClassName, isDisabled && cssClasses.disabledItem, isSelected && cssClasses.selectedItem),
18322
- link: cssClasses.link
18323
- };
18324
-
18325
- if (isDisabled) {
18326
- return v("li", {
18327
- className: classes.item
18328
- }, v("span", {
18329
- className: classes.link,
18330
- dangerouslySetInnerHTML: {
18331
- __html: label
18332
- }
18333
- }));
18334
- }
18335
-
18336
- return v("li", {
18337
- className: classes.item
18338
- }, v("a", {
18339
- className: classes.link,
18340
- "aria-label": ariaLabel,
18341
- href: createURL(pageNumber),
18342
- onClick: function onClick(event) {
18343
- return handleClick(pageNumber, event);
18344
- },
18345
- dangerouslySetInnerHTML: {
18346
- __html: label
18347
- }
18348
- }));
18349
- }
18350
-
18351
- var defaultProps$3 = {
18352
- currentPage: 0,
18353
- nbPages: 0,
18354
- pages: []
18355
- };
18356
-
18357
18354
  function Pagination(props) {
18358
- var handleClick = function handleClick(pageNumber, event) {
18359
- if (isSpecialClick(event)) {
18360
- // do not alter the default browser behavior
18361
- // if one special key is down
18362
- return;
18363
- }
18355
+ function createClickHandler(pageNumber) {
18356
+ return function (event) {
18357
+ if (isSpecialClick(event)) {
18358
+ // do not alter the default browser behavior
18359
+ // if one special key is down
18360
+ return;
18361
+ }
18364
18362
 
18365
- event.preventDefault();
18366
- props.setCurrentPage(pageNumber);
18367
- };
18363
+ event.preventDefault();
18364
+ props.setCurrentPage(pageNumber);
18365
+ };
18366
+ }
18368
18367
 
18369
18368
  return v("div", {
18370
18369
  className: classnames(props.cssClasses.root, _defineProperty({}, props.cssClasses.noRefinementRoot, props.nbPages <= 1))
18371
18370
  }, v("ul", {
18372
18371
  className: props.cssClasses.list
18373
18372
  }, props.showFirst && v(PaginationLink, {
18374
- key: "first",
18375
- ariaLabel: 'First',
18376
- additionalClassName: props.cssClasses.firstPageItem,
18373
+ ariaLabel: "First",
18374
+ className: props.cssClasses.firstPageItem,
18377
18375
  isDisabled: props.isFirstPage,
18378
18376
  label: props.templates.first,
18379
18377
  pageNumber: 0,
18380
18378
  createURL: props.createURL,
18381
18379
  cssClasses: props.cssClasses,
18382
- handleClick: handleClick
18380
+ createClickHandler: createClickHandler
18383
18381
  }), props.showPrevious && v(PaginationLink, {
18384
- key: "previous",
18385
- ariaLabel: 'Previous',
18386
- additionalClassName: props.cssClasses.previousPageItem,
18382
+ ariaLabel: "Previous",
18383
+ className: props.cssClasses.previousPageItem,
18387
18384
  isDisabled: props.isFirstPage,
18388
18385
  label: props.templates.previous,
18389
18386
  pageNumber: props.currentPage - 1,
18390
18387
  createURL: props.createURL,
18391
18388
  cssClasses: props.cssClasses,
18392
- handleClick: handleClick
18389
+ createClickHandler: createClickHandler
18393
18390
  }), props.pages.map(function (pageNumber) {
18394
18391
  return v(PaginationLink, {
18395
18392
  key: pageNumber,
18396
18393
  ariaLabel: "".concat(pageNumber + 1),
18397
- additionalClassName: props.cssClasses.pageItem,
18394
+ className: props.cssClasses.pageItem,
18398
18395
  isSelected: pageNumber === props.currentPage,
18399
18396
  label: "".concat(pageNumber + 1),
18400
18397
  pageNumber: pageNumber,
18401
18398
  createURL: props.createURL,
18402
18399
  cssClasses: props.cssClasses,
18403
- handleClick: handleClick
18400
+ createClickHandler: createClickHandler
18404
18401
  });
18405
18402
  }), props.showNext && v(PaginationLink, {
18406
- key: "next",
18407
- ariaLabel: 'Next',
18408
- additionalClassName: props.cssClasses.nextPageItem,
18403
+ ariaLabel: "Next",
18404
+ className: props.cssClasses.nextPageItem,
18409
18405
  isDisabled: props.isLastPage,
18410
18406
  label: props.templates.next,
18411
18407
  pageNumber: props.currentPage + 1,
18412
18408
  createURL: props.createURL,
18413
18409
  cssClasses: props.cssClasses,
18414
- handleClick: handleClick
18410
+ createClickHandler: createClickHandler
18415
18411
  }), props.showLast && v(PaginationLink, {
18416
- key: "last",
18417
- ariaLabel: 'Last',
18418
- additionalClassName: props.cssClasses.lastPageItem,
18412
+ ariaLabel: "Last",
18413
+ className: props.cssClasses.lastPageItem,
18419
18414
  isDisabled: props.isLastPage,
18420
18415
  label: props.templates.last,
18421
18416
  pageNumber: props.nbPages - 1,
18422
18417
  createURL: props.createURL,
18423
18418
  cssClasses: props.cssClasses,
18424
- handleClick: handleClick
18419
+ createClickHandler: createClickHandler
18425
18420
  })));
18426
18421
  }
18427
18422
 
18428
- Pagination.defaultProps = defaultProps$3;
18423
+ function PaginationLink(_ref) {
18424
+ var label = _ref.label,
18425
+ ariaLabel = _ref.ariaLabel,
18426
+ pageNumber = _ref.pageNumber,
18427
+ className = _ref.className,
18428
+ _ref$isDisabled = _ref.isDisabled,
18429
+ isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
18430
+ _ref$isSelected = _ref.isSelected,
18431
+ isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
18432
+ cssClasses = _ref.cssClasses,
18433
+ createURL = _ref.createURL,
18434
+ createClickHandler = _ref.createClickHandler;
18435
+ return v("li", {
18436
+ className: classnames(cssClasses.item, className, isDisabled && cssClasses.disabledItem, isSelected && cssClasses.selectedItem)
18437
+ }, isDisabled ? v("span", {
18438
+ className: cssClasses.link,
18439
+ dangerouslySetInnerHTML: {
18440
+ __html: label
18441
+ }
18442
+ }) : v("a", {
18443
+ className: cssClasses.link,
18444
+ "aria-label": ariaLabel,
18445
+ href: createURL(pageNumber),
18446
+ onClick: createClickHandler(pageNumber),
18447
+ dangerouslySetInnerHTML: {
18448
+ __html: label
18449
+ }
18450
+ }));
18451
+ }
18429
18452
 
18430
18453
  var suit$h = component('Pagination');
18431
18454
  var withUsage$G = createDocumentationMessageGenerator({