matsuri-hooks 2.0.1 → 2.0.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/cjs/index.js +0 -12
- package/cjs/index.js.map +1 -1
- package/cjs/useAuth.js +0 -6
- package/cjs/useAuth.js.map +1 -1
- package/cjs/useClipboardCopy.js +0 -8
- package/cjs/useClipboardCopy.js.map +1 -1
- package/cjs/useFetch.js +8 -27
- package/cjs/useFetch.js.map +1 -1
- package/cjs/useIntersectionObserver.js +2 -9
- package/cjs/useIntersectionObserver.js.map +1 -1
- package/cjs/useKeyboardShortcut.js +0 -5
- package/cjs/useKeyboardShortcut.js.map +1 -1
- package/cjs/useOnClickOutside.js +2 -10
- package/cjs/useOnClickOutside.js.map +1 -1
- package/cjs/utils/isBrowser.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/useAuth.js +0 -2
- package/esm/useAuth.js.map +1 -1
- package/esm/useClipboardCopy.js +4 -12
- package/esm/useClipboardCopy.js.map +1 -1
- package/esm/useFetch.js +4 -21
- package/esm/useFetch.js.map +1 -1
- package/esm/useIntersectionObserver.js +2 -8
- package/esm/useIntersectionObserver.js.map +1 -1
- package/esm/useKeyboardShortcut.js +0 -2
- package/esm/useKeyboardShortcut.js.map +1 -1
- package/esm/useOnClickOutside.js +2 -6
- package/esm/useOnClickOutside.js.map +1 -1
- package/esm/utils/isBrowser.js.map +1 -1
- package/index.js.map +1 -1
- package/package.json +9 -9
- package/useAuth.js +0 -2
- package/useAuth.js.map +1 -1
- package/useClipboardCopy.js +4 -12
- package/useClipboardCopy.js.map +1 -1
- package/useFetch.js +4 -21
- package/useFetch.js.map +1 -1
- package/useIntersectionObserver.js +2 -8
- package/useIntersectionObserver.js.map +1 -1
- package/useKeyboardShortcut.js +0 -2
- package/useKeyboardShortcut.js.map +1 -1
- package/useOnClickOutside.js +2 -6
- package/useOnClickOutside.js.map +1 -1
- package/utils/isBrowser.js.map +1 -1
package/cjs/index.js
CHANGED
|
@@ -1,49 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
|
|
5
4
|
var _useOnClickOutside = require("./useOnClickOutside");
|
|
6
|
-
|
|
7
5
|
Object.keys(_useOnClickOutside).forEach(function (key) {
|
|
8
6
|
if (key === "default" || key === "__esModule") return;
|
|
9
7
|
if (key in exports && exports[key] === _useOnClickOutside[key]) return;
|
|
10
8
|
exports[key] = _useOnClickOutside[key];
|
|
11
9
|
});
|
|
12
|
-
|
|
13
10
|
var _useAuth = require("./useAuth");
|
|
14
|
-
|
|
15
11
|
Object.keys(_useAuth).forEach(function (key) {
|
|
16
12
|
if (key === "default" || key === "__esModule") return;
|
|
17
13
|
if (key in exports && exports[key] === _useAuth[key]) return;
|
|
18
14
|
exports[key] = _useAuth[key];
|
|
19
15
|
});
|
|
20
|
-
|
|
21
16
|
var _useFetch = require("./useFetch");
|
|
22
|
-
|
|
23
17
|
Object.keys(_useFetch).forEach(function (key) {
|
|
24
18
|
if (key === "default" || key === "__esModule") return;
|
|
25
19
|
if (key in exports && exports[key] === _useFetch[key]) return;
|
|
26
20
|
exports[key] = _useFetch[key];
|
|
27
21
|
});
|
|
28
|
-
|
|
29
22
|
var _useIntersectionObserver = require("./useIntersectionObserver");
|
|
30
|
-
|
|
31
23
|
Object.keys(_useIntersectionObserver).forEach(function (key) {
|
|
32
24
|
if (key === "default" || key === "__esModule") return;
|
|
33
25
|
if (key in exports && exports[key] === _useIntersectionObserver[key]) return;
|
|
34
26
|
exports[key] = _useIntersectionObserver[key];
|
|
35
27
|
});
|
|
36
|
-
|
|
37
28
|
var _useClipboardCopy = require("./useClipboardCopy");
|
|
38
|
-
|
|
39
29
|
Object.keys(_useClipboardCopy).forEach(function (key) {
|
|
40
30
|
if (key === "default" || key === "__esModule") return;
|
|
41
31
|
if (key in exports && exports[key] === _useClipboardCopy[key]) return;
|
|
42
32
|
exports[key] = _useClipboardCopy[key];
|
|
43
33
|
});
|
|
44
|
-
|
|
45
34
|
var _useKeyboardShortcut = require("./useKeyboardShortcut");
|
|
46
|
-
|
|
47
35
|
Object.keys(_useKeyboardShortcut).forEach(function (key) {
|
|
48
36
|
if (key === "default" || key === "__esModule") return;
|
|
49
37
|
if (key in exports && exports[key] === _useKeyboardShortcut[key]) return;
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./useOnClickOutside\"\nexport * from \"./useAuth\"\nexport * from \"./useFetch\"\nexport * from \"./useIntersectionObserver\"\nexport * from \"./useClipboardCopy\"\nexport * from \"./useKeyboardShortcut\"\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_useOnClickOutside","require","Object","keys","forEach","key","exports","_useAuth","_useFetch","_useIntersectionObserver","_useClipboardCopy","_useKeyboardShortcut"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./useOnClickOutside\"\nexport * from \"./useAuth\"\nexport * from \"./useFetch\"\nexport * from \"./useIntersectionObserver\"\nexport * from \"./useClipboardCopy\"\nexport * from \"./useKeyboardShortcut\"\n"],"mappings":";;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,kBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,kBAAA,CAAAK,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAL,kBAAA,CAAAK,GAAA;AAAA;AACA,IAAAE,QAAA,GAAAN,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAI,QAAA,EAAAH,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAE,QAAA,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 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.useAuth = exports.tokenStorageApiWithLocalStorage = exports.checkJwtExpiration = void 0;
|
|
5
|
-
|
|
6
5
|
var _react = require("react");
|
|
7
|
-
|
|
8
6
|
const checkJwtExpiration = jwt => {
|
|
9
7
|
const splitted = jwt.split(".");
|
|
10
8
|
if (splitted.length !== 3) return false;
|
|
@@ -12,7 +10,6 @@ const checkJwtExpiration = jwt => {
|
|
|
12
10
|
const exp = JSON.parse(atob(payload))["exp"];
|
|
13
11
|
return new Date() < new Date(exp * 1000);
|
|
14
12
|
};
|
|
15
|
-
|
|
16
13
|
exports.checkJwtExpiration = checkJwtExpiration;
|
|
17
14
|
const tokenStorageApiWithLocalStorage = {
|
|
18
15
|
setToken: token => {
|
|
@@ -27,7 +24,6 @@ const tokenStorageApiWithLocalStorage = {
|
|
|
27
24
|
};
|
|
28
25
|
exports.tokenStorageApiWithLocalStorage = tokenStorageApiWithLocalStorage;
|
|
29
26
|
let tokenCache = null;
|
|
30
|
-
|
|
31
27
|
const useAuth = option => {
|
|
32
28
|
const tokenStorageApi = option?.tokenStorageApi ?? tokenStorageApiWithLocalStorage;
|
|
33
29
|
const jwtExpirationChecker = option?.jwtExpirationChecker ?? checkJwtExpiration;
|
|
@@ -36,7 +32,6 @@ const useAuth = option => {
|
|
|
36
32
|
const [authenticated, setAuthenticated] = (0, _react.useState)(!!tokenCache);
|
|
37
33
|
const tryCheckAuth = (0, _react.useCallback)(() => {
|
|
38
34
|
const authToken = tokenStorageApi.getToken();
|
|
39
|
-
|
|
40
35
|
if (!(authToken && jwtExpirationChecker(authToken))) {
|
|
41
36
|
tokenStorageApi.clearToken();
|
|
42
37
|
setToken("");
|
|
@@ -65,6 +60,5 @@ const useAuth = option => {
|
|
|
65
60
|
signout
|
|
66
61
|
};
|
|
67
62
|
};
|
|
68
|
-
|
|
69
63
|
exports.useAuth = useAuth;
|
|
70
64
|
//# sourceMappingURL=useAuth.js.map
|
package/cjs/useAuth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.js","names":["checkJwtExpiration","jwt","splitted","split","length","payload","exp","JSON","parse","atob","Date","tokenStorageApiWithLocalStorage","setToken","token","localStorage","setItem","getToken","getItem","clearToken","removeItem","tokenCache","useAuth","option","tokenStorageApi","jwtExpirationChecker","useState","authenticated","setAuthenticated","tryCheckAuth","useCallback","authToken","useEffect","signin","signout"],"sources":["../../src/useAuth.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\"\n\nexport const checkJwtExpiration = (jwt: string): boolean => {\n const splitted = jwt.split(\".\")\n if (splitted.length !== 3) return false\n\n const [, payload] = splitted\n const exp = JSON.parse(atob(payload))[\"exp\"]\n return new Date() < new Date(exp * 1000)\n}\n\nexport interface TokenStorageApi {\n setToken: (token: string) => void\n getToken: () => string | null\n clearToken: () => void\n}\n\nexport const tokenStorageApiWithLocalStorage: TokenStorageApi = {\n setToken: (token: string) => {\n return localStorage.setItem(\"auth_token\", token)\n },\n getToken: (): string | null => {\n return localStorage.getItem(\"auth_token\")\n },\n clearToken: () => {\n localStorage.removeItem(\"auth_token\")\n }\n}\n\nlet tokenCache: null | string = null\n\nexport interface UseAuthOption {\n jwtExpirationChecker?: (jwt: string) => boolean\n tokenStorageApi?: TokenStorageApi\n}\n\nexport interface UseAuthState {\n token: string\n authenticated: boolean\n signin: (token: string) => void\n signout: () => void\n}\n\nexport const useAuth = (option?: UseAuthOption): UseAuthState => {\n const tokenStorageApi = option?.tokenStorageApi ?? tokenStorageApiWithLocalStorage\n const jwtExpirationChecker = option?.jwtExpirationChecker ?? checkJwtExpiration\n\n if (!tokenCache) tokenCache = tokenStorageApi.getToken()\n const [token, setToken] = useState<string>(tokenCache || \"\")\n const [authenticated, setAuthenticated] = useState(!!tokenCache)\n\n const tryCheckAuth = useCallback(() => {\n const authToken = tokenStorageApi.getToken()\n if (!(authToken && jwtExpirationChecker(authToken))) {\n tokenStorageApi.clearToken()\n setToken(\"\")\n setAuthenticated(false)\n tokenCache = null\n } else {\n setToken(authToken)\n setAuthenticated(true)\n }\n }, [jwtExpirationChecker, tokenStorageApi])\n\n useEffect(() => {\n tryCheckAuth()\n }, [tryCheckAuth])\n\n const signin = useCallback(\n (token: string) => {\n tokenStorageApi.setToken(token)\n tryCheckAuth()\n },\n [tokenStorageApi, tryCheckAuth]\n )\n\n const signout = useCallback(() => {\n tokenStorageApi.clearToken()\n tryCheckAuth()\n }, [tokenStorageApi, tryCheckAuth])\n\n return {\n token,\n authenticated,\n signin,\n signout\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAuth.js","names":["_react","require","checkJwtExpiration","jwt","splitted","split","length","payload","exp","JSON","parse","atob","Date","exports","tokenStorageApiWithLocalStorage","setToken","token","localStorage","setItem","getToken","getItem","clearToken","removeItem","tokenCache","useAuth","option","tokenStorageApi","jwtExpirationChecker","useState","authenticated","setAuthenticated","tryCheckAuth","useCallback","authToken","useEffect","signin","signout"],"sources":["../../src/useAuth.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\"\n\nexport const checkJwtExpiration = (jwt: string): boolean => {\n const splitted = jwt.split(\".\")\n if (splitted.length !== 3) return false\n\n const [, payload] = splitted\n const exp = JSON.parse(atob(payload))[\"exp\"]\n return new Date() < new Date(exp * 1000)\n}\n\nexport interface TokenStorageApi {\n setToken: (token: string) => void\n getToken: () => string | null\n clearToken: () => void\n}\n\nexport const tokenStorageApiWithLocalStorage: TokenStorageApi = {\n setToken: (token: string) => {\n return localStorage.setItem(\"auth_token\", token)\n },\n getToken: (): string | null => {\n return localStorage.getItem(\"auth_token\")\n },\n clearToken: () => {\n localStorage.removeItem(\"auth_token\")\n }\n}\n\nlet tokenCache: null | string = null\n\nexport interface UseAuthOption {\n jwtExpirationChecker?: (jwt: string) => boolean\n tokenStorageApi?: TokenStorageApi\n}\n\nexport interface UseAuthState {\n token: string\n authenticated: boolean\n signin: (token: string) => void\n signout: () => void\n}\n\nexport const useAuth = (option?: UseAuthOption): UseAuthState => {\n const tokenStorageApi = option?.tokenStorageApi ?? tokenStorageApiWithLocalStorage\n const jwtExpirationChecker = option?.jwtExpirationChecker ?? checkJwtExpiration\n\n if (!tokenCache) tokenCache = tokenStorageApi.getToken()\n const [token, setToken] = useState<string>(tokenCache || \"\")\n const [authenticated, setAuthenticated] = useState(!!tokenCache)\n\n const tryCheckAuth = useCallback(() => {\n const authToken = tokenStorageApi.getToken()\n if (!(authToken && jwtExpirationChecker(authToken))) {\n tokenStorageApi.clearToken()\n setToken(\"\")\n setAuthenticated(false)\n tokenCache = null\n } else {\n setToken(authToken)\n setAuthenticated(true)\n }\n }, [jwtExpirationChecker, tokenStorageApi])\n\n useEffect(() => {\n tryCheckAuth()\n }, [tryCheckAuth])\n\n const signin = useCallback(\n (token: string) => {\n tokenStorageApi.setToken(token)\n tryCheckAuth()\n },\n [tokenStorageApi, tryCheckAuth]\n )\n\n const signout = useCallback(() => {\n tokenStorageApi.clearToken()\n tryCheckAuth()\n }, [tokenStorageApi, tryCheckAuth])\n\n return {\n token,\n authenticated,\n signin,\n signout\n }\n}\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEO,MAAMC,kBAAkB,GAAIC,GAAW,IAAc;EACxD,MAAMC,QAAQ,GAAGD,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC;EAC/B,IAAID,QAAQ,CAACE,MAAM,KAAK,CAAC,EAAE,OAAO,KAAK;EAEvC,MAAM,GAAGC,OAAO,CAAC,GAAGH,QAAQ;EAC5B,MAAMI,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACC,IAAI,CAACJ,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;EAC5C,OAAO,IAAIK,IAAI,CAAC,CAAC,GAAG,IAAIA,IAAI,CAACJ,GAAG,GAAG,IAAI,CAAC;AAC5C,CAAC;AAAAK,OAAA,CAAAX,kBAAA,GAAAA,kBAAA;AAQM,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C;IAC1B;EACJ,CAAC,EAAE,CAACH,oBAAoB,EAAED,eAAe,CAAC,CAAC;EAE3C,IAAAQ,gBAAS,EAAC,MAAM;IACZH,YAAY,CAAC,CAAC;EAClB,CAAC,EAAE,CAACA,YAAY,CAAC,CAAC;EAElB,MAAMI,MAAM,GAAG,IAAAH,kBAAW,EACrBhB,KAAa,IAAK;IACfU,eAAe,CAACX,QAAQ,CAACC,KAAK,CAAC;IAC/Be,YAAY,CAAC,CAAC;EAClB,CAAC,EACD,CAACL,eAAe,EAAEK,YAAY,CAClC,CAAC;EAED,MAAMK,OAAO,GAAG,IAAAJ,kBAAW,EAAC,MAAM;IAC9BN,eAAe,CAACL,UAAU,CAAC,CAAC;IAC5BU,YAAY,CAAC,CAAC;EAClB,CAAC,EAAE,CAACL,eAAe,EAAEK,YAAY,CAAC,CAAC;EAEnC,OAAO;IACHf,KAAK;IACLa,aAAa;IACbM,MAAM;IACNC;EACJ,CAAC;AACL,CAAC;AAAAvB,OAAA,CAAAW,OAAA,GAAAA,OAAA"}
|
package/cjs/useClipboardCopy.js
CHANGED
|
@@ -2,32 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.useClipboardCopy = void 0;
|
|
5
|
-
|
|
6
5
|
var _react = require("react");
|
|
7
|
-
|
|
8
6
|
var _useKeyboardShortcut = require("./useKeyboardShortcut");
|
|
9
|
-
|
|
10
7
|
const useClipboardCopy = options => {
|
|
11
8
|
const copy = (0, _react.useCallback)(async otherText => {
|
|
12
9
|
const copyText = otherText || options?.text;
|
|
13
|
-
|
|
14
10
|
if (copyText === undefined) {
|
|
15
11
|
return false;
|
|
16
12
|
}
|
|
17
|
-
|
|
18
13
|
const successed = await navigator?.clipboard?.writeText(copyText).then(() => true).catch(() => false);
|
|
19
|
-
|
|
20
14
|
if (successed) {
|
|
21
15
|
options?.onSuccess?.(copyText);
|
|
22
16
|
} else {
|
|
23
17
|
options?.onFailure?.(copyText);
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
return successed;
|
|
27
20
|
}, [options]);
|
|
28
21
|
(0, _useKeyboardShortcut.useKeyboardShortcut)(options?.key, copy);
|
|
29
22
|
return copy;
|
|
30
23
|
};
|
|
31
|
-
|
|
32
24
|
exports.useClipboardCopy = useClipboardCopy;
|
|
33
25
|
//# sourceMappingURL=useClipboardCopy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClipboardCopy.js","names":["useClipboardCopy","options","copy","useCallback","otherText","copyText","text","undefined","successed","navigator","clipboard","writeText","then","catch","onSuccess","onFailure","useKeyboardShortcut","key"],"sources":["../../src/useClipboardCopy.tsx"],"sourcesContent":["import { useCallback } from \"react\"\nimport { useKeyboardShortcut } from \"./useKeyboardShortcut\"\n\nexport const useClipboardCopy = (options?: {\n text?: string\n onSuccess?: (text: string) => void\n onFailure?: (text: string) => void\n key?: string\n}) => {\n const copy = useCallback(\n async (otherText?: string) => {\n const copyText = otherText || options?.text\n if (copyText === undefined) {\n return false\n }\n const successed = await navigator?.clipboard\n ?.writeText(copyText)\n .then(() => true)\n .catch(() => false)\n if (successed) {\n options?.onSuccess?.(copyText)\n } else {\n options?.onFailure?.(copyText)\n }\n return successed\n },\n [options]\n )\n\n useKeyboardShortcut(options?.key, copy)\n return copy\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useClipboardCopy.js","names":["_react","require","_useKeyboardShortcut","useClipboardCopy","options","copy","useCallback","otherText","copyText","text","undefined","successed","navigator","clipboard","writeText","then","catch","onSuccess","onFailure","useKeyboardShortcut","key","exports"],"sources":["../../src/useClipboardCopy.tsx"],"sourcesContent":["import { useCallback } from \"react\"\nimport { useKeyboardShortcut } from \"./useKeyboardShortcut\"\n\nexport const useClipboardCopy = (options?: {\n text?: string\n onSuccess?: (text: string) => void\n onFailure?: (text: string) => void\n key?: string\n}) => {\n const copy = useCallback(\n async (otherText?: string) => {\n const copyText = otherText || options?.text\n if (copyText === undefined) {\n return false\n }\n const successed = await navigator?.clipboard\n ?.writeText(copyText)\n .then(() => true)\n .catch(() => false)\n if (successed) {\n options?.onSuccess?.(copyText)\n } else {\n options?.onFailure?.(copyText)\n }\n return successed\n },\n [options]\n )\n\n useKeyboardShortcut(options?.key, copy)\n return copy\n}\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAEO,MAAME,gBAAgB,GAAIC,OAKhC,IAAK;EACF,MAAMC,IAAI,GAAG,IAAAC,kBAAW,EACpB,MAAOC,SAAkB,IAAK;IAC1B,MAAMC,QAAQ,GAAGD,SAAS,IAAIH,OAAO,EAAEK,IAAI;IAC3C,IAAID,QAAQ,KAAKE,SAAS,EAAE;MACxB,OAAO,KAAK;IAChB;IACA,MAAMC,SAAS,GAAG,MAAMC,SAAS,EAAEC,SAAS,EACtCC,SAAS,CAACN,QAAQ,CAAC,CACpBO,IAAI,CAAC,MAAM,IAAI,CAAC,CAChBC,KAAK,CAAC,MAAM,KAAK,CAAC;IACvB,IAAIL,SAAS,EAAE;MACXP,OAAO,EAAEa,SAAS,GAAGT,QAAQ,CAAC;IAClC,CAAC,MAAM;MACHJ,OAAO,EAAEc,SAAS,GAAGV,QAAQ,CAAC;IAClC;IACA,OAAOG,SAAS;EACpB,CAAC,EACD,CAACP,OAAO,CACZ,CAAC;EAED,IAAAe,wCAAmB,EAACf,OAAO,EAAEgB,GAAG,EAAEf,IAAI,CAAC;EACvC,OAAOA,IAAI;AACf,CAAC;AAAAgB,OAAA,CAAAlB,gBAAA,GAAAA,gBAAA"}
|
package/cjs/useFetch.js
CHANGED
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.useFetch = exports.useAuthFetch = exports.useAuthBearerFetch = exports.fetcher = exports.bearerFetcher = void 0;
|
|
5
|
-
|
|
6
5
|
var _react = require("react");
|
|
7
|
-
|
|
8
6
|
var _swr = _interopRequireDefault(require("swr"));
|
|
9
|
-
|
|
10
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
8
|
const fetcher = async (url, options) => {
|
|
13
9
|
try {
|
|
14
10
|
return {
|
|
@@ -22,57 +18,45 @@ const fetcher = async (url, options) => {
|
|
|
22
18
|
};
|
|
23
19
|
}
|
|
24
20
|
};
|
|
25
|
-
|
|
26
21
|
exports.fetcher = fetcher;
|
|
27
|
-
|
|
28
22
|
const bearerFetcher = (token, url, options) => {
|
|
29
|
-
return fetcher(url, {
|
|
23
|
+
return fetcher(url, {
|
|
24
|
+
...options,
|
|
30
25
|
token,
|
|
31
26
|
authTokenHeader: "Authorization"
|
|
32
27
|
});
|
|
33
28
|
};
|
|
34
|
-
|
|
35
29
|
exports.bearerFetcher = bearerFetcher;
|
|
36
|
-
|
|
37
30
|
const fetcherThrows = async (url, options) => {
|
|
38
31
|
const obj = {};
|
|
39
|
-
|
|
40
32
|
if (options.token) {
|
|
41
33
|
const header = options.authTokenHeader ?? "X-Access-Token";
|
|
42
34
|
obj.headers = {
|
|
43
35
|
[header]: header === "Authorization" ? `Bearer ${options.token}` : options.token
|
|
44
36
|
};
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
if (options.method) {
|
|
48
39
|
obj.method = options.method || "GET";
|
|
49
40
|
}
|
|
50
|
-
|
|
51
41
|
const hasBody = !(options?.body === null || options?.body === undefined);
|
|
52
|
-
|
|
53
42
|
if (hasBody) {
|
|
54
43
|
obj.body = options.body;
|
|
55
44
|
}
|
|
56
|
-
|
|
57
45
|
if (hasBody && obj.method === "GET") {
|
|
58
46
|
throw new TypeError("The `GET` method cannot be used with a body");
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
obj.headers = {
|
|
62
49
|
"Content-Type": "application/json",
|
|
63
50
|
...(obj.headers ?? {})
|
|
64
51
|
};
|
|
65
52
|
const resp = await (options.fetch ?? fetch)(url, obj);
|
|
66
|
-
|
|
67
53
|
if (!resp.ok) {
|
|
68
54
|
throw new Error(`${resp.status}: ${await resp.text()}`);
|
|
69
55
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
const bodyText = await resp.text();
|
|
57
|
+
// responseが空の場合があるのでケアする
|
|
73
58
|
return bodyText && JSON.parse(bodyText);
|
|
74
59
|
};
|
|
75
|
-
|
|
76
60
|
const useFetch = (url, options) => {
|
|
77
61
|
const key = (0, _react.useMemo)(() => url ? {
|
|
78
62
|
url,
|
|
@@ -105,25 +89,22 @@ const useFetch = (url, options) => {
|
|
|
105
89
|
isValidating
|
|
106
90
|
};
|
|
107
91
|
};
|
|
108
|
-
|
|
109
92
|
exports.useFetch = useFetch;
|
|
110
|
-
|
|
111
93
|
const useAuthFetch = (token, url, options) => {
|
|
112
94
|
return useFetch(url && token ? url : null, {
|
|
113
95
|
token,
|
|
114
96
|
authTokenHeader: "X-Access-Token",
|
|
115
97
|
...options
|
|
116
98
|
});
|
|
117
|
-
};
|
|
118
|
-
|
|
99
|
+
};
|
|
119
100
|
|
|
101
|
+
// Authorization: Bearer [TOKEN]の形式でセットするuseAuthFetch
|
|
120
102
|
exports.useAuthFetch = useAuthFetch;
|
|
121
|
-
|
|
122
103
|
const useAuthBearerFetch = (token, url, options) => {
|
|
123
|
-
return useAuthFetch(token, url, {
|
|
104
|
+
return useAuthFetch(token, url, {
|
|
105
|
+
...options,
|
|
124
106
|
authTokenHeader: "Authorization"
|
|
125
107
|
});
|
|
126
108
|
};
|
|
127
|
-
|
|
128
109
|
exports.useAuthBearerFetch = useAuthBearerFetch;
|
|
129
110
|
//# sourceMappingURL=useFetch.js.map
|
package/cjs/useFetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetch.js","names":["fetcher","url","options","data","fetcherThrows","error","undefined","e","bearerFetcher","token","authTokenHeader","
|
|
1
|
+
{"version":3,"file":"useFetch.js","names":["_react","require","_swr","_interopRequireDefault","obj","__esModule","default","fetcher","url","options","data","fetcherThrows","error","undefined","e","exports","bearerFetcher","token","authTokenHeader","header","headers","method","hasBody","body","TypeError","resp","fetch","ok","Error","status","text","bodyText","JSON","parse","useFetch","key","useMemo","fetcherWrapper","mutate","isLoading","isValidating","useSWR","swrConfig","refetch","useAuthFetch","useAuthBearerFetch"],"sources":["../../src/useFetch.ts"],"sourcesContent":["import { useMemo } from \"react\"\nimport useSWR, { type KeyedMutator, type SWRConfiguration } from \"swr\"\n\nexport interface FetcherResult<T> {\n data: T | undefined\n error: Error | undefined\n}\n\nexport type AuthTokenHeader = \"Authorization\" | \"X-Access-Token\" | \"x-authorization\"\n\nexport interface FetcherOptions {\n method?: \"GET\" | \"POST\" | \"PATCH\" | \"PUT\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\"\n token?: string\n body?: RequestInit[\"body\"]\n fetch?: (info: RequestInfo, init?: RequestInit) => Promise<Response>\n authTokenHeader?: AuthTokenHeader\n}\n\nexport const fetcher = async <T>(url: string, options: FetcherOptions): Promise<FetcherResult<T>> => {\n try {\n return { data: await fetcherThrows(url, options), error: undefined }\n } catch (e) {\n return { data: undefined, error: e as unknown as Error }\n }\n}\n\nexport const bearerFetcher = <T>(token: string, url: string, options?: FetcherOptions): Promise<FetcherResult<T>> => {\n return fetcher(url, { ...options, token, authTokenHeader: \"Authorization\" })\n}\n\nconst fetcherThrows = async <T>(url: string, options: FetcherOptions): Promise<T> => {\n const obj: RequestInit = {}\n if (options.token) {\n const header = options.authTokenHeader ?? \"X-Access-Token\"\n\n obj.headers = {\n [header]: header === \"Authorization\" ? `Bearer ${options.token}` : options.token\n }\n }\n if (options.method) {\n obj.method = options.method || \"GET\"\n }\n\n const hasBody = !(options?.body === null || options?.body === undefined)\n\n if (hasBody) {\n obj.body = options.body\n }\n\n if (hasBody && obj.method === \"GET\") {\n throw new TypeError(\"The `GET` method cannot be used with a body\")\n }\n\n obj.headers = {\n \"Content-Type\": \"application/json\",\n ...(obj.headers ?? {})\n }\n\n const resp = await (options.fetch ?? fetch)(url, obj)\n\n if (!resp.ok) {\n throw new Error(`${resp.status}: ${await resp.text()}`)\n }\n\n const bodyText = await resp.text()\n // responseが空の場合があるのでケアする\n return bodyText && JSON.parse(bodyText)\n}\n\nexport interface UseFetchState<T> extends FetcherResult<T> {\n refetch: KeyedMutator<T>\n isLoading: boolean\n isValidating: boolean\n}\n\ninterface UseFetchOptions<T> extends Omit<FetcherOptions, \"fetch\"> {\n fetch?: (args: { url: string; token?: string }) => Promise<T>\n swrConfig?: Partial<SWRConfiguration>\n authTokenHeader?: AuthTokenHeader\n}\n\nexport const useFetch = <T>(url: string | null, options: UseFetchOptions<T>): UseFetchState<T> => {\n const key = useMemo(\n () =>\n url\n ? {\n url,\n token: options.token,\n body: options.body\n }\n : null,\n [options.body, options.token, url]\n )\n const fetcherWrapper = useMemo(\n () =>\n options.fetch ??\n (({ url, token }: { url: string; token?: string }) => {\n return fetcherThrows<T>(url, {\n method: options.method,\n token,\n body: options.body,\n authTokenHeader: options.authTokenHeader\n })\n }),\n [options.authTokenHeader, options.body, options.fetch, options.method]\n )\n\n const { data, error, mutate, isLoading, isValidating } = useSWR<T>(key, fetcherWrapper, options.swrConfig)\n\n return {\n data,\n error,\n refetch: mutate,\n isLoading,\n isValidating\n }\n}\n\ntype UseAuthFetchOptions<T> = Omit<UseFetchOptions<T>, \"token\">\n\nexport const useAuthFetch = <T>(\n token: string,\n url: string | null,\n options: UseAuthFetchOptions<T>\n): UseFetchState<T> => {\n return useFetch(url && token ? url : null, { token, authTokenHeader: \"X-Access-Token\", ...options })\n}\n\n// Authorization: Bearer [TOKEN]の形式でセットするuseAuthFetch\nexport const useAuthBearerFetch = <T>(\n token: string,\n url: string | null,\n options: UseAuthFetchOptions<T>\n): UseFetchState<T> => {\n return useAuthFetch(token, url, { ...options, authTokenHeader: \"Authorization\" })\n}\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAC,sBAAA,CAA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0;
|
|
5
|
-
|
|
6
5
|
var _isBrowser = require("./utils/isBrowser");
|
|
7
|
-
|
|
8
6
|
var _react = require("react");
|
|
9
|
-
|
|
10
7
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
8
|
+
|
|
11
9
|
const useIntersectionObserver = (ref, options = {}) => {
|
|
12
10
|
const [isIntersecting, setIsIntersecting] = (0, _react.useState)(false);
|
|
13
11
|
const observer = (0, _react.useRef)();
|
|
14
12
|
const disconnect = (0, _react.useCallback)(() => {
|
|
15
13
|
observer?.current?.disconnect();
|
|
16
14
|
}, []);
|
|
17
|
-
/* istanbul ignore next */
|
|
18
15
|
|
|
16
|
+
/* istanbul ignore next */
|
|
19
17
|
if (!_isBrowser.isBrowser) {
|
|
20
18
|
return {
|
|
21
19
|
isIntersecting,
|
|
22
20
|
disconnect
|
|
23
21
|
};
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
(0, _react.useEffect)(() => {
|
|
27
24
|
const element = ref.current;
|
|
28
|
-
|
|
29
25
|
if (!element) {
|
|
30
26
|
return;
|
|
31
27
|
}
|
|
32
|
-
|
|
33
28
|
observer.current = new IntersectionObserver(entries => {
|
|
34
29
|
/* istanbul ignore next */
|
|
35
30
|
if (!entries.length) {
|
|
36
31
|
return;
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
setIsIntersecting(entries[0].isIntersecting);
|
|
40
34
|
}, options);
|
|
41
35
|
observer.current.observe(element);
|
|
@@ -48,6 +42,5 @@ const useIntersectionObserver = (ref, options = {}) => {
|
|
|
48
42
|
disconnect
|
|
49
43
|
};
|
|
50
44
|
};
|
|
51
|
-
|
|
52
45
|
exports.useIntersectionObserver = useIntersectionObserver;
|
|
53
46
|
//# sourceMappingURL=useIntersectionObserver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntersectionObserver.js","names":["useIntersectionObserver","ref","options","isIntersecting","setIsIntersecting","useState","observer","useRef","disconnect","useCallback","current","isBrowser","useEffect","element","IntersectionObserver","entries","length","observe"],"sources":["../../src/useIntersectionObserver.ts"],"sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\nimport { isBrowser } from \"./utils/isBrowser\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport const useIntersectionObserver = <E extends Element = HTMLElement>(\n ref: React.RefObject<E>,\n options: IntersectionObserverInit = {}\n) => {\n const [isIntersecting, setIsIntersecting] = useState<boolean>(false);\n const observer = useRef<IntersectionObserver>()\n const disconnect = useCallback(() => {\n observer?.current?.disconnect()\n }, [])\n\n /* istanbul ignore next */\n if (!isBrowser) {\n return { isIntersecting, disconnect }\n }\n useEffect(() => {\n const element = ref.current\n if (!element) {\n return\n }\n observer.current = new IntersectionObserver((entries) => {\n /* istanbul ignore next */\n if (!entries.length) {\n return\n }\n setIsIntersecting(entries[0].isIntersecting)\n }, options)\n\n observer.current.observe(element)\n return () => {\n disconnect()\n }\n }, [disconnect, options, ref])\n \n return { isIntersecting, disconnect }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntersectionObserver.js","names":["_isBrowser","require","_react","useIntersectionObserver","ref","options","isIntersecting","setIsIntersecting","useState","observer","useRef","disconnect","useCallback","current","isBrowser","useEffect","element","IntersectionObserver","entries","length","observe","exports"],"sources":["../../src/useIntersectionObserver.ts"],"sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\nimport { isBrowser } from \"./utils/isBrowser\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport const useIntersectionObserver = <E extends Element = HTMLElement>(\n ref: React.RefObject<E>,\n options: IntersectionObserverInit = {}\n) => {\n const [isIntersecting, setIsIntersecting] = useState<boolean>(false);\n const observer = useRef<IntersectionObserver>()\n const disconnect = useCallback(() => {\n observer?.current?.disconnect()\n }, [])\n\n /* istanbul ignore next */\n if (!isBrowser) {\n return { isIntersecting, disconnect }\n }\n useEffect(() => {\n const element = ref.current\n if (!element) {\n return\n }\n observer.current = new IntersectionObserver((entries) => {\n /* istanbul ignore next */\n if (!entries.length) {\n return\n }\n setIsIntersecting(entries[0].isIntersecting)\n }, options)\n\n observer.current.observe(element)\n return () => {\n disconnect()\n }\n }, [disconnect, options, ref])\n \n return { isIntersecting, disconnect }\n}\n"],"mappings":";;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAFA;;AAIO,MAAME,uBAAuB,GAAGA,CACnCC,GAAuB,EACvBC,OAAiC,GAAG,CAAC,CAAC,KACrC;EACD,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAG,IAAAC,eAAQ,EAAU,KAAK,CAAC;EACpE,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAuB,CAAC;EAC/C,MAAMC,UAAU,GAAG,IAAAC,kBAAW,EAAC,MAAM;IACjCH,QAAQ,EAAEI,OAAO,EAAEF,UAAU,CAAC,CAAC;EACnC,CAAC,EAAE,EAAE,CAAC;;EAEN;EACA,IAAI,CAACG,oBAAS,EAAE;IACZ,OAAO;MAAER,cAAc;MAAEK;IAAW,CAAC;EACzC;EACA,IAAAI,gBAAS,EAAC,MAAM;IACZ,MAAMC,OAAO,GAAGZ,GAAG,CAACS,OAAO;IAC3B,IAAI,CAACG,OAAO,EAAE;MACV;IACJ;IACAP,QAAQ,CAACI,OAAO,GAAG,IAAII,oBAAoB,CAAEC,OAAO,IAAK;MACrD;MACA,IAAI,CAACA,OAAO,CAACC,MAAM,EAAE;QACjB;MACJ;MACAZ,iBAAiB,CAACW,OAAO,CAAC,CAAC,CAAC,CAACZ,cAAc,CAAC;IAChD,CAAC,EAAED,OAAO,CAAC;IAEXI,QAAQ,CAACI,OAAO,CAACO,OAAO,CAACJ,OAAO,CAAC;IACjC,OAAO,MAAM;MACTL,UAAU,CAAC,CAAC;IAChB,CAAC;EACL,CAAC,EAAE,CAACA,UAAU,EAAEN,OAAO,EAAED,GAAG,CAAC,CAAC;EAE9B,OAAO;IAAEE,cAAc;IAAEK;EAAW,CAAC;AACzC,CAAC;AAAAU,OAAA,CAAAlB,uBAAA,GAAAA,uBAAA"}
|
|
@@ -2,27 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.useKeyboardShortcut = void 0;
|
|
5
|
-
|
|
6
5
|
var _react = require("react");
|
|
7
|
-
|
|
8
6
|
const useKeyboardShortcut = (key, callback) => {
|
|
9
7
|
(0, _react.useEffect)(() => {
|
|
10
8
|
if (key === undefined || callback === undefined) {
|
|
11
9
|
return;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
const handler = event => {
|
|
15
12
|
if ((event.ctrlKey || event.metaKey) && event.key === key) {
|
|
16
13
|
callback();
|
|
17
14
|
}
|
|
18
15
|
};
|
|
19
|
-
|
|
20
16
|
window.addEventListener("keydown", handler);
|
|
21
17
|
return () => {
|
|
22
18
|
window.removeEventListener("keydown", handler);
|
|
23
19
|
};
|
|
24
20
|
}, [key, callback]);
|
|
25
21
|
};
|
|
26
|
-
|
|
27
22
|
exports.useKeyboardShortcut = useKeyboardShortcut;
|
|
28
23
|
//# sourceMappingURL=useKeyboardShortcut.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useKeyboardShortcut.js","names":["useKeyboardShortcut","key","callback","useEffect","undefined","handler","event","ctrlKey","metaKey","window","addEventListener","removeEventListener"],"sources":["../../src/useKeyboardShortcut.ts"],"sourcesContent":["import { useEffect } from \"react\"\n\nexport const useKeyboardShortcut = (key?: string, callback?: () => void) => {\n useEffect(() => {\n if (key === undefined || callback === undefined) {\n return\n }\n const handler = (event: KeyboardEvent) => {\n if ((event.ctrlKey || event.metaKey) && event.key === key) {\n callback()\n }\n }\n window.addEventListener(\"keydown\", handler)\n return () => {\n window.removeEventListener(\"keydown\", handler)\n }\n }, [key, callback])\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useKeyboardShortcut.js","names":["_react","require","useKeyboardShortcut","key","callback","useEffect","undefined","handler","event","ctrlKey","metaKey","window","addEventListener","removeEventListener","exports"],"sources":["../../src/useKeyboardShortcut.ts"],"sourcesContent":["import { useEffect } from \"react\"\n\nexport const useKeyboardShortcut = (key?: string, callback?: () => void) => {\n useEffect(() => {\n if (key === undefined || callback === undefined) {\n return\n }\n const handler = (event: KeyboardEvent) => {\n if ((event.ctrlKey || event.metaKey) && event.key === key) {\n callback()\n }\n }\n window.addEventListener(\"keydown\", handler)\n return () => {\n window.removeEventListener(\"keydown\", handler)\n }\n }, [key, callback])\n}\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEO,MAAMC,mBAAmB,GAAGA,CAACC,GAAY,EAAEC,QAAqB,KAAK;EACxE,IAAAC,gBAAS,EAAC,MAAM;IACZ,IAAIF,GAAG,KAAKG,SAAS,IAAIF,QAAQ,KAAKE,SAAS,EAAE;MAC7C;IACJ;IACA,MAAMC,OAAO,GAAIC,KAAoB,IAAK;MACtC,IAAI,CAACA,KAAK,CAACC,OAAO,IAAID,KAAK,CAACE,OAAO,KAAKF,KAAK,CAACL,GAAG,KAAKA,GAAG,EAAE;QACvDC,QAAQ,CAAC,CAAC;MACd;IACJ,CAAC;IACDO,MAAM,CAACC,gBAAgB,CAAC,SAAS,EAAEL,OAAO,CAAC;IAC3C,OAAO,MAAM;MACTI,MAAM,CAACE,mBAAmB,CAAC,SAAS,EAAEN,OAAO,CAAC;IAClD,CAAC;EACL,CAAC,EAAE,CAACJ,GAAG,EAAEC,QAAQ,CAAC,CAAC;AACvB,CAAC;AAAAU,OAAA,CAAAZ,mBAAA,GAAAA,mBAAA"}
|
package/cjs/useOnClickOutside.js
CHANGED
|
@@ -2,30 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.useOnClickOutside = void 0;
|
|
5
|
-
|
|
6
5
|
var _isBrowser = require("./utils/isBrowser");
|
|
7
|
-
|
|
8
6
|
var _react = require("react");
|
|
9
|
-
|
|
10
7
|
const useOnClickOutside = (ref, handler) => {
|
|
11
8
|
if (!_isBrowser.isBrowser) {
|
|
12
9
|
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
}
|
|
11
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
16
12
|
(0, _react.useEffect)(() => {
|
|
17
13
|
if (!handler) {
|
|
18
14
|
return;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
const listener = event => {
|
|
22
17
|
if (!ref.current || ref.current.contains(event.target)) {
|
|
23
18
|
return;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
handler(event);
|
|
27
21
|
};
|
|
28
|
-
|
|
29
22
|
document.addEventListener("mousedown", listener, {
|
|
30
23
|
passive: true
|
|
31
24
|
});
|
|
@@ -38,6 +31,5 @@ const useOnClickOutside = (ref, handler) => {
|
|
|
38
31
|
};
|
|
39
32
|
}, [handler, ref]);
|
|
40
33
|
};
|
|
41
|
-
|
|
42
34
|
exports.useOnClickOutside = useOnClickOutside;
|
|
43
35
|
//# sourceMappingURL=useOnClickOutside.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnClickOutside.js","names":["useOnClickOutside","ref","handler","isBrowser","useEffect","listener","event","current","contains","target","document","addEventListener","passive","removeEventListener"],"sources":["../../src/useOnClickOutside.ts"],"sourcesContent":["import { isBrowser } from \"./utils/isBrowser\"\nimport { useEffect } from \"react\"\n\nexport const useOnClickOutside = <E extends Element = HTMLElement>(\n ref: React.RefObject<E>,\n handler?: (event: MouseEvent | TouchEvent) => void\n) => {\n if (!isBrowser) {\n return\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (!handler) {\n return\n }\n const listener = (event: MouseEvent | TouchEvent) => {\n if (!ref.current || ref.current.contains(event.target as Node)) {\n return\n }\n\n handler(event)\n }\n\n document.addEventListener(\"mousedown\", listener, { passive: true })\n document.addEventListener(\"touchstart\", listener, { passive: true })\n\n return () => {\n document.removeEventListener(\"mousedown\", listener)\n document.removeEventListener(\"touchstart\", listener)\n }\n }, [handler, ref])\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useOnClickOutside.js","names":["_isBrowser","require","_react","useOnClickOutside","ref","handler","isBrowser","useEffect","listener","event","current","contains","target","document","addEventListener","passive","removeEventListener","exports"],"sources":["../../src/useOnClickOutside.ts"],"sourcesContent":["import { isBrowser } from \"./utils/isBrowser\"\nimport { useEffect } from \"react\"\n\nexport const useOnClickOutside = <E extends Element = HTMLElement>(\n ref: React.RefObject<E>,\n handler?: (event: MouseEvent | TouchEvent) => void\n) => {\n if (!isBrowser) {\n return\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (!handler) {\n return\n }\n const listener = (event: MouseEvent | TouchEvent) => {\n if (!ref.current || ref.current.contains(event.target as Node)) {\n return\n }\n\n handler(event)\n }\n\n document.addEventListener(\"mousedown\", listener, { passive: true })\n document.addEventListener(\"touchstart\", listener, { passive: true })\n\n return () => {\n document.removeEventListener(\"mousedown\", listener)\n document.removeEventListener(\"touchstart\", listener)\n }\n }, [handler, ref])\n}\n"],"mappings":";;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEO,MAAME,iBAAiB,GAAGA,CAC7BC,GAAuB,EACvBC,OAAkD,KACjD;EACD,IAAI,CAACC,oBAAS,EAAE;IACZ;EACJ;EACA;EACA,IAAAC,gBAAS,EAAC,MAAM;IACZ,IAAI,CAACF,OAAO,EAAE;MACV;IACJ;IACA,MAAMG,QAAQ,GAAIC,KAA8B,IAAK;MACjD,IAAI,CAACL,GAAG,CAACM,OAAO,IAAIN,GAAG,CAACM,OAAO,CAACC,QAAQ,CAACF,KAAK,CAACG,MAAc,CAAC,EAAE;QAC5D;MACJ;MAEAP,OAAO,CAACI,KAAK,CAAC;IAClB,CAAC;IAEDI,QAAQ,CAACC,gBAAgB,CAAC,WAAW,EAAEN,QAAQ,EAAE;MAAEO,OAAO,EAAE;IAAK,CAAC,CAAC;IACnEF,QAAQ,CAACC,gBAAgB,CAAC,YAAY,EAAEN,QAAQ,EAAE;MAAEO,OAAO,EAAE;IAAK,CAAC,CAAC;IAEpE,OAAO,MAAM;MACTF,QAAQ,CAACG,mBAAmB,CAAC,WAAW,EAAER,QAAQ,CAAC;MACnDK,QAAQ,CAACG,mBAAmB,CAAC,YAAY,EAAER,QAAQ,CAAC;IACxD,CAAC;EACL,CAAC,EAAE,CAACH,OAAO,EAAED,GAAG,CAAC,CAAC;AACtB,CAAC;AAAAa,OAAA,CAAAd,iBAAA,GAAAA,iBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isBrowser.js","names":["isBrowser","window","document"],"sources":["../../../src/utils/isBrowser.ts"],"sourcesContent":["export const isBrowser =\n typeof window !== \"undefined\" && typeof document !== \"undefined\" && window.document === document\n"],"mappings":";;;;AAAO,MAAMA,SAAS,GAClB,OAAOC,
|
|
1
|
+
{"version":3,"file":"isBrowser.js","names":["isBrowser","window","document","exports"],"sources":["../../../src/utils/isBrowser.ts"],"sourcesContent":["export const isBrowser =\n typeof window !== \"undefined\" && typeof document !== \"undefined\" && window.document === document\n"],"mappings":";;;;AAAO,MAAMA,SAAS,GAClB,OAAOC,MAAM,KAAK,WAAW,IAAI,OAAOC,QAAQ,KAAK,WAAW,IAAID,MAAM,CAACC,QAAQ,KAAKA,QAAQ;AAAAC,OAAA,CAAAH,SAAA,GAAAA,SAAA"}
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./useOnClickOutside\"\nexport * from \"./useAuth\"\nexport * from \"./useFetch\"\nexport * from \"./useIntersectionObserver\"\nexport * from \"./useClipboardCopy\"\nexport * from \"./useKeyboardShortcut\"\n"],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./useOnClickOutside\"\nexport * from \"./useAuth\"\nexport * from \"./useFetch\"\nexport * from \"./useIntersectionObserver\"\nexport * from \"./useClipboardCopy\"\nexport * from \"./useKeyboardShortcut\"\n"],"mappings":"AAAA,cAAc,qBAAqB;AACnC,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,2BAA2B;AACzC,cAAc,oBAAoB;AAClC,cAAc,uBAAuB"}
|
package/esm/useAuth.js
CHANGED
|
@@ -20,7 +20,6 @@ export var tokenStorageApiWithLocalStorage = {
|
|
|
20
20
|
var tokenCache = null;
|
|
21
21
|
export var useAuth = option => {
|
|
22
22
|
var _option$tokenStorageA, _option$jwtExpiration;
|
|
23
|
-
|
|
24
23
|
var tokenStorageApi = (_option$tokenStorageA = option == null ? void 0 : option.tokenStorageApi) != null ? _option$tokenStorageA : tokenStorageApiWithLocalStorage;
|
|
25
24
|
var jwtExpirationChecker = (_option$jwtExpiration = option == null ? void 0 : option.jwtExpirationChecker) != null ? _option$jwtExpiration : checkJwtExpiration;
|
|
26
25
|
if (!tokenCache) tokenCache = tokenStorageApi.getToken();
|
|
@@ -28,7 +27,6 @@ export var useAuth = option => {
|
|
|
28
27
|
var [authenticated, setAuthenticated] = useState(!!tokenCache);
|
|
29
28
|
var tryCheckAuth = useCallback(() => {
|
|
30
29
|
var authToken = tokenStorageApi.getToken();
|
|
31
|
-
|
|
32
30
|
if (!(authToken && jwtExpirationChecker(authToken))) {
|
|
33
31
|
tokenStorageApi.clearToken();
|
|
34
32
|
setToken("");
|
package/esm/useAuth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.js","names":["useCallback","useEffect","useState","checkJwtExpiration","jwt","splitted","split","length","payload","exp","JSON","parse","atob","Date","tokenStorageApiWithLocalStorage","setToken","token","localStorage","setItem","getToken","getItem","clearToken","removeItem","tokenCache","useAuth","option","tokenStorageApi","jwtExpirationChecker","authenticated","setAuthenticated","tryCheckAuth","authToken","signin","signout"],"sources":["../../src/useAuth.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\"\n\nexport const checkJwtExpiration = (jwt: string): boolean => {\n const splitted = jwt.split(\".\")\n if (splitted.length !== 3) return false\n\n const [, payload] = splitted\n const exp = JSON.parse(atob(payload))[\"exp\"]\n return new Date() < new Date(exp * 1000)\n}\n\nexport interface TokenStorageApi {\n setToken: (token: string) => void\n getToken: () => string | null\n clearToken: () => void\n}\n\nexport const tokenStorageApiWithLocalStorage: TokenStorageApi = {\n setToken: (token: string) => {\n return localStorage.setItem(\"auth_token\", token)\n },\n getToken: (): string | null => {\n return localStorage.getItem(\"auth_token\")\n },\n clearToken: () => {\n localStorage.removeItem(\"auth_token\")\n }\n}\n\nlet tokenCache: null | string = null\n\nexport interface UseAuthOption {\n jwtExpirationChecker?: (jwt: string) => boolean\n tokenStorageApi?: TokenStorageApi\n}\n\nexport interface UseAuthState {\n token: string\n authenticated: boolean\n signin: (token: string) => void\n signout: () => void\n}\n\nexport const useAuth = (option?: UseAuthOption): UseAuthState => {\n const tokenStorageApi = option?.tokenStorageApi ?? tokenStorageApiWithLocalStorage\n const jwtExpirationChecker = option?.jwtExpirationChecker ?? checkJwtExpiration\n\n if (!tokenCache) tokenCache = tokenStorageApi.getToken()\n const [token, setToken] = useState<string>(tokenCache || \"\")\n const [authenticated, setAuthenticated] = useState(!!tokenCache)\n\n const tryCheckAuth = useCallback(() => {\n const authToken = tokenStorageApi.getToken()\n if (!(authToken && jwtExpirationChecker(authToken))) {\n tokenStorageApi.clearToken()\n setToken(\"\")\n setAuthenticated(false)\n tokenCache = null\n } else {\n setToken(authToken)\n setAuthenticated(true)\n }\n }, [jwtExpirationChecker, tokenStorageApi])\n\n useEffect(() => {\n tryCheckAuth()\n }, [tryCheckAuth])\n\n const signin = useCallback(\n (token: string) => {\n tokenStorageApi.setToken(token)\n tryCheckAuth()\n },\n [tokenStorageApi, tryCheckAuth]\n )\n\n const signout = useCallback(() => {\n tokenStorageApi.clearToken()\n tryCheckAuth()\n }, [tokenStorageApi, tryCheckAuth])\n\n return {\n token,\n authenticated,\n signin,\n signout\n }\n}\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"useAuth.js","names":["useCallback","useEffect","useState","checkJwtExpiration","jwt","splitted","split","length","payload","exp","JSON","parse","atob","Date","tokenStorageApiWithLocalStorage","setToken","token","localStorage","setItem","getToken","getItem","clearToken","removeItem","tokenCache","useAuth","option","_option$tokenStorageA","_option$jwtExpiration","tokenStorageApi","jwtExpirationChecker","authenticated","setAuthenticated","tryCheckAuth","authToken","signin","signout"],"sources":["../../src/useAuth.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\"\n\nexport const checkJwtExpiration = (jwt: string): boolean => {\n const splitted = jwt.split(\".\")\n if (splitted.length !== 3) return false\n\n const [, payload] = splitted\n const exp = JSON.parse(atob(payload))[\"exp\"]\n return new Date() < new Date(exp * 1000)\n}\n\nexport interface TokenStorageApi {\n setToken: (token: string) => void\n getToken: () => string | null\n clearToken: () => void\n}\n\nexport const tokenStorageApiWithLocalStorage: TokenStorageApi = {\n setToken: (token: string) => {\n return localStorage.setItem(\"auth_token\", token)\n },\n getToken: (): string | null => {\n return localStorage.getItem(\"auth_token\")\n },\n clearToken: () => {\n localStorage.removeItem(\"auth_token\")\n }\n}\n\nlet tokenCache: null | string = null\n\nexport interface UseAuthOption {\n jwtExpirationChecker?: (jwt: string) => boolean\n tokenStorageApi?: TokenStorageApi\n}\n\nexport interface UseAuthState {\n token: string\n authenticated: boolean\n signin: (token: string) => void\n signout: () => void\n}\n\nexport const useAuth = (option?: UseAuthOption): UseAuthState => {\n const tokenStorageApi = option?.tokenStorageApi ?? tokenStorageApiWithLocalStorage\n const jwtExpirationChecker = option?.jwtExpirationChecker ?? checkJwtExpiration\n\n if (!tokenCache) tokenCache = tokenStorageApi.getToken()\n const [token, setToken] = useState<string>(tokenCache || \"\")\n const [authenticated, setAuthenticated] = useState(!!tokenCache)\n\n const tryCheckAuth = useCallback(() => {\n const authToken = tokenStorageApi.getToken()\n if (!(authToken && jwtExpirationChecker(authToken))) {\n tokenStorageApi.clearToken()\n setToken(\"\")\n setAuthenticated(false)\n tokenCache = null\n } else {\n setToken(authToken)\n setAuthenticated(true)\n }\n }, [jwtExpirationChecker, tokenStorageApi])\n\n useEffect(() => {\n tryCheckAuth()\n }, [tryCheckAuth])\n\n const signin = useCallback(\n (token: string) => {\n tokenStorageApi.setToken(token)\n tryCheckAuth()\n },\n [tokenStorageApi, tryCheckAuth]\n )\n\n const signout = useCallback(() => {\n tokenStorageApi.clearToken()\n tryCheckAuth()\n }, [tokenStorageApi, tryCheckAuth])\n\n return {\n token,\n authenticated,\n signin,\n signout\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExD,OAAO,IAAMC,kBAAkB,GAAIC,GAAW,IAAc;EACxD,IAAMC,QAAQ,GAAGD,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC;EAC/B,IAAID,QAAQ,CAACE,MAAM,KAAK,CAAC,EAAE,OAAO,KAAK;EAEvC,IAAM,GAAGC,OAAO,CAAC,GAAGH,QAAQ;EAC5B,IAAMI,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACC,IAAI,CAACJ,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;EAC5C,OAAO,IAAIK,IAAI,CAAC,CAAC,GAAG,IAAIA,IAAI,CAACJ,GAAG,GAAG,IAAI,CAAC;AAC5C,CAAC;AAQD,OAAO,IAAMK,+BAAgD,GAAG;EAC5DC,QAAQ,EAAGC,KAAa,IAAK;IACzB,OAAOC,YAAY,CAACC,OAAO,CAAC,YAAY,EAAEF,KAAK,CAAC;EACpD,CAAC;EACDG,QAAQ,EAAEA,CAAA,KAAqB;IAC3B,OAAOF,YAAY,CAACG,OAAO,CAAC,YAAY,CAAC;EAC7C,CAAC;EACDC,UAAU,EAAEA,CAAA,KAAM;IACdJ,YAAY,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,KAAa,IAAK;IACfY,eAAe,CAACb,QAAQ,CAACC,KAAK,CAAC;IAC/BgB,YAAY,CAAC,CAAC;EAClB,CAAC,EACD,CAACJ,eAAe,EAAEI,YAAY,CAClC,CAAC;EAED,IAAMG,OAAO,GAAGnC,WAAW,CAAC,MAAM;IAC9B4B,eAAe,CAACP,UAAU,CAAC,CAAC;IAC5BW,YAAY,CAAC,CAAC;EAClB,CAAC,EAAE,CAACJ,eAAe,EAAEI,YAAY,CAAC,CAAC;EAEnC,OAAO;IACHhB,KAAK;IACLc,aAAa;IACbI,MAAM;IACNC;EACJ,CAAC;AACL,CAAC"}
|
package/esm/useClipboardCopy.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
-
|
|
3
2
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
|
-
|
|
5
3
|
import { useCallback } from "react";
|
|
6
4
|
import { useKeyboardShortcut } from "./useKeyboardShortcut";
|
|
7
5
|
export var useClipboardCopy = options => {
|
|
8
6
|
var copy = useCallback( /*#__PURE__*/function () {
|
|
9
7
|
var _ref = _asyncToGenerator(function* (otherText) {
|
|
10
|
-
var _navigator
|
|
11
|
-
|
|
8
|
+
var _navigator;
|
|
12
9
|
var copyText = otherText || (options == null ? void 0 : options.text);
|
|
13
|
-
|
|
14
10
|
if (copyText === undefined) {
|
|
15
11
|
return false;
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
var successed = yield (_navigator = navigator) == null ? void 0 : (_navigator$clipboard = _navigator.clipboard) == null ? void 0 : _navigator$clipboard.writeText(copyText).then(() => true).catch(() => false);
|
|
19
|
-
|
|
13
|
+
var successed = yield (_navigator = navigator) == null || (_navigator = _navigator.clipboard) == null ? void 0 : _navigator.writeText(copyText).then(() => true).catch(() => false);
|
|
20
14
|
if (successed) {
|
|
21
|
-
options == null
|
|
15
|
+
options == null || options.onSuccess == null ? void 0 : options.onSuccess(copyText);
|
|
22
16
|
} else {
|
|
23
|
-
options == null
|
|
17
|
+
options == null || options.onFailure == null ? void 0 : options.onFailure(copyText);
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
return successed;
|
|
27
20
|
});
|
|
28
|
-
|
|
29
21
|
return function (_x) {
|
|
30
22
|
return _ref.apply(this, arguments);
|
|
31
23
|
};
|