@tamagui/use-controllable-state 1.116.0 → 1.116.2
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,15 @@
|
|
|
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
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-controllable-state",
|
|
3
|
-
"version": "1.116.
|
|
3
|
+
"version": "1.116.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/start-transition": "1.116.
|
|
35
|
-
"@tamagui/use-event": "1.116.
|
|
34
|
+
"@tamagui/start-transition": "1.116.2",
|
|
35
|
+
"@tamagui/use-event": "1.116.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@tamagui/build": "1.116.
|
|
38
|
+
"@tamagui/build": "1.116.2",
|
|
39
39
|
"react": "^18.2.0 || ^19.0.0"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
File without changes
|
|
File without changes
|