@react-stately/utils 3.4.0 → 3.5.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.
- package/dist/main.js +13 -34
- package/dist/main.js.map +1 -1
- package/dist/module.js +10 -21
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +2 -3
package/dist/main.js
CHANGED
|
@@ -1,38 +1,24 @@
|
|
|
1
|
-
var $
|
|
1
|
+
var $kC0mY$react = require("react");
|
|
2
2
|
|
|
3
|
-
function $parcel$exportWildcard(dest, source) {
|
|
4
|
-
Object.keys(source).forEach(function(key) {
|
|
5
|
-
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(dest, key, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function get() {
|
|
12
|
-
return source[key];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return dest;
|
|
18
|
-
}
|
|
19
3
|
function $parcel$export(e, n, v, s) {
|
|
20
4
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
21
5
|
}
|
|
22
|
-
var $696cc5cbfdc54f5b$exports = {};
|
|
23
6
|
|
|
24
|
-
$parcel$export(
|
|
7
|
+
$parcel$export(module.exports, "useControlledState", () => $8d8fdfab47455712$export$40bfa8c7b0832715);
|
|
8
|
+
$parcel$export(module.exports, "clamp", () => $ac8e4d4816275668$export$7d15b64cf5a3a4c4);
|
|
9
|
+
$parcel$export(module.exports, "snapValueToStep", () => $ac8e4d4816275668$export$cb6e0bb50bc19463);
|
|
10
|
+
$parcel$export(module.exports, "toFixedNumber", () => $ac8e4d4816275668$export$b6268554fba451f);
|
|
25
11
|
|
|
26
|
-
function $
|
|
27
|
-
let [stateValue, setStateValue] = $
|
|
28
|
-
let ref = $
|
|
12
|
+
function $8d8fdfab47455712$export$40bfa8c7b0832715(value1, defaultValue, onChange) {
|
|
13
|
+
let [stateValue, setStateValue] = $kC0mY$react.useState(value1 || defaultValue);
|
|
14
|
+
let ref = $kC0mY$react.useRef(value1 !== undefined);
|
|
29
15
|
let wasControlled = ref.current;
|
|
30
16
|
let isControlled = value1 !== undefined;
|
|
31
17
|
// Internal state reference for useCallback
|
|
32
|
-
let stateRef = $
|
|
18
|
+
let stateRef = $kC0mY$react.useRef(stateValue);
|
|
33
19
|
if (wasControlled !== isControlled) console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);
|
|
34
20
|
ref.current = isControlled;
|
|
35
|
-
let setValue = $
|
|
21
|
+
let setValue = $kC0mY$react.useCallback((value2, ...args)=>{
|
|
36
22
|
let onChangeCaller = (value, ...onChangeArgs)=>{
|
|
37
23
|
if (onChange) {
|
|
38
24
|
if (!Object.is(stateRef.current, value)) onChange(value, ...onChangeArgs);
|
|
@@ -71,16 +57,11 @@ function $696cc5cbfdc54f5b$export$40bfa8c7b0832715(value1, defaultValue, onChang
|
|
|
71
57
|
}
|
|
72
58
|
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
$parcel$export($8d9cdca37bcf2e83$exports, "clamp", () => $8d9cdca37bcf2e83$export$7d15b64cf5a3a4c4);
|
|
77
|
-
$parcel$export($8d9cdca37bcf2e83$exports, "snapValueToStep", () => $8d9cdca37bcf2e83$export$cb6e0bb50bc19463);
|
|
78
|
-
$parcel$export($8d9cdca37bcf2e83$exports, "toFixedNumber", () => $8d9cdca37bcf2e83$export$b6268554fba451f);
|
|
79
|
-
function $8d9cdca37bcf2e83$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) {
|
|
60
|
+
function $ac8e4d4816275668$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) {
|
|
80
61
|
let newValue = Math.min(Math.max(value, min), max);
|
|
81
62
|
return newValue;
|
|
82
63
|
}
|
|
83
|
-
function $
|
|
64
|
+
function $ac8e4d4816275668$export$cb6e0bb50bc19463(value, min, max, step) {
|
|
84
65
|
let remainder = (value - (isNaN(min) ? 0 : min)) % step;
|
|
85
66
|
let snappedValue = Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder;
|
|
86
67
|
if (!isNaN(min)) {
|
|
@@ -97,14 +78,12 @@ function $8d9cdca37bcf2e83$export$cb6e0bb50bc19463(value, min, max, step) {
|
|
|
97
78
|
}
|
|
98
79
|
return snappedValue;
|
|
99
80
|
}
|
|
100
|
-
function $
|
|
81
|
+
function $ac8e4d4816275668$export$b6268554fba451f(value, digits, base = 10) {
|
|
101
82
|
const pow = Math.pow(base, digits);
|
|
102
83
|
return Math.round(value * pow) / pow;
|
|
103
84
|
}
|
|
104
85
|
|
|
105
86
|
|
|
106
|
-
$parcel$exportWildcard(module.exports, $696cc5cbfdc54f5b$exports);
|
|
107
|
-
$parcel$exportWildcard(module.exports, $8d9cdca37bcf2e83$exports);
|
|
108
87
|
|
|
109
88
|
|
|
110
89
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;SCcgB,yCAAkB,CAChC,MAAQ,EACR,YAAe,EACf,QAA4C,EACF,CAAC;IAC3C,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,qBAAQ,CAAC,MAAK,IAAI,YAAY;IAChE,GAAG,CAAC,GAAG,GAAG,mBAAM,CAAC,MAAK,KAAK,SAAS;IACpC,GAAG,CAAC,aAAa,GAAG,GAAG,CAAC,OAAO;IAC/B,GAAG,CAAC,YAAY,GAAG,MAAK,KAAK,SAAS;IACtC,EAA2C,AAA3C,yCAA2C;IAC3C,GAAG,CAAC,QAAQ,GAAG,mBAAM,CAAC,UAAU;IAChC,EAAE,EAAE,aAAa,KAAK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AAK,CAAC,GAAG,GAAG,IAAI,IAAI,IAAI;IAG9C,EAAgE,AAAhE,8DAAgE;IAChE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ;IAC1B,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAG;IAC9B,GAAG,CAAC,SAAS,GAAG,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC;IAEtD,EAAE,EAAE,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS;QAChC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,GAAG,IAAI,GAAG;IACrD,CAAC;IAED,MAAM,CAAC,YAAY;AACrB,CAAC;SAGe,wCAAa,CAAC,KAAa,EAAE,MAAc,EAAE,IAAY,GAAG,EAAE,EAAU,CAAC;IACvF,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM;IAEjC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,IAAI,GAAG;AACtC,CAAC;;","sources":["packages/@react-stately/utils/src/index.ts","packages/@react-stately/utils/src/useControlledState.ts","packages/@react-stately/utils/src/number.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from './useControlledState';\nexport {clamp, snapValueToStep, toFixedNumber} from './number';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback, useRef, useState} from 'react';\n\nexport function useControlledState<T>(\n value: T,\n defaultValue: T,\n onChange: (value: T, ...args: any[]) => void\n): [T, (value: T, ...args: any[]) => void] {\n let [stateValue, setStateValue] = useState(value || defaultValue);\n let ref = useRef(value !== undefined);\n let wasControlled = ref.current;\n let isControlled = value !== undefined;\n // Internal state reference for useCallback\n let stateRef = useRef(stateValue);\n if (wasControlled !== isControlled) {\n console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);\n }\n\n ref.current = isControlled;\n\n let setValue = useCallback((value, ...args) => {\n let onChangeCaller = (value, ...onChangeArgs) => {\n if (onChange) {\n if (!Object.is(stateRef.current, value)) {\n onChange(value, ...onChangeArgs);\n }\n }\n if (!isControlled) {\n stateRef.current = value;\n }\n };\n\n if (typeof value === 'function') {\n console.warn('We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320');\n // this supports functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates\n // when someone using useControlledState calls setControlledState(myFunc)\n // this will call our useState setState with a function as well which invokes myFunc and calls onChange with the value from myFunc\n // if we're in an uncontrolled state, then we also return the value of myFunc which to setState looks as though it was just called with myFunc from the beginning\n // otherwise we just return the controlled value, which won't cause a rerender because React knows to bail out when the value is the same\n let updateFunction = (oldValue, ...functionArgs) => {\n let interceptedValue = value(isControlled ? stateRef.current : oldValue, ...functionArgs);\n onChangeCaller(interceptedValue, ...args);\n if (!isControlled) {\n return interceptedValue;\n }\n return oldValue;\n };\n setStateValue(updateFunction);\n } else {\n if (!isControlled) {\n setStateValue(value);\n }\n onChangeCaller(value, ...args);\n }\n }, [isControlled, onChange]);\n\n // If a controlled component's value prop changes, we need to update stateRef\n if (isControlled) {\n stateRef.current = value;\n } else {\n value = stateValue;\n }\n\n return [value, setValue];\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/**\n * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.\n */\nexport function clamp(value: number, min: number = -Infinity, max: number = Infinity): number {\n let newValue = Math.min(Math.max(value, min), max);\n return newValue;\n}\n\nexport function snapValueToStep(value: number, min: number, max: number, step: number): number {\n let remainder = ((value - (isNaN(min) ? 0 : min)) % step);\n let snappedValue = Math.abs(remainder) * 2 >= step\n ? value + Math.sign(remainder) * (step - Math.abs(remainder))\n : value - remainder;\n\n if (!isNaN(min)) {\n if (snappedValue < min) {\n snappedValue = min;\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = min + Math.floor((max - min) / step) * step;\n }\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = Math.floor(max / step) * step;\n }\n\n // correct floating point behavior by rounding to step precision\n let string = step.toString();\n let index = string.indexOf('.');\n let precision = index >= 0 ? string.length - index : 0;\n\n if (precision > 0) {\n let pow = Math.pow(10, precision);\n snappedValue = Math.round(snappedValue * pow) / pow;\n }\n\n return snappedValue;\n}\n\n/* Takes a value and rounds off to the number of digits. */\nexport function toFixedNumber(value: number, digits: number, base: number = 10): number {\n const pow = Math.pow(base, digits);\n\n return Math.round(value * pow) / pow;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import {useState as $
|
|
1
|
+
import {useState as $6imuh$useState, useRef as $6imuh$useRef, useCallback as $6imuh$useCallback} from "react";
|
|
2
2
|
|
|
3
|
-
function $parcel$export(e, n, v, s) {
|
|
4
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
5
|
-
}
|
|
6
|
-
var $7eb364dbb661fcb7$exports = {};
|
|
7
|
-
|
|
8
|
-
$parcel$export($7eb364dbb661fcb7$exports, "useControlledState", () => $7eb364dbb661fcb7$export$40bfa8c7b0832715);
|
|
9
3
|
|
|
10
|
-
function $
|
|
11
|
-
let [stateValue, setStateValue] = $
|
|
12
|
-
let ref = $
|
|
4
|
+
function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value1, defaultValue, onChange) {
|
|
5
|
+
let [stateValue, setStateValue] = $6imuh$useState(value1 || defaultValue);
|
|
6
|
+
let ref = $6imuh$useRef(value1 !== undefined);
|
|
13
7
|
let wasControlled = ref.current;
|
|
14
8
|
let isControlled = value1 !== undefined;
|
|
15
9
|
// Internal state reference for useCallback
|
|
16
|
-
let stateRef = $
|
|
10
|
+
let stateRef = $6imuh$useRef(stateValue);
|
|
17
11
|
if (wasControlled !== isControlled) console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);
|
|
18
12
|
ref.current = isControlled;
|
|
19
|
-
let setValue = $
|
|
13
|
+
let setValue = $6imuh$useCallback((value2, ...args)=>{
|
|
20
14
|
let onChangeCaller = (value, ...onChangeArgs)=>{
|
|
21
15
|
if (onChange) {
|
|
22
16
|
if (!Object.is(stateRef.current, value)) onChange(value, ...onChangeArgs);
|
|
@@ -55,16 +49,11 @@ function $7eb364dbb661fcb7$export$40bfa8c7b0832715(value1, defaultValue, onChang
|
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
$parcel$export($0538fb457bd4249d$exports, "clamp", () => $0538fb457bd4249d$export$7d15b64cf5a3a4c4);
|
|
61
|
-
$parcel$export($0538fb457bd4249d$exports, "snapValueToStep", () => $0538fb457bd4249d$export$cb6e0bb50bc19463);
|
|
62
|
-
$parcel$export($0538fb457bd4249d$exports, "toFixedNumber", () => $0538fb457bd4249d$export$b6268554fba451f);
|
|
63
|
-
function $0538fb457bd4249d$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) {
|
|
52
|
+
function $9446cca9a3875146$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) {
|
|
64
53
|
let newValue = Math.min(Math.max(value, min), max);
|
|
65
54
|
return newValue;
|
|
66
55
|
}
|
|
67
|
-
function $
|
|
56
|
+
function $9446cca9a3875146$export$cb6e0bb50bc19463(value, min, max, step) {
|
|
68
57
|
let remainder = (value - (isNaN(min) ? 0 : min)) % step;
|
|
69
58
|
let snappedValue = Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder;
|
|
70
59
|
if (!isNaN(min)) {
|
|
@@ -81,7 +70,7 @@ function $0538fb457bd4249d$export$cb6e0bb50bc19463(value, min, max, step) {
|
|
|
81
70
|
}
|
|
82
71
|
return snappedValue;
|
|
83
72
|
}
|
|
84
|
-
function $
|
|
73
|
+
function $9446cca9a3875146$export$b6268554fba451f(value, digits, base = 10) {
|
|
85
74
|
const pow = Math.pow(base, digits);
|
|
86
75
|
return Math.round(value * pow) / pow;
|
|
87
76
|
}
|
|
@@ -89,5 +78,5 @@ function $0538fb457bd4249d$export$b6268554fba451f(value, digits, base = 10) {
|
|
|
89
78
|
|
|
90
79
|
|
|
91
80
|
|
|
92
|
-
export {$
|
|
81
|
+
export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState, $9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$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AAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,IAAI,GAAG;AACtC,CAAC;;","sources":["packages/@react-stately/utils/src/index.ts","packages/@react-stately/utils/src/useControlledState.ts","packages/@react-stately/utils/src/number.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from './useControlledState';\nexport {clamp, snapValueToStep, toFixedNumber} from './number';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback, useRef, useState} from 'react';\n\nexport function useControlledState<T>(\n value: T,\n defaultValue: T,\n onChange: (value: T, ...args: any[]) => void\n): [T, (value: T, ...args: any[]) => void] {\n let [stateValue, setStateValue] = useState(value || defaultValue);\n let ref = useRef(value !== undefined);\n let wasControlled = ref.current;\n let isControlled = value !== undefined;\n // Internal state reference for useCallback\n let stateRef = useRef(stateValue);\n if (wasControlled !== isControlled) {\n console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);\n }\n\n ref.current = isControlled;\n\n let setValue = useCallback((value, ...args) => {\n let onChangeCaller = (value, ...onChangeArgs) => {\n if (onChange) {\n if (!Object.is(stateRef.current, value)) {\n onChange(value, ...onChangeArgs);\n }\n }\n if (!isControlled) {\n stateRef.current = value;\n }\n };\n\n if (typeof value === 'function') {\n console.warn('We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320');\n // this supports functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates\n // when someone using useControlledState calls setControlledState(myFunc)\n // this will call our useState setState with a function as well which invokes myFunc and calls onChange with the value from myFunc\n // if we're in an uncontrolled state, then we also return the value of myFunc which to setState looks as though it was just called with myFunc from the beginning\n // otherwise we just return the controlled value, which won't cause a rerender because React knows to bail out when the value is the same\n let updateFunction = (oldValue, ...functionArgs) => {\n let interceptedValue = value(isControlled ? stateRef.current : oldValue, ...functionArgs);\n onChangeCaller(interceptedValue, ...args);\n if (!isControlled) {\n return interceptedValue;\n }\n return oldValue;\n };\n setStateValue(updateFunction);\n } else {\n if (!isControlled) {\n setStateValue(value);\n }\n onChangeCaller(value, ...args);\n }\n }, [isControlled, onChange]);\n\n // If a controlled component's value prop changes, we need to update stateRef\n if (isControlled) {\n stateRef.current = value;\n } else {\n value = stateValue;\n }\n\n return [value, setValue];\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/**\n * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.\n */\nexport function clamp(value: number, min: number = -Infinity, max: number = Infinity): number {\n let newValue = Math.min(Math.max(value, min), max);\n return newValue;\n}\n\nexport function snapValueToStep(value: number, min: number, max: number, step: number): number {\n let remainder = ((value - (isNaN(min) ? 0 : min)) % step);\n let snappedValue = Math.abs(remainder) * 2 >= step\n ? value + Math.sign(remainder) * (step - Math.abs(remainder))\n : value - remainder;\n\n if (!isNaN(min)) {\n if (snappedValue < min) {\n snappedValue = min;\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = min + Math.floor((max - min) / step) * step;\n }\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = Math.floor(max / step) * step;\n }\n\n // correct floating point behavior by rounding to step precision\n let string = step.toString();\n let index = string.indexOf('.');\n let precision = index >= 0 ? string.length - index : 0;\n\n if (precision > 0) {\n let pow = Math.pow(10, precision);\n snappedValue = Math.round(snappedValue * pow) / pow;\n }\n\n return snappedValue;\n}\n\n/* Takes a value and rounds off to the number of digits. */\nexport function toFixedNumber(value: number, digits: number, base: number = 10): number {\n const pow = Math.pow(base, digits);\n\n return Math.round(value * pow) / pow;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAcA,mCAAmC,CAAC,EAClC,KAAK,EAAE,CAAC,EACR,YAAY,EAAE,CAAC,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAC3C,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAyDzC;AC/DD;;GAEG;AACH,sBAAsB,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAkB,EAAE,GAAG,GAAE,MAAiB,GAAG,MAAM,CAG5F;AAED,gCAAgC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2B7F;AAGD,8BAA8B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,MAAW,GAAG,MAAM,CAItF","sources":["packages/@react-stately/utils/src/packages/@react-stately/utils/src/useControlledState.ts","packages/@react-stately/utils/src/packages/@react-stately/utils/src/number.ts","packages/@react-stately/utils/src/packages/@react-stately/utils/src/index.ts","packages/@react-stately/utils/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\
|
|
1
|
+
{"mappings":"AAcA,mCAAmC,CAAC,EAClC,KAAK,EAAE,CAAC,EACR,YAAY,EAAE,CAAC,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAC3C,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAyDzC;AC/DD;;GAEG;AACH,sBAAsB,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAkB,EAAE,GAAG,GAAE,MAAiB,GAAG,MAAM,CAG5F;AAED,gCAAgC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2B7F;AAGD,8BAA8B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,MAAW,GAAG,MAAM,CAItF","sources":["packages/@react-stately/utils/src/packages/@react-stately/utils/src/useControlledState.ts","packages/@react-stately/utils/src/packages/@react-stately/utils/src/number.ts","packages/@react-stately/utils/src/packages/@react-stately/utils/src/index.ts","packages/@react-stately/utils/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from './useControlledState';\nexport {clamp, snapValueToStep, toFixedNumber} from './number';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"url": "https://github.com/adobe/react-spectrum"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
20
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/runtime": "^7.6.2"
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "cd7c0ec917122c7612f653c22f8ed558f8b66ecd"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,5 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
export * from './number';
|
|
12
|
+
export {useControlledState} from './useControlledState';
|
|
13
|
+
export {clamp, snapValueToStep, toFixedNumber} from './number';
|