@panphora/clayjs 1.20.0 → 1.22.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 +7865 -8022
- package/dist/m/{c-JOH753EJ.js → c-26KVJS6J.js} +1 -1
- package/dist/m/{c-ZE46QDIH.js → c-3TLG3OLG.js} +1 -1
- package/dist/m/{c-RT3C74GY.js → c-4OGEVKR3.js} +1 -1
- package/dist/m/{c-Y33LUUIQ.js → c-4PHDUV3H.js} +1 -1
- package/dist/m/{c-SJPD46ZO.js → c-4RFZROCF.js} +4 -4
- package/dist/m/{c-XQSXKIKM.js → c-4TWARTLS.js} +1 -1
- package/dist/m/{c-S5IEIZCN.js → c-5AQYL27I.js} +1 -1
- package/dist/m/{c-OJYM642Q.js → c-5FKRZNJV.js} +1 -1
- package/dist/m/{c-CJFDLD43.js → c-6KBKYLPO.js} +1 -1
- package/dist/m/{c-DHXPDLW6.js → c-6PBXRWDX.js} +1 -1
- package/dist/m/{c-BRLCTNMC.js → c-6RC66MYY.js} +1 -1
- package/dist/m/{c-PIVIYLTY.js → c-6UEFPHHE.js} +1 -1
- package/dist/m/{c-YQUJ74R3.js → c-BV6FQQXM.js} +1 -1
- package/dist/m/{c-YSB6JKV2.js → c-DEAFCHDO.js} +2 -2
- package/dist/m/{c-NLZ5AN4L.js → c-DKFSOJCV.js} +1 -1
- package/dist/m/c-DP4X4JID.js +1 -0
- package/dist/m/{c-LIBE4HPD.js → c-DZBZ57EE.js} +1 -1
- package/dist/m/c-ECY5AZMH.js +1 -0
- package/dist/m/{c-VAK7SG37.js → c-EUGJVHDD.js} +1 -1
- package/dist/m/{c-GPGYKER7.js → c-F5AER2ID.js} +1 -1
- package/dist/m/{c-RG6XUZFA.js → c-FAXQU7MQ.js} +1 -1
- package/dist/m/{c-XD5MOROJ.js → c-FLBUYV3P.js} +1 -1
- package/dist/m/{c-NFR673TL.js → c-FMCPQ4VT.js} +2 -2
- package/dist/m/{c-VBLFAQD2.js → c-FNIGX4FI.js} +1 -1
- package/dist/m/{c-BTLFLLML.js → c-FWFJUU3T.js} +1 -1
- package/dist/m/{c-2VB555FG.js → c-GPTKI7AQ.js} +1 -1
- package/dist/m/{c-EZ7B5AZT.js → c-GY4ODHO2.js} +1 -1
- package/dist/m/{c-5734MF2P.js → c-H6DXQEH2.js} +1 -1
- package/dist/m/{c-Z32V4MHK.js → c-HAVGDXAL.js} +1 -1
- package/dist/m/{c-D3E4WJ4M.js → c-HDWZEJHM.js} +49 -32
- package/dist/m/{c-W23KVGUO.js → c-HWR6GMGK.js} +1 -1
- package/dist/m/{c-BJ7YQ5QZ.js → c-IHUWUKIU.js} +1 -1
- package/dist/m/{c-AL4RBJF2.js → c-ILGQ3UXQ.js} +1 -1
- package/dist/m/{c-W3K23S72.js → c-IWTTOC2V.js} +1 -1
- package/dist/m/c-JFST6QE7.js +1 -0
- package/dist/m/{c-FNVQAACK.js → c-KE33W4RE.js} +1 -1
- package/dist/m/c-KV7R47FR.js +1 -0
- package/dist/m/{c-LPUJXRXW.js → c-L7K5EXU2.js} +1 -1
- package/dist/m/{c-3YH6JSIL.js → c-LF6HNVPU.js} +1 -1
- package/dist/m/{c-MIL4B2JQ.js → c-MRURHLKV.js} +1 -1
- package/dist/m/{c-LQU7TXIH.js → c-N33TPVTL.js} +1 -1
- package/dist/m/{c-EOCZ2YVL.js → c-NBNRLZXO.js} +1 -1
- package/dist/m/{c-JUE7B4OX.js → c-NLWEZYKJ.js} +1 -1
- package/dist/m/{c-DDDOKPI6.js → c-NNNR7OXA.js} +1 -1
- package/dist/m/{c-E4IBSAQM.js → c-OI2BYWVV.js} +1 -1
- package/dist/m/{c-SBSMJIPC.js → c-P3WATEDR.js} +1 -1
- package/dist/m/{c-ZJLU56DV.js → c-PCEMXY2K.js} +1 -1
- package/dist/m/{c-3GJ4XARY.js → c-PWBJVHA4.js} +1 -1
- package/dist/m/{c-67ILSNPR.js → c-Q5KAQJAG.js} +1 -1
- package/dist/m/{c-U5X57T4L.js → c-QHVCUTJV.js} +1 -1
- package/dist/m/{c-GKEATME6.js → c-QJFYVCJO.js} +1 -1
- package/dist/m/{c-VY6XRBOW.js → c-QTC6VGA4.js} +1 -1
- package/dist/m/{c-44B5ODN7.js → c-TMT5TL65.js} +2 -2
- package/dist/m/{c-OABVRYOT.js → c-TV7JHSRL.js} +1 -1
- package/dist/m/{c-SO63UGPQ.js → c-UWT4CXQ4.js} +1 -1
- package/dist/m/{c-EFD6QNTE.js → c-VFES2BP5.js} +1 -1
- package/dist/m/{c-UXEVJ63W.js → c-VIW5X35H.js} +1 -1
- package/dist/m/{c-EOCKLMKX.js → c-WWE67K5Y.js} +1 -1
- package/dist/m/{c-J3BXFTZS.js → c-XDVAZDUE.js} +1 -1
- package/dist/m/{c-K76AUL4I.js → c-XZJ5IK6Q.js} +1 -1
- package/dist/m/{c-2ZZBC45O.js → c-Z7RJANGO.js} +1 -1
- package/dist/m/{c-I2IFKJX2.js → c-ZAHTFCXQ.js} +1 -1
- package/dist/m/{c-GVPNDIKJ.js → c-ZKELCT4T.js} +1 -1
- package/dist/m/{c-7SXYQCN4.js → c-ZO6VL2SC.js} +1 -1
- package/dist/m/{c-M4FSPNQ2.js → c-ZYEJLZEY.js} +1 -1
- package/dist/m/core/{autosave-VPORYJSE.js → autosave-GI3WNJYN.js} +1 -1
- package/dist/m/core/{conflict-notice-JMAZLVRX.js → conflict-notice-CEI3XY6A.js} +1 -1
- package/dist/m/core/{save-AOJBDSOK.js → save-OJ5NSLS7.js} +1 -1
- package/dist/m/core/{save-core-IOCMXO5L.js → save-core-DX3RFVO3.js} +1 -1
- package/dist/m/core/{unsaved-warning-U5VUJFOE.js → unsaved-warning-HGYH7O4H.js} +1 -1
- package/dist/m/internals/{index-HDRANDWE.js → index-V4WC44FU.js} +1 -1
- package/dist/m/loader-V6VI46HU.js +1 -0
- package/dist/m/{manifest-3AEF5191.js → manifest-83C18DED.js} +1 -1
- package/dist/m/{manifest-edit-29A26F22.js → manifest-edit-B28C1985.js} +1 -1
- package/dist/m/manifest.json +567 -567
- package/dist/m/page/{editor-EY2WAAGB.js → editor-BQEPCJLG.js} +2 -2
- package/dist/m/plugins/ai-edit-45A2J6LC.js +6 -0
- package/dist/m/plugins/cms-IFTKWF4S.js +2235 -0
- package/dist/m/plugins/{derive-FRE5JJQE.js → derive-QVI3LI3A.js} +1 -1
- package/dist/m/plugins/{indicator-4VDXWYTD.js → indicator-IPZJ35K6.js} +1 -1
- package/dist/m/plugins/{live-5EZN2EYP.js → live-GPQXSXSM.js} +1 -1
- package/dist/m/plugins/menu-UN3KRCOF.js +1 -0
- package/dist/m/plugins/{page-LVW5DWA4.js → page-BAVLWCP6.js} +2 -2
- package/dist/m/plugins/{page-view-5KQ76IJB.js → page-view-P3UGJFDZ.js} +1 -1
- package/dist/m/plugins/{people-C7TVBBMR.js → people-Z4RGVQAV.js} +1 -1
- package/dist/m/plugins/{quickcrop-BQ5YYFCH.js → quickcrop-E34PUYA3.js} +2 -2
- package/dist/m/plugins/{richclay-KLGETK77.js → richclay-S4NVJYIK.js} +2 -2
- package/dist/m/plugins/{source-CCEUM3OR.js → source-KVN6YNTY.js} +1 -1
- package/dist/m/plugins/{upgrade-NW556WJD.js → upgrade-KTSICB22.js} +1 -1
- package/dist/m/plugins/{wire-VRYPY6EJ.js → wire-SYVIBNSE.js} +1 -1
- package/dist/m/{reader-core-2GXY7SHY.js → reader-core-RUIFH32Y.js} +2 -2
- package/dist/m/sync/{live-sync-SKPMFYOO.js → live-sync-RGQMMWK2.js} +1 -1
- package/dist/m/ui/{index-QNIPDHXQ.js → index-EZGLEM5P.js} +1 -1
- package/dist/m/vendor/{sap-core.vendor-RN4ZVY4X.js → sap-core.vendor-OA5SKL7Q.js} +1 -1
- package/dist/offline-manifest.json +463 -469
- package/docs/guide.md +16 -8
- package/entries/sap.js +1 -1
- package/package.json +2 -2
- package/src/loader-logic.js +4 -1
- package/src/plugins/ai-edit.js +6 -17
- package/src/plugins/cms.js +3 -6
- package/src/plugins/menu/style.js +59 -31
- package/src/plugins/menu.js +131 -28
- package/src/ui/bevel.js +1 -1
- package/src/ui/skins/cms.js +1 -1
- package/src/ui/skins/quickcrop.js +1 -1
- package/src/ui/skins/richclay.js +1 -1
- package/src/vendor/hypercms.vendor.js +16 -69
- package/src/vendor/sap-core.vendor.js +1 -1
- package/dist/m/c-FSWRGBVQ.js +0 -1
- package/dist/m/c-HMYWIHFG.js +0 -1
- package/dist/m/c-M6FNQCTQ.js +0 -1
- package/dist/m/c-WFMRX5RZ.js +0 -1
- package/dist/m/loader-DZZLUBVB.js +0 -1
- package/dist/m/plugins/ai-edit-J5VLSW5I.js +0 -6
- package/dist/m/plugins/cms-LRAOZHT7.js +0 -2293
- package/dist/m/plugins/menu-KGWKT6CS.js +0 -1
- package/src/ui/skins/cms-toggle.js +0 -15
- /package/dist/m/plugins/{quickcrop-BQ5YYFCH.js.LEGAL.txt → quickcrop-E34PUYA3.js.LEGAL.txt} +0 -0
- /package/dist/m/plugins/{richclay-KLGETK77.js.LEGAL.txt → richclay-S4NVJYIK.js.LEGAL.txt} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import{A as Kt,B as Ht,C as jt,E as ot,H as lt,I as dt,J as V,a as O,b as D,ba as Ut,ca as ut,d as $,da as Ft,e as Z,f as Vt,g as tt,ga as Wt,ha as Gt,ia as Xt,j as L,k as et,m as T,ma as ft,n as nt,q as Rt,t as qt,ta as Qt,v as ct,z as _t}from"./c-QIXT3Q7C.js";var be=e=>e==="left"||e==="right"?e:null,{Plugin:wt,PluginKey:ke,TextSelection:I,NodeSelection:Yt,Selection:st}=D,M=T.nodes,S=e=>e.type===M.list_item,A=e=>e.type===M.toggle,k=e=>e.attrs.parent??null,Et="page-step",q="page-move",Mt=e=>e&&(n=>e(Z.closeHistory(n).setMeta(Et,!0)));function y(e,n=null){let t=[],o=new Map,r=[];e.forEach((s,a)=>{let i=t.length,l=t[i-1],c=k(s),d=c!==null&&o.has(c)?o.get(c):-1,f=d;if(S(s)){for(l&&S(l.node)&&k(l.node)===c||(r=[]);r.length&&t[r[r.length-1]].node.attrs.indent>=s.attrs.indent;)r.pop();r.length&&(f=r[r.length-1]),r.push(i)}else r=[];let p=A(s)&&(s.attrs.open||!!n?.has(s.attrs.id)),u=d>=0&&(t[d].hidden||!t[d].open);t.push({node:s,at:a,end:a+s.nodeSize,i,up:f,depth:d>=0?t[d].depth+1:0,hidden:u,open:p,subEnd:i}),A(s)&&s.attrs.id&&o.set(s.attrs.id,i)});for(let s=t.length-1;s>=0;s--){let a=t[s].up;a>=0&&t[s].subEnd>t[a].subEnd&&(t[a].subEnd=t[s].subEnd)}return t}var Jn=(e,n)=>({from:e[n].at,to:e[e[n].subEnd].end});function xe(e,n=null){let t=new Map;n?.forEach(c=>{c.attrs.id&&t.set(c.attrs.id,k(c))}),e.forEach(c=>{c.attrs.id&&t.set(c.attrs.id,k(c))});let o=[];e.forEach((c,d)=>o.push({node:c,at:d}));let r=new Array(o.length).fill(null);for(let c=o.length-2;c>=0;c--){let d=k(o[c+1].node);r[c]=d!==k(o[c].node)?d:r[c+1]}let s=[],a=[null],i=null,l=[];return o.forEach(({node:c,at:d},f)=>{let p=k(c),u=new Set;for(;p!==null&&!a.includes(p)&&!u.has(p);)u.add(p),p=t.has(p)?t.get(p):null;a.includes(p)||(p=null);let h=r[f];a.indexOf(h)>a.indexOf(p)&&(p=h);let m=a.slice(0,a.indexOf(p)+1),g=c.attrs.indent;if(S(c)){let E=Number.isInteger(g)&&g>0?g:0,b=i&&S(i.node)&&i.parent===p;for(b||(l=[]);l.length&&l[l.length-1].orig>E;)l.pop();let N=0;if(l.length){let C=l[l.length-1];N=C.shift,C.orig===E&&l.pop()}g=Math.max(0,Math.min(E-N,b?i.indent+1:0)),l.push({orig:E,shift:E-g})}else l=[];(p!==k(c)||S(c)&&g!==c.attrs.indent)&&s.push({at:d,attrs:{...c.attrs,parent:p,...S(c)?{indent:g}:{}}}),i={node:c,parent:p,indent:g},a=A(c)&&c.attrs.id?[...m,c.attrs.id]:m}),s}function Zn(){let e=new WeakSet;return new wt({appendTransaction(n,t,o){if(!n.some(a=>a.docChanged&&!a.getMeta(ot)))return null;if(e.has(t.doc)&&je(t.doc,o.doc))return e.add(o.doc),null;let r=xe(o.doc,t.doc);if(!r.length)return e.add(o.doc),null;let s=o.tr;for(let a of r)s.setNodeMarkup(a.at,null,a.attrs);return s}})}function at(e,n,t){let o=e.resolve(n.from).index(0),r=Math.min(e.resolve(n.to).index(0),t.length-1);return r>o&&n.to<=t[r].at&&r--,[Math.min(o,t.length-1),r]}var ne=at;function z(e,n,t){let o=n;for(;e[o].up>=0&&t>e[e[o].up].subEnd;)o=e[o].up;let r=e[o].up,s=e[o].subEnd;for(;s<t;)s=e[s+1].subEnd;return{lo:o,hi:s,up:r}}var ye=(e,n,t)=>{let o=e.resolve(Math.max(0,Math.min(n,e.content.size)));return o.depth===0?o.pos:t<0?o.before(1):o.after(1)},Jt=e=>({id:e.node.attrs.id,at:e.at,node:e.node}),bt=(e,n)=>n.id?e.node.attrs.id===n.id:e.at===n.at&&e.node.type===n.node.type&&e.node.content.eq(n.node.content);function Ae(e,n,t){let o=[];for(let r=n;r<=t;r=e[r].subEnd+1)o.push(Jt(e[r]));return{roots:o,members:e.slice(n,t+1).map(Jt)}}function Se(e,n){let t=n.roots.map(a=>e.findIndex(i=>bt(i,a))).filter(a=>a>=0);if(!t.length||t.some(a=>e[a].hidden))return null;let o=t[0],r=e[o].up,s=e[o].subEnd;for(let a of t.slice(1)){if(a!==s+1||e[a].up!==r)return null;s=e[a].subEnd}return e.slice(o,s+1).some(a=>!n.members.some(i=>bt(a,i)))?null:{lo:o,hi:s}}var we=(e,n)=>{let t=o=>({...o,at:n.map(o.at,1)});return{roots:e.roots.map(t),members:e.members.map(t)}},x=class e extends st{map(n,t){return this.getBookmark().map(t).resolve(n)}eq(n){return n instanceof e&&n.anchor===this.anchor&&n.head===this.head}toJSON(){return{type:"page-block",anchor:this.anchor,head:this.head}}static fromJSON(n,t){return new e(n.resolve(t.anchor),n.resolve(t.head))}getBookmark(){let{lo:n,hi:t}=this.span();return new kt(this.anchor,this.head,Ae(y(this.$from.doc),n,t))}span(n=this.$from.doc){return{lo:n.resolve(this.from).index(0),hi:n.resolve(this.to).index(0)-1}}};x.prototype.visible=!1;st.jsonID("page-block",x);var kt=class e{constructor(n,t,o){this.anchor=n,this.head=t,this.span=o}map(n){let t=this.anchor<=this.head;return new e(n.map(this.anchor,t?1:-1),n.map(this.head,t?-1:1),we(this.span,n))}resolve(n){let t=y(n),o=Se(t,this.span);if(!o){let a=t.find(i=>bt(i,this.span.roots[0]));return st.near(n.resolve(a?.at??ye(n,Math.min(this.anchor,this.head),-1)))}let r=t[o.lo].at,s=t[o.hi].end;return this.anchor<=this.head?new x(n.resolve(r),n.resolve(s)):new x(n.resolve(s),n.resolve(r))}},oe=(e,n)=>{for(let t=n-1;t>=0;t--)if(e[t].up===e[n].up)return t;return-1};function G(e,n,t,o,r=()=>null){let s=r(e[n])||{},a="parent"in s?s.parent:k(e[n].node),i=null;for(let d=0;d<e.length&&e[d].end<=o;d++)d>=n&&d<=t||k(e[d].node)===a&&(i=e[d].node.attrs.id);let l=[],c={};for(let d=n;d<=t;d++){let f=e[d].node,p=r(e[d]);l.push(f.attrs.id),p&&"indent"in p&&p.indent!==f.attrs.indent&&(c[f.attrs.id]={indent:p.indent})}return{ids:l,afterId:i,parent:a,attrs:c}}function re(e,n,t,o,r,s=()=>null,a=e.selection){let i=n[t].at,l=n[o].end,c=l-i,d=[];for(let h=t;h<=o;h++){let m=n[h].node;d.push(m.type.create({...m.attrs,...s(n[h])||{},pos:null},m.content,m.marks))}let f=e.tr.delete(i,l),p=r>i?r-c:r;f.insert(p,d);let u=p-i;return a instanceof x?f.setSelection(new x(f.doc.resolve(a.anchor+u),f.doc.resolve(a.head+u))):a instanceof Yt?f.setSelection(Yt.create(f.doc,a.from+u)):f.setSelection(I.create(f.doc,a.anchor+u,a.head+u)),f.setMeta(q,G(n,t,o,r,s))}function xt(e,n,t){let o=e[t].node;if(A(o)){let s=o.attrs.id,a=k(o);return i=>k(i.node)===s?{parent:a}:null}let r=o.attrs.indent-e[n].node.attrs.indent;return s=>S(s.node)?{indent:s.node.attrs.indent+r}:null}var Zt=e=>(n,t)=>{t=Mt(t);let o=y(n.doc);if(!o.length)return!1;let[r,s]=at(n.doc,n.selection,o),{lo:a,hi:i,up:l}=z(o,r,s),c,d=()=>null;if(e<0){let f=oe(o,a);if(f>=0)c=o[f].at;else if(l>=0)c=o[l].at,d=xt(o,a,l);else return!0}else{let f=i+1;if(f<o.length&&o[f].up===l)c=o[o[f].subEnd].end;else if(l>=0)c=o[o[l].subEnd].end,d=xt(o,a,l);else return!0}return t&&t(re(n,o,a,i,c,d).scrollIntoView()),!0},Ee=8,rt=(e,n)=>S(e.node)&&S(n.node)&&k(e.node)===k(n.node);function Me(e,n){n=Mt(n);let t=y(e.doc);if(!t.length)return!1;let[o,r]=at(e.doc,e.selection,t),s=t[o];if(S(s.node)&&o>0&&rt(t[o-1],s)){if(s.node.attrs.indent>t[o-1].node.attrs.indent)return!0;for(let i=o;i<=Math.max(r,s.subEnd);i++)if(t[i].node.attrs.indent>=Ee)return!0;if(n){let i=e.tr,l=r;for(let d=o;d<=l;d++)l=Math.max(l,t[d].subEnd);let c=o-1;for(let d=o;d<=l&&rt(t[d],s);d++)i.setNodeMarkup(t[d].at,null,{...t[d].node.attrs,indent:t[d].node.attrs.indent+1}),c=d;i.setMeta(q,G(t,o,c,t[o].at,d=>d.i>=o&&d.i<=c?{indent:d.node.attrs.indent+1}:null)),n(i)}return!0}let a=oe(t,o);if(a<0||!A(t[a].node)||t[a].subEnd!==o-1)return!0;if(n){let{hi:i}=z(t,o,r),l=e.tr,c=k(s.node),d=t[a].node.attrs.id,f=[];for(let u=o;u<=i;u++)k(t[u].node)===c&&(l.setNodeMarkup(t[u].at,null,{...t[u].node.attrs,parent:d}),f.push(t[u].node.attrs.id));t[a].node.attrs.open||l.setNodeMarkup(t[a].at,null,{...t[a].node.attrs,open:!0});let p=G(t,o,i,t[o].at,u=>u.i>=o&&u.i<=i&&k(u.node)===c?{parent:d}:null);l.setMeta(q,{...p,ids:f,attrs:t[a].node.attrs.open?p.attrs:{...p.attrs,[d]:{open:!0}}}),n(l)}return!0}function vt(e,n){n=Mt(n);let t=y(e.doc);if(!t.length)return!1;let[o,r]=at(e.doc,e.selection,t),s=t[o];if(S(s.node)&&s.node.attrs.indent>0){if(n){let{lo:d,hi:f}=z(t,o,r),p=e.tr,u=new Set;for(let h=o;h<=r;){let m=t[h];if(S(m.node)&&m.node.attrs.indent>0)for(let g=h;g<=m.subEnd;g++)S(t[g].node)&&(p.setNodeMarkup(t[g].at,null,{...t[g].node.attrs,indent:t[g].node.attrs.indent-1}),u.add(g));h=m.subEnd+1}p.setMeta(q,G(t,d,f,t[d].at,h=>u.has(h.i)?{indent:h.node.attrs.indent-1}:null)),n(p)}return!0}if(k(s.node)===null)return!0;let{lo:i,hi:l}=z(t,o,r),c=t[i].up;for(;c>=0&&!A(t[c].node);)c=t[c].up;if(c<0)return!0;if(n){let d=xt(t,i,c),f=t[c].subEnd;if(l===f){let p=e.tr;for(let u=i;u<=l;u++){let h=d(t[u]);h&&p.setNodeMarkup(t[u].at,null,{...t[u].node.attrs,...h})}p.setMeta(q,G(t,i,l,t[i].at,d)),n(p)}else n(re(e,t,i,l,t[f].end,d).scrollIntoView())}return!0}function se(e){let n=e.tr;return e.selection.empty||n.deleteSelection(),n}function ve(e,n){let{$from:t,$to:o,empty:r}=e.selection;if(t.depth!==1||!S(t.parent)||!t.sameParent(o))return!1;if(r&&t.parent.content.size===0){let h=t.parent;return h.attrs.indent>0?vt(e,n):(n&&n(e.tr.setNodeMarkup(t.before(),M.paragraph,{id:h.attrs.id,pos:h.attrs.pos,parent:h.attrs.parent})),!0)}let s=se(e),a=s.selection.$from,i=a.parent,l=y(s.doc),c=a.index(0),d=a.parentOffset===0,f=a.parentOffset===i.content.size,p=l[c+1],u=f&&p&&rt(p,l[c])&&p.node.attrs.indent>i.attrs.indent;return d?(s.split(a.pos,1,[{type:M.list_item,attrs:i.attrs}]),s.setNodeMarkup(l[c].at,null,{...i.attrs,checked:!1})):s.split(a.pos,1,[{type:M.list_item,attrs:{...i.attrs,checked:!1,indent:i.attrs.indent+(u?1:0)}}]),n&&n(s.scrollIntoView()),!0}function Te(e,n){let{$from:t,$to:o}=e.selection;if(t.depth!==1||!A(t.parent)||!t.sameParent(o))return!1;let r=se(e),s=r.selection.$from,a=s.parent,i=y(r.doc),l=s.index(0),c=i[l],d=c.subEnd>l;if(a.content.size===0&&!d)return r.setNodeMarkup(c.at,M.paragraph,{id:a.attrs.id,pos:a.attrs.pos,parent:a.attrs.parent}),n&&n(r),!0;if(s.parentOffset===0&&a.content.size>0)return r.insert(c.at,M.paragraph.create({parent:k(a)})),n&&n(r.scrollIntoView()),!0;let f=a.content.cut(s.parentOffset);if(a.attrs.open)r.split(s.pos,1,[{type:M.paragraph,attrs:{parent:a.attrs.id}}]);else{let p=i[c.subEnd].end,u=r.steps.length;r.delete(s.pos,c.end-1);let h=r.mapping.slice(u).map(p);r.insert(h,M.toggle.create({parent:k(a),open:!1},f)),r.setSelection(I.create(r.doc,h+1))}return n&&n(r.scrollIntoView()),!0}function Ne(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||t.parent.type!==M.paragraph||t.parent.content.size)return!1;let r=k(t.parent);if(r===null)return!1;let s=y(e.doc),a=t.index(0),i=s.findIndex(l=>l.node.attrs.id===r);if(i<0||s[i].subEnd!==a)return!1;if(n){let l=s[a].node.attrs.id,c=k(s[i].node),d=a>0?s[a-1].node:null,f=e.tr.setNodeMarkup(s[a].at,null,{...t.parent.attrs,parent:c});f.setMeta(q,{ids:[l],afterId:d?d.attrs.id:null,parent:k(d??s[a].node),attrs:{[l]:{parent:c}}}),n(f)}return!0}function Ie(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!t.parent.isTextblock||t.parent.type.spec.code)return!1;let r=t.parent;if(S(r)||A(r)||k(r)===null||t.parentOffset!==r.content.size)return!1;if(n){let s=e.tr.split(t.pos,1,[{type:M.paragraph,attrs:{parent:k(r)}}]);n(s.scrollIntoView())}return!0}function Ce(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!S(t.parent)||t.parentOffset!==0)return!1;if(t.parent.attrs.indent>0)return vt(e,n);let r=t.parent;return n&&n(e.tr.setNodeMarkup(t.before(),M.paragraph,{id:r.attrs.id,pos:r.attrs.pos,parent:r.attrs.parent})),!0}function Oe(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!A(t.parent)||t.parentOffset!==0)return!1;let r=t.parent;return n&&n(e.tr.setNodeMarkup(t.before(),M.paragraph,{id:r.attrs.id,pos:r.attrs.pos,parent:r.attrs.parent})),!0}function Tt(e,n){if(n<=0||!e[n-1].hidden)return-1;let t=n-1;for(;t>=0&&e[t].hidden;)t--;return t>=0&&A(e[t].node)&&e[t].subEnd>=n-1?t:-1}function Nt(e,n,t,o){let r=e.tr,s=n[o],a=n[t].end-1;return r.delete(s.at,s.end),s.node.content.size&&r.insert(a,s.node.content),r.setSelection(I.create(r.doc,a))}function De(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||t.parentOffset!==0||!t.parent.isTextblock)return!1;let r=y(e.doc),s=t.index(0),a=Tt(r,s);return a<0?!1:(n&&n(Nt(e,r,a,s).scrollIntoView()),!0)}function $e(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!A(t.parent)||t.parent.attrs.open||t.parentOffset!==t.parent.content.size)return!1;let r=y(e.doc),s=t.index(0),a=r[s].subEnd+1;return a===s+1?!1:(a>=r.length||!r[a].node.isTextblock||n&&n(Nt(e,r,s,a).scrollIntoView()),!0)}function Le(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1)return!1;let r=t.parent,s=t.index(0);if(!r.isTextblock||r.type.spec.code||A(r)||!r.content.size||t.parentOffset!==r.content.size||s+1>=e.doc.childCount||!A(e.doc.child(s+1)))return!1;if(n&&r.type!==M.paragraph)n(e.tr.setSelection(I.create(e.doc,t.after()+1)).scrollIntoView());else if(n){let a=t.before(),i=e.tr.insert(t.after()+1,r.content).delete(a,t.after());n(i.setSelection(I.create(i.doc,a+1+r.content.size)).scrollIntoView())}return!0}var ae=e=>(n,t)=>{let{$from:o,empty:r}=n.selection;if(!r||o.depth!==1||!o.parent.isTextblock)return!1;let s=o.parent,a=o.index(0);if(o.parentOffset!==(e<0?0:s.content.size))return!1;let i=y(n.doc),l=e<0?Tt(i,a):-1,c=l>=0?l:a+e;if(c<0||c>=i.length)return!1;let d=i[c].node;if(!d.isTextblock||!s.type.spec.code&&!d.type.spec.code)return!1;if(!t)return!0;let f=n.tr,p=i[a],u=i[c],h=e<0?u.end-1:u.at+1;return!s.content.size&&!s.type.spec.code?f.delete(p.at,p.end).setSelection(I.create(f.doc,f.mapping.map(h))):!d.content.size&&!d.type.spec.code?f.delete(u.at,u.end):f.setSelection(I.create(f.doc,h)),t(f.scrollIntoView()),!0},Be=ae(-1),Pe=ae(1);function ze(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||t.parentOffset!==0||!t.parent.isTextblock)return!1;let r=t.parent;if(S(r)||A(r)||k(r)===null)return!1;let s=t.index(0);return e.doc.child(s-1).attrs.id!==k(r)?!1:(n&&n(Nt(e,y(e.doc),s-1,s).scrollIntoView()),!0)}var It="page-reveal";function to(e,n){return n.length?e.setMeta(It,{add:n}):e}function ie(e,n,t,o=y(e.doc)){let r=o[n];return e.tr.setNodeMarkup(r.at,null,{...r.node.attrs,open:t}).setMeta("addToHistory",!1).setMeta(It,{clear:[r.node.attrs.id]})}function Ve(e,n){let{$from:t}=e.selection;return t.depth!==1||!A(t.parent)?!1:(n&&n(ie(e,t.index(0),!t.parent.attrs.open)),!0)}function Re(e){let n=[];for(let t of e)!A(t.node)||t.hidden||t.open||t.subEnd===t.i||n.push({line:t.at+1,sumEnd:t.end-1,from:t.end,to:e[t.subEnd].end});return n}var yt=(e,n)=>n>e.from&&n<e.to;function At(e,n,t,o){if(o>0){let r=t.to;for(;;){let s=st.findFrom(e.resolve(r),1,!0);if(!s)break;let a=n.find(i=>yt(i,s.head));if(!a)return s.head;r=a.to}}return t.sumEnd}function te(e,n,t,o=-1,r=!1){if(!t.length)return null;let{anchor:s,head:a}=n;if(!(n instanceof I)){let c=t.find(d=>n.from>=d.from&&n.from<d.to);return c?I.create(e,c.sumEnd):null}let i=t.find(c=>yt(c,a));i&&(a=At(e,t,i,o));let l=t.find(c=>yt(c,s));if(l&&(s=l.sumEnd),!r&&s!==a){let c=Math.min(s,a),d=Math.max(s,a),f=t.find(p=>(c>p.line||c===p.sumEnd)&&c<p.from&&d>=p.to);if(f){let p=c===f.sumEnd?At(e,t,f,1):f.line;s<a?s=p:a=p}}return s===n.anchor&&a===n.head?null:I.create(e,s,a)}var qe=e=>{let n="";for(;e>0;)e--,n=String.fromCharCode(97+e%26)+n,e=Math.floor(e/26);return n},_e=e=>[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]].reduce((n,[t,o])=>{for(;e>=t;)n+=o,e-=t;return n},"");function Ke(e){let n=new Map,t=[];return e.forEach((o,r)=>{if(!S(o.node)){t=[];return}r>0&&!rt(e[r-1],o)&&(t=[]);let s=o.node.attrs.indent;if(t.length=s+1,o.node.attrs.kind!=="ordered"){t[s]=0;return}t[s]=(t[s]||0)+1;let a=t[s];n.set(r,`${s%3===0?a:s%3===1?qe(a):_e(a)}.`)}),n}var F=new ke("page-collapse"),He=["id","parent","indent","kind","open"];function je(e,n){if(e.childCount!==n.childCount)return!1;for(let t=0;t<e.childCount;t++){let o=e.child(t),r=n.child(t);if(o!==r){if(o.type!==r.type)return!1;for(let s of He)if(o.attrs[s]!==r.attrs[s])return!1}}return!0}var Ue=new Set;function pt(e,n=Ue){let t=y(e,n);return{decos:Ge(e,t),ranges:Re(t),reveal:n}}var Fe=null,We=()=>Fe??=class extends $.DecorationSet{forChild(e,n){if(n.isLeaf)return $.DecorationSet.empty;let t=this.children,o=0,r=t.length/3;for(;o<r;){let s=o+r>>1;t[s*3]<e?o=s+1:r=s}return o*3<t.length&&t[o*3]===e?t[o*3+2]:$.DecorationSet.empty}};function Ge(e,n=y(e)){let{Decoration:t,DecorationSet:o}=$,r=Ke(n),s=[],a=[];for(let i of n){let l={};if(i.hidden&&(l.class="page-hidden",l["aria-hidden"]="true"),i.depth&&(l.style=`--page-depth:${i.depth}`),r.has(i.i)&&(l["data-marker"]=r.get(i.i)),A(i.node)&&(l["aria-expanded"]=i.open?"true":"false"),Object.keys(l).length&&s.push(t.node(i.at,i.end,l)),A(i.node)&&!i.hidden){let c=t.widget(0,()=>Xe(i.node,i.open),{side:-1,ignoreSelection:!0,key:`t:${i.node.attrs.id}:${i.open}`});a.push(i.at,i.end,new o([c],[]))}}return!s.length&&!a.length?o.empty:new(We())(s,a)}function Xe(e,n=e.attrs.open){let t=document.createElement("button");return t.type="button",t.className="page-toggle-button",t.contentEditable="false",t.setAttribute("aria-label",n?"Collapse":"Expand"),t.setAttribute("data-toggle",e.attrs.id||""),t}function eo(){let e=!1;return new wt({key:F,state:{init:(n,t)=>pt(t.doc),apply(n,t,o,r){let s=n.getMeta(It);if(s){let a=new Set(t.reveal);for(let i of s.add??[])a.add(i);for(let i of s.clear??[])a.delete(i);return pt(r.doc,a)}return n.docChanged?pt(r.doc,t.reveal):t}},appendTransaction(n,t,o){if(!n.some(i=>i.docChanged||i.selectionSet))return null;let s=n.some(i=>i.selectionSet)&&o.selection.head>=t.selection.head?1:-1,a=te(o.doc,o.selection,F.getState(o).ranges,s,e);return a?o.tr.setSelection(a):null},props:{decorations:n=>F.getState(n).decos,handleDOMEvents:{mousedown:(n,t)=>{let o=t.target.closest?.(".page-toggle-button");if(o){t.preventDefault();let a=y(n.state.doc),i=a.findIndex(l=>l.node.attrs.id===o.dataset.toggle);return i>=0&&n.dispatch(ie(n.state,i,!a[i].node.attrs.open,a)),!0}e=!0;let r=n.dom.ownerDocument.defaultView,s=()=>{e=!1,r.removeEventListener("mouseup",s,!0);let a=te(n.state.doc,n.state.selection,F.getState(n.state).ranges,1,!1);a&&n.dispatch(n.state.tr.setSelection(a))};return r.addEventListener("mouseup",s,!0),!1}},handleKeyDown(n,t){let o={ArrowDown:1,ArrowRight:1,ArrowUp:-1,ArrowLeft:-1}[t.key];if(!o||t.altKey||t.metaKey||t.ctrlKey)return!1;let{head:r}=n.state.selection,a=t.key==="ArrowDown"||t.key==="ArrowUp"?o>0?"down":"up":o>0?"forward":"backward";if(!n.endOfTextblock(a))return!1;let i=y(n.state.doc),{ranges:l}=F.getState(n.state),d=n.state.doc.resolve(r).index(0),f=null;if(o>0){let u=l.find(h=>h.from===i[d].end);u&&(f=At(n.state.doc,l,u,1))}else{let u=Tt(i,d);u>=0&&(f=t.shiftKey?i[u].at+1:i[u].end-1)}if(f===null||f===r)return!1;let p=t.shiftKey?n.state.selection.anchor:f;return n.dispatch(n.state.tr.setSelection(I.create(n.state.doc,p,f)).scrollIntoView()),!0}}})}var ee=/^([ \t]*)(?:([-*+•])|(\d+)[.)])[ \t]+(?:\[([ xX])\][ \t]+)?(.*)$/;function Qe(e){let n=e.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);if(!n.some(r=>ee.test(r)))return null;let t=[],o=[];for(let r of n){if(!r.trim())continue;let s=ee.exec(r);if(!s){t.length=0,o.push(M.paragraph.create(null,r.trim()?T.text(r.trim()):null));continue}let a=s[1].replace(/\t/g," ").length;for(;t.length&&t[t.length-1]>a;)t.pop();(!t.length||t[t.length-1]<a)&&t.push(a);let i=Math.min(t.length-1,o.length&&S(o[o.length-1])?o[o.length-1].attrs.indent+1:0),l=s[4]!==void 0?"check":s[3]!==void 0?"ordered":"bullet";o.push(M.list_item.create({kind:l,indent:i,checked:s[4]==="x"||s[4]==="X"},s[5]?T.text(s[5]):null))}return new O.Slice(O.Fragment.from(o),0,0)}var ht=new Set(["UL","OL"]),mt=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","PRE","BLOCKQUOTE","UL","OL","LI","DETAILS","SUMMARY","TABLE","HR","FIGURE"]);function Ye(e){let n=e.querySelector(":scope > input[type=checkbox], :scope > p > input[type=checkbox], :scope > label > input[type=checkbox]");if(n)return{check:!0,checked:n.checked||n.hasAttribute("checked")};if(e.getAttribute("role")==="checkbox"||e.hasAttribute("aria-checked"))return{check:!0,checked:e.getAttribute("aria-checked")==="true"};if(e.hasAttribute("data-checked"))return{check:!0,checked:e.getAttribute("data-checked")==="true"};let o=e.className||"";return/\b(checked|task-list-item|to-do)\b/.test(o)||e.closest?.("ul.to-do-list, ul.contains-task-list")?{check:!0,checked:/\bchecked\b/.test(o)||!!e.querySelector(".checkbox-on")}:{check:!1,checked:!1}}function Je(e){let n=(e.getAttribute("style")||"")+";"+(e.parentElement?.getAttribute("style")||""),t=/list-style-type\s*:\s*([a-z-]+)/i.exec(e.getAttribute("style")||"")?.[1];return t?/decimal|alpha|roman|latin|greek/.test(t)?"ordered":"bullet":e.parentElement?.tagName==="OL"?"ordered":"bullet"}function Ze(e,n=globalThis.document){let t=n.createElement("div");t.innerHTML=e;for(let u of t.querySelectorAll('b[style*="font-weight:normal"], b[style*="font-weight: normal"]'))u.replaceWith(...u.childNodes);let o=0,r=n.createElement("div"),s=u=>{let h=parseInt(u.getAttribute("aria-level"),10);if(h>0)return h-1;let m=-1;for(let g=u.parentElement;g&&g!==t;g=g.parentElement)ht.has(g.tagName)&&m++;return Math.max(0,m)},a=[];function i(u,h,m){let g=n.createElement("div"),{check:E,checked:b}=Ye(u);g.setAttribute("data-page-li",""),g.setAttribute("data-kind",E?"check":Je(u)),g.setAttribute("data-checked",b?"true":"false"),g.dataset.depth=String(s(u)),h&&g.setAttribute("data-page-parent",h);let N=!0,C=[];for(let w of[...u.childNodes]){if(w.nodeType===1&&ht.has(w.tagName)){C.push(w);continue}if(!(w.nodeType===1&&w.tagName==="INPUT")){if(w.nodeType===1&&mt.has(w.tagName)){N||g.appendChild(n.createElement("br"));for(let P of[...w.childNodes])P.nodeType===1&&P.tagName==="INPUT"||g.appendChild(P);N=!1;continue}g.appendChild(w),(w.nodeType!==3||w.textContent.trim())&&(N=!1)}}m.appendChild(g),a.push(g);for(let w of C)l(w,h,m)}function l(u,h,m){let g=null,E=b=>{g||(g=n.createElement("p"),h&&g.setAttribute("data-page-parent",h),m.appendChild(g)),g.appendChild(b)};for(let b of[...u.childNodes])if(!(b.nodeType===1&&(b.tagName==="META"||b.tagName==="STYLE"))){if(b.nodeType===1&&b.tagName==="BR"){g=null;continue}if(b.nodeType!==1){b.nodeType===3&&(g||b.textContent.trim())&&E(b);continue}if(!mt.has(b.tagName)&&b.tagName!=="ASIDE"){E(b);continue}if(g=null,ht.has(b.tagName)){l(b,h,m);continue}if(b.tagName==="LI"){i(b,h,m);continue}if(b.tagName==="DETAILS"){let N=`paste-${++o}`,C=b.querySelector(":scope > summary"),w=n.createElement("div");w.setAttribute("data-page-toggle",N),b.hasAttribute("open")&&w.setAttribute("data-open","true"),h&&w.setAttribute("data-page-parent",h);let P=C?.querySelector(":scope > h1, :scope > h2, :scope > h3");P?(w.setAttribute("data-level",P.tagName[1]),w.append(...P.childNodes)):C&&w.append(...C.childNodes),m.appendChild(w);for(let Pt of[...b.childNodes])if(Pt!==C){let zt=n.createElement("div");zt.appendChild(Pt),l(zt,N,m)}continue}if(b.tagName==="DIV"&&!b.hasAttribute("data-page-li")&&[...b.children].some(N=>mt.has(N.tagName))){l(b,h,m);continue}h&&b.setAttribute("data-page-parent",h),m.appendChild(b)}}l(t,null,r);let c=a.length?Math.min(...a.map(u=>+u.dataset.depth)):0,d=null;for(let u of a){let h=+u.dataset.depth-c,m=d&&u.previousElementSibling===d?+d.getAttribute("data-indent")+1:0;u.setAttribute("data-indent",String(Math.min(h,m))),u.removeAttribute("data-depth"),d=u}let f=u=>{if(u.nodeType!==1||u.tagName==="IMG")return[u.cloneNode(!0)];let h=[],m=u.cloneNode(!1);for(let g of u.childNodes)for(let E of f(g))E.nodeType===1&&E.tagName==="IMG"?(m.hasChildNodes()&&h.push(m),h.push(E),m=u.cloneNode(!1)):m.appendChild(E);return(m.hasChildNodes()||!h.length)&&h.push(m),h};for(let u of[...r.children]){if(!u.matches("p, h1, h2, h3, h4, h5, h6, aside, div[data-page-li], div.page-li")||!u.querySelector("img"))continue;let h=f(u),m=u.getAttribute("data-page-parent");if(m)for(let g of h)g.setAttribute("data-page-parent",m);u.replaceWith(...h)}let p=t.querySelector("[data-pm-slice]");return p&&r.firstElementChild?.setAttribute("data-pm-slice",p.dataset.pmSlice),r.innerHTML}var gt=(e,n=0)=>e!==null&&e!==""&&Number.isInteger(+e)&&+e>=n?+e:null,v=e=>e.getAttribute("data-page-parent")||null,tn=Rt([]).type,en=Object.create(T,{marks:{value:{...T.marks,[nt]:tn}}}),ce=e=>{let n;try{n=Qt(e)}catch{return null}return!n||typeof n.t!="string"||n.t==="opaque_block"||Object.hasOwn(Ft,n.t)?null:n},nn=e=>{let n=ce(e);return n?{raw:n,parent:v(e)}:!1},on=e=>{let n=ce(e);if(!n||typeof n.c!="string"||!n.c)return O.Fragment.empty;let t=Ht(n.m,n.c.length);return O.Fragment.from(jt(T,n.c,t,T.nodes.opaque_block))},rn=e=>{try{return{entries:Wt(e.getAttribute(ut))}}catch{return!1}},X=null,sn=()=>import("./c-RT3C74GY.js").then(e=>{X=e},()=>{}),an=new O.DOMParser(en,[{tag:"table",node:"table",getAttrs:e=>X?.table(e)??!1,getContent:e=>X.rows(e)},{tag:`div[${Ut}]`,node:"opaque_block",getAttrs:nn,getContent:on},{tag:`span[${ut}]`,mark:nt,getAttrs:rn},{tag:"div[data-page-li]",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div.page-li",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div[data-page-toggle]",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-page-toggle"),open:e.getAttribute("data-open")==="true",parent:v(e),level:ft(Number(e.getAttribute("data-level")))})},{tag:"div.page-toggle",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-id"),open:e.getAttribute("data-open")==="true",parent:null,level:ft(Number(e.getAttribute("data-level")))})},{tag:"h1",node:"heading",getAttrs:e=>({level:1,parent:v(e)})},{tag:"h2",node:"heading",getAttrs:e=>({level:2,parent:v(e)})},{tag:"h3",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"h4",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"pre",node:"code_block",preserveWhitespace:"full",getAttrs:e=>({lang:e.getAttribute("data-lang")||"",parent:v(e)})},{tag:"hr",node:"divider",getAttrs:e=>({parent:v(e)})},{tag:"aside.page-callout",node:"callout",getAttrs:e=>({parent:v(e)})},{tag:'figure:not([data-type]), figure[data-type="image"]',node:"image",getAttrs:e=>{let n=e.querySelector("img"),t=et(n?.getAttribute("src"));return t?{src:t,alt:n.getAttribute("alt")||"",caption:e.querySelector("figcaption")?.textContent||"",width:gt(e.getAttribute("data-width")??n.getAttribute("width"),1),align:be(e.getAttribute("data-align")),parent:v(e)}:!1}},{tag:"img[src]",node:"image",getAttrs:e=>{let n=et(e.getAttribute("src"));return n?{src:n,alt:e.getAttribute("alt")||"",width:gt(e.getAttribute("width"),1),parent:v(e)}:!1}},{tag:'div.page-file, div[data-type="file"]',node:"file",getAttrs:e=>{let n=L(e.getAttribute("data-src"));return n?{src:n,name:e.getAttribute("data-name")||"file",size:gt(e.getAttribute("data-size")),mime:e.getAttribute("data-mime")||null,parent:v(e)}:!1}},{tag:"p",node:"paragraph",getAttrs:e=>({parent:v(e)})},{tag:"br",node:"hard_break"},{tag:"strong",mark:"strong"},{tag:"b",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(normal|[1-5]00)\b/.test(e.getAttribute("style")||"")?!1:null},{tag:"span",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(bold|[6-9]00)\b/.test(e.getAttribute("style")||"")?null:!1},{tag:"em",mark:"em"},{tag:"i",mark:"em"},{tag:"span",mark:"em",getAttrs:e=>/font-style\s*:\s*italic/.test(e.getAttribute("style")||"")?null:!1},{tag:"s",mark:"strike"},{tag:"del",mark:"strike"},{tag:"code",mark:"code"},{tag:"a[href]",mark:"link",getAttrs:e=>{let n=L(e.getAttribute("href"));return n?{href:n}:!1}},{tag:"blockquote",node:"quote",getAttrs:e=>({parent:v(e)})},{tag:"u",mark:"underline"},{tag:"mark",mark:"highlight",getAttrs:e=>ct("highlight",{color:e.getAttribute("data-color")})??!1},{tag:"span[data-color]",mark:"text_color",getAttrs:e=>ct("text_color",{color:e.getAttribute("data-color")})??!1}]);function cn(e,n){let t=n.selection.$from,o=n.selection instanceof x,r=o?n.doc.child(n.selection.span().lo):t.depth>=1?t.node(1):null,s=r?k(r):null,a=r&&S(r)?r.attrs.indent:0,i=new Map;e.content.forEach(m=>{A(m)&&m.attrs.id&&i.set(m.attrs.id,V())});let l=[];e.content.forEach(m=>{if(!m.type.spec.group?.includes("block")){l.push(m);return}let g=k(m),E={...m.attrs,pos:null,id:A(m)?i.get(m.attrs.id)??null:null,parent:g!==null&&i.has(g)?i.get(g):s};S(m)&&(E.indent=m.attrs.indent+a),l.push(m.type.create(E,m.content,m.marks))});let c=!r||!(S(r)||A(r)),d=m=>m&&(S(m)||A(m)),f=c&&d(l[0])?0:e.openStart,p=l[l.length-1],u=new Set(i.values()),h=c&&(d(p)||p&&u.has(k(p)))?0:e.openEnd;return new O.Slice(O.Fragment.from(l),o?0:f,o?0:h)}var St=class extends O.DOMSerializer{serializeFragment(n,t,o){let r=super.serializeFragment(n,t,o);if(!n.firstChild?.isBlock)return r;let s=[...r.childNodes];return n.forEach((a,i,l)=>{let c=s[l];!c||c.nodeType!==1||(k(a)!==null&&c.setAttribute("data-page-parent",k(a)),A(a)&&a.attrs.id&&c.setAttribute("data-page-toggle",a.attrs.id),a.type===M.image&&a.attrs.width&&c.setAttribute("data-width",String(a.attrs.width)))}),X?.copy(n,s),r}},le=O.DOMSerializer.fromSchema(T),ln=e=>{let{t:n,...t}=e.attrs.raw??{},{c:o,m:r}=_t(e.content);return o?{t:n,...t,c:o,...r.some(Boolean)?{m:Kt(r)}:{}}:{t:n,...t}},dn=e=>["div",{"data-type":"newer-format",...Gt(ln(e))},0],un=e=>["span",Xt(e.attrs.entries),0],fn={...le.nodes,opaque_block:dn},pn={...le.marks,[nt]:un},hn=new St(fn,pn);function mn(e,n,t){let{$from:o}=e.state.selection,r=o.depth>=1?o.node(1):null;if(!r||!A(r)||r.attrs.open||t.content.childCount<2)return!1;let s=e.state.tr.setNodeMarkup(o.before(1),null,{...r.attrs,open:!0}).replaceSelection(t);return e.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function gn(e){let n=!1;return e?.content?.descendants(t=>n?!1:((t.type===M.quote||t.isText&&t.marks.some(o=>qt.has(o.type.name)))&&(n=!0),!n)),n}function bn(e,n,t){let o=e.state.selection.from,r=e.state.selection.to,s=e.state.doc,a=()=>{let i=t.content.textBetween(0,t.content.size,`
|
|
4
|
-
`," ");return!e.isDestroyed&&i&&e.state.doc===s&&e.dispatch(e.state.tr.insertText(i,o,r)),!1};return import("./c-VBLFAQD2.js").then(({pasteFormats:i})=>i(e,t,o,r),a),!0}function no(){return new wt({view(){return sn(),{}},props:{handlePaste(e,n,t){return gn(t)?bn(e,n,t):mn(e,n,t)},clipboardSerializer:hn,clipboardTextSerializer:e=>X?.text(e),transformPastedHTML:e=>Ze(e),clipboardParser:an,clipboardTextParser:(e,n,t)=>t?null:Qe(e),transformPasted:(e,n)=>cn(e,n.state)}})}var W=tt.chainCommands(Ce,Oe,Be,ze,De),R=tt.chainCommands($e,Le,Pe),oo={Enter:tt.chainCommands(ve,Te,Ne,Ie),Backspace:W,"Shift-Backspace":W,"Mod-Backspace":W,"Alt-Backspace":W,"Ctrl-h":W,Delete:R,"Shift-Delete":R,"Mod-Delete":R,"Alt-Delete":R,"Ctrl-d":R,"Ctrl-Alt-Backspace":R,Tab:Me,"Shift-Tab":vt,"Mod-Shift-ArrowUp":Zt(-1),"Mod-Shift-ArrowDown":Zt(1),"Mod-Enter":Ve};function io(){return new D.Plugin({view(e){let n=e.dom.ownerDocument.createElement("div");return n.className="page-live",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),e.dom.parentElement.appendChild(n),{destroy:()=>n.remove()}}})}function Ct(e,n){let t=e.dom.parentElement?.querySelector(".page-live");t&&(t.textContent="",t.textContent=n)}var de=new D.PluginKey("tableRect");var{Selection:kn,TextSelection:K,NodeSelection:xn,Plugin:yn,PluginKey:An}=D,Q=T.nodes,H=e=>Z.closeHistory(e).setMeta(Et,!0);function Y(e,n,t=n,o=y(e)){let{lo:r,hi:s}=z(o,Math.min(n,t),Math.max(n,t)),a=o[r].at,i=o[s].end;return n<=t?new x(e.resolve(a),e.resolve(i)):new x(e.resolve(i),e.resolve(a))}function Sn(e,n=y(e.doc)){let[t,o]=ne(e.doc,e.selection,n);return z(n,t,o)}var _=(e,n,t)=>{for(let o=n;o>=0&&o<e.length;o+=t)if(!e[o].hidden)return o;return-1};function wn(e,n){if(e.selection instanceof x)return!1;let t=Math.min(e.selection.$head.index(0),e.doc.childCount-1);return n&&n(e.tr.setSelection(Y(e.doc,t))),!0}var ue=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=e<0?_(r,s-1,-1):_(r,a+1,1);return i<0||t&&t(n.tr.setSelection(Y(n.doc,i)).scrollIntoView()),!0};function Dt(e,n,t,o){if(o<0)return n;let r=n;for(;e[r].subEnd<t;)r=e[r].subEnd+1;return r}function En(e,n){for(let t=n-1;t>=0;t--)if(e[t].up===e[n].up)return t;return n}var fe=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=o.anchor<=o.head,l=i?s:Dt(r,s,a,1),c=i?Dt(r,s,a,1):s;return e>0?i||s===a||c===l?c=_(r,(i?a:c)+1,1):c=_(r,r[c].subEnd+1,1):!i||c===l?c=_(r,(i?c:s)-1,-1):c=En(r,c),c<0||t&&t(n.tr.setSelection(Y(n.doc,l,c,r)).scrollIntoView()),!0};function it(e,n){let t=e.selection;if(!(t instanceof x))return!1;if(n){let o=e.tr.delete(t.from,t.to);o.doc.content.size===0&&o.insert(0,Q.paragraph.create()),o.setSelection(kn.near(o.doc.resolve(Math.min(t.from,o.doc.content.size)),-1)),n(H(o).scrollIntoView())}return!0}function Mn({columns:e={},cards:n={}}){let t=dt(e),o=new Map(t.map(a=>[a,V("c")])),r=lt(null,null,t.length),s={};for(let a of new Set([...t,...Object.values(n).map(i=>i.col)])){let i=dt(Object.fromEntries(Object.entries(n).filter(([,c])=>c.col===a))),l=lt(null,null,i.length);i.forEach((c,d)=>{s[V("k")]={...n[c],col:o.get(a)??a,pos:l[d]}})}return{columns:Object.fromEntries(t.map((a,i)=>[o.get(a),{...e[a],pos:r[i]}])),cards:s}}function vn(e,n){let t=y(e.doc);if(!t.length)return!1;let{lo:o,hi:r}=Sn(e,t);if(n){let s=new Map;for(let f=o;f<=r;f++)t[f].node.type===Q.toggle&&t[f].node.attrs.id&&s.set(t[f].node.attrs.id,V());let a=[];for(let f=o;f<=r;f++){let p=t[f].node,u=p.attrs.parent??null;a.push(p.type.create({...p.attrs,...p.type===Q.board?Mn(p.attrs):{},id:s.get(p.attrs.id)??null,pos:null,parent:s.get(u)??u},p.content,p.marks))}let i=t[r].end,l=i-t[o].at,c=e.tr.insert(i,a),d=e.selection;c.setSelection(d instanceof x?new x(c.doc.resolve(i),c.doc.resolve(i+l)):K.create(c.doc,d.anchor+l,d.head+l)),n(H(c).scrollIntoView())}return!0}var he=(e,n,t,o)=>{for(let r=t;r<=o;r++)if(n[r].node.isTextblock)return n[r].end-1;return-1};function pe(e,n){let t=e.selection;if(!(t instanceof x))return!1;let o=y(e.doc),{lo:r,hi:s}=t.span(e.doc);if(n){let a=he(e.doc,o,r,s);n(e.tr.setSelection(a>=0?K.create(e.doc,a):xn.create(e.doc,o[r].at)))}return!0}var Tn=({$from:e,$to:n})=>{if(e.depth<2||n.depth<2)return null;let t=e.node(1);return t.type.name==="table"&&n.node(1)===t?{from:e.before(1),to:e.after(1)}:null};function Nn(e,n){let t=e.selection,{$from:o,$to:r}=t,s=o.parent.isTextblock&&o.sameParent(r)&&!de.getState(e),a=s&&o.parentOffset===0&&r.parentOffset===r.parent.content.size;if(s&&!a&&o.parent.content.size)return n&&n(e.tr.setSelection(K.create(e.doc,o.start(),o.end()))),!0;let i=Tn(t);return i&&!(t instanceof x&&t.from===i.from&&t.to===i.to)?(n&&n(e.tr.setSelection(new x(e.doc.resolve(i.from),e.doc.resolve(i.to)))),!0):(n&&n(e.tr.setSelection(new x(e.doc.resolve(0),e.doc.resolve(e.doc.content.size)))),!0)}var In=(e,n)=>{let t=e.state,o=t.selection;if(!(o instanceof x))return!1;let r=y(t.doc),{lo:s,hi:a}=o.span(t.doc),i=he(t.doc,r,s,a),l=t.tr;if(i<0){let c=r[a].end;l.insert(c,Q.paragraph.create({parent:r[s].node.attrs.parent??null})),l.setSelection(K.create(l.doc,c+1)),H(l)}else l.setSelection(K.create(l.doc,i));return l.insertText(n),e.dispatch(l.scrollIntoView()),!0},Cn=(e,n,t)=>{let o=e.selection;if(!(o instanceof K)||!t?.endOfTextblock("down"))return!1;let{$anchor:r,$head:s}=o;if(r.depth!==1||r.parent.type!==Q.toggle||r.parent.attrs.open||r.index(0)!==s.index(0))return!1;let a=y(e.doc),i=r.index(0),l=_(a,a[i].subEnd+1,1);return l<0?!1:(n&&n(e.tr.setSelection(Y(e.doc,i,l,a)).scrollIntoView()),!0)},On=e=>(n,t,o)=>n.selection instanceof x&&e(n,t,o),Dn={Escape:(e,n)=>pe(e,n)||wn(e,n),Enter:On(pe),ArrowUp:ue(-1),ArrowDown:ue(1),"Shift-ArrowUp":fe(-1),"Shift-ArrowDown":(e,n,t)=>fe(1)(e,n)||Cn(e,n,t),Backspace:it,"Alt-Backspace":it,"Ctrl-h":it,Delete:it,"Mod-d":vn,"Mod-a":Nn},Ot=new An("page-blocksel"),$n=e=>{let n=e.selection,{lo:t,hi:o}=n.span(e.doc);return y(e.doc).filter(r=>r.i>=t&&r.i<=o&&!r.hidden).length};function ko(){let e=Vt.keymap(Dn);return new yn({key:Ot,state:{init:()=>0,apply:(n,t,o,r)=>n.getMeta(ot)&&o.selection instanceof x&&!(r.selection instanceof x)?t+1:t},props:{handleKeyDown:(n,t)=>e.props.handleKeyDown(n,t),handleTextInput:(n,t,o,r)=>In(n,r),decorations(n){let t=n.selection;if(!(t instanceof x))return null;let o=[];return n.doc.nodesBetween(t.from,t.to,(r,s)=>(o.push($.Decoration.node(s,s+r.nodeSize,{class:"page-block-selected"})),!1)),$.DecorationSet.create(n.doc,o)},createSelectionBetween(n,t,o){let r=n.state.selection;return r instanceof x&&t.pos===r.anchor&&o.pos===r.head?r:null},handleDOMEvents:{mousedown(n,t){let o=n.state.selection;if(!t.shiftKey||!(o instanceof x)||t.button!==0)return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});if(!r)return!1;let s=y(n.state.doc),a=Math.min(n.state.doc.resolve(r.inside>=0?r.inside:r.pos).index(0),s.length-1),{lo:i,hi:l}=o.span(n.state.doc),c=o.anchor<=o.head?i:Dt(s,i,l,1);return t.preventDefault(),n.dispatch(n.state.tr.setSelection(Y(n.state.doc,c,a,s))),!0}}},view:()=>({update(n,t){let o=n.state.selection,r=t.selection;if(o instanceof x&&!o.eq(r)){let s=$n(n.state);Ct(n,`${s} ${s===1?"block":"blocks"} selected`)}else r instanceof x&&!(o instanceof x)&&Ct(n,Ot.getState(n.state)!==Ot.getState(t)?"Block selection cleared because the document changed":"Selection cleared")}})})}var{Plugin:Ln,PluginKey:Bn,TextSelection:J}=D,{Decoration:Pn,DecorationSet:zn}=$,U=T.marks.link,Vn=e=>/^(https?:\/\/|mailto:|tel:|www\.)\S+$/i.test(e.trim())&&L(e)!==null;function $t(e,n){let t=e.resolve(n);if(!t.parent.inlineContent)return null;let o=U.isInSet((t.nodeAfter??t.nodeBefore)?.marks??[]);if(!o)return null;let r=[];t.parent.forEach((c,d)=>r.push({n:c,off:d}));let s=r.findIndex(({n:c,off:d})=>d<=t.parentOffset&&t.parentOffset<=d+c.nodeSize&&o.isInSet(c.marks));if(s<0)return null;let a=s,i=s;for(;a>0&&o.isInSet(r[a-1].n.marks);)a--;for(;i<r.length-1&&o.isInSet(r[i+1].n.marks);)i++;let l=t.start();return{from:l+r[a].off,to:l+r[i].off+r[i].n.nodeSize,href:o.attrs.href}}function me(e,n,t,o){let r=e.tr.removeMark(n,t,U);return o&&r.addMark(n,t,U.create({href:o})),H(r)}var B=new Bn("page-link"),Lt=new WeakMap,ge=e=>`<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">${e}</svg>`,Rn=ge('<path d="M9 3h4v4M13 3 7.5 8.5M11 9.5V13H3V5h3.5"/>'),qn=ge('<path d="M4 4l8 8M12 4l-8 8"/>');function j(e,n,t,o={}){let r=e.createElement(n);t&&(r.className=t);for(let[s,a]of Object.entries(o))r.setAttribute(s,a);return r}function _n(e,n,t){let o=null;return e.doc.nodesBetween(n,t,r=>{let s=U.isInSet(r.marks);s&&(o=s.attrs.href)}),o}var Bt=class{constructor(n){this.view=n,this.shell=n.dom.parentElement,this.doc=n.dom.ownerDocument,this.mode=null,this.range=null;let t=this.doc;this.dom=j(t,"div","page-link",{role:"dialog","aria-label":"Link",hidden:""}),this.input=j(t,"input","page-link-input",{type:"url","aria-label":"Link address",placeholder:"Paste or type a link",autocomplete:"off",spellcheck:"false"}),this.url=j(t,"a","page-link-url",{target:"_blank",rel:"noopener noreferrer"}),this.open=j(t,"a","page-link-btn",{"data-act":"open",target:"_blank",rel:"noopener noreferrer","aria-label":"Open link in a new tab",title:"Open in a new tab"}),this.open.innerHTML=Rn,this.edit=j(t,"button","page-link-btn",{type:"button","data-act":"edit"}),this.edit.textContent="Edit",this.remove=j(t,"button","page-link-btn",{type:"button","data-act":"remove","aria-label":"Remove link",title:"Remove link"}),this.remove.innerHTML=qn,this.dom.append(this.input,this.url,this.open,this.edit,this.remove),this.shell.append(this.dom),Lt.set(n,this),this.dom.addEventListener("mousedown",o=>{o.target!==this.input&&o.preventDefault()}),this.edit.addEventListener("click",()=>this.openEdit()),this.remove.addEventListener("click",()=>this.apply("")),this.input.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||(o.key==="Enter"?(o.preventDefault(),this.apply(this.input.value)):o.key==="Escape"&&(o.preventDefault(),this.close()))}),this.onDocDown=o=>{this.mode==="edit"&&!this.dom.contains(o.target)&&this.close(!1)},this.doc.addEventListener("mousedown",this.onDocDown,!0)}openEdit(){let n=this.view.state,t=n.selection;if(!(t instanceof J)||!t.$from.sameParent(t.$to)||!t.$from.parent.inlineContent||t.$from.parent.type.spec.code)return!1;let o=t.empty?$t(n.doc,t.head):null;return this.range=o??{from:t.from,to:t.to,href:t.empty?null:_n(n,t.from,t.to)},this.mode="edit",this.view.dispatch(n.tr.setMeta(B,{from:this.range.from,to:this.range.to})),this.render(),this.input.value=this.range.href??"",this.input.removeAttribute("aria-invalid"),this.input.focus(),this.input.select(),!0}apply(n){let t=String(n).trim(),o=t?L(t):null;if(t&&!o){this.input.setAttribute("aria-invalid","true");return}let r=this.view.state,s=B.getState(r)??(this.mode==="view"?this.range:null);if(!s)return this.close();let a;if(s.from===s.to){if(!o)return this.close();a=r.tr.insert(s.from,T.text(t,[U.create({href:o})])),a.setSelection(J.create(a.doc,s.from+t.length))}else a=me(r,s.from,s.to,o),a.setSelection(J.create(a.doc,s.to));this.view.dispatch(H(a).setMeta(B,null)),this.close()}close(n=!0){this.mode=null,this.range=null,B.getState(this.view.state)&&this.view.dispatch(this.view.state.tr.setMeta(B,null)),this.dom.hidden=!0,this.dom.dataset.mode="",n&&this.view.focus(),this.update(this.view)}render(){let n=this.mode==="edit",t=L(this.range?.href);this.dom.dataset.mode=this.mode??"",this.input.hidden=!n,this.url.hidden=n,this.edit.hidden=n,this.open.hidden=!t,this.remove.hidden=!this.range?.href,t?(this.open.href=t,this.url.href=t,this.url.textContent=t.replace(/^https?:\/\//,"")):(this.open.removeAttribute("href"),this.url.removeAttribute("href"),this.url.textContent=""),this.dom.hidden=!1,this.place()}place(){let n=this.range;if(!n)return;let t=this.shell.getBoundingClientRect(),o=this.view.coordsAtPos(n.from),r=this.view.coordsAtPos(n.to,-1);this.dom.style.setProperty("--page-pop-x",`${Math.min(o.left,r.left)-t.left}px`),this.dom.style.setProperty("--page-pop-y",`${Math.max(o.bottom,r.bottom)-t.top+6}px`)}update(n){if(this.view=n,this.mode==="edit"){let r=B.getState(n.state);if(r)return this.range={...this.range,...r},this.place();this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}let t=n.state.selection,o=t instanceof J&&t.empty&&n.hasFocus()?$t(n.state.doc,t.head):null;if(!o||t.head===o.from||t.head===o.to){this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}this.mode="view",this.range=o,this.render()}destroy(){this.doc.removeEventListener("mousedown",this.onDocDown,!0),this.dom.remove(),Lt.delete(this.view)}},Kn=e=>Lt.get(e)?.openEdit()??!1;function Hn(e,n){if(n.clipboardData?.files?.length)return!1;let t=n.clipboardData?.getData("text/plain")??"";if(!Vn(t))return!1;let o=e.state.selection;if(!(o instanceof J)||!o.$from.sameParent(o.$to)||o.$from.parent.type.spec.code)return!1;let r=L(t),s=o.empty?e.state.tr.replaceSelectionWith(T.text(t.trim(),[U.create({href:r})]),!1):me(e.state,o.from,o.to,r);return e.dispatch(s.scrollIntoView().setMeta("uiEvent","paste")),!0}function Eo(){return new Ln({key:B,state:{init:()=>null,apply(e,n){let t=e.getMeta(B);if(t!==void 0)return t;if(!n||!e.docChanged)return n;let o=e.mapping.mapResult(n.from,1),r=e.mapping.mapResult(n.to,n.from===n.to?1:-1);return o.deletedAcross||r.deletedAcross||n.from!==n.to&&o.pos>=r.pos?null:{from:o.pos,to:r.pos}}},view:e=>new Bt(e),props:{decorations(e){let n=B.getState(e);return n&&n.from<n.to?zn.create(e.doc,[Pn.inline(n.from,n.to,{class:"page-link-pending"})]):null},handleKeyDown(e,n){return(n.metaKey||n.ctrlKey)&&!n.altKey&&!n.shiftKey&&n.key.toLowerCase()==="k"?(n.preventDefault(),Kn(e)||!0):!1},handlePaste:Hn,handleClick(e,n,t){if(!(t.metaKey||t.ctrlKey))return!1;let o=$t(e.state.doc,n),r=L(o?.href);return r?(e.dom.ownerDocument.defaultView.open(r,"_blank","noopener,noreferrer"),!0):!1}}})}export{Kn as a,Eo as b,io as c,Ct as d,de as e,Et as f,q as g,y as h,Jn as i,xe as j,Zn as k,z as l,Ae as m,Se as n,x as o,G as p,re as q,Zt as r,Ee as s,Me as t,vt as u,to as v,eo as w,an as x,hn as y,no as z,oo as A,H as B,Y as C,Sn as D,it as E,vn as F,In as G,ko as H};
|
|
3
|
+
`);if(!n.some(r=>ee.test(r)))return null;let t=[],o=[];for(let r of n){if(!r.trim())continue;let s=ee.exec(r);if(!s){t.length=0,o.push(M.paragraph.create(null,r.trim()?T.text(r.trim()):null));continue}let a=s[1].replace(/\t/g," ").length;for(;t.length&&t[t.length-1]>a;)t.pop();(!t.length||t[t.length-1]<a)&&t.push(a);let i=Math.min(t.length-1,o.length&&S(o[o.length-1])?o[o.length-1].attrs.indent+1:0),l=s[4]!==void 0?"check":s[3]!==void 0?"ordered":"bullet";o.push(M.list_item.create({kind:l,indent:i,checked:s[4]==="x"||s[4]==="X"},s[5]?T.text(s[5]):null))}return new O.Slice(O.Fragment.from(o),0,0)}var ht=new Set(["UL","OL"]),mt=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","PRE","BLOCKQUOTE","UL","OL","LI","DETAILS","SUMMARY","TABLE","HR","FIGURE"]);function Ye(e){let n=e.querySelector(":scope > input[type=checkbox], :scope > p > input[type=checkbox], :scope > label > input[type=checkbox]");if(n)return{check:!0,checked:n.checked||n.hasAttribute("checked")};if(e.getAttribute("role")==="checkbox"||e.hasAttribute("aria-checked"))return{check:!0,checked:e.getAttribute("aria-checked")==="true"};if(e.hasAttribute("data-checked"))return{check:!0,checked:e.getAttribute("data-checked")==="true"};let o=e.className||"";return/\b(checked|task-list-item|to-do)\b/.test(o)||e.closest?.("ul.to-do-list, ul.contains-task-list")?{check:!0,checked:/\bchecked\b/.test(o)||!!e.querySelector(".checkbox-on")}:{check:!1,checked:!1}}function Je(e){let n=(e.getAttribute("style")||"")+";"+(e.parentElement?.getAttribute("style")||""),t=/list-style-type\s*:\s*([a-z-]+)/i.exec(e.getAttribute("style")||"")?.[1];return t?/decimal|alpha|roman|latin|greek/.test(t)?"ordered":"bullet":e.parentElement?.tagName==="OL"?"ordered":"bullet"}function Ze(e,n=globalThis.document){let t=n.createElement("div");t.innerHTML=e;for(let u of t.querySelectorAll('b[style*="font-weight:normal"], b[style*="font-weight: normal"]'))u.replaceWith(...u.childNodes);let o=0,r=n.createElement("div"),s=u=>{let h=parseInt(u.getAttribute("aria-level"),10);if(h>0)return h-1;let m=-1;for(let g=u.parentElement;g&&g!==t;g=g.parentElement)ht.has(g.tagName)&&m++;return Math.max(0,m)},a=[];function i(u,h,m){let g=n.createElement("div"),{check:E,checked:b}=Ye(u);g.setAttribute("data-page-li",""),g.setAttribute("data-kind",E?"check":Je(u)),g.setAttribute("data-checked",b?"true":"false"),g.dataset.depth=String(s(u)),h&&g.setAttribute("data-page-parent",h);let N=!0,C=[];for(let w of[...u.childNodes]){if(w.nodeType===1&&ht.has(w.tagName)){C.push(w);continue}if(!(w.nodeType===1&&w.tagName==="INPUT")){if(w.nodeType===1&&mt.has(w.tagName)){N||g.appendChild(n.createElement("br"));for(let P of[...w.childNodes])P.nodeType===1&&P.tagName==="INPUT"||g.appendChild(P);N=!1;continue}g.appendChild(w),(w.nodeType!==3||w.textContent.trim())&&(N=!1)}}m.appendChild(g),a.push(g);for(let w of C)l(w,h,m)}function l(u,h,m){let g=null,E=b=>{g||(g=n.createElement("p"),h&&g.setAttribute("data-page-parent",h),m.appendChild(g)),g.appendChild(b)};for(let b of[...u.childNodes])if(!(b.nodeType===1&&(b.tagName==="META"||b.tagName==="STYLE"))){if(b.nodeType===1&&b.tagName==="BR"){g=null;continue}if(b.nodeType!==1){b.nodeType===3&&(g||b.textContent.trim())&&E(b);continue}if(!mt.has(b.tagName)&&b.tagName!=="ASIDE"){E(b);continue}if(g=null,ht.has(b.tagName)){l(b,h,m);continue}if(b.tagName==="LI"){i(b,h,m);continue}if(b.tagName==="DETAILS"){let N=`paste-${++o}`,C=b.querySelector(":scope > summary"),w=n.createElement("div");w.setAttribute("data-page-toggle",N),b.hasAttribute("open")&&w.setAttribute("data-open","true"),h&&w.setAttribute("data-page-parent",h);let P=C?.querySelector(":scope > h1, :scope > h2, :scope > h3");P?(w.setAttribute("data-level",P.tagName[1]),w.append(...P.childNodes)):C&&w.append(...C.childNodes),m.appendChild(w);for(let Pt of[...b.childNodes])if(Pt!==C){let zt=n.createElement("div");zt.appendChild(Pt),l(zt,N,m)}continue}if(b.tagName==="DIV"&&!b.hasAttribute("data-page-li")&&[...b.children].some(N=>mt.has(N.tagName))){l(b,h,m);continue}h&&b.setAttribute("data-page-parent",h),m.appendChild(b)}}l(t,null,r);let c=a.length?Math.min(...a.map(u=>+u.dataset.depth)):0,d=null;for(let u of a){let h=+u.dataset.depth-c,m=d&&u.previousElementSibling===d?+d.getAttribute("data-indent")+1:0;u.setAttribute("data-indent",String(Math.min(h,m))),u.removeAttribute("data-depth"),d=u}let f=u=>{if(u.nodeType!==1||u.tagName==="IMG")return[u.cloneNode(!0)];let h=[],m=u.cloneNode(!1);for(let g of u.childNodes)for(let E of f(g))E.nodeType===1&&E.tagName==="IMG"?(m.hasChildNodes()&&h.push(m),h.push(E),m=u.cloneNode(!1)):m.appendChild(E);return(m.hasChildNodes()||!h.length)&&h.push(m),h};for(let u of[...r.children]){if(!u.matches("p, h1, h2, h3, h4, h5, h6, aside, div[data-page-li], div.page-li")||!u.querySelector("img"))continue;let h=f(u),m=u.getAttribute("data-page-parent");if(m)for(let g of h)g.setAttribute("data-page-parent",m);u.replaceWith(...h)}let p=t.querySelector("[data-pm-slice]");return p&&r.firstElementChild?.setAttribute("data-pm-slice",p.dataset.pmSlice),r.innerHTML}var gt=(e,n=0)=>e!==null&&e!==""&&Number.isInteger(+e)&&+e>=n?+e:null,v=e=>e.getAttribute("data-page-parent")||null,tn=Rt([]).type,en=Object.create(T,{marks:{value:{...T.marks,[nt]:tn}}}),ce=e=>{let n;try{n=Qt(e)}catch{return null}return!n||typeof n.t!="string"||n.t==="opaque_block"||Object.hasOwn(Ft,n.t)?null:n},nn=e=>{let n=ce(e);return n?{raw:n,parent:v(e)}:!1},on=e=>{let n=ce(e);if(!n||typeof n.c!="string"||!n.c)return O.Fragment.empty;let t=Ht(n.m,n.c.length);return O.Fragment.from(jt(T,n.c,t,T.nodes.opaque_block))},rn=e=>{try{return{entries:Wt(e.getAttribute(ut))}}catch{return!1}},X=null,sn=()=>import("./c-4OGEVKR3.js").then(e=>{X=e},()=>{}),an=new O.DOMParser(en,[{tag:"table",node:"table",getAttrs:e=>X?.table(e)??!1,getContent:e=>X.rows(e)},{tag:`div[${Ut}]`,node:"opaque_block",getAttrs:nn,getContent:on},{tag:`span[${ut}]`,mark:nt,getAttrs:rn},{tag:"div[data-page-li]",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div.page-li",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div[data-page-toggle]",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-page-toggle"),open:e.getAttribute("data-open")==="true",parent:v(e),level:ft(Number(e.getAttribute("data-level")))})},{tag:"div.page-toggle",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-id"),open:e.getAttribute("data-open")==="true",parent:null,level:ft(Number(e.getAttribute("data-level")))})},{tag:"h1",node:"heading",getAttrs:e=>({level:1,parent:v(e)})},{tag:"h2",node:"heading",getAttrs:e=>({level:2,parent:v(e)})},{tag:"h3",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"h4",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"pre",node:"code_block",preserveWhitespace:"full",getAttrs:e=>({lang:e.getAttribute("data-lang")||"",parent:v(e)})},{tag:"hr",node:"divider",getAttrs:e=>({parent:v(e)})},{tag:"aside.page-callout",node:"callout",getAttrs:e=>({parent:v(e)})},{tag:'figure:not([data-type]), figure[data-type="image"]',node:"image",getAttrs:e=>{let n=e.querySelector("img"),t=et(n?.getAttribute("src"));return t?{src:t,alt:n.getAttribute("alt")||"",caption:e.querySelector("figcaption")?.textContent||"",width:gt(e.getAttribute("data-width")??n.getAttribute("width"),1),align:be(e.getAttribute("data-align")),parent:v(e)}:!1}},{tag:"img[src]",node:"image",getAttrs:e=>{let n=et(e.getAttribute("src"));return n?{src:n,alt:e.getAttribute("alt")||"",width:gt(e.getAttribute("width"),1),parent:v(e)}:!1}},{tag:'div.page-file, div[data-type="file"]',node:"file",getAttrs:e=>{let n=L(e.getAttribute("data-src"));return n?{src:n,name:e.getAttribute("data-name")||"file",size:gt(e.getAttribute("data-size")),mime:e.getAttribute("data-mime")||null,parent:v(e)}:!1}},{tag:"p",node:"paragraph",getAttrs:e=>({parent:v(e)})},{tag:"br",node:"hard_break"},{tag:"strong",mark:"strong"},{tag:"b",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(normal|[1-5]00)\b/.test(e.getAttribute("style")||"")?!1:null},{tag:"span",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(bold|[6-9]00)\b/.test(e.getAttribute("style")||"")?null:!1},{tag:"em",mark:"em"},{tag:"i",mark:"em"},{tag:"span",mark:"em",getAttrs:e=>/font-style\s*:\s*italic/.test(e.getAttribute("style")||"")?null:!1},{tag:"s",mark:"strike"},{tag:"del",mark:"strike"},{tag:"code",mark:"code"},{tag:"a[href]",mark:"link",getAttrs:e=>{let n=L(e.getAttribute("href"));return n?{href:n}:!1}},{tag:"blockquote",node:"quote",getAttrs:e=>({parent:v(e)})},{tag:"u",mark:"underline"},{tag:"mark",mark:"highlight",getAttrs:e=>ct("highlight",{color:e.getAttribute("data-color")})??!1},{tag:"span[data-color]",mark:"text_color",getAttrs:e=>ct("text_color",{color:e.getAttribute("data-color")})??!1}]);function cn(e,n){let t=n.selection.$from,o=n.selection instanceof x,r=o?n.doc.child(n.selection.span().lo):t.depth>=1?t.node(1):null,s=r?k(r):null,a=r&&S(r)?r.attrs.indent:0,i=new Map;e.content.forEach(m=>{A(m)&&m.attrs.id&&i.set(m.attrs.id,V())});let l=[];e.content.forEach(m=>{if(!m.type.spec.group?.includes("block")){l.push(m);return}let g=k(m),E={...m.attrs,pos:null,id:A(m)?i.get(m.attrs.id)??null:null,parent:g!==null&&i.has(g)?i.get(g):s};S(m)&&(E.indent=m.attrs.indent+a),l.push(m.type.create(E,m.content,m.marks))});let c=!r||!(S(r)||A(r)),d=m=>m&&(S(m)||A(m)),f=c&&d(l[0])?0:e.openStart,p=l[l.length-1],u=new Set(i.values()),h=c&&(d(p)||p&&u.has(k(p)))?0:e.openEnd;return new O.Slice(O.Fragment.from(l),o?0:f,o?0:h)}var St=class extends O.DOMSerializer{serializeFragment(n,t,o){let r=super.serializeFragment(n,t,o);if(!n.firstChild?.isBlock)return r;let s=[...r.childNodes];return n.forEach((a,i,l)=>{let c=s[l];!c||c.nodeType!==1||(k(a)!==null&&c.setAttribute("data-page-parent",k(a)),A(a)&&a.attrs.id&&c.setAttribute("data-page-toggle",a.attrs.id),a.type===M.image&&a.attrs.width&&c.setAttribute("data-width",String(a.attrs.width)))}),X?.copy(n,s),r}},le=O.DOMSerializer.fromSchema(T),ln=e=>{let{t:n,...t}=e.attrs.raw??{},{c:o,m:r}=_t(e.content);return o?{t:n,...t,c:o,...r.some(Boolean)?{m:Kt(r)}:{}}:{t:n,...t}},dn=e=>["div",{"data-type":"newer-format",...Gt(ln(e))},0],un=e=>["span",Xt(e.attrs.entries),0],fn={...le.nodes,opaque_block:dn},pn={...le.marks,[nt]:un},hn=new St(fn,pn);function mn(e,n,t){let{$from:o}=e.state.selection,r=o.depth>=1?o.node(1):null;if(!r||!A(r)||r.attrs.open||t.content.childCount<2)return!1;let s=e.state.tr.setNodeMarkup(o.before(1),null,{...r.attrs,open:!0}).replaceSelection(t);return e.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function gn(e){let n=!1;return e?.content?.descendants(t=>n?!1:((t.type===M.quote||t.isText&&t.marks.some(o=>qt.has(o.type.name)))&&(n=!0),!n)),n}function bn(e,n,t){let o=e.state.selection.from,r=e.state.selection.to,s=e.state.doc,a=()=>{let i=t.content.textBetween(0,t.content.size,`
|
|
4
|
+
`," ");return!e.isDestroyed&&i&&e.state.doc===s&&e.dispatch(e.state.tr.insertText(i,o,r)),!1};return import("./c-FNIGX4FI.js").then(({pasteFormats:i})=>i(e,t,o,r),a),!0}function no(){return new wt({view(){return sn(),{}},props:{handlePaste(e,n,t){return gn(t)?bn(e,n,t):mn(e,n,t)},clipboardSerializer:hn,clipboardTextSerializer:e=>X?.text(e),transformPastedHTML:e=>Ze(e),clipboardParser:an,clipboardTextParser:(e,n,t)=>t?null:Qe(e),transformPasted:(e,n)=>cn(e,n.state)}})}var W=tt.chainCommands(Ce,Oe,Be,ze,De),R=tt.chainCommands($e,Le,Pe),oo={Enter:tt.chainCommands(ve,Te,Ne,Ie),Backspace:W,"Shift-Backspace":W,"Mod-Backspace":W,"Alt-Backspace":W,"Ctrl-h":W,Delete:R,"Shift-Delete":R,"Mod-Delete":R,"Alt-Delete":R,"Ctrl-d":R,"Ctrl-Alt-Backspace":R,Tab:Me,"Shift-Tab":vt,"Mod-Shift-ArrowUp":Zt(-1),"Mod-Shift-ArrowDown":Zt(1),"Mod-Enter":Ve};function io(){return new D.Plugin({view(e){let n=e.dom.ownerDocument.createElement("div");return n.className="page-live",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),e.dom.parentElement.appendChild(n),{destroy:()=>n.remove()}}})}function Ct(e,n){let t=e.dom.parentElement?.querySelector(".page-live");t&&(t.textContent="",t.textContent=n)}var de=new D.PluginKey("tableRect");var{Selection:kn,TextSelection:K,NodeSelection:xn,Plugin:yn,PluginKey:An}=D,Q=T.nodes,H=e=>Z.closeHistory(e).setMeta(Et,!0);function Y(e,n,t=n,o=y(e)){let{lo:r,hi:s}=z(o,Math.min(n,t),Math.max(n,t)),a=o[r].at,i=o[s].end;return n<=t?new x(e.resolve(a),e.resolve(i)):new x(e.resolve(i),e.resolve(a))}function Sn(e,n=y(e.doc)){let[t,o]=ne(e.doc,e.selection,n);return z(n,t,o)}var _=(e,n,t)=>{for(let o=n;o>=0&&o<e.length;o+=t)if(!e[o].hidden)return o;return-1};function wn(e,n){if(e.selection instanceof x)return!1;let t=Math.min(e.selection.$head.index(0),e.doc.childCount-1);return n&&n(e.tr.setSelection(Y(e.doc,t))),!0}var ue=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=e<0?_(r,s-1,-1):_(r,a+1,1);return i<0||t&&t(n.tr.setSelection(Y(n.doc,i)).scrollIntoView()),!0};function Dt(e,n,t,o){if(o<0)return n;let r=n;for(;e[r].subEnd<t;)r=e[r].subEnd+1;return r}function En(e,n){for(let t=n-1;t>=0;t--)if(e[t].up===e[n].up)return t;return n}var fe=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=o.anchor<=o.head,l=i?s:Dt(r,s,a,1),c=i?Dt(r,s,a,1):s;return e>0?i||s===a||c===l?c=_(r,(i?a:c)+1,1):c=_(r,r[c].subEnd+1,1):!i||c===l?c=_(r,(i?c:s)-1,-1):c=En(r,c),c<0||t&&t(n.tr.setSelection(Y(n.doc,l,c,r)).scrollIntoView()),!0};function it(e,n){let t=e.selection;if(!(t instanceof x))return!1;if(n){let o=e.tr.delete(t.from,t.to);o.doc.content.size===0&&o.insert(0,Q.paragraph.create()),o.setSelection(kn.near(o.doc.resolve(Math.min(t.from,o.doc.content.size)),-1)),n(H(o).scrollIntoView())}return!0}function Mn({columns:e={},cards:n={}}){let t=dt(e),o=new Map(t.map(a=>[a,V("c")])),r=lt(null,null,t.length),s={};for(let a of new Set([...t,...Object.values(n).map(i=>i.col)])){let i=dt(Object.fromEntries(Object.entries(n).filter(([,c])=>c.col===a))),l=lt(null,null,i.length);i.forEach((c,d)=>{s[V("k")]={...n[c],col:o.get(a)??a,pos:l[d]}})}return{columns:Object.fromEntries(t.map((a,i)=>[o.get(a),{...e[a],pos:r[i]}])),cards:s}}function vn(e,n){let t=y(e.doc);if(!t.length)return!1;let{lo:o,hi:r}=Sn(e,t);if(n){let s=new Map;for(let f=o;f<=r;f++)t[f].node.type===Q.toggle&&t[f].node.attrs.id&&s.set(t[f].node.attrs.id,V());let a=[];for(let f=o;f<=r;f++){let p=t[f].node,u=p.attrs.parent??null;a.push(p.type.create({...p.attrs,...p.type===Q.board?Mn(p.attrs):{},id:s.get(p.attrs.id)??null,pos:null,parent:s.get(u)??u},p.content,p.marks))}let i=t[r].end,l=i-t[o].at,c=e.tr.insert(i,a),d=e.selection;c.setSelection(d instanceof x?new x(c.doc.resolve(i),c.doc.resolve(i+l)):K.create(c.doc,d.anchor+l,d.head+l)),n(H(c).scrollIntoView())}return!0}var he=(e,n,t,o)=>{for(let r=t;r<=o;r++)if(n[r].node.isTextblock)return n[r].end-1;return-1};function pe(e,n){let t=e.selection;if(!(t instanceof x))return!1;let o=y(e.doc),{lo:r,hi:s}=t.span(e.doc);if(n){let a=he(e.doc,o,r,s);n(e.tr.setSelection(a>=0?K.create(e.doc,a):xn.create(e.doc,o[r].at)))}return!0}var Tn=({$from:e,$to:n})=>{if(e.depth<2||n.depth<2)return null;let t=e.node(1);return t.type.name==="table"&&n.node(1)===t?{from:e.before(1),to:e.after(1)}:null};function Nn(e,n){let t=e.selection,{$from:o,$to:r}=t,s=o.parent.isTextblock&&o.sameParent(r)&&!de.getState(e),a=s&&o.parentOffset===0&&r.parentOffset===r.parent.content.size;if(s&&!a&&o.parent.content.size)return n&&n(e.tr.setSelection(K.create(e.doc,o.start(),o.end()))),!0;let i=Tn(t);return i&&!(t instanceof x&&t.from===i.from&&t.to===i.to)?(n&&n(e.tr.setSelection(new x(e.doc.resolve(i.from),e.doc.resolve(i.to)))),!0):(n&&n(e.tr.setSelection(new x(e.doc.resolve(0),e.doc.resolve(e.doc.content.size)))),!0)}var In=(e,n)=>{let t=e.state,o=t.selection;if(!(o instanceof x))return!1;let r=y(t.doc),{lo:s,hi:a}=o.span(t.doc),i=he(t.doc,r,s,a),l=t.tr;if(i<0){let c=r[a].end;l.insert(c,Q.paragraph.create({parent:r[s].node.attrs.parent??null})),l.setSelection(K.create(l.doc,c+1)),H(l)}else l.setSelection(K.create(l.doc,i));return l.insertText(n),e.dispatch(l.scrollIntoView()),!0},Cn=(e,n,t)=>{let o=e.selection;if(!(o instanceof K)||!t?.endOfTextblock("down"))return!1;let{$anchor:r,$head:s}=o;if(r.depth!==1||r.parent.type!==Q.toggle||r.parent.attrs.open||r.index(0)!==s.index(0))return!1;let a=y(e.doc),i=r.index(0),l=_(a,a[i].subEnd+1,1);return l<0?!1:(n&&n(e.tr.setSelection(Y(e.doc,i,l,a)).scrollIntoView()),!0)},On=e=>(n,t,o)=>n.selection instanceof x&&e(n,t,o),Dn={Escape:(e,n)=>pe(e,n)||wn(e,n),Enter:On(pe),ArrowUp:ue(-1),ArrowDown:ue(1),"Shift-ArrowUp":fe(-1),"Shift-ArrowDown":(e,n,t)=>fe(1)(e,n)||Cn(e,n,t),Backspace:it,"Alt-Backspace":it,"Ctrl-h":it,Delete:it,"Mod-d":vn,"Mod-a":Nn},Ot=new An("page-blocksel"),$n=e=>{let n=e.selection,{lo:t,hi:o}=n.span(e.doc);return y(e.doc).filter(r=>r.i>=t&&r.i<=o&&!r.hidden).length};function ko(){let e=Vt.keymap(Dn);return new yn({key:Ot,state:{init:()=>0,apply:(n,t,o,r)=>n.getMeta(ot)&&o.selection instanceof x&&!(r.selection instanceof x)?t+1:t},props:{handleKeyDown:(n,t)=>e.props.handleKeyDown(n,t),handleTextInput:(n,t,o,r)=>In(n,r),decorations(n){let t=n.selection;if(!(t instanceof x))return null;let o=[];return n.doc.nodesBetween(t.from,t.to,(r,s)=>(o.push($.Decoration.node(s,s+r.nodeSize,{class:"page-block-selected"})),!1)),$.DecorationSet.create(n.doc,o)},createSelectionBetween(n,t,o){let r=n.state.selection;return r instanceof x&&t.pos===r.anchor&&o.pos===r.head?r:null},handleDOMEvents:{mousedown(n,t){let o=n.state.selection;if(!t.shiftKey||!(o instanceof x)||t.button!==0)return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});if(!r)return!1;let s=y(n.state.doc),a=Math.min(n.state.doc.resolve(r.inside>=0?r.inside:r.pos).index(0),s.length-1),{lo:i,hi:l}=o.span(n.state.doc),c=o.anchor<=o.head?i:Dt(s,i,l,1);return t.preventDefault(),n.dispatch(n.state.tr.setSelection(Y(n.state.doc,c,a,s))),!0}}},view:()=>({update(n,t){let o=n.state.selection,r=t.selection;if(o instanceof x&&!o.eq(r)){let s=$n(n.state);Ct(n,`${s} ${s===1?"block":"blocks"} selected`)}else r instanceof x&&!(o instanceof x)&&Ct(n,Ot.getState(n.state)!==Ot.getState(t)?"Block selection cleared because the document changed":"Selection cleared")}})})}var{Plugin:Ln,PluginKey:Bn,TextSelection:J}=D,{Decoration:Pn,DecorationSet:zn}=$,U=T.marks.link,Vn=e=>/^(https?:\/\/|mailto:|tel:|www\.)\S+$/i.test(e.trim())&&L(e)!==null;function $t(e,n){let t=e.resolve(n);if(!t.parent.inlineContent)return null;let o=U.isInSet((t.nodeAfter??t.nodeBefore)?.marks??[]);if(!o)return null;let r=[];t.parent.forEach((c,d)=>r.push({n:c,off:d}));let s=r.findIndex(({n:c,off:d})=>d<=t.parentOffset&&t.parentOffset<=d+c.nodeSize&&o.isInSet(c.marks));if(s<0)return null;let a=s,i=s;for(;a>0&&o.isInSet(r[a-1].n.marks);)a--;for(;i<r.length-1&&o.isInSet(r[i+1].n.marks);)i++;let l=t.start();return{from:l+r[a].off,to:l+r[i].off+r[i].n.nodeSize,href:o.attrs.href}}function me(e,n,t,o){let r=e.tr.removeMark(n,t,U);return o&&r.addMark(n,t,U.create({href:o})),H(r)}var B=new Bn("page-link"),Lt=new WeakMap,ge=e=>`<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">${e}</svg>`,Rn=ge('<path d="M9 3h4v4M13 3 7.5 8.5M11 9.5V13H3V5h3.5"/>'),qn=ge('<path d="M4 4l8 8M12 4l-8 8"/>');function j(e,n,t,o={}){let r=e.createElement(n);t&&(r.className=t);for(let[s,a]of Object.entries(o))r.setAttribute(s,a);return r}function _n(e,n,t){let o=null;return e.doc.nodesBetween(n,t,r=>{let s=U.isInSet(r.marks);s&&(o=s.attrs.href)}),o}var Bt=class{constructor(n){this.view=n,this.shell=n.dom.parentElement,this.doc=n.dom.ownerDocument,this.mode=null,this.range=null;let t=this.doc;this.dom=j(t,"div","page-link",{role:"dialog","aria-label":"Link",hidden:""}),this.input=j(t,"input","page-link-input",{type:"url","aria-label":"Link address",placeholder:"Paste or type a link",autocomplete:"off",spellcheck:"false"}),this.url=j(t,"a","page-link-url",{target:"_blank",rel:"noopener noreferrer"}),this.open=j(t,"a","page-link-btn",{"data-act":"open",target:"_blank",rel:"noopener noreferrer","aria-label":"Open link in a new tab",title:"Open in a new tab"}),this.open.innerHTML=Rn,this.edit=j(t,"button","page-link-btn",{type:"button","data-act":"edit"}),this.edit.textContent="Edit",this.remove=j(t,"button","page-link-btn",{type:"button","data-act":"remove","aria-label":"Remove link",title:"Remove link"}),this.remove.innerHTML=qn,this.dom.append(this.input,this.url,this.open,this.edit,this.remove),this.shell.append(this.dom),Lt.set(n,this),this.dom.addEventListener("mousedown",o=>{o.target!==this.input&&o.preventDefault()}),this.edit.addEventListener("click",()=>this.openEdit()),this.remove.addEventListener("click",()=>this.apply("")),this.input.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||(o.key==="Enter"?(o.preventDefault(),this.apply(this.input.value)):o.key==="Escape"&&(o.preventDefault(),this.close()))}),this.onDocDown=o=>{this.mode==="edit"&&!this.dom.contains(o.target)&&this.close(!1)},this.doc.addEventListener("mousedown",this.onDocDown,!0)}openEdit(){let n=this.view.state,t=n.selection;if(!(t instanceof J)||!t.$from.sameParent(t.$to)||!t.$from.parent.inlineContent||t.$from.parent.type.spec.code)return!1;let o=t.empty?$t(n.doc,t.head):null;return this.range=o??{from:t.from,to:t.to,href:t.empty?null:_n(n,t.from,t.to)},this.mode="edit",this.view.dispatch(n.tr.setMeta(B,{from:this.range.from,to:this.range.to})),this.render(),this.input.value=this.range.href??"",this.input.removeAttribute("aria-invalid"),this.input.focus(),this.input.select(),!0}apply(n){let t=String(n).trim(),o=t?L(t):null;if(t&&!o){this.input.setAttribute("aria-invalid","true");return}let r=this.view.state,s=B.getState(r)??(this.mode==="view"?this.range:null);if(!s)return this.close();let a;if(s.from===s.to){if(!o)return this.close();a=r.tr.insert(s.from,T.text(t,[U.create({href:o})])),a.setSelection(J.create(a.doc,s.from+t.length))}else a=me(r,s.from,s.to,o),a.setSelection(J.create(a.doc,s.to));this.view.dispatch(H(a).setMeta(B,null)),this.close()}close(n=!0){this.mode=null,this.range=null,B.getState(this.view.state)&&this.view.dispatch(this.view.state.tr.setMeta(B,null)),this.dom.hidden=!0,this.dom.dataset.mode="",n&&this.view.focus(),this.update(this.view)}render(){let n=this.mode==="edit",t=L(this.range?.href);this.dom.dataset.mode=this.mode??"",this.input.hidden=!n,this.url.hidden=n,this.edit.hidden=n,this.open.hidden=!t,this.remove.hidden=!this.range?.href,t?(this.open.href=t,this.url.href=t,this.url.textContent=t.replace(/^https?:\/\//,"")):(this.open.removeAttribute("href"),this.url.removeAttribute("href"),this.url.textContent=""),this.dom.hidden=!1,this.place()}place(){let n=this.range;if(!n)return;let t=this.shell.getBoundingClientRect(),o=this.view.coordsAtPos(n.from),r=this.view.coordsAtPos(n.to,-1);this.dom.style.setProperty("--page-pop-x",`${Math.min(o.left,r.left)-t.left}px`),this.dom.style.setProperty("--page-pop-y",`${Math.max(o.bottom,r.bottom)-t.top+6}px`)}update(n){if(this.view=n,this.mode==="edit"){let r=B.getState(n.state);if(r)return this.range={...this.range,...r},this.place();this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}let t=n.state.selection,o=t instanceof J&&t.empty&&n.hasFocus()?$t(n.state.doc,t.head):null;if(!o||t.head===o.from||t.head===o.to){this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}this.mode="view",this.range=o,this.render()}destroy(){this.doc.removeEventListener("mousedown",this.onDocDown,!0),this.dom.remove(),Lt.delete(this.view)}},Kn=e=>Lt.get(e)?.openEdit()??!1;function Hn(e,n){if(n.clipboardData?.files?.length)return!1;let t=n.clipboardData?.getData("text/plain")??"";if(!Vn(t))return!1;let o=e.state.selection;if(!(o instanceof J)||!o.$from.sameParent(o.$to)||o.$from.parent.type.spec.code)return!1;let r=L(t),s=o.empty?e.state.tr.replaceSelectionWith(T.text(t.trim(),[U.create({href:r})]),!1):me(e.state,o.from,o.to,r);return e.dispatch(s.scrollIntoView().setMeta("uiEvent","paste")),!0}function Eo(){return new Ln({key:B,state:{init:()=>null,apply(e,n){let t=e.getMeta(B);if(t!==void 0)return t;if(!n||!e.docChanged)return n;let o=e.mapping.mapResult(n.from,1),r=e.mapping.mapResult(n.to,n.from===n.to?1:-1);return o.deletedAcross||r.deletedAcross||n.from!==n.to&&o.pos>=r.pos?null:{from:o.pos,to:r.pos}}},view:e=>new Bt(e),props:{decorations(e){let n=B.getState(e);return n&&n.from<n.to?zn.create(e.doc,[Pn.inline(n.from,n.to,{class:"page-link-pending"})]):null},handleKeyDown(e,n){return(n.metaKey||n.ctrlKey)&&!n.altKey&&!n.shiftKey&&n.key.toLowerCase()==="k"?(n.preventDefault(),Kn(e)||!0):!1},handlePaste:Hn,handleClick(e,n,t){if(!(t.metaKey||t.ctrlKey))return!1;let o=$t(e.state.doc,n),r=L(o?.href);return r?(e.dom.ownerDocument.defaultView.open(r,"_blank","noopener,noreferrer"),!0):!1}}})}export{Kn as a,Eo as b,io as c,Ct as d,de as e,Et as f,q as g,y as h,Jn as i,xe as j,Zn as k,z as l,Ae as m,Se as n,x as o,G as p,re as q,Zt as r,Ee as s,Me as t,vt as u,to as v,eo as w,an as x,hn as y,no as z,oo as A,H as B,Y as C,Sn as D,it as E,vn as F,In as G,ko as H};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as u}from"./c-VJYEVRYK.js";import{B as M}from"./c-
|
|
1
|
+
import{a as u}from"./c-VJYEVRYK.js";import{B as M}from"./c-TMT5TL65.js";import{b,d as x,m as v}from"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var{Plugin:R}=b,{Decoration:D}=x;var O=[["","Plain text"],["javascript","JavaScript"],["typescript","TypeScript"],["jsx","JSX"],["tsx","TSX"],["json","JSON"],["html","HTML"],["css","CSS"],["python","Python"],["shellscript","Shell"],["sql","SQL"],["go","Go"],["rust","Rust"],["java","Java"],["c","C"],["cpp","C++"],["csharp","C#"],["ruby","Ruby"],["php","PHP"],["yaml","YAML"],["markdown","Markdown"],["diff","Diff"],["swift","Swift"],["kotlin","Kotlin"],["xml","XML"]],L=new Set(O.map(([s])=>s)),T={js:"javascript",mjs:"javascript",ts:"typescript",py:"python",sh:"shellscript",bash:"shellscript",shell:"shellscript",zsh:"shellscript",rb:"ruby",yml:"yaml",md:"markdown",htm:"html",golang:"go",rs:"rust","c++":"cpp",cs:"csharp","c#":"csharp",kt:"kotlin"},m=s=>{let t=String(s??"").trim().toLowerCase(),e=T[t]??t;return L.has(e)?e:""},n=s=>({color:s}),C={name:"page",appearance:"light",cssVariables:{prefix:"--page-code-token-"},style:{syntax:{comment:n("comment"),keyword:n("keyword"),operator:n("keyword"),preproc:n("keyword"),"punctuation.special":n("keyword"),string:n("string-expression"),"string.escape":n("constant"),"string.regex":n("constant"),"string.special":n("constant"),number:n("constant"),boolean:n("constant"),constant:n("constant"),type:n("constant"),property:n("constant"),enum:n("constant"),variant:n("constant"),namespace:n("constant"),label:n("constant"),function:n("function"),constructor:n("function"),selector:n("function"),attribute:n("function"),"variable.parameter":n("parameter"),tag:n("string-expression"),link_uri:n("link"),link_text:n("link"),"diff.plus":n("string-expression"),"diff.minus":n("keyword"),title:{font_weight:700},emphasis:{font_style:"italic"},"emphasis.strong":{font_weight:700}}}},E=null;async function P(s,t){E??=import("./c-3OWDMNJR.js");let{codeToTokens:e}=await E;return e(s,{lang:t,theme:C}).tokens}var _="var(--page-code-token-foreground)",A=s=>{let t=[];return s.color&&s.color!==_&&t.push(`color: ${s.color}`),s.fontStyle&1&&t.push("font-style: italic"),s.fontStyle&2&&t.push("font-weight: 600"),s.fontStyle&4&&t.push("text-decoration: underline"),t.join("; ")},H=200,y=class{constructor(t,e,i){this.view=t,this.run=e,this.delay=i,this.cache=new Map,this.pending=new Set,this.visible=new Set,this.targets=new Map,this.timer=0;let c=t.dom.ownerDocument.defaultView.IntersectionObserver;this.io=c?new c(a=>{for(let o of a){let r=o.target.dataset.id;this.targets.get(r)===o.target&&this.visible[o.isIntersecting?"add":"delete"](r)}this.schedule(0)},{rootMargin:"200px 0px"}):null,this.schedule(0)}update(t,e){(!e||t.state.doc!==e.doc)&&this.schedule(this.delay)}schedule(t){clearTimeout(this.timer),this.timer=setTimeout(()=>this.pass(),t)}pass(){let{view:t}=this;if(t.isDestroyed)return;let e=[],i=new Map,c=u.getState(t.state);t.state.doc.forEach((o,r)=>{if(o.type!==v.nodes.code_block)return;let p=o.attrs.id,d=t.nodeDOM(r);d&&i.set(p,d);let g=m(o.attrs.lang);if(!g)return;let k=o.textContent,l=`${g}
|
|
2
2
|
${k}`,w=this.cache.get(l);if(w)for(let h of w){let S=A(h);S&&h.content&&e.push(D.inline(r+1+h.offset,r+1+h.offset+h.content.length,{style:S}))}else{if(e.push(...c.find(r,r+o.nodeSize)),this.io&&!this.visible.has(p)||this.pending.has(l))return;this.pending.add(l),this.run(k,g).then(h=>h.flat(),()=>[]).then(h=>{this.pending.delete(l),this.cache.set(l,h),this.cache.size>H&&this.cache.delete(this.cache.keys().next().value),this.schedule(0)})}}),this.track(i);let a=o=>o.map(r=>`${r.from}:${r.to}:${r.type.attrs.style}`).join("|");a(e)!==a(u.getState(t.state).find())&&t.dispatch(t.state.tr.setMeta(u,e).setMeta("addToHistory",!1))}track(t){if(this.io){for(let[e,i]of this.targets)t.get(e)!==i&&(this.io.unobserve(i),this.targets.delete(e),this.visible.delete(e));for(let[e,i]of t)this.targets.get(e)!==i&&(this.targets.set(e,i),this.io.observe(i))}}destroy(){clearTimeout(this.timer),this.io?.disconnect()}};function j(s,{tokenize:t=P,delay:e=300}={}){let i=new y(s,t,e),c=s.dispatch.bind(s),a=s.state.doc,o=p=>{if(c(p),s.state.doc===a)return;let d={doc:a};a=s.state.doc,i.update(s,d)};s.dispatch=o;let r=i.destroy.bind(i);return i.destroy=()=>{s.dispatch===o&&(s.dispatch=c),r()},i}var f=class{constructor(t,e,i){this.node=t,this.view=e,this.getPos=i;let c=e.dom.ownerDocument;this.dom=c.createElement("pre"),this.contentDOM=c.createElement("code"),this.select=c.createElement("select"),this.select.className="page-code-lang",this.select.contentEditable="false",this.select.setAttribute("aria-label","Code language");for(let[a,o]of O)this.select.append(new Option(o,a));this.select.addEventListener("change",()=>this.setLang(this.select.value)),this.dom.append(this.select,this.contentDOM),this.render(t)}render(t){this.node=t,this.dom.dataset.id=t.attrs.id??"";let e=m(t.attrs.lang);e?this.dom.dataset.lang=e:delete this.dom.dataset.lang,this.select.value=e}setLang(t){let e=this.getPos();e==null||t===m(this.node.attrs.lang)||(this.view.dispatch(M(this.view.state.tr.setNodeMarkup(e,null,{...this.node.attrs,lang:t}))),this.view.focus())}update(t){return t.type!==this.node.type?!1:(this.render(t),!0)}stopEvent(t){return this.select.contains(t.target)}ignoreMutation(t){return t.type!=="selection"&&this.select.contains(t.target)}};function X({view:s=null,highlight:t={}}={}){let e=s?j(s,t):null;return{id:"code",nodeViews:{code_block:(i,c,a)=>new f(i,c,a)},css:null,dispose(){e?.destroy()}}}export{X as createFeature};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as g}from"./c-
|
|
1
|
+
import{B as g}from"./c-TMT5TL65.js";import"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var p=(t,r)=>{let s=-1;return t.forEach((n,l,c)=>{n.attrs.id===r&&(s=c)}),s};function y(t,r,s){let n=t.state,l=p(n.doc,r);if(l<0)return!1;let c=0;for(let e=0;e<l;e++)c+=n.doc.child(e).nodeSize;let a=n.doc.child(l);return t.dispatch(g(n.tr.setNodeMarkup(c,null,{...a.attrs,...s}))),!0}function b(t,r){let s=p(t.state.doc,r);if(s<0)return!1;let n=t.dom.parentElement,l=n.ownerDocument,c=0;for(let o=0;o<s;o++)c+=t.state.doc.child(o).nodeSize;let a=l.createElement("div");a.className="page-link",a.dataset.mode="alt";let e=l.createElement("input");e.className="page-link-input",e.type="text",e.value=t.state.doc.child(s).attrs.alt||"",e.placeholder="Describe the image",e.setAttribute("aria-label","Alt text"),a.append(e);let d=t.nodeDOM(c)?.getBoundingClientRect?.(),u=n.getBoundingClientRect();d&&(a.style.setProperty("--page-pop-x",`${d.left-u.left}px`),a.style.setProperty("--page-pop-y",`${d.bottom-u.top+6}px`)),n.append(a);let f=!1,i=(o,h=!0)=>{if(f)return;f=!0;let m=e.value.trim();a.remove();let x=p(t.state.doc,r);o&&x>=0&&m!==t.state.doc.child(x).attrs.alt&&y(t,r,{alt:m}),h&&t.focus()};return e.addEventListener("keydown",o=>{o.key==="Enter"?(o.preventDefault(),i(!0)):o.key==="Escape"&&(o.preventDefault(),o.stopPropagation(),i(!1))}),e.addEventListener("blur",()=>i(!0,!1)),e.focus(),!0}export{b as openAltEditor,y as setImageAttrs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as $}from"./c-R2XUODVY.js";import{a as k,b as B,c as L}from"./c-GBKB5WDL.js";import{B as M}from"./c-
|
|
1
|
+
import{b as $}from"./c-R2XUODVY.js";import{a as k,b as B,c as L}from"./c-GBKB5WDL.js";import{B as M}from"./c-TMT5TL65.js";import{G as P,J as R,b as O,m as q}from"./c-QIXT3Q7C.js";import"./c-3GJ4SDE2.js";import{a as N}from"./c-3LDGIBMN.js";import"./c-VHNSBD2M.js";var K=16384,G=p=>new TextEncoder().encode(JSON.stringify(p)).length,I=class extends Error{constructor(s,n=s){super(n),this.name="ToolRequestError",this.code=s}};function V(p){let s=N(p);for(Array.isArray(s.tables)||(s.tables=[]),Array.isArray(s.outline)||(s.outline=[]);G(s)>K;){let n=[...s.tables].reverse().find(i=>Array.isArray(i.rows)&&i.rows.length);if(n)n.rows.pop();else if(s.outline.length)s.outline.pop();else break}if(G(s)>K)throw new I("context-too-large");return s}function J({transport:p,newId:s}){let n=null,i=a=>{!a||a.discarded||a.done||(a.discarded=!0,n===a&&(n=null),p.cancel(a.requestId),a.resolve({requestId:a.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(a,r,t=null){let m=V(r);n&&i(n);let c=s(),l={requestId:c,discarded:!1,done:!1};l.promise=new Promise(o=>{l.resolve=o}),n=l;let y={protocol:"page-tool/1",requestId:c,prompt:a,context:m,target:t};l.request=y;let v=o=>{if(!(l.discarded||l.done||o?.requestId!==c))if(l.done=!0,n===l&&(n=null),o?.artifact!==void 0){let d=k(o.artifact),C=B(o.state),w=d.ok?C.ok?null:C:d;l.resolve(w?{requestId:c,code:w.code,message:w.code}:o)}else l.resolve(typeof o?.code=="string"?o:{requestId:c,code:"invalid-result",message:"invalid-result"})};try{Promise.resolve(p.request(y)).then(v,o=>v({requestId:c,code:"transport-error",message:String(o?.message??o)}))}catch(o){v({requestId:c,code:"transport-error",message:String(o?.message??o)})}return l},discard:i,async wait(a,{signal:r}={}){if(r?.aborted)throw new DOMException("Aborted","AbortError");let t,m=await(r?Promise.race([a.promise,new Promise((c,l)=>{t=()=>l(new DOMException("Aborted","AbortError")),r.addEventListener("abort",t,{once:!0})})]).finally(()=>r.removeEventListener("abort",t)):a.promise);if(m?.code)throw new I(m.code,m.message);return m}}}var{Selection:X}=O;function W(p,s){let n=null;return p.forEach((i,a,r)=>{i.attrs.id===s&&(n={node:i,at:a,index:r})}),n}function j(p,s,n){let i=p.state,a=W(i.doc,n?.hostId)??(()=>{let w=Math.min(i.selection.$head.index(0),i.doc.childCount-1),f=0;for(let g=0;g<w;g++)f+=i.doc.child(g).nodeSize;return{node:i.doc.child(w),at:f,index:w}})(),{node:r,at:t,index:m}=a,c=i.doc.maybeChild(m+1),l=r.isTextblock&&(r.content.size===0||n?.hostId===r.attrs.id&&r.textContent===n.slashText),y=l?r.attrs.pos:P(r.attrs.pos,c?.attrs.pos??null),v=q.nodes.tool.create({id:s.id,pos:y,parent:r.attrs.parent??null,artifact:s.artifact,rev:s.rev,state:s.state}),o=l?t:t+r.nodeSize,d=i.tr;if(!l&&n?.hostId===r.attrs.id&&n.slashText&&n.slashOffset>=0){let w=t+1+n.slashOffset,f=w+n.slashText.length;f<=t+r.nodeSize-1&&i.doc.textBetween(w,f)===n.slashText&&d.delete(w,f)}let C=d.mapping.map(o);d.replaceWith(C,l?d.mapping.map(t+r.nodeSize):C,v),d.setSelection(X.near(d.doc.resolve(Math.min(C+v.nodeSize,d.doc.content.size)))),p.dispatch(M(d).scrollIntoView())}function ie({getView:p,store:s,transport:n,acceptState:i=()=>globalThis.clay?.save?.flush?.(),newId:a=R}){let r=n?J({transport:n,newId:()=>a("request")}):null,t=null,m=0,c=()=>{m++,t&&(r?.discard(t.pending),t.preview?.dispose(),t.previewHost?.dispose(),t.element.remove(),t=null)};return{open:({target:y=null,remove:v=null}={})=>{c();let o=p();if(!o)return;let d=o.state.selection,w={hostId:o.state.doc.child(Math.min(d.$head.index(0),o.state.doc.childCount-1))?.attrs.id,slashText:v?o.state.doc.textBetween(v.from,v.to):null,slashOffset:v&&d.$head.depth?v.from-d.$head.before(1)-1:null},f=o.dom.ownerDocument,g=f.createElement("section");g.className="page-ai-panel",g.contentEditable="false",g.setAttribute("role","dialog"),g.setAttribute("aria-label",y?"Revise tool":"Make a tool with AI");let E=f.createElement("textarea");E.setAttribute("aria-label","Describe the tool"),E.placeholder=y?"What should change?":"Describe the tool you want";let A=f.createElement("p");A.className="page-ai-status";let S=f.createElement("div");S.className="page-ai-preview";let T=f.createElement("div");T.className="page-ai-actions",g.append(E,A,S,T),o.dom.parentElement.append(g),t={element:g,input:E,status:A,previewRoot:S,actions:T,target:y,bookmark:w,candidate:null,pending:null,preview:null,previewHost:null,kept:!1,busy:!1};let x=(e,u)=>{let h=f.createElement("button");h.type="button",h.textContent=e,h.addEventListener("click",u),T.append(h)},z=()=>{t&&(t.preview?.dispose(),t.previewHost?.dispose(),t.preview=null,t.previewHost=null,t.previewRoot.replaceChildren(),t.input.hidden=!1,t.actions.replaceChildren(),x("Generate",D),x("Cancel",c),t.input.focus())},_=()=>{let e=t;e.input.hidden=!0,e.status.textContent="",e.previewHost=L({mode:"view"}),e.preview=e.previewHost.mount(e.previewRoot,{id:"preview",rev:"preview",artifact:e.candidate.artifact,seed:e.candidate.state}),e.actions.replaceChildren(),x("Keep",H),x("Revise",z),x("Discard",c)},D=async()=>{let e=t;if(!e||e.busy||!e.input.value.trim())return;if(!r){e.status.textContent="Tool generation is unavailable";return}e.busy=!0,e.status.textContent="Making your tool\u2026",e.actions.replaceChildren(),x("Cancel",c);let u=++m,h=r.request(e.input.value.trim(),$(o.state.doc,f.title),e.target);e.pending=h;try{let b=await r.wait(h);if(t!==e||u!==m)return;e.candidate={artifact:b.artifact,state:b.state,id:null,rev:null},_()}catch(b){if(t!==e||u!==m)return;e.status.textContent=b.message,e.actions.replaceChildren(),x("Generate",D),x("Cancel",c)}finally{e.busy=!1}},H=async()=>{let e=t;if(!e?.candidate||e.busy||e.kept)return;e.busy=!0;let u=e.candidate;u.id??=e.target?.toolId??a("b"),u.rev??=a("rev");try{if(!s)throw new Error("This document can't save tool state");await s.set([u.id,u.rev],u.state);let h=await i();if(h?.ok!==!0&&!["saved","clean"].includes(h?.state))throw new Error(h?.msg??h?.message??"Tool state was not saved");if(t!==e||e.kept)return;if(e.target){let b=W(o.state.doc,e.target.toolId);if(b?.node.type!==q.nodes.tool||b.node.attrs.rev!==e.target.rev){e.status.textContent="This tool changed while you were revising. Keep as a new tool, or discard.",e.target=null,u.id=null,u.rev=null,e.actions.replaceChildren(),x("Keep as new tool",H),x("Discard",c);return}o.dispatch(M(o.state.tr.setNodeMarkup(b.at,null,{...b.node.attrs,artifact:u.artifact,rev:u.rev})))}else j(o,u,e.bookmark);e.kept=!0,c()}catch(h){t===e&&(e.status.textContent=h.message)}finally{e.busy=!1}};return z(),g},dispose:c}}export{ie as createAiTool};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Ot,c as Tt,d as Rt,e as Pt,f as be,g as $t}from"./c-JKZJIUIP.js";import{a as Z}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Ct,g as ze,h as Mt,i as K,j as Ae,k as R,l as Lt,m as _t,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as qt}from"./c-57XDY6HC.js";import{e as Et}from"./c-LZJPNR2W.js";import{E as Je,J as Ue,f as xt,q as Ie}from"./c-NLZ5AN4L.js";import{a as We}from"./c-I2SCCUEW.js";import{e as De,f as He,j as bt,k as kt,l as At,x as St}from"./c-GVPNDIKJ.js";import{a as yt}from"./c-ATKAOH23.js";import{a as Ne}from"./c-EK63G3CG.js";import{a as je,c as wt}from"./c-NQJRVJ56.js";import{e as we,k as vt}from"./c-XGH4GS2T.js";import{f as Q}from"./c-3O7OBDCM.js";import{f as mt,k as gt}from"./c-EGTIAL6P.js";var mn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),gn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",ee=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),yn=(e,t)=>R(e)===R(t);function jt(e,t){let r=[];try{for(let o of t){let n=Ct(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function vn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&K(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>K(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(K(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&K(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&K(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function wn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:V=null,room:L=null,cause:ce=null}={}){if(!U(l)||ee(l)!==ee(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${ee(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:V,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),Lt(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&ee(f.value)!==ee(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${ee(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)wn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&mn.has(f))return(...S)=>{let $=T(u),V=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),V===$?B(u,l):V};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!gn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),X,Me=new Promise(l=>{X=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Mt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return X(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=jt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:V=null}={}){let L=jt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>yn(k,i[D].op)),ye=a&&!_&&me===0?vn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:V});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),hn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:hn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let fn=null,_e=()=>fn??=ie(L),dn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),pn=k=>{if(dn)return J(_e(),k);for(let D of L)if(K(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:V,get prev(){return _e()},before:pn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Nt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var te=[0,1e4,3e4],bn=6e3,kn=2;async function An(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function Sn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=kn)break}return t}function xn(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Dt({query:e,digest:t=An,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=Sn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(bn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||xn(g,y,I)&&ae(y,I)}function X(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<te.length;f+=1)te[f]<=l&&(u=f);if(u<0){for(let f=0;f<te.length;f+=1)B(X,h+te[f]-r());return}X();for(let f=u+1;f<te.length;f+=1)B(X,h+te[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var En="/_/sync/data";function Wt(){return new URL(En,window.location.origin)}async function On(e,t){let r=Wt();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Tn(e,t=null,{signal:r}={}){let o=Wt();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function It(){return{start(e){return Et({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:On,fetchState:Tn}}var Pn=()=>Promise.all([import("./c-NWX3MFT4.js"),import("./c-HG2C77BM.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),$n=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Kt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Cn=0,Mn=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Qn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Rt(o),ancestors:Pt(o)}}function Ln(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Ot(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Kt,Qe+1]},d=$t(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var z=new Map,F=null,q=null,H=null,_n=Dt({query:e=>vt?.(e)??null}),j=new Map;function Gt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Xt=(e,t)=>F===null||!He()?!1:z.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Xt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Jt=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Xt(e.store.name,t));function qn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Mn)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,en(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(qn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Gt(e);let t=e.store.name;if(e.recovery&&!Nn(e)&&en(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function jn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Qt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Nn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Dn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Hn(e,t){Zt(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,Zt(e))}function Zt(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function en(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function tn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function Wn(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ut(n);a.run=_n.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>In(n,c,d),onUnknown:({reason:c})=>Jn(n,c)})}},()=>{e.html=null,Ut(n)})}function In(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Hn(s,o.deadline)}}}function Ut(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Jn(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Un(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(Z(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Fn(){if(!Q||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function nn(){for(let e of[...et])e()}var M=Nt({needsSave:Fn,blocked:()=>!he()||!Ue()||Ie()||xt()||Qt(),save:()=>Je().finally(nn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function rn(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function on({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();rn();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:rn,flush:on});function Yn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function Bn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,ne=null,G=null,e?.stop()}function Pr(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Yt(P,{adopted:!0});sn();let t={admitted:!1,wantsLane:!0};return P=t,Yn(),Pe(),Yt(t)}}}function Ft(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Yt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Ft())},quiesce(){if(P===e)return e.admitted=!1,on()},resume(){P===e&&(e.admitted=!0,Ft())},dispose(){P===e&&(P=null,Bn())}}}var Te=null,ut=null,ne=null,G=null;function sn(){Te=new Promise(e=>{ne=e}),ut=new Promise(e=>{G=e})}function ft(){return Te||sn(),{laneReady:Te,writerReady:ut}}function $r(){return ft().laneReady}function Cr(){return ft().writerReady}function Bt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Un(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=z.get(e);return z.delete(e),F===e&&(F=null),q===e&&(q=null),t}function an(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function zn(e,t){let r=e?.code,o=r==="page-converting"||r==="page-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function zt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&G?.(p)},onApplied:Bt,onLanded:()=>{Bt(),nn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Jt(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:jn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Jt(t)||re(t,{read:!1}))}}}function Vn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=Z(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Q))return;tt=!0;let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await Pn().catch(()=>null);if(e===xe){if(!o){ne?.(null),G?.(null);return}if(t)p=o.createFastLane(zt(It()));else if(o.localLaneSupported())W=o.localTransport({seed:Vn,rooms:!0,floor:document.querySelector('meta[name="clay-page-format"]')?.getAttribute("content")}),p=o.createFastLane(zt(W));else{ne?.(null),G?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{cn(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),ne?.(p),p.status.writer!==null&&G?.(p)}}).catch(()=>{ne?.(null),G?.(null)})}function Kn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Kn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if($n.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Gn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^page(\.[0-9]+)?$/.test(e.store.name)?qt(r):r;return e.layout==="lines"?Xn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Vt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Xn(e){return Vt(e)?`{${Object.entries(e).map(([r,o])=>!Vt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
|
|
1
|
+
import{a as Ot,c as Tt,d as Rt,e as Pt,f as be,g as $t}from"./c-JKZJIUIP.js";import{a as Z}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Ct,g as ze,h as Mt,i as K,j as Ae,k as R,l as Lt,m as _t,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as qt}from"./c-57XDY6HC.js";import{e as Et}from"./c-LZJPNR2W.js";import{E as Je,J as Ue,f as xt,q as Ie}from"./c-DKFSOJCV.js";import{a as We}from"./c-I2SCCUEW.js";import{e as De,f as He,j as bt,k as kt,l as At,x as St}from"./c-ZKELCT4T.js";import{a as yt}from"./c-ATKAOH23.js";import{a as Ne}from"./c-EK63G3CG.js";import{a as je,c as wt}from"./c-NQJRVJ56.js";import{e as we,k as vt}from"./c-XGH4GS2T.js";import{f as Q}from"./c-3O7OBDCM.js";import{f as mt,k as gt}from"./c-EGTIAL6P.js";var mn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),gn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",ee=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),yn=(e,t)=>R(e)===R(t);function jt(e,t){let r=[];try{for(let o of t){let n=Ct(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function vn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&K(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>K(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(K(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&K(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&K(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function wn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:V=null,room:L=null,cause:ce=null}={}){if(!U(l)||ee(l)!==ee(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${ee(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:V,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),Lt(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&ee(f.value)!==ee(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${ee(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)wn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&mn.has(f))return(...S)=>{let $=T(u),V=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),V===$?B(u,l):V};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!gn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),X,Me=new Promise(l=>{X=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Mt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return X(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=jt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:V=null}={}){let L=jt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>yn(k,i[D].op)),ye=a&&!_&&me===0?vn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:V});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),hn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:hn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let fn=null,_e=()=>fn??=ie(L),dn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),pn=k=>{if(dn)return J(_e(),k);for(let D of L)if(K(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:V,get prev(){return _e()},before:pn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Nt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var te=[0,1e4,3e4],bn=6e3,kn=2;async function An(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function Sn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=kn)break}return t}function xn(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Dt({query:e,digest:t=An,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=Sn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(bn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||xn(g,y,I)&&ae(y,I)}function X(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<te.length;f+=1)te[f]<=l&&(u=f);if(u<0){for(let f=0;f<te.length;f+=1)B(X,h+te[f]-r());return}X();for(let f=u+1;f<te.length;f+=1)B(X,h+te[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var En="/_/sync/data";function Wt(){return new URL(En,window.location.origin)}async function On(e,t){let r=Wt();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Tn(e,t=null,{signal:r}={}){let o=Wt();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function It(){return{start(e){return Et({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:On,fetchState:Tn}}var Pn=()=>Promise.all([import("./c-NWX3MFT4.js"),import("./c-HG2C77BM.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),$n=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Kt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Cn=0,Mn=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Qn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Rt(o),ancestors:Pt(o)}}function Ln(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Ot(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Kt,Qe+1]},d=$t(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var z=new Map,F=null,q=null,H=null,_n=Dt({query:e=>vt?.(e)??null}),j=new Map;function Gt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Xt=(e,t)=>F===null||!He()?!1:z.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Xt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Jt=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Xt(e.store.name,t));function qn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Mn)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,en(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(qn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Gt(e);let t=e.store.name;if(e.recovery&&!Nn(e)&&en(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function jn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Qt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Nn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Dn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Hn(e,t){Zt(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,Zt(e))}function Zt(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function en(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function tn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function Wn(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ut(n);a.run=_n.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>In(n,c,d),onUnknown:({reason:c})=>Jn(n,c)})}},()=>{e.html=null,Ut(n)})}function In(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Hn(s,o.deadline)}}}function Ut(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Jn(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Un(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(Z(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Fn(){if(!Q||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function nn(){for(let e of[...et])e()}var M=Nt({needsSave:Fn,blocked:()=>!he()||!Ue()||Ie()||xt()||Qt(),save:()=>Je().finally(nn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function rn(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function on({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();rn();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:rn,flush:on});function Yn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function Bn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,ne=null,G=null,e?.stop()}function Pr(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Yt(P,{adopted:!0});sn();let t={admitted:!1,wantsLane:!0};return P=t,Yn(),Pe(),Yt(t)}}}function Ft(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Yt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Ft())},quiesce(){if(P===e)return e.admitted=!1,on()},resume(){P===e&&(e.admitted=!0,Ft())},dispose(){P===e&&(P=null,Bn())}}}var Te=null,ut=null,ne=null,G=null;function sn(){Te=new Promise(e=>{ne=e}),ut=new Promise(e=>{G=e})}function ft(){return Te||sn(),{laneReady:Te,writerReady:ut}}function $r(){return ft().laneReady}function Cr(){return ft().writerReady}function Bt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Un(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=z.get(e);return z.delete(e),F===e&&(F=null),q===e&&(q=null),t}function an(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function zn(e,t){let r=e?.code,o=r==="page-converting"||r==="page-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function zt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&G?.(p)},onApplied:Bt,onLanded:()=>{Bt(),nn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Jt(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:jn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Jt(t)||re(t,{read:!1}))}}}function Vn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=Z(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Q))return;tt=!0;let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await Pn().catch(()=>null);if(e===xe){if(!o){ne?.(null),G?.(null);return}if(t)p=o.createFastLane(zt(It()));else if(o.localLaneSupported())W=o.localTransport({seed:Vn,rooms:!0,floor:document.querySelector('meta[name="clay-page-format"]')?.getAttribute("content")}),p=o.createFastLane(zt(W));else{ne?.(null),G?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{cn(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),ne?.(p),p.status.writer!==null&&G?.(p)}}).catch(()=>{ne?.(null),G?.(null)})}function Kn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Kn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if($n.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Gn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^page(\.[0-9]+)?$/.test(e.store.name)?qt(r):r;return e.layout==="lines"?Xn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Vt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Xn(e){return Vt(e)?`{${Object.entries(e).map(([r,o])=>!Vt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
|
|
2
2
|
${Object.entries(o).map(([n,s])=>`${R(n)}:${R(s)}`).join(`,
|
|
3
3
|
`)}
|
|
4
4
|
}`).join(`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as M,g as _,h as A,w as q}from"./c-SJPD46ZO.js";import{B as G}from"./c-44B5ODN7.js";import{D as O,G as $,I as y,J as B,M as R,Z as j,_ as U,b as z,m as p,na as F}from"./c-QIXT3Q7C.js";import{a as x}from"./c-E4IBSAQM.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function g(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),a=s.filter(r=>r!==s[0]&&i[r]==="number");return a.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:a,title:"",highlight:null}:null}function wt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,a=e.maybeChild(e.resolve(i).index(0)),r=Q(s,$(s.attrs.pos,a?.attrs.pos??null),s.attrs.parent);return r?(D.add(r.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(r))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!g(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let a=0;for(let m=0;m<t;m++)a+=i.doc.child(m).nodeSize;let r=i.doc.child(t),c=r.isTextblock&&r.content.size===0,h=i.doc.maybeChild(t+1),f=c?r.attrs.pos:$(r.attrs.pos,h?.attrs.pos??null),d=Q(e,f,r.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let w=p.nodes.chart.create(d);return i=c?i.replaceWith(a,a+r.nodeSize,w):i.insert(a+r.nodeSize,w),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function kt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,a=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,a,s.map(r=>({label:A(i,r.attrs.id)??"",description:`${r.childCount} ${r.childCount===1?"row":"rows"} \xB7 ${X(r)}`,icon:"\u25A6",run:()=>W(n,t,r,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<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>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function at(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(a=>e[a]!=="number")??t[0],i=t.filter(a=>a!==s&&e[a]==="number");return{x:s,series:i.length?i:t.filter(a=>a!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","page-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="page-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","page-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","page-chart-title"),this.chip=l(i,"button","page-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","page-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","page-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","page-chart-plot"),this.broken=l(i,"div","page-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",a=>this.brokenClick(a)),this.panel=l(i,"div","page-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",a=>this.panelClick(a)),this.panel.addEventListener("change",a=>this.panelChange(a)),this.panel.addEventListener("mousedown",a=>{a.target.closest?.("button")&&a.preventDefault()}),this.outside=a=>{!this.panel.isConnected||this.dom.contains(a.target)||(this.commitTitle(),this.closePanel())},this.escape=a=>{!this.panel.isConnected||a.key!=="Escape"||(a.preventDefault(),a.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=g(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let a=this.doc;this.broken.textContent="",this.broken.append(l(a,"div","page-chart-broken-head","This chart's table was deleted"),l(a,"p","page-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let r=l(a,"div","page-chart-broken-actions");if(s.length){let h=T(a,"rescue","Source table");for(let d of s)h.append(C(a,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(a,"button","page-chart-use","Use this table");f.type="button",f.dataset.action="use",r.append(h,f)}let c=l(a,"button","page-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",r.append(c),this.broken.append(r)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!g(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","page-chart-row");return t&&s.append(l(this.doc,"span","page-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(g(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let a=[...this.panel.querySelectorAll("button, input, select")].find(r=>["field","kind","col","action"].every(c=>r.dataset[c]===e[c]));if(!a)return this.panel.focus();a.focus(),i&&a===this.titleInput&&a.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],a=s?.rows??[],r=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","page-chart-types");for(let[o,P]of st){let b=l(t,"button","page-chart-type",P);b.type="button",b.dataset.kind=o,b.setAttribute("aria-pressed",String(e.kind===o)),c.append(b)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let o of E(this.view.state.doc))h.append(C(t,o.id,`${o.name} (${o.rows} ${o.rows===1?"row":"rows"})`,o.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let o of i)f.append(C(t,o.id,o.name||o.id,o.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","page-chart-values");i.filter(o=>o.id!==e.x).forEach((o,P)=>{let b=l(t,"label","page-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=o.id,v.checked=e.series.includes(o.id);let I=l(t,"span","page-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),b.append(v,I,l(t,"span","page-chart-value-name",o.name||o.id)),d.append(b)});let w=this.row(r?"Value column":"Value columns",d);r&&w.append(l(t,"span","page-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(w);let m=T(t,"highlight","Highlight row");m.append(C(t,"","None",!e.highlight));for(let o of a)m.append(C(t,o.id,O(o.cells?.[e.x])||o.id,o.id===e.highlight));this.panel.append(this.row("Highlight row",m));let u=l(t,"input","page-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||o.key==="Enter"&&(o.preventDefault(),o.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","page-chart-foot"),k=l(t,"button","page-chart-remove");k.type="button",k.dataset.action="remove",k.innerHTML=et,k.append("Remove");let L=l(t,"button","page-chart-done","Done");L.type="button",L.dataset.action="done",H.append(k,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=g(this.view.state.doc,t),s=e?at(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=g(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".page-chart-head, .page-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{wt as a,X as b,kt as c,Y as d,vt as e};
|
|
1
|
+
import{c as M,g as _,h as A,w as q}from"./c-4RFZROCF.js";import{B as G}from"./c-TMT5TL65.js";import{D as O,G as $,I as y,J as B,M as R,Z as j,_ as U,b as z,m as p,na as F}from"./c-QIXT3Q7C.js";import{a as x}from"./c-OI2BYWVV.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function g(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),a=s.filter(r=>r!==s[0]&&i[r]==="number");return a.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:a,title:"",highlight:null}:null}function wt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,a=e.maybeChild(e.resolve(i).index(0)),r=Q(s,$(s.attrs.pos,a?.attrs.pos??null),s.attrs.parent);return r?(D.add(r.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(r))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!g(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let a=0;for(let m=0;m<t;m++)a+=i.doc.child(m).nodeSize;let r=i.doc.child(t),c=r.isTextblock&&r.content.size===0,h=i.doc.maybeChild(t+1),f=c?r.attrs.pos:$(r.attrs.pos,h?.attrs.pos??null),d=Q(e,f,r.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let w=p.nodes.chart.create(d);return i=c?i.replaceWith(a,a+r.nodeSize,w):i.insert(a+r.nodeSize,w),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function kt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,a=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,a,s.map(r=>({label:A(i,r.attrs.id)??"",description:`${r.childCount} ${r.childCount===1?"row":"rows"} \xB7 ${X(r)}`,icon:"\u25A6",run:()=>W(n,t,r,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<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>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function at(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(a=>e[a]!=="number")??t[0],i=t.filter(a=>a!==s&&e[a]==="number");return{x:s,series:i.length?i:t.filter(a=>a!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","page-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="page-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","page-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","page-chart-title"),this.chip=l(i,"button","page-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","page-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","page-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","page-chart-plot"),this.broken=l(i,"div","page-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",a=>this.brokenClick(a)),this.panel=l(i,"div","page-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",a=>this.panelClick(a)),this.panel.addEventListener("change",a=>this.panelChange(a)),this.panel.addEventListener("mousedown",a=>{a.target.closest?.("button")&&a.preventDefault()}),this.outside=a=>{!this.panel.isConnected||this.dom.contains(a.target)||(this.commitTitle(),this.closePanel())},this.escape=a=>{!this.panel.isConnected||a.key!=="Escape"||(a.preventDefault(),a.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=g(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let a=this.doc;this.broken.textContent="",this.broken.append(l(a,"div","page-chart-broken-head","This chart's table was deleted"),l(a,"p","page-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let r=l(a,"div","page-chart-broken-actions");if(s.length){let h=T(a,"rescue","Source table");for(let d of s)h.append(C(a,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(a,"button","page-chart-use","Use this table");f.type="button",f.dataset.action="use",r.append(h,f)}let c=l(a,"button","page-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",r.append(c),this.broken.append(r)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!g(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","page-chart-row");return t&&s.append(l(this.doc,"span","page-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(g(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let a=[...this.panel.querySelectorAll("button, input, select")].find(r=>["field","kind","col","action"].every(c=>r.dataset[c]===e[c]));if(!a)return this.panel.focus();a.focus(),i&&a===this.titleInput&&a.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],a=s?.rows??[],r=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","page-chart-types");for(let[o,P]of st){let b=l(t,"button","page-chart-type",P);b.type="button",b.dataset.kind=o,b.setAttribute("aria-pressed",String(e.kind===o)),c.append(b)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let o of E(this.view.state.doc))h.append(C(t,o.id,`${o.name} (${o.rows} ${o.rows===1?"row":"rows"})`,o.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let o of i)f.append(C(t,o.id,o.name||o.id,o.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","page-chart-values");i.filter(o=>o.id!==e.x).forEach((o,P)=>{let b=l(t,"label","page-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=o.id,v.checked=e.series.includes(o.id);let I=l(t,"span","page-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),b.append(v,I,l(t,"span","page-chart-value-name",o.name||o.id)),d.append(b)});let w=this.row(r?"Value column":"Value columns",d);r&&w.append(l(t,"span","page-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(w);let m=T(t,"highlight","Highlight row");m.append(C(t,"","None",!e.highlight));for(let o of a)m.append(C(t,o.id,O(o.cells?.[e.x])||o.id,o.id===e.highlight));this.panel.append(this.row("Highlight row",m));let u=l(t,"input","page-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||o.key==="Enter"&&(o.preventDefault(),o.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","page-chart-foot"),k=l(t,"button","page-chart-remove");k.type="button",k.dataset.action="remove",k.innerHTML=et,k.append("Remove");let L=l(t,"button","page-chart-done","Done");L.type="button",L.dataset.action="done",H.append(k,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=g(this.view.state.doc,t),s=e?at(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=g(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".page-chart-head, .page-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{wt as a,X as b,kt as c,Y as d,vt as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as j}from"./c-UGNV5MFB.js";import{b as S,c as A,f as C,i as l,j as P,l as L,n as B}from"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var y=0,x=[],b=[],d=null,I=!1,E=!1,v=null,M=null,$=15e3,u=()=>P().mode,p=(e,t)=>Object.assign(new Error(`clay.modeLifecycle: ${e}`),{code:t});function U(){document.dispatchEvent(new Event("clay:modechange"))}function h(e,t="idle",o={}){return l({phase:t,reason:e}),{ok:!1,mode:u(),code:e,...o}}function k(e){for(let t of[...e].reverse())try{t.dispose?.()}catch{}}function D(e){try{e?.reclaimArticle?.()}catch{}try{e?.resume?.()}catch{}}function O(e){document.documentElement.setAttribute("editmode",e?"true":"false")}function G(){try{let e=new URL(window.location.href);if(!e.searchParams.has("editmode"))return;e.searchParams.delete("editmode"),window.history.replaceState(window.history.state,"",`${e.pathname}${e.search}${e.hash}`)}catch(e){console.warn("clayjs: the URL could not be rewritten after the mode switch",e)}}var N=e=>[...e?.edit?.core??[],...e?.edit?.plugins??[],...e?.edit?.late??[]];function X(e){let t=[];for(let o of N(e)){let n=j(o);if(n!=="export"&&typeof n!="function")continue;let r=e.loaded?.[o];r&&t.push(typeof n=="function"?n(r):r.modeParticipant?.())}return t}async function _(e){let t=new Set(b.map(({id:n})=>n)),o=n=>{if(typeof n?.id!="string"||typeof n.prepare!="function")throw p("a participant needs an id and a prepare()","unsupported-plugin");t.has(n.id)||(t.add(n.id),b.push(n))};if(e)for(let n of X(e))o(await n);for(let n of B())o(await n);return[...b].sort((n,r)=>(n.order??0)-(r.order??0))}function z(e){let t=b.findIndex(o=>o.id===e);t!==-1&&b.splice(t,1)}L(z);function H(e,t){if(!e||e.bytes===null)return!1;let o=t??{};return typeof e.seq=="number"&&typeof o.seq=="number"&&e.seq!==o.seq?e.seq>o.seq:(e.etag??null)!==(o.etag??null)}async function V(e=null){let t=u(),o=C,n=new AbortController,r={generation:++y,destination:P().destination,signal:n.signal,represented:null,reader:null,initial:!1,isCurrent:()=>r.generation===y&&!n.signal.aborted};l({phase:"entering",generation:r.generation,reason:null}),e||(I=!0,E=!1,v=null);let s=[],c=[],f=null,i=null,w=!1,m=(async()=>{try{if(e){let a=await import("./c-V2J5C5MT.js");i=await a.prepareReader(e,r),c.push(...await a.importPlan(e,e.edit,{signal:n.signal})),await i?.reconcile(),r.represented=i?i.represented:null,r.reader=i,M=r.represented}f=e?.loaded?.["core/save.js"]??await import("./core/save-
|
|
1
|
+
import{a as j}from"./c-UGNV5MFB.js";import{b as S,c as A,f as C,i as l,j as P,l as L,n as B}from"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var y=0,x=[],b=[],d=null,I=!1,E=!1,v=null,M=null,$=15e3,u=()=>P().mode,p=(e,t)=>Object.assign(new Error(`clay.modeLifecycle: ${e}`),{code:t});function U(){document.dispatchEvent(new Event("clay:modechange"))}function h(e,t="idle",o={}){return l({phase:t,reason:e}),{ok:!1,mode:u(),code:e,...o}}function k(e){for(let t of[...e].reverse())try{t.dispose?.()}catch{}}function D(e){try{e?.reclaimArticle?.()}catch{}try{e?.resume?.()}catch{}}function O(e){document.documentElement.setAttribute("editmode",e?"true":"false")}function G(){try{let e=new URL(window.location.href);if(!e.searchParams.has("editmode"))return;e.searchParams.delete("editmode"),window.history.replaceState(window.history.state,"",`${e.pathname}${e.search}${e.hash}`)}catch(e){console.warn("clayjs: the URL could not be rewritten after the mode switch",e)}}var N=e=>[...e?.edit?.core??[],...e?.edit?.plugins??[],...e?.edit?.late??[]];function X(e){let t=[];for(let o of N(e)){let n=j(o);if(n!=="export"&&typeof n!="function")continue;let r=e.loaded?.[o];r&&t.push(typeof n=="function"?n(r):r.modeParticipant?.())}return t}async function _(e){let t=new Set(b.map(({id:n})=>n)),o=n=>{if(typeof n?.id!="string"||typeof n.prepare!="function")throw p("a participant needs an id and a prepare()","unsupported-plugin");t.has(n.id)||(t.add(n.id),b.push(n))};if(e)for(let n of X(e))o(await n);for(let n of B())o(await n);return[...b].sort((n,r)=>(n.order??0)-(r.order??0))}function z(e){let t=b.findIndex(o=>o.id===e);t!==-1&&b.splice(t,1)}L(z);function H(e,t){if(!e||e.bytes===null)return!1;let o=t??{};return typeof e.seq=="number"&&typeof o.seq=="number"&&e.seq!==o.seq?e.seq>o.seq:(e.etag??null)!==(o.etag??null)}async function V(e=null){let t=u(),o=C,n=new AbortController,r={generation:++y,destination:P().destination,signal:n.signal,represented:null,reader:null,initial:!1,isCurrent:()=>r.generation===y&&!n.signal.aborted};l({phase:"entering",generation:r.generation,reason:null}),e||(I=!0,E=!1,v=null);let s=[],c=[],f=null,i=null,w=!1,m=(async()=>{try{if(e){let a=await import("./c-V2J5C5MT.js");i=await a.prepareReader(e,r),c.push(...await a.importPlan(e,e.edit,{signal:n.signal})),await i?.reconcile(),r.represented=i?i.represented:null,r.reader=i,M=r.represented}f=e?.loaded?.["core/save.js"]??await import("./core/save-OJ5NSLS7.js");for(let a of await _(e)){w=!0;let g=await a.prepare(r);if(g){if(s.push(g),!r.isCurrent())throw p(`"${a.id}" prepared for a stale generation`,"stale-document");if(g.ready&&await g.ready,!r.isCurrent())throw p(`"${a.id}" became ready for a stale generation`,"stale-document")}}if(e||!o){let a=f.adoptEntryBaseline({represented:r.represented});if(a&&a.ok===!1)throw Object.assign(p("the page moved since the last session",a.code||"pending-input"),a);if(H(i?.held??i?.represented,r.represented))throw p("the reader holds a newer file than the session was built from","stale-document")}return!0}catch(a){throw k(s),a}})(),q=null,W=new Promise(a=>{q=setTimeout(()=>{n.abort(),a(!1)},$)}),T;try{T=await Promise.race([m,W])}catch(a){return clearTimeout(q),n.abort(),w?(D(i),h(a?.code||"load-failed","blocked",{message:a?.message})):(D(i),l({phase:"idle",reason:null}),null)}if(clearTimeout(q),!T)return m.catch(()=>{}),k(s.splice(0)),D(i),h("timeout");i?.commit(),l({mode:S?"draft":"edit",isEditMode:!0}),e&&G(),O(!0),f?.setSaveGeneration(r.generation);try{for(let a of s)a.enable()}catch(a){return l({mode:t,isEditMode:o}),O(!1),k(s),n.abort(),e&&(await import("./c-V2J5C5MT.js").catch(()=>null))?.startReader(e,M),h(a?.code||"load-failed","blocked",{message:a?.message})}x=s,l({phase:"idle",reason:null}),U();for(let a of c)e?.announce?.(a);return{ok:!0,mode:u(),changed:t!==u()}}async function J(e){if(!e)return[];let t=[];for(let r of N(e)){let s=j(r);if(s!=="export"&&typeof s!="function")continue;let c=e.loaded?.[r];if(!c)continue;let f=await(typeof s=="function"?s(c):c.modeParticipant?.());if(typeof f?.id!="string"||typeof f.prepare!="function")return null;t.push(f)}t.sort((r,s)=>(r.order??0)-(s.order??0));let o=[],n={generation:y,destination:P().destination,signal:void 0,represented:null,reader:null,initial:!0,isCurrent:()=>!0};for(let r of t){let s=null;try{s=await r.prepare(n)}catch{return null}s&&o.push(s)}return o}async function K(e){return(e?.loaded?.["core/save.js"]??await import("./core/save-OJ5NSLS7.js").catch(()=>null))?.acceptedReceipt?.(y)??null}var R=Symbol("the exit deadline passed");function Q(){let e=null,t=Date.now()+$;return{expired:new Promise(n=>{e=setTimeout(()=>n(R),$)}),remaining:()=>Math.max(0,t-Date.now()),clear:()=>clearTimeout(e)}}async function Y(e,t){if(!e)return;let n=(await import("./c-V2J5C5MT.js")).importPlan(e,e.view);n.catch(()=>{});let r=await Promise.race([n.then(()=>null,s=>s),t]);if(r&&r!==R)throw r}async function Z(e=null){let t=Q();try{return await ee(e,t)}finally{t.clear()}}async function ee(e,t){let o=I;l({phase:"leaving"});let n=await import("./c-LF6HNVPU.js").catch(()=>null);if(!n)return h("load-failed");let r=x;if(o&&!E){v??=J(e);let i=await Promise.race([v,t.expired]);if(i===R)return h("timeout");if(!i)return v=null,l({phase:"idle",reason:null}),null;E=!0,r=[...i,...r],x=r}try{await Y(e,t.expired)}catch(i){return h(i?.code||"load-failed","idle",{message:i?.message})}let s=[],c=null;try{if(c=n.claimOperation("mode"),!c)throw p("another document operation is in progress","busy");for(let w of[...r].reverse()){s.push(w);let m=await Promise.race([Promise.resolve(w.quiesce?.()),t.expired]);if(m===R)throw p("the exit deadline passed while a lease quiesced","timeout");if(m&&m.ok===!1)throw Object.assign(p("a lease refused the exit",m.code||"pending-input"),m)}let i=await n.runSaveBarrier({operation:c,timeoutMs:t.remaining()});if(!i.ok)throw Object.assign(p("the exit barrier refused",i.code||"save-failed"),i)}catch(i){for(let w of[...s].reverse())try{w.resume?.()}catch{}return l({phase:"idle",reason:i?.code||"save-failed"}),{ok:!1,mode:u(),code:i?.code||"save-failed",state:i?.state,pending:i?.pending}}finally{c&&n.releaseOperation(c)}k(r),x=[],I=!1,E=!1,v=null;let f=await K(e)??M;return M=null,e&&(await import("./c-V2J5C5MT.js").catch(()=>null))?.startReader(e,f),y++,O(!1),l({mode:"view",isEditMode:!1,phase:"idle",generation:y,reason:null}),G(),U(),{ok:!0,mode:"view",changed:!0}}function F(e,t=null){if(e!=="edit"&&e!=="view")throw new TypeError(`clay.modeLifecycle: unknown mode "${e}"`);if(d)return d.target===e?d.promise:{ok:!1,mode:u(),code:"busy"};if(e===u())return{ok:!0,mode:u(),changed:!1};if(S||e==="edit"&&!A)return{ok:!1,mode:u(),code:"not-allowed"};let o=(e==="edit"?V(t):Z(t)).finally(()=>{d=null});return d={target:e,promise:o},o}async function re(e,t){let o=await import("./c-V2J5C5MT.js").catch(()=>null);return!o||!o.liveAllowed(t)?null:(d||e===u()||e==="edit"&&o.openResources(),F(e,t))}async function oe(){if(u()==="view")return{ok:!0,mode:"view",changed:!1};if(d)return d.promise;let e=V().finally(()=>{d=null});return d={target:"edit",promise:e},e}export{oe as activateInitial,z as forgetParticipant,F as requestMode,re as switchMode};
|