@panphora/clayjs 1.19.0 → 1.21.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/dist/all.js +1 -1
- package/dist/clay-dom.js +1 -1
- package/dist/clay-events.js +1 -1
- package/dist/clay-internals.js +1 -1
- package/dist/clay-options.js +1 -1
- package/dist/clay-router.js +1 -1
- package/dist/clay-ui.js +1 -1
- package/dist/clay-utils.js +1 -1
- package/dist/clay.js +1 -1
- package/dist/clay.standalone.js +8349 -8125
- package/dist/m/attrs/{refetch-on-save-ZUE7PSCI.js → refetch-on-save-DPGJJMGN.js} +1 -1
- package/dist/m/attrs/save-freeze-MTFVVYV5.js +1 -0
- package/dist/m/{c-DHUCEMXE.js → c-2VB555FG.js} +1 -1
- package/dist/m/{c-KGHVFRR3.js → c-3AXJDL2P.js} +1 -1
- package/dist/m/{c-FOOE4GML.js → c-3GJ4XARY.js} +1 -1
- package/dist/m/c-3TWCKFOP.js +1 -0
- package/dist/m/{c-LPCZOYTX.js → c-3YH6JSIL.js} +1 -1
- package/dist/m/{c-AIWN4QN4.js → c-44B5ODN7.js} +2 -2
- package/dist/m/{c-WQWIRWO3.js → c-5FEU5MMY.js} +1 -1
- package/dist/m/{c-S2U6NJU4.js → c-62HZW5DH.js} +1 -1
- package/dist/m/{c-ZGDYHKG3.js → c-67ILSNPR.js} +1 -1
- package/dist/m/c-67LGZ52V.js +20 -0
- package/dist/m/{c-ZRUQ5FSU.js → c-7SXYQCN4.js} +1 -1
- package/dist/m/{c-LACAAQFB.js → c-AL4RBJF2.js} +1 -1
- package/dist/m/{c-L42OLXWM.js → c-ANNFZFLN.js} +1 -1
- package/dist/m/{c-QO4HNGCQ.js → c-B4VYNXTQ.js} +1 -1
- package/dist/m/{c-7PRJCA3E.js → c-BJPZCWAV.js} +1 -1
- package/dist/m/{c-V52FE5FI.js → c-BTLFLLML.js} +1 -1
- package/dist/m/c-C4IIQZGJ.js +1 -0
- package/dist/m/{c-5T6NZHNM.js → c-CAWNFER6.js} +1 -1
- package/dist/m/c-CSNE5EIF.js +1 -0
- package/dist/m/{c-DVYGFTSK.js → c-DDDOKPI6.js} +2 -2
- package/dist/m/{c-2RARVIAK.js → c-DHXPDLW6.js} +1 -1
- package/dist/m/{c-WCXLG3MV.js → c-E4IBSAQM.js} +1 -1
- package/dist/m/{c-IVTRVENZ.js → c-EDSPKYMA.js} +1 -1
- package/dist/m/{c-2Y4DOHSY.js → c-EFD6QNTE.js} +1 -1
- package/dist/m/{c-7MG5RU63.js → c-EGTIAL6P.js} +1 -1
- package/dist/m/{c-FCNAO2MI.js → c-EOCKLMKX.js} +1 -1
- package/dist/m/{c-UXFUJEZO.js → c-EOCZ2YVL.js} +1 -1
- package/dist/m/{c-K72SY2TL.js → c-EZ7B5AZT.js} +1 -1
- package/dist/m/{c-UPD33ZPE.js → c-FDAXZ2PM.js} +1 -1
- package/dist/m/{c-P3CK66NT.js → c-FNVQAACK.js} +1 -1
- package/dist/m/c-FSWRGBVQ.js +1 -0
- package/dist/m/c-FTWGYI5E.js +1 -0
- package/dist/m/{c-WKNRJX3C.js → c-GKEATME6.js} +1 -1
- package/dist/m/{c-QINHDETP.js → c-GPGYKER7.js} +1 -1
- package/dist/m/{c-FWKHM4E7.js → c-GSRLXYWL.js} +1 -1
- package/dist/m/{c-B7J4K2AE.js → c-GVPNDIKJ.js} +2 -2
- package/dist/m/{c-D3E4WJ4M.js → c-HDWZEJHM.js} +49 -32
- package/dist/m/{c-FTQKI7SP.js → c-I2IFKJX2.js} +1 -1
- package/dist/m/c-ICMAOOGK.js +1 -0
- package/dist/m/{c-HUISJXHF.js → c-J3BXFTZS.js} +1 -1
- package/dist/m/{c-BIJALSRD.js → c-JDZDF2QM.js} +1 -1
- package/dist/m/{c-UDHIVLYH.js → c-JH5FF4NL.js} +1 -1
- package/dist/m/{c-OYRZ7XG2.js → c-JHJR5BQX.js} +1 -1
- package/dist/m/{c-V44KWI2L.js → c-JOH753EJ.js} +2 -2
- package/dist/m/{c-P3OFYUMA.js → c-JUE7B4OX.js} +1 -1
- package/dist/m/c-K76AUL4I.js +7 -0
- package/dist/m/{c-ZWIOJGMT.js → c-LA2BW7UY.js} +1 -1
- package/dist/m/{c-ICJYHABF.js → c-LDUNOR57.js} +1 -1
- package/dist/m/{c-XSZKP646.js → c-LIBE4HPD.js} +1 -1
- package/dist/m/c-LPUJXRXW.js +1 -0
- package/dist/m/{c-JK3PHE7J.js → c-LQU7TXIH.js} +1 -1
- package/dist/m/{c-5ZQV7KC4.js → c-LV5MABYD.js} +1 -1
- package/dist/m/{c-GWNC3UGL.js → c-M4FSPNQ2.js} +1 -1
- package/dist/m/{c-2KIEGNC4.js → c-MEWUGR4D.js} +1 -1
- package/dist/m/c-MIL4B2JQ.js +1 -0
- package/dist/m/{c-IVMD3FEM.js → c-N7Y52HJH.js} +1 -1
- package/dist/m/{c-O4JMKN6U.js → c-NFR673TL.js} +2 -2
- package/dist/m/{c-ZKNBMNN3.js → c-NLZ5AN4L.js} +1 -1
- package/dist/m/{c-RRZJWFLE.js → c-OABVRYOT.js} +1 -1
- package/dist/m/c-PIVIYLTY.js +1 -0
- package/dist/m/{c-L7JL5TL3.js → c-QY7F6EN6.js} +1 -1
- package/dist/m/{c-UY4QX42B.js → c-RG6XUZFA.js} +1 -1
- package/dist/m/c-RHMPKZZ7.js +1 -0
- package/dist/m/{c-TJAXGIRV.js → c-RQRMPZXD.js} +1 -1
- package/dist/m/{c-GY422N3Q.js → c-RS77ODLY.js} +1 -1
- package/dist/m/{c-BAUBNYXK.js → c-RT3C74GY.js} +1 -1
- package/dist/m/{c-CAS3NND4.js → c-S5IEIZCN.js} +1 -1
- package/dist/m/{c-HXPHZN7Q.js → c-SBSMJIPC.js} +1 -1
- package/dist/m/c-SFKI6OLM.js +2 -0
- package/dist/m/{c-4FJTBE6I.js → c-SJPD46ZO.js} +4 -4
- package/dist/m/{c-JCP3XDSJ.js → c-SO63UGPQ.js} +1 -1
- package/dist/m/{c-PLP4JKFC.js → c-TUGVINJR.js} +1 -1
- package/dist/m/{c-Q26MME6N.js → c-TWCXBWS3.js} +1 -1
- package/dist/m/{c-GNDL3TKB.js → c-U5X57T4L.js} +1 -1
- package/dist/m/{c-ZS4US2XV.js → c-UXEVJ63W.js} +1 -1
- package/dist/m/{c-KJJPV77R.js → c-V2J5C5MT.js} +1 -1
- package/dist/m/{c-7PYNAULW.js → c-VBLFAQD2.js} +1 -1
- package/dist/m/{c-ERQSNR6K.js → c-VQCEOGKH.js} +2 -2
- package/dist/m/{c-YVZ2L7CE.js → c-VSPAFOKU.js} +1 -1
- package/dist/m/{c-L6FLIUXP.js → c-VY6XRBOW.js} +1 -1
- package/dist/m/{c-2KL3BD52.js → c-W23KVGUO.js} +1 -1
- package/dist/m/{c-AXGY2WTB.js → c-W3K23S72.js} +1 -1
- package/dist/m/c-WFMRX5RZ.js +1 -0
- package/dist/m/{c-BWFVSBDF.js → c-WN3MXOLT.js} +1 -1
- package/dist/m/{c-MIKZEG5I.js → c-XD5MOROJ.js} +1 -1
- package/dist/m/{c-CQQDL6O4.js → c-XQSXKIKM.js} +1 -1
- package/dist/m/{c-I4MQHOEY.js → c-Y33LUUIQ.js} +1 -1
- package/dist/m/{c-JDARJDOT.js → c-YQUJ74R3.js} +1 -1
- package/dist/m/{c-F6G2OGYG.js → c-YSB6JKV2.js} +2 -2
- package/dist/m/{c-BHZYSHW4.js → c-ZJLU56DV.js} +1 -1
- package/dist/m/{c-DKLS74XB.js → c-ZQXNHZZT.js} +2 -2
- package/dist/m/{c-TNEM3RNM.js → c-ZSCBEB7I.js} +1 -1
- package/dist/m/core/{admin-attrs-YY7T5FGU.js → admin-attrs-ZG7R5V3E.js} +1 -1
- package/dist/m/core/{autosave-RVJPYLRT.js → autosave-VPORYJSE.js} +1 -1
- package/dist/m/core/{conflict-notice-2WGT52LH.js → conflict-notice-JMAZLVRX.js} +1 -1
- package/dist/m/core/{persist-UKXV5KLA.js → persist-3OPWJKZS.js} +1 -1
- package/dist/m/core/{recovery-ZOUOJVIX.js → recovery-DRFZRJED.js} +1 -1
- package/dist/m/core/{save-A5JXV6ME.js → save-AOJBDSOK.js} +1 -1
- package/dist/m/core/{save-core-MKRPSEEO.js → save-core-IOCMXO5L.js} +1 -1
- package/dist/m/core/{snapshot-NU3YM6GR.js → snapshot-O7II2AGG.js} +1 -1
- package/dist/m/core/unsaved-warning-U5VUJFOE.js +1 -0
- package/dist/m/events/{index-RN2JNGBV.js → index-B6TGDYMG.js} +1 -1
- package/dist/m/internals/{index-TGLQINN3.js → index-HDRANDWE.js} +1 -1
- package/dist/m/lib/{cache-bust-MUMFXZK6.js → cache-bust-NH7VBWHO.js} +1 -1
- package/dist/m/lib/{region-policy-SB2AWVG5.js → region-policy-KWBPROWF.js} +1 -1
- package/dist/m/{loader-34YPFKOH.js → loader-ZVPK4ZN3.js} +1 -1
- package/dist/m/manifest-5498AFD3.js +1 -0
- package/dist/m/manifest-edit-62A5A00F.js +1 -0
- package/dist/m/manifest.json +1215 -1171
- package/dist/m/options/{options-EJMS3K24.js → options-55LQHSJ4.js} +1 -1
- package/dist/m/page/{editor-WRQGHDSG.js → editor-EY2WAAGB.js} +2 -2
- package/dist/m/plugins/{ai-edit-X2L2KIEP.js → ai-edit-J5VLSW5I.js} +1 -1
- package/dist/m/plugins/{demo-OYO5GCAO.js → demo-42BSYQ7T.js} +1 -1
- package/dist/m/plugins/{derive-FRE5JJQE.js → derive-QVI3LI3A.js} +1 -1
- package/dist/m/plugins/{live-7C36XEI2.js → live-5EZN2EYP.js} +1 -1
- package/dist/m/plugins/menu-DM2JHPSR.js +1 -0
- package/dist/m/plugins/{page-BSW6MGDO.js → page-LVW5DWA4.js} +2 -2
- package/dist/m/plugins/{page-view-WFZVTPQK.js → page-view-5KQ76IJB.js} +1 -1
- package/dist/m/plugins/{sortable-4S6SQC3D.js → sortable-WJZZBM7R.js} +1 -1
- package/dist/m/plugins/{source-TJXOIOYY.js → source-CCEUM3OR.js} +1 -1
- package/dist/m/plugins/{undo-NLPGCJQY.js → undo-3JEYK5QY.js} +1 -1
- package/dist/m/plugins/{upgrade-HSUNDNJD.js → upgrade-NW556WJD.js} +1 -1
- package/dist/m/plugins/{upload-NHGJXZK2.js → upload-TTCQRIM5.js} +1 -1
- package/dist/m/plugins/{visitor-drafts-BW43DGY3.js → visitor-drafts-2AWNT23K.js} +2 -2
- package/dist/m/plugins/{visitor-drafts-owner-7ODQG7JX.js → visitor-drafts-owner-MZP45XSG.js} +1 -1
- package/dist/m/plugins/{wire-6OSIL3I7.js → wire-VRYPY6EJ.js} +1 -1
- package/dist/m/{reader-core-PLZYLYLT.js → reader-core-2GXY7SHY.js} +2 -2
- package/dist/m/sync/{live-sync-UXNI6ZF6.js → live-sync-SKPMFYOO.js} +1 -1
- package/dist/m/ui/{index-IVWN2QC4.js → index-QNIPDHXQ.js} +1 -1
- package/dist/m/vendor/{sap-core.vendor-RN4ZVY4X.js → sap-core.vendor-OA5SKL7Q.js} +1 -1
- package/dist/offline-manifest.json +650 -626
- package/docs/guide.md +38 -14
- package/entries/sap.js +1 -1
- package/package.json +3 -2
- package/src/core/conflict-download.js +8 -7
- package/src/core/conflict-notice-ui.js +4 -4
- package/src/core/copy-content.js +103 -0
- package/src/core/download.js +14 -2
- package/src/core/save-size-notice.js +2 -2
- package/src/core/upgrade-run.js +5 -1
- package/src/lib/region-policy.js +1 -1
- package/src/page/features/export-html.js +4 -4
- package/src/page/features/export-markdown.js +2 -2
- package/src/page/recovery-ui.js +2 -2
- package/src/page/save-states.js +4 -4
- package/src/plugins/menu/actions.js +1 -1
- package/src/plugins/menu/style.js +59 -31
- package/src/plugins/menu.js +131 -28
- package/src/plugins/page.js +4 -4
- package/src/plugins/visitor-drafts/prompt.js +12 -12
- package/src/plugins/wire.js +3 -1
- package/src/vendor/sap-core.vendor.js +1 -1
- package/dist/m/attrs/save-freeze-LWGF6XUN.js +0 -1
- package/dist/m/c-DCFSEJZG.js +0 -1
- package/dist/m/c-EXEDYU4H.js +0 -1
- package/dist/m/c-GRXHHFPO.js +0 -1
- package/dist/m/c-HT2DKBV2.js +0 -1
- package/dist/m/c-MCOOHCSG.js +0 -1
- package/dist/m/c-MMXKAX2W.js +0 -1
- package/dist/m/c-VE7RKNKZ.js +0 -7
- package/dist/m/c-VR2BJ4AN.js +0 -1
- package/dist/m/c-WGW764WX.js +0 -1
- package/dist/m/c-WNTYKCDG.js +0 -1
- package/dist/m/c-YBSS55KU.js +0 -20
- package/dist/m/core/unsaved-warning-4ZPEV7BF.js +0 -1
- package/dist/m/manifest-0D166F4F.js +0 -1
- package/dist/m/manifest-edit-3877153E.js +0 -1
- package/dist/m/plugins/menu-MFC4DI5E.js +0 -1
- /package/dist/m/{c-QTTJYJMA.js → c-FILLTJA7.js} +0 -0
- /package/dist/m/{c-5JLFROUB.js → c-X5LNHET5.js} +0 -0
- /package/dist/m/plugins/{people-JCHVPF7P.js → people-C7TVBBMR.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{F as mt,K as ot,O as $e,r as Ie,v as Le,w as ft,x as De}from"./c-EXKHPOVC.js";import{a as Ae,d as pt,g as Oe,h as ve}from"./c-L5VFATT6.js";import{f as Pe,o as Re}from"./c-CQQDL6O4.js";import{a as gt,c as Be}from"./c-ZGDYHKG3.js";import{b as Ne}from"./c-W4JCVLAB.js";import{B as w,C as zt,D as We,E as Ft,F as Ue,G as Ge,a as _e,d as P,e as S,f as He,h as J,i as ze,l as Fe,o as z,r as Ht,t as Ke,u as Ve,x as je,y as qe}from"./c-AIWN4QN4.js";import{D as ut,E as Me,F as R,G as A,H as N,I,J as k,K as dt,L as we,O as Y,T as Se,U as ht,V as Nt,W as Te,X as Ee,Y as Ce,b as C,d as Pt,f as at,g as ge,h as Rt,j as be,l as ye,m as g,oa as nt,p as ke,q as xe}from"./c-QIXT3Q7C.js";import{a as H}from"./c-WCXLG3MV.js";var Ye=new WeakMap;function Je(n){let t=Ye.get(n);if(t)return t;t={};for(let[e,o]of I(n.attrs.cols).entries()){let s=[];n.forEach(r=>{e<r.childCount&&s.push(r.child(e).textContent.trim())}),t[o]=Ee(n.attrs.cols[o].kind,s)}return Ye.set(n,t),t}var Cs=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),As=Object.freeze({text:"Text",number:"Number",date:"Date"});var Kt=(n,t,e)=>{let o=n.attrs.get(t.baseId),s={};for(let r of Oe(e))s[r]=o&&o.has(r)?o.get(r):ve(e,r);return e.name==="board"&&Object.assign(s,Le(n.boardFields,t.baseId)),e.name==="table"&&Object.assign(s,Ie(n.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},Xe=n=>n===void 0?n:JSON.parse(JSON.stringify(n)),qn=(n,t)=>{let e={},o=n.attrs.get(t.baseId);return o&&o.forEach((s,r)=>{r!=="pos"&&(e[r]=Xe(s))}),e.t=t.t,e};function Bs(n,t,e=null){let o=d=>{if(d.opaque){let a=d.recovered?{...Xe(d.fields??{})}:qn(n,d);return{b:d,type:g.nodes.opaque_block,fields:a,opaque:!0}}let u=g.nodes[d.t]??g.nodes.paragraph;return{b:d,type:u,fields:{...d.fields??Kt(n,d,u)}}},s=t.visible.map(d=>{let u=e?.get(d);return u?{b:d,node:u}:o(d)}),r=new Map(s.map((d,u)=>[d.b.id,u])),i=d=>s[d].node?s[d].node.attrs.parent:s[d].fields.parent,l=d=>(d.b.recovered?n.gone._map.get(mt(d.b.sourceKey,"parent")):n.attrs.get(d.b.baseId)?._map.get("parent"))?.id??{clock:-1,client:-1};for(let d of r.keys()){let u=new Map,a=[],h=d;for(;r.has(h)&&!u.has(h);)u.set(h,a.length),a.push(h),h=i(r.get(h));if(!u.has(h))continue;let f=a.slice(u.get(h)).reduce((b,x)=>{let O=l(s[r.get(b)]),_=l(s[r.get(x)]);return O.clock<_.clock||O.clock===_.clock&&O.client<_.client?b:x}),m=r.get(f);s[m].node&&(s[m]=o(s[m].b)),s[m].fields.parent=null}let c=s.map(({b:d,node:u,type:a,fields:h,opaque:p})=>{if(u)return u;if(p){let b=[];for(let x of d.runs)x.hole||(x.br?b.push(g.nodes.hard_break.create()):b.push(g.text(x.text,x.marks)));return a.create({id:d.id,pos:null,raw:h},b)}let f={id:d.id,pos:null,...h};if(a.name==="table"&&Object.keys(f.rows??{}).length&&Object.keys(f.cols??{}).length)return Y(g,d.id,{t:"table",...f});if(!a.isTextblock)return a.create(f);let m=[];for(let b of d.runs)b.hole||(b.br?m.push(g.nodes.hard_break.create()):m.push(g.text(b.text,b.marks)));return a.create(f,m)});return c.length?g.nodes.doc.create(null,c):g.nodes.doc.createAndFill()}var E=n=>({status:"refused",code:n}),bt=n=>JSON.parse(JSON.stringify(n)),Wn=["title","owner","due"],Un=/^\d{4}-\d{2}-\d{2}$/,yt=(n,t)=>n==="title"?typeof t=="string":n==="due"?t===null||typeof t=="string"&&Un.test(t):t===null||typeof t=="string"&&t.length>0,Gn=n=>n!==null&&typeof n=="object"&&!Array.isArray(n);function Qe(n,t){let e=t>0?n[t-1]:null,o=n.slice(t).find(r=>e===null||r>e)??null,s=r=>(e===null||r>e)&&(o===null||r<o);for(let[r,i]of[[e,o],[null,o],[e,null]]){if(r!==null&&!R(r)||i!==null&&!R(i)||r!==null&&i!==null&&r>=i)continue;let l=A(r,i);if(s(l))return l}return`${n.reduce((r,i)=>i>r?i:r,"")}V`}function Vt(n,t,e){let o=n.map(t),s=e>0?o[e-1]:null,r=e;for(;s!==null&&r<o.length&&o[r]===s;)r++;if(r===e)return{pos:Qe(o,e),rekey:[]};let i=o.slice(r).find(c=>c>s)??null,l=[];for(let c=e,d=s;c<=r;c++)l.push(d=Qe(i===null?[d]:[d,i],1));return{pos:l[0],rekey:n.slice(e,r).map((c,d)=>[c,l[d+1]])}}var kt=(n,t,e)=>{let{pos:o,rekey:s}=Vt(t,r=>n[r].pos,e);for(let[r,i]of s)n[r]={...n[r],pos:i};return o};function qs({pd:n,um:t=null,origins:e=null,render:o=()=>{}}){let s=u=>{if(typeof u!="string")return null;let a=$e(n,e).visible.find(p=>p.id===u);if(!a||a.t!=="board")return null;let h=a.fields??Kt(n,a,g.nodes.board);return{columns:bt(h.columns??{}),cards:bt(h.cards??{})}},r=(u,a,h,p)=>{let f=ot(u);return t?.stopCapturing(),n.ydoc.transact(()=>{if(!f)De(n,u,a,h);else for(let m of["columns","cards"])nt(a[m])!==nt(h[m])&&n.gone.set(mt(f,m),bt(h[m]))},Ae),t?.stopCapturing(),o(),p},i=(u,a,h=null)=>I(Object.fromEntries(Object.entries(u.cards).filter(([p,f])=>f.col===a&&p!==h))),l=(u,a)=>a===void 0?u.length:a===null?0:u.indexOf(a)+1,c=(u,a)=>a!=null&&!u.includes(a),d=(u,a)=>{let h=s(u);return h?a(h,bt(h)):E("missing-board")};return{read:u=>s(u),removed(u){return s(u)?ot(u)?{columns:{},cards:{}}:ft(n.boardFields,u):null},createColumn:(u,{name:a="",afterId:h}={})=>d(u,(p,f)=>{if(typeof a!="string")return E("invalid-value");let m=I(p.columns);if(c(m,h))return E("missing-destination");let b=k("c");return f.columns[b]={pos:kt(f.columns,m,l(m,h)),name:a},r(u,p,f,{status:"created",id:b})}),renameColumn:(u,a,h)=>d(u,(p,f)=>Object.hasOwn(p.columns,a)?typeof h!="string"?E("invalid-value"):p.columns[a].name===h?{status:"unchanged"}:(f.columns[a].name=h,r(u,p,f,{status:"changed"})):E("missing-column")),moveColumn:(u,a,{afterId:h=null}={})=>d(u,(p,f)=>{if(!Object.hasOwn(p.columns,a))return E("missing-column");let m=I(p.columns).filter(O=>O!==a);if(c(m,h))return E("missing-destination");let b=l(m,h),x=I(p.columns);return[...m.slice(0,b),a,...m.slice(b)].every((O,_)=>O===x[_])?{status:"unchanged"}:(f.columns[a].pos=kt(f.columns,m,b),r(u,p,f,{status:"moved"}))}),removeColumn:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.columns,a)?(delete p.columns[a],r(u,h,p,{status:"removed",cards:i(h,a).length})):E("missing-column")),restoreColumn:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.columns,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).columns[a];return f?(p.columns[a]=f,r(u,h,p,{status:"restored"})):E("missing-column")}),createCard:(u,{columnId:a,title:h="",owner:p=null,due:f=null,afterId:m}={})=>d(u,(b,x)=>{if(!Object.hasOwn(b.columns,a))return E("missing-column");if(!yt("title",h)||!yt("owner",p)||!yt("due",f))return E("invalid-value");let O=i(b,a);if(c(O,m))return E("missing-destination");let _=k("k");return x.cards[_]={pos:kt(x.cards,O,l(O,m)),col:a,title:h,...p!==null?{owner:p}:{},...f!==null?{due:f}:{}},r(u,b,x,{status:"created",id:_})}),editCard:(u,a,h)=>d(u,(p,f)=>{if(!Object.hasOwn(p.cards,a))return E("missing-card");if(!Gn(h)||!Object.keys(h).length||Object.keys(h).some(b=>!Wn.includes(b)))return E("invalid-field");if(Object.entries(h).some(([b,x])=>!yt(b,x)))return E("invalid-value");let m={...p.cards[a]};for(let[b,x]of Object.entries(h))x===null?delete m[b]:m[b]=x;return nt(m)===nt(p.cards[a])?{status:"unchanged"}:(f.cards[a]=m,r(u,p,f,{status:"changed"}))}),moveCard:(u,a,{columnId:h,afterId:p=null}={})=>d(u,(f,m)=>{if(!Object.hasOwn(f.cards,a))return E("missing-card");if(!Object.hasOwn(f.columns,h))return E("missing-column");let b=i(f,h,a);if(c(b,p))return E("missing-destination");let x=l(b,p),O=f.cards[a];if(O.col===h){let _=i(f,h);if([...b.slice(0,x),a,...b.slice(x)].every((ct,jn)=>ct===_[jn]))return{status:"unchanged"}}return m.cards[a]={...O,col:h,pos:kt(m.cards,b,x)},r(u,f,m,{status:"moved"})}),removeCard:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.cards,a)?(delete p.cards[a],r(u,h,p,{status:"removed"})):E("missing-card")),restoreCard:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.cards,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).cards[a];return f?(p.cards[a]=f,r(u,h,p,{status:"restored"})):E("missing-card")})}}var xt="page-history-intent",Yn=500,Jn=(n,t)=>{let e=n.resolve(t);return e.depth?e.node(1).attrs.id:null},Xn=n=>(n.storedMarks??n.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(",");function qt(n,t,e,o){return{kind:"insert",blockId:Jn(n.doc,t),from:t,end:t+o.length,replaced:t!==e,text:o,marks:Xn(n),at:Date.now()}}function Ys(n,t){return!n||!t||n.kind!==t.kind?!1:t.kind==="compose"?n.id===t.id:n.blockId!==t.blockId||t.at-n.at>Yn?!1:t.kind==="insert"?!t.replaced&&t.from===n.end&&t.marks===n.marks&&!(/\s$/.test(n.text)&&/^\S/.test(t.text)):t.direction===n.direction&&(t.direction<0?t.to===n.from:t.from===n.from)}var Qn={deleteContentBackward:-1,deleteContentForward:1},jt=new WeakMap,Zn=1e3,Wt="page-derived";function to(n){let t=jt.get(n)??null;return jt.delete(n),t}function eo(n,t){if(!t||n.before!==t.doc||Date.now()-t.at>Zn||n.getMeta(He)||n.steps.length!==1)return null;let e=n.steps[0];if(e.slice?.size!==0||e.from===e.to)return null;let o=n.before.resolve(e.from),s=n.before.resolve(e.to);return!o.parent.isTextblock||!o.sameParent(s)?null:{kind:"delete",blockId:o.depth?o.node(1).attrs.id:null,direction:t.direction,from:e.from,to:e.to,at:t.at}}function Js(n,t=null){let e=t?to(t):null,o=n.filter(i=>!i.getMeta(Wt));if(o.length!==1)return null;let s=o[0],r=s.getMeta("composition");return r!=null?{kind:"compose",id:r,at:Date.now()}:s.getMeta(xt)??eo(s,e)}function Xs(){return new C.Plugin({props:{handleTextInput(n,t,e,o,s){return n.dispatch(s().setMeta(xt,qt(n.state,t,e,o))),!0},handleDOMEvents:{beforeinput(n,t){let e=Qn[t.inputType];return e&&jt.set(n,{direction:e,at:Date.now(),doc:n.state.doc}),!1}}}})}function no(n,t){if(!n||!/<table[\s>]/i.test(n))return null;let e=t.defaultView?.DOMParser??globalThis.DOMParser;if(!e)return null;let o=new e().parseFromString(n,"text/html").body,s=[...o.querySelectorAll("table")].filter(d=>!d.parentElement.closest("table"));if(s.length!==1)return null;let r=o.cloneNode(!0);for(let d of r.querySelectorAll("table, style, script, template, meta, title"))d.remove();if(r.textContent.trim())return null;let i=s[0];return{grid:[...i.querySelectorAll("tr")].filter(d=>d.closest("table")===i).map(d=>[...d.children].filter(u=>u.tagName==="TD"||u.tagName==="TH").map(u=>dt(je.parse(u,{topNode:g.nodes.table_cell.create()})))).filter(d=>d.length),own:!!i.querySelector("td[data-col]")}}function oo(n){if(!n||!n.includes(" "))return null;let{header:t,rows:e}=ht(n.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...e],own:!1}}function Ze(n,t,e=globalThis.document){let o=null;try{o=no(n,e)}catch{o=null}if(!o&&!/<table[\s>]/i.test(n||""))try{o=oo(t)}catch{o=null}if(!o||!o.grid.length)return null;let s=Math.max(...o.grid.map(r=>r.length));for(let r of o.grid)for(;r.length<s;)r.push("");return{...o,width:s,height:o.grid.length}}function Mt(n,{header:t=n.length>1}={}){let e=Math.max(0,...n.map(a=>a.length));if(!e)return null;let o=t?n[0]:[],s=t?n.slice(1):n,r=Array.from({length:e},()=>k("c")),i=N(null,null,e),l=Object.fromEntries(r.map((a,h)=>[a,{pos:i[h],name:ut(o[h]??"").replace(/\s+/g," ").trim()||`Column ${h+1}`}])),c=s.length?s:[[]],d=N(null,null,c.length),u=Object.fromEntries(c.map((a,h)=>[k("r"),{pos:d[h],cells:Object.fromEntries(r.map((p,f)=>[p,a[f]??""]))}]));return Y(g,k(),{t:"table",pos:null,cols:l,rows:u})}var{Plugin:so,TextSelection:ro}=C,Ut=g.nodes;var on=(n,t)=>{let e=null;return n.forEach((o,s)=>{!e&&o.type===Ut.table&&o.attrs.id===t&&(e={node:o,pos:s})}),e};function V(n,t){if(!t)return null;let e=on(n,t.table);if(!e)return null;let o=[];e.node.forEach(p=>o.push(p.attrs.id));let s=I(e.node.attrs.cols),r=[o.indexOf(t.anchor[0]),o.indexOf(t.head[0])],i=[s.indexOf(t.anchor[1]),s.indexOf(t.head[1])];if(r.includes(-1)||i.includes(-1))return null;let l=Math.min(...r),c=Math.max(...r),d=Math.min(...i),u=Math.max(...i),a=[],h=e.pos+1;return e.node.forEach((p,f,m)=>{if(m>=l&&m<=c){let b=[],x=h+1;p.forEach((O,_,ct)=>{ct>=d&&ct<=u&&b.push({cell:O,pos:x}),x+=O.nodeSize}),a.push(b)}h+=p.nodeSize}),{...e,top:l,bottom:c,left:d,right:u,cells:a}}var st=(n,t)=>{let e=n.resolve(t);for(let o=e.depth;o>0;o--)if(e.node(o).type===Ut.table_cell&&o>=3)return{table:e.node(o-2).attrs.id,row:e.node(o-1).attrs.id,col:e.node(o).attrs.col,start:e.start(o)};return null};function wt(n,t,e){let o=st(n.state.doc,t),s=st(n.state.doc,e);if(!o||!s||o.table!==s.table)return!1;let r={table:o.table,anchor:[o.row,o.col],head:[s.row,s.col]},i=n.state.tr.setSelection(ro.create(n.state.doc,s.start)).setMeta(S,r);n.dispatch(i);let l=V(n.state.doc,r),c=l?(l.bottom-l.top+1)*(l.right-l.left+1):0;return P(n,`${c} ${c===1?"cell":"cells"} selected`),!0}function fr(n,t,e,o){let s=n.state.doc.nodeAt(t);if(s?.type!==Ut.table||!s.childCount)return!1;let r=s.childCount-1,i=s.child(0).childCount-1,l=(c,d)=>{let u=t+1;for(let a=0;a<c;a++)u+=s.child(a).nodeSize;u++;for(let a=0;a<d;a++)u+=s.child(c).child(a).nodeSize;return u+1};return e==="row"?wt(n,l(o,0),l(o,i)):wt(n,l(0,o),l(r,o))}var io=new Set(["Shift","Control","Alt","Meta","CapsLock"]),lo=n=>/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n;function co(n,t){let e=n.cells.map(r=>r.map(({cell:i})=>lo(ut(dt(i)))).join(" ")).join(`
|
|
2
|
-
`),o=t.createElement("table"),s=o.appendChild(t.createElement("tbody"));for(let r of n.cells){let i=s.appendChild(t.createElement("tr"));for(let{cell:l}of r){let c=i.appendChild(t.createElement("td"));c.dataset.col=l.attrs.col,c.append(qe.serializeFragment(l.content,{document:t}))}}return{text:e,html:o.outerHTML}}function tn(n,t){let e=V(n.doc,S.getState(n));if(!e)return!1;if(t){let o=n.tr;for(let s of[...e.cells].reverse())for(let{cell:r,pos:i}of[...s].reverse())r.content.size&&o.delete(i+1,i+r.nodeSize-1);o.setMeta(S,S.getState(n)),t(w(o))}return!0}var en=(n,t,e)=>{let{text:o,html:s}=co(t,e.dom.ownerDocument);n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",s),n.preventDefault()},ao=(n,t)=>(e,o,s)=>{let r=S.getState(e),i=V(e.doc,r);if(!i||!s)return!1;let l=[],c=I(i.node.attrs.cols);i.node.forEach(a=>l.push(a.attrs.id));let d=Math.max(0,Math.min(l.length-1,l.indexOf(r.head[0])+n)),u=Math.max(0,Math.min(c.length-1,c.indexOf(r.head[1])+t));return o&&o(e.tr.setMeta(S,{...r,head:[l[d],c[u]]})),!0},nn=(n,t)=>{let e=t.target?.closest?.("td");if(!e||!n.dom.contains(e))return null;try{return n.posAtDOM(e,0)}catch{return null}};function mr(){let n=null;return new so({key:S,state:{init:()=>null,apply(t,e,o,s){let r=t.getMeta(S);return r!==void 0?r:!e||t.selectionSet||t.docChanged&&!t.getMeta(pt)?null:V(s.doc,e)?e:null}},props:{attributes:t=>S.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>S.getState(t.state)?t.state.selection:null,decorations(t){let e=V(t.doc,S.getState(t));return e?Pt.DecorationSet.create(t.doc,e.cells.flat().map(({cell:o,pos:s})=>Pt.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,e){let o=t.state;if(!S.getState(o))return!1;if(e.key==="Escape")return t.dispatch(o.tr.setMeta(S,null)),!0;if(e.key==="Backspace"||e.key==="Delete")return tn(o,t.dispatch);if(e.shiftKey){let s={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(s)return ao(...s)(o,t.dispatch,t)}return io.has(e.key)||(e.metaKey||e.ctrlKey)&&(e.key==="a"||e.key==="c"||e.key==="x"||e.key==="v")||t.dispatch(o.tr.setMeta(S,null)),!1},handleDOMEvents:{mousedown(t,e){if(e.button!==0)return!1;!e.shiftKey&&S.getState(t.state)&&t.dispatch(t.state.tr.setMeta(S,null));let o=nn(t,e);if(o===null)return!1;if(e.shiftKey){let c=S.getState(t.state),d=(c&&uo(t.state.doc,c))??t.state.selection.$anchor.pos;return st(t.state.doc,d)?(e.preventDefault(),wt(t,d,o)):!1}let s=t.dom.ownerDocument,r=o,i=c=>{let d=nn(t,c);if(d===null)return;let u=st(t.state.doc,r),a=st(t.state.doc,d);if(!u||!a||u.table!==a.table)return;let h=S.getState(t.state);u.row===a.row&&u.col===a.col&&!h||h&&h.head[0]===a.row&&h.head[1]===a.col||(c.preventDefault(),wt(t,r,d))},l=()=>{s.removeEventListener("mouseover",i),s.removeEventListener("mouseup",l),n=null};return n?.(),n=l,s.addEventListener("mouseover",i),s.addEventListener("mouseup",l),!1},copy(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),!0)},cut(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),tn(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>n?.()})})}function uo(n,t){let e=on(n,t.table),o=null;return e?.node.forEach((s,r)=>{if(s.attrs.id!==t.anchor[0])return;let i=e.pos+1+r+1;s.forEach(l=>{l.attrs.col===t.anchor[1]&&(o=i+1),i+=l.nodeSize})}),o}var sn=n=>{let t=V(n.doc,S.getState(n));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var Gt=new WeakMap;var{Plugin:ho,TextSelection:j}=C,T=g.nodes,Jt=256*1024,B=n=>I(n.attrs.cols),rn=n=>{let t=n.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type===T.table){let o=t.node(e),s=e<t.depth?t.index(e):0,r=e+1<t.depth?t.index(e+1):0;return{table:o,pos:t.before(e),row:s,cell:r}}return null},rt=(n,t,e,o)=>{let s=n.nodeAt(t);if(!s||!s.childCount)return null;e=Math.max(0,Math.min(e,s.childCount-1)),o=Math.max(0,Math.min(o,s.child(e).childCount-1));let r=t+1;for(let i=0;i<e;i++)r+=s.child(i).nodeSize;r++;for(let i=0;i<o;i++)r+=s.child(e).child(i).nodeSize;return r+1},St=(n,t=A())=>T.table_row.create({id:k("r"),pos:t},n.map(e=>T.table_cell.create({col:e}))),L=(n,t,e)=>T.table.create({...n.attrs,...t},e);function D(n,t,e){let o=rn(n);if(!o)return!1;let s=e(o.table,o);if(!s)return!1;if(t){let{table:r,row:i=o.row,cell:l=o.cell}=s,c=n.tr.replaceWith(o.pos,o.pos+o.table.nodeSize,r),d=rt(c.doc,o.pos,i,l);d!==null&&c.setSelection(j.create(c.doc,d)),t(w(c))}return!0}function F(n,t,e,o=null,s=null,r=null){r??=o?n.doc.resolve(o.from).index(0):n.selection.$head.index(0);let i=n.doc.child(r),l=0;for(let h=0;h<r;h++)l+=n.doc.child(h).nodeSize;let c=i.isTextblock&&(i.content.size===0||o?.from===l+1&&o?.to===l+i.nodeSize-1),d=n.doc.maybeChild(r+1),u=c?i.attrs.pos:A(i.attrs.pos,d?.attrs.pos??null),a=e.type.create({...e.attrs,pos:u,parent:i.attrs.parent??null},e.content);if(t){let h=n.tr;o&&h.delete(o.from,o.to);let p=h.mapping.map(l),f=h.doc.child(r),m=c?p:p+f.nodeSize;if(h.replaceWith(m,c?p+f.nodeSize:m,a),s){let b=s.type.create({...s.attrs,pos:A(u,d?.attrs.pos??null),parent:i.attrs.parent??null},s.content);h.insert(m+a.nodeSize,b)}h.setSelection(j.create(h.doc,rt(h.doc,m,0,0))),t(w(h).scrollIntoView())}return!0}function ln(n=3,t=3){if(!Number.isInteger(n)||!Number.isInteger(t)||n<1||t<1)return null;let e=Array.from({length:t},()=>k("c")),o=N(null,null,t),s=Object.fromEntries(e.map((l,c)=>[l,{pos:o[c],name:`Column ${c+1}`}])),i=N(null,null,n).map(l=>St(e,l));return T.table.create({id:k(),cols:s},i)}var Xt=n=>(t,e)=>{let o=rn(t);if(!o||t.selection.$head.parent.type!==T.table_cell)return!1;let s=o.table.child(o.row).childCount,r=o.row,i=o.cell;return n==="down"?r++:(i+=n,i>=s&&(r++,i=0),i<0&&(r--,i=s-1)),r<0?!0:r>=o.table.childCount?n===-1?!0:po(t,e,o,i):(e&&e(t.tr.setSelection(j.create(t.doc,rt(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function po(n,t,e,o){let s=[...e.table.content.content];if(s.push(St(B(e.table),A(s.at(-1).attrs.pos,null))),t){let r=n.tr.replaceWith(e.pos,e.pos+e.table.nodeSize,L(e.table,{sort:null},s));r.setSelection(j.create(r.doc,rt(r.doc,e.pos,s.length-1,o))),t(w(r).scrollIntoView())}return!0}var fo=Xt(1),mo=Xt(-1),go=Xt("down"),bo=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=[...o.content.content],i=s.row+(n?1:0),l=A(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,St(B(o),l)),{table:L(o,{sort:null},r),row:i}}),Lr=(n,t)=>D(n,t,(e,o)=>{let s=[...e.content.content];if(s.length===1){let r=s[0];s[0]=T.table_row.create(r.attrs,B(e).map(i=>T.table_cell.create({col:i})))}else s.splice(o.row,1);return{table:L(e,{sort:null},s),row:Math.min(o.row,s.length-1)}}),cn=(n,t,e,o,s)=>{let{pos:r,rekey:i}=Vt(t,c=>n[c]?.pos??"",e),l={...n,[o]:{...s,pos:r}};for(let[c,d]of i)l[c]={...l[c],pos:d};return l},Dr=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+(n?1:0),l=k("c"),c=cn(o.attrs.cols,r,i,l,{name:`Column ${r.length+1}`}),d=o.content.content.map(u=>{let a=[...u.content.content];return a.splice(i,0,T.table_cell.create({col:l})),T.table_row.create(u.attrs,a)});return{table:L(o,{cols:c},d),cell:i}}),$r=(n,t)=>D(n,t,(e,o)=>{let s=B(e);if(s.length<=1)return null;let r={...e.attrs.cols};delete r[s[o.cell]];let i=e.content.content.map(l=>T.table_row.create(l.attrs,l.content.content.filter((c,d)=>d!==o.cell)));return{table:L(e,{cols:r,sort:e.attrs.sort?.col===s[o.cell]?null:e.attrs.sort},i),cell:Math.min(o.cell,s.length-2)}}),_r=n=>(t,e)=>D(t,e,(o,s)=>{let r=s.row+n;if(r<0||r>=o.childCount)return null;let i=[...o.content.content],[l]=i.splice(s.row,1);i.splice(r,0,l);let c=A(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=T.table_row.create({...l.attrs,pos:c},l.content),{table:L(o,{sort:null},i),row:r}}),Br=n=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+n;if(i<0||i>=r.length)return null;let l=[...r],[c]=l.splice(s.cell,1);l.splice(i,0,c);let d=cn(o.attrs.cols,l.filter(a=>a!==c),i,c,o.attrs.cols[c]),u=o.content.content.map(a=>{let h=[...a.content.content],[p]=h.splice(s.cell,1);return h.splice(i,0,p),T.table_row.create(a.attrs,h)});return{table:L(o,{cols:d},u),cell:i}}),yo=48,ko=1200,Pr=160,an=n=>Number.isFinite(n)&&n>0?Math.round(Math.min(ko,Math.max(yo,n))):null,Rr=n=>(t,e)=>D(t,e,o=>{let s=B(o);if(!s.some(i=>o.attrs.cols[i].width))return null;let r={};for(let i of s){let{width:l,...c}=o.attrs.cols[i];r[i]=c}return{table:L(o,{cols:r},o.content),cell:Math.max(0,s.indexOf(n))}}),Nr=(n,t)=>(e,o)=>D(e,o,s=>{let r={...s.attrs.cols},i=!1;for(let[l,c]of Object.entries(n)){let d=an(c);!r[l]||d===null||r[l].width===d||(r[l]={...r[l],width:d},i=!0)}return i?{table:L(s,{cols:r},s.content),cell:B(s).indexOf(t)}:null}),Hr=(n,t)=>(e,o)=>D(e,o,s=>{let r=s.attrs.cols[n];if(!r)return null;let i=t===null?null:an(t);if(t!==null&&i===null||(r.width??null)===i)return null;let{width:l,...c}=r,d={...s.attrs.cols,[n]:i===null?c:{...r,width:i}};return{table:L(s,{cols:d},s.content),cell:B(s).indexOf(n)}}),zr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!String(t).trim())return null;let r={...s.attrs.cols,[n]:{...s.attrs.cols[n],name:String(t).trim()}};return{table:L(s,{cols:r},s.content)}}),Fr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!(t==="auto"||Te.includes(t)))return null;let{kind:r,...i}=s.attrs.cols[n],l={...s.attrs.cols,[n]:t==="auto"?i:{...s.attrs.cols[n],kind:t}};return{table:L(s,{cols:l,sort:s.attrs.sort?.col===n?null:s.attrs.sort},s.content)}}),Kr=(n,t="asc")=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!["asc","desc"].includes(t))return null;let r=B(s).indexOf(n),i=Je(s)[n],l=[...s.content.content].map((u,a)=>({row:u,previous:a,text:u.child(r).textContent.trim()}));l.sort((u,a)=>{if(!u.text||!a.text)return!u.text&&!a.text?u.previous-a.previous:u.text?-1:1;let h=i==="number"?Nt(u.text):u.text,p=i==="number"?Nt(a.text):a.text;if(h==null||p==null)return h==null&&p==null?u.previous-a.previous:h==null?1:-1;let f=i==="number"?h-p:i==="date"?h<p?-1:h>p?1:0:h.localeCompare(p,void 0,{numeric:!0,sensitivity:"base"});return f?t==="asc"?f:-f:u.previous-a.previous});let c=N(null,null,l.length),d=l.map(({row:u},a)=>T.table_row.create({...u.attrs,pos:c[a]},u.content));return{table:L(s,{sort:{col:n,dir:t}},d)}}),Yt=(n,t=null)=>(e,o)=>D(e,o,(s,r)=>{let i=B(s),l=t?.row??r.row,c=t?.cell??r.cell,d=[...s.content.content];n.forEach((a,h)=>{let p=l+h;p>=d.length&&d.push(St(i,A(d.at(-1).attrs.pos,null)));let f=[...d[p].content.content];a.forEach((m,b)=>{c+b<i.length&&(f[c+b]=T.table_cell.create({col:i[c+b]},we(g,m)))}),d[p]=T.table_row.create(d[p].attrs,f)});let u=Math.max(1,...n.map(a=>a.length));return{table:L(s,{sort:null},d),row:l+n.length-1,cell:Math.min(c+u-1,i.length-1)}}),xo=n=>new TextEncoder().encode(JSON.stringify(n.toJSON())).length;function Mo(n,t){let e=t.clipboardData;if(!e||e.files?.length)return!1;let o=n.state;if(o.selection.$from.parent.type.spec.code)return!1;let s=sn(o),r=e.getData("text/plain").replace(/\r?\n$/,""),i=Ze(e.getData("text/html"),e.getData("text/plain"),n.dom.ownerDocument)??(s&&r&&!/[\r\n]/.test(r)?{grid:[[r]],width:1,height:1,own:!1}:null);if(!i)return!1;if(s&&s.rows*s.cols>1&&i.width*i.height===1)return Yt(Array.from({length:s.rows},()=>Array(s.cols).fill(i.grid[0][0])),{row:s.row,cell:s.cell})(o,n.dispatch);if(s)return Yt(i.grid,{row:s.row,cell:s.cell})(o,n.dispatch);if(o.selection.$head.parent.type===T.table_cell)return i.width*i.height<2?!1:Yt(i.grid)(o,n.dispatch);if(i.width*i.height<2||i.own||i.height<2&&!/<table[\s>]/i.test(e.getData("text/html")))return!1;let l=Mt(i.grid,{header:i.height>1});if(!l)return!1;if(xo(l)>Jt)return H("This paste is too large for one table.","error"),!0;let{from:c,to:d,empty:u,$from:a,$to:h}=o.selection;if(!u&&a.index(0)!==h.index(0)){let p=o.tr.deleteSelection();return F(o.apply(p),f=>{for(let m of f.steps)p.step(m);p.setSelection(j.create(p.doc,f.selection.from)),n.dispatch(w(p).scrollIntoView())},l)}return F(o,n.dispatch,l,u?null:{from:c,to:d})}var Vr=at.keymap({Tab:fo,"Shift-Tab":mo,Enter:go,"Mod-Enter":bo(!0)});function wo(n,t){let e=Gt.get(t.target),o=e?.getPos();if(o==null||t.button||t.shiftKey||!n.editable)return!1;t.preventDefault();let s=t.clientX<e.contentDOM.getBoundingClientRect().left;return n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,o+1+(s?0:e.node.content.size)))),n.focus(),e.openDate(),!0}function jr(){return new ho({props:{handlePaste:Mo,handleDOMEvents:{mousedown:wo},handleClickOn(n,t,e,o,s,r){if(e.type!==T.table_cell||!r||s.button)return!1;let i=n.nodeDOM(o),l=i&&Gt.get(i);return l&&l.openDate(),!1}},appendTransaction(n,t,e){if(!n.some(r=>r.docChanged&&!r.getMeta(pt)))return null;let o=new Map;t.doc.forEach(r=>{r.type===T.table&&o.set(r.attrs.id,r)});let s=e.tr;return e.doc.forEach((r,i)=>{if(r.type!==T.table||!r.attrs.sort)return;let l=o.get(r.attrs.id),c=r.attrs.sort.col;if(!l)return;let d=h=>Object.fromEntries(h.content.content.map(p=>[p.attrs.id,p.content.content.find(f=>f.attrs.col===c)?.textContent])),u=d(l),a=d(r);(Object.keys(u).length!==Object.keys(a).length||Object.keys(u).some(h=>u[h]!==a[h]||!Object.hasOwn(a,h)))&&s.setNodeMarkup(i,null,{...r.attrs,sort:null})}),s.docChanged?s.setMeta(Wt,!0):null}})}function qr(n,t,e){let o=n.state.doc.nodeAt(t);if(o?.type!==T.table_cell)return!1;let s=n.state.tr.replaceWith(t+1,t+o.nodeSize-1,e?g.text(e):[]);return n.dispatch(s.setSelection(j.create(s.doc,t+1+e.length))),!0}function Wr(n,t,e,o){let s=rt(n.state.doc,t,e,o);return s===null?!1:(n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,s))),!0)}var{TextSelection:So}=C,Qt=g.nodes,To=Object.freeze(["To do","In progress","Done"]),un=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function Zt(n=To){let t=N(null,null,n.length),e=Object.fromEntries(n.map((o,s)=>[k("c"),{pos:t[s],name:o}]));return Qt.board.create({id:k(),columns:e,cards:{}})}function dn(n,t,e=Zt(),o=null,s=null){let r=n.tr;o&&r.delete(o.from,o.to),s??=r.doc.resolve(r.mapping.map(n.selection.head)).index(0);let i=J(r.doc),l=r.doc.child(s),c=l.isTextblock&&l.content.size===0,d=c?s:i[s].subEnd,u=c?i[s].at:i[d].end,a=i[d+1]?.node.attrs.pos??null,h=l.attrs.parent??null,p=c?l.attrs.pos:un(i[d].node.attrs.pos,a),f=Qt.board.create({...e.attrs,pos:p,parent:h}),m=Qt.paragraph.create({id:k(),pos:un(p,a),parent:h});return r.replaceWith(u,c?i[s].end:u,[f,m]),r.setSelection(So.create(r.doc,u+f.nodeSize+1)),t&&t(w(r).scrollIntoView()),!0}function hn(n){let t=[];return n.forEach(e=>{e.type===g.nodes.table&&I(e.attrs.cols).length>1&&t.push(e)}),t}function ni(n,t){let e="",o=0,s=null;return n.forEach(r=>{s===null&&(r.type===g.nodes.heading&&(e=r.textContent),r.type===g.nodes.table&&(o+=1,r.attrs.id===t&&(s=e||`Table ${o}`),e=""))}),s}var pn=new Set(["page-format-unsupported","unsupported-host"]),Eo="This host can't store that yet, so nothing was added.",Co="That didn't go through. Try again.",Ao="That couldn't be added here.";function fn(n,t){let e=t?.status==="upgrade-required"&&t.message?t.message:pn.has(t?.code)||pn.has(t?.status)?Eo:t?.retry===!0?Co:Ao;n.isDestroyed||(P(n,e),H(e,"error"))}async function Tt(n,t){if(typeof n.runFormatCommand!="function")return fn(n,{code:"page-format-unsupported"}),{ok:!1,code:"page-format-unsupported"};let e=await n.runFormatCommand(t);return e?.status==="applied"?e.result:(fn(n,e),{ok:!1,code:e?.code??e?.status??"page-format-refused",retry:e?.retry===!0})}var{TextSelection:it}=C,v=g.nodes,q=[{key:"text",label:"Text",description:"Plain writing",icon:"T",type:"paragraph",aliases:["p","paragraph","plain"]},{key:"h1",label:"Heading 1",description:"Big section heading",icon:"H1",type:"heading",attrs:{level:1},hint:"#",aliases:["h1","title"]},{key:"h2",label:"Heading 2",description:"Medium section heading",icon:"H2",type:"heading",attrs:{level:2},hint:"##",aliases:["h2","subtitle"]},{key:"h3",label:"Heading 3",description:"Small section heading",icon:"H3",type:"heading",attrs:{level:3},hint:"###",aliases:["h3"]},{key:"bullet",label:"Bulleted list",description:"A simple list",icon:"\u2022",type:"list_item",attrs:{kind:"bullet"},hint:"-",aliases:["ul","bullet","list","unordered"]},{key:"ordered",label:"Numbered list",description:"A list with numbers",icon:"1.",type:"list_item",attrs:{kind:"ordered"},hint:"1.",aliases:["ol","num","numbered","ordered"]},{key:"check",label:"Checklist",description:"Tasks to tick off",icon:"\u2610",type:"list_item",attrs:{kind:"check"},hint:"[]",aliases:["todo","to-do","task","check","checkbox"]},{key:"toggle",label:"Toggle",description:"Hide details under a line",icon:"\u25B8",type:"toggle",attrs:{open:!0},hint:">",aliases:["collapse","details","fold"]},{key:"toggle-h1",label:"Toggle heading 1",description:"Collapsible heading",icon:"H1",type:"toggle",attrs:{open:!0,level:1},aliases:["toggle heading"]},{key:"toggle-h2",label:"Toggle heading 2",description:"Collapsible heading",icon:"H2",type:"toggle",attrs:{open:!0,level:2},aliases:["toggle heading"]},{key:"toggle-h3",label:"Toggle heading 3",description:"Collapsible heading",icon:"H3",type:"toggle",attrs:{open:!0,level:3},aliases:["toggle heading"]},{key:"callout",label:"Callout",description:"Make a note stand out",icon:"!",type:"callout",aliases:["note","aside","info"]},{key:"quote",label:"Quote",description:"Set text apart as a quotation",icon:"\u201C",type:"quote",hint:'"',aliases:["blockquote","quotation","cite"]},{key:"code",label:"Code",description:"Code with highlighting",icon:"</>",type:"code_block",hint:"```",aliases:["pre","snippet"]}],Oo=[{key:"divider",label:"Divider",description:"A line between sections",icon:"\u2014",hint:"---",aliases:["hr","line","separator","rule"],insert:"divider"},{key:"toc",label:"Table of contents",description:"Links to this page's headings",icon:"\u2261",aliases:["toc","contents","outline","index"],insert:"toc"},{key:"image",label:"Image",description:"Upload or paste a picture",icon:"\u25A3",aliases:["img","picture","photo"],insert:"image"},{key:"file",label:"File",description:"Attach any file",icon:"\u2398",aliases:["upload","attachment","pdf"],insert:"file"},{key:"table",label:"Table",description:"Rows and columns, paste from a spreadsheet",icon:"\u25A6",aliases:["grid","spreadsheet"],insert:"table"},{key:"csv",label:"Import CSV\u2026",description:"Turn a CSV file into a table",icon:"\u21E7",aliases:["comma separated","import"],insert:"csv"},{key:"board",label:"Board",description:"Cards in columns, like a kanban",icon:"\u25A5",aliases:["kanban","cards","columns","status"],insert:"board"},{key:"mention",label:"Mention",description:"Name someone on the page",icon:"@",aliases:["person","people","assign"],command:"mentions"},{key:"date",label:"Date",description:"Today, tomorrow or a calendar day",icon:"\u25A7",aliases:["calendar","today","tomorrow","due"],command:"dates"},{key:"emoji",label:"Emoji",description:"Insert one glyph",icon:"\u263A",aliases:["smiley","glyph","symbol"],command:"emoji"},{key:"import-markdown",label:"Import Markdown\u2026",description:"Turn a Markdown file into blocks",icon:"M\u2193",aliases:["md","markdown","import"],command:"importMarkdown"}],vo={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},te=n=>(Ne.get(n)?.ensure("chart")??Promise.resolve()).catch(()=>{}).then(()=>n.isDestroyed?null:import("./c-MMXKAX2W.js")),At=[...q,...Oo],gn=(n,t=At)=>hn(n.doc).length?[...t,vo]:t;function Ot(n){let t=n.type.name;return q.find(e=>e.type===t&&(!e.attrs||(t==="heading"||t==="toggle"?(e.attrs.level??null)===(n.attrs.level??null):t==="list_item"?e.attrs.kind===n.attrs.kind:!0)))??q[0]}var ee=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e};function G(n,t,e){let o=ee(n.doc,t),s=n.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===v.list_item&&e.type==="list_item"&&(r.indent=s.attrs.indent),n.setBlockType(o+1,o+s.nodeSize-1,v[e.type],{...r,...e.attrs||{}})}var bn=Object.freeze({status:"refused",code:"unsupported-format"}),Io=xe([]).type,Lo=n=>{let t=!1;return n.forEach(e=>{!t&&e.marks.some(ke)&&(t=!0)}),t};function Q(n,t){return!n.isTextblock||n.type===v.opaque_block?!1:!Lo(n)||v[t.type].allowsMarkType(Io)}var yn=n=>n.type==="toggle"&&n.attrs?.level!=null,Et=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e},ne={ok:!1,code:"stale-target"};function kn(n,t,e){let o=()=>e.map(r=>Et(n.state.doc,r)),s=()=>{let r=o();if(r.includes(-1))return ne;if(r.some(l=>!Q(n.state.doc.child(l),t)))return bn;let i=n.state.tr;for(let l of r)G(i,l,t);return n.dispatch(w(i).scrollIntoView()),n.focus(),{ok:!0}};return yn(t)?Tt(n,s):t.type==="quote"?import("./c-7PYNAULW.js").then(r=>n.isDestroyed?!1:r.gateTurn(n,s)):s()}function xn(n,t,e=n.tr){let o=J(e.doc),{to:s}=ze(o,t),r=e.doc.child(t);return e.insert(s,v.paragraph.create({parent:r.attrs.parent??null})),e.setSelection(it.create(e.doc,s+1))}var X=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function oe(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.divider.create({id:r,pos:i,parent:l}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function Do(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return oe(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.divider.create({id:k(),pos:c,parent:d}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function $o(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.toc.create({id:r,pos:i,parent:l,maxLevel:3}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function _o(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return $o(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.toc.create({id:k(),pos:c,parent:d,maxLevel:3}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function Bo(n,t){if(n.length<2||n.length>32)return 1/0;let e=-1,o=0;for(let s of n){let r=t.indexOf(s,e+1);if(r<0)return 1/0;o+=r-e-1,e=r}return o}function Mn(n,t){let e=t.trim().toLowerCase();if(!e)return n;let o=s=>{let r=s.label.toLowerCase(),i=[s.key,...s.aliases||[],...s.hint?[s.hint]:[]].map(c=>c.toLowerCase());if(r===e||i.includes(e))return[0,0];if(r.startsWith(e))return[1,0];if([...r.split(/\s+/),...i].some(c=>c.startsWith(e)))return[2,0];if([r,...i].some(c=>c.includes(e)))return[3,0];if(e.length>=3&&s.description&&s.description.toLowerCase().split(/[^a-z0-9]+/).some(c=>c.startsWith(e)))return[4,0];let l=Math.min(...[r,s.key,...s.aliases||[]].map(c=>Bo(e,c.toLowerCase())));return l===1/0?null:[5,l]};return n.map((s,r)=>({it:s,order:r,rank:o(s)})).filter(s=>s.rank).sort((s,r)=>s.rank[0]-r.rank[0]||s.rank[1]-r.rank[1]||s.order-r.order).map(s=>s.it)}function mn(n,t,e,o){let s=n.state,r=s.tr;o&&r.delete(o.from,o.to);let i=r.doc.child(e);return i.isTextblock&&i.content.size===0&&!Q(i,t)?bn:(t.insert==="divider"?r=Do(s,e,r):i.isTextblock&&i.content.size===0?r=G(r,e,t):(r=xn(s,e,r),r=G(r,r.doc.resolve(r.selection.head).index(0),t)),n.dispatch(w(r).scrollIntoView()),n.focus(),!0)}function Po(n,t,e=null){let o=n.state,s=o.doc.maybeChild(t)?.attrs.id??null,r=e&&{...e,text:o.doc.textBetween(e.from,e.to)};return Tt(n,()=>{let i=n.state;if((s===null?-1:Et(i.doc,s))<0||r&&i.doc.textBetween(r.from,r.to)!==r.text)return ne;let c=r?i.tr.delete(r.from,r.to):i.tr;return c=_o(i,Et(c.doc,s),c),n.dispatch(w(c).scrollIntoView()),n.focus(),{ok:!0}})}var Z=(n,t,e)=>import("./page/editor-WRQGHDSG.js").then(({runPageCommand:o})=>n.isDestroyed?{ok:!1,code:"not-editing"}:o(n,t,e));function Ro(n,t,e){return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),Z(n,t,{})}function wn(n,t,e,o=null){let s=n.state;if(t.insert==="image"||t.insert==="file")return Re(n,t.insert==="image"?"image/*":"",Pe(s,e),o);if(t.insert==="csv")return Ct(n,o);if(t.insert==="table")return F(s,n.dispatch,ln(),o,null,e);if(t.insert==="board")return dn(s,n.dispatch,Zt(),o,e);if(t.insert==="chart")return te(n).then(l=>l&&!n.isDestroyed?l.chartFromSlash(n,e,o):!1);if(t.insert==="toc")return Po(n,e,o);if(t.command)return Ro(n,t.command,o);if(!yn(t)&&t.type!=="quote")return mn(n,t,e,o);let r=s.doc.maybeChild(e)?.attrs.id??null,i=o&&{...o,text:s.doc.textBetween(o.from,o.to)};return Tt(n,()=>{let l=n.state,c=r===null?-1:Et(l.doc,r);return c<0||i&&l.doc.textBetween(i.from,i.to)!==i.text?ne:mn(n,t,c,i)})}var{InputRule:ie}=Rt,W=g.nodes,vt=(n,t,e)=>n.doc.rangeHasMark(t,e,g.marks.code)||!!g.marks.code.isInSet(n.storedMarks||n.selection.$from.marks()),tt=(n,t,e=["paragraph"],o=!1)=>new ie(n,(s,r,i,l)=>{let c=s.doc.resolve(i);return!s.selection.empty||c.depth!==1||c.parentOffset!==0||!e.includes(c.parent.type.name)||o&&l!==c.end()||vt(s,i,l)?null:w(G(s.tr.delete(i,l),c.index(0),typeof t=="function"?t(r):t))}),No=new ie(/^---$/,(n,t,e,o)=>{let s=n.doc.resolve(e);return!n.selection.empty||s.depth!==1||s.parent.type!==W.paragraph||s.parentOffset!==0||s.parent.content.size!==o-e||vt(n,e,o)?null:w(oe(n.tr,s.index(0)))}),le=`\\s\\(\\[\\{'\u2018\u201C"`,Ho=new RegExp(`[${le}]`),se=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Sn=n=>`([^\\s${n}](?:[\\s\\S]*?[^\\s${n}])?)`,It=(n,t)=>!!n?.isComposing||n?.keyCode===229||!!t?.composing,Tn=n=>{let t=0;for(let e=n.length-1;e>=0&&n[e]==="\\";e--)t++;return t},zo=(n,t)=>{let e=n.doc.resolve(t);return!e.parent.inlineContent||Tn(e.parent.textBetween(0,e.parentOffset,null,"\uFFFC"))%2?!1:e.parentOffset===0||Ho.test(e.parent.textBetween(e.parentOffset-1,e.parentOffset))},Fo=(n,t,e,o,s)=>{let r=s(t);if(!r||!n.selection.empty||e<0||e>o||o>n.doc.content.size)return null;let i=n.doc.resolve(e),l=n.doc.resolve(o);if(!i.sameParent(l)||!i.parent.inlineContent)return null;let[c,d,u,a]=t;if(vt(n,e,o))return null;let h=c.slice(d.length,c.length-u.length-a.length),p=e+d.length;if(!zo(n,p)||Tn(c.slice(0,c.length-a.length))%2)return null;let f=c.length-(o-e);if(f<0)return null;let m=n.tr;f&&m.insertText(c.slice(-f),o,o);let b=p+h.length,x=b+u.length;return m.delete(x,e+c.length),m.delete(p,b),m.addMark(p,p+u.length,r),m.removeStoredMark(r.type),w(m)},En=(n,t)=>new ie(n,(e,o,s,r)=>Fo(e,o,s,r,t),{inCodeMark:!1}),et=(n,t,e)=>En(new RegExp(`(^|[${le}])${se(n)}${Sn(se(t))}(${se(t)})$`),()=>e.create()),Ko=En(new RegExp(`(^|[${le}])\\[${Sn("\\[\\]")}(\\]\\([^()\\s]*\\))$`),n=>{let t=be(n[3].slice(2,-1));return t?g.marks.link.create({href:t}):null}),Vo=[et("**","**",g.marks.strong),et("__","__",g.marks.strong),et("*","*",g.marks.em),et("_","_",g.marks.em),et("`","`",g.marks.code),et("~~","~~",g.marks.strike),Ko],re=["paragraph","list_item"],jo=[tt(/^(#{1,3})\s$/,n=>({type:"heading",attrs:{level:n[1].length}})),tt(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},re),tt(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},re),tt(/^\[( |x|X)?\]\s$/,n=>({type:"list_item",attrs:{kind:"check",checked:!!n[1]&&n[1]!==" "}}),re),tt(/^>\s$/,{type:"toggle",attrs:{open:!0}}),tt(/^```$/,{type:"code_block"},["paragraph"],!0),No,...Vo];function qo(n,t,e,o,s){if(s!==" "||e!==o)return!1;let r=t.state,i=r.doc.resolve(e),l=i.parent;if(i.depth!==1||l.type!==W.paragraph||i.parentOffset!==1||l.textContent!=='"'||!t.editable||typeof t.runFormatCommand!="function")return!1;let c=()=>{t.isDestroyed||t.state.doc!==r.doc||t.dispatch(t.state.tr.insertText(" ",e,o))},d=i.before(1);return import("./c-7PYNAULW.js").then(({quoteFromSpace:u})=>u(n,t,{at:d,from:e,to:o},c),c),!0}var Oi=()=>{let n=Rt.inputRules({rules:jo}),t=n.props.handleTextInput;return n.props.handleTextInput=(e,o,s,r)=>qo(n,e,o,s,r)||t(e,o,s,r),n},Wo=/^\s*\|(.*)\|\s*$/;function Uo(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parent.type!==W.paragraph||e.parentOffset!==e.parent.content.size||vt(n,e.start(),e.end()))return!1;let s=Wo.exec(e.parent.textContent);if(!s)return!1;let r=s[1].split("|").map(l=>l.trim());if(!r.some(Boolean))return!1;let i=Mt([r,r.map(()=>"")],{header:!0});return F(n,t,i,{from:e.start(),to:e.end()})}var vi=()=>at.keymap({Enter:(n,t,e)=>!It(null,e)&&Uo(n,t)});function Ii(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parentOffset!==0)return!1;let s=e.parent;return s.type===W.heading||s.type===W.callout||s.type===W.quote||s.type===W.code_block&&s.content.size===0?(t&&t(w(n.tr.setNodeMarkup(e.before(),W.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:In,PluginKey:Ln,TextSelection:$t,NodeSelection:Go}=C,Dn=g.marks,U=g.nodes,Dt=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",$n=n=>{let t=gt(n.doc),{lo:e,hi:o}=n.selection.span(n.doc);return t.slice(e,o+1).filter(s=>s.up===t[e].up)},Lt=(n,t)=>n.state.doc.child(t).attrs.id,Yo=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e},Cn=["aria-haspopup","aria-controls","aria-activedescendant"],Jo="That block is no longer available.",he="This block holds content from a newer version, so it can't be converted here.";function ce(n){let t=n.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:n.innerWidth,height:n.innerHeight}}function Xo(n,t,e,o=0){let s=$,r=Math.min(t,Math.max(0,n.width-s*2));return{left:n.left+(n.width-r)/2,top:Math.max(n.top+s,n.top+n.height-e-o-s),width:r}}function Qo(n,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(n)}`}function Zo(n){if(!n)return;let t=()=>H("Link copied"),e=()=>H("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){e();return}globalThis.navigator.clipboard.writeText(Qo(n)).then(t,e)}var _n=[{key:"up",label:"Move up",icon:"up",hint:`${Dt}\u21E7\u2191`,run:n=>Ht(-1)(n.state,n.dispatch)},{key:"down",label:"Move down",icon:"down",hint:`${Dt}\u21E7\u2193`,run:n=>Ht(1)(n.state,n.dispatch)},{key:"indent",label:"Indent",icon:"indent",hint:"Tab",run:n=>{let t=n.state.doc;Ke(n.state,n.dispatch),n.state.doc===t&&(P(n,"Indent works on list items and inside toggles."),H("Indent works on list items and inside toggles."))}},{key:"outdent",label:"Outdent",icon:"outdent",hint:"\u21E7Tab",run:n=>Ve(n.state,n.dispatch)},{key:"duplicate",label:"Duplicate",icon:"duplicate",hint:`${Dt}D`,run:n=>Ue(n.state,n.dispatch)},{key:"delete",label:"Delete",icon:"trash",hint:"Del",run:n=>Ft(n.state,n.dispatch)},{key:"turn",label:"Turn into",icon:"turn",hint:"\u203A",only:"text",run:(n,t)=>t.openMenu("turn",t.plus)},{key:"link",label:"Copy link",icon:"link",run:(n,t,e)=>Zo(n.state.doc.child(e).attrs.id)},{key:"alt",label:"Alt text\u2026",icon:"alt",only:"image",focus:!1,run:(n,t,e)=>{let o=Lt(n,e);return import("./c-JCP3XDSJ.js").then(s=>s.openAltEditor(n,o))}},{key:"small",label:"Small",icon:"small",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-JCP3XDSJ.js").then(s=>s.setImageAttrs(n,o,{width:240}))}},{key:"medium",label:"Medium",icon:"medium",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-JCP3XDSJ.js").then(s=>s.setImageAttrs(n,o,{width:480}))}},{key:"full",label:"Full width",icon:"full",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-JCP3XDSJ.js").then(s=>s.setImageAttrs(n,o,{width:null}))}},{key:"chart",label:"Chart this table",icon:"chart",only:"table",run:(n,t,e)=>{let o=Yo(n.state.doc,e);return te(n).then(({insertChartAfterTable:s})=>s(n,o))}},{key:"csv",label:"Import CSV\u2026",icon:"csv",only:"table",focus:!1,run:(n,t,e)=>Ct(n,null,n.state.doc.child(e).attrs.id)}],ts=n=>{if(!(n.selection instanceof z))return[];let t=$n(n),e=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===U.image,s=t.length===1&&t[0].node.type===U.table;return _n.filter(r=>r.only==="text"?e:r.only==="image"?o:r.only==="table"?s:!0)},M=n=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,K={plus:M('<path d="M8 3.5v9M3.5 8h9"/>'),grip:M('<path stroke-width="2.2" d="M6 3.5h.01M10 3.5h.01M6 8h.01M10 8h.01M6 12.5h.01M10 12.5h.01"/>'),strong:M('<path d="M5 3h4a2.5 2.5 0 0 1 0 5H5zM5 8h4.6a2.5 2.5 0 0 1 0 5H5z"/>'),em:M('<path d="M10 3H6.5M9.5 13H6M9 3l-2 10"/>'),strike:M('<path d="M3 8h10M10.8 5.2C10.5 4 9.4 3.2 8 3.2c-1.7 0-2.8.9-2.8 2.1M5.2 10.8c.3 1.2 1.4 2 2.8 2 1.7 0 2.8-.9 2.8-2.1"/>'),code:M('<path d="M6 4.5 2.5 8 6 11.5M10 4.5 13.5 8 10 11.5"/>'),link:M('<path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.7.7M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.7-.7"/>'),bullet:M('<path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7"/><path stroke-width="2.4" d="M3 4.5h.01M3 8h.01M3 11.5h.01"/>'),ordered:M('<path d="M7 4.5h6.5M7 8h6.5M7 11.5h6.5M2.5 3.5l1-.5v3M2.5 9.3c.2-.5.6-.8 1.1-.8.6 0 1 .4 1 .9 0 .9-2.1 1.4-2.1 2.6h2.1"/>'),check:M('<rect x="2.5" y="2.5" width="11" height="11" rx="2.5"/><path d="M5.5 8.2l1.8 1.8 3.4-4"/>'),more:M('<path stroke-width="2.2" d="M3 8h.01M8 8h.01M13 8h.01"/>'),gear:M('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),close:M('<path d="M4 4l8 8M12 4l-8 8"/>'),up:M('<path d="M8 13V3.5M4 7.5 8 3.5l4 4"/>'),down:M('<path d="M8 3v9.5M4 8.5l4 4 4-4"/>'),indent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M2.5 6l2.5 2-2.5 2"/>'),outdent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M5 6 2.5 8 5 10"/>'),duplicate:M('<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 3.5v-.5A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v5A1.5 1.5 0 0 0 4 9.5h.5"/>'),trash:M('<path d="M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5"/>'),turn:M('<path d="M3 5.5h9.5M10 3l2.5 2.5L10 8M13 10.5H3.5M6 8l-2.5 2.5L6 13"/>'),chart:M('<path d="M3 13V3M3 13h10.5M6 10.5V8M9 10.5V5.5M12 10.5V7"/>'),csv:M('<path d="M4 1.5h5L12.5 5v9.5h-8.5zM9 1.5V5h3.5M8 7.5v5M6 10.5l2 2 2-2"/>'),alt:M('<path d="M2.5 12.5 5.5 4l3 8.5M3.6 9.5h3.8M10 12.5V7.5M10 8.5c.4-.7 1.1-1 2-1h.5"/>'),small:M('<rect x="5" y="5" width="6" height="6" rx="1"/>'),medium:M('<rect x="3.5" y="3.5" width="9" height="9" rx="1.2"/>'),full:M('<rect x="1.5" y="3.5" width="13" height="9" rx="1.2"/>')},ae=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],Bn=new Set(["strong","em","link"]),es=new Set(["up","down","indent","outdent"]),ns=204,os=52,$=8,Pn=new Set(["bullet","ordered","check"]),ss=[["assignees","Checklist assignees"],["dates","Checklist due dates"]],rs=new Set(["paragraph","heading","list_item"]),lt=n=>{let t=n.selection;if(t instanceof z)return $n(n).map(l=>l.i);let{$from:e,$to:o,empty:s}=t,r=Math.min(!s&&o.depth===0?o.index(0)-1:o.index(0),n.doc.childCount-1),i=[];for(let l=e.index(0);l<=r;l++)i.push(l);return i},Rn=n=>lt(n).filter(t=>{let e=n.doc.child(t);return e.isTextblock&&e.type!==U.code_block}),Nn=(n,t)=>n.type===U.list_item&&n.attrs.kind===t,Hn=(n,t)=>{let e=Rn(n);return e.length>0&&e.every(o=>Nn(n.doc.child(o),t))},is=n=>{let t="";return n.forEach(e=>{t+=e.isText?e.text:e.type===U.hard_break?`
|
|
1
|
+
import{F as mt,K as ot,O as $e,r as Ie,v as Le,w as ft,x as De}from"./c-EXKHPOVC.js";import{a as Ae,d as pt,g as Oe,h as ve}from"./c-L5VFATT6.js";import{f as Pe,o as Re}from"./c-XQSXKIKM.js";import{a as gt,c as Be}from"./c-67ILSNPR.js";import{b as Ne}from"./c-W4JCVLAB.js";import{B as w,C as zt,D as We,E as Ft,F as Ue,G as Ge,a as _e,d as P,e as S,f as He,h as J,i as ze,l as Fe,o as z,r as Ht,t as Ke,u as Ve,x as je,y as qe}from"./c-44B5ODN7.js";import{D as ut,E as Me,F as R,G as A,H as N,I,J as k,K as dt,L as we,O as Y,T as Se,U as ht,V as Nt,W as Te,X as Ee,Y as Ce,b as C,d as Pt,f as at,g as ge,h as Rt,j as be,l as ye,m as g,oa as nt,p as ke,q as xe}from"./c-QIXT3Q7C.js";import{a as H}from"./c-E4IBSAQM.js";var Ye=new WeakMap;function Je(n){let t=Ye.get(n);if(t)return t;t={};for(let[e,o]of I(n.attrs.cols).entries()){let s=[];n.forEach(r=>{e<r.childCount&&s.push(r.child(e).textContent.trim())}),t[o]=Ee(n.attrs.cols[o].kind,s)}return Ye.set(n,t),t}var Cs=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),As=Object.freeze({text:"Text",number:"Number",date:"Date"});var Kt=(n,t,e)=>{let o=n.attrs.get(t.baseId),s={};for(let r of Oe(e))s[r]=o&&o.has(r)?o.get(r):ve(e,r);return e.name==="board"&&Object.assign(s,Le(n.boardFields,t.baseId)),e.name==="table"&&Object.assign(s,Ie(n.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},Xe=n=>n===void 0?n:JSON.parse(JSON.stringify(n)),qn=(n,t)=>{let e={},o=n.attrs.get(t.baseId);return o&&o.forEach((s,r)=>{r!=="pos"&&(e[r]=Xe(s))}),e.t=t.t,e};function Bs(n,t,e=null){let o=d=>{if(d.opaque){let a=d.recovered?{...Xe(d.fields??{})}:qn(n,d);return{b:d,type:g.nodes.opaque_block,fields:a,opaque:!0}}let u=g.nodes[d.t]??g.nodes.paragraph;return{b:d,type:u,fields:{...d.fields??Kt(n,d,u)}}},s=t.visible.map(d=>{let u=e?.get(d);return u?{b:d,node:u}:o(d)}),r=new Map(s.map((d,u)=>[d.b.id,u])),i=d=>s[d].node?s[d].node.attrs.parent:s[d].fields.parent,l=d=>(d.b.recovered?n.gone._map.get(mt(d.b.sourceKey,"parent")):n.attrs.get(d.b.baseId)?._map.get("parent"))?.id??{clock:-1,client:-1};for(let d of r.keys()){let u=new Map,a=[],h=d;for(;r.has(h)&&!u.has(h);)u.set(h,a.length),a.push(h),h=i(r.get(h));if(!u.has(h))continue;let f=a.slice(u.get(h)).reduce((b,x)=>{let O=l(s[r.get(b)]),_=l(s[r.get(x)]);return O.clock<_.clock||O.clock===_.clock&&O.client<_.client?b:x}),m=r.get(f);s[m].node&&(s[m]=o(s[m].b)),s[m].fields.parent=null}let c=s.map(({b:d,node:u,type:a,fields:h,opaque:p})=>{if(u)return u;if(p){let b=[];for(let x of d.runs)x.hole||(x.br?b.push(g.nodes.hard_break.create()):b.push(g.text(x.text,x.marks)));return a.create({id:d.id,pos:null,raw:h},b)}let f={id:d.id,pos:null,...h};if(a.name==="table"&&Object.keys(f.rows??{}).length&&Object.keys(f.cols??{}).length)return Y(g,d.id,{t:"table",...f});if(!a.isTextblock)return a.create(f);let m=[];for(let b of d.runs)b.hole||(b.br?m.push(g.nodes.hard_break.create()):m.push(g.text(b.text,b.marks)));return a.create(f,m)});return c.length?g.nodes.doc.create(null,c):g.nodes.doc.createAndFill()}var E=n=>({status:"refused",code:n}),bt=n=>JSON.parse(JSON.stringify(n)),Wn=["title","owner","due"],Un=/^\d{4}-\d{2}-\d{2}$/,yt=(n,t)=>n==="title"?typeof t=="string":n==="due"?t===null||typeof t=="string"&&Un.test(t):t===null||typeof t=="string"&&t.length>0,Gn=n=>n!==null&&typeof n=="object"&&!Array.isArray(n);function Qe(n,t){let e=t>0?n[t-1]:null,o=n.slice(t).find(r=>e===null||r>e)??null,s=r=>(e===null||r>e)&&(o===null||r<o);for(let[r,i]of[[e,o],[null,o],[e,null]]){if(r!==null&&!R(r)||i!==null&&!R(i)||r!==null&&i!==null&&r>=i)continue;let l=A(r,i);if(s(l))return l}return`${n.reduce((r,i)=>i>r?i:r,"")}V`}function Vt(n,t,e){let o=n.map(t),s=e>0?o[e-1]:null,r=e;for(;s!==null&&r<o.length&&o[r]===s;)r++;if(r===e)return{pos:Qe(o,e),rekey:[]};let i=o.slice(r).find(c=>c>s)??null,l=[];for(let c=e,d=s;c<=r;c++)l.push(d=Qe(i===null?[d]:[d,i],1));return{pos:l[0],rekey:n.slice(e,r).map((c,d)=>[c,l[d+1]])}}var kt=(n,t,e)=>{let{pos:o,rekey:s}=Vt(t,r=>n[r].pos,e);for(let[r,i]of s)n[r]={...n[r],pos:i};return o};function qs({pd:n,um:t=null,origins:e=null,render:o=()=>{}}){let s=u=>{if(typeof u!="string")return null;let a=$e(n,e).visible.find(p=>p.id===u);if(!a||a.t!=="board")return null;let h=a.fields??Kt(n,a,g.nodes.board);return{columns:bt(h.columns??{}),cards:bt(h.cards??{})}},r=(u,a,h,p)=>{let f=ot(u);return t?.stopCapturing(),n.ydoc.transact(()=>{if(!f)De(n,u,a,h);else for(let m of["columns","cards"])nt(a[m])!==nt(h[m])&&n.gone.set(mt(f,m),bt(h[m]))},Ae),t?.stopCapturing(),o(),p},i=(u,a,h=null)=>I(Object.fromEntries(Object.entries(u.cards).filter(([p,f])=>f.col===a&&p!==h))),l=(u,a)=>a===void 0?u.length:a===null?0:u.indexOf(a)+1,c=(u,a)=>a!=null&&!u.includes(a),d=(u,a)=>{let h=s(u);return h?a(h,bt(h)):E("missing-board")};return{read:u=>s(u),removed(u){return s(u)?ot(u)?{columns:{},cards:{}}:ft(n.boardFields,u):null},createColumn:(u,{name:a="",afterId:h}={})=>d(u,(p,f)=>{if(typeof a!="string")return E("invalid-value");let m=I(p.columns);if(c(m,h))return E("missing-destination");let b=k("c");return f.columns[b]={pos:kt(f.columns,m,l(m,h)),name:a},r(u,p,f,{status:"created",id:b})}),renameColumn:(u,a,h)=>d(u,(p,f)=>Object.hasOwn(p.columns,a)?typeof h!="string"?E("invalid-value"):p.columns[a].name===h?{status:"unchanged"}:(f.columns[a].name=h,r(u,p,f,{status:"changed"})):E("missing-column")),moveColumn:(u,a,{afterId:h=null}={})=>d(u,(p,f)=>{if(!Object.hasOwn(p.columns,a))return E("missing-column");let m=I(p.columns).filter(O=>O!==a);if(c(m,h))return E("missing-destination");let b=l(m,h),x=I(p.columns);return[...m.slice(0,b),a,...m.slice(b)].every((O,_)=>O===x[_])?{status:"unchanged"}:(f.columns[a].pos=kt(f.columns,m,b),r(u,p,f,{status:"moved"}))}),removeColumn:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.columns,a)?(delete p.columns[a],r(u,h,p,{status:"removed",cards:i(h,a).length})):E("missing-column")),restoreColumn:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.columns,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).columns[a];return f?(p.columns[a]=f,r(u,h,p,{status:"restored"})):E("missing-column")}),createCard:(u,{columnId:a,title:h="",owner:p=null,due:f=null,afterId:m}={})=>d(u,(b,x)=>{if(!Object.hasOwn(b.columns,a))return E("missing-column");if(!yt("title",h)||!yt("owner",p)||!yt("due",f))return E("invalid-value");let O=i(b,a);if(c(O,m))return E("missing-destination");let _=k("k");return x.cards[_]={pos:kt(x.cards,O,l(O,m)),col:a,title:h,...p!==null?{owner:p}:{},...f!==null?{due:f}:{}},r(u,b,x,{status:"created",id:_})}),editCard:(u,a,h)=>d(u,(p,f)=>{if(!Object.hasOwn(p.cards,a))return E("missing-card");if(!Gn(h)||!Object.keys(h).length||Object.keys(h).some(b=>!Wn.includes(b)))return E("invalid-field");if(Object.entries(h).some(([b,x])=>!yt(b,x)))return E("invalid-value");let m={...p.cards[a]};for(let[b,x]of Object.entries(h))x===null?delete m[b]:m[b]=x;return nt(m)===nt(p.cards[a])?{status:"unchanged"}:(f.cards[a]=m,r(u,p,f,{status:"changed"}))}),moveCard:(u,a,{columnId:h,afterId:p=null}={})=>d(u,(f,m)=>{if(!Object.hasOwn(f.cards,a))return E("missing-card");if(!Object.hasOwn(f.columns,h))return E("missing-column");let b=i(f,h,a);if(c(b,p))return E("missing-destination");let x=l(b,p),O=f.cards[a];if(O.col===h){let _=i(f,h);if([...b.slice(0,x),a,...b.slice(x)].every((ct,jn)=>ct===_[jn]))return{status:"unchanged"}}return m.cards[a]={...O,col:h,pos:kt(m.cards,b,x)},r(u,f,m,{status:"moved"})}),removeCard:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.cards,a)?(delete p.cards[a],r(u,h,p,{status:"removed"})):E("missing-card")),restoreCard:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.cards,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).cards[a];return f?(p.cards[a]=f,r(u,h,p,{status:"restored"})):E("missing-card")})}}var xt="page-history-intent",Yn=500,Jn=(n,t)=>{let e=n.resolve(t);return e.depth?e.node(1).attrs.id:null},Xn=n=>(n.storedMarks??n.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(",");function qt(n,t,e,o){return{kind:"insert",blockId:Jn(n.doc,t),from:t,end:t+o.length,replaced:t!==e,text:o,marks:Xn(n),at:Date.now()}}function Ys(n,t){return!n||!t||n.kind!==t.kind?!1:t.kind==="compose"?n.id===t.id:n.blockId!==t.blockId||t.at-n.at>Yn?!1:t.kind==="insert"?!t.replaced&&t.from===n.end&&t.marks===n.marks&&!(/\s$/.test(n.text)&&/^\S/.test(t.text)):t.direction===n.direction&&(t.direction<0?t.to===n.from:t.from===n.from)}var Qn={deleteContentBackward:-1,deleteContentForward:1},jt=new WeakMap,Zn=1e3,Wt="page-derived";function to(n){let t=jt.get(n)??null;return jt.delete(n),t}function eo(n,t){if(!t||n.before!==t.doc||Date.now()-t.at>Zn||n.getMeta(He)||n.steps.length!==1)return null;let e=n.steps[0];if(e.slice?.size!==0||e.from===e.to)return null;let o=n.before.resolve(e.from),s=n.before.resolve(e.to);return!o.parent.isTextblock||!o.sameParent(s)?null:{kind:"delete",blockId:o.depth?o.node(1).attrs.id:null,direction:t.direction,from:e.from,to:e.to,at:t.at}}function Js(n,t=null){let e=t?to(t):null,o=n.filter(i=>!i.getMeta(Wt));if(o.length!==1)return null;let s=o[0],r=s.getMeta("composition");return r!=null?{kind:"compose",id:r,at:Date.now()}:s.getMeta(xt)??eo(s,e)}function Xs(){return new C.Plugin({props:{handleTextInput(n,t,e,o,s){return n.dispatch(s().setMeta(xt,qt(n.state,t,e,o))),!0},handleDOMEvents:{beforeinput(n,t){let e=Qn[t.inputType];return e&&jt.set(n,{direction:e,at:Date.now(),doc:n.state.doc}),!1}}}})}function no(n,t){if(!n||!/<table[\s>]/i.test(n))return null;let e=t.defaultView?.DOMParser??globalThis.DOMParser;if(!e)return null;let o=new e().parseFromString(n,"text/html").body,s=[...o.querySelectorAll("table")].filter(d=>!d.parentElement.closest("table"));if(s.length!==1)return null;let r=o.cloneNode(!0);for(let d of r.querySelectorAll("table, style, script, template, meta, title"))d.remove();if(r.textContent.trim())return null;let i=s[0];return{grid:[...i.querySelectorAll("tr")].filter(d=>d.closest("table")===i).map(d=>[...d.children].filter(u=>u.tagName==="TD"||u.tagName==="TH").map(u=>dt(je.parse(u,{topNode:g.nodes.table_cell.create()})))).filter(d=>d.length),own:!!i.querySelector("td[data-col]")}}function oo(n){if(!n||!n.includes(" "))return null;let{header:t,rows:e}=ht(n.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...e],own:!1}}function Ze(n,t,e=globalThis.document){let o=null;try{o=no(n,e)}catch{o=null}if(!o&&!/<table[\s>]/i.test(n||""))try{o=oo(t)}catch{o=null}if(!o||!o.grid.length)return null;let s=Math.max(...o.grid.map(r=>r.length));for(let r of o.grid)for(;r.length<s;)r.push("");return{...o,width:s,height:o.grid.length}}function Mt(n,{header:t=n.length>1}={}){let e=Math.max(0,...n.map(a=>a.length));if(!e)return null;let o=t?n[0]:[],s=t?n.slice(1):n,r=Array.from({length:e},()=>k("c")),i=N(null,null,e),l=Object.fromEntries(r.map((a,h)=>[a,{pos:i[h],name:ut(o[h]??"").replace(/\s+/g," ").trim()||`Column ${h+1}`}])),c=s.length?s:[[]],d=N(null,null,c.length),u=Object.fromEntries(c.map((a,h)=>[k("r"),{pos:d[h],cells:Object.fromEntries(r.map((p,f)=>[p,a[f]??""]))}]));return Y(g,k(),{t:"table",pos:null,cols:l,rows:u})}var{Plugin:so,TextSelection:ro}=C,Ut=g.nodes;var on=(n,t)=>{let e=null;return n.forEach((o,s)=>{!e&&o.type===Ut.table&&o.attrs.id===t&&(e={node:o,pos:s})}),e};function V(n,t){if(!t)return null;let e=on(n,t.table);if(!e)return null;let o=[];e.node.forEach(p=>o.push(p.attrs.id));let s=I(e.node.attrs.cols),r=[o.indexOf(t.anchor[0]),o.indexOf(t.head[0])],i=[s.indexOf(t.anchor[1]),s.indexOf(t.head[1])];if(r.includes(-1)||i.includes(-1))return null;let l=Math.min(...r),c=Math.max(...r),d=Math.min(...i),u=Math.max(...i),a=[],h=e.pos+1;return e.node.forEach((p,f,m)=>{if(m>=l&&m<=c){let b=[],x=h+1;p.forEach((O,_,ct)=>{ct>=d&&ct<=u&&b.push({cell:O,pos:x}),x+=O.nodeSize}),a.push(b)}h+=p.nodeSize}),{...e,top:l,bottom:c,left:d,right:u,cells:a}}var st=(n,t)=>{let e=n.resolve(t);for(let o=e.depth;o>0;o--)if(e.node(o).type===Ut.table_cell&&o>=3)return{table:e.node(o-2).attrs.id,row:e.node(o-1).attrs.id,col:e.node(o).attrs.col,start:e.start(o)};return null};function wt(n,t,e){let o=st(n.state.doc,t),s=st(n.state.doc,e);if(!o||!s||o.table!==s.table)return!1;let r={table:o.table,anchor:[o.row,o.col],head:[s.row,s.col]},i=n.state.tr.setSelection(ro.create(n.state.doc,s.start)).setMeta(S,r);n.dispatch(i);let l=V(n.state.doc,r),c=l?(l.bottom-l.top+1)*(l.right-l.left+1):0;return P(n,`${c} ${c===1?"cell":"cells"} selected`),!0}function fr(n,t,e,o){let s=n.state.doc.nodeAt(t);if(s?.type!==Ut.table||!s.childCount)return!1;let r=s.childCount-1,i=s.child(0).childCount-1,l=(c,d)=>{let u=t+1;for(let a=0;a<c;a++)u+=s.child(a).nodeSize;u++;for(let a=0;a<d;a++)u+=s.child(c).child(a).nodeSize;return u+1};return e==="row"?wt(n,l(o,0),l(o,i)):wt(n,l(0,o),l(r,o))}var io=new Set(["Shift","Control","Alt","Meta","CapsLock"]),lo=n=>/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n;function co(n,t){let e=n.cells.map(r=>r.map(({cell:i})=>lo(ut(dt(i)))).join(" ")).join(`
|
|
2
|
+
`),o=t.createElement("table"),s=o.appendChild(t.createElement("tbody"));for(let r of n.cells){let i=s.appendChild(t.createElement("tr"));for(let{cell:l}of r){let c=i.appendChild(t.createElement("td"));c.dataset.col=l.attrs.col,c.append(qe.serializeFragment(l.content,{document:t}))}}return{text:e,html:o.outerHTML}}function tn(n,t){let e=V(n.doc,S.getState(n));if(!e)return!1;if(t){let o=n.tr;for(let s of[...e.cells].reverse())for(let{cell:r,pos:i}of[...s].reverse())r.content.size&&o.delete(i+1,i+r.nodeSize-1);o.setMeta(S,S.getState(n)),t(w(o))}return!0}var en=(n,t,e)=>{let{text:o,html:s}=co(t,e.dom.ownerDocument);n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",s),n.preventDefault()},ao=(n,t)=>(e,o,s)=>{let r=S.getState(e),i=V(e.doc,r);if(!i||!s)return!1;let l=[],c=I(i.node.attrs.cols);i.node.forEach(a=>l.push(a.attrs.id));let d=Math.max(0,Math.min(l.length-1,l.indexOf(r.head[0])+n)),u=Math.max(0,Math.min(c.length-1,c.indexOf(r.head[1])+t));return o&&o(e.tr.setMeta(S,{...r,head:[l[d],c[u]]})),!0},nn=(n,t)=>{let e=t.target?.closest?.("td");if(!e||!n.dom.contains(e))return null;try{return n.posAtDOM(e,0)}catch{return null}};function mr(){let n=null;return new so({key:S,state:{init:()=>null,apply(t,e,o,s){let r=t.getMeta(S);return r!==void 0?r:!e||t.selectionSet||t.docChanged&&!t.getMeta(pt)?null:V(s.doc,e)?e:null}},props:{attributes:t=>S.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>S.getState(t.state)?t.state.selection:null,decorations(t){let e=V(t.doc,S.getState(t));return e?Pt.DecorationSet.create(t.doc,e.cells.flat().map(({cell:o,pos:s})=>Pt.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,e){let o=t.state;if(!S.getState(o))return!1;if(e.key==="Escape")return t.dispatch(o.tr.setMeta(S,null)),!0;if(e.key==="Backspace"||e.key==="Delete")return tn(o,t.dispatch);if(e.shiftKey){let s={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(s)return ao(...s)(o,t.dispatch,t)}return io.has(e.key)||(e.metaKey||e.ctrlKey)&&(e.key==="a"||e.key==="c"||e.key==="x"||e.key==="v")||t.dispatch(o.tr.setMeta(S,null)),!1},handleDOMEvents:{mousedown(t,e){if(e.button!==0)return!1;!e.shiftKey&&S.getState(t.state)&&t.dispatch(t.state.tr.setMeta(S,null));let o=nn(t,e);if(o===null)return!1;if(e.shiftKey){let c=S.getState(t.state),d=(c&&uo(t.state.doc,c))??t.state.selection.$anchor.pos;return st(t.state.doc,d)?(e.preventDefault(),wt(t,d,o)):!1}let s=t.dom.ownerDocument,r=o,i=c=>{let d=nn(t,c);if(d===null)return;let u=st(t.state.doc,r),a=st(t.state.doc,d);if(!u||!a||u.table!==a.table)return;let h=S.getState(t.state);u.row===a.row&&u.col===a.col&&!h||h&&h.head[0]===a.row&&h.head[1]===a.col||(c.preventDefault(),wt(t,r,d))},l=()=>{s.removeEventListener("mouseover",i),s.removeEventListener("mouseup",l),n=null};return n?.(),n=l,s.addEventListener("mouseover",i),s.addEventListener("mouseup",l),!1},copy(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),!0)},cut(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),tn(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>n?.()})})}function uo(n,t){let e=on(n,t.table),o=null;return e?.node.forEach((s,r)=>{if(s.attrs.id!==t.anchor[0])return;let i=e.pos+1+r+1;s.forEach(l=>{l.attrs.col===t.anchor[1]&&(o=i+1),i+=l.nodeSize})}),o}var sn=n=>{let t=V(n.doc,S.getState(n));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var Gt=new WeakMap;var{Plugin:ho,TextSelection:j}=C,T=g.nodes,Jt=256*1024,B=n=>I(n.attrs.cols),rn=n=>{let t=n.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type===T.table){let o=t.node(e),s=e<t.depth?t.index(e):0,r=e+1<t.depth?t.index(e+1):0;return{table:o,pos:t.before(e),row:s,cell:r}}return null},rt=(n,t,e,o)=>{let s=n.nodeAt(t);if(!s||!s.childCount)return null;e=Math.max(0,Math.min(e,s.childCount-1)),o=Math.max(0,Math.min(o,s.child(e).childCount-1));let r=t+1;for(let i=0;i<e;i++)r+=s.child(i).nodeSize;r++;for(let i=0;i<o;i++)r+=s.child(e).child(i).nodeSize;return r+1},St=(n,t=A())=>T.table_row.create({id:k("r"),pos:t},n.map(e=>T.table_cell.create({col:e}))),L=(n,t,e)=>T.table.create({...n.attrs,...t},e);function D(n,t,e){let o=rn(n);if(!o)return!1;let s=e(o.table,o);if(!s)return!1;if(t){let{table:r,row:i=o.row,cell:l=o.cell}=s,c=n.tr.replaceWith(o.pos,o.pos+o.table.nodeSize,r),d=rt(c.doc,o.pos,i,l);d!==null&&c.setSelection(j.create(c.doc,d)),t(w(c))}return!0}function F(n,t,e,o=null,s=null,r=null){r??=o?n.doc.resolve(o.from).index(0):n.selection.$head.index(0);let i=n.doc.child(r),l=0;for(let h=0;h<r;h++)l+=n.doc.child(h).nodeSize;let c=i.isTextblock&&(i.content.size===0||o?.from===l+1&&o?.to===l+i.nodeSize-1),d=n.doc.maybeChild(r+1),u=c?i.attrs.pos:A(i.attrs.pos,d?.attrs.pos??null),a=e.type.create({...e.attrs,pos:u,parent:i.attrs.parent??null},e.content);if(t){let h=n.tr;o&&h.delete(o.from,o.to);let p=h.mapping.map(l),f=h.doc.child(r),m=c?p:p+f.nodeSize;if(h.replaceWith(m,c?p+f.nodeSize:m,a),s){let b=s.type.create({...s.attrs,pos:A(u,d?.attrs.pos??null),parent:i.attrs.parent??null},s.content);h.insert(m+a.nodeSize,b)}h.setSelection(j.create(h.doc,rt(h.doc,m,0,0))),t(w(h).scrollIntoView())}return!0}function ln(n=3,t=3){if(!Number.isInteger(n)||!Number.isInteger(t)||n<1||t<1)return null;let e=Array.from({length:t},()=>k("c")),o=N(null,null,t),s=Object.fromEntries(e.map((l,c)=>[l,{pos:o[c],name:`Column ${c+1}`}])),i=N(null,null,n).map(l=>St(e,l));return T.table.create({id:k(),cols:s},i)}var Xt=n=>(t,e)=>{let o=rn(t);if(!o||t.selection.$head.parent.type!==T.table_cell)return!1;let s=o.table.child(o.row).childCount,r=o.row,i=o.cell;return n==="down"?r++:(i+=n,i>=s&&(r++,i=0),i<0&&(r--,i=s-1)),r<0?!0:r>=o.table.childCount?n===-1?!0:po(t,e,o,i):(e&&e(t.tr.setSelection(j.create(t.doc,rt(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function po(n,t,e,o){let s=[...e.table.content.content];if(s.push(St(B(e.table),A(s.at(-1).attrs.pos,null))),t){let r=n.tr.replaceWith(e.pos,e.pos+e.table.nodeSize,L(e.table,{sort:null},s));r.setSelection(j.create(r.doc,rt(r.doc,e.pos,s.length-1,o))),t(w(r).scrollIntoView())}return!0}var fo=Xt(1),mo=Xt(-1),go=Xt("down"),bo=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=[...o.content.content],i=s.row+(n?1:0),l=A(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,St(B(o),l)),{table:L(o,{sort:null},r),row:i}}),Lr=(n,t)=>D(n,t,(e,o)=>{let s=[...e.content.content];if(s.length===1){let r=s[0];s[0]=T.table_row.create(r.attrs,B(e).map(i=>T.table_cell.create({col:i})))}else s.splice(o.row,1);return{table:L(e,{sort:null},s),row:Math.min(o.row,s.length-1)}}),cn=(n,t,e,o,s)=>{let{pos:r,rekey:i}=Vt(t,c=>n[c]?.pos??"",e),l={...n,[o]:{...s,pos:r}};for(let[c,d]of i)l[c]={...l[c],pos:d};return l},Dr=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+(n?1:0),l=k("c"),c=cn(o.attrs.cols,r,i,l,{name:`Column ${r.length+1}`}),d=o.content.content.map(u=>{let a=[...u.content.content];return a.splice(i,0,T.table_cell.create({col:l})),T.table_row.create(u.attrs,a)});return{table:L(o,{cols:c},d),cell:i}}),$r=(n,t)=>D(n,t,(e,o)=>{let s=B(e);if(s.length<=1)return null;let r={...e.attrs.cols};delete r[s[o.cell]];let i=e.content.content.map(l=>T.table_row.create(l.attrs,l.content.content.filter((c,d)=>d!==o.cell)));return{table:L(e,{cols:r,sort:e.attrs.sort?.col===s[o.cell]?null:e.attrs.sort},i),cell:Math.min(o.cell,s.length-2)}}),_r=n=>(t,e)=>D(t,e,(o,s)=>{let r=s.row+n;if(r<0||r>=o.childCount)return null;let i=[...o.content.content],[l]=i.splice(s.row,1);i.splice(r,0,l);let c=A(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=T.table_row.create({...l.attrs,pos:c},l.content),{table:L(o,{sort:null},i),row:r}}),Br=n=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+n;if(i<0||i>=r.length)return null;let l=[...r],[c]=l.splice(s.cell,1);l.splice(i,0,c);let d=cn(o.attrs.cols,l.filter(a=>a!==c),i,c,o.attrs.cols[c]),u=o.content.content.map(a=>{let h=[...a.content.content],[p]=h.splice(s.cell,1);return h.splice(i,0,p),T.table_row.create(a.attrs,h)});return{table:L(o,{cols:d},u),cell:i}}),yo=48,ko=1200,Pr=160,an=n=>Number.isFinite(n)&&n>0?Math.round(Math.min(ko,Math.max(yo,n))):null,Rr=n=>(t,e)=>D(t,e,o=>{let s=B(o);if(!s.some(i=>o.attrs.cols[i].width))return null;let r={};for(let i of s){let{width:l,...c}=o.attrs.cols[i];r[i]=c}return{table:L(o,{cols:r},o.content),cell:Math.max(0,s.indexOf(n))}}),Nr=(n,t)=>(e,o)=>D(e,o,s=>{let r={...s.attrs.cols},i=!1;for(let[l,c]of Object.entries(n)){let d=an(c);!r[l]||d===null||r[l].width===d||(r[l]={...r[l],width:d},i=!0)}return i?{table:L(s,{cols:r},s.content),cell:B(s).indexOf(t)}:null}),Hr=(n,t)=>(e,o)=>D(e,o,s=>{let r=s.attrs.cols[n];if(!r)return null;let i=t===null?null:an(t);if(t!==null&&i===null||(r.width??null)===i)return null;let{width:l,...c}=r,d={...s.attrs.cols,[n]:i===null?c:{...r,width:i}};return{table:L(s,{cols:d},s.content),cell:B(s).indexOf(n)}}),zr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!String(t).trim())return null;let r={...s.attrs.cols,[n]:{...s.attrs.cols[n],name:String(t).trim()}};return{table:L(s,{cols:r},s.content)}}),Fr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!(t==="auto"||Te.includes(t)))return null;let{kind:r,...i}=s.attrs.cols[n],l={...s.attrs.cols,[n]:t==="auto"?i:{...s.attrs.cols[n],kind:t}};return{table:L(s,{cols:l,sort:s.attrs.sort?.col===n?null:s.attrs.sort},s.content)}}),Kr=(n,t="asc")=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!["asc","desc"].includes(t))return null;let r=B(s).indexOf(n),i=Je(s)[n],l=[...s.content.content].map((u,a)=>({row:u,previous:a,text:u.child(r).textContent.trim()}));l.sort((u,a)=>{if(!u.text||!a.text)return!u.text&&!a.text?u.previous-a.previous:u.text?-1:1;let h=i==="number"?Nt(u.text):u.text,p=i==="number"?Nt(a.text):a.text;if(h==null||p==null)return h==null&&p==null?u.previous-a.previous:h==null?1:-1;let f=i==="number"?h-p:i==="date"?h<p?-1:h>p?1:0:h.localeCompare(p,void 0,{numeric:!0,sensitivity:"base"});return f?t==="asc"?f:-f:u.previous-a.previous});let c=N(null,null,l.length),d=l.map(({row:u},a)=>T.table_row.create({...u.attrs,pos:c[a]},u.content));return{table:L(s,{sort:{col:n,dir:t}},d)}}),Yt=(n,t=null)=>(e,o)=>D(e,o,(s,r)=>{let i=B(s),l=t?.row??r.row,c=t?.cell??r.cell,d=[...s.content.content];n.forEach((a,h)=>{let p=l+h;p>=d.length&&d.push(St(i,A(d.at(-1).attrs.pos,null)));let f=[...d[p].content.content];a.forEach((m,b)=>{c+b<i.length&&(f[c+b]=T.table_cell.create({col:i[c+b]},we(g,m)))}),d[p]=T.table_row.create(d[p].attrs,f)});let u=Math.max(1,...n.map(a=>a.length));return{table:L(s,{sort:null},d),row:l+n.length-1,cell:Math.min(c+u-1,i.length-1)}}),xo=n=>new TextEncoder().encode(JSON.stringify(n.toJSON())).length;function Mo(n,t){let e=t.clipboardData;if(!e||e.files?.length)return!1;let o=n.state;if(o.selection.$from.parent.type.spec.code)return!1;let s=sn(o),r=e.getData("text/plain").replace(/\r?\n$/,""),i=Ze(e.getData("text/html"),e.getData("text/plain"),n.dom.ownerDocument)??(s&&r&&!/[\r\n]/.test(r)?{grid:[[r]],width:1,height:1,own:!1}:null);if(!i)return!1;if(s&&s.rows*s.cols>1&&i.width*i.height===1)return Yt(Array.from({length:s.rows},()=>Array(s.cols).fill(i.grid[0][0])),{row:s.row,cell:s.cell})(o,n.dispatch);if(s)return Yt(i.grid,{row:s.row,cell:s.cell})(o,n.dispatch);if(o.selection.$head.parent.type===T.table_cell)return i.width*i.height<2?!1:Yt(i.grid)(o,n.dispatch);if(i.width*i.height<2||i.own||i.height<2&&!/<table[\s>]/i.test(e.getData("text/html")))return!1;let l=Mt(i.grid,{header:i.height>1});if(!l)return!1;if(xo(l)>Jt)return H("This paste is too large for one table.","error"),!0;let{from:c,to:d,empty:u,$from:a,$to:h}=o.selection;if(!u&&a.index(0)!==h.index(0)){let p=o.tr.deleteSelection();return F(o.apply(p),f=>{for(let m of f.steps)p.step(m);p.setSelection(j.create(p.doc,f.selection.from)),n.dispatch(w(p).scrollIntoView())},l)}return F(o,n.dispatch,l,u?null:{from:c,to:d})}var Vr=at.keymap({Tab:fo,"Shift-Tab":mo,Enter:go,"Mod-Enter":bo(!0)});function wo(n,t){let e=Gt.get(t.target),o=e?.getPos();if(o==null||t.button||t.shiftKey||!n.editable)return!1;t.preventDefault();let s=t.clientX<e.contentDOM.getBoundingClientRect().left;return n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,o+1+(s?0:e.node.content.size)))),n.focus(),e.openDate(),!0}function jr(){return new ho({props:{handlePaste:Mo,handleDOMEvents:{mousedown:wo},handleClickOn(n,t,e,o,s,r){if(e.type!==T.table_cell||!r||s.button)return!1;let i=n.nodeDOM(o),l=i&&Gt.get(i);return l&&l.openDate(),!1}},appendTransaction(n,t,e){if(!n.some(r=>r.docChanged&&!r.getMeta(pt)))return null;let o=new Map;t.doc.forEach(r=>{r.type===T.table&&o.set(r.attrs.id,r)});let s=e.tr;return e.doc.forEach((r,i)=>{if(r.type!==T.table||!r.attrs.sort)return;let l=o.get(r.attrs.id),c=r.attrs.sort.col;if(!l)return;let d=h=>Object.fromEntries(h.content.content.map(p=>[p.attrs.id,p.content.content.find(f=>f.attrs.col===c)?.textContent])),u=d(l),a=d(r);(Object.keys(u).length!==Object.keys(a).length||Object.keys(u).some(h=>u[h]!==a[h]||!Object.hasOwn(a,h)))&&s.setNodeMarkup(i,null,{...r.attrs,sort:null})}),s.docChanged?s.setMeta(Wt,!0):null}})}function qr(n,t,e){let o=n.state.doc.nodeAt(t);if(o?.type!==T.table_cell)return!1;let s=n.state.tr.replaceWith(t+1,t+o.nodeSize-1,e?g.text(e):[]);return n.dispatch(s.setSelection(j.create(s.doc,t+1+e.length))),!0}function Wr(n,t,e,o){let s=rt(n.state.doc,t,e,o);return s===null?!1:(n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,s))),!0)}var{TextSelection:So}=C,Qt=g.nodes,To=Object.freeze(["To do","In progress","Done"]),un=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function Zt(n=To){let t=N(null,null,n.length),e=Object.fromEntries(n.map((o,s)=>[k("c"),{pos:t[s],name:o}]));return Qt.board.create({id:k(),columns:e,cards:{}})}function dn(n,t,e=Zt(),o=null,s=null){let r=n.tr;o&&r.delete(o.from,o.to),s??=r.doc.resolve(r.mapping.map(n.selection.head)).index(0);let i=J(r.doc),l=r.doc.child(s),c=l.isTextblock&&l.content.size===0,d=c?s:i[s].subEnd,u=c?i[s].at:i[d].end,a=i[d+1]?.node.attrs.pos??null,h=l.attrs.parent??null,p=c?l.attrs.pos:un(i[d].node.attrs.pos,a),f=Qt.board.create({...e.attrs,pos:p,parent:h}),m=Qt.paragraph.create({id:k(),pos:un(p,a),parent:h});return r.replaceWith(u,c?i[s].end:u,[f,m]),r.setSelection(So.create(r.doc,u+f.nodeSize+1)),t&&t(w(r).scrollIntoView()),!0}function hn(n){let t=[];return n.forEach(e=>{e.type===g.nodes.table&&I(e.attrs.cols).length>1&&t.push(e)}),t}function ni(n,t){let e="",o=0,s=null;return n.forEach(r=>{s===null&&(r.type===g.nodes.heading&&(e=r.textContent),r.type===g.nodes.table&&(o+=1,r.attrs.id===t&&(s=e||`Table ${o}`),e=""))}),s}var pn=new Set(["page-format-unsupported","unsupported-host"]),Eo="This host can't store that yet, so nothing was added.",Co="That didn't go through. Try again.",Ao="That couldn't be added here.";function fn(n,t){let e=t?.status==="upgrade-required"&&t.message?t.message:pn.has(t?.code)||pn.has(t?.status)?Eo:t?.retry===!0?Co:Ao;n.isDestroyed||(P(n,e),H(e,"error"))}async function Tt(n,t){if(typeof n.runFormatCommand!="function")return fn(n,{code:"page-format-unsupported"}),{ok:!1,code:"page-format-unsupported"};let e=await n.runFormatCommand(t);return e?.status==="applied"?e.result:(fn(n,e),{ok:!1,code:e?.code??e?.status??"page-format-refused",retry:e?.retry===!0})}var{TextSelection:it}=C,v=g.nodes,q=[{key:"text",label:"Text",description:"Plain writing",icon:"T",type:"paragraph",aliases:["p","paragraph","plain"]},{key:"h1",label:"Heading 1",description:"Big section heading",icon:"H1",type:"heading",attrs:{level:1},hint:"#",aliases:["h1","title"]},{key:"h2",label:"Heading 2",description:"Medium section heading",icon:"H2",type:"heading",attrs:{level:2},hint:"##",aliases:["h2","subtitle"]},{key:"h3",label:"Heading 3",description:"Small section heading",icon:"H3",type:"heading",attrs:{level:3},hint:"###",aliases:["h3"]},{key:"bullet",label:"Bulleted list",description:"A simple list",icon:"\u2022",type:"list_item",attrs:{kind:"bullet"},hint:"-",aliases:["ul","bullet","list","unordered"]},{key:"ordered",label:"Numbered list",description:"A list with numbers",icon:"1.",type:"list_item",attrs:{kind:"ordered"},hint:"1.",aliases:["ol","num","numbered","ordered"]},{key:"check",label:"Checklist",description:"Tasks to tick off",icon:"\u2610",type:"list_item",attrs:{kind:"check"},hint:"[]",aliases:["todo","to-do","task","check","checkbox"]},{key:"toggle",label:"Toggle",description:"Hide details under a line",icon:"\u25B8",type:"toggle",attrs:{open:!0},hint:">",aliases:["collapse","details","fold"]},{key:"toggle-h1",label:"Toggle heading 1",description:"Collapsible heading",icon:"H1",type:"toggle",attrs:{open:!0,level:1},aliases:["toggle heading"]},{key:"toggle-h2",label:"Toggle heading 2",description:"Collapsible heading",icon:"H2",type:"toggle",attrs:{open:!0,level:2},aliases:["toggle heading"]},{key:"toggle-h3",label:"Toggle heading 3",description:"Collapsible heading",icon:"H3",type:"toggle",attrs:{open:!0,level:3},aliases:["toggle heading"]},{key:"callout",label:"Callout",description:"Make a note stand out",icon:"!",type:"callout",aliases:["note","aside","info"]},{key:"quote",label:"Quote",description:"Set text apart as a quotation",icon:"\u201C",type:"quote",hint:'"',aliases:["blockquote","quotation","cite"]},{key:"code",label:"Code",description:"Code with highlighting",icon:"</>",type:"code_block",hint:"```",aliases:["pre","snippet"]}],Oo=[{key:"divider",label:"Divider",description:"A line between sections",icon:"\u2014",hint:"---",aliases:["hr","line","separator","rule"],insert:"divider"},{key:"toc",label:"Table of contents",description:"Links to this page's headings",icon:"\u2261",aliases:["toc","contents","outline","index"],insert:"toc"},{key:"image",label:"Image",description:"Upload or paste a picture",icon:"\u25A3",aliases:["img","picture","photo"],insert:"image"},{key:"file",label:"File",description:"Attach any file",icon:"\u2398",aliases:["upload","attachment","pdf"],insert:"file"},{key:"table",label:"Table",description:"Rows and columns, paste from a spreadsheet",icon:"\u25A6",aliases:["grid","spreadsheet"],insert:"table"},{key:"csv",label:"Import CSV\u2026",description:"Turn a CSV file into a table",icon:"\u21E7",aliases:["comma separated","import"],insert:"csv"},{key:"board",label:"Board",description:"Cards in columns, like a kanban",icon:"\u25A5",aliases:["kanban","cards","columns","status"],insert:"board"},{key:"mention",label:"Mention",description:"Name someone on the page",icon:"@",aliases:["person","people","assign"],command:"mentions"},{key:"date",label:"Date",description:"Today, tomorrow or a calendar day",icon:"\u25A7",aliases:["calendar","today","tomorrow","due"],command:"dates"},{key:"emoji",label:"Emoji",description:"Insert one glyph",icon:"\u263A",aliases:["smiley","glyph","symbol"],command:"emoji"},{key:"import-markdown",label:"Import Markdown\u2026",description:"Turn a Markdown file into blocks",icon:"M\u2193",aliases:["md","markdown","import"],command:"importMarkdown"}],vo={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},te=n=>(Ne.get(n)?.ensure("chart")??Promise.resolve()).catch(()=>{}).then(()=>n.isDestroyed?null:import("./c-WFMRX5RZ.js")),At=[...q,...Oo],gn=(n,t=At)=>hn(n.doc).length?[...t,vo]:t;function Ot(n){let t=n.type.name;return q.find(e=>e.type===t&&(!e.attrs||(t==="heading"||t==="toggle"?(e.attrs.level??null)===(n.attrs.level??null):t==="list_item"?e.attrs.kind===n.attrs.kind:!0)))??q[0]}var ee=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e};function G(n,t,e){let o=ee(n.doc,t),s=n.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===v.list_item&&e.type==="list_item"&&(r.indent=s.attrs.indent),n.setBlockType(o+1,o+s.nodeSize-1,v[e.type],{...r,...e.attrs||{}})}var bn=Object.freeze({status:"refused",code:"unsupported-format"}),Io=xe([]).type,Lo=n=>{let t=!1;return n.forEach(e=>{!t&&e.marks.some(ke)&&(t=!0)}),t};function Q(n,t){return!n.isTextblock||n.type===v.opaque_block?!1:!Lo(n)||v[t.type].allowsMarkType(Io)}var yn=n=>n.type==="toggle"&&n.attrs?.level!=null,Et=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e},ne={ok:!1,code:"stale-target"};function kn(n,t,e){let o=()=>e.map(r=>Et(n.state.doc,r)),s=()=>{let r=o();if(r.includes(-1))return ne;if(r.some(l=>!Q(n.state.doc.child(l),t)))return bn;let i=n.state.tr;for(let l of r)G(i,l,t);return n.dispatch(w(i).scrollIntoView()),n.focus(),{ok:!0}};return yn(t)?Tt(n,s):t.type==="quote"?import("./c-VBLFAQD2.js").then(r=>n.isDestroyed?!1:r.gateTurn(n,s)):s()}function xn(n,t,e=n.tr){let o=J(e.doc),{to:s}=ze(o,t),r=e.doc.child(t);return e.insert(s,v.paragraph.create({parent:r.attrs.parent??null})),e.setSelection(it.create(e.doc,s+1))}var X=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function oe(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.divider.create({id:r,pos:i,parent:l}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function Do(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return oe(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.divider.create({id:k(),pos:c,parent:d}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function $o(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.toc.create({id:r,pos:i,parent:l,maxLevel:3}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function _o(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return $o(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.toc.create({id:k(),pos:c,parent:d,maxLevel:3}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function Bo(n,t){if(n.length<2||n.length>32)return 1/0;let e=-1,o=0;for(let s of n){let r=t.indexOf(s,e+1);if(r<0)return 1/0;o+=r-e-1,e=r}return o}function Mn(n,t){let e=t.trim().toLowerCase();if(!e)return n;let o=s=>{let r=s.label.toLowerCase(),i=[s.key,...s.aliases||[],...s.hint?[s.hint]:[]].map(c=>c.toLowerCase());if(r===e||i.includes(e))return[0,0];if(r.startsWith(e))return[1,0];if([...r.split(/\s+/),...i].some(c=>c.startsWith(e)))return[2,0];if([r,...i].some(c=>c.includes(e)))return[3,0];if(e.length>=3&&s.description&&s.description.toLowerCase().split(/[^a-z0-9]+/).some(c=>c.startsWith(e)))return[4,0];let l=Math.min(...[r,s.key,...s.aliases||[]].map(c=>Bo(e,c.toLowerCase())));return l===1/0?null:[5,l]};return n.map((s,r)=>({it:s,order:r,rank:o(s)})).filter(s=>s.rank).sort((s,r)=>s.rank[0]-r.rank[0]||s.rank[1]-r.rank[1]||s.order-r.order).map(s=>s.it)}function mn(n,t,e,o){let s=n.state,r=s.tr;o&&r.delete(o.from,o.to);let i=r.doc.child(e);return i.isTextblock&&i.content.size===0&&!Q(i,t)?bn:(t.insert==="divider"?r=Do(s,e,r):i.isTextblock&&i.content.size===0?r=G(r,e,t):(r=xn(s,e,r),r=G(r,r.doc.resolve(r.selection.head).index(0),t)),n.dispatch(w(r).scrollIntoView()),n.focus(),!0)}function Po(n,t,e=null){let o=n.state,s=o.doc.maybeChild(t)?.attrs.id??null,r=e&&{...e,text:o.doc.textBetween(e.from,e.to)};return Tt(n,()=>{let i=n.state;if((s===null?-1:Et(i.doc,s))<0||r&&i.doc.textBetween(r.from,r.to)!==r.text)return ne;let c=r?i.tr.delete(r.from,r.to):i.tr;return c=_o(i,Et(c.doc,s),c),n.dispatch(w(c).scrollIntoView()),n.focus(),{ok:!0}})}var Z=(n,t,e)=>import("./page/editor-EY2WAAGB.js").then(({runPageCommand:o})=>n.isDestroyed?{ok:!1,code:"not-editing"}:o(n,t,e));function Ro(n,t,e){return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),Z(n,t,{})}function wn(n,t,e,o=null){let s=n.state;if(t.insert==="image"||t.insert==="file")return Re(n,t.insert==="image"?"image/*":"",Pe(s,e),o);if(t.insert==="csv")return Ct(n,o);if(t.insert==="table")return F(s,n.dispatch,ln(),o,null,e);if(t.insert==="board")return dn(s,n.dispatch,Zt(),o,e);if(t.insert==="chart")return te(n).then(l=>l&&!n.isDestroyed?l.chartFromSlash(n,e,o):!1);if(t.insert==="toc")return Po(n,e,o);if(t.command)return Ro(n,t.command,o);if(!yn(t)&&t.type!=="quote")return mn(n,t,e,o);let r=s.doc.maybeChild(e)?.attrs.id??null,i=o&&{...o,text:s.doc.textBetween(o.from,o.to)};return Tt(n,()=>{let l=n.state,c=r===null?-1:Et(l.doc,r);return c<0||i&&l.doc.textBetween(i.from,i.to)!==i.text?ne:mn(n,t,c,i)})}var{InputRule:ie}=Rt,W=g.nodes,vt=(n,t,e)=>n.doc.rangeHasMark(t,e,g.marks.code)||!!g.marks.code.isInSet(n.storedMarks||n.selection.$from.marks()),tt=(n,t,e=["paragraph"],o=!1)=>new ie(n,(s,r,i,l)=>{let c=s.doc.resolve(i);return!s.selection.empty||c.depth!==1||c.parentOffset!==0||!e.includes(c.parent.type.name)||o&&l!==c.end()||vt(s,i,l)?null:w(G(s.tr.delete(i,l),c.index(0),typeof t=="function"?t(r):t))}),No=new ie(/^---$/,(n,t,e,o)=>{let s=n.doc.resolve(e);return!n.selection.empty||s.depth!==1||s.parent.type!==W.paragraph||s.parentOffset!==0||s.parent.content.size!==o-e||vt(n,e,o)?null:w(oe(n.tr,s.index(0)))}),le=`\\s\\(\\[\\{'\u2018\u201C"`,Ho=new RegExp(`[${le}]`),se=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Sn=n=>`([^\\s${n}](?:[\\s\\S]*?[^\\s${n}])?)`,It=(n,t)=>!!n?.isComposing||n?.keyCode===229||!!t?.composing,Tn=n=>{let t=0;for(let e=n.length-1;e>=0&&n[e]==="\\";e--)t++;return t},zo=(n,t)=>{let e=n.doc.resolve(t);return!e.parent.inlineContent||Tn(e.parent.textBetween(0,e.parentOffset,null,"\uFFFC"))%2?!1:e.parentOffset===0||Ho.test(e.parent.textBetween(e.parentOffset-1,e.parentOffset))},Fo=(n,t,e,o,s)=>{let r=s(t);if(!r||!n.selection.empty||e<0||e>o||o>n.doc.content.size)return null;let i=n.doc.resolve(e),l=n.doc.resolve(o);if(!i.sameParent(l)||!i.parent.inlineContent)return null;let[c,d,u,a]=t;if(vt(n,e,o))return null;let h=c.slice(d.length,c.length-u.length-a.length),p=e+d.length;if(!zo(n,p)||Tn(c.slice(0,c.length-a.length))%2)return null;let f=c.length-(o-e);if(f<0)return null;let m=n.tr;f&&m.insertText(c.slice(-f),o,o);let b=p+h.length,x=b+u.length;return m.delete(x,e+c.length),m.delete(p,b),m.addMark(p,p+u.length,r),m.removeStoredMark(r.type),w(m)},En=(n,t)=>new ie(n,(e,o,s,r)=>Fo(e,o,s,r,t),{inCodeMark:!1}),et=(n,t,e)=>En(new RegExp(`(^|[${le}])${se(n)}${Sn(se(t))}(${se(t)})$`),()=>e.create()),Ko=En(new RegExp(`(^|[${le}])\\[${Sn("\\[\\]")}(\\]\\([^()\\s]*\\))$`),n=>{let t=be(n[3].slice(2,-1));return t?g.marks.link.create({href:t}):null}),Vo=[et("**","**",g.marks.strong),et("__","__",g.marks.strong),et("*","*",g.marks.em),et("_","_",g.marks.em),et("`","`",g.marks.code),et("~~","~~",g.marks.strike),Ko],re=["paragraph","list_item"],jo=[tt(/^(#{1,3})\s$/,n=>({type:"heading",attrs:{level:n[1].length}})),tt(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},re),tt(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},re),tt(/^\[( |x|X)?\]\s$/,n=>({type:"list_item",attrs:{kind:"check",checked:!!n[1]&&n[1]!==" "}}),re),tt(/^>\s$/,{type:"toggle",attrs:{open:!0}}),tt(/^```$/,{type:"code_block"},["paragraph"],!0),No,...Vo];function qo(n,t,e,o,s){if(s!==" "||e!==o)return!1;let r=t.state,i=r.doc.resolve(e),l=i.parent;if(i.depth!==1||l.type!==W.paragraph||i.parentOffset!==1||l.textContent!=='"'||!t.editable||typeof t.runFormatCommand!="function")return!1;let c=()=>{t.isDestroyed||t.state.doc!==r.doc||t.dispatch(t.state.tr.insertText(" ",e,o))},d=i.before(1);return import("./c-VBLFAQD2.js").then(({quoteFromSpace:u})=>u(n,t,{at:d,from:e,to:o},c),c),!0}var Oi=()=>{let n=Rt.inputRules({rules:jo}),t=n.props.handleTextInput;return n.props.handleTextInput=(e,o,s,r)=>qo(n,e,o,s,r)||t(e,o,s,r),n},Wo=/^\s*\|(.*)\|\s*$/;function Uo(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parent.type!==W.paragraph||e.parentOffset!==e.parent.content.size||vt(n,e.start(),e.end()))return!1;let s=Wo.exec(e.parent.textContent);if(!s)return!1;let r=s[1].split("|").map(l=>l.trim());if(!r.some(Boolean))return!1;let i=Mt([r,r.map(()=>"")],{header:!0});return F(n,t,i,{from:e.start(),to:e.end()})}var vi=()=>at.keymap({Enter:(n,t,e)=>!It(null,e)&&Uo(n,t)});function Ii(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parentOffset!==0)return!1;let s=e.parent;return s.type===W.heading||s.type===W.callout||s.type===W.quote||s.type===W.code_block&&s.content.size===0?(t&&t(w(n.tr.setNodeMarkup(e.before(),W.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:In,PluginKey:Ln,TextSelection:$t,NodeSelection:Go}=C,Dn=g.marks,U=g.nodes,Dt=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",$n=n=>{let t=gt(n.doc),{lo:e,hi:o}=n.selection.span(n.doc);return t.slice(e,o+1).filter(s=>s.up===t[e].up)},Lt=(n,t)=>n.state.doc.child(t).attrs.id,Yo=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e},Cn=["aria-haspopup","aria-controls","aria-activedescendant"],Jo="That block is no longer available.",he="This block holds content from a newer version, so it can't be converted here.";function ce(n){let t=n.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:n.innerWidth,height:n.innerHeight}}function Xo(n,t,e,o=0){let s=$,r=Math.min(t,Math.max(0,n.width-s*2));return{left:n.left+(n.width-r)/2,top:Math.max(n.top+s,n.top+n.height-e-o-s),width:r}}function Qo(n,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(n)}`}function Zo(n){if(!n)return;let t=()=>H("Link copied"),e=()=>H("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){e();return}globalThis.navigator.clipboard.writeText(Qo(n)).then(t,e)}var _n=[{key:"up",label:"Move up",icon:"up",hint:`${Dt}\u21E7\u2191`,run:n=>Ht(-1)(n.state,n.dispatch)},{key:"down",label:"Move down",icon:"down",hint:`${Dt}\u21E7\u2193`,run:n=>Ht(1)(n.state,n.dispatch)},{key:"indent",label:"Indent",icon:"indent",hint:"Tab",run:n=>{let t=n.state.doc;Ke(n.state,n.dispatch),n.state.doc===t&&(P(n,"Indent works on list items and inside toggles."),H("Indent works on list items and inside toggles."))}},{key:"outdent",label:"Outdent",icon:"outdent",hint:"\u21E7Tab",run:n=>Ve(n.state,n.dispatch)},{key:"duplicate",label:"Duplicate",icon:"duplicate",hint:`${Dt}D`,run:n=>Ue(n.state,n.dispatch)},{key:"delete",label:"Delete",icon:"trash",hint:"Del",run:n=>Ft(n.state,n.dispatch)},{key:"turn",label:"Turn into",icon:"turn",hint:"\u203A",only:"text",run:(n,t)=>t.openMenu("turn",t.plus)},{key:"link",label:"Copy link",icon:"link",run:(n,t,e)=>Zo(n.state.doc.child(e).attrs.id)},{key:"alt",label:"Alt text\u2026",icon:"alt",only:"image",focus:!1,run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.openAltEditor(n,o))}},{key:"small",label:"Small",icon:"small",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.setImageAttrs(n,o,{width:240}))}},{key:"medium",label:"Medium",icon:"medium",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.setImageAttrs(n,o,{width:480}))}},{key:"full",label:"Full width",icon:"full",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.setImageAttrs(n,o,{width:null}))}},{key:"chart",label:"Chart this table",icon:"chart",only:"table",run:(n,t,e)=>{let o=Yo(n.state.doc,e);return te(n).then(({insertChartAfterTable:s})=>s(n,o))}},{key:"csv",label:"Import CSV\u2026",icon:"csv",only:"table",focus:!1,run:(n,t,e)=>Ct(n,null,n.state.doc.child(e).attrs.id)}],ts=n=>{if(!(n.selection instanceof z))return[];let t=$n(n),e=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===U.image,s=t.length===1&&t[0].node.type===U.table;return _n.filter(r=>r.only==="text"?e:r.only==="image"?o:r.only==="table"?s:!0)},M=n=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,K={plus:M('<path d="M8 3.5v9M3.5 8h9"/>'),grip:M('<path stroke-width="2.2" d="M6 3.5h.01M10 3.5h.01M6 8h.01M10 8h.01M6 12.5h.01M10 12.5h.01"/>'),strong:M('<path d="M5 3h4a2.5 2.5 0 0 1 0 5H5zM5 8h4.6a2.5 2.5 0 0 1 0 5H5z"/>'),em:M('<path d="M10 3H6.5M9.5 13H6M9 3l-2 10"/>'),strike:M('<path d="M3 8h10M10.8 5.2C10.5 4 9.4 3.2 8 3.2c-1.7 0-2.8.9-2.8 2.1M5.2 10.8c.3 1.2 1.4 2 2.8 2 1.7 0 2.8-.9 2.8-2.1"/>'),code:M('<path d="M6 4.5 2.5 8 6 11.5M10 4.5 13.5 8 10 11.5"/>'),link:M('<path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.7.7M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.7-.7"/>'),bullet:M('<path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7"/><path stroke-width="2.4" d="M3 4.5h.01M3 8h.01M3 11.5h.01"/>'),ordered:M('<path d="M7 4.5h6.5M7 8h6.5M7 11.5h6.5M2.5 3.5l1-.5v3M2.5 9.3c.2-.5.6-.8 1.1-.8.6 0 1 .4 1 .9 0 .9-2.1 1.4-2.1 2.6h2.1"/>'),check:M('<rect x="2.5" y="2.5" width="11" height="11" rx="2.5"/><path d="M5.5 8.2l1.8 1.8 3.4-4"/>'),more:M('<path stroke-width="2.2" d="M3 8h.01M8 8h.01M13 8h.01"/>'),gear:M('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),close:M('<path d="M4 4l8 8M12 4l-8 8"/>'),up:M('<path d="M8 13V3.5M4 7.5 8 3.5l4 4"/>'),down:M('<path d="M8 3v9.5M4 8.5l4 4 4-4"/>'),indent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M2.5 6l2.5 2-2.5 2"/>'),outdent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M5 6 2.5 8 5 10"/>'),duplicate:M('<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 3.5v-.5A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v5A1.5 1.5 0 0 0 4 9.5h.5"/>'),trash:M('<path d="M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5"/>'),turn:M('<path d="M3 5.5h9.5M10 3l2.5 2.5L10 8M13 10.5H3.5M6 8l-2.5 2.5L6 13"/>'),chart:M('<path d="M3 13V3M3 13h10.5M6 10.5V8M9 10.5V5.5M12 10.5V7"/>'),csv:M('<path d="M4 1.5h5L12.5 5v9.5h-8.5zM9 1.5V5h3.5M8 7.5v5M6 10.5l2 2 2-2"/>'),alt:M('<path d="M2.5 12.5 5.5 4l3 8.5M3.6 9.5h3.8M10 12.5V7.5M10 8.5c.4-.7 1.1-1 2-1h.5"/>'),small:M('<rect x="5" y="5" width="6" height="6" rx="1"/>'),medium:M('<rect x="3.5" y="3.5" width="9" height="9" rx="1.2"/>'),full:M('<rect x="1.5" y="3.5" width="13" height="9" rx="1.2"/>')},ae=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],Bn=new Set(["strong","em","link"]),es=new Set(["up","down","indent","outdent"]),ns=204,os=52,$=8,Pn=new Set(["bullet","ordered","check"]),ss=[["assignees","Checklist assignees"],["dates","Checklist due dates"]],rs=new Set(["paragraph","heading","list_item"]),lt=n=>{let t=n.selection;if(t instanceof z)return $n(n).map(l=>l.i);let{$from:e,$to:o,empty:s}=t,r=Math.min(!s&&o.depth===0?o.index(0)-1:o.index(0),n.doc.childCount-1),i=[];for(let l=e.index(0);l<=r;l++)i.push(l);return i},Rn=n=>lt(n).filter(t=>{let e=n.doc.child(t);return e.isTextblock&&e.type!==U.code_block}),Nn=(n,t)=>n.type===U.list_item&&n.attrs.kind===t,Hn=(n,t)=>{let e=Rn(n);return e.length>0&&e.every(o=>Nn(n.doc.child(o),t))},is=n=>{let t="";return n.forEach(e=>{t+=e.isText?e.text:e.type===U.hard_break?`
|
|
3
3
|
`:""}),t};function ls(n){let{$from:t,$to:e,empty:o}=n.selection;if(o||!(n.selection instanceof $t)||t.depth!==1||e.depth!==1||t.parentOffset!==0||e.parentOffset!==e.parent.content.size)return null;let s=lt(n);return s.every(r=>rs.has(n.doc.child(r).type.name))?s:null}function cs(n,t){let e=n.doc.child(t[0]),o=n.selection.$from.before(1),s=n.selection.$to.after(1),r=t.map(u=>is(n.doc.child(u))).join(`
|
|
4
4
|
`),{id:i,pos:l,parent:c}=e.attrs,d=n.tr.replaceWith(o,s,U.code_block.create({id:i,pos:l,parent:c},r?g.text(r):null));return d.setSelection($t.create(d.doc,o+1,o+1+r.length))}function as(n,t){let e=n.tr,o=n.doc.resolve(n.selection.from).before(1),s=0;for(let r of[...t].reverse()){let i=0;for(let h=0;h<r;h++)i+=n.doc.child(h).nodeSize;let l=n.doc.child(r),{id:c,pos:d,parent:u}=l.attrs,a=l.textContent.split(`
|
|
5
|
-
`).map((h,p)=>U.paragraph.create(p===0?{id:c,pos:d,parent:u}:{parent:u},h?g.text(h):null));e.replaceWith(i,i+l.nodeSize,a),s||(s=i+a.reduce((h,p)=>h+p.nodeSize,0))}return s=e.mapping.slice(1).map(s),e.setSelection($t.create(e.doc,o+1,s-1))}var zn=n=>{let t=lt(n);return t.length>0&&t.every(e=>n.doc.child(e).type===U.code_block)?t:null};function An(n,t){if(Pn.has(t))return Hn(n,t);if(t==="code"&&zn(n))return!0;let e=Dn[t],{from:o,to:s,empty:r,$from:i}=n.selection;return r?!!e.isInSet(n.storedMarks||i.marks()):n.doc.rangeHasMark(o,s,e)}function us(n,t){let e=n.state,o=Hn(e,t),s=q.find(l=>l.key===(o?"text":t)),r=Rn(e).filter(l=>o||!Nn(e.doc.child(l),t));if(r.some(l=>!Q(e.doc.child(l),s))){P(n,he);return}let i=e.tr;for(let l of r)G(i,l,s);i.docChanged&&n.dispatch(w(i))}var ue=(n,t,e)=>import("./c-7PYNAULW.js").then(o=>o.nativeMenu(n,e,t.pickedFrom??t.more));function On(n,t){if(t==="link")return _e(n);let e=n.state,o=t==="code"?zn(e):null,s=t==="code"&&!o?ls(e):null;Pn.has(t)?us(n,t):o?n.dispatch(w(as(e,o)).scrollIntoView()):s&&s.some(r=>!Q(e.doc.child(r),q.find(i=>i.key==="code")))?P(n,he):s?n.dispatch(w(cs(e,s)).scrollIntoView()):ge.toggleMark(Dn[t])(e,n.dispatch),n.focus()}var y=(n,t,e={})=>{let o=document.createElement(n);t&&(o.className=t);for(let[s,r]of Object.entries(e))o.setAttribute(s,r);return o};function vn(n,t){let e=y("button",`page-tool${Bn.has(n)?" page-tool-primary":" page-tool-desk"}`,{type:"button","data-cmd":n,"aria-label":t,title:t});return e.innerHTML=K[n],e}var ds=1600,hs=0,ps=new Ln("page-chrome"),pe=new WeakMap,_t=new Ln("page-slash-range"),fs={init:()=>null,apply(n,t){let e=t;if(e&&n.docChanged){let s=n.mapping.map(e.from,1),r=n.mapping.map(e.to,-1);e=s<=r&&n.doc.textBetween(s,r)===e.text?{...e,from:s,to:r}:null}let o=n.getMeta(_t);return o!==void 0&&(e=o),e}},Yi=()=>new In({key:_t,state:fs}),Fn=(n,t)=>{let e=t?n.state.doc.textBetween(t.from,t.to):null;n.dispatch(n.state.tr.setMeta(_t,t?{...t,text:e}:null))},Kn=n=>{let t=_t.getState(n);return t?{from:t.from,to:t.to}:null};function Ji(n,t,e,{persist:o=!1}={}){let s=pe.get(n);return s?(s.openMenu("external",t),s.menu.externalItems=e,s.menu.persist=o,s.renderMenu(),!0):!1}function Xi(n,t,e){let o=pe.get(n),s=o?.menu;return!s||s.anchor!==t||!e||e===t?!1:(s.anchor=e,e.setAttribute("aria-expanded","true"),n.dom.setAttribute("aria-controls",o.menuId),!0)}var de=class{constructor(t,e){this.view=t,this.onAiTool=e,this.shell=t.dom.parentElement,this.menu=null,this.priorAria=null,this.movedTimer=0,this.hover=null,this.pendingHover=null,this.win=t.dom.ownerDocument.defaultView??globalThis,this.frame=null,this.destroyed=!1,this.probe=null,this.roving=null,this.remote=!1,this.dock=y("div","page-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=y("button","page-tool page-tool-turn page-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=K.more,this.settingsBtn=y("button","page-tool page-tool-desk page-tool-settings",{type:"button","aria-label":"Document settings",title:"Document settings","aria-haspopup":"dialog","aria-expanded":"false"}),this.settingsBtn.innerHTML=K.gear,this.settingsEl=null,this.settingsOpen=!1,this.settingsAnchor=null,this.settingSwitches={},this.dock.append(this.turn,y("span","page-tool-sep page-tool-desk"),...ae.map(([r,i])=>vn(r,i)),this.more),this.dock.insertBefore(this.settingsBtn,this.more),this.settingsBtn.hidden=!this.settingsAPI,this.plus=y("button","page-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=K.plus,this.grip=y("button","page-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=K.grip,this.bubble=y("div","page-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubbleTurn=y("button","page-tool page-tool-turn",{type:"button","aria-haspopup":"menu"}),this.bubbleMore=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.bubbleMore.innerHTML=K.more,this.bubble.append(this.bubbleTurn,y("span","page-tool-sep"),...ae.map(([r,i])=>vn(r,i)),this.bubbleMore),this.menuId=`page-menu-${++hs}`,this.menuEl=y("div","page-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=y("div","page-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let o=r=>r.preventDefault();for(let r of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])r.addEventListener("mousedown",o);for(let r of[this.dock,this.bubble])r.addEventListener("click",i=>{let l=i.target.closest("[data-cmd]");l&&On(this.view,l.dataset.cmd)});this.turn.addEventListener("click",()=>this.toggleMenu("turn",this.turn)),this.more.addEventListener("click",()=>this.toggleMenu("more",this.more)),this.settingsBtn.addEventListener("click",()=>this.toggleSettings()),this.bubbleTurn.addEventListener("click",()=>this.toggleMenu("turn",this.bubbleTurn)),this.bubbleMore.addEventListener("click",()=>this.toggleMenu("more",this.bubbleMore)),this.dock.addEventListener("keydown",r=>this.dockKey(r)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",r=>{r.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Be(t,this.grip,{index:()=>this.gutterIndex(),onClick:r=>this.gripAction(r)});let s=!1;this.scrim.addEventListener("pointerdown",()=>{s=!0}),this.scrim.addEventListener("click",()=>{s&&this.closeMenu(),s=!1}),this.menuEl.addEventListener("click",r=>{let i=r.target.closest(".page-menu-item");i&&this.pick(Number(i.dataset.index))}),this.menuEl.addEventListener("keydown",r=>{this.key(r)&&r.preventDefault()}),this.onMove=r=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),ds),this.trackHover(r)},this.onKey=()=>{clearTimeout(this.movedTimer),this.shell.classList.remove("is-moved"),this.pendingHover=null,this.setHover(null)},this.onLeave=()=>{this.pendingHover=null,this.setHover(null)},this.onResize=()=>{this.scheduleLayout(),this.placeSettings()},this.onDocDown=r=>{this.settingsOpen&&![this.settingsEl,this.settingsAnchor].some(i=>i?.contains(r.target))&&this.closeSettings(),this.menu&&([this.menuEl,this.plus,this.grip,this.turn,this.bubbleTurn,this.bubbleMore].some(i=>i.contains(r.target))||this.closeMenu())},this.onSettingsKey=r=>{r.key!=="Escape"||!this.settingsOpen||(r.preventDefault(),r.stopPropagation(),this.closeSettings(!0))},document.addEventListener("mousedown",this.onDocDown,!0),document.addEventListener("keydown",this.onSettingsKey,!0),this.shell.addEventListener("mousemove",this.onMove),this.shell.addEventListener("mouseleave",this.onLeave),this.shell.addEventListener("keydown",this.onKey),this.win.addEventListener("resize",this.onResize),this.win.addEventListener("scroll",this.onResize,!0),this.win.visualViewport?.addEventListener("resize",this.onResize),this.win.visualViewport?.addEventListener("scroll",this.onResize),this.update(t,null)}blockIndex(){let t=this.view.state,e=t.selection,o=e instanceof z||e instanceof Go?e.from:e.head;return Math.min(t.doc.resolve(o).index(0),t.doc.childCount-1)}isPhone(){return!!this.win?.matchMedia?.("(max-width: 560px)").matches}gutterIndex(){return this.isPhone()?this.blockIndex():(this.settleHover(),Math.min(this.hover??this.blockIndex(),this.view.state.doc.childCount-1))}dockControls(){let t=[...this.dock.querySelectorAll("button")].filter(e=>this.rendered(e));return this.isPhone()?t.filter(e=>e.classList.contains("page-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("page-tool-primary")?!1:this.rendered(t)}rendered(t){if(t.hidden)return!1;let e=this.win?.getComputedStyle?.(t);return!e||e.display!=="none"}setRoving(t){this.roving=t;let e=new Set(this.dockControls());for(let o of this.dock.querySelectorAll("button"))o.tabIndex=o===t&&e.has(o)?0:-1}leaveToToolbar(){queueMicrotask(()=>{this.view.isDestroyed||this.focusToolbar()})}focusToolbar(){let[t]=this.dockControls();return t?(this.setRoving(t),t.focus(),!0):!1}dockKey(t){if(t.key==="Escape"){t.preventDefault(),this.view.focus();return}if(t.key!=="ArrowRight"&&t.key!=="ArrowLeft")return;let e=this.dockControls(),o=e.indexOf(t.target);if(o<0)return;t.preventDefault();let s=e[(o+(t.key==="ArrowRight"?1:-1)+e.length)%e.length];this.setRoving(s),s.focus()}selectionIds(){let t=this.view.state;return lt(t).map(e=>t.doc.child(e).attrs.id)}idIndex(t){let e=-1;return this.view.state.doc.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e}invoker(){let t=this.menu;if(!t||t.slashAt!==null)return this.view.dom;let e=t.anchor;return e&&e!==this.view.dom&&e.isConnected&&(e.tagName==="BUTTON"||e.hasAttribute("tabindex"))?e:this.view.dom}selectCaretBlock(t=null){let e=this.view.state;if(e.selection instanceof z)return;let o=(t??[]).map(r=>this.idIndex(r)).filter(r=>r>=0),s=o.length?o[0]:this.blockIndex();this.view.dispatch(e.tr.setSelection(zt(e.doc,s,o.length?o[o.length-1]:s)))}gripAction(t){this.menu?this.closeMenu():this.openActions(this.grip,t)}trackHover(t){this.menu||this.drag.state||[this.plus,this.grip,this.dock,this.bubble].some(e=>e.contains(t.target))||(this.pendingHover={clientY:t.clientY},this.scheduleLayout())}hoverAt(t){let e=this.view,o=e.posAtCoords({left:e.dom.getBoundingClientRect().left+2,top:t});if(!o)return;let s=e.state.doc,r=gt(s),i=Math.min(s.resolve(o.inside>=0?o.inside:o.pos).index(0),r.length-1);for(;i>0&&r[i].hidden;)i--;this.hover=i}setHover(t){t!==this.hover&&(this.hover=t,this.scheduleLayout())}settleHover(){if(!this.pendingHover)return;let{clientY:t}=this.pendingHover;this.pendingHover=null,this.hoverAt(t)}fromPlus(){this.view.focus();let t=this.gutterIndex();this.openMenu("insert",this.plus,null,null,this.view.state.doc.child(t).attrs.id)}buildSettings(){if(this.settingsEl)return this.settingsEl;let t=y("div","page-settings",{role:"dialog","aria-label":"Document settings",hidden:""}),e=y("div","page-settings-head"),o=y("span","page-settings-title");o.textContent="Document settings";let s=y("button","page-settings-close",{type:"button","aria-label":"Close settings"});s.innerHTML=K.close,s.addEventListener("click",()=>this.closeSettings(!0)),e.append(o,s);let r=ss.map(([l,c])=>{let d=y("div","page-settings-row"),u=y("span","page-settings-name",{id:`${this.menuId}-set-${l}`});u.textContent=c;let a=y("button","page-settings-switch",{type:"button",role:"switch","aria-checked":"true","aria-labelledby":u.id,"data-setting":l});return a.append(y("span","page-settings-knob")),a.addEventListener("click",()=>this.flipSetting(l)),this.settingSwitches[l]=a,d.append(u,a),d}),i=y("div","page-settings-note");return i.textContent="Hidden values stay saved and come back when turned on.",t.append(e,...r,i),this.settingsEl=t,this.shell.append(t),t}flipSetting(t){let e=this.settingSwitches[t],o=e.getAttribute("aria-checked")!=="true";e.setAttribute("aria-checked",String(o)),Promise.resolve().then(()=>this.settingsAPI.set(t,o)).catch(()=>{e.setAttribute("aria-checked",String(!o)),H("That setting could not be saved.","error")})}openSettings(t=this.settingsBtn){if(!this.settingsAPI)return;this.menu&&this.closeMenu();let e=this.buildSettings(),o=this.settingsAPI.read();for(let[s,r]of Object.entries(this.settingSwitches))r.setAttribute("aria-checked",String(o[s]!==!1));this.settingsOpen=!0,this.settingsAnchor=t,t.setAttribute("aria-expanded","true"),e.hidden=!1,this.placeSettings(),e.querySelector(".page-settings-close")?.focus({preventScroll:!0})}closeSettings(t=!1){if(!this.settingsOpen)return;let e=this.settingsAnchor;this.settingsOpen=!1,this.settingsAnchor=null,this.settingsEl&&(this.settingsEl.hidden=!0),e?.setAttribute("aria-expanded","false"),t&&e?.isConnected&&e.focus({preventScroll:!0})}toggleSettings(){this.settingsOpen?this.closeSettings(!0):this.openSettings(this.settingsBtn)}placeSettings(){let t=this.settingsEl;if(!t||t.hidden||!this.settingsAnchor)return;let e=this.settingsAnchor.getBoundingClientRect(),o=t.offsetWidth||264,s=t.offsetHeight||0;if(this.isPhone()){let c=ce(this.win),d=Math.max(c.left+$,Math.min(e.right-o,c.left+c.width-$-o)),u=e.top-6-s;u<c.top+$&&(u=Math.min(e.bottom+6,c.top+c.height-$-s)),t.style.setProperty("--page-pop-x",`${d}px`),t.style.setProperty("--page-pop-y",`${Math.max(c.top+$,u)}px`);return}let r=this.shell.getBoundingClientRect(),i=Math.max(8,Math.min(e.right-r.left-o,Math.max(8,r.width-o-8))),l=e.bottom-r.top+6;l+s>this.win.innerHeight-8&&e.top-r.top-6-s>=8&&(l=e.top-r.top-6-s),t.style.setProperty("--page-pop-x",`${i}px`),t.style.setProperty("--page-pop-y",`${l}px`)}toggleMenu(t,e){this.menu?this.closeMenu():this.openMenu(t,e)}slashKey(t){let e=this.view.state.doc.resolve(t);return`${e.parent.attrs.id}\0${this.view.state.doc.textBetween(e.start(),t-1)}`}openMenu(t,e,o=null,s=null,r=null){this.closeSettings(),this.menu={mode:t,anchor:e,slashAt:o,anchorId:r,ids:s??(t==="insert"?[]:this.selectionIds()),query:"",active:0,items:[],persist:!1},e.setAttribute("aria-expanded","true"),o!==null?(this.priorAria||(this.priorAria=Cn.map(i=>[i,this.view.dom.getAttribute(i)])),this.view.dom.setAttribute("aria-haspopup","listbox")):this.view.dom.setAttribute("aria-haspopup","menu"),this.view.dom.setAttribute("aria-controls",this.menuId),this.renderMenu()}closeMenu(){if(this.menu?.anchor.setAttribute("aria-expanded","false"),this.menu=null,this.menuEl.hidden=!0,this.scrim.hidden=!0,this.priorAria){for(let[t,e]of this.priorAria)e===null?this.view.dom.removeAttribute(t):this.view.dom.setAttribute(t,e);this.priorAria=null}else for(let t of Cn)this.view.dom.removeAttribute(t)}moreItems(){let t=this.isPhone(),e=t?ae.filter(([s])=>!Bn.has(s)).map(([s,r])=>({key:s,label:r,icon:s,run:i=>On(i,s)})):[],o=_n.filter(s=>es.has(s.key)).map(s=>({...s,blocks:!0}));return[...e,{key:"underline",label:"Underline",icon:"U",hint:`${Dt}u`,run:(s,r)=>ue(s,r,"underline")},{key:"text_color",label:"Text color",icon:"A",hint:"\u203A",run:(s,r)=>ue(s,r,"text_color")},{key:"highlight",label:"Highlight",icon:"\u25A0",hint:"\u203A",run:(s,r)=>ue(s,r,"highlight")},...t?[{key:"turn",label:"Turn into",icon:"turn",run:(s,r)=>r.openMenu("turn",r.more)}]:[],{key:"insert",label:"Insert",icon:"+",run:(s,r)=>r.openMenu("insert",r.pickedFrom??r.more,null,null,s.state.doc.child(r.blockIndex()).attrs.id)},...o,...t&&this.settingsAPI?[{key:"settings",label:"Document settings",icon:"gear",focus:!1,run:(s,r)=>r.openSettings(r.more)}]:[],{key:"titleIcon",label:"Page icon",icon:"\u263A",run:s=>Z(s,"titleIcon")},{key:"titleCover",label:"Add cover",icon:"\u25A4",run:s=>Z(s,"titleCover")},{key:"exportHtml",label:"Export reading copy",icon:"\u21E9",run:s=>Z(s,"exportHtml")},{key:"exportMarkdown",label:"Export as Markdown",icon:"M\u21E9",run:s=>Z(s,"exportMarkdown")}]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return ts(this.view.state);if(t.mode==="more")return this.moreItems();let e=t.mode==="turn"?q:gn(this.view.state,this.onAiTool?[...At,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:At);return Mn(e,t.query)}currentTypes(){let t=this.view.state;return new Set(lt(t).map(e=>Ot(t.doc.child(e)).key))}openActions(t=this.plus,e=null){let o=this.view.state,s=gt(o.doc),r=o.selection,i=e!==null&&r instanceof z&&r.span(o.doc).lo<=e&&e<=r.span(o.doc).hi,{lo:l,hi:c}=e===null||i?We(o,s):Fe(s,e,e);this.view.dispatch(o.tr.setSelection(zt(o.doc,l,c,s)));let d=[];for(let u=l;u<=c;u++)d.push(o.doc.child(u).attrs.id);this.openMenu("actions",t,null,d)}renderMenu(){let t=this.menu;t.items=this.menuItems(t),t.active=Math.min(t.active,Math.max(0,t.items.length-1));let e=t.slashAt!==null,o=t.mode==="turn"?this.currentTypes():null;this.menuEl.setAttribute("role",e?"listbox":"menu");let s=[];if(t.mode==="turn"){let r=y("div","page-menu-title");r.textContent=t.query?`Turn into \u201C${t.query}\u201D`:"Turn into",s.push(r)}if(!t.items.length){let r=y("div","page-menu-empty");r.textContent="No matching blocks",s.push(r)}t.items.forEach((r,i)=>{let l=i===t.active,c=o?o.size===1&&r.key===[...o][0]:typeof r.checked=="boolean"?r.checked:null,d=t.mode==="turn"?"menuitemradio":typeof c=="boolean"?"menuitemcheckbox":e?"option":"menuitem",u=y("button",`page-menu-item${l?" is-active":""}`,{type:"button",role:d,tabindex:!e&&l?"0":"-1",id:`${this.menuId}-${i}`,"data-index":String(i),...d==="menuitemradio"?{}:{"aria-selected":l?"true":"false"},...typeof c=="boolean"?{"aria-checked":String(c)}:{}}),a=y("span","page-menu-icon");K[r.icon]?a.innerHTML=K[r.icon]:a.textContent=r.icon||"";let h=y("span","page-menu-label");if(h.textContent=r.label,r.description){let p=y("span","page-menu-text"),f=y("span","page-menu-desc");f.textContent=r.description,p.append(h,f),u.append(a,p)}else u.append(a,h);if(r.hint){let p=y("span","page-menu-hint");p.textContent=r.hint,u.append(p)}s.push(u)}),this.menuEl.replaceChildren(...s),e&&t.items.length?this.view.dom.setAttribute("aria-activedescendant",`${this.menuId}-${t.active}`):this.view.dom.removeAttribute("aria-activedescendant"),this.menuEl.hidden=!1,this.scrim.hidden=!1,this.scheduleLayout(),e||this.menuEl.querySelectorAll("button")[t.active]?.focus({preventScroll:!0})}pick(t){let e=this.menu,o=e?.items[t];if(!o)return;let s=this.view.state,r=e.slashAt!==null&&s.selection.head>=e.slashAt?{from:e.slashAt-1,to:s.selection.head}:null,i=e.mode==="insert"?e.anchorId?[e.anchorId]:[]:e.ids,l=i.some(d=>!d||this.idIndex(d)<0),c=i.length?this.idIndex(i[0]):-1;if(this.pickedFrom=e.anchor,this.closeMenu(),l&&e.mode!=="external"){P(this.view,Jo),this.view.focus();return}if(e.mode==="turn"){if(i.some(d=>!Q(s.doc.child(this.idIndex(d)),o))){P(this.view,he),this.view.focus();return}kn(this.view,o,i)}else e.mode==="actions"||e.mode==="more"||e.mode==="external"?(o.blocks&&this.selectCaretBlock(i),o.run(this.view,this,c>=0?c:this.blockIndex()),!this.menu&&o.focus!==!1&&this.view.focus()):o.insert==="ai"?this.onAiTool(this.view,r):wn(this.view,o,c>=0?c:this.blockIndex(),r)}key(t){if(It(t,this.view))return!1;let e=this.menu;if(!e)return t.key==="Escape"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&this.view.state.selection instanceof z&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&e.mode==="actions"&&this.view.state.selection instanceof z)return this.closeMenu(),this.view.focus(),Ft(this.view.state,this.view.dispatch),!0;if(t.key==="ArrowDown"||t.key==="ArrowUp")return e.items.length&&(e.active=(e.active+(t.key==="ArrowDown"?1:-1)+e.items.length)%e.items.length,this.renderMenu()),!0;if(t.key==="Enter")return e.items.length&&this.pick(e.active),!0;if(t.key==="Tab"&&e.slashAt===null)return this.closeMenu(),!1;if(t.key==="Escape"){let o=this.invoker();return e.slashAt!==null&&(this.dismissedSlash=this.slashKey(e.slashAt)),this.closeMenu(),o===this.view.dom?this.view.focus():o?.focus?.(),!0}return!1}slashQuery(){let t=this.menu;if(!t||t.slashAt===null)return;let{$head:e}=this.view.state.selection,o=e.start();if(e.pos<t.slashAt||t.slashAt<o||this.view.state.doc.textBetween(t.slashAt-1,t.slashAt)!=="/")return this.closeMenu();if(t.query=this.view.state.doc.textBetween(t.slashAt,e.pos),t.active=0,/\s$/.test(t.query)&&!this.menuItems(t).length)return this.closeMenu();this.renderMenu()}scheduleLayout(){this.frame!==null||this.destroyed||(this.frame=this.win.requestAnimationFrame(()=>{if(this.frame=null,this.destroyed)return;let t=this.measureLayout();this.paintLayout(t)}))}safeBottom(){return this.probe||(this.probe=y("div","page-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let e=ce(this.win),o=Math.max(0,e.height-$*2),s=Math.min(280,Math.max(0,e.width-$*2)),r=this.menuEl.style.getPropertyValue("--page-pop-max");this.menuEl.style.removeProperty("--page-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--page-pop-max",r);let l=Math.min(i,o),c=Math.max(e.left+$,Math.min(t.left,e.left+e.width-$-s)),d=t.top-6-l;return d<e.top+$&&(d=Math.min(t.top+t.height+6,e.top+e.height-$-l)),{left:c,top:d,width:s,maxHeight:o}}measureLayout(){let t=this.view,e=t.state;this.settleHover();let o=this.shell.getBoundingClientRect(),s=t.dom.getBoundingClientRect(),r=this.gutterIndex(),i=0;for(let a=0;a<r;a++)i+=e.doc.child(a).nodeSize;let l=t.nodeDOM(i),c={textLeft:s.left-o.left,gutter:null,bubble:null,menu:null,bar:null,desk:!1};if(l&&l.getBoundingClientRect){let a=l.getBoundingClientRect(),h=parseFloat(getComputedStyle(l).lineHeight)||a.height;c.gutter={top:a.top-o.top+Math.min(a.height,h)/2,left:a.left-o.left}}let d=this.isPhone();if(d){let a=ce(this.win),h=this.dock.offsetHeight||os;c.bar={...Xo(a,this.dock.offsetWidth||ns,h,this.safeBottom()),height:h}}else c.desk=!!this.dock.style.left;let u=e.selection;if(!this.bubble.hidden&&!d){let a=t.coordsAtPos(u.from),h=t.coordsAtPos(u.to,-1),p=(Math.min(a.left,h.left)+Math.max(a.right,h.right))/2;c.bubble={x:p-o.left,y:Math.min(a.top,h.top)-o.top}}if(this.menu&&d){let a=this.menuBox(c.bar);c.menu={x:a.left,y:a.top,width:a.width,maxHeight:a.maxHeight}}else if(this.menu){let a=this.menu,h,p;if(a.slashAt!==null){let f=t.coordsAtPos(a.slashAt-1);h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}else{let f=a.anchor===this.plus?l?.getBoundingClientRect?.()??s:a.anchor.getBoundingClientRect();h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}c.menu={x:Math.max(8,Math.min(h-o.left,o.width-280)),y:p-o.top}}return c}paintLayout(t){if(t.bar)this.dock.style.left=`${t.bar.left}px`,this.dock.style.top=`${t.bar.top}px`,this.dock.style.width=`${t.bar.width}px`,this.grip.style.setProperty("--page-grip-lift",`${t.bar.height}px`);else{if(t.desk)for(let e of["left","top","width"])this.dock.style.removeProperty(e);this.grip.style.removeProperty("--page-grip-lift")}if(t.gutter)for(let e of[this.plus,this.grip])e.style.setProperty("--page-plus-top",`${t.gutter.top}px`),e.style.setProperty("--page-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--page-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--page-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--page-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--page-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--page-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--page-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--page-pop-max",`${t.menu.maxHeight}px`)))}get settingsAPI(){return globalThis.clay?.page?.settings??null}update(t,e){let o=!this.settingsAPI;if(this.settingsBtn.hidden!==o&&(this.settingsBtn.hidden=o),this.view=t,this.menu&&this.menu.slashAt===null&&e&&e.doc!==t.state.doc)if(this.menu.persist&&this.menu.anchor?.isConnected)this.scheduleLayout();else{let c=this.menuEl.contains(document.activeElement);this.closeMenu(),c&&t.focus()}let s=t.state,r=s.doc.child(this.blockIndex());this.turn.textContent=`${Ot(r).label} \u25BE`,this.bubbleTurn.textContent=this.turn.textContent;for(let c of this.dock.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));let l=!!this.menu&&[this.bubbleTurn,this.bubbleMore].includes(this.menu.anchor)||!s.selection.empty&&s.selection instanceof $t&&t.hasFocus();if(this.bubble.hidden=!l,l)for(let c of this.bubble.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));if(this.grip.classList.toggle("is-on",s.selection instanceof z),this.inRoving(this.roving)||this.setRoving(this.dockControls()[0]),!this.menu&&e&&e.doc!==s.doc&&!this.remote&&t.hasFocus()&&s.selection.empty){let c=s.selection.$head;if(c.depth===1&&c.parent.isTextblock&&!c.parent.type.spec.code){let d=s.doc.textBetween(c.start(),c.pos),u=/(?:^|\s)\/([a-z]*)$/i.exec(d),a=u?c.start()+u.index+u[0].indexOf("/")+1:null;u&&this.slashKey(a)!==this.dismissedSlash&&this.openMenu("insert",this.plus,a,null,c.parent.attrs.id)}}this.slashQuery(),this.scheduleLayout()}destroy(){this.destroyed=!0,this.frame!==null&&this.win.cancelAnimationFrame(this.frame),this.frame=null,clearTimeout(this.movedTimer),this.drag.destroy(),this.shell.removeEventListener("mousemove",this.onMove),this.shell.removeEventListener("mouseleave",this.onLeave),this.shell.removeEventListener("keydown",this.onKey),this.win.removeEventListener("resize",this.onResize),this.win.removeEventListener("scroll",this.onResize,!0),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onResize),document.removeEventListener("mousedown",this.onDocDown,!0),document.removeEventListener("keydown",this.onSettingsKey,!0);for(let t of[this.dock,this.plus,this.grip,this.bubble,this.scrim,this.menuEl,this.settingsEl,this.probe])t?.remove()}};function Qi({onAiTool:n=null}={}){let t=null;return new In({key:ps,view(e){return t=new de(e,n),pe.set(e,t),t},filterTransaction(e){return t&&e.docChanged&&(t.remote=!!e.getMeta(Me)),!0},props:{handleKeyDown(e,o){return t?o.key==="/"&&(o.metaKey||o.ctrlKey)&&!o.altKey&&!t.menu?(o.preventDefault(),t.openActions(),!0):t.key(o):!1},handleTextInput(e,o,s,r){if(r!=="/"||!t)return!1;let i=Ge(e,r);i&&(o=e.state.selection.from-1);let l=e.state.doc.resolve(o);if(l.depth!==1||!l.parent.isTextblock||l.parent.type.spec.code||l.parentOffset>0&&!/\s/.test(e.state.doc.textBetween(o-1,o,"",`
|
|
6
|
-
`)))return i;i||e.dispatch(e.state.tr.insertText("/",o,s).setMeta(xt,qt(e.state,o,s,"/")));let c=Math.min(e.state.doc.resolve(o).index(0),e.state.doc.childCount-1);return t.openMenu("insert",t.plus,o+1,null,e.state.doc.child(c).attrs.id),!0},handleDOMEvents:{keydown(e,o){return It(o,e)},blur(e){return t&&!(t.menu&&[t.bubbleTurn,t.bubbleMore].includes(t.menu.anchor))&&(t.bubble.hidden=!0),!1}}}})}var{Plugin:ms}=C,me=new WeakMap,gs=n=>typeof n.text=="function"?n.text():new Promise((t,e)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>e(o.error),o.readAsText(n)});function Bt(n,t){let e=n.dom.ownerDocument,o=n.dom.parentElement.querySelector(".page-csv-error");o||(o=e.createElement("div"),o.className="page-csv-error",o.setAttribute("role","alert"),n.dom.parentElement.append(o)),o.textContent=t}function bs(n){let t=0,e=Ce(n,{maxBytes:Jt,newId:()=>k(t++<n.header.length?"c":"r")});if(!Object.keys(e.cols).length)return null;if(!Object.keys(e.rows).length){let o=Object.fromEntries(Object.keys(e.cols).map(s=>[s,""]));e.rows[k("r")]={pos:A(),cells:o}}return{node:Y(g,k(),{t:"table",pos:null,cols:e.cols,rows:e.rows}),truncated:e.truncated}}async function ys({kept:n,total:t}){let e=`This file has ${t} rows. The first ${n} fit in a table.`,o=globalThis.clay?.confirm,s=globalThis.clay?.modal;o||(o=(await import("./c-
|
|
5
|
+
`).map((h,p)=>U.paragraph.create(p===0?{id:c,pos:d,parent:u}:{parent:u},h?g.text(h):null));e.replaceWith(i,i+l.nodeSize,a),s||(s=i+a.reduce((h,p)=>h+p.nodeSize,0))}return s=e.mapping.slice(1).map(s),e.setSelection($t.create(e.doc,o+1,s-1))}var zn=n=>{let t=lt(n);return t.length>0&&t.every(e=>n.doc.child(e).type===U.code_block)?t:null};function An(n,t){if(Pn.has(t))return Hn(n,t);if(t==="code"&&zn(n))return!0;let e=Dn[t],{from:o,to:s,empty:r,$from:i}=n.selection;return r?!!e.isInSet(n.storedMarks||i.marks()):n.doc.rangeHasMark(o,s,e)}function us(n,t){let e=n.state,o=Hn(e,t),s=q.find(l=>l.key===(o?"text":t)),r=Rn(e).filter(l=>o||!Nn(e.doc.child(l),t));if(r.some(l=>!Q(e.doc.child(l),s))){P(n,he);return}let i=e.tr;for(let l of r)G(i,l,s);i.docChanged&&n.dispatch(w(i))}var ue=(n,t,e)=>import("./c-VBLFAQD2.js").then(o=>o.nativeMenu(n,e,t.pickedFrom??t.more));function On(n,t){if(t==="link")return _e(n);let e=n.state,o=t==="code"?zn(e):null,s=t==="code"&&!o?ls(e):null;Pn.has(t)?us(n,t):o?n.dispatch(w(as(e,o)).scrollIntoView()):s&&s.some(r=>!Q(e.doc.child(r),q.find(i=>i.key==="code")))?P(n,he):s?n.dispatch(w(cs(e,s)).scrollIntoView()):ge.toggleMark(Dn[t])(e,n.dispatch),n.focus()}var y=(n,t,e={})=>{let o=document.createElement(n);t&&(o.className=t);for(let[s,r]of Object.entries(e))o.setAttribute(s,r);return o};function vn(n,t){let e=y("button",`page-tool${Bn.has(n)?" page-tool-primary":" page-tool-desk"}`,{type:"button","data-cmd":n,"aria-label":t,title:t});return e.innerHTML=K[n],e}var ds=1600,hs=0,ps=new Ln("page-chrome"),pe=new WeakMap,_t=new Ln("page-slash-range"),fs={init:()=>null,apply(n,t){let e=t;if(e&&n.docChanged){let s=n.mapping.map(e.from,1),r=n.mapping.map(e.to,-1);e=s<=r&&n.doc.textBetween(s,r)===e.text?{...e,from:s,to:r}:null}let o=n.getMeta(_t);return o!==void 0&&(e=o),e}},Yi=()=>new In({key:_t,state:fs}),Fn=(n,t)=>{let e=t?n.state.doc.textBetween(t.from,t.to):null;n.dispatch(n.state.tr.setMeta(_t,t?{...t,text:e}:null))},Kn=n=>{let t=_t.getState(n);return t?{from:t.from,to:t.to}:null};function Ji(n,t,e,{persist:o=!1}={}){let s=pe.get(n);return s?(s.openMenu("external",t),s.menu.externalItems=e,s.menu.persist=o,s.renderMenu(),!0):!1}function Xi(n,t,e){let o=pe.get(n),s=o?.menu;return!s||s.anchor!==t||!e||e===t?!1:(s.anchor=e,e.setAttribute("aria-expanded","true"),n.dom.setAttribute("aria-controls",o.menuId),!0)}var de=class{constructor(t,e){this.view=t,this.onAiTool=e,this.shell=t.dom.parentElement,this.menu=null,this.priorAria=null,this.movedTimer=0,this.hover=null,this.pendingHover=null,this.win=t.dom.ownerDocument.defaultView??globalThis,this.frame=null,this.destroyed=!1,this.probe=null,this.roving=null,this.remote=!1,this.dock=y("div","page-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=y("button","page-tool page-tool-turn page-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=K.more,this.settingsBtn=y("button","page-tool page-tool-desk page-tool-settings",{type:"button","aria-label":"Document settings",title:"Document settings","aria-haspopup":"dialog","aria-expanded":"false"}),this.settingsBtn.innerHTML=K.gear,this.settingsEl=null,this.settingsOpen=!1,this.settingsAnchor=null,this.settingSwitches={},this.dock.append(this.turn,y("span","page-tool-sep page-tool-desk"),...ae.map(([r,i])=>vn(r,i)),this.more),this.dock.insertBefore(this.settingsBtn,this.more),this.settingsBtn.hidden=!this.settingsAPI,this.plus=y("button","page-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=K.plus,this.grip=y("button","page-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=K.grip,this.bubble=y("div","page-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubbleTurn=y("button","page-tool page-tool-turn",{type:"button","aria-haspopup":"menu"}),this.bubbleMore=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.bubbleMore.innerHTML=K.more,this.bubble.append(this.bubbleTurn,y("span","page-tool-sep"),...ae.map(([r,i])=>vn(r,i)),this.bubbleMore),this.menuId=`page-menu-${++hs}`,this.menuEl=y("div","page-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=y("div","page-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let o=r=>r.preventDefault();for(let r of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])r.addEventListener("mousedown",o);for(let r of[this.dock,this.bubble])r.addEventListener("click",i=>{let l=i.target.closest("[data-cmd]");l&&On(this.view,l.dataset.cmd)});this.turn.addEventListener("click",()=>this.toggleMenu("turn",this.turn)),this.more.addEventListener("click",()=>this.toggleMenu("more",this.more)),this.settingsBtn.addEventListener("click",()=>this.toggleSettings()),this.bubbleTurn.addEventListener("click",()=>this.toggleMenu("turn",this.bubbleTurn)),this.bubbleMore.addEventListener("click",()=>this.toggleMenu("more",this.bubbleMore)),this.dock.addEventListener("keydown",r=>this.dockKey(r)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",r=>{r.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Be(t,this.grip,{index:()=>this.gutterIndex(),onClick:r=>this.gripAction(r)});let s=!1;this.scrim.addEventListener("pointerdown",()=>{s=!0}),this.scrim.addEventListener("click",()=>{s&&this.closeMenu(),s=!1}),this.menuEl.addEventListener("click",r=>{let i=r.target.closest(".page-menu-item");i&&this.pick(Number(i.dataset.index))}),this.menuEl.addEventListener("keydown",r=>{this.key(r)&&r.preventDefault()}),this.onMove=r=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),ds),this.trackHover(r)},this.onKey=()=>{clearTimeout(this.movedTimer),this.shell.classList.remove("is-moved"),this.pendingHover=null,this.setHover(null)},this.onLeave=()=>{this.pendingHover=null,this.setHover(null)},this.onResize=()=>{this.scheduleLayout(),this.placeSettings()},this.onDocDown=r=>{this.settingsOpen&&![this.settingsEl,this.settingsAnchor].some(i=>i?.contains(r.target))&&this.closeSettings(),this.menu&&([this.menuEl,this.plus,this.grip,this.turn,this.bubbleTurn,this.bubbleMore].some(i=>i.contains(r.target))||this.closeMenu())},this.onSettingsKey=r=>{r.key!=="Escape"||!this.settingsOpen||(r.preventDefault(),r.stopPropagation(),this.closeSettings(!0))},document.addEventListener("mousedown",this.onDocDown,!0),document.addEventListener("keydown",this.onSettingsKey,!0),this.shell.addEventListener("mousemove",this.onMove),this.shell.addEventListener("mouseleave",this.onLeave),this.shell.addEventListener("keydown",this.onKey),this.win.addEventListener("resize",this.onResize),this.win.addEventListener("scroll",this.onResize,!0),this.win.visualViewport?.addEventListener("resize",this.onResize),this.win.visualViewport?.addEventListener("scroll",this.onResize),this.update(t,null)}blockIndex(){let t=this.view.state,e=t.selection,o=e instanceof z||e instanceof Go?e.from:e.head;return Math.min(t.doc.resolve(o).index(0),t.doc.childCount-1)}isPhone(){return!!this.win?.matchMedia?.("(max-width: 560px)").matches}gutterIndex(){return this.isPhone()?this.blockIndex():(this.settleHover(),Math.min(this.hover??this.blockIndex(),this.view.state.doc.childCount-1))}dockControls(){let t=[...this.dock.querySelectorAll("button")].filter(e=>this.rendered(e));return this.isPhone()?t.filter(e=>e.classList.contains("page-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("page-tool-primary")?!1:this.rendered(t)}rendered(t){if(t.hidden)return!1;let e=this.win?.getComputedStyle?.(t);return!e||e.display!=="none"}setRoving(t){this.roving=t;let e=new Set(this.dockControls());for(let o of this.dock.querySelectorAll("button"))o.tabIndex=o===t&&e.has(o)?0:-1}leaveToToolbar(){queueMicrotask(()=>{this.view.isDestroyed||this.focusToolbar()})}focusToolbar(){let[t]=this.dockControls();return t?(this.setRoving(t),t.focus(),!0):!1}dockKey(t){if(t.key==="Escape"){t.preventDefault(),this.view.focus();return}if(t.key!=="ArrowRight"&&t.key!=="ArrowLeft")return;let e=this.dockControls(),o=e.indexOf(t.target);if(o<0)return;t.preventDefault();let s=e[(o+(t.key==="ArrowRight"?1:-1)+e.length)%e.length];this.setRoving(s),s.focus()}selectionIds(){let t=this.view.state;return lt(t).map(e=>t.doc.child(e).attrs.id)}idIndex(t){let e=-1;return this.view.state.doc.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e}invoker(){let t=this.menu;if(!t||t.slashAt!==null)return this.view.dom;let e=t.anchor;return e&&e!==this.view.dom&&e.isConnected&&(e.tagName==="BUTTON"||e.hasAttribute("tabindex"))?e:this.view.dom}selectCaretBlock(t=null){let e=this.view.state;if(e.selection instanceof z)return;let o=(t??[]).map(r=>this.idIndex(r)).filter(r=>r>=0),s=o.length?o[0]:this.blockIndex();this.view.dispatch(e.tr.setSelection(zt(e.doc,s,o.length?o[o.length-1]:s)))}gripAction(t){this.menu?this.closeMenu():this.openActions(this.grip,t)}trackHover(t){this.menu||this.drag.state||[this.plus,this.grip,this.dock,this.bubble].some(e=>e.contains(t.target))||(this.pendingHover={clientY:t.clientY},this.scheduleLayout())}hoverAt(t){let e=this.view,o=e.posAtCoords({left:e.dom.getBoundingClientRect().left+2,top:t});if(!o)return;let s=e.state.doc,r=gt(s),i=Math.min(s.resolve(o.inside>=0?o.inside:o.pos).index(0),r.length-1);for(;i>0&&r[i].hidden;)i--;this.hover=i}setHover(t){t!==this.hover&&(this.hover=t,this.scheduleLayout())}settleHover(){if(!this.pendingHover)return;let{clientY:t}=this.pendingHover;this.pendingHover=null,this.hoverAt(t)}fromPlus(){this.view.focus();let t=this.gutterIndex();this.openMenu("insert",this.plus,null,null,this.view.state.doc.child(t).attrs.id)}buildSettings(){if(this.settingsEl)return this.settingsEl;let t=y("div","page-settings",{role:"dialog","aria-label":"Document settings",hidden:""}),e=y("div","page-settings-head"),o=y("span","page-settings-title");o.textContent="Document settings";let s=y("button","page-settings-close",{type:"button","aria-label":"Close settings"});s.innerHTML=K.close,s.addEventListener("click",()=>this.closeSettings(!0)),e.append(o,s);let r=ss.map(([l,c])=>{let d=y("div","page-settings-row"),u=y("span","page-settings-name",{id:`${this.menuId}-set-${l}`});u.textContent=c;let a=y("button","page-settings-switch",{type:"button",role:"switch","aria-checked":"true","aria-labelledby":u.id,"data-setting":l});return a.append(y("span","page-settings-knob")),a.addEventListener("click",()=>this.flipSetting(l)),this.settingSwitches[l]=a,d.append(u,a),d}),i=y("div","page-settings-note");return i.textContent="Hidden values stay saved and come back when turned on.",t.append(e,...r,i),this.settingsEl=t,this.shell.append(t),t}flipSetting(t){let e=this.settingSwitches[t],o=e.getAttribute("aria-checked")!=="true";e.setAttribute("aria-checked",String(o)),Promise.resolve().then(()=>this.settingsAPI.set(t,o)).catch(()=>{e.setAttribute("aria-checked",String(!o)),H("That setting could not be saved.","error")})}openSettings(t=this.settingsBtn){if(!this.settingsAPI)return;this.menu&&this.closeMenu();let e=this.buildSettings(),o=this.settingsAPI.read();for(let[s,r]of Object.entries(this.settingSwitches))r.setAttribute("aria-checked",String(o[s]!==!1));this.settingsOpen=!0,this.settingsAnchor=t,t.setAttribute("aria-expanded","true"),e.hidden=!1,this.placeSettings(),e.querySelector(".page-settings-close")?.focus({preventScroll:!0})}closeSettings(t=!1){if(!this.settingsOpen)return;let e=this.settingsAnchor;this.settingsOpen=!1,this.settingsAnchor=null,this.settingsEl&&(this.settingsEl.hidden=!0),e?.setAttribute("aria-expanded","false"),t&&e?.isConnected&&e.focus({preventScroll:!0})}toggleSettings(){this.settingsOpen?this.closeSettings(!0):this.openSettings(this.settingsBtn)}placeSettings(){let t=this.settingsEl;if(!t||t.hidden||!this.settingsAnchor)return;let e=this.settingsAnchor.getBoundingClientRect(),o=t.offsetWidth||264,s=t.offsetHeight||0;if(this.isPhone()){let c=ce(this.win),d=Math.max(c.left+$,Math.min(e.right-o,c.left+c.width-$-o)),u=e.top-6-s;u<c.top+$&&(u=Math.min(e.bottom+6,c.top+c.height-$-s)),t.style.setProperty("--page-pop-x",`${d}px`),t.style.setProperty("--page-pop-y",`${Math.max(c.top+$,u)}px`);return}let r=this.shell.getBoundingClientRect(),i=Math.max(8,Math.min(e.right-r.left-o,Math.max(8,r.width-o-8))),l=e.bottom-r.top+6;l+s>this.win.innerHeight-8&&e.top-r.top-6-s>=8&&(l=e.top-r.top-6-s),t.style.setProperty("--page-pop-x",`${i}px`),t.style.setProperty("--page-pop-y",`${l}px`)}toggleMenu(t,e){this.menu?this.closeMenu():this.openMenu(t,e)}slashKey(t){let e=this.view.state.doc.resolve(t);return`${e.parent.attrs.id}\0${this.view.state.doc.textBetween(e.start(),t-1)}`}openMenu(t,e,o=null,s=null,r=null){this.closeSettings(),this.menu={mode:t,anchor:e,slashAt:o,anchorId:r,ids:s??(t==="insert"?[]:this.selectionIds()),query:"",active:0,items:[],persist:!1},e.setAttribute("aria-expanded","true"),o!==null?(this.priorAria||(this.priorAria=Cn.map(i=>[i,this.view.dom.getAttribute(i)])),this.view.dom.setAttribute("aria-haspopup","listbox")):this.view.dom.setAttribute("aria-haspopup","menu"),this.view.dom.setAttribute("aria-controls",this.menuId),this.renderMenu()}closeMenu(){if(this.menu?.anchor.setAttribute("aria-expanded","false"),this.menu=null,this.menuEl.hidden=!0,this.scrim.hidden=!0,this.priorAria){for(let[t,e]of this.priorAria)e===null?this.view.dom.removeAttribute(t):this.view.dom.setAttribute(t,e);this.priorAria=null}else for(let t of Cn)this.view.dom.removeAttribute(t)}moreItems(){let t=this.isPhone(),e=t?ae.filter(([s])=>!Bn.has(s)).map(([s,r])=>({key:s,label:r,icon:s,run:i=>On(i,s)})):[],o=_n.filter(s=>es.has(s.key)).map(s=>({...s,blocks:!0}));return[...e,{key:"underline",label:"Underline",icon:"U",hint:`${Dt}u`,run:(s,r)=>ue(s,r,"underline")},{key:"text_color",label:"Text color",icon:"A",hint:"\u203A",run:(s,r)=>ue(s,r,"text_color")},{key:"highlight",label:"Highlight",icon:"\u25A0",hint:"\u203A",run:(s,r)=>ue(s,r,"highlight")},...t?[{key:"turn",label:"Turn into",icon:"turn",run:(s,r)=>r.openMenu("turn",r.more)}]:[],{key:"insert",label:"Insert",icon:"+",run:(s,r)=>r.openMenu("insert",r.pickedFrom??r.more,null,null,s.state.doc.child(r.blockIndex()).attrs.id)},...o,...t&&this.settingsAPI?[{key:"settings",label:"Document settings",icon:"gear",focus:!1,run:(s,r)=>r.openSettings(r.more)}]:[],{key:"titleIcon",label:"Page icon",icon:"\u263A",run:s=>Z(s,"titleIcon")},{key:"titleCover",label:"Add cover",icon:"\u25A4",run:s=>Z(s,"titleCover")},{key:"exportHtml",label:"Export reading copy",icon:"\u21E9",run:s=>Z(s,"exportHtml")},{key:"exportMarkdown",label:"Export as Markdown",icon:"M\u21E9",run:s=>Z(s,"exportMarkdown")}]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return ts(this.view.state);if(t.mode==="more")return this.moreItems();let e=t.mode==="turn"?q:gn(this.view.state,this.onAiTool?[...At,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:At);return Mn(e,t.query)}currentTypes(){let t=this.view.state;return new Set(lt(t).map(e=>Ot(t.doc.child(e)).key))}openActions(t=this.plus,e=null){let o=this.view.state,s=gt(o.doc),r=o.selection,i=e!==null&&r instanceof z&&r.span(o.doc).lo<=e&&e<=r.span(o.doc).hi,{lo:l,hi:c}=e===null||i?We(o,s):Fe(s,e,e);this.view.dispatch(o.tr.setSelection(zt(o.doc,l,c,s)));let d=[];for(let u=l;u<=c;u++)d.push(o.doc.child(u).attrs.id);this.openMenu("actions",t,null,d)}renderMenu(){let t=this.menu;t.items=this.menuItems(t),t.active=Math.min(t.active,Math.max(0,t.items.length-1));let e=t.slashAt!==null,o=t.mode==="turn"?this.currentTypes():null;this.menuEl.setAttribute("role",e?"listbox":"menu");let s=[];if(t.mode==="turn"){let r=y("div","page-menu-title");r.textContent=t.query?`Turn into \u201C${t.query}\u201D`:"Turn into",s.push(r)}if(!t.items.length){let r=y("div","page-menu-empty");r.textContent="No matching blocks",s.push(r)}t.items.forEach((r,i)=>{let l=i===t.active,c=o?o.size===1&&r.key===[...o][0]:typeof r.checked=="boolean"?r.checked:null,d=t.mode==="turn"?"menuitemradio":typeof c=="boolean"?"menuitemcheckbox":e?"option":"menuitem",u=y("button",`page-menu-item${l?" is-active":""}`,{type:"button",role:d,tabindex:!e&&l?"0":"-1",id:`${this.menuId}-${i}`,"data-index":String(i),...d==="menuitemradio"?{}:{"aria-selected":l?"true":"false"},...typeof c=="boolean"?{"aria-checked":String(c)}:{}}),a=y("span","page-menu-icon");K[r.icon]?a.innerHTML=K[r.icon]:a.textContent=r.icon||"";let h=y("span","page-menu-label");if(h.textContent=r.label,r.description){let p=y("span","page-menu-text"),f=y("span","page-menu-desc");f.textContent=r.description,p.append(h,f),u.append(a,p)}else u.append(a,h);if(r.hint){let p=y("span","page-menu-hint");p.textContent=r.hint,u.append(p)}s.push(u)}),this.menuEl.replaceChildren(...s),e&&t.items.length?this.view.dom.setAttribute("aria-activedescendant",`${this.menuId}-${t.active}`):this.view.dom.removeAttribute("aria-activedescendant"),this.menuEl.hidden=!1,this.scrim.hidden=!1,this.scheduleLayout(),e||this.menuEl.querySelectorAll("button")[t.active]?.focus({preventScroll:!0})}pick(t){let e=this.menu,o=e?.items[t];if(!o)return;let s=this.view.state,r=e.slashAt!==null&&s.selection.head>=e.slashAt?{from:e.slashAt-1,to:s.selection.head}:null,i=e.mode==="insert"?e.anchorId?[e.anchorId]:[]:e.ids,l=i.some(d=>!d||this.idIndex(d)<0),c=i.length?this.idIndex(i[0]):-1;if(this.pickedFrom=e.anchor,this.closeMenu(),l&&e.mode!=="external"){P(this.view,Jo),this.view.focus();return}if(e.mode==="turn"){if(i.some(d=>!Q(s.doc.child(this.idIndex(d)),o))){P(this.view,he),this.view.focus();return}kn(this.view,o,i)}else e.mode==="actions"||e.mode==="more"||e.mode==="external"?(o.blocks&&this.selectCaretBlock(i),o.run(this.view,this,c>=0?c:this.blockIndex()),!this.menu&&o.focus!==!1&&this.view.focus()):o.insert==="ai"?this.onAiTool(this.view,r):wn(this.view,o,c>=0?c:this.blockIndex(),r)}key(t){if(It(t,this.view))return!1;let e=this.menu;if(!e)return t.key==="Escape"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&this.view.state.selection instanceof z&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&e.mode==="actions"&&this.view.state.selection instanceof z)return this.closeMenu(),this.view.focus(),Ft(this.view.state,this.view.dispatch),!0;if(t.key==="ArrowDown"||t.key==="ArrowUp")return e.items.length&&(e.active=(e.active+(t.key==="ArrowDown"?1:-1)+e.items.length)%e.items.length,this.renderMenu()),!0;if(t.key==="Enter")return e.items.length&&this.pick(e.active),!0;if(t.key==="Tab"&&e.slashAt===null)return this.closeMenu(),!1;if(t.key==="Escape"){let o=this.invoker();return e.slashAt!==null&&(this.dismissedSlash=this.slashKey(e.slashAt)),this.closeMenu(),o===this.view.dom?this.view.focus():o?.focus?.(),!0}return!1}slashQuery(){let t=this.menu;if(!t||t.slashAt===null)return;let{$head:e}=this.view.state.selection,o=e.start();if(e.pos<t.slashAt||t.slashAt<o||this.view.state.doc.textBetween(t.slashAt-1,t.slashAt)!=="/")return this.closeMenu();if(t.query=this.view.state.doc.textBetween(t.slashAt,e.pos),t.active=0,/\s$/.test(t.query)&&!this.menuItems(t).length)return this.closeMenu();this.renderMenu()}scheduleLayout(){this.frame!==null||this.destroyed||(this.frame=this.win.requestAnimationFrame(()=>{if(this.frame=null,this.destroyed)return;let t=this.measureLayout();this.paintLayout(t)}))}safeBottom(){return this.probe||(this.probe=y("div","page-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let e=ce(this.win),o=Math.max(0,e.height-$*2),s=Math.min(280,Math.max(0,e.width-$*2)),r=this.menuEl.style.getPropertyValue("--page-pop-max");this.menuEl.style.removeProperty("--page-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--page-pop-max",r);let l=Math.min(i,o),c=Math.max(e.left+$,Math.min(t.left,e.left+e.width-$-s)),d=t.top-6-l;return d<e.top+$&&(d=Math.min(t.top+t.height+6,e.top+e.height-$-l)),{left:c,top:d,width:s,maxHeight:o}}measureLayout(){let t=this.view,e=t.state;this.settleHover();let o=this.shell.getBoundingClientRect(),s=t.dom.getBoundingClientRect(),r=this.gutterIndex(),i=0;for(let a=0;a<r;a++)i+=e.doc.child(a).nodeSize;let l=t.nodeDOM(i),c={textLeft:s.left-o.left,gutter:null,bubble:null,menu:null,bar:null,desk:!1};if(l&&l.getBoundingClientRect){let a=l.getBoundingClientRect(),h=parseFloat(getComputedStyle(l).lineHeight)||a.height;c.gutter={top:a.top-o.top+Math.min(a.height,h)/2,left:a.left-o.left}}let d=this.isPhone();if(d){let a=ce(this.win),h=this.dock.offsetHeight||os;c.bar={...Xo(a,this.dock.offsetWidth||ns,h,this.safeBottom()),height:h}}else c.desk=!!this.dock.style.left;let u=e.selection;if(!this.bubble.hidden&&!d){let a=t.coordsAtPos(u.from),h=t.coordsAtPos(u.to,-1),p=(Math.min(a.left,h.left)+Math.max(a.right,h.right))/2;c.bubble={x:p-o.left,y:Math.min(a.top,h.top)-o.top}}if(this.menu&&d){let a=this.menuBox(c.bar);c.menu={x:a.left,y:a.top,width:a.width,maxHeight:a.maxHeight}}else if(this.menu){let a=this.menu,h,p;if(a.slashAt!==null){let f=t.coordsAtPos(a.slashAt-1);h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}else{let f=a.anchor===this.plus?l?.getBoundingClientRect?.()??s:a.anchor.getBoundingClientRect();h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}c.menu={x:Math.max(8,Math.min(h-o.left,o.width-280)),y:p-o.top}}return c}paintLayout(t){if(t.bar)this.dock.style.left=`${t.bar.left}px`,this.dock.style.top=`${t.bar.top}px`,this.dock.style.width=`${t.bar.width}px`,this.grip.style.setProperty("--page-grip-lift",`${t.bar.height}px`);else{if(t.desk)for(let e of["left","top","width"])this.dock.style.removeProperty(e);this.grip.style.removeProperty("--page-grip-lift")}if(t.gutter)for(let e of[this.plus,this.grip])e.style.setProperty("--page-plus-top",`${t.gutter.top}px`),e.style.setProperty("--page-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--page-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--page-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--page-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--page-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--page-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--page-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--page-pop-max",`${t.menu.maxHeight}px`)))}get settingsAPI(){return globalThis.clay?.page?.settings??null}update(t,e){let o=!this.settingsAPI;if(this.settingsBtn.hidden!==o&&(this.settingsBtn.hidden=o),this.view=t,this.menu&&this.menu.slashAt===null&&e&&e.doc!==t.state.doc)if(this.menu.persist&&this.menu.anchor?.isConnected)this.scheduleLayout();else{let c=this.menuEl.contains(document.activeElement);this.closeMenu(),c&&t.focus()}let s=t.state,r=s.doc.child(this.blockIndex());this.turn.textContent=`${Ot(r).label} \u25BE`,this.bubbleTurn.textContent=this.turn.textContent;for(let c of this.dock.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));let l=!!this.menu&&[this.bubbleTurn,this.bubbleMore].includes(this.menu.anchor)||!s.selection.empty&&s.selection instanceof $t&&t.hasFocus();if(this.bubble.hidden=!l,l)for(let c of this.bubble.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));if(this.grip.classList.toggle("is-on",s.selection instanceof z),this.inRoving(this.roving)||this.setRoving(this.dockControls()[0]),!this.menu&&e&&e.doc!==s.doc&&!this.remote&&t.hasFocus()&&s.selection.empty){let c=s.selection.$head;if(c.depth===1&&c.parent.isTextblock&&!c.parent.type.spec.code){let d=s.doc.textBetween(c.start(),c.pos),u=/(?:^|\s)\/([a-z]*)$/i.exec(d),a=u?c.start()+u.index+u[0].indexOf("/")+1:null;u&&this.slashKey(a)!==this.dismissedSlash&&this.openMenu("insert",this.plus,a,null,c.parent.attrs.id)}}this.slashQuery(),this.scheduleLayout()}destroy(){this.destroyed=!0,this.frame!==null&&this.win.cancelAnimationFrame(this.frame),this.frame=null,clearTimeout(this.movedTimer),this.drag.destroy(),this.shell.removeEventListener("mousemove",this.onMove),this.shell.removeEventListener("mouseleave",this.onLeave),this.shell.removeEventListener("keydown",this.onKey),this.win.removeEventListener("resize",this.onResize),this.win.removeEventListener("scroll",this.onResize,!0),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onResize),document.removeEventListener("mousedown",this.onDocDown,!0),document.removeEventListener("keydown",this.onSettingsKey,!0);for(let t of[this.dock,this.plus,this.grip,this.bubble,this.scrim,this.menuEl,this.settingsEl,this.probe])t?.remove()}};function Qi({onAiTool:n=null}={}){let t=null;return new In({key:ps,view(e){return t=new de(e,n),pe.set(e,t),t},filterTransaction(e){return t&&e.docChanged&&(t.remote=!!e.getMeta(Me)),!0},props:{handleKeyDown(e,o){return t?o.key==="/"&&(o.metaKey||o.ctrlKey)&&!o.altKey&&!t.menu?(o.preventDefault(),t.openActions(),!0):t.key(o):!1},handleTextInput(e,o,s,r){if(r!=="/"||!t)return!1;let i=Ge(e,r);i&&(o=e.state.selection.from-1);let l=e.state.doc.resolve(o);if(l.depth!==1||!l.parent.isTextblock||l.parent.type.spec.code||l.parentOffset>0&&!/\s/.test(e.state.doc.textBetween(o-1,o,"",`
|
|
6
|
+
`)))return i;i||e.dispatch(e.state.tr.insertText("/",o,s).setMeta(xt,qt(e.state,o,s,"/")));let c=Math.min(e.state.doc.resolve(o).index(0),e.state.doc.childCount-1);return t.openMenu("insert",t.plus,o+1,null,e.state.doc.child(c).attrs.id),!0},handleDOMEvents:{keydown(e,o){return It(o,e)},blur(e){return t&&!(t.menu&&[t.bubbleTurn,t.bubbleMore].includes(t.menu.anchor))&&(t.bubble.hidden=!0),!1}}}})}var{Plugin:ms}=C,me=new WeakMap,gs=n=>typeof n.text=="function"?n.text():new Promise((t,e)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>e(o.error),o.readAsText(n)});function Bt(n,t){let e=n.dom.ownerDocument,o=n.dom.parentElement.querySelector(".page-csv-error");o||(o=e.createElement("div"),o.className="page-csv-error",o.setAttribute("role","alert"),n.dom.parentElement.append(o)),o.textContent=t}function bs(n){let t=0,e=Ce(n,{maxBytes:Jt,newId:()=>k(t++<n.header.length?"c":"r")});if(!Object.keys(e.cols).length)return null;if(!Object.keys(e.rows).length){let o=Object.fromEntries(Object.keys(e.cols).map(s=>[s,""]));e.rows[k("r")]={pos:A(),cells:o}}return{node:Y(g,k(),{t:"table",pos:null,cols:e.cols,rows:e.rows}),truncated:e.truncated}}async function ys({kept:n,total:t}){let e=`This file has ${t} rows. The first ${n} fit in a table.`,o=globalThis.clay?.confirm,s=globalThis.clay?.modal;o||(o=(await import("./c-FSWRGBVQ.js")).consent,s=(await import("./c-HMYWIHFG.js")).default);let r=o(e);s&&(s.yes=`Insert first ${n} rows and attach the file`);try{return await r,!0}catch{return!1}}var ks=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{e<0&&o.type===g.nodes.table&&o.attrs.id===t&&(e=r)}),e},xs=n=>{let t=!0;return n.descendants(e=>(e.isText&&(t=!1),t)),t};function Ms(n,t,e,o){let s=n.state,r=ks(s.doc,e);if(r<0)return F(s,n.dispatch,t,null,o);let i=0;for(let u=0;u<r;u++)i+=s.doc.child(u).nodeSize;let l=s.doc.child(r);if(!xs(l)||o){let u=s.doc.maybeChild(r+1),a=l.attrs.parent??null,h=A(l.attrs.pos,u?.attrs.pos??null),p=t.type.create({...t.attrs,pos:h,parent:a},t.content),f=i+l.nodeSize,m=s.tr.insert(f,p);return o&&m.insert(f+p.nodeSize,o.type.create({...o.attrs,pos:A(h,u?.attrs.pos??null),parent:a},o.content)),m.setSelection(C.TextSelection.create(m.doc,f+3)),n.dispatch(w(m).scrollIntoView()),!0}let c=t.type.create({...t.attrs,id:l.attrs.id,pos:l.attrs.pos,parent:l.attrs.parent},t.content),d=s.tr.replaceWith(i,i+l.nodeSize,c);return d.setSelection(C.TextSelection.create(d.doc,i+3)),n.dispatch(w(d).scrollIntoView()),!0}async function fe(n,t,{upload:e,remove:o=null,table:s=null}={}){try{n.dom.parentElement.querySelector(".page-csv-error")?.remove();let r=ht(await gs(t)),i=bs(r);if(!i)return Bt(n,"Couldn't read this CSV: no columns."),!1;let l=null;if(i.truncated){if(!await ys(i.truncated))return!1;let u=await e?.(t),a=ye(u?.uploads?.[0]?.url);if(!u?.ok||!a)return Bt(n,"Couldn't attach the original CSV."),!1;l=g.nodes.file.create({id:k(),src:a,name:t.name,size:t.size??null,mime:t.type||"text/csv"})}if(n.isDestroyed)return!1;if(s)return Ms(n,i.node,s,l);let c=o?Kn(n.state):null;return o&&!c&&Ss(n,o.block),F(n.state,n.dispatch,i.node,c,l)}catch(r){return r instanceof Se?Bt(n,`Couldn't read this CSV: unclosed quote on line ${r.line}.`):Bt(n,"Couldn't read this CSV."),!1}}function Ct(n,t=null,e=null){let o=me.get(n);return o?(t&&Fn(n,t),o._remove=t?{...t,block:ws(n.state.doc,t.from)}:null,o._table=e,o.click(),!0):!1}var ws=(n,t)=>n.child(n.resolve(Math.max(0,Math.min(t,n.content.size))).index(0)).attrs.id;function Ss(n,t){let e=n.state,o=null;return e.doc.forEach((s,r)=>{o===null&&s.attrs.id===t&&(o=r)}),o===null?!1:(n.dispatch(e.tr.setSelection(C.TextSelection.near(e.doc.resolve(o)))),!0)}var Vn=n=>[...n].filter(t=>/\.csv$/i.test(t.name||"")||/^(text\/csv|application\/csv)$/i.test(t.type||""));function al({upload:n}){return new ms({view(t){let e=t.dom.ownerDocument.createElement("input");return e.type="file",e.accept=".csv,text/csv",e.hidden=!0,e.className="page-csv-input",t.dom.parentElement.append(e),me.set(t,e),e.addEventListener("change",()=>{let o=e.files?.[0];o&&fe(t,o,{upload:n,remove:e._remove,table:e._table}),e._remove=null,e._table=null,e.value=""}),{destroy(){me.delete(t),e.remove()}}},props:{handlePaste(t,e){let o=Vn(e.clipboardData?.files||[]);return o.length?(e.preventDefault(),fe(t,o[0],{upload:n}),!0):!1},handleDrop(t,e,o,s){let r=Vn(e.dataTransfer?.files||[]);if(s||!r.length)return!1;e.preventDefault();let i=t.posAtCoords({left:e.clientX,top:e.clientY});return i&&t.dispatch(t.state.tr.setSelection(C.TextSelection.near(t.state.doc.resolve(i.pos)))),fe(t,r[0],{upload:n}),!0}}})}export{Bs as a,qs as b,Je as c,Cs as d,As as e,al as f,hn as g,ni as h,Tt as i,It as j,Oi as k,vi as l,Ii as m,fr as n,mr as o,Ys as p,Js as q,Xs as r,te as s,Yi as t,Fn as u,Kn as v,Ji as w,Xi as x,Qi as y,Gt as z,bo as A,Lr as B,Dr as C,$r as D,_r as E,Br as F,yo as G,ko as H,Pr as I,Rr as J,Nr as K,Hr as L,zr as M,Fr as N,Kr as O,Vr as P,jr as Q,qr as R,Wr as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as g}from"./c-
|
|
1
|
+
import{B as g}from"./c-44B5ODN7.js";import"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var p=(t,r)=>{let s=-1;return t.forEach((n,l,c)=>{n.attrs.id===r&&(s=c)}),s};function y(t,r,s){let n=t.state,l=p(n.doc,r);if(l<0)return!1;let c=0;for(let e=0;e<l;e++)c+=n.doc.child(e).nodeSize;let a=n.doc.child(l);return t.dispatch(g(n.tr.setNodeMarkup(c,null,{...a.attrs,...s}))),!0}function b(t,r){let s=p(t.state.doc,r);if(s<0)return!1;let n=t.dom.parentElement,l=n.ownerDocument,c=0;for(let o=0;o<s;o++)c+=t.state.doc.child(o).nodeSize;let a=l.createElement("div");a.className="page-link",a.dataset.mode="alt";let e=l.createElement("input");e.className="page-link-input",e.type="text",e.value=t.state.doc.child(s).attrs.alt||"",e.placeholder="Describe the image",e.setAttribute("aria-label","Alt text"),a.append(e);let d=t.nodeDOM(c)?.getBoundingClientRect?.(),u=n.getBoundingClientRect();d&&(a.style.setProperty("--page-pop-x",`${d.left-u.left}px`),a.style.setProperty("--page-pop-y",`${d.bottom-u.top+6}px`)),n.append(a);let f=!1,i=(o,h=!0)=>{if(f)return;f=!0;let m=e.value.trim();a.remove();let x=p(t.state.doc,r);o&&x>=0&&m!==t.state.doc.child(x).attrs.alt&&y(t,r,{alt:m}),h&&t.focus()};return e.addEventListener("keydown",o=>{o.key==="Enter"?(o.preventDefault(),i(!0)):o.key==="Escape"&&(o.preventDefault(),o.stopPropagation(),i(!1))}),e.addEventListener("blur",()=>i(!0,!1)),e.focus(),!0}export{b as openAltEditor,y as setImageAttrs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d,b as c,c as o,d as n}from"./c-
|
|
1
|
+
import{a as d,b as c,c as o,d as n}from"./c-TWCXBWS3.js";import{a as u}from"./c-VKEDWYDF.js";import{f as a}from"./c-3O7OBDCM.js";import{b as l,q as b}from"./c-EGTIAL6P.js";var r="[editmode\\:contenteditable]";function m(){b(e=>{e.querySelectorAll(r).forEach(t=>{n(t),o(t,l(t)??t)})})}function s(){a&&u(()=>{p()})}function p(e=document){e.querySelectorAll(r).forEach(t=>{d(t);let i=t.getAttribute("inert-contenteditable")??t.getAttribute("contenteditable")??c(t,"inert-contenteditable")??"true",f=i.toLowerCase();t.setAttribute("contenteditable",["","true","false","plaintext-only"].includes(f)?i:"true"),t.removeAttribute("inert-contenteditable")})}function y(){document.querySelectorAll(r).forEach(e=>{n(e),o(e)})}function S(){m(),s()}export{r as a,p as b,y as c,S as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d}from"./c-
|
|
1
|
+
import{a as d}from"./c-LA2BW7UY.js";import{b as A,k as c}from"./c-HA6INT6J.js";import{i as s}from"./c-ICMAOOGK.js";import{a as v}from"./c-VHNSBD2M.js";var O={};v(O,{CONTROLLED_SELECTOR:()=>m,authoredAttr:()=>b,canonicalContentEditable:()=>x,canonicalContentEditableValue:()=>E,captureAll:()=>h,captureAuthored:()=>u,captureFrozen:()=>p,frozenOriginal:()=>L,restoreAuthoredOrder:()=>T});var m="[editmode\\:contenteditable], [editmode\\:onclick], [viewmode\\:disabled], [viewmode\\:readonly]",l=new WeakMap,f=new WeakMap;function u(e){let t=l.get(e);if(!t){let r=e.getAttributeNames(),n={};for(let i of r)n[i]=e.getAttribute(i);t={order:r,values:n},l.set(e,t)}return t}function b(e,t){if(!e)return null;let{values:r}=u(e);return t in r?r[t]:null}function T(e,t=e){let r=l.get(t);if(!r)return;let n=e.getAttributeNames(),i=[...r.order.filter(o=>n.includes(o)),...n.filter(o=>!r.order.includes(o))];if(i.every((o,a)=>o===n[a]))return;let g=i.map(o=>[o,e.getAttribute(o)]);for(let o of n)e.removeAttribute(o);for(let[o,a]of g)e.setAttribute(o,a)}function E(e){return e.getAttribute("contenteditable")??e.getAttribute("inert-contenteditable")??b(e,"inert-contenteditable")??b(e,"contenteditable")??"true"}function x(e){e.setAttribute("inert-contenteditable",E(e)),e.removeAttribute("contenteditable")}function y(e){let t=e.innerHTML;if(!e.querySelector(`[${c}]`)&&!t.includes("ephemeral")&&!t.includes("<dialog"))return t;let r=e.cloneNode(!0);for(let n of r.querySelectorAll(`[${c}]`))n.removeAttribute(c);for(let n of r.children)A(n);return r.innerHTML}function p(e){f.has(e)||f.set(e,y(e))}function L(e){return f.get(e)}function h(){for(let e of document.querySelectorAll(m))u(e);for(let e of document.querySelectorAll(s))p(e)}h();d.onAddElement({selectorFilter:m,require:"observed",pausable:!1,debounce:0},e=>{e.forEach(({element:t})=>u(t))});d.onAddElement({selectorFilter:s,require:"observed",pausable:!1,debounce:0},e=>{e.forEach(({element:t})=>p(t))});export{u as a,b,T as c,x as d,L as e,h as f,O as g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./c-
|
|
1
|
+
import{a}from"./c-S5IEIZCN.js";import"./c-GVPNDIKJ.js";import"./c-ATKAOH23.js";import"./c-EK63G3CG.js";import"./c-NQJRVJ56.js";import"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-EGTIAL6P.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{a as replace};
|