@malloy-publisher/app 0.9.14 → 0.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-doc.yaml +33 -10
- package/dist/assets/{EnvironmentPage-C0Y7JsgF.js → EnvironmentPage-BfcAd2yi.js} +1 -1
- package/dist/assets/{HomePage-B3LsCOlr.js → HomePage-Ci_5k81i.js} +1 -1
- package/dist/assets/{MainPage-BCDlscxh.js → MainPage-D3QeyfA0.js} +1 -1
- package/dist/assets/{ModelPage-DGXivK0m.js → ModelPage-Bpeml30i.js} +2 -2
- package/dist/assets/PackagePage-C9Ptmg2y.js +1 -0
- package/dist/assets/RenderedResult-DxmHGZNQ.es-D0Ona1d0.js +171 -0
- package/dist/assets/{RouteError-1Eclkzb_.js → RouteError-C8LT19mj.js} +1 -1
- package/dist/assets/{ThemeEditorPage-loRmpKoQ.js → ThemeEditorPage-CynRJmSm.js} +1 -1
- package/dist/assets/{ToggleButtonGroup-CnciHZDP.js → ToggleButtonGroup-ChqidtS2.js} +1 -1
- package/dist/assets/{documentRoutes-e6eAjpuN.js → documentRoutes-DZ-IkgZk.js} +1 -1
- package/dist/assets/{editPageMounted-BiGObPJ4.js → editPageMounted-BaIkidNI.js} +2 -2
- package/dist/assets/{index-Bp7WJqoi.js → index-CIAQd_g-.js} +1 -1
- package/dist/assets/{index-1Jwtzdx_.js → index-CtRRADnY.js} +1 -1
- package/dist/assets/{index-Dnzp7ChL.js → index-Cu8EElmh.js} +1 -1
- package/dist/assets/index-Dzz5PLbw.js +481 -0
- package/dist/assets/index.es-DvW5H23D.js +144 -0
- package/dist/index.html +1 -1
- package/package.json +2 -2
- package/dist/assets/PackagePage-BBvnnh9f.js +0 -1
- package/dist/assets/RenderedResult-DnBtf-cI.es-Bs8KIO86.js +0 -153
- package/dist/assets/index-B_gOHtqJ.js +0 -481
- package/dist/assets/index.es-396NBJA3.js +0 -143
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import{g as tf,b as nf,r as S,u as rf,b6 as sf,k as of,i as af,b7 as lf,l as cf,j as m,f as df,h as uf,s as ta,m as hf,t as gl,Z as ff,V as Ve,b8 as Yt,b9 as hs,aD as tt,ae as Je,L as St,K as Fn,ba as Fr,ak as Me,bb as na,bc as Jr,bd as Fi,be as pf,bf as mf,bg as gf,bh as vf,bi as bf,T as pe,as as it,bj as xf,bk as yf,bl as wf,O as ra,aK as kf,bm as Lt,bn as Sf,bo as ia,bp as $f,bq as Mc,br as Ec,bs as jf,bt as Cf,a0 as Zs,bu as Mf,bv as Ef,bw as vl,bx as hi,aX as Oc,B as Dc,by as Le,I as V,aJ as vt,bz as ot,bA as sa,bB as Of,bC as In,bD as Df,ag as Af,bE as Tf,bF as Rf,bG as Pf,bH as If,bI as zf,bJ as Ac,bK as Wf,bL as Nf,bM as Tc,bN as Rc,bO as Pc,bP as Lf,bQ as Ff,bR as Bf,bS as _f,bT as Vf,bU as qf,bV as Hf,bW as Uf,bX as Gf,F as Kf,bY as Yf,bZ as Xf,b_ as Js,b$ as Qs,c0 as bl,c1 as Zf,c2 as Jf,c3 as Qf,c4 as ep,c5 as cn,c6 as tp,c7 as np,c8 as rp,c9 as Ic,ca as oa,cb as ip,cc as sp,cd as zc,ce as op,cf as ap,cg as lp,ch as aa,ci as Ht,cj as cp,ck as dp,cl as Wc,cm as up,cn as hp,aP as la,aF as Ft,co as eo,cp as fp,cq as pp,Y as Bi,X as mp,cr as gp,cs as vp,ct as to,cu as bp,cv as xp,cw as yp,cx as Nc,cy as wp,G as kp,cz as Sp,cA as $p,cB as jp,cC as Cp,cD as ca,cE as Mp,cF as da,aT as Ep,cG as Op,cH as Dp,cI as Ap,cJ as Tp,cK as Rp,cL as bn,cM as xl,cN as yl,cO as Os,cP as Pp,S as Ip,cQ as zp,cR as Wp,cS as Np,cT as Lp,cU as Lc,aj as Fp}from"./index-B_gOHtqJ.js";import{cV as D0,cW as A0,cX as T0,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-B_gOHtqJ.js";import{T as Fc,a as no}from"./ToggleButtonGroup-CnciHZDP.js";function Bp(e){return tf("MuiCollapse",e)}nf("MuiCollapse",["root","horizontal","vertical","entered","hidden","wrapper","wrapperInner"]);const _p=e=>{const{orientation:t,classes:n}=e,r={root:["root",`${t}`],entered:["entered"],hidden:["hidden"],wrapper:["wrapper",`${t}`],wrapperInner:["wrapperInner",`${t}`]};return uf(r,Bp,n)},Vp=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]}})(hf(({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"}}]}))),qp=ta("div",{name:"MuiCollapse",slot:"Wrapper"})({display:"flex",width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),Hp=ta("div",{name:"MuiCollapse",slot:"WrapperInner"})({width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),ro=S.forwardRef(function(t,n){const r=rf({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=sf.standard,TransitionComponent:x=of,...w}=r,$={...r,orientation:k,collapsedSize:a},M=_p($),A=af(),j=lf(),C=S.useRef(null),I=S.useRef(),T=typeof a=="number"?`${a}px`:a,R=k==="horizontal",N=R?"width":"height",H=S.useRef(null),B=cf(n,H),D=L=>J=>{if(L){const re=H.current;J===void 0?L(re):L(re,J)}},W=()=>C.current?C.current[R?"clientWidth":"clientHeight"]:0,F=D((L,J)=>{C.current&&R&&(C.current.style.position="absolute"),L.style[N]=T,l&&l(L,J)}),z=D((L,J)=>{const re=W();C.current&&R&&(C.current.style.position="");const{duration:ce,easing:ee}=gl({style:h,timeout:b,easing:f},{mode:"enter"});if(b==="auto"){const we=A.transitions.getAutoHeightDuration(re);L.style.transitionDuration=`${we}ms`,I.current=we}else L.style.transitionDuration=typeof ce=="string"?ce:`${ce}ms`;L.style[N]=`${re}px`,L.style.transitionTimingFunction=ee,p&&p(L,J)}),_=D((L,J)=>{L.style[N]="auto",u&&u(L,J)}),Q=D(L=>{L.style[N]=`${W()}px`,g&&g(L)}),G=D(v),ne=D(L=>{const J=W(),{duration:re,easing:ce}=gl({style:h,timeout:b,easing:f},{mode:"exit"});if(b==="auto"){const ee=A.transitions.getAutoHeightDuration(J);L.style.transitionDuration=`${ee}ms`,I.current=ee}else L.style.transitionDuration=typeof re=="string"?re:`${re}ms`;L.style[N]=T,L.style.transitionTimingFunction=ce,y&&y(L)}),Z=L=>{b==="auto"&&j.start(I.current||0,L),i&&i(H.current,L)};return m.jsx(x,{in:c,onEnter:F,onEntered:_,onEntering:z,onExit:Q,onExited:G,onExiting:ne,addEndListener:Z,nodeRef:H,timeout:b==="auto"?null:b,...w,children:(L,{ownerState:J,...re})=>m.jsx(Vp,{as:d,className:df(M.root,o,{entered:M.entered,exited:!c&&T==="0px"&&M.hidden}[L]),style:{[R?"minWidth":"minHeight"]:T,...h},ref:B,ownerState:{...$,state:L},...re,children:m.jsx(qp,{ownerState:{...$,state:L},className:M.wrapper,ref:C,children:m.jsx(Hp,{ownerState:{...$,state:L},className:M.wrapperInner,children:s})})})})});ro&&(ro.muiSupportAuto=!0);var wl={};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"})),Up=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 Vc(e){const{theme:t}=Ve(),n=t.ui,[r,i]=S.useState(null),{status:s,draftKeptAt:o,discard:a,restored:d,dismissRestored:f}=e,c=d!==void 0&&!d.pending&&s==="unsaved"?d:void 0,l=s==="saved"?"Saved":s==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",u=c?`Restored your unsaved edits from ${io(c.savedAt)}`:void 0,p=s==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,g=a!==void 0&&s==="unsaved",v=()=>{i(null),c&&f?.()},y=b=>({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"?b.palette.text.secondary:b.palette.text.primary,transition:`color ${Le}, background-color ${Le}`,...g?{"&:hover":{bgcolor:b.palette.action.hover}}:{}}),k=m.jsxs(m.Fragment,{children:[m.jsx(V,{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(V,{component:"span","data-restored":c?"true":void 0,sx:b=>({width:7,height:7,borderRadius:"50%",bgcolor:c?t.accent:s==="saving"||o!==void 0?b.palette.text.disabled:b.palette.warning.main,transition:`background-color ${Le}`})})}),m.jsx(V,{component:"span","aria-hidden":!0,children:l}),m.jsx(na,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:g?"visible":"hidden"}})]}),h=m.jsx(V,{component:"span",role:"status","aria-live":"polite",sx:Gp,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[h,m.jsx(St,{title:u??p,describeChild:!0,children:g?m.jsx(Dc,{className:Je.saveStatus,"aria-label":l,...u?{"aria-description":u}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:b=>i(b.currentTarget),sx:y,children:k}):m.jsx(V,{component:"span",className:Je.saveStatus,sx:y,children:k})}),m.jsxs(Fi,{className:Je.menu,anchorEl:r,open:r!==null,onClose:v,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${Yt(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(u!==void 0||o!==void 0)&&m.jsx(V,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:u??`Kept in this browser at ${io(o)}`}),m.jsxs(vt,{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(Up,{fontSize:"small"}),"Discard edits"]})]})]})}function io(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 Gp={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},so=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),dn=so?"⌘":"Ctrl+",kl=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Ds=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function Kp(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(kl(s.target)||Ds(s.target))return;o.escape();return}if(kl(s.target)){if(a&&d==="s"){if(s.preventDefault(),!o.save||Ds(s.target))return;s.target.blur(),r(!0)}return}if(Ds(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 Ar=(e,t,n=sa)=>({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}}}),_i=(e=sa)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),Vi={height:20,alignSelf:"center",mx:.5,my:0},qi=(e,t=sa)=>({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 Yp({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,saveStatus:p}){const{theme:g}=Ve(),v=Yt(g.cardBorder),y=hs(g.cardBorder,g.tileTitle);return m.jsxs(tt,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[l&&m.jsx(Me,{variant:"outlined",startIcon:m.jsx(Jr,{}),onClick:l,"aria-label":"Add tile",sx:Ar(v,y,g.ui),children:"Tile"}),l&&m.jsx(Fr,{orientation:"vertical",sx:Vi}),m.jsx(St,{title:`Undo (${dn}Z)`,children:m.jsx("span",{children:m.jsx(Fn,{"aria-label":"Undo",disabled:!e,onClick:n,sx:_i(g.ui),children:m.jsx(_c,{fontSize:"small"})})})}),m.jsx(St,{title:`Redo (${dn}⇧Z)`,children:m.jsx("span",{children:m.jsx(Fn,{"aria-label":"Redo",disabled:!t,onClick:r,sx:_i(g.ui),children:m.jsx(Bc,{fontSize:"small"})})})}),(c||o||u)&&m.jsx(Fr,{orientation:"vertical",sx:Vi}),c,o&&p&&m.jsx(Vc,{...p}),o?m.jsx(St,{title:i?`Save (${dn}S) · ${d??oo[a]}`:d??oo[a],children:m.jsx("span",{children:m.jsx(Me,{ref:f,variant:i?"contained":"outlined",disabled:!i||s,onClick:o,sx:{...Ar(v,y,g.ui),minWidth:88},children:s?"Saving…":i?"Save":"Saved"})})}):null,o&&m.jsx(V,{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(kp,{label:"Close",icon:m.jsx(aa,{}),onClick:u})]})}const Xp={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function qc(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:Xp[i],...s?{disabled:!0,reason:s}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Sl(e){return e.description??Wp(e.name)}const Zp={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"},fi=(e,t)=>`${e}\0${t}`;function Jp({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o,renderPreview:a}){const{theme:d}=Ve(),f=d.ui,c=Yt(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 D=new Set(t.sources.map(W=>W.base));return[...l].sort((W,F)=>Number(D.has(F.name))-Number(D.has(W.name)))},[l,t]),$=w.filter(D=>D.views.length>0),M=w.filter(D=>D.views.length===0),A=S.useMemo(()=>new Map($.flatMap(D=>D.views.map(W=>[fi(D.name,W.name),{source:D,view:W,key:fi(D.name,W.name)}]))),[$]),j=S.useMemo(()=>$.map(D=>({key:D.name,label:D.name,...D.description?{detail:D.description}:{},entries:D.views.map(W=>({key:fi(D.name,W.name),name:W.name,title:Sl(W),...W.chart?{chart:W.chart}:{}}))})),[$]),C=g===void 0?void 0:A.get(g);S.useEffect(()=>{if(!e)return;p(""),k(""),b("default");const D=$[0]?.views[0];v(D&&$[0]?fi($[0].name,D.name):void 0)},[e]);const I=C?[C.source.name,C.view.name].filter(D=>!to(D)).map(D=>`"${D}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,T=C!==void 0&&I===void 0,R=C?Sl(C.view):"",N=h!=="default"&&C?{chart:h,chartCarried:C.view.chart?[C.view.chart]:[]}:{},H=(D=C)=>{if(!D||![D.source.name,D.view.name].every(to))return;const W=D.key===C?.key;s({base:D.source.name,modelPath:D.source.modelPath,...D.source.exporters?{exporters:D.source.exporters}:{},view:D.view.name,...W&&y.trim()?{label:y.trim()}:{},...W?N:{},colspan:Math.ceil(r/2)})},B=C?qc(C.view,h).filter(D=>D.value!=="custom"&&D.disabled!==!0):[];return m.jsx(la,{className:`${Je.dialog} ${Je.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(Me,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx(Me,{onClick:i,children:"Cancel"}),m.jsx(Me,{variant:"contained",disabled:!T,onClick:()=>H(),children:"Add tile"})]}),children:m.jsxs(V,{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(V,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(bp,{groups:j,query:u,onQuery:p,picked:C?.key,onPick:D=>{v(D),b("default")},onTake:D=>H(A.get(D)),searchRef:x,empty:m.jsx(pe,{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:M.length>0&&m.jsxs(pe,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",M.map(D=>D.name).join(", "),"."]})})}),m.jsx(V,{sx:D=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${D.palette.text.primary} 3%, ${D.palette.background.paper})`}),children:C?m.jsxs(m.Fragment,{children:[m.jsx(V,{"aria-label":"Preview",role:"region",sx:D=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${c}`,bgcolor:D.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${D.palette.background.paper})`}}),children:a?m.jsx(V,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:C.source.name,modelPath:C.source.modelPath,view:C.view.name,label:y.trim()||R,...h!=="default"?N:{},givens:C.source.givens})}):m.jsxs(V,{sx:D=>({flex:1,border:`1px solid ${c}`,borderRadius:f.radius.tile,bgcolor:D.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(xp,{chart:C.view.chart}),m.jsxs(pe,{variant:"body2",children:[C.source.name," → ",C.view.name]})]})}),m.jsx(Ft,{size:"small",label:"Title",placeholder:R,value:y,onChange:D=>k(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs(V,{children:[m.jsx(pe,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx(Fc,{size:"small",exclusive:!0,value:h,"aria-label":"Chart",onChange:(D,W)=>{W!==null&&b(W)},sx:{...qi(c,f),"& .MuiToggleButton-root":{...qi(c,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:B.map(D=>m.jsx(no,{value:D.value,children:D.label},D.value))}),m.jsx(pe,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:C.view.chart?`The view declares ${Zp[C.view.chart]??"a chart"}.`:"The view declares no chart, so it shows as a table."})]}),I&&m.jsx(pe,{variant:"body2",color:"error",children:I})]}):m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const Ae=e=>e.kind==="text",ue=e=>e.kind!=="text",ur=e=>ue(e)?e.label??e.name:e.name,ze=e=>Ae(e)?`text.${e.name}`:`${e.source}.${e.name}`;function Qp(e,t,{modelPath:n,textHeld:r,widths:i,insertAt:s}){t.modelPath&&!r&&(e.imports=Pp(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Hc(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 Hc(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(ue).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 Hi(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 em(e,t){const n=e.tiles[t];if(!n||!ue(n)||Hi(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)??Hc(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 pi="self";function tm({open:e,document:t,source:n,givenNames:r,dashboards:i,tileLabel:s,onClose:o,onApply:a}){const{theme:d}=Ve(),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 M={...w};return b(M),M})),p=[pi,...i.filter(h=>h!==pi)],g=h=>h===pi?"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=Yt(d.cardBorder),k=(h,b)=>u(h,x=>{b?x.to=x.lastTo?.length?x.lastTo:[pi]:(x.lastTo=x.to,x.to=[])});return m.jsx(la,{className:`${Je.dialog} ${Je.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[s&&m.jsxs(V,{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(Me,{onClick:o,children:"Cancel"}),m.jsx(Me,{variant:"contained",onClick:v,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx(pe,{variant:"body2",sx:{color:d.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx(V,{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(V,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx(V,{role:"list","aria-label":"Dimensions",children:c.map((h,b)=>{const x=h.to.length>0;return m.jsxs(V,{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(V,{sx:{minWidth:0},children:[m.jsx(V,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:nm(h.name)}),m.jsxs(V,{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(V,{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 M=w.target.value,A=Array.isArray(M)?M:String(M).split(",").filter(Boolean);A.length===0&&($.lastTo=$.to),$.to=A}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:p.map(w=>m.jsxs(vt,{value:w,children:[m.jsx(eo,{size:"small",checked:h.to.includes(w),sx:{p:0,mr:1}}),m.jsx(Bi,{primary:g(w)})]},w))}),m.jsx(V,{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(vt,{value:"",children:m.jsx(Bi,{primary:h.name,secondary:"Named like the dimension"})}),r.map(w=>m.jsx(vt,{value:w,children:w},w))]})]}):m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},h.name)})})})}function nm(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const rm=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"})),im=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"})),sm=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"})),om=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"})),am=ot(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),lm=ot(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function cm(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of ue(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 Ui(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function dm(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function Tr(e,t){const n=dm(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 um(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const hm=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function fm(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=Lc(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 pm=[{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 pr(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=>ue(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function mm(e,t){return e.tiles.map(n=>{const r=(ue(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}:Ui(t.type)!==void 0?{op:Ui(t.type)}:{}}})}function gm(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 vm(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 bm(e,t){for(const r of e.tiles){if(!ue(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 xm({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([]),[$,M]=S.useState(!1),[A,j]=S.useState(!1),C=E=>t.sources.find(P=>P.name===E.source)?.base??E.source;S.useEffect(()=>{if(e)if(j(n!==void 0),n){l({kind:"existing",name:n.name}),p(n.label??"");const E=mm(t,n);w(E);const P=E.filter(O=>O.include),q=new Set(P.map(O=>O.field));b(q.size===1?P[0].field:n.field??""),M(q.size>1)}else l({kind:"new"}),p(""),v("select"),b(""),k(new Date().toISOString().slice(0,10)),w(t.tiles.map(E=>({include:co(E),field:""}))),M(!1)},[e,n,t]);const I=S.useMemo(()=>[...(t.localGivens??[]).map(E=>E.name),...r.map(E=>E.name),...i],[t,r,i]),T=S.useMemo(()=>h.trim()?fm(h.trim(),I):"",[h,I]),R=c.kind==="existing"?n??r.find(E=>E.name===c.name):T?{name:T,type:pr({name:T,label:u,kind:g,field:h}).type}:void 0,N=R?.type!==void 0&&!R.type.startsWith("filter<"),H=x.find(E=>E.include)?.op??Ui(R?.type),B=(E,P)=>{j(!0),w(q=>q.map((O,te)=>te===E?{...O,...P}:O))},D=E=>{j(!0),w(P=>P.map(q=>({...q,op:E})))},W=E=>{const P=Ui(E);w(q=>q.map(({op:O,...te})=>P?{...te,op:P}:te))},F=E=>{j(!0),l({kind:"existing",name:E.name}),b(E.field??""),W(E.type)},z=E=>{j(!0),v(E),W(pr({name:"X",label:u,kind:E,field:h}).type)},_=t.tiles.map(co),Q=_.filter(Boolean).length,G=x.filter((E,P)=>E.include&&_[P]).length,ne=t.tiles.filter((E,P)=>(x[P]?.include??!1)&&_[P]&&ue(E)),Z=ne.length>0?ne:t.tiles.filter((E,P)=>_[P]&&ue(E)),L=S.useMemo(()=>{const E=new Map;let P=!1;for(const q of Z){const O=s?.(q);if(O){P=!0;for(const te of O)E.has(te.name)||E.set(te.name,te)}}return P?[...E.values()]:void 0},[x,t.tiles,s]),J=(()=>{const E=h.trim();for(const P of ne){const q=s?.(P);if(!q||q.some(O=>O.name===E))return C(P)}return ne[0]?C(ne[0]):t.sources[0]?.base})(),re=E=>{j(!0),w(P=>P.map((q,O)=>({...q,include:E&&_[O]})))},ce=S.useMemo(()=>$?x:x.map(E=>({...E,field:h})),[$,x,h]),ee=E=>{for(const P of Z){const q=s?.(P)?.find(O=>O.name===E.trim());if(q?.type)return q.type}},we=E=>Tr(R?.type,E.type),me=(E,P)=>{if(E.trim()==="")return"Pick the field this filter compares.";const q=P?s?.(P):void 0;if(!q)return;const O=q.find(te=>te.name===E.trim());if(!O)return`Not a field of ${P?C(P):"the tiles' source"}.`;if(O.type&&!Tr(R?.type,O.type))return`${E.trim()} is ${lo(O.type)}; this filter compares ${lo(R?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},K=E=>{if(j(!0),b(E),f||c.kind!=="new")return;const P=ee(E),q=pr({name:"X",label:u,kind:g,field:E}).type;P&&!Tr(q,P)&&z(um(P))},ke=E=>{const P=t.tiles[E];return P&&ue(P)?P:void 0},fe=ce.map((E,P)=>E.include&&_[P]?me(E.field,ke(P)):void 0),le=fe.every(E=>E===void 0),Fe=A?fe:fe.map(()=>{}),Ge=A&&!$&&G>0?ne.map(E=>me(h,E)).find(Boolean):void 0,qe=R!==void 0&&le&&(c.kind==="existing"||h.trim()!==""&&T!==""),Ke=()=>{if(!(!R||!qe))if(c.kind==="new")o(R.name,ce,pr({name:R.name,label:u.trim()||uo(R.name),kind:g,field:h.trim(),...J?{source:J}:{},...y?{dateDefault:y}:{}}));else if(n?.origin==="dashboard"&&n.local){const E=u.trim(),P=E!==(n.local.label??"");o(R.name,ce,P?{...n.local,...E?{label:E}:{}}:void 0)}else o(R.name,ce)},Re=f&&d.origin==="model";return{editing:f,shown:d,fromModel:Re,source:c,setSource:l,label:u,setLabel:p,kind:g,dateDefault:y,setDateDefault:k,field:h,rows:x,setRows:w,perTile:$,setPerTile:M,newName:T,target:R,valueTyped:N,commonOp:H,setRow:B,setCommonOp:D,pickExisting:F,pickKind:z,bindable:_,bindableCount:Q,included:G,commonFields:L,setAll:re,accepts:we,pickField:K,rowProblems:Fe,commonProblem:Ge,canApply:qe,apply:Ke}}function $l({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(zp,{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(Cl,{type:g.get(y)}),m.jsx(pe,{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(V,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Cl,{type:g.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":s}}),sx:u})}const ym=e=>e&&ue(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 wm({open:e,document:t,control:n,available:r,takenNames:i,fieldsFor:s,onClose:o,onApply:a,onRemove:d}){const{theme:f}=Ve(),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:M,perTile:A,setPerTile:j,newName:C,target:I,valueTyped:T,commonOp:R,setRow:N,setCommonOp:H,pickExisting:B,pickKind:D,bindable:W,bindableCount:F,included:z,commonFields:_,setAll:Q,accepts:G,pickField:ne,rowProblems:Z,commonProblem:L,canApply:J,apply:re}=xm({open:e,document:t,control:n,available:r,...i?{takenNames:i}:{},fieldsFor:s,onApply:a}),ce=S.useRef(null),ee=Yt(f.cardBorder),we=hs(f.cardBorder,f.tileTitle),[me,K]=S.useState(!1),[ke,fe]=S.useState(!1);S.useEffect(()=>{e?fe(!0):K(!1)},[e]),S.useEffect(()=>{ke&&(fe(!1),K(l&&z<F))},[ke]),S.useEffect(()=>{A&&K(!0)},[A]);const le=_?.find(E=>E.name===w.trim())?.type,Fe=E=>{if(!le)return;const P=pr({name:"X",label:y,kind:E,field:w}).type;return Tr(P,le)?void 0:`${w.trim()} is ${lo(le)}, which this control cannot filter.`},Ge=y.trim()||(C?uo(C):"Filter"),qe=h==="number"?"Any":h==="date"?b?new Date(`${b}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ke={...qi(ee,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...qi(ee,c)["& .MuiToggleButton-root"],textTransform:"none"}},Re=(E,P,q)=>m.jsx(Ft,{select:!0,size:"small",label:"Compares",value:E??">=",onChange:O=>P(O.target.value),inputProps:{"aria-label":q},sx:{width:130},children:hm.filter(O=>O.op!=="~").map(O=>m.jsx(vt,{value:O.op,children:O.label},O.op))});return m.jsx(la,{className:`${Je.dialog} ${Je.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:ce},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs(V,{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(Me,{color:"error",startIcon:m.jsx(pp,{}),onClick:()=>d(u.name),sx:E=>({mr:"auto",color:fp(E)}),children:"Remove filter"}),m.jsx(Me,{onClick:o,children:"Cancel"}),m.jsx(St,{title:J||I===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx(Me,{variant:"contained",onClick:re,disabled:!J,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs(tt,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs(Fc,{exclusive:!0,size:"small",value:g.kind,onChange:(E,P)=>{P==="new"?v({kind:"new"}):P==="existing"&&r[0]&&B(r[0])},"aria-label":"Where the filter comes from",sx:Ke,children:[m.jsx(no,{value:"new",children:"New in this report"}),m.jsx(no,{value:"existing",children:"From the model"})]}),!l&&g.kind==="existing"?m.jsx(Ft,{select:!0,size:"small",label:"Filter",value:g.name,onChange:E=>{const P=r.find(q=>q.name===E.target.value);P&&B(P)},children:r.map(E=>m.jsxs(vt,{value:E.name,children:[E.label??E.name,m.jsxs(pe,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",E.name]})]},E.name))}):null,m.jsxs(V,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:p?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!A&&m.jsx($l,{value:w,onChange:ne,fields:_,accepts:G,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:ce,error:L!==void 0,helperText:L??(!l&&C?`Declared as $${C}`:void 0)}),!p&&m.jsx(Ft,{size:"small",label:"Label",placeholder:C?uo(C):"",value:y,onChange:E=>k(E.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),T&&!A&&Re(R,H,"Comparison"),!l&&g.kind==="new"&&m.jsxs(V,{children:[m.jsx(jl,{children:"Control"}),m.jsx(V,{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:pm.map(E=>{const P=E.kind===h,q=Fe(E.kind);return m.jsx(St,{title:q??E.hint,describeChild:!0,children:m.jsxs(Dc,{role:"radio","aria-checked":P,"aria-label":E.label,"aria-disabled":q!==void 0,onClick:()=>{q===void 0&&D(E.kind)},sx:O=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${P?f.accent:ee}`,boxShadow:P?`0 0 0 1px ${f.accent}`:"none",bgcolor:P?`color-mix(in srgb, ${f.accent} 6%, ${O.palette.background.paper})`:O.palette.background.paper,color:P?f.accent:O.palette.text.secondary,opacity:q?.45:1,cursor:q?"default":"pointer",transition:`border-color ${Le}, background-color ${Le}`,"&:hover":q||P?{}:{borderColor:we}}),children:[m.jsx(Sm,{kind:E.kind}),m.jsx(V,{component:"span",sx:{...c.type.caption,fontWeight:P?600:500,color:P?f.accent:"text.primary",textAlign:"center"},children:km[E.kind]})]})},E.kind)})}),h==="date"&&m.jsx(Ft,{size:"small",type:"date",label:"Starts at",value:b,onChange:E=>x(E.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs(V,{sx:{border:`1px solid ${ee}`,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(lm,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs(pe,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx(V,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:z===F&&F>0?`Applies to all ${z} tile${z===1?"":"s"}`:`Applies to ${z} of ${F} tile${F===1?"":"s"}`}),!A&&w.trim()!==""&&z>0&&m.jsxs(V,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx(V,{component:"span",sx:{...c.type.code},children:w.trim()})]})]}),!A&&m.jsx(Me,{size:"small","aria-expanded":me,onClick:()=>K(E=>!E),children:me?"Done choosing":"Choose tiles"})]}),m.jsx(ro,{in:me,unmountOnExit:!0,children:m.jsxs(V,{sx:{borderTop:`1px solid ${ee}`,px:.5,pb:1},children:[m.jsxs(tt,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx(eo,{size:"small",checked:F>0&&z===F,indeterminate:z>0&&z<F,disabled:F===0,onChange:E=>Q(E.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx(pe,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx(Me,{size:"small",onClick:()=>{A||M(E=>E.map(P=>({...P,field:w}))),j(E=>!E)},children:A?"Same field for all":"Adjust per tile"})]}),m.jsx(tt,{sx:{gap:A?1:0},children:t.tiles.map((E,P)=>{if(!ue(E))return null;const q=$[P],O=E.label??E.name,te=A?Z[P]:void 0;return m.jsxs(tt,{direction:"row",sx:{gap:1,alignItems:A?"flex-start":"center",opacity:W[P]?1:.6},children:[m.jsx(eo,{size:"small",disabled:!W[P],checked:(q?.include??!1)&&W[P],inputProps:{"aria-label":`Filter ${O}`},onChange:U=>N(P,{include:U.target.checked})}),m.jsx(pe,{variant:"body2",sx:{flex:1,minWidth:0,pt:A?1:0},noWrap:!0,children:O}),W[P]?A&&m.jsxs(m.Fragment,{children:[T&&Re(q?.op,U=>N(P,{op:U}),`Comparison for ${O}`),m.jsx($l,{value:q?.field??"",onChange:U=>N(P,{field:U}),fields:s?.(E),accepts:G,label:"Field",ariaLabel:`Field for ${O}`,disabled:!q?.include,error:te!==void 0,helperText:te,sx:{width:220,pr:1}})]}):m.jsx(pe,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:ym(t.tiles[P]).reason})]},`${E.source}.${E.name}`)})})]})})]}),z===0&&m.jsx(pe,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!p&&m.jsxs(V,{children:[m.jsx(jl,{children:"Preview"}),m.jsx(V,{sx:E=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:E.palette.action.hover}),children:m.jsxs(V,{"aria-hidden":!0,sx:E=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${ee}`,bgcolor:E.palette.background.paper,...c.type.control}),children:[m.jsx(V,{component:"span",sx:{color:"text.secondary"},children:Ge}),m.jsx(V,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:qe}),m.jsx(na,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function jl({children:e}){const t=Ve().theme.ui;return m.jsx(pe,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const km={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function Sm({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(rm,{sx:t});case"multiselect":return m.jsx(im,{sx:t});case"text":return m.jsx(am,{sx:t});case"number":return m.jsx(om,{sx:t});case"date":return m.jsx(sm,{sx:t})}}function Cl({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=Ve().theme.ui;return n?m.jsx(V,{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 $m=ot(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Uc(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 jm=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.`,Cm="Declared on its source, so its chart is set in the model.";function Mm({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:i,onDuplicate:s,duplicateBlocked:o,view:a}){const{theme:d}=Ve(),f=d.ui,{draft:c,apply:l,close:u}=Uc(t,e!==null,r,n),[p,g]=S.useState(void 0),v=c!==void 0&&ue(c)?c:void 0,y=v!==void 0&&v.declaration.kind!=="inherited",k=I=>l(T=>{ue(T)&&I(T)}),h=S.useRef(void 0),b=e!==null;S.useEffect(()=>{b?h.current=t&&ue(t)?t.chart:void 0:g(void 0)},[b]);const x=v?.chart??"default",w=qc(a,x),$=v?y?v.chart==="custom"?jm(v.chartLines):void 0:Cm:void 0,M=I=>k(T=>{const R=h.current;I===(R??"default")?(R===void 0?delete T.chart:T.chart=R,delete T.chartCarried):(T.chart=I,a?T.chartCarried=a.chart?[a.chart]:[]:delete T.chartCarried)}),A=y?i?void 0:"Its source declares no dimension a click could filter by.":void 0,j=I=>T=>g({kind:I,anchor:T.currentTarget}),C=(I,T,R)=>m.jsxs(m.Fragment,{children:[m.jsx(Bi,{primary:I,...R?{secondary:R}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),T&&m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",ml:2},children:T})]});return m.jsxs(m.Fragment,{children:[m.jsxs(Fi,{className:Je.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 ${Yt(d.cardBorder)}`,boxShadow:f.shadow.menu}}},children:[v&&m.jsxs(vt,{"aria-haspopup":"menu","aria-expanded":p?.kind==="chart",disabled:$!==void 0,onClick:j("chart"),onKeyDown:I=>{I.key==="ArrowRight"&&$===void 0&&g({kind:"chart",anchor:I.currentTarget})},children:[C("Chart",$?void 0:w.find(I=>I.value===x)?.label,$),m.jsx($m,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),y&&m.jsx(vt,{"aria-haspopup":"dialog",disabled:A!==void 0,onClick:()=>{u(),i?.()},children:C("Clickable cells…",void 0,A)}),v&&s&&m.jsx(vt,{disabled:o!==void 0,onClick:()=>{u(),s()},children:C("Duplicate",void 0,o)}),v?.declaration.kind==="opaque"&&m.jsxs(pe,{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(Fr,{}),v&&m.jsxs(V,{"aria-hidden":!0,sx:{px:2,py:.5,...f.type.code,color:"text.secondary"},children:[v.source," → ",v.name]})]}),m.jsx(Fi,{className:Je.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:I=>{I.key==="ArrowLeft"&&(I.preventDefault(),g(void 0))}},children:w.filter(I=>I.value!=="custom").map(I=>m.jsxs(vt,{role:"menuitemradio","aria-checked":I.value===x,disabled:I.disabled===!0,onClick:()=>{M(I.value),g(void 0)},children:[m.jsx(Bi,{primary:I.label,...I.reason?{secondary:I.reason}:{}}),I.value===x&&m.jsx(mp,{sx:{minWidth:0,ml:2},children:m.jsx(aa,{fontSize:"small",sx:{color:d.accent}})})]},I.value))})]})}const zn=e=>e.label??gp(`${e.source} -> ${e.name}`);function Em({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&&ue(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(wm,{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(Mm,{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&&Hi(h)!==void 0?{duplicateBlocked:Hi(h)}:{},...(e.document.sources.find(x=>x.name===h?.source)?.dimensions?.length??0)>0?{onDrills:()=>{y(h?zn(h):void 0),a(h?.source)}}:{}}),m.jsx(tm,{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(M=>M.source!==o),...x];$.length===0?delete w.drills:w.drills=$})}),m.jsx(Af,{...d}),m.jsx(Jp,{open:s.addingTile,document:e.document,catalog:t,columns:n,onClose:s.closeAdd,onAdd:s.addTile,onAddText:s.addText,...f?{renderPreview:f}:{}})]})}var Om=Symbol.for("preact-signals");function fs(){if(Dt>1)Dt--;else{var e,t=!1;for((function(){var i=Ki;for(Ki=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}})();Pr!==void 0;){var n=Pr;for(Pr=void 0,Gi++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Kc(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(Gi=0,Dt--,t)throw e}}function Ce(e){if(Dt>0)return e();ho=++Dm,Dt++;try{return e()}finally{fs()}}var Rr,xe=void 0;function se(e){var t=xe,n=Rr;xe=void 0,Rr=void 0;try{return e()}finally{xe=t,Rr=n}}var Pr=void 0,Dt=0,Gi=0,Dm=0,ho=0,Ki=void 0,Yi=0;function Gc(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=Om;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:se(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&&se(function(){var i;(i=t.Z)==null||i.call(t)}))}};Qe.prototype.subscribe=function(e){var t=this;return ft(function(){var n=t.value;se(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 se(function(){return e.value})};Object.defineProperty(Qe.prototype,"value",{get:function(){var e=Gc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Gi>100)throw new Error("Cycle detected");(function(n){Dt!==0&&Gi===0&&n.l!==ho&&(n.l=ho,Ki={S:n,v:n.v,i:n.i,o:Ki})})(this),this.v=e,this.i++,Yi++,Dt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{fs()}}}});function Gn(e,t){return new Qe(e,t)}function Kc(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 Xc(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 fn(e,t){Qe.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Yi-1,this.f=4}fn.prototype=new Qe;fn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Yi))return!0;if(this.g=Yi,this.f|=1,this.i>0&&!Kc(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,Xc(this),this.f&=-2,!0};fn.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)};fn.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)}};fn.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(fn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Gc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Ml(e,t){return new fn(e,t)}function Zc(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Dt++;var n=xe;xe=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,ua(e),r}finally{xe=n,fs()}}}function ua(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Zc(e)}function Am(e){if(xe!==this)throw new Error("Out-of-order effect");Xc(this),xe=e,this.f&=-2,8&this.f&&ua(this),fs()}function Kn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Rr&&Rr.push(this)}Kn.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()}};Kn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Zc(this),Yc(this),Dt++;var e=xe;return xe=this,Am.bind(this,e)};Kn.prototype.N=function(){2&this.f||(this.f|=2,this.u=Pr,Pr=this)};Kn.prototype.d=function(){this.f|=8,1&this.f||ua(this)};Kn.prototype.dispose=function(){this.d()};function ft(e,t){var n=new Kn(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Tm=Object.create,ha=Object.defineProperty,Rm=Object.defineProperties,Pm=Object.getOwnPropertyDescriptor,Im=Object.getOwnPropertyDescriptors,El=Object.getOwnPropertySymbols,zm=Object.prototype.hasOwnProperty,Wm=Object.prototype.propertyIsEnumerable,Nm=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Yn=e=>{throw TypeError(e)},fo=(e,t,n)=>t in e?ha(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lm=(e,t)=>{for(var n in t||(t={}))zm.call(t,n)&&fo(e,n,t[n]);if(El)for(var n of El(t))Wm.call(t,n)&&fo(e,n,t[n]);return e},Fm=(e,t)=>Rm(e,Im(t)),Ol=(e,t)=>ha(e,"name",{value:t,configurable:!0}),Bm=e=>{var t;return[,,,Tm((t=void 0)!=null?t:null)]},Jc=["class","method","getter","setter","accessor","field","value","get","set"],mr=e=>e!==void 0&&typeof e!="function"?Yn("Function expected"):e,_m=(e,t,n,r,i)=>({kind:Jc[e],name:t,metadata:r,addInitializer:s=>n._?Yn("Already initialized"):i.push(mr(s||null))}),Qc=(e,t)=>fo(t,Nm("metadata"),e[3]),Zt=(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},Xn=(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)&&Pm(l<4?i:{get[n](){return lt(this,s)},set[n](x){return Nt(this,s,x)}},n));l?p&&l<4&&Ol(s,(l>2?"set ":l>1?"get ":"")+n):Ol(i,n);for(var b=r.length-1;b>=0;b--)f=_m(l,n,d={},e[3],k),l&&(f.static=u,f.private=p,c=f.access={has:p?x=>Vm(i,x):x=>n in x},l^3&&(c.get=p?x=>(l^1?lt:qm)(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?mr(a)&&(l>4?y.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?Yn("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||Qc(e,i),h&&ha(i,n,h),p?l^4?s:h:i},fa=(e,t,n)=>t.has(e)||Yn("Cannot "+n),Vm=(e,t)=>Object(t)!==t?Yn('Cannot use the "in" operator on this value'):e.has(t),lt=(e,t,n)=>(fa(e,t,"read from private field"),n?n.call(e):t.get(e)),gr=(e,t,n)=>t.has(e)?Yn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Nt=(e,t,n,r)=>(fa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),qm=(e,t,n)=>(fa(e,t,"access private method"),n);function po(e,t){if(t){let n;return Ml(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Ml(e)}function mt(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)=>!mt(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=>!mt(e[i],t[i]))}return!1}function oe({get:e},t){return{init(n){return Gn(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 As(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,Fm(Lm({},i),{enumerable:e}))})}}function Qr(...e){const t=e.map(n=>ft(n));return()=>t.forEach(n=>n())}var ed,td,nd,rd,id,sd,Ye,pa,Ts,mo,go,He,ma,Rs,od,vo,ga,Ps,bo,xo;sd=[oe],id=[oe],rd=[oe],nd=[As()],td=[As()],ed=[As()];var pn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Zt(Ye,5,this),gr(this,He),gr(this,pa,Zt(Ye,8,this)),Zt(Ye,11,this),gr(this,ma,Zt(Ye,12,this)),Zt(Ye,15,this),gr(this,ga,Zt(Ye,16,this)),Zt(Ye,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return lt(this,He,bo)}get initial(){return lt(this,He,mo)}get previous(){return lt(this,He,od)}set current(e){const t=se(()=>lt(this,He,bo));e&&t&&this.equals(t,e)||Ce(()=>{lt(this,He,mo)||Nt(this,He,e,go),Nt(this,He,t,vo),Nt(this,He,e,xo)})}reset(e=this.defaultValue){Ce(()=>{Nt(this,He,void 0,vo),Nt(this,He,e,go),Nt(this,He,e,xo)})}};Ye=Bm();pa=new WeakMap;He=new WeakSet;ma=new WeakMap;ga=new WeakMap;Ts=Xn(Ye,20,"#initial",sd,He,pa),mo=Ts.get,go=Ts.set;Rs=Xn(Ye,20,"#previous",id,He,ma),od=Rs.get,vo=Rs.set;Ps=Xn(Ye,20,"#current",rd,He,ga),bo=Ps.get,xo=Ps.set;Xn(Ye,2,"current",nd,pn);Xn(Ye,2,"initial",td,pn);Xn(Ye,2,"previous",ed,pn);Qc(Ye,pn);function Is(e){return se(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Jt,Hm=class{constructor(){gr(this,Jt,new WeakMap)}get(e,t){var n;return e?(n=lt(this,Jt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return lt(this,Jt).has(e)||lt(this,Jt).set(e,new Map),(r=lt(this,Jt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=lt(this,Jt).get(e))==null?void 0:t.clear():void 0}};Jt=new WeakMap;var Um=Object.create,ad=Object.defineProperty,Gm=Object.getOwnPropertyDescriptor,Dl=Object.getOwnPropertySymbols,Km=Object.prototype.hasOwnProperty,Ym=Object.prototype.propertyIsEnumerable,ld=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ps=e=>{throw TypeError(e)},Al=Math.pow,yo=(e,t,n)=>t in e?ad(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xm=(e,t)=>{for(var n in t||(t={}))Km.call(t,n)&&yo(e,n,t[n]);if(Dl)for(var n of Dl(t))Ym.call(t,n)&&yo(e,n,t[n]);return e},Zm=e=>{var t;return[,,,Um((t=e?.[ld("metadata")])!=null?t:null)]},cd=["class","method","getter","setter","accessor","field","value","get","set"],dd=e=>e!==void 0&&typeof e!="function"?ps("Function expected"):e,Jm=(e,t,n,r,i)=>({kind:cd[e],name:t,metadata:r,addInitializer:s=>n._?ps("Already initialized"):i.push(dd(s||null))}),Qm=(e,t)=>yo(t,ld("metadata"),e[3]),eg=(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},ud=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=cd[c+5],v=e[p]||(e[p]=[]),y=(i=i.prototype,Gm(i,n)),k=r.length-1;k>=0;k--)d=Jm(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,dd(o)&&(y[g]=o);return y&&ad(i,n,y),i},hd=(e,t,n)=>t.has(e)||ps("Cannot "+n),tg=(e,t,n)=>(hd(e,t,"read from private field"),t.get(e)),ng=(e,t,n)=>t.has(e)?ps("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rg=(e,t,n,r)=>(hd(e,t,"write to private field"),t.set(e,n),n),ct=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=Xm({},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 ct((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?ig(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 ct.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 ig(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 fd,pd,ko,Ci,ei,ms=class extends(ko=pn,pd=[Oe],fd=[Oe],ko){constructor(e){const t=ct.from(e);super(t,(n,r)=>ct.equals(n,r)),eg(ei,5,this),ng(this,Ci,0),this.velocity={x:0,y:0}}get delta(){return ct.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=ct.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-tg(this,Ci),o=a=>Math.round(a/s*100);Ce(()=>{rg(this,Ci,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(ct.from(e)),this.velocity={x:0,y:0}}};ei=Zm(ko);Ci=new WeakMap;ud(ei,2,"delta",pd,ms);ud(ei,2,"direction",fd,ms);Qm(ei,ms);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 md=(e=>(e.Horizontal="x",e.Vertical="y",e))(md||{}),gd=Object.values(md),sg=Object.create,va=Object.defineProperty,og=Object.defineProperties,ag=Object.getOwnPropertyDescriptor,lg=Object.getOwnPropertyDescriptors,Xi=Object.getOwnPropertySymbols,vd=Object.prototype.hasOwnProperty,bd=Object.prototype.propertyIsEnumerable,xd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zn=e=>{throw TypeError(e)},$o=(e,t,n)=>t in e?va(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ba=(e,t)=>{for(var n in t||(t={}))vd.call(t,n)&&$o(e,n,t[n]);if(Xi)for(var n of Xi(t))bd.call(t,n)&&$o(e,n,t[n]);return e},xa=(e,t)=>og(e,lg(t)),Tl=(e,t)=>va(e,"name",{value:t,configurable:!0}),yd=(e,t)=>{var n={};for(var r in e)vd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Xi)for(var r of Xi(e))t.indexOf(r)<0&&bd.call(e,r)&&(n[r]=e[r]);return n},Jn=e=>{var t;return[,,,sg((t=e?.[xd("metadata")])!=null?t:null)]},wd=["class","method","getter","setter","accessor","field","value","get","set"],vr=e=>e!==void 0&&typeof e!="function"?Zn("Function expected"):e,cg=(e,t,n,r,i)=>({kind:wd[e],name:t,metadata:r,addInitializer:s=>n._?Zn("Already initialized"):i.push(vr(s||null))}),mn=(e,t)=>$o(t,xd("metadata"),e[3]),X=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},ae=(e,t,n,r,i,s)=>{var o,a,d,f,c,l=t&7,u=!!(t&8),p=!!(t&16),g=l>3?e.length+1:l?u?1:2:0,v=wd[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)&&ag(l<4?i:{get[n](){return Ee(this,s)},set[n](x){return st(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=cg(l,n,d={},e[3],k),l&&(f.static=u,f.private=p,c=f.access={has:p?x=>dg(i,x):x=>n in x},l^3&&(c.get=p?x=>(l^1?Ee:kd)(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?vr(a)&&(l>4?y.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?Zn("Object expected"):(vr(o=a.get)&&(h.get=o),vr(o=a.set)&&(h.set=o),vr(o=a.init)&&y.unshift(o));return l||mn(e,i),h&&va(i,n,h),p?l^4?s:h:i},ya=(e,t,n)=>t.has(e)||Zn("Cannot "+n),dg=(e,t)=>Object(t)!==t?Zn('Cannot use the "in" operator on this value'):e.has(t),Ee=(e,t,n)=>(ya(e,t,"read from private field"),n?n.call(e):t.get(e)),he=(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),st=(e,t,n,r)=>(ya(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),kd=(e,t,n)=>(ya(e,t,"access private method"),n);function Sd(e,t){return{plugin:e,options:t}}function ti(e){return t=>Sd(e,t)}function Br(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var $d,_r,wa,Mi;$d=[oe];var Ue=class{constructor(e,t){this.manager=e,this.options=t,he(this,wa,X(_r,8,this,!1)),X(_r,11,this),he(this,Mi,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return se(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=ft(e.bind(this));return Ee(this,Mi).add(t),t}destroy(){Ee(this,Mi).forEach(e=>e())}static configure(e){return Sd(this,e)}};_r=Jn(null);wa=new WeakMap;Mi=new WeakMap;ae(_r,4,"disabled",$d,Ue,wa);mn(_r,Ue);var ni=class extends Ue{},Ei,zs=class{constructor(e){this.manager=e,this.instances=new Map,he(this,Ei,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Br).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,Ei))if(!n.includes(r)){if(r.prototype instanceof ni)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);st(this,Ei,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()}};Ei=new WeakMap;function ug(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var mi=[],jn,Cn,hg=class extends Ue{constructor(e){super(e),he(this,jn),he(this,Cn),this.computeCollisions=this.computeCollisions.bind(this),st(this,Cn,Gn(mi)),this.destroy=Qr(()=>{const t=this.computeCollisions(),n=se(()=>this.manager.dragOperation.position.current);if(t!==mi){const r=Ee(this,jn);if(st(this,jn,n),r&&n.x==r.x&&n.y==r.y)return}else st(this,jn,void 0);Ee(this,Cn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){se(()=>{e?Ee(this,Cn).value=this.computeCollisions():st(this,jn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return mi;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=se(()=>c({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return d.length===0?mi:(a.sort(ug),a)}get collisions(){return Ee(this,Cn).value}};jn=new WeakMap;Cn=new WeakMap;var jd,Cd,Md,ka,Ed,gt,Sa,Tn,$a,ja;Md=[oe],Cd=[oe],jd=[oe];var Tt=class en{constructor(t,n){he(this,Sa,X(gt,8,this)),X(gt,11,this),he(this,Tn),he(this,$a,X(gt,12,this)),X(gt,15,this),he(this,ja,X(gt,16,this)),X(gt,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let d=i;st(this,Tn,Gn(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,Tn).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,Tn).peek();t!==i&&(en.pendingIdChanges||(en.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return kd(s=en,ka,Ed).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)}};gt=Jn(null);ka=new WeakSet;Ed=function(){const e=Tt.pendingIdChanges;Tt.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)Ee(t,Tn).value=n})};Sa=new WeakMap;Tn=new WeakMap;$a=new WeakMap;ja=new WeakMap;ae(gt,4,"manager",Md,Tt,Sa);ae(gt,4,"data",Cd,Tt,$a);ae(gt,4,"disabled",jd,Tt,ja);he(Tt,ka);mn(gt,Tt);Tt.pendingIdChanges=null;var gs=Tt,Rl=class{constructor(){this.map=Gn(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=Qr(...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}},Od,Dd,Ad,Td,Rd,Pd,jo,Xe,Ca,Ma,Ea,Ct=class extends(jo=gs,Pd=[oe],Rd=[oe],Td=[oe],Ad=[Oe],Dd=[Oe],Od=[Oe],jo){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,d=yd(n,["modifiers","type","sensors","plugins","effects"]);super(xa(ba({},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}=Br(u);c.registry.plugins.register(p)}}]}}),t),X(Xe,5,this),he(this,Ca,X(Xe,8,this)),X(Xe,11,this),he(this,Ma,X(Xe,12,this)),X(Xe,15,this),he(this,Ea,X(Xe,16,this,this.isDragSource?"dragging":"idle")),X(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=Br(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=Jn(jo);Ca=new WeakMap;Ma=new WeakMap;Ea=new WeakMap;ae(Xe,4,"type",Pd,Ct,Ca);ae(Xe,4,"modifiers",Rd,Ct,Ma);ae(Xe,4,"status",Td,Ct,Ea);ae(Xe,2,"isDropping",Ad,Ct);ae(Xe,2,"isDragging",Dd,Ct);ae(Xe,2,"isDragSource",Od,Ct);mn(Xe,Ct);var Id,zd,Wd,Nd,Ld,Fd,Co,Ie,Oa,Da,Aa,Ta,Ra,Mt=class extends(Co=gs,Fd=[oe],Ld=[oe],Nd=[oe],Wd=[oe],zd=[oe],Id=[Oe],Co){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=yd(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),X(Ie,5,this),he(this,Oa,X(Ie,8,this)),X(Ie,11,this),he(this,Da,X(Ie,12,this)),X(Ie,15,this),he(this,Aa,X(Ie,16,this)),X(Ie,19,this),he(this,Ta,X(Ie,20,this)),X(Ie,23,this),he(this,Ra,X(Ie,24,this)),X(Ie,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}};Ie=Jn(Co);Oa=new WeakMap;Da=new WeakMap;Aa=new WeakMap;Ta=new WeakMap;Ra=new WeakMap;ae(Ie,4,"accept",Fd,Mt,Oa);ae(Ie,4,"type",Ld,Mt,Da);ae(Ie,4,"collisionDetector",Nd,Mt,Aa);ae(Ie,4,"collisionPriority",Wd,Mt,Ta);ae(Ie,4,"shape",zd,Mt,Ra);ae(Ie,2,"isDropTarget",Id,Mt);mn(Ie,Mt);var fg=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)}},pg=class extends fg{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function Oi(e,t=!0){let n=!1;return xa(ba({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var mg=class extends ni{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=Qr(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||gs.pendingIdChanges)return;const o=Oi({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;se(()=>{var d;a?.id!==((d=e.dragOperation.target)==null?void 0:d.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Qn=(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))(Qn||{}),er=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(er||{}),Bd,_d,Vd,qd,Hd,Ud,Gd,ht,Pa;Gd=[oe],Ud=[Oe],Hd=[Oe],qd=[Oe],Vd=[Oe],_d=[Oe],Bd=[Oe];var Pt=class{constructor(){X(ht,5,this),he(this,Pa,X(ht,8,this,"idle")),X(ht,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}};ht=Jn(null);Pa=new WeakMap;ae(ht,4,"value",Gd,Pt,Pa);ae(ht,2,"current",Ud,Pt);ae(ht,2,"idle",Hd,Pt);ae(ht,2,"initializing",qd,Pt);ae(ht,2,"initialized",Vd,Pt);ae(ht,2,"dragging",_d,Pt);ae(ht,2,"dropped",Bd,Pt);mn(ht,Pt);var gg=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 se(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=Oi({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return se(()=>{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;Ce(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=r??null,t.position.reset(i)});const s=Oi({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"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:r,operation:t.snapshot(),cancelable:!1})})}),n)})}move(e){return se(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=Oi({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 se(()=>{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=se(()=>{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=ft(()=>{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()})}},Bn=class extends Ue{constructor(e,t){super(e,t),this.manager=e,this.options=t}},vg=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)}},Di,Kd=class{constructor(e){this.options=e,he(this,Di)}set controller(e){st(this,Di,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ee(this,Di))==null||t.activate(e)}};Di=new WeakMap;var Pl=class extends Ue{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},bg=class{constructor(e){this.draggables=new Rl,this.droppables=new Rl,this.plugins=new zs(e),this.sensors=new zs(e),this.modifiers=new zs(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 Pl)return this.modifiers.register(e,t);if(e.prototype instanceof Bn)return this.sensors.register(e,t);if(e.prototype instanceof Ue)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof gs)return e instanceof Ct?this.draggables.unregister(e.id,e):e instanceof Mt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Pl)return this.modifiers.unregister(e);if(e.prototype instanceof Bn)return this.sensors.unregister(e);if(e.prototype instanceof Ue)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,Xd,Zd,Jd,Qd,eu,tu,nu,ru,br,Ai,Mn,je,Ia,za,Wa,Na,La,xr;ru=[Oe],nu=[oe],tu=[oe],eu=[oe],Qd=[oe],Jd=[oe],Zd=[Oe],Xd=[Oe],Yd=[Oe];var yt=class{constructor(e){X(je,5,this),he(this,br),he(this,Ai),he(this,Mn,new pn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Pt,he(this,Ia,X(je,8,this,!1)),X(je,11,this),he(this,za,X(je,12,this,null)),X(je,15,this),he(this,Wa,X(je,16,this,null)),X(je,19,this),he(this,Na,X(je,20,this,null)),X(je,23,this),he(this,La,X(je,24,this,[])),X(je,27,this),this.position=new ms({x:0,y:0}),he(this,xr,{x:0,y:0}),st(this,br,e)}get shape(){const{current:e,initial:t,previous:n}=Ee(this,Mn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ee(this,Mn).current=e:Ee(this,Mn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ee(this,br).registry.draggables.get(t);return n&&st(this,Ai,n),(e=n??Ee(this,Ai))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ee(this,br).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(xa(ba({},this.snapshot()),{transform:n}));return st(this,xr,n),n}snapshot(){return se(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ee(this,xr),shape:this.shape?Is(this.shape):null,position:Is(this.position),status:Is(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Ee(this,Mn).reset(),this.position.reset({x:0,y:0}),st(this,xr,{x:0,y:0}),this.modifiers=[]})}};je=Jn(null);br=new WeakMap;Ai=new WeakMap;Mn=new WeakMap;Ia=new WeakMap;za=new WeakMap;Wa=new WeakMap;Na=new WeakMap;La=new WeakMap;xr=new WeakMap;ae(je,2,"shape",ru,yt);ae(je,4,"canceled",nu,yt,Ia);ae(je,4,"activatorEvent",tu,yt,za);ae(je,4,"sourceIdentifier",eu,yt,Wa);ae(je,4,"targetIdentifier",Qd,yt,Na);ae(je,4,"modifiers",Jd,yt,La);ae(je,2,"source",Zd,yt);ae(je,2,"target",Xd,yt);ae(je,2,"transform",Yd,yt);mn(je,yt);var xg={get rendering(){return Promise.resolve()}};function xt(e,t){return typeof e=="function"?e(t):e??t}var yg=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=xt(n.plugins,[]),i=xt(n.sensors,[]),s=xt(n.modifiers,[]),o=(t=n.renderer)!=null?t:xg,a=new pg(this),d=new bg(this);this.registry=d,this.monitor=a,this.renderer=o,this.actions=new gg(this),this.dragOperation=new yt(this),this.collisionObserver=new hg(this),this.plugins=[mg,...r],this.modifiers=s,this.sensors=i;const{destroy:f}=this,c=Qr(()=>{var l,u,p;const g=se(()=>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}=Br(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}},iu=e=>{throw TypeError(e)},Fa=(e,t,n)=>t.has(e)||iu("Cannot "+n),Y=(e,t,n)=>(Fa(e,t,"read from private field"),t.get(e)),et=(e,t,n)=>t.has(e)?iu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rt=(e,t,n,r)=>(Fa(e,t,"write to private field"),t.set(e,n),n),su=(e,t,n)=>(Fa(e,t,"access private method"),n);function vs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function ou(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,o=(vs(s)?s.getKeyframes():[]).filter(t);o.length>0&&(r=[o[o.length-1],i])}return r}function bs(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 Ba(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function ri(e){return"nodeType"in e}function at(e){var t,n,r;return e?Ba(e)?e:ri(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 _a(e){const{Document:t}=at(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Ut(e){return!e||Ba(e)?!1:e instanceof at(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function au(e){return e instanceof at(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function tr(e){return e?Ba(e)?e.document:ri(e)?_a(e)?e:Ut(e)||au(e)?e.ownerDocument:document:document:document}function wg(e){var t,n,r,i;const{documentElement:s}=tr(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 kg(e,t){if(Sg(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function Sg(e){return e.tagName==="DETAILS"}function Vr(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(!kg(l)){const b=l.getBoundingClientRect(),x=n*(b.bottom-b.top),w=n*(b.right-b.left),$=n*(b.bottom-b.top),M=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-M),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 _n(e){return{x:e.clientX,y:e.clientY}}var lu=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 Va(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function cu(){var e,t;const n=Va()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function qa(e){return!e||!ri(e)?!1:e instanceof at(e).ShadowRoot}function Zi(e){if(e&&ri(e)){let t=e.getRootNode();if(qa(t)||t instanceof Document)return t}return tr(e)}function Ha(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function $g(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];Il(i)&&Il(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),zl(i)&&zl(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function Il(e){return"value"in e}function zl(e){return e.tagName==="CANVAS"}function du(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(jg(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return du(i,{x:t-s,y:n-o})}}return r}function jg(e){return e?.tagName==="IFRAME"}var Eo=new WeakMap;function Cg(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 uu=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 Vn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Mg(e){const t=new Set;let n=Vn(e);for(;n;)t.add(n),n=Vn(n);return t}function Eg(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function hu(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=Eg(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function Og(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 Dg(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Vr(e,t);return n>0&&r>0}var Ag=lu?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Ti,Tg=class extends Ag{constructor(e){super(t=>{if(!Y(this,Ti)){rt(this,Ti,!0);return}e(t,this)}),et(this,Ti,!1)}};Ti=new WeakMap;var Wl=Array.from({length:100},(e,t)=>t/100),fu=75,tn,Ji,zt,nn,yr,_e,Ir,wr,Qi,pu,mu,gu=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,et(this,Qi),this.disconnect=()=>{var s,o,a;rt(this,Ir,!0),(s=Y(this,zt))==null||s.disconnect(),(o=Y(this,nn))==null||o.disconnect(),Y(this,yr).disconnect(),(a=Y(this,_e))==null||a.remove()},et(this,tn,!0),et(this,Ji),et(this,zt),et(this,nn),et(this,yr),et(this,_e),et(this,Ir,!1),et(this,wr,hu(()=>{var s,o,a;const{element:d}=this;if((s=Y(this,nn))==null||s.disconnect(),Y(this,Ir)||!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=Vr(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(M=>{const[A]=M,{intersectionRect:j}=A;(A.intersectionRatio!==1?A.intersectionRatio:jt.intersectionRatio(j,Vr(d)))!==1&&Y(this,wr).call(this)},{threshold:Wl,rootMargin:$,root:f})),Y(this,nn).observe(d),su(this,Qi,pu).call(this)},fu)),this.boundingClientRect=e.getBoundingClientRect(),rt(this,tn,Dg(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(rt(this,_e,document.createElement("div")),Y(this,_e).style.background="rgba(0,0,0,0.15)",Y(this,_e).style.position="fixed",Y(this,_e).style.pointerEvents="none",i.body.appendChild(Y(this,_e))),rt(this,yr,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,_e)&&(Y(this,_e).style.visibility="hidden")):Y(this,wr).call(this),c&&!Y(this,zt)&&(rt(this,zt,new Tg(Y(this,wr))),Y(this,zt).observe(e)))},{threshold:Wl,root:i})),Y(this,tn)&&!n.skipInitial&&this.callback(this.boundingClientRect),Y(this,yr).observe(e)}};tn=new WeakMap;Ji=new WeakMap;zt=new WeakMap;nn=new WeakMap;yr=new WeakMap;_e=new WeakMap;Ir=new WeakMap;wr=new WeakMap;Qi=new WeakSet;pu=function(){Y(this,Ir)||(su(this,Qi,mu).call(this),!Og(this.boundingClientRect,Y(this,Ji))&&(this.callback(this.boundingClientRect),rt(this,Ji,this.boundingClientRect)))};mu=function(){if(Y(this,_e)){const{top:e,left:t,width:n,height:r}=Vr(this.element);Y(this,_e).style.overflow="hidden",Y(this,_e).style.visibility="visible",Y(this,_e).style.top=`${Math.floor(e)}px`,Y(this,_e).style.left=`${Math.floor(t)}px`,Y(this,_e).style.width=`${Math.floor(n)}px`,Y(this,_e).style.height=`${Math.floor(r)}px`}};var gi=new WeakMap,vi=new WeakMap;function Rg(e,t){let n=gi.get(e);return n||(n={disconnect:new gu(e,r=>{const i=gi.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),gi.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(gi.delete(e),n.disconnect())}}function Pg(e,t){const n=new Set;for(const r of e){const i=Rg(r,t);n.add(i)}return()=>n.forEach(r=>r())}function Ig(e,t){var n;const r=e.ownerDocument;if(!vi.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}),vi.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=vi.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),vi.delete(r))})}var kr,Sr,Ri,Oo,zg=class{constructor(e,t,n){this.callback=t,et(this,kr),et(this,Sr,!1),et(this,Ri),et(this,Oo,hu(o=>{if(!Y(this,Sr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of Y(this,Ri))if(o.target.contains(a)){this.callback(Y(this,kr).boundingClientRect);break}}},fu));const r=Mg(e),i=Pg(r,t),s=Ig(e,Y(this,Oo));rt(this,Ri,r),rt(this,kr,new gu(e,t,n)),this.disconnect=()=>{Y(this,Sr)||(rt(this,Sr,!0),i(),s(),Y(this,kr).disconnect())}}};kr=new WeakMap;Sr=new WeakMap;Ri=new WeakMap;Oo=new WeakMap;function Do(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Wn(e){try{Do(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Nl(e){return!lu||!e?!1:e===tr(e).scrollingElement}function vu(e){var t,n;const r=at(e),i=Nl(e)?wg(e):bs(e),s=r.visualViewport,o=Nl(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 Wg(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=vu(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 Ua=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))}},es=new Ua(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Ng=new Ua(e=>setTimeout(e,50)),ts=new Map,Lg=ts.clear.bind(ts);function Et(e,t=!1){if(!t)return Ll(e);let n=ts.get(e);return n||(n=Ll(e),ts.set(e,n),Ng.schedule(Lg),n)}function Ll(e){return at(e).getComputedStyle(e)}function Fg(e,t=Et(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Bg(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 _g={excludeElement:!0,escapeShadowDOM:!0};function Ao(e,t=_g){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(_a(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&qa(a))return o(a.host);if(!Ut(a))return au(a)?o(a.parentElement):s;if(s.has(a))return s;const d=Et(a,!0);if(r&&a===e||Bg(a,d)&&s.add(a),Fg(a,d)){const{scrollingElement:f}=a.ownerDocument;return f&&s.add(f),s}return o(a.parentNode)}return e?o(e):s}function qn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Vn(e);for(;r;){if(r===t)return n;const i=bs(r),{x:s,y:o}=Vg(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=Vn(r)}return n}function Vg(e,t=bs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Ut(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 qg(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 qr(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 xs(e){var t,n,r,i,s,o,a,d,f;const{scale:c,transform:l,translate:u}=e,p=qg(c),g=qr(u),v=Hg(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 Hg(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 dt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(dt||{}),Ug={x:.2,y:.2},Gg={x:10,y:10};function Kg(e,t,n,r=25,i=Ug,s=Gg){const{x:o,y:a}=t,{rect:d,isTop:f,isBottom:c,isLeft:l,isRight:u}=vu(e),p=qn(e),g=Et(e,!0),v=xs(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 bu(e,{block:t="nearest",inline:n="nearest"}={}){if(!Ut(e))return;const r=Ao(e),i=[];for(const s of r){if(!Ut(s))continue;const{top:o,left:a}=Yg(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 Fl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!Ut(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function Yg(e,t){const n=Fl(e),r=Fl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Xg(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 Zg(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 xu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Bl(e,t=Et(e).translate,n=!0){if(n){const r=ou(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=qr(i);if(s)return s}}}if(t){const r=qr(t);if(r)return r}return{x:0,y:0,z:0}}var Jg=new Ua(e=>setTimeout(e,0)),zr=new Map,Qg=zr.clear.bind(zr);function ev(e){const t=e.ownerDocument;let n=zr.get(t);if(n)return n;n=t.getAnimations(),zr.set(t,n),Jg.schedule(Qg);const r=n.filter(i=>vs(i.effect)&&i.effect.target===e);return zr.set(e,r),n}function tv(e,t){const n=ev(e).filter(r=>{var i,s;if(vs(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=qn(e),ignoreTransforms:a,getBoundingClientRect:d=bs}=t,f=tv(e,{properties:["transform","translate","scale","width","height"],isValidTarget:w=>(w!==e||Va())&&w.contains(e)}),c=d(e);let{top:l,left:u,width:p,height:g}=c,v;const y=Et(e),k=xs(y),h={x:(n=k?.scaleX)!=null?n:1,y:(r=k?.scaleY)!=null?r:1},b=nv(e,y);f?.(),k&&(v=Zg(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=Xg(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 nv(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=vs(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?xs({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function Wr(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 rv=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Wr(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(Wr(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(Wr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function un(e){return e?e instanceof at(e).Element||ri(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Hr(e){if(!e)return!1;const{KeyboardEvent:t}=at(e.target);return e instanceof t}function iv(e){if(!e)return!1;const{PointerEvent:t}=at(e.target);return e instanceof t}function sv(e){if(!un(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||ov(e)}function ov(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Ws={};function To(e){const t=Ws[e]==null?0:Ws[e]+1;return Ws[e]=t,`${e}-${t}`}var Ga=({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=ct.distance(t.shape.center,n);return{id:r,value:1/i,type:er.PointerIntersection,priority:Qn.High}}return null},av=({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=ct.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:er.ShapeIntersection,priority:Qn.Normal}}return null},yu=e=>{var t;return(t=Ga(e))!=null?t:av(e)},lv=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+ct.distance(ct.from(d),(c=s?.[f])!=null?c:i.current)},0)/4;return{id:n.id,value:1/o,type:er.Collision,priority:Qn.Normal}},cv=Object.create,Ka=Object.defineProperty,dv=Object.defineProperties,uv=Object.getOwnPropertyDescriptor,hv=Object.getOwnPropertyDescriptors,ns=Object.getOwnPropertySymbols,wu=Object.prototype.hasOwnProperty,ku=Object.prototype.propertyIsEnumerable,Su=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),nr=e=>{throw TypeError(e)},Ro=(e,t,n)=>t in e?Ka(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ur=(e,t)=>{for(var n in t||(t={}))wu.call(t,n)&&Ro(e,n,t[n]);if(ns)for(var n of ns(t))ku.call(t,n)&&Ro(e,n,t[n]);return e},Ya=(e,t)=>dv(e,hv(t)),_l=(e,t)=>Ka(e,"name",{value:t,configurable:!0}),$u=(e,t)=>{var n={};for(var r in e)wu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ns)for(var r of ns(e))t.indexOf(r)<0&&ku.call(e,r)&&(n[r]=e[r]);return n},rr=e=>{var t;return[,,,cv((t=e?.[Su("metadata")])!=null?t:null)]},ju=["class","method","getter","setter","accessor","field","value","get","set"],$r=e=>e!==void 0&&typeof e!="function"?nr("Function expected"):e,fv=(e,t,n,r,i)=>({kind:ju[e],name:t,metadata:r,addInitializer:s=>n._?nr("Already initialized"):i.push($r(s||null))}),gn=(e,t)=>Ro(t,Su("metadata"),e[3]),We=(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},pt=(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=ju[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)&&uv(l<4?i:{get[n](){return ge(this,s)},set[n](x){return Ze(this,s,x)}},n));l?p&&l<4&&_l(s,(l>2?"set ":l>1?"get ":"")+n):_l(i,n);for(var b=r.length-1;b>=0;b--)f=fv(l,n,d={},e[3],k),l&&(f.static=u,f.private=p,c=f.access={has:p?x=>pv(i,x):x=>n in x},l^3&&(c.get=p?x=>(l^1?ge:hn)(x,i,l^4?s:h.get):x=>x[n]),l>2&&(c.set=p?(x,w)=>Ze(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?$r(a)&&(l>4?y.unshift(a):l?p?s=a:h[v]=a:i=a):typeof a!="object"||a===null?nr("Object expected"):($r(o=a.get)&&(h.get=o),$r(o=a.set)&&(h.set=o),$r(o=a.init)&&y.unshift(o));return l||gn(e,i),h&&Ka(i,n,h),p?l^4?s:h:i},Xa=(e,t,n)=>t.has(e)||nr("Cannot "+n),pv=(e,t)=>Object(t)!==t?nr('Cannot use the "in" operator on this value'):e.has(t),ge=(e,t,n)=>(Xa(e,t,"read from private field"),n?n.call(e):t.get(e)),Te=(e,t,n)=>t.has(e)?nr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ze=(e,t,n,r)=>(Xa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),hn=(e,t,n)=>(Xa(e,t,"access private method"),n),Vl={role:"button",roleDescription:"draggable"},mv="dnd-kit-description",gv="dnd-kit-announcement",vv={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."},bv={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 xv(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function yv(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function wv(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 kv=["dragover","dragmove"],Sv=class extends Ue{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=mv,announcement:i=gv}={},announcements:s=bv,screenReaderInstructions:o=vv,debounce:a=500}=t??{},d=n?`${r}-${n}`:To(r),f=n?`${i}-${n}`:To(i);let c,l,u,p;const g=(w=p)=>{!u||!w||u?.nodeValue!==w&&(u.nodeValue=w)},v=()=>es.schedule(g),y=$v(v,a),k=Object.entries(s).map(([w,$])=>this.manager.monitor.addEventListener(w,(M,A)=>{const j=u;if(!j)return;const C=$?.(M,A);C&&j.nodeValue!==C&&(p=C,kv.includes(w)?y():(v(),y.cancel()))})),h=()=>{let w=[];c?.isConnected||(c=yv(d,o.draggable),w.push(c)),l?.isConnected||(l=wv(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 M=(w=$.handle)!=null?w:$.element;if(M){(!c||!l)&&b.add(h),(!xv(M)||Va())&&!M.hasAttribute("tabindex")&&b.add(()=>M.setAttribute("tabindex","0")),!M.hasAttribute("role")&&M.tagName.toLowerCase()!=="button"&&b.add(()=>M.setAttribute("role",Vl.role)),M.hasAttribute("aria-roledescription")||b.add(()=>M.setAttribute("aria-roledescription",Vl.roleDescription)),M.hasAttribute("aria-describedby")||b.add(()=>M.setAttribute("aria-describedby",d));for(const j of["aria-pressed","aria-grabbed"]){const C=String($.isDragging);M.getAttribute(j)!==C&&b.add(()=>M.setAttribute(j,C))}const A=String($.disabled);M.getAttribute("aria-disabled")!==A&&b.add(()=>M.setAttribute("aria-disabled",A))}}b.size>0&&es.schedule(x)}),this.destroy=()=>{super.destroy(),c?.remove(),l?.remove(),k.forEach(w=>w())}}};function $v(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var rs=new Map,Cu,Mu,Eu,Ou,Po,Nr,At,Za,Hn,Du,Au,Tu,Ru,Gt=class extends(Po=ni,Ou=[oe],Eu=[Oe],Mu=[Oe],Cu=[Oe],Po){constructor(e,t){super(e,t),We(At,5,this),Te(this,Hn),Te(this,Nr,new Set),Te(this,Za,We(At,8,this,new Set)),We(At,11,this),this.registerEffect(hn(this,Hn,Du))}register(e){return ge(this,Nr).add(e),()=>{ge(this,Nr).delete(e)}}addRoot(e){return se(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{se(()=>{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}};At=rr(Po);Nr=new WeakMap;Za=new WeakMap;Hn=new WeakSet;Du=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ge(this,Nr))t.push(hn(this,Hn,Au).call(this,n,r));return()=>{for(const n of t)n()}};Au=function(e,t){let n=rs.get(e);n||(n=new Map,rs.set(e,n));let r=n.get(t);if(!r){const s=_a(e)?hn(this,Hn,Tu).call(this,e,n,t):hn(this,Hn,Ru).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())}};Tu=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&&rs.delete(e)}}};Ru=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&&rs.delete(e)}}};pt(At,4,"additionalRoots",Ou,Gt,Za);pt(At,2,"sourceRoot",Eu,Gt);pt(At,2,"targetRoot",Mu,Gt);pt(At,2,"roots",Cu,Gt);gn(At,Gt);Gt.configure=ti(Gt);var ys=Gt,jv=class extends Ue{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(ys),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},ii="data-dnd-",Io=`${ii}dropping`,Be="--dnd-",kt=`${ii}dragging`,is=`${ii}placeholder`,Cv=[kt,is,"popover","aria-pressed","aria-grabbing"],Mv=["view-transition-name"],Ev=`
|
|
9
|
-
:is(:root,:host) [${kt}] {
|
|
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(${Be}top, 0px) !important;
|
|
16
|
-
left: var(${Be}left, 0px) !important;
|
|
17
|
-
right: unset !important;
|
|
18
|
-
bottom: unset !important;
|
|
19
|
-
width: var(${Be}width, auto);
|
|
20
|
-
max-width: var(${Be}width, auto);
|
|
21
|
-
height: var(${Be}height, auto);
|
|
22
|
-
max-height: var(${Be}height, auto);
|
|
23
|
-
transform: var(${Be}transform, none) !important;
|
|
24
|
-
transition: var(${Be}transition) !important;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
:is(:root,:host) [${is}] {
|
|
28
|
-
transition: none;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
:is(:root,:host) [${is}='hidden'] {
|
|
32
|
-
visibility: hidden;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
[${kt}] * {
|
|
36
|
-
pointer-events: none !important;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
[${kt}]:not([${Io}]) {
|
|
40
|
-
translate: var(${Be}translate) !important;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
[${kt}][style*='${Be}scale'] {
|
|
44
|
-
scale: var(${Be}scale) !important;
|
|
45
|
-
transform-origin: var(${Be}transform-origin) !important;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@layer dnd-kit {
|
|
49
|
-
:where([${kt}][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
|
-
[${kt}]::backdrop, [${ii}overlay]:not([${kt}]) {
|
|
64
|
-
display: none;
|
|
65
|
-
visibility: hidden;
|
|
66
|
-
}
|
|
67
|
-
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Ov(e,t="hidden"){return se(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Dv(n,r.registry.droppables),s=[],o=$g(n),{remove:a}=o;return Av(i,o,s),Tv(o,t),o.remove=()=>{s.forEach(d=>d()),a.call(o)},o})}function Dv(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${ii}${To("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Av(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 Tv(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(is,t)}function Pu(e,t){return e===t?!0:Vn(e)===Vn(t)}function ql(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&un(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Wn(t))}function zo(e){return e.tagName==="TR"}function Rv(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-")||Cv.includes(a))continue;const d=e.getAttribute(a);if(a==="style"){if(Wr(e)&&Wr(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(Mv.includes(c)||c.startsWith(Be))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 Pv(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),Wn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Wn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Wn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Iv(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=cu();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},Be),(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 zv=250,Wv="ease";function Nv(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=zv,easing:a=Wv}=s??{};Wn(e.feedbackElement);const[,d]=(t=ou(e.feedbackElement,h=>"translate"in h))!=null?t:[];d?.pause();const f=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Pu(e.feedbackElement,f)?null:void 0},l=new $t(e.feedbackElement,c),u=(r=qr(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},Be),e.feedbackElement.setAttribute(Io,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),xu({element:e.feedbackElement,keyframes:Ya(Ur(Ur({},y),k),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:Ha(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 Iu,Wo,Gr,Ja,Pi,zu,Wu,Un=class extends(Wo=Ue,Iu=[oe],Wo){constructor(e,t){super(e,t),Te(this,Pi),Te(this,Ja,We(Gr,8,this)),We(Gr,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(ys),r=n?.register(Ev);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(hn(this,Pi,zu).bind(this,n)),this.registerEffect(hn(this,Pi,Wu))}};Gr=rr(Wo);Ja=new WeakMap;Pi=new WeakSet;zu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Zi(t);if(n)return e.addRoot(n)};Wu=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(Un),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=qn(b),w=qn(g),$=!Pu(g,b),M=new $t(g,{frameTransform:$?w:null,ignoreTransforms:!$}),A={x:w.scaleX/x.scaleX,y:w.scaleY/x.scaleY};let{width:j,height:C,top:I,left:T}=M;$&&(j=j/A.x,C=C/A.y);const R=new rv(b),N=Et(g),{transition:H,translate:B,boxSizing:D,paddingBlockStart:W,paddingBlockEnd:F,paddingInlineStart:z,paddingInlineEnd:_,borderInlineStartWidth:Q,borderInlineEndWidth:G,borderBlockStartWidth:ne,borderBlockEndWidth:Z}=N,L=H.split(",").filter(be=>!/^\s*(transform|translate|scale)\b/.test(be)).join(","),J=xs(N),re=N.transform,ce=k==="clone",ee=D==="content-box",we=ee?parseInt(z)+parseInt(_)+parseInt(Q)+parseInt(G):0,me=ee?parseInt(W)+parseInt(F)+parseInt(ne)+parseInt(Z):0,K=k!=="move"&&!this.overlay?Ov(u,ce?"clone":"hidden"):null,ke=se(()=>Hr(d.dragOperation.activatorEvent));if(!h.translate){if(this.overlay&&J)h.translate={x:J.x,y:J.y};else if(B!=="none"){const be=qr(B);be&&(h.translate=be)}}if(!h.transformOrigin){const be=se(()=>l.current),Ne=T+((r=J?.x)!=null?r:0),nt=I+((i=J?.y)!=null?i:0);h.transformOrigin={x:(be.x-Ne*x.scaleX-x.x)/(j*x.scaleX),y:(be.y-nt*x.scaleY-x.y)/(C*x.scaleY)}}const{transformOrigin:fe}=h,le=I*x.scaleY+x.y,Fe=T*x.scaleX+x.x;if(!h.coordinates&&(h.coordinates={x:Fe,y:le},A.x!==1||A.y!==1)){const{scaleX:be,scaleY:Ne}=w,{x:nt,y:It}=fe;h.coordinates.x+=(j*be-j)*nt,h.coordinates.y+=(C*Ne-C)*It}h.dimensions||(h.dimensions={width:j,height:C}),h.frameTransform||(h.frameTransform=x);const Ge={x:h.coordinates.x-Fe,y:h.coordinates.y-le},qe={width:(h.dimensions.width*h.frameTransform.scaleX-j*x.scaleX)*fe.x,height:(h.dimensions.height*h.frameTransform.scaleY-C*x.scaleY)*fe.y},Ke={x:Ge.x/x.scaleX+qe.width,y:Ge.y/x.scaleY+qe.height},Re={left:T+Ke.x,top:I+Ke.y};b.setAttribute(kt,"true");const E=se(()=>c.transform),P=(s=h.translate)!=null?s:{x:0,y:0},q=E.x*x.scaleX+P.x,O=E.y*x.scaleY+P.y,te=cu();R.set({width:j-we,height:C-me,top:Re.top+te.y,left:Re.left+te.x,translate:`${q}px ${O}px 0`,transform:this.overlay?"none":re,transition:L?`${L}, translate 0ms linear`:"translate 0ms linear",scale:$?`${A.x} ${A.y}`:"","transform-origin":`${fe.x*100}% ${fe.y*100}%`},Be),K&&(g.insertAdjacentElement("afterend",K),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(g)),Do(b)&&(b.hasAttribute("popover")||b.setAttribute("popover","manual"),Wn(b),b.addEventListener("beforetoggle",ql));let U,de,ve;const ie=Iv({placeholder:K,element:g,feedbackElement:b,frameTransform:x,transformOrigin:fe,width:j,height:C,top:I,left:T,widthOffset:we,heightOffset:me,delta:Ke,styles:R,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>U,getSavedCellWidths:()=>ve,setSavedCellWidths:be=>{ve=be}}),wt=new $t(b);se(()=>c.shape=wt);const Ot=at(b),Xt=be=>{this.manager.actions.stop({event:be})},or=Ha(Ot);ke&&Ot.addEventListener("resize",Xt),se(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),K&&(ie.observe(K),U=Rv(g,K,ce),de=Pv(g,K,b));const ar=(o=d.dragOperation.source)==null?void 0:o.id,js=()=>{var be;if(!ke||ar==null)return;const Ne=d.registry.draggables.get(ar),nt=(be=Ne?.handle)!=null?be:Ne?.element;Ut(nt)&&nt.focus()},lr=()=>{U?.disconnect(),de?.disconnect(),ie.disconnect(),Ot.removeEventListener("resize",Xt),Do(b)&&(b.removeEventListener("beforetoggle",ql),b.removeAttribute("popover")),b.removeAttribute(kt),R.reset();const be=()=>{var Ne;if(ve&&zo(g)){const Cs=Array.from(g.cells);for(const[ui,vn]of Cs.entries())vn.style.width=(Ne=ve[ui])!=null?Ne:""}u.status="idle";const nt=a.current.translate!=null,It=c.status.dragging;K&&(!It&&nt||K.parentElement!==b.parentElement)&&b.isConnected&&K.replaceWith(b),K?.remove()};b===this.overlay?setTimeout(be,0):be()},cr=f?.dropAnimation,di=this,Qh=Qr(()=>{var be,Ne,nt;const{transform:It,status:Cs}=c;if(!(!It.x&&!It.y&&!a.current.translate)&&Cs.dragging){const ui=(be=h.translate)!=null?be:{x:0,y:0},vn={x:It.x/x.scaleX+ui.x,y:It.y/x.scaleY+ui.y},pl=a.current.translate,ef=se(()=>c.modifiers),Ms=se(()=>{var dr;return(dr=c.shape)==null?void 0:dr.current}),Es=f?.keyboardTransition,ml=ke&&!or&&Es!==null?`${(Ne=Es?.duration)!=null?Ne:250}ms ${(nt=Es?.easing)!=null?nt:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(R.set({transition:L?`${L}, translate ${ml}`:`translate ${ml}`,translate:`${vn.x}px ${vn.y}px 0`},Be),U?.takeRecords(),Ms&&Ms!==wt&&pl&&!ef.length){const dr=ct.delta(vn,pl);c.shape=jt.from(Ms.boundingRectangle).translate(dr.x*x.scaleX,dr.y*x.scaleY)}else c.shape=new $t(b);a.current.translate=vn}},function(){if(c.status.dropped){this.dispose(),u.status="dropping";const be=v?.dropAnimation!==void 0?v.dropAnimation:di.dropAnimation!==void 0?di.dropAnimation:cr;let Ne=a.current.translate;const nt=Ne!=null;if(!Ne&&g!==b&&(Ne={x:0,y:0}),!Ne||be===null){lr();return}d.renderer.rendering.then(()=>{Nv({source:u,element:g,feedbackElement:b,placeholder:K,translate:Ne,moved:nt,transition:H,alignment:u.alignment,styles:R,animation:be??void 0,getElementMutationObserver:()=>U,cleanup:lr,restoreFocus:js})})}});return()=>{lr(),Qh()}};pt(Gr,4,"overlay",Iu,Un,Ja);gn(Gr,Un);Un.configure=ti(Un);var Qa=Un,hr=!0,Lv=!1,Nu,Lu,Fu,Bu,Bt,el,tl;Bu=(Fu=[oe],dt.Forward),Lu=(Nu=[oe],dt.Reverse);var Kr=class{constructor(){Te(this,el,We(Bt,8,this,hr)),We(Bt,11,this),Te(this,tl,We(Bt,12,this,hr)),We(Bt,15,this)}isLocked(e){return e===dt.Idle?!1:e==null?this[dt.Forward]===hr&&this[dt.Reverse]===hr:this[e]===hr}unlock(e){e!==dt.Idle&&(this[e]=Lv)}};Bt=rr(null);el=new WeakMap;tl=new WeakMap;pt(Bt,4,Bu,Fu,Kr,el);pt(Bt,4,Lu,Nu,Kr,tl);gn(Bt,Kr);var Fv=[dt.Forward,dt.Reverse],Hl=class{constructor(){this.x=new Kr,this.y=new Kr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Bv=class extends Ue{constructor(e){super(e);const t=Gn(new Hl);let n=null;this.signal=t,ft(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new Hl;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:Ul(i.x,n.x),y:Ul(i.y,n.y)},o=t.peek();Ce(()=>{for(const a of gd)for(const d of Fv)s[a]===d&&o[a].unlock(d);t.value=o})}n=i})}get current(){return this.signal.peek()}};function Ul(e,t){return Math.sign(e-t)}var _u,No,Yr,nl,Wt,Lo,si=class extends(No=ni,_u=[oe],No){constructor(e){super(e),Te(this,nl,We(Yr,8,this,!1)),We(Yr,11,this),Te(this,Wt),Te(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 Ze(this,Wt,void 0),!1;const{position:f}=this.manager.dragOperation,c=f?.current;if(c){const{by:l}=s??{},u=l?{x:Gl(l.x),y:Gl(l.y)}:void 0,p=u?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const g of d){const v=Wg(g,l);if(v.x||v.y){const{speed:y,direction:k}=Kg(g,c,u,o?.acceleration,o?.threshold);if(p)for(const h of gd)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 Ze(this,Wt,{element:g,by:{x,y:w}}),es.schedule(ge(this,Lo)),!0}}}}}return Ze(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=du(Zi(o?.element),s.current);return a&&(t=a),a??t}),i=po(()=>{const s=r.value,{documentElement:o}=tr(s);if(!s||s===o){const{target:a}=e.dragOperation,d=a?.element;if(d){const f=Ao(d,{excludeElement:!1});return n=f,f}}if(s){const a=Ao(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},mt);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new Bv(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!Hr(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};Yr=rr(No);nl=new WeakMap;Wt=new WeakMap;Lo=new WeakMap;pt(Yr,4,"autoScrolling",_u,si,nl);gn(Yr,si);function Gl(e){return e>0?dt.Forward:e<0?dt.Reverse:dt.Idle}var _v=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))}},Vv=new _v(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),qv=10,Fo=class extends Ue{constructor(e,t){super(e,t);const n=e.registry.plugins.get(si);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=ft(()=>{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(()=>Vv.schedule(()=>n.scroll(void 0,d)),qv);return()=>{clearInterval(f)}}else n.autoScrolling=!1}})}};Fo.configure=ti(Fo);var Vu=Fo,Kl={capture:!0,passive:!0},jr,Hv=class extends ni{constructor(e){super(e),Te(this,jr),this.handleScroll=()=>{ge(this,jr)==null&&Ze(this,jr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ze(this,jr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=ft(()=>{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,Kl),()=>{s.removeEventListener("scroll",this.handleScroll,Kl)}}})}};jr=new WeakMap;var Uv="* { user-select: none !important; -webkit-user-select: none !important; }",Gv=class extends Ue{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(ys),n=t?.register(Uv);if(this.destroy=ft(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Ns(),document.addEventListener("selectionchange",Ns,{capture:!0}),()=>{document.removeEventListener("selectionchange",Ns,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Ns(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Cr=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}}),En,ss=class extends Bn{constructor(e,t){super(e),this.manager=e,this.options=t,Te(this,En,[]),this.listeners=new uu,this.handleSourceKeyDown=(n,r,i)=>{if(this.disabled||n.defaultPrevented||!un(n.target)||r.disabled)return;const{keyboardCodes:s=Cr.keyboardCodes,preventActivation:o=Cr.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 ft(()=>{var n;const r=(n=e.handle)!=null?n:e.element,i=s=>{Hr(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(),bu(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=tr(r),o=[this.listeners.bind(s,[{type:"keydown",listener:a=>this.handleKeyDown(a,t,n),options:{capture:!0}}])];ge(this,En).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=Cr.keyboardCodes}=n??{};if(xn(e,[...r.end,...r.cancel])){e.preventDefault();const i=xn(e,r.cancel);this.handleEnd(e,i);return}xn(e,r.up)?this.handleMove("up",e):xn(e,r.down)&&this.handleMove("down",e),xn(e,r.left)?this.handleMove("left",e):xn(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:Cr.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(Vu);e?.disabled===!1&&(e.disable(),ge(this,En).push(()=>{e.enable()}))}cleanup(){ge(this,En).forEach(e=>e()),Ze(this,En,[])}destroy(){this.cleanup(),this.listeners.clear()}};En=new WeakMap;ss.configure=ti(ss);ss.defaults=Cr;var qu=ss;function xn(e,t){return t.includes(e.code)}var rn,Kv=class extends Kd{constructor(){super(...arguments),Te(this,rn)}onEvent(e){switch(e.type){case"pointerdown":Ze(this,rn,_n(e));break;case"pointermove":if(!ge(this,rn))return;const{x:t,y:n}=_n(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(){Ze(this,rn,void 0)}};rn=new WeakMap;var On,sn,Yv=class extends Kd{constructor(){super(...arguments),Te(this,On),Te(this,sn)}onEvent(e){switch(e.type){case"pointerdown":Ze(this,sn,_n(e)),Ze(this,On,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ge(this,sn))return;const{x:t,y:n}=_n(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,On)&&(clearTimeout(ge(this,On)),Ze(this,sn,void 0),Ze(this,On,void 0))}};On=new WeakMap;sn=new WeakMap;var Rn=class{};Rn.Delay=Yv;Rn.Distance=Kv;var Bo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&un(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new Rn.Delay({value:250,tolerance:5})]:sv(i)&&!e.defaultPrevented?[new Rn.Delay({value:200,tolerance:0})]:[new Rn.Delay({value:200,tolerance:10}),new Rn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!un(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=Cg(r);return i===t.element?!1:!!i}}),Dn,os=class extends Bn{constructor(e,t){super(e),this.manager=e,this.options=t,Te(this,Dn,new Set),this.listeners=new uu,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 ft(()=>{var n;const r=new AbortController,{signal:i}=r,s=a=>{iv(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&&(Jv(a.ownerDocument.defaultView),a.addEventListener("pointerdown",s,{signal:i}));return()=>r.abort()})}handlePointerDown(e,t,n){if(this.disabled||!e.isPrimary||e.button!==0||!un(e.target)||t.disabled||Xv(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=Bo.preventActivation}=n??{};if(r?.(e,t))return;const{target:i}=e,s=Ut(i)&&i.draggable&&i.getAttribute("draggable")==="true",o=qn(t.element),{x:a,y:d}=_n(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 vg(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:bi,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=_n(e),s=qn(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,es.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=tr(t.target).body;try{i.setPointerCapture(t.pointerId)}catch{this.handleCancel(t);return}const s=un(t.target)?[t.target,i]:i,o=this.listeners.bind(s,[{type:"touchmove",listener:bi,options:{passive:!1}},{type:"click",listener:bi},{type:"contextmenu",listener:bi},{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;os.configure=ti(os);os.defaults=Bo;var _o=os;function Xv(e){return"sensor"in e}function bi(e){e.preventDefault()}function Zv(){}var Yl=new WeakSet;function Jv(e){!e||Yl.has(e)||(e.addEventListener("touchmove",Zv,{capture:!1,passive:!1}),Yl.add(e))}var Nn={modifiers:[],plugins:[Sv,Vu,jv,Qa,Gv],sensors:[_o,qu]},Hu=class extends yg{constructor(e={}){const t=xt(e.plugins,Nn.plugins),n=xt(e.sensors,Nn.sensors),r=xt(e.modifiers,Nn.modifiers);super(Ya(Ur({},e),{plugins:[Hv,si,ys,...t],sensors:n,modifiers:r}))}},Uu,Gu,Vo,_t,rl,il,ws=class extends(Vo=Ct,Gu=[oe],Uu=[oe],Vo){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=$u(n,["element","effects","handle"]);super(Ur({effects:()=>[...i(),()=>{var a,d;const{manager:f}=this;if(!f)return;const c=((d=(a=this.sensors)==null?void 0:a.map(Br))!=null?d:[...f.sensors]).map(l=>{const u=l instanceof Bn?l:f.registry.register(l.plugin),p=l instanceof Bn?void 0:l.options;return u.bind(this,p)});return function(){c.forEach(l=>l())}}]},o),t),Te(this,rl,We(_t,8,this)),We(_t,11,this),Te(this,il,We(_t,12,this)),We(_t,15,this),this.element=r,this.handle=s}};_t=rr(Vo);rl=new WeakMap;il=new WeakMap;pt(_t,4,"handle",Gu,ws,rl);pt(_t,4,"element",Uu,ws,il);gn(_t,ws);var Ku,Yu,qo,Vt,sl,Ls,Xu,Zu,Lr,ol,ks=class extends(qo=Mt,Yu=[oe],Ku=[oe],qo){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=$u(n,["element","effects"]);const{collisionDetector:o=yu}=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=se(()=>this.shape);return u&&p?.equals(u)?p:(this.shape=u,u)},d=Gn(!1);super(Ya(Ur({},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 zg(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),Te(this,Lr),Te(this,sl,We(Vt,8,this)),We(Vt,11,this),Te(this,ol,We(Vt,12,this)),We(Vt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ze(this,Lr,e,Zu)}get element(){var e;return(e=this.proxy)!=null?e:ge(this,Lr,Xu)}};Vt=rr(qo);sl=new WeakMap;Lr=new WeakSet;ol=new WeakMap;Ls=pt(Vt,20,"#element",Yu,Lr,sl),Xu=Ls.get,Zu=Ls.set;pt(Vt,4,"proxy",Ku,ks,ol);gn(Vt,ks);function Qv(e){return e!=null&&typeof e=="object"&&"current"in e}function Ln(e){var t;if(e!=null)return Qv(e)?(t=e.current)!=null?t:void 0:e}var eb=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",ir=eb?S.useLayoutEffect:S.useEffect;function tb(){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=tb();return ir(()=>{if(!e){n.current.clear();return}return ft(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[d]=a,f=se(()=>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(()=>Fp.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 nb(e,t){e()}function yn(e){const t=S.useRef(e);return ir(()=>{t.current=e},[e]),t}function $e(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 Ii(e,t){const n=S.useRef(Ln(e));ir(()=>{const r=Ln(e);r!==n.current&&(n.current=r,t(r))})}var rb=Object.defineProperty,ib=Object.defineProperties,sb=Object.getOwnPropertyDescriptors,as=Object.getOwnPropertySymbols,Qu=Object.prototype.hasOwnProperty,eh=Object.prototype.propertyIsEnumerable,Xl=(e,t,n)=>t in e?rb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ob=(e,t)=>{for(var n in t||(t={}))Qu.call(t,n)&&Xl(e,n,t[n]);if(as)for(var n of as(t))eh.call(t,n)&&Xl(e,n,t[n]);return e},ab=(e,t)=>ib(e,sb(t)),lb=(e,t)=>{var n={};for(var r in e)Qu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&as)for(var r of as(e))t.indexOf(r)<0&&eh.call(e,r)&&(n[r]=e[r]);return n},cb=new Hu,th=S.createContext(cb),db=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 ir(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),S.useImperativeHandle(t,()=>o),null})),Fs=[void 0,mt];function ub(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:d}=t,f=lb(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:l,modifiers:u,sensors:p}=f,g=xt(l,Nn.plugins),v=xt(p,Nn.sensors),y=xt(u,Nn.modifiers),k=yn(i),h=yn(s),b=yn(a),x=yn(o),w=yn(d),$=yn(r),M=hb(()=>{var A;return(A=f.manager)!=null?A:new Hu(f)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:A,trackRendering:j}=c.current,{monitor:C}=M;M.renderer=A;const I=[C.addEventListener("beforedragstart",T=>{const R=k.current;R&&j(()=>R(T,M))}),C.addEventListener("dragstart",T=>{var R;return(R=h.current)==null?void 0:R.call(h,T,M)}),C.addEventListener("dragover",T=>{const R=b.current;R&&j(()=>R(T,M))}),C.addEventListener("dragmove",T=>{const R=x.current;R&&j(()=>R(T,M))}),C.addEventListener("dragend",T=>{const R=w.current;R&&j(()=>R(T,M))}),C.addEventListener("collision",T=>{var R;return(R=$.current)==null?void 0:R.call($,T,M)})];return()=>I.forEach(T=>T())},[M]),$e(g,()=>M&&(M.plugins=g),...Fs),$e(v,()=>M&&(M.sensors=v),...Fs),$e(y,()=>M&&(M.modifiers=y),...Fs),m.jsxs(th.Provider,{value:M,children:[m.jsx(db,{ref:c,children:n}),n]})}function hb(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 fb(){return S.useContext(th)}function nh(e){var t;const n=(t=fb())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),ir(r.register,[n,r]),r}var pb=Object.create,rh=Object.defineProperty,mb=Object.getOwnPropertyDescriptor,ih=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ss=e=>{throw TypeError(e)},gb=(e,t,n)=>t in e?rh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,vb=e=>{var t;return[,,,pb((t=e?.[ih("metadata")])!=null?t:null)]},sh=["class","method","getter","setter","accessor","field","value","get","set"],oh=e=>e!==void 0&&typeof e!="function"?Ss("Function expected"):e,bb=(e,t,n,r,i)=>({kind:sh[e],name:t,metadata:r,addInitializer:s=>n._?Ss("Already initialized"):i.push(oh(s||null))}),xb=(e,t)=>gb(t,ih("metadata"),e[3]),yb=(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},ah=(e,t,n,r,i,s)=>{for(var o,a,d,f,c=t&7,l=!1,u=!1,p=2,g=sh[c+5],v=e[p]||(e[p]=[]),y=(i=i.prototype,mb(i,n)),k=r.length-1;k>=0;k--)d=bb(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,oh(o)&&(y[g]=o);return y&&rh(i,n,y),i},lh=(e,t,n)=>t.has(e)||Ss("Cannot "+n),wb=(e,t,n)=>(lh(e,t,"read from private field"),t.get(e)),kb=(e,t,n)=>t.has(e)?Ss("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Sb=(e,t,n,r)=>(lh(e,t,"write to private field"),t.set(e,n),n),an=class Ho{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ho(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 Ho(t,n)}},ch,dh,Uo,zi,oi,al=class extends(Uo=pn,dh=[Oe],ch=[Oe],Uo){constructor(e){const t=an.from(e);super(t,(n,r)=>an.equals(n,r)),yb(oi,5,this),kb(this,zi,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-wb(this,zi),o=a=>Math.round(a/s*100);Ce(()=>{Sb(this,zi,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}}};oi=vb(Uo);zi=new WeakMap;ah(oi,2,"delta",dh,al);ah(oi,2,"direction",ch,al);xb(oi,al);var uh=(e=>(e.Horizontal="x",e.Vertical="y",e))(uh||{});Object.values(uh);var $b=({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:er.PointerIntersection,priority:Qn.High}}return null},jb=({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:er.ShapeIntersection,priority:Qn.Normal}}return null},Cb=e=>{var t;return(t=$b(e))!=null?t:jb(e)};function Mb(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,d=nh(c=>new ks(ab(ob({},e),{register:!1,element:Ln(i)}),c)),f=Ju(d);return $e(s,()=>d.id=s),Ii(i,c=>d.element=c),$e(o,()=>d.accept=o,void 0,mt),$e(t,()=>d.collisionDetector=t??Cb),$e(n,()=>n&&(d.data=n)),$e(r,()=>d.disabled=r===!0),$e(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 hh=(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 ${Le}`,...Ht,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},fh=S.createContext(void 0);function ph(e,t){const n=S.useContext(fh),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}=Ve(),[o,a]=S.useState(void 0),d=S.useRef(!1),f=()=>{d.current||o===void 0||(a(void 0),o!==e&&r(o))};ph(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(V,{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}},hh(s)],children:l?t:e})}return m.jsx(Nc,{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 Eb=(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}),Ob=(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},mh=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),gh=e=>`gap.${e}`,Db=(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:ze(e[o-1]),colspan:t-r}),d&&(r=0),n.push(mh(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:ze(i),colspan:t-r}),n};var Ab=Object.create,vh=Object.defineProperty,Tb=Object.defineProperties,Rb=Object.getOwnPropertyDescriptor,Pb=Object.getOwnPropertyDescriptors,ls=Object.getOwnPropertySymbols,bh=Object.prototype.hasOwnProperty,xh=Object.prototype.propertyIsEnumerable,Ib=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ai=e=>{throw TypeError(e)},Ko=(e,t,n)=>t in e?vh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Bs=(e,t)=>{for(var n in t||(t={}))bh.call(t,n)&&Ko(e,n,t[n]);if(ls)for(var n of ls(t))xh.call(t,n)&&Ko(e,n,t[n]);return e},_s=(e,t)=>Tb(e,Pb(t)),zb=(e,t)=>{var n={};for(var r in e)bh.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&&xh.call(e,r)&&(n[r]=e[r]);return n},Wb=e=>{var t;return[,,,Ab((t=void 0)!=null?t:null)]},yh=["class","method","getter","setter","accessor","field","value","get","set"],Mr=e=>e!==void 0&&typeof e!="function"?ai("Function expected"):e,Nb=(e,t,n,r,i)=>({kind:yh[e],name:t,metadata:r,addInitializer:s=>n._?ai("Already initialized"):i.push(Mr(s||null))}),Lb=(e,t)=>Ko(t,Ib("metadata"),e[3]),xi=(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},wh=(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=yh[l+5],y=e[g-1]=[],k=e[g]||(e[g]=[]),h=(i=i.prototype,Rb({get[n](){return Er(this,s)},set[n](x){return on(this,s,x)}},n)),b=r.length-1;b>=0;b--)f=Nb(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?Mr(a)&&(h[v]=a):typeof a!="object"||a===null?ai("Object expected"):(Mr(o=a.get)&&(h.get=o),Mr(o=a.set)&&(h.set=o),Mr(o=a.init)&&y.unshift(o));return h&&vh(i,n,h),i},kh=(e,t,n)=>t.has(e)||ai("Cannot "+n),Er=(e,t,n)=>(kh(e,t,"read from private field"),t.get(e)),fr=(e,t,n)=>t.has(e)?ai("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),on=(e,t,n,r)=>(kh(e,t,"write to private field"),t.set(e,n),n);function ln(e){return e instanceof dl||e instanceof Ch}var yi=10,Fb=class extends Ue{constructor(e){super(e);const t=ft(()=>{const{dragOperation:r}=e;if(Hr(r.activatorEvent)&&ln(r.source)&&r.status.initialized){const i=e.registry.plugins.get(si);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(!Hr(r.nativeEvent)||!ln(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:d}=i,{by:f}=r;if(!f)return;const c=Bb(f),{source:l,target:u}=s,{center:p}=s.shape.current,g=[],v=[];Ce(()=>{for(const w of d.droppables){const{id:$}=w;if(!w.accepts(l)||$===u?.id&&ln(w)||!w.element)continue;let M=w.shape;const A=new $t(w.element,{getBoundingClientRect:j=>Vr(j,void 0,.2)});!A.height||!A.width||(c=="down"&&p.y+yi<A.center.y||c=="up"&&p.y-yi>A.center.y||c=="left"&&p.x-yi>A.center.x||c=="right"&&p.x+yi<A.center.x)&&(g.push(w),w.shape=A,v.push(()=>w.shape=M))}}),r.preventDefault(),a.disable();const y=a.computeCollisions(g,lv);Ce(()=>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:M}=s;if(!w||!ln(w)||!M)return;const{index:A,group:j,target:C}=w.sortable,I=b!==A||x!==j,T=I?C:$?.element;if(!T)return;bu(T);const R=new $t(T);if(!R)return;const N=jt.delta(R,jt.from(M.current.boundingRectangle),w.alignment);o.move({by:N}),I?o.setDropTarget(w.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Bb(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 _b=Object.defineProperty,Vb=Object.defineProperties,qb=Object.getOwnPropertyDescriptors,Zl=Object.getOwnPropertySymbols,Hb=Object.prototype.hasOwnProperty,Ub=Object.prototype.propertyIsEnumerable,Jl=(e,t,n)=>t in e?_b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wn=(e,t)=>{for(var n in t||(t={}))Hb.call(t,n)&&Jl(e,n,t[n]);if(Zl)for(var n of Zl(t))Ub.call(t,n)&&Jl(e,n,t[n]);return e},kn=(e,t)=>Vb(e,qb(t));function Gb(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function wi(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Vs(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Kb(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(Vs(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&&Vs(s)){const h=s.initialGroup==null?void 0:wi(e,s.initialGroup),b=s.initialIndex,x=s.group==null?void 0:wi(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 kn(wn({},e),{[h]:n(e[h],b,w)});const $=e[h][b];return kn(wn({},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=wi(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&&Vs(s)){const h=s.group==null?void 0:wi(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 kn(wn({},e),{[l]:n(e[l],c,s.index)});const $=e[l][c];return kn(wn({},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 kn(wn({},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 kn(wn({},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 Yb(e,t){return Kb(e,t,Gb)}function Ql(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function ec(e,t,n){var r;for(const[i,s]of t)for(const o of s){const a=e.get(o.id);if(o.index!==a||o.group!==i||!((r=n.get(i))!=null&&r.has(o)))return!0}return!1}var tc="__default__",Xb=class extends Ue{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof dl){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=Ql(d),c=o.sortable.group===a.sortable.group,l=d.get(o.sortable.group),u=c?l:d.get(a.sortable.group);!l||!u||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var p,g;const v=t();if(ec(f,d,v))return;const y=o.sortable.element,k=a.sortable.element;if(!k||!y||!c&&a.id===o.sortable.group)return;const h=ki(l),b=c?h:ki(u),x=(p=o.sortable.group)!=null?p:tc,w=(g=a.sortable.group)!=null?g:tc,$={[x]:h,[w]:b},M=Yb($,r);if($===M)return;const A=M[w].indexOf(o.sortable),j=M[w].indexOf(a.sortable);i.collisionObserver.disable(),nc(y,A,k,j),Ce(()=>{for(const[C,I]of M[x].entries())I.index=C;if(!c)for(const[C,I]of M[w].entries())I.group=a.sortable.group,I.index=C}),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=Ql(a),f=a.get(o.sortable.initialGroup);f&&i.renderer.rendering.then(()=>{const c=t();if(ec(d,a,c))return;const l=ki(f),u=ki(f,Jb),p=o.sortable.element,g=u.indexOf(o.sortable),v=l[g],y=v?.element;!v||!y||!p||(nc(p,v.index,y,o.index),Ce(()=>{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 nc(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function Zb(e,t){return e.index-t.index}function Jb(e,t){return e.initialIndex-t.initialIndex}function ki(e,t=Zb){return Array.from(e).sort(t)}var rc=[Fb,Xb],Sh={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function ic(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 Si=new Hm,$h,jh,qt,ll,Or,Dr,cl,An;jh=[oe],$h=[oe];var $s=class{constructor(e,t){fr(this,ll,xi(qt,8,this)),xi(qt,11,this),fr(this,Or),fr(this,Dr),fr(this,cl,xi(qt,12,this)),xi(qt,15,this),fr(this,An),this.register=()=>(Ce(()=>{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=()=>{Ce(()=>{var g,v;(g=this.manager)==null||g.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:d,transition:f=Sh,plugins:c}=n,l=zb(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=xt(c,rc),p=ic(i);this.droppable=new dl(_s(Bs({},l),{disabled:p.droppable}),t,this),this.draggable=new Ch(_s(Bs({},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)&&Si.clear(this.manager),k?.dragging&&Si.set(this.manager,this.id,se(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:v,manager:y}=this,k=Er(this,Dr),h=Er(this,Or);(g!==k||v!==h)&&(on(this,Dr,g),on(this,Or,v),this.animate())},()=>{var g,v;const{target:y}=this,{isDragSource:k}=this.draggable;((v=(g=this.draggable.pluginConfig(Qa))==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,Dr,o),this.group=s,on(this,Or,s),this.type=d,this.transition=f}get initialIndex(){var e,t;return(t=(e=Si.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Si.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){se(()=>{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=Bl(i,a,!1),f=Bl(i,a);if(o.x||o.y){const c=Ha(at(i))?_s(Bs({},t),{duration:0}):t;xu({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){Ce(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ce(()=>{const t=Er(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=Er(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=xt(e,rc)}set disabled(e){const t=ic(e);Ce(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ce(()=>{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??yu}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Ce(()=>{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)}};qt=Wb();ll=new WeakMap;Or=new WeakMap;Dr=new WeakMap;cl=new WeakMap;An=new WeakMap;wh(qt,4,"index",jh,$s,ll);wh(qt,4,"group",$h,$s,cl);Lb(qt,$s);var Ch=class extends ws{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}},dl=class extends ks{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Qb=Object.defineProperty,ex=Object.defineProperties,tx=Object.getOwnPropertyDescriptors,sc=Object.getOwnPropertySymbols,nx=Object.prototype.hasOwnProperty,rx=Object.prototype.propertyIsEnumerable,oc=(e,t,n)=>t in e?Qb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qs=(e,t)=>{for(var n in t||(t={}))nx.call(t,n)&&oc(e,n,t[n]);if(sc)for(var n of sc(t))rx.call(t,n)&&oc(e,n,t[n]);return e},ix=(e,t)=>ex(e,tx(t));function sx(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=qs(qs({},Sh),e.transition),k=nh(b=>new $s(ix(qs({},e),{transition:y,register:!1,handle:Ln(a),element:Ln(o),target:Ln(p)}),b)),h=Ju(k,ox);return $e(i,()=>k.id=i),ir(()=>{Ce(()=>{k.group=f,k.index=d})},[k,f,d]),$e(g,()=>k.type=g),$e(t,()=>k.accept=t,void 0,mt),$e(s,()=>s&&(k.data=s)),$e(d,()=>{var b;(b=k.manager)!=null&&b.dragOperation.status.idle&&y?.idle&&k.refreshShape()},nb),Ii(a,b=>k.handle=b),Ii(o,b=>k.element=b),Ii(p,b=>k.target=b),$e(c,()=>k.disabled=c??!1,void 0,mt),$e(u,()=>k.sensors=u,void 0,mt),$e(n,()=>k.collisionDetector=n),$e(r,()=>k.collisionPriority=r),$e(v,()=>k.plugins=v,void 0,mt),$e(y,()=>k.transition=y,void 0,mt),$e(l,()=>k.modifiers=l,void 0,mt),$e(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 ox(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Yo="tile",Mh="gap",ax=[_o.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Eh}], ${lx}`)!==null||(_o.defaults.preventActivation?.(e,t)??!1)}),qu],Eh="data-no-drag",lx=".malloy-render, .malloy-table",cx=e=>[...e,Qa.configure({feedback:"clone"})];function dx({id:e,index:t,children:n}){const{ref:r,handleRef:i,isDragSource:s}=sx({id:e,index:t,type:Yo,accept:Yo,collisionDetector:Ga,plugins:cx});return m.jsx(m.Fragment,{children:n({ref:r,handleRef:i,isDragSource:s})})}function ux({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=Mb({id:e,type:Mh,accept:Yo,collisionDetector:Ga,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:i})})}const Oh=e=>e.ok===!1,Pe=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),sr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,Se={sourceDefinition:e=>Pe(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Pe(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Pe(e,"VIEW","subQueryDefList"),defDimension:e=>Pe(e,"defList","DIMENSION"),exploreProperties:e=>Pe(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Pe(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Pe(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Pe(e,"WHERE","filterClauseList"),givenDef:e=>Pe(e,"givenNameDef"),givenStatement:e=>Pe(e,"GIVEN","givenDefList"),importStatement:e=>Pe(e,"IMPORT","importURL"),vArrow:e=>Pe(e,"ARROW","vExpr","segExpr"),segRefine:e=>Pe(e,"PLUS","segExpr"),segOps:e=>Pe(e,"queryProperties"),segField:e=>Pe(e,"fieldPath")&&!Pe(e,"segExpr"),segParen:e=>Pe(e,"OPAREN","CPAREN","vExpr"),compare:e=>Pe(e,"fieldExpr","compareOp"),givenRef:e=>Pe(e,"GIVEN_REF")};function hx(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 fx(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
-
`&&t.push(n+1);return t}function Dh(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const i=t.getChild(r);if(!sr(i))continue;const s=De(i,"docAnnotations");if(s)for(const o of Kt(s,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class Ah{constructor(t){this.text=t,this.map=hx(t),this.lineStarts=fx(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!sr(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 li(e,t,n=[]){sr(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)li(e.getChild(r),t,n);return n}const px=e=>Pe(e,"OCURLY","CCURLY");function Xr(e,t){const n=[],r=i=>{if(sr(i)){if(t(i)){n.push(i);return}if(!px(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 De=(e,t)=>e[t]?.call(e),Kt=(e,t)=>e[t]?.call(e)??[];function mx(e,t){if(!Se.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!Se.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 Th(e,t){const n=e.positioned(t);if(!n)return;const r=De(t,"filterClauseList"),i=[];for(const s of r?Kt(r,"fieldExpr"):[]){const o=e.positioned(s);if(!o)continue;const a=li(s,Se.givenRef).map(d=>e.text_(d)).filter(d=>d!==void 0).map(d=>d.replace(/^\$/,""));i.push({...o,givens:a,binding:mx(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 Xr(t,Se.queryStatement)){const c=e.positioned(f);c&&r.push(c);const l=De(f,"whereStatement");if(l&&Se.whereStatement(l)){const u=Th(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 ul(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 gx(e,t){const n=De(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=Se.vArrow(t);if(Se.segOps(n)){const i=De(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(Se.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(Se.segRefine(n)){const i=Kt(n,"segExpr"),s=i[0],o=i[i.length-1];let a=s;for(;Se.segRefine(a);){const u=Kt(a,"segExpr");if(u.some(p=>Se.segOps(p)||Se.segParen(p)))return{kind:"unsupported",why:"a chained refinement"};a=u[0]}if(a&&Se.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!Se.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(!Se.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=De(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 vx(e,t){const n=[];for(const r of Xr(t,Se.defExploreQuery)){const i=e.span(r),s=De(r,"subQueryDefList");if(!i||!s)continue;const o=Kt(s,"exploreQueryDef").filter(Se.exploreQueryDef),a=e.terminal(De(r,"VIEW"));for(const d of o){const f=e.span(d),c=De(d,"exploreQueryNameDef"),l=e.text_(c),u=De(d,"vExpr");!f||!l||!u||n.push({name:l,span:f,line:e.line(f.start),statement:i,tags:ul(e,i,a?.start??f.start),siblings:o.length,body:gx(e,u)})}}return n}function bx(e,t){const n=[];for(const r of Xr(t,Se.defDimension)){const i=e.span(r),s=De(r,"defList");if(!i||!s)continue;const o=e.terminal(De(r,"DIMENSION"));for(const a of Kt(s,"fieldDef")){const d=e.span(a),f=e.text_(De(a,"fieldNameDef"))?.trim(),c=e.text_(De(a,"fieldExpr"))?.trim();!d||!f||c===void 0||n.push({name:f,expression:c,span:d,line:e.line(d.start),statement:i,tags:ul(e,i,o?.start??d.start)})}}return n}function xx(e,t){const n=[];for(const r of li(t,Se.sourceDefinition)){const i=e.span(r),s=e.text_(De(r,"sourceNameDef")),o=De(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=Xr(o,Se.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 Xr(c,Se.whereStatement)){const v=Th(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?vx(e,c):[],dimensions:c?bx(e,c):[],wheres:p})}return n}function yx(e,t){const n=[];for(const r of li(t,Se.givenStatement)){const i=e.terminal(De(r,"GIVEN")),s=De(r,"givenDefList"),o=i?e.line(i.start):void 0;for(const a of s?Kt(s,"givenDef"):[]){const d=e.span(a),f=e.span(De(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:ul(e,d,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function wx(e,t){const n=[];for(const r of li(t,Se.importStatement)){const i=e.span(r),s=e.text_(De(r,"importURL"));if(!i||s===void 0)continue;const o=De(r,"importSelect"),a=o?Kt(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 Rh(e){let t;try{t=await hl(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||!sr(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 Ah(e),d=kx(a,s);a.commentLines=d.lines;const f=e.split(`
|
|
70
|
-
`),c=u=>d.lines.has(u);a.proseLines=Op(f,c),a.blocks=Dp(f,c).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=xx(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:wx(a,i),sources:l,givens:yx(a,i),textBlocks:$x(a,s),modelNotes:Dh(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=>Sx(a,d.lines,u)}}}async function hl(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 kx(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 Sx(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 $x(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=Np(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 Ph(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 Ih(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')r=Ph(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 jx(e,r+s[0].length-1)}}}function jx(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=Ph(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 Cx(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 Mx(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=Cx(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 zh(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=Mx(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const ac=(e,t)=>{try{return e.text(t)}catch{return}},Ex=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Ox=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\`.`,Dx=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=[…]\`.`,Ax="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 Wh(e,t){const n=e.filter(Ex).filter(c=>!c.includes("@env.")).map(zc),{tag:r,errors:i}=n.length>0?zh(t,n):{tag:void 0,errors:[]},s=r?.tag("artifact");if(!s)return e.some(lp)?{status:"unparsed",errors:i}:{status:"none"};const o=ac(s,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=ac(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 Oc();let n=[];try{const r=(await hl(e,"file://report.malloy")).parse?.root;r&&sr(r)&&typeof r.getChild=="function"&&(n=Dh(new Ah(e),r))}catch{n=[]}return Wh(n,t)}const Zo=e=>e.ok===!1;function ci(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 cs=e=>e.map(t=>t.text);function lc(e){const t=cs(e),n=Ap(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:Tp(t)}:{chart:n}}function Tx(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:Rp(i),given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function Rx(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(),...Px(n(cs(ci(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function Px(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 Hs(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 Ix=/^"((?:[^"\\]|\\.)+)"$/,zx=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Jo(e,t,n=!1){try{return await Wx(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 Wx(e){const{parseAnnotation:t}=await Oc(),n=rp(e),r=await Rh(e);if(Oh(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,s=Ic(n).text,o=Wh(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:Ox(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?Dx(o.unknownLayout):Ax};const a=o.layout,d=oa(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}=zh(t,[zc(d.text)]),l=f?.tag("artifact"),u=Ih(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 M={name:$.name,base:$.base};$.dimensions.length>0&&(M.dimensions=$.dimensions.map(j=>({name:j.name,expression:j.expression})));const A=new Set($.wheres.flatMap(j=>j.clauses.flatMap(C=>C.givens)));A.size>0&&(M.scopedBy=Array.from(A)),g.push(M);for(const j of $.dimensions){const C=t(cs(ci(i,n,j.line).tags)).tag?.tag("drill");if(!C)continue;const I=C.textArray("to")??[C.text("to")??""];v.push({source:$.name,name:j.name,expression:j.expression,to:I.filter(Boolean),...C.text("given")?{given:C.text("given")}:{}})}y.set($.name,new Map($.views.map(j=>[j.name,j])))}const k=[];for(const{text:$}of u.entries){const M=Ix.exec($),A=M?void 0:zx.exec($)?.[1];if(A!==void 0){const D=t([`# ${$}`]).tag?.tag(A);if(D?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${$}\` is neither a quoted \`source -> view\` expression nor a \`${A} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(k.some(F=>Ae(F)&&F.name===A))return{ok:!1,reason:`Two text tiles are named \`${A}\`, so the builder cannot tell them apart.`};const W=Hs(D,"colspan");k.push({kind:"text",name:A,markdown:i.textBlocks.find(F=>F.name===A)?.body??"",...W===void 0?{}:{colspan:W},...D.has("break")?{break:!0}:{}});continue}const j=M?.[1]??$,C=M?op(j):void 0;if(!C)return{ok:!1,reason:`The tile \`${j}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:I,view:T}=C,R=y.get(I)?.get(T);if(R===void 0){k.push({name:T,source:I,declaration:{kind:"inherited"}});continue}const N=t(cs(R.tags)).tag,H=R.body.kind==="reference"?{kind:"reference",from:R.body.from}:R.body.kind==="inline"?{kind:"inline"}:void 0;if(H===void 0){k.push({name:T,source:I,declaration:{kind:"opaque",why:R.body.kind==="unsupported"?R.body.why:"unreadable"},...N?.text("label")?{label:N.text("label")}:{},...N?.text("subtitle")?{subtitle:N.text("subtitle")}:{},...N?.numeric("colspan")!==void 0?{colspan:N.numeric("colspan")}:{},...lc(R.tags),...N?.has("break")?{break:!0}:{},...N?.has("borderless")?{borderless:!0}:{}});continue}const B=Tx(R.body.kind==="reference"?R.body.refinement:R.body.kind==="inline"?R.body.stage:void 0);k.push({name:T,source:I,declaration:H,...B?{filters:B}:{},...N?.text("label")?{label:N.text("label")}:{},...N?.text("subtitle")?{subtitle:N.text("subtitle")}:{},...N?.numeric("colspan")!==void 0?{colspan:N.numeric("colspan")}:{},...lc(R.tags),...N?.has("break")?{break:!0}:{},...N?.has("borderless")?{borderless:!0}:{}})}const h=Rx(i,n,t),b={},x=l?.tag("givens");for(const $ of Object.keys(x?.dict??{})){const M=x?.text($);M!==void 0&&(b[$]=M)}const w=f?.tag("dashboard")?.has("columns")?Hs(f.tag("dashboard"),"columns"):l?.array("tiles")?Hs(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 cc(e){const{problems:t}=await hl(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 Nh(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Nx(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
-
`&&t.push(n+1);return t}function Lx(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 Lh=e=>e==="none"||da(e)?e:void 0;function Fh(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=${bt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${bt(e.subtitle)}`);const r=t?Lh(e.chart):void 0;return r!==void 0&&n.push(cn(r,e.chartCarried)),n}function Wi(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Fx=new Set(["colspan","break","borderless","label","subtitle"]),Bx=new Set(["label","description","control","suggest","range_min","range_max"]);function dc(e){const t=[];if(e.label!==void 0&&t.push(`label=${bt(e.label)}`),e.description!==void 0&&t.push(`description=${bt(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=${bt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${bt(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 uc=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function _x(e,t,n){const r=e.sources.find(i=>i.name===t)?.views.find(i=>i.name===n);return r?r.line:-1}function hc(e){const t=n=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(n)?n:bt(n);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(bt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const ds=e=>`${e.source}.${e.name}`,bt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,ea=e=>Ae(e)?ye(["text",e.name]):ye([e.name,e.source,e.declaration]),ut=ea,fc=e=>ye(e.tiles.map(ut));function Vx(e,t,n){const r=new Set(e.tiles.map(ut)),i=new Set(t.tiles.map(ut)),s=e.tiles.filter(u=>!i.has(ut(u))),o=t.tiles.filter(u=>!r.has(ut(u))),a=s.length>0||o.length>0||fc(e)!==fc(t);for(const u of o)if(ue(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=>ue(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 pc=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function qx(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Zr(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function mc(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=qx(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 Hx(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(Ae).map(h=>[h.name,h])),c=i.tiles.filter(Ae).some(h=>{const b=f.get(h.name);return b!==void 0&&pc(b,h)});if(!s&&!c)return;const l=oa(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,p=Ih(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(ut(h));if(Ae(h)){const x=g.get(`text.${h.name}`);return x!==void 0?f.has(h.name)&&!pc(f.get(h.name),h)?x:mc(h,x):b?mc(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=[${Ux(u,p,v)}]${u.slice(p.close+1)}`;k!==u&&d.push({...Bh(n,l),text:`${k}
|
|
78
|
-
`})}function Bh(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Ux(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 Gx(e,t){let n=0,r=0;for(let i=0;i<e.length;i++){const s=e[i];if(s==='"')i=Zr(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]==='"'?Zr(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 Kx(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Zr(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=Zr(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 Zr(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 Yx(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=oa(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=Bh(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?bt(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}=${bt(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=Gx(f,"dashboard_columns"),f=Kx(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}=Ic(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=Nh(i.description??"").split(`
|
|
87
|
-
`).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
|
|
88
|
-
`),u=o.length>0&&o[0]<xl(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(xl(t)).start;s.push({start:v,end:v,text:`${l}
|
|
90
|
-
`})}}}function Xx(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}=ci(a,t,y.line),b=[...(v===void 0?k:k.filter(A=>{const j=Wi(A.text);return j!==void 0&&Bx.has(j)})).map(A=>A.line),...v===void 0?h:[]];for(const A of b)o.push({...n(A),text:""}),l.add(A);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 R=y.line;R<=x;R++)l.add(R);const A=Math.min(y.line,...b),j=y.blockHeader??A,C=(t[x+1]??"x").trim()==="",I=j===0||t[j-1].trim()==="",T=y.blockHeader===void 0||![...c.values()].some(R=>R.blockHeader===y.blockHeader&&R.line>y.line&&f.has([...c.entries()].find(([,N])=>N===R)?.[0]??""));C&&I&&T&&!l.has(x+1)&&(o.push({...n(x+1),text:""}),l.add(x+1));continue}const w=r(y.line),$=dc(v),M=v.type!==g.type||v.default!==g.default?y.blockHeader===void 0?uc(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}${M}
|
|
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=dc(h);return(b?`${b}
|
|
94
|
-
`:"")+`${uc(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 gc=(e,t)=>`import { ${e.join(", ")} } from ${bt(t)}`;function Zx(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(ue).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?fl(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?"":gc(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=>`${gc(p.names,p.from)}
|
|
99
|
-
`).join("")})}}function Jx(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,d=new Map((i.drills??[]).map(c=>[ds(c),c])),f=new Map((s.drills??[]).map(c=>[ds(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}=ci(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}${hc(u)}
|
|
100
|
-
`});else{const h=n(g.line).start;o.push({start:h,end:h,text:`${k}${hc(u)}
|
|
101
|
-
`})}}}function Qx(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if(Ae(o)||o.declaration.kind==="inherited")continue;const a=_h(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({...fl(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 ey(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(Ae(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: ${ca(y.field)} ${y.op??"~"} $${y.given}`).join(", ");return[...Fh(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 ty(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=>[ut(c),c]));for(const c of o.tiles){const l=f.get(ut(c));if(l===void 0||Ae(c)||Ae(l)||ye(us(l))===ye(us(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=_x(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}=ci(d,t,u),g=i(u),v=Fh(c,!1),y=new Map(v.map(j=>[Wi(j)??j,j])),k=new Set,h=Lh(c.chart),b=vc(l)!==vc(c);if(b){const j=p.filter(T=>yl(T.text)),C=p.filter(T=>Os(T.text)),I=l.chart==="custom"?p.filter(T=>Os(T.text)||yl(T.text)):j.length>0?j:C.length>1?C:[];if(I.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${I.map(T=>T.text).join(" and ")}), so its chart cannot be changed here.`}}let x=!1;for(const j of p){if(b&&Os(j.text)){h===void 0?a.push({...r(j.line),text:""}):j.text!==cn(h,c.chartCarried)&&a.push({...r(j.line),text:`${g}${cn(h,c.chartCarried)}
|
|
115
|
-
`}),x=!0;continue}const C=Wi(j.text);if(C===void 0||!Fx.has(C))continue;const I=y.get(C);if(I===void 0){a.push({...r(j.line),text:""});continue}k.add(C),I!==j.text&&a.push({...r(j.line),text:`${g}${I}
|
|
116
|
-
`})}const w=v.filter(j=>!k.has(Wi(j)??j));if(b&&h!==void 0&&!x&&w.push(cn(h,c.chartCarried)),w.length>0){const j=n[u];a.push({start:j,end:j,text:w.map(C=>`${g}${C}
|
|
117
|
-
`).join("")})}if(ye(l.filters)===ye(c.filters))continue;const $=_h(e,c);if(!$)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if($.body.kind==="reference"){const j=ly(e,c,$);if(j)return j;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 M=Vh(c.filters,$.body.stage);if(M)return qh(c.name,M.given);const A=Hh(e,c,$.body.stage);if(A)return A}}const vc=e=>e.chart==="default"?void 0:e.chart,us=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:i,...s}=r;return s};function ny(e,t){const n=new Map(e.tiles.map(r=>[ut(r),r]));return{...t,tiles:t.tiles.map(r=>{const i=n.get(ut(r));return ue(r)&&r.chart===void 0&&i&&ue(i)&&i.chart!==void 0?{...r,chart:i.chart}:r})}}function Ni(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 ry(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&&!Lp(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=Ni(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 Us=e=>`##|(markdown) ${e.name}
|
|
118
|
-
${e.markdown===""?"":`${e.markdown}
|
|
119
|
-
`}|##
|
|
120
|
-
`;function iy(e){const{sourceText:t,lines:n,wholeLine:r,current:i,next:s,parsed:o,edits:a}=e,d=new Map(i.tiles.filter(Ae).map(p=>[p.name,p])),f=s.tiles.filter(Ae),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(Us(p))}else g.markdown!==p.markdown&&(v?a.push({...v.span,text:Us(p)}):u.push(Us(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 $i=(e,t=to)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function sy(e,t){const n=new Map(e.tiles.map(o=>[ut(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(ut(o));if(Ae(o)){const l=ry(o,a&&Ae(a)?a:void 0,r);if(l)return l;continue}const d=a&&ue(a)?a:void 0;if(a&&!d)continue;const f=o.chart;if(f!==void 0&&f!=="default"&&f!=="none"&&!da(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=$i(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=bn(`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=$i(a);if(d)return d}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=bn("description line",o);if(a)return a}if(t.title!==e.title){const o=bn("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=$i(o.name,Lc);if(f)return f}const d=o.suggest?.source;if(d!==void 0&&d!==a?.suggest?.source){const f=$i(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=bn(`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=bn(`given ${f}`,c);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const d=bn(`starting value for ${o}`,a);if(d)return d}}const Rt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function _h(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Vh(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 qh(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 Li=e=>`where: ${ca(e.field)} ${e.op??"~"} $${e.given}`;function bc(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 oy(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 ay(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 fl(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 Hh(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=fl(r,u.span),y=oy(r,u.span,v);if(y)return bc(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=ay(u.clauses,k),w=r.commentIn(x);if(w)return bc(t.name,r,w);i.push({...x,text:""});continue}const b=Li(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(Li).join(", ")}`:d.map(u=>`
|
|
138
|
-
${n.indent}${Li(u)}`).join("");i.push({start:f,end:f,text:l})}function ly(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:s}=n.body,o=Vh(t.filters,s);if(o)return qh(t.name,o.given);const a=t.filters??[];if(!s){if(a.length===0)return;const c=` + { ${a.map(Li).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 Hh(e,t,s)}async function cy(e,t,n={}){if(!(e.includes(`\r
|
|
139
|
-
`)&&!/(?<!\r)\n/.test(e)))return xc(e,t,n);const r=await xc(e.replace(/\r\n/g,`
|
|
140
|
-
`),t,n);return Qo(r)?r:{...r,source:r.source.replace(/\n/g,`\r
|
|
141
|
-
`)}}async function xc(e,t,n){const r=await Jo(e);if(Zo(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const i=r.document,s=ny(i,t),o=Vx(i,s,n.visibleSources);if("reason"in o)return o;const a=sy(i,s);if(a)return{ok:!1,reason:a};const d=await Rh(e);if(Oh(d))return{ok:!1,reason:`Cannot edit a file that will not open: ${d.reason}`};const f=e.split(`
|
|
142
|
-
`),c=Nx(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[Hx,Yx,Zx,Xx,Jx,Qx,ey,ty,iy]){const b=h(g);if(b)return b}const v=h=>{const{drills:b,localGivens:x,description:w,...$}=h,M=h.tiles.map(A=>{if(Ae(A))return A;if(A.filters?.length)return us(A);const{filters:j,...C}=A;return us(C)});return{...$,...w===void 0?{}:{description:Nh(w)},tiles:M,...b?.length?{drills:[...b].sort((A,j)=>ds(A).localeCompare(ds(j)))}:{},...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=Lx(e,p);if((await cc(e)).length===0){const h=await cc(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 Jo(y);return Zo(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 Uh({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=Ve(),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}=Uc(f,a,x=>n(x.text),()=>d(!1)),g=a&&c!==void 0&&c.text!==e,v=c!==void 0&&c.text!==e?Ni(c.text):void 0;ph(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()?Ni(e):void 0;return m.jsxs(V,{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},hh(i,"prose")],children:[e.trim()?m.jsx(yp,{variant:r,children:e}):m.jsx(pe,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),x&&m.jsx(pe,{variant:"caption",color:"error",role:"alert",children:x})]})}const h=c.text!==e?Ni(c.text):void 0,b=()=>{h===void 0&&u()};return m.jsxs(V,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx(Nc,{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(pe,{variant:"caption",color:"error",role:"alert",children:h}),m.jsxs(pe,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",dn,"↩ done · Esc cancels"]})]})}const dy="Write markdown: # heading, **bold**, - list";function uy({tile:e,onChange:t}){return m.jsx(Ac,{sx:{overflow:"visible"},children:m.jsx(Uh,{markdown:e.markdown,placeholder:dy,onCommit:t})})}const hy={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Gh=(e,t)=>t===0?e:Gh(t,e%t);function fy(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Gh(e,t),i=hy[`${e/r}/${t/r}`];return i?`${n} · ${i}`:n}function py({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}=Ve(),h=k.ui;return m.jsx(dx,{id:ze(e),index:t,children:({ref:b,handleRef:x})=>m.jsxs(V,{ref:b,onClick:a,onPointerDown:w=>{w.button===0&&a()},role:"group",className:Je.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":ze(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Kh(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(V,{ref:x,"aria-label":`Move ${ur(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(dp,{label:`Remove ${ur(e)}`,onRemove:f,...c?{disabledReason:c}:{},inset:s?Wc:0}),!Ae(e)&&m.jsx(Fn,{className:"builder-affordance",size:"small","aria-label":`Settings for ${ur(e)}`,onClick:w=>{w.stopPropagation(),d(w.currentTarget)},sx:{position:"absolute",top:s?0:`${yc}px`,right:s?0:`${yc}px`,borderRadius:h.radius.control,width:28,height:28,zIndex:2,color:"text.secondary",bgcolor:"action.hover",opacity:n||i?1:0,transition:`opacity ${Le}`,...Ht,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(by,{})}),p&&m.jsx(V,{className:`builder-affordance ${Je.widthHandle}`,[Eh]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${ur(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 ${Le}`,...Ht,"&: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:Yt(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 ${Le}`},"&::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(V,{"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:fy(u.span,u.columns)})}),o&&m.jsx(Fn,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${ur(e)}`,onClick:w=>{w.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${In/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 ${Le}`,...Ht,"&:hover, &:focus-visible":{opacity:1,bgcolor:k.tile}},children:m.jsx(Jr,{sx:{fontSize:14}})})]})})}const yc=14,Gs=7,Kh=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:i=Wc})=>{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 ${Le}, border-color ${Le}, opacity ${Le}, box-shadow ${Le}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:typeof i=="number"?`${-i}px`:`${-i.y}px ${-i.x}px`,borderRadius:1,border:`2px solid ${o}`,...a&&{boxShadow:a},pointerEvents:"none",transition:d,...Ht}}:{borderRadius:s.radius.tile,"& > .MuiPaper-root":{transition:d,...Ht,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:d,...Ht,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:hs(e.cardBorder,e.tileTitle)}}}}};function my({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=Ve();return m.jsxs(Js,{chrome:r,children:[m.jsx(Qs,{title:t?.title??zn(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx(pe,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),m.jsxs(pe,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function gy({after:e}){const{theme:t}=Ve();return m.jsx(ux,{id:gh(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx(V,{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 ${Le}, background-color ${Le}`,...Ht}})})}function vy({columns:e}){const{theme:t}=Ve();return m.jsx(V,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${In}px`},children:Array.from({length:e},(n,r)=>m.jsx(V,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function by(){return m.jsxs(Ip,{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 xy({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:M,startResize:A,onResize:j,endResize:C}=n,I=B=>B.colspan===void 0?{...B,colspan:i}:B,T=(M!==void 0?e.document.tiles.map((B,D)=>D===M.index?{...B,colspan:M.span}:B):h??e.document.tiles).map(I),R=e.document.tiles.length===0,N=k||M!==void 0?Db(T,$):T.map(mh),H=B=>yy(B,zn(B),v);return m.jsxs(m.Fragment,{children:[m.jsx(ub,{sensors:ax,onDragStart:b,onDragOver:x,onDragEnd:w,children:m.jsxs(V,{ref:r,sx:{position:"relative"},children:[s.widths&&(k||M!==void 0)&&m.jsx(vy,{columns:$}),m.jsx(Df,{tiles:N,columns:$,rowGapPx:In,keyOf:B=>B.kind==="gap"?gh(B.after):ze(B.tile),renderTile:B=>{if(B.kind==="gap")return m.jsx(gy,{after:B.after});const{tile:D,index:W}=B;return m.jsx(py,{tile:D,index:W,selected:W===a,flash:ze(D)===d,menuOpen:f===W,bare:Ae(D),...s.insertBetween&&o&&W<e.document.tiles.length-1?{onInsertAfter:()=>g(W+1)}:{},...s.widths&&wy(D)?{resizing:M?.index===W,width:{span:D.colspan??1,columns:$,onStep:F=>{F!==(D.colspan??1)&&e.update(z=>{const _=z.tiles[W];_&&(_.colspan=F)})}},onResizeStart:F=>A(F,W),onResizeMove:j,onResizeEnd:C}:{},onSelect:()=>c(W),onOpenMenu:F=>l(F,W),onRemove:()=>u(W),...p?{removeBlocked:p}:{},children:Ae(D)?m.jsx(uy,{tile:D,onChange:F=>v(ze(D),z=>{Ae(z)&&(z.markdown=F)})}):y?y(D,H(D),"card"):m.jsx(my,{tile:D,heading:H(D)})})}})]})}),s.insertBetween&&o&&!R&&m.jsx(Me,{size:"small",startIcon:m.jsx(Jr,{}),"aria-label":"Add tile at the end",onClick:()=>g(),sx:{alignSelf:"center"},children:"Add tile"})]})}const yy=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=ze(e),i=s=>o=>n(r,a=>{ue(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")})}},wy=e=>Ae(e)||e.declaration.kind!=="inherited",ky={x:12,y:6};function Sy({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:i}){const{theme:s}=Ve();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(V,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:i,onFocus:i,children:m.jsx(Ac,{sx:{position:"relative",overflow:"visible",...Kh(s,{selected:r,bare:!0,ringOffset:ky})},children:m.jsx(Uh,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const $y=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:s}=Mc({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 jy(e,t){const n=S.useRef(t);n.current=t;const r=S.useRef(e);r.current=e;const i=S.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.()}),[]),{status:s,saveTarget:o,canUndo:a,canRedo:d,add:{filterUnavailable:f}}=t,c=t.save!==void 0,l=t.add.tile!==void 0,u=t.add.text!==void 0,p=t.add.filter!==void 0,g=t.exit!==void 0,v=t.done!==void 0,y=t.discard!==void 0,{draftKeptAt:k}=t,h=t.restored?.savedAt,b=t.restored?.stale??!1,x=t.restored?.pending??!1,w=t.restore!==void 0,$=t.dismissRestored!==void 0,M=S.useMemo(()=>({status:s,saveTarget:o,...c?{save:i.save}:{},canUndo:a,undo:i.undo,canRedo:d,redo:i.redo,add:{...l?{tile:i.addTile}:{},...u?{text:i.addText}:{},...p?{filter:i.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...g?{exit:i.exit}:{},...v?{done:i.done}:{},...k!==void 0?{draftKeptAt:k}:{},...y?{discard:i.discard}:{},...h!==void 0?{restored:{savedAt:h,stale:b,pending:x}}:{},...w?{restore:i.restore}:{},...$?{dismissRestored:i.dismissRestored}:{}}),[i,s,o,c,a,d,l,u,p,f,g,v,k,y,h,b,x,w,$]);S.useEffect(()=>{r.current?.(M)},[M,e!==void 0]),S.useEffect(()=>()=>r.current?.(void 0),[])}function Cy({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(Tf,{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 My(e,t){const n=new Map(e.tiles.map((r,i)=>[ze(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(ze(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return ze(i)}}function Ey({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(Oy)===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=My(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:Of()}))},[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 Oy=["[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 Dy({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 Ay({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 D=Lt(),{structural:W}=e,F=y.current.size;return e.save().then(z=>{z.ok===!0?y.current.saved({size:F,structural:W,durationMs:Lt()-D}):y.current.refused(z.reason)}).finally(()=>u(!1))},[e]),M=S.useRef(!1),A=S.useRef(!1);S.useEffect(()=>{!A.current||l||(A.current=!1,v.current?.focus())},[p,l]);const j=S.useCallback(()=>{if(!t||l||M.current||!e.canUndoSave)return;M.current=!0,u(!0);const D=Lt(),W=e.lastSave?.structural??!1,F=y.current.size;return e.undoSave().then(z=>{z.ok===!0?(A.current=!0,g(!0),y.current.undone({size:F,structural:W,durationMs:Lt()-D})):y.current.undoRefused(z.reason)}).finally(()=>{M.current=!1,u(!1)})},[t,l,e]),C=S.useCallback(()=>{if(!(!t||!e.dirty||l))return $()},[t,e,l,$]),I=S.useRef(C);I.current=C;const T=S.useCallback(()=>{const D=()=>I.current();return f?f(D):D()},[f]),R=Dy({dirty:h,saving:l,canSave:!!t,save:T,onExit:()=>r?.()});Kp(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:T}:{},paused:R.dialog.open}),[c,e,t,T,R.dialog.open]));const N=!!t&&!l&&e.canUndoSave,H=e.lastSave,B={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:k,saving:l,saveButton:v,...t?{onSave:T}:{},...r?{onExit:R.requestExit}:{}};return{saving:l,save:T,exitGuard:R,...r?{done:R.saveAndExit}:{},undoSave:j,canUndoSave:N,lastSave:H,toolbarProps:B}}const Ty=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 Ry(e){const t=new Map;for(const n of Xh(e))t.set(n.name,Yh(n.schema?.fields,"",Ty));return t}function Xh(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 Py=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&Ep.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Iy(e){const t=new Map;for(const n of Xh(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(Py)&&r.add(i.name)}t.set(n.name,r)}return t}function wc(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const kc=(e,t)=>e!==void 0&&t.has(e),Sc=e=>e.path||e.modelPath||"";function zy(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=Sc(a);if(kc(d,t))continue;const f=Ef(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=Sc(a);if(kc(d,t))continue;const f=Ry(a),c=Iy(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],...hi(l.annotations)?{description:hi(l.annotations)}:{},views:(l.views??[]).filter(g=>typeof g.name=="string").map(g=>({name:g.name,...hi(g.annotations)?{description:hi(g.annotations)}:{},...vl(g.annotations)?{chart:vl(g.annotations)}:{},...c.get(u)?.has(g.name)?{aggregateOnly:!0}:{}})),givens:p,fields:f.get(u)??[]})}}return{sources:n}}function Wy({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(()=>cm(e.document,o),[e.document,o]),d=S.useMemo(()=>new Map(e.document.sources.map(u=>[u.name,wc(r,u.base)])),[r,e.document.sources]),f=S.useCallback(u=>d.get(u.source)??wc(r,u.source),[d,r]),c=(u,p)=>{const g=[];for(const v of e.document.tiles){if(!ue(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)||!Tr(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&&vm(v,g),gm(v,u,p)})},dropControl:u=>{s(void 0),e.update(p=>bm(p,u))}}}function Ny(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),$=z=>{b.current=z,w(z)},[M,A]=S.useState(void 0),j=S.useCallback(z=>{c(void 0),o(_=>{const Q=structuredClone(_.stack[_.index]);if(z(Q),JSON.stringify(Q)===JSON.stringify(_.stack[_.index]))return _;const G=[..._.stack.slice(0,_.index+1),Q].slice(-100);return{stack:G,index:G.length-1}})},[]),C=S.useCallback(()=>{c(void 0),o(z=>z.index>0?{...z,index:z.index-1}:z)},[]),I=S.useCallback(()=>{c(void 0),o(z=>z.index<z.stack.length-1?{...z,index:z.index+1}:z)},[]),T=S.useCallback(async(z,_)=>{try{return await t(z,_)}catch(Q){return{ok:!1,reason:`Could not build the file: ${Q instanceof Error?Q.message:String(Q)}`}}},[t]),R=S.useCallback(async()=>{if(b.current)return{ok:!1,reason:"A save is still being written."};const z={source:a,saved:l,history:h.current,replacing:p,unwritten:v},_=i?.(l,k)??!1,Q=r?.(l,k)??!1;$(!0);try{const G=await T(a,k);if(Qo(G))return c(G.reason),{ok:!1,reason:G.reason};try{await n?.(G.source,{purpose:"save",document:k})}catch(Z){const L=`Could not save: ${Z instanceof Error?Z.message:String(Z)}`;return c(L),{ok:!1,reason:L}}d(G.source),u(k),g(void 0),y(!1);const ne=_?{stack:[k],index:0}:z.history;return o(Z=>Z===z.history?ne:_?{stack:[Z.stack[Z.index]],index:0}:Z),A(n?{before:z,after:ne,lastSave:{before:p??a,after:G.source,structural:Q,clearsHistory:_}}:void 0),c(void 0),{ok:!0}}finally{$(!1)}},[k,T,n,a,l,p,v,i,r]),N=S.useCallback(async()=>{if(b.current)return{ok:!1,reason:"A save is still being written."};if(!n||M===void 0||M.after!==h.current)return{ok:!1,reason:"There is no save to undo."};const{before:z}=M;$(!0);try{await n(z.replacing??z.source,{purpose:"undo",document:z.saved})}catch(_){const Q=`Could not undo the save: ${_ instanceof Error?_.message:String(_)}`;return c(Q),{ok:!1,reason:Q}}finally{$(!1)}return d(z.source),u(z.saved),g(z.replacing),y(z.unwritten||z.replacing!==void 0),o(_=>_===M.after?z.history:_),A(void 0),c(void 0),{ok:!0}},[n,M]),H=S.useMemo(()=>v||JSON.stringify(k)!==JSON.stringify(l),[k,l,v]),B=S.useMemo(()=>r?.(l,k)??!1,[k,l,r]),D=S.useMemo(()=>i?.(l,k)??!1,[k,l,i]),W=M!==void 0&&M.after===s,F=S.useCallback(async()=>{const z=await T(a,k);return Qo(z)?{ok:!1,reason:z.reason}:{ok:!0,source:z.source}},[k,T,a]);return{document:k,saved:l,source:a,canUndo:s.index>0,canRedo:s.index<s.stack.length-1,dirty:H,edited:H,...f===void 0?{}:{error:f},update:j,undo:C,redo:I,save:R,preview:F,structural:B,clearsHistory:D,canUndoSave:W&&!x&&n!==void 0,...W?{lastSave:M.lastSave}:{},undoSave:N}}const Ly=(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 Fy(e){const{visibleSources:t,...n}=e,r=S.useCallback((i,s)=>cy(i,s,t?{visibleSources:t}:{}),[t]);return Ny({...n,splice:r,structural:Ly})}function By({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 _y({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=>Qp(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(Ae).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($=>ze($)===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&&ue(b)&&Hi(b)===void 0?h+1:void 0;e.update(w=>{em(w,h)}),x!==void 0&&i(x)}}}var Vy=Object.defineProperty,qy=Object.defineProperties,Hy=Object.getOwnPropertyDescriptors,$c=Object.getOwnPropertySymbols,Uy=Object.prototype.hasOwnProperty,Gy=Object.prototype.propertyIsEnumerable,jc=(e,t,n)=>t in e?Vy(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sn=(e,t)=>{for(var n in t||(t={}))Uy.call(t,n)&&jc(e,n,t[n]);if($c)for(var n of $c(t))Gy.call(t,n)&&jc(e,n,t[n]);return e},$n=(e,t)=>qy(e,Hy(t));function Ky(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ji(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Ks(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Yy(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(Ks(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&&Ks(s)){const h=s.initialGroup==null?void 0:ji(e,s.initialGroup),b=s.initialIndex,x=s.group==null?void 0:ji(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 $n(Sn({},e),{[h]:n(e[h],b,w)});const $=e[h][b];return $n(Sn({},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=ji(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&&Ks(s)){const h=s.group==null?void 0:ji(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 $n(Sn({},e),{[l]:n(e[l],c,s.index)});const $=e[l][c];return $n(Sn({},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 $n(Sn({},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 $n(Sn({},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 Xy(e,t){return Yy(e,t,Ky)}function Zy({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===Mh){const{after:p}=c.data,g=l.findIndex(y=>ze(y)===f.id);if(g<0||p===f.id)return;const v=l.filter((y,k)=>k!==g).findIndex(y=>ze(y)===p)+1;u=Ob(l,g,v)}else{const p=l.map(ze),g=Xy(p,d);if(g.every((y,k)=>y===p[k]))return;const v=new Map(l.map(y=>[ze(y),y]));u=Eb(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=>ze(l)===d.operation.source?.id);c>=0&&n(c)}}}const Ys=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Jy({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(()=>()=>Ys(!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),Ys(!0),r(c);const p=e[c]?.colspan??1;d({index:c,span:p,from:p,left:u.left,track:(l.width-In*(t-1))/t})},onResize:f=>{const c=a.current;if(!c)return;const l=f.clientX-c.left,u=Math.round((l+In)/(c.track+In)),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),Ys(!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 Zh({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,onExit:s,renderTile:o,renderViewPreview:a,controls:d,givens:f,catalog:c,toolbar:l,dashboards:u,onEvent:p,savesTo:g="package",saveLabel:v,replaces:y,modelPath:k,visibleSources:h,addFilterDisabledReason:b,fixedFilters:x,onOpenModel:w,takenGivenNames:$,onControlsChange:M,draftKey:A}){const j=Fy({source:e,document:t,...n?{onSave:n}:{},...y!==void 0?{replaces:y}:{},...h?{visibleSources:h}:{}}),C=pf(A,j,e),I=S.useRef(null),{selected:T,descriptionSelected:R,selectTile:N,deselectTile:H,selectDescription:B,clearSelection:D,flash:W,stepEditor:F}=Ey({editor:j,gridBox:I}),z=mf(j.document.layout,j.document.columns),{columns:_}=z,Q=k?.split("/").at(-1)?.replace(/\.malloy$/,""),G=Zy({tiles:j.document.tiles,commit:U=>j.update(de=>{de.tiles=U}),onLanded:N}),{dragging:ne}=G,Z=gf(I,_),L=S.useMemo(()=>j.document.tiles.map(U=>U.colspan===void 0?{...U,colspan:Z}:U),[j.document.tiles,Z]),J=Jy({tiles:L,columns:_,gridBox:I,onStart:N,commit:(U,de)=>j.update(ve=>{const ie=ve.tiles[U];ie&&(ie.colspan=de)})}),re=_y({editor:j,rules:z,modelPath:k,textHeld:h!==void 0,selectTile:N,deselectTile:H}),{menu:ce,addingTile:ee,openAdd:we}=re,me=Wy({editor:j,opened:t,givens:f,catalog:c}),{filterDialog:K,setFilterDialog:ke}=me,[fe,le]=S.useState(void 0),{draftDirty:Fe,openDraft:Ge,prepare:qe}=By({editorDirty:j.dirty}),Ke=S.useMemo(()=>({escape:()=>{!ce&&!K&&!ee&&fe===void 0&&D()},nudge:U=>{if(ne||T===void 0||!z.widths)return;const de=j.document.tiles[T];if(!de||ue(de)&&de.declaration.kind==="inherited")return;const ve=vf(de.colspan??Z,U,_);ve!==(de.colspan??Z)&&j.update(ie=>{ie.tiles[T].colspan=ve})}}),[Z,j,ce,K,ee,fe,D,T,_,z,ne]),Re=Ay({editor:F,extraDirty:Fe,keepsEdits:A!==void 0&&C.keeping,prepare:qe,unit:{name:"tile",count:U=>U.tiles.length},onSave:n,onDirtyChange:i,onExit:s,onChange:r,shortcuts:Ke,report:$y({size:j.document.tiles.length,path:k??"",layout:j.document.layout,savesTo:g,onEvent:p})}),E=j.document.tiles.length===0,{toolbarProps:P}=Re,q=C.restored,O={status:Re.saving?"saving":P.dirty?"unsaved":"saved",saveTarget:v??oo[g],...C.keptAt!==void 0?{draftKeptAt:C.keptAt}:{},...(P.dirty||q?.pending)&&A!==void 0?{discard:C.discard}:{},...q?{restored:q}:{},...q&&!q.pending?{dismissRestored:C.dismissRestored}:{}};jy(M,{...O,...P.onSave?{save:P.onSave}:{},canUndo:P.canUndo,undo:P.onUndo,canRedo:P.canRedo,redo:P.onRedo,add:{...c?{tile:()=>re.openAdd()}:{},text:re.appendText,...b!==void 0?{filterUnavailable:b}:E?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>ke({})}},...P.onExit?{exit:P.onExit}:{},...Re.done?{done:Re.done}:{},...q?.pending?{restore:C.restoreOffered}:{}});const te=M?void 0:m.jsx(Yp,{...Re.toolbarProps,...l?{actions:l}:{},...c?{onAddTile:()=>we()}:{},savesTo:g,...v?{saveLabel:v}:{},...A!==void 0&&P.onSave?{saveStatus:O}:{}});return m.jsx(fh.Provider,{value:Ge,children:m.jsx(tt,{className:Je.builder,"data-saves-to":g,sx:{gap:0,mx:`-${Gs}px`},children:m.jsxs(bf,{layout:z.layout,sx:{px:`${Gs}px`,pb:`${Gs}px`},header:m.jsx(Sy,{editor:j,documentSlug:Q,actions:te,descriptionSelected:R,selectDescription:B}),controls:E?void 0:m.jsx(Cy,{controls:me.controlList,unknownFieldsOf:me.unknownFieldsOf,onEdit:U=>ke({control:U}),onAdd:()=>ke({}),...b?{addDisabledReason:b}:{},onRemove:me.dropControl,...x?{fixedFilters:x}:{},...w?{onOpenModel:w}:{},...j.document.startingGivens?{startingValues:j.document.startingGivens}:{},onStartingValue:(U,de)=>j.update(ve=>{const ie={...ve.startingGivens??{}};de===void 0?delete ie[U]:ie[U]=de,Object.keys(ie).length>0?ve.startingGivens=ie:delete ve.startingGivens}),children:d}),children:[E&&m.jsxs(tt,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx(pe,{variant:"body2",children:"This report is not served until it has a tile."}),c&&m.jsx(Me,{size:"small",startIcon:m.jsx(Jr,{}),onClick:()=>we(),children:"Add tile"})]}),q?.pending&&m.jsx(it,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx(Me,{color:"inherit",size:"small",onClick:C.restoreOffered,children:"Restore them"}),m.jsx(Me,{color:"inherit",size:"small",onClick:C.discard,children:"Discard"})]}),children:`You have unsaved edits from ${io(q.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),j.error&&m.jsx(it,{severity:"warning",children:j.error}),m.jsx(xy,{editor:j,reorder:G,resizing:J,gridBox:I,defaultSpan:Z,rules:z,canAdd:!!c,selected:T,flash:W,menuIndex:ce?.index,onSelect:N,onOpenMenu:(U,de)=>{N(de),re.setMenu({anchor:U,index:de})},onRemove:re.removeTile,...j.document.tiles.length===1&&j.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:we,editTile:re.editTile,...o?{renderTile:o}:{}}),m.jsx(Em,{editor:j,catalog:c,columns:_,dashboards:u,bindings:me,tiles:re,drillSource:fe,setDrillSource:le,exitDialog:Re.exitGuard.dialog,...a?{renderViewPreview:a}:{},...$?{takenGivenNames:$}:{}})]})})})}const Qy=ot(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),e0=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"})),t0=ot(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function $0({controls:e,onDone:t}){const n=t??e?.exit,r=ff("(max-width: 599.95px)"),{theme:i}=Ve(),s=Yt(i.cardBorder),o=hs(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:Je.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(Vc,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx(St,{title:`Undo (${dn}Z)`,children:m.jsx("span",{children:m.jsx(Fn,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:_i(i.ui),children:m.jsx(_c,{fontSize:"small"})})})}),m.jsx(St,{title:`Redo (${dn}⇧Z)`,children:m.jsx("span",{children:m.jsx(Fn,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:_i(i.ui),children:m.jsx(Bc,{fontSize:"small"})})})}),p&&m.jsx(Fr,{orientation:"vertical",sx:Vi}),p&&m.jsxs(m.Fragment,{children:[m.jsx(Me,{variant:"outlined",startIcon:m.jsx(Jr,{}),endIcon:m.jsx(na,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:v=>d(v.currentTarget),sx:{...Ar(s,o),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs(Fi,{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(Xs,{icon:m.jsx(e0,{}),title:"Tile",detail:"A view from the model",onClick:g(u.tile)}),u?.text&&m.jsx(Xs,{icon:m.jsx(t0,{}),title:"Text",detail:"Prose between the tiles",onClick:g(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(Xs,{icon:m.jsx(Qy,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:g(u.filter)})]})]})]})]}),(c||l)&&e&&m.jsx(Fr,{orientation:"vertical",sx:Vi}),c&&m.jsx(St,{enterDelay:800,enterNextDelay:800,title:e?.done&&f?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx(Me,{variant:l?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:c,sx:{...Ar(s,o,i.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&l&&m.jsx(St,{title:`Save (${dn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx(Me,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...Ar(s,o,i.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const n0=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Xs({icon:e,title:t,detail:n,disabled:r=!1,onClick:i}){const{theme:s}=Ve(),o=s.ui;return m.jsxs(vt,{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 ${Le}, background-color ${Le}`,"& 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(V,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs(V,{className:"add-text",sx:{minWidth:0},children:[m.jsx(V,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx(V,{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 ue(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(Cp(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)ue(s)&&r.set(Pn(`${s.source} -> ${s.name}`),new Set((s.filters??[]).map(o=>o.given)));const i=new Set;for(const s of e.tiles){if(!ue(s))continue;const o=Pn(`${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 Pn(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: ${ca(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=Mp(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"||da(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=jp({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?zy(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,queryVersionId:s,opened:o,replaces:a,onSave:d,onDirtyChange:f,onExit:c,onOpenModel:l,onControlsChange:u,draftKey:p,onEvent:g,savesTo:v,saveLabel:y,note:k}){const{apiClients:h}=ra(),[b,x]=S.useState(o.document.tiles.length>0);S.useEffect(()=>x(o.document.tiles.length>0),[o.generation,o.document]);const{data:w,isSuccess:$,isError:M}=ia({...qf(h,{environmentName:t,packageName:n,path:r,versionId:s},Hf),enabled:b&&!e}),A=e?.modelPath??r,j=h0(o.source,e?.compileSource),C=Uf({environmentName:t,packageName:n,modelPath:A,source:j.text??o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&j.text!==void 0}),I=C.data?.document,T=e?C.isSuccess?I?.manifest??c0:void 0:w,R=e?C.isSuccess:$,N=e?C.isError||j.problem!==void 0:M,H=e?Gf(I?.cells):void 0,B=(C.data?.result.problems??[]).filter(O=>O.severity==="error"),D=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),W=e?.givens,F=S.useMemo(()=>new Set((T?.tiles??[]).flatMap(O=>O.restricted&&O.query?[Pn(O.query)]:[])),[T]),{reports:z,settled:_}=Kf(t,n,s),Q=S.useMemo(()=>z.map(O=>O.path).filter(O=>!!O&&O!==r&&O.endsWith(".malloy")).map(O=>O.replace(/\.malloy$/,"")),[z,r]),G=l0({environmentName:t,packageName:n,...s!==void 0?{versionId:s}:{},modelPath:r,reports:z,reportsSettled:_}),ne=S.useMemo(()=>e?(G?.sources??[]).filter(O=>(O.visibleIn??O.exporters??[O.modelPath]).includes(A)).map(O=>O.name):void 0,[G,e,A]),Z=S.useMemo(()=>G&&ne?{sources:G.sources.filter(O=>ne.includes(O.name))}:G,[G,ne]),[L,J]=S.useState(o.document);S.useEffect(()=>J(o.document),[o.document]);const re=S.useMemo(()=>d&&(async(O,te)=>{await d(O,te.document.layout),v==="package"&&x(te.document.tiles.length>0)}),[d,v]),ce=S.useMemo(()=>(T?.givens??[]).filter(O=>!(e&&O.secure===!0)&&!(O.name!==void 0&&D.has(O.name))),[T,D,e]),ee=S.useMemo(()=>new Set([...ce.map(O=>O.name).filter(O=>O!==void 0),...Object.keys(W??{})]),[ce,W]),we=S.useMemo(()=>new Map((T?.tiles??[]).flatMap(O=>O.kind!=="text"&&O.query&&O.givenNames?[[Pn(O.query),O.givenNames]]:[])),[T]),me=S.useMemo(()=>i0(L,o.document,we),[L,o.document,we]),K=S.useMemo(()=>r0(L,ce,me),[L,ce,me]),ke=S.useMemo(()=>{const O=new Set(L.tiles.flatMap(ie=>ue(ie)?(ie.filters??[]).map(wt=>wt.given):[])),te=new Set((L.localGivens??[]).map(ie=>ie.name)),U=[...new Set(L.imports.map(ie=>ie.from))],de=U.length===1?f0(r,U[0]):U.length===0&&e?e.modelPath:void 0,ve=ie=>{const wt=L.sources.filter(Ot=>Ot.scopedBy?.includes(ie)).map(Ot=>Ot.name);return wt.length>0?{reason:`Applied to every tile on ${wt.join(", ")} by this report's own source. Edit the file to change it.`}:te.has(ie)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:de!==void 0?{reason:`Set in the model ${de}. Edit the model to change it.`,modelPath:de}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...me].filter(ie=>!O.has(ie)).map(ie=>[ie,ve(ie)]))},[L,me,e,r]),{declaredTypes:fe,applied:le,panel:Fe}=Yf({specs:K,loaded:R,startingValues:T?.startingGivens,documentKey:`${t}/${n}/${i??""}/${r}/edit`,autorun:T?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?A:T?.path,versionId:s,documentName:r,...H!==void 0?{preamble:H}:{},...W?{hostGivens:W}:{}}),Ge=S.useMemo(()=>Xf(K,le,W),[K,le,W]),qe=S.useMemo(()=>Object.fromEntries(Object.entries(W??{}).filter(([O])=>!fe.has(O))),[W,fe]),Ke=!b||R||N,Re=e!==void 0&&(j.problem!==void 0||C.isError||B.length>0),E=S.useMemo(()=>new Map(o.document.tiles.map(O=>[ze(O),O])),[o.document]),P=S.useMemo(()=>function(O,te,U="card"){if(Re)return m.jsxs(Js,{chrome:U,children:[m.jsx(Qs,{title:te?.title??zn(O),subtitle:te?te.subtitle:O.subtitle}),m.jsx(pe,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!Ke)return m.jsxs(Js,{chrome:U,children:[m.jsx(Qs,{title:te?.title??zn(O),subtitle:te?te.subtitle:O.subtitle}),m.jsx(Zs,{text:"Running…"})]});const de=we.get(Pn(`${O.source} -> ${O.name}`)),ve=H===void 0&&de!==void 0&&u0(E.get(ze(O)),O)?{expression:`${O.source} -> ${O.name}`,givenNames:[...de],reads:[...de]}:a0(L,O,ee,le,de);return m.jsx(bl,{environmentName:t,packageName:n,versionId:s,modelPath:A,...H!==void 0?{preamble:H}:{},...F.has(Pn(`${O.source} -> ${O.name}`))?{restricted:!0}:{},tile:ve.expression,...ve.annotation?{annotation:ve.annotation}:{},label:zn(O),chrome:U,subtitle:O.subtitle,...te?{heading:te}:{},borderless:O.borderless,givens:le,hostGivens:qe,declaredTypes:fe,givenNames:ve.givenNames,...(()=>{const ie=Qf(Ge,ve.reads??ve.givenNames);return ie.length>0?{waitingFor:ep(ie)}:{}})(),ignoredFilters:Jf(ve.reads,K),height:Zf})},[L,E,Ke,Re,Ge,ee,we,t,n,s,A,H,F,le,qe,fe,K]),q=S.useMemo(()=>function(O){return m.jsx(bl,{environmentName:t,packageName:n,versionId:s,modelPath:O.modelPath,tile:`${O.base} -> ${O.view}`,...O.chart?{annotation:cn(O.chart,O.chartCarried)}:{},label:O.label,borderless:!0,givens:le,hostGivens:qe,declaredTypes:fe,givenNames:O.givens,height:200})},[t,n,s,le,qe,fe]);return m.jsxs(tt,{sx:{gap:1},children:[e&&B.length>0&&m.jsxs(it,{severity:"error",children:["The server could not compile this document:"," ",B.map(O=>O.message).join("; ")]}),Ge.length>0&&!Re&&m.jsx(it,{severity:"info",children:tp(Ge)}),e&&j.problem!==void 0&&m.jsxs(it,{severity:"error",children:["This document could not be prepared to compile:"," ",j.problem]}),e&&C.isError&&m.jsxs(it,{severity:"error",children:["The server could not compile this document:"," ",C.error?.message]}),m.jsx(Zh,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:o.source,document:o.document,fixedFilters:ke,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:P,renderViewPreview:q,givens:K.filter(O=>O.name!==void 0).map(O=>({name:O.name,...O.label?{label:O.label}:{},...O.type?{type:O.type}:{},...O.suggest?.dimension?{field:O.suggest.dimension}:{}})),onChange:J,onDirtyChange:f,...c?{onExit:c}:{},...l?{onOpenModel:l}:{},...u?{onControlsChange:u}:{},...p!==void 0?{draftKey:p}:{},...Z?{catalog:Z}:{},dashboards:Q,...g?{onEvent:g}:{},controls:R?m.jsx(np,{...Fe,layout:"bar"}):void 0,...re?{onSave:re}:{},savesTo:v,...y?{saveLabel:y}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:ne}:{}}),m.jsx(V,{sx:{px:.5},children:m.jsx(pe,{variant:"caption",sx:{opacity:.7},children:k})})]})}function u0(e,t){return e!==void 0&&JSON.stringify(Cc(e))===JSON.stringify(Cc(t))}function Cc(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(Tc(t,k.name,r,i,s)).catch(b=>{if(!Rc(b))throw b});if(y)return;f(h),p(h!==void 0)}}catch(k){if(y)return;v(Pc(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 Jo(e);return Zo(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((K,ke)=>{try{g.current?.(Lf(K,{...v.current,...ke?{layout:ke}:{}}))}catch{}}),k=e?.authoritative===!0,h=k&&r!==void 0,[b,x]=S.useState(void 0),w=(k||b===!0)&&t!==void 0,[$,M]=S.useState(void 0),[A,j]=S.useState(l?v0:void 0),C=S.useRef(void 0),I=S.useRef(void 0),[T,R]=S.useState(void 0),N=S.useRef(s);N.current=s;const H=T!==void 0&&T.onFetch===s?T.text:i,B=S.useRef(H);B.current=H;const D=w?t:H,[W,F]=S.useState(!1),[z,_]=S.useState(void 0),[Q,G]=S.useState(void 0),ne=D!==void 0&&D!==Q,Z=$?.source,L=ne&&(W||!k&&t!==void 0&&Z===t&&t!==H)&&Z!==void 0&&D!==z,J=L?Z:ne?D:Z??D,re=L?D:void 0,ce=S.useRef(Z);ce.current=Z;const ee=S.useRef(D);ee.current=D;const we=S.useRef("package");we.current=w?k?"record":"draft":"package",S.useEffect(()=>{if(J===void 0||!n||h||J===ce.current)return;let K=!1;const ke=B.current,fe=ee.current;return g0(J).then(le=>{if(!K){if(le.ok===!1){j(le.reason),y.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}j(void 0),C.current=void 0,I.current=ke,R(void 0),_(void 0),G(fe),M(Fe=>({source:J,document:le.document,...ke!==void 0?{packageText:ke}:{},generation:(Fe?.generation??0)+1})),y.current({type:"report.opened",surface:"edit",from:we.current,tiles:le.document.tiles.length,durationMs:Lt()-p.current},le.document.layout)}}).catch(le=>{if(K)return;const Fe=`Could not read the ${c}: ${le instanceof Error?le.message:String(le)}`;j(Fe),y.current({type:"report.load_failed",surface:"edit",category:Ec(le)})}),()=>{K=!0}},[J,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&&j("the host's storage has no document at this location."):j("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,$,r,k,t]);const me=f&&!u&&!$&&n&&!w&&o&&i===void 0;return S.useEffect(()=>{me&&(j(b0),y.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[me]),{authoritative:k,blockedOnRecord:h,resume:b,setResume:x,fromDraft:w,opened:$,setOpened:M,openError:A,savedHashRef:C,packageBaseRef:I,setWrote:R,fetchedAtRef:N,setDirty:F,setSeen:G,held:re,choose:K=>{p.current=Lt(),_(K?t:H),x(K)},acceptHeld:()=>{p.current=Lt(),_(re)}}}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:M}){const A=S.useCallback(F=>t===void 0?void 0:Tc(F,t.name,i,s,o),[t,i,s,o]),j=A(n),C=S.useCallback(async(F,z=n)=>{const _=A(z);if(!e||!_)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(_,F),y(Q=>Q&&{...Q,source:F}),k(F),(p||g===!0)&&b(F),p||v(Q=>Q??!1)},[e,A,n,p,g,y,k,b,v]),[I,T]=S.useState(void 0),R=S.useCallback(async F=>{const z=await Ff(w.current,$.current);if(z===void 0)throw new Error("The package file is still loading; try again.");const _=["dashboard-editor-model",i,s,o,a,r];await Bf({apiClients:d,queryClient:f,environmentName:i,packageName:s,modelPath:o,source:F,expectedHash:z,invalidateOnError:[_],afterWrite:async Q=>{if(y(G=>G&&{...G,source:F}),x({text:F,onFetch:M.current}),b(F),w.current=Q,T(void 0),e&&j)try{await e.deleteDocument(j),k(void 0),h(!1)}catch(G){Rc(G)?(k(void 0),h(!1)):T(Pc(G))}v(!1)},invalidate:[{queryKey:_,wait:!0},{queryKey:$p({environmentName:i,packageName:s,versionId:a,modelPath:o})}]}),_f(f,i,s,o)},[d,i,s,o,a,r,e,j,f,w,$,M,y,x,b,k,h,v]),N=t?.writeable===!0,H=c===!0&&!l,{savesTo:B,pinnedPackageSave:D,writer:W}=Sp({authoritative:p,mutable:H,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!j&&N&&(!r||p),readFailed:u!==void 0});return{save:W==="storage"?C:W==="package"?R:void 0,savesTo:B,writer:W,pinnedPackageSave:D,takesWrites:H,supersedeFailure:I}}function Jh(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:i,onOpenModel:s,onControlsChange:o,keepDraft:a,kind:d,path:f,textSource:c,queryVersionId:l}=e,u=e.layout??(d?xf(d):"grid"),p=u==="linear",g=c!==void 0,{environmentName:v,packageName:y,versionId:k,namesBoth:h}=yf(e),b=("resourceUri"in e?e.dashboard:e.dashboardName)??wf(f)??"",x="report",{apiClients:w,mutable:$,isLoadingStatus:M,server:A}=ra(),j=kf(),C=S.useRef(Lt()),I=S.useRef(t);I.current=t;const T=S.useRef(r);T.current=r;const R=Sf()?.documentStorage,N=f??Wf(d??"dashboard",b),H=/\.malloynb$/i.test(N)||p&&/\.malloynb$/i.test(b),B=ia({queryKey:["dashboard-editor-model",v,y,N,k,p],queryFn:()=>w.models.getModel(v,y,N,k,p?!0:void 0),enabled:h&&!H&&!g}),D=B.data?.data?.sourceText,{workspace:W,draft:F,setDraft:z,draftChecked:_,offered:Q,setOffered:G,readFailure:ne}=p0({storage:R,layout:u,notebook:p,environmentName:v,packageName:y,modelPath:N}),{authoritative:Z,blockedOnRecord:L,resume:J,setResume:re,fromDraft:ce,opened:ee,setOpened:we,openError:me,savedHashRef:K,packageBaseRef:ke,setWrote:fe,fetchedAtRef:le,setDirty:Fe,setSeen:Ge,held:qe,choose:Ke,acceptHeld:Re}=x0({workspace:W,draft:F,draftChecked:_,readFailure:ne,packageText:D,fetchedAt:B.dataUpdatedAt,packageSettled:B.isSuccess&&!B.isFetching,modelPath:N,layout:u,notebook:p,noun:x,legacyFormat:H,textHeld:g,startedAt:C,onEventRef:I}),{save:E,savesTo:P,writer:q,pinnedPackageSave:O,takesWrites:te,supersedeFailure:U}=y0({storage:R,workspace:W,layout:u,notebook:p,environmentName:v,packageName:y,modelPath:N,versionId:k,apiClients:w,queryClient:j,mutable:$,textHeld:g,readFailure:ne,authoritative:Z,resume:J,setResume:re,setOpened:we,setDraft:z,setOffered:G,setSeen:Ge,setWrote:fe,savedHashRef:K,packageBaseRef:ke,fetchedAtRef:le}),de=W?.name,ve=S.useCallback(cr=>{I.current?.($f(cr,de))},[de]),ie=B.isError&&!ee,wt=S.useRef(!1);S.useEffect(()=>{!ie||wt.current||(wt.current=!0,Mc({path:N,layout:u},I.current).emit({type:"report.load_failed",surface:"edit",category:Ec(B.error)}))},[ie,B.error,N,u]);const Ot=S.useCallback((cr,di)=>{Fe(cr),T.current?.(di)},[Fe]),Xt=a?Vf({server:A,environmentName:v,packageName:y,versionId:k,path:f??b}):void 0,or=P==="host"&&W?.description?W.description:void 0,ar=!Z&&!g&&$===void 0?M?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":jf({authoritative:Z,mutable:te,pinnedPackageSave:O,...W?{workspace:W}:{},...ne!==void 0?{readFailure:ne}:{},...k!==void 0?{versionId:k}:{}}),js=P==="package"&&te===!0&&!O&&ne===void 0||ar===or?"":ar;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(me)return m.jsxs(it,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened in the builder: ",me]});if(B.isError&&!ee)return m.jsx(Cf,{error:B.error,context:`Opening the ${x}`});if(!ee&&(!(g||D)||!_))return n??m.jsx(Zs,{text:`Opening the ${x}…`});if(L)return m.jsxs(it,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened: ",ne]});const lr=F!==void 0&&F!==D;return m.jsxs(tt,{sx:{gap:2},children:[B.isError&&m.jsxs(it,{severity:"warning",children:["The ",x," could not be re-read from the server:"," ",B.error?.message,". Your edits are still here."]}),!p&&!Z&&Q&&lr&&J===void 0&&m.jsx(it,{severity:"info",action:m.jsxs(tt,{direction:"row",sx:{gap:1},children:[m.jsx(Me,{size:"small",onClick:()=>Ke(!0),children:"Resume"}),m.jsx(Me,{size:"small",onClick:()=>Ke(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),qe!==void 0&&m.jsx(it,{severity:"warning",action:m.jsx(Me,{size:"small",onClick:()=>{Xt!==void 0&&Mf(Xt),Re()},children:"Load it"}),children:P==="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.":P==="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."}),U!==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:"," ",U]}),!ee&&(n??m.jsx(Zs,{text:`Opening the ${x}…`})),ee&&m.jsx(d0,{environmentName:v,packageName:y,modelPath:N,...c?{textSource:c}:{},slug:b,...k!==void 0?{versionId:k}:{},...(l??k)!==void 0?{queryVersionId:l??k}:{},opened:ee,...ce&&q==="package"&&ee.packageText!==void 0?{replaces:ee.packageText}:{},onSave:E,onDirtyChange:Ot,...i?{onExit:i}:{},...s?{onOpenModel:s}:{},...o?{onControlsChange:o}:{},...Xt!==void 0?{draftKey:Xt}:{},savesTo:P,...or?{saveLabel:or}:{},...t?{onEvent:ve}:{},note:js},ee.generation)]})}const j0=Jh,C0=Zh;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:{}}:wl===void 0&&(wl={});export{$0 as BuilderBar,C0 as DashboardBuilder,j0 as DashboardEditor,D0 as MAX_SLUG_ATTEMPTS,M0 as NotebookEditor,Zh as ReportBuilder,Jh as ReportEditor,zy as buildCatalog,A0 as createDocument,T0 as createRoute,Tc as locatorFor,R0 as newDashboardSource,P0 as newDocumentProblem,I0 as newNotebookSource,Jo as readDashboardDocument,Zo as readFailed,S0 as readReportTagOfText,z0 as reportPathFor,W0 as reportPathForTitle,N0 as slugFor,L0 as slugOrFallback,cy as spliceDashboardDocument,Qo as spliceFailed,F0 as useDocumentChoices};
|