instantsearch.js 4.55.0 → 4.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/cjs/components/Breadcrumb/Breadcrumb.js +2 -2
  2. package/cjs/components/RangeInput/RangeInput.js +22 -11
  3. package/cjs/components/RefinementList/RefinementList.js +34 -52
  4. package/cjs/components/Slider/Rheostat.js +163 -249
  5. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +22 -7
  6. package/cjs/lib/InstantSearch.js +2 -4
  7. package/cjs/lib/routers/history.js +54 -1
  8. package/cjs/lib/utils/render-args.js +3 -2
  9. package/cjs/lib/version.js +1 -1
  10. package/cjs/widgets/hits-per-page/hits-per-page.js +3 -1
  11. package/cjs/widgets/index/index.js +8 -8
  12. package/dist/instantsearch.development.d.ts +76 -76
  13. package/dist/instantsearch.development.js +345 -341
  14. package/dist/instantsearch.development.js.map +1 -1
  15. package/dist/instantsearch.production.d.ts +76 -76
  16. package/dist/instantsearch.production.min.d.ts +76 -76
  17. package/dist/instantsearch.production.min.js +2 -2
  18. package/dist/instantsearch.production.min.js.map +1 -1
  19. package/es/components/Breadcrumb/Breadcrumb.d.ts +2 -2
  20. package/es/components/Breadcrumb/Breadcrumb.js +2 -2
  21. package/es/components/GeoSearchControls/GeoSearchButton.d.ts +1 -1
  22. package/es/components/GeoSearchControls/GeoSearchControls.d.ts +3 -3
  23. package/es/components/GeoSearchControls/GeoSearchToggle.d.ts +1 -1
  24. package/es/components/Pagination/Pagination.d.ts +2 -2
  25. package/es/components/RangeInput/RangeInput.d.ts +7 -4
  26. package/es/components/RangeInput/RangeInput.js +22 -11
  27. package/es/components/RefinementList/RefinementList.d.ts +0 -1
  28. package/es/components/RefinementList/RefinementList.js +34 -52
  29. package/es/components/RelevantSort/RelevantSort.d.ts +1 -1
  30. package/es/components/Selector/Selector.d.ts +2 -2
  31. package/es/components/Slider/Rheostat.d.ts +23 -17
  32. package/es/components/Slider/Rheostat.js +163 -249
  33. package/es/components/Slider/Slider.d.ts +1 -1
  34. package/es/connectors/current-refinements/connectCurrentRefinements.d.ts +2 -2
  35. package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +2 -2
  36. package/es/connectors/geo-search/connectGeoSearch.d.ts +7 -7
  37. package/es/connectors/infinite-hits/connectInfiniteHits.js +23 -8
  38. package/es/connectors/menu/connectMenu.d.ts +2 -2
  39. package/es/connectors/pagination/connectPagination.d.ts +1 -1
  40. package/es/connectors/range/connectRange.d.ts +3 -3
  41. package/es/connectors/refinement-list/connectRefinementList.d.ts +3 -3
  42. package/es/connectors/relevant-sort/connectRelevantSort.d.ts +1 -1
  43. package/es/lib/InstantSearch.d.ts +13 -13
  44. package/es/lib/InstantSearch.js +3 -5
  45. package/es/lib/routers/history.d.ts +2 -2
  46. package/es/lib/routers/history.js +55 -2
  47. package/es/lib/utils/defer.d.ts +2 -2
  48. package/es/lib/utils/render-args.js +3 -2
  49. package/es/lib/version.d.ts +1 -1
  50. package/es/lib/version.js +1 -1
  51. package/es/types/middleware.d.ts +6 -6
  52. package/es/types/router.d.ts +7 -7
  53. package/es/types/widget.d.ts +1 -1
  54. package/es/widgets/dynamic-widgets/dynamic-widgets.d.ts +2 -2
  55. package/es/widgets/geo-search/createHTMLMarker.d.ts +1 -1
  56. package/es/widgets/geo-search/geo-search.d.ts +1 -1
  57. package/es/widgets/hits-per-page/hits-per-page.js +3 -1
  58. package/es/widgets/index/index.d.ts +20 -20
  59. package/es/widgets/index/index.js +8 -8
  60. package/es/widgets/panel/panel.d.ts +2 -2
  61. package/es/widgets/range-slider/range-slider.d.ts +1 -1
  62. package/package.json +6 -6
@@ -1,7 +1,7 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
2
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
3
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
5
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
6
6
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
7
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -68,10 +68,16 @@ var _ref6 = h("div", {
68
68
  var Rheostat = /*#__PURE__*/function (_Component) {
69
69
  _inherits(Rheostat, _Component);
70
70
  var _super = _createSuper(Rheostat);
71
- function Rheostat(props) {
71
+ function Rheostat() {
72
72
  var _this;
73
73
  _classCallCheck(this, Rheostat);
74
- _this = _super.call(this, props);
74
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
75
+ args[_key] = arguments[_key];
76
+ }
77
+ _this = _super.call.apply(_super, [this].concat(args));
78
+ _defineProperty(_assertThisInitialized(_this), "x", [0, 0].map(function (y) {
79
+ return y;
80
+ }));
75
81
  _defineProperty(_assertThisInitialized(_this), "state", {
76
82
  className: getClassName(_this.props),
77
83
  // non-null thanks to defaultProps
@@ -86,44 +92,14 @@ var Rheostat = /*#__PURE__*/function (_Component) {
86
92
  values: _this.props.values
87
93
  });
88
94
  _defineProperty(_assertThisInitialized(_this), "rheostat", createRef());
89
- _this.getPublicState = _this.getPublicState.bind(_assertThisInitialized(_this));
90
- _this.getSliderBoundingBox = _this.getSliderBoundingBox.bind(_assertThisInitialized(_this));
91
- _this.getProgressStyle = _this.getProgressStyle.bind(_assertThisInitialized(_this));
92
- _this.getMinValue = _this.getMinValue.bind(_assertThisInitialized(_this));
93
- _this.getMaxValue = _this.getMaxValue.bind(_assertThisInitialized(_this));
94
- _this.getHandleDimensions = _this.getHandleDimensions.bind(_assertThisInitialized(_this));
95
- _this.getClosestSnapPoint = _this.getClosestSnapPoint.bind(_assertThisInitialized(_this));
96
- _this.getSnapPosition = _this.getSnapPosition.bind(_assertThisInitialized(_this));
97
- _this.getNextPositionForKey = _this.getNextPositionForKey.bind(_assertThisInitialized(_this));
98
- _this.getNextState = _this.getNextState.bind(_assertThisInitialized(_this));
99
- _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
100
- _this.getClosestHandle = _this.getClosestHandle.bind(_assertThisInitialized(_this));
101
- _this.setStartSlide = _this.setStartSlide.bind(_assertThisInitialized(_this));
102
- _this.startMouseSlide = _this.startMouseSlide.bind(_assertThisInitialized(_this));
103
- _this.startTouchSlide = _this.startTouchSlide.bind(_assertThisInitialized(_this));
104
- _this.handleMouseSlide = _this.handleMouseSlide.bind(_assertThisInitialized(_this));
105
- _this.handleTouchSlide = _this.handleTouchSlide.bind(_assertThisInitialized(_this));
106
- _this.handleSlide = _this.handleSlide.bind(_assertThisInitialized(_this));
107
- _this.endSlide = _this.endSlide.bind(_assertThisInitialized(_this));
108
- _this.handleKeydown = _this.handleKeydown.bind(_assertThisInitialized(_this));
109
- _this.validatePosition = _this.validatePosition.bind(_assertThisInitialized(_this));
110
- _this.validateValues = _this.validateValues.bind(_assertThisInitialized(_this));
111
- _this.canMove = _this.canMove.bind(_assertThisInitialized(_this));
112
- _this.fireChangeEvent = _this.fireChangeEvent.bind(_assertThisInitialized(_this));
113
- _this.slideTo = _this.slideTo.bind(_assertThisInitialized(_this));
114
- _this.updateNewValues = _this.updateNewValues.bind(_assertThisInitialized(_this));
115
- return _this;
116
- }
117
- _createClass(Rheostat, [{
118
- key: "componentWillReceiveProps",
119
- value: function componentWillReceiveProps(nextProps) {
120
- var _this$props = this.props,
95
+ _defineProperty(_assertThisInitialized(_this), "componentWillReceiveProps", function (nextProps) {
96
+ var _this$props = _this.props,
121
97
  className = _this$props.className,
122
98
  disabled = _this$props.disabled,
123
99
  min = _this$props.min,
124
100
  max = _this$props.max,
125
101
  orientation = _this$props.orientation;
126
- var _this$state = this.state,
102
+ var _this$state = _this.state,
127
103
  values = _this$state.values,
128
104
  slidingIndex = _this$state.slidingIndex;
129
105
  var minMaxChanged = nextProps.min !== min || nextProps.max !== max;
@@ -133,33 +109,29 @@ var Rheostat = /*#__PURE__*/function (_Component) {
133
109
  var orientationChanged = nextProps.className !== className || nextProps.orientation !== orientation;
134
110
  var willBeDisabled = nextProps.disabled && !disabled;
135
111
  if (orientationChanged) {
136
- this.setState({
112
+ _this.setState({
137
113
  className: getClassName(nextProps)
138
114
  });
139
115
  }
140
- if (minMaxChanged || valuesChanged) this.updateNewValues(nextProps);
116
+ if (minMaxChanged || valuesChanged) _this.updateNewValues(nextProps);
141
117
  if (willBeDisabled && slidingIndex !== null) {
142
- this.endSlide();
118
+ _this.endSlide();
143
119
  }
144
- }
145
- }, {
146
- key: "getPublicState",
147
- value: function getPublicState() {
148
- var _this$props2 = this.props,
120
+ });
121
+ _defineProperty(_assertThisInitialized(_this), "getPublicState", function () {
122
+ var _this$props2 = _this.props,
149
123
  min = _this$props2.min,
150
124
  max = _this$props2.max;
151
- var values = this.state.values;
125
+ var values = _this.state.values;
152
126
  return {
153
127
  max: max,
154
128
  min: min,
155
129
  values: values
156
130
  };
157
- }
158
- }, {
159
- key: "getSliderBoundingBox",
160
- value: function getSliderBoundingBox() {
131
+ });
132
+ _defineProperty(_assertThisInitialized(_this), "getSliderBoundingBox", function () {
161
133
  // only gets called after render, so it will always be defined
162
- var node = this.rheostat.current;
134
+ var node = _this.rheostat.current;
163
135
  var rect = node.getBoundingClientRect();
164
136
  return {
165
137
  height: rect.height || node.clientHeight,
@@ -167,14 +139,12 @@ var Rheostat = /*#__PURE__*/function (_Component) {
167
139
  top: rect.top,
168
140
  width: rect.width || node.clientWidth
169
141
  };
170
- }
171
- }, {
172
- key: "getProgressStyle",
173
- value: function getProgressStyle(idx) {
174
- var handlePos = this.state.handlePos;
142
+ });
143
+ _defineProperty(_assertThisInitialized(_this), "getProgressStyle", function (idx) {
144
+ var handlePos = _this.state.handlePos;
175
145
  var value = handlePos[idx];
176
146
  if (idx === 0) {
177
- return this.props.orientation === 'vertical' ? {
147
+ return _this.props.orientation === 'vertical' ? {
178
148
  height: "".concat(value, "%"),
179
149
  top: 0
180
150
  } : {
@@ -184,63 +154,51 @@ var Rheostat = /*#__PURE__*/function (_Component) {
184
154
  }
185
155
  var prevValue = handlePos[idx - 1];
186
156
  var diffValue = value - prevValue;
187
- return this.props.orientation === 'vertical' ? {
157
+ return _this.props.orientation === 'vertical' ? {
188
158
  height: "".concat(diffValue, "%"),
189
159
  top: "".concat(prevValue, "%")
190
160
  } : {
191
161
  left: "".concat(prevValue, "%"),
192
162
  width: "".concat(diffValue, "%")
193
163
  };
194
- }
195
- }, {
196
- key: "getMinValue",
197
- value: function getMinValue(idx) {
198
- return this.state.values[idx - 1] ? Math.max(this.props.min, this.state.values[idx - 1]) : this.props.min;
199
- }
200
- }, {
201
- key: "getMaxValue",
202
- value: function getMaxValue(idx) {
203
- return this.state.values[idx + 1] ? Math.min(this.props.max, this.state.values[idx + 1]) : this.props.max;
204
- }
205
- }, {
206
- key: "getHandleDimensions",
207
- value: function getHandleDimensions(ev, sliderBox) {
164
+ });
165
+ _defineProperty(_assertThisInitialized(_this), "getMinValue", function (idx) {
166
+ return _this.state.values[idx - 1] ? Math.max(_this.props.min, _this.state.values[idx - 1]) : _this.props.min;
167
+ });
168
+ _defineProperty(_assertThisInitialized(_this), "getMaxValue", function (idx) {
169
+ return _this.state.values[idx + 1] ? Math.min(_this.props.max, _this.state.values[idx + 1]) : _this.props.max;
170
+ });
171
+ _defineProperty(_assertThisInitialized(_this), "getHandleDimensions", function (ev, sliderBox) {
208
172
  var handleNode = ev.currentTarget || null;
209
173
  if (!handleNode) return 0;
210
- return this.props.orientation === 'vertical' ? handleNode.clientHeight / sliderBox.height * PERCENT_FULL / 2 : handleNode.clientWidth / sliderBox.width * PERCENT_FULL / 2;
211
- }
212
- }, {
213
- key: "getClosestSnapPoint",
214
- value: function getClosestSnapPoint(value) {
174
+ return _this.props.orientation === 'vertical' ? handleNode.clientHeight / sliderBox.height * PERCENT_FULL / 2 : handleNode.clientWidth / sliderBox.width * PERCENT_FULL / 2;
175
+ });
176
+ _defineProperty(_assertThisInitialized(_this), "getClosestSnapPoint", function (value) {
215
177
  // non-null thanks to defaultProps
216
- if (!this.props.snapPoints.length) return value;
217
- return this.props.snapPoints.reduce(function (snapTo, snap) {
178
+ if (!_this.props.snapPoints.length) return value;
179
+ return _this.props.snapPoints.reduce(function (snapTo, snap) {
218
180
  return Math.abs(snapTo - value) < Math.abs(snap - value) ? snapTo : snap;
219
181
  });
220
- }
221
- }, {
222
- key: "getSnapPosition",
223
- value: function getSnapPosition(positionPercent) {
224
- if (!this.props.snap) return positionPercent;
225
- var _ref = this.props,
182
+ });
183
+ _defineProperty(_assertThisInitialized(_this), "getSnapPosition", function (positionPercent) {
184
+ if (!_this.props.snap) return positionPercent;
185
+ var _ref = _this.props,
226
186
  max = _ref.max,
227
187
  min = _ref.min;
228
188
  var value = getValue(positionPercent, min, max);
229
- var snapValue = this.getClosestSnapPoint(value);
189
+ var snapValue = _this.getClosestSnapPoint(value);
230
190
  return getPosition(snapValue, min, max);
231
- }
232
- }, {
233
- key: "getNextPositionForKey",
234
- value: function getNextPositionForKey(idx, keyCode) {
191
+ });
192
+ _defineProperty(_assertThisInitialized(_this), "getNextPositionForKey", function (idx, keyCode) {
235
193
  var _stepMultiplier;
236
- var _this$state2 = this.state,
194
+ var _this$state2 = _this.state,
237
195
  handlePos = _this$state2.handlePos,
238
196
  values = _this$state2.values;
239
- var _ref2 = this.props,
197
+ var _ref2 = _this.props,
240
198
  max = _ref2.max,
241
199
  min = _ref2.min,
242
200
  snapPoints = _ref2.snapPoints;
243
- var shouldSnap = this.props.snap;
201
+ var shouldSnap = _this.props.snap;
244
202
  var proposedValue = values[idx];
245
203
  var proposedPercentage = handlePos[idx];
246
204
  var originalPercentage = proposedPercentage;
@@ -252,7 +210,7 @@ var Rheostat = /*#__PURE__*/function (_Component) {
252
210
  }
253
211
  var currentIndex = null;
254
212
  if (shouldSnap) {
255
- currentIndex = snapPoints.indexOf(this.getClosestSnapPoint(values[idx]));
213
+ currentIndex = snapPoints.indexOf(_this.getClosestSnapPoint(values[idx]));
256
214
  }
257
215
  var stepMultiplier = (_stepMultiplier = {}, _defineProperty(_stepMultiplier, KEYS.LEFT, function (v) {
258
216
  return v * -1;
@@ -296,15 +254,13 @@ var Rheostat = /*#__PURE__*/function (_Component) {
296
254
  return null;
297
255
  }
298
256
  return shouldSnap ? getPosition(proposedValue, min, max) : proposedPercentage;
299
- }
300
- }, {
301
- key: "getNextState",
302
- value: function getNextState(idx, proposedPosition) {
303
- var handlePos = this.state.handlePos;
304
- var _ref3 = this.props,
257
+ });
258
+ _defineProperty(_assertThisInitialized(_this), "getNextState", function (idx, proposedPosition) {
259
+ var handlePos = _this.state.handlePos;
260
+ var _ref3 = _this.props,
305
261
  max = _ref3.max,
306
262
  min = _ref3.min;
307
- var actualPosition = this.validatePosition(idx, proposedPosition);
263
+ var actualPosition = _this.validatePosition(idx, proposedPosition);
308
264
  var nextHandlePos = handlePos.map(function (pos, index) {
309
265
  return index === idx ? actualPosition : pos;
310
266
  });
@@ -314,23 +270,19 @@ var Rheostat = /*#__PURE__*/function (_Component) {
314
270
  return getValue(pos, min, max);
315
271
  })
316
272
  };
317
- }
318
- }, {
319
- key: "getClosestHandle",
320
- value: function getClosestHandle(positionPercent) {
321
- var handlePos = this.state.handlePos;
273
+ });
274
+ _defineProperty(_assertThisInitialized(_this), "getClosestHandle", function (positionPercent) {
275
+ var handlePos = _this.state.handlePos;
322
276
  return handlePos.reduce(function (closestIdx, _node, idx) {
323
277
  var challenger = Math.abs(handlePos[idx] - positionPercent);
324
278
  var current = Math.abs(handlePos[closestIdx] - positionPercent);
325
279
  return challenger < current ? idx : closestIdx;
326
280
  }, 0);
327
- }
328
- }, {
329
- key: "setStartSlide",
330
- value: function setStartSlide(ev, x, y) {
331
- var sliderBox = this.getSliderBoundingBox();
332
- this.setState({
333
- handleDimensions: this.getHandleDimensions(ev, sliderBox),
281
+ });
282
+ _defineProperty(_assertThisInitialized(_this), "setStartSlide", function (ev, x, y) {
283
+ var sliderBox = _this.getSliderBoundingBox();
284
+ _this.setState({
285
+ handleDimensions: _this.getHandleDimensions(ev, sliderBox),
334
286
  mousePos: {
335
287
  x: x,
336
288
  y: y
@@ -338,144 +290,118 @@ var Rheostat = /*#__PURE__*/function (_Component) {
338
290
  sliderBox: sliderBox,
339
291
  slidingIndex: getHandleFor(ev)
340
292
  });
341
- }
342
- }, {
343
- key: "startMouseSlide",
344
- value: function startMouseSlide(ev) {
345
- this.setStartSlide(ev, ev.clientX, ev.clientY);
346
- document.addEventListener('mousemove', this.handleMouseSlide, false);
347
- document.addEventListener('mouseup', this.endSlide, false);
293
+ });
294
+ _defineProperty(_assertThisInitialized(_this), "startMouseSlide", function (ev) {
295
+ _this.setStartSlide(ev, ev.clientX, ev.clientY);
296
+ document.addEventListener('mousemove', _this.handleMouseSlide, false);
297
+ document.addEventListener('mouseup', _this.endSlide, false);
348
298
  killEvent(ev);
349
- }
350
- }, {
351
- key: "startTouchSlide",
352
- value: function startTouchSlide(ev) {
299
+ });
300
+ _defineProperty(_assertThisInitialized(_this), "startTouchSlide", function (ev) {
353
301
  if (ev.changedTouches.length > 1) return;
354
302
  var touch = ev.changedTouches[0];
355
- this.setStartSlide(ev, touch.clientX, touch.clientY);
356
- document.addEventListener('touchmove', this.handleTouchSlide, false);
357
- document.addEventListener('touchend', this.endSlide, false);
358
- if (this.props.onSliderDragStart) this.props.onSliderDragStart();
303
+ _this.setStartSlide(ev, touch.clientX, touch.clientY);
304
+ document.addEventListener('touchmove', _this.handleTouchSlide, false);
305
+ document.addEventListener('touchend', _this.endSlide, false);
306
+ if (_this.props.onSliderDragStart) _this.props.onSliderDragStart();
359
307
  killEvent(ev);
360
- }
361
- }, {
362
- key: "handleMouseSlide",
363
- value: function handleMouseSlide(ev) {
364
- if (this.state.slidingIndex === null) return;
365
- this.handleSlide(ev.clientX, ev.clientY);
308
+ });
309
+ _defineProperty(_assertThisInitialized(_this), "handleMouseSlide", function (ev) {
310
+ if (_this.state.slidingIndex === null) return;
311
+ _this.handleSlide(ev.clientX, ev.clientY);
366
312
  killEvent(ev);
367
- }
368
- }, {
369
- key: "handleTouchSlide",
370
- value: function handleTouchSlide(ev) {
371
- if (this.state.slidingIndex === null) return;
313
+ });
314
+ _defineProperty(_assertThisInitialized(_this), "handleTouchSlide", function (ev) {
315
+ if (_this.state.slidingIndex === null) return;
372
316
  if (ev.changedTouches.length > 1) {
373
- this.endSlide();
317
+ _this.endSlide();
374
318
  return;
375
319
  }
376
320
  var touch = ev.changedTouches[0];
377
- this.handleSlide(touch.clientX, touch.clientY);
321
+ _this.handleSlide(touch.clientX, touch.clientY);
378
322
  killEvent(ev);
379
- }
380
- }, {
381
- key: "handleSlide",
382
- value: function handleSlide(x, y) {
383
- var _this$state3 = this.state,
323
+ });
324
+ _defineProperty(_assertThisInitialized(_this), "handleSlide", function (x, y) {
325
+ var _this$state3 = _this.state,
384
326
  idx = _this$state3.slidingIndex,
385
327
  sliderBox = _this$state3.sliderBox;
386
- var positionPercent = this.props.orientation === 'vertical' ? (y - sliderBox.top) / sliderBox.height * PERCENT_FULL : (x - sliderBox.left) / sliderBox.width * PERCENT_FULL;
387
- this.slideTo(idx, positionPercent);
388
- if (this.canMove(idx, positionPercent)) {
328
+ var positionPercent = _this.props.orientation === 'vertical' ? (y - sliderBox.top) / sliderBox.height * PERCENT_FULL : (x - sliderBox.left) / sliderBox.width * PERCENT_FULL;
329
+ _this.slideTo(idx, positionPercent);
330
+ if (_this.canMove(idx, positionPercent)) {
389
331
  // update mouse positions
390
- this.setState({
332
+ _this.setState({
391
333
  mousePos: {
392
334
  x: x,
393
335
  y: y
394
336
  }
395
337
  });
396
- if (this.props.onSliderDragMove) this.props.onSliderDragMove();
338
+ if (_this.props.onSliderDragMove) _this.props.onSliderDragMove();
397
339
  }
398
- }
399
- }, {
400
- key: "endSlide",
401
- value: function endSlide() {
402
- var _this2 = this;
403
- var idx = this.state.slidingIndex;
404
- this.setState({
340
+ });
341
+ _defineProperty(_assertThisInitialized(_this), "endSlide", function () {
342
+ var idx = _this.state.slidingIndex;
343
+ _this.setState({
405
344
  slidingIndex: null
406
345
  });
407
- document.removeEventListener('mouseup', this.endSlide, false);
408
- document.removeEventListener('touchend', this.endSlide, false);
409
- document.removeEventListener('touchmove', this.handleTouchSlide, false);
410
- document.removeEventListener('mousemove', this.handleMouseSlide, false);
411
- if (this.props.onSliderDragEnd) this.props.onSliderDragEnd();
412
- if (this.props.snap) {
413
- var positionPercent = this.getSnapPosition(this.state.handlePos[idx]);
414
- this.slideTo(idx, positionPercent, function () {
415
- return _this2.fireChangeEvent();
346
+ document.removeEventListener('mouseup', _this.endSlide, false);
347
+ document.removeEventListener('touchend', _this.endSlide, false);
348
+ document.removeEventListener('touchmove', _this.handleTouchSlide, false);
349
+ document.removeEventListener('mousemove', _this.handleMouseSlide, false);
350
+ if (_this.props.onSliderDragEnd) _this.props.onSliderDragEnd();
351
+ if (_this.props.snap) {
352
+ var positionPercent = _this.getSnapPosition(_this.state.handlePos[idx]);
353
+ _this.slideTo(idx, positionPercent, function () {
354
+ return _this.fireChangeEvent();
416
355
  });
417
356
  } else {
418
- this.fireChangeEvent();
357
+ _this.fireChangeEvent();
419
358
  }
420
- }
421
- }, {
422
- key: "handleClick",
423
- value: function handleClick(ev) {
424
- var _this3 = this;
359
+ });
360
+ _defineProperty(_assertThisInitialized(_this), "handleClick", function (ev) {
425
361
  if (ev.target.getAttribute('data-handle-key')) {
426
362
  return;
427
363
  }
428
364
 
429
365
  // Calculate the position of the slider on the page so we can determine
430
366
  // the position where you click in relativity.
431
- var sliderBox = this.getSliderBoundingBox();
432
- var positionDecimal = this.props.orientation === 'vertical' ? (ev.clientY - sliderBox.top) / sliderBox.height : (ev.clientX - sliderBox.left) / sliderBox.width;
367
+ var sliderBox = _this.getSliderBoundingBox();
368
+ var positionDecimal = _this.props.orientation === 'vertical' ? (ev.clientY - sliderBox.top) / sliderBox.height : (ev.clientX - sliderBox.left) / sliderBox.width;
433
369
  var positionPercent = positionDecimal * PERCENT_FULL;
434
- var handleId = this.getClosestHandle(positionPercent);
435
- var validPositionPercent = this.getSnapPosition(positionPercent);
370
+ var handleId = _this.getClosestHandle(positionPercent);
371
+ var validPositionPercent = _this.getSnapPosition(positionPercent);
436
372
 
437
373
  // Move the handle there
438
- this.slideTo(handleId, validPositionPercent, function () {
439
- return _this3.fireChangeEvent();
374
+ _this.slideTo(handleId, validPositionPercent, function () {
375
+ return _this.fireChangeEvent();
440
376
  });
441
- if (this.props.onClick) this.props.onClick();
442
- }
443
- }, {
444
- key: "handleKeydown",
445
- value: function handleKeydown(ev) {
446
- var _this4 = this;
377
+ if (_this.props.onClick) _this.props.onClick();
378
+ });
379
+ _defineProperty(_assertThisInitialized(_this), "handleKeydown", function (ev) {
447
380
  var idx = getHandleFor(ev);
448
381
  if (ev.keyCode === KEYS.ESC) {
449
382
  ev.currentTarget.blur();
450
383
  return;
451
384
  }
452
- var proposedPercentage = this.getNextPositionForKey(idx, ev.keyCode);
385
+ var proposedPercentage = _this.getNextPositionForKey(idx, ev.keyCode);
453
386
  if (proposedPercentage === null) return;
454
- if (this.canMove(idx, proposedPercentage)) {
455
- this.slideTo(idx, proposedPercentage, function () {
456
- return _this4.fireChangeEvent();
387
+ if (_this.canMove(idx, proposedPercentage)) {
388
+ _this.slideTo(idx, proposedPercentage, function () {
389
+ return _this.fireChangeEvent();
457
390
  });
458
- if (this.props.onKeyPress) this.props.onKeyPress();
391
+ if (_this.props.onKeyPress) _this.props.onKeyPress();
459
392
  }
460
393
  killEvent(ev);
461
- }
462
-
463
- // Make sure the proposed position respects the bounds and
464
- // does not collide with other handles too much.
465
- }, {
466
- key: "validatePosition",
467
- value: function validatePosition(idx, proposedPosition) {
468
- var _this$state4 = this.state,
394
+ });
395
+ _defineProperty(_assertThisInitialized(_this), "validatePosition", function (idx, proposedPosition) {
396
+ var _this$state4 = _this.state,
469
397
  handlePos = _this$state4.handlePos,
470
398
  handleDimensions = _this$state4.handleDimensions;
471
399
  return Math.max(Math.min(proposedPosition, handlePos[idx + 1] !== undefined ? handlePos[idx + 1] - handleDimensions : PERCENT_FULL // 100% is the highest value
472
400
  ), handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : PERCENT_EMPTY // 0% is the lowest value
473
401
  );
474
- }
475
- }, {
476
- key: "validateValues",
477
- value: function validateValues(proposedValues, props) {
478
- var _ref4 = props || this.props,
402
+ });
403
+ _defineProperty(_assertThisInitialized(_this), "validateValues", function (proposedValues, props) {
404
+ var _ref4 = props || _this.props,
479
405
  max = _ref4.max,
480
406
  min = _ref4.min;
481
407
  return proposedValues.map(function (value, idx, values) {
@@ -485,11 +411,9 @@ var Rheostat = /*#__PURE__*/function (_Component) {
485
411
  }
486
412
  return realValue;
487
413
  });
488
- }
489
- }, {
490
- key: "canMove",
491
- value: function canMove(idx, proposedPosition) {
492
- var _this$state5 = this.state,
414
+ });
415
+ _defineProperty(_assertThisInitialized(_this), "canMove", function (idx, proposedPosition) {
416
+ var _this$state5 = _this.state,
493
417
  handlePos = _this$state5.handlePos,
494
418
  handleDimensions = _this$state5.handleDimensions;
495
419
  if (proposedPosition < PERCENT_EMPTY) return false;
@@ -499,29 +423,21 @@ var Rheostat = /*#__PURE__*/function (_Component) {
499
423
  var prevHandlePosition = handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : -Infinity;
500
424
  if (proposedPosition < prevHandlePosition) return false;
501
425
  return true;
502
- }
503
- }, {
504
- key: "fireChangeEvent",
505
- value: function fireChangeEvent() {
506
- var onChange = this.props.onChange;
507
- if (onChange) onChange(this.getPublicState());
508
- }
509
- }, {
510
- key: "slideTo",
511
- value: function slideTo(idx, proposedPosition, onAfterSet) {
512
- var _this5 = this;
513
- var nextState = this.getNextState(idx, proposedPosition);
514
- this.setState(nextState, function () {
515
- var onValuesUpdated = _this5.props.onValuesUpdated;
516
- if (onValuesUpdated) onValuesUpdated(_this5.getPublicState());
426
+ });
427
+ _defineProperty(_assertThisInitialized(_this), "fireChangeEvent", function () {
428
+ var onChange = _this.props.onChange;
429
+ if (onChange) onChange(_this.getPublicState());
430
+ });
431
+ _defineProperty(_assertThisInitialized(_this), "slideTo", function (idx, proposedPosition, onAfterSet) {
432
+ var nextState = _this.getNextState(idx, proposedPosition);
433
+ _this.setState(nextState, function () {
434
+ var onValuesUpdated = _this.props.onValuesUpdated;
435
+ if (onValuesUpdated) onValuesUpdated(_this.getPublicState());
517
436
  if (onAfterSet) onAfterSet();
518
437
  });
519
- }
520
- }, {
521
- key: "updateNewValues",
522
- value: function updateNewValues(nextProps) {
523
- var _this6 = this;
524
- var slidingIndex = this.state.slidingIndex;
438
+ });
439
+ _defineProperty(_assertThisInitialized(_this), "updateNewValues", function (nextProps) {
440
+ var slidingIndex = _this.state.slidingIndex;
525
441
 
526
442
  // Don't update while the slider is sliding
527
443
  if (slidingIndex !== null) {
@@ -530,21 +446,18 @@ var Rheostat = /*#__PURE__*/function (_Component) {
530
446
  var max = nextProps.max,
531
447
  min = nextProps.min,
532
448
  values = nextProps.values;
533
- var nextValues = this.validateValues(values, nextProps);
534
- this.setState({
449
+ var nextValues = _this.validateValues(values, nextProps);
450
+ _this.setState({
535
451
  handlePos: nextValues.map(function (value) {
536
452
  return getPosition(value, min, max);
537
453
  }),
538
454
  values: nextValues
539
455
  }, function () {
540
- return _this6.fireChangeEvent();
456
+ return _this.fireChangeEvent();
541
457
  });
542
- }
543
- }, {
544
- key: "render",
545
- value: function render() {
546
- var _this7 = this;
547
- var _ref5 = this.props,
458
+ });
459
+ _defineProperty(_assertThisInitialized(_this), "render", function () {
460
+ var _ref5 = _this.props,
548
461
  children = _ref5.children,
549
462
  disabled = _ref5.disabled,
550
463
  Handle = _ref5.handle,
@@ -554,14 +467,14 @@ var Rheostat = /*#__PURE__*/function (_Component) {
554
467
  PitComponent = _ref5.pitComponent,
555
468
  pitPoints = _ref5.pitPoints,
556
469
  ProgressBar = _ref5.progressBar; // all required thanks to defaultProps
557
- var _this$state6 = this.state,
470
+ var _this$state6 = _this.state,
558
471
  className = _this$state6.className,
559
472
  handlePos = _this$state6.handlePos,
560
473
  values = _this$state6.values;
561
474
  return h("div", {
562
475
  className: className,
563
- ref: this.rheostat,
564
- onClick: disabled ? undefined : this.handleClick,
476
+ ref: _this.rheostat,
477
+ onClick: disabled ? undefined : _this.handleClick,
565
478
  style: {
566
479
  position: 'relative'
567
480
  }
@@ -574,17 +487,17 @@ var Rheostat = /*#__PURE__*/function (_Component) {
574
487
  position: 'absolute'
575
488
  };
576
489
  return h(Handle, {
577
- "aria-valuemax": _this7.getMaxValue(idx),
578
- "aria-valuemin": _this7.getMinValue(idx),
490
+ "aria-valuemax": _this.getMaxValue(idx),
491
+ "aria-valuemin": _this.getMinValue(idx),
579
492
  "aria-valuenow": values[idx],
580
493
  "aria-disabled": disabled,
581
494
  "data-handle-key": idx,
582
495
  className: "rheostat-handle",
583
496
  key: "handle-".concat(idx),
584
497
  onClick: killEvent,
585
- onKeyDown: disabled ? undefined : _this7.handleKeydown,
586
- onMouseDown: disabled ? undefined : _this7.startMouseSlide,
587
- onTouchStart: disabled ? undefined : _this7.startTouchSlide,
498
+ onKeyDown: disabled ? undefined : _this.handleKeydown,
499
+ onMouseDown: disabled ? undefined : _this.startMouseSlide,
500
+ onTouchStart: disabled ? undefined : _this.startTouchSlide,
588
501
  role: "slider",
589
502
  style: handleStyle,
590
503
  tabIndex: 0
@@ -596,7 +509,7 @@ var Rheostat = /*#__PURE__*/function (_Component) {
596
509
  return h(ProgressBar, {
597
510
  className: "rheostat-progress",
598
511
  key: "progress-bar-".concat(idx),
599
- style: _this7.getProgressStyle(idx)
512
+ style: _this.getProgressStyle(idx)
600
513
  });
601
514
  }), PitComponent && pitPoints.map(function (n) {
602
515
  var pos = getPosition(n, min, max);
@@ -612,9 +525,10 @@ var Rheostat = /*#__PURE__*/function (_Component) {
612
525
  style: pitStyle
613
526
  }, n);
614
527
  }), children);
615
- }
616
- }]);
617
- return Rheostat;
528
+ });
529
+ return _this;
530
+ }
531
+ return _createClass(Rheostat);
618
532
  }(Component);
619
533
  _defineProperty(Rheostat, "defaultProps", {
620
534
  className: '',
@@ -5,7 +5,7 @@ import type { ComponentCSSClasses } from '../../types';
5
5
  import type { RangeSliderCssClasses, RangeSliderWidgetParams } from '../../widgets/range-slider/range-slider';
6
6
  export type RangeSliderComponentCSSClasses = ComponentCSSClasses<RangeSliderCssClasses>;
7
7
  export type SliderProps = {
8
- refine(values: RangeBoundaries): void;
8
+ refine: (values: RangeBoundaries) => void;
9
9
  min?: number;
10
10
  max?: number;
11
11
  values: RangeBoundaries;