@radix-ui/react-use-controllable-state 1.1.0-rc.1 → 1.1.0-rc.3

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/index.js CHANGED
@@ -1,76 +1,80 @@
1
1
  "use strict";
2
- (() => {
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
29
 
32
- // packages/react/use-controllable-state/src/useControllableState.tsx
33
- var React = __toESM(__require("react"));
34
- var import_react_use_callback_ref = __require("@radix-ui/react-use-callback-ref");
35
- function useControllableState({
36
- prop,
37
- defaultProp,
38
- onChange = () => {
39
- }
40
- }) {
41
- const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({ defaultProp, onChange });
42
- const isControlled = prop !== void 0;
43
- const value = isControlled ? prop : uncontrolledProp;
44
- const handleChange = (0, import_react_use_callback_ref.useCallbackRef)(onChange);
45
- const setValue = React.useCallback(
46
- (nextValue) => {
47
- if (isControlled) {
48
- const setter = nextValue;
49
- const value2 = typeof nextValue === "function" ? setter(prop) : nextValue;
50
- if (value2 !== prop) handleChange(value2);
51
- } else {
52
- setUncontrolledProp(nextValue);
53
- }
54
- },
55
- [isControlled, prop, setUncontrolledProp, handleChange]
56
- );
57
- return [value, setValue];
30
+ // packages/react/use-controllable-state/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ useControllableState: () => useControllableState
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // packages/react/use-controllable-state/src/useControllableState.tsx
38
+ var React = __toESM(require("react"));
39
+ var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
40
+ function useControllableState({
41
+ prop,
42
+ defaultProp,
43
+ onChange = () => {
58
44
  }
59
- function useUncontrolledState({
60
- defaultProp,
61
- onChange
62
- }) {
63
- const uncontrolledState = React.useState(defaultProp);
64
- const [value] = uncontrolledState;
65
- const prevValueRef = React.useRef(value);
66
- const handleChange = (0, import_react_use_callback_ref.useCallbackRef)(onChange);
67
- React.useEffect(() => {
68
- if (prevValueRef.current !== value) {
69
- handleChange(value);
70
- prevValueRef.current = value;
45
+ }) {
46
+ const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({ defaultProp, onChange });
47
+ const isControlled = prop !== void 0;
48
+ const value = isControlled ? prop : uncontrolledProp;
49
+ const handleChange = (0, import_react_use_callback_ref.useCallbackRef)(onChange);
50
+ const setValue = React.useCallback(
51
+ (nextValue) => {
52
+ if (isControlled) {
53
+ const setter = nextValue;
54
+ const value2 = typeof nextValue === "function" ? setter(prop) : nextValue;
55
+ if (value2 !== prop) handleChange(value2);
56
+ } else {
57
+ setUncontrolledProp(nextValue);
71
58
  }
72
- }, [value, prevValueRef, handleChange]);
73
- return uncontrolledState;
74
- }
75
- })();
59
+ },
60
+ [isControlled, prop, setUncontrolledProp, handleChange]
61
+ );
62
+ return [value, setValue];
63
+ }
64
+ function useUncontrolledState({
65
+ defaultProp,
66
+ onChange
67
+ }) {
68
+ const uncontrolledState = React.useState(defaultProp);
69
+ const [value] = uncontrolledState;
70
+ const prevValueRef = React.useRef(value);
71
+ const handleChange = (0, import_react_use_callback_ref.useCallbackRef)(onChange);
72
+ React.useEffect(() => {
73
+ if (prevValueRef.current !== value) {
74
+ handleChange(value);
75
+ prevValueRef.current = value;
76
+ }
77
+ }, [value, prevValueRef, handleChange]);
78
+ return uncontrolledState;
79
+ }
76
80
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/useControllableState.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\n\ntype UseControllableStateParams<T> = {\n prop?: T | undefined;\n defaultProp?: T | undefined;\n onChange?: (state: T) => void;\n};\n\ntype SetStateFn<T> = (prevState?: T) => T;\n\nfunction useControllableState<T>({\n prop,\n defaultProp,\n onChange = () => {},\n}: UseControllableStateParams<T>) {\n const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({ defaultProp, onChange });\n const isControlled = prop !== undefined;\n const value = isControlled ? prop : uncontrolledProp;\n const handleChange = useCallbackRef(onChange);\n\n const setValue: React.Dispatch<React.SetStateAction<T | undefined>> = React.useCallback(\n (nextValue) => {\n if (isControlled) {\n const setter = nextValue as SetStateFn<T>;\n const value = typeof nextValue === 'function' ? setter(prop) : nextValue;\n if (value !== prop) handleChange(value as T);\n } else {\n setUncontrolledProp(nextValue);\n }\n },\n [isControlled, prop, setUncontrolledProp, handleChange]\n );\n\n return [value, setValue] as const;\n}\n\nfunction useUncontrolledState<T>({\n defaultProp,\n onChange,\n}: Omit<UseControllableStateParams<T>, 'prop'>) {\n const uncontrolledState = React.useState<T | undefined>(defaultProp);\n const [value] = uncontrolledState;\n const prevValueRef = React.useRef(value);\n const handleChange = useCallbackRef(onChange);\n\n React.useEffect(() => {\n if (prevValueRef.current !== value) {\n handleChange(value as T);\n prevValueRef.current = value;\n }\n }, [value, prevValueRef, handleChange]);\n\n return uncontrolledState;\n}\n\nexport { useControllableState };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AACvB,sCAA+B;AAU/B,WAAS,qBAAwB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,WAAW,MAAM;AAAA,IAAC;AAAA,EACpB,GAAkC;AAChC,UAAM,CAAC,kBAAkB,mBAAmB,IAAI,qBAAqB,EAAE,aAAa,SAAS,CAAC;AAC9F,UAAM,eAAe,SAAS;AAC9B,UAAM,QAAQ,eAAe,OAAO;AACpC,UAAM,mBAAe,8CAAe,QAAQ;AAE5C,UAAM,WAAsE;AAAA,MAC1E,CAAC,cAAc;AACb,YAAI,cAAc;AAChB,gBAAM,SAAS;AACf,gBAAMA,SAAQ,OAAO,cAAc,aAAa,OAAO,IAAI,IAAI;AAC/D,cAAIA,WAAU,KAAM,cAAaA,MAAU;AAAA,QAC7C,OAAO;AACL,8BAAoB,SAAS;AAAA,QAC/B;AAAA,MACF;AAAA,MACA,CAAC,cAAc,MAAM,qBAAqB,YAAY;AAAA,IACxD;AAEA,WAAO,CAAC,OAAO,QAAQ;AAAA,EACzB;AAEA,WAAS,qBAAwB;AAAA,IAC/B;AAAA,IACA;AAAA,EACF,GAAgD;AAC9C,UAAM,oBAA0B,eAAwB,WAAW;AACnE,UAAM,CAAC,KAAK,IAAI;AAChB,UAAM,eAAqB,aAAO,KAAK;AACvC,UAAM,mBAAe,8CAAe,QAAQ;AAE5C,IAAM,gBAAU,MAAM;AACpB,UAAI,aAAa,YAAY,OAAO;AAClC,qBAAa,KAAU;AACvB,qBAAa,UAAU;AAAA,MACzB;AAAA,IACF,GAAG,CAAC,OAAO,cAAc,YAAY,CAAC;AAEtC,WAAO;AAAA,EACT;",
3
+ "sources": ["../src/index.ts", "../src/useControllableState.tsx"],
4
+ "sourcesContent": ["export { useControllableState } from './useControllableState';\n", "import * as React from 'react';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\n\ntype UseControllableStateParams<T> = {\n prop?: T | undefined;\n defaultProp?: T | undefined;\n onChange?: (state: T) => void;\n};\n\ntype SetStateFn<T> = (prevState?: T) => T;\n\nfunction useControllableState<T>({\n prop,\n defaultProp,\n onChange = () => {},\n}: UseControllableStateParams<T>) {\n const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({ defaultProp, onChange });\n const isControlled = prop !== undefined;\n const value = isControlled ? prop : uncontrolledProp;\n const handleChange = useCallbackRef(onChange);\n\n const setValue: React.Dispatch<React.SetStateAction<T | undefined>> = React.useCallback(\n (nextValue) => {\n if (isControlled) {\n const setter = nextValue as SetStateFn<T>;\n const value = typeof nextValue === 'function' ? setter(prop) : nextValue;\n if (value !== prop) handleChange(value as T);\n } else {\n setUncontrolledProp(nextValue);\n }\n },\n [isControlled, prop, setUncontrolledProp, handleChange]\n );\n\n return [value, setValue] as const;\n}\n\nfunction useUncontrolledState<T>({\n defaultProp,\n onChange,\n}: Omit<UseControllableStateParams<T>, 'prop'>) {\n const uncontrolledState = React.useState<T | undefined>(defaultProp);\n const [value] = uncontrolledState;\n const prevValueRef = React.useRef(value);\n const handleChange = useCallbackRef(onChange);\n\n React.useEffect(() => {\n if (prevValueRef.current !== value) {\n handleChange(value as T);\n prevValueRef.current = value;\n }\n }, [value, prevValueRef, handleChange]);\n\n return uncontrolledState;\n}\n\nexport { useControllableState };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,oCAA+B;AAU/B,SAAS,qBAAwB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,WAAW,MAAM;AAAA,EAAC;AACpB,GAAkC;AAChC,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,qBAAqB,EAAE,aAAa,SAAS,CAAC;AAC9F,QAAM,eAAe,SAAS;AAC9B,QAAM,QAAQ,eAAe,OAAO;AACpC,QAAM,mBAAe,8CAAe,QAAQ;AAE5C,QAAM,WAAsE;AAAA,IAC1E,CAAC,cAAc;AACb,UAAI,cAAc;AAChB,cAAM,SAAS;AACf,cAAMA,SAAQ,OAAO,cAAc,aAAa,OAAO,IAAI,IAAI;AAC/D,YAAIA,WAAU,KAAM,cAAaA,MAAU;AAAA,MAC7C,OAAO;AACL,4BAAoB,SAAS;AAAA,MAC/B;AAAA,IACF;AAAA,IACA,CAAC,cAAc,MAAM,qBAAqB,YAAY;AAAA,EACxD;AAEA,SAAO,CAAC,OAAO,QAAQ;AACzB;AAEA,SAAS,qBAAwB;AAAA,EAC/B;AAAA,EACA;AACF,GAAgD;AAC9C,QAAM,oBAA0B,eAAwB,WAAW;AACnE,QAAM,CAAC,KAAK,IAAI;AAChB,QAAM,eAAqB,aAAO,KAAK;AACvC,QAAM,mBAAe,8CAAe,QAAQ;AAE5C,EAAM,gBAAU,MAAM;AACpB,QAAI,aAAa,YAAY,OAAO;AAClC,mBAAa,KAAU;AACvB,mBAAa,UAAU;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,OAAO,cAAc,YAAY,CAAC;AAEtC,SAAO;AACT;",
6
6
  "names": ["value"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-use-controllable-state",
3
- "version": "1.1.0-rc.1",
3
+ "version": "1.1.0-rc.3",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -28,7 +28,7 @@
28
28
  "version": "yarn version"
29
29
  },
30
30
  "dependencies": {
31
- "@radix-ui/react-use-callback-ref": "1.1.0-rc.1"
31
+ "@radix-ui/react-use-callback-ref": "1.1.0-rc.3"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@types/react": "*",