"use strict";(globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[]).push([[170],{96269:(e,t,r)=>{r.d(t,{A:()=>d});var a=r(86326),n=r(73634),i=r(51405);let u=a.use||(e=>{if("pending"===e.status)throw e;if("fulfilled"===e.status)return e.value;if("rejected"===e.status)throw e.reason;throw e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e}),l={dedupe:!0};i.qv.defineProperty(i.BE,"defaultValue",{value:i.sb});let s=(0,i.qm)((e,t,r)=>{let{cache:s,compare:d,suspense:o,fallbackData:c,revalidateOnMount:f,revalidateIfStale:b,refreshInterval:g,refreshWhenHidden:E,refreshWhenOffline:R,keepPreviousData:V}=r,[T,_,v,h]=i.bZ.get(s),[m,w]=(0,i.lK)(e),L=(0,a.useRef)(!1),p=(0,a.useRef)(!1),O=(0,a.useRef)(m),k=(0,a.useRef)(t),y=(0,a.useRef)(r),C=()=>y.current,S=()=>C().isVisible()&&C().isOnline(),[N,P,A,D]=(0,i.r9)(s,m),F=(0,a.useRef)({}).current,Z=(0,i.b0)(c)?r.fallback[m]:c,H=(e,t)=>{for(let r in F)if("data"===r){if(!d(e[r],t[r])&&(!(0,i.b0)(e[r])||!d(B,t[r])))return!1}else if(t[r]!==e[r])return!1;return!0},I=(0,a.useMemo)(()=>{let e=!!m&&!!t&&((0,i.b0)(f)?!C().isPaused()&&!o&&(!!(0,i.b0)(b)||b):f),r=t=>{let r=(0,i.rL)(t);return(delete r._k,e)?{isValidating:!0,isLoading:!0,...r}:r},a=N(),n=D(),u=r(a),l=a===n?u:r(n),s=u;return[()=>{let e=r(N());return H(e,s)?(s.data=e.data,s.isLoading=e.isLoading,s.isValidating=e.isValidating,s.error=e.error,s):(s=e,e)},()=>l]},[s,m]),q=(0,n.useSyncExternalStore)((0,a.useCallback)(e=>A(m,(t,r)=>{H(r,t)||e()}),[s,m]),I[0],I[1]),K=!L.current,j=T[m]&&T[m].length>0,M=q.data,U=(0,i.b0)(M)?Z:M,X=q.error,x=(0,a.useRef)(U),B=V?(0,i.b0)(M)?x.current:M:U,z=(!j||!!(0,i.b0)(X))&&(K&&!(0,i.b0)(f)?f:!C().isPaused()&&(o?!(0,i.b0)(U)&&b:(0,i.b0)(U)||b)),G=!!(m&&t&&K&&z),J=(0,i.b0)(q.isValidating)?G:q.isValidating,Q=(0,i.b0)(q.isLoading)?G:q.isLoading,W=(0,a.useCallback)(async e=>{let t,a;let n=k.current;if(!m||!n||p.current||C().isPaused())return!1;let u=!0,l=e||{},s=!v[m]||!l.dedupe,o=()=>i.dO?!p.current&&m===O.current&&L.current:m===O.current,c={isValidating:!1,isLoading:!1},f=()=>{P(c)},b=()=>{let e=v[m];e&&e[1]===a&&delete v[m]},g={isValidating:!0};(0,i.b0)(N().data)&&(g.isLoading=!0);try{if(s&&(P(g),r.loadingTimeout&&(0,i.b0)(N().data)&&setTimeout(()=>{u&&o()&&C().onLoadingSlow(m,r)},r.loadingTimeout),v[m]=[n(w),(0,i.lg)()]),[t,a]=v[m],t=await t,s&&setTimeout(b,r.dedupingInterval),!v[m]||v[m][1]!==a)return s&&o()&&C().onDiscarded(m),!1;c.error=i.ZH;let e=_[m];if(!(0,i.b0)(e)&&(a<=e[0]||a<=e[1]||0===e[1]))return f(),s&&o()&&C().onDiscarded(m),!1;let l=N().data;c.data=d(l,t)?l:t,s&&o()&&C().onSuccess(t,m,r)}catch(r){b();let e=C(),{shouldRetryOnError:t}=e;!e.isPaused()&&(c.error=r,s&&o()&&(e.onError(r,m,e),(!0===t||(0,i.Tn)(t)&&t(r))&&(!C().revalidateOnFocus||!C().revalidateOnReconnect||S())&&e.onErrorRetry(r,m,e,e=>{let t=T[m];t&&t[0]&&t[0](i.bu.ERROR_REVALIDATE_EVENT,e)},{retryCount:(l.retryCount||0)+1,dedupe:!0})))}return u=!1,f(),!0},[m,s]),Y=(0,a.useCallback)((...e)=>(0,i.mF)(s,O.current,...e),[]);if((0,i.Es)(()=>{k.current=t,y.current=r,(0,i.b0)(M)||(x.current=M)}),(0,i.Es)(()=>{if(!m)return;let e=W.bind(i.ZH,l),t=0,r=(0,i.aw)(m,T,(r,a={})=>{if(r==i.bu.FOCUS_EVENT){let r=Date.now();C().revalidateOnFocus&&r>t&&S()&&(t=r+C().focusThrottleInterval,e())}else if(r==i.bu.RECONNECT_EVENT)C().revalidateOnReconnect&&S()&&e();else if(r==i.bu.MUTATE_EVENT)return W();else if(r==i.bu.ERROR_REVALIDATE_EVENT)return W(a)});return p.current=!1,O.current=m,L.current=!0,P({_k:w}),z&&((0,i.b0)(U)||i.X3?e():(0,i.mf)(e)),()=>{p.current=!0,r()}},[m]),(0,i.Es)(()=>{let e;function t(){let t=(0,i.Tn)(g)?g(N().data):g;t&&-1!==e&&(e=setTimeout(r,t))}function r(){!N().error&&(E||C().isVisible())&&(R||C().isOnline())?W(l).then(t):t()}return t(),()=>{e&&(clearTimeout(e),e=-1)}},[g,E,R,m]),(0,a.useDebugValue)(B),o&&(0,i.b0)(U)&&m){if(!i.dO&&i.X3)throw Error("Fallback data is required when using suspense in SSR.");k.current=t,y.current=r,p.current=!1;let e=h[m];if((0,i.b0)(e)||u(Y(e)),(0,i.b0)(X)){let e=W(l);(0,i.b0)(B)||(e.status="fulfilled",e.value=!0),u(e)}else throw X}return{mutate:Y,get data(){return F.data=!0,B},get error(){return F.error=!0,X},get isValidating(){return F.isValidating=!0,J},get isLoading(){return F.isLoading=!0,Q}}}),d=(0,i.Ht)(s,e=>(t,r,a)=>(a.revalidateOnFocus=!1,a.revalidateIfStale=!1,a.revalidateOnReconnect=!1,e(t,r,a)))},13709:(e,t,r)=>{r.d(t,{Ay:()=>c});var a=r(86326),n=r(73634),i=r(51405);let u=a.use||(e=>{if("pending"===e.status)throw e;if("fulfilled"===e.status)return e.value;if("rejected"===e.status)throw e.reason;throw e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e}),l={dedupe:!0};i.qv.defineProperty(i.BE,"defaultValue",{value:i.sb});let s=(0,i.qm)((e,t,r)=>{let{cache:s,compare:d,suspense:o,fallbackData:c,revalidateOnMount:f,revalidateIfStale:b,refreshInterval:g,refreshWhenHidden:E,refreshWhenOffline:R,keepPreviousData:V}=r,[T,_,v,h]=i.bZ.get(s),[m,w]=(0,i.lK)(e),L=(0,a.useRef)(!1),p=(0,a.useRef)(!1),O=(0,a.useRef)(m),k=(0,a.useRef)(t),y=(0,a.useRef)(r),C=()=>y.current,S=()=>C().isVisible()&&C().isOnline(),[N,P,A,D]=(0,i.r9)(s,m),F=(0,a.useRef)({}).current,Z=(0,i.b0)(c)?r.fallback[m]:c,H=(e,t)=>{for(let r in F)if("data"===r){if(!d(e[r],t[r])&&(!(0,i.b0)(e[r])||!d(B,t[r])))return!1}else if(t[r]!==e[r])return!1;return!0},I=(0,a.useMemo)(()=>{let e=!!m&&!!t&&((0,i.b0)(f)?!C().isPaused()&&!o&&(!!(0,i.b0)(b)||b):f),r=t=>{let r=(0,i.rL)(t);return(delete r._k,e)?{isValidating:!0,isLoading:!0,...r}:r},a=N(),n=D(),u=r(a),l=a===n?u:r(n),s=u;return[()=>{let e=r(N());return H(e,s)?(s.data=e.data,s.isLoading=e.isLoading,s.isValidating=e.isValidating,s.error=e.error,s):(s=e,e)},()=>l]},[s,m]),q=(0,n.useSyncExternalStore)((0,a.useCallback)(e=>A(m,(t,r)=>{H(r,t)||e()}),[s,m]),I[0],I[1]),K=!L.current,j=T[m]&&T[m].length>0,M=q.data,U=(0,i.b0)(M)?Z:M,X=q.error,x=(0,a.useRef)(U),B=V?(0,i.b0)(M)?x.current:M:U,z=(!j||!!(0,i.b0)(X))&&(K&&!(0,i.b0)(f)?f:!C().isPaused()&&(o?!(0,i.b0)(U)&&b:(0,i.b0)(U)||b)),G=!!(m&&t&&K&&z),J=(0,i.b0)(q.isValidating)?G:q.isValidating,Q=(0,i.b0)(q.isLoading)?G:q.isLoading,W=(0,a.useCallback)(async e=>{let t,a;let n=k.current;if(!m||!n||p.current||C().isPaused())return!1;let u=!0,l=e||{},s=!v[m]||!l.dedupe,o=()=>i.dO?!p.current&&m===O.current&&L.current:m===O.current,c={isValidating:!1,isLoading:!1},f=()=>{P(c)},b=()=>{let e=v[m];e&&e[1]===a&&delete v[m]},g={isValidating:!0};(0,i.b0)(N().data)&&(g.isLoading=!0);try{if(s&&(P(g),r.loadingTimeout&&(0,i.b0)(N().data)&&setTimeout(()=>{u&&o()&&C().onLoadingSlow(m,r)},r.loadingTimeout),v[m]=[n(w),(0,i.lg)()]),[t,a]=v[m],t=await t,s&&setTimeout(b,r.dedupingInterval),!v[m]||v[m][1]!==a)return s&&o()&&C().onDiscarded(m),!1;c.error=i.ZH;let e=_[m];if(!(0,i.b0)(e)&&(a<=e[0]||a<=e[1]||0===e[1]))return f(),s&&o()&&C().onDiscarded(m),!1;let l=N().data;c.data=d(l,t)?l:t,s&&o()&&C().onSuccess(t,m,r)}catch(r){b();let e=C(),{shouldRetryOnError:t}=e;!e.isPaused()&&(c.error=r,s&&o()&&(e.onError(r,m,e),(!0===t||(0,i.Tn)(t)&&t(r))&&(!C().revalidateOnFocus||!C().revalidateOnReconnect||S())&&e.onErrorRetry(r,m,e,e=>{let t=T[m];t&&t[0]&&t[0](i.bu.ERROR_REVALIDATE_EVENT,e)},{retryCount:(l.retryCount||0)+1,dedupe:!0})))}return u=!1,f(),!0},[m,s]),Y=(0,a.useCallback)((...e)=>(0,i.mF)(s,O.current,...e),[]);if((0,i.Es)(()=>{k.current=t,y.current=r,(0,i.b0)(M)||(x.current=M)}),(0,i.Es)(()=>{if(!m)return;let e=W.bind(i.ZH,l),t=0,r=(0,i.aw)(m,T,(r,a={})=>{if(r==i.bu.FOCUS_EVENT){let r=Date.now();C().revalidateOnFocus&&r>t&&S()&&(t=r+C().focusThrottleInterval,e())}else if(r==i.bu.RECONNECT_EVENT)C().revalidateOnReconnect&&S()&&e();else if(r==i.bu.MUTATE_EVENT)return W();else if(r==i.bu.ERROR_REVALIDATE_EVENT)return W(a)});return p.current=!1,O.current=m,L.current=!0,P({_k:w}),z&&((0,i.b0)(U)||i.X3?e():(0,i.mf)(e)),()=>{p.current=!0,r()}},[m]),(0,i.Es)(()=>{let e;function t(){let t=(0,i.Tn)(g)?g(N().data):g;t&&-1!==e&&(e=setTimeout(r,t))}function r(){!N().error&&(E||C().isVisible())&&(R||C().isOnline())?W(l).then(t):t()}return t(),()=>{e&&(clearTimeout(e),e=-1)}},[g,E,R,m]),(0,a.useDebugValue)(B),o&&(0,i.b0)(U)&&m){if(!i.dO&&i.X3)throw Error("Fallback data is required when using suspense in SSR.");k.current=t,y.current=r,p.current=!1;let e=h[m];if((0,i.b0)(e)||u(Y(e)),(0,i.b0)(X)){let e=W(l);(0,i.b0)(B)||(e.status="fulfilled",e.value=!0),u(e)}else throw X}return{mutate:Y,get data(){return F.data=!0,B},get error(){return F.error=!0,X},get isValidating(){return F.isValidating=!0,J},get isLoading(){return F.isLoading=!0,Q}}}),d=e=>(0,i.lK)(e?e(0,null):null)[0],o=Promise.resolve(),c=(0,i.Ht)(s,e=>(t,r,u)=>{let l;let s=(0,a.useRef)(!1),{cache:c,initialSize:f=1,revalidateAll:b=!1,persistSize:g=!1,revalidateFirstPage:E=!0,revalidateOnMount:R=!1,parallel:V=!1}=u,[,,,T]=i.bZ.get(i.PP);try{(l=d(t))&&(l=i.q9+l)}catch(e){}let[_,v,h]=(0,i.r9)(c,l),m=(0,a.useCallback)(()=>(0,i.b0)(_()._l)?f:_()._l,[c,l,f]);(0,n.useSyncExternalStore)((0,a.useCallback)(e=>l?h(l,()=>{e()}):()=>{},[c,l]),m,m);let w=(0,a.useCallback)(()=>{let e=_()._l;return(0,i.b0)(e)?f:e},[l,f]),L=(0,a.useRef)(w());(0,i.Es)(()=>{if(!s.current){s.current=!0;return}l&&v({_l:g?L.current:w()})},[l,c]);let p=R&&!s.current,O=e(l,async e=>{let a=_()._i,n=_()._r;v({_r:i.ZH});let l=[],s=w(),[d]=(0,i.r9)(c,e),o=d().data,f=[],g=null;for(let e=0;e{if(s in T){let e=T[s];delete T[s],v=await e}else v=await r(d);_({data:v,_k:d}),l[e]=v};V?f.push(t):await t()}else l[e]=v;V||(g=v)}return V&&await Promise.all(f.map(e=>e())),v({_i:i.ZH}),l},u),k=(0,a.useCallback)(function(e,t){let r="boolean"==typeof t?{revalidate:t}:t||{},a=!1!==r.revalidate;return l?(a&&((0,i.b0)(e)?v({_i:!0,_r:r.revalidate}):v({_i:!1,_r:r.revalidate})),arguments.length?O.mutate(e,{...r,revalidate:a}):O.mutate()):o},[l,c]),y=(0,a.useCallback)(e=>{let r;if(!l)return o;let[,a]=(0,i.r9)(c,l);if((0,i.Tn)(e)?r=e(w()):"number"==typeof e&&(r=e),"number"!=typeof r)return o;a({_l:r}),L.current=r;let n=[],[u]=(0,i.r9)(c,l),s=null;for(let e=0;e