@tamagui/use-controllable-state 1.114.3 → 1.115.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
+ get: () => from[key],
8
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
+ });
10
+ return to;
11
+ },
12
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
13
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
14
+ value: !0
15
+ }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./useControllableState.cjs"), module.exports);
@@ -0,0 +1,72 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ 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", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var useControllableState_exports = {};
33
+ __export(useControllableState_exports, {
34
+ useControllableState: () => useControllableState
35
+ });
36
+ module.exports = __toCommonJS(useControllableState_exports);
37
+ var import_use_event = require("@tamagui/use-event"),
38
+ React = __toESM(require("react")),
39
+ import_start_transition = require("@tamagui/start-transition");
40
+ const emptyCallbackFn = _ => _();
41
+ function useControllableState({
42
+ prop,
43
+ defaultProp,
44
+ onChange,
45
+ strategy = "prop-wins",
46
+ preventUpdate,
47
+ transition
48
+ }) {
49
+ const [state, setState] = React.useState(prop ?? defaultProp),
50
+ previous = React.useRef(state),
51
+ propWins = strategy === "prop-wins" && prop !== void 0,
52
+ value = propWins ? prop : state,
53
+ onChangeCb = (0, import_use_event.useEvent)(onChange || idFn),
54
+ transitionFn = transition ? import_start_transition.startTransition : emptyCallbackFn;
55
+ React.useEffect(() => {
56
+ prop !== void 0 && (previous.current = prop, transitionFn(() => {
57
+ setState(prop);
58
+ }));
59
+ }, [prop]), React.useEffect(() => {
60
+ propWins || state !== previous.current && (previous.current = state, onChangeCb(state));
61
+ }, [onChangeCb, state, propWins]);
62
+ const setter = (0, import_use_event.useEvent)(next => {
63
+ if (!preventUpdate) if (propWins) {
64
+ const nextValue = typeof next == "function" ? next(previous.current) : next;
65
+ onChangeCb(nextValue);
66
+ } else transitionFn(() => {
67
+ setState(next);
68
+ });
69
+ });
70
+ return [value, setter];
71
+ }
72
+ const idFn = () => {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-controllable-state",
3
- "version": "1.114.3",
3
+ "version": "1.115.0",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -26,15 +26,16 @@
26
26
  "react-native": "./dist/cjs/index.native.js",
27
27
  "types": "./types/index.d.ts",
28
28
  "import": "./dist/esm/index.mjs",
29
- "require": "./dist/cjs/index.js"
29
+ "require": "./dist/cjs/index.cjs",
30
+ "default": "./dist/cjs/index.native.js"
30
31
  }
31
32
  },
32
33
  "dependencies": {
33
- "@tamagui/start-transition": "1.114.3",
34
- "@tamagui/use-event": "1.114.3"
34
+ "@tamagui/start-transition": "1.115.0",
35
+ "@tamagui/use-event": "1.115.0"
35
36
  },
36
37
  "devDependencies": {
37
- "@tamagui/build": "1.114.3",
38
+ "@tamagui/build": "1.115.0",
38
39
  "react": "^18.2.0 || ^19.0.0"
39
40
  },
40
41
  "publishConfig": {
package/dist/cjs/index.js DELETED
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var src_exports = {};
13
- module.exports = __toCommonJS(src_exports);
14
- __reExport(src_exports, require("./useControllableState"), module.exports);
15
- //# sourceMappingURL=index.js.map
@@ -1,60 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var useControllableState_exports = {};
24
- __export(useControllableState_exports, {
25
- useControllableState: () => useControllableState
26
- });
27
- module.exports = __toCommonJS(useControllableState_exports);
28
- var import_use_event = require("@tamagui/use-event"), React = __toESM(require("react")), import_start_transition = require("@tamagui/start-transition");
29
- const emptyCallbackFn = (_) => _();
30
- function useControllableState({
31
- prop,
32
- defaultProp,
33
- onChange,
34
- strategy = "prop-wins",
35
- preventUpdate,
36
- transition
37
- }) {
38
- const [state, setState] = React.useState(prop ?? defaultProp), previous = React.useRef(state), propWins = strategy === "prop-wins" && prop !== void 0, value = propWins ? prop : state, onChangeCb = (0, import_use_event.useEvent)(onChange || idFn), transitionFn = transition ? import_start_transition.startTransition : emptyCallbackFn;
39
- React.useEffect(() => {
40
- prop !== void 0 && (previous.current = prop, transitionFn(() => {
41
- setState(prop);
42
- }));
43
- }, [prop]), React.useEffect(() => {
44
- propWins || state !== previous.current && (previous.current = state, onChangeCb(state));
45
- }, [onChangeCb, state, propWins]);
46
- const setter = (0, import_use_event.useEvent)((next) => {
47
- if (!preventUpdate)
48
- if (propWins) {
49
- const nextValue = typeof next == "function" ? next(previous.current) : next;
50
- onChangeCb(nextValue);
51
- } else
52
- transitionFn(() => {
53
- setState(next);
54
- });
55
- });
56
- return [value, setter];
57
- }
58
- const idFn = () => {
59
- };
60
- //# sourceMappingURL=useControllableState.js.map
File without changes