@malloy-publisher/app 0.9.10 → 0.9.12
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 +121 -45
- package/dist/assets/{EnvironmentPage-DfL-2Fy5.js → EnvironmentPage-BFcCRfvE.js} +1 -1
- package/dist/assets/{HomePage-Cc5z85GD.js → HomePage-C0LnSonK.js} +1 -1
- package/dist/assets/MainPage-D3EM60u0.js +1 -0
- package/dist/assets/ModelPage-B1wvZV7r.js +2 -0
- package/dist/assets/PackagePage-QZ59dwip.js +1 -0
- package/dist/assets/RenderedResult-CDiXJAh9.es-C9BYYEfH.js +153 -0
- package/dist/assets/{RouteError-Bc7-ukP7.js → RouteError-v8LP_Q9x.js} +1 -1
- package/dist/assets/ThemeEditorPage-B5l2nzAq.js +1 -0
- package/dist/assets/ToggleButtonGroup-C6Lespxy.js +1 -0
- package/dist/assets/{documentRoutes-CvCc_EZs.js → documentRoutes-xv0fP4cS.js} +1 -1
- package/dist/assets/editPageMounted-COiBq84S.js +2 -0
- package/dist/assets/index-5On9Gkpl.js +480 -0
- package/dist/assets/{index-DugQbYOk.js → index-BG7MWz9o.js} +1 -1
- package/dist/assets/{index-DnRXl1Nu.js → index-Dynd6zeI.js} +1 -1
- package/dist/assets/{index-Ddy-NxB_.js → index-mIetEOsB.js} +1 -1
- package/dist/assets/index.es-FZZk_rEa.js +143 -0
- package/dist/index.html +1 -1
- package/package.json +2 -2
- package/dist/assets/MainPage-Cv63Ip_P.js +0 -1
- package/dist/assets/ModelPage-DvyYSgri.js +0 -2
- package/dist/assets/PackagePage-BDzBa7qB.js +0 -1
- package/dist/assets/RenderedResult-Dp1Qdajz.es-woQDtiv_.js +0 -153
- package/dist/assets/ThemeEditorPage-DShPXmlS.js +0 -1
- package/dist/assets/ToggleButtonGroup-WO-9ZUmS.js +0 -1
- package/dist/assets/index-BvSbJtsT.js +0 -483
- package/dist/assets/index.es-BhMC9nt1.js +0 -195
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import{g as ef,b as tf,r as S,u as nf,b6 as rf,k as sf,i as of,b7 as af,l as lf,j as m,f as cf,h as df,s as ta,m as uf,t as vl,Z as hf,V as _e,b8 as Vt,b9 as fs,aD as tt,ae as Ze,L as lt,K as _n,ba as zn,ak as ke,bb as na,bc as ti,bd as Hi,be as ff,bf as pf,bg as mf,bh as gf,bi as vf,T as fe,as as it,bj as bf,bk as xf,bl as yf,O as ra,aK as wf,bm as Lt,bn as kf,bo as ia,bp as Sf,bq as sa,br as Oc,bs as $f,bt as jf,a0 as Qs,bu as Cf,bv as Mf,bw as bl,bx as mi,aX as Tc,I as H,B as Dc,by as Be,aJ as bt,bz as ot,bA as oa,bB as Ef,bC as Wn,G as Of,bD as aa,bE as Tf,ag as Df,bF as Af,bG as Rf,bH as Pf,bI as If,bJ as zf,bK as Ac,bL as Wf,bM as Nf,bN as Rc,bO as Pc,bP as Ic,bQ as Lf,bR as Ff,bS as Bf,bT as _f,bU as Hf,bV as Uf,bW as qf,bX as Kf,bY as Gf,F as Yf,bZ as Vf,b_ as Xf,b$ as eo,c0 as to,c1 as xl,c2 as Jf,c3 as Zf,c4 as Qf,c5 as ep,c6 as cn,c7 as tp,c8 as np,c9 as rp,ca as zc,cb as la,cc as ip,cd as sp,ce as Wc,cf as op,cg as ap,ch as lp,ci as qt,cj as cp,ck as dp,cl as Nc,cm as up,cn as hp,aP as ca,aF as Ft,co as no,cp as fp,cq as pp,Y as Ui,X as mp,cr as gp,cs as vp,ct as ro,cu as bp,cv as xp,cw as yp,cx as Lc,cy as wp,cz as kp,cA as Sp,cB as $p,cC as jp,cD as da,cE as Cp,cF as ua,aT as Mp,cG as Ep,cH as Op,cI as Tp,cJ as Dp,cK as Ap,cL as xn,cM as yl,cN as wl,cO as Ds,cP as Rp,S as Pp,cQ as Ip,cR as zp,cS as Wp,cT as Np,cU as Fc,aj as Lp}from"./index-5On9Gkpl.js";import{cV as T0,cW as D0,cX as A0,cY as R0,cZ as P0,c_ as I0,c$ as z0,d0 as W0,d1 as N0,d2 as L0,d3 as F0}from"./index-5On9Gkpl.js";import{T as ps,a as un}from"./ToggleButtonGroup-C6Lespxy.js";function Fp(e){return ef("MuiCollapse",e)}tf("MuiCollapse",["root","horizontal","vertical","entered","hidden","wrapper","wrapperInner"]);const Bp=e=>{const{orientation:t,classes:n}=e,r={root:["root",`${t}`],entered:["entered"],hidden:["hidden"],wrapper:["wrapper",`${t}`],wrapperInner:["wrapperInner",`${t}`]};return df(r,Fp,n)},_p=ta("div",{name:"MuiCollapse",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[n.orientation],n.state==="entered"&&t.entered,n.state==="exited"&&!n.in&&n.collapsedSize==="0px"&&t.hidden]}})(uf(({theme:e})=>({height:0,overflow:"hidden",transition:e.transitions.create("height"),variants:[{props:{orientation:"horizontal"},style:{height:"auto",width:0,transition:e.transitions.create("width")}},{props:{state:"entered"},style:{height:"auto",overflow:"visible"}},{props:{state:"entered",orientation:"horizontal"},style:{width:"auto"}},{props:({ownerState:t})=>t.state==="exited"&&!t.in&&t.collapsedSize==="0px",style:{visibility:"hidden"}}]}))),Hp=ta("div",{name:"MuiCollapse",slot:"Wrapper"})({display:"flex",width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),Up=ta("div",{name:"MuiCollapse",slot:"WrapperInner"})({width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),io=S.forwardRef(function(t,n){const r=nf({props:t,name:"MuiCollapse"}),{addEndListener:i,children:s,className:o,collapsedSize:a="0px",component:d,easing:f,in:c,onEnter:l,onEntered:u,onEntering:p,onExit:g,onExited:v,onExiting:y,orientation:k="vertical",style:h,timeout:b=rf.standard,TransitionComponent:x=sf,...w}=r,$={...r,orientation:k,collapsedSize:a},E=Bp($),D=of(),O=af(),j=S.useRef(null),P=S.useRef(),R=typeof a=="number"?`${a}px`:a,A=k==="horizontal",L=A?"width":"height",U=S.useRef(null),_=lf(n,U),T=N=>Z=>{if(N){const pe=U.current;Z===void 0?N(pe):N(pe,Z)}},z=()=>j.current?j.current[A?"clientWidth":"clientHeight"]:0,F=T((N,Z)=>{j.current&&A&&(j.current.style.position="absolute"),N.style[L]=R,l&&l(N,Z)}),W=T((N,Z)=>{const pe=z();j.current&&A&&(j.current.style.position="");const{duration:ne,easing:Q}=vl({style:h,timeout:b,easing:f},{mode:"enter"});if(b==="auto"){const Se=D.transitions.getAutoHeightDuration(pe);N.style.transitionDuration=`${Se}ms`,P.current=Se}else N.style.transitionDuration=typeof ne=="string"?ne:`${ne}ms`;N.style[L]=`${pe}px`,N.style.transitionTimingFunction=Q,p&&p(N,Z)}),B=T((N,Z)=>{N.style[L]="auto",u&&u(N,Z)}),X=T(N=>{N.style[L]=`${z()}px`,g&&g(N)}),J=T(v),re=T(N=>{const Z=z(),{duration:pe,easing:ne}=vl({style:h,timeout:b,easing:f},{mode:"exit"});if(b==="auto"){const Q=D.transitions.getAutoHeightDuration(Z);N.style.transitionDuration=`${Q}ms`,P.current=Q}else N.style.transitionDuration=typeof pe=="string"?pe:`${pe}ms`;N.style[L]=R,N.style.transitionTimingFunction=ne,y&&y(N)}),ee=N=>{b==="auto"&&O.start(P.current||0,N),i&&i(U.current,N)};return m.jsx(x,{in:c,onEnter:F,onEntered:B,onEntering:W,onExit:X,onExited:J,onExiting:re,addEndListener:ee,nodeRef:U,timeout:b==="auto"?null:b,...w,children:(N,{ownerState:Z,...pe})=>m.jsx(_p,{as:d,className:cf(E.root,o,{entered:E.entered,exited:!c&&R==="0px"&&E.hidden}[N]),style:{[A?"minWidth":"minHeight"]:R,...h},ref:_,ownerState:{...$,state:N},...pe,children:m.jsx(Hp,{ownerState:{...$,state:N},className:E.wrapper,ref:j,children:m.jsx(Up,{ownerState:{...$,state:N},className:E.wrapperInner,children:s})})})})});io&&(io.muiSupportAuto=!0);var kl={};const Bc=ot(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"})),_c=ot(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"})),so=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),dn=so?"⌘":"Ctrl+",Sl=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},As=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function qp(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=so?s.metaKey:s.ctrlKey,d=s.key.toLowerCase();if(s.key==="Escape"){if(Sl(s.target)||As(s.target))return;o.escape();return}if(Sl(s.target)){if(a&&d==="s"){if(s.preventDefault(),!o.save||As(s.target))return;s.target.blur(),r(!0)}return}if(As(s.target)){a&&d==="s"&&s.preventDefault();return}if(a&&d==="z"){s.preventDefault(),s.shiftKey?o.redo():o.undo();return}if(!so&&a&&d==="y"){s.preventDefault(),o.redo();return}if(a&&d==="s"){s.preventDefault(),o.save?.();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 Pr=(e,t,n=oa)=>({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}}}),qi=(e=oa)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),Ir={height:20,alignSelf:"center",mx:.5,my:0},Hn=(e,t=oa)=>({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"}}}),oo={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Kp({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,onExit:u,layout:p,onLayoutChange:g}){const{theme:v}=_e(),y=Vt(v.cardBorder),k=fs(v.cardBorder,v.tileTitle);return m.jsxs(tt,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[p&&g&&m.jsxs(m.Fragment,{children:[m.jsx(lt,{title:"Layout: tiles side by side, or one after another",children:m.jsxs(ps,{size:"small",exclusive:!0,value:p,"aria-label":"Layout",onChange:(h,b)=>{b&&b!==p&&g(b)},sx:Hn(y,v.ui),children:[m.jsx(un,{value:"linear","aria-label":"Linear layout",children:"Linear"}),m.jsx(un,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),m.jsx(zn,{orientation:"vertical",sx:Ir})]}),l&&m.jsx(ke,{variant:"outlined",startIcon:m.jsx(ti,{}),onClick:l,"aria-label":"Add tile",sx:Pr(y,k,v.ui),children:"Tile"}),l&&m.jsx(zn,{orientation:"vertical",sx:Ir}),m.jsx(lt,{title:`Undo (${dn}Z)`,children:m.jsx("span",{children:m.jsx(_n,{"aria-label":"Undo",disabled:!e,onClick:n,sx:qi(v.ui),children:m.jsx(_c,{fontSize:"small"})})})}),m.jsx(lt,{title:`Redo (${dn}⇧Z)`,children:m.jsx("span",{children:m.jsx(_n,{"aria-label":"Redo",disabled:!t,onClick:r,sx:qi(v.ui),children:m.jsx(Bc,{fontSize:"small"})})})}),(c||o||u)&&m.jsx(zn,{orientation:"vertical",sx:Ir}),c,o?m.jsx(lt,{title:i?`Save (${dn}S) · ${d??oo[a]}`:d??oo[a],children:m.jsx("span",{children:m.jsx(ke,{ref:f,variant:i?"contained":"outlined",disabled:!i||s,onClick:o,sx:{...Pr(y,k,v.ui),minWidth:88},children:s?"Saving…":i?"Save":"Saved"})})}):null,o&&m.jsx(H,{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"}),u&&m.jsx(Of,{label:"Close",icon:m.jsx(aa,{}),onClick:u})]})}const Gp={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Hc(e,t,n){const r=i=>{if(t!==i){if(i==="big_value")return e?.aggregateOnly===!0?void 0:"Needs a view with only totals (no group by)";if(i==="shape_map"||i==="segment_map")return e?.chart===i?void 0:"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(i=>{const s=r(i);return{value:i,label:Gp[i],...s?{disabled:!0,reason:s}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function $l(e){return e.description??zp(e.name)}const Yp={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},gi=(e,t)=>`${e}\0${t}`;function Vp({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o,renderPreview:a}){const{theme:d}=_e(),f=d.ui,c=Vt(d.cardBorder),l=S.useMemo(()=>n?.sources??[],[n]),[u,p]=S.useState(""),[g,v]=S.useState(),[y,k]=S.useState(""),[h,b]=S.useState("default"),x=S.useRef(null),w=S.useMemo(()=>{const T=new Set(t.sources.map(z=>z.base));return[...l].sort((z,F)=>Number(T.has(F.name))-Number(T.has(z.name)))},[l,t]),$=w.filter(T=>T.views.length>0),E=w.filter(T=>T.views.length===0),D=S.useMemo(()=>new Map($.flatMap(T=>T.views.map(z=>[gi(T.name,z.name),{source:T,view:z,key:gi(T.name,z.name)}]))),[$]),O=S.useMemo(()=>$.map(T=>({key:T.name,label:T.name,...T.description?{detail:T.description}:{},entries:T.views.map(z=>({key:gi(T.name,z.name),name:z.name,title:$l(z),...z.chart?{chart:z.chart}:{}}))})),[$]),j=g===void 0?void 0:D.get(g);S.useEffect(()=>{if(!e)return;p(""),k(""),b("default");const T=$[0]?.views[0];v(T&&$[0]?gi($[0].name,T.name):void 0)},[e]);const P=j?[j.source.name,j.view.name].filter(T=>!ro(T)).map(T=>`"${T}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,R=j!==void 0&&P===void 0,A=j?$l(j.view):"",L=h!=="default"&&j?{chart:h,chartCarried:j.view.chart?[j.view.chart]:[]}:{},U=(T=j)=>{if(!T||![T.source.name,T.view.name].every(ro))return;const z=T.key===j?.key;s({base:T.source.name,modelPath:T.source.modelPath,...T.source.exporters?{exporters:T.source.exporters}:{},view:T.view.name,...z&&y.trim()?{label:y.trim()}:{},...z?L:{},colspan:Math.ceil(r/2)})},_=j?Hc(j.view,h).filter(T=>T.value!=="custom"&&T.disabled!==!0):[];return m.jsx(ca,{className:`${Ze.dialog} ${Ze.addTileDialog}`,open:e,onClose:i,maxWidth:"md",initialFocus:x,title:"Add a tile",description:"Pick a view from this package. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx(ke,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx(ke,{onClick:i,children:"Cancel"}),m.jsx(ke,{variant:"contained",disabled:!R,onClick:()=>U(),children:"Add tile"})]}),children:m.jsxs(H,{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(H,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(bp,{groups:O,query:u,onQuery:p,picked:j?.key,onPick:T=>{v(T),b("default")},onTake:T=>U(D.get(T)),searchRef:x,empty:m.jsx(fe,{variant:"body2",sx:{color:d.tileTitle,p:2},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}),footer:E.length>0&&m.jsxs(fe,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",E.map(T=>T.name).join(", "),"."]})})}),m.jsx(H,{sx:T=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${T.palette.text.primary} 3%, ${T.palette.background.paper})`}),children:j?m.jsxs(m.Fragment,{children:[m.jsx(H,{"aria-label":"Preview",role:"region",sx:T=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${c}`,bgcolor:T.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${T.palette.background.paper})`}}),children:a?m.jsx(H,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:j.source.name,modelPath:j.source.modelPath,view:j.view.name,label:y.trim()||A,...h!=="default"?L:{},givens:j.source.givens})}):m.jsxs(H,{sx:T=>({flex:1,border:`1px solid ${c}`,borderRadius:f.radius.tile,bgcolor:T.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(xp,{chart:j.view.chart}),m.jsxs(fe,{variant:"body2",children:[j.source.name," → ",j.view.name]})]})}),m.jsx(Ft,{size:"small",label:"Title",placeholder:A,value:y,onChange:T=>k(T.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs(H,{children:[m.jsx(fe,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx(ps,{size:"small",exclusive:!0,value:h,"aria-label":"Chart",onChange:(T,z)=>{z!==null&&b(z)},sx:{...Hn(c,f),"& .MuiToggleButton-root":{...Hn(c,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:_.map(T=>m.jsx(un,{value:T.value,children:T.label},T.value))}),m.jsx(fe,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:j.view.chart?`The view declares ${Yp[j.view.chart]??"a chart"}.`:"The view declares no chart, so it shows as a table."})]}),P&&m.jsx(fe,{variant:"body2",color:"error",children:P})]}):m.jsx(fe,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const De=e=>e.kind==="text",de=e=>e.kind!=="text",pr=e=>de(e)?e.label??e.name:e.name,Ie=e=>De(e)?`text.${e.name}`:`${e.source}.${e.name}`;function Xp(e,t,{modelPath:n,textHeld:r,widths:i,insertAt:s}){t.modelPath&&!r&&(e.imports=Rp(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Uc(e,t.base),a=ao(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?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Uc(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 ao(e,t,n){const r=new Set(e.tiles.filter(de).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 Ki(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.`;default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function Jp(e,t){const n=e.tiles[t];if(!n||!de(n)||Ki(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:i,...s}=structuredClone(n);r={...s,name:ao(e,n.source,n.declaration.from)}}else{const i=e.sources.find(s=>s.name===n.source)??Uc(e,n.source,{unscoped:!0});r={name:ao(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}return e.tiles.splice(t+1,0,r),t+1}const vi="self";function Zp({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(b=>b.source===n.name);l((n.dimensions??[]).map(b=>{const x=h.find(w=>w.name===b.name);return{name:b.name,expression:b.expression,to:x?.to??[],given:x?.given??""}}))},[e,n,t]);const u=(h,b)=>l(x=>x.map((w,$)=>{if($!==h)return w;const E={...w};return b(E),E})),p=[vi,...i.filter(h=>h!==vi)],g=h=>h===vi?"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())},y=Vt(d.cardBorder),k=(h,b)=>u(h,x=>{b?x.to=x.lastTo?.length?x.lastTo:[vi]:(x.lastTo=x.to,x.to=[])});return m.jsx(ca,{className:`${Ze.dialog} ${Ze.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[s&&m.jsxs(H,{component:"span",sx:{fontWeight:f.type.label.fontWeight},children:[s," ·"," "]}),"A click on a cell sets a filter to its value, on this report or on the one it opens."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx(ke,{onClick:o,children:"Cancel"}),m.jsx(ke,{variant:"contained",onClick:v,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx(fe,{variant:"body2",sx:{color:d.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx(H,{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(H,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx(H,{role:"list","aria-label":"Dimensions",children:c.map((h,b)=>{const x=h.to.length>0;return m.jsxs(H,{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:b===0?"none":`1px solid ${y}`},children:[m.jsx(vp,{size:"small",checked:x,onChange:w=>k(b,w.target.checked),slotProps:{input:{"aria-label":`${h.name} is clickable`}}}),m.jsxs(H,{sx:{minWidth:0},children:[m.jsx(H,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:Qp(h.name)}),m.jsxs(H,{title:h.expression,sx:{...f.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[h.name," is ",h.expression]})]}),x?m.jsxs(tt,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...f.type.control},children:[m.jsx(H,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx(Ft,{select:!0,size:"small",value:h.to,inputProps:{"aria-label":`Where ${h.name} goes`},SelectProps:{multiple:!0,renderValue:w=>w.map(g).join(", ")},onChange:w=>u(b,$=>{const E=w.target.value,D=Array.isArray(E)?E:String(E).split(",").filter(Boolean);D.length===0&&($.lastTo=$.to),$.to=D}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:p.map(w=>m.jsxs(bt,{value:w,children:[m.jsx(no,{size:"small",checked:h.to.includes(w),sx:{p:0,mr:1}}),m.jsx(Ui,{primary:g(w)})]},w))}),m.jsx(H,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs(Ft,{select:!0,size:"small",value:h.given,inputProps:{"aria-label":`Control ${h.name} sets`},SelectProps:{displayEmpty:!0,renderValue:w=>w===""?h.name:String(w)},onChange:w=>u(b,$=>{$.given=w.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx(bt,{value:"",children:m.jsx(Ui,{primary:h.name,secondary:"Named like the dimension"})}),r.map(w=>m.jsx(bt,{value:w,children:w},w))]})]}):m.jsx(fe,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},h.name)})})})}function Qp(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const em=ot(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"})),tm=ot(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"})),nm=ot(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"})),rm=ot(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"})),im=ot(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),sm=ot(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function om(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of de(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 Gi(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function am(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function zr(e,t){const n=am(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 lo(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 lm(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const cm=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function dm(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=Fc(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 um=[{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 vr(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=>de(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function hm(e,t){return e.tiles.map(n=>{const r=(de(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}:Gi(t.type)!==void 0?{op:Gi(t.type)}:{}}})}function fm(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 pm(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 mm(e,t){for(const r of e.tiles){if(!de(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 uo=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function gm({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"),[y,k]=S.useState(""),[h,b]=S.useState(""),[x,w]=S.useState([]),[$,E]=S.useState(!1),[D,O]=S.useState(!1),j=M=>t.sources.find(I=>I.name===M.source)?.base??M.source;S.useEffect(()=>{if(e)if(O(n!==void 0),n){l({kind:"existing",name:n.name}),p(n.label??"");const M=hm(t,n);w(M);const I=M.filter(C=>C.include),q=new Set(I.map(C=>C.field));b(q.size===1?I[0].field:n.field??""),E(q.size>1)}else l({kind:"new"}),p(""),v("select"),b(""),k(new Date().toISOString().slice(0,10)),w(t.tiles.map(M=>({include:co(M),field:""}))),E(!1)},[e,n,t]);const P=S.useMemo(()=>[...(t.localGivens??[]).map(M=>M.name),...r.map(M=>M.name),...i],[t,r,i]),R=S.useMemo(()=>h.trim()?dm(h.trim(),P):"",[h,P]),A=c.kind==="existing"?n??r.find(M=>M.name===c.name):R?{name:R,type:vr({name:R,label:u,kind:g,field:h}).type}:void 0,L=A?.type!==void 0&&!A.type.startsWith("filter<"),U=x.find(M=>M.include)?.op??Gi(A?.type),_=(M,I)=>{O(!0),w(q=>q.map((C,te)=>te===M?{...C,...I}:C))},T=M=>{O(!0),w(I=>I.map(q=>({...q,op:M})))},z=M=>{const I=Gi(M);w(q=>q.map(({op:C,...te})=>I?{...te,op:I}:te))},F=M=>{O(!0),l({kind:"existing",name:M.name}),b(M.field??""),z(M.type)},W=M=>{O(!0),v(M),z(vr({name:"X",label:u,kind:M,field:h}).type)},B=t.tiles.map(co),X=B.filter(Boolean).length,J=x.filter((M,I)=>M.include&&B[I]).length,re=t.tiles.filter((M,I)=>(x[I]?.include??!1)&&B[I]&&de(M)),ee=re.length>0?re:t.tiles.filter((M,I)=>B[I]&&de(M)),N=S.useMemo(()=>{const M=new Map;let I=!1;for(const q of ee){const C=s?.(q);if(C){I=!0;for(const te of C)M.has(te.name)||M.set(te.name,te)}}return I?[...M.values()]:void 0},[x,t.tiles,s]),Z=(()=>{const M=h.trim();for(const I of re){const q=s?.(I);if(!q||q.some(C=>C.name===M))return j(I)}return re[0]?j(re[0]):t.sources[0]?.base})(),pe=M=>{O(!0),w(I=>I.map((q,C)=>({...q,include:M&&B[C]})))},ne=S.useMemo(()=>$?x:x.map(M=>({...M,field:h})),[$,x,h]),Q=M=>{for(const I of ee){const q=s?.(I)?.find(C=>C.name===M.trim());if(q?.type)return q.type}},Se=M=>zr(A?.type,M.type),be=(M,I)=>{if(M.trim()==="")return"Pick the field this filter compares.";const q=I?s?.(I):void 0;if(!q)return;const C=q.find(te=>te.name===M.trim());if(!C)return`Not a field of ${I?j(I):"the tiles' source"}.`;if(C.type&&!zr(A?.type,C.type))return`${M.trim()} is ${lo(C.type)}; this filter compares ${lo(A?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},G=M=>{if(O(!0),b(M),f||c.kind!=="new")return;const I=Q(M),q=vr({name:"X",label:u,kind:g,field:M}).type;I&&!zr(q,I)&&W(lm(I))},$e=M=>{const I=t.tiles[M];return I&&de(I)?I:void 0},he=ne.map((M,I)=>M.include&&B[I]?be(M.field,$e(I)):void 0),ie=he.every(M=>M===void 0),Ne=D?he:he.map(()=>{}),Ke=D&&!$&&J>0?re.map(M=>be(h,M)).find(Boolean):void 0,He=A!==void 0&&ie&&(c.kind==="existing"||h.trim()!==""&&R!==""),Ge=()=>{if(!(!A||!He))if(c.kind==="new")o(A.name,ne,vr({name:A.name,label:u.trim()||uo(A.name),kind:g,field:h.trim(),...Z?{source:Z}:{},...y?{dateDefault:y}:{}}));else if(n?.origin==="dashboard"&&n.local){const M=u.trim(),I=M!==(n.local.label??"");o(A.name,ne,I?{...n.local,...M?{label:M}:{}}:void 0)}else o(A.name,ne)},Ye=f&&d.origin==="model";return{editing:f,shown:d,fromModel:Ye,source:c,setSource:l,label:u,setLabel:p,kind:g,dateDefault:y,setDateDefault:k,field:h,rows:x,setRows:w,perTile:$,setPerTile:E,newName:R,target:A,valueTyped:L,commonOp:U,setRow:_,setCommonOp:T,pickExisting:F,pickKind:W,bindable:B,bindableCount:X,included:J,commonFields:N,setAll:pe,accepts:Se,pickField:G,rowProblems:Ne,commonProblem:Ke,canApply:He,apply:Ge}}function jl({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(Ip,{freeSolo:!0,size:"small",options:p,inputValue:e,onInputChange:(v,y)=>t(y),value:e,onChange:(v,y)=>t(typeof y=="string"?y:""),disabled:d,disableClearable:!0,renderOption:(v,y)=>S.createElement("li",{...v,key:y},m.jsx(Ml,{type:g.get(y)}),m.jsx(fe,{variant:"body2",sx:{flex:1,ml:1},children:y})),renderInput:v=>m.jsx(Ft,{...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(H,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Ml,{type:g.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":s}}),sx:u})}const vm=e=>e&&de(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function bm({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:y,setLabel:k,kind:h,dateDefault:b,setDateDefault:x,field:w,rows:$,setRows:E,perTile:D,setPerTile:O,newName:j,target:P,valueTyped:R,commonOp:A,setRow:L,setCommonOp:U,pickExisting:_,pickKind:T,bindable:z,bindableCount:F,included:W,commonFields:B,setAll:X,accepts:J,pickField:re,rowProblems:ee,commonProblem:N,canApply:Z,apply:pe}=gm({open:e,document:t,control:n,available:r,...i?{takenNames:i}:{},fieldsFor:s,onApply:a}),ne=S.useRef(null),Q=Vt(f.cardBorder),Se=fs(f.cardBorder,f.tileTitle),[be,G]=S.useState(!1),[$e,he]=S.useState(!1);S.useEffect(()=>{e?he(!0):G(!1)},[e]),S.useEffect(()=>{$e&&(he(!1),G(l&&W<F))},[$e]),S.useEffect(()=>{D&&G(!0)},[D]);const ie=B?.find(M=>M.name===w.trim())?.type,Ne=M=>{if(!ie)return;const I=vr({name:"X",label:y,kind:M,field:w}).type;return zr(I,ie)?void 0:`${w.trim()} is ${lo(ie)}, which this control cannot filter.`},Ke=y.trim()||(j?uo(j):"Filter"),He=h==="number"?"Any":h==="date"?b?new Date(`${b}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ge={...Hn(Q,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...Hn(Q,c)["& .MuiToggleButton-root"],textTransform:"none"}},Ye=(M,I,q)=>m.jsx(Ft,{select:!0,size:"small",label:"Compares",value:M??">=",onChange:C=>I(C.target.value),inputProps:{"aria-label":q},sx:{width:130},children:cm.filter(C=>C.op!=="~").map(C=>m.jsx(bt,{value:C.op,children:C.label},C.op))});return m.jsx(ca,{className:`${Ze.dialog} ${Ze.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:ne},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs(H,{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(ke,{color:"error",startIcon:m.jsx(pp,{}),onClick:()=>d(u.name),sx:M=>({mr:"auto",color:fp(M)}),children:"Remove filter"}),m.jsx(ke,{onClick:o,children:"Cancel"}),m.jsx(lt,{title:Z||P===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx(ke,{variant:"contained",onClick:pe,disabled:!Z,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs(tt,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs(ps,{exclusive:!0,size:"small",value:g.kind,onChange:(M,I)=>{I==="new"?v({kind:"new"}):I==="existing"&&r[0]&&_(r[0])},"aria-label":"Where the filter comes from",sx:Ge,children:[m.jsx(un,{value:"new",children:"New in this report"}),m.jsx(un,{value:"existing",children:"From the model"})]}),!l&&g.kind==="existing"?m.jsx(Ft,{select:!0,size:"small",label:"Filter",value:g.name,onChange:M=>{const I=r.find(q=>q.name===M.target.value);I&&_(I)},children:r.map(M=>m.jsxs(bt,{value:M.name,children:[M.label??M.name,m.jsxs(fe,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",M.name]})]},M.name))}):null,m.jsxs(H,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:p?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!D&&m.jsx(jl,{value:w,onChange:re,fields:B,accepts:J,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:ne,error:N!==void 0,helperText:N??(!l&&j?`Declared as $${j}`:void 0)}),!p&&m.jsx(Ft,{size:"small",label:"Label",placeholder:j?uo(j):"",value:y,onChange:M=>k(M.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),R&&!D&&Ye(A,U,"Comparison"),!l&&g.kind==="new"&&m.jsxs(H,{children:[m.jsx(Cl,{children:"Control"}),m.jsx(H,{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:um.map(M=>{const I=M.kind===h,q=Ne(M.kind);return m.jsx(lt,{title:q??M.hint,describeChild:!0,children:m.jsxs(Dc,{role:"radio","aria-checked":I,"aria-label":M.label,"aria-disabled":q!==void 0,onClick:()=>{q===void 0&&T(M.kind)},sx:C=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${I?f.accent:Q}`,boxShadow:I?`0 0 0 1px ${f.accent}`:"none",bgcolor:I?`color-mix(in srgb, ${f.accent} 6%, ${C.palette.background.paper})`:C.palette.background.paper,color:I?f.accent:C.palette.text.secondary,opacity:q?.45:1,cursor:q?"default":"pointer",transition:`border-color ${Be}, background-color ${Be}`,"&:hover":q||I?{}:{borderColor:Se}}),children:[m.jsx(ym,{kind:M.kind}),m.jsx(H,{component:"span",sx:{...c.type.caption,fontWeight:I?600:500,color:I?f.accent:"text.primary",textAlign:"center"},children:xm[M.kind]})]})},M.kind)})}),h==="date"&&m.jsx(Ft,{size:"small",type:"date",label:"Starts at",value:b,onChange:M=>x(M.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs(H,{sx:{border:`1px solid ${Q}`,borderRadius:c.radius.tile,overflow:"hidden"},children:[m.jsxs(tt,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(sm,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs(fe,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx(H,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:W===F&&F>0?`Applies to all ${W} tile${W===1?"":"s"}`:`Applies to ${W} of ${F} tile${F===1?"":"s"}`}),!D&&w.trim()!==""&&W>0&&m.jsxs(H,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx(H,{component:"span",sx:{...c.type.code},children:w.trim()})]})]}),!D&&m.jsx(ke,{size:"small","aria-expanded":be,onClick:()=>G(M=>!M),children:be?"Done choosing":"Choose tiles"})]}),m.jsx(io,{in:be,unmountOnExit:!0,children:m.jsxs(H,{sx:{borderTop:`1px solid ${Q}`,px:.5,pb:1},children:[m.jsxs(tt,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx(no,{size:"small",checked:F>0&&W===F,indeterminate:W>0&&W<F,disabled:F===0,onChange:M=>X(M.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx(fe,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx(ke,{size:"small",onClick:()=>{D||E(M=>M.map(I=>({...I,field:w}))),O(M=>!M)},children:D?"Same field for all":"Adjust per tile"})]}),m.jsx(tt,{sx:{gap:D?1:0},children:t.tiles.map((M,I)=>{if(!de(M))return null;const q=$[I],C=M.label??M.name,te=D?ee[I]:void 0;return m.jsxs(tt,{direction:"row",sx:{gap:1,alignItems:D?"flex-start":"center",opacity:z[I]?1:.6},children:[m.jsx(no,{size:"small",disabled:!z[I],checked:(q?.include??!1)&&z[I],inputProps:{"aria-label":`Filter ${C}`},onChange:K=>L(I,{include:K.target.checked})}),m.jsx(fe,{variant:"body2",sx:{flex:1,minWidth:0,pt:D?1:0},noWrap:!0,children:C}),z[I]?D&&m.jsxs(m.Fragment,{children:[R&&Ye(q?.op,K=>L(I,{op:K}),`Comparison for ${C}`),m.jsx(jl,{value:q?.field??"",onChange:K=>L(I,{field:K}),fields:s?.(M),accepts:J,label:"Field",ariaLabel:`Field for ${C}`,disabled:!q?.include,error:te!==void 0,helperText:te,sx:{width:220,pr:1}})]}):m.jsx(fe,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:vm(t.tiles[I]).reason})]},`${M.source}.${M.name}`)})})]})})]}),W===0&&m.jsx(fe,{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(H,{children:[m.jsx(Cl,{children:"Preview"}),m.jsx(H,{sx:M=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:M.palette.action.hover}),children:m.jsxs(H,{"aria-hidden":!0,sx:M=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${Q}`,bgcolor:M.palette.background.paper,...c.type.control}),children:[m.jsx(H,{component:"span",sx:{color:"text.secondary"},children:Ke}),m.jsx(H,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:He}),m.jsx(na,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function Cl({children:e}){const t=_e().theme.ui;return m.jsx(fe,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const xm={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function ym({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(em,{sx:t});case"multiselect":return m.jsx(tm,{sx:t});case"text":return m.jsx(im,{sx:t});case"number":return m.jsx(rm,{sx:t});case"date":return m.jsx(nm,{sx:t})}}function Ml({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(H,{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 wm=ot(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function qc(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 km=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.`,Sm="Declared on its source, so its chart is set in the model.";function $m({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:i,onDuplicate:s,duplicateBlocked:o,view:a}){const{theme:d}=_e(),f=d.ui,{draft:c,apply:l,close:u}=qc(t,e!==null,r,n),[p,g]=S.useState(void 0),v=c!==void 0&&de(c)?c:void 0,y=v!==void 0&&v.declaration.kind!=="inherited",k=P=>l(R=>{de(R)&&P(R)}),h=S.useRef(void 0),b=e!==null;S.useEffect(()=>{b?h.current=t&&de(t)?t.chart:void 0:g(void 0)},[b]);const x=v?.chart??"default",w=Hc(a,x),$=v?y?v.chart==="custom"?km(v.chartLines):void 0:Sm:void 0,E=P=>k(R=>{const A=h.current;P===(A??"default")?(A===void 0?delete R.chart:R.chart=A,delete R.chartCarried):(R.chart=P,a?R.chartCarried=a.chart?[a.chart]:[]:delete R.chartCarried)}),D=y?i?void 0:"Its source declares no dimension a click could filter by.":void 0,O=P=>R=>g({kind:P,anchor:R.currentTarget}),j=(P,R,A)=>m.jsxs(m.Fragment,{children:[m.jsx(Ui,{primary:P,...A?{secondary:A}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),R&&m.jsx(fe,{variant:"body2",sx:{color:"text.secondary",ml:2},children:R})]});return m.jsxs(m.Fragment,{children:[m.jsxs(Hi,{className:Ze.menu,open:e!==null&&c!==void 0,anchorEl:e,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":v?`${v.source} ${v.name}`:"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:f.radius.menu,border:`1px solid ${Vt(d.cardBorder)}`,boxShadow:f.shadow.menu}}},children:[v&&m.jsxs(bt,{"aria-haspopup":"menu","aria-expanded":p?.kind==="chart",disabled:$!==void 0,onClick:O("chart"),onKeyDown:P=>{P.key==="ArrowRight"&&$===void 0&&g({kind:"chart",anchor:P.currentTarget})},children:[j("Chart",$?void 0:w.find(P=>P.value===x)?.label,$),m.jsx(wm,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),y&&m.jsx(bt,{"aria-haspopup":"dialog",disabled:D!==void 0,onClick:()=>{u(),i?.()},children:j("Clickable cells…",void 0,D)}),v&&s&&m.jsx(bt,{disabled:o!==void 0,onClick:()=>{u(),s()},children:j("Duplicate",void 0,o)}),v?.declaration.kind==="opaque"&&m.jsxs(fe,{variant:"body2",sx:{color:d.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",v.declaration.why,", so a filter has no single place to go."]}),v&&m.jsx(zn,{}),v&&m.jsxs(H,{"aria-hidden":!0,sx:{px:2,py:.5,...f.type.code,color:"text.secondary"},children:[v.source," → ",v.name]})]}),m.jsx(Hi,{className:Ze.menu,open:p?.kind==="chart",anchorEl:p?.anchor??null,onClose:()=>g(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:P=>{P.key==="ArrowLeft"&&(P.preventDefault(),g(void 0))}},children:w.filter(P=>P.value!=="custom").map(P=>m.jsxs(bt,{role:"menuitemradio","aria-checked":P.value===x,disabled:P.disabled===!0,onClick:()=>{E(P.value),g(void 0)},children:[m.jsx(Ui,{primary:P.label,...P.reason?{secondary:P.reason}:{}}),P.value===x&&m.jsx(mp,{sx:{minWidth:0,ml:2},children:m.jsx(aa,{fontSize:"small",sx:{color:d.accent}})})]},P.value))})]})}const Nn=e=>e.label??gp(`${e.source} -> ${e.name}`);function jm({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,y]=S.useState(),k=p===void 0?void 0:e.document.tiles[p.index],h=k&&de(k)?k:void 0,b=(()=>{if(!h||!t)return;const x=e.document.sources.find($=>$.name===h.source)?.base??h.source,w=h.declaration.kind==="reference"?h.declaration.from:h.name;return t.sources.find($=>$.name===x)?.views.find($=>$.name===w)})();return m.jsxs(m.Fragment,{children:[m.jsx(bm,{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($m,{anchor:p?.anchor??null,tile:p===void 0?void 0:e.document.tiles[p.index],onClose:()=>g(void 0),onCommit:x=>{const w=p?.index;w!==void 0&&e.update($=>{$.tiles[w]=x})},view:b,onDuplicate:()=>{p&&s.duplicate(p.index)},...h&&Ki(h)!==void 0?{duplicateBlocked:Ki(h)}:{},...(e.document.sources.find(x=>x.name===h?.source)?.dimensions?.length??0)>0?{onDrills:()=>{y(h?Nn(h):void 0),a(h?.source)}}:{}}),m.jsx(Zp,{open:o!==void 0,document:e.document,source:e.document.sources.find(x=>x.name===o),givenNames:i.controlList.map(x=>x.name),dashboards:r??[],...v?{tileLabel:v}:{},onClose:()=>a(void 0),onApply:x=>e.update(w=>{const $=[...(w.drills??[]).filter(E=>E.source!==o),...x];$.length===0?delete w.drills:w.drills=$})}),m.jsx(Df,{...d}),m.jsx(Vp,{open:s.addingTile,document:e.document,catalog:t,columns:n,onClose:s.closeAdd,onAdd:s.addTile,onAddText:s.addText,...f?{renderPreview:f}:{}})]})}var Cm=Symbol.for("preact-signals");function ms(){if(Tt>1)Tt--;else{var e,t=!1;for((function(){var i=Vi;for(Vi=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}})();Nr!==void 0;){var n=Nr;for(Nr=void 0,Yi++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Gc(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(Yi=0,Tt--,t)throw e}}function Me(e){if(Tt>0)return e();ho=++Mm,Tt++;try{return e()}finally{ms()}}var Wr,xe=void 0;function ae(e){var t=xe,n=Wr;xe=void 0,Wr=void 0;try{return e()}finally{xe=t,Wr=n}}var Nr=void 0,Tt=0,Yi=0,Mm=0,ho=0,Vi=void 0,Xi=0;function Kc(e){if(xe!==void 0){var t=e.n;if(t===void 0||t.t!==xe)return t={i:0,S:e,p:xe.s,n:void 0,t:xe,e:void 0,x:void 0,r:t},xe.s!==void 0&&(xe.s.n=t),xe.s=t,e.n=t,32&xe.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=xe.s,t.n=void 0,xe.s.n=t,xe.s=t),t}}function Qe(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}Qe.prototype.brand=Cm;Qe.prototype.h=function(){return!0};Qe.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:ae(function(){var r;(r=t.W)==null||r.call(t)}))};Qe.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&&ae(function(){var i;(i=t.Z)==null||i.call(t)}))}};Qe.prototype.subscribe=function(e){var t=this;return pt(function(){var n=t.value;ae(function(){return e(n)})},{name:"sub"})};Qe.prototype.valueOf=function(){return this.value};Qe.prototype.toString=function(){return this.value+""};Qe.prototype.toJSON=function(){return this.value};Qe.prototype.peek=function(){var e=this;return ae(function(){return e.value})};Object.defineProperty(Qe.prototype,"value",{get:function(){var e=Kc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Yi>100)throw new Error("Cycle detected");(function(n){Tt!==0&&Yi===0&&n.l!==ho&&(n.l=ho,Vi={S:n,v:n.v,i:n.i,o:Vi})})(this),this.v=e,this.i++,Xi++,Tt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{ms()}}}});function Xn(e,t){return new Qe(e,t)}function Gc(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 Yc(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 Vc(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 pn(e,t){Qe.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Xi-1,this.f=4}pn.prototype=new Qe;pn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Xi))return!0;if(this.g=Xi,this.f|=1,this.i>0&&!Gc(this))return this.f&=-2,!0;var e=xe;try{Yc(this),xe=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 xe=e,Vc(this),this.f&=-2,!0};pn.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)}Qe.prototype.S.call(this,e)};pn.prototype.U=function(e){if(this.t!==void 0&&(Qe.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)}};pn.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(pn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Kc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function El(e,t){return new pn(e,t)}function Xc(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Tt++;var n=xe;xe=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,ha(e),r}finally{xe=n,ms()}}}function ha(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Xc(e)}function Em(e){if(xe!==this)throw new Error("Out-of-order effect");Vc(this),xe=e,this.f&=-2,8&this.f&&ha(this),ms()}function Jn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Wr&&Wr.push(this)}Jn.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()}};Jn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Xc(this),Yc(this),Tt++;var e=xe;return xe=this,Em.bind(this,e)};Jn.prototype.N=function(){2&this.f||(this.f|=2,this.u=Nr,Nr=this)};Jn.prototype.d=function(){this.f|=8,1&this.f||ha(this)};Jn.prototype.dispose=function(){this.d()};function pt(e,t){var n=new Jn(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Om=Object.create,fa=Object.defineProperty,Tm=Object.defineProperties,Dm=Object.getOwnPropertyDescriptor,Am=Object.getOwnPropertyDescriptors,Ol=Object.getOwnPropertySymbols,Rm=Object.prototype.hasOwnProperty,Pm=Object.prototype.propertyIsEnumerable,Im=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zn=e=>{throw TypeError(e)},fo=(e,t,n)=>t in e?fa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zm=(e,t)=>{for(var n in t||(t={}))Rm.call(t,n)&&fo(e,n,t[n]);if(Ol)for(var n of Ol(t))Pm.call(t,n)&&fo(e,n,t[n]);return e},Wm=(e,t)=>Tm(e,Am(t)),Tl=(e,t)=>fa(e,"name",{value:t,configurable:!0}),Nm=e=>{var t;return[,,,Om((t=void 0)!=null?t:null)]},Jc=["class","method","getter","setter","accessor","field","value","get","set"],br=e=>e!==void 0&&typeof e!="function"?Zn("Function expected"):e,Lm=(e,t,n,r,i)=>({kind:Jc[e],name:t,metadata:r,addInitializer:s=>n._?Zn("Already initialized"):i.push(br(s||null))}),Zc=(e,t)=>fo(t,Im("metadata"),e[3]),Jt=(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},Qn=(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=Jc[l+5],y=l>3&&(e[g-1]=[]),k=e[g]||(e[g]=[]),h=l&&(!p&&!u&&(i=i.prototype),l<5&&(l>3||!p)&&Dm(l<4?i:{get[n](){return ct(this,s)},set[n](x){return Nt(this,s,x)}},n));l?p&&l<4&&Tl(s,(l>2?"set ":l>1?"get ":"")+n):Tl(i,n);for(var b=r.length-1;b>=0;b--)f=Lm(l,n,d={},e[3],k),l&&(f.static=u,f.private=p,c=f.access={has:p?x=>Fm(i,x):x=>n in x},l^3&&(c.get=p?x=>(l^1?ct:Bm)(x,i,l^4?s:h.get):x=>x[n]),l>2&&(c.set=p?(x,w)=>Nt(x,i,w,l^4?s:h.set):(x,w)=>x[n]=w)),a=(0,r[b])(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?br(a)&&(l>4?y.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?Zn("Object expected"):(br(o=a.get)&&(h.get=o),br(o=a.set)&&(h.set=o),br(o=a.init)&&y.unshift(o));return l||Zc(e,i),h&&fa(i,n,h),p?l^4?s:h:i},pa=(e,t,n)=>t.has(e)||Zn("Cannot "+n),Fm=(e,t)=>Object(t)!==t?Zn('Cannot use the "in" operator on this value'):e.has(t),ct=(e,t,n)=>(pa(e,t,"read from private field"),n?n.call(e):t.get(e)),xr=(e,t,n)=>t.has(e)?Zn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Nt=(e,t,n,r)=>(pa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Bm=(e,t,n)=>(pa(e,t,"access private method"),n);function po(e,t){if(t){let n;return El(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return El(e)}function gt(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)=>!gt(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=>!gt(e[i],t[i]))}return!1}function le({get:e},t){return{init(n){return Xn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Oe(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=po(e.bind(this)),n.set(this,r)),r.value}}function Rs(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,Wm(zm({},i),{enumerable:e}))})}}function ni(...e){const t=e.map(n=>pt(n));return()=>t.forEach(n=>n())}var Qc,ed,td,nd,rd,id,Ve,ma,Ps,mo,go,Ue,ga,Is,sd,vo,va,zs,bo,xo;id=[le],rd=[le],nd=[le],td=[Rs()],ed=[Rs()],Qc=[Rs()];var mn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Jt(Ve,5,this),xr(this,Ue),xr(this,ma,Jt(Ve,8,this)),Jt(Ve,11,this),xr(this,ga,Jt(Ve,12,this)),Jt(Ve,15,this),xr(this,va,Jt(Ve,16,this)),Jt(Ve,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return ct(this,Ue,bo)}get initial(){return ct(this,Ue,mo)}get previous(){return ct(this,Ue,sd)}set current(e){const t=ae(()=>ct(this,Ue,bo));e&&t&&this.equals(t,e)||Me(()=>{ct(this,Ue,mo)||Nt(this,Ue,e,go),Nt(this,Ue,t,vo),Nt(this,Ue,e,xo)})}reset(e=this.defaultValue){Me(()=>{Nt(this,Ue,void 0,vo),Nt(this,Ue,e,go),Nt(this,Ue,e,xo)})}};Ve=Nm();ma=new WeakMap;Ue=new WeakSet;ga=new WeakMap;va=new WeakMap;Ps=Qn(Ve,20,"#initial",id,Ue,ma),mo=Ps.get,go=Ps.set;Is=Qn(Ve,20,"#previous",rd,Ue,ga),sd=Is.get,vo=Is.set;zs=Qn(Ve,20,"#current",nd,Ue,va),bo=zs.get,xo=zs.set;Qn(Ve,2,"current",td,mn);Qn(Ve,2,"initial",ed,mn);Qn(Ve,2,"previous",Qc,mn);Zc(Ve,mn);function Ws(e){return ae(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Zt,_m=class{constructor(){xr(this,Zt,new WeakMap)}get(e,t){var n;return e?(n=ct(this,Zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return ct(this,Zt).has(e)||ct(this,Zt).set(e,new Map),(r=ct(this,Zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=ct(this,Zt).get(e))==null?void 0:t.clear():void 0}};Zt=new WeakMap;var Hm=Object.create,od=Object.defineProperty,Um=Object.getOwnPropertyDescriptor,Dl=Object.getOwnPropertySymbols,qm=Object.prototype.hasOwnProperty,Km=Object.prototype.propertyIsEnumerable,ad=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),gs=e=>{throw TypeError(e)},Al=Math.pow,yo=(e,t,n)=>t in e?od(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gm=(e,t)=>{for(var n in t||(t={}))qm.call(t,n)&&yo(e,n,t[n]);if(Dl)for(var n of Dl(t))Km.call(t,n)&&yo(e,n,t[n]);return e},Ym=e=>{var t;return[,,,Hm((t=e?.[ad("metadata")])!=null?t:null)]},ld=["class","method","getter","setter","accessor","field","value","get","set"],cd=e=>e!==void 0&&typeof e!="function"?gs("Function expected"):e,Vm=(e,t,n,r,i)=>({kind:ld[e],name:t,metadata:r,addInitializer:s=>n._?gs("Already initialized"):i.push(cd(s||null))}),Xm=(e,t)=>yo(t,ad("metadata"),e[3]),Jm=(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},dd=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=ld[c+5],v=e[p]||(e[p]=[]),y=(i=i.prototype,Um(i,n)),k=r.length-1;k>=0;k--)d=Vm(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[k])(y[g],d),a._=1,cd(o)&&(y[g]=o);return y&&od(i,n,y),i},ud=(e,t,n)=>t.has(e)||gs("Cannot "+n),Zm=(e,t,n)=>(ud(e,t,"read from private field"),t.get(e)),Qm=(e,t,n)=>t.has(e)?gs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),eg=(e,t,n,r)=>(ud(e,t,"write to private field"),t.set(e,n),n),dt=class wo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new wo(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 wo(t,n)}},jt=class Qt{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 Qt(i+t,r+n,s,o);return d.scale=Gm({},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 dt((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Qt))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 Qt?tg(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 Qt(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 dt.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return Qt.from(t).intersectionRatio(Qt.from(n))}};function tg(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 hd,fd,ko,Oi,ri,vs=class extends(ko=mn,fd=[Oe],hd=[Oe],ko){constructor(e){const t=dt.from(e);super(t,(n,r)=>dt.equals(n,r)),Jm(ri,5,this),Qm(this,Oi,0),this.velocity={x:0,y:0}}get delta(){return dt.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=dt.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-Zm(this,Oi),o=a=>Math.round(a/s*100);Me(()=>{eg(this,Oi,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(dt.from(e)),this.velocity={x:0,y:0}}};ri=Ym(ko);Oi=new WeakMap;dd(ri,2,"delta",fd,vs);dd(ri,2,"direction",hd,vs);Xm(ri,vs);function So({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(Al(r,2)+Al(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 pd=(e=>(e.Horizontal="x",e.Vertical="y",e))(pd||{}),md=Object.values(pd),ng=Object.create,ba=Object.defineProperty,rg=Object.defineProperties,ig=Object.getOwnPropertyDescriptor,sg=Object.getOwnPropertyDescriptors,Ji=Object.getOwnPropertySymbols,gd=Object.prototype.hasOwnProperty,vd=Object.prototype.propertyIsEnumerable,bd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),er=e=>{throw TypeError(e)},$o=(e,t,n)=>t in e?ba(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xa=(e,t)=>{for(var n in t||(t={}))gd.call(t,n)&&$o(e,n,t[n]);if(Ji)for(var n of Ji(t))vd.call(t,n)&&$o(e,n,t[n]);return e},ya=(e,t)=>rg(e,sg(t)),Rl=(e,t)=>ba(e,"name",{value:t,configurable:!0}),xd=(e,t)=>{var n={};for(var r in e)gd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ji)for(var r of Ji(e))t.indexOf(r)<0&&vd.call(e,r)&&(n[r]=e[r]);return n},tr=e=>{var t;return[,,,ng((t=e?.[bd("metadata")])!=null?t:null)]},yd=["class","method","getter","setter","accessor","field","value","get","set"],yr=e=>e!==void 0&&typeof e!="function"?er("Function expected"):e,og=(e,t,n,r,i)=>({kind:yd[e],name:t,metadata:r,addInitializer:s=>n._?er("Already initialized"):i.push(yr(s||null))}),gn=(e,t)=>$o(t,bd("metadata"),e[3]),V=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},ce=(e,t,n,r,i,s)=>{var o,a,d,f,c,l=t&7,u=!!(t&8),p=!!(t&16),g=l>3?e.length+1:l?u?1:2:0,v=yd[l+5],y=l>3&&(e[g-1]=[]),k=e[g]||(e[g]=[]),h=l&&(!p&&!u&&(i=i.prototype),l<5&&(l>3||!p)&&ig(l<4?i:{get[n](){return Ee(this,s)},set[n](x){return st(this,s,x)}},n));l?p&&l<4&&Rl(s,(l>2?"set ":l>1?"get ":"")+n):Rl(i,n);for(var b=r.length-1;b>=0;b--)f=og(l,n,d={},e[3],k),l&&(f.static=u,f.private=p,c=f.access={has:p?x=>ag(i,x):x=>n in x},l^3&&(c.get=p?x=>(l^1?Ee:wd)(x,i,l^4?s:h.get):x=>x[n]),l>2&&(c.set=p?(x,w)=>st(x,i,w,l^4?s:h.set):(x,w)=>x[n]=w)),a=(0,r[b])(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?yr(a)&&(l>4?y.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?er("Object expected"):(yr(o=a.get)&&(h.get=o),yr(o=a.set)&&(h.set=o),yr(o=a.init)&&y.unshift(o));return l||gn(e,i),h&&ba(i,n,h),p?l^4?s:h:i},wa=(e,t,n)=>t.has(e)||er("Cannot "+n),ag=(e,t)=>Object(t)!==t?er('Cannot use the "in" operator on this value'):e.has(t),Ee=(e,t,n)=>(wa(e,t,"read from private field"),n?n.call(e):t.get(e)),ue=(e,t,n)=>t.has(e)?er("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),st=(e,t,n,r)=>(wa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),wd=(e,t,n)=>(wa(e,t,"access private method"),n);function kd(e,t){return{plugin:e,options:t}}function ii(e){return t=>kd(e,t)}function Ur(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Sd,qr,ka,Ti;Sd=[le];var qe=class{constructor(e,t){this.manager=e,this.options=t,ue(this,ka,V(qr,8,this,!1)),V(qr,11,this),ue(this,Ti,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ae(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=pt(e.bind(this));return Ee(this,Ti).add(t),t}destroy(){Ee(this,Ti).forEach(e=>e())}static configure(e){return kd(this,e)}};qr=tr(null);ka=new WeakMap;Ti=new WeakMap;ce(qr,4,"disabled",Sd,qe,ka);gn(qr,qe);var si=class extends qe{},Di,Ns=class{constructor(e){this.manager=e,this.instances=new Map,ue(this,Di,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Ur).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 Ee(this,Di))if(!n.includes(r)){if(r.prototype instanceof si)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);st(this,Di,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()}};Di=new WeakMap;function lg(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var bi=[],Cn,Mn,cg=class extends qe{constructor(e){super(e),ue(this,Cn),ue(this,Mn),this.computeCollisions=this.computeCollisions.bind(this),st(this,Mn,Xn(bi)),this.destroy=ni(()=>{const t=this.computeCollisions(),n=ae(()=>this.manager.dragOperation.position.current);if(t!==bi){const r=Ee(this,Cn);if(st(this,Cn,n),r&&n.x==r.x&&n.y==r.y)return}else st(this,Cn,void 0);Ee(this,Mn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ae(()=>{e?Ee(this,Mn).value=this.computeCollisions():st(this,Cn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return bi;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=ae(()=>c({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return d.length===0?bi:(a.sort(lg),a)}get collisions(){return Ee(this,Mn).value}};Cn=new WeakMap;Mn=new WeakMap;var $d,jd,Cd,Sa,Md,vt,$a,Rn,ja,Ca;Cd=[le],jd=[le],$d=[le];var At=class en{constructor(t,n){ue(this,$a,V(vt,8,this)),V(vt,11,this),ue(this,Rn),ue(this,ja,V(vt,12,this)),V(vt,15,this),ue(this,Ca,V(vt,16,this)),V(vt,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let d=i;st(this,Rn,Xn(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=Ee(this,Rn).value;return(n=(t=en.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=en.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Ee(this,Rn).peek();t!==i&&(en.pendingIdChanges||(en.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return wd(s=en,Sa,Md).call(s)})),en.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)}};vt=tr(null);Sa=new WeakSet;Md=function(){const e=At.pendingIdChanges;At.pendingIdChanges=null,e&&Me(()=>{for(const[t,n]of e)Ee(t,Rn).value=n})};$a=new WeakMap;Rn=new WeakMap;ja=new WeakMap;Ca=new WeakMap;ce(vt,4,"manager",Cd,At,$a);ce(vt,4,"data",jd,At,ja);ce(vt,4,"disabled",$d,At,Ca);ue(At,Sa);gn(vt,At);At.pendingIdChanges=null;var bs=At,Pl=class{constructor(){this.map=Xn(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=ni(...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}},Ed,Od,Td,Dd,Ad,Rd,jo,Xe,Ma,Ea,Oa,Ct=class extends(jo=bs,Rd=[le],Ad=[le],Dd=[le],Td=[Oe],Od=[Oe],Ed=[Oe],jo){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,d=xd(n,["modifiers","type","sensors","plugins","effects"]);super(ya(xa({},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}=Ur(u);c.registry.plugins.register(p)}}]}}),t),V(Xe,5,this),ue(this,Ma,V(Xe,8,this)),V(Xe,11,this),ue(this,Ea,V(Xe,12,this)),V(Xe,15,this),ue(this,Oa,V(Xe,16,this,this.isDragSource?"dragging":"idle")),V(Xe,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=Ur(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}};Xe=tr(jo);Ma=new WeakMap;Ea=new WeakMap;Oa=new WeakMap;ce(Xe,4,"type",Rd,Ct,Ma);ce(Xe,4,"modifiers",Ad,Ct,Ea);ce(Xe,4,"status",Dd,Ct,Oa);ce(Xe,2,"isDropping",Td,Ct);ce(Xe,2,"isDragging",Od,Ct);ce(Xe,2,"isDragSource",Ed,Ct);gn(Xe,Ct);var Pd,Id,zd,Wd,Nd,Ld,Co,Pe,Ta,Da,Aa,Ra,Pa,Mt=class extends(Co=bs,Ld=[le],Nd=[le],Wd=[le],zd=[le],Id=[le],Pd=[Oe],Co){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=xd(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),V(Pe,5,this),ue(this,Ta,V(Pe,8,this)),V(Pe,11,this),ue(this,Da,V(Pe,12,this)),V(Pe,15,this),ue(this,Aa,V(Pe,16,this)),V(Pe,19,this),ue(this,Ra,V(Pe,20,this)),V(Pe,23,this),ue(this,Pa,V(Pe,24,this)),V(Pe,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}};Pe=tr(Co);Ta=new WeakMap;Da=new WeakMap;Aa=new WeakMap;Ra=new WeakMap;Pa=new WeakMap;ce(Pe,4,"accept",Ld,Mt,Ta);ce(Pe,4,"type",Nd,Mt,Da);ce(Pe,4,"collisionDetector",Wd,Mt,Aa);ce(Pe,4,"collisionPriority",zd,Mt,Ra);ce(Pe,4,"shape",Id,Mt,Pa);ce(Pe,2,"isDropTarget",Pd,Mt);gn(Pe,Mt);var dg=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)}},ug=class extends dg{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function Ai(e,t=!0){let n=!1;return ya(xa({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var hg=class extends si{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=ni(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||bs.pendingIdChanges)return;const o=Ai({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;ae(()=>{var d;a?.id!==((d=e.dragOperation.target)==null?void 0:d.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},nr=(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))(nr||{}),rr=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(rr||{}),Fd,Bd,_d,Hd,Ud,qd,Kd,ft,Ia;Kd=[le],qd=[Oe],Ud=[Oe],Hd=[Oe],_d=[Oe],Bd=[Oe],Fd=[Oe];var Pt=class{constructor(){V(ft,5,this),ue(this,Ia,V(ft,8,this,"idle")),V(ft,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}};ft=tr(null);Ia=new WeakMap;ce(ft,4,"value",Kd,Pt,Ia);ce(ft,2,"current",qd,Pt);ce(ft,2,"idle",Ud,Pt);ce(ft,2,"initializing",Hd,Pt);ce(ft,2,"initialized",_d,Pt);ce(ft,2,"dragging",Bd,Pt);ce(ft,2,"dropped",Fd,Pt);gn(ft,Pt);var fg=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 ae(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=Ai({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ae(()=>{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;Me(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=r??null,t.position.reset(i)});const s=Ai({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"&&Me(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:r,operation:t.snapshot(),cancelable:!1})})}),n)})}move(e){return ae(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=Ai({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 ae(()=>{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=ae(()=>{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=pt(()=>{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()})}},Un=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}},pg=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)}},Ri,Gd=class{constructor(e){this.options=e,ue(this,Ri)}set controller(e){st(this,Ri,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ee(this,Ri))==null||t.activate(e)}};Ri=new WeakMap;var Il=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},mg=class{constructor(e){this.draggables=new Pl,this.droppables=new Pl,this.plugins=new Ns(e),this.sensors=new Ns(e),this.modifiers=new Ns(e)}register(e,t){if(e instanceof Ct)return this.draggables.register(e.id,e);if(e instanceof Mt)return this.droppables.register(e.id,e);if(e.prototype instanceof Il)return this.modifiers.register(e,t);if(e.prototype instanceof Un)return this.sensors.register(e,t);if(e.prototype instanceof qe)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof bs)return e instanceof Ct?this.draggables.unregister(e.id,e):e instanceof Mt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Il)return this.modifiers.unregister(e);if(e.prototype instanceof Un)return this.sensors.unregister(e);if(e.prototype instanceof qe)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()}},Yd,Vd,Xd,Jd,Zd,Qd,eu,tu,nu,wr,Pi,En,Ce,za,Wa,Na,La,Fa,kr;nu=[Oe],tu=[le],eu=[le],Qd=[le],Zd=[le],Jd=[le],Xd=[Oe],Vd=[Oe],Yd=[Oe];var wt=class{constructor(e){V(Ce,5,this),ue(this,wr),ue(this,Pi),ue(this,En,new mn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Pt,ue(this,za,V(Ce,8,this,!1)),V(Ce,11,this),ue(this,Wa,V(Ce,12,this,null)),V(Ce,15,this),ue(this,Na,V(Ce,16,this,null)),V(Ce,19,this),ue(this,La,V(Ce,20,this,null)),V(Ce,23,this),ue(this,Fa,V(Ce,24,this,[])),V(Ce,27,this),this.position=new vs({x:0,y:0}),ue(this,kr,{x:0,y:0}),st(this,wr,e)}get shape(){const{current:e,initial:t,previous:n}=Ee(this,En);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ee(this,En).current=e:Ee(this,En).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ee(this,wr).registry.draggables.get(t);return n&&st(this,Pi,n),(e=n??Ee(this,Pi))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ee(this,wr).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(ya(xa({},this.snapshot()),{transform:n}));return st(this,kr,n),n}snapshot(){return ae(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ee(this,kr),shape:this.shape?Ws(this.shape):null,position:Ws(this.position),status:Ws(this.status),canceled:this.canceled}))}reset(){Me(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Ee(this,En).reset(),this.position.reset({x:0,y:0}),st(this,kr,{x:0,y:0}),this.modifiers=[]})}};Ce=tr(null);wr=new WeakMap;Pi=new WeakMap;En=new WeakMap;za=new WeakMap;Wa=new WeakMap;Na=new WeakMap;La=new WeakMap;Fa=new WeakMap;kr=new WeakMap;ce(Ce,2,"shape",nu,wt);ce(Ce,4,"canceled",tu,wt,za);ce(Ce,4,"activatorEvent",eu,wt,Wa);ce(Ce,4,"sourceIdentifier",Qd,wt,Na);ce(Ce,4,"targetIdentifier",Zd,wt,La);ce(Ce,4,"modifiers",Jd,wt,Fa);ce(Ce,2,"source",Xd,wt);ce(Ce,2,"target",Vd,wt);ce(Ce,2,"transform",Yd,wt);gn(Ce,wt);var gg={get rendering(){return Promise.resolve()}};function yt(e,t){return typeof e=="function"?e(t):e??t}var vg=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=yt(n.plugins,[]),i=yt(n.sensors,[]),s=yt(n.modifiers,[]),o=(t=n.renderer)!=null?t:gg,a=new ug(this),d=new mg(this);this.registry=d,this.monitor=a,this.renderer=o,this.actions=new fg(this),this.dragOperation=new wt(this),this.collisionObserver=new cg(this),this.plugins=[hg,...r],this.modifiers=s,this.sensors=i;const{destroy:f}=this,c=ni(()=>{var l,u,p;const g=ae(()=>this.dragOperation.modifiers),v=this.modifiers;for(const y of g)v.includes(y)||y.destroy();this.dragOperation.modifiers=(p=(u=(l=this.dragOperation.source)==null?void 0:l.modifiers)==null?void 0:u.map(y=>{const{plugin:k,options:h}=Ur(y);return new k(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}},ru=e=>{throw TypeError(e)},Ba=(e,t,n)=>t.has(e)||ru("Cannot "+n),Y=(e,t,n)=>(Ba(e,t,"read from private field"),t.get(e)),et=(e,t,n)=>t.has(e)?ru("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rt=(e,t,n,r)=>(Ba(e,t,"write to private field"),t.set(e,n),n),iu=(e,t,n)=>(Ba(e,t,"access private method"),n);function xs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function su(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,o=(xs(s)?s.getKeyframes():[]).filter(t);o.length>0&&(r=[o[o.length-1],i])}return r}function ys(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 _a(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function oi(e){return"nodeType"in e}function at(e){var t,n,r;return e?_a(e)?e:oi(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 Ha(e){const{Document:t}=at(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Kt(e){return!e||_a(e)?!1:e instanceof at(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function ou(e){return e instanceof at(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function ir(e){return e?_a(e)?e.document:oi(e)?Ha(e)?e:Kt(e)||ou(e)?e.ownerDocument:document:document:document}function bg(e){var t,n,r,i;const{documentElement:s}=ir(e),o=at(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 xg(e,t){if(yg(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function yg(e){return e.tagName==="DETAILS"}function Kr(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(!xg(l)){const b=l.getBoundingClientRect(),x=n*(b.bottom-b.top),w=n*(b.right-b.left),$=n*(b.bottom-b.top),E=n*(b.right-b.left);d={top:Math.max(d.top,b.top-x),right:Math.min(d.right,b.right+w),bottom:Math.min(d.bottom,b.bottom+$),left:Math.max(d.left,b.left-E),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,y=(a=u?.height)!=null?a:c.innerHeight,k=n*y,h=n*v;return d={top:Math.max(d.top,p-k),right:Math.min(d.right,g+v+h),bottom:Math.min(d.bottom,p+y+k),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 qn(e){return{x:e.clientX,y:e.clientY}}var au=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Mo(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(...Mo(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(...Mo(i.document,t))}}catch{}return n}function Ua(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function lu(){var e,t;const n=Ua()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function qa(e){return!e||!oi(e)?!1:e instanceof at(e).ShadowRoot}function Zi(e){if(e&&oi(e)){let t=e.getRootNode();if(qa(t)||t instanceof Document)return t}return ir(e)}function Ka(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function wg(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];zl(i)&&zl(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),Wl(i)&&Wl(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function zl(e){return"value"in e}function Wl(e){return e.tagName==="CANVAS"}function cu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(kg(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return cu(i,{x:t-s,y:n-o})}}return r}function kg(e){return e?.tagName==="IFRAME"}var Eo=new WeakMap;function Sg(e){return e.closest(`
|
|
2
|
+
input:not([disabled]),
|
|
3
|
+
select:not([disabled]),
|
|
4
|
+
textarea:not([disabled]),
|
|
5
|
+
button:not([disabled]),
|
|
6
|
+
a[href],
|
|
7
|
+
[contenteditable]:not([contenteditable="false"])
|
|
8
|
+
`)}var du=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 Kn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function $g(e){const t=new Set;let n=Kn(e);for(;n;)t.add(n),n=Kn(n);return t}function jg(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function uu(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=jg(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function Cg(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 Mg(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Kr(e,t);return n>0&&r>0}var Eg=au?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Ii,Og=class extends Eg{constructor(e){super(t=>{if(!Y(this,Ii)){rt(this,Ii,!0);return}e(t,this)}),et(this,Ii,!1)}};Ii=new WeakMap;var Nl=Array.from({length:100},(e,t)=>t/100),hu=75,tn,Qi,zt,nn,Sr,Fe,Lr,$r,es,fu,pu,mu=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,et(this,es),this.disconnect=()=>{var s,o,a;rt(this,Lr,!0),(s=Y(this,zt))==null||s.disconnect(),(o=Y(this,nn))==null||o.disconnect(),Y(this,Sr).disconnect(),(a=Y(this,Fe))==null||a.remove()},et(this,tn,!0),et(this,Qi),et(this,zt),et(this,nn),et(this,Sr),et(this,Fe),et(this,Lr,!1),et(this,$r,uu(()=>{var s,o,a;const{element:d}=this;if((s=Y(this,nn))==null||s.disconnect(),Y(this,Lr)||!Y(this,tn)||!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=Kr(d,u),{top:g,left:v,bottom:y,right:k}=p,h=-Math.floor(g),b=-Math.floor(v),x=-Math.floor(l-k),w=-Math.floor(c-y),$=`${h}px ${x}px ${w}px ${b}px`;this.boundingClientRect=u,rt(this,nn,new IntersectionObserver(E=>{const[D]=E,{intersectionRect:O}=D;(D.intersectionRatio!==1?D.intersectionRatio:jt.intersectionRatio(O,Kr(d)))!==1&&Y(this,$r).call(this)},{threshold:Nl,rootMargin:$,root:f})),Y(this,nn).observe(d),iu(this,es,fu).call(this)},hu)),this.boundingClientRect=e.getBoundingClientRect(),rt(this,tn,Mg(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(rt(this,Fe,document.createElement("div")),Y(this,Fe).style.background="rgba(0,0,0,0.15)",Y(this,Fe).style.position="fixed",Y(this,Fe).style.pointerEvents="none",i.body.appendChild(Y(this,Fe))),rt(this,Sr,new IntersectionObserver(s=>{var o,a;const d=s[s.length-1],{boundingClientRect:f,isIntersecting:c}=d,{width:l,height:u}=f,p=Y(this,tn);rt(this,tn,c),!(!l&&!u)&&(p&&!c?((o=Y(this,nn))==null||o.disconnect(),this.callback(null),(a=Y(this,zt))==null||a.disconnect(),rt(this,zt,void 0),Y(this,Fe)&&(Y(this,Fe).style.visibility="hidden")):Y(this,$r).call(this),c&&!Y(this,zt)&&(rt(this,zt,new Og(Y(this,$r))),Y(this,zt).observe(e)))},{threshold:Nl,root:i})),Y(this,tn)&&!n.skipInitial&&this.callback(this.boundingClientRect),Y(this,Sr).observe(e)}};tn=new WeakMap;Qi=new WeakMap;zt=new WeakMap;nn=new WeakMap;Sr=new WeakMap;Fe=new WeakMap;Lr=new WeakMap;$r=new WeakMap;es=new WeakSet;fu=function(){Y(this,Lr)||(iu(this,es,pu).call(this),!Cg(this.boundingClientRect,Y(this,Qi))&&(this.callback(this.boundingClientRect),rt(this,Qi,this.boundingClientRect)))};pu=function(){if(Y(this,Fe)){const{top:e,left:t,width:n,height:r}=Kr(this.element);Y(this,Fe).style.overflow="hidden",Y(this,Fe).style.visibility="visible",Y(this,Fe).style.top=`${Math.floor(e)}px`,Y(this,Fe).style.left=`${Math.floor(t)}px`,Y(this,Fe).style.width=`${Math.floor(n)}px`,Y(this,Fe).style.height=`${Math.floor(r)}px`}};var xi=new WeakMap,yi=new WeakMap;function Tg(e,t){let n=xi.get(e);return n||(n={disconnect:new mu(e,r=>{const i=xi.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),xi.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(xi.delete(e),n.disconnect())}}function Dg(e,t){const n=new Set;for(const r of e){const i=Tg(r,t);n.add(i)}return()=>n.forEach(r=>r())}function Ag(e,t){var n;const r=e.ownerDocument;if(!yi.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}),yi.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=yi.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),yi.delete(r))})}var jr,Cr,zi,Oo,Rg=class{constructor(e,t,n){this.callback=t,et(this,jr),et(this,Cr,!1),et(this,zi),et(this,Oo,uu(o=>{if(!Y(this,Cr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of Y(this,zi))if(o.target.contains(a)){this.callback(Y(this,jr).boundingClientRect);break}}},hu));const r=$g(e),i=Dg(r,t),s=Ag(e,Y(this,Oo));rt(this,zi,r),rt(this,jr,new mu(e,t,n)),this.disconnect=()=>{Y(this,Cr)||(rt(this,Cr,!0),i(),s(),Y(this,jr).disconnect())}}};jr=new WeakMap;Cr=new WeakMap;zi=new WeakMap;Oo=new WeakMap;function To(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Ln(e){try{To(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Ll(e){return!au||!e?!1:e===ir(e).scrollingElement}function gu(e){var t,n;const r=at(e),i=Ll(e)?bg(e):ys(e),s=r.visualViewport,o=Ll(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 Pg(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=gu(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 Ga=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))}},ts=new Ga(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Ig=new Ga(e=>setTimeout(e,50)),ns=new Map,zg=ns.clear.bind(ns);function Et(e,t=!1){if(!t)return Fl(e);let n=ns.get(e);return n||(n=Fl(e),ns.set(e,n),Ig.schedule(zg),n)}function Fl(e){return at(e).getComputedStyle(e)}function Wg(e,t=Et(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Ng(e,t=Et(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 Lg={excludeElement:!0,escapeShadowDOM:!0};function Do(e,t=Lg){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(Ha(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&qa(a))return o(a.host);if(!Kt(a))return ou(a)?o(a.parentElement):s;if(s.has(a))return s;const d=Et(a,!0);if(r&&a===e||Ng(a,d)&&s.add(a),Wg(a,d)){const{scrollingElement:f}=a.ownerDocument;return f&&s.add(f),s}return o(a.parentNode)}return e?o(e):s}function Gn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Kn(e);for(;r;){if(r===t)return n;const i=ys(r),{x:s,y:o}=Fg(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=Kn(r)}return n}function Fg(e,t=ys(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Kt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=Et(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function Bg(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 Gr(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 ws(e){var t,n,r,i,s,o,a,d,f;const{scale:c,transform:l,translate:u}=e,p=Bg(c),g=Gr(u),v=_g(l);if(!v&&!p&&!g)return null;const y={x:(t=p?.x)!=null?t:1,y:(n=p?.y)!=null?n:1},k={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:k.x+h.x,y:k.y+h.y,z:(f=g?.z)!=null?f:0,scaleX:y.x*h.scaleX,scaleY:y.y*h.scaleY}}function _g(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 ut=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(ut||{}),Hg={x:.2,y:.2},Ug={x:10,y:10};function qg(e,t,n,r=25,i=Hg,s=Ug){const{x:o,y:a}=t,{rect:d,isTop:f,isBottom:c,isLeft:l,isRight:u}=gu(e),p=Gn(e),g=Et(e,!0),v=ws(g),y=v!==null?v?.scaleX<0:!1,k=v!==null?v?.scaleY<0:!1,h=new jt(d.left*p.scaleX+p.x,d.top*p.scaleY+p.y,d.width*p.scaleX,d.height*p.scaleY),b={x:0,y:0},x={x:0,y:0},w={height:h.height*i.y,width:h.width*i.x};return w.height>0&&(!f||k&&!c)&&a<=h.top+w.height&&n?.y!==1&&o>=h.left-s.x&&o<=h.right+s.x?(b.y=k?1:-1,x.y=r*Math.abs((h.top+w.height-a)/w.height)):w.height>0&&(!c||k&&!f)&&a>=h.bottom-w.height&&n?.y!==-1&&o>=h.left-s.x&&o<=h.right+s.x&&(b.y=k?-1:1,x.y=r*Math.abs((h.bottom-w.height-a)/w.height)),w.width>0&&(!u||y&&!l)&&o>=h.right-w.width&&n?.x!==-1&&a>=h.top-s.y&&a<=h.bottom+s.y?(b.x=y?-1:1,x.x=r*Math.abs((h.right-w.width-o)/w.width)):w.width>0&&(!l||y&&!u)&&o<=h.left+w.width&&n?.x!==1&&a>=h.top-s.y&&a<=h.bottom+s.y&&(b.x=y?1:-1,x.x=r*Math.abs((h.left+w.width-o)/w.width)),{direction:b,speed:x}}function vu(e,{block:t="nearest",inline:n="nearest"}={}){if(!Kt(e))return;const r=Do(e),i=[];for(const s of r){if(!Kt(s))continue;const{top:o,left:a}=Kg(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 Bl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!Kt(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function Kg(e,t){const n=Bl(e),r=Bl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Gg(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 Yg(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 bu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function _l(e,t=Et(e).translate,n=!0){if(n){const r=su(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=Gr(i);if(s)return s}}}if(t){const r=Gr(t);if(r)return r}return{x:0,y:0,z:0}}var Vg=new Ga(e=>setTimeout(e,0)),Fr=new Map,Xg=Fr.clear.bind(Fr);function Jg(e){const t=e.ownerDocument;let n=Fr.get(t);if(n)return n;n=t.getAnimations(),Fr.set(t,n),Vg.schedule(Xg);const r=n.filter(i=>xs(i.effect)&&i.effect.target===e);return Fr.set(e,r),n}function Zg(e,t){const n=Jg(e).filter(r=>{var i,s;if(xs(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 $t=class extends jt{constructor(e,t={}){var n,r,i,s;const{frameTransform:o=Gn(e),ignoreTransforms:a,getBoundingClientRect:d=ys}=t,f=Zg(e,{properties:["transform","translate","scale","width","height"],isValidTarget:w=>(w!==e||Ua())&&w.contains(e)}),c=d(e);let{top:l,left:u,width:p,height:g}=c,v;const y=Et(e),k=ws(y),h={x:(n=k?.scaleX)!=null?n:1,y:(r=k?.scaleY)!=null?r:1},b=Qg(e,y);f?.(),k&&(v=Yg(c,k,y.transformOrigin),(a||b)&&(l=v.top,u=v.left,p=v.width,g=v.height));const x={width:(i=v?.width)!=null?i:p,height:(s=v?.height)!=null?s:g};if(b&&!a&&v){const w=Gg(v,b,y.transformOrigin);l=w.top,u=w.left,p=w.width,g=w.height,h.x=b.scaleX,h.y=b.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=x.width,this.intrinsicHeight=x.height}};function Qg(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=xs(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?ws({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function Br(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 ev=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Br(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(Br(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(Br(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function hn(e){return e?e instanceof at(e).Element||oi(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Yr(e){if(!e)return!1;const{KeyboardEvent:t}=at(e.target);return e instanceof t}function tv(e){if(!e)return!1;const{PointerEvent:t}=at(e.target);return e instanceof t}function nv(e){if(!hn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||rv(e)}function rv(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Ls={};function Ao(e){const t=Ls[e]==null?0:Ls[e]+1;return Ls[e]=t,`${e}-${t}`}var Ya=({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=dt.distance(t.shape.center,n);return{id:r,value:1/i,type:rr.PointerIntersection,priority:nr.High}}return null},iv=({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=dt.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:rr.ShapeIntersection,priority:nr.Normal}}return null},xu=e=>{var t;return(t=Ya(e))!=null?t:iv(e)},sv=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const s=r?jt.from(r.current.boundingRectangle).corners:void 0,o=jt.from(n.shape.boundingRectangle).corners.reduce((a,d,f)=>{var c;return a+dt.distance(dt.from(d),(c=s?.[f])!=null?c:i.current)},0)/4;return{id:n.id,value:1/o,type:rr.Collision,priority:nr.Normal}},ov=Object.create,Va=Object.defineProperty,av=Object.defineProperties,lv=Object.getOwnPropertyDescriptor,cv=Object.getOwnPropertyDescriptors,rs=Object.getOwnPropertySymbols,yu=Object.prototype.hasOwnProperty,wu=Object.prototype.propertyIsEnumerable,ku=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),sr=e=>{throw TypeError(e)},Ro=(e,t,n)=>t in e?Va(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Vr=(e,t)=>{for(var n in t||(t={}))yu.call(t,n)&&Ro(e,n,t[n]);if(rs)for(var n of rs(t))wu.call(t,n)&&Ro(e,n,t[n]);return e},Xa=(e,t)=>av(e,cv(t)),Hl=(e,t)=>Va(e,"name",{value:t,configurable:!0}),Su=(e,t)=>{var n={};for(var r in e)yu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&rs)for(var r of rs(e))t.indexOf(r)<0&&wu.call(e,r)&&(n[r]=e[r]);return n},or=e=>{var t;return[,,,ov((t=e?.[ku("metadata")])!=null?t:null)]},$u=["class","method","getter","setter","accessor","field","value","get","set"],Mr=e=>e!==void 0&&typeof e!="function"?sr("Function expected"):e,dv=(e,t,n,r,i)=>({kind:$u[e],name:t,metadata:r,addInitializer:s=>n._?sr("Already initialized"):i.push(Mr(s||null))}),vn=(e,t)=>Ro(t,ku("metadata"),e[3]),ze=(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},mt=(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=$u[l+5],y=l>3&&(e[g-1]=[]),k=e[g]||(e[g]=[]),h=l&&(!p&&!u&&(i=i.prototype),l<5&&(l>3||!p)&&lv(l<4?i:{get[n](){return ge(this,s)},set[n](x){return Je(this,s,x)}},n));l?p&&l<4&&Hl(s,(l>2?"set ":l>1?"get ":"")+n):Hl(i,n);for(var b=r.length-1;b>=0;b--)f=dv(l,n,d={},e[3],k),l&&(f.static=u,f.private=p,c=f.access={has:p?x=>uv(i,x):x=>n in x},l^3&&(c.get=p?x=>(l^1?ge:fn)(x,i,l^4?s:h.get):x=>x[n]),l>2&&(c.set=p?(x,w)=>Je(x,i,w,l^4?s:h.set):(x,w)=>x[n]=w)),a=(0,r[b])(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?Mr(a)&&(l>4?y.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?sr("Object expected"):(Mr(o=a.get)&&(h.get=o),Mr(o=a.set)&&(h.set=o),Mr(o=a.init)&&y.unshift(o));return l||vn(e,i),h&&Va(i,n,h),p?l^4?s:h:i},Ja=(e,t,n)=>t.has(e)||sr("Cannot "+n),uv=(e,t)=>Object(t)!==t?sr('Cannot use the "in" operator on this value'):e.has(t),ge=(e,t,n)=>(Ja(e,t,"read from private field"),n?n.call(e):t.get(e)),Ae=(e,t,n)=>t.has(e)?sr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Je=(e,t,n,r)=>(Ja(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),fn=(e,t,n)=>(Ja(e,t,"access private method"),n),Ul={role:"button",roleDescription:"draggable"},hv="dnd-kit-description",fv="dnd-kit-announcement",pv={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."},mv={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 gv(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function vv(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function bv(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 xv=["dragover","dragmove"],yv=class extends qe{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=hv,announcement:i=fv}={},announcements:s=mv,screenReaderInstructions:o=pv,debounce:a=500}=t??{},d=n?`${r}-${n}`:Ao(r),f=n?`${i}-${n}`:Ao(i);let c,l,u,p;const g=(w=p)=>{!u||!w||u?.nodeValue!==w&&(u.nodeValue=w)},v=()=>ts.schedule(g),y=wv(v,a),k=Object.entries(s).map(([w,$])=>this.manager.monitor.addEventListener(w,(E,D)=>{const O=u;if(!O)return;const j=$?.(E,D);j&&O.nodeValue!==j&&(p=j,xv.includes(w)?y():(v(),y.cancel()))})),h=()=>{let w=[];c?.isConnected||(c=vv(d,o.draggable),w.push(c)),l?.isConnected||(l=bv(f),u=document.createTextNode(""),l.appendChild(u),w.push(l)),w.length>0&&document.body.append(...w)},b=new Set;function x(){for(const w of b)w()}this.registerEffect(()=>{var w;b.clear();for(const $ of this.manager.registry.draggables.value){const E=(w=$.handle)!=null?w:$.element;if(E){(!c||!l)&&b.add(h),(!gv(E)||Ua())&&!E.hasAttribute("tabindex")&&b.add(()=>E.setAttribute("tabindex","0")),!E.hasAttribute("role")&&E.tagName.toLowerCase()!=="button"&&b.add(()=>E.setAttribute("role",Ul.role)),E.hasAttribute("aria-roledescription")||b.add(()=>E.setAttribute("aria-roledescription",Ul.roleDescription)),E.hasAttribute("aria-describedby")||b.add(()=>E.setAttribute("aria-describedby",d));for(const O of["aria-pressed","aria-grabbed"]){const j=String($.isDragging);E.getAttribute(O)!==j&&b.add(()=>E.setAttribute(O,j))}const D=String($.disabled);E.getAttribute("aria-disabled")!==D&&b.add(()=>E.setAttribute("aria-disabled",D))}}b.size>0&&ts.schedule(x)}),this.destroy=()=>{super.destroy(),c?.remove(),l?.remove(),k.forEach(w=>w())}}};function wv(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var is=new Map,ju,Cu,Mu,Eu,Po,_r,Dt,Za,Yn,Ou,Tu,Du,Au,Gt=class extends(Po=si,Eu=[le],Mu=[Oe],Cu=[Oe],ju=[Oe],Po){constructor(e,t){super(e,t),ze(Dt,5,this),Ae(this,Yn),Ae(this,_r,new Set),Ae(this,Za,ze(Dt,8,this,new Set)),ze(Dt,11,this),this.registerEffect(fn(this,Yn,Ou))}register(e){return ge(this,_r).add(e),()=>{ge(this,_r).delete(e)}}addRoot(e){return ae(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{ae(()=>{const t=new Set(this.additionalRoots);t.delete(e),this.additionalRoots=t})}}get sourceRoot(){var e;const{source:t}=this.manager.dragOperation;return Zi((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return Zi((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}};Dt=or(Po);_r=new WeakMap;Za=new WeakMap;Yn=new WeakSet;Ou=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ge(this,_r))t.push(fn(this,Yn,Tu).call(this,n,r));return()=>{for(const n of t)n()}};Tu=function(e,t){let n=is.get(e);n||(n=new Map,is.set(e,n));let r=n.get(t);if(!r){const s=Ha(e)?fn(this,Yn,Du).call(this,e,n,t):fn(this,Yn,Au).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())}};Du=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&&is.delete(e)}}};Au=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(qa(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&&is.delete(e)}}};mt(Dt,4,"additionalRoots",Eu,Gt,Za);mt(Dt,2,"sourceRoot",Mu,Gt);mt(Dt,2,"targetRoot",Cu,Gt);mt(Dt,2,"roots",ju,Gt);vn(Dt,Gt);Gt.configure=ii(Gt);var ks=Gt,kv=class extends qe{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(ks),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},ai="data-dnd-",Io=`${ai}dropping`,Le="--dnd-",St=`${ai}dragging`,ss=`${ai}placeholder`,Sv=[St,ss,"popover","aria-pressed","aria-grabbing"],$v=["view-transition-name"],jv=`
|
|
9
|
+
:is(:root,:host) [${St}] {
|
|
10
|
+
position: fixed !important;
|
|
11
|
+
pointer-events: none !important;
|
|
12
|
+
touch-action: none;
|
|
13
|
+
z-index: calc(infinity);
|
|
14
|
+
will-change: translate;
|
|
15
|
+
top: var(${Le}top, 0px) !important;
|
|
16
|
+
left: var(${Le}left, 0px) !important;
|
|
17
|
+
right: unset !important;
|
|
18
|
+
bottom: unset !important;
|
|
19
|
+
width: var(${Le}width, auto);
|
|
20
|
+
max-width: var(${Le}width, auto);
|
|
21
|
+
height: var(${Le}height, auto);
|
|
22
|
+
max-height: var(${Le}height, auto);
|
|
23
|
+
transform: var(${Le}transform, none) !important;
|
|
24
|
+
transition: var(${Le}transition) !important;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
:is(:root,:host) [${ss}] {
|
|
28
|
+
transition: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
:is(:root,:host) [${ss}='hidden'] {
|
|
32
|
+
visibility: hidden;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
[${St}] * {
|
|
36
|
+
pointer-events: none !important;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[${St}]:not([${Io}]) {
|
|
40
|
+
translate: var(${Le}translate) !important;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
[${St}][style*='${Le}scale'] {
|
|
44
|
+
scale: var(${Le}scale) !important;
|
|
45
|
+
transform-origin: var(${Le}transform-origin) !important;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@layer dnd-kit {
|
|
49
|
+
:where([${St}][popover]) {
|
|
50
|
+
overflow: visible;
|
|
51
|
+
background: unset;
|
|
52
|
+
border: unset;
|
|
53
|
+
margin: unset;
|
|
54
|
+
padding: unset;
|
|
55
|
+
color: inherit;
|
|
56
|
+
|
|
57
|
+
&:is(input, button) {
|
|
58
|
+
border: revert;
|
|
59
|
+
background: revert;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
[${St}]::backdrop, [${ai}overlay]:not([${St}]) {
|
|
64
|
+
display: none;
|
|
65
|
+
visibility: hidden;
|
|
66
|
+
}
|
|
67
|
+
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Cv(e,t="hidden"){return ae(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Mv(n,r.registry.droppables),s=[],o=wg(n),{remove:a}=o;return Ev(i,o,s),Ov(o,t),o.remove=()=>{s.forEach(d=>d()),a.call(o)},o})}function Mv(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${ai}${Ao("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Ev(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),Eo.set(a,o),n.push(()=>{Eo.delete(a),r.proxy=void 0})}}function Ov(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(ss,t)}function Ru(e,t){return e===t?!0:Kn(e)===Kn(t)}function ql(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&hn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Ln(t))}function zo(e){return e.tagName==="TR"}function Tv(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-")||Sv.includes(a))continue;const d=e.getAttribute(a);if(a==="style"){if(Br(e)&&Br(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($v.includes(c)||c.startsWith(Le))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 Dv(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),Ln(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Ln(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Ln(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Av(e){return new ResizeObserver(()=>{var t,n,r;const i=new $t(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=lu();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},Le),(n=e.getElementMutationObserver())==null||n.takeRecords(),zo(e.element)&&zo(e.placeholder)){const v=Array.from(e.element.cells),y=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(v.map(k=>k.style.width));for(const[k,h]of v.entries()){const b=y[k];h.style.width=`${b.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 jt(c*g.scaleX+g.x,l*g.scaleY+g.y,u*g.scaleX,p*g.scaleY)})}var Rv=250,Pv="ease";function Iv(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=Rv,easing:a=Pv}=s??{};Ln(e.feedbackElement);const[,d]=(t=su(e.feedbackElement,h=>"translate"in h))!=null?t:[];d?.pause();const f=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Ru(e.feedbackElement,f)?null:void 0},l=new $t(e.feedbackElement,c),u=(r=Gr(Et(e.feedbackElement).translate))!=null?r:e.translate,p=new $t(f,c),g=jt.delta(l,p,e.alignment),v={x:u.x-g.x,y:u.y-g.y},y=Math.round(l.intrinsicHeight)!==Math.round(p.intrinsicHeight)?{minHeight:[`${l.intrinsicHeight}px`,`${p.intrinsicHeight}px`],maxHeight:[`${l.intrinsicHeight}px`,`${p.intrinsicHeight}px`]}:{},k=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},Le),e.feedbackElement.setAttribute(Io,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),bu({element:e.feedbackElement,keyframes:Xa(Vr(Vr({},y),k),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:Ka(at(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Io),d?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Pu,Wo,Xr,Qa,Wi,Iu,zu,Vn=class extends(Wo=qe,Pu=[le],Wo){constructor(e,t){super(e,t),Ae(this,Wi),Ae(this,Qa,ze(Xr,8,this)),ze(Xr,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(ks),r=n?.register(jv);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(fn(this,Wi,Iu).bind(this,n)),this.registerEffect(fn(this,Wi,zu))}};Xr=or(Wo);Qa=new WeakMap;Wi=new WeakSet;Iu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Zi(t);if(n)return e.addRoot(n)};zu=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(Vn),y=(t=(e=v?.feedback)!=null?e:f?.feedback)!=null?t:"default",k=typeof y=="function"?y(u,d):y;if(!g||k==="none"||!p.initialized||p.initializing)return;const{initial:h}=a,b=(n=this.overlay)!=null?n:g,x=Gn(b),w=Gn(g),$=!Ru(g,b),E=new $t(g,{frameTransform:$?w:null,ignoreTransforms:!$}),D={x:w.scaleX/x.scaleX,y:w.scaleY/x.scaleY};let{width:O,height:j,top:P,left:R}=E;$&&(O=O/D.x,j=j/D.y);const A=new ev(b),L=Et(g),{transition:U,translate:_,boxSizing:T,paddingBlockStart:z,paddingBlockEnd:F,paddingInlineStart:W,paddingInlineEnd:B,borderInlineStartWidth:X,borderInlineEndWidth:J,borderBlockStartWidth:re,borderBlockEndWidth:ee}=L,N=U.split(",").filter(ve=>!/^\s*(transform|translate|scale)\b/.test(ve)).join(","),Z=ws(L),pe=L.transform,ne=k==="clone",Q=T==="content-box",Se=Q?parseInt(W)+parseInt(B)+parseInt(X)+parseInt(J):0,be=Q?parseInt(z)+parseInt(F)+parseInt(re)+parseInt(ee):0,G=k!=="move"&&!this.overlay?Cv(u,ne?"clone":"hidden"):null,$e=ae(()=>Yr(d.dragOperation.activatorEvent));if(!h.translate){if(this.overlay&&Z)h.translate={x:Z.x,y:Z.y};else if(_!=="none"){const ve=Gr(_);ve&&(h.translate=ve)}}if(!h.transformOrigin){const ve=ae(()=>l.current),We=R+((r=Z?.x)!=null?r:0),nt=P+((i=Z?.y)!=null?i:0);h.transformOrigin={x:(ve.x-We*x.scaleX-x.x)/(O*x.scaleX),y:(ve.y-nt*x.scaleY-x.y)/(j*x.scaleY)}}const{transformOrigin:he}=h,ie=P*x.scaleY+x.y,Ne=R*x.scaleX+x.x;if(!h.coordinates&&(h.coordinates={x:Ne,y:ie},D.x!==1||D.y!==1)){const{scaleX:ve,scaleY:We}=w,{x:nt,y:It}=he;h.coordinates.x+=(O*ve-O)*nt,h.coordinates.y+=(j*We-j)*It}h.dimensions||(h.dimensions={width:O,height:j}),h.frameTransform||(h.frameTransform=x);const Ke={x:h.coordinates.x-Ne,y:h.coordinates.y-ie},He={width:(h.dimensions.width*h.frameTransform.scaleX-O*x.scaleX)*he.x,height:(h.dimensions.height*h.frameTransform.scaleY-j*x.scaleY)*he.y},Ge={x:Ke.x/x.scaleX+He.width,y:Ke.y/x.scaleY+He.height},Ye={left:R+Ge.x,top:P+Ge.y};b.setAttribute(St,"true");const M=ae(()=>c.transform),I=(s=h.translate)!=null?s:{x:0,y:0},q=M.x*x.scaleX+I.x,C=M.y*x.scaleY+I.y,te=lu();A.set({width:O-Se,height:j-be,top:Ye.top+te.y,left:Ye.left+te.x,translate:`${q}px ${C}px 0`,transform:this.overlay?"none":pe,transition:N?`${N}, translate 0ms linear`:"translate 0ms linear",scale:$?`${D.x} ${D.y}`:"","transform-origin":`${he.x*100}% ${he.y*100}%`},Le),G&&(g.insertAdjacentElement("afterend",G),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(g)),To(b)&&(b.hasAttribute("popover")||b.setAttribute("popover","manual"),Ln(b),b.addEventListener("beforetoggle",ql));let K,se,me;const oe=Av({placeholder:G,element:g,feedbackElement:b,frameTransform:x,transformOrigin:he,width:O,height:j,top:P,left:R,widthOffset:Se,heightOffset:be,delta:Ge,styles:A,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>K,getSavedCellWidths:()=>me,setSavedCellWidths:ve=>{me=ve}}),kt=new $t(b);ae(()=>c.shape=kt);const Ot=at(b),Xt=ve=>{this.manager.actions.stop({event:ve})},cr=Ka(Ot);$e&&Ot.addEventListener("resize",Xt),ae(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),G&&(oe.observe(G),K=Tv(g,G,ne),se=Dv(g,G,b));const dr=(o=d.dragOperation.source)==null?void 0:o.id,Ms=()=>{var ve;if(!$e||dr==null)return;const We=d.registry.draggables.get(dr),nt=(ve=We?.handle)!=null?ve:We?.element;Kt(nt)&&nt.focus()},ur=()=>{K?.disconnect(),se?.disconnect(),oe.disconnect(),Ot.removeEventListener("resize",Xt),To(b)&&(b.removeEventListener("beforetoggle",ql),b.removeAttribute("popover")),b.removeAttribute(St),A.reset();const ve=()=>{var We;if(me&&zo(g)){const Es=Array.from(g.cells);for(const[pi,bn]of Es.entries())bn.style.width=(We=me[pi])!=null?We:""}u.status="idle";const nt=a.current.translate!=null,It=c.status.dragging;G&&(!It&&nt||G.parentElement!==b.parentElement)&&b.isConnected&&G.replaceWith(b),G?.remove()};b===this.overlay?setTimeout(ve,0):ve()},hr=f?.dropAnimation,fi=this,Zh=ni(()=>{var ve,We,nt;const{transform:It,status:Es}=c;if(!(!It.x&&!It.y&&!a.current.translate)&&Es.dragging){const pi=(ve=h.translate)!=null?ve:{x:0,y:0},bn={x:It.x/x.scaleX+pi.x,y:It.y/x.scaleY+pi.y},ml=a.current.translate,Qh=ae(()=>c.modifiers),Os=ae(()=>{var fr;return(fr=c.shape)==null?void 0:fr.current}),Ts=f?.keyboardTransition,gl=$e&&!cr&&Ts!==null?`${(We=Ts?.duration)!=null?We:250}ms ${(nt=Ts?.easing)!=null?nt:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(A.set({transition:N?`${N}, translate ${gl}`:`translate ${gl}`,translate:`${bn.x}px ${bn.y}px 0`},Le),K?.takeRecords(),Os&&Os!==kt&&ml&&!Qh.length){const fr=dt.delta(bn,ml);c.shape=jt.from(Os.boundingRectangle).translate(fr.x*x.scaleX,fr.y*x.scaleY)}else c.shape=new $t(b);a.current.translate=bn}},function(){if(c.status.dropped){this.dispose(),u.status="dropping";const ve=v?.dropAnimation!==void 0?v.dropAnimation:fi.dropAnimation!==void 0?fi.dropAnimation:hr;let We=a.current.translate;const nt=We!=null;if(!We&&g!==b&&(We={x:0,y:0}),!We||ve===null){ur();return}d.renderer.rendering.then(()=>{Iv({source:u,element:g,feedbackElement:b,placeholder:G,translate:We,moved:nt,transition:U,alignment:u.alignment,styles:A,animation:ve??void 0,getElementMutationObserver:()=>K,cleanup:ur,restoreFocus:Ms})})}});return()=>{ur(),Zh()}};mt(Xr,4,"overlay",Pu,Vn,Qa);vn(Xr,Vn);Vn.configure=ii(Vn);var el=Vn,mr=!0,zv=!1,Wu,Nu,Lu,Fu,Bt,tl,nl;Fu=(Lu=[le],ut.Forward),Nu=(Wu=[le],ut.Reverse);var Jr=class{constructor(){Ae(this,tl,ze(Bt,8,this,mr)),ze(Bt,11,this),Ae(this,nl,ze(Bt,12,this,mr)),ze(Bt,15,this)}isLocked(e){return e===ut.Idle?!1:e==null?this[ut.Forward]===mr&&this[ut.Reverse]===mr:this[e]===mr}unlock(e){e!==ut.Idle&&(this[e]=zv)}};Bt=or(null);tl=new WeakMap;nl=new WeakMap;mt(Bt,4,Fu,Lu,Jr,tl);mt(Bt,4,Nu,Wu,Jr,nl);vn(Bt,Jr);var Wv=[ut.Forward,ut.Reverse],Kl=class{constructor(){this.x=new Jr,this.y=new Jr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Nv=class extends qe{constructor(e){super(e);const t=Xn(new Kl);let n=null;this.signal=t,pt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new Kl;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:Gl(i.x,n.x),y:Gl(i.y,n.y)},o=t.peek();Me(()=>{for(const a of md)for(const d of Wv)s[a]===d&&o[a].unlock(d);t.value=o})}n=i})}get current(){return this.signal.peek()}};function Gl(e,t){return Math.sign(e-t)}var Bu,No,Zr,rl,Wt,Lo,li=class extends(No=si,Bu=[le],No){constructor(e){super(e),Ae(this,rl,ze(Zr,8,this,!1)),ze(Zr,11,this),Ae(this,Wt),Ae(this,Lo,()=>{if(!ge(this,Wt))return;const{element:s,by:o}=ge(this,Wt);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 Je(this,Wt,void 0),!1;const{position:f}=this.manager.dragOperation,c=f?.current;if(c){const{by:l}=s??{},u=l?{x:Yl(l.x),y:Yl(l.y)}:void 0,p=u?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const g of d){const v=Pg(g,l);if(v.x||v.y){const{speed:y,direction:k}=qg(g,c,u,o?.acceleration,o?.threshold);if(p)for(const h of md)p[h].isLocked(k[h])&&(y[h]=0,k[h]=0);if(k.x||k.y){const{x:h,y:b}=l??k,x=h*y.x,w=b*y.y;if(x||w){const $=(a=ge(this,Wt))==null?void 0:a.by;if(this.autoScrolling&&$&&($.x&&!x||$.y&&!w))continue;return Je(this,Wt,{element:g,by:{x,y:w}}),ts.schedule(ge(this,Lo)),!0}}}}}return Je(this,Wt,void 0),!1};let t=null,n=null;const r=po(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=cu(Zi(o?.element),s.current);return a&&(t=a),a??t}),i=po(()=>{const s=r.value,{documentElement:o}=ir(s);if(!s||s===o){const{target:a}=e.dragOperation,d=a?.element;if(d){const f=Do(d,{excludeElement:!1});return n=f,f}}if(s){const a=Do(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},gt);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new Nv(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!Yr(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};Zr=or(No);rl=new WeakMap;Wt=new WeakMap;Lo=new WeakMap;mt(Zr,4,"autoScrolling",Bu,li,rl);vn(Zr,li);function Yl(e){return e>0?ut.Forward:e<0?ut.Reverse:ut.Idle}var Lv=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))}},Fv=new Lv(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Bv=10,Fo=class extends qe{constructor(e,t){super(e,t);const n=e.registry.plugins.get(li);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=pt(()=>{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(()=>Fv.schedule(()=>n.scroll(void 0,d)),Bv);return()=>{clearInterval(f)}}else n.autoScrolling=!1}})}};Fo.configure=ii(Fo);var _u=Fo,Vl={capture:!0,passive:!0},Er,_v=class extends si{constructor(e){super(e),Ae(this,Er),this.handleScroll=()=>{ge(this,Er)==null&&Je(this,Er,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Je(this,Er,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=pt(()=>{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,Vl),()=>{s.removeEventListener("scroll",this.handleScroll,Vl)}}})}};Er=new WeakMap;var Hv="* { user-select: none !important; -webkit-user-select: none !important; }",Uv=class extends qe{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(ks),n=t?.register(Hv);if(this.destroy=pt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Fs(),document.addEventListener("selectionchange",Fs,{capture:!0}),()=>{document.removeEventListener("selectionchange",Fs,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Fs(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Or=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}}),On,os=class extends Un{constructor(e,t){super(e),this.manager=e,this.options=t,Ae(this,On,[]),this.listeners=new du,this.handleSourceKeyDown=(n,r,i)=>{if(this.disabled||n.defaultPrevented||!hn(n.target)||r.disabled)return;const{keyboardCodes:s=Or.keyboardCodes,preventActivation:o=Or.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 pt(()=>{var n;const r=(n=e.handle)!=null?n:e.element,i=s=>{Yr(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(),vu(r);const{center:i}=new $t(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=ir(r),o=[this.listeners.bind(s,[{type:"keydown",listener:a=>this.handleKeyDown(a,t,n),options:{capture:!0}}])];ge(this,On).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=Or.keyboardCodes}=n??{};if(yn(e,[...r.end,...r.cancel])){e.preventDefault();const i=yn(e,r.cancel);this.handleEnd(e,i);return}yn(e,r.up)?this.handleMove("up",e):yn(e,r.down)&&this.handleMove("down",e),yn(e,r.left)?this.handleMove("left",e):yn(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:Or.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(_u);e?.disabled===!1&&(e.disable(),ge(this,On).push(()=>{e.enable()}))}cleanup(){ge(this,On).forEach(e=>e()),Je(this,On,[])}destroy(){this.cleanup(),this.listeners.clear()}};On=new WeakMap;os.configure=ii(os);os.defaults=Or;var Hu=os;function yn(e,t){return t.includes(e.code)}var rn,qv=class extends Gd{constructor(){super(...arguments),Ae(this,rn)}onEvent(e){switch(e.type){case"pointerdown":Je(this,rn,qn(e));break;case"pointermove":if(!ge(this,rn))return;const{x:t,y:n}=qn(e),r={x:t-ge(this,rn).x,y:n-ge(this,rn).y},{tolerance:i}=this.options;if(i&&So(r,i)){this.abort();return}So(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Je(this,rn,void 0)}};rn=new WeakMap;var Tn,sn,Kv=class extends Gd{constructor(){super(...arguments),Ae(this,Tn),Ae(this,sn)}onEvent(e){switch(e.type){case"pointerdown":Je(this,sn,qn(e)),Je(this,Tn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ge(this,sn))return;const{x:t,y:n}=qn(e),r={x:t-ge(this,sn).x,y:n-ge(this,sn).y};So(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ge(this,Tn)&&(clearTimeout(ge(this,Tn)),Je(this,sn,void 0),Je(this,Tn,void 0))}};Tn=new WeakMap;sn=new WeakMap;var Pn=class{};Pn.Delay=Kv;Pn.Distance=qv;var Bo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&hn(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new Pn.Delay({value:250,tolerance:5})]:nv(i)&&!e.defaultPrevented?[new Pn.Delay({value:200,tolerance:0})]:[new Pn.Delay({value:200,tolerance:10}),new Pn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!hn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=Sg(r);return i===t.element?!1:!!i}}),Dn,as=class extends Un{constructor(e,t){super(e),this.manager=e,this.options=t,Ae(this,Dn,new Set),this.listeners=new du,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=Bo.activationConstraints}=n??{};return typeof r=="function"?r(e,t):r}bind(e,t=this.options){return pt(()=>{var n;const r=new AbortController,{signal:i}=r,s=a=>{tv(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&&(Vv(a.ownerDocument.defaultView),a.addEventListener("pointerdown",s,{signal:i}));return()=>r.abort()})}handlePointerDown(e,t,n){if(this.disabled||!e.isPrimary||e.button!==0||!hn(e.target)||t.disabled||Gv(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=Bo.preventActivation}=n??{};if(r?.(e,t))return;const{target:i}=e,s=Kt(i)&&i.draggable&&i.getAttribute("draggable")==="true",o=Gn(t.element),{x:a,y:d}=qn(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 pg(f,g=>this.handleStart(t,g));c.signal.onabort=()=>this.handleCancel(e),c.onEvent(e),this.controller=c;const l=Mo(),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:wi,options:{capture:!0}}]),p=()=>{u(),this.initialCoordinates=void 0};ge(this,Dn).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=qn(e),s=Gn(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,ts.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=ir(t.target).body;try{i.setPointerCapture(t.pointerId)}catch{this.handleCancel(t);return}const s=hn(t.target)?[t.target,i]:i,o=this.listeners.bind(s,[{type:"touchmove",listener:wi,options:{passive:!1}},{type:"click",listener:wi},{type:"contextmenu",listener:wi},{type:"keydown",listener:this.handleKeyDown}]);ge(this,Dn).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},ge(this,Dn).forEach(t=>t()),ge(this,Dn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Dn=new WeakMap;as.configure=ii(as);as.defaults=Bo;var _o=as;function Gv(e){return"sensor"in e}function wi(e){e.preventDefault()}function Yv(){}var Xl=new WeakSet;function Vv(e){!e||Xl.has(e)||(e.addEventListener("touchmove",Yv,{capture:!1,passive:!1}),Xl.add(e))}var Fn={modifiers:[],plugins:[yv,_u,kv,el,Uv],sensors:[_o,Hu]},Uu=class extends vg{constructor(e={}){const t=yt(e.plugins,Fn.plugins),n=yt(e.sensors,Fn.sensors),r=yt(e.modifiers,Fn.modifiers);super(Xa(Vr({},e),{plugins:[_v,li,ks,...t],sensors:n,modifiers:r}))}},qu,Ku,Ho,_t,il,sl,Ss=class extends(Ho=Ct,Ku=[le],qu=[le],Ho){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=Su(n,["element","effects","handle"]);super(Vr({effects:()=>[...i(),()=>{var a,d;const{manager:f}=this;if(!f)return;const c=((d=(a=this.sensors)==null?void 0:a.map(Ur))!=null?d:[...f.sensors]).map(l=>{const u=l instanceof Un?l:f.registry.register(l.plugin),p=l instanceof Un?void 0:l.options;return u.bind(this,p)});return function(){c.forEach(l=>l())}}]},o),t),Ae(this,il,ze(_t,8,this)),ze(_t,11,this),Ae(this,sl,ze(_t,12,this)),ze(_t,15,this),this.element=r,this.handle=s}};_t=or(Ho);il=new WeakMap;sl=new WeakMap;mt(_t,4,"handle",Ku,Ss,il);mt(_t,4,"element",qu,Ss,sl);vn(_t,Ss);var Gu,Yu,Uo,Ht,ol,Bs,Vu,Xu,Hr,al,$s=class extends(Uo=Mt,Yu=[le],Gu=[le],Uo){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=Su(n,["element","effects"]);const{collisionDetector:o=xu}=s,a=f=>{const{manager:c,element:l}=this;if(!l||f===null){this.shape=void 0;return}if(!c)return;const u=new $t(l),p=ae(()=>this.shape);return u&&p?.equals(u)?p:(this.shape=u,u)},d=Xn(!1);super(Xa(Vr({},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 Rg(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),Ae(this,Hr),Ae(this,ol,ze(Ht,8,this)),ze(Ht,11,this),Ae(this,al,ze(Ht,12,this)),ze(Ht,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Je(this,Hr,e,Xu)}get element(){var e;return(e=this.proxy)!=null?e:ge(this,Hr,Vu)}};Ht=or(Uo);ol=new WeakMap;Hr=new WeakSet;al=new WeakMap;Bs=mt(Ht,20,"#element",Yu,Hr,ol),Vu=Bs.get,Xu=Bs.set;mt(Ht,4,"proxy",Gu,$s,al);vn(Ht,$s);function Xv(e){return e!=null&&typeof e=="object"&&"current"in e}function Bn(e){var t;if(e!=null)return Xv(e)?(t=e.current)!=null?t:void 0:e}var Jv=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",ar=Jv?S.useLayoutEffect:S.useEffect;function Zv(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Ju(e,t){const n=S.useRef(new Map),r=Zv();return ar(()=>{if(!e){n.current.clear();return}return pt(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[d]=a,f=ae(()=>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(()=>Lp.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 Qv(e,t){e()}function wn(e){const t=S.useRef(e);return ar(()=>{t.current=e},[e]),t}function je(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 Ni(e,t){const n=S.useRef(Bn(e));ar(()=>{const r=Bn(e);r!==n.current&&(n.current=r,t(r))})}var eb=Object.defineProperty,tb=Object.defineProperties,nb=Object.getOwnPropertyDescriptors,ls=Object.getOwnPropertySymbols,Zu=Object.prototype.hasOwnProperty,Qu=Object.prototype.propertyIsEnumerable,Jl=(e,t,n)=>t in e?eb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rb=(e,t)=>{for(var n in t||(t={}))Zu.call(t,n)&&Jl(e,n,t[n]);if(ls)for(var n of ls(t))Qu.call(t,n)&&Jl(e,n,t[n]);return e},ib=(e,t)=>tb(e,nb(t)),sb=(e,t)=>{var n={};for(var r in e)Zu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ls)for(var r of ls(e))t.indexOf(r)<0&&Qu.call(e,r)&&(n[r]=e[r]);return n},ob=new Uu,eh=S.createContext(ob),ab=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 ar(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),S.useImperativeHandle(t,()=>o),null})),_s=[void 0,gt];function lb(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:d}=t,f=sb(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:l,modifiers:u,sensors:p}=f,g=yt(l,Fn.plugins),v=yt(p,Fn.sensors),y=yt(u,Fn.modifiers),k=wn(i),h=wn(s),b=wn(a),x=wn(o),w=wn(d),$=wn(r),E=cb(()=>{var D;return(D=f.manager)!=null?D:new Uu(f)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:D,trackRendering:O}=c.current,{monitor:j}=E;E.renderer=D;const P=[j.addEventListener("beforedragstart",R=>{const A=k.current;A&&O(()=>A(R,E))}),j.addEventListener("dragstart",R=>{var A;return(A=h.current)==null?void 0:A.call(h,R,E)}),j.addEventListener("dragover",R=>{const A=b.current;A&&O(()=>A(R,E))}),j.addEventListener("dragmove",R=>{const A=x.current;A&&O(()=>A(R,E))}),j.addEventListener("dragend",R=>{const A=w.current;A&&O(()=>A(R,E))}),j.addEventListener("collision",R=>{var A;return(A=$.current)==null?void 0:A.call($,R,E)})];return()=>P.forEach(R=>R())},[E]),je(g,()=>E&&(E.plugins=g),..._s),je(v,()=>E&&(E.sensors=v),..._s),je(y,()=>E&&(E.modifiers=y),..._s),m.jsxs(eh.Provider,{value:E,children:[m.jsx(ab,{ref:c,children:n}),n]})}function cb(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 db(){return S.useContext(eh)}function th(e){var t;const n=(t=db())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),ar(r.register,[n,r]),r}var ub=Object.create,nh=Object.defineProperty,hb=Object.getOwnPropertyDescriptor,rh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),js=e=>{throw TypeError(e)},fb=(e,t,n)=>t in e?nh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pb=e=>{var t;return[,,,ub((t=e?.[rh("metadata")])!=null?t:null)]},ih=["class","method","getter","setter","accessor","field","value","get","set"],sh=e=>e!==void 0&&typeof e!="function"?js("Function expected"):e,mb=(e,t,n,r,i)=>({kind:ih[e],name:t,metadata:r,addInitializer:s=>n._?js("Already initialized"):i.push(sh(s||null))}),gb=(e,t)=>fb(t,rh("metadata"),e[3]),vb=(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},oh=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=ih[c+5],v=e[p]||(e[p]=[]),y=(i=i.prototype,hb(i,n)),k=r.length-1;k>=0;k--)d=mb(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[k])(y[g],d),a._=1,sh(o)&&(y[g]=o);return y&&nh(i,n,y),i},ah=(e,t,n)=>t.has(e)||js("Cannot "+n),bb=(e,t,n)=>(ah(e,t,"read from private field"),t.get(e)),xb=(e,t,n)=>t.has(e)?js("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),yb=(e,t,n,r)=>(ah(e,t,"write to private field"),t.set(e,n),n),an=class qo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new qo(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 qo(t,n)}},lh,ch,Ko,Li,ci,ll=class extends(Ko=mn,ch=[Oe],lh=[Oe],Ko){constructor(e){const t=an.from(e);super(t,(n,r)=>an.equals(n,r)),vb(ci,5,this),xb(this,Li,0),this.velocity={x:0,y:0}}get delta(){return an.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=an.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-bb(this,Li),o=a=>Math.round(a/s*100);Me(()=>{yb(this,Li,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(an.from(e)),this.velocity={x:0,y:0}}};ci=pb(Ko);Li=new WeakMap;oh(ci,2,"delta",ch,ll);oh(ci,2,"direction",lh,ll);gb(ci,ll);var dh=(e=>(e.Horizontal="x",e.Vertical="y",e))(dh||{});Object.values(dh);var wb=({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=an.distance(t.shape.center,n);return{id:r,value:1/i,type:rr.PointerIntersection,priority:nr.High}}return null},kb=({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=an.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:rr.ShapeIntersection,priority:nr.Normal}}return null},Sb=e=>{var t;return(t=wb(e))!=null?t:kb(e)};function $b(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,d=th(c=>new $s(ib(rb({},e),{register:!1,element:Bn(i)}),c)),f=Ju(d);return je(s,()=>d.id=s),Ni(i,c=>d.element=c),je(o,()=>d.accept=o,void 0,gt),je(t,()=>d.collisionDetector=t??Sb),je(n,()=>n&&(d.data=n)),je(r,()=>d.disabled=r===!0),je(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 uh=(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 ${Be}`,...qt,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},hh=S.createContext(void 0);function fh(e,t){const n=S.useContext(hh),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 Go({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))};fh(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(H,{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}},uh(s)],children:l?t:e})}return m.jsx(Lc,{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 jb=(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},ph=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),mh=e=>`gap.${e}`,Mb=(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:Ie(e[o-1]),colspan:t-r}),d&&(r=0),n.push(ph(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:Ie(i),colspan:t-r}),n};var Eb=Object.create,gh=Object.defineProperty,Ob=Object.defineProperties,Tb=Object.getOwnPropertyDescriptor,Db=Object.getOwnPropertyDescriptors,cs=Object.getOwnPropertySymbols,vh=Object.prototype.hasOwnProperty,bh=Object.prototype.propertyIsEnumerable,Ab=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),di=e=>{throw TypeError(e)},Yo=(e,t,n)=>t in e?gh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hs=(e,t)=>{for(var n in t||(t={}))vh.call(t,n)&&Yo(e,n,t[n]);if(cs)for(var n of cs(t))bh.call(t,n)&&Yo(e,n,t[n]);return e},Us=(e,t)=>Ob(e,Db(t)),Rb=(e,t)=>{var n={};for(var r in e)vh.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&cs)for(var r of cs(e))t.indexOf(r)<0&&bh.call(e,r)&&(n[r]=e[r]);return n},Pb=e=>{var t;return[,,,Eb((t=void 0)!=null?t:null)]},xh=["class","method","getter","setter","accessor","field","value","get","set"],Tr=e=>e!==void 0&&typeof e!="function"?di("Function expected"):e,Ib=(e,t,n,r,i)=>({kind:xh[e],name:t,metadata:r,addInitializer:s=>n._?di("Already initialized"):i.push(Tr(s||null))}),zb=(e,t)=>Yo(t,Ab("metadata"),e[3]),ki=(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},yh=(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=xh[l+5],y=e[g-1]=[],k=e[g]||(e[g]=[]),h=(i=i.prototype,Tb({get[n](){return Dr(this,s)},set[n](x){return on(this,s,x)}},n)),b=r.length-1;b>=0;b--)f=Ib(l,n,d={},e[3],k),f.static=u,f.private=p,c=f.access={has:x=>n in x},c.get=x=>x[n],c.set=(x,w)=>x[n]=w,a=(0,r[b])({get:h.get,set:h.set},f),d._=1,a===void 0?Tr(a)&&(h[v]=a):typeof a!="object"||a===null?di("Object expected"):(Tr(o=a.get)&&(h.get=o),Tr(o=a.set)&&(h.set=o),Tr(o=a.init)&&y.unshift(o));return h&&gh(i,n,h),i},wh=(e,t,n)=>t.has(e)||di("Cannot "+n),Dr=(e,t,n)=>(wh(e,t,"read from private field"),t.get(e)),gr=(e,t,n)=>t.has(e)?di("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),on=(e,t,n,r)=>(wh(e,t,"write to private field"),t.set(e,n),n);function ln(e){return e instanceof ul||e instanceof jh}var Si=10,Wb=class extends qe{constructor(e){super(e);const t=pt(()=>{const{dragOperation:r}=e;if(Yr(r.activatorEvent)&&ln(r.source)&&r.status.initialized){const i=e.registry.plugins.get(li);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(!Yr(r.nativeEvent)||!ln(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:d}=i,{by:f}=r;if(!f)return;const c=Nb(f),{source:l,target:u}=s,{center:p}=s.shape.current,g=[],v=[];Me(()=>{for(const w of d.droppables){const{id:$}=w;if(!w.accepts(l)||$===u?.id&&ln(w)||!w.element)continue;let E=w.shape;const D=new $t(w.element,{getBoundingClientRect:O=>Kr(O,void 0,.2)});!D.height||!D.width||(c=="down"&&p.y+Si<D.center.y||c=="up"&&p.y-Si>D.center.y||c=="left"&&p.x-Si>D.center.x||c=="right"&&p.x+Si<D.center.x)&&(g.push(w),w.shape=D,v.push(()=>w.shape=E))}}),r.preventDefault(),a.disable();const y=a.computeCollisions(g,sv);Me(()=>v.forEach(w=>w()));const[k]=y;if(!k)return;const{id:h}=k,{index:b,group:x}=l.sortable;o.setDropTarget(h).then(()=>{const{source:w,target:$,shape:E}=s;if(!w||!ln(w)||!E)return;const{index:D,group:O,target:j}=w.sortable,P=b!==D||x!==O,R=P?j:$?.element;if(!R)return;vu(R);const A=new $t(R);if(!A)return;const L=jt.delta(A,jt.from(E.current.boundingRectangle),w.alignment);o.move({by:L}),P?o.setDropTarget(w.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Nb(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 Lb=Object.defineProperty,Fb=Object.defineProperties,Bb=Object.getOwnPropertyDescriptors,Zl=Object.getOwnPropertySymbols,_b=Object.prototype.hasOwnProperty,Hb=Object.prototype.propertyIsEnumerable,Ql=(e,t,n)=>t in e?Lb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,kn=(e,t)=>{for(var n in t||(t={}))_b.call(t,n)&&Ql(e,n,t[n]);if(Zl)for(var n of Zl(t))Hb.call(t,n)&&Ql(e,n,t[n]);return e},Sn=(e,t)=>Fb(e,Bb(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 $i(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function qs(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function qb(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,b)=>h===b||h!==null&&typeof h=="object"&&"id"in h&&h.id===b;if(Array.isArray(e)){const h=e.findIndex(x=>d(x,s.id)),b=e.findIndex(x=>d(x,o.id));if(h===-1||b===-1){if(qs(s)){const x=s.initialIndex,w=s.index;return x===w||x<0||x>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,x,w)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const x=s.index;if(x!==h)return n(e,h,x)}return n(e,h,b)}const f=Object.entries(e);let c=-1,l,u=-1,p;for(const[h,b]of f)if(c===-1&&(c=b.findIndex(x=>d(x,s.id)),c!==-1&&(l=h)),u===-1&&(u=b.findIndex(x=>d(x,o.id)),u!==-1&&(p=h)),c!==-1&&u!==-1)break;if(c===-1&&qs(s)){const h=s.initialGroup==null?void 0:$i(e,s.initialGroup),b=s.initialIndex,x=s.group==null?void 0:$i(e,s.group),w=s.index;if(h==null||x==null||h===x&&b===w)return"preventDefault"in t&&t.preventDefault(),e;if(h===x)return Sn(kn({},e),{[h]:n(e[h],b,w)});const $=e[h][b];return Sn(kn({},e),{[h]:[...e[h].slice(0,b),...e[h].slice(b+1)],[x]:[...e[x].slice(0,w),$,...e[x].slice(w)]})}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=$i(e,o.id);if(h!=null){const b=o.shape&&v.y>o.shape.center.y?e[h].length:0;p=h,u=b}}if(l==null||p==null||l===p&&c===u){if(l!=null&&l===p&&c===u&&qs(s)){const h=s.group==null?void 0:$i(e,s.group),b=s.group!=null&&h!==l,x=s.index!==c;if(b||x){const w=s.group==null?l:h;if(w!=null){if(l===w)return Sn(kn({},e),{[l]:n(e[l],c,s.index)});const $=e[l][c];return Sn(kn({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[w]:[...e[w].slice(0,s.index),$,...e[w].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===p)return Sn(kn({},e),{[l]:n(e[l],c,u)});const y=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,k=e[l][c];return Sn(kn({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[p]:[...e[p].slice(0,u+y),k,...e[p].slice(u+y)]})}function Kb(e,t){return qb(e,t,Ub)}function ec(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function tc(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 nc="__default__",Gb=class extends qe{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof ul){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(!ln(o)||!ln(a)||o.sortable===a.sortable)return;const d=t(),f=ec(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(tc(f,d,v))return;const y=o.sortable.element,k=a.sortable.element;if(!k||!y||!c&&a.id===o.sortable.group)return;const h=ji(l),b=c?h:ji(u),x=(p=o.sortable.group)!=null?p:nc,w=(g=a.sortable.group)!=null?g:nc,$={[x]:h,[w]:b},E=Kb($,r);if($===E)return;const D=E[w].indexOf(o.sortable),O=E[w].indexOf(a.sortable);i.collisionObserver.disable(),rc(y,D,k,O),Me(()=>{for(const[j,P]of E[x].entries())P.index=j;if(!c)for(const[j,P]of E[w].entries())P.group=a.sortable.group,P.index=j}),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;ln(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),d=ec(a),f=a.get(o.sortable.initialGroup);f&&i.renderer.rendering.then(()=>{const c=t();if(tc(d,a,c))return;const l=ji(f),u=ji(f,Vb),p=o.sortable.element,g=u.indexOf(o.sortable),v=l[g],y=v?.element;!v||!y||!p||(rc(p,v.index,y,o.index),Me(()=>{for(const k of a.values()){const h=Array.from(k).values();for(const b of h)b.index=b.initialIndex,b.group=b.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function rc(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function Yb(e,t){return e.index-t.index}function Vb(e,t){return e.initialIndex-t.initialIndex}function ji(e,t=Yb){return Array.from(e).sort(t)}var ic=[Wb,Gb],kh={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function sc(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 Ci=new _m,Sh,$h,Ut,cl,Ar,Rr,dl,An;$h=[le],Sh=[le];var Cs=class{constructor(e,t){gr(this,cl,ki(Ut,8,this)),ki(Ut,11,this),gr(this,Ar),gr(this,Rr),gr(this,dl,ki(Ut,12,this)),ki(Ut,15,this),gr(this,An),this.register=()=>(Me(()=>{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=()=>{Me(()=>{var g,v;(g=this.manager)==null||g.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Me(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:d,transition:f=kh,plugins:c}=n,l=Rb(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=yt(c,ic),p=sc(i);this.droppable=new ul(Us(Hs({},l),{disabled:p.droppable}),t,this),this.draggable=new jh(Us(Hs({},l),{disabled:p.draggable,plugins:u,effects:()=>[()=>{var g,v,y;const k=(g=this.manager)==null?void 0:g.dragOperation.status;k?.initializing&&this.id===((y=(v=this.manager)==null?void 0:v.dragOperation.source)==null?void 0:y.id)&&Ci.clear(this.manager),k?.dragging&&Ci.set(this.manager,this.id,ae(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:v,manager:y}=this,k=Dr(this,Rr),h=Dr(this,Ar);(g!==k||v!==h)&&(on(this,Rr,g),on(this,Ar,v),this.animate())},()=>{var g,v;const{target:y}=this,{isDragSource:k}=this.draggable;((v=(g=this.draggable.pluginConfig(el))==null?void 0:g.feedback)!=null?v:"default")==="move"&&k&&(this.droppable.disabled=!y)},...r()],type:d,sensors:a}),t,this),on(this,An,l.element),this.manager=t,this.index=o,on(this,Rr,o),this.group=s,on(this,Ar,s),this.type=d,this.transition=f}get initialIndex(){var e,t;return(t=(e=Ci.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Ci.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ae(()=>{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}=Et(i),d=_l(i,a,!1),f=_l(i,a);if(o.x||o.y){const c=Ka(at(i))?Us(Hs({},t),{duration:0}):t;bu({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){Me(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Me(()=>{const t=Dr(this,An),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),on(this,An,e)})}get element(){var e,t;const n=Dr(this,An);if(n)return(t=(e=Eo.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=yt(e,ic)}set disabled(e){const t=sc(e);Me(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Me(()=>{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??xu}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Me(()=>{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)}};Ut=Pb();cl=new WeakMap;Ar=new WeakMap;Rr=new WeakMap;dl=new WeakMap;An=new WeakMap;yh(Ut,4,"index",$h,Cs,cl);yh(Ut,4,"group",Sh,Cs,dl);zb(Ut,Cs);var jh=class extends Ss{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}},ul=class extends $s{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Xb=Object.defineProperty,Jb=Object.defineProperties,Zb=Object.getOwnPropertyDescriptors,oc=Object.getOwnPropertySymbols,Qb=Object.prototype.hasOwnProperty,ex=Object.prototype.propertyIsEnumerable,ac=(e,t,n)=>t in e?Xb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ks=(e,t)=>{for(var n in t||(t={}))Qb.call(t,n)&&ac(e,n,t[n]);if(oc)for(var n of oc(t))ex.call(t,n)&&ac(e,n,t[n]);return e},tx=(e,t)=>Jb(e,Zb(t));function nx(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,y=Ks(Ks({},kh),e.transition),k=th(b=>new Cs(tx(Ks({},e),{transition:y,register:!1,handle:Bn(a),element:Bn(o),target:Bn(p)}),b)),h=Ju(k,rx);return je(i,()=>k.id=i),ar(()=>{Me(()=>{k.group=f,k.index=d})},[k,f,d]),je(g,()=>k.type=g),je(t,()=>k.accept=t,void 0,gt),je(s,()=>s&&(k.data=s)),je(d,()=>{var b;(b=k.manager)!=null&&b.dragOperation.status.idle&&y?.idle&&k.refreshShape()},Qv),Ni(a,b=>k.handle=b),Ni(o,b=>k.element=b),Ni(p,b=>k.target=b),je(c,()=>k.disabled=c??!1,void 0,gt),je(u,()=>k.sensors=u,void 0,gt),je(n,()=>k.collisionDetector=n),je(r,()=>k.collisionPriority=r),je(v,()=>k.plugins=v,void 0,gt),je(y,()=>k.transition=y,void 0,gt),je(l,()=>k.modifiers=l,void 0,gt),je(e.alignment,()=>k.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(b=>{k.handle=b??void 0},[k]),ref:S.useCallback(b=>{var x,w;!b&&(x=k.element)!=null&&x.isConnected&&!((w=k.manager)!=null&&w.dragOperation.status.idle)||(k.element=b??void 0)},[k]),sourceRef:S.useCallback(b=>{var x,w;!b&&(x=k.source)!=null&&x.isConnected&&!((w=k.manager)!=null&&w.dragOperation.status.idle)||(k.source=b??void 0)},[k]),targetRef:S.useCallback(b=>{var x,w;!b&&(x=k.target)!=null&&x.isConnected&&!((w=k.manager)!=null&&w.dragOperation.status.idle)||(k.target=b??void 0)},[k])}}function rx(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Vo="tile",Ch="gap",ix=[_o.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Mh}], ${sx}`)!==null||(_o.defaults.preventActivation?.(e,t)??!1)}),Hu],Mh="data-no-drag",sx=".malloy-render, .malloy-table",ox=e=>[...e,el.configure({feedback:"clone"})];function ax({id:e,index:t,children:n}){const{ref:r,handleRef:i,isDragSource:s}=nx({id:e,index:t,type:Vo,accept:Vo,collisionDetector:Ya,plugins:ox});return m.jsx(m.Fragment,{children:n({ref:r,handleRef:i,isDragSource:s})})}function lx({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=$b({id:e,type:Ch,accept:Vo,collisionDetector:Ya,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:i})})}const Eh=e=>e.ok===!1,Re=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),lr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,we={sourceDefinition:e=>Re(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Re(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Re(e,"VIEW","subQueryDefList"),defDimension:e=>Re(e,"defList","DIMENSION"),exploreProperties:e=>Re(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Re(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Re(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Re(e,"WHERE","filterClauseList"),givenDef:e=>Re(e,"givenNameDef"),givenStatement:e=>Re(e,"GIVEN","givenDefList"),importStatement:e=>Re(e,"IMPORT","importURL"),vArrow:e=>Re(e,"ARROW","vExpr","segExpr"),segRefine:e=>Re(e,"PLUS","segExpr"),segOps:e=>Re(e,"queryProperties"),segField:e=>Re(e,"fieldPath")&&!Re(e,"segExpr"),segParen:e=>Re(e,"OPAREN","CPAREN","vExpr"),compare:e=>Re(e,"fieldExpr","compareOp"),givenRef:e=>Re(e,"GIVEN_REF")};function cx(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 dx(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
+
`&&t.push(n+1);return t}function Oh(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const i=t.getChild(r);if(!lr(i))continue;const s=Te(i,"docAnnotations");if(s)for(const o of Yt(s,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class Th{constructor(t){this.text=t,this.map=cx(t),this.lineStarts=dx(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!lr(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 ui(e,t,n=[]){lr(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)ui(e.getChild(r),t,n);return n}const ux=e=>Re(e,"OCURLY","CCURLY");function Qr(e,t){const n=[],r=i=>{if(lr(i)){if(t(i)){n.push(i);return}if(!ux(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 Te=(e,t)=>e[t]?.call(e),Yt=(e,t)=>e[t]?.call(e)??[];function hx(e,t){if(!we.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!we.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 Dh(e,t){const n=e.positioned(t);if(!n)return;const r=Te(t,"filterClauseList"),i=[];for(const s of r?Yt(r,"fieldExpr"):[]){const o=e.positioned(s);if(!o)continue;const a=ui(s,we.givenRef).map(d=>e.text_(d)).filter(d=>d!==void 0).map(d=>d.replace(/^\$/,""));i.push({...o,givens:a,binding:hx(e,s)})}return{...n,clauses:i}}function Xo(e,t){const n=e.span(t);if(!n)return;const r=[],i=[];for(const f of Qr(t,we.queryStatement)){const c=e.positioned(f);c&&r.push(c);const l=Te(f,"whereStatement");if(l&&we.whereStatement(l)){const u=Dh(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 hl(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 fx(e,t){const n=Te(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=we.vArrow(t);if(we.segOps(n)){const i=Te(n,"queryProperties"),s=i&&Xo(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(we.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(we.segRefine(n)){const i=Yt(n,"segExpr"),s=i[0],o=i[i.length-1];let a=s;for(;we.segRefine(a);){const u=Yt(a,"segExpr");if(u.some(p=>we.segOps(p)||we.segParen(p)))return{kind:"unsupported",why:"a chained refinement"};a=u[0]}if(a&&we.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!we.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(!we.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=Te(o,"queryProperties"),l=c&&Xo(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 px(e,t){const n=[];for(const r of Qr(t,we.defExploreQuery)){const i=e.span(r),s=Te(r,"subQueryDefList");if(!i||!s)continue;const o=Yt(s,"exploreQueryDef").filter(we.exploreQueryDef),a=e.terminal(Te(r,"VIEW"));for(const d of o){const f=e.span(d),c=Te(d,"exploreQueryNameDef"),l=e.text_(c),u=Te(d,"vExpr");!f||!l||!u||n.push({name:l,span:f,line:e.line(f.start),statement:i,tags:hl(e,i,a?.start??f.start),siblings:o.length,body:fx(e,u)})}}return n}function mx(e,t){const n=[];for(const r of Qr(t,we.defDimension)){const i=e.span(r),s=Te(r,"defList");if(!i||!s)continue;const o=e.terminal(Te(r,"DIMENSION"));for(const a of Yt(s,"fieldDef")){const d=e.span(a),f=e.text_(Te(a,"fieldNameDef"))?.trim(),c=e.text_(Te(a,"fieldExpr"))?.trim();!d||!f||c===void 0||n.push({name:f,expression:c,span:d,line:e.line(d.start),statement:i,tags:hl(e,i,o?.start??d.start)})}}return n}function gx(e,t){const n=[];for(const r of ui(t,we.sourceDefinition)){const i=e.span(r),s=e.text_(Te(r,"sourceNameDef")),o=Te(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=Qr(o,we.exploreProperties)[0],l=c&&Xo(e,c),u={start:e.lineStarts[e.line(i.start)],end:i.end},p=[];if(c)for(const g of Qr(c,we.whereStatement)){const v=Dh(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?px(e,c):[],dimensions:c?mx(e,c):[],wheres:p})}return n}function vx(e,t){const n=[];for(const r of ui(t,we.givenStatement)){const i=e.terminal(Te(r,"GIVEN")),s=Te(r,"givenDefList"),o=i?e.line(i.start):void 0;for(const a of s?Yt(s,"givenDef"):[]){const d=e.span(a),f=e.span(Te(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:hl(e,d,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function bx(e,t){const n=[];for(const r of ui(t,we.importStatement)){const i=e.span(r),s=e.text_(Te(r,"importURL"));if(!i||s===void 0)continue;const o=Te(r,"importSelect"),a=o?Yt(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 Ah(e){let t;try{t=await fl(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||!lr(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 Th(e),d=xx(a,s);a.commentLines=d.lines;const f=e.split(`
|
|
70
|
+
`),c=u=>d.lines.has(u);a.proseLines=Ep(f,c),a.blocks=Op(f,c).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=gx(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:bx(a,i),sources:l,givens:vx(a,i),textBlocks:wx(a,s),modelNotes:Oh(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=>yx(a,d.lines,u)}}}async function fl(e,t){const{MalloyTranslator:n}=await ap(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function xx(e,t){const n=new Map,r=new Set,i=[],s=t.tokenSource?.vocabulary;for(const c of t.getTokens?.()??[]){const l=s?.getSymbolicName(c.type);if(l!=="COMMENT_TO_EOL"&&l!=="BLOCK_COMMENT")continue;const u=e.utf16(c.startIndex);let p=e.utf16(c.stopIndex+1);if(!(u===void 0||p===void 0||p<u)){for(;p>u&&(e.text[p-1]===`
|
|
71
|
+
`||e.text[p-1]==="\r");)p--;i.push({start:u,end:p})}}const o=[...i].sort((c,l)=>c.start-l.start);let a="",d=0;for(const c of o)a+=e.text.slice(d,Math.max(d,c.start)),a+=e.text.slice(Math.max(d,c.start),Math.max(d,c.end)).replace(/[^\n\r]/g," "),d=Math.max(d,c.end);a+=e.text.slice(d);const f=c=>a.slice(e.lineStarts[c],e.lineStarts[c+1]??a.length);for(const c of i){const l=e.line(c.start),u=e.line(c.end-1);for(let v=l;v<=u;v++)f(v).trim()===""&&r.add(v);const p=a.slice(e.lineStarts[l],c.start).trim(),g=a.slice(c.end,e.lineStarts[u+1]??a.length).trim();p!==""&&g===""&&n.set(u,c)}return{trailing:n,lines:r,all:i}}function yx(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 wx(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=Wp(s(n[a]).replace(/\r?\n$/,""));if(!d)continue;const f=[];let c=a+1;for(;i(n[c]??n[a])==="BLOCK_ANNOTATION_TEXT";c++)f.push(s(n[c]));const l=n[c];if(!l||i(l)!=="BLOCK_ANNOTATION_END")continue;const u=e.line(e.utf16(n[a].startIndex)??0),p=e.utf16(l.stopIndex+1)??e.text.length,g=d.name===void 0&&d.rest?[`${d.rest}
|
|
72
|
+
`]:[];o.push({...d.name===void 0?{}:{name:d.name},route:d.route,body:[...g,...f].join("").replace(/\r\n?/g,`
|
|
73
|
+
`).replace(/\n$/,""),span:{start:e.lineStarts[u],end:p},line:u}),a=c}return o}function Rh(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 Ph(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')r=Rh(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 kx(e,r+s[0].length-1)}}}function kx(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=Rh(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 Sx(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
|
|
74
|
+
`)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const i=e.indexOf(`
|
|
75
|
+
`,r),s=i===-1?e.length:i;if(e.slice(r,s).trim()===">>>")return s;if(i===-1)return e.length;r=i+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let i=t+3;i<e.length;i++)if(e[i]==="\\")i++;else if(e.startsWith(r,i))return i+3;return e.length}for(let i=t+1;i<e.length;i++)if(e[i]==="\\")i++;else{if(e[i]===n)return i+1;if(e[i]===`
|
|
76
|
+
`)return i}return e.length}return t}function $x(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=Sx(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 Ih(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=$x(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const lc=(e,t)=>{try{return e.text(t)}catch{return}},jx=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Cx=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\`.`,Mx=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=[…]\`.`,Ex="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 zh(e,t){const n=e.filter(jx).filter(c=>!c.includes("@env.")).map(Wc),{tag:r,errors:i}=n.length>0?Ih(t,n):{tag:void 0,errors:[]},s=r?.tag("artifact");if(!s)return e.some(lp)?{status:"unparsed",errors:i}:{status:"none"};const o=lc(s,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=lc(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 S0(e){const{parseAnnotation:t}=await Tc();let n=[];try{const r=(await fl(e,"file://report.malloy")).parse?.root;r&&lr(r)&&typeof r.getChild=="function"&&(n=Oh(new Th(e),r))}catch{n=[]}return zh(n,t)}const Jo=e=>e.ok===!1;function hi(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 ds=e=>e.map(t=>t.text);function cc(e){const t=ds(e),n=Tp(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:Dp(t)}:{chart:n}}function Ox(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:Ap(i),given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function Tx(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(),...Dx(n(ds(hi(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function Dx(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 Gs(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 Ax=/^"((?:[^"\\]|\\.)+)"$/,Rx=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Zo(e,t,n=!1){try{return await Px(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 Px(e){const{parseAnnotation:t}=await Tc(),n=rp(e),r=await Ah(e);if(Eh(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,s=zc(n).text,o=zh(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:Cx(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?Mx(o.unknownLayout):Ex};const a=o.layout,d=la(n);if(d===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!ip(d.text))return{ok:!1,reason:sp,line:d.from+1};const{tag:f,errors:c}=Ih(t,[Wc(d.text)]),l=f?.tag("artifact"),u=Ph(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=[],y=new Map;for(const $ of i.sources){const E={name:$.name,base:$.base};$.dimensions.length>0&&(E.dimensions=$.dimensions.map(O=>({name:O.name,expression:O.expression})));const D=new Set($.wheres.flatMap(O=>O.clauses.flatMap(j=>j.givens)));D.size>0&&(E.scopedBy=Array.from(D)),g.push(E);for(const O of $.dimensions){const j=t(ds(hi(i,n,O.line).tags)).tag?.tag("drill");if(!j)continue;const P=j.textArray("to")??[j.text("to")??""];v.push({source:$.name,name:O.name,expression:O.expression,to:P.filter(Boolean),...j.text("given")?{given:j.text("given")}:{}})}y.set($.name,new Map($.views.map(O=>[O.name,O])))}const k=[];for(const{text:$}of u.entries){const E=Ax.exec($),D=E?void 0:Rx.exec($)?.[1];if(D!==void 0){const T=t([`# ${$}`]).tag?.tag(D);if(T?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${$}\` is neither a quoted \`source -> view\` expression nor a \`${D} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(k.some(F=>De(F)&&F.name===D))return{ok:!1,reason:`Two text tiles are named \`${D}\`, so the builder cannot tell them apart.`};const z=Gs(T,"colspan");k.push({kind:"text",name:D,markdown:i.textBlocks.find(F=>F.name===D)?.body??"",...z===void 0?{}:{colspan:z},...T.has("break")?{break:!0}:{}});continue}const O=E?.[1]??$,j=E?op(O):void 0;if(!j)return{ok:!1,reason:`The tile \`${O}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:P,view:R}=j,A=y.get(P)?.get(R);if(A===void 0){k.push({name:R,source:P,declaration:{kind:"inherited"}});continue}const L=t(ds(A.tags)).tag,U=A.body.kind==="reference"?{kind:"reference",from:A.body.from}:A.body.kind==="inline"?{kind:"inline"}:void 0;if(U===void 0){k.push({name:R,source:P,declaration:{kind:"opaque",why:A.body.kind==="unsupported"?A.body.why:"unreadable"},...L?.text("label")?{label:L.text("label")}:{},...L?.text("subtitle")?{subtitle:L.text("subtitle")}:{},...L?.numeric("colspan")!==void 0?{colspan:L.numeric("colspan")}:{},...cc(A.tags),...L?.has("break")?{break:!0}:{},...L?.has("borderless")?{borderless:!0}:{}});continue}const _=Ox(A.body.kind==="reference"?A.body.refinement:A.body.kind==="inline"?A.body.stage:void 0);k.push({name:R,source:P,declaration:U,..._?{filters:_}:{},...L?.text("label")?{label:L.text("label")}:{},...L?.text("subtitle")?{subtitle:L.text("subtitle")}:{},...L?.numeric("colspan")!==void 0?{colspan:L.numeric("colspan")}:{},...cc(A.tags),...L?.has("break")?{break:!0}:{},...L?.has("borderless")?{borderless:!0}:{}})}const h=Tx(i,n,t),b={},x=l?.tag("givens");for(const $ of Object.keys(x?.dict??{})){const E=x?.text($);E!==void 0&&(b[$]=E)}const w=f?.tag("dashboard")?.has("columns")?Gs(f.tag("dashboard"),"columns"):l?.array("tiles")?Gs(l,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:l?.text("title")??"",...s?{description:s}:{},...w===void 0?{}:{columns:w},...l?.has("autorun")?{autorun:l.isTrue("autorun")}:{},imports:p,sources:g,...h?{localGivens:h}:{},...Object.keys(b).length>0?{startingGivens:b}:{},...v.length>0?{drills:v}:{},tiles:k}}}const Qo=e=>e.ok===!1;async function dc(e){const{problems:t}=await fl(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function ye(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 Wh(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Ix(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
+
`&&t.push(n+1);return t}function zx(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 Nh=e=>e==="none"||ua(e)?e:void 0;function Lh(e,t=!0){const n=[];e.colspan!==void 0&&n.push(`# colspan=${e.colspan}`),e.break&&n.push("# break"),e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${xt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${xt(e.subtitle)}`);const r=t?Nh(e.chart):void 0;return r!==void 0&&n.push(cn(r,e.chartCarried)),n}function Fi(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Wx=new Set(["colspan","break","borderless","label","subtitle"]),Nx=new Set(["label","description","control","suggest","range_min","range_max"]);function uc(e){const t=[];if(e.label!==void 0&&t.push(`label=${xt(e.label)}`),e.description!==void 0&&t.push(`description=${xt(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=${xt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${xt(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 hc=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Lx(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:xt(n);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(xt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const us=e=>`${e.source}.${e.name}`,xt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,ea=e=>De(e)?ye(["text",e.name]):ye([e.name,e.source,e.declaration]),ht=ea,pc=e=>ye(e.tiles.map(ht));function Fx(e,t,n){const r=new Set(e.tiles.map(ht)),i=new Set(t.tiles.map(ht)),s=e.tiles.filter(u=>!i.has(ht(u))),o=t.tiles.filter(u=>!r.has(ht(u))),a=s.length>0||o.length>0||pc(e)!==pc(t);for(const u of o)if(de(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=>de(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 mc=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function Bx(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=ei(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function gc(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=Bx(t),r=n.indexOf("{"),i=n.lastIndexOf("}");let s=t.slice(r+1,i),o=n.slice(r+1,i);const a=f=>{const c=f.exec(o);c&&(s=s.slice(0,c.index)+s.slice(c.index+c[0].length),o=o.slice(0,c.index)+o.slice(c.index+c[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const d=[s.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${d.join(" ")} }${t.slice(i+1)}`}function _x(e){const{lines:t,wholeLine:n,current:r,next:i,reordered:s,currentKeys:o,nextKeys:a,edits:d}=e,f=new Map(r.tiles.filter(De).map(h=>[h.name,h])),c=i.tiles.filter(De).some(h=>{const b=f.get(h.name);return b!==void 0&&mc(b,h)});if(!s&&!c)return;const l=la(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,p=Ph(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 b=/^"((?:[^"\\]|\\.)+)"$/.exec(h);if(b){const w=b[1].split("->").map($=>$.trim());w.length===2&&g.set(`${w[0]}->${w[1]}`,h);continue}const x=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(h)?.[1];x!==void 0&&g.set(`text.${x}`,h)}const v=i.tiles.map(h=>{const b=!o.has(ht(h));if(De(h)){const x=g.get(`text.${h.name}`);return x!==void 0?f.has(h.name)&&!mc(f.get(h.name),h)?x:gc(h,x):b?gc(h):void 0}return g.get(`${h.source}->${h.name}`)??(b?`"${h.source} -> ${h.name}"`:void 0)});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 y=u.slice(0,p.open).search(/tiles\s*=\s*$/),k=`${u.slice(0,y)}tiles=[${Hx(u,p,v)}]${u.slice(p.close+1)}`;k!==u&&d.push({...Fh(n,l),text:`${k}
|
|
78
|
+
`})}function Fh(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Hx(e,t,n){const r=t.entries[0],i=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const s=e.slice(t.open+1,r.span.start),o=e.slice(i.span.end,t.close),a=s.slice(s.lastIndexOf(`
|
|
79
|
+
`)),d=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
|
|
80
|
+
`)?a:" "}`;return`${s}${n.join(d)}${o}`}function Ux(e,t){let n=0,r=0;for(let i=0;i<e.length;i++){const s=e[i];if(s==='"')i=ei(e,i);else if(s==="{"||s==="[")n++===0&&r++;else if(s==="}"||s==="]")n--;else if(r===1&&n===1&&e.startsWith(t,i)&&!/[A-Za-z0-9_]/.test(e[i-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(i+t.length));if(!o)continue;const a=i+t.length+o[0].length,d=e[a]==='"'?ei(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),f=i-(/\s*$/.exec(e.slice(0,i))?.[0].length??0);return e.slice(0,f)+e.slice(d)}}return e}function qx(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=ei(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=ei(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 ei(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 Kx(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||ye(r.startingGivens)!==ye(i.startingGivens)){const o=la(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=Fh(n,o),d=s.find(b=>b.start===a.start&&b.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 b=u;b<f.length;b++)if(f[b]==="{")p++;else if(f[b]==="}"&&--p===0){g=b;break}if(u<0||g<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let v=f.slice(u+1,g);const y=o.block?`
|
|
81
|
+
${/\n([ \t]+)\S/.exec(v)?.[1]??" "}`:" ",k=b=>o.block?`${v.trimEnd()}${y}${b}
|
|
82
|
+
`:`${v.trimEnd()} ${b} `,h=(b,x)=>{const w=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${b}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(x===void 0){const $=new RegExp(`
|
|
83
|
+
${w.source}[ \\t]*(?=
|
|
84
|
+
)`);v=v.replace(o.block&&$.test(v)?$:w,"")}else w.test(v)?v=v.replace(w,$=>`${o.block?$.slice(0,$.length-$.trimStart().length):" "}${b}=${x}`):v=k(`${b}=${x}`)};if(c&&h("layout",i.layout),r.title!==i.title&&h("title",i.title?xt(i.title):void 0),r.autorun!==i.autorun&&h("autorun",i.autorun===void 0?void 0:String(i.autorun)),ye(r.startingGivens)!==ye(i.startingGivens)){v=v.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const b=Object.entries(i.startingGivens??{});b.length>0&&(v=k(`givens { ${b.map(([x,w])=>`${x}=${xt(w)}`).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=Ux(f,"dashboard_columns"),f=qx(f),i.columns!==void 0&&(f=`${f.trimEnd()} dashboard { columns=${i.columns} }`)),d?d.text=`${f}
|
|
85
|
+
`:s.push({...a,text:`${f}
|
|
86
|
+
`})}if(r.description!==i.description){const{read:o,blankAbove:a,below:d,belowBlock:f,inBlock:c}=zc(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=Wh(i.description??"").split(`
|
|
87
|
+
`).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
|
|
88
|
+
`),u=o.length>0&&o[0]<yl(t),p=i.description===void 0,g=u?[...o.slice(1),...p?d:[]]:[...o,...a];for(const v of g)s.push({...n(v),text:""});if(u)s.push({...n(o[0]),text:i.description===void 0?"":`${l}
|
|
89
|
+
`});else if(i.description!==void 0){const v=n(yl(t)).start;s.push({start:v,end:v,text:`${l}
|
|
90
|
+
`})}}}function Gx(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&&ye(v)===ye(g))continue;const y=c.get(p);if(y===void 0)return{ok:!1,reason:`Could not find where the given \`${p}\` is declared.`};const{tags:k,prose:h}=hi(a,t,y.line),b=[...(v===void 0?k:k.filter(D=>{const O=Fi(D.text);return O!==void 0&&Nx.has(O)})).map(D=>D.line),...v===void 0?h:[]];for(const D of b)o.push({...n(D),text:""}),l.add(D);const x=Rt(a,y.span.end-1);if(v===void 0){o.push({start:n(y.line).start,end:n(x).end,text:""});for(let A=y.line;A<=x;A++)l.add(A);const D=Math.min(y.line,...b),O=y.blockHeader??D,j=(t[x+1]??"x").trim()==="",P=O===0||t[O-1].trim()==="",R=y.blockHeader===void 0||![...c.values()].some(A=>A.blockHeader===y.blockHeader&&A.line>y.line&&f.has([...c.entries()].find(([,L])=>L===A)?.[0]??""));j&&P&&R&&!l.has(x+1)&&(o.push({...n(x+1),text:""}),l.add(x+1));continue}const w=r(y.line),$=uc(v),E=v.type!==g.type||v.default!==g.default?y.blockHeader===void 0?hc(v):`${v.name} :: ${v.type} is ${v.default}`:t.slice(y.line,x+1).join(`
|
|
91
|
+
`).trim();o.push({start:n(y.line).start,end:n(x).end,text:($?`${w}${$}
|
|
92
|
+
`:"")+`${w}${E}
|
|
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 b=0;b<t.length;b++){const x=t[b].trim();(x.startsWith("import ")||h>=0&&/^}\s*from\s/.test(x))&&(h=b)}return h})(),v=p>=0?p:g,y=u.map(h=>{const b=uc(h);return(b?`${b}
|
|
94
|
+
`:"")+`${hc(h)}
|
|
95
|
+
`}).join(`
|
|
96
|
+
`),k=v>=0?n(v).end:n(0).end;o.push({start:k,end:k,text:`
|
|
97
|
+
${y}`}),t.some(h=>h.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
|
|
98
|
+
`})}}const vc=(e,t)=>`import { ${e.join(", ")} } from ${xt(t)}`;function Yx(e){const{parsed:t,current:n,next:r,edits:i,wholeLine:s}=e,o=l=>ye(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(ye(n.imports)===ye(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(de).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(ye(g)===ye(u.names))continue;const y=g.length===0?pl(t,l.statement):l.statement,k=t.commentIn(y);if(k)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(k.start,k.end).trim()}\`), so nothing was written. Delete it in the file first.`};i.push({...y,text:g.length===0?"":vc(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(Rt(t,l.statement.end-1)).end;i.push({start:u,end:u,text:c.map(p=>`${vc(p.names,p.from)}
|
|
99
|
+
`).join("")})}}function Vx(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,d=new Map((i.drills??[]).map(c=>[us(c),c])),f=new Map((s.drills??[]).map(c=>[us(c),c]));for(const c of new Set([...d.keys(),...f.keys()])){const l=d.get(c),u=f.get(c);if(l&&u&&ye(l)===ye(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}=hi(a,t,g.line),y=v.find(h=>/^#\s*drill\b/.test(h.text)),k=r(g.line);if(u===void 0)y&&o.push({...n(y.line),text:""});else if(y)o.push({...n(y.line),text:`${k}${fc(u)}
|
|
100
|
+
`});else{const h=n(g.line).start;o.push({start:h,end:h,text:`${k}${fc(u)}
|
|
101
|
+
`})}}}function Xx(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if(De(o)||o.declaration.kind==="inherited")continue;const a=Bh(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=Rt(s,a.statement.start),f=Rt(s,a.statement.end-1),c=s.trailingComment(f),l=c&&c.start>=a.statement.end?c.end:a.statement.end;if(s.text.slice(s.lineStarts[d],a.statement.start).trim()!==""||s.text.slice(l,n(f).end).trim()!==""){i.push({...pl(s,a.statement),text:""});continue}i.push({start:s.lineStarts[d],end:n(f).end,text:""});const u=d===0?"":t[d-1].trim();(t[f+1]??"x").trim()===""&&(d===0||u===""||u.endsWith("{"))&&i.push({...n(f+1),text:""})}}function Jx(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(De(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(y=>`where: ${da(y.field)} ${y.op??"~"} $${y.given}`).join(", ");return[...Lh(u).map(y=>`${p}${y}`),`${p}view: ${u.name} is ${g}${v?` + { ${v} }`:""}`].join(`
|
|
102
|
+
`)};let l=-1;for(const u of d.sources)l=Math.max(l,Rt(d,u.span.end-1));for(const[u,p]of f)if(o.has(u)){const g=d.sources.find(x=>x.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,y=Rt(d,g.properties.closeStart);let k=" ";for(let x=v+1;x<y;x++){const w=/^(\s+)view:/.exec(n[x]);if(w){k=w[1];break}}const h=r(y).start,b=(n[y-1]??"").trim()==="";a.push({start:h,end:h,text:(b?"":`
|
|
103
|
+
`)+p.map(x=>c(x,k)).join(`
|
|
104
|
+
|
|
105
|
+
`)+`
|
|
106
|
+
`})}else{const g=s.find(b=>b.name===u);if(!g)return{ok:!1,reason:`The tile's source \`${u}\` is not declared.`};const v=`
|
|
107
|
+
source: ${g.name} is ${g.base} extend {
|
|
108
|
+
`+p.map(b=>c(b," ")).join(`
|
|
109
|
+
|
|
110
|
+
`)+`
|
|
111
|
+
}
|
|
112
|
+
`;let y=l;if(y<0)for(let b=0;b<n.length;b++){const x=n[b].trim();(/^(import\s|given:|}\s*from\s)/.test(x)||/^[A-Z_]+\s*::/.test(x))&&(y=b)}const k=y>=0?r(y).end:t.length,h=k===t.length&&!t.endsWith(`
|
|
113
|
+
`)?`
|
|
114
|
+
`:"";a.push({start:k,end:k,text:h+v}),l=y}}function Zx(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=>[ht(c),c]));for(const c of o.tiles){const l=f.get(ht(c));if(l===void 0||De(c)||De(l)||ye(hs(l))===ye(hs(c)))continue;if(c.declaration.kind==="inherited")return{ok:!1,reason:`\`${c.source} -> ${c.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const u=Lx(d,c.source,c.name);if(u<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:p}=hi(d,t,u),g=i(u),v=Lh(c,!1),y=new Map(v.map(O=>[Fi(O)??O,O])),k=new Set,h=Nh(c.chart),b=bc(l)!==bc(c);if(b){const O=p.filter(R=>wl(R.text)),j=p.filter(R=>Ds(R.text)),P=l.chart==="custom"?p.filter(R=>Ds(R.text)||wl(R.text)):O.length>0?O:j.length>1?j:[];if(P.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${P.map(R=>R.text).join(" and ")}), so its chart cannot be changed here.`}}let x=!1;for(const O of p){if(b&&Ds(O.text)){h===void 0?a.push({...r(O.line),text:""}):O.text!==cn(h,c.chartCarried)&&a.push({...r(O.line),text:`${g}${cn(h,c.chartCarried)}
|
|
115
|
+
`}),x=!0;continue}const j=Fi(O.text);if(j===void 0||!Wx.has(j))continue;const P=y.get(j);if(P===void 0){a.push({...r(O.line),text:""});continue}k.add(j),P!==O.text&&a.push({...r(O.line),text:`${g}${P}
|
|
116
|
+
`})}const w=v.filter(O=>!k.has(Fi(O)??O));if(b&&h!==void 0&&!x&&w.push(cn(h,c.chartCarried)),w.length>0){const O=n[u];a.push({start:O,end:O,text:w.map(j=>`${g}${j}
|
|
117
|
+
`).join("")})}if(ye(l.filters)===ye(c.filters))continue;const $=Bh(e,c);if(!$)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if($.body.kind==="reference"){const O=sy(e,c,$);if(O)return O;continue}if($.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${$.body.why}, so there is no single first stage to write its filter into.`};const E=_h(c.filters,$.body.stage);if(E)return Hh(c.name,E.given);const D=Uh(e,c,$.body.stage);if(D)return D}}const bc=e=>e.chart==="default"?void 0:e.chart,hs=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:i,...s}=r;return s};function Qx(e,t){const n=new Map(e.tiles.map(r=>[ht(r),r]));return{...t,tiles:t.tiles.map(r=>{const i=n.get(ht(r));return de(r)&&r.chart===void 0&&i&&de(i)&&i.chart!==void 0?{...r,chart:i.chart}:r})}}function Bi(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 ey(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&&!Np(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=Bi(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 Ys=e=>`##|(markdown) ${e.name}
|
|
118
|
+
${e.markdown===""?"":`${e.markdown}
|
|
119
|
+
`}|##
|
|
120
|
+
`;function ty(e){const{sourceText:t,lines:n,wholeLine:r,current:i,next:s,parsed:o,edits:a}=e,d=new Map(i.tiles.filter(De).map(p=>[p.name,p])),f=s.tiles.filter(De),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=Rt(o,g.span.end-1);a.push({...g.span,text:""});const y=r(v+1),k=g.line===0||n[g.line-1].trim()==="";y.end>y.start&&n[v+1].trim()===""&&k?a.push({...y,text:""}):g.line>0&&k&&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(Ys(p))}else g.markdown!==p.markdown&&(v?a.push({...v.span,text:Ys(p)}):u.push(Ys(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,b=t.slice(h);a.push({start:h,end:h,text:`
|
|
121
|
+
${u.join(`
|
|
122
|
+
`)}${b===""||b.startsWith(`
|
|
123
|
+
`)?"":`
|
|
124
|
+
`}`});return}if(v){const h=e.starts[o.blockStart(v.line)],b=h===0||t.slice(0,h).endsWith(`
|
|
125
|
+
|
|
126
|
+
`);a.push({start:h,end:h,text:`${b?"":`
|
|
127
|
+
`}${u.join(`
|
|
128
|
+
`)}
|
|
129
|
+
`});return}const y=t.length,k=t===""||t.endsWith(`
|
|
130
|
+
|
|
131
|
+
`)?"":t.endsWith(`
|
|
132
|
+
`)?`
|
|
133
|
+
`:`
|
|
134
|
+
|
|
135
|
+
`;a.push({start:y,end:y,text:k+u.join(`
|
|
136
|
+
`)})}}const Mi=(e,t=ro)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function ny(e,t){const n=new Map(e.tiles.map(o=>[ht(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(ht(o));if(De(o)){const l=ey(o,a&&De(a)?a:void 0,r);if(l)return l;continue}const d=a&&de(a)?a:void 0;if(a&&!d)continue;const f=o.chart;if(f!==void 0&&f!=="default"&&f!=="none"&&!ua(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=Mi(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=xn(`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=Mi(a);if(d)return d}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=xn("description line",o);if(a)return a}if(t.title!==e.title){const o=xn("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=Mi(o.name,Fc);if(f)return f}const d=o.suggest?.source;if(d!==void 0&&d!==a?.suggest?.source){const f=Mi(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=xn(`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=xn(`given ${f}`,c);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const d=xn(`starting value for ${o}`,a);if(d)return d}}const Rt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Bh(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function _h(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 Hh(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 _i=e=>`where: ${da(e.field)} ${e.op??"~"} $${e.given}`;function xc(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 ry(e,t,n){const r=e.commentIn(n);if(r)return r;const i=e.trailingComment(Rt(e,t.end-1));return i&&i.start>=t.end&&e.text.slice(t.end,i.start).trim()===""?i:void 0}function iy(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function pl(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),i=e.text.indexOf(`
|
|
137
|
+
`,t.end),s=e.text.slice(t.end,i<0?void 0:i);if(r.trim()===""&&s.trim()==="")return{start:n,end:i<0?e.text.length:i+1};if(r.trim()===""){const a=/^\s*/.exec(s)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function Uh(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,y)=>({clause:v,index:y})).filter(({clause:v})=>v.binding!==void 0);if(p.length===0)continue;const g=p.filter(({clause:v})=>s.has(v.binding.given));for(const{clause:v}of p)o.add(v.binding.given);if(g.length===0&&p.length===u.clauses.length){const v=pl(r,u.span),y=ry(r,u.span,v);if(y)return xc(t.name,r,y);i.push({...v,text:""});continue}g.length>0&&(a=u.span);for(let v=p.length-1;v>=0;v--){const{clause:y,index:k}=p[v],h=s.get(y.binding.given);if(!h){const x=iy(u.clauses,k),w=r.commentIn(x);if(w)return xc(t.name,r,w);i.push({...x,text:""});continue}const b=_i(h).replace(/^where:\s*/,"");b!==r.text.slice(y.span.start,y.span.end)&&i.push({...y.span,text:b})}}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(Rt(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(_i).join(", ")}`:d.map(u=>`
|
|
138
|
+
${n.indent}${_i(u)}`).join("");i.push({start:f,end:f,text:l})}function sy(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:s}=n.body,o=_h(t.filters,s);if(o)return Hh(t.name,o.given);const a=t.filters??[];if(!s){if(a.length===0)return;const c=` + { ${a.map(_i).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 Uh(e,t,s)}async function oy(e,t,n={}){if(!(e.includes(`\r
|
|
139
|
+
`)&&!/(?<!\r)\n/.test(e)))return yc(e,t,n);const r=await yc(e.replace(/\r\n/g,`
|
|
140
|
+
`),t,n);return Qo(r)?r:{...r,source:r.source.replace(/\n/g,`\r
|
|
141
|
+
`)}}async function yc(e,t,n){const r=await Zo(e);if(Jo(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const i=r.document,s=Qx(i,t),o=Fx(i,s,n.visibleSources);if("reason"in o)return o;const a=ny(i,s);if(a)return{ok:!1,reason:a};const d=await Ah(e);if(Eh(d))return{ok:!1,reason:`Cannot edit a file that will not open: ${d.reason}`};const f=e.split(`
|
|
142
|
+
`),c=Ix(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[_x,Kx,Yx,Gx,Vx,Xx,Jx,Zx,ty]){const b=h(g);if(b)return b}const v=h=>{const{drills:b,localGivens:x,description:w,...$}=h,E=h.tiles.map(D=>{if(De(D))return D;if(D.filters?.length)return hs(D);const{filters:O,...j}=D;return hs(j)});return{...$,...w===void 0?{}:{description:Wh(w)},tiles:E,...b?.length?{drills:[...b].sort((D,O)=>us(D).localeCompare(us(O)))}:{},...x?.length?{localGivens:x}:{}}};if(p.length===0)return ye(v(i))!==ye(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 y=zx(e,p);if((await dc(e)).length===0){const h=await dc(y);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 k=await Zo(y);return Jo(k)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${k.reason}`}:ye(v(k.document))!==ye(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:y}}function qh({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}=qc(f,a,x=>n(x.text),()=>d(!1)),g=a&&c!==void 0&&c.text!==e,v=c!==void 0&&c.text!==e?Bi(c.text):void 0;fh(g,()=>v!==void 0?!1:(u(),!0));const y=S.useRef(!1);S.useEffect(()=>{a||(y.current=!1)},[a]);const k=S.useCallback(x=>{!x||y.current||(y.current=!0,x.setSelectionRange(x.value.length,x.value.length))},[]);if(!a||c===void 0){const x=e.trim()?Bi(e):void 0;return m.jsxs(H,{role:"button",tabIndex:0,onClick:w=>{w.target.closest("a")?w.preventDefault():d(!0)},onKeyDown:w=>{w.target===w.currentTarget&&(w.key!=="Enter"&&w.key!==" "||(w.preventDefault(),d(!0)))},sx:[{minHeight:24},uh(i,"prose")],children:[e.trim()?m.jsx(yp,{variant:r,children:e}):m.jsx(fe,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),x&&m.jsx(fe,{variant:"caption",color:"error",role:"alert",children:x})]})}const h=c.text!==e?Bi(c.text):void 0,b=()=>{h===void 0&&u()};return m.jsxs(H,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx(Lc,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:c.text,placeholder:t,error:h!==void 0,inputRef:k,inputProps:{"aria-label":"Markdown","aria-describedby":o,...h!==void 0?{"aria-invalid":!0}:{}},onChange:x=>l(w=>{w.text=x.target.value}),onKeyDown:x=>{x.key==="Escape"?(x.preventDefault(),p(),d(!1)):x.key==="Enter"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),b())},onBlur:()=>u(),sx:{p:0,...s.type.prose,color:"inherit",maxWidth:wp,"& textarea":{p:0}}}),h!==void 0&&m.jsx(fe,{variant:"caption",color:"error",role:"alert",children:h}),m.jsxs(fe,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",dn,"↩ done · Esc cancels"]})]})}const ay="Write markdown: # heading, **bold**, - list";function ly({tile:e,onChange:t}){return m.jsx(Ac,{sx:{overflow:"visible"},children:m.jsx(qh,{markdown:e.markdown,placeholder:ay,onCommit:t})})}const cy={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Kh=(e,t)=>t===0?e:Kh(t,e%t);function dy(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Kh(e,t),i=cy[`${e/r}/${t/r}`];return i?`${n} · ${i}`:n}function uy({tile:e,index:t,selected:n,flash:r=!1,menuOpen:i,bare:s=!1,onInsertAfter:o,onSelect:a,onOpenMenu:d,onRemove:f,removeBlocked:c,resizing:l=!1,width:u,onResizeStart:p,onResizeMove:g,onResizeEnd:v,children:y}){const{theme:k}=_e(),h=k.ui;return m.jsx(ax,{id:Ie(e),index:t,children:({ref:b,handleRef:x})=>m.jsxs(H,{ref:b,onClick:a,onPointerDown:w=>{w.button===0&&a()},role:"group",className:Ze.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Ie(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Gh(k,{selected:n,flash:r,bare:s}),...!s&&{[`& .${hp}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:k.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${k.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...cp,...n&&{[`& .${up}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[y,m.jsx(H,{ref:x,"aria-label":`Move ${pr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(dp,{label:`Remove ${pr(e)}`,onRemove:f,...c?{disabledReason:c}:{},inset:s?Nc:0}),!De(e)&&m.jsx(_n,{className:"builder-affordance",size:"small","aria-label":`Settings for ${pr(e)}`,onClick:w=>{w.stopPropagation(),d(w.currentTarget)},sx:{position:"absolute",top:s?0:`${wc}px`,right:s?0:`${wc}px`,borderRadius:h.radius.control,width:28,height:28,zIndex:2,color:"text.secondary",bgcolor:"action.hover",opacity:n||i?1:0,transition:`opacity ${Be}`,...qt,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(my,{})}),p&&m.jsx(H,{className:`builder-affordance ${Ze.widthHandle}`,[Mh]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${pr(e)}`,...u?{"aria-valuenow":u.span,"aria-valuemin":1,"aria-valuemax":u.columns,"aria-valuetext":`${u.span} of ${u.columns} columns`}:{},onKeyDown:w=>{if(!u)return;const $=w.key==="ArrowRight"?u.span+1:w.key==="ArrowLeft"?u.span-1:w.key==="Home"?1:w.key==="End"?u.columns:void 0;$!==void 0&&(w.preventDefault(),w.stopPropagation(),u.onStep(Math.min(Math.max($,1),u.columns)))},onPointerDown:p,onPointerMove:g,onPointerUp:v,onPointerCancel:v,onClick:w=>w.stopPropagation(),sx:w=>({position:"absolute",top:0,bottom:0,right:"-8px",width:"16px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:l||n?1:0,transition:`opacity ${Be}`,...qt,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${k.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"12px",height:"40px",boxSizing:"border-box",borderRadius:h.radius.control,border:`1px solid ${l?k.accent:Vt(k.cardBorder)}`,bgcolor:w.palette.background.paper,boxShadow:"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",transition:`border-color ${Be}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"5px",height:"16px",borderLeft:`1.5px solid ${l?k.accent:w.palette.text.secondary}`,borderRight:`1.5px solid ${l?k.accent:w.palette.text.secondary}`,boxSizing:"border-box",opacity:l?1:.7},"&:hover::before":{borderColor:k.accent},"&:hover::after":{borderColor:k.accent,opacity:1}}),children:l&&u&&m.jsx(H,{"aria-hidden":!0,sx:w=>({position:"absolute",top:"50%",right:"50%",transform:"translateY(calc(-100% - 28px))",px:1,py:.5,borderRadius:h.radius.control,bgcolor:w.palette.text.primary,color:w.palette.background.paper,...h.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:dy(u.span,u.columns)})}),o&&m.jsx(_n,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${pr(e)}`,onClick:w=>{w.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${Wn/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:k.tileTitle,bgcolor:k.tile,border:k.cardBorder,opacity:0,transition:`opacity ${Be}`,...qt,"&:hover, &:focus-visible":{opacity:1,bgcolor:k.tile}},children:m.jsx(ti,{sx:{fontSize:14}})})]})})}const wc=14,Vs=7,Gh=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:i=Nc})=>{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 ${Be}, border-color ${Be}, opacity ${Be}, box-shadow ${Be}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-i}px`,borderRadius:1,border:`2px solid ${o}`,...a&&{boxShadow:a},pointerEvents:"none",transition:d,...qt}}:{borderRadius:s.radius.tile,"& > .MuiPaper-root":{transition:d,...qt,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:d,...qt,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:fs(e.cardBorder,e.tileTitle)}}}}};function hy({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=_e();return m.jsxs(eo,{chrome:r,children:[m.jsx(to,{title:t?.title??Nn(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx(fe,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),m.jsxs(fe,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function fy({after:e}){const{theme:t}=_e();return m.jsx(lx,{id:mh(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx(H,{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 ${Be}, background-color ${Be}`,...qt}})})}function py({columns:e}){const{theme:t}=_e();return m.jsx(H,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${Wn}px`},children:Array.from({length:e},(n,r)=>m.jsx(H,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function my(){return m.jsxs(Pp,{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"})]})}function gy({editor:e,reorder:t,resizing:n,gridBox:r,defaultSpan:i=1,rules:s,canAdd:o,selected:a,flash:d,menuIndex:f,onSelect:c,onOpenMenu:l,onRemove:u,removeBlocked:p,openAdd:g,editTile:v,renderTile:y}){const{dragging:k,preview:h,onDragStart:b,onDragOver:x,onDragEnd:w}=t,{columns:$}=s,{resize:E,startResize:D,onResize:O,endResize:j}=n,P=_=>_.colspan===void 0?{..._,colspan:i}:_,R=(E!==void 0?e.document.tiles.map((_,T)=>T===E.index?{..._,colspan:E.span}:_):h??e.document.tiles).map(P),A=e.document.tiles.length===0,L=k||E!==void 0?Mb(R,$):R.map(ph),U=_=>vy(_,Nn(_),v);return m.jsxs(m.Fragment,{children:[m.jsx(lb,{sensors:ix,onDragStart:b,onDragOver:x,onDragEnd:w,children:m.jsxs(H,{ref:r,sx:{position:"relative"},children:[s.widths&&(k||E!==void 0)&&m.jsx(py,{columns:$}),m.jsx(Tf,{tiles:L,columns:$,rowGapPx:Wn,keyOf:_=>_.kind==="gap"?mh(_.after):Ie(_.tile),renderTile:_=>{if(_.kind==="gap")return m.jsx(fy,{after:_.after});const{tile:T,index:z}=_;return m.jsx(uy,{tile:T,index:z,selected:z===a,flash:Ie(T)===d,menuOpen:f===z,bare:De(T),...s.insertBetween&&o&&z<e.document.tiles.length-1?{onInsertAfter:()=>g(z+1)}:{},...s.widths&&by(T)?{resizing:E?.index===z,width:{span:T.colspan??1,columns:$,onStep:F=>{F!==(T.colspan??1)&&e.update(W=>{const B=W.tiles[z];B&&(B.colspan=F)})}},onResizeStart:F=>D(F,z),onResizeMove:O,onResizeEnd:j}:{},onSelect:()=>c(z),onOpenMenu:F=>l(F,z),onRemove:()=>u(z),...p?{removeBlocked:p}:{},children:De(T)?m.jsx(ly,{tile:T,onChange:F=>v(Ie(T),W=>{De(W)&&(W.markdown=F)})}):y?y(T,U(T),"card"):m.jsx(hy,{tile:T,heading:U(T)})})}})]})}),s.insertBetween&&o&&!A&&m.jsx(ke,{size:"small",startIcon:m.jsx(ti,{}),"aria-label":"Add tile at the end",onClick:()=>g(),sx:{alignSelf:"center"},children:"Add tile"})]})}const vy=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Ie(e),i=s=>o=>n(r,a=>{de(a)&&(o===""?delete a[s]:a[s]=o)});return{title:m.jsx(Go,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:i("label")}),subtitle:m.jsx(Go,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:i("subtitle")})}},by=e=>De(e)||e.declaration.kind!=="inherited",xy=12;function yy({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:i}){const{theme:s}=_e();return m.jsx(zf,{actions:n,title:m.jsx(Go,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx(H,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:i,onFocus:i,children:m.jsx(Ac,{sx:{position:"relative",overflow:"visible",...Gh(s,{selected:r,bare:!0,ringOffset:xy})},children:m.jsx(qh,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const wy=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:s}=sa({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 ky(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(),setLayout:x=>n.current.layout?.set(x),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?.()}),[]),{status:s,saveTarget:o,canUndo:a,canRedo:d,add:{filterUnavailable:f}}=t,c=t.save!==void 0,l=t.layout?.value,u=t.add.tile!==void 0,p=t.add.text!==void 0,g=t.add.filter!==void 0,v=t.exit!==void 0,y=t.done!==void 0,k=t.discard!==void 0,{draftKeptAt:h}=t,b=S.useMemo(()=>({status:s,saveTarget:o,...c?{save:i.save}:{},canUndo:a,undo:i.undo,canRedo:d,redo:i.redo,...l!==void 0?{layout:{value:l,set:i.setLayout}}:{},add:{...u?{tile:i.addTile}:{},...p?{text:i.addText}:{},...g?{filter:i.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...v?{exit:i.exit}:{},...y?{done:i.done}:{},...h!==void 0?{draftKeptAt:h}:{},...k?{discard:i.discard}:{}}),[i,s,o,c,a,d,l,u,p,g,f,v,y,h,k]);S.useEffect(()=>{r.current?.(b)},[b,e!==void 0]),S.useEffect(()=>()=>r.current?.(void 0),[])}function Sy({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:"model",fixed:v.reason,...h!==void 0&&a?{openModel:()=>a(h)}:{}}}const y=p.get(g);if(!y)return;const k=t(y.name,y.type);return{origin:y.origin,...k.length>0?{problem:`Cannot filter on ${k.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(Af,{children:m.jsx(Rf.Provider,{value:u,children:l?c:m.jsxs(tt,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(p=>m.jsx(Pf,{name:p.name,label:p.label??p.name,unused:p.boundTiles===0},p.name)),m.jsx(If,{})]})})})}function $y(e,t){const n=new Map(e.tiles.map((r,i)=>[Ie(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(Ie(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return Ie(i)}}function jy({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(y=>r(k=>typeof k=="object"&&k.tile===y?k:{tile:y}),[]),a=S.useCallback(()=>r(y=>y==="description"?y:void 0),[]),d=S.useCallback(()=>r("description"),[]),f=S.useCallback(()=>r(void 0),[]),c=n!==void 0;S.useEffect(()=>{if(!c)return;const y=k=>{const h=k.target;h instanceof Element&&h!==document.documentElement&&h.closest(Cy)===null&&f()};return document.addEventListener("pointerdown",y,!0),()=>document.removeEventListener("pointerdown",y,!0)},[c,f]);const[l,u]=S.useState(void 0),p=S.useRef(!1),g=S.useRef(e.document);S.useEffect(()=>{const y=g.current;if(g.current=e.document,!p.current)return;p.current=!1;const k=$y(y,e.document);k!==void 0&&(u(k),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(h=>h.dataset.tileKey===k)?.scrollIntoView?.({block:"nearest",behavior:Ef()}))},[e.document,t]),S.useEffect(()=>{if(l===void 0)return;const y=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(y)},[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 Cy=["[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 My({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 Ey({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),y=S.useRef(a);y.current=a;const k=e.dirty||s,h=(e.edited??e.dirty)||s,b=o?s:h;S.useEffect(()=>{i?.(e.document)},[e.document,i]),S.useLayoutEffect(()=>{n?.(h,b)},[h,b,n]);const x=S.useRef(n);x.current=n,S.useEffect(()=>()=>x.current?.(!1,!1),[]);const w=S.useRef(d);w.current=d,S.useEffect(()=>{g(!1)},[e.document]);const $=S.useCallback(()=>{u(!0),g(!1);const T=Lt(),{structural:z}=e,F=y.current.size;return e.save().then(W=>{W.ok===!0?y.current.saved({size:F,structural:z,durationMs:Lt()-T}):y.current.refused(W.reason)}).finally(()=>u(!1))},[e]),E=S.useRef(!1),D=S.useRef(!1);S.useEffect(()=>{!D.current||l||(D.current=!1,v.current?.focus())},[p,l]);const O=S.useCallback(()=>{if(!t||l||E.current||!e.canUndoSave)return;E.current=!0,u(!0);const T=Lt(),z=e.lastSave?.structural??!1,F=y.current.size;return e.undoSave().then(W=>{W.ok===!0?(D.current=!0,g(!0),y.current.undone({size:F,structural:z,durationMs:Lt()-T})):y.current.undoRefused(W.reason)}).finally(()=>{E.current=!1,u(!1)})},[t,l,e]),j=S.useCallback(()=>{if(!(!t||!e.dirty||l))return $()},[t,e,l,$]),P=S.useRef(j);P.current=j;const R=S.useCallback(()=>{const T=()=>P.current();return f?f(T):T()},[f]),A=My({dirty:h,saving:l,canSave:!!t,save:R,onExit:()=>r?.()});qp(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:R}:{},paused:A.dialog.open}),[c,e,t,R,A.dialog.open]));const L=!!t&&!l&&e.canUndoSave,U=e.lastSave,_={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:k,saving:l,saveButton:v,...t?{onSave:R}:{},...r?{onExit:A.requestExit}:{}};return{saving:l,save:R,exitGuard:A,...r?{done:A.saveAndExit}:{},undoSave:O,canUndoSave:L,lastSave:U,toolbarProps:_}}const Oy=1;function Yh(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(...Yh(a,`${t}${s}.`,n-1))}}}return r}function Ty(e){const t=new Map;for(const n of Vh(e))t.set(n.name,Yh(n.schema?.fields,"",Oy));return t}function Vh(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}const Dy=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&Mp.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Ay(e){const t=new Map;for(const n of Vh(e)){const r=new Set;for(const i of n.schema?.fields??[]){if(i.kind!=="view"||typeof i.name!="string")continue;const s=i.schema?.fields;s&&s.length>0&&s.every(Dy)&&r.add(i.name)}t.set(n.name,r)}return t}function kc(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const Sc=(e,t)=>e!==void 0&&t.has(e),$c=e=>e.path||e.modelPath||"";function Ry(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=$c(a);if(Sc(d,t))continue;const f=Mf(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=$c(a);if(Sc(d,t))continue;const f=Ty(a),c=Ay(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],...mi(l.annotations)?{description:mi(l.annotations)}:{},views:(l.views??[]).filter(g=>typeof g.name=="string").map(g=>({name:g.name,...mi(g.annotations)?{description:mi(g.annotations)}:{},...bl(g.annotations)?{chart:bl(g.annotations)}:{},...c.get(u)?.has(g.name)?{aggregateOnly:!0}:{}})),givens:p,fields:f.get(u)??[]})}}return{sources:n}}function Py({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(()=>om(e.document,o),[e.document,o]),d=S.useMemo(()=>new Map(e.document.sources.map(u=>[u.name,kc(r,u.base)])),[r,e.document.sources]),f=S.useCallback(u=>d.get(u.source)??kc(r,u.source),[d,r]),c=(u,p)=>{const g=[];for(const v of e.document.tiles){if(!de(v))continue;const y=f(v);if(!y)continue;const k=new Map(y.map(h=>[h.name,h.type]));for(const h of v.filters??[])h.given===u&&(!k.has(h.field)||!zr(p,k.get(h.field)))&&g.push(`${h.field} on ${v.label??v.name} (${e.document.sources.find(b=>b.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&&pm(v,g),fm(v,u,p)})},dropControl:u=>{s(void 0),e.update(p=>mm(p,u))}}}function Iy(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,y]=S.useState(!1),k=s.stack[s.index],h=S.useRef(s);h.current=s;const b=S.useRef(!1),[x,w]=S.useState(!1),$=W=>{b.current=W,w(W)},[E,D]=S.useState(void 0),O=S.useCallback(W=>{c(void 0),o(B=>{const X=structuredClone(B.stack[B.index]);if(W(X),JSON.stringify(X)===JSON.stringify(B.stack[B.index]))return B;const J=[...B.stack.slice(0,B.index+1),X].slice(-100);return{stack:J,index:J.length-1}})},[]),j=S.useCallback(()=>{c(void 0),o(W=>W.index>0?{...W,index:W.index-1}:W)},[]),P=S.useCallback(()=>{c(void 0),o(W=>W.index<W.stack.length-1?{...W,index:W.index+1}:W)},[]),R=S.useCallback(async(W,B)=>{try{return await t(W,B)}catch(X){return{ok:!1,reason:`Could not build the file: ${X instanceof Error?X.message:String(X)}`}}},[t]),A=S.useCallback(async()=>{if(b.current)return{ok:!1,reason:"A save is still being written."};const W={source:a,saved:l,history:h.current,replacing:p,unwritten:v},B=i?.(l,k)??!1,X=r?.(l,k)??!1;$(!0);try{const J=await R(a,k);if(Qo(J))return c(J.reason),{ok:!1,reason:J.reason};try{await n?.(J.source,{purpose:"save",document:k})}catch(ee){const N=`Could not save: ${ee instanceof Error?ee.message:String(ee)}`;return c(N),{ok:!1,reason:N}}d(J.source),u(k),g(void 0),y(!1);const re=B?{stack:[k],index:0}:W.history;return o(ee=>ee===W.history?re:B?{stack:[ee.stack[ee.index]],index:0}:ee),D(n?{before:W,after:re,lastSave:{before:p??a,after:J.source,structural:X,clearsHistory:B}}:void 0),c(void 0),{ok:!0}}finally{$(!1)}},[k,R,n,a,l,p,v,i,r]),L=S.useCallback(async()=>{if(b.current)return{ok:!1,reason:"A save is still being written."};if(!n||E===void 0||E.after!==h.current)return{ok:!1,reason:"There is no save to undo."};const{before:W}=E;$(!0);try{await n(W.replacing??W.source,{purpose:"undo",document:W.saved})}catch(B){const X=`Could not undo the save: ${B instanceof Error?B.message:String(B)}`;return c(X),{ok:!1,reason:X}}finally{$(!1)}return d(W.source),u(W.saved),g(W.replacing),y(W.unwritten||W.replacing!==void 0),o(B=>B===E.after?W.history:B),D(void 0),c(void 0),{ok:!0}},[n,E]),U=S.useMemo(()=>v||JSON.stringify(k)!==JSON.stringify(l),[k,l,v]),_=S.useMemo(()=>r?.(l,k)??!1,[k,l,r]),T=S.useMemo(()=>i?.(l,k)??!1,[k,l,i]),z=E!==void 0&&E.after===s,F=S.useCallback(async()=>{const W=await R(a,k);return Qo(W)?{ok:!1,reason:W.reason}:{ok:!0,source:W.source}},[k,R,a]);return{document:k,saved:l,source:a,canUndo:s.index>0,canRedo:s.index<s.stack.length-1,dirty:U,edited:U,...f===void 0?{}:{error:f},update:O,undo:j,redo:P,save:A,preview:F,structural:_,clearsHistory:T,canUndoSave:z&&!x&&n!==void 0,...z?{lastSave:E.lastSave}:{},undoSave:L}}const zy=(e,t)=>{const n=new Set(e.tiles.map(ea)),r=new Set(t.tiles.map(ea));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function Wy(e){const{visibleSources:t,...n}=e,r=S.useCallback((i,s)=>oy(i,s,t?{visibleSources:t}:{}),[t]);return Iy({...n,splice:r,structural:zy})}function Ny({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 Ly({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(b=>Xp(b,h,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c})),i(c??e.document.tiles.length)},v=()=>k(c),y=()=>k(void 0),k=h=>{f(!1),e.update(b=>{const x=new Set(b.tiles.filter(De).map($=>$.name));let w=1;for(;x.has(`text_${w}`);)w++;b.tiles.splice(h??b.tiles.length,0,{kind:"text",name:`text_${w}`,markdown:"",...t.widths?{colspan:t.columns}:{}})}),i(h??e.document.tiles.length)};return{menu:o,setMenu:a,addingTile:d,openAdd:u,closeAdd:p,addTile:g,addText:v,appendText:y,editTile:(h,b)=>e.update(x=>{const w=x.tiles.find($=>Ie($)===h);w&&b(w)}),removeTile:h=>{a(void 0),s(),e.update(b=>{b.tiles.splice(h,1)})},duplicate:h=>{a(void 0);const b=e.document.tiles[h],x=b&&de(b)&&Ki(b)===void 0?h+1:void 0;e.update(w=>{Jp(w,h)}),x!==void 0&&i(x)}}}var Fy=Object.defineProperty,By=Object.defineProperties,_y=Object.getOwnPropertyDescriptors,jc=Object.getOwnPropertySymbols,Hy=Object.prototype.hasOwnProperty,Uy=Object.prototype.propertyIsEnumerable,Cc=(e,t,n)=>t in e?Fy(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$n=(e,t)=>{for(var n in t||(t={}))Hy.call(t,n)&&Cc(e,n,t[n]);if(jc)for(var n of jc(t))Uy.call(t,n)&&Cc(e,n,t[n]);return e},jn=(e,t)=>By(e,_y(t));function qy(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Ei(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Xs(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Ky(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,b)=>h===b||h!==null&&typeof h=="object"&&"id"in h&&h.id===b;if(Array.isArray(e)){const h=e.findIndex(x=>d(x,s.id)),b=e.findIndex(x=>d(x,o.id));if(h===-1||b===-1){if(Xs(s)){const x=s.initialIndex,w=s.index;return x===w||x<0||x>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,x,w)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const x=s.index;if(x!==h)return n(e,h,x)}return n(e,h,b)}const f=Object.entries(e);let c=-1,l,u=-1,p;for(const[h,b]of f)if(c===-1&&(c=b.findIndex(x=>d(x,s.id)),c!==-1&&(l=h)),u===-1&&(u=b.findIndex(x=>d(x,o.id)),u!==-1&&(p=h)),c!==-1&&u!==-1)break;if(c===-1&&Xs(s)){const h=s.initialGroup==null?void 0:Ei(e,s.initialGroup),b=s.initialIndex,x=s.group==null?void 0:Ei(e,s.group),w=s.index;if(h==null||x==null||h===x&&b===w)return"preventDefault"in t&&t.preventDefault(),e;if(h===x)return jn($n({},e),{[h]:n(e[h],b,w)});const $=e[h][b];return jn($n({},e),{[h]:[...e[h].slice(0,b),...e[h].slice(b+1)],[x]:[...e[x].slice(0,w),$,...e[x].slice(w)]})}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=Ei(e,o.id);if(h!=null){const b=o.shape&&v.y>o.shape.center.y?e[h].length:0;p=h,u=b}}if(l==null||p==null||l===p&&c===u){if(l!=null&&l===p&&c===u&&Xs(s)){const h=s.group==null?void 0:Ei(e,s.group),b=s.group!=null&&h!==l,x=s.index!==c;if(b||x){const w=s.group==null?l:h;if(w!=null){if(l===w)return jn($n({},e),{[l]:n(e[l],c,s.index)});const $=e[l][c];return jn($n({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[w]:[...e[w].slice(0,s.index),$,...e[w].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===p)return jn($n({},e),{[l]:n(e[l],c,u)});const y=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,k=e[l][c];return jn($n({},e),{[l]:[...e[l].slice(0,c),...e[l].slice(c+1)],[p]:[...e[p].slice(0,u+y),k,...e[p].slice(u+y)]})}function Gy(e,t){return Ky(e,t,qy)}function Yy({tiles:e,commit:t,onLanded:n}){const[r,i]=S.useState(void 0),s=S.useRef(void 0),[o,a]=S.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),s.current=e},onDragOver:d=>{const{source:f,target:c}=d.operation;if(!f||!c)return;const l=s.current??e;let u;if(c.type===Ch){const{after:p}=c.data,g=l.findIndex(y=>Ie(y)===f.id);if(g<0||p===f.id)return;const v=l.filter((y,k)=>k!==g).findIndex(y=>Ie(y)===p)+1;u=Cb(l,g,v)}else{const p=l.map(Ie),g=Gy(p,d);if(g.every((y,k)=>y===p[k]))return;const v=new Map(l.map(y=>[Ie(y),y]));u=jb(g.map(y=>v.get(y)),e.map(y=>y.break??!1))}s.current=u,i(u)},onDragEnd:d=>{a(!1);const f=s.current;if(s.current=void 0,i(void 0),d.canceled||!f)return;t(f);const c=f.findIndex(l=>Ie(l)===d.operation.source?.id);c>=0&&n(c)}}}const Js=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Vy({tiles:e,columns:t,gridBox:n,onStart:r,commit:i}){const[s,o]=S.useState(void 0),a=S.useRef(void 0),d=f=>{a.current=f,o(f)};return S.useEffect(()=>()=>Js(!1),[]),{resize:s,startResize:(f,c)=>{const l=n.current?.getBoundingClientRect(),u=f.currentTarget.parentElement?.getBoundingClientRect();if(!l||!u)return;f.stopPropagation(),f.preventDefault(),f.currentTarget.setPointerCapture(f.pointerId),Js(!0),r(c);const p=e[c]?.colspan??1;d({index:c,span:p,from:p,left:u.left,track:(l.width-Wn*(t-1))/t})},onResize:f=>{const c=a.current;if(!c)return;const l=f.clientX-c.left,u=Math.round((l+Wn)/(c.track+Wn)),p=Math.min(Math.max(u,1),t);p!==c.span&&d({...c,span:p})},endResize:f=>{f.currentTarget.hasPointerCapture(f.pointerId)&&f.currentTarget.releasePointerCapture(f.pointerId),Js(!1);const c=a.current;if(!c)return;const{index:l,span:u,from:p}=c;d(void 0),!(f.type==="pointercancel"||u===p)&&i(l,u)}}}function Xh({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,onExit:s,allowLayoutChange:o=!0,renderTile:a,renderViewPreview:d,controls:f,givens:c,catalog:l,toolbar:u,dashboards:p,onEvent:g,savesTo:v="package",saveLabel:y,replaces:k,modelPath:h,visibleSources:b,addFilterDisabledReason:x,fixedFilters:w,onOpenModel:$,takenGivenNames:E,onControlsChange:D,draftKey:O}){const j=Wy({source:e,document:t,...n?{onSave:n}:{},...k!==void 0?{replaces:k}:{},...b?{visibleSources:b}:{}}),P=ff(O,j,e),R=S.useRef(null),{selected:A,descriptionSelected:L,selectTile:U,deselectTile:_,selectDescription:T,clearSelection:z,flash:F,stepEditor:W}=jy({editor:j,gridBox:R}),B=pf(j.document.layout,j.document.columns),{columns:X}=B,J=h?.split("/").at(-1)?.replace(/\.malloy$/,""),re=Yy({tiles:j.document.tiles,commit:K=>j.update(se=>{se.tiles=K}),onLanded:U}),{dragging:ee}=re,N=mf(R,X),Z=S.useMemo(()=>j.document.tiles.map(K=>K.colspan===void 0?{...K,colspan:N}:K),[j.document.tiles,N]),pe=Vy({tiles:Z,columns:X,gridBox:R,onStart:U,commit:(K,se)=>j.update(me=>{const oe=me.tiles[K];oe&&(oe.colspan=se)})}),ne=Ly({editor:j,rules:B,modelPath:h,textHeld:b!==void 0,selectTile:U,deselectTile:_}),{menu:Q,addingTile:Se,openAdd:be}=ne,G=Py({editor:j,opened:t,givens:c,catalog:l}),{filterDialog:$e,setFilterDialog:he}=G,[ie,Ne]=S.useState(void 0),{draftDirty:Ke,openDraft:He,prepare:Ge}=Ny({editorDirty:j.dirty}),Ye=S.useMemo(()=>({escape:()=>{!Q&&!$e&&!Se&&ie===void 0&&z()},nudge:K=>{if(ee||A===void 0||!B.widths)return;const se=j.document.tiles[A];if(!se||de(se)&&se.declaration.kind==="inherited")return;const me=gf(se.colspan??N,K,X);me!==(se.colspan??N)&&j.update(oe=>{oe.tiles[A].colspan=me})}}),[N,j,Q,$e,Se,ie,z,A,X,B,ee]),M=Ey({editor:W,extraDirty:Ke,keepsEdits:O!==void 0&&P.keeping,prepare:Ge,unit:{name:"tile",count:K=>K.tiles.length},onSave:n,onDirtyChange:i,onExit:s,onChange:r,shortcuts:Ye,report:wy({size:j.document.tiles.length,path:h??"",layout:j.document.layout,savesTo:v,onEvent:g})}),I=j.document.tiles.length===0,q=b===void 0&&o?{layout:j.document.layout,onLayoutChange:K=>{const se=j.document.layout;K!==se&&(j.update(me=>{me.layout=K}),sa({path:h??"",layout:K},g).emit({type:"report.layout_changed",from:se,to:K}))}}:void 0,{toolbarProps:C}=M;ky(D,{status:M.saving?"saving":C.dirty?"unsaved":"saved",saveTarget:y??oo[v],...C.onSave?{save:C.onSave}:{},canUndo:C.canUndo,undo:C.onUndo,canRedo:C.canRedo,redo:C.onRedo,...q?{layout:{value:q.layout,set:q.onLayoutChange}}:{},add:{...l?{tile:()=>ne.openAdd()}:{},text:ne.appendText,...x!==void 0?{filterUnavailable:x}:I?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>he({})}},...C.onExit?{exit:C.onExit}:{},...M.done?{done:M.done}:{},...P.keptAt!==void 0?{draftKeptAt:P.keptAt}:{},...C.dirty&&O!==void 0?{discard:P.discard}:{}});const te=D?void 0:m.jsx(Kp,{...M.toolbarProps,...u?{actions:u}:{},...l?{onAddTile:()=>be()}:{},savesTo:v,...y?{saveLabel:y}:{},...q??{}});return m.jsx(hh.Provider,{value:He,children:m.jsx(tt,{className:Ze.builder,"data-saves-to":v,sx:{gap:0,mx:`-${Vs}px`},children:m.jsxs(vf,{layout:B.layout,sx:{px:`${Vs}px`,pb:`${Vs}px`},header:m.jsx(yy,{editor:j,documentSlug:J,actions:te,descriptionSelected:L,selectDescription:T}),controls:I?void 0:m.jsx(Sy,{controls:G.controlList,unknownFieldsOf:G.unknownFieldsOf,onEdit:K=>he({control:K}),onAdd:()=>he({}),...x?{addDisabledReason:x}:{},onRemove:G.dropControl,...w?{fixedFilters:w}:{},...$?{onOpenModel:$}:{},...j.document.startingGivens?{startingValues:j.document.startingGivens}:{},onStartingValue:(K,se)=>j.update(me=>{const oe={...me.startingGivens??{}};se===void 0?delete oe[K]:oe[K]=se,Object.keys(oe).length>0?me.startingGivens=oe:delete me.startingGivens}),children:f}),children:[I&&m.jsxs(tt,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx(fe,{variant:"body2",children:"This report is not served until it has a tile."}),l&&m.jsx(ke,{size:"small",startIcon:m.jsx(ti,{}),onClick:()=>be(),children:"Add tile"})]}),P.restored&&m.jsx(it,{severity:P.restored.pending?"warning":"info",onClose:P.dismissRestored,action:P.restored.pending?m.jsxs(m.Fragment,{children:[m.jsx(ke,{color:"inherit",size:"small",onClick:P.restoreOffered,children:"Restore them"}),m.jsx(ke,{color:"inherit",size:"small",onClick:P.discard,children:"Discard"})]}):m.jsx(ke,{color:"inherit",size:"small",onClick:P.discard,children:"Discard edits"}),children:P.restored.pending?`You have unsaved edits from ${Mc(P.restored.savedAt)}, made before this report changed. Restoring them replaces the current version.`:`Restored your unsaved edits from ${Mc(P.restored.savedAt)}.`}),j.error&&m.jsx(it,{severity:"warning",children:j.error}),m.jsx(gy,{editor:j,reorder:re,resizing:pe,gridBox:R,defaultSpan:N,rules:B,canAdd:!!l,selected:A,flash:F,menuIndex:Q?.index,onSelect:U,onOpenMenu:(K,se)=>{U(se),ne.setMenu({anchor:K,index:se})},onRemove:ne.removeTile,...j.document.tiles.length===1&&j.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:be,editTile:ne.editTile,...a?{renderTile:a}:{}}),m.jsx(jm,{editor:j,catalog:l,columns:X,dashboards:p,bindings:G,tiles:ne,drillSource:ie,setDrillSource:Ne,exitDialog:M.exitGuard.dialog,...d?{renderViewPreview:d}:{},...E?{takenGivenNames:E}:{}})]})})})}function Mc(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 Xy=ot(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),Jy=ot(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"})),Zy=ot(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"})),Qy=ot(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 $0({controls:e,onDone:t}){const n=t??e?.exit,r=hf("(max-width: 599.95px)"),{theme:i}=_e(),s=Vt(i.cardBorder),o=fs(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(tt,{direction:"row",role:"toolbar",className:Ze.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(e0,{controls:e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx(lt,{title:`Undo (${dn}Z)`,children:m.jsx("span",{children:m.jsx(_n,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:qi(i.ui),children:m.jsx(_c,{fontSize:"small"})})})}),m.jsx(lt,{title:`Redo (${dn}⇧Z)`,children:m.jsx("span",{children:m.jsx(_n,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:qi(i.ui),children:m.jsx(Bc,{fontSize:"small"})})})}),(e.layout||p)&&m.jsx(zn,{orientation:"vertical",sx:Ir}),e.layout&&m.jsx(lt,{title:"Layout: tiles side by side, or one after another",children:m.jsxs(ps,{size:"small",exclusive:!0,value:e.layout.value,"aria-label":"Layout",onChange:(v,y)=>{y&&y!==e.layout?.value&&e.layout?.set(y)},sx:Hn(s,i.ui),children:[m.jsx(un,{value:"linear","aria-label":"Linear layout",children:"Linear"}),m.jsx(un,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),p&&m.jsxs(m.Fragment,{children:[m.jsx(ke,{variant:"outlined",startIcon:m.jsx(ti,{}),endIcon:m.jsx(na,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:v=>d(v.currentTarget),sx:{...Pr(s,o),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs(Hi,{anchorEl:a,open:a!==null,onClose:()=>d(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:n0(s,i.ui)}},MenuListProps:{sx:{p:.5}},children:[u?.tile&&m.jsx(Zs,{icon:m.jsx(Jy,{}),title:"Tile",detail:"A view from the model",onClick:g(u.tile)}),u?.text&&m.jsx(Zs,{icon:m.jsx(Zy,{}),title:"Text",detail:"Prose between the tiles",onClick:g(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(Zs,{icon:m.jsx(Xy,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:g(u.filter)})]})]})]})]}),(c||l)&&e&&m.jsx(zn,{orientation:"vertical",sx:Ir}),c&&m.jsx(lt,{enterDelay:800,enterNextDelay:800,title:e?.done&&f?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx(ke,{variant:l?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:c,sx:{...Pr(s,o,i.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&l&&m.jsx(lt,{title:`Save (${dn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx(ke,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...Pr(s,o,i.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}function e0({controls:e}){const{theme:t}=_e(),n=t.ui,[r,i]=S.useState(null),{status:s,draftKeptAt:o,discard:a}=e,d=s==="saved"?"Saved":s==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",f=s==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,c=a!==void 0&&s==="unsaved",l=p=>({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"?p.palette.text.secondary:p.palette.text.primary,transition:`color ${Be}, background-color ${Be}`,...c?{"&:hover":{bgcolor:p.palette.action.hover}}:{}}),u=m.jsxs(m.Fragment,{children:[m.jsx(H,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:s==="saved"?m.jsx(aa,{sx:{fontSize:16}}):m.jsx(H,{component:"span",sx:p=>({width:7,height:7,borderRadius:"50%",bgcolor:s==="saving"||o!==void 0?p.palette.text.disabled:p.palette.warning.main})})}),m.jsx(H,{component:"span","aria-hidden":!0,children:d}),m.jsx(na,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:c?"visible":"hidden"}})]});return m.jsxs(m.Fragment,{children:[m.jsx(H,{component:"span",role:"status","aria-live":"polite",sx:t0,children:d}),m.jsx(lt,{title:f,describeChild:!0,children:c?m.jsx(Dc,{className:Ze.saveStatus,"aria-label":d,"aria-haspopup":"menu","aria-expanded":r!==null,onClick:p=>i(p.currentTarget),sx:l,children:u}):m.jsx(H,{component:"span",className:Ze.saveStatus,sx:l,children:u})}),m.jsxs(Hi,{className:Ze.menu,anchorEl:r,open:r!==null,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${Vt(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[o!==void 0&&m.jsxs(H,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:["Kept in this browser at"," ",new Date(o).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),m.jsxs(bt,{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(Qy,{fontSize:"small"}),"Discard edits"]})]})]})}const t0={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},n0=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Zs({icon:e,title:t,detail:n,disabled:r=!1,onClick:i}){const{theme:s}=_e(),o=s.ui;return m.jsxs(bt,{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 ${Be}, background-color ${Be}`,"& 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(H,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs(H,{className:"add-text",sx:{minWidth:0},children:[m.jsx(H,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx(H,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function r0(e,t,n=new Set){const r=new Set;for(const o of e.tiles)for(const a of de(o)?o.filters??[]:[])r.add(a.given);const i=[],s=new Set;for(const o of e.localGivens??[])r.has(o.name)&&(s.add(o.name),i.push(jp(o)));for(const o of t)o.name===void 0||s.has(o.name)||!(r.has(o.name)||n.has(o.name))||(s.add(o.name),i.push(o));return i}function i0(e,t,n){const r=new Map;for(const s of t.tiles)de(s)&&r.set(In(`${s.source} -> ${s.name}`),new Set((s.filters??[]).map(o=>o.given)));const i=new Set;for(const s of e.tiles){if(!de(s))continue;const o=In(`${s.source} -> ${s.name}`),a=r.get(o);for(const d of n.get(o)??[])a?.has(d)||i.add(d)}return i}function s0(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function o0(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function In(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function a0(e,t,n,r=new Map,i){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:i&&[...i]};const s=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(y=>[y.name,y.type])),d=new Map((e.localGivens??[]).map(y=>[y.name,y.default])),f=e.sources.find(y=>y.name===s)?.scopedBy??[],c=new Set([...f,...i??[]].filter(y=>n.has(y))),l=new Set([...f,...i??[]]),u=[];for(const y of t.filters??[]){const k=`where: ${da(y.field)} ${y.op??"~"}`;if(n.has(y.given)){c.add(y.given),l.add(y.given),u.push(`${k} $${y.given}`);continue}if(!a.has(y.given))continue;l.add(y.given);const h=Cp(r.get(y.given),a.get(y.given))??s0(d.get(y.given));h!==void 0&&u.push(`${k} ${h}`)}const p=u.join(", "),g=t.chart,v=g==="none"||ua(g)?cn(g,t.chartCarried):g==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
+
`):g==="default"&&o0(t.declaration)?cn("none"):void 0;return{...v?{annotation:v}:{},expression:`${s} -> ${o}`+(p?` + { ${p} }`:""),givenNames:Array.from(c),reads:i||l.size>0?Array.from(l):void 0}}function l0({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:i,reportsSettled:s}){const{apiClients:o,server:a}=ra(),{data:d}=ia({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=$p({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?Ry(l.flatMap((g,v)=>g.data?[{...g.data,path:c[v]}]:[]),f):void 0,[u,c,p,f])}const c0={};function d0({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:i,opened:s,replaces:o,onSave:a,onDirtyChange:d,onExit:f,onOpenModel:c,onControlsChange:l,draftKey:u,allowLayoutChange:p,onEvent:g,savesTo:v,saveLabel:y,note:k}){const{apiClients:h}=ra(),[b,x]=S.useState(s.document.tiles.length>0);S.useEffect(()=>x(s.document.tiles.length>0),[s.generation,s.document]);const{data:w,isSuccess:$,isError:E}=ia({...Uf(h,{environmentName:t,packageName:n,path:r,versionId:i},qf),enabled:b&&!e}),D=e?.modelPath??r,O=h0(s.source,e?.compileSource),j=Kf({environmentName:t,packageName:n,modelPath:D,source:O.text??s.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&O.text!==void 0}),P=j.data?.document,R=e?j.isSuccess?P?.manifest??c0:void 0:w,A=e?j.isSuccess:$,L=e?j.isError||O.problem!==void 0:E,U=e?Gf(P?.cells):void 0,_=(j.data?.result.problems??[]).filter(C=>C.severity==="error"),T=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),z=e?.givens,F=S.useMemo(()=>new Set((R?.tiles??[]).flatMap(C=>C.restricted&&C.query?[In(C.query)]:[])),[R]),{reports:W,settled:B}=Yf(t,n,i),X=S.useMemo(()=>W.map(C=>C.path).filter(C=>!!C&&C!==r&&C.endsWith(".malloy")).map(C=>C.replace(/\.malloy$/,"")),[W,r]),J=l0({environmentName:t,packageName:n,...i!==void 0?{versionId:i}:{},modelPath:r,reports:W,reportsSettled:B}),re=S.useMemo(()=>e?(J?.sources??[]).filter(C=>(C.visibleIn??C.exporters??[C.modelPath]).includes(D)).map(C=>C.name):void 0,[J,e,D]),ee=S.useMemo(()=>J&&re?{sources:J.sources.filter(C=>re.includes(C.name))}:J,[J,re]),[N,Z]=S.useState(s.document);S.useEffect(()=>Z(s.document),[s.document]);const pe=S.useMemo(()=>a&&(async(C,te)=>{await a(C,te.document.layout),v==="package"&&x(te.document.tiles.length>0)}),[a,v]),ne=S.useMemo(()=>(R?.givens??[]).filter(C=>!(e&&C.secure===!0)&&!(C.name!==void 0&&T.has(C.name))),[R,T,e]),Q=S.useMemo(()=>new Set([...ne.map(C=>C.name).filter(C=>C!==void 0),...Object.keys(z??{})]),[ne,z]),Se=S.useMemo(()=>new Map((R?.tiles??[]).flatMap(C=>C.kind!=="text"&&C.query&&C.givenNames?[[In(C.query),C.givenNames]]:[])),[R]),be=S.useMemo(()=>i0(N,s.document,Se),[N,s.document,Se]),G=S.useMemo(()=>r0(N,ne,be),[N,ne,be]),$e=S.useMemo(()=>{const C=new Set(N.tiles.flatMap(oe=>de(oe)?(oe.filters??[]).map(kt=>kt.given):[])),te=new Set((N.localGivens??[]).map(oe=>oe.name)),K=[...new Set(N.imports.map(oe=>oe.from))],se=K.length===1?f0(r,K[0]):K.length===0&&e?e.modelPath:void 0,me=oe=>{const kt=N.sources.filter(Ot=>Ot.scopedBy?.includes(oe)).map(Ot=>Ot.name);return kt.length>0?{reason:`Applied to every tile on ${kt.join(", ")} by this report's own source. Edit the file to change it.`}:te.has(oe)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:se!==void 0?{reason:`Set in the model ${se}. Edit the model to change it.`,modelPath:se}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...be].filter(oe=>!C.has(oe)).map(oe=>[oe,me(oe)]))},[N,be,e,r]),{declaredTypes:he,applied:ie,panel:Ne}=Vf({specs:G,loaded:A,startingValues:R?.startingGivens,documentKey:`${t}/${n}/${i??""}/${r}/edit`,autorun:R?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?D:R?.path,versionId:i,documentName:r,...U!==void 0?{preamble:U}:{},...z?{hostGivens:z}:{}}),Ke=S.useMemo(()=>Xf(G,ie,z),[G,ie,z]),He=S.useMemo(()=>Object.fromEntries(Object.entries(z??{}).filter(([C])=>!he.has(C))),[z,he]),Ge=!b||A||L,Ye=e!==void 0&&(O.problem!==void 0||j.isError||_.length>0),M=S.useMemo(()=>new Map(s.document.tiles.map(C=>[Ie(C),C])),[s.document]),I=S.useMemo(()=>function(C,te,K="card"){if(Ye)return m.jsxs(eo,{chrome:K,children:[m.jsx(to,{title:te?.title??Nn(C),subtitle:te?te.subtitle:C.subtitle}),m.jsx(fe,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!Ge)return m.jsxs(eo,{chrome:K,children:[m.jsx(to,{title:te?.title??Nn(C),subtitle:te?te.subtitle:C.subtitle}),m.jsx(Qs,{text:"Running…"})]});const se=Se.get(In(`${C.source} -> ${C.name}`)),me=U===void 0&&se!==void 0&&u0(M.get(Ie(C)),C)?{expression:`${C.source} -> ${C.name}`,givenNames:[...se],reads:[...se]}:a0(N,C,Q,ie,se);return m.jsx(xl,{environmentName:t,packageName:n,versionId:i,modelPath:D,...U!==void 0?{preamble:U}:{},...F.has(In(`${C.source} -> ${C.name}`))?{restricted:!0}:{},tile:me.expression,...me.annotation?{annotation:me.annotation}:{},label:Nn(C),chrome:K,subtitle:C.subtitle,...te?{heading:te}:{},borderless:C.borderless,givens:ie,hostGivens:He,declaredTypes:he,givenNames:me.givenNames,...(()=>{const oe=Qf(Ke,me.reads??me.givenNames);return oe.length>0?{waitingFor:ep(oe)}:{}})(),ignoredFilters:Zf(me.reads,G),height:Jf})},[N,M,Ge,Ye,Ke,Q,Se,t,n,i,D,U,F,ie,He,he,G]),q=S.useMemo(()=>function(C){return m.jsx(xl,{environmentName:t,packageName:n,versionId:i,modelPath:C.modelPath,tile:`${C.base} -> ${C.view}`,...C.chart?{annotation:cn(C.chart,C.chartCarried)}:{},label:C.label,borderless:!0,givens:ie,hostGivens:He,declaredTypes:he,givenNames:C.givens,height:200})},[t,n,i,ie,He,he]);return m.jsxs(tt,{sx:{gap:1},children:[e&&_.length>0&&m.jsxs(it,{severity:"error",children:["The server could not compile this document:"," ",_.map(C=>C.message).join("; ")]}),Ke.length>0&&!Ye&&m.jsx(it,{severity:"info",children:tp(Ke)}),e&&O.problem!==void 0&&m.jsxs(it,{severity:"error",children:["This document could not be prepared to compile:"," ",O.problem]}),e&&j.isError&&m.jsxs(it,{severity:"error",children:["The server could not compile this document:"," ",j.error?.message]}),m.jsx(Xh,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:s.source,document:s.document,fixedFilters:$e,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:I,renderViewPreview:q,givens:G.filter(C=>C.name!==void 0).map(C=>({name:C.name,...C.label?{label:C.label}:{},...C.type?{type:C.type}:{},...C.suggest?.dimension?{field:C.suggest.dimension}:{}})),onChange:Z,onDirtyChange:d,...f?{onExit:f}:{},...c?{onOpenModel:c}:{},...l?{onControlsChange:l}:{},...u!==void 0?{draftKey:u}:{},...p!==void 0?{allowLayoutChange:p}:{},...ee?{catalog:ee}:{},dashboards:X,...g?{onEvent:g}:{},controls:A?m.jsx(np,{...Ne,layout:"bar"}):void 0,...pe?{onSave:pe}:{},savesTo:v,...y?{saveLabel:y}:{},...o!==void 0?{replaces:o}:{},modelPath:r,...e?{visibleSources:re}:{}}),m.jsx(H,{sx:{px:.5},children:m.jsx(fe,{variant:"caption",sx:{opacity:.7},children:k})})]})}function u0(e,t){return e!==void 0&&JSON.stringify(Ec(e))===JSON.stringify(Ec(t))}function Ec(e){const{label:t,subtitle:n,colspan:r,break:i,borderless:s,...o}=e;return o}function h0(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 f0(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 p0({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 y=!1;return v(void 0),(async()=>{try{const k=Nf(await e.listWorkspaces(!1));if(y)return;if(a(k),k!==void 0&&(!n||k.authoritative)){const h=await e.getDocument(Rc(t,k.name,r,i,s)).catch(b=>{if(!Pc(b))throw b});if(y)return;f(h),p(h!==void 0)}}catch(k){if(y)return;v(Ic(k))}y||l(!0)})(),()=>{y=!0}},[e,t,n,r,i,s]),{workspace:o,draft:d,setDraft:f,draftChecked:c,offered:u,setOffered:p,readFailure:g}}const m0=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function g0(e){const t=await Zo(e);return Jo(t)?{ok:!1,reason:m0(t.reason,t.line)}:{ok:!0,document:t.document}}const v0="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",b0="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function x0({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 y=S.useRef((G,$e)=>{try{g.current?.(Lf(G,{...v.current,...$e?{layout:$e}:{}}))}catch{}}),k=e?.authoritative===!0,h=k&&r!==void 0,[b,x]=S.useState(void 0),w=(k||b===!0)&&t!==void 0,[$,E]=S.useState(void 0),[D,O]=S.useState(l?v0:void 0),j=S.useRef(void 0),P=S.useRef(void 0),[R,A]=S.useState(void 0),L=S.useRef(s);L.current=s;const U=R!==void 0&&R.onFetch===s?R.text:i,_=S.useRef(U);_.current=U;const T=w?t:U,[z,F]=S.useState(!1),[W,B]=S.useState(void 0),[X,J]=S.useState(void 0),re=T!==void 0&&T!==X,ee=$?.source,N=re&&(z||!k&&t!==void 0&&ee===t&&t!==U)&&ee!==void 0&&T!==W,Z=N?ee:re?T:ee??T,pe=N?T:void 0,ne=S.useRef(ee);ne.current=ee;const Q=S.useRef(T);Q.current=T;const Se=S.useRef("package");Se.current=w?k?"record":"draft":"package",S.useEffect(()=>{if(Z===void 0||!n||h||Z===ne.current)return;let G=!1;const $e=_.current,he=Q.current;return g0(Z).then(ie=>{if(!G){if(ie.ok===!1){O(ie.reason),y.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}O(void 0),j.current=void 0,P.current=$e,A(void 0),B(void 0),J(he),E(Ne=>({source:Z,document:ie.document,...$e!==void 0?{packageText:$e}:{},generation:(Ne?.generation??0)+1})),y.current({type:"report.opened",surface:"edit",from:Se.current,tiles:ie.document.tiles.length,durationMs:Lt()-p.current},ie.document.layout)}}).catch(ie=>{if(G)return;const Ne=`Could not read the ${c}: ${ie instanceof Error?ie.message:String(ie)}`;O(Ne),y.current({type:"report.load_failed",surface:"edit",category:Oc(ie)})}),()=>{G=!0}},[Z,a,n,h,f,c,u,p]),S.useEffect(()=>{l&&y.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[l]),S.useEffect(()=>{!u||!n||$||r!==void 0||(k?t===void 0&&O("the host's storage has no document at this location."):O("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,$,r,k,t]);const be=f&&!u&&!$&&n&&!w&&o&&i===void 0;return S.useEffect(()=>{be&&(O(b0),y.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[be]),{authoritative:k,blockedOnRecord:h,resume:b,setResume:x,fromDraft:w,opened:$,setOpened:E,openError:D,savedHashRef:j,packageBaseRef:P,setWrote:A,fetchedAtRef:L,setDirty:F,setSeen:J,held:pe,choose:G=>{p.current=Lt(),B(G?t:U),x(G)},acceptHeld:()=>{p.current=Lt(),B(pe)}}}function y0({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:y,setDraft:k,setOffered:h,setSeen:b,setWrote:x,savedHashRef:w,packageBaseRef:$,fetchedAtRef:E}){const D=S.useCallback(F=>t===void 0?void 0:Rc(F,t.name,i,s,o),[t,i,s,o]),O=D(n),j=S.useCallback(async(F,W=n)=>{const B=D(W);if(!e||!B)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(B,F),y(X=>X&&{...X,source:F}),k(F),(p||g===!0)&&b(F),p||v(X=>X??!1)},[e,D,n,p,g,y,k,b,v]),[P,R]=S.useState(void 0),A=S.useCallback(async F=>{const W=await Ff(w.current,$.current);if(W===void 0)throw new Error("The package file is still loading; try again.");const B=["dashboard-editor-model",i,s,o,a,r];await Bf({apiClients:d,queryClient:f,environmentName:i,packageName:s,modelPath:o,source:F,expectedHash:W,invalidateOnError:[B],afterWrite:async X=>{if(y(J=>J&&{...J,source:F}),x({text:F,onFetch:E.current}),b(F),w.current=X,R(void 0),e&&O)try{await e.deleteDocument(O),k(void 0),h(!1)}catch(J){Pc(J)?(k(void 0),h(!1)):R(Ic(J))}v(!1)},invalidate:[{queryKey:B,wait:!0},{queryKey:Sp({environmentName:i,packageName:s,versionId:a,modelPath:o})}]}),_f(f,i,s,o)},[d,i,s,o,a,r,e,O,f,w,$,E,y,x,b,k,h,v]),L=t?.writeable===!0,U=c===!0&&!l,{savesTo:_,pinnedPackageSave:T,writer:z}=kp({authoritative:p,mutable:U,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!O&&L&&(!r||p),readFailed:u!==void 0});return{save:z==="storage"?j:z==="package"?A:void 0,savesTo:_,writer:z,pinnedPackageSave:T,takesWrites:U,supersedeFailure:P}}function Jh(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:i,onOpenModel:s,onControlsChange:o,keepDraft:a,kind:d,path:f,textSource:c,allowLayoutChange:l}=e,u=e.layout??(d?bf(d):"grid"),p=u==="linear",g=c!==void 0,{environmentName:v,packageName:y,versionId:k,namesBoth:h}=xf(e),b=("resourceUri"in e?e.dashboard:e.dashboardName)??yf(f)??"",x="report",{apiClients:w,mutable:$,isLoadingStatus:E,server:D}=ra(),O=wf(),j=S.useRef(Lt()),P=S.useRef(t);P.current=t;const R=S.useRef(r);R.current=r;const A=kf()?.documentStorage,L=f??Wf(d??"dashboard",b),U=/\.malloynb$/i.test(L)||p&&/\.malloynb$/i.test(b),_=ia({queryKey:["dashboard-editor-model",v,y,L,k,p],queryFn:()=>w.models.getModel(v,y,L,k,p?!0:void 0),enabled:h&&!U&&!g}),T=_.data?.data?.sourceText,{workspace:z,draft:F,setDraft:W,draftChecked:B,offered:X,setOffered:J,readFailure:re}=p0({storage:A,layout:u,notebook:p,environmentName:v,packageName:y,modelPath:L}),{authoritative:ee,blockedOnRecord:N,resume:Z,setResume:pe,fromDraft:ne,opened:Q,setOpened:Se,openError:be,savedHashRef:G,packageBaseRef:$e,setWrote:he,fetchedAtRef:ie,setDirty:Ne,setSeen:Ke,held:He,choose:Ge,acceptHeld:Ye}=x0({workspace:z,draft:F,draftChecked:B,readFailure:re,packageText:T,fetchedAt:_.dataUpdatedAt,packageSettled:_.isSuccess&&!_.isFetching,modelPath:L,layout:u,notebook:p,noun:x,legacyFormat:U,textHeld:g,startedAt:j,onEventRef:P}),{save:M,savesTo:I,writer:q,pinnedPackageSave:C,takesWrites:te,supersedeFailure:K}=y0({storage:A,workspace:z,layout:u,notebook:p,environmentName:v,packageName:y,modelPath:L,versionId:k,apiClients:w,queryClient:O,mutable:$,textHeld:g,readFailure:re,authoritative:ee,resume:Z,setResume:pe,setOpened:Se,setDraft:W,setOffered:J,setSeen:Ke,setWrote:he,savedHashRef:G,packageBaseRef:$e,fetchedAtRef:ie}),se=z?.name,me=S.useCallback(hr=>{P.current?.(Sf(hr,se))},[se]),oe=_.isError&&!Q,kt=S.useRef(!1);S.useEffect(()=>{!oe||kt.current||(kt.current=!0,sa({path:L,layout:u},P.current).emit({type:"report.load_failed",surface:"edit",category:Oc(_.error)}))},[oe,_.error,L,u]);const Ot=S.useCallback((hr,fi)=>{Ne(hr),R.current?.(fi)},[Ne]),Xt=a?Hf({server:D,environmentName:v,packageName:y,versionId:k,path:f??b}):void 0,cr=I==="host"&&z?.description?z.description:void 0,dr=!ee&&!g&&$===void 0?E?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":$f({authoritative:ee,mutable:te,pinnedPackageSave:C,...z?{workspace:z}:{},...re!==void 0?{readFailure:re}:{},...k!==void 0?{versionId:k}:{}}),Ms=I==="package"&&te===!0&&!C&&re===void 0||dr===cr?"":dr;if(!h&&"resourceUri"in e)return m.jsxs(it,{severity:"error",sx:{m:2},children:["A ",x," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(be)return m.jsxs(it,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened in the builder: ",be]});if(_.isError&&!Q)return m.jsx(jf,{error:_.error,context:`Opening the ${x}`});if(!Q&&(!(g||T)||!B))return n??m.jsx(Qs,{text:`Opening the ${x}…`});if(N)return m.jsxs(it,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened: ",re]});const ur=F!==void 0&&F!==T;return m.jsxs(tt,{sx:{gap:2},children:[_.isError&&m.jsxs(it,{severity:"warning",children:["The ",x," could not be re-read from the server:"," ",_.error?.message,". Your edits are still here."]}),!p&&!ee&&X&&ur&&Z===void 0&&m.jsx(it,{severity:"info",action:m.jsxs(tt,{direction:"row",sx:{gap:1},children:[m.jsx(ke,{size:"small",onClick:()=>Ge(!0),children:"Resume"}),m.jsx(ke,{size:"small",onClick:()=>Ge(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),He!==void 0&&m.jsx(it,{severity:"warning",action:m.jsx(ke,{size:"small",onClick:()=>{Xt!==void 0&&Cf(Xt),Ye()},children:"Load it"}),children:I==="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.":I==="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."}),K!==void 0&&m.jsxs(it,{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:"," ",K]}),!Q&&(n??m.jsx(Qs,{text:`Opening the ${x}…`})),Q&&m.jsx(d0,{environmentName:v,packageName:y,modelPath:L,...c?{textSource:c}:{},slug:b,...k!==void 0?{versionId:k}:{},opened:Q,...ne&&q==="package"&&Q.packageText!==void 0?{replaces:Q.packageText}:{},onSave:M,onDirtyChange:Ot,...i?{onExit:i}:{},...s?{onOpenModel:s}:{},...o?{onControlsChange:o}:{},...Xt!==void 0?{draftKey:Xt}:{},...l!==void 0?{allowLayoutChange:l}:{},savesTo:I,...cr?{saveLabel:cr}:{},...t?{onEvent:me}:{},note:Ms},Q.generation)]})}const j0=Jh,C0=Xh;function M0(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(Jh,{...s,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:kl===void 0&&(kl={});export{$0 as BuilderBar,C0 as DashboardBuilder,j0 as DashboardEditor,T0 as MAX_SLUG_ATTEMPTS,M0 as NotebookEditor,Xh as ReportBuilder,Jh as ReportEditor,Ry as buildCatalog,D0 as createDocument,A0 as createRoute,Rc as locatorFor,R0 as newDashboardSource,P0 as newDocumentProblem,I0 as newNotebookSource,Zo as readDashboardDocument,Jo as readFailed,S0 as readReportTagOfText,z0 as reportPathFor,W0 as reportPathForTitle,N0 as slugFor,L0 as slugOrFallback,oy as spliceDashboardDocument,Qo as spliceFailed,F0 as useDocumentChoices};
|