@react-stately/utils 3.5.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 CHANGED
@@ -1,27 +1,13 @@
1
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 $8d8fdfab47455712$exports = {};
23
6
 
24
- $parcel$export($8d8fdfab47455712$exports, "useControlledState", () => $8d8fdfab47455712$export$40bfa8c7b0832715);
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
12
  function $8d8fdfab47455712$export$40bfa8c7b0832715(value1, defaultValue, onChange) {
27
13
  let [stateValue, setStateValue] = $kC0mY$react.useState(value1 || defaultValue);
@@ -71,11 +57,6 @@ function $8d8fdfab47455712$export$40bfa8c7b0832715(value1, defaultValue, onChang
71
57
  }
72
58
 
73
59
 
74
- var $ac8e4d4816275668$exports = {};
75
-
76
- $parcel$export($ac8e4d4816275668$exports, "clamp", () => $ac8e4d4816275668$export$7d15b64cf5a3a4c4);
77
- $parcel$export($ac8e4d4816275668$exports, "snapValueToStep", () => $ac8e4d4816275668$export$cb6e0bb50bc19463);
78
- $parcel$export($ac8e4d4816275668$exports, "toFixedNumber", () => $ac8e4d4816275668$export$b6268554fba451f);
79
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;
@@ -103,8 +84,6 @@ function $ac8e4d4816275668$export$b6268554fba451f(value, digits, base = 10) {
103
84
  }
104
85
 
105
86
 
106
- $parcel$exportWildcard(module.exports, $8d8fdfab47455712$exports);
107
- $parcel$exportWildcard(module.exports, $ac8e4d4816275668$exports);
108
87
 
109
88
 
110
89
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
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,YAAY,EAChC,OAAO,CAAC,IAAI,EAAE,+BAA+B,EAAE,aAAa,GAAG,CAAY,cAAG,CAAc,cAAC,IAAI,EAAE,YAAY,GAAG,CAAY,cAAG,CAAc,cAAC,CAAC;IAGnJ,GAAG,CAAC,OAAO,GAAG,YAAY;IAE1B,GAAG,CAAC,QAAQ,GAAG,wBAAW,EAAE,MAAK,KAAK,IAAI,GAAK,CAAC;QAC9C,GAAG,CAAC,cAAc,IAAI,KAAK,KAAK,YAAY,GAAK,CAAC;YAChD,EAAE,EAAE,QAAQ,EACV,CAAC;gBAAD,EAAE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AAI,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 */\n\nexport * from './useControlledState';\nexport * 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"}
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,C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,GAAG,EAC1C,YAAY,GAAG,IAAI,CAAC,KAAK,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,11 +1,5 @@
1
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 $458b0a5536c1a7cf$exports = {};
7
-
8
- $parcel$export($458b0a5536c1a7cf$exports, "useControlledState", () => $458b0a5536c1a7cf$export$40bfa8c7b0832715);
9
3
 
10
4
  function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value1, defaultValue, onChange) {
11
5
  let [stateValue, setStateValue] = $6imuh$useState(value1 || defaultValue);
@@ -55,11 +49,6 @@ function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value1, defaultValue, onChang
55
49
  }
56
50
 
57
51
 
58
- var $9446cca9a3875146$exports = {};
59
-
60
- $parcel$export($9446cca9a3875146$exports, "clamp", () => $9446cca9a3875146$export$7d15b64cf5a3a4c4);
61
- $parcel$export($9446cca9a3875146$exports, "snapValueToStep", () => $9446cca9a3875146$export$cb6e0bb50bc19463);
62
- $parcel$export($9446cca9a3875146$exports, "toFixedNumber", () => $9446cca9a3875146$export$b6268554fba451f);
63
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;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;SCcgB,yCAAkB,CAChC,MAAQ,EACR,YAAe,EACf,QAA4C,EACF,CAAC;IAC3C,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,eAAQ,CAAC,MAAK,IAAI,YAAY;IAChE,GAAG,CAAC,GAAG,GAAG,aAAM,CAAC,MAAK,KAAK,SAAS;IACpC,GAAG,CAAC,aAAa,GAAG,GAAG,CAAC,OAAO;IAC/B,GAAG,CAAC,YAAY,GAAG,MAAK,KAAK,SAAS;IACtC,EAA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AE9D,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,KAAK,YAAY,GAAG,GAAG,EAC1C,YAAY,GAAG,IAAI,CAAC,KAAK,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 */\n\nexport * from './useControlledState';\nexport * 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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tC,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"}
@@ -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 */\n\nexport * from './useControlledState';\nexport * from './number';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
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.5.0",
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",
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "8f921ec5094e7c2b3c301bcb6133372e35a2052b"
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 * from './useControlledState';
14
- export * from './number';
12
+ export {useControlledState} from './useControlledState';
13
+ export {clamp, snapValueToStep, toFixedNumber} from './number';