@hanzogui/use-controllable-state 8.3.1 → 8.3.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,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./useControllableState.js"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyC"}
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useControllableState = useControllableState;
4
+ const tslib_1 = require("tslib");
5
+ const use_event_1 = require("@hanzogui/use-event");
6
+ const React = tslib_1.__importStar(require("react"));
7
+ const start_transition_1 = require("@hanzogui/start-transition");
8
+ const emptyCallbackFn = (_) => _();
9
+ function useControllableState({ prop, defaultProp, onChange, strategy = 'prop-wins', preventUpdate, transition, }) {
10
+ const [state, setState] = React.useState(prop ?? defaultProp);
11
+ const previous = React.useRef(state);
12
+ const propWins = strategy === 'prop-wins' && prop !== undefined;
13
+ const value = propWins ? prop : state;
14
+ const onChangeCb = (0, use_event_1.useEvent)(onChange || idFn);
15
+ const transitionFn = transition ? start_transition_1.startTransition : emptyCallbackFn;
16
+ React.useEffect(() => {
17
+ if (prop === undefined)
18
+ return;
19
+ previous.current = prop;
20
+ transitionFn(() => {
21
+ setState(prop);
22
+ });
23
+ }, [prop]);
24
+ React.useEffect(() => {
25
+ if (propWins)
26
+ return;
27
+ if (state !== previous.current) {
28
+ previous.current = state;
29
+ onChangeCb(state);
30
+ }
31
+ }, [onChangeCb, state, propWins]);
32
+ const setter = (0, use_event_1.useEvent)((next) => {
33
+ if (preventUpdate)
34
+ return;
35
+ if (propWins) {
36
+ const nextValue = typeof next === 'function' ? next(previous.current) : next;
37
+ onChangeCb(nextValue);
38
+ }
39
+ else {
40
+ transitionFn(() => {
41
+ setState(next);
42
+ });
43
+ }
44
+ });
45
+ return [value, setter];
46
+ }
47
+ const idFn = () => { };
48
+ //# sourceMappingURL=useControllableState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useControllableState.js","sourceRoot":"","sources":["../../src/useControllableState.ts"],"names":[],"mappings":";;;;AAAA,mDAA8C;AAC9C,MAAY,KAAK,0CAAa;AAC9B,iEAA4D;AAO5D,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAA;AAElC,8BAAwC,EACtC,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAQ,GAAG,WAAW,EACtB,aAAa,EACb,UAAU,GAQX;IACC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,IAAI,WAAW,CAAC,CAAA;IAC7D,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAM,KAAK,CAAC,CAAA;IACzC,MAAM,QAAQ,GAAG,QAAQ,KAAK,WAAW,IAAI,IAAI,KAAK,SAAS,CAAA;IAC/D,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;IACrC,MAAM,UAAU,GAAG,IAAA,oBAAQ,EAAC,QAAQ,IAAI,IAAI,CAAC,CAAA;IAE7C,MAAM,YAAY,GAAG,UAAU,CAAC,CAAC,CAAC,kCAAe,CAAC,CAAC,CAAC,eAAe,CAAA;IAEnE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,IAAI,KAAK,SAAS;YAAE,OAAM;QAC9B,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAA;QACvB,YAAY,CAAC,GAAG,EAAE;YAChB,QAAQ,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IAEV,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,QAAQ;YAAE,OAAM;QACpB,IAAI,KAAK,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC/B,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAA;YACxB,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;IAEjC,MAAM,MAAM,GAAG,IAAA,oBAAQ,EAAC,CAAC,IAAI,EAAE,EAAE;QAC/B,IAAI,aAAa;YAAE,OAAM;QACzB,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YAC5E,UAAU,CAAC,SAAS,CAAC,CAAA;QACvB,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,GAAG,EAAE;gBAChB,QAAQ,CAAC,IAAI,CAAC,CAAA;YAChB,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,KAAU,EAAE,MAAM,CAAC,CAAA;AAC7B,CAAC;AAED,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./useControllableState.mjs";
2
- //# sourceMappingURL=index.js.map
1
+ export * from './useControllableState.js';
2
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA"}
@@ -0,0 +1,44 @@
1
+ import { useEvent } from '@hanzogui/use-event';
2
+ import * as React from 'react';
3
+ import { startTransition } from '@hanzogui/start-transition';
4
+ const emptyCallbackFn = (_) => _();
5
+ export function useControllableState({ prop, defaultProp, onChange, strategy = 'prop-wins', preventUpdate, transition, }) {
6
+ const [state, setState] = React.useState(prop ?? defaultProp);
7
+ const previous = React.useRef(state);
8
+ const propWins = strategy === 'prop-wins' && prop !== undefined;
9
+ const value = propWins ? prop : state;
10
+ const onChangeCb = useEvent(onChange || idFn);
11
+ const transitionFn = transition ? startTransition : emptyCallbackFn;
12
+ React.useEffect(() => {
13
+ if (prop === undefined)
14
+ return;
15
+ previous.current = prop;
16
+ transitionFn(() => {
17
+ setState(prop);
18
+ });
19
+ }, [prop]);
20
+ React.useEffect(() => {
21
+ if (propWins)
22
+ return;
23
+ if (state !== previous.current) {
24
+ previous.current = state;
25
+ onChangeCb(state);
26
+ }
27
+ }, [onChangeCb, state, propWins]);
28
+ const setter = useEvent((next) => {
29
+ if (preventUpdate)
30
+ return;
31
+ if (propWins) {
32
+ const nextValue = typeof next === 'function' ? next(previous.current) : next;
33
+ onChangeCb(nextValue);
34
+ }
35
+ else {
36
+ transitionFn(() => {
37
+ setState(next);
38
+ });
39
+ }
40
+ });
41
+ return [value, setter];
42
+ }
43
+ const idFn = () => { };
44
+ //# sourceMappingURL=useControllableState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useControllableState.js","sourceRoot":"","sources":["../../src/useControllableState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAO5D,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAA;AAElC,MAAM,UAAU,oBAAoB,CAAI,EACtC,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAQ,GAAG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G,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YAC5E,UAAU,CAAC,SAAS,CAAC,CAAA;QACvB,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,GAAG,EAAE;gBAChB,QAAQ,CAAC,IAAI,CAAC,CAAA;YAChB,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,KAAU,EAAE,MAAM,CAAC,CAAA;AAC7B,CAAC;AAED,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzogui/use-controllable-state",
3
- "version": "8.3.1",
3
+ "version": "8.3.2",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "source": "src/index.ts",
6
6
  "files": [
@@ -10,39 +10,44 @@
10
10
  ],
11
11
  "type": "module",
12
12
  "sideEffects": false,
13
- "main": "dist/cjs",
14
- "module": "dist/esm",
13
+ "main": "./dist/cjs/index.js",
14
+ "module": "./dist/esm/index.js",
15
15
  "types": "./types/index.d.ts",
16
16
  "exports": {
17
17
  "./package.json": "./package.json",
18
18
  ".": {
19
19
  "types": "./types/index.d.ts",
20
- "react-native": "./dist/esm/index.native.js",
21
- "browser": "./dist/esm/index.mjs",
22
- "module": "./dist/esm/index.mjs",
23
- "import": "./dist/esm/index.mjs",
24
- "require": "./dist/cjs/index.cjs",
25
- "default": "./dist/esm/index.mjs"
20
+ "react-native": "./dist/esm/index.js",
21
+ "browser": "./dist/esm/index.js",
22
+ "module": "./dist/esm/index.js",
23
+ "import": "./dist/esm/index.js",
24
+ "require": "./dist/cjs/index.js",
25
+ "default": "./dist/esm/index.js"
26
26
  }
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
31
  "scripts": {
32
- "build": "hanzogui-build",
32
+ "build": "hanzogui-build --skip-native",
33
33
  "watch": "hanzogui-build --watch",
34
34
  "clean": "hanzogui-build clean",
35
35
  "clean:build": "hanzogui-build clean:build"
36
36
  },
37
37
  "dependencies": {
38
- "@hanzogui/start-transition": "8.3.1",
39
- "@hanzogui/use-event": "8.3.1"
38
+ "@hanzogui/start-transition": "8.3.2",
39
+ "@hanzogui/use-event": "8.3.2"
40
40
  },
41
41
  "devDependencies": {
42
- "@hanzogui/build": "8.3.1",
43
- "react": ">=19"
42
+ "@hanzogui/build": "8.3.2",
43
+ "react": "19.2.8"
44
44
  },
45
45
  "peerDependencies": {
46
- "react": ">=19"
46
+ "react": ">=19.2.8"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/hanzoai/gui.git",
51
+ "directory": "pkgs/core/use-controllable-state"
47
52
  }
48
53
  }
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * from './useControllableState'
1
+ export * from './useControllableState.ts'
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './useControllableState';
1
+ export * from './useControllableState.ts';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA"}
@@ -1,20 +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)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
- get: () => from[key],
9
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
- });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
- value: true
17
- }), mod);
18
- var index_exports = {};
19
- module.exports = __toCommonJS(index_exports);
20
- __reExport(index_exports, require("./useControllableState.cjs"), module.exports);
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
- get: () => from[key],
11
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
- });
13
- }
14
- return to;
15
- };
16
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
18
- value: true
19
- }), mod);
20
- var index_exports = {};
21
- module.exports = __toCommonJS(index_exports);
22
- __reExport(index_exports, require("./useControllableState.native.js"), module.exports);
23
- //# sourceMappingURL=index.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA","ignoreList":[]}
@@ -1,84 +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;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
34
- var useControllableState_exports = {};
35
- __export(useControllableState_exports, {
36
- useControllableState: () => useControllableState
37
- });
38
- module.exports = __toCommonJS(useControllableState_exports);
39
- var import_use_event = require("@hanzogui/use-event");
40
- var React = __toESM(require("react"), 1);
41
- var import_start_transition = require("@hanzogui/start-transition");
42
- const emptyCallbackFn = _ => _();
43
- function useControllableState({
44
- prop,
45
- defaultProp,
46
- onChange,
47
- strategy = "prop-wins",
48
- preventUpdate,
49
- transition
50
- }) {
51
- const [state, setState] = React.useState(prop ?? defaultProp);
52
- const previous = React.useRef(state);
53
- const propWins = strategy === "prop-wins" && prop !== void 0;
54
- const value = propWins ? prop : state;
55
- const onChangeCb = (0, import_use_event.useEvent)(onChange || idFn);
56
- const transitionFn = transition ? import_start_transition.startTransition : emptyCallbackFn;
57
- React.useEffect(() => {
58
- if (prop === void 0) return;
59
- previous.current = prop;
60
- transitionFn(() => {
61
- setState(prop);
62
- });
63
- }, [prop]);
64
- React.useEffect(() => {
65
- if (propWins) return;
66
- if (state !== previous.current) {
67
- previous.current = state;
68
- onChangeCb(state);
69
- }
70
- }, [onChangeCb, state, propWins]);
71
- const setter = (0, import_use_event.useEvent)(next => {
72
- if (preventUpdate) return;
73
- if (propWins) {
74
- const nextValue = typeof next === "function" ? next(previous.current) : next;
75
- onChangeCb(nextValue);
76
- } else {
77
- transitionFn(() => {
78
- setState(next);
79
- });
80
- }
81
- });
82
- return [value, setter];
83
- }
84
- const idFn = () => {};
@@ -1,90 +0,0 @@
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 __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
- get: () => from[key],
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
- value: mod,
31
- enumerable: true
32
- }) : target, mod));
33
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
- value: true
35
- }), mod);
36
- var useControllableState_exports = {};
37
- __export(useControllableState_exports, {
38
- useControllableState: () => useControllableState
39
- });
40
- module.exports = __toCommonJS(useControllableState_exports);
41
- var import_use_event = require("@hanzogui/use-event");
42
- var React = __toESM(require("react"), 1);
43
- var import_start_transition = require("@hanzogui/start-transition");
44
- var emptyCallbackFn = function (_) {
45
- return _();
46
- };
47
- function useControllableState(param) {
48
- var {
49
- prop,
50
- defaultProp,
51
- onChange,
52
- strategy = "prop-wins",
53
- preventUpdate,
54
- transition
55
- } = param;
56
- var [state, setState] = React.useState(prop !== null && prop !== void 0 ? prop : defaultProp);
57
- var previous = React.useRef(state);
58
- var propWins = strategy === "prop-wins" && prop !== void 0;
59
- var value = propWins ? prop : state;
60
- var onChangeCb = (0, import_use_event.useEvent)(onChange || idFn);
61
- var transitionFn = transition ? import_start_transition.startTransition : emptyCallbackFn;
62
- React.useEffect(function () {
63
- if (prop === void 0) return;
64
- previous.current = prop;
65
- transitionFn(function () {
66
- setState(prop);
67
- });
68
- }, [prop]);
69
- React.useEffect(function () {
70
- if (propWins) return;
71
- if (state !== previous.current) {
72
- previous.current = state;
73
- onChangeCb(state);
74
- }
75
- }, [onChangeCb, state, propWins]);
76
- var setter = (0, import_use_event.useEvent)(function (next) {
77
- if (preventUpdate) return;
78
- if (propWins) {
79
- var nextValue = typeof next === "function" ? next(previous.current) : next;
80
- onChangeCb(nextValue);
81
- } else {
82
- transitionFn(function () {
83
- setState(next);
84
- });
85
- }
86
- });
87
- return [value, setter];
88
- }
89
- var idFn = function () {};
90
- //# sourceMappingURL=useControllableState.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useControllableState_exports","__export","useControllableState","module","exports","import_use_event","require","React","__toESM","import_start_transition","emptyCallbackFn","_","param","prop","defaultProp","onChange","strategy","preventUpdate","transition","state","setState","useState","previous","useRef","propWins","onChangeCb","useEvent","idFn","transitionFn","startTransition","useEffect","current","setter","next","nextValue"],"sources":["../../src/useControllableState.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,4BAAA;AAAAC,QAAA,CAAAD,4BAAA;EAAAE,oBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAyB,CAAAK,4BAAA;AACzB,IAAAK,gBAAuB,GAAAC,OAAA;AACvB,IAAAC,KAAA,GAAAC,OAAA,CAAAF,OAAA,QAAgC;AAOhC,IAAAG,uBAAyB,GAAAH,OAAQ;AAE1B,IAAAI,eAAS,YAAAA,CAAwBC,CAAA;EACtC,OAAAA,CAAA;AAAA;AACA,SACAT,qBAAAU,KAAA;EACA;IAAAC,IAAA;IAAWC,WAAA;IAAAC,QAAA;IAAAC,QAAA;IAAAC,aAAA;IAAAC;EAAA,IAAAN,KAAA;EACX,KAAAO,KAAA,EAAAC,QAAA,IAAAb,KAAA,CAAAc,QAAA,CAAAR,IAAA,aAAAA,IAAA,cAAAA,IAAA,GAAAC,WAAA;EACA,IAAAQ,QAAA,GAAAf,KAAA,CAAAgB,MAAA,CAAAJ,KAAA;EACF,IAOiDK,QAAA,GAAAR,QAAA,oBAAAH,IAAA;EAC/C,IAAAd,KAAO,GAAAyB,QAAO,GAAQX,IAAI,GAAAM,KAAM;EAChC,IAAAM,UAAM,GAAW,IAAApB,gBAAuB,CAAAqB,QAAA,EAAAX,QAAA,IAAAY,IAAA;EACxC,IAAAC,YAAM,GAAWV,UAAA,GAAaT,uBAAwB,CAAAoB,eAAA,GAAAnB,eAAA;EACtDH,KAAA,CAAMuB,SAAQ,aAAW;IACzB,IAAMjB,IAAA,aAAa;IAEnBS,QAAM,CAAAS,OAAA,GAAelB,IAAA;IAErBe,YAAM,aAAgB;MACpBR,QAAI,CAAAP,IAAS;IACb;EACA,IACEA,IAAA,CAAa,CACf;EACFN,KAAI,CAAAuB,SAAK;IAET,IAAMN,QAAA,EAAU;IACd,IAAIL,KAAA,KAAUG,QAAA,CAAAS,OAAA;MACdT,QAAI,CAAAS,OAAU,GAAAZ,KAAS;MACrBM,UAAS,CAAAN,KAAA;IACT;EAAgB,GAClB,CACFM,UAAI,EAEJN,KAAM,EACJK,QAAI,CACJ;EACE,IAAAQ,MAAM,OAAA3B,gBAAmB,CAAAqB,QAAS,YAAaO,IAAK;IACpD,IAAAhB,aAAW;IACb,IAAAO,QAAO;MACL,IAAAU,SAAa,UAAMD,IAAA,kBAAAA,IAAA,CAAAX,QAAA,CAAAS,OAAA,IAAAE,IAAA;MACjBR,UAAA,CAASS,SAAI;IAAA,OACd;MACHN,YAAA;QACDR,QAAA,CAAAa,IAAA;MAED;IACF;EAEA;EAAoB,Q","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export * from "./useControllableState.mjs";
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export * from "./useControllableState.native.js";
2
- //# sourceMappingURL=index.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -1,48 +0,0 @@
1
- import { useEvent } from "@hanzogui/use-event";
2
- import * as React from "react";
3
- import { startTransition } from "@hanzogui/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);
14
- const previous = React.useRef(state);
15
- const propWins = strategy === "prop-wins" && prop !== void 0;
16
- const value = propWins ? prop : state;
17
- const onChangeCb = useEvent(onChange || idFn);
18
- const transitionFn = transition ? startTransition : emptyCallbackFn;
19
- React.useEffect(() => {
20
- if (prop === void 0) return;
21
- previous.current = prop;
22
- transitionFn(() => {
23
- setState(prop);
24
- });
25
- }, [prop]);
26
- React.useEffect(() => {
27
- if (propWins) return;
28
- if (state !== previous.current) {
29
- previous.current = state;
30
- onChangeCb(state);
31
- }
32
- }, [onChangeCb, state, propWins]);
33
- const setter = useEvent(next => {
34
- if (preventUpdate) return;
35
- if (propWins) {
36
- const nextValue = typeof next === "function" ? next(previous.current) : next;
37
- onChangeCb(nextValue);
38
- } else {
39
- transitionFn(() => {
40
- setState(next);
41
- });
42
- }
43
- });
44
- return [value, setter];
45
- }
46
- const idFn = () => {};
47
- export { useControllableState };
48
- //# sourceMappingURL=useControllableState.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEvent","React","startTransition","emptyCallbackFn","_","useControllableState","prop","defaultProp","onChange","strategy","preventUpdate","transition","state","setState","useState","previous","useRef","propWins","value","onChangeCb","idFn","transitionFn","useEffect","current","setter","next","nextValue"],"sources":["../../src/useControllableState.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AACzB,YAAYC,KAAA,MAAW;AACvB,SAASC,eAAA,QAAuB;AAOhC,MAAMC,eAAA,GAAmBC,CAAA,IAAMA,CAAA,CAAE;AAE1B,SAASC,qBAAwB;EACtCC,IAAA;EACAC,WAAA;EACAC,QAAA;EACAC,QAAA,GAAW;EACXC,aAAA;EACAC;AACF,GAOiD;EAC/C,MAAM,CAACC,KAAA,EAAOC,QAAQ,IAAIZ,KAAA,CAAMa,QAAA,CAASR,IAAA,IAAQC,WAAW;EAC5D,MAAMQ,QAAA,GAAWd,KAAA,CAAMe,MAAA,CAAYJ,KAAK;EACxC,MAAMK,QAAA,GAAWR,QAAA,KAAa,eAAeH,IAAA,KAAS;EACtD,MAAMY,KAAA,GAAQD,QAAA,GAAWX,IAAA,GAAOM,KAAA;EAChC,MAAMO,UAAA,GAAanB,QAAA,CAASQ,QAAA,IAAYY,IAAI;EAE5C,MAAMC,YAAA,GAAeV,UAAA,GAAaT,eAAA,GAAkBC,eAAA;EAEpDF,KAAA,CAAMqB,SAAA,CAAU,MAAM;IACpB,IAAIhB,IAAA,KAAS,QAAW;IACxBS,QAAA,CAASQ,OAAA,GAAUjB,IAAA;IACnBe,YAAA,CAAa,MAAM;MACjBR,QAAA,CAASP,IAAI;IACf,CAAC;EACH,GAAG,CAACA,IAAI,CAAC;EAETL,KAAA,CAAMqB,SAAA,CAAU,MAAM;IACpB,IAAIL,QAAA,EAAU;IACd,IAAIL,KAAA,KAAUG,QAAA,CAASQ,OAAA,EAAS;MAC9BR,QAAA,CAASQ,OAAA,GAAUX,KAAA;MACnBO,UAAA,CAAWP,KAAK;IAClB;EACF,GAAG,CAACO,UAAA,EAAYP,KAAA,EAAOK,QAAQ,CAAC;EAEhC,MAAMO,MAAA,GAASxB,QAAA,CAAUyB,IAAA,IAAS;IAChC,IAAIf,aAAA,EAAe;IACnB,IAAIO,QAAA,EAAU;MACZ,MAAMS,SAAA,GAAY,OAAOD,IAAA,KAAS,aAAaA,IAAA,CAAKV,QAAA,CAASQ,OAAO,IAAIE,IAAA;MACxEN,UAAA,CAAWO,SAAS;IACtB,OAAO;MACLL,YAAA,CAAa,MAAM;QACjBR,QAAA,CAASY,IAAI;MACf,CAAC;IACH;EACF,CAAC;EAED,OAAO,CAACP,KAAA,EAAYM,MAAM;AAC5B;AAEA,MAAMJ,IAAA,GAAOA,CAAA,KAAM,CAAC","ignoreList":[]}
@@ -1,51 +0,0 @@
1
- import { useEvent } from "@hanzogui/use-event";
2
- import * as React from "react";
3
- import { startTransition } from "@hanzogui/start-transition";
4
- var emptyCallbackFn = function (_) {
5
- return _();
6
- };
7
- function useControllableState(param) {
8
- var {
9
- prop,
10
- defaultProp,
11
- onChange,
12
- strategy = "prop-wins",
13
- preventUpdate,
14
- transition
15
- } = param;
16
- var [state, setState] = React.useState(prop !== null && prop !== void 0 ? prop : defaultProp);
17
- var previous = React.useRef(state);
18
- var propWins = strategy === "prop-wins" && prop !== void 0;
19
- var value = propWins ? prop : state;
20
- var onChangeCb = useEvent(onChange || idFn);
21
- var transitionFn = transition ? startTransition : emptyCallbackFn;
22
- React.useEffect(function () {
23
- if (prop === void 0) return;
24
- previous.current = prop;
25
- transitionFn(function () {
26
- setState(prop);
27
- });
28
- }, [prop]);
29
- React.useEffect(function () {
30
- if (propWins) return;
31
- if (state !== previous.current) {
32
- previous.current = state;
33
- onChangeCb(state);
34
- }
35
- }, [onChangeCb, state, propWins]);
36
- var setter = useEvent(function (next) {
37
- if (preventUpdate) return;
38
- if (propWins) {
39
- var nextValue = typeof next === "function" ? next(previous.current) : next;
40
- onChangeCb(nextValue);
41
- } else {
42
- transitionFn(function () {
43
- setState(next);
44
- });
45
- }
46
- });
47
- return [value, setter];
48
- }
49
- var idFn = function () {};
50
- export { useControllableState };
51
- //# sourceMappingURL=useControllableState.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEvent","React","startTransition","emptyCallbackFn","_","useControllableState","param","prop","defaultProp","onChange","strategy","preventUpdate","transition","state","setState","useState","previous","useRef","propWins","value","onChangeCb","idFn","transitionFn","useEffect","current","setter","next","nextValue"],"sources":["../../src/useControllableState.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AACzB,YAAYC,KAAA,MAAW;AACvB,SAASC,eAAA,QAAuB;AAOhC,IAAAC,eAAM,YAAAA,CAAyBC,CAAA,EAAE;EAE1B,OAASA,CAAA;AAAwB;AACtC,SACAC,qBAAAC,KAAA;EACA;IAAAC,IAAA;IAAAC,WAAA;IAAAC,QAAA;IAAAC,QAAA;IAAAC,aAAA;IAAAC;EAAA,IAAAN,KAAA;EACA,KAAAO,KAAA,EAAWC,QAAA,IAAAb,KAAA,CAAAc,QAAA,CAAAR,IAAA,aAAA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