@panphora/clayjs 1.25.1 → 1.26.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 +1141 -345
- package/dist/m/c-2EPHRF47.js +1 -0
- package/dist/m/{c-2GB34XL4.js → c-2SUFMUZX.js} +2 -2
- package/dist/m/{c-BHLYQGTA.js → c-3S3647J6.js} +1 -1
- package/dist/m/{c-QL4NYM2L.js → c-3S5TNRZA.js} +1 -1
- package/dist/m/{c-3Y234AUB.js → c-3XGLJAS7.js} +2 -2
- package/dist/m/{c-O4YIDULY.js → c-42WBOKFM.js} +1 -1
- package/dist/m/{c-42RLKGEY.js → c-4TP3UXBT.js} +1 -1
- package/dist/m/{c-ASGHHLFX.js → c-5ELELG2F.js} +1 -1
- package/dist/m/{c-T5IWJOMW.js → c-5ZYLTN3Q.js} +1 -1
- package/dist/m/{c-DDCYVLGG.js → c-67TBU56I.js} +1 -1
- package/dist/m/{c-WNOLMHI2.js → c-6BGJAJ67.js} +1 -1
- package/dist/m/{c-XS7G6U3Z.js → c-ABOBD7F3.js} +1 -1
- package/dist/m/{c-5IIEOPIV.js → c-ARO6CPMA.js} +1 -1
- package/dist/m/{c-XUZMRQ7O.js → c-BCS3AZQZ.js} +1 -1
- package/dist/m/c-BOS7GONO.js +1 -0
- package/dist/m/{c-NICICT4P.js → c-DEYHCYJB.js} +1 -1
- package/dist/m/{c-T7LOTEWO.js → c-DZT6W2NG.js} +1 -1
- package/dist/m/c-EHJWIGWN.js +1 -0
- package/dist/m/{c-V2V5FKXX.js → c-EIUKME3W.js} +1 -1
- package/dist/m/{c-ASMLERFA.js → c-EXZOA6XY.js} +1 -1
- package/dist/m/{c-STAPQ2X6.js → c-EYFMAR3M.js} +1 -1
- package/dist/m/{c-DVMDYRAE.js → c-FUN6AKFE.js} +1 -1
- package/dist/m/{c-XMIDHEKF.js → c-GY36NO7C.js} +1 -1
- package/dist/m/{c-TWB5ZQU4.js → c-H47C6PJZ.js} +1 -1
- package/dist/m/c-KD2ME5UN.js +2 -0
- package/dist/m/{c-GO635CRU.js → c-LAKBBJOU.js} +2 -2
- package/dist/m/{c-GNFDX6SU.js → c-LETPPG2F.js} +1 -1
- package/dist/m/{c-LS7IVQVW.js → c-MMV5JULA.js} +1 -1
- package/dist/m/{c-NEQRFC4O.js → c-MVVEIJUU.js} +1 -1
- package/dist/m/{c-XCOQNISP.js → c-N362HNGO.js} +1 -1
- package/dist/m/{c-7K4SCQB7.js → c-ND3W7D5U.js} +1 -1
- package/dist/m/{c-4NAYDOWH.js → c-NNHNXD6M.js} +1 -1
- package/dist/m/{c-DAUQ6JZ3.js → c-NYJ577NL.js} +1 -1
- package/dist/m/{c-3AAQJAKJ.js → c-PWILUN4T.js} +1 -1
- package/dist/m/{c-7Z2625LX.js → c-QA3Q3MDI.js} +1 -1
- package/dist/m/{c-2A2ATCIH.js → c-QKOKMQXA.js} +1 -1
- package/dist/m/{c-TGIMBAWE.js → c-RBWVF4N5.js} +1 -1
- package/dist/m/{c-A5IYL7JI.js → c-SPOEDIMP.js} +1 -1
- package/dist/m/{c-ZJ7726FO.js → c-SRW5OBCF.js} +1 -1
- package/dist/m/{c-A3OKSYRI.js → c-SYOA4T7V.js} +1 -1
- package/dist/m/{c-MHTO3QAD.js → c-TJ5PFOJ2.js} +1 -1
- package/dist/m/{c-NW4ZFKCY.js → c-TKV273YU.js} +1 -1
- package/dist/m/{c-D4N4UJCQ.js → c-UEKJWXCB.js} +2 -2
- package/dist/m/{c-44WITKWQ.js → c-V4DBV5ZV.js} +1 -1
- package/dist/m/c-WHMZCRQD.js +6 -0
- package/dist/m/{c-WMRJKQ2V.js → c-WHQUZM2V.js} +1 -1
- package/dist/m/{c-C27EVUQ6.js → c-XHD7XJTE.js} +1 -1
- package/dist/m/{c-PP3CUF3U.js → c-XONFK3WC.js} +1 -1
- package/dist/m/c-YYIN4NAF.js +30 -0
- package/dist/m/c-ZFAPQQIB.js +1 -0
- package/dist/m/core/{conflict-notice-Y2NTMDGJ.js → conflict-notice-UNDOD4BL.js} +1 -1
- package/dist/m/core/site-edits-C22O53GS.js +1 -0
- package/dist/m/loader-DCKCZKY6.js +1 -0
- package/dist/m/{manifest-A27A4278.js → manifest-7954CBE3.js} +1 -1
- package/dist/m/{manifest-edit-E8A61EB4.js → manifest-edit-93AA79D7.js} +1 -1
- package/dist/m/manifest.json +442 -441
- package/dist/m/page/{editor-HS2CAV3W.js → editor-UF3CIA6V.js} +2 -2
- package/dist/m/plugins/{cms-4KET6RZT.js → cms-KG6TCTR3.js} +1 -1
- package/dist/m/plugins/{live-CO4VJS46.js → live-DF5YS5AH.js} +1 -1
- package/dist/m/plugins/page-GZSU77JS.js +2 -0
- package/dist/m/plugins/{page-view-6KNTXABH.js → page-view-7MM3FEAR.js} +1 -1
- package/dist/m/plugins/{quickcrop-VNRXGRPC.js → quickcrop-UHURKA2F.js} +2 -2
- package/dist/m/plugins/richclay-MXH2GFAZ.js +549 -0
- package/dist/m/plugins/undo-KLHAGV75.js +1 -0
- package/dist/m/sync/{live-sync-DX4K5GDB.js → live-sync-RZQSDMZW.js} +1 -1
- package/dist/offline-manifest.json +360 -360
- package/package.json +1 -1
- package/src/core/site-edits.js +1 -1
- package/src/loader-logic.js +0 -13
- package/src/page/boot-pack.js +1 -0
- package/src/page/history-intent.js +111 -4
- package/src/page/ybind/bridge.js +14 -7
- package/src/page/ybind/moves.js +437 -3
- package/src/page/ybind/origins.js +1 -1
- package/src/page/ybind/recovery.js +1 -1
- package/src/plugins/page.js +48 -4
- package/src/plugins/richclay.js +136 -0
- package/src/plugins/undo.js +169 -7
- package/src/recovery/undo.js +14 -7
- package/src/sync/live-sync.js +24 -0
- package/src/ui/vendor-skin.js +9 -4
- package/dist/m/c-3XNTQQEJ.js +0 -1
- package/dist/m/c-4OZZ7ENT.js +0 -30
- package/dist/m/c-D2OPWOWO.js +0 -2
- package/dist/m/c-LUBZU4AZ.js +0 -6
- package/dist/m/c-LYNLY3MR.js +0 -1
- package/dist/m/c-MLMJUNRV.js +0 -1
- package/dist/m/c-V5L6HWVL.js +0 -1
- package/dist/m/core/site-edits-TIJDPG6H.js +0 -1
- package/dist/m/loader-7ORQVRCK.js +0 -1
- package/dist/m/plugins/page-L3VKIQU2.js +0 -2
- package/dist/m/plugins/richclay-V6WKJTUF.js +0 -549
- package/dist/m/plugins/undo-WUK2NLBA.js +0 -1
- /package/dist/m/plugins/{quickcrop-VNRXGRPC.js.LEGAL.txt → quickcrop-UHURKA2F.js.LEGAL.txt} +0 -0
- /package/dist/m/plugins/{richclay-V6WKJTUF.js.LEGAL.txt → richclay-MXH2GFAZ.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{J as yt,O as it,T as ze,s as Re,w as Ne,x as kt,y as He}from"./c-LAKBBJOU.js";import{a as _e,d as bt,g as Be,h as Pe}from"./c-EIUKME3W.js";import{f as Ve,o as je}from"./c-DZT6W2NG.js";import{a as xt,c as Ke}from"./c-SYOA4T7V.js";import{C as S,D as Wt,E as Ze,F as Ut,G as tn,H as en,a as Fe,d as R,e as T,f as We,h as Q,i as Ue,m as Ge,p as F,s as qt,u as Ye,v as Je,y as Xe,z as Qe}from"./c-3XGLJAS7.js";import{A as x,B as mt,C as ve,F as X,K as $e,L as gt,M as jt,N as Ie,O as Le,P as De,a as Te,c as Ee,d as b,fa as rt,g as Ce,h as Ae,u as ft,v as Oe,w as H,x as v,y as z,z as I}from"./c-OH2FPYSY.js";import{b as qe}from"./c-FSQXFG5T.js";import{b as O,d as Kt,f as pt,g as Se,h as Vt}from"./c-RETTCOWO.js";import{a as N}from"./c-JC4RZW4E.js";var nn=new WeakMap;function on(n){let t=nn.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]=Le(n.attrs.cols[o].kind,s)}return nn.set(n,t),t}var Ps=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),Rs=Object.freeze({text:"Text",number:"Number",date:"Date"});var Gt=(n,t,e)=>{let o=n.attrs.get(t.baseId),s={};for(let r of Be(e))s[r]=o&&o.has(r)?o.get(r):Pe(e,r);return e.name==="board"&&Object.assign(s,Ne(n.boardFields,t.baseId)),e.name==="table"&&Object.assign(s,Re(n.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},sn=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]=sn(s))}),e.t=t.t,e};function qs(n,t,e=null){let o=d=>{if(d.opaque){let a=d.recovered?{...sn(d.fields??{})}:Qn(n,d);return{b:d,type:b.nodes.opaque_block,fields:a,opaque:!0}}let u=b.nodes[d.t]??b.nodes.paragraph;return{b:d,type:u,fields:{...d.fields??Gt(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(yt(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((g,k)=>{let w=l(s[r.get(g)]),A=l(s[r.get(k)]);return w.clock<A.clock||w.clock===A.clock&&w.client<A.client?g:k}),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 g=[];for(let k of d.runs)k.hole||(k.br?g.push(b.nodes.hard_break.create()):g.push(b.text(k.text,k.marks)));return a.create({id:d.id,pos:null,raw:h},g)}let f={id:d.id,pos:null,...h};if(a.name==="table"&&Object.keys(f.rows??{}).length&&Object.keys(f.cols??{}).length)return X(b,d.id,{t:"table",...f});if(!a.isTextblock)return a.create(f);let m=[];for(let g of d.runs)g.hole||(g.br?m.push(b.nodes.hard_break.create()):m.push(b.text(g.text,g.marks)));return a.create(f,m)});return c.length?b.nodes.doc.create(null,c):b.nodes.doc.createAndFill()}var C=n=>({status:"refused",code:n}),Mt=n=>JSON.parse(JSON.stringify(n)),Zn=["title","owner","due"],to=/^\d{4}-\d{2}-\d{2}$/,wt=(n,t)=>n==="title"?typeof t=="string":n==="due"?t===null||typeof t=="string"&&to.test(t):t===null||typeof t=="string"&&t.length>0,eo=n=>n!==null&&typeof n=="object"&&!Array.isArray(n);function rn(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&&!H(r)||i!==null&&!H(i)||r!==null&&i!==null&&r>=i)continue;let l=v(r,i);if(s(l))return l}return`${n.reduce((r,i)=>i>r?i:r,"")}V`}function Yt(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:rn(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=rn(i===null?[d]:[d,i],1));return{pos:l[0],rekey:n.slice(e,r).map((c,d)=>[c,l[d+1]])}}var St=(n,t,e)=>{let{pos:o,rekey:s}=Yt(t,r=>n[r].pos,e);for(let[r,i]of s)n[r]={...n[r],pos:i};return o};function er({pd:n,um:t=null,origins:e=null,render:o=()=>{}}){let s=u=>{if(typeof u!="string")return null;let a=ze(n,e).visible.find(p=>p.id===u);if(!a||a.t!=="board")return null;let h=a.fields??Gt(n,a,b.nodes.board);return{columns:Mt(h.columns??{}),cards:Mt(h.cards??{})}},r=(u,a,h,p)=>{let f=it(u);return t?.stopCapturing(),n.ydoc.transact(()=>{if(!f)He(n,u,a,h);else for(let m of["columns","cards"])rt(a[m])!==rt(h[m])&&n.gone.set(yt(f,m),Mt(h[m]))},_e),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,Mt(h)):C("missing-board")};return{read:u=>s(u),removed(u){return s(u)?it(u)?{columns:{},cards:{}}:kt(n.boardFields,u):null},createColumn:(u,{name:a="",afterId:h}={})=>d(u,(p,f)=>{if(typeof a!="string")return C("invalid-value");let m=I(p.columns);if(c(m,h))return C("missing-destination");let g=x("c");return f.columns[g]={pos:St(f.columns,m,l(m,h)),name:a},r(u,p,f,{status:"created",id:g})}),renameColumn:(u,a,h)=>d(u,(p,f)=>Object.hasOwn(p.columns,a)?typeof h!="string"?C("invalid-value"):p.columns[a].name===h?{status:"unchanged"}:(f.columns[a].name=h,r(u,p,f,{status:"changed"})):C("missing-column")),moveColumn:(u,a,{afterId:h=null}={})=>d(u,(p,f)=>{if(!Object.hasOwn(p.columns,a))return C("missing-column");let m=I(p.columns).filter(w=>w!==a);if(c(m,h))return C("missing-destination");let g=l(m,h),k=I(p.columns);return[...m.slice(0,g),a,...m.slice(g)].every((w,A)=>w===k[A])?{status:"unchanged"}:(f.columns[a].pos=St(f.columns,m,g),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})):C("missing-column")),restoreColumn:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.columns,a))return{status:"unchanged"};let f=it(u)?null:kt(n.boardFields,u).columns[a];return f?(p.columns[a]=f,r(u,h,p,{status:"restored"})):C("missing-column")}),createCard:(u,{columnId:a,title:h="",owner:p=null,due:f=null,afterId:m}={})=>d(u,(g,k)=>{if(!Object.hasOwn(g.columns,a))return C("missing-column");if(!wt("title",h)||!wt("owner",p)||!wt("due",f))return C("invalid-value");let w=i(g,a);if(c(w,m))return C("missing-destination");let A=x("k");return k.cards[A]={pos:St(k.cards,w,l(w,m)),col:a,title:h,...p!==null?{owner:p}:{},...f!==null?{due:f}:{}},r(u,g,k,{status:"created",id:A})}),editCard:(u,a,h)=>d(u,(p,f)=>{if(!Object.hasOwn(p.cards,a))return C("missing-card");if(!eo(h)||!Object.keys(h).length||Object.keys(h).some(g=>!Zn.includes(g)))return C("invalid-field");if(Object.entries(h).some(([g,k])=>!wt(g,k)))return C("invalid-value");let m={...p.cards[a]};for(let[g,k]of Object.entries(h))k===null?delete m[g]:m[g]=k;return rt(m)===rt(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 C("missing-card");if(!Object.hasOwn(f.columns,h))return C("missing-column");let g=i(f,h,a);if(c(g,p))return C("missing-destination");let k=l(g,p),w=f.cards[a];if(w.col===h){let A=i(f,h);if([...g.slice(0,k),a,...g.slice(k)].every((P,Y)=>P===A[Y]))return{status:"unchanged"}}return m.cards[a]={...w,col:h,pos:St(m.cards,g,k)},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"})):C("missing-card")),restoreCard:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.cards,a))return{status:"unchanged"};let f=it(u)?null:kt(n.boardFields,u).cards[a];return f?(p.cards[a]=f,r(u,h,p,{status:"restored"})):C("missing-card")})}}var Tt="blockeditor-history-intent",no=500,oo=(n,t)=>{let e=n.resolve(t);return e.depth?e.node(1).attrs.id:null},so=n=>(n.storedMarks??n.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(","),ro=/[.?!]["'\u201D\u2019)\]]*$/,io=(n,t,e)=>{if(!/\s$/.test(e))return!1;let o=n.doc.resolve(t),s=o.parent.textBetween(0,o.parentOffset)+e.replace(/\s+$/,"");return!/\s$/.test(s)&&ro.test(s)};function Xt(n,t,e,o){return{kind:"insert",blockId:oo(n.doc,t),from:t,end:t+o.length,replaced:t!==e,text:o,marks:so(n),breakAfter:io(n,t,o),at:Date.now()}}function rr(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>no?!1:t.kind==="insert"?!n.breakAfter&&!t.replaced&&t.from===n.end&&t.marks===n.marks:t.direction===n.direction&&(t.direction<0?t.to===n.from:t.from===n.from)}var lo={deleteContentBackward:-1,deleteContentForward:1},Jt=new WeakMap,co=1e3,Qt="blockeditor-derived";function ao(n){let t=Jt.get(n)??null;return Jt.delete(n),t}function uo(n,t){if(!t||n.before!==t.doc||Date.now()-t.at>co||n.getMeta(We)||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 ir(n,t=null){let e=t?ao(t):null,o=n.filter(i=>!i.getMeta(Qt));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(Tt)??uo(s,e)}function lr(){return new O.Plugin({props:{handleTextInput(n,t,e,o,s){return n.dispatch(s().setMeta(Tt,Xt(n.state,t,e,o))),!0},handleDOMEvents:{beforeinput(n,t){let e=lo[t.inputType];return e&&Jt.set(n,{direction:e,at:Date.now(),doc:n.state.doc}),!1}}}})}function cr({um:n,undo:t,redo:e,article:o,focus:s}){let r=()=>window.clay?.undo,i=Math.random().toString(36).slice(2),l=0,c=!1,d=!1,u=!1,a=(g,k)=>{let w=k==="undo"?"undoStack":"redoStack",A=k==="undo"?"redoStack":"undoStack",P=n[w],Y=n[A],zt=P.indexOf(g.item);if(zt<0)throw new Error("blockeditor: history item is no longer available");let dt=P.filter((Ds,Xn)=>Xn!==zt),st=[...Y,...dt],Ft=st.length;n[w]=[g.item],n[A]=st,c=!0;let we,ht;try{we=k==="undo"?t():e()}finally{ht=st.slice(Ft),n[w]=dt,n[A]=[...Y,...ht],c=!1,n.stopCapturing()}if(!we||!ht.length)throw g.item=null,new Error("blockeditor: history item was emptied by another edit");g.item=ht[0],g.applied=k==="redo"},h=g=>{if(c||g.origin===n||g.type!=="undo"||r()?.pageHistory!==!0)return;let k={item:g.stackItem,applied:!0},w=`${i}:${++l}`,A=`${w}:undone`,P=`${w}:applied`,Y={kind:"value",target:o,prop:`blockeditor-step:${w}`,oldValue:A,newValue:P,read:()=>!u&&k.item&&(k.applied?n.undoStack:n.redoStack).includes(k.item)?k.applied?P:A:null,write:(zt,dt)=>{let st=!!document.activeElement?.closest?.('[contenteditable]:not([contenteditable="false"])'),Ft=o.textContent;a(k,dt===A?"undo":"redo"),st&&o.textContent!==Ft&&typeof s=="function"&&s()}};d=!0;try{try{r().recordStep("Edit",Y)}catch{r().record(Y)}}finally{d=!1}},p=()=>{d||n.stopCapturing()};n.on("stack-item-added",h);let f=null,m=()=>{let g=r()?.pageHistory===!0?r():null;g!==f&&(f?.off?.("commit",p),f=g,f?.on?.("commit",p))};return m(),document.addEventListener("clay:undo-session",m),{dispose(){u=!0,n.off("stack-item-added",h),f?.off?.("commit",p),document.removeEventListener("clay:undo-session",m)}}}function ho(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=>mt(Xe.parse(u,{topNode:b.nodes.table_cell.create()})))).filter(d=>d.length),own:!!i.querySelector("td[data-col]")}}function po(n){if(!n||!n.includes(" "))return null;let{header:t,rows:e}=gt(n.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...e],own:!1}}function ln(n,t,e=globalThis.document){let o=null;try{o=ho(n,e)}catch{o=null}if(!o&&!/<table[\s>]/i.test(n||""))try{o=po(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 Et(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},()=>x("c")),i=z(null,null,e),l=Object.fromEntries(r.map((a,h)=>[a,{pos:i[h],name:ft(o[h]??"").replace(/\s+/g," ").trim()||`Column ${h+1}`}])),c=s.length?s:[[]],d=z(null,null,c.length),u=Object.fromEntries(c.map((a,h)=>[x("r"),{pos:d[h],cells:Object.fromEntries(r.map((p,f)=>[p,a[f]??""]))}]));return X(b,x(),{t:"table",pos:null,cols:l,rows:u})}var{Plugin:fo,TextSelection:mo}=O,Zt=b.nodes;var dn=(n,t)=>{let e=null;return n.forEach((o,s)=>{!e&&o.type===Zt.table&&o.attrs.id===t&&(e={node:o,pos:s})}),e};function j(n,t){if(!t)return null;let e=dn(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 g=[],k=h+1;p.forEach((w,A,P)=>{P>=d&&P<=u&&g.push({cell:w,pos:k}),k+=w.nodeSize}),a.push(g)}h+=p.nodeSize}),{...e,top:l,bottom:c,left:d,right:u,cells:a}}var lt=(n,t)=>{let e=n.resolve(t);for(let o=e.depth;o>0;o--)if(e.node(o).type===Zt.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 Ct(n,t,e){let o=lt(n.state.doc,t),s=lt(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(mo.create(n.state.doc,s.start)).setMeta(T,r);n.dispatch(i);let l=j(n.state.doc,r),c=l?(l.bottom-l.top+1)*(l.right-l.left+1):0;return R(n,`${c} ${c===1?"cell":"cells"} selected`),!0}function Er(n,t,e,o){let s=n.state.doc.nodeAt(t);if(s?.type!==Zt.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"?Ct(n,l(o,0),l(o,i)):Ct(n,l(0,o),l(r,o))}var go=new Set(["Shift","Control","Alt","Meta","CapsLock"]),bo=n=>/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n;function ko(n,t){let e=n.cells.map(r=>r.map(({cell:i})=>bo(ft(mt(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 cn(n,t){let e=j(n.doc,T.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(T,T.getState(n)),t(S(o))}return!0}var an=(n,t,e)=>{let{text:o,html:s}=ko(t,e.dom.ownerDocument);n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",s),n.preventDefault()},yo=(n,t)=>(e,o,s)=>{let r=T.getState(e),i=j(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(T,{...r,head:[l[d],c[u]]})),!0},un=(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 Cr(){let n=null;return new fo({key:T,state:{init:()=>null,apply(t,e,o,s){let r=t.getMeta(T);return r!==void 0?r:!e||t.selectionSet||t.docChanged&&!t.getMeta(bt)?null:j(s.doc,e)?e:null}},props:{attributes:t=>T.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>T.getState(t.state)?t.state.selection:null,decorations(t){let e=j(t.doc,T.getState(t));return e?Kt.DecorationSet.create(t.doc,e.cells.flat().map(({cell:o,pos:s})=>Kt.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,e){let o=t.state;if(!T.getState(o))return!1;if(e.key==="Escape")return t.dispatch(o.tr.setMeta(T,null)),!0;if(e.key==="Backspace"||e.key==="Delete")return cn(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 yo(...s)(o,t.dispatch,t)}return go.has(e.key)||(e.metaKey||e.ctrlKey)&&(e.key==="a"||e.key==="c"||e.key==="x"||e.key==="v")||t.dispatch(o.tr.setMeta(T,null)),!1},handleDOMEvents:{mousedown(t,e){if(e.button!==0)return!1;!e.shiftKey&&T.getState(t.state)&&t.dispatch(t.state.tr.setMeta(T,null));let o=un(t,e);if(o===null)return!1;if(e.shiftKey){let c=T.getState(t.state),d=(c&&xo(t.state.doc,c))??t.state.selection.$anchor.pos;return lt(t.state.doc,d)?(e.preventDefault(),Ct(t,d,o)):!1}let s=t.dom.ownerDocument,r=o,i=c=>{let d=un(t,c);if(d===null)return;let u=lt(t.state.doc,r),a=lt(t.state.doc,d);if(!u||!a||u.table!==a.table)return;let h=T.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(),Ct(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=j(t.state.doc,T.getState(t.state));return!o||!e.clipboardData?!1:(an(e,o,t),!0)},cut(t,e){let o=j(t.state.doc,T.getState(t.state));return!o||!e.clipboardData?!1:(an(e,o,t),cn(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>n?.()})})}function xo(n,t){let e=dn(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 hn=n=>{let t=j(n.doc,T.getState(n));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var te=new WeakMap;var{Plugin:Mo,TextSelection:q}=O,E=b.nodes,ne=256*1024,B=n=>I(n.attrs.cols),pn=n=>{let t=n.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type===E.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},ct=(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},At=(n,t=v())=>E.table_row.create({id:x("r"),pos:t},n.map(e=>E.table_cell.create({col:e}))),L=(n,t,e)=>E.table.create({...n.attrs,...t},e);function D(n,t,e){let o=pn(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=ct(c.doc,o.pos,i,l);d!==null&&c.setSelection(q.create(c.doc,d)),t(S(c))}return!0}function K(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:v(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 g=s.type.create({...s.attrs,pos:v(u,d?.attrs.pos??null),parent:i.attrs.parent??null},s.content);h.insert(m+a.nodeSize,g)}h.setSelection(q.create(h.doc,ct(h.doc,m,0,0))),t(S(h).scrollIntoView())}return!0}function fn(n=3,t=3){if(!Number.isInteger(n)||!Number.isInteger(t)||n<1||t<1)return null;let e=Array.from({length:t},()=>x("c")),o=z(null,null,t),s=Object.fromEntries(e.map((l,c)=>[l,{pos:o[c],name:`Column ${c+1}`}])),i=z(null,null,n).map(l=>At(e,l));return E.table.create({id:x(),cols:s},i)}var oe=n=>(t,e)=>{let o=pn(t);if(!o||t.selection.$head.parent.type!==E.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:wo(t,e,o,i):(e&&e(t.tr.setSelection(q.create(t.doc,ct(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function wo(n,t,e,o){let s=[...e.table.content.content];if(s.push(At(B(e.table),v(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(q.create(r.doc,ct(r.doc,e.pos,s.length-1,o))),t(S(r).scrollIntoView())}return!0}var So=oe(1),To=oe(-1),Eo=oe("down"),Co=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=[...o.content.content],i=s.row+(n?1:0),l=v(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,At(B(o),l)),{table:L(o,{sort:null},r),row:i}}),Kr=(n,t)=>D(n,t,(e,o)=>{let s=[...e.content.content];if(s.length===1){let r=s[0];s[0]=E.table_row.create(r.attrs,B(e).map(i=>E.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)}}),mn=(n,t,e,o,s)=>{let{pos:r,rekey:i}=Yt(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},Vr=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+(n?1:0),l=x("c"),c=mn(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,E.table_cell.create({col:l})),E.table_row.create(u.attrs,a)});return{table:L(o,{cols:c},d),cell:i}}),jr=(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=>E.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)}}),qr=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=v(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=E.table_row.create({...l.attrs,pos:c},l.content),{table:L(o,{sort:null},i),row:r}}),Wr=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=mn(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),E.table_row.create(a.attrs,h)});return{table:L(o,{cols:d},u),cell:i}}),Ao=48,Oo=1200,Ur=160,gn=n=>Number.isFinite(n)&&n>0?Math.round(Math.min(Oo,Math.max(Ao,n))):null,Gr=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))}}),Yr=(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=gn(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}),Jr=(n,t)=>(e,o)=>D(e,o,s=>{let r=s.attrs.cols[n];if(!r)return null;let i=t===null?null:gn(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)}}),Xr=(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)}}),Qr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!(t==="auto"||Ie.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)}}),Zr=(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=on(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"?jt(u.text):u.text,p=i==="number"?jt(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=z(null,null,l.length),d=l.map(({row:u},a)=>E.table_row.create({...u.attrs,pos:c[a]},u.content));return{table:L(s,{sort:{col:n,dir:t}},d)}}),ee=(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(At(i,v(d.at(-1).attrs.pos,null)));let f=[...d[p].content.content];a.forEach((m,g)=>{c+g<i.length&&(f[c+g]=E.table_cell.create({col:i[c+g]},ve(b,m)))}),d[p]=E.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)}}),vo=n=>new TextEncoder().encode(JSON.stringify(n.toJSON())).length;function $o(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=hn(o),r=e.getData("text/plain").replace(/\r?\n$/,""),i=ln(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 ee(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 ee(i.grid,{row:s.row,cell:s.cell})(o,n.dispatch);if(o.selection.$head.parent.type===E.table_cell)return i.width*i.height<2?!1:ee(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=Et(i.grid,{header:i.height>1});if(!l)return!1;if(vo(l)>ne)return N("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 K(o.apply(p),f=>{for(let m of f.steps)p.step(m);p.setSelection(q.create(p.doc,f.selection.from)),n.dispatch(S(p).scrollIntoView())},l)}return K(o,n.dispatch,l,u?null:{from:c,to:d})}var ti=pt.keymap({Tab:So,"Shift-Tab":To,Enter:Eo,"Mod-Enter":Co(!0)});function Io(n,t){let e=te.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(q.create(n.state.doc,o+1+(s?0:e.node.content.size)))),n.focus(),e.openDate(),!0}function ei(){return new Mo({props:{handlePaste:$o,handleDOMEvents:{mousedown:Io},handleClickOn(n,t,e,o,s,r){if(e.type!==E.table_cell||!r||s.button)return!1;let i=n.nodeDOM(o),l=i&&te.get(i);return l&&l.openDate(),!1}},appendTransaction(n,t,e){if(!n.some(r=>r.docChanged&&!r.getMeta(bt)))return null;let o=new Map;t.doc.forEach(r=>{r.type===E.table&&o.set(r.attrs.id,r)});let s=e.tr;return e.doc.forEach((r,i)=>{if(r.type!==E.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(Qt,!0):null}})}function ni(n,t,e){let o=n.state.doc.nodeAt(t);if(o?.type!==E.table_cell)return!1;let s=n.state.tr.replaceWith(t+1,t+o.nodeSize-1,e?b.text(e):[]);return n.dispatch(s.setSelection(q.create(s.doc,t+1+e.length))),!0}function oi(n,t,e,o){let s=ct(n.state.doc,t,e,o);return s===null?!1:(n.dispatch(n.state.tr.setSelection(q.create(n.state.doc,s))),!0)}var{TextSelection:Lo}=O,se=b.nodes,Do=Object.freeze(["To do","In progress","Done"]),bn=(n,t)=>H(n)&&(t===null||H(t)&&n<t)?v(n,t):null;function re(n=Do){let t=z(null,null,n.length),e=Object.fromEntries(n.map((o,s)=>[x("c"),{pos:t[s],name:o}]));return se.board.create({id:x(),columns:e,cards:{}})}function kn(n,t,e=re(),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=Q(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:bn(i[d].node.attrs.pos,a),f=se.board.create({...e.attrs,pos:p,parent:h}),m=se.paragraph.create({id:x(),pos:bn(p,a),parent:h});return r.replaceWith(u,c?i[s].end:u,[f,m]),r.setSelection(Lo.create(r.doc,u+f.nodeSize+1)),t&&t(S(r).scrollIntoView()),!0}function yn(n){let t=[];return n.forEach(e=>{e.type===b.nodes.table&&I(e.attrs.cols).length>1&&t.push(e)}),t}function pi(n,t){let e="",o=0,s=null;return n.forEach(r=>{s===null&&(r.type===b.nodes.heading&&(e=r.textContent),r.type===b.nodes.table&&(o+=1,r.attrs.id===t&&(s=e||`Table ${o}`),e=""))}),s}var xn=new Set(["blockeditor-format-unsupported","unsupported-host"]),_o="This host can't store that yet, so nothing was added.",Bo="That didn't go through. Try again.",Po="That couldn't be added here.";function Mn(n,t){let e=t?.status==="upgrade-required"&&t.message?t.message:xn.has(t?.code)||xn.has(t?.status)?_o:t?.retry===!0?Bo:Po;n.isDestroyed||(R(n,e),N(e,"error"))}async function Ot(n,t){if(typeof n.runFormatCommand!="function")return Mn(n,{code:"blockeditor-format-unsupported"}),{ok:!1,code:"blockeditor-format-unsupported"};let e=await n.runFormatCommand(t);return e?.status==="applied"?e.result:(Mn(n,e),{ok:!1,code:e?.code??e?.status??"blockeditor-format-refused",retry:e?.retry===!0})}var{TextSelection:at}=O,$=b.nodes,W=[{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"]}],Ro=[{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"}],No={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},ie=n=>(qe.get(n)?.ensure("chart")??Promise.resolve()).catch(()=>{}).then(()=>n.isDestroyed?null:import("./c-BOS7GONO.js")),It=[...W,...Ro],Sn=(n,t=It)=>yn(n.doc).length?[...t,No]:t;function Lt(n){let t=n.type.name;return W.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)))??W[0]}var le=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e};function J(n,t,e){let o=le(n.doc,t),s=n.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===$.list_item&&e.type==="list_item"&&(r.indent=s.attrs.indent),n.setBlockType(o+1,o+s.nodeSize-1,$[e.type],{...r,...e.attrs||{}})}var Tn=Object.freeze({status:"refused",code:"unsupported-format"}),Ho=Ae([]).type,zo=n=>{let t=!1;return n.forEach(e=>{!t&&e.marks.some(Ce)&&(t=!0)}),t};function tt(n,t){return!n.isTextblock||n.type===$.opaque_block?!1:!zo(n)||$[t.type].allowsMarkType(Ho)}var En=n=>n.type==="toggle"&&n.attrs?.level!=null,vt=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e},ce={ok:!1,code:"stale-target"};function Cn(n,t,e){let o=()=>e.map(r=>vt(n.state.doc,r)),s=()=>{let r=o();if(r.includes(-1))return ce;if(r.some(l=>!tt(n.state.doc.child(l),t)))return Tn;let i=n.state.tr;for(let l of r)J(i,l,t);return n.dispatch(S(i).scrollIntoView()),n.focus(),{ok:!0}};return En(t)?Ot(n,s):t.type==="quote"?import("./c-3S3647J6.js").then(r=>n.isDestroyed?!1:r.gateTurn(n,s)):s()}function An(n,t,e=n.tr){let o=Q(e.doc),{to:s}=Ue(o,t),r=e.doc.child(t);return e.insert(s,$.paragraph.create({parent:r.attrs.parent??null})),e.setSelection(at.create(e.doc,s+1))}var Z=(n,t)=>H(n)&&(t===null||H(t)&&n<t)?v(n,t):null;function ae(n,t){let e=le(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,[$.divider.create({id:r,pos:i,parent:l}),$.paragraph.create({id:x(),pos:Z(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(at.create(n.doc,e+2))}function Fo(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===$.paragraph&&o.content.size===0)return ae(e,t);let s=Q(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=Z(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[$.divider.create({id:x(),pos:c,parent:d}),$.paragraph.create({id:x(),pos:Z(c,l),parent:d})]),e.setSelection(at.create(e.doc,i+2))}function Ko(n,t){let e=le(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,[$.toc.create({id:r,pos:i,parent:l,maxLevel:3}),$.paragraph.create({id:x(),pos:Z(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(at.create(n.doc,e+2))}function Vo(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===$.paragraph&&o.content.size===0)return Ko(e,t);let s=Q(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=Z(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[$.toc.create({id:x(),pos:c,parent:d,maxLevel:3}),$.paragraph.create({id:x(),pos:Z(c,l),parent:d})]),e.setSelection(at.create(e.doc,i+2))}function jo(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 On(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=>jo(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 wn(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&&!tt(i,t)?Tn:(t.insert==="divider"?r=Fo(s,e,r):i.isTextblock&&i.content.size===0?r=J(r,e,t):(r=An(s,e,r),r=J(r,r.doc.resolve(r.selection.head).index(0),t)),n.dispatch(S(r).scrollIntoView()),n.focus(),!0)}function qo(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 Ot(n,()=>{let i=n.state;if((s===null?-1:vt(i.doc,s))<0||r&&i.doc.textBetween(r.from,r.to)!==r.text)return ce;let c=r?i.tr.delete(r.from,r.to):i.tr;return c=Vo(i,vt(c.doc,s),c),n.dispatch(S(c).scrollIntoView()),n.focus(),{ok:!0}})}var et=(n,t,e)=>import("./page/editor-UF3CIA6V.js").then(({runPageCommand:o})=>n.isDestroyed?{ok:!1,code:"not-editing"}:o(n,t,e));function Wo(n,t,e){return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),et(n,t,{})}function vn(n,t,e,o=null){let s=n.state;if(t.insert==="image"||t.insert==="file")return je(n,t.insert==="image"?"image/*":"",Ve(s,e),o);if(t.insert==="csv")return $t(n,o);if(t.insert==="table")return K(s,n.dispatch,fn(),o,null,e);if(t.insert==="board")return kn(s,n.dispatch,re(),o,e);if(t.insert==="chart")return ie(n).then(l=>l&&!n.isDestroyed?l.chartFromSlash(n,e,o):!1);if(t.insert==="toc")return qo(n,e,o);if(t.command)return Wo(n,t.command,o);if(!En(t)&&t.type!=="quote")return wn(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 Ot(n,()=>{let l=n.state,c=r===null?-1:vt(l.doc,r);return c<0||i&&l.doc.textBetween(i.from,i.to)!==i.text?ce:wn(n,t,c,i)})}var{InputRule:he}=Vt,U=b.nodes,Dt=(n,t,e)=>n.doc.rangeHasMark(t,e,b.marks.code)||!!b.marks.code.isInSet(n.storedMarks||n.selection.$from.marks()),nt=(n,t,e=["paragraph"],o=!1)=>new he(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()||Dt(s,i,l)?null:S(J(s.tr.delete(i,l),c.index(0),typeof t=="function"?t(r):t))}),Uo=new he(/^---$/,(n,t,e,o)=>{let s=n.doc.resolve(e);return!n.selection.empty||s.depth!==1||s.parent.type!==U.paragraph||s.parentOffset!==0||s.parent.content.size!==o-e||Dt(n,e,o)?null:S(ae(n.tr,s.index(0)))}),pe=`\\s\\(\\[\\{'\u2018\u201C"`,Go=new RegExp(`[${pe}]`),ue=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),$n=n=>`([^\\s${n}](?:[\\s\\S]*?[^\\s${n}])?)`,_t=(n,t)=>!!n?.isComposing||n?.keyCode===229||!!t?.composing,In=n=>{let t=0;for(let e=n.length-1;e>=0&&n[e]==="\\";e--)t++;return t},Yo=(n,t)=>{let e=n.doc.resolve(t);return!e.parent.inlineContent||In(e.parent.textBetween(0,e.parentOffset,null,"\uFFFC"))%2?!1:e.parentOffset===0||Go.test(e.parent.textBetween(e.parentOffset-1,e.parentOffset))},Jo=(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(Dt(n,e,o))return null;let h=c.slice(d.length,c.length-u.length-a.length),p=e+d.length;if(!Yo(n,p)||In(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 g=p+h.length,k=g+u.length;return m.delete(k,e+c.length),m.delete(p,g),m.addMark(p,p+u.length,r),m.removeStoredMark(r.type),S(m)},Ln=(n,t)=>new he(n,(e,o,s,r)=>Jo(e,o,s,r,t),{inCodeMark:!1}),ot=(n,t,e)=>Ln(new RegExp(`(^|[${pe}])${ue(n)}${$n(ue(t))}(${ue(t)})$`),()=>e.create()),Xo=Ln(new RegExp(`(^|[${pe}])\\[${$n("\\[\\]")}(\\]\\([^()\\s]*\\))$`),n=>{let t=Te(n[3].slice(2,-1));return t?b.marks.link.create({href:t}):null}),Qo=[ot("**","**",b.marks.strong),ot("__","__",b.marks.strong),ot("*","*",b.marks.em),ot("_","_",b.marks.em),ot("`","`",b.marks.code),ot("~~","~~",b.marks.strike),Xo],de=["paragraph","list_item"],Zo=[nt(/^(#{1,3})\s$/,n=>({type:"heading",attrs:{level:n[1].length}})),nt(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},de),nt(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},de),nt(/^\[( |x|X)?\]\s$/,n=>({type:"list_item",attrs:{kind:"check",checked:!!n[1]&&n[1]!==" "}}),de),nt(/^>\s$/,{type:"toggle",attrs:{open:!0}}),nt(/^```$/,{type:"code_block"},["paragraph"],!0),Uo,...Qo];function ts(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!==U.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-3S3647J6.js").then(({quoteFromSpace:u})=>u(n,t,{at:d,from:e,to:o},c),c),!0}var Hi=()=>{let n=Vt.inputRules({rules:Zo}),t=n.props.handleTextInput;return n.props.handleTextInput=(e,o,s,r)=>ts(n,e,o,s,r)||t(e,o,s,r),n},es=/^\s*\|(.*)\|\s*$/;function ns(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parent.type!==U.paragraph||e.parentOffset!==e.parent.content.size||Dt(n,e.start(),e.end()))return!1;let s=es.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=Et([r,r.map(()=>"")],{header:!0});return K(n,t,i,{from:e.start(),to:e.end()})}var zi=()=>pt.keymap({Enter:(n,t,e)=>!_t(null,e)&&ns(n,t)});function Fi(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===U.heading||s.type===U.callout||s.type===U.quote||s.type===U.code_block&&s.content.size===0?(t&&t(S(n.tr.setNodeMarkup(e.before(),U.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:Rn,PluginKey:Nn,TextSelection:Rt,NodeSelection:os}=O,Hn=b.marks,G=b.nodes,Pt=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",zn=n=>{let t=xt(n.doc),{lo:e,hi:o}=n.selection.span(n.doc);return t.slice(e,o+1).filter(s=>s.up===t[e].up)},Bt=(n,t)=>n.state.doc.child(t).attrs.id,ss=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e},Dn=["aria-haspopup","aria-controls","aria-activedescendant"],rs="That block is no longer available.",ke="This block holds content from a newer version, so it can't be converted here.";function fe(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 is(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 ls(n,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(n)}`}function cs(n){if(!n)return;let t=()=>N("Link copied"),e=()=>N("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){e();return}globalThis.navigator.clipboard.writeText(ls(n)).then(t,e)}var Fn=[{key:"up",label:"Move up",icon:"up",hint:`${Pt}\u21E7\u2191`,run:n=>qt(-1)(n.state,n.dispatch)},{key:"down",label:"Move down",icon:"down",hint:`${Pt}\u21E7\u2193`,run:n=>qt(1)(n.state,n.dispatch)},{key:"indent",label:"Indent",icon:"indent",hint:"Tab",run:n=>{let t=n.state.doc;Ye(n.state,n.dispatch),n.state.doc===t&&(R(n,"Indent works on list items and inside toggles."),N("Indent works on list items and inside toggles."))}},{key:"outdent",label:"Outdent",icon:"outdent",hint:"\u21E7Tab",run:n=>Je(n.state,n.dispatch)},{key:"duplicate",label:"Duplicate",icon:"duplicate",hint:`${Pt}D`,run:n=>tn(n.state,n.dispatch)},{key:"delete",label:"Delete",icon:"trash",hint:"Del",run:n=>Ut(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)=>cs(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=Bt(n,e);return import("./c-5ELELG2F.js").then(s=>s.openAltEditor(n,o))}},{key:"small",label:"Small",icon:"small",only:"image",run:(n,t,e)=>{let o=Bt(n,e);return import("./c-5ELELG2F.js").then(s=>s.setImageAttrs(n,o,{width:240}))}},{key:"medium",label:"Medium",icon:"medium",only:"image",run:(n,t,e)=>{let o=Bt(n,e);return import("./c-5ELELG2F.js").then(s=>s.setImageAttrs(n,o,{width:480}))}},{key:"full",label:"Full width",icon:"full",only:"image",run:(n,t,e)=>{let o=Bt(n,e);return import("./c-5ELELG2F.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=ss(n.state.doc,e);return ie(n).then(({insertChartAfterTable:s})=>s(n,o))}},{key:"csv",label:"Import CSV\u2026",icon:"csv",only:"table",focus:!1,run:(n,t,e)=>$t(n,null,n.state.doc.child(e).attrs.id)}],as=n=>{if(!(n.selection instanceof F))return[];let t=zn(n),e=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===G.image,s=t.length===1&&t[0].node.type===G.table;return Fn.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>`,V={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"/>')},me=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],Kn=new Set(["strong","em","link"]),us=new Set(["up","down","indent","outdent"]),ds=204,hs=52,_=8,Vn=new Set(["bullet","ordered","check"]),ps=[["assignees","Checklist assignees"],["dates","Checklist due dates"]],fs=new Set(["paragraph","heading","list_item"]),ut=n=>{let t=n.selection;if(t instanceof F)return zn(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},jn=n=>ut(n).filter(t=>{let e=n.doc.child(t);return e.isTextblock&&e.type!==G.code_block}),qn=(n,t)=>n.type===G.list_item&&n.attrs.kind===t,Wn=(n,t)=>{let e=jn(n);return e.length>0&&e.every(o=>qn(n.doc.child(o),t))},ms=n=>{let t="";return n.forEach(e=>{t+=e.isText?e.text:e.type===G.hard_break?`
|
|
3
|
+
`:""}),t};function gs(n){let{$from:t,$to:e,empty:o}=n.selection;if(o||!(n.selection instanceof Rt)||t.depth!==1||e.depth!==1||t.parentOffset!==0||e.parentOffset!==e.parent.content.size)return null;let s=ut(n);return s.every(r=>fs.has(n.doc.child(r).type.name))?s:null}function bs(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=>ms(n.doc.child(u))).join(`
|
|
4
|
+
`),{id:i,pos:l,parent:c}=e.attrs,d=n.tr.replaceWith(o,s,G.code_block.create({id:i,pos:l,parent:c},r?b.text(r):null));return d.setSelection(Rt.create(d.doc,o+1,o+1+r.length))}function ks(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)=>G.paragraph.create(p===0?{id:c,pos:d,parent:u}:{parent:u},h?b.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(Rt.create(e.doc,o+1,s-1))}var Un=n=>{let t=ut(n);return t.length>0&&t.every(e=>n.doc.child(e).type===G.code_block)?t:null};function _n(n,t){if(Vn.has(t))return Wn(n,t);if(t==="code"&&Un(n))return!0;let e=Hn[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 ys(n,t){let e=n.state,o=Wn(e,t),s=W.find(l=>l.key===(o?"text":t)),r=jn(e).filter(l=>o||!qn(e.doc.child(l),t));if(r.some(l=>!tt(e.doc.child(l),s))){R(n,ke);return}let i=e.tr;for(let l of r)J(i,l,s);i.docChanged&&n.dispatch(S(i))}var ge=(n,t,e)=>import("./c-3S3647J6.js").then(o=>o.nativeMenu(n,e,t.pickedFrom??t.more));function Bn(n,t){if(t==="link")return Fe(n);let e=n.state,o=t==="code"?Un(e):null,s=t==="code"&&!o?gs(e):null;Vn.has(t)?ys(n,t):o?n.dispatch(S(ks(e,o)).scrollIntoView()):s&&s.some(r=>!tt(e.doc.child(r),W.find(i=>i.key==="code")))?R(n,ke):s?n.dispatch(S(bs(e,s)).scrollIntoView()):Se.toggleMark(Hn[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 Pn(n,t){let e=y("button",`blockeditor-tool${Kn.has(n)?" blockeditor-tool-primary":" blockeditor-tool-desk"}`,{type:"button","data-cmd":n,"aria-label":t,title:t});return e.innerHTML=V[n],e}var xs=1600,Ms=0,ws=new Nn("blockeditor-chrome"),ye=new WeakMap,Nt=new Nn("blockeditor-slash-range"),Ss={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(Nt);return o!==void 0&&(e=o),e}},il=()=>new Rn({key:Nt,state:Ss}),Gn=(n,t)=>{let e=t?n.state.doc.textBetween(t.from,t.to):null;n.dispatch(n.state.tr.setMeta(Nt,t?{...t,text:e}:null))},Yn=n=>{let t=Nt.getState(n);return t?{from:t.from,to:t.to}:null};function ll(n,t,e,{persist:o=!1}={}){let s=ye.get(n);return s?(s.openMenu("external",t),s.menu.externalItems=e,s.menu.persist=o,s.renderMenu(),!0):!1}function cl(n,t,e){let o=ye.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 be=class{constructor(t,e,o){this.view=t,this.onAiTool=e,this.mediaNote=o,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","blockeditor-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=y("button","blockeditor-tool blockeditor-tool-turn blockeditor-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=y("button","blockeditor-tool blockeditor-tool-primary blockeditor-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=V.more,this.settingsBtn=y("button","blockeditor-tool blockeditor-tool-desk blockeditor-tool-settings",{type:"button","aria-label":"Document settings",title:"Document settings","aria-haspopup":"dialog","aria-expanded":"false"}),this.settingsBtn.innerHTML=V.gear,this.settingsEl=null,this.settingsOpen=!1,this.settingsAnchor=null,this.settingSwitches={},this.dock.append(this.turn,y("span","blockeditor-tool-sep blockeditor-tool-desk"),...me.map(([i,l])=>Pn(i,l)),this.more),this.dock.insertBefore(this.settingsBtn,this.more),this.settingsBtn.hidden=!this.settingsAPI,this.plus=y("button","blockeditor-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=V.plus,this.grip=y("button","blockeditor-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=V.grip,this.bubble=y("div","blockeditor-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubbleTurn=y("button","blockeditor-tool blockeditor-tool-turn",{type:"button","aria-haspopup":"menu"}),this.bubbleMore=y("button","blockeditor-tool blockeditor-tool-primary blockeditor-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.bubbleMore.innerHTML=V.more,this.bubble.append(this.bubbleTurn,y("span","blockeditor-tool-sep"),...me.map(([i,l])=>Pn(i,l)),this.bubbleMore),this.menuId=`blockeditor-menu-${++Ms}`,this.menuEl=y("div","blockeditor-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=y("div","blockeditor-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let s=i=>i.preventDefault();for(let i of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])i.addEventListener("mousedown",s);for(let i of[this.dock,this.bubble])i.addEventListener("click",l=>{let c=l.target.closest("[data-cmd]");c&&Bn(this.view,c.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",i=>this.dockKey(i)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",i=>{i.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Ke(t,this.grip,{index:()=>this.gutterIndex(),onClick:i=>this.gripAction(i)});let r=!1;this.scrim.addEventListener("pointerdown",()=>{r=!0}),this.scrim.addEventListener("click",()=>{r&&this.closeMenu(),r=!1}),this.menuEl.addEventListener("click",i=>{let l=i.target.closest(".blockeditor-menu-item");l&&this.pick(Number(l.dataset.index))}),this.menuEl.addEventListener("keydown",i=>{this.key(i)&&i.preventDefault()}),this.onMove=i=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),xs),this.trackHover(i)},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=i=>{this.settingsOpen&&![this.settingsEl,this.settingsAnchor].some(l=>l?.contains(i.target))&&this.closeSettings(),this.menu&&([this.menuEl,this.plus,this.grip,this.turn,this.bubbleTurn,this.bubbleMore].some(l=>l.contains(i.target))||this.closeMenu())},this.onSettingsKey=i=>{i.key!=="Escape"||!this.settingsOpen||(i.preventDefault(),i.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 F||e instanceof os?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("blockeditor-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("blockeditor-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 ut(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 F)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(Wt(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=xt(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","blockeditor-settings",{role:"dialog","aria-label":"Document settings",hidden:""}),e=y("div","blockeditor-settings-head"),o=y("span","blockeditor-settings-title");o.textContent="Document settings";let s=y("button","blockeditor-settings-close",{type:"button","aria-label":"Close settings"});s.innerHTML=V.close,s.addEventListener("click",()=>this.closeSettings(!0)),e.append(o,s);let r=ps.map(([l,c])=>{let d=y("div","blockeditor-settings-row"),u=y("span","blockeditor-settings-name",{id:`${this.menuId}-set-${l}`});u.textContent=c;let a=y("button","blockeditor-settings-switch",{type:"button",role:"switch","aria-checked":"true","aria-labelledby":u.id,"data-setting":l});return a.append(y("span","blockeditor-settings-knob")),a.addEventListener("click",()=>this.flipSetting(l)),this.settingSwitches[l]=a,d.append(u,a),d}),i=y("div","blockeditor-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)),N("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(".blockeditor-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=fe(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("--blockeditor-pop-x",`${d}px`),t.style.setProperty("--blockeditor-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("--blockeditor-pop-x",`${i}px`),t.style.setProperty("--blockeditor-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=Dn.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 Dn)this.view.dom.removeAttribute(t)}moreItems(){let t=this.isPhone(),e=t?me.filter(([s])=>!Kn.has(s)).map(([s,r])=>({key:s,label:r,icon:s,run:i=>Bn(i,s)})):[],o=Fn.filter(s=>us.has(s.key)).map(s=>({...s,blocks:!0}));return[...e,{key:"underline",label:"Underline",icon:"U",hint:`${Pt}u`,run:(s,r)=>ge(s,r,"underline")},{key:"text_color",label:"Text color",icon:"A",hint:"\u203A",run:(s,r)=>ge(s,r,"text_color")},{key:"highlight",label:"Highlight",icon:"\u25A0",hint:"\u203A",run:(s,r)=>ge(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=>et(s,"titleIcon")},...this.mediaNote?[]:[{key:"titleCover",label:"Add cover",icon:"\u25A4",run:s=>et(s,"titleCover")}],{key:"exportHtml",label:"Export reading copy",icon:"\u21E9",run:s=>et(s,"exportHtml")},{key:"exportMarkdown",label:"Export as Markdown",icon:"M\u21E9",run:s=>et(s,"exportMarkdown")}]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return as(this.view.state);if(t.mode==="more")return this.moreItems();let e=this.onAiTool?[...It,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:It,o=this.mediaNote?e.filter(r=>r.key!=="image"&&r.key!=="file"):e,s=t.mode==="turn"?W:Sn(this.view.state,o);return On(s,t.query)}currentTypes(){let t=this.view.state;return new Set(ut(t).map(e=>Lt(t.doc.child(e)).key))}openActions(t=this.plus,e=null){let o=this.view.state,s=xt(o.doc),r=o.selection,i=e!==null&&r instanceof F&&r.span(o.doc).lo<=e&&e<=r.span(o.doc).hi,{lo:l,hi:c}=e===null||i?Ze(o,s):Ge(s,e,e);this.view.dispatch(o.tr.setSelection(Wt(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","blockeditor-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","blockeditor-menu-empty");r.textContent="No matching blocks",s.push(r)}if(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",`blockeditor-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","blockeditor-menu-icon");V[r.icon]?a.innerHTML=V[r.icon]:a.textContent=r.icon||"";let h=y("span","blockeditor-menu-label");if(h.textContent=r.label,r.description){let p=y("span","blockeditor-menu-text"),f=y("span","blockeditor-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","blockeditor-menu-hint");p.textContent=r.hint,u.append(p)}s.push(u)}),this.mediaNote&&t.mode!=="turn"&&t.mode!=="actions"&&t.mode!=="more"&&t.mode!=="external"){let r=y("div","blockeditor-menu-note",{role:"note"});r.textContent=this.mediaNote,s.push(r)}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"){R(this.view,rs),this.view.focus();return}if(e.mode==="turn"){if(i.some(d=>!tt(s.doc.child(this.idIndex(d)),o))){R(this.view,ke),this.view.focus();return}Cn(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):vn(this.view,o,c>=0?c:this.blockIndex(),r)}key(t){if(_t(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 F&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&e.mode==="actions"&&this.view.state.selection instanceof F)return this.closeMenu(),this.view.focus(),Ut(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","blockeditor-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let e=fe(this.win),o=Math.max(0,e.height-_*2),s=Math.min(280,Math.max(0,e.width-_*2)),r=this.menuEl.style.getPropertyValue("--blockeditor-pop-max");this.menuEl.style.removeProperty("--blockeditor-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--blockeditor-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=fe(this.win),h=this.dock.offsetHeight||hs;c.bar={...is(a,this.dock.offsetWidth||ds,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("--blockeditor-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("--blockeditor-grip-lift")}if(t.gutter)for(let e of[this.plus,this.grip])e.style.setProperty("--blockeditor-plus-top",`${t.gutter.top}px`),e.style.setProperty("--blockeditor-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--blockeditor-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--blockeditor-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--blockeditor-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--blockeditor-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--blockeditor-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--blockeditor-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--blockeditor-pop-max",`${t.menu.maxHeight}px`)))}get settingsAPI(){return globalThis.clay?.blockeditor?.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=`${Lt(r).label} \u25BE`,this.bubbleTurn.textContent=this.turn.textContent;for(let c of this.dock.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(_n(s,c.dataset.cmd)));let l=!!this.menu&&[this.bubbleTurn,this.bubbleMore].includes(this.menu.anchor)||!s.selection.empty&&s.selection instanceof Rt&&t.hasFocus();if(this.bubble.hidden=!l,l)for(let c of this.bubble.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(_n(s,c.dataset.cmd)));if(this.grip.classList.toggle("is-on",s.selection instanceof F),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 al({onAiTool:n=null,mediaNote:t=null}={}){let e=null;return new Rn({key:ws,view(o){return e=new be(o,n,t),ye.set(o,e),e},filterTransaction(o){return e&&o.docChanged&&(e.remote=!!o.getMeta(Oe)),!0},props:{handleKeyDown(o,s){return e?s.key==="/"&&(s.metaKey||s.ctrlKey)&&!s.altKey&&!e.menu?(s.preventDefault(),e.openActions(),!0):e.key(s):!1},handleTextInput(o,s,r,i){if(i!=="/"||!e)return!1;let l=en(o,i);l&&(s=o.state.selection.from-1);let c=o.state.doc.resolve(s);if(c.depth!==1||!c.parent.isTextblock||c.parent.type.spec.code||c.parentOffset>0&&!/\s/.test(o.state.doc.textBetween(s-1,s,"",`
|
|
6
|
+
`)))return l;l||o.dispatch(o.state.tr.insertText("/",s,r).setMeta(Tt,Xt(o.state,s,r,"/")));let d=Math.min(o.state.doc.resolve(s).index(0),o.state.doc.childCount-1);return e.openMenu("insert",e.plus,s+1,null,o.state.doc.child(d).attrs.id),!0},handleDOMEvents:{keydown(o,s){return _t(s,o)},blur(o){return e&&!(e.menu&&[e.bubbleTurn,e.bubbleMore].includes(e.menu.anchor))&&(e.bubble.hidden=!0),!1}}}})}var{Plugin:Ts}=O,Me=new WeakMap,Es=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 Ht(n,t){let e=n.dom.ownerDocument,o=n.dom.parentElement.querySelector(".blockeditor-csv-error");o||(o=e.createElement("div"),o.className="blockeditor-csv-error",o.setAttribute("role","alert"),n.dom.parentElement.append(o)),o.textContent=t}function Cs(n){let t=0,e=De(n,{maxBytes:ne,newId:()=>x(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[x("r")]={pos:v(),cells:o}}return{node:X(b,x(),{t:"table",pos:null,cols:e.cols,rows:e.rows}),truncated:e.truncated}}async function As({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-47M4QHCK.js")).consent,s=(await import("./c-J2YYLEVM.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 Os=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{e<0&&o.type===b.nodes.table&&o.attrs.id===t&&(e=r)}),e},vs=n=>{let t=!0;return n.descendants(e=>(e.isText&&(t=!1),t)),t};function $s(n,t,e,o){let s=n.state,r=Os(s.doc,e);if(r<0)return K(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(!vs(l)||o){let u=s.doc.maybeChild(r+1),a=l.attrs.parent??null,h=v(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:v(h,u?.attrs.pos??null),parent:a},o.content)),m.setSelection(O.TextSelection.create(m.doc,f+3)),n.dispatch(S(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(O.TextSelection.create(d.doc,i+3)),n.dispatch(S(d).scrollIntoView()),!0}async function xe(n,t,{upload:e,remove:o=null,table:s=null}={}){try{n.dom.parentElement.querySelector(".blockeditor-csv-error")?.remove();let r=gt(await Es(t)),i=Cs(r);if(!i)return Ht(n,"Couldn't read this CSV: no columns."),!1;let l=null;if(i.truncated){if(!await As(i.truncated))return!1;let u=await e?.(t),a=Ee(u?.uploads?.[0]?.url);if(!u?.ok||!a)return Ht(n,"Couldn't attach the original CSV."),!1;l=b.nodes.file.create({id:x(),src:a,name:t.name,size:t.size??null,mime:t.type||"text/csv"})}if(n.isDestroyed)return!1;if(s)return $s(n,i.node,s,l);let c=o?Yn(n.state):null;return o&&!c&&Ls(n,o.block),K(n.state,n.dispatch,i.node,c,l)}catch(r){return r instanceof $e?Ht(n,`Couldn't read this CSV: unclosed quote on line ${r.line}.`):Ht(n,"Couldn't read this CSV."),!1}}function $t(n,t=null,e=null){let o=Me.get(n);return o?(t&&Gn(n,t),o._remove=t?{...t,block:Is(n.state.doc,t.from)}:null,o._table=e,o.click(),!0):!1}var Is=(n,t)=>n.child(n.resolve(Math.max(0,Math.min(t,n.content.size))).index(0)).attrs.id;function Ls(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(O.TextSelection.near(e.doc.resolve(o)))),!0)}var Jn=n=>[...n].filter(t=>/\.csv$/i.test(t.name||"")||/^(text\/csv|application\/csv)$/i.test(t.type||""));function xl({upload:n}){return new Ts({view(t){let e=t.dom.ownerDocument.createElement("input");return e.type="file",e.accept=".csv,text/csv",e.hidden=!0,e.className="blockeditor-csv-input",t.dom.parentElement.append(e),Me.set(t,e),e.addEventListener("change",()=>{let o=e.files?.[0];o&&xe(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=Jn(e.clipboardData?.files||[]);return o.length?(e.preventDefault(),xe(t,o[0],{upload:n}),!0):!1},handleDrop(t,e,o,s){let r=Jn(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(O.TextSelection.near(t.state.doc.resolve(i.pos)))),xe(t,r[0],{upload:n}),!0}}})}export{qs as a,er as b,on as c,Ps as d,Rs as e,xl as f,yn as g,pi as h,Ot as i,_t as j,Hi as k,zi as l,Fi as m,Er as n,Cr as o,rr as p,ir as q,lr as r,cr as s,ie as t,il as u,Gn as v,Yn as w,ll as x,cl as y,al as z,te as A,Co as B,Kr as C,Vr as D,jr as E,qr as F,Wr as G,Ao as H,Oo as I,Ur as J,Gr as K,Yr as L,Jr as M,Xr as N,Qr as O,Zr as P,ti as Q,ei as R,ni as S,oi as T};
|
|
@@ -2,4 +2,4 @@ var As=Object.defineProperty,xs=(t,e,r)=>e in t?As(t,e,{enumerable:!0,configurab
|
|
|
2
2
|
`)}},Me=(t,e)=>t===e?!0:t==null||e==null||t.constructor!==e.constructor?!1:t[Dt]?on(t,e):ut(t)?Xe(t,r=>qe(e,n=>Me(r,n))):pi(t)?Tt(t,(r,n)=>Me(r,e[n])):!1,I=class{extends(t){let[e,r]=[this.shape,t.shape];return this.constructor._dilutes&&([r,e]=[e,r]),Me(e,r)}equals(t){return this.constructor===t.constructor&&Bt(this.shape,t.shape)}[Vi](){return!0}[Dt](t){return this.equals(t)}validate(t){return this.check(t)}check(t,e){P()}get nullable(){return mt(this,de)}get optional(){return new pn(this)}cast(t){return Lr(t,this),t}expect(t){return Lr(t,this),t}};Ge(I,"_dilutes",!1);var sr=class extends I{constructor(t,e){super(),this.shape=t,this._c=e}check(t,e=void 0){let r=t?.constructor===this.shape&&(this._c==null||this._c(t));return!r&&e?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},S=(t,e=null)=>new sr(t,e),oc=S(sr),ir=class extends I{constructor(t){super(),this.shape=t}check(t,e){let r=this.shape(t);return!r&&e?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),r}},D=t=>new ir(t),cc=S(ir),ce=class extends I{constructor(t){super(),this.shape=t}check(t,e){let r=this.shape.some(n=>n===t);return!r&&e?.extend(null,this.shape.join(" | "),t.toString()),r}},ae=(...t)=>new ce(t),gn=S(ce),Pi=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),fn=t=>{if(ft.check(t))return[Pi(t)];if(gn.check(t))return t.shape.map(e=>e+"");if(xn.check(t))return["[+-]?\\d+.?\\d*"];if(In.check(t))return[".*"];if(Xt.check(t))return t.shape.map(fn).flat(1);O()},ji=class extends I{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(fn).map(e=>`(${e.join("|")})`).join("")+"$")}check(t,e){let r=this._r.exec(t)!=null;return!r&&e?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),r}},ac=S(ji),zi=Symbol("optional"),pn=class extends I{constructor(t){super(),this.shape=t}check(t,e){let r=t===void 0||this.shape.check(t);return!r&&e?.extend(null,"undefined (optional)","()"),r}get[zi](){return!0}},Ji=S(pn),wn=class extends I{check(t,e){return e?.extend(null,"never",typeof t),!1}},hc=new wn,uc=S(wn),mn=class kn extends I{constructor(e,r=!1){super(),this.shape=e,this._isPartial=r}get partial(){return new kn(this.shape,!0)}check(e,r){return e==null?(r?.extend(null,"object","null"),!1):Tt(this.shape,(n,s)=>{let i=this._isPartial&&!er(e,s)||n.check(e[s],r);return!i&&r?.extend(s.toString(),n.toString(),typeof e[s],"Object property does not match"),i})}};Ge(mn,"_dilutes",!0);var yn=mn,$i=t=>new yn(t),Bi=S(yn),Wi=D(t=>t!=null&&(t.constructor===Object||t.constructor==null)),bn=class extends I{constructor(t,e){super(),this.shape={keys:t,values:e}}check(t,e){return t!=null&&Tt(t,(r,n)=>{let s=this.shape.keys.check(n,e);return!s&&e?.extend(n+"","Record",typeof t,s?"Key doesn't match schema":"Value doesn't match value"),s&&this.shape.values.check(r,e)})}},_n=(t,e)=>new bn(t,e),Yi=S(bn),vn=class extends I{constructor(t){super(),this.shape=t}check(t,e){return t!=null&&Tt(this.shape,(r,n)=>{let s=r.check(t[n],e);return!s&&e?.extend(n.toString(),"Tuple",typeof r),s})}},Ki=(...t)=>new vn(t),dc=S(vn),Sn=class extends I{constructor(t){super(),this.shape=t.length===1?t[0]:new he(t)}check(t,e){let r=ut(t)&&Xe(t,n=>this.shape.check(n));return!r&&e?.extend(null,"Array",""),r}},En=(...t)=>new Sn(t),Hi=S(Sn),Gi=D(t=>ut(t)),Cn=class extends I{constructor(t,e){super(),this.shape=t,this._c=e}check(t,e){let r=t instanceof this.shape&&(this._c==null||this._c(t));return!r&&e?.extend(null,this.shape.name,t?.constructor.name),r}},Xi=(t,e=null)=>new Cn(t,e),gc=S(Cn),qi=Xi(I),Qi=class extends I{constructor(t){super(),this.len=t.length-1,this.args=Ki(...t.slice(-1)),this.res=t[this.len]}check(t,e){let r=t.constructor===Function&&t.length<=this.len;return!r&&e?.extend(null,"function",typeof t),r}},Zi=S(Qi),tl=D(t=>typeof t=="function"),el=class extends I{constructor(t){super(),this.shape=t}check(t,e){let r=Xe(this.shape,n=>n.check(t,e));return!r&&e?.extend(null,"Intersectinon",typeof t),r}},fc=S(el,t=>t.shape.length>0),he=class extends I{constructor(t){super(),this.shape=t}check(t,e){let r=qe(this.shape,n=>n.check(t,e));return e?.extend(null,"Union",typeof t),r}};Ge(he,"_dilutes",!0);var mt=(...t)=>t.findIndex(e=>Xt.check(e))>=0?mt(...t.map(e=>At(e)).map(e=>Xt.check(e)?e.shape:[e]).flat(1)):t.length===1?t[0]:new he(t),Xt=S(he),Dn=()=>!0,qt=D(Dn),rl=S(ir,t=>t.shape===Dn),lr=D(t=>typeof t=="bigint"),nl=D(t=>t===lr),An=D(t=>typeof t=="symbol"),pc=D(t=>t===An),ot=D(t=>typeof t=="number"),xn=D(t=>t===ot),ft=D(t=>typeof t=="string"),In=D(t=>t===ft),ue=D(t=>typeof t=="boolean"),sl=D(t=>t===ue),Un=ae(void 0),wc=S(ce,t=>t.shape.length===1&&t.shape[0]===void 0),mc=ae(void 0),de=ae(null),il=S(ce,t=>t.shape.length===1&&t.shape[0]===null),kc=S(Uint8Array),yc=S(sr,t=>t.shape===Uint8Array),ll=mt(ot,ft,de,Un,lr,ue,An),bc=(()=>{let t=En(qt),e=_n(ft,qt),r=mt(ot,ft,de,ue,t,e);return t.shape=r,e.shape.values=r,r})(),At=t=>{if(qi.check(t))return t;if(Wi.check(t)){let e={};for(let r in t)e[r]=At(t[r]);return $i(e)}else{if(Gi.check(t))return mt(...t.map(At));if(ll.check(t))return ae(t);if(tl.check(t))return S(t)}O()},Lr=Di?()=>{}:(t,e)=>{let r=new Fi;if(!e.check(t,r))throw J(`Expected value to be of type ${e.constructor.name}.
|
|
3
3
|
${r.toString()}`)},ol=class{constructor(t){this.patterns=[],this.$state=t}if(t,e){return this.patterns.push({if:At(t),h:e}),this}else(t){return this.if(qt,t)}done(){return(t,e)=>{for(let r=0;r<this.patterns.length;r++){let n=this.patterns[r];if(n.if.check(t))return n.h(t,e)}throw J("Unhandled pattern")}}},cl=t=>new ol(t),On=cl(qt).if(xn,(t,e)=>Ee(e,Cr,Kt)).if(In,(t,e)=>Ri(e)).if(sl,(t,e)=>Nr(e)).if(nl,(t,e)=>BigInt(Ee(e,Cr,Kt))).if(Xt,(t,e)=>it(e,Ce(e,t.shape))).if(Bi,(t,e)=>{let r={};for(let n in t.shape){let s=t.shape[n];if(Ji.check(s)){if(Nr(e))continue;s=s.shape}r[n]=On(s,e)}return r}).if(Hi,(t,e)=>{let r=[],n=dn(e,0,42);for(let s=0;s<n;s++)r.push(it(e,t.shape));return r}).if(gn,(t,e)=>Ce(e,t.shape)).if(il,(t,e)=>null).if(Zi,(t,e)=>{let r=it(e,t.res);return()=>r}).if(rl,(t,e)=>it(e,Ce(e,[ot,ft,de,Un,lr,ue,En(ot),_n(mt("a","b","c"),ot)]))).if(Yi,(t,e)=>{let r={},n=Ee(e,0,3);for(let s=0;s<n;s++){let i=it(e,t.shape.keys),l=it(e,t.shape.values);r[i]=l}return r}).done(),it=(t,e)=>On(At(e),t),st=typeof document<"u"?document:{},_c=D(t=>t.nodeType===gl),vc=typeof DOMParser<"u"?new DOMParser:null,Sc=D(t=>t.nodeType===hl),Ec=D(t=>t.nodeType===ul),al=t=>Is(t,(e,r)=>`${r}:${e};`).join(""),hl=st.ELEMENT_NODE,ul=st.TEXT_NODE,Cc=st.CDATA_SECTION_NODE,Dc=st.COMMENT_NODE,dl=st.DOCUMENT_NODE,Ac=st.DOCUMENT_TYPE_NODE,gl=st.DOCUMENT_FRAGMENT_NODE,xc=D(t=>t.nodeType===dl),Y=Symbol,Mn=Y(),Tn=Y(),fl=Y(),pl=Y(),wl=Y(),Nn=Y(),ml=Y(),or=Y(),kl=Y(),yl=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());let e=[],r=[],n=0;for(;n<t.length;n++){let s=t[n];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)e.push(s);else if(s.constructor===Object)break}for(n>0&&r.push(e.join(""));n<t.length;n++){let s=t[n];s instanceof Symbol||r.push(s)}return r},Ic=sn(),bl={[Mn]:B("font-weight","bold"),[Tn]:B("font-weight","normal"),[fl]:B("color","blue"),[wl]:B("color","green"),[pl]:B("color","grey"),[Nn]:B("color","red"),[ml]:B("color","purple"),[or]:B("color","orange"),[kl]:B("color","black")},_l=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());let e=[],r=[],n=F(),s=[],i=0;for(;i<t.length;i++){let l=t[i],o=bl[l];if(o!==void 0)n.set(o.left,o.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){let c=al(n);i>0||c.length>0?(e.push("%c"+l),r.push(c)):e.push(l)}else break}}for(i>0&&(s=r,s.unshift(e.join("")));i<t.length;i++){let l=t[i];l instanceof Symbol||s.push(l)}return s},Ln=xi?_l:yl,vl=(...t)=>{console.log(...Ln(t)),Vn.forEach(e=>e.print(t))},Rn=(...t)=>{console.warn(...Ln(t)),t.unshift(or),Vn.forEach(e=>e.print(t))},Vn=ht(),Fn=t=>({[Symbol.iterator](){return this},next:t}),Sl=(t,e)=>Fn(()=>{let r;do r=t.next();while(!r.done&&!e(r.value));return r}),De=(t,e)=>Fn(()=>{let{done:r,value:n}=t.next();return{done:r,value:r?void 0:e(n)}});var cr=class{constructor(t,e){this.clock=t,this.len=e}},kt=class{constructor(){this.clients=new Map}},pt=(t,e,r)=>e.clients.forEach((n,s)=>{let i=t.doc.store.clients.get(s);if(i!=null){let l=i[i.length-1],o=l.id.clock+l.length;for(let c=0,u=n[c];c<n.length&&u.clock<o;u=n[++c])qn(t,i,u.clock,u.len,r)}}),El=(t,e)=>{let r=0,n=t.length-1;for(;r<=n;){let s=z((r+n)/2),i=t[s],l=i.clock;if(l<=e){if(e<l+i.len)return s;r=s+1}else n=s-1}return null},Nt=(t,e)=>{let r=t.clients.get(e.client);return r!==void 0&&El(r,e.clock)!==null},ar=t=>{t.clients.forEach(e=>{e.sort((s,i)=>s.clock-i.clock);let r,n;for(r=1,n=1;r<e.length;r++){let s=e[n-1],i=e[r];s.clock+s.len>=i.clock?s.len=nt(s.len,i.clock+i.len-s.clock):(n<r&&(e[n]=i),n++)}e.length=n})},Te=t=>{let e=new kt;for(let r=0;r<t.length;r++)t[r].clients.forEach((n,s)=>{if(!e.clients.has(s)){let i=n.slice();for(let l=r+1;l<t.length;l++)Os(i,t[l].clients.get(s)||[]);e.clients.set(s,i)}});return ar(e),e},xt=(t,e,r,n)=>{q(t.clients,e,()=>[]).push(new cr(r,n))},Pn=()=>new kt,Cl=t=>{let e=Pn();return t.clients.forEach((r,n)=>{let s=[];for(let i=0;i<r.length;i++){let l=r[i];if(l.deleted){let o=l.id.clock,c=l.length;if(i+1<r.length)for(let u=r[i+1];i+1<r.length&&u.deleted;u=r[++i+1])c+=u.length;s.push(new cr(o,c))}}s.length>0&&e.clients.set(n,s)}),e},yt=(t,e)=>{p(t.restEncoder,e.clients.size),G(e.clients.entries()).sort((r,n)=>n[0]-r[0]).forEach(([r,n])=>{t.resetDsCurVal(),p(t.restEncoder,r);let s=n.length;p(t.restEncoder,s);for(let i=0;i<s;i++){let l=n[i];t.writeDsClock(l.clock),t.writeDsLen(l.len)}})},ge=t=>{let e=new kt,r=w(t.restDecoder);for(let n=0;n<r;n++){t.resetDsCurVal();let s=w(t.restDecoder),i=w(t.restDecoder);if(i>0){let l=q(e.clients,s,()=>[]);for(let o=0;o<i;o++)l.push(new cr(t.readDsClock(),t.readDsLen()))}}return e},Rr=(t,e,r)=>{let n=new kt,s=w(t.restDecoder);for(let i=0;i<s;i++){t.resetDsCurVal();let l=w(t.restDecoder),o=w(t.restDecoder),c=r.clients.get(l)||[],u=_(r,l);for(let a=0;a<o;a++){let h=t.readDsClock(),d=h+t.readDsLen();if(h<u){u<d&&xt(n,l,u,d-u);let g=$(c,h),f=c[g];for(!f.deleted&&f.id.clock<h&&(c.splice(g+1,0,ne(e,f,h-f.id.clock)),g++);g<c.length&&(f=c[g++],f.id.clock<d);)f.deleted||(d<f.id.clock+f.length&&c.splice(g,0,ne(e,f,d-f.id.clock)),f.delete(e))}else xt(n,l,h,d-h)}}if(n.clients.size>0){let i=new et;return p(i.restEncoder,0),yt(i,n),i.toUint8Array()}return null},Uc=(t,e)=>{if(t.clients.size!==e.clients.size)return!1;for(let[r,n]of t.clients.entries()){let s=e.clients.get(r);if(s===void 0||n.length!==s.length)return!1;for(let i=0;i<n.length;i++){let l=n[i],o=s[i];if(l.clock!==o.clock||l.len!==o.len)return!1}}return!0},jn=nn,fe=class zn extends Qr{constructor({guid:e=ui(),collectionid:r=null,gc:n=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:l=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=s,this.clientID=jn(),this.guid=e,this.collectionid=r,this.share=new Map,this.store=new Gn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=l,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Mr(u=>{this.on("load",()=>{this.isLoaded=!0,u(this)})});let c=()=>Mr(u=>{let a=h=>{(h===void 0||h===!0)&&(this.off("sync",a),u())};this.on("sync",a)});this.on("sync",u=>{u===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=u===void 0||u===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&y(e.parent.doc,r=>{r.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(G(this.subdocs).map(e=>e.guid))}transact(e,r=null){return y(this,e,r)}get(e,r=C){let n=q(this.share,e,()=>{let i=new r;return i._integrate(this,null),i}),s=n.constructor;if(r!==C&&s!==r)if(s===C){let i=new r;i._map=n._map,n._map.forEach(l=>{for(;l!==null;l=l.left)l.parent=i}),i._start=n._start;for(let l=i._start;l!==null;l=l.right)l.parent=i;return i._length=n._length,this.share.set(e,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=""){return this.get(e,us)}getText(e=""){return this.get(e,kr)}getMap(e=""){return this.get(e,mr)}getXmlElement(e=""){return this.get(e,yr)}getXmlFragment(e=""){return this.get(e,be)}toJSON(){let e={};return this.share.forEach((r,n)=>{e[n]=r.toJSON()}),e}destroy(){this.isDestroyed=!0,G(this.subdocs).forEach(r=>r.destroy());let e=this._item;if(e!==null){this._item=null;let r=e.content;r.doc=new zn({guid:this.guid,...r.opts,shouldLoad:!1}),r.doc._item=e,y(e.parent.doc,n=>{let s=r.doc;e.deleted||n.subdocsAdded.add(s),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Jn=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}},Dl=class extends Jn{readLeftID(){return m(w(this.restDecoder),w(this.restDecoder))}readRightID(){return m(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return dt(this.restDecoder)}readString(){return tt(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Ct(this.restDecoder)}readBuf(){return Ti(T(this.restDecoder))}readJSON(){return JSON.parse(tt(this.restDecoder))}readKey(){return tt(this.restDecoder)}},Al=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=w(this.restDecoder),this.dsCurrVal}readDsLen(){let t=w(this.restDecoder)+1;return this.dsCurrVal+=t,t}},X=class extends Al{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new Se(T(t)),this.clientDecoder=new $t(T(t)),this.leftClockDecoder=new Se(T(t)),this.rightClockDecoder=new Se(T(t)),this.infoDecoder=new Or(T(t),dt),this.stringDecoder=new ci(T(t)),this.parentInfoDecoder=new Or(T(t),dt),this.typeRefDecoder=new $t(T(t)),this.lenDecoder=new $t(T(t))}readLeftID(){return new ct(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ct(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Ct(this.restDecoder)}readBuf(){return T(this.restDecoder)}readJSON(){return Ct(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},$n=class{constructor(){this.restEncoder=wt()}toUint8Array(){return R(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}},pe=class extends $n{writeLeftID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeRightID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeClient(t){p(this.restEncoder,t)}writeInfo(t){St(this.restEncoder,t)}writeString(t){Z(this.restEncoder,t)}writeParentInfo(t){p(this.restEncoder,t?1:0)}writeTypeRef(t){p(this.restEncoder,t)}writeLen(t){p(this.restEncoder,t)}writeAny(t){Et(this.restEncoder,t)}writeBuf(t){M(this.restEncoder,t)}writeJSON(t){Z(this.restEncoder,JSON.stringify(t))}writeKey(t){Z(this.restEncoder,t)}},hr=class{constructor(){this.restEncoder=wt(),this.dsCurrVal=0}toUint8Array(){return R(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let e=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,e)}writeDsLen(t){t===0&&O(),p(this.restEncoder,t-1),this.dsCurrVal+=t}},et=class extends hr{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new ve,this.clientEncoder=new Jt,this.leftClockEncoder=new ve,this.rightClockEncoder=new ve,this.infoEncoder=new xr(St),this.stringEncoder=new Qs,this.parentInfoEncoder=new xr(St),this.typeRefEncoder=new Jt,this.lenEncoder=new Jt}toUint8Array(){let t=wt();return p(t,0),M(t,this.keyClockEncoder.toUint8Array()),M(t,this.clientEncoder.toUint8Array()),M(t,this.leftClockEncoder.toUint8Array()),M(t,this.rightClockEncoder.toUint8Array()),M(t,R(this.infoEncoder)),M(t,this.stringEncoder.toUint8Array()),M(t,R(this.parentInfoEncoder)),M(t,this.typeRefEncoder.toUint8Array()),M(t,this.lenEncoder.toUint8Array()),Mt(t,R(this.restEncoder)),R(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Et(this.restEncoder,t)}writeBuf(t){M(this.restEncoder,t)}writeJSON(t){Et(this.restEncoder,t)}writeKey(t){let e=this.keyMap.get(t);e===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}},xl=(t,e,r,n)=>{n=nt(n,e[0].id.clock);let s=$(e,n);p(t.restEncoder,e.length-s),t.writeClient(r),p(t.restEncoder,n);let i=e[s];i.write(t,n-i.id.clock);for(let l=s+1;l<e.length;l++)e[l].write(t,0)},ur=(t,e,r)=>{let n=new Map;r.forEach((s,i)=>{_(e,i)>s&&n.set(i,s)}),we(e).forEach((s,i)=>{r.has(i)||n.set(i,0)}),p(t.restEncoder,n.size),G(n.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{xl(t,e.clients.get(s),s,i)})},Il=(t,e)=>{let r=F(),n=w(t.restDecoder);for(let s=0;s<n;s++){let i=w(t.restDecoder),l=new Array(i),o=t.readClient(),c=w(t.restDecoder);r.set(o,{i:0,refs:l});for(let u=0;u<i;u++){let a=t.readInfo();switch(31&a){case 0:{let h=t.readLen();l[u]=new L(m(o,c),h),c+=h;break}case 10:{let h=w(t.restDecoder);l[u]=new N(m(o,c),h),c+=h;break}default:{let h=(a&192)===0,d=new b(m(o,c),null,(a&128)===128?t.readLeftID():null,null,(a&64)===64?t.readRightID():null,h?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,h&&(a&32)===32?t.readString():null,Es(t,a));l[u]=d,c+=d.length}}}}return r},Ul=(t,e,r)=>{let n=[],s=G(r.keys()).sort((g,f)=>g-f);if(s.length===0)return null;let i=()=>{if(s.length===0)return null;let g=r.get(s[s.length-1]);for(;g.refs.length===g.i;)if(s.pop(),s.length>0)g=r.get(s[s.length-1]);else return null;return g},l=i();if(l===null)return null;let o=new Gn,c=new Map,u=(g,f)=>{let k=c.get(g);(k==null||k>f)&&c.set(g,f)},a=l.refs[l.i++],h=new Map,d=()=>{for(let g of n){let f=g.id.client,k=r.get(f);k?(k.i--,o.clients.set(f,k.refs.slice(k.i)),r.delete(f),k.i=0,k.refs=[]):o.clients.set(f,[g]),s=s.filter(V=>V!==f)}n.length=0};for(;;){if(a.constructor!==N){let g=q(h,a.id.client,()=>_(e,a.id.client))-a.id.clock;if(g<0)n.push(a),u(a.id.client,a.id.clock-1),d();else{let f=a.getMissing(t,e);if(f!==null){n.push(a);let k=r.get(f)||{refs:[],i:0};if(k.refs.length===k.i)u(f,_(e,f)),d();else{a=k.refs[k.i++];continue}}else(g===0||g<a.length)&&(a.integrate(t,g),h.set(a.id.client,a.id.clock+a.length))}}if(n.length>0)a=n.pop();else if(l!==null&&l.i<l.refs.length)a=l.refs[l.i++];else{if(l=i(),l===null)break;a=l.refs[l.i++]}}if(o.clients.size>0){let g=new et;return ur(g,o,new Map),p(g.restEncoder,0),{missing:c,update:g.toUint8Array()}}return null},Ol=(t,e)=>ur(t,e.doc.store,e.beforeState),Ml=(t,e,r,n=new X(t))=>y(e,s=>{s.local=!1;let i=!1,l=s.doc,o=l.store,c=Il(n,l),u=Ul(s,o,c),a=o.pendingStructs;if(a){for(let[d,g]of a.missing)if(g<_(o,d)){i=!0;break}if(u){for(let[d,g]of u.missing){let f=a.missing.get(d);(f==null||f>g)&&a.missing.set(d,g)}a.update=Zt([a.update,u.update])}}else o.pendingStructs=u;let h=Rr(n,s,o);if(o.pendingDs){let d=new X(W(o.pendingDs));w(d.restDecoder);let g=Rr(d,s,o);h&&g?o.pendingDs=Zt([h,g]):o.pendingDs=h||g}else o.pendingDs=h;if(i){let d=o.pendingStructs.update;o.pendingStructs=null,Tl(s.doc,d)}},r,!1);var Tl=(t,e,r,n=X)=>{let s=W(e);Ml(s,t,r,new n(s))};var Nl=(t,e,r=new Map)=>{ur(t,e.store,r),yt(t,Cl(e.store))},Oc=(t,e=new Uint8Array([0]),r=new et)=>{let n=Bn(e);Nl(r,t,n);let s=[r.toUint8Array()];if(t.store.pendingDs&&s.push(t.store.pendingDs),t.store.pendingStructs&&s.push(eo(t.store.pendingStructs.update,e)),s.length>1){if(r.constructor===pe)return Zl(s.map((i,l)=>l===0?i:no(i)));if(r.constructor===et)return Zt(s)}return s[0]};var Ll=t=>{let e=new Map,r=w(t.restDecoder);for(let n=0;n<r;n++){let s=w(t.restDecoder),i=w(t.restDecoder);e.set(s,i)}return e},Bn=t=>Ll(new Jn(W(t))),Wn=(t,e)=>(p(t.restEncoder,e.size),G(e.entries()).sort((r,n)=>n[0]-r[0]).forEach(([r,n])=>{p(t.restEncoder,r),p(t.restEncoder,n)}),t),Rl=(t,e)=>Wn(t,we(e.store)),Vl=(t,e=new hr)=>(t instanceof Map?Wn(e,t):Rl(e,t),e.toUint8Array()),Mc=t=>Vl(t,new $n),Fl=class{constructor(){this.l=[]}},Vr=()=>new Fl,Fr=(t,e)=>t.l.push(e),Pr=(t,e)=>{let r=t.l,n=r.length;t.l=r.filter(s=>e!==s),n===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Yn=(t,e,r)=>rr(t.l,[e,r]),ct=class{constructor(t,e){this.client=t,this.clock=e}},Vt=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,m=(t,e)=>new ct(t,e),jr=(t,e)=>{p(t,e.client),p(t,e.clock)},zr=t=>m(w(t),w(t)),Kn=t=>{for(let[e,r]of t.doc.share.entries())if(r===t)return e;throw O()},Qt=(t,e)=>{for(;e!==null;){if(e.parent===t)return!0;e=e.parent._item}return!1};var Hn=class{constructor(t,e,r,n=0){this.type=t,this.tname=e,this.item=r,this.assoc=n}};var Pl=class{constructor(t,e,r=0){this.type=t,this.index=e,this.assoc=r}},jl=(t,e,r=0)=>new Pl(t,e,r),Ft=(t,e,r)=>{let n=null,s=null;return t._item===null?s=Kn(t):n=m(t._item.id.client,t._item.id.clock),new Hn(n,s,e,r)},Tc=(t,e,r=0)=>{let n=t._start;if(r<0){if(e===0)return Ft(t,null,r);e--}for(;n!==null;){if(!n.deleted&&n.countable){if(n.length>e)return Ft(t,m(n.id.client,n.id.clock+e),r);e-=n.length}if(n.right===null&&r<0)return Ft(t,n.lastId,r);n=n.right}return Ft(t,null,r)},zl=(t,e)=>{let{type:r,tname:n,item:s,assoc:i}=e;if(s!==null)p(t,0),jr(t,s);else if(n!==null)St(t,1),Z(t,n);else if(r!==null)St(t,2),jr(t,r);else throw O();return se(t,i),t},Nc=t=>{let e=wt();return zl(e,t),R(e)},Jl=t=>{let e=null,r=null,n=null;switch(w(t)){case 0:n=zr(t);break;case 1:r=tt(t);break;case 2:e=zr(t)}let s=rn(t)?oe(t):0;return new Hn(e,r,n,s)},Lc=t=>Jl(W(t)),$l=(t,e)=>{let r=at(t,e),n=e.clock-r.id.clock;return{item:r,diff:n}},Rc=(t,e,r=!0)=>{let n=e.store,s=t.item,i=t.type,l=t.tname,o=t.assoc,c=null,u=0;if(s!==null){if(_(n,s.client)<=s.clock)return null;let a=r?Ke(n,s):$l(n,s),h=a.item;if(!(h instanceof b))return null;if(c=h.parent,c._item===null||!c._item.deleted){u=h.deleted||!h.countable?0:a.diff+(o>=0?0:1);let d=h.left;for(;d!==null;)!d.deleted&&d.countable&&(u+=d.length),d=d.left}}else{if(l!==null)c=e.get(l);else if(i!==null){if(_(n,i.client)<=i.clock)return null;let{item:a}=r?Ke(n,i):{item:at(n,i)};if(a instanceof b&&a.content instanceof Q)c=a.content.type;else return null}else throw O();o>=0?u=c._length:u=0}return jl(c,u,t.assoc)};var Bl=class{constructor(t,e){this.ds=t,this.sv=e}};var Wl=(t,e)=>new Bl(t,e),Vc=Wl(Pn(),new Map);var lt=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Nt(e.ds,t.id),Ne=(t,e)=>{let r=q(t.meta,Ne,ht),n=t.doc.store;r.has(e)||(e.sv.forEach((s,i)=>{s<_(n,i)&&U(t,m(i,s))}),pt(t,e.ds,s=>{}),r.add(e))};var Gn=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},we=t=>{let e=new Map;return t.clients.forEach((r,n)=>{let s=r[r.length-1];e.set(n,s.id.clock+s.length)}),e},_=(t,e)=>{let r=t.clients.get(e);if(r===void 0)return 0;let n=r[r.length-1];return n.id.clock+n.length},Xn=(t,e)=>{let r=t.clients.get(e.id.client);if(r===void 0)r=[],t.clients.set(e.id.client,r);else{let n=r[r.length-1];if(n.id.clock+n.length!==e.id.clock)throw O()}r.push(e)},$=(t,e)=>{let r=0,n=t.length-1,s=t[n],i=s.id.clock;if(i===e)return n;let l=z(e/(i+s.length-1)*n);for(;r<=n;){if(s=t[l],i=s.id.clock,i<=e){if(e<i+s.length)return l;r=l+1}else n=l-1;l=z((r+n)/2)}throw O()},Yl=(t,e)=>{let r=t.clients.get(e.client);return r[$(r,e.clock)]},at=Yl,Le=(t,e,r)=>{let n=$(e,r),s=e[n];return s.id.clock<r&&s instanceof b?(e.splice(n+1,0,ne(t,s,r-s.id.clock)),n+1):n},U=(t,e)=>{let r=t.doc.store.clients.get(e.client);return r[Le(t,r,e.clock)]},Jr=(t,e,r)=>{let n=e.clients.get(r.client),s=$(n,r.clock),i=n[s];return r.clock!==i.id.clock+i.length-1&&i.constructor!==L&&n.splice(s+1,0,ne(t,i,r.clock-i.id.clock+1)),i},Kl=(t,e,r)=>{let n=t.clients.get(e.id.client);n[$(n,e.id.clock)]=r},qn=(t,e,r,n,s)=>{if(n===0)return;let i=r+n,l=Le(t,e,r),o;do o=e[l++],i<o.id.clock+o.length&&Le(t,e,i),s(o);while(l<e.length&&e[l].id.clock<i)},Hl=class{constructor(t,e,r){this.doc=t,this.deleteSet=new kt,this.beforeState=we(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},$r=(t,e)=>e.deleteSet.clients.size===0&&!Us(e.afterState,(r,n)=>e.beforeState.get(n)!==r)?!1:(ar(e.deleteSet),Ol(t,e),yt(t,e.deleteSet),!0),Br=(t,e,r)=>{let n=e._item;(n===null||n.id.clock<(t.beforeState.get(n.id.client)||0)&&!n.deleted)&&q(t.changed,e,ht).add(r)},Wt=(t,e)=>{let r=t[e],n=t[e-1],s=e;for(;s>0;r=n,n=t[--s-1]){if(n.deleted===r.deleted&&n.constructor===r.constructor&&n.mergeWith(r)){r instanceof b&&r.parentSub!==null&&r.parent._map.get(r.parentSub)===r&&r.parent._map.set(r.parentSub,n);continue}break}let i=e-s;return i&&t.splice(e+1-i,i),i},Gl=(t,e,r)=>{for(let[n,s]of t.clients.entries()){let i=e.clients.get(n);for(let l=s.length-1;l>=0;l--){let o=s[l],c=o.clock+o.len;for(let u=$(i,o.clock),a=i[u];u<i.length&&a.id.clock<c;a=i[++u]){let h=i[u];if(o.clock+o.len<=h.id.clock)break;h instanceof b&&h.deleted&&!h.keep&&r(h)&&h.gc(e,!1)}}}},Xl=(t,e)=>{t.clients.forEach((r,n)=>{let s=e.clients.get(n);for(let i=r.length-1;i>=0;i--){let l=r[i],o=Zr(s.length-1,1+$(s,l.clock+l.len-1));for(let c=o,u=s[c];c>0&&u.id.clock>=l.clock;u=s[c])c-=1+Wt(s,c)}})};var Qn=(t,e)=>{if(e<t.length){let r=t[e],n=r.doc,s=n.store,i=r.deleteSet,l=r._mergeStructs;try{ar(i),r.afterState=we(r.doc.store),n.emit("beforeObserverCalls",[r,n]);let o=[];r.changed.forEach((c,u)=>o.push(()=>{(u._item===null||!u._item.deleted)&&u._callObserver(r,c)})),o.push(()=>{r.changedParentTypes.forEach((c,u)=>{u._dEH.l.length>0&&(u._item===null||!u._item.deleted)&&(c=c.filter(a=>a.target._item===null||!a.target._item.deleted),c.forEach(a=>{a.currentTarget=u,a._path=null}),c.sort((a,h)=>a.path.length-h.path.length),Yn(u._dEH,c,r))})}),o.push(()=>n.emit("afterTransaction",[r,n])),rr(o,[]),r._needFormattingCleanup&&ko(r)}finally{n.gc&&Gl(i,s,n.gcFilter),Xl(i,s),r.afterState.forEach((a,h)=>{let d=r.beforeState.get(h)||0;if(d!==a){let g=s.clients.get(h),f=nt($(g,d),1);for(let k=g.length-1;k>=f;)k-=1+Wt(g,k)}});for(let a=l.length-1;a>=0;a--){let{client:h,clock:d}=l[a].id,g=s.clients.get(h),f=$(g,d);f+1<g.length&&Wt(g,f+1)>1||f>0&&Wt(g,f)}if(!r.local&&r.afterState.get(n.clientID)!==r.beforeState.get(n.clientID)&&(vl(or,Mn,"[yjs] ",Tn,Nn,"Changed the client-id because another client seems to be using it."),n.clientID=jn()),n.emit("afterTransactionCleanup",[r,n]),n._observers.has("update")){let a=new pe;$r(a,r)&&n.emit("update",[a.toUint8Array(),r.origin,n,r])}if(n._observers.has("updateV2")){let a=new et;$r(a,r)&&n.emit("updateV2",[a.toUint8Array(),r.origin,n,r])}let{subdocsAdded:o,subdocsLoaded:c,subdocsRemoved:u}=r;(o.size>0||u.size>0||c.size>0)&&(o.forEach(a=>{a.clientID=n.clientID,a.collectionid==null&&(a.collectionid=n.collectionid),n.subdocs.add(a)}),u.forEach(a=>n.subdocs.delete(a)),n.emit("subdocs",[{loaded:c,added:o,removed:u},n,r]),u.forEach(a=>a.destroy())),t.length<=e+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,t])):Qn(t,e+1)}}},y=(t,e,r=null,n=!0)=>{let s=t._transactionCleanups,i=!1,l=null;t._transaction===null&&(i=!0,t._transaction=new Hl(t,r,n),s.push(t._transaction),s.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{l=e(t._transaction)}finally{if(i){let o=t._transaction===s[0];t._transaction=null,o&&Qn(s,0)}}return l},ql=class{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}},Wr=(t,e,r)=>{pt(t,r.deletions,n=>{n instanceof b&&e.scope.some(s=>s===t.doc||Qt(s,n))&&Sr(n,!1)})},Yr=(t,e,r)=>{let n=null,s=t.doc,i=t.scope;y(s,o=>{for(;e.length>0&&t.currStackItem===null;){let c=s.store,u=e.pop(),a=new Set,h=[],d=!1;pt(o,u.insertions,g=>{if(g instanceof b){if(g.redone!==null){let{item:f,diff:k}=Ke(c,g.id);k>0&&(f=U(o,m(f.id.client,f.id.clock+k))),g=f}!g.deleted&&i.some(f=>f===o.doc||Qt(f,g))&&h.push(g)}}),pt(o,u.deletions,g=>{g instanceof b&&i.some(f=>f===o.doc||Qt(f,g))&&!Nt(u.insertions,g.id)&&a.add(g)}),a.forEach(g=>{d=Ss(o,g,a,u.insertions,t.ignoreRemoteMapChanges,t)!==null||d});for(let g=h.length-1;g>=0;g--){let f=h[g];t.deleteFilter(f)&&(f.delete(o),d=!0)}t.currStackItem=d?u:null}o.changed.forEach((c,u)=>{c.has(null)&&u._searchMarker&&(u._searchMarker.length=0)}),n=o},t);let l=t.currStackItem;if(l!=null){let o=n.changedParentTypes;t.emit("stack-item-popped",[{stackItem:l,type:r,changedParentTypes:o,origin:t},t]),t.currStackItem=null}return l},Fc=class extends Qr{constructor(t,{captureTimeout:e=500,captureTransaction:r=o=>!0,deleteFilter:n=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:l=ut(t)?t[0].doc:t instanceof fe?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=n,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=e,this.afterTransactionHandler=o=>{if(!this.captureTransaction(o)||!this.scope.some(k=>o.changedParentTypes.has(k)||k===this.doc)||!this.trackedOrigins.has(o.origin)&&(!o.origin||!this.trackedOrigins.has(o.origin.constructor)))return;let c=this.undoing,u=this.redoing,a=c?this.redoStack:this.undoStack;c?this.stopCapturing():u||this.clear(!1,!0);let h=new kt;o.afterState.forEach((k,V)=>{let v=o.beforeState.get(V)||0,Er=k-v;Er>0&&xt(h,V,v,Er)});let d=sn(),g=!1;if(this.lastChange>0&&d-this.lastChange<this.captureTimeout&&a.length>0&&!c&&!u){let k=a[a.length-1];k.deletions=Te([k.deletions,o.deleteSet]),k.insertions=Te([k.insertions,h])}else a.push(new ql(o.deleteSet,h)),g=!0;!c&&!u&&(this.lastChange=d),pt(o,o.deleteSet,k=>{k instanceof b&&this.scope.some(V=>V===o.doc||Qt(V,k))&&Sr(k,!0)});let f=[{stackItem:a[a.length-1],origin:o.origin,type:c?"redo":"undo",changedParentTypes:o.changedParentTypes},this];g?this.emit("stack-item-added",f):this.emit("stack-item-updated",f)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let e=new Set(this.scope);t=ut(t)?t:[t],t.forEach(r=>{e.has(r)||(e.add(r),(r instanceof C?r.doc!==this.doc:r!==this.doc)&&Rn("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,e=!0){(t&&this.canUndo()||e&&this.canRedo())&&this.doc.transact(r=>{t&&(this.undoStack.forEach(n=>Wr(r,this,n)),this.undoStack=[]),e&&(this.redoStack.forEach(n=>Wr(r,this,n)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:e}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Yr(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Yr(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*Ql(t){let e=w(t.restDecoder);for(let r=0;r<e;r++){let n=w(t.restDecoder),s=t.readClient(),i=w(t.restDecoder);for(let l=0;l<n;l++){let o=t.readInfo();if(o===10){let c=w(t.restDecoder);yield new N(m(s,i),c),i+=c}else if((31&o)!==0){let c=(o&192)===0,u=new b(m(s,i),null,(o&128)===128?t.readLeftID():null,null,(o&64)===64?t.readRightID():null,c?t.readParentInfo()?t.readString():t.readLeftID():null,c&&(o&32)===32?t.readString():null,Es(t,o));yield u,i+=u.length}else{let c=t.readLen();yield new L(m(s,i),c),i+=c}}}}var Lt=class{constructor(t,e){this.gen=Ql(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===N);return this.curr}};var Pc=(t,e=X)=>{let r=[],n=new e(W(t)),s=new Lt(n,!1);for(let i=s.curr;i!==null;i=s.next())r.push(i);return{structs:r,ds:ge(n)}},dr=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},Zl=t=>Zt(t,Dl,pe),jc=(t,e=hr,r=X)=>{let n=new e,s=new Lt(new r(W(t)),!1),i=s.curr;if(i!==null){let l=0,o=i.id.client,c=i.id.clock!==0,u=c?0:i.id.clock+i.length;for(;i!==null;i=s.next())o!==i.id.client&&(u!==0&&(l++,p(n.restEncoder,o),p(n.restEncoder,u)),o=i.id.client,u=0,c=i.id.clock!==0),i.constructor===N&&(c=!0),c||(u=i.id.clock+i.length);u!==0&&(l++,p(n.restEncoder,o),p(n.restEncoder,u));let a=wt();return p(a,l),Ks(a,n.restEncoder),n.restEncoder=a,n.toUint8Array()}else return p(n.restEncoder,0),n.toUint8Array()};var to=(t,e)=>{if(t.constructor===L){let{client:r,clock:n}=t.id;return new L(m(r,n+e),t.length-e)}else if(t.constructor===N){let{client:r,clock:n}=t.id;return new N(m(r,n+e),t.length-e)}else{let r=t,{client:n,clock:s}=r.id;return new b(m(n,s+e),null,m(n,s+e-1),null,r.rightOrigin,r.parent,r.parentSub,r.content.splice(e))}},Zt=(t,e=X,r=et)=>{if(t.length===1)return t[0];let n=t.map(a=>new e(W(a))),s=n.map(a=>new Lt(a,!0)),i=null,l=new r,o=new dr(l);for(;s=s.filter(a=>a.curr!==null),s.sort((a,h)=>{if(a.curr.id.client===h.curr.id.client){let d=a.curr.id.clock-h.curr.id.clock;return d===0?a.curr.constructor===h.curr.constructor?0:a.curr.constructor===N?1:-1:d}else return h.curr.id.client-a.curr.id.client}),s.length!==0;){let a=s[0],h=a.curr.id.client;if(i!==null){let d=a.curr,g=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=a.next(),g=!0;if(d===null||d.id.client!==h||g&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(h!==i.struct.id.client)K(o,i.struct,i.offset),i={struct:d,offset:0},a.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===N)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{K(o,i.struct,i.offset);let f=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new N(m(h,i.struct.id.clock+i.struct.length),f),offset:0}}else{let f=i.struct.id.clock+i.struct.length-d.id.clock;f>0&&(i.struct.constructor===N?i.struct.length-=f:d=to(d,f)),i.struct.mergeWith(d)||(K(o,i.struct,i.offset),i={struct:d,offset:0},a.next())}}else i={struct:a.curr,offset:0},a.next();for(let d=a.curr;d!==null&&d.id.client===h&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==N;d=a.next())K(o,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(K(o,i.struct,i.offset),i=null),gr(o);let c=n.map(a=>ge(a)),u=Te(c);return yt(l,u),l.toUint8Array()},eo=(t,e,r=X,n=et)=>{let s=Bn(e),i=new n,l=new dr(i),o=new r(W(t)),c=new Lt(o,!1);for(;c.curr;){let a=c.curr,h=a.id.client,d=s.get(h)||0;if(c.curr.constructor===N){c.next();continue}if(a.id.clock+a.length>d)for(K(l,a,nt(d-a.id.clock,0)),c.next();c.curr&&c.curr.id.client===h;)K(l,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===h&&c.curr.id.clock+c.curr.length<=d;)c.next()}gr(l);let u=ge(o);return yt(i,u),i.toUint8Array()};var Zn=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:R(t.encoder.restEncoder)}),t.encoder.restEncoder=wt(),t.written=0)},K=(t,e,r)=>{t.written>0&&t.currClient!==e.id.client&&Zn(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),p(t.encoder.restEncoder,e.id.clock+r)),e.write(t.encoder,r),t.written++},gr=t=>{Zn(t);let e=t.encoder.restEncoder;p(e,t.clientStructs.length);for(let r=0;r<t.clientStructs.length;r++){let n=t.clientStructs[r];p(e,n.written),Mt(e,n.restEncoder)}},ro=(t,e,r,n)=>{let s=new r(W(t)),i=new Lt(s,!1),l=new n,o=new dr(l);for(let u=i.curr;u!==null;u=i.next())K(o,e(u),0);gr(o);let c=ge(s);return yt(l,c),l.toUint8Array()};var no=t=>ro(t,vi,X,pe),Kr="You must not compute changes after the event-handler fired.",me=class{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=so(this.currentTarget,this.target))}deletes(t){return Nt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw J(Kr);let t=new Map,e=this.target;this.transaction.changed.get(e).forEach(r=>{if(r!==null){let n=e._map.get(r),s,i;if(this.adds(n)){let l=n.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(n))if(l!==null&&this.deletes(l))s="delete",i=_e(l.content.getContent());else return;else l!==null&&this.deletes(l)?(s="update",i=_e(l.content.getContent())):(s="add",i=void 0)}else if(this.deletes(n))s="delete",i=_e(n.content.getContent());else return;t.set(r,{action:s,oldValue:i})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw J(Kr);let e=this.target,r=ht(),n=ht(),s=[];if(t={added:r,deleted:n,delta:s,keys:this.keys},this.transaction.changed.get(e).has(null)){let i=null,l=()=>{i&&s.push(i)};for(let o=e._start;o!==null;o=o.right)o.deleted?this.deletes(o)&&!this.adds(o)&&((i===null||i.delete===void 0)&&(l(),i={delete:0}),i.delete+=o.length,n.add(o)):this.adds(o)?((i===null||i.insert===void 0)&&(l(),i={insert:[]}),i.insert=i.insert.concat(o.content.getContent()),r.add(o)):((i===null||i.retain===void 0)&&(l(),i={retain:0}),i.retain+=o.length);i!==null&&i.retain===void 0&&l()}this._changes=t}return t}},so=(t,e)=>{let r=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)r.unshift(e._item.parentSub);else{let n=0,s=e._item.parent._start;for(;s!==e._item&&s!==null;)!s.deleted&&s.countable&&(n+=s.length),s=s.right;r.unshift(n)}e=e._item.parent}return r},x=()=>{Rn("Invalid access: Add Yjs type to a document before reading data.")},ts=80,fr=0,io=class{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=fr++}},lo=t=>{t.timestamp=fr++},es=(t,e,r)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=r,t.timestamp=fr++},oo=(t,e,r)=>{if(t.length>=ts){let n=t.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return es(n,e,r),n}else{let n=new io(e,r);return t.push(n),n}},ke=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;let r=t._searchMarker.length===0?null:t._searchMarker.reduce((i,l)=>zt(e-i.index)<zt(e-l.index)?i:l),n=t._start,s=0;for(r!==null&&(n=r.p,s=r.index,lo(r));n.right!==null&&s<e;){if(!n.deleted&&n.countable){if(e<s+n.length)break;s+=n.length}n=n.right}for(;n.left!==null&&s>e;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);return r!==null&&zt(r.index-s)<n.parent.length/ts?(es(r,n,s),r):oo(t._searchMarker,n,s)},It=(t,e,r)=>{for(let n=t.length-1;n>=0;n--){let s=t[n];if(r>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){t.splice(n,1);continue}s.p=i,i.marker=!0}(e<s.index||r>0&&e===s.index)&&(s.index=nt(e,s.index+r))}};var ye=(t,e,r)=>{let n=t,s=e.changedParentTypes;for(;q(s,t,()=>[]).push(r),t._item!==null;)t=t._item.parent;Yn(n._eH,r,e)},C=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Vr(),this._dEH=Vr(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw P()}clone(){throw P()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Fr(this._eH,t)}observeDeep(t){Fr(this._dEH,t)}unobserve(t){Pr(this._eH,t)}unobserveDeep(t){Pr(this._dEH,t)}toJSON(){}},rs=(t,e,r)=>{t.doc??x(),e<0&&(e=t._length+e),r<0&&(r=t._length+r);let n=r-e,s=[],i=t._start;for(;i!==null&&n>0;){if(i.countable&&!i.deleted){let l=i.content.getContent();if(l.length<=e)e-=l.length;else{for(let o=e;o<l.length&&n>0;o++)s.push(l[o]),n--;e=0}}i=i.right}return s},ns=t=>{t.doc??x();let e=[],r=t._start;for(;r!==null;){if(r.countable&&!r.deleted){let n=r.content.getContent();for(let s=0;s<n.length;s++)e.push(n[s])}r=r.right}return e};var Ut=(t,e)=>{let r=0,n=t._start;for(t.doc??x();n!==null;){if(n.countable&&!n.deleted){let s=n.content.getContent();for(let i=0;i<s.length;i++)e(s[i],r++,t)}n=n.right}},ss=(t,e)=>{let r=[];return Ut(t,(n,s)=>{r.push(e(n,s,t))}),r},co=t=>{let e=t._start,r=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(r===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};r=e.content.getContent(),n=0,e=e.right}let s=r[n++];return r.length<=n&&(r=null),{done:!1,value:s}}}},is=(t,e)=>{t.doc??x();let r=ke(t,e),n=t._start;for(r!==null&&(n=r.p,e-=r.index);n!==null;n=n.right)if(!n.deleted&&n.countable){if(e<n.length)return n.content.getContent()[e];e-=n.length}},te=(t,e,r,n)=>{let s=r,i=t.doc,l=i.clientID,o=i.store,c=r===null?e._start:r.right,u=[],a=()=>{u.length>0&&(s=new b(m(l,_(o,l)),s,s&&s.lastId,c,c&&c.id,e,null,new re(u)),s.integrate(t,0),u=[])};n.forEach(h=>{if(h===null)u.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(h);break;default:switch(a(),h.constructor){case Uint8Array:case ArrayBuffer:s=new b(m(l,_(o,l)),s,s&&s.lastId,c,c&&c.id,e,null,new _r(new Uint8Array(h))),s.integrate(t,0);break;case fe:s=new b(m(l,_(o,l)),s,s&&s.lastId,c,c&&c.id,e,null,new vr(h)),s.integrate(t,0);break;default:if(h instanceof C)s=new b(m(l,_(o,l)),s,s&&s.lastId,c,c&&c.id,e,null,new Q(h)),s.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},ls=()=>J("Length exceeded!"),os=(t,e,r,n)=>{if(r>e._length)throw ls();if(r===0)return e._searchMarker&&It(e._searchMarker,r,n.length),te(t,e,null,n);let s=r,i=ke(e,r),l=e._start;for(i!==null&&(l=i.p,r-=i.index,r===0&&(l=l.prev,r+=l&&l.countable&&!l.deleted?l.length:0));l!==null;l=l.right)if(!l.deleted&&l.countable){if(r<=l.length){r<l.length&&U(t,m(l.id.client,l.id.clock+r));break}r-=l.length}return e._searchMarker&&It(e._searchMarker,s,n.length),te(t,e,l,n)},ao=(t,e,r)=>{let n=(e._searchMarker||[]).reduce((s,i)=>i.index>s.index?i:s,{index:0,p:e._start}).p;if(n)for(;n.right;)n=n.right;return te(t,e,n,r)},cs=(t,e,r,n)=>{if(n===0)return;let s=r,i=n,l=ke(e,r),o=e._start;for(l!==null&&(o=l.p,r-=l.index);o!==null&&r>0;o=o.right)!o.deleted&&o.countable&&(r<o.length&&U(t,m(o.id.client,o.id.clock+r)),r-=o.length);for(;n>0&&o!==null;)o.deleted||(n<o.length&&U(t,m(o.id.client,o.id.clock+n)),o.delete(t),n-=o.length),o=o.right;if(n>0)throw ls();e._searchMarker&&It(e._searchMarker,s,-i+n)},ee=(t,e,r)=>{let n=e._map.get(r);n!==void 0&&n.delete(t)},pr=(t,e,r,n)=>{let s=e._map.get(r)||null,i=t.doc,l=i.clientID,o;if(n==null)o=new re([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new re([n]);break;case Uint8Array:o=new _r(n);break;case fe:o=new vr(n);break;default:if(n instanceof C)o=new Q(n);else throw new Error("Unexpected content type")}new b(m(l,_(i.store,l)),s,s&&s.lastId,null,null,e,r,o).integrate(t,0)},wr=(t,e)=>{t.doc??x();let r=t._map.get(e);return r!==void 0&&!r.deleted?r.content.getContent()[r.length-1]:void 0},as=t=>{let e={};return t.doc??x(),t._map.forEach((r,n)=>{r.deleted||(e[n]=r.content.getContent()[r.length-1])}),e},hs=(t,e)=>{t.doc??x();let r=t._map.get(e);return r!==void 0&&!r.deleted};var ho=(t,e)=>{let r={};return t._map.forEach((n,s)=>{let i=n;for(;i!==null&&(!e.sv.has(i.id.client)||i.id.clock>=(e.sv.get(i.id.client)||0));)i=i.left;i!==null&<(i,e)&&(r[s]=i.content.getContent()[i.length-1])}),r},Pt=t=>(t.doc??x(),Sl(t._map.entries(),e=>!e[1].deleted)),uo=class extends me{},us=class Yt extends C{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let r=new Yt;return r.push(e),r}_integrate(e,r){super._integrate(e,r),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Yt}clone(){let e=new Yt;return e.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),e}get length(){return this.doc??x(),this._length}_callObserver(e,r){super._callObserver(e,r),ye(this,e,new uo(this,e))}insert(e,r){this.doc!==null?y(this.doc,n=>{os(n,this,e,r)}):this._prelimContent.splice(e,0,...r)}push(e){this.doc!==null?y(this.doc,r=>{ao(r,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,r=1){this.doc!==null?y(this.doc,n=>{cs(n,this,e,r)}):this._prelimContent.splice(e,r)}get(e){return is(this,e)}toArray(){return ns(this)}slice(e=0,r=this.length){return rs(this,e,r)}toJSON(){return this.map(e=>e instanceof C?e.toJSON():e)}map(e){return ss(this,e)}forEach(e){Ut(this,e)}[Symbol.iterator](){return co(this)}_write(e){e.writeTypeRef(jo)}},go=t=>new us,fo=class extends me{constructor(t,e,r){super(t,e),this.keysChanged=r}},mr=class Re extends C{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,r){super._integrate(e,r),this._prelimContent.forEach((n,s)=>{this.set(s,n)}),this._prelimContent=null}_copy(){return new Re}clone(){let e=new Re;return this.forEach((r,n)=>{e.set(n,r instanceof C?r.clone():r)}),e}_callObserver(e,r){ye(this,e,new fo(this,e,r))}toJSON(){this.doc??x();let e={};return this._map.forEach((r,n)=>{if(!r.deleted){let s=r.content.getContent()[r.length-1];e[n]=s instanceof C?s.toJSON():s}}),e}get size(){return[...Pt(this)].length}keys(){return De(Pt(this),e=>e[0])}values(){return De(Pt(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return De(Pt(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??x(),this._map.forEach((r,n)=>{r.deleted||e(r.content.getContent()[r.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?y(this.doc,r=>{ee(r,this,e)}):this._prelimContent.delete(e)}set(e,r){return this.doc!==null?y(this.doc,n=>{pr(n,this,e,r)}):this._prelimContent.set(e,r),r}get(e){return wr(this,e)}has(e){return hs(this,e)}clear(){this.doc!==null?y(this.doc,e=>{this.forEach(function(r,n,s){ee(e,s,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(zo)}},po=t=>new mr,H=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&bi(t,e),Ve=class{constructor(t,e,r,n){this.left=t,this.right=e,this.index=r,this.currentAttributes=n}forward(){this.right===null&&O(),this.right.content.constructor===A?this.right.deleted||bt(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},Hr=(t,e,r)=>{for(;e.right!==null&&r>0;)e.right.content.constructor===A?e.right.deleted||bt(e.currentAttributes,e.right.content):e.right.deleted||(r<e.right.length&&U(t,m(e.right.id.client,e.right.id.clock+r)),e.index+=e.right.length,r-=e.right.length),e.left=e.right,e.right=e.right.right;return e},jt=(t,e,r,n)=>{let s=new Map,i=n?ke(e,r):null;if(i){let l=new Ve(i.p.left,i.p,i.index,s);return Hr(t,l,r-i.index)}else{let l=new Ve(null,e._start,0,s);return Hr(t,l,r)}},ds=(t,e,r,n)=>{for(;r.right!==null&&(r.right.deleted===!0||r.right.content.constructor===A&&H(n.get(r.right.content.key),r.right.content.value));)r.right.deleted||n.delete(r.right.content.key),r.forward();let s=t.doc,i=s.clientID;n.forEach((l,o)=>{let c=r.left,u=r.right,a=new b(m(i,_(s.store,i)),c,c&&c.lastId,u,u&&u.id,e,null,new A(o,l));a.integrate(t,0),r.right=a,r.forward()})},bt=(t,e)=>{let{key:r,value:n}=e;n===null?t.delete(r):t.set(r,n)},gs=(t,e)=>{for(;t.right!==null&&(t.right.deleted||t.right.content.constructor===A&&H(e[t.right.content.key]??null,t.right.content.value));)t.forward()},fs=(t,e,r,n)=>{let s=t.doc,i=s.clientID,l=new Map;for(let o in n){let c=n[o],u=r.currentAttributes.get(o)??null;if(!H(u,c)){l.set(o,u);let{left:a,right:h}=r;r.right=new b(m(i,_(s.store,i)),a,a&&a.lastId,h,h&&h.id,e,null,new A(o,c)),r.right.integrate(t,0),r.forward()}}return l},Ae=(t,e,r,n,s)=>{r.currentAttributes.forEach((d,g)=>{s[g]===void 0&&(s[g]=null)});let i=t.doc,l=i.clientID;gs(r,s);let o=fs(t,e,r,s),c=n.constructor===String?new rt(n):n instanceof C?new Q(n):new Rt(n),{left:u,right:a,index:h}=r;e._searchMarker&&It(e._searchMarker,r.index,c.getLength()),a=new b(m(l,_(i.store,l)),u,u&&u.lastId,a,a&&a.id,e,null,c),a.integrate(t,0),r.right=a,r.index=h,r.forward(),ds(t,e,r,o)},Gr=(t,e,r,n,s)=>{let i=t.doc,l=i.clientID;gs(r,s);let o=fs(t,e,r,s);t:for(;r.right!==null&&(n>0||o.size>0&&(r.right.deleted||r.right.content.constructor===A));){if(!r.right.deleted)switch(r.right.content.constructor){case A:{let{key:c,value:u}=r.right.content,a=s[c];if(a!==void 0){if(H(a,u))o.delete(c);else{if(n===0)break t;o.set(c,u)}r.right.delete(t)}else r.currentAttributes.set(c,u);break}default:n<r.right.length&&U(t,m(r.right.id.client,r.right.id.clock+n)),n-=r.right.length;break}r.forward()}if(n>0){let c="";for(;n>0;n--)c+=`
|
|
4
4
|
`;r.right=new b(m(l,_(i.store,l)),r.left,r.left&&r.left.lastId,r.right,r.right&&r.right.id,e,null,new rt(c)),r.right.integrate(t,0),r.forward()}ds(t,e,r,o)},ps=(t,e,r,n,s)=>{let i=e,l=F();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===A){let u=i.content;l.set(u.key,u)}i=i.right}let o=0,c=!1;for(;e!==i;){if(r===e&&(c=!0),!e.deleted){let u=e.content;if(u.constructor===A){let{key:a,value:h}=u,d=n.get(a)??null;(l.get(a)!==u||d===h)&&(e.delete(t),o++,!c&&(s.get(a)??null)===h&&d!==h&&(d===null?s.delete(a):s.set(a,d))),!c&&!e.deleted&&bt(s,u)}}e=e.right}return o},wo=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let r=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===A){let n=e.content.key;r.has(n)?e.delete(t):r.add(n)}e=e.left}},mo=t=>{let e=0;return y(t.doc,r=>{let n=t._start,s=t._start,i=F(),l=Ie(i);for(;s;)s.deleted===!1&&(s.content.constructor===A?bt(l,s.content):(e+=ps(r,n,s,i,l),i=Ie(l),n=s)),s=s.right}),e},ko=t=>{let e=new Set,r=t.doc;for(let[n,s]of t.afterState.entries()){let i=t.beforeState.get(n)||0;s!==i&&qn(t,r.store.clients.get(n),i,s,l=>{!l.deleted&&l.content.constructor===A&&l.constructor!==L&&e.add(l.parent)})}y(r,n=>{pt(t,t.deleteSet,s=>{if(s instanceof L||!s.parent._hasFormatting||e.has(s.parent))return;let i=s.parent;s.content.constructor===A?e.add(i):wo(n,s)});for(let s of e)mo(s)})},Xr=(t,e,r)=>{let n=r,s=Ie(e.currentAttributes),i=e.right;for(;r>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Q:case Rt:case rt:r<e.right.length&&U(t,m(e.right.id.client,e.right.id.clock+r)),r-=e.right.length,e.right.delete(t);break}e.forward()}i&&ps(t,i,e.right,s,e.currentAttributes);let l=(e.left||e.right).parent;return l._searchMarker&&It(l._searchMarker,e.index,-n+r),e},yo=class extends me{constructor(t,e,r){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(n=>{n===null?this.childListChanged=!0:this.keysChanged.add(n)})}get changes(){if(this._changes===null){let t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){let t=this.target.doc,e=[];y(t,r=>{let n=new Map,s=new Map,i=this.target._start,l=null,o={},c="",u=0,a=0,h=()=>{if(l!==null){let d=null;switch(l){case"delete":a>0&&(d={delete:a}),a=0;break;case"insert":(typeof c=="object"||c.length>0)&&(d={insert:c},n.size>0&&(d.attributes={},n.forEach((g,f)=>{g!==null&&(d.attributes[f]=g)}))),c="";break;case"retain":u>0&&(d={retain:u},yi(o)||(d.attributes=wi({},o))),u=0;break}d&&e.push(d),l=null}};for(;i!==null;){switch(i.content.constructor){case Q:case Rt:this.adds(i)?this.deletes(i)||(h(),l="insert",c=i.content.getContent()[0],h()):this.deletes(i)?(l!=="delete"&&(h(),l="delete"),a+=1):i.deleted||(l!=="retain"&&(h(),l="retain"),u+=1);break;case rt:this.adds(i)?this.deletes(i)||(l!=="insert"&&(h(),l="insert"),c+=i.content.str):this.deletes(i)?(l!=="delete"&&(h(),l="delete"),a+=i.length):i.deleted||(l!=="retain"&&(h(),l="retain"),u+=i.length);break;case A:{let{key:d,value:g}=i.content;if(this.adds(i)){if(!this.deletes(i)){let f=n.get(d)??null;H(f,g)?g!==null&&i.delete(r):(l==="retain"&&h(),H(g,s.get(d)??null)?delete o[d]:o[d]=g)}}else if(this.deletes(i)){s.set(d,g);let f=n.get(d)??null;H(f,g)||(l==="retain"&&h(),o[d]=f)}else if(!i.deleted){s.set(d,g);let f=o[d];f!==void 0&&(H(f,g)?f!==null&&i.delete(r):(l==="retain"&&h(),g===null?delete o[d]:o[d]=g))}i.deleted||(l==="insert"&&h(),bt(n,i.content));break}}i=i.right}for(h();e.length>0;){let d=e[e.length-1];if(d.retain!==void 0&&d.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}},kr=class Fe extends C{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??x(),this._length}_integrate(e,r){super._integrate(e,r);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new Fe}clone(){let e=new Fe;return e.applyDelta(this.toDelta()),e}_callObserver(e,r){super._callObserver(e,r);let n=new yo(this,e,r);ye(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??x();let e="",r=this._start;for(;r!==null;)!r.deleted&&r.countable&&r.content.constructor===rt&&(e+=r.content.str),r=r.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:r=!0}={}){this.doc!==null?y(this.doc,n=>{let s=new Ve(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let l=e[i];if(l.insert!==void 0){let o=!r&&typeof l.insert=="string"&&i===e.length-1&&s.right===null&&l.insert.slice(-1)===`
|
|
5
|
-
`?l.insert.slice(0,-1):l.insert;(typeof o!="string"||o.length>0)&&Ae(n,this,s,o,l.attributes||{})}else l.retain!==void 0?Gr(n,this,s,l.retain,l.attributes||{}):l.delete!==void 0&&Xr(n,s,l.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,r,n){this.doc??x();let s=[],i=new Map,l=this.doc,o="",c=this._start;function u(){if(o.length>0){let h={},d=!1;i.forEach((f,k)=>{d=!0,h[k]=f});let g={insert:o};d&&(g.attributes=h),s.push(g),o=""}}let a=()=>{for(;c!==null;){if(lt(c,e)||r!==void 0&<(c,r))switch(c.content.constructor){case rt:{let h=i.get("ychange");e!==void 0&&!lt(c,e)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(u(),i.set("ychange",n?n("removed",c.id):{type:"removed"})):r!==void 0&&!lt(c,r)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(u(),i.set("ychange",n?n("added",c.id):{type:"added"})):h!==void 0&&(u(),i.delete("ychange")),o+=c.content.str;break}case Q:case Rt:{u();let h={insert:c.content.getContent()[0]};if(i.size>0){let d={};h.attributes=d,i.forEach((g,f)=>{d[f]=g})}s.push(h);break}case A:lt(c,e)&&(u(),bt(i,c.content));break}c=c.right}u()};return e||r?y(l,h=>{e&&Ne(h,e),r&&Ne(h,r),a()},"cleanup"):a(),s}insert(e,r,n){if(r.length<=0)return;let s=this.doc;s!==null?y(s,i=>{let l=jt(i,this,e,!n);n||(n={},l.currentAttributes.forEach((o,c)=>{n[c]=o})),Ae(i,this,l,r,n)}):this._pending.push(()=>this.insert(e,r,n))}insertEmbed(e,r,n){let s=this.doc;s!==null?y(s,i=>{let l=jt(i,this,e,!n);Ae(i,this,l,r,n||{})}):this._pending.push(()=>this.insertEmbed(e,r,n||{}))}delete(e,r){if(r===0)return;let n=this.doc;n!==null?y(n,s=>{Xr(s,jt(s,this,e,!0),r)}):this._pending.push(()=>this.delete(e,r))}format(e,r,n){if(r===0)return;let s=this.doc;s!==null?y(s,i=>{let l=jt(i,this,e,!1);l.right!==null&&Gr(i,this,l,r,n)}):this._pending.push(()=>this.format(e,r,n))}removeAttribute(e){this.doc!==null?y(this.doc,r=>{ee(r,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,r){this.doc!==null?y(this.doc,n=>{pr(n,this,e,r)}):this._pending.push(()=>this.setAttribute(e,r))}getAttribute(e){return wr(this,e)}getAttributes(){return as(this)}_write(e){e.writeTypeRef(Jo)}},bo=t=>new kr,xe=class{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??x()}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===yr||e.constructor===be)&&e._start!==null)t=e._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}},be=class Pe extends C{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,r){super._integrate(e,r),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Pe}clone(){let e=new Pe;return e.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),e}get length(){return this.doc??x(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new xe(this,e)}querySelector(e){e=e.toUpperCase();let r=new xe(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),G(new xe(this,r=>r.nodeName&&r.nodeName.toUpperCase()===e))}_callObserver(e,r){ye(this,e,new So(this,r,e))}toString(){return ss(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,r={},n){let s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ut(this,i=>{s.insertBefore(i.toDOM(e,r,n),null)}),s}insert(e,r){this.doc!==null?y(this.doc,n=>{os(n,this,e,r)}):this._prelimContent.splice(e,0,...r)}insertAfter(e,r){if(this.doc!==null)y(this.doc,n=>{let s=e&&e instanceof C?e._item:e;te(n,this,s,r)});else{let n=this._prelimContent,s=e===null?0:n.findIndex(i=>i===e)+1;if(s===0&&e!==null)throw J("Reference item not found");n.splice(s,0,...r)}}delete(e,r=1){this.doc!==null?y(this.doc,n=>{cs(n,this,e,r)}):this._prelimContent.splice(e,r)}toArray(){return ns(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return is(this,e)}slice(e=0,r=this.length){return rs(this,e,r)}forEach(e){Ut(this,e)}_write(e){e.writeTypeRef(Bo)}},_o=t=>new be,yr=class je extends be{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,r){super._integrate(e,r),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new je(this.nodeName)}clone(){let e=new je(this.nodeName),r=this.getAttributes();return ki(r,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof C?n.clone():n)),e}toString(){let e=this.getAttributes(),r=[],n=[];for(let o in e)n.push(o);n.sort();let s=n.length;for(let o=0;o<s;o++){let c=n[o];r.push(c+'="'+e[c]+'"')}let i=this.nodeName.toLocaleLowerCase(),l=r.length>0?" "+r.join(" "):"";return`<${i}${l}>${super.toString()}</${i}>`}removeAttribute(e){this.doc!==null?y(this.doc,r=>{ee(r,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,r){this.doc!==null?y(this.doc,n=>{pr(n,this,e,r)}):this._prelimAttrs.set(e,r)}getAttribute(e){return wr(this,e)}hasAttribute(e){return hs(this,e)}getAttributes(e){return e?ho(this,e):as(this)}toDOM(e=document,r={},n){let s=e.createElement(this.nodeName),i=this.getAttributes();for(let l in i){let o=i[l];typeof o=="string"&&s.setAttribute(l,o)}return Ut(this,l=>{s.appendChild(l.toDOM(e,r,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef($o),e.writeKey(this.nodeName)}},vo=t=>new yr(t.readKey()),So=class extends me{constructor(t,e,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(n=>{n===null?this.childListChanged=!0:this.attributesChanged.add(n)})}},Eo=class ze extends mr{constructor(e){super(),this.hookName=e}_copy(){return new ze(this.hookName)}clone(){let e=new ze(this.hookName);return this.forEach((r,n)=>{e.set(n,r)}),e}toDOM(e=document,r={},n){let s=r[this.hookName],i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Wo),e.writeKey(this.hookName)}},Co=t=>new Eo(t.readKey()),Do=class Je extends kr{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Je}clone(){let e=new Je;return e.applyDelta(this.toDelta()),e}toDOM(e=document,r,n){let s=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(s,this),s}toString(){return this.toDelta().map(e=>{let r=[];for(let s in e.attributes){let i=[];for(let l in e.attributes[s])i.push({key:l,value:e.attributes[s][l]});i.sort((l,o)=>l.key<o.key?-1:1),r.push({nodeName:s,attrs:i})}r.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let n="";for(let s=0;s<r.length;s++){let i=r[s];n+=`<${i.nodeName}`;for(let l=0;l<i.attrs.length;l++){let o=i.attrs[l];n+=` ${o.key}="${o.value}"`}n+=">"}n+=e.insert;for(let s=r.length-1;s>=0;s--)n+=`</${r[s].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Yo)}},Ao=t=>new Do,br=class{constructor(t,e){this.id=t,this.length=e}get deleted(){throw P()}mergeWith(t){return!1}write(t,e,r){throw P()}integrate(t,e){throw P()}},xo=0,L=class extends br{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),Xn(t.doc.store,this)}write(t,e){t.writeInfo(xo),t.writeLen(this.length-e)}getMissing(t,e){return null}},_r=class ws{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ws(this.content)}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){}delete(e){}gc(e){}write(e,r){e.writeBuf(this.content)}getRef(){return 3}},Io=t=>new _r(t.readBuf()),ms=class $e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new $e(this.len)}splice(e){let r=new $e(this.len-e);return this.len=e,r}mergeWith(e){return this.len+=e.len,!0}integrate(e,r){xt(e.deleteSet,r.id.client,r.id.clock,this.len),r.markDeleted()}delete(e){}gc(e){}write(e,r){e.writeLen(this.len-r)}getRef(){return 1}},Uo=t=>new ms(t.readLen()),ks=(t,e)=>new fe({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),vr=class ys{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let r={};this.opts=r,e.gc||(r.gc=!1),e.autoLoad&&(r.autoLoad=!0),e.meta!==null&&(r.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ys(ks(this.doc.guid,this.opts))}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){this.doc._item=r,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,r){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},Oo=t=>new vr(ks(t.readString(),t.readAny())),Rt=class bs{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new bs(this.embed)}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){}delete(e){}gc(e){}write(e,r){e.writeJSON(this.embed)}getRef(){return 5}},Mo=t=>new Rt(t.readJSON()),A=class _s{constructor(e,r){this.key=e,this.value=r}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new _s(this.key,this.value)}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){let n=r.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,r){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},To=t=>new A(t.readKey(),t.readJSON()),No=class Be{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Be(this.arr)}splice(e){let r=new Be(this.arr.slice(e));return this.arr=this.arr.slice(0,e),r}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,r){}delete(e){}gc(e){}write(e,r){let n=this.arr.length;e.writeLen(n-r);for(let s=r;s<n;s++){let i=this.arr[s];e.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}},Lo=t=>{let e=t.readLen(),r=[];for(let n=0;n<e;n++){let s=t.readString();s==="undefined"?r.push(void 0):r.push(JSON.parse(s))}return new No(r)},Ro=Gt("node_env")==="development",re=class We{constructor(e){this.arr=e,Ro&&cn(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new We(this.arr)}splice(e){let r=new We(this.arr.slice(e));return this.arr=this.arr.slice(0,e),r}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,r){}delete(e){}gc(e){}write(e,r){let n=this.arr.length;e.writeLen(n-r);for(let s=r;s<n;s++){let i=this.arr[s];e.writeAny(i)}}getRef(){return 8}},Vo=t=>{let e=t.readLen(),r=[];for(let n=0;n<e;n++)r.push(t.readAny());return new re(r)},rt=class Ye{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Ye(this.str)}splice(e){let r=new Ye(this.str.slice(e));this.str=this.str.slice(0,e);let n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",r.str="\uFFFD"+r.str.slice(1)),r}mergeWith(e){return this.str+=e.str,!0}integrate(e,r){}delete(e){}gc(e){}write(e,r){e.writeString(r===0?this.str:this.str.slice(r))}getRef(){return 4}},Fo=t=>new rt(t.readString()),Po=[go,po,bo,vo,_o,Co,Ao],jo=0,zo=1,Jo=2,$o=3,Bo=4,Wo=5,Yo=6,Q=class vs{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new vs(this.type._copy())}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){this.type._integrate(e.doc,r)}delete(e){let r=this.type._start;for(;r!==null;)r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e),r=r.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e)}),e.changed.delete(this.type)}gc(e){let r=this.type._start;for(;r!==null;)r.gc(e,!0),r=r.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,r){this.type._write(e)}getRef(){return 7}},Ko=t=>new Q(Po[t.readTypeRef()](t)),Ke=(t,e)=>{let r=e,n=0,s;do n>0&&(r=m(r.client,r.clock+n)),s=at(t,r),n=r.clock-s.id.clock,r=s.redone;while(r!==null&&s instanceof b);return{item:s,diff:n}},Sr=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},ne=(t,e,r)=>{let{client:n,clock:s}=e.id,i=new b(m(n,s+r),e,m(n,s+r-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(r));return e.deleted&&i.markDeleted(),e.keep&&(i.keep=!0),e.redone!==null&&(i.redone=m(e.redone.client,e.redone.clock+r)),e.right=i,i.right!==null&&(i.right.left=i),t._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),e.length=r,i},qr=(t,e)=>qe(t,r=>Nt(r.deletions,e)),Ss=(t,e,r,n,s,i)=>{let l=t.doc,o=l.store,c=l.clientID,u=e.redone;if(u!==null)return U(t,u);let a=e.parent._item,h=null,d;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!r.has(a)||Ss(t,a,r,n,s,i)===null))return null;for(;a.redone!==null;)a=U(t,a.redone)}let g=a===null?e.parent:a.content.type;if(e.parentSub===null){for(h=e.left,d=e;h!==null;){let v=h;for(;v!==null&&v.parent._item!==a;)v=v.redone===null?null:U(t,v.redone);if(v!==null&&v.parent._item===a){h=v;break}h=h.left}for(;d!==null;){let v=d;for(;v!==null&&v.parent._item!==a;)v=v.redone===null?null:U(t,v.redone);if(v!==null&&v.parent._item===a){d=v;break}d=d.right}}else if(d=null,e.right&&!s){for(h=e;h!==null&&h.right!==null&&(h.right.redone||Nt(n,h.right.id)||qr(i.undoStack,h.right.id)||qr(i.redoStack,h.right.id));)for(h=h.right;h.redone;)h=U(t,h.redone);if(h&&h.right!==null)return null}else h=g._map.get(e.parentSub)||null;let f=_(o,c),k=m(c,f),V=new b(k,h,h&&h.lastId,d,d&&d.id,g,e.parentSub,e.content.copy());return e.redone=k,Sr(V,!0),V.integrate(t,0),V},b=class He extends br{constructor(e,r,n,s,i,l,o,c){super(e,c.getLength()),this.origin=n,this.left=r,this.right=s,this.rightOrigin=i,this.parent=l,this.parentSub=o,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,r){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=_(r,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=_(r,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ct&&this.id.client!==this.parent.client&&this.parent.clock>=_(r,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Jr(e,r,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=U(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===L||this.right&&this.right.constructor===L)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===He?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===He&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ct){let n=at(r,this.parent);n.constructor===L?this.parent=null:this.parent=n.content.type}return null}integrate(e,r){if(r>0&&(this.id.clock+=r,this.left=Jr(e,e.doc.store,m(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(r),this.length-=r),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let i=new Set,l=new Set;for(;s!==null&&s!==this.right;){if(l.add(s),i.add(s),Vt(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,i.clear();else if(Vt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&l.has(at(e.doc.store,s.origin)))i.has(at(e.doc.store,s.origin))||(n=s,i.clear());else break;s=s.right}this.left=n}if(this.left!==null){let n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Xn(e.doc.store,this),this.content.integrate(e,this),Br(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new L(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:m(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Vt(e.origin,this.lastId)&&this.right===e&&Vt(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let r=this.parent._searchMarker;return r&&r.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let r=this.parent;this.countable&&this.parentSub===null&&(r._length-=this.length),this.markDeleted(),xt(e.deleteSet,this.id.client,this.id.clock,this.length),Br(e,r,this.parentSub),this.content.delete(e)}}gc(e,r){if(!this.deleted)throw O();this.content.gc(e),r?Kl(e,this,new L(this.id,this.length)):this.content=new ms(this.length)}write(e,r){let n=r>0?m(this.id.client,this.id.clock+r-1):this.origin,s=this.rightOrigin,i=this.parentSub,l=this.content.getRef()&31|(n===null?0:128)|(s===null?0:64)|(i===null?0:32);if(e.writeInfo(l),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){let o=this.parent;if(o._item!==void 0){let c=o._item;if(c===null){let u=Kn(o);e.writeParentInfo(!0),e.writeString(u)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else o.constructor===String?(e.writeParentInfo(!0),e.writeString(o)):o.constructor===ct?(e.writeParentInfo(!1),e.writeLeftID(o)):O();i!==null&&e.writeString(i)}this.content.write(e,r)}},Es=(t,e)=>Ho[e&31](t),Ho=[()=>{O()},Uo,Lo,Io,Fo,Mo,To,Ko,Vo,Oo,()=>{O()}],Go=10,N=class extends br{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){O()}write(t,e){t.writeInfo(Go),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}},Cs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Ds="__ $YJS$ __";Cs[Ds]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Cs[Ds]=!0;export{ic as a,lc as b,pt as c,Cl as d,Uc as e,fe as f,Tl as g,Oc as h,Bn as i,Mc as j,Tc as k,Nc as l,Lc as m,Rc as n,at as o,Fc as p,Pc as q,jc as r,Zt as s,C as t,mr as u,Rt as v,A as w,rt as x,b as y,N as z};
|
|
5
|
+
`?l.insert.slice(0,-1):l.insert;(typeof o!="string"||o.length>0)&&Ae(n,this,s,o,l.attributes||{})}else l.retain!==void 0?Gr(n,this,s,l.retain,l.attributes||{}):l.delete!==void 0&&Xr(n,s,l.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,r,n){this.doc??x();let s=[],i=new Map,l=this.doc,o="",c=this._start;function u(){if(o.length>0){let h={},d=!1;i.forEach((f,k)=>{d=!0,h[k]=f});let g={insert:o};d&&(g.attributes=h),s.push(g),o=""}}let a=()=>{for(;c!==null;){if(lt(c,e)||r!==void 0&<(c,r))switch(c.content.constructor){case rt:{let h=i.get("ychange");e!==void 0&&!lt(c,e)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(u(),i.set("ychange",n?n("removed",c.id):{type:"removed"})):r!==void 0&&!lt(c,r)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(u(),i.set("ychange",n?n("added",c.id):{type:"added"})):h!==void 0&&(u(),i.delete("ychange")),o+=c.content.str;break}case Q:case Rt:{u();let h={insert:c.content.getContent()[0]};if(i.size>0){let d={};h.attributes=d,i.forEach((g,f)=>{d[f]=g})}s.push(h);break}case A:lt(c,e)&&(u(),bt(i,c.content));break}c=c.right}u()};return e||r?y(l,h=>{e&&Ne(h,e),r&&Ne(h,r),a()},"cleanup"):a(),s}insert(e,r,n){if(r.length<=0)return;let s=this.doc;s!==null?y(s,i=>{let l=jt(i,this,e,!n);n||(n={},l.currentAttributes.forEach((o,c)=>{n[c]=o})),Ae(i,this,l,r,n)}):this._pending.push(()=>this.insert(e,r,n))}insertEmbed(e,r,n){let s=this.doc;s!==null?y(s,i=>{let l=jt(i,this,e,!n);Ae(i,this,l,r,n||{})}):this._pending.push(()=>this.insertEmbed(e,r,n||{}))}delete(e,r){if(r===0)return;let n=this.doc;n!==null?y(n,s=>{Xr(s,jt(s,this,e,!0),r)}):this._pending.push(()=>this.delete(e,r))}format(e,r,n){if(r===0)return;let s=this.doc;s!==null?y(s,i=>{let l=jt(i,this,e,!1);l.right!==null&&Gr(i,this,l,r,n)}):this._pending.push(()=>this.format(e,r,n))}removeAttribute(e){this.doc!==null?y(this.doc,r=>{ee(r,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,r){this.doc!==null?y(this.doc,n=>{pr(n,this,e,r)}):this._pending.push(()=>this.setAttribute(e,r))}getAttribute(e){return wr(this,e)}getAttributes(){return as(this)}_write(e){e.writeTypeRef(Jo)}},bo=t=>new kr,xe=class{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??x()}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===yr||e.constructor===be)&&e._start!==null)t=e._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}},be=class Pe extends C{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,r){super._integrate(e,r),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Pe}clone(){let e=new Pe;return e.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),e}get length(){return this.doc??x(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new xe(this,e)}querySelector(e){e=e.toUpperCase();let r=new xe(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),G(new xe(this,r=>r.nodeName&&r.nodeName.toUpperCase()===e))}_callObserver(e,r){ye(this,e,new So(this,r,e))}toString(){return ss(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,r={},n){let s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ut(this,i=>{s.insertBefore(i.toDOM(e,r,n),null)}),s}insert(e,r){this.doc!==null?y(this.doc,n=>{os(n,this,e,r)}):this._prelimContent.splice(e,0,...r)}insertAfter(e,r){if(this.doc!==null)y(this.doc,n=>{let s=e&&e instanceof C?e._item:e;te(n,this,s,r)});else{let n=this._prelimContent,s=e===null?0:n.findIndex(i=>i===e)+1;if(s===0&&e!==null)throw J("Reference item not found");n.splice(s,0,...r)}}delete(e,r=1){this.doc!==null?y(this.doc,n=>{cs(n,this,e,r)}):this._prelimContent.splice(e,r)}toArray(){return ns(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return is(this,e)}slice(e=0,r=this.length){return rs(this,e,r)}forEach(e){Ut(this,e)}_write(e){e.writeTypeRef(Bo)}},_o=t=>new be,yr=class je extends be{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,r){super._integrate(e,r),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new je(this.nodeName)}clone(){let e=new je(this.nodeName),r=this.getAttributes();return ki(r,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof C?n.clone():n)),e}toString(){let e=this.getAttributes(),r=[],n=[];for(let o in e)n.push(o);n.sort();let s=n.length;for(let o=0;o<s;o++){let c=n[o];r.push(c+'="'+e[c]+'"')}let i=this.nodeName.toLocaleLowerCase(),l=r.length>0?" "+r.join(" "):"";return`<${i}${l}>${super.toString()}</${i}>`}removeAttribute(e){this.doc!==null?y(this.doc,r=>{ee(r,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,r){this.doc!==null?y(this.doc,n=>{pr(n,this,e,r)}):this._prelimAttrs.set(e,r)}getAttribute(e){return wr(this,e)}hasAttribute(e){return hs(this,e)}getAttributes(e){return e?ho(this,e):as(this)}toDOM(e=document,r={},n){let s=e.createElement(this.nodeName),i=this.getAttributes();for(let l in i){let o=i[l];typeof o=="string"&&s.setAttribute(l,o)}return Ut(this,l=>{s.appendChild(l.toDOM(e,r,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef($o),e.writeKey(this.nodeName)}},vo=t=>new yr(t.readKey()),So=class extends me{constructor(t,e,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(n=>{n===null?this.childListChanged=!0:this.attributesChanged.add(n)})}},Eo=class ze extends mr{constructor(e){super(),this.hookName=e}_copy(){return new ze(this.hookName)}clone(){let e=new ze(this.hookName);return this.forEach((r,n)=>{e.set(n,r)}),e}toDOM(e=document,r={},n){let s=r[this.hookName],i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Wo),e.writeKey(this.hookName)}},Co=t=>new Eo(t.readKey()),Do=class Je extends kr{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Je}clone(){let e=new Je;return e.applyDelta(this.toDelta()),e}toDOM(e=document,r,n){let s=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(s,this),s}toString(){return this.toDelta().map(e=>{let r=[];for(let s in e.attributes){let i=[];for(let l in e.attributes[s])i.push({key:l,value:e.attributes[s][l]});i.sort((l,o)=>l.key<o.key?-1:1),r.push({nodeName:s,attrs:i})}r.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let n="";for(let s=0;s<r.length;s++){let i=r[s];n+=`<${i.nodeName}`;for(let l=0;l<i.attrs.length;l++){let o=i.attrs[l];n+=` ${o.key}="${o.value}"`}n+=">"}n+=e.insert;for(let s=r.length-1;s>=0;s--)n+=`</${r[s].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Yo)}},Ao=t=>new Do,br=class{constructor(t,e){this.id=t,this.length=e}get deleted(){throw P()}mergeWith(t){return!1}write(t,e,r){throw P()}integrate(t,e){throw P()}},xo=0,L=class extends br{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),Xn(t.doc.store,this)}write(t,e){t.writeInfo(xo),t.writeLen(this.length-e)}getMissing(t,e){return null}},_r=class ws{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ws(this.content)}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){}delete(e){}gc(e){}write(e,r){e.writeBuf(this.content)}getRef(){return 3}},Io=t=>new _r(t.readBuf()),ms=class $e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new $e(this.len)}splice(e){let r=new $e(this.len-e);return this.len=e,r}mergeWith(e){return this.len+=e.len,!0}integrate(e,r){xt(e.deleteSet,r.id.client,r.id.clock,this.len),r.markDeleted()}delete(e){}gc(e){}write(e,r){e.writeLen(this.len-r)}getRef(){return 1}},Uo=t=>new ms(t.readLen()),ks=(t,e)=>new fe({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),vr=class ys{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let r={};this.opts=r,e.gc||(r.gc=!1),e.autoLoad&&(r.autoLoad=!0),e.meta!==null&&(r.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ys(ks(this.doc.guid,this.opts))}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){this.doc._item=r,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,r){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},Oo=t=>new vr(ks(t.readString(),t.readAny())),Rt=class bs{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new bs(this.embed)}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){}delete(e){}gc(e){}write(e,r){e.writeJSON(this.embed)}getRef(){return 5}},Mo=t=>new Rt(t.readJSON()),A=class _s{constructor(e,r){this.key=e,this.value=r}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new _s(this.key,this.value)}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){let n=r.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,r){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},To=t=>new A(t.readKey(),t.readJSON()),No=class Be{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Be(this.arr)}splice(e){let r=new Be(this.arr.slice(e));return this.arr=this.arr.slice(0,e),r}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,r){}delete(e){}gc(e){}write(e,r){let n=this.arr.length;e.writeLen(n-r);for(let s=r;s<n;s++){let i=this.arr[s];e.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}},Lo=t=>{let e=t.readLen(),r=[];for(let n=0;n<e;n++){let s=t.readString();s==="undefined"?r.push(void 0):r.push(JSON.parse(s))}return new No(r)},Ro=Gt("node_env")==="development",re=class We{constructor(e){this.arr=e,Ro&&cn(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new We(this.arr)}splice(e){let r=new We(this.arr.slice(e));return this.arr=this.arr.slice(0,e),r}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,r){}delete(e){}gc(e){}write(e,r){let n=this.arr.length;e.writeLen(n-r);for(let s=r;s<n;s++){let i=this.arr[s];e.writeAny(i)}}getRef(){return 8}},Vo=t=>{let e=t.readLen(),r=[];for(let n=0;n<e;n++)r.push(t.readAny());return new re(r)},rt=class Ye{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Ye(this.str)}splice(e){let r=new Ye(this.str.slice(e));this.str=this.str.slice(0,e);let n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",r.str="\uFFFD"+r.str.slice(1)),r}mergeWith(e){return this.str+=e.str,!0}integrate(e,r){}delete(e){}gc(e){}write(e,r){e.writeString(r===0?this.str:this.str.slice(r))}getRef(){return 4}},Fo=t=>new rt(t.readString()),Po=[go,po,bo,vo,_o,Co,Ao],jo=0,zo=1,Jo=2,$o=3,Bo=4,Wo=5,Yo=6,Q=class vs{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new vs(this.type._copy())}splice(e){throw P()}mergeWith(e){return!1}integrate(e,r){this.type._integrate(e.doc,r)}delete(e){let r=this.type._start;for(;r!==null;)r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e),r=r.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e)}),e.changed.delete(this.type)}gc(e){let r=this.type._start;for(;r!==null;)r.gc(e,!0),r=r.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,r){this.type._write(e)}getRef(){return 7}},Ko=t=>new Q(Po[t.readTypeRef()](t)),Ke=(t,e)=>{let r=e,n=0,s;do n>0&&(r=m(r.client,r.clock+n)),s=at(t,r),n=r.clock-s.id.clock,r=s.redone;while(r!==null&&s instanceof b);return{item:s,diff:n}},Sr=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},ne=(t,e,r)=>{let{client:n,clock:s}=e.id,i=new b(m(n,s+r),e,m(n,s+r-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(r));return e.deleted&&i.markDeleted(),e.keep&&(i.keep=!0),e.redone!==null&&(i.redone=m(e.redone.client,e.redone.clock+r)),e.right=i,i.right!==null&&(i.right.left=i),t._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),e.length=r,i},qr=(t,e)=>qe(t,r=>Nt(r.deletions,e)),Ss=(t,e,r,n,s,i)=>{let l=t.doc,o=l.store,c=l.clientID,u=e.redone;if(u!==null)return U(t,u);let a=e.parent._item,h=null,d;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!r.has(a)||Ss(t,a,r,n,s,i)===null))return null;for(;a.redone!==null;)a=U(t,a.redone)}let g=a===null?e.parent:a.content.type;if(e.parentSub===null){for(h=e.left,d=e;h!==null;){let v=h;for(;v!==null&&v.parent._item!==a;)v=v.redone===null?null:U(t,v.redone);if(v!==null&&v.parent._item===a){h=v;break}h=h.left}for(;d!==null;){let v=d;for(;v!==null&&v.parent._item!==a;)v=v.redone===null?null:U(t,v.redone);if(v!==null&&v.parent._item===a){d=v;break}d=d.right}}else if(d=null,e.right&&!s){for(h=e;h!==null&&h.right!==null&&(h.right.redone||Nt(n,h.right.id)||qr(i.undoStack,h.right.id)||qr(i.redoStack,h.right.id));)for(h=h.right;h.redone;)h=U(t,h.redone);if(h&&h.right!==null)return null}else h=g._map.get(e.parentSub)||null;let f=_(o,c),k=m(c,f),V=new b(k,h,h&&h.lastId,d,d&&d.id,g,e.parentSub,e.content.copy());return e.redone=k,Sr(V,!0),V.integrate(t,0),V},b=class He extends br{constructor(e,r,n,s,i,l,o,c){super(e,c.getLength()),this.origin=n,this.left=r,this.right=s,this.rightOrigin=i,this.parent=l,this.parentSub=o,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,r){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=_(r,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=_(r,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ct&&this.id.client!==this.parent.client&&this.parent.clock>=_(r,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Jr(e,r,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=U(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===L||this.right&&this.right.constructor===L)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===He?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===He&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ct){let n=at(r,this.parent);n.constructor===L?this.parent=null:this.parent=n.content.type}return null}integrate(e,r){if(r>0&&(this.id.clock+=r,this.left=Jr(e,e.doc.store,m(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(r),this.length-=r),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let i=new Set,l=new Set;for(;s!==null&&s!==this.right;){if(l.add(s),i.add(s),Vt(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,i.clear();else if(Vt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&l.has(at(e.doc.store,s.origin)))i.has(at(e.doc.store,s.origin))||(n=s,i.clear());else break;s=s.right}this.left=n}if(this.left!==null){let n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Xn(e.doc.store,this),this.content.integrate(e,this),Br(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new L(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:m(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Vt(e.origin,this.lastId)&&this.right===e&&Vt(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let r=this.parent._searchMarker;return r&&r.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let r=this.parent;this.countable&&this.parentSub===null&&(r._length-=this.length),this.markDeleted(),xt(e.deleteSet,this.id.client,this.id.clock,this.length),Br(e,r,this.parentSub),this.content.delete(e)}}gc(e,r){if(!this.deleted)throw O();this.content.gc(e),r?Kl(e,this,new L(this.id,this.length)):this.content=new ms(this.length)}write(e,r){let n=r>0?m(this.id.client,this.id.clock+r-1):this.origin,s=this.rightOrigin,i=this.parentSub,l=this.content.getRef()&31|(n===null?0:128)|(s===null?0:64)|(i===null?0:32);if(e.writeInfo(l),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){let o=this.parent;if(o._item!==void 0){let c=o._item;if(c===null){let u=Kn(o);e.writeParentInfo(!0),e.writeString(u)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else o.constructor===String?(e.writeParentInfo(!0),e.writeString(o)):o.constructor===ct?(e.writeParentInfo(!1),e.writeLeftID(o)):O();i!==null&&e.writeString(i)}this.content.write(e,r)}},Es=(t,e)=>Ho[e&31](t),Ho=[()=>{O()},Uo,Lo,Io,Fo,Mo,To,Ko,Vo,Oo,()=>{O()}],Go=10,N=class extends br{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){O()}write(t,e){t.writeInfo(Go),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}},Cs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Ds="__ $YJS$ __";Cs[Ds]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Cs[Ds]=!0;export{ic as a,lc as b,pt as c,Nt as d,Te as e,Pn as f,Cl as g,Uc as h,fe as i,Tl as j,Oc as k,Bn as l,Mc as m,Tc as n,Nc as o,Lc as p,Rc as q,_ as r,at as s,Fc as t,Pc as u,jc as v,Zt as w,C as x,mr as y,Rt as z,A,rt as B,b as C,N as D};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as K}from"./c-
|
|
1
|
+
import{b as K}from"./c-SYOA4T7V.js";import{d as h}from"./c-3XGLJAS7.js";import{d as w,z as C}from"./c-OH2FPYSY.js";import{c as O}from"./c-FSQXFG5T.js";import"./c-RETTCOWO.js";import"./c-VHNSBD2M.js";var z=`
|
|
2
2
|
:where(article[data-blockeditor], .blockeditor-shell) { --blockeditor-board-lane: 274px; --blockeditor-board-gap: 14px; --blockeditor-board-radius: 8px; --blockeditor-board-panel: 360px; }
|
|
3
3
|
.blockeditor-editor .blockeditor-board { margin-block: 1.1em 1.5em; font-size: 15px; line-height: 1.4; white-space: normal; }
|
|
4
4
|
:is(.blockeditor-board, .blockeditor-board-panel) .i { flex: none; width: 16px; height: 16px; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ae}from"./c-7WZSUTYP.js";import{i as re,j as se}from"./c-LUBZU4AZ.js";import"./c-GO635CRU.js";import"./c-V2V5FKXX.js";import"./c-T7LOTEWO.js";import"./c-A3OKSYRI.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import{C as ce}from"./c-3Y234AUB.js";import{A as _,F as te,a as W,b as Y,d as V,ea as oe,ia as ne,o as Z,r as U,y as N,z as ee}from"./c-OH2FPYSY.js";import"./c-FSQXFG5T.js";import{b as Q}from"./c-RETTCOWO.js";import"./c-JC4RZW4E.js";import"./c-57XDY6HC.js";import{a as G}from"./c-I2SCCUEW.js";import"./c-PGSBXHUE.js";import"./c-VHNSBD2M.js";var ye="iframe, frame, frameset, object, embed, applet, meta, base, link, form, style, animate, set, animateMotion, animateTransform, portal",we=/^(srcdoc|data|formaction|codebase|archive|ping|background|poster|lowsrc|dynsrc)$/i,xe=/^\s*(javascript|vbscript|data):/i;function Me(o,a){let c=a.createElement("template");c.innerHTML=o;for(let d of c.content.querySelectorAll(ye))d.remove();for(let d of c.content.querySelectorAll("*"))for(let{name:h,value:m}of[...d.attributes])(we.test(h)||xe.test(m.replace(/[\u0000-\u0020]/g,"")))&&d.removeAttribute(h);return c.innerHTML}var H=2*1024*1024,le=32,ie=1e4,I=class extends Error{constructor(a,c){super(c),this.name="MarkdownImportError",this.code=a}},pe="\uFFFC",ue={type:"hard_break"},fe=new Set(["paragraph","heading","list","blockquote","code","table","hr","html","def","space"]),Se=new TextEncoder,de=V.marks,me=o=>o.slice().sort((a,c)=>a.type.rank-c.type.rank);function R(o,a,c){return o.some(d=>d.type===de[a])?o:me([...o,de[a].create(c)])}var he=/^(?![a-z][a-z0-9+.-]*:|[/#?])\S/i;function Ee(o,a){let c=typeof a=="function"?a(o):null;return typeof c=="string"&&c?W(c):he.test(o.trim())?null:W(o)}function Te(o,{images:a=!0,refused:c=[],unsupported:d=[],resolveLink:h=null}={}){let m=[],O="",v=[],q=()=>{O&&m.push({c:O,m:v}),O="",v=[]},M=($,k)=>{let u=String($??"");if(!u)return;let P=Z(me(k));O+=u;for(let b=0;b<u.length;b++)v.push(P)},S=$=>{O+=pe,v.push("@"+JSON.stringify($))},E=($,k)=>{for(let u of $??[]){let P=u?.type;if(typeof P!="string")throw new I("malformed-input","A Markdown token has no type.");switch(P){case"text":Array.isArray(u.tokens)?E(u.tokens.filter(b=>typeof b?.type=="string"&&!fe.has(b.type)),k):M(u.text,k);break;case"escape":M(u.text,k);break;case"strong":E(u.tokens,R(k,"strong"));break;case"em":E(u.tokens,R(k,"em"));break;case"del":case"strike":E(u.tokens,R(k,"strike"));break;case"codespan":M(u.text,R(k,"code"));break;case"br":S(ue);break;case"link":{let b=Ee(String(u.href??""),h);b?E(u.tokens,R(k,"link",{href:b})):(c.push({type:"link",href:String(u.href??"")}),E(u.tokens,k));break}case"image":{let b={src:String(u.href??""),alt:String(u.text??""),title:u.title??""};if(!a){M(b.alt,k);break}q(),m.push({image:b});break}case"html":M(u.text??u.raw,k);break;case"checkbox":break;default:d.push({type:P,text:String(u.raw??u.text??"")}),M(u.raw??u.text,k);break}}};return E(o,[]),q(),{parts:m}}function ke(o,{document:a=globalThis.document,resolveImage:c=null,resolveLink:d=null}={}){if(!Array.isArray(o))throw new I("malformed-input","Markdown import needs the lexer's token list.");let h=0;for(let n of o){if(!n||typeof n!="object"||typeof n.type!="string")throw new I("malformed-input","A Markdown token has no type.");h+=Se.encode(String(n.raw??"")).length}if(h>H)throw new I("input-too-large",`Markdown import is limited to ${H} bytes; this file is ${h}.`);let m=[],O=[],v=[],q=new Set,M=n=>{let r=_(n);for(;q.has(r);)r=_(n);return q.add(r),r},S=n=>{if(m.length+1>ie)throw new I("too-many-blocks",`Markdown import is limited to ${ie} blocks.`);m.push(n)},E=n=>{let r=n.depth+1;if(r>le)throw new I("nesting-too-deep",`Markdown import is limited to ${le} levels of nesting.`);return r},$=(n,r,{c:t,m:p})=>{let s={t:n,...r,c:t};return p.some(Boolean)&&(s.m=U(p)),s},k=n=>{let r=typeof c=="function"?c(n.src):null,t=typeof r=="string"&&r?r:null,p=t?Y(t):he.test(String(n.src).trim())?null:Y(n.src);return p?{t:"image",src:p,...n.alt?{alt:n.alt}:{},...n.title?{caption:n.title}:{}}:(v.push({type:"image",href:n.src}),n.alt?$("paragraph",{},{c:n.alt,m:[]}):null)},u=(n,r,t)=>{for(let p of t.parts){if(!p.image){S($(n,r,p));continue}let s=k(p.image);s&&S(s)}},P=(n,r)=>u(r.quote?"quote":"paragraph",{},n),b=(n,r={})=>Te(n,{refused:v,unsupported:O,resolveLink:d,...r}),K=n=>{let r=String(n.raw??n.text??"");O.push({type:n.type,text:r}),S({t:"code_block",lang:"markdown",c:r})},e=(n,r)=>{for(let t of n??[]){let p=t?.type;if(typeof p!="string")throw new I("malformed-input","A Markdown token has no type.");switch(p){case"space":break;case"heading":{let s=Math.min(6,Math.max(1,Number.parseInt(t.depth,10)||1));u("heading",s===2?{}:{level:s},b(t.tokens,{images:!1}));break}case"paragraph":case"text":P(b(t.tokens??[t]),r);break;case"hr":S({t:"divider"});break;case"code":S({t:"code_block",...t.lang?{lang:String(t.lang)}:{},c:String(t.text??"")});break;case"html":{let s=String(t.text??t.raw??"");O.push({type:"HTML block cleaned",text:s}),S({t:"preserved",html:Me(ne(a).fallback(s),a)});break}case"blockquote":{let s=E(r);e(t.tokens,{...r,depth:s,quote:!0});break}case"list":{let s=E(r),y=r.indent??0,f=t.ordered?"ordered":"bullet";for(let w of t.items??[]){let A={c:"",m:[]},C=[];for(let x of w?.tokens??[]){let g=x?.type;if(!(g==="checkbox"||g==="space"))if(g==="text"||g==="paragraph"){A.c&&(A={c:A.c+pe,m:[...A.m,"@"+JSON.stringify(ue)]});let j=g==="paragraph"?x.tokens??[]:[x];for(let T of b(j,{images:!1}).parts)A={c:A.c+T.c,m:[...A.m,...T.m]};C.push(...(x.tokens??[]).filter(T=>typeof T?.type=="string"&&fe.has(T.type)&&T.type!=="space"))}else C.push(x)}let D=w?.task?"check":f,B={...D==="bullet"?{}:{kind:D},...y?{indent:y}:{},...w?.task&&w.checked?{checked:!0}:{}};S($("list_item",B,A)),C.length&&e(C,{...r,depth:s,indent:y+1,quote:!1})}break}case"table":{let s=t.header??[];if(!s.length){K(t);break}let y=x=>b(x,{images:!1}).parts[0]??{c:"",m:[]},f=s.map(()=>M("c")),w=N(null,null,s.length),A=Object.fromEntries(f.map((x,g)=>[x,{pos:w[g],name:y(s[g]?.tokens).c}])),C=t.rows?.length?t.rows:[[]],D=N(null,null,C.length),B=C.map(x=>Object.fromEntries(f.map((g,j)=>{let T=y(x?.[j]?.tokens);return[g,T.m.some(Boolean)?{c:T.c,m:U(T.m)}:T.c]})));S({t:"table",cols:A,rows:Object.fromEntries(B.map((x,g)=>[M("r"),{pos:D[g],cells:x}]))});break}default:K(t);break}}};e(o,{depth:0,indent:0,quote:!1});let l=N(null,null,m.length),i={};return m.forEach((n,r)=>{i[M("b")]={...n,pos:l[r]}}),{blocks:i,unsupported:O,refused:v}}var Ae="markdown-import-preview",ze=new TextEncoder,Oe=o=>{let a=String(o??"").replace(/\s+/g," ").trim();return a.length>60?`${a.slice(0,60)}\u2026`:a},$e=o=>typeof o.text=="function"?o.text():new Promise((a,c)=>{let d=new FileReader;d.onload=()=>a(d.result),d.onerror=()=>c(d.error),d.readAsText(o)}),Ce=()=>globalThis.clay?.assets?.load?.("marked")??import("./c-XN6MBKI6.js"),ve=(o,a)=>{let c=-1;return o.forEach((d,h,m)=>{c<0&&d.attrs.id===a&&(c=m)}),c};function Pe(o){let a=o.selection.$from;if(a.depth>=1)return{node:a.node(1),at:a.before(1),textblock:a.parent.isTextblock};let c=Math.min(a.index(0),Math.max(0,o.doc.childCount-1)),d=0;for(let h=0;h<c;h++)d+=o.doc.child(h).nodeSize;return{node:o.doc.child(c),at:d,textblock:!1}}function Be(o){let{node:a,at:c,textblock:d}=Pe(o),h=o.selection,m=d?Math.max(0,h.from-c-1):0;return{id:a.attrs.id,textblock:d,size:a.isTextblock?a.content.size:0,fromOff:m,toOff:d?Math.max(m,h.to-c-1):0}}var Ie=o=>{try{return ae(oe(o))>0}catch{return!0}},qe=o=>o?.code==="blockeditor-format-upgrade-required"?"This document needs a newer page format before Markdown can be added. The preview stays open.":o?.code==="blockeditor-format-unsupported"?"This host cannot record the newer page format this file needs. The preview stays open.":o?.code==="stale-target"?"The place this import was started from changed. The preview stays open.":o?.code==="empty-import"?"This file holds nothing that can be inserted.":"The Markdown could not be inserted. The preview stays open.";function Qe({view:o=null,load:a=Ce}={}){if(!o)return{run:()=>Promise.resolve({ok:!1,code:"not-editing"}),dispose(){}};let c=o.dom.ownerDocument,d=null,h=null,m=!1,O=G({id:Ae,isPending:()=>d!==null}),v=()=>h??=Promise.resolve().then(a).catch(e=>{throw h=null,e});function q(){try{let e=o.dom.parentElement?.getBoundingClientRect?.()??{left:0,top:0},l=o.coordsAtPos(Math.min(o.state.selection.from,o.state.doc.content.size));return{x:Math.max(8,l.left-e.left),y:l.bottom+6-e.top}}catch{return null}}function M(){let e=d;if(!e)return!1;d=null;for(let[l,i,n,r]of e.listen)l.removeEventListener(i,n,r);return e.panel.remove(),!0}function S(){return M()?(o.focus?.(),{ok:!0,cancelled:!0}):{ok:!1,code:"cancelled"}}function E(e){let l=[],i=(s,y)=>{let f=c.createElement("div");return f.className=s,f.textContent=y,f};if(l.push(i("blockeditor-menu-title",e.error?"Couldn't read that Markdown":`Import ${e.name}`)),!e.error){let s=[`${e.count} block${e.count===1?"":"s"}`];e.unsupported.length&&s.push(`${e.unsupported.length} kept as written`),e.refused.length&&s.push(`${e.refused.length} address${e.refused.length===1?"":"es"} left out`),l.push(i("blockeditor-menu-title blockeditor-import-summary",s.join(" \xB7 ")))}let n=(s,y)=>{let f=c.createElement("div");return f.className=s,f.replaceChildren(...y.map(w=>i("blockeditor-import-row",w))),f};e.unsupported.length&&l.push(n("blockeditor-import-unsupported",e.unsupported.map(s=>`${s.type}: ${Oe(s.text)}`))),e.refused.length&&l.push(n("blockeditor-import-refused",e.refused.map(s=>`${s.type}: ${s.href}`)));let r=e.error??e.notice??null;if(r){let s=c.createElement("p");s.className="blockeditor-import-error",s.setAttribute("role","alert"),s.textContent=r,l.push(s)}let t=(s,y)=>{let f=c.createElement("button");return f.type="button",f.className="blockeditor-menu-item",f.dataset.import=s,f.textContent=y,f.addEventListener("mousedown",w=>w.preventDefault()),f.addEventListener("click",()=>s==="insert"?k():S()),f},p=t("insert","Insert at the selection");p.disabled=!!e.error,l.push(p,t("cancel","Cancel")),e.panel.replaceChildren(...l)}function $(e,l){let i=o.state,n=i.doc,r=ve(n,e.id);if(r<0)return{ok:!1,code:"stale-target"};let t=n.child(r);if(e.textblock?!t.isTextblock||t.content.size!==e.size:t.isTextblock)return{ok:!1,code:"stale-target"};let p=ee(l).map(z=>te(V,z,{...l[z],pos:null,parent:null}));if(!p.length)return{ok:!1,code:"empty-import"};let s=0;for(let z=0;z<r;z++)s+=n.child(z).nodeSize;let y=n.maybeChild(r+1),f=t.type.name==="toggle",w=e.textblock&&!f&&t.content.size>0,A=w||e.textblock&&!f&&t.content.size===0,C=w?Math.min(e.fromOff,t.content.size):0,D=w?Math.min(Math.max(C,e.toOff),t.content.size):0,B=w&&C>0?t.type.create({...t.attrs},t.content.cut(0,C)):null,x=w?t.content.cut(D):null,g=x&&x.size?t.type.create({...t.attrs,id:_(),pos:null},x):null,j=w&&!B?r>0?n.child(r-1).attrs.pos:null:t.attrs.pos,T=N(j,y?.attrs.pos??null,p.length+(g?1:0)),be=f?t.attrs.id:t.attrs.parent??null,F=p.map((z,ge)=>z.type.create({...z.attrs,pos:T[ge],parent:be},z.content,z.marks)),X=g?g.type.create({...g.attrs,pos:T[p.length]},g.content,g.marks):null,L=i.tr;A?L.replaceWith(s,s+t.nodeSize,[...B?[B]:[],...F,...X?[X]:[]]):L.insert(s+t.nodeSize,F),f&&!t.attrs.open&&F.length>0&&L.setNodeMarkup(s,null,{...t.attrs,open:!0});let J=s+(A?B?B.nodeSize:0:t.nodeSize);for(let z of F)J+=z.nodeSize;return L.setSelection(Q.TextSelection.near(L.doc.resolve(X?J:Math.max(0,J-1)),X?1:-1)),o.dispatch(ce(L).scrollIntoView()),o.focus?.(),{ok:!0,blocks:F.length}}async function k(){let e=d;if(!e||e.error)return e?{ok:!1,code:"no-import"}:{ok:!1,code:"not-editing"};e.notice&&(e.notice=null,E(e));let l=()=>$(e.target,e.blocks),i=e.floor?await re(o,l):l();return i?.ok?(M(),i):(d===e&&(e.notice=qe(i),E(e)),i??{ok:!1,code:"import-failed"})}function u(e){!d||se(e,o)||(e.key==="Escape"?(e.preventDefault(),e.stopPropagation(),S()):e.key==="Enter"&&!e.target?.closest?.("[data-import]")&&(e.preventDefault(),e.stopPropagation(),k()))}function P(){return new Promise(e=>{let l=c.createElement("input");l.type="file",l.accept=".md,.markdown,text/markdown,text/plain",l.hidden=!0,l.className="blockeditor-markdown-input";let i=n=>{l.remove(),e(n)};l.addEventListener("change",()=>i(l.files?.[0]??null)),l.addEventListener("cancel",()=>i(null)),(o.dom.parentElement??c.body).appendChild(l),l.click()})}async function b(e,l=null){e.error=l;let i=c.createElement("div");i.className="blockeditor-menu blockeditor-import-preview",i.setAttribute("role","dialog"),i.setAttribute("aria-label","Import Markdown"),e.panel=i,d=e;let n=(p,s,y,f)=>{p.addEventListener(s,y,f),e.listen.push([p,s,y,f])};n(c,"keydown",p=>u(p),!0),n(c,"mousedown",p=>{e.panel.contains(p.target)||S()},!0),(o.dom.parentElement??c.body).appendChild(i),E(e);let r=q();r&&(i.style.setProperty("--blockeditor-pop-x",`${r.x}px`),i.style.setProperty("--blockeditor-pop-y",`${r.y}px`));let t=i.querySelector('[data-import="insert"]');return t&&!t.disabled&&t.focus?.(),{ok:!0,preview:!0}}async function K(e={}){if(m||o.isDestroyed)return{ok:!1,code:"not-editing"};M();let l=Be(o.state),i=e?.file??await P();if(!i)return{ok:!1,code:"cancelled"};if(typeof i.size=="number"&&i.size>H)return{ok:!1,code:"input-too-large"};let n;try{n=await $e(i)}catch(p){return{ok:!1,code:"unreadable",error:p}}if(m||o.isDestroyed)return{ok:!1,code:"not-editing"};if(ze.encode(n).length>H)return{ok:!1,code:"input-too-large"};let r={target:l,name:String(i.name??"Markdown"),blocks:{},count:0,unsupported:[],refused:[],floor:0,panel:null,error:null,notice:null,listen:[]},t;try{let p=await v();t=ke(new p.Marked().lexer(n))}catch(p){return m||o.isDestroyed?{ok:!1,code:"not-editing"}:b(r,String(p?.message??"The Markdown could not be read."))}return m||o.isDestroyed?{ok:!1,code:"not-editing"}:(r.blocks=t.blocks,r.count=Object.keys(t.blocks).length,r.unsupported=t.unsupported,r.refused=t.refused,r.floor=Ie(t.blocks)?1:0,b(r))}return{async run(e){return K(e)},dispose(){m=!0,M(),O.dispose()}}}export{Qe as createFeature};
|
|
1
|
+
import{a as ae}from"./c-7WZSUTYP.js";import{i as re,j as se}from"./c-WHMZCRQD.js";import"./c-LAKBBJOU.js";import"./c-EIUKME3W.js";import"./c-DZT6W2NG.js";import"./c-SYOA4T7V.js";import"./c-ND3W7D5U.js";import"./c-WHQUZM2V.js";import{C as ce}from"./c-3XGLJAS7.js";import{A as _,F as te,a as W,b as Y,d as V,ea as oe,ia as ne,o as Z,r as U,y as N,z as ee}from"./c-OH2FPYSY.js";import"./c-FSQXFG5T.js";import{b as Q}from"./c-RETTCOWO.js";import"./c-JC4RZW4E.js";import"./c-57XDY6HC.js";import{a as G}from"./c-I2SCCUEW.js";import"./c-PGSBXHUE.js";import"./c-VHNSBD2M.js";var ye="iframe, frame, frameset, object, embed, applet, meta, base, link, form, style, animate, set, animateMotion, animateTransform, portal",we=/^(srcdoc|data|formaction|codebase|archive|ping|background|poster|lowsrc|dynsrc)$/i,xe=/^\s*(javascript|vbscript|data):/i;function Me(o,a){let c=a.createElement("template");c.innerHTML=o;for(let d of c.content.querySelectorAll(ye))d.remove();for(let d of c.content.querySelectorAll("*"))for(let{name:h,value:m}of[...d.attributes])(we.test(h)||xe.test(m.replace(/[\u0000-\u0020]/g,"")))&&d.removeAttribute(h);return c.innerHTML}var H=2*1024*1024,le=32,ie=1e4,I=class extends Error{constructor(a,c){super(c),this.name="MarkdownImportError",this.code=a}},pe="\uFFFC",ue={type:"hard_break"},fe=new Set(["paragraph","heading","list","blockquote","code","table","hr","html","def","space"]),Se=new TextEncoder,de=V.marks,me=o=>o.slice().sort((a,c)=>a.type.rank-c.type.rank);function R(o,a,c){return o.some(d=>d.type===de[a])?o:me([...o,de[a].create(c)])}var he=/^(?![a-z][a-z0-9+.-]*:|[/#?])\S/i;function Ee(o,a){let c=typeof a=="function"?a(o):null;return typeof c=="string"&&c?W(c):he.test(o.trim())?null:W(o)}function Te(o,{images:a=!0,refused:c=[],unsupported:d=[],resolveLink:h=null}={}){let m=[],O="",v=[],q=()=>{O&&m.push({c:O,m:v}),O="",v=[]},M=($,k)=>{let u=String($??"");if(!u)return;let P=Z(me(k));O+=u;for(let b=0;b<u.length;b++)v.push(P)},S=$=>{O+=pe,v.push("@"+JSON.stringify($))},E=($,k)=>{for(let u of $??[]){let P=u?.type;if(typeof P!="string")throw new I("malformed-input","A Markdown token has no type.");switch(P){case"text":Array.isArray(u.tokens)?E(u.tokens.filter(b=>typeof b?.type=="string"&&!fe.has(b.type)),k):M(u.text,k);break;case"escape":M(u.text,k);break;case"strong":E(u.tokens,R(k,"strong"));break;case"em":E(u.tokens,R(k,"em"));break;case"del":case"strike":E(u.tokens,R(k,"strike"));break;case"codespan":M(u.text,R(k,"code"));break;case"br":S(ue);break;case"link":{let b=Ee(String(u.href??""),h);b?E(u.tokens,R(k,"link",{href:b})):(c.push({type:"link",href:String(u.href??"")}),E(u.tokens,k));break}case"image":{let b={src:String(u.href??""),alt:String(u.text??""),title:u.title??""};if(!a){M(b.alt,k);break}q(),m.push({image:b});break}case"html":M(u.text??u.raw,k);break;case"checkbox":break;default:d.push({type:P,text:String(u.raw??u.text??"")}),M(u.raw??u.text,k);break}}};return E(o,[]),q(),{parts:m}}function ke(o,{document:a=globalThis.document,resolveImage:c=null,resolveLink:d=null}={}){if(!Array.isArray(o))throw new I("malformed-input","Markdown import needs the lexer's token list.");let h=0;for(let n of o){if(!n||typeof n!="object"||typeof n.type!="string")throw new I("malformed-input","A Markdown token has no type.");h+=Se.encode(String(n.raw??"")).length}if(h>H)throw new I("input-too-large",`Markdown import is limited to ${H} bytes; this file is ${h}.`);let m=[],O=[],v=[],q=new Set,M=n=>{let r=_(n);for(;q.has(r);)r=_(n);return q.add(r),r},S=n=>{if(m.length+1>ie)throw new I("too-many-blocks",`Markdown import is limited to ${ie} blocks.`);m.push(n)},E=n=>{let r=n.depth+1;if(r>le)throw new I("nesting-too-deep",`Markdown import is limited to ${le} levels of nesting.`);return r},$=(n,r,{c:t,m:p})=>{let s={t:n,...r,c:t};return p.some(Boolean)&&(s.m=U(p)),s},k=n=>{let r=typeof c=="function"?c(n.src):null,t=typeof r=="string"&&r?r:null,p=t?Y(t):he.test(String(n.src).trim())?null:Y(n.src);return p?{t:"image",src:p,...n.alt?{alt:n.alt}:{},...n.title?{caption:n.title}:{}}:(v.push({type:"image",href:n.src}),n.alt?$("paragraph",{},{c:n.alt,m:[]}):null)},u=(n,r,t)=>{for(let p of t.parts){if(!p.image){S($(n,r,p));continue}let s=k(p.image);s&&S(s)}},P=(n,r)=>u(r.quote?"quote":"paragraph",{},n),b=(n,r={})=>Te(n,{refused:v,unsupported:O,resolveLink:d,...r}),K=n=>{let r=String(n.raw??n.text??"");O.push({type:n.type,text:r}),S({t:"code_block",lang:"markdown",c:r})},e=(n,r)=>{for(let t of n??[]){let p=t?.type;if(typeof p!="string")throw new I("malformed-input","A Markdown token has no type.");switch(p){case"space":break;case"heading":{let s=Math.min(6,Math.max(1,Number.parseInt(t.depth,10)||1));u("heading",s===2?{}:{level:s},b(t.tokens,{images:!1}));break}case"paragraph":case"text":P(b(t.tokens??[t]),r);break;case"hr":S({t:"divider"});break;case"code":S({t:"code_block",...t.lang?{lang:String(t.lang)}:{},c:String(t.text??"")});break;case"html":{let s=String(t.text??t.raw??"");O.push({type:"HTML block cleaned",text:s}),S({t:"preserved",html:Me(ne(a).fallback(s),a)});break}case"blockquote":{let s=E(r);e(t.tokens,{...r,depth:s,quote:!0});break}case"list":{let s=E(r),y=r.indent??0,f=t.ordered?"ordered":"bullet";for(let w of t.items??[]){let A={c:"",m:[]},C=[];for(let x of w?.tokens??[]){let g=x?.type;if(!(g==="checkbox"||g==="space"))if(g==="text"||g==="paragraph"){A.c&&(A={c:A.c+pe,m:[...A.m,"@"+JSON.stringify(ue)]});let j=g==="paragraph"?x.tokens??[]:[x];for(let T of b(j,{images:!1}).parts)A={c:A.c+T.c,m:[...A.m,...T.m]};C.push(...(x.tokens??[]).filter(T=>typeof T?.type=="string"&&fe.has(T.type)&&T.type!=="space"))}else C.push(x)}let D=w?.task?"check":f,B={...D==="bullet"?{}:{kind:D},...y?{indent:y}:{},...w?.task&&w.checked?{checked:!0}:{}};S($("list_item",B,A)),C.length&&e(C,{...r,depth:s,indent:y+1,quote:!1})}break}case"table":{let s=t.header??[];if(!s.length){K(t);break}let y=x=>b(x,{images:!1}).parts[0]??{c:"",m:[]},f=s.map(()=>M("c")),w=N(null,null,s.length),A=Object.fromEntries(f.map((x,g)=>[x,{pos:w[g],name:y(s[g]?.tokens).c}])),C=t.rows?.length?t.rows:[[]],D=N(null,null,C.length),B=C.map(x=>Object.fromEntries(f.map((g,j)=>{let T=y(x?.[j]?.tokens);return[g,T.m.some(Boolean)?{c:T.c,m:U(T.m)}:T.c]})));S({t:"table",cols:A,rows:Object.fromEntries(B.map((x,g)=>[M("r"),{pos:D[g],cells:x}]))});break}default:K(t);break}}};e(o,{depth:0,indent:0,quote:!1});let l=N(null,null,m.length),i={};return m.forEach((n,r)=>{i[M("b")]={...n,pos:l[r]}}),{blocks:i,unsupported:O,refused:v}}var Ae="markdown-import-preview",ze=new TextEncoder,Oe=o=>{let a=String(o??"").replace(/\s+/g," ").trim();return a.length>60?`${a.slice(0,60)}\u2026`:a},$e=o=>typeof o.text=="function"?o.text():new Promise((a,c)=>{let d=new FileReader;d.onload=()=>a(d.result),d.onerror=()=>c(d.error),d.readAsText(o)}),Ce=()=>globalThis.clay?.assets?.load?.("marked")??import("./c-XN6MBKI6.js"),ve=(o,a)=>{let c=-1;return o.forEach((d,h,m)=>{c<0&&d.attrs.id===a&&(c=m)}),c};function Pe(o){let a=o.selection.$from;if(a.depth>=1)return{node:a.node(1),at:a.before(1),textblock:a.parent.isTextblock};let c=Math.min(a.index(0),Math.max(0,o.doc.childCount-1)),d=0;for(let h=0;h<c;h++)d+=o.doc.child(h).nodeSize;return{node:o.doc.child(c),at:d,textblock:!1}}function Be(o){let{node:a,at:c,textblock:d}=Pe(o),h=o.selection,m=d?Math.max(0,h.from-c-1):0;return{id:a.attrs.id,textblock:d,size:a.isTextblock?a.content.size:0,fromOff:m,toOff:d?Math.max(m,h.to-c-1):0}}var Ie=o=>{try{return ae(oe(o))>0}catch{return!0}},qe=o=>o?.code==="blockeditor-format-upgrade-required"?"This document needs a newer page format before Markdown can be added. The preview stays open.":o?.code==="blockeditor-format-unsupported"?"This host cannot record the newer page format this file needs. The preview stays open.":o?.code==="stale-target"?"The place this import was started from changed. The preview stays open.":o?.code==="empty-import"?"This file holds nothing that can be inserted.":"The Markdown could not be inserted. The preview stays open.";function Qe({view:o=null,load:a=Ce}={}){if(!o)return{run:()=>Promise.resolve({ok:!1,code:"not-editing"}),dispose(){}};let c=o.dom.ownerDocument,d=null,h=null,m=!1,O=G({id:Ae,isPending:()=>d!==null}),v=()=>h??=Promise.resolve().then(a).catch(e=>{throw h=null,e});function q(){try{let e=o.dom.parentElement?.getBoundingClientRect?.()??{left:0,top:0},l=o.coordsAtPos(Math.min(o.state.selection.from,o.state.doc.content.size));return{x:Math.max(8,l.left-e.left),y:l.bottom+6-e.top}}catch{return null}}function M(){let e=d;if(!e)return!1;d=null;for(let[l,i,n,r]of e.listen)l.removeEventListener(i,n,r);return e.panel.remove(),!0}function S(){return M()?(o.focus?.(),{ok:!0,cancelled:!0}):{ok:!1,code:"cancelled"}}function E(e){let l=[],i=(s,y)=>{let f=c.createElement("div");return f.className=s,f.textContent=y,f};if(l.push(i("blockeditor-menu-title",e.error?"Couldn't read that Markdown":`Import ${e.name}`)),!e.error){let s=[`${e.count} block${e.count===1?"":"s"}`];e.unsupported.length&&s.push(`${e.unsupported.length} kept as written`),e.refused.length&&s.push(`${e.refused.length} address${e.refused.length===1?"":"es"} left out`),l.push(i("blockeditor-menu-title blockeditor-import-summary",s.join(" \xB7 ")))}let n=(s,y)=>{let f=c.createElement("div");return f.className=s,f.replaceChildren(...y.map(w=>i("blockeditor-import-row",w))),f};e.unsupported.length&&l.push(n("blockeditor-import-unsupported",e.unsupported.map(s=>`${s.type}: ${Oe(s.text)}`))),e.refused.length&&l.push(n("blockeditor-import-refused",e.refused.map(s=>`${s.type}: ${s.href}`)));let r=e.error??e.notice??null;if(r){let s=c.createElement("p");s.className="blockeditor-import-error",s.setAttribute("role","alert"),s.textContent=r,l.push(s)}let t=(s,y)=>{let f=c.createElement("button");return f.type="button",f.className="blockeditor-menu-item",f.dataset.import=s,f.textContent=y,f.addEventListener("mousedown",w=>w.preventDefault()),f.addEventListener("click",()=>s==="insert"?k():S()),f},p=t("insert","Insert at the selection");p.disabled=!!e.error,l.push(p,t("cancel","Cancel")),e.panel.replaceChildren(...l)}function $(e,l){let i=o.state,n=i.doc,r=ve(n,e.id);if(r<0)return{ok:!1,code:"stale-target"};let t=n.child(r);if(e.textblock?!t.isTextblock||t.content.size!==e.size:t.isTextblock)return{ok:!1,code:"stale-target"};let p=ee(l).map(z=>te(V,z,{...l[z],pos:null,parent:null}));if(!p.length)return{ok:!1,code:"empty-import"};let s=0;for(let z=0;z<r;z++)s+=n.child(z).nodeSize;let y=n.maybeChild(r+1),f=t.type.name==="toggle",w=e.textblock&&!f&&t.content.size>0,A=w||e.textblock&&!f&&t.content.size===0,C=w?Math.min(e.fromOff,t.content.size):0,D=w?Math.min(Math.max(C,e.toOff),t.content.size):0,B=w&&C>0?t.type.create({...t.attrs},t.content.cut(0,C)):null,x=w?t.content.cut(D):null,g=x&&x.size?t.type.create({...t.attrs,id:_(),pos:null},x):null,j=w&&!B?r>0?n.child(r-1).attrs.pos:null:t.attrs.pos,T=N(j,y?.attrs.pos??null,p.length+(g?1:0)),be=f?t.attrs.id:t.attrs.parent??null,F=p.map((z,ge)=>z.type.create({...z.attrs,pos:T[ge],parent:be},z.content,z.marks)),X=g?g.type.create({...g.attrs,pos:T[p.length]},g.content,g.marks):null,L=i.tr;A?L.replaceWith(s,s+t.nodeSize,[...B?[B]:[],...F,...X?[X]:[]]):L.insert(s+t.nodeSize,F),f&&!t.attrs.open&&F.length>0&&L.setNodeMarkup(s,null,{...t.attrs,open:!0});let J=s+(A?B?B.nodeSize:0:t.nodeSize);for(let z of F)J+=z.nodeSize;return L.setSelection(Q.TextSelection.near(L.doc.resolve(X?J:Math.max(0,J-1)),X?1:-1)),o.dispatch(ce(L).scrollIntoView()),o.focus?.(),{ok:!0,blocks:F.length}}async function k(){let e=d;if(!e||e.error)return e?{ok:!1,code:"no-import"}:{ok:!1,code:"not-editing"};e.notice&&(e.notice=null,E(e));let l=()=>$(e.target,e.blocks),i=e.floor?await re(o,l):l();return i?.ok?(M(),i):(d===e&&(e.notice=qe(i),E(e)),i??{ok:!1,code:"import-failed"})}function u(e){!d||se(e,o)||(e.key==="Escape"?(e.preventDefault(),e.stopPropagation(),S()):e.key==="Enter"&&!e.target?.closest?.("[data-import]")&&(e.preventDefault(),e.stopPropagation(),k()))}function P(){return new Promise(e=>{let l=c.createElement("input");l.type="file",l.accept=".md,.markdown,text/markdown,text/plain",l.hidden=!0,l.className="blockeditor-markdown-input";let i=n=>{l.remove(),e(n)};l.addEventListener("change",()=>i(l.files?.[0]??null)),l.addEventListener("cancel",()=>i(null)),(o.dom.parentElement??c.body).appendChild(l),l.click()})}async function b(e,l=null){e.error=l;let i=c.createElement("div");i.className="blockeditor-menu blockeditor-import-preview",i.setAttribute("role","dialog"),i.setAttribute("aria-label","Import Markdown"),e.panel=i,d=e;let n=(p,s,y,f)=>{p.addEventListener(s,y,f),e.listen.push([p,s,y,f])};n(c,"keydown",p=>u(p),!0),n(c,"mousedown",p=>{e.panel.contains(p.target)||S()},!0),(o.dom.parentElement??c.body).appendChild(i),E(e);let r=q();r&&(i.style.setProperty("--blockeditor-pop-x",`${r.x}px`),i.style.setProperty("--blockeditor-pop-y",`${r.y}px`));let t=i.querySelector('[data-import="insert"]');return t&&!t.disabled&&t.focus?.(),{ok:!0,preview:!0}}async function K(e={}){if(m||o.isDestroyed)return{ok:!1,code:"not-editing"};M();let l=Be(o.state),i=e?.file??await P();if(!i)return{ok:!1,code:"cancelled"};if(typeof i.size=="number"&&i.size>H)return{ok:!1,code:"input-too-large"};let n;try{n=await $e(i)}catch(p){return{ok:!1,code:"unreadable",error:p}}if(m||o.isDestroyed)return{ok:!1,code:"not-editing"};if(ze.encode(n).length>H)return{ok:!1,code:"input-too-large"};let r={target:l,name:String(i.name??"Markdown"),blocks:{},count:0,unsupported:[],refused:[],floor:0,panel:null,error:null,notice:null,listen:[]},t;try{let p=await v();t=ke(new p.Marked().lexer(n))}catch(p){return m||o.isDestroyed?{ok:!1,code:"not-editing"}:b(r,String(p?.message??"The Markdown could not be read."))}return m||o.isDestroyed?{ok:!1,code:"not-editing"}:(r.blocks=t.blocks,r.count=Object.keys(t.blocks).length,r.unsupported=t.unsupported,r.refused=t.refused,r.floor=Ie(t.blocks)?1:0,b(r))}return{async run(e){return K(e)},dispose(){m=!0,M(),O.dispose()}}}export{Qe as createFeature};
|