instantsearch.js 4.54.1 → 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.
- package/cjs/components/Breadcrumb/Breadcrumb.js +2 -2
- package/cjs/components/Hits/Hits.js +16 -7
- package/cjs/components/InfiniteHits/InfiniteHits.js +13 -2
- package/cjs/components/RangeInput/RangeInput.js +22 -11
- package/cjs/components/RefinementList/RefinementList.js +34 -52
- package/cjs/components/Slider/Rheostat.js +163 -249
- package/cjs/connectors/autocomplete/connectAutocomplete.js +1 -1
- package/cjs/connectors/geo-search/connectGeoSearch.js +1 -1
- package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
- package/cjs/connectors/hits/connectHits.js +1 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +55 -32
- package/cjs/connectors/menu/connectMenu.js +1 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +1 -1
- package/cjs/connectors/rating-menu/connectRatingMenu.js +7 -3
- package/cjs/connectors/refinement-list/connectRefinementList.js +1 -1
- package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +14 -4
- package/cjs/helpers/insights.js +3 -4
- package/cjs/lib/InstantSearch.js +20 -6
- package/cjs/lib/insights/listener.js +43 -36
- package/cjs/lib/routers/history.js +55 -1
- package/cjs/lib/stateMappings/simple.js +1 -0
- package/cjs/lib/stateMappings/singleIndex.js +1 -0
- package/cjs/lib/utils/createSendEventForFacet.js +12 -2
- package/cjs/lib/utils/createSendEventForHits.js +34 -11
- package/cjs/lib/utils/render-args.js +3 -2
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createInsightsMiddleware.js +135 -33
- package/cjs/middlewares/createMetadataMiddleware.js +17 -5
- package/cjs/middlewares/createRouterMiddleware.js +5 -1
- package/cjs/widgets/hits/hits.js +1 -2
- package/cjs/widgets/hits-per-page/hits-per-page.js +3 -1
- package/cjs/widgets/index/index.js +8 -8
- package/cjs/widgets/infinite-hits/infinite-hits.js +1 -2
- package/dist/instantsearch.development.d.ts +143 -84
- package/dist/instantsearch.development.js +770 -584
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +143 -84
- package/dist/instantsearch.production.min.d.ts +143 -84
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Breadcrumb/Breadcrumb.d.ts +2 -2
- package/es/components/Breadcrumb/Breadcrumb.js +2 -2
- package/es/components/GeoSearchControls/GeoSearchButton.d.ts +1 -1
- package/es/components/GeoSearchControls/GeoSearchControls.d.ts +3 -3
- package/es/components/GeoSearchControls/GeoSearchToggle.d.ts +1 -1
- package/es/components/Hits/Hits.d.ts +5 -5
- package/es/components/Hits/Hits.js +15 -5
- package/es/components/InfiniteHits/InfiniteHits.d.ts +3 -2
- package/es/components/InfiniteHits/InfiniteHits.js +13 -2
- package/es/components/Pagination/Pagination.d.ts +2 -2
- package/es/components/RangeInput/RangeInput.d.ts +7 -4
- package/es/components/RangeInput/RangeInput.js +22 -11
- package/es/components/RefinementList/RefinementList.d.ts +0 -1
- package/es/components/RefinementList/RefinementList.js +34 -52
- package/es/components/RelevantSort/RelevantSort.d.ts +1 -1
- package/es/components/Selector/Selector.d.ts +2 -2
- package/es/components/Slider/Rheostat.d.ts +23 -17
- package/es/components/Slider/Rheostat.js +163 -249
- package/es/components/Slider/Slider.d.ts +1 -1
- package/es/connectors/autocomplete/connectAutocomplete.js +1 -1
- package/es/connectors/current-refinements/connectCurrentRefinements.d.ts +2 -2
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +2 -2
- package/es/connectors/geo-search/connectGeoSearch.d.ts +7 -7
- package/es/connectors/geo-search/connectGeoSearch.js +1 -1
- package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
- package/es/connectors/hits/connectHits.js +1 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +56 -33
- package/es/connectors/menu/connectMenu.d.ts +2 -2
- package/es/connectors/menu/connectMenu.js +1 -1
- package/es/connectors/numeric-menu/connectNumericMenu.js +1 -1
- package/es/connectors/pagination/connectPagination.d.ts +1 -1
- package/es/connectors/range/connectRange.d.ts +3 -3
- package/es/connectors/rating-menu/connectRatingMenu.js +7 -3
- package/es/connectors/refinement-list/connectRefinementList.d.ts +3 -3
- package/es/connectors/refinement-list/connectRefinementList.js +1 -1
- package/es/connectors/relevant-sort/connectRelevantSort.d.ts +1 -1
- package/es/connectors/toggle-refinement/connectToggleRefinement.js +13 -3
- package/es/helpers/insights.d.ts +2 -1
- package/es/helpers/insights.js +3 -3
- package/es/lib/InstantSearch.d.ts +24 -14
- package/es/lib/InstantSearch.js +21 -7
- package/es/lib/insights/listener.d.ts +10 -6
- package/es/lib/insights/listener.js +42 -36
- package/es/lib/routers/history.d.ts +3 -2
- package/es/lib/routers/history.js +56 -2
- package/es/lib/stateMappings/simple.js +1 -0
- package/es/lib/stateMappings/singleIndex.js +1 -0
- package/es/lib/utils/createSendEventForFacet.js +12 -2
- package/es/lib/utils/createSendEventForHits.d.ts +8 -0
- package/es/lib/utils/createSendEventForHits.js +33 -11
- package/es/lib/utils/defer.d.ts +2 -2
- package/es/lib/utils/render-args.js +3 -2
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createInsightsMiddleware.d.ts +12 -12
- package/es/middlewares/createInsightsMiddleware.js +136 -34
- package/es/middlewares/createMetadataMiddleware.d.ts +3 -1
- package/es/middlewares/createMetadataMiddleware.js +17 -5
- package/es/middlewares/createRouterMiddleware.js +5 -1
- package/es/types/insights.d.ts +19 -1
- package/es/types/middleware.d.ts +22 -6
- package/es/types/router.d.ts +15 -7
- package/es/types/widget.d.ts +1 -1
- package/es/widgets/dynamic-widgets/dynamic-widgets.d.ts +2 -2
- package/es/widgets/geo-search/createHTMLMarker.d.ts +1 -1
- package/es/widgets/geo-search/geo-search.d.ts +1 -1
- package/es/widgets/hits/hits.js +2 -3
- package/es/widgets/hits-per-page/hits-per-page.js +3 -1
- package/es/widgets/index/index.d.ts +20 -20
- package/es/widgets/index/index.js +8 -8
- package/es/widgets/infinite-hits/infinite-hits.js +2 -3
- package/es/widgets/panel/panel.d.ts +2 -2
- package/es/widgets/range-slider/range-slider.d.ts +1 -1
- package/package.json +7 -7
|
@@ -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(
|
|
71
|
+
function Rheostat() {
|
|
72
72
|
var _this;
|
|
73
73
|
_classCallCheck(this, Rheostat);
|
|
74
|
-
|
|
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
|
-
|
|
90
|
-
|
|
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 =
|
|
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
|
-
|
|
112
|
+
_this.setState({
|
|
137
113
|
className: getClassName(nextProps)
|
|
138
114
|
});
|
|
139
115
|
}
|
|
140
|
-
if (minMaxChanged || valuesChanged)
|
|
116
|
+
if (minMaxChanged || valuesChanged) _this.updateNewValues(nextProps);
|
|
141
117
|
if (willBeDisabled && slidingIndex !== null) {
|
|
142
|
-
|
|
118
|
+
_this.endSlide();
|
|
143
119
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
|
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 (!
|
|
217
|
-
return
|
|
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
|
-
|
|
223
|
-
|
|
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 =
|
|
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 =
|
|
194
|
+
var _this$state2 = _this.state,
|
|
237
195
|
handlePos = _this$state2.handlePos,
|
|
238
196
|
values = _this$state2.values;
|
|
239
|
-
var _ref2 =
|
|
197
|
+
var _ref2 = _this.props,
|
|
240
198
|
max = _ref2.max,
|
|
241
199
|
min = _ref2.min,
|
|
242
200
|
snapPoints = _ref2.snapPoints;
|
|
243
|
-
var shouldSnap =
|
|
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(
|
|
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
|
-
|
|
302
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
|
|
356
|
-
document.addEventListener('touchmove',
|
|
357
|
-
document.addEventListener('touchend',
|
|
358
|
-
if (
|
|
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
|
-
|
|
363
|
-
|
|
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
|
-
|
|
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
|
-
|
|
317
|
+
_this.endSlide();
|
|
374
318
|
return;
|
|
375
319
|
}
|
|
376
320
|
var touch = ev.changedTouches[0];
|
|
377
|
-
|
|
321
|
+
_this.handleSlide(touch.clientX, touch.clientY);
|
|
378
322
|
killEvent(ev);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
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 =
|
|
387
|
-
|
|
388
|
-
if (
|
|
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
|
-
|
|
332
|
+
_this.setState({
|
|
391
333
|
mousePos: {
|
|
392
334
|
x: x,
|
|
393
335
|
y: y
|
|
394
336
|
}
|
|
395
337
|
});
|
|
396
|
-
if (
|
|
338
|
+
if (_this.props.onSliderDragMove) _this.props.onSliderDragMove();
|
|
397
339
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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',
|
|
408
|
-
document.removeEventListener('touchend',
|
|
409
|
-
document.removeEventListener('touchmove',
|
|
410
|
-
document.removeEventListener('mousemove',
|
|
411
|
-
if (
|
|
412
|
-
if (
|
|
413
|
-
var positionPercent =
|
|
414
|
-
|
|
415
|
-
return
|
|
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
|
-
|
|
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 =
|
|
432
|
-
var positionDecimal =
|
|
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 =
|
|
435
|
-
var validPositionPercent =
|
|
370
|
+
var handleId = _this.getClosestHandle(positionPercent);
|
|
371
|
+
var validPositionPercent = _this.getSnapPosition(positionPercent);
|
|
436
372
|
|
|
437
373
|
// Move the handle there
|
|
438
|
-
|
|
439
|
-
return
|
|
374
|
+
_this.slideTo(handleId, validPositionPercent, function () {
|
|
375
|
+
return _this.fireChangeEvent();
|
|
440
376
|
});
|
|
441
|
-
if (
|
|
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 =
|
|
385
|
+
var proposedPercentage = _this.getNextPositionForKey(idx, ev.keyCode);
|
|
453
386
|
if (proposedPercentage === null) return;
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
return
|
|
387
|
+
if (_this.canMove(idx, proposedPercentage)) {
|
|
388
|
+
_this.slideTo(idx, proposedPercentage, function () {
|
|
389
|
+
return _this.fireChangeEvent();
|
|
457
390
|
});
|
|
458
|
-
if (
|
|
391
|
+
if (_this.props.onKeyPress) _this.props.onKeyPress();
|
|
459
392
|
}
|
|
460
393
|
killEvent(ev);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
-
|
|
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 =
|
|
534
|
-
|
|
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
|
|
456
|
+
return _this.fireChangeEvent();
|
|
541
457
|
});
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
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 =
|
|
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:
|
|
564
|
-
onClick: disabled ? undefined :
|
|
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":
|
|
578
|
-
"aria-valuemin":
|
|
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 :
|
|
586
|
-
onMouseDown: disabled ? undefined :
|
|
587
|
-
onTouchStart: disabled ? undefined :
|
|
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:
|
|
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
|
-
|
|
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)
|
|
8
|
+
refine: (values: RangeBoundaries) => void;
|
|
9
9
|
min?: number;
|
|
10
10
|
max?: number;
|
|
11
11
|
values: RangeBoundaries;
|