aio-range 2.0.3 → 2.1.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/index.d.ts +3 -0
- package/index.js +48 -23
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -245,12 +245,16 @@ const useRange = (PROPS, type) => {
|
|
|
245
245
|
dom: mainDom.current,
|
|
246
246
|
childIndexAttr: 'data-range-index',
|
|
247
247
|
start: ({ index }) => {
|
|
248
|
+
var _a;
|
|
248
249
|
const { disabled } = propsRef.current;
|
|
249
250
|
if (disabled === true) {
|
|
250
251
|
return false;
|
|
251
252
|
}
|
|
252
253
|
temp.index = index;
|
|
253
254
|
temp.start = [...values];
|
|
255
|
+
if ((_a = PROPS.rangeOption) === null || _a === void 0 ? void 0 : _a.onStartDrag) {
|
|
256
|
+
PROPS.rangeOption.onStartDrag(index || 0);
|
|
257
|
+
}
|
|
254
258
|
return [0, 0];
|
|
255
259
|
},
|
|
256
260
|
move: (p) => {
|
|
@@ -259,36 +263,50 @@ const useRange = (PROPS, type) => {
|
|
|
259
263
|
changeHandle({ dx: change.dx, dy: change.dy, deltaCenterAngle: change.deltaCenterAngle, centerAngle: mousePosition.centerAngle });
|
|
260
264
|
}
|
|
261
265
|
},
|
|
266
|
+
end: () => {
|
|
267
|
+
var _a;
|
|
268
|
+
if ((_a = PROPS.rangeOption) === null || _a === void 0 ? void 0 : _a.onEndDrag) {
|
|
269
|
+
PROPS.rangeOption.onEndDrag();
|
|
270
|
+
}
|
|
271
|
+
},
|
|
262
272
|
onClick: function (p) {
|
|
263
273
|
const { disabled } = propsRef.current;
|
|
264
274
|
if (disabled) {
|
|
265
275
|
return;
|
|
266
276
|
}
|
|
267
|
-
click(p.mousePosition);
|
|
277
|
+
click(p.mousePosition, p.domLimit);
|
|
268
278
|
}
|
|
269
279
|
});
|
|
270
280
|
}, 100);
|
|
271
281
|
}, [changeHandle]);
|
|
272
|
-
function click(mousePosition) {
|
|
282
|
+
function click(mousePosition, domLimit) {
|
|
283
|
+
var _a;
|
|
284
|
+
const exactClick = type === 'slider' && ((_a = props.rangeOption) === null || _a === void 0 ? void 0 : _a.clickMode) === 'exact' && !props.multiple && !props.vertical;
|
|
273
285
|
if (props.disabled === true) {
|
|
274
286
|
return;
|
|
275
287
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
288
|
+
if (!exactClick) {
|
|
289
|
+
let clickedValue;
|
|
290
|
+
//vertical condition
|
|
291
|
+
if (type === "spinner") {
|
|
292
|
+
clickedValue = getValueByAngle(mousePosition.centerAngle);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
clickedValue = getValueByXP(mousePosition[props.vertical ? 'yp' : 'xp']);
|
|
296
|
+
}
|
|
297
|
+
if (clickedValue < values[values.length - 1] && clickedValue > values[0]) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (clickedValue < values[0]) {
|
|
301
|
+
change1Unit(-1);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
change1Unit(1);
|
|
305
|
+
}
|
|
289
306
|
}
|
|
290
307
|
else {
|
|
291
|
-
|
|
308
|
+
const xp = 100 * mousePosition.x / domLimit.width;
|
|
309
|
+
changeByPercent(props.reverse ? 100 - xp : xp);
|
|
292
310
|
}
|
|
293
311
|
}
|
|
294
312
|
function changeHandle(obj) {
|
|
@@ -345,6 +363,20 @@ const useRange = (PROPS, type) => {
|
|
|
345
363
|
newValue = moveAll(newValue, dir * props.step);
|
|
346
364
|
changeValue(newValue);
|
|
347
365
|
}
|
|
366
|
+
function changeByPercent(percent) {
|
|
367
|
+
const { start, end } = props;
|
|
368
|
+
const range = end - start;
|
|
369
|
+
const value = percent * range / 100 + start;
|
|
370
|
+
let newValue = [value];
|
|
371
|
+
changeValue(newValue);
|
|
372
|
+
}
|
|
373
|
+
function moveAll(newValue, offset, ifFailedReturnOriginalValue) {
|
|
374
|
+
let res = newValue.map((o) => o + offset);
|
|
375
|
+
if (res[0] < props.start || res[res.length - 1] > props.end) {
|
|
376
|
+
return ifFailedReturnOriginalValue ? values : newValue;
|
|
377
|
+
}
|
|
378
|
+
return res;
|
|
379
|
+
}
|
|
348
380
|
function changeValue(newValue) {
|
|
349
381
|
if (!props.onChange || props.disabled === true) {
|
|
350
382
|
return;
|
|
@@ -368,13 +400,6 @@ const useRange = (PROPS, type) => {
|
|
|
368
400
|
}
|
|
369
401
|
return { before, after };
|
|
370
402
|
}
|
|
371
|
-
function moveAll(newValue, offset, ifFailedReturnOriginalValue) {
|
|
372
|
-
let res = newValue.map((o) => o + offset);
|
|
373
|
-
if (res[0] < props.start || res[res.length - 1] > props.end) {
|
|
374
|
-
return ifFailedReturnOriginalValue ? values : newValue;
|
|
375
|
-
}
|
|
376
|
-
return res;
|
|
377
|
-
}
|
|
378
403
|
const getFloatLength = (step) => {
|
|
379
404
|
const str = step.toString();
|
|
380
405
|
if (str.indexOf('.') === -1) {
|