@hanzogui/use-controllable-state 8.3.0 → 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.
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/useControllableState.js +48 -0
- package/dist/cjs/useControllableState.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useControllableState.js +44 -0
- package/dist/esm/useControllableState.js.map +1 -0
- package/package.json +15 -15
- package/src/index.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/dist/cjs/index.cjs +0 -20
- package/dist/cjs/index.native.js +0 -23
- package/dist/cjs/index.native.js.map +0 -1
- package/dist/cjs/useControllableState.cjs +0 -84
- package/dist/cjs/useControllableState.native.js +0 -90
- package/dist/cjs/useControllableState.native.js.map +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -2
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/useControllableState.mjs +0 -48
- package/dist/esm/useControllableState.mjs.map +0 -1
- package/dist/esm/useControllableState.native.js +0 -51
- package/dist/esm/useControllableState.native.js.map +0 -1
|
@@ -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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K,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
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from './useControllableState.js';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,CAA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AM;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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzogui/use-controllable-state",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.2",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -10,40 +10,40 @@
|
|
|
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.
|
|
21
|
-
"browser": "./dist/esm/index.
|
|
22
|
-
"module": "./dist/esm/index.
|
|
23
|
-
"import": "./dist/esm/index.
|
|
24
|
-
"require": "./dist/cjs/index.
|
|
25
|
-
"default": "./dist/esm/index.
|
|
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.
|
|
39
|
-
"@hanzogui/use-event": "8.3.
|
|
38
|
+
"@hanzogui/start-transition": "8.3.2",
|
|
39
|
+
"@hanzogui/use-event": "8.3.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@hanzogui/build": "8.3.
|
|
43
|
-
"react": "
|
|
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
47
|
},
|
|
48
48
|
"repository": {
|
|
49
49
|
"type": "git",
|
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
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA"}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -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);
|
package/dist/cjs/index.native.js
DELETED
|
@@ -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":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__copyProps","to","from","except","desc","key","call","get","enumerable","__reExport","target","mod","secondTarget","__toCommonJS","value","index_exports","module","exports","require"],"sources":["index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\nmodule.exports = __toCommonJS(index_exports);\n__reExport(index_exports, require(\"./useControllableState\"), module.exports);\n//# sourceMappingURL=index.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;IAClE,KAAK,IAAIG,GAAG,IAAIV,iBAAiB,CAACO,IAAI,CAAC,EACrC,IAAI,CAACL,YAAY,CAACS,IAAI,CAACL,EAAE,EAAEI,GAAG,CAAC,IAAIA,GAAG,KAAKF,MAAM,EAC/Cb,SAAS,CAACW,EAAE,EAAEI,GAAG,EAAE;MAAEE,GAAG,EAAEA,CAAA,KAAML,IAAI,CAACG,GAAG,CAAC;MAAEG,UAAU,EAAE,EAAEJ,IAAI,GAAGX,gBAAgB,CAACS,IAAI,EAAEG,GAAG,CAAC,CAAC,IAAID,IAAI,CAACI;IAAW,CAAC,CAAC;EACxH;EACA,OAAOP,EAAE;AACX,CAAC;AACD,IAAIQ,UAAU,GAAGA,CAACC,MAAM,EAAEC,GAAG,EAAEC,YAAY,MAAMZ,WAAW,CAACU,MAAM,EAAEC,GAAG,EAAE,SAAS,CAAC,EAAEC,YAAY,IAAIZ,WAAW,CAACY,YAAY,EAAED,GAAG,EAAE,SAAS,CAAC,CAAC;AAChJ,IAAIE,YAAY,GAAIF,GAAG,IAAKX,WAAW,CAACV,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE;EAAEwB,KAAK,EAAE;AAAK,CAAC,CAAC,EAAEH,GAAG,CAAC;AAC1F,IAAII,aAAa,GAAG,CAAC,CAAC;AACtBC,MAAM,CAACC,OAAO,GAAGJ,YAAY,CAACE,aAAa,CAAC;AAC5CN,UAAU,CAACM,aAAa,EAAEG,OAAO,CAAC,kCAAwB,CAAC,EAAEF,MAAM,CAACC,OAAO,CAAC","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":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","useControllableState_exports","useControllableState","module","exports","import_use_event","require","React","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":["useControllableState.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useControllableState_exports = {};\n__export(useControllableState_exports, {\n useControllableState: () => useControllableState\n});\nmodule.exports = __toCommonJS(useControllableState_exports);\nvar import_use_event = require(\"@hanzogui/use-event\");\nvar React = __toESM(require(\"react\"), 1);\nvar import_start_transition = require(\"@hanzogui/start-transition\");\nvar emptyCallbackFn = function(_) {\n return _();\n};\nfunction useControllableState(param) {\n var { prop, defaultProp, onChange, strategy = \"prop-wins\", preventUpdate, transition } = param;\n var [state, setState] = React.useState(prop !== null && prop !== void 0 ? prop : defaultProp);\n var previous = React.useRef(state);\n var propWins = strategy === \"prop-wins\" && prop !== void 0;\n var value = propWins ? prop : state;\n var onChangeCb = (0, import_use_event.useEvent)(onChange || idFn);\n var transitionFn = transition ? import_start_transition.startTransition : emptyCallbackFn;\n React.useEffect(function() {\n if (prop === void 0) return;\n previous.current = prop;\n transitionFn(function() {\n setState(prop);\n });\n }, [\n prop\n ]);\n React.useEffect(function() {\n if (propWins) return;\n if (state !== previous.current) {\n previous.current = state;\n onChangeCb(state);\n }\n }, [\n onChangeCb,\n state,\n propWins\n ]);\n var setter = (0, import_use_event.useEvent)(function(next) {\n if (preventUpdate) return;\n if (propWins) {\n var nextValue = typeof next === \"function\" ? next(previous.current) : next;\n onChangeCb(nextValue);\n } else {\n transitionFn(function() {\n setState(next);\n });\n }\n });\n return [\n value,\n setter\n ];\n}\nvar idFn = function() {\n};\n//# sourceMappingURL=useContro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;IACvB,CAAC,MAAM;MACLN,YAAY,CAAC,YAAW;QACtBR,QAAQ,CAACa,IAAI,CAAC;MAChB,CAAC,CAAC;IACJ;EACF,CAAC,CAAC;EACF,OAAO,CACLjC,KAAK,EACLgC,MAAM,CACP;AACH;AACA,IAAIL,IAAI,GAAG,SAAAA,CAAA,EAAW,CACtB,CAAC","ignoreList":[]}
|
package/dist/esm/index.mjs
DELETED
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/esm/index.native.js
DELETED
|
@@ -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,aAAAA,IAAA,cAAAA,IAAA,GAAAC,WAAA;EACX,IAAAQ,QAAA,GAAAf,KAAA,CAAAgB,MAAA,CAAAJ,KAAA;EACA,IAAAK,QAAA,GAAAR,QAAA,oBAAAH,IAAA;EACF,IAOiDY,KAAA,GAAAD,QAAA,GAAAX,IAAA,GAAAM,KAAA;EAC/C,IAAAO,UAAc,GAAApB,QAAQ,CAAIS,QAAM,IAAAY,IAAS;EACzC,IAAAC,YAAM,GAAWV,UAAM,GAAYV,eAAK,GAAAC,eAAA;EACxCF,KAAA,CAAMsB,SAAA,aAAW;IACjB,IAAMhB,IAAA,KAAQ;IACdS,QAAM,CAAAQ,OAAA,GAAajB,IAAA;IAEnBe,YAAM,aAAe;MAErBR,QAAM,CAAAP,IAAU;IACd;EACA,IACAA,IAAA,CACE;EAAaN,KACd,CAAAsB,SAAA;IACH,IAAIL,QAAK;IAET,IAAML,KAAA,KAAUG,QAAM,CAAAQ,OAAA;MACpBR,QAAI,CAAAQ,OAAU,GAAAX,KAAA;MACdO,UAAI,CAAAP,KAAU;IACZ;EACA,IACFO,UAAA,EACFP,KAAI,EAEJK,QAAM,CACJ;EACA,IAAAO,MAAI,GAAAzB,QAAU,WAAA0B,IAAA;IACZ,IAAAf,aAAM;IACN,IAAAO,Q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