"use strict";(globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[]).push([[4654],{98780:(e,t,r)=>{r.r(t),r.d(t,{DevTools:()=>T,useAtomDevtools:()=>A,useAtomsDebugValue:()=>g,useAtomsDevtools:()=>w,useAtomsSnapshot:()=>y,useGotoAtomsSnapshot:()=>b});var n=r(86326),u=r(5863),s=e=>!!e&&"dev4_get_internal_weak_map"in e,o=e=>!s(e),a=e=>"subscribeStore"in e,i=e=>{let{sub:t,set:r,get:n}=e,u=new Set,s=new WeakMap,o=(e,t)=>{let r=s.get(e);"number"==typeof r&&(r>1?s.set(e,r-1):s.delete(e),t?.())},a=e=>{let t=s.get(e);s.set(e,(t||0)+1)};return e.sub=(...e)=>{let r=t(...e);return u.forEach(e=>e({type:"sub"})),()=>{r(),o(e[0]),u.forEach(e=>e({type:"unsub"}))}},e.get=(...e)=>{let t=n(...e);return o(e[0],()=>{t instanceof Promise&&t.then(()=>{Promise.resolve().then(()=>{u.forEach(e=>e({type:"async-get"}))})})}),u.forEach(e=>e({type:"get"})),t},e.set=(...e)=>{let t=r(...e);return a(e[0]),u.forEach(e=>e({type:"set"})),t},e.subscribeStore=e=>(u.add(e),()=>{u.delete(e)}),e.getMountedAtoms=()=>e.dev4_get_mounted_atoms(),e.getAtomState=t=>{let r=e.dev4_get_internal_weak_map().get(t);if(r)return{v:r.v,e:r.e,d:new Set(r.d.keys())}},e.getMountedAtomState=t=>{let r=e.dev4_get_internal_weak_map().get(t);if(r&&r.m)return{l:r.m.l,t:r.m.t}},e.restoreAtoms=t=>{e.dev4_restore_atoms(t),u.forEach(e=>e({type:"restore"}))},e},c=e=>{if("dev_subscribe_store"in e&&"dev_get_mounted_atoms"in e&&"dev_get_atom_state"in e&&"dev_get_mounted"in e&&"dev_restore_atoms"in e){let{dev_subscribe_store:t,dev_get_mounted_atoms:r,dev_get_atom_state:n,dev_get_mounted:u,dev_restore_atoms:s}=e;e.subscribeStore=e=>t(t=>{("write"===t.type||"async-write"===t.type)&&e({type:"set"}),"sub"===t.type&&e({type:"sub"}),"unsub"===t.type&&e({type:"unsub"}),"restore"===t.type&&e({type:"restore"})},2),e.getMountedAtoms=()=>r(),e.getAtomState=e=>{let t=n(e);if(t){let r=new Set(t.d.keys());return(r.delete(e),"v"in t)?{v:t.v,d:r}:"e"in t?{e:t.e,d:r}:void 0}},e.getMountedAtomState=e=>u(e),e.restoreAtoms=e=>{s(e)}}return e},l=e=>a(e)?e:s(e)?i(e):o(e)?c(e):e,f=e=>l((0,u.Pj)(e)),d=(e,t)=>e.size===t.size&&Array.from(e).every(([e,r])=>Object.is(t.get(e),r)),p=(e,t)=>e.size===t.size&&Array.from(e).every(([e,r])=>{let n=t.get(e);return n&&r.size===n.size&&Array.from(r).every(e=>n.has(e))});function y({shouldShowPrivateAtoms:e=!1,...t}={}){let r=f(t),[u,s]=(0,n.useState)(()=>({values:new Map,dependents:new Map})),o=(0,n.useRef)(!0);return o.current=!0,(0,n.useLayoutEffect)(()=>{o.current=!1}),(0,n.useEffect)(()=>{if(!a(r))return;let t=new Map,n=new Map,u=()=>{let u=new Map,a=new Map;for(let t of r.getMountedAtoms()||[]){if(!e&&t.debugPrivate)continue;let n=r.getAtomState(t);n&&"v"in n&&u.set(t,n.v);let s=r.getMountedAtomState(t);if(s){let r=s.t;e||(r=new Set(Array.from(r.values()).filter(e=>!e.debugPrivate))),a.set(t,r)}}if(d(t,u)&&p(n,a))return;t=u,n=a;let i=()=>s({values:u,dependents:a});o.current?Promise.resolve().then(i):i()},i=r.subscribeStore(u);return u(),i},[r,e]),u}function b(e){let t=f(e);return(0,n.useCallback)(e=>{a(t)&&t.restoreAtoms(e.values)},[t])}var m=e=>e.debugLabel||e.toString(),_=([e,t])=>Object.fromEntries(t.flatMap(t=>{let r=a(e)&&e.getMountedAtomState(t);if(!r)return[];let n=r.t,u=e.getAtomState(t)||{};return[[m(t),{..."e"in u&&{error:u.e},..."v"in u&&{value:u.v},dependents:Array.from(n).map(m)}]]})),g=e=>{let t=e?.enabled??!1,r=f(e),[u,s]=(0,n.useState)([]),o=(0,n.useRef)(!0);o.current=!0,(0,n.useLayoutEffect)(()=>{o.current=!1}),(0,n.useEffect)(()=>{if(!t||!a(r))return;let e=()=>{let e=()=>s(Array.from(r.getMountedAtoms()||[]));o.current?Promise.resolve().then(e):e()},n=r.subscribeStore(e);return e(),n},[t,r]),(0,n.useDebugValue)([r,u],_)},v=(e,t)=>{if(e)return Object.assign(e.connect({name:t}),{shouldInit:!0})},S=(e=!1)=>{if(e)return window.__REDUX_DEVTOOLS_EXTENSION__};function A(e,t){let{enabled:r,name:s}=t||{},o=S(r),[a,i]=(0,u.fp)(e,t),c=(0,n.useRef)(a),l=(0,n.useRef)(!1),f=(0,n.useRef)(),d=s||e.debugLabel||e.toString();(0,n.useEffect)(()=>{if(!o)return;let t=t=>{if("function"==typeof i){i(t);return}console.warn("[Warn] you cannot do write operations (Time-travelling, etc) in read-only atoms\n",e)};return f.current=v(o,d),f.current?.subscribe(e=>{if("ACTION"===e.type&&e.payload)try{t(JSON.parse(e.payload))}catch(e){console.error("please dispatch a serializable value that JSON.parse() support\n",e)}else"DISPATCH"===e.type&&e.state?(e.payload?.type==="JUMP_TO_ACTION"||e.payload?.type==="JUMP_TO_STATE")&&(l.current=!0,t(JSON.parse(e.state))):"DISPATCH"===e.type&&e.payload?.type==="COMMIT"?f.current?.init(c.current):"DISPATCH"===e.type&&e.payload?.type==="IMPORT_STATE"&&(e.payload.nextLiftedState?.computedStates||[]).forEach(({state:e},r)=>{0===r?f.current?.init(e):t(e)})})},[e,o,d,i]),(0,n.useEffect)(()=>{f.current&&(c.current=a,f.current.shouldInit?(f.current.init(a),f.current.shouldInit=!1):l.current?l.current=!1:f.current.send(`${d} - ${new Date().toLocaleString()}`,a))},[e,o,d,a])}var h=e=>e.debugLabel?`${e}:${e.debugLabel}`:`${e}`,E=e=>{let t={};e.values.forEach((e,r)=>{t[h(r)]=e});let r={};return e.dependents.forEach((e,t)=>{r[h(t)]=Array.from(e).map(h)}),{values:t,dependents:r}};function w(e,t){let{enabled:r}=t||{},u=S(r),s=y(t),o=b(t),a=(0,n.useRef)(!1),i=(0,n.useRef)(!0),c=(0,n.useRef)(),l=(0,n.useRef)([]);(0,n.useEffect)(()=>{if(!u)return;let t=(e=l.current.length-1)=>{let t=l.current[e>=0?e:0];if(!t)throw Error("snapshot index out of bounds");return t};c.current=v(u,e);let r=c.current?.subscribe(e=>{if("DISPATCH"===e.type)switch(e.payload?.type){case"RESET":break;case"COMMIT":c.current?.init(E(t())),l.current=[];break;case"JUMP_TO_ACTION":case"JUMP_TO_STATE":a.current=!0,o(t(e.payload.actionId-1));break;case"PAUSE_RECORDING":i.current=!i.current}});return()=>{u?.disconnect?.(),r?.()}},[u,o,e]),(0,n.useEffect)(()=>{if(c.current){if(c.current.shouldInit){c.current.init(void 0),c.current.shouldInit=!1;return}a.current?a.current=!1:i.current&&(l.current.push(s),c.current.send({type:`${l.current.length}`,updatedAt:new Date().toLocaleString()},E(s)))}},[s])}var T=()=>null}}]); //# sourceMappingURL=chunk.npm-async-jotai-devtools.a48efa18.js.map