"use strict";(globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[]).push([[5212],{5863:(e,t,n)=>{n.d(t,{Kq:()=>u,Pj:()=>o,Xr:()=>f,fp:()=>c,md:()=>d});var r=n(86326),l=n(49791);let i=(0,r.createContext)(void 0),o=e=>{let t=(0,r.useContext)(i);return(null==e?void 0:e.store)||t||(0,l.zp)()},u=({children:e,store:t})=>{let n=(0,r.useRef)();return t||n.current||(n.current=(0,l.y$)()),(0,r.createElement)(i.Provider,{value:t||n.current},e)},a=e=>"function"==typeof(null==e?void 0:e.then),s=r.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});function d(e,t){let n=o(t),[[l,i,u],d]=(0,r.useReducer)(t=>{let r=n.get(e);return Object.is(t[0],r)&&t[1]===n&&t[2]===e?t:[r,n,e]},void 0,()=>[n.get(e),n,e]),f=l;(i!==n||u!==e)&&(d(),f=n.get(e));let c=null==t?void 0:t.delay;return(0,r.useEffect)(()=>{let t=n.sub(e,()=>{if("number"==typeof c){setTimeout(d,c);return}d()});return d(),t},[n,e,c]),(0,r.useDebugValue)(f),a(f)?s(f):f}function f(e,t){let n=o(t);return(0,r.useCallback)((...t)=>{if(!("write"in e))throw Error("not writable atom");return n.set(e,...t)},[n,e])}function c(e,t){return[d(e,t),f(e,t)]}},19189:(e,t,n)=>{n.d(t,{RH:()=>i}),n(86326);var r=n(5863);let l=new WeakMap;function i(e,t){let n=(0,r.Pj)(t),l=o(n);for(let[r,i]of e)(!l.has(r)||(null==t?void 0:t.dangerouslyForceHydrate))&&(l.add(r),n.set(r,i))}let o=e=>{let t=l.get(e);return t||(t=new WeakSet,l.set(e,t)),t}},49791:(e,t,n)=>{let r;n.d(t,{eU:()=>i,y$:()=>O,zp:()=>j});let l=0;function i(e,t){let n=`atom${++l}`,r={toString(){return this.debugLabel?n+":"+this.debugLabel:n}};return"function"==typeof e?r.read=e:(r.init=e,r.read=o,r.write=u),t&&(r.write=t),r}function o(e){return e(this)}function u(e,t,n){return t(this,"function"==typeof n?n(e(this)):n)}let a=(e,t)=>e.unstable_is?e.unstable_is(t):t===e,s=e=>"init"in e,d=e=>!!e.write,f=Symbol("CONTINUE_PROMISE"),c="pending",v=e=>"object"==typeof e&&null!==e&&f in e,m=new WeakMap,w=(e,t,n)=>{if(!m.has(e)){let r;let l=new Promise((i,o)=>{let u=e,a=e=>t=>{u===e&&(l.status="fulfilled",l.value=t,i(t),n())},s=e=>t=>{u===e&&(l.status="rejected",l.reason=t,o(t),n())};e.then(a(e),s(e)),r=(e,n)=>{e&&(m.set(e,l),u=e,e.then(a(e),s(e)),t(),t=n)}});l.status=c,l[f]=r,m.set(e,l)}return m.get(e)},b=e=>"function"==typeof(null==e?void 0:e.then),h=e=>"v"in e||"e"in e,g=e=>{if("e"in e)throw e.e;if(!("v"in e))throw Error("[Bug] atom state is not initialized");return e.v},p=e=>{let t=e.v;return v(t)&&t.status===c?t:null},y=(e,t,n)=>{n.p.has(e)||(n.p.add(e),t.then(()=>{n.p.delete(e)},()=>{n.p.delete(e)}))},_=()=>[new Map,new Map,new Set],S=(e,t,n)=>{e[0].has(t)||e[0].set(t,new Set),e[1].set(t,n)},E=(e,t,n)=>{let r=e[0].get(t);r&&r.add(n)},k=(e,t)=>e[0].get(t),T=(e,t)=>{e[2].add(t)},I=e=>{for(;e[1].size||e[2].size;){e[0].clear();let t=new Set(e[1].values());e[1].clear();let n=new Set(e[2]);e[2].clear(),t.forEach(e=>{var t;return null==(t=e.m)?void 0:t.l.forEach(e=>e())}),n.forEach(e=>e())}},O=()=>{let e;let t=new WeakMap;e=new Set;let n=e=>{let n=t.get(e);return n||(n={d:new Map,p:new Set,n:0},t.set(e,n)),n},r=(e,t,r,l=()=>{},i=()=>{})=>{let o="v"in t,u=t.v,a=p(t);if(b(r)){if(a)a!==r&&(a[f](r,l),++t.n);else{let o=w(r,l,i);if(o.status===c)for(let r of t.d.keys())y(e,o,n(r));t.v=o,delete t.e}}else a&&a[f](Promise.resolve(r),l),t.v=r,delete t.e;(!o||!Object.is(u,t.v))&&++t.n},l=(e,t,r,l)=>{var i;if(r===t)throw Error("[Bug] atom cannot depend on itself");let o=n(t);o.d.set(r,l.n);let u=p(o);u&&y(t,u,l),null==(i=l.m)||i.t.add(t),e&&E(e,r,t)},i=(e,t,o)=>{let u,f;let c=n(t);if(!(null==o?void 0:o(t))&&h(c)&&(c.m||Array.from(c.d).every(([t,n])=>i(e,t,o).n===n)))return c;c.d.clear();let w=!0;try{let b=t.read(u=>{if(a(t,u)){let e=n(u);if(!h(e)){if(s(u))r(u,e,u.init);else throw Error("no atom init")}return g(e)}let d=i(e,u,o);if(w)l(e,t,u,d);else{let e=_();l(e,t,u,d),m(e,t,c),I(e)}return g(d)},{get signal(){return u||(u=new AbortController),u.signal},get setSelf(){return d(t)||console.warn("setSelf function cannot be used with read-only atom"),!f&&d(t)&&(f=(...e)=>{if(w&&console.warn("setSelf function cannot be called in sync"),!w)return v(t,...e)}),f}});return r(t,c,b,()=>null==u?void 0:u.abort(),()=>{if(c.m){let e=_();m(e,t,c),I(e)}}),c}catch(e){return delete c.v,c.e=e,++c.n,c}finally{w=!1}},o=(e,t)=>{let r=t=>{var r,l;let i=n(t),o=new Set(null==(r=i.m)?void 0:r.t);for(let e of i.p)o.add(e);return null==(l=k(e,t))||l.forEach(e=>{o.add(e)}),o},l=[],o=new Set,u=e=>{if(!o.has(e)){for(let t of(o.add(e),r(e)))e!==t&&u(t);l.push(e)}};u(t);let a=new Set([t]),s=e=>o.has(e);for(let t=l.length-1;t>=0;--t){let r=l[t],u=n(r),d=u.n,f=!1;for(let e of u.d.keys())if(e!==r&&a.has(e)){f=!0;break}f&&(i(e,r,s),m(e,r,u),d!==u.n&&(S(e,r,u),a.add(r))),o.delete(r)}},u=(e,t,...l)=>t.write(t=>g(i(e,t)),(l,...i)=>{let d;if(a(t,l)){if(!s(l))throw Error("atom not writable");let t=n(l),u="v"in t,a=t.v;r(l,t,i[0]),m(e,l,t),u&&Object.is(a,t.v)||(S(e,l,t),o(e,l))}else d=u(e,l,...i);return I(e),d},...l),v=(e,...t)=>{let n=_(),r=u(n,e,...t);return I(n),r},m=(e,t,n)=>{if(n.m&&!p(n)){for(let r of n.d.keys())n.m.d.has(r)||(O(e,r).t.add(t),n.m.d.add(r));for(let r of n.m.d||[])if(!n.d.has(r)){n.m.d.delete(r);let l=j(e,r);null==l||l.t.delete(t)}}},O=(t,r)=>{let l=n(r);if(!l.m){for(let e of(i(t,r),l.d.keys()))O(t,e).t.add(r);if(l.m={l:new Set,d:new Set(l.d.keys()),t:new Set},e.add(r),d(r)&&r.onMount){let e=l.m,{onMount:n}=r;T(t,()=>{let l=n((...e)=>u(t,r,...e));l&&(e.u=l)})}}return l.m},j=(t,r)=>{let l=n(r);if(l.m&&!l.m.l.size&&!Array.from(l.m.t).some(e=>{var t;return null==(t=n(e).m)?void 0:t.d.has(r)})){let n=l.m.u;for(let i of(n&&T(t,n),delete l.m,e.delete(r),l.d.keys())){let e=j(t,i);null==e||e.t.delete(r)}let i=p(l);i&&i[f](void 0,()=>{});return}return l.m},M={get:e=>g(i(void 0,e)),set:v,sub:(e,t)=>{let n=_(),r=O(n,e);I(n);let l=r.l;return l.add(t),()=>{l.delete(t);let n=_();j(n,e),I(n)}}};return Object.assign(M,{dev4_get_internal_weak_map:()=>t,dev4_get_mounted_atoms:()=>e,dev4_restore_atoms:e=>{let t=_();for(let[l,i]of e)if(s(l)){let e=n(l),u="v"in e,a=e.v;r(l,e,i),m(t,l,e),u&&Object.is(a,e.v)||(S(t,l,e),o(t,l))}I(t)}}),M},j=()=>(r||(r=O(),globalThis.__JOTAI_DEFAULT_STORE__||(globalThis.__JOTAI_DEFAULT_STORE__=r),globalThis.__JOTAI_DEFAULT_STORE__!==r&&console.warn("Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044")),r)},17597:(e,t,n)=>{n.d(t,{mg:()=>a,tG:()=>f,zx:()=>c});var r=n(49791);let l=Symbol("RESET"),i=(e,t,n)=>(t.has(n)?t:t.set(n,e())).get(n),o=new WeakMap,u=(e,t,n,r)=>{let l=i(()=>new WeakMap,o,t),u=i(()=>new WeakMap,l,n);return i(e,u,r)};function a(e,t,n=Object.is){return u(()=>{let l=Symbol(),i=([e,r])=>{if(r===l)return t(e);let i=t(e,r);return n(r,i)?r:i},o=(0,r.eU)(t=>{let n=t(o);return i([t(e),n])});return o.init=l,o},e,t,n)}let s=e=>"function"==typeof(null==e?void 0:e.then),d=function(e=()=>{try{return window.localStorage}catch(e){"undefined"!=typeof window&&console.warn(e);return}},t){var n;let r,l,i;let o={getItem:(t,n)=>{var i,o;let u=e=>{if(r!==(e=e||"")){try{l=JSON.parse(e,void 0)}catch(e){return n}r=e}return l},a=null!=(o=null==(i=e())?void 0:i.getItem(t))?o:null;return s(a)?a.then(u):u(a)},setItem:(t,n)=>{var r;return null==(r=e())?void 0:r.setItem(t,JSON.stringify(n,void 0))},removeItem:t=>{var n;return null==(n=e())?void 0:n.removeItem(t)}};try{i=null==(n=e())?void 0:n.subscribe}catch(e){}if(!i&&"undefined"!=typeof window&&"function"==typeof window.addEventListener&&window.Storage&&(i=(t,n)=>{if(!(e() instanceof window.Storage))return()=>{};let r=r=>{r.storageArea===e()&&r.key===t&&n(r.newValue)};return window.addEventListener("storage",r),()=>{window.removeEventListener("storage",r)}}),i){let e;o.subscribe=(e=i,(t,n,r)=>e(t,e=>{let t;try{t=JSON.parse(e||"")}catch(e){t=r}n(t)}))}return o}();function f(e,t,n=d,i){let o=null==i?void 0:i.getOnInit,u=(0,r.eU)(o?n.getItem(e,t):t);return u.debugPrivate=!0,u.onMount=r=>{let l;return r(n.getItem(e,t)),n.subscribe&&(l=n.subscribe(e,r,t)),l},(0,r.eU)(e=>e(u),(r,i,o)=>{let a="function"==typeof o?o(r(u)):o;return a===l?(i(u,t),n.removeItem(e)):a instanceof Promise?a.then(t=>(i(u,t),n.setItem(e,t))):(i(u,a),n.setItem(e,a))})}function c(e,t){let n=e=>{if("e"in e)throw e.e;return e.d},l=(0,r.eU)(n=>{var l;let i,o,u,a,s;let d=e(n),f=null==(l=d[Symbol.observable])?void 0:l.call(d);f&&(d=f);let c=()=>new Promise(e=>{i=e}),v=t&&"initialValue"in t?{d:"function"==typeof t.initialValue?t.initialValue():t.initialValue}:c(),m=e=>{u=e,null==i||i(e),null==o||o(e)},w=()=>!o,b=()=>{a&&(clearTimeout(s),a.unsubscribe()),a=d.subscribe({next:e=>m({d:e}),error:e=>m({e}),complete:()=>{}}),w()&&(null==t?void 0:t.unstable_timeout)&&(s=setTimeout(()=>{a&&(a.unsubscribe(),a=void 0)},t.unstable_timeout))};b();let h=(0,r.eU)(u||v);return h.debugPrivate=!0,h.onMount=e=>(o=e,u&&e(u),a?clearTimeout(s):b(),()=>{o=void 0,a&&(a.unsubscribe(),a=void 0)}),[h,d,c,b,w]});return l.debugPrivate=!0,(0,r.eU)(e=>{let[t]=e(l),r=e(t);return r instanceof Promise?r.then(n):n(r)},(e,t,n)=>{let[r,i,o,u,a]=e(l);if("next"in i)a()&&(t(r,o()),u()),i.next(n);else throw Error("observable is not subject")})}}}]); //# sourceMappingURL=npm-jotai.38b412f8.js.map