instantsearch.js 4.55.0 → 4.56.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 (70) hide show
  1. package/cjs/components/Breadcrumb/Breadcrumb.js +2 -2
  2. package/cjs/components/Hits/Hits.js +4 -0
  3. package/cjs/components/InfiniteHits/InfiniteHits.js +4 -0
  4. package/cjs/components/RangeInput/RangeInput.js +22 -11
  5. package/cjs/components/RefinementList/RefinementList.js +34 -52
  6. package/cjs/components/Slider/Rheostat.js +163 -249
  7. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +22 -7
  8. package/cjs/lib/InstantSearch.js +2 -4
  9. package/cjs/lib/routers/history.js +54 -1
  10. package/cjs/lib/utils/escape-highlight.js +2 -0
  11. package/cjs/lib/utils/getHighlightedParts.js +1 -0
  12. package/cjs/lib/utils/render-args.js +3 -2
  13. package/cjs/lib/version.js +1 -1
  14. package/cjs/widgets/hits-per-page/hits-per-page.js +3 -1
  15. package/cjs/widgets/index/index.js +8 -8
  16. package/dist/instantsearch.development.d.ts +76 -76
  17. package/dist/instantsearch.development.js +356 -341
  18. package/dist/instantsearch.development.js.map +1 -1
  19. package/dist/instantsearch.production.d.ts +76 -76
  20. package/dist/instantsearch.production.min.d.ts +76 -76
  21. package/dist/instantsearch.production.min.js +2 -2
  22. package/dist/instantsearch.production.min.js.map +1 -1
  23. package/es/components/Breadcrumb/Breadcrumb.d.ts +2 -2
  24. package/es/components/Breadcrumb/Breadcrumb.js +2 -2
  25. package/es/components/GeoSearchControls/GeoSearchButton.d.ts +1 -1
  26. package/es/components/GeoSearchControls/GeoSearchControls.d.ts +3 -3
  27. package/es/components/GeoSearchControls/GeoSearchToggle.d.ts +1 -1
  28. package/es/components/Hits/Hits.js +4 -0
  29. package/es/components/InfiniteHits/InfiniteHits.js +4 -0
  30. package/es/components/Pagination/Pagination.d.ts +2 -2
  31. package/es/components/RangeInput/RangeInput.d.ts +7 -4
  32. package/es/components/RangeInput/RangeInput.js +22 -11
  33. package/es/components/RefinementList/RefinementList.d.ts +0 -1
  34. package/es/components/RefinementList/RefinementList.js +34 -52
  35. package/es/components/RelevantSort/RelevantSort.d.ts +1 -1
  36. package/es/components/Selector/Selector.d.ts +2 -2
  37. package/es/components/Slider/Rheostat.d.ts +23 -17
  38. package/es/components/Slider/Rheostat.js +163 -249
  39. package/es/components/Slider/Slider.d.ts +1 -1
  40. package/es/connectors/current-refinements/connectCurrentRefinements.d.ts +2 -2
  41. package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +2 -2
  42. package/es/connectors/geo-search/connectGeoSearch.d.ts +7 -7
  43. package/es/connectors/infinite-hits/connectInfiniteHits.js +23 -8
  44. package/es/connectors/menu/connectMenu.d.ts +2 -2
  45. package/es/connectors/pagination/connectPagination.d.ts +1 -1
  46. package/es/connectors/range/connectRange.d.ts +3 -3
  47. package/es/connectors/refinement-list/connectRefinementList.d.ts +3 -3
  48. package/es/connectors/relevant-sort/connectRelevantSort.d.ts +1 -1
  49. package/es/lib/InstantSearch.d.ts +13 -13
  50. package/es/lib/InstantSearch.js +3 -5
  51. package/es/lib/routers/history.d.ts +2 -2
  52. package/es/lib/routers/history.js +55 -2
  53. package/es/lib/utils/defer.d.ts +2 -2
  54. package/es/lib/utils/escape-highlight.js +2 -0
  55. package/es/lib/utils/getHighlightedParts.js +1 -0
  56. package/es/lib/utils/render-args.js +3 -2
  57. package/es/lib/version.d.ts +1 -1
  58. package/es/lib/version.js +1 -1
  59. package/es/types/middleware.d.ts +6 -6
  60. package/es/types/router.d.ts +7 -7
  61. package/es/types/widget.d.ts +1 -1
  62. package/es/widgets/dynamic-widgets/dynamic-widgets.d.ts +2 -2
  63. package/es/widgets/geo-search/createHTMLMarker.d.ts +1 -1
  64. package/es/widgets/geo-search/geo-search.d.ts +1 -1
  65. package/es/widgets/hits-per-page/hits-per-page.js +3 -1
  66. package/es/widgets/index/index.d.ts +20 -20
  67. package/es/widgets/index/index.js +8 -8
  68. package/es/widgets/panel/panel.d.ts +2 -2
  69. package/es/widgets/range-slider/range-slider.d.ts +1 -1
  70. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.55.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.56.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) :
@@ -641,6 +641,8 @@
641
641
  highlightPreTag: '<mark>',
642
642
  highlightPostTag: '</mark>'
643
643
  };
644
+
645
+ // @MAJOR: in the future, this should only escape, not replace
644
646
  function replaceTagsAndEscape(value) {
645
647
  return escape$1(value).replace(new RegExp(TAG_PLACEHOLDER.highlightPreTag, 'g'), TAG_REPLACEMENT.highlightPreTag).replace(new RegExp(TAG_PLACEHOLDER.highlightPostTag, 'g'), TAG_REPLACEMENT.highlightPostTag);
646
648
  }
@@ -1202,6 +1204,7 @@
1202
1204
  }
1203
1205
 
1204
1206
  function getHighlightedParts(highlightedValue) {
1207
+ // @MAJOR: this should use TAG_PLACEHOLDER
1205
1208
  var highlightPostTag = TAG_REPLACEMENT.highlightPostTag,
1206
1209
  highlightPreTag = TAG_REPLACEMENT.highlightPreTag;
1207
1210
  var splitByPreTag = highlightedValue.split(highlightPreTag);
@@ -1446,6 +1449,18 @@
1446
1449
  return isMiddleClick || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
1447
1450
  }
1448
1451
 
1452
+ /**
1453
+ * Recurse over all child indices
1454
+ */
1455
+ function walkIndex(indexWidget, callback) {
1456
+ callback(indexWidget);
1457
+ indexWidget.getWidgets().forEach(function (widget) {
1458
+ if (isIndexWidget(widget)) {
1459
+ walkIndex(widget, callback);
1460
+ }
1461
+ });
1462
+ }
1463
+
1449
1464
  function uniq(array) {
1450
1465
  return array.filter(function (value, index, self) {
1451
1466
  return self.indexOf(value) === index;
@@ -1615,13 +1630,14 @@
1615
1630
  }
1616
1631
  function createRenderArgs(instantSearchInstance, parent) {
1617
1632
  var results = parent.getResults();
1633
+ var helper = parent.getHelper();
1618
1634
  return {
1619
- helper: parent.getHelper(),
1635
+ helper: helper,
1620
1636
  parent: parent,
1621
1637
  instantSearchInstance: instantSearchInstance,
1622
1638
  results: results,
1623
1639
  scopedResults: parent.getScopedResults(),
1624
- state: results._state,
1640
+ state: results ? results._state : helper.state,
1625
1641
  renderState: instantSearchInstance.renderState,
1626
1642
  templatesConfig: instantSearchInstance.templatesConfig,
1627
1643
  createURL: parent.createURL,
@@ -3063,6 +3079,7 @@
3063
3079
  });
3064
3080
  isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
3065
3081
  } else {
3082
+ var _results$disjunctiveF, _results$facets, _results$hierarchical;
3066
3083
  var _state$page3 = state.page,
3067
3084
  _page = _state$page3 === void 0 ? 0 : _state$page3;
3068
3085
  if (escapeHTML && results.hits.length > 0) {
@@ -3073,7 +3090,21 @@
3073
3090
  var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
3074
3091
  results: results
3075
3092
  });
3076
- if (cachedHits[_page] === undefined && !results.__isArtificial && instantSearchInstance.status === 'idle') {
3093
+
3094
+ /*
3095
+ With dynamic widgets, facets are not included in the state before their relevant widgets are mounted. Until then, we need to bail out of writing this incomplete state representation in cache.
3096
+ */
3097
+ var hasDynamicWidgets = false;
3098
+ walkIndex(instantSearchInstance.mainIndex, function (indexWidget) {
3099
+ if (!hasDynamicWidgets && indexWidget.getWidgets().some(function (_ref7) {
3100
+ var $$type = _ref7.$$type;
3101
+ return $$type === 'ais.dynamicWidgets';
3102
+ })) {
3103
+ hasDynamicWidgets = true;
3104
+ }
3105
+ });
3106
+ var hasNoFacets = !((_results$disjunctiveF = results.disjunctiveFacets) !== null && _results$disjunctiveF !== void 0 && _results$disjunctiveF.length) && !((_results$facets = results.facets) !== null && _results$facets !== void 0 && _results$facets.length) && !((_results$hierarchical = results.hierarchicalFacets) !== null && _results$hierarchical !== void 0 && _results$hierarchical.length);
3107
+ if (cachedHits[_page] === undefined && !results.__isArtificial && instantSearchInstance.status === 'idle' && !(hasDynamicWidgets && hasNoFacets)) {
3077
3108
  cachedHits[_page] = transformedHits;
3078
3109
  cache.write({
3079
3110
  state: normalizeState(state),
@@ -3098,8 +3129,8 @@
3098
3129
  widgetParams: widgetParams
3099
3130
  };
3100
3131
  },
3101
- dispose: function dispose(_ref7) {
3102
- var state = _ref7.state;
3132
+ dispose: function dispose(_ref8) {
3133
+ var state = _ref8.state;
3103
3134
  unmountFn();
3104
3135
  var stateWithoutPage = state.setQueryParameter('page', undefined);
3105
3136
  if (!escapeHTML) {
@@ -3109,8 +3140,8 @@
3109
3140
  return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, undefined));
3110
3141
  }, {}));
3111
3142
  },
3112
- getWidgetUiState: function getWidgetUiState(uiState, _ref8) {
3113
- var searchParameters = _ref8.searchParameters;
3143
+ getWidgetUiState: function getWidgetUiState(uiState, _ref9) {
3144
+ var searchParameters = _ref9.searchParameters;
3114
3145
  var page = searchParameters.page || 0;
3115
3146
  if (!page) {
3116
3147
  // return without adding `page` to uiState
@@ -3123,8 +3154,8 @@
3123
3154
  page: page + 1
3124
3155
  });
3125
3156
  },
3126
- getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref9) {
3127
- var uiState = _ref9.uiState;
3157
+ getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref10) {
3158
+ var uiState = _ref10.uiState;
3128
3159
  var widgetSearchParameters = searchParameters;
3129
3160
  if (escapeHTML) {
3130
3161
  widgetSearchParameters = searchParameters.setQueryParameters(TAG_PLACEHOLDER);
@@ -9409,7 +9440,7 @@
9409
9440
 
9410
9441
  var requestBuilder_1 = requestBuilder;
9411
9442
 
9412
- var version = '3.11.3';
9443
+ var version = '3.13.0';
9413
9444
 
9414
9445
  var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
9415
9446
 
@@ -10675,7 +10706,9 @@
10675
10706
 
10676
10707
  var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
10677
10708
  var derivedState = derivedHelper.getModifiedState(state);
10678
- var derivedStateQueries = requestBuilder_1._getQueries(derivedState.index, derivedState);
10709
+ var derivedStateQueries = derivedState.index
10710
+ ? requestBuilder_1._getQueries(derivedState.index, derivedState)
10711
+ : [];
10679
10712
 
10680
10713
  states.push({
10681
10714
  state: derivedState,
@@ -10692,10 +10725,16 @@
10692
10725
  });
10693
10726
 
10694
10727
  var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
10695
- var queryId = this._queryId++;
10696
10728
 
10729
+ var queryId = this._queryId++;
10697
10730
  this._currentNbQueries++;
10698
10731
 
10732
+ if (!queries.length) {
10733
+ return Promise.resolve({results: []}).then(
10734
+ this._dispatchAlgoliaResponse.bind(this, states, queryId)
10735
+ );
10736
+ }
10737
+
10699
10738
  try {
10700
10739
  this.client.search(queries)
10701
10740
  .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
@@ -10740,6 +10779,14 @@
10740
10779
  var helper = s.helper;
10741
10780
  var specificResults = results.splice(0, queriesCount);
10742
10781
 
10782
+ if (!state.index) {
10783
+ helper.emit('result', {
10784
+ results: null,
10785
+ state: state
10786
+ });
10787
+ return;
10788
+ }
10789
+
10743
10790
  var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
10744
10791
 
10745
10792
  helper.emit('result', {
@@ -13062,6 +13109,48 @@
13062
13109
  }
13063
13110
  };
13064
13111
  var BrowserHistory = /*#__PURE__*/function () {
13112
+ /**
13113
+ * Transforms a UI state into a title for the page.
13114
+ */
13115
+
13116
+ /**
13117
+ * Time in milliseconds before performing a write in the history.
13118
+ * It prevents from adding too many entries in the history and
13119
+ * makes the back button more usable.
13120
+ *
13121
+ * @default 400
13122
+ */
13123
+
13124
+ /**
13125
+ * Creates a full URL based on the route state.
13126
+ * The storage adaptor maps all syncable keys to the query string of the URL.
13127
+ */
13128
+
13129
+ /**
13130
+ * Parses the URL into a route state.
13131
+ * It should be symmetrical to `createURL`.
13132
+ */
13133
+
13134
+ /**
13135
+ * Returns the location to store in the history.
13136
+ * @default () => window.location
13137
+ */
13138
+
13139
+ /**
13140
+ * Indicates if last action was back/forward in the browser.
13141
+ */
13142
+
13143
+ /**
13144
+ * Indicates whether the history router is disposed or not.
13145
+ */
13146
+
13147
+ /**
13148
+ * Indicates the window.history.length before the last call to
13149
+ * window.history.pushState (called in `write`).
13150
+ * It allows to determine if a `pushState` has been triggered elsewhere,
13151
+ * and thus to prevent the `write` method from calling `pushState`.
13152
+ */
13153
+
13065
13154
  /**
13066
13155
  * Initializes a new storage provider that syncs the search state to the URL
13067
13156
  * using web APIs (`window.location.pushState` and `onpopstate` event).
@@ -13085,6 +13174,7 @@
13085
13174
  _defineProperty(this, "parseURL", void 0);
13086
13175
  _defineProperty(this, "getLocation", void 0);
13087
13176
  _defineProperty(this, "writeTimer", void 0);
13177
+ _defineProperty(this, "_onPopState", void 0);
13088
13178
  _defineProperty(this, "inPopState", false);
13089
13179
  _defineProperty(this, "isDisposed", false);
13090
13180
  _defineProperty(this, "latestAcknowledgedHistory", 0);
@@ -13190,11 +13280,21 @@
13190
13280
  }, {
13191
13281
  key: "createURL",
13192
13282
  value: function createURL(routeState) {
13193
- return this._createURL({
13283
+ var url = this._createURL({
13194
13284
  qsModule: lib$1,
13195
13285
  routeState: routeState,
13196
13286
  location: this.getLocation()
13197
13287
  });
13288
+ {
13289
+ try {
13290
+ // We just want to check if the URL is valid.
13291
+ // eslint-disable-next-line no-new
13292
+ new URL(url);
13293
+ } catch (e) {
13294
+ _warning(false, "The URL returned by the `createURL` function is invalid.\nPlease make sure it returns an absolute URL to avoid issues, e.g: `https://algolia.com/search?query=iphone`.") ;
13295
+ }
13296
+ }
13297
+ return url;
13198
13298
  }
13199
13299
 
13200
13300
  /**
@@ -13715,7 +13815,7 @@
13715
13815
  // does not have access to lastResults, which it used to in pre-federated
13716
13816
  // search behavior.
13717
13817
  helper.lastResults = results;
13718
- lastValidSearchParameters = results._state;
13818
+ lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
13719
13819
  });
13720
13820
 
13721
13821
  // We compute the render state before calling `init` in a separate loop
@@ -13771,16 +13871,16 @@
13771
13871
  render: function render(_ref5) {
13772
13872
  var _this4 = this;
13773
13873
  var instantSearchInstance = _ref5.instantSearchInstance;
13774
- if (!this.getResults()) {
13775
- return;
13776
- }
13777
-
13778
13874
  // we can't attach a listener to the error event of search, as the error
13779
13875
  // then would no longer be thrown for global handlers.
13780
- if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests()) {
13876
+ if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
13781
13877
  helper.setState(lastValidSearchParameters);
13782
13878
  }
13783
- localWidgets.forEach(function (widget) {
13879
+
13880
+ // We only render index widgets if there are no results.
13881
+ // This makes sure `render` is never called with `results` being `null`.
13882
+ var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
13883
+ widgetsToRender.forEach(function (widget) {
13784
13884
  if (widget.getRenderState) {
13785
13885
  var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
13786
13886
  storeRenderState({
@@ -13790,7 +13890,7 @@
13790
13890
  });
13791
13891
  }
13792
13892
  });
13793
- localWidgets.forEach(function (widget) {
13893
+ widgetsToRender.forEach(function (widget) {
13794
13894
  // At this point, all the variables used below are set. Both `helper`
13795
13895
  // and `derivedHelper` have been created at the `init` step. The attribute
13796
13896
  // `lastResults` might be `null` though. It's possible that a stalled render
@@ -13932,7 +14032,7 @@
13932
14032
  };
13933
14033
  }
13934
14034
 
13935
- var version$1 = '4.55.0';
14035
+ var version$1 = '4.56.1';
13936
14036
 
13937
14037
  var withUsage$r = createDocumentationMessageGenerator({
13938
14038
  name: 'instantsearch'
@@ -14011,7 +14111,7 @@
14011
14111
  }));
14012
14112
  _this.setMaxListeners(100);
14013
14113
  var _options$indexName = options.indexName,
14014
- indexName = _options$indexName === void 0 ? null : _options$indexName,
14114
+ indexName = _options$indexName === void 0 ? '' : _options$indexName,
14015
14115
  numberLocale = options.numberLocale,
14016
14116
  _options$initialUiSta = options.initialUiState,
14017
14117
  initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
@@ -14028,9 +14128,6 @@
14028
14128
  insightsClient = _options$insightsClie === void 0 ? null : _options$insightsClie,
14029
14129
  _options$onStateChang = options.onStateChange,
14030
14130
  onStateChange = _options$onStateChang === void 0 ? null : _options$onStateChang;
14031
- if (indexName === null) {
14032
- throw new Error(withUsage$r('The `indexName` option is required.'));
14033
- }
14034
14131
  if (searchClient === null) {
14035
14132
  throw new Error(withUsage$r('The `searchClient` option is required.'));
14036
14133
  }
@@ -14272,6 +14369,7 @@
14272
14369
  mainHelper.search = function () {
14273
14370
  _this3.status = 'loading';
14274
14371
  _this3.scheduleRender(false);
14372
+ _warning(Boolean(_this3.indexName) || _this3.mainIndex.getWidgets().some(isIndexWidget), 'No indexName provided, nor an explicit index widget in the widgets tree. This is required to be able to display results.') ;
14275
14373
 
14276
14374
  // This solution allows us to keep the exact same API for the users but
14277
14375
  // under the hood, we have a different implementation. It should be
@@ -16134,10 +16232,10 @@
16134
16232
  rootTagName: "a",
16135
16233
  rootProps: {
16136
16234
  className: cssClasses.link,
16137
- href: createURL(undefined),
16235
+ href: createURL(null),
16138
16236
  onClick: function onClick(event) {
16139
16237
  event.preventDefault();
16140
- refine(undefined);
16238
+ refine(null);
16141
16239
  }
16142
16240
  }
16143
16241
  }))), items.map(function (item, idx) {
@@ -17264,49 +17362,36 @@
17264
17362
  var RefinementList$1 = /*#__PURE__*/function (_Component) {
17265
17363
  _inherits(RefinementList, _Component);
17266
17364
  var _super = _createSuper(RefinementList);
17267
- function RefinementList(props) {
17365
+ function RefinementList() {
17268
17366
  var _this;
17269
17367
  _classCallCheck(this, RefinementList);
17270
- _this = _super.call(this, props);
17271
- _defineProperty(_assertThisInitialized(_this), "searchBox", y());
17272
- _this.handleItemClick = _this.handleItemClick.bind(_assertThisInitialized(_this));
17273
- return _this;
17274
- }
17275
- _createClass(RefinementList, [{
17276
- key: "shouldComponentUpdate",
17277
- value: function shouldComponentUpdate(nextProps) {
17278
- var areFacetValuesDifferent = !isEqual(this.props.facetValues, nextProps.facetValues);
17279
- return areFacetValuesDifferent;
17280
- }
17281
- }, {
17282
- key: "refine",
17283
- value: function refine(facetValueToRefine) {
17284
- this.props.toggleRefinement(facetValueToRefine);
17368
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
17369
+ args[_key] = arguments[_key];
17285
17370
  }
17286
- }, {
17287
- key: "_generateFacetItem",
17288
- value: function _generateFacetItem(facetValue) {
17371
+ _this = _super.call.apply(_super, [this].concat(args));
17372
+ _defineProperty(_assertThisInitialized(_this), "searchBox", y());
17373
+ _defineProperty(_assertThisInitialized(_this), "_generateFacetItem", function (facetValue) {
17289
17374
  var subItems;
17290
17375
  if (isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) {
17291
- var _this$props$cssClasse = this.props.cssClasses,
17376
+ var _this$props$cssClasse = _this.props.cssClasses,
17292
17377
  root = _this$props$cssClasse.root,
17293
17378
  cssClasses = _objectWithoutProperties(_this$props$cssClasse, _excluded$k);
17294
- subItems = h(RefinementList, _extends({}, this.props, {
17379
+ subItems = h(RefinementList, _extends({}, _this.props, {
17295
17380
  // We want to keep `root` required for external usage but not for the
17296
17381
  // sub items.
17297
17382
  cssClasses: cssClasses,
17298
- depth: this.props.depth + 1,
17383
+ depth: _this.props.depth + 1,
17299
17384
  facetValues: facetValue.data,
17300
17385
  showMore: false,
17301
- className: this.props.cssClasses.childList
17386
+ className: _this.props.cssClasses.childList
17302
17387
  }));
17303
17388
  }
17304
- var url = this.props.createURL(facetValue.value);
17389
+ var url = _this.props.createURL(facetValue.value);
17305
17390
  var templateData = _objectSpread2(_objectSpread2({}, facetValue), {}, {
17306
17391
  url: url,
17307
- attribute: this.props.attribute,
17308
- cssClasses: this.props.cssClasses,
17309
- isFromSearch: this.props.isFromSearch
17392
+ attribute: _this.props.attribute,
17393
+ cssClasses: _this.props.cssClasses,
17394
+ isFromSearch: _this.props.isFromSearch
17310
17395
  });
17311
17396
  var key = facetValue.value;
17312
17397
  if (facetValue.isRefined !== undefined) {
@@ -17315,38 +17400,20 @@
17315
17400
  if (facetValue.count !== undefined) {
17316
17401
  key += "/".concat(facetValue.count);
17317
17402
  }
17318
- var refinementListItemClassName = cx(this.props.cssClasses.item, facetValue.isRefined && this.props.cssClasses.selectedItem, !facetValue.count && this.props.cssClasses.disabledItem, Boolean(isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) && this.props.cssClasses.parentItem);
17403
+ var refinementListItemClassName = cx(_this.props.cssClasses.item, facetValue.isRefined && _this.props.cssClasses.selectedItem, !facetValue.count && _this.props.cssClasses.disabledItem, Boolean(isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) && _this.props.cssClasses.parentItem);
17319
17404
  return h(RefinementListItem, {
17320
17405
  templateKey: "item",
17321
17406
  key: key,
17322
17407
  facetValueToRefine: facetValue.value,
17323
- handleClick: this.handleItemClick,
17408
+ handleClick: _this.handleItemClick,
17324
17409
  isRefined: facetValue.isRefined,
17325
17410
  className: refinementListItemClassName,
17326
17411
  subItems: subItems,
17327
17412
  templateData: templateData,
17328
- templateProps: this.props.templateProps
17413
+ templateProps: _this.props.templateProps
17329
17414
  });
17330
- }
17331
-
17332
- // Click events on DOM tree like LABEL > INPUT will result in two click events
17333
- // instead of one.
17334
- // No matter the framework, see https://www.google.com/search?q=click+label+twice
17335
- //
17336
- // Thus making it hard to distinguish activation from deactivation because both click events
17337
- // are very close. Debounce is a solution but hacky.
17338
- //
17339
- // So the code here checks if the click was done on or in a LABEL. If this LABEL
17340
- // has a checkbox inside, we ignore the first click event because we will get another one.
17341
- //
17342
- // We also check if the click was done inside a link and then e.preventDefault() because we already
17343
- // handle the url
17344
- //
17345
- // Finally, we always stop propagation of the event to avoid multiple levels RefinementLists to fail: click
17346
- // on child would click on parent also
17347
- }, {
17348
- key: "handleItemClick",
17349
- value: function handleItemClick(_ref) {
17415
+ });
17416
+ _defineProperty(_assertThisInitialized(_this), "handleItemClick", function (_ref) {
17350
17417
  var facetValueToRefine = _ref.facetValueToRefine,
17351
17418
  isRefined = _ref.isRefined,
17352
17419
  originalEvent = _ref.originalEvent;
@@ -17363,7 +17430,7 @@
17363
17430
  return;
17364
17431
  }
17365
17432
  if (originalEvent.target.tagName === 'INPUT') {
17366
- this.refine(facetValueToRefine);
17433
+ _this.refine(facetValueToRefine);
17367
17434
  return;
17368
17435
  }
17369
17436
  var parent = originalEvent.target;
@@ -17377,7 +17444,20 @@
17377
17444
  parent = parent.parentNode;
17378
17445
  }
17379
17446
  originalEvent.stopPropagation();
17380
- this.refine(facetValueToRefine);
17447
+ _this.refine(facetValueToRefine);
17448
+ });
17449
+ return _this;
17450
+ }
17451
+ _createClass(RefinementList, [{
17452
+ key: "shouldComponentUpdate",
17453
+ value: function shouldComponentUpdate(nextProps) {
17454
+ var areFacetValuesDifferent = !isEqual(this.props.facetValues, nextProps.facetValues);
17455
+ return areFacetValuesDifferent;
17456
+ }
17457
+ }, {
17458
+ key: "refine",
17459
+ value: function refine(facetValueToRefine) {
17460
+ this.props.toggleRefinement(facetValueToRefine);
17381
17461
  }
17382
17462
  }, {
17383
17463
  key: "componentWillReceiveProps",
@@ -17693,6 +17773,10 @@
17693
17773
  onClick: function onClick(event) {
17694
17774
  handleInsightsClick(event);
17695
17775
  sendEvent('click:internal', hit, 'Hit Clicked');
17776
+ },
17777
+ onAuxClick: function onAuxClick(event) {
17778
+ handleInsightsClick(event);
17779
+ sendEvent('click:internal', hit, 'Hit Clicked');
17696
17780
  }
17697
17781
  },
17698
17782
  key: hit.objectID,
@@ -17835,7 +17919,9 @@
17835
17919
  }, h(Selector, {
17836
17920
  cssClasses: cssClasses,
17837
17921
  currentValue: currentValue,
17838
- options: items,
17922
+ options: items
17923
+ // @ts-expect-error: the refine function expects a number, but setValue will call it with a string. We don't want to change the type of the refine function because it's part of the connector API.
17924
+ ,
17839
17925
  setValue: refine
17840
17926
  })), containerNode);
17841
17927
  };
@@ -17923,6 +18009,10 @@
17923
18009
  onClick: function onClick(event) {
17924
18010
  handleInsightsClick(event);
17925
18011
  sendEvent('click:internal', hit, 'Hit Clicked');
18012
+ },
18013
+ onAuxClick: function onAuxClick(event) {
18014
+ handleInsightsClick(event);
18015
+ sendEvent('click:internal', hit, 'Hit Clicked');
17926
18016
  }
17927
18017
  },
17928
18018
  key: hit.objectID,
@@ -19194,10 +19284,17 @@
19194
19284
  });
19195
19285
  };
19196
19286
 
19287
+ // Strips leading `0` from a positive number value
19288
+ function stripLeadingZeroFromInput(value) {
19289
+ return value.replace(/^(0+)\d/, function (part) {
19290
+ return Number(part).toString();
19291
+ });
19292
+ }
19197
19293
  var RangeInput = /*#__PURE__*/function (_Component) {
19198
19294
  _inherits(RangeInput, _Component);
19199
19295
  var _super = _createSuper(RangeInput);
19200
19296
  function RangeInput() {
19297
+ var _this$props$values$mi, _this$props$values$ma;
19201
19298
  var _this;
19202
19299
  _classCallCheck(this, RangeInput);
19203
19300
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -19205,36 +19302,40 @@
19205
19302
  }
19206
19303
  _this = _super.call.apply(_super, [this].concat(args));
19207
19304
  _defineProperty(_assertThisInitialized(_this), "state", {
19208
- min: _this.props.values.min,
19209
- max: _this.props.values.max
19305
+ min: (_this$props$values$mi = _this.props.values.min) === null || _this$props$values$mi === void 0 ? void 0 : _this$props$values$mi.toString(),
19306
+ max: (_this$props$values$ma = _this.props.values.max) === null || _this$props$values$ma === void 0 ? void 0 : _this$props$values$ma.toString()
19210
19307
  });
19211
19308
  _defineProperty(_assertThisInitialized(_this), "onInput", function (key) {
19212
19309
  return function (event) {
19213
19310
  var _ref = event.currentTarget,
19214
19311
  value = _ref.value;
19215
- _this.setState(_defineProperty({}, key, Number(value)));
19312
+ _this.setState(_defineProperty({}, key, value));
19216
19313
  };
19217
19314
  });
19218
19315
  _defineProperty(_assertThisInitialized(_this), "onSubmit", function (event) {
19219
19316
  event.preventDefault();
19220
- _this.props.refine([_this.state.min, _this.state.max]);
19317
+ var _this$state = _this.state,
19318
+ min = _this$state.min,
19319
+ max = _this$state.max;
19320
+ _this.props.refine([min ? Number(min) : undefined, max ? Number(max) : undefined]);
19221
19321
  });
19222
19322
  return _this;
19223
19323
  }
19224
19324
  _createClass(RangeInput, [{
19225
19325
  key: "componentWillReceiveProps",
19226
19326
  value: function componentWillReceiveProps(nextProps) {
19327
+ var _nextProps$values$min, _nextProps$values$max;
19227
19328
  this.setState({
19228
- min: nextProps.values.min,
19229
- max: nextProps.values.max
19329
+ min: (_nextProps$values$min = nextProps.values.min) === null || _nextProps$values$min === void 0 ? void 0 : _nextProps$values$min.toString(),
19330
+ max: (_nextProps$values$max = nextProps.values.max) === null || _nextProps$values$max === void 0 ? void 0 : _nextProps$values$max.toString()
19230
19331
  });
19231
19332
  }
19232
19333
  }, {
19233
19334
  key: "render",
19234
19335
  value: function render() {
19235
- var _this$state = this.state,
19236
- minValue = _this$state.min,
19237
- maxValue = _this$state.max;
19336
+ var _this$state2 = this.state,
19337
+ minValue = _this$state2.min,
19338
+ maxValue = _this$state2.max;
19238
19339
  var _this$props = this.props,
19239
19340
  min = _this$props.min,
19240
19341
  max = _this$props.max,
@@ -19257,7 +19358,7 @@
19257
19358
  min: min,
19258
19359
  max: max,
19259
19360
  step: step,
19260
- value: minValue !== null && minValue !== void 0 ? minValue : '',
19361
+ value: stripLeadingZeroFromInput(minValue !== null && minValue !== void 0 ? minValue : ''),
19261
19362
  onInput: this.onInput('min'),
19262
19363
  placeholder: min === null || min === void 0 ? void 0 : min.toString(),
19263
19364
  disabled: isDisabled
@@ -19275,7 +19376,7 @@
19275
19376
  min: min,
19276
19377
  max: max,
19277
19378
  step: step,
19278
- value: maxValue !== null && maxValue !== void 0 ? maxValue : '',
19379
+ value: stripLeadingZeroFromInput(maxValue !== null && maxValue !== void 0 ? maxValue : ''),
19279
19380
  onInput: this.onInput('max'),
19280
19381
  placeholder: max === null || max === void 0 ? void 0 : max.toString(),
19281
19382
  disabled: isDisabled
@@ -19478,10 +19579,16 @@
19478
19579
  var Rheostat = /*#__PURE__*/function (_Component) {
19479
19580
  _inherits(Rheostat, _Component);
19480
19581
  var _super = _createSuper(Rheostat);
19481
- function Rheostat(props) {
19582
+ function Rheostat() {
19482
19583
  var _this;
19483
19584
  _classCallCheck(this, Rheostat);
19484
- _this = _super.call(this, props);
19585
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
19586
+ args[_key] = arguments[_key];
19587
+ }
19588
+ _this = _super.call.apply(_super, [this].concat(args));
19589
+ _defineProperty(_assertThisInitialized(_this), "x", [0, 0].map(function (y) {
19590
+ return y;
19591
+ }));
19485
19592
  _defineProperty(_assertThisInitialized(_this), "state", {
19486
19593
  className: getClassName(_this.props),
19487
19594
  // non-null thanks to defaultProps
@@ -19496,44 +19603,14 @@
19496
19603
  values: _this.props.values
19497
19604
  });
19498
19605
  _defineProperty(_assertThisInitialized(_this), "rheostat", y());
19499
- _this.getPublicState = _this.getPublicState.bind(_assertThisInitialized(_this));
19500
- _this.getSliderBoundingBox = _this.getSliderBoundingBox.bind(_assertThisInitialized(_this));
19501
- _this.getProgressStyle = _this.getProgressStyle.bind(_assertThisInitialized(_this));
19502
- _this.getMinValue = _this.getMinValue.bind(_assertThisInitialized(_this));
19503
- _this.getMaxValue = _this.getMaxValue.bind(_assertThisInitialized(_this));
19504
- _this.getHandleDimensions = _this.getHandleDimensions.bind(_assertThisInitialized(_this));
19505
- _this.getClosestSnapPoint = _this.getClosestSnapPoint.bind(_assertThisInitialized(_this));
19506
- _this.getSnapPosition = _this.getSnapPosition.bind(_assertThisInitialized(_this));
19507
- _this.getNextPositionForKey = _this.getNextPositionForKey.bind(_assertThisInitialized(_this));
19508
- _this.getNextState = _this.getNextState.bind(_assertThisInitialized(_this));
19509
- _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
19510
- _this.getClosestHandle = _this.getClosestHandle.bind(_assertThisInitialized(_this));
19511
- _this.setStartSlide = _this.setStartSlide.bind(_assertThisInitialized(_this));
19512
- _this.startMouseSlide = _this.startMouseSlide.bind(_assertThisInitialized(_this));
19513
- _this.startTouchSlide = _this.startTouchSlide.bind(_assertThisInitialized(_this));
19514
- _this.handleMouseSlide = _this.handleMouseSlide.bind(_assertThisInitialized(_this));
19515
- _this.handleTouchSlide = _this.handleTouchSlide.bind(_assertThisInitialized(_this));
19516
- _this.handleSlide = _this.handleSlide.bind(_assertThisInitialized(_this));
19517
- _this.endSlide = _this.endSlide.bind(_assertThisInitialized(_this));
19518
- _this.handleKeydown = _this.handleKeydown.bind(_assertThisInitialized(_this));
19519
- _this.validatePosition = _this.validatePosition.bind(_assertThisInitialized(_this));
19520
- _this.validateValues = _this.validateValues.bind(_assertThisInitialized(_this));
19521
- _this.canMove = _this.canMove.bind(_assertThisInitialized(_this));
19522
- _this.fireChangeEvent = _this.fireChangeEvent.bind(_assertThisInitialized(_this));
19523
- _this.slideTo = _this.slideTo.bind(_assertThisInitialized(_this));
19524
- _this.updateNewValues = _this.updateNewValues.bind(_assertThisInitialized(_this));
19525
- return _this;
19526
- }
19527
- _createClass(Rheostat, [{
19528
- key: "componentWillReceiveProps",
19529
- value: function componentWillReceiveProps(nextProps) {
19530
- var _this$props = this.props,
19606
+ _defineProperty(_assertThisInitialized(_this), "componentWillReceiveProps", function (nextProps) {
19607
+ var _this$props = _this.props,
19531
19608
  className = _this$props.className,
19532
19609
  disabled = _this$props.disabled,
19533
19610
  min = _this$props.min,
19534
19611
  max = _this$props.max,
19535
19612
  orientation = _this$props.orientation;
19536
- var _this$state = this.state,
19613
+ var _this$state = _this.state,
19537
19614
  values = _this$state.values,
19538
19615
  slidingIndex = _this$state.slidingIndex;
19539
19616
  var minMaxChanged = nextProps.min !== min || nextProps.max !== max;
@@ -19543,33 +19620,29 @@
19543
19620
  var orientationChanged = nextProps.className !== className || nextProps.orientation !== orientation;
19544
19621
  var willBeDisabled = nextProps.disabled && !disabled;
19545
19622
  if (orientationChanged) {
19546
- this.setState({
19623
+ _this.setState({
19547
19624
  className: getClassName(nextProps)
19548
19625
  });
19549
19626
  }
19550
- if (minMaxChanged || valuesChanged) this.updateNewValues(nextProps);
19627
+ if (minMaxChanged || valuesChanged) _this.updateNewValues(nextProps);
19551
19628
  if (willBeDisabled && slidingIndex !== null) {
19552
- this.endSlide();
19629
+ _this.endSlide();
19553
19630
  }
19554
- }
19555
- }, {
19556
- key: "getPublicState",
19557
- value: function getPublicState() {
19558
- var _this$props2 = this.props,
19631
+ });
19632
+ _defineProperty(_assertThisInitialized(_this), "getPublicState", function () {
19633
+ var _this$props2 = _this.props,
19559
19634
  min = _this$props2.min,
19560
19635
  max = _this$props2.max;
19561
- var values = this.state.values;
19636
+ var values = _this.state.values;
19562
19637
  return {
19563
19638
  max: max,
19564
19639
  min: min,
19565
19640
  values: values
19566
19641
  };
19567
- }
19568
- }, {
19569
- key: "getSliderBoundingBox",
19570
- value: function getSliderBoundingBox() {
19642
+ });
19643
+ _defineProperty(_assertThisInitialized(_this), "getSliderBoundingBox", function () {
19571
19644
  // only gets called after render, so it will always be defined
19572
- var node = this.rheostat.current;
19645
+ var node = _this.rheostat.current;
19573
19646
  var rect = node.getBoundingClientRect();
19574
19647
  return {
19575
19648
  height: rect.height || node.clientHeight,
@@ -19577,14 +19650,12 @@
19577
19650
  top: rect.top,
19578
19651
  width: rect.width || node.clientWidth
19579
19652
  };
19580
- }
19581
- }, {
19582
- key: "getProgressStyle",
19583
- value: function getProgressStyle(idx) {
19584
- var handlePos = this.state.handlePos;
19653
+ });
19654
+ _defineProperty(_assertThisInitialized(_this), "getProgressStyle", function (idx) {
19655
+ var handlePos = _this.state.handlePos;
19585
19656
  var value = handlePos[idx];
19586
19657
  if (idx === 0) {
19587
- return this.props.orientation === 'vertical' ? {
19658
+ return _this.props.orientation === 'vertical' ? {
19588
19659
  height: "".concat(value, "%"),
19589
19660
  top: 0
19590
19661
  } : {
@@ -19594,63 +19665,51 @@
19594
19665
  }
19595
19666
  var prevValue = handlePos[idx - 1];
19596
19667
  var diffValue = value - prevValue;
19597
- return this.props.orientation === 'vertical' ? {
19668
+ return _this.props.orientation === 'vertical' ? {
19598
19669
  height: "".concat(diffValue, "%"),
19599
19670
  top: "".concat(prevValue, "%")
19600
19671
  } : {
19601
19672
  left: "".concat(prevValue, "%"),
19602
19673
  width: "".concat(diffValue, "%")
19603
19674
  };
19604
- }
19605
- }, {
19606
- key: "getMinValue",
19607
- value: function getMinValue(idx) {
19608
- return this.state.values[idx - 1] ? Math.max(this.props.min, this.state.values[idx - 1]) : this.props.min;
19609
- }
19610
- }, {
19611
- key: "getMaxValue",
19612
- value: function getMaxValue(idx) {
19613
- return this.state.values[idx + 1] ? Math.min(this.props.max, this.state.values[idx + 1]) : this.props.max;
19614
- }
19615
- }, {
19616
- key: "getHandleDimensions",
19617
- value: function getHandleDimensions(ev, sliderBox) {
19675
+ });
19676
+ _defineProperty(_assertThisInitialized(_this), "getMinValue", function (idx) {
19677
+ return _this.state.values[idx - 1] ? Math.max(_this.props.min, _this.state.values[idx - 1]) : _this.props.min;
19678
+ });
19679
+ _defineProperty(_assertThisInitialized(_this), "getMaxValue", function (idx) {
19680
+ return _this.state.values[idx + 1] ? Math.min(_this.props.max, _this.state.values[idx + 1]) : _this.props.max;
19681
+ });
19682
+ _defineProperty(_assertThisInitialized(_this), "getHandleDimensions", function (ev, sliderBox) {
19618
19683
  var handleNode = ev.currentTarget || null;
19619
19684
  if (!handleNode) return 0;
19620
- return this.props.orientation === 'vertical' ? handleNode.clientHeight / sliderBox.height * PERCENT_FULL / 2 : handleNode.clientWidth / sliderBox.width * PERCENT_FULL / 2;
19621
- }
19622
- }, {
19623
- key: "getClosestSnapPoint",
19624
- value: function getClosestSnapPoint(value) {
19685
+ return _this.props.orientation === 'vertical' ? handleNode.clientHeight / sliderBox.height * PERCENT_FULL / 2 : handleNode.clientWidth / sliderBox.width * PERCENT_FULL / 2;
19686
+ });
19687
+ _defineProperty(_assertThisInitialized(_this), "getClosestSnapPoint", function (value) {
19625
19688
  // non-null thanks to defaultProps
19626
- if (!this.props.snapPoints.length) return value;
19627
- return this.props.snapPoints.reduce(function (snapTo, snap) {
19689
+ if (!_this.props.snapPoints.length) return value;
19690
+ return _this.props.snapPoints.reduce(function (snapTo, snap) {
19628
19691
  return Math.abs(snapTo - value) < Math.abs(snap - value) ? snapTo : snap;
19629
19692
  });
19630
- }
19631
- }, {
19632
- key: "getSnapPosition",
19633
- value: function getSnapPosition(positionPercent) {
19634
- if (!this.props.snap) return positionPercent;
19635
- var _ref = this.props,
19693
+ });
19694
+ _defineProperty(_assertThisInitialized(_this), "getSnapPosition", function (positionPercent) {
19695
+ if (!_this.props.snap) return positionPercent;
19696
+ var _ref = _this.props,
19636
19697
  max = _ref.max,
19637
19698
  min = _ref.min;
19638
19699
  var value = getValue$1(positionPercent, min, max);
19639
- var snapValue = this.getClosestSnapPoint(value);
19700
+ var snapValue = _this.getClosestSnapPoint(value);
19640
19701
  return getPosition(snapValue, min, max);
19641
- }
19642
- }, {
19643
- key: "getNextPositionForKey",
19644
- value: function getNextPositionForKey(idx, keyCode) {
19702
+ });
19703
+ _defineProperty(_assertThisInitialized(_this), "getNextPositionForKey", function (idx, keyCode) {
19645
19704
  var _stepMultiplier;
19646
- var _this$state2 = this.state,
19705
+ var _this$state2 = _this.state,
19647
19706
  handlePos = _this$state2.handlePos,
19648
19707
  values = _this$state2.values;
19649
- var _ref2 = this.props,
19708
+ var _ref2 = _this.props,
19650
19709
  max = _ref2.max,
19651
19710
  min = _ref2.min,
19652
19711
  snapPoints = _ref2.snapPoints;
19653
- var shouldSnap = this.props.snap;
19712
+ var shouldSnap = _this.props.snap;
19654
19713
  var proposedValue = values[idx];
19655
19714
  var proposedPercentage = handlePos[idx];
19656
19715
  var originalPercentage = proposedPercentage;
@@ -19662,7 +19721,7 @@
19662
19721
  }
19663
19722
  var currentIndex = null;
19664
19723
  if (shouldSnap) {
19665
- currentIndex = snapPoints.indexOf(this.getClosestSnapPoint(values[idx]));
19724
+ currentIndex = snapPoints.indexOf(_this.getClosestSnapPoint(values[idx]));
19666
19725
  }
19667
19726
  var stepMultiplier = (_stepMultiplier = {}, _defineProperty(_stepMultiplier, KEYS.LEFT, function (v) {
19668
19727
  return v * -1;
@@ -19704,15 +19763,13 @@
19704
19763
  return null;
19705
19764
  }
19706
19765
  return shouldSnap ? getPosition(proposedValue, min, max) : proposedPercentage;
19707
- }
19708
- }, {
19709
- key: "getNextState",
19710
- value: function getNextState(idx, proposedPosition) {
19711
- var handlePos = this.state.handlePos;
19712
- var _ref3 = this.props,
19766
+ });
19767
+ _defineProperty(_assertThisInitialized(_this), "getNextState", function (idx, proposedPosition) {
19768
+ var handlePos = _this.state.handlePos;
19769
+ var _ref3 = _this.props,
19713
19770
  max = _ref3.max,
19714
19771
  min = _ref3.min;
19715
- var actualPosition = this.validatePosition(idx, proposedPosition);
19772
+ var actualPosition = _this.validatePosition(idx, proposedPosition);
19716
19773
  var nextHandlePos = handlePos.map(function (pos, index) {
19717
19774
  return index === idx ? actualPosition : pos;
19718
19775
  });
@@ -19722,23 +19779,19 @@
19722
19779
  return getValue$1(pos, min, max);
19723
19780
  })
19724
19781
  };
19725
- }
19726
- }, {
19727
- key: "getClosestHandle",
19728
- value: function getClosestHandle(positionPercent) {
19729
- var handlePos = this.state.handlePos;
19782
+ });
19783
+ _defineProperty(_assertThisInitialized(_this), "getClosestHandle", function (positionPercent) {
19784
+ var handlePos = _this.state.handlePos;
19730
19785
  return handlePos.reduce(function (closestIdx, _node, idx) {
19731
19786
  var challenger = Math.abs(handlePos[idx] - positionPercent);
19732
19787
  var current = Math.abs(handlePos[closestIdx] - positionPercent);
19733
19788
  return challenger < current ? idx : closestIdx;
19734
19789
  }, 0);
19735
- }
19736
- }, {
19737
- key: "setStartSlide",
19738
- value: function setStartSlide(ev, x, y) {
19739
- var sliderBox = this.getSliderBoundingBox();
19740
- this.setState({
19741
- handleDimensions: this.getHandleDimensions(ev, sliderBox),
19790
+ });
19791
+ _defineProperty(_assertThisInitialized(_this), "setStartSlide", function (ev, x, y) {
19792
+ var sliderBox = _this.getSliderBoundingBox();
19793
+ _this.setState({
19794
+ handleDimensions: _this.getHandleDimensions(ev, sliderBox),
19742
19795
  mousePos: {
19743
19796
  x: x,
19744
19797
  y: y
@@ -19746,144 +19799,118 @@
19746
19799
  sliderBox: sliderBox,
19747
19800
  slidingIndex: getHandleFor(ev)
19748
19801
  });
19749
- }
19750
- }, {
19751
- key: "startMouseSlide",
19752
- value: function startMouseSlide(ev) {
19753
- this.setStartSlide(ev, ev.clientX, ev.clientY);
19754
- document.addEventListener('mousemove', this.handleMouseSlide, false);
19755
- document.addEventListener('mouseup', this.endSlide, false);
19802
+ });
19803
+ _defineProperty(_assertThisInitialized(_this), "startMouseSlide", function (ev) {
19804
+ _this.setStartSlide(ev, ev.clientX, ev.clientY);
19805
+ document.addEventListener('mousemove', _this.handleMouseSlide, false);
19806
+ document.addEventListener('mouseup', _this.endSlide, false);
19756
19807
  killEvent(ev);
19757
- }
19758
- }, {
19759
- key: "startTouchSlide",
19760
- value: function startTouchSlide(ev) {
19808
+ });
19809
+ _defineProperty(_assertThisInitialized(_this), "startTouchSlide", function (ev) {
19761
19810
  if (ev.changedTouches.length > 1) return;
19762
19811
  var touch = ev.changedTouches[0];
19763
- this.setStartSlide(ev, touch.clientX, touch.clientY);
19764
- document.addEventListener('touchmove', this.handleTouchSlide, false);
19765
- document.addEventListener('touchend', this.endSlide, false);
19766
- if (this.props.onSliderDragStart) this.props.onSliderDragStart();
19812
+ _this.setStartSlide(ev, touch.clientX, touch.clientY);
19813
+ document.addEventListener('touchmove', _this.handleTouchSlide, false);
19814
+ document.addEventListener('touchend', _this.endSlide, false);
19815
+ if (_this.props.onSliderDragStart) _this.props.onSliderDragStart();
19767
19816
  killEvent(ev);
19768
- }
19769
- }, {
19770
- key: "handleMouseSlide",
19771
- value: function handleMouseSlide(ev) {
19772
- if (this.state.slidingIndex === null) return;
19773
- this.handleSlide(ev.clientX, ev.clientY);
19817
+ });
19818
+ _defineProperty(_assertThisInitialized(_this), "handleMouseSlide", function (ev) {
19819
+ if (_this.state.slidingIndex === null) return;
19820
+ _this.handleSlide(ev.clientX, ev.clientY);
19774
19821
  killEvent(ev);
19775
- }
19776
- }, {
19777
- key: "handleTouchSlide",
19778
- value: function handleTouchSlide(ev) {
19779
- if (this.state.slidingIndex === null) return;
19822
+ });
19823
+ _defineProperty(_assertThisInitialized(_this), "handleTouchSlide", function (ev) {
19824
+ if (_this.state.slidingIndex === null) return;
19780
19825
  if (ev.changedTouches.length > 1) {
19781
- this.endSlide();
19826
+ _this.endSlide();
19782
19827
  return;
19783
19828
  }
19784
19829
  var touch = ev.changedTouches[0];
19785
- this.handleSlide(touch.clientX, touch.clientY);
19830
+ _this.handleSlide(touch.clientX, touch.clientY);
19786
19831
  killEvent(ev);
19787
- }
19788
- }, {
19789
- key: "handleSlide",
19790
- value: function handleSlide(x, y) {
19791
- var _this$state3 = this.state,
19832
+ });
19833
+ _defineProperty(_assertThisInitialized(_this), "handleSlide", function (x, y) {
19834
+ var _this$state3 = _this.state,
19792
19835
  idx = _this$state3.slidingIndex,
19793
19836
  sliderBox = _this$state3.sliderBox;
19794
- var positionPercent = this.props.orientation === 'vertical' ? (y - sliderBox.top) / sliderBox.height * PERCENT_FULL : (x - sliderBox.left) / sliderBox.width * PERCENT_FULL;
19795
- this.slideTo(idx, positionPercent);
19796
- if (this.canMove(idx, positionPercent)) {
19837
+ var positionPercent = _this.props.orientation === 'vertical' ? (y - sliderBox.top) / sliderBox.height * PERCENT_FULL : (x - sliderBox.left) / sliderBox.width * PERCENT_FULL;
19838
+ _this.slideTo(idx, positionPercent);
19839
+ if (_this.canMove(idx, positionPercent)) {
19797
19840
  // update mouse positions
19798
- this.setState({
19841
+ _this.setState({
19799
19842
  mousePos: {
19800
19843
  x: x,
19801
19844
  y: y
19802
19845
  }
19803
19846
  });
19804
- if (this.props.onSliderDragMove) this.props.onSliderDragMove();
19847
+ if (_this.props.onSliderDragMove) _this.props.onSliderDragMove();
19805
19848
  }
19806
- }
19807
- }, {
19808
- key: "endSlide",
19809
- value: function endSlide() {
19810
- var _this2 = this;
19811
- var idx = this.state.slidingIndex;
19812
- this.setState({
19849
+ });
19850
+ _defineProperty(_assertThisInitialized(_this), "endSlide", function () {
19851
+ var idx = _this.state.slidingIndex;
19852
+ _this.setState({
19813
19853
  slidingIndex: null
19814
19854
  });
19815
- document.removeEventListener('mouseup', this.endSlide, false);
19816
- document.removeEventListener('touchend', this.endSlide, false);
19817
- document.removeEventListener('touchmove', this.handleTouchSlide, false);
19818
- document.removeEventListener('mousemove', this.handleMouseSlide, false);
19819
- if (this.props.onSliderDragEnd) this.props.onSliderDragEnd();
19820
- if (this.props.snap) {
19821
- var positionPercent = this.getSnapPosition(this.state.handlePos[idx]);
19822
- this.slideTo(idx, positionPercent, function () {
19823
- return _this2.fireChangeEvent();
19855
+ document.removeEventListener('mouseup', _this.endSlide, false);
19856
+ document.removeEventListener('touchend', _this.endSlide, false);
19857
+ document.removeEventListener('touchmove', _this.handleTouchSlide, false);
19858
+ document.removeEventListener('mousemove', _this.handleMouseSlide, false);
19859
+ if (_this.props.onSliderDragEnd) _this.props.onSliderDragEnd();
19860
+ if (_this.props.snap) {
19861
+ var positionPercent = _this.getSnapPosition(_this.state.handlePos[idx]);
19862
+ _this.slideTo(idx, positionPercent, function () {
19863
+ return _this.fireChangeEvent();
19824
19864
  });
19825
19865
  } else {
19826
- this.fireChangeEvent();
19866
+ _this.fireChangeEvent();
19827
19867
  }
19828
- }
19829
- }, {
19830
- key: "handleClick",
19831
- value: function handleClick(ev) {
19832
- var _this3 = this;
19868
+ });
19869
+ _defineProperty(_assertThisInitialized(_this), "handleClick", function (ev) {
19833
19870
  if (ev.target.getAttribute('data-handle-key')) {
19834
19871
  return;
19835
19872
  }
19836
19873
 
19837
19874
  // Calculate the position of the slider on the page so we can determine
19838
19875
  // the position where you click in relativity.
19839
- var sliderBox = this.getSliderBoundingBox();
19840
- var positionDecimal = this.props.orientation === 'vertical' ? (ev.clientY - sliderBox.top) / sliderBox.height : (ev.clientX - sliderBox.left) / sliderBox.width;
19876
+ var sliderBox = _this.getSliderBoundingBox();
19877
+ var positionDecimal = _this.props.orientation === 'vertical' ? (ev.clientY - sliderBox.top) / sliderBox.height : (ev.clientX - sliderBox.left) / sliderBox.width;
19841
19878
  var positionPercent = positionDecimal * PERCENT_FULL;
19842
- var handleId = this.getClosestHandle(positionPercent);
19843
- var validPositionPercent = this.getSnapPosition(positionPercent);
19879
+ var handleId = _this.getClosestHandle(positionPercent);
19880
+ var validPositionPercent = _this.getSnapPosition(positionPercent);
19844
19881
 
19845
19882
  // Move the handle there
19846
- this.slideTo(handleId, validPositionPercent, function () {
19847
- return _this3.fireChangeEvent();
19883
+ _this.slideTo(handleId, validPositionPercent, function () {
19884
+ return _this.fireChangeEvent();
19848
19885
  });
19849
- if (this.props.onClick) this.props.onClick();
19850
- }
19851
- }, {
19852
- key: "handleKeydown",
19853
- value: function handleKeydown(ev) {
19854
- var _this4 = this;
19886
+ if (_this.props.onClick) _this.props.onClick();
19887
+ });
19888
+ _defineProperty(_assertThisInitialized(_this), "handleKeydown", function (ev) {
19855
19889
  var idx = getHandleFor(ev);
19856
19890
  if (ev.keyCode === KEYS.ESC) {
19857
19891
  ev.currentTarget.blur();
19858
19892
  return;
19859
19893
  }
19860
- var proposedPercentage = this.getNextPositionForKey(idx, ev.keyCode);
19894
+ var proposedPercentage = _this.getNextPositionForKey(idx, ev.keyCode);
19861
19895
  if (proposedPercentage === null) return;
19862
- if (this.canMove(idx, proposedPercentage)) {
19863
- this.slideTo(idx, proposedPercentage, function () {
19864
- return _this4.fireChangeEvent();
19896
+ if (_this.canMove(idx, proposedPercentage)) {
19897
+ _this.slideTo(idx, proposedPercentage, function () {
19898
+ return _this.fireChangeEvent();
19865
19899
  });
19866
- if (this.props.onKeyPress) this.props.onKeyPress();
19900
+ if (_this.props.onKeyPress) _this.props.onKeyPress();
19867
19901
  }
19868
19902
  killEvent(ev);
19869
- }
19870
-
19871
- // Make sure the proposed position respects the bounds and
19872
- // does not collide with other handles too much.
19873
- }, {
19874
- key: "validatePosition",
19875
- value: function validatePosition(idx, proposedPosition) {
19876
- var _this$state4 = this.state,
19903
+ });
19904
+ _defineProperty(_assertThisInitialized(_this), "validatePosition", function (idx, proposedPosition) {
19905
+ var _this$state4 = _this.state,
19877
19906
  handlePos = _this$state4.handlePos,
19878
19907
  handleDimensions = _this$state4.handleDimensions;
19879
19908
  return Math.max(Math.min(proposedPosition, handlePos[idx + 1] !== undefined ? handlePos[idx + 1] - handleDimensions : PERCENT_FULL // 100% is the highest value
19880
19909
  ), handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : PERCENT_EMPTY // 0% is the lowest value
19881
19910
  );
19882
- }
19883
- }, {
19884
- key: "validateValues",
19885
- value: function validateValues(proposedValues, props) {
19886
- var _ref4 = props || this.props,
19911
+ });
19912
+ _defineProperty(_assertThisInitialized(_this), "validateValues", function (proposedValues, props) {
19913
+ var _ref4 = props || _this.props,
19887
19914
  max = _ref4.max,
19888
19915
  min = _ref4.min;
19889
19916
  return proposedValues.map(function (value, idx, values) {
@@ -19893,11 +19920,9 @@
19893
19920
  }
19894
19921
  return realValue;
19895
19922
  });
19896
- }
19897
- }, {
19898
- key: "canMove",
19899
- value: function canMove(idx, proposedPosition) {
19900
- var _this$state5 = this.state,
19923
+ });
19924
+ _defineProperty(_assertThisInitialized(_this), "canMove", function (idx, proposedPosition) {
19925
+ var _this$state5 = _this.state,
19901
19926
  handlePos = _this$state5.handlePos,
19902
19927
  handleDimensions = _this$state5.handleDimensions;
19903
19928
  if (proposedPosition < PERCENT_EMPTY) return false;
@@ -19907,29 +19932,21 @@
19907
19932
  var prevHandlePosition = handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : -Infinity;
19908
19933
  if (proposedPosition < prevHandlePosition) return false;
19909
19934
  return true;
19910
- }
19911
- }, {
19912
- key: "fireChangeEvent",
19913
- value: function fireChangeEvent() {
19914
- var onChange = this.props.onChange;
19915
- if (onChange) onChange(this.getPublicState());
19916
- }
19917
- }, {
19918
- key: "slideTo",
19919
- value: function slideTo(idx, proposedPosition, onAfterSet) {
19920
- var _this5 = this;
19921
- var nextState = this.getNextState(idx, proposedPosition);
19922
- this.setState(nextState, function () {
19923
- var onValuesUpdated = _this5.props.onValuesUpdated;
19924
- if (onValuesUpdated) onValuesUpdated(_this5.getPublicState());
19935
+ });
19936
+ _defineProperty(_assertThisInitialized(_this), "fireChangeEvent", function () {
19937
+ var onChange = _this.props.onChange;
19938
+ if (onChange) onChange(_this.getPublicState());
19939
+ });
19940
+ _defineProperty(_assertThisInitialized(_this), "slideTo", function (idx, proposedPosition, onAfterSet) {
19941
+ var nextState = _this.getNextState(idx, proposedPosition);
19942
+ _this.setState(nextState, function () {
19943
+ var onValuesUpdated = _this.props.onValuesUpdated;
19944
+ if (onValuesUpdated) onValuesUpdated(_this.getPublicState());
19925
19945
  if (onAfterSet) onAfterSet();
19926
19946
  });
19927
- }
19928
- }, {
19929
- key: "updateNewValues",
19930
- value: function updateNewValues(nextProps) {
19931
- var _this6 = this;
19932
- var slidingIndex = this.state.slidingIndex;
19947
+ });
19948
+ _defineProperty(_assertThisInitialized(_this), "updateNewValues", function (nextProps) {
19949
+ var slidingIndex = _this.state.slidingIndex;
19933
19950
 
19934
19951
  // Don't update while the slider is sliding
19935
19952
  if (slidingIndex !== null) {
@@ -19938,21 +19955,18 @@
19938
19955
  var max = nextProps.max,
19939
19956
  min = nextProps.min,
19940
19957
  values = nextProps.values;
19941
- var nextValues = this.validateValues(values, nextProps);
19942
- this.setState({
19958
+ var nextValues = _this.validateValues(values, nextProps);
19959
+ _this.setState({
19943
19960
  handlePos: nextValues.map(function (value) {
19944
19961
  return getPosition(value, min, max);
19945
19962
  }),
19946
19963
  values: nextValues
19947
19964
  }, function () {
19948
- return _this6.fireChangeEvent();
19965
+ return _this.fireChangeEvent();
19949
19966
  });
19950
- }
19951
- }, {
19952
- key: "render",
19953
- value: function render() {
19954
- var _this7 = this;
19955
- var _ref5 = this.props,
19967
+ });
19968
+ _defineProperty(_assertThisInitialized(_this), "render", function () {
19969
+ var _ref5 = _this.props,
19956
19970
  children = _ref5.children,
19957
19971
  disabled = _ref5.disabled,
19958
19972
  Handle = _ref5.handle,
@@ -19962,14 +19976,14 @@
19962
19976
  PitComponent = _ref5.pitComponent,
19963
19977
  pitPoints = _ref5.pitPoints,
19964
19978
  ProgressBar = _ref5.progressBar; // all required thanks to defaultProps
19965
- var _this$state6 = this.state,
19979
+ var _this$state6 = _this.state,
19966
19980
  className = _this$state6.className,
19967
19981
  handlePos = _this$state6.handlePos,
19968
19982
  values = _this$state6.values;
19969
19983
  return h("div", {
19970
19984
  className: className,
19971
- ref: this.rheostat,
19972
- onClick: disabled ? undefined : this.handleClick,
19985
+ ref: _this.rheostat,
19986
+ onClick: disabled ? undefined : _this.handleClick,
19973
19987
  style: {
19974
19988
  position: 'relative'
19975
19989
  }
@@ -19982,17 +19996,17 @@
19982
19996
  position: 'absolute'
19983
19997
  };
19984
19998
  return h(Handle, {
19985
- "aria-valuemax": _this7.getMaxValue(idx),
19986
- "aria-valuemin": _this7.getMinValue(idx),
19999
+ "aria-valuemax": _this.getMaxValue(idx),
20000
+ "aria-valuemin": _this.getMinValue(idx),
19987
20001
  "aria-valuenow": values[idx],
19988
20002
  "aria-disabled": disabled,
19989
20003
  "data-handle-key": idx,
19990
20004
  className: "rheostat-handle",
19991
20005
  key: "handle-".concat(idx),
19992
20006
  onClick: killEvent,
19993
- onKeyDown: disabled ? undefined : _this7.handleKeydown,
19994
- onMouseDown: disabled ? undefined : _this7.startMouseSlide,
19995
- onTouchStart: disabled ? undefined : _this7.startTouchSlide,
20007
+ onKeyDown: disabled ? undefined : _this.handleKeydown,
20008
+ onMouseDown: disabled ? undefined : _this.startMouseSlide,
20009
+ onTouchStart: disabled ? undefined : _this.startTouchSlide,
19996
20010
  role: "slider",
19997
20011
  style: handleStyle,
19998
20012
  tabIndex: 0
@@ -20004,7 +20018,7 @@
20004
20018
  return h(ProgressBar, {
20005
20019
  className: "rheostat-progress",
20006
20020
  key: "progress-bar-".concat(idx),
20007
- style: _this7.getProgressStyle(idx)
20021
+ style: _this.getProgressStyle(idx)
20008
20022
  });
20009
20023
  }), PitComponent && pitPoints.map(function (n) {
20010
20024
  var pos = getPosition(n, min, max);
@@ -20020,9 +20034,10 @@
20020
20034
  style: pitStyle
20021
20035
  }, n);
20022
20036
  }), children);
20023
- }
20024
- }]);
20025
- return Rheostat;
20037
+ });
20038
+ return _this;
20039
+ }
20040
+ return _createClass(Rheostat);
20026
20041
  }(d);
20027
20042
  _defineProperty(Rheostat, "defaultProps", {
20028
20043
  className: '',