@malloy-publisher/app 0.9.15 → 0.9.16

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.
@@ -0,0 +1,144 @@
1
+ import{g as rp,a as ip,r as S,u as sp,b9 as op,k as ap,i as lp,ba as cp,l as dp,j as m,f as up,h as hp,s as ka,m as fp,t as Wl,Z as ad,V as qe,bb as cn,bc as Cs,aD as ft,ae as rt,N as Ot,L as $n,bd as nr,ak as Ae,be as Sa,bf as vi,bg as Xn,bh as pp,bi as ld,bj as rn,bk as mp,bl as gp,bm as mo,bn as vp,T as ve,as as ht,bo as xp,bp,bq as yp,Q as $a,aK as wp,br as Qt,bs as kp,bt as ja,bu as Sp,bv as cd,bw as dd,bx as $p,by as jp,a0 as go,bz as Mp,bA as Ep,bB as vo,aZ as ud,B as hd,bC as nt,I as _,aJ as Xe,bD as mt,bE as Ma,Y as Bt,bF as Cp,bG as pt,bH as zl,bI as Gr,bJ as fd,bK as Tp,bL as Ea,ag as Op,bM as Ap,bN as Rp,bO as Dp,bP as Pp,bQ as Ip,bR as pd,bS as Np,bT as Wp,bU as md,bV as gd,bW as vd,bX as zp,bY as Lp,bZ as Fp,b_ as Bp,b$ as _p,c0 as qp,c1 as Hp,c2 as Up,c3 as Vp,J as Kp,c4 as Gp,c5 as Yp,c6 as xo,c7 as bo,c8 as Ll,c9 as Xp,ca as Qp,cb as Zp,cc as Qn,cd as Jp,ce as em,cf as tm,cg as nm,ch as rm,ci as xd,cj as Ca,ck as im,cl as sm,cm as bd,cn as om,co as am,cp as lm,cq as Ts,cr as ns,cs as cm,ct as dm,cu as rs,cv as um,cw as kn,cx as hm,cy as fm,cz as yd,cA as pm,cB as mm,aP as Ta,aF as Zt,cC as yo,cD as gm,cE as vm,cF as wd,X as kd,cG as xm,cH as bm,cI as Os,cJ as ym,cK as wo,cL as wm,cM as km,cN as Sm,cO as Sd,cP as $m,H as jm,cQ as Mm,cR as Em,cS as Cm,cT as Tm,cU as Om,cV as Am,cW as Oa,cX as Rm,cY as Dm,cZ as $d,c_ as Pm,c$ as Im,d0 as Nm,d1 as Aa,d2 as Wm,d3 as zm,d4 as Lm,d5 as Dn,d6 as jd,d7 as Fl,d8 as Bl,d9 as Vs,da as Fm,S as Bm,db as _m,dc as qm,dd as Hm,de as Md,df as Um,dg as Vm,aj as Km}from"./index-Dzz5PLbw.js";import{dh as tk,di as nk,dj as rk,dk as ik,dl as sk,dm as ok,dn as ak,dp as lk,dq as ck,dr as dk,ds as uk}from"./index-Dzz5PLbw.js";import{T as Ed,a as ko}from"./ToggleButtonGroup-ChqidtS2.js";function Gm(e){return rp("MuiCollapse",e)}ip("MuiCollapse",["root","horizontal","vertical","entered","hidden","wrapper","wrapperInner"]);const Ym=e=>{const{orientation:t,classes:n}=e,r={root:["root",`${t}`],entered:["entered"],hidden:["hidden"],wrapper:["wrapper",`${t}`],wrapperInner:["wrapperInner",`${t}`]};return hp(r,Gm,n)},Xm=ka("div",{name:"MuiCollapse",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[n.orientation],n.state==="entered"&&t.entered,n.state==="exited"&&!n.in&&n.collapsedSize==="0px"&&t.hidden]}})(fp(({theme:e})=>({height:0,overflow:"hidden",transition:e.transitions.create("height"),variants:[{props:{orientation:"horizontal"},style:{height:"auto",width:0,transition:e.transitions.create("width")}},{props:{state:"entered"},style:{height:"auto",overflow:"visible"}},{props:{state:"entered",orientation:"horizontal"},style:{width:"auto"}},{props:({ownerState:t})=>t.state==="exited"&&!t.in&&t.collapsedSize==="0px",style:{visibility:"hidden"}}]}))),Qm=ka("div",{name:"MuiCollapse",slot:"Wrapper"})({display:"flex",width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),Zm=ka("div",{name:"MuiCollapse",slot:"WrapperInner"})({width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),So=S.forwardRef(function(t,n){const r=sp({props:t,name:"MuiCollapse"}),{addEndListener:i,children:s,className:o,collapsedSize:a="0px",component:d,easing:f,in:c,onEnter:l,onEntered:u,onEntering:p,onExit:g,onExited:v,onExiting:b,orientation:w="vertical",style:h,timeout:x=op.standard,TransitionComponent:y=ap,...k}=r,C={...r,orientation:w,collapsedSize:a},$=Ym(C),T=lp(),j=cp(),M=S.useRef(null),I=S.useRef(),N=typeof a=="number"?`${a}px`:a,R=w==="horizontal",L=R?"width":"height",B=S.useRef(null),q=dp(n,B),D=H=>ne=>{if(H){const Q=B.current;ne===void 0?H(Q):H(Q,ne)}},F=()=>M.current?M.current[R?"clientWidth":"clientHeight"]:0,E=D((H,ne)=>{M.current&&R&&(M.current.style.position="absolute"),H.style[L]=N,l&&l(H,ne)}),O=D((H,ne)=>{const Q=F();M.current&&R&&(M.current.style.position="");const{duration:ge,easing:Z}=Wl({style:h,timeout:x,easing:f},{mode:"enter"});if(x==="auto"){const Re=T.transitions.getAutoHeightDuration(Q);H.style.transitionDuration=`${Re}ms`,I.current=Re}else H.style.transitionDuration=typeof ge=="string"?ge:`${ge}ms`;H.style[L]=`${Q}px`,H.style.transitionTimingFunction=Z,p&&p(H,ne)}),W=D((H,ne)=>{H.style[L]="auto",u&&u(H,ne)}),U=D(H=>{H.style[L]=`${F()}px`,g&&g(H)}),V=D(v),Y=D(H=>{const ne=F(),{duration:Q,easing:ge}=Wl({style:h,timeout:x,easing:f},{mode:"exit"});if(x==="auto"){const Z=T.transitions.getAutoHeightDuration(ne);H.style.transitionDuration=`${Z}ms`,I.current=Z}else H.style.transitionDuration=typeof Q=="string"?Q:`${Q}ms`;H.style[L]=N,H.style.transitionTimingFunction=ge,b&&b(H)}),re=H=>{x==="auto"&&j.start(I.current||0,H),i&&i(B.current,H)};return m.jsx(y,{in:c,onEnter:E,onEntered:W,onEntering:O,onExit:U,onExited:V,onExiting:Y,addEndListener:re,nodeRef:B,timeout:x==="auto"?null:x,...k,children:(H,{ownerState:ne,...Q})=>m.jsx(Xm,{as:d,className:up($.root,o,{entered:$.entered,exited:!c&&N==="0px"&&$.hidden}[H]),style:{[R?"minWidth":"minHeight"]:N,...h},ref:q,ownerState:{...C,state:H},...Q,children:m.jsx(Qm,{ownerState:{...C,state:H},className:$.wrapper,ref:M,children:m.jsx(Zm,{ownerState:{...C,state:H},className:$.wrapperInner,children:s})})})})});So&&(So.muiSupportAuto=!0);var _l={};const Ee=e=>e.kind==="text",le=e=>e.kind!=="text",Mr=e=>le(e)?e.label??e.name:e.name,vt=e=>e.declaration.kind==="query"?e.name:`${e.source} -> ${e.name}`,cr=e=>e.declaration.kind==="inherited"||e.declaration.kind==="query",fe=e=>Ee(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,ql=".malloy-big-value, .malloy-table",Jm=e=>e.querySelector(ql)!==null&&![...e.querySelectorAll(".malloy-chart")].some(t=>t.closest(ql)===null),is=(e,t)=>Ee(e)?cm:t&&Jm(t)?dm:rs,ii=e=>e.rowspan??Ea[Ee(e)?"text":"query"];function sn(e,t){if(e.row===void 0||e.col===void 0)return;const n=Math.min(e.colspan??1,t);return{row:e.row,col:Math.min(e.col,t-n+1),colspan:n,rowspan:ii(e)}}const si=(e,t)=>e.col<t.col+t.colspan&&t.col<e.col+e.colspan&&e.row<t.row+t.rowspan&&t.row<e.row+e.rowspan;function Kn(e){return e.map((t,n)=>({tile:t,index:n})).sort((t,n)=>(t.tile.row??1/0)-(n.tile.row??1/0)||(t.tile.col??1/0)-(n.tile.col??1/0)||t.index-n.index).map(({tile:t})=>t)}function Ht(e,t,n){const r=e.map(a=>({...a})),i=[],s=a=>{const d=sn(r[a],t);d&&(r[a].col=d.col,i.push(d))};n!==void 0&&s(n);const o=r.map((a,d)=>({tile:a,index:d})).filter(({index:a,tile:d})=>a!==n&&d.row!==void 0).sort((a,d)=>(a.tile.row??0)-(d.tile.row??0)||(a.tile.col??0)-(d.tile.col??0)||a.index-d.index);for(const{index:a}of o){const d=sn(r[a],t);if(d){for(;;){const f=i.filter(c=>si(d,c));if(f.length===0)break;d.row=Math.max(...f.map(c=>c.row+c.rowspan))}r[a].row=d.row,s(a)}}return r}function eg(e,t,n,r){const i=e.flatMap((d,f)=>{const c=f===t?void 0:sn(d,r);return c?[c]:[]}),s=Math.max(1,...i.map(d=>d.row+d.rowspan)),o={...e[t],...n,row:Math.min(n.row,s)},a=sn(o,r);if(a){for(;;){const d=i.filter(f=>f.row<a.row&&si(a,f));if(d.length===0)break;a.row=Math.max(...d.map(f=>f.row+f.rowspan))}o.row=a.row}return Ht(e.map((d,f)=>f===t?o:d),r,t)}const ss=(e,t)=>(e-pt*(t-1))/t,Cd=ns+pt;function Td(e,t,n,r,i){const s=Math.min(n,r),o=Math.round(e/(i+pt))+1;return{row:Math.max(1,Math.round(t/Cd)+1),col:Math.min(Math.max(o,1),r-s+1)}}function Od(e,t,n,r){const i=e.map((s,o)=>{if(s.row!==void 0&&s.col!==void 0)return s;const a=t[o];if(!a)return s;const{break:d,...f}=s,c=s.colspan??Math.max(1,Math.round((a.width+pt)/(r+pt))),l=Td(a.left,a.top,c,n,r),u=Math.round((a.top+a.height+pt)/Cd);return{...f,...l,colspan:c,rowspan:s.rowspan??Math.max(is(s),u-l.row+1)}});return Ht(i,n)}function Hl(e,t,n){const r=e.flatMap((s,o)=>{const a=o===t?void 0:sn(s,n);return a?[a]:[]});if(r.length===0)return[...e];const i=Math.max(...r.map(s=>s.row+s.rowspan));return e.map((s,o)=>o===t?{...s,row:i,col:1}:s)}function Ad(e,t){const n=e.map(s=>({...s})),r=[],i=n.map((s,o)=>({tile:s,index:o})).filter(({tile:s})=>s.row!==void 0&&s.col!==void 0).sort((s,o)=>(s.tile.row??0)-(o.tile.row??0)||(s.tile.col??0)-(o.tile.col??0)||s.index-o.index);for(const{index:s}of i){const o=sn(n[s],t);if(o){for(;o.row>1&&!r.some(a=>si({...o,row:o.row-1},a));)o.row-=1;n[s].row=o.row,n[s].col=o.col,r.push(o)}}return n}const tg=(e,t)=>Ad(e,t).some((n,r)=>n.row!==e[r].row||n.col!==e[r].col);function ng(e){return Kn(e).map(t=>{const{row:n,col:r,...i}=t;return i})}const rg=(e,t,n)=>e.map((r,i)=>i===t?{...r,...n}:r);function Ul(e,t,n,r,i){const s=sn(e[t],i);if(!s)return[...e];const o={row:Math.max(1,s.row+n),col:Math.min(Math.max(1,s.col+r),i-s.colspan+1)};if(o.row===s.row&&o.col===s.col)return[...e];const a={...s,...o},d=e.flatMap((p,g)=>{const v=g===t?void 0:sn(p,i);return v&&si(a,v)&&!si(s,v)?[{i:g,other:v}]:[]}),f=d.length===1?d[0]:void 0;if(!f)return Ht(rg(e,t,o),i,t);const{i:c,other:l}=f,u=e.map(p=>({...p}));return n>0?(u[c].row=s.row,u[t].row=s.row+l.rowspan):n<0?(u[t].row=l.row,u[c].row=l.row+s.rowspan):r>0?(u[c].col=s.col,u[t].col=s.col+l.colspan):(u[t].col=l.col,u[c].col=l.col+s.colspan),Ht(u,i,t)}const Rd=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1);function ig(e){return Ee(e)||e.rowspan===void 0?e:Os(e.chart)&&e.chart!=="big_value"&&e.rowspan<rs?{...e,rowspan:rs}:e}const Dd=mt(m.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),Pd=mt(m.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),sg=mt(m.jsx("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}));function Id(e){const{theme:t}=qe(),n=t.ui,[r,i]=S.useState(null),{status:s,draftKeptAt:o,discard:a,restored:d,dismissRestored:f}=e,c=d!==void 0&&!d.pending&&s==="unsaved"?d:void 0,l=s==="saved"?"Saved":s==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",u=c?`Restored your unsaved edits from ${$o(c.savedAt)}`:void 0,p=s==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,g=a!==void 0&&s==="unsaved",v=()=>{i(null),c&&f?.()},b=x=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:s==="saved"?x.palette.text.secondary:x.palette.text.primary,transition:`color ${nt}, background-color ${nt}`,...g?{"&:hover":{bgcolor:x.palette.action.hover}}:{}}),w=m.jsxs(m.Fragment,{children:[m.jsx(_,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:s==="saved"?m.jsx(Ts,{sx:{fontSize:16}}):m.jsx(_,{component:"span","data-restored":c?"true":void 0,sx:x=>({width:7,height:7,borderRadius:"50%",bgcolor:c?t.accent:s==="saving"||o!==void 0?x.palette.text.disabled:x.palette.warning.main,transition:`background-color ${nt}`})})}),m.jsx(_,{component:"span","aria-hidden":!0,children:l}),m.jsx(Sa,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:g?"visible":"hidden"}})]}),h=m.jsx(_,{component:"span",role:"status","aria-live":"polite",sx:og,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[h,m.jsx(Ot,{title:u??p,describeChild:!0,children:g?m.jsx(hd,{className:rt.saveStatus,"aria-label":l,...u?{"aria-description":u}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:x=>i(x.currentTarget),sx:b,children:w}):m.jsx(_,{component:"span",className:rt.saveStatus,sx:b,children:w})}),m.jsxs(Xn,{className:rt.menu,anchorEl:r,open:r!==null,onClose:v,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${cn(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(u!==void 0||o!==void 0)&&m.jsx(_,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:u??`Kept in this browser at ${$o(o)}`}),m.jsxs(Xe,{onClick:()=>{i(null),a?.()},sx:{mx:.5,borderRadius:n.radius.control,gap:1.25,color:"error.main","&.Mui-focusVisible":{outline:"none",bgcolor:"action.hover"}},children:[m.jsx(sg,{fontSize:"small"}),"Discard edits"]})]})]})}function $o(e){const t=new Date(e);return new Date().toDateString()===t.toDateString()?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}const og={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},jo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Sn=jo?"⌘":"Ctrl+",Vl=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Ks=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function ag(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e});const[n,r]=S.useState(!1);S.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),S.useEffect(()=>{const i=s=>{const o=t.current;if(o.paused)return;const a=jo?s.metaKey:s.ctrlKey,d=s.key.toLowerCase();if(s.key==="Escape"){if(Vl(s.target)||Ks(s.target))return;o.escape();return}if(Vl(s.target)){if(a&&d==="s"){if(s.preventDefault(),!o.save||Ks(s.target))return;s.target.blur(),r(!0)}return}if(Ks(s.target)){a&&d==="s"&&s.preventDefault();return}if(a&&d==="z"){s.preventDefault(),s.shiftKey?o.redo():o.undo();return}if(!jo&&a&&d==="y"){s.preventDefault(),o.redo();return}if(a&&d==="s"){s.preventDefault(),o.save?.();return}if(o.move&&s.altKey&&!a&&!s.shiftKey){const f=s.key==="ArrowLeft"?[0,-1]:s.key==="ArrowRight"?[0,1]:s.key==="ArrowUp"?[-1,0]:s.key==="ArrowDown"?[1,0]:void 0;if(f&&o.move(f[0],f[1])){s.preventDefault();return}}o.nudge&&!a&&!s.altKey&&!s.shiftKey&&(s.key==="ArrowLeft"||s.key==="ArrowRight")&&(s.preventDefault(),o.nudge(s.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[])}const Yr=(e,t,n=Ma)=>({height:n.size.control,minHeight:n.size.control,px:1.5,borderRadius:n.radius.control,boxShadow:"none",...n.type.control,"&:hover":{boxShadow:"none"},"& .MuiButton-startIcon":{mr:.5,"& svg":{fontSize:18}},"&.MuiButton-outlined":{borderColor:e,"&:hover":{borderColor:t}}}),oi=(e=Ma)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),os={height:20,alignSelf:"center",mx:.5,my:0},as=(e,t=Ma)=>({height:t.size.control,boxSizing:"border-box",borderRadius:t.radius.control,border:`1px solid ${e}`,overflow:"hidden",bgcolor:"background.paper","& .MuiToggleButton-root":{border:"none",borderRadius:"0 !important",m:"0 !important",px:1.5,py:0,height:"100%",...t.type.control,color:"text.secondary","& + .MuiToggleButton-root":{borderLeft:`1px solid ${e}`},"&:hover":{bgcolor:"action.hover"},"&.Mui-selected, &.Mui-selected:hover":{bgcolor:"action.selected",color:"text.primary"}}}),Mo={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function lg({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:i,saving:s,onSave:o,savesTo:a="package",saveLabel:d,saveButton:f,actions:c,onAddTile:l,arrange:u,onExit:p,saveStatus:g}){const{theme:v}=qe(),b=cn(v.cardBorder),w=Cs(v.cardBorder,v.tileTitle);return m.jsxs(ft,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[u,l&&m.jsx(Ae,{variant:"outlined",startIcon:m.jsx(vi,{}),onClick:l,"aria-label":"Add tile",sx:Yr(b,w,v.ui),children:"Tile"}),l&&m.jsx(nr,{orientation:"vertical",sx:os}),m.jsx(Ot,{title:`Undo (${Sn}Z)`,children:m.jsx("span",{children:m.jsx($n,{"aria-label":"Undo",disabled:!e,onClick:n,sx:oi(v.ui),children:m.jsx(Pd,{fontSize:"small"})})})}),m.jsx(Ot,{title:`Redo (${Sn}⇧Z)`,children:m.jsx("span",{children:m.jsx($n,{"aria-label":"Redo",disabled:!t,onClick:r,sx:oi(v.ui),children:m.jsx(Dd,{fontSize:"small"})})})}),(c||o||p)&&m.jsx(nr,{orientation:"vertical",sx:os}),c,o&&g&&m.jsx(Id,{...g}),o?m.jsx(Ot,{title:i?`Save (${Sn}S) · ${d??Mo[a]}`:d??Mo[a],children:m.jsx("span",{children:m.jsx(Ae,{ref:f,variant:i?"contained":"outlined",disabled:!i||s,onClick:o,sx:{...Yr(b,w,v.ui),minWidth:88},children:s?"Saving…":i?"Save":"Saved"})})}):null,o&&m.jsx(_,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:s?"Saving":i?"Unsaved changes":"All changes saved"}),p&&m.jsx(jm,{label:"Close",icon:m.jsx(Ts,{}),onClick:p})]})}const cg=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Kl={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map",combo_chart:"Bar and line"};function Nd(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this tile's details":n==="unlisted"?"Not in the model's list, so its shape is unknown":void 0,i=e?.shape,s=o=>{if(t===o)return;if(o==="big_value")return e?.aggregateOnly===!0?void 0:i&&i.groupBys>0?"This view has a group by, so it is more than one row; big numbers need a view of totals only":r??"Needs results that are only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:r??"Needs a map chart set in the model";if(e?.chart===o)return;if(!i)return o==="combo_chart"?r??"Needs a view with a group by and exactly two totals: the first is drawn as bars, the second as a line":void 0;const a=`A ${Kl[o].toLowerCase()} chart`;switch(Um(o,i)){case"no_x_axis":return cg(a);case"combo_totals":return`A bar and line chart needs exactly two totals, the first drawn as bars and the second as a line; this view has ${i.totals}`;case"no_y_axis":return`This view has no total for the y-axis: ${a.toLowerCase()} needs at least one aggregate`;default:return}};return[{value:"default",label:"Default",hint:"As set in the model"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map","combo_chart"].map(o=>{const a=s(o);return{value:o,label:Kl[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Gl(e){return e.description??qm(e.name)}const dg={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",combo_chart:"a bar and line chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},Ci=(e,t)=>`${e}\0${t}`;function ug({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o,renderPreview:a}){const{theme:d}=qe(),f=d.ui,c=cn(d.cardBorder),l=S.useMemo(()=>n?.sources??[],[n]),[u,p]=S.useState(""),[g,v]=S.useState(),[b,w]=S.useState(""),[h,x]=S.useState("default"),y=S.useRef(null),k=S.useMemo(()=>{const D=new Set(t.sources.map(F=>F.base));return[...l].sort((F,E)=>Number(D.has(E.name))-Number(D.has(F.name)))},[l,t]),C=k.filter(D=>D.views.length>0),$=k.filter(D=>D.views.length===0),T=S.useMemo(()=>new Map(C.flatMap(D=>D.views.map(F=>[Ci(D.name,F.name),{source:D,view:F,key:Ci(D.name,F.name)}]))),[C]),j=S.useMemo(()=>C.map(D=>({key:D.name,label:D.name,...D.description?{detail:D.description}:{},entries:D.views.map(F=>({key:Ci(D.name,F.name),name:F.name,title:Gl(F),...F.chart?{chart:F.chart}:{}}))})),[C]),M=g===void 0?void 0:T.get(g);S.useEffect(()=>{if(!e)return;p(""),w(""),x("default");const D=C[0]?.views[0];v(D&&C[0]?Ci(C[0].name,D.name):void 0)},[e]);const I=M?[M.source.name,M.view.name].filter(D=>!wo(D)).map(D=>`"${D}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,N=M!==void 0&&I===void 0,R=M?Gl(M.view):"",L=h!=="default"&&M?{chart:h,chartCarried:M.view.chart?[M.view.chart]:[]}:{},B=(D=M)=>{if(!D||![D.source.name,D.view.name].every(wo))return;const F=D.key===M?.key,E=Vm(Math.ceil(r/2),r);s({base:D.source.name,modelPath:D.source.modelPath,...D.source.exporters?{exporters:D.source.exporters}:{},view:D.view.name,...F&&b.trim()?{label:b.trim()}:{},...F?L:{},...E!==void 0?{colspan:E}:{}})},q=M?Nd(M.view,h).filter(D=>D.value!=="custom"&&D.disabled!==!0):[];return m.jsx(Ta,{className:`${rt.dialog} ${rt.addTileDialog}`,open:e,onClose:i,maxWidth:"md",initialFocus:y,title:"Add a tile",description:"Pick what the tile shows from the model. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx(Ae,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx(Ae,{onClick:i,children:"Cancel"}),m.jsx(Ae,{variant:"contained",disabled:!N,onClick:()=>B(),children:"Add tile"})]}),children:m.jsxs(_,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${c}`,borderBottom:`1px solid ${c}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx(_,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(wm,{groups:j,query:u,onQuery:p,picked:M?.key,onPick:D=>{v(D),x("default")},onTake:D=>B(T.get(D)),searchRef:y,empty:m.jsx(ve,{variant:"body2",sx:{color:d.tileTitle,p:2},children:n?"This package's models have nothing to put on a tile yet.":"The package's sources are still loading."}),footer:$.length>0&&m.jsxs(ve,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",$.map(D=>D.name).join(", "),"."]})})}),m.jsx(_,{sx:D=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${D.palette.text.primary} 3%, ${D.palette.background.paper})`}),children:M?m.jsxs(m.Fragment,{children:[m.jsx(_,{"aria-label":"Preview",role:"region",sx:D=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${c}`,bgcolor:D.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${D.palette.background.paper})`}}),children:a?m.jsx(_,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:M.source.name,modelPath:M.source.modelPath,view:M.view.name,label:b.trim()||R,...h!=="default"?L:{},givens:M.source.givens})}):m.jsxs(_,{sx:D=>({flex:1,border:`1px solid ${c}`,borderRadius:f.radius.tile,bgcolor:D.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(km,{chart:M.view.chart}),m.jsxs(ve,{variant:"body2",children:[M.source.name," → ",M.view.name]})]})}),m.jsx(Zt,{size:"small",label:"Title",placeholder:R,value:b,onChange:D=>w(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs(_,{children:[m.jsx(ve,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx(Ed,{size:"small",exclusive:!0,value:h,"aria-label":"Chart",onChange:(D,F)=>{F!==null&&x(F)},sx:{...as(c,f),"& .MuiToggleButton-root":{...as(c,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:q.map(D=>m.jsx(ko,{value:D.value,children:D.label},D.value))}),m.jsx(ve,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:M.view.chart?`The model sets ${dg[M.view.chart]??"a chart"}.`:"The model sets no chart, so it shows as a table."})]}),I&&m.jsx(ve,{variant:"body2",color:"error",children:I})]}):m.jsx(ve,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}function hg(e,t,{modelPath:n,textHeld:r,widths:i,insertAt:s}){t.modelPath&&!r&&(e.imports=Fm(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Wd(e,t.base),a=Eo(e,o.name,t.view);e.tiles.splice(s??e.tiles.length,0,{name:a,source:o.name,declaration:{kind:"reference",from:t.view},...i&&t.colspan!==void 0?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Wd(e,t,{unscoped:n=!1}={}){const r=e.sources.find(a=>a.base===t&&(!n||!a.scopedBy?.length));if(r)return r;const i=new Set(e.sources.map(a=>a.name));let s=`${t}_tiles`;for(let a=2;i.has(s);a++)s=`${t}_tiles_${a}`;const o={name:s,base:t};return e.sources.push(o),o}function Eo(e,t,n){const r=new Set(e.tiles.filter(le).filter(s=>s.source===t).map(s=>s.name));let i=`${n}_tile`;for(let s=2;r.has(i);s++)i=`${n}_tile_${s}`;return i}function ls(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;case"query":return"It names a query, and a copy could not be told apart from it: the builder writes nothing about such a tile but its place.";default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function fg(e,t){const n=e.tiles[t];if(!n||!le(n)||ls(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...o}=structuredClone(n);r={...o,name:Eo(e,n.source,n.declaration.from)}}else{const s=e.sources.find(o=>o.name===n.source)??Wd(e,n.source,{unscoped:!0});r={name:Eo(e,s.name,n.name),source:s.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}const i=n.row!==void 0&&n.col!==void 0;return i&&(r={...r,row:(n.row??1)+ii(n),col:n.col,...n.rowspan!==void 0?{rowspan:n.rowspan}:{}}),e.tiles.splice(t+1,0,r),i&&(e.tiles=Ht(e.tiles,e.columns??um,t+1)),t+1}const Ti="self";function pg({open:e,document:t,source:n,givenNames:r,dashboards:i,tileLabel:s,onClose:o,onApply:a}){const{theme:d}=qe(),f=d.ui,[c,l]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const h=(t.drills??[]).filter(x=>x.source===n.name);l((n.dimensions??[]).map(x=>{const y=h.find(k=>k.name===x.name);return{name:x.name,expression:x.expression,to:y?.to??[],given:y?.given??""}}))},[e,n,t]);const u=(h,x)=>l(y=>y.map((k,C)=>{if(C!==h)return k;const $={...k};return x($),$})),p=[Ti,...i.filter(h=>h!==Ti)],g=h=>h===Ti?"This report":h,v=()=>{n&&(a(c.filter(h=>h.to.length>0).map(h=>({source:n.name,name:h.name,expression:h.expression,to:h.to,...h.given?{given:h.given}:{}}))),o())},b=cn(d.cardBorder),w=(h,x)=>u(h,y=>{x?y.to=y.lastTo?.length?y.lastTo:[Ti]:(y.lastTo=y.to,y.to=[])});return m.jsx(Ta,{className:`${rt.dialog} ${rt.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[s&&m.jsxs(_,{component:"span",sx:{fontWeight:f.type.label.fontWeight},children:[s," ·"," "]}),"A click on a table cell sets a filter to its value, on this report or on the one it opens. Bars, lines and points on a chart do not respond to a click. Clicks work in the report, not while you edit it."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx(Ae,{onClick:o,children:"Cancel"}),m.jsx(Ae,{variant:"contained",onClick:v,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx(ve,{variant:"body2",sx:{color:d.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx(_,{component:"code",children:n.name})," declares no dimensions of its own in this file. A click is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",m.jsx(_,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx(_,{role:"list","aria-label":"Dimensions",children:c.map((h,x)=>{const y=h.to.length>0;return m.jsxs(_,{role:"listitem",sx:{display:"grid",gridTemplateColumns:{xs:"auto minmax(0, 1fr)",sm:"auto minmax(0, 0.9fr) minmax(0, 1.6fr)"},alignItems:"center",columnGap:1.5,rowGap:1,py:1.25,borderTop:x===0?"none":`1px solid ${b}`},children:[m.jsx(ym,{size:"small",checked:y,onChange:k=>w(x,k.target.checked),slotProps:{input:{"aria-label":`${h.name} is clickable`}}}),m.jsxs(_,{sx:{minWidth:0},children:[m.jsx(_,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:mg(h.name)}),m.jsxs(_,{title:h.expression,sx:{...f.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[h.name," is ",h.expression]})]}),y?m.jsxs(ft,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...f.type.control},children:[m.jsx(_,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx(Zt,{select:!0,size:"small",value:h.to,inputProps:{"aria-label":`Where ${h.name} goes`},SelectProps:{multiple:!0,renderValue:k=>k.map(g).join(", ")},onChange:k=>u(x,C=>{const $=k.target.value,T=Array.isArray($)?$:String($).split(",").filter(Boolean);T.length===0&&(C.lastTo=C.to),C.to=T}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:p.map(k=>m.jsxs(Xe,{value:k,children:[m.jsx(yo,{size:"small",checked:h.to.includes(k),sx:{p:0,mr:1}}),m.jsx(Bt,{primary:g(k)})]},k))}),m.jsx(_,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs(Zt,{select:!0,size:"small",value:h.given,inputProps:{"aria-label":`Control ${h.name} sets`},SelectProps:{displayEmpty:!0,renderValue:k=>k===""?h.name:String(k)},onChange:k=>u(x,C=>{C.given=k.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx(Xe,{value:"",children:m.jsx(Bt,{primary:h.name,secondary:"Named like the dimension"})}),r.map(k=>m.jsx(Xe,{value:k,children:k},k))]})]}):m.jsx(ve,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},h.name)})})})}function mg(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const gg=mt(m.jsx("path",{d:"M12 4c4.41 0 8 3.59 8 8s-3.59 8-8 8-8-3.59-8-8 3.59-8 8-8m0-2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 13-4-4h8z"})),vg=mt(m.jsx("path",{d:"M11 7H2v2h9zm0 8H2v2h9zm5.34-4L12.8 7.46l1.41-1.41 2.12 2.12 4.24-4.24L22 5.34zm0 8-3.54-3.54 1.41-1.41 2.12 2.12 4.24-4.24L22 13.34z"})),xg=mt(m.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 16H5V10h14zm0-12H5V6h14zm-7 5h5v5h-5z"})),bg=mt(m.jsx("path",{d:"M19.5 9.5c-1.03 0-1.9.62-2.29 1.5h-2.92c-.39-.88-1.26-1.5-2.29-1.5s-1.9.62-2.29 1.5H6.79c-.39-.88-1.26-1.5-2.29-1.5C3.12 9.5 2 10.62 2 12s1.12 2.5 2.5 2.5c1.03 0 1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5s1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5 1.38 0 2.5-1.12 2.5-2.5s-1.12-2.5-2.5-2.5"})),yg=mt(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),wg=mt(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function kg(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of le(s)?s.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],i=new Set;for(const s of e.localGivens??[])i.add(s.name),r.push({name:s.name,...s.label===void 0?{}:{label:s.label},type:s.type,...s.suggest?{field:s.suggest.dimension}:{},origin:"dashboard",local:s,boundTiles:n.get(s.name)??0});for(const s of t)i.has(s.name)||(i.add(s.name),r.push({...s,origin:"model",boundTiles:n.get(s.name)??0}));for(const[s,o]of n)i.has(s)||r.push({name:s,origin:"model",boundTiles:o});return r}function cs(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function Sg(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function Xr(e,t){const n=Sg(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const i=new Set(["date","timestamp"]);return i.has(n)?i.has(r):n===r}function Co(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function $g(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const jg=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function Mg(e,t){const n=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",r=/^[A-Z_]/.test(n)?n:`F_${n}`,i=Md(r)?r:`${r}_FILTER`,s=new Set(t);if(!s.has(i))return i;for(let o=2;;o++)if(!s.has(`${i}_${o}`))return`${i}_${o}`}const Eg=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function Or(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const To=e=>le(e)&&!cr(e)&&e.declaration.kind!=="opaque";function Cg(e,t){return e.tiles.map(n=>{const r=(le(n)?n.filters??[]:[]).find(i=>i.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:cs(t.type)!==void 0?{op:cs(t.type)}:{}}})}function Tg(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!To(s))return;const o=(s.filters??[]).filter(d=>d.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?s.filters=a:delete s.filters})}function Og(e,t){const n=(e.localGivens??[]).filter(s=>s.name!==t.name),r=(e.localGivens??[]).findIndex(s=>s.name===t.name),i=[...n];i.splice(r>=0?r:i.length,0,t),e.localGivens=i}function Ag(e,t){for(const r of e.tiles){if(!le(r))continue;const i=(r.filters??[]).filter(s=>s.given!==t);i.length>0?r.filters=i:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Oo=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function Rg({open:e,document:t,control:n,available:r,takenNames:i=[],fieldsFor:s,onApply:o}){const a=S.useRef(n);e&&(a.current=n);const d=e?n:a.current,f=d!==void 0,[c,l]=S.useState({kind:"new"}),[u,p]=S.useState(""),[g,v]=S.useState("select"),[b,w]=S.useState(""),[h,x]=S.useState(""),[y,k]=S.useState([]),[C,$]=S.useState(!1),[T,j]=S.useState(!1),M=A=>t.sources.find(z=>z.name===A.source)?.base??A.source;S.useEffect(()=>{if(e)if(j(n!==void 0),n){l({kind:"existing",name:n.name}),p(n.label??"");const A=Cg(t,n);k(A);const z=A.filter(G=>G.include),K=new Set(z.map(G=>G.field));x(K.size===1?z[0].field:n.field??""),$(K.size>1)}else l({kind:"new"}),p(""),v("select"),x(""),w(new Date().toISOString().slice(0,10)),k(t.tiles.map(A=>({include:To(A),field:""}))),$(!1)},[e,n,t]);const I=S.useMemo(()=>[...(t.localGivens??[]).map(A=>A.name),...r.map(A=>A.name),...i],[t,r,i]),N=S.useMemo(()=>h.trim()?Mg(h.trim(),I):"",[h,I]),R=c.kind==="existing"?n??r.find(A=>A.name===c.name):N?{name:N,type:Or({name:N,label:u,kind:g,field:h}).type}:void 0,L=R?.type!==void 0&&!R.type.startsWith("filter<"),B=y.find(A=>A.include)?.op??cs(R?.type),q=(A,z)=>{j(!0),k(K=>K.map((G,ke)=>ke===A?{...G,...z}:G))},D=A=>{j(!0),k(z=>z.map(K=>({...K,op:A})))},F=A=>{const z=cs(A);k(K=>K.map(({op:G,...ke})=>z?{...ke,op:z}:ke))},E=A=>{j(!0),l({kind:"existing",name:A.name}),x(A.field??""),F(A.type)},O=A=>{j(!0),v(A),F(Or({name:"X",label:u,kind:A,field:h}).type)},W=t.tiles.map(To),U=W.filter(Boolean).length,V=y.filter((A,z)=>A.include&&W[z]).length,Y=t.tiles.filter((A,z)=>(y[z]?.include??!1)&&W[z]&&le(A)),re=Y.length>0?Y:t.tiles.filter((A,z)=>W[z]&&le(A)),H=S.useMemo(()=>{const A=new Map;let z=!1;for(const K of re){const G=s?.(K);if(G){z=!0;for(const ke of G)A.has(ke.name)||A.set(ke.name,ke)}}return z?[...A.values()]:void 0},[y,t.tiles,s]),ne=(()=>{const A=h.trim();for(const z of Y){const K=s?.(z);if(!K||K.some(G=>G.name===A))return M(z)}return Y[0]?M(Y[0]):t.sources[0]?.base})(),Q=A=>{j(!0),k(z=>z.map((K,G)=>({...K,include:A&&W[G]})))},ge=S.useMemo(()=>C?y:y.map(A=>({...A,field:h})),[C,y,h]),Z=A=>{for(const z of re){const K=s?.(z)?.find(G=>G.name===A.trim());if(K?.type)return K.type}},Re=A=>Xr(R?.type,A.type),De=(A,z)=>{if(A.trim()==="")return"Pick the field this filter compares.";const K=z?s?.(z):void 0;if(!K)return;const G=K.find(ke=>ke.name===A.trim());if(!G)return`Not a field of ${z?M(z):"the tiles' source"}.`;if(G.type&&!Xr(R?.type,G.type))return`${A.trim()} is ${Co(G.type)}; this filter compares ${Co(R?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},X=A=>{if(j(!0),x(A),f||c.kind!=="new")return;const z=Z(A),K=Or({name:"X",label:u,kind:g,field:A}).type;z&&!Xr(K,z)&&O($g(z))},we=A=>{const z=t.tiles[A];return z&&le(z)?z:void 0},ye=ge.map((A,z)=>A.include&&W[z]?De(A.field,we(z)):void 0),se=ye.every(A=>A===void 0),Pe=T?ye:ye.map(()=>{}),Ke=T&&!C&&V>0?Y.map(A=>De(h,A)).find(Boolean):void 0,Ie=R!==void 0&&se&&(c.kind==="existing"||h.trim()!==""&&N!==""),Qe=()=>{if(!(!R||!Ie))if(c.kind==="new")o(R.name,ge,Or({name:R.name,label:u.trim()||Oo(R.name),kind:g,field:h.trim(),...ne?{source:ne}:{},...b?{dateDefault:b}:{}}));else if(n?.origin==="dashboard"&&n.local){const A=u.trim(),z=A!==(n.local.label??"");o(R.name,ge,z?{...n.local,...A?{label:A}:{}}:void 0)}else o(R.name,ge)},Ze=f&&d.origin==="model";return{editing:f,shown:d,fromModel:Ze,source:c,setSource:l,label:u,setLabel:p,kind:g,dateDefault:b,setDateDefault:w,field:h,rows:y,setRows:k,perTile:C,setPerTile:$,newName:N,target:R,valueTyped:L,commonOp:B,setRow:q,setCommonOp:D,pickExisting:E,pickKind:O,bindable:W,bindableCount:U,included:V,commonFields:H,setAll:Q,accepts:Re,pickField:X,rowProblems:Pe,commonProblem:Ke,canApply:Ie,apply:Qe}}function Yl({value:e,onChange:t,fields:n,accepts:r,label:i,ariaLabel:s,error:o,helperText:a,disabled:d,autoFocus:f,placeholder:c,inputRef:l,sx:u}){const p=S.useMemo(()=>(n??[]).filter(v=>r?.(v)??!0).map(v=>v.name),[n,r]),g=S.useMemo(()=>new Map((n??[]).map(v=>[v.name,v.type])),[n]);return m.jsx(_m,{freeSolo:!0,size:"small",options:p,inputValue:e,onInputChange:(v,b)=>t(b),value:e,onChange:(v,b)=>t(typeof b=="string"?b:""),disabled:d,disableClearable:!0,renderOption:(v,b)=>S.createElement("li",{...v,key:b},m.jsx(Ql,{type:g.get(b)}),m.jsx(ve,{variant:"body2",sx:{flex:1,ml:1},children:b})),renderInput:v=>m.jsx(Zt,{...v,label:i,placeholder:c,autoFocus:f,...l?{inputRef:l}:{},error:o,helperText:a,InputLabelProps:{...v.InputLabelProps,shrink:!0},InputProps:{...v.InputProps,startAdornment:g.get(e.trim())?m.jsx(_,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Ql,{type:g.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":s}}),sx:u})}const Dg=e=>e&&le(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:e&&le(e)&&e.declaration.kind==="query"?{label:"Not bindable",reason:"It names a query, whose filters live in that query's own definition."}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function Pg({open:e,document:t,control:n,available:r,takenNames:i,fieldsFor:s,onClose:o,onApply:a,onRemove:d}){const{theme:f}=qe(),c=f.ui,{editing:l,shown:u,fromModel:p,source:g,setSource:v,label:b,setLabel:w,kind:h,dateDefault:x,setDateDefault:y,field:k,rows:C,setRows:$,perTile:T,setPerTile:j,newName:M,target:I,valueTyped:N,commonOp:R,setRow:L,setCommonOp:B,pickExisting:q,pickKind:D,bindable:F,bindableCount:E,included:O,commonFields:W,setAll:U,accepts:V,pickField:Y,rowProblems:re,commonProblem:H,canApply:ne,apply:Q}=Rg({open:e,document:t,control:n,available:r,...i?{takenNames:i}:{},fieldsFor:s,onApply:a}),ge=S.useRef(null),Z=cn(f.cardBorder),Re=Cs(f.cardBorder,f.tileTitle),[De,X]=S.useState(!1),[we,ye]=S.useState(!1);S.useEffect(()=>{e?ye(!0):X(!1)},[e]),S.useEffect(()=>{we&&(ye(!1),X(l&&O<E))},[we]),S.useEffect(()=>{T&&X(!0)},[T]);const se=W?.find(A=>A.name===k.trim())?.type,Pe=A=>{if(!se)return;const z=Or({name:"X",label:b,kind:A,field:k}).type;return Xr(z,se)?void 0:`${k.trim()} is ${Co(se)}, which this control cannot filter.`},Ke=b.trim()||(M?Oo(M):"Filter"),Ie=h==="number"?"Any":h==="date"?x?new Date(`${x}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Qe={...as(Z,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...as(Z,c)["& .MuiToggleButton-root"],textTransform:"none"}},Ze=(A,z,K)=>m.jsx(Zt,{select:!0,size:"small",label:"Compares",value:A??">=",onChange:G=>z(G.target.value),inputProps:{"aria-label":K},sx:{width:130},children:jg.filter(G=>G.op!=="~").map(G=>m.jsx(Xe,{value:G.op,children:G.label},G.op))});return m.jsx(Ta,{className:`${rt.dialog} ${rt.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:ge},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs(_,{component:"span",sx:{fontFamily:c.font.mono},children:["$",u.name]}),p?" · declared in the model, so its label and options are set there":" · declared in this report"]}):"A filter on the page, and the tiles it filters.",actions:m.jsxs(m.Fragment,{children:[l&&m.jsx(Ae,{color:"error",startIcon:m.jsx(vm,{}),onClick:()=>d(u.name),sx:A=>({mr:"auto",color:gm(A)}),children:"Remove filter"}),m.jsx(Ae,{onClick:o,children:"Cancel"}),m.jsx(Ot,{title:ne||I===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx(Ae,{variant:"contained",onClick:Q,disabled:!ne,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs(ft,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs(Ed,{exclusive:!0,size:"small",value:g.kind,onChange:(A,z)=>{z==="new"?v({kind:"new"}):z==="existing"&&r[0]&&q(r[0])},"aria-label":"Where the filter comes from",sx:Qe,children:[m.jsx(ko,{value:"new",children:"New in this report"}),m.jsx(ko,{value:"existing",children:"From the model"})]}),!l&&g.kind==="existing"?m.jsx(Zt,{select:!0,size:"small",label:"Filter",value:g.name,onChange:A=>{const z=r.find(K=>K.name===A.target.value);z&&q(z)},children:r.map(A=>m.jsxs(Xe,{value:A.name,children:[A.label??A.name,m.jsxs(ve,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",A.name]})]},A.name))}):null,m.jsxs(_,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:p?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!T&&m.jsx(Yl,{value:k,onChange:Y,fields:W,accepts:V,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:ge,error:H!==void 0,helperText:H??(!l&&M?`Declared as $${M}`:void 0)}),!p&&m.jsx(Zt,{size:"small",label:"Label",placeholder:M?Oo(M):"",value:b,onChange:A=>w(A.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),N&&!T&&Ze(R,B,"Comparison"),!l&&g.kind==="new"&&m.jsxs(_,{children:[m.jsx(Xl,{children:"Control"}),m.jsx(_,{role:"radiogroup","aria-label":"Filter kind",sx:{display:"grid",gridTemplateColumns:{xs:"repeat(3, minmax(0, 1fr))",sm:"repeat(5, minmax(0, 1fr))"},gap:1},children:Eg.map(A=>{const z=A.kind===h,K=Pe(A.kind);return m.jsx(Ot,{title:K??A.hint,describeChild:!0,children:m.jsxs(hd,{role:"radio","aria-checked":z,"aria-label":A.label,"aria-disabled":K!==void 0,onClick:()=>{K===void 0&&D(A.kind)},sx:G=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${z?f.accent:Z}`,boxShadow:z?`0 0 0 1px ${f.accent}`:"none",bgcolor:z?`color-mix(in srgb, ${f.accent} 6%, ${G.palette.background.paper})`:G.palette.background.paper,color:z?f.accent:G.palette.text.secondary,opacity:K?.45:1,cursor:K?"default":"pointer",transition:`border-color ${nt}, background-color ${nt}`,"&:hover":K||z?{}:{borderColor:Re}}),children:[m.jsx(Ng,{kind:A.kind}),m.jsx(_,{component:"span",sx:{...c.type.caption,fontWeight:z?600:500,color:z?f.accent:"text.primary",textAlign:"center"},children:Ig[A.kind]})]})},A.kind)})}),h==="date"&&m.jsx(Zt,{size:"small",type:"date",label:"Starts at",value:x,onChange:A=>y(A.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs(_,{sx:{border:`1px solid ${Z}`,borderRadius:c.radius.tile,overflow:"hidden"},children:[m.jsxs(ft,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(wg,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs(ve,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx(_,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:O===E&&E>0?`Applies to all ${O} tile${O===1?"":"s"}`:`Applies to ${O} of ${E} tile${E===1?"":"s"}`}),!T&&k.trim()!==""&&O>0&&m.jsxs(_,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx(_,{component:"span",sx:{...c.type.code},children:k.trim()})]})]}),!T&&m.jsx(Ae,{size:"small","aria-expanded":De,onClick:()=>X(A=>!A),children:De?"Done choosing":"Choose tiles"})]}),m.jsx(So,{in:De,unmountOnExit:!0,children:m.jsxs(_,{sx:{borderTop:`1px solid ${Z}`,px:.5,pb:1},children:[m.jsxs(ft,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx(yo,{size:"small",checked:E>0&&O===E,indeterminate:O>0&&O<E,disabled:E===0,onChange:A=>U(A.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx(ve,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx(Ae,{size:"small",onClick:()=>{T||$(A=>A.map(z=>({...z,field:k}))),j(A=>!A)},children:T?"Same field for all":"Adjust per tile"})]}),m.jsx(ft,{sx:{gap:T?1:0},children:t.tiles.map((A,z)=>{if(!le(A))return null;const K=C[z],G=A.label??A.name,ke=T?re[z]:void 0;return m.jsxs(ft,{direction:"row",sx:{gap:1,alignItems:T?"flex-start":"center",opacity:F[z]?1:.6},children:[m.jsx(yo,{size:"small",disabled:!F[z],checked:(K?.include??!1)&&F[z],inputProps:{"aria-label":`Filter ${G}`},onChange:je=>L(z,{include:je.target.checked})}),m.jsx(ve,{variant:"body2",sx:{flex:1,minWidth:0,pt:T?1:0},noWrap:!0,children:G}),F[z]?T&&m.jsxs(m.Fragment,{children:[N&&Ze(K?.op,je=>L(z,{op:je}),`Comparison for ${G}`),m.jsx(Yl,{value:K?.field??"",onChange:je=>L(z,{field:je}),fields:s?.(A),accepts:V,label:"Field",ariaLabel:`Field for ${G}`,disabled:!K?.include,error:ke!==void 0,helperText:ke,sx:{width:220,pr:1}})]}):m.jsx(ve,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:Dg(t.tiles[z]).reason})]},fe(A))})})]})})]}),O===0&&m.jsx(ve,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!p&&m.jsxs(_,{children:[m.jsx(Xl,{children:"Preview"}),m.jsx(_,{sx:A=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:A.palette.action.hover}),children:m.jsxs(_,{"aria-hidden":!0,sx:A=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${Z}`,bgcolor:A.palette.background.paper,...c.type.control}),children:[m.jsx(_,{component:"span",sx:{color:"text.secondary"},children:Ke}),m.jsx(_,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:Ie}),m.jsx(Sa,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function Xl({children:e}){const t=qe().theme.ui;return m.jsx(ve,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const Ig={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function Ng({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(gg,{sx:t});case"multiselect":return m.jsx(vg,{sx:t});case"text":return m.jsx(yg,{sx:t});case"number":return m.jsx(bg,{sx:t});case"date":return m.jsx(xg,{sx:t})}}function Ql({type:e}){const t=e?.replace(/_type$/,""),n=t==="string"?"Abc":t==="number"?"#":t==="date"||t==="timestamp"?"Date":t==="boolean"?"T/F":void 0,r=qe().theme.ui;return n?m.jsx(_,{component:"span","aria-hidden":!0,sx:i=>({fontFamily:r.font.mono,fontSize:10,fontWeight:r.type.label.fontWeight,color:i.palette.text.secondary,bgcolor:i.palette.action.hover,borderRadius:"4px",px:.5,py:.25,minWidth:22,textAlign:"center",flex:"none"}),children:n}):null}const Zl=mt(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function zd(e,t,n,r){const[i,s]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&s(structuredClone(e))},[t,e]),{draft:i,patch:o=>s(a=>{if(a===void 0)return a;const d=structuredClone(a);return o(d),d}),apply:o=>{if(i===void 0)return;const a=structuredClone(i);o(a),s(a),JSON.stringify(a)!==JSON.stringify(e)&&n(a)},close:()=>{i!==void 0&&e!==void 0&&JSON.stringify(i)!==JSON.stringify(e)&&n(i),r()},discard:()=>s(void 0)}}const Wg=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,zg=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Lg="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",Fg="Declared on its source, so its chart is set in the model.",Bg="It names a query, so its chart is set where that query is declared.";function _g({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:i,onDuplicate:s,duplicateBlocked:o,view:a,viewStatus:d}){const{theme:f}=qe(),c=f.ui,{draft:l,apply:u,patch:p,close:g}=zd(t,e!==null,r,n),[v,b]=S.useState(void 0),w=l!==void 0&&le(l)?l:void 0,h=w!==void 0&&!cr(w),x=E=>u(O=>{le(O)&&E(O)}),y=S.useRef(void 0),k=S.useRef(null),C=e!==null;S.useEffect(()=>{C?y.current=t&&le(t)?t.chart:void 0:b(void 0)},[C]);const $=w?.chart??"default",T=Nd(a,$,d),j=w?w.declaration.kind==="query"?Bg:h?w.chart==="custom"?Wg(w.chartLines):void 0:Fg:void 0,M=E=>x(O=>{const W=y.current;E===(W??"default")?(W===void 0?delete O.chart:O.chart=W,delete O.chartCarried):(O.chart=E,a?O.chartCarried=a.chart?[a.chart]:[]:delete O.chartCarried)}),I=h?i?void 0:"Its source declares no dimension a click could filter by.":void 0,N=$==="default"?a?.chart:$,R=N!==void 0&&zg.has(N)?Lg:void 0,L=E=>O=>b({kind:E,anchor:O.currentTarget}),B=j??(N===void 0||!qg.has(N)?"Only a bar, line, scatter or bar and line chart has a color to set.":void 0),q=Array.from(new Set(f.series.map(wd).filter(E=>E!==void 0))).slice(0,8),D=E=>x(O=>{E===void 0?delete O.color:O.color=E.toLowerCase()}),F=(E,O,W)=>m.jsxs(m.Fragment,{children:[m.jsx(Bt,{primary:E,...W?{secondary:W}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),O&&m.jsx(ve,{variant:"body2",sx:{color:"text.secondary",ml:2},children:O})]});return m.jsxs(m.Fragment,{children:[m.jsxs(Xn,{className:rt.menu,open:e!==null&&l!==void 0,anchorEl:e,onClose:g,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":w?vt(w):"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:c.radius.menu,border:`1px solid ${cn(f.cardBorder)}`,boxShadow:c.shadow.menu}}},children:[w&&m.jsxs(Xe,{"aria-haspopup":"menu","aria-expanded":v?.kind==="chart",disabled:j!==void 0,onClick:L("chart"),onKeyDown:E=>{E.key==="ArrowRight"&&j===void 0&&b({kind:"chart",anchor:E.currentTarget})},children:[F("Chart",j?void 0:T.find(E=>E.value===$)?.label,j),m.jsx(Zl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),w&&j===void 0&&m.jsxs(Xe,{"aria-haspopup":"menu","aria-expanded":v?.kind==="color",disabled:B!==void 0,onClick:L("color"),onKeyDown:E=>{E.key==="ArrowRight"&&B===void 0&&b({kind:"color",anchor:E.currentTarget})},children:[F("Color",B?void 0:w.color??"Theme",B),!B&&m.jsx(Gs,{color:w.color??f.series[0],trailing:!0}),m.jsx(Zl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),h&&m.jsx(Xe,{"aria-haspopup":"dialog",disabled:I!==void 0,onClick:()=>{g(),i?.()},children:F("Clickable cells…",void 0,I??R)}),w&&s&&m.jsx(Xe,{disabled:o!==void 0,onClick:()=>{g(),s()},children:F("Duplicate",void 0,o)}),w?.declaration.kind==="opaque"&&m.jsxs(ve,{variant:"body2",sx:{color:f.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",w.declaration.why,", so a filter has no single place to go."]}),w&&m.jsx(nr,{}),w&&m.jsx(_,{"aria-hidden":!0,sx:{px:2,py:.5,...c.type.code,color:"text.secondary"},children:vt(w).replace("->","→")})]}),m.jsx(Xn,{className:rt.menu,open:v?.kind==="chart",anchorEl:v?.anchor??null,onClose:()=>b(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:E=>{E.key==="ArrowLeft"&&(E.preventDefault(),b(void 0))}},children:T.filter(E=>E.value!=="custom").map(E=>m.jsxs(Xe,{role:"menuitemradio","aria-checked":E.value===$,disabled:E.disabled===!0,onClick:()=>{M(E.value),b(void 0)},children:[m.jsx(Bt,{primary:E.label,...E.reason??E.hint?{secondary:E.reason??E.hint}:{}}),E.value===$&&m.jsx(kd,{sx:{minWidth:0,ml:2},children:m.jsx(Ts,{fontSize:"small",sx:{color:f.accent}})})]},E.value))}),m.jsxs(Xn,{className:rt.menu,open:v?.kind==="color",anchorEl:v?.anchor??null,onClose:()=>b(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,"aria-label":"Color",onKeyDown:E=>{E.key==="ArrowLeft"&&(E.preventDefault(),b(void 0))}},children:[m.jsxs(Xe,{role:"menuitemradio","aria-checked":w?.color===void 0,onClick:()=>{D(void 0),b(void 0)},children:[m.jsx(Gs,{color:f.series[0]}),m.jsx(Bt,{primary:"Theme",secondary:"The page's own colors"}),w?.color===void 0&&m.jsx(Jl,{color:f.accent})]}),q.map(E=>m.jsxs(Xe,{role:"menuitemradio","aria-checked":w?.color===E.toLowerCase(),onClick:()=>{D(E),b(void 0)},children:[m.jsx(Gs,{color:E}),m.jsx(Bt,{primary:E.toLowerCase()}),w?.color===E.toLowerCase()&&m.jsx(Jl,{color:f.accent})]},E)),m.jsx(nr,{}),m.jsxs(Xe,{component:"label","aria-checked":w?.color!==void 0&&!q.some(E=>E.toLowerCase()===w.color),role:"menuitemradio",onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),k.current?.click())},children:[m.jsx("input",{ref:k,type:"color","aria-label":"Other color",value:w?.color??Hg(f.series[0]),onChange:E=>{const O=E.target.value;xm(O)&&p(W=>{le(W)&&(W.color=O.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx(Bt,{primary:"Other color…"})]})]})]})}const qg=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Hg=e=>(e&&wd(e))??"#000000";function Gs({color:e,trailing:t=!1}){return m.jsx(_,{"aria-hidden":!0,"data-swatch":t?"trailing":"leading",sx:{width:14,height:14,borderRadius:"3px",bgcolor:e,border:"1px solid rgba(0,0,0,0.15)",...t?{ml:1}:{mr:1.5},flex:"none"}})}function Jl({color:e}){return m.jsx(kd,{sx:{minWidth:0,ml:2},children:m.jsx(Ts,{fontSize:"small",sx:{color:e}})})}const As=e=>e.label??bm(vt(e));function Ug({editor:e,catalog:t,columns:n,dashboards:r,bindings:i,tiles:s,drillSource:o,setDrillSource:a,exitDialog:d,renderViewPreview:f,takenGivenNames:c}){const{filterDialog:l,setFilterDialog:u}=i,{menu:p,setMenu:g}=s,[v,b]=S.useState(),w=p===void 0?void 0:e.document.tiles[p.index],h=w&&le(w)?w:void 0,x=(()=>{if(!h||!t)return;const y=t.documentViews?.get(h.source??"")?.get(h.name);if(y&&e.document.sources.some($=>$.name===h.source))return y;if(h.declaration.kind==="inline"||h.declaration.kind==="opaque")return;const k=e.document.sources.find($=>$.name===h.source)?.base??h.source,C=h.declaration.kind==="reference"?h.declaration.from:h.name;return t.sources.find($=>$.name===k)?.views.find($=>$.name===C)})();return m.jsxs(m.Fragment,{children:[m.jsx(Pg,{open:l!==void 0,document:e.document,...l?.control?{control:l.control}:{},available:i.available,...c?{takenNames:c}:{},...t?{fieldsFor:i.fieldsFor}:{},onClose:()=>u(void 0),onApply:i.applyFilter,onRemove:i.dropControl}),m.jsx(_g,{anchor:p?.anchor??null,tile:p===void 0?void 0:e.document.tiles[p.index],onClose:()=>g(void 0),onCommit:y=>{const k=p?.index;if(k===void 0)return;const C=ig(y);e.update($=>{$.tiles[k]=C,C!==y&&rn($.tiles)&&($.tiles=Ht($.tiles,n,k))})},view:x,...x===void 0&&h?{viewStatus:t?"unlisted":"loading"}:{},onDuplicate:()=>{p&&s.duplicate(p.index)},...h&&ls(h)!==void 0?{duplicateBlocked:ls(h)}:{},...(e.document.sources.find(y=>y.name===h?.source)?.dimensions?.length??0)>0?{onDrills:()=>{b(h?As(h):void 0),a(h?.source)}}:{}}),m.jsx(pg,{open:o!==void 0,document:e.document,source:e.document.sources.find(y=>y.name===o),givenNames:i.controlList.map(y=>y.name),dashboards:r??[],...v?{tileLabel:v}:{},onClose:()=>a(void 0),onApply:y=>e.update(k=>{const C=[...(k.drills??[]).filter($=>$.source!==o),...y];C.length===0?delete k.drills:k.drills=C})}),m.jsx(Op,{...d}),m.jsx(ug,{open:s.addingTile,document:e.document,catalog:t,columns:n,onClose:s.closeAdd,onAdd:s.addTile,onAddText:s.addText,...f?{renderPreview:f}:{}})]})}var Vg=Symbol.for("preact-signals");function Rs(){if(_t>1)_t--;else{var e,t=!1;for((function(){var i=us;for(us=void 0;i!==void 0;){var s=i.S;if(s.v===i.v)for(var o=s.t;o!==void 0;o=o.x)o.i===i.i&&(o.i=s.i);i=i.o}})();Zr!==void 0;){var n=Zr;for(Zr=void 0,ds++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Fd(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(ds=0,_t--,t)throw e}}function Oe(e){if(_t>0)return e();Ao=++Kg,_t++;try{return e()}finally{Rs()}}var Qr,Se=void 0;function oe(e){var t=Se,n=Qr;Se=void 0,Qr=void 0;try{return e()}finally{Se=t,Qr=n}}var Zr=void 0,_t=0,ds=0,Kg=0,Ao=0,us=void 0,hs=0;function Ld(e){if(Se!==void 0){var t=e.n;if(t===void 0||t.t!==Se)return t={i:0,S:e,p:Se.s,n:void 0,t:Se,e:void 0,x:void 0,r:t},Se.s!==void 0&&(Se.s.n=t),Se.s=t,e.n=t,32&Se.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=Se.s,t.n=void 0,Se.s.n=t,Se.s=t),t}}function dt(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}dt.prototype.brand=Vg;dt.prototype.h=function(){return!0};dt.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:oe(function(){var r;(r=t.W)==null||r.call(t)}))};dt.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&oe(function(){var i;(i=t.Z)==null||i.call(t)}))}};dt.prototype.subscribe=function(e){var t=this;return $t(function(){var n=t.value;oe(function(){return e(n)})},{name:"sub"})};dt.prototype.valueOf=function(){return this.value};dt.prototype.toString=function(){return this.value+""};dt.prototype.toJSON=function(){return this.value};dt.prototype.peek=function(){var e=this;return oe(function(){return e.value})};Object.defineProperty(dt.prototype,"value",{get:function(){var e=Ld(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ds>100)throw new Error("Cycle detected");(function(n){_t!==0&&ds===0&&n.l!==Ao&&(n.l=Ao,us={S:n,v:n.v,i:n.i,o:us})})(this),this.v=e,this.i++,hs++,_t++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Rs()}}}});function dr(e,t){return new dt(e,t)}function Fd(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Bd(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function _d(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function En(e,t){dt.call(this,void 0,t),this.x=e,this.s=void 0,this.g=hs-1,this.f=4}En.prototype=new dt;En.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===hs))return!0;if(this.g=hs,this.f|=1,this.i>0&&!Fd(this))return this.f&=-2,!0;var e=Se;try{Bd(this),Se=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return Se=e,_d(this),this.f&=-2,!0};En.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}dt.prototype.S.call(this,e)};En.prototype.U=function(e){if(this.t!==void 0&&(dt.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};En.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(En.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Ld(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function ec(e,t){return new En(e,t)}function qd(e){var t=e.m;if(e.m=void 0,typeof t=="function"){_t++;var n=Se;Se=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Ra(e),r}finally{Se=n,Rs()}}}function Ra(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,qd(e)}function Gg(e){if(Se!==this)throw new Error("Out-of-order effect");_d(this),Se=e,this.f&=-2,8&this.f&&Ra(this),Rs()}function ur(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Qr&&Qr.push(this)}ur.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};ur.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,qd(this),Bd(this),_t++;var e=Se;return Se=this,Gg.bind(this,e)};ur.prototype.N=function(){2&this.f||(this.f|=2,this.u=Zr,Zr=this)};ur.prototype.d=function(){this.f|=8,1&this.f||Ra(this)};ur.prototype.dispose=function(){this.d()};function $t(e,t){var n=new ur(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Yg=Object.create,Da=Object.defineProperty,Xg=Object.defineProperties,Qg=Object.getOwnPropertyDescriptor,Zg=Object.getOwnPropertyDescriptors,tc=Object.getOwnPropertySymbols,Jg=Object.prototype.hasOwnProperty,ev=Object.prototype.propertyIsEnumerable,tv=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),hr=e=>{throw TypeError(e)},Ro=(e,t,n)=>t in e?Da(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nv=(e,t)=>{for(var n in t||(t={}))Jg.call(t,n)&&Ro(e,n,t[n]);if(tc)for(var n of tc(t))ev.call(t,n)&&Ro(e,n,t[n]);return e},rv=(e,t)=>Xg(e,Zg(t)),nc=(e,t)=>Da(e,"name",{value:t,configurable:!0}),iv=e=>{var t;return[,,,Yg((t=void 0)!=null?t:null)]},Hd=["class","method","getter","setter","accessor","field","value","get","set"],Ar=e=>e!==void 0&&typeof e!="function"?hr("Function expected"):e,sv=(e,t,n,r,i)=>({kind:Hd[e],name:t,metadata:r,addInitializer:s=>n._?hr("Already initialized"):i.push(Ar(s||null))}),Ud=(e,t)=>Ro(t,tv("metadata"),e[3]),un=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},fr=(e,t,n,r,i,s)=>{var o,a,d,f,c,l=t&7,u=!!(t&8),p=!!(t&16),g=l>3?e.length+1:l?u?1:2:0,v=Hd[l+5],b=l>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),h=l&&(!p&&!u&&(i=i.prototype),l<5&&(l>3||!p)&&Qg(l<4?i:{get[n](){return yt(this,s)},set[n](y){return Xt(this,s,y)}},n));l?p&&l<4&&nc(s,(l>2?"set ":l>1?"get ":"")+n):nc(i,n);for(var x=r.length-1;x>=0;x--)f=sv(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>ov(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?yt:av)(y,i,l^4?s:h.get):y=>y[n]),l>2&&(c.set=p?(y,k)=>Xt(y,i,k,l^4?s:h.set):(y,k)=>y[n]=k)),a=(0,r[x])(l?l<4?p?s:h[v]:l>4?void 0:{get:h.get,set:h.set}:i,f),d._=1,l^4||a===void 0?Ar(a)&&(l>4?b.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?hr("Object expected"):(Ar(o=a.get)&&(h.get=o),Ar(o=a.set)&&(h.set=o),Ar(o=a.init)&&b.unshift(o));return l||Ud(e,i),h&&Da(i,n,h),p?l^4?s:h:i},Pa=(e,t,n)=>t.has(e)||hr("Cannot "+n),ov=(e,t)=>Object(t)!==t?hr('Cannot use the "in" operator on this value'):e.has(t),yt=(e,t,n)=>(Pa(e,t,"read from private field"),n?n.call(e):t.get(e)),Rr=(e,t,n)=>t.has(e)?hr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Xt=(e,t,n,r)=>(Pa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),av=(e,t,n)=>(Pa(e,t,"access private method"),n);function Do(e,t){if(t){let n;return ec(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return ec(e)}function Ct(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((n,r)=>!Ct(n,t[r]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(i=>!Ct(e[i],t[i]))}return!1}function ae({get:e},t){return{init(n){return dr(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function ze(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Do(e.bind(this)),n.set(this,r)),r.value}}function Ys(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),i=Object.getOwnPropertyDescriptor(r,n.name);i&&Object.defineProperty(r,n.name,rv(nv({},i),{enumerable:e}))})}}function xi(...e){const t=e.map(n=>$t(n));return()=>t.forEach(n=>n())}var Vd,Kd,Gd,Yd,Xd,Qd,ot,Ia,Xs,Po,Io,tt,Na,Qs,Zd,No,Wa,Zs,Wo,zo;Qd=[ae],Xd=[ae],Yd=[ae],Gd=[Ys()],Kd=[Ys()],Vd=[Ys()];var Cn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,un(ot,5,this),Rr(this,tt),Rr(this,Ia,un(ot,8,this)),un(ot,11,this),Rr(this,Na,un(ot,12,this)),un(ot,15,this),Rr(this,Wa,un(ot,16,this)),un(ot,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return yt(this,tt,Wo)}get initial(){return yt(this,tt,Po)}get previous(){return yt(this,tt,Zd)}set current(e){const t=oe(()=>yt(this,tt,Wo));e&&t&&this.equals(t,e)||Oe(()=>{yt(this,tt,Po)||Xt(this,tt,e,Io),Xt(this,tt,t,No),Xt(this,tt,e,zo)})}reset(e=this.defaultValue){Oe(()=>{Xt(this,tt,void 0,No),Xt(this,tt,e,Io),Xt(this,tt,e,zo)})}};ot=iv();Ia=new WeakMap;tt=new WeakSet;Na=new WeakMap;Wa=new WeakMap;Xs=fr(ot,20,"#initial",Qd,tt,Ia),Po=Xs.get,Io=Xs.set;Qs=fr(ot,20,"#previous",Xd,tt,Na),Zd=Qs.get,No=Qs.set;Zs=fr(ot,20,"#current",Yd,tt,Wa),Wo=Zs.get,zo=Zs.set;fr(ot,2,"current",Gd,Cn);fr(ot,2,"initial",Kd,Cn);fr(ot,2,"previous",Vd,Cn);Ud(ot,Cn);function Js(e){return oe(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var hn,lv=class{constructor(){Rr(this,hn,new WeakMap)}get(e,t){var n;return e?(n=yt(this,hn).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return yt(this,hn).has(e)||yt(this,hn).set(e,new Map),(r=yt(this,hn).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=yt(this,hn).get(e))==null?void 0:t.clear():void 0}};hn=new WeakMap;var cv=Object.create,Jd=Object.defineProperty,dv=Object.getOwnPropertyDescriptor,rc=Object.getOwnPropertySymbols,uv=Object.prototype.hasOwnProperty,hv=Object.prototype.propertyIsEnumerable,eu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ds=e=>{throw TypeError(e)},ic=Math.pow,Lo=(e,t,n)=>t in e?Jd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fv=(e,t)=>{for(var n in t||(t={}))uv.call(t,n)&&Lo(e,n,t[n]);if(rc)for(var n of rc(t))hv.call(t,n)&&Lo(e,n,t[n]);return e},pv=e=>{var t;return[,,,cv((t=e?.[eu("metadata")])!=null?t:null)]},tu=["class","method","getter","setter","accessor","field","value","get","set"],nu=e=>e!==void 0&&typeof e!="function"?Ds("Function expected"):e,mv=(e,t,n,r,i)=>({kind:tu[e],name:t,metadata:r,addInitializer:s=>n._?Ds("Already initialized"):i.push(nu(s||null))}),gv=(e,t)=>Lo(t,eu("metadata"),e[3]),vv=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},ru=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=tu[c+5],v=e[p]||(e[p]=[]),b=(i=i.prototype,dv(i,n)),w=r.length-1;w>=0;w--)d=mv(c,n,a={},e[3],v),d.static=l,d.private=u,f=d.access={has:h=>n in h},f.get=h=>h[n],o=(0,r[w])(b[g],d),a._=1,nu(o)&&(b[g]=o);return b&&Jd(i,n,b),i},iu=(e,t,n)=>t.has(e)||Ds("Cannot "+n),xv=(e,t,n)=>(iu(e,t,"read from private field"),t.get(e)),bv=(e,t,n)=>t.has(e)?Ds("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),yv=(e,t,n,r)=>(iu(e,t,"write to private field"),t.set(e,n),n),wt=class Fo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Fo(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Fo(t,n)}},Nt=class fn{constructor(t,n,r,i){this.left=t,this.top=n,this.width=r,this.height=i,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:i,width:s,height:o,scale:a}=this,d=new fn(i+t,r+n,s,o);return d.scale=fv({},a),d}get boundingRectangle(){const{width:t,height:n,left:r,top:i,right:s,bottom:o}=this;return{width:t,height:n,left:r,top:i,right:s,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:i}=this;return new wt((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof fn))return!1;const{left:n,top:r,width:i,height:s}=this;return n===t.left&&r===t.top&&i===t.width&&s===t.height}containsPoint(t){const{top:n,left:r,bottom:i,right:s}=this;return n<=t.y&&t.y<=i&&r<=t.x&&t.x<=s}intersectionArea(t){return t instanceof fn?wv(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:i}){return new fn(n,t,r,i)}static delta(t,n,r={x:"center",y:"center"}){const i=(s,o)=>{const a=r[o],d=o==="x"?s.left:s.top,f=o==="x"?s.width:s.height;return a=="start"?d:a=="end"?d+f:d+f/2};return wt.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return fn.from(t).intersectionRatio(fn.from(n))}};function wv(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),o=i-r,a=s-n;return r<i&&n<s?o*a:0}var su,ou,Bo,_i,bi,Ps=class extends(Bo=Cn,ou=[ze],su=[ze],Bo){constructor(e){const t=wt.from(e);super(t,(n,r)=>wt.equals(n,r)),vv(bi,5,this),bv(this,_i,0),this.velocity={x:0,y:0}}get delta(){return wt.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=wt.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-xv(this,_i),o=a=>Math.round(a/s*100);Oe(()=>{yv(this,_i,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(wt.from(e)),this.velocity={x:0,y:0}}};bi=pv(Bo);_i=new WeakMap;ru(bi,2,"delta",ou,Ps);ru(bi,2,"direction",su,Ps);gv(bi,Ps);function _o({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(ic(r,2)+ic(i,2))>n:"x"in n&&"y"in n?r>n.x&&i>n.y:"x"in n?r>n.x:"y"in n?i>n.y:!1}var au=(e=>(e.Horizontal="x",e.Vertical="y",e))(au||{}),lu=Object.values(au),kv=Object.create,za=Object.defineProperty,Sv=Object.defineProperties,$v=Object.getOwnPropertyDescriptor,jv=Object.getOwnPropertyDescriptors,fs=Object.getOwnPropertySymbols,cu=Object.prototype.hasOwnProperty,du=Object.prototype.propertyIsEnumerable,uu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),pr=e=>{throw TypeError(e)},qo=(e,t,n)=>t in e?za(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,La=(e,t)=>{for(var n in t||(t={}))cu.call(t,n)&&qo(e,n,t[n]);if(fs)for(var n of fs(t))du.call(t,n)&&qo(e,n,t[n]);return e},Fa=(e,t)=>Sv(e,jv(t)),sc=(e,t)=>za(e,"name",{value:t,configurable:!0}),hu=(e,t)=>{var n={};for(var r in e)cu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&fs)for(var r of fs(e))t.indexOf(r)<0&&du.call(e,r)&&(n[r]=e[r]);return n},mr=e=>{var t;return[,,,kv((t=e?.[uu("metadata")])!=null?t:null)]},fu=["class","method","getter","setter","accessor","field","value","get","set"],Dr=e=>e!==void 0&&typeof e!="function"?pr("Function expected"):e,Mv=(e,t,n,r,i)=>({kind:fu[e],name:t,metadata:r,addInitializer:s=>n._?pr("Already initialized"):i.push(Dr(s||null))}),Tn=(e,t)=>qo(t,uu("metadata"),e[3]),te=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},ce=(e,t,n,r,i,s)=>{var o,a,d,f,c,l=t&7,u=!!(t&8),p=!!(t&16),g=l>3?e.length+1:l?u?1:2:0,v=fu[l+5],b=l>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),h=l&&(!p&&!u&&(i=i.prototype),l<5&&(l>3||!p)&&$v(l<4?i:{get[n](){return We(this,s)},set[n](y){return xt(this,s,y)}},n));l?p&&l<4&&sc(s,(l>2?"set ":l>1?"get ":"")+n):sc(i,n);for(var x=r.length-1;x>=0;x--)f=Mv(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>Ev(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?We:pu)(y,i,l^4?s:h.get):y=>y[n]),l>2&&(c.set=p?(y,k)=>xt(y,i,k,l^4?s:h.set):(y,k)=>y[n]=k)),a=(0,r[x])(l?l<4?p?s:h[v]:l>4?void 0:{get:h.get,set:h.set}:i,f),d._=1,l^4||a===void 0?Dr(a)&&(l>4?b.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?pr("Object expected"):(Dr(o=a.get)&&(h.get=o),Dr(o=a.set)&&(h.set=o),Dr(o=a.init)&&b.unshift(o));return l||Tn(e,i),h&&za(i,n,h),p?l^4?s:h:i},Ba=(e,t,n)=>t.has(e)||pr("Cannot "+n),Ev=(e,t)=>Object(t)!==t?pr('Cannot use the "in" operator on this value'):e.has(t),We=(e,t,n)=>(Ba(e,t,"read from private field"),n?n.call(e):t.get(e)),me=(e,t,n)=>t.has(e)?pr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),xt=(e,t,n,r)=>(Ba(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),pu=(e,t,n)=>(Ba(e,t,"access private method"),n);function mu(e,t){return{plugin:e,options:t}}function yi(e){return t=>mu(e,t)}function ai(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var gu,li,_a,qi;gu=[ae];var it=class{constructor(e,t){this.manager=e,this.options=t,me(this,_a,te(li,8,this,!1)),te(li,11,this),me(this,qi,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return oe(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=$t(e.bind(this));return We(this,qi).add(t),t}destroy(){We(this,qi).forEach(e=>e())}static configure(e){return mu(this,e)}};li=mr(null);_a=new WeakMap;qi=new WeakMap;ce(li,4,"disabled",gu,it,_a);Tn(li,it);var wi=class extends it{},Hi,eo=class{constructor(e){this.manager=e,this.instances=new Map,me(this,Hi,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(ai).reduce((r,i)=>{const s=r.find(({plugin:o})=>o===i.plugin);return s?(s.options=i.options,r):[...r,i]},[]),n=t.map(({plugin:r})=>r);for(const r of We(this,Hi))if(!n.includes(r)){if(r.prototype instanceof wi)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);xt(this,Hi,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};Hi=new WeakMap;function Cv(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Oi=[],Fn,Bn,Tv=class extends it{constructor(e){super(e),me(this,Fn),me(this,Bn),this.computeCollisions=this.computeCollisions.bind(this),xt(this,Bn,dr(Oi)),this.destroy=xi(()=>{const t=this.computeCollisions(),n=oe(()=>this.manager.dragOperation.position.current);if(t!==Oi){const r=We(this,Fn);if(xt(this,Fn,n),r&&n.x==r.x&&n.y==r.y)return}else xt(this,Fn,void 0);We(this,Bn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){oe(()=>{e?We(this,Bn).value=this.computeCollisions():xt(this,Fn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return Oi;const a=[],d=[];for(const f of e??n.droppables){if(f.disabled||i&&!f.accepts(i))continue;const c=t??f.collisionDetector;if(!c)continue;d.push(f),f.shape;const l=oe(()=>c({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return d.length===0?Oi:(a.sort(Cv),a)}get collisions(){return We(this,Bn).value}};Fn=new WeakMap;Bn=new WeakMap;var vu,xu,bu,qa,yu,Tt,Ha,Gn,Ua,Va;bu=[ae],xu=[ae],vu=[ae];var Ut=class pn{constructor(t,n){me(this,Ha,te(Tt,8,this)),te(Tt,11,this),me(this,Gn),me(this,Ua,te(Tt,12,this)),te(Tt,15,this),me(this,Va,te(Tt,16,this)),te(Tt,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let d=i;xt(this,Gn,dr(i)),this.manager=n,this.data=s,this.disabled=o,this.effects=()=>{var f;return[()=>{const{id:c,manager:l}=this;if(c!==d)return d=c,l?.registry.register(this),()=>l?.registry.unregister(this)},...(f=r?.())!=null?f:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=We(this,Gn).value;return(n=(t=pn.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=pn.pendingIdChanges)==null?void 0:n.get(this))!=null?r:We(this,Gn).peek();t!==i&&(pn.pendingIdChanges||(pn.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return pu(s=pn,qa,yu).call(s)})),pn.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};Tt=mr(null);qa=new WeakSet;yu=function(){const e=Ut.pendingIdChanges;Ut.pendingIdChanges=null,e&&Oe(()=>{for(const[t,n]of e)We(t,Gn).value=n})};Ha=new WeakMap;Gn=new WeakMap;Ua=new WeakMap;Va=new WeakMap;ce(Tt,4,"manager",bu,Ut,Ha);ce(Tt,4,"data",xu,Ut,Ua);ce(Tt,4,"disabled",vu,Ut,Va);me(Ut,qa);Tn(Tt,Ut);Ut.pendingIdChanges=null;var Is=Ut,oc=class{constructor(){this.map=dr(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),i=()=>this.unregister(e,t);if(r===t)return i;r&&r.id===e&&(this.cleanupFunctions.get(r)?.(),this.cleanupFunctions.delete(r));const s=new Map(n);for(const[a,d]of n)if(d===t&&a!==e){s.delete(a);break}s.set(e,t),this.map.value=s;const o=xi(...t.effects());return this.cleanupFunctions.set(t,o),i},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;this.cleanupFunctions.get(t)?.(),this.cleanupFunctions.delete(t);const i=new Map(n);i.delete(e),this.map.value=i}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this)this.cleanupFunctions.get(e)?.(),e.destroy();this.map.value=new Map}},wu,ku,Su,$u,ju,Mu,Ho,at,Ka,Ga,Ya,Wt=class extends(Ho=Is,Mu=[ae],ju=[ae],$u=[ae],Su=[ze],ku=[ze],wu=[ze],Ho){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,d=hu(n,["modifiers","type","sensors","plugins","effects"]);super(Fa(La({},d),{effects:()=>{var f;return[...(f=a?.())!=null?f:[],()=>{const{manager:c,plugins:l}=this;if(!(!c||!l))for(const u of l){const{plugin:p}=ai(u);c.registry.plugins.register(p)}}]}}),t),te(at,5,this),me(this,Ka,te(at,8,this)),te(at,11,this),me(this,Ga,te(at,12,this)),te(at,15,this),me(this,Ya,te(at,16,this,this.isDragSource?"dragging":"idle")),te(at,19,this),this.type=i,this.sensors=s,this.modifiers=r,this.alignment=d.alignment,this.plugins=o}pluginConfig(e){if(this.plugins)for(const t of this.plugins){const n=ai(t);if(n.plugin===e)return n.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var e,t;return((t=(e=this.manager)==null?void 0:e.dragOperation.source)==null?void 0:t.id)===this.id}};at=mr(Ho);Ka=new WeakMap;Ga=new WeakMap;Ya=new WeakMap;ce(at,4,"type",Mu,Wt,Ka);ce(at,4,"modifiers",ju,Wt,Ga);ce(at,4,"status",$u,Wt,Ya);ce(at,2,"isDropping",Su,Wt);ce(at,2,"isDragging",ku,Wt);ce(at,2,"isDragSource",wu,Wt);Tn(at,Wt);var Eu,Cu,Tu,Ou,Au,Ru,Uo,Ue,Xa,Qa,Za,Ja,el,zt=class extends(Uo=Is,Ru=[ae],Au=[ae],Ou=[ae],Tu=[ae],Cu=[ae],Eu=[ze],Uo){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=hu(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),te(Ue,5,this),me(this,Xa,te(Ue,8,this)),te(Ue,11,this),me(this,Qa,te(Ue,12,this)),te(Ue,15,this),me(this,Za,te(Ue,16,this)),te(Ue,19,this),me(this,Ja,te(Ue,20,this)),te(Ue,23,this),me(this,el,te(Ue,24,this)),te(Ue,27,this),this.accept=r,this.collisionDetector=i,this.collisionPriority=s,this.type=o}accepts(e){const{accept:t}=this;return t?typeof t=="function"?t(e):e.type?Array.isArray(t)?t.includes(e.type):e.type===t:!1:!0}get isDropTarget(){var e,t;return((t=(e=this.manager)==null?void 0:e.dragOperation.target)==null?void 0:t.id)===this.id}};Ue=mr(Uo);Xa=new WeakMap;Qa=new WeakMap;Za=new WeakMap;Ja=new WeakMap;el=new WeakMap;ce(Ue,4,"accept",Ru,zt,Xa);ce(Ue,4,"type",Au,zt,Qa);ce(Ue,4,"collisionDetector",Ou,zt,Za);ce(Ue,4,"collisionPriority",Tu,zt,Ja);ce(Ue,4,"shape",Cu,zt,el);ce(Ue,2,"isDropTarget",Eu,zt);Tn(Ue,zt);var Ov=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const i of r)i(...t)}},Av=class extends Ov{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function Ui(e,t=!0){let n=!1;return Fa(La({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var Rv=class extends wi{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=xi(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||Is.pendingIdChanges)return;const o=Ui({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;oe(()=>{var d;a?.id!==((d=e.dragOperation.target)==null?void 0:d.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},gr=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(gr||{}),vr=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(vr||{}),Du,Pu,Iu,Nu,Wu,zu,Lu,St,tl;Lu=[ae],zu=[ze],Wu=[ze],Nu=[ze],Iu=[ze],Pu=[ze],Du=[ze];var Kt=class{constructor(){te(St,5,this),me(this,tl,te(St,8,this,"idle")),te(St,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};St=mr(null);tl=new WeakMap;ce(St,4,"value",Lu,Kt,tl);ce(St,2,"current",zu,Kt);ce(St,2,"idle",Wu,Kt);ce(St,2,"initializing",Nu,Kt);ce(St,2,"initialized",Iu,Kt);ce(St,2,"dragging",Pu,Kt);ce(St,2,"dropped",Du,Kt);Tn(St,Kt);var Dv=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return oe(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=Ui({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return oe(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const n=new AbortController,{event:r,coordinates:i}=e;Oe(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=r??null,t.position.reset(i)});const s=Ui({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",s),s.defaultPrevented?(t.reset(),n.abort(),n):(t.status.set("initializing"),t.controller=n,this.manager.renderer.rendering.then(()=>{if(n.signal.aborted)return;const{status:o}=t;o.current==="initializing"&&Oe(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:r,operation:t.snapshot(),cancelable:!1})})}),n)})}move(e){return oe(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=Ui({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,d,f,c,l;if(o.defaultPrevented)return;const u=(l=e.to)!=null?l:{x:r.position.current.x+((d=(a=e.by)==null?void 0:a.x)!=null?d:0),y:r.position.current.y+((c=(f=e.by)==null?void 0:f.y)!=null?c:0)};r.position.current=u})})}stop(e={}){return oe(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:i}=r;if(!i||i.signal.aborted)return;let s;const o=()=>{const d={resume:()=>{},abort:()=>{}};return s=new Promise((f,c)=>{d.resume=f,d.abort=c}),d};i.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const d=oe(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),f=()=>{r.controller===i&&(r.controller=void 0),r.reset()};if(d){const{source:c}=r,l=$t(()=>{c?.status==="idle"&&(l(),f())})}else this.manager.renderer.rendering.then(f)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),s?s.then(a).catch(()=>r.reset()):a()})}},rr=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Pv=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},Vi,Fu=class{constructor(e){this.options=e,me(this,Vi)}set controller(e){xt(this,Vi,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=We(this,Vi))==null||t.activate(e)}};Vi=new WeakMap;var ac=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Iv=class{constructor(e){this.draggables=new oc,this.droppables=new oc,this.plugins=new eo(e),this.sensors=new eo(e),this.modifiers=new eo(e)}register(e,t){if(e instanceof Wt)return this.draggables.register(e.id,e);if(e instanceof zt)return this.droppables.register(e.id,e);if(e.prototype instanceof ac)return this.modifiers.register(e,t);if(e.prototype instanceof rr)return this.sensors.register(e,t);if(e.prototype instanceof it)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Is)return e instanceof Wt?this.draggables.unregister(e.id,e):e instanceof zt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof ac)return this.modifiers.unregister(e);if(e.prototype instanceof rr)return this.sensors.unregister(e);if(e.prototype instanceof it)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},Bu,_u,qu,Hu,Uu,Vu,Ku,Gu,Yu,Pr,Ki,_n,Te,nl,rl,il,sl,ol,Ir;Yu=[ze],Gu=[ae],Ku=[ae],Vu=[ae],Uu=[ae],Hu=[ae],qu=[ze],_u=[ze],Bu=[ze];var Dt=class{constructor(e){te(Te,5,this),me(this,Pr),me(this,Ki),me(this,_n,new Cn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Kt,me(this,nl,te(Te,8,this,!1)),te(Te,11,this),me(this,rl,te(Te,12,this,null)),te(Te,15,this),me(this,il,te(Te,16,this,null)),te(Te,19,this),me(this,sl,te(Te,20,this,null)),te(Te,23,this),me(this,ol,te(Te,24,this,[])),te(Te,27,this),this.position=new Ps({x:0,y:0}),me(this,Ir,{x:0,y:0}),xt(this,Pr,e)}get shape(){const{current:e,initial:t,previous:n}=We(this,_n);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?We(this,_n).current=e:We(this,_n).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=We(this,Pr).registry.draggables.get(t);return n&&xt(this,Ki,n),(e=n??We(this,Ki))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=We(this,Pr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Fa(La({},this.snapshot()),{transform:n}));return xt(this,Ir,n),n}snapshot(){return oe(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:We(this,Ir),shape:this.shape?Js(this.shape):null,position:Js(this.position),status:Js(this.status),canceled:this.canceled}))}reset(){Oe(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,We(this,_n).reset(),this.position.reset({x:0,y:0}),xt(this,Ir,{x:0,y:0}),this.modifiers=[]})}};Te=mr(null);Pr=new WeakMap;Ki=new WeakMap;_n=new WeakMap;nl=new WeakMap;rl=new WeakMap;il=new WeakMap;sl=new WeakMap;ol=new WeakMap;Ir=new WeakMap;ce(Te,2,"shape",Yu,Dt);ce(Te,4,"canceled",Gu,Dt,nl);ce(Te,4,"activatorEvent",Ku,Dt,rl);ce(Te,4,"sourceIdentifier",Vu,Dt,il);ce(Te,4,"targetIdentifier",Uu,Dt,sl);ce(Te,4,"modifiers",Hu,Dt,ol);ce(Te,2,"source",qu,Dt);ce(Te,2,"target",_u,Dt);ce(Te,2,"transform",Bu,Dt);Tn(Te,Dt);var Nv={get rendering(){return Promise.resolve()}};function Rt(e,t){return typeof e=="function"?e(t):e??t}var Wv=class{constructor(e){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(l=>l.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var t;const n=e??{},r=Rt(n.plugins,[]),i=Rt(n.sensors,[]),s=Rt(n.modifiers,[]),o=(t=n.renderer)!=null?t:Nv,a=new Av(this),d=new Iv(this);this.registry=d,this.monitor=a,this.renderer=o,this.actions=new Dv(this),this.dragOperation=new Dt(this),this.collisionObserver=new Tv(this),this.plugins=[Rv,...r],this.modifiers=s,this.sensors=i;const{destroy:f}=this,c=xi(()=>{var l,u,p;const g=oe(()=>this.dragOperation.modifiers),v=this.modifiers;for(const b of g)v.includes(b)||b.destroy();this.dragOperation.modifiers=(p=(u=(l=this.dragOperation.source)==null?void 0:l.modifiers)==null?void 0:u.map(b=>{const{plugin:w,options:h}=ai(b);return new w(this,h)}))!=null?p:v});this.destroy=()=>{c(),f()}}get plugins(){return this.registry.plugins.values}set plugins(e){this.registry.plugins.values=e}get modifiers(){return this.registry.modifiers.values}set modifiers(e){this.registry.modifiers.values=e}get sensors(){return this.registry.sensors.values}set sensors(e){this.registry.sensors.values=e}},Xu=e=>{throw TypeError(e)},al=(e,t,n)=>t.has(e)||Xu("Cannot "+n),ee=(e,t,n)=>(al(e,t,"read from private field"),t.get(e)),ut=(e,t,n)=>t.has(e)?Xu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),gt=(e,t,n,r)=>(al(e,t,"write to private field"),t.set(e,n),n),Qu=(e,t,n)=>(al(e,t,"access private method"),n);function Ns(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Zu(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,o=(Ns(s)?s.getKeyframes():[]).filter(t);o.length>0&&(r=[o[o.length-1],i])}return r}function Ws(e){const{width:t,height:n,top:r,left:i,bottom:s,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:i,bottom:s,right:o}}function ll(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function ki(e){return"nodeType"in e}function bt(e){var t,n,r;return e?ll(e)?e:ki(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function cl(e){const{Document:t}=bt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function on(e){return!e||ll(e)?!1:e instanceof bt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Ju(e){return e instanceof bt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function xr(e){return e?ll(e)?e.document:ki(e)?cl(e)?e:on(e)||Ju(e)?e.ownerDocument:document:document:document}function zv(e){var t,n,r,i;const{documentElement:s}=xr(e),o=bt(e).visualViewport,a=(t=o?.width)!=null?t:s.clientWidth,d=(n=o?.height)!=null?n:s.clientHeight,f=(r=o?.offsetTop)!=null?r:0,c=(i=o?.offsetLeft)!=null?i:0;return{top:f,left:c,right:c+a,bottom:f+d,width:a,height:d}}function Lv(e,t){if(Fv(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function Fv(e){return e.tagName==="DETAILS"}function ci(e,t=e.getBoundingClientRect(),n=0){var r,i,s,o,a;let d=t;const{ownerDocument:f}=e,c=(r=f.defaultView)!=null?r:window;let l=e.parentElement;for(;l&&l!==f.documentElement;){if(!Lv(l)){const x=l.getBoundingClientRect(),y=n*(x.bottom-x.top),k=n*(x.right-x.left),C=n*(x.bottom-x.top),$=n*(x.right-x.left);d={top:Math.max(d.top,x.top-y),right:Math.min(d.right,x.right+k),bottom:Math.min(d.bottom,x.bottom+C),left:Math.max(d.left,x.left-$),width:0,height:0},d.width=d.right-d.left,d.height=d.bottom-d.top}l=l.parentElement}const u=c.visualViewport,p=(i=u?.offsetTop)!=null?i:0,g=(s=u?.offsetLeft)!=null?s:0,v=(o=u?.width)!=null?o:c.innerWidth,b=(a=u?.height)!=null?a:c.innerHeight,w=n*b,h=n*v;return d={top:Math.max(d.top,p-w),right:Math.min(d.right,g+v+h),bottom:Math.min(d.bottom,p+b+w),left:Math.max(d.left,g-h),width:0,height:0},d.width=d.right-d.left,d.height=d.bottom-d.top,d.width<0&&(d.width=0),d.height<0&&(d.height=0),d}function ir(e){return{x:e.clientX,y:e.clientY}}var eh=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Vo(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const i=r.contentDocument;i&&!t.has(i)&&n.push(...Vo(i,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const i=r.parent;i&&i.document&&i.document!==e&&n.push(...Vo(i.document,t))}}catch{}return n}function dl(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function th(){var e,t;const n=dl()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function ul(e){return!e||!ki(e)?!1:e instanceof bt(e).ShadowRoot}function ps(e){if(e&&ki(e)){let t=e.getRootNode();if(ul(t)||t instanceof Document)return t}return xr(e)}function hl(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Bv(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,s)=>{const o=r[s];lc(i)&&lc(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),cc(i)&&cc(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function lc(e){return"value"in e}function cc(e){return e.tagName==="CANVAS"}function nh(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(_v(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return nh(i,{x:t-s,y:n-o})}}return r}function _v(e){return e?.tagName==="IFRAME"}var Ko=new WeakMap;function qv(e){return e.closest(`
2
+ input:not([disabled]),
3
+ select:not([disabled]),
4
+ textarea:not([disabled]),
5
+ button:not([disabled]),
6
+ a[href],
7
+ [contenteditable]:not([contenteditable="false"])
8
+ `)}var rh=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:i}]=e;t.removeEventListener(n,r,i)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],i=[];for(const o of n)for(const a of r){const{type:d,listener:f,options:c}=a,l=[o,a];o.addEventListener(d,f,c),this.entries.add(l),i.push(l)}const s=this.entries;return function(){for(const o of i){const[a,{type:d,listener:f,options:c}]=o;a.removeEventListener(d,f,c),s.delete(o)}}}};function sr(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Hv(e){const t=new Set;let n=sr(e);for(;n;)t.add(n),n=sr(n);return t}function Uv(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function ih(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=Uv(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function Vv(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function Kv(e,t=e.getBoundingClientRect()){const{width:n,height:r}=ci(e,t);return n>0&&r>0}var Gv=eh?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Gi,Yv=class extends Gv{constructor(e){super(t=>{if(!ee(this,Gi)){gt(this,Gi,!0);return}e(t,this)}),ut(this,Gi,!1)}};Gi=new WeakMap;var dc=Array.from({length:100},(e,t)=>t/100),sh=75,mn,ms,Gt,gn,Nr,Ye,Jr,Wr,gs,oh,ah,lh=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,ut(this,gs),this.disconnect=()=>{var s,o,a;gt(this,Jr,!0),(s=ee(this,Gt))==null||s.disconnect(),(o=ee(this,gn))==null||o.disconnect(),ee(this,Nr).disconnect(),(a=ee(this,Ye))==null||a.remove()},ut(this,mn,!0),ut(this,ms),ut(this,Gt),ut(this,gn),ut(this,Nr),ut(this,Ye),ut(this,Jr,!1),ut(this,Wr,ih(()=>{var s,o,a;const{element:d}=this;if((s=ee(this,gn))==null||s.disconnect(),ee(this,Jr)||!ee(this,mn)||!d.isConnected)return;const f=(o=d.ownerDocument)!=null?o:document,{innerHeight:c,innerWidth:l}=(a=f.defaultView)!=null?a:window,u=d.getBoundingClientRect(),p=ci(d,u),{top:g,left:v,bottom:b,right:w}=p,h=-Math.floor(g),x=-Math.floor(v),y=-Math.floor(l-w),k=-Math.floor(c-b),C=`${h}px ${y}px ${k}px ${x}px`;this.boundingClientRect=u,gt(this,gn,new IntersectionObserver($=>{const[T]=$,{intersectionRect:j}=T;(T.intersectionRatio!==1?T.intersectionRatio:Nt.intersectionRatio(j,ci(d)))!==1&&ee(this,Wr).call(this)},{threshold:dc,rootMargin:C,root:f})),ee(this,gn).observe(d),Qu(this,gs,oh).call(this)},sh)),this.boundingClientRect=e.getBoundingClientRect(),gt(this,mn,Kv(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(gt(this,Ye,document.createElement("div")),ee(this,Ye).style.background="rgba(0,0,0,0.15)",ee(this,Ye).style.position="fixed",ee(this,Ye).style.pointerEvents="none",i.body.appendChild(ee(this,Ye))),gt(this,Nr,new IntersectionObserver(s=>{var o,a;const d=s[s.length-1],{boundingClientRect:f,isIntersecting:c}=d,{width:l,height:u}=f,p=ee(this,mn);gt(this,mn,c),!(!l&&!u)&&(p&&!c?((o=ee(this,gn))==null||o.disconnect(),this.callback(null),(a=ee(this,Gt))==null||a.disconnect(),gt(this,Gt,void 0),ee(this,Ye)&&(ee(this,Ye).style.visibility="hidden")):ee(this,Wr).call(this),c&&!ee(this,Gt)&&(gt(this,Gt,new Yv(ee(this,Wr))),ee(this,Gt).observe(e)))},{threshold:dc,root:i})),ee(this,mn)&&!n.skipInitial&&this.callback(this.boundingClientRect),ee(this,Nr).observe(e)}};mn=new WeakMap;ms=new WeakMap;Gt=new WeakMap;gn=new WeakMap;Nr=new WeakMap;Ye=new WeakMap;Jr=new WeakMap;Wr=new WeakMap;gs=new WeakSet;oh=function(){ee(this,Jr)||(Qu(this,gs,ah).call(this),!Vv(this.boundingClientRect,ee(this,ms))&&(this.callback(this.boundingClientRect),gt(this,ms,this.boundingClientRect)))};ah=function(){if(ee(this,Ye)){const{top:e,left:t,width:n,height:r}=ci(this.element);ee(this,Ye).style.overflow="hidden",ee(this,Ye).style.visibility="visible",ee(this,Ye).style.top=`${Math.floor(e)}px`,ee(this,Ye).style.left=`${Math.floor(t)}px`,ee(this,Ye).style.width=`${Math.floor(n)}px`,ee(this,Ye).style.height=`${Math.floor(r)}px`}};var Ai=new WeakMap,Ri=new WeakMap;function Xv(e,t){let n=Ai.get(e);return n||(n={disconnect:new lh(e,r=>{const i=Ai.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Ai.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Ai.delete(e),n.disconnect())}}function Qv(e,t){const n=new Set;for(const r of e){const i=Xv(r,t);n.add(i)}return()=>n.forEach(r=>r())}function Zv(e,t){var n;const r=e.ownerDocument;if(!Ri.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",d=>a.forEach(f=>f(d)),{capture:!0,passive:!0,signal:o.signal}),Ri.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=Ri.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),Ri.delete(r))})}var zr,Lr,Yi,Go,Jv=class{constructor(e,t,n){this.callback=t,ut(this,zr),ut(this,Lr,!1),ut(this,Yi),ut(this,Go,ih(o=>{if(!ee(this,Lr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of ee(this,Yi))if(o.target.contains(a)){this.callback(ee(this,zr).boundingClientRect);break}}},sh));const r=Hv(e),i=Qv(r,t),s=Zv(e,ee(this,Go));gt(this,Yi,r),gt(this,zr,new lh(e,t,n)),this.disconnect=()=>{ee(this,Lr)||(gt(this,Lr,!0),i(),s(),ee(this,zr).disconnect())}}};zr=new WeakMap;Lr=new WeakMap;Yi=new WeakMap;Go=new WeakMap;function Yo(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Zn(e){try{Yo(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function uc(e){return!eh||!e?!1:e===xr(e).scrollingElement}function ch(e){var t,n;const r=bt(e),i=uc(e)?zv(e):Ws(e),s=r.visualViewport,o=uc(e)?{height:(t=s?.height)!=null?t:r.innerHeight,width:(n=s?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},d=a.current.y<=0,f=a.current.x<=0,c=a.current.y>=a.max.y,l=a.current.x>=a.max.x;return{rect:i,position:a,isTop:d,isLeft:f,isBottom:c,isRight:l}}function ex(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=ch(e),{x:a,y:d}=t??{x:0,y:0},f=!n&&o.current.y+d>0,c=!r&&o.current.y+d<o.max.y,l=!i&&o.current.x+a>0,u=!s&&o.current.x+a<o.max.x;return{top:f,bottom:c,left:l,right:u,x:l||u,y:f||c}}var fl=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},vs=new fl(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),tx=new fl(e=>setTimeout(e,50)),xs=new Map,nx=xs.clear.bind(xs);function Lt(e,t=!1){if(!t)return hc(e);let n=xs.get(e);return n||(n=hc(e),xs.set(e,n),tx.schedule(nx),n)}function hc(e){return bt(e).getComputedStyle(e)}function rx(e,t=Lt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function ix(e,t=Lt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const i=t[r];return typeof i=="string"?n.test(i):!1})}var sx={excludeElement:!0,escapeShadowDOM:!0};function Xo(e,t=sx){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(cl(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&ul(a))return o(a.host);if(!on(a))return Ju(a)?o(a.parentElement):s;if(s.has(a))return s;const d=Lt(a,!0);if(r&&a===e||ix(a,d)&&s.add(a),rx(a,d)){const{scrollingElement:f}=a.ownerDocument;return f&&s.add(f),s}return o(a.parentNode)}return e?o(e):s}function or(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=sr(e);for(;r;){if(r===t)return n;const i=Ws(r),{x:s,y:o}=ox(r,i);n.x=n.x+i.left,n.y=n.y+i.top,n.scaleX=n.scaleX*s,n.scaleY=n.scaleY*o,r=sr(r)}return n}function ox(e,t=Ws(e)){const n=Math.round(t.width),r=Math.round(t.height);if(on(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=Lt(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function ax(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function di(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),i={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(i.x)&&isNaN(i.y)?null:{x:isNaN(i.x)?0:i.x,y:isNaN(i.y)?0:i.y,z:isNaN(i.z)?0:i.z}}function zs(e){var t,n,r,i,s,o,a,d,f;const{scale:c,transform:l,translate:u}=e,p=ax(c),g=di(u),v=lx(l);if(!v&&!p&&!g)return null;const b={x:(t=p?.x)!=null?t:1,y:(n=p?.y)!=null?n:1},w={x:(r=g?.x)!=null?r:0,y:(i=g?.y)!=null?i:0},h={x:(s=v?.x)!=null?s:0,y:(o=v?.y)!=null?o:0,scaleX:(a=v?.scaleX)!=null?a:1,scaleY:(d=v?.scaleY)!=null?d:1};return{x:w.x+h.x,y:w.y+h.y,z:(f=g?.z)!=null?f:0,scaleX:b.x*h.scaleX,scaleY:b.y*h.scaleY}}function lx(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var kt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(kt||{}),cx={x:.2,y:.2},dx={x:10,y:10};function ux(e,t,n,r=25,i=cx,s=dx){const{x:o,y:a}=t,{rect:d,isTop:f,isBottom:c,isLeft:l,isRight:u}=ch(e),p=or(e),g=Lt(e,!0),v=zs(g),b=v!==null?v?.scaleX<0:!1,w=v!==null?v?.scaleY<0:!1,h=new Nt(d.left*p.scaleX+p.x,d.top*p.scaleY+p.y,d.width*p.scaleX,d.height*p.scaleY),x={x:0,y:0},y={x:0,y:0},k={height:h.height*i.y,width:h.width*i.x};return k.height>0&&(!f||w&&!c)&&a<=h.top+k.height&&n?.y!==1&&o>=h.left-s.x&&o<=h.right+s.x?(x.y=w?1:-1,y.y=r*Math.abs((h.top+k.height-a)/k.height)):k.height>0&&(!c||w&&!f)&&a>=h.bottom-k.height&&n?.y!==-1&&o>=h.left-s.x&&o<=h.right+s.x&&(x.y=w?-1:1,y.y=r*Math.abs((h.bottom-k.height-a)/k.height)),k.width>0&&(!u||b&&!l)&&o>=h.right-k.width&&n?.x!==-1&&a>=h.top-s.y&&a<=h.bottom+s.y?(x.x=b?-1:1,y.x=r*Math.abs((h.right-k.width-o)/k.width)):k.width>0&&(!l||b&&!u)&&o<=h.left+k.width&&n?.x!==1&&a>=h.top-s.y&&a<=h.bottom+s.y&&(x.x=b?1:-1,y.x=r*Math.abs((h.left+k.width-o)/k.width)),{direction:x,speed:y}}function dh(e,{block:t="nearest",inline:n="nearest"}={}){if(!on(e))return;const r=Xo(e),i=[];for(const s of r){if(!on(s))continue;const{top:o,left:a}=hx(e,s);let d=o,f=a;for(const c of i)d-=c.scrollTop,f-=c.scrollLeft;if(t!=="none"){const c=d<s.scrollTop,l=d+e.offsetHeight>s.scrollTop+s.clientHeight;c!==l&&(t==="center"?s.scrollTop=d-s.clientHeight/2+e.offsetHeight/2:c?s.scrollTop=d:s.scrollTop=d+e.offsetHeight-s.clientHeight)}if(n!=="none"){const c=f<s.scrollLeft,l=f+e.offsetWidth>s.scrollLeft+s.clientWidth;c!==l&&(n==="center"?s.scrollLeft=f-s.clientWidth/2+e.offsetWidth/2:c?s.scrollLeft=f:s.scrollLeft=f+e.offsetWidth-s.clientWidth)}i.push(s)}}function fc(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!on(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function hx(e,t){const n=fc(e),r=fc(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function fx(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left+s+(1-r)*parseFloat(n),d=e.top+o+(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width*r:e.width,c=i?e.height*i:e.height;return{width:f,height:c,top:d,right:a+f,bottom:d+c,left:a}}function px(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left-s-(1-r)*parseFloat(n),d=e.top-o-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width/r:e.width,c=i?e.height/i:e.height;return{width:f,height:c,top:d,right:a+f,bottom:d+c,left:a}}function uh({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function pc(e,t=Lt(e).translate,n=!0){if(n){const r=Zu(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=di(i);if(s)return s}}}if(t){const r=di(t);if(r)return r}return{x:0,y:0,z:0}}var mx=new fl(e=>setTimeout(e,0)),ei=new Map,gx=ei.clear.bind(ei);function vx(e){const t=e.ownerDocument;let n=ei.get(t);if(n)return n;n=t.getAnimations(),ei.set(t,n),mx.schedule(gx);const r=n.filter(i=>Ns(i.effect)&&i.effect.target===e);return ei.set(e,r),n}function xx(e,t){const n=vx(e).filter(r=>{var i,s;if(Ns(r.effect)){const{target:o}=r.effect;if((s=o&&((i=t.isValidTarget)==null?void 0:i.call(t,o)))==null||s)return r.effect.getKeyframes().some(a=>{for(const d of t.properties)if(a[d])return!0})}}).map(r=>{const{effect:i,currentTime:s}=r,o=i?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof s=="number"&&s<o)return r.currentTime=o,()=>{r.currentTime=s}});if(n.length>0)return()=>n.forEach(r=>r?.())}var It=class extends Nt{constructor(e,t={}){var n,r,i,s;const{frameTransform:o=or(e),ignoreTransforms:a,getBoundingClientRect:d=Ws}=t,f=xx(e,{properties:["transform","translate","scale","width","height"],isValidTarget:k=>(k!==e||dl())&&k.contains(e)}),c=d(e);let{top:l,left:u,width:p,height:g}=c,v;const b=Lt(e),w=zs(b),h={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},x=bx(e,b);f?.(),w&&(v=px(c,w,b.transformOrigin),(a||x)&&(l=v.top,u=v.left,p=v.width,g=v.height));const y={width:(i=v?.width)!=null?i:p,height:(s=v?.height)!=null?s:g};if(x&&!a&&v){const k=fx(v,x,b.transformOrigin);l=k.top,u=k.left,p=k.width,g=k.height,h.x=x.scaleX,h.y=x.scaleY}o&&(a||(u*=o.scaleX,p*=o.scaleX,l*=o.scaleY,g*=o.scaleY),u+=o.x,l+=o.y),super(u,l,p,g),this.scale=h,this.intrinsicWidth=y.width,this.intrinsicHeight=y.height}};function bx(e,t){const n=e.getAnimations();if(!n.length)return null;let r,i,s,o=!1;for(const a of n){if(a.playState!=="running")continue;const d=Ns(a.effect)?a.effect.getKeyframes():[],f=d[d.length-1];if(!f)continue;const{transform:c,translate:l,scale:u}=f;typeof c=="string"&&c&&(r=c,o=!0),typeof l=="string"&&l&&(i=l,o=!0),typeof u=="string"&&u&&(s=u,o=!0)}return o?zs({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function ti(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var yx=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(ti(n))for(const[r,i]of Object.entries(e)){const s=`${t}${r}`;this.initial.has(s)||this.initial.set(s,n.style.getPropertyValue(s)),n.style.setProperty(s,typeof i=="string"?i:`${i}px`)}}remove(e,t=""){const{element:n}=this;if(ti(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(ti(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function jn(e){return e?e instanceof bt(e).Element||ki(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function ui(e){if(!e)return!1;const{KeyboardEvent:t}=bt(e.target);return e instanceof t}function wx(e){if(!e)return!1;const{PointerEvent:t}=bt(e.target);return e instanceof t}function kx(e){if(!jn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||Sx(e)}function Sx(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var to={};function Qo(e){const t=to[e]==null?0:to[e]+1;return to[e]=t,`${e}-${t}`}var pl=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=wt.distance(t.shape.center,n);return{id:r,value:1/i,type:vr.PointerIntersection,priority:gr.High}}return null},$x=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=wt.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:vr.ShapeIntersection,priority:gr.Normal}}return null},hh=e=>{var t;return(t=pl(e))!=null?t:$x(e)},jx=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const s=r?Nt.from(r.current.boundingRectangle).corners:void 0,o=Nt.from(n.shape.boundingRectangle).corners.reduce((a,d,f)=>{var c;return a+wt.distance(wt.from(d),(c=s?.[f])!=null?c:i.current)},0)/4;return{id:n.id,value:1/o,type:vr.Collision,priority:gr.Normal}},Mx=Object.create,ml=Object.defineProperty,Ex=Object.defineProperties,Cx=Object.getOwnPropertyDescriptor,Tx=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,fh=Object.prototype.hasOwnProperty,ph=Object.prototype.propertyIsEnumerable,mh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),br=e=>{throw TypeError(e)},Zo=(e,t,n)=>t in e?ml(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hi=(e,t)=>{for(var n in t||(t={}))fh.call(t,n)&&Zo(e,n,t[n]);if(bs)for(var n of bs(t))ph.call(t,n)&&Zo(e,n,t[n]);return e},gl=(e,t)=>Ex(e,Tx(t)),mc=(e,t)=>ml(e,"name",{value:t,configurable:!0}),gh=(e,t)=>{var n={};for(var r in e)fh.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&bs)for(var r of bs(e))t.indexOf(r)<0&&ph.call(e,r)&&(n[r]=e[r]);return n},yr=e=>{var t;return[,,,Mx((t=e?.[mh("metadata")])!=null?t:null)]},vh=["class","method","getter","setter","accessor","field","value","get","set"],Fr=e=>e!==void 0&&typeof e!="function"?br("Function expected"):e,Ox=(e,t,n,r,i)=>({kind:vh[e],name:t,metadata:r,addInitializer:s=>n._?br("Already initialized"):i.push(Fr(s||null))}),On=(e,t)=>Zo(t,mh("metadata"),e[3]),Ve=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},jt=(e,t,n,r,i,s)=>{var o,a,d,f,c,l=t&7,u=!!(t&8),p=!!(t&16),g=l>3?e.length+1:l?u?1:2:0,v=vh[l+5],b=l>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),h=l&&(!p&&!u&&(i=i.prototype),l<5&&(l>3||!p)&&Cx(l<4?i:{get[n](){return be(this,s)},set[n](y){return lt(this,s,y)}},n));l?p&&l<4&&mc(s,(l>2?"set ":l>1?"get ":"")+n):mc(i,n);for(var x=r.length-1;x>=0;x--)f=Ox(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>Ax(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?be:Mn)(y,i,l^4?s:h.get):y=>y[n]),l>2&&(c.set=p?(y,k)=>lt(y,i,k,l^4?s:h.set):(y,k)=>y[n]=k)),a=(0,r[x])(l?l<4?p?s:h[v]:l>4?void 0:{get:h.get,set:h.set}:i,f),d._=1,l^4||a===void 0?Fr(a)&&(l>4?b.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?br("Object expected"):(Fr(o=a.get)&&(h.get=o),Fr(o=a.set)&&(h.set=o),Fr(o=a.init)&&b.unshift(o));return l||On(e,i),h&&ml(i,n,h),p?l^4?s:h:i},vl=(e,t,n)=>t.has(e)||br("Cannot "+n),Ax=(e,t)=>Object(t)!==t?br('Cannot use the "in" operator on this value'):e.has(t),be=(e,t,n)=>(vl(e,t,"read from private field"),n?n.call(e):t.get(e)),Fe=(e,t,n)=>t.has(e)?br("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),lt=(e,t,n,r)=>(vl(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Mn=(e,t,n)=>(vl(e,t,"access private method"),n),gc={role:"button",roleDescription:"draggable"},Rx="dnd-kit-description",Dx="dnd-kit-announcement",Px={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Ix={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function Nx(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Wx(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function zx(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var Lx=["dragover","dragmove"],Fx=class extends it{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=Rx,announcement:i=Dx}={},announcements:s=Ix,screenReaderInstructions:o=Px,debounce:a=500}=t??{},d=n?`${r}-${n}`:Qo(r),f=n?`${i}-${n}`:Qo(i);let c,l,u,p;const g=(k=p)=>{!u||!k||u?.nodeValue!==k&&(u.nodeValue=k)},v=()=>vs.schedule(g),b=Bx(v,a),w=Object.entries(s).map(([k,C])=>this.manager.monitor.addEventListener(k,($,T)=>{const j=u;if(!j)return;const M=C?.($,T);M&&j.nodeValue!==M&&(p=M,Lx.includes(k)?b():(v(),b.cancel()))})),h=()=>{let k=[];c?.isConnected||(c=Wx(d,o.draggable),k.push(c)),l?.isConnected||(l=zx(f),u=document.createTextNode(""),l.appendChild(u),k.push(l)),k.length>0&&document.body.append(...k)},x=new Set;function y(){for(const k of x)k()}this.registerEffect(()=>{var k;x.clear();for(const C of this.manager.registry.draggables.value){const $=(k=C.handle)!=null?k:C.element;if($){(!c||!l)&&x.add(h),(!Nx($)||dl())&&!$.hasAttribute("tabindex")&&x.add(()=>$.setAttribute("tabindex","0")),!$.hasAttribute("role")&&$.tagName.toLowerCase()!=="button"&&x.add(()=>$.setAttribute("role",gc.role)),$.hasAttribute("aria-roledescription")||x.add(()=>$.setAttribute("aria-roledescription",gc.roleDescription)),$.hasAttribute("aria-describedby")||x.add(()=>$.setAttribute("aria-describedby",d));for(const j of["aria-pressed","aria-grabbed"]){const M=String(C.isDragging);$.getAttribute(j)!==M&&x.add(()=>$.setAttribute(j,M))}const T=String(C.disabled);$.getAttribute("aria-disabled")!==T&&x.add(()=>$.setAttribute("aria-disabled",T))}}x.size>0&&vs.schedule(y)}),this.destroy=()=>{super.destroy(),c?.remove(),l?.remove(),w.forEach(k=>k())}}};function Bx(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var ys=new Map,xh,bh,yh,wh,Jo,ni,qt,xl,ar,kh,Sh,$h,jh,an=class extends(Jo=wi,wh=[ae],yh=[ze],bh=[ze],xh=[ze],Jo){constructor(e,t){super(e,t),Ve(qt,5,this),Fe(this,ar),Fe(this,ni,new Set),Fe(this,xl,Ve(qt,8,this,new Set)),Ve(qt,11,this),this.registerEffect(Mn(this,ar,kh))}register(e){return be(this,ni).add(e),()=>{be(this,ni).delete(e)}}addRoot(e){return oe(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{oe(()=>{const t=new Set(this.additionalRoots);t.delete(e),this.additionalRoots=t})}}get sourceRoot(){var e;const{source:t}=this.manager.dragOperation;return ps((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return ps((e=t?.element)!=null?e:null)}get roots(){const{status:e}=this.manager.dragOperation;if(e.initializing||e.initialized){const t=[this.sourceRoot,this.targetRoot].filter(n=>n!=null);return new Set([...t,...this.additionalRoots])}return new Set}};qt=yr(Jo);ni=new WeakMap;xl=new WeakMap;ar=new WeakSet;kh=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of be(this,ni))t.push(Mn(this,ar,Sh).call(this,n,r));return()=>{for(const n of t)n()}};Sh=function(e,t){let n=ys.get(e);n||(n=new Map,ys.set(e,n));let r=n.get(t);if(!r){const s=cl(e)?Mn(this,ar,$h).call(this,e,n,t):Mn(this,ar,jh).call(this,e,n,t);if(!s)return()=>{};r=s,n.set(t,r)}r.refCount++;let i=!1;return()=>{i||(i=!0,r.refCount--,r.refCount===0&&r.cleanup())}};$h=function(e,t,n){var r;const i=e.createElement("style"),{nonce:s}=(r=this.options)!=null?r:{};s&&i.setAttribute("nonce",s),i.textContent=n,e.head.prepend(i);const o=new MutationObserver(a=>{for(const d of a)for(const f of Array.from(d.removedNodes))if(f===i){e.head.prepend(i);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),i.remove(),t.delete(n),t.size===0&&ys.delete(e)}}};jh=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:i}=r??{};if(!i)return null;const s=new i;return s.replaceSync(n),e.adoptedStyleSheets.push(s),{refCount:0,cleanup:()=>{var o;if(ul(e)&&(o=e.host)!=null&&o.isConnected){const a=e.adoptedStyleSheets.indexOf(s);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&ys.delete(e)}}};jt(qt,4,"additionalRoots",wh,an,xl);jt(qt,2,"sourceRoot",yh,an);jt(qt,2,"targetRoot",bh,an);jt(qt,2,"roots",xh,an);On(qt,an);an.configure=yi(an);var Ls=an,_x=class extends it{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Ls),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},Si="data-dnd-",ea=`${Si}dropping`,Ge="--dnd-",Pt=`${Si}dragging`,ws=`${Si}placeholder`,qx=[Pt,ws,"popover","aria-pressed","aria-grabbing"],Hx=["view-transition-name"],Ux=`
9
+ :is(:root,:host) [${Pt}] {
10
+ position: fixed !important;
11
+ pointer-events: none !important;
12
+ touch-action: none;
13
+ z-index: calc(infinity);
14
+ will-change: translate;
15
+ top: var(${Ge}top, 0px) !important;
16
+ left: var(${Ge}left, 0px) !important;
17
+ right: unset !important;
18
+ bottom: unset !important;
19
+ width: var(${Ge}width, auto);
20
+ max-width: var(${Ge}width, auto);
21
+ height: var(${Ge}height, auto);
22
+ max-height: var(${Ge}height, auto);
23
+ transform: var(${Ge}transform, none) !important;
24
+ transition: var(${Ge}transition) !important;
25
+ }
26
+
27
+ :is(:root,:host) [${ws}] {
28
+ transition: none;
29
+ }
30
+
31
+ :is(:root,:host) [${ws}='hidden'] {
32
+ visibility: hidden;
33
+ }
34
+
35
+ [${Pt}] * {
36
+ pointer-events: none !important;
37
+ }
38
+
39
+ [${Pt}]:not([${ea}]) {
40
+ translate: var(${Ge}translate) !important;
41
+ }
42
+
43
+ [${Pt}][style*='${Ge}scale'] {
44
+ scale: var(${Ge}scale) !important;
45
+ transform-origin: var(${Ge}transform-origin) !important;
46
+ }
47
+
48
+ @layer dnd-kit {
49
+ :where([${Pt}][popover]) {
50
+ overflow: visible;
51
+ background: unset;
52
+ border: unset;
53
+ margin: unset;
54
+ padding: unset;
55
+ color: inherit;
56
+
57
+ &:is(input, button) {
58
+ border: revert;
59
+ background: revert;
60
+ }
61
+ }
62
+ }
63
+ [${Pt}]::backdrop, [${Si}overlay]:not([${Pt}]) {
64
+ display: none;
65
+ visibility: hidden;
66
+ }
67
+ `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Vx(e,t="hidden"){return oe(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Kx(n,r.registry.droppables),s=[],o=Bv(n),{remove:a}=o;return Gx(i,o,s),Yx(o,t),o.remove=()=>{s.forEach(d=>d()),a.call(o)},o})}function Kx(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${Si}${Qo("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Gx(e,t,n){for(const[r,i]of e){if(!r.element)continue;const s=`[${i}]`,o=t.matches(s)?t:t.querySelector(s);if(r.element.removeAttribute(i),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(i),Ko.set(a,o),n.push(()=>{Ko.delete(a),r.proxy=void 0})}}function Yx(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(ws,t)}function Mh(e,t){return e===t?!0:sr(e)===sr(t)}function vc(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&jn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Zn(t))}function ta(e){return e.tagName==="TR"}function Xx(e,t,n){const r=new MutationObserver(i=>{let s=!1;for(const o of i){if(o.target!==e){s=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||qx.includes(a))continue;const d=e.getAttribute(a);if(a==="style"){if(ti(e)&&ti(t)){const f=e.style;for(const c of Array.from(t.style))f.getPropertyValue(c)===""&&t.style.removeProperty(c);for(const c of Array.from(f)){if(Hx.includes(c)||c.startsWith(Ge))continue;const l=f.getPropertyValue(c);t.style.setProperty(c,l)}}}else d!==null?t.setAttribute(a,d):t.removeAttribute(a)}s&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Qx(e,t,n){const r=new MutationObserver(i=>{for(const s of i)if(s.addedNodes.length!==0)for(const o of Array.from(s.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),Zn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Zn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Zn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Zx(e){return new ResizeObserver(()=>{var t,n,r;const i=new It(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-i.width)*s.x+e.delta.x,a=(e.height-i.height)*s.y+e.delta.y,d=th();if(e.styles.set({width:i.width-e.widthOffset,height:i.height-e.heightOffset,top:e.top+a+d.y,left:e.left+o+d.x},Ge),(n=e.getElementMutationObserver())==null||n.takeRecords(),ta(e.element)&&ta(e.placeholder)){const v=Array.from(e.element.cells),b=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(v.map(w=>w.style.width));for(const[w,h]of v.entries()){const x=b[w];h.style.width=`${x.getBoundingClientRect().width}px`}}const f=(r=e.getTranslate())!=null?r:{x:0,y:0},c=e.left+o+d.x+f.x,l=e.top+a+d.y+f.y,u=i.width-e.widthOffset,p=i.height-e.heightOffset,g=e.frameTransform;e.dragOperation.shape=new Nt(c*g.scaleX+g.x,l*g.scaleY+g.y,u*g.scaleX,p*g.scaleY)})}var Jx=250,eb="ease";function tb(e){var t,n,r,i;const{animation:s}=e;if(typeof s=="function"){const h=s({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(h).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Jx,easing:a=eb}=s??{};Zn(e.feedbackElement);const[,d]=(t=Zu(e.feedbackElement,h=>"translate"in h))!=null?t:[];d?.pause();const f=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Mh(e.feedbackElement,f)?null:void 0},l=new It(e.feedbackElement,c),u=(r=di(Lt(e.feedbackElement).translate))!=null?r:e.translate,p=new It(f,c),g=Nt.delta(l,p,e.alignment),v={x:u.x-g.x,y:u.y-g.y},b=Math.round(l.intrinsicHeight)!==Math.round(p.intrinsicHeight)?{minHeight:[`${l.intrinsicHeight}px`,`${p.intrinsicHeight}px`],maxHeight:[`${l.intrinsicHeight}px`,`${p.intrinsicHeight}px`]}:{},w=Math.round(l.intrinsicWidth)!==Math.round(p.intrinsicWidth)?{minWidth:[`${l.intrinsicWidth}px`,`${p.intrinsicWidth}px`],maxWidth:[`${l.intrinsicWidth}px`,`${p.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Ge),e.feedbackElement.setAttribute(ea,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),uh({element:e.feedbackElement,keyframes:gl(hi(hi({},b),w),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:hl(bt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(ea),d?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Eh,na,fi,bl,Xi,Ch,Th,lr=class extends(na=it,Eh=[ae],na){constructor(e,t){super(e,t),Fe(this,Xi),Fe(this,bl,Ve(fi,8,this)),Ve(fi,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(Ls),r=n?.register(Ux);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(Mn(this,Xi,Ch).bind(this,n)),this.registerEffect(Mn(this,Xi,Th))}};fi=yr(na);bl=new WeakMap;Xi=new WeakSet;Ch=function(e){const{overlay:t}=this;if(!t||!e)return;const n=ps(t);if(n)return e.addRoot(n)};Th=function(){var e,t,n,r,i,s,o;const{state:a,manager:d,options:f}=this,{dragOperation:c}=d,{position:l,source:u,status:p}=c;if(p.idle){a.current={},a.initial={};return}if(!u)return;const{element:g}=u,v=u.pluginConfig(lr),b=(t=(e=v?.feedback)!=null?e:f?.feedback)!=null?t:"default",w=typeof b=="function"?b(u,d):b;if(!g||w==="none"||!p.initialized||p.initializing)return;const{initial:h}=a,x=(n=this.overlay)!=null?n:g,y=or(x),k=or(g),C=!Mh(g,x),$=new It(g,{frameTransform:C?k:null,ignoreTransforms:!C}),T={x:k.scaleX/y.scaleX,y:k.scaleY/y.scaleY};let{width:j,height:M,top:I,left:N}=$;C&&(j=j/T.x,M=M/T.y);const R=new yx(x),L=Lt(g),{transition:B,translate:q,boxSizing:D,paddingBlockStart:F,paddingBlockEnd:E,paddingInlineStart:O,paddingInlineEnd:W,borderInlineStartWidth:U,borderInlineEndWidth:V,borderBlockStartWidth:Y,borderBlockEndWidth:re}=L,H=B.split(",").filter(de=>!/^\s*(transform|translate|scale)\b/.test(de)).join(","),ne=zs(L),Q=L.transform,ge=w==="clone",Z=D==="content-box",Re=Z?parseInt(O)+parseInt(W)+parseInt(U)+parseInt(V):0,De=Z?parseInt(F)+parseInt(E)+parseInt(Y)+parseInt(re):0,X=w!=="move"&&!this.overlay?Vx(u,ge?"clone":"hidden"):null,we=oe(()=>ui(d.dragOperation.activatorEvent));if(!h.translate){if(this.overlay&&ne)h.translate={x:ne.x,y:ne.y};else if(q!=="none"){const de=di(q);de&&(h.translate=de)}}if(!h.transformOrigin){const de=oe(()=>l.current),pe=N+((r=ne?.x)!=null?r:0),He=I+((i=ne?.y)!=null?i:0);h.transformOrigin={x:(de.x-pe*y.scaleX-y.x)/(j*y.scaleX),y:(de.y-He*y.scaleY-y.y)/(M*y.scaleY)}}const{transformOrigin:ye}=h,se=I*y.scaleY+y.y,Pe=N*y.scaleX+y.x;if(!h.coordinates&&(h.coordinates={x:Pe,y:se},T.x!==1||T.y!==1)){const{scaleX:de,scaleY:pe}=k,{x:He,y:Et}=ye;h.coordinates.x+=(j*de-j)*He,h.coordinates.y+=(M*pe-M)*Et}h.dimensions||(h.dimensions={width:j,height:M}),h.frameTransform||(h.frameTransform=y);const Ke={x:h.coordinates.x-Pe,y:h.coordinates.y-se},Ie={width:(h.dimensions.width*h.frameTransform.scaleX-j*y.scaleX)*ye.x,height:(h.dimensions.height*h.frameTransform.scaleY-M*y.scaleY)*ye.y},Qe={x:Ke.x/y.scaleX+Ie.width,y:Ke.y/y.scaleY+Ie.height},Ze={left:N+Qe.x,top:I+Qe.y};x.setAttribute(Pt,"true");const A=oe(()=>c.transform),z=(s=h.translate)!=null?s:{x:0,y:0},K=A.x*y.scaleX+z.x,G=A.y*y.scaleY+z.y,ke=th();R.set({width:j-Re,height:M-De,top:Ze.top+ke.y,left:Ze.left+ke.x,translate:`${K}px ${G}px 0`,transform:this.overlay?"none":Q,transition:H?`${H}, translate 0ms linear`:"translate 0ms linear",scale:C?`${T.x} ${T.y}`:"","transform-origin":`${ye.x*100}% ${ye.y*100}%`},Ge),X&&(g.insertAdjacentElement("afterend",X),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(g)),Yo(x)&&(x.hasAttribute("popover")||x.setAttribute("popover","manual"),Zn(x),x.addEventListener("beforetoggle",vc));let je,Mt,P;const ue=Zx({placeholder:X,element:g,feedbackElement:x,frameTransform:y,transformOrigin:ye,width:j,height:M,top:I,left:N,widthOffset:Re,heightOffset:De,delta:Qe,styles:R,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>je,getSavedCellWidths:()=>P,setSavedCellWidths:de=>{P=de}}),Je=new It(x);oe(()=>c.shape=Je);const Be=bt(x),st=de=>{this.manager.actions.stop({event:de})},ie=hl(Be);we&&Be.addEventListener("resize",st),oe(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),X&&(ue.observe(X),je=Xx(g,X,ge),Mt=Qx(g,X,x));const et=(o=d.dragOperation.source)==null?void 0:o.id,J=()=>{var de;if(!we||et==null)return;const pe=d.registry.draggables.get(et),He=(de=pe?.handle)!=null?de:pe?.element;on(He)&&He.focus()},he=()=>{je?.disconnect(),Mt?.disconnect(),ue.disconnect(),Be.removeEventListener("resize",st),Yo(x)&&(x.removeEventListener("beforetoggle",vc),x.removeAttribute("popover")),x.removeAttribute(Pt),R.reset();const de=()=>{var pe;if(P&&ta(g)){const $r=Array.from(g.cells);for(const[An,Rn]of $r.entries())Rn.style.width=(pe=P[An])!=null?pe:""}u.status="idle";const He=a.current.translate!=null,Et=c.status.dragging;X&&(!Et&&He||X.parentElement!==x.parentElement)&&x.isConnected&&X.replaceWith(x),X?.remove()};x===this.overlay?setTimeout(de,0):de()},Ne=f?.dropAnimation,xe=this,dn=xi(()=>{var de,pe,He;const{transform:Et,status:$r}=c;if(!(!Et.x&&!Et.y&&!a.current.translate)&&$r.dragging){const An=(de=h.translate)!=null?de:{x:0,y:0},Rn={x:Et.x/y.scaleX+An.x,y:Et.y/y.scaleY+An.y},Il=a.current.translate,np=oe(()=>c.modifiers),Hs=oe(()=>{var jr;return(jr=c.shape)==null?void 0:jr.current}),Us=f?.keyboardTransition,Nl=we&&!ie&&Us!==null?`${(pe=Us?.duration)!=null?pe:250}ms ${(He=Us?.easing)!=null?He:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(R.set({transition:H?`${H}, translate ${Nl}`:`translate ${Nl}`,translate:`${Rn.x}px ${Rn.y}px 0`},Ge),je?.takeRecords(),Hs&&Hs!==Je&&Il&&!np.length){const jr=wt.delta(Rn,Il);c.shape=Nt.from(Hs.boundingRectangle).translate(jr.x*y.scaleX,jr.y*y.scaleY)}else c.shape=new It(x);a.current.translate=Rn}},function(){if(c.status.dropped){this.dispose(),u.status="dropping";const de=v?.dropAnimation!==void 0?v.dropAnimation:xe.dropAnimation!==void 0?xe.dropAnimation:Ne;let pe=a.current.translate;const He=pe!=null;if(!pe&&g!==x&&(pe={x:0,y:0}),!pe||de===null){he();return}d.renderer.rendering.then(()=>{tb({source:u,element:g,feedbackElement:x,placeholder:X,translate:pe,moved:He,transition:B,alignment:u.alignment,styles:R,animation:de??void 0,getElementMutationObserver:()=>je,cleanup:he,restoreFocus:J})})}});return()=>{he(),dn()}};jt(fi,4,"overlay",Eh,lr,bl);On(fi,lr);lr.configure=yi(lr);var yl=lr,Er=!0,nb=!1,Oh,Ah,Rh,Dh,Jt,wl,kl;Dh=(Rh=[ae],kt.Forward),Ah=(Oh=[ae],kt.Reverse);var pi=class{constructor(){Fe(this,wl,Ve(Jt,8,this,Er)),Ve(Jt,11,this),Fe(this,kl,Ve(Jt,12,this,Er)),Ve(Jt,15,this)}isLocked(e){return e===kt.Idle?!1:e==null?this[kt.Forward]===Er&&this[kt.Reverse]===Er:this[e]===Er}unlock(e){e!==kt.Idle&&(this[e]=nb)}};Jt=yr(null);wl=new WeakMap;kl=new WeakMap;jt(Jt,4,Dh,Rh,pi,wl);jt(Jt,4,Ah,Oh,pi,kl);On(Jt,pi);var rb=[kt.Forward,kt.Reverse],xc=class{constructor(){this.x=new pi,this.y=new pi}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},ib=class extends it{constructor(e){super(e);const t=dr(new xc);let n=null;this.signal=t,$t(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new xc;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:bc(i.x,n.x),y:bc(i.y,n.y)},o=t.peek();Oe(()=>{for(const a of lu)for(const d of rb)s[a]===d&&o[a].unlock(d);t.value=o})}n=i})}get current(){return this.signal.peek()}};function bc(e,t){return Math.sign(e-t)}var Ph,ra,mi,Sl,Yt,ia,$i=class extends(ra=wi,Ph=[ae],ra){constructor(e){super(e),Fe(this,Sl,Ve(mi,8,this,!1)),Ve(mi,11,this),Fe(this,Yt),Fe(this,ia,()=>{if(!be(this,Yt))return;const{element:s,by:o}=be(this,Yt);o.y&&(s.scrollTop+=o.y),o.x&&(s.scrollLeft+=o.x)}),this.scroll=(s,o)=>{var a;if(this.disabled)return!1;const d=this.getScrollableElements();if(!d)return lt(this,Yt,void 0),!1;const{position:f}=this.manager.dragOperation,c=f?.current;if(c){const{by:l}=s??{},u=l?{x:yc(l.x),y:yc(l.y)}:void 0,p=u?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const g of d){const v=ex(g,l);if(v.x||v.y){const{speed:b,direction:w}=ux(g,c,u,o?.acceleration,o?.threshold);if(p)for(const h of lu)p[h].isLocked(w[h])&&(b[h]=0,w[h]=0);if(w.x||w.y){const{x:h,y:x}=l??w,y=h*b.x,k=x*b.y;if(y||k){const C=(a=be(this,Yt))==null?void 0:a.by;if(this.autoScrolling&&C&&(C.x&&!y||C.y&&!k))continue;return lt(this,Yt,{element:g,by:{x:y,y:k}}),vs.schedule(be(this,ia)),!0}}}}}return lt(this,Yt,void 0),!1};let t=null,n=null;const r=Do(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=nh(ps(o?.element),s.current);return a&&(t=a),a??t}),i=Do(()=>{const s=r.value,{documentElement:o}=xr(s);if(!s||s===o){const{target:a}=e.dragOperation,d=a?.element;if(d){const f=Xo(d,{excludeElement:!1});return n=f,f}}if(s){const a=Xo(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},Ct);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new ib(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!ui(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};mi=yr(ra);Sl=new WeakMap;Yt=new WeakMap;ia=new WeakMap;jt(mi,4,"autoScrolling",Ph,$i,Sl);On(mi,$i);function yc(e){return e>0?kt.Forward:e<0?kt.Reverse:kt.Idle}var sb=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},ob=new sb(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),ab=10,sa=class extends it{constructor(e,t){super(e,t);const n=e.registry.plugins.get($i);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=$t(()=>{var r,i,s;if(this.disabled)return;const{position:o,status:a}=e.dragOperation;if(a.dragging){const d={acceleration:(r=this.options)==null?void 0:r.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(s=this.options)==null?void 0:s.threshold};if(n.scroll(void 0,d)){n.autoScrolling=!0;const f=setInterval(()=>ob.schedule(()=>n.scroll(void 0,d)),ab);return()=>{clearInterval(f)}}else n.autoScrolling=!1}})}};sa.configure=yi(sa);var Ih=sa,wc={capture:!0,passive:!0},Br,lb=class extends wi{constructor(e){super(e),Fe(this,Br),this.handleScroll=()=>{be(this,Br)==null&&lt(this,Br,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),lt(this,Br,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=$t(()=>{var n,r,i;if(t.status.dragging){const s=(i=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?i:document;return s.addEventListener("scroll",this.handleScroll,wc),()=>{s.removeEventListener("scroll",this.handleScroll,wc)}}})}};Br=new WeakMap;var cb="* { user-select: none !important; -webkit-user-select: none !important; }",db=class extends it{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Ls),n=t?.register(cb);if(this.destroy=$t(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return no(),document.addEventListener("selectionchange",no,{capture:!0}),()=>{document.removeEventListener("selectionchange",no,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function no(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var _r=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),qn,ks=class extends rr{constructor(e,t){super(e),this.manager=e,this.options=t,Fe(this,qn,[]),this.listeners=new rh,this.handleSourceKeyDown=(n,r,i)=>{if(this.disabled||n.defaultPrevented||!jn(n.target)||r.disabled)return;const{keyboardCodes:s=_r.keyboardCodes,preventActivation:o=_r.preventActivation}=i??{};s.start.includes(n.code)&&this.manager.dragOperation.status.idle&&(o?.(n,r)||this.handleStart(n,r,i))}}bind(e,t=this.options){return $t(()=>{var n;const r=(n=e.handle)!=null?n:e.element,i=s=>{ui(s)&&this.handleSourceKeyDown(s,e,t)};if(r)return r.addEventListener("keydown",i),()=>{r.removeEventListener("keydown",i)}})}handleStart(e,t,n){const{element:r}=t;if(!r)throw new Error("Source draggable does not have an associated element");e.preventDefault(),e.stopImmediatePropagation(),dh(r);const{center:i}=new It(r);if(this.manager.actions.start({event:e,coordinates:{x:i.x,y:i.y},source:t}).signal.aborted)return this.cleanup();this.sideEffects();const s=xr(r),o=[this.listeners.bind(s,[{type:"keydown",listener:a=>this.handleKeyDown(a,t,n),options:{capture:!0}}])];be(this,qn).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=_r.keyboardCodes}=n??{};if(Pn(e,[...r.end,...r.cancel])){e.preventDefault();const i=Pn(e,r.cancel);this.handleEnd(e,i);return}Pn(e,r.up)?this.handleMove("up",e):Pn(e,r.down)&&this.handleMove("down",e),Pn(e,r.left)?this.handleMove("left",e):Pn(e,r.right)&&this.handleMove("right",e)}handleEnd(e,t){this.manager.actions.stop({event:e,canceled:t}),this.cleanup()}handleMove(e,t){var n,r;const{shape:i}=this.manager.dragOperation,s=t.shiftKey?5:1;let o={x:0,y:0},a=(r=(n=this.options)==null?void 0:n.offset)!=null?r:_r.offset;if(typeof a=="number"&&(a={x:a,y:a}),!!i){switch(e){case"up":o={x:0,y:-a.y*s};break;case"down":o={x:0,y:a.y*s};break;case"left":o={x:-a.x*s,y:0};break;case"right":o={x:a.x*s,y:0};break}(o.x||o.y)&&(t.preventDefault(),this.manager.actions.move({event:t,by:o}))}}sideEffects(){const e=this.manager.registry.plugins.get(Ih);e?.disabled===!1&&(e.disable(),be(this,qn).push(()=>{e.enable()}))}cleanup(){be(this,qn).forEach(e=>e()),lt(this,qn,[])}destroy(){this.cleanup(),this.listeners.clear()}};qn=new WeakMap;ks.configure=yi(ks);ks.defaults=_r;var Nh=ks;function Pn(e,t){return t.includes(e.code)}var vn,ub=class extends Fu{constructor(){super(...arguments),Fe(this,vn)}onEvent(e){switch(e.type){case"pointerdown":lt(this,vn,ir(e));break;case"pointermove":if(!be(this,vn))return;const{x:t,y:n}=ir(e),r={x:t-be(this,vn).x,y:n-be(this,vn).y},{tolerance:i}=this.options;if(i&&_o(r,i)){this.abort();return}_o(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){lt(this,vn,void 0)}};vn=new WeakMap;var Hn,xn,hb=class extends Fu{constructor(){super(...arguments),Fe(this,Hn),Fe(this,xn)}onEvent(e){switch(e.type){case"pointerdown":lt(this,xn,ir(e)),lt(this,Hn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!be(this,xn))return;const{x:t,y:n}=ir(e),r={x:t-be(this,xn).x,y:n-be(this,xn).y};_o(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){be(this,Hn)&&(clearTimeout(be(this,Hn)),lt(this,xn,void 0),lt(this,Hn,void 0))}};Hn=new WeakMap;xn=new WeakMap;var Yn=class{};Yn.Delay=hb;Yn.Distance=ub;var oa=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&jn(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new Yn.Delay({value:250,tolerance:5})]:kx(i)&&!e.defaultPrevented?[new Yn.Delay({value:200,tolerance:0})]:[new Yn.Delay({value:200,tolerance:10}),new Yn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!jn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=qv(r);return i===t.element?!1:!!i}}),Un,Ss=class extends rr{constructor(e,t){super(e),this.manager=e,this.options=t,Fe(this,Un,new Set),this.listeners=new rh,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:n,coordinates:r}=this.latest;!n||!r||this.manager.actions.move({event:n,to:r})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(e,t,n=this.options){const{activationConstraints:r=oa.activationConstraints}=n??{};return typeof r=="function"?r(e,t):r}bind(e,t=this.options){return $t(()=>{var n;const r=new AbortController,{signal:i}=r,s=a=>{wx(a)&&this.handlePointerDown(a,e,t)};let o=[(n=e.handle)!=null?n:e.element];t?.activatorElements&&(Array.isArray(t.activatorElements)?o=t.activatorElements:o=t.activatorElements(e));for(const a of o)a&&(mb(a.ownerDocument.defaultView),a.addEventListener("pointerdown",s,{signal:i}));return()=>r.abort()})}handlePointerDown(e,t,n){if(this.disabled||!e.isPrimary||e.button!==0||!jn(e.target)||t.disabled||fb(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=oa.preventActivation}=n??{};if(r?.(e,t))return;const{target:i}=e,s=on(i)&&i.draggable&&i.getAttribute("draggable")==="true",o=or(t.element),{x:a,y:d}=ir(e);this.initialCoordinates={x:a*o.scaleX+o.x,y:d*o.scaleY+o.y};const f=this.activationConstraints(e,t,n);e.sensor=this;const c=new Pv(f,g=>this.handleStart(t,g));c.signal.onabort=()=>this.handleCancel(e),c.onEvent(e),this.controller=c;const l=Vo(),u=this.listeners.bind(l,[{type:"pointermove",listener:g=>this.handlePointerMove(g,t)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:s?this.handleCancel:Di,options:{capture:!0}}]),p=()=>{u(),this.initialCoordinates=void 0};be(this,Un).add(p)}handlePointerMove(e,t){var n,r;if(((n=this.controller)==null?void 0:n.activated)===!1){(r=this.controller)==null||r.onEvent(e);return}if(this.manager.dragOperation.status.dragging){const i=ir(e),s=or(t.element);i.x=i.x*s.scaleX+s.x,i.y=i.y*s.scaleY+s.y,e.preventDefault(),e.stopPropagation(),this.latest.event=e,this.latest.coordinates=i,vs.schedule(this.handleMove)}}handlePointerUp(e){const{status:t}=this.manager.dragOperation;if(!t.idle){e.preventDefault(),e.stopPropagation();const n=!t.initialized;this.manager.actions.stop({event:e,canceled:n})}this.cleanup()}handleKeyDown(e){e.key==="Escape"&&(e.preventDefault(),this.handleCancel(e))}handleStart(e,t){const{manager:n,initialCoordinates:r}=this;if(!r||!n.dragOperation.status.idle||t.defaultPrevented)return;if(n.actions.start({coordinates:r,event:t,source:e}).signal.aborted)return this.cleanup();t.preventDefault();const i=xr(t.target).body;try{i.setPointerCapture(t.pointerId)}catch{this.handleCancel(t);return}const s=jn(t.target)?[t.target,i]:i,o=this.listeners.bind(s,[{type:"touchmove",listener:Di,options:{passive:!1}},{type:"click",listener:Di},{type:"contextmenu",listener:Di},{type:"keydown",listener:this.handleKeyDown}]);be(this,Un).add(o)}handleCancel(e){const{dragOperation:t}=this.manager;t.status.initialized&&this.manager.actions.stop({event:e,canceled:!0}),this.cleanup()}cleanup(){const{controller:e}=this;this.controller=void 0,e&&!e.signal.aborted&&e.abort(),this.latest={event:void 0,coordinates:void 0},be(this,Un).forEach(t=>t()),be(this,Un).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Un=new WeakMap;Ss.configure=yi(Ss);Ss.defaults=oa;var aa=Ss;function fb(e){return"sensor"in e}function Di(e){e.preventDefault()}function pb(){}var kc=new WeakSet;function mb(e){!e||kc.has(e)||(e.addEventListener("touchmove",pb,{capture:!1,passive:!1}),kc.add(e))}var Jn={modifiers:[],plugins:[Fx,Ih,_x,yl,db],sensors:[aa,Nh]},Wh=class extends Wv{constructor(e={}){const t=Rt(e.plugins,Jn.plugins),n=Rt(e.sensors,Jn.sensors),r=Rt(e.modifiers,Jn.modifiers);super(gl(hi({},e),{plugins:[lb,$i,Ls,...t],sensors:n,modifiers:r}))}},zh,Lh,la,en,$l,jl,Fs=class extends(la=Wt,Lh=[ae],zh=[ae],la){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=gh(n,["element","effects","handle"]);super(hi({effects:()=>[...i(),()=>{var a,d;const{manager:f}=this;if(!f)return;const c=((d=(a=this.sensors)==null?void 0:a.map(ai))!=null?d:[...f.sensors]).map(l=>{const u=l instanceof rr?l:f.registry.register(l.plugin),p=l instanceof rr?void 0:l.options;return u.bind(this,p)});return function(){c.forEach(l=>l())}}]},o),t),Fe(this,$l,Ve(en,8,this)),Ve(en,11,this),Fe(this,jl,Ve(en,12,this)),Ve(en,15,this),this.element=r,this.handle=s}};en=yr(la);$l=new WeakMap;jl=new WeakMap;jt(en,4,"handle",Lh,Fs,$l);jt(en,4,"element",zh,Fs,jl);On(en,Fs);var Fh,Bh,ca,tn,Ml,ro,_h,qh,ri,El,Bs=class extends(ca=zt,Bh=[ae],Fh=[ae],ca){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=gh(n,["element","effects"]);const{collisionDetector:o=hh}=s,a=f=>{const{manager:c,element:l}=this;if(!l||f===null){this.shape=void 0;return}if(!c)return;const u=new It(l),p=oe(()=>this.shape);return u&&p?.equals(u)?p:(this.shape=u,u)},d=dr(!1);super(gl(hi({},s),{collisionDetector:o,effects:()=>[...i(),()=>{const{element:f,manager:c}=this;if(!c)return;const{dragOperation:l}=c,{source:u}=l;d.value=!!(u&&l.status.initialized&&f&&!this.disabled&&this.accepts(u))},()=>{const{element:f}=this;if(d.value&&f){const c=new Jv(f,a);return()=>{c.disconnect(),this.shape=void 0}}},()=>{var f;if((f=this.manager)!=null&&f.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Fe(this,ri),Fe(this,Ml,Ve(tn,8,this)),Ve(tn,11,this),Fe(this,El,Ve(tn,12,this)),Ve(tn,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){lt(this,ri,e,qh)}get element(){var e;return(e=this.proxy)!=null?e:be(this,ri,_h)}};tn=yr(ca);Ml=new WeakMap;ri=new WeakSet;El=new WeakMap;ro=jt(tn,20,"#element",Bh,ri,Ml),_h=ro.get,qh=ro.set;jt(tn,4,"proxy",Fh,Bs,El);On(tn,Bs);function gb(e){return e!=null&&typeof e=="object"&&"current"in e}function er(e){var t;if(e!=null)return gb(e)?(t=e.current)!=null?t:void 0:e}var vb=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",wr=vb?S.useLayoutEffect:S.useEffect;function xb(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Hh(e,t){const n=S.useRef(new Map),r=xb();return wr(()=>{if(!e){n.current.clear();return}return $t(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[d]=a,f=oe(()=>a[1]),c=e[d];f!==c&&(s=!0,n.current.set(d,c),o=(i=t?.(d,f,c))!=null?i:!1)}s&&(o?queueMicrotask(()=>Km.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(i,s){const o=i[s];return n.current.set(s,o),o}}),[e])}function bb(e,t){e()}function In(e){const t=S.useRef(e);return wr(()=>{t.current=e},[e]),t}function Ce(e,t,n=S.useEffect,r=Object.is){const i=S.useRef(e);n(()=>{const s=i.current;r(e,s)||(i.current=e,t(e,s))},[t,e])}function Qi(e,t){const n=S.useRef(er(e));wr(()=>{const r=er(e);r!==n.current&&(n.current=r,t(r))})}var yb=Object.defineProperty,wb=Object.defineProperties,kb=Object.getOwnPropertyDescriptors,$s=Object.getOwnPropertySymbols,Uh=Object.prototype.hasOwnProperty,Vh=Object.prototype.propertyIsEnumerable,Sc=(e,t,n)=>t in e?yb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sb=(e,t)=>{for(var n in t||(t={}))Uh.call(t,n)&&Sc(e,n,t[n]);if($s)for(var n of $s(t))Vh.call(t,n)&&Sc(e,n,t[n]);return e},$b=(e,t)=>wb(e,kb(t)),jb=(e,t)=>{var n={};for(var r in e)Uh.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&$s)for(var r of $s(e))t.indexOf(r)<0&&Vh.call(e,r)&&(n[r]=e[r]);return n},Mb=new Wh,Kh=S.createContext(Mb),Eb=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),i=S.useRef(null),s=S.useRef(null),o=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=i.current)!=null?a:Promise.resolve()}},trackRendering(a){i.current||(i.current=new Promise(d=>{s.current=d})),S.startTransition(()=>{a(),r(d=>d+1)})}}),[]);return wr(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),S.useImperativeHandle(t,()=>o),null})),io=[void 0,Ct];function Cb(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:d}=t,f=jb(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:l,modifiers:u,sensors:p}=f,g=Rt(l,Jn.plugins),v=Rt(p,Jn.sensors),b=Rt(u,Jn.modifiers),w=In(i),h=In(s),x=In(a),y=In(o),k=In(d),C=In(r),$=Tb(()=>{var T;return(T=f.manager)!=null?T:new Wh(f)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:T,trackRendering:j}=c.current,{monitor:M}=$;$.renderer=T;const I=[M.addEventListener("beforedragstart",N=>{const R=w.current;R&&j(()=>R(N,$))}),M.addEventListener("dragstart",N=>{var R;return(R=h.current)==null?void 0:R.call(h,N,$)}),M.addEventListener("dragover",N=>{const R=x.current;R&&j(()=>R(N,$))}),M.addEventListener("dragmove",N=>{const R=y.current;R&&j(()=>R(N,$))}),M.addEventListener("dragend",N=>{const R=k.current;R&&j(()=>R(N,$))}),M.addEventListener("collision",N=>{var R;return(R=C.current)==null?void 0:R.call(C,N,$)})];return()=>I.forEach(N=>N())},[$]),Ce(g,()=>$&&($.plugins=g),...io),Ce(v,()=>$&&($.sensors=v),...io),Ce(b,()=>$&&($.modifiers=b),...io),m.jsxs(Kh.Provider,{value:$,children:[m.jsx(Eb,{ref:c,children:n}),n]})}function Tb(e){const t=S.useRef(null);return t.current||(t.current=e()),S.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function Gh(){return S.useContext(Kh)}function Yh(e){var t;const n=(t=Gh())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),wr(r.register,[n,r]),r}var Ob=Object.create,Xh=Object.defineProperty,Ab=Object.getOwnPropertyDescriptor,Qh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),_s=e=>{throw TypeError(e)},Rb=(e,t,n)=>t in e?Xh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Db=e=>{var t;return[,,,Ob((t=e?.[Qh("metadata")])!=null?t:null)]},Zh=["class","method","getter","setter","accessor","field","value","get","set"],Jh=e=>e!==void 0&&typeof e!="function"?_s("Function expected"):e,Pb=(e,t,n,r,i)=>({kind:Zh[e],name:t,metadata:r,addInitializer:s=>n._?_s("Already initialized"):i.push(Jh(s||null))}),Ib=(e,t)=>Rb(t,Qh("metadata"),e[3]),Nb=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},ef=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=Zh[c+5],v=e[p]||(e[p]=[]),b=(i=i.prototype,Ab(i,n)),w=r.length-1;w>=0;w--)d=Pb(c,n,a={},e[3],v),d.static=l,d.private=u,f=d.access={has:h=>n in h},f.get=h=>h[n],o=(0,r[w])(b[g],d),a._=1,Jh(o)&&(b[g]=o);return b&&Xh(i,n,b),i},tf=(e,t,n)=>t.has(e)||_s("Cannot "+n),Wb=(e,t,n)=>(tf(e,t,"read from private field"),t.get(e)),zb=(e,t,n)=>t.has(e)?_s("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Lb=(e,t,n,r)=>(tf(e,t,"write to private field"),t.set(e,n),n),yn=class da{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new da(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new da(t,n)}},nf,rf,ua,Zi,ji,Cl=class extends(ua=Cn,rf=[ze],nf=[ze],ua){constructor(e){const t=yn.from(e);super(t,(n,r)=>yn.equals(n,r)),Nb(ji,5,this),zb(this,Zi,0),this.velocity={x:0,y:0}}get delta(){return yn.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=yn.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-Wb(this,Zi),o=a=>Math.round(a/s*100);Oe(()=>{Lb(this,Zi,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(yn.from(e)),this.velocity={x:0,y:0}}};ji=Db(ua);Zi=new WeakMap;ef(ji,2,"delta",rf,Cl);ef(ji,2,"direction",nf,Cl);Ib(ji,Cl);var sf=(e=>(e.Horizontal="x",e.Vertical="y",e))(sf||{});Object.values(sf);var Fb=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=yn.distance(t.shape.center,n);return{id:r,value:1/i,type:vr.PointerIntersection,priority:gr.High}}return null},Bb=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=yn.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:vr.ShapeIntersection,priority:gr.Normal}}return null},_b=e=>{var t;return(t=Fb(e))!=null?t:Bb(e)};function qb(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,d=Yh(c=>new Bs($b(Sb({},e),{register:!1,element:er(i)}),c)),f=Hh(d);return Ce(s,()=>d.id=s),Qi(i,c=>d.element=c),Ce(o,()=>d.accept=o,void 0,Ct),Ce(t,()=>d.collisionDetector=t??_b),Ce(n,()=>n&&(d.data=n)),Ce(r,()=>d.disabled=r===!0),Ce(a,()=>d.type=a),{droppable:f,get isDropTarget(){return f.isDropTarget},ref:S.useCallback(c=>{var l,u;!c&&(l=d.element)!=null&&l.isConnected&&!((u=d.manager)!=null&&u.dragOperation.status.idle)||(d.element=c??void 0)},[d])}}const of=(e,t="line")=>{const[n,r]=t==="line"?["6px","2px"]:["10px","6px"];return{cursor:"text",borderRadius:t==="line"?"4px":"6px",mx:`-${n}`,px:n,my:`-${r}`,py:r,transition:`background-color ${nt}`,...kn,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},af=S.createContext(void 0);function lf(e,t){const n=S.useContext(af),r=S.useRef(t);r.current=t,S.useEffect(()=>{if(!n||!e)return;const s=()=>r.current();return n.commitRef.current=s,()=>{n.commitRef.current===s&&(n.commitRef.current=void 0)}},[n,e]);const i=S.useRef(!1);S.useLayoutEffect(()=>{!e&&!i.current||(i.current=e,n?.setDirty(e))},[n,e]),S.useLayoutEffect(()=>()=>{i.current&&n?.setDirty(!1)},[n])}function ha({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:i=!1}){const{theme:s}=qe(),[o,a]=S.useState(void 0),d=S.useRef(!1),f=()=>{d.current||o===void 0||(a(void 0),o!==e&&r(o))};lf(o!==void 0&&o!==e,()=>(f(),!0));const c=()=>{d.current=!1,a(e)};if(o===void 0){const l=e==="",u=l&&i;return m.jsx(_,{component:"button",type:"button",className:u?"builder-affordance":void 0,onClick:c,onKeyDown:p=>{p.key!=="Enter"&&p.key!==" "||(p.preventDefault(),c())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...l&&{fontStyle:"italic",opacity:u?0:.6}},of(s)],children:l?t:e})}return m.jsx(Sd,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:l=>l.target.select(),onChange:l=>a(l.target.value),onKeyDown:l=>{l.key==="Enter"&&!l.nativeEvent.isComposing?f():l.key==="Escape"&&(d.current=!0,a(void 0))},onBlur:f,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Hb=(e,t)=>e.map((n,r)=>{const i=t[r]??!1;if(i===(n.break??!1))return n;const s={...n};return i?s.break=!0:delete s.break,s}),Ub=(e,t,n)=>{const r=[...e],[i]=r.splice(t,1);if(!i)return[...e];const s=r[t];i.break&&s&&!s.break&&(r[t]={...s,break:!0});const o={...i};return delete o.break,r.splice(n,0,o),r},cf=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),df=e=>`gap.${e}`,Vb=(e,t)=>{const n=[];let r=0;e.forEach((s,o)=>{const a=Math.min(s.colspan??1,t),d=o===0||s.break===!0||r+a>t;d&&o>0&&r<t&&n.push({kind:"gap",after:fe(e[o-1]),colspan:t-r}),d&&(r=0),n.push(cf(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:fe(i),colspan:t-r}),n};var Kb=Object.create,uf=Object.defineProperty,Gb=Object.defineProperties,Yb=Object.getOwnPropertyDescriptor,Xb=Object.getOwnPropertyDescriptors,js=Object.getOwnPropertySymbols,hf=Object.prototype.hasOwnProperty,ff=Object.prototype.propertyIsEnumerable,Qb=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Mi=e=>{throw TypeError(e)},fa=(e,t,n)=>t in e?uf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,so=(e,t)=>{for(var n in t||(t={}))hf.call(t,n)&&fa(e,n,t[n]);if(js)for(var n of js(t))ff.call(t,n)&&fa(e,n,t[n]);return e},oo=(e,t)=>Gb(e,Xb(t)),Zb=(e,t)=>{var n={};for(var r in e)hf.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&js)for(var r of js(e))t.indexOf(r)<0&&ff.call(e,r)&&(n[r]=e[r]);return n},Jb=e=>{var t;return[,,,Kb((t=void 0)!=null?t:null)]},pf=["class","method","getter","setter","accessor","field","value","get","set"],qr=e=>e!==void 0&&typeof e!="function"?Mi("Function expected"):e,ey=(e,t,n,r,i)=>({kind:pf[e],name:t,metadata:r,addInitializer:s=>n._?Mi("Already initialized"):i.push(qr(s||null))}),ty=(e,t)=>fa(t,Qb("metadata"),e[3]),Pi=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},mf=(e,t,n,r,i,s)=>{for(var o,a,d,f,c,l=t&7,u=!1,p=!1,g=e.length+1,v=pf[l+5],b=e[g-1]=[],w=e[g]||(e[g]=[]),h=(i=i.prototype,Yb({get[n](){return Hr(this,s)},set[n](y){return bn(this,s,y)}},n)),x=r.length-1;x>=0;x--)f=ey(l,n,d={},e[3],w),f.static=u,f.private=p,c=f.access={has:y=>n in y},c.get=y=>y[n],c.set=(y,k)=>y[n]=k,a=(0,r[x])({get:h.get,set:h.set},f),d._=1,a===void 0?qr(a)&&(h[v]=a):typeof a!="object"||a===null?Mi("Object expected"):(qr(o=a.get)&&(h.get=o),qr(o=a.set)&&(h.set=o),qr(o=a.init)&&b.unshift(o));return h&&uf(i,n,h),i},gf=(e,t,n)=>t.has(e)||Mi("Cannot "+n),Hr=(e,t,n)=>(gf(e,t,"read from private field"),t.get(e)),Cr=(e,t,n)=>t.has(e)?Mi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),bn=(e,t,n,r)=>(gf(e,t,"write to private field"),t.set(e,n),n);function wn(e){return e instanceof Al||e instanceof yf}var Ii=10,ny=class extends it{constructor(e){super(e);const t=$t(()=>{const{dragOperation:r}=e;if(ui(r.activatorEvent)&&wn(r.source)&&r.status.initialized){const i=e.registry.plugins.get($i);if(i)return i.disable(),()=>i.enable()}}),n=e.monitor.addEventListener("dragmove",(r,i)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:s}=i;if(!ui(r.nativeEvent)||!wn(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:d}=i,{by:f}=r;if(!f)return;const c=ry(f),{source:l,target:u}=s,{center:p}=s.shape.current,g=[],v=[];Oe(()=>{for(const k of d.droppables){const{id:C}=k;if(!k.accepts(l)||C===u?.id&&wn(k)||!k.element)continue;let $=k.shape;const T=new It(k.element,{getBoundingClientRect:j=>ci(j,void 0,.2)});!T.height||!T.width||(c=="down"&&p.y+Ii<T.center.y||c=="up"&&p.y-Ii>T.center.y||c=="left"&&p.x-Ii>T.center.x||c=="right"&&p.x+Ii<T.center.x)&&(g.push(k),k.shape=T,v.push(()=>k.shape=$))}}),r.preventDefault(),a.disable();const b=a.computeCollisions(g,jx);Oe(()=>v.forEach(k=>k()));const[w]=b;if(!w)return;const{id:h}=w,{index:x,group:y}=l.sortable;o.setDropTarget(h).then(()=>{const{source:k,target:C,shape:$}=s;if(!k||!wn(k)||!$)return;const{index:T,group:j,target:M}=k.sortable,I=x!==T||y!==j,N=I?M:C?.element;if(!N)return;dh(N);const R=new It(N);if(!R)return;const L=Nt.delta(R,Nt.from($.current.boundingRectangle),k.alignment);o.move({by:L}),I?o.setDropTarget(k.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function ry(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var iy=Object.defineProperty,sy=Object.defineProperties,oy=Object.getOwnPropertyDescriptors,$c=Object.getOwnPropertySymbols,ay=Object.prototype.hasOwnProperty,ly=Object.prototype.propertyIsEnumerable,jc=(e,t,n)=>t in e?iy(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nn=(e,t)=>{for(var n in t||(t={}))ay.call(t,n)&&jc(e,n,t[n]);if($c)for(var n of $c(t))ly.call(t,n)&&jc(e,n,t[n]);return e},Wn=(e,t)=>sy(e,oy(t));function cy(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Ni(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function ao(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function dy(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const d=(h,x)=>h===x||h!==null&&typeof h=="object"&&"id"in h&&h.id===x;if(Array.isArray(e)){const h=e.findIndex(y=>d(y,s.id)),x=e.findIndex(y=>d(y,o.id));if(h===-1||x===-1){if(ao(s)){const y=s.initialIndex,k=s.index;return y===k||y<0||y>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,y,k)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const y=s.index;if(y!==h)return n(e,h,y)}return n(e,h,x)}const f=Object.entries(e);let c=-1,l,u=-1,p;for(const[h,x]of f)if(c===-1&&(c=x.findIndex(y=>d(y,s.id)),c!==-1&&(l=h)),u===-1&&(u=x.findIndex(y=>d(y,o.id)),u!==-1&&(p=h)),c!==-1&&u!==-1)break;if(c===-1&&ao(s)){const h=s.initialGroup==null?void 0:Ni(e,s.initialGroup),x=s.initialIndex,y=s.group==null?void 0:Ni(e,s.group),k=s.index;if(h==null||y==null||h===y&&x===k)return"preventDefault"in t&&t.preventDefault(),e;if(h===y)return Wn(Nn({},e),{[h]:n(e[h],x,k)});const C=e[h][x];return Wn(Nn({},e),{[h]:[...e[h].slice(0,x),...e[h].slice(x+1)],[y]:[...e[y].slice(0,k),C,...e[y].slice(k)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,v=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(p==null){const h=Ni(e,o.id);if(h!=null){const x=o.shape&&v.y>o.shape.center.y?e[h].length:0;p=h,u=x}}if(l==null||p==null||l===p&&c===u){if(l!=null&&l===p&&c===u&&ao(s)){const h=s.group==null?void 0:Ni(e,s.group),x=s.group!=null&&h!==l,y=s.index!==c;if(x||y){const k=s.group==null?l:h;if(k!=null){if(l===k)return Wn(Nn({},e),{[l]:n(e[l],c,s.index)});const C=e[l][c];return Wn(Nn({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[k]:[...e[k].slice(0,s.index),C,...e[k].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===p)return Wn(Nn({},e),{[l]:n(e[l],c,u)});const b=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,w=e[l][c];return Wn(Nn({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[p]:[...e[p].slice(0,u+b),w,...e[p].slice(u+b)]})}function uy(e,t){return dy(e,t,cy)}function Mc(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Ec(e,t,n){var r;for(const[i,s]of t)for(const o of s){const a=e.get(o.id);if(o.index!==a||o.group!==i||!((r=n.get(i))!=null&&r.has(o)))return!0}return!1}var Cc="__default__",hy=class extends it{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof Al){const{sortable:s}=i,{group:o}=s;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(s)}return r},n=[e.monitor.addEventListener("dragover",(r,i)=>{if(this.disabled)return;const{dragOperation:s}=i,{source:o,target:a}=s;if(!wn(o)||!wn(a)||o.sortable===a.sortable)return;const d=t(),f=Mc(d),c=o.sortable.group===a.sortable.group,l=d.get(o.sortable.group),u=c?l:d.get(a.sortable.group);!l||!u||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var p,g;const v=t();if(Ec(f,d,v))return;const b=o.sortable.element,w=a.sortable.element;if(!w||!b||!c&&a.id===o.sortable.group)return;const h=Wi(l),x=c?h:Wi(u),y=(p=o.sortable.group)!=null?p:Cc,k=(g=a.sortable.group)!=null?g:Cc,C={[y]:h,[k]:x},$=uy(C,r);if(C===$)return;const T=$[k].indexOf(o.sortable),j=$[k].indexOf(a.sortable);i.collisionObserver.disable(),Tc(b,T,w,j),Oe(()=>{for(const[M,I]of $[y].entries())I.index=M;if(!c)for(const[M,I]of $[k].entries())I.group=a.sortable.group,I.index=M}),i.actions.setDropTarget(o.id).then(()=>i.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,i)=>{if(!r.canceled)return;const{dragOperation:s}=i,{source:o}=s;wn(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),d=Mc(a),f=a.get(o.sortable.initialGroup);f&&i.renderer.rendering.then(()=>{const c=t();if(Ec(d,a,c))return;const l=Wi(f),u=Wi(f,py),p=o.sortable.element,g=u.indexOf(o.sortable),v=l[g],b=v?.element;!v||!b||!p||(Tc(p,v.index,b,o.index),Oe(()=>{for(const w of a.values()){const h=Array.from(w).values();for(const x of h)x.index=x.initialIndex,x.group=x.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function Tc(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function fy(e,t){return e.index-t.index}function py(e,t){return e.initialIndex-t.initialIndex}function Wi(e,t=fy){return Array.from(e).sort(t)}var Oc=[ny,hy],vf={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Ac(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var zi=new lv,xf,bf,nn,Tl,Ur,Vr,Ol,Vn;bf=[ae],xf=[ae];var qs=class{constructor(e,t){Cr(this,Tl,Pi(nn,8,this)),Pi(nn,11,this),Cr(this,Ur),Cr(this,Vr),Cr(this,Ol,Pi(nn,12,this)),Pi(nn,15,this),Cr(this,Vn),this.register=()=>(Oe(()=>{var g,v;(g=this.manager)==null||g.registry.register(this.droppable),(v=this.manager)==null||v.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Oe(()=>{var g,v;(g=this.manager)==null||g.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Oe(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:d,transition:f=vf,plugins:c}=n,l=Zb(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=Rt(c,Oc),p=Ac(i);this.droppable=new Al(oo(so({},l),{disabled:p.droppable}),t,this),this.draggable=new yf(oo(so({},l),{disabled:p.draggable,plugins:u,effects:()=>[()=>{var g,v,b;const w=(g=this.manager)==null?void 0:g.dragOperation.status;w?.initializing&&this.id===((b=(v=this.manager)==null?void 0:v.dragOperation.source)==null?void 0:b.id)&&zi.clear(this.manager),w?.dragging&&zi.set(this.manager,this.id,oe(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:v,manager:b}=this,w=Hr(this,Vr),h=Hr(this,Ur);(g!==w||v!==h)&&(bn(this,Vr,g),bn(this,Ur,v),this.animate())},()=>{var g,v;const{target:b}=this,{isDragSource:w}=this.draggable;((v=(g=this.draggable.pluginConfig(yl))==null?void 0:g.feedback)!=null?v:"default")==="move"&&w&&(this.droppable.disabled=!b)},...r()],type:d,sensors:a}),t,this),bn(this,Vn,l.element),this.manager=t,this.index=o,bn(this,Vr,o),this.group=s,bn(this,Ur,s),this.type=d,this.transition=f}get initialIndex(){var e,t;return(t=(e=zi.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=zi.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){oe(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:i}=this;if(!i)return;for(const c of i.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const s=this.refreshShape();if(!s)return;const o={x:n.boundingRectangle.left-s.boundingRectangle.left,y:n.boundingRectangle.top-s.boundingRectangle.top},{translate:a}=Lt(i),d=pc(i,a,!1),f=pc(i,a);if(o.x||o.y){const c=hl(bt(i))?oo(so({},t),{duration:0}):t;uh({element:i,keyframes:{translate:[`${d.x+o.x}px ${d.y+o.y}px ${d.z}`,`${f.x}px ${f.y}px ${f.z}`]},options:c}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Oe(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Oe(()=>{const t=Hr(this,Vn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),bn(this,Vn,e)})}get element(){var e,t;const n=Hr(this,Vn);if(n)return(t=(e=Ko.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=Rt(e,Oc)}set disabled(e){const t=Ac(e);Oe(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Oe(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??hh}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Oe(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};nn=Jb();Tl=new WeakMap;Ur=new WeakMap;Vr=new WeakMap;Ol=new WeakMap;Vn=new WeakMap;mf(nn,4,"index",bf,qs,Tl);mf(nn,4,"group",xf,qs,Ol);ty(nn,qs);var yf=class extends Fs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},Al=class extends Bs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},my=Object.defineProperty,gy=Object.defineProperties,vy=Object.getOwnPropertyDescriptors,Rc=Object.getOwnPropertySymbols,xy=Object.prototype.hasOwnProperty,by=Object.prototype.propertyIsEnumerable,Dc=(e,t,n)=>t in e?my(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lo=(e,t)=>{for(var n in t||(t={}))xy.call(t,n)&&Dc(e,n,t[n]);if(Rc)for(var n of Rc(t))by.call(t,n)&&Dc(e,n,t[n]);return e},yy=(e,t)=>gy(e,vy(t));function wy(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:i,data:s,element:o,handle:a,index:d,group:f,disabled:c,modifiers:l,sensors:u,target:p,type:g,plugins:v}=e,b=lo(lo({},vf),e.transition),w=Yh(x=>new qs(yy(lo({},e),{transition:b,register:!1,handle:er(a),element:er(o),target:er(p)}),x)),h=Hh(w,ky);return Ce(i,()=>w.id=i),wr(()=>{Oe(()=>{w.group=f,w.index=d})},[w,f,d]),Ce(g,()=>w.type=g),Ce(t,()=>w.accept=t,void 0,Ct),Ce(s,()=>s&&(w.data=s)),Ce(d,()=>{var x;(x=w.manager)!=null&&x.dragOperation.status.idle&&b?.idle&&w.refreshShape()},bb),Qi(a,x=>w.handle=x),Qi(o,x=>w.element=x),Qi(p,x=>w.target=x),Ce(c,()=>w.disabled=c??!1,void 0,Ct),Ce(u,()=>w.sensors=u,void 0,Ct),Ce(n,()=>w.collisionDetector=n),Ce(r,()=>w.collisionPriority=r),Ce(v,()=>w.plugins=v,void 0,Ct),Ce(b,()=>w.transition=b,void 0,Ct),Ce(l,()=>w.modifiers=l,void 0,Ct),Ce(e.alignment,()=>w.alignment=e.alignment),{sortable:h,get isDragging(){return h.isDragging},get isDropping(){return h.isDropping},get isDragSource(){return h.isDragSource},get isDropTarget(){return h.isDropTarget},handleRef:S.useCallback(x=>{w.handle=x??void 0},[w]),ref:S.useCallback(x=>{var y,k;!x&&(y=w.element)!=null&&y.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.element=x??void 0)},[w]),sourceRef:S.useCallback(x=>{var y,k;!x&&(y=w.source)!=null&&y.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.source=x??void 0)},[w]),targetRef:S.useCallback(x=>{var y,k;!x&&(y=w.target)!=null&&y.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.target=x??void 0)},[w])}}function ky(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const pa="tile",wf="gap",Sy=[aa.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${kf}], ${$y}`)!==null||(aa.defaults.preventActivation?.(e,t)??!1)}),Nh],kf="data-no-drag",$y=".malloy-render, .malloy-table",jy=e=>[...e,yl.configure({feedback:"clone"})];function My({id:e,index:t,disabled:n=!1,children:r}){const{ref:i,handleRef:s,isDragSource:o}=wy({id:e,index:t,disabled:n,type:pa,accept:pa,collisionDetector:pl,plugins:jy});return m.jsx(m.Fragment,{children:r({ref:i,handleRef:s,isDragSource:o})})}function Ey({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=qb({id:e,type:wf,accept:pa,collisionDetector:pl,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:i})})}function Cy({active:e}){const t=Gh();return S.useEffect(()=>{if(!e||!t)return;const n=r=>{r.key!=="Escape"||t.dragOperation.status.idle||(r.preventDefault(),r.stopPropagation(),t.actions.stop({event:r,canceled:!0}))};return window.addEventListener("keydown",n,!0),()=>window.removeEventListener("keydown",n,!0)},[e,t]),null}const Sf=e=>e.ok===!1,_e=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),kr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,Me={sourceDefinition:e=>_e(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>_e(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>_e(e,"VIEW","subQueryDefList"),defDimension:e=>_e(e,"defList","DIMENSION"),exploreProperties:e=>_e(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>_e(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>_e(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>_e(e,"WHERE","filterClauseList"),givenDef:e=>_e(e,"givenNameDef"),givenStatement:e=>_e(e,"GIVEN","givenDefList"),importStatement:e=>_e(e,"IMPORT","importURL"),vArrow:e=>_e(e,"ARROW","vExpr","segExpr"),segRefine:e=>_e(e,"PLUS","segExpr"),segOps:e=>_e(e,"queryProperties"),segField:e=>_e(e,"fieldPath")&&!_e(e,"segExpr"),segParen:e=>_e(e,"OPAREN","CPAREN","vExpr"),compare:e=>_e(e,"fieldExpr","compareOp"),givenRef:e=>_e(e,"GIVEN_REF")};function Ty(e){const t=new Int32Array([...e].length+1);let n=0;for(let r=0;r<e.length;)t[n++]=r,r+=e.codePointAt(r)>65535?2:1;return t[n]=e.length,t}function Oy(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
+ `&&t.push(n+1);return t}function $f(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const i=t.getChild(r);if(!kr(i))continue;const s=Le(i,"docAnnotations");if(s)for(const o of ln(s,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class jf{constructor(t){this.text=t,this.map=Ty(t),this.lineStarts=Oy(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!kr(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const i=this.map[n.startIndex],s=this.map[r.stopIndex+1];if(!(i===void 0||s===void 0||s<i))return{start:i,end:s}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],i=this.map[n.stopIndex+1];if(!(r===void 0||i===void 0||i<r))return{start:r,end:i}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const i=n+r+1>>1;this.lineStarts[i]<=t?n=i:r=i-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function Ei(e,t,n=[]){kr(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Ei(e.getChild(r),t,n);return n}const Ay=e=>_e(e,"OCURLY","CCURLY");function gi(e,t){const n=[],r=i=>{if(kr(i)){if(t(i)){n.push(i);return}if(!Ay(i))for(let s=0;s<(i.childCount??0);s++)r(i.getChild(s))}};for(let i=0;i<(e.childCount??0);i++)r(e.getChild(i));return n}const Le=(e,t)=>e[t]?.call(e),ln=(e,t)=>e[t]?.call(e)??[];function Ry(e,t){if(!Me.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!Me.givenRef(n))return;const r=e.text_(t.getChild(0)),i=e.text_(t.getChild(1)),s=e.text_(n)??"";if(!(r===void 0||i===void 0))return{field:r,op:i.trim(),given:s.replace(/^\$/,"")}}function Mf(e,t){const n=e.positioned(t);if(!n)return;const r=Le(t,"filterClauseList"),i=[];for(const s of r?ln(r,"fieldExpr"):[]){const o=e.positioned(s);if(!o)continue;const a=Ei(s,Me.givenRef).map(d=>e.text_(d)).filter(d=>d!==void 0).map(d=>d.replace(/^\$/,""));i.push({...o,givens:a,binding:Ry(e,s)})}return{...n,clauses:i}}function ma(e,t){const n=e.span(t);if(!n)return;const r=[],i=[];for(const f of gi(t,Me.queryStatement)){const c=e.positioned(f);c&&r.push(c);const l=Le(f,"whereStatement");if(l&&Me.whereStatement(l)){const u=Mf(e,l);u&&i.push(u)}}const s=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
+ `),d=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:s,closeStart:o,statements:r,wheres:i,indent:d,oneLine:a}}function Rl(e,t,n){const r=[],i=e.line(t.start),s=e.line(n);for(let o=i;o<s;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function Dy(e,t){const n=Le(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=Me.vArrow(t);if(Me.segOps(n)){const i=Le(n,"queryProperties"),s=i&&ma(e,i);return s?{kind:"inline",stage:s,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(Me.segField(n)){const i=e.span(n);return i?{kind:"reference",from:e.text.slice(i.start,i.end),fromSpan:i}:{kind:"unsupported",why:"an unreadable name"}}if(Me.segRefine(n)){const i=ln(n,"segExpr"),s=i[0],o=i[i.length-1];let a=s;for(;Me.segRefine(a);){const u=ln(a,"segExpr");if(u.some(p=>Me.segOps(p)||Me.segParen(p)))return{kind:"unsupported",why:"a chained refinement"};a=u[0]}if(a&&Me.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!Me.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const d=e.span(s);if(!d||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!Me.segOps(o)){const u=e.span(n);return u?{kind:"reference",from:e.text.slice(u.start,u.end),fromSpan:u}:{kind:"unsupported",why:"an unreadable refinement"}}const f=e.text.slice(d.start,d.end),c=Le(o,"queryProperties"),l=c&&ma(e,c);return l?{kind:"reference",from:f,fromSpan:d,refinement:l}:{kind:"reference",from:f,fromSpan:d}}return{kind:"unsupported",why:"a parenthesized expression"}}function Py(e,t){const n=[];for(const r of gi(t,Me.defExploreQuery)){const i=e.span(r),s=Le(r,"subQueryDefList");if(!i||!s)continue;const o=ln(s,"exploreQueryDef").filter(Me.exploreQueryDef),a=e.terminal(Le(r,"VIEW"));for(const d of o){const f=e.span(d),c=Le(d,"exploreQueryNameDef"),l=e.text_(c),u=Le(d,"vExpr");!f||!l||!u||n.push({name:l,span:f,line:e.line(f.start),statement:i,tags:Rl(e,i,a?.start??f.start),siblings:o.length,body:Dy(e,u)})}}return n}function Iy(e,t){const n=[];for(const r of gi(t,Me.defDimension)){const i=e.span(r),s=Le(r,"defList");if(!i||!s)continue;const o=e.terminal(Le(r,"DIMENSION"));for(const a of ln(s,"fieldDef")){const d=e.span(a),f=e.text_(Le(a,"fieldNameDef"))?.trim(),c=e.text_(Le(a,"fieldExpr"))?.trim();!d||!f||c===void 0||n.push({name:f,expression:c,span:d,line:e.line(d.start),statement:i,tags:Rl(e,i,o?.start??d.start)})}}return n}function Ny(e,t){const n=[];for(const r of Ei(t,Me.sourceDefinition)){const i=e.span(r),s=e.text_(Le(r,"sourceNameDef")),o=Le(r,"sqExplore");if(!i||!s||!o)continue;const a=e.span(o),d=a?e.text.slice(a.start,a.end):"",f=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(d)?.[1]??"").trim(),c=gi(o,Me.exploreProperties)[0],l=c&&ma(e,c),u={start:e.lineStarts[e.line(i.start)],end:i.end},p=[];if(c)for(const g of gi(c,Me.whereStatement)){const v=Mf(e,g);v&&p.push(v)}n.push({name:s,base:f,span:i,line:e.line(i.start),statement:u,...l?{properties:l}:{},views:c?Py(e,c):[],dimensions:c?Iy(e,c):[],wheres:p})}return n}function Wy(e,t){const n=[];for(const r of Ei(t,Me.givenStatement)){const i=e.terminal(Le(r,"GIVEN")),s=Le(r,"givenDefList"),o=i?e.line(i.start):void 0;for(const a of s?ln(s,"givenDef"):[]){const d=e.span(a),f=e.span(Le(a,"givenNameDef")),c=f&&e.text.slice(f.start,f.end);if(!d||!f||!c)continue;const l={start:f.start,end:d.end},u=e.line(l.start);n.push({name:c,declaration:e.text.slice(l.start,l.end),span:l,line:u,statement:{start:e.lineStarts[u],end:l.end},tags:Rl(e,d,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function zy(e,t){const n=[];for(const r of Ei(t,Me.importStatement)){const i=e.span(r),s=e.text_(Le(r,"importURL"));if(!i||s===void 0)continue;const o=Le(r,"importSelect"),a=o?ln(o,"importItem").map(d=>e.text_(d)).filter(d=>d!==void 0).map(d=>d.trim()):void 0;n.push({from:s.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:i,line:e.line(i.start),statement:i})}return n}async function Ef(e){let t;try{t=await Dl(e,"file://dashboard-builder.malloy")}catch(u){return{ok:!1,reason:`Malloy could not read this file: ${u}`}}const n=t.problems.filter(u=>u.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,i=r?.root;if(!i||!kr(i)||typeof i.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const s=r?.tokenStream??{},o=typeof s.getTokens=="function"?s.getTokens():void 0;if(!o||typeof s.tokenSource?.vocabulary?.getSymbolicName!="function"||o.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new jf(e),d=Ly(a,s);a.commentLines=d.lines;const f=e.split(`
70
+ `),c=u=>d.lines.has(u);a.proseLines=Im(f,c),a.blocks=Nm(f,c).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=Ny(a,i);return l.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:zy(a,i),sources:l,givens:Wy(a,i),textBlocks:By(a,s),modelNotes:$f(a,i),trailingComment:u=>d.trailing.get(u),comments:d.all,commentLine:u=>d.lines.has(u),proseLine:u=>a.proseLines.has(u),commentIn:u=>d.all.find(p=>p.start>=u.start&&p.start<u.end),blockStart:u=>Fy(a,d.lines,u)}}}async function Dl(e,t){const{MalloyTranslator:n}=await am(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Ly(e,t){const n=new Map,r=new Set,i=[],s=t.tokenSource?.vocabulary;for(const c of t.getTokens?.()??[]){const l=s?.getSymbolicName(c.type);if(l!=="COMMENT_TO_EOL"&&l!=="BLOCK_COMMENT")continue;const u=e.utf16(c.startIndex);let p=e.utf16(c.stopIndex+1);if(!(u===void 0||p===void 0||p<u)){for(;p>u&&(e.text[p-1]===`
71
+ `||e.text[p-1]==="\r");)p--;i.push({start:u,end:p})}}const o=[...i].sort((c,l)=>c.start-l.start);let a="",d=0;for(const c of o)a+=e.text.slice(d,Math.max(d,c.start)),a+=e.text.slice(Math.max(d,c.start),Math.max(d,c.end)).replace(/[^\n\r]/g," "),d=Math.max(d,c.end);a+=e.text.slice(d);const f=c=>a.slice(e.lineStarts[c],e.lineStarts[c+1]??a.length);for(const c of i){const l=e.line(c.start),u=e.line(c.end-1);for(let v=l;v<=u;v++)f(v).trim()===""&&r.add(v);const p=a.slice(e.lineStarts[l],c.start).trim(),g=a.slice(c.end,e.lineStarts[u+1]??a.length).trim();p!==""&&g===""&&n.set(u,c)}return{trailing:n,lines:r,all:i}}function Fy(e,t,n){const r=s=>e.text.slice(e.lineStarts[s],e.lineStarts[s+1]??e.text.length).trim();let i=n;for(let s=n-1;s>=0;s--){const o=r(s),a=e.blocks.find(([,d])=>d===s);if(a){i=s=a[0];continue}if(o===""&&!t.has(s))break;if(o.startsWith("#")||t.has(s))i=s;else break}return i}function By(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,i=a=>r?.getSymbolicName(a.type),s=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),o=[];for(let a=0;a<n.length;a++){if(i(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const d=Hm(s(n[a]).replace(/\r?\n$/,""));if(!d)continue;const f=[];let c=a+1;for(;i(n[c]??n[a])==="BLOCK_ANNOTATION_TEXT";c++)f.push(s(n[c]));const l=n[c];if(!l||i(l)!=="BLOCK_ANNOTATION_END")continue;const u=e.line(e.utf16(n[a].startIndex)??0),p=e.utf16(l.stopIndex+1)??e.text.length,g=d.name===void 0&&d.rest?[`${d.rest}
72
+ `]:[];o.push({...d.name===void 0?{}:{name:d.name},route:d.route,body:[...g,...f].join("").replace(/\r\n?/g,`
73
+ `).replace(/\n$/,""),span:{start:e.lineStarts[u],end:p},line:u}),a=c}return o}function Cf(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function Tf(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')r=Cf(e,r);else if(i==="{"||i==="[")t++===0&&n++;else if(i==="}"||i==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const s=/^tiles\s*=\s*\[/.exec(e.slice(r));if(s)return _y(e,r+s[0].length-1)}}}function _y(e,t){const n=[];let r=0,i=t+1;const s=o=>{const a=e.slice(i,o),d=a.length-a.trimStart().length,f=a.trim();f!==""&&n.push({text:f,span:{start:i+d,end:i+d+f.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=Cf(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return s(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(s(o),i=o+1)}}function qy(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
74
+ `)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const i=e.indexOf(`
75
+ `,r),s=i===-1?e.length:i;if(e.slice(r,s).trim()===">>>")return s;if(i===-1)return e.length;r=i+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let i=t+3;i<e.length;i++)if(e[i]==="\\")i++;else if(e.startsWith(r,i))return i+3;return e.length}for(let i=t+1;i<e.length;i++)if(e[i]==="\\")i++;else{if(e[i]===n)return i+1;if(e[i]===`
76
+ `)return i}return e.length}return t}function Hy(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=qy(e,r);if(i>r){n+=e.slice(r,i),r=i;continue}const s=e[r];if(/[=[,]/.test(s)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${s}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=s,r+=1}return n}function Of(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(s=>{if(e([s]).log.length===0)return s;const o=Hy(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const Pc=(e,t)=>{try{return e.text(t)}catch{return}},Uy=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Vy=e=>`\`kind=${e}\` is no longer read, so this file is not a report. Fix: remove \`kind=${e}\` and write \`layout=grid\` or \`layout=linear\`.`,Ky=e=>`\`layout=${e}\` is not a layout Publisher knows (grid, linear), and the tag lists no tiles, so this file is not a report. Fix: write \`layout=grid\` or \`layout=linear\`, and list the tiles in \`tiles=[…]\`.`,Gy="A linear report written as `run:` cells is no longer read, so this file is not a report. Fix: list its tiles in `tiles=[…]` (a text tile per prose block, a query tile per view), or remove the `## artifact` tag.";function Af(e,t){const n=e.filter(Uy).filter(c=>!c.includes("@env.")).map(bd),{tag:r,errors:i}=n.length>0?Of(t,n):{tag:void 0,errors:[]},s=r?.tag("artifact");if(!s)return e.some(lm)?{status:"unparsed",errors:i}:{status:"none"};const o=Pc(s,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=Pc(s,"layout"),d=s.has("tiles");if(d&&s.array("tiles")===void 0)return{status:"unparsed",errors:i};const f=a==="grid"||a==="linear"?a:d||r?.tag("dashboard")!==void 0?"grid":"linear";return f==="linear"&&!d?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:f}}async function Gw(e){const{parseAnnotation:t}=await ud();let n=[];try{const r=(await Dl(e,"file://report.malloy")).parse?.root;r&&kr(r)&&typeof r.getChild=="function"&&(n=$f(new jf(e),r))}catch{n=[]}return Af(n,t)}const ga=e=>e.ok===!1;function Sr(e,t,n){const r=e.blockStart(n),i=[],s=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){s.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&i.push({line:o,text:a})}return{start:r,tags:i,prose:s}}const tr=e=>e.map(t=>t.text);function Ic(e){const t=tr(e),n=Wm(t),r=t.map(Aa).filter(Boolean).at(-1),i=r?{color:r}:{};return n===void 0?i:n==="custom"?{chart:n,chartLines:zm(t),...i}:{chart:n,...i}}function Nc(e,t){return tr(e).some(n=>Aa(n)===void 0&&t([n]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Yy(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:i,op:s,given:o}=r.binding;t.push({field:Lm(i),given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function Xy(e,t,n){const r=[];for(const i of e.givens){const s=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(i.declaration);s&&r.push({name:s[1],type:s[2],default:s[3].trim(),...Qy(n(tr(Sr(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function Qy(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),i=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...i===void 0?{}:{rangeMax:i}}}function Wc(e){const t=e?.numeric("colspan");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:!0}:{}}}function Kr(e,t){const n=e?.text(t)?.trim();if(n===void 0||!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(n))return;const r=Number(n);return Number.isInteger(r)&&r>=1?r:void 0}const Zy=/^"((?:[^"\\]|\\.)+)"\s*(\{[\s\S]*\})?$/;function co(e){const t=Kr(e,"colspan"),n=Kr(e,"rowspan"),r=Kr(e,"row"),i=Kr(e,"col");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:e.text("break")!=="false"}:{},...n===void 0?{}:{rowspan:n},...r===void 0?{}:{row:r},...i===void 0?{}:{col:i}}}function Tr(e,t){const n=t.colspan??e.colspan;return{...n===void 0?{}:{colspan:n},...t.break??e.break?{break:!0}:{},...t.rowspan===void 0?{}:{rowspan:t.rowspan},...t.row===void 0?{}:{row:t.row},...t.col===void 0?{}:{col:t.col}}}const Jy=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,e0=/^[A-Za-z_][A-Za-z0-9_]*$/;function t0(e,t,n){const r=new RegExp(`^\\s*query\\s*:\\s*${n}\\s+is\\b`);for(let i=0;i<t.length;i++)if(!(e.commentLine(i)||e.proseLine(i))&&r.test(t[i]))return Sr(e,t,i).tags;return[]}function zc(e){return{...e?.text("label")?{label:e.text("label")}:{},...e?.text("subtitle")?{subtitle:e.text("subtitle")}:{},...e?.numeric("colspan")!==void 0?{colspan:e.numeric("colspan")}:{},...e?.has("break")?{break:!0}:{},...e?.has("borderless")?{borderless:!0}:{}}}function Lc(e){const{colspan:t,break:n,...r}=e;return r}async function va(e,t,n=!1){try{return await n0(e)}catch(r){return{ok:!1,reason:`A value in this file's tags cannot be read (${r instanceof Error?r.message:String(r)}), so it cannot be opened in the builder.`}}}async function n0(e){const{parseAnnotation:t}=await ud(),n=rm(e),r=await Ef(e);if(Sf(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,s=xd(n).text,o=Af(i.modelNotes,t);if(o.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(o.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${o.errors[0]?`: ${o.errors[0]}`:"."}`};if(o.status==="kind-removed")return{ok:!1,reason:Vy(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?Ky(o.unknownLayout):Gy};const a=o.layout,d=Ca(n);if(d===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!im(d.text))return{ok:!1,reason:sm,line:d.from+1};const{tag:f,errors:c}=Of(t,[bd(d.text)]),l=f?.tag("artifact"),u=Tf(d.text);if(u===void 0)return c.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${c[0]}`}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const p=i.imports.map($=>$.names?{kind:"names",names:$.names,from:$.from}:{kind:"all",from:$.from}),g=[],v=[],b=new Map;for(const $ of i.sources){const T={name:$.name,base:$.base};$.dimensions.length>0&&(T.dimensions=$.dimensions.map(M=>({name:M.name,expression:M.expression})));const j=new Set($.wheres.flatMap(M=>M.clauses.flatMap(I=>I.givens)));j.size>0&&(T.scopedBy=Array.from(j)),g.push(T);for(const M of $.dimensions){const I=t(tr(Sr(i,n,M.line).tags)).tag?.tag("drill");if(!I)continue;const N=I.textArray("to")??[I.text("to")??""];v.push({source:$.name,name:M.name,expression:M.expression,to:N.filter(Boolean),...I.text("given")?{given:I.text("given")}:{}})}b.set($.name,new Map($.views.map(M=>[M.name,M])))}const w=[],h=($,T)=>{const j=zc(t(tr(t0(i,n,$))).tag);return{name:$,declaration:{kind:"query"},...Lc(j),...Tr({colspan:j.colspan,break:j.break},T)}};for(const{text:$}of u.entries){const T=Zy.exec($),j=T?void 0:Jy.exec($)?.[1];if(j!==void 0){const E=t([`# ${$}`]).tag?.tag(j),O=E?.text("kind");if(O===void 0||O==="query"){w.push(h(j,co(E)));continue}if(O!=="text")return{ok:!1,reason:`The tile \`${$}\` is neither a quoted \`source -> view\` expression nor a \`${j} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(w.some(W=>Ee(W)&&W.name===j))return{ok:!1,reason:`Two text tiles are named \`${j}\`, so the builder cannot tell them apart.`};w.push({kind:"text",name:j,markdown:i.textBlocks.find(W=>W.name===j)?.body??"",...Tr({},co(E))});continue}const M=T?.[1]??$,I=co(T?.[2]?t([`# tile ${T[2]}`]).tag?.tag("tile")??void 0:void 0);if(e0.test(M.trim())){w.push(h(M.trim(),I));continue}const N=T?om(M):void 0;if(!N)return{ok:!1,reason:`The tile \`${M}\` is neither a \`source -> view\` expression nor the name of a query, which are the forms the builder can lay out.`};const{source:R,view:L}=N,B=b.get(R)?.get(L);if(B===void 0){w.push({name:L,source:R,declaration:{kind:"inherited"},...Tr({},I)});continue}const q=t(tr(B.tags)).tag,D=B.body.kind==="reference"?{kind:"reference",from:B.body.from}:B.body.kind==="inline"?{kind:"inline"}:void 0;if(D===void 0){w.push({name:L,source:R,declaration:{kind:"opaque",why:B.body.kind==="unsupported"?B.body.why:"unreadable"},...Lc(zc(q)),...Tr(Wc(q),I),...Ic(B.tags),...Nc(B.tags,t)});continue}const F=Yy(B.body.kind==="reference"?B.body.refinement:B.body.kind==="inline"?B.body.stage:void 0);w.push({name:L,source:R,declaration:D,...F?{filters:F}:{},...q?.text("label")?{label:q.text("label")}:{},...q?.text("subtitle")?{subtitle:q.text("subtitle")}:{},...Tr(Wc(q),I),...Ic(B.tags),...Nc(B.tags,t),...q?.has("borderless")?{borderless:!0}:{}})}const x=Xy(i,n,t),y={},k=l?.tag("givens");for(const $ of Object.keys(k?.dict??{})){const T=k?.text($);T!==void 0&&(y[$]=T)}const C=f?.tag("dashboard")?.has("columns")?Kr(f.tag("dashboard"),"columns"):void 0;return{ok:!0,document:{layout:a,title:l?.text("title")??"",...s?{description:s}:{},...C===void 0?{}:{columns:C},...l?.has("autorun")?{autorun:l.isTrue("autorun")}:{},imports:p,sources:g,...x?{localGivens:x}:{},...Object.keys(y).length>0?{startingGivens:y}:{},...v.length>0?{drills:v}:{},tiles:w}}}const xa=e=>e.ok===!1;async function Fc(e){const{problems:t}=await Dl(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function $e(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const i of Object.keys(n).sort())r[i]=t(n[i]);return r}return n};return JSON.stringify(t(e))}function Rf(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function r0(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
+ `&&t.push(n+1);return t}function i0(e,t){let n=e;const r=t.map((i,s)=>({edit:i,index:s}));for(const{edit:i}of r.sort((s,o)=>o.edit.start-s.edit.start||o.edit.end-s.edit.end||o.index-s.index))n=n.slice(0,i.start)+i.text+n.slice(i.end);return n}const Df=e=>e==="none"||Os(e)?e:void 0;function Pf(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${At(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${At(e.subtitle)}`);const r=t?Df(e.chart):void 0;return r!==void 0&&n.push(Qn(r,e.chartCarried)),e.color!==void 0&&n.push($d(e.color)),n}const If="theme.palette.series";function Ji(e){return Aa(e)!==void 0?If:/^#\s*([a-z_]+)/.exec(e)?.[1]}const s0=new Set(["colspan","break","borderless","label","subtitle",If]),o0=new Set(["label","description","control","suggest","range_min","range_max"]);function Bc(e){const t=[];if(e.label!==void 0&&t.push(`label=${At(e.label)}`),e.description!==void 0&&t.push(`description=${At(e.description)}`),e.control!==void 0&&t.push(`control=${e.control}`),e.suggest){const n=e.suggest.source!==void 0?`source=${e.suggest.source}`:e.suggest.query!==void 0?`query=${At(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${At(e.suggest.dimension)} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const _c=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function a0(e,t,n){const r=e.sources.find(i=>i.name===t)?.views.find(i=>i.name===n);return r?r.line:-1}function qc(e){const t=n=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(n)?n:At(n);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(At).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ms=e=>`${e.source}.${e.name}`,At=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,ba=e=>Ee(e)?$e(["text",e.name]):$e([e.name,e.source,e.declaration]),ct=ba,Hc=e=>$e(e.tiles.map(ct));function l0(e,t,n){const r=new Set(e.tiles.map(ct)),i=new Set(t.tiles.map(ct)),s=e.tiles.filter(u=>!i.has(ct(u))),o=t.tiles.filter(u=>!r.has(ct(u))),a=s.length>0||o.length>0||Hc(e)!==Hc(t);for(const u of o)if(le(u)&&u.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${u.name}\` is ${u.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const d=new Map(e.sources.map(u=>[u.name,u])),f=new Set(t.imports.flatMap(u=>u.kind==="names"?u.names:[]));for(const u of e.sources)f.add(u.base);const c=t.imports.some(u=>u.kind==="all"),l=t.sources.filter(u=>!d.has(u.name));for(const u of e.sources){const p=t.sources.find(g=>g.name===u.name);if(!p||p.base!==u.base)return{ok:!1,reason:`The source \`${u.name}\` cannot be changed or removed here.`}}for(const u of l){if(!o.some(p=>le(p)&&p.source===u.name))return{ok:!1,reason:`A new source \`${u.name}\` needs a tile on it.`};if(!f.has(u.base)&&!c&&!n?.includes(u.base))return{ok:!1,reason:`\`${u.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:i,removedTiles:s,addedTiles:o,newSources:l,currentSources:d,reordered:a}}const c0=new Set(["colspan","break"]),ya=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break||e.rowspan!==t.rowspan||e.row!==t.row||e.col!==t.col,Uc=e=>{const{colspan:t,break:n,rowspan:r,row:i,col:s,...o}=e;return o},d0=e=>[...e.row===void 0?[]:[`row=${e.row}`],...e.col===void 0?[]:[`col=${e.col}`],...e.colspan===void 0?[]:[`colspan=${e.colspan}`],...e.break?["break"]:[],...e.rowspan===void 0?[]:[`rowspan=${e.rowspan}`]];function Nf(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=wa(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Vc(e,t){const n=d0(e);if(t===void 0){const c=Ee(e)?e.name:`"${vt(e)}"`,l=[...Ee(e)?["kind=text"]:[],...n];return l.length>0?`${c} { ${l.join(" ")} }`:c}const r=Nf(t),i=r.indexOf("{");if(i===-1)return n.length>0?`${t} { ${n.join(" ")} }`:t;const s=r.lastIndexOf("}");let o=t.slice(i+1,s),a=r.slice(i+1,s);const d=c=>{const l=c.exec(a);l&&(o=o.slice(0,l.index)+o.slice(l.index+l[0].length),a=a.slice(0,l.index)+a.slice(l.index+l[0].length))};d(/\s*\bcolspan\s*=\s*[^\s}]+/),d(/\s*\bbreak\b(?:\s*=\s*[^\s}]+)?/),d(/\s*\browspan\s*=\s*[^\s}]+/),d(/\s*\brow\s*=\s*[^\s}]+/),d(/\s*\bcol\s*=\s*[^\s}]+/);const f=[o.trim(),...n].filter(Boolean);return f.length===0?t.slice(0,i).trimEnd():`${t.slice(0,i)}{ ${f.join(" ")} }${t.slice(s+1)}`}function u0(e){const{lines:t,wholeLine:n,current:r,next:i,reordered:s,currentKeys:o,nextKeys:a,edits:d}=e,f=new Map(r.tiles.map(h=>[ct(h),h])),c=i.tiles.some(h=>{const x=f.get(ct(h));return x!==void 0&&ya(x,h)});if(!s&&!c)return;const l=Ca(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,p=Tf(u);if(!p)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&o.size>0)return{ok:!1,reason:"A grid report with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const g=new Map;for(const{text:h}of p.entries){const x=/^"((?:[^"\\]|\\.)+)"\s*(?:\{[\s\S]*\})?$/.exec(h);if(x){const k=x[1].split("->").map(C=>C.trim());k.length===2?g.set(`${k[0]}->${k[1]}`,h):k.length===1&&g.set(`query.${k[0]}`,h);continue}if(jd(h)){g.set(`query.${h}`,h);continue}const y=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(h)?.[1];y!==void 0&&g.set(/\bkind\s*=\s*text\b/.test(Nf(h))?`text.${y}`:`query.${y}`,h)}const v=i.tiles.map(h=>{const x=!o.has(ct(h)),y=g.get(Ee(h)?`text.${h.name}`:h.declaration.kind==="query"?`query.${h.name}`:`${h.source}->${h.name}`);if(y===void 0)return x?Vc(h):void 0;const k=f.get(ct(h));return k!==void 0&&!ya(k,h)?y:Vc(h,y)});if(v.some(h=>h===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const b=u.slice(0,p.open).search(/tiles\s*=\s*$/),w=`${u.slice(0,b)}tiles=[${h0(u,p,v)}]${u.slice(p.close+1)}`;w!==u&&d.push({...Wf(n,l),text:`${w}
78
+ `})}function Wf(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function h0(e,t,n){const r=t.entries[0],i=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const s=e.slice(t.open+1,r.span.start),o=e.slice(i.span.end,t.close),a=s.slice(s.lastIndexOf(`
79
+ `)),d=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
80
+ `)?a:" "}`;return`${s}${n.join(d)}${o}`}function f0(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=wa(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const i=/^dashboard\s*\{/.exec(e.slice(n));if(!i)continue;let s=1,o=n+i[0].length;for(;o<e.length&&s>0;o++)e[o]==='"'?o=wa(e,o):e[o]==="{"?s++:e[o]==="}"&&s--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function wa(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function p0(e){const{lines:t,wholeLine:n,current:r,next:i,edits:s}=e;if(r.layout!==i.layout||r.title!==i.title||r.autorun!==i.autorun||r.columns!==i.columns||$e(r.startingGivens)!==$e(i.startingGivens)){const o=Ca(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=Wf(n,o),d=s.find(x=>x.start===a.start&&x.end===a.end);let f=d?d.text.replace(/\n$/,""):o.text;const c=r.layout!==i.layout,l=f.indexOf("artifact"),u=f.indexOf("{",l);let p=0,g=-1;for(let x=u;x<f.length;x++)if(f[x]==="{")p++;else if(f[x]==="}"&&--p===0){g=x;break}if(u<0||g<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let v=f.slice(u+1,g);const b=o.block?`
81
+ ${/\n([ \t]+)\S/.exec(v)?.[1]??" "}`:" ",w=x=>o.block?`${v.trimEnd()}${b}${x}
82
+ `:`${v.trimEnd()} ${x} `,h=(x,y)=>{const k=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${x}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(y===void 0){const C=new RegExp(`
83
+ ${k.source}[ \\t]*(?=
84
+ )`);v=v.replace(o.block&&C.test(v)?C:k,"")}else k.test(v)?v=v.replace(k,C=>`${o.block?C.slice(0,C.length-C.trimStart().length):" "}${x}=${y}`):v=w(`${x}=${y}`)};if(c&&h("layout",i.layout),r.title!==i.title&&h("title",i.title?At(i.title):void 0),r.autorun!==i.autorun&&h("autorun",i.autorun===void 0?void 0:String(i.autorun)),$e(r.startingGivens)!==$e(i.startingGivens)){v=v.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const x=Object.entries(i.startingGivens??{});x.length>0&&(v=w(`givens { ${x.map(([y,k])=>`${y}=${At(k)}`).join(" ")} }`))}o.block?f=`${f.slice(0,u+1)}${v}${f.slice(g)}`:(v=v.replace(/\s{2,}/g," "),f=`${f.slice(0,u+1)}${v.startsWith(" ")?v:` ${v}`}${v.endsWith(" ")?"":" "}${f.slice(g)}`),r.columns!==i.columns&&(f=f0(f),i.columns!==void 0&&(f=`${f.trimEnd()} dashboard { columns=${i.columns} }`)),d?d.text=`${f}
85
+ `:s.push({...a,text:`${f}
86
+ `})}if(r.description!==i.description){const{read:o,blankAbove:a,below:d,belowBlock:f,inBlock:c}=xd(t);if(c||i.description===void 0&&f)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const l=Rf(i.description??"").split(`
87
+ `).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
88
+ `),u=o.length>0&&o[0]<Fl(t),p=i.description===void 0,g=u?[...o.slice(1),...p?d:[]]:[...o,...a];for(const v of g)s.push({...n(v),text:""});if(u)s.push({...n(o[0]),text:i.description===void 0?"":`${l}
89
+ `});else if(i.description!==void 0){const v=n(Fl(t)).start;s.push({start:v,end:v,text:`${l}
90
+ `})}}}function m0(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,d=new Map((i.localGivens??[]).map(p=>[p.name,p])),f=new Map((s.localGivens??[]).map(p=>[p.name,p])),c=new Map(a.givens.map(p=>[p.name,p])),l=new Set;for(const[p,g]of d){const v=f.get(p);if(v!==void 0&&$e(v)===$e(g))continue;const b=c.get(p);if(b===void 0)return{ok:!1,reason:`Could not find where the given \`${p}\` is declared.`};const{tags:w,prose:h}=Sr(a,t,b.line),x=[...(v===void 0?w:w.filter(T=>{const j=Ji(T.text);return j!==void 0&&o0.has(j)})).map(T=>T.line),...v===void 0?h:[]];for(const T of x)o.push({...n(T),text:""}),l.add(T);const y=Vt(a,b.span.end-1);if(v===void 0){o.push({start:n(b.line).start,end:n(y).end,text:""});for(let R=b.line;R<=y;R++)l.add(R);const T=Math.min(b.line,...x),j=b.blockHeader??T,M=(t[y+1]??"x").trim()==="",I=j===0||t[j-1].trim()==="",N=b.blockHeader===void 0||![...c.values()].some(R=>R.blockHeader===b.blockHeader&&R.line>b.line&&f.has([...c.entries()].find(([,L])=>L===R)?.[0]??""));M&&I&&N&&!l.has(y+1)&&(o.push({...n(y+1),text:""}),l.add(y+1));continue}const k=r(b.line),C=Bc(v),$=v.type!==g.type||v.default!==g.default?b.blockHeader===void 0?_c(v):`${v.name} :: ${v.type} is ${v.default}`:t.slice(b.line,y+1).join(`
91
+ `).trim();o.push({start:n(b.line).start,end:n(y).end,text:(C?`${k}${C}
92
+ `:"")+`${k}${$}
93
+ `})}for(const[p,g]of c)g.blockHeader===void 0||f.has(p)||![...c.values()].some(v=>v.blockHeader===g.blockHeader&&!l.has(v.line))&&!l.has(g.blockHeader)&&(o.push({...n(g.blockHeader),text:""}),l.add(g.blockHeader));const u=[...f.values()].filter(p=>!d.has(p.name));if(u.length>0){const p=Math.max(-1,...[...c.values()].map(h=>h.line)),g=(()=>{let h=-1;for(let x=0;x<t.length;x++){const y=t[x].trim();(y.startsWith("import ")||h>=0&&/^}\s*from\s/.test(y))&&(h=x)}return h})(),v=p>=0?p:g,b=u.map(h=>{const x=Bc(h);return(x?`${x}
94
+ `:"")+`${_c(h)}
95
+ `}).join(`
96
+ `),w=v>=0?n(v).end:n(0).end;o.push({start:w,end:w,text:`
97
+ ${b}`}),t.some(h=>h.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
98
+ `})}}const Kc=(e,t)=>`import { ${e.join(", ")} } from ${At(t)}`;function g0(e){const{parsed:t,current:n,next:r,edits:i,wholeLine:s}=e,o=l=>$e(l.imports.flatMap(u=>u.kind==="all"?[u.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if($e(n.imports)===$e(r.imports))return;const a=r.imports.flatMap(l=>l.kind==="names"?[{...l,claimed:!1}]:[]),d=new Set([...r.sources.map(l=>l.base),...r.tiles.filter(le).map(l=>l.source)]),f=t.imports.map((l,u)=>({statement:l,entry:n.imports[u]}));for(const{statement:l,entry:u}of f){if(!u||u.kind!=="names")continue;const p=a.find(h=>!h.claimed&&h.from===u.from);p&&(p.claimed=!0);const g=p?.names??[],v=u.names.filter(h=>!g.includes(h)).find(h=>d.has(h));if(v!==void 0)return{ok:!1,reason:`\`${v}\` is still read by a tile, so its import cannot be removed.`};if($e(g)===$e(u.names))continue;const b=g.length===0?Pl(t,l.statement):l.statement,w=t.commentIn(b);if(w)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(w.start,w.end).trim()}\`), so nothing was written. Delete it in the file first.`};i.push({...b,text:g.length===0?"":Kc(g,u.from)})}const c=a.filter(l=>!l.claimed);if(c.length>0){const l=t.imports.at(-1);if(!l)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const u=s(Vt(t,l.statement.end-1)).end;i.push({start:u,end:u,text:c.map(p=>`${Kc(p.names,p.from)}
99
+ `).join("")})}}function v0(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,d=new Map((i.drills??[]).map(c=>[Ms(c),c])),f=new Map((s.drills??[]).map(c=>[Ms(c),c]));for(const c of new Set([...d.keys(),...f.keys()])){const l=d.get(c),u=f.get(c);if(l&&u&&$e(l)===$e(u))continue;const p=u??l;if(u&&u.to.length===0)return{ok:!1,reason:`The drill on \`${c}\` names no destination.`};const g=a.sources.find(h=>h.name===p.source)?.dimensions.find(h=>h.name===p.name);if(g===void 0)return{ok:!1,reason:`\`${p.name}\` is not a dimension \`${p.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:v}=Sr(a,t,g.line),b=v.find(h=>/^#\s*drill\b/.test(h.text)),w=r(g.line);if(u===void 0)b&&o.push({...n(b.line),text:""});else if(b)o.push({...n(b.line),text:`${w}${qc(u)}
100
+ `});else{const h=n(g.line).start;o.push({start:h,end:h,text:`${w}${qc(u)}
101
+ `})}}}function x0(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if(Ee(o)||cr(o))continue;const a=zf(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const d=Vt(s,a.statement.start),f=Vt(s,a.statement.end-1),c=s.trailingComment(f),l=c&&c.start>=a.statement.end?c.end:a.statement.end;if(s.text.slice(s.lineStarts[d],a.statement.start).trim()!==""||s.text.slice(l,n(f).end).trim()!==""){i.push({...Pl(s,a.statement),text:""});continue}i.push({start:s.lineStarts[d],end:n(f).end,text:""});const u=d===0?"":t[d-1].trim();(t[f+1]??"x").trim()===""&&(d===0||u===""||u.endsWith("{"))&&i.push({...n(f+1),text:""})}}function b0(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:i,newSources:s,currentSources:o,edits:a,parsed:d}=e,f=new Map;for(const u of i){if(Ee(u))continue;const p=f.get(u.source)??[];p.push(u),f.set(u.source,p)}const c=(u,p)=>{const g=u.declaration.kind==="reference"?u.declaration.from:u.name,v=(u.filters??[]).map(b=>`where: ${Oa(b.field)} ${b.op??"~"} $${b.given}`).join(", ");return[...Pf(u).map(b=>`${p}${b}`),`${p}view: ${u.name} is ${g}${v?` + { ${v} }`:""}`].join(`
102
+ `)};let l=-1;for(const u of d.sources)l=Math.max(l,Vt(d,u.span.end-1));for(const[u,p]of f)if(o.has(u)){const g=d.sources.find(y=>y.name===u);if(!g)return{ok:!1,reason:`Could not find where the source \`${u}\` is declared.`};if(!g.properties)return{ok:!1,reason:`\`${u}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const v=g.line,b=Vt(d,g.properties.closeStart);let w=" ";for(let y=v+1;y<b;y++){const k=/^(\s+)view:/.exec(n[y]);if(k){w=k[1];break}}const h=r(b).start,x=(n[b-1]??"").trim()==="";a.push({start:h,end:h,text:(x?"":`
103
+ `)+p.map(y=>c(y,w)).join(`
104
+
105
+ `)+`
106
+ `})}else{const g=s.find(x=>x.name===u);if(!g)return{ok:!1,reason:`The tile's source \`${u}\` is not declared.`};const v=`
107
+ source: ${g.name} is ${g.base} extend {
108
+ `+p.map(x=>c(x," ")).join(`
109
+
110
+ `)+`
111
+ }
112
+ `;let b=l;if(b<0)for(let x=0;x<n.length;x++){const y=n[x].trim();(/^(import\s|given:|}\s*from\s)/.test(y)||/^[A-Z_]+\s*::/.test(y))&&(b=x)}const w=b>=0?r(b).end:t.length,h=w===t.length&&!t.endsWith(`
113
+ `)?`
114
+ `:"";a.push({start:w,end:w,text:h+v}),l=b}}function y0(e){const{lines:t,starts:n,wholeLine:r,indentOf:i,current:s,next:o,edits:a,parsed:d}=e,f=new Map(s.tiles.map(c=>[ct(c),c]));for(const c of o.tiles){const l=f.get(ct(c));if(l===void 0||Ee(c)||Ee(l))continue;const u=ya(l,c),p=$e(Uc(Es(l)))!==$e(Uc(Es(c)));if(!p&&!u)continue;if(c.declaration.kind==="inherited"){if(!p)continue;return{ok:!1,reason:`\`${vt(c)}\` is declared on its source, not in this report, so its presentation cannot be changed here.`}}if(c.declaration.kind==="query"){if(!p)continue;return{ok:!1,reason:`\`${c.name}\` names a query, whose presentation is the query's own, so it cannot be changed here.`}}const g=a0(d,c.source,c.name);if(g<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:v}=Sr(d,t,g),b=i(g),w=Pf(c,!1),h=new Map(w.map(I=>[Ji(I)??I,I])),x=new Set,y=Df(c.chart),k=Gc(l)!==Gc(c);if(k){const I=v.filter(L=>Bl(L.text)),N=v.filter(L=>Vs(L.text)),R=l.chart==="custom"?v.filter(L=>Vs(L.text)||Bl(L.text)):I.length>0?I:N.length>1?N:[];if(R.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${R.map(L=>L.text).join(" and ")}), so its chart cannot be changed here.`}}let C=!1;for(const I of v){if(k&&Vs(I.text)){y===void 0?a.push({...r(I.line),text:""}):I.text!==Qn(y,c.chartCarried)&&a.push({...r(I.line),text:`${b}${Qn(y,c.chartCarried)}
115
+ `}),C=!0;continue}const N=Ji(I.text);if(N===void 0||!s0.has(N))continue;if(c0.has(N)){u&&a.push({...r(I.line),text:""});continue}const R=h.get(N);if(R===void 0){a.push({...r(I.line),text:""});continue}x.add(N),R!==I.text&&a.push({...r(I.line),text:`${b}${R}
116
+ `})}const $=w.filter(I=>!x.has(Ji(I)??I));if(k&&y!==void 0&&!C&&$.push(Qn(y,c.chartCarried)),$.length>0){const I=n[g];a.push({start:I,end:I,text:$.map(N=>`${b}${N}
117
+ `).join("")})}if($e(l.filters)===$e(c.filters))continue;const T=zf(e,c);if(!T)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(T.body.kind==="reference"){const I=E0(e,c,T);if(I)return I;continue}if(T.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${T.body.why}, so there is no single first stage to write its filter into.`};const j=Lf(c.filters,T.body.stage);if(j)return Ff(c.name,j.given);const M=Bf(e,c,T.body.stage);if(M)return M}}const Gc=e=>e.chart==="default"?void 0:e.chart,Es=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:i,...s}=r;return s};function w0(e,t){const n=new Map(e.tiles.map(r=>[ct(r),r]));return{...t,tiles:t.tiles.map(r=>{const i=n.get(ct(r));return le(r)&&r.chart===void 0&&i&&le(i)&&i.chart!==void 0?{...r,chart:i.chart}:r})}}function es(e){if(e.includes("\r"))return"Text uses plain line breaks; a carriage return cannot be written.";if(/^\|##/m.test(e))return"A line starting with `|##` would close the text early. Indent that line or reword it."}function k0(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!jd(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=es(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const uo=e=>`##|(markdown) ${e.name}
118
+ ${e.markdown===""?"":`${e.markdown}
119
+ `}|##
120
+ `;function S0(e){const{sourceText:t,lines:n,wholeLine:r,current:i,next:s,parsed:o,edits:a}=e,d=new Map(i.tiles.filter(Ee).map(p=>[p.name,p])),f=s.tiles.filter(Ee),c=p=>o.textBlocks.find(g=>g.name===p),l=new Set(f.map(p=>p.name));for(const p of d.keys()){const g=l.has(p)?void 0:c(p);if(!g)continue;const v=Vt(o,g.span.end-1);a.push({...g.span,text:""});const b=r(v+1),w=g.line===0||n[g.line-1].trim()==="";b.end>b.start&&n[v+1].trim()===""&&w?a.push({...b,text:""}):g.line>0&&w&&t.slice(g.span.end).trim()===""&&a.push({...r(g.line-1),text:""})}const u=[];for(const p of f){const g=d.get(p.name),v=c(p.name);if(g===void 0){if(v)return{ok:!1,reason:`A block named \`${p.name}\` is already in this file, so a new text tile cannot take that name.`};u.push(uo(p))}else g.markdown!==p.markdown&&(v?a.push({...v.span,text:uo(p)}):u.push(uo(p)))}if(u.length>0){const p=o.textBlocks.filter(h=>h.name===void 0||l.has(h.name)),g=p[p.length-1],v=o.sources.find(h=>h.name.endsWith("_tiles"));if(g){const h=g.span.end,x=t.slice(h);a.push({start:h,end:h,text:`
121
+ ${u.join(`
122
+ `)}${x===""||x.startsWith(`
123
+ `)?"":`
124
+ `}`});return}if(v){const h=e.starts[o.blockStart(v.line)],x=h===0||t.slice(0,h).endsWith(`
125
+
126
+ `);a.push({start:h,end:h,text:`${x?"":`
127
+ `}${u.join(`
128
+ `)}
129
+ `});return}const b=t.length,w=t===""||t.endsWith(`
130
+
131
+ `)?"":t.endsWith(`
132
+ `)?`
133
+ `:`
134
+
135
+ `;a.push({start:b,end:b,text:w+u.join(`
136
+ `)})}}const Li=(e,t=wo)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function $0(e,t){const n=new Map(e.tiles.map(o=>[ct(o),o]));if(t.layout==="linear"&&t.columns!==void 0&&t.columns!==e.columns)return"A linear report is one column, so its width is not written.";const r=new Set;for(const o of t.tiles){const a=n.get(ct(o));if(Ee(o)){const l=k0(o,a&&Ee(a)?a:void 0,r);if(l)return l;continue}const d=a&&le(a)?a:void 0;if(a&&!d)continue;const f=o.chart;if(f!==void 0&&f!=="default"&&f!=="none"&&!Os(f)&&!(f==="custom"&&d?.chart==="custom"))return`"${String(f)}" is not a chart this editor writes.`;const c=new Set(d?.filters?.map(l=>l.field));for(const l of o.filters??[])if(!c.has(l.field)&&/[\r\n]/.test(l.field))return"A filter field is one line.";if(a===void 0){const l=[o.name,o.source];o.declaration.kind==="reference"&&l.push(o.declaration.from);for(const u of l){const p=Li(u);if(p)return p}}for(const l of["label","subtitle"]){const u=o[l];if(u===void 0||u===d?.[l])continue;const p=Dn(`tile ${l}`,u);if(p)return p}}const i=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!i.has(o.name))for(const a of[o.name,o.base]){const d=Li(a);if(d)return d}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=Dn("description line",o);if(a)return a}if(t.title!==e.title){const o=Dn("title",t.title);if(o)return o}const s=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=s.get(o.name);if(a===void 0){const f=Li(o.name,Md);if(f)return f}const d=o.suggest?.source;if(d!==void 0&&d!==a?.suggest?.source){const f=Li(d);if(f)return`The suggest source is not a name. ${f}`}for(const f of["query","dimension"]){const c=o.suggest?.[f];if(c===void 0||c===a?.suggest?.[f])continue;const l=Dn(`suggest ${f}`,c);if(l)return l}for(const f of["label","description"]){const c=o[f];if(c===void 0||c===s.get(o.name)?.[f])continue;const l=Dn(`given ${f}`,c);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const d=Dn(`starting value for ${o}`,a);if(d)return d}}const Vt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function zf(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Lf(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const i of r.clauses)if(!i.binding)for(const s of i.givens)n.add(s);return(e??[]).find(r=>n.has(r.given))}function Ff(e,t){return{ok:!1,reason:`\`${e}\` already filters on \`$${t}\` in a \`where:\` the builder does not manage, so binding it again would filter on it twice. Edit that \`where:\` in the file instead.`}}const ts=e=>`where: ${Oa(e.field)} ${e.op??"~"} $${e.given}`;function Yc(e,t,n){return{ok:!1,reason:`Removing a filter from \`${e}\` would also remove the comment written beside it (\`${t.text.slice(n.start,n.end).trim()}\`), so nothing was written. Delete it in the file first.`}}function j0(e,t,n){const r=e.commentIn(n);if(r)return r;const i=e.trailingComment(Vt(e,t.end-1));return i&&i.start>=t.end&&e.text.slice(t.end,i.start).trim()===""?i:void 0}function M0(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function Pl(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),i=e.text.indexOf(`
137
+ `,t.end),s=e.text.slice(t.end,i<0?void 0:i);if(r.trim()===""&&s.trim()==="")return{start:n,end:i<0?e.text.length:i+1};if(r.trim()===""){const a=/^\s*/.exec(s)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function Bf(e,t,n){const{parsed:r,edits:i}=e,s=new Map((t.filters??[]).map(u=>[u.given,u])),o=new Set;let a;for(const u of n.wheres){const p=u.clauses.map((v,b)=>({clause:v,index:b})).filter(({clause:v})=>v.binding!==void 0);if(p.length===0)continue;const g=p.filter(({clause:v})=>s.has(v.binding.given));for(const{clause:v}of p)o.add(v.binding.given);if(g.length===0&&p.length===u.clauses.length){const v=Pl(r,u.span),b=j0(r,u.span,v);if(b)return Yc(t.name,r,b);i.push({...v,text:""});continue}g.length>0&&(a=u.span);for(let v=p.length-1;v>=0;v--){const{clause:b,index:w}=p[v],h=s.get(b.binding.given);if(!h){const y=M0(u.clauses,w),k=r.commentIn(y);if(k)return Yc(t.name,r,k);i.push({...y,text:""});continue}const x=ts(h).replace(/^where:\s*/,"");x!==r.text.slice(b.span.start,b.span.end)&&i.push({...b.span,text:x})}}const d=(t.filters??[]).filter(u=>!o.has(u.given));if(d.length===0)return;let f=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const u=r.trailingComment(Vt(r,f));u&&u.start>=f&&(f=u.end)}const c=a!==void 0&&!/,\s*$/.test(r.text.slice(0,f))?", ":" ",l=n.oneLine?`${c}${d.map(ts).join(", ")}`:d.map(u=>`
138
+ ${n.indent}${ts(u)}`).join("");i.push({start:f,end:f,text:l})}function E0(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:s}=n.body,o=Lf(t.filters,s);if(o)return Ff(t.name,o.given);const a=t.filters??[];if(!s){if(a.length===0)return;const c=` + { ${a.map(ts).join(", ")} }`;r.push({start:i.end,end:i.end,text:c});return}const d=s.wheres.some(c=>c.clauses.some(l=>!l.binding)),f=s.statements.some(c=>!s.wheres.some(l=>l.span.start===c.span.start));if(a.length===0&&!d&&!f){const c={start:i.end,end:s.span.end},l=e.parsed.commentIn(c);if(l)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(l.start,l.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...c,text:""});return}return Bf(e,t,s)}async function C0(e,t,n={}){if(!(e.includes(`\r
139
+ `)&&!/(?<!\r)\n/.test(e)))return Xc(e,t,n);const r=await Xc(e.replace(/\r\n/g,`
140
+ `),t,n);return xa(r)?r:{...r,source:r.source.replace(/\n/g,`\r
141
+ `)}}async function Xc(e,t,n){const r=await va(e);if(ga(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const i=r.document,s=w0(i,t),o=l0(i,s,n.visibleSources);if("reason"in o)return o;const a=$0(i,s);if(a)return{ok:!1,reason:a};const d=await Ef(e);if(Sf(d))return{ok:!1,reason:`Cannot edit a file that will not open: ${d.reason}`};const f=e.split(`
142
+ `),c=r0(e),l=h=>({start:c[h],end:h+1<c.length?c[h+1]:e.length}),u=h=>/^\s*/.exec(f[h])?.[0]??"",p=[],g={...o,sourceText:e,parsed:d.parsed,lines:f,starts:c,wholeLine:l,indentOf:u,current:i,next:s,edits:p};for(const h of[u0,p0,g0,m0,v0,x0,b0,y0,S0]){const x=h(g);if(x)return x}const v=h=>{const{drills:x,localGivens:y,description:k,...C}=h,$=h.tiles.map(T=>{if(Ee(T))return T;if(T.filters?.length)return Es(T);const{filters:j,...M}=T;return Es(M)});return{...C,...k===void 0?{}:{description:Rf(k)},tiles:$,...x?.length?{drills:[...x].sort((T,j)=>Ms(T).localeCompare(Ms(j)))}:{},...y?.length?{localGivens:y}:{}}};if(p.length===0)return $e(v(i))!==$e(v(s))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const b=i0(e,p);if((await Fc(e)).length===0){const h=await Fc(b);if(h.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${h[0]}). Your changes are still here.`}}const w=await va(b);return ga(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:$e(v(w.document))!==$e(v(s))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:b}}function _f({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=qe(),s=i.ui,o=S.useId(),[a,d]=S.useState(!1),f=S.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:c,patch:l,close:u,discard:p}=zd(f,a,y=>n(y.text),()=>d(!1)),g=a&&c!==void 0&&c.text!==e,v=c!==void 0&&c.text!==e?es(c.text):void 0;lf(g,()=>v!==void 0?!1:(u(),!0));const b=S.useRef(!1);S.useEffect(()=>{a||(b.current=!1)},[a]);const w=S.useCallback(y=>{!y||b.current||(b.current=!0,y.setSelectionRange(y.value.length,y.value.length))},[]);if(!a||c===void 0){const y=e.trim()?es(e):void 0;return m.jsxs(_,{role:"button",tabIndex:0,onClick:k=>{k.target.closest("a")?k.preventDefault():d(!0)},onKeyDown:k=>{k.target===k.currentTarget&&(k.key!=="Enter"&&k.key!==" "||(k.preventDefault(),d(!0)))},sx:[{minHeight:24},of(i,"prose")],children:[e.trim()?m.jsx(Sm,{variant:r,children:e}):m.jsx(ve,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),y&&m.jsx(ve,{variant:"caption",color:"error",role:"alert",children:y})]})}const h=c.text!==e?es(c.text):void 0,x=()=>{h===void 0&&u()};return m.jsxs(_,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx(Sd,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:c.text,placeholder:t,error:h!==void 0,inputRef:w,inputProps:{"aria-label":"Markdown","aria-describedby":o,...h!==void 0?{"aria-invalid":!0}:{}},onChange:y=>l(k=>{k.text=y.target.value}),onKeyDown:y=>{y.key==="Escape"?(y.preventDefault(),p(),d(!1)):y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&(y.preventDefault(),x())},onBlur:()=>u(),sx:{p:0,...s.type.prose,color:"inherit",maxWidth:$m,"& textarea":{p:0}}}),h!==void 0&&m.jsx(ve,{variant:"caption",color:"error",role:"alert",children:h}),m.jsxs(ve,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",Sn,"↩ done · Esc cancels"]})]})}const T0="Write markdown: # heading, **bold**, - list";function O0({tile:e,onChange:t}){return m.jsx(pd,{sx:{overflow:"visible"},children:m.jsx(_f,{markdown:e.markdown,placeholder:T0,onCommit:t})})}var A0=Object.defineProperty,R0=Object.defineProperties,D0=Object.getOwnPropertyDescriptors,Qc=Object.getOwnPropertySymbols,P0=Object.prototype.hasOwnProperty,I0=Object.prototype.propertyIsEnumerable,Zc=(e,t,n)=>t in e?A0(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zn=(e,t)=>{for(var n in t||(t={}))P0.call(t,n)&&Zc(e,n,t[n]);if(Qc)for(var n of Qc(t))I0.call(t,n)&&Zc(e,n,t[n]);return e},Ln=(e,t)=>R0(e,D0(t));function N0(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Fi(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function ho(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function W0(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const d=(h,x)=>h===x||h!==null&&typeof h=="object"&&"id"in h&&h.id===x;if(Array.isArray(e)){const h=e.findIndex(y=>d(y,s.id)),x=e.findIndex(y=>d(y,o.id));if(h===-1||x===-1){if(ho(s)){const y=s.initialIndex,k=s.index;return y===k||y<0||y>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,y,k)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const y=s.index;if(y!==h)return n(e,h,y)}return n(e,h,x)}const f=Object.entries(e);let c=-1,l,u=-1,p;for(const[h,x]of f)if(c===-1&&(c=x.findIndex(y=>d(y,s.id)),c!==-1&&(l=h)),u===-1&&(u=x.findIndex(y=>d(y,o.id)),u!==-1&&(p=h)),c!==-1&&u!==-1)break;if(c===-1&&ho(s)){const h=s.initialGroup==null?void 0:Fi(e,s.initialGroup),x=s.initialIndex,y=s.group==null?void 0:Fi(e,s.group),k=s.index;if(h==null||y==null||h===y&&x===k)return"preventDefault"in t&&t.preventDefault(),e;if(h===y)return Ln(zn({},e),{[h]:n(e[h],x,k)});const C=e[h][x];return Ln(zn({},e),{[h]:[...e[h].slice(0,x),...e[h].slice(x+1)],[y]:[...e[y].slice(0,k),C,...e[y].slice(k)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,v=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(p==null){const h=Fi(e,o.id);if(h!=null){const x=o.shape&&v.y>o.shape.center.y?e[h].length:0;p=h,u=x}}if(l==null||p==null||l===p&&c===u){if(l!=null&&l===p&&c===u&&ho(s)){const h=s.group==null?void 0:Fi(e,s.group),x=s.group!=null&&h!==l,y=s.index!==c;if(x||y){const k=s.group==null?l:h;if(k!=null){if(l===k)return Ln(zn({},e),{[l]:n(e[l],c,s.index)});const C=e[l][c];return Ln(zn({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[k]:[...e[k].slice(0,s.index),C,...e[k].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===p)return Ln(zn({},e),{[l]:n(e[l],c,u)});const b=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,w=e[l][c];return Ln(zn({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[p]:[...e[p].slice(0,u+b),w,...e[p].slice(u+b)]})}function z0(e,t){return W0(e,t,N0)}function qf(e){const t=e.getBoundingClientRect(),n=new Map;for(const r of e.querySelectorAll("[data-tile-key]")){const i=r.dataset.tileKey;if(!i)continue;const s=r.getBoundingClientRect();n.set(i,{top:s.top-t.top,left:s.left-t.left,width:s.width,height:s.height})}return n}function L0({tiles:e,commit:t,onLanded:n,placement:r}){const[i,s]=S.useState(void 0),o=S.useRef(void 0),[a,d]=S.useState(!1),f=S.useRef(void 0);return{dragging:a,preview:i,onDragStart:c=>{d(!0),o.current=e;const l=r?.gridBox.current,u=c?.operation.source?.id;if(!r||!l)return;const p=e.findIndex(y=>fe(y)===u),g=qf(l),v=g.get(String(u));if(p<0||!v)return;const b=Od(e,e.map(y=>g.get(fe(y))),r.columns,ss(l.getBoundingClientRect().width,r.columns)),w=l.getBoundingClientRect(),h=c?.operation.position?.current,x=h?{x:h.x-(w.left+v.left),y:h.y-(w.top+v.top)}:{x:0,y:0};f.current={base:b,index:p,from:v,grab:x},o.current=b,s(b)},onDragMove:c=>{const l=f.current,u=r?.gridBox.current;if(!l||!r||!u)return;const p=u.getBoundingClientRect(),g=c.operation.position.current,v=c.to??(c.by?{x:g.x+c.by.x,y:g.y+c.by.y}:g),b=l.base[l.index],w=Td(v.x-l.grab.x-p.left,v.y-l.grab.y-p.top,b.colspan??1,r.columns,ss(u.getBoundingClientRect().width,r.columns)),h=o.current?.[l.index];if(h?.row===w.row&&h.col===w.col)return;const x=eg(l.base,l.index,w,r.columns);o.current=x,s(x)},onDragOver:c=>{if(f.current){c.preventDefault();return}const{source:l,target:u}=c.operation;if(!l||!u)return;const p=o.current??e;let g;if(u.type===wf){const{after:v}=u.data,b=p.findIndex(h=>fe(h)===l.id);if(b<0||v===l.id)return;const w=p.filter((h,x)=>x!==b).findIndex(h=>fe(h)===v)+1;g=Ub(p,b,w)}else{const v=p.map(fe),b=z0(v,c);if(b.every((h,x)=>h===v[x]))return;const w=new Map(p.map(h=>[fe(h),h]));g=Hb(b.map(h=>w.get(h)),e.map(h=>h.break??!1))}o.current=g,s(g)},onDragEnd:c=>{d(!1);const l=f.current,u=l!==void 0;f.current=void 0;const p=o.current,g=l!==void 0&&p!==void 0&&p[l.index]?.row===l.base[l.index]?.row&&p[l.index]?.col===l.base[l.index]?.col,v=u&&p?Kn(p):p;if(o.current=void 0,s(void 0),c.canceled||!v||g)return;t(v);const b=v.findIndex(w=>fe(w)===c.operation.source?.id);b>=0&&n(b)}}}const F0={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Hf=(e,t)=>t===0?e:Hf(t,e%t);function B0(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Hf(e,t),i=F0[`${e/r}/${t/r}`];return i?`${n} · ${i}`:n}const Jc=ns+pt,Uf=e=>e.n&&e.w||e.s&&e.e?"nwse-resize":e.n&&e.e||e.s&&e.w?"nesw-resize":e.n||e.s?"ns-resize":"ew-resize",Bi=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e??""},_0=e=>({...e.row!==void 0?{row:e.row}:{},...e.col!==void 0?{col:e.col}:{},colspan:e.colspan??1,rowspan:e.rowspan}),ed=(e,t)=>e.row===t.row&&e.col===t.col&&e.colspan===t.colspan&&e.rowspan===t.rowspan;function Vf(e,t,n,r){const i={...e};return(n.e||n.w)&&(i.colspan=t.colspan,r&&t.col!==void 0&&(i.col=t.col)),(n.n||n.s)&&(t.rowspan===void 0?delete i.rowspan:i.rowspan=t.rowspan,r&&t.row!==void 0&&(i.row=t.row)),i}function q0({tiles:e,columns:t,gridBox:n,onStart:r,commit:i}){const[s,o]=S.useState(void 0),a=S.useRef(void 0),d=S.useRef(void 0),f=u=>{a.current=u,o(u)};S.useEffect(()=>()=>Bi(void 0),[]);const c=s!==void 0;S.useEffect(()=>{if(!c)return;const u=p=>{p.key!=="Escape"||!a.current||(p.preventDefault(),p.stopPropagation(),a.current=void 0,o(void 0),d.current=void 0,Bi(void 0))};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c]);const l=u=>{const p=new Set(u.base.filter(b=>b.rowspan===void 0).map(fe)),g=u.base[u.index];let v=d.current;for(const b of n.current?.querySelectorAll("[data-tile-key]")??[]){const w=b.dataset.tileKey;if(!w||!p.has(w)||g&&w===fe(g))continue;const h=b.getBoundingClientRect();Math.abs(h.top-u.top)>1||(v=Math.max(v??0,h.height))}return v};return{drag:s,start:(u,p,g)=>{const v=n.current,b=v?.getBoundingClientRect(),w=u.currentTarget.parentElement?.getBoundingClientRect();if(!v||!b||!w||!e[p])return;u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Bi(Uf(g)),r(p);const h=(g.n||g.w)&&(!rn(e)||e[p].row===void 0||e[p].col===void 0),x=h?(()=>{const T=qf(v);return Od(e,e.map(j=>T.get(fe(j))),t,ss(b.width,t))})():[...e],y=rn(x),k=x[p],C=_0(k);!y&&C.rowspan===void 0?d.current=w.height:d.current=void 0;const $=y?{...C,rowspan:ii(k)}:C;f({index:p,edges:g,base:x,placedHere:!!h,placed:y,from:C,begun:$,shape:$,guideTop:w.top-b.top,min:is(k,u.currentTarget.parentElement),top:w.top,left:w.left})},move:u=>{const p=a.current,g=n.current?.getBoundingClientRect();if(!p||!g)return;const v=p.base[p.index];if(!v)return;const b=ss(g.width,t)+pt,w=u.clientX-g.left,h=u.clientY-g.top,x=u.currentTarget.parentElement?.getBoundingClientRect(),y=x?.top??p.top,k=x?.left??p.left,{min:C}=p,$=p.shape;let{row:T,col:j,colspan:M,rowspan:I}=$;if(p.placed&&j!==void 0&&T!==void 0){const R=p.from,L=R.col??j,B=L+R.colspan-1,q=R.row??T,D=R.rowspan??ii(v),F=q+D-1;if(p.edges.e){const E=Math.round((w+pt)/b);M=Math.min(Math.max(E,L),t)-L+1,j=L}if(p.edges.w){const E=Math.round(w/b)+1;j=Math.min(Math.max(E,1),B),M=B-j+1}if(p.edges.s){const E=p.edges.n?g.top+(q-1)*Jc:y;I=zl(u.clientY-E,C),T=q}if(p.edges.n){const E=Math.round(h/Jc)+1,O=Math.min(C,D);T=Math.max(1,Math.min(Math.max(E,F-Gr+1),F-O+1)),I=F-T+1}}else{if(p.edges.e){const R=Math.round((u.clientX-k+pt)/b);M=Math.min(Math.max(R,1),t)}if(p.edges.s){const R=u.clientY-y,L=zl(R,C),B=l(p);I=B!==void 0&&Math.abs(R-B)<Math.abs(R-fd(L))?void 0:L}}const N={...T!==void 0?{row:T}:{},...j!==void 0?{col:j}:{},colspan:M,rowspan:I};ed(N,$)||f({...p,shape:N})},end:u=>{u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Bi(void 0);const p=a.current;d.current=void 0,p&&(f(void 0),!(u.type==="pointercancel"||ed(p.shape,p.begun))&&i({index:p.index,edges:p.edges,shape:p.shape,placed:p.placed,...p.placedHere?{placedAll:p.base}:{}}))}}}function H0(e,t){const n=[];return(e.edges.e||e.edges.w)&&n.push(B0(e.shape.colspan,t)),(e.edges.n||e.edges.s)&&n.push(e.shape.rowspan===void 0?"Auto height":`${e.shape.rowspan} rows tall`),n.join(" · ")}function U0({tile:e,index:t,selected:n,flash:r=!1,menuOpen:i,bare:s=!1,onInsertAfter:o,onSelect:a,onOpenMenu:d,onRemove:f,removeBlocked:c,width:l,edges:u,heightEdge:p,fixed:g=!1,children:v}){const{theme:b}=qe(),w=b.ui;return m.jsx(My,{id:fe(e),index:t,disabled:g,children:({ref:h,handleRef:x})=>m.jsxs(_,{ref:h,onClick:a,onPointerDown:y=>{y.button===0&&a()},role:"group",className:rt.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",...(e.rowspan!==void 0||e.row!==void 0)&&{gridTemplateRows:"minmax(0, 1fr)",minHeight:0},minWidth:0,cursor:"grab",...Kf(b,{selected:n,flash:r,bare:s}),...!s&&{[`& .${mm}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:b.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${b.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...hm,...n&&{[`& .${pm}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[v,m.jsx(_,{ref:x,"aria-label":`Move ${Mr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(fm,{label:`Remove ${Mr(e)}`,onRemove:f,...c?{disabledReason:c}:{},inset:s?yd:0}),!Ee(e)&&m.jsx($n,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Mr(e)}`,onClick:y=>{y.stopPropagation(),d(y.currentTarget)},sx:{position:"absolute",top:s?0:`${td}px`,right:s?0:`${td}px`,borderRadius:w.radius.control,width:28,height:28,zIndex:3,color:"text.secondary",bgcolor:"action.hover",opacity:n||i?1:0,transition:`opacity ${nt}`,...kn,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(Y0,{})}),u&&m.jsx(Q0,{edges:u,width:l,heightEdge:p,label:Mr(e)}),o&&m.jsx($n,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Mr(e)}`,onClick:y=>{y.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${pt/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:b.tileTitle,bgcolor:b.tile,border:b.cardBorder,opacity:0,transition:`opacity ${nt}`,...kn,"&:hover, &:focus-visible":{opacity:1,bgcolor:b.tile}},children:m.jsx(vi,{sx:{fontSize:14}})})]})})}const td=14,fo=7,Kf=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:i=yd})=>{const s=e.ui,o=t||n?e.accent:"transparent",a=n?`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`:t?`0 0 0 4px color-mix(in srgb, ${e.accent} 14%, transparent)`:void 0,d=`outline-color ${nt}, border-color ${nt}, opacity ${nt}, box-shadow ${nt}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:typeof i=="number"?`${-i}px`:`${-i.y}px ${-i.x}px`,borderRadius:1,border:`2px solid ${o}`,...a&&{boxShadow:a},pointerEvents:"none",transition:d,...kn}}:{borderRadius:s.radius.tile,"& > .MuiPaper-root":{transition:d,...kn,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:d,...kn,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:Cs(e.cardBorder,e.tileTitle)}}}}};function V0({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=qe();return m.jsxs(xo,{chrome:r,children:[m.jsx(bo,{title:t?.title??As(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx(ve,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),m.jsx(ve,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:vt(e).replace("->","→")})]})}function K0({after:e}){const{theme:t}=qe();return m.jsx(Ey,{id:df(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx(_,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${nt}, background-color ${nt}`,...kn}})})}function G0({columns:e,faint:t=!1}){const{theme:n}=qe();return m.jsx(_,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${pt}px`},children:Array.from({length:e},(r,i)=>m.jsx(_,{sx:{bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},i))})}function nd({top:e,faint:t=!1}){const{theme:n}=qe(),r=ns+pt,i=-Math.ceil(e/r);return m.jsx(_,{"aria-hidden":!0,sx:{position:"absolute",inset:0,overflow:"hidden",pointerEvents:"none",zIndex:0},children:Array.from({length:-i+4*Gr},(s,o)=>m.jsx(_,{sx:{position:"absolute",top:e+(i+o)*r,left:0,right:0,height:ns,bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},o))})}function Y0(){return m.jsxs(Bm,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[m.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),m.jsx("circle",{cx:"12",cy:"12",r:"2"}),m.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}const X0=[{edges:{n:!0},sx:{top:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{s:!0},sx:{bottom:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{e:!0},sx:{right:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{w:!0},sx:{left:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{n:!0,w:!0},sx:{top:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{n:!0,e:!0},sx:{top:"-8px",right:"-8px",width:"32px",height:"32px"}},{edges:{s:!0,w:!0},sx:{bottom:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{s:!0,e:!0},sx:{bottom:"-8px",right:"-8px",width:"20px",height:"20px"}}];function Q0({edges:e,width:t,heightEdge:n,label:r}){const{theme:i}=qe(),s=i.ui,[o,a]=S.useState(void 0),d=o??n?.min??rs,f=u=>n&&a(n.minFor?.(u)??n.min),c=u=>(!(u.n||u.w)||e.all)&&(!u.e||e.right),l={"&:focus-visible":{outline:`2px solid ${i.accent}`,outlineOffset:-4,borderRadius:"3px"}};return m.jsxs(m.Fragment,{children:[X0.filter(u=>c(u.edges)).map(u=>{const p=Object.keys(u.edges).join(""),g=p==="e",v=g&&t?{role:"separator",tabIndex:0,"aria-orientation":"vertical","aria-label":`Width of ${r}`,"aria-valuenow":t.span,"aria-valuemin":1,"aria-valuemax":t.max??t.columns,"aria-valuetext":`${t.span} of ${t.columns} columns`,onKeyDown:b=>{if(b.altKey)return;const w=t.max??t.columns,h=b.key==="ArrowRight"?t.span+1:b.key==="ArrowLeft"?t.span-1:b.key==="Home"?1:b.key==="End"?w:void 0;h!==void 0&&(b.preventDefault(),b.stopPropagation(),t.onStep(Math.min(Math.max(h,1),w)))}}:p==="s"&&n?{role:"separator",tabIndex:0,"aria-orientation":"horizontal","aria-label":`Height of ${r}`,"aria-valuemin":d,onFocus:b=>f(b.currentTarget.parentElement),onPointerEnter:b=>f(b.currentTarget.parentElement),"aria-valuemax":Gr,...n.rows===void 0?{}:{"aria-valuenow":n.rows},"aria-valuetext":Z0(n.rows),onKeyDown:b=>{if(b.altKey)return;const w=n.rows,h=w??d,x=b.key==="ArrowDown"?h+1:b.key==="ArrowUp"?h-1:b.key==="Home"?d:b.key==="End"?Gr:b.key==="Delete"||b.key==="Backspace"?null:void 0;if(x===void 0)return;if(b.preventDefault(),b.stopPropagation(),x===null){w!==void 0&&n.onStep(void 0);return}const y=Math.min(Math.max(x,d),Gr);y!==w&&n.onStep(y)}}:{"aria-hidden":!0};return m.jsx(_,{className:`builder-affordance${g?` ${rt.widthHandle}`:""}`,[kf]:"",...v,"data-edge":p,onPointerDown:b=>{b.button===0&&e.start(b,u.edges)},onPointerMove:e.move,onPointerUp:e.end,onPointerCancel:e.end,onClick:b=>b.stopPropagation(),onDoubleClick:b=>{!u.edges.s||u.edges.e||u.edges.w||(b.stopPropagation(),n&&n.rows!==void 0&&n.onStep(void 0))},sx:{position:"absolute",...u.sx,cursor:Uf(u.edges),touchAction:"none",zIndex:Object.keys(u.edges).length>1?2:1,...l}},p)}),e.label&&m.jsx(_,{"aria-hidden":!0,sx:u=>({position:"absolute",right:12,bottom:12,px:1,py:.5,borderRadius:s.radius.control,bgcolor:u.palette.text.primary,color:u.palette.background.paper,...s.type.label,whiteSpace:"nowrap",pointerEvents:"none",zIndex:4}),children:e.label})]})}const Z0=e=>e===void 0?"Auto height":`${e} rows tall`;function J0({editor:e,reorder:t,edging:n,place:r=x=>x,arrange:i=!0,gridBox:s,defaultSpan:o=1,rules:a,canAdd:d,selected:f,flash:c,menuIndex:l,onSelect:u,onOpenMenu:p,onRemove:g,removeBlocked:v,openAdd:b,editTile:w,renderTile:h}){const{dragging:x,preview:y,onDragStart:k,onDragMove:C,onDragOver:$,onDragEnd:T}=t,{columns:j}=a,M=n.drag,I=E=>E.colspan===void 0?{...E,colspan:o}:E,N=(M!==void 0?(()=>{const E=M.placedHere?M.base:e.document.tiles;if(!E[M.index])return E;const O=E.map((W,U)=>U===M.index?Vf(W,M.shape,M.edges,M.placed):W);return M.placed?Ht(O,j,M.index):O})():y??e.document.tiles).map(I),R=rn(N),L=x||M!==void 0,B=!L&&R&&i&&f!==void 0,q=e.document.tiles.length===0,D=L&&!R?Vb(N,j):N.map(cf),F=E=>ew(E,As(E),w);return m.jsxs(m.Fragment,{children:[m.jsxs(Cb,{sensors:Sy,onDragStart:k,onDragMove:C,onDragOver:$,onDragEnd:T,children:[m.jsx(Cy,{active:x}),m.jsxs(_,{ref:s,sx:{position:"relative"},children:[a.widths&&(L||B)&&m.jsx(G0,{columns:j,faint:!L}),M!==void 0&&!M.placed?(M.edges.s||M.edges.n)&&m.jsx(nd,{top:M.guideTop}):R&&(L||B)&&m.jsx(nd,{top:0,faint:!L}),m.jsx(Tp,{tiles:D,columns:j,rowGapPx:pt,defaultRowspan:E=>E.kind==="tile"?ii(E.tile):Ea.query,keyOf:E=>E.kind==="gap"?df(E.after):fe(E.tile),renderTile:E=>{if(E.kind==="gap")return m.jsx(K0,{after:E.after});const{tile:O,index:W}=E;return m.jsx(U0,{tile:O,index:W,selected:W===f,flash:fe(O)===c,menuOpen:l===W,bare:Ee(O),...a.insertBetween&&d&&W<e.document.tiles.length-1?{onInsertAfter:()=>b(W+1)}:{},fixed:!i,...a.widths?{edges:{all:i,right:i,start:(U,V)=>n.start(U,W,V),move:n.move,end:n.end,...M?.index===W?{label:H0(M,j)}:{}}}:{},...a.widths&&i?{width:{span:O.colspan??1,columns:j,max:Rd(O,j),onStep:U=>{U!==(O.colspan??1)&&e.update(V=>{if(!Number.isInteger(W)||W<0)return;const Y=V.tiles[W];Y&&(V.tiles[W]=mo(Y,U,j,o)),V.tiles=r(V.tiles,W)})}}}:{},...a.widths?{heightEdge:{rows:O.rowspan,min:is(O),minFor:U=>is(O,U),onStep:U=>e.update(V=>{if(!Number.isInteger(W)||W<0)return;const Y=V.tiles[W];Y&&(U===void 0?delete Y.rowspan:Y.rowspan=U,V.tiles=r(V.tiles,W))})}}:{},onSelect:()=>u(W),onOpenMenu:U=>p(U,W),onRemove:()=>g(W),...v?{removeBlocked:v}:{},children:Ee(O)?m.jsx(O0,{tile:O,onChange:U=>w(fe(O),V=>{Ee(V)&&(V.markdown=U)})}):h?h(O,F(O),"card"):m.jsx(V0,{tile:O,heading:F(O)})})}})]})]}),a.insertBetween&&d&&!q&&m.jsx(Ae,{size:"small",startIcon:m.jsx(vi,{}),"aria-label":"Add tile at the end",onClick:()=>b(),sx:{alignSelf:"center"},children:"Add tile"})]})}const ew=(e,t,n)=>{if(cr(e))return;const r=fe(e),i=s=>o=>n(r,a=>{le(a)&&(o===""?delete a[s]:a[s]=o)});return{title:m.jsx(ha,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:i("label")}),subtitle:m.jsx(ha,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:i("subtitle")})}},tw={x:12,y:6};function nw({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:i}){const{theme:s}=qe();return m.jsx(Ip,{actions:n,title:m.jsx(ha,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx(_,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:i,onFocus:i,children:m.jsx(pd,{sx:{position:"relative",overflow:"visible",...Kf(s,{selected:r,bare:!0,ringOffset:tw})},children:m.jsx(_f,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const rw=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:s}=cd({path:t,layout:n},i);return{size:e,saved:({size:o,structural:a,durationMs:d})=>s({type:"report.saved",tiles:o,structural:a,where:r,durationMs:d}),refused:o=>s({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:d})=>s({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:d}),undoRefused:o=>s({type:"report.save_undo_refused",reason:o})}};function iw(e,t){const n=S.useRef(t);n.current=t;const r=S.useRef(e);r.current=e;const i=S.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.(),pack:()=>n.current.arrange?.pack?.(),flow:()=>n.current.arrange?.flow()}),[]),{status:s,saveTarget:o,canUndo:a,canRedo:d,add:{filterUnavailable:f}}=t,c=t.save!==void 0,l=t.add.tile!==void 0,u=t.add.text!==void 0,p=t.add.filter!==void 0,g=t.exit!==void 0,v=t.done!==void 0,b=t.discard!==void 0,{draftKeptAt:w}=t,h=t.restored?.savedAt,x=t.restored?.stale??!1,y=t.restored?.pending??!1,k=t.restore!==void 0,C=t.dismissRestored!==void 0,$=t.arrange!==void 0,T=t.arrange?.pack!==void 0,j=S.useMemo(()=>({status:s,saveTarget:o,...c?{save:i.save}:{},canUndo:a,undo:i.undo,canRedo:d,redo:i.redo,add:{...l?{tile:i.addTile}:{},...u?{text:i.addText}:{},...p?{filter:i.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...g?{exit:i.exit}:{},...v?{done:i.done}:{},...w!==void 0?{draftKeptAt:w}:{},...b?{discard:i.discard}:{},...h!==void 0?{restored:{savedAt:h,stale:x,pending:y}}:{},...k?{restore:i.restore}:{},...C?{dismissRestored:i.dismissRestored}:{},...$?{arrange:{...T?{pack:i.pack}:{},flow:i.flow}}:{}}),[i,s,o,c,a,d,l,u,p,f,g,v,w,b,h,x,y,k,C,$,T]);S.useEffect(()=>{r.current?.(j)},[j,e!==void 0]),S.useEffect(()=>()=>r.current?.(void 0),[])}function sw({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:i,onRemove:s,fixedFilters:o,onOpenModel:a,startingValues:d,onStartingValue:f,children:c}){const l=c!=null,u=S.useMemo(()=>{const p=new Map(e.map(g=>[g.name,g]));return{stateOf:g=>{const v=o?.get(g);if(v!==void 0){const{modelPath:h}=v;return{origin:p.get(g)?.origin??"model",fixed:v.reason,...h!==void 0&&a?{openModel:()=>a(h)}:{}}}const b=p.get(g);if(!b)return;const w=t(b.name,b.type);return{origin:b.origin,...w.length>0?{problem:`Cannot filter on ${w.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:l?e.filter(g=>g.boundTiles===0&&!o?.has(g.name)).map(g=>({name:g.name,label:g.label??g.name})):[],onEdit:g=>{const v=p.get(g);v&&n(v)},onRemove:s,onAdd:r,...i!==void 0?{addDisabledReason:i}:{},...f?{startingValueOf:g=>d?.[g],setStartingValue:f}:{}}},[e,t,l,n,s,r,i,o,a,d,f]);return m.jsx(Ap,{children:m.jsx(Rp.Provider,{value:u,children:l?c:m.jsxs(ft,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(p=>m.jsx(Dp,{name:p.name,label:p.label??p.name,unused:p.boundTiles===0},p.name)),m.jsx(Pp,{})]})})})}function ow(e,t){const n=new Map(e.tiles.map((r,i)=>[fe(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(fe(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return fe(i)}}function aw({editor:e,gridBox:t}){const[n,r]=S.useState(void 0),i=typeof n=="object"?n.tile:void 0,s=n==="description",o=S.useCallback(b=>r(w=>typeof w=="object"&&w.tile===b?w:{tile:b}),[]),a=S.useCallback(()=>r(b=>b==="description"?b:void 0),[]),d=S.useCallback(()=>r("description"),[]),f=S.useCallback(()=>r(void 0),[]),c=n!==void 0;S.useEffect(()=>{if(!c)return;const b=w=>{const h=w.target;h instanceof Element&&h!==document.documentElement&&h.closest(lw)===null&&f()};return document.addEventListener("pointerdown",b,!0),()=>document.removeEventListener("pointerdown",b,!0)},[c,f]);const[l,u]=S.useState(void 0),p=S.useRef(!1),g=S.useRef(e.document);S.useEffect(()=>{const b=g.current;if(g.current=e.document,!p.current)return;p.current=!1;const w=ow(b,e.document);w!==void 0&&(u(w),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(h=>h.dataset.tileKey===w)?.scrollIntoView?.({block:"nearest",behavior:Cp()}))},[e.document,t]),S.useEffect(()=>{if(l===void 0)return;const b=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(b)},[l]);const v=S.useMemo(()=>({...e,undo:()=>{p.current=!0,e.undo()},redo:()=>{p.current=!0,e.redo()}}),[e]);return{selected:i,descriptionSelected:s,selectTile:o,deselectTile:a,selectDescription:d,clearSelection:f,flash:l,stepEditor:v}}const lw=["[data-tile-key]",'[role="group"][aria-label="Description"]','[role="toolbar"][aria-label="Report builder"]','[aria-label="Builder actions"]',".MuiPopover-root",".MuiPopper-root",".MuiDialog-root",".MuiModal-root",'[role="menu"]','[role="dialog"]','[role="listbox"]','[role="tooltip"]'].join(", ");function cw({dirty:e,saving:t,canSave:n,save:r,onExit:i}){const[s,o]=S.useState("idle"),[a,d]=S.useState(!1),f=S.useRef(r);f.current=r;const c=S.useRef(i);c.current=i;const l=S.useRef(0),u=S.useCallback(async()=>{const v=++l.current;d(!1),o("saving");try{await f.current()}catch{l.current===v&&o("idle");return}l.current===v&&d(!0)},[]);S.useEffect(()=>{if(s==="waiting"){if(t)return;e?u():(o("idle"),c.current())}else if(s==="saving"){if(!a||t)return;o("idle"),e||c.current()}},[s,a,t,e,u]);const p=S.useCallback(()=>{s==="idle"&&(e?o("asking"):c.current())},[s,e]),g=S.useCallback(()=>{s==="idle"&&(e?n?t?o("waiting"):u():o("asking"):c.current())},[s,e,n,t,u]);return{requestExit:p,saveAndExit:g,finishing:s==="saving"||s==="waiting",dialog:{open:s==="asking",canSave:n,onKeepEditing:()=>{s==="asking"&&o("idle")},onDiscard:()=>{s==="asking"&&(o("idle"),c.current())},onSaveAndExit:()=>{s==="asking"&&(t?o("waiting"):u())}}}}function dw({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:i,extraDirty:s=!1,keepsEdits:o=!1,report:a,unit:d,prepare:f,shortcuts:c}){const[l,u]=S.useState(!1),[p,g]=S.useState(!1),v=S.useRef(null),b=S.useRef(a);b.current=a;const w=e.dirty||s,h=(e.edited??e.dirty)||s,x=o?s:h;S.useEffect(()=>{i?.(e.document)},[e.document,i]),S.useLayoutEffect(()=>{n?.(h,x)},[h,x,n]);const y=S.useRef(n);y.current=n,S.useEffect(()=>()=>y.current?.(!1,!1),[]);const k=S.useRef(d);k.current=d,S.useEffect(()=>{g(!1)},[e.document]);const C=S.useCallback(()=>{u(!0),g(!1);const D=Qt(),{structural:F}=e,E=b.current.size;return e.save().then(O=>{O.ok===!0?b.current.saved({size:E,structural:F,durationMs:Qt()-D}):b.current.refused(O.reason)}).finally(()=>u(!1))},[e]),$=S.useRef(!1),T=S.useRef(!1);S.useEffect(()=>{!T.current||l||(T.current=!1,v.current?.focus())},[p,l]);const j=S.useCallback(()=>{if(!t||l||$.current||!e.canUndoSave)return;$.current=!0,u(!0);const D=Qt(),F=e.lastSave?.structural??!1,E=b.current.size;return e.undoSave().then(O=>{O.ok===!0?(T.current=!0,g(!0),b.current.undone({size:E,structural:F,durationMs:Qt()-D})):b.current.undoRefused(O.reason)}).finally(()=>{$.current=!1,u(!1)})},[t,l,e]),M=S.useCallback(()=>{if(!(!t||!e.dirty||l))return C()},[t,e,l,C]),I=S.useRef(M);I.current=M;const N=S.useCallback(()=>{const D=()=>I.current();return f?f(D):D()},[f]),R=cw({dirty:h,saving:l,canSave:!!t,save:N,onExit:()=>r?.()});ag(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:N}:{},paused:R.dialog.open||c.paused===!0}),[c,e,t,N,R.dialog.open]));const L=!!t&&!l&&e.canUndoSave,B=e.lastSave,q={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:w,saving:l,saveButton:v,...t?{onSave:N}:{},...r?{onExit:R.requestExit}:{}};return{saving:l,save:N,exitGuard:R,...r?{done:R.saveAndExit}:{},undoSave:j,canUndoSave:L,lastSave:B,toolbarProps:q}}const uw=1;function Gf(e,t,n){const r=[];for(const i of e??[]){const s=i.name,o=i.kind;if(typeof s=="string"){if(o==="dimension"||o==="measure"){const a=i.type?.kind;r.push({name:t+s,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=i.schema?.fields;r.push(...Gf(a,`${t}${s}.`,n-1))}}}return r}function hw(e){const t=new Map;for(const n of Yf(e))t.set(n.name,Gf(n.schema?.fields,"",uw));return t}function Yf(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}function Xf(e){const t=new Map;for(const n of Yf(e)){const r=new Map;for(const i of n.schema?.fields??[]){if(i.kind!=="view"||typeof i.name!="string")continue;const s=i.schema?.fields;if(!s||s.length===0)continue;const{groupBys:o,totals:a}=tm(s);r.set(i.name,{shape:{groupBys:o,totals:a},...a===s.length?{aggregateOnly:!0}:{}})}t.set(n.name,r)}return t}function Qf(e,t){const n=vo(e.annotations),r=nm(e.annotations);return{name:e.name,...n?{description:n}:{},...r?{chart:r}:{},...t}}const Zf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function fw(e){const t=Xf(e),n=new Map;for(const r of e.sources??[]){if(!r.name)continue;const i=t.get(r.name);n.set(r.name,new Map(Zf(r).map(s=>[s.name,Qf(s,i?.get(s.name))])))}return n}function rd(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const id=(e,t)=>e!==void 0&&t.has(e),sd=e=>e.path||e.modelPath||"";function pw(e,t=new Set){const n=[],r=new Set,i=new Map,s=new Map,o=new Map;for(const a of e){const d=sd(a);if(id(d,t))continue;const f=Ep(a.modelInfo);s.set(a,f);for(const{name:c}of a.sources??[])c&&o.set(c,[...o.get(c)??[],d]);for(const c of f)i.set(c,[...i.get(c)??[],d])}for(const a of e){const d=sd(a);if(id(d,t))continue;const f=hw(a),c=Xf(a);for(const l of a.sources??[]){const u=l.name;if(!u||!s.get(a)?.has(u)||r.has(u))continue;r.add(u);const p=(l.givens??[]).map(g=>g.name).filter(g=>typeof g=="string");n.push({name:u,modelPath:d,exporters:i.get(u)??[d],visibleIn:o.get(u)??[d],...vo(l.annotations)?{description:vo(l.annotations)}:{},views:Zf(l).map(g=>Qf(g,c.get(u)?.get(g.name))),givens:p,fields:f.get(u)??[]})}}return{sources:n}}function mw({editor:e,opened:t,givens:n,catalog:r}){const[i,s]=S.useState(void 0),o=S.useMemo(()=>{const u=new Set((t.localGivens??[]).map(p=>p.name));return(n??[]).filter(p=>!u.has(p.name))},[t,n]),a=S.useMemo(()=>kg(e.document,o),[e.document,o]),d=S.useMemo(()=>new Map(e.document.sources.map(u=>[u.name,rd(r,u.base)])),[r,e.document.sources]),f=S.useCallback(u=>d.get(u.source)??rd(r,u.source),[d,r]),c=(u,p)=>{const g=[];for(const v of e.document.tiles){if(!le(v))continue;const b=f(v);if(!b)continue;const w=new Map(b.map(h=>[h.name,h.type]));for(const h of v.filters??[])h.given===u&&(!w.has(h.field)||!Xr(p,w.get(h.field)))&&g.push(`${h.field} on ${v.label??v.name} (${e.document.sources.find(x=>x.name===v.source)?.base??v.source})`)}return g},l=S.useMemo(()=>a.filter(u=>u.origin==="model"&&u.boundTiles===0),[a]);return{filterDialog:i,setFilterDialog:s,controlList:a,fieldsFor:f,unknownFieldsOf:c,available:l,applyFilter:(u,p,g)=>{s(void 0),e.update(v=>{g&&Og(v,g),Tg(v,u,p)})},dropControl:u=>{s(void 0),e.update(p=>Ag(p,u))}}}function gw(e){const{splice:t,onSave:n,structural:r,clearsHistory:i}=e,[s,o]=S.useState({stack:[e.document],index:0}),[a,d]=S.useState(e.source),[f,c]=S.useState(void 0),[l,u]=S.useState(e.document),[p,g]=S.useState(e.replaces),[v,b]=S.useState(!1),w=s.stack[s.index],h=S.useRef(s);h.current=s;const x=S.useRef(!1),[y,k]=S.useState(!1),C=O=>{x.current=O,k(O)},[$,T]=S.useState(void 0),j=S.useCallback(O=>{c(void 0),o(W=>{const U=structuredClone(W.stack[W.index]);if(O(U),JSON.stringify(U)===JSON.stringify(W.stack[W.index]))return W;const V=[...W.stack.slice(0,W.index+1),U].slice(-100);return{stack:V,index:V.length-1}})},[]),M=S.useCallback(()=>{c(void 0),o(O=>O.index>0?{...O,index:O.index-1}:O)},[]),I=S.useCallback(()=>{c(void 0),o(O=>O.index<O.stack.length-1?{...O,index:O.index+1}:O)},[]),N=S.useCallback(async(O,W)=>{try{return await t(O,W)}catch(U){return{ok:!1,reason:`Could not build the file: ${U instanceof Error?U.message:String(U)}`}}},[t]),R=S.useCallback(async()=>{if(x.current)return{ok:!1,reason:"A save is still being written."};const O={source:a,saved:l,history:h.current,replacing:p,unwritten:v},W=i?.(l,w)??!1,U=r?.(l,w)??!1;C(!0);try{const V=await N(a,w);if(xa(V))return c(V.reason),{ok:!1,reason:V.reason};try{await n?.(V.source,{purpose:"save",document:w})}catch(re){const H=`Could not save: ${re instanceof Error?re.message:String(re)}`;return c(H),{ok:!1,reason:H}}d(V.source),u(w),g(void 0),b(!1);const Y=W?{stack:[w],index:0}:O.history;return o(re=>re===O.history?Y:W?{stack:[re.stack[re.index]],index:0}:re),T(n?{before:O,after:Y,lastSave:{before:p??a,after:V.source,structural:U,clearsHistory:W}}:void 0),c(void 0),{ok:!0}}finally{C(!1)}},[w,N,n,a,l,p,v,i,r]),L=S.useCallback(async()=>{if(x.current)return{ok:!1,reason:"A save is still being written."};if(!n||$===void 0||$.after!==h.current)return{ok:!1,reason:"There is no save to undo."};const{before:O}=$;C(!0);try{await n(O.replacing??O.source,{purpose:"undo",document:O.saved})}catch(W){const U=`Could not undo the save: ${W instanceof Error?W.message:String(W)}`;return c(U),{ok:!1,reason:U}}finally{C(!1)}return d(O.source),u(O.saved),g(O.replacing),b(O.unwritten||O.replacing!==void 0),o(W=>W===$.after?O.history:W),T(void 0),c(void 0),{ok:!0}},[n,$]),B=S.useMemo(()=>v||JSON.stringify(w)!==JSON.stringify(l),[w,l,v]),q=S.useMemo(()=>r?.(l,w)??!1,[w,l,r]),D=S.useMemo(()=>i?.(l,w)??!1,[w,l,i]),F=$!==void 0&&$.after===s,E=S.useCallback(async()=>{const O=await N(a,w);return xa(O)?{ok:!1,reason:O.reason}:{ok:!0,source:O.source}},[w,N,a]);return{document:w,saved:l,source:a,canUndo:s.index>0,canRedo:s.index<s.stack.length-1,dirty:B,edited:B,...f===void 0?{}:{error:f},update:j,undo:M,redo:I,save:R,preview:E,structural:q,clearsHistory:D,canUndoSave:F&&!y&&n!==void 0,...F?{lastSave:$.lastSave}:{},undoSave:L}}const vw=(e,t)=>{const n=new Set(e.tiles.map(ba)),r=new Set(t.tiles.map(ba));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function xw(e){const{visibleSources:t,...n}=e,r=S.useCallback((i,s)=>C0(i,s,t?{visibleSources:t}:{}),[t]);return gw({...n,splice:r,structural:vw})}function bw({editorDirty:e}){const[t,n]=S.useState(!1),r=S.useRef(void 0),i=S.useRef(void 0),s=S.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=S.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(d=>{i.current=()=>d(a())})},[]);return S.useEffect(()=>{if(t||!i.current)return;const a=i.current;i.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:s,prepare:o}}function yw({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:i,deselectTile:s}){const[o,a]=S.useState(void 0),[d,f]=S.useState(!1),[c,l]=S.useState(void 0),u=h=>{l(h),f(!0)},p=()=>f(!1),g=h=>{f(!1),e.update(x=>{hg(x,h,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c}),t.widths&&(x.tiles=Hl(x.tiles,c??x.tiles.length-1,t.columns))}),i(c??e.document.tiles.length)},v=()=>w(c),b=()=>w(void 0),w=h=>{f(!1),e.update(x=>{const y=new Set(x.tiles.filter(Ee).map(C=>C.name));let k=1;for(;y.has(`text_${k}`);)k++;x.tiles.splice(h??x.tiles.length,0,{kind:"text",name:`text_${k}`,markdown:"",...t.widths?{colspan:t.columns}:{}}),t.widths&&(x.tiles=Hl(x.tiles,h??x.tiles.length-1,t.columns))}),i(h??e.document.tiles.length)};return{menu:o,setMenu:a,addingTile:d,openAdd:u,closeAdd:p,addTile:g,addText:v,appendText:b,editTile:(h,x)=>e.update(y=>{const k=y.tiles.find(C=>fe(C)===h);k&&x(k)}),removeTile:h=>{a(void 0),s(),e.update(x=>{x.tiles.splice(h,1)})},duplicate:h=>{a(void 0);const x=e.document.tiles[h],y=x&&le(x)&&ls(x)===void 0?h+1:void 0;e.update(k=>{fg(k,h)}),y!==void 0&&i(y)}}}const ww=mt(m.jsx("path",{d:"M19 5v2h-4V5zM9 5v6H5V5zm10 8v6h-4v-6zM9 17v2H5v-2zM21 3h-8v6h8zM11 3H3v10h8zm10 8h-8v10h8zm-10 4H3v6h8z"}));function Jf({arrange:e}){const{theme:t}=qe(),[n,r]=S.useState(null),i=s=>()=>{r(null),s?.()};return m.jsxs(m.Fragment,{children:[m.jsx(Ot,{title:"Arrange tiles",children:m.jsx($n,{"aria-label":"Arrange tiles","aria-haspopup":"menu","aria-expanded":n!==null,onClick:s=>r(s.currentTarget),sx:oi(t.ui),children:m.jsx(ww,{fontSize:"small"})})}),m.jsxs(Xn,{anchorEl:n,open:n!==null,onClose:()=>r(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:{minWidth:260,borderRadius:t.ui.radius.menu,border:`1px solid ${cn(t.cardBorder)}`,boxShadow:t.ui.shadow.menu}}},children:[m.jsx(Xe,{disabled:!e.pack,onClick:i(e.pack),children:m.jsx(Bt,{primary:"Pack tiles upward",secondary:e.pack?"Close every gap above a tile":"There are no gaps to close"})}),m.jsx(Xe,{onClick:i(e.flow),children:m.jsx(Bt,{primary:"Let tiles flow",secondary:"Clear each tile's place; keep its size"})})]})]})}function ep({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,onExit:s,renderTile:o,renderViewPreview:a,controls:d,givens:f,catalog:c,toolbar:l,dashboards:u,onEvent:p,savesTo:g="package",saveLabel:v,replaces:b,modelPath:w,visibleSources:h,addFilterDisabledReason:x,fixedFilters:y,onOpenModel:k,takenGivenNames:C,onControlsChange:$,draftKey:T}){const j=xw({source:e,document:t,...n?{onSave:n}:{},...b!==void 0?{replaces:b}:{},...h?{visibleSources:h}:{}}),M=pp(T,j,e),I=S.useRef(null),{selected:N,descriptionSelected:R,selectTile:L,deselectTile:B,selectDescription:q,clearSelection:D,flash:F,stepEditor:E}=aw({editor:j,gridBox:I}),O=ld(j.document.layout,j.document.columns),{columns:W}=O,U=w?.split("/").at(-1)?.replace(/\.malloy$/,""),V=ad("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),Y=!O.widths||V,re=L0({tiles:j.document.tiles,commit:J=>j.update(he=>{he.tiles=J}),onLanded:L,...O.widths&&V?{placement:{columns:W,gridBox:I}}:{}}),H=(J,he)=>{if(j.update(xe=>{xe.tiles=J}),he===void 0)return;const Ne=J.findIndex(xe=>fe(xe)===he);Ne>=0&&L(Ne)},ne=O.widths,Q=S.useCallback((J,he)=>ne&&rn(J)?Ht(J,W,he):J,[ne,W]),{dragging:ge}=re,Z=mp(I,W),Re=S.useMemo(()=>j.document.tiles.map(J=>J.colspan===void 0?{...J,colspan:Z}:J),[j.document.tiles,Z]),De=q0({tiles:Re,columns:W,gridBox:I,onStart:L,commit:({index:J,edges:he,shape:Ne,placed:xe,placedAll:dn})=>{const de=dn??j.document.tiles,pe=de[J];if(!pe)return;let He=Vf(pe,Ne,he,xe);(he.e||he.w)&&(He=mo(He,Ne.colspan,W,Z));const Et=de.map(($r,An)=>An===J?He:$r);H(xe?Kn(Ht(Et,W,J)):Et,fe(pe))}}),X=yw({editor:j,rules:O,modelPath:w,textHeld:h!==void 0,selectTile:L,deselectTile:B}),{menu:we,addingTile:ye,openAdd:se}=X,Pe=mw({editor:j,opened:t,givens:f,catalog:c}),{filterDialog:Ke,setFilterDialog:Ie}=Pe,[Qe,Ze]=S.useState(void 0),{draftDirty:A,openDraft:z,prepare:K}=bw({editorDirty:j.dirty}),G=De.drag!==void 0,ke=S.useMemo(()=>({paused:G,escape:()=>{!we&&!Ke&&!ye&&Qe===void 0&&D()},move:(J,he)=>{if(ge||N===void 0||!O.widths||!Y)return!1;const Ne=j.document.tiles[N];if(!Ne||Ne.row===void 0||Ne.col===void 0)return!1;const xe=Ul(j.document.tiles,N,J,he,W);if(xe.every((pe,He)=>pe===j.document.tiles[He]))return!0;const dn=fe(Ne);j.update(pe=>{pe.tiles=Kn(Ul(pe.tiles,N,J,he,W))});const de=Kn(xe).findIndex(pe=>fe(pe)===dn);return de>=0&&L(de),!0},nudge:J=>{if(ge||N===void 0||!O.widths||!Y)return;const he=j.document.tiles[N];if(!he)return;const Ne=gp(he.colspan??Z,J,Rd(he,W));Ne!==(he.colspan??Z)&&j.update(xe=>{xe.tiles[N]=mo(xe.tiles[N],Ne,W,Z),xe.tiles=Q(xe.tiles,N)})}}),[G,Z,Y,Q,L,j,we,Ke,ye,Qe,D,N,W,O,ge]),je=dw({editor:E,extraDirty:A,keepsEdits:T!==void 0&&M.keeping,prepare:K,unit:{name:"tile",count:J=>J.tiles.length},onSave:n,onDirtyChange:i,onExit:s,onChange:r,shortcuts:ke,report:rw({size:j.document.tiles.length,path:w??"",layout:j.document.layout,savesTo:g,onEvent:p})}),Mt=j.document.tiles.length===0,{toolbarProps:P}=je,ue=M.restored,Je={status:je.saving?"saving":P.dirty?"unsaved":"saved",saveTarget:v??Mo[g],...M.keptAt!==void 0?{draftKeptAt:M.keptAt}:{},...(P.dirty||ue?.pending)&&T!==void 0?{discard:M.discard}:{},...ue?{restored:ue}:{},...ue&&!ue.pending?{dismissRestored:M.dismissRestored}:{}},Be=j.document.tiles,st=N!==void 0&&Be[N]?fe(Be[N]):void 0,ie=O.widths&&Y&&rn(Be)?{...tg(Be,W)?{pack:()=>H(Kn(Ad(Be,W)),st)}:{},flow:()=>H(ng(Be),st)}:void 0;iw($,{...Je,...P.onSave?{save:P.onSave}:{},canUndo:P.canUndo,undo:P.onUndo,canRedo:P.canRedo,redo:P.onRedo,add:{...c?{tile:()=>X.openAdd()}:{},text:X.appendText,...x!==void 0?{filterUnavailable:x}:Mt?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>Ie({})}},...P.onExit?{exit:P.onExit}:{},...je.done?{done:je.done}:{},...ue?.pending?{restore:M.restoreOffered}:{},...ie?{arrange:ie}:{}});const et=$?void 0:m.jsx(lg,{...je.toolbarProps,...l?{actions:l}:{},...c?{onAddTile:()=>se()}:{},...ie?{arrange:m.jsx(Jf,{arrange:ie})}:{},savesTo:g,...v?{saveLabel:v}:{},...T!==void 0&&P.onSave?{saveStatus:Je}:{}});return m.jsx(af.Provider,{value:z,children:m.jsx(ft,{className:rt.builder,"data-saves-to":g,sx:{gap:0,mx:`-${fo}px`},children:m.jsxs(vp,{layout:O.layout,sx:{px:`${fo}px`,pb:`${fo}px`},header:m.jsx(nw,{editor:j,documentSlug:U,actions:et,descriptionSelected:R,selectDescription:q}),controls:Mt?void 0:m.jsx(sw,{controls:Pe.controlList,unknownFieldsOf:Pe.unknownFieldsOf,onEdit:J=>Ie({control:J}),onAdd:()=>Ie({}),...x?{addDisabledReason:x}:{},onRemove:Pe.dropControl,...y?{fixedFilters:y}:{},...k?{onOpenModel:k}:{},...j.document.startingGivens?{startingValues:j.document.startingGivens}:{},onStartingValue:(J,he)=>j.update(Ne=>{const xe={...Ne.startingGivens??{}};he===void 0?delete xe[J]:xe[J]=he,Object.keys(xe).length>0?Ne.startingGivens=xe:delete Ne.startingGivens}),children:d}),children:[Mt&&m.jsxs(ft,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx(ve,{variant:"body2",children:"This report is not served until it has a tile."}),c&&m.jsx(Ae,{size:"small",startIcon:m.jsx(vi,{}),onClick:()=>se(),children:"Add tile"})]}),ue?.pending&&m.jsx(ht,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx(Ae,{color:"inherit",size:"small",onClick:M.restoreOffered,children:"Restore them"}),m.jsx(Ae,{color:"inherit",size:"small",onClick:M.discard,children:"Discard"})]}),children:`You have unsaved edits from ${$o(ue.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),j.error&&m.jsx(ht,{severity:"warning",children:j.error}),!Y&&m.jsx(ht,{severity:"info",children:"This window is too narrow for the grid, so tiles stack in one column, as on a phone. Widen it to move tiles or change their width."}),m.jsx(J0,{editor:j,arrange:Y,reorder:re,edging:De,place:Q,gridBox:I,defaultSpan:Z,rules:O,canAdd:!!c,selected:N,flash:F,menuIndex:we?.index,onSelect:L,onOpenMenu:(J,he)=>{L(he),X.setMenu({anchor:J,index:he})},onRemove:X.removeTile,...j.document.tiles.length===1&&j.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:se,editTile:X.editTile,...o?{renderTile:o}:{}}),m.jsx(Ug,{editor:j,catalog:c,columns:W,dashboards:u,bindings:Pe,tiles:X,drillSource:Qe,setDrillSource:Ze,exitDialog:je.exitGuard.dialog,...a?{renderViewPreview:a}:{},...C?{takenGivenNames:C}:{}})]})})})}const kw=mt(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),Sw=mt(m.jsx("path",{d:"M9 17H7v-7h2zm4 0h-2V7h2zm4 0h-2v-4h2zm2.5 2.1h-15V5h15zm0-16.1h-15c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"})),$w=mt(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function Yw({controls:e,onDone:t}){const n=t??e?.exit,r=ad("(max-width: 599.95px)"),{theme:i}=qe(),s=cn(i.cardBorder),o=Cs(i.cardBorder,i.tileTitle),[a,d]=S.useState(null),f=e?.save!==void 0&&e.status!=="saved",c=e?.done??n,l=f&&e?.done===void 0,u=e?.add,p=u!==void 0&&(u.tile!==void 0||u.text!==void 0||u.filter!==void 0||u.filterUnavailable!==void 0),g=v=>()=>{d(null),v?.()};return m.jsxs(ft,{direction:"row",role:"toolbar",className:rt.builderBar,"aria-label":"Report builder",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[e&&m.jsxs(m.Fragment,{children:[e.save&&m.jsx(Id,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx(Ot,{title:`Undo (${Sn}Z)`,children:m.jsx("span",{children:m.jsx($n,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:oi(i.ui),children:m.jsx(Pd,{fontSize:"small"})})})}),m.jsx(Ot,{title:`Redo (${Sn}⇧Z)`,children:m.jsx("span",{children:m.jsx($n,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:oi(i.ui),children:m.jsx(Dd,{fontSize:"small"})})})}),e.arrange&&m.jsx(Jf,{arrange:e.arrange}),p&&m.jsx(nr,{orientation:"vertical",sx:os}),p&&m.jsxs(m.Fragment,{children:[m.jsx(Ae,{variant:"outlined",startIcon:m.jsx(vi,{}),endIcon:m.jsx(Sa,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:v=>d(v.currentTarget),sx:{...Yr(s,o),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs(Xn,{anchorEl:a,open:a!==null,onClose:()=>d(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:jw(s,i.ui)}},MenuListProps:{sx:{p:.5}},children:[u?.tile&&m.jsx(po,{icon:m.jsx(Sw,{}),title:"Tile",detail:"A chart or table from the model",onClick:g(u.tile)}),u?.text&&m.jsx(po,{icon:m.jsx($w,{}),title:"Text",detail:"Prose between the tiles",onClick:g(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(po,{icon:m.jsx(kw,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:g(u.filter)})]})]})]})]}),(c||l)&&e&&m.jsx(nr,{orientation:"vertical",sx:os}),c&&m.jsx(Ot,{enterDelay:800,enterNextDelay:800,title:e?.done&&f?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx(Ae,{variant:l?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:c,sx:{...Yr(s,o,i.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&l&&m.jsx(Ot,{title:`Save (${Sn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx(Ae,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...Yr(s,o,i.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const jw=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function po({icon:e,title:t,detail:n,disabled:r=!1,onClick:i}){const{theme:s}=qe(),o=s.ui;return m.jsxs(Xe,{onClick:i,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:o.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:o.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${nt}, background-color ${nt}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:s.accent,bgcolor:`color-mix(in srgb, ${s.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx(_,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs(_,{className:"add-text",sx:{minWidth:0},children:[m.jsx(_,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx(_,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function Mw(e,t,n=new Set,r=new Map){const i=[];for(const c of e.tiles){if(!le(c))continue;const l=(c.filters??[]).map(p=>p.given),u=r.get(Ft(`${c.source} -> ${c.name}`))??[];for(const p of u)(n.has(p)||l.includes(p))&&i.push(p);i.push(...l)}const s=new Set(i),o=t.flatMap(c=>c.name!==void 0&&n.has(c.name)&&!s.has(c.name)?[c.name]:[]),a=new Map((e.localGivens??[]).map(c=>[c.name,c])),d=new Map(t.flatMap(c=>c.name===void 0?[]:[[c.name,c]])),f=[];for(const c of new Set([...o,...i])){const l=a.get(c),u=l?Tm(l):d.get(c);u&&f.push(u)}return f}function Ew(e,t,n){const r=new Map;for(const s of t.tiles)le(s)&&r.set(Ft(vt(s)),new Set((s.filters??[]).map(o=>o.given)));const i=new Set;for(const s of e.tiles){if(!le(s))continue;const o=Ft(vt(s)),a=r.get(o);for(const d of n.get(o)??[])a?.has(d)||i.add(d)}return i}function Cw(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function Tw(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function Ft(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function Ow(e,t,n,r){const i=new Set(t.sources.map(o=>o.name)),s=new Set(e.sources.map(o=>o.name).filter(o=>!i.has(o)));return s.size===0?void 0:{sources:s,modelOf:o=>{if(r)return;const a=e.imports.find(f=>f.kind==="names"&&f.names.includes(o));if(a===void 0)return;const d=Om(a.from,n);return Am(t,o,d,n)?void 0:d}}}function Aw(e,t,n){if(!n||t.declaration.kind!=="reference")return;let r=t.source,i=t.declaration.from;if(r===void 0||!n.sources.has(r))return;const s=e.tiles.length+e.sources.length;for(let o=0;o<=s;o++){if(!n.sources.has(r)){const f=n.modelOf?.(r);return{source:r,view:i,...f?{modelPath:f}:{}}}const a=e.sources.find(f=>f.name===r);if(!a||a.scopedBy?.length)return;const d=e.tiles.find(f=>le(f)&&f.source===r&&f.name===i);if(!d)r=a.base;else if(d.declaration.kind==="reference")i=d.declaration.from;else return}}function Rw(e,t,n,r=new Map,i,s){if(cr(t))return{expression:vt(t),givenNames:void 0,reads:i&&[...i]};const o=Aw(e,t,s),a=o?.source??t.source,d=o?.view??(t.declaration.kind==="reference"?t.declaration.from:t.name),f=o?.modelPath!==void 0?new Set:n,c=new Map((e.localGivens??[]).map(k=>[k.name,k.type])),l=new Map((e.localGivens??[]).map(k=>[k.name,k.default])),u=e.sources.find(k=>k.name===a)?.scopedBy??[],p=new Set([...u,...i??[]].filter(k=>f.has(k))),g=new Set([...u,...i??[]]),v=[];for(const k of t.filters??[]){const C=`where: ${Oa(k.field)} ${k.op??"~"}`;if(f.has(k.given)){p.add(k.given),g.add(k.given),v.push(`${C} $${k.given}`);continue}if(!c.has(k.given))continue;g.add(k.given);const $=Rm(r.get(k.given),c.get(k.given))??Cw(l.get(k.given));$!==void 0&&v.push(`${C} ${$}`)}const b=v.join(", "),w=t.chart,h=w==="none"||Os(w)?Qn(w,t.chartCarried):w==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
+ `):w==="default"&&Tw(t.declaration)?Dm():void 0,x=t.color!==void 0?$d(t.color):t.declaration.kind!=="reference"&&!t.ownPalette?Pm:void 0,y=[h,x].filter(Boolean).join(`
144
+ `)||void 0;return{...y?{annotation:y}:{},...o?.modelPath!==void 0?{modelPath:o.modelPath}:{},expression:`${a} -> ${d}`+(b?` + { ${b} }`:""),givenNames:Array.from(p),reads:i||g.size>0?Array.from(g):void 0}}function Dw({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:i,reportsSettled:s}){const{apiClients:o,server:a}=$a(),{data:d}=ja({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(g=>g.path&&!g.error?[g.path]:[])}),f=S.useMemo(()=>new Set([r,...i.flatMap(g=>g.path?[g.path]:[])]),[i,r]),c=S.useMemo(()=>s?(d??[]).filter(g=>!f.has(g)):[],[d,f,s]),l=Cm({queries:c.map(g=>({queryKey:["report-editor-model",e,t,g,n,a],queryFn:async()=>(await o.models.getModel(e,t,g,n)).data,retry:!1}))}),u=d!==void 0&&s&&l.every(g=>g.isSuccess||g.isError),p=l.map(g=>g.dataUpdatedAt).join();return S.useMemo(()=>u?pw(l.flatMap((g,v)=>g.data?[{...g.data,path:c[v]}]:[]),f):void 0,[u,c,p,f])}const Pw={};function Iw({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:i,queryVersionId:s,opened:o,replaces:a,onSave:d,onDirtyChange:f,onExit:c,onOpenModel:l,onControlsChange:u,draftKey:p,onEvent:g,savesTo:v,saveLabel:b,note:w,fileModel:h}){const{apiClients:x}=$a(),[y,k]=S.useState(o.document.tiles.length>0);S.useEffect(()=>k(o.document.tiles.length>0),[o.generation,o.document]);const{data:C,isSuccess:$,isError:T}=ja({...qp(x,{environmentName:t,packageName:n,path:r,versionId:s},Hp),enabled:y&&!e}),j=e?.modelPath??r,M=Ww(o.source,e?.compileSource),I=Up({environmentName:t,packageName:n,modelPath:j,source:M.text??o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&M.text!==void 0}),N=I.data?.document,R=e?I.isSuccess?N?.manifest??Pw:void 0:C,L=e?I.isSuccess:$,B=e?I.isError||M.problem!==void 0:T,q=e?Vp(N?.cells):void 0,D=(I.data?.result.problems??[]).filter(P=>P.severity==="error"),F=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),E=e?.givens,O=S.useMemo(()=>new Set((R?.tiles??[]).flatMap(P=>P.restricted&&P.query?[Ft(P.query)]:[])),[R]),{reports:W,settled:U}=Kp(t,n,s),V=S.useMemo(()=>W.map(P=>P.path).filter(P=>!!P&&P!==r&&P.endsWith(".malloy")).map(P=>P.replace(/\.malloy$/,"")),[W,r]),Y=Dw({environmentName:t,packageName:n,...s!==void 0?{versionId:s}:{},modelPath:r,reports:W,reportsSettled:U}),re=S.useMemo(()=>e?(Y?.sources??[]).filter(P=>(P.visibleIn??P.exporters??[P.modelPath]).includes(j)).map(P=>P.name):void 0,[Y,e,j]),H=S.useMemo(()=>h?fw(h):void 0,[h]),ne=S.useMemo(()=>{const P=Y&&re?{sources:Y.sources.filter(ue=>re.includes(ue.name))}:Y;return P&&H?{...P,documentViews:H}:P},[Y,re,H]),[Q,ge]=S.useState(o.document);S.useEffect(()=>ge(o.document),[o.document]);const Z=S.useMemo(()=>d&&(async(P,ue)=>{await d(P,ue.document.layout),v==="package"&&k(ue.document.tiles.length>0)}),[d,v]),Re=S.useMemo(()=>(R?.givens??[]).filter(P=>!(e&&P.secure===!0)&&!(P.name!==void 0&&F.has(P.name))),[R,F,e]),De=S.useMemo(()=>new Set([...Re.map(P=>P.name).filter(P=>P!==void 0),...Object.keys(E??{})]),[Re,E]),X=S.useMemo(()=>new Map((R?.tiles??[]).flatMap(P=>P.kind!=="text"&&P.query&&P.givenNames?[[Ft(P.query),P.givenNames]]:[])),[R]),we=S.useMemo(()=>new Map((R?.tiles??[]).flatMap(P=>P.kind!=="text"&&P.query&&P.label?[[Ft(P.query),P.label]]:[])),[R]),ye=S.useMemo(()=>Ew(Q,o.document,X),[Q,o.document,X]),se=S.useMemo(()=>Mw(Q,Re,ye,X),[Q,Re,ye,X]),Pe=S.useMemo(()=>{const P=new Set(Q.tiles.flatMap(ie=>le(ie)?(ie.filters??[]).map(et=>et.given):[])),ue=new Set((Q.localGivens??[]).map(ie=>ie.name)),Je=[...new Set(Q.imports.map(ie=>ie.from))],Be=Je.length===1?zw(r,Je[0]):Je.length===0&&e?e.modelPath:void 0,st=ie=>{const et=Q.sources.filter(J=>J.scopedBy?.includes(ie)).map(J=>J.name);return et.length>0?{reason:`Applied to every tile on ${et.join(", ")} by this report's own source. Edit the file to change it.`}:ue.has(ie)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:Be!==void 0?{reason:`Set in the model ${Be}. Edit the model to change it.`,modelPath:Be}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...ye].filter(ie=>!P.has(ie)).map(ie=>[ie,st(ie)]))},[Q,ye,e,r]),{declaredTypes:Ke,applied:Ie,panel:Qe}=Gp({specs:se,loaded:L,startingValues:R?.startingGivens,documentKey:`${t}/${n}/${i??""}/${r}/edit`,autorun:R?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?j:R?.path,versionId:s,documentName:r,...q!==void 0?{preamble:q}:{},...E?{hostGivens:E}:{}}),Ze=S.useMemo(()=>Yp(se,Ie,E),[se,Ie,E]),A=S.useMemo(()=>Object.fromEntries(Object.entries(E??{}).filter(([P])=>!Ke.has(P))),[E,Ke]),z=!y||L||B,K=e!==void 0&&(M.problem!==void 0||I.isError||D.length>0),G=S.useMemo(()=>new Map(o.document.tiles.map(P=>[fe(P),P])),[o.document]),ke=S.useMemo(()=>Ow(Q,o.document,r,!!e),[Q,o.document,r,e]),je=S.useMemo(()=>function(P,ue,Je="card"){const Be=(cr(P)?we.get(Ft(vt(P))):void 0)??As(P);if(K)return m.jsxs(xo,{chrome:Je,children:[m.jsx(bo,{title:ue?.title??Be,subtitle:ue?ue.subtitle:P.subtitle}),m.jsx(ve,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!z)return m.jsxs(xo,{chrome:Je,children:[m.jsx(bo,{title:ue?.title??Be,subtitle:ue?ue.subtitle:P.subtitle}),m.jsx(go,{text:"Running…"})]});const st=X.get(Ft(vt(P))),ie=q===void 0&&st!==void 0&&Nw(G.get(fe(P)),P)?{expression:vt(P),givenNames:[...st],reads:[...st]}:Rw(Q,P,De,Ie,st,ke),et=ld(Q.layout,Q.columns);return m.jsx(Ll,{environmentName:t,packageName:n,versionId:s,modelPath:ie.modelPath??j,...q!==void 0&&ie.modelPath===void 0?{preamble:q}:{},...O.has(Ft(vt(P)))?{restricted:!0}:{},tile:ie.expression,...ie.annotation?{annotation:ie.annotation}:{},label:Be,chrome:Je,subtitle:P.subtitle,...ue?{heading:ue}:{},borderless:P.borderless,givens:Ie,hostGivens:A,declaredTypes:Ke,givenNames:ie.givenNames,...(()=>{const J=Qp(Ze,ie.reads??ie.givenNames);return J.length>0?{waitingFor:Zp(J)}:{}})(),ignoredFilters:Xp(ie.reads,se),height:P.rowspan!==void 0||rn(Q.tiles)?fd(P.rowspan??Ea.query):et.tileMaxHeight,tableMaxHeight:et.tableMaxHeight,fixedHeight:P.rowspan!==void 0||rn(Q.tiles)})},[Q,G,z,K,Ze,De,X,we,t,n,s,j,q,ke,O,Ie,A,Ke,se]),Mt=S.useMemo(()=>function(P){return m.jsx(Ll,{environmentName:t,packageName:n,versionId:s,modelPath:P.modelPath,tile:`${P.base} -> ${P.view}`,...P.chart?{annotation:Qn(P.chart,P.chartCarried)}:{},label:P.label,borderless:!0,givens:Ie,hostGivens:A,declaredTypes:Ke,givenNames:P.givens,height:200})},[t,n,s,Ie,A,Ke]);return m.jsxs(ft,{sx:{gap:1},children:[e&&D.length>0&&m.jsxs(ht,{severity:"error",children:["The server could not compile this document:"," ",D.map(P=>P.message).join("; ")]}),Ze.length>0&&!K&&m.jsx(ht,{severity:"info",children:Jp(Ze)}),e&&M.problem!==void 0&&m.jsxs(ht,{severity:"error",children:["This document could not be prepared to compile:"," ",M.problem]}),e&&I.isError&&m.jsxs(ht,{severity:"error",children:["The server could not compile this document:"," ",I.error?.message]}),m.jsx(ep,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:o.source,document:o.document,fixedFilters:Pe,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:je,renderViewPreview:Mt,givens:se.filter(P=>P.name!==void 0).map(P=>({name:P.name,...P.label?{label:P.label}:{},...P.type?{type:P.type}:{},...P.suggest?.dimension?{field:P.suggest.dimension}:{}})),onChange:ge,onDirtyChange:f,...c?{onExit:c}:{},...l?{onOpenModel:l}:{},...u?{onControlsChange:u}:{},...p!==void 0?{draftKey:p}:{},...ne?{catalog:ne}:{},dashboards:V,...g?{onEvent:g}:{},controls:L?m.jsx(em,{...Qe,layout:"bar"}):void 0,...Z?{onSave:Z}:{},savesTo:v,...b?{saveLabel:b}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:re}:{}}),m.jsx(_,{sx:{px:.5},children:m.jsx(ve,{variant:"caption",sx:{opacity:.7},children:w})})]})}function Nw(e,t){return e!==void 0&&JSON.stringify(od(e))===JSON.stringify(od(t))}function od(e){const{label:t,subtitle:n,colspan:r,break:i,rowspan:s,row:o,col:a,borderless:d,...f}=e;return f}function Ww(e,t){const n=S.useRef(t);n.current=t;const r=t!==void 0,[i,s]=S.useState();return S.useEffect(()=>{if(!r)return;let o=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{o&&s({from:e,text:a})},a=>{o&&s({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{o=!1}},[e,r]),r?i?.from!==e?{}:i.problem!==void 0?{problem:i.problem}:{text:i.text}:{text:e}}function zw(e,t){const n=e.split("/").slice(0,-1);for(const r of t.split("/"))r===".."?n.pop():r!=="."&&r!==""&&n.push(r);return n.join("/")}function Lw({storage:e,layout:t,notebook:n,environmentName:r,packageName:i,modelPath:s}){const[o,a]=S.useState(void 0),[d,f]=S.useState(void 0),[c,l]=S.useState(e===void 0),[u,p]=S.useState(!1),[g,v]=S.useState(void 0);return S.useEffect(()=>{if(!e)return;let b=!1;return v(void 0),(async()=>{try{const w=Wp(await e.listWorkspaces(!1));if(b)return;if(a(w),w!==void 0&&(!n||w.authoritative)){const h=await e.getDocument(md(t,w.name,r,i,s)).catch(x=>{if(!gd(x))throw x});if(b)return;f(h),p(h!==void 0)}}catch(w){if(b)return;v(vd(w))}b||l(!0)})(),()=>{b=!0}},[e,t,n,r,i,s]),{workspace:o,draft:d,setDraft:f,draftChecked:c,offered:u,setOffered:p,readFailure:g}}const Fw=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Bw(e){const t=await va(e);return ga(t)?{ok:!1,reason:Fw(t.reason,t.line)}:{ok:!0,document:t.document}}const _w="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",qw="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Hw({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:i,fetchedAt:s,packageSettled:o,modelPath:a,layout:d,notebook:f,noun:c,legacyFormat:l,textHeld:u,startedAt:p,onEventRef:g}){const v=S.useRef({path:a,layout:d});v.current={path:a,layout:d};const b=S.useRef((X,we)=>{try{g.current?.(zp(X,{...v.current,...we?{layout:we}:{}}))}catch{}}),w=e?.authoritative===!0,h=w&&r!==void 0,[x,y]=S.useState(void 0),k=(w||x===!0)&&t!==void 0,[C,$]=S.useState(void 0),[T,j]=S.useState(l?_w:void 0),M=S.useRef(void 0),I=S.useRef(void 0),[N,R]=S.useState(void 0),L=S.useRef(s);L.current=s;const B=N!==void 0&&N.onFetch===s?N.text:i,q=S.useRef(B);q.current=B;const D=k?t:B,[F,E]=S.useState(!1),[O,W]=S.useState(void 0),[U,V]=S.useState(void 0),Y=D!==void 0&&D!==U,re=C?.source,H=Y&&(F||!w&&t!==void 0&&re===t&&t!==B)&&re!==void 0&&D!==O,ne=H?re:Y?D:re??D,Q=H?D:void 0,ge=S.useRef(re);ge.current=re;const Z=S.useRef(D);Z.current=D;const Re=S.useRef("package");Re.current=k?w?"record":"draft":"package",S.useEffect(()=>{if(ne===void 0||!n||h||ne===ge.current)return;let X=!1;const we=q.current,ye=Z.current;return Bw(ne).then(se=>{if(!X){if(se.ok===!1){j(se.reason),b.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}j(void 0),M.current=void 0,I.current=we,R(void 0),W(void 0),V(ye),$(Pe=>({source:ne,document:se.document,...we!==void 0?{packageText:we}:{},generation:(Pe?.generation??0)+1})),b.current({type:"report.opened",surface:"edit",from:Re.current,tiles:se.document.tiles.length,durationMs:Qt()-p.current},se.document.layout)}}).catch(se=>{if(X)return;const Pe=`Could not read the ${c}: ${se instanceof Error?se.message:String(se)}`;j(Pe),b.current({type:"report.load_failed",surface:"edit",category:dd(se)})}),()=>{X=!0}},[ne,a,n,h,f,c,u,p]),S.useEffect(()=>{l&&b.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[l]),S.useEffect(()=>{!u||!n||C||r!==void 0||(w?t===void 0&&j("the host's storage has no document at this location."):j("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,C,r,w,t]);const De=f&&!u&&!C&&n&&!k&&o&&i===void 0;return S.useEffect(()=>{De&&(j(qw),b.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[De]),{authoritative:w,blockedOnRecord:h,resume:x,setResume:y,fromDraft:k,opened:C,setOpened:$,openError:T,savedHashRef:M,packageBaseRef:I,setWrote:R,fetchedAtRef:L,setDirty:E,setSeen:V,held:Q,choose:X=>{p.current=Qt(),W(X?t:B),y(X)},acceptHeld:()=>{p.current=Qt(),W(Q)}}}function Uw({storage:e,workspace:t,layout:n,notebook:r,environmentName:i,packageName:s,modelPath:o,versionId:a,apiClients:d,queryClient:f,mutable:c,textHeld:l,readFailure:u,authoritative:p,resume:g,setResume:v,setOpened:b,setDraft:w,setOffered:h,setSeen:x,setWrote:y,savedHashRef:k,packageBaseRef:C,fetchedAtRef:$}){const T=S.useCallback(E=>t===void 0?void 0:md(E,t.name,i,s,o),[t,i,s,o]),j=T(n),M=S.useCallback(async(E,O=n)=>{const W=T(O);if(!e||!W)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(W,E),b(U=>U&&{...U,source:E}),w(E),(p||g===!0)&&x(E),p||v(U=>U??!1)},[e,T,n,p,g,b,w,x,v]),[I,N]=S.useState(void 0),R=S.useCallback(async E=>{const O=await Lp(k.current,C.current);if(O===void 0)throw new Error("The package file is still loading; try again.");const W=["dashboard-editor-model",i,s,o,a,r];await Fp({apiClients:d,queryClient:f,environmentName:i,packageName:s,modelPath:o,source:E,expectedHash:O,invalidateOnError:[W],afterWrite:async U=>{if(b(V=>V&&{...V,source:E}),y({text:E,onFetch:$.current}),x(E),k.current=U,N(void 0),e&&j)try{await e.deleteDocument(j),w(void 0),h(!1)}catch(V){gd(V)?(w(void 0),h(!1)):N(vd(V))}v(!1)},invalidate:[{queryKey:W,wait:!0},{queryKey:Em({environmentName:i,packageName:s,versionId:a,modelPath:o})}]}),Bp(f,i,s,o)},[d,i,s,o,a,r,e,j,f,k,C,$,b,y,x,w,h,v]),L=t?.writeable===!0,B=c===!0&&!l,{savesTo:q,pinnedPackageSave:D,writer:F}=Mm({authoritative:p,mutable:B,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!j&&L&&(!r||p),readFailed:u!==void 0});return{save:F==="storage"?M:F==="package"?R:void 0,savesTo:q,writer:F,pinnedPackageSave:D,takesWrites:B,supersedeFailure:I}}function tp(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:i,onOpenModel:s,onControlsChange:o,keepDraft:a,kind:d,path:f,textSource:c,queryVersionId:l}=e,u=e.layout??(d?xp(d):"grid"),p=u==="linear",g=c!==void 0,{environmentName:v,packageName:b,versionId:w,namesBoth:h}=bp(e),x=("resourceUri"in e?e.dashboard:e.dashboardName)??yp(f)??"",y="report",{apiClients:k,mutable:C,isLoadingStatus:$,server:T}=$a(),j=wp(),M=S.useRef(Qt()),I=S.useRef(t);I.current=t;const N=S.useRef(r);N.current=r;const R=kp()?.documentStorage,L=f??Np(d??"dashboard",x),B=/\.malloynb$/i.test(L)||p&&/\.malloynb$/i.test(x),q=ja({queryKey:["dashboard-editor-model",v,b,L,w,p],queryFn:()=>k.models.getModel(v,b,L,w,p?!0:void 0),enabled:h&&!B&&!g}),D=q.data?.data?.sourceText,{workspace:F,draft:E,setDraft:O,draftChecked:W,offered:U,setOffered:V,readFailure:Y}=Lw({storage:R,layout:u,notebook:p,environmentName:v,packageName:b,modelPath:L}),{authoritative:re,blockedOnRecord:H,resume:ne,setResume:Q,fromDraft:ge,opened:Z,setOpened:Re,openError:De,savedHashRef:X,packageBaseRef:we,setWrote:ye,fetchedAtRef:se,setDirty:Pe,setSeen:Ke,held:Ie,choose:Qe,acceptHeld:Ze}=Hw({workspace:F,draft:E,draftChecked:W,readFailure:Y,packageText:D,fetchedAt:q.dataUpdatedAt,packageSettled:q.isSuccess&&!q.isFetching,modelPath:L,layout:u,notebook:p,noun:y,legacyFormat:B,textHeld:g,startedAt:M,onEventRef:I}),{save:A,savesTo:z,writer:K,pinnedPackageSave:G,takesWrites:ke,supersedeFailure:je}=Uw({storage:R,workspace:F,layout:u,notebook:p,environmentName:v,packageName:b,modelPath:L,versionId:w,apiClients:k,queryClient:j,mutable:C,textHeld:g,readFailure:Y,authoritative:re,resume:ne,setResume:Q,setOpened:Re,setDraft:O,setOffered:V,setSeen:Ke,setWrote:ye,savedHashRef:X,packageBaseRef:we,fetchedAtRef:se}),Mt=F?.name,P=S.useCallback(xe=>{I.current?.(Sp(xe,Mt))},[Mt]),ue=q.isError&&!Z,Je=S.useRef(!1);S.useEffect(()=>{!ue||Je.current||(Je.current=!0,cd({path:L,layout:u},I.current).emit({type:"report.load_failed",surface:"edit",category:dd(q.error)}))},[ue,q.error,L,u]);const Be=S.useCallback((xe,dn)=>{Pe(xe),N.current?.(dn)},[Pe]),st=!c&&q.data?.data&&D!==void 0&&Z?.source===D?q.data.data:void 0,ie=a?_p({server:T,environmentName:v,packageName:b,versionId:w,path:f??x}):void 0,et=z==="host"&&F?.description?F.description:void 0,J=!re&&!g&&C===void 0?$?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":$p({authoritative:re,mutable:ke,pinnedPackageSave:G,...F?{workspace:F}:{},...Y!==void 0?{readFailure:Y}:{},...w!==void 0?{versionId:w}:{}}),he=z==="package"&&ke===!0&&!G&&Y===void 0||J===et?"":J;if(!h&&"resourceUri"in e)return m.jsxs(ht,{severity:"error",sx:{m:2},children:["A ",y," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(De)return m.jsxs(ht,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened in the builder: ",De]});if(q.isError&&!Z)return m.jsx(jp,{error:q.error,context:`Opening the ${y}`});if(!Z&&(!(g||D)||!W))return n??m.jsx(go,{text:`Opening the ${y}…`});if(H)return m.jsxs(ht,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened: ",Y]});const Ne=E!==void 0&&E!==D;return m.jsxs(ft,{sx:{gap:2},children:[q.isError&&m.jsxs(ht,{severity:"warning",children:["The ",y," could not be re-read from the server:"," ",q.error?.message,". Your edits are still here."]}),!p&&!re&&U&&Ne&&ne===void 0&&m.jsx(ht,{severity:"info",action:m.jsxs(ft,{direction:"row",sx:{gap:1},children:[m.jsx(Ae,{size:"small",onClick:()=>Qe(!0),children:"Resume"}),m.jsx(Ae,{size:"small",onClick:()=>Qe(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),Ie!==void 0&&m.jsx(ht,{severity:"warning",action:m.jsx(Ae,{size:"small",onClick:()=>{ie!==void 0&&Mp(ie),Ze()},children:"Load it"}),children:z==="package"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":z==="host"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this report changed since you opened it. Your edits are still here; loading the new version replaces them."}),je!==void 0&&m.jsxs(ht,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",je]}),!Z&&(n??m.jsx(go,{text:`Opening the ${y}…`})),Z&&m.jsx(Iw,{environmentName:v,packageName:b,modelPath:L,...c?{textSource:c}:{},slug:x,...w!==void 0?{versionId:w}:{},...(l??w)!==void 0?{queryVersionId:l??w}:{},opened:Z,...ge&&K==="package"&&Z.packageText!==void 0?{replaces:Z.packageText}:{},onSave:A,onDirtyChange:Be,...i?{onExit:i}:{},...s?{onOpenModel:s}:{},...o?{onControlsChange:o}:{},...ie!==void 0?{draftKey:ie}:{},savesTo:z,...et?{saveLabel:et}:{},...t?{onEvent:P}:{},note:he,...st?{fileModel:st}:{}},Z.generation)]})}const Xw=tp,Qw=ep;function Zw(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:i}=e,s="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(tp,{...s,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:_l===void 0&&(_l={});export{Yw as BuilderBar,Qw as DashboardBuilder,Xw as DashboardEditor,tk as MAX_SLUG_ATTEMPTS,Zw as NotebookEditor,ep as ReportBuilder,tp as ReportEditor,pw as buildCatalog,nk as createDocument,rk as createRoute,md as locatorFor,ik as newDashboardSource,sk as newDocumentProblem,ok as newNotebookSource,va as readDashboardDocument,ga as readFailed,Gw as readReportTagOfText,ak as reportPathFor,lk as reportPathForTitle,ck as slugFor,dk as slugOrFallback,C0 as spliceDashboardDocument,xa as spliceFailed,uk as useDocumentChoices};