@malloy-publisher/app 0.9.15 → 0.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-doc.yaml +0 -2
- package/dist/assets/{EnvironmentPage-FClzTET1.js → EnvironmentPage-BfcAd2yi.js} +1 -1
- package/dist/assets/{HomePage-DY8r_SPS.js → HomePage-Ci_5k81i.js} +1 -1
- package/dist/assets/{MainPage-COdVBhUS.js → MainPage-D3QeyfA0.js} +1 -1
- package/dist/assets/{ModelPage-DpS3jA5N.js → ModelPage-Bpeml30i.js} +2 -2
- package/dist/assets/{PackagePage-CS5ePUwy.js → PackagePage-C9Ptmg2y.js} +1 -1
- package/dist/assets/RenderedResult-DxmHGZNQ.es-D0Ona1d0.js +171 -0
- package/dist/assets/{RouteError-BnzLDEen.js → RouteError-C8LT19mj.js} +1 -1
- package/dist/assets/{ThemeEditorPage-CjaJvkiM.js → ThemeEditorPage-CynRJmSm.js} +1 -1
- package/dist/assets/{ToggleButtonGroup-DpS5j6nj.js → ToggleButtonGroup-ChqidtS2.js} +1 -1
- package/dist/assets/{documentRoutes-BGPsDJa0.js → documentRoutes-DZ-IkgZk.js} +1 -1
- package/dist/assets/{editPageMounted-C8_ZEAFO.js → editPageMounted-BaIkidNI.js} +2 -2
- package/dist/assets/{index-D6CnUO9j.js → index-CIAQd_g-.js} +1 -1
- package/dist/assets/{index-Bohg2UjZ.js → index-CtRRADnY.js} +1 -1
- package/dist/assets/{index-BLeRYy_z.js → index-Cu8EElmh.js} +1 -1
- package/dist/assets/{index-JQs0UPrG.js → index-Dzz5PLbw.js} +80 -80
- package/dist/assets/index.es-DvW5H23D.js +144 -0
- package/dist/index.html +1 -1
- package/package.json +2 -2
- package/dist/assets/RenderedResult-YBzVMVH2.es-CzJTpX_s.js +0 -154
- package/dist/assets/index.es-JmXuGuMS.js +0 -144
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import{g as Gf,a as Vf,r as S,u as Uf,b8 as Kf,k as Yf,i as Xf,b9 as Zf,l as Qf,j as m,f as Jf,h as ep,s as ma,m as tp,t as Il,Y as nd,U as qe,ba as _t,bb as vo,aD as ct,ae as Qe,L as Ot,K as Kn,bc as Yn,ak as Ee,bd as ga,be as ai,bf as Lr,bg as np,bh as rd,bi as id,bj as rp,bk as ip,bl as ls,bm as op,T as me,as as lt,bn as sp,bo as ap,bp as lp,O as va,aK as cp,bq as Kt,br as dp,bs as xa,bt as up,bu as od,bv as sd,bw as hp,bx as fp,a0 as cs,by as pp,bz as mp,bA as ds,aY as ad,B as ld,bB as Fe,I as H,aJ as tt,bC as mt,bD as ba,bE as gp,bF as pt,bG as vp,bH as xp,bI as ya,ag as bp,bJ as yp,bK as wp,bL as kp,bM as Sp,bN as $p,bO as cd,bP as jp,bQ as Mp,bR as dd,bS as ud,bT as hd,bU as Cp,bV as Ep,bW as Dp,bX as Op,bY as Tp,bZ as Ap,b_ as Rp,b$ as Pp,c0 as Ip,Z as Np,c1 as Wp,c2 as zp,c3 as us,c4 as hs,c5 as Nl,c6 as fd,c7 as Lp,c8 as Fp,c9 as Bp,ca as Hn,cb as _p,cc as Hp,cd as qp,ce as Gp,cf as Vp,cg as pd,ch as wa,ci as Up,cj as Kp,ck as md,cl as Yp,cm as Xp,cn as Zp,co as xo,cp as Qp,cq as Jp,cr as em,cs as Ai,ct as fs,cu as Wt,cv as tm,cw as nm,cx as gd,cy as rm,cz as im,aP as ka,aF as Yt,cA as ps,cB as om,cC as sm,cD as vd,X as fn,W as xd,cE as am,cF as lm,cG as cm,cH as ms,cI as dm,cJ as um,cK as hm,cL as bd,cM as fm,G as pm,cN as mm,cO as gm,cP as vm,cQ as xm,cR as bm,cS as ym,cT as Sa,cU as wm,cV as $a,cW as km,cX as yd,cY as Sm,cZ as $m,c_ as jm,c$ as ja,d0 as Mm,d1 as Cm,d2 as Em,d3 as jn,d4 as wd,d5 as Wl,d6 as zl,d7 as zo,d8 as Dm,S as Om,d9 as Tm,da as Am,db as Rm,dc as kd,dd as Pm,de as Im,aj as Nm}from"./index-JQs0UPrG.js";import{df as Fw,dg as Bw,dh as _w,di as Hw,dj as qw,dk as Gw,dl as Vw,dm as Uw,dn as Kw,dp as Yw,dq as Xw}from"./index-JQs0UPrG.js";import{T as Sd,a as gs}from"./ToggleButtonGroup-DpS5j6nj.js";function Wm(e){return Gf("MuiCollapse",e)}Vf("MuiCollapse",["root","horizontal","vertical","entered","hidden","wrapper","wrapperInner"]);const zm=e=>{const{orientation:t,classes:n}=e,r={root:["root",`${t}`],entered:["entered"],hidden:["hidden"],wrapper:["wrapper",`${t}`],wrapperInner:["wrapperInner",`${t}`]};return ep(r,Wm,n)},Lm=ma("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]}})(tp(({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"}}]}))),Fm=ma("div",{name:"MuiCollapse",slot:"Wrapper"})({display:"flex",width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),Bm=ma("div",{name:"MuiCollapse",slot:"WrapperInner"})({width:"100%",variants:[{props:{orientation:"horizontal"},style:{width:"auto",height:"100%"}}]}),vs=S.forwardRef(function(t,n){const r=Uf({props:t,name:"MuiCollapse"}),{addEndListener:i,children:o,className:s,collapsedSize:a="0px",component:d,easing:h,in:l,onEnter:c,onEntered:u,onEntering:p,onExit:g,onExited:x,onExiting:w,orientation:y="vertical",style:f,timeout:v=Kf.standard,TransitionComponent:b=Yf,...k}=r,C={...r,orientation:y,collapsedSize:a},$=zm(C),D=Xf(),j=Zf(),M=S.useRef(null),A=S.useRef(),N=typeof a=="number"?`${a}px`:a,P=y==="horizontal",L=P?"width":"height",_=S.useRef(null),V=Qf(n,_),T=B=>X=>{if(B){const ee=_.current;X===void 0?B(ee):B(ee,X)}},F=()=>M.current?M.current[P?"clientWidth":"clientHeight"]:0,O=T((B,X)=>{M.current&&P&&(M.current.style.position="absolute"),B.style[L]=N,c&&c(B,X)}),R=T((B,X)=>{const ee=F();M.current&&P&&(M.current.style.position="");const{duration:oe,easing:ie}=Il({style:f,timeout:v,easing:h},{mode:"enter"});if(v==="auto"){const Oe=D.transitions.getAutoHeightDuration(ee);B.style.transitionDuration=`${Oe}ms`,A.current=Oe}else B.style.transitionDuration=typeof oe=="string"?oe:`${oe}ms`;B.style[L]=`${ee}px`,B.style.transitionTimingFunction=ie,p&&p(B,X)}),z=T((B,X)=>{B.style[L]="auto",u&&u(B,X)}),q=T(B=>{B.style[L]=`${F()}px`,g&&g(B)}),U=T(x),G=T(B=>{const X=F(),{duration:ee,easing:oe}=Il({style:f,timeout:v,easing:h},{mode:"exit"});if(v==="auto"){const ie=D.transitions.getAutoHeightDuration(X);B.style.transitionDuration=`${ie}ms`,A.current=ie}else B.style.transitionDuration=typeof ee=="string"?ee:`${ee}ms`;B.style[L]=N,B.style.transitionTimingFunction=oe,w&&w(B)}),K=B=>{v==="auto"&&j.start(A.current||0,B),i&&i(_.current,B)};return m.jsx(b,{in:l,onEnter:O,onEntered:z,onEntering:R,onExit:q,onExited:U,onExiting:G,addEndListener:K,nodeRef:_,timeout:v==="auto"?null:v,...k,children:(B,{ownerState:X,...ee})=>m.jsx(Lm,{as:d,className:Jf($.root,s,{entered:$.entered,exited:!l&&N==="0px"&&$.hidden}[B]),style:{[P?"minWidth":"minHeight"]:N,...f},ref:V,ownerState:{...C,state:B},...ee,children:m.jsx(Fm,{ownerState:{...C,state:B},className:$.wrapper,ref:M,children:m.jsx(Bm,{ownerState:{...C,state:B},className:$.wrapperInner,children:o})})})})});vs&&(vs.muiSupportAuto=!0);var Ll={};const $d=mt(m.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),jd=mt(m.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),_m=mt(m.jsx("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}));function Md(e){const{theme:t}=qe(),n=t.ui,[r,i]=S.useState(null),{status:o,draftKeptAt:s,discard:a,restored:d,dismissRestored:h}=e,l=d!==void 0&&!d.pending&&o==="unsaved"?d:void 0,c=o==="saved"?"Saved":o==="saving"?"Saving…":s!==void 0?"Draft saved":"Unsaved changes",u=l?`Restored your unsaved edits from ${xs(l.savedAt)}`:void 0,p=o==="unsaved"&&s!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,g=a!==void 0&&o==="unsaved",x=()=>{i(null),l&&h?.()},w=v=>({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:o==="saved"?v.palette.text.secondary:v.palette.text.primary,transition:`color ${Fe}, background-color ${Fe}`,...g?{"&:hover":{bgcolor:v.palette.action.hover}}:{}}),y=m.jsxs(m.Fragment,{children:[m.jsx(H,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:o==="saved"?m.jsx(xo,{sx:{fontSize:16}}):m.jsx(H,{component:"span","data-restored":l?"true":void 0,sx:v=>({width:7,height:7,borderRadius:"50%",bgcolor:l?t.accent:o==="saving"||s!==void 0?v.palette.text.disabled:v.palette.warning.main,transition:`background-color ${Fe}`})})}),m.jsx(H,{component:"span","aria-hidden":!0,children:c}),m.jsx(ga,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:g?"visible":"hidden"}})]}),f=m.jsx(H,{component:"span",role:"status","aria-live":"polite",sx:Hm,children:u?`${c}. ${u}.`:c});return m.jsxs(m.Fragment,{children:[f,m.jsx(Ot,{title:u??p,describeChild:!0,children:g?m.jsx(ld,{className:Qe.saveStatus,"aria-label":c,...u?{"aria-description":u}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:v=>i(v.currentTarget),sx:w,children:y}):m.jsx(H,{component:"span",className:Qe.saveStatus,sx:w,children:y})}),m.jsxs(Lr,{className:Qe.menu,anchorEl:r,open:r!==null,onClose:x,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${_t(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(u!==void 0||s!==void 0)&&m.jsx(H,{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 ${xs(s)}`}),m.jsxs(tt,{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(_m,{fontSize:"small"}),"Discard edits"]})]})]})}function xs(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 Hm={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},bs=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),gn=bs?"⌘":"Ctrl+",Fl=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Lo=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function qm(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e});const[n,r]=S.useState(!1);S.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),S.useEffect(()=>{const i=o=>{const s=t.current;if(s.paused)return;const a=bs?o.metaKey:o.ctrlKey,d=o.key.toLowerCase();if(o.key==="Escape"){if(Fl(o.target)||Lo(o.target))return;s.escape();return}if(Fl(o.target)){if(a&&d==="s"){if(o.preventDefault(),!s.save||Lo(o.target))return;o.target.blur(),r(!0)}return}if(Lo(o.target)){a&&d==="s"&&o.preventDefault();return}if(a&&d==="z"){o.preventDefault(),o.shiftKey?s.redo():s.undo();return}if(!bs&&a&&d==="y"){o.preventDefault(),s.redo();return}if(a&&d==="s"){o.preventDefault(),s.save?.();return}s.nudge&&!a&&!o.altKey&&!o.shiftKey&&(o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.preventDefault(),s.nudge(o.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[])}const Fr=(e,t,n=ba)=>({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}}}),Ui=(e=ba)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),Ki={height:20,alignSelf:"center",mx:.5,my:0},Yi=(e,t=ba)=>({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"}}}),ys={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Gm({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:i,saving:o,onSave:s,savesTo:a="package",saveLabel:d,saveButton:h,actions:l,onAddTile:c,onExit:u,saveStatus:p}){const{theme:g}=qe(),x=_t(g.cardBorder),w=vo(g.cardBorder,g.tileTitle);return m.jsxs(ct,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[c&&m.jsx(Ee,{variant:"outlined",startIcon:m.jsx(ai,{}),onClick:c,"aria-label":"Add tile",sx:Fr(x,w,g.ui),children:"Tile"}),c&&m.jsx(Yn,{orientation:"vertical",sx:Ki}),m.jsx(Ot,{title:`Undo (${gn}Z)`,children:m.jsx("span",{children:m.jsx(Kn,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Ui(g.ui),children:m.jsx(jd,{fontSize:"small"})})})}),m.jsx(Ot,{title:`Redo (${gn}⇧Z)`,children:m.jsx("span",{children:m.jsx(Kn,{"aria-label":"Redo",disabled:!t,onClick:r,sx:Ui(g.ui),children:m.jsx($d,{fontSize:"small"})})})}),(l||s||u)&&m.jsx(Yn,{orientation:"vertical",sx:Ki}),l,s&&p&&m.jsx(Md,{...p}),s?m.jsx(Ot,{title:i?`Save (${gn}S) · ${d??ys[a]}`:d??ys[a],children:m.jsx("span",{children:m.jsx(Ee,{ref:h,variant:i?"contained":"outlined",disabled:!i||o,onClick:s,sx:{...Fr(x,w,g.ui),minWidth:88},children:o?"Saving…":i?"Save":"Saved"})})}):null,s&&m.jsx(H,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:o?"Saving":i?"Unsaved changes":"All changes saved"}),u&&m.jsx(pm,{label:"Close",icon:m.jsx(xo,{}),onClick:u})]})}const Vm=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Bl={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map",combo_chart:"Bar and line"};function Cd(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this tile's details":n==="unlisted"?"Not in the model's list, so its shape is unknown":void 0,i=e?.shape,o=s=>{if(t===s)return;if(s==="big_value")return e?.aggregateOnly===!0?void 0:i&&i.groupBys>0?"This view has a group by, so it is more than one row; big numbers need a view of totals only":r??"Needs results that are only totals (no group by)";if(s==="shape_map"||s==="segment_map")return e?.chart===s?void 0:r??"Needs a map chart set in the model";if(e?.chart===s)return;if(!i)return s==="combo_chart"?r??"Needs a view with a group by and exactly two totals: the first is drawn as bars, the second as a line":void 0;const a=`A ${Bl[s].toLowerCase()} chart`;switch(Pm(s,i)){case"no_x_axis":return Vm(a);case"combo_totals":return`A bar and line chart needs exactly two totals, the first drawn as bars and the second as a line; this view has ${i.totals}`;case"no_y_axis":return`This view has no total for the y-axis: ${a.toLowerCase()} needs at least one aggregate`;default:return}};return[{value:"default",label:"Default",hint:"As set in the model"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map","combo_chart"].map(s=>{const a=o(s);return{value:s,label:Bl[s],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function _l(e){return e.description??Am(e.name)}const Um={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",combo_chart:"a bar and line chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},bi=(e,t)=>`${e}\0${t}`;function Km({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:o,onAddText:s,renderPreview:a}){const{theme:d}=qe(),h=d.ui,l=_t(d.cardBorder),c=S.useMemo(()=>n?.sources??[],[n]),[u,p]=S.useState(""),[g,x]=S.useState(),[w,y]=S.useState(""),[f,v]=S.useState("default"),b=S.useRef(null),k=S.useMemo(()=>{const T=new Set(t.sources.map(F=>F.base));return[...c].sort((F,O)=>Number(T.has(O.name))-Number(T.has(F.name)))},[c,t]),C=k.filter(T=>T.views.length>0),$=k.filter(T=>T.views.length===0),D=S.useMemo(()=>new Map(C.flatMap(T=>T.views.map(F=>[bi(T.name,F.name),{source:T,view:F,key:bi(T.name,F.name)}]))),[C]),j=S.useMemo(()=>C.map(T=>({key:T.name,label:T.name,...T.description?{detail:T.description}:{},entries:T.views.map(F=>({key:bi(T.name,F.name),name:F.name,title:_l(F),...F.chart?{chart:F.chart}:{}}))})),[C]),M=g===void 0?void 0:D.get(g);S.useEffect(()=>{if(!e)return;p(""),y(""),v("default");const T=C[0]?.views[0];x(T&&C[0]?bi(C[0].name,T.name):void 0)},[e]);const A=M?[M.source.name,M.view.name].filter(T=>!ms(T)).map(T=>`"${T}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,N=M!==void 0&&A===void 0,P=M?_l(M.view):"",L=f!=="default"&&M?{chart:f,chartCarried:M.view.chart?[M.view.chart]:[]}:{},_=(T=M)=>{if(!T||![T.source.name,T.view.name].every(ms))return;const F=T.key===M?.key,O=Im(Math.ceil(r/2),r);o({base:T.source.name,modelPath:T.source.modelPath,...T.source.exporters?{exporters:T.source.exporters}:{},view:T.view.name,...F&&w.trim()?{label:w.trim()}:{},...F?L:{},...O!==void 0?{colspan:O}:{}})},V=M?Cd(M.view,f).filter(T=>T.value!=="custom"&&T.disabled!==!0):[];return m.jsx(ka,{className:`${Qe.dialog} ${Qe.addTileDialog}`,open:e,onClose:i,maxWidth:"md",initialFocus:b,title:"Add a tile",description:"Pick what the tile shows from the model. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx(Ee,{onClick:s,sx:{mr:"auto"},children:"Add text instead"}),m.jsx(Ee,{onClick:i,children:"Cancel"}),m.jsx(Ee,{variant:"contained",disabled:!N,onClick:()=>_(),children:"Add tile"})]}),children:m.jsxs(H,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${l}`,borderBottom:`1px solid ${l}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx(H,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${l}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(dm,{groups:j,query:u,onQuery:p,picked:M?.key,onPick:T=>{x(T),v("default")},onTake:T=>_(D.get(T)),searchRef:b,empty:m.jsx(me,{variant:"body2",sx:{color:d.tileTitle,p:2},children:n?"This package's models have nothing to put on a tile yet.":"The package's sources are still loading."}),footer:$.length>0&&m.jsxs(me,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",$.map(T=>T.name).join(", "),"."]})})}),m.jsx(H,{sx:T=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${T.palette.text.primary} 3%, ${T.palette.background.paper})`}),children:M?m.jsxs(m.Fragment,{children:[m.jsx(H,{"aria-label":"Preview",role:"region",sx:T=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:h.radius.tile,border:`1px solid ${l}`,bgcolor:T.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${T.palette.background.paper})`}}),children:a?m.jsx(H,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:M.source.name,modelPath:M.source.modelPath,view:M.view.name,label:w.trim()||P,...f!=="default"?L:{},givens:M.source.givens})}):m.jsxs(H,{sx:T=>({flex:1,border:`1px solid ${l}`,borderRadius:h.radius.tile,bgcolor:T.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(um,{chart:M.view.chart}),m.jsxs(me,{variant:"body2",children:[M.source.name," → ",M.view.name]})]})}),m.jsx(Yt,{size:"small",label:"Title",placeholder:P,value:w,onChange:T=>y(T.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs(H,{children:[m.jsx(me,{component:"div",sx:{...h.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx(Sd,{size:"small",exclusive:!0,value:f,"aria-label":"Chart",onChange:(T,F)=>{F!==null&&v(F)},sx:{...Yi(l,h),"& .MuiToggleButton-root":{...Yi(l,h)["& .MuiToggleButton-root"],textTransform:"none"}},children:V.map(T=>m.jsx(gs,{value:T.value,children:T.label},T.value))}),m.jsx(me,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:M.view.chart?`The model sets ${Um[M.view.chart]??"a chart"}.`:"The model sets no chart, so it shows as a table."})]}),A&&m.jsx(me,{variant:"body2",color:"error",children:A})]}):m.jsx(me,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const De=e=>e.kind==="text",de=e=>e.kind!=="text",Mn=e=>de(e)?e.label??e.name:e.name,ht=e=>e.declaration.kind==="query"?e.name:`${e.source} -> ${e.name}`,nr=e=>e.declaration.kind==="inherited"||e.declaration.kind==="query",ke=e=>De(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,Ma=e=>De(e)?Qp:Jp,Ca=e=>e.rowspan??ya[De(e)?"text":"query"];function Yr(e,t){if(e.row===void 0||e.col===void 0)return;const n=Math.min(e.colspan??1,t);return{row:e.row,col:Math.min(e.col,t-n+1),colspan:n,rowspan:Ca(e)}}const Ed=(e,t)=>e.col<t.col+t.colspan&&t.col<e.col+e.colspan&&e.row<t.row+t.rowspan&&t.row<e.row+e.rowspan;function Ym(e){return e.map((t,n)=>({tile:t,index:n})).sort((t,n)=>(t.tile.row??1/0)-(n.tile.row??1/0)||(t.tile.col??1/0)-(n.tile.col??1/0)||t.index-n.index).map(({tile:t})=>t)}function bo(e,t,n){const r=e.map(a=>({...a})),i=[],o=a=>{const d=Yr(r[a],t);d&&(r[a].col=d.col,i.push(d))};n!==void 0&&o(n);const s=r.map((a,d)=>({tile:a,index:d})).filter(({index:a,tile:d})=>a!==n&&d.row!==void 0).sort((a,d)=>(a.tile.row??0)-(d.tile.row??0)||(a.tile.col??0)-(d.tile.col??0)||a.index-d.index);for(const{index:a}of s){const d=Yr(r[a],t);if(d){for(;;){const h=i.filter(l=>Ed(d,l));if(h.length===0)break;d.row=Math.max(...h.map(l=>l.row+l.rowspan))}r[a].row=d.row,o(a)}}return r}function Xm(e,t,n,r){const i=e.flatMap((d,h)=>{const l=h===t?void 0:Yr(d,r);return l?[l]:[]}),o=Math.max(1,...i.map(d=>d.row+d.rowspan)),s={...e[t],...n,row:Math.min(n.row,o)},a=Yr(s,r);if(a){for(;;){const d=i.filter(h=>h.row<a.row&&Ed(a,h));if(d.length===0)break;a.row=Math.max(...d.map(h=>h.row+h.rowspan))}s.row=a.row}return bo(e.map((d,h)=>h===t?s:d),r,t)}const Hl=(e,t)=>(e-pt*(t-1))/t,Dd=fs+pt;function Od(e,t,n,r,i){const o=Math.min(n,r),s=Math.round(e/(i+pt))+1;return{row:Math.max(1,Math.round(t/Dd)+1),col:Math.min(Math.max(s,1),r-o+1)}}function Zm(e,t,n,r){const i=e.map((o,s)=>{if(o.row!==void 0&&o.col!==void 0)return o;const a=t[s];if(!a)return o;const{break:d,...h}=o,l=o.colspan??Math.max(1,Math.round((a.width+pt)/(r+pt)));return{...h,...Od(a.left,a.top,l,n,r),colspan:l,rowspan:o.rowspan??Math.max(Ma(o),Math.round((a.height+pt)/Dd))}});return bo(i,n)}function ql(e,t,n){const r=e.flatMap((o,s)=>{const a=s===t?void 0:Yr(o,n);return a?[a]:[]});if(r.length===0)return[...e];const i=Math.max(...r.map(o=>o.row+o.rowspan));return e.map((o,s)=>s===t?{...o,row:i,col:1}:o)}function Qm(e,t,{modelPath:n,textHeld:r,widths:i,insertAt:o}){t.modelPath&&!r&&(e.imports=Dm(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const s=Td(e,t.base),a=ws(e,s.name,t.view);e.tiles.splice(o??e.tiles.length,0,{name:a,source:s.name,declaration:{kind:"reference",from:t.view},...i&&t.colspan!==void 0?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Td(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 o=`${t}_tiles`;for(let a=2;i.has(o);a++)o=`${t}_tiles_${a}`;const s={name:o,base:t};return e.sources.push(s),s}function ws(e,t,n){const r=new Set(e.tiles.filter(de).filter(o=>o.source===t).map(o=>o.name));let i=`${n}_tile`;for(let o=2;r.has(i);o++)i=`${n}_tile_${o}`;return i}function Xi(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;case"query":return"It names a query, and a copy could not be told apart from it: the builder writes nothing about such a tile but its place.";default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function Jm(e,t){const n=e.tiles[t];if(!n||!de(n)||Xi(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:o,...s}=structuredClone(n);r={...s,name:ws(e,n.source,n.declaration.from)}}else{const o=e.sources.find(s=>s.name===n.source)??Td(e,n.source,{unscoped:!0});r={name:ws(e,o.name,n.name),source:o.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}const i=n.row!==void 0&&n.col!==void 0;return i&&(r={...r,row:(n.row??1)+Ca(n),col:n.col,...n.rowspan!==void 0?{rowspan:n.rowspan}:{}}),e.tiles.splice(t+1,0,r),i&&(e.tiles=bo(e.tiles,e.columns??em,t+1)),t+1}const yi="self";function eg({open:e,document:t,source:n,givenNames:r,dashboards:i,tileLabel:o,onClose:s,onApply:a}){const{theme:d}=qe(),h=d.ui,[l,c]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const f=(t.drills??[]).filter(v=>v.source===n.name);c((n.dimensions??[]).map(v=>{const b=f.find(k=>k.name===v.name);return{name:v.name,expression:v.expression,to:b?.to??[],given:b?.given??""}}))},[e,n,t]);const u=(f,v)=>c(b=>b.map((k,C)=>{if(C!==f)return k;const $={...k};return v($),$})),p=[yi,...i.filter(f=>f!==yi)],g=f=>f===yi?"This report":f,x=()=>{n&&(a(l.filter(f=>f.to.length>0).map(f=>({source:n.name,name:f.name,expression:f.expression,to:f.to,...f.given?{given:f.given}:{}}))),s())},w=_t(d.cardBorder),y=(f,v)=>u(f,b=>{v?b.to=b.lastTo?.length?b.lastTo:[yi]:(b.lastTo=b.to,b.to=[])});return m.jsx(ka,{className:`${Qe.dialog} ${Qe.clickableCellsDialog}`,open:e,onClose:s,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[o&&m.jsxs(H,{component:"span",sx:{fontWeight:h.type.label.fontWeight},children:[o," ·"," "]}),"A click on a table cell sets a filter to its value, on this report or on the one it opens. Bars, lines and points on a chart do not respond to a click. Clicks work in the report, not while you edit it."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx(Ee,{onClick:s,children:"Cancel"}),m.jsx(Ee,{variant:"contained",onClick:x,disabled:l.length===0,children:"Apply"})]}),children:l.length===0?m.jsx(me,{variant:"body2",sx:{color:d.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx(H,{component:"code",children:n.name})," declares no dimensions of its own in this file. A click is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",m.jsx(H,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx(H,{role:"list","aria-label":"Dimensions",children:l.map((f,v)=>{const b=f.to.length>0;return m.jsxs(H,{role:"listitem",sx:{display:"grid",gridTemplateColumns:{xs:"auto minmax(0, 1fr)",sm:"auto minmax(0, 0.9fr) minmax(0, 1.6fr)"},alignItems:"center",columnGap:1.5,rowGap:1,py:1.25,borderTop:v===0?"none":`1px solid ${w}`},children:[m.jsx(cm,{size:"small",checked:b,onChange:k=>y(v,k.target.checked),slotProps:{input:{"aria-label":`${f.name} is clickable`}}}),m.jsxs(H,{sx:{minWidth:0},children:[m.jsx(H,{sx:{...h.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:tg(f.name)}),m.jsxs(H,{title:f.expression,sx:{...h.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[f.name," is ",f.expression]})]}),b?m.jsxs(ct,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...h.type.control},children:[m.jsx(H,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx(Yt,{select:!0,size:"small",value:f.to,inputProps:{"aria-label":`Where ${f.name} goes`},SelectProps:{multiple:!0,renderValue:k=>k.map(g).join(", ")},onChange:k=>u(v,C=>{const $=k.target.value,D=Array.isArray($)?$:String($).split(",").filter(Boolean);D.length===0&&(C.lastTo=C.to),C.to=D}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:p.map(k=>m.jsxs(tt,{value:k,children:[m.jsx(ps,{size:"small",checked:f.to.includes(k),sx:{p:0,mr:1}}),m.jsx(fn,{primary:g(k)})]},k))}),m.jsx(H,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs(Yt,{select:!0,size:"small",value:f.given,inputProps:{"aria-label":`Control ${f.name} sets`},SelectProps:{displayEmpty:!0,renderValue:k=>k===""?f.name:String(k)},onChange:k=>u(v,C=>{C.given=k.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx(tt,{value:"",children:m.jsx(fn,{primary:f.name,secondary:"Named like the dimension"})}),r.map(k=>m.jsx(tt,{value:k,children:k},k))]})]}):m.jsx(me,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},f.name)})})})}function tg(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const ng=mt(m.jsx("path",{d:"M12 4c4.41 0 8 3.59 8 8s-3.59 8-8 8-8-3.59-8-8 3.59-8 8-8m0-2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 13-4-4h8z"})),rg=mt(m.jsx("path",{d:"M11 7H2v2h9zm0 8H2v2h9zm5.34-4L12.8 7.46l1.41-1.41 2.12 2.12 4.24-4.24L22 5.34zm0 8-3.54-3.54 1.41-1.41 2.12 2.12 4.24-4.24L22 13.34z"})),ig=mt(m.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 16H5V10h14zm0-12H5V6h14zm-7 5h5v5h-5z"})),og=mt(m.jsx("path",{d:"M19.5 9.5c-1.03 0-1.9.62-2.29 1.5h-2.92c-.39-.88-1.26-1.5-2.29-1.5s-1.9.62-2.29 1.5H6.79c-.39-.88-1.26-1.5-2.29-1.5C3.12 9.5 2 10.62 2 12s1.12 2.5 2.5 2.5c1.03 0 1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5s1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5 1.38 0 2.5-1.12 2.5-2.5s-1.12-2.5-2.5-2.5"})),sg=mt(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),ag=mt(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function lg(e,t=[]){const n=new Map;for(const o of e.tiles)for(const s of de(o)?o.filters??[]:[])n.set(s.given,(n.get(s.given)??0)+1);const r=[],i=new Set;for(const o of e.localGivens??[])i.add(o.name),r.push({name:o.name,...o.label===void 0?{}:{label:o.label},type:o.type,...o.suggest?{field:o.suggest.dimension}:{},origin:"dashboard",local:o,boundTiles:n.get(o.name)??0});for(const o of t)i.has(o.name)||(i.add(o.name),r.push({...o,origin:"model",boundTiles:n.get(o.name)??0}));for(const[o,s]of n)i.has(o)||r.push({name:o,origin:"model",boundTiles:s});return r}function Zi(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function cg(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function Br(e,t){const n=cg(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 ks(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 dg(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const ug=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function hg(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=kd(r)?r:`${r}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let s=2;;s++)if(!o.has(`${i}_${s}`))return`${i}_${s}`}const fg=[{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 kr(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 Ss=e=>de(e)&&!nr(e)&&e.declaration.kind!=="opaque";function pg(e,t){return e.tiles.map(n=>{const r=(de(n)?n.filters??[]:[]).find(i=>i.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:Zi(t.type)!==void 0?{op:Zi(t.type)}:{}}})}function mg(e,t,n){n.forEach((r,i)=>{const o=e.tiles[i];if(!o||!Ss(o))return;const s=(o.filters??[]).filter(d=>d.given!==t),a=r.include?[...s,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:s;a.length>0?o.filters=a:delete o.filters})}function gg(e,t){const n=(e.localGivens??[]).filter(o=>o.name!==t.name),r=(e.localGivens??[]).findIndex(o=>o.name===t.name),i=[...n];i.splice(r>=0?r:i.length,0,t),e.localGivens=i}function vg(e,t){for(const r of e.tiles){if(!de(r))continue;const i=(r.filters??[]).filter(o=>o.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 $s=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function xg({open:e,document:t,control:n,available:r,takenNames:i=[],fieldsFor:o,onApply:s}){const a=S.useRef(n);e&&(a.current=n);const d=e?n:a.current,h=d!==void 0,[l,c]=S.useState({kind:"new"}),[u,p]=S.useState(""),[g,x]=S.useState("select"),[w,y]=S.useState(""),[f,v]=S.useState(""),[b,k]=S.useState([]),[C,$]=S.useState(!1),[D,j]=S.useState(!1),M=E=>t.sources.find(W=>W.name===E.source)?.base??E.source;S.useEffect(()=>{if(e)if(j(n!==void 0),n){c({kind:"existing",name:n.name}),p(n.label??"");const E=pg(t,n);k(E);const W=E.filter(Z=>Z.include),Y=new Set(W.map(Z=>Z.field));v(Y.size===1?W[0].field:n.field??""),$(Y.size>1)}else c({kind:"new"}),p(""),x("select"),v(""),y(new Date().toISOString().slice(0,10)),k(t.tiles.map(E=>({include:Ss(E),field:""}))),$(!1)},[e,n,t]);const A=S.useMemo(()=>[...(t.localGivens??[]).map(E=>E.name),...r.map(E=>E.name),...i],[t,r,i]),N=S.useMemo(()=>f.trim()?hg(f.trim(),A):"",[f,A]),P=l.kind==="existing"?n??r.find(E=>E.name===l.name):N?{name:N,type:kr({name:N,label:u,kind:g,field:f}).type}:void 0,L=P?.type!==void 0&&!P.type.startsWith("filter<"),_=b.find(E=>E.include)?.op??Zi(P?.type),V=(E,W)=>{j(!0),k(Y=>Y.map((Z,fe)=>fe===E?{...Z,...W}:Z))},T=E=>{j(!0),k(W=>W.map(Y=>({...Y,op:E})))},F=E=>{const W=Zi(E);k(Y=>Y.map(({op:Z,...fe})=>W?{...fe,op:W}:fe))},O=E=>{j(!0),c({kind:"existing",name:E.name}),v(E.field??""),F(E.type)},R=E=>{j(!0),x(E),F(kr({name:"X",label:u,kind:E,field:f}).type)},z=t.tiles.map(Ss),q=z.filter(Boolean).length,U=b.filter((E,W)=>E.include&&z[W]).length,G=t.tiles.filter((E,W)=>(b[W]?.include??!1)&&z[W]&&de(E)),K=G.length>0?G:t.tiles.filter((E,W)=>z[W]&&de(E)),B=S.useMemo(()=>{const E=new Map;let W=!1;for(const Y of K){const Z=o?.(Y);if(Z){W=!0;for(const fe of Z)E.has(fe.name)||E.set(fe.name,fe)}}return W?[...E.values()]:void 0},[b,t.tiles,o]),X=(()=>{const E=f.trim();for(const W of G){const Y=o?.(W);if(!Y||Y.some(Z=>Z.name===E))return M(W)}return G[0]?M(G[0]):t.sources[0]?.base})(),ee=E=>{j(!0),k(W=>W.map((Y,Z)=>({...Y,include:E&&z[Z]})))},oe=S.useMemo(()=>C?b:b.map(E=>({...E,field:f})),[C,b,f]),ie=E=>{for(const W of K){const Y=o?.(W)?.find(Z=>Z.name===E.trim());if(Y?.type)return Y.type}},Oe=E=>Br(P?.type,E.type),We=(E,W)=>{if(E.trim()==="")return"Pick the field this filter compares.";const Y=W?o?.(W):void 0;if(!Y)return;const Z=Y.find(fe=>fe.name===E.trim());if(!Z)return`Not a field of ${W?M(W):"the tiles' source"}.`;if(Z.type&&!Br(P?.type,Z.type))return`${E.trim()} is ${ks(Z.type)}; this filter compares ${ks(P?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},J=E=>{if(j(!0),v(E),h||l.kind!=="new")return;const W=ie(E),Y=kr({name:"X",label:u,kind:g,field:E}).type;W&&!Br(Y,W)&&R(dg(W))},be=E=>{const W=t.tiles[E];return W&&de(W)?W:void 0},ve=oe.map((E,W)=>E.include&&z[W]?We(E.field,be(W)):void 0),se=ve.every(E=>E===void 0),Te=D?ve:ve.map(()=>{}),Ge=D&&!C&&U>0?G.map(E=>We(f,E)).find(Boolean):void 0,Ae=P!==void 0&&se&&(l.kind==="existing"||f.trim()!==""&&N!==""),Ye=()=>{if(!(!P||!Ae))if(l.kind==="new")s(P.name,oe,kr({name:P.name,label:u.trim()||$s(P.name),kind:g,field:f.trim(),...X?{source:X}:{},...w?{dateDefault:w}:{}}));else if(n?.origin==="dashboard"&&n.local){const E=u.trim(),W=E!==(n.local.label??"");s(P.name,oe,W?{...n.local,...E?{label:E}:{}}:void 0)}else s(P.name,oe)},Xe=h&&d.origin==="model";return{editing:h,shown:d,fromModel:Xe,source:l,setSource:c,label:u,setLabel:p,kind:g,dateDefault:w,setDateDefault:y,field:f,rows:b,setRows:k,perTile:C,setPerTile:$,newName:N,target:P,valueTyped:L,commonOp:_,setRow:V,setCommonOp:T,pickExisting:O,pickKind:R,bindable:z,bindableCount:q,included:U,commonFields:B,setAll:ee,accepts:Oe,pickField:J,rowProblems:Te,commonProblem:Ge,canApply:Ae,apply:Ye}}function Gl({value:e,onChange:t,fields:n,accepts:r,label:i,ariaLabel:o,error:s,helperText:a,disabled:d,autoFocus:h,placeholder:l,inputRef:c,sx:u}){const p=S.useMemo(()=>(n??[]).filter(x=>r?.(x)??!0).map(x=>x.name),[n,r]),g=S.useMemo(()=>new Map((n??[]).map(x=>[x.name,x.type])),[n]);return m.jsx(Tm,{freeSolo:!0,size:"small",options:p,inputValue:e,onInputChange:(x,w)=>t(w),value:e,onChange:(x,w)=>t(typeof w=="string"?w:""),disabled:d,disableClearable:!0,renderOption:(x,w)=>S.createElement("li",{...x,key:w},m.jsx(Ul,{type:g.get(w)}),m.jsx(me,{variant:"body2",sx:{flex:1,ml:1},children:w})),renderInput:x=>m.jsx(Yt,{...x,label:i,placeholder:l,autoFocus:h,...c?{inputRef:c}:{},error:s,helperText:a,InputLabelProps:{...x.InputLabelProps,shrink:!0},InputProps:{...x.InputProps,startAdornment:g.get(e.trim())?m.jsx(H,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Ul,{type:g.get(e.trim())})}):void 0},inputProps:{...x.inputProps,"aria-label":o}}),sx:u})}const bg=e=>e&&de(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:e&&de(e)&&e.declaration.kind==="query"?{label:"Not bindable",reason:"It names a query, whose filters live in that query's own definition."}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function yg({open:e,document:t,control:n,available:r,takenNames:i,fieldsFor:o,onClose:s,onApply:a,onRemove:d}){const{theme:h}=qe(),l=h.ui,{editing:c,shown:u,fromModel:p,source:g,setSource:x,label:w,setLabel:y,kind:f,dateDefault:v,setDateDefault:b,field:k,rows:C,setRows:$,perTile:D,setPerTile:j,newName:M,target:A,valueTyped:N,commonOp:P,setRow:L,setCommonOp:_,pickExisting:V,pickKind:T,bindable:F,bindableCount:O,included:R,commonFields:z,setAll:q,accepts:U,pickField:G,rowProblems:K,commonProblem:B,canApply:X,apply:ee}=xg({open:e,document:t,control:n,available:r,...i?{takenNames:i}:{},fieldsFor:o,onApply:a}),oe=S.useRef(null),ie=_t(h.cardBorder),Oe=vo(h.cardBorder,h.tileTitle),[We,J]=S.useState(!1),[be,ve]=S.useState(!1);S.useEffect(()=>{e?ve(!0):J(!1)},[e]),S.useEffect(()=>{be&&(ve(!1),J(c&&R<O))},[be]),S.useEffect(()=>{D&&J(!0)},[D]);const se=z?.find(E=>E.name===k.trim())?.type,Te=E=>{if(!se)return;const W=kr({name:"X",label:w,kind:E,field:k}).type;return Br(W,se)?void 0:`${k.trim()} is ${ks(se)}, which this control cannot filter.`},Ge=w.trim()||(M?$s(M):"Filter"),Ae=f==="number"?"Any":f==="date"?v?new Date(`${v}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ye={...Yi(ie,l),alignSelf:"flex-start","& .MuiToggleButton-root":{...Yi(ie,l)["& .MuiToggleButton-root"],textTransform:"none"}},Xe=(E,W,Y)=>m.jsx(Yt,{select:!0,size:"small",label:"Compares",value:E??">=",onChange:Z=>W(Z.target.value),inputProps:{"aria-label":Y},sx:{width:130},children:ug.filter(Z=>Z.op!=="~").map(Z=>m.jsx(tt,{value:Z.op,children:Z.label},Z.op))});return m.jsx(ka,{className:`${Qe.dialog} ${Qe.filterDialog}`,open:e,onClose:s,...c?{}:{initialFocus:oe},title:c?u.label??u.name:"Add a filter",description:c?m.jsxs(m.Fragment,{children:[m.jsxs(H,{component:"span",sx:{fontFamily:l.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:[c&&m.jsx(Ee,{color:"error",startIcon:m.jsx(sm,{}),onClick:()=>d(u.name),sx:E=>({mr:"auto",color:om(E)}),children:"Remove filter"}),m.jsx(Ee,{onClick:s,children:"Cancel"}),m.jsx(Ot,{title:X||A===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx(Ee,{variant:"contained",onClick:ee,disabled:!X,children:c?"Apply":"Add filter"})})})]}),children:m.jsxs(ct,{sx:{gap:2.5,pt:1},children:[!c&&r.length>0&&m.jsxs(Sd,{exclusive:!0,size:"small",value:g.kind,onChange:(E,W)=>{W==="new"?x({kind:"new"}):W==="existing"&&r[0]&&V(r[0])},"aria-label":"Where the filter comes from",sx:Ye,children:[m.jsx(gs,{value:"new",children:"New in this report"}),m.jsx(gs,{value:"existing",children:"From the model"})]}),!c&&g.kind==="existing"?m.jsx(Yt,{select:!0,size:"small",label:"Filter",value:g.name,onChange:E=>{const W=r.find(Y=>Y.name===E.target.value);W&&V(W)},children:r.map(E=>m.jsxs(tt,{value:E.name,children:[E.label??E.name,m.jsxs(me,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",E.name]})]},E.name))}):null,m.jsxs(H,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:p?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!D&&m.jsx(Gl,{value:k,onChange:G,fields:z,accepts:U,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:oe,error:B!==void 0,helperText:B??(!c&&M?`Declared as $${M}`:void 0)}),!p&&m.jsx(Yt,{size:"small",label:"Label",placeholder:M?$s(M):"",value:w,onChange:E=>y(E.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),N&&!D&&Xe(P,_,"Comparison"),!c&&g.kind==="new"&&m.jsxs(H,{children:[m.jsx(Vl,{children:"Control"}),m.jsx(H,{role:"radiogroup","aria-label":"Filter kind",sx:{display:"grid",gridTemplateColumns:{xs:"repeat(3, minmax(0, 1fr))",sm:"repeat(5, minmax(0, 1fr))"},gap:1},children:fg.map(E=>{const W=E.kind===f,Y=Te(E.kind);return m.jsx(Ot,{title:Y??E.hint,describeChild:!0,children:m.jsxs(ld,{role:"radio","aria-checked":W,"aria-label":E.label,"aria-disabled":Y!==void 0,onClick:()=>{Y===void 0&&T(E.kind)},sx:Z=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:l.radius.tile,border:`1px solid ${W?h.accent:ie}`,boxShadow:W?`0 0 0 1px ${h.accent}`:"none",bgcolor:W?`color-mix(in srgb, ${h.accent} 6%, ${Z.palette.background.paper})`:Z.palette.background.paper,color:W?h.accent:Z.palette.text.secondary,opacity:Y?.45:1,cursor:Y?"default":"pointer",transition:`border-color ${Fe}, background-color ${Fe}`,"&:hover":Y||W?{}:{borderColor:Oe}}),children:[m.jsx(kg,{kind:E.kind}),m.jsx(H,{component:"span",sx:{...l.type.caption,fontWeight:W?600:500,color:W?h.accent:"text.primary",textAlign:"center"},children:wg[E.kind]})]})},E.kind)})}),f==="date"&&m.jsx(Yt,{size:"small",type:"date",label:"Starts at",value:v,onChange:E=>b(E.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs(H,{sx:{border:`1px solid ${ie}`,borderRadius:l.radius.tile,overflow:"hidden"},children:[m.jsxs(ct,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(ag,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs(me,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx(H,{component:"span",sx:{fontWeight:l.type.label.fontWeight},children:R===O&&O>0?`Applies to all ${R} tile${R===1?"":"s"}`:`Applies to ${R} of ${O} tile${O===1?"":"s"}`}),!D&&k.trim()!==""&&R>0&&m.jsxs(H,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx(H,{component:"span",sx:{...l.type.code},children:k.trim()})]})]}),!D&&m.jsx(Ee,{size:"small","aria-expanded":We,onClick:()=>J(E=>!E),children:We?"Done choosing":"Choose tiles"})]}),m.jsx(vs,{in:We,unmountOnExit:!0,children:m.jsxs(H,{sx:{borderTop:`1px solid ${ie}`,px:.5,pb:1},children:[m.jsxs(ct,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx(ps,{size:"small",checked:O>0&&R===O,indeterminate:R>0&&R<O,disabled:O===0,onChange:E=>q(E.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx(me,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx(Ee,{size:"small",onClick:()=>{D||$(E=>E.map(W=>({...W,field:k}))),j(E=>!E)},children:D?"Same field for all":"Adjust per tile"})]}),m.jsx(ct,{sx:{gap:D?1:0},children:t.tiles.map((E,W)=>{if(!de(E))return null;const Y=C[W],Z=E.label??E.name,fe=D?K[W]:void 0;return m.jsxs(ct,{direction:"row",sx:{gap:1,alignItems:D?"flex-start":"center",opacity:F[W]?1:.6},children:[m.jsx(ps,{size:"small",disabled:!F[W],checked:(Y?.include??!1)&&F[W],inputProps:{"aria-label":`Filter ${Z}`},onChange:ze=>L(W,{include:ze.target.checked})}),m.jsx(me,{variant:"body2",sx:{flex:1,minWidth:0,pt:D?1:0},noWrap:!0,children:Z}),F[W]?D&&m.jsxs(m.Fragment,{children:[N&&Xe(Y?.op,ze=>L(W,{op:ze}),`Comparison for ${Z}`),m.jsx(Gl,{value:Y?.field??"",onChange:ze=>L(W,{field:ze}),fields:o?.(E),accepts:U,label:"Field",ariaLabel:`Field for ${Z}`,disabled:!Y?.include,error:fe!==void 0,helperText:fe,sx:{width:220,pr:1}})]}):m.jsx(me,{variant:"caption",sx:{color:h.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:bg(t.tiles[W]).reason})]},ke(E))})})]})})]}),R===0&&m.jsx(me,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!p&&m.jsxs(H,{children:[m.jsx(Vl,{children:"Preview"}),m.jsx(H,{sx:E=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:l.radius.tile,bgcolor:E.palette.action.hover}),children:m.jsxs(H,{"aria-hidden":!0,sx:E=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:l.radius.control,border:`1px solid ${ie}`,bgcolor:E.palette.background.paper,...l.type.control}),children:[m.jsx(H,{component:"span",sx:{color:"text.secondary"},children:Ge}),m.jsx(H,{component:"span",sx:{fontWeight:l.type.label.fontWeight},children:Ae}),m.jsx(ga,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function Vl({children:e}){const t=qe().theme.ui;return m.jsx(me,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const wg={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function kg({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(ng,{sx:t});case"multiselect":return m.jsx(rg,{sx:t});case"text":return m.jsx(sg,{sx:t});case"number":return m.jsx(og,{sx:t});case"date":return m.jsx(ig,{sx:t})}}function Ul({type:e}){const t=e?.replace(/_type$/,""),n=t==="string"?"Abc":t==="number"?"#":t==="date"||t==="timestamp"?"Date":t==="boolean"?"T/F":void 0,r=qe().theme.ui;return n?m.jsx(H,{component:"span","aria-hidden":!0,sx:i=>({fontFamily:r.font.mono,fontSize:10,fontWeight:r.type.label.fontWeight,color:i.palette.text.secondary,bgcolor:i.palette.action.hover,borderRadius:"4px",px:.5,py:.25,minWidth:22,textAlign:"center",flex:"none"}),children:n}):null}const Kl=mt(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Ad(e,t,n,r){const[i,o]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&o(structuredClone(e))},[t,e]),{draft:i,patch:s=>o(a=>{if(a===void 0)return a;const d=structuredClone(a);return s(d),d}),apply:s=>{if(i===void 0)return;const a=structuredClone(i);s(a),o(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:()=>o(void 0)}}const Sg=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.`,$g=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),jg="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",Mg="Declared on its source, so its chart is set in the model.",Cg="It names a query, so its chart is set where that query is declared.";function Eg({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:i,onDuplicate:o,duplicateBlocked:s,view:a,viewStatus:d}){const{theme:h}=qe(),l=h.ui,{draft:c,apply:u,patch:p,close:g}=Ad(t,e!==null,r,n),[x,w]=S.useState(void 0),y=c!==void 0&&de(c)?c:void 0,f=y!==void 0&&!nr(y),v=O=>u(R=>{de(R)&&O(R)}),b=S.useRef(void 0),k=S.useRef(null),C=e!==null;S.useEffect(()=>{C?b.current=t&&de(t)?t.chart:void 0:w(void 0)},[C]);const $=y?.chart??"default",D=Cd(a,$,d),j=y?y.declaration.kind==="query"?Cg:f?y.chart==="custom"?Sg(y.chartLines):void 0:Mg:void 0,M=O=>v(R=>{const z=b.current;O===(z??"default")?(z===void 0?delete R.chart:R.chart=z,delete R.chartCarried):(R.chart=O,a?R.chartCarried=a.chart?[a.chart]:[]:delete R.chartCarried)}),A=f?i?void 0:"Its source declares no dimension a click could filter by.":void 0,N=$==="default"?a?.chart:$,P=N!==void 0&&$g.has(N)?jg:void 0,L=O=>R=>w({kind:O,anchor:R.currentTarget}),_=j??(N===void 0||!Dg.has(N)?"Only a bar, line, scatter or bar and line chart has a color to set.":void 0),V=Array.from(new Set(h.series.map(vd).filter(O=>O!==void 0))).slice(0,8),T=O=>v(R=>{O===void 0?delete R.color:R.color=O.toLowerCase()}),F=(O,R,z)=>m.jsxs(m.Fragment,{children:[m.jsx(fn,{primary:O,...z?{secondary:z}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),R&&m.jsx(me,{variant:"body2",sx:{color:"text.secondary",ml:2},children:R})]});return m.jsxs(m.Fragment,{children:[m.jsxs(Lr,{className:Qe.menu,open:e!==null&&c!==void 0,anchorEl:e,onClose:g,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":y?ht(y):"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:l.radius.menu,border:`1px solid ${_t(h.cardBorder)}`,boxShadow:l.shadow.menu}}},children:[y&&m.jsxs(tt,{"aria-haspopup":"menu","aria-expanded":x?.kind==="chart",disabled:j!==void 0,onClick:L("chart"),onKeyDown:O=>{O.key==="ArrowRight"&&j===void 0&&w({kind:"chart",anchor:O.currentTarget})},children:[F("Chart",j?void 0:D.find(O=>O.value===$)?.label,j),m.jsx(Kl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),y&&j===void 0&&m.jsxs(tt,{"aria-haspopup":"menu","aria-expanded":x?.kind==="color",disabled:_!==void 0,onClick:L("color"),onKeyDown:O=>{O.key==="ArrowRight"&&_===void 0&&w({kind:"color",anchor:O.currentTarget})},children:[F("Color",_?void 0:y.color??"Theme",_),!_&&m.jsx(Fo,{color:y.color??h.series[0],trailing:!0}),m.jsx(Kl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),f&&m.jsx(tt,{"aria-haspopup":"dialog",disabled:A!==void 0,onClick:()=>{g(),i?.()},children:F("Clickable cells…",void 0,A??P)}),y&&o&&m.jsx(tt,{disabled:s!==void 0,onClick:()=>{g(),o()},children:F("Duplicate",void 0,s)}),y?.declaration.kind==="opaque"&&m.jsxs(me,{variant:"body2",sx:{color:h.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",y.declaration.why,", so a filter has no single place to go."]}),y&&m.jsx(Yn,{}),y&&m.jsx(H,{"aria-hidden":!0,sx:{px:2,py:.5,...l.type.code,color:"text.secondary"},children:ht(y).replace("->","→")})]}),m.jsx(Lr,{className:Qe.menu,open:x?.kind==="chart",anchorEl:x?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:O=>{O.key==="ArrowLeft"&&(O.preventDefault(),w(void 0))}},children:D.filter(O=>O.value!=="custom").map(O=>m.jsxs(tt,{role:"menuitemradio","aria-checked":O.value===$,disabled:O.disabled===!0,onClick:()=>{M(O.value),w(void 0)},children:[m.jsx(fn,{primary:O.label,...O.reason??O.hint?{secondary:O.reason??O.hint}:{}}),O.value===$&&m.jsx(xd,{sx:{minWidth:0,ml:2},children:m.jsx(xo,{fontSize:"small",sx:{color:h.accent}})})]},O.value))}),m.jsxs(Lr,{className:Qe.menu,open:x?.kind==="color",anchorEl:x?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,"aria-label":"Color",onKeyDown:O=>{O.key==="ArrowLeft"&&(O.preventDefault(),w(void 0))}},children:[m.jsxs(tt,{role:"menuitemradio","aria-checked":y?.color===void 0,onClick:()=>{T(void 0),w(void 0)},children:[m.jsx(Fo,{color:h.series[0]}),m.jsx(fn,{primary:"Theme",secondary:"The page's own colors"}),y?.color===void 0&&m.jsx(Yl,{color:h.accent})]}),V.map(O=>m.jsxs(tt,{role:"menuitemradio","aria-checked":y?.color===O.toLowerCase(),onClick:()=>{T(O),w(void 0)},children:[m.jsx(Fo,{color:O}),m.jsx(fn,{primary:O.toLowerCase()}),y?.color===O.toLowerCase()&&m.jsx(Yl,{color:h.accent})]},O)),m.jsx(Yn,{}),m.jsxs(tt,{component:"label","aria-checked":y?.color!==void 0&&!V.some(O=>O.toLowerCase()===y.color),role:"menuitemradio",onKeyDown:O=>{(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),k.current?.click())},children:[m.jsx("input",{ref:k,type:"color","aria-label":"Other color",value:y?.color??Og(h.series[0]),onChange:O=>{const R=O.target.value;am(R)&&p(z=>{de(z)&&(z.color=R.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx(fn,{primary:"Other color…"})]})]})]})}const Dg=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Og=e=>(e&&vd(e))??"#000000";function Fo({color:e,trailing:t=!1}){return m.jsx(H,{"aria-hidden":!0,"data-swatch":t?"trailing":"leading",sx:{width:14,height:14,borderRadius:"3px",bgcolor:e,border:"1px solid rgba(0,0,0,0.15)",...t?{ml:1}:{mr:1.5},flex:"none"}})}function Yl({color:e}){return m.jsx(xd,{sx:{minWidth:0,ml:2},children:m.jsx(xo,{fontSize:"small",sx:{color:e}})})}const yo=e=>e.label??lm(ht(e));function Tg({editor:e,catalog:t,columns:n,dashboards:r,bindings:i,tiles:o,drillSource:s,setDrillSource:a,exitDialog:d,renderViewPreview:h,takenGivenNames:l}){const{filterDialog:c,setFilterDialog:u}=i,{menu:p,setMenu:g}=o,[x,w]=S.useState(),y=p===void 0?void 0:e.document.tiles[p.index],f=y&&de(y)?y:void 0,v=(()=>{if(!f||!t)return;const b=t.documentViews?.get(f.source??"")?.get(f.name);if(b&&e.document.sources.some($=>$.name===f.source))return b;if(f.declaration.kind==="inline"||f.declaration.kind==="opaque")return;const k=e.document.sources.find($=>$.name===f.source)?.base??f.source,C=f.declaration.kind==="reference"?f.declaration.from:f.name;return t.sources.find($=>$.name===k)?.views.find($=>$.name===C)})();return m.jsxs(m.Fragment,{children:[m.jsx(yg,{open:c!==void 0,document:e.document,...c?.control?{control:c.control}:{},available:i.available,...l?{takenNames:l}:{},...t?{fieldsFor:i.fieldsFor}:{},onClose:()=>u(void 0),onApply:i.applyFilter,onRemove:i.dropControl}),m.jsx(Eg,{anchor:p?.anchor??null,tile:p===void 0?void 0:e.document.tiles[p.index],onClose:()=>g(void 0),onCommit:b=>{const k=p?.index;k!==void 0&&e.update(C=>{C.tiles[k]=b})},view:v,...v===void 0&&f?{viewStatus:t?"unlisted":"loading"}:{},onDuplicate:()=>{p&&o.duplicate(p.index)},...f&&Xi(f)!==void 0?{duplicateBlocked:Xi(f)}:{},...(e.document.sources.find(b=>b.name===f?.source)?.dimensions?.length??0)>0?{onDrills:()=>{w(f?yo(f):void 0),a(f?.source)}}:{}}),m.jsx(eg,{open:s!==void 0,document:e.document,source:e.document.sources.find(b=>b.name===s),givenNames:i.controlList.map(b=>b.name),dashboards:r??[],...x?{tileLabel:x}:{},onClose:()=>a(void 0),onApply:b=>e.update(k=>{const C=[...(k.drills??[]).filter($=>$.source!==s),...b];C.length===0?delete k.drills:k.drills=C})}),m.jsx(bp,{...d}),m.jsx(Km,{open:o.addingTile,document:e.document,catalog:t,columns:n,onClose:o.closeAdd,onAdd:o.addTile,onAddText:o.addText,...h?{renderPreview:h}:{}})]})}var Ag=Symbol.for("preact-signals");function wo(){if(zt>1)zt--;else{var e,t=!1;for((function(){var i=Ji;for(Ji=void 0;i!==void 0;){var o=i.S;if(o.v===i.v)for(var s=o.t;s!==void 0;s=s.x)s.i===i.i&&(s.i=o.i);i=i.o}})();Hr!==void 0;){var n=Hr;for(Hr=void 0,Qi++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Pd(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(Qi=0,zt--,t)throw e}}function Ce(e){if(zt>0)return e();js=++Rg,zt++;try{return e()}finally{wo()}}var _r,we=void 0;function le(e){var t=we,n=_r;we=void 0,_r=void 0;try{return e()}finally{we=t,_r=n}}var Hr=void 0,zt=0,Qi=0,Rg=0,js=0,Ji=void 0,eo=0;function Rd(e){if(we!==void 0){var t=e.n;if(t===void 0||t.t!==we)return t={i:0,S:e,p:we.s,n:void 0,t:we,e:void 0,x:void 0,r:t},we.s!==void 0&&(we.s.n=t),we.s=t,e.n=t,32&we.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=we.s,t.n=void 0,we.s.n=t,we.s=t),t}}function st(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}st.prototype.brand=Ag;st.prototype.h=function(){return!0};st.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:le(function(){var r;(r=t.W)==null||r.call(t)}))};st.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&&le(function(){var i;(i=t.Z)==null||i.call(t)}))}};st.prototype.subscribe=function(e){var t=this;return wt(function(){var n=t.value;le(function(){return e(n)})},{name:"sub"})};st.prototype.valueOf=function(){return this.value};st.prototype.toString=function(){return this.value+""};st.prototype.toJSON=function(){return this.value};st.prototype.peek=function(){var e=this;return le(function(){return e.value})};Object.defineProperty(st.prototype,"value",{get:function(){var e=Rd(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Qi>100)throw new Error("Cycle detected");(function(n){zt!==0&&Qi===0&&n.l!==js&&(n.l=js,Ji={S:n,v:n.v,i:n.i,o:Ji})})(this),this.v=e,this.i++,eo++,zt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{wo()}}}});function rr(e,t){return new st(e,t)}function Pd(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 Id(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 Nd(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 bn(e,t){st.call(this,void 0,t),this.x=e,this.s=void 0,this.g=eo-1,this.f=4}bn.prototype=new st;bn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===eo))return!0;if(this.g=eo,this.f|=1,this.i>0&&!Pd(this))return this.f&=-2,!0;var e=we;try{Id(this),we=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 we=e,Nd(this),this.f&=-2,!0};bn.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)}st.prototype.S.call(this,e)};bn.prototype.U=function(e){if(this.t!==void 0&&(st.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)}};bn.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(bn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Rd(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Xl(e,t){return new bn(e,t)}function Wd(e){var t=e.m;if(e.m=void 0,typeof t=="function"){zt++;var n=we;we=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Ea(e),r}finally{we=n,wo()}}}function Ea(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Wd(e)}function Pg(e){if(we!==this)throw new Error("Out-of-order effect");Nd(this),we=e,this.f&=-2,8&this.f&&Ea(this),wo()}function ir(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,_r&&_r.push(this)}ir.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()}};ir.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Wd(this),Id(this),zt++;var e=we;return we=this,Pg.bind(this,e)};ir.prototype.N=function(){2&this.f||(this.f|=2,this.u=Hr,Hr=this)};ir.prototype.d=function(){this.f|=8,1&this.f||Ea(this)};ir.prototype.dispose=function(){this.d()};function wt(e,t){var n=new ir(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Ig=Object.create,Da=Object.defineProperty,Ng=Object.defineProperties,Wg=Object.getOwnPropertyDescriptor,zg=Object.getOwnPropertyDescriptors,Zl=Object.getOwnPropertySymbols,Lg=Object.prototype.hasOwnProperty,Fg=Object.prototype.propertyIsEnumerable,Bg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),or=e=>{throw TypeError(e)},Ms=(e,t,n)=>t in e?Da(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_g=(e,t)=>{for(var n in t||(t={}))Lg.call(t,n)&&Ms(e,n,t[n]);if(Zl)for(var n of Zl(t))Fg.call(t,n)&&Ms(e,n,t[n]);return e},Hg=(e,t)=>Ng(e,zg(t)),Ql=(e,t)=>Da(e,"name",{value:t,configurable:!0}),qg=e=>{var t;return[,,,Ig((t=void 0)!=null?t:null)]},zd=["class","method","getter","setter","accessor","field","value","get","set"],Sr=e=>e!==void 0&&typeof e!="function"?or("Function expected"):e,Gg=(e,t,n,r,i)=>({kind:zd[e],name:t,metadata:r,addInitializer:o=>n._?or("Already initialized"):i.push(Sr(o||null))}),Ld=(e,t)=>Ms(t,Bg("metadata"),e[3]),rn=(e,t,n,r)=>{for(var i=0,o=e[t>>1],s=o&&o.length;i<s;i++)t&1?o[i].call(n):r=o[i].call(n,r);return r},sr=(e,t,n,r,i,o)=>{var s,a,d,h,l,c=t&7,u=!!(t&8),p=!!(t&16),g=c>3?e.length+1:c?u?1:2:0,x=zd[c+5],w=c>3&&(e[g-1]=[]),y=e[g]||(e[g]=[]),f=c&&(!p&&!u&&(i=i.prototype),c<5&&(c>3||!p)&&Wg(c<4?i:{get[n](){return vt(this,o)},set[n](b){return Ut(this,o,b)}},n));c?p&&c<4&&Ql(o,(c>2?"set ":c>1?"get ":"")+n):Ql(i,n);for(var v=r.length-1;v>=0;v--)h=Gg(c,n,d={},e[3],y),c&&(h.static=u,h.private=p,l=h.access={has:p?b=>Vg(i,b):b=>n in b},c^3&&(l.get=p?b=>(c^1?vt:Ug)(b,i,c^4?o:f.get):b=>b[n]),c>2&&(l.set=p?(b,k)=>Ut(b,i,k,c^4?o:f.set):(b,k)=>b[n]=k)),a=(0,r[v])(c?c<4?p?o:f[x]:c>4?void 0:{get:f.get,set:f.set}:i,h),d._=1,c^4||a===void 0?Sr(a)&&(c>4?w.unshift(a):c?p?o=a:f[x]=a:i=a):typeof a!="object"||a===null?or("Object expected"):(Sr(s=a.get)&&(f.get=s),Sr(s=a.set)&&(f.set=s),Sr(s=a.init)&&w.unshift(s));return c||Ld(e,i),f&&Da(i,n,f),p?c^4?o:f:i},Oa=(e,t,n)=>t.has(e)||or("Cannot "+n),Vg=(e,t)=>Object(t)!==t?or('Cannot use the "in" operator on this value'):e.has(t),vt=(e,t,n)=>(Oa(e,t,"read from private field"),n?n.call(e):t.get(e)),$r=(e,t,n)=>t.has(e)?or("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ut=(e,t,n,r)=>(Oa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Ug=(e,t,n)=>(Oa(e,t,"access private method"),n);function Cs(e,t){if(t){let n;return Xl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Xl(e)}function $t(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)=>!$t(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=>!$t(e[i],t[i]))}return!1}function ce({get:e},t){return{init(n){return rr(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Pe(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Cs(e.bind(this)),n.set(this,r)),r.value}}function Bo(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,Hg(_g({},i),{enumerable:e}))})}}function li(...e){const t=e.map(n=>wt(n));return()=>t.forEach(n=>n())}var Fd,Bd,_d,Hd,qd,Gd,nt,Ta,_o,Es,Ds,Ze,Aa,Ho,Vd,Os,Ra,qo,Ts,As;Gd=[ce],qd=[ce],Hd=[ce],_d=[Bo()],Bd=[Bo()],Fd=[Bo()];var yn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,rn(nt,5,this),$r(this,Ze),$r(this,Ta,rn(nt,8,this)),rn(nt,11,this),$r(this,Aa,rn(nt,12,this)),rn(nt,15,this),$r(this,Ra,rn(nt,16,this)),rn(nt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return vt(this,Ze,Ts)}get initial(){return vt(this,Ze,Es)}get previous(){return vt(this,Ze,Vd)}set current(e){const t=le(()=>vt(this,Ze,Ts));e&&t&&this.equals(t,e)||Ce(()=>{vt(this,Ze,Es)||Ut(this,Ze,e,Ds),Ut(this,Ze,t,Os),Ut(this,Ze,e,As)})}reset(e=this.defaultValue){Ce(()=>{Ut(this,Ze,void 0,Os),Ut(this,Ze,e,Ds),Ut(this,Ze,e,As)})}};nt=qg();Ta=new WeakMap;Ze=new WeakSet;Aa=new WeakMap;Ra=new WeakMap;_o=sr(nt,20,"#initial",Gd,Ze,Ta),Es=_o.get,Ds=_o.set;Ho=sr(nt,20,"#previous",qd,Ze,Aa),Vd=Ho.get,Os=Ho.set;qo=sr(nt,20,"#current",Hd,Ze,Ra),Ts=qo.get,As=qo.set;sr(nt,2,"current",_d,yn);sr(nt,2,"initial",Bd,yn);sr(nt,2,"previous",Fd,yn);Ld(nt,yn);function Go(e){return le(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var on,Kg=class{constructor(){$r(this,on,new WeakMap)}get(e,t){var n;return e?(n=vt(this,on).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return vt(this,on).has(e)||vt(this,on).set(e,new Map),(r=vt(this,on).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=vt(this,on).get(e))==null?void 0:t.clear():void 0}};on=new WeakMap;var Yg=Object.create,Ud=Object.defineProperty,Xg=Object.getOwnPropertyDescriptor,Jl=Object.getOwnPropertySymbols,Zg=Object.prototype.hasOwnProperty,Qg=Object.prototype.propertyIsEnumerable,Kd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ko=e=>{throw TypeError(e)},ec=Math.pow,Rs=(e,t,n)=>t in e?Ud(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Jg=(e,t)=>{for(var n in t||(t={}))Zg.call(t,n)&&Rs(e,n,t[n]);if(Jl)for(var n of Jl(t))Qg.call(t,n)&&Rs(e,n,t[n]);return e},ev=e=>{var t;return[,,,Yg((t=e?.[Kd("metadata")])!=null?t:null)]},Yd=["class","method","getter","setter","accessor","field","value","get","set"],Xd=e=>e!==void 0&&typeof e!="function"?ko("Function expected"):e,tv=(e,t,n,r,i)=>({kind:Yd[e],name:t,metadata:r,addInitializer:o=>n._?ko("Already initialized"):i.push(Xd(o||null))}),nv=(e,t)=>Rs(t,Kd("metadata"),e[3]),rv=(e,t,n,r)=>{for(var i=0,o=e[t>>1],s=o&&o.length;i<s;i++)o[i].call(n);return r},Zd=(e,t,n,r,i,o)=>{for(var s,a,d,h,l=t&7,c=!1,u=!1,p=2,g=Yd[l+5],x=e[p]||(e[p]=[]),w=(i=i.prototype,Xg(i,n)),y=r.length-1;y>=0;y--)d=tv(l,n,a={},e[3],x),d.static=c,d.private=u,h=d.access={has:f=>n in f},h.get=f=>f[n],s=(0,r[y])(w[g],d),a._=1,Xd(s)&&(w[g]=s);return w&&Ud(i,n,w),i},Qd=(e,t,n)=>t.has(e)||ko("Cannot "+n),iv=(e,t,n)=>(Qd(e,t,"read from private field"),t.get(e)),ov=(e,t,n)=>t.has(e)?ko("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),sv=(e,t,n,r)=>(Qd(e,t,"write to private field"),t.set(e,n),n),xt=class Ps{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ps(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 Ps(t,n)}},At=class sn{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:o,height:s,scale:a}=this,d=new sn(i+t,r+n,o,s);return d.scale=Jg({},a),d}get boundingRectangle(){const{width:t,height:n,left:r,top:i,right:o,bottom:s}=this;return{width:t,height:n,left:r,top:i,right:o,bottom:s}}get center(){const{left:t,top:n,right:r,bottom:i}=this;return new xt((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof sn))return!1;const{left:n,top:r,width:i,height:o}=this;return n===t.left&&r===t.top&&i===t.width&&o===t.height}containsPoint(t){const{top:n,left:r,bottom:i,right:o}=this;return n<=t.y&&t.y<=i&&r<=t.x&&t.x<=o}intersectionArea(t){return t instanceof sn?av(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 sn(n,t,r,i)}static delta(t,n,r={x:"center",y:"center"}){const i=(o,s)=>{const a=r[s],d=s==="x"?o.left:o.top,h=s==="x"?o.width:o.height;return a=="start"?d:a=="end"?d+h:d+h/2};return xt.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return sn.from(t).intersectionRatio(sn.from(n))}};function av(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),o=Math.min(t.top+t.height,e.top+e.height),s=i-r,a=o-n;return r<i&&n<o?s*a:0}var Jd,eu,Is,Ri,ci,So=class extends(Is=yn,eu=[Pe],Jd=[Pe],Is){constructor(e){const t=xt.from(e);super(t,(n,r)=>xt.equals(n,r)),rv(ci,5,this),ov(this,Ri,0),this.velocity={x:0,y:0}}get delta(){return xt.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=xt.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),o=i-iv(this,Ri),s=a=>Math.round(a/o*100);Ce(()=>{sv(this,Ri,i),this.velocity={x:s(r.x),y:s(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(xt.from(e)),this.velocity={x:0,y:0}}};ci=ev(Is);Ri=new WeakMap;Zd(ci,2,"delta",eu,So);Zd(ci,2,"direction",Jd,So);nv(ci,So);function Ns({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(ec(r,2)+ec(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 tu=(e=>(e.Horizontal="x",e.Vertical="y",e))(tu||{}),nu=Object.values(tu),lv=Object.create,Pa=Object.defineProperty,cv=Object.defineProperties,dv=Object.getOwnPropertyDescriptor,uv=Object.getOwnPropertyDescriptors,to=Object.getOwnPropertySymbols,ru=Object.prototype.hasOwnProperty,iu=Object.prototype.propertyIsEnumerable,ou=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ar=e=>{throw TypeError(e)},Ws=(e,t,n)=>t in e?Pa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ia=(e,t)=>{for(var n in t||(t={}))ru.call(t,n)&&Ws(e,n,t[n]);if(to)for(var n of to(t))iu.call(t,n)&&Ws(e,n,t[n]);return e},Na=(e,t)=>cv(e,uv(t)),tc=(e,t)=>Pa(e,"name",{value:t,configurable:!0}),su=(e,t)=>{var n={};for(var r in e)ru.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&to)for(var r of to(e))t.indexOf(r)<0&&iu.call(e,r)&&(n[r]=e[r]);return n},lr=e=>{var t;return[,,,lv((t=e?.[ou("metadata")])!=null?t:null)]},au=["class","method","getter","setter","accessor","field","value","get","set"],jr=e=>e!==void 0&&typeof e!="function"?ar("Function expected"):e,hv=(e,t,n,r,i)=>({kind:au[e],name:t,metadata:r,addInitializer:o=>n._?ar("Already initialized"):i.push(jr(o||null))}),wn=(e,t)=>Ws(t,ou("metadata"),e[3]),re=(e,t,n,r)=>{for(var i=0,o=e[t>>1],s=o&&o.length;i<s;i++)t&1?o[i].call(n):r=o[i].call(n,r);return r},ue=(e,t,n,r,i,o)=>{var s,a,d,h,l,c=t&7,u=!!(t&8),p=!!(t&16),g=c>3?e.length+1:c?u?1:2:0,x=au[c+5],w=c>3&&(e[g-1]=[]),y=e[g]||(e[g]=[]),f=c&&(!p&&!u&&(i=i.prototype),c<5&&(c>3||!p)&&dv(c<4?i:{get[n](){return Re(this,o)},set[n](b){return ft(this,o,b)}},n));c?p&&c<4&&tc(o,(c>2?"set ":c>1?"get ":"")+n):tc(i,n);for(var v=r.length-1;v>=0;v--)h=hv(c,n,d={},e[3],y),c&&(h.static=u,h.private=p,l=h.access={has:p?b=>fv(i,b):b=>n in b},c^3&&(l.get=p?b=>(c^1?Re:lu)(b,i,c^4?o:f.get):b=>b[n]),c>2&&(l.set=p?(b,k)=>ft(b,i,k,c^4?o:f.set):(b,k)=>b[n]=k)),a=(0,r[v])(c?c<4?p?o:f[x]:c>4?void 0:{get:f.get,set:f.set}:i,h),d._=1,c^4||a===void 0?jr(a)&&(c>4?w.unshift(a):c?p?o=a:f[x]=a:i=a):typeof a!="object"||a===null?ar("Object expected"):(jr(s=a.get)&&(f.get=s),jr(s=a.set)&&(f.set=s),jr(s=a.init)&&w.unshift(s));return c||wn(e,i),f&&Pa(i,n,f),p?c^4?o:f:i},Wa=(e,t,n)=>t.has(e)||ar("Cannot "+n),fv=(e,t)=>Object(t)!==t?ar('Cannot use the "in" operator on this value'):e.has(t),Re=(e,t,n)=>(Wa(e,t,"read from private field"),n?n.call(e):t.get(e)),pe=(e,t,n)=>t.has(e)?ar("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ft=(e,t,n,r)=>(Wa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),lu=(e,t,n)=>(Wa(e,t,"access private method"),n);function cu(e,t){return{plugin:e,options:t}}function di(e){return t=>cu(e,t)}function Xr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var du,Zr,za,Pi;du=[ce];var Je=class{constructor(e,t){this.manager=e,this.options=t,pe(this,za,re(Zr,8,this,!1)),re(Zr,11,this),pe(this,Pi,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return le(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=wt(e.bind(this));return Re(this,Pi).add(t),t}destroy(){Re(this,Pi).forEach(e=>e())}static configure(e){return cu(this,e)}};Zr=lr(null);za=new WeakMap;Pi=new WeakMap;ue(Zr,4,"disabled",du,Je,za);wn(Zr,Je);var ui=class extends Je{},Ii,Vo=class{constructor(e){this.manager=e,this.instances=new Map,pe(this,Ii,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Xr).reduce((r,i)=>{const o=r.find(({plugin:s})=>s===i.plugin);return o?(o.options=i.options,r):[...r,i]},[]),n=t.map(({plugin:r})=>r);for(const r of Re(this,Ii))if(!n.includes(r)){if(r.prototype instanceof ui)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);ft(this,Ii,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()}};Ii=new WeakMap;function pv(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var wi=[],Rn,Pn,mv=class extends Je{constructor(e){super(e),pe(this,Rn),pe(this,Pn),this.computeCollisions=this.computeCollisions.bind(this),ft(this,Pn,rr(wi)),this.destroy=li(()=>{const t=this.computeCollisions(),n=le(()=>this.manager.dragOperation.position.current);if(t!==wi){const r=Re(this,Rn);if(ft(this,Rn,n),r&&n.x==r.x&&n.y==r.y)return}else ft(this,Rn,void 0);Re(this,Pn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){le(()=>{e?Re(this,Pn).value=this.computeCollisions():ft(this,Rn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:o,status:s}=r;if(!s.initialized||!o)return wi;const a=[],d=[];for(const h of e??n.droppables){if(h.disabled||i&&!h.accepts(i))continue;const l=t??h.collisionDetector;if(!l)continue;d.push(h),h.shape;const c=le(()=>l({droppable:h,dragOperation:r}));c&&(h.collisionPriority!=null&&(c.priority=h.collisionPriority),a.push(c))}return d.length===0?wi:(a.sort(pv),a)}get collisions(){return Re(this,Pn).value}};Rn=new WeakMap;Pn=new WeakMap;var uu,hu,fu,La,pu,jt,Fa,Fn,Ba,_a;fu=[ce],hu=[ce],uu=[ce];var Ft=class an{constructor(t,n){pe(this,Fa,re(jt,8,this)),re(jt,11,this),pe(this,Fn),pe(this,Ba,re(jt,12,this)),re(jt,15,this),pe(this,_a,re(jt,16,this)),re(jt,19,this);const{effects:r,id:i,data:o={},disabled:s=!1,register:a=!0}=t;let d=i;ft(this,Fn,rr(i)),this.manager=n,this.data=o,this.disabled=s,this.effects=()=>{var h;return[()=>{const{id:l,manager:c}=this;if(l!==d)return d=l,c?.registry.register(this),()=>c?.registry.unregister(this)},...(h=r?.())!=null?h:[]]},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=Re(this,Fn).value;return(n=(t=an.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=an.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Re(this,Fn).peek();t!==i&&(an.pendingIdChanges||(an.pendingIdChanges=new Map,queueMicrotask(()=>{var o;return lu(o=an,La,pu).call(o)})),an.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)}};jt=lr(null);La=new WeakSet;pu=function(){const e=Ft.pendingIdChanges;Ft.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)Re(t,Fn).value=n})};Fa=new WeakMap;Fn=new WeakMap;Ba=new WeakMap;_a=new WeakMap;ue(jt,4,"manager",fu,Ft,Fa);ue(jt,4,"data",hu,Ft,Ba);ue(jt,4,"disabled",uu,Ft,_a);pe(Ft,La);wn(jt,Ft);Ft.pendingIdChanges=null;var $o=Ft,nc=class{constructor(){this.map=rr(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 o=new Map(n);for(const[a,d]of n)if(d===t&&a!==e){o.delete(a);break}o.set(e,t),this.map.value=o;const s=li(...t.effects());return this.cleanupFunctions.set(t,s),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}},mu,gu,vu,xu,bu,yu,zs,rt,Ha,qa,Ga,Rt=class extends(zs=$o,yu=[ce],bu=[ce],xu=[ce],vu=[Pe],gu=[Pe],mu=[Pe],zs){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:o,plugins:s,effects:a}=n,d=su(n,["modifiers","type","sensors","plugins","effects"]);super(Na(Ia({},d),{effects:()=>{var h;return[...(h=a?.())!=null?h:[],()=>{const{manager:l,plugins:c}=this;if(!(!l||!c))for(const u of c){const{plugin:p}=Xr(u);l.registry.plugins.register(p)}}]}}),t),re(rt,5,this),pe(this,Ha,re(rt,8,this)),re(rt,11,this),pe(this,qa,re(rt,12,this)),re(rt,15,this),pe(this,Ga,re(rt,16,this,this.isDragSource?"dragging":"idle")),re(rt,19,this),this.type=i,this.sensors=o,this.modifiers=r,this.alignment=d.alignment,this.plugins=s}pluginConfig(e){if(this.plugins)for(const t of this.plugins){const n=Xr(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}};rt=lr(zs);Ha=new WeakMap;qa=new WeakMap;Ga=new WeakMap;ue(rt,4,"type",yu,Rt,Ha);ue(rt,4,"modifiers",bu,Rt,qa);ue(rt,4,"status",xu,Rt,Ga);ue(rt,2,"isDropping",vu,Rt);ue(rt,2,"isDragging",gu,Rt);ue(rt,2,"isDragSource",mu,Rt);wn(rt,Rt);var wu,ku,Su,$u,ju,Mu,Ls,_e,Va,Ua,Ka,Ya,Xa,Pt=class extends(Ls=$o,Mu=[ce],ju=[ce],$u=[ce],Su=[ce],ku=[ce],wu=[Pe],Ls){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:o,type:s}=n,a=su(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),re(_e,5,this),pe(this,Va,re(_e,8,this)),re(_e,11,this),pe(this,Ua,re(_e,12,this)),re(_e,15,this),pe(this,Ka,re(_e,16,this)),re(_e,19,this),pe(this,Ya,re(_e,20,this)),re(_e,23,this),pe(this,Xa,re(_e,24,this)),re(_e,27,this),this.accept=r,this.collisionDetector=i,this.collisionPriority=o,this.type=s}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}};_e=lr(Ls);Va=new WeakMap;Ua=new WeakMap;Ka=new WeakMap;Ya=new WeakMap;Xa=new WeakMap;ue(_e,4,"accept",Mu,Pt,Va);ue(_e,4,"type",ju,Pt,Ua);ue(_e,4,"collisionDetector",$u,Pt,Ka);ue(_e,4,"collisionPriority",Su,Pt,Ya);ue(_e,4,"shape",ku,Pt,Xa);ue(_e,2,"isDropTarget",wu,Pt);wn(_e,Pt);var gv=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)}},vv=class extends gv{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function Ni(e,t=!0){let n=!1;return Na(Ia({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var xv=class extends ui{constructor(e){super(e);const t=(r,i)=>r.map(({id:o})=>o).join("")===i.map(({id:o})=>o).join("");let n=[];this.destroy=li(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:o}=r;if(r.isDisabled()||$o.pendingIdChanges)return;const s=Ni({collisions:o});if(i.dispatch("collision",s),s.defaultPrevented||t(o,n))return;n=o;const[a]=o;le(()=>{var d;a?.id!==((d=e.dragOperation.target)==null?void 0:d.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},cr=(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))(cr||{}),dr=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(dr||{}),Cu,Eu,Du,Ou,Tu,Au,Ru,yt,Za;Ru=[ce],Au=[Pe],Tu=[Pe],Ou=[Pe],Du=[Pe],Eu=[Pe],Cu=[Pe];var Ht=class{constructor(){re(yt,5,this),pe(this,Za,re(yt,8,this,"idle")),re(yt,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}};yt=lr(null);Za=new WeakMap;ue(yt,4,"value",Ru,Ht,Za);ue(yt,2,"current",Au,Ht);ue(yt,2,"idle",Tu,Ht);ue(yt,2,"initializing",Ou,Ht);ue(yt,2,"initialized",Du,Ht);ue(yt,2,"dragging",Eu,Ht);ue(yt,2,"dropped",Cu,Ht);wn(yt,Ht);var bv=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 le(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=Ni({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return le(()=>{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 o=Ni({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.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:s}=t;s.current==="initializing"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:r,operation:t.snapshot(),cancelable:!1})})}),n)})}move(e){return le(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:o}=r;if(!i.dragging||!o||o.signal.aborted)return;const s=Ni({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",s),queueMicrotask(()=>{var a,d,h,l,c;if(s.defaultPrevented)return;const u=(c=e.to)!=null?c:{x:r.position.current.x+((d=(a=e.by)==null?void 0:a.x)!=null?d:0),y:r.position.current.y+((l=(h=e.by)==null?void 0:h.y)!=null?l:0)};r.position.current=u})})}stop(e={}){return le(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:i}=r;if(!i||i.signal.aborted)return;let o;const s=()=>{const d={resume:()=>{},abort:()=>{}};return o=new Promise((h,l)=>{d.resume=h,d.abort=l}),d};i.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const d=le(()=>{var l;return((l=r.source)==null?void 0:l.status)==="dropping"}),h=()=>{r.controller===i&&(r.controller=void 0),r.reset()};if(d){const{source:l}=r,c=wt(()=>{l?.status==="idle"&&(c(),h())})}else this.manager.renderer.rendering.then(h)})};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:s}),o?o.then(a).catch(()=>r.reset()):a()})}},Xn=class extends Je{constructor(e,t){super(e,t),this.manager=e,this.options=t}},yv=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)}},Wi,Pu=class{constructor(e){this.options=e,pe(this,Wi)}set controller(e){ft(this,Wi,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Re(this,Wi))==null||t.activate(e)}};Wi=new WeakMap;var rc=class extends Je{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},wv=class{constructor(e){this.draggables=new nc,this.droppables=new nc,this.plugins=new Vo(e),this.sensors=new Vo(e),this.modifiers=new Vo(e)}register(e,t){if(e instanceof Rt)return this.draggables.register(e.id,e);if(e instanceof Pt)return this.droppables.register(e.id,e);if(e.prototype instanceof rc)return this.modifiers.register(e,t);if(e.prototype instanceof Xn)return this.sensors.register(e,t);if(e.prototype instanceof Je)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof $o)return e instanceof Rt?this.draggables.unregister(e.id,e):e instanceof Pt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof rc)return this.modifiers.unregister(e);if(e.prototype instanceof Xn)return this.sensors.unregister(e);if(e.prototype instanceof Je)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()}},Iu,Nu,Wu,zu,Lu,Fu,Bu,_u,Hu,Mr,zi,In,Me,Qa,Ja,el,tl,nl,Cr;Hu=[Pe],_u=[ce],Bu=[ce],Fu=[ce],Lu=[ce],zu=[ce],Wu=[Pe],Nu=[Pe],Iu=[Pe];var Et=class{constructor(e){re(Me,5,this),pe(this,Mr),pe(this,zi),pe(this,In,new yn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Ht,pe(this,Qa,re(Me,8,this,!1)),re(Me,11,this),pe(this,Ja,re(Me,12,this,null)),re(Me,15,this),pe(this,el,re(Me,16,this,null)),re(Me,19,this),pe(this,tl,re(Me,20,this,null)),re(Me,23,this),pe(this,nl,re(Me,24,this,[])),re(Me,27,this),this.position=new So({x:0,y:0}),pe(this,Cr,{x:0,y:0}),ft(this,Mr,e)}get shape(){const{current:e,initial:t,previous:n}=Re(this,In);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Re(this,In).current=e:Re(this,In).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Re(this,Mr).registry.draggables.get(t);return n&&ft(this,zi,n),(e=n??Re(this,zi))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Re(this,Mr).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(Na(Ia({},this.snapshot()),{transform:n}));return ft(this,Cr,n),n}snapshot(){return le(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Re(this,Cr),shape:this.shape?Go(this.shape):null,position:Go(this.position),status:Go(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Re(this,In).reset(),this.position.reset({x:0,y:0}),ft(this,Cr,{x:0,y:0}),this.modifiers=[]})}};Me=lr(null);Mr=new WeakMap;zi=new WeakMap;In=new WeakMap;Qa=new WeakMap;Ja=new WeakMap;el=new WeakMap;tl=new WeakMap;nl=new WeakMap;Cr=new WeakMap;ue(Me,2,"shape",Hu,Et);ue(Me,4,"canceled",_u,Et,Qa);ue(Me,4,"activatorEvent",Bu,Et,Ja);ue(Me,4,"sourceIdentifier",Fu,Et,el);ue(Me,4,"targetIdentifier",Lu,Et,tl);ue(Me,4,"modifiers",zu,Et,nl);ue(Me,2,"source",Wu,Et);ue(Me,2,"target",Nu,Et);ue(Me,2,"transform",Iu,Et);wn(Me,Et);var kv={get rendering(){return Promise.resolve()}};function Ct(e,t){return typeof e=="function"?e(t):e??t}var Sv=class{constructor(e){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(c=>c.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var t;const n=e??{},r=Ct(n.plugins,[]),i=Ct(n.sensors,[]),o=Ct(n.modifiers,[]),s=(t=n.renderer)!=null?t:kv,a=new vv(this),d=new wv(this);this.registry=d,this.monitor=a,this.renderer=s,this.actions=new bv(this),this.dragOperation=new Et(this),this.collisionObserver=new mv(this),this.plugins=[xv,...r],this.modifiers=o,this.sensors=i;const{destroy:h}=this,l=li(()=>{var c,u,p;const g=le(()=>this.dragOperation.modifiers),x=this.modifiers;for(const w of g)x.includes(w)||w.destroy();this.dragOperation.modifiers=(p=(u=(c=this.dragOperation.source)==null?void 0:c.modifiers)==null?void 0:u.map(w=>{const{plugin:y,options:f}=Xr(w);return new y(this,f)}))!=null?p:x});this.destroy=()=>{l(),h()}}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}},qu=e=>{throw TypeError(e)},rl=(e,t,n)=>t.has(e)||qu("Cannot "+n),ne=(e,t,n)=>(rl(e,t,"read from private field"),t.get(e)),at=(e,t,n)=>t.has(e)?qu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ut=(e,t,n,r)=>(rl(e,t,"write to private field"),t.set(e,n),n),Gu=(e,t,n)=>(rl(e,t,"access private method"),n);function jo(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Vu(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:o}=i,s=(jo(o)?o.getKeyframes():[]).filter(t);s.length>0&&(r=[s[s.length-1],i])}return r}function Mo(e){const{width:t,height:n,top:r,left:i,bottom:o,right:s}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:i,bottom:o,right:s}}function il(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function hi(e){return"nodeType"in e}function gt(e){var t,n,r;return e?il(e)?e:hi(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 ol(e){const{Document:t}=gt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function en(e){return!e||il(e)?!1:e instanceof gt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Uu(e){return e instanceof gt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function ur(e){return e?il(e)?e.document:hi(e)?ol(e)?e:en(e)||Uu(e)?e.ownerDocument:document:document:document}function $v(e){var t,n,r,i;const{documentElement:o}=ur(e),s=gt(e).visualViewport,a=(t=s?.width)!=null?t:o.clientWidth,d=(n=s?.height)!=null?n:o.clientHeight,h=(r=s?.offsetTop)!=null?r:0,l=(i=s?.offsetLeft)!=null?i:0;return{top:h,left:l,right:l+a,bottom:h+d,width:a,height:d}}function jv(e,t){if(Mv(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function Mv(e){return e.tagName==="DETAILS"}function Qr(e,t=e.getBoundingClientRect(),n=0){var r,i,o,s,a;let d=t;const{ownerDocument:h}=e,l=(r=h.defaultView)!=null?r:window;let c=e.parentElement;for(;c&&c!==h.documentElement;){if(!jv(c)){const v=c.getBoundingClientRect(),b=n*(v.bottom-v.top),k=n*(v.right-v.left),C=n*(v.bottom-v.top),$=n*(v.right-v.left);d={top:Math.max(d.top,v.top-b),right:Math.min(d.right,v.right+k),bottom:Math.min(d.bottom,v.bottom+C),left:Math.max(d.left,v.left-$),width:0,height:0},d.width=d.right-d.left,d.height=d.bottom-d.top}c=c.parentElement}const u=l.visualViewport,p=(i=u?.offsetTop)!=null?i:0,g=(o=u?.offsetLeft)!=null?o:0,x=(s=u?.width)!=null?s:l.innerWidth,w=(a=u?.height)!=null?a:l.innerHeight,y=n*w,f=n*x;return d={top:Math.max(d.top,p-y),right:Math.min(d.right,g+x+f),bottom:Math.min(d.bottom,p+w+y),left:Math.max(d.left,g-f),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 Zn(e){return{x:e.clientX,y:e.clientY}}var Ku=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Fs(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(...Fs(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(...Fs(i.document,t))}}catch{}return n}function sl(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Yu(){var e,t;const n=sl()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function al(e){return!e||!hi(e)?!1:e instanceof gt(e).ShadowRoot}function no(e){if(e&&hi(e)){let t=e.getRootNode();if(al(t)||t instanceof Document)return t}return ur(e)}function ll(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Cv(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,o)=>{const s=r[o];ic(i)&&ic(s)&&(i.type!=="file"&&(i.value=s.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),oc(i)&&oc(s)&&s.width>0&&s.height>0&&i.getContext("2d")?.drawImage(s,0,0)}),n}function ic(e){return"value"in e}function oc(e){return e.tagName==="CANVAS"}function Xu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Ev(r)){const{contentDocument:i}=r;if(i){const{left:o,top:s}=r.getBoundingClientRect();return Xu(i,{x:t-o,y:n-s})}}return r}function Ev(e){return e?.tagName==="IFRAME"}var Bs=new WeakMap;function Dv(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 Zu=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 s of n)for(const a of r){const{type:d,listener:h,options:l}=a,c=[s,a];s.addEventListener(d,h,l),this.entries.add(c),i.push(c)}const o=this.entries;return function(){for(const s of i){const[a,{type:d,listener:h,options:l}]=s;a.removeEventListener(d,h,l),o.delete(s)}}}};function Qn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Ov(e){const t=new Set;let n=Qn(e);for(;n;)t.add(n),n=Qn(n);return t}function Tv(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function Qu(e,t){const n=()=>performance.now();let r,i;return function(...o){const s=this;i?(r?.(),r=Tv(()=>{e.apply(s,o),i=n()},t-(n()-i))):(e.apply(s,o),i=n())}}function Av(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 Rv(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Qr(e,t);return n>0&&r>0}var Pv=Ku?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Li,Iv=class extends Pv{constructor(e){super(t=>{if(!ne(this,Li)){ut(this,Li,!0);return}e(t,this)}),at(this,Li,!1)}};Li=new WeakMap;var sc=Array.from({length:100},(e,t)=>t/100),Ju=75,ln,ro,Gt,cn,Er,Ke,qr,Dr,io,eh,th,nh=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,at(this,io),this.disconnect=()=>{var o,s,a;ut(this,qr,!0),(o=ne(this,Gt))==null||o.disconnect(),(s=ne(this,cn))==null||s.disconnect(),ne(this,Er).disconnect(),(a=ne(this,Ke))==null||a.remove()},at(this,ln,!0),at(this,ro),at(this,Gt),at(this,cn),at(this,Er),at(this,Ke),at(this,qr,!1),at(this,Dr,Qu(()=>{var o,s,a;const{element:d}=this;if((o=ne(this,cn))==null||o.disconnect(),ne(this,qr)||!ne(this,ln)||!d.isConnected)return;const h=(s=d.ownerDocument)!=null?s:document,{innerHeight:l,innerWidth:c}=(a=h.defaultView)!=null?a:window,u=d.getBoundingClientRect(),p=Qr(d,u),{top:g,left:x,bottom:w,right:y}=p,f=-Math.floor(g),v=-Math.floor(x),b=-Math.floor(c-y),k=-Math.floor(l-w),C=`${f}px ${b}px ${k}px ${v}px`;this.boundingClientRect=u,ut(this,cn,new IntersectionObserver($=>{const[D]=$,{intersectionRect:j}=D;(D.intersectionRatio!==1?D.intersectionRatio:At.intersectionRatio(j,Qr(d)))!==1&&ne(this,Dr).call(this)},{threshold:sc,rootMargin:C,root:h})),ne(this,cn).observe(d),Gu(this,io,eh).call(this)},Ju)),this.boundingClientRect=e.getBoundingClientRect(),ut(this,ln,Rv(e,this.boundingClientRect));let r=!0;this.callback=o=>{r&&(r=!1,n.skipInitial)||t(o)};const i=e.ownerDocument;n?.debug&&(ut(this,Ke,document.createElement("div")),ne(this,Ke).style.background="rgba(0,0,0,0.15)",ne(this,Ke).style.position="fixed",ne(this,Ke).style.pointerEvents="none",i.body.appendChild(ne(this,Ke))),ut(this,Er,new IntersectionObserver(o=>{var s,a;const d=o[o.length-1],{boundingClientRect:h,isIntersecting:l}=d,{width:c,height:u}=h,p=ne(this,ln);ut(this,ln,l),!(!c&&!u)&&(p&&!l?((s=ne(this,cn))==null||s.disconnect(),this.callback(null),(a=ne(this,Gt))==null||a.disconnect(),ut(this,Gt,void 0),ne(this,Ke)&&(ne(this,Ke).style.visibility="hidden")):ne(this,Dr).call(this),l&&!ne(this,Gt)&&(ut(this,Gt,new Iv(ne(this,Dr))),ne(this,Gt).observe(e)))},{threshold:sc,root:i})),ne(this,ln)&&!n.skipInitial&&this.callback(this.boundingClientRect),ne(this,Er).observe(e)}};ln=new WeakMap;ro=new WeakMap;Gt=new WeakMap;cn=new WeakMap;Er=new WeakMap;Ke=new WeakMap;qr=new WeakMap;Dr=new WeakMap;io=new WeakSet;eh=function(){ne(this,qr)||(Gu(this,io,th).call(this),!Av(this.boundingClientRect,ne(this,ro))&&(this.callback(this.boundingClientRect),ut(this,ro,this.boundingClientRect)))};th=function(){if(ne(this,Ke)){const{top:e,left:t,width:n,height:r}=Qr(this.element);ne(this,Ke).style.overflow="hidden",ne(this,Ke).style.visibility="visible",ne(this,Ke).style.top=`${Math.floor(e)}px`,ne(this,Ke).style.left=`${Math.floor(t)}px`,ne(this,Ke).style.width=`${Math.floor(n)}px`,ne(this,Ke).style.height=`${Math.floor(r)}px`}};var ki=new WeakMap,Si=new WeakMap;function Nv(e,t){let n=ki.get(e);return n||(n={disconnect:new nh(e,r=>{const i=ki.get(e);i&&i.callbacks.forEach(o=>o(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),ki.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(ki.delete(e),n.disconnect())}}function Wv(e,t){const n=new Set;for(const r of e){const i=Nv(r,t);n.add(i)}return()=>n.forEach(r=>r())}function zv(e,t){var n;const r=e.ownerDocument;if(!Si.has(r)){const s=new AbortController,a=new Set;document.addEventListener("scroll",d=>a.forEach(h=>h(d)),{capture:!0,passive:!0,signal:s.signal}),Si.set(r,{disconnect:()=>s.abort(),listeners:a})}const{listeners:i,disconnect:o}=(n=Si.get(r))!=null?n:{};return!i||!o?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(o(),Si.delete(r))})}var Or,Tr,Fi,_s,Lv=class{constructor(e,t,n){this.callback=t,at(this,Or),at(this,Tr,!1),at(this,Fi),at(this,_s,Qu(s=>{if(!ne(this,Tr)&&s.target&&"contains"in s.target&&typeof s.target.contains=="function"){for(const a of ne(this,Fi))if(s.target.contains(a)){this.callback(ne(this,Or).boundingClientRect);break}}},Ju));const r=Ov(e),i=Wv(r,t),o=zv(e,ne(this,_s));ut(this,Fi,r),ut(this,Or,new nh(e,t,n)),this.disconnect=()=>{ne(this,Tr)||(ut(this,Tr,!0),i(),o(),ne(this,Or).disconnect())}}};Or=new WeakMap;Tr=new WeakMap;Fi=new WeakMap;_s=new WeakMap;function Hs(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function qn(e){try{Hs(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function ac(e){return!Ku||!e?!1:e===ur(e).scrollingElement}function rh(e){var t,n;const r=gt(e),i=ac(e)?$v(e):Mo(e),o=r.visualViewport,s=ac(e)?{height:(t=o?.height)!=null?t:r.innerHeight,width:(n=o?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-s.width,y:e.scrollHeight-s.height}},d=a.current.y<=0,h=a.current.x<=0,l=a.current.y>=a.max.y,c=a.current.x>=a.max.x;return{rect:i,position:a,isTop:d,isLeft:h,isBottom:l,isRight:c}}function Fv(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:o,position:s}=rh(e),{x:a,y:d}=t??{x:0,y:0},h=!n&&s.current.y+d>0,l=!r&&s.current.y+d<s.max.y,c=!i&&s.current.x+a>0,u=!o&&s.current.x+a<s.max.x;return{top:h,bottom:l,left:c,right:u,x:c||u,y:h||l}}var cl=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))}},oo=new cl(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Bv=new cl(e=>setTimeout(e,50)),so=new Map,_v=so.clear.bind(so);function It(e,t=!1){if(!t)return lc(e);let n=so.get(e);return n||(n=lc(e),so.set(e,n),Bv.schedule(_v),n)}function lc(e){return gt(e).getComputedStyle(e)}function Hv(e,t=It(e,!0)){return t.position==="fixed"||t.position==="sticky"}function qv(e,t=It(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 Gv={excludeElement:!0,escapeShadowDOM:!0};function qs(e,t=Gv){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,o=new Set;function s(a){if(n!=null&&o.size>=n||!a)return o;if(ol(a)&&a.scrollingElement!=null&&!o.has(a.scrollingElement))return o.add(a.scrollingElement),o;if(i&&al(a))return s(a.host);if(!en(a))return Uu(a)?s(a.parentElement):o;if(o.has(a))return o;const d=It(a,!0);if(r&&a===e||qv(a,d)&&o.add(a),Hv(a,d)){const{scrollingElement:h}=a.ownerDocument;return h&&o.add(h),o}return s(a.parentNode)}return e?s(e):o}function Jn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Qn(e);for(;r;){if(r===t)return n;const i=Mo(r),{x:o,y:s}=Vv(r,i);n.x=n.x+i.left,n.y=n.y+i.top,n.scaleX=n.scaleX*o,n.scaleY=n.scaleY*s,r=Qn(r)}return n}function Vv(e,t=Mo(e)){const n=Math.round(t.width),r=Math.round(t.height);if(en(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=It(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function Uv(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 Jr(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 Co(e){var t,n,r,i,o,s,a,d,h;const{scale:l,transform:c,translate:u}=e,p=Uv(l),g=Jr(u),x=Kv(c);if(!x&&!p&&!g)return null;const w={x:(t=p?.x)!=null?t:1,y:(n=p?.y)!=null?n:1},y={x:(r=g?.x)!=null?r:0,y:(i=g?.y)!=null?i:0},f={x:(o=x?.x)!=null?o:0,y:(s=x?.y)!=null?s:0,scaleX:(a=x?.scaleX)!=null?a:1,scaleY:(d=x?.scaleY)!=null?d:1};return{x:y.x+f.x,y:y.y+f.y,z:(h=g?.z)!=null?h:0,scaleX:w.x*f.scaleX,scaleY:w.y*f.scaleY}}function Kv(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 bt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(bt||{}),Yv={x:.2,y:.2},Xv={x:10,y:10};function Zv(e,t,n,r=25,i=Yv,o=Xv){const{x:s,y:a}=t,{rect:d,isTop:h,isBottom:l,isLeft:c,isRight:u}=rh(e),p=Jn(e),g=It(e,!0),x=Co(g),w=x!==null?x?.scaleX<0:!1,y=x!==null?x?.scaleY<0:!1,f=new At(d.left*p.scaleX+p.x,d.top*p.scaleY+p.y,d.width*p.scaleX,d.height*p.scaleY),v={x:0,y:0},b={x:0,y:0},k={height:f.height*i.y,width:f.width*i.x};return k.height>0&&(!h||y&&!l)&&a<=f.top+k.height&&n?.y!==1&&s>=f.left-o.x&&s<=f.right+o.x?(v.y=y?1:-1,b.y=r*Math.abs((f.top+k.height-a)/k.height)):k.height>0&&(!l||y&&!h)&&a>=f.bottom-k.height&&n?.y!==-1&&s>=f.left-o.x&&s<=f.right+o.x&&(v.y=y?-1:1,b.y=r*Math.abs((f.bottom-k.height-a)/k.height)),k.width>0&&(!u||w&&!c)&&s>=f.right-k.width&&n?.x!==-1&&a>=f.top-o.y&&a<=f.bottom+o.y?(v.x=w?-1:1,b.x=r*Math.abs((f.right-k.width-s)/k.width)):k.width>0&&(!c||w&&!u)&&s<=f.left+k.width&&n?.x!==1&&a>=f.top-o.y&&a<=f.bottom+o.y&&(v.x=w?1:-1,b.x=r*Math.abs((f.left+k.width-s)/k.width)),{direction:v,speed:b}}function ih(e,{block:t="nearest",inline:n="nearest"}={}){if(!en(e))return;const r=qs(e),i=[];for(const o of r){if(!en(o))continue;const{top:s,left:a}=Qv(e,o);let d=s,h=a;for(const l of i)d-=l.scrollTop,h-=l.scrollLeft;if(t!=="none"){const l=d<o.scrollTop,c=d+e.offsetHeight>o.scrollTop+o.clientHeight;l!==c&&(t==="center"?o.scrollTop=d-o.clientHeight/2+e.offsetHeight/2:l?o.scrollTop=d:o.scrollTop=d+e.offsetHeight-o.clientHeight)}if(n!=="none"){const l=h<o.scrollLeft,c=h+e.offsetWidth>o.scrollLeft+o.clientWidth;l!==c&&(n==="center"?o.scrollLeft=h-o.clientWidth/2+e.offsetWidth/2:l?o.scrollLeft=h:o.scrollLeft=h+e.offsetWidth-o.clientWidth)}i.push(o)}}function cc(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!en(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function Qv(e,t){const n=cc(e),r=cc(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Jv(e,t,n){const{scaleX:r,scaleY:i,x:o,y:s}=t,a=e.left+o+(1-r)*parseFloat(n),d=e.top+s+(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),h=r?e.width*r:e.width,l=i?e.height*i:e.height;return{width:h,height:l,top:d,right:a+h,bottom:d+l,left:a}}function ex(e,t,n){const{scaleX:r,scaleY:i,x:o,y:s}=t,a=e.left-o-(1-r)*parseFloat(n),d=e.top-s-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),h=r?e.width/r:e.width,l=i?e.height/i:e.height;return{width:h,height:l,top:d,right:a+h,bottom:d+l,left:a}}function oh({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function dc(e,t=It(e).translate,n=!0){if(n){const r=Vu(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const o=Jr(i);if(o)return o}}}if(t){const r=Jr(t);if(r)return r}return{x:0,y:0,z:0}}var tx=new cl(e=>setTimeout(e,0)),Gr=new Map,nx=Gr.clear.bind(Gr);function rx(e){const t=e.ownerDocument;let n=Gr.get(t);if(n)return n;n=t.getAnimations(),Gr.set(t,n),tx.schedule(nx);const r=n.filter(i=>jo(i.effect)&&i.effect.target===e);return Gr.set(e,r),n}function ix(e,t){const n=rx(e).filter(r=>{var i,o;if(jo(r.effect)){const{target:s}=r.effect;if((o=s&&((i=t.isValidTarget)==null?void 0:i.call(t,s)))==null||o)return r.effect.getKeyframes().some(a=>{for(const d of t.properties)if(a[d])return!0})}}).map(r=>{const{effect:i,currentTime:o}=r,s=i?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof s=="number"&&typeof o=="number"&&o<s)return r.currentTime=s,()=>{r.currentTime=o}});if(n.length>0)return()=>n.forEach(r=>r?.())}var Tt=class extends At{constructor(e,t={}){var n,r,i,o;const{frameTransform:s=Jn(e),ignoreTransforms:a,getBoundingClientRect:d=Mo}=t,h=ix(e,{properties:["transform","translate","scale","width","height"],isValidTarget:k=>(k!==e||sl())&&k.contains(e)}),l=d(e);let{top:c,left:u,width:p,height:g}=l,x;const w=It(e),y=Co(w),f={x:(n=y?.scaleX)!=null?n:1,y:(r=y?.scaleY)!=null?r:1},v=ox(e,w);h?.(),y&&(x=ex(l,y,w.transformOrigin),(a||v)&&(c=x.top,u=x.left,p=x.width,g=x.height));const b={width:(i=x?.width)!=null?i:p,height:(o=x?.height)!=null?o:g};if(v&&!a&&x){const k=Jv(x,v,w.transformOrigin);c=k.top,u=k.left,p=k.width,g=k.height,f.x=v.scaleX,f.y=v.scaleY}s&&(a||(u*=s.scaleX,p*=s.scaleX,c*=s.scaleY,g*=s.scaleY),u+=s.x,c+=s.y),super(u,c,p,g),this.scale=f,this.intrinsicWidth=b.width,this.intrinsicHeight=b.height}};function ox(e,t){const n=e.getAnimations();if(!n.length)return null;let r,i,o,s=!1;for(const a of n){if(a.playState!=="running")continue;const d=jo(a.effect)?a.effect.getKeyframes():[],h=d[d.length-1];if(!h)continue;const{transform:l,translate:c,scale:u}=h;typeof l=="string"&&l&&(r=l,s=!0),typeof c=="string"&&c&&(i=c,s=!0),typeof u=="string"&&u&&(o=u,s=!0)}return s?Co({transform:r??t.transform,translate:i??t.translate,scale:o??t.scale}):null}function Vr(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 sx=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Vr(n))for(const[r,i]of Object.entries(e)){const o=`${t}${r}`;this.initial.has(o)||this.initial.set(o,n.style.getPropertyValue(o)),n.style.setProperty(o,typeof i=="string"?i:`${i}px`)}}remove(e,t=""){const{element:n}=this;if(Vr(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(Vr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function vn(e){return e?e instanceof gt(e).Element||hi(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function ei(e){if(!e)return!1;const{KeyboardEvent:t}=gt(e.target);return e instanceof t}function ax(e){if(!e)return!1;const{PointerEvent:t}=gt(e.target);return e instanceof t}function lx(e){if(!vn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||cx(e)}function cx(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Uo={};function Gs(e){const t=Uo[e]==null?0:Uo[e]+1;return Uo[e]=t,`${e}-${t}`}var dl=({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=xt.distance(t.shape.center,n);return{id:r,value:1/i,type:dr.PointerIntersection,priority:cr.High}}return null},dx=({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,o=xt.distance(t.shape.center,i.current),s=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:s,type:dr.ShapeIntersection,priority:cr.Normal}}return null},sh=e=>{var t;return(t=dl(e))!=null?t:dx(e)},ux=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const o=r?At.from(r.current.boundingRectangle).corners:void 0,s=At.from(n.shape.boundingRectangle).corners.reduce((a,d,h)=>{var l;return a+xt.distance(xt.from(d),(l=o?.[h])!=null?l:i.current)},0)/4;return{id:n.id,value:1/s,type:dr.Collision,priority:cr.Normal}},hx=Object.create,ul=Object.defineProperty,fx=Object.defineProperties,px=Object.getOwnPropertyDescriptor,mx=Object.getOwnPropertyDescriptors,ao=Object.getOwnPropertySymbols,ah=Object.prototype.hasOwnProperty,lh=Object.prototype.propertyIsEnumerable,ch=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),hr=e=>{throw TypeError(e)},Vs=(e,t,n)=>t in e?ul(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ti=(e,t)=>{for(var n in t||(t={}))ah.call(t,n)&&Vs(e,n,t[n]);if(ao)for(var n of ao(t))lh.call(t,n)&&Vs(e,n,t[n]);return e},hl=(e,t)=>fx(e,mx(t)),uc=(e,t)=>ul(e,"name",{value:t,configurable:!0}),dh=(e,t)=>{var n={};for(var r in e)ah.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ao)for(var r of ao(e))t.indexOf(r)<0&&lh.call(e,r)&&(n[r]=e[r]);return n},fr=e=>{var t;return[,,,hx((t=e?.[ch("metadata")])!=null?t:null)]},uh=["class","method","getter","setter","accessor","field","value","get","set"],Ar=e=>e!==void 0&&typeof e!="function"?hr("Function expected"):e,gx=(e,t,n,r,i)=>({kind:uh[e],name:t,metadata:r,addInitializer:o=>n._?hr("Already initialized"):i.push(Ar(o||null))}),kn=(e,t)=>Vs(t,ch("metadata"),e[3]),He=(e,t,n,r)=>{for(var i=0,o=e[t>>1],s=o&&o.length;i<s;i++)t&1?o[i].call(n):r=o[i].call(n,r);return r},kt=(e,t,n,r,i,o)=>{var s,a,d,h,l,c=t&7,u=!!(t&8),p=!!(t&16),g=c>3?e.length+1:c?u?1:2:0,x=uh[c+5],w=c>3&&(e[g-1]=[]),y=e[g]||(e[g]=[]),f=c&&(!p&&!u&&(i=i.prototype),c<5&&(c>3||!p)&&px(c<4?i:{get[n](){return ge(this,o)},set[n](b){return it(this,o,b)}},n));c?p&&c<4&&uc(o,(c>2?"set ":c>1?"get ":"")+n):uc(i,n);for(var v=r.length-1;v>=0;v--)h=gx(c,n,d={},e[3],y),c&&(h.static=u,h.private=p,l=h.access={has:p?b=>vx(i,b):b=>n in b},c^3&&(l.get=p?b=>(c^1?ge:xn)(b,i,c^4?o:f.get):b=>b[n]),c>2&&(l.set=p?(b,k)=>it(b,i,k,c^4?o:f.set):(b,k)=>b[n]=k)),a=(0,r[v])(c?c<4?p?o:f[x]:c>4?void 0:{get:f.get,set:f.set}:i,h),d._=1,c^4||a===void 0?Ar(a)&&(c>4?w.unshift(a):c?p?o=a:f[x]=a:i=a):typeof a!="object"||a===null?hr("Object expected"):(Ar(s=a.get)&&(f.get=s),Ar(s=a.set)&&(f.set=s),Ar(s=a.init)&&w.unshift(s));return c||kn(e,i),f&&ul(i,n,f),p?c^4?o:f:i},fl=(e,t,n)=>t.has(e)||hr("Cannot "+n),vx=(e,t)=>Object(t)!==t?hr('Cannot use the "in" operator on this value'):e.has(t),ge=(e,t,n)=>(fl(e,t,"read from private field"),n?n.call(e):t.get(e)),Ne=(e,t,n)=>t.has(e)?hr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),it=(e,t,n,r)=>(fl(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),xn=(e,t,n)=>(fl(e,t,"access private method"),n),hc={role:"button",roleDescription:"draggable"},xx="dnd-kit-description",bx="dnd-kit-announcement",yx={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."},wx={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 kx(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Sx(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function $x(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 jx=["dragover","dragmove"],Mx=class extends Je{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=xx,announcement:i=bx}={},announcements:o=wx,screenReaderInstructions:s=yx,debounce:a=500}=t??{},d=n?`${r}-${n}`:Gs(r),h=n?`${i}-${n}`:Gs(i);let l,c,u,p;const g=(k=p)=>{!u||!k||u?.nodeValue!==k&&(u.nodeValue=k)},x=()=>oo.schedule(g),w=Cx(x,a),y=Object.entries(o).map(([k,C])=>this.manager.monitor.addEventListener(k,($,D)=>{const j=u;if(!j)return;const M=C?.($,D);M&&j.nodeValue!==M&&(p=M,jx.includes(k)?w():(x(),w.cancel()))})),f=()=>{let k=[];l?.isConnected||(l=Sx(d,s.draggable),k.push(l)),c?.isConnected||(c=$x(h),u=document.createTextNode(""),c.appendChild(u),k.push(c)),k.length>0&&document.body.append(...k)},v=new Set;function b(){for(const k of v)k()}this.registerEffect(()=>{var k;v.clear();for(const C of this.manager.registry.draggables.value){const $=(k=C.handle)!=null?k:C.element;if($){(!l||!c)&&v.add(f),(!kx($)||sl())&&!$.hasAttribute("tabindex")&&v.add(()=>$.setAttribute("tabindex","0")),!$.hasAttribute("role")&&$.tagName.toLowerCase()!=="button"&&v.add(()=>$.setAttribute("role",hc.role)),$.hasAttribute("aria-roledescription")||v.add(()=>$.setAttribute("aria-roledescription",hc.roleDescription)),$.hasAttribute("aria-describedby")||v.add(()=>$.setAttribute("aria-describedby",d));for(const j of["aria-pressed","aria-grabbed"]){const M=String(C.isDragging);$.getAttribute(j)!==M&&v.add(()=>$.setAttribute(j,M))}const D=String(C.disabled);$.getAttribute("aria-disabled")!==D&&v.add(()=>$.setAttribute("aria-disabled",D))}}v.size>0&&oo.schedule(b)}),this.destroy=()=>{super.destroy(),l?.remove(),c?.remove(),y.forEach(k=>k())}}};function Cx(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var lo=new Map,hh,fh,ph,mh,Us,Ur,Lt,pl,er,gh,vh,xh,bh,tn=class extends(Us=ui,mh=[ce],ph=[Pe],fh=[Pe],hh=[Pe],Us){constructor(e,t){super(e,t),He(Lt,5,this),Ne(this,er),Ne(this,Ur,new Set),Ne(this,pl,He(Lt,8,this,new Set)),He(Lt,11,this),this.registerEffect(xn(this,er,gh))}register(e){return ge(this,Ur).add(e),()=>{ge(this,Ur).delete(e)}}addRoot(e){return le(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{le(()=>{const t=new Set(this.additionalRoots);t.delete(e),this.additionalRoots=t})}}get sourceRoot(){var e;const{source:t}=this.manager.dragOperation;return no((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return no((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}};Lt=fr(Us);Ur=new WeakMap;pl=new WeakMap;er=new WeakSet;gh=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ge(this,Ur))t.push(xn(this,er,vh).call(this,n,r));return()=>{for(const n of t)n()}};vh=function(e,t){let n=lo.get(e);n||(n=new Map,lo.set(e,n));let r=n.get(t);if(!r){const o=ol(e)?xn(this,er,xh).call(this,e,n,t):xn(this,er,bh).call(this,e,n,t);if(!o)return()=>{};r=o,n.set(t,r)}r.refCount++;let i=!1;return()=>{i||(i=!0,r.refCount--,r.refCount===0&&r.cleanup())}};xh=function(e,t,n){var r;const i=e.createElement("style"),{nonce:o}=(r=this.options)!=null?r:{};o&&i.setAttribute("nonce",o),i.textContent=n,e.head.prepend(i);const s=new MutationObserver(a=>{for(const d of a)for(const h of Array.from(d.removedNodes))if(h===i){e.head.prepend(i);return}});return s.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{s.disconnect(),i.remove(),t.delete(n),t.size===0&&lo.delete(e)}}};bh=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:i}=r??{};if(!i)return null;const o=new i;return o.replaceSync(n),e.adoptedStyleSheets.push(o),{refCount:0,cleanup:()=>{var s;if(al(e)&&(s=e.host)!=null&&s.isConnected){const a=e.adoptedStyleSheets.indexOf(o);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&lo.delete(e)}}};kt(Lt,4,"additionalRoots",mh,tn,pl);kt(Lt,2,"sourceRoot",ph,tn);kt(Lt,2,"targetRoot",fh,tn);kt(Lt,2,"roots",hh,tn);kn(Lt,tn);tn.configure=di(tn);var Eo=tn,Ex=class extends Je{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Eo),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const o=this.destroy.bind(this);this.destroy=()=>{i(),o()}}}},fi="data-dnd-",Ks=`${fi}dropping`,Ue="--dnd-",Dt=`${fi}dragging`,co=`${fi}placeholder`,Dx=[Dt,co,"popover","aria-pressed","aria-grabbing"],Ox=["view-transition-name"],Tx=`
|
|
9
|
-
:is(:root,:host) [${Dt}] {
|
|
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(${Ue}top, 0px) !important;
|
|
16
|
-
left: var(${Ue}left, 0px) !important;
|
|
17
|
-
right: unset !important;
|
|
18
|
-
bottom: unset !important;
|
|
19
|
-
width: var(${Ue}width, auto);
|
|
20
|
-
max-width: var(${Ue}width, auto);
|
|
21
|
-
height: var(${Ue}height, auto);
|
|
22
|
-
max-height: var(${Ue}height, auto);
|
|
23
|
-
transform: var(${Ue}transform, none) !important;
|
|
24
|
-
transition: var(${Ue}transition) !important;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
:is(:root,:host) [${co}] {
|
|
28
|
-
transition: none;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
:is(:root,:host) [${co}='hidden'] {
|
|
32
|
-
visibility: hidden;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
[${Dt}] * {
|
|
36
|
-
pointer-events: none !important;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
[${Dt}]:not([${Ks}]) {
|
|
40
|
-
translate: var(${Ue}translate) !important;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
[${Dt}][style*='${Ue}scale'] {
|
|
44
|
-
scale: var(${Ue}scale) !important;
|
|
45
|
-
transform-origin: var(${Ue}transform-origin) !important;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@layer dnd-kit {
|
|
49
|
-
:where([${Dt}][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
|
-
[${Dt}]::backdrop, [${fi}overlay]:not([${Dt}]) {
|
|
64
|
-
display: none;
|
|
65
|
-
visibility: hidden;
|
|
66
|
-
}
|
|
67
|
-
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Ax(e,t="hidden"){return le(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Rx(n,r.registry.droppables),o=[],s=Cv(n),{remove:a}=s;return Px(i,s,o),Ix(s,t),s.remove=()=>{o.forEach(d=>d()),a.call(s)},s})}function Rx(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${fi}${Gs("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Px(e,t,n){for(const[r,i]of e){if(!r.element)continue;const o=`[${i}]`,s=t.matches(o)?t:t.querySelector(o);if(r.element.removeAttribute(i),!s)continue;const a=r.element;r.proxy=s,s.removeAttribute(i),Bs.set(a,s),n.push(()=>{Bs.delete(a),r.proxy=void 0})}}function Ix(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(co,t)}function yh(e,t){return e===t?!0:Qn(e)===Qn(t)}function fc(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&vn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>qn(t))}function Ys(e){return e.tagName==="TR"}function Nx(e,t,n){const r=new MutationObserver(i=>{let o=!1;for(const s of i){if(s.target!==e){o=!0;continue}if(s.type!=="attributes")continue;const a=s.attributeName;if(a.startsWith("aria-")||Dx.includes(a))continue;const d=e.getAttribute(a);if(a==="style"){if(Vr(e)&&Vr(t)){const h=e.style;for(const l of Array.from(t.style))h.getPropertyValue(l)===""&&t.style.removeProperty(l);for(const l of Array.from(h)){if(Ox.includes(l)||l.startsWith(Ue))continue;const c=h.getPropertyValue(l);t.style.setProperty(l,c)}}}else d!==null?t.setAttribute(a,d):t.removeAttribute(a)}o&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Wx(e,t,n){const r=new MutationObserver(i=>{for(const o of i)if(o.addedNodes.length!==0)for(const s of Array.from(o.addedNodes)){if(s.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),qn(n);return}if(s.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),qn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),qn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function zx(e){return new ResizeObserver(()=>{var t,n,r;const i=new Tt(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),o=(t=e.transformOrigin)!=null?t:{x:1,y:1},s=(e.width-i.width)*o.x+e.delta.x,a=(e.height-i.height)*o.y+e.delta.y,d=Yu();if(e.styles.set({width:i.width-e.widthOffset,height:i.height-e.heightOffset,top:e.top+a+d.y,left:e.left+s+d.x},Ue),(n=e.getElementMutationObserver())==null||n.takeRecords(),Ys(e.element)&&Ys(e.placeholder)){const x=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(x.map(y=>y.style.width));for(const[y,f]of x.entries()){const v=w[y];f.style.width=`${v.getBoundingClientRect().width}px`}}const h=(r=e.getTranslate())!=null?r:{x:0,y:0},l=e.left+s+d.x+h.x,c=e.top+a+d.y+h.y,u=i.width-e.widthOffset,p=i.height-e.heightOffset,g=e.frameTransform;e.dragOperation.shape=new At(l*g.scaleX+g.x,c*g.scaleY+g.y,u*g.scaleX,p*g.scaleY)})}var Lx=250,Fx="ease";function Bx(e){var t,n,r,i;const{animation:o}=e;if(typeof o=="function"){const f=o({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(f).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:s=Lx,easing:a=Fx}=o??{};qn(e.feedbackElement);const[,d]=(t=Vu(e.feedbackElement,f=>"translate"in f))!=null?t:[];d?.pause();const h=(n=e.placeholder)!=null?n:e.element,l={frameTransform:yh(e.feedbackElement,h)?null:void 0},c=new Tt(e.feedbackElement,l),u=(r=Jr(It(e.feedbackElement).translate))!=null?r:e.translate,p=new Tt(h,l),g=At.delta(c,p,e.alignment),x={x:u.x-g.x,y:u.y-g.y},w=Math.round(c.intrinsicHeight)!==Math.round(p.intrinsicHeight)?{minHeight:[`${c.intrinsicHeight}px`,`${p.intrinsicHeight}px`],maxHeight:[`${c.intrinsicHeight}px`,`${p.intrinsicHeight}px`]}:{},y=Math.round(c.intrinsicWidth)!==Math.round(p.intrinsicWidth)?{minWidth:[`${c.intrinsicWidth}px`,`${p.intrinsicWidth}px`],maxWidth:[`${c.intrinsicWidth}px`,`${p.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Ue),e.feedbackElement.setAttribute(Ks,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),oh({element:e.feedbackElement,keyframes:hl(ti(ti({},w),y),{translate:[`${u.x}px ${u.y}px 0`,`${x.x}px ${x.y}px 0`]}),options:{duration:ll(gt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?s:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Ks),d?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var wh,Xs,ni,ml,Bi,kh,Sh,tr=class extends(Xs=Je,wh=[ce],Xs){constructor(e,t){super(e,t),Ne(this,Bi),Ne(this,ml,He(ni,8,this)),He(ni,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(Eo),r=n?.register(Tx);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(xn(this,Bi,kh).bind(this,n)),this.registerEffect(xn(this,Bi,Sh))}};ni=fr(Xs);ml=new WeakMap;Bi=new WeakSet;kh=function(e){const{overlay:t}=this;if(!t||!e)return;const n=no(t);if(n)return e.addRoot(n)};Sh=function(){var e,t,n,r,i,o,s;const{state:a,manager:d,options:h}=this,{dragOperation:l}=d,{position:c,source:u,status:p}=l;if(p.idle){a.current={},a.initial={};return}if(!u)return;const{element:g}=u,x=u.pluginConfig(tr),w=(t=(e=x?.feedback)!=null?e:h?.feedback)!=null?t:"default",y=typeof w=="function"?w(u,d):w;if(!g||y==="none"||!p.initialized||p.initializing)return;const{initial:f}=a,v=(n=this.overlay)!=null?n:g,b=Jn(v),k=Jn(g),C=!yh(g,v),$=new Tt(g,{frameTransform:C?k:null,ignoreTransforms:!C}),D={x:k.scaleX/b.scaleX,y:k.scaleY/b.scaleY};let{width:j,height:M,top:A,left:N}=$;C&&(j=j/D.x,M=M/D.y);const P=new sx(v),L=It(g),{transition:_,translate:V,boxSizing:T,paddingBlockStart:F,paddingBlockEnd:O,paddingInlineStart:R,paddingInlineEnd:z,borderInlineStartWidth:q,borderInlineEndWidth:U,borderBlockStartWidth:G,borderBlockEndWidth:K}=L,B=_.split(",").filter(xe=>!/^\s*(transform|translate|scale)\b/.test(xe)).join(","),X=Co(L),ee=L.transform,oe=y==="clone",ie=T==="content-box",Oe=ie?parseInt(R)+parseInt(z)+parseInt(q)+parseInt(U):0,We=ie?parseInt(F)+parseInt(O)+parseInt(G)+parseInt(K):0,J=y!=="move"&&!this.overlay?Ax(u,oe?"clone":"hidden"):null,be=le(()=>ei(d.dragOperation.activatorEvent));if(!f.translate){if(this.overlay&&X)f.translate={x:X.x,y:X.y};else if(V!=="none"){const xe=Jr(V);xe&&(f.translate=xe)}}if(!f.transformOrigin){const xe=le(()=>c.current),Ve=N+((r=X?.x)!=null?r:0),dt=A+((i=X?.y)!=null?i:0);f.transformOrigin={x:(xe.x-Ve*b.scaleX-b.x)/(j*b.scaleX),y:(xe.y-dt*b.scaleY-b.y)/(M*b.scaleY)}}const{transformOrigin:ve}=f,se=A*b.scaleY+b.y,Te=N*b.scaleX+b.x;if(!f.coordinates&&(f.coordinates={x:Te,y:se},D.x!==1||D.y!==1)){const{scaleX:xe,scaleY:Ve}=k,{x:dt,y:qt}=ve;f.coordinates.x+=(j*xe-j)*dt,f.coordinates.y+=(M*Ve-M)*qt}f.dimensions||(f.dimensions={width:j,height:M}),f.frameTransform||(f.frameTransform=b);const Ge={x:f.coordinates.x-Te,y:f.coordinates.y-se},Ae={width:(f.dimensions.width*f.frameTransform.scaleX-j*b.scaleX)*ve.x,height:(f.dimensions.height*f.frameTransform.scaleY-M*b.scaleY)*ve.y},Ye={x:Ge.x/b.scaleX+Ae.width,y:Ge.y/b.scaleY+Ae.height},Xe={left:N+Ye.x,top:A+Ye.y};v.setAttribute(Dt,"true");const E=le(()=>l.transform),W=(o=f.translate)!=null?o:{x:0,y:0},Y=E.x*b.scaleX+W.x,Z=E.y*b.scaleY+W.y,fe=Yu();P.set({width:j-Oe,height:M-We,top:Xe.top+fe.y,left:Xe.left+fe.x,translate:`${Y}px ${Z}px 0`,transform:this.overlay?"none":ee,transition:B?`${B}, translate 0ms linear`:"translate 0ms linear",scale:C?`${D.x} ${D.y}`:"","transform-origin":`${ve.x*100}% ${ve.y*100}%`},Ue),J&&(g.insertAdjacentElement("afterend",J),h?.rootElement&&(typeof h.rootElement=="function"?h.rootElement(u):h.rootElement).appendChild(g)),Hs(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),qn(v),v.addEventListener("beforetoggle",fc));let ze,Be,I;const ye=zx({placeholder:J,element:g,feedbackElement:v,frameTransform:b,transformOrigin:ve,width:j,height:M,top:A,left:N,widthOffset:Oe,heightOffset:We,delta:Ye,styles:P,dragOperation:l,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>ze,getSavedCellWidths:()=>I,setSavedCellWidths:xe=>{I=xe}}),et=new Tt(v);le(()=>l.shape=et);const te=gt(v),ae=xe=>{this.manager.actions.stop({event:xe})},Q=ll(te);be&&te.addEventListener("resize",ae),le(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),J&&(ye.observe(J),ze=Nx(g,J,oe),Be=Wx(g,J,v));const he=(s=d.dragOperation.source)==null?void 0:s.id,St=()=>{var xe;if(!be||he==null)return;const Ve=d.registry.draggables.get(he),dt=(xe=Ve?.handle)!=null?xe:Ve?.element;en(dt)&&dt.focus()},vr=()=>{ze?.disconnect(),Be?.disconnect(),ye.disconnect(),te.removeEventListener("resize",ae),Hs(v)&&(v.removeEventListener("beforetoggle",fc),v.removeAttribute("popover")),v.removeAttribute(Dt),P.reset();const xe=()=>{var Ve;if(I&&Ys(g)){const Io=Array.from(g.cells);for(const[xi,$n]of Io.entries())$n.style.width=(Ve=I[xi])!=null?Ve:""}u.status="idle";const dt=a.current.translate!=null,qt=l.status.dragging;J&&(!qt&&dt||J.parentElement!==v.parentElement)&&v.isConnected&&J.replaceWith(v),J?.remove()};v===this.overlay?setTimeout(xe,0):xe()},Ro=h?.dropAnimation,Sn=this,Po=li(()=>{var xe,Ve,dt;const{transform:qt,status:Io}=l;if(!(!qt.x&&!qt.y&&!a.current.translate)&&Io.dragging){const xi=(xe=f.translate)!=null?xe:{x:0,y:0},$n={x:qt.x/b.scaleX+xi.x,y:qt.y/b.scaleY+xi.y},Rl=a.current.translate,qf=le(()=>l.modifiers),No=le(()=>{var xr;return(xr=l.shape)==null?void 0:xr.current}),Wo=h?.keyboardTransition,Pl=be&&!Q&&Wo!==null?`${(Ve=Wo?.duration)!=null?Ve:250}ms ${(dt=Wo?.easing)!=null?dt:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(P.set({transition:B?`${B}, translate ${Pl}`:`translate ${Pl}`,translate:`${$n.x}px ${$n.y}px 0`},Ue),ze?.takeRecords(),No&&No!==et&&Rl&&!qf.length){const xr=xt.delta($n,Rl);l.shape=At.from(No.boundingRectangle).translate(xr.x*b.scaleX,xr.y*b.scaleY)}else l.shape=new Tt(v);a.current.translate=$n}},function(){if(l.status.dropped){this.dispose(),u.status="dropping";const xe=x?.dropAnimation!==void 0?x.dropAnimation:Sn.dropAnimation!==void 0?Sn.dropAnimation:Ro;let Ve=a.current.translate;const dt=Ve!=null;if(!Ve&&g!==v&&(Ve={x:0,y:0}),!Ve||xe===null){vr();return}d.renderer.rendering.then(()=>{Bx({source:u,element:g,feedbackElement:v,placeholder:J,translate:Ve,moved:dt,transition:_,alignment:u.alignment,styles:P,animation:xe??void 0,getElementMutationObserver:()=>ze,cleanup:vr,restoreFocus:St})})}});return()=>{vr(),Po()}};kt(ni,4,"overlay",wh,tr,ml);kn(ni,tr);tr.configure=di(tr);var gl=tr,br=!0,_x=!1,$h,jh,Mh,Ch,Xt,vl,xl;Ch=(Mh=[ce],bt.Forward),jh=($h=[ce],bt.Reverse);var ri=class{constructor(){Ne(this,vl,He(Xt,8,this,br)),He(Xt,11,this),Ne(this,xl,He(Xt,12,this,br)),He(Xt,15,this)}isLocked(e){return e===bt.Idle?!1:e==null?this[bt.Forward]===br&&this[bt.Reverse]===br:this[e]===br}unlock(e){e!==bt.Idle&&(this[e]=_x)}};Xt=fr(null);vl=new WeakMap;xl=new WeakMap;kt(Xt,4,Ch,Mh,ri,vl);kt(Xt,4,jh,$h,ri,xl);kn(Xt,ri);var Hx=[bt.Forward,bt.Reverse],pc=class{constructor(){this.x=new ri,this.y=new ri}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},qx=class extends Je{constructor(e){super(e);const t=rr(new pc);let n=null;this.signal=t,wt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new pc;return}const{delta:i}=e.dragOperation.position;if(n){const o={x:mc(i.x,n.x),y:mc(i.y,n.y)},s=t.peek();Ce(()=>{for(const a of nu)for(const d of Hx)o[a]===d&&s[a].unlock(d);t.value=s})}n=i})}get current(){return this.signal.peek()}};function mc(e,t){return Math.sign(e-t)}var Eh,Zs,ii,bl,Vt,Qs,pi=class extends(Zs=ui,Eh=[ce],Zs){constructor(e){super(e),Ne(this,bl,He(ii,8,this,!1)),He(ii,11,this),Ne(this,Vt),Ne(this,Qs,()=>{if(!ge(this,Vt))return;const{element:o,by:s}=ge(this,Vt);s.y&&(o.scrollTop+=s.y),s.x&&(o.scrollLeft+=s.x)}),this.scroll=(o,s)=>{var a;if(this.disabled)return!1;const d=this.getScrollableElements();if(!d)return it(this,Vt,void 0),!1;const{position:h}=this.manager.dragOperation,l=h?.current;if(l){const{by:c}=o??{},u=c?{x:gc(c.x),y:gc(c.y)}:void 0,p=u?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const g of d){const x=Fv(g,c);if(x.x||x.y){const{speed:w,direction:y}=Zv(g,l,u,s?.acceleration,s?.threshold);if(p)for(const f of nu)p[f].isLocked(y[f])&&(w[f]=0,y[f]=0);if(y.x||y.y){const{x:f,y:v}=c??y,b=f*w.x,k=v*w.y;if(b||k){const C=(a=ge(this,Vt))==null?void 0:a.by;if(this.autoScrolling&&C&&(C.x&&!b||C.y&&!k))continue;return it(this,Vt,{element:g,by:{x:b,y:k}}),oo.schedule(ge(this,Qs)),!0}}}}}return it(this,Vt,void 0),!1};let t=null,n=null;const r=Cs(()=>{const{position:o,source:s}=e.dragOperation;if(!o)return null;const a=Xu(no(s?.element),o.current);return a&&(t=a),a??t}),i=Cs(()=>{const o=r.value,{documentElement:s}=ur(o);if(!o||o===s){const{target:a}=e.dragOperation,d=a?.element;if(d){const h=qs(d,{excludeElement:!1});return n=h,h}}if(o){const a=qs(o,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},$t);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new qx(e),this.destroy=e.monitor.addEventListener("dragmove",o=>{this.disabled||o.defaultPrevented||!ei(e.dragOperation.activatorEvent)||!o.by||this.scroll({by:o.by})&&o.preventDefault()})}};ii=fr(Zs);bl=new WeakMap;Vt=new WeakMap;Qs=new WeakMap;kt(ii,4,"autoScrolling",Eh,pi,bl);kn(ii,pi);function gc(e){return e>0?bt.Forward:e<0?bt.Reverse:bt.Idle}var Gx=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))}},Vx=new Gx(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Ux=10,Js=class extends Je{constructor(e,t){super(e,t);const n=e.registry.plugins.get(pi);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=wt(()=>{var r,i,o;if(this.disabled)return;const{position:s,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}:(o=this.options)==null?void 0:o.threshold};if(n.scroll(void 0,d)){n.autoScrolling=!0;const h=setInterval(()=>Vx.schedule(()=>n.scroll(void 0,d)),Ux);return()=>{clearInterval(h)}}else n.autoScrolling=!1}})}};Js.configure=di(Js);var Dh=Js,vc={capture:!0,passive:!0},Rr,Kx=class extends ui{constructor(e){super(e),Ne(this,Rr),this.handleScroll=()=>{ge(this,Rr)==null&&it(this,Rr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),it(this,Rr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=wt(()=>{var n,r,i;if(t.status.dragging){const o=(i=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?i:document;return o.addEventListener("scroll",this.handleScroll,vc),()=>{o.removeEventListener("scroll",this.handleScroll,vc)}}})}};Rr=new WeakMap;var Yx="* { user-select: none !important; -webkit-user-select: none !important; }",Xx=class extends Je{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Eo),n=t?.register(Yx);if(this.destroy=wt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Ko(),document.addEventListener("selectionchange",Ko,{capture:!0}),()=>{document.removeEventListener("selectionchange",Ko,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Ko(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Pr=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}}),Nn,uo=class extends Xn{constructor(e,t){super(e),this.manager=e,this.options=t,Ne(this,Nn,[]),this.listeners=new Zu,this.handleSourceKeyDown=(n,r,i)=>{if(this.disabled||n.defaultPrevented||!vn(n.target)||r.disabled)return;const{keyboardCodes:o=Pr.keyboardCodes,preventActivation:s=Pr.preventActivation}=i??{};o.start.includes(n.code)&&this.manager.dragOperation.status.idle&&(s?.(n,r)||this.handleStart(n,r,i))}}bind(e,t=this.options){return wt(()=>{var n;const r=(n=e.handle)!=null?n:e.element,i=o=>{ei(o)&&this.handleSourceKeyDown(o,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(),ih(r);const{center:i}=new Tt(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 o=ur(r),s=[this.listeners.bind(o,[{type:"keydown",listener:a=>this.handleKeyDown(a,t,n),options:{capture:!0}}])];ge(this,Nn).push(...s)}handleKeyDown(e,t,n){const{keyboardCodes:r=Pr.keyboardCodes}=n??{};if(Cn(e,[...r.end,...r.cancel])){e.preventDefault();const i=Cn(e,r.cancel);this.handleEnd(e,i);return}Cn(e,r.up)?this.handleMove("up",e):Cn(e,r.down)&&this.handleMove("down",e),Cn(e,r.left)?this.handleMove("left",e):Cn(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,o=t.shiftKey?5:1;let s={x:0,y:0},a=(r=(n=this.options)==null?void 0:n.offset)!=null?r:Pr.offset;if(typeof a=="number"&&(a={x:a,y:a}),!!i){switch(e){case"up":s={x:0,y:-a.y*o};break;case"down":s={x:0,y:a.y*o};break;case"left":s={x:-a.x*o,y:0};break;case"right":s={x:a.x*o,y:0};break}(s.x||s.y)&&(t.preventDefault(),this.manager.actions.move({event:t,by:s}))}}sideEffects(){const e=this.manager.registry.plugins.get(Dh);e?.disabled===!1&&(e.disable(),ge(this,Nn).push(()=>{e.enable()}))}cleanup(){ge(this,Nn).forEach(e=>e()),it(this,Nn,[])}destroy(){this.cleanup(),this.listeners.clear()}};Nn=new WeakMap;uo.configure=di(uo);uo.defaults=Pr;var Oh=uo;function Cn(e,t){return t.includes(e.code)}var dn,Zx=class extends Pu{constructor(){super(...arguments),Ne(this,dn)}onEvent(e){switch(e.type){case"pointerdown":it(this,dn,Zn(e));break;case"pointermove":if(!ge(this,dn))return;const{x:t,y:n}=Zn(e),r={x:t-ge(this,dn).x,y:n-ge(this,dn).y},{tolerance:i}=this.options;if(i&&Ns(r,i)){this.abort();return}Ns(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){it(this,dn,void 0)}};dn=new WeakMap;var Wn,un,Qx=class extends Pu{constructor(){super(...arguments),Ne(this,Wn),Ne(this,un)}onEvent(e){switch(e.type){case"pointerdown":it(this,un,Zn(e)),it(this,Wn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ge(this,un))return;const{x:t,y:n}=Zn(e),r={x:t-ge(this,un).x,y:n-ge(this,un).y};Ns(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ge(this,Wn)&&(clearTimeout(ge(this,Wn)),it(this,un,void 0),it(this,Wn,void 0))}};Wn=new WeakMap;un=new WeakMap;var Bn=class{};Bn.Delay=Qx;Bn.Distance=Zx;var ea=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&vn(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new Bn.Delay({value:250,tolerance:5})]:lx(i)&&!e.defaultPrevented?[new Bn.Delay({value:200,tolerance:0})]:[new Bn.Delay({value:200,tolerance:10}),new Bn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!vn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=Dv(r);return i===t.element?!1:!!i}}),zn,ho=class extends Xn{constructor(e,t){super(e),this.manager=e,this.options=t,Ne(this,zn,new Set),this.listeners=new Zu,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=ea.activationConstraints}=n??{};return typeof r=="function"?r(e,t):r}bind(e,t=this.options){return wt(()=>{var n;const r=new AbortController,{signal:i}=r,o=a=>{ax(a)&&this.handlePointerDown(a,e,t)};let s=[(n=e.handle)!=null?n:e.element];t?.activatorElements&&(Array.isArray(t.activatorElements)?s=t.activatorElements:s=t.activatorElements(e));for(const a of s)a&&(tb(a.ownerDocument.defaultView),a.addEventListener("pointerdown",o,{signal:i}));return()=>r.abort()})}handlePointerDown(e,t,n){if(this.disabled||!e.isPrimary||e.button!==0||!vn(e.target)||t.disabled||Jx(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=ea.preventActivation}=n??{};if(r?.(e,t))return;const{target:i}=e,o=en(i)&&i.draggable&&i.getAttribute("draggable")==="true",s=Jn(t.element),{x:a,y:d}=Zn(e);this.initialCoordinates={x:a*s.scaleX+s.x,y:d*s.scaleY+s.y};const h=this.activationConstraints(e,t,n);e.sensor=this;const l=new yv(h,g=>this.handleStart(t,g));l.signal.onabort=()=>this.handleCancel(e),l.onEvent(e),this.controller=l;const c=Fs(),u=this.listeners.bind(c,[{type:"pointermove",listener:g=>this.handlePointerMove(g,t)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:$i,options:{capture:!0}}]),p=()=>{u(),this.initialCoordinates=void 0};ge(this,zn).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=Zn(e),o=Jn(t.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,e.preventDefault(),e.stopPropagation(),this.latest.event=e,this.latest.coordinates=i,oo.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=ur(t.target).body;try{i.setPointerCapture(t.pointerId)}catch{this.handleCancel(t);return}const o=vn(t.target)?[t.target,i]:i,s=this.listeners.bind(o,[{type:"touchmove",listener:$i,options:{passive:!1}},{type:"click",listener:$i},{type:"contextmenu",listener:$i},{type:"keydown",listener:this.handleKeyDown}]);ge(this,zn).add(s)}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,zn).forEach(t=>t()),ge(this,zn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};zn=new WeakMap;ho.configure=di(ho);ho.defaults=ea;var ta=ho;function Jx(e){return"sensor"in e}function $i(e){e.preventDefault()}function eb(){}var xc=new WeakSet;function tb(e){!e||xc.has(e)||(e.addEventListener("touchmove",eb,{capture:!1,passive:!1}),xc.add(e))}var Gn={modifiers:[],plugins:[Mx,Dh,Ex,gl,Xx],sensors:[ta,Oh]},Th=class extends Sv{constructor(e={}){const t=Ct(e.plugins,Gn.plugins),n=Ct(e.sensors,Gn.sensors),r=Ct(e.modifiers,Gn.modifiers);super(hl(ti({},e),{plugins:[Kx,pi,Eo,...t],sensors:n,modifiers:r}))}},Ah,Rh,na,Zt,yl,wl,Do=class extends(na=Rt,Rh=[ce],Ah=[ce],na){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:o}=n,s=dh(n,["element","effects","handle"]);super(ti({effects:()=>[...i(),()=>{var a,d;const{manager:h}=this;if(!h)return;const l=((d=(a=this.sensors)==null?void 0:a.map(Xr))!=null?d:[...h.sensors]).map(c=>{const u=c instanceof Xn?c:h.registry.register(c.plugin),p=c instanceof Xn?void 0:c.options;return u.bind(this,p)});return function(){l.forEach(c=>c())}}]},s),t),Ne(this,yl,He(Zt,8,this)),He(Zt,11,this),Ne(this,wl,He(Zt,12,this)),He(Zt,15,this),this.element=r,this.handle=o}};Zt=fr(na);yl=new WeakMap;wl=new WeakMap;kt(Zt,4,"handle",Rh,Do,yl);kt(Zt,4,"element",Ah,Do,wl);kn(Zt,Do);var Ph,Ih,ra,Qt,kl,Yo,Nh,Wh,Kr,Sl,Oo=class extends(ra=Pt,Ih=[ce],Ph=[ce],ra){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,o=dh(n,["element","effects"]);const{collisionDetector:s=sh}=o,a=h=>{const{manager:l,element:c}=this;if(!c||h===null){this.shape=void 0;return}if(!l)return;const u=new Tt(c),p=le(()=>this.shape);return u&&p?.equals(u)?p:(this.shape=u,u)},d=rr(!1);super(hl(ti({},o),{collisionDetector:s,effects:()=>[...i(),()=>{const{element:h,manager:l}=this;if(!l)return;const{dragOperation:c}=l,{source:u}=c;d.value=!!(u&&c.status.initialized&&h&&!this.disabled&&this.accepts(u))},()=>{const{element:h}=this;if(d.value&&h){const l=new Lv(h,a);return()=>{l.disconnect(),this.shape=void 0}}},()=>{var h;if((h=this.manager)!=null&&h.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Ne(this,Kr),Ne(this,kl,He(Qt,8,this)),He(Qt,11,this),Ne(this,Sl,He(Qt,12,this)),He(Qt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){it(this,Kr,e,Wh)}get element(){var e;return(e=this.proxy)!=null?e:ge(this,Kr,Nh)}};Qt=fr(ra);kl=new WeakMap;Kr=new WeakSet;Sl=new WeakMap;Yo=kt(Qt,20,"#element",Ih,Kr,kl),Nh=Yo.get,Wh=Yo.set;kt(Qt,4,"proxy",Ph,Oo,Sl);kn(Qt,Oo);function nb(e){return e!=null&&typeof e=="object"&&"current"in e}function Vn(e){var t;if(e!=null)return nb(e)?(t=e.current)!=null?t:void 0:e}var rb=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",pr=rb?S.useLayoutEffect:S.useEffect;function ib(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function zh(e,t){const n=S.useRef(new Map),r=ib();return pr(()=>{if(!e){n.current.clear();return}return wt(()=>{var i;let o=!1,s=!1;for(const a of n.current){const[d]=a,h=le(()=>a[1]),l=e[d];h!==l&&(o=!0,n.current.set(d,l),s=(i=t?.(d,h,l))!=null?i:!1)}o&&(s?queueMicrotask(()=>Nm.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(i,o){const s=i[o];return n.current.set(o,s),s}}),[e])}function ob(e,t){e()}function En(e){const t=S.useRef(e);return pr(()=>{t.current=e},[e]),t}function je(e,t,n=S.useEffect,r=Object.is){const i=S.useRef(e);n(()=>{const o=i.current;r(e,o)||(i.current=e,t(e,o))},[t,e])}function _i(e,t){const n=S.useRef(Vn(e));pr(()=>{const r=Vn(e);r!==n.current&&(n.current=r,t(r))})}var sb=Object.defineProperty,ab=Object.defineProperties,lb=Object.getOwnPropertyDescriptors,fo=Object.getOwnPropertySymbols,Lh=Object.prototype.hasOwnProperty,Fh=Object.prototype.propertyIsEnumerable,bc=(e,t,n)=>t in e?sb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,cb=(e,t)=>{for(var n in t||(t={}))Lh.call(t,n)&&bc(e,n,t[n]);if(fo)for(var n of fo(t))Fh.call(t,n)&&bc(e,n,t[n]);return e},db=(e,t)=>ab(e,lb(t)),ub=(e,t)=>{var n={};for(var r in e)Lh.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&fo)for(var r of fo(e))t.indexOf(r)<0&&Fh.call(e,r)&&(n[r]=e[r]);return n},hb=new Th,Bh=S.createContext(hb),fb=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),i=S.useRef(null),o=S.useRef(null),s=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=i.current)!=null?a:Promise.resolve()}},trackRendering(a){i.current||(i.current=new Promise(d=>{o.current=d})),S.startTransition(()=>{a(),r(d=>d+1)})}}),[]);return pr(()=>{var a;(a=o.current)==null||a.call(o),i.current=null},[e,n]),S.useImperativeHandle(t,()=>s),null})),Xo=[void 0,$t];function pb(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:o,onDragMove:s,onDragOver:a,onDragEnd:d}=t,h=ub(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const l=S.useRef(null),{plugins:c,modifiers:u,sensors:p}=h,g=Ct(c,Gn.plugins),x=Ct(p,Gn.sensors),w=Ct(u,Gn.modifiers),y=En(i),f=En(o),v=En(a),b=En(s),k=En(d),C=En(r),$=mb(()=>{var D;return(D=h.manager)!=null?D:new Th(h)});return S.useEffect(()=>{if(!l.current)throw new Error("Renderer not found");const{renderer:D,trackRendering:j}=l.current,{monitor:M}=$;$.renderer=D;const A=[M.addEventListener("beforedragstart",N=>{const P=y.current;P&&j(()=>P(N,$))}),M.addEventListener("dragstart",N=>{var P;return(P=f.current)==null?void 0:P.call(f,N,$)}),M.addEventListener("dragover",N=>{const P=v.current;P&&j(()=>P(N,$))}),M.addEventListener("dragmove",N=>{const P=b.current;P&&j(()=>P(N,$))}),M.addEventListener("dragend",N=>{const P=k.current;P&&j(()=>P(N,$))}),M.addEventListener("collision",N=>{var P;return(P=C.current)==null?void 0:P.call(C,N,$)})];return()=>A.forEach(N=>N())},[$]),je(g,()=>$&&($.plugins=g),...Xo),je(x,()=>$&&($.sensors=x),...Xo),je(w,()=>$&&($.modifiers=w),...Xo),m.jsxs(Bh.Provider,{value:$,children:[m.jsx(fb,{ref:l,children:n}),n]})}function mb(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 gb(){return S.useContext(Bh)}function _h(e){var t;const n=(t=gb())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),pr(r.register,[n,r]),r}var vb=Object.create,Hh=Object.defineProperty,xb=Object.getOwnPropertyDescriptor,qh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),To=e=>{throw TypeError(e)},bb=(e,t,n)=>t in e?Hh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yb=e=>{var t;return[,,,vb((t=e?.[qh("metadata")])!=null?t:null)]},Gh=["class","method","getter","setter","accessor","field","value","get","set"],Vh=e=>e!==void 0&&typeof e!="function"?To("Function expected"):e,wb=(e,t,n,r,i)=>({kind:Gh[e],name:t,metadata:r,addInitializer:o=>n._?To("Already initialized"):i.push(Vh(o||null))}),kb=(e,t)=>bb(t,qh("metadata"),e[3]),Sb=(e,t,n,r)=>{for(var i=0,o=e[t>>1],s=o&&o.length;i<s;i++)o[i].call(n);return r},Uh=(e,t,n,r,i,o)=>{for(var s,a,d,h,l=t&7,c=!1,u=!1,p=2,g=Gh[l+5],x=e[p]||(e[p]=[]),w=(i=i.prototype,xb(i,n)),y=r.length-1;y>=0;y--)d=wb(l,n,a={},e[3],x),d.static=c,d.private=u,h=d.access={has:f=>n in f},h.get=f=>f[n],s=(0,r[y])(w[g],d),a._=1,Vh(s)&&(w[g]=s);return w&&Hh(i,n,w),i},Kh=(e,t,n)=>t.has(e)||To("Cannot "+n),$b=(e,t,n)=>(Kh(e,t,"read from private field"),t.get(e)),jb=(e,t,n)=>t.has(e)?To("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Mb=(e,t,n,r)=>(Kh(e,t,"write to private field"),t.set(e,n),n),pn=class ia{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ia(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 ia(t,n)}},Yh,Xh,oa,Hi,mi,$l=class extends(oa=yn,Xh=[Pe],Yh=[Pe],oa){constructor(e){const t=pn.from(e);super(t,(n,r)=>pn.equals(n,r)),Sb(mi,5,this),jb(this,Hi,0),this.velocity={x:0,y:0}}get delta(){return pn.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=pn.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),o=i-$b(this,Hi),s=a=>Math.round(a/o*100);Ce(()=>{Mb(this,Hi,i),this.velocity={x:s(r.x),y:s(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(pn.from(e)),this.velocity={x:0,y:0}}};mi=yb(oa);Hi=new WeakMap;Uh(mi,2,"delta",Xh,$l);Uh(mi,2,"direction",Yh,$l);kb(mi,$l);var Zh=(e=>(e.Horizontal="x",e.Vertical="y",e))(Zh||{});Object.values(Zh);var Cb=({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=pn.distance(t.shape.center,n);return{id:r,value:1/i,type:dr.PointerIntersection,priority:cr.High}}return null},Eb=({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,o=pn.distance(t.shape.center,i.current),s=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:s,type:dr.ShapeIntersection,priority:cr.Normal}}return null},Db=e=>{var t;return(t=Cb(e))!=null?t:Eb(e)};function Ob(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:o,accept:s,type:a}=e,d=_h(l=>new Oo(db(cb({},e),{register:!1,element:Vn(i)}),l)),h=zh(d);return je(o,()=>d.id=o),_i(i,l=>d.element=l),je(s,()=>d.accept=s,void 0,$t),je(t,()=>d.collisionDetector=t??Db),je(n,()=>n&&(d.data=n)),je(r,()=>d.disabled=r===!0),je(a,()=>d.type=a),{droppable:h,get isDropTarget(){return h.isDropTarget},ref:S.useCallback(l=>{var c,u;!l&&(c=d.element)!=null&&c.isConnected&&!((u=d.manager)!=null&&u.dragOperation.status.idle)||(d.element=l??void 0)},[d])}}const Qh=(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 ${Fe}`,...Wt,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},Jh=S.createContext(void 0);function ef(e,t){const n=S.useContext(Jh),r=S.useRef(t);r.current=t,S.useEffect(()=>{if(!n||!e)return;const o=()=>r.current();return n.commitRef.current=o,()=>{n.commitRef.current===o&&(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 sa({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:i=!1}){const{theme:o}=qe(),[s,a]=S.useState(void 0),d=S.useRef(!1),h=()=>{d.current||s===void 0||(a(void 0),s!==e&&r(s))};ef(s!==void 0&&s!==e,()=>(h(),!0));const l=()=>{d.current=!1,a(e)};if(s===void 0){const c=e==="",u=c&&i;return m.jsx(H,{component:"button",type:"button",className:u?"builder-affordance":void 0,onClick:l,onKeyDown:p=>{p.key!=="Enter"&&p.key!==" "||(p.preventDefault(),l())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...c&&{fontStyle:"italic",opacity:u?0:.6}},Qh(o)],children:c?t:e})}return m.jsx(bd,{autoFocus:!0,fullWidth:!0,value:s,placeholder:t,inputProps:{"aria-label":n},onFocus:c=>c.target.select(),onChange:c=>a(c.target.value),onKeyDown:c=>{c.key==="Enter"&&!c.nativeEvent.isComposing?h():c.key==="Escape"&&(d.current=!0,a(void 0))},onBlur:h,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Tb=(e,t)=>e.map((n,r)=>{const i=t[r]??!1;if(i===(n.break??!1))return n;const o={...n};return i?o.break=!0:delete o.break,o}),Ab=(e,t,n)=>{const r=[...e],[i]=r.splice(t,1);if(!i)return[...e];const o=r[t];i.break&&o&&!o.break&&(r[t]={...o,break:!0});const s={...i};return delete s.break,r.splice(n,0,s),r},tf=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),nf=e=>`gap.${e}`,Rb=(e,t)=>{const n=[];let r=0;e.forEach((o,s)=>{const a=Math.min(o.colspan??1,t),d=s===0||o.break===!0||r+a>t;d&&s>0&&r<t&&n.push({kind:"gap",after:ke(e[s-1]),colspan:t-r}),d&&(r=0),n.push(tf(o,s)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:ke(i),colspan:t-r}),n};var Pb=Object.create,rf=Object.defineProperty,Ib=Object.defineProperties,Nb=Object.getOwnPropertyDescriptor,Wb=Object.getOwnPropertyDescriptors,po=Object.getOwnPropertySymbols,of=Object.prototype.hasOwnProperty,sf=Object.prototype.propertyIsEnumerable,zb=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),gi=e=>{throw TypeError(e)},aa=(e,t,n)=>t in e?rf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Zo=(e,t)=>{for(var n in t||(t={}))of.call(t,n)&&aa(e,n,t[n]);if(po)for(var n of po(t))sf.call(t,n)&&aa(e,n,t[n]);return e},Qo=(e,t)=>Ib(e,Wb(t)),Lb=(e,t)=>{var n={};for(var r in e)of.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&po)for(var r of po(e))t.indexOf(r)<0&&sf.call(e,r)&&(n[r]=e[r]);return n},Fb=e=>{var t;return[,,,Pb((t=void 0)!=null?t:null)]},af=["class","method","getter","setter","accessor","field","value","get","set"],Ir=e=>e!==void 0&&typeof e!="function"?gi("Function expected"):e,Bb=(e,t,n,r,i)=>({kind:af[e],name:t,metadata:r,addInitializer:o=>n._?gi("Already initialized"):i.push(Ir(o||null))}),_b=(e,t)=>aa(t,zb("metadata"),e[3]),ji=(e,t,n,r)=>{for(var i=0,o=e[t>>1],s=o&&o.length;i<s;i++)t&1?o[i].call(n):r=o[i].call(n,r);return r},lf=(e,t,n,r,i,o)=>{for(var s,a,d,h,l,c=t&7,u=!1,p=!1,g=e.length+1,x=af[c+5],w=e[g-1]=[],y=e[g]||(e[g]=[]),f=(i=i.prototype,Nb({get[n](){return Nr(this,o)},set[n](b){return hn(this,o,b)}},n)),v=r.length-1;v>=0;v--)h=Bb(c,n,d={},e[3],y),h.static=u,h.private=p,l=h.access={has:b=>n in b},l.get=b=>b[n],l.set=(b,k)=>b[n]=k,a=(0,r[v])({get:f.get,set:f.set},h),d._=1,a===void 0?Ir(a)&&(f[x]=a):typeof a!="object"||a===null?gi("Object expected"):(Ir(s=a.get)&&(f.get=s),Ir(s=a.set)&&(f.set=s),Ir(s=a.init)&&w.unshift(s));return f&&rf(i,n,f),i},cf=(e,t,n)=>t.has(e)||gi("Cannot "+n),Nr=(e,t,n)=>(cf(e,t,"read from private field"),t.get(e)),yr=(e,t,n)=>t.has(e)?gi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),hn=(e,t,n,r)=>(cf(e,t,"write to private field"),t.set(e,n),n);function mn(e){return e instanceof Cl||e instanceof ff}var Mi=10,Hb=class extends Je{constructor(e){super(e);const t=wt(()=>{const{dragOperation:r}=e;if(ei(r.activatorEvent)&&mn(r.source)&&r.status.initialized){const i=e.registry.plugins.get(pi);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:o}=i;if(!ei(r.nativeEvent)||!mn(o.source)||!o.shape)return;const{actions:s,collisionObserver:a,registry:d}=i,{by:h}=r;if(!h)return;const l=qb(h),{source:c,target:u}=o,{center:p}=o.shape.current,g=[],x=[];Ce(()=>{for(const k of d.droppables){const{id:C}=k;if(!k.accepts(c)||C===u?.id&&mn(k)||!k.element)continue;let $=k.shape;const D=new Tt(k.element,{getBoundingClientRect:j=>Qr(j,void 0,.2)});!D.height||!D.width||(l=="down"&&p.y+Mi<D.center.y||l=="up"&&p.y-Mi>D.center.y||l=="left"&&p.x-Mi>D.center.x||l=="right"&&p.x+Mi<D.center.x)&&(g.push(k),k.shape=D,x.push(()=>k.shape=$))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(g,ux);Ce(()=>x.forEach(k=>k()));const[y]=w;if(!y)return;const{id:f}=y,{index:v,group:b}=c.sortable;s.setDropTarget(f).then(()=>{const{source:k,target:C,shape:$}=o;if(!k||!mn(k)||!$)return;const{index:D,group:j,target:M}=k.sortable,A=v!==D||b!==j,N=A?M:C?.element;if(!N)return;ih(N);const P=new Tt(N);if(!P)return;const L=At.delta(P,At.from($.current.boundingRectangle),k.alignment);s.move({by:L}),A?s.setDropTarget(k.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function qb(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 Gb=Object.defineProperty,Vb=Object.defineProperties,Ub=Object.getOwnPropertyDescriptors,yc=Object.getOwnPropertySymbols,Kb=Object.prototype.hasOwnProperty,Yb=Object.prototype.propertyIsEnumerable,wc=(e,t,n)=>t in e?Gb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dn=(e,t)=>{for(var n in t||(t={}))Kb.call(t,n)&&wc(e,n,t[n]);if(yc)for(var n of yc(t))Yb.call(t,n)&&wc(e,n,t[n]);return e},On=(e,t)=>Vb(e,Ub(t));function Xb(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Ci(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Jo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Zb(e,t,n){var r,i;const{source:o,target:s,canceled:a}=t.operation;if(!o||!s||a)return"preventDefault"in t&&t.preventDefault(),e;const d=(f,v)=>f===v||f!==null&&typeof f=="object"&&"id"in f&&f.id===v;if(Array.isArray(e)){const f=e.findIndex(b=>d(b,o.id)),v=e.findIndex(b=>d(b,s.id));if(f===-1||v===-1){if(Jo(o)){const b=o.initialIndex,k=o.index;return b===k||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,k)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==f)return n(e,f,b)}return n(e,f,v)}const h=Object.entries(e);let l=-1,c,u=-1,p;for(const[f,v]of h)if(l===-1&&(l=v.findIndex(b=>d(b,o.id)),l!==-1&&(c=f)),u===-1&&(u=v.findIndex(b=>d(b,s.id)),u!==-1&&(p=f)),l!==-1&&u!==-1)break;if(l===-1&&Jo(o)){const f=o.initialGroup==null?void 0:Ci(e,o.initialGroup),v=o.initialIndex,b=o.group==null?void 0:Ci(e,o.group),k=o.index;if(f==null||b==null||f===b&&v===k)return"preventDefault"in t&&t.preventDefault(),e;if(f===b)return On(Dn({},e),{[f]:n(e[f],v,k)});const C=e[f][v];return On(Dn({},e),{[f]:[...e[f].slice(0,v),...e[f].slice(v+1)],[b]:[...e[b].slice(0,k),C,...e[b].slice(k)]})}if(!o.manager)return e;const{dragOperation:g}=o.manager,x=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(p==null){const f=Ci(e,s.id);if(f!=null){const v=s.shape&&x.y>s.shape.center.y?e[f].length:0;p=f,u=v}}if(c==null||p==null||c===p&&l===u){if(c!=null&&c===p&&l===u&&Jo(o)){const f=o.group==null?void 0:Ci(e,o.group),v=o.group!=null&&f!==c,b=o.index!==l;if(v||b){const k=o.group==null?c:f;if(k!=null){if(c===k)return On(Dn({},e),{[c]:n(e[c],l,o.index)});const C=e[c][l];return On(Dn({},e),{[c]:[...e[c].slice(0,l),...e[c].slice(l+1)],[k]:[...e[k].slice(0,o.index),C,...e[k].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===p)return On(Dn({},e),{[c]:n(e[c],l,u)});const w=s.shape&&Math.round(x.y)>Math.round(s.shape.center.y)?1:0,y=e[c][l];return On(Dn({},e),{[c]:[...e[c].slice(0,l),...e[c].slice(l+1)],[p]:[...e[p].slice(0,u+w),y,...e[p].slice(u+w)]})}function Qb(e,t){return Zb(e,t,Xb)}function kc(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Sc(e,t,n){var r;for(const[i,o]of t)for(const s of o){const a=e.get(s.id);if(s.index!==a||s.group!==i||!((r=n.get(i))!=null&&r.has(s)))return!0}return!1}var $c="__default__",Jb=class extends Je{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof Cl){const{sortable:o}=i,{group:s}=o;let a=r.get(s);a||(a=new Set,r.set(s,a)),a.add(o)}return r},n=[e.monitor.addEventListener("dragover",(r,i)=>{if(this.disabled)return;const{dragOperation:o}=i,{source:s,target:a}=o;if(!mn(s)||!mn(a)||s.sortable===a.sortable)return;const d=t(),h=kc(d),l=s.sortable.group===a.sortable.group,c=d.get(s.sortable.group),u=l?c:d.get(a.sortable.group);!c||!u||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var p,g;const x=t();if(Sc(h,d,x))return;const w=s.sortable.element,y=a.sortable.element;if(!y||!w||!l&&a.id===s.sortable.group)return;const f=Ei(c),v=l?f:Ei(u),b=(p=s.sortable.group)!=null?p:$c,k=(g=a.sortable.group)!=null?g:$c,C={[b]:f,[k]:v},$=Qb(C,r);if(C===$)return;const D=$[k].indexOf(s.sortable),j=$[k].indexOf(a.sortable);i.collisionObserver.disable(),jc(w,D,y,j),Ce(()=>{for(const[M,A]of $[b].entries())A.index=M;if(!l)for(const[M,A]of $[k].entries())A.group=a.sortable.group,A.index=M}),i.actions.setDropTarget(s.id).then(()=>i.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,i)=>{if(!r.canceled)return;const{dragOperation:o}=i,{source:s}=o;mn(s)&&(s.sortable.initialIndex===s.sortable.index&&s.sortable.initialGroup===s.sortable.group||queueMicrotask(()=>{const a=t(),d=kc(a),h=a.get(s.sortable.initialGroup);h&&i.renderer.rendering.then(()=>{const l=t();if(Sc(d,a,l))return;const c=Ei(h),u=Ei(h,ty),p=s.sortable.element,g=u.indexOf(s.sortable),x=c[g],w=x?.element;!x||!w||!p||(jc(p,x.index,w,s.index),Ce(()=>{for(const y of a.values()){const f=Array.from(y).values();for(const v of f)v.index=v.initialIndex,v.group=v.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function jc(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function ey(e,t){return e.index-t.index}function ty(e,t){return e.initialIndex-t.initialIndex}function Ei(e,t=ey){return Array.from(e).sort(t)}var Mc=[Hb,Jb],df={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Cc(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var Di=new Kg,uf,hf,Jt,jl,Wr,zr,Ml,Ln;hf=[ce],uf=[ce];var Ao=class{constructor(e,t){yr(this,jl,ji(Jt,8,this)),ji(Jt,11,this),yr(this,Wr),yr(this,zr),yr(this,Ml,ji(Jt,12,this)),ji(Jt,15,this),yr(this,Ln),this.register=()=>(Ce(()=>{var g,x;(g=this.manager)==null||g.registry.register(this.droppable),(x=this.manager)==null||x.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ce(()=>{var g,x;(g=this.manager)==null||g.registry.unregister(this.droppable),(x=this.manager)==null||x.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:o,index:s,sensors:a,type:d,transition:h=df,plugins:l}=n,c=Lb(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=Ct(l,Mc),p=Cc(i);this.droppable=new Cl(Qo(Zo({},c),{disabled:p.droppable}),t,this),this.draggable=new ff(Qo(Zo({},c),{disabled:p.draggable,plugins:u,effects:()=>[()=>{var g,x,w;const y=(g=this.manager)==null?void 0:g.dragOperation.status;y?.initializing&&this.id===((w=(x=this.manager)==null?void 0:x.dragOperation.source)==null?void 0:w.id)&&Di.clear(this.manager),y?.dragging&&Di.set(this.manager,this.id,le(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:x,manager:w}=this,y=Nr(this,zr),f=Nr(this,Wr);(g!==y||x!==f)&&(hn(this,zr,g),hn(this,Wr,x),this.animate())},()=>{var g,x;const{target:w}=this,{isDragSource:y}=this.draggable;((x=(g=this.draggable.pluginConfig(gl))==null?void 0:g.feedback)!=null?x:"default")==="move"&&y&&(this.droppable.disabled=!w)},...r()],type:d,sensors:a}),t,this),hn(this,Ln,c.element),this.manager=t,this.index=s,hn(this,zr,s),this.group=o,hn(this,Wr,o),this.type=d,this.transition=h}get initialIndex(){var e,t;return(t=(e=Di.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Di.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){le(()=>{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 l of i.getAnimations())"transitionProperty"in l&&(l.transitionProperty==="transform"||l.transitionProperty==="translate"||l.transitionProperty==="scale")&&l.cancel();const o=this.refreshShape();if(!o)return;const s={x:n.boundingRectangle.left-o.boundingRectangle.left,y:n.boundingRectangle.top-o.boundingRectangle.top},{translate:a}=It(i),d=dc(i,a,!1),h=dc(i,a);if(s.x||s.y){const l=ll(gt(i))?Qo(Zo({},t),{duration:0}):t;oh({element:i,keyframes:{translate:[`${d.x+s.x}px ${d.y+s.y}px ${d.z}`,`${h.x}px ${h.y}px ${h.z}`]},options:l}).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=Nr(this,Ln),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),hn(this,Ln,e)})}get element(){var e,t;const n=Nr(this,Ln);if(n)return(t=(e=Bs.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=Ct(e,Mc)}set disabled(e){const t=Cc(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??sh}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)}};Jt=Fb();jl=new WeakMap;Wr=new WeakMap;zr=new WeakMap;Ml=new WeakMap;Ln=new WeakMap;lf(Jt,4,"index",hf,Ao,jl);lf(Jt,4,"group",uf,Ao,Ml);_b(Jt,Ao);var ff=class extends Do{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}},Cl=class extends Oo{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},ny=Object.defineProperty,ry=Object.defineProperties,iy=Object.getOwnPropertyDescriptors,Ec=Object.getOwnPropertySymbols,oy=Object.prototype.hasOwnProperty,sy=Object.prototype.propertyIsEnumerable,Dc=(e,t,n)=>t in e?ny(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,es=(e,t)=>{for(var n in t||(t={}))oy.call(t,n)&&Dc(e,n,t[n]);if(Ec)for(var n of Ec(t))sy.call(t,n)&&Dc(e,n,t[n]);return e},ay=(e,t)=>ry(e,iy(t));function ly(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:i,data:o,element:s,handle:a,index:d,group:h,disabled:l,modifiers:c,sensors:u,target:p,type:g,plugins:x}=e,w=es(es({},df),e.transition),y=_h(v=>new Ao(ay(es({},e),{transition:w,register:!1,handle:Vn(a),element:Vn(s),target:Vn(p)}),v)),f=zh(y,cy);return je(i,()=>y.id=i),pr(()=>{Ce(()=>{y.group=h,y.index=d})},[y,h,d]),je(g,()=>y.type=g),je(t,()=>y.accept=t,void 0,$t),je(o,()=>o&&(y.data=o)),je(d,()=>{var v;(v=y.manager)!=null&&v.dragOperation.status.idle&&w?.idle&&y.refreshShape()},ob),_i(a,v=>y.handle=v),_i(s,v=>y.element=v),_i(p,v=>y.target=v),je(l,()=>y.disabled=l??!1,void 0,$t),je(u,()=>y.sensors=u,void 0,$t),je(n,()=>y.collisionDetector=n),je(r,()=>y.collisionPriority=r),je(x,()=>y.plugins=x,void 0,$t),je(w,()=>y.transition=w,void 0,$t),je(c,()=>y.modifiers=c,void 0,$t),je(e.alignment,()=>y.alignment=e.alignment),{sortable:f,get isDragging(){return f.isDragging},get isDropping(){return f.isDropping},get isDragSource(){return f.isDragSource},get isDropTarget(){return f.isDropTarget},handleRef:S.useCallback(v=>{y.handle=v??void 0},[y]),ref:S.useCallback(v=>{var b,k;!v&&(b=y.element)!=null&&b.isConnected&&!((k=y.manager)!=null&&k.dragOperation.status.idle)||(y.element=v??void 0)},[y]),sourceRef:S.useCallback(v=>{var b,k;!v&&(b=y.source)!=null&&b.isConnected&&!((k=y.manager)!=null&&k.dragOperation.status.idle)||(y.source=v??void 0)},[y]),targetRef:S.useCallback(v=>{var b,k;!v&&(b=y.target)!=null&&b.isConnected&&!((k=y.manager)!=null&&k.dragOperation.status.idle)||(y.target=v??void 0)},[y])}}function cy(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const la="tile",pf="gap",dy=[ta.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${El}], ${uy}`)!==null||(ta.defaults.preventActivation?.(e,t)??!1)}),Oh],El="data-no-drag",uy=".malloy-render, .malloy-table",hy=e=>[...e,gl.configure({feedback:"clone"})];function fy({id:e,index:t,disabled:n=!1,children:r}){const{ref:i,handleRef:o,isDragSource:s}=ly({id:e,index:t,disabled:n,type:la,accept:la,collisionDetector:dl,plugins:hy});return m.jsx(m.Fragment,{children:r({ref:i,handleRef:o,isDragSource:s})})}function py({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=Ob({id:e,type:pf,accept:la,collisionDetector:dl,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:i})})}const mf=e=>e.ok===!1,Le=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),mr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,$e={sourceDefinition:e=>Le(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Le(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Le(e,"VIEW","subQueryDefList"),defDimension:e=>Le(e,"defList","DIMENSION"),exploreProperties:e=>Le(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Le(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Le(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Le(e,"WHERE","filterClauseList"),givenDef:e=>Le(e,"givenNameDef"),givenStatement:e=>Le(e,"GIVEN","givenDefList"),importStatement:e=>Le(e,"IMPORT","importURL"),vArrow:e=>Le(e,"ARROW","vExpr","segExpr"),segRefine:e=>Le(e,"PLUS","segExpr"),segOps:e=>Le(e,"queryProperties"),segField:e=>Le(e,"fieldPath")&&!Le(e,"segExpr"),segParen:e=>Le(e,"OPAREN","CPAREN","vExpr"),compare:e=>Le(e,"fieldExpr","compareOp"),givenRef:e=>Le(e,"GIVEN_REF")};function my(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 gy(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
-
`&&t.push(n+1);return t}function gf(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const i=t.getChild(r);if(!mr(i))continue;const o=Ie(i,"docAnnotations");if(o)for(const s of nn(o,"docAnnotation")){const a=e.text_(s);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class vf{constructor(t){this.text=t,this.map=my(t),this.lineStarts=gy(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!mr(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const i=this.map[n.startIndex],o=this.map[r.stopIndex+1];if(!(i===void 0||o===void 0||o<i))return{start:i,end:o}}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 vi(e,t,n=[]){mr(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)vi(e.getChild(r),t,n);return n}const vy=e=>Le(e,"OCURLY","CCURLY");function oi(e,t){const n=[],r=i=>{if(mr(i)){if(t(i)){n.push(i);return}if(!vy(i))for(let o=0;o<(i.childCount??0);o++)r(i.getChild(o))}};for(let i=0;i<(e.childCount??0);i++)r(e.getChild(i));return n}const Ie=(e,t)=>e[t]?.call(e),nn=(e,t)=>e[t]?.call(e)??[];function xy(e,t){if(!$e.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!$e.givenRef(n))return;const r=e.text_(t.getChild(0)),i=e.text_(t.getChild(1)),o=e.text_(n)??"";if(!(r===void 0||i===void 0))return{field:r,op:i.trim(),given:o.replace(/^\$/,"")}}function xf(e,t){const n=e.positioned(t);if(!n)return;const r=Ie(t,"filterClauseList"),i=[];for(const o of r?nn(r,"fieldExpr"):[]){const s=e.positioned(o);if(!s)continue;const a=vi(o,$e.givenRef).map(d=>e.text_(d)).filter(d=>d!==void 0).map(d=>d.replace(/^\$/,""));i.push({...s,givens:a,binding:xy(e,o)})}return{...n,clauses:i}}function ca(e,t){const n=e.span(t);if(!n)return;const r=[],i=[];for(const h of oi(t,$e.queryStatement)){const l=e.positioned(h);l&&r.push(l);const c=Ie(h,"whereStatement");if(c&&$e.whereStatement(c)){const u=xf(e,c);u&&i.push(u)}}const o=n.start+1,s=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:o,closeStart:s,statements:r,wheres:i,indent:d,oneLine:a}}function Dl(e,t,n){const r=[],i=e.line(t.start),o=e.line(n);for(let s=i;s<o;s++){if(e.commentLines.has(s)||e.proseLines.has(s))continue;const a=e.text.slice(e.lineStarts[s],e.lineStarts[s+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:s,text:a})}return r}function by(e,t){const n=Ie(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=$e.vArrow(t);if($e.segOps(n)){const i=Ie(n,"queryProperties"),o=i&&ca(e,i);return o?{kind:"inline",stage:o,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if($e.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($e.segRefine(n)){const i=nn(n,"segExpr"),o=i[0],s=i[i.length-1];let a=o;for(;$e.segRefine(a);){const u=nn(a,"segExpr");if(u.some(p=>$e.segOps(p)||$e.segParen(p)))return{kind:"unsupported",why:"a chained refinement"};a=u[0]}if(a&&$e.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!$e.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const d=e.span(o);if(!d||!s)return{kind:"unsupported",why:"an unreadable refinement"};if(!$e.segOps(s)){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 h=e.text.slice(d.start,d.end),l=Ie(s,"queryProperties"),c=l&&ca(e,l);return c?{kind:"reference",from:h,fromSpan:d,refinement:c}:{kind:"reference",from:h,fromSpan:d}}return{kind:"unsupported",why:"a parenthesized expression"}}function yy(e,t){const n=[];for(const r of oi(t,$e.defExploreQuery)){const i=e.span(r),o=Ie(r,"subQueryDefList");if(!i||!o)continue;const s=nn(o,"exploreQueryDef").filter($e.exploreQueryDef),a=e.terminal(Ie(r,"VIEW"));for(const d of s){const h=e.span(d),l=Ie(d,"exploreQueryNameDef"),c=e.text_(l),u=Ie(d,"vExpr");!h||!c||!u||n.push({name:c,span:h,line:e.line(h.start),statement:i,tags:Dl(e,i,a?.start??h.start),siblings:s.length,body:by(e,u)})}}return n}function wy(e,t){const n=[];for(const r of oi(t,$e.defDimension)){const i=e.span(r),o=Ie(r,"defList");if(!i||!o)continue;const s=e.terminal(Ie(r,"DIMENSION"));for(const a of nn(o,"fieldDef")){const d=e.span(a),h=e.text_(Ie(a,"fieldNameDef"))?.trim(),l=e.text_(Ie(a,"fieldExpr"))?.trim();!d||!h||l===void 0||n.push({name:h,expression:l,span:d,line:e.line(d.start),statement:i,tags:Dl(e,i,s?.start??d.start)})}}return n}function ky(e,t){const n=[];for(const r of vi(t,$e.sourceDefinition)){const i=e.span(r),o=e.text_(Ie(r,"sourceNameDef")),s=Ie(r,"sqExplore");if(!i||!o||!s)continue;const a=e.span(s),d=a?e.text.slice(a.start,a.end):"",h=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(d)?.[1]??"").trim(),l=oi(s,$e.exploreProperties)[0],c=l&&ca(e,l),u={start:e.lineStarts[e.line(i.start)],end:i.end},p=[];if(l)for(const g of oi(l,$e.whereStatement)){const x=xf(e,g);x&&p.push(x)}n.push({name:o,base:h,span:i,line:e.line(i.start),statement:u,...c?{properties:c}:{},views:l?yy(e,l):[],dimensions:l?wy(e,l):[],wheres:p})}return n}function Sy(e,t){const n=[];for(const r of vi(t,$e.givenStatement)){const i=e.terminal(Ie(r,"GIVEN")),o=Ie(r,"givenDefList"),s=i?e.line(i.start):void 0;for(const a of o?nn(o,"givenDef"):[]){const d=e.span(a),h=e.span(Ie(a,"givenNameDef")),l=h&&e.text.slice(h.start,h.end);if(!d||!h||!l)continue;const c={start:h.start,end:d.end},u=e.line(c.start);n.push({name:l,declaration:e.text.slice(c.start,c.end),span:c,line:u,statement:{start:e.lineStarts[u],end:c.end},tags:Dl(e,d,c.start),...s!==void 0&&s!==u?{blockHeader:s}:{}})}}return n}function $y(e,t){const n=[];for(const r of vi(t,$e.importStatement)){const i=e.span(r),o=e.text_(Ie(r,"importURL"));if(!i||o===void 0)continue;const s=Ie(r,"importSelect"),a=s?nn(s,"importItem").map(d=>e.text_(d)).filter(d=>d!==void 0).map(d=>d.trim()):void 0;n.push({from:o.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:i,line:e.line(i.start),statement:i})}return n}async function bf(e){let t;try{t=await Ol(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||!mr(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 o=r?.tokenStream??{},s=typeof o.getTokens=="function"?o.getTokens():void 0;if(!s||typeof o.tokenSource?.vocabulary?.getSymbolicName!="function"||s.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 vf(e),d=jy(a,o);a.commentLines=d.lines;const h=e.split(`
|
|
70
|
-
`),l=u=>d.lines.has(u);a.proseLines=$m(h,l),a.blocks=jm(h,l).filter(([u])=>!h[u].trimStart().startsWith("##"));const c=ky(a,i);return c.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:$y(a,i),sources:c,givens:Sy(a,i),textBlocks:Cy(a,o),modelNotes:gf(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=>My(a,d.lines,u)}}}async function Ol(e,t){const{MalloyTranslator:n}=await Xp(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function jy(e,t){const n=new Map,r=new Set,i=[],o=t.tokenSource?.vocabulary;for(const l of t.getTokens?.()??[]){const c=o?.getSymbolicName(l.type);if(c!=="COMMENT_TO_EOL"&&c!=="BLOCK_COMMENT")continue;const u=e.utf16(l.startIndex);let p=e.utf16(l.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 s=[...i].sort((l,c)=>l.start-c.start);let a="",d=0;for(const l of s)a+=e.text.slice(d,Math.max(d,l.start)),a+=e.text.slice(Math.max(d,l.start),Math.max(d,l.end)).replace(/[^\n\r]/g," "),d=Math.max(d,l.end);a+=e.text.slice(d);const h=l=>a.slice(e.lineStarts[l],e.lineStarts[l+1]??a.length);for(const l of i){const c=e.line(l.start),u=e.line(l.end-1);for(let x=c;x<=u;x++)h(x).trim()===""&&r.add(x);const p=a.slice(e.lineStarts[c],l.start).trim(),g=a.slice(l.end,e.lineStarts[u+1]??a.length).trim();p!==""&&g===""&&n.set(u,l)}return{trailing:n,lines:r,all:i}}function My(e,t,n){const r=o=>e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();let i=n;for(let o=n-1;o>=0;o--){const s=r(o),a=e.blocks.find(([,d])=>d===o);if(a){i=o=a[0];continue}if(s===""&&!t.has(o))break;if(s.startsWith("#")||t.has(o))i=o;else break}return i}function Cy(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,i=a=>r?.getSymbolicName(a.type),o=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),s=[];for(let a=0;a<n.length;a++){if(i(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const d=Rm(o(n[a]).replace(/\r?\n$/,""));if(!d)continue;const h=[];let l=a+1;for(;i(n[l]??n[a])==="BLOCK_ANNOTATION_TEXT";l++)h.push(o(n[l]));const c=n[l];if(!c||i(c)!=="BLOCK_ANNOTATION_END")continue;const u=e.line(e.utf16(n[a].startIndex)??0),p=e.utf16(c.stopIndex+1)??e.text.length,g=d.name===void 0&&d.rest?[`${d.rest}
|
|
72
|
-
`]:[];s.push({...d.name===void 0?{}:{name:d.name},route:d.route,body:[...g,...h].join("").replace(/\r\n?/g,`
|
|
73
|
-
`).replace(/\n$/,""),span:{start:e.lineStarts[u],end:p},line:u}),a=l}return s}function yf(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 wf(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')r=yf(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 o=/^tiles\s*=\s*\[/.exec(e.slice(r));if(o)return Ey(e,r+o[0].length-1)}}}function Ey(e,t){const n=[];let r=0,i=t+1;const o=s=>{const a=e.slice(i,s),d=a.length-a.trimStart().length,h=a.trim();h!==""&&n.push({text:h,span:{start:i+d,end:i+d+h.length}})};for(let s=t+1;s<e.length;s++){const a=e[s];if(a==='"')s=yf(e,s);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return o(s),{open:t,close:s,entries:n};r--}else a===","&&r===0&&(o(s),i=s+1)}}function Dy(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),o=i===-1?e.length:i;if(e.slice(r,o).trim()===">>>")return o;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 Oy(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=Dy(e,r);if(i>r){n+=e.slice(r,i),r=i;continue}const o=e[r];if(/[=[,]/.test(o)){const s=t.exec(e.slice(r+1));if(s){const a=s[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${o}${s[1]}"f'${a}'"`,r+=1+s[0].length;continue}}n+=o,r+=1}return n}function kf(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(o=>{if(e([o]).log.length===0)return o;const s=Oy(o);return e([s]).log.length===0?s:o}),i=e(r);return{tag:i.tag,errors:i.log.map(o=>o.message)}}const Oc=(e,t)=>{try{return e.text(t)}catch{return}},Ty=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Ay=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\`.`,Ry=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=[…]\`.`,Py="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 Sf(e,t){const n=e.filter(Ty).filter(l=>!l.includes("@env.")).map(md),{tag:r,errors:i}=n.length>0?kf(t,n):{tag:void 0,errors:[]},o=r?.tag("artifact");if(!o)return e.some(Zp)?{status:"unparsed",errors:i}:{status:"none"};const s=Oc(o,"kind");if(s!==void 0)return{status:"kind-removed",kind:s};const a=Oc(o,"layout"),d=o.has("tiles");if(d&&o.array("tiles")===void 0)return{status:"unparsed",errors:i};const h=a==="grid"||a==="linear"?a:d||r?.tag("dashboard")!==void 0?"grid":"linear";return h==="linear"&&!d?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:h}}async function Rw(e){const{parseAnnotation:t}=await ad();let n=[];try{const r=(await Ol(e,"file://report.malloy")).parse?.root;r&&mr(r)&&typeof r.getChild=="function"&&(n=gf(new vf(e),r))}catch{n=[]}return Sf(n,t)}const da=e=>e.ok===!1;function gr(e,t,n){const r=e.blockStart(n),i=[],o=[];for(let s=r;s<n;s++){if(e.commentLine(s))continue;if(e.proseLine(s)){o.push(s);continue}const a=t[s].trim();a.startsWith("#")&&!a.startsWith("##")&&i.push({line:s,text:a})}return{start:r,tags:i,prose:o}}const Un=e=>e.map(t=>t.text);function Tc(e){const t=Un(e),n=Mm(t),r=t.map(ja).filter(Boolean).at(-1),i=r?{color:r}:{};return n===void 0?i:n==="custom"?{chart:n,chartLines:Cm(t),...i}:{chart:n,...i}}function Ac(e,t){return Un(e).some(n=>ja(n)===void 0&&t([n]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Iy(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:o,given:s}=r.binding;t.push({field:Em(i),given:s,...o==="~"?{}:{op:o}})}return t.length>0?t:void 0}function Ny(e,t,n){const r=[];for(const i of e.givens){const o=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(i.declaration);o&&r.push({name:o[1],type:o[2],default:o[3].trim(),...Wy(n(Un(gr(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function Wy(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),i=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...i===void 0?{}:{rangeMax:i}}}function Rc(e){const t=e?.numeric("colspan");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:!0}:{}}}function _n(e,t){const n=e?.text(t)?.trim();if(n===void 0||!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(n))return;const r=Number(n);return Number.isInteger(r)&&r>=1?r:void 0}const zy=/^"((?:[^"\\]|\\.)+)"\s*(\{[\s\S]*\})?$/;function ts(e){const t=_n(e,"colspan"),n=_n(e,"rowspan"),r=_n(e,"row"),i=_n(e,"col");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:e.text("break")!=="false"}:{},...n===void 0?{}:{rowspan:n},...r===void 0?{}:{row:r},...i===void 0?{}:{col:i}}}function wr(e,t){const n=t.colspan??e.colspan;return{...n===void 0?{}:{colspan:n},...t.break??e.break?{break:!0}:{},...t.rowspan===void 0?{}:{rowspan:t.rowspan},...t.row===void 0?{}:{row:t.row},...t.col===void 0?{}:{col:t.col}}}const Ly=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,Fy=/^[A-Za-z_][A-Za-z0-9_]*$/;function By(e,t,n){const r=new RegExp(`^\\s*query\\s*:\\s*${n}\\s+is\\b`);for(let i=0;i<t.length;i++)if(!(e.commentLine(i)||e.proseLine(i))&&r.test(t[i]))return gr(e,t,i).tags;return[]}function Pc(e){return{...e?.text("label")?{label:e.text("label")}:{},...e?.text("subtitle")?{subtitle:e.text("subtitle")}:{},...e?.numeric("colspan")!==void 0?{colspan:e.numeric("colspan")}:{},...e?.has("break")?{break:!0}:{},...e?.has("borderless")?{borderless:!0}:{}}}function Ic(e){const{colspan:t,break:n,...r}=e;return r}async function ua(e,t,n=!1){try{return await _y(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 _y(e){const{parseAnnotation:t}=await ad(),n=Vp(e),r=await bf(e);if(mf(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,o=pd(n).text,s=Sf(i.modelNotes,t);if(s.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(s.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${s.errors[0]?`: ${s.errors[0]}`:"."}`};if(s.status==="kind-removed")return{ok:!1,reason:Ay(s.kind)};if(s.status==="cells-removed")return{ok:!1,reason:s.unknownLayout!==void 0?Ry(s.unknownLayout):Py};const a=s.layout,d=wa(n);if(d===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!Up(d.text))return{ok:!1,reason:Kp,line:d.from+1};const{tag:h,errors:l}=kf(t,[md(d.text)]),c=h?.tag("artifact"),u=wf(d.text);if(u===void 0)return l.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${l[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=[],x=[],w=new Map;for(const $ of i.sources){const D={name:$.name,base:$.base};$.dimensions.length>0&&(D.dimensions=$.dimensions.map(M=>({name:M.name,expression:M.expression})));const j=new Set($.wheres.flatMap(M=>M.clauses.flatMap(A=>A.givens)));j.size>0&&(D.scopedBy=Array.from(j)),g.push(D);for(const M of $.dimensions){const A=t(Un(gr(i,n,M.line).tags)).tag?.tag("drill");if(!A)continue;const N=A.textArray("to")??[A.text("to")??""];x.push({source:$.name,name:M.name,expression:M.expression,to:N.filter(Boolean),...A.text("given")?{given:A.text("given")}:{}})}w.set($.name,new Map($.views.map(M=>[M.name,M])))}const y=[],f=($,D)=>{const j=Pc(t(Un(By(i,n,$))).tag);return{name:$,declaration:{kind:"query"},...Ic(j),...wr({colspan:j.colspan,break:j.break},D)}};for(const{text:$}of u.entries){const D=zy.exec($),j=D?void 0:Ly.exec($)?.[1];if(j!==void 0){const O=t([`# ${$}`]).tag?.tag(j),R=O?.text("kind");if(R===void 0||R==="query"){y.push(f(j,ts(O)));continue}if(R!=="text")return{ok:!1,reason:`The tile \`${$}\` is neither a quoted \`source -> view\` expression nor a \`${j} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(y.some(z=>De(z)&&z.name===j))return{ok:!1,reason:`Two text tiles are named \`${j}\`, so the builder cannot tell them apart.`};y.push({kind:"text",name:j,markdown:i.textBlocks.find(z=>z.name===j)?.body??"",...wr({},ts(O))});continue}const M=D?.[1]??$,A=ts(D?.[2]?t([`# tile ${D[2]}`]).tag?.tag("tile")??void 0:void 0);if(Fy.test(M.trim())){y.push(f(M.trim(),A));continue}const N=D?Yp(M):void 0;if(!N)return{ok:!1,reason:`The tile \`${M}\` is neither a \`source -> view\` expression nor the name of a query, which are the forms the builder can lay out.`};const{source:P,view:L}=N,_=w.get(P)?.get(L);if(_===void 0){y.push({name:L,source:P,declaration:{kind:"inherited"},...wr({},A)});continue}const V=t(Un(_.tags)).tag,T=_.body.kind==="reference"?{kind:"reference",from:_.body.from}:_.body.kind==="inline"?{kind:"inline"}:void 0;if(T===void 0){y.push({name:L,source:P,declaration:{kind:"opaque",why:_.body.kind==="unsupported"?_.body.why:"unreadable"},...Ic(Pc(V)),...wr(Rc(V),A),...Tc(_.tags),...Ac(_.tags,t)});continue}const F=Iy(_.body.kind==="reference"?_.body.refinement:_.body.kind==="inline"?_.body.stage:void 0);y.push({name:L,source:P,declaration:T,...F?{filters:F}:{},...V?.text("label")?{label:V.text("label")}:{},...V?.text("subtitle")?{subtitle:V.text("subtitle")}:{},...wr(Rc(V),A),...Tc(_.tags),...Ac(_.tags,t),...V?.has("borderless")?{borderless:!0}:{}})}const v=Ny(i,n,t),b={},k=c?.tag("givens");for(const $ of Object.keys(k?.dict??{})){const D=k?.text($);D!==void 0&&(b[$]=D)}const C=h?.tag("dashboard")?.has("columns")?_n(h.tag("dashboard"),"columns"):c?.array("tiles")?_n(c,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:c?.text("title")??"",...o?{description:o}:{},...C===void 0?{}:{columns:C},...c?.has("autorun")?{autorun:c.isTrue("autorun")}:{},imports:p,sources:g,...v?{localGivens:v}:{},...Object.keys(b).length>0?{startingGivens:b}:{},...x.length>0?{drills:x}:{},tiles:y}}}const ha=e=>e.ok===!1;async function Nc(e){const{problems:t}=await Ol(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function Se(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const i of Object.keys(n).sort())r[i]=t(n[i]);return r}return n};return JSON.stringify(t(e))}function $f(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Hy(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
-
`&&t.push(n+1);return t}function qy(e,t){let n=e;const r=t.map((i,o)=>({edit:i,index:o}));for(const{edit:i}of r.sort((o,s)=>s.edit.start-o.edit.start||s.edit.end-o.edit.end||s.index-o.index))n=n.slice(0,i.start)+i.text+n.slice(i.end);return n}const jf=e=>e==="none"||$a(e)?e:void 0;function Mf(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${Mt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${Mt(e.subtitle)}`);const r=t?jf(e.chart):void 0;return r!==void 0&&n.push(Hn(r,e.chartCarried)),e.color!==void 0&&n.push(yd(e.color)),n}const Cf="theme.palette.series";function qi(e){return ja(e)!==void 0?Cf:/^#\s*([a-z_]+)/.exec(e)?.[1]}const Gy=new Set(["colspan","break","borderless","label","subtitle",Cf]),Vy=new Set(["label","description","control","suggest","range_min","range_max"]);function Wc(e){const t=[];if(e.label!==void 0&&t.push(`label=${Mt(e.label)}`),e.description!==void 0&&t.push(`description=${Mt(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=${Mt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${Mt(e.suggest.dimension)} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const zc=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Uy(e,t,n){const r=e.sources.find(i=>i.name===t)?.views.find(i=>i.name===n);return r?r.line:-1}function Lc(e){const t=n=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(n)?n:Mt(n);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(Mt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const mo=e=>`${e.source}.${e.name}`,Mt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,fa=e=>De(e)?Se(["text",e.name]):Se([e.name,e.source,e.declaration]),ot=fa,Fc=e=>Se(e.tiles.map(ot));function Ky(e,t,n){const r=new Set(e.tiles.map(ot)),i=new Set(t.tiles.map(ot)),o=e.tiles.filter(u=>!i.has(ot(u))),s=t.tiles.filter(u=>!r.has(ot(u))),a=o.length>0||s.length>0||Fc(e)!==Fc(t);for(const u of s)if(de(u)&&u.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${u.name}\` is ${u.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const d=new Map(e.sources.map(u=>[u.name,u])),h=new Set(t.imports.flatMap(u=>u.kind==="names"?u.names:[]));for(const u of e.sources)h.add(u.base);const l=t.imports.some(u=>u.kind==="all"),c=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 c){if(!s.some(p=>de(p)&&p.source===u.name))return{ok:!1,reason:`A new source \`${u.name}\` needs a tile on it.`};if(!h.has(u.base)&&!l&&!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:o,addedTiles:s,newSources:c,currentSources:d,reordered:a}}const Yy=new Set(["colspan","break"]),pa=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break||e.rowspan!==t.rowspan||e.row!==t.row||e.col!==t.col,Bc=e=>{const{colspan:t,break:n,rowspan:r,row:i,col:o,...s}=e;return s},Xy=e=>[...e.row===void 0?[]:[`row=${e.row}`],...e.col===void 0?[]:[`col=${e.col}`],...e.colspan===void 0?[]:[`colspan=${e.colspan}`],...e.break?["break"]:[],...e.rowspan===void 0?[]:[`rowspan=${e.rowspan}`]];function Ef(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=si(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function _c(e,t){const n=Xy(e);if(t===void 0){const l=De(e)?e.name:`"${ht(e)}"`,c=[...De(e)?["kind=text"]:[],...n];return c.length>0?`${l} { ${c.join(" ")} }`:l}const r=Ef(t),i=r.indexOf("{");if(i===-1)return n.length>0?`${t} { ${n.join(" ")} }`:t;const o=r.lastIndexOf("}");let s=t.slice(i+1,o),a=r.slice(i+1,o);const d=l=>{const c=l.exec(a);c&&(s=s.slice(0,c.index)+s.slice(c.index+c[0].length),a=a.slice(0,c.index)+a.slice(c.index+c[0].length))};d(/\s*\bcolspan\s*=\s*[^\s}]+/),d(/\s*\bbreak\b(?:\s*=\s*[^\s}]+)?/),d(/\s*\browspan\s*=\s*[^\s}]+/),d(/\s*\brow\s*=\s*[^\s}]+/),d(/\s*\bcol\s*=\s*[^\s}]+/);const h=[s.trim(),...n].filter(Boolean);return h.length===0?t.slice(0,i).trimEnd():`${t.slice(0,i)}{ ${h.join(" ")} }${t.slice(o+1)}`}function Zy(e){const{lines:t,wholeLine:n,current:r,next:i,reordered:o,currentKeys:s,nextKeys:a,edits:d}=e,h=new Map(r.tiles.map(f=>[ot(f),f])),l=i.tiles.some(f=>{const v=h.get(ot(f));return v!==void 0&&pa(v,f)});if(!o&&!l)return;const c=wa(t);if(!c)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=c.text,p=wf(u);if(!p)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&s.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:f}of p.entries){const v=/^"((?:[^"\\]|\\.)+)"\s*(?:\{[\s\S]*\})?$/.exec(f);if(v){const k=v[1].split("->").map(C=>C.trim());k.length===2?g.set(`${k[0]}->${k[1]}`,f):k.length===1&&g.set(`query.${k[0]}`,f);continue}if(wd(f)){g.set(`query.${f}`,f);continue}const b=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(f)?.[1];b!==void 0&&g.set(/\bkind\s*=\s*text\b/.test(Ef(f))?`text.${b}`:`query.${b}`,f)}const x=i.tiles.map(f=>{const v=!s.has(ot(f)),b=g.get(De(f)?`text.${f.name}`:f.declaration.kind==="query"?`query.${f.name}`:`${f.source}->${f.name}`);if(b===void 0)return v?_c(f):void 0;const k=h.get(ot(f));return k!==void 0&&!pa(k,f)?b:_c(f,b)});if(x.some(f=>f===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const w=u.slice(0,p.open).search(/tiles\s*=\s*$/),y=`${u.slice(0,w)}tiles=[${Qy(u,p,x)}]${u.slice(p.close+1)}`;y!==u&&d.push({...Df(n,c),text:`${y}
|
|
78
|
-
`})}function Df(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Qy(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 o=e.slice(t.open+1,r.span.start),s=e.slice(i.span.end,t.close),a=o.slice(o.lastIndexOf(`
|
|
79
|
-
`)),d=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
|
|
80
|
-
`)?a:" "}`;return`${o}${n.join(d)}${s}`}function Jy(e,t){let n=0,r=0;for(let i=0;i<e.length;i++){const o=e[i];if(o==='"')i=si(e,i);else if(o==="{"||o==="[")n++===0&&r++;else if(o==="}"||o==="]")n--;else if(r===1&&n===1&&e.startsWith(t,i)&&!/[A-Za-z0-9_]/.test(e[i-1]??" ")){const s=/^\s*=\s*/.exec(e.slice(i+t.length));if(!s)continue;const a=i+t.length+s[0].length,d=e[a]==='"'?si(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),h=i-(/\s*$/.exec(e.slice(0,i))?.[0].length??0);return e.slice(0,h)+e.slice(d)}}return e}function e0(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=si(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 o=1,s=n+i[0].length;for(;s<e.length&&o>0;s++)e[s]==='"'?s=si(e,s):e[s]==="{"?o++:e[s]==="}"&&o--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(s)}}return e}function si(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 t0(e){const{lines:t,wholeLine:n,current:r,next:i,edits:o}=e;if(r.layout!==i.layout||r.title!==i.title||r.autorun!==i.autorun||r.columns!==i.columns||Se(r.startingGivens)!==Se(i.startingGivens)){const s=wa(t);if(!s)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=Df(n,s),d=o.find(v=>v.start===a.start&&v.end===a.end);let h=d?d.text.replace(/\n$/,""):s.text;const l=r.layout!==i.layout,c=h.indexOf("artifact"),u=h.indexOf("{",c);let p=0,g=-1;for(let v=u;v<h.length;v++)if(h[v]==="{")p++;else if(h[v]==="}"&&--p===0){g=v;break}if(u<0||g<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let x=h.slice(u+1,g);const w=s.block?`
|
|
81
|
-
${/\n([ \t]+)\S/.exec(x)?.[1]??" "}`:" ",y=v=>s.block?`${x.trimEnd()}${w}${v}
|
|
82
|
-
`:`${x.trimEnd()} ${v} `,f=(v,b)=>{const k=new RegExp(`${s.block?"[ \\t]*":"\\s*"}\\b${v}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(b===void 0){const C=new RegExp(`
|
|
83
|
-
${k.source}[ \\t]*(?=
|
|
84
|
-
)`);x=x.replace(s.block&&C.test(x)?C:k,"")}else k.test(x)?x=x.replace(k,C=>`${s.block?C.slice(0,C.length-C.trimStart().length):" "}${v}=${b}`):x=y(`${v}=${b}`)};if(l&&f("layout",i.layout),r.title!==i.title&&f("title",i.title?Mt(i.title):void 0),r.autorun!==i.autorun&&f("autorun",i.autorun===void 0?void 0:String(i.autorun)),Se(r.startingGivens)!==Se(i.startingGivens)){x=x.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const v=Object.entries(i.startingGivens??{});v.length>0&&(x=y(`givens { ${v.map(([b,k])=>`${b}=${Mt(k)}`).join(" ")} }`))}s.block?h=`${h.slice(0,u+1)}${x}${h.slice(g)}`:(x=x.replace(/\s{2,}/g," "),h=`${h.slice(0,u+1)}${x.startsWith(" ")?x:` ${x}`}${x.endsWith(" ")?"":" "}${h.slice(g)}`),r.columns!==i.columns&&(h=Jy(h,"dashboard_columns"),h=e0(h),i.columns!==void 0&&(h=`${h.trimEnd()} dashboard { columns=${i.columns} }`)),d?d.text=`${h}
|
|
85
|
-
`:o.push({...a,text:`${h}
|
|
86
|
-
`})}if(r.description!==i.description){const{read:s,blankAbove:a,below:d,belowBlock:h,inBlock:l}=pd(t);if(l||i.description===void 0&&h)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 c=$f(i.description??"").split(`
|
|
87
|
-
`).map(x=>x.trim()===""?'##"':`##" ${x.trim()}`).join(`
|
|
88
|
-
`),u=s.length>0&&s[0]<Wl(t),p=i.description===void 0,g=u?[...s.slice(1),...p?d:[]]:[...s,...a];for(const x of g)o.push({...n(x),text:""});if(u)o.push({...n(s[0]),text:i.description===void 0?"":`${c}
|
|
89
|
-
`});else if(i.description!==void 0){const x=n(Wl(t)).start;o.push({start:x,end:x,text:`${c}
|
|
90
|
-
`})}}}function n0(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:o,edits:s,parsed:a}=e,d=new Map((i.localGivens??[]).map(p=>[p.name,p])),h=new Map((o.localGivens??[]).map(p=>[p.name,p])),l=new Map(a.givens.map(p=>[p.name,p])),c=new Set;for(const[p,g]of d){const x=h.get(p);if(x!==void 0&&Se(x)===Se(g))continue;const w=l.get(p);if(w===void 0)return{ok:!1,reason:`Could not find where the given \`${p}\` is declared.`};const{tags:y,prose:f}=gr(a,t,w.line),v=[...(x===void 0?y:y.filter(D=>{const j=qi(D.text);return j!==void 0&&Vy.has(j)})).map(D=>D.line),...x===void 0?f:[]];for(const D of v)s.push({...n(D),text:""}),c.add(D);const b=Bt(a,w.span.end-1);if(x===void 0){s.push({start:n(w.line).start,end:n(b).end,text:""});for(let P=w.line;P<=b;P++)c.add(P);const D=Math.min(w.line,...v),j=w.blockHeader??D,M=(t[b+1]??"x").trim()==="",A=j===0||t[j-1].trim()==="",N=w.blockHeader===void 0||![...l.values()].some(P=>P.blockHeader===w.blockHeader&&P.line>w.line&&h.has([...l.entries()].find(([,L])=>L===P)?.[0]??""));M&&A&&N&&!c.has(b+1)&&(s.push({...n(b+1),text:""}),c.add(b+1));continue}const k=r(w.line),C=Wc(x),$=x.type!==g.type||x.default!==g.default?w.blockHeader===void 0?zc(x):`${x.name} :: ${x.type} is ${x.default}`:t.slice(w.line,b+1).join(`
|
|
91
|
-
`).trim();s.push({start:n(w.line).start,end:n(b).end,text:(C?`${k}${C}
|
|
92
|
-
`:"")+`${k}${$}
|
|
93
|
-
`})}for(const[p,g]of l)g.blockHeader===void 0||h.has(p)||![...l.values()].some(x=>x.blockHeader===g.blockHeader&&!c.has(x.line))&&!c.has(g.blockHeader)&&(s.push({...n(g.blockHeader),text:""}),c.add(g.blockHeader));const u=[...h.values()].filter(p=>!d.has(p.name));if(u.length>0){const p=Math.max(-1,...[...l.values()].map(f=>f.line)),g=(()=>{let f=-1;for(let v=0;v<t.length;v++){const b=t[v].trim();(b.startsWith("import ")||f>=0&&/^}\s*from\s/.test(b))&&(f=v)}return f})(),x=p>=0?p:g,w=u.map(f=>{const v=Wc(f);return(v?`${v}
|
|
94
|
-
`:"")+`${zc(f)}
|
|
95
|
-
`}).join(`
|
|
96
|
-
`),y=x>=0?n(x).end:n(0).end;s.push({start:y,end:y,text:`
|
|
97
|
-
${w}`}),t.some(f=>f.trim().startsWith("##! experimental.givens"))||s.push({start:0,end:0,text:`##! experimental.givens
|
|
98
|
-
`})}}const Hc=(e,t)=>`import { ${e.join(", ")} } from ${Mt(t)}`;function r0(e){const{parsed:t,current:n,next:r,edits:i,wholeLine:o}=e,s=c=>Se(c.imports.flatMap(u=>u.kind==="all"?[u.from]:[]).sort());if(s(n)!==s(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(Se(n.imports)===Se(r.imports))return;const a=r.imports.flatMap(c=>c.kind==="names"?[{...c,claimed:!1}]:[]),d=new Set([...r.sources.map(c=>c.base),...r.tiles.filter(de).map(c=>c.source)]),h=t.imports.map((c,u)=>({statement:c,entry:n.imports[u]}));for(const{statement:c,entry:u}of h){if(!u||u.kind!=="names")continue;const p=a.find(f=>!f.claimed&&f.from===u.from);p&&(p.claimed=!0);const g=p?.names??[],x=u.names.filter(f=>!g.includes(f)).find(f=>d.has(f));if(x!==void 0)return{ok:!1,reason:`\`${x}\` is still read by a tile, so its import cannot be removed.`};if(Se(g)===Se(u.names))continue;const w=g.length===0?Tl(t,c.statement):c.statement,y=t.commentIn(w);if(y)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(y.start,y.end).trim()}\`), so nothing was written. Delete it in the file first.`};i.push({...w,text:g.length===0?"":Hc(g,u.from)})}const l=a.filter(c=>!c.claimed);if(l.length>0){const c=t.imports.at(-1);if(!c)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const u=o(Bt(t,c.statement.end-1)).end;i.push({start:u,end:u,text:l.map(p=>`${Hc(p.names,p.from)}
|
|
99
|
-
`).join("")})}}function i0(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:o,edits:s,parsed:a}=e,d=new Map((i.drills??[]).map(l=>[mo(l),l])),h=new Map((o.drills??[]).map(l=>[mo(l),l]));for(const l of new Set([...d.keys(),...h.keys()])){const c=d.get(l),u=h.get(l);if(c&&u&&Se(c)===Se(u))continue;const p=u??c;if(u&&u.to.length===0)return{ok:!1,reason:`The drill on \`${l}\` names no destination.`};const g=a.sources.find(f=>f.name===p.source)?.dimensions.find(f=>f.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:x}=gr(a,t,g.line),w=x.find(f=>/^#\s*drill\b/.test(f.text)),y=r(g.line);if(u===void 0)w&&s.push({...n(w.line),text:""});else if(w)s.push({...n(w.line),text:`${y}${Lc(u)}
|
|
100
|
-
`});else{const f=n(g.line).start;s.push({start:f,end:f,text:`${y}${Lc(u)}
|
|
101
|
-
`})}}}function o0(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:o}=e;for(const s of r){if(De(s)||nr(s))continue;const a=Of(e,s);if(!a)return{ok:!1,reason:`Could not find where \`${s.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${s.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const d=Bt(o,a.statement.start),h=Bt(o,a.statement.end-1),l=o.trailingComment(h),c=l&&l.start>=a.statement.end?l.end:a.statement.end;if(o.text.slice(o.lineStarts[d],a.statement.start).trim()!==""||o.text.slice(c,n(h).end).trim()!==""){i.push({...Tl(o,a.statement),text:""});continue}i.push({start:o.lineStarts[d],end:n(h).end,text:""});const u=d===0?"":t[d-1].trim();(t[h+1]??"x").trim()===""&&(d===0||u===""||u.endsWith("{"))&&i.push({...n(h+1),text:""})}}function s0(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:i,newSources:o,currentSources:s,edits:a,parsed:d}=e,h=new Map;for(const u of i){if(De(u))continue;const p=h.get(u.source)??[];p.push(u),h.set(u.source,p)}const l=(u,p)=>{const g=u.declaration.kind==="reference"?u.declaration.from:u.name,x=(u.filters??[]).map(w=>`where: ${Sa(w.field)} ${w.op??"~"} $${w.given}`).join(", ");return[...Mf(u).map(w=>`${p}${w}`),`${p}view: ${u.name} is ${g}${x?` + { ${x} }`:""}`].join(`
|
|
102
|
-
`)};let c=-1;for(const u of d.sources)c=Math.max(c,Bt(d,u.span.end-1));for(const[u,p]of h)if(s.has(u)){const g=d.sources.find(b=>b.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 x=g.line,w=Bt(d,g.properties.closeStart);let y=" ";for(let b=x+1;b<w;b++){const k=/^(\s+)view:/.exec(n[b]);if(k){y=k[1];break}}const f=r(w).start,v=(n[w-1]??"").trim()==="";a.push({start:f,end:f,text:(v?"":`
|
|
103
|
-
`)+p.map(b=>l(b,y)).join(`
|
|
104
|
-
|
|
105
|
-
`)+`
|
|
106
|
-
`})}else{const g=o.find(v=>v.name===u);if(!g)return{ok:!1,reason:`The tile's source \`${u}\` is not declared.`};const x=`
|
|
107
|
-
source: ${g.name} is ${g.base} extend {
|
|
108
|
-
`+p.map(v=>l(v," ")).join(`
|
|
109
|
-
|
|
110
|
-
`)+`
|
|
111
|
-
}
|
|
112
|
-
`;let w=c;if(w<0)for(let v=0;v<n.length;v++){const b=n[v].trim();(/^(import\s|given:|}\s*from\s)/.test(b)||/^[A-Z_]+\s*::/.test(b))&&(w=v)}const y=w>=0?r(w).end:t.length,f=y===t.length&&!t.endsWith(`
|
|
113
|
-
`)?`
|
|
114
|
-
`:"";a.push({start:y,end:y,text:f+x}),c=w}}function a0(e){const{lines:t,starts:n,wholeLine:r,indentOf:i,current:o,next:s,edits:a,parsed:d}=e,h=new Map(o.tiles.map(l=>[ot(l),l]));for(const l of s.tiles){const c=h.get(ot(l));if(c===void 0||De(l)||De(c))continue;const u=pa(c,l),p=Se(Bc(go(c)))!==Se(Bc(go(l)));if(!p&&!u)continue;if(l.declaration.kind==="inherited"){if(!p)continue;return{ok:!1,reason:`\`${ht(l)}\` is declared on its source, not in this report, so its presentation cannot be changed here.`}}if(l.declaration.kind==="query"){if(!p)continue;return{ok:!1,reason:`\`${l.name}\` names a query, whose presentation is the query's own, so it cannot be changed here.`}}const g=Uy(d,l.source,l.name);if(g<0)return{ok:!1,reason:`Could not find where \`${l.name}\` is declared inside \`${l.source}\`.`};const{tags:x}=gr(d,t,g),w=i(g),y=Mf(l,!1),f=new Map(y.map(A=>[qi(A)??A,A])),v=new Set,b=jf(l.chart),k=qc(c)!==qc(l);if(k){const A=x.filter(L=>zl(L.text)),N=x.filter(L=>zo(L.text)),P=c.chart==="custom"?x.filter(L=>zo(L.text)||zl(L.text)):A.length>0?A:N.length>1?N:[];if(P.length>0)return{ok:!1,reason:`\`${l.source} -> ${l.name}\` has a chart line the builder does not model (${P.map(L=>L.text).join(" and ")}), so its chart cannot be changed here.`}}let C=!1;for(const A of x){if(k&&zo(A.text)){b===void 0?a.push({...r(A.line),text:""}):A.text!==Hn(b,l.chartCarried)&&a.push({...r(A.line),text:`${w}${Hn(b,l.chartCarried)}
|
|
115
|
-
`}),C=!0;continue}const N=qi(A.text);if(N===void 0||!Gy.has(N))continue;if(Yy.has(N)){u&&a.push({...r(A.line),text:""});continue}const P=f.get(N);if(P===void 0){a.push({...r(A.line),text:""});continue}v.add(N),P!==A.text&&a.push({...r(A.line),text:`${w}${P}
|
|
116
|
-
`})}const $=y.filter(A=>!v.has(qi(A)??A));if(k&&b!==void 0&&!C&&$.push(Hn(b,l.chartCarried)),$.length>0){const A=n[g];a.push({start:A,end:A,text:$.map(N=>`${w}${N}
|
|
117
|
-
`).join("")})}if(Se(c.filters)===Se(l.filters))continue;const D=Of(e,l);if(!D)return{ok:!1,reason:`Could not find \`${l.name}\`'s declaration to filter it.`};if(D.body.kind==="reference"){const A=p0(e,l,D);if(A)return A;continue}if(D.body.kind!=="inline")return{ok:!1,reason:`\`${l.name}\`'s body is ${D.body.why}, so there is no single first stage to write its filter into.`};const j=Tf(l.filters,D.body.stage);if(j)return Af(l.name,j.given);const M=Rf(e,l,D.body.stage);if(M)return M}}const qc=e=>e.chart==="default"?void 0:e.chart,go=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:i,...o}=r;return o};function l0(e,t){const n=new Map(e.tiles.map(r=>[ot(r),r]));return{...t,tiles:t.tiles.map(r=>{const i=n.get(ot(r));return de(r)&&r.chart===void 0&&i&&de(i)&&i.chart!==void 0?{...r,chart:i.chart}:r})}}function Gi(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 c0(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&&!wd(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=Gi(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 ns=e=>`##|(markdown) ${e.name}
|
|
118
|
-
${e.markdown===""?"":`${e.markdown}
|
|
119
|
-
`}|##
|
|
120
|
-
`;function d0(e){const{sourceText:t,lines:n,wholeLine:r,current:i,next:o,parsed:s,edits:a}=e,d=new Map(i.tiles.filter(De).map(p=>[p.name,p])),h=o.tiles.filter(De),l=p=>s.textBlocks.find(g=>g.name===p),c=new Set(h.map(p=>p.name));for(const p of d.keys()){const g=c.has(p)?void 0:l(p);if(!g)continue;const x=Bt(s,g.span.end-1);a.push({...g.span,text:""});const w=r(x+1),y=g.line===0||n[g.line-1].trim()==="";w.end>w.start&&n[x+1].trim()===""&&y?a.push({...w,text:""}):g.line>0&&y&&t.slice(g.span.end).trim()===""&&a.push({...r(g.line-1),text:""})}const u=[];for(const p of h){const g=d.get(p.name),x=l(p.name);if(g===void 0){if(x)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(ns(p))}else g.markdown!==p.markdown&&(x?a.push({...x.span,text:ns(p)}):u.push(ns(p)))}if(u.length>0){const p=s.textBlocks.filter(f=>f.name===void 0||c.has(f.name)),g=p[p.length-1],x=s.sources.find(f=>f.name.endsWith("_tiles"));if(g){const f=g.span.end,v=t.slice(f);a.push({start:f,end:f,text:`
|
|
121
|
-
${u.join(`
|
|
122
|
-
`)}${v===""||v.startsWith(`
|
|
123
|
-
`)?"":`
|
|
124
|
-
`}`});return}if(x){const f=e.starts[s.blockStart(x.line)],v=f===0||t.slice(0,f).endsWith(`
|
|
125
|
-
|
|
126
|
-
`);a.push({start:f,end:f,text:`${v?"":`
|
|
127
|
-
`}${u.join(`
|
|
128
|
-
`)}
|
|
129
|
-
`});return}const w=t.length,y=t===""||t.endsWith(`
|
|
130
|
-
|
|
131
|
-
`)?"":t.endsWith(`
|
|
132
|
-
`)?`
|
|
133
|
-
`:`
|
|
134
|
-
|
|
135
|
-
`;a.push({start:w,end:w,text:y+u.join(`
|
|
136
|
-
`)})}}const Oi=(e,t=ms)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function u0(e,t){const n=new Map(e.tiles.map(s=>[ot(s),s]));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 s of t.tiles){const a=n.get(ot(s));if(De(s)){const c=c0(s,a&&De(a)?a:void 0,r);if(c)return c;continue}const d=a&&de(a)?a:void 0;if(a&&!d)continue;const h=s.chart;if(h!==void 0&&h!=="default"&&h!=="none"&&!$a(h)&&!(h==="custom"&&d?.chart==="custom"))return`"${String(h)}" is not a chart this editor writes.`;const l=new Set(d?.filters?.map(c=>c.field));for(const c of s.filters??[])if(!l.has(c.field)&&/[\r\n]/.test(c.field))return"A filter field is one line.";if(a===void 0){const c=[s.name,s.source];s.declaration.kind==="reference"&&c.push(s.declaration.from);for(const u of c){const p=Oi(u);if(p)return p}}for(const c of["label","subtitle"]){const u=s[c];if(u===void 0||u===d?.[c])continue;const p=jn(`tile ${c}`,u);if(p)return p}}const i=new Set(e.sources.map(s=>s.name));for(const s of t.sources)if(!i.has(s.name))for(const a of[s.name,s.base]){const d=Oi(a);if(d)return d}if(t.description!==e.description)for(const s of(t.description??"").split(/\r?\n/)){const a=jn("description line",s);if(a)return a}if(t.title!==e.title){const s=jn("title",t.title);if(s)return s}const o=new Map((e.localGivens??[]).map(s=>[s.name,s]));for(const s of t.localGivens??[]){const a=o.get(s.name);if(a===void 0){const h=Oi(s.name,kd);if(h)return h}const d=s.suggest?.source;if(d!==void 0&&d!==a?.suggest?.source){const h=Oi(d);if(h)return`The suggest source is not a name. ${h}`}for(const h of["query","dimension"]){const l=s.suggest?.[h];if(l===void 0||l===a?.suggest?.[h])continue;const c=jn(`suggest ${h}`,l);if(c)return c}for(const h of["label","description"]){const l=s[h];if(l===void 0||l===o.get(s.name)?.[h])continue;const c=jn(`given ${h}`,l);if(c)return c}}for(const[s,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[s])continue;const d=jn(`starting value for ${s}`,a);if(d)return d}}const Bt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Of(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Tf(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 o of i.givens)n.add(o);return(e??[]).find(r=>n.has(r.given))}function Af(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 Vi=e=>`where: ${Sa(e.field)} ${e.op??"~"} $${e.given}`;function Gc(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 h0(e,t,n){const r=e.commentIn(n);if(r)return r;const i=e.trailingComment(Bt(e,t.end-1));return i&&i.start>=t.end&&e.text.slice(t.end,i.start).trim()===""?i:void 0}function f0(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 Tl(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),o=e.text.slice(t.end,i<0?void 0:i);if(r.trim()===""&&o.trim()==="")return{start:n,end:i<0?e.text.length:i+1};if(r.trim()===""){const a=/^\s*/.exec(o)?.[0].length??0;return{start:t.start,end:t.end+a}}const s=r.replace(/[\s,]*$/,"");return{start:n+s.length,end:t.end}}function Rf(e,t,n){const{parsed:r,edits:i}=e,o=new Map((t.filters??[]).map(u=>[u.given,u])),s=new Set;let a;for(const u of n.wheres){const p=u.clauses.map((x,w)=>({clause:x,index:w})).filter(({clause:x})=>x.binding!==void 0);if(p.length===0)continue;const g=p.filter(({clause:x})=>o.has(x.binding.given));for(const{clause:x}of p)s.add(x.binding.given);if(g.length===0&&p.length===u.clauses.length){const x=Tl(r,u.span),w=h0(r,u.span,x);if(w)return Gc(t.name,r,w);i.push({...x,text:""});continue}g.length>0&&(a=u.span);for(let x=p.length-1;x>=0;x--){const{clause:w,index:y}=p[x],f=o.get(w.binding.given);if(!f){const b=f0(u.clauses,y),k=r.commentIn(b);if(k)return Gc(t.name,r,k);i.push({...b,text:""});continue}const v=Vi(f).replace(/^where:\s*/,"");v!==r.text.slice(w.span.start,w.span.end)&&i.push({...w.span,text:v})}}const d=(t.filters??[]).filter(u=>!s.has(u.given));if(d.length===0)return;let h=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const u=r.trailingComment(Bt(r,h));u&&u.start>=h&&(h=u.end)}const l=a!==void 0&&!/,\s*$/.test(r.text.slice(0,h))?", ":" ",c=n.oneLine?`${l}${d.map(Vi).join(", ")}`:d.map(u=>`
|
|
138
|
-
${n.indent}${Vi(u)}`).join("");i.push({start:h,end:h,text:c})}function p0(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:o}=n.body,s=Tf(t.filters,o);if(s)return Af(t.name,s.given);const a=t.filters??[];if(!o){if(a.length===0)return;const l=` + { ${a.map(Vi).join(", ")} }`;r.push({start:i.end,end:i.end,text:l});return}const d=o.wheres.some(l=>l.clauses.some(c=>!c.binding)),h=o.statements.some(l=>!o.wheres.some(c=>c.span.start===l.span.start));if(a.length===0&&!d&&!h){const l={start:i.end,end:o.span.end},c=e.parsed.commentIn(l);if(c)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(c.start,c.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...l,text:""});return}return Rf(e,t,o)}async function m0(e,t,n={}){if(!(e.includes(`\r
|
|
139
|
-
`)&&!/(?<!\r)\n/.test(e)))return Vc(e,t,n);const r=await Vc(e.replace(/\r\n/g,`
|
|
140
|
-
`),t,n);return ha(r)?r:{...r,source:r.source.replace(/\n/g,`\r
|
|
141
|
-
`)}}async function Vc(e,t,n){const r=await ua(e);if(da(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const i=r.document,o=l0(i,t),s=Ky(i,o,n.visibleSources);if("reason"in s)return s;const a=u0(i,o);if(a)return{ok:!1,reason:a};const d=await bf(e);if(mf(d))return{ok:!1,reason:`Cannot edit a file that will not open: ${d.reason}`};const h=e.split(`
|
|
142
|
-
`),l=Hy(e),c=f=>({start:l[f],end:f+1<l.length?l[f+1]:e.length}),u=f=>/^\s*/.exec(h[f])?.[0]??"",p=[],g={...s,sourceText:e,parsed:d.parsed,lines:h,starts:l,wholeLine:c,indentOf:u,current:i,next:o,edits:p};for(const f of[Zy,t0,r0,n0,i0,o0,s0,a0,d0]){const v=f(g);if(v)return v}const x=f=>{const{drills:v,localGivens:b,description:k,...C}=f,$=f.tiles.map(D=>{if(De(D))return D;if(D.filters?.length)return go(D);const{filters:j,...M}=D;return go(M)});return{...C,...k===void 0?{}:{description:$f(k)},tiles:$,...v?.length?{drills:[...v].sort((D,j)=>mo(D).localeCompare(mo(j)))}:{},...b?.length?{localGivens:b}:{}}};if(p.length===0)return Se(x(i))!==Se(x(o))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const w=qy(e,p);if((await Nc(e)).length===0){const f=await Nc(w);if(f.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${f[0]}). Your changes are still here.`}}const y=await ua(w);return da(y)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${y.reason}`}:Se(x(y.document))!==Se(x(o))?{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:w}}function Pf({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=qe(),o=i.ui,s=S.useId(),[a,d]=S.useState(!1),h=S.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:l,patch:c,close:u,discard:p}=Ad(h,a,b=>n(b.text),()=>d(!1)),g=a&&l!==void 0&&l.text!==e,x=l!==void 0&&l.text!==e?Gi(l.text):void 0;ef(g,()=>x!==void 0?!1:(u(),!0));const w=S.useRef(!1);S.useEffect(()=>{a||(w.current=!1)},[a]);const y=S.useCallback(b=>{!b||w.current||(w.current=!0,b.setSelectionRange(b.value.length,b.value.length))},[]);if(!a||l===void 0){const b=e.trim()?Gi(e):void 0;return m.jsxs(H,{role:"button",tabIndex:0,onClick:k=>{k.target.closest("a")?k.preventDefault():d(!0)},onKeyDown:k=>{k.target===k.currentTarget&&(k.key!=="Enter"&&k.key!==" "||(k.preventDefault(),d(!0)))},sx:[{minHeight:24},Qh(i,"prose")],children:[e.trim()?m.jsx(hm,{variant:r,children:e}):m.jsx(me,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),b&&m.jsx(me,{variant:"caption",color:"error",role:"alert",children:b})]})}const f=l.text!==e?Gi(l.text):void 0,v=()=>{f===void 0&&u()};return m.jsxs(H,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx(bd,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:l.text,placeholder:t,error:f!==void 0,inputRef:y,inputProps:{"aria-label":"Markdown","aria-describedby":s,...f!==void 0?{"aria-invalid":!0}:{}},onChange:b=>c(k=>{k.text=b.target.value}),onKeyDown:b=>{b.key==="Escape"?(b.preventDefault(),p(),d(!1)):b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),v())},onBlur:()=>u(),sx:{p:0,...o.type.prose,color:"inherit",maxWidth:fm,"& textarea":{p:0}}}),f!==void 0&&m.jsx(me,{variant:"caption",color:"error",role:"alert",children:f}),m.jsxs(me,{id:s,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",gn,"↩ done · Esc cancels"]})]})}const g0="Write markdown: # heading, **bold**, - list";function v0({tile:e,onChange:t}){return m.jsx(cd,{sx:{overflow:"visible"},children:m.jsx(Pf,{markdown:e.markdown,placeholder:g0,onCommit:t})})}const x0={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},If=(e,t)=>t===0?e:If(t,e%t);function b0(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=If(e,t),i=x0[`${e/r}/${t/r}`];return i?`${n} · ${i}`:n}function y0({tile:e,index:t,selected:n,flash:r=!1,menuOpen:i,bare:o=!1,onInsertAfter:s,onSelect:a,onOpenMenu:d,onRemove:h,removeBlocked:l,resizing:c=!1,width:u,onResizeStart:p,onResizeMove:g,onResizeEnd:x,heightEdge:w,fixed:y=!1,children:f}){const{theme:v}=qe(),b=v.ui;return m.jsx(fy,{id:ke(e),index:t,disabled:y,children:({ref:k,handleRef:C})=>m.jsxs(H,{ref:k,onClick:a,onPointerDown:$=>{$.button===0&&a()},role:"group",className:Qe.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":ke(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",...(e.rowspan!==void 0||e.row!==void 0)&&{gridTemplateRows:"minmax(0, 1fr)",minHeight:0},minWidth:0,cursor:"grab",...Nf(v,{selected:n,flash:r,bare:o}),...!o&&{[`& .${im}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:v.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${v.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...tm,...n&&{[`& .${rm}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[f,m.jsx(H,{ref:C,"aria-label":`Move ${Mn(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(nm,{label:`Remove ${Mn(e)}`,onRemove:h,...l?{disabledReason:l}:{},inset:o?gd:0}),!De(e)&&m.jsx(Kn,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Mn(e)}`,onClick:$=>{$.stopPropagation(),d($.currentTarget)},sx:{position:"absolute",top:o?0:`${Uc}px`,right:o?0:`${Uc}px`,borderRadius:b.radius.control,width:28,height:28,zIndex:2,color:"text.secondary",bgcolor:"action.hover",opacity:n||i?1:0,transition:`opacity ${Fe}`,...Wt,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx($0,{})}),p&&m.jsx(H,{className:`builder-affordance ${Qe.widthHandle}`,[El]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Mn(e)}`,...u?{"aria-valuenow":u.span,"aria-valuemin":1,"aria-valuemax":u.max??u.columns,"aria-valuetext":`${u.span} of ${u.columns} columns`}:{},onKeyDown:$=>{if(!u)return;const D=$.key==="ArrowRight"?u.span+1:$.key==="ArrowLeft"?u.span-1:$.key==="Home"?1:$.key==="End"?u.max??u.columns:void 0;D!==void 0&&($.preventDefault(),$.stopPropagation(),u.onStep(Math.min(Math.max(D,1),u.max??u.columns)))},onPointerDown:p,onPointerMove:g,onPointerUp:x,onPointerCancel:x,onClick:$=>$.stopPropagation(),sx:$=>({position:"absolute",top:0,bottom:0,right:"-8px",width:"16px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:c||n?1:0,transition:`opacity ${Fe}`,...Wt,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${v.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:b.radius.control,border:`1px solid ${c?v.accent:_t(v.cardBorder)}`,bgcolor:$.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 ${Fe}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"5px",height:"16px",borderLeft:`1.5px solid ${c?v.accent:$.palette.text.secondary}`,borderRight:`1.5px solid ${c?v.accent:$.palette.text.secondary}`,boxSizing:"border-box",opacity:c?1:.7},"&:hover::before":{borderColor:v.accent},"&:hover::after":{borderColor:v.accent,opacity:1}}),children:c&&u&&m.jsx(H,{"aria-hidden":!0,sx:$=>({position:"absolute",top:"50%",right:"50%",transform:"translateY(calc(-100% - 28px))",px:1,py:.5,borderRadius:b.radius.control,bgcolor:$.palette.text.primary,color:$.palette.background.paper,...b.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:b0(u.span,u.columns)})}),w&&m.jsx(j0,{edge:w,label:Mn(e),selected:n}),s&&m.jsx(Kn,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Mn(e)}`,onClick:$=>{$.stopPropagation(),s()},sx:{position:"absolute",bottom:`-${pt/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:v.tileTitle,bgcolor:v.tile,border:v.cardBorder,opacity:0,transition:`opacity ${Fe}`,...Wt,"&:hover, &:focus-visible":{opacity:1,bgcolor:v.tile}},children:m.jsx(ai,{sx:{fontSize:14}})})]})})}const Uc=14,rs=7,Nf=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:i=gd})=>{const o=e.ui,s=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 ${Fe}, border-color ${Fe}, opacity ${Fe}, box-shadow ${Fe}`;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 ${s}`,...a&&{boxShadow:a},pointerEvents:"none",transition:d,...Wt}}:{borderRadius:o.radius.tile,"& > .MuiPaper-root":{transition:d,...Wt,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:d,...Wt,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:vo(e.cardBorder,e.tileTitle)}}}}};function w0({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=qe();return m.jsxs(us,{chrome:r,children:[m.jsx(hs,{title:t?.title??yo(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx(me,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),m.jsx(me,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:ht(e).replace("->","→")})]})}function k0({after:e}){const{theme:t}=qe();return m.jsx(py,{id:nf(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx(H,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${Fe}, background-color ${Fe}`,...Wt}})})}function S0({columns:e}){const{theme:t}=qe();return m.jsx(H,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${pt}px`},children:Array.from({length:e},(n,r)=>m.jsx(H,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function Kc({top:e}){const{theme:t}=qe(),n=fs+pt,r=-Math.ceil(e/n);return m.jsx(H,{"aria-hidden":!0,sx:{position:"absolute",inset:0,overflow:"hidden",pointerEvents:"none",zIndex:0},children:Array.from({length:-r+4*Ai},(i,o)=>m.jsx(H,{sx:{position:"absolute",top:e+(r+o)*n,left:0,right:0,height:fs,bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},o))})}function $0(){return m.jsxs(Om,{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 j0({edge:e,label:t,selected:n}){const{theme:r}=qe(),i=r.ui,{rows:o,dragging:s}=e,a=o===void 0;return m.jsx(H,{className:"builder-affordance",[El]:"",role:"separator",tabIndex:0,"aria-orientation":"horizontal","aria-label":`Height of ${t}`,"aria-valuemin":e.min,"aria-valuemax":Ai,...a?{}:{"aria-valuenow":o},"aria-valuetext":Yc(o),onKeyDown:d=>{const h=o??e.min,l=d.key==="ArrowDown"?h+1:d.key==="ArrowUp"?h-1:d.key==="Home"?e.min:d.key==="End"?Ai:d.key==="Delete"||d.key==="Backspace"?null:void 0;if(l===void 0)return;if(d.preventDefault(),d.stopPropagation(),l===null){a||e.onStep(void 0);return}const c=Math.min(Math.max(l,e.min),Ai);c!==o&&e.onStep(c)},onPointerDown:e.onStart,onPointerMove:e.onMove,onPointerUp:e.onEnd,onPointerCancel:e.onEnd,onClick:d=>d.stopPropagation(),onDoubleClick:d=>{d.stopPropagation(),a||e.onStep(void 0)},sx:d=>({position:"absolute",left:0,right:0,bottom:"-8px",height:"16px",cursor:"row-resize",touchAction:"none",zIndex:2,opacity:s||n?1:0,transition:`opacity ${Fe}`,...Wt,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${r.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"40px",height:"12px",boxSizing:"border-box",borderRadius:i.radius.control,border:`1px solid ${s?r.accent:_t(r.cardBorder)}`,bgcolor:d.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 ${Fe}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"16px",height:"5px",borderTop:`1.5px solid ${s?r.accent:d.palette.text.secondary}`,borderBottom:`1.5px solid ${s?r.accent:d.palette.text.secondary}`,boxSizing:"border-box",opacity:s?1:.7},"&:hover::before":{borderColor:r.accent},"&:hover::after":{borderColor:r.accent,opacity:1}}),children:s&&m.jsx(H,{"aria-hidden":!0,sx:d=>({position:"absolute",left:"50%",bottom:"50%",transform:"translate(32px, 50%)",px:1,py:.5,borderRadius:i.radius.control,bgcolor:d.palette.text.primary,color:d.palette.background.paper,...i.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:Yc(o)})})}const Yc=e=>e===void 0?"Auto height":`${e} rows tall`,Al=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1),is=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function M0({tiles:e,columns:t,gridBox:n,onStart:r,commit:i}){const[o,s]=S.useState(void 0),a=S.useRef(void 0),d=h=>{a.current=h,s(h)};return S.useEffect(()=>()=>is(!1),[]),{resize:o,startResize:(h,l)=>{const c=n.current?.getBoundingClientRect(),u=h.currentTarget.parentElement?.getBoundingClientRect();if(!c||!u)return;h.stopPropagation(),h.preventDefault(),h.currentTarget.setPointerCapture(h.pointerId),is(!0),r(l);const p=e[l]?.colspan??1,g=Al(e[l],t);d({index:l,span:p,from:p,left:u.left,track:(c.width-pt*(t-1))/t,max:g})},onResize:h=>{const l=a.current;if(!l)return;const c=h.clientX-l.left,u=Math.round((c+pt)/(l.track+pt)),p=Math.min(Math.max(u,1),l.max);p!==l.span&&d({...l,span:p})},endResize:h=>{h.currentTarget.hasPointerCapture(h.pointerId)&&h.currentTarget.releasePointerCapture(h.pointerId),is(!1);const l=a.current;if(!l)return;const{index:c,span:u,from:p}=l;d(void 0),!(h.type==="pointercancel"||u===p)&&i(c,u)}}}function C0({editor:e,reorder:t,resizing:n,sizing:r,place:i=b=>b,arrange:o=!0,gridBox:s,defaultSpan:a=1,rules:d,canAdd:h,selected:l,flash:c,menuIndex:u,onSelect:p,onOpenMenu:g,onRemove:x,removeBlocked:w,openAdd:y,editTile:f,renderTile:v}){const{dragging:b,preview:k,onDragStart:C,onDragMove:$,onDragOver:D,onDragEnd:j}=t,{columns:M}=d,{resize:A,startResize:N,onResize:P,endResize:L}=n,_=r?.height,V=q=>q.colspan===void 0?{...q,colspan:a}:q,T=(A!==void 0?i(e.document.tiles.map((q,U)=>U===A.index?{...q,colspan:A.span}:q),A.index):_!==void 0?i(e.document.tiles.map((q,U)=>U===_.index?E0(q,_.rows):q),_.index):k??e.document.tiles).map(V),F=id(T),O=e.document.tiles.length===0,R=(b||A!==void 0)&&!F?Rb(T,M):T.map(tf),z=q=>D0(q,yo(q),f);return m.jsxs(m.Fragment,{children:[m.jsx(pb,{sensors:dy,onDragStart:C,onDragMove:$,onDragOver:D,onDragEnd:j,children:m.jsxs(H,{ref:s,sx:{position:"relative"},children:[d.widths&&(b||A!==void 0)&&m.jsx(S0,{columns:M}),_!==void 0?m.jsx(Kc,{top:_.guideTop}):F&&(b||A!==void 0)&&m.jsx(Kc,{top:0}),m.jsx(xp,{tiles:R,columns:M,rowGapPx:pt,defaultRowspan:q=>q.kind==="tile"?Ca(q.tile):ya.query,keyOf:q=>q.kind==="gap"?nf(q.after):ke(q.tile),renderTile:q=>{if(q.kind==="gap")return m.jsx(k0,{after:q.after});const{tile:U,index:G}=q;return m.jsx(y0,{tile:U,index:G,selected:G===l,flash:ke(U)===c,menuOpen:u===G,bare:De(U),...d.insertBetween&&h&&G<e.document.tiles.length-1?{onInsertAfter:()=>y(G+1)}:{},fixed:!o,...d.widths&&o?{resizing:A?.index===G,width:{span:U.colspan??1,columns:M,max:Al(U,M),onStep:K=>{K!==(U.colspan??1)&&e.update(B=>{if(!Number.isInteger(G)||G<0)return;const X=B.tiles[G];X&&(B.tiles[G]=ls(X,K,M,a)),B.tiles=i(B.tiles,G)})}},onResizeStart:K=>N(K,G),onResizeMove:P,onResizeEnd:L}:{},...d.widths&&r?{heightEdge:{rows:U.rowspan,dragging:_?.index===G,min:Ma(U),onStart:K=>r.startHeight(K,G),onMove:r.onHeight,onEnd:r.endHeight,onStep:K=>e.update(B=>{if(!Number.isInteger(G)||G<0)return;const X=B.tiles[G];X&&(K===void 0?delete X.rowspan:X.rowspan=K,B.tiles=i(B.tiles,G))})}}:{},onSelect:()=>p(G),onOpenMenu:K=>g(K,G),onRemove:()=>x(G),...w?{removeBlocked:w}:{},children:De(U)?m.jsx(v0,{tile:U,onChange:K=>f(ke(U),B=>{De(B)&&(B.markdown=K)})}):v?v(U,z(U),"card"):m.jsx(w0,{tile:U,heading:z(U)})})}})]})}),d.insertBetween&&h&&!O&&m.jsx(Ee,{size:"small",startIcon:m.jsx(ai,{}),"aria-label":"Add tile at the end",onClick:()=>y(),sx:{alignSelf:"center"},children:"Add tile"})]})}const E0=(e,t)=>{const{rowspan:n,...r}=e;return t===void 0?r:{...r,rowspan:t}},D0=(e,t,n)=>{if(nr(e))return;const r=ke(e),i=o=>s=>n(r,a=>{de(a)&&(s===""?delete a[o]:a[o]=s)});return{title:m.jsx(sa,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:i("label")}),subtitle:m.jsx(sa,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:i("subtitle")})}},O0={x:12,y:6};function T0({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:i}){const{theme:o}=qe();return m.jsx($p,{actions:n,title:m.jsx(sa,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:s=>e.update(a=>{a.title=s})}),description:m.jsx(H,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:i,onFocus:i,children:m.jsx(cd,{sx:{position:"relative",overflow:"visible",...Nf(o,{selected:r,bare:!0,ringOffset:O0})},children:m.jsx(Pf,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:s=>e.update(a=>{s.trim()===""?delete a.description:a.description=s})})})})})}const A0=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:o}=od({path:t,layout:n},i);return{size:e,saved:({size:s,structural:a,durationMs:d})=>o({type:"report.saved",tiles:s,structural:a,where:r,durationMs:d}),refused:s=>o({type:"report.save_refused",reason:s}),undone:({size:s,structural:a,durationMs:d})=>o({type:"report.save_undone",tiles:s,structural:a,where:r,durationMs:d}),undoRefused:s=>o({type:"report.save_undo_refused",reason:s})}};function R0(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:o,saveTarget:s,canUndo:a,canRedo:d,add:{filterUnavailable:h}}=t,l=t.save!==void 0,c=t.add.tile!==void 0,u=t.add.text!==void 0,p=t.add.filter!==void 0,g=t.exit!==void 0,x=t.done!==void 0,w=t.discard!==void 0,{draftKeptAt:y}=t,f=t.restored?.savedAt,v=t.restored?.stale??!1,b=t.restored?.pending??!1,k=t.restore!==void 0,C=t.dismissRestored!==void 0,$=S.useMemo(()=>({status:o,saveTarget:s,...l?{save:i.save}:{},canUndo:a,undo:i.undo,canRedo:d,redo:i.redo,add:{...c?{tile:i.addTile}:{},...u?{text:i.addText}:{},...p?{filter:i.addFilter}:{},...h!==void 0?{filterUnavailable:h}:{}},...g?{exit:i.exit}:{},...x?{done:i.done}:{},...y!==void 0?{draftKeptAt:y}:{},...w?{discard:i.discard}:{},...f!==void 0?{restored:{savedAt:f,stale:v,pending:b}}:{},...k?{restore:i.restore}:{},...C?{dismissRestored:i.dismissRestored}:{}}),[i,o,s,l,a,d,c,u,p,h,g,x,y,w,f,v,b,k,C]);S.useEffect(()=>{r.current?.($)},[$,e!==void 0]),S.useEffect(()=>()=>r.current?.(void 0),[])}function P0({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:i,onRemove:o,fixedFilters:s,onOpenModel:a,startingValues:d,onStartingValue:h,children:l}){const c=l!=null,u=S.useMemo(()=>{const p=new Map(e.map(g=>[g.name,g]));return{stateOf:g=>{const x=s?.get(g);if(x!==void 0){const{modelPath:f}=x;return{origin:p.get(g)?.origin??"model",fixed:x.reason,...f!==void 0&&a?{openModel:()=>a(f)}:{}}}const w=p.get(g);if(!w)return;const y=t(w.name,w.type);return{origin:w.origin,...y.length>0?{problem:`Cannot filter on ${y.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:c?e.filter(g=>g.boundTiles===0&&!s?.has(g.name)).map(g=>({name:g.name,label:g.label??g.name})):[],onEdit:g=>{const x=p.get(g);x&&n(x)},onRemove:o,onAdd:r,...i!==void 0?{addDisabledReason:i}:{},...h?{startingValueOf:g=>d?.[g],setStartingValue:h}:{}}},[e,t,c,n,o,r,i,s,a,d,h]);return m.jsx(yp,{children:m.jsx(wp.Provider,{value:u,children:c?l:m.jsxs(ct,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(p=>m.jsx(kp,{name:p.name,label:p.label??p.name,unused:p.boundTiles===0},p.name)),m.jsx(Sp,{})]})})})}function I0(e,t){const n=new Map(e.tiles.map((r,i)=>[ke(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const o=n.get(ke(i));if(!o||o.index!==r||JSON.stringify(o.tile)!==JSON.stringify(i))return ke(i)}}function N0({editor:e,gridBox:t}){const[n,r]=S.useState(void 0),i=typeof n=="object"?n.tile:void 0,o=n==="description",s=S.useCallback(w=>r(y=>typeof y=="object"&&y.tile===w?y:{tile:w}),[]),a=S.useCallback(()=>r(w=>w==="description"?w:void 0),[]),d=S.useCallback(()=>r("description"),[]),h=S.useCallback(()=>r(void 0),[]),l=n!==void 0;S.useEffect(()=>{if(!l)return;const w=y=>{const f=y.target;f instanceof Element&&f!==document.documentElement&&f.closest(W0)===null&&h()};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[l,h]);const[c,u]=S.useState(void 0),p=S.useRef(!1),g=S.useRef(e.document);S.useEffect(()=>{const w=g.current;if(g.current=e.document,!p.current)return;p.current=!1;const y=I0(w,e.document);y!==void 0&&(u(y),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(f=>f.dataset.tileKey===y)?.scrollIntoView?.({block:"nearest",behavior:gp()}))},[e.document,t]),S.useEffect(()=>{if(c===void 0)return;const w=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(w)},[c]);const x=S.useMemo(()=>({...e,undo:()=>{p.current=!0,e.undo()},redo:()=>{p.current=!0,e.redo()}}),[e]);return{selected:i,descriptionSelected:o,selectTile:s,deselectTile:a,selectDescription:d,clearSelection:h,flash:c,stepEditor:x}}const W0=["[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 z0({dirty:e,saving:t,canSave:n,save:r,onExit:i}){const[o,s]=S.useState("idle"),[a,d]=S.useState(!1),h=S.useRef(r);h.current=r;const l=S.useRef(i);l.current=i;const c=S.useRef(0),u=S.useCallback(async()=>{const x=++c.current;d(!1),s("saving");try{await h.current()}catch{c.current===x&&s("idle");return}c.current===x&&d(!0)},[]);S.useEffect(()=>{if(o==="waiting"){if(t)return;e?u():(s("idle"),l.current())}else if(o==="saving"){if(!a||t)return;s("idle"),e||l.current()}},[o,a,t,e,u]);const p=S.useCallback(()=>{o==="idle"&&(e?s("asking"):l.current())},[o,e]),g=S.useCallback(()=>{o==="idle"&&(e?n?t?s("waiting"):u():s("asking"):l.current())},[o,e,n,t,u]);return{requestExit:p,saveAndExit:g,finishing:o==="saving"||o==="waiting",dialog:{open:o==="asking",canSave:n,onKeepEditing:()=>{o==="asking"&&s("idle")},onDiscard:()=>{o==="asking"&&(s("idle"),l.current())},onSaveAndExit:()=>{o==="asking"&&(t?s("waiting"):u())}}}}function L0({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:i,extraDirty:o=!1,keepsEdits:s=!1,report:a,unit:d,prepare:h,shortcuts:l}){const[c,u]=S.useState(!1),[p,g]=S.useState(!1),x=S.useRef(null),w=S.useRef(a);w.current=a;const y=e.dirty||o,f=(e.edited??e.dirty)||o,v=s?o:f;S.useEffect(()=>{i?.(e.document)},[e.document,i]),S.useLayoutEffect(()=>{n?.(f,v)},[f,v,n]);const b=S.useRef(n);b.current=n,S.useEffect(()=>()=>b.current?.(!1,!1),[]);const k=S.useRef(d);k.current=d,S.useEffect(()=>{g(!1)},[e.document]);const C=S.useCallback(()=>{u(!0),g(!1);const T=Kt(),{structural:F}=e,O=w.current.size;return e.save().then(R=>{R.ok===!0?w.current.saved({size:O,structural:F,durationMs:Kt()-T}):w.current.refused(R.reason)}).finally(()=>u(!1))},[e]),$=S.useRef(!1),D=S.useRef(!1);S.useEffect(()=>{!D.current||c||(D.current=!1,x.current?.focus())},[p,c]);const j=S.useCallback(()=>{if(!t||c||$.current||!e.canUndoSave)return;$.current=!0,u(!0);const T=Kt(),F=e.lastSave?.structural??!1,O=w.current.size;return e.undoSave().then(R=>{R.ok===!0?(D.current=!0,g(!0),w.current.undone({size:O,structural:F,durationMs:Kt()-T})):w.current.undoRefused(R.reason)}).finally(()=>{$.current=!1,u(!1)})},[t,c,e]),M=S.useCallback(()=>{if(!(!t||!e.dirty||c))return C()},[t,e,c,C]),A=S.useRef(M);A.current=M;const N=S.useCallback(()=>{const T=()=>A.current();return h?h(T):T()},[h]),P=z0({dirty:f,saving:c,canSave:!!t,save:N,onExit:()=>r?.()});qm(S.useMemo(()=>({...l,undo:e.undo,redo:e.redo,...t?{save:N}:{},paused:P.dialog.open}),[l,e,t,N,P.dialog.open]));const L=!!t&&!c&&e.canUndoSave,_=e.lastSave,V={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:y,saving:c,saveButton:x,...t?{onSave:N}:{},...r?{onExit:P.requestExit}:{}};return{saving:c,save:N,exitGuard:P,...r?{done:P.saveAndExit}:{},undoSave:j,canUndoSave:L,lastSave:_,toolbarProps:V}}const F0=1;function Wf(e,t,n){const r=[];for(const i of e??[]){const o=i.name,s=i.kind;if(typeof o=="string"){if(s==="dimension"||s==="measure"){const a=i.type?.kind;r.push({name:t+o,kind:s,...a?{type:a}:{}})}else if(s==="join"&&n>0){const a=i.schema?.fields;r.push(...Wf(a,`${t}${o}.`,n-1))}}}return r}function B0(e){const t=new Map;for(const n of zf(e))t.set(n.name,Wf(n.schema?.fields,"",F0));return t}function zf(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}function Lf(e){const t=new Map;for(const n of zf(e)){const r=new Map;for(const i of n.schema?.fields??[]){if(i.kind!=="view"||typeof i.name!="string")continue;const o=i.schema?.fields;if(!o||o.length===0)continue;const{groupBys:s,totals:a}=qp(o);r.set(i.name,{shape:{groupBys:s,totals:a},...a===o.length?{aggregateOnly:!0}:{}})}t.set(n.name,r)}return t}function Ff(e,t){const n=ds(e.annotations),r=Gp(e.annotations);return{name:e.name,...n?{description:n}:{},...r?{chart:r}:{},...t}}const Bf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function _0(e){const t=Lf(e),n=new Map;for(const r of e.sources??[]){if(!r.name)continue;const i=t.get(r.name);n.set(r.name,new Map(Bf(r).map(o=>[o.name,Ff(o,i?.get(o.name))])))}return n}function Xc(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const Zc=(e,t)=>e!==void 0&&t.has(e),Qc=e=>e.path||e.modelPath||"";function H0(e,t=new Set){const n=[],r=new Set,i=new Map,o=new Map,s=new Map;for(const a of e){const d=Qc(a);if(Zc(d,t))continue;const h=mp(a.modelInfo);o.set(a,h);for(const{name:l}of a.sources??[])l&&s.set(l,[...s.get(l)??[],d]);for(const l of h)i.set(l,[...i.get(l)??[],d])}for(const a of e){const d=Qc(a);if(Zc(d,t))continue;const h=B0(a),l=Lf(a);for(const c of a.sources??[]){const u=c.name;if(!u||!o.get(a)?.has(u)||r.has(u))continue;r.add(u);const p=(c.givens??[]).map(g=>g.name).filter(g=>typeof g=="string");n.push({name:u,modelPath:d,exporters:i.get(u)??[d],visibleIn:s.get(u)??[d],...ds(c.annotations)?{description:ds(c.annotations)}:{},views:Bf(c).map(g=>Ff(g,l.get(u)?.get(g.name))),givens:p,fields:h.get(u)??[]})}}return{sources:n}}function q0({editor:e,opened:t,givens:n,catalog:r}){const[i,o]=S.useState(void 0),s=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(()=>lg(e.document,s),[e.document,s]),d=S.useMemo(()=>new Map(e.document.sources.map(u=>[u.name,Xc(r,u.base)])),[r,e.document.sources]),h=S.useCallback(u=>d.get(u.source)??Xc(r,u.source),[d,r]),l=(u,p)=>{const g=[];for(const x of e.document.tiles){if(!de(x))continue;const w=h(x);if(!w)continue;const y=new Map(w.map(f=>[f.name,f.type]));for(const f of x.filters??[])f.given===u&&(!y.has(f.field)||!Br(p,y.get(f.field)))&&g.push(`${f.field} on ${x.label??x.name} (${e.document.sources.find(v=>v.name===x.source)?.base??x.source})`)}return g},c=S.useMemo(()=>a.filter(u=>u.origin==="model"&&u.boundTiles===0),[a]);return{filterDialog:i,setFilterDialog:o,controlList:a,fieldsFor:h,unknownFieldsOf:l,available:c,applyFilter:(u,p,g)=>{o(void 0),e.update(x=>{g&&gg(x,g),mg(x,u,p)})},dropControl:u=>{o(void 0),e.update(p=>vg(p,u))}}}function G0(e){const{splice:t,onSave:n,structural:r,clearsHistory:i}=e,[o,s]=S.useState({stack:[e.document],index:0}),[a,d]=S.useState(e.source),[h,l]=S.useState(void 0),[c,u]=S.useState(e.document),[p,g]=S.useState(e.replaces),[x,w]=S.useState(!1),y=o.stack[o.index],f=S.useRef(o);f.current=o;const v=S.useRef(!1),[b,k]=S.useState(!1),C=R=>{v.current=R,k(R)},[$,D]=S.useState(void 0),j=S.useCallback(R=>{l(void 0),s(z=>{const q=structuredClone(z.stack[z.index]);if(R(q),JSON.stringify(q)===JSON.stringify(z.stack[z.index]))return z;const U=[...z.stack.slice(0,z.index+1),q].slice(-100);return{stack:U,index:U.length-1}})},[]),M=S.useCallback(()=>{l(void 0),s(R=>R.index>0?{...R,index:R.index-1}:R)},[]),A=S.useCallback(()=>{l(void 0),s(R=>R.index<R.stack.length-1?{...R,index:R.index+1}:R)},[]),N=S.useCallback(async(R,z)=>{try{return await t(R,z)}catch(q){return{ok:!1,reason:`Could not build the file: ${q instanceof Error?q.message:String(q)}`}}},[t]),P=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};const R={source:a,saved:c,history:f.current,replacing:p,unwritten:x},z=i?.(c,y)??!1,q=r?.(c,y)??!1;C(!0);try{const U=await N(a,y);if(ha(U))return l(U.reason),{ok:!1,reason:U.reason};try{await n?.(U.source,{purpose:"save",document:y})}catch(K){const B=`Could not save: ${K instanceof Error?K.message:String(K)}`;return l(B),{ok:!1,reason:B}}d(U.source),u(y),g(void 0),w(!1);const G=z?{stack:[y],index:0}:R.history;return s(K=>K===R.history?G:z?{stack:[K.stack[K.index]],index:0}:K),D(n?{before:R,after:G,lastSave:{before:p??a,after:U.source,structural:q,clearsHistory:z}}:void 0),l(void 0),{ok:!0}}finally{C(!1)}},[y,N,n,a,c,p,x,i,r]),L=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};if(!n||$===void 0||$.after!==f.current)return{ok:!1,reason:"There is no save to undo."};const{before:R}=$;C(!0);try{await n(R.replacing??R.source,{purpose:"undo",document:R.saved})}catch(z){const q=`Could not undo the save: ${z instanceof Error?z.message:String(z)}`;return l(q),{ok:!1,reason:q}}finally{C(!1)}return d(R.source),u(R.saved),g(R.replacing),w(R.unwritten||R.replacing!==void 0),s(z=>z===$.after?R.history:z),D(void 0),l(void 0),{ok:!0}},[n,$]),_=S.useMemo(()=>x||JSON.stringify(y)!==JSON.stringify(c),[y,c,x]),V=S.useMemo(()=>r?.(c,y)??!1,[y,c,r]),T=S.useMemo(()=>i?.(c,y)??!1,[y,c,i]),F=$!==void 0&&$.after===o,O=S.useCallback(async()=>{const R=await N(a,y);return ha(R)?{ok:!1,reason:R.reason}:{ok:!0,source:R.source}},[y,N,a]);return{document:y,saved:c,source:a,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:_,edited:_,...h===void 0?{}:{error:h},update:j,undo:M,redo:A,save:P,preview:O,structural:V,clearsHistory:T,canUndoSave:F&&!b&&n!==void 0,...F?{lastSave:$.lastSave}:{},undoSave:L}}const V0=(e,t)=>{const n=new Set(e.tiles.map(fa)),r=new Set(t.tiles.map(fa));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function U0(e){const{visibleSources:t,...n}=e,r=S.useCallback((i,o)=>m0(i,o,t?{visibleSources:t}:{}),[t]);return G0({...n,splice:r,structural:V0})}function K0({editorDirty:e}){const[t,n]=S.useState(!1),r=S.useRef(void 0),i=S.useRef(void 0),o=S.useMemo(()=>({setDirty:n,commitRef:r}),[]),s=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:o,prepare:s}}function Y0({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:i,deselectTile:o}){const[s,a]=S.useState(void 0),[d,h]=S.useState(!1),[l,c]=S.useState(void 0),u=f=>{c(f),h(!0)},p=()=>h(!1),g=f=>{h(!1),e.update(v=>{Qm(v,f,{modelPath:n,textHeld:r,widths:t.widths,insertAt:l}),t.widths&&(v.tiles=ql(v.tiles,l??v.tiles.length-1,t.columns))}),i(l??e.document.tiles.length)},x=()=>y(l),w=()=>y(void 0),y=f=>{h(!1),e.update(v=>{const b=new Set(v.tiles.filter(De).map(C=>C.name));let k=1;for(;b.has(`text_${k}`);)k++;v.tiles.splice(f??v.tiles.length,0,{kind:"text",name:`text_${k}`,markdown:"",...t.widths?{colspan:t.columns}:{}}),t.widths&&(v.tiles=ql(v.tiles,f??v.tiles.length-1,t.columns))}),i(f??e.document.tiles.length)};return{menu:s,setMenu:a,addingTile:d,openAdd:u,closeAdd:p,addTile:g,addText:x,appendText:w,editTile:(f,v)=>e.update(b=>{const k=b.tiles.find(C=>ke(C)===f);k&&v(k)}),removeTile:f=>{a(void 0),o(),e.update(v=>{v.tiles.splice(f,1)})},duplicate:f=>{a(void 0);const v=e.document.tiles[f],b=v&&de(v)&&Xi(v)===void 0?f+1:void 0;e.update(k=>{Jm(k,f)}),b!==void 0&&i(b)}}}var X0=Object.defineProperty,Z0=Object.defineProperties,Q0=Object.getOwnPropertyDescriptors,Jc=Object.getOwnPropertySymbols,J0=Object.prototype.hasOwnProperty,ew=Object.prototype.propertyIsEnumerable,ed=(e,t,n)=>t in e?X0(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tn=(e,t)=>{for(var n in t||(t={}))J0.call(t,n)&&ed(e,n,t[n]);if(Jc)for(var n of Jc(t))ew.call(t,n)&&ed(e,n,t[n]);return e},An=(e,t)=>Z0(e,Q0(t));function tw(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Ti(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function os(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function nw(e,t,n){var r,i;const{source:o,target:s,canceled:a}=t.operation;if(!o||!s||a)return"preventDefault"in t&&t.preventDefault(),e;const d=(f,v)=>f===v||f!==null&&typeof f=="object"&&"id"in f&&f.id===v;if(Array.isArray(e)){const f=e.findIndex(b=>d(b,o.id)),v=e.findIndex(b=>d(b,s.id));if(f===-1||v===-1){if(os(o)){const b=o.initialIndex,k=o.index;return b===k||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,k)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==f)return n(e,f,b)}return n(e,f,v)}const h=Object.entries(e);let l=-1,c,u=-1,p;for(const[f,v]of h)if(l===-1&&(l=v.findIndex(b=>d(b,o.id)),l!==-1&&(c=f)),u===-1&&(u=v.findIndex(b=>d(b,s.id)),u!==-1&&(p=f)),l!==-1&&u!==-1)break;if(l===-1&&os(o)){const f=o.initialGroup==null?void 0:Ti(e,o.initialGroup),v=o.initialIndex,b=o.group==null?void 0:Ti(e,o.group),k=o.index;if(f==null||b==null||f===b&&v===k)return"preventDefault"in t&&t.preventDefault(),e;if(f===b)return An(Tn({},e),{[f]:n(e[f],v,k)});const C=e[f][v];return An(Tn({},e),{[f]:[...e[f].slice(0,v),...e[f].slice(v+1)],[b]:[...e[b].slice(0,k),C,...e[b].slice(k)]})}if(!o.manager)return e;const{dragOperation:g}=o.manager,x=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(p==null){const f=Ti(e,s.id);if(f!=null){const v=s.shape&&x.y>s.shape.center.y?e[f].length:0;p=f,u=v}}if(c==null||p==null||c===p&&l===u){if(c!=null&&c===p&&l===u&&os(o)){const f=o.group==null?void 0:Ti(e,o.group),v=o.group!=null&&f!==c,b=o.index!==l;if(v||b){const k=o.group==null?c:f;if(k!=null){if(c===k)return An(Tn({},e),{[c]:n(e[c],l,o.index)});const C=e[c][l];return An(Tn({},e),{[c]:[...e[c].slice(0,l),...e[c].slice(l+1)],[k]:[...e[k].slice(0,o.index),C,...e[k].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===p)return An(Tn({},e),{[c]:n(e[c],l,u)});const w=s.shape&&Math.round(x.y)>Math.round(s.shape.center.y)?1:0,y=e[c][l];return An(Tn({},e),{[c]:[...e[c].slice(0,l),...e[c].slice(l+1)],[p]:[...e[p].slice(0,u+w),y,...e[p].slice(u+w)]})}function rw(e,t){return nw(e,t,tw)}function iw(e){const t=e.getBoundingClientRect(),n=new Map;for(const r of e.querySelectorAll("[data-tile-key]")){const i=r.dataset.tileKey;if(!i)continue;const o=r.getBoundingClientRect();n.set(i,{top:o.top-t.top,left:o.left-t.left,width:o.width,height:o.height})}return n}function ow({tiles:e,commit:t,onLanded:n,placement:r}){const[i,o]=S.useState(void 0),s=S.useRef(void 0),[a,d]=S.useState(!1),h=S.useRef(void 0);return{dragging:a,preview:i,onDragStart:l=>{d(!0),s.current=e;const c=r?.gridBox.current,u=l?.operation.source?.id;if(!r||!c)return;const p=e.findIndex(b=>ke(b)===u),g=iw(c),x=g.get(String(u));if(p<0||!x)return;const w=Zm(e,e.map(b=>g.get(ke(b))),r.columns,Hl(c.getBoundingClientRect().width,r.columns)),y=c.getBoundingClientRect(),f=l?.operation.position?.current,v=f?{x:f.x-(y.left+x.left),y:f.y-(y.top+x.top)}:{x:0,y:0};h.current={base:w,index:p,from:x,grab:v},s.current=w,o(w)},onDragMove:l=>{const c=h.current,u=r?.gridBox.current;if(!c||!r||!u)return;const p=u.getBoundingClientRect(),g=l.operation.position.current,x=l.to??(l.by?{x:g.x+l.by.x,y:g.y+l.by.y}:g),w=c.base[c.index],y=Od(x.x-c.grab.x-p.left,x.y-c.grab.y-p.top,w.colspan??1,r.columns,Hl(u.getBoundingClientRect().width,r.columns)),f=s.current?.[c.index];if(f?.row===y.row&&f.col===y.col)return;const v=Xm(c.base,c.index,y,r.columns);s.current=v,o(v)},onDragOver:l=>{if(h.current){l.preventDefault();return}const{source:c,target:u}=l.operation;if(!c||!u)return;const p=s.current??e;let g;if(u.type===pf){const{after:x}=u.data,w=p.findIndex(f=>ke(f)===c.id);if(w<0||x===c.id)return;const y=p.filter((f,v)=>v!==w).findIndex(f=>ke(f)===x)+1;g=Ab(p,w,y)}else{const x=p.map(ke),w=rw(x,l);if(w.every((f,v)=>f===x[v]))return;const y=new Map(p.map(f=>[ke(f),f]));g=Tb(w.map(f=>y.get(f)),e.map(f=>f.break??!1))}s.current=g,o(g)},onDragEnd:l=>{d(!1);const c=h.current,u=c!==void 0;h.current=void 0;const p=s.current,g=c!==void 0&&p!==void 0&&p[c.index]?.row===c.base[c.index]?.row&&p[c.index]?.col===c.base[c.index]?.col,x=u&&p?Ym(p):p;if(s.current=void 0,o(void 0),l.canceled||!x||g)return;t(x);const w=x.findIndex(y=>ke(y)===l.operation.source?.id);w>=0&&n(w)}}}const ss=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"row-resize":""};function sw({tiles:e,gridBox:t,onStart:n,commit:r}){const[i,o]=S.useState(void 0),s=S.useRef(void 0),a=S.useRef(void 0),d=l=>{s.current=l,o(l)};S.useEffect(()=>()=>ss(!1),[]);const h=l=>{const c=new Set(e.filter(g=>g.rowspan===void 0).map(ke)),u=e[l.index];let p=a.current;for(const g of t.current?.querySelectorAll("[data-tile-key]")??[]){const x=g.dataset.tileKey;if(!x||!c.has(x)||u&&x===ke(u))continue;const w=g.getBoundingClientRect();Math.abs(w.top-l.top)>1||(p=Math.max(p??0,w.height))}return p};return{height:i,startHeight:(l,c)=>{const u=l.currentTarget.parentElement?.getBoundingClientRect(),p=t.current?.getBoundingClientRect();if(!u||!p)return;l.stopPropagation(),l.preventDefault(),l.currentTarget.setPointerCapture(l.pointerId),ss(!0),n(c);const g=e[c]?.rowspan;a.current=g===void 0?u.height:void 0,d({index:c,rows:g,from:g,top:u.top,guideTop:u.top-p.top})},onHeight:l=>{const c=s.current;if(!c)return;const u=l.clientY-c.top,p=e[c.index],g=vp(u,p?Ma(p):void 0),x=h(c),w=x!==void 0&&Math.abs(u-x)<Math.abs(u-fd(g))?void 0:g;w!==c.rows&&d({...c,rows:w})},endHeight:l=>{l.currentTarget.hasPointerCapture(l.pointerId)&&l.currentTarget.releasePointerCapture(l.pointerId),ss(!1);const c=s.current;if(!c)return;const{index:u,rows:p,from:g}=c;d(void 0),a.current=void 0,!(l.type==="pointercancel"||p===g)&&r(u,p)}}}function _f({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,onExit:o,renderTile:s,renderViewPreview:a,controls:d,givens:h,catalog:l,toolbar:c,dashboards:u,onEvent:p,savesTo:g="package",saveLabel:x,replaces:w,modelPath:y,visibleSources:f,addFilterDisabledReason:v,fixedFilters:b,onOpenModel:k,takenGivenNames:C,onControlsChange:$,draftKey:D}){const j=U0({source:e,document:t,...n?{onSave:n}:{},...w!==void 0?{replaces:w}:{},...f?{visibleSources:f}:{}}),M=np(D,j,e),A=S.useRef(null),{selected:N,descriptionSelected:P,selectTile:L,deselectTile:_,selectDescription:V,clearSelection:T,flash:F,stepEditor:O}=N0({editor:j,gridBox:A}),R=rd(j.document.layout,j.document.columns),{columns:z}=R,q=y?.split("/").at(-1)?.replace(/\.malloy$/,""),U=nd("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),G=!R.widths||U,K=ow({tiles:j.document.tiles,commit:te=>j.update(ae=>{ae.tiles=te}),onLanded:L,...R.widths&&U?{placement:{columns:z,gridBox:A}}:{}}),B=R.widths,X=S.useCallback((te,ae)=>B&&id(te)?bo(te,z,ae):te,[B,z]),{dragging:ee}=K,oe=rp(A,z),ie=S.useMemo(()=>j.document.tiles.map(te=>te.colspan===void 0?{...te,colspan:oe}:te),[j.document.tiles,oe]),Oe=M0({tiles:ie,columns:z,gridBox:A,onStart:L,commit:(te,ae)=>j.update(Q=>{const he=Q.tiles[te];he&&(Q.tiles[te]=ls(he,ae,z,oe)),Q.tiles=X(Q.tiles,te)})}),We=sw({tiles:j.document.tiles,gridBox:A,onStart:L,commit:(te,ae)=>j.update(Q=>{const he=Q.tiles[te];he&&(ae===void 0?delete he.rowspan:he.rowspan=ae,Q.tiles=X(Q.tiles,te))})}),J=Y0({editor:j,rules:R,modelPath:y,textHeld:f!==void 0,selectTile:L,deselectTile:_}),{menu:be,addingTile:ve,openAdd:se}=J,Te=q0({editor:j,opened:t,givens:h,catalog:l}),{filterDialog:Ge,setFilterDialog:Ae}=Te,[Ye,Xe]=S.useState(void 0),{draftDirty:E,openDraft:W,prepare:Y}=K0({editorDirty:j.dirty}),Z=S.useMemo(()=>({escape:()=>{!be&&!Ge&&!ve&&Ye===void 0&&T()},nudge:te=>{if(ee||N===void 0||!R.widths||!G)return;const ae=j.document.tiles[N];if(!ae)return;const Q=ip(ae.colspan??oe,te,Al(ae,z));Q!==(ae.colspan??oe)&&j.update(he=>{he.tiles[N]=ls(he.tiles[N],Q,z,oe),he.tiles=X(he.tiles,N)})}}),[oe,G,X,j,be,Ge,ve,Ye,T,N,z,R,ee]),fe=L0({editor:O,extraDirty:E,keepsEdits:D!==void 0&&M.keeping,prepare:Y,unit:{name:"tile",count:te=>te.tiles.length},onSave:n,onDirtyChange:i,onExit:o,onChange:r,shortcuts:Z,report:A0({size:j.document.tiles.length,path:y??"",layout:j.document.layout,savesTo:g,onEvent:p})}),ze=j.document.tiles.length===0,{toolbarProps:Be}=fe,I=M.restored,ye={status:fe.saving?"saving":Be.dirty?"unsaved":"saved",saveTarget:x??ys[g],...M.keptAt!==void 0?{draftKeptAt:M.keptAt}:{},...(Be.dirty||I?.pending)&&D!==void 0?{discard:M.discard}:{},...I?{restored:I}:{},...I&&!I.pending?{dismissRestored:M.dismissRestored}:{}};R0($,{...ye,...Be.onSave?{save:Be.onSave}:{},canUndo:Be.canUndo,undo:Be.onUndo,canRedo:Be.canRedo,redo:Be.onRedo,add:{...l?{tile:()=>J.openAdd()}:{},text:J.appendText,...v!==void 0?{filterUnavailable:v}:ze?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>Ae({})}},...Be.onExit?{exit:Be.onExit}:{},...fe.done?{done:fe.done}:{},...I?.pending?{restore:M.restoreOffered}:{}});const et=$?void 0:m.jsx(Gm,{...fe.toolbarProps,...c?{actions:c}:{},...l?{onAddTile:()=>se()}:{},savesTo:g,...x?{saveLabel:x}:{},...D!==void 0&&Be.onSave?{saveStatus:ye}:{}});return m.jsx(Jh.Provider,{value:W,children:m.jsx(ct,{className:Qe.builder,"data-saves-to":g,sx:{gap:0,mx:`-${rs}px`},children:m.jsxs(op,{layout:R.layout,sx:{px:`${rs}px`,pb:`${rs}px`},header:m.jsx(T0,{editor:j,documentSlug:q,actions:et,descriptionSelected:P,selectDescription:V}),controls:ze?void 0:m.jsx(P0,{controls:Te.controlList,unknownFieldsOf:Te.unknownFieldsOf,onEdit:te=>Ae({control:te}),onAdd:()=>Ae({}),...v?{addDisabledReason:v}:{},onRemove:Te.dropControl,...b?{fixedFilters:b}:{},...k?{onOpenModel:k}:{},...j.document.startingGivens?{startingValues:j.document.startingGivens}:{},onStartingValue:(te,ae)=>j.update(Q=>{const he={...Q.startingGivens??{}};ae===void 0?delete he[te]:he[te]=ae,Object.keys(he).length>0?Q.startingGivens=he:delete Q.startingGivens}),children:d}),children:[ze&&m.jsxs(ct,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx(me,{variant:"body2",children:"This report is not served until it has a tile."}),l&&m.jsx(Ee,{size:"small",startIcon:m.jsx(ai,{}),onClick:()=>se(),children:"Add tile"})]}),I?.pending&&m.jsx(lt,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx(Ee,{color:"inherit",size:"small",onClick:M.restoreOffered,children:"Restore them"}),m.jsx(Ee,{color:"inherit",size:"small",onClick:M.discard,children:"Discard"})]}),children:`You have unsaved edits from ${xs(I.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),j.error&&m.jsx(lt,{severity:"warning",children:j.error}),!G&&m.jsx(lt,{severity:"info",children:"This window is too narrow for the grid, so tiles stack in one column, as on a phone. Widen it to move tiles or change their width."}),m.jsx(C0,{editor:j,arrange:G,reorder:K,resizing:Oe,sizing:We,place:X,gridBox:A,defaultSpan:oe,rules:R,canAdd:!!l,selected:N,flash:F,menuIndex:be?.index,onSelect:L,onOpenMenu:(te,ae)=>{L(ae),J.setMenu({anchor:te,index:ae})},onRemove:J.removeTile,...j.document.tiles.length===1&&j.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:se,editTile:J.editTile,...s?{renderTile:s}:{}}),m.jsx(Tg,{editor:j,catalog:l,columns:z,dashboards:u,bindings:Te,tiles:J,drillSource:Ye,setDrillSource:Xe,exitDialog:fe.exitGuard.dialog,...a?{renderViewPreview:a}:{},...C?{takenGivenNames:C}:{}})]})})})}const aw=mt(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),lw=mt(m.jsx("path",{d:"M9 17H7v-7h2zm4 0h-2V7h2zm4 0h-2v-4h2zm2.5 2.1h-15V5h15zm0-16.1h-15c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"})),cw=mt(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function Pw({controls:e,onDone:t}){const n=t??e?.exit,r=nd("(max-width: 599.95px)"),{theme:i}=qe(),o=_t(i.cardBorder),s=vo(i.cardBorder,i.tileTitle),[a,d]=S.useState(null),h=e?.save!==void 0&&e.status!=="saved",l=e?.done??n,c=h&&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=x=>()=>{d(null),x?.()};return m.jsxs(ct,{direction:"row",role:"toolbar",className:Qe.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(Md,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx(Ot,{title:`Undo (${gn}Z)`,children:m.jsx("span",{children:m.jsx(Kn,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:Ui(i.ui),children:m.jsx(jd,{fontSize:"small"})})})}),m.jsx(Ot,{title:`Redo (${gn}⇧Z)`,children:m.jsx("span",{children:m.jsx(Kn,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:Ui(i.ui),children:m.jsx($d,{fontSize:"small"})})})}),p&&m.jsx(Yn,{orientation:"vertical",sx:Ki}),p&&m.jsxs(m.Fragment,{children:[m.jsx(Ee,{variant:"outlined",startIcon:m.jsx(ai,{}),endIcon:m.jsx(ga,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:x=>d(x.currentTarget),sx:{...Fr(o,s),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs(Lr,{anchorEl:a,open:a!==null,onClose:()=>d(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:dw(o,i.ui)}},MenuListProps:{sx:{p:.5}},children:[u?.tile&&m.jsx(as,{icon:m.jsx(lw,{}),title:"Tile",detail:"A chart or table from the model",onClick:g(u.tile)}),u?.text&&m.jsx(as,{icon:m.jsx(cw,{}),title:"Text",detail:"Prose between the tiles",onClick:g(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(as,{icon:m.jsx(aw,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:g(u.filter)})]})]})]})]}),(l||c)&&e&&m.jsx(Yn,{orientation:"vertical",sx:Ki}),l&&m.jsx(Ot,{enterDelay:800,enterNextDelay:800,title:e?.done&&h?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx(Ee,{variant:c?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:l,sx:{...Fr(o,s,i.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&c&&m.jsx(Ot,{title:`Save (${gn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx(Ee,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...Fr(o,s,i.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const dw=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function as({icon:e,title:t,detail:n,disabled:r=!1,onClick:i}){const{theme:o}=qe(),s=o.ui;return m.jsxs(tt,{onClick:i,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:s.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:s.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${Fe}, background-color ${Fe}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:o.accent,bgcolor:`color-mix(in srgb, ${o.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx(H,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs(H,{className:"add-text",sx:{minWidth:0},children:[m.jsx(H,{sx:{...s.type.control,fontWeight:s.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx(H,{sx:{...s.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function uw(e,t,n=new Set,r=new Map){const i=[];for(const l of e.tiles){if(!de(l))continue;const c=(l.filters??[]).map(p=>p.given),u=r.get(Nt(`${l.source} -> ${l.name}`))??[];for(const p of u)(n.has(p)||c.includes(p))&&i.push(p);i.push(...c)}const o=new Set(i),s=t.flatMap(l=>l.name!==void 0&&n.has(l.name)&&!o.has(l.name)?[l.name]:[]),a=new Map((e.localGivens??[]).map(l=>[l.name,l])),d=new Map(t.flatMap(l=>l.name===void 0?[]:[[l.name,l]])),h=[];for(const l of new Set([...s,...i])){const c=a.get(l),u=c?xm(c):d.get(l);u&&h.push(u)}return h}function hw(e,t,n){const r=new Map;for(const o of t.tiles)de(o)&&r.set(Nt(ht(o)),new Set((o.filters??[]).map(s=>s.given)));const i=new Set;for(const o of e.tiles){if(!de(o))continue;const s=Nt(ht(o)),a=r.get(s);for(const d of n.get(s)??[])a?.has(d)||i.add(d)}return i}function fw(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function pw(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function Nt(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function mw(e,t,n,r){const i=new Set(t.sources.map(s=>s.name)),o=new Set(e.sources.map(s=>s.name).filter(s=>!i.has(s)));return o.size===0?void 0:{sources:o,modelOf:s=>{if(r)return;const a=e.imports.find(h=>h.kind==="names"&&h.names.includes(s));if(a===void 0)return;const d=bm(a.from,n);return ym(t,s,d,n)?void 0:d}}}function gw(e,t,n){if(!n||t.declaration.kind!=="reference")return;let r=t.source,i=t.declaration.from;if(r===void 0||!n.sources.has(r))return;const o=e.tiles.length+e.sources.length;for(let s=0;s<=o;s++){if(!n.sources.has(r)){const h=n.modelOf?.(r);return{source:r,view:i,...h?{modelPath:h}:{}}}const a=e.sources.find(h=>h.name===r);if(!a||a.scopedBy?.length)return;const d=e.tiles.find(h=>de(h)&&h.source===r&&h.name===i);if(!d)r=a.base;else if(d.declaration.kind==="reference")i=d.declaration.from;else return}}function vw(e,t,n,r=new Map,i,o){if(nr(t))return{expression:ht(t),givenNames:void 0,reads:i&&[...i]};const s=gw(e,t,o),a=s?.source??t.source,d=s?.view??(t.declaration.kind==="reference"?t.declaration.from:t.name),h=s?.modelPath!==void 0?new Set:n,l=new Map((e.localGivens??[]).map(k=>[k.name,k.type])),c=new Map((e.localGivens??[]).map(k=>[k.name,k.default])),u=e.sources.find(k=>k.name===a)?.scopedBy??[],p=new Set([...u,...i??[]].filter(k=>h.has(k))),g=new Set([...u,...i??[]]),x=[];for(const k of t.filters??[]){const C=`where: ${Sa(k.field)} ${k.op??"~"}`;if(h.has(k.given)){p.add(k.given),g.add(k.given),x.push(`${C} $${k.given}`);continue}if(!l.has(k.given))continue;g.add(k.given);const $=wm(r.get(k.given),l.get(k.given))??fw(c.get(k.given));$!==void 0&&x.push(`${C} ${$}`)}const w=x.join(", "),y=t.chart,f=y==="none"||$a(y)?Hn(y,t.chartCarried):y==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
-
`):y==="default"&&pw(t.declaration)?km():void 0,v=t.color!==void 0?yd(t.color):t.declaration.kind!=="reference"&&!t.ownPalette?Sm:void 0,b=[f,v].filter(Boolean).join(`
|
|
144
|
-
`)||void 0;return{...b?{annotation:b}:{},...s?.modelPath!==void 0?{modelPath:s.modelPath}:{},expression:`${a} -> ${d}`+(w?` + { ${w} }`:""),givenNames:Array.from(p),reads:i||g.size>0?Array.from(g):void 0}}function xw({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:i,reportsSettled:o}){const{apiClients:s,server:a}=va(),{data:d}=xa({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await s.models.listModels(e,t,n)).data.flatMap(g=>g.path&&!g.error?[g.path]:[])}),h=S.useMemo(()=>new Set([r,...i.flatMap(g=>g.path?[g.path]:[])]),[i,r]),l=S.useMemo(()=>o?(d??[]).filter(g=>!h.has(g)):[],[d,h,o]),c=vm({queries:l.map(g=>({queryKey:["report-editor-model",e,t,g,n,a],queryFn:async()=>(await s.models.getModel(e,t,g,n)).data,retry:!1}))}),u=d!==void 0&&o&&c.every(g=>g.isSuccess||g.isError),p=c.map(g=>g.dataUpdatedAt).join();return S.useMemo(()=>u?H0(c.flatMap((g,x)=>g.data?[{...g.data,path:l[x]}]:[]),h):void 0,[u,l,p,h])}const bw={};function yw({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:i,queryVersionId:o,opened:s,replaces:a,onSave:d,onDirtyChange:h,onExit:l,onOpenModel:c,onControlsChange:u,draftKey:p,onEvent:g,savesTo:x,saveLabel:w,note:y,fileModel:f}){const{apiClients:v}=va(),[b,k]=S.useState(s.document.tiles.length>0);S.useEffect(()=>k(s.document.tiles.length>0),[s.generation,s.document]);const{data:C,isSuccess:$,isError:D}=xa({...Ap(v,{environmentName:t,packageName:n,path:r,versionId:o},Rp),enabled:b&&!e}),j=e?.modelPath??r,M=kw(s.source,e?.compileSource),A=Pp({environmentName:t,packageName:n,modelPath:j,source:M.text??s.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&M.text!==void 0}),N=A.data?.document,P=e?A.isSuccess?N?.manifest??bw:void 0:C,L=e?A.isSuccess:$,_=e?A.isError||M.problem!==void 0:D,V=e?Ip(N?.cells):void 0,T=(A.data?.result.problems??[]).filter(I=>I.severity==="error"),F=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),O=e?.givens,R=S.useMemo(()=>new Set((P?.tiles??[]).flatMap(I=>I.restricted&&I.query?[Nt(I.query)]:[])),[P]),{reports:z,settled:q}=Np(t,n,o),U=S.useMemo(()=>z.map(I=>I.path).filter(I=>!!I&&I!==r&&I.endsWith(".malloy")).map(I=>I.replace(/\.malloy$/,"")),[z,r]),G=xw({environmentName:t,packageName:n,...o!==void 0?{versionId:o}:{},modelPath:r,reports:z,reportsSettled:q}),K=S.useMemo(()=>e?(G?.sources??[]).filter(I=>(I.visibleIn??I.exporters??[I.modelPath]).includes(j)).map(I=>I.name):void 0,[G,e,j]),B=S.useMemo(()=>f?_0(f):void 0,[f]),X=S.useMemo(()=>{const I=G&&K?{sources:G.sources.filter(ye=>K.includes(ye.name))}:G;return I&&B?{...I,documentViews:B}:I},[G,K,B]),[ee,oe]=S.useState(s.document);S.useEffect(()=>oe(s.document),[s.document]);const ie=S.useMemo(()=>d&&(async(I,ye)=>{await d(I,ye.document.layout),x==="package"&&k(ye.document.tiles.length>0)}),[d,x]),Oe=S.useMemo(()=>(P?.givens??[]).filter(I=>!(e&&I.secure===!0)&&!(I.name!==void 0&&F.has(I.name))),[P,F,e]),We=S.useMemo(()=>new Set([...Oe.map(I=>I.name).filter(I=>I!==void 0),...Object.keys(O??{})]),[Oe,O]),J=S.useMemo(()=>new Map((P?.tiles??[]).flatMap(I=>I.kind!=="text"&&I.query&&I.givenNames?[[Nt(I.query),I.givenNames]]:[])),[P]),be=S.useMemo(()=>new Map((P?.tiles??[]).flatMap(I=>I.kind!=="text"&&I.query&&I.label?[[Nt(I.query),I.label]]:[])),[P]),ve=S.useMemo(()=>hw(ee,s.document,J),[ee,s.document,J]),se=S.useMemo(()=>uw(ee,Oe,ve,J),[ee,Oe,ve,J]),Te=S.useMemo(()=>{const I=new Set(ee.tiles.flatMap(Q=>de(Q)?(Q.filters??[]).map(he=>he.given):[])),ye=new Set((ee.localGivens??[]).map(Q=>Q.name)),et=[...new Set(ee.imports.map(Q=>Q.from))],te=et.length===1?Sw(r,et[0]):et.length===0&&e?e.modelPath:void 0,ae=Q=>{const he=ee.sources.filter(St=>St.scopedBy?.includes(Q)).map(St=>St.name);return he.length>0?{reason:`Applied to every tile on ${he.join(", ")} by this report's own source. Edit the file to change it.`}:ye.has(Q)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:te!==void 0?{reason:`Set in the model ${te}. Edit the model to change it.`,modelPath:te}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...ve].filter(Q=>!I.has(Q)).map(Q=>[Q,ae(Q)]))},[ee,ve,e,r]),{declaredTypes:Ge,applied:Ae,panel:Ye}=Wp({specs:se,loaded:L,startingValues:P?.startingGivens,documentKey:`${t}/${n}/${i??""}/${r}/edit`,autorun:P?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?j:P?.path,versionId:o,documentName:r,...V!==void 0?{preamble:V}:{},...O?{hostGivens:O}:{}}),Xe=S.useMemo(()=>zp(se,Ae,O),[se,Ae,O]),E=S.useMemo(()=>Object.fromEntries(Object.entries(O??{}).filter(([I])=>!Ge.has(I))),[O,Ge]),W=!b||L||_,Y=e!==void 0&&(M.problem!==void 0||A.isError||T.length>0),Z=S.useMemo(()=>new Map(s.document.tiles.map(I=>[ke(I),I])),[s.document]),fe=S.useMemo(()=>mw(ee,s.document,r,!!e),[ee,s.document,r,e]),ze=S.useMemo(()=>function(I,ye,et="card"){const te=(nr(I)?be.get(Nt(ht(I))):void 0)??yo(I);if(Y)return m.jsxs(us,{chrome:et,children:[m.jsx(hs,{title:ye?.title??te,subtitle:ye?ye.subtitle:I.subtitle}),m.jsx(me,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!W)return m.jsxs(us,{chrome:et,children:[m.jsx(hs,{title:ye?.title??te,subtitle:ye?ye.subtitle:I.subtitle}),m.jsx(cs,{text:"Running…"})]});const ae=J.get(Nt(ht(I))),Q=V===void 0&&ae!==void 0&&ww(Z.get(ke(I)),I)?{expression:ht(I),givenNames:[...ae],reads:[...ae]}:vw(ee,I,We,Ae,ae,fe),he=rd(ee.layout,ee.columns);return m.jsx(Nl,{environmentName:t,packageName:n,versionId:o,modelPath:Q.modelPath??j,...V!==void 0&&Q.modelPath===void 0?{preamble:V}:{},...R.has(Nt(ht(I)))?{restricted:!0}:{},tile:Q.expression,...Q.annotation?{annotation:Q.annotation}:{},label:te,chrome:et,subtitle:I.subtitle,...ye?{heading:ye}:{},borderless:I.borderless,givens:Ae,hostGivens:E,declaredTypes:Ge,givenNames:Q.givenNames,...(()=>{const St=Fp(Xe,Q.reads??Q.givenNames);return St.length>0?{waitingFor:Bp(St)}:{}})(),ignoredFilters:Lp(Q.reads,se),height:I.rowspan!==void 0||I.row!==void 0?fd(I.rowspan??ya.query):he.tileMaxHeight,tableMaxHeight:he.tableMaxHeight})},[ee,Z,W,Y,Xe,We,J,be,t,n,o,j,V,fe,R,Ae,E,Ge,se]),Be=S.useMemo(()=>function(I){return m.jsx(Nl,{environmentName:t,packageName:n,versionId:o,modelPath:I.modelPath,tile:`${I.base} -> ${I.view}`,...I.chart?{annotation:Hn(I.chart,I.chartCarried)}:{},label:I.label,borderless:!0,givens:Ae,hostGivens:E,declaredTypes:Ge,givenNames:I.givens,height:200})},[t,n,o,Ae,E,Ge]);return m.jsxs(ct,{sx:{gap:1},children:[e&&T.length>0&&m.jsxs(lt,{severity:"error",children:["The server could not compile this document:"," ",T.map(I=>I.message).join("; ")]}),Xe.length>0&&!Y&&m.jsx(lt,{severity:"info",children:_p(Xe)}),e&&M.problem!==void 0&&m.jsxs(lt,{severity:"error",children:["This document could not be prepared to compile:"," ",M.problem]}),e&&A.isError&&m.jsxs(lt,{severity:"error",children:["The server could not compile this document:"," ",A.error?.message]}),m.jsx(_f,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:s.source,document:s.document,fixedFilters:Te,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:ze,renderViewPreview:Be,givens:se.filter(I=>I.name!==void 0).map(I=>({name:I.name,...I.label?{label:I.label}:{},...I.type?{type:I.type}:{},...I.suggest?.dimension?{field:I.suggest.dimension}:{}})),onChange:oe,onDirtyChange:h,...l?{onExit:l}:{},...c?{onOpenModel:c}:{},...u?{onControlsChange:u}:{},...p!==void 0?{draftKey:p}:{},...X?{catalog:X}:{},dashboards:U,...g?{onEvent:g}:{},controls:L?m.jsx(Hp,{...Ye,layout:"bar"}):void 0,...ie?{onSave:ie}:{},savesTo:x,...w?{saveLabel:w}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:K}:{}}),m.jsx(H,{sx:{px:.5},children:m.jsx(me,{variant:"caption",sx:{opacity:.7},children:y})})]})}function ww(e,t){return e!==void 0&&JSON.stringify(td(e))===JSON.stringify(td(t))}function td(e){const{label:t,subtitle:n,colspan:r,break:i,rowspan:o,row:s,col:a,borderless:d,...h}=e;return h}function kw(e,t){const n=S.useRef(t);n.current=t;const r=t!==void 0,[i,o]=S.useState();return S.useEffect(()=>{if(!r)return;let s=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{s&&o({from:e,text:a})},a=>{s&&o({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{s=!1}},[e,r]),r?i?.from!==e?{}:i.problem!==void 0?{problem:i.problem}:{text:i.text}:{text:e}}function Sw(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 $w({storage:e,layout:t,notebook:n,environmentName:r,packageName:i,modelPath:o}){const[s,a]=S.useState(void 0),[d,h]=S.useState(void 0),[l,c]=S.useState(e===void 0),[u,p]=S.useState(!1),[g,x]=S.useState(void 0);return S.useEffect(()=>{if(!e)return;let w=!1;return x(void 0),(async()=>{try{const y=Mp(await e.listWorkspaces(!1));if(w)return;if(a(y),y!==void 0&&(!n||y.authoritative)){const f=await e.getDocument(dd(t,y.name,r,i,o)).catch(v=>{if(!ud(v))throw v});if(w)return;h(f),p(f!==void 0)}}catch(y){if(w)return;x(hd(y))}w||c(!0)})(),()=>{w=!0}},[e,t,n,r,i,o]),{workspace:s,draft:d,setDraft:h,draftChecked:l,offered:u,setOffered:p,readFailure:g}}const jw=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Mw(e){const t=await ua(e);return da(t)?{ok:!1,reason:jw(t.reason,t.line)}:{ok:!0,document:t.document}}const Cw="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Ew="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Dw({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:i,fetchedAt:o,packageSettled:s,modelPath:a,layout:d,notebook:h,noun:l,legacyFormat:c,textHeld:u,startedAt:p,onEventRef:g}){const x=S.useRef({path:a,layout:d});x.current={path:a,layout:d};const w=S.useRef((J,be)=>{try{g.current?.(Cp(J,{...x.current,...be?{layout:be}:{}}))}catch{}}),y=e?.authoritative===!0,f=y&&r!==void 0,[v,b]=S.useState(void 0),k=(y||v===!0)&&t!==void 0,[C,$]=S.useState(void 0),[D,j]=S.useState(c?Cw:void 0),M=S.useRef(void 0),A=S.useRef(void 0),[N,P]=S.useState(void 0),L=S.useRef(o);L.current=o;const _=N!==void 0&&N.onFetch===o?N.text:i,V=S.useRef(_);V.current=_;const T=k?t:_,[F,O]=S.useState(!1),[R,z]=S.useState(void 0),[q,U]=S.useState(void 0),G=T!==void 0&&T!==q,K=C?.source,B=G&&(F||!y&&t!==void 0&&K===t&&t!==_)&&K!==void 0&&T!==R,X=B?K:G?T:K??T,ee=B?T:void 0,oe=S.useRef(K);oe.current=K;const ie=S.useRef(T);ie.current=T;const Oe=S.useRef("package");Oe.current=k?y?"record":"draft":"package",S.useEffect(()=>{if(X===void 0||!n||f||X===oe.current)return;let J=!1;const be=V.current,ve=ie.current;return Mw(X).then(se=>{if(!J){if(se.ok===!1){j(se.reason),w.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}j(void 0),M.current=void 0,A.current=be,P(void 0),z(void 0),U(ve),$(Te=>({source:X,document:se.document,...be!==void 0?{packageText:be}:{},generation:(Te?.generation??0)+1})),w.current({type:"report.opened",surface:"edit",from:Oe.current,tiles:se.document.tiles.length,durationMs:Kt()-p.current},se.document.layout)}}).catch(se=>{if(J)return;const Te=`Could not read the ${l}: ${se instanceof Error?se.message:String(se)}`;j(Te),w.current({type:"report.load_failed",surface:"edit",category:sd(se)})}),()=>{J=!0}},[X,a,n,f,h,l,u,p]),S.useEffect(()=>{c&&w.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[c]),S.useEffect(()=>{!u||!n||C||r!==void 0||(y?t===void 0&&j("the host's storage has no document at this location."):j("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,C,r,y,t]);const We=h&&!u&&!C&&n&&!k&&s&&i===void 0;return S.useEffect(()=>{We&&(j(Ew),w.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[We]),{authoritative:y,blockedOnRecord:f,resume:v,setResume:b,fromDraft:k,opened:C,setOpened:$,openError:D,savedHashRef:M,packageBaseRef:A,setWrote:P,fetchedAtRef:L,setDirty:O,setSeen:U,held:ee,choose:J=>{p.current=Kt(),z(J?t:_),b(J)},acceptHeld:()=>{p.current=Kt(),z(ee)}}}function Ow({storage:e,workspace:t,layout:n,notebook:r,environmentName:i,packageName:o,modelPath:s,versionId:a,apiClients:d,queryClient:h,mutable:l,textHeld:c,readFailure:u,authoritative:p,resume:g,setResume:x,setOpened:w,setDraft:y,setOffered:f,setSeen:v,setWrote:b,savedHashRef:k,packageBaseRef:C,fetchedAtRef:$}){const D=S.useCallback(O=>t===void 0?void 0:dd(O,t.name,i,o,s),[t,i,o,s]),j=D(n),M=S.useCallback(async(O,R=n)=>{const z=D(R);if(!e||!z)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(z,O),w(q=>q&&{...q,source:O}),y(O),(p||g===!0)&&v(O),p||x(q=>q??!1)},[e,D,n,p,g,w,y,v,x]),[A,N]=S.useState(void 0),P=S.useCallback(async O=>{const R=await Ep(k.current,C.current);if(R===void 0)throw new Error("The package file is still loading; try again.");const z=["dashboard-editor-model",i,o,s,a,r];await Dp({apiClients:d,queryClient:h,environmentName:i,packageName:o,modelPath:s,source:O,expectedHash:R,invalidateOnError:[z],afterWrite:async q=>{if(w(U=>U&&{...U,source:O}),b({text:O,onFetch:$.current}),v(O),k.current=q,N(void 0),e&&j)try{await e.deleteDocument(j),y(void 0),f(!1)}catch(U){ud(U)?(y(void 0),f(!1)):N(hd(U))}x(!1)},invalidate:[{queryKey:z,wait:!0},{queryKey:gm({environmentName:i,packageName:o,versionId:a,modelPath:s})}]}),Op(h,i,o,s)},[d,i,o,s,a,r,e,j,h,k,C,$,w,b,v,y,f,x]),L=t?.writeable===!0,_=l===!0&&!c,{savesTo:V,pinnedPackageSave:T,writer:F}=mm({authoritative:p,mutable:_,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!j&&L&&(!r||p),readFailed:u!==void 0});return{save:F==="storage"?M:F==="package"?P:void 0,savesTo:V,writer:F,pinnedPackageSave:T,takesWrites:_,supersedeFailure:A}}function Hf(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:i,onOpenModel:o,onControlsChange:s,keepDraft:a,kind:d,path:h,textSource:l,queryVersionId:c}=e,u=e.layout??(d?sp(d):"grid"),p=u==="linear",g=l!==void 0,{environmentName:x,packageName:w,versionId:y,namesBoth:f}=ap(e),v=("resourceUri"in e?e.dashboard:e.dashboardName)??lp(h)??"",b="report",{apiClients:k,mutable:C,isLoadingStatus:$,server:D}=va(),j=cp(),M=S.useRef(Kt()),A=S.useRef(t);A.current=t;const N=S.useRef(r);N.current=r;const P=dp()?.documentStorage,L=h??jp(d??"dashboard",v),_=/\.malloynb$/i.test(L)||p&&/\.malloynb$/i.test(v),V=xa({queryKey:["dashboard-editor-model",x,w,L,y,p],queryFn:()=>k.models.getModel(x,w,L,y,p?!0:void 0),enabled:f&&!_&&!g}),T=V.data?.data?.sourceText,{workspace:F,draft:O,setDraft:R,draftChecked:z,offered:q,setOffered:U,readFailure:G}=$w({storage:P,layout:u,notebook:p,environmentName:x,packageName:w,modelPath:L}),{authoritative:K,blockedOnRecord:B,resume:X,setResume:ee,fromDraft:oe,opened:ie,setOpened:Oe,openError:We,savedHashRef:J,packageBaseRef:be,setWrote:ve,fetchedAtRef:se,setDirty:Te,setSeen:Ge,held:Ae,choose:Ye,acceptHeld:Xe}=Dw({workspace:F,draft:O,draftChecked:z,readFailure:G,packageText:T,fetchedAt:V.dataUpdatedAt,packageSettled:V.isSuccess&&!V.isFetching,modelPath:L,layout:u,notebook:p,noun:b,legacyFormat:_,textHeld:g,startedAt:M,onEventRef:A}),{save:E,savesTo:W,writer:Y,pinnedPackageSave:Z,takesWrites:fe,supersedeFailure:ze}=Ow({storage:P,workspace:F,layout:u,notebook:p,environmentName:x,packageName:w,modelPath:L,versionId:y,apiClients:k,queryClient:j,mutable:C,textHeld:g,readFailure:G,authoritative:K,resume:X,setResume:ee,setOpened:Oe,setDraft:R,setOffered:U,setSeen:Ge,setWrote:ve,savedHashRef:J,packageBaseRef:be,fetchedAtRef:se}),Be=F?.name,I=S.useCallback(Sn=>{A.current?.(up(Sn,Be))},[Be]),ye=V.isError&&!ie,et=S.useRef(!1);S.useEffect(()=>{!ye||et.current||(et.current=!0,od({path:L,layout:u},A.current).emit({type:"report.load_failed",surface:"edit",category:sd(V.error)}))},[ye,V.error,L,u]);const te=S.useCallback((Sn,Po)=>{Te(Sn),N.current?.(Po)},[Te]),ae=!l&&V.data?.data&&T!==void 0&&ie?.source===T?V.data.data:void 0,Q=a?Tp({server:D,environmentName:x,packageName:w,versionId:y,path:h??v}):void 0,he=W==="host"&&F?.description?F.description:void 0,St=!K&&!g&&C===void 0?$?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":hp({authoritative:K,mutable:fe,pinnedPackageSave:Z,...F?{workspace:F}:{},...G!==void 0?{readFailure:G}:{},...y!==void 0?{versionId:y}:{}}),vr=W==="package"&&fe===!0&&!Z&&G===void 0||St===he?"":St;if(!f&&"resourceUri"in e)return m.jsxs(lt,{severity:"error",sx:{m:2},children:["A ",b," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(We)return m.jsxs(lt,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened in the builder: ",We]});if(V.isError&&!ie)return m.jsx(fp,{error:V.error,context:`Opening the ${b}`});if(!ie&&(!(g||T)||!z))return n??m.jsx(cs,{text:`Opening the ${b}…`});if(B)return m.jsxs(lt,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",G]});const Ro=O!==void 0&&O!==T;return m.jsxs(ct,{sx:{gap:2},children:[V.isError&&m.jsxs(lt,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",V.error?.message,". Your edits are still here."]}),!p&&!K&&q&&Ro&&X===void 0&&m.jsx(lt,{severity:"info",action:m.jsxs(ct,{direction:"row",sx:{gap:1},children:[m.jsx(Ee,{size:"small",onClick:()=>Ye(!0),children:"Resume"}),m.jsx(Ee,{size:"small",onClick:()=>Ye(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),Ae!==void 0&&m.jsx(lt,{severity:"warning",action:m.jsx(Ee,{size:"small",onClick:()=>{Q!==void 0&&pp(Q),Xe()},children:"Load it"}),children:W==="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.":W==="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."}),ze!==void 0&&m.jsxs(lt,{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:"," ",ze]}),!ie&&(n??m.jsx(cs,{text:`Opening the ${b}…`})),ie&&m.jsx(yw,{environmentName:x,packageName:w,modelPath:L,...l?{textSource:l}:{},slug:v,...y!==void 0?{versionId:y}:{},...(c??y)!==void 0?{queryVersionId:c??y}:{},opened:ie,...oe&&Y==="package"&&ie.packageText!==void 0?{replaces:ie.packageText}:{},onSave:E,onDirtyChange:te,...i?{onExit:i}:{},...o?{onOpenModel:o}:{},...s?{onControlsChange:s}:{},...Q!==void 0?{draftKey:Q}:{},savesTo:W,...he?{saveLabel:he}:{},...t?{onEvent:I}:{},note:vr,...ae?{fileModel:ae}:{}},ie.generation)]})}const Iw=Hf,Nw=_f;function Ww(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:i}=e,o="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(Hf,{...o,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:Ll===void 0&&(Ll={});export{Pw as BuilderBar,Nw as DashboardBuilder,Iw as DashboardEditor,Fw as MAX_SLUG_ATTEMPTS,Ww as NotebookEditor,_f as ReportBuilder,Hf as ReportEditor,H0 as buildCatalog,Bw as createDocument,_w as createRoute,dd as locatorFor,Hw as newDashboardSource,qw as newDocumentProblem,Gw as newNotebookSource,ua as readDashboardDocument,da as readFailed,Rw as readReportTagOfText,Vw as reportPathFor,Uw as reportPathForTitle,Kw as slugFor,Yw as slugOrFallback,m0 as spliceDashboardDocument,ha as spliceFailed,Xw as useDocumentChoices};
|