@hanzogui/use-event 2.0.0-rc.41-hanzoai.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
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("./useEvent.cjs"), module.exports);
21
+ __reExport(index_exports, require("./useGet.cjs"), module.exports);
@@ -0,0 +1,24 @@
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("./useEvent.native.js"), module.exports);
23
+ __reExport(index_exports, require("./useGet.native.js"), module.exports);
24
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"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;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,wBADd,EAAAH,MAAA,CAAAC,OAAA","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var useEvent_exports = {};
24
+ __export(useEvent_exports, {
25
+ useEvent: () => useEvent
26
+ });
27
+ module.exports = __toCommonJS(useEvent_exports);
28
+ var import_useGet = require("./useGet.cjs");
29
+ function useEvent(callback) {
30
+ return (0, import_useGet.useGet)(callback, defaultValue, true);
31
+ }
32
+ const defaultValue = () => {
33
+ throw new Error("Cannot call an event handler while rendering.");
34
+ };
@@ -0,0 +1,37 @@
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 __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 __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var useEvent_exports = {};
26
+ __export(useEvent_exports, {
27
+ useEvent: () => useEvent
28
+ });
29
+ module.exports = __toCommonJS(useEvent_exports);
30
+ var import_useGet = require("./useGet.native.js");
31
+ function useEvent(callback) {
32
+ return (0, import_useGet.useGet)(callback, defaultValue, true);
33
+ }
34
+ var defaultValue = function () {
35
+ throw new Error("Cannot call an event handler while rendering.");
36
+ };
37
+ //# sourceMappingURL=useEvent.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useEvent_exports","__export","useEvent","module","exports","import_useGet","require","callback","useGet","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAuB,CAAAK,gBAAA;AAIhB,IAAAK,aAAS,GAAgCC,OAAA,CAAiB;AAC/D,SAAAJ,QAAOA,CAAAK,QAAA;EACT,WAAAF,aAAA,CAAAG,MAAA,EAAAD,QAAA,EAAAE,YAAA;AAEA;AACE,IAAAA,YAAU,GAAM,SAAAA,CAAA;EAClB,UAAAC,KAAA","ignoreList":[]}
@@ -0,0 +1,47 @@
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 useGet_exports = {};
35
+ __export(useGet_exports, {
36
+ useGet: () => useGet
37
+ });
38
+ module.exports = __toCommonJS(useGet_exports);
39
+ var React = __toESM(require("react"), 1);
40
+ const useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
41
+ function useGet(currentValue, initialValue, forwardToFunction) {
42
+ const curRef = React.useRef(initialValue ?? currentValue);
43
+ useIsomorphicInsertionEffect(() => {
44
+ curRef.current = currentValue;
45
+ });
46
+ return React.useCallback(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
47
+ }
@@ -0,0 +1,58 @@
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 useGet_exports = {};
37
+ __export(useGet_exports, {
38
+ useGet: () => useGet
39
+ });
40
+ module.exports = __toCommonJS(useGet_exports);
41
+ var React = __toESM(require("react"), 1);
42
+ var useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
43
+ function useGet(currentValue, initialValue, forwardToFunction) {
44
+ var curRef = React.useRef(initialValue !== null && initialValue !== void 0 ? initialValue : currentValue);
45
+ useIsomorphicInsertionEffect(function () {
46
+ curRef.current = currentValue;
47
+ });
48
+ return React.useCallback(forwardToFunction ? function () {
49
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
50
+ args[_key] = arguments[_key];
51
+ }
52
+ var _curRef_current;
53
+ return (_curRef_current = curRef.current) === null || _curRef_current === void 0 ? void 0 : _curRef_current.apply(null, args);
54
+ } : function () {
55
+ return curRef.current;
56
+ }, []);
57
+ }
58
+ //# sourceMappingURL=useGet.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useGet_exports","__export","useGet","module","exports","React","__toESM","require","useIsomorphicInsertionEffect","useInsertionEffect","useLayoutEffect","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,cAAA;AAAAC,QAAA,CAAAD,cAAA;EAAAE,MAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAuB,GAAAT,YAAA,CAAAK,cAAA;AAOvB,IAAAK,KAAM,GAAAC,OAAA,CAAAC,OAAA,WAA+B;AAI9B,IAAAC,4BAEL,GAAAH,KAAA,CAAAI,kBACA,IACSJ,KAAA,CAAAK,eAAA;AACT,SAAMR,OAAAS,YAAe,EAAYC,YAAA,EAAAC,iBAA4B;EAC7D,IAAAC,MAAA,GAAAT,KAAA,CAAAU,MAAA,CAAAH,YAAmC,aAAAA,YAAA,cAAAA,YAAA,GAAAD,YAAA;EACjCH,4BAAiB;IAClBM,MAAA,CAAAE,OAAA,GAAAL,YAAA;EAED;EAAa,OACXN,KAAA,CAAAY,WACI,CAAAJ,iBAAoB,eAAS;IAEjC,KAAC,IAAAK,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MACHF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IACF","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from "./useEvent.mjs";
2
+ export * from "./useGet.mjs";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from "./useEvent.mjs";
2
+ export * from "./useGet.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from "./useEvent.native.js";
2
+ export * from "./useGet.native.js";
3
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import { useGet } from "./useGet.mjs";
2
+ function useEvent(callback) {
3
+ return useGet(callback, defaultValue, true);
4
+ }
5
+ const defaultValue = () => {
6
+ throw new Error("Cannot call an event handler while rendering.");
7
+ };
8
+ export { useEvent };
9
+ //# sourceMappingURL=useEvent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,IAAI;AAC5C;AAEA,MAAMA,YAAA,GAAeA,CAAA,KAAM;EACzB,MAAM,IAAIC,KAAA,CAAM,+CAA+C;AACjE","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import { useGet } from "./useGet.native.js";
2
+ function useEvent(callback) {
3
+ return useGet(callback, defaultValue, true);
4
+ }
5
+ var defaultValue = function () {
6
+ throw new Error("Cannot call an event handler while rendering.");
7
+ };
8
+ export { useEvent };
9
+ //# sourceMappingURL=useEvent.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,IAAI;AAC5C;AAEA,IAAAA,YAAM,YAAAA,CAAA,EAAqB;EACzB,MAAM,IAAIC,KAAA,CAAM,+CAA+C;AACjE","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ const useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
3
+ function useGet(currentValue, initialValue, forwardToFunction) {
4
+ const curRef = React.useRef(initialValue ?? currentValue);
5
+ useIsomorphicInsertionEffect(() => {
6
+ curRef.current = currentValue;
7
+ });
8
+ return React.useCallback(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
9
+ }
10
+ export { useGet };
11
+ //# sourceMappingURL=useGet.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useIsomorphicInsertionEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","args","apply"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAOvB,MAAMC,4BAAA,GAA+BD,KAAA,CAAME,kBAAA,IAAsBF,KAAA,CAAMG,eAAA;AAIhE,SAASC,OACdC,YAAA,EACAC,YAAA,EACAC,iBAAA,EACS;EACT,MAAMC,MAAA,GAASR,KAAA,CAAMS,MAAA,CAAYH,YAAA,IAAgBD,YAAY;EAC7DJ,4BAAA,CAA6B,MAAM;IACjCO,MAAA,CAAOE,OAAA,GAAUL,YAAA;EACnB,CAAC;EAED,OAAOL,KAAA,CAAMW,WAAA,CACXJ,iBAAA,GACI,IAAIK,IAAA,KAASJ,MAAA,CAAOE,OAAA,EAASG,KAAA,CAAM,MAAMD,IAAI,IAC7C,MAAMJ,MAAA,CAAOE,OAAA,EACjB,EACF;AACF","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ var useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
3
+ function useGet(currentValue, initialValue, forwardToFunction) {
4
+ var curRef = React.useRef(initialValue !== null && initialValue !== void 0 ? initialValue : currentValue);
5
+ useIsomorphicInsertionEffect(function () {
6
+ curRef.current = currentValue;
7
+ });
8
+ return React.useCallback(forwardToFunction ? function () {
9
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ args[_key] = arguments[_key];
11
+ }
12
+ var _curRef_current;
13
+ return (_curRef_current = curRef.current) === null || _curRef_current === void 0 ? void 0 : _curRef_current.apply(null, args);
14
+ } : function () {
15
+ return curRef.current;
16
+ }, []);
17
+ }
18
+ export { useGet };
19
+ //# sourceMappingURL=useGet.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useIsomorphicInsertionEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key","_curRef_current"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAOvB,IAAAC,4BAAM,GAAAD,KAA+B,CAAAE,kBAAM,IAAAF,KAAsB,CAAAG,eAAM;AAIhE,SAASC,OACdC,YAAA,EACAC,YAAA,EACAC,iBAAA,EACS;EACT,IAAAC,MAAM,GAAAR,KAAS,CAAAS,MAAM,CAAAH,YAAY,SAAgB,IAAAA,YAAY,cAAAA,YAAA,GAAAD,YAAA;EAC7DJ,4BAAA,CAA6B,YAAM;IACjCO,MAAA,CAAOE,OAAA,GAAUL,YAAA;EACnB,CAAC;EAED,OAAOL,KAAA,CAAMW,WAAA,CAAAJ,iBAAA;IACX,SAAAK,IAAA,GAAAC,SACQ,CAAAC,MAAA,EAASC,IAAA,GAAO,IAAAC,KAAS,CAAAJ,IAAM,GAAAK,IAAM,GAAI,GAAAA,IAC7C,GAAML,IAAA,EAAAK,IAAO;MAChBF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IACH;IACF,IAAAC,eAAA","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@hanzogui/use-event",
3
+ "version": "2.0.0-rc.41-hanzoai.5",
4
+ "files": [
5
+ "src",
6
+ "types",
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "sideEffects": false,
11
+ "main": "dist/cjs",
12
+ "module": "dist/esm",
13
+ "types": "./types/index.d.ts",
14
+ "exports": {
15
+ "./package.json": "./package.json",
16
+ ".": {
17
+ "types": "./types/index.d.ts",
18
+ "react-native": "./dist/esm/index.native.js",
19
+ "browser": "./dist/esm/index.mjs",
20
+ "module": "./dist/esm/index.mjs",
21
+ "import": "./dist/esm/index.mjs",
22
+ "require": "./dist/cjs/index.cjs",
23
+ "default": "./dist/esm/index.mjs"
24
+ }
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build": "hanzogui-build",
31
+ "watch": "hanzogui-build --watch",
32
+ "clean": "hanzogui-build clean",
33
+ "clean:build": "hanzogui-build clean:build"
34
+ },
35
+ "dependencies": {},
36
+ "devDependencies": {
37
+ "@hanzogui/build": "2.0.0-rc.41-hanzoai.5",
38
+ "react": ">=19"
39
+ },
40
+ "peerDependencies": {
41
+ "react": ">=19"
42
+ }
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './useEvent'
2
+ export * from './useGet'
@@ -0,0 +1,11 @@
1
+ import { useGet } from './useGet'
2
+
3
+ type AnyFunction = (...args: any[]) => any
4
+
5
+ export function useEvent<T extends AnyFunction>(callback?: T): T {
6
+ return useGet(callback, defaultValue, true) as T
7
+ }
8
+
9
+ const defaultValue = () => {
10
+ throw new Error('Cannot call an event handler while rendering.')
11
+ }
package/src/useGet.ts ADDED
@@ -0,0 +1,28 @@
1
+ import * as React from 'react'
2
+
3
+ // useInsertionEffect ensures the ref is updated before any useLayoutEffect
4
+ // reads the returned callback — fixes a React 19 timing issue where a
5
+ // consumer's useLayoutEffect could fire before this ref update, causing stale
6
+ // values. Falls back to useLayoutEffect for React < 18.3. No SSR branch: SSR
7
+ // doesn't run layout effects, so the non-SSR path is correct everywhere.
8
+ const useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect
9
+
10
+ // keeps a reference to the current value easily
11
+
12
+ export function useGet<A>(
13
+ currentValue: A,
14
+ initialValue?: any,
15
+ forwardToFunction?: boolean
16
+ ): () => A {
17
+ const curRef = React.useRef<any>(initialValue ?? currentValue)
18
+ useIsomorphicInsertionEffect(() => {
19
+ curRef.current = currentValue
20
+ })
21
+
22
+ return React.useCallback(
23
+ forwardToFunction
24
+ ? (...args) => curRef.current?.apply(null, args)
25
+ : () => curRef.current,
26
+ []
27
+ )
28
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./useEvent";
2
+ export * from "./useGet";
3
+
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAAA,cAAc;AACd,cAAc",
3
+ "names": [],
4
+ "sources": [
5
+ "src/index.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "export * from './useEvent'\nexport * from './useGet'\n"
10
+ ]
11
+ }
@@ -0,0 +1,5 @@
1
+ type AnyFunction = (...args: any[]) => any;
2
+ export declare function useEvent<T extends AnyFunction>(callback?: T): T;
3
+ export {};
4
+
5
+ //# sourceMappingURL=useEvent.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "KAEK,eAAe,GAAG;AAEvB,OAAO,iBAAS,SAAS,UAAU,aAAa,WAAW,IAAI",
3
+ "names": [],
4
+ "sources": [
5
+ "src/useEvent.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import { useGet } from './useGet'\n\ntype AnyFunction = (...args: any[]) => any\n\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T\n}\n\nconst defaultValue = () => {\n throw new Error('Cannot call an event handler while rendering.')\n}\n"
10
+ ]
11
+ }
@@ -0,0 +1,3 @@
1
+ export declare function useGet<A>(currentValue: A, initialValue?: any, forwardToFunction?: boolean): () => A;
2
+
3
+ //# sourceMappingURL=useGet.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAWA,OAAO,iBAAS,OAAO,GACrB,cAAc,GACd,oBACA,oCACO",
3
+ "names": [],
4
+ "sources": [
5
+ "src/useGet.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import * as React from 'react'\n\n// useInsertionEffect ensures the ref is updated before any useLayoutEffect\n// reads the returned callback — fixes a React 19 timing issue where a\n// consumer's useLayoutEffect could fire before this ref update, causing stale\n// values. Falls back to useLayoutEffect for React < 18.3. No SSR branch: SSR\n// doesn't run layout effects, so the non-SSR path is correct everywhere.\nconst useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect\n\n// keeps a reference to the current value easily\n\nexport function useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = React.useRef<any>(initialValue ?? currentValue)\n useIsomorphicInsertionEffect(() => {\n curRef.current = currentValue\n })\n\n return React.useCallback(\n forwardToFunction\n ? (...args) => curRef.current?.apply(null, args)\n : () => curRef.current,\n []\n )\n}\n"
10
+ ]
11
+ }