@malloy-publisher/app 0.17.0 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-doc.yaml +212 -618
- package/dist/assets/{EnvironmentPage-D2-0ts2G.js → EnvironmentPage-DF2PahCR.js} +1 -1
- package/dist/assets/{HomePage-S_Bkczsx.js → HomePage-DIYlgPCz.js} +1 -1
- package/dist/assets/{MainPage-DEy4SyjJ.js → MainPage-C7PGAA5k.js} +1 -1
- package/dist/assets/ModelPage-BMoBnrW7.js +2 -0
- package/dist/assets/PackagePage-DD2vLSFe.js +1 -0
- package/dist/assets/{PackageSplatRoute-ChFCJOWE.js → PackageSplatRoute-BYIMwnLL.js} +2 -2
- package/dist/assets/{RenderedResult-BcEDcw0V.es-BD6PNbt6.js → RenderedResult-CYJ2Y9Fm.es-C8nokn71.js} +7 -7
- package/dist/assets/{RouteError-CDSSYdLB.js → RouteError-B8dE60Vs.js} +1 -1
- package/dist/assets/{ThemeEditorPage-DO2JWYOR.js → ThemeEditorPage-D0wf74fh.js} +1 -1
- package/dist/assets/{ToggleButtonGroup-BylAiUaK.js → ToggleButtonGroup-CX0_J2zR.js} +1 -1
- package/dist/assets/{documentRoutes-CaOt2rpR.js → documentRoutes-DgSMAc0m.js} +1 -1
- package/dist/assets/{editPageMounted-79YCIKgP.js → editPageMounted-BUGVg-_g.js} +2 -2
- package/dist/assets/{index-BOCBPBsi.js → index-BQL8UUcK.js} +1 -1
- package/dist/assets/{index-CPSEdm5f.js → index-BiOT4K_d.js} +1 -1
- package/dist/assets/{index-keJ8KKBp.js → index-DAQjZOAL.js} +1 -1
- package/dist/assets/index-DRkw60sj.js +512 -0
- package/dist/assets/{index.es-DTreXoC5.js → index.es-DgNl8IqU.js} +20 -20
- package/dist/assets/usePackageLinkNavigate-bHr_AFYo.js +1 -0
- package/dist/assets/{usePackageRoute-G6fA1__J.js → usePackageRoute-BhB6txS6.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/mcp-app/report.js +2683 -757
- package/package.json +2 -2
- package/dist/assets/ModelPage-BVHjDM-u.js +0 -2
- package/dist/assets/PackagePage-Cbrg7o1X.js +0 -1
- package/dist/assets/index-BKjEX4_C.js +0 -512
- package/dist/assets/usePackageLinkNavigate-BfSAqkJS.js +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{Z as id,V as _e,aO as cn,aP as Es,r as S,j as m,ad as ft,az as rt,N as Ot,L as $n,aQ as nr,a2 as De,aR as wa,aS as vi,aT as Xn,aU as ep,aV as sd,aW as rn,aX as tp,aY as np,aZ as mo,a_ as rp,T as pe,a1 as ht,a$ as ip,b0 as sp,b1 as op,Q as ka,ak as ap,b2 as Qt,b3 as lp,b4 as Sa,b5 as cp,b6 as od,b7 as ad,b8 as dp,b9 as up,a0 as go,ba as hp,bb as fp,bc as vo,aF as ld,B as cd,bd as nt,J as B,aj as Xe,be as mt,bf as $a,Y as Bt,bg as pp,bh as pt,bi as Il,bj as Gr,bk as dd,bl as mp,bm as ja,bn as gp,bo as vp,bp as xp,bq as bp,br as yp,bs as wp,bt as ud,bu as kp,bv as Sp,bw as hd,bx as fd,by as pd,bz as $p,bA as jp,bB as Mp,bC as Cp,bD as Ep,bE as Tp,bF as Op,bG as Dp,F as Ap,bH as Pp,bI as Rp,bJ as xo,bK as bo,bL as Nl,bM as Ip,bN as Np,bO as Wp,bP as Qn,bQ as Lp,bR as zp,bS as Fp,bT as Bp,bU as _p,bV as md,bW as Ma,bX as qp,bY as Hp,bZ as gd,b_ as Up,b$ as Vp,c0 as Kp,c1 as Ts,c2 as ns,c3 as Gp,c4 as Yp,c5 as rs,c6 as Xp,c7 as kn,c8 as Qp,c9 as Zp,ca as vd,cb as Jp,cc as em,ap as Ca,af as Zt,cd as tm,ce as yo,cf as nm,cg as rm,ch as xd,X as bd,ci as im,cj as sm,ck as Os,cl as om,cm as wo,cn as am,co as lm,cp as cm,cq as yd,cr as dm,G as um,cs as hm,ct as fm,cu as pm,cv as mm,cw as gm,cx as vm,cy as xm,cz as Ea,cA as bm,cB as ym,cC as wd,cD as wm,cE as km,cF as Sm,cG as Ta,cH as $m,cI as jm,cJ as Mm,cK as Pn,cL as kd,cM as Wl,cN as Ll,cO as Vs,cP as Cm,S as Em,cQ as Tm,cR as Om,cS as Dm,cT as Sd,cU as Am,cV as Pm,as as Rm}from"./index-BKjEX4_C.js";import{cW as Ww,cX as Lw,cY as zw,cZ as Fw,c_ as Bw,c$ as _w,d0 as qw,d1 as Hw,d2 as Uw,d3 as Vw,d4 as Kw}from"./index-BKjEX4_C.js";import{T as $d,a as ko}from"./ToggleButtonGroup-BylAiUaK.js";var zl={};const $e=e=>e.kind==="text",oe=e=>e.kind!=="text",Mr=e=>oe(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",ue=e=>$e(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,Fl=".malloy-big-value, .malloy-table",Im=e=>e.querySelector(Fl)!==null&&![...e.querySelectorAll(".malloy-chart")].some(t=>t.closest(Fl)===null),is=(e,t)=>$e(e)?Gp:t&&Im(t)?Yp:rs,ii=e=>e.rowspan??ja[$e(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 Nm(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,jd=ns+pt;function Md(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/jd)+1),col:Math.min(Math.max(o,1),r-s+1)}}function Cd(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=Md(a.left,a.top,c,n,r),u=(a.top+a.height+pt)/jd,p=$e(s)?Math.ceil(u-.02):Math.round(u);return{...f,...l,colspan:c,rowspan:s.rowspan??Math.max(is(s),p-l.row+1)}});return Ht(i,n)}function Bl(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 Ed(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 Wm=(e,t)=>Ed(e,t).some((n,r)=>n.row!==e[r].row||n.col!==e[r].col);function Lm(e){return Kn(e).map(t=>{const{row:n,col:r,...i}=t;return i})}const zm=(e,t,n)=>e.map((r,i)=>i===t?{...r,...n}:r);function _l(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(zm(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 Td=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1);function Fm(e){return $e(e)||e.rowspan===void 0?e:Os(e.chart)&&e.chart!=="big_value"&&e.rowspan<rs?{...e,rowspan:rs}:e}const Od=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"})),Dd=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"})),Bm=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 Ad(e){const{theme:t}=_e(),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 ${So(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(B,{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(B,{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(B,{component:"span","aria-hidden":!0,children:l}),m.jsx(wa,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:g?"visible":"hidden"}})]}),h=m.jsx(B,{component:"span",role:"status","aria-live":"polite",sx:_m,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[h,m.jsx(Ot,{title:u??p,describeChild:!0,children:g?m.jsx(cd,{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(B,{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(B,{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 ${So(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(Bm,{fontSize:"small"}),"Discard edits"]})]})]})}function So(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 _m={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},$o=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Sn=$o?"⌘":"Ctrl+",ql=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 qm(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=$o?s.metaKey:s.ctrlKey,d=s.key.toLowerCase();if(s.key==="Escape"){if(ql(s.target)||Ks(s.target))return;o.escape();return}if(ql(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(!$o&&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=$a)=>({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=$a)=>({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=$a)=>({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"}}}),jo={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Hm({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}=_e(),b=cn(v.cardBorder),w=Es(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(De,{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(Dd,{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(Od,{fontSize:"small"})})})}),(c||o||p)&&m.jsx(nr,{orientation:"vertical",sx:os}),c,o&&g&&m.jsx(Ad,{...g}),o?m.jsx(Ot,{title:i?`Save (${Sn}S) · ${d??jo[a]}`:d??jo[a],children:m.jsx("span",{children:m.jsx(De,{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(B,{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(um,{label:"Close",icon:m.jsx(Ts,{}),onClick:p})]})}const Um=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Hl={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 Pd(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 ${Hl[o].toLowerCase()} chart`;switch(Am(o,i)){case"no_x_axis":return Um(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:Hl[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ul(e){return e.description??Om(e.name)}const Vm={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"},Ei=(e,t)=>`${e}\0${t}`;function Km({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o,renderPreview:a}){const{theme:d}=_e(),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 P=new Set(t.sources.map(F=>F.base));return[...l].sort((F,C)=>Number(P.has(C.name))-Number(P.has(F.name)))},[l,t]),E=k.filter(P=>P.views.length>0),$=k.filter(P=>P.views.length===0),T=S.useMemo(()=>new Map(E.flatMap(P=>P.views.map(F=>[Ei(P.name,F.name),{source:P,view:F,key:Ei(P.name,F.name)}]))),[E]),j=S.useMemo(()=>E.map(P=>({key:P.name,label:P.name,...P.description?{detail:P.description}:{},entries:P.views.map(F=>({key:Ei(P.name,F.name),name:F.name,title:Ul(F),...F.chart?{chart:F.chart}:{}}))})),[E]),M=g===void 0?void 0:T.get(g);S.useEffect(()=>{if(!e)return;p(""),w(""),x("default");const P=E[0]?.views[0];v(P&&E[0]?Ei(E[0].name,P.name):void 0)},[e]);const I=M?[M.source.name,M.view.name].filter(P=>!wo(P)).map(P=>`"${P}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,W=M!==void 0&&I===void 0,A=M?Ul(M.view):"",z=h!=="default"&&M?{chart:h,chartCarried:M.view.chart?[M.view.chart]:[]}:{},_=(P=M)=>{if(!P||![P.source.name,P.view.name].every(wo))return;const F=P.key===M?.key,C=Pm(Math.ceil(r/2),r);s({base:P.source.name,modelPath:P.source.modelPath,...P.source.exporters?{exporters:P.source.exporters}:{},view:P.view.name,...F&&b.trim()?{label:b.trim()}:{},...F?z:{},...C!==void 0?{colspan:C}:{}})},q=M?Pd(M.view,h).filter(P=>P.value!=="custom"&&P.disabled!==!0):[];return m.jsx(Ca,{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(De,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx(De,{onClick:i,children:"Cancel"}),m.jsx(De,{variant:"contained",disabled:!W,onClick:()=>_(),children:"Add tile"})]}),children:m.jsxs(B,{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(B,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(am,{groups:j,query:u,onQuery:p,picked:M?.key,onPick:P=>{v(P),x("default")},onTake:P=>_(T.get(P)),searchRef:y,empty:m.jsx(pe,{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(pe,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",$.map(P=>P.name).join(", "),"."]})})}),m.jsx(B,{sx:P=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${P.palette.text.primary} 3%, ${P.palette.background.paper})`}),children:M?m.jsxs(m.Fragment,{children:[m.jsx(B,{"aria-label":"Preview",role:"region",sx:P=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${c}`,bgcolor:P.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${P.palette.background.paper})`}}),children:a?m.jsx(B,{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()||A,...h!=="default"?z:{},givens:M.source.givens})}):m.jsxs(B,{sx:P=>({flex:1,border:`1px solid ${c}`,borderRadius:f.radius.tile,bgcolor:P.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(lm,{chart:M.view.chart}),m.jsxs(pe,{variant:"body2",children:[M.source.name," → ",M.view.name]})]})}),m.jsx(Zt,{size:"small",label:"Title",placeholder:A,value:b,onChange:P=>w(P.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs(B,{children:[m.jsx(pe,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($d,{size:"small",exclusive:!0,value:h,"aria-label":"Chart",onChange:(P,F)=>{F!==null&&x(F)},sx:{...as(c,f),"& .MuiToggleButton-root":{...as(c,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:q.map(P=>m.jsx(ko,{value:P.value,children:P.label},P.value))}),m.jsx(pe,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:M.view.chart?`The model sets ${Vm[M.view.chart]??"a chart"}.`:"The model sets no chart, so it shows as a table."})]}),I&&m.jsx(pe,{variant:"body2",color:"error",children:I})]}):m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}function Gm(e,t,{modelPath:n,textHeld:r,widths:i,insertAt:s}){t.modelPath&&!r&&(e.imports=Cm(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Rd(e,t.base),a=Mo(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 Rd(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 Mo(e,t,n){const r=new Set(e.tiles.filter(oe).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 Ym(e,t){const n=e.tiles[t];if(!n||!oe(n)||ls(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...o}=structuredClone(n);r={...o,name:Mo(e,n.source,n.declaration.from)}}else{const s=e.sources.find(o=>o.name===n.source)??Rd(e,n.source,{unscoped:!0});r={name:Mo(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??Xp,t+1)),t+1}const Ti="self";function Xm({open:e,document:t,source:n,givenNames:r,dashboards:i,tileLabel:s,onClose:o,onApply:a}){const{theme:d}=_e(),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,E)=>{if(E!==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(Ca,{className:`${rt.dialog} ${rt.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[s&&m.jsxs(B,{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(De,{onClick:o,children:"Cancel"}),m.jsx(De,{variant:"contained",onClick:v,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx(pe,{variant:"body2",sx:{color:d.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx(B,{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(B,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx(B,{role:"list","aria-label":"Dimensions",children:c.map((h,x)=>{const y=h.to.length>0;return m.jsxs(B,{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(om,{size:"small",checked:y,onChange:k=>w(x,k.target.checked),slotProps:{input:{"aria-label":`${h.name} is clickable`}}}),m.jsxs(B,{sx:{minWidth:0},children:[m.jsx(B,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:Qm(h.name)}),m.jsxs(B,{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(B,{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,E=>{const $=k.target.value,T=Array.isArray($)?$:String($).split(",").filter(Boolean);T.length===0&&(E.lastTo=E.to),E.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(B,{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,E=>{E.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(pe,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},h.name)})})})}function Qm(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const Zm=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"})),Jm=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"})),eg=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"})),tg=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"})),ng=mt(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),rg=mt(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function ig(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of oe(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 og(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const ag=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function lg(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=Sd(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 cg=[{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 Eo=e=>oe(e)&&!cr(e)&&e.declaration.kind!=="opaque";function dg(e,t){return e.tiles.map(n=>{const r=(oe(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 ug(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!Eo(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 hg(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 fg(e,t){for(const r of e.tiles){if(!oe(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 To=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function pg({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([]),[E,$]=S.useState(!1),[T,j]=S.useState(!1),M=D=>t.sources.find(L=>L.name===D.source)?.base??D.source;S.useEffect(()=>{if(e)if(j(n!==void 0),n){l({kind:"existing",name:n.name}),p(n.label??"");const D=dg(t,n);k(D);const L=D.filter(V=>V.include),U=new Set(L.map(V=>V.field));x(U.size===1?L[0].field:n.field??""),$(U.size>1)}else l({kind:"new"}),p(""),v("select"),x(""),w(new Date().toISOString().slice(0,10)),k(t.tiles.map(D=>({include:Eo(D),field:""}))),$(!1)},[e,n,t]);const I=S.useMemo(()=>[...(t.localGivens??[]).map(D=>D.name),...r.map(D=>D.name),...i],[t,r,i]),W=S.useMemo(()=>h.trim()?lg(h.trim(),I):"",[h,I]),A=c.kind==="existing"?n??r.find(D=>D.name===c.name):W?{name:W,type:Or({name:W,label:u,kind:g,field:h}).type}:void 0,z=A?.type!==void 0&&!A.type.startsWith("filter<"),_=y.find(D=>D.include)?.op??cs(A?.type),q=(D,L)=>{j(!0),k(U=>U.map((V,we)=>we===D?{...V,...L}:V))},P=D=>{j(!0),k(L=>L.map(U=>({...U,op:D})))},F=D=>{const L=cs(D);k(U=>U.map(({op:V,...we})=>L?{...we,op:L}:we))},C=D=>{j(!0),l({kind:"existing",name:D.name}),x(D.field??""),F(D.type)},O=D=>{j(!0),v(D),F(Or({name:"X",label:u,kind:D,field:h}).type)},N=t.tiles.map(Eo),H=N.filter(Boolean).length,K=y.filter((D,L)=>D.include&&N[L]).length,Y=t.tiles.filter((D,L)=>(y[L]?.include??!1)&&N[L]&&oe(D)),te=Y.length>0?Y:t.tiles.filter((D,L)=>N[L]&&oe(D)),xe=S.useMemo(()=>{const D=new Map;let L=!1;for(const U of te){const V=s?.(U);if(V){L=!0;for(const we of V)D.has(we.name)||D.set(we.name,we)}}return L?[...D.values()]:void 0},[y,t.tiles,s]),me=(()=>{const D=h.trim();for(const L of Y){const U=s?.(L);if(!U||U.some(V=>V.name===D))return M(L)}return Y[0]?M(Y[0]):t.sources[0]?.base})(),ne=D=>{j(!0),k(L=>L.map((U,V)=>({...U,include:D&&N[V]})))},Ce=S.useMemo(()=>E?y:y.map(D=>({...D,field:h})),[E,y,h]),J=D=>{for(const L of te){const U=s?.(L)?.find(V=>V.name===D.trim());if(U?.type)return U.type}},Ve=D=>Xr(A?.type,D.type),Ae=(D,L)=>{if(D.trim()==="")return"Pick the field this filter compares.";const U=L?s?.(L):void 0;if(!U)return;const V=U.find(we=>we.name===D.trim());if(!V)return`Not a field of ${L?M(L):"the tiles' source"}.`;if(V.type&&!Xr(A?.type,V.type))return`${D.trim()} is ${Co(V.type)}; this filter compares ${Co(A?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},G=D=>{if(j(!0),x(D),f||c.kind!=="new")return;const L=J(D),U=Or({name:"X",label:u,kind:g,field:D}).type;L&&!Xr(U,L)&&O(og(L))},ye=D=>{const L=t.tiles[D];return L&&oe(L)?L:void 0},be=Ce.map((D,L)=>D.include&&N[L]?Ae(D.field,ye(L)):void 0),re=be.every(D=>D===void 0),Pe=T?be:be.map(()=>{}),Ke=T&&!E&&K>0?Y.map(D=>Ae(h,D)).find(Boolean):void 0,Re=A!==void 0&&re&&(c.kind==="existing"||h.trim()!==""&&W!==""),Qe=()=>{if(!(!A||!Re))if(c.kind==="new")o(A.name,Ce,Or({name:A.name,label:u.trim()||To(A.name),kind:g,field:h.trim(),...me?{source:me}:{},...b?{dateDefault:b}:{}}));else if(n?.origin==="dashboard"&&n.local){const D=u.trim(),L=D!==(n.local.label??"");o(A.name,Ce,L?{...n.local,...D?{label:D}:{}}:void 0)}else o(A.name,Ce)},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:E,setPerTile:$,newName:W,target:A,valueTyped:z,commonOp:_,setRow:q,setCommonOp:P,pickExisting:C,pickKind:O,bindable:N,bindableCount:H,included:K,commonFields:xe,setAll:ne,accepts:Ve,pickField:G,rowProblems:Pe,commonProblem:Ke,canApply:Re,apply:Qe}}function Vl({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(Tm,{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(Gl,{type:g.get(b)}),m.jsx(pe,{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(B,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Gl,{type:g.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":s}}),sx:u})}const mg=e=>e&&oe(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&&oe(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 gg({open:e,document:t,control:n,available:r,takenNames:i,fieldsFor:s,onClose:o,onApply:a,onRemove:d}){const{theme:f}=_e(),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:E,setRows:$,perTile:T,setPerTile:j,newName:M,target:I,valueTyped:W,commonOp:A,setRow:z,setCommonOp:_,pickExisting:q,pickKind:P,bindable:F,bindableCount:C,included:O,commonFields:N,setAll:H,accepts:K,pickField:Y,rowProblems:te,commonProblem:xe,canApply:me,apply:ne}=pg({open:e,document:t,control:n,available:r,...i?{takenNames:i}:{},fieldsFor:s,onApply:a}),Ce=S.useRef(null),J=cn(f.cardBorder),Ve=Es(f.cardBorder,f.tileTitle),[Ae,G]=S.useState(!1),[ye,be]=S.useState(!1);S.useEffect(()=>{e?be(!0):G(!1)},[e]),S.useEffect(()=>{ye&&(be(!1),G(l&&O<C))},[ye]),S.useEffect(()=>{T&&G(!0)},[T]);const re=N?.find(D=>D.name===k.trim())?.type,Pe=D=>{if(!re)return;const L=Or({name:"X",label:b,kind:D,field:k}).type;return Xr(L,re)?void 0:`${k.trim()} is ${Co(re)}, which this control cannot filter.`},Ke=b.trim()||(M?To(M):"Filter"),Re=h==="number"?"Any":h==="date"?x?new Date(`${x}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Qe={...as(J,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...as(J,c)["& .MuiToggleButton-root"],textTransform:"none"}},Ze=(D,L,U)=>m.jsx(Zt,{select:!0,size:"small",label:"Compares",value:D??">=",onChange:V=>L(V.target.value),inputProps:{"aria-label":U},sx:{width:130},children:ag.filter(V=>V.op!=="~").map(V=>m.jsx(Xe,{value:V.op,children:V.label},V.op))});return m.jsx(Ca,{className:`${rt.dialog} ${rt.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:Ce},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs(B,{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(De,{color:"error",startIcon:m.jsx(rm,{}),onClick:()=>d(u.name),sx:D=>({mr:"auto",color:nm(D)}),children:"Remove filter"}),m.jsx(De,{onClick:o,children:"Cancel"}),m.jsx(Ot,{title:me||I===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx(De,{variant:"contained",onClick:ne,disabled:!me,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs(ft,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs($d,{exclusive:!0,size:"small",value:g.kind,onChange:(D,L)=>{L==="new"?v({kind:"new"}):L==="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:D=>{const L=r.find(U=>U.name===D.target.value);L&&q(L)},children:r.map(D=>m.jsxs(Xe,{value:D.name,children:[D.label??D.name,m.jsxs(pe,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",D.name]})]},D.name))}):null,m.jsxs(B,{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(Vl,{value:k,onChange:Y,fields:N,accepts:K,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:Ce,error:xe!==void 0,helperText:xe??(!l&&M?`Declared as $${M}`:void 0)}),!p&&m.jsx(Zt,{size:"small",label:"Label",placeholder:M?To(M):"",value:b,onChange:D=>w(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),W&&!T&&Ze(A,_,"Comparison"),!l&&g.kind==="new"&&m.jsxs(B,{children:[m.jsx(Kl,{children:"Control"}),m.jsx(B,{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:cg.map(D=>{const L=D.kind===h,U=Pe(D.kind);return m.jsx(Ot,{title:U??D.hint,describeChild:!0,children:m.jsxs(cd,{role:"radio","aria-checked":L,"aria-label":D.label,"aria-disabled":U!==void 0,onClick:()=>{U===void 0&&P(D.kind)},sx:V=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${L?f.accent:J}`,boxShadow:L?`0 0 0 1px ${f.accent}`:"none",bgcolor:L?`color-mix(in srgb, ${f.accent} 6%, ${V.palette.background.paper})`:V.palette.background.paper,color:L?f.accent:V.palette.text.secondary,opacity:U?.45:1,cursor:U?"default":"pointer",transition:`border-color ${nt}, background-color ${nt}`,"&:hover":U||L?{}:{borderColor:Ve}}),children:[m.jsx(xg,{kind:D.kind}),m.jsx(B,{component:"span",sx:{...c.type.caption,fontWeight:L?600:500,color:L?f.accent:"text.primary",textAlign:"center"},children:vg[D.kind]})]})},D.kind)})}),h==="date"&&m.jsx(Zt,{size:"small",type:"date",label:"Starts at",value:x,onChange:D=>y(D.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs(B,{sx:{border:`1px solid ${J}`,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(rg,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs(pe,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx(B,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:O===C&&C>0?`Applies to all ${O} tile${O===1?"":"s"}`:`Applies to ${O} of ${C} tile${C===1?"":"s"}`}),!T&&k.trim()!==""&&O>0&&m.jsxs(B,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx(B,{component:"span",sx:{...c.type.code},children:k.trim()})]})]}),!T&&m.jsx(De,{size:"small","aria-expanded":Ae,onClick:()=>G(D=>!D),children:Ae?"Done choosing":"Choose tiles"})]}),m.jsx(tm,{in:Ae,unmountOnExit:!0,children:m.jsxs(B,{sx:{borderTop:`1px solid ${J}`,px:.5,pb:1},children:[m.jsxs(ft,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx(yo,{size:"small",checked:C>0&&O===C,indeterminate:O>0&&O<C,disabled:C===0,onChange:D=>H(D.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx(pe,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx(De,{size:"small",onClick:()=>{T||$(D=>D.map(L=>({...L,field:k}))),j(D=>!D)},children:T?"Same field for all":"Adjust per tile"})]}),m.jsx(ft,{sx:{gap:T?1:0},children:t.tiles.map((D,L)=>{if(!oe(D))return null;const U=E[L],V=D.label??D.name,we=T?te[L]:void 0;return m.jsxs(ft,{direction:"row",sx:{gap:1,alignItems:T?"flex-start":"center",opacity:F[L]?1:.6},children:[m.jsx(yo,{size:"small",disabled:!F[L],checked:(U?.include??!1)&&F[L],inputProps:{"aria-label":`Filter ${V}`},onChange:je=>z(L,{include:je.target.checked})}),m.jsx(pe,{variant:"body2",sx:{flex:1,minWidth:0,pt:T?1:0},noWrap:!0,children:V}),F[L]?T&&m.jsxs(m.Fragment,{children:[W&&Ze(U?.op,je=>z(L,{op:je}),`Comparison for ${V}`),m.jsx(Vl,{value:U?.field??"",onChange:je=>z(L,{field:je}),fields:s?.(D),accepts:K,label:"Field",ariaLabel:`Field for ${V}`,disabled:!U?.include,error:we!==void 0,helperText:we,sx:{width:220,pr:1}})]}):m.jsx(pe,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:mg(t.tiles[L]).reason})]},ue(D))})})]})})]}),O===0&&m.jsx(pe,{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(B,{children:[m.jsx(Kl,{children:"Preview"}),m.jsx(B,{sx:D=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:D.palette.action.hover}),children:m.jsxs(B,{"aria-hidden":!0,sx:D=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${J}`,bgcolor:D.palette.background.paper,...c.type.control}),children:[m.jsx(B,{component:"span",sx:{color:"text.secondary"},children:Ke}),m.jsx(B,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:Re}),m.jsx(wa,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function Kl({children:e}){const t=_e().theme.ui;return m.jsx(pe,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const vg={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function xg({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(Zm,{sx:t});case"multiselect":return m.jsx(Jm,{sx:t});case"text":return m.jsx(ng,{sx:t});case"number":return m.jsx(tg,{sx:t});case"date":return m.jsx(eg,{sx:t})}}function Gl({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=_e().theme.ui;return n?m.jsx(B,{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 Yl=mt(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Id(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 bg=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.`,yg=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),wg="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",kg="Declared on its source, so its chart is set in the model.",Sg="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}=_e(),c=f.ui,{draft:l,apply:u,patch:p,close:g}=Id(t,e!==null,r,n),[v,b]=S.useState(void 0),w=l!==void 0&&oe(l)?l:void 0,h=w!==void 0&&!cr(w),x=C=>u(O=>{oe(O)&&C(O)}),y=S.useRef(void 0),k=S.useRef(null),E=e!==null;S.useEffect(()=>{E?y.current=t&&oe(t)?t.chart:void 0:b(void 0)},[E]);const $=w?.chart??"default",T=Pd(a,$,d),j=w?w.declaration.kind==="query"?Sg:h?w.chart==="custom"?bg(w.chartLines):void 0:kg:void 0,M=C=>x(O=>{const N=y.current;C===(N??"default")?(N===void 0?delete O.chart:O.chart=N,delete O.chartCarried):(O.chart=C,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,W=$==="default"?a?.chart:$,A=W!==void 0&&yg.has(W)?wg:void 0,z=C=>O=>b({kind:C,anchor:O.currentTarget}),_=j??(W===void 0||!jg.has(W)?"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(xd).filter(C=>C!==void 0))).slice(0,8),P=C=>x(O=>{C===void 0?delete O.color:O.color=C.toLowerCase()}),F=(C,O,N)=>m.jsxs(m.Fragment,{children:[m.jsx(Bt,{primary:C,...N?{secondary:N}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),O&&m.jsx(pe,{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:z("chart"),onKeyDown:C=>{C.key==="ArrowRight"&&j===void 0&&b({kind:"chart",anchor:C.currentTarget})},children:[F("Chart",j?void 0:T.find(C=>C.value===$)?.label,j),m.jsx(Yl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),w&&j===void 0&&m.jsxs(Xe,{"aria-haspopup":"menu","aria-expanded":v?.kind==="color",disabled:_!==void 0,onClick:z("color"),onKeyDown:C=>{C.key==="ArrowRight"&&_===void 0&&b({kind:"color",anchor:C.currentTarget})},children:[F("Color",_?void 0:w.color??"Theme",_),!_&&m.jsx(Gs,{color:w.color??f.series[0],trailing:!0}),m.jsx(Yl,{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??A)}),w&&s&&m.jsx(Xe,{disabled:o!==void 0,onClick:()=>{g(),s()},children:F("Duplicate",void 0,o)}),w?.declaration.kind==="opaque"&&m.jsxs(pe,{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(B,{"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:C=>{C.key==="ArrowLeft"&&(C.preventDefault(),b(void 0))}},children:T.filter(C=>C.value!=="custom").map(C=>m.jsxs(Xe,{role:"menuitemradio","aria-checked":C.value===$,disabled:C.disabled===!0,onClick:()=>{M(C.value),b(void 0)},children:[m.jsx(Bt,{primary:C.label,...C.reason??C.hint?{secondary:C.reason??C.hint}:{}}),C.value===$&&m.jsx(bd,{sx:{minWidth:0,ml:2},children:m.jsx(Ts,{fontSize:"small",sx:{color:f.accent}})})]},C.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:C=>{C.key==="ArrowLeft"&&(C.preventDefault(),b(void 0))}},children:[m.jsxs(Xe,{role:"menuitemradio","aria-checked":w?.color===void 0,onClick:()=>{P(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(Xl,{color:f.accent})]}),q.map(C=>m.jsxs(Xe,{role:"menuitemradio","aria-checked":w?.color===C.toLowerCase(),onClick:()=>{P(C),b(void 0)},children:[m.jsx(Gs,{color:C}),m.jsx(Bt,{primary:C.toLowerCase()}),w?.color===C.toLowerCase()&&m.jsx(Xl,{color:f.accent})]},C)),m.jsx(nr,{}),m.jsxs(Xe,{component:"label","aria-checked":w?.color!==void 0&&!q.some(C=>C.toLowerCase()===w.color),role:"menuitemradio",onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),k.current?.click())},children:[m.jsx("input",{ref:k,type:"color","aria-label":"Other color",value:w?.color??Mg(f.series[0]),onChange:C=>{const O=C.target.value;im(O)&&p(N=>{oe(N)&&(N.color=O.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx(Bt,{primary:"Other color…"})]})]})]})}const jg=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Mg=e=>(e&&xd(e))??"#000000";function Gs({color:e,trailing:t=!1}){return m.jsx(B,{"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 Xl({color:e}){return m.jsx(bd,{sx:{minWidth:0,ml:2},children:m.jsx(Ts,{fontSize:"small",sx:{color:e}})})}const Ds=e=>e.label??sm(vt(e));function Cg({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&&oe(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,E=h.declaration.kind==="reference"?h.declaration.from:h.name;return t.sources.find($=>$.name===k)?.views.find($=>$.name===E)})();return m.jsxs(m.Fragment,{children:[m.jsx(gg,{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 E=Fm(y);e.update($=>{$.tiles[k]=E,E!==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?Ds(h):void 0),a(h?.source)}}:{}}),m.jsx(Xm,{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 E=[...(k.drills??[]).filter($=>$.source!==o),...y];E.length===0?delete k.drills:k.drills=E})}),m.jsx(gp,{...d}),m.jsx(Km,{open:s.addingTile,document:e.document,catalog:t,columns:n,onClose:s.closeAdd,onAdd:s.addTile,onAddText:s.addText,...f?{renderPreview:f}:{}})]})}var Eg=Symbol.for("preact-signals");function As(){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)&&Wd(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();Oo=++Tg,_t++;try{return e()}finally{As()}}var Qr,ke=void 0;function ie(e){var t=ke,n=Qr;ke=void 0,Qr=void 0;try{return e()}finally{ke=t,Qr=n}}var Zr=void 0,_t=0,ds=0,Tg=0,Oo=0,us=void 0,hs=0;function Nd(e){if(ke!==void 0){var t=e.n;if(t===void 0||t.t!==ke)return t={i:0,S:e,p:ke.s,n:void 0,t:ke,e:void 0,x:void 0,r:t},ke.s!==void 0&&(ke.s.n=t),ke.s=t,e.n=t,32&ke.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=ke.s,t.n=void 0,ke.s.n=t,ke.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=Eg;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:ie(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&&ie(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;ie(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 ie(function(){return e.value})};Object.defineProperty(dt.prototype,"value",{get:function(){var e=Nd(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!==Oo&&(n.l=Oo,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{As()}}}});function dr(e,t){return new dt(e,t)}function Wd(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 Ld(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 zd(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 Cn(e,t){dt.call(this,void 0,t),this.x=e,this.s=void 0,this.g=hs-1,this.f=4}Cn.prototype=new dt;Cn.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&&!Wd(this))return this.f&=-2,!0;var e=ke;try{Ld(this),ke=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 ke=e,zd(this),this.f&=-2,!0};Cn.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)};Cn.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)}};Cn.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(Cn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Nd(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Ql(e,t){return new Cn(e,t)}function Fd(e){var t=e.m;if(e.m=void 0,typeof t=="function"){_t++;var n=ke;ke=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Oa(e),r}finally{ke=n,As()}}}function Oa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Fd(e)}function Og(e){if(ke!==this)throw new Error("Out-of-order effect");zd(this),ke=e,this.f&=-2,8&this.f&&Oa(this),As()}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,Fd(this),Ld(this),_t++;var e=ke;return ke=this,Og.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||Oa(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 Dg=Object.create,Da=Object.defineProperty,Ag=Object.defineProperties,Pg=Object.getOwnPropertyDescriptor,Rg=Object.getOwnPropertyDescriptors,Zl=Object.getOwnPropertySymbols,Ig=Object.prototype.hasOwnProperty,Ng=Object.prototype.propertyIsEnumerable,Wg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),hr=e=>{throw TypeError(e)},Do=(e,t,n)=>t in e?Da(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lg=(e,t)=>{for(var n in t||(t={}))Ig.call(t,n)&&Do(e,n,t[n]);if(Zl)for(var n of Zl(t))Ng.call(t,n)&&Do(e,n,t[n]);return e},zg=(e,t)=>Ag(e,Rg(t)),Jl=(e,t)=>Da(e,"name",{value:t,configurable:!0}),Fg=e=>{var t;return[,,,Dg((t=void 0)!=null?t:null)]},Bd=["class","method","getter","setter","accessor","field","value","get","set"],Dr=e=>e!==void 0&&typeof e!="function"?hr("Function expected"):e,Bg=(e,t,n,r,i)=>({kind:Bd[e],name:t,metadata:r,addInitializer:s=>n._?hr("Already initialized"):i.push(Dr(s||null))}),_d=(e,t)=>Do(t,Wg("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=Bd[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)&&Pg(l<4?i:{get[n](){return yt(this,s)},set[n](y){return Xt(this,s,y)}},n));l?p&&l<4&&Jl(s,(l>2?"set ":l>1?"get ":"")+n):Jl(i,n);for(var x=r.length-1;x>=0;x--)f=Bg(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>_g(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?yt:qg)(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?hr("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||_d(e,i),h&&Da(i,n,h),p?l^4?s:h:i},Aa=(e,t,n)=>t.has(e)||hr("Cannot "+n),_g=(e,t)=>Object(t)!==t?hr('Cannot use the "in" operator on this value'):e.has(t),yt=(e,t,n)=>(Aa(e,t,"read from private field"),n?n.call(e):t.get(e)),Ar=(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)=>(Aa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),qg=(e,t,n)=>(Aa(e,t,"access private method"),n);function Ao(e,t){if(t){let n;return Ql(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Ql(e)}function Et(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)=>!Et(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=>!Et(e[i],t[i]))}return!1}function se({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 We(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Ao(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,zg(Lg({},i),{enumerable:e}))})}}function xi(...e){const t=e.map(n=>$t(n));return()=>t.forEach(n=>n())}var qd,Hd,Ud,Vd,Kd,Gd,ot,Pa,Xs,Po,Ro,tt,Ra,Qs,Yd,Io,Ia,Zs,No,Wo;Gd=[se],Kd=[se],Vd=[se],Ud=[Ys()],Hd=[Ys()],qd=[Ys()];var En=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,un(ot,5,this),Ar(this,tt),Ar(this,Pa,un(ot,8,this)),un(ot,11,this),Ar(this,Ra,un(ot,12,this)),un(ot,15,this),Ar(this,Ia,un(ot,16,this)),un(ot,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return yt(this,tt,No)}get initial(){return yt(this,tt,Po)}get previous(){return yt(this,tt,Yd)}set current(e){const t=ie(()=>yt(this,tt,No));e&&t&&this.equals(t,e)||Oe(()=>{yt(this,tt,Po)||Xt(this,tt,e,Ro),Xt(this,tt,t,Io),Xt(this,tt,e,Wo)})}reset(e=this.defaultValue){Oe(()=>{Xt(this,tt,void 0,Io),Xt(this,tt,e,Ro),Xt(this,tt,e,Wo)})}};ot=Fg();Pa=new WeakMap;tt=new WeakSet;Ra=new WeakMap;Ia=new WeakMap;Xs=fr(ot,20,"#initial",Gd,tt,Pa),Po=Xs.get,Ro=Xs.set;Qs=fr(ot,20,"#previous",Kd,tt,Ra),Yd=Qs.get,Io=Qs.set;Zs=fr(ot,20,"#current",Vd,tt,Ia),No=Zs.get,Wo=Zs.set;fr(ot,2,"current",Ud,En);fr(ot,2,"initial",Hd,En);fr(ot,2,"previous",qd,En);_d(ot,En);function Js(e){return ie(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var hn,Hg=class{constructor(){Ar(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 Ug=Object.create,Xd=Object.defineProperty,Vg=Object.getOwnPropertyDescriptor,ec=Object.getOwnPropertySymbols,Kg=Object.prototype.hasOwnProperty,Gg=Object.prototype.propertyIsEnumerable,Qd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ps=e=>{throw TypeError(e)},tc=Math.pow,Lo=(e,t,n)=>t in e?Xd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yg=(e,t)=>{for(var n in t||(t={}))Kg.call(t,n)&&Lo(e,n,t[n]);if(ec)for(var n of ec(t))Gg.call(t,n)&&Lo(e,n,t[n]);return e},Xg=e=>{var t;return[,,,Ug((t=e?.[Qd("metadata")])!=null?t:null)]},Zd=["class","method","getter","setter","accessor","field","value","get","set"],Jd=e=>e!==void 0&&typeof e!="function"?Ps("Function expected"):e,Qg=(e,t,n,r,i)=>({kind:Zd[e],name:t,metadata:r,addInitializer:s=>n._?Ps("Already initialized"):i.push(Jd(s||null))}),Zg=(e,t)=>Lo(t,Qd("metadata"),e[3]),Jg=(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},eu=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=Zd[c+5],v=e[p]||(e[p]=[]),b=(i=i.prototype,Vg(i,n)),w=r.length-1;w>=0;w--)d=Qg(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,Jd(o)&&(b[g]=o);return b&&Xd(i,n,b),i},tu=(e,t,n)=>t.has(e)||Ps("Cannot "+n),ev=(e,t,n)=>(tu(e,t,"read from private field"),t.get(e)),tv=(e,t,n)=>t.has(e)?Ps("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),nv=(e,t,n,r)=>(tu(e,t,"write to private field"),t.set(e,n),n),wt=class zo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new zo(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 zo(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=Yg({},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?rv(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 rv(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 nu,ru,Fo,_i,bi,Rs=class extends(Fo=En,ru=[We],nu=[We],Fo){constructor(e){const t=wt.from(e);super(t,(n,r)=>wt.equals(n,r)),Jg(bi,5,this),tv(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-ev(this,_i),o=a=>Math.round(a/s*100);Oe(()=>{nv(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=Xg(Fo);_i=new WeakMap;eu(bi,2,"delta",ru,Rs);eu(bi,2,"direction",nu,Rs);Zg(bi,Rs);function Bo({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(tc(r,2)+tc(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 iu=(e=>(e.Horizontal="x",e.Vertical="y",e))(iu||{}),su=Object.values(iu),iv=Object.create,Na=Object.defineProperty,sv=Object.defineProperties,ov=Object.getOwnPropertyDescriptor,av=Object.getOwnPropertyDescriptors,fs=Object.getOwnPropertySymbols,ou=Object.prototype.hasOwnProperty,au=Object.prototype.propertyIsEnumerable,lu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),pr=e=>{throw TypeError(e)},_o=(e,t,n)=>t in e?Na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Wa=(e,t)=>{for(var n in t||(t={}))ou.call(t,n)&&_o(e,n,t[n]);if(fs)for(var n of fs(t))au.call(t,n)&&_o(e,n,t[n]);return e},La=(e,t)=>sv(e,av(t)),nc=(e,t)=>Na(e,"name",{value:t,configurable:!0}),cu=(e,t)=>{var n={};for(var r in e)ou.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&&au.call(e,r)&&(n[r]=e[r]);return n},mr=e=>{var t;return[,,,iv((t=e?.[lu("metadata")])!=null?t:null)]},du=["class","method","getter","setter","accessor","field","value","get","set"],Pr=e=>e!==void 0&&typeof e!="function"?pr("Function expected"):e,lv=(e,t,n,r,i)=>({kind:du[e],name:t,metadata:r,addInitializer:s=>n._?pr("Already initialized"):i.push(Pr(s||null))}),Tn=(e,t)=>_o(t,lu("metadata"),e[3]),Z=(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},ae=(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=du[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)&&ov(l<4?i:{get[n](){return Ne(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=lv(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>cv(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?Ne:uu)(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?Pr(a)&&(l>4?b.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?pr("Object expected"):(Pr(o=a.get)&&(h.get=o),Pr(o=a.set)&&(h.set=o),Pr(o=a.init)&&b.unshift(o));return l||Tn(e,i),h&&Na(i,n,h),p?l^4?s:h:i},za=(e,t,n)=>t.has(e)||pr("Cannot "+n),cv=(e,t)=>Object(t)!==t?pr('Cannot use the "in" operator on this value'):e.has(t),Ne=(e,t,n)=>(za(e,t,"read from private field"),n?n.call(e):t.get(e)),fe=(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)=>(za(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),uu=(e,t,n)=>(za(e,t,"access private method"),n);function hu(e,t){return{plugin:e,options:t}}function yi(e){return t=>hu(e,t)}function ai(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var fu,li,Fa,qi;fu=[se];var it=class{constructor(e,t){this.manager=e,this.options=t,fe(this,Fa,Z(li,8,this,!1)),Z(li,11,this),fe(this,qi,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ie(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=$t(e.bind(this));return Ne(this,qi).add(t),t}destroy(){Ne(this,qi).forEach(e=>e())}static configure(e){return hu(this,e)}};li=mr(null);Fa=new WeakMap;qi=new WeakMap;ae(li,4,"disabled",fu,it,Fa);Tn(li,it);var wi=class extends it{},Hi,eo=class{constructor(e){this.manager=e,this.instances=new Map,fe(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 Ne(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 dv(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,uv=class extends it{constructor(e){super(e),fe(this,Fn),fe(this,Bn),this.computeCollisions=this.computeCollisions.bind(this),xt(this,Bn,dr(Oi)),this.destroy=xi(()=>{const t=this.computeCollisions(),n=ie(()=>this.manager.dragOperation.position.current);if(t!==Oi){const r=Ne(this,Fn);if(xt(this,Fn,n),r&&n.x==r.x&&n.y==r.y)return}else xt(this,Fn,void 0);Ne(this,Bn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ie(()=>{e?Ne(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=ie(()=>c({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return d.length===0?Oi:(a.sort(dv),a)}get collisions(){return Ne(this,Bn).value}};Fn=new WeakMap;Bn=new WeakMap;var pu,mu,gu,Ba,vu,Tt,_a,Gn,qa,Ha;gu=[se],mu=[se],pu=[se];var Ut=class pn{constructor(t,n){fe(this,_a,Z(Tt,8,this)),Z(Tt,11,this),fe(this,Gn),fe(this,qa,Z(Tt,12,this)),Z(Tt,15,this),fe(this,Ha,Z(Tt,16,this)),Z(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=Ne(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:Ne(this,Gn).peek();t!==i&&(pn.pendingIdChanges||(pn.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return uu(s=pn,Ba,vu).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);Ba=new WeakSet;vu=function(){const e=Ut.pendingIdChanges;Ut.pendingIdChanges=null,e&&Oe(()=>{for(const[t,n]of e)Ne(t,Gn).value=n})};_a=new WeakMap;Gn=new WeakMap;qa=new WeakMap;Ha=new WeakMap;ae(Tt,4,"manager",gu,Ut,_a);ae(Tt,4,"data",mu,Ut,qa);ae(Tt,4,"disabled",pu,Ut,Ha);fe(Ut,Ba);Tn(Tt,Ut);Ut.pendingIdChanges=null;var Is=Ut,rc=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}},xu,bu,yu,wu,ku,Su,qo,at,Ua,Va,Ka,Wt=class extends(qo=Is,Su=[se],ku=[se],wu=[se],yu=[We],bu=[We],xu=[We],qo){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,d=cu(n,["modifiers","type","sensors","plugins","effects"]);super(La(Wa({},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),Z(at,5,this),fe(this,Ua,Z(at,8,this)),Z(at,11,this),fe(this,Va,Z(at,12,this)),Z(at,15,this),fe(this,Ka,Z(at,16,this,this.isDragSource?"dragging":"idle")),Z(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(qo);Ua=new WeakMap;Va=new WeakMap;Ka=new WeakMap;ae(at,4,"type",Su,Wt,Ua);ae(at,4,"modifiers",ku,Wt,Va);ae(at,4,"status",wu,Wt,Ka);ae(at,2,"isDropping",yu,Wt);ae(at,2,"isDragging",bu,Wt);ae(at,2,"isDragSource",xu,Wt);Tn(at,Wt);var $u,ju,Mu,Cu,Eu,Tu,Ho,He,Ga,Ya,Xa,Qa,Za,Lt=class extends(Ho=Is,Tu=[se],Eu=[se],Cu=[se],Mu=[se],ju=[se],$u=[We],Ho){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=cu(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),Z(He,5,this),fe(this,Ga,Z(He,8,this)),Z(He,11,this),fe(this,Ya,Z(He,12,this)),Z(He,15,this),fe(this,Xa,Z(He,16,this)),Z(He,19,this),fe(this,Qa,Z(He,20,this)),Z(He,23,this),fe(this,Za,Z(He,24,this)),Z(He,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}};He=mr(Ho);Ga=new WeakMap;Ya=new WeakMap;Xa=new WeakMap;Qa=new WeakMap;Za=new WeakMap;ae(He,4,"accept",Tu,Lt,Ga);ae(He,4,"type",Eu,Lt,Ya);ae(He,4,"collisionDetector",Cu,Lt,Xa);ae(He,4,"collisionPriority",Mu,Lt,Qa);ae(He,4,"shape",ju,Lt,Za);ae(He,2,"isDropTarget",$u,Lt);Tn(He,Lt);var hv=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)}},fv=class extends hv{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 La(Wa({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var pv=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;ie(()=>{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||{}),Ou,Du,Au,Pu,Ru,Iu,Nu,St,Ja;Nu=[se],Iu=[We],Ru=[We],Pu=[We],Au=[We],Du=[We],Ou=[We];var Kt=class{constructor(){Z(St,5,this),fe(this,Ja,Z(St,8,this,"idle")),Z(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);Ja=new WeakMap;ae(St,4,"value",Nu,Kt,Ja);ae(St,2,"current",Iu,Kt);ae(St,2,"idle",Ru,Kt);ae(St,2,"initializing",Pu,Kt);ae(St,2,"initialized",Au,Kt);ae(St,2,"dragging",Du,Kt);ae(St,2,"dropped",Ou,Kt);Tn(St,Kt);var mv=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 ie(()=>{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 ie(()=>{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 ie(()=>{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 ie(()=>{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=ie(()=>{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}},gv=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,Wu=class{constructor(e){this.options=e,fe(this,Vi)}set controller(e){xt(this,Vi,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ne(this,Vi))==null||t.activate(e)}};Vi=new WeakMap;var ic=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},vv=class{constructor(e){this.draggables=new rc,this.droppables=new rc,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 Lt)return this.droppables.register(e.id,e);if(e.prototype instanceof ic)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 Lt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof ic)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()}},Lu,zu,Fu,Bu,_u,qu,Hu,Uu,Vu,Rr,Ki,_n,Te,el,tl,nl,rl,il,Ir;Vu=[We],Uu=[se],Hu=[se],qu=[se],_u=[se],Bu=[se],Fu=[We],zu=[We],Lu=[We];var Pt=class{constructor(e){Z(Te,5,this),fe(this,Rr),fe(this,Ki),fe(this,_n,new En(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Kt,fe(this,el,Z(Te,8,this,!1)),Z(Te,11,this),fe(this,tl,Z(Te,12,this,null)),Z(Te,15,this),fe(this,nl,Z(Te,16,this,null)),Z(Te,19,this),fe(this,rl,Z(Te,20,this,null)),Z(Te,23,this),fe(this,il,Z(Te,24,this,[])),Z(Te,27,this),this.position=new Rs({x:0,y:0}),fe(this,Ir,{x:0,y:0}),xt(this,Rr,e)}get shape(){const{current:e,initial:t,previous:n}=Ne(this,_n);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ne(this,_n).current=e:Ne(this,_n).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ne(this,Rr).registry.draggables.get(t);return n&&xt(this,Ki,n),(e=n??Ne(this,Ki))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ne(this,Rr).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(La(Wa({},this.snapshot()),{transform:n}));return xt(this,Ir,n),n}snapshot(){return ie(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ne(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,Ne(this,_n).reset(),this.position.reset({x:0,y:0}),xt(this,Ir,{x:0,y:0}),this.modifiers=[]})}};Te=mr(null);Rr=new WeakMap;Ki=new WeakMap;_n=new WeakMap;el=new WeakMap;tl=new WeakMap;nl=new WeakMap;rl=new WeakMap;il=new WeakMap;Ir=new WeakMap;ae(Te,2,"shape",Vu,Pt);ae(Te,4,"canceled",Uu,Pt,el);ae(Te,4,"activatorEvent",Hu,Pt,tl);ae(Te,4,"sourceIdentifier",qu,Pt,nl);ae(Te,4,"targetIdentifier",_u,Pt,rl);ae(Te,4,"modifiers",Bu,Pt,il);ae(Te,2,"source",Fu,Pt);ae(Te,2,"target",zu,Pt);ae(Te,2,"transform",Lu,Pt);Tn(Te,Pt);var xv={get rendering(){return Promise.resolve()}};function At(e,t){return typeof e=="function"?e(t):e??t}var bv=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=At(n.plugins,[]),i=At(n.sensors,[]),s=At(n.modifiers,[]),o=(t=n.renderer)!=null?t:xv,a=new fv(this),d=new vv(this);this.registry=d,this.monitor=a,this.renderer=o,this.actions=new mv(this),this.dragOperation=new Pt(this),this.collisionObserver=new uv(this),this.plugins=[pv,...r],this.modifiers=s,this.sensors=i;const{destroy:f}=this,c=xi(()=>{var l,u,p;const g=ie(()=>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}},Ku=e=>{throw TypeError(e)},sl=(e,t,n)=>t.has(e)||Ku("Cannot "+n),Q=(e,t,n)=>(sl(e,t,"read from private field"),t.get(e)),ut=(e,t,n)=>t.has(e)?Ku("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),gt=(e,t,n,r)=>(sl(e,t,"write to private field"),t.set(e,n),n),Gu=(e,t,n)=>(sl(e,t,"access private method"),n);function Ns(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Yu(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 ol(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?ol(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 al(e){const{Document:t}=bt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function on(e){return!e||ol(e)?!1:e instanceof bt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Xu(e){return e instanceof bt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function xr(e){return e?ol(e)?e.document:ki(e)?al(e)?e:on(e)||Xu(e)?e.ownerDocument:document:document:document}function yv(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 wv(e,t){if(kv(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function kv(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(!wv(l)){const x=l.getBoundingClientRect(),y=n*(x.bottom-x.top),k=n*(x.right-x.left),E=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+E),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 Qu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Uo(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(...Uo(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(...Uo(i.document,t))}}catch{}return n}function ll(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Zu(){var e,t;const n=ll()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function cl(e){return!e||!ki(e)?!1:e instanceof bt(e).ShadowRoot}function ps(e){if(e&&ki(e)){let t=e.getRootNode();if(cl(t)||t instanceof Document)return t}return xr(e)}function dl(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Sv(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];sc(i)&&sc(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),oc(i)&&oc(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function sc(e){return"value"in e}function oc(e){return e.tagName==="CANVAS"}function Ju(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 Ju(i,{x:t-s,y:n-o})}}return r}function $v(e){return e?.tagName==="IFRAME"}var Vo=new WeakMap;function jv(e){return e.closest(`
|
|
1
|
+
import{Z as id,U as _e,aO as cn,aP as Cs,r as S,j as m,ad as ft,az as rt,K as Ot,J as $n,aQ as nr,a2 as De,aR as wa,aS as vi,aT as Xn,aU as ep,aV as sd,aW as rn,aX as tp,aY as np,aZ as mo,a_ as rp,T as pe,a1 as ht,a$ as ip,b0 as sp,b1 as op,O as ka,ak as ap,b2 as Zt,b3 as lp,b4 as Sa,b5 as cp,b6 as od,b7 as ad,b8 as dp,b9 as up,a0 as go,ba as hp,bb as fp,bc as vo,aF as ld,B as cd,bd as nt,H as B,aj as Xe,be as mt,bf as $a,X as Bt,bg as pp,bh as pt,bi as Il,bj as Gr,bk as dd,bl as mp,bm as ja,bn as gp,bo as vp,bp as xp,bq as bp,br as yp,bs as wp,bt as ud,bu as kp,bv as Sp,bw as hd,bx as fd,by as pd,bz as $p,bA as jp,bB as Mp,bC as Ep,bD as Cp,bE as Tp,bF as Op,bG as Dp,E as Ap,bH as Pp,bI as Rp,bJ as xo,bK as bo,bL as Nl,bM as Ip,bN as Np,bO as Wp,bP as Zn,bQ as Lp,bR as zp,bS as Fp,bT as Bp,bU as _p,bV as md,bW as Ma,bX as qp,bY as Hp,bZ as gd,b_ as Up,b$ as Vp,c0 as Kp,c1 as Ts,c2 as ns,c3 as Gp,c4 as Yp,c5 as rs,c6 as Xp,c7 as kn,c8 as Zp,c9 as Qp,ca as vd,cb as Jp,cc as em,ap as Ea,af as Qt,cd as tm,ce as yo,cf as nm,cg as rm,ch as xd,W as bd,ci as im,cj as sm,ck as Os,cl as om,cm as wo,cn as am,co as lm,cp as cm,cq as yd,cr as dm,F as um,cs as hm,ct as fm,cu as pm,cv as mm,cw as gm,cx as vm,cy as xm,cz as Ca,cA as bm,cB as ym,cC as wd,cD as wm,cE as km,cF as Sm,cG as Ta,cH as $m,cI as jm,cJ as Mm,cK as Pn,cL as kd,cM as Wl,cN as Ll,cO as Vs,cP as Em,S as Cm,cQ as Tm,cR as Om,cS as Dm,cT as Sd,cU as Am,cV as Pm,as as Rm}from"./index-DRkw60sj.js";import{cW as Ww,cX as Lw,cY as zw,cZ as Fw,c_ as Bw,c$ as _w,d0 as qw,d1 as Hw,d2 as Uw,d3 as Vw,d4 as Kw}from"./index-DRkw60sj.js";import{T as $d,a as ko}from"./ToggleButtonGroup-CX0_J2zR.js";var zl={};const $e=e=>e.kind==="text",oe=e=>e.kind!=="text",Mr=e=>oe(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",ue=e=>$e(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,Fl=".malloy-big-value, .malloy-table",Im=e=>e.querySelector(Fl)!==null&&![...e.querySelectorAll(".malloy-chart")].some(t=>t.closest(Fl)===null),is=(e,t)=>$e(e)?Gp:t&&Im(t)?Yp:rs,ii=e=>e.rowspan??ja[$e(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 Nm(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,jd=ns+pt;function Md(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/jd)+1),col:Math.min(Math.max(o,1),r-s+1)}}function Ed(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=Md(a.left,a.top,c,n,r),u=(a.top+a.height+pt)/jd,p=$e(s)?Math.ceil(u-.02):Math.round(u);return{...f,...l,colspan:c,rowspan:s.rowspan??Math.max(is(s),p-l.row+1)}});return Ht(i,n)}function Bl(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 Cd(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 Wm=(e,t)=>Cd(e,t).some((n,r)=>n.row!==e[r].row||n.col!==e[r].col);function Lm(e){return Kn(e).map(t=>{const{row:n,col:r,...i}=t;return i})}const zm=(e,t,n)=>e.map((r,i)=>i===t?{...r,...n}:r);function _l(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(zm(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 Td=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1);function Fm(e){return $e(e)||e.rowspan===void 0?e:Os(e.chart)&&e.chart!=="big_value"&&e.rowspan<rs?{...e,rowspan:rs}:e}const Od=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"})),Dd=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"})),Bm=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 Ad(e){const{theme:t}=_e(),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 ${So(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(B,{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(B,{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(B,{component:"span","aria-hidden":!0,children:l}),m.jsx(wa,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:g?"visible":"hidden"}})]}),h=m.jsx(B,{component:"span",role:"status","aria-live":"polite",sx:_m,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[h,m.jsx(Ot,{title:u??p,describeChild:!0,children:g?m.jsx(cd,{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(B,{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(B,{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 ${So(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(Bm,{fontSize:"small"}),"Discard edits"]})]})]})}function So(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 _m={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},$o=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Sn=$o?"⌘":"Ctrl+",ql=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 qm(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=$o?s.metaKey:s.ctrlKey,d=s.key.toLowerCase();if(s.key==="Escape"){if(ql(s.target)||Ks(s.target))return;o.escape();return}if(ql(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(!$o&&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=$a)=>({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=$a)=>({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=$a)=>({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"}}}),jo={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Hm({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}=_e(),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(De,{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(Dd,{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(Od,{fontSize:"small"})})})}),(c||o||p)&&m.jsx(nr,{orientation:"vertical",sx:os}),c,o&&g&&m.jsx(Ad,{...g}),o?m.jsx(Ot,{title:i?`Save (${Sn}S) · ${d??jo[a]}`:d??jo[a],children:m.jsx("span",{children:m.jsx(De,{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(B,{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(um,{label:"Close",icon:m.jsx(Ts,{}),onClick:p})]})}const Um=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Hl={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 Pd(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 ${Hl[o].toLowerCase()} chart`;switch(Am(o,i)){case"no_x_axis":return Um(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:Hl[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ul(e){return e.description??Om(e.name)}const Vm={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 Km({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o,renderPreview:a}){const{theme:d}=_e(),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 P=new Set(t.sources.map(F=>F.base));return[...l].sort((F,E)=>Number(P.has(E.name))-Number(P.has(F.name)))},[l,t]),C=k.filter(P=>P.views.length>0),$=k.filter(P=>P.views.length===0),T=S.useMemo(()=>new Map(C.flatMap(P=>P.views.map(F=>[Ci(P.name,F.name),{source:P,view:F,key:Ci(P.name,F.name)}]))),[C]),j=S.useMemo(()=>C.map(P=>({key:P.name,label:P.name,...P.description?{detail:P.description}:{},entries:P.views.map(F=>({key:Ci(P.name,F.name),name:F.name,title:Ul(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 P=C[0]?.views[0];v(P&&C[0]?Ci(C[0].name,P.name):void 0)},[e]);const I=M?[M.source.name,M.view.name].filter(P=>!wo(P)).map(P=>`"${P}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,W=M!==void 0&&I===void 0,A=M?Ul(M.view):"",z=h!=="default"&&M?{chart:h,chartCarried:M.view.chart?[M.view.chart]:[]}:{},_=(P=M)=>{if(!P||![P.source.name,P.view.name].every(wo))return;const F=P.key===M?.key,E=Pm(Math.ceil(r/2),r);s({base:P.source.name,modelPath:P.source.modelPath,...P.source.exporters?{exporters:P.source.exporters}:{},view:P.view.name,...F&&b.trim()?{label:b.trim()}:{},...F?z:{},...E!==void 0?{colspan:E}:{}})},q=M?Pd(M.view,h).filter(P=>P.value!=="custom"&&P.disabled!==!0):[];return m.jsx(Ea,{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(De,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx(De,{onClick:i,children:"Cancel"}),m.jsx(De,{variant:"contained",disabled:!W,onClick:()=>_(),children:"Add tile"})]}),children:m.jsxs(B,{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(B,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(am,{groups:j,query:u,onQuery:p,picked:M?.key,onPick:P=>{v(P),x("default")},onTake:P=>_(T.get(P)),searchRef:y,empty:m.jsx(pe,{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(pe,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",$.map(P=>P.name).join(", "),"."]})})}),m.jsx(B,{sx:P=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${P.palette.text.primary} 3%, ${P.palette.background.paper})`}),children:M?m.jsxs(m.Fragment,{children:[m.jsx(B,{"aria-label":"Preview",role:"region",sx:P=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${c}`,bgcolor:P.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${P.palette.background.paper})`}}),children:a?m.jsx(B,{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()||A,...h!=="default"?z:{},givens:M.source.givens})}):m.jsxs(B,{sx:P=>({flex:1,border:`1px solid ${c}`,borderRadius:f.radius.tile,bgcolor:P.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(lm,{chart:M.view.chart}),m.jsxs(pe,{variant:"body2",children:[M.source.name," → ",M.view.name]})]})}),m.jsx(Qt,{size:"small",label:"Title",placeholder:A,value:b,onChange:P=>w(P.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs(B,{children:[m.jsx(pe,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($d,{size:"small",exclusive:!0,value:h,"aria-label":"Chart",onChange:(P,F)=>{F!==null&&x(F)},sx:{...as(c,f),"& .MuiToggleButton-root":{...as(c,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:q.map(P=>m.jsx(ko,{value:P.value,children:P.label},P.value))}),m.jsx(pe,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:M.view.chart?`The model sets ${Vm[M.view.chart]??"a chart"}.`:"The model sets no chart, so it shows as a table."})]}),I&&m.jsx(pe,{variant:"body2",color:"error",children:I})]}):m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}function Gm(e,t,{modelPath:n,textHeld:r,widths:i,insertAt:s}){t.modelPath&&!r&&(e.imports=Em(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Rd(e,t.base),a=Mo(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 Rd(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 Mo(e,t,n){const r=new Set(e.tiles.filter(oe).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 Ym(e,t){const n=e.tiles[t];if(!n||!oe(n)||ls(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...o}=structuredClone(n);r={...o,name:Mo(e,n.source,n.declaration.from)}}else{const s=e.sources.find(o=>o.name===n.source)??Rd(e,n.source,{unscoped:!0});r={name:Mo(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??Xp,t+1)),t+1}const Ti="self";function Xm({open:e,document:t,source:n,givenNames:r,dashboards:i,tileLabel:s,onClose:o,onApply:a}){const{theme:d}=_e(),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(Ea,{className:`${rt.dialog} ${rt.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[s&&m.jsxs(B,{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(De,{onClick:o,children:"Cancel"}),m.jsx(De,{variant:"contained",onClick:v,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx(pe,{variant:"body2",sx:{color:d.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx(B,{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(B,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx(B,{role:"list","aria-label":"Dimensions",children:c.map((h,x)=>{const y=h.to.length>0;return m.jsxs(B,{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(om,{size:"small",checked:y,onChange:k=>w(x,k.target.checked),slotProps:{input:{"aria-label":`${h.name} is clickable`}}}),m.jsxs(B,{sx:{minWidth:0},children:[m.jsx(B,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:Zm(h.name)}),m.jsxs(B,{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(B,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx(Qt,{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(B,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs(Qt,{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(pe,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},h.name)})})})}function Zm(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const Qm=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"})),Jm=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"})),eg=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"})),tg=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"})),ng=mt(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),rg=mt(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function ig(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of oe(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 Eo(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 og(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const ag=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function lg(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=Sd(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 cg=[{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 Co=e=>oe(e)&&!cr(e)&&e.declaration.kind!=="opaque";function dg(e,t){return e.tiles.map(n=>{const r=(oe(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 ug(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!Co(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 hg(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 fg(e,t){for(const r of e.tiles){if(!oe(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 To=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function pg({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=D=>t.sources.find(L=>L.name===D.source)?.base??D.source;S.useEffect(()=>{if(e)if(j(n!==void 0),n){l({kind:"existing",name:n.name}),p(n.label??"");const D=dg(t,n);k(D);const L=D.filter(V=>V.include),U=new Set(L.map(V=>V.field));x(U.size===1?L[0].field:n.field??""),$(U.size>1)}else l({kind:"new"}),p(""),v("select"),x(""),w(new Date().toISOString().slice(0,10)),k(t.tiles.map(D=>({include:Co(D),field:""}))),$(!1)},[e,n,t]);const I=S.useMemo(()=>[...(t.localGivens??[]).map(D=>D.name),...r.map(D=>D.name),...i],[t,r,i]),W=S.useMemo(()=>h.trim()?lg(h.trim(),I):"",[h,I]),A=c.kind==="existing"?n??r.find(D=>D.name===c.name):W?{name:W,type:Or({name:W,label:u,kind:g,field:h}).type}:void 0,z=A?.type!==void 0&&!A.type.startsWith("filter<"),_=y.find(D=>D.include)?.op??cs(A?.type),q=(D,L)=>{j(!0),k(U=>U.map((V,we)=>we===D?{...V,...L}:V))},P=D=>{j(!0),k(L=>L.map(U=>({...U,op:D})))},F=D=>{const L=cs(D);k(U=>U.map(({op:V,...we})=>L?{...we,op:L}:we))},E=D=>{j(!0),l({kind:"existing",name:D.name}),x(D.field??""),F(D.type)},O=D=>{j(!0),v(D),F(Or({name:"X",label:u,kind:D,field:h}).type)},N=t.tiles.map(Co),H=N.filter(Boolean).length,K=y.filter((D,L)=>D.include&&N[L]).length,Y=t.tiles.filter((D,L)=>(y[L]?.include??!1)&&N[L]&&oe(D)),te=Y.length>0?Y:t.tiles.filter((D,L)=>N[L]&&oe(D)),xe=S.useMemo(()=>{const D=new Map;let L=!1;for(const U of te){const V=s?.(U);if(V){L=!0;for(const we of V)D.has(we.name)||D.set(we.name,we)}}return L?[...D.values()]:void 0},[y,t.tiles,s]),me=(()=>{const D=h.trim();for(const L of Y){const U=s?.(L);if(!U||U.some(V=>V.name===D))return M(L)}return Y[0]?M(Y[0]):t.sources[0]?.base})(),ne=D=>{j(!0),k(L=>L.map((U,V)=>({...U,include:D&&N[V]})))},Ee=S.useMemo(()=>C?y:y.map(D=>({...D,field:h})),[C,y,h]),J=D=>{for(const L of te){const U=s?.(L)?.find(V=>V.name===D.trim());if(U?.type)return U.type}},Ve=D=>Xr(A?.type,D.type),Ae=(D,L)=>{if(D.trim()==="")return"Pick the field this filter compares.";const U=L?s?.(L):void 0;if(!U)return;const V=U.find(we=>we.name===D.trim());if(!V)return`Not a field of ${L?M(L):"the tiles' source"}.`;if(V.type&&!Xr(A?.type,V.type))return`${D.trim()} is ${Eo(V.type)}; this filter compares ${Eo(A?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},G=D=>{if(j(!0),x(D),f||c.kind!=="new")return;const L=J(D),U=Or({name:"X",label:u,kind:g,field:D}).type;L&&!Xr(U,L)&&O(og(L))},ye=D=>{const L=t.tiles[D];return L&&oe(L)?L:void 0},be=Ee.map((D,L)=>D.include&&N[L]?Ae(D.field,ye(L)):void 0),re=be.every(D=>D===void 0),Pe=T?be:be.map(()=>{}),Ke=T&&!C&&K>0?Y.map(D=>Ae(h,D)).find(Boolean):void 0,Re=A!==void 0&&re&&(c.kind==="existing"||h.trim()!==""&&W!==""),Ze=()=>{if(!(!A||!Re))if(c.kind==="new")o(A.name,Ee,Or({name:A.name,label:u.trim()||To(A.name),kind:g,field:h.trim(),...me?{source:me}:{},...b?{dateDefault:b}:{}}));else if(n?.origin==="dashboard"&&n.local){const D=u.trim(),L=D!==(n.local.label??"");o(A.name,Ee,L?{...n.local,...D?{label:D}:{}}:void 0)}else o(A.name,Ee)},Qe=f&&d.origin==="model";return{editing:f,shown:d,fromModel:Qe,source:c,setSource:l,label:u,setLabel:p,kind:g,dateDefault:b,setDateDefault:w,field:h,rows:y,setRows:k,perTile:C,setPerTile:$,newName:W,target:A,valueTyped:z,commonOp:_,setRow:q,setCommonOp:P,pickExisting:E,pickKind:O,bindable:N,bindableCount:H,included:K,commonFields:xe,setAll:ne,accepts:Ve,pickField:G,rowProblems:Pe,commonProblem:Ke,canApply:Re,apply:Ze}}function Vl({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(Tm,{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(Gl,{type:g.get(b)}),m.jsx(pe,{variant:"body2",sx:{flex:1,ml:1},children:b})),renderInput:v=>m.jsx(Qt,{...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(B,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Gl,{type:g.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":s}}),sx:u})}const mg=e=>e&&oe(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&&oe(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 gg({open:e,document:t,control:n,available:r,takenNames:i,fieldsFor:s,onClose:o,onApply:a,onRemove:d}){const{theme:f}=_e(),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:W,commonOp:A,setRow:z,setCommonOp:_,pickExisting:q,pickKind:P,bindable:F,bindableCount:E,included:O,commonFields:N,setAll:H,accepts:K,pickField:Y,rowProblems:te,commonProblem:xe,canApply:me,apply:ne}=pg({open:e,document:t,control:n,available:r,...i?{takenNames:i}:{},fieldsFor:s,onApply:a}),Ee=S.useRef(null),J=cn(f.cardBorder),Ve=Cs(f.cardBorder,f.tileTitle),[Ae,G]=S.useState(!1),[ye,be]=S.useState(!1);S.useEffect(()=>{e?be(!0):G(!1)},[e]),S.useEffect(()=>{ye&&(be(!1),G(l&&O<E))},[ye]),S.useEffect(()=>{T&&G(!0)},[T]);const re=N?.find(D=>D.name===k.trim())?.type,Pe=D=>{if(!re)return;const L=Or({name:"X",label:b,kind:D,field:k}).type;return Xr(L,re)?void 0:`${k.trim()} is ${Eo(re)}, which this control cannot filter.`},Ke=b.trim()||(M?To(M):"Filter"),Re=h==="number"?"Any":h==="date"?x?new Date(`${x}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ze={...as(J,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...as(J,c)["& .MuiToggleButton-root"],textTransform:"none"}},Qe=(D,L,U)=>m.jsx(Qt,{select:!0,size:"small",label:"Compares",value:D??">=",onChange:V=>L(V.target.value),inputProps:{"aria-label":U},sx:{width:130},children:ag.filter(V=>V.op!=="~").map(V=>m.jsx(Xe,{value:V.op,children:V.label},V.op))});return m.jsx(Ea,{className:`${rt.dialog} ${rt.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:Ee},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs(B,{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(De,{color:"error",startIcon:m.jsx(rm,{}),onClick:()=>d(u.name),sx:D=>({mr:"auto",color:nm(D)}),children:"Remove filter"}),m.jsx(De,{onClick:o,children:"Cancel"}),m.jsx(Ot,{title:me||I===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx(De,{variant:"contained",onClick:ne,disabled:!me,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs(ft,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs($d,{exclusive:!0,size:"small",value:g.kind,onChange:(D,L)=>{L==="new"?v({kind:"new"}):L==="existing"&&r[0]&&q(r[0])},"aria-label":"Where the filter comes from",sx:Ze,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(Qt,{select:!0,size:"small",label:"Filter",value:g.name,onChange:D=>{const L=r.find(U=>U.name===D.target.value);L&&q(L)},children:r.map(D=>m.jsxs(Xe,{value:D.name,children:[D.label??D.name,m.jsxs(pe,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",D.name]})]},D.name))}):null,m.jsxs(B,{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(Vl,{value:k,onChange:Y,fields:N,accepts:K,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:Ee,error:xe!==void 0,helperText:xe??(!l&&M?`Declared as $${M}`:void 0)}),!p&&m.jsx(Qt,{size:"small",label:"Label",placeholder:M?To(M):"",value:b,onChange:D=>w(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),W&&!T&&Qe(A,_,"Comparison"),!l&&g.kind==="new"&&m.jsxs(B,{children:[m.jsx(Kl,{children:"Control"}),m.jsx(B,{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:cg.map(D=>{const L=D.kind===h,U=Pe(D.kind);return m.jsx(Ot,{title:U??D.hint,describeChild:!0,children:m.jsxs(cd,{role:"radio","aria-checked":L,"aria-label":D.label,"aria-disabled":U!==void 0,onClick:()=>{U===void 0&&P(D.kind)},sx:V=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${L?f.accent:J}`,boxShadow:L?`0 0 0 1px ${f.accent}`:"none",bgcolor:L?`color-mix(in srgb, ${f.accent} 6%, ${V.palette.background.paper})`:V.palette.background.paper,color:L?f.accent:V.palette.text.secondary,opacity:U?.45:1,cursor:U?"default":"pointer",transition:`border-color ${nt}, background-color ${nt}`,"&:hover":U||L?{}:{borderColor:Ve}}),children:[m.jsx(xg,{kind:D.kind}),m.jsx(B,{component:"span",sx:{...c.type.caption,fontWeight:L?600:500,color:L?f.accent:"text.primary",textAlign:"center"},children:vg[D.kind]})]})},D.kind)})}),h==="date"&&m.jsx(Qt,{size:"small",type:"date",label:"Starts at",value:x,onChange:D=>y(D.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs(B,{sx:{border:`1px solid ${J}`,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(rg,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs(pe,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx(B,{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(B,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx(B,{component:"span",sx:{...c.type.code},children:k.trim()})]})]}),!T&&m.jsx(De,{size:"small","aria-expanded":Ae,onClick:()=>G(D=>!D),children:Ae?"Done choosing":"Choose tiles"})]}),m.jsx(tm,{in:Ae,unmountOnExit:!0,children:m.jsxs(B,{sx:{borderTop:`1px solid ${J}`,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:D=>H(D.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx(pe,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx(De,{size:"small",onClick:()=>{T||$(D=>D.map(L=>({...L,field:k}))),j(D=>!D)},children:T?"Same field for all":"Adjust per tile"})]}),m.jsx(ft,{sx:{gap:T?1:0},children:t.tiles.map((D,L)=>{if(!oe(D))return null;const U=C[L],V=D.label??D.name,we=T?te[L]:void 0;return m.jsxs(ft,{direction:"row",sx:{gap:1,alignItems:T?"flex-start":"center",opacity:F[L]?1:.6},children:[m.jsx(yo,{size:"small",disabled:!F[L],checked:(U?.include??!1)&&F[L],inputProps:{"aria-label":`Filter ${V}`},onChange:je=>z(L,{include:je.target.checked})}),m.jsx(pe,{variant:"body2",sx:{flex:1,minWidth:0,pt:T?1:0},noWrap:!0,children:V}),F[L]?T&&m.jsxs(m.Fragment,{children:[W&&Qe(U?.op,je=>z(L,{op:je}),`Comparison for ${V}`),m.jsx(Vl,{value:U?.field??"",onChange:je=>z(L,{field:je}),fields:s?.(D),accepts:K,label:"Field",ariaLabel:`Field for ${V}`,disabled:!U?.include,error:we!==void 0,helperText:we,sx:{width:220,pr:1}})]}):m.jsx(pe,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:mg(t.tiles[L]).reason})]},ue(D))})})]})})]}),O===0&&m.jsx(pe,{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(B,{children:[m.jsx(Kl,{children:"Preview"}),m.jsx(B,{sx:D=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:D.palette.action.hover}),children:m.jsxs(B,{"aria-hidden":!0,sx:D=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${J}`,bgcolor:D.palette.background.paper,...c.type.control}),children:[m.jsx(B,{component:"span",sx:{color:"text.secondary"},children:Ke}),m.jsx(B,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:Re}),m.jsx(wa,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function Kl({children:e}){const t=_e().theme.ui;return m.jsx(pe,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const vg={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function xg({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(Qm,{sx:t});case"multiselect":return m.jsx(Jm,{sx:t});case"text":return m.jsx(ng,{sx:t});case"number":return m.jsx(tg,{sx:t});case"date":return m.jsx(eg,{sx:t})}}function Gl({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=_e().theme.ui;return n?m.jsx(B,{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 Yl=mt(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Id(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 bg=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.`,yg=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),wg="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",kg="Declared on its source, so its chart is set in the model.",Sg="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}=_e(),c=f.ui,{draft:l,apply:u,patch:p,close:g}=Id(t,e!==null,r,n),[v,b]=S.useState(void 0),w=l!==void 0&&oe(l)?l:void 0,h=w!==void 0&&!cr(w),x=E=>u(O=>{oe(O)&&E(O)}),y=S.useRef(void 0),k=S.useRef(null),C=e!==null;S.useEffect(()=>{C?y.current=t&&oe(t)?t.chart:void 0:b(void 0)},[C]);const $=w?.chart??"default",T=Pd(a,$,d),j=w?w.declaration.kind==="query"?Sg:h?w.chart==="custom"?bg(w.chartLines):void 0:kg:void 0,M=E=>x(O=>{const N=y.current;E===(N??"default")?(N===void 0?delete O.chart:O.chart=N,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,W=$==="default"?a?.chart:$,A=W!==void 0&&yg.has(W)?wg:void 0,z=E=>O=>b({kind:E,anchor:O.currentTarget}),_=j??(W===void 0||!jg.has(W)?"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(xd).filter(E=>E!==void 0))).slice(0,8),P=E=>x(O=>{E===void 0?delete O.color:O.color=E.toLowerCase()}),F=(E,O,N)=>m.jsxs(m.Fragment,{children:[m.jsx(Bt,{primary:E,...N?{secondary:N}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),O&&m.jsx(pe,{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:z("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(Yl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),w&&j===void 0&&m.jsxs(Xe,{"aria-haspopup":"menu","aria-expanded":v?.kind==="color",disabled:_!==void 0,onClick:z("color"),onKeyDown:E=>{E.key==="ArrowRight"&&_===void 0&&b({kind:"color",anchor:E.currentTarget})},children:[F("Color",_?void 0:w.color??"Theme",_),!_&&m.jsx(Gs,{color:w.color??f.series[0],trailing:!0}),m.jsx(Yl,{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??A)}),w&&s&&m.jsx(Xe,{disabled:o!==void 0,onClick:()=>{g(),s()},children:F("Duplicate",void 0,o)}),w?.declaration.kind==="opaque"&&m.jsxs(pe,{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(B,{"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(bd,{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:()=>{P(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(Xl,{color:f.accent})]}),q.map(E=>m.jsxs(Xe,{role:"menuitemradio","aria-checked":w?.color===E.toLowerCase(),onClick:()=>{P(E),b(void 0)},children:[m.jsx(Gs,{color:E}),m.jsx(Bt,{primary:E.toLowerCase()}),w?.color===E.toLowerCase()&&m.jsx(Xl,{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??Mg(f.series[0]),onChange:E=>{const O=E.target.value;im(O)&&p(N=>{oe(N)&&(N.color=O.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx(Bt,{primary:"Other color…"})]})]})]})}const jg=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Mg=e=>(e&&xd(e))??"#000000";function Gs({color:e,trailing:t=!1}){return m.jsx(B,{"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 Xl({color:e}){return m.jsx(bd,{sx:{minWidth:0,ml:2},children:m.jsx(Ts,{fontSize:"small",sx:{color:e}})})}const Ds=e=>e.label??sm(vt(e));function Eg({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&&oe(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(gg,{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=Fm(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?Ds(h):void 0),a(h?.source)}}:{}}),m.jsx(Xm,{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(gp,{...d}),m.jsx(Km,{open:s.addingTile,document:e.document,catalog:t,columns:n,onClose:s.closeAdd,onAdd:s.addTile,onAddText:s.addText,...f?{renderPreview:f}:{}})]})}var Cg=Symbol.for("preact-signals");function As(){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}})();Qr!==void 0;){var n=Qr;for(Qr=void 0,ds++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Wd(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();Oo=++Tg,_t++;try{return e()}finally{As()}}var Zr,ke=void 0;function ie(e){var t=ke,n=Zr;ke=void 0,Zr=void 0;try{return e()}finally{ke=t,Zr=n}}var Qr=void 0,_t=0,ds=0,Tg=0,Oo=0,us=void 0,hs=0;function Nd(e){if(ke!==void 0){var t=e.n;if(t===void 0||t.t!==ke)return t={i:0,S:e,p:ke.s,n:void 0,t:ke,e:void 0,x:void 0,r:t},ke.s!==void 0&&(ke.s.n=t),ke.s=t,e.n=t,32&ke.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=ke.s,t.n=void 0,ke.s.n=t,ke.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=Cg;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:ie(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&&ie(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;ie(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 ie(function(){return e.value})};Object.defineProperty(dt.prototype,"value",{get:function(){var e=Nd(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!==Oo&&(n.l=Oo,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{As()}}}});function dr(e,t){return new dt(e,t)}function Wd(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 Ld(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 zd(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&&!Wd(this))return this.f&=-2,!0;var e=ke;try{Ld(this),ke=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 ke=e,zd(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=Nd(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Zl(e,t){return new En(e,t)}function Fd(e){var t=e.m;if(e.m=void 0,typeof t=="function"){_t++;var n=ke;ke=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Oa(e),r}finally{ke=n,As()}}}function Oa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Fd(e)}function Og(e){if(ke!==this)throw new Error("Out-of-order effect");zd(this),ke=e,this.f&=-2,8&this.f&&Oa(this),As()}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,Zr&&Zr.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,Fd(this),Ld(this),_t++;var e=ke;return ke=this,Og.bind(this,e)};ur.prototype.N=function(){2&this.f||(this.f|=2,this.u=Qr,Qr=this)};ur.prototype.d=function(){this.f|=8,1&this.f||Oa(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 Dg=Object.create,Da=Object.defineProperty,Ag=Object.defineProperties,Pg=Object.getOwnPropertyDescriptor,Rg=Object.getOwnPropertyDescriptors,Ql=Object.getOwnPropertySymbols,Ig=Object.prototype.hasOwnProperty,Ng=Object.prototype.propertyIsEnumerable,Wg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),hr=e=>{throw TypeError(e)},Do=(e,t,n)=>t in e?Da(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lg=(e,t)=>{for(var n in t||(t={}))Ig.call(t,n)&&Do(e,n,t[n]);if(Ql)for(var n of Ql(t))Ng.call(t,n)&&Do(e,n,t[n]);return e},zg=(e,t)=>Ag(e,Rg(t)),Jl=(e,t)=>Da(e,"name",{value:t,configurable:!0}),Fg=e=>{var t;return[,,,Dg((t=void 0)!=null?t:null)]},Bd=["class","method","getter","setter","accessor","field","value","get","set"],Dr=e=>e!==void 0&&typeof e!="function"?hr("Function expected"):e,Bg=(e,t,n,r,i)=>({kind:Bd[e],name:t,metadata:r,addInitializer:s=>n._?hr("Already initialized"):i.push(Dr(s||null))}),_d=(e,t)=>Do(t,Wg("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=Bd[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)&&Pg(l<4?i:{get[n](){return yt(this,s)},set[n](y){return Xt(this,s,y)}},n));l?p&&l<4&&Jl(s,(l>2?"set ":l>1?"get ":"")+n):Jl(i,n);for(var x=r.length-1;x>=0;x--)f=Bg(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>_g(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?yt:qg)(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?hr("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||_d(e,i),h&&Da(i,n,h),p?l^4?s:h:i},Aa=(e,t,n)=>t.has(e)||hr("Cannot "+n),_g=(e,t)=>Object(t)!==t?hr('Cannot use the "in" operator on this value'):e.has(t),yt=(e,t,n)=>(Aa(e,t,"read from private field"),n?n.call(e):t.get(e)),Ar=(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)=>(Aa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),qg=(e,t,n)=>(Aa(e,t,"access private method"),n);function Ao(e,t){if(t){let n;return Zl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Zl(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 se({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 We(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Ao(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,zg(Lg({},i),{enumerable:e}))})}}function xi(...e){const t=e.map(n=>$t(n));return()=>t.forEach(n=>n())}var qd,Hd,Ud,Vd,Kd,Gd,ot,Pa,Xs,Po,Ro,tt,Ra,Zs,Yd,Io,Ia,Qs,No,Wo;Gd=[se],Kd=[se],Vd=[se],Ud=[Ys()],Hd=[Ys()],qd=[Ys()];var Cn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,un(ot,5,this),Ar(this,tt),Ar(this,Pa,un(ot,8,this)),un(ot,11,this),Ar(this,Ra,un(ot,12,this)),un(ot,15,this),Ar(this,Ia,un(ot,16,this)),un(ot,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return yt(this,tt,No)}get initial(){return yt(this,tt,Po)}get previous(){return yt(this,tt,Yd)}set current(e){const t=ie(()=>yt(this,tt,No));e&&t&&this.equals(t,e)||Oe(()=>{yt(this,tt,Po)||Xt(this,tt,e,Ro),Xt(this,tt,t,Io),Xt(this,tt,e,Wo)})}reset(e=this.defaultValue){Oe(()=>{Xt(this,tt,void 0,Io),Xt(this,tt,e,Ro),Xt(this,tt,e,Wo)})}};ot=Fg();Pa=new WeakMap;tt=new WeakSet;Ra=new WeakMap;Ia=new WeakMap;Xs=fr(ot,20,"#initial",Gd,tt,Pa),Po=Xs.get,Ro=Xs.set;Zs=fr(ot,20,"#previous",Kd,tt,Ra),Yd=Zs.get,Io=Zs.set;Qs=fr(ot,20,"#current",Vd,tt,Ia),No=Qs.get,Wo=Qs.set;fr(ot,2,"current",Ud,Cn);fr(ot,2,"initial",Hd,Cn);fr(ot,2,"previous",qd,Cn);_d(ot,Cn);function Js(e){return ie(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var hn,Hg=class{constructor(){Ar(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 Ug=Object.create,Xd=Object.defineProperty,Vg=Object.getOwnPropertyDescriptor,ec=Object.getOwnPropertySymbols,Kg=Object.prototype.hasOwnProperty,Gg=Object.prototype.propertyIsEnumerable,Zd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ps=e=>{throw TypeError(e)},tc=Math.pow,Lo=(e,t,n)=>t in e?Xd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yg=(e,t)=>{for(var n in t||(t={}))Kg.call(t,n)&&Lo(e,n,t[n]);if(ec)for(var n of ec(t))Gg.call(t,n)&&Lo(e,n,t[n]);return e},Xg=e=>{var t;return[,,,Ug((t=e?.[Zd("metadata")])!=null?t:null)]},Qd=["class","method","getter","setter","accessor","field","value","get","set"],Jd=e=>e!==void 0&&typeof e!="function"?Ps("Function expected"):e,Zg=(e,t,n,r,i)=>({kind:Qd[e],name:t,metadata:r,addInitializer:s=>n._?Ps("Already initialized"):i.push(Jd(s||null))}),Qg=(e,t)=>Lo(t,Zd("metadata"),e[3]),Jg=(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},eu=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=Qd[c+5],v=e[p]||(e[p]=[]),b=(i=i.prototype,Vg(i,n)),w=r.length-1;w>=0;w--)d=Zg(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,Jd(o)&&(b[g]=o);return b&&Xd(i,n,b),i},tu=(e,t,n)=>t.has(e)||Ps("Cannot "+n),ev=(e,t,n)=>(tu(e,t,"read from private field"),t.get(e)),tv=(e,t,n)=>t.has(e)?Ps("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),nv=(e,t,n,r)=>(tu(e,t,"write to private field"),t.set(e,n),n),wt=class zo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new zo(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 zo(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=Yg({},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?rv(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 rv(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 nu,ru,Fo,_i,bi,Rs=class extends(Fo=Cn,ru=[We],nu=[We],Fo){constructor(e){const t=wt.from(e);super(t,(n,r)=>wt.equals(n,r)),Jg(bi,5,this),tv(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-ev(this,_i),o=a=>Math.round(a/s*100);Oe(()=>{nv(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=Xg(Fo);_i=new WeakMap;eu(bi,2,"delta",ru,Rs);eu(bi,2,"direction",nu,Rs);Qg(bi,Rs);function Bo({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(tc(r,2)+tc(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 iu=(e=>(e.Horizontal="x",e.Vertical="y",e))(iu||{}),su=Object.values(iu),iv=Object.create,Na=Object.defineProperty,sv=Object.defineProperties,ov=Object.getOwnPropertyDescriptor,av=Object.getOwnPropertyDescriptors,fs=Object.getOwnPropertySymbols,ou=Object.prototype.hasOwnProperty,au=Object.prototype.propertyIsEnumerable,lu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),pr=e=>{throw TypeError(e)},_o=(e,t,n)=>t in e?Na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Wa=(e,t)=>{for(var n in t||(t={}))ou.call(t,n)&&_o(e,n,t[n]);if(fs)for(var n of fs(t))au.call(t,n)&&_o(e,n,t[n]);return e},La=(e,t)=>sv(e,av(t)),nc=(e,t)=>Na(e,"name",{value:t,configurable:!0}),cu=(e,t)=>{var n={};for(var r in e)ou.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&&au.call(e,r)&&(n[r]=e[r]);return n},mr=e=>{var t;return[,,,iv((t=e?.[lu("metadata")])!=null?t:null)]},du=["class","method","getter","setter","accessor","field","value","get","set"],Pr=e=>e!==void 0&&typeof e!="function"?pr("Function expected"):e,lv=(e,t,n,r,i)=>({kind:du[e],name:t,metadata:r,addInitializer:s=>n._?pr("Already initialized"):i.push(Pr(s||null))}),Tn=(e,t)=>_o(t,lu("metadata"),e[3]),Q=(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},ae=(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=du[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)&&ov(l<4?i:{get[n](){return Ne(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=lv(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>cv(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?Ne:uu)(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?Pr(a)&&(l>4?b.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?pr("Object expected"):(Pr(o=a.get)&&(h.get=o),Pr(o=a.set)&&(h.set=o),Pr(o=a.init)&&b.unshift(o));return l||Tn(e,i),h&&Na(i,n,h),p?l^4?s:h:i},za=(e,t,n)=>t.has(e)||pr("Cannot "+n),cv=(e,t)=>Object(t)!==t?pr('Cannot use the "in" operator on this value'):e.has(t),Ne=(e,t,n)=>(za(e,t,"read from private field"),n?n.call(e):t.get(e)),fe=(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)=>(za(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),uu=(e,t,n)=>(za(e,t,"access private method"),n);function hu(e,t){return{plugin:e,options:t}}function yi(e){return t=>hu(e,t)}function ai(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var fu,li,Fa,qi;fu=[se];var it=class{constructor(e,t){this.manager=e,this.options=t,fe(this,Fa,Q(li,8,this,!1)),Q(li,11,this),fe(this,qi,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ie(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=$t(e.bind(this));return Ne(this,qi).add(t),t}destroy(){Ne(this,qi).forEach(e=>e())}static configure(e){return hu(this,e)}};li=mr(null);Fa=new WeakMap;qi=new WeakMap;ae(li,4,"disabled",fu,it,Fa);Tn(li,it);var wi=class extends it{},Hi,eo=class{constructor(e){this.manager=e,this.instances=new Map,fe(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 Ne(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 dv(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,uv=class extends it{constructor(e){super(e),fe(this,Fn),fe(this,Bn),this.computeCollisions=this.computeCollisions.bind(this),xt(this,Bn,dr(Oi)),this.destroy=xi(()=>{const t=this.computeCollisions(),n=ie(()=>this.manager.dragOperation.position.current);if(t!==Oi){const r=Ne(this,Fn);if(xt(this,Fn,n),r&&n.x==r.x&&n.y==r.y)return}else xt(this,Fn,void 0);Ne(this,Bn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ie(()=>{e?Ne(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=ie(()=>c({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return d.length===0?Oi:(a.sort(dv),a)}get collisions(){return Ne(this,Bn).value}};Fn=new WeakMap;Bn=new WeakMap;var pu,mu,gu,Ba,vu,Tt,_a,Gn,qa,Ha;gu=[se],mu=[se],pu=[se];var Ut=class pn{constructor(t,n){fe(this,_a,Q(Tt,8,this)),Q(Tt,11,this),fe(this,Gn),fe(this,qa,Q(Tt,12,this)),Q(Tt,15,this),fe(this,Ha,Q(Tt,16,this)),Q(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=Ne(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:Ne(this,Gn).peek();t!==i&&(pn.pendingIdChanges||(pn.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return uu(s=pn,Ba,vu).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);Ba=new WeakSet;vu=function(){const e=Ut.pendingIdChanges;Ut.pendingIdChanges=null,e&&Oe(()=>{for(const[t,n]of e)Ne(t,Gn).value=n})};_a=new WeakMap;Gn=new WeakMap;qa=new WeakMap;Ha=new WeakMap;ae(Tt,4,"manager",gu,Ut,_a);ae(Tt,4,"data",mu,Ut,qa);ae(Tt,4,"disabled",pu,Ut,Ha);fe(Ut,Ba);Tn(Tt,Ut);Ut.pendingIdChanges=null;var Is=Ut,rc=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}},xu,bu,yu,wu,ku,Su,qo,at,Ua,Va,Ka,Wt=class extends(qo=Is,Su=[se],ku=[se],wu=[se],yu=[We],bu=[We],xu=[We],qo){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,d=cu(n,["modifiers","type","sensors","plugins","effects"]);super(La(Wa({},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),Q(at,5,this),fe(this,Ua,Q(at,8,this)),Q(at,11,this),fe(this,Va,Q(at,12,this)),Q(at,15,this),fe(this,Ka,Q(at,16,this,this.isDragSource?"dragging":"idle")),Q(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(qo);Ua=new WeakMap;Va=new WeakMap;Ka=new WeakMap;ae(at,4,"type",Su,Wt,Ua);ae(at,4,"modifiers",ku,Wt,Va);ae(at,4,"status",wu,Wt,Ka);ae(at,2,"isDropping",yu,Wt);ae(at,2,"isDragging",bu,Wt);ae(at,2,"isDragSource",xu,Wt);Tn(at,Wt);var $u,ju,Mu,Eu,Cu,Tu,Ho,He,Ga,Ya,Xa,Za,Qa,Lt=class extends(Ho=Is,Tu=[se],Cu=[se],Eu=[se],Mu=[se],ju=[se],$u=[We],Ho){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=cu(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),Q(He,5,this),fe(this,Ga,Q(He,8,this)),Q(He,11,this),fe(this,Ya,Q(He,12,this)),Q(He,15,this),fe(this,Xa,Q(He,16,this)),Q(He,19,this),fe(this,Za,Q(He,20,this)),Q(He,23,this),fe(this,Qa,Q(He,24,this)),Q(He,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}};He=mr(Ho);Ga=new WeakMap;Ya=new WeakMap;Xa=new WeakMap;Za=new WeakMap;Qa=new WeakMap;ae(He,4,"accept",Tu,Lt,Ga);ae(He,4,"type",Cu,Lt,Ya);ae(He,4,"collisionDetector",Eu,Lt,Xa);ae(He,4,"collisionPriority",Mu,Lt,Za);ae(He,4,"shape",ju,Lt,Qa);ae(He,2,"isDropTarget",$u,Lt);Tn(He,Lt);var hv=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)}},fv=class extends hv{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 La(Wa({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var pv=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;ie(()=>{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||{}),Ou,Du,Au,Pu,Ru,Iu,Nu,St,Ja;Nu=[se],Iu=[We],Ru=[We],Pu=[We],Au=[We],Du=[We],Ou=[We];var Kt=class{constructor(){Q(St,5,this),fe(this,Ja,Q(St,8,this,"idle")),Q(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);Ja=new WeakMap;ae(St,4,"value",Nu,Kt,Ja);ae(St,2,"current",Iu,Kt);ae(St,2,"idle",Ru,Kt);ae(St,2,"initializing",Pu,Kt);ae(St,2,"initialized",Au,Kt);ae(St,2,"dragging",Du,Kt);ae(St,2,"dropped",Ou,Kt);Tn(St,Kt);var mv=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 ie(()=>{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 ie(()=>{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 ie(()=>{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 ie(()=>{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=ie(()=>{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}},gv=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,Wu=class{constructor(e){this.options=e,fe(this,Vi)}set controller(e){xt(this,Vi,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ne(this,Vi))==null||t.activate(e)}};Vi=new WeakMap;var ic=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},vv=class{constructor(e){this.draggables=new rc,this.droppables=new rc,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 Lt)return this.droppables.register(e.id,e);if(e.prototype instanceof ic)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 Lt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof ic)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()}},Lu,zu,Fu,Bu,_u,qu,Hu,Uu,Vu,Rr,Ki,_n,Te,el,tl,nl,rl,il,Ir;Vu=[We],Uu=[se],Hu=[se],qu=[se],_u=[se],Bu=[se],Fu=[We],zu=[We],Lu=[We];var Pt=class{constructor(e){Q(Te,5,this),fe(this,Rr),fe(this,Ki),fe(this,_n,new Cn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Kt,fe(this,el,Q(Te,8,this,!1)),Q(Te,11,this),fe(this,tl,Q(Te,12,this,null)),Q(Te,15,this),fe(this,nl,Q(Te,16,this,null)),Q(Te,19,this),fe(this,rl,Q(Te,20,this,null)),Q(Te,23,this),fe(this,il,Q(Te,24,this,[])),Q(Te,27,this),this.position=new Rs({x:0,y:0}),fe(this,Ir,{x:0,y:0}),xt(this,Rr,e)}get shape(){const{current:e,initial:t,previous:n}=Ne(this,_n);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ne(this,_n).current=e:Ne(this,_n).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ne(this,Rr).registry.draggables.get(t);return n&&xt(this,Ki,n),(e=n??Ne(this,Ki))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ne(this,Rr).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(La(Wa({},this.snapshot()),{transform:n}));return xt(this,Ir,n),n}snapshot(){return ie(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ne(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,Ne(this,_n).reset(),this.position.reset({x:0,y:0}),xt(this,Ir,{x:0,y:0}),this.modifiers=[]})}};Te=mr(null);Rr=new WeakMap;Ki=new WeakMap;_n=new WeakMap;el=new WeakMap;tl=new WeakMap;nl=new WeakMap;rl=new WeakMap;il=new WeakMap;Ir=new WeakMap;ae(Te,2,"shape",Vu,Pt);ae(Te,4,"canceled",Uu,Pt,el);ae(Te,4,"activatorEvent",Hu,Pt,tl);ae(Te,4,"sourceIdentifier",qu,Pt,nl);ae(Te,4,"targetIdentifier",_u,Pt,rl);ae(Te,4,"modifiers",Bu,Pt,il);ae(Te,2,"source",Fu,Pt);ae(Te,2,"target",zu,Pt);ae(Te,2,"transform",Lu,Pt);Tn(Te,Pt);var xv={get rendering(){return Promise.resolve()}};function At(e,t){return typeof e=="function"?e(t):e??t}var bv=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=At(n.plugins,[]),i=At(n.sensors,[]),s=At(n.modifiers,[]),o=(t=n.renderer)!=null?t:xv,a=new fv(this),d=new vv(this);this.registry=d,this.monitor=a,this.renderer=o,this.actions=new mv(this),this.dragOperation=new Pt(this),this.collisionObserver=new uv(this),this.plugins=[pv,...r],this.modifiers=s,this.sensors=i;const{destroy:f}=this,c=xi(()=>{var l,u,p;const g=ie(()=>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}},Ku=e=>{throw TypeError(e)},sl=(e,t,n)=>t.has(e)||Ku("Cannot "+n),Z=(e,t,n)=>(sl(e,t,"read from private field"),t.get(e)),ut=(e,t,n)=>t.has(e)?Ku("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),gt=(e,t,n,r)=>(sl(e,t,"write to private field"),t.set(e,n),n),Gu=(e,t,n)=>(sl(e,t,"access private method"),n);function Ns(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Yu(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 ol(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?ol(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 al(e){const{Document:t}=bt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function on(e){return!e||ol(e)?!1:e instanceof bt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Xu(e){return e instanceof bt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function xr(e){return e?ol(e)?e.document:ki(e)?al(e)?e:on(e)||Xu(e)?e.ownerDocument:document:document:document}function yv(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 wv(e,t){if(kv(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function kv(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(!wv(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 Zu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Uo(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(...Uo(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(...Uo(i.document,t))}}catch{}return n}function ll(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Qu(){var e,t;const n=ll()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function cl(e){return!e||!ki(e)?!1:e instanceof bt(e).ShadowRoot}function ps(e){if(e&&ki(e)){let t=e.getRootNode();if(cl(t)||t instanceof Document)return t}return xr(e)}function dl(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Sv(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];sc(i)&&sc(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),oc(i)&&oc(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function sc(e){return"value"in e}function oc(e){return e.tagName==="CANVAS"}function Ju(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 Ju(i,{x:t-s,y:n-o})}}return r}function $v(e){return e?.tagName==="IFRAME"}var Vo=new WeakMap;function jv(e){return e.closest(`
|
|
2
2
|
input:not([disabled]),
|
|
3
3
|
select:not([disabled]),
|
|
4
4
|
textarea:not([disabled]),
|
|
5
5
|
button:not([disabled]),
|
|
6
6
|
a[href],
|
|
7
7
|
[contenteditable]:not([contenteditable="false"])
|
|
8
|
-
`)}var eh=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 Mv(e){const t=new Set;let n=sr(e);for(;n;)t.add(n),n=sr(n);return t}function Cv(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function th(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=Cv(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function Ev(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 Tv(e,t=e.getBoundingClientRect()){const{width:n,height:r}=ci(e,t);return n>0&&r>0}var Ov=Qu?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Gi,Dv=class extends Ov{constructor(e){super(t=>{if(!Q(this,Gi)){gt(this,Gi,!0);return}e(t,this)}),ut(this,Gi,!1)}};Gi=new WeakMap;var ac=Array.from({length:100},(e,t)=>t/100),nh=75,mn,ms,Gt,gn,Nr,Ye,Jr,Wr,gs,rh,ih,sh=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=Q(this,Gt))==null||s.disconnect(),(o=Q(this,gn))==null||o.disconnect(),Q(this,Nr).disconnect(),(a=Q(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,th(()=>{var s,o,a;const{element:d}=this;if((s=Q(this,gn))==null||s.disconnect(),Q(this,Jr)||!Q(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),E=`${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&&Q(this,Wr).call(this)},{threshold:ac,rootMargin:E,root:f})),Q(this,gn).observe(d),Gu(this,gs,rh).call(this)},nh)),this.boundingClientRect=e.getBoundingClientRect(),gt(this,mn,Tv(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")),Q(this,Ye).style.background="rgba(0,0,0,0.15)",Q(this,Ye).style.position="fixed",Q(this,Ye).style.pointerEvents="none",i.body.appendChild(Q(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=Q(this,mn);gt(this,mn,c),!(!l&&!u)&&(p&&!c?((o=Q(this,gn))==null||o.disconnect(),this.callback(null),(a=Q(this,Gt))==null||a.disconnect(),gt(this,Gt,void 0),Q(this,Ye)&&(Q(this,Ye).style.visibility="hidden")):Q(this,Wr).call(this),c&&!Q(this,Gt)&&(gt(this,Gt,new Dv(Q(this,Wr))),Q(this,Gt).observe(e)))},{threshold:ac,root:i})),Q(this,mn)&&!n.skipInitial&&this.callback(this.boundingClientRect),Q(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;rh=function(){Q(this,Jr)||(Gu(this,gs,ih).call(this),!Ev(this.boundingClientRect,Q(this,ms))&&(this.callback(this.boundingClientRect),gt(this,ms,this.boundingClientRect)))};ih=function(){if(Q(this,Ye)){const{top:e,left:t,width:n,height:r}=ci(this.element);Q(this,Ye).style.overflow="hidden",Q(this,Ye).style.visibility="visible",Q(this,Ye).style.top=`${Math.floor(e)}px`,Q(this,Ye).style.left=`${Math.floor(t)}px`,Q(this,Ye).style.width=`${Math.floor(n)}px`,Q(this,Ye).style.height=`${Math.floor(r)}px`}};var Di=new WeakMap,Ai=new WeakMap;function Av(e,t){let n=Di.get(e);return n||(n={disconnect:new sh(e,r=>{const i=Di.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Di.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Di.delete(e),n.disconnect())}}function Pv(e,t){const n=new Set;for(const r of e){const i=Av(r,t);n.add(i)}return()=>n.forEach(r=>r())}function Rv(e,t){var n;const r=e.ownerDocument;if(!Ai.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}),Ai.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=Ai.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),Ai.delete(r))})}var Lr,zr,Yi,Ko,Iv=class{constructor(e,t,n){this.callback=t,ut(this,Lr),ut(this,zr,!1),ut(this,Yi),ut(this,Ko,th(o=>{if(!Q(this,zr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of Q(this,Yi))if(o.target.contains(a)){this.callback(Q(this,Lr).boundingClientRect);break}}},nh));const r=Mv(e),i=Pv(r,t),s=Rv(e,Q(this,Ko));gt(this,Yi,r),gt(this,Lr,new sh(e,t,n)),this.disconnect=()=>{Q(this,zr)||(gt(this,zr,!0),i(),s(),Q(this,Lr).disconnect())}}};Lr=new WeakMap;zr=new WeakMap;Yi=new WeakMap;Ko=new WeakMap;function Go(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Zn(e){try{Go(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function lc(e){return!Qu||!e?!1:e===xr(e).scrollingElement}function oh(e){var t,n;const r=bt(e),i=lc(e)?yv(e):Ws(e),s=r.visualViewport,o=lc(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 Nv(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=oh(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 ul=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 ul(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Wv=new ul(e=>setTimeout(e,50)),xs=new Map,Lv=xs.clear.bind(xs);function zt(e,t=!1){if(!t)return cc(e);let n=xs.get(e);return n||(n=cc(e),xs.set(e,n),Wv.schedule(Lv),n)}function cc(e){return bt(e).getComputedStyle(e)}function zv(e,t=zt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Fv(e,t=zt(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 Bv={excludeElement:!0,escapeShadowDOM:!0};function Yo(e,t=Bv){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(al(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&cl(a))return o(a.host);if(!on(a))return Xu(a)?o(a.parentElement):s;if(s.has(a))return s;const d=zt(a,!0);if(r&&a===e||Fv(a,d)&&s.add(a),zv(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}=_v(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 _v(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=zt(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function qv(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 Ls(e){var t,n,r,i,s,o,a,d,f;const{scale:c,transform:l,translate:u}=e,p=qv(c),g=di(u),v=Hv(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 Hv(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||{}),Uv={x:.2,y:.2},Vv={x:10,y:10};function Kv(e,t,n,r=25,i=Uv,s=Vv){const{x:o,y:a}=t,{rect:d,isTop:f,isBottom:c,isLeft:l,isRight:u}=oh(e),p=or(e),g=zt(e,!0),v=Ls(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 ah(e,{block:t="nearest",inline:n="nearest"}={}){if(!on(e))return;const r=Yo(e),i=[];for(const s of r){if(!on(s))continue;const{top:o,left:a}=Gv(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 dc(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 Gv(e,t){const n=dc(e),r=dc(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Yv(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 Xv(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 lh({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function uc(e,t=zt(e).translate,n=!0){if(n){const r=Yu(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 Qv=new ul(e=>setTimeout(e,0)),ei=new Map,Zv=ei.clear.bind(ei);function Jv(e){const t=e.ownerDocument;let n=ei.get(t);if(n)return n;n=t.getAnimations(),ei.set(t,n),Qv.schedule(Zv);const r=n.filter(i=>Ns(i.effect)&&i.effect.target===e);return ei.set(e,r),n}function ex(e,t){const n=Jv(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=ex(e,{properties:["transform","translate","scale","width","height"],isValidTarget:k=>(k!==e||ll())&&k.contains(e)}),c=d(e);let{top:l,left:u,width:p,height:g}=c,v;const b=zt(e),w=Ls(b),h={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},x=tx(e,b);f?.(),w&&(v=Xv(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=Yv(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 tx(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?Ls({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 nx=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 rx(e){if(!e)return!1;const{PointerEvent:t}=bt(e.target);return e instanceof t}function ix(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 Xo(e){const t=to[e]==null?0:to[e]+1;return to[e]=t,`${e}-${t}`}var hl=({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},ox=({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},ch=e=>{var t;return(t=hl(e))!=null?t:ox(e)},ax=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}},lx=Object.create,fl=Object.defineProperty,cx=Object.defineProperties,dx=Object.getOwnPropertyDescriptor,ux=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,dh=Object.prototype.hasOwnProperty,uh=Object.prototype.propertyIsEnumerable,hh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),br=e=>{throw TypeError(e)},Qo=(e,t,n)=>t in e?fl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hi=(e,t)=>{for(var n in t||(t={}))dh.call(t,n)&&Qo(e,n,t[n]);if(bs)for(var n of bs(t))uh.call(t,n)&&Qo(e,n,t[n]);return e},pl=(e,t)=>cx(e,ux(t)),hc=(e,t)=>fl(e,"name",{value:t,configurable:!0}),fh=(e,t)=>{var n={};for(var r in e)dh.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&&uh.call(e,r)&&(n[r]=e[r]);return n},yr=e=>{var t;return[,,,lx((t=e?.[hh("metadata")])!=null?t:null)]},ph=["class","method","getter","setter","accessor","field","value","get","set"],Fr=e=>e!==void 0&&typeof e!="function"?br("Function expected"):e,hx=(e,t,n,r,i)=>({kind:ph[e],name:t,metadata:r,addInitializer:s=>n._?br("Already initialized"):i.push(Fr(s||null))}),On=(e,t)=>Qo(t,hh("metadata"),e[3]),Ue=(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=ph[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)&&dx(l<4?i:{get[n](){return ve(this,s)},set[n](y){return lt(this,s,y)}},n));l?p&&l<4&&hc(s,(l>2?"set ":l>1?"get ":"")+n):hc(i,n);for(var x=r.length-1;x>=0;x--)f=hx(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>fx(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?ve: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&&fl(i,n,h),p?l^4?s:h:i},ml=(e,t,n)=>t.has(e)||br("Cannot "+n),fx=(e,t)=>Object(t)!==t?br('Cannot use the "in" operator on this value'):e.has(t),ve=(e,t,n)=>(ml(e,t,"read from private field"),n?n.call(e):t.get(e)),ze=(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)=>(ml(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Mn=(e,t,n)=>(ml(e,t,"access private method"),n),fc={role:"button",roleDescription:"draggable"},px="dnd-kit-description",mx="dnd-kit-announcement",gx={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."},vx={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 xx(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function bx(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function yx(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 wx=["dragover","dragmove"],kx=class extends it{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=px,announcement:i=mx}={},announcements:s=vx,screenReaderInstructions:o=gx,debounce:a=500}=t??{},d=n?`${r}-${n}`:Xo(r),f=n?`${i}-${n}`:Xo(i);let c,l,u,p;const g=(k=p)=>{!u||!k||u?.nodeValue!==k&&(u.nodeValue=k)},v=()=>vs.schedule(g),b=Sx(v,a),w=Object.entries(s).map(([k,E])=>this.manager.monitor.addEventListener(k,($,T)=>{const j=u;if(!j)return;const M=E?.($,T);M&&j.nodeValue!==M&&(p=M,wx.includes(k)?b():(v(),b.cancel()))})),h=()=>{let k=[];c?.isConnected||(c=bx(d,o.draggable),k.push(c)),l?.isConnected||(l=yx(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 E of this.manager.registry.draggables.value){const $=(k=E.handle)!=null?k:E.element;if($){(!c||!l)&&x.add(h),(!xx($)||ll())&&!$.hasAttribute("tabindex")&&x.add(()=>$.setAttribute("tabindex","0")),!$.hasAttribute("role")&&$.tagName.toLowerCase()!=="button"&&x.add(()=>$.setAttribute("role",fc.role)),$.hasAttribute("aria-roledescription")||x.add(()=>$.setAttribute("aria-roledescription",fc.roleDescription)),$.hasAttribute("aria-describedby")||x.add(()=>$.setAttribute("aria-describedby",d));for(const j of["aria-pressed","aria-grabbed"]){const M=String(E.isDragging);$.getAttribute(j)!==M&&x.add(()=>$.setAttribute(j,M))}const T=String(E.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 Sx(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var ys=new Map,mh,gh,vh,xh,Zo,ni,qt,gl,ar,bh,yh,wh,kh,an=class extends(Zo=wi,xh=[se],vh=[We],gh=[We],mh=[We],Zo){constructor(e,t){super(e,t),Ue(qt,5,this),ze(this,ar),ze(this,ni,new Set),ze(this,gl,Ue(qt,8,this,new Set)),Ue(qt,11,this),this.registerEffect(Mn(this,ar,bh))}register(e){return ve(this,ni).add(e),()=>{ve(this,ni).delete(e)}}addRoot(e){return ie(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{ie(()=>{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(Zo);ni=new WeakMap;gl=new WeakMap;ar=new WeakSet;bh=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ve(this,ni))t.push(Mn(this,ar,yh).call(this,n,r));return()=>{for(const n of t)n()}};yh=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=al(e)?Mn(this,ar,wh).call(this,e,n,t):Mn(this,ar,kh).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())}};wh=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)}}};kh=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(cl(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",xh,an,gl);jt(qt,2,"sourceRoot",vh,an);jt(qt,2,"targetRoot",gh,an);jt(qt,2,"roots",mh,an);On(qt,an);an.configure=yi(an);var zs=an,$x=class extends it{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(zs),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},Si="data-dnd-",Jo=`${Si}dropping`,Ge="--dnd-",Rt=`${Si}dragging`,ws=`${Si}placeholder`,jx=[Rt,ws,"popover","aria-pressed","aria-grabbing"],Mx=["view-transition-name"],Cx=`
|
|
8
|
+
`)}var eh=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 Mv(e){const t=new Set;let n=sr(e);for(;n;)t.add(n),n=sr(n);return t}function Ev(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function th(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=Ev(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function Cv(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 Tv(e,t=e.getBoundingClientRect()){const{width:n,height:r}=ci(e,t);return n>0&&r>0}var Ov=Zu?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Gi,Dv=class extends Ov{constructor(e){super(t=>{if(!Z(this,Gi)){gt(this,Gi,!0);return}e(t,this)}),ut(this,Gi,!1)}};Gi=new WeakMap;var ac=Array.from({length:100},(e,t)=>t/100),nh=75,mn,ms,Gt,gn,Nr,Ye,Jr,Wr,gs,rh,ih,sh=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=Z(this,Gt))==null||s.disconnect(),(o=Z(this,gn))==null||o.disconnect(),Z(this,Nr).disconnect(),(a=Z(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,th(()=>{var s,o,a;const{element:d}=this;if((s=Z(this,gn))==null||s.disconnect(),Z(this,Jr)||!Z(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&&Z(this,Wr).call(this)},{threshold:ac,rootMargin:C,root:f})),Z(this,gn).observe(d),Gu(this,gs,rh).call(this)},nh)),this.boundingClientRect=e.getBoundingClientRect(),gt(this,mn,Tv(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")),Z(this,Ye).style.background="rgba(0,0,0,0.15)",Z(this,Ye).style.position="fixed",Z(this,Ye).style.pointerEvents="none",i.body.appendChild(Z(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=Z(this,mn);gt(this,mn,c),!(!l&&!u)&&(p&&!c?((o=Z(this,gn))==null||o.disconnect(),this.callback(null),(a=Z(this,Gt))==null||a.disconnect(),gt(this,Gt,void 0),Z(this,Ye)&&(Z(this,Ye).style.visibility="hidden")):Z(this,Wr).call(this),c&&!Z(this,Gt)&&(gt(this,Gt,new Dv(Z(this,Wr))),Z(this,Gt).observe(e)))},{threshold:ac,root:i})),Z(this,mn)&&!n.skipInitial&&this.callback(this.boundingClientRect),Z(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;rh=function(){Z(this,Jr)||(Gu(this,gs,ih).call(this),!Cv(this.boundingClientRect,Z(this,ms))&&(this.callback(this.boundingClientRect),gt(this,ms,this.boundingClientRect)))};ih=function(){if(Z(this,Ye)){const{top:e,left:t,width:n,height:r}=ci(this.element);Z(this,Ye).style.overflow="hidden",Z(this,Ye).style.visibility="visible",Z(this,Ye).style.top=`${Math.floor(e)}px`,Z(this,Ye).style.left=`${Math.floor(t)}px`,Z(this,Ye).style.width=`${Math.floor(n)}px`,Z(this,Ye).style.height=`${Math.floor(r)}px`}};var Di=new WeakMap,Ai=new WeakMap;function Av(e,t){let n=Di.get(e);return n||(n={disconnect:new sh(e,r=>{const i=Di.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Di.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Di.delete(e),n.disconnect())}}function Pv(e,t){const n=new Set;for(const r of e){const i=Av(r,t);n.add(i)}return()=>n.forEach(r=>r())}function Rv(e,t){var n;const r=e.ownerDocument;if(!Ai.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}),Ai.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=Ai.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),Ai.delete(r))})}var Lr,zr,Yi,Ko,Iv=class{constructor(e,t,n){this.callback=t,ut(this,Lr),ut(this,zr,!1),ut(this,Yi),ut(this,Ko,th(o=>{if(!Z(this,zr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of Z(this,Yi))if(o.target.contains(a)){this.callback(Z(this,Lr).boundingClientRect);break}}},nh));const r=Mv(e),i=Pv(r,t),s=Rv(e,Z(this,Ko));gt(this,Yi,r),gt(this,Lr,new sh(e,t,n)),this.disconnect=()=>{Z(this,zr)||(gt(this,zr,!0),i(),s(),Z(this,Lr).disconnect())}}};Lr=new WeakMap;zr=new WeakMap;Yi=new WeakMap;Ko=new WeakMap;function Go(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Qn(e){try{Go(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function lc(e){return!Zu||!e?!1:e===xr(e).scrollingElement}function oh(e){var t,n;const r=bt(e),i=lc(e)?yv(e):Ws(e),s=r.visualViewport,o=lc(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 Nv(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=oh(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 ul=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 ul(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Wv=new ul(e=>setTimeout(e,50)),xs=new Map,Lv=xs.clear.bind(xs);function zt(e,t=!1){if(!t)return cc(e);let n=xs.get(e);return n||(n=cc(e),xs.set(e,n),Wv.schedule(Lv),n)}function cc(e){return bt(e).getComputedStyle(e)}function zv(e,t=zt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Fv(e,t=zt(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 Bv={excludeElement:!0,escapeShadowDOM:!0};function Yo(e,t=Bv){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(al(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&cl(a))return o(a.host);if(!on(a))return Xu(a)?o(a.parentElement):s;if(s.has(a))return s;const d=zt(a,!0);if(r&&a===e||Fv(a,d)&&s.add(a),zv(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}=_v(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 _v(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=zt(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function qv(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 Ls(e){var t,n,r,i,s,o,a,d,f;const{scale:c,transform:l,translate:u}=e,p=qv(c),g=di(u),v=Hv(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 Hv(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||{}),Uv={x:.2,y:.2},Vv={x:10,y:10};function Kv(e,t,n,r=25,i=Uv,s=Vv){const{x:o,y:a}=t,{rect:d,isTop:f,isBottom:c,isLeft:l,isRight:u}=oh(e),p=or(e),g=zt(e,!0),v=Ls(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 ah(e,{block:t="nearest",inline:n="nearest"}={}){if(!on(e))return;const r=Yo(e),i=[];for(const s of r){if(!on(s))continue;const{top:o,left:a}=Gv(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 dc(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 Gv(e,t){const n=dc(e),r=dc(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Yv(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 Xv(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 lh({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function uc(e,t=zt(e).translate,n=!0){if(n){const r=Yu(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 Zv=new ul(e=>setTimeout(e,0)),ei=new Map,Qv=ei.clear.bind(ei);function Jv(e){const t=e.ownerDocument;let n=ei.get(t);if(n)return n;n=t.getAnimations(),ei.set(t,n),Zv.schedule(Qv);const r=n.filter(i=>Ns(i.effect)&&i.effect.target===e);return ei.set(e,r),n}function ex(e,t){const n=Jv(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=ex(e,{properties:["transform","translate","scale","width","height"],isValidTarget:k=>(k!==e||ll())&&k.contains(e)}),c=d(e);let{top:l,left:u,width:p,height:g}=c,v;const b=zt(e),w=Ls(b),h={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},x=tx(e,b);f?.(),w&&(v=Xv(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=Yv(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 tx(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?Ls({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 nx=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 rx(e){if(!e)return!1;const{PointerEvent:t}=bt(e.target);return e instanceof t}function ix(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 Xo(e){const t=to[e]==null?0:to[e]+1;return to[e]=t,`${e}-${t}`}var hl=({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},ox=({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},ch=e=>{var t;return(t=hl(e))!=null?t:ox(e)},ax=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}},lx=Object.create,fl=Object.defineProperty,cx=Object.defineProperties,dx=Object.getOwnPropertyDescriptor,ux=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,dh=Object.prototype.hasOwnProperty,uh=Object.prototype.propertyIsEnumerable,hh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),br=e=>{throw TypeError(e)},Zo=(e,t,n)=>t in e?fl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hi=(e,t)=>{for(var n in t||(t={}))dh.call(t,n)&&Zo(e,n,t[n]);if(bs)for(var n of bs(t))uh.call(t,n)&&Zo(e,n,t[n]);return e},pl=(e,t)=>cx(e,ux(t)),hc=(e,t)=>fl(e,"name",{value:t,configurable:!0}),fh=(e,t)=>{var n={};for(var r in e)dh.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&&uh.call(e,r)&&(n[r]=e[r]);return n},yr=e=>{var t;return[,,,lx((t=e?.[hh("metadata")])!=null?t:null)]},ph=["class","method","getter","setter","accessor","field","value","get","set"],Fr=e=>e!==void 0&&typeof e!="function"?br("Function expected"):e,hx=(e,t,n,r,i)=>({kind:ph[e],name:t,metadata:r,addInitializer:s=>n._?br("Already initialized"):i.push(Fr(s||null))}),On=(e,t)=>Zo(t,hh("metadata"),e[3]),Ue=(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=ph[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)&&dx(l<4?i:{get[n](){return ve(this,s)},set[n](y){return lt(this,s,y)}},n));l?p&&l<4&&hc(s,(l>2?"set ":l>1?"get ":"")+n):hc(i,n);for(var x=r.length-1;x>=0;x--)f=hx(l,n,d={},e[3],w),l&&(f.static=u,f.private=p,c=f.access={has:p?y=>fx(i,y):y=>n in y},l^3&&(c.get=p?y=>(l^1?ve: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&&fl(i,n,h),p?l^4?s:h:i},ml=(e,t,n)=>t.has(e)||br("Cannot "+n),fx=(e,t)=>Object(t)!==t?br('Cannot use the "in" operator on this value'):e.has(t),ve=(e,t,n)=>(ml(e,t,"read from private field"),n?n.call(e):t.get(e)),ze=(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)=>(ml(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Mn=(e,t,n)=>(ml(e,t,"access private method"),n),fc={role:"button",roleDescription:"draggable"},px="dnd-kit-description",mx="dnd-kit-announcement",gx={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."},vx={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 xx(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function bx(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function yx(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 wx=["dragover","dragmove"],kx=class extends it{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=px,announcement:i=mx}={},announcements:s=vx,screenReaderInstructions:o=gx,debounce:a=500}=t??{},d=n?`${r}-${n}`:Xo(r),f=n?`${i}-${n}`:Xo(i);let c,l,u,p;const g=(k=p)=>{!u||!k||u?.nodeValue!==k&&(u.nodeValue=k)},v=()=>vs.schedule(g),b=Sx(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,wx.includes(k)?b():(v(),b.cancel()))})),h=()=>{let k=[];c?.isConnected||(c=bx(d,o.draggable),k.push(c)),l?.isConnected||(l=yx(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),(!xx($)||ll())&&!$.hasAttribute("tabindex")&&x.add(()=>$.setAttribute("tabindex","0")),!$.hasAttribute("role")&&$.tagName.toLowerCase()!=="button"&&x.add(()=>$.setAttribute("role",fc.role)),$.hasAttribute("aria-roledescription")||x.add(()=>$.setAttribute("aria-roledescription",fc.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 Sx(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var ys=new Map,mh,gh,vh,xh,Qo,ni,qt,gl,ar,bh,yh,wh,kh,an=class extends(Qo=wi,xh=[se],vh=[We],gh=[We],mh=[We],Qo){constructor(e,t){super(e,t),Ue(qt,5,this),ze(this,ar),ze(this,ni,new Set),ze(this,gl,Ue(qt,8,this,new Set)),Ue(qt,11,this),this.registerEffect(Mn(this,ar,bh))}register(e){return ve(this,ni).add(e),()=>{ve(this,ni).delete(e)}}addRoot(e){return ie(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{ie(()=>{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(Qo);ni=new WeakMap;gl=new WeakMap;ar=new WeakSet;bh=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ve(this,ni))t.push(Mn(this,ar,yh).call(this,n,r));return()=>{for(const n of t)n()}};yh=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=al(e)?Mn(this,ar,wh).call(this,e,n,t):Mn(this,ar,kh).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())}};wh=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)}}};kh=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(cl(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",xh,an,gl);jt(qt,2,"sourceRoot",vh,an);jt(qt,2,"targetRoot",gh,an);jt(qt,2,"roots",mh,an);On(qt,an);an.configure=yi(an);var zs=an,$x=class extends it{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(zs),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},Si="data-dnd-",Jo=`${Si}dropping`,Ge="--dnd-",Rt=`${Si}dragging`,ws=`${Si}placeholder`,jx=[Rt,ws,"popover","aria-pressed","aria-grabbing"],Mx=["view-transition-name"],Ex=`
|
|
9
9
|
:is(:root,:host) [${Rt}] {
|
|
10
10
|
position: fixed !important;
|
|
11
11
|
pointer-events: none !important;
|
|
@@ -64,41 +64,41 @@ import{Z as id,V as _e,aO as cn,aP as Es,r as S,j as m,ad as ft,az as rt,N as Ot
|
|
|
64
64
|
display: none;
|
|
65
65
|
visibility: hidden;
|
|
66
66
|
}
|
|
67
|
-
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Ex(e,t="hidden"){return ie(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Tx(n,r.registry.droppables),s=[],o=Sv(n),{remove:a}=o;return Ox(i,o,s),Dx(o,t),o.remove=()=>{s.forEach(d=>d()),a.call(o)},o})}function Tx(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${Si}${Xo("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Ox(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),Vo.set(a,o),n.push(()=>{Vo.delete(a),r.proxy=void 0})}}function Dx(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(ws,t)}function Sh(e,t){return e===t?!0:sr(e)===sr(t)}function pc(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&jn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Zn(t))}function ea(e){return e.tagName==="TR"}function Ax(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-")||jx.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(Mx.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 Px(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 Rx(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=Zu();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(),ea(e.element)&&ea(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 Ix=250,Nx="ease";function Wx(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=Ix,easing:a=Nx}=s??{};Zn(e.feedbackElement);const[,d]=(t=Yu(e.feedbackElement,h=>"translate"in h))!=null?t:[];d?.pause();const f=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Sh(e.feedbackElement,f)?null:void 0},l=new It(e.feedbackElement,c),u=(r=di(zt(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(Jo,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),lh({element:e.feedbackElement,keyframes:pl(hi(hi({},b),w),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:dl(bt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Jo),d?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var $h,ta,fi,vl,Xi,jh,Mh,lr=class extends(ta=it,$h=[se],ta){constructor(e,t){super(e,t),ze(this,Xi),ze(this,vl,Ue(fi,8,this)),Ue(fi,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(zs),r=n?.register(Cx);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(Mn(this,Xi,jh).bind(this,n)),this.registerEffect(Mn(this,Xi,Mh))}};fi=yr(ta);vl=new WeakMap;Xi=new WeakSet;jh=function(e){const{overlay:t}=this;if(!t||!e)return;const n=ps(t);if(n)return e.addRoot(n)};Mh=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),E=!Sh(g,x),$=new It(g,{frameTransform:E?k:null,ignoreTransforms:!E}),T={x:k.scaleX/y.scaleX,y:k.scaleY/y.scaleY};let{width:j,height:M,top:I,left:W}=$;E&&(j=j/T.x,M=M/T.y);const A=new nx(x),z=zt(g),{transition:_,translate:q,boxSizing:P,paddingBlockStart:F,paddingBlockEnd:C,paddingInlineStart:O,paddingInlineEnd:N,borderInlineStartWidth:H,borderInlineEndWidth:K,borderBlockStartWidth:Y,borderBlockEndWidth:te}=z,xe=_.split(",").filter(le=>!/^\s*(transform|translate|scale)\b/.test(le)).join(","),me=Ls(z),ne=z.transform,Ce=w==="clone",J=P==="content-box",Ve=J?parseInt(O)+parseInt(N)+parseInt(H)+parseInt(K):0,Ae=J?parseInt(F)+parseInt(C)+parseInt(Y)+parseInt(te):0,G=w!=="move"&&!this.overlay?Ex(u,Ce?"clone":"hidden"):null,ye=ie(()=>ui(d.dragOperation.activatorEvent));if(!h.translate){if(this.overlay&&me)h.translate={x:me.x,y:me.y};else if(q!=="none"){const le=di(q);le&&(h.translate=le)}}if(!h.transformOrigin){const le=ie(()=>l.current),he=W+((r=me?.x)!=null?r:0),qe=I+((i=me?.y)!=null?i:0);h.transformOrigin={x:(le.x-he*y.scaleX-y.x)/(j*y.scaleX),y:(le.y-qe*y.scaleY-y.y)/(M*y.scaleY)}}const{transformOrigin:be}=h,re=I*y.scaleY+y.y,Pe=W*y.scaleX+y.x;if(!h.coordinates&&(h.coordinates={x:Pe,y:re},T.x!==1||T.y!==1)){const{scaleX:le,scaleY:he}=k,{x:qe,y:Ct}=be;h.coordinates.x+=(j*le-j)*qe,h.coordinates.y+=(M*he-M)*Ct}h.dimensions||(h.dimensions={width:j,height:M}),h.frameTransform||(h.frameTransform=y);const Ke={x:h.coordinates.x-Pe,y:h.coordinates.y-re},Re={width:(h.dimensions.width*h.frameTransform.scaleX-j*y.scaleX)*be.x,height:(h.dimensions.height*h.frameTransform.scaleY-M*y.scaleY)*be.y},Qe={x:Ke.x/y.scaleX+Re.width,y:Ke.y/y.scaleY+Re.height},Ze={left:W+Qe.x,top:I+Qe.y};x.setAttribute(Rt,"true");const D=ie(()=>c.transform),L=(s=h.translate)!=null?s:{x:0,y:0},U=D.x*y.scaleX+L.x,V=D.y*y.scaleY+L.y,we=Zu();A.set({width:j-Ve,height:M-Ae,top:Ze.top+we.y,left:Ze.left+we.x,translate:`${U}px ${V}px 0`,transform:this.overlay?"none":ne,transition:xe?`${xe}, translate 0ms linear`:"translate 0ms linear",scale:E?`${T.x} ${T.y}`:"","transform-origin":`${be.x*100}% ${be.y*100}%`},Ge),G&&(g.insertAdjacentElement("afterend",G),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(g)),Go(x)&&(x.hasAttribute("popover")||x.setAttribute("popover","manual"),Zn(x),x.addEventListener("beforetoggle",pc));let je,Mt,R;const ce=Rx({placeholder:G,element:g,feedbackElement:x,frameTransform:y,transformOrigin:be,width:j,height:M,top:I,left:W,widthOffset:Ve,heightOffset:Ae,delta:Qe,styles:A,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>je,getSavedCellWidths:()=>R,setSavedCellWidths:le=>{R=le}}),Je=new It(x);ie(()=>c.shape=Je);const Fe=bt(x),st=le=>{this.manager.actions.stop({event:le})},ee=dl(Fe);ye&&Fe.addEventListener("resize",st),ie(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),G&&(ce.observe(G),je=Ax(g,G,Ce),Mt=Px(g,G,x));const et=(o=d.dragOperation.source)==null?void 0:o.id,X=()=>{var le;if(!ye||et==null)return;const he=d.registry.draggables.get(et),qe=(le=he?.handle)!=null?le:he?.element;on(qe)&&qe.focus()},de=()=>{je?.disconnect(),Mt?.disconnect(),ce.disconnect(),Fe.removeEventListener("resize",st),Go(x)&&(x.removeEventListener("beforetoggle",pc),x.removeAttribute("popover")),x.removeAttribute(Rt),A.reset();const le=()=>{var he;if(R&&ea(g)){const $r=Array.from(g.cells);for(const[Dn,An]of $r.entries())An.style.width=(he=R[Dn])!=null?he:""}u.status="idle";const qe=a.current.translate!=null,Ct=c.status.dragging;G&&(!Ct&&qe||G.parentElement!==x.parentElement)&&x.isConnected&&G.replaceWith(x),G?.remove()};x===this.overlay?setTimeout(le,0):le()},Ie=f?.dropAnimation,ge=this,dn=xi(()=>{var le,he,qe;const{transform:Ct,status:$r}=c;if(!(!Ct.x&&!Ct.y&&!a.current.translate)&&$r.dragging){const Dn=(le=h.translate)!=null?le:{x:0,y:0},An={x:Ct.x/y.scaleX+Dn.x,y:Ct.y/y.scaleY+Dn.y},Pl=a.current.translate,Jf=ie(()=>c.modifiers),Hs=ie(()=>{var jr;return(jr=c.shape)==null?void 0:jr.current}),Us=f?.keyboardTransition,Rl=ye&&!ee&&Us!==null?`${(he=Us?.duration)!=null?he:250}ms ${(qe=Us?.easing)!=null?qe:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(A.set({transition:xe?`${xe}, translate ${Rl}`:`translate ${Rl}`,translate:`${An.x}px ${An.y}px 0`},Ge),je?.takeRecords(),Hs&&Hs!==Je&&Pl&&!Jf.length){const jr=wt.delta(An,Pl);c.shape=Nt.from(Hs.boundingRectangle).translate(jr.x*y.scaleX,jr.y*y.scaleY)}else c.shape=new It(x);a.current.translate=An}},function(){if(c.status.dropped){this.dispose(),u.status="dropping";const le=v?.dropAnimation!==void 0?v.dropAnimation:ge.dropAnimation!==void 0?ge.dropAnimation:Ie;let he=a.current.translate;const qe=he!=null;if(!he&&g!==x&&(he={x:0,y:0}),!he||le===null){de();return}d.renderer.rendering.then(()=>{Wx({source:u,element:g,feedbackElement:x,placeholder:G,translate:he,moved:qe,transition:_,alignment:u.alignment,styles:A,animation:le??void 0,getElementMutationObserver:()=>je,cleanup:de,restoreFocus:X})})}});return()=>{de(),dn()}};jt(fi,4,"overlay",$h,lr,vl);On(fi,lr);lr.configure=yi(lr);var xl=lr,Cr=!0,Lx=!1,Ch,Eh,Th,Oh,Jt,bl,yl;Oh=(Th=[se],kt.Forward),Eh=(Ch=[se],kt.Reverse);var pi=class{constructor(){ze(this,bl,Ue(Jt,8,this,Cr)),Ue(Jt,11,this),ze(this,yl,Ue(Jt,12,this,Cr)),Ue(Jt,15,this)}isLocked(e){return e===kt.Idle?!1:e==null?this[kt.Forward]===Cr&&this[kt.Reverse]===Cr:this[e]===Cr}unlock(e){e!==kt.Idle&&(this[e]=Lx)}};Jt=yr(null);bl=new WeakMap;yl=new WeakMap;jt(Jt,4,Oh,Th,pi,bl);jt(Jt,4,Eh,Ch,pi,yl);On(Jt,pi);var zx=[kt.Forward,kt.Reverse],mc=class{constructor(){this.x=new pi,this.y=new pi}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Fx=class extends it{constructor(e){super(e);const t=dr(new mc);let n=null;this.signal=t,$t(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new mc;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:gc(i.x,n.x),y:gc(i.y,n.y)},o=t.peek();Oe(()=>{for(const a of su)for(const d of zx)s[a]===d&&o[a].unlock(d);t.value=o})}n=i})}get current(){return this.signal.peek()}};function gc(e,t){return Math.sign(e-t)}var Dh,na,mi,wl,Yt,ra,$i=class extends(na=wi,Dh=[se],na){constructor(e){super(e),ze(this,wl,Ue(mi,8,this,!1)),Ue(mi,11,this),ze(this,Yt),ze(this,ra,()=>{if(!ve(this,Yt))return;const{element:s,by:o}=ve(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:vc(l.x),y:vc(l.y)}:void 0,p=u?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const g of d){const v=Nv(g,l);if(v.x||v.y){const{speed:b,direction:w}=Kv(g,c,u,o?.acceleration,o?.threshold);if(p)for(const h of su)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 E=(a=ve(this,Yt))==null?void 0:a.by;if(this.autoScrolling&&E&&(E.x&&!y||E.y&&!k))continue;return lt(this,Yt,{element:g,by:{x:y,y:k}}),vs.schedule(ve(this,ra)),!0}}}}}return lt(this,Yt,void 0),!1};let t=null,n=null;const r=Ao(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=Ju(ps(o?.element),s.current);return a&&(t=a),a??t}),i=Ao(()=>{const s=r.value,{documentElement:o}=xr(s);if(!s||s===o){const{target:a}=e.dragOperation,d=a?.element;if(d){const f=Yo(d,{excludeElement:!1});return n=f,f}}if(s){const a=Yo(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},Et);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new Fx(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(na);wl=new WeakMap;Yt=new WeakMap;ra=new WeakMap;jt(mi,4,"autoScrolling",Dh,$i,wl);On(mi,$i);function vc(e){return e>0?kt.Forward:e<0?kt.Reverse:kt.Idle}var Bx=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))}},_x=new Bx(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),qx=10,ia=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(()=>_x.schedule(()=>n.scroll(void 0,d)),qx);return()=>{clearInterval(f)}}else n.autoScrolling=!1}})}};ia.configure=yi(ia);var Ah=ia,xc={capture:!0,passive:!0},Br,Hx=class extends wi{constructor(e){super(e),ze(this,Br),this.handleScroll=()=>{ve(this,Br)==null&<(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,xc),()=>{s.removeEventListener("scroll",this.handleScroll,xc)}}})}};Br=new WeakMap;var Ux="* { user-select: none !important; -webkit-user-select: none !important; }",Vx=class extends it{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(zs),n=t?.register(Ux);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,ze(this,qn,[]),this.listeners=new eh,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(),ah(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}}])];ve(this,qn).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=_r.keyboardCodes}=n??{};if(Rn(e,[...r.end,...r.cancel])){e.preventDefault();const i=Rn(e,r.cancel);this.handleEnd(e,i);return}Rn(e,r.up)?this.handleMove("up",e):Rn(e,r.down)&&this.handleMove("down",e),Rn(e,r.left)?this.handleMove("left",e):Rn(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(Ah);e?.disabled===!1&&(e.disable(),ve(this,qn).push(()=>{e.enable()}))}cleanup(){ve(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 Ph=ks;function Rn(e,t){return t.includes(e.code)}var vn,Kx=class extends Wu{constructor(){super(...arguments),ze(this,vn)}onEvent(e){switch(e.type){case"pointerdown":lt(this,vn,ir(e));break;case"pointermove":if(!ve(this,vn))return;const{x:t,y:n}=ir(e),r={x:t-ve(this,vn).x,y:n-ve(this,vn).y},{tolerance:i}=this.options;if(i&&Bo(r,i)){this.abort();return}Bo(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,Gx=class extends Wu{constructor(){super(...arguments),ze(this,Hn),ze(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(!ve(this,xn))return;const{x:t,y:n}=ir(e),r={x:t-ve(this,xn).x,y:n-ve(this,xn).y};Bo(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ve(this,Hn)&&(clearTimeout(ve(this,Hn)),lt(this,xn,void 0),lt(this,Hn,void 0))}};Hn=new WeakMap;xn=new WeakMap;var Yn=class{};Yn.Delay=Gx;Yn.Distance=Kx;var sa=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})]:ix(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=jv(r);return i===t.element?!1:!!i}}),Un,Ss=class extends rr{constructor(e,t){super(e),this.manager=e,this.options=t,ze(this,Un,new Set),this.listeners=new eh,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=sa.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=>{rx(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&&(Qx(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||Yx(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=sa.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 gv(f,g=>this.handleStart(t,g));c.signal.onabort=()=>this.handleCancel(e),c.onEvent(e),this.controller=c;const l=Uo(),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:Pi,options:{capture:!0}}]),p=()=>{u(),this.initialCoordinates=void 0};ve(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:Pi,options:{passive:!1}},{type:"click",listener:Pi},{type:"contextmenu",listener:Pi},{type:"keydown",listener:this.handleKeyDown}]);ve(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},ve(this,Un).forEach(t=>t()),ve(this,Un).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Un=new WeakMap;Ss.configure=yi(Ss);Ss.defaults=sa;var oa=Ss;function Yx(e){return"sensor"in e}function Pi(e){e.preventDefault()}function Xx(){}var bc=new WeakSet;function Qx(e){!e||bc.has(e)||(e.addEventListener("touchmove",Xx,{capture:!1,passive:!1}),bc.add(e))}var Jn={modifiers:[],plugins:[kx,Ah,$x,xl,Vx],sensors:[oa,Ph]},Rh=class extends bv{constructor(e={}){const t=At(e.plugins,Jn.plugins),n=At(e.sensors,Jn.sensors),r=At(e.modifiers,Jn.modifiers);super(pl(hi({},e),{plugins:[Hx,$i,zs,...t],sensors:n,modifiers:r}))}},Ih,Nh,aa,en,kl,Sl,Fs=class extends(aa=Wt,Nh=[se],Ih=[se],aa){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=fh(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),ze(this,kl,Ue(en,8,this)),Ue(en,11,this),ze(this,Sl,Ue(en,12,this)),Ue(en,15,this),this.element=r,this.handle=s}};en=yr(aa);kl=new WeakMap;Sl=new WeakMap;jt(en,4,"handle",Nh,Fs,kl);jt(en,4,"element",Ih,Fs,Sl);On(en,Fs);var Wh,Lh,la,tn,$l,ro,zh,Fh,ri,jl,Bs=class extends(la=Lt,Lh=[se],Wh=[se],la){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=fh(n,["element","effects"]);const{collisionDetector:o=ch}=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=ie(()=>this.shape);return u&&p?.equals(u)?p:(this.shape=u,u)},d=dr(!1);super(pl(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 Iv(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),ze(this,ri),ze(this,$l,Ue(tn,8,this)),Ue(tn,11,this),ze(this,jl,Ue(tn,12,this)),Ue(tn,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){lt(this,ri,e,Fh)}get element(){var e;return(e=this.proxy)!=null?e:ve(this,ri,zh)}};tn=yr(la);$l=new WeakMap;ri=new WeakSet;jl=new WeakMap;ro=jt(tn,20,"#element",Lh,ri,$l),zh=ro.get,Fh=ro.set;jt(tn,4,"proxy",Wh,Bs,jl);On(tn,Bs);function Zx(e){return e!=null&&typeof e=="object"&&"current"in e}function er(e){var t;if(e!=null)return Zx(e)?(t=e.current)!=null?t:void 0:e}var Jx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",wr=Jx?S.useLayoutEffect:S.useEffect;function eb(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Bh(e,t){const n=S.useRef(new Map),r=eb();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=ie(()=>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(()=>Rm.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 tb(e,t){e()}function In(e){const t=S.useRef(e);return wr(()=>{t.current=e},[e]),t}function Ee(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 nb=Object.defineProperty,rb=Object.defineProperties,ib=Object.getOwnPropertyDescriptors,$s=Object.getOwnPropertySymbols,_h=Object.prototype.hasOwnProperty,qh=Object.prototype.propertyIsEnumerable,yc=(e,t,n)=>t in e?nb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sb=(e,t)=>{for(var n in t||(t={}))_h.call(t,n)&&yc(e,n,t[n]);if($s)for(var n of $s(t))qh.call(t,n)&&yc(e,n,t[n]);return e},ob=(e,t)=>rb(e,ib(t)),ab=(e,t)=>{var n={};for(var r in e)_h.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&&qh.call(e,r)&&(n[r]=e[r]);return n},lb=new Rh,Hh=S.createContext(lb),cb=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,Et];function db(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:d}=t,f=ab(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:l,modifiers:u,sensors:p}=f,g=At(l,Jn.plugins),v=At(p,Jn.sensors),b=At(u,Jn.modifiers),w=In(i),h=In(s),x=In(a),y=In(o),k=In(d),E=In(r),$=ub(()=>{var T;return(T=f.manager)!=null?T:new Rh(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",W=>{const A=w.current;A&&j(()=>A(W,$))}),M.addEventListener("dragstart",W=>{var A;return(A=h.current)==null?void 0:A.call(h,W,$)}),M.addEventListener("dragover",W=>{const A=x.current;A&&j(()=>A(W,$))}),M.addEventListener("dragmove",W=>{const A=y.current;A&&j(()=>A(W,$))}),M.addEventListener("dragend",W=>{const A=k.current;A&&j(()=>A(W,$))}),M.addEventListener("collision",W=>{var A;return(A=E.current)==null?void 0:A.call(E,W,$)})];return()=>I.forEach(W=>W())},[$]),Ee(g,()=>$&&($.plugins=g),...io),Ee(v,()=>$&&($.sensors=v),...io),Ee(b,()=>$&&($.modifiers=b),...io),m.jsxs(Hh.Provider,{value:$,children:[m.jsx(cb,{ref:c,children:n}),n]})}function ub(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 Uh(){return S.useContext(Hh)}function Vh(e){var t;const n=(t=Uh())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),wr(r.register,[n,r]),r}var hb=Object.create,Kh=Object.defineProperty,fb=Object.getOwnPropertyDescriptor,Gh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),_s=e=>{throw TypeError(e)},pb=(e,t,n)=>t in e?Kh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mb=e=>{var t;return[,,,hb((t=e?.[Gh("metadata")])!=null?t:null)]},Yh=["class","method","getter","setter","accessor","field","value","get","set"],Xh=e=>e!==void 0&&typeof e!="function"?_s("Function expected"):e,gb=(e,t,n,r,i)=>({kind:Yh[e],name:t,metadata:r,addInitializer:s=>n._?_s("Already initialized"):i.push(Xh(s||null))}),vb=(e,t)=>pb(t,Gh("metadata"),e[3]),xb=(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},Qh=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=Yh[c+5],v=e[p]||(e[p]=[]),b=(i=i.prototype,fb(i,n)),w=r.length-1;w>=0;w--)d=gb(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,Xh(o)&&(b[g]=o);return b&&Kh(i,n,b),i},Zh=(e,t,n)=>t.has(e)||_s("Cannot "+n),bb=(e,t,n)=>(Zh(e,t,"read from private field"),t.get(e)),yb=(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),wb=(e,t,n,r)=>(Zh(e,t,"write to private field"),t.set(e,n),n),yn=class ca{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ca(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 ca(t,n)}},Jh,ef,da,Zi,ji,Ml=class extends(da=En,ef=[We],Jh=[We],da){constructor(e){const t=yn.from(e);super(t,(n,r)=>yn.equals(n,r)),xb(ji,5,this),yb(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-bb(this,Zi),o=a=>Math.round(a/s*100);Oe(()=>{wb(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=mb(da);Zi=new WeakMap;Qh(ji,2,"delta",ef,Ml);Qh(ji,2,"direction",Jh,Ml);vb(ji,Ml);var tf=(e=>(e.Horizontal="x",e.Vertical="y",e))(tf||{});Object.values(tf);var kb=({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},Sb=({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=kb(e))!=null?t:Sb(e)};function jb(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,d=Vh(c=>new Bs(ob(sb({},e),{register:!1,element:er(i)}),c)),f=Bh(d);return Ee(s,()=>d.id=s),Qi(i,c=>d.element=c),Ee(o,()=>d.accept=o,void 0,Et),Ee(t,()=>d.collisionDetector=t??$b),Ee(n,()=>n&&(d.data=n)),Ee(r,()=>d.disabled=r===!0),Ee(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 nf=(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}}},rf=S.createContext(void 0);function sf(e,t){const n=S.useContext(rf),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 ua({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:i=!1}){const{theme:s}=_e(),[o,a]=S.useState(void 0),d=S.useRef(!1),f=()=>{d.current||o===void 0||(a(void 0),o!==e&&r(o))};sf(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(B,{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}},nf(s)],children:l?t:e})}return m.jsx(yd,{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 Mb=(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}),Cb=(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},of=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),af=e=>`gap.${e}`,Eb=(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:ue(e[o-1]),colspan:t-r}),d&&(r=0),n.push(of(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:ue(i),colspan:t-r}),n};var Tb=Object.create,lf=Object.defineProperty,Ob=Object.defineProperties,Db=Object.getOwnPropertyDescriptor,Ab=Object.getOwnPropertyDescriptors,js=Object.getOwnPropertySymbols,cf=Object.prototype.hasOwnProperty,df=Object.prototype.propertyIsEnumerable,Pb=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Mi=e=>{throw TypeError(e)},ha=(e,t,n)=>t in e?lf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,so=(e,t)=>{for(var n in t||(t={}))cf.call(t,n)&&ha(e,n,t[n]);if(js)for(var n of js(t))df.call(t,n)&&ha(e,n,t[n]);return e},oo=(e,t)=>Ob(e,Ab(t)),Rb=(e,t)=>{var n={};for(var r in e)cf.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&&df.call(e,r)&&(n[r]=e[r]);return n},Ib=e=>{var t;return[,,,Tb((t=void 0)!=null?t:null)]},uf=["class","method","getter","setter","accessor","field","value","get","set"],qr=e=>e!==void 0&&typeof e!="function"?Mi("Function expected"):e,Nb=(e,t,n,r,i)=>({kind:uf[e],name:t,metadata:r,addInitializer:s=>n._?Mi("Already initialized"):i.push(qr(s||null))}),Wb=(e,t)=>ha(t,Pb("metadata"),e[3]),Ri=(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},hf=(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=uf[l+5],b=e[g-1]=[],w=e[g]||(e[g]=[]),h=(i=i.prototype,Db({get[n](){return Hr(this,s)},set[n](y){return bn(this,s,y)}},n)),x=r.length-1;x>=0;x--)f=Nb(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&&lf(i,n,h),i},ff=(e,t,n)=>t.has(e)||Mi("Cannot "+n),Hr=(e,t,n)=>(ff(e,t,"read from private field"),t.get(e)),Er=(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)=>(ff(e,t,"write to private field"),t.set(e,n),n);function wn(e){return e instanceof Tl||e instanceof vf}var Ii=10,Lb=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=zb(f),{source:l,target:u}=s,{center:p}=s.shape.current,g=[],v=[];Oe(()=>{for(const k of d.droppables){const{id:E}=k;if(!k.accepts(l)||E===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,ax);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:E,shape:$}=s;if(!k||!wn(k)||!$)return;const{index:T,group:j,target:M}=k.sortable,I=x!==T||y!==j,W=I?M:E?.element;if(!W)return;ah(W);const A=new It(W);if(!A)return;const z=Nt.delta(A,Nt.from($.current.boundingRectangle),k.alignment);o.move({by:z}),I?o.setDropTarget(k.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function zb(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 Fb=Object.defineProperty,Bb=Object.defineProperties,_b=Object.getOwnPropertyDescriptors,wc=Object.getOwnPropertySymbols,qb=Object.prototype.hasOwnProperty,Hb=Object.prototype.propertyIsEnumerable,kc=(e,t,n)=>t in e?Fb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nn=(e,t)=>{for(var n in t||(t={}))qb.call(t,n)&&kc(e,n,t[n]);if(wc)for(var n of wc(t))Hb.call(t,n)&&kc(e,n,t[n]);return e},Wn=(e,t)=>Bb(e,_b(t));function Ub(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 Vb(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 E=e[h][x];return Wn(Nn({},e),{[h]:[...e[h].slice(0,x),...e[h].slice(x+1)],[y]:[...e[y].slice(0,k),E,...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 E=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),E,...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 Kb(e,t){return Vb(e,t,Ub)}function Sc(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function $c(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 jc="__default__",Gb=class extends it{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof Tl){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=Sc(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($c(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:jc,k=(g=a.sortable.group)!=null?g:jc,E={[y]:h,[k]:x},$=Kb(E,r);if(E===$)return;const T=$[k].indexOf(o.sortable),j=$[k].indexOf(a.sortable);i.collisionObserver.disable(),Mc(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=Sc(a),f=a.get(o.sortable.initialGroup);f&&i.renderer.rendering.then(()=>{const c=t();if($c(d,a,c))return;const l=Wi(f),u=Wi(f,Xb),p=o.sortable.element,g=u.indexOf(o.sortable),v=l[g],b=v?.element;!v||!b||!p||(Mc(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 Mc(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function Yb(e,t){return e.index-t.index}function Xb(e,t){return e.initialIndex-t.initialIndex}function Wi(e,t=Yb){return Array.from(e).sort(t)}var Cc=[Lb,Gb],pf={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Ec(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 Li=new Hg,mf,gf,nn,Cl,Ur,Vr,El,Vn;gf=[se],mf=[se];var qs=class{constructor(e,t){Er(this,Cl,Ri(nn,8,this)),Ri(nn,11,this),Er(this,Ur),Er(this,Vr),Er(this,El,Ri(nn,12,this)),Ri(nn,15,this),Er(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=pf,plugins:c}=n,l=Rb(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=At(c,Cc),p=Ec(i);this.droppable=new Tl(oo(so({},l),{disabled:p.droppable}),t,this),this.draggable=new vf(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)&&Li.clear(this.manager),w?.dragging&&Li.set(this.manager,this.id,ie(()=>({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(xl))==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=Li.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Li.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ie(()=>{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}=zt(i),d=uc(i,a,!1),f=uc(i,a);if(o.x||o.y){const c=dl(bt(i))?oo(so({},t),{duration:0}):t;lh({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=Vo.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=At(e,Cc)}set disabled(e){const t=Ec(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??ch}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=Ib();Cl=new WeakMap;Ur=new WeakMap;Vr=new WeakMap;El=new WeakMap;Vn=new WeakMap;hf(nn,4,"index",gf,qs,Cl);hf(nn,4,"group",mf,qs,El);Wb(nn,qs);var vf=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}},Tl=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}},Qb=Object.defineProperty,Zb=Object.defineProperties,Jb=Object.getOwnPropertyDescriptors,Tc=Object.getOwnPropertySymbols,ey=Object.prototype.hasOwnProperty,ty=Object.prototype.propertyIsEnumerable,Oc=(e,t,n)=>t in e?Qb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lo=(e,t)=>{for(var n in t||(t={}))ey.call(t,n)&&Oc(e,n,t[n]);if(Tc)for(var n of Tc(t))ty.call(t,n)&&Oc(e,n,t[n]);return e},ny=(e,t)=>Zb(e,Jb(t));function ry(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({},pf),e.transition),w=Vh(x=>new qs(ny(lo({},e),{transition:b,register:!1,handle:er(a),element:er(o),target:er(p)}),x)),h=Bh(w,iy);return Ee(i,()=>w.id=i),wr(()=>{Oe(()=>{w.group=f,w.index=d})},[w,f,d]),Ee(g,()=>w.type=g),Ee(t,()=>w.accept=t,void 0,Et),Ee(s,()=>s&&(w.data=s)),Ee(d,()=>{var x;(x=w.manager)!=null&&x.dragOperation.status.idle&&b?.idle&&w.refreshShape()},tb),Qi(a,x=>w.handle=x),Qi(o,x=>w.element=x),Qi(p,x=>w.target=x),Ee(c,()=>w.disabled=c??!1,void 0,Et),Ee(u,()=>w.sensors=u,void 0,Et),Ee(n,()=>w.collisionDetector=n),Ee(r,()=>w.collisionPriority=r),Ee(v,()=>w.plugins=v,void 0,Et),Ee(b,()=>w.transition=b,void 0,Et),Ee(l,()=>w.modifiers=l,void 0,Et),Ee(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 iy(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const fa="tile",xf="gap",sy=[oa.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${bf}], ${oy}`)!==null||(oa.defaults.preventActivation?.(e,t)??!1)}),Ph],bf="data-no-drag",oy=".malloy-render, .malloy-table",ay=e=>[...e,xl.configure({feedback:"clone"})];function ly({id:e,index:t,disabled:n=!1,children:r}){const{ref:i,handleRef:s,isDragSource:o}=ry({id:e,index:t,disabled:n,type:fa,accept:fa,collisionDetector:hl,plugins:ay});return m.jsx(m.Fragment,{children:r({ref:i,handleRef:s,isDragSource:o})})}function cy({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=jb({id:e,type:xf,accept:fa,collisionDetector:hl,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:i})})}function dy({active:e}){const t=Uh();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 yf=e=>e.ok===!1,Be=(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=>Be(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Be(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Be(e,"VIEW","subQueryDefList"),defDimension:e=>Be(e,"defList","DIMENSION"),exploreProperties:e=>Be(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Be(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Be(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Be(e,"WHERE","filterClauseList"),givenDef:e=>Be(e,"givenNameDef"),givenStatement:e=>Be(e,"GIVEN","givenDefList"),importStatement:e=>Be(e,"IMPORT","importURL"),vArrow:e=>Be(e,"ARROW","vExpr","segExpr"),segRefine:e=>Be(e,"PLUS","segExpr"),segOps:e=>Be(e,"queryProperties"),segField:e=>Be(e,"fieldPath")&&!Be(e,"segExpr"),segParen:e=>Be(e,"OPAREN","CPAREN","vExpr"),compare:e=>Be(e,"fieldExpr","compareOp"),givenRef:e=>Be(e,"GIVEN_REF")};function uy(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 hy(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
-
`&&t.push(n+1);return t}function wf(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 kf{constructor(t){this.text=t,this.map=uy(t),this.lineStarts=hy(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
|
|
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 Ol(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 my(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&&pa(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&&pa(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 gy(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:Ol(e,i,a?.start??f.start),siblings:o.length,body:my(e,u)})}}return n}function vy(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:Ol(e,i,o?.start??d.start)})}}return n}function xy(e,t){const n=[];for(const r of
|
|
67
|
+
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Cx(e,t="hidden"){return ie(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Tx(n,r.registry.droppables),s=[],o=Sv(n),{remove:a}=o;return Ox(i,o,s),Dx(o,t),o.remove=()=>{s.forEach(d=>d()),a.call(o)},o})}function Tx(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${Si}${Xo("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Ox(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),Vo.set(a,o),n.push(()=>{Vo.delete(a),r.proxy=void 0})}}function Dx(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(ws,t)}function Sh(e,t){return e===t?!0:sr(e)===sr(t)}function pc(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&jn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Qn(t))}function ea(e){return e.tagName==="TR"}function Ax(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-")||jx.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(Mx.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 Px(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),Qn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Qn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Qn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Rx(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=Qu();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(),ea(e.element)&&ea(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 Ix=250,Nx="ease";function Wx(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=Ix,easing:a=Nx}=s??{};Qn(e.feedbackElement);const[,d]=(t=Yu(e.feedbackElement,h=>"translate"in h))!=null?t:[];d?.pause();const f=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Sh(e.feedbackElement,f)?null:void 0},l=new It(e.feedbackElement,c),u=(r=di(zt(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(Jo,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),lh({element:e.feedbackElement,keyframes:pl(hi(hi({},b),w),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:dl(bt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Jo),d?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var $h,ta,fi,vl,Xi,jh,Mh,lr=class extends(ta=it,$h=[se],ta){constructor(e,t){super(e,t),ze(this,Xi),ze(this,vl,Ue(fi,8,this)),Ue(fi,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(zs),r=n?.register(Ex);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(Mn(this,Xi,jh).bind(this,n)),this.registerEffect(Mn(this,Xi,Mh))}};fi=yr(ta);vl=new WeakMap;Xi=new WeakSet;jh=function(e){const{overlay:t}=this;if(!t||!e)return;const n=ps(t);if(n)return e.addRoot(n)};Mh=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=!Sh(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:W}=$;C&&(j=j/T.x,M=M/T.y);const A=new nx(x),z=zt(g),{transition:_,translate:q,boxSizing:P,paddingBlockStart:F,paddingBlockEnd:E,paddingInlineStart:O,paddingInlineEnd:N,borderInlineStartWidth:H,borderInlineEndWidth:K,borderBlockStartWidth:Y,borderBlockEndWidth:te}=z,xe=_.split(",").filter(le=>!/^\s*(transform|translate|scale)\b/.test(le)).join(","),me=Ls(z),ne=z.transform,Ee=w==="clone",J=P==="content-box",Ve=J?parseInt(O)+parseInt(N)+parseInt(H)+parseInt(K):0,Ae=J?parseInt(F)+parseInt(E)+parseInt(Y)+parseInt(te):0,G=w!=="move"&&!this.overlay?Cx(u,Ee?"clone":"hidden"):null,ye=ie(()=>ui(d.dragOperation.activatorEvent));if(!h.translate){if(this.overlay&&me)h.translate={x:me.x,y:me.y};else if(q!=="none"){const le=di(q);le&&(h.translate=le)}}if(!h.transformOrigin){const le=ie(()=>l.current),he=W+((r=me?.x)!=null?r:0),qe=I+((i=me?.y)!=null?i:0);h.transformOrigin={x:(le.x-he*y.scaleX-y.x)/(j*y.scaleX),y:(le.y-qe*y.scaleY-y.y)/(M*y.scaleY)}}const{transformOrigin:be}=h,re=I*y.scaleY+y.y,Pe=W*y.scaleX+y.x;if(!h.coordinates&&(h.coordinates={x:Pe,y:re},T.x!==1||T.y!==1)){const{scaleX:le,scaleY:he}=k,{x:qe,y:Et}=be;h.coordinates.x+=(j*le-j)*qe,h.coordinates.y+=(M*he-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-re},Re={width:(h.dimensions.width*h.frameTransform.scaleX-j*y.scaleX)*be.x,height:(h.dimensions.height*h.frameTransform.scaleY-M*y.scaleY)*be.y},Ze={x:Ke.x/y.scaleX+Re.width,y:Ke.y/y.scaleY+Re.height},Qe={left:W+Ze.x,top:I+Ze.y};x.setAttribute(Rt,"true");const D=ie(()=>c.transform),L=(s=h.translate)!=null?s:{x:0,y:0},U=D.x*y.scaleX+L.x,V=D.y*y.scaleY+L.y,we=Qu();A.set({width:j-Ve,height:M-Ae,top:Qe.top+we.y,left:Qe.left+we.x,translate:`${U}px ${V}px 0`,transform:this.overlay?"none":ne,transition:xe?`${xe}, translate 0ms linear`:"translate 0ms linear",scale:C?`${T.x} ${T.y}`:"","transform-origin":`${be.x*100}% ${be.y*100}%`},Ge),G&&(g.insertAdjacentElement("afterend",G),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(g)),Go(x)&&(x.hasAttribute("popover")||x.setAttribute("popover","manual"),Qn(x),x.addEventListener("beforetoggle",pc));let je,Mt,R;const ce=Rx({placeholder:G,element:g,feedbackElement:x,frameTransform:y,transformOrigin:be,width:j,height:M,top:I,left:W,widthOffset:Ve,heightOffset:Ae,delta:Ze,styles:A,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>je,getSavedCellWidths:()=>R,setSavedCellWidths:le=>{R=le}}),Je=new It(x);ie(()=>c.shape=Je);const Fe=bt(x),st=le=>{this.manager.actions.stop({event:le})},ee=dl(Fe);ye&&Fe.addEventListener("resize",st),ie(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),G&&(ce.observe(G),je=Ax(g,G,Ee),Mt=Px(g,G,x));const et=(o=d.dragOperation.source)==null?void 0:o.id,X=()=>{var le;if(!ye||et==null)return;const he=d.registry.draggables.get(et),qe=(le=he?.handle)!=null?le:he?.element;on(qe)&&qe.focus()},de=()=>{je?.disconnect(),Mt?.disconnect(),ce.disconnect(),Fe.removeEventListener("resize",st),Go(x)&&(x.removeEventListener("beforetoggle",pc),x.removeAttribute("popover")),x.removeAttribute(Rt),A.reset();const le=()=>{var he;if(R&&ea(g)){const $r=Array.from(g.cells);for(const[Dn,An]of $r.entries())An.style.width=(he=R[Dn])!=null?he:""}u.status="idle";const qe=a.current.translate!=null,Et=c.status.dragging;G&&(!Et&&qe||G.parentElement!==x.parentElement)&&x.isConnected&&G.replaceWith(x),G?.remove()};x===this.overlay?setTimeout(le,0):le()},Ie=f?.dropAnimation,ge=this,dn=xi(()=>{var le,he,qe;const{transform:Et,status:$r}=c;if(!(!Et.x&&!Et.y&&!a.current.translate)&&$r.dragging){const Dn=(le=h.translate)!=null?le:{x:0,y:0},An={x:Et.x/y.scaleX+Dn.x,y:Et.y/y.scaleY+Dn.y},Pl=a.current.translate,Jf=ie(()=>c.modifiers),Hs=ie(()=>{var jr;return(jr=c.shape)==null?void 0:jr.current}),Us=f?.keyboardTransition,Rl=ye&&!ee&&Us!==null?`${(he=Us?.duration)!=null?he:250}ms ${(qe=Us?.easing)!=null?qe:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(A.set({transition:xe?`${xe}, translate ${Rl}`:`translate ${Rl}`,translate:`${An.x}px ${An.y}px 0`},Ge),je?.takeRecords(),Hs&&Hs!==Je&&Pl&&!Jf.length){const jr=wt.delta(An,Pl);c.shape=Nt.from(Hs.boundingRectangle).translate(jr.x*y.scaleX,jr.y*y.scaleY)}else c.shape=new It(x);a.current.translate=An}},function(){if(c.status.dropped){this.dispose(),u.status="dropping";const le=v?.dropAnimation!==void 0?v.dropAnimation:ge.dropAnimation!==void 0?ge.dropAnimation:Ie;let he=a.current.translate;const qe=he!=null;if(!he&&g!==x&&(he={x:0,y:0}),!he||le===null){de();return}d.renderer.rendering.then(()=>{Wx({source:u,element:g,feedbackElement:x,placeholder:G,translate:he,moved:qe,transition:_,alignment:u.alignment,styles:A,animation:le??void 0,getElementMutationObserver:()=>je,cleanup:de,restoreFocus:X})})}});return()=>{de(),dn()}};jt(fi,4,"overlay",$h,lr,vl);On(fi,lr);lr.configure=yi(lr);var xl=lr,Er=!0,Lx=!1,Eh,Ch,Th,Oh,Jt,bl,yl;Oh=(Th=[se],kt.Forward),Ch=(Eh=[se],kt.Reverse);var pi=class{constructor(){ze(this,bl,Ue(Jt,8,this,Er)),Ue(Jt,11,this),ze(this,yl,Ue(Jt,12,this,Er)),Ue(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]=Lx)}};Jt=yr(null);bl=new WeakMap;yl=new WeakMap;jt(Jt,4,Oh,Th,pi,bl);jt(Jt,4,Ch,Eh,pi,yl);On(Jt,pi);var zx=[kt.Forward,kt.Reverse],mc=class{constructor(){this.x=new pi,this.y=new pi}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Fx=class extends it{constructor(e){super(e);const t=dr(new mc);let n=null;this.signal=t,$t(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new mc;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:gc(i.x,n.x),y:gc(i.y,n.y)},o=t.peek();Oe(()=>{for(const a of su)for(const d of zx)s[a]===d&&o[a].unlock(d);t.value=o})}n=i})}get current(){return this.signal.peek()}};function gc(e,t){return Math.sign(e-t)}var Dh,na,mi,wl,Yt,ra,$i=class extends(na=wi,Dh=[se],na){constructor(e){super(e),ze(this,wl,Ue(mi,8,this,!1)),Ue(mi,11,this),ze(this,Yt),ze(this,ra,()=>{if(!ve(this,Yt))return;const{element:s,by:o}=ve(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:vc(l.x),y:vc(l.y)}:void 0,p=u?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const g of d){const v=Nv(g,l);if(v.x||v.y){const{speed:b,direction:w}=Kv(g,c,u,o?.acceleration,o?.threshold);if(p)for(const h of su)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=ve(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(ve(this,ra)),!0}}}}}return lt(this,Yt,void 0),!1};let t=null,n=null;const r=Ao(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=Ju(ps(o?.element),s.current);return a&&(t=a),a??t}),i=Ao(()=>{const s=r.value,{documentElement:o}=xr(s);if(!s||s===o){const{target:a}=e.dragOperation,d=a?.element;if(d){const f=Yo(d,{excludeElement:!1});return n=f,f}}if(s){const a=Yo(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 Fx(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(na);wl=new WeakMap;Yt=new WeakMap;ra=new WeakMap;jt(mi,4,"autoScrolling",Dh,$i,wl);On(mi,$i);function vc(e){return e>0?kt.Forward:e<0?kt.Reverse:kt.Idle}var Bx=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))}},_x=new Bx(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),qx=10,ia=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(()=>_x.schedule(()=>n.scroll(void 0,d)),qx);return()=>{clearInterval(f)}}else n.autoScrolling=!1}})}};ia.configure=yi(ia);var Ah=ia,xc={capture:!0,passive:!0},Br,Hx=class extends wi{constructor(e){super(e),ze(this,Br),this.handleScroll=()=>{ve(this,Br)==null&<(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,xc),()=>{s.removeEventListener("scroll",this.handleScroll,xc)}}})}};Br=new WeakMap;var Ux="* { user-select: none !important; -webkit-user-select: none !important; }",Vx=class extends it{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(zs),n=t?.register(Ux);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,ze(this,qn,[]),this.listeners=new eh,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(),ah(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}}])];ve(this,qn).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=_r.keyboardCodes}=n??{};if(Rn(e,[...r.end,...r.cancel])){e.preventDefault();const i=Rn(e,r.cancel);this.handleEnd(e,i);return}Rn(e,r.up)?this.handleMove("up",e):Rn(e,r.down)&&this.handleMove("down",e),Rn(e,r.left)?this.handleMove("left",e):Rn(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(Ah);e?.disabled===!1&&(e.disable(),ve(this,qn).push(()=>{e.enable()}))}cleanup(){ve(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 Ph=ks;function Rn(e,t){return t.includes(e.code)}var vn,Kx=class extends Wu{constructor(){super(...arguments),ze(this,vn)}onEvent(e){switch(e.type){case"pointerdown":lt(this,vn,ir(e));break;case"pointermove":if(!ve(this,vn))return;const{x:t,y:n}=ir(e),r={x:t-ve(this,vn).x,y:n-ve(this,vn).y},{tolerance:i}=this.options;if(i&&Bo(r,i)){this.abort();return}Bo(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,Gx=class extends Wu{constructor(){super(...arguments),ze(this,Hn),ze(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(!ve(this,xn))return;const{x:t,y:n}=ir(e),r={x:t-ve(this,xn).x,y:n-ve(this,xn).y};Bo(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ve(this,Hn)&&(clearTimeout(ve(this,Hn)),lt(this,xn,void 0),lt(this,Hn,void 0))}};Hn=new WeakMap;xn=new WeakMap;var Yn=class{};Yn.Delay=Gx;Yn.Distance=Kx;var sa=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})]:ix(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=jv(r);return i===t.element?!1:!!i}}),Un,Ss=class extends rr{constructor(e,t){super(e),this.manager=e,this.options=t,ze(this,Un,new Set),this.listeners=new eh,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=sa.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=>{rx(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&&(Zx(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||Yx(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=sa.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 gv(f,g=>this.handleStart(t,g));c.signal.onabort=()=>this.handleCancel(e),c.onEvent(e),this.controller=c;const l=Uo(),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:Pi,options:{capture:!0}}]),p=()=>{u(),this.initialCoordinates=void 0};ve(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:Pi,options:{passive:!1}},{type:"click",listener:Pi},{type:"contextmenu",listener:Pi},{type:"keydown",listener:this.handleKeyDown}]);ve(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},ve(this,Un).forEach(t=>t()),ve(this,Un).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Un=new WeakMap;Ss.configure=yi(Ss);Ss.defaults=sa;var oa=Ss;function Yx(e){return"sensor"in e}function Pi(e){e.preventDefault()}function Xx(){}var bc=new WeakSet;function Zx(e){!e||bc.has(e)||(e.addEventListener("touchmove",Xx,{capture:!1,passive:!1}),bc.add(e))}var Jn={modifiers:[],plugins:[kx,Ah,$x,xl,Vx],sensors:[oa,Ph]},Rh=class extends bv{constructor(e={}){const t=At(e.plugins,Jn.plugins),n=At(e.sensors,Jn.sensors),r=At(e.modifiers,Jn.modifiers);super(pl(hi({},e),{plugins:[Hx,$i,zs,...t],sensors:n,modifiers:r}))}},Ih,Nh,aa,en,kl,Sl,Fs=class extends(aa=Wt,Nh=[se],Ih=[se],aa){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=fh(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),ze(this,kl,Ue(en,8,this)),Ue(en,11,this),ze(this,Sl,Ue(en,12,this)),Ue(en,15,this),this.element=r,this.handle=s}};en=yr(aa);kl=new WeakMap;Sl=new WeakMap;jt(en,4,"handle",Nh,Fs,kl);jt(en,4,"element",Ih,Fs,Sl);On(en,Fs);var Wh,Lh,la,tn,$l,ro,zh,Fh,ri,jl,Bs=class extends(la=Lt,Lh=[se],Wh=[se],la){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=fh(n,["element","effects"]);const{collisionDetector:o=ch}=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=ie(()=>this.shape);return u&&p?.equals(u)?p:(this.shape=u,u)},d=dr(!1);super(pl(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 Iv(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),ze(this,ri),ze(this,$l,Ue(tn,8,this)),Ue(tn,11,this),ze(this,jl,Ue(tn,12,this)),Ue(tn,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){lt(this,ri,e,Fh)}get element(){var e;return(e=this.proxy)!=null?e:ve(this,ri,zh)}};tn=yr(la);$l=new WeakMap;ri=new WeakSet;jl=new WeakMap;ro=jt(tn,20,"#element",Lh,ri,$l),zh=ro.get,Fh=ro.set;jt(tn,4,"proxy",Wh,Bs,jl);On(tn,Bs);function Qx(e){return e!=null&&typeof e=="object"&&"current"in e}function er(e){var t;if(e!=null)return Qx(e)?(t=e.current)!=null?t:void 0:e}var Jx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",wr=Jx?S.useLayoutEffect:S.useEffect;function eb(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Bh(e,t){const n=S.useRef(new Map),r=eb();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=ie(()=>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(()=>Rm.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 tb(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 Zi(e,t){const n=S.useRef(er(e));wr(()=>{const r=er(e);r!==n.current&&(n.current=r,t(r))})}var nb=Object.defineProperty,rb=Object.defineProperties,ib=Object.getOwnPropertyDescriptors,$s=Object.getOwnPropertySymbols,_h=Object.prototype.hasOwnProperty,qh=Object.prototype.propertyIsEnumerable,yc=(e,t,n)=>t in e?nb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sb=(e,t)=>{for(var n in t||(t={}))_h.call(t,n)&&yc(e,n,t[n]);if($s)for(var n of $s(t))qh.call(t,n)&&yc(e,n,t[n]);return e},ob=(e,t)=>rb(e,ib(t)),ab=(e,t)=>{var n={};for(var r in e)_h.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&&qh.call(e,r)&&(n[r]=e[r]);return n},lb=new Rh,Hh=S.createContext(lb),cb=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 db(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:d}=t,f=ab(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:l,modifiers:u,sensors:p}=f,g=At(l,Jn.plugins),v=At(p,Jn.sensors),b=At(u,Jn.modifiers),w=In(i),h=In(s),x=In(a),y=In(o),k=In(d),C=In(r),$=ub(()=>{var T;return(T=f.manager)!=null?T:new Rh(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",W=>{const A=w.current;A&&j(()=>A(W,$))}),M.addEventListener("dragstart",W=>{var A;return(A=h.current)==null?void 0:A.call(h,W,$)}),M.addEventListener("dragover",W=>{const A=x.current;A&&j(()=>A(W,$))}),M.addEventListener("dragmove",W=>{const A=y.current;A&&j(()=>A(W,$))}),M.addEventListener("dragend",W=>{const A=k.current;A&&j(()=>A(W,$))}),M.addEventListener("collision",W=>{var A;return(A=C.current)==null?void 0:A.call(C,W,$)})];return()=>I.forEach(W=>W())},[$]),Ce(g,()=>$&&($.plugins=g),...io),Ce(v,()=>$&&($.sensors=v),...io),Ce(b,()=>$&&($.modifiers=b),...io),m.jsxs(Hh.Provider,{value:$,children:[m.jsx(cb,{ref:c,children:n}),n]})}function ub(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 Uh(){return S.useContext(Hh)}function Vh(e){var t;const n=(t=Uh())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),wr(r.register,[n,r]),r}var hb=Object.create,Kh=Object.defineProperty,fb=Object.getOwnPropertyDescriptor,Gh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),_s=e=>{throw TypeError(e)},pb=(e,t,n)=>t in e?Kh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mb=e=>{var t;return[,,,hb((t=e?.[Gh("metadata")])!=null?t:null)]},Yh=["class","method","getter","setter","accessor","field","value","get","set"],Xh=e=>e!==void 0&&typeof e!="function"?_s("Function expected"):e,gb=(e,t,n,r,i)=>({kind:Yh[e],name:t,metadata:r,addInitializer:s=>n._?_s("Already initialized"):i.push(Xh(s||null))}),vb=(e,t)=>pb(t,Gh("metadata"),e[3]),xb=(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},Zh=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=Yh[c+5],v=e[p]||(e[p]=[]),b=(i=i.prototype,fb(i,n)),w=r.length-1;w>=0;w--)d=gb(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,Xh(o)&&(b[g]=o);return b&&Kh(i,n,b),i},Qh=(e,t,n)=>t.has(e)||_s("Cannot "+n),bb=(e,t,n)=>(Qh(e,t,"read from private field"),t.get(e)),yb=(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),wb=(e,t,n,r)=>(Qh(e,t,"write to private field"),t.set(e,n),n),yn=class ca{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ca(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 ca(t,n)}},Jh,ef,da,Qi,ji,Ml=class extends(da=Cn,ef=[We],Jh=[We],da){constructor(e){const t=yn.from(e);super(t,(n,r)=>yn.equals(n,r)),xb(ji,5,this),yb(this,Qi,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-bb(this,Qi),o=a=>Math.round(a/s*100);Oe(()=>{wb(this,Qi,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=mb(da);Qi=new WeakMap;Zh(ji,2,"delta",ef,Ml);Zh(ji,2,"direction",Jh,Ml);vb(ji,Ml);var tf=(e=>(e.Horizontal="x",e.Vertical="y",e))(tf||{});Object.values(tf);var kb=({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},Sb=({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=kb(e))!=null?t:Sb(e)};function jb(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,d=Vh(c=>new Bs(ob(sb({},e),{register:!1,element:er(i)}),c)),f=Bh(d);return Ce(s,()=>d.id=s),Zi(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 nf=(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}}},rf=S.createContext(void 0);function sf(e,t){const n=S.useContext(rf),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 ua({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:i=!1}){const{theme:s}=_e(),[o,a]=S.useState(void 0),d=S.useRef(!1),f=()=>{d.current||o===void 0||(a(void 0),o!==e&&r(o))};sf(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(B,{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}},nf(s)],children:l?t:e})}return m.jsx(yd,{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 Mb=(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}),Eb=(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},of=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),af=e=>`gap.${e}`,Cb=(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:ue(e[o-1]),colspan:t-r}),d&&(r=0),n.push(of(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:ue(i),colspan:t-r}),n};var Tb=Object.create,lf=Object.defineProperty,Ob=Object.defineProperties,Db=Object.getOwnPropertyDescriptor,Ab=Object.getOwnPropertyDescriptors,js=Object.getOwnPropertySymbols,cf=Object.prototype.hasOwnProperty,df=Object.prototype.propertyIsEnumerable,Pb=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Mi=e=>{throw TypeError(e)},ha=(e,t,n)=>t in e?lf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,so=(e,t)=>{for(var n in t||(t={}))cf.call(t,n)&&ha(e,n,t[n]);if(js)for(var n of js(t))df.call(t,n)&&ha(e,n,t[n]);return e},oo=(e,t)=>Ob(e,Ab(t)),Rb=(e,t)=>{var n={};for(var r in e)cf.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&&df.call(e,r)&&(n[r]=e[r]);return n},Ib=e=>{var t;return[,,,Tb((t=void 0)!=null?t:null)]},uf=["class","method","getter","setter","accessor","field","value","get","set"],qr=e=>e!==void 0&&typeof e!="function"?Mi("Function expected"):e,Nb=(e,t,n,r,i)=>({kind:uf[e],name:t,metadata:r,addInitializer:s=>n._?Mi("Already initialized"):i.push(qr(s||null))}),Wb=(e,t)=>ha(t,Pb("metadata"),e[3]),Ri=(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},hf=(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=uf[l+5],b=e[g-1]=[],w=e[g]||(e[g]=[]),h=(i=i.prototype,Db({get[n](){return Hr(this,s)},set[n](y){return bn(this,s,y)}},n)),x=r.length-1;x>=0;x--)f=Nb(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&&lf(i,n,h),i},ff=(e,t,n)=>t.has(e)||Mi("Cannot "+n),Hr=(e,t,n)=>(ff(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)=>(ff(e,t,"write to private field"),t.set(e,n),n);function wn(e){return e instanceof Tl||e instanceof vf}var Ii=10,Lb=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=zb(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,ax);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,W=I?M:C?.element;if(!W)return;ah(W);const A=new It(W);if(!A)return;const z=Nt.delta(A,Nt.from($.current.boundingRectangle),k.alignment);o.move({by:z}),I?o.setDropTarget(k.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function zb(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 Fb=Object.defineProperty,Bb=Object.defineProperties,_b=Object.getOwnPropertyDescriptors,wc=Object.getOwnPropertySymbols,qb=Object.prototype.hasOwnProperty,Hb=Object.prototype.propertyIsEnumerable,kc=(e,t,n)=>t in e?Fb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nn=(e,t)=>{for(var n in t||(t={}))qb.call(t,n)&&kc(e,n,t[n]);if(wc)for(var n of wc(t))Hb.call(t,n)&&kc(e,n,t[n]);return e},Wn=(e,t)=>Bb(e,_b(t));function Ub(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 Vb(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 Kb(e,t){return Vb(e,t,Ub)}function Sc(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function $c(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 jc="__default__",Gb=class extends it{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof Tl){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=Sc(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($c(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:jc,k=(g=a.sortable.group)!=null?g:jc,C={[y]:h,[k]:x},$=Kb(C,r);if(C===$)return;const T=$[k].indexOf(o.sortable),j=$[k].indexOf(a.sortable);i.collisionObserver.disable(),Mc(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=Sc(a),f=a.get(o.sortable.initialGroup);f&&i.renderer.rendering.then(()=>{const c=t();if($c(d,a,c))return;const l=Wi(f),u=Wi(f,Xb),p=o.sortable.element,g=u.indexOf(o.sortable),v=l[g],b=v?.element;!v||!b||!p||(Mc(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 Mc(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function Yb(e,t){return e.index-t.index}function Xb(e,t){return e.initialIndex-t.initialIndex}function Wi(e,t=Yb){return Array.from(e).sort(t)}var Ec=[Lb,Gb],pf={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Cc(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 Li=new Hg,mf,gf,nn,El,Ur,Vr,Cl,Vn;gf=[se],mf=[se];var qs=class{constructor(e,t){Cr(this,El,Ri(nn,8,this)),Ri(nn,11,this),Cr(this,Ur),Cr(this,Vr),Cr(this,Cl,Ri(nn,12,this)),Ri(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=pf,plugins:c}=n,l=Rb(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=At(c,Ec),p=Cc(i);this.droppable=new Tl(oo(so({},l),{disabled:p.droppable}),t,this),this.draggable=new vf(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)&&Li.clear(this.manager),w?.dragging&&Li.set(this.manager,this.id,ie(()=>({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(xl))==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=Li.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Li.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ie(()=>{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}=zt(i),d=uc(i,a,!1),f=uc(i,a);if(o.x||o.y){const c=dl(bt(i))?oo(so({},t),{duration:0}):t;lh({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=Vo.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=At(e,Ec)}set disabled(e){const t=Cc(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??ch}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=Ib();El=new WeakMap;Ur=new WeakMap;Vr=new WeakMap;Cl=new WeakMap;Vn=new WeakMap;hf(nn,4,"index",gf,qs,El);hf(nn,4,"group",mf,qs,Cl);Wb(nn,qs);var vf=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}},Tl=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}},Zb=Object.defineProperty,Qb=Object.defineProperties,Jb=Object.getOwnPropertyDescriptors,Tc=Object.getOwnPropertySymbols,ey=Object.prototype.hasOwnProperty,ty=Object.prototype.propertyIsEnumerable,Oc=(e,t,n)=>t in e?Zb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lo=(e,t)=>{for(var n in t||(t={}))ey.call(t,n)&&Oc(e,n,t[n]);if(Tc)for(var n of Tc(t))ty.call(t,n)&&Oc(e,n,t[n]);return e},ny=(e,t)=>Qb(e,Jb(t));function ry(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({},pf),e.transition),w=Vh(x=>new qs(ny(lo({},e),{transition:b,register:!1,handle:er(a),element:er(o),target:er(p)}),x)),h=Bh(w,iy);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()},tb),Zi(a,x=>w.handle=x),Zi(o,x=>w.element=x),Zi(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 iy(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const fa="tile",xf="gap",sy=[oa.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${bf}], ${oy}`)!==null||(oa.defaults.preventActivation?.(e,t)??!1)}),Ph],bf="data-no-drag",oy=".malloy-render, .malloy-table",ay=e=>[...e,xl.configure({feedback:"clone"})];function ly({id:e,index:t,disabled:n=!1,children:r}){const{ref:i,handleRef:s,isDragSource:o}=ry({id:e,index:t,disabled:n,type:fa,accept:fa,collisionDetector:hl,plugins:ay});return m.jsx(m.Fragment,{children:r({ref:i,handleRef:s,isDragSource:o})})}function cy({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=jb({id:e,type:xf,accept:fa,collisionDetector:hl,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:i})})}function dy({active:e}){const t=Uh();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 yf=e=>e.ok===!1,Be=(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=>Be(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Be(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Be(e,"VIEW","subQueryDefList"),defDimension:e=>Be(e,"defList","DIMENSION"),exploreProperties:e=>Be(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Be(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Be(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Be(e,"WHERE","filterClauseList"),givenDef:e=>Be(e,"givenNameDef"),givenStatement:e=>Be(e,"GIVEN","givenDefList"),importStatement:e=>Be(e,"IMPORT","importURL"),vArrow:e=>Be(e,"ARROW","vExpr","segExpr"),segRefine:e=>Be(e,"PLUS","segExpr"),segOps:e=>Be(e,"queryProperties"),segField:e=>Be(e,"fieldPath")&&!Be(e,"segExpr"),segParen:e=>Be(e,"OPAREN","CPAREN","vExpr"),compare:e=>Be(e,"fieldExpr","compareOp"),givenRef:e=>Be(e,"GIVEN_REF")};function uy(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 hy(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
+
`&&t.push(n+1);return t}function wf(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 kf{constructor(t){this.text=t,this.map=uy(t),this.lineStarts=hy(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 fy=e=>Be(e,"OCURLY","CCURLY");function gi(e,t){const n=[],r=i=>{if(kr(i)){if(t(i)){n.push(i);return}if(!fy(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 py(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 Sf(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:py(e,s)})}return{...n,clauses:i}}function pa(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=Sf(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 Ol(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 my(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&&pa(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&&pa(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 gy(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:Ol(e,i,a?.start??f.start),siblings:o.length,body:my(e,u)})}}return n}function vy(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:Ol(e,i,o?.start??d.start)})}}return n}function xy(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&&pa(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=Sf(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?gy(e,c):[],dimensions:c?vy(e,c):[],wheres:p})}return n}function by(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:Ol(e,d,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function yy(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 $f(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 kf(e),d=wy(a,s);a.commentLines=d.lines;const f=e.split(`
|
|
70
70
|
`),c=u=>d.lines.has(u);a.proseLines=km(f,c),a.blocks=Sm(f,c).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=xy(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:yy(a,i),sources:l,givens:by(a,i),textBlocks:Sy(a,s),modelNotes:wf(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=>ky(a,d.lines,u)}}}async function Dl(e,t){const{MalloyTranslator:n}=await Vp(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function wy(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
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 ky(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 Sy(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=Dm(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
72
|
`]:[];o.push({...d.name===void 0?{}:{name:d.name},route:d.route,body:[...g,...f].join("").replace(/\r\n?/g,`
|
|
73
73
|
`).replace(/\n$/,""),span:{start:e.lineStarts[u],end:p},line:u}),a=c}return o}function jf(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 Mf(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')r=jf(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=jf(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 jy(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
74
|
`)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const i=e.indexOf(`
|
|
75
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 My(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=jy(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 Cf(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=My(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const Dc=(e,t)=>{try{return e.text(t)}catch{return}},Cy=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Ey=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\`.`,Ty=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=[…]\`.`,Oy="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 Ef(e,t){const n=e.filter(Cy).filter(c=>!c.includes("@env.")).map(gd),{tag:r,errors:i}=n.length>0?Cf(t,n):{tag:void 0,errors:[]},s=r?.tag("artifact");if(!s)return e.some(Kp)?{status:"unparsed",errors:i}:{status:"none"};const o=Dc(s,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=Dc(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 Ow(e){const{parseAnnotation:t}=await ld();let n=[];try{const r=(await Dl(e,"file://report.malloy")).parse?.root;r&&kr(r)&&typeof r.getChild=="function"&&(n=wf(new kf(e),r))}catch{n=[]}return Ef(n,t)}const ma=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 Ac(e){const t=tr(e),n=$m(t),r=t.map(Ta).filter(Boolean).at(-1),i=r?{color:r}:{};return n===void 0?i:n==="custom"?{chart:n,chartLines:jm(t),...i}:{chart:n,...i}}function Pc(e,t){return tr(e).some(n=>Ta(n)===void 0&&t([n]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Dy(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:Mm(i),given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function Ay(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(),...Py(n(tr(Sr(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function Py(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 Rc(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 Ry=/^"((?:[^"\\]|\\.)+)"\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 Iy=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,Ny=/^[A-Za-z_][A-Za-z0-9_]*$/;function Wy(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 Ic(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 Nc(e){const{colspan:t,break:n,...r}=e;return r}async function ga(e,t,n=!1){try{return await Ly(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 Ly(e){const{parseAnnotation:t}=await ld(),n=_p(e),r=await $f(e);if(yf(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,s=md(n).text,o=Ef(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:Ey(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?Ty(o.unknownLayout):Oy};const a=o.layout,d=Ma(n);if(d===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!qp(d.text))return{ok:!1,reason:Hp,line:d.from+1};const{tag:f,errors:c}=Cf(t,[gd(d.text)]),l=f?.tag("artifact"),u=Mf(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 W=I.textArray("to")??[I.text("to")??""];v.push({source:$.name,name:M.name,expression:M.expression,to:W.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=Ic(t(tr(Wy(i,n,$))).tag);return{name:$,declaration:{kind:"query"},...Nc(j),...Tr({colspan:j.colspan,break:j.break},T)}};for(const{text:$}of u.entries){const T=Ry.exec($),j=T?void 0:Iy.exec($)?.[1];if(j!==void 0){const C=t([`# ${$}`]).tag?.tag(j),O=C?.text("kind");if(O===void 0||O==="query"){w.push(h(j,co(C)));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(N=>$e(N)&&N.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(N=>N.name===j)?.body??"",...Tr({},co(C))});continue}const M=T?.[1]??$,I=co(T?.[2]?t([`# tile ${T[2]}`]).tag?.tag("tile")??void 0:void 0);if(Ny.test(M.trim())){w.push(h(M.trim(),I));continue}const W=T?Up(M):void 0;if(!W)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:A,view:z}=W,_=b.get(A)?.get(z);if(_===void 0){w.push({name:z,source:A,declaration:{kind:"inherited"},...Tr({},I)});continue}const q=t(tr(_.tags)).tag,P=_.body.kind==="reference"?{kind:"reference",from:_.body.from}:_.body.kind==="inline"?{kind:"inline"}:void 0;if(P===void 0){w.push({name:z,source:A,declaration:{kind:"opaque",why:_.body.kind==="unsupported"?_.body.why:"unreadable"},...Nc(Ic(q)),...Tr(Rc(q),I),...Ac(_.tags),...Pc(_.tags,t)});continue}const F=Dy(_.body.kind==="reference"?_.body.refinement:_.body.kind==="inline"?_.body.stage:void 0);w.push({name:z,source:A,declaration:P,...F?{filters:F}:{},...q?.text("label")?{label:q.text("label")}:{},...q?.text("subtitle")?{subtitle:q.text("subtitle")}:{},...Tr(Rc(q),I),...Ac(_.tags),...Pc(_.tags,t),...q?.has("borderless")?{borderless:!0}:{}})}const x=Ay(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 E=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}:{},...E===void 0?{}:{columns:E},...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 va=e=>e.ok===!1;async function Wc(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 Se(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 Tf(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function zy(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
-
`&&t.push(n+1);return t}function Fy(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 Of=e=>e==="none"||Os(e)?e:void 0;function Df(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${Dt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${Dt(e.subtitle)}`);const r=t?Of(e.chart):void 0;return r!==void 0&&n.push(
|
|
76
|
+
`)return i}return e.length}return t}function My(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=jy(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 Ef(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=My(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const Dc=(e,t)=>{try{return e.text(t)}catch{return}},Ey=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Cy=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\`.`,Ty=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=[…]\`.`,Oy="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 Cf(e,t){const n=e.filter(Ey).filter(c=>!c.includes("@env.")).map(gd),{tag:r,errors:i}=n.length>0?Ef(t,n):{tag:void 0,errors:[]},s=r?.tag("artifact");if(!s)return e.some(Kp)?{status:"unparsed",errors:i}:{status:"none"};const o=Dc(s,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=Dc(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 Ow(e){const{parseAnnotation:t}=await ld();let n=[];try{const r=(await Dl(e,"file://report.malloy")).parse?.root;r&&kr(r)&&typeof r.getChild=="function"&&(n=wf(new kf(e),r))}catch{n=[]}return Cf(n,t)}const ma=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 Ac(e){const t=tr(e),n=$m(t),r=t.map(Ta).filter(Boolean).at(-1),i=r?{color:r}:{};return n===void 0?i:n==="custom"?{chart:n,chartLines:jm(t),...i}:{chart:n,...i}}function Pc(e,t){return tr(e).some(n=>Ta(n)===void 0&&t([n]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Dy(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:Mm(i),given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function Ay(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(),...Py(n(tr(Sr(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function Py(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 Rc(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 Ry=/^"((?:[^"\\]|\\.)+)"\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 Iy=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,Ny=/^[A-Za-z_][A-Za-z0-9_]*$/;function Wy(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 Ic(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 Nc(e){const{colspan:t,break:n,...r}=e;return r}async function ga(e,t,n=!1){try{return await Ly(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 Ly(e){const{parseAnnotation:t}=await ld(),n=_p(e),r=await $f(e);if(yf(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,s=md(n).text,o=Cf(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:Cy(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?Ty(o.unknownLayout):Oy};const a=o.layout,d=Ma(n);if(d===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!qp(d.text))return{ok:!1,reason:Hp,line:d.from+1};const{tag:f,errors:c}=Ef(t,[gd(d.text)]),l=f?.tag("artifact"),u=Mf(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 W=I.textArray("to")??[I.text("to")??""];v.push({source:$.name,name:M.name,expression:M.expression,to:W.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=Ic(t(tr(Wy(i,n,$))).tag);return{name:$,declaration:{kind:"query"},...Nc(j),...Tr({colspan:j.colspan,break:j.break},T)}};for(const{text:$}of u.entries){const T=Ry.exec($),j=T?void 0:Iy.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(N=>$e(N)&&N.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(N=>N.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(Ny.test(M.trim())){w.push(h(M.trim(),I));continue}const W=T?Up(M):void 0;if(!W)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:A,view:z}=W,_=b.get(A)?.get(z);if(_===void 0){w.push({name:z,source:A,declaration:{kind:"inherited"},...Tr({},I)});continue}const q=t(tr(_.tags)).tag,P=_.body.kind==="reference"?{kind:"reference",from:_.body.from}:_.body.kind==="inline"?{kind:"inline"}:void 0;if(P===void 0){w.push({name:z,source:A,declaration:{kind:"opaque",why:_.body.kind==="unsupported"?_.body.why:"unreadable"},...Nc(Ic(q)),...Tr(Rc(q),I),...Ac(_.tags),...Pc(_.tags,t)});continue}const F=Dy(_.body.kind==="reference"?_.body.refinement:_.body.kind==="inline"?_.body.stage:void 0);w.push({name:z,source:A,declaration:P,...F?{filters:F}:{},...q?.text("label")?{label:q.text("label")}:{},...q?.text("subtitle")?{subtitle:q.text("subtitle")}:{},...Tr(Rc(q),I),...Ac(_.tags),...Pc(_.tags,t),...q?.has("borderless")?{borderless:!0}:{}})}const x=Ay(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 va=e=>e.ok===!1;async function Wc(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 Se(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 Tf(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function zy(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
+
`&&t.push(n+1);return t}function Fy(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 Of=e=>e==="none"||Os(e)?e:void 0;function Df(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${Dt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${Dt(e.subtitle)}`);const r=t?Of(e.chart):void 0;return r!==void 0&&n.push(Zn(r,e.chartCarried)),e.color!==void 0&&n.push(wd(e.color)),n}const Af="theme.palette.series";function Ji(e){return Ta(e)!==void 0?Af:/^#\s*([a-z_]+)/.exec(e)?.[1]}const By=new Set(["colspan","break","borderless","label","subtitle",Af]),_y=new Set(["label","description","control","suggest","range_min","range_max"]);function Lc(e){const t=[];if(e.label!==void 0&&t.push(`label=${Dt(e.label)}`),e.description!==void 0&&t.push(`description=${Dt(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=${Dt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${Dt(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 zc=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function qy(e,t,n){const r=e.sources.find(i=>i.name===t)?.views.find(i=>i.name===n);return r?r.line:-1}function Fc(e){const t=n=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(n)?n:Dt(n);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(Dt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ms=e=>`${e.source}.${e.name}`,Dt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,xa=e=>$e(e)?Se(["text",e.name]):Se([e.name,e.source,e.declaration]),ct=xa,Bc=e=>Se(e.tiles.map(ct));function Hy(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||Bc(e)!==Bc(t);for(const u of o)if(oe(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=>oe(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 Uy=new Set(["colspan","break"]),ba=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break||e.rowspan!==t.rowspan||e.row!==t.row||e.col!==t.col,_c=e=>{const{colspan:t,break:n,rowspan:r,row:i,col:s,...o}=e;return o},Vy=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 Pf(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=ya(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function qc(e,t){const n=Vy(e);if(t===void 0){const c=$e(e)?e.name:`"${vt(e)}"`,l=[...$e(e)?["kind=text"]:[],...n];return l.length>0?`${c} { ${l.join(" ")} }`:c}const r=Pf(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 Ky(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&&ba(x,h)});if(!s&&!c)return;const l=Ma(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,p=Mf(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(kd(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(Pf(h))?`text.${y}`:`query.${y}`,h)}const v=i.tiles.map(h=>{const x=!o.has(ct(h)),y=g.get($e(h)?`text.${h.name}`:h.declaration.kind==="query"?`query.${h.name}`:`${h.source}->${h.name}`);if(y===void 0)return x?qc(h):void 0;const k=f.get(ct(h));return k!==void 0&&!ba(k,h)?y:qc(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=[${Gy(u,p,v)}]${u.slice(p.close+1)}`;w!==u&&d.push({...Rf(n,l),text:`${w}
|
|
78
78
|
`})}function Rf(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Gy(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
79
|
`)),d=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
|
|
80
80
|
`)?a:" "}`;return`${s}${n.join(d)}${o}`}function Yy(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=ya(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=ya(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 ya(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 Xy(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||Se(r.startingGivens)!==Se(i.startingGivens)){const o=Ma(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=Rf(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
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
|
|
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
83
|
${k.source}[ \\t]*(?=
|
|
84
|
-
)`);v=v.replace(o.block&&
|
|
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?Dt(i.title):void 0),r.autorun!==i.autorun&&h("autorun",i.autorun===void 0?void 0:String(i.autorun)),Se(r.startingGivens)!==Se(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}=${Dt(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=Yy(f),i.columns!==void 0&&(f=`${f.trimEnd()} dashboard { columns=${i.columns} }`)),d?d.text=`${f}
|
|
85
85
|
`:s.push({...a,text:`${f}
|
|
86
86
|
`})}if(r.description!==i.description){const{read:o,blankAbove:a,below:d,belowBlock:f,inBlock:c}=md(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=Tf(i.description??"").split(`
|
|
87
87
|
`).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
|
|
88
88
|
`),u=o.length>0&&o[0]<Wl(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
89
|
`});else if(i.description!==void 0){const v=n(Wl(t)).start;s.push({start:v,end:v,text:`${l}
|
|
90
|
-
`})}}}function
|
|
91
|
-
`).trim();o.push({start:n(b.line).start,end:n(y).end,text:(
|
|
90
|
+
`})}}}function Zy(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&&Se(v)===Se(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&&_y.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 A=b.line;A<=y;A++)l.add(A);const T=Math.min(b.line,...x),j=b.blockHeader??T,M=(t[y+1]??"x").trim()==="",I=j===0||t[j-1].trim()==="",W=b.blockHeader===void 0||![...c.values()].some(A=>A.blockHeader===b.blockHeader&&A.line>b.line&&f.has([...c.entries()].find(([,z])=>z===A)?.[0]??""));M&&I&&W&&!l.has(y+1)&&(o.push({...n(y+1),text:""}),l.add(y+1));continue}const k=r(b.line),C=Lc(v),$=v.type!==g.type||v.default!==g.default?b.blockHeader===void 0?zc(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
92
|
`:"")+`${k}${$}
|
|
93
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=Lc(h);return(x?`${x}
|
|
94
94
|
`:"")+`${zc(h)}
|
|
95
95
|
`}).join(`
|
|
96
96
|
`),w=v>=0?n(v).end:n(0).end;o.push({start:w,end:w,text:`
|
|
97
97
|
${b}`}),t.some(h=>h.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
|
|
98
|
-
`})}}const Hc=(e,t)=>`import { ${e.join(", ")} } from ${Dt(t)}`;function
|
|
98
|
+
`})}}const Hc=(e,t)=>`import { ${e.join(", ")} } from ${Dt(t)}`;function Qy(e){const{parsed:t,current:n,next:r,edits:i,wholeLine:s}=e,o=l=>Se(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(Se(n.imports)===Se(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(oe).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(Se(g)===Se(u.names))continue;const b=g.length===0?Al(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?"":Hc(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=>`${Hc(p.names,p.from)}
|
|
99
99
|
`).join("")})}}function Jy(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&&Se(l)===Se(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}${Fc(u)}
|
|
100
100
|
`});else{const h=n(g.line).start;o.push({start:h,end:h,text:`${w}${Fc(u)}
|
|
101
|
-
`})}}}function e0(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if($e(o)||cr(o))continue;const a=If(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({...Al(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 t0(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($e(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: ${
|
|
101
|
+
`})}}}function e0(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if($e(o)||cr(o))continue;const a=If(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({...Al(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 t0(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($e(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: ${Ca(b.field)} ${b.op??"~"} $${b.given}`).join(", ");return[...Df(u).map(b=>`${p}${b}`),`${p}view: ${u.name} is ${g}${v?` + { ${v} }`:""}`].join(`
|
|
102
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
103
|
`)+p.map(y=>c(y,w)).join(`
|
|
104
104
|
|
|
@@ -111,10 +111,10 @@ source: ${g.name} is ${g.base} extend {
|
|
|
111
111
|
}
|
|
112
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
113
|
`)?`
|
|
114
|
-
`:"";a.push({start:w,end:w,text:h+v}),l=b}}function n0(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||$e(c)||$e(l))continue;const u=ba(l,c),p=Se(_c(
|
|
115
|
-
`}),
|
|
116
|
-
`})}const $=w.filter(I=>!x.has(Ji(I)??I));if(k&&y!==void 0&&!
|
|
117
|
-
`).join("")})}if(Se(l.filters)===Se(c.filters))continue;const T=If(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=c0(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=Nf(c.filters,T.body.stage);if(j)return Wf(c.name,j.given);const M=Lf(e,c,T.body.stage);if(M)return M}}const Uc=e=>e.chart==="default"?void 0:e.chart,
|
|
114
|
+
`:"";a.push({start:w,end:w,text:h+v}),l=b}}function n0(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||$e(c)||$e(l))continue;const u=ba(l,c),p=Se(_c(Es(l)))!==Se(_c(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=qy(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=Df(c,!1),h=new Map(w.map(I=>[Ji(I)??I,I])),x=new Set,y=Of(c.chart),k=Uc(l)!==Uc(c);if(k){const I=v.filter(z=>Ll(z.text)),W=v.filter(z=>Vs(z.text)),A=l.chart==="custom"?v.filter(z=>Vs(z.text)||Ll(z.text)):I.length>0?I:W.length>1?W:[];if(A.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${A.map(z=>z.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!==Zn(y,c.chartCarried)&&a.push({...r(I.line),text:`${b}${Zn(y,c.chartCarried)}
|
|
115
|
+
`}),C=!0;continue}const W=Ji(I.text);if(W===void 0||!By.has(W))continue;if(Uy.has(W)){u&&a.push({...r(I.line),text:""});continue}const A=h.get(W);if(A===void 0){a.push({...r(I.line),text:""});continue}x.add(W),A!==I.text&&a.push({...r(I.line),text:`${b}${A}
|
|
116
|
+
`})}const $=w.filter(I=>!x.has(Ji(I)??I));if(k&&y!==void 0&&!C&&$.push(Zn(y,c.chartCarried)),$.length>0){const I=n[g];a.push({start:I,end:I,text:$.map(W=>`${b}${W}
|
|
117
|
+
`).join("")})}if(Se(l.filters)===Se(c.filters))continue;const T=If(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=c0(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=Nf(c.filters,T.body.stage);if(j)return Wf(c.name,j.given);const M=Lf(e,c,T.body.stage);if(M)return M}}const Uc=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 r0(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 oe(r)&&r.chart===void 0&&i&&oe(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 i0(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&&!kd(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
118
|
${e.markdown===""?"":`${e.markdown}
|
|
119
119
|
`}|##
|
|
120
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($e).map(p=>[p.name,p])),f=s.tiles.filter($e),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:`
|
|
@@ -133,12 +133,12 @@ ${u.join(`
|
|
|
133
133
|
`:`
|
|
134
134
|
|
|
135
135
|
`;a.push({start:b,end:b,text:w+u.join(`
|
|
136
|
-
`)})}}const zi=(e,t=wo)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function o0(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($e(o)){const l=i0(o,a&&$e(a)?a:void 0,r);if(l)return l;continue}const d=a&&oe(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=zi(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=Pn(`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=zi(a);if(d)return d}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=Pn("description line",o);if(a)return a}if(t.title!==e.title){const o=Pn("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=zi(o.name,Sd);if(f)return f}const d=o.suggest?.source;if(d!==void 0&&d!==a?.suggest?.source){const f=zi(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=Pn(`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=Pn(`given ${f}`,c);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const d=Pn(`starting value for ${o}`,a);if(d)return d}}const Vt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function If(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Nf(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 Wf(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: ${
|
|
136
|
+
`)})}}const zi=(e,t=wo)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function o0(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($e(o)){const l=i0(o,a&&$e(a)?a:void 0,r);if(l)return l;continue}const d=a&&oe(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=zi(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=Pn(`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=zi(a);if(d)return d}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=Pn("description line",o);if(a)return a}if(t.title!==e.title){const o=Pn("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=zi(o.name,Sd);if(f)return f}const d=o.suggest?.source;if(d!==void 0&&d!==a?.suggest?.source){const f=zi(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=Pn(`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=Pn(`given ${f}`,c);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const d=Pn(`starting value for ${o}`,a);if(d)return d}}const Vt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function If(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Nf(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 Wf(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: ${Ca(e.field)} ${e.op??"~"} $${e.given}`;function Vc(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 a0(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 l0(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 Al(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
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 Lf(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=Al(r,u.span),b=a0(r,u.span,v);if(b)return Vc(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=l0(u.clauses,w),k=r.commentIn(y);if(k)return Vc(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
138
|
${n.indent}${ts(u)}`).join("");i.push({start:f,end:f,text:l})}function c0(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:s}=n.body,o=Nf(t.filters,s);if(o)return Wf(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 Lf(e,t,s)}async function d0(e,t,n={}){if(!(e.includes(`\r
|
|
139
139
|
`)&&!/(?<!\r)\n/.test(e)))return Kc(e,t,n);const r=await Kc(e.replace(/\r\n/g,`
|
|
140
140
|
`),t,n);return va(r)?r:{...r,source:r.source.replace(/\n/g,`\r
|
|
141
141
|
`)}}async function Kc(e,t,n){const r=await ga(e);if(ma(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const i=r.document,s=r0(i,t),o=Hy(i,s,n.visibleSources);if("reason"in o)return o;const a=o0(i,s);if(a)return{ok:!1,reason:a};const d=await $f(e);if(yf(d))return{ok:!1,reason:`Cannot edit a file that will not open: ${d.reason}`};const f=e.split(`
|
|
142
|
-
`),c=zy(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[Ky,Xy,Zy,Qy,Jy,e0,t0,n0,s0]){const x=h(g);if(x)return x}const v=h=>{const{drills:x,localGivens:y,description:k,...E}=h,$=h.tiles.map(T=>{if($e(T))return T;if(T.filters?.length)return Cs(T);const{filters:j,...M}=T;return Cs(M)});return{...E,...k===void 0?{}:{description:Tf(k)},tiles:$,...x?.length?{drills:[...x].sort((T,j)=>Ms(T).localeCompare(Ms(j)))}:{},...y?.length?{localGivens:y}:{}}};if(p.length===0)return Se(v(i))!==Se(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=Fy(e,p);if((await Wc(e)).length===0){const h=await Wc(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 ga(b);return ma(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:Se(v(w.document))!==Se(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 zf({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=_e(),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}=Id(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;sf(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(B,{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},nf(i,"prose")],children:[e.trim()?m.jsx(cm,{variant:r,children:e}):m.jsx(pe,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),y&&m.jsx(pe,{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(B,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx(yd,{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:dm,"& textarea":{p:0}}}),h!==void 0&&m.jsx(pe,{variant:"caption",color:"error",role:"alert",children:h}),m.jsxs(pe,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",Sn,"↩ done · Esc cancels"]})]})}const u0="Write markdown: # heading, **bold**, - list";function h0({tile:e,sized:t=!1,onChange:n}){const r=m.jsx(ud,{sx:{overflow:"visible"},children:m.jsx(zf,{markdown:e.markdown,placeholder:u0,onCommit:n})});return t?m.jsx(B,{"data-testid":"text-tile-scroller",sx:{minHeight:0,overflow:"auto",p:"4px",m:"-4px"},children:r}):r}var f0=Object.defineProperty,p0=Object.defineProperties,m0=Object.getOwnPropertyDescriptors,Gc=Object.getOwnPropertySymbols,g0=Object.prototype.hasOwnProperty,v0=Object.prototype.propertyIsEnumerable,Yc=(e,t,n)=>t in e?f0(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ln=(e,t)=>{for(var n in t||(t={}))g0.call(t,n)&&Yc(e,n,t[n]);if(Gc)for(var n of Gc(t))v0.call(t,n)&&Yc(e,n,t[n]);return e},zn=(e,t)=>p0(e,m0(t));function x0(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 b0(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 zn(Ln({},e),{[h]:n(e[h],x,k)});const E=e[h][x];return zn(Ln({},e),{[h]:[...e[h].slice(0,x),...e[h].slice(x+1)],[y]:[...e[y].slice(0,k),E,...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 zn(Ln({},e),{[l]:n(e[l],c,s.index)});const E=e[l][c];return zn(Ln({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[k]:[...e[k].slice(0,s.index),E,...e[k].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===p)return zn(Ln({},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 zn(Ln({},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 y0(e,t){return b0(e,t,x0)}function Ff(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 w0({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=>ue(y)===u),g=Ff(l),v=g.get(String(u));if(p<0||!v)return;const b=Cd(e,e.map(y=>g.get(ue(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=Md(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=Nm(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===xf){const{after:v}=u.data,b=p.findIndex(h=>ue(h)===l.id);if(b<0||v===l.id)return;const w=p.filter((h,x)=>x!==b).findIndex(h=>ue(h)===v)+1;g=Cb(p,b,w)}else{const v=p.map(ue),b=y0(v,c);if(b.every((h,x)=>h===v[x]))return;const w=new Map(p.map(h=>[ue(h),h]));g=Mb(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=>ue(w)===c.operation.source?.id);b>=0&&n(b)}}}const k0={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Bf=(e,t)=>t===0?e:Bf(t,e%t);function S0(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Bf(e,t),i=k0[`${e/r}/${t/r}`];return i?`${n} · ${i}`:n}const Xc=ns+pt,_f=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}),Qc=(e,t)=>e.row===t.row&&e.col===t.col&&e.colspan===t.colspan&&e.rowspan===t.rowspan;function qf(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 j0({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(ue)),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===ue(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(_f(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=Ff(v);return Cd(e,e.map(j=>T.get(ue(j))),t,ss(b.width,t))})():[...e],y=rn(x),k=x[p],E=$0(k);!y&&E.rowspan===void 0?d.current=w.height:d.current=void 0;const $=y?{...E,rowspan:ii(k)}:E;f({index:p,edges:g,base:x,placedHere:!!h,placed:y,from:E,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:E}=p,$=p.shape;let{row:T,col:j,colspan:M,rowspan:I}=$;if(p.placed&&j!==void 0&&T!==void 0){const A=p.from,z=A.col??j,_=z+A.colspan-1,q=A.row??T,P=A.rowspan??ii(v),F=q+P-1;if(p.edges.e){const C=Math.round((w+pt)/b);M=Math.min(Math.max(C,z),t)-z+1,j=z}if(p.edges.w){const C=Math.round(w/b)+1;j=Math.min(Math.max(C,1),_),M=_-j+1}if(p.edges.s){const C=p.edges.n?g.top+(q-1)*Xc:y;I=Il(u.clientY-C,E),T=q}if(p.edges.n){const C=Math.round(h/Xc)+1,O=Math.min(E,P);T=Math.max(1,Math.min(Math.max(C,F-Gr+1),F-O+1)),I=F-T+1}}else{if(p.edges.e){const A=Math.round((u.clientX-k+pt)/b);M=Math.min(Math.max(A,1),t)}if(p.edges.s){const A=u.clientY-y,z=Il(A,E),_=l(p);I=_!==void 0&&Math.abs(A-_)<Math.abs(A-dd(z))?void 0:z}}const W={...T!==void 0?{row:T}:{},...j!==void 0?{col:j}:{},colspan:M,rowspan:I};Qc(W,$)||f({...p,shape:W})},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"||Qc(p.shape,p.begun))&&i({index:p.index,edges:p.edges,shape:p.shape,placed:p.placed,...p.placedHere?{placedAll:p.base}:{}}))}}}function M0(e,t){const n=[];return(e.edges.e||e.edges.w)&&n.push(S0(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 C0({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}=_e(),w=b.ui;return m.jsx(ly,{id:ue(e),index:t,disabled:g,children:({ref:h,handleRef:x})=>m.jsxs(B,{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":ue(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",...Hf(b,{selected:n,flash:r,bare:s}),...!s&&{[`& .${em}`]:{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},...Qp,...n&&{[`& .${Jp}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[v,m.jsx(B,{ref:x,"aria-label":`Move ${Mr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(Zp,{label:`Remove ${Mr(e)}`,onRemove:f,...c?{disabledReason:c}:{},inset:s?vd:0}),!$e(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:`${Zc}px`,right:s?0:`${Zc}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(D0,{})}),u&&m.jsx(P0,{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 Zc=14,fo=7,Hf=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:i=vd})=>{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:Es(e.cardBorder,e.tileTitle)}}}}};function E0({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=_e();return m.jsxs(xo,{chrome:r,children:[m.jsx(bo,{title:t?.title??Ds(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx(pe,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),m.jsx(pe,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:vt(e).replace("->","→")})]})}function T0({after:e}){const{theme:t}=_e();return m.jsx(cy,{id:af(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx(B,{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 O0({columns:e,faint:t=!1}){const{theme:n}=_e();return m.jsx(B,{"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(B,{sx:{bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},i))})}function Jc({top:e,faint:t=!1}){const{theme:n}=_e(),r=ns+pt,i=-Math.ceil(e/r);return m.jsx(B,{"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(B,{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 D0(){return m.jsxs(Em,{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 A0=[{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 P0({edges:e,width:t,heightEdge:n,label:r}){const{theme:i}=_e(),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:[A0.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":R0(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(B,{className:`builder-affordance${g?` ${rt.widthHandle}`:""}`,[bf]:"",...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:_f(u.edges),touchAction:"none",zIndex:Object.keys(u.edges).length>1?2:1,...l}},p)}),e.label&&m.jsx(B,{"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 R0=e=>e===void 0?"Auto height":`${e} rows tall`;function I0({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:E,onDragOver:$,onDragEnd:T}=t,{columns:j}=a,M=n.drag,I=C=>C.colspan===void 0?{...C,colspan:o}:C,W=(M!==void 0?(()=>{const C=M.placedHere?M.base:e.document.tiles;if(!C[M.index])return C;const O=C.map((N,H)=>H===M.index?qf(N,M.shape,M.edges,M.placed):N);return M.placed?Ht(O,j,M.index):O})():y??e.document.tiles).map(I),A=rn(W),z=x||M!==void 0,_=!z&&A&&i&&f!==void 0,q=e.document.tiles.length===0,P=z&&!A?Eb(W,j):W.map(of),F=C=>N0(C,Ds(C),w);return m.jsxs(m.Fragment,{children:[m.jsxs(db,{sensors:sy,onDragStart:k,onDragMove:E,onDragOver:$,onDragEnd:T,children:[m.jsx(dy,{active:x}),m.jsxs(B,{ref:s,sx:{position:"relative"},children:[a.widths&&(z||_)&&m.jsx(O0,{columns:j,faint:!z}),M!==void 0&&!M.placed?(M.edges.s||M.edges.n)&&m.jsx(Jc,{top:M.guideTop}):A&&(z||_)&&m.jsx(Jc,{top:0,faint:!z}),m.jsx(mp,{tiles:P,columns:j,rowGapPx:pt,defaultRowspan:C=>C.kind==="tile"?ii(C.tile):ja.query,keyOf:C=>C.kind==="gap"?af(C.after):ue(C.tile),renderTile:C=>{if(C.kind==="gap")return m.jsx(T0,{after:C.after});const{tile:O,index:N}=C;return m.jsx(C0,{tile:O,index:N,selected:N===f,flash:ue(O)===c,menuOpen:l===N,bare:$e(O),...a.insertBetween&&d&&N<e.document.tiles.length-1?{onInsertAfter:()=>b(N+1)}:{},fixed:!i,...a.widths?{edges:{all:i,right:i,start:(H,K)=>n.start(H,N,K),move:n.move,end:n.end,...M?.index===N?{label:M0(M,j)}:{}}}:{},...a.widths&&i?{width:{span:O.colspan??1,columns:j,max:Td(O,j),onStep:H=>{H!==(O.colspan??1)&&e.update(K=>{if(!Number.isInteger(N)||N<0)return;const Y=K.tiles[N];Y&&(K.tiles[N]=mo(Y,H,j,o)),K.tiles=r(K.tiles,N)})}}}:{},...a.widths?{heightEdge:{rows:O.rowspan,min:is(O),minFor:H=>is(O,H),onStep:H=>e.update(K=>{if(!Number.isInteger(N)||N<0)return;const Y=K.tiles[N];Y&&(H===void 0?delete Y.rowspan:Y.rowspan=H,K.tiles=r(K.tiles,N))})}}:{},onSelect:()=>u(N),onOpenMenu:H=>p(H,N),onRemove:()=>g(N),...v?{removeBlocked:v}:{},children:$e(O)?m.jsx(h0,{tile:O,sized:O.rowspan!==void 0||A,onChange:H=>w(ue(O),K=>{$e(K)&&(K.markdown=H)})}):h?h(O,F(O),"card"):m.jsx(E0,{tile:O,heading:F(O)})})}})]})]}),a.insertBetween&&d&&!q&&m.jsx(De,{size:"small",startIcon:m.jsx(vi,{}),"aria-label":"Add tile at the end",onClick:()=>b(),sx:{alignSelf:"center"},children:"Add tile"})]})}const N0=(e,t,n)=>{if(cr(e))return;const r=ue(e),i=s=>o=>n(r,a=>{oe(a)&&(o===""?delete a[s]:a[s]=o)});return{title:m.jsx(ua,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:i("label")}),subtitle:m.jsx(ua,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:i("subtitle")})}},W0={x:12,y:6};function L0({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:i}){const{theme:s}=_e();return m.jsx(wp,{actions:n,title:m.jsx(ua,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx(B,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:i,onFocus:i,children:m.jsx(ud,{sx:{position:"relative",overflow:"visible",...Hf(s,{selected:r,bare:!0,ringOffset:W0})},children:m.jsx(zf,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const z0=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:s}=od({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 F0(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,E=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}:{},...E?{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,E,$,T]);S.useEffect(()=>{r.current?.(j)},[j,e!==void 0]),S.useEffect(()=>()=>r.current?.(void 0),[])}function B0({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(vp,{children:m.jsx(xp.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(bp,{name:p.name,label:p.label??p.name,unused:p.boundTiles===0},p.name)),m.jsx(yp,{})]})})})}function _0(e,t){const n=new Map(e.tiles.map((r,i)=>[ue(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(ue(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return ue(i)}}function q0({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(H0)===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=_0(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:pp()}))},[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 H0=["[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 U0({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 V0({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 E=S.useCallback(()=>{u(!0),g(!1);const P=Qt(),{structural:F}=e,C=b.current.size;return e.save().then(O=>{O.ok===!0?b.current.saved({size:C,structural:F,durationMs:Qt()-P}):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 P=Qt(),F=e.lastSave?.structural??!1,C=b.current.size;return e.undoSave().then(O=>{O.ok===!0?(T.current=!0,g(!0),b.current.undone({size:C,structural:F,durationMs:Qt()-P})):b.current.undoRefused(O.reason)}).finally(()=>{$.current=!1,u(!1)})},[t,l,e]),M=S.useCallback(()=>{if(!(!t||!e.dirty||l))return E()},[t,e,l,E]),I=S.useRef(M);I.current=M;const W=S.useCallback(()=>{const P=()=>I.current();return f?f(P):P()},[f]),A=U0({dirty:h,saving:l,canSave:!!t,save:W,onExit:()=>r?.()});qm(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:W}:{},paused:A.dialog.open||c.paused===!0}),[c,e,t,W,A.dialog.open]));const z=!!t&&!l&&e.canUndoSave,_=e.lastSave,q={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:w,saving:l,saveButton:v,...t?{onSave:W}:{},...r?{onExit:A.requestExit}:{}};return{saving:l,save:W,exitGuard:A,...r?{done:A.saveAndExit}:{},undoSave:j,canUndoSave:z,lastSave:_,toolbarProps:q}}const K0=1;function Uf(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(...Uf(a,`${t}${s}.`,n-1))}}}return r}function G0(e){const t=new Map;for(const n of Vf(e))t.set(n.name,Uf(n.schema?.fields,"",K0));return t}function Vf(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 Kf(e){const t=new Map;for(const n of Vf(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}=Fp(s);r.set(i.name,{shape:{groupBys:o,totals:a},...a===s.length?{aggregateOnly:!0}:{}})}t.set(n.name,r)}return t}function Gf(e,t){const n=vo(e.annotations),r=Bp(e.annotations);return{name:e.name,...n?{description:n}:{},...r?{chart:r}:{},...t}}const Yf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function Y0(e){const t=Kf(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(Yf(r).map(s=>[s.name,Gf(s,i?.get(s.name))])))}return n}function ed(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const td=(e,t)=>e!==void 0&&t.has(e),nd=e=>e.path||e.modelPath||"";function X0(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=nd(a);if(td(d,t))continue;const f=fp(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=nd(a);if(td(d,t))continue;const f=G0(a),c=Kf(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:Yf(l).map(g=>Gf(g,c.get(u)?.get(g.name))),givens:p,fields:f.get(u)??[]})}}return{sources:n}}function Q0({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(()=>ig(e.document,o),[e.document,o]),d=S.useMemo(()=>new Map(e.document.sources.map(u=>[u.name,ed(r,u.base)])),[r,e.document.sources]),f=S.useCallback(u=>d.get(u.source)??ed(r,u.source),[d,r]),c=(u,p)=>{const g=[];for(const v of e.document.tiles){if(!oe(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&&hg(v,g),ug(v,u,p)})},dropControl:u=>{s(void 0),e.update(p=>fg(p,u))}}}function Z0(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),E=O=>{x.current=O,k(O)},[$,T]=S.useState(void 0),j=S.useCallback(O=>{c(void 0),o(N=>{const H=structuredClone(N.stack[N.index]);if(O(H),JSON.stringify(H)===JSON.stringify(N.stack[N.index]))return N;const K=[...N.stack.slice(0,N.index+1),H].slice(-100);return{stack:K,index:K.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)},[]),W=S.useCallback(async(O,N)=>{try{return await t(O,N)}catch(H){return{ok:!1,reason:`Could not build the file: ${H instanceof Error?H.message:String(H)}`}}},[t]),A=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},N=i?.(l,w)??!1,H=r?.(l,w)??!1;E(!0);try{const K=await W(a,w);if(va(K))return c(K.reason),{ok:!1,reason:K.reason};try{await n?.(K.source,{purpose:"save",document:w})}catch(te){const xe=`Could not save: ${te instanceof Error?te.message:String(te)}`;return c(xe),{ok:!1,reason:xe}}d(K.source),u(w),g(void 0),b(!1);const Y=N?{stack:[w],index:0}:O.history;return o(te=>te===O.history?Y:N?{stack:[te.stack[te.index]],index:0}:te),T(n?{before:O,after:Y,lastSave:{before:p??a,after:K.source,structural:H,clearsHistory:N}}:void 0),c(void 0),{ok:!0}}finally{E(!1)}},[w,W,n,a,l,p,v,i,r]),z=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}=$;E(!0);try{await n(O.replacing??O.source,{purpose:"undo",document:O.saved})}catch(N){const H=`Could not undo the save: ${N instanceof Error?N.message:String(N)}`;return c(H),{ok:!1,reason:H}}finally{E(!1)}return d(O.source),u(O.saved),g(O.replacing),b(O.unwritten||O.replacing!==void 0),o(N=>N===$.after?O.history:N),T(void 0),c(void 0),{ok:!0}},[n,$]),_=S.useMemo(()=>v||JSON.stringify(w)!==JSON.stringify(l),[w,l,v]),q=S.useMemo(()=>r?.(l,w)??!1,[w,l,r]),P=S.useMemo(()=>i?.(l,w)??!1,[w,l,i]),F=$!==void 0&&$.after===s,C=S.useCallback(async()=>{const O=await W(a,w);return va(O)?{ok:!1,reason:O.reason}:{ok:!0,source:O.source}},[w,W,a]);return{document:w,saved:l,source:a,canUndo:s.index>0,canRedo:s.index<s.stack.length-1,dirty:_,edited:_,...f===void 0?{}:{error:f},update:j,undo:M,redo:I,save:A,preview:C,structural:q,clearsHistory:P,canUndoSave:F&&!y&&n!==void 0,...F?{lastSave:$.lastSave}:{},undoSave:z}}const J0=(e,t)=>{const n=new Set(e.tiles.map(xa)),r=new Set(t.tiles.map(xa));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function ew(e){const{visibleSources:t,...n}=e,r=S.useCallback((i,s)=>d0(i,s,t?{visibleSources:t}:{}),[t]);return Z0({...n,splice:r,structural:J0})}function tw({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 nw({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=>{Gm(x,h,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c}),t.widths&&(x.tiles=Bl(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($e).map(E=>E.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=Bl(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(E=>ue(E)===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&&oe(x)&&ls(x)===void 0?h+1:void 0;e.update(k=>{Ym(k,h)}),y!==void 0&&i(y)}}}const rw=mt(m.jsx("path",{d:"M19 5v2h-4V5zM9 5v6H5V5zm10 8v6h-4v-6zM9 17v2H5v-2zM21 3h-8v6h8zM11 3H3v10h8zm10 8h-8v10h8zm-10 4H3v6h8z"}));function Xf({arrange:e}){const{theme:t}=_e(),[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(rw,{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 Qf({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:E,onControlsChange:$,draftKey:T}){const j=ew({source:e,document:t,...n?{onSave:n}:{},...b!==void 0?{replaces:b}:{},...h?{visibleSources:h}:{}}),M=ep(T,j,e),I=S.useRef(null),{selected:W,descriptionSelected:A,selectTile:z,deselectTile:_,selectDescription:q,clearSelection:P,flash:F,stepEditor:C}=q0({editor:j,gridBox:I}),O=sd(j.document.layout,j.document.columns),{columns:N}=O,H=w?.split("/").at(-1)?.replace(/\.malloy$/,""),K=id("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),Y=!O.widths||K,te=w0({tiles:j.document.tiles,commit:X=>j.update(de=>{de.tiles=X}),onLanded:z,...O.widths&&K?{placement:{columns:N,gridBox:I}}:{}}),xe=(X,de)=>{if(j.update(ge=>{ge.tiles=X}),de===void 0)return;const Ie=X.findIndex(ge=>ue(ge)===de);Ie>=0&&z(Ie)},me=O.widths,ne=S.useCallback((X,de)=>me&&rn(X)?Ht(X,N,de):X,[me,N]),{dragging:Ce}=te,J=tp(I,N),Ve=S.useMemo(()=>j.document.tiles.map(X=>X.colspan===void 0?{...X,colspan:J}:X),[j.document.tiles,J]),Ae=j0({tiles:Ve,columns:N,gridBox:I,onStart:z,commit:({index:X,edges:de,shape:Ie,placed:ge,placedAll:dn})=>{const le=dn??j.document.tiles,he=le[X];if(!he)return;let qe=qf(he,Ie,de,ge);(de.e||de.w)&&(qe=mo(qe,Ie.colspan,N,J));const Ct=le.map(($r,Dn)=>Dn===X?qe:$r);xe(ge?Kn(Ht(Ct,N,X)):Ct,ue(he))}}),G=nw({editor:j,rules:O,modelPath:w,textHeld:h!==void 0,selectTile:z,deselectTile:_}),{menu:ye,addingTile:be,openAdd:re}=G,Pe=Q0({editor:j,opened:t,givens:f,catalog:c}),{filterDialog:Ke,setFilterDialog:Re}=Pe,[Qe,Ze]=S.useState(void 0),{draftDirty:D,openDraft:L,prepare:U}=tw({editorDirty:j.dirty}),V=Ae.drag!==void 0,we=S.useMemo(()=>({paused:V,escape:()=>{!ye&&!Ke&&!be&&Qe===void 0&&P()},move:(X,de)=>{if(Ce||W===void 0||!O.widths||!Y)return!1;const Ie=j.document.tiles[W];if(!Ie||Ie.row===void 0||Ie.col===void 0)return!1;const ge=_l(j.document.tiles,W,X,de,N);if(ge.every((he,qe)=>he===j.document.tiles[qe]))return!0;const dn=ue(Ie);j.update(he=>{he.tiles=Kn(_l(he.tiles,W,X,de,N))});const le=Kn(ge).findIndex(he=>ue(he)===dn);return le>=0&&z(le),!0},nudge:X=>{if(Ce||W===void 0||!O.widths||!Y)return;const de=j.document.tiles[W];if(!de)return;const Ie=np(de.colspan??J,X,Td(de,N));Ie!==(de.colspan??J)&&j.update(ge=>{ge.tiles[W]=mo(ge.tiles[W],Ie,N,J),ge.tiles=ne(ge.tiles,W)})}}),[V,J,Y,ne,z,j,ye,Ke,be,Qe,P,W,N,O,Ce]),je=V0({editor:C,extraDirty:D,keepsEdits:T!==void 0&&M.keeping,prepare:U,unit:{name:"tile",count:X=>X.tiles.length},onSave:n,onDirtyChange:i,onExit:s,onChange:r,shortcuts:we,report:z0({size:j.document.tiles.length,path:w??"",layout:j.document.layout,savesTo:g,onEvent:p})}),Mt=j.document.tiles.length===0,{toolbarProps:R}=je,ce=M.restored,Je={status:je.saving?"saving":R.dirty?"unsaved":"saved",saveTarget:v??jo[g],...M.keptAt!==void 0?{draftKeptAt:M.keptAt}:{},...(R.dirty||ce?.pending)&&T!==void 0?{discard:M.discard}:{},...ce?{restored:ce}:{},...ce&&!ce.pending?{dismissRestored:M.dismissRestored}:{}},Fe=j.document.tiles,st=W!==void 0&&Fe[W]?ue(Fe[W]):void 0,ee=O.widths&&Y&&rn(Fe)?{...Wm(Fe,N)?{pack:()=>xe(Kn(Ed(Fe,N)),st)}:{},flow:()=>xe(Lm(Fe),st)}:void 0;F0($,{...Je,...R.onSave?{save:R.onSave}:{},canUndo:R.canUndo,undo:R.onUndo,canRedo:R.canRedo,redo:R.onRedo,add:{...c?{tile:()=>G.openAdd()}:{},text:G.appendText,...x!==void 0?{filterUnavailable:x}:Mt?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>Re({})}},...R.onExit?{exit:R.onExit}:{},...je.done?{done:je.done}:{},...ce?.pending?{restore:M.restoreOffered}:{},...ee?{arrange:ee}:{}});const et=$?void 0:m.jsx(Hm,{...je.toolbarProps,...l?{actions:l}:{},...c?{onAddTile:()=>re()}:{},...ee?{arrange:m.jsx(Xf,{arrange:ee})}:{},savesTo:g,...v?{saveLabel:v}:{},...T!==void 0&&R.onSave?{saveStatus:Je}:{}});return m.jsx(rf.Provider,{value:L,children:m.jsx(ft,{className:rt.builder,"data-saves-to":g,sx:{gap:0,mx:`-${fo}px`},children:m.jsxs(rp,{layout:O.layout,sx:{px:`${fo}px`,pb:`${fo}px`},header:m.jsx(L0,{editor:j,documentSlug:H,actions:et,descriptionSelected:A,selectDescription:q}),controls:Mt?void 0:m.jsx(B0,{controls:Pe.controlList,unknownFieldsOf:Pe.unknownFieldsOf,onEdit:X=>Re({control:X}),onAdd:()=>Re({}),...x?{addDisabledReason:x}:{},onRemove:Pe.dropControl,...y?{fixedFilters:y}:{},...k?{onOpenModel:k}:{},...j.document.startingGivens?{startingValues:j.document.startingGivens}:{},onStartingValue:(X,de)=>j.update(Ie=>{const ge={...Ie.startingGivens??{}};de===void 0?delete ge[X]:ge[X]=de,Object.keys(ge).length>0?Ie.startingGivens=ge:delete Ie.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(pe,{variant:"body2",children:"This report is not served until it has a tile."}),c&&m.jsx(De,{size:"small",startIcon:m.jsx(vi,{}),onClick:()=>re(),children:"Add tile"})]}),ce?.pending&&m.jsx(ht,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx(De,{color:"inherit",size:"small",onClick:M.restoreOffered,children:"Restore them"}),m.jsx(De,{color:"inherit",size:"small",onClick:M.discard,children:"Discard"})]}),children:`You have unsaved edits from ${So(ce.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(I0,{editor:j,arrange:Y,reorder:te,edging:Ae,place:ne,gridBox:I,defaultSpan:J,rules:O,canAdd:!!c,selected:W,flash:F,menuIndex:ye?.index,onSelect:z,onOpenMenu:(X,de)=>{z(de),G.setMenu({anchor:X,index:de})},onRemove:G.removeTile,...j.document.tiles.length===1&&j.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:re,editTile:G.editTile,...o?{renderTile:o}:{}}),m.jsx(Cg,{editor:j,catalog:c,columns:N,dashboards:u,bindings:Pe,tiles:G,drillSource:Qe,setDrillSource:Ze,exitDialog:je.exitGuard.dialog,...a?{renderViewPreview:a}:{},...E?{takenGivenNames:E}:{}})]})})})}const iw=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"})),ow=mt(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function Dw({controls:e,onDone:t}){const n=t??e?.exit,r=id("(max-width: 599.95px)"),{theme:i}=_e(),s=cn(i.cardBorder),o=Es(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(Ad,{...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(Dd,{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(Od,{fontSize:"small"})})})}),e.arrange&&m.jsx(Xf,{arrange:e.arrange}),p&&m.jsx(nr,{orientation:"vertical",sx:os}),p&&m.jsxs(m.Fragment,{children:[m.jsx(De,{variant:"outlined",startIcon:m.jsx(vi,{}),endIcon:m.jsx(wa,{}),"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:aw(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(ow,{}),title:"Text",detail:"Prose between the tiles",onClick:g(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(po,{icon:m.jsx(iw,{}),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(De,{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(De,{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 aw=(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}=_e(),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(B,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs(B,{className:"add-text",sx:{minWidth:0},children:[m.jsx(B,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx(B,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function lw(e,t,n=new Set,r=new Map){const i=[];for(const c of e.tiles){if(!oe(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?gm(l):d.get(c);u&&f.push(u)}return f}function cw(e,t,n){const r=new Map;for(const s of t.tiles)oe(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(!oe(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 dw(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function uw(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 hw(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=vm(a.from,n);return xm(t,o,d,n)?void 0:d}}}function fw(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=>oe(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 pw(e,t,n,r=new Map,i,s){if(cr(t))return{expression:vt(t),givenNames:void 0,reads:i&&[...i]};const o=fw(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 E=`where: ${Ea(k.field)} ${k.op??"~"}`;if(f.has(k.given)){p.add(k.given),g.add(k.given),v.push(`${E} $${k.given}`);continue}if(!c.has(k.given))continue;g.add(k.given);const $=bm(r.get(k.given),c.get(k.given))??dw(l.get(k.given));$!==void 0&&v.push(`${E} ${$}`)}const b=v.join(", "),w=t.chart,h=w==="none"||Os(w)?Qn(w,t.chartCarried):w==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
142
|
+
`),c=zy(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[Ky,Xy,Qy,Zy,Jy,e0,t0,n0,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($e(T))return T;if(T.filters?.length)return Es(T);const{filters:j,...M}=T;return Es(M)});return{...C,...k===void 0?{}:{description:Tf(k)},tiles:$,...x?.length?{drills:[...x].sort((T,j)=>Ms(T).localeCompare(Ms(j)))}:{},...y?.length?{localGivens:y}:{}}};if(p.length===0)return Se(v(i))!==Se(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=Fy(e,p);if((await Wc(e)).length===0){const h=await Wc(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 ga(b);return ma(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:Se(v(w.document))!==Se(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 zf({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=_e(),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}=Id(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;sf(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(B,{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},nf(i,"prose")],children:[e.trim()?m.jsx(cm,{variant:r,children:e}):m.jsx(pe,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),y&&m.jsx(pe,{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(B,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx(yd,{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:dm,"& textarea":{p:0}}}),h!==void 0&&m.jsx(pe,{variant:"caption",color:"error",role:"alert",children:h}),m.jsxs(pe,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",Sn,"↩ done · Esc cancels"]})]})}const u0="Write markdown: # heading, **bold**, - list";function h0({tile:e,sized:t=!1,onChange:n}){const r=m.jsx(ud,{sx:{overflow:"visible"},children:m.jsx(zf,{markdown:e.markdown,placeholder:u0,onCommit:n})});return t?m.jsx(B,{"data-testid":"text-tile-scroller",sx:{minHeight:0,overflow:"auto",p:"4px",m:"-4px"},children:r}):r}var f0=Object.defineProperty,p0=Object.defineProperties,m0=Object.getOwnPropertyDescriptors,Gc=Object.getOwnPropertySymbols,g0=Object.prototype.hasOwnProperty,v0=Object.prototype.propertyIsEnumerable,Yc=(e,t,n)=>t in e?f0(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ln=(e,t)=>{for(var n in t||(t={}))g0.call(t,n)&&Yc(e,n,t[n]);if(Gc)for(var n of Gc(t))v0.call(t,n)&&Yc(e,n,t[n]);return e},zn=(e,t)=>p0(e,m0(t));function x0(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 b0(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 zn(Ln({},e),{[h]:n(e[h],x,k)});const C=e[h][x];return zn(Ln({},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 zn(Ln({},e),{[l]:n(e[l],c,s.index)});const C=e[l][c];return zn(Ln({},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 zn(Ln({},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 zn(Ln({},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 y0(e,t){return b0(e,t,x0)}function Ff(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 w0({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=>ue(y)===u),g=Ff(l),v=g.get(String(u));if(p<0||!v)return;const b=Ed(e,e.map(y=>g.get(ue(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=Md(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=Nm(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===xf){const{after:v}=u.data,b=p.findIndex(h=>ue(h)===l.id);if(b<0||v===l.id)return;const w=p.filter((h,x)=>x!==b).findIndex(h=>ue(h)===v)+1;g=Eb(p,b,w)}else{const v=p.map(ue),b=y0(v,c);if(b.every((h,x)=>h===v[x]))return;const w=new Map(p.map(h=>[ue(h),h]));g=Mb(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=>ue(w)===c.operation.source?.id);b>=0&&n(b)}}}const k0={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Bf=(e,t)=>t===0?e:Bf(t,e%t);function S0(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Bf(e,t),i=k0[`${e/r}/${t/r}`];return i?`${n} · ${i}`:n}const Xc=ns+pt,_f=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}),Zc=(e,t)=>e.row===t.row&&e.col===t.col&&e.colspan===t.colspan&&e.rowspan===t.rowspan;function qf(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 j0({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(ue)),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===ue(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(_f(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=Ff(v);return Ed(e,e.map(j=>T.get(ue(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 A=p.from,z=A.col??j,_=z+A.colspan-1,q=A.row??T,P=A.rowspan??ii(v),F=q+P-1;if(p.edges.e){const E=Math.round((w+pt)/b);M=Math.min(Math.max(E,z),t)-z+1,j=z}if(p.edges.w){const E=Math.round(w/b)+1;j=Math.min(Math.max(E,1),_),M=_-j+1}if(p.edges.s){const E=p.edges.n?g.top+(q-1)*Xc:y;I=Il(u.clientY-E,C),T=q}if(p.edges.n){const E=Math.round(h/Xc)+1,O=Math.min(C,P);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 A=Math.round((u.clientX-k+pt)/b);M=Math.min(Math.max(A,1),t)}if(p.edges.s){const A=u.clientY-y,z=Il(A,C),_=l(p);I=_!==void 0&&Math.abs(A-_)<Math.abs(A-dd(z))?void 0:z}}const W={...T!==void 0?{row:T}:{},...j!==void 0?{col:j}:{},colspan:M,rowspan:I};Zc(W,$)||f({...p,shape:W})},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"||Zc(p.shape,p.begun))&&i({index:p.index,edges:p.edges,shape:p.shape,placed:p.placed,...p.placedHere?{placedAll:p.base}:{}}))}}}function M0(e,t){const n=[];return(e.edges.e||e.edges.w)&&n.push(S0(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 E0({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}=_e(),w=b.ui;return m.jsx(ly,{id:ue(e),index:t,disabled:g,children:({ref:h,handleRef:x})=>m.jsxs(B,{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":ue(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",...Hf(b,{selected:n,flash:r,bare:s}),...!s&&{[`& .${em}`]:{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},...Zp,...n&&{[`& .${Jp}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[v,m.jsx(B,{ref:x,"aria-label":`Move ${Mr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(Qp,{label:`Remove ${Mr(e)}`,onRemove:f,...c?{disabledReason:c}:{},inset:s?vd:0}),!$e(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:`${Qc}px`,right:s?0:`${Qc}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(D0,{})}),u&&m.jsx(P0,{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 Qc=14,fo=7,Hf=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:i=vd})=>{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 C0({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=_e();return m.jsxs(xo,{chrome:r,children:[m.jsx(bo,{title:t?.title??Ds(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx(pe,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),m.jsx(pe,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:vt(e).replace("->","→")})]})}function T0({after:e}){const{theme:t}=_e();return m.jsx(cy,{id:af(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx(B,{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 O0({columns:e,faint:t=!1}){const{theme:n}=_e();return m.jsx(B,{"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(B,{sx:{bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},i))})}function Jc({top:e,faint:t=!1}){const{theme:n}=_e(),r=ns+pt,i=-Math.ceil(e/r);return m.jsx(B,{"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(B,{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 D0(){return m.jsxs(Cm,{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 A0=[{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 P0({edges:e,width:t,heightEdge:n,label:r}){const{theme:i}=_e(),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:[A0.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":R0(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(B,{className:`builder-affordance${g?` ${rt.widthHandle}`:""}`,[bf]:"",...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:_f(u.edges),touchAction:"none",zIndex:Object.keys(u.edges).length>1?2:1,...l}},p)}),e.label&&m.jsx(B,{"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 R0=e=>e===void 0?"Auto height":`${e} rows tall`;function I0({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,W=(M!==void 0?(()=>{const E=M.placedHere?M.base:e.document.tiles;if(!E[M.index])return E;const O=E.map((N,H)=>H===M.index?qf(N,M.shape,M.edges,M.placed):N);return M.placed?Ht(O,j,M.index):O})():y??e.document.tiles).map(I),A=rn(W),z=x||M!==void 0,_=!z&&A&&i&&f!==void 0,q=e.document.tiles.length===0,P=z&&!A?Cb(W,j):W.map(of),F=E=>N0(E,Ds(E),w);return m.jsxs(m.Fragment,{children:[m.jsxs(db,{sensors:sy,onDragStart:k,onDragMove:C,onDragOver:$,onDragEnd:T,children:[m.jsx(dy,{active:x}),m.jsxs(B,{ref:s,sx:{position:"relative"},children:[a.widths&&(z||_)&&m.jsx(O0,{columns:j,faint:!z}),M!==void 0&&!M.placed?(M.edges.s||M.edges.n)&&m.jsx(Jc,{top:M.guideTop}):A&&(z||_)&&m.jsx(Jc,{top:0,faint:!z}),m.jsx(mp,{tiles:P,columns:j,rowGapPx:pt,defaultRowspan:E=>E.kind==="tile"?ii(E.tile):ja.query,keyOf:E=>E.kind==="gap"?af(E.after):ue(E.tile),renderTile:E=>{if(E.kind==="gap")return m.jsx(T0,{after:E.after});const{tile:O,index:N}=E;return m.jsx(E0,{tile:O,index:N,selected:N===f,flash:ue(O)===c,menuOpen:l===N,bare:$e(O),...a.insertBetween&&d&&N<e.document.tiles.length-1?{onInsertAfter:()=>b(N+1)}:{},fixed:!i,...a.widths?{edges:{all:i,right:i,start:(H,K)=>n.start(H,N,K),move:n.move,end:n.end,...M?.index===N?{label:M0(M,j)}:{}}}:{},...a.widths&&i?{width:{span:O.colspan??1,columns:j,max:Td(O,j),onStep:H=>{H!==(O.colspan??1)&&e.update(K=>{if(!Number.isInteger(N)||N<0)return;const Y=K.tiles[N];Y&&(K.tiles[N]=mo(Y,H,j,o)),K.tiles=r(K.tiles,N)})}}}:{},...a.widths?{heightEdge:{rows:O.rowspan,min:is(O),minFor:H=>is(O,H),onStep:H=>e.update(K=>{if(!Number.isInteger(N)||N<0)return;const Y=K.tiles[N];Y&&(H===void 0?delete Y.rowspan:Y.rowspan=H,K.tiles=r(K.tiles,N))})}}:{},onSelect:()=>u(N),onOpenMenu:H=>p(H,N),onRemove:()=>g(N),...v?{removeBlocked:v}:{},children:$e(O)?m.jsx(h0,{tile:O,sized:O.rowspan!==void 0||A,onChange:H=>w(ue(O),K=>{$e(K)&&(K.markdown=H)})}):h?h(O,F(O),"card"):m.jsx(C0,{tile:O,heading:F(O)})})}})]})]}),a.insertBetween&&d&&!q&&m.jsx(De,{size:"small",startIcon:m.jsx(vi,{}),"aria-label":"Add tile at the end",onClick:()=>b(),sx:{alignSelf:"center"},children:"Add tile"})]})}const N0=(e,t,n)=>{if(cr(e))return;const r=ue(e),i=s=>o=>n(r,a=>{oe(a)&&(o===""?delete a[s]:a[s]=o)});return{title:m.jsx(ua,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:i("label")}),subtitle:m.jsx(ua,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:i("subtitle")})}},W0={x:12,y:6};function L0({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:i}){const{theme:s}=_e();return m.jsx(wp,{actions:n,title:m.jsx(ua,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx(B,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:i,onFocus:i,children:m.jsx(ud,{sx:{position:"relative",overflow:"visible",...Hf(s,{selected:r,bare:!0,ringOffset:W0})},children:m.jsx(zf,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const z0=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:s}=od({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 F0(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 B0({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(vp,{children:m.jsx(xp.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(bp,{name:p.name,label:p.label??p.name,unused:p.boundTiles===0},p.name)),m.jsx(yp,{})]})})})}function _0(e,t){const n=new Map(e.tiles.map((r,i)=>[ue(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(ue(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return ue(i)}}function q0({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(H0)===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=_0(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:pp()}))},[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 H0=["[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 U0({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 V0({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 P=Zt(),{structural:F}=e,E=b.current.size;return e.save().then(O=>{O.ok===!0?b.current.saved({size:E,structural:F,durationMs:Zt()-P}):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 P=Zt(),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:Zt()-P})):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 W=S.useCallback(()=>{const P=()=>I.current();return f?f(P):P()},[f]),A=U0({dirty:h,saving:l,canSave:!!t,save:W,onExit:()=>r?.()});qm(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:W}:{},paused:A.dialog.open||c.paused===!0}),[c,e,t,W,A.dialog.open]));const z=!!t&&!l&&e.canUndoSave,_=e.lastSave,q={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:w,saving:l,saveButton:v,...t?{onSave:W}:{},...r?{onExit:A.requestExit}:{}};return{saving:l,save:W,exitGuard:A,...r?{done:A.saveAndExit}:{},undoSave:j,canUndoSave:z,lastSave:_,toolbarProps:q}}const K0=1;function Uf(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(...Uf(a,`${t}${s}.`,n-1))}}}return r}function G0(e){const t=new Map;for(const n of Vf(e))t.set(n.name,Uf(n.schema?.fields,"",K0));return t}function Vf(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 Kf(e){const t=new Map;for(const n of Vf(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}=Fp(s);r.set(i.name,{shape:{groupBys:o,totals:a},...a===s.length?{aggregateOnly:!0}:{}})}t.set(n.name,r)}return t}function Gf(e,t){const n=vo(e.annotations),r=Bp(e.annotations);return{name:e.name,...n?{description:n}:{},...r?{chart:r}:{},...t}}const Yf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function Y0(e){const t=Kf(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(Yf(r).map(s=>[s.name,Gf(s,i?.get(s.name))])))}return n}function ed(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const td=(e,t)=>e!==void 0&&t.has(e),nd=e=>e.path||e.modelPath||"";function X0(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=nd(a);if(td(d,t))continue;const f=fp(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=nd(a);if(td(d,t))continue;const f=G0(a),c=Kf(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:Yf(l).map(g=>Gf(g,c.get(u)?.get(g.name))),givens:p,fields:f.get(u)??[]})}}return{sources:n}}function Z0({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(()=>ig(e.document,o),[e.document,o]),d=S.useMemo(()=>new Map(e.document.sources.map(u=>[u.name,ed(r,u.base)])),[r,e.document.sources]),f=S.useCallback(u=>d.get(u.source)??ed(r,u.source),[d,r]),c=(u,p)=>{const g=[];for(const v of e.document.tiles){if(!oe(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&&hg(v,g),ug(v,u,p)})},dropControl:u=>{s(void 0),e.update(p=>fg(p,u))}}}function Q0(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(N=>{const H=structuredClone(N.stack[N.index]);if(O(H),JSON.stringify(H)===JSON.stringify(N.stack[N.index]))return N;const K=[...N.stack.slice(0,N.index+1),H].slice(-100);return{stack:K,index:K.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)},[]),W=S.useCallback(async(O,N)=>{try{return await t(O,N)}catch(H){return{ok:!1,reason:`Could not build the file: ${H instanceof Error?H.message:String(H)}`}}},[t]),A=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},N=i?.(l,w)??!1,H=r?.(l,w)??!1;C(!0);try{const K=await W(a,w);if(va(K))return c(K.reason),{ok:!1,reason:K.reason};try{await n?.(K.source,{purpose:"save",document:w})}catch(te){const xe=`Could not save: ${te instanceof Error?te.message:String(te)}`;return c(xe),{ok:!1,reason:xe}}d(K.source),u(w),g(void 0),b(!1);const Y=N?{stack:[w],index:0}:O.history;return o(te=>te===O.history?Y:N?{stack:[te.stack[te.index]],index:0}:te),T(n?{before:O,after:Y,lastSave:{before:p??a,after:K.source,structural:H,clearsHistory:N}}:void 0),c(void 0),{ok:!0}}finally{C(!1)}},[w,W,n,a,l,p,v,i,r]),z=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(N){const H=`Could not undo the save: ${N instanceof Error?N.message:String(N)}`;return c(H),{ok:!1,reason:H}}finally{C(!1)}return d(O.source),u(O.saved),g(O.replacing),b(O.unwritten||O.replacing!==void 0),o(N=>N===$.after?O.history:N),T(void 0),c(void 0),{ok:!0}},[n,$]),_=S.useMemo(()=>v||JSON.stringify(w)!==JSON.stringify(l),[w,l,v]),q=S.useMemo(()=>r?.(l,w)??!1,[w,l,r]),P=S.useMemo(()=>i?.(l,w)??!1,[w,l,i]),F=$!==void 0&&$.after===s,E=S.useCallback(async()=>{const O=await W(a,w);return va(O)?{ok:!1,reason:O.reason}:{ok:!0,source:O.source}},[w,W,a]);return{document:w,saved:l,source:a,canUndo:s.index>0,canRedo:s.index<s.stack.length-1,dirty:_,edited:_,...f===void 0?{}:{error:f},update:j,undo:M,redo:I,save:A,preview:E,structural:q,clearsHistory:P,canUndoSave:F&&!y&&n!==void 0,...F?{lastSave:$.lastSave}:{},undoSave:z}}const J0=(e,t)=>{const n=new Set(e.tiles.map(xa)),r=new Set(t.tiles.map(xa));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function ew(e){const{visibleSources:t,...n}=e,r=S.useCallback((i,s)=>d0(i,s,t?{visibleSources:t}:{}),[t]);return Q0({...n,splice:r,structural:J0})}function tw({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 nw({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=>{Gm(x,h,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c}),t.widths&&(x.tiles=Bl(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($e).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=Bl(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=>ue(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&&oe(x)&&ls(x)===void 0?h+1:void 0;e.update(k=>{Ym(k,h)}),y!==void 0&&i(y)}}}const rw=mt(m.jsx("path",{d:"M19 5v2h-4V5zM9 5v6H5V5zm10 8v6h-4v-6zM9 17v2H5v-2zM21 3h-8v6h8zM11 3H3v10h8zm10 8h-8v10h8zm-10 4H3v6h8z"}));function Xf({arrange:e}){const{theme:t}=_e(),[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(rw,{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 Zf({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=ew({source:e,document:t,...n?{onSave:n}:{},...b!==void 0?{replaces:b}:{},...h?{visibleSources:h}:{}}),M=ep(T,j,e),I=S.useRef(null),{selected:W,descriptionSelected:A,selectTile:z,deselectTile:_,selectDescription:q,clearSelection:P,flash:F,stepEditor:E}=q0({editor:j,gridBox:I}),O=sd(j.document.layout,j.document.columns),{columns:N}=O,H=w?.split("/").at(-1)?.replace(/\.malloy$/,""),K=id("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),Y=!O.widths||K,te=w0({tiles:j.document.tiles,commit:X=>j.update(de=>{de.tiles=X}),onLanded:z,...O.widths&&K?{placement:{columns:N,gridBox:I}}:{}}),xe=(X,de)=>{if(j.update(ge=>{ge.tiles=X}),de===void 0)return;const Ie=X.findIndex(ge=>ue(ge)===de);Ie>=0&&z(Ie)},me=O.widths,ne=S.useCallback((X,de)=>me&&rn(X)?Ht(X,N,de):X,[me,N]),{dragging:Ee}=te,J=tp(I,N),Ve=S.useMemo(()=>j.document.tiles.map(X=>X.colspan===void 0?{...X,colspan:J}:X),[j.document.tiles,J]),Ae=j0({tiles:Ve,columns:N,gridBox:I,onStart:z,commit:({index:X,edges:de,shape:Ie,placed:ge,placedAll:dn})=>{const le=dn??j.document.tiles,he=le[X];if(!he)return;let qe=qf(he,Ie,de,ge);(de.e||de.w)&&(qe=mo(qe,Ie.colspan,N,J));const Et=le.map(($r,Dn)=>Dn===X?qe:$r);xe(ge?Kn(Ht(Et,N,X)):Et,ue(he))}}),G=nw({editor:j,rules:O,modelPath:w,textHeld:h!==void 0,selectTile:z,deselectTile:_}),{menu:ye,addingTile:be,openAdd:re}=G,Pe=Z0({editor:j,opened:t,givens:f,catalog:c}),{filterDialog:Ke,setFilterDialog:Re}=Pe,[Ze,Qe]=S.useState(void 0),{draftDirty:D,openDraft:L,prepare:U}=tw({editorDirty:j.dirty}),V=Ae.drag!==void 0,we=S.useMemo(()=>({paused:V,escape:()=>{!ye&&!Ke&&!be&&Ze===void 0&&P()},move:(X,de)=>{if(Ee||W===void 0||!O.widths||!Y)return!1;const Ie=j.document.tiles[W];if(!Ie||Ie.row===void 0||Ie.col===void 0)return!1;const ge=_l(j.document.tiles,W,X,de,N);if(ge.every((he,qe)=>he===j.document.tiles[qe]))return!0;const dn=ue(Ie);j.update(he=>{he.tiles=Kn(_l(he.tiles,W,X,de,N))});const le=Kn(ge).findIndex(he=>ue(he)===dn);return le>=0&&z(le),!0},nudge:X=>{if(Ee||W===void 0||!O.widths||!Y)return;const de=j.document.tiles[W];if(!de)return;const Ie=np(de.colspan??J,X,Td(de,N));Ie!==(de.colspan??J)&&j.update(ge=>{ge.tiles[W]=mo(ge.tiles[W],Ie,N,J),ge.tiles=ne(ge.tiles,W)})}}),[V,J,Y,ne,z,j,ye,Ke,be,Ze,P,W,N,O,Ee]),je=V0({editor:E,extraDirty:D,keepsEdits:T!==void 0&&M.keeping,prepare:U,unit:{name:"tile",count:X=>X.tiles.length},onSave:n,onDirtyChange:i,onExit:s,onChange:r,shortcuts:we,report:z0({size:j.document.tiles.length,path:w??"",layout:j.document.layout,savesTo:g,onEvent:p})}),Mt=j.document.tiles.length===0,{toolbarProps:R}=je,ce=M.restored,Je={status:je.saving?"saving":R.dirty?"unsaved":"saved",saveTarget:v??jo[g],...M.keptAt!==void 0?{draftKeptAt:M.keptAt}:{},...(R.dirty||ce?.pending)&&T!==void 0?{discard:M.discard}:{},...ce?{restored:ce}:{},...ce&&!ce.pending?{dismissRestored:M.dismissRestored}:{}},Fe=j.document.tiles,st=W!==void 0&&Fe[W]?ue(Fe[W]):void 0,ee=O.widths&&Y&&rn(Fe)?{...Wm(Fe,N)?{pack:()=>xe(Kn(Cd(Fe,N)),st)}:{},flow:()=>xe(Lm(Fe),st)}:void 0;F0($,{...Je,...R.onSave?{save:R.onSave}:{},canUndo:R.canUndo,undo:R.onUndo,canRedo:R.canRedo,redo:R.onRedo,add:{...c?{tile:()=>G.openAdd()}:{},text:G.appendText,...x!==void 0?{filterUnavailable:x}:Mt?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>Re({})}},...R.onExit?{exit:R.onExit}:{},...je.done?{done:je.done}:{},...ce?.pending?{restore:M.restoreOffered}:{},...ee?{arrange:ee}:{}});const et=$?void 0:m.jsx(Hm,{...je.toolbarProps,...l?{actions:l}:{},...c?{onAddTile:()=>re()}:{},...ee?{arrange:m.jsx(Xf,{arrange:ee})}:{},savesTo:g,...v?{saveLabel:v}:{},...T!==void 0&&R.onSave?{saveStatus:Je}:{}});return m.jsx(rf.Provider,{value:L,children:m.jsx(ft,{className:rt.builder,"data-saves-to":g,sx:{gap:0,mx:`-${fo}px`},children:m.jsxs(rp,{layout:O.layout,sx:{px:`${fo}px`,pb:`${fo}px`},header:m.jsx(L0,{editor:j,documentSlug:H,actions:et,descriptionSelected:A,selectDescription:q}),controls:Mt?void 0:m.jsx(B0,{controls:Pe.controlList,unknownFieldsOf:Pe.unknownFieldsOf,onEdit:X=>Re({control:X}),onAdd:()=>Re({}),...x?{addDisabledReason:x}:{},onRemove:Pe.dropControl,...y?{fixedFilters:y}:{},...k?{onOpenModel:k}:{},...j.document.startingGivens?{startingValues:j.document.startingGivens}:{},onStartingValue:(X,de)=>j.update(Ie=>{const ge={...Ie.startingGivens??{}};de===void 0?delete ge[X]:ge[X]=de,Object.keys(ge).length>0?Ie.startingGivens=ge:delete Ie.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(pe,{variant:"body2",children:"This report is not served until it has a tile."}),c&&m.jsx(De,{size:"small",startIcon:m.jsx(vi,{}),onClick:()=>re(),children:"Add tile"})]}),ce?.pending&&m.jsx(ht,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx(De,{color:"inherit",size:"small",onClick:M.restoreOffered,children:"Restore them"}),m.jsx(De,{color:"inherit",size:"small",onClick:M.discard,children:"Discard"})]}),children:`You have unsaved edits from ${So(ce.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(I0,{editor:j,arrange:Y,reorder:te,edging:Ae,place:ne,gridBox:I,defaultSpan:J,rules:O,canAdd:!!c,selected:W,flash:F,menuIndex:ye?.index,onSelect:z,onOpenMenu:(X,de)=>{z(de),G.setMenu({anchor:X,index:de})},onRemove:G.removeTile,...j.document.tiles.length===1&&j.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:re,editTile:G.editTile,...o?{renderTile:o}:{}}),m.jsx(Eg,{editor:j,catalog:c,columns:N,dashboards:u,bindings:Pe,tiles:G,drillSource:Ze,setDrillSource:Qe,exitDialog:je.exitGuard.dialog,...a?{renderViewPreview:a}:{},...C?{takenGivenNames:C}:{}})]})})})}const iw=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"})),ow=mt(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function Dw({controls:e,onDone:t}){const n=t??e?.exit,r=id("(max-width: 599.95px)"),{theme:i}=_e(),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(Ad,{...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(Dd,{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(Od,{fontSize:"small"})})})}),e.arrange&&m.jsx(Xf,{arrange:e.arrange}),p&&m.jsx(nr,{orientation:"vertical",sx:os}),p&&m.jsxs(m.Fragment,{children:[m.jsx(De,{variant:"outlined",startIcon:m.jsx(vi,{}),endIcon:m.jsx(wa,{}),"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:aw(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(ow,{}),title:"Text",detail:"Prose between the tiles",onClick:g(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(po,{icon:m.jsx(iw,{}),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(De,{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(De,{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 aw=(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}=_e(),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(B,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs(B,{className:"add-text",sx:{minWidth:0},children:[m.jsx(B,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx(B,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function lw(e,t,n=new Set,r=new Map){const i=[];for(const c of e.tiles){if(!oe(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?gm(l):d.get(c);u&&f.push(u)}return f}function cw(e,t,n){const r=new Map;for(const s of t.tiles)oe(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(!oe(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 dw(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function uw(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 hw(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=vm(a.from,n);return xm(t,o,d,n)?void 0:d}}}function fw(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=>oe(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 pw(e,t,n,r=new Map,i,s){if(cr(t))return{expression:vt(t),givenNames:void 0,reads:i&&[...i]};const o=fw(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: ${Ca(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 $=bm(r.get(k.given),c.get(k.given))??dw(l.get(k.given));$!==void 0&&v.push(`${C} ${$}`)}const b=v.join(", "),w=t.chart,h=w==="none"||Os(w)?Zn(w,t.chartCarried):w==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
143
|
`):w==="default"&&uw(t.declaration)?ym():void 0,x=t.color!==void 0?wd(t.color):t.declaration.kind!=="reference"&&!t.ownPalette?wm: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 mw({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:i,reportsSettled:s}){const{apiClients:o,server:a}=ka(),{data:d}=Sa({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=mm({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?X0(l.flatMap((g,v)=>g.data?[{...g.data,path:c[v]}]:[]),f):void 0,[u,c,p,f])}const gw={};function vw({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}=ka(),[y,k]=S.useState(o.document.tiles.length>0);S.useEffect(()=>k(o.document.tiles.length>0),[o.generation,o.document]);const{data:E,isSuccess:$,isError:T}=Sa({...Tp(x,{environmentName:t,packageName:n,path:r,versionId:s},pm),enabled:y&&!e}),j=e?.modelPath??r,M=bw(o.source,e?.compileSource),I=Op({environmentName:t,packageName:n,modelPath:j,source:M.text??o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&M.text!==void 0}),W=I.data?.document,A=e?I.isSuccess?W?.manifest??gw:void 0:E,z=e?I.isSuccess:$,_=e?I.isError||M.problem!==void 0:T,q=e?Dp(W?.cells):void 0,P=(I.data?.result.problems??[]).filter(R=>R.severity==="error"),F=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),C=e?.givens,O=S.useMemo(()=>new Set((A?.tiles??[]).flatMap(R=>R.restricted&&R.query?[Ft(R.query)]:[])),[A]),{reports:N,settled:H}=Ap(t,n,s),K=S.useMemo(()=>N.map(R=>R.path).filter(R=>!!R&&R!==r&&R.endsWith(".malloy")).map(R=>R.replace(/\.malloy$/,"")),[N,r]),Y=mw({environmentName:t,packageName:n,...s!==void 0?{versionId:s}:{},modelPath:r,reports:N,reportsSettled:H}),te=S.useMemo(()=>e?(Y?.sources??[]).filter(R=>(R.visibleIn??R.exporters??[R.modelPath]).includes(j)).map(R=>R.name):void 0,[Y,e,j]),xe=S.useMemo(()=>h?Y0(h):void 0,[h]),me=S.useMemo(()=>{const R=Y&&te?{sources:Y.sources.filter(ce=>te.includes(ce.name))}:Y;return R&&xe?{...R,documentViews:xe}:R},[Y,te,xe]),[ne,Ce]=S.useState(o.document);S.useEffect(()=>Ce(o.document),[o.document]);const J=S.useMemo(()=>d&&(async(R,ce)=>{await d(R,ce.document.layout),v==="package"&&k(ce.document.tiles.length>0)}),[d,v]),Ve=S.useMemo(()=>(A?.givens??[]).filter(R=>!(e&&R.secure===!0)&&!(R.name!==void 0&&F.has(R.name))),[A,F,e]),Ae=S.useMemo(()=>new Set([...Ve.map(R=>R.name).filter(R=>R!==void 0),...Object.keys(C??{})]),[Ve,C]),G=S.useMemo(()=>new Map((A?.tiles??[]).flatMap(R=>R.kind!=="text"&&R.query&&R.givenNames?[[Ft(R.query),R.givenNames]]:[])),[A]),ye=S.useMemo(()=>new Map((A?.tiles??[]).flatMap(R=>R.kind!=="text"&&R.query&&R.label?[[Ft(R.query),R.label]]:[])),[A]),be=S.useMemo(()=>cw(ne,o.document,G),[ne,o.document,G]),re=S.useMemo(()=>lw(ne,Ve,be,G),[ne,Ve,be,G]),Pe=S.useMemo(()=>{const R=new Set(ne.tiles.flatMap(ee=>oe(ee)?(ee.filters??[]).map(et=>et.given):[])),ce=new Set((ne.localGivens??[]).map(ee=>ee.name)),Je=[...new Set(ne.imports.map(ee=>ee.from))],Fe=Je.length===1?yw(r,Je[0]):Je.length===0&&e?e.modelPath:void 0,st=ee=>{const et=ne.sources.filter(X=>X.scopedBy?.includes(ee)).map(X=>X.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.`}:ce.has(ee)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:Fe!==void 0?{reason:`Set in the model ${Fe}. Edit the model to change it.`,modelPath:Fe}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...be].filter(ee=>!R.has(ee)).map(ee=>[ee,st(ee)]))},[ne,be,e,r]),{declaredTypes:Ke,applied:Re,panel:Qe}=Pp({specs:re,loaded:z,startingValues:A?.startingGivens,documentKey:`${t}/${n}/${i??""}/${r}/edit`,autorun:A?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?j:A?.path,versionId:s,documentName:r,...q!==void 0?{preamble:q}:{},...C?{hostGivens:C}:{}}),Ze=S.useMemo(()=>Rp(re,Re,C),[re,Re,C]),D=S.useMemo(()=>Object.fromEntries(Object.entries(C??{}).filter(([R])=>!Ke.has(R))),[C,Ke]),L=!y||z||_,U=e!==void 0&&(M.problem!==void 0||I.isError||P.length>0),V=S.useMemo(()=>new Map(o.document.tiles.map(R=>[ue(R),R])),[o.document]),we=S.useMemo(()=>hw(ne,o.document,r,!!e),[ne,o.document,r,e]),je=S.useMemo(()=>function(R,ce,Je="card"){const Fe=(cr(R)?ye.get(Ft(vt(R))):void 0)??Ds(R);if(U)return m.jsxs(xo,{chrome:Je,children:[m.jsx(bo,{title:ce?.title??Fe,subtitle:ce?ce.subtitle:R.subtitle}),m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!L)return m.jsxs(xo,{chrome:Je,children:[m.jsx(bo,{title:ce?.title??Fe,subtitle:ce?ce.subtitle:R.subtitle}),m.jsx(go,{text:"Running…"})]});const st=G.get(Ft(vt(R))),ee=q===void 0&&st!==void 0&&xw(V.get(ue(R)),R)?{expression:vt(R),givenNames:[...st],reads:[...st]}:pw(ne,R,Ae,Re,st,we),et=sd(ne.layout,ne.columns);return m.jsx(Nl,{environmentName:t,packageName:n,versionId:s,modelPath:ee.modelPath??j,...q!==void 0&&ee.modelPath===void 0?{preamble:q}:{},...O.has(Ft(vt(R)))?{restricted:!0}:{},tile:ee.expression,...ee.annotation?{annotation:ee.annotation}:{},label:Fe,chrome:Je,subtitle:R.subtitle,...ce?{heading:ce}:{},borderless:R.borderless,givens:Re,hostGivens:D,declaredTypes:Ke,givenNames:ee.givenNames,...(()=>{const X=Np(Ze,ee.reads??ee.givenNames);return X.length>0?{waitingFor:Wp(X)}:{}})(),ignoredFilters:Ip(ee.reads,re),height:R.rowspan!==void 0||rn(ne.tiles)?dd(R.rowspan??ja.query):et.tileMaxHeight,tableMaxHeight:et.tableMaxHeight,fixedHeight:R.rowspan!==void 0||rn(ne.tiles)})},[ne,V,L,U,Ze,Ae,G,ye,t,n,s,j,q,we,O,Re,D,Ke,re]),Mt=S.useMemo(()=>function(R){return m.jsx(Nl,{environmentName:t,packageName:n,versionId:s,modelPath:R.modelPath,tile:`${R.base} -> ${R.view}`,...R.chart?{annotation:Qn(R.chart,R.chartCarried)}:{},label:R.label,borderless:!0,givens:Re,hostGivens:D,declaredTypes:Ke,givenNames:R.givens,height:200})},[t,n,s,Re,D,Ke]);return m.jsxs(ft,{sx:{gap:1},children:[e&&P.length>0&&m.jsxs(ht,{severity:"error",children:["The server could not compile this document:"," ",P.map(R=>R.message).join("; ")]}),Ze.length>0&&!U&&m.jsx(ht,{severity:"info",children:Lp(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(Qf,{...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:re.filter(R=>R.name!==void 0).map(R=>({name:R.name,...R.label?{label:R.label}:{},...R.type?{type:R.type}:{},...R.suggest?.dimension?{field:R.suggest.dimension}:{}})),onChange:Ce,onDirtyChange:f,...c?{onExit:c}:{},...l?{onOpenModel:l}:{},...u?{onControlsChange:u}:{},...p!==void 0?{draftKey:p}:{},...me?{catalog:me}:{},dashboards:K,...g?{onEvent:g}:{},controls:z?m.jsx(zp,{...Qe,layout:"bar"}):void 0,...J?{onSave:J}:{},savesTo:v,...b?{saveLabel:b}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:te}:{}}),m.jsx(B,{sx:{px:.5},children:m.jsx(pe,{variant:"caption",sx:{opacity:.7},children:w})})]})}function xw(e,t){return e!==void 0&&JSON.stringify(rd(e))===JSON.stringify(rd(t))}function rd(e){const{label:t,subtitle:n,colspan:r,break:i,rowspan:s,row:o,col:a,borderless:d,...f}=e;return f}function bw(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 yw(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 ww({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=Sp(await e.listWorkspaces(!1));if(b)return;if(a(w),w!==void 0&&(!n||w.authoritative)){const h=await e.getDocument(hd(t,w.name,r,i,s)).catch(x=>{if(!fd(x))throw x});if(b)return;f(h),p(h!==void 0)}}catch(w){if(b)return;v(pd(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 kw=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Sw(e){const t=await ga(e);return ma(t)?{ok:!1,reason:kw(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.",jw="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Mw({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((G,ye)=>{try{g.current?.($p(G,{...v.current,...ye?{layout:ye}:{}}))}catch{}}),w=e?.authoritative===!0,h=w&&r!==void 0,[x,y]=S.useState(void 0),k=(w||x===!0)&&t!==void 0,[E,$]=S.useState(void 0),[T,j]=S.useState(l?$w:void 0),M=S.useRef(void 0),I=S.useRef(void 0),[W,A]=S.useState(void 0),z=S.useRef(s);z.current=s;const _=W!==void 0&&W.onFetch===s?W.text:i,q=S.useRef(_);q.current=_;const P=k?t:_,[F,C]=S.useState(!1),[O,N]=S.useState(void 0),[H,K]=S.useState(void 0),Y=P!==void 0&&P!==H,te=E?.source,xe=Y&&(F||!w&&t!==void 0&&te===t&&t!==_)&&te!==void 0&&P!==O,me=xe?te:Y?P:te??P,ne=xe?P:void 0,Ce=S.useRef(te);Ce.current=te;const J=S.useRef(P);J.current=P;const Ve=S.useRef("package");Ve.current=k?w?"record":"draft":"package",S.useEffect(()=>{if(me===void 0||!n||h||me===Ce.current)return;let G=!1;const ye=q.current,be=J.current;return Sw(me).then(re=>{if(!G){if(re.ok===!1){j(re.reason),b.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}j(void 0),M.current=void 0,I.current=ye,A(void 0),N(void 0),K(be),$(Pe=>({source:me,document:re.document,...ye!==void 0?{packageText:ye}:{},generation:(Pe?.generation??0)+1})),b.current({type:"report.opened",surface:"edit",from:Ve.current,tiles:re.document.tiles.length,durationMs:Qt()-p.current},re.document.layout)}}).catch(re=>{if(G)return;const Pe=`Could not read the ${c}: ${re instanceof Error?re.message:String(re)}`;j(Pe),b.current({type:"report.load_failed",surface:"edit",category:ad(re)})}),()=>{G=!0}},[me,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||E||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,E,r,w,t]);const Ae=f&&!u&&!E&&n&&!k&&o&&i===void 0;return S.useEffect(()=>{Ae&&(j(jw),b.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Ae]),{authoritative:w,blockedOnRecord:h,resume:x,setResume:y,fromDraft:k,opened:E,setOpened:$,openError:T,savedHashRef:M,packageBaseRef:I,setWrote:A,fetchedAtRef:z,setDirty:C,setSeen:K,held:ne,choose:G=>{p.current=Qt(),N(G?t:_),y(G)},acceptHeld:()=>{p.current=Qt(),N(ne)}}}function Cw({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:E,fetchedAtRef:$}){const T=S.useCallback(C=>t===void 0?void 0:hd(C,t.name,i,s,o),[t,i,s,o]),j=T(n),M=S.useCallback(async(C,O=n)=>{const N=T(O);if(!e||!N)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(N,C),b(H=>H&&{...H,source:C}),w(C),(p||g===!0)&&x(C),p||v(H=>H??!1)},[e,T,n,p,g,b,w,x,v]),[I,W]=S.useState(void 0),A=S.useCallback(async C=>{const O=await jp(k.current,E.current);if(O===void 0)throw new Error("The package file is still loading; try again.");const N=["dashboard-editor-model",i,s,o,a,r];await Mp({apiClients:d,queryClient:f,environmentName:i,packageName:s,modelPath:o,source:C,expectedHash:O,invalidateOnError:[N],afterWrite:async H=>{if(b(K=>K&&{...K,source:C}),y({text:C,onFetch:$.current}),x(C),k.current=H,W(void 0),e&&j)try{await e.deleteDocument(j),w(void 0),h(!1)}catch(K){fd(K)?(w(void 0),h(!1)):W(pd(K))}v(!1)},invalidate:[{queryKey:N,wait:!0},{queryKey:fm({environmentName:i,packageName:s,versionId:a,modelPath:o})}]}),Cp(f,i,s,o)},[d,i,s,o,a,r,e,j,f,k,E,$,b,y,x,w,h,v]),z=t?.writeable===!0,_=c===!0&&!l,{savesTo:q,pinnedPackageSave:P,writer:F}=hm({authoritative:p,mutable:_,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!j&&z&&(!r||p),readFailed:u!==void 0});return{save:F==="storage"?M:F==="package"?A:void 0,savesTo:q,writer:F,pinnedPackageSave:P,takesWrites:_,supersedeFailure:I}}function Zf(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?ip(d):"grid"),p=u==="linear",g=c!==void 0,{environmentName:v,packageName:b,versionId:w,namesBoth:h}=sp(e),x=("resourceUri"in e?e.dashboard:e.dashboardName)??op(f)??"",y="report",{apiClients:k,mutable:E,isLoadingStatus:$,server:T}=ka(),j=ap(),M=S.useRef(Qt()),I=S.useRef(t);I.current=t;const W=S.useRef(r);W.current=r;const A=lp()?.documentStorage,z=f??kp(d??"dashboard",x),_=/\.malloynb$/i.test(z)||p&&/\.malloynb$/i.test(x),q=Sa({queryKey:["dashboard-editor-model",v,b,z,w,p],queryFn:()=>k.models.getModel(v,b,z,w,p?!0:void 0),enabled:h&&!_&&!g}),P=q.data?.data?.sourceText,{workspace:F,draft:C,setDraft:O,draftChecked:N,offered:H,setOffered:K,readFailure:Y}=ww({storage:A,layout:u,notebook:p,environmentName:v,packageName:b,modelPath:z}),{authoritative:te,blockedOnRecord:xe,resume:me,setResume:ne,fromDraft:Ce,opened:J,setOpened:Ve,openError:Ae,savedHashRef:G,packageBaseRef:ye,setWrote:be,fetchedAtRef:re,setDirty:Pe,setSeen:Ke,held:Re,choose:Qe,acceptHeld:Ze}=Mw({workspace:F,draft:C,draftChecked:N,readFailure:Y,packageText:P,fetchedAt:q.dataUpdatedAt,packageSettled:q.isSuccess&&!q.isFetching,modelPath:z,layout:u,notebook:p,noun:y,legacyFormat:_,textHeld:g,startedAt:M,onEventRef:I}),{save:D,savesTo:L,writer:U,pinnedPackageSave:V,takesWrites:we,supersedeFailure:je}=Cw({storage:A,workspace:F,layout:u,notebook:p,environmentName:v,packageName:b,modelPath:z,versionId:w,apiClients:k,queryClient:j,mutable:E,textHeld:g,readFailure:Y,authoritative:te,resume:me,setResume:ne,setOpened:Ve,setDraft:O,setOffered:K,setSeen:Ke,setWrote:be,savedHashRef:G,packageBaseRef:ye,fetchedAtRef:re}),Mt=F?.name,R=S.useCallback(ge=>{I.current?.(cp(ge,Mt))},[Mt]),ce=q.isError&&!J,Je=S.useRef(!1);S.useEffect(()=>{!ce||Je.current||(Je.current=!0,od({path:z,layout:u},I.current).emit({type:"report.load_failed",surface:"edit",category:ad(q.error)}))},[ce,q.error,z,u]);const Fe=S.useCallback((ge,dn)=>{Pe(ge),W.current?.(dn)},[Pe]),st=!c&&q.data?.data&&P!==void 0&&J?.source===P?q.data.data:void 0,ee=a?Ep({server:T,environmentName:v,packageName:b,versionId:w,path:f??x}):void 0,et=L==="host"&&F?.description?F.description:void 0,X=!te&&!g&&E===void 0?$?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":dp({authoritative:te,mutable:we,pinnedPackageSave:V,...F?{workspace:F}:{},...Y!==void 0?{readFailure:Y}:{},...w!==void 0?{versionId:w}:{}}),de=L==="package"&&we===!0&&!V&&Y===void 0||X===et?"":X;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(Ae)return m.jsxs(ht,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened in the builder: ",Ae]});if(q.isError&&!J)return m.jsx(up,{error:q.error,context:`Opening the ${y}`});if(!J&&(!(g||P)||!N))return n??m.jsx(go,{text:`Opening the ${y}…`});if(xe)return m.jsxs(ht,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened: ",Y]});const Ie=C!==void 0&&C!==P;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&&!te&&H&&Ie&&me===void 0&&m.jsx(ht,{severity:"info",action:m.jsxs(ft,{direction:"row",sx:{gap:1},children:[m.jsx(De,{size:"small",onClick:()=>Qe(!0),children:"Resume"}),m.jsx(De,{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."}),Re!==void 0&&m.jsx(ht,{severity:"warning",action:m.jsx(De,{size:"small",onClick:()=>{ee!==void 0&&hp(ee),Ze()},children:"Load it"}),children:L==="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.":L==="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]}),!J&&(n??m.jsx(go,{text:`Opening the ${y}…`})),J&&m.jsx(vw,{environmentName:v,packageName:b,modelPath:z,...c?{textSource:c}:{},slug:x,...w!==void 0?{versionId:w}:{},...(l??w)!==void 0?{queryVersionId:l??w}:{},opened:J,...Ce&&U==="package"&&J.packageText!==void 0?{replaces:J.packageText}:{},onSave:D,onDirtyChange:Fe,...i?{onExit:i}:{},...s?{onOpenModel:s}:{},...o?{onControlsChange:o}:{},...ee!==void 0?{draftKey:ee}:{},savesTo:L,...et?{saveLabel:et}:{},...t?{onEvent:R}:{},note:de,...st?{fileModel:st}:{}},J.generation)]})}const Aw=Zf,Pw=Qf;function Rw(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(Zf,{...s,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:zl===void 0&&(zl={});export{Dw as BuilderBar,Pw as DashboardBuilder,Aw as DashboardEditor,Ww as MAX_SLUG_ATTEMPTS,Rw as NotebookEditor,Qf as ReportBuilder,Zf as ReportEditor,X0 as buildCatalog,Lw as createDocument,zw as createRoute,hd as locatorFor,Fw as newDashboardSource,Bw as newDocumentProblem,_w as newNotebookSource,ga as readDashboardDocument,ma as readFailed,Ow as readReportTagOfText,qw as reportPathFor,Hw as reportPathForTitle,Uw as slugFor,Vw as slugOrFallback,d0 as spliceDashboardDocument,va as spliceFailed,Kw as useDocumentChoices};
|
|
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 mw({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:i,reportsSettled:s}){const{apiClients:o,server:a}=ka(),{data:d}=Sa({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=mm({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?X0(l.flatMap((g,v)=>g.data?[{...g.data,path:c[v]}]:[]),f):void 0,[u,c,p,f])}const gw={};function vw({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}=ka(),[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}=Sa({...Tp(x,{environmentName:t,packageName:n,path:r,versionId:s},pm),enabled:y&&!e}),j=e?.modelPath??r,M=bw(o.source,e?.compileSource),I=Op({environmentName:t,packageName:n,modelPath:j,source:M.text??o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&M.text!==void 0}),W=I.data?.document,A=e?I.isSuccess?W?.manifest??gw:void 0:C,z=e?I.isSuccess:$,_=e?I.isError||M.problem!==void 0:T,q=e?Dp(W?.cells):void 0,P=(I.data?.result.problems??[]).filter(R=>R.severity==="error"),F=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),E=e?.givens,O=S.useMemo(()=>new Set((A?.tiles??[]).flatMap(R=>R.restricted&&R.query?[Ft(R.query)]:[])),[A]),{reports:N,settled:H}=Ap(t,n,s),K=S.useMemo(()=>N.map(R=>R.path).filter(R=>!!R&&R!==r&&R.endsWith(".malloy")).map(R=>R.replace(/\.malloy$/,"")),[N,r]),Y=mw({environmentName:t,packageName:n,...s!==void 0?{versionId:s}:{},modelPath:r,reports:N,reportsSettled:H}),te=S.useMemo(()=>e?(Y?.sources??[]).filter(R=>(R.visibleIn??R.exporters??[R.modelPath]).includes(j)).map(R=>R.name):void 0,[Y,e,j]),xe=S.useMemo(()=>h?Y0(h):void 0,[h]),me=S.useMemo(()=>{const R=Y&&te?{sources:Y.sources.filter(ce=>te.includes(ce.name))}:Y;return R&&xe?{...R,documentViews:xe}:R},[Y,te,xe]),[ne,Ee]=S.useState(o.document);S.useEffect(()=>Ee(o.document),[o.document]);const J=S.useMemo(()=>d&&(async(R,ce)=>{await d(R,ce.document.layout),v==="package"&&k(ce.document.tiles.length>0)}),[d,v]),Ve=S.useMemo(()=>(A?.givens??[]).filter(R=>!(e&&R.secure===!0)&&!(R.name!==void 0&&F.has(R.name))),[A,F,e]),Ae=S.useMemo(()=>new Set([...Ve.map(R=>R.name).filter(R=>R!==void 0),...Object.keys(E??{})]),[Ve,E]),G=S.useMemo(()=>new Map((A?.tiles??[]).flatMap(R=>R.kind!=="text"&&R.query&&R.givenNames?[[Ft(R.query),R.givenNames]]:[])),[A]),ye=S.useMemo(()=>new Map((A?.tiles??[]).flatMap(R=>R.kind!=="text"&&R.query&&R.label?[[Ft(R.query),R.label]]:[])),[A]),be=S.useMemo(()=>cw(ne,o.document,G),[ne,o.document,G]),re=S.useMemo(()=>lw(ne,Ve,be,G),[ne,Ve,be,G]),Pe=S.useMemo(()=>{const R=new Set(ne.tiles.flatMap(ee=>oe(ee)?(ee.filters??[]).map(et=>et.given):[])),ce=new Set((ne.localGivens??[]).map(ee=>ee.name)),Je=[...new Set(ne.imports.map(ee=>ee.from))],Fe=Je.length===1?yw(r,Je[0]):Je.length===0&&e?e.modelPath:void 0,st=ee=>{const et=ne.sources.filter(X=>X.scopedBy?.includes(ee)).map(X=>X.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.`}:ce.has(ee)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:Fe!==void 0?{reason:`Set in the model ${Fe}. Edit the model to change it.`,modelPath:Fe}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...be].filter(ee=>!R.has(ee)).map(ee=>[ee,st(ee)]))},[ne,be,e,r]),{declaredTypes:Ke,applied:Re,panel:Ze}=Pp({specs:re,loaded:z,startingValues:A?.startingGivens,documentKey:`${t}/${n}/${i??""}/${r}/edit`,autorun:A?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?j:A?.path,versionId:s,documentName:r,...q!==void 0?{preamble:q}:{},...E?{hostGivens:E}:{}}),Qe=S.useMemo(()=>Rp(re,Re,E),[re,Re,E]),D=S.useMemo(()=>Object.fromEntries(Object.entries(E??{}).filter(([R])=>!Ke.has(R))),[E,Ke]),L=!y||z||_,U=e!==void 0&&(M.problem!==void 0||I.isError||P.length>0),V=S.useMemo(()=>new Map(o.document.tiles.map(R=>[ue(R),R])),[o.document]),we=S.useMemo(()=>hw(ne,o.document,r,!!e),[ne,o.document,r,e]),je=S.useMemo(()=>function(R,ce,Je="card"){const Fe=(cr(R)?ye.get(Ft(vt(R))):void 0)??Ds(R);if(U)return m.jsxs(xo,{chrome:Je,children:[m.jsx(bo,{title:ce?.title??Fe,subtitle:ce?ce.subtitle:R.subtitle}),m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!L)return m.jsxs(xo,{chrome:Je,children:[m.jsx(bo,{title:ce?.title??Fe,subtitle:ce?ce.subtitle:R.subtitle}),m.jsx(go,{text:"Running…"})]});const st=G.get(Ft(vt(R))),ee=q===void 0&&st!==void 0&&xw(V.get(ue(R)),R)?{expression:vt(R),givenNames:[...st],reads:[...st]}:pw(ne,R,Ae,Re,st,we),et=sd(ne.layout,ne.columns);return m.jsx(Nl,{environmentName:t,packageName:n,versionId:s,modelPath:ee.modelPath??j,...q!==void 0&&ee.modelPath===void 0?{preamble:q}:{},...O.has(Ft(vt(R)))?{restricted:!0}:{},tile:ee.expression,...ee.annotation?{annotation:ee.annotation}:{},label:Fe,chrome:Je,subtitle:R.subtitle,...ce?{heading:ce}:{},borderless:R.borderless,givens:Re,hostGivens:D,declaredTypes:Ke,givenNames:ee.givenNames,...(()=>{const X=Np(Qe,ee.reads??ee.givenNames);return X.length>0?{waitingFor:Wp(X)}:{}})(),ignoredFilters:Ip(ee.reads,re),height:R.rowspan!==void 0||rn(ne.tiles)?dd(R.rowspan??ja.query):et.tileMaxHeight,tableMaxHeight:et.tableMaxHeight,fixedHeight:R.rowspan!==void 0||rn(ne.tiles)})},[ne,V,L,U,Qe,Ae,G,ye,t,n,s,j,q,we,O,Re,D,Ke,re]),Mt=S.useMemo(()=>function(R){return m.jsx(Nl,{environmentName:t,packageName:n,versionId:s,modelPath:R.modelPath,tile:`${R.base} -> ${R.view}`,...R.chart?{annotation:Zn(R.chart,R.chartCarried)}:{},label:R.label,borderless:!0,givens:Re,hostGivens:D,declaredTypes:Ke,givenNames:R.givens,height:200})},[t,n,s,Re,D,Ke]);return m.jsxs(ft,{sx:{gap:1},children:[e&&P.length>0&&m.jsxs(ht,{severity:"error",children:["The server could not compile this document:"," ",P.map(R=>R.message).join("; ")]}),Qe.length>0&&!U&&m.jsx(ht,{severity:"info",children:Lp(Qe)}),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(Zf,{...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:re.filter(R=>R.name!==void 0).map(R=>({name:R.name,...R.label?{label:R.label}:{},...R.type?{type:R.type}:{},...R.suggest?.dimension?{field:R.suggest.dimension}:{}})),onChange:Ee,onDirtyChange:f,...c?{onExit:c}:{},...l?{onOpenModel:l}:{},...u?{onControlsChange:u}:{},...p!==void 0?{draftKey:p}:{},...me?{catalog:me}:{},dashboards:K,...g?{onEvent:g}:{},controls:z?m.jsx(zp,{...Ze,layout:"bar"}):void 0,...J?{onSave:J}:{},savesTo:v,...b?{saveLabel:b}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:te}:{}}),m.jsx(B,{sx:{px:.5},children:m.jsx(pe,{variant:"caption",sx:{opacity:.7},children:w})})]})}function xw(e,t){return e!==void 0&&JSON.stringify(rd(e))===JSON.stringify(rd(t))}function rd(e){const{label:t,subtitle:n,colspan:r,break:i,rowspan:s,row:o,col:a,borderless:d,...f}=e;return f}function bw(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 yw(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 ww({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=Sp(await e.listWorkspaces(!1));if(b)return;if(a(w),w!==void 0&&(!n||w.authoritative)){const h=await e.getDocument(hd(t,w.name,r,i,s)).catch(x=>{if(!fd(x))throw x});if(b)return;f(h),p(h!==void 0)}}catch(w){if(b)return;v(pd(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 kw=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Sw(e){const t=await ga(e);return ma(t)?{ok:!1,reason:kw(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.",jw="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Mw({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((G,ye)=>{try{g.current?.($p(G,{...v.current,...ye?{layout:ye}:{}}))}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),[W,A]=S.useState(void 0),z=S.useRef(s);z.current=s;const _=W!==void 0&&W.onFetch===s?W.text:i,q=S.useRef(_);q.current=_;const P=k?t:_,[F,E]=S.useState(!1),[O,N]=S.useState(void 0),[H,K]=S.useState(void 0),Y=P!==void 0&&P!==H,te=C?.source,xe=Y&&(F||!w&&t!==void 0&&te===t&&t!==_)&&te!==void 0&&P!==O,me=xe?te:Y?P:te??P,ne=xe?P:void 0,Ee=S.useRef(te);Ee.current=te;const J=S.useRef(P);J.current=P;const Ve=S.useRef("package");Ve.current=k?w?"record":"draft":"package",S.useEffect(()=>{if(me===void 0||!n||h||me===Ee.current)return;let G=!1;const ye=q.current,be=J.current;return Sw(me).then(re=>{if(!G){if(re.ok===!1){j(re.reason),b.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}j(void 0),M.current=void 0,I.current=ye,A(void 0),N(void 0),K(be),$(Pe=>({source:me,document:re.document,...ye!==void 0?{packageText:ye}:{},generation:(Pe?.generation??0)+1})),b.current({type:"report.opened",surface:"edit",from:Ve.current,tiles:re.document.tiles.length,durationMs:Zt()-p.current},re.document.layout)}}).catch(re=>{if(G)return;const Pe=`Could not read the ${c}: ${re instanceof Error?re.message:String(re)}`;j(Pe),b.current({type:"report.load_failed",surface:"edit",category:ad(re)})}),()=>{G=!0}},[me,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 Ae=f&&!u&&!C&&n&&!k&&o&&i===void 0;return S.useEffect(()=>{Ae&&(j(jw),b.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Ae]),{authoritative:w,blockedOnRecord:h,resume:x,setResume:y,fromDraft:k,opened:C,setOpened:$,openError:T,savedHashRef:M,packageBaseRef:I,setWrote:A,fetchedAtRef:z,setDirty:E,setSeen:K,held:ne,choose:G=>{p.current=Zt(),N(G?t:_),y(G)},acceptHeld:()=>{p.current=Zt(),N(ne)}}}function Ew({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:hd(E,t.name,i,s,o),[t,i,s,o]),j=T(n),M=S.useCallback(async(E,O=n)=>{const N=T(O);if(!e||!N)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(N,E),b(H=>H&&{...H,source:E}),w(E),(p||g===!0)&&x(E),p||v(H=>H??!1)},[e,T,n,p,g,b,w,x,v]),[I,W]=S.useState(void 0),A=S.useCallback(async E=>{const O=await jp(k.current,C.current);if(O===void 0)throw new Error("The package file is still loading; try again.");const N=["dashboard-editor-model",i,s,o,a,r];await Mp({apiClients:d,queryClient:f,environmentName:i,packageName:s,modelPath:o,source:E,expectedHash:O,invalidateOnError:[N],afterWrite:async H=>{if(b(K=>K&&{...K,source:E}),y({text:E,onFetch:$.current}),x(E),k.current=H,W(void 0),e&&j)try{await e.deleteDocument(j),w(void 0),h(!1)}catch(K){fd(K)?(w(void 0),h(!1)):W(pd(K))}v(!1)},invalidate:[{queryKey:N,wait:!0},{queryKey:fm({environmentName:i,packageName:s,versionId:a,modelPath:o})}]}),Ep(f)},[d,i,s,o,a,r,e,j,f,k,C,$,b,y,x,w,h,v]),z=t?.writeable===!0,_=c===!0&&!l,{savesTo:q,pinnedPackageSave:P,writer:F}=hm({authoritative:p,mutable:_,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!j&&z&&(!r||p),readFailed:u!==void 0});return{save:F==="storage"?M:F==="package"?A:void 0,savesTo:q,writer:F,pinnedPackageSave:P,takesWrites:_,supersedeFailure:I}}function Qf(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?ip(d):"grid"),p=u==="linear",g=c!==void 0,{environmentName:v,packageName:b,versionId:w,namesBoth:h}=sp(e),x=("resourceUri"in e?e.dashboard:e.dashboardName)??op(f)??"",y="report",{apiClients:k,mutable:C,isLoadingStatus:$,server:T}=ka(),j=ap(),M=S.useRef(Zt()),I=S.useRef(t);I.current=t;const W=S.useRef(r);W.current=r;const A=lp()?.documentStorage,z=f??kp(d??"dashboard",x),_=/\.malloynb$/i.test(z)||p&&/\.malloynb$/i.test(x),q=Sa({queryKey:["dashboard-editor-model",v,b,z,w,p],queryFn:()=>k.models.getModel(v,b,z,w,p?!0:void 0),enabled:h&&!_&&!g}),P=q.data?.data?.sourceText,{workspace:F,draft:E,setDraft:O,draftChecked:N,offered:H,setOffered:K,readFailure:Y}=ww({storage:A,layout:u,notebook:p,environmentName:v,packageName:b,modelPath:z}),{authoritative:te,blockedOnRecord:xe,resume:me,setResume:ne,fromDraft:Ee,opened:J,setOpened:Ve,openError:Ae,savedHashRef:G,packageBaseRef:ye,setWrote:be,fetchedAtRef:re,setDirty:Pe,setSeen:Ke,held:Re,choose:Ze,acceptHeld:Qe}=Mw({workspace:F,draft:E,draftChecked:N,readFailure:Y,packageText:P,fetchedAt:q.dataUpdatedAt,packageSettled:q.isSuccess&&!q.isFetching,modelPath:z,layout:u,notebook:p,noun:y,legacyFormat:_,textHeld:g,startedAt:M,onEventRef:I}),{save:D,savesTo:L,writer:U,pinnedPackageSave:V,takesWrites:we,supersedeFailure:je}=Ew({storage:A,workspace:F,layout:u,notebook:p,environmentName:v,packageName:b,modelPath:z,versionId:w,apiClients:k,queryClient:j,mutable:C,textHeld:g,readFailure:Y,authoritative:te,resume:me,setResume:ne,setOpened:Ve,setDraft:O,setOffered:K,setSeen:Ke,setWrote:be,savedHashRef:G,packageBaseRef:ye,fetchedAtRef:re}),Mt=F?.name,R=S.useCallback(ge=>{I.current?.(cp(ge,Mt))},[Mt]),ce=q.isError&&!J,Je=S.useRef(!1);S.useEffect(()=>{!ce||Je.current||(Je.current=!0,od({path:z,layout:u},I.current).emit({type:"report.load_failed",surface:"edit",category:ad(q.error)}))},[ce,q.error,z,u]);const Fe=S.useCallback((ge,dn)=>{Pe(ge),W.current?.(dn)},[Pe]),st=!c&&q.data?.data&&P!==void 0&&J?.source===P?q.data.data:void 0,ee=a?Cp({server:T,environmentName:v,packageName:b,versionId:w,path:f??x}):void 0,et=L==="host"&&F?.description?F.description:void 0,X=!te&&!g&&C===void 0?$?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":dp({authoritative:te,mutable:we,pinnedPackageSave:V,...F?{workspace:F}:{},...Y!==void 0?{readFailure:Y}:{},...w!==void 0?{versionId:w}:{}}),de=L==="package"&&we===!0&&!V&&Y===void 0||X===et?"":X;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(Ae)return m.jsxs(ht,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened in the builder: ",Ae]});if(q.isError&&!J)return m.jsx(up,{error:q.error,context:`Opening the ${y}`});if(!J&&(!(g||P)||!N))return n??m.jsx(go,{text:`Opening the ${y}…`});if(xe)return m.jsxs(ht,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened: ",Y]});const Ie=E!==void 0&&E!==P;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&&!te&&H&&Ie&&me===void 0&&m.jsx(ht,{severity:"info",action:m.jsxs(ft,{direction:"row",sx:{gap:1},children:[m.jsx(De,{size:"small",onClick:()=>Ze(!0),children:"Resume"}),m.jsx(De,{size:"small",onClick:()=>Ze(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),Re!==void 0&&m.jsx(ht,{severity:"warning",action:m.jsx(De,{size:"small",onClick:()=>{ee!==void 0&&hp(ee),Qe()},children:"Load it"}),children:L==="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.":L==="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]}),!J&&(n??m.jsx(go,{text:`Opening the ${y}…`})),J&&m.jsx(vw,{environmentName:v,packageName:b,modelPath:z,...c?{textSource:c}:{},slug:x,...w!==void 0?{versionId:w}:{},...(l??w)!==void 0?{queryVersionId:l??w}:{},opened:J,...Ee&&U==="package"&&J.packageText!==void 0?{replaces:J.packageText}:{},onSave:D,onDirtyChange:Fe,...i?{onExit:i}:{},...s?{onOpenModel:s}:{},...o?{onControlsChange:o}:{},...ee!==void 0?{draftKey:ee}:{},savesTo:L,...et?{saveLabel:et}:{},...t?{onEvent:R}:{},note:de,...st?{fileModel:st}:{}},J.generation)]})}const Aw=Qf,Pw=Zf;function Rw(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(Qf,{...s,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:zl===void 0&&(zl={});export{Dw as BuilderBar,Pw as DashboardBuilder,Aw as DashboardEditor,Ww as MAX_SLUG_ATTEMPTS,Rw as NotebookEditor,Zf as ReportBuilder,Qf as ReportEditor,X0 as buildCatalog,Lw as createDocument,zw as createRoute,hd as locatorFor,Fw as newDashboardSource,Bw as newDocumentProblem,_w as newNotebookSource,ga as readDashboardDocument,ma as readFailed,Ow as readReportTagOfText,qw as reportPathFor,Hw as reportPathForTitle,Uw as slugFor,Vw as slugOrFallback,d0 as spliceDashboardDocument,va as spliceFailed,Kw as useDocumentChoices};
|