@tamagui/use-event 1.0.1-beta.101

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,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var src_exports = {};
16
+ module.exports = __toCommonJS(src_exports);
17
+ __reExport(src_exports, require("./useEvent"), module.exports);
18
+ __reExport(src_exports, require("./useGet"), module.exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './useEvent'\nexport * from './useGet'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,uBAAd;AACA,wBAAc,qBADd;",
6
+ "names": []
7
+ }
@@ -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)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var useEvent_exports = {};
19
+ __export(useEvent_exports, {
20
+ useEvent: () => useEvent
21
+ });
22
+ module.exports = __toCommonJS(useEvent_exports);
23
+ var import_useGet = require("./useGet");
24
+ function useEvent(callback) {
25
+ return (0, import_useGet.useGet)(callback, defaultValue, true);
26
+ }
27
+ const defaultValue = () => {
28
+ throw new Error("Cannot call an event handler while rendering.");
29
+ };
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ useEvent
33
+ });
34
+ //# sourceMappingURL=useEvent.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useEvent.ts"],
4
+ "sourcesContent": ["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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAIhB,kBAAyC,UAAiB;AAC/D,SAAO,0BAAO,UAAU,cAAc,IAAI;AAC5C;AAEA,MAAM,eAAe,MAAM;AACzB,QAAM,IAAI,MAAM,+CAA+C;AACjE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,41 @@
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)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var useGet_exports = {};
19
+ __export(useGet_exports, {
20
+ useGet: () => useGet
21
+ });
22
+ module.exports = __toCommonJS(useGet_exports);
23
+ var import_react = require("react");
24
+ const isWeb = process.env.TAMAGUI_TARGET === "web";
25
+ const isClient = typeof window !== "undefined";
26
+ const useIsomorphicLayoutEffect = !isWeb || isClient ? import_react.useLayoutEffect : import_react.useEffect;
27
+ function useGet(currentValue, initialValue, forwardToFunction) {
28
+ const curRef = (0, import_react.useRef)(initialValue ?? currentValue);
29
+ useIsomorphicLayoutEffect(() => {
30
+ curRef.current = currentValue;
31
+ });
32
+ return (0, import_react.useCallback)(forwardToFunction ? (...args) => {
33
+ var _a;
34
+ return (_a = curRef.current) == null ? void 0 : _a.apply(null, args);
35
+ } : () => curRef.current, []);
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ useGet
40
+ });
41
+ //# sourceMappingURL=useGet.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useGet.ts"],
4
+ "sourcesContent": ["import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'\n\nconst isWeb = process.env.TAMAGUI_TARGET === 'web'\nconst isClient = typeof window !== 'undefined'\nconst useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect\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 = useRef<any>(initialValue ?? currentValue)\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useCallback(\n forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,\n []\n )\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgE;AAEhE,MAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,4BAA4B,CAAC,SAAS,WAAW,+BAAkB;AAIlE,gBACL,cACA,cACA,mBACS;AACT,QAAM,SAAS,yBAAY,gBAAgB,YAAY;AACvD,4BAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC;AAED,SAAO,8BACL,oBAAoB,IAAI,SAAM;AAnBlC;AAmBqC,wBAAO,YAAP,mBAAgB,MAAM,MAAM;AAAA,MAAQ,MAAM,OAAO,SAClF,CAAC,CACH;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./useEvent";
2
+ export * from "./useGet";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './useEvent'\nexport * from './useGet'\n"],
5
+ "mappings": "AAAA;AACA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,11 @@
1
+ import { useGet } from "./useGet";
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 {
9
+ useEvent
10
+ };
11
+ //# sourceMappingURL=useEvent.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useEvent.ts"],
4
+ "sourcesContent": ["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"],
5
+ "mappings": "AAAA;AAIO,kBAAyC,UAAiB;AAC/D,SAAO,OAAO,UAAU,cAAc,IAAI;AAC5C;AAEA,MAAM,eAAe,MAAM;AACzB,QAAM,IAAI,MAAM,+CAA+C;AACjE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
2
+ const isWeb = process.env.TAMAGUI_TARGET === "web";
3
+ const isClient = typeof window !== "undefined";
4
+ const useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect;
5
+ function useGet(currentValue, initialValue, forwardToFunction) {
6
+ const curRef = useRef(initialValue ?? currentValue);
7
+ useIsomorphicLayoutEffect(() => {
8
+ curRef.current = currentValue;
9
+ });
10
+ return useCallback(forwardToFunction ? (...args) => {
11
+ var _a;
12
+ return (_a = curRef.current) == null ? void 0 : _a.apply(null, args);
13
+ } : () => curRef.current, []);
14
+ }
15
+ export {
16
+ useGet
17
+ };
18
+ //# sourceMappingURL=useGet.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useGet.ts"],
4
+ "sourcesContent": ["import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'\n\nconst isWeb = process.env.TAMAGUI_TARGET === 'web'\nconst isClient = typeof window !== 'undefined'\nconst useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect\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 = useRef<any>(initialValue ?? currentValue)\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useCallback(\n forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,\n []\n )\n}\n"],
5
+ "mappings": "AAAA;AAEA,MAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,4BAA4B,CAAC,SAAS,WAAW,kBAAkB;AAIlE,gBACL,cACA,cACA,mBACS;AACT,QAAM,SAAS,OAAY,gBAAgB,YAAY;AACvD,4BAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC;AAED,SAAO,YACL,oBAAoB,IAAI,SAAM;AAnBlC;AAmBqC,wBAAO,YAAP,mBAAgB,MAAM,MAAM;AAAA,MAAQ,MAAM,OAAO,SAClF,CAAC,CACH;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./useEvent";
2
+ export * from "./useGet";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './useEvent'\nexport * from './useGet'\n"],
5
+ "mappings": "AAAA;AACA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,11 @@
1
+ import { useGet } from "./useGet";
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 {
9
+ useEvent
10
+ };
11
+ //# sourceMappingURL=useEvent.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useEvent.ts"],
4
+ "sourcesContent": ["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"],
5
+ "mappings": "AAAA;AAIO,kBAAyC,UAAiB;AAC/D,SAAO,OAAO,UAAU,cAAc,IAAI;AAC5C;AAEA,MAAM,eAAe,MAAM;AACzB,QAAM,IAAI,MAAM,+CAA+C;AACjE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
2
+ const isWeb = process.env.TAMAGUI_TARGET === "web";
3
+ const isClient = typeof window !== "undefined";
4
+ const useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect;
5
+ function useGet(currentValue, initialValue, forwardToFunction) {
6
+ const curRef = useRef(initialValue != null ? initialValue : currentValue);
7
+ useIsomorphicLayoutEffect(() => {
8
+ curRef.current = currentValue;
9
+ });
10
+ return useCallback(forwardToFunction ? (...args) => {
11
+ var _a;
12
+ return (_a = curRef.current) == null ? void 0 : _a.apply(null, args);
13
+ } : () => curRef.current, []);
14
+ }
15
+ export {
16
+ useGet
17
+ };
18
+ //# sourceMappingURL=useGet.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useGet.ts"],
4
+ "sourcesContent": ["import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'\n\nconst isWeb = process.env.TAMAGUI_TARGET === 'web'\nconst isClient = typeof window !== 'undefined'\nconst useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect\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 = useRef<any>(initialValue ?? currentValue)\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useCallback(\n forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,\n []\n )\n}\n"],
5
+ "mappings": "AAAA;AAEA,MAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,4BAA4B,CAAC,SAAS,WAAW,kBAAkB;AAIlE,gBACL,cACA,cACA,mBACS;AACT,QAAM,SAAS,OAAY,sCAAgB,YAAY;AACvD,4BAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC;AAED,SAAO,YACL,oBAAoB,IAAI,SAAM;AAnBlC;AAmBqC,wBAAO,YAAP,mBAAgB,MAAM,MAAM;AAAA,MAAQ,MAAM,OAAO,SAClF,CAAC,CACH;AACF;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@tamagui/use-event",
3
+ "version": "1.0.1-beta.101",
4
+ "types": "./types/index.d.ts",
5
+ "main": "dist/cjs",
6
+ "module": "dist/esm",
7
+ "module:jsx": "dist/jsx",
8
+ "files": [
9
+ "src",
10
+ "types",
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tamagui-build",
15
+ "watch": "tamagui-build --watch",
16
+ "clean": "tamagui-build clean",
17
+ "clean:build": "tamagui-build clean:build"
18
+ },
19
+ "devDependencies": {
20
+ "@tamagui/build": "^1.0.1-beta.101",
21
+ "react": "*"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "*"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }
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,23 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'
2
+
3
+ const isWeb = process.env.TAMAGUI_TARGET === 'web'
4
+ const isClient = typeof window !== 'undefined'
5
+ const useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect
6
+
7
+ // keeps a reference to the current value easily
8
+
9
+ export function useGet<A>(
10
+ currentValue: A,
11
+ initialValue?: any,
12
+ forwardToFunction?: boolean
13
+ ): () => A {
14
+ const curRef = useRef<any>(initialValue ?? currentValue)
15
+ useIsomorphicLayoutEffect(() => {
16
+ curRef.current = currentValue
17
+ })
18
+ // eslint-disable-next-line react-hooks/exhaustive-deps
19
+ return useCallback(
20
+ forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,
21
+ []
22
+ )
23
+ }
@@ -0,0 +1,3 @@
1
+ export * from './useEvent';
2
+ export * from './useGet';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
@@ -0,0 +1,4 @@
1
+ declare type AnyFunction = (...args: any[]) => any;
2
+ export declare function useEvent<T extends AnyFunction>(callback?: T): T;
3
+ export {};
4
+ //# sourceMappingURL=useEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../src/useEvent.ts"],"names":[],"mappings":"AAEA,aAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;AAE1C,wBAAgB,QAAQ,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAE/D"}
@@ -0,0 +1,2 @@
1
+ export declare function useGet<A>(currentValue: A, initialValue?: any, forwardToFunction?: boolean): () => A;
2
+ //# sourceMappingURL=useGet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGet.d.ts","sourceRoot":"","sources":["../src/useGet.ts"],"names":[],"mappings":"AAQA,wBAAgB,MAAM,CAAC,CAAC,EACtB,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,GAAG,EAClB,iBAAiB,CAAC,EAAE,OAAO,GAC1B,MAAM,CAAC,CAUT"}