@tamagui/use-controllable-state 2.0.0-rc.3 → 2.0.0-rc.30
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/cjs/index.js +11 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/package.json +7 -10
- package/src/useControllableState.ts +1 -1
- package/types/useControllableState.d.ts +1 -1
- package/types/useControllableState.d.ts.map +1 -1
- package/dist/cjs/useControllableState.js +0 -60
- package/dist/cjs/useControllableState.js.map +0 -6
- package/dist/esm/useControllableState.js +0 -38
- package/dist/esm/useControllableState.js.map +0 -6
package/dist/cjs/index.js
CHANGED
|
@@ -3,13 +3,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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);
|
|
12
16
|
var index_exports = {};
|
|
13
17
|
module.exports = __toCommonJS(index_exports);
|
|
14
|
-
__reExport(index_exports, require("./useControllableState"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
18
|
+
__reExport(index_exports, require("./useControllableState.cjs"), module.exports);
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./useControllableState";
|
|
1
|
+
export * from "./useControllableState.mjs";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-controllable-state",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.30",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -17,15 +17,12 @@
|
|
|
17
17
|
"./package.json": "./package.json",
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./types/index.d.ts",
|
|
20
|
-
"react-native":
|
|
21
|
-
|
|
22
|
-
"import": "./dist/esm/index.native.js",
|
|
23
|
-
"require": "./dist/cjs/index.native.js"
|
|
24
|
-
},
|
|
20
|
+
"react-native": "./dist/esm/index.native.js",
|
|
21
|
+
"browser": "./dist/esm/index.mjs",
|
|
25
22
|
"module": "./dist/esm/index.mjs",
|
|
26
23
|
"import": "./dist/esm/index.mjs",
|
|
27
24
|
"require": "./dist/cjs/index.cjs",
|
|
28
|
-
"default": "./dist/
|
|
25
|
+
"default": "./dist/esm/index.mjs"
|
|
29
26
|
}
|
|
30
27
|
},
|
|
31
28
|
"publishConfig": {
|
|
@@ -38,11 +35,11 @@
|
|
|
38
35
|
"clean:build": "tamagui-build clean:build"
|
|
39
36
|
},
|
|
40
37
|
"dependencies": {
|
|
41
|
-
"@tamagui/start-transition": "2.0.0-rc.
|
|
42
|
-
"@tamagui/use-event": "2.0.0-rc.
|
|
38
|
+
"@tamagui/start-transition": "2.0.0-rc.30",
|
|
39
|
+
"@tamagui/use-event": "2.0.0-rc.30"
|
|
43
40
|
},
|
|
44
41
|
"devDependencies": {
|
|
45
|
-
"@tamagui/build": "2.0.0-rc.
|
|
42
|
+
"@tamagui/build": "2.0.0-rc.30",
|
|
46
43
|
"react": ">=19"
|
|
47
44
|
},
|
|
48
45
|
"peerDependencies": {
|
|
@@ -5,7 +5,7 @@ import { startTransition } from '@tamagui/start-transition'
|
|
|
5
5
|
// can configure to allow most-recent-wins or prop-wins
|
|
6
6
|
// defaults to prop-wins
|
|
7
7
|
|
|
8
|
-
type ChangeCb<T> = (
|
|
8
|
+
type ChangeCb<T> = (next: T) => void
|
|
9
9
|
|
|
10
10
|
const emptyCallbackFn = (_) => _()
|
|
11
11
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
type ChangeCb<T> = (
|
|
2
|
+
type ChangeCb<T> = (next: T) => void;
|
|
3
3
|
export declare function useControllableState<T>({ prop, defaultProp, onChange, strategy, preventUpdate, transition, }: {
|
|
4
4
|
prop?: T | undefined;
|
|
5
5
|
defaultProp: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../src/useControllableState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../src/useControllableState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;AAIpC,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EACtC,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAsB,EACtB,aAAa,EACb,UAAU,GACX,EAAE;IACD,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IACpB,WAAW,EAAE,CAAC,CAAA;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IACtB,QAAQ,CAAC,EAAE,WAAW,GAAG,kBAAkB,CAAA;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAsC/C"}
|
|
@@ -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"), 1), 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
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useControllableState.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB,+BACzB,QAAuB,8BACvB,0BAAgC;AAOhC,MAAM,kBAAkB,CAAC,MAAM,EAAE;AAE1B,SAAS,qBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAOiD;AAC/C,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,QAAQ,WAAW,GACtD,WAAW,MAAM,OAAY,KAAK,GAClC,WAAW,aAAa,eAAe,SAAS,QAChD,QAAQ,WAAW,OAAO,OAC1B,iBAAa,2BAAS,YAAY,IAAI,GAEtC,eAAe,aAAa,0CAAkB;AAEpD,QAAM,UAAU,MAAM;AACpB,IAAI,SAAS,WACb,SAAS,UAAU,MACnB,aAAa,MAAM;AACjB,eAAS,IAAI;AAAA,IACf,CAAC;AAAA,EACH,GAAG,CAAC,IAAI,CAAC,GAET,MAAM,UAAU,MAAM;AACpB,IAAI,YACA,UAAU,SAAS,YACrB,SAAS,UAAU,OACnB,WAAW,KAAK;AAAA,EAEpB,GAAG,CAAC,YAAY,OAAO,QAAQ,CAAC;AAEhC,QAAM,aAAS,2BAAS,CAAC,SAAS;AAChC,QAAI;AACJ,UAAI,UAAU;AACZ,cAAM,YAAY,OAAO,QAAS,aAAa,KAAK,SAAS,OAAO,IAAI;AACxE,mBAAW,SAAS;AAAA,MACtB;AACE,qBAAa,MAAM;AACjB,mBAAS,IAAI;AAAA,QACf,CAAC;AAAA,EAEL,CAAC;AAED,SAAO,CAAC,OAAY,MAAM;AAC5B;AAEA,MAAM,OAAO,MAAM;AAAC;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { useEvent } from "@tamagui/use-event";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { startTransition } from "@tamagui/start-transition";
|
|
4
|
-
const emptyCallbackFn = (_) => _();
|
|
5
|
-
function useControllableState({
|
|
6
|
-
prop,
|
|
7
|
-
defaultProp,
|
|
8
|
-
onChange,
|
|
9
|
-
strategy = "prop-wins",
|
|
10
|
-
preventUpdate,
|
|
11
|
-
transition
|
|
12
|
-
}) {
|
|
13
|
-
const [state, setState] = React.useState(prop ?? defaultProp), previous = React.useRef(state), propWins = strategy === "prop-wins" && prop !== void 0, value = propWins ? prop : state, onChangeCb = useEvent(onChange || idFn), transitionFn = transition ? startTransition : emptyCallbackFn;
|
|
14
|
-
React.useEffect(() => {
|
|
15
|
-
prop !== void 0 && (previous.current = prop, transitionFn(() => {
|
|
16
|
-
setState(prop);
|
|
17
|
-
}));
|
|
18
|
-
}, [prop]), React.useEffect(() => {
|
|
19
|
-
propWins || state !== previous.current && (previous.current = state, onChangeCb(state));
|
|
20
|
-
}, [onChangeCb, state, propWins]);
|
|
21
|
-
const setter = useEvent((next) => {
|
|
22
|
-
if (!preventUpdate)
|
|
23
|
-
if (propWins) {
|
|
24
|
-
const nextValue = typeof next == "function" ? next(previous.current) : next;
|
|
25
|
-
onChangeCb(nextValue);
|
|
26
|
-
} else
|
|
27
|
-
transitionFn(() => {
|
|
28
|
-
setState(next);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
return [value, setter];
|
|
32
|
-
}
|
|
33
|
-
const idFn = () => {
|
|
34
|
-
};
|
|
35
|
-
export {
|
|
36
|
-
useControllableState
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=useControllableState.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useControllableState.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AACvB,SAAS,uBAAuB;AAOhC,MAAM,kBAAkB,CAAC,MAAM,EAAE;AAE1B,SAAS,qBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAOiD;AAC/C,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,QAAQ,WAAW,GACtD,WAAW,MAAM,OAAY,KAAK,GAClC,WAAW,aAAa,eAAe,SAAS,QAChD,QAAQ,WAAW,OAAO,OAC1B,aAAa,SAAS,YAAY,IAAI,GAEtC,eAAe,aAAa,kBAAkB;AAEpD,QAAM,UAAU,MAAM;AACpB,IAAI,SAAS,WACb,SAAS,UAAU,MACnB,aAAa,MAAM;AACjB,eAAS,IAAI;AAAA,IACf,CAAC;AAAA,EACH,GAAG,CAAC,IAAI,CAAC,GAET,MAAM,UAAU,MAAM;AACpB,IAAI,YACA,UAAU,SAAS,YACrB,SAAS,UAAU,OACnB,WAAW,KAAK;AAAA,EAEpB,GAAG,CAAC,YAAY,OAAO,QAAQ,CAAC;AAEhC,QAAM,SAAS,SAAS,CAAC,SAAS;AAChC,QAAI;AACJ,UAAI,UAAU;AACZ,cAAM,YAAY,OAAO,QAAS,aAAa,KAAK,SAAS,OAAO,IAAI;AACxE,mBAAW,SAAS;AAAA,MACtB;AACE,qBAAa,MAAM;AACjB,mBAAS,IAAI;AAAA,QACf,CAAC;AAAA,EAEL,CAAC;AAED,SAAO,CAAC,OAAY,MAAM;AAC5B;AAEA,MAAM,OAAO,MAAM;AAAC;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|