@react-stately/utils
Advanced tools
| export { useControlledState } from 'react-stately/useControlledState'; | ||
| export { clamp, snapValueToStep, toFixedNumber } from 'react-stately/private/utils/number'; |
+3
-3
@@ -1,3 +0,3 @@ | ||
| import {useControlledState as $458b0a5536c1a7cf$export$40bfa8c7b0832715} from "./useControlledState.mjs"; | ||
| import {clamp as $9446cca9a3875146$export$7d15b64cf5a3a4c4, snapValueToStep as $9446cca9a3875146$export$cb6e0bb50bc19463, toFixedNumber as $9446cca9a3875146$export$b6268554fba451f} from "./number.mjs"; | ||
| import {useControlledState as $fd7ccfc2ebe0ae74$re_export$useControlledState} from "react-stately/useControlledState"; | ||
| import {clamp as $fd7ccfc2ebe0ae74$re_export$clamp, snapValueToStep as $fd7ccfc2ebe0ae74$re_export$snapValueToStep, toFixedNumber as $fd7ccfc2ebe0ae74$re_export$toFixedNumber} from "react-stately/private/utils/number"; | ||
@@ -18,3 +18,3 @@ /* | ||
| export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState, $9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber}; | ||
| export {$fd7ccfc2ebe0ae74$re_export$useControlledState as useControlledState, $fd7ccfc2ebe0ae74$re_export$clamp as clamp, $fd7ccfc2ebe0ae74$re_export$snapValueToStep as snapValueToStep, $fd7ccfc2ebe0ae74$re_export$toFixedNumber as toFixedNumber}; | ||
| //# sourceMappingURL=module.js.map |
+6
-6
@@ -1,3 +0,3 @@ | ||
| var $8d8fdfab47455712$exports = require("./useControlledState.main.js"); | ||
| var $ac8e4d4816275668$exports = require("./number.main.js"); | ||
| var $g1Hlx$reactstatelyuseControlledState = require("react-stately/useControlledState"); | ||
| var $g1Hlx$reactstatelyprivateutilsnumber = require("react-stately/private/utils/number"); | ||
@@ -9,6 +9,6 @@ | ||
| $parcel$export(module.exports, "useControlledState", () => $8d8fdfab47455712$exports.useControlledState); | ||
| $parcel$export(module.exports, "clamp", () => $ac8e4d4816275668$exports.clamp); | ||
| $parcel$export(module.exports, "snapValueToStep", () => $ac8e4d4816275668$exports.snapValueToStep); | ||
| $parcel$export(module.exports, "toFixedNumber", () => $ac8e4d4816275668$exports.toFixedNumber); | ||
| $parcel$export(module.exports, "useControlledState", function () { return $g1Hlx$reactstatelyuseControlledState.useControlledState; }); | ||
| $parcel$export(module.exports, "clamp", function () { return $g1Hlx$reactstatelyprivateutilsnumber.clamp; }); | ||
| $parcel$export(module.exports, "snapValueToStep", function () { return $g1Hlx$reactstatelyprivateutilsnumber.snapValueToStep; }); | ||
| $parcel$export(module.exports, "toFixedNumber", function () { return $g1Hlx$reactstatelyprivateutilsnumber.toFixedNumber; }); | ||
| /* | ||
@@ -15,0 +15,0 @@ * Copyright 2020 Adobe. All rights reserved. |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.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"],"names":[],"version":3,"file":"main.js.map"} | ||
| {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.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 'react-stately/useControlledState';\n\nexport {clamp, snapValueToStep, toFixedNumber} from 'react-stately/private/utils/number';\n"],"names":[],"version":3,"file":"main.js.map"} |
+3
-3
@@ -1,3 +0,3 @@ | ||
| import {useControlledState as $458b0a5536c1a7cf$export$40bfa8c7b0832715} from "./useControlledState.module.js"; | ||
| import {clamp as $9446cca9a3875146$export$7d15b64cf5a3a4c4, snapValueToStep as $9446cca9a3875146$export$cb6e0bb50bc19463, toFixedNumber as $9446cca9a3875146$export$b6268554fba451f} from "./number.module.js"; | ||
| import {useControlledState as $fd7ccfc2ebe0ae74$re_export$useControlledState} from "react-stately/useControlledState"; | ||
| import {clamp as $fd7ccfc2ebe0ae74$re_export$clamp, snapValueToStep as $fd7ccfc2ebe0ae74$re_export$snapValueToStep, toFixedNumber as $fd7ccfc2ebe0ae74$re_export$toFixedNumber} from "react-stately/private/utils/number"; | ||
@@ -18,3 +18,3 @@ /* | ||
| export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState, $9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber}; | ||
| export {$fd7ccfc2ebe0ae74$re_export$useControlledState as useControlledState, $fd7ccfc2ebe0ae74$re_export$clamp as clamp, $fd7ccfc2ebe0ae74$re_export$snapValueToStep as snapValueToStep, $fd7ccfc2ebe0ae74$re_export$toFixedNumber as toFixedNumber}; | ||
| //# sourceMappingURL=module.js.map |
@@ -1,1 +0,1 @@ | ||
| {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.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"],"names":[],"version":3,"file":"module.js.map"} | ||
| {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.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 'react-stately/useControlledState';\n\nexport {clamp, snapValueToStep, toFixedNumber} from 'react-stately/private/utils/number';\n"],"names":[],"version":3,"file":"module.js.map"} |
+29
-17
| { | ||
| "name": "@react-stately/utils", | ||
| "version": "3.0.0-nightly-086ad3115-240912", | ||
| "version": "3.0.0-nightly-092229c62-260516", | ||
| "description": "Spectrum UI components in React", | ||
| "license": "Apache-2.0", | ||
| "main": "dist/main.js", | ||
| "module": "dist/module.js", | ||
| "exports": { | ||
| "types": "./dist/types.d.ts", | ||
| "import": "./dist/import.mjs", | ||
| "require": "./dist/main.js" | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/adobe/react-spectrum" | ||
| }, | ||
| "types": "dist/types.d.ts", | ||
| "source": "src/index.ts", | ||
@@ -20,16 +16,32 @@ "files": [ | ||
| "sideEffects": false, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/adobe/react-spectrum" | ||
| "main": "dist/main.js", | ||
| "module": "dist/module.js", | ||
| "types": "dist/types/src/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "source": "./src/index.ts", | ||
| "types": "./dist/types/src/index.d.ts", | ||
| "import": "./dist/import.mjs", | ||
| "require": "./dist/main.js" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0" | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@swc/helpers": "^0.5.0" | ||
| "@swc/helpers": "^0.5.0", | ||
| "react-stately": "3.0.0-nightly-092229c62-260516" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| "devDependencies": { | ||
| "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", | ||
| "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" | ||
| }, | ||
| "stableVersion": "3.10.3" | ||
| "peerDependencies": { | ||
| "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", | ||
| "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" | ||
| }, | ||
| "targets": { | ||
| "types": false | ||
| } | ||
| } |
+3
-2
@@ -12,3 +12,4 @@ /* | ||
| */ | ||
| export {useControlledState} from './useControlledState'; | ||
| export {clamp, snapValueToStep, toFixedNumber} from './number'; | ||
| export {useControlledState} from 'react-stately/useControlledState'; | ||
| export {clamp, snapValueToStep, toFixedNumber} from 'react-stately/private/utils/number'; |
| function $parcel$export(e, n, v, s) { | ||
| Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); | ||
| } | ||
| $parcel$export(module.exports, "clamp", () => $ac8e4d4816275668$export$7d15b64cf5a3a4c4); | ||
| $parcel$export(module.exports, "snapValueToStep", () => $ac8e4d4816275668$export$cb6e0bb50bc19463); | ||
| $parcel$export(module.exports, "toFixedNumber", () => $ac8e4d4816275668$export$b6268554fba451f); | ||
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ /** | ||
| * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step. | ||
| */ function $ac8e4d4816275668$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) { | ||
| let newValue = Math.min(Math.max(value, min), max); | ||
| return newValue; | ||
| } | ||
| function $ac8e4d4816275668$export$e1a7b8e69ef6c52f(value, step) { | ||
| let roundedValue = value; | ||
| let stepString = step.toString(); | ||
| let pointIndex = stepString.indexOf('.'); | ||
| let precision = pointIndex >= 0 ? stepString.length - pointIndex : 0; | ||
| if (precision > 0) { | ||
| let pow = Math.pow(10, precision); | ||
| roundedValue = Math.round(roundedValue * pow) / pow; | ||
| } | ||
| return roundedValue; | ||
| } | ||
| function $ac8e4d4816275668$export$cb6e0bb50bc19463(value, min, max, step) { | ||
| min = Number(min); | ||
| max = Number(max); | ||
| let remainder = (value - (isNaN(min) ? 0 : min)) % step; | ||
| let snappedValue = $ac8e4d4816275668$export$e1a7b8e69ef6c52f(Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder, step); | ||
| if (!isNaN(min)) { | ||
| if (snappedValue < min) snappedValue = min; | ||
| else if (!isNaN(max) && snappedValue > max) snappedValue = min + Math.floor($ac8e4d4816275668$export$e1a7b8e69ef6c52f((max - min) / step, step)) * step; | ||
| } else if (!isNaN(max) && snappedValue > max) snappedValue = Math.floor($ac8e4d4816275668$export$e1a7b8e69ef6c52f(max / step, step)) * step; | ||
| // correct floating point behavior by rounding to step precision | ||
| snappedValue = $ac8e4d4816275668$export$e1a7b8e69ef6c52f(snappedValue, step); | ||
| return snappedValue; | ||
| } | ||
| function $ac8e4d4816275668$export$b6268554fba451f(value, digits, base = 10) { | ||
| const pow = Math.pow(base, digits); | ||
| return Math.round(value * pow) / pow; | ||
| } | ||
| //# sourceMappingURL=number.main.js.map |
| {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC,GAED;;CAEC,GACM,SAAS,0CAAM,KAAa,EAAE,MAAc,CAAC,QAAQ,EAAE,MAAc,QAAQ;IAClF,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO,MAAM;IAC9C,OAAO;AACT;AAEO,SAAS,0CAAqB,KAAa,EAAE,IAAY;IAC9D,IAAI,eAAe;IACnB,IAAI,aAAa,KAAK,QAAQ;IAC9B,IAAI,aAAa,WAAW,OAAO,CAAC;IACpC,IAAI,YAAY,cAAc,IAAI,WAAW,MAAM,GAAG,aAAa;IACnE,IAAI,YAAY,GAAG;QACjB,IAAI,MAAM,KAAK,GAAG,CAAC,IAAI;QACvB,eAAe,KAAK,KAAK,CAAC,eAAe,OAAO;IAClD;IACA,OAAO;AACT;AAEO,SAAS,0CAAgB,KAAa,EAAE,GAAuB,EAAE,GAAuB,EAAE,IAAY;IAC3G,MAAM,OAAO;IACb,MAAM,OAAO;IACb,IAAI,YAAa,AAAC,CAAA,QAAS,CAAA,MAAM,OAAO,IAAI,GAAE,CAAC,IAAK;IACpD,IAAI,eAAe,0CAAqB,KAAK,GAAG,CAAC,aAAa,KAAK,OAC/D,QAAQ,KAAK,IAAI,CAAC,aAAc,CAAA,OAAO,KAAK,GAAG,CAAC,UAAS,IACzD,QAAQ,WAAW;IAEvB,IAAI,CAAC,MAAM,MAAM;QACf,IAAI,eAAe,KACjB,eAAe;aACV,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,MAAM,KAAK,KAAK,CAAC,0CAAqB,AAAC,CAAA,MAAM,GAAE,IAAK,MAAM,SAAS;IAEtF,OAAO,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,KAAK,KAAK,CAAC,0CAAqB,MAAM,MAAM,SAAS;IAGtE,gEAAgE;IAChE,eAAe,0CAAqB,cAAc;IAElD,OAAO;AACT;AAGO,SAAS,yCAAc,KAAa,EAAE,MAAc,EAAE,OAAe,EAAE;IAC5E,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM;IAE3B,OAAO,KAAK,KAAK,CAAC,QAAQ,OAAO;AACnC","sources":["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\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 roundToStepPrecision(value: number, step: number) {\n let roundedValue = value;\n let stepString = step.toString();\n let pointIndex = stepString.indexOf('.');\n let precision = pointIndex >= 0 ? stepString.length - pointIndex : 0;\n if (precision > 0) {\n let pow = Math.pow(10, precision);\n roundedValue = Math.round(roundedValue * pow) / pow;\n }\n return roundedValue;\n}\n\nexport function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number {\n min = Number(min);\n max = Number(max);\n let remainder = ((value - (isNaN(min) ? 0 : min)) % step);\n let snappedValue = roundToStepPrecision(Math.abs(remainder) * 2 >= step\n ? value + Math.sign(remainder) * (step - Math.abs(remainder))\n : value - remainder, step);\n\n if (!isNaN(min)) {\n if (snappedValue < min) {\n snappedValue = min;\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = min + Math.floor(roundToStepPrecision((max - min) / step, step)) * step;\n }\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = Math.floor(roundToStepPrecision(max / step, step)) * step;\n }\n\n // correct floating point behavior by rounding to step precision\n snappedValue = roundToStepPrecision(snappedValue, step);\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":"number.main.js.map"} |
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ /** | ||
| * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step. | ||
| */ function $9446cca9a3875146$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) { | ||
| let newValue = Math.min(Math.max(value, min), max); | ||
| return newValue; | ||
| } | ||
| function $9446cca9a3875146$export$e1a7b8e69ef6c52f(value, step) { | ||
| let roundedValue = value; | ||
| let stepString = step.toString(); | ||
| let pointIndex = stepString.indexOf('.'); | ||
| let precision = pointIndex >= 0 ? stepString.length - pointIndex : 0; | ||
| if (precision > 0) { | ||
| let pow = Math.pow(10, precision); | ||
| roundedValue = Math.round(roundedValue * pow) / pow; | ||
| } | ||
| return roundedValue; | ||
| } | ||
| function $9446cca9a3875146$export$cb6e0bb50bc19463(value, min, max, step) { | ||
| min = Number(min); | ||
| max = Number(max); | ||
| let remainder = (value - (isNaN(min) ? 0 : min)) % step; | ||
| let snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder, step); | ||
| if (!isNaN(min)) { | ||
| if (snappedValue < min) snappedValue = min; | ||
| else if (!isNaN(max) && snappedValue > max) snappedValue = min + Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f((max - min) / step, step)) * step; | ||
| } else if (!isNaN(max) && snappedValue > max) snappedValue = Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f(max / step, step)) * step; | ||
| // correct floating point behavior by rounding to step precision | ||
| snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(snappedValue, step); | ||
| return snappedValue; | ||
| } | ||
| function $9446cca9a3875146$export$b6268554fba451f(value, digits, base = 10) { | ||
| const pow = Math.pow(base, digits); | ||
| return Math.round(value * pow) / pow; | ||
| } | ||
| export {$9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$e1a7b8e69ef6c52f as roundToStepPrecision, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber}; | ||
| //# sourceMappingURL=number.module.js.map |
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ /** | ||
| * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step. | ||
| */ function $9446cca9a3875146$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) { | ||
| let newValue = Math.min(Math.max(value, min), max); | ||
| return newValue; | ||
| } | ||
| function $9446cca9a3875146$export$e1a7b8e69ef6c52f(value, step) { | ||
| let roundedValue = value; | ||
| let stepString = step.toString(); | ||
| let pointIndex = stepString.indexOf('.'); | ||
| let precision = pointIndex >= 0 ? stepString.length - pointIndex : 0; | ||
| if (precision > 0) { | ||
| let pow = Math.pow(10, precision); | ||
| roundedValue = Math.round(roundedValue * pow) / pow; | ||
| } | ||
| return roundedValue; | ||
| } | ||
| function $9446cca9a3875146$export$cb6e0bb50bc19463(value, min, max, step) { | ||
| min = Number(min); | ||
| max = Number(max); | ||
| let remainder = (value - (isNaN(min) ? 0 : min)) % step; | ||
| let snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder, step); | ||
| if (!isNaN(min)) { | ||
| if (snappedValue < min) snappedValue = min; | ||
| else if (!isNaN(max) && snappedValue > max) snappedValue = min + Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f((max - min) / step, step)) * step; | ||
| } else if (!isNaN(max) && snappedValue > max) snappedValue = Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f(max / step, step)) * step; | ||
| // correct floating point behavior by rounding to step precision | ||
| snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(snappedValue, step); | ||
| return snappedValue; | ||
| } | ||
| function $9446cca9a3875146$export$b6268554fba451f(value, digits, base = 10) { | ||
| const pow = Math.pow(base, digits); | ||
| return Math.round(value * pow) / pow; | ||
| } | ||
| export {$9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$e1a7b8e69ef6c52f as roundToStepPrecision, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber}; | ||
| //# sourceMappingURL=number.module.js.map |
| {"mappings":"AAAA;;;;;;;;;;CAUC,GAED;;CAEC,GACM,SAAS,0CAAM,KAAa,EAAE,MAAc,CAAC,QAAQ,EAAE,MAAc,QAAQ;IAClF,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO,MAAM;IAC9C,OAAO;AACT;AAEO,SAAS,0CAAqB,KAAa,EAAE,IAAY;IAC9D,IAAI,eAAe;IACnB,IAAI,aAAa,KAAK,QAAQ;IAC9B,IAAI,aAAa,WAAW,OAAO,CAAC;IACpC,IAAI,YAAY,cAAc,IAAI,WAAW,MAAM,GAAG,aAAa;IACnE,IAAI,YAAY,GAAG;QACjB,IAAI,MAAM,KAAK,GAAG,CAAC,IAAI;QACvB,eAAe,KAAK,KAAK,CAAC,eAAe,OAAO;IAClD;IACA,OAAO;AACT;AAEO,SAAS,0CAAgB,KAAa,EAAE,GAAuB,EAAE,GAAuB,EAAE,IAAY;IAC3G,MAAM,OAAO;IACb,MAAM,OAAO;IACb,IAAI,YAAa,AAAC,CAAA,QAAS,CAAA,MAAM,OAAO,IAAI,GAAE,CAAC,IAAK;IACpD,IAAI,eAAe,0CAAqB,KAAK,GAAG,CAAC,aAAa,KAAK,OAC/D,QAAQ,KAAK,IAAI,CAAC,aAAc,CAAA,OAAO,KAAK,GAAG,CAAC,UAAS,IACzD,QAAQ,WAAW;IAEvB,IAAI,CAAC,MAAM,MAAM;QACf,IAAI,eAAe,KACjB,eAAe;aACV,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,MAAM,KAAK,KAAK,CAAC,0CAAqB,AAAC,CAAA,MAAM,GAAE,IAAK,MAAM,SAAS;IAEtF,OAAO,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,KAAK,KAAK,CAAC,0CAAqB,MAAM,MAAM,SAAS;IAGtE,gEAAgE;IAChE,eAAe,0CAAqB,cAAc;IAElD,OAAO;AACT;AAGO,SAAS,yCAAc,KAAa,EAAE,MAAc,EAAE,OAAe,EAAE;IAC5E,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM;IAE3B,OAAO,KAAK,KAAK,CAAC,QAAQ,OAAO;AACnC","sources":["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\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 roundToStepPrecision(value: number, step: number) {\n let roundedValue = value;\n let stepString = step.toString();\n let pointIndex = stepString.indexOf('.');\n let precision = pointIndex >= 0 ? stepString.length - pointIndex : 0;\n if (precision > 0) {\n let pow = Math.pow(10, precision);\n roundedValue = Math.round(roundedValue * pow) / pow;\n }\n return roundedValue;\n}\n\nexport function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number {\n min = Number(min);\n max = Number(max);\n let remainder = ((value - (isNaN(min) ? 0 : min)) % step);\n let snappedValue = roundToStepPrecision(Math.abs(remainder) * 2 >= step\n ? value + Math.sign(remainder) * (step - Math.abs(remainder))\n : value - remainder, step);\n\n if (!isNaN(min)) {\n if (snappedValue < min) {\n snappedValue = min;\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = min + Math.floor(roundToStepPrecision((max - min) / step, step)) * step;\n }\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = Math.floor(roundToStepPrecision(max / step, step)) * step;\n }\n\n // correct floating point behavior by rounding to step precision\n snappedValue = roundToStepPrecision(snappedValue, step);\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":"number.module.js.map"} |
| export function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void]; | ||
| export function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void]; | ||
| /** | ||
| * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step. | ||
| */ | ||
| export function clamp(value: number, min?: number, max?: number): number; | ||
| export function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number; | ||
| export function toFixedNumber(value: number, digits: number, base?: number): number; | ||
| //# sourceMappingURL=types.d.ts.map |
| {"mappings":"AAcA,mCAAmC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC;AAChN,mCAAmC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC;ACHhN;;GAEG;AACH,sBAAsB,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAkB,EAAE,GAAG,GAAE,MAAiB,GAAG,MAAM,CAG5F;AAcD,gCAAgC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAsBrH;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"} |
| var $ecn6s$react = require("react"); | ||
| function $parcel$export(e, n, v, s) { | ||
| Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); | ||
| } | ||
| $parcel$export(module.exports, "useControlledState", () => $8d8fdfab47455712$export$40bfa8c7b0832715); | ||
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| function $8d8fdfab47455712$export$40bfa8c7b0832715(value, defaultValue, onChange) { | ||
| let [stateValue, setStateValue] = (0, $ecn6s$react.useState)(value || defaultValue); | ||
| let isControlledRef = (0, $ecn6s$react.useRef)(value !== undefined); | ||
| let isControlled = value !== undefined; | ||
| (0, $ecn6s$react.useEffect)(()=>{ | ||
| let wasControlled = isControlledRef.current; | ||
| if (wasControlled !== isControlled) console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`); | ||
| isControlledRef.current = isControlled; | ||
| }, [ | ||
| isControlled | ||
| ]); | ||
| let currentValue = isControlled ? value : stateValue; | ||
| let setValue = (0, $ecn6s$react.useCallback)((value, ...args)=>{ | ||
| let onChangeCaller = (value, ...onChangeArgs)=>{ | ||
| if (onChange) { | ||
| if (!Object.is(currentValue, value)) onChange(value, ...onChangeArgs); | ||
| } | ||
| if (!isControlled) // If uncontrolled, mutate the currentValue local variable so that | ||
| // calling setState multiple times with the same value only emits onChange once. | ||
| // We do not use a ref for this because we specifically _do_ want the value to | ||
| // reset every render, and assigning to a ref in render breaks aborted suspended renders. | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| currentValue = value; | ||
| }; | ||
| if (typeof value === 'function') { | ||
| console.warn('We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320'); | ||
| // this supports functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates | ||
| // when someone using useControlledState calls setControlledState(myFunc) | ||
| // this will call our useState setState with a function as well which invokes myFunc and calls onChange with the value from myFunc | ||
| // 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 | ||
| // 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 | ||
| let updateFunction = (oldValue, ...functionArgs)=>{ | ||
| let interceptedValue = value(isControlled ? currentValue : oldValue, ...functionArgs); | ||
| onChangeCaller(interceptedValue, ...args); | ||
| if (!isControlled) return interceptedValue; | ||
| return oldValue; | ||
| }; | ||
| setStateValue(updateFunction); | ||
| } else { | ||
| if (!isControlled) setStateValue(value); | ||
| onChangeCaller(value, ...args); | ||
| } | ||
| }, [ | ||
| isControlled, | ||
| currentValue, | ||
| onChange | ||
| ]); | ||
| return [ | ||
| currentValue, | ||
| setValue | ||
| ]; | ||
| } | ||
| //# sourceMappingURL=useControlledState.main.js.map |
| {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAMM,SAAS,0CAA6B,KAAQ,EAAE,YAAe,EAAE,QAAyC;IAC/G,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,qBAAO,EAAE,SAAS;IAEpD,IAAI,kBAAkB,CAAA,GAAA,mBAAK,EAAE,UAAU;IACvC,IAAI,eAAe,UAAU;IAC7B,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,gBAAgB,gBAAgB,OAAO;QAC3C,IAAI,kBAAkB,cACpB,QAAQ,IAAI,CAAC,CAAC,+BAA+B,EAAE,gBAAgB,eAAe,eAAe,IAAI,EAAE,eAAe,eAAe,eAAe,CAAC,CAAC;QAEpJ,gBAAgB,OAAO,GAAG;IAC5B,GAAG;QAAC;KAAa;IAEjB,IAAI,eAAe,eAAe,QAAQ;IAC1C,IAAI,WAAW,CAAA,GAAA,wBAAU,EAAE,CAAC,OAAO,GAAG;QACpC,IAAI,iBAAiB,CAAC,OAAO,GAAG;YAC9B,IAAI,UACF;gBAAA,IAAI,CAAC,OAAO,EAAE,CAAC,cAAc,QAC3B,SAAS,UAAU;YACrB;YAEF,IAAI,CAAC,cACH,kEAAkE;YAClE,gFAAgF;YAChF,8EAA8E;YAC9E,yFAAyF;YACzF,uDAAuD;YACvD,eAAe;QAEnB;QAEA,IAAI,OAAO,UAAU,YAAY;YAC/B,QAAQ,IAAI,CAAC;YACb,oGAAoG;YACpG,yEAAyE;YACzE,kIAAkI;YAClI,iKAAiK;YACjK,yIAAyI;YACzI,IAAI,iBAAiB,CAAC,UAAU,GAAG;gBACjC,IAAI,mBAAmB,MAAM,eAAe,eAAe,aAAa;gBACxE,eAAe,qBAAqB;gBACpC,IAAI,CAAC,cACH,OAAO;gBAET,OAAO;YACT;YACA,cAAc;QAChB,OAAO;YACL,IAAI,CAAC,cACH,cAAc;YAEhB,eAAe,UAAU;QAC3B;IACF,GAAG;QAAC;QAAc;QAAc;KAAS;IAEzC,OAAO;QAAC;QAAc;KAAS;AACjC","sources":["packages/@react-stately/utils/src/useControlledState.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\nimport {useCallback, useEffect, useRef, useState} from 'react';\n\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: T, defaultValue: T, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void] {\n let [stateValue, setStateValue] = useState(value || defaultValue);\n\n let isControlledRef = useRef(value !== undefined);\n let isControlled = value !== undefined;\n useEffect(() => {\n let wasControlled = isControlledRef.current;\n if (wasControlled !== isControlled) {\n console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);\n }\n isControlledRef.current = isControlled;\n }, [isControlled]);\n\n let currentValue = isControlled ? value : stateValue;\n let setValue = useCallback((value, ...args) => {\n let onChangeCaller = (value, ...onChangeArgs) => {\n if (onChange) {\n if (!Object.is(currentValue, value)) {\n onChange(value, ...onChangeArgs);\n }\n }\n if (!isControlled) {\n // If uncontrolled, mutate the currentValue local variable so that\n // calling setState multiple times with the same value only emits onChange once.\n // We do not use a ref for this because we specifically _do_ want the value to\n // reset every render, and assigning to a ref in render breaks aborted suspended renders.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n currentValue = 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 ? currentValue : 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, currentValue, onChange]);\n\n return [currentValue, setValue];\n}\n"],"names":[],"version":3,"file":"useControlledState.main.js.map"} |
| import {useState as $3whtM$useState, useRef as $3whtM$useRef, useEffect as $3whtM$useEffect, useCallback as $3whtM$useCallback} from "react"; | ||
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value, defaultValue, onChange) { | ||
| let [stateValue, setStateValue] = (0, $3whtM$useState)(value || defaultValue); | ||
| let isControlledRef = (0, $3whtM$useRef)(value !== undefined); | ||
| let isControlled = value !== undefined; | ||
| (0, $3whtM$useEffect)(()=>{ | ||
| let wasControlled = isControlledRef.current; | ||
| if (wasControlled !== isControlled) console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`); | ||
| isControlledRef.current = isControlled; | ||
| }, [ | ||
| isControlled | ||
| ]); | ||
| let currentValue = isControlled ? value : stateValue; | ||
| let setValue = (0, $3whtM$useCallback)((value, ...args)=>{ | ||
| let onChangeCaller = (value, ...onChangeArgs)=>{ | ||
| if (onChange) { | ||
| if (!Object.is(currentValue, value)) onChange(value, ...onChangeArgs); | ||
| } | ||
| if (!isControlled) // If uncontrolled, mutate the currentValue local variable so that | ||
| // calling setState multiple times with the same value only emits onChange once. | ||
| // We do not use a ref for this because we specifically _do_ want the value to | ||
| // reset every render, and assigning to a ref in render breaks aborted suspended renders. | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| currentValue = value; | ||
| }; | ||
| if (typeof value === 'function') { | ||
| console.warn('We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320'); | ||
| // this supports functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates | ||
| // when someone using useControlledState calls setControlledState(myFunc) | ||
| // this will call our useState setState with a function as well which invokes myFunc and calls onChange with the value from myFunc | ||
| // 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 | ||
| // 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 | ||
| let updateFunction = (oldValue, ...functionArgs)=>{ | ||
| let interceptedValue = value(isControlled ? currentValue : oldValue, ...functionArgs); | ||
| onChangeCaller(interceptedValue, ...args); | ||
| if (!isControlled) return interceptedValue; | ||
| return oldValue; | ||
| }; | ||
| setStateValue(updateFunction); | ||
| } else { | ||
| if (!isControlled) setStateValue(value); | ||
| onChangeCaller(value, ...args); | ||
| } | ||
| }, [ | ||
| isControlled, | ||
| currentValue, | ||
| onChange | ||
| ]); | ||
| return [ | ||
| currentValue, | ||
| setValue | ||
| ]; | ||
| } | ||
| export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState}; | ||
| //# sourceMappingURL=useControlledState.module.js.map |
| import {useState as $3whtM$useState, useRef as $3whtM$useRef, useEffect as $3whtM$useEffect, useCallback as $3whtM$useCallback} from "react"; | ||
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value, defaultValue, onChange) { | ||
| let [stateValue, setStateValue] = (0, $3whtM$useState)(value || defaultValue); | ||
| let isControlledRef = (0, $3whtM$useRef)(value !== undefined); | ||
| let isControlled = value !== undefined; | ||
| (0, $3whtM$useEffect)(()=>{ | ||
| let wasControlled = isControlledRef.current; | ||
| if (wasControlled !== isControlled) console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`); | ||
| isControlledRef.current = isControlled; | ||
| }, [ | ||
| isControlled | ||
| ]); | ||
| let currentValue = isControlled ? value : stateValue; | ||
| let setValue = (0, $3whtM$useCallback)((value, ...args)=>{ | ||
| let onChangeCaller = (value, ...onChangeArgs)=>{ | ||
| if (onChange) { | ||
| if (!Object.is(currentValue, value)) onChange(value, ...onChangeArgs); | ||
| } | ||
| if (!isControlled) // If uncontrolled, mutate the currentValue local variable so that | ||
| // calling setState multiple times with the same value only emits onChange once. | ||
| // We do not use a ref for this because we specifically _do_ want the value to | ||
| // reset every render, and assigning to a ref in render breaks aborted suspended renders. | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| currentValue = value; | ||
| }; | ||
| if (typeof value === 'function') { | ||
| console.warn('We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320'); | ||
| // this supports functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates | ||
| // when someone using useControlledState calls setControlledState(myFunc) | ||
| // this will call our useState setState with a function as well which invokes myFunc and calls onChange with the value from myFunc | ||
| // 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 | ||
| // 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 | ||
| let updateFunction = (oldValue, ...functionArgs)=>{ | ||
| let interceptedValue = value(isControlled ? currentValue : oldValue, ...functionArgs); | ||
| onChangeCaller(interceptedValue, ...args); | ||
| if (!isControlled) return interceptedValue; | ||
| return oldValue; | ||
| }; | ||
| setStateValue(updateFunction); | ||
| } else { | ||
| if (!isControlled) setStateValue(value); | ||
| onChangeCaller(value, ...args); | ||
| } | ||
| }, [ | ||
| isControlled, | ||
| currentValue, | ||
| onChange | ||
| ]); | ||
| return [ | ||
| currentValue, | ||
| setValue | ||
| ]; | ||
| } | ||
| export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState}; | ||
| //# sourceMappingURL=useControlledState.module.js.map |
| {"mappings":";;AAAA;;;;;;;;;;CAUC;AAMM,SAAS,0CAA6B,KAAQ,EAAE,YAAe,EAAE,QAAyC;IAC/G,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,eAAO,EAAE,SAAS;IAEpD,IAAI,kBAAkB,CAAA,GAAA,aAAK,EAAE,UAAU;IACvC,IAAI,eAAe,UAAU;IAC7B,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,gBAAgB,gBAAgB,OAAO;QAC3C,IAAI,kBAAkB,cACpB,QAAQ,IAAI,CAAC,CAAC,+BAA+B,EAAE,gBAAgB,eAAe,eAAe,IAAI,EAAE,eAAe,eAAe,eAAe,CAAC,CAAC;QAEpJ,gBAAgB,OAAO,GAAG;IAC5B,GAAG;QAAC;KAAa;IAEjB,IAAI,eAAe,eAAe,QAAQ;IAC1C,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE,CAAC,OAAO,GAAG;QACpC,IAAI,iBAAiB,CAAC,OAAO,GAAG;YAC9B,IAAI,UACF;gBAAA,IAAI,CAAC,OAAO,EAAE,CAAC,cAAc,QAC3B,SAAS,UAAU;YACrB;YAEF,IAAI,CAAC,cACH,kEAAkE;YAClE,gFAAgF;YAChF,8EAA8E;YAC9E,yFAAyF;YACzF,uDAAuD;YACvD,eAAe;QAEnB;QAEA,IAAI,OAAO,UAAU,YAAY;YAC/B,QAAQ,IAAI,CAAC;YACb,oGAAoG;YACpG,yEAAyE;YACzE,kIAAkI;YAClI,iKAAiK;YACjK,yIAAyI;YACzI,IAAI,iBAAiB,CAAC,UAAU,GAAG;gBACjC,IAAI,mBAAmB,MAAM,eAAe,eAAe,aAAa;gBACxE,eAAe,qBAAqB;gBACpC,IAAI,CAAC,cACH,OAAO;gBAET,OAAO;YACT;YACA,cAAc;QAChB,OAAO;YACL,IAAI,CAAC,cACH,cAAc;YAEhB,eAAe,UAAU;QAC3B;IACF,GAAG;QAAC;QAAc;QAAc;KAAS;IAEzC,OAAO;QAAC;QAAc;KAAS;AACjC","sources":["packages/@react-stately/utils/src/useControlledState.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\nimport {useCallback, useEffect, useRef, useState} from 'react';\n\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: T, defaultValue: T, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void] {\n let [stateValue, setStateValue] = useState(value || defaultValue);\n\n let isControlledRef = useRef(value !== undefined);\n let isControlled = value !== undefined;\n useEffect(() => {\n let wasControlled = isControlledRef.current;\n if (wasControlled !== isControlled) {\n console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);\n }\n isControlledRef.current = isControlled;\n }, [isControlled]);\n\n let currentValue = isControlled ? value : stateValue;\n let setValue = useCallback((value, ...args) => {\n let onChangeCaller = (value, ...onChangeArgs) => {\n if (onChange) {\n if (!Object.is(currentValue, value)) {\n onChange(value, ...onChangeArgs);\n }\n }\n if (!isControlled) {\n // If uncontrolled, mutate the currentValue local variable so that\n // calling setState multiple times with the same value only emits onChange once.\n // We do not use a ref for this because we specifically _do_ want the value to\n // reset every render, and assigning to a ref in render breaks aborted suspended renders.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n currentValue = 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 ? currentValue : 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, currentValue, onChange]);\n\n return [currentValue, setValue];\n}\n"],"names":[],"version":3,"file":"useControlledState.module.js.map"} |
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| /** | ||
| * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step. | ||
| */ | ||
| export function clamp(value: number, min: number = -Infinity, max: number = Infinity): number { | ||
| let newValue = Math.min(Math.max(value, min), max); | ||
| return newValue; | ||
| } | ||
| export function roundToStepPrecision(value: number, step: number) { | ||
| let roundedValue = value; | ||
| let stepString = step.toString(); | ||
| let pointIndex = stepString.indexOf('.'); | ||
| let precision = pointIndex >= 0 ? stepString.length - pointIndex : 0; | ||
| if (precision > 0) { | ||
| let pow = Math.pow(10, precision); | ||
| roundedValue = Math.round(roundedValue * pow) / pow; | ||
| } | ||
| return roundedValue; | ||
| } | ||
| export function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number { | ||
| min = Number(min); | ||
| max = Number(max); | ||
| let remainder = ((value - (isNaN(min) ? 0 : min)) % step); | ||
| let snappedValue = roundToStepPrecision(Math.abs(remainder) * 2 >= step | ||
| ? value + Math.sign(remainder) * (step - Math.abs(remainder)) | ||
| : value - remainder, step); | ||
| if (!isNaN(min)) { | ||
| if (snappedValue < min) { | ||
| snappedValue = min; | ||
| } else if (!isNaN(max) && snappedValue > max) { | ||
| snappedValue = min + Math.floor(roundToStepPrecision((max - min) / step, step)) * step; | ||
| } | ||
| } else if (!isNaN(max) && snappedValue > max) { | ||
| snappedValue = Math.floor(roundToStepPrecision(max / step, step)) * step; | ||
| } | ||
| // correct floating point behavior by rounding to step precision | ||
| snappedValue = roundToStepPrecision(snappedValue, step); | ||
| return snappedValue; | ||
| } | ||
| /* Takes a value and rounds off to the number of digits. */ | ||
| export function toFixedNumber(value: number, digits: number, base: number = 10): number { | ||
| const pow = Math.pow(base, digits); | ||
| return Math.round(value * pow) / pow; | ||
| } |
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| import {useCallback, useEffect, useRef, useState} from 'react'; | ||
| export function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void]; | ||
| export function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void]; | ||
| export function useControlledState<T, C = T>(value: T, defaultValue: T, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void] { | ||
| let [stateValue, setStateValue] = useState(value || defaultValue); | ||
| let isControlledRef = useRef(value !== undefined); | ||
| let isControlled = value !== undefined; | ||
| useEffect(() => { | ||
| let wasControlled = isControlledRef.current; | ||
| if (wasControlled !== isControlled) { | ||
| console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`); | ||
| } | ||
| isControlledRef.current = isControlled; | ||
| }, [isControlled]); | ||
| let currentValue = isControlled ? value : stateValue; | ||
| let setValue = useCallback((value, ...args) => { | ||
| let onChangeCaller = (value, ...onChangeArgs) => { | ||
| if (onChange) { | ||
| if (!Object.is(currentValue, value)) { | ||
| onChange(value, ...onChangeArgs); | ||
| } | ||
| } | ||
| if (!isControlled) { | ||
| // If uncontrolled, mutate the currentValue local variable so that | ||
| // calling setState multiple times with the same value only emits onChange once. | ||
| // We do not use a ref for this because we specifically _do_ want the value to | ||
| // reset every render, and assigning to a ref in render breaks aborted suspended renders. | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| currentValue = value; | ||
| } | ||
| }; | ||
| if (typeof value === 'function') { | ||
| console.warn('We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320'); | ||
| // this supports functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates | ||
| // when someone using useControlledState calls setControlledState(myFunc) | ||
| // this will call our useState setState with a function as well which invokes myFunc and calls onChange with the value from myFunc | ||
| // 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 | ||
| // 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 | ||
| let updateFunction = (oldValue, ...functionArgs) => { | ||
| let interceptedValue = value(isControlled ? currentValue : oldValue, ...functionArgs); | ||
| onChangeCaller(interceptedValue, ...args); | ||
| if (!isControlled) { | ||
| return interceptedValue; | ||
| } | ||
| return oldValue; | ||
| }; | ||
| setStateValue(updateFunction); | ||
| } else { | ||
| if (!isControlled) { | ||
| setStateValue(value); | ||
| } | ||
| onChangeCaller(value, ...args); | ||
| } | ||
| }, [isControlled, currentValue, onChange]); | ||
| return [currentValue, setValue]; | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
0
-100%8166
-85.01%4
100%2
Infinity%9
-59.09%66
-87.73%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added