matsuri-hooks 0.0.5 → 0.1.0
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/README.md +59 -27
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/useClipboardCopy.d.ts +6 -0
- package/dist/useKeyboardShortcut.d.ts +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/useClipboardCopy.d.ts +6 -0
- package/esm/useClipboardCopy.js +65 -0
- package/esm/useKeyboardShortcut.d.ts +1 -0
- package/esm/useKeyboardShortcut.js +17 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Matsuri Hooks
|
|
2
2
|
|
|
3
3
|
<!-- vscode-markdown-toc -->
|
|
4
|
+
<!-- prettier-ignore -->
|
|
4
5
|
* [Motivation](#Motivation)
|
|
5
6
|
* [Usage](#Usage)
|
|
6
7
|
* [Installation](#Installation)
|
|
@@ -10,6 +11,8 @@
|
|
|
10
11
|
* [useAuthFetch](#useAuthFetch)
|
|
11
12
|
* [useIntersectionObserver](#useIntersectionObserver)
|
|
12
13
|
* [useOnClickOutside](#useOnClickOutside)
|
|
14
|
+
* [useKeyboardShortcut](#useKeyboardShortcut)
|
|
15
|
+
* [useClipboardCopy](#useClipboardCopy)
|
|
13
16
|
|
|
14
17
|
<!-- vscode-markdown-toc-config
|
|
15
18
|
numbering=false
|
|
@@ -17,13 +20,10 @@
|
|
|
17
20
|
/vscode-markdown-toc-config -->
|
|
18
21
|
<!-- /vscode-markdown-toc -->
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
23
|
## <a name='Motivation'></a>Motivation
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
- Provide complex processing with safety guaranteed by testing
|
|
26
|
+
- Be common processing for each product
|
|
27
27
|
|
|
28
28
|
## <a name='Usage'></a>Usage
|
|
29
29
|
|
|
@@ -41,31 +41,28 @@ yarn add matsuri-hooks
|
|
|
41
41
|
const { token, authenticated, signin, signout } = useAuth()
|
|
42
42
|
|
|
43
43
|
return (
|
|
44
|
-
<div>
|
|
45
|
-
{authenticated ? (
|
|
46
|
-
<button onClick={signout}>Signout</button>
|
|
47
|
-
):(
|
|
48
|
-
<button onClick={signin}>Signin</button>
|
|
49
|
-
)}
|
|
50
|
-
</div>
|
|
44
|
+
<div>{authenticated ? <button onClick={signout}>Signout</button> : <button onClick={signin}>Signin</button>}</div>
|
|
51
45
|
)
|
|
52
46
|
```
|
|
53
47
|
|
|
54
48
|
### <a name='useFetch'></a>useFetch
|
|
55
49
|
|
|
56
50
|
```tsx
|
|
57
|
-
const { data, error, refetch } = useFetch<{species: "fish"}>("https://example.com/fish", { method: "GET" })
|
|
51
|
+
const { data, error, refetch } = useFetch<{ species: "fish" }>("https://example.com/fish", { method: "GET" })
|
|
58
52
|
|
|
59
53
|
return (
|
|
60
54
|
<div>
|
|
61
55
|
<p>Species: {data?.species}</p>
|
|
62
56
|
<button onClick={refetch}>Refetch</button>
|
|
63
57
|
{error ? (
|
|
64
|
-
<p>
|
|
65
|
-
|
|
58
|
+
<p>
|
|
59
|
+
{error.name}: {error.message}
|
|
60
|
+
</p>
|
|
61
|
+
) : null}
|
|
66
62
|
</div>
|
|
67
63
|
)
|
|
68
64
|
```
|
|
65
|
+
|
|
69
66
|
### <a name='useAuthFetch'></a>useAuthFetch
|
|
70
67
|
|
|
71
68
|
This default token format is `X-Access-Token: [TOKEN]`.
|
|
@@ -75,7 +72,7 @@ const { token } = useAuth()
|
|
|
75
72
|
const { error, refetch } = useAuthFetch<never>(token, "https://example.com", { method: "POST", ... )
|
|
76
73
|
```
|
|
77
74
|
|
|
78
|
-
|
|
75
|
+
- useAuthBearerFetch:this default token format is `Authorization: Bearer [TOKEN]`.
|
|
79
76
|
|
|
80
77
|
### <a name='useIntersectionObserver'></a>useIntersectionObserver
|
|
81
78
|
|
|
@@ -86,7 +83,7 @@ const { entry, disconnect } = useIntersectionObserver(ref, { threshold: 0.1 })
|
|
|
86
83
|
const [image, setImage] = useState<string>()
|
|
87
84
|
|
|
88
85
|
useEffect(() => {
|
|
89
|
-
if(entry){
|
|
86
|
+
if (entry) {
|
|
90
87
|
const fetchImage = async () => {
|
|
91
88
|
//...
|
|
92
89
|
return image
|
|
@@ -94,29 +91,64 @@ useEffect(() => {
|
|
|
94
91
|
disconnect()
|
|
95
92
|
setImage(fetchImage())
|
|
96
93
|
}
|
|
97
|
-
},[])
|
|
94
|
+
}, [])
|
|
95
|
+
|
|
96
|
+
return <img ref={ref} src={image || "dummy.png"} />
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### <a name='useOnClickOutside'></a>useOnClickOutside
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
const [open, setOpen] = useState(false)
|
|
103
|
+
const ref = useRef(null)
|
|
104
|
+
useOnClickOutside(ref, () => {
|
|
105
|
+
setOpen(false)
|
|
106
|
+
})
|
|
107
|
+
return (
|
|
108
|
+
<div>
|
|
109
|
+
<button onClick={() => setOpen(true)}>OPEN</button>
|
|
110
|
+
<Modal ref={ref} open={open} />
|
|
111
|
+
</div>
|
|
112
|
+
)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### <a name='useKeyboardShortcut'></a>useKeyboardShortcut
|
|
116
|
+
|
|
117
|
+
If the specified key and control or meta key are pressed together, the second argument callback is executed.
|
|
98
118
|
|
|
119
|
+
```tsx
|
|
120
|
+
const [open, setOpen] = useState(false)
|
|
121
|
+
const ref = useRef(null)
|
|
122
|
+
useKeyboardShortcut("j", () => {
|
|
123
|
+
setOpen(true)
|
|
124
|
+
})
|
|
99
125
|
return (
|
|
100
|
-
<
|
|
126
|
+
<div>
|
|
127
|
+
<Modal ref={ref} open={open} />
|
|
128
|
+
</div>
|
|
101
129
|
)
|
|
102
130
|
```
|
|
103
131
|
|
|
104
|
-
### <a name='
|
|
132
|
+
### <a name='useClipboardCopy'></a>useClipboardCopy
|
|
105
133
|
|
|
134
|
+
If the specified key is pressed together with a control or meta key, or if the return method is called, the specified text is copied to clipboard.
|
|
135
|
+
Then, if the copy fails, onFailure is called, and if it succeeds, onSuccess is called.
|
|
106
136
|
|
|
107
137
|
```tsx
|
|
108
138
|
const [open, setOpen] = useState(false)
|
|
109
139
|
const ref = useRef(null)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
() => {
|
|
113
|
-
|
|
140
|
+
const copy = useKeyboardShortcut(SOME_TOKEN, {
|
|
141
|
+
key: "j",
|
|
142
|
+
onSuccess: () => {
|
|
143
|
+
addAlert("Success")
|
|
144
|
+
},
|
|
145
|
+
onFailure: () => {
|
|
146
|
+
addAlert("Failed", { type: "error" })
|
|
114
147
|
}
|
|
115
|
-
)
|
|
148
|
+
})
|
|
116
149
|
return (
|
|
117
150
|
<div>
|
|
118
|
-
<
|
|
119
|
-
<Modal ref={ref} open={open}/>
|
|
151
|
+
<Button onClick={copy} />
|
|
120
152
|
</div>
|
|
121
153
|
)
|
|
122
154
|
```
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};var u=true;try{e[t].call(n.exports,n,n.exports,__webpack_require__);u=false}finally{if(u)delete r[t]}n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(144)}return startup()}({75:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.useAuth=t.tokenStorageApiWithLocalStorage=t.checkJwtExpiration=void 0;var n=r(297);t.checkJwtExpiration=function(e){var t=e.split(".");if(t.length!==3)return false;var r=t[1];var n=JSON.parse(atob(r))["exp"];return new Date<new Date(n*1e3)};t.tokenStorageApiWithLocalStorage={setToken:function(e){return localStorage.setItem("auth_token",e)},getToken:function(){return localStorage.getItem("auth_token")},clearToken:function(){localStorage.removeItem("auth_token")}};var u=null;t.useAuth=function(e){var r,i;var a=(r=e===null||e===void 0?void 0:e.tokenStorageApi)!==null&&r!==void 0?r:t.tokenStorageApiWithLocalStorage;var o=(i=e===null||e===void 0?void 0:e.jwtExpirationChecker)!==null&&i!==void 0?i:t.checkJwtExpiration;if(!u)u=a.getToken();var f=n.useState(u||""),c=f[0],s=f[1];var l=n.useState(!!u),d=l[0],v=l[1];var h=n.useCallback(function(){var e=a.getToken();if(!(e&&o(e))){a.clearToken();s("");v(false);u=null}else{s(e);v(true)}},[o,a]);n.useEffect(function(){h()},[h]);var p=n.useCallback(function(e){a.setToken(e);h()},[a,h]);var y=n.useCallback(function(){a.clearToken();h()},[a,h]);return{token:c,authenticated:d,signin:p,signout:y}}},144:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var u=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!t.hasOwnProperty(r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});u(r(500),t);u(r(75),t);u(r(526),t);u(r(207),t)},163:function(e,t,r){e.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};e[t].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(325)}return startup()}({48:function(e,t){var r=Object.prototype.hasOwnProperty;function dequal(e,t){var n,u;if(e===t)return true;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((u=e.length)===t.length){while(u--&&dequal(e[u],t[u]));}return u===-1}if(!n||typeof e==="object"){u=0;for(n in e){if(r.call(e,n)&&++u&&!r.call(t,n))return false;if(!(n in t)||!dequal(e[n],t[n]))return false}return Object.keys(t).length===u}}return e!==e&&t!==t}t.dequal=dequal},202:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:true});var r=new WeakMap;var n=0;function hash(e){if(!e.length)return"";var t="arg";for(var u=0;u<e.length;++u){if(e[u]===null){t+="@null";continue}var i=void 0;if(typeof e[u]!=="object"&&typeof e[u]!=="function"){if(typeof e[u]==="string"){i='"'+e[u]+'"'}else{i=String(e[u])}}else{if(!r.has(e[u])){i=n;r.set(e[u],n++)}else{i=r.get(e[u])}}t+="@"+i}return t}t.default=hash},209:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});var n=r(297);var u=n.createContext({});u.displayName="SWRConfigContext";t.default=u},297:function(e){e.exports=r(297)},323:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:true});var r=true;var n=function(){return r};var u=function(){if(typeof document!=="undefined"&&document.visibilityState!==undefined){return document.visibilityState!=="hidden"}return true};var i=function(e){return fetch(e).then(function(e){return e.json()})};var a=function(e){if(typeof window!=="undefined"&&window.addEventListener!==undefined&&typeof document!=="undefined"&&document.addEventListener!==undefined){document.addEventListener("visibilitychange",function(){return e()},false);window.addEventListener("focus",function(){return e()},false)}};var o=function(e){if(typeof window!=="undefined"&&window.addEventListener!==undefined){window.addEventListener("online",function(){r=true;e()},false);window.addEventListener("offline",function(){return r=false},false)}};t.default={isOnline:n,isDocumentVisible:u,fetcher:i,registerOnFocus:a,registerOnReconnect:o}},325:function(e,t,r){"use strict";function __export(e){for(var r in e)if(!t.hasOwnProperty(r))t[r]=e[r]}var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var u=n(r(516));t.default=u.default;__export(r(516));var i=r(942);t.useSWRInfinite=i.useSWRInfinite;var a=r(641);t.cache=a.cache},516:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,u){function fulfilled(e){try{step(n.next(e))}catch(e){u(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){u(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var u=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,u,i,a;return a={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function verb(e){return function(t){return step([e,t])}}function step(a){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,u&&(i=a[0]&2?u["return"]:a[0]?u["throw"]||((i=u["return"])&&i.call(u),0):u.next)&&!(i=i.call(u,a[1])).done)return i;if(u=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;u=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1];i=a;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(a);break}if(i[2])r.ops.pop();r.trys.pop();continue}a=t.call(e,r)}catch(e){a=[6,e];u=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};var i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(Object.hasOwnProperty.call(e,r))t[r]=e[r];t["default"]=e;return t};var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var o=r(297);var f=i(r(641));var c=r(564);var s=a(r(209));var l={};var d={};var v={};var h={};var p={};var y={};var b={};var _=function(){var e=0;return function(){return++e}}();if(!c.IS_SERVER){var g=function(e){if(!f.default.isDocumentVisible()||!f.default.isOnline())return;for(var t in e){if(e[t][0])e[t][0]()}};if(typeof f.default.registerOnFocus==="function"){f.default.registerOnFocus(function(){return g(v)})}if(typeof f.default.registerOnReconnect==="function"){f.default.registerOnReconnect(function(){return g(h)})}}var w=function(e,t){if(t===void 0){t=true}var r=f.cache.serializeKey(e),n=r[0],u=r[2],i=r[3];if(!n)return Promise.resolve();var a=p[n];if(n&&a){var o=f.cache.get(n);var c=f.cache.get(u);var s=f.cache.get(i);var l=[];for(var d=0;d<a.length;++d){l.push(a[d](t,o,c,s,d>0))}return Promise.all(l).then(function(){return f.cache.get(n)})}return Promise.resolve(f.cache.get(n))};t.trigger=w;var m=function(e,t,r,n){var u=p[e];if(e&&u){for(var i=0;i<u.length;++i){u[i](false,t,r,n)}}};var O=function(e,t,r){if(r===void 0){r=true}return n(void 0,void 0,void 0,function(){var n,i,a,o,c,s,l,v,h,g,m,O,k;return u(this,function(u){switch(u.label){case 0:n=f.cache.serializeKey(e),i=n[0],a=n[2];if(!i)return[2];if(typeof t==="undefined")return[2,w(e,r)];y[i]=_()-1;b[i]=0;o=y[i];c=d[i];v=false;if(t&&typeof t==="function"){try{t=t(f.cache.get(i))}catch(e){t=undefined;l=e}}if(!(t&&typeof t.then==="function"))return[3,5];v=true;u.label=1;case 1:u.trys.push([1,3,,4]);return[4,t];case 2:s=u.sent();return[3,4];case 3:h=u.sent();l=h;return[3,4];case 4:return[3,6];case 5:s=t;u.label=6;case 6:g=function(){if(o!==y[i]||c!==d[i]){if(l)throw l;return true}};if(g())return[2,s];if(typeof s!=="undefined"){f.cache.set(i,s)}f.cache.set(a,l);b[i]=_()-1;if(!v){if(g())return[2,s]}m=p[i];if(m){O=[];for(k=0;k<m.length;++k){O.push(m[k](!!r,s,l,undefined,k>0))}return[2,Promise.all(O).then(function(){if(l)throw l;return f.cache.get(i)})]}if(l)throw l;return[2,s]}})})};t.mutate=O;function useSWR(){var e=this;var t=[];for(var r=0;r<arguments.length;r++){t[r]=arguments[r]}var i=t[0];var a=Object.assign({},f.default,o.useContext(s.default),t.length>2?t[2]:t.length===2&&typeof t[1]==="object"?t[1]:{});var g=t.length>2?t[1]:t.length===2&&typeof t[1]==="function"?t[1]:t[1]===null?t[1]:a.fetcher;var w=f.cache.serializeKey(i),k=w[0],E=w[1],S=w[2],j=w[3];var x=o.useRef(a);c.useIsomorphicLayoutEffect(function(){x.current=a});var P=function(){return a.revalidateOnMount||!a.initialData&&a.revalidateOnMount===undefined};var R=function(){var e=f.cache.get(k);return typeof e==="undefined"?a.initialData:e};var T=function(){return!!f.cache.get(j)||k&&P()};var C=R();var I=f.cache.get(S);var M=T();var V=o.useRef({data:false,error:false,isValidating:false});var L=o.useRef({data:C,error:I,isValidating:M});o.useDebugValue(L.current.data);var A=o.useState({})[1];var D=o.useCallback(function(e){var t=false;for(var r in e){if(L.current[r]===e[r]){continue}L.current[r]=e[r];if(V.current[r]){t=true}}if(t){if(W.current||!q.current)return;A({})}},[]);var W=o.useRef(false);var z=o.useRef(k);var q=o.useRef(false);var F=o.useCallback(function(e){var t;var r=[];for(var n=1;n<arguments.length;n++){r[n-1]=arguments[n]}if(W.current)return;if(!q.current)return;if(k!==z.current)return;(t=x.current)[e].apply(t,r)},[k]);var H=o.useCallback(function(e,t){return O(z.current,e,t)},[]);var K=function(e,t){if(!e[k]){e[k]=[t]}else{e[k].push(t)}return function(){var r=e[k];var n=r.indexOf(t);if(n>=0){r[n]=r[r.length-1];r.pop()}}};var B=o.useCallback(function(t){if(t===void 0){t={}}return n(e,void 0,void 0,function(){var e,r,n,i,o,c,s,v,h,p;return u(this,function(u){switch(u.label){case 0:if(!k||!g)return[2,false];if(W.current)return[2,false];if(x.current.isPaused())return[2,false];e=t.retryCount,r=e===void 0?0:e,n=t.dedupe,i=n===void 0?false:n;o=true;c=typeof l[k]!=="undefined"&&i;u.label=1;case 1:u.trys.push([1,6,,7]);D({isValidating:true});f.cache.set(j,true);if(!c){m(k,L.current.data,L.current.error,true)}s=void 0;v=void 0;if(!c)return[3,3];v=d[k];return[4,l[k]];case 2:s=u.sent();return[3,5];case 3:if(a.loadingTimeout&&!f.cache.get(k)){setTimeout(function(){if(o)F("onLoadingSlow",k,a)},a.loadingTimeout)}if(E!==null){l[k]=g.apply(void 0,E)}else{l[k]=g(k)}d[k]=v=_();return[4,l[k]];case 4:s=u.sent();setTimeout(function(){delete l[k];delete d[k]},a.dedupingInterval);F("onSuccess",s,k,a);u.label=5;case 5:if(d[k]>v){return[2,false]}if(y[k]&&(v<=y[k]||v<=b[k]||b[k]===0)){D({isValidating:false});return[2,false]}f.cache.set(S,undefined);f.cache.set(j,false);h={isValidating:false};if(typeof L.current.error!=="undefined"){h.error=undefined}if(!a.compare(L.current.data,s)){h.data=s}if(!a.compare(f.cache.get(k),s)){f.cache.set(k,s)}D(h);if(!c){m(k,s,h.error,false)}return[3,7];case 6:p=u.sent();delete l[k];delete d[k];if(x.current.isPaused()){D({isValidating:false});return[2,false]}f.cache.set(S,p);if(L.current.error!==p){D({isValidating:false,error:p});if(!c){m(k,undefined,p,false)}}F("onError",p,k,a);if(a.shouldRetryOnError){F("onErrorRetry",p,k,a,B,{retryCount:r+1,dedupe:true})}return[3,7];case 7:o=false;return[2,true]}})})},[k]);c.useIsomorphicLayoutEffect(function(){if(!k)return undefined;W.current=false;var e=q.current;q.current=true;var t=L.current.data;var r=R();z.current=k;if(!a.compare(t,r)){D({data:r})}var n=function(){return B({dedupe:true})};if(e||P()){if(typeof r!=="undefined"&&!c.IS_SERVER){c.rAF(n)}else{n()}}var u=false;var i=function(){if(u||!x.current.revalidateOnFocus)return;u=true;n();setTimeout(function(){return u=false},x.current.focusThrottleInterval)};var o=function(){if(x.current.revalidateOnReconnect){n()}};var f=function(e,t,r,u,i){if(e===void 0){e=true}if(i===void 0){i=true}var o={};var f=false;if(typeof t!=="undefined"&&!a.compare(L.current.data,t)){o.data=t;f=true}if(L.current.error!==r){o.error=r;f=true}if(typeof u!=="undefined"&&L.current.isValidating!==u){o.isValidating=u;f=true}if(f){D(o)}if(e){if(i){return n()}else{return B()}}return false};var s=K(v,i);var l=K(h,o);var d=K(p,f);return function(){D=function(){return null};W.current=true;s();l();d()}},[k,B]);c.useIsomorphicLayoutEffect(function(){var t=null;var r=function(){return n(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:if(!(!L.current.error&&(x.current.refreshWhenHidden||x.current.isDocumentVisible())&&(x.current.refreshWhenOffline||x.current.isOnline())))return[3,2];return[4,B({dedupe:true})];case 1:e.sent();e.label=2;case 2:if(x.current.refreshInterval&&t){t=setTimeout(r,x.current.refreshInterval)}return[2]}})})};if(x.current.refreshInterval){t=setTimeout(r,x.current.refreshInterval)}return function(){if(t){clearTimeout(t);t=null}}},[a.refreshInterval,a.refreshWhenHidden,a.refreshWhenOffline,B]);var G;var J;if(a.suspense){G=f.cache.get(k);J=f.cache.get(S);if(typeof G==="undefined"){G=C}if(typeof J==="undefined"){J=I}if(typeof G==="undefined"&&typeof J==="undefined"){if(!l[k]){B()}if(l[k]&&typeof l[k].then==="function"){throw l[k]}G=l[k]}if(typeof G==="undefined"&&J){throw J}}var N=o.useMemo(function(){var e={revalidate:B,mutate:H};Object.defineProperties(e,{error:{get:function(){V.current.error=true;if(a.suspense){return J}return z.current===k?L.current.error:I},enumerable:true},data:{get:function(){V.current.data=true;if(a.suspense){return G}return z.current===k?L.current.data:C},enumerable:true},isValidating:{get:function(){V.current.isValidating=true;return k?L.current.isValidating:false},enumerable:true}});return e},[B,C,I,H,k,a.suspense,J,G]);return N}Object.defineProperty(s.default.Provider,"default",{value:f.default});var k=s.default.Provider;t.SWRConfig=k;t.default=useSWR},564:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});var n=r(297);t.IS_SERVER=typeof window==="undefined"||!!(typeof Deno!=="undefined"&&Deno&&Deno.version&&Deno.version.deno);t.rAF=t.IS_SERVER?null:window["requestAnimationFrame"]?function(e){return window["requestAnimationFrame"](e)}:function(e){return setTimeout(e,1)};t.useIsomorphicLayoutEffect=t.IS_SERVER?n.useEffect:n.useLayoutEffect},641:function(e,t,r){"use strict";var n=this&&this.__assign||function(){n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var u in t)if(Object.prototype.hasOwnProperty.call(t,u))e[u]=t[u]}return e};return n.apply(this,arguments)};var u=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var i=r(48);var a=u(r(722));var o=u(r(323));var f=new a.default;t.cache=f;function onErrorRetry(e,t,r,n,u){if(!r.isDocumentVisible()){return}if(typeof r.errorRetryCount==="number"&&u.retryCount>r.errorRetryCount){return}var i=Math.min(u.retryCount,8);var a=~~((Math.random()+.5)*(1<<i))*r.errorRetryInterval;setTimeout(n,a,u)}var c=typeof window!=="undefined"&&navigator["connection"]&&["slow-2g","2g"].indexOf(navigator["connection"].effectiveType)!==-1;var s=n({onLoadingSlow:function(){},onSuccess:function(){},onError:function(){},onErrorRetry:onErrorRetry,errorRetryInterval:(c?10:5)*1e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:(c?5:3)*1e3,refreshInterval:0,revalidateOnFocus:true,revalidateOnReconnect:true,refreshWhenHidden:false,refreshWhenOffline:false,shouldRetryOnError:true,suspense:false,compare:i.dequal,isPaused:function(){return false}},o.default);t.default=s},722:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var u=n(r(202));var i=function(){function Cache(e){if(e===void 0){e={}}this.cache=new Map(Object.entries(e));this.subs=[]}Cache.prototype.get=function(e){var t=this.serializeKey(e)[0];return this.cache.get(t)};Cache.prototype.set=function(e,t){var r=this.serializeKey(e)[0];this.cache.set(r,t);this.notify()};Cache.prototype.keys=function(){return Array.from(this.cache.keys())};Cache.prototype.has=function(e){var t=this.serializeKey(e)[0];return this.cache.has(t)};Cache.prototype.clear=function(){this.cache.clear();this.notify()};Cache.prototype.delete=function(e){var t=this.serializeKey(e)[0];this.cache.delete(t);this.notify()};Cache.prototype.serializeKey=function(e){var t=null;if(typeof e==="function"){try{e=e()}catch(t){e=""}}if(Array.isArray(e)){t=e;e=u.default(e)}else{e=String(e||"")}var r=e?"err@"+e:"";var n=e?"validating@"+e:"";return[e,t,r,n]};Cache.prototype.subscribe=function(e){var t=this;if(typeof e!=="function"){throw new Error("Expected the listener to be a function.")}var r=true;this.subs.push(e);return function(){if(!r)return;r=false;var n=t.subs.indexOf(e);if(n>-1){t.subs[n]=t.subs[t.subs.length-1];t.subs.length--}}};Cache.prototype.notify=function(){for(var e=0,t=this.subs;e<t.length;e++){var r=t[e];r()}};return Cache}();t.default=i},942:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,u){function fulfilled(e){try{step(n.next(e))}catch(e){u(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){u(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var u=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,u,i,a;return a={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function verb(e){return function(t){return step([e,t])}}function step(a){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,u&&(i=a[0]&2?u["return"]:a[0]?u["throw"]||((i=u["return"])&&i.call(u),0):u.next)&&!(i=i.call(u,a[1])).done)return i;if(u=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;u=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1];i=a;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(a);break}if(i[2])r.ops.pop();r.trys.pop();continue}a=t.call(e,r)}catch(e){a=[6,e];u=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};var i=this&&this.__rest||function(e,t){var r={};for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0)r[n]=e[n];if(e!=null&&typeof Object.getOwnPropertySymbols==="function")for(var u=0,n=Object.getOwnPropertySymbols(e);u<n.length;u++){if(t.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u]))r[n[u]]=e[n[u]]}return r};var a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(Object.hasOwnProperty.call(e,r))t[r]=e[r];t["default"]=e;return t};var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var f=r(297);var c=a(r(641));var s=r(564);var l=o(r(209));var d=o(r(516));function useSWRInfinite(){var e=this;var t=[];for(var r=0;r<arguments.length;r++){t[r]=arguments[r]}var a=t[0];var o=Object.assign({},c.default,f.useContext(l.default),t.length>2?t[2]:t.length===2&&typeof t[1]==="object"?t[1]:{});var v=t.length>2?t[1]:t.length===2&&typeof t[1]==="function"?t[1]:o.fetcher;var h=o.initialSize,p=h===void 0?1:h,y=o.revalidateAll,b=y===void 0?false:y,_=o.persistSize,g=_===void 0?false:_,w=i(o,["initialSize","revalidateAll","persistSize"]);var m=null;try{m=c.cache.serializeKey(a(0,null))[0]}catch(e){}var O=f.useState({})[1];var k=null;if(m){k="ctx@"+m}var E=null;if(m){E="len@"+m}var S=f.useRef(false);var j=f.useCallback(function(){var e=c.cache.get(E);return typeof e!=="undefined"?e:p},[E,p]);var x=f.useRef(j());s.useIsomorphicLayoutEffect(function(){if(!S.current){S.current=true;return}c.cache.set(E,g?x.current:p)},[m]);var P=f.useRef();var R=d.default(m?["inf",m]:null,function(){return n(e,void 0,void 0,function(){var e,t,r,n,i,f,s,l,d,h,p,y;return u(this,function(u){switch(u.label){case 0:e=c.cache.get(k)||{},t=e.data,r=e.force;n=[];i=j();f=null;s=0;u.label=1;case 1:if(!(s<i))return[3,8];l=c.cache.serializeKey(a(s,f)),d=l[0],h=l[1];if(!d){return[3,8]}p=c.cache.get(d);y=b||r||typeof p==="undefined"||typeof r==="undefined"&&s===0&&typeof P.current!=="undefined"||t&&!o.compare(t[s],p);if(!y)return[3,6];if(!(h!==null))return[3,3];return[4,v.apply(void 0,h)];case 2:p=u.sent();return[3,5];case 3:return[4,v(d)];case 4:p=u.sent();u.label=5;case 5:c.cache.set(d,p);u.label=6;case 6:n.push(p);f=p;u.label=7;case 7:++s;return[3,1];case 8:c.cache.delete(k);return[2,n]}})})},w);s.useIsomorphicLayoutEffect(function(){P.current=R.data},[R.data]);var T=f.useCallback(function(e,t){if(t===void 0){t=true}if(t&&typeof e!=="undefined"){var r=P.current;c.cache.set(k,{data:r,force:false})}else if(t){c.cache.set(k,{force:true})}return R.mutate(e,t)},[k]);var C=f.useCallback(function(e){var t;if(typeof e==="function"){t=e(j())}else if(typeof e==="number"){t=e}if(typeof t==="number"){c.cache.set(E,t);x.current=t}O({});return T(function(e){return e})},[E,j,T,O]);var I={size:j(),setSize:C,mutate:T};Object.defineProperties(I,{error:{get:function(){return R.error},enumerable:true},data:{get:function(){return R.data},enumerable:true},revalidate:{get:function(){return R.revalidate},enumerable:true},isValidating:{get:function(){return R.isValidating},enumerable:true}});return I}t.useSWRInfinite=useSWRInfinite}})},207:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.useIntersectionObserver=void 0;var n=r(303);var u=r(297);t.useIntersectionObserver=function(e,t){if(t===void 0){t={}}var r=u.useState(),i=r[0],a=r[1];var o=u.useRef();var f=u.useCallback(function(){var e;(e=o===null||o===void 0?void 0:o.current)===null||e===void 0?void 0:e.disconnect()},[]);if(!n.isBrowser){return{entry:i,disconnect:f}}u.useEffect(function(){var r=e&&e.current;if(!r){return}o.current=new IntersectionObserver(function(e){if(!e.length){return}a(e[0])},t);o.current.observe(r);return function(){f()}},[f,t,e]);return{entry:i,disconnect:f}}},297:function(e){e.exports=require("react")},303:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.isBrowser=void 0;t.isBrowser=typeof window!=="undefined"&&typeof document!=="undefined"&&window.document===document},500:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.useOnClickOutside=void 0;var n=r(303);var u=r(297);t.useOnClickOutside=function(e,t){if(!n.isBrowser){return}u.useEffect(function(){if(!t){return}var r=function(r){if(!e.current||e.current.contains(r.target)){return}t(r)};document.addEventListener("mousedown",r,{passive:true});document.addEventListener("touchstart",r,{passive:true});return function(){document.removeEventListener("mousedown",r);document.removeEventListener("touchstart",r)}},[t,e])}},526:function(e,t,r){"use strict";var n=this&&this.__assign||function(){n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var u in t)if(Object.prototype.hasOwnProperty.call(t,u))e[u]=t[u]}return e};return n.apply(this,arguments)};var u=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(r!=="default"&&Object.hasOwnProperty.call(e,r))u(t,e,r);i(t,e);return t};var o=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,u){function fulfilled(e){try{step(n.next(e))}catch(e){u(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){u(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var f=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,u,i,a;return a={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function verb(e){return function(t){return step([e,t])}}function step(a){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,u&&(i=a[0]&2?u["return"]:a[0]?u["throw"]||((i=u["return"])&&i.call(u),0):u.next)&&!(i=i.call(u,a[1])).done)return i;if(u=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;u=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1];i=a;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(a);break}if(i[2])r.ops.pop();r.trys.pop();continue}a=t.call(e,r)}catch(e){a=[6,e];u=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};Object.defineProperty(t,"__esModule",{value:true});t.useAuthBearerFetch=t.useAuthFetch=t.useFetch=t.fetcher=void 0;var c=r(297);var s=a(r(163));t.fetcher=function(e,t){return o(void 0,void 0,void 0,function(){var r,n;return f(this,function(u){switch(u.label){case 0:u.trys.push([0,2,,3]);r={};return[4,l(e,t)];case 1:return[2,(r.data=u.sent(),r.error=undefined,r)];case 2:n=u.sent();return[2,{data:undefined,error:n}];case 3:return[2]}})})};var l=function(e,t){return o(void 0,void 0,void 0,function(){var r,u,i,a,o,c;var s;var l,d,v;return f(this,function(f){switch(f.label){case 0:r={};if(t.token){u=(l=t.authTokenHeader)!==null&&l!==void 0?l:"X-Access-Token";r.headers=(s={},s[u]=u==="Authorization"?"Bearer "+t.token:t.token,s)}if(t.method){r.method=t.method||"GET"}if(t===null||t===void 0?void 0:t.body){r.body=t.body}if(r.body&&r.method==="GET"){throw new TypeError("The `GET` method cannot be used with a body")}r.headers=n({"Content-Type":"application/json"},(d=r.headers)!==null&&d!==void 0?d:{});return[4,((v=t.fetch)!==null&&v!==void 0?v:fetch)(e,r)];case 1:i=f.sent();if(!!i.ok)return[3,3];a=Error.bind;o=i.status+": ";return[4,i.text()];case 2:throw new(a.apply(Error,[void 0,o+f.sent()]));case 3:return[4,i.text()];case 4:c=f.sent();return[2,c&&JSON.parse(c)]}})})};t.useFetch=function(e,t){var r=e?[e,t.token,t.body]:null;var n=c.useMemo(function(){var e;return(e=t.fetch)!==null&&e!==void 0?e:function(e,r){return l(e,{method:t.method,token:r,body:t.body,authTokenHeader:t.authTokenHeader})}},[t.authTokenHeader,t.body,t.fetch,t.method]);var u=s.default(r,n,t.swrConfig),i=u.data,a=u.error;var d=c.useCallback(function(){return o(void 0,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:if(!r)return[3,2];return[4,s.mutate(r)];case 1:e.sent();e.label=2;case 2:return[2]}})})},[r]);return{data:i,error:a,refetch:d}};t.useAuthFetch=function(e,t,r){var n=t&&e?[t,e,r.body]:null;var u=c.useMemo(function(){var e;return(e=r.fetch)!==null&&e!==void 0?e:function(e,t){var n;return l(e,{method:r.method,token:t,body:r.body,authTokenHeader:(n=r.authTokenHeader)!==null&&n!==void 0?n:"X-Access-Token"})}},[r.authTokenHeader,r.body,r.fetch,r.method]);var i=s.default(n,u,r.swrConfig),a=i.data,d=i.error;var v=c.useCallback(function(){return o(void 0,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:if(!n)return[3,2];return[4,s.mutate(n)];case 1:e.sent();e.label=2;case 2:return[2]}})})},[n]);return{data:a,error:d,refetch:v}};t.useAuthBearerFetch=function(e,r,u){return t.useAuthFetch(e,r,n(n({},u),{authTokenHeader:"Authorization"}))}}});
|
|
1
|
+
module.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};var u=true;try{e[t].call(n.exports,n,n.exports,__webpack_require__);u=false}finally{if(u)delete r[t]}n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(144)}return startup()}({75:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.useAuth=t.tokenStorageApiWithLocalStorage=t.checkJwtExpiration=void 0;var n=r(297);t.checkJwtExpiration=function(e){var t=e.split(".");if(t.length!==3)return false;var r=t[1];var n=JSON.parse(atob(r))["exp"];return new Date<new Date(n*1e3)};t.tokenStorageApiWithLocalStorage={setToken:function(e){return localStorage.setItem("auth_token",e)},getToken:function(){return localStorage.getItem("auth_token")},clearToken:function(){localStorage.removeItem("auth_token")}};var u=null;t.useAuth=function(e){var r,i;var a=(r=e===null||e===void 0?void 0:e.tokenStorageApi)!==null&&r!==void 0?r:t.tokenStorageApiWithLocalStorage;var o=(i=e===null||e===void 0?void 0:e.jwtExpirationChecker)!==null&&i!==void 0?i:t.checkJwtExpiration;if(!u)u=a.getToken();var f=n.useState(u||""),c=f[0],s=f[1];var l=n.useState(!!u),d=l[0],v=l[1];var h=n.useCallback(function(){var e=a.getToken();if(!(e&&o(e))){a.clearToken();s("");v(false);u=null}else{s(e);v(true)}},[o,a]);n.useEffect(function(){h()},[h]);var p=n.useCallback(function(e){a.setToken(e);h()},[a,h]);var y=n.useCallback(function(){a.clearToken();h()},[a,h]);return{token:c,authenticated:d,signin:p,signout:y}}},144:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var u=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!t.hasOwnProperty(r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});u(r(500),t);u(r(75),t);u(r(526),t);u(r(207),t);u(r(949),t);u(r(347),t)},163:function(e,t,r){e.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};e[t].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(325)}return startup()}({48:function(e,t){var r=Object.prototype.hasOwnProperty;function dequal(e,t){var n,u;if(e===t)return true;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((u=e.length)===t.length){while(u--&&dequal(e[u],t[u]));}return u===-1}if(!n||typeof e==="object"){u=0;for(n in e){if(r.call(e,n)&&++u&&!r.call(t,n))return false;if(!(n in t)||!dequal(e[n],t[n]))return false}return Object.keys(t).length===u}}return e!==e&&t!==t}t.dequal=dequal},202:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:true});var r=new WeakMap;var n=0;function hash(e){if(!e.length)return"";var t="arg";for(var u=0;u<e.length;++u){if(e[u]===null){t+="@null";continue}var i=void 0;if(typeof e[u]!=="object"&&typeof e[u]!=="function"){if(typeof e[u]==="string"){i='"'+e[u]+'"'}else{i=String(e[u])}}else{if(!r.has(e[u])){i=n;r.set(e[u],n++)}else{i=r.get(e[u])}}t+="@"+i}return t}t.default=hash},209:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});var n=r(297);var u=n.createContext({});u.displayName="SWRConfigContext";t.default=u},297:function(e){e.exports=r(297)},323:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:true});var r=true;var n=function(){return r};var u=function(){if(typeof document!=="undefined"&&document.visibilityState!==undefined){return document.visibilityState!=="hidden"}return true};var i=function(e){return fetch(e).then(function(e){return e.json()})};var a=function(e){if(typeof window!=="undefined"&&window.addEventListener!==undefined&&typeof document!=="undefined"&&document.addEventListener!==undefined){document.addEventListener("visibilitychange",function(){return e()},false);window.addEventListener("focus",function(){return e()},false)}};var o=function(e){if(typeof window!=="undefined"&&window.addEventListener!==undefined){window.addEventListener("online",function(){r=true;e()},false);window.addEventListener("offline",function(){return r=false},false)}};t.default={isOnline:n,isDocumentVisible:u,fetcher:i,registerOnFocus:a,registerOnReconnect:o}},325:function(e,t,r){"use strict";function __export(e){for(var r in e)if(!t.hasOwnProperty(r))t[r]=e[r]}var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var u=n(r(516));t.default=u.default;__export(r(516));var i=r(942);t.useSWRInfinite=i.useSWRInfinite;var a=r(641);t.cache=a.cache},516:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,u){function fulfilled(e){try{step(n.next(e))}catch(e){u(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){u(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var u=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,u,i,a;return a={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function verb(e){return function(t){return step([e,t])}}function step(a){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,u&&(i=a[0]&2?u["return"]:a[0]?u["throw"]||((i=u["return"])&&i.call(u),0):u.next)&&!(i=i.call(u,a[1])).done)return i;if(u=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;u=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1];i=a;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(a);break}if(i[2])r.ops.pop();r.trys.pop();continue}a=t.call(e,r)}catch(e){a=[6,e];u=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};var i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(Object.hasOwnProperty.call(e,r))t[r]=e[r];t["default"]=e;return t};var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var o=r(297);var f=i(r(641));var c=r(564);var s=a(r(209));var l={};var d={};var v={};var h={};var p={};var y={};var b={};var g=function(){var e=0;return function(){return++e}}();if(!c.IS_SERVER){var _=function(e){if(!f.default.isDocumentVisible()||!f.default.isOnline())return;for(var t in e){if(e[t][0])e[t][0]()}};if(typeof f.default.registerOnFocus==="function"){f.default.registerOnFocus(function(){return _(v)})}if(typeof f.default.registerOnReconnect==="function"){f.default.registerOnReconnect(function(){return _(h)})}}var w=function(e,t){if(t===void 0){t=true}var r=f.cache.serializeKey(e),n=r[0],u=r[2],i=r[3];if(!n)return Promise.resolve();var a=p[n];if(n&&a){var o=f.cache.get(n);var c=f.cache.get(u);var s=f.cache.get(i);var l=[];for(var d=0;d<a.length;++d){l.push(a[d](t,o,c,s,d>0))}return Promise.all(l).then(function(){return f.cache.get(n)})}return Promise.resolve(f.cache.get(n))};t.trigger=w;var m=function(e,t,r,n){var u=p[e];if(e&&u){for(var i=0;i<u.length;++i){u[i](false,t,r,n)}}};var O=function(e,t,r){if(r===void 0){r=true}return n(void 0,void 0,void 0,function(){var n,i,a,o,c,s,l,v,h,_,m,O,k;return u(this,function(u){switch(u.label){case 0:n=f.cache.serializeKey(e),i=n[0],a=n[2];if(!i)return[2];if(typeof t==="undefined")return[2,w(e,r)];y[i]=g()-1;b[i]=0;o=y[i];c=d[i];v=false;if(t&&typeof t==="function"){try{t=t(f.cache.get(i))}catch(e){t=undefined;l=e}}if(!(t&&typeof t.then==="function"))return[3,5];v=true;u.label=1;case 1:u.trys.push([1,3,,4]);return[4,t];case 2:s=u.sent();return[3,4];case 3:h=u.sent();l=h;return[3,4];case 4:return[3,6];case 5:s=t;u.label=6;case 6:_=function(){if(o!==y[i]||c!==d[i]){if(l)throw l;return true}};if(_())return[2,s];if(typeof s!=="undefined"){f.cache.set(i,s)}f.cache.set(a,l);b[i]=g()-1;if(!v){if(_())return[2,s]}m=p[i];if(m){O=[];for(k=0;k<m.length;++k){O.push(m[k](!!r,s,l,undefined,k>0))}return[2,Promise.all(O).then(function(){if(l)throw l;return f.cache.get(i)})]}if(l)throw l;return[2,s]}})})};t.mutate=O;function useSWR(){var e=this;var t=[];for(var r=0;r<arguments.length;r++){t[r]=arguments[r]}var i=t[0];var a=Object.assign({},f.default,o.useContext(s.default),t.length>2?t[2]:t.length===2&&typeof t[1]==="object"?t[1]:{});var _=t.length>2?t[1]:t.length===2&&typeof t[1]==="function"?t[1]:t[1]===null?t[1]:a.fetcher;var w=f.cache.serializeKey(i),k=w[0],S=w[1],E=w[2],j=w[3];var x=o.useRef(a);c.useIsomorphicLayoutEffect(function(){x.current=a});var P=function(){return a.revalidateOnMount||!a.initialData&&a.revalidateOnMount===undefined};var C=function(){var e=f.cache.get(k);return typeof e==="undefined"?a.initialData:e};var R=function(){return!!f.cache.get(j)||k&&P()};var T=C();var M=f.cache.get(E);var I=R();var L=o.useRef({data:false,error:false,isValidating:false});var V=o.useRef({data:T,error:M,isValidating:I});o.useDebugValue(V.current.data);var A=o.useState({})[1];var D=o.useCallback(function(e){var t=false;for(var r in e){if(V.current[r]===e[r]){continue}V.current[r]=e[r];if(L.current[r]){t=true}}if(t){if(W.current||!q.current)return;A({})}},[]);var W=o.useRef(false);var z=o.useRef(k);var q=o.useRef(false);var F=o.useCallback(function(e){var t;var r=[];for(var n=1;n<arguments.length;n++){r[n-1]=arguments[n]}if(W.current)return;if(!q.current)return;if(k!==z.current)return;(t=x.current)[e].apply(t,r)},[k]);var K=o.useCallback(function(e,t){return O(z.current,e,t)},[]);var H=function(e,t){if(!e[k]){e[k]=[t]}else{e[k].push(t)}return function(){var r=e[k];var n=r.indexOf(t);if(n>=0){r[n]=r[r.length-1];r.pop()}}};var B=o.useCallback(function(t){if(t===void 0){t={}}return n(e,void 0,void 0,function(){var e,r,n,i,o,c,s,v,h,p;return u(this,function(u){switch(u.label){case 0:if(!k||!_)return[2,false];if(W.current)return[2,false];if(x.current.isPaused())return[2,false];e=t.retryCount,r=e===void 0?0:e,n=t.dedupe,i=n===void 0?false:n;o=true;c=typeof l[k]!=="undefined"&&i;u.label=1;case 1:u.trys.push([1,6,,7]);D({isValidating:true});f.cache.set(j,true);if(!c){m(k,V.current.data,V.current.error,true)}s=void 0;v=void 0;if(!c)return[3,3];v=d[k];return[4,l[k]];case 2:s=u.sent();return[3,5];case 3:if(a.loadingTimeout&&!f.cache.get(k)){setTimeout(function(){if(o)F("onLoadingSlow",k,a)},a.loadingTimeout)}if(S!==null){l[k]=_.apply(void 0,S)}else{l[k]=_(k)}d[k]=v=g();return[4,l[k]];case 4:s=u.sent();setTimeout(function(){delete l[k];delete d[k]},a.dedupingInterval);F("onSuccess",s,k,a);u.label=5;case 5:if(d[k]>v){return[2,false]}if(y[k]&&(v<=y[k]||v<=b[k]||b[k]===0)){D({isValidating:false});return[2,false]}f.cache.set(E,undefined);f.cache.set(j,false);h={isValidating:false};if(typeof V.current.error!=="undefined"){h.error=undefined}if(!a.compare(V.current.data,s)){h.data=s}if(!a.compare(f.cache.get(k),s)){f.cache.set(k,s)}D(h);if(!c){m(k,s,h.error,false)}return[3,7];case 6:p=u.sent();delete l[k];delete d[k];if(x.current.isPaused()){D({isValidating:false});return[2,false]}f.cache.set(E,p);if(V.current.error!==p){D({isValidating:false,error:p});if(!c){m(k,undefined,p,false)}}F("onError",p,k,a);if(a.shouldRetryOnError){F("onErrorRetry",p,k,a,B,{retryCount:r+1,dedupe:true})}return[3,7];case 7:o=false;return[2,true]}})})},[k]);c.useIsomorphicLayoutEffect(function(){if(!k)return undefined;W.current=false;var e=q.current;q.current=true;var t=V.current.data;var r=C();z.current=k;if(!a.compare(t,r)){D({data:r})}var n=function(){return B({dedupe:true})};if(e||P()){if(typeof r!=="undefined"&&!c.IS_SERVER){c.rAF(n)}else{n()}}var u=false;var i=function(){if(u||!x.current.revalidateOnFocus)return;u=true;n();setTimeout(function(){return u=false},x.current.focusThrottleInterval)};var o=function(){if(x.current.revalidateOnReconnect){n()}};var f=function(e,t,r,u,i){if(e===void 0){e=true}if(i===void 0){i=true}var o={};var f=false;if(typeof t!=="undefined"&&!a.compare(V.current.data,t)){o.data=t;f=true}if(V.current.error!==r){o.error=r;f=true}if(typeof u!=="undefined"&&V.current.isValidating!==u){o.isValidating=u;f=true}if(f){D(o)}if(e){if(i){return n()}else{return B()}}return false};var s=H(v,i);var l=H(h,o);var d=H(p,f);return function(){D=function(){return null};W.current=true;s();l();d()}},[k,B]);c.useIsomorphicLayoutEffect(function(){var t=null;var r=function(){return n(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:if(!(!V.current.error&&(x.current.refreshWhenHidden||x.current.isDocumentVisible())&&(x.current.refreshWhenOffline||x.current.isOnline())))return[3,2];return[4,B({dedupe:true})];case 1:e.sent();e.label=2;case 2:if(x.current.refreshInterval&&t){t=setTimeout(r,x.current.refreshInterval)}return[2]}})})};if(x.current.refreshInterval){t=setTimeout(r,x.current.refreshInterval)}return function(){if(t){clearTimeout(t);t=null}}},[a.refreshInterval,a.refreshWhenHidden,a.refreshWhenOffline,B]);var G;var J;if(a.suspense){G=f.cache.get(k);J=f.cache.get(E);if(typeof G==="undefined"){G=T}if(typeof J==="undefined"){J=M}if(typeof G==="undefined"&&typeof J==="undefined"){if(!l[k]){B()}if(l[k]&&typeof l[k].then==="function"){throw l[k]}G=l[k]}if(typeof G==="undefined"&&J){throw J}}var N=o.useMemo(function(){var e={revalidate:B,mutate:K};Object.defineProperties(e,{error:{get:function(){L.current.error=true;if(a.suspense){return J}return z.current===k?V.current.error:M},enumerable:true},data:{get:function(){L.current.data=true;if(a.suspense){return G}return z.current===k?V.current.data:T},enumerable:true},isValidating:{get:function(){L.current.isValidating=true;return k?V.current.isValidating:false},enumerable:true}});return e},[B,T,M,K,k,a.suspense,J,G]);return N}Object.defineProperty(s.default.Provider,"default",{value:f.default});var k=s.default.Provider;t.SWRConfig=k;t.default=useSWR},564:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});var n=r(297);t.IS_SERVER=typeof window==="undefined"||!!(typeof Deno!=="undefined"&&Deno&&Deno.version&&Deno.version.deno);t.rAF=t.IS_SERVER?null:window["requestAnimationFrame"]?function(e){return window["requestAnimationFrame"](e)}:function(e){return setTimeout(e,1)};t.useIsomorphicLayoutEffect=t.IS_SERVER?n.useEffect:n.useLayoutEffect},641:function(e,t,r){"use strict";var n=this&&this.__assign||function(){n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var u in t)if(Object.prototype.hasOwnProperty.call(t,u))e[u]=t[u]}return e};return n.apply(this,arguments)};var u=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var i=r(48);var a=u(r(722));var o=u(r(323));var f=new a.default;t.cache=f;function onErrorRetry(e,t,r,n,u){if(!r.isDocumentVisible()){return}if(typeof r.errorRetryCount==="number"&&u.retryCount>r.errorRetryCount){return}var i=Math.min(u.retryCount,8);var a=~~((Math.random()+.5)*(1<<i))*r.errorRetryInterval;setTimeout(n,a,u)}var c=typeof window!=="undefined"&&navigator["connection"]&&["slow-2g","2g"].indexOf(navigator["connection"].effectiveType)!==-1;var s=n({onLoadingSlow:function(){},onSuccess:function(){},onError:function(){},onErrorRetry:onErrorRetry,errorRetryInterval:(c?10:5)*1e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:(c?5:3)*1e3,refreshInterval:0,revalidateOnFocus:true,revalidateOnReconnect:true,refreshWhenHidden:false,refreshWhenOffline:false,shouldRetryOnError:true,suspense:false,compare:i.dequal,isPaused:function(){return false}},o.default);t.default=s},722:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var u=n(r(202));var i=function(){function Cache(e){if(e===void 0){e={}}this.cache=new Map(Object.entries(e));this.subs=[]}Cache.prototype.get=function(e){var t=this.serializeKey(e)[0];return this.cache.get(t)};Cache.prototype.set=function(e,t){var r=this.serializeKey(e)[0];this.cache.set(r,t);this.notify()};Cache.prototype.keys=function(){return Array.from(this.cache.keys())};Cache.prototype.has=function(e){var t=this.serializeKey(e)[0];return this.cache.has(t)};Cache.prototype.clear=function(){this.cache.clear();this.notify()};Cache.prototype.delete=function(e){var t=this.serializeKey(e)[0];this.cache.delete(t);this.notify()};Cache.prototype.serializeKey=function(e){var t=null;if(typeof e==="function"){try{e=e()}catch(t){e=""}}if(Array.isArray(e)){t=e;e=u.default(e)}else{e=String(e||"")}var r=e?"err@"+e:"";var n=e?"validating@"+e:"";return[e,t,r,n]};Cache.prototype.subscribe=function(e){var t=this;if(typeof e!=="function"){throw new Error("Expected the listener to be a function.")}var r=true;this.subs.push(e);return function(){if(!r)return;r=false;var n=t.subs.indexOf(e);if(n>-1){t.subs[n]=t.subs[t.subs.length-1];t.subs.length--}}};Cache.prototype.notify=function(){for(var e=0,t=this.subs;e<t.length;e++){var r=t[e];r()}};return Cache}();t.default=i},942:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,u){function fulfilled(e){try{step(n.next(e))}catch(e){u(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){u(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var u=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,u,i,a;return a={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function verb(e){return function(t){return step([e,t])}}function step(a){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,u&&(i=a[0]&2?u["return"]:a[0]?u["throw"]||((i=u["return"])&&i.call(u),0):u.next)&&!(i=i.call(u,a[1])).done)return i;if(u=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;u=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1];i=a;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(a);break}if(i[2])r.ops.pop();r.trys.pop();continue}a=t.call(e,r)}catch(e){a=[6,e];u=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};var i=this&&this.__rest||function(e,t){var r={};for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0)r[n]=e[n];if(e!=null&&typeof Object.getOwnPropertySymbols==="function")for(var u=0,n=Object.getOwnPropertySymbols(e);u<n.length;u++){if(t.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u]))r[n[u]]=e[n[u]]}return r};var a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(Object.hasOwnProperty.call(e,r))t[r]=e[r];t["default"]=e;return t};var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});var f=r(297);var c=a(r(641));var s=r(564);var l=o(r(209));var d=o(r(516));function useSWRInfinite(){var e=this;var t=[];for(var r=0;r<arguments.length;r++){t[r]=arguments[r]}var a=t[0];var o=Object.assign({},c.default,f.useContext(l.default),t.length>2?t[2]:t.length===2&&typeof t[1]==="object"?t[1]:{});var v=t.length>2?t[1]:t.length===2&&typeof t[1]==="function"?t[1]:o.fetcher;var h=o.initialSize,p=h===void 0?1:h,y=o.revalidateAll,b=y===void 0?false:y,g=o.persistSize,_=g===void 0?false:g,w=i(o,["initialSize","revalidateAll","persistSize"]);var m=null;try{m=c.cache.serializeKey(a(0,null))[0]}catch(e){}var O=f.useState({})[1];var k=null;if(m){k="ctx@"+m}var S=null;if(m){S="len@"+m}var E=f.useRef(false);var j=f.useCallback(function(){var e=c.cache.get(S);return typeof e!=="undefined"?e:p},[S,p]);var x=f.useRef(j());s.useIsomorphicLayoutEffect(function(){if(!E.current){E.current=true;return}c.cache.set(S,_?x.current:p)},[m]);var P=f.useRef();var C=d.default(m?["inf",m]:null,function(){return n(e,void 0,void 0,function(){var e,t,r,n,i,f,s,l,d,h,p,y;return u(this,function(u){switch(u.label){case 0:e=c.cache.get(k)||{},t=e.data,r=e.force;n=[];i=j();f=null;s=0;u.label=1;case 1:if(!(s<i))return[3,8];l=c.cache.serializeKey(a(s,f)),d=l[0],h=l[1];if(!d){return[3,8]}p=c.cache.get(d);y=b||r||typeof p==="undefined"||typeof r==="undefined"&&s===0&&typeof P.current!=="undefined"||t&&!o.compare(t[s],p);if(!y)return[3,6];if(!(h!==null))return[3,3];return[4,v.apply(void 0,h)];case 2:p=u.sent();return[3,5];case 3:return[4,v(d)];case 4:p=u.sent();u.label=5;case 5:c.cache.set(d,p);u.label=6;case 6:n.push(p);f=p;u.label=7;case 7:++s;return[3,1];case 8:c.cache.delete(k);return[2,n]}})})},w);s.useIsomorphicLayoutEffect(function(){P.current=C.data},[C.data]);var R=f.useCallback(function(e,t){if(t===void 0){t=true}if(t&&typeof e!=="undefined"){var r=P.current;c.cache.set(k,{data:r,force:false})}else if(t){c.cache.set(k,{force:true})}return C.mutate(e,t)},[k]);var T=f.useCallback(function(e){var t;if(typeof e==="function"){t=e(j())}else if(typeof e==="number"){t=e}if(typeof t==="number"){c.cache.set(S,t);x.current=t}O({});return R(function(e){return e})},[S,j,R,O]);var M={size:j(),setSize:T,mutate:R};Object.defineProperties(M,{error:{get:function(){return C.error},enumerable:true},data:{get:function(){return C.data},enumerable:true},revalidate:{get:function(){return C.revalidate},enumerable:true},isValidating:{get:function(){return C.isValidating},enumerable:true}});return M}t.useSWRInfinite=useSWRInfinite}})},207:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.useIntersectionObserver=void 0;var n=r(303);var u=r(297);t.useIntersectionObserver=function(e,t){if(t===void 0){t={}}var r=u.useState(),i=r[0],a=r[1];var o=u.useRef();var f=u.useCallback(function(){var e;(e=o===null||o===void 0?void 0:o.current)===null||e===void 0?void 0:e.disconnect()},[]);if(!n.isBrowser){return{entry:i,disconnect:f}}u.useEffect(function(){var r=e&&e.current;if(!r){return}o.current=new IntersectionObserver(function(e){if(!e.length){return}a(e[0])},t);o.current.observe(r);return function(){f()}},[f,t,e]);return{entry:i,disconnect:f}}},297:function(e){e.exports=require("react")},303:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.isBrowser=void 0;t.isBrowser=typeof window!=="undefined"&&typeof document!=="undefined"&&window.document===document},347:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.useKeyboardShortcut=void 0;var n=r(297);t.useKeyboardShortcut=function(e,t){n.useEffect(function(){if(e===undefined||t===undefined){return}var r=function(r){if((r.ctrlKey||r.metaKey)&&r.key===e){t()}};window.addEventListener("keydown",r);return function(){window.removeEventListener("keydown",r)}},[e,t])}},500:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.useOnClickOutside=void 0;var n=r(303);var u=r(297);t.useOnClickOutside=function(e,t){if(!n.isBrowser){return}u.useEffect(function(){if(!t){return}var r=function(r){if(!e.current||e.current.contains(r.target)){return}t(r)};document.addEventListener("mousedown",r,{passive:true});document.addEventListener("touchstart",r,{passive:true});return function(){document.removeEventListener("mousedown",r);document.removeEventListener("touchstart",r)}},[t,e])}},526:function(e,t,r){"use strict";var n=this&&this.__assign||function(){n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var u in t)if(Object.prototype.hasOwnProperty.call(t,u))e[u]=t[u]}return e};return n.apply(this,arguments)};var u=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(r!=="default"&&Object.hasOwnProperty.call(e,r))u(t,e,r);i(t,e);return t};var o=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,u){function fulfilled(e){try{step(n.next(e))}catch(e){u(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){u(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var f=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,u,i,a;return a={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function verb(e){return function(t){return step([e,t])}}function step(a){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,u&&(i=a[0]&2?u["return"]:a[0]?u["throw"]||((i=u["return"])&&i.call(u),0):u.next)&&!(i=i.call(u,a[1])).done)return i;if(u=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;u=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1];i=a;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(a);break}if(i[2])r.ops.pop();r.trys.pop();continue}a=t.call(e,r)}catch(e){a=[6,e];u=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};Object.defineProperty(t,"__esModule",{value:true});t.useAuthBearerFetch=t.useAuthFetch=t.useFetch=t.fetcher=void 0;var c=r(297);var s=a(r(163));t.fetcher=function(e,t){return o(void 0,void 0,void 0,function(){var r,n;return f(this,function(u){switch(u.label){case 0:u.trys.push([0,2,,3]);r={};return[4,l(e,t)];case 1:return[2,(r.data=u.sent(),r.error=undefined,r)];case 2:n=u.sent();return[2,{data:undefined,error:n}];case 3:return[2]}})})};var l=function(e,t){return o(void 0,void 0,void 0,function(){var r,u,i,a,o,c;var s;var l,d,v;return f(this,function(f){switch(f.label){case 0:r={};if(t.token){u=(l=t.authTokenHeader)!==null&&l!==void 0?l:"X-Access-Token";r.headers=(s={},s[u]=u==="Authorization"?"Bearer "+t.token:t.token,s)}if(t.method){r.method=t.method||"GET"}if(t===null||t===void 0?void 0:t.body){r.body=t.body}if(r.body&&r.method==="GET"){throw new TypeError("The `GET` method cannot be used with a body")}r.headers=n({"Content-Type":"application/json"},(d=r.headers)!==null&&d!==void 0?d:{});return[4,((v=t.fetch)!==null&&v!==void 0?v:fetch)(e,r)];case 1:i=f.sent();if(!!i.ok)return[3,3];a=Error.bind;o=i.status+": ";return[4,i.text()];case 2:throw new(a.apply(Error,[void 0,o+f.sent()]));case 3:return[4,i.text()];case 4:c=f.sent();return[2,c&&JSON.parse(c)]}})})};t.useFetch=function(e,t){var r=e?[e,t.token,t.body]:null;var n=c.useMemo(function(){var e;return(e=t.fetch)!==null&&e!==void 0?e:function(e,r){return l(e,{method:t.method,token:r,body:t.body,authTokenHeader:t.authTokenHeader})}},[t.authTokenHeader,t.body,t.fetch,t.method]);var u=s.default(r,n,t.swrConfig),i=u.data,a=u.error;var d=c.useCallback(function(){return o(void 0,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:if(!r)return[3,2];return[4,s.mutate(r)];case 1:e.sent();e.label=2;case 2:return[2]}})})},[r]);return{data:i,error:a,refetch:d}};t.useAuthFetch=function(e,t,r){var n=t&&e?[t,e,r.body]:null;var u=c.useMemo(function(){var e;return(e=r.fetch)!==null&&e!==void 0?e:function(e,t){var n;return l(e,{method:r.method,token:t,body:r.body,authTokenHeader:(n=r.authTokenHeader)!==null&&n!==void 0?n:"X-Access-Token"})}},[r.authTokenHeader,r.body,r.fetch,r.method]);var i=s.default(n,u,r.swrConfig),a=i.data,d=i.error;var v=c.useCallback(function(){return o(void 0,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:if(!n)return[3,2];return[4,s.mutate(n)];case 1:e.sent();e.label=2;case 2:return[2]}})})},[n]);return{data:a,error:d,refetch:v}};t.useAuthBearerFetch=function(e,r,u){return t.useAuthFetch(e,r,n(n({},u),{authTokenHeader:"Authorization"}))}},949:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,u){function fulfilled(e){try{step(n.next(e))}catch(e){u(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){u(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var u=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,u,i,a;return a={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function verb(e){return function(t){return step([e,t])}}function step(a){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,u&&(i=a[0]&2?u["return"]:a[0]?u["throw"]||((i=u["return"])&&i.call(u),0):u.next)&&!(i=i.call(u,a[1])).done)return i;if(u=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;u=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1];i=a;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(a);break}if(i[2])r.ops.pop();r.trys.pop();continue}a=t.call(e,r)}catch(e){a=[6,e];u=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};Object.defineProperty(t,"__esModule",{value:true});t.useClipboardCopy=void 0;var i=r(297);var a=r(347);t.useClipboardCopy=function(e){var t=i.useCallback(function(t){return n(void 0,void 0,void 0,function(){var r,n;var i,a,o;return u(this,function(u){switch(u.label){case 0:r=t||(e===null||e===void 0?void 0:e.text);if(r===undefined){return[2,false]}return[4,(i=navigator===null||navigator===void 0?void 0:navigator.clipboard)===null||i===void 0?void 0:i.writeText(r).then(function(){return true}).catch(function(){return false})];case 1:n=u.sent();if(n){(a=e===null||e===void 0?void 0:e.onSuccess)===null||a===void 0?void 0:a.call(e,r)}else{(o=e===null||e===void 0?void 0:e.onFailure)===null||o===void 0?void 0:o.call(e,r)}return[2,n]}})})},[e]);a.useKeyboardShortcut(e===null||e===void 0?void 0:e.key,t);return t}}});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const useClipboardCopy: (options?: {
|
|
2
|
+
text?: string | undefined;
|
|
3
|
+
onSuccess?: ((text: string) => void) | undefined;
|
|
4
|
+
onFailure?: ((text: string) => void) | undefined;
|
|
5
|
+
key?: string | undefined;
|
|
6
|
+
} | undefined) => (otherText?: string | undefined) => Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useKeyboardShortcut: (key?: string | undefined, callback?: (() => void) | undefined) => void;
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const useClipboardCopy: (options?: {
|
|
2
|
+
text?: string | undefined;
|
|
3
|
+
onSuccess?: ((text: string) => void) | undefined;
|
|
4
|
+
onFailure?: ((text: string) => void) | undefined;
|
|
5
|
+
key?: string | undefined;
|
|
6
|
+
} | undefined) => (otherText?: string | undefined) => Promise<boolean>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { useCallback } from "react";
|
|
38
|
+
import { useKeyboardShortcut } from "./useKeyboardShortcut";
|
|
39
|
+
export var useClipboardCopy = function (options) {
|
|
40
|
+
var copy = useCallback(function (otherText) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
+
var copyText, successed;
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
return __generator(this, function (_d) {
|
|
44
|
+
switch (_d.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
copyText = otherText || (options === null || options === void 0 ? void 0 : options.text);
|
|
47
|
+
if (copyText === undefined) {
|
|
48
|
+
return [2 /*return*/, false];
|
|
49
|
+
}
|
|
50
|
+
return [4 /*yield*/, ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(copyText).then(function () { return true; }).catch(function () { return false; }))];
|
|
51
|
+
case 1:
|
|
52
|
+
successed = _d.sent();
|
|
53
|
+
if (successed) {
|
|
54
|
+
(_b = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _b === void 0 ? void 0 : _b.call(options, copyText);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
(_c = options === null || options === void 0 ? void 0 : options.onFailure) === null || _c === void 0 ? void 0 : _c.call(options, copyText);
|
|
58
|
+
}
|
|
59
|
+
return [2 /*return*/, successed];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}); }, [options]);
|
|
63
|
+
useKeyboardShortcut(options === null || options === void 0 ? void 0 : options.key, copy);
|
|
64
|
+
return copy;
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useKeyboardShortcut: (key?: string | undefined, callback?: (() => void) | undefined) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
export var useKeyboardShortcut = function (key, callback) {
|
|
3
|
+
useEffect(function () {
|
|
4
|
+
if (key === undefined || callback === undefined) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
var handler = function (event) {
|
|
8
|
+
if ((event.ctrlKey || event.metaKey) && event.key === key) {
|
|
9
|
+
callback();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
window.addEventListener("keydown", handler);
|
|
13
|
+
return function () {
|
|
14
|
+
window.removeEventListener("keydown", handler);
|
|
15
|
+
};
|
|
16
|
+
}, [key, callback]);
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matsuri-hooks",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"repository": "https://github.com/matsuri-tech/matsuri-hooks.git",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@commitlint/config-conventional": "^9.1.1",
|
|
29
29
|
"@testing-library/react": "^10.4.6",
|
|
30
30
|
"@testing-library/react-hooks": "^3.3.0",
|
|
31
|
+
"@testing-library/user-event": "^14.2.0",
|
|
31
32
|
"@types/jest": "^27.0.1",
|
|
32
33
|
"@types/react": "^16.9.43",
|
|
33
34
|
"@types/react-dom": "^16.9.8",
|