@malloy-publisher/server 0.9.8 → 0.9.9
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/app/api-doc.yaml +531 -0
- package/dist/app/assets/{EnvironmentPage-1dxk_vne.js → EnvironmentPage-DaNUmaHg.js} +1 -1
- package/dist/app/assets/{HomePage-DOCeWyiv.js → HomePage-CRLoVDIs.js} +1 -1
- package/dist/app/assets/{MainPage-Baqv8q6B.js → MainPage-BsV5UnlK.js} +1 -1
- package/dist/app/assets/{ModelPage-BuMKFY0Q.js → ModelPage-DOOiyJAE.js} +2 -2
- package/dist/app/assets/{PackagePage-DMRAjKE6.js → PackagePage-QHG55rBw.js} +1 -1
- package/dist/app/assets/{RenderedResult-DZj-FnOJ.es-8Pxk7Ln2.js → RenderedResult-BHuJpdSn.es-C37LMpwi.js} +2 -2
- package/dist/app/assets/{RouteError-CXf8Frkp.js → RouteError-ziodz3bt.js} +1 -1
- package/dist/app/assets/ThemeEditorPage-Cs3rIs4e.js +1 -0
- package/dist/app/assets/ToggleButtonGroup-BrygJ1WP.js +1 -0
- package/dist/app/assets/{documentRoutes-B2MDvZ3y.js → documentRoutes-1Qgo5Pvl.js} +1 -1
- package/dist/app/assets/index-BK0mbcyQ.js +483 -0
- package/dist/app/assets/{index-Buv5Qzfs.js → index-Bwc6-9Dc.js} +1 -1
- package/dist/app/assets/{index-CvMqTqVr.js → index-CA5a5gJj.js} +1 -1
- package/dist/app/assets/{index-BuyzVBLU.js → index-CXJpj7He.js} +1 -1
- package/dist/app/assets/{index.es-CECvOvgr.js → index.es-CxcPJdYO.js} +33 -33
- package/dist/app/index.html +1 -1
- package/dist/instrumentation.mjs +23 -24
- package/dist/package_load_worker.mjs +9131 -6901
- package/dist/server.mjs +120365 -119669
- package/package.json +1 -1
- package/dist/app/assets/ThemeEditorPage-BzjDFaw6.js +0 -1
- package/dist/app/assets/ToggleButtonGroup-o0Gqmq5F.js +0 -1
- package/dist/app/assets/index-CDTd6FbM.js +0 -483
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{r as S,b4 as Uf,b5 as Xf,j as b,b6 as _o,aA as ye,ap as at,T as ue,aq as Oe,b7 as Nr,b8 as Yf,b9 as Kf,ba as Zf,W as Bo,aH as Qf,bb as At,bc as Jf,bd as qo,be as eh,bf as yc,bg as th,bh as nh,a0 as xc,bi as rh,aZ as Ho,bj as ih,bk as En,K as Tt,bl as ks,J as Ti,H as De,G as sh,bm as oh,R as Ze,bn as ah,bo as ts,bp as lh,I as Us,bq as Lt,br as dt,bs as ch,bt as wc,aM as ns,af as dh,bu as uh,bv as fh,bw as kc,bx as Sc,by as $c,bz as hh,bA as ph,bB as mh,bC as gh,bD as vh,bE as bh,F as yh,bF as xh,bG as Cc,bH as wh,bI as kh,bJ as Sh,bK as $h,bL as Ch,bM as jc,bN as rs,bO as Ec,bP as Oc,bQ as Mc,bR as jh,bS as Go,bT as Ac,bU as Eh,bV as Wr,bW as Oh,bX as Mh,aC as Je,bY as Tc,aG as Nt,bZ as Xs,b_ as Dc,b$ as Ic,aD as Ah,X as Vo,c0 as Uo,c1 as Th,c2 as Dh,c3 as Ih,c4 as Ph,c5 as Xo,c6 as Rh,aR as Lh,c7 as Nh,c8 as Wh,c9 as zh,ca as Gt,cb as ol,S as Fh,cc as _h,L as Bh,U as qh,cd as Hh,ce as Gh,cf as Pc,aO as Vh}from"./index-CDTd6FbM.js";import{cg as yx,ch as xx,ci as wx,cj as kx,ck as Sx,cl as $x,cm as Cx,cn as jx,co as Ex,cp as Ox,cq as Mx}from"./index-CDTd6FbM.js";import{T as Yo,a as Dn}from"./ToggleButtonGroup-o0Gqmq5F.js";var al={};const Uh={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Xh(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this view's details":n==="unlisted"?"Not a view the catalog lists, so its shape is unknown":void 0,i=s=>{if(t!==s){if(s==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(s==="shape_map"||s==="segment_map")return e?.chart===s?void 0:r??"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(s=>{const o=i(s);return{value:s,label:Uh[s],...o?{disabled:!0,reason:o}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ys({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:i,onOpen:s,onChange:o,variant:a="standard"}){const c=Xh(t,e,n),u=S.useId();return b.jsx(Je,{select:!0,size:"small",variant:a,label:"Viz type",value:e,disabled:i!==void 0,onChange:l=>{const d=l.target.value;c.find(f=>f.value===d)?.disabled||o(d)},helperText:i,FormHelperTextProps:{id:u},SelectProps:{...s?{onOpen:s}:{},renderValue:l=>c.find(d=>d.value===l)?.label??String(l),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...i?{"aria-describedby":u}:{}}},sx:{minWidth:140},children:c.map(l=>b.jsx(Nt,{value:l.value,disabled:l.value==="custom"||l.disabled===!0,children:b.jsx(Vo,{primary:l.label,...l.reason?{secondary:l.reason}:{}})},l.value))})}function Yh({sources:e,source:t,view:n,onSource:r,onView:i}){const{theme:s}=Ze(),o=e.find(a=>a.name===t);return b.jsxs(b.Fragment,{children:[b.jsx(Je,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>b.jsxs(Nt,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&b.jsx(ue,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&b.jsx(ue,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),b.jsxs(De,{children:[b.jsx(ue,{variant:"subtitle2",sx:{mb:.5},children:"View"}),b.jsxs(Bh,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:s.border,borderRadius:1},children:[(o?.views??[]).map(a=>b.jsxs(qh,{selected:n===a.name,onClick:()=>i(a.name),"aria-label":`View ${a.name}`,children:[b.jsx(Vo,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&b.jsx(Us,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&b.jsx(ue,{variant:"body2",sx:{p:1.5,color:s.tileTitle},children:"This source declares no views."})]})]})]})}function Kh({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o}){const{theme:a}=Ze(),c=S.useMemo(()=>n?.sources??[],[n]),[u,l]=S.useState("query"),[d,f]=S.useState(""),[h,g]=S.useState(""),[m,y]=S.useState(""),[w,p]=S.useState("default"),[v,x]=S.useState(Math.ceil(r/2));S.useEffect(()=>{if(!e)return;l("query");const $=D=>c.some(z=>z.name===D&&z.views.length>0);f(t.sources.map(D=>D.base).find($)??c.find(D=>D.views.length>0)?.name??""),g(""),y(""),p("default"),x(Math.ceil(r/2))},[e,t,c,r]);const k=d!==""&&h!=="",C=[d,h].filter($=>$!==""&&!Uo($)).map($=>`"${$}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],O=c.find($=>$.name===d),T=O?.views.find($=>$.name===h);return b.jsx(ns,{open:e,onClose:i,title:"Add a tile",description:"A tile shows one view of a source in this package.",actions:b.jsxs(b.Fragment,{children:[b.jsx(Oe,{onClick:i,children:"Cancel"}),b.jsx(Oe,{variant:"contained",disabled:u==="query"&&(!k||C!==void 0),onClick:()=>u==="text"?o():s({base:d,modelPath:O?.modelPath??"",...O?.exporters?{exporters:O.exporters}:{},view:h,...m.trim()?{label:m.trim()}:{},...w!=="default"?{chart:w,...T?{chartCarried:T.chart?[T.chart]:[]}:{}}:{},colspan:v}),children:u==="text"?"Add text":"Add tile"})]}),children:b.jsxs(ye,{sx:{gap:2,pt:1},children:[b.jsxs(Yo,{size:"small",exclusive:!0,value:u,"aria-label":"Tile type",onChange:($,D)=>{D!==null&&l(D)},children:[b.jsx(Dn,{value:"query",sx:{px:1.5},children:"Query"}),b.jsx(Dn,{value:"text",sx:{px:1.5},children:"Text"})]}),u==="text"?b.jsx(ue,{variant:"body2",sx:{color:a.tileTitle},children:"A text tile holds markdown: a heading, a paragraph, a list. It is added empty, and written on the tile itself."}):c.length===0?b.jsx(ue,{variant:"body2",sx:{color:a.tileTitle},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}):b.jsxs(b.Fragment,{children:[b.jsx(Yh,{sources:c,source:d,view:h,onSource:$=>{f($),g("")},onView:$=>{g($),p("default")}}),C&&b.jsx(ue,{variant:"body2",color:"error",children:C}),b.jsx(Ys,{state:w,view:T,cellLabel:"new tile",variant:"outlined",...T?{}:{disabledReason:"Pick a view to choose its chart."},onChange:$=>p($)}),b.jsx(ye,{direction:"row",sx:{gap:1.5},children:b.jsx(Je,{size:"small",label:"Title",placeholder:"Uses the view's name",value:m,onChange:$=>y($.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}})})]})]})})}const Re=e=>e.kind==="text",ve=e=>e.kind!=="text",ei=e=>ve(e)?e.label??e.name:e.name,ze=e=>Re(e)?`text.${e.name}`:`${e.source}.${e.name}`,Ss="self";function Zh({open:e,document:t,source:n,givenNames:r,dashboards:i,onClose:s,onApply:o}){const{theme:a}=Ze(),[c,u]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const h=(t.drills??[]).filter(g=>g.source===n.name);u((n.dimensions??[]).map(g=>{const m=h.find(y=>y.name===g.name);return{name:g.name,expression:g.expression,to:m?.to??[],given:m?.given??""}}))},[e,n,t]);const l=(h,g)=>u(m=>m.map((y,w)=>{if(w!==h)return y;const p={...y};return g(p),p})),d=[Ss,...i.filter(h=>h!==Ss)],f=h=>h===Ss?"This report":h;return b.jsx(ns,{open:e,onClose:s,title:"Drill",description:"A cell in a column that groups by one of these dimensions becomes a link. Clicking it writes the value into a control — here, or on the report it opens.",actions:b.jsxs(b.Fragment,{children:[b.jsx(Oe,{onClick:s,children:"Cancel"}),b.jsx(Oe,{variant:"contained",onClick:()=>{n&&(o(c.filter(h=>h.to.length>0).map(h=>({source:n.name,name:h.name,expression:h.expression,to:h.to,...h.given?{given:h.given}:{}}))),s())},disabled:c.length===0,children:"Apply"})]}),children:b.jsx(ye,{sx:{gap:2,pt:1},children:c.length===0?b.jsx(ue,{variant:"body2",sx:{color:a.tileTitle},children:n?b.jsxs(b.Fragment,{children:[b.jsx(De,{component:"code",children:n.name})," declares no dimensions of its own in this file. A drill 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"," ",b.jsx(De,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):c.map((h,g)=>b.jsxs(De,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[b.jsxs(De,{sx:{minWidth:0,pt:.75},children:[b.jsx(ue,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:h.name}),b.jsxs(ue,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:h.expression,children:["is ",h.expression]})]}),b.jsx(Je,{select:!0,size:"small",label:"Clicks go to",value:h.to,inputProps:{"aria-label":`Where ${h.name} goes`},SelectProps:{multiple:!0,renderValue:m=>m.length===0?"Not clickable":m.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:m=>l(g,y=>{const w=m.target.value;y.to=Array.isArray(w)?w:String(w).split(",").filter(Boolean)}),children:d.map(m=>b.jsxs(Nt,{value:m,children:[b.jsx(Xs,{size:"small",checked:h.to.includes(m),sx:{p:0,mr:1}}),b.jsx(Vo,{primary:f(m)})]},m))}),b.jsxs(Je,{select:!0,size:"small",label:"Sets the filter",value:h.given,disabled:h.to.length===0,inputProps:{"aria-label":`Control ${h.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:h.given===""?`Named ${h.name}, like the dimension`:void 0,onChange:m=>l(g,y=>{y.given=m.target.value}),children:[b.jsx(Nt,{value:"",children:b.jsx("em",{children:"Same name as the dimension"})}),r.map(m=>b.jsx(Nt,{value:m,children:m},m))]})]},h.name))})})}function Qh(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of ve(s)?s.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],i=new Set;for(const s of e.localGivens??[])i.add(s.name),r.push({name:s.name,...s.label===void 0?{}:{label:s.label},type:s.type,...s.suggest?{field:s.suggest.dimension}:{},origin:"dashboard",local:s,boundTiles:n.get(s.name)??0});for(const s of t)i.has(s.name)||(i.add(s.name),r.push({...s,origin:"model",boundTiles:n.get(s.name)??0}));for(const[s,o]of n)i.has(s)||r.push({name:s,origin:"model",boundTiles:o});return r}function Di(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function Jh(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function gi(e,t){const n=Jh(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 ll(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 ep(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const tp=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function np(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=Pc(r)?r:`${r}_FILTER`,s=new Set(t);if(!s.has(i))return i;for(let o=2;;o++)if(!s.has(`${i}_${o}`))return`${i}_${o}`}const cl=[{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 ti(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 Ks=e=>ve(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function rp(e,t){return e.tiles.map(n=>{const r=(ve(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}:Di(t.type)!==void 0?{op:Di(t.type)}:{}}})}function ip(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!Ks(s))return;const o=(s.filters??[]).filter(c=>c.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?s.filters=a:delete s.filters})}function sp(e,t){const n=(e.localGivens??[]).filter(s=>s.name!==t.name),r=(e.localGivens??[]).findIndex(s=>s.name===t.name),i=[...n];i.splice(r>=0?r:i.length,0,t),e.localGivens=i}function op(e,t){for(const r of e.tiles){if(!ve(r))continue;const i=(r.filters??[]).filter(s=>s.given!==t);i.length>0?r.filters=i:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Rc=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function ap({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:s}){const o=S.useRef(n);e&&(o.current=n);const a=e?n:o.current,c=a!==void 0,[u,l]=S.useState({kind:"new"}),[d,f]=S.useState(""),[h,g]=S.useState("select"),[m,y]=S.useState(""),[w,p]=S.useState(""),[v,x]=S.useState([]),[k,C]=S.useState(!1),[O,T]=S.useState(!1),$=P=>t.sources.find(q=>q.name===P.source)?.base??P.source;S.useEffect(()=>{if(e)if(T(n!==void 0),n){l({kind:"existing",name:n.name}),f(n.label??"");const P=rp(t,n);x(P);const q=P.filter(pe=>pe.include),oe=new Set(q.map(pe=>pe.field));p(oe.size===1?q[0].field:n.field??""),C(oe.size>1)}else l({kind:"new"}),f(""),g("select"),p(""),y(new Date().toISOString().slice(0,10)),x(t.tiles.map(P=>({include:Ks(P),field:""}))),C(!1)},[e,n,t]);const D=S.useMemo(()=>[...(t.localGivens??[]).map(P=>P.name),...r.map(P=>P.name)],[t,r]),z=S.useMemo(()=>w.trim()?np(w.trim(),D):"",[w,D]),N=u.kind==="existing"?n??r.find(P=>P.name===u.name):z?{name:z,type:ti({name:z,label:d,kind:h,field:w}).type}:void 0,L=N?.type!==void 0&&!N.type.startsWith("filter<"),B=v.find(P=>P.include)?.op??Di(N?.type),H=(P,q)=>{T(!0),x(oe=>oe.map((pe,Be)=>Be===P?{...pe,...q}:pe))},U=P=>{T(!0),x(q=>q.map(oe=>({...oe,op:P})))},Z=P=>{const q=Di(P);x(oe=>oe.map(({op:pe,...Be})=>q?{...Be,op:q}:Be))},ne=P=>{T(!0),l({kind:"existing",name:P.name}),p(P.field??""),Z(P.type)},J=P=>{T(!0),g(P),Z(ti({name:"X",label:d,kind:P,field:w}).type)},M=t.tiles.map(Ks),F=M.filter(Boolean).length,W=v.filter((P,q)=>P.include&&M[q]).length,R=t.tiles.filter((P,q)=>(v[q]?.include??!1)&&M[q]&&ve(P)),_=R.length>0?R:t.tiles.filter((P,q)=>M[q]&&ve(P)),Y=S.useMemo(()=>{const P=new Map;let q=!1;for(const oe of _){const pe=i?.(oe);if(pe){q=!0;for(const Be of pe)P.has(Be.name)||P.set(Be.name,Be)}}return q?[...P.values()]:void 0},[v,t.tiles,i]),Q=(()=>{const P=w.trim();for(const q of R){const oe=i?.(q);if(!oe||oe.some(pe=>pe.name===P))return $(q)}return R[0]?$(R[0]):t.sources[0]?.base})(),E=P=>{T(!0),x(q=>q.map((oe,pe)=>({...oe,include:P&&M[pe]})))},j=S.useMemo(()=>k?v:v.map(P=>({...P,field:w})),[k,v,w]),A=P=>{for(const q of _){const oe=i?.(q)?.find(pe=>pe.name===P.trim());if(oe?.type)return oe.type}},K=P=>gi(N?.type,P.type),V=(P,q)=>{if(P.trim()==="")return"Pick the field this filter compares.";const oe=q?i?.(q):void 0;if(!oe)return;const pe=oe.find(Be=>Be.name===P.trim());if(!pe)return`Not a field of ${q?$(q):"the tiles' source"}.`;if(pe.type&&!gi(N?.type,pe.type))return`${P.trim()} is ${ll(pe.type)}; this filter compares ${ll(N?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},te=P=>{if(T(!0),p(P),c||u.kind!=="new")return;const q=A(P),oe=ti({name:"X",label:d,kind:h,field:P}).type;q&&!gi(oe,q)&&J(ep(q))},G=P=>{const q=t.tiles[P];return q&&ve(q)?q:void 0},ae=j.map((P,q)=>P.include&&M[q]?V(P.field,G(q)):void 0),ee=ae.every(P=>P===void 0),I=O?ae:ae.map(()=>{}),re=O&&!k&&W>0?R.map(P=>V(w,P)).find(Boolean):void 0,he=N!==void 0&&ee&&(u.kind==="existing"||w.trim()!==""&&z!==""),we=()=>{if(!(!N||!he))if(u.kind==="new")s(N.name,j,ti({name:N.name,label:d.trim()||Rc(N.name),kind:h,field:w.trim(),...Q?{source:Q}:{},...m?{dateDefault:m}:{}}));else if(n?.origin==="dashboard"&&n.local){const P=d.trim(),q=P!==(n.local.label??"");s(N.name,j,q?{...n.local,...P?{label:P}:{}}:void 0)}else s(N.name,j)},X=c&&a.origin==="model";return{editing:c,shown:a,fromModel:X,source:u,setSource:l,label:d,setLabel:f,kind:h,dateDefault:m,setDateDefault:y,field:w,rows:v,setRows:x,perTile:k,setPerTile:C,newName:z,target:N,valueTyped:L,commonOp:B,setRow:H,setCommonOp:U,pickExisting:ne,pickKind:J,bindable:M,bindableCount:F,included:W,commonFields:Y,setAll:E,accepts:K,pickField:te,rowProblems:I,commonProblem:re,canApply:he,apply:we}}function dl({value:e,onChange:t,fields:n,accepts:r,label:i,ariaLabel:s,error:o,helperText:a,disabled:c,autoFocus:u,placeholder:l,sx:d}){const f=S.useMemo(()=>(n??[]).filter(g=>r?.(g)??!0).map(g=>g.name),[n,r]),h=S.useMemo(()=>new Map((n??[]).map(g=>[g.name,g.type])),[n]);return b.jsx(_h,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(g,m)=>t(m),value:e,onChange:(g,m)=>t(typeof m=="string"?m:""),disabled:c,disableClearable:!0,renderOption:(g,m)=>S.createElement("li",{...g,key:m},b.jsx(ue,{variant:"body2",sx:{flex:1},children:m}),h.get(m)&&b.jsx(ue,{variant:"caption",sx:{opacity:.6},children:h.get(m)?.replace(/_type$/,"")})),renderInput:g=>b.jsx(Je,{...g,label:i,placeholder:l,autoFocus:u,error:o,helperText:a,inputProps:{...g.inputProps,"aria-label":s}}),sx:d})}const ul=e=>e&&ve(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function lp({open:e,document:t,control:n,available:r,fieldsFor:i,onClose:s,onApply:o,onRemove:a}){const{theme:c}=Ze(),{editing:u,shown:l,fromModel:d,source:f,setSource:h,label:g,setLabel:m,kind:y,dateDefault:w,setDateDefault:p,field:v,rows:x,setRows:k,perTile:C,setPerTile:O,newName:T,target:$,valueTyped:D,commonOp:z,setRow:N,setCommonOp:L,pickExisting:B,pickKind:H,bindable:U,bindableCount:Z,included:ne,commonFields:J,setAll:M,accepts:F,pickField:W,rowProblems:R,commonProblem:_,canApply:Y,apply:Q}=ap({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:o}),E=(j,A,K)=>b.jsx(Je,{select:!0,size:"small",label:"Compares",value:j??">=",onChange:V=>A(V.target.value),inputProps:{"aria-label":K},sx:{width:130},children:tp.filter(V=>V.op!=="~").map(V=>b.jsx(Nt,{value:V.op,children:V.label},V.op))});return b.jsx(ns,{open:e,onClose:s,title:u?l.label??l.name:"Add a filter",description:u?b.jsxs(b.Fragment,{children:[b.jsxs(De,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",l.name]}),d?" · 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:b.jsxs(b.Fragment,{children:[u&&b.jsx(Oe,{color:"error",startIcon:b.jsx(Ic,{}),onClick:()=>a(l.name),sx:j=>({mr:"auto",color:Dc(j)}),children:"Remove filter"}),b.jsx(Oe,{onClick:s,children:"Cancel"}),b.jsx(Tt,{title:Y||$===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:b.jsx("span",{children:b.jsx(Oe,{variant:"contained",onClick:Q,disabled:!Y,children:u?"Apply":"Add filter"})})})]}),children:b.jsxs(ye,{sx:{gap:2.5,pt:1},children:[!u&&r.length>0&&b.jsxs(Yo,{exclusive:!0,size:"small",value:f.kind,onChange:(j,A)=>{A==="new"?h({kind:"new"}):A==="existing"&&r[0]&&B(r[0])},"aria-label":"Where the filter comes from",children:[b.jsx(Dn,{value:"new",children:"New in this report"}),b.jsx(Dn,{value:"existing",children:"From the model"})]}),!u&&f.kind==="existing"?b.jsx(Je,{select:!0,size:"small",label:"Filter",value:f.name,onChange:j=>{const A=r.find(K=>K.name===j.target.value);A&&B(A)},children:r.map(j=>b.jsxs(Nt,{value:j.name,children:[j.label??j.name,b.jsxs(ue,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",j.name]})]},j.name))}):null,b.jsxs(ye,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!C&&b.jsx(dl,{value:v,onChange:W,fields:J,accepts:F,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!u,error:_!==void 0,helperText:_??(!u&&T?`Declared as $${T}`:void 0),sx:{flex:1,minWidth:200}}),!d&&b.jsx(Je,{size:"small",label:"Label",placeholder:T?Rc(T):"",value:g,onChange:j=>m(j.target.value),inputProps:{"aria-label":"Filter label"},sx:{flex:1,minWidth:160}}),D&&!C&&E(z,L,"Comparison")]}),!u&&f.kind==="new"&&b.jsxs(ye,{direction:"row",sx:{gap:1.5},children:[b.jsx(Je,{select:!0,size:"small",label:"Filter kind",value:y,onChange:j=>H(j.target.value),inputProps:{"aria-label":"Filter kind"},slotProps:{select:{renderValue:j=>cl.find(A=>A.kind===j)?.label??String(j)}},sx:{flex:1},children:cl.map(j=>b.jsxs(Nt,{value:j.kind,children:[j.label,b.jsx(ue,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:j.hint})]},j.kind))}),y==="date"&&b.jsx(Je,{size:"small",type:"date",label:"Starts at",value:w,onChange:j=>p(j.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),b.jsxs(De,{children:[b.jsxs(ye,{direction:"row",sx:{alignItems:"center",gap:.5},children:[b.jsx(Xs,{size:"small",checked:Z>0&&ne===Z,indeterminate:ne>0&&ne<Z,disabled:Z===0,onChange:j=>M(j.target.checked),inputProps:{"aria-label":"All tiles"}}),b.jsxs(ue,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",ne," of ",t.tiles.length," tiles"]}),b.jsx(Oe,{size:"small",onClick:()=>{C||k(j=>j.map(A=>({...A,field:v}))),O(j=>!j)},children:C?"Same field for all":"Adjust per tile"})]}),b.jsx(ye,{sx:{gap:C?1:0},children:t.tiles.map((j,A)=>{if(!ve(j))return null;const K=x[A],V=j.label??j.name,te=C?R[A]:void 0;return b.jsxs(ye,{direction:"row",sx:{gap:1,alignItems:C?"flex-start":"center",opacity:U[A]?1:.6},children:[b.jsx(Xs,{size:"small",disabled:!U[A],checked:(K?.include??!1)&&U[A],inputProps:{"aria-label":`Filter ${V}`},onChange:G=>N(A,{include:G.target.checked})}),b.jsx(ue,{variant:"body2",sx:{flex:1,minWidth:0,pt:C?1:0},noWrap:!0,children:V}),U[A]?C&&b.jsxs(b.Fragment,{children:[D&&E(K?.op,G=>N(A,{op:G}),`Comparison for ${V}`),b.jsx(dl,{value:K?.field??"",onChange:G=>N(A,{field:G}),fields:i?.(j),accepts:F,label:"Field",ariaLabel:`Field for ${V}`,disabled:!K?.include,error:te!==void 0,helperText:te,sx:{width:220}})]}):b.jsx(Tt,{title:ul(t.tiles[A]).reason,children:b.jsx(ue,{variant:"caption",sx:{color:c.tileTitle},children:ul(t.tiles[A]).label})})]},`${j.source}.${j.name}`)})}),ne===0&&b.jsx(ue,{variant:"caption",sx:{color:"warning.main",display:"block",mt:1},children:"No tile is ticked, so this control will not appear on the dashboard."})]})]})})}const cp=Wr(b.jsx("path",{d:"M11.71 17.99C8.53 17.84 6 15.22 6 12c0-3.31 2.69-6 6-6 3.22 0 5.84 2.53 5.99 5.71l-2.1-.63C15.48 9.31 13.89 8 12 8c-2.21 0-4 1.79-4 4 0 1.89 1.31 3.48 3.08 3.89zM22 12c0 .3-.01.6-.04.9l-1.97-.59c.01-.1.01-.21.01-.31 0-4.42-3.58-8-8-8s-8 3.58-8 8 3.58 8 8 8c.1 0 .21 0 .31-.01l.59 1.97c-.3.03-.6.04-.9.04-5.52 0-10-4.48-10-10S6.48 2 12 2s10 4.48 10 10m-3.77 4.26L22 15l-10-3 3 10 1.26-3.77 4.27 4.27 1.98-1.98z"}));function Lc(e,t,n,r){const[i,s]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&s(structuredClone(e))},[t,e]),{draft:i,patch:o=>s(a=>{if(a===void 0)return a;const c=structuredClone(a);return o(c),c}),apply:o=>{if(i===void 0)return;const a=structuredClone(i);o(a),s(a),JSON.stringify(a)!==JSON.stringify(e)&&n(a)},close:()=>{i!==void 0&&e!==void 0&&JSON.stringify(i)!==JSON.stringify(e)&&n(i),r()},discard:()=>s(void 0)}}const dp=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.`,up="This tile's view is declared on its source, so its chart is set in the model.";function fp({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:i,removeBlocked:s,onDrills:o,view:a}){const c=S.useId(),{theme:u}=Ze(),{draft:l,apply:d,close:f,discard:h}=Lc(t,e!==null,r,n),g=l!==void 0&&ve(l)?l:void 0,m=g!==void 0&&g.declaration.kind!=="inherited",y=v=>d(x=>{ve(x)&&v(x)}),w=S.useRef(void 0),p=e!==null;return S.useEffect(()=>{p&&(w.current=t&&ve(t)?t.chart:void 0)},[p]),b.jsx(Ah,{open:e!==null&&l!==void 0,anchorEl:e,onClose:f,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:l&&b.jsxs(ye,{sx:{gap:1.5},children:[b.jsx(ue,{variant:"overline",sx:{color:u.tileTitle,lineHeight:1.5},children:g?`${g.source} → ${g.name}`:`Text · ${l.name}`}),g&&m&&b.jsx(b.Fragment,{children:b.jsx(Ys,{state:g.chart??"default",view:a,cellLabel:`${g.source} ${g.name}`,...g.chart==="custom"?{disabledReason:dp(g.chartLines)}:{},onChange:v=>y(x=>{const k=w.current;v===(k??"default")?(k===void 0?delete x.chart:x.chart=k,delete x.chartCarried):(x.chart=v,a?x.chartCarried=a.chart?[a.chart]:[]:delete x.chartCarried)})})}),g&&!m&&b.jsxs(b.Fragment,{children:[b.jsx(ue,{variant:"body2",sx:{color:u.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),b.jsx(Ys,{state:"default",view:a,cellLabel:`${g.source} ${g.name}`,disabledReason:up,onChange:()=>{}})]}),g?.declaration.kind==="opaque"&&b.jsxs(ue,{variant:"body2",sx:{color:u.tileTitle},children:["Its body is ",g.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),b.jsxs(ye,{direction:"row",sx:{justifyContent:"space-between"},children:[m?b.jsx(Oe,{size:"small",startIcon:b.jsx(cp,{}),"aria-haspopup":"dialog",onClick:()=>{f(),o()},children:"Drill"}):b.jsx("span",{}),b.jsx(Oe,{color:"error",size:"small",startIcon:b.jsx(Ic,{}),"aria-disabled":s!==void 0||void 0,"aria-describedby":s!==void 0?c:void 0,disableRipple:s!==void 0,sx:v=>({color:Dc(v),...s!==void 0?{opacity:.5,cursor:"default"}:{}}),onClick:()=>{s===void 0&&(h(),i())},children:"Delete"})]}),s!==void 0&&b.jsx(ue,{id:c,variant:"caption",sx:{color:u.tileTitle},children:s})]})})}function hp({editor:e,catalog:t,columns:n,dashboards:r,bindings:i,tiles:s,drillSource:o,setDrillSource:a,confirmConversion:c,exitDialog:u}){const{filterDialog:l,setFilterDialog:d}=i,{menu:f,setMenu:h}=s,g=f===void 0?void 0:e.document.tiles[f.index],m=g&&ve(g)?g:void 0,y=(()=>{if(!m||!t)return;const w=e.document.sources.find(v=>v.name===m.source)?.base??m.source,p=m.declaration.kind==="reference"?m.declaration.from:m.name;return t.sources.find(v=>v.name===w)?.views.find(v=>v.name===p)})();return b.jsxs(b.Fragment,{children:[b.jsx(lp,{open:l!==void 0,document:e.document,...l?.control?{control:l.control}:{},available:i.available,...t?{fieldsFor:i.fieldsFor}:{},onClose:()=>d(void 0),onApply:i.applyFilter,onRemove:i.dropControl}),b.jsx(fp,{anchor:f?.anchor??null,tile:f===void 0?void 0:e.document.tiles[f.index],onClose:()=>h(void 0),onCommit:w=>{const p=f?.index;p!==void 0&&e.update(v=>{v.tiles[p]=w})},onRemove:()=>{f!==void 0&&s.removeTile(f.index)},...e.document.tiles.length===1&&e.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},view:y,onDrills:()=>{a(m?.source)}}),b.jsx(Zh,{open:o!==void 0,document:e.document,source:e.document.sources.find(w=>w.name===o),givenNames:i.controlList.map(w=>w.name),dashboards:r??[],onClose:()=>a(void 0),onApply:w=>e.update(p=>{const v=[...(p.drills??[]).filter(x=>x.source!==o),...w];v.length===0?delete p.drills:p.drills=v})}),b.jsx(ns,{open:c!==void 0,onClose:()=>c?.stop(),title:"Convert this report?",description:"Saving rewrites this report in the tile layout. The builder cannot take that back; the file's history in your repository can.",actions:b.jsxs(b.Fragment,{children:[b.jsx(Oe,{onClick:()=>c?.stop(),children:"Cancel"}),b.jsx(Oe,{variant:"contained",onClick:()=>c?.go(),children:"Convert and save"})]}),children:null}),b.jsx(dh,{...u}),b.jsx(Kh,{open:s.addingTile,document:e.document,catalog:t,columns:n,onClose:s.closeAdd,onAdd:s.addTile,onAddText:s.addText})]})}var pp=Symbol.for("preact-signals");function is(){if(xt>1)xt--;else{var e,t=!1;for((function(){var i=Pi;for(Pi=void 0;i!==void 0;){var s=i.S;if(s.v===i.v)for(var o=s.t;o!==void 0;o=o.x)o.i===i.i&&(o.i=s.i);i=i.o}})();yr!==void 0;){var n=yr;for(yr=void 0,Ii++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Wc(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(Ii=0,xt--,t)throw e}}function Ce(e){if(xt>0)return e();Zs=++mp,xt++;try{return e()}finally{is()}}var br,be=void 0;function le(e){var t=be,n=br;be=void 0,br=void 0;try{return e()}finally{be=t,br=n}}var yr=void 0,xt=0,Ii=0,mp=0,Zs=0,Pi=void 0,Ri=0;function Nc(e){if(be!==void 0){var t=e.n;if(t===void 0||t.t!==be)return t={i:0,S:e,p:be.s,n:void 0,t:be,e:void 0,x:void 0,r:t},be.s!==void 0&&(be.s.n=t),be.s=t,e.n=t,32&be.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=be.s,t.n=void 0,be.s.n=t,be.s=t),t}}function Ve(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}Ve.prototype.brand=pp;Ve.prototype.h=function(){return!0};Ve.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)}))};Ve.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)}))}};Ve.prototype.subscribe=function(e){var t=this;return st(function(){var n=t.value;le(function(){return e(n)})},{name:"sub"})};Ve.prototype.valueOf=function(){return this.value};Ve.prototype.toString=function(){return this.value+""};Ve.prototype.toJSON=function(){return this.value};Ve.prototype.peek=function(){var e=this;return le(function(){return e.value})};Object.defineProperty(Ve.prototype,"value",{get:function(){var e=Nc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ii>100)throw new Error("Cycle detected");(function(n){xt!==0&&Ii===0&&n.l!==Zs&&(n.l=Zs,Pi={S:n,v:n.v,i:n.i,o:Pi})})(this),this.v=e,this.i++,Ri++,xt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{is()}}}});function zn(e,t){return new Ve(e,t)}function Wc(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 zc(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 Fc(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 sn(e,t){Ve.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Ri-1,this.f=4}sn.prototype=new Ve;sn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ri))return!0;if(this.g=Ri,this.f|=1,this.i>0&&!Wc(this))return this.f&=-2,!0;var e=be;try{zc(this),be=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 be=e,Fc(this),this.f&=-2,!0};sn.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)}Ve.prototype.S.call(this,e)};sn.prototype.U=function(e){if(this.t!==void 0&&(Ve.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)}};sn.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(sn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Nc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function fl(e,t){return new sn(e,t)}function _c(e){var t=e.m;if(e.m=void 0,typeof t=="function"){xt++;var n=be;be=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Ko(e),r}finally{be=n,is()}}}function Ko(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,_c(e)}function gp(e){if(be!==this)throw new Error("Out-of-order effect");Fc(this),be=e,this.f&=-2,8&this.f&&Ko(this),is()}function Fn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,br&&br.push(this)}Fn.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()}};Fn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,_c(this),zc(this),xt++;var e=be;return be=this,gp.bind(this,e)};Fn.prototype.N=function(){2&this.f||(this.f|=2,this.u=yr,yr=this)};Fn.prototype.d=function(){this.f|=8,1&this.f||Ko(this)};Fn.prototype.dispose=function(){this.d()};function st(e,t){var n=new Fn(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var vp=Object.create,Zo=Object.defineProperty,bp=Object.defineProperties,yp=Object.getOwnPropertyDescriptor,xp=Object.getOwnPropertyDescriptors,hl=Object.getOwnPropertySymbols,wp=Object.prototype.hasOwnProperty,kp=Object.prototype.propertyIsEnumerable,Sp=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),_n=e=>{throw TypeError(e)},Qs=(e,t,n)=>t in e?Zo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$p=(e,t)=>{for(var n in t||(t={}))wp.call(t,n)&&Qs(e,n,t[n]);if(hl)for(var n of hl(t))kp.call(t,n)&&Qs(e,n,t[n]);return e},Cp=(e,t)=>bp(e,xp(t)),pl=(e,t)=>Zo(e,"name",{value:t,configurable:!0}),jp=e=>{var t;return[,,,vp((t=void 0)!=null?t:null)]},Bc=["class","method","getter","setter","accessor","field","value","get","set"],nr=e=>e!==void 0&&typeof e!="function"?_n("Function expected"):e,Ep=(e,t,n,r,i)=>({kind:Bc[e],name:t,metadata:r,addInitializer:s=>n._?_n("Already initialized"):i.push(nr(s||null))}),qc=(e,t)=>Qs(t,Sp("metadata"),e[3]),Ht=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},Bn=(e,t,n,r,i,s)=>{var o,a,c,u,l,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,m=Bc[d+5],y=d>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(i=i.prototype),d<5&&(d>3||!h)&&yp(d<4?i:{get[n](){return et(this,s)},set[n](x){return Mt(this,s,x)}},n));d?h&&d<4&&pl(s,(d>2?"set ":d>1?"get ":"")+n):pl(i,n);for(var v=r.length-1;v>=0;v--)u=Ep(d,n,c={},e[3],w),d&&(u.static=f,u.private=h,l=u.access={has:h?x=>Op(i,x):x=>n in x},d^3&&(l.get=h?x=>(d^1?et:Mp)(x,i,d^4?s:p.get):x=>x[n]),d>2&&(l.set=h?(x,k)=>Mt(x,i,k,d^4?s:p.set):(x,k)=>x[n]=k)),a=(0,r[v])(d?d<4?h?s:p[m]:d>4?void 0:{get:p.get,set:p.set}:i,u),c._=1,d^4||a===void 0?nr(a)&&(d>4?y.unshift(a):d?h?s=a:p[m]=a:i=a):typeof a!="object"||a===null?_n("Object expected"):(nr(o=a.get)&&(p.get=o),nr(o=a.set)&&(p.set=o),nr(o=a.init)&&y.unshift(o));return d||qc(e,i),p&&Zo(i,n,p),h?d^4?s:p:i},Qo=(e,t,n)=>t.has(e)||_n("Cannot "+n),Op=(e,t)=>Object(t)!==t?_n('Cannot use the "in" operator on this value'):e.has(t),et=(e,t,n)=>(Qo(e,t,"read from private field"),n?n.call(e):t.get(e)),rr=(e,t,n)=>t.has(e)?_n("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Mt=(e,t,n,r)=>(Qo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Mp=(e,t,n)=>(Qo(e,t,"access private method"),n);function Js(e,t){if(t){let n;return fl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return fl(e)}function lt(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)=>!lt(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=>!lt(e[i],t[i]))}return!1}function ce({get:e},t){return{init(n){return zn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ee(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Js(e.bind(this)),n.set(this,r)),r.value}}function $s(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,Cp($p({},i),{enumerable:e}))})}}function zr(...e){const t=e.map(n=>st(n));return()=>t.forEach(n=>n())}var Hc,Gc,Vc,Uc,Xc,Yc,qe,Jo,Cs,eo,to,Fe,ea,js,Kc,no,ta,Es,ro,io;Yc=[ce],Xc=[ce],Uc=[ce],Vc=[$s()],Gc=[$s()],Hc=[$s()];var on=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ht(qe,5,this),rr(this,Fe),rr(this,Jo,Ht(qe,8,this)),Ht(qe,11,this),rr(this,ea,Ht(qe,12,this)),Ht(qe,15,this),rr(this,ta,Ht(qe,16,this)),Ht(qe,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return et(this,Fe,ro)}get initial(){return et(this,Fe,eo)}get previous(){return et(this,Fe,Kc)}set current(e){const t=le(()=>et(this,Fe,ro));e&&t&&this.equals(t,e)||Ce(()=>{et(this,Fe,eo)||Mt(this,Fe,e,to),Mt(this,Fe,t,no),Mt(this,Fe,e,io)})}reset(e=this.defaultValue){Ce(()=>{Mt(this,Fe,void 0,no),Mt(this,Fe,e,to),Mt(this,Fe,e,io)})}};qe=jp();Jo=new WeakMap;Fe=new WeakSet;ea=new WeakMap;ta=new WeakMap;Cs=Bn(qe,20,"#initial",Yc,Fe,Jo),eo=Cs.get,to=Cs.set;js=Bn(qe,20,"#previous",Xc,Fe,ea),Kc=js.get,no=js.set;Es=Bn(qe,20,"#current",Uc,Fe,ta),ro=Es.get,io=Es.set;Bn(qe,2,"current",Vc,on);Bn(qe,2,"initial",Gc,on);Bn(qe,2,"previous",Hc,on);qc(qe,on);function Os(e){return le(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Vt,Ap=class{constructor(){rr(this,Vt,new WeakMap)}get(e,t){var n;return e?(n=et(this,Vt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return et(this,Vt).has(e)||et(this,Vt).set(e,new Map),(r=et(this,Vt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=et(this,Vt).get(e))==null?void 0:t.clear():void 0}};Vt=new WeakMap;var Tp=Object.create,Zc=Object.defineProperty,Dp=Object.getOwnPropertyDescriptor,ml=Object.getOwnPropertySymbols,Ip=Object.prototype.hasOwnProperty,Pp=Object.prototype.propertyIsEnumerable,Qc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ss=e=>{throw TypeError(e)},gl=Math.pow,so=(e,t,n)=>t in e?Zc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rp=(e,t)=>{for(var n in t||(t={}))Ip.call(t,n)&&so(e,n,t[n]);if(ml)for(var n of ml(t))Pp.call(t,n)&&so(e,n,t[n]);return e},Lp=e=>{var t;return[,,,Tp((t=e?.[Qc("metadata")])!=null?t:null)]},Jc=["class","method","getter","setter","accessor","field","value","get","set"],ed=e=>e!==void 0&&typeof e!="function"?ss("Function expected"):e,Np=(e,t,n,r,i)=>({kind:Jc[e],name:t,metadata:r,addInitializer:s=>n._?ss("Already initialized"):i.push(ed(s||null))}),Wp=(e,t)=>so(t,Qc("metadata"),e[3]),zp=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},td=(e,t,n,r,i,s)=>{for(var o,a,c,u,l=t&7,d=!1,f=!1,h=2,g=Jc[l+5],m=e[h]||(e[h]=[]),y=(i=i.prototype,Dp(i,n)),w=r.length-1;w>=0;w--)c=Np(l,n,a={},e[3],m),c.static=d,c.private=f,u=c.access={has:p=>n in p},u.get=p=>p[n],o=(0,r[w])(y[g],c),a._=1,ed(o)&&(y[g]=o);return y&&Zc(i,n,y),i},nd=(e,t,n)=>t.has(e)||ss("Cannot "+n),Fp=(e,t,n)=>(nd(e,t,"read from private field"),t.get(e)),_p=(e,t,n)=>t.has(e)?ss("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Bp=(e,t,n,r)=>(nd(e,t,"write to private field"),t.set(e,n),n),tt=class oo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new oo(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 oo(t,n)}},gt=class Ut{constructor(t,n,r,i){this.left=t,this.top=n,this.width=r,this.height=i,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:i,width:s,height:o,scale:a}=this,c=new Ut(i+t,r+n,s,o);return c.scale=Rp({},a),c}get boundingRectangle(){const{width:t,height:n,left:r,top:i,right:s,bottom:o}=this;return{width:t,height:n,left:r,top:i,right:s,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:i}=this;return new tt((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Ut))return!1;const{left:n,top:r,width:i,height:s}=this;return n===t.left&&r===t.top&&i===t.width&&s===t.height}containsPoint(t){const{top:n,left:r,bottom:i,right:s}=this;return n<=t.y&&t.y<=i&&r<=t.x&&t.x<=s}intersectionArea(t){return t instanceof Ut?qp(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 Ut(n,t,r,i)}static delta(t,n,r={x:"center",y:"center"}){const i=(s,o)=>{const a=r[o],c=o==="x"?s.left:s.top,u=o==="x"?s.width:s.height;return a=="start"?c:a=="end"?c+u:c+u/2};return tt.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return Ut.from(t).intersectionRatio(Ut.from(n))}};function qp(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),o=i-r,a=s-n;return r<i&&n<s?o*a:0}var rd,id,ao,vi,Fr,os=class extends(ao=on,id=[Ee],rd=[Ee],ao){constructor(e){const t=tt.from(e);super(t,(n,r)=>tt.equals(n,r)),zp(Fr,5,this),_p(this,vi,0),this.velocity={x:0,y:0}}get delta(){return tt.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=tt.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-Fp(this,vi),o=a=>Math.round(a/s*100);Ce(()=>{Bp(this,vi,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(tt.from(e)),this.velocity={x:0,y:0}}};Fr=Lp(ao);vi=new WeakMap;td(Fr,2,"delta",id,os);td(Fr,2,"direction",rd,os);Wp(Fr,os);function lo({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(gl(r,2)+gl(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 sd=(e=>(e.Horizontal="x",e.Vertical="y",e))(sd||{}),od=Object.values(sd),Hp=Object.create,na=Object.defineProperty,Gp=Object.defineProperties,Vp=Object.getOwnPropertyDescriptor,Up=Object.getOwnPropertyDescriptors,Li=Object.getOwnPropertySymbols,ad=Object.prototype.hasOwnProperty,ld=Object.prototype.propertyIsEnumerable,cd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),qn=e=>{throw TypeError(e)},co=(e,t,n)=>t in e?na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ra=(e,t)=>{for(var n in t||(t={}))ad.call(t,n)&&co(e,n,t[n]);if(Li)for(var n of Li(t))ld.call(t,n)&&co(e,n,t[n]);return e},ia=(e,t)=>Gp(e,Up(t)),vl=(e,t)=>na(e,"name",{value:t,configurable:!0}),dd=(e,t)=>{var n={};for(var r in e)ad.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Li)for(var r of Li(e))t.indexOf(r)<0&&ld.call(e,r)&&(n[r]=e[r]);return n},Hn=e=>{var t;return[,,,Hp((t=e?.[cd("metadata")])!=null?t:null)]},ud=["class","method","getter","setter","accessor","field","value","get","set"],ir=e=>e!==void 0&&typeof e!="function"?qn("Function expected"):e,Xp=(e,t,n,r,i)=>({kind:ud[e],name:t,metadata:r,addInitializer:s=>n._?qn("Already initialized"):i.push(ir(s||null))}),an=(e,t)=>co(t,cd("metadata"),e[3]),se=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},de=(e,t,n,r,i,s)=>{var o,a,c,u,l,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,m=ud[d+5],y=d>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(i=i.prototype),d<5&&(d>3||!h)&&Vp(d<4?i:{get[n](){return je(this,s)},set[n](x){return Ke(this,s,x)}},n));d?h&&d<4&&vl(s,(d>2?"set ":d>1?"get ":"")+n):vl(i,n);for(var v=r.length-1;v>=0;v--)u=Xp(d,n,c={},e[3],w),d&&(u.static=f,u.private=h,l=u.access={has:h?x=>Yp(i,x):x=>n in x},d^3&&(l.get=h?x=>(d^1?je:fd)(x,i,d^4?s:p.get):x=>x[n]),d>2&&(l.set=h?(x,k)=>Ke(x,i,k,d^4?s:p.set):(x,k)=>x[n]=k)),a=(0,r[v])(d?d<4?h?s:p[m]:d>4?void 0:{get:p.get,set:p.set}:i,u),c._=1,d^4||a===void 0?ir(a)&&(d>4?y.unshift(a):d?h?s=a:p[m]=a:i=a):typeof a!="object"||a===null?qn("Object expected"):(ir(o=a.get)&&(p.get=o),ir(o=a.set)&&(p.set=o),ir(o=a.init)&&y.unshift(o));return d||an(e,i),p&&na(i,n,p),h?d^4?s:p:i},sa=(e,t,n)=>t.has(e)||qn("Cannot "+n),Yp=(e,t)=>Object(t)!==t?qn('Cannot use the "in" operator on this value'):e.has(t),je=(e,t,n)=>(sa(e,t,"read from private field"),n?n.call(e):t.get(e)),fe=(e,t,n)=>t.has(e)?qn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ke=(e,t,n,r)=>(sa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),fd=(e,t,n)=>(sa(e,t,"access private method"),n);function hd(e,t){return{plugin:e,options:t}}function _r(e){return t=>hd(e,t)}function Cr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var pd,jr,oa,bi;pd=[ce];var _e=class{constructor(e,t){this.manager=e,this.options=t,fe(this,oa,se(jr,8,this,!1)),se(jr,11,this),fe(this,bi,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return le(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=st(e.bind(this));return je(this,bi).add(t),t}destroy(){je(this,bi).forEach(e=>e())}static configure(e){return hd(this,e)}};jr=Hn(null);oa=new WeakMap;bi=new WeakMap;de(jr,4,"disabled",pd,_e,oa);an(jr,_e);var Br=class extends _e{},yi,Ms=class{constructor(e){this.manager=e,this.instances=new Map,fe(this,yi,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Cr).reduce((r,i)=>{const s=r.find(({plugin:o})=>o===i.plugin);return s?(s.options=i.options,r):[...r,i]},[]),n=t.map(({plugin:r})=>r);for(const r of je(this,yi))if(!n.includes(r)){if(r.prototype instanceof Br)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);Ke(this,yi,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()}};yi=new WeakMap;function Kp(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var ni=[],bn,yn,Zp=class extends _e{constructor(e){super(e),fe(this,bn),fe(this,yn),this.computeCollisions=this.computeCollisions.bind(this),Ke(this,yn,zn(ni)),this.destroy=zr(()=>{const t=this.computeCollisions(),n=le(()=>this.manager.dragOperation.position.current);if(t!==ni){const r=je(this,bn);if(Ke(this,bn,n),r&&n.x==r.x&&n.y==r.y)return}else Ke(this,bn,void 0);je(this,yn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){le(()=>{e?je(this,yn).value=this.computeCollisions():Ke(this,bn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return ni;const a=[],c=[];for(const u of e??n.droppables){if(u.disabled||i&&!u.accepts(i))continue;const l=t??u.collisionDetector;if(!l)continue;c.push(u),u.shape;const d=le(()=>l({droppable:u,dragOperation:r}));d&&(u.collisionPriority!=null&&(d.priority=u.collisionPriority),a.push(d))}return c.length===0?ni:(a.sort(Kp),a)}get collisions(){return je(this,yn).value}};bn=new WeakMap;yn=new WeakMap;var md,gd,vd,aa,bd,ct,la,Cn,ca,da;vd=[ce],gd=[ce],md=[ce];var kt=class Xt{constructor(t,n){fe(this,la,se(ct,8,this)),se(ct,11,this),fe(this,Cn),fe(this,ca,se(ct,12,this)),se(ct,15,this),fe(this,da,se(ct,16,this)),se(ct,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let c=i;Ke(this,Cn,zn(i)),this.manager=n,this.data=s,this.disabled=o,this.effects=()=>{var u;return[()=>{const{id:l,manager:d}=this;if(l!==c)return c=l,d?.registry.register(this),()=>d?.registry.unregister(this)},...(u=r?.())!=null?u:[]]},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=je(this,Cn).value;return(n=(t=Xt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=Xt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:je(this,Cn).peek();t!==i&&(Xt.pendingIdChanges||(Xt.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return fd(s=Xt,aa,bd).call(s)})),Xt.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)}};ct=Hn(null);aa=new WeakSet;bd=function(){const e=kt.pendingIdChanges;kt.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)je(t,Cn).value=n})};la=new WeakMap;Cn=new WeakMap;ca=new WeakMap;da=new WeakMap;de(ct,4,"manager",vd,kt,la);de(ct,4,"data",gd,kt,ca);de(ct,4,"disabled",md,kt,da);fe(kt,aa);an(ct,kt);kt.pendingIdChanges=null;var as=kt,bl=class{constructor(){this.map=zn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),i=()=>this.unregister(e,t);if(r===t)return i;r&&r.id===e&&(this.cleanupFunctions.get(r)?.(),this.cleanupFunctions.delete(r));const s=new Map(n);for(const[a,c]of n)if(c===t&&a!==e){s.delete(a);break}s.set(e,t),this.map.value=s;const o=zr(...t.effects());return this.cleanupFunctions.set(t,o),i},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;this.cleanupFunctions.get(t)?.(),this.cleanupFunctions.delete(t);const i=new Map(n);i.delete(e),this.map.value=i}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this)this.cleanupFunctions.get(e)?.(),e.destroy();this.map.value=new Map}},yd,xd,wd,kd,Sd,$d,uo,He,ua,fa,ha,vt=class extends(uo=as,$d=[ce],Sd=[ce],kd=[ce],wd=[Ee],xd=[Ee],yd=[Ee],uo){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,c=dd(n,["modifiers","type","sensors","plugins","effects"]);super(ia(ra({},c),{effects:()=>{var u;return[...(u=a?.())!=null?u:[],()=>{const{manager:l,plugins:d}=this;if(!(!l||!d))for(const f of d){const{plugin:h}=Cr(f);l.registry.plugins.register(h)}}]}}),t),se(He,5,this),fe(this,ua,se(He,8,this)),se(He,11,this),fe(this,fa,se(He,12,this)),se(He,15,this),fe(this,ha,se(He,16,this,this.isDragSource?"dragging":"idle")),se(He,19,this),this.type=i,this.sensors=s,this.modifiers=r,this.alignment=c.alignment,this.plugins=o}pluginConfig(e){if(this.plugins)for(const t of this.plugins){const n=Cr(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}};He=Hn(uo);ua=new WeakMap;fa=new WeakMap;ha=new WeakMap;de(He,4,"type",$d,vt,ua);de(He,4,"modifiers",Sd,vt,fa);de(He,4,"status",kd,vt,ha);de(He,2,"isDropping",wd,vt);de(He,2,"isDragging",xd,vt);de(He,2,"isDragSource",yd,vt);an(He,vt);var Cd,jd,Ed,Od,Md,Ad,fo,Ie,pa,ma,ga,va,ba,bt=class extends(fo=as,Ad=[ce],Md=[ce],Od=[ce],Ed=[ce],jd=[ce],Cd=[Ee],fo){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=dd(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),se(Ie,5,this),fe(this,pa,se(Ie,8,this)),se(Ie,11,this),fe(this,ma,se(Ie,12,this)),se(Ie,15,this),fe(this,ga,se(Ie,16,this)),se(Ie,19,this),fe(this,va,se(Ie,20,this)),se(Ie,23,this),fe(this,ba,se(Ie,24,this)),se(Ie,27,this),this.accept=r,this.collisionDetector=i,this.collisionPriority=s,this.type=o}accepts(e){const{accept:t}=this;return t?typeof t=="function"?t(e):e.type?Array.isArray(t)?t.includes(e.type):e.type===t:!1:!0}get isDropTarget(){var e,t;return((t=(e=this.manager)==null?void 0:e.dragOperation.target)==null?void 0:t.id)===this.id}};Ie=Hn(fo);pa=new WeakMap;ma=new WeakMap;ga=new WeakMap;va=new WeakMap;ba=new WeakMap;de(Ie,4,"accept",Ad,bt,pa);de(Ie,4,"type",Md,bt,ma);de(Ie,4,"collisionDetector",Od,bt,ga);de(Ie,4,"collisionPriority",Ed,bt,va);de(Ie,4,"shape",jd,bt,ba);de(Ie,2,"isDropTarget",Cd,bt);an(Ie,bt);var Qp=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)}},Jp=class extends Qp{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function xi(e,t=!0){let n=!1;return ia(ra({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var em=class extends Br{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=zr(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||as.pendingIdChanges)return;const o=xi({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;le(()=>{var c;a?.id!==((c=e.dragOperation.target)==null?void 0:c.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Gn=(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))(Gn||{}),Vn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Vn||{}),Td,Dd,Id,Pd,Rd,Ld,Nd,it,ya;Nd=[ce],Ld=[Ee],Rd=[Ee],Pd=[Ee],Id=[Ee],Dd=[Ee],Td=[Ee];var $t=class{constructor(){se(it,5,this),fe(this,ya,se(it,8,this,"idle")),se(it,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}};it=Hn(null);ya=new WeakMap;de(it,4,"value",Nd,$t,ya);de(it,2,"current",Ld,$t);de(it,2,"idle",Rd,$t);de(it,2,"initializing",Pd,$t);de(it,2,"initialized",Id,$t);de(it,2,"dragging",Dd,$t);de(it,2,"dropped",Td,$t);an(it,$t);var tm=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=xi({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 s=xi({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",s),s.defaultPrevented?(t.reset(),n.abort(),n):(t.status.set("initializing"),t.controller=n,this.manager.renderer.rendering.then(()=>{if(n.signal.aborted)return;const{status:o}=t;o.current==="initializing"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:r,operation:t.snapshot(),cancelable:!1})})}),n)})}move(e){return le(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=xi({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,c,u,l,d;if(o.defaultPrevented)return;const f=(d=e.to)!=null?d:{x:r.position.current.x+((c=(a=e.by)==null?void 0:a.x)!=null?c:0),y:r.position.current.y+((l=(u=e.by)==null?void 0:u.y)!=null?l:0)};r.position.current=f})})}stop(e={}){return le(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:i}=r;if(!i||i.signal.aborted)return;let s;const o=()=>{const c={resume:()=>{},abort:()=>{}};return s=new Promise((u,l)=>{c.resume=u,c.abort=l}),c};i.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const c=le(()=>{var l;return((l=r.source)==null?void 0:l.status)==="dropping"}),u=()=>{r.controller===i&&(r.controller=void 0),r.reset()};if(c){const{source:l}=r,d=st(()=>{l?.status==="idle"&&(d(),u())})}else this.manager.renderer.rendering.then(u)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),s?s.then(a).catch(()=>r.reset()):a()})}},In=class extends _e{constructor(e,t){super(e,t),this.manager=e,this.options=t}},nm=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,Wd=class{constructor(e){this.options=e,fe(this,wi)}set controller(e){Ke(this,wi,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=je(this,wi))==null||t.activate(e)}};wi=new WeakMap;var yl=class extends _e{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},rm=class{constructor(e){this.draggables=new bl,this.droppables=new bl,this.plugins=new Ms(e),this.sensors=new Ms(e),this.modifiers=new Ms(e)}register(e,t){if(e instanceof vt)return this.draggables.register(e.id,e);if(e instanceof bt)return this.droppables.register(e.id,e);if(e.prototype instanceof yl)return this.modifiers.register(e,t);if(e.prototype instanceof In)return this.sensors.register(e,t);if(e.prototype instanceof _e)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof as)return e instanceof vt?this.draggables.unregister(e.id,e):e instanceof bt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof yl)return this.modifiers.unregister(e);if(e.prototype instanceof In)return this.sensors.unregister(e);if(e.prototype instanceof _e)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()}},zd,Fd,_d,Bd,qd,Hd,Gd,Vd,Ud,sr,ki,xn,$e,xa,wa,ka,Sa,$a,or;Ud=[Ee],Vd=[ce],Gd=[ce],Hd=[ce],qd=[ce],Bd=[ce],_d=[Ee],Fd=[Ee],zd=[Ee];var ht=class{constructor(e){se($e,5,this),fe(this,sr),fe(this,ki),fe(this,xn,new on(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new $t,fe(this,xa,se($e,8,this,!1)),se($e,11,this),fe(this,wa,se($e,12,this,null)),se($e,15,this),fe(this,ka,se($e,16,this,null)),se($e,19,this),fe(this,Sa,se($e,20,this,null)),se($e,23,this),fe(this,$a,se($e,24,this,[])),se($e,27,this),this.position=new os({x:0,y:0}),fe(this,or,{x:0,y:0}),Ke(this,sr,e)}get shape(){const{current:e,initial:t,previous:n}=je(this,xn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?je(this,xn).current=e:je(this,xn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=je(this,sr).registry.draggables.get(t);return n&&Ke(this,ki,n),(e=n??je(this,ki))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=je(this,sr).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(ia(ra({},this.snapshot()),{transform:n}));return Ke(this,or,n),n}snapshot(){return le(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:je(this,or),shape:this.shape?Os(this.shape):null,position:Os(this.position),status:Os(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,je(this,xn).reset(),this.position.reset({x:0,y:0}),Ke(this,or,{x:0,y:0}),this.modifiers=[]})}};$e=Hn(null);sr=new WeakMap;ki=new WeakMap;xn=new WeakMap;xa=new WeakMap;wa=new WeakMap;ka=new WeakMap;Sa=new WeakMap;$a=new WeakMap;or=new WeakMap;de($e,2,"shape",Ud,ht);de($e,4,"canceled",Vd,ht,xa);de($e,4,"activatorEvent",Gd,ht,wa);de($e,4,"sourceIdentifier",Hd,ht,ka);de($e,4,"targetIdentifier",qd,ht,Sa);de($e,4,"modifiers",Bd,ht,$a);de($e,2,"source",_d,ht);de($e,2,"target",Fd,ht);de($e,2,"transform",zd,ht);an($e,ht);var im={get rendering(){return Promise.resolve()}};function ft(e,t){return typeof e=="function"?e(t):e??t}var sm=class{constructor(e){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(d=>d.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var t;const n=e??{},r=ft(n.plugins,[]),i=ft(n.sensors,[]),s=ft(n.modifiers,[]),o=(t=n.renderer)!=null?t:im,a=new Jp(this),c=new rm(this);this.registry=c,this.monitor=a,this.renderer=o,this.actions=new tm(this),this.dragOperation=new ht(this),this.collisionObserver=new Zp(this),this.plugins=[em,...r],this.modifiers=s,this.sensors=i;const{destroy:u}=this,l=zr(()=>{var d,f,h;const g=le(()=>this.dragOperation.modifiers),m=this.modifiers;for(const y of g)m.includes(y)||y.destroy();this.dragOperation.modifiers=(h=(f=(d=this.dragOperation.source)==null?void 0:d.modifiers)==null?void 0:f.map(y=>{const{plugin:w,options:p}=Cr(y);return new w(this,p)}))!=null?h:m});this.destroy=()=>{l(),u()}}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}},Xd=e=>{throw TypeError(e)},Ca=(e,t,n)=>t.has(e)||Xd("Cannot "+n),ie=(e,t,n)=>(Ca(e,t,"read from private field"),t.get(e)),Ue=(e,t,n)=>t.has(e)?Xd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,r)=>(Ca(e,t,"write to private field"),t.set(e,n),n),Yd=(e,t,n)=>(Ca(e,t,"access private method"),n);function ls(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Kd(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,o=(ls(s)?s.getKeyframes():[]).filter(t);o.length>0&&(r=[o[o.length-1],i])}return r}function cs(e){const{width:t,height:n,top:r,left:i,bottom:s,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:i,bottom:s,right:o}}function ja(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function qr(e){return"nodeType"in e}function Qe(e){var t,n,r;return e?ja(e)?e:qr(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 Ea(e){const{Document:t}=Qe(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function zt(e){return!e||ja(e)?!1:e instanceof Qe(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Zd(e){return e instanceof Qe(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Un(e){return e?ja(e)?e.document:qr(e)?Ea(e)?e:zt(e)||Zd(e)?e.ownerDocument:document:document:document}function om(e){var t,n,r,i;const{documentElement:s}=Un(e),o=Qe(e).visualViewport,a=(t=o?.width)!=null?t:s.clientWidth,c=(n=o?.height)!=null?n:s.clientHeight,u=(r=o?.offsetTop)!=null?r:0,l=(i=o?.offsetLeft)!=null?i:0;return{top:u,left:l,right:l+a,bottom:u+c,width:a,height:c}}function am(e,t){if(lm(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function lm(e){return e.tagName==="DETAILS"}function Er(e,t=e.getBoundingClientRect(),n=0){var r,i,s,o,a;let c=t;const{ownerDocument:u}=e,l=(r=u.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==u.documentElement;){if(!am(d)){const v=d.getBoundingClientRect(),x=n*(v.bottom-v.top),k=n*(v.right-v.left),C=n*(v.bottom-v.top),O=n*(v.right-v.left);c={top:Math.max(c.top,v.top-x),right:Math.min(c.right,v.right+k),bottom:Math.min(c.bottom,v.bottom+C),left:Math.max(c.left,v.left-O),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top}d=d.parentElement}const f=l.visualViewport,h=(i=f?.offsetTop)!=null?i:0,g=(s=f?.offsetLeft)!=null?s:0,m=(o=f?.width)!=null?o:l.innerWidth,y=(a=f?.height)!=null?a:l.innerHeight,w=n*y,p=n*m;return c={top:Math.max(c.top,h-w),right:Math.min(c.right,g+m+p),bottom:Math.min(c.bottom,h+y+w),left:Math.max(c.left,g-p),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top,c.width<0&&(c.width=0),c.height<0&&(c.height=0),c}function Pn(e){return{x:e.clientX,y:e.clientY}}var Qd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ho(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(...ho(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(...ho(i.document,t))}}catch{}return n}function Oa(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Jd(){var e,t;const n=Oa()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Ma(e){return!e||!qr(e)?!1:e instanceof Qe(e).ShadowRoot}function Ni(e){if(e&&qr(e)){let t=e.getRootNode();if(Ma(t)||t instanceof Document)return t}return Un(e)}function Aa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function cm(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,s)=>{const o=r[s];xl(i)&&xl(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),wl(i)&&wl(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function xl(e){return"value"in e}function wl(e){return e.tagName==="CANVAS"}function eu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(dm(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return eu(i,{x:t-s,y:n-o})}}return r}function dm(e){return e?.tagName==="IFRAME"}var po=new WeakMap;function um(e){return e.closest(`
|
|
1
|
+
import{r as S,b4 as Yf,b5 as Uf,j as b,b6 as _o,aA as ye,ap as at,T as ue,aq as Oe,b7 as Nr,b8 as Xf,b9 as Kf,ba as Zf,Q as Bo,aH as Qf,bb as At,bc as Jf,bd as qo,be as eh,bf as yc,bg as th,bh as nh,a0 as xc,bi as rh,aZ as Ho,bj as ih,bk as En,L as Tt,bl as ks,K as Ti,I as De,H as sh,bm as oh,V as Ze,bn as ah,bo as ts,bp as lh,J as Ys,bq as Lt,br as dt,bs as ch,bt as wc,aM as ns,af as dh,bu as uh,bv as fh,bw as kc,bx as Sc,by as $c,bz as hh,bA as ph,bB as mh,bC as gh,bD as vh,bE as bh,G as yh,bF as xh,bG as Cc,bH as wh,bI as kh,bJ as Sh,bK as $h,bL as Ch,bM as jc,bN as rs,bO as Ec,bP as Oc,bQ as Mc,bR as jh,bS as Go,bT as Ac,bU as Eh,bV as Wr,bW as Oh,bX as Mh,aC as Je,bY as Tc,aG as Nt,bZ as Us,b_ as Dc,b$ as Ic,aD as Ah,Y as Vo,c0 as Yo,c1 as Th,c2 as Dh,c3 as Ih,c4 as Ph,c5 as Uo,c6 as Rh,aR as Lh,c7 as Nh,c8 as Wh,c9 as zh,ca as Gt,cb as ol,S as Fh,cc as _h,O as Bh,W as qh,cd as Hh,ce as Gh,cf as Pc,aO as Vh}from"./index-BK0mbcyQ.js";import{cg as yx,ch as xx,ci as wx,cj as kx,ck as Sx,cl as $x,cm as Cx,cn as jx,co as Ex,cp as Ox,cq as Mx}from"./index-BK0mbcyQ.js";import{T as Xo,a as Dn}from"./ToggleButtonGroup-BrygJ1WP.js";var al={};const Yh={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Uh(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this view's details":n==="unlisted"?"Not a view the catalog lists, so its shape is unknown":void 0,i=s=>{if(t!==s){if(s==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(s==="shape_map"||s==="segment_map")return e?.chart===s?void 0:r??"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(s=>{const o=i(s);return{value:s,label:Yh[s],...o?{disabled:!0,reason:o}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Xs({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:i,onOpen:s,onChange:o,variant:a="standard"}){const c=Uh(t,e,n),u=S.useId();return b.jsx(Je,{select:!0,size:"small",variant:a,label:"Viz type",value:e,disabled:i!==void 0,onChange:l=>{const d=l.target.value;c.find(f=>f.value===d)?.disabled||o(d)},helperText:i,FormHelperTextProps:{id:u},SelectProps:{...s?{onOpen:s}:{},renderValue:l=>c.find(d=>d.value===l)?.label??String(l),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...i?{"aria-describedby":u}:{}}},sx:{minWidth:140},children:c.map(l=>b.jsx(Nt,{value:l.value,disabled:l.value==="custom"||l.disabled===!0,children:b.jsx(Vo,{primary:l.label,...l.reason?{secondary:l.reason}:{}})},l.value))})}function Xh({sources:e,source:t,view:n,onSource:r,onView:i}){const{theme:s}=Ze(),o=e.find(a=>a.name===t);return b.jsxs(b.Fragment,{children:[b.jsx(Je,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>b.jsxs(Nt,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&b.jsx(ue,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&b.jsx(ue,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),b.jsxs(De,{children:[b.jsx(ue,{variant:"subtitle2",sx:{mb:.5},children:"View"}),b.jsxs(Bh,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:s.border,borderRadius:1},children:[(o?.views??[]).map(a=>b.jsxs(qh,{selected:n===a.name,onClick:()=>i(a.name),"aria-label":`View ${a.name}`,children:[b.jsx(Vo,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&b.jsx(Ys,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&b.jsx(ue,{variant:"body2",sx:{p:1.5,color:s.tileTitle},children:"This source declares no views."})]})]})]})}function Kh({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s,onAddText:o}){const{theme:a}=Ze(),c=S.useMemo(()=>n?.sources??[],[n]),[u,l]=S.useState("query"),[d,f]=S.useState(""),[h,g]=S.useState(""),[m,y]=S.useState(""),[w,p]=S.useState("default"),[v,x]=S.useState(Math.ceil(r/2));S.useEffect(()=>{if(!e)return;l("query");const $=D=>c.some(z=>z.name===D&&z.views.length>0);f(t.sources.map(D=>D.base).find($)??c.find(D=>D.views.length>0)?.name??""),g(""),y(""),p("default"),x(Math.ceil(r/2))},[e,t,c,r]);const k=d!==""&&h!=="",C=[d,h].filter($=>$!==""&&!Yo($)).map($=>`"${$}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],O=c.find($=>$.name===d),T=O?.views.find($=>$.name===h);return b.jsx(ns,{open:e,onClose:i,title:"Add a tile",description:"A tile shows one view of a source in this package.",actions:b.jsxs(b.Fragment,{children:[b.jsx(Oe,{onClick:i,children:"Cancel"}),b.jsx(Oe,{variant:"contained",disabled:u==="query"&&(!k||C!==void 0),onClick:()=>u==="text"?o():s({base:d,modelPath:O?.modelPath??"",...O?.exporters?{exporters:O.exporters}:{},view:h,...m.trim()?{label:m.trim()}:{},...w!=="default"?{chart:w,...T?{chartCarried:T.chart?[T.chart]:[]}:{}}:{},colspan:v}),children:u==="text"?"Add text":"Add tile"})]}),children:b.jsxs(ye,{sx:{gap:2,pt:1},children:[b.jsxs(Xo,{size:"small",exclusive:!0,value:u,"aria-label":"Tile type",onChange:($,D)=>{D!==null&&l(D)},children:[b.jsx(Dn,{value:"query",sx:{px:1.5},children:"Query"}),b.jsx(Dn,{value:"text",sx:{px:1.5},children:"Text"})]}),u==="text"?b.jsx(ue,{variant:"body2",sx:{color:a.tileTitle},children:"A text tile holds markdown: a heading, a paragraph, a list. It is added empty, and written on the tile itself."}):c.length===0?b.jsx(ue,{variant:"body2",sx:{color:a.tileTitle},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}):b.jsxs(b.Fragment,{children:[b.jsx(Xh,{sources:c,source:d,view:h,onSource:$=>{f($),g("")},onView:$=>{g($),p("default")}}),C&&b.jsx(ue,{variant:"body2",color:"error",children:C}),b.jsx(Xs,{state:w,view:T,cellLabel:"new tile",variant:"outlined",...T?{}:{disabledReason:"Pick a view to choose its chart."},onChange:$=>p($)}),b.jsx(ye,{direction:"row",sx:{gap:1.5},children:b.jsx(Je,{size:"small",label:"Title",placeholder:"Uses the view's name",value:m,onChange:$=>y($.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}})})]})]})})}const Re=e=>e.kind==="text",ve=e=>e.kind!=="text",ei=e=>ve(e)?e.label??e.name:e.name,ze=e=>Re(e)?`text.${e.name}`:`${e.source}.${e.name}`,Ss="self";function Zh({open:e,document:t,source:n,givenNames:r,dashboards:i,onClose:s,onApply:o}){const{theme:a}=Ze(),[c,u]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const h=(t.drills??[]).filter(g=>g.source===n.name);u((n.dimensions??[]).map(g=>{const m=h.find(y=>y.name===g.name);return{name:g.name,expression:g.expression,to:m?.to??[],given:m?.given??""}}))},[e,n,t]);const l=(h,g)=>u(m=>m.map((y,w)=>{if(w!==h)return y;const p={...y};return g(p),p})),d=[Ss,...i.filter(h=>h!==Ss)],f=h=>h===Ss?"This report":h;return b.jsx(ns,{open:e,onClose:s,title:"Drill",description:"A cell in a column that groups by one of these dimensions becomes a link. Clicking it writes the value into a control — here, or on the report it opens.",actions:b.jsxs(b.Fragment,{children:[b.jsx(Oe,{onClick:s,children:"Cancel"}),b.jsx(Oe,{variant:"contained",onClick:()=>{n&&(o(c.filter(h=>h.to.length>0).map(h=>({source:n.name,name:h.name,expression:h.expression,to:h.to,...h.given?{given:h.given}:{}}))),s())},disabled:c.length===0,children:"Apply"})]}),children:b.jsx(ye,{sx:{gap:2,pt:1},children:c.length===0?b.jsx(ue,{variant:"body2",sx:{color:a.tileTitle},children:n?b.jsxs(b.Fragment,{children:[b.jsx(De,{component:"code",children:n.name})," declares no dimensions of its own in this file. A drill 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"," ",b.jsx(De,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):c.map((h,g)=>b.jsxs(De,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[b.jsxs(De,{sx:{minWidth:0,pt:.75},children:[b.jsx(ue,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:h.name}),b.jsxs(ue,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:h.expression,children:["is ",h.expression]})]}),b.jsx(Je,{select:!0,size:"small",label:"Clicks go to",value:h.to,inputProps:{"aria-label":`Where ${h.name} goes`},SelectProps:{multiple:!0,renderValue:m=>m.length===0?"Not clickable":m.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:m=>l(g,y=>{const w=m.target.value;y.to=Array.isArray(w)?w:String(w).split(",").filter(Boolean)}),children:d.map(m=>b.jsxs(Nt,{value:m,children:[b.jsx(Us,{size:"small",checked:h.to.includes(m),sx:{p:0,mr:1}}),b.jsx(Vo,{primary:f(m)})]},m))}),b.jsxs(Je,{select:!0,size:"small",label:"Sets the filter",value:h.given,disabled:h.to.length===0,inputProps:{"aria-label":`Control ${h.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:h.given===""?`Named ${h.name}, like the dimension`:void 0,onChange:m=>l(g,y=>{y.given=m.target.value}),children:[b.jsx(Nt,{value:"",children:b.jsx("em",{children:"Same name as the dimension"})}),r.map(m=>b.jsx(Nt,{value:m,children:m},m))]})]},h.name))})})}function Qh(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of ve(s)?s.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],i=new Set;for(const s of e.localGivens??[])i.add(s.name),r.push({name:s.name,...s.label===void 0?{}:{label:s.label},type:s.type,...s.suggest?{field:s.suggest.dimension}:{},origin:"dashboard",local:s,boundTiles:n.get(s.name)??0});for(const s of t)i.has(s.name)||(i.add(s.name),r.push({...s,origin:"model",boundTiles:n.get(s.name)??0}));for(const[s,o]of n)i.has(s)||r.push({name:s,origin:"model",boundTiles:o});return r}function Di(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function Jh(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function gi(e,t){const n=Jh(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 ll(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 ep(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const tp=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function np(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=Pc(r)?r:`${r}_FILTER`,s=new Set(t);if(!s.has(i))return i;for(let o=2;;o++)if(!s.has(`${i}_${o}`))return`${i}_${o}`}const cl=[{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 ti(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 Ks=e=>ve(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function rp(e,t){return e.tiles.map(n=>{const r=(ve(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}:Di(t.type)!==void 0?{op:Di(t.type)}:{}}})}function ip(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!Ks(s))return;const o=(s.filters??[]).filter(c=>c.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?s.filters=a:delete s.filters})}function sp(e,t){const n=(e.localGivens??[]).filter(s=>s.name!==t.name),r=(e.localGivens??[]).findIndex(s=>s.name===t.name),i=[...n];i.splice(r>=0?r:i.length,0,t),e.localGivens=i}function op(e,t){for(const r of e.tiles){if(!ve(r))continue;const i=(r.filters??[]).filter(s=>s.given!==t);i.length>0?r.filters=i:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Rc=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function ap({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:s}){const o=S.useRef(n);e&&(o.current=n);const a=e?n:o.current,c=a!==void 0,[u,l]=S.useState({kind:"new"}),[d,f]=S.useState(""),[h,g]=S.useState("select"),[m,y]=S.useState(""),[w,p]=S.useState(""),[v,x]=S.useState([]),[k,C]=S.useState(!1),[O,T]=S.useState(!1),$=P=>t.sources.find(q=>q.name===P.source)?.base??P.source;S.useEffect(()=>{if(e)if(T(n!==void 0),n){l({kind:"existing",name:n.name}),f(n.label??"");const P=rp(t,n);x(P);const q=P.filter(pe=>pe.include),oe=new Set(q.map(pe=>pe.field));p(oe.size===1?q[0].field:n.field??""),C(oe.size>1)}else l({kind:"new"}),f(""),g("select"),p(""),y(new Date().toISOString().slice(0,10)),x(t.tiles.map(P=>({include:Ks(P),field:""}))),C(!1)},[e,n,t]);const D=S.useMemo(()=>[...(t.localGivens??[]).map(P=>P.name),...r.map(P=>P.name)],[t,r]),z=S.useMemo(()=>w.trim()?np(w.trim(),D):"",[w,D]),N=u.kind==="existing"?n??r.find(P=>P.name===u.name):z?{name:z,type:ti({name:z,label:d,kind:h,field:w}).type}:void 0,L=N?.type!==void 0&&!N.type.startsWith("filter<"),B=v.find(P=>P.include)?.op??Di(N?.type),H=(P,q)=>{T(!0),x(oe=>oe.map((pe,Be)=>Be===P?{...pe,...q}:pe))},Y=P=>{T(!0),x(q=>q.map(oe=>({...oe,op:P})))},Z=P=>{const q=Di(P);x(oe=>oe.map(({op:pe,...Be})=>q?{...Be,op:q}:Be))},ne=P=>{T(!0),l({kind:"existing",name:P.name}),p(P.field??""),Z(P.type)},J=P=>{T(!0),g(P),Z(ti({name:"X",label:d,kind:P,field:w}).type)},M=t.tiles.map(Ks),F=M.filter(Boolean).length,W=v.filter((P,q)=>P.include&&M[q]).length,R=t.tiles.filter((P,q)=>(v[q]?.include??!1)&&M[q]&&ve(P)),_=R.length>0?R:t.tiles.filter((P,q)=>M[q]&&ve(P)),X=S.useMemo(()=>{const P=new Map;let q=!1;for(const oe of _){const pe=i?.(oe);if(pe){q=!0;for(const Be of pe)P.has(Be.name)||P.set(Be.name,Be)}}return q?[...P.values()]:void 0},[v,t.tiles,i]),Q=(()=>{const P=w.trim();for(const q of R){const oe=i?.(q);if(!oe||oe.some(pe=>pe.name===P))return $(q)}return R[0]?$(R[0]):t.sources[0]?.base})(),E=P=>{T(!0),x(q=>q.map((oe,pe)=>({...oe,include:P&&M[pe]})))},j=S.useMemo(()=>k?v:v.map(P=>({...P,field:w})),[k,v,w]),A=P=>{for(const q of _){const oe=i?.(q)?.find(pe=>pe.name===P.trim());if(oe?.type)return oe.type}},K=P=>gi(N?.type,P.type),V=(P,q)=>{if(P.trim()==="")return"Pick the field this filter compares.";const oe=q?i?.(q):void 0;if(!oe)return;const pe=oe.find(Be=>Be.name===P.trim());if(!pe)return`Not a field of ${q?$(q):"the tiles' source"}.`;if(pe.type&&!gi(N?.type,pe.type))return`${P.trim()} is ${ll(pe.type)}; this filter compares ${ll(N?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},te=P=>{if(T(!0),p(P),c||u.kind!=="new")return;const q=A(P),oe=ti({name:"X",label:d,kind:h,field:P}).type;q&&!gi(oe,q)&&J(ep(q))},G=P=>{const q=t.tiles[P];return q&&ve(q)?q:void 0},ae=j.map((P,q)=>P.include&&M[q]?V(P.field,G(q)):void 0),ee=ae.every(P=>P===void 0),I=O?ae:ae.map(()=>{}),re=O&&!k&&W>0?R.map(P=>V(w,P)).find(Boolean):void 0,he=N!==void 0&&ee&&(u.kind==="existing"||w.trim()!==""&&z!==""),we=()=>{if(!(!N||!he))if(u.kind==="new")s(N.name,j,ti({name:N.name,label:d.trim()||Rc(N.name),kind:h,field:w.trim(),...Q?{source:Q}:{},...m?{dateDefault:m}:{}}));else if(n?.origin==="dashboard"&&n.local){const P=d.trim(),q=P!==(n.local.label??"");s(N.name,j,q?{...n.local,...P?{label:P}:{}}:void 0)}else s(N.name,j)},U=c&&a.origin==="model";return{editing:c,shown:a,fromModel:U,source:u,setSource:l,label:d,setLabel:f,kind:h,dateDefault:m,setDateDefault:y,field:w,rows:v,setRows:x,perTile:k,setPerTile:C,newName:z,target:N,valueTyped:L,commonOp:B,setRow:H,setCommonOp:Y,pickExisting:ne,pickKind:J,bindable:M,bindableCount:F,included:W,commonFields:X,setAll:E,accepts:K,pickField:te,rowProblems:I,commonProblem:re,canApply:he,apply:we}}function dl({value:e,onChange:t,fields:n,accepts:r,label:i,ariaLabel:s,error:o,helperText:a,disabled:c,autoFocus:u,placeholder:l,sx:d}){const f=S.useMemo(()=>(n??[]).filter(g=>r?.(g)??!0).map(g=>g.name),[n,r]),h=S.useMemo(()=>new Map((n??[]).map(g=>[g.name,g.type])),[n]);return b.jsx(_h,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(g,m)=>t(m),value:e,onChange:(g,m)=>t(typeof m=="string"?m:""),disabled:c,disableClearable:!0,renderOption:(g,m)=>S.createElement("li",{...g,key:m},b.jsx(ue,{variant:"body2",sx:{flex:1},children:m}),h.get(m)&&b.jsx(ue,{variant:"caption",sx:{opacity:.6},children:h.get(m)?.replace(/_type$/,"")})),renderInput:g=>b.jsx(Je,{...g,label:i,placeholder:l,autoFocus:u,error:o,helperText:a,inputProps:{...g.inputProps,"aria-label":s}}),sx:d})}const ul=e=>e&&ve(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function lp({open:e,document:t,control:n,available:r,fieldsFor:i,onClose:s,onApply:o,onRemove:a}){const{theme:c}=Ze(),{editing:u,shown:l,fromModel:d,source:f,setSource:h,label:g,setLabel:m,kind:y,dateDefault:w,setDateDefault:p,field:v,rows:x,setRows:k,perTile:C,setPerTile:O,newName:T,target:$,valueTyped:D,commonOp:z,setRow:N,setCommonOp:L,pickExisting:B,pickKind:H,bindable:Y,bindableCount:Z,included:ne,commonFields:J,setAll:M,accepts:F,pickField:W,rowProblems:R,commonProblem:_,canApply:X,apply:Q}=ap({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:o}),E=(j,A,K)=>b.jsx(Je,{select:!0,size:"small",label:"Compares",value:j??">=",onChange:V=>A(V.target.value),inputProps:{"aria-label":K},sx:{width:130},children:tp.filter(V=>V.op!=="~").map(V=>b.jsx(Nt,{value:V.op,children:V.label},V.op))});return b.jsx(ns,{open:e,onClose:s,title:u?l.label??l.name:"Add a filter",description:u?b.jsxs(b.Fragment,{children:[b.jsxs(De,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",l.name]}),d?" · 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:b.jsxs(b.Fragment,{children:[u&&b.jsx(Oe,{color:"error",startIcon:b.jsx(Ic,{}),onClick:()=>a(l.name),sx:j=>({mr:"auto",color:Dc(j)}),children:"Remove filter"}),b.jsx(Oe,{onClick:s,children:"Cancel"}),b.jsx(Tt,{title:X||$===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:b.jsx("span",{children:b.jsx(Oe,{variant:"contained",onClick:Q,disabled:!X,children:u?"Apply":"Add filter"})})})]}),children:b.jsxs(ye,{sx:{gap:2.5,pt:1},children:[!u&&r.length>0&&b.jsxs(Xo,{exclusive:!0,size:"small",value:f.kind,onChange:(j,A)=>{A==="new"?h({kind:"new"}):A==="existing"&&r[0]&&B(r[0])},"aria-label":"Where the filter comes from",children:[b.jsx(Dn,{value:"new",children:"New in this report"}),b.jsx(Dn,{value:"existing",children:"From the model"})]}),!u&&f.kind==="existing"?b.jsx(Je,{select:!0,size:"small",label:"Filter",value:f.name,onChange:j=>{const A=r.find(K=>K.name===j.target.value);A&&B(A)},children:r.map(j=>b.jsxs(Nt,{value:j.name,children:[j.label??j.name,b.jsxs(ue,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",j.name]})]},j.name))}):null,b.jsxs(ye,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!C&&b.jsx(dl,{value:v,onChange:W,fields:J,accepts:F,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!u,error:_!==void 0,helperText:_??(!u&&T?`Declared as $${T}`:void 0),sx:{flex:1,minWidth:200}}),!d&&b.jsx(Je,{size:"small",label:"Label",placeholder:T?Rc(T):"",value:g,onChange:j=>m(j.target.value),inputProps:{"aria-label":"Filter label"},sx:{flex:1,minWidth:160}}),D&&!C&&E(z,L,"Comparison")]}),!u&&f.kind==="new"&&b.jsxs(ye,{direction:"row",sx:{gap:1.5},children:[b.jsx(Je,{select:!0,size:"small",label:"Filter kind",value:y,onChange:j=>H(j.target.value),inputProps:{"aria-label":"Filter kind"},slotProps:{select:{renderValue:j=>cl.find(A=>A.kind===j)?.label??String(j)}},sx:{flex:1},children:cl.map(j=>b.jsxs(Nt,{value:j.kind,children:[j.label,b.jsx(ue,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:j.hint})]},j.kind))}),y==="date"&&b.jsx(Je,{size:"small",type:"date",label:"Starts at",value:w,onChange:j=>p(j.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),b.jsxs(De,{children:[b.jsxs(ye,{direction:"row",sx:{alignItems:"center",gap:.5},children:[b.jsx(Us,{size:"small",checked:Z>0&&ne===Z,indeterminate:ne>0&&ne<Z,disabled:Z===0,onChange:j=>M(j.target.checked),inputProps:{"aria-label":"All tiles"}}),b.jsxs(ue,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",ne," of ",t.tiles.length," tiles"]}),b.jsx(Oe,{size:"small",onClick:()=>{C||k(j=>j.map(A=>({...A,field:v}))),O(j=>!j)},children:C?"Same field for all":"Adjust per tile"})]}),b.jsx(ye,{sx:{gap:C?1:0},children:t.tiles.map((j,A)=>{if(!ve(j))return null;const K=x[A],V=j.label??j.name,te=C?R[A]:void 0;return b.jsxs(ye,{direction:"row",sx:{gap:1,alignItems:C?"flex-start":"center",opacity:Y[A]?1:.6},children:[b.jsx(Us,{size:"small",disabled:!Y[A],checked:(K?.include??!1)&&Y[A],inputProps:{"aria-label":`Filter ${V}`},onChange:G=>N(A,{include:G.target.checked})}),b.jsx(ue,{variant:"body2",sx:{flex:1,minWidth:0,pt:C?1:0},noWrap:!0,children:V}),Y[A]?C&&b.jsxs(b.Fragment,{children:[D&&E(K?.op,G=>N(A,{op:G}),`Comparison for ${V}`),b.jsx(dl,{value:K?.field??"",onChange:G=>N(A,{field:G}),fields:i?.(j),accepts:F,label:"Field",ariaLabel:`Field for ${V}`,disabled:!K?.include,error:te!==void 0,helperText:te,sx:{width:220}})]}):b.jsx(Tt,{title:ul(t.tiles[A]).reason,children:b.jsx(ue,{variant:"caption",sx:{color:c.tileTitle},children:ul(t.tiles[A]).label})})]},`${j.source}.${j.name}`)})}),ne===0&&b.jsx(ue,{variant:"caption",sx:{color:"warning.main",display:"block",mt:1},children:"No tile is ticked, so this control will not appear on the dashboard."})]})]})})}const cp=Wr(b.jsx("path",{d:"M11.71 17.99C8.53 17.84 6 15.22 6 12c0-3.31 2.69-6 6-6 3.22 0 5.84 2.53 5.99 5.71l-2.1-.63C15.48 9.31 13.89 8 12 8c-2.21 0-4 1.79-4 4 0 1.89 1.31 3.48 3.08 3.89zM22 12c0 .3-.01.6-.04.9l-1.97-.59c.01-.1.01-.21.01-.31 0-4.42-3.58-8-8-8s-8 3.58-8 8 3.58 8 8 8c.1 0 .21 0 .31-.01l.59 1.97c-.3.03-.6.04-.9.04-5.52 0-10-4.48-10-10S6.48 2 12 2s10 4.48 10 10m-3.77 4.26L22 15l-10-3 3 10 1.26-3.77 4.27 4.27 1.98-1.98z"}));function Lc(e,t,n,r){const[i,s]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&s(structuredClone(e))},[t,e]),{draft:i,patch:o=>s(a=>{if(a===void 0)return a;const c=structuredClone(a);return o(c),c}),apply:o=>{if(i===void 0)return;const a=structuredClone(i);o(a),s(a),JSON.stringify(a)!==JSON.stringify(e)&&n(a)},close:()=>{i!==void 0&&e!==void 0&&JSON.stringify(i)!==JSON.stringify(e)&&n(i),r()},discard:()=>s(void 0)}}const dp=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.`,up="This tile's view is declared on its source, so its chart is set in the model.";function fp({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:i,removeBlocked:s,onDrills:o,view:a}){const c=S.useId(),{theme:u}=Ze(),{draft:l,apply:d,close:f,discard:h}=Lc(t,e!==null,r,n),g=l!==void 0&&ve(l)?l:void 0,m=g!==void 0&&g.declaration.kind!=="inherited",y=v=>d(x=>{ve(x)&&v(x)}),w=S.useRef(void 0),p=e!==null;return S.useEffect(()=>{p&&(w.current=t&&ve(t)?t.chart:void 0)},[p]),b.jsx(Ah,{open:e!==null&&l!==void 0,anchorEl:e,onClose:f,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:l&&b.jsxs(ye,{sx:{gap:1.5},children:[b.jsx(ue,{variant:"overline",sx:{color:u.tileTitle,lineHeight:1.5},children:g?`${g.source} → ${g.name}`:`Text · ${l.name}`}),g&&m&&b.jsx(b.Fragment,{children:b.jsx(Xs,{state:g.chart??"default",view:a,cellLabel:`${g.source} ${g.name}`,...g.chart==="custom"?{disabledReason:dp(g.chartLines)}:{},onChange:v=>y(x=>{const k=w.current;v===(k??"default")?(k===void 0?delete x.chart:x.chart=k,delete x.chartCarried):(x.chart=v,a?x.chartCarried=a.chart?[a.chart]:[]:delete x.chartCarried)})})}),g&&!m&&b.jsxs(b.Fragment,{children:[b.jsx(ue,{variant:"body2",sx:{color:u.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),b.jsx(Xs,{state:"default",view:a,cellLabel:`${g.source} ${g.name}`,disabledReason:up,onChange:()=>{}})]}),g?.declaration.kind==="opaque"&&b.jsxs(ue,{variant:"body2",sx:{color:u.tileTitle},children:["Its body is ",g.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),b.jsxs(ye,{direction:"row",sx:{justifyContent:"space-between"},children:[m?b.jsx(Oe,{size:"small",startIcon:b.jsx(cp,{}),"aria-haspopup":"dialog",onClick:()=>{f(),o()},children:"Drill"}):b.jsx("span",{}),b.jsx(Oe,{color:"error",size:"small",startIcon:b.jsx(Ic,{}),"aria-disabled":s!==void 0||void 0,"aria-describedby":s!==void 0?c:void 0,disableRipple:s!==void 0,sx:v=>({color:Dc(v),...s!==void 0?{opacity:.5,cursor:"default"}:{}}),onClick:()=>{s===void 0&&(h(),i())},children:"Delete"})]}),s!==void 0&&b.jsx(ue,{id:c,variant:"caption",sx:{color:u.tileTitle},children:s})]})})}function hp({editor:e,catalog:t,columns:n,dashboards:r,bindings:i,tiles:s,drillSource:o,setDrillSource:a,confirmConversion:c,exitDialog:u}){const{filterDialog:l,setFilterDialog:d}=i,{menu:f,setMenu:h}=s,g=f===void 0?void 0:e.document.tiles[f.index],m=g&&ve(g)?g:void 0,y=(()=>{if(!m||!t)return;const w=e.document.sources.find(v=>v.name===m.source)?.base??m.source,p=m.declaration.kind==="reference"?m.declaration.from:m.name;return t.sources.find(v=>v.name===w)?.views.find(v=>v.name===p)})();return b.jsxs(b.Fragment,{children:[b.jsx(lp,{open:l!==void 0,document:e.document,...l?.control?{control:l.control}:{},available:i.available,...t?{fieldsFor:i.fieldsFor}:{},onClose:()=>d(void 0),onApply:i.applyFilter,onRemove:i.dropControl}),b.jsx(fp,{anchor:f?.anchor??null,tile:f===void 0?void 0:e.document.tiles[f.index],onClose:()=>h(void 0),onCommit:w=>{const p=f?.index;p!==void 0&&e.update(v=>{v.tiles[p]=w})},onRemove:()=>{f!==void 0&&s.removeTile(f.index)},...e.document.tiles.length===1&&e.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},view:y,onDrills:()=>{a(m?.source)}}),b.jsx(Zh,{open:o!==void 0,document:e.document,source:e.document.sources.find(w=>w.name===o),givenNames:i.controlList.map(w=>w.name),dashboards:r??[],onClose:()=>a(void 0),onApply:w=>e.update(p=>{const v=[...(p.drills??[]).filter(x=>x.source!==o),...w];v.length===0?delete p.drills:p.drills=v})}),b.jsx(ns,{open:c!==void 0,onClose:()=>c?.stop(),title:"Convert this report?",description:"Saving rewrites this report in the tile layout. The builder cannot take that back; the file's history in your repository can.",actions:b.jsxs(b.Fragment,{children:[b.jsx(Oe,{onClick:()=>c?.stop(),children:"Cancel"}),b.jsx(Oe,{variant:"contained",onClick:()=>c?.go(),children:"Convert and save"})]}),children:null}),b.jsx(dh,{...u}),b.jsx(Kh,{open:s.addingTile,document:e.document,catalog:t,columns:n,onClose:s.closeAdd,onAdd:s.addTile,onAddText:s.addText})]})}var pp=Symbol.for("preact-signals");function is(){if(xt>1)xt--;else{var e,t=!1;for((function(){var i=Pi;for(Pi=void 0;i!==void 0;){var s=i.S;if(s.v===i.v)for(var o=s.t;o!==void 0;o=o.x)o.i===i.i&&(o.i=s.i);i=i.o}})();yr!==void 0;){var n=yr;for(yr=void 0,Ii++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Wc(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(Ii=0,xt--,t)throw e}}function Ce(e){if(xt>0)return e();Zs=++mp,xt++;try{return e()}finally{is()}}var br,be=void 0;function le(e){var t=be,n=br;be=void 0,br=void 0;try{return e()}finally{be=t,br=n}}var yr=void 0,xt=0,Ii=0,mp=0,Zs=0,Pi=void 0,Ri=0;function Nc(e){if(be!==void 0){var t=e.n;if(t===void 0||t.t!==be)return t={i:0,S:e,p:be.s,n:void 0,t:be,e:void 0,x:void 0,r:t},be.s!==void 0&&(be.s.n=t),be.s=t,e.n=t,32&be.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=be.s,t.n=void 0,be.s.n=t,be.s=t),t}}function Ve(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}Ve.prototype.brand=pp;Ve.prototype.h=function(){return!0};Ve.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)}))};Ve.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)}))}};Ve.prototype.subscribe=function(e){var t=this;return st(function(){var n=t.value;le(function(){return e(n)})},{name:"sub"})};Ve.prototype.valueOf=function(){return this.value};Ve.prototype.toString=function(){return this.value+""};Ve.prototype.toJSON=function(){return this.value};Ve.prototype.peek=function(){var e=this;return le(function(){return e.value})};Object.defineProperty(Ve.prototype,"value",{get:function(){var e=Nc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ii>100)throw new Error("Cycle detected");(function(n){xt!==0&&Ii===0&&n.l!==Zs&&(n.l=Zs,Pi={S:n,v:n.v,i:n.i,o:Pi})})(this),this.v=e,this.i++,Ri++,xt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{is()}}}});function zn(e,t){return new Ve(e,t)}function Wc(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 zc(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 Fc(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 sn(e,t){Ve.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Ri-1,this.f=4}sn.prototype=new Ve;sn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ri))return!0;if(this.g=Ri,this.f|=1,this.i>0&&!Wc(this))return this.f&=-2,!0;var e=be;try{zc(this),be=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 be=e,Fc(this),this.f&=-2,!0};sn.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)}Ve.prototype.S.call(this,e)};sn.prototype.U=function(e){if(this.t!==void 0&&(Ve.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)}};sn.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(sn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Nc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function fl(e,t){return new sn(e,t)}function _c(e){var t=e.m;if(e.m=void 0,typeof t=="function"){xt++;var n=be;be=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Ko(e),r}finally{be=n,is()}}}function Ko(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,_c(e)}function gp(e){if(be!==this)throw new Error("Out-of-order effect");Fc(this),be=e,this.f&=-2,8&this.f&&Ko(this),is()}function Fn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,br&&br.push(this)}Fn.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()}};Fn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,_c(this),zc(this),xt++;var e=be;return be=this,gp.bind(this,e)};Fn.prototype.N=function(){2&this.f||(this.f|=2,this.u=yr,yr=this)};Fn.prototype.d=function(){this.f|=8,1&this.f||Ko(this)};Fn.prototype.dispose=function(){this.d()};function st(e,t){var n=new Fn(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var vp=Object.create,Zo=Object.defineProperty,bp=Object.defineProperties,yp=Object.getOwnPropertyDescriptor,xp=Object.getOwnPropertyDescriptors,hl=Object.getOwnPropertySymbols,wp=Object.prototype.hasOwnProperty,kp=Object.prototype.propertyIsEnumerable,Sp=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),_n=e=>{throw TypeError(e)},Qs=(e,t,n)=>t in e?Zo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$p=(e,t)=>{for(var n in t||(t={}))wp.call(t,n)&&Qs(e,n,t[n]);if(hl)for(var n of hl(t))kp.call(t,n)&&Qs(e,n,t[n]);return e},Cp=(e,t)=>bp(e,xp(t)),pl=(e,t)=>Zo(e,"name",{value:t,configurable:!0}),jp=e=>{var t;return[,,,vp((t=void 0)!=null?t:null)]},Bc=["class","method","getter","setter","accessor","field","value","get","set"],nr=e=>e!==void 0&&typeof e!="function"?_n("Function expected"):e,Ep=(e,t,n,r,i)=>({kind:Bc[e],name:t,metadata:r,addInitializer:s=>n._?_n("Already initialized"):i.push(nr(s||null))}),qc=(e,t)=>Qs(t,Sp("metadata"),e[3]),Ht=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},Bn=(e,t,n,r,i,s)=>{var o,a,c,u,l,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,m=Bc[d+5],y=d>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(i=i.prototype),d<5&&(d>3||!h)&&yp(d<4?i:{get[n](){return et(this,s)},set[n](x){return Mt(this,s,x)}},n));d?h&&d<4&&pl(s,(d>2?"set ":d>1?"get ":"")+n):pl(i,n);for(var v=r.length-1;v>=0;v--)u=Ep(d,n,c={},e[3],w),d&&(u.static=f,u.private=h,l=u.access={has:h?x=>Op(i,x):x=>n in x},d^3&&(l.get=h?x=>(d^1?et:Mp)(x,i,d^4?s:p.get):x=>x[n]),d>2&&(l.set=h?(x,k)=>Mt(x,i,k,d^4?s:p.set):(x,k)=>x[n]=k)),a=(0,r[v])(d?d<4?h?s:p[m]:d>4?void 0:{get:p.get,set:p.set}:i,u),c._=1,d^4||a===void 0?nr(a)&&(d>4?y.unshift(a):d?h?s=a:p[m]=a:i=a):typeof a!="object"||a===null?_n("Object expected"):(nr(o=a.get)&&(p.get=o),nr(o=a.set)&&(p.set=o),nr(o=a.init)&&y.unshift(o));return d||qc(e,i),p&&Zo(i,n,p),h?d^4?s:p:i},Qo=(e,t,n)=>t.has(e)||_n("Cannot "+n),Op=(e,t)=>Object(t)!==t?_n('Cannot use the "in" operator on this value'):e.has(t),et=(e,t,n)=>(Qo(e,t,"read from private field"),n?n.call(e):t.get(e)),rr=(e,t,n)=>t.has(e)?_n("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Mt=(e,t,n,r)=>(Qo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Mp=(e,t,n)=>(Qo(e,t,"access private method"),n);function Js(e,t){if(t){let n;return fl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return fl(e)}function lt(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)=>!lt(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=>!lt(e[i],t[i]))}return!1}function ce({get:e},t){return{init(n){return zn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ee(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Js(e.bind(this)),n.set(this,r)),r.value}}function $s(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,Cp($p({},i),{enumerable:e}))})}}function zr(...e){const t=e.map(n=>st(n));return()=>t.forEach(n=>n())}var Hc,Gc,Vc,Yc,Uc,Xc,qe,Jo,Cs,eo,to,Fe,ea,js,Kc,no,ta,Es,ro,io;Xc=[ce],Uc=[ce],Yc=[ce],Vc=[$s()],Gc=[$s()],Hc=[$s()];var on=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ht(qe,5,this),rr(this,Fe),rr(this,Jo,Ht(qe,8,this)),Ht(qe,11,this),rr(this,ea,Ht(qe,12,this)),Ht(qe,15,this),rr(this,ta,Ht(qe,16,this)),Ht(qe,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return et(this,Fe,ro)}get initial(){return et(this,Fe,eo)}get previous(){return et(this,Fe,Kc)}set current(e){const t=le(()=>et(this,Fe,ro));e&&t&&this.equals(t,e)||Ce(()=>{et(this,Fe,eo)||Mt(this,Fe,e,to),Mt(this,Fe,t,no),Mt(this,Fe,e,io)})}reset(e=this.defaultValue){Ce(()=>{Mt(this,Fe,void 0,no),Mt(this,Fe,e,to),Mt(this,Fe,e,io)})}};qe=jp();Jo=new WeakMap;Fe=new WeakSet;ea=new WeakMap;ta=new WeakMap;Cs=Bn(qe,20,"#initial",Xc,Fe,Jo),eo=Cs.get,to=Cs.set;js=Bn(qe,20,"#previous",Uc,Fe,ea),Kc=js.get,no=js.set;Es=Bn(qe,20,"#current",Yc,Fe,ta),ro=Es.get,io=Es.set;Bn(qe,2,"current",Vc,on);Bn(qe,2,"initial",Gc,on);Bn(qe,2,"previous",Hc,on);qc(qe,on);function Os(e){return le(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Vt,Ap=class{constructor(){rr(this,Vt,new WeakMap)}get(e,t){var n;return e?(n=et(this,Vt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return et(this,Vt).has(e)||et(this,Vt).set(e,new Map),(r=et(this,Vt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=et(this,Vt).get(e))==null?void 0:t.clear():void 0}};Vt=new WeakMap;var Tp=Object.create,Zc=Object.defineProperty,Dp=Object.getOwnPropertyDescriptor,ml=Object.getOwnPropertySymbols,Ip=Object.prototype.hasOwnProperty,Pp=Object.prototype.propertyIsEnumerable,Qc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ss=e=>{throw TypeError(e)},gl=Math.pow,so=(e,t,n)=>t in e?Zc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rp=(e,t)=>{for(var n in t||(t={}))Ip.call(t,n)&&so(e,n,t[n]);if(ml)for(var n of ml(t))Pp.call(t,n)&&so(e,n,t[n]);return e},Lp=e=>{var t;return[,,,Tp((t=e?.[Qc("metadata")])!=null?t:null)]},Jc=["class","method","getter","setter","accessor","field","value","get","set"],ed=e=>e!==void 0&&typeof e!="function"?ss("Function expected"):e,Np=(e,t,n,r,i)=>({kind:Jc[e],name:t,metadata:r,addInitializer:s=>n._?ss("Already initialized"):i.push(ed(s||null))}),Wp=(e,t)=>so(t,Qc("metadata"),e[3]),zp=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},td=(e,t,n,r,i,s)=>{for(var o,a,c,u,l=t&7,d=!1,f=!1,h=2,g=Jc[l+5],m=e[h]||(e[h]=[]),y=(i=i.prototype,Dp(i,n)),w=r.length-1;w>=0;w--)c=Np(l,n,a={},e[3],m),c.static=d,c.private=f,u=c.access={has:p=>n in p},u.get=p=>p[n],o=(0,r[w])(y[g],c),a._=1,ed(o)&&(y[g]=o);return y&&Zc(i,n,y),i},nd=(e,t,n)=>t.has(e)||ss("Cannot "+n),Fp=(e,t,n)=>(nd(e,t,"read from private field"),t.get(e)),_p=(e,t,n)=>t.has(e)?ss("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Bp=(e,t,n,r)=>(nd(e,t,"write to private field"),t.set(e,n),n),tt=class oo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new oo(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 oo(t,n)}},gt=class Yt{constructor(t,n,r,i){this.left=t,this.top=n,this.width=r,this.height=i,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:i,width:s,height:o,scale:a}=this,c=new Yt(i+t,r+n,s,o);return c.scale=Rp({},a),c}get boundingRectangle(){const{width:t,height:n,left:r,top:i,right:s,bottom:o}=this;return{width:t,height:n,left:r,top:i,right:s,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:i}=this;return new tt((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Yt))return!1;const{left:n,top:r,width:i,height:s}=this;return n===t.left&&r===t.top&&i===t.width&&s===t.height}containsPoint(t){const{top:n,left:r,bottom:i,right:s}=this;return n<=t.y&&t.y<=i&&r<=t.x&&t.x<=s}intersectionArea(t){return t instanceof Yt?qp(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 Yt(n,t,r,i)}static delta(t,n,r={x:"center",y:"center"}){const i=(s,o)=>{const a=r[o],c=o==="x"?s.left:s.top,u=o==="x"?s.width:s.height;return a=="start"?c:a=="end"?c+u:c+u/2};return tt.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return Yt.from(t).intersectionRatio(Yt.from(n))}};function qp(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),o=i-r,a=s-n;return r<i&&n<s?o*a:0}var rd,id,ao,vi,Fr,os=class extends(ao=on,id=[Ee],rd=[Ee],ao){constructor(e){const t=tt.from(e);super(t,(n,r)=>tt.equals(n,r)),zp(Fr,5,this),_p(this,vi,0),this.velocity={x:0,y:0}}get delta(){return tt.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=tt.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-Fp(this,vi),o=a=>Math.round(a/s*100);Ce(()=>{Bp(this,vi,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(tt.from(e)),this.velocity={x:0,y:0}}};Fr=Lp(ao);vi=new WeakMap;td(Fr,2,"delta",id,os);td(Fr,2,"direction",rd,os);Wp(Fr,os);function lo({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(gl(r,2)+gl(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 sd=(e=>(e.Horizontal="x",e.Vertical="y",e))(sd||{}),od=Object.values(sd),Hp=Object.create,na=Object.defineProperty,Gp=Object.defineProperties,Vp=Object.getOwnPropertyDescriptor,Yp=Object.getOwnPropertyDescriptors,Li=Object.getOwnPropertySymbols,ad=Object.prototype.hasOwnProperty,ld=Object.prototype.propertyIsEnumerable,cd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),qn=e=>{throw TypeError(e)},co=(e,t,n)=>t in e?na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ra=(e,t)=>{for(var n in t||(t={}))ad.call(t,n)&&co(e,n,t[n]);if(Li)for(var n of Li(t))ld.call(t,n)&&co(e,n,t[n]);return e},ia=(e,t)=>Gp(e,Yp(t)),vl=(e,t)=>na(e,"name",{value:t,configurable:!0}),dd=(e,t)=>{var n={};for(var r in e)ad.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Li)for(var r of Li(e))t.indexOf(r)<0&&ld.call(e,r)&&(n[r]=e[r]);return n},Hn=e=>{var t;return[,,,Hp((t=e?.[cd("metadata")])!=null?t:null)]},ud=["class","method","getter","setter","accessor","field","value","get","set"],ir=e=>e!==void 0&&typeof e!="function"?qn("Function expected"):e,Up=(e,t,n,r,i)=>({kind:ud[e],name:t,metadata:r,addInitializer:s=>n._?qn("Already initialized"):i.push(ir(s||null))}),an=(e,t)=>co(t,cd("metadata"),e[3]),se=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},de=(e,t,n,r,i,s)=>{var o,a,c,u,l,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,m=ud[d+5],y=d>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(i=i.prototype),d<5&&(d>3||!h)&&Vp(d<4?i:{get[n](){return je(this,s)},set[n](x){return Ke(this,s,x)}},n));d?h&&d<4&&vl(s,(d>2?"set ":d>1?"get ":"")+n):vl(i,n);for(var v=r.length-1;v>=0;v--)u=Up(d,n,c={},e[3],w),d&&(u.static=f,u.private=h,l=u.access={has:h?x=>Xp(i,x):x=>n in x},d^3&&(l.get=h?x=>(d^1?je:fd)(x,i,d^4?s:p.get):x=>x[n]),d>2&&(l.set=h?(x,k)=>Ke(x,i,k,d^4?s:p.set):(x,k)=>x[n]=k)),a=(0,r[v])(d?d<4?h?s:p[m]:d>4?void 0:{get:p.get,set:p.set}:i,u),c._=1,d^4||a===void 0?ir(a)&&(d>4?y.unshift(a):d?h?s=a:p[m]=a:i=a):typeof a!="object"||a===null?qn("Object expected"):(ir(o=a.get)&&(p.get=o),ir(o=a.set)&&(p.set=o),ir(o=a.init)&&y.unshift(o));return d||an(e,i),p&&na(i,n,p),h?d^4?s:p:i},sa=(e,t,n)=>t.has(e)||qn("Cannot "+n),Xp=(e,t)=>Object(t)!==t?qn('Cannot use the "in" operator on this value'):e.has(t),je=(e,t,n)=>(sa(e,t,"read from private field"),n?n.call(e):t.get(e)),fe=(e,t,n)=>t.has(e)?qn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ke=(e,t,n,r)=>(sa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),fd=(e,t,n)=>(sa(e,t,"access private method"),n);function hd(e,t){return{plugin:e,options:t}}function _r(e){return t=>hd(e,t)}function Cr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var pd,jr,oa,bi;pd=[ce];var _e=class{constructor(e,t){this.manager=e,this.options=t,fe(this,oa,se(jr,8,this,!1)),se(jr,11,this),fe(this,bi,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return le(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=st(e.bind(this));return je(this,bi).add(t),t}destroy(){je(this,bi).forEach(e=>e())}static configure(e){return hd(this,e)}};jr=Hn(null);oa=new WeakMap;bi=new WeakMap;de(jr,4,"disabled",pd,_e,oa);an(jr,_e);var Br=class extends _e{},yi,Ms=class{constructor(e){this.manager=e,this.instances=new Map,fe(this,yi,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Cr).reduce((r,i)=>{const s=r.find(({plugin:o})=>o===i.plugin);return s?(s.options=i.options,r):[...r,i]},[]),n=t.map(({plugin:r})=>r);for(const r of je(this,yi))if(!n.includes(r)){if(r.prototype instanceof Br)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);Ke(this,yi,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()}};yi=new WeakMap;function Kp(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var ni=[],bn,yn,Zp=class extends _e{constructor(e){super(e),fe(this,bn),fe(this,yn),this.computeCollisions=this.computeCollisions.bind(this),Ke(this,yn,zn(ni)),this.destroy=zr(()=>{const t=this.computeCollisions(),n=le(()=>this.manager.dragOperation.position.current);if(t!==ni){const r=je(this,bn);if(Ke(this,bn,n),r&&n.x==r.x&&n.y==r.y)return}else Ke(this,bn,void 0);je(this,yn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){le(()=>{e?je(this,yn).value=this.computeCollisions():Ke(this,bn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return ni;const a=[],c=[];for(const u of e??n.droppables){if(u.disabled||i&&!u.accepts(i))continue;const l=t??u.collisionDetector;if(!l)continue;c.push(u),u.shape;const d=le(()=>l({droppable:u,dragOperation:r}));d&&(u.collisionPriority!=null&&(d.priority=u.collisionPriority),a.push(d))}return c.length===0?ni:(a.sort(Kp),a)}get collisions(){return je(this,yn).value}};bn=new WeakMap;yn=new WeakMap;var md,gd,vd,aa,bd,ct,la,Cn,ca,da;vd=[ce],gd=[ce],md=[ce];var kt=class Ut{constructor(t,n){fe(this,la,se(ct,8,this)),se(ct,11,this),fe(this,Cn),fe(this,ca,se(ct,12,this)),se(ct,15,this),fe(this,da,se(ct,16,this)),se(ct,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let c=i;Ke(this,Cn,zn(i)),this.manager=n,this.data=s,this.disabled=o,this.effects=()=>{var u;return[()=>{const{id:l,manager:d}=this;if(l!==c)return c=l,d?.registry.register(this),()=>d?.registry.unregister(this)},...(u=r?.())!=null?u:[]]},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=je(this,Cn).value;return(n=(t=Ut.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=Ut.pendingIdChanges)==null?void 0:n.get(this))!=null?r:je(this,Cn).peek();t!==i&&(Ut.pendingIdChanges||(Ut.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return fd(s=Ut,aa,bd).call(s)})),Ut.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)}};ct=Hn(null);aa=new WeakSet;bd=function(){const e=kt.pendingIdChanges;kt.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)je(t,Cn).value=n})};la=new WeakMap;Cn=new WeakMap;ca=new WeakMap;da=new WeakMap;de(ct,4,"manager",vd,kt,la);de(ct,4,"data",gd,kt,ca);de(ct,4,"disabled",md,kt,da);fe(kt,aa);an(ct,kt);kt.pendingIdChanges=null;var as=kt,bl=class{constructor(){this.map=zn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),i=()=>this.unregister(e,t);if(r===t)return i;r&&r.id===e&&(this.cleanupFunctions.get(r)?.(),this.cleanupFunctions.delete(r));const s=new Map(n);for(const[a,c]of n)if(c===t&&a!==e){s.delete(a);break}s.set(e,t),this.map.value=s;const o=zr(...t.effects());return this.cleanupFunctions.set(t,o),i},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;this.cleanupFunctions.get(t)?.(),this.cleanupFunctions.delete(t);const i=new Map(n);i.delete(e),this.map.value=i}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this)this.cleanupFunctions.get(e)?.(),e.destroy();this.map.value=new Map}},yd,xd,wd,kd,Sd,$d,uo,He,ua,fa,ha,vt=class extends(uo=as,$d=[ce],Sd=[ce],kd=[ce],wd=[Ee],xd=[Ee],yd=[Ee],uo){constructor(e,t){var n=e,{modifiers:r,type:i,sensors:s,plugins:o,effects:a}=n,c=dd(n,["modifiers","type","sensors","plugins","effects"]);super(ia(ra({},c),{effects:()=>{var u;return[...(u=a?.())!=null?u:[],()=>{const{manager:l,plugins:d}=this;if(!(!l||!d))for(const f of d){const{plugin:h}=Cr(f);l.registry.plugins.register(h)}}]}}),t),se(He,5,this),fe(this,ua,se(He,8,this)),se(He,11,this),fe(this,fa,se(He,12,this)),se(He,15,this),fe(this,ha,se(He,16,this,this.isDragSource?"dragging":"idle")),se(He,19,this),this.type=i,this.sensors=s,this.modifiers=r,this.alignment=c.alignment,this.plugins=o}pluginConfig(e){if(this.plugins)for(const t of this.plugins){const n=Cr(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}};He=Hn(uo);ua=new WeakMap;fa=new WeakMap;ha=new WeakMap;de(He,4,"type",$d,vt,ua);de(He,4,"modifiers",Sd,vt,fa);de(He,4,"status",kd,vt,ha);de(He,2,"isDropping",wd,vt);de(He,2,"isDragging",xd,vt);de(He,2,"isDragSource",yd,vt);an(He,vt);var Cd,jd,Ed,Od,Md,Ad,fo,Ie,pa,ma,ga,va,ba,bt=class extends(fo=as,Ad=[ce],Md=[ce],Od=[ce],Ed=[ce],jd=[ce],Cd=[Ee],fo){constructor(e,t){var n=e,{accept:r,collisionDetector:i,collisionPriority:s,type:o}=n,a=dd(n,["accept","collisionDetector","collisionPriority","type"]);super(a,t),se(Ie,5,this),fe(this,pa,se(Ie,8,this)),se(Ie,11,this),fe(this,ma,se(Ie,12,this)),se(Ie,15,this),fe(this,ga,se(Ie,16,this)),se(Ie,19,this),fe(this,va,se(Ie,20,this)),se(Ie,23,this),fe(this,ba,se(Ie,24,this)),se(Ie,27,this),this.accept=r,this.collisionDetector=i,this.collisionPriority=s,this.type=o}accepts(e){const{accept:t}=this;return t?typeof t=="function"?t(e):e.type?Array.isArray(t)?t.includes(e.type):e.type===t:!1:!0}get isDropTarget(){var e,t;return((t=(e=this.manager)==null?void 0:e.dragOperation.target)==null?void 0:t.id)===this.id}};Ie=Hn(fo);pa=new WeakMap;ma=new WeakMap;ga=new WeakMap;va=new WeakMap;ba=new WeakMap;de(Ie,4,"accept",Ad,bt,pa);de(Ie,4,"type",Md,bt,ma);de(Ie,4,"collisionDetector",Od,bt,ga);de(Ie,4,"collisionPriority",Ed,bt,va);de(Ie,4,"shape",jd,bt,ba);de(Ie,2,"isDropTarget",Cd,bt);an(Ie,bt);var Qp=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)}},Jp=class extends Qp{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function xi(e,t=!0){let n=!1;return ia(ra({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var em=class extends Br{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=zr(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||as.pendingIdChanges)return;const o=xi({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;le(()=>{var c;a?.id!==((c=e.dragOperation.target)==null?void 0:c.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Gn=(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))(Gn||{}),Vn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Vn||{}),Td,Dd,Id,Pd,Rd,Ld,Nd,it,ya;Nd=[ce],Ld=[Ee],Rd=[Ee],Pd=[Ee],Id=[Ee],Dd=[Ee],Td=[Ee];var $t=class{constructor(){se(it,5,this),fe(this,ya,se(it,8,this,"idle")),se(it,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}};it=Hn(null);ya=new WeakMap;de(it,4,"value",Nd,$t,ya);de(it,2,"current",Ld,$t);de(it,2,"idle",Rd,$t);de(it,2,"initializing",Pd,$t);de(it,2,"initialized",Id,$t);de(it,2,"dragging",Dd,$t);de(it,2,"dropped",Td,$t);an(it,$t);var tm=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=xi({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 s=xi({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",s),s.defaultPrevented?(t.reset(),n.abort(),n):(t.status.set("initializing"),t.controller=n,this.manager.renderer.rendering.then(()=>{if(n.signal.aborted)return;const{status:o}=t;o.current==="initializing"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:r,operation:t.snapshot(),cancelable:!1})})}),n)})}move(e){return le(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=xi({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,c,u,l,d;if(o.defaultPrevented)return;const f=(d=e.to)!=null?d:{x:r.position.current.x+((c=(a=e.by)==null?void 0:a.x)!=null?c:0),y:r.position.current.y+((l=(u=e.by)==null?void 0:u.y)!=null?l:0)};r.position.current=f})})}stop(e={}){return le(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:i}=r;if(!i||i.signal.aborted)return;let s;const o=()=>{const c={resume:()=>{},abort:()=>{}};return s=new Promise((u,l)=>{c.resume=u,c.abort=l}),c};i.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const c=le(()=>{var l;return((l=r.source)==null?void 0:l.status)==="dropping"}),u=()=>{r.controller===i&&(r.controller=void 0),r.reset()};if(c){const{source:l}=r,d=st(()=>{l?.status==="idle"&&(d(),u())})}else this.manager.renderer.rendering.then(u)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),s?s.then(a).catch(()=>r.reset()):a()})}},In=class extends _e{constructor(e,t){super(e,t),this.manager=e,this.options=t}},nm=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,Wd=class{constructor(e){this.options=e,fe(this,wi)}set controller(e){Ke(this,wi,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=je(this,wi))==null||t.activate(e)}};wi=new WeakMap;var yl=class extends _e{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},rm=class{constructor(e){this.draggables=new bl,this.droppables=new bl,this.plugins=new Ms(e),this.sensors=new Ms(e),this.modifiers=new Ms(e)}register(e,t){if(e instanceof vt)return this.draggables.register(e.id,e);if(e instanceof bt)return this.droppables.register(e.id,e);if(e.prototype instanceof yl)return this.modifiers.register(e,t);if(e.prototype instanceof In)return this.sensors.register(e,t);if(e.prototype instanceof _e)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof as)return e instanceof vt?this.draggables.unregister(e.id,e):e instanceof bt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof yl)return this.modifiers.unregister(e);if(e.prototype instanceof In)return this.sensors.unregister(e);if(e.prototype instanceof _e)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()}},zd,Fd,_d,Bd,qd,Hd,Gd,Vd,Yd,sr,ki,xn,$e,xa,wa,ka,Sa,$a,or;Yd=[Ee],Vd=[ce],Gd=[ce],Hd=[ce],qd=[ce],Bd=[ce],_d=[Ee],Fd=[Ee],zd=[Ee];var ht=class{constructor(e){se($e,5,this),fe(this,sr),fe(this,ki),fe(this,xn,new on(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new $t,fe(this,xa,se($e,8,this,!1)),se($e,11,this),fe(this,wa,se($e,12,this,null)),se($e,15,this),fe(this,ka,se($e,16,this,null)),se($e,19,this),fe(this,Sa,se($e,20,this,null)),se($e,23,this),fe(this,$a,se($e,24,this,[])),se($e,27,this),this.position=new os({x:0,y:0}),fe(this,or,{x:0,y:0}),Ke(this,sr,e)}get shape(){const{current:e,initial:t,previous:n}=je(this,xn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?je(this,xn).current=e:je(this,xn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=je(this,sr).registry.draggables.get(t);return n&&Ke(this,ki,n),(e=n??je(this,ki))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=je(this,sr).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(ia(ra({},this.snapshot()),{transform:n}));return Ke(this,or,n),n}snapshot(){return le(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:je(this,or),shape:this.shape?Os(this.shape):null,position:Os(this.position),status:Os(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,je(this,xn).reset(),this.position.reset({x:0,y:0}),Ke(this,or,{x:0,y:0}),this.modifiers=[]})}};$e=Hn(null);sr=new WeakMap;ki=new WeakMap;xn=new WeakMap;xa=new WeakMap;wa=new WeakMap;ka=new WeakMap;Sa=new WeakMap;$a=new WeakMap;or=new WeakMap;de($e,2,"shape",Yd,ht);de($e,4,"canceled",Vd,ht,xa);de($e,4,"activatorEvent",Gd,ht,wa);de($e,4,"sourceIdentifier",Hd,ht,ka);de($e,4,"targetIdentifier",qd,ht,Sa);de($e,4,"modifiers",Bd,ht,$a);de($e,2,"source",_d,ht);de($e,2,"target",Fd,ht);de($e,2,"transform",zd,ht);an($e,ht);var im={get rendering(){return Promise.resolve()}};function ft(e,t){return typeof e=="function"?e(t):e??t}var sm=class{constructor(e){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(d=>d.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var t;const n=e??{},r=ft(n.plugins,[]),i=ft(n.sensors,[]),s=ft(n.modifiers,[]),o=(t=n.renderer)!=null?t:im,a=new Jp(this),c=new rm(this);this.registry=c,this.monitor=a,this.renderer=o,this.actions=new tm(this),this.dragOperation=new ht(this),this.collisionObserver=new Zp(this),this.plugins=[em,...r],this.modifiers=s,this.sensors=i;const{destroy:u}=this,l=zr(()=>{var d,f,h;const g=le(()=>this.dragOperation.modifiers),m=this.modifiers;for(const y of g)m.includes(y)||y.destroy();this.dragOperation.modifiers=(h=(f=(d=this.dragOperation.source)==null?void 0:d.modifiers)==null?void 0:f.map(y=>{const{plugin:w,options:p}=Cr(y);return new w(this,p)}))!=null?h:m});this.destroy=()=>{l(),u()}}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}},Ud=e=>{throw TypeError(e)},Ca=(e,t,n)=>t.has(e)||Ud("Cannot "+n),ie=(e,t,n)=>(Ca(e,t,"read from private field"),t.get(e)),Ye=(e,t,n)=>t.has(e)?Ud("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Xe=(e,t,n,r)=>(Ca(e,t,"write to private field"),t.set(e,n),n),Xd=(e,t,n)=>(Ca(e,t,"access private method"),n);function ls(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Kd(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,o=(ls(s)?s.getKeyframes():[]).filter(t);o.length>0&&(r=[o[o.length-1],i])}return r}function cs(e){const{width:t,height:n,top:r,left:i,bottom:s,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:i,bottom:s,right:o}}function ja(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function qr(e){return"nodeType"in e}function Qe(e){var t,n,r;return e?ja(e)?e:qr(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 Ea(e){const{Document:t}=Qe(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function zt(e){return!e||ja(e)?!1:e instanceof Qe(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Zd(e){return e instanceof Qe(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Yn(e){return e?ja(e)?e.document:qr(e)?Ea(e)?e:zt(e)||Zd(e)?e.ownerDocument:document:document:document}function om(e){var t,n,r,i;const{documentElement:s}=Yn(e),o=Qe(e).visualViewport,a=(t=o?.width)!=null?t:s.clientWidth,c=(n=o?.height)!=null?n:s.clientHeight,u=(r=o?.offsetTop)!=null?r:0,l=(i=o?.offsetLeft)!=null?i:0;return{top:u,left:l,right:l+a,bottom:u+c,width:a,height:c}}function am(e,t){if(lm(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function lm(e){return e.tagName==="DETAILS"}function Er(e,t=e.getBoundingClientRect(),n=0){var r,i,s,o,a;let c=t;const{ownerDocument:u}=e,l=(r=u.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==u.documentElement;){if(!am(d)){const v=d.getBoundingClientRect(),x=n*(v.bottom-v.top),k=n*(v.right-v.left),C=n*(v.bottom-v.top),O=n*(v.right-v.left);c={top:Math.max(c.top,v.top-x),right:Math.min(c.right,v.right+k),bottom:Math.min(c.bottom,v.bottom+C),left:Math.max(c.left,v.left-O),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top}d=d.parentElement}const f=l.visualViewport,h=(i=f?.offsetTop)!=null?i:0,g=(s=f?.offsetLeft)!=null?s:0,m=(o=f?.width)!=null?o:l.innerWidth,y=(a=f?.height)!=null?a:l.innerHeight,w=n*y,p=n*m;return c={top:Math.max(c.top,h-w),right:Math.min(c.right,g+m+p),bottom:Math.min(c.bottom,h+y+w),left:Math.max(c.left,g-p),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top,c.width<0&&(c.width=0),c.height<0&&(c.height=0),c}function Pn(e){return{x:e.clientX,y:e.clientY}}var Qd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ho(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(...ho(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(...ho(i.document,t))}}catch{}return n}function Oa(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Jd(){var e,t;const n=Oa()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Ma(e){return!e||!qr(e)?!1:e instanceof Qe(e).ShadowRoot}function Ni(e){if(e&&qr(e)){let t=e.getRootNode();if(Ma(t)||t instanceof Document)return t}return Yn(e)}function Aa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function cm(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,s)=>{const o=r[s];xl(i)&&xl(o)&&(i.type!=="file"&&(i.value=o.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),wl(i)&&wl(o)&&o.width>0&&o.height>0&&i.getContext("2d")?.drawImage(o,0,0)}),n}function xl(e){return"value"in e}function wl(e){return e.tagName==="CANVAS"}function eu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(dm(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return eu(i,{x:t-s,y:n-o})}}return r}function dm(e){return e?.tagName==="IFRAME"}var po=new WeakMap;function um(e){return e.closest(`
|
|
2
2
|
input:not([disabled]),
|
|
3
3
|
select:not([disabled]),
|
|
4
4
|
textarea:not([disabled]),
|
|
5
5
|
button:not([disabled]),
|
|
6
6
|
a[href],
|
|
7
7
|
[contenteditable]:not([contenteditable="false"])
|
|
8
|
-
`)}var tu=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:i}]=e;t.removeEventListener(n,r,i)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],i=[];for(const o of n)for(const a of r){const{type:c,listener:u,options:l}=a,d=[o,a];o.addEventListener(c,u,l),this.entries.add(d),i.push(d)}const s=this.entries;return function(){for(const o of i){const[a,{type:c,listener:u,options:l}]=o;a.removeEventListener(c,u,l),s.delete(o)}}}};function Rn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function fm(e){const t=new Set;let n=Rn(e);for(;n;)t.add(n),n=Rn(n);return t}function hm(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function nu(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=hm(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function pm(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 mm(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Er(e,t);return n>0&&r>0}var gm=Qd?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Si,vm=class extends gm{constructor(e){super(t=>{if(!ie(this,Si)){Ye(this,Si,!0);return}e(t,this)}),Ue(this,Si,!1)}};Si=new WeakMap;var kl=Array.from({length:100},(e,t)=>t/100),ru=75,Yt,Wi,Et,Kt,ar,We,xr,lr,zi,iu,su,ou=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ue(this,zi),this.disconnect=()=>{var s,o,a;Ye(this,xr,!0),(s=ie(this,Et))==null||s.disconnect(),(o=ie(this,Kt))==null||o.disconnect(),ie(this,ar).disconnect(),(a=ie(this,We))==null||a.remove()},Ue(this,Yt,!0),Ue(this,Wi),Ue(this,Et),Ue(this,Kt),Ue(this,ar),Ue(this,We),Ue(this,xr,!1),Ue(this,lr,nu(()=>{var s,o,a;const{element:c}=this;if((s=ie(this,Kt))==null||s.disconnect(),ie(this,xr)||!ie(this,Yt)||!c.isConnected)return;const u=(o=c.ownerDocument)!=null?o:document,{innerHeight:l,innerWidth:d}=(a=u.defaultView)!=null?a:window,f=c.getBoundingClientRect(),h=Er(c,f),{top:g,left:m,bottom:y,right:w}=h,p=-Math.floor(g),v=-Math.floor(m),x=-Math.floor(d-w),k=-Math.floor(l-y),C=`${p}px ${x}px ${k}px ${v}px`;this.boundingClientRect=f,Ye(this,Kt,new IntersectionObserver(O=>{const[T]=O,{intersectionRect:$}=T;(T.intersectionRatio!==1?T.intersectionRatio:gt.intersectionRatio($,Er(c)))!==1&&ie(this,lr).call(this)},{threshold:kl,rootMargin:C,root:u})),ie(this,Kt).observe(c),Yd(this,zi,iu).call(this)},ru)),this.boundingClientRect=e.getBoundingClientRect(),Ye(this,Yt,mm(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(Ye(this,We,document.createElement("div")),ie(this,We).style.background="rgba(0,0,0,0.15)",ie(this,We).style.position="fixed",ie(this,We).style.pointerEvents="none",i.body.appendChild(ie(this,We))),Ye(this,ar,new IntersectionObserver(s=>{var o,a;const c=s[s.length-1],{boundingClientRect:u,isIntersecting:l}=c,{width:d,height:f}=u,h=ie(this,Yt);Ye(this,Yt,l),!(!d&&!f)&&(h&&!l?((o=ie(this,Kt))==null||o.disconnect(),this.callback(null),(a=ie(this,Et))==null||a.disconnect(),Ye(this,Et,void 0),ie(this,We)&&(ie(this,We).style.visibility="hidden")):ie(this,lr).call(this),l&&!ie(this,Et)&&(Ye(this,Et,new vm(ie(this,lr))),ie(this,Et).observe(e)))},{threshold:kl,root:i})),ie(this,Yt)&&!n.skipInitial&&this.callback(this.boundingClientRect),ie(this,ar).observe(e)}};Yt=new WeakMap;Wi=new WeakMap;Et=new WeakMap;Kt=new WeakMap;ar=new WeakMap;We=new WeakMap;xr=new WeakMap;lr=new WeakMap;zi=new WeakSet;iu=function(){ie(this,xr)||(Yd(this,zi,su).call(this),!pm(this.boundingClientRect,ie(this,Wi))&&(this.callback(this.boundingClientRect),Ye(this,Wi,this.boundingClientRect)))};su=function(){if(ie(this,We)){const{top:e,left:t,width:n,height:r}=Er(this.element);ie(this,We).style.overflow="hidden",ie(this,We).style.visibility="visible",ie(this,We).style.top=`${Math.floor(e)}px`,ie(this,We).style.left=`${Math.floor(t)}px`,ie(this,We).style.width=`${Math.floor(n)}px`,ie(this,We).style.height=`${Math.floor(r)}px`}};var ri=new WeakMap,ii=new WeakMap;function bm(e,t){let n=ri.get(e);return n||(n={disconnect:new ou(e,r=>{const i=ri.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),ri.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(ri.delete(e),n.disconnect())}}function ym(e,t){const n=new Set;for(const r of e){const i=bm(r,t);n.add(i)}return()=>n.forEach(r=>r())}function xm(e,t){var n;const r=e.ownerDocument;if(!ii.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",c=>a.forEach(u=>u(c)),{capture:!0,passive:!0,signal:o.signal}),ii.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=ii.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),ii.delete(r))})}var cr,dr,$i,mo,wm=class{constructor(e,t,n){this.callback=t,Ue(this,cr),Ue(this,dr,!1),Ue(this,$i),Ue(this,mo,nu(o=>{if(!ie(this,dr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of ie(this,$i))if(o.target.contains(a)){this.callback(ie(this,cr).boundingClientRect);break}}},ru));const r=fm(e),i=ym(r,t),s=xm(e,ie(this,mo));Ye(this,$i,r),Ye(this,cr,new ou(e,t,n)),this.disconnect=()=>{ie(this,dr)||(Ye(this,dr,!0),i(),s(),ie(this,cr).disconnect())}}};cr=new WeakMap;dr=new WeakMap;$i=new WeakMap;mo=new WeakMap;function go(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function On(e){try{go(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Sl(e){return!Qd||!e?!1:e===Un(e).scrollingElement}function au(e){var t,n;const r=Qe(e),i=Sl(e)?om(e):cs(e),s=r.visualViewport,o=Sl(e)?{height:(t=s?.height)!=null?t:r.innerHeight,width:(n=s?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},c=a.current.y<=0,u=a.current.x<=0,l=a.current.y>=a.max.y,d=a.current.x>=a.max.x;return{rect:i,position:a,isTop:c,isLeft:u,isBottom:l,isRight:d}}function km(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=au(e),{x:a,y:c}=t??{x:0,y:0},u=!n&&o.current.y+c>0,l=!r&&o.current.y+c<o.max.y,d=!i&&o.current.x+a>0,f=!s&&o.current.x+a<o.max.x;return{top:u,bottom:l,left:d,right:f,x:d||f,y:u||l}}var Ta=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))}},Fi=new Ta(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Sm=new Ta(e=>setTimeout(e,50)),_i=new Map,$m=_i.clear.bind(_i);function yt(e,t=!1){if(!t)return $l(e);let n=_i.get(e);return n||(n=$l(e),_i.set(e,n),Sm.schedule($m),n)}function $l(e){return Qe(e).getComputedStyle(e)}function Cm(e,t=yt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function jm(e,t=yt(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 Em={excludeElement:!0,escapeShadowDOM:!0};function vo(e,t=Em){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(Ea(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&Ma(a))return o(a.host);if(!zt(a))return Zd(a)?o(a.parentElement):s;if(s.has(a))return s;const c=yt(a,!0);if(r&&a===e||jm(a,c)&&s.add(a),Cm(a,c)){const{scrollingElement:u}=a.ownerDocument;return u&&s.add(u),s}return o(a.parentNode)}return e?o(e):s}function Ln(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Rn(e);for(;r;){if(r===t)return n;const i=cs(r),{x:s,y:o}=Om(r,i);n.x=n.x+i.left,n.y=n.y+i.top,n.scaleX=n.scaleX*s,n.scaleY=n.scaleY*o,r=Rn(r)}return n}function Om(e,t=cs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(zt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=yt(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function Mm(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 Or(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 ds(e){var t,n,r,i,s,o,a,c,u;const{scale:l,transform:d,translate:f}=e,h=Mm(l),g=Or(f),m=Am(d);if(!m&&!h&&!g)return null;const y={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},w={x:(r=g?.x)!=null?r:0,y:(i=g?.y)!=null?i:0},p={x:(s=m?.x)!=null?s:0,y:(o=m?.y)!=null?o:0,scaleX:(a=m?.scaleX)!=null?a:1,scaleY:(c=m?.scaleY)!=null?c:1};return{x:w.x+p.x,y:w.y+p.y,z:(u=g?.z)!=null?u:0,scaleX:y.x*p.scaleX,scaleY:y.y*p.scaleY}}function Am(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 nt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(nt||{}),Tm={x:.2,y:.2},Dm={x:10,y:10};function Im(e,t,n,r=25,i=Tm,s=Dm){const{x:o,y:a}=t,{rect:c,isTop:u,isBottom:l,isLeft:d,isRight:f}=au(e),h=Ln(e),g=yt(e,!0),m=ds(g),y=m!==null?m?.scaleX<0:!1,w=m!==null?m?.scaleY<0:!1,p=new gt(c.left*h.scaleX+h.x,c.top*h.scaleY+h.y,c.width*h.scaleX,c.height*h.scaleY),v={x:0,y:0},x={x:0,y:0},k={height:p.height*i.y,width:p.width*i.x};return k.height>0&&(!u||w&&!l)&&a<=p.top+k.height&&n?.y!==1&&o>=p.left-s.x&&o<=p.right+s.x?(v.y=w?1:-1,x.y=r*Math.abs((p.top+k.height-a)/k.height)):k.height>0&&(!l||w&&!u)&&a>=p.bottom-k.height&&n?.y!==-1&&o>=p.left-s.x&&o<=p.right+s.x&&(v.y=w?-1:1,x.y=r*Math.abs((p.bottom-k.height-a)/k.height)),k.width>0&&(!f||y&&!d)&&o>=p.right-k.width&&n?.x!==-1&&a>=p.top-s.y&&a<=p.bottom+s.y?(v.x=y?-1:1,x.x=r*Math.abs((p.right-k.width-o)/k.width)):k.width>0&&(!d||y&&!f)&&o<=p.left+k.width&&n?.x!==1&&a>=p.top-s.y&&a<=p.bottom+s.y&&(v.x=y?1:-1,x.x=r*Math.abs((p.left+k.width-o)/k.width)),{direction:v,speed:x}}function lu(e,{block:t="nearest",inline:n="nearest"}={}){if(!zt(e))return;const r=vo(e),i=[];for(const s of r){if(!zt(s))continue;const{top:o,left:a}=Pm(e,s);let c=o,u=a;for(const l of i)c-=l.scrollTop,u-=l.scrollLeft;if(t!=="none"){const l=c<s.scrollTop,d=c+e.offsetHeight>s.scrollTop+s.clientHeight;l!==d&&(t==="center"?s.scrollTop=c-s.clientHeight/2+e.offsetHeight/2:l?s.scrollTop=c:s.scrollTop=c+e.offsetHeight-s.clientHeight)}if(n!=="none"){const l=u<s.scrollLeft,d=u+e.offsetWidth>s.scrollLeft+s.clientWidth;l!==d&&(n==="center"?s.scrollLeft=u-s.clientWidth/2+e.offsetWidth/2:l?s.scrollLeft=u:s.scrollLeft=u+e.offsetWidth-s.clientWidth)}i.push(s)}}function Cl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!zt(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function Pm(e,t){const n=Cl(e),r=Cl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Rm(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left+s+(1-r)*parseFloat(n),c=e.top+o+(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,l=i?e.height*i:e.height;return{width:u,height:l,top:c,right:a+u,bottom:c+l,left:a}}function Lm(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left-s-(1-r)*parseFloat(n),c=e.top-o-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,l=i?e.height/i:e.height;return{width:u,height:l,top:c,right:a+u,bottom:c+l,left:a}}function cu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function jl(e,t=yt(e).translate,n=!0){if(n){const r=Kd(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=Or(i);if(s)return s}}}if(t){const r=Or(t);if(r)return r}return{x:0,y:0,z:0}}var Nm=new Ta(e=>setTimeout(e,0)),wr=new Map,Wm=wr.clear.bind(wr);function zm(e){const t=e.ownerDocument;let n=wr.get(t);if(n)return n;n=t.getAnimations(),wr.set(t,n),Nm.schedule(Wm);const r=n.filter(i=>ls(i.effect)&&i.effect.target===e);return wr.set(e,r),n}function Fm(e,t){const n=zm(e).filter(r=>{var i,s;if(ls(r.effect)){const{target:o}=r.effect;if((s=o&&((i=t.isValidTarget)==null?void 0:i.call(t,o)))==null||s)return r.effect.getKeyframes().some(a=>{for(const c of t.properties)if(a[c])return!0})}}).map(r=>{const{effect:i,currentTime:s}=r,o=i?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof s=="number"&&s<o)return r.currentTime=o,()=>{r.currentTime=s}});if(n.length>0)return()=>n.forEach(r=>r?.())}var mt=class extends gt{constructor(e,t={}){var n,r,i,s;const{frameTransform:o=Ln(e),ignoreTransforms:a,getBoundingClientRect:c=cs}=t,u=Fm(e,{properties:["transform","translate","scale","width","height"],isValidTarget:k=>(k!==e||Oa())&&k.contains(e)}),l=c(e);let{top:d,left:f,width:h,height:g}=l,m;const y=yt(e),w=ds(y),p={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},v=_m(e,y);u?.(),w&&(m=Lm(l,w,y.transformOrigin),(a||v)&&(d=m.top,f=m.left,h=m.width,g=m.height));const x={width:(i=m?.width)!=null?i:h,height:(s=m?.height)!=null?s:g};if(v&&!a&&m){const k=Rm(m,v,y.transformOrigin);d=k.top,f=k.left,h=k.width,g=k.height,p.x=v.scaleX,p.y=v.scaleY}o&&(a||(f*=o.scaleX,h*=o.scaleX,d*=o.scaleY,g*=o.scaleY),f+=o.x,d+=o.y),super(f,d,h,g),this.scale=p,this.intrinsicWidth=x.width,this.intrinsicHeight=x.height}};function _m(e,t){const n=e.getAnimations();if(!n.length)return null;let r,i,s,o=!1;for(const a of n){if(a.playState!=="running")continue;const c=ls(a.effect)?a.effect.getKeyframes():[],u=c[c.length-1];if(!u)continue;const{transform:l,translate:d,scale:f}=u;typeof l=="string"&&l&&(r=l,o=!0),typeof d=="string"&&d&&(i=d,o=!0),typeof f=="string"&&f&&(s=f,o=!0)}return o?ds({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function kr(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 Bm=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(kr(n))for(const[r,i]of Object.entries(e)){const s=`${t}${r}`;this.initial.has(s)||this.initial.set(s,n.style.getPropertyValue(s)),n.style.setProperty(s,typeof i=="string"?i:`${i}px`)}}remove(e,t=""){const{element:n}=this;if(kr(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(kr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function nn(e){return e?e instanceof Qe(e).Element||qr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Mr(e){if(!e)return!1;const{KeyboardEvent:t}=Qe(e.target);return e instanceof t}function qm(e){if(!e)return!1;const{PointerEvent:t}=Qe(e.target);return e instanceof t}function Hm(e){if(!nn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||Gm(e)}function Gm(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var As={};function bo(e){const t=As[e]==null?0:As[e]+1;return As[e]=t,`${e}-${t}`}var Da=({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=tt.distance(t.shape.center,n);return{id:r,value:1/i,type:Vn.PointerIntersection,priority:Gn.High}}return null},Vm=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=tt.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:Vn.ShapeIntersection,priority:Gn.Normal}}return null},du=e=>{var t;return(t=Da(e))!=null?t:Vm(e)},Um=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const s=r?gt.from(r.current.boundingRectangle).corners:void 0,o=gt.from(n.shape.boundingRectangle).corners.reduce((a,c,u)=>{var l;return a+tt.distance(tt.from(c),(l=s?.[u])!=null?l:i.current)},0)/4;return{id:n.id,value:1/o,type:Vn.Collision,priority:Gn.Normal}},Xm=Object.create,Ia=Object.defineProperty,Ym=Object.defineProperties,Km=Object.getOwnPropertyDescriptor,Zm=Object.getOwnPropertyDescriptors,Bi=Object.getOwnPropertySymbols,uu=Object.prototype.hasOwnProperty,fu=Object.prototype.propertyIsEnumerable,hu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Xn=e=>{throw TypeError(e)},yo=(e,t,n)=>t in e?Ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ar=(e,t)=>{for(var n in t||(t={}))uu.call(t,n)&&yo(e,n,t[n]);if(Bi)for(var n of Bi(t))fu.call(t,n)&&yo(e,n,t[n]);return e},Pa=(e,t)=>Ym(e,Zm(t)),El=(e,t)=>Ia(e,"name",{value:t,configurable:!0}),pu=(e,t)=>{var n={};for(var r in e)uu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Bi)for(var r of Bi(e))t.indexOf(r)<0&&fu.call(e,r)&&(n[r]=e[r]);return n},Yn=e=>{var t;return[,,,Xm((t=e?.[hu("metadata")])!=null?t:null)]},mu=["class","method","getter","setter","accessor","field","value","get","set"],ur=e=>e!==void 0&&typeof e!="function"?Xn("Function expected"):e,Qm=(e,t,n,r,i)=>({kind:mu[e],name:t,metadata:r,addInitializer:s=>n._?Xn("Already initialized"):i.push(ur(s||null))}),ln=(e,t)=>yo(t,hu("metadata"),e[3]),Pe=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},ot=(e,t,n,r,i,s)=>{var o,a,c,u,l,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,m=mu[d+5],y=d>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(i=i.prototype),d<5&&(d>3||!h)&&Km(d<4?i:{get[n](){return me(this,s)},set[n](x){return Ge(this,s,x)}},n));d?h&&d<4&&El(s,(d>2?"set ":d>1?"get ":"")+n):El(i,n);for(var v=r.length-1;v>=0;v--)u=Qm(d,n,c={},e[3],w),d&&(u.static=f,u.private=h,l=u.access={has:h?x=>Jm(i,x):x=>n in x},d^3&&(l.get=h?x=>(d^1?me:rn)(x,i,d^4?s:p.get):x=>x[n]),d>2&&(l.set=h?(x,k)=>Ge(x,i,k,d^4?s:p.set):(x,k)=>x[n]=k)),a=(0,r[v])(d?d<4?h?s:p[m]:d>4?void 0:{get:p.get,set:p.set}:i,u),c._=1,d^4||a===void 0?ur(a)&&(d>4?y.unshift(a):d?h?s=a:p[m]=a:i=a):typeof a!="object"||a===null?Xn("Object expected"):(ur(o=a.get)&&(p.get=o),ur(o=a.set)&&(p.set=o),ur(o=a.init)&&y.unshift(o));return d||ln(e,i),p&&Ia(i,n,p),h?d^4?s:p:i},Ra=(e,t,n)=>t.has(e)||Xn("Cannot "+n),Jm=(e,t)=>Object(t)!==t?Xn('Cannot use the "in" operator on this value'):e.has(t),me=(e,t,n)=>(Ra(e,t,"read from private field"),n?n.call(e):t.get(e)),Ae=(e,t,n)=>t.has(e)?Xn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ge=(e,t,n,r)=>(Ra(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),rn=(e,t,n)=>(Ra(e,t,"access private method"),n),Ol={role:"button",roleDescription:"draggable"},eg="dnd-kit-description",tg="dnd-kit-announcement",ng={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."},rg={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 ig(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function sg(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function og(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 ag=["dragover","dragmove"],lg=class extends _e{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=eg,announcement:i=tg}={},announcements:s=rg,screenReaderInstructions:o=ng,debounce:a=500}=t??{},c=n?`${r}-${n}`:bo(r),u=n?`${i}-${n}`:bo(i);let l,d,f,h;const g=(k=h)=>{!f||!k||f?.nodeValue!==k&&(f.nodeValue=k)},m=()=>Fi.schedule(g),y=cg(m,a),w=Object.entries(s).map(([k,C])=>this.manager.monitor.addEventListener(k,(O,T)=>{const $=f;if(!$)return;const D=C?.(O,T);D&&$.nodeValue!==D&&(h=D,ag.includes(k)?y():(m(),y.cancel()))})),p=()=>{let k=[];l?.isConnected||(l=sg(c,o.draggable),k.push(l)),d?.isConnected||(d=og(u),f=document.createTextNode(""),d.appendChild(f),k.push(d)),k.length>0&&document.body.append(...k)},v=new Set;function x(){for(const k of v)k()}this.registerEffect(()=>{var k;v.clear();for(const C of this.manager.registry.draggables.value){const O=(k=C.handle)!=null?k:C.element;if(O){(!l||!d)&&v.add(p),(!ig(O)||Oa())&&!O.hasAttribute("tabindex")&&v.add(()=>O.setAttribute("tabindex","0")),!O.hasAttribute("role")&&O.tagName.toLowerCase()!=="button"&&v.add(()=>O.setAttribute("role",Ol.role)),O.hasAttribute("aria-roledescription")||v.add(()=>O.setAttribute("aria-roledescription",Ol.roleDescription)),O.hasAttribute("aria-describedby")||v.add(()=>O.setAttribute("aria-describedby",c));for(const $ of["aria-pressed","aria-grabbed"]){const D=String(C.isDragging);O.getAttribute($)!==D&&v.add(()=>O.setAttribute($,D))}const T=String(C.disabled);O.getAttribute("aria-disabled")!==T&&v.add(()=>O.setAttribute("aria-disabled",T))}}v.size>0&&Fi.schedule(x)}),this.destroy=()=>{super.destroy(),l?.remove(),d?.remove(),w.forEach(k=>k())}}};function cg(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var qi=new Map,gu,vu,bu,yu,xo,Sr,wt,La,Nn,xu,wu,ku,Su,Ft=class extends(xo=Br,yu=[ce],bu=[Ee],vu=[Ee],gu=[Ee],xo){constructor(e,t){super(e,t),Pe(wt,5,this),Ae(this,Nn),Ae(this,Sr,new Set),Ae(this,La,Pe(wt,8,this,new Set)),Pe(wt,11,this),this.registerEffect(rn(this,Nn,xu))}register(e){return me(this,Sr).add(e),()=>{me(this,Sr).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 Ni((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return Ni((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}};wt=Yn(xo);Sr=new WeakMap;La=new WeakMap;Nn=new WeakSet;xu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of me(this,Sr))t.push(rn(this,Nn,wu).call(this,n,r));return()=>{for(const n of t)n()}};wu=function(e,t){let n=qi.get(e);n||(n=new Map,qi.set(e,n));let r=n.get(t);if(!r){const s=Ea(e)?rn(this,Nn,ku).call(this,e,n,t):rn(this,Nn,Su).call(this,e,n,t);if(!s)return()=>{};r=s,n.set(t,r)}r.refCount++;let i=!1;return()=>{i||(i=!0,r.refCount--,r.refCount===0&&r.cleanup())}};ku=function(e,t,n){var r;const i=e.createElement("style"),{nonce:s}=(r=this.options)!=null?r:{};s&&i.setAttribute("nonce",s),i.textContent=n,e.head.prepend(i);const o=new MutationObserver(a=>{for(const c of a)for(const u of Array.from(c.removedNodes))if(u===i){e.head.prepend(i);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),i.remove(),t.delete(n),t.size===0&&qi.delete(e)}}};Su=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:i}=r??{};if(!i)return null;const s=new i;return s.replaceSync(n),e.adoptedStyleSheets.push(s),{refCount:0,cleanup:()=>{var o;if(Ma(e)&&(o=e.host)!=null&&o.isConnected){const a=e.adoptedStyleSheets.indexOf(s);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&qi.delete(e)}}};ot(wt,4,"additionalRoots",yu,Ft,La);ot(wt,2,"sourceRoot",bu,Ft);ot(wt,2,"targetRoot",vu,Ft);ot(wt,2,"roots",gu,Ft);ln(wt,Ft);Ft.configure=_r(Ft);var us=Ft,dg=class extends _e{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(us),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},Hr="data-dnd-",wo=`${Hr}dropping`,Ne="--dnd-",pt=`${Hr}dragging`,Hi=`${Hr}placeholder`,ug=[pt,Hi,"popover","aria-pressed","aria-grabbing"],fg=["view-transition-name"],hg=`
|
|
8
|
+
`)}var tu=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:i}]=e;t.removeEventListener(n,r,i)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],i=[];for(const o of n)for(const a of r){const{type:c,listener:u,options:l}=a,d=[o,a];o.addEventListener(c,u,l),this.entries.add(d),i.push(d)}const s=this.entries;return function(){for(const o of i){const[a,{type:c,listener:u,options:l}]=o;a.removeEventListener(c,u,l),s.delete(o)}}}};function Rn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function fm(e){const t=new Set;let n=Rn(e);for(;n;)t.add(n),n=Rn(n);return t}function hm(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function nu(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=hm(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function pm(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 mm(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Er(e,t);return n>0&&r>0}var gm=Qd?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Si,vm=class extends gm{constructor(e){super(t=>{if(!ie(this,Si)){Xe(this,Si,!0);return}e(t,this)}),Ye(this,Si,!1)}};Si=new WeakMap;var kl=Array.from({length:100},(e,t)=>t/100),ru=75,Xt,Wi,Et,Kt,ar,We,xr,lr,zi,iu,su,ou=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ye(this,zi),this.disconnect=()=>{var s,o,a;Xe(this,xr,!0),(s=ie(this,Et))==null||s.disconnect(),(o=ie(this,Kt))==null||o.disconnect(),ie(this,ar).disconnect(),(a=ie(this,We))==null||a.remove()},Ye(this,Xt,!0),Ye(this,Wi),Ye(this,Et),Ye(this,Kt),Ye(this,ar),Ye(this,We),Ye(this,xr,!1),Ye(this,lr,nu(()=>{var s,o,a;const{element:c}=this;if((s=ie(this,Kt))==null||s.disconnect(),ie(this,xr)||!ie(this,Xt)||!c.isConnected)return;const u=(o=c.ownerDocument)!=null?o:document,{innerHeight:l,innerWidth:d}=(a=u.defaultView)!=null?a:window,f=c.getBoundingClientRect(),h=Er(c,f),{top:g,left:m,bottom:y,right:w}=h,p=-Math.floor(g),v=-Math.floor(m),x=-Math.floor(d-w),k=-Math.floor(l-y),C=`${p}px ${x}px ${k}px ${v}px`;this.boundingClientRect=f,Xe(this,Kt,new IntersectionObserver(O=>{const[T]=O,{intersectionRect:$}=T;(T.intersectionRatio!==1?T.intersectionRatio:gt.intersectionRatio($,Er(c)))!==1&&ie(this,lr).call(this)},{threshold:kl,rootMargin:C,root:u})),ie(this,Kt).observe(c),Xd(this,zi,iu).call(this)},ru)),this.boundingClientRect=e.getBoundingClientRect(),Xe(this,Xt,mm(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(Xe(this,We,document.createElement("div")),ie(this,We).style.background="rgba(0,0,0,0.15)",ie(this,We).style.position="fixed",ie(this,We).style.pointerEvents="none",i.body.appendChild(ie(this,We))),Xe(this,ar,new IntersectionObserver(s=>{var o,a;const c=s[s.length-1],{boundingClientRect:u,isIntersecting:l}=c,{width:d,height:f}=u,h=ie(this,Xt);Xe(this,Xt,l),!(!d&&!f)&&(h&&!l?((o=ie(this,Kt))==null||o.disconnect(),this.callback(null),(a=ie(this,Et))==null||a.disconnect(),Xe(this,Et,void 0),ie(this,We)&&(ie(this,We).style.visibility="hidden")):ie(this,lr).call(this),l&&!ie(this,Et)&&(Xe(this,Et,new vm(ie(this,lr))),ie(this,Et).observe(e)))},{threshold:kl,root:i})),ie(this,Xt)&&!n.skipInitial&&this.callback(this.boundingClientRect),ie(this,ar).observe(e)}};Xt=new WeakMap;Wi=new WeakMap;Et=new WeakMap;Kt=new WeakMap;ar=new WeakMap;We=new WeakMap;xr=new WeakMap;lr=new WeakMap;zi=new WeakSet;iu=function(){ie(this,xr)||(Xd(this,zi,su).call(this),!pm(this.boundingClientRect,ie(this,Wi))&&(this.callback(this.boundingClientRect),Xe(this,Wi,this.boundingClientRect)))};su=function(){if(ie(this,We)){const{top:e,left:t,width:n,height:r}=Er(this.element);ie(this,We).style.overflow="hidden",ie(this,We).style.visibility="visible",ie(this,We).style.top=`${Math.floor(e)}px`,ie(this,We).style.left=`${Math.floor(t)}px`,ie(this,We).style.width=`${Math.floor(n)}px`,ie(this,We).style.height=`${Math.floor(r)}px`}};var ri=new WeakMap,ii=new WeakMap;function bm(e,t){let n=ri.get(e);return n||(n={disconnect:new ou(e,r=>{const i=ri.get(e);i&&i.callbacks.forEach(s=>s(r))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),ri.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(ri.delete(e),n.disconnect())}}function ym(e,t){const n=new Set;for(const r of e){const i=bm(r,t);n.add(i)}return()=>n.forEach(r=>r())}function xm(e,t){var n;const r=e.ownerDocument;if(!ii.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",c=>a.forEach(u=>u(c)),{capture:!0,passive:!0,signal:o.signal}),ii.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=ii.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),ii.delete(r))})}var cr,dr,$i,mo,wm=class{constructor(e,t,n){this.callback=t,Ye(this,cr),Ye(this,dr,!1),Ye(this,$i),Ye(this,mo,nu(o=>{if(!ie(this,dr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of ie(this,$i))if(o.target.contains(a)){this.callback(ie(this,cr).boundingClientRect);break}}},ru));const r=fm(e),i=ym(r,t),s=xm(e,ie(this,mo));Xe(this,$i,r),Xe(this,cr,new ou(e,t,n)),this.disconnect=()=>{ie(this,dr)||(Xe(this,dr,!0),i(),s(),ie(this,cr).disconnect())}}};cr=new WeakMap;dr=new WeakMap;$i=new WeakMap;mo=new WeakMap;function go(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function On(e){try{go(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Sl(e){return!Qd||!e?!1:e===Yn(e).scrollingElement}function au(e){var t,n;const r=Qe(e),i=Sl(e)?om(e):cs(e),s=r.visualViewport,o=Sl(e)?{height:(t=s?.height)!=null?t:r.innerHeight,width:(n=s?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},c=a.current.y<=0,u=a.current.x<=0,l=a.current.y>=a.max.y,d=a.current.x>=a.max.x;return{rect:i,position:a,isTop:c,isLeft:u,isBottom:l,isRight:d}}function km(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=au(e),{x:a,y:c}=t??{x:0,y:0},u=!n&&o.current.y+c>0,l=!r&&o.current.y+c<o.max.y,d=!i&&o.current.x+a>0,f=!s&&o.current.x+a<o.max.x;return{top:u,bottom:l,left:d,right:f,x:d||f,y:u||l}}var Ta=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))}},Fi=new Ta(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Sm=new Ta(e=>setTimeout(e,50)),_i=new Map,$m=_i.clear.bind(_i);function yt(e,t=!1){if(!t)return $l(e);let n=_i.get(e);return n||(n=$l(e),_i.set(e,n),Sm.schedule($m),n)}function $l(e){return Qe(e).getComputedStyle(e)}function Cm(e,t=yt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function jm(e,t=yt(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 Em={excludeElement:!0,escapeShadowDOM:!0};function vo(e,t=Em){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(Ea(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&Ma(a))return o(a.host);if(!zt(a))return Zd(a)?o(a.parentElement):s;if(s.has(a))return s;const c=yt(a,!0);if(r&&a===e||jm(a,c)&&s.add(a),Cm(a,c)){const{scrollingElement:u}=a.ownerDocument;return u&&s.add(u),s}return o(a.parentNode)}return e?o(e):s}function Ln(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Rn(e);for(;r;){if(r===t)return n;const i=cs(r),{x:s,y:o}=Om(r,i);n.x=n.x+i.left,n.y=n.y+i.top,n.scaleX=n.scaleX*s,n.scaleY=n.scaleY*o,r=Rn(r)}return n}function Om(e,t=cs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(zt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=yt(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function Mm(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 Or(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 ds(e){var t,n,r,i,s,o,a,c,u;const{scale:l,transform:d,translate:f}=e,h=Mm(l),g=Or(f),m=Am(d);if(!m&&!h&&!g)return null;const y={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},w={x:(r=g?.x)!=null?r:0,y:(i=g?.y)!=null?i:0},p={x:(s=m?.x)!=null?s:0,y:(o=m?.y)!=null?o:0,scaleX:(a=m?.scaleX)!=null?a:1,scaleY:(c=m?.scaleY)!=null?c:1};return{x:w.x+p.x,y:w.y+p.y,z:(u=g?.z)!=null?u:0,scaleX:y.x*p.scaleX,scaleY:y.y*p.scaleY}}function Am(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 nt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(nt||{}),Tm={x:.2,y:.2},Dm={x:10,y:10};function Im(e,t,n,r=25,i=Tm,s=Dm){const{x:o,y:a}=t,{rect:c,isTop:u,isBottom:l,isLeft:d,isRight:f}=au(e),h=Ln(e),g=yt(e,!0),m=ds(g),y=m!==null?m?.scaleX<0:!1,w=m!==null?m?.scaleY<0:!1,p=new gt(c.left*h.scaleX+h.x,c.top*h.scaleY+h.y,c.width*h.scaleX,c.height*h.scaleY),v={x:0,y:0},x={x:0,y:0},k={height:p.height*i.y,width:p.width*i.x};return k.height>0&&(!u||w&&!l)&&a<=p.top+k.height&&n?.y!==1&&o>=p.left-s.x&&o<=p.right+s.x?(v.y=w?1:-1,x.y=r*Math.abs((p.top+k.height-a)/k.height)):k.height>0&&(!l||w&&!u)&&a>=p.bottom-k.height&&n?.y!==-1&&o>=p.left-s.x&&o<=p.right+s.x&&(v.y=w?-1:1,x.y=r*Math.abs((p.bottom-k.height-a)/k.height)),k.width>0&&(!f||y&&!d)&&o>=p.right-k.width&&n?.x!==-1&&a>=p.top-s.y&&a<=p.bottom+s.y?(v.x=y?-1:1,x.x=r*Math.abs((p.right-k.width-o)/k.width)):k.width>0&&(!d||y&&!f)&&o<=p.left+k.width&&n?.x!==1&&a>=p.top-s.y&&a<=p.bottom+s.y&&(v.x=y?1:-1,x.x=r*Math.abs((p.left+k.width-o)/k.width)),{direction:v,speed:x}}function lu(e,{block:t="nearest",inline:n="nearest"}={}){if(!zt(e))return;const r=vo(e),i=[];for(const s of r){if(!zt(s))continue;const{top:o,left:a}=Pm(e,s);let c=o,u=a;for(const l of i)c-=l.scrollTop,u-=l.scrollLeft;if(t!=="none"){const l=c<s.scrollTop,d=c+e.offsetHeight>s.scrollTop+s.clientHeight;l!==d&&(t==="center"?s.scrollTop=c-s.clientHeight/2+e.offsetHeight/2:l?s.scrollTop=c:s.scrollTop=c+e.offsetHeight-s.clientHeight)}if(n!=="none"){const l=u<s.scrollLeft,d=u+e.offsetWidth>s.scrollLeft+s.clientWidth;l!==d&&(n==="center"?s.scrollLeft=u-s.clientWidth/2+e.offsetWidth/2:l?s.scrollLeft=u:s.scrollLeft=u+e.offsetWidth-s.clientWidth)}i.push(s)}}function Cl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!zt(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function Pm(e,t){const n=Cl(e),r=Cl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Rm(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left+s+(1-r)*parseFloat(n),c=e.top+o+(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,l=i?e.height*i:e.height;return{width:u,height:l,top:c,right:a+u,bottom:c+l,left:a}}function Lm(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left-s-(1-r)*parseFloat(n),c=e.top-o-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,l=i?e.height/i:e.height;return{width:u,height:l,top:c,right:a+u,bottom:c+l,left:a}}function cu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function jl(e,t=yt(e).translate,n=!0){if(n){const r=Kd(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=Or(i);if(s)return s}}}if(t){const r=Or(t);if(r)return r}return{x:0,y:0,z:0}}var Nm=new Ta(e=>setTimeout(e,0)),wr=new Map,Wm=wr.clear.bind(wr);function zm(e){const t=e.ownerDocument;let n=wr.get(t);if(n)return n;n=t.getAnimations(),wr.set(t,n),Nm.schedule(Wm);const r=n.filter(i=>ls(i.effect)&&i.effect.target===e);return wr.set(e,r),n}function Fm(e,t){const n=zm(e).filter(r=>{var i,s;if(ls(r.effect)){const{target:o}=r.effect;if((s=o&&((i=t.isValidTarget)==null?void 0:i.call(t,o)))==null||s)return r.effect.getKeyframes().some(a=>{for(const c of t.properties)if(a[c])return!0})}}).map(r=>{const{effect:i,currentTime:s}=r,o=i?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof s=="number"&&s<o)return r.currentTime=o,()=>{r.currentTime=s}});if(n.length>0)return()=>n.forEach(r=>r?.())}var mt=class extends gt{constructor(e,t={}){var n,r,i,s;const{frameTransform:o=Ln(e),ignoreTransforms:a,getBoundingClientRect:c=cs}=t,u=Fm(e,{properties:["transform","translate","scale","width","height"],isValidTarget:k=>(k!==e||Oa())&&k.contains(e)}),l=c(e);let{top:d,left:f,width:h,height:g}=l,m;const y=yt(e),w=ds(y),p={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},v=_m(e,y);u?.(),w&&(m=Lm(l,w,y.transformOrigin),(a||v)&&(d=m.top,f=m.left,h=m.width,g=m.height));const x={width:(i=m?.width)!=null?i:h,height:(s=m?.height)!=null?s:g};if(v&&!a&&m){const k=Rm(m,v,y.transformOrigin);d=k.top,f=k.left,h=k.width,g=k.height,p.x=v.scaleX,p.y=v.scaleY}o&&(a||(f*=o.scaleX,h*=o.scaleX,d*=o.scaleY,g*=o.scaleY),f+=o.x,d+=o.y),super(f,d,h,g),this.scale=p,this.intrinsicWidth=x.width,this.intrinsicHeight=x.height}};function _m(e,t){const n=e.getAnimations();if(!n.length)return null;let r,i,s,o=!1;for(const a of n){if(a.playState!=="running")continue;const c=ls(a.effect)?a.effect.getKeyframes():[],u=c[c.length-1];if(!u)continue;const{transform:l,translate:d,scale:f}=u;typeof l=="string"&&l&&(r=l,o=!0),typeof d=="string"&&d&&(i=d,o=!0),typeof f=="string"&&f&&(s=f,o=!0)}return o?ds({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function kr(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 Bm=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(kr(n))for(const[r,i]of Object.entries(e)){const s=`${t}${r}`;this.initial.has(s)||this.initial.set(s,n.style.getPropertyValue(s)),n.style.setProperty(s,typeof i=="string"?i:`${i}px`)}}remove(e,t=""){const{element:n}=this;if(kr(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(kr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function nn(e){return e?e instanceof Qe(e).Element||qr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Mr(e){if(!e)return!1;const{KeyboardEvent:t}=Qe(e.target);return e instanceof t}function qm(e){if(!e)return!1;const{PointerEvent:t}=Qe(e.target);return e instanceof t}function Hm(e){if(!nn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||Gm(e)}function Gm(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var As={};function bo(e){const t=As[e]==null?0:As[e]+1;return As[e]=t,`${e}-${t}`}var Da=({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=tt.distance(t.shape.center,n);return{id:r,value:1/i,type:Vn.PointerIntersection,priority:Gn.High}}return null},Vm=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=tt.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:Vn.ShapeIntersection,priority:Gn.Normal}}return null},du=e=>{var t;return(t=Da(e))!=null?t:Vm(e)},Ym=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const s=r?gt.from(r.current.boundingRectangle).corners:void 0,o=gt.from(n.shape.boundingRectangle).corners.reduce((a,c,u)=>{var l;return a+tt.distance(tt.from(c),(l=s?.[u])!=null?l:i.current)},0)/4;return{id:n.id,value:1/o,type:Vn.Collision,priority:Gn.Normal}},Um=Object.create,Ia=Object.defineProperty,Xm=Object.defineProperties,Km=Object.getOwnPropertyDescriptor,Zm=Object.getOwnPropertyDescriptors,Bi=Object.getOwnPropertySymbols,uu=Object.prototype.hasOwnProperty,fu=Object.prototype.propertyIsEnumerable,hu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Un=e=>{throw TypeError(e)},yo=(e,t,n)=>t in e?Ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ar=(e,t)=>{for(var n in t||(t={}))uu.call(t,n)&&yo(e,n,t[n]);if(Bi)for(var n of Bi(t))fu.call(t,n)&&yo(e,n,t[n]);return e},Pa=(e,t)=>Xm(e,Zm(t)),El=(e,t)=>Ia(e,"name",{value:t,configurable:!0}),pu=(e,t)=>{var n={};for(var r in e)uu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Bi)for(var r of Bi(e))t.indexOf(r)<0&&fu.call(e,r)&&(n[r]=e[r]);return n},Xn=e=>{var t;return[,,,Um((t=e?.[hu("metadata")])!=null?t:null)]},mu=["class","method","getter","setter","accessor","field","value","get","set"],ur=e=>e!==void 0&&typeof e!="function"?Un("Function expected"):e,Qm=(e,t,n,r,i)=>({kind:mu[e],name:t,metadata:r,addInitializer:s=>n._?Un("Already initialized"):i.push(ur(s||null))}),ln=(e,t)=>yo(t,hu("metadata"),e[3]),Pe=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},ot=(e,t,n,r,i,s)=>{var o,a,c,u,l,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,m=mu[d+5],y=d>3&&(e[g-1]=[]),w=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(i=i.prototype),d<5&&(d>3||!h)&&Km(d<4?i:{get[n](){return me(this,s)},set[n](x){return Ge(this,s,x)}},n));d?h&&d<4&&El(s,(d>2?"set ":d>1?"get ":"")+n):El(i,n);for(var v=r.length-1;v>=0;v--)u=Qm(d,n,c={},e[3],w),d&&(u.static=f,u.private=h,l=u.access={has:h?x=>Jm(i,x):x=>n in x},d^3&&(l.get=h?x=>(d^1?me:rn)(x,i,d^4?s:p.get):x=>x[n]),d>2&&(l.set=h?(x,k)=>Ge(x,i,k,d^4?s:p.set):(x,k)=>x[n]=k)),a=(0,r[v])(d?d<4?h?s:p[m]:d>4?void 0:{get:p.get,set:p.set}:i,u),c._=1,d^4||a===void 0?ur(a)&&(d>4?y.unshift(a):d?h?s=a:p[m]=a:i=a):typeof a!="object"||a===null?Un("Object expected"):(ur(o=a.get)&&(p.get=o),ur(o=a.set)&&(p.set=o),ur(o=a.init)&&y.unshift(o));return d||ln(e,i),p&&Ia(i,n,p),h?d^4?s:p:i},Ra=(e,t,n)=>t.has(e)||Un("Cannot "+n),Jm=(e,t)=>Object(t)!==t?Un('Cannot use the "in" operator on this value'):e.has(t),me=(e,t,n)=>(Ra(e,t,"read from private field"),n?n.call(e):t.get(e)),Ae=(e,t,n)=>t.has(e)?Un("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ge=(e,t,n,r)=>(Ra(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),rn=(e,t,n)=>(Ra(e,t,"access private method"),n),Ol={role:"button",roleDescription:"draggable"},eg="dnd-kit-description",tg="dnd-kit-announcement",ng={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."},rg={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 ig(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function sg(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function og(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 ag=["dragover","dragmove"],lg=class extends _e{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=eg,announcement:i=tg}={},announcements:s=rg,screenReaderInstructions:o=ng,debounce:a=500}=t??{},c=n?`${r}-${n}`:bo(r),u=n?`${i}-${n}`:bo(i);let l,d,f,h;const g=(k=h)=>{!f||!k||f?.nodeValue!==k&&(f.nodeValue=k)},m=()=>Fi.schedule(g),y=cg(m,a),w=Object.entries(s).map(([k,C])=>this.manager.monitor.addEventListener(k,(O,T)=>{const $=f;if(!$)return;const D=C?.(O,T);D&&$.nodeValue!==D&&(h=D,ag.includes(k)?y():(m(),y.cancel()))})),p=()=>{let k=[];l?.isConnected||(l=sg(c,o.draggable),k.push(l)),d?.isConnected||(d=og(u),f=document.createTextNode(""),d.appendChild(f),k.push(d)),k.length>0&&document.body.append(...k)},v=new Set;function x(){for(const k of v)k()}this.registerEffect(()=>{var k;v.clear();for(const C of this.manager.registry.draggables.value){const O=(k=C.handle)!=null?k:C.element;if(O){(!l||!d)&&v.add(p),(!ig(O)||Oa())&&!O.hasAttribute("tabindex")&&v.add(()=>O.setAttribute("tabindex","0")),!O.hasAttribute("role")&&O.tagName.toLowerCase()!=="button"&&v.add(()=>O.setAttribute("role",Ol.role)),O.hasAttribute("aria-roledescription")||v.add(()=>O.setAttribute("aria-roledescription",Ol.roleDescription)),O.hasAttribute("aria-describedby")||v.add(()=>O.setAttribute("aria-describedby",c));for(const $ of["aria-pressed","aria-grabbed"]){const D=String(C.isDragging);O.getAttribute($)!==D&&v.add(()=>O.setAttribute($,D))}const T=String(C.disabled);O.getAttribute("aria-disabled")!==T&&v.add(()=>O.setAttribute("aria-disabled",T))}}v.size>0&&Fi.schedule(x)}),this.destroy=()=>{super.destroy(),l?.remove(),d?.remove(),w.forEach(k=>k())}}};function cg(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var qi=new Map,gu,vu,bu,yu,xo,Sr,wt,La,Nn,xu,wu,ku,Su,Ft=class extends(xo=Br,yu=[ce],bu=[Ee],vu=[Ee],gu=[Ee],xo){constructor(e,t){super(e,t),Pe(wt,5,this),Ae(this,Nn),Ae(this,Sr,new Set),Ae(this,La,Pe(wt,8,this,new Set)),Pe(wt,11,this),this.registerEffect(rn(this,Nn,xu))}register(e){return me(this,Sr).add(e),()=>{me(this,Sr).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 Ni((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return Ni((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}};wt=Xn(xo);Sr=new WeakMap;La=new WeakMap;Nn=new WeakSet;xu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of me(this,Sr))t.push(rn(this,Nn,wu).call(this,n,r));return()=>{for(const n of t)n()}};wu=function(e,t){let n=qi.get(e);n||(n=new Map,qi.set(e,n));let r=n.get(t);if(!r){const s=Ea(e)?rn(this,Nn,ku).call(this,e,n,t):rn(this,Nn,Su).call(this,e,n,t);if(!s)return()=>{};r=s,n.set(t,r)}r.refCount++;let i=!1;return()=>{i||(i=!0,r.refCount--,r.refCount===0&&r.cleanup())}};ku=function(e,t,n){var r;const i=e.createElement("style"),{nonce:s}=(r=this.options)!=null?r:{};s&&i.setAttribute("nonce",s),i.textContent=n,e.head.prepend(i);const o=new MutationObserver(a=>{for(const c of a)for(const u of Array.from(c.removedNodes))if(u===i){e.head.prepend(i);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),i.remove(),t.delete(n),t.size===0&&qi.delete(e)}}};Su=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:i}=r??{};if(!i)return null;const s=new i;return s.replaceSync(n),e.adoptedStyleSheets.push(s),{refCount:0,cleanup:()=>{var o;if(Ma(e)&&(o=e.host)!=null&&o.isConnected){const a=e.adoptedStyleSheets.indexOf(s);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&qi.delete(e)}}};ot(wt,4,"additionalRoots",yu,Ft,La);ot(wt,2,"sourceRoot",bu,Ft);ot(wt,2,"targetRoot",vu,Ft);ot(wt,2,"roots",gu,Ft);ln(wt,Ft);Ft.configure=_r(Ft);var us=Ft,dg=class extends _e{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(us),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},Hr="data-dnd-",wo=`${Hr}dropping`,Ne="--dnd-",pt=`${Hr}dragging`,Hi=`${Hr}placeholder`,ug=[pt,Hi,"popover","aria-pressed","aria-grabbing"],fg=["view-transition-name"],hg=`
|
|
9
9
|
:is(:root,:host) [${pt}] {
|
|
10
10
|
position: fixed !important;
|
|
11
11
|
pointer-events: none !important;
|
|
@@ -64,16 +64,16 @@ import{r as S,b4 as Uf,b5 as Xf,j as b,b6 as _o,aA as ye,ap as at,T as ue,aq as
|
|
|
64
64
|
display: none;
|
|
65
65
|
visibility: hidden;
|
|
66
66
|
}
|
|
67
|
-
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function pg(e,t="hidden"){return le(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=mg(n,r.registry.droppables),s=[],o=cm(n),{remove:a}=o;return gg(i,o,s),vg(o,t),o.remove=()=>{s.forEach(c=>c()),a.call(o)},o})}function mg(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${Hr}${bo("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function gg(e,t,n){for(const[r,i]of e){if(!r.element)continue;const s=`[${i}]`,o=t.matches(s)?t:t.querySelector(s);if(r.element.removeAttribute(i),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(i),po.set(a,o),n.push(()=>{po.delete(a),r.proxy=void 0})}}function vg(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Hi,t)}function $u(e,t){return e===t?!0:Rn(e)===Rn(t)}function Ml(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&nn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>On(t))}function ko(e){return e.tagName==="TR"}function bg(e,t,n){const r=new MutationObserver(i=>{let s=!1;for(const o of i){if(o.target!==e){s=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||ug.includes(a))continue;const c=e.getAttribute(a);if(a==="style"){if(kr(e)&&kr(t)){const u=e.style;for(const l of Array.from(t.style))u.getPropertyValue(l)===""&&t.style.removeProperty(l);for(const l of Array.from(u)){if(fg.includes(l)||l.startsWith(Ne))continue;const d=u.getPropertyValue(l);t.style.setProperty(l,d)}}}else c!==null?t.setAttribute(a,c):t.removeAttribute(a)}s&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function yg(e,t,n){const r=new MutationObserver(i=>{for(const s of i)if(s.addedNodes.length!==0)for(const o of Array.from(s.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),On(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),On(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),On(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function xg(e){return new ResizeObserver(()=>{var t,n,r;const i=new mt(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-i.width)*s.x+e.delta.x,a=(e.height-i.height)*s.y+e.delta.y,c=Jd();if(e.styles.set({width:i.width-e.widthOffset,height:i.height-e.heightOffset,top:e.top+a+c.y,left:e.left+o+c.x},Ne),(n=e.getElementMutationObserver())==null||n.takeRecords(),ko(e.element)&&ko(e.placeholder)){const m=Array.from(e.element.cells),y=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(m.map(w=>w.style.width));for(const[w,p]of m.entries()){const v=y[w];p.style.width=`${v.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},l=e.left+o+c.x+u.x,d=e.top+a+c.y+u.y,f=i.width-e.widthOffset,h=i.height-e.heightOffset,g=e.frameTransform;e.dragOperation.shape=new gt(l*g.scaleX+g.x,d*g.scaleY+g.y,f*g.scaleX,h*g.scaleY)})}var wg=250,kg="ease";function Sg(e){var t,n,r,i;const{animation:s}=e;if(typeof s=="function"){const p=s({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(p).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=wg,easing:a=kg}=s??{};On(e.feedbackElement);const[,c]=(t=Kd(e.feedbackElement,p=>"translate"in p))!=null?t:[];c?.pause();const u=(n=e.placeholder)!=null?n:e.element,l={frameTransform:$u(e.feedbackElement,u)?null:void 0},d=new mt(e.feedbackElement,l),f=(r=Or(yt(e.feedbackElement).translate))!=null?r:e.translate,h=new mt(u,l),g=gt.delta(d,h,e.alignment),m={x:f.x-g.x,y:f.y-g.y},y=Math.round(d.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},w=Math.round(d.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Ne),e.feedbackElement.setAttribute(wo,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),cu({element:e.feedbackElement,keyframes:Pa(Ar(Ar({},y),w),{translate:[`${f.x}px ${f.y}px 0`,`${m.x}px ${m.y}px 0`]}),options:{duration:Aa(Qe(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(wo),c?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Cu,So,Tr,Na,Ci,ju,Eu,Wn=class extends(So=_e,Cu=[ce],So){constructor(e,t){super(e,t),Ae(this,Ci),Ae(this,Na,Pe(Tr,8,this)),Pe(Tr,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(us),r=n?.register(hg);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(rn(this,Ci,ju).bind(this,n)),this.registerEffect(rn(this,Ci,Eu))}};Tr=Yn(So);Na=new WeakMap;Ci=new WeakSet;ju=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Ni(t);if(n)return e.addRoot(n)};Eu=function(){var e,t,n,r,i,s,o;const{state:a,manager:c,options:u}=this,{dragOperation:l}=c,{position:d,source:f,status:h}=l;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:g}=f,m=f.pluginConfig(Wn),y=(t=(e=m?.feedback)!=null?e:u?.feedback)!=null?t:"default",w=typeof y=="function"?y(f,c):y;if(!g||w==="none"||!h.initialized||h.initializing)return;const{initial:p}=a,v=(n=this.overlay)!=null?n:g,x=Ln(v),k=Ln(g),C=!$u(g,v),O=new mt(g,{frameTransform:C?k:null,ignoreTransforms:!C}),T={x:k.scaleX/x.scaleX,y:k.scaleY/x.scaleY};let{width:$,height:D,top:z,left:N}=O;C&&($=$/T.x,D=D/T.y);const L=new Bm(v),B=yt(g),{transition:H,translate:U,boxSizing:Z,paddingBlockStart:ne,paddingBlockEnd:J,paddingInlineStart:M,paddingInlineEnd:F,borderInlineStartWidth:W,borderInlineEndWidth:R,borderBlockStartWidth:_,borderBlockEndWidth:Y}=B,Q=H.split(",").filter(ge=>!/^\s*(transform|translate|scale)\b/.test(ge)).join(","),E=ds(B),j=B.transform,A=w==="clone",K=Z==="content-box",V=K?parseInt(M)+parseInt(F)+parseInt(W)+parseInt(R):0,te=K?parseInt(ne)+parseInt(J)+parseInt(_)+parseInt(Y):0,G=w!=="move"&&!this.overlay?pg(f,A?"clone":"hidden"):null,ae=le(()=>Mr(c.dragOperation.activatorEvent));if(!p.translate){if(this.overlay&&E)p.translate={x:E.x,y:E.y};else if(U!=="none"){const ge=Or(U);ge&&(p.translate=ge)}}if(!p.transformOrigin){const ge=le(()=>d.current),Le=N+((r=E?.x)!=null?r:0),Xe=z+((i=E?.y)!=null?i:0);p.transformOrigin={x:(ge.x-Le*x.scaleX-x.x)/($*x.scaleX),y:(ge.y-Xe*x.scaleY-x.y)/(D*x.scaleY)}}const{transformOrigin:ee}=p,I=z*x.scaleY+x.y,re=N*x.scaleX+x.x;if(!p.coordinates&&(p.coordinates={x:re,y:I},T.x!==1||T.y!==1)){const{scaleX:ge,scaleY:Le}=k,{x:Xe,y:jt}=ee;p.coordinates.x+=($*ge-$)*Xe,p.coordinates.y+=(D*Le-D)*jt}p.dimensions||(p.dimensions={width:$,height:D}),p.frameTransform||(p.frameTransform=x);const he={x:p.coordinates.x-re,y:p.coordinates.y-I},we={width:(p.dimensions.width*p.frameTransform.scaleX-$*x.scaleX)*ee.x,height:(p.dimensions.height*p.frameTransform.scaleY-D*x.scaleY)*ee.y},X={x:he.x/x.scaleX+we.width,y:he.y/x.scaleY+we.height},P={left:N+X.x,top:z+X.y};v.setAttribute(pt,"true");const q=le(()=>l.transform),oe=(s=p.translate)!=null?s:{x:0,y:0},pe=q.x*x.scaleX+oe.x,Be=q.y*x.scaleY+oe.y,Zn=Jd();L.set({width:$-V,height:D-te,top:P.top+Zn.y,left:P.left+Zn.x,translate:`${pe}px ${Be}px 0`,transform:this.overlay?"none":j,transition:Q?`${Q}, translate 0ms linear`:"translate 0ms linear",scale:C?`${T.x} ${T.y}`:"","transform-origin":`${ee.x*100}% ${ee.y*100}%`},Ne),G&&(g.insertAdjacentElement("afterend",G),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(g)),go(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),On(v),v.addEventListener("beforetoggle",Ml));let Bt,dn,qt;const Zr=xg({placeholder:G,element:g,feedbackElement:v,frameTransform:x,transformOrigin:ee,width:$,height:D,top:z,left:N,widthOffset:V,heightOffset:te,delta:X,styles:L,dragOperation:l,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>Bt,getSavedCellWidths:()=>qt,setSavedCellWidths:ge=>{qt=ge}}),Qr=new mt(v);le(()=>l.shape=Qr);const Ct=Qe(v),tl=ge=>{this.manager.actions.stop({event:ge})},Bf=Aa(Ct);ae&&Ct.addEventListener("resize",tl),le(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),G&&(Zr.observe(G),Bt=bg(g,G,A),dn=yg(g,G,v));const nl=(o=c.dragOperation.source)==null?void 0:o.id,qf=()=>{var ge;if(!ae||nl==null)return;const Le=c.registry.draggables.get(nl),Xe=(ge=Le?.handle)!=null?ge:Le?.element;zt(Xe)&&Xe.focus()},bs=()=>{Bt?.disconnect(),dn?.disconnect(),Zr.disconnect(),Ct.removeEventListener("resize",tl),go(v)&&(v.removeEventListener("beforetoggle",Ml),v.removeAttribute("popover")),v.removeAttribute(pt),L.reset();const ge=()=>{var Le;if(qt&&ko(g)){const ys=Array.from(g.cells);for(const[Jr,un]of ys.entries())un.style.width=(Le=qt[Jr])!=null?Le:""}f.status="idle";const Xe=a.current.translate!=null,jt=l.status.dragging;G&&(!jt&&Xe||G.parentElement!==v.parentElement)&&v.isConnected&&G.replaceWith(v),G?.remove()};v===this.overlay?setTimeout(ge,0):ge()},Hf=u?.dropAnimation,rl=this,Gf=zr(()=>{var ge,Le,Xe;const{transform:jt,status:ys}=l;if(!(!jt.x&&!jt.y&&!a.current.translate)&&ys.dragging){const Jr=(ge=p.translate)!=null?ge:{x:0,y:0},un={x:jt.x/x.scaleX+Jr.x,y:jt.y/x.scaleY+Jr.y},il=a.current.translate,Vf=le(()=>l.modifiers),xs=le(()=>{var Qn;return(Qn=l.shape)==null?void 0:Qn.current}),ws=u?.keyboardTransition,sl=ae&&!Bf&&ws!==null?`${(Le=ws?.duration)!=null?Le:250}ms ${(Xe=ws?.easing)!=null?Xe:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:Q?`${Q}, translate ${sl}`:`translate ${sl}`,translate:`${un.x}px ${un.y}px 0`},Ne),Bt?.takeRecords(),xs&&xs!==Qr&&il&&!Vf.length){const Qn=tt.delta(un,il);l.shape=gt.from(xs.boundingRectangle).translate(Qn.x*x.scaleX,Qn.y*x.scaleY)}else l.shape=new mt(v);a.current.translate=un}},function(){if(l.status.dropped){this.dispose(),f.status="dropping";const ge=m?.dropAnimation!==void 0?m.dropAnimation:rl.dropAnimation!==void 0?rl.dropAnimation:Hf;let Le=a.current.translate;const Xe=Le!=null;if(!Le&&g!==v&&(Le={x:0,y:0}),!Le||ge===null){bs();return}c.renderer.rendering.then(()=>{Sg({source:f,element:g,feedbackElement:v,placeholder:G,translate:Le,moved:Xe,transition:H,alignment:f.alignment,styles:L,animation:ge??void 0,getElementMutationObserver:()=>Bt,cleanup:bs,restoreFocus:qf})})}});return()=>{bs(),Gf()}};ot(Tr,4,"overlay",Cu,Wn,Na);ln(Tr,Wn);Wn.configure=_r(Wn);var Wa=Wn,Jn=!0,$g=!1,Ou,Mu,Au,Tu,Dt,za,Fa;Tu=(Au=[ce],nt.Forward),Mu=(Ou=[ce],nt.Reverse);var Dr=class{constructor(){Ae(this,za,Pe(Dt,8,this,Jn)),Pe(Dt,11,this),Ae(this,Fa,Pe(Dt,12,this,Jn)),Pe(Dt,15,this)}isLocked(e){return e===nt.Idle?!1:e==null?this[nt.Forward]===Jn&&this[nt.Reverse]===Jn:this[e]===Jn}unlock(e){e!==nt.Idle&&(this[e]=$g)}};Dt=Yn(null);za=new WeakMap;Fa=new WeakMap;ot(Dt,4,Tu,Au,Dr,za);ot(Dt,4,Mu,Ou,Dr,Fa);ln(Dt,Dr);var Cg=[nt.Forward,nt.Reverse],Al=class{constructor(){this.x=new Dr,this.y=new Dr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},jg=class extends _e{constructor(e){super(e);const t=zn(new Al);let n=null;this.signal=t,st(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new Al;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:Tl(i.x,n.x),y:Tl(i.y,n.y)},o=t.peek();Ce(()=>{for(const a of od)for(const c of Cg)s[a]===c&&o[a].unlock(c);t.value=o})}n=i})}get current(){return this.signal.peek()}};function Tl(e,t){return Math.sign(e-t)}var Du,$o,Ir,_a,Ot,Co,Gr=class extends($o=Br,Du=[ce],$o){constructor(e){super(e),Ae(this,_a,Pe(Ir,8,this,!1)),Pe(Ir,11,this),Ae(this,Ot),Ae(this,Co,()=>{if(!me(this,Ot))return;const{element:s,by:o}=me(this,Ot);o.y&&(s.scrollTop+=o.y),o.x&&(s.scrollLeft+=o.x)}),this.scroll=(s,o)=>{var a;if(this.disabled)return!1;const c=this.getScrollableElements();if(!c)return Ge(this,Ot,void 0),!1;const{position:u}=this.manager.dragOperation,l=u?.current;if(l){const{by:d}=s??{},f=d?{x:Dl(d.x),y:Dl(d.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const g of c){const m=km(g,d);if(m.x||m.y){const{speed:y,direction:w}=Im(g,l,f,o?.acceleration,o?.threshold);if(h)for(const p of od)h[p].isLocked(w[p])&&(y[p]=0,w[p]=0);if(w.x||w.y){const{x:p,y:v}=d??w,x=p*y.x,k=v*y.y;if(x||k){const C=(a=me(this,Ot))==null?void 0:a.by;if(this.autoScrolling&&C&&(C.x&&!x||C.y&&!k))continue;return Ge(this,Ot,{element:g,by:{x,y:k}}),Fi.schedule(me(this,Co)),!0}}}}}return Ge(this,Ot,void 0),!1};let t=null,n=null;const r=Js(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=eu(Ni(o?.element),s.current);return a&&(t=a),a??t}),i=Js(()=>{const s=r.value,{documentElement:o}=Un(s);if(!s||s===o){const{target:a}=e.dragOperation,c=a?.element;if(c){const u=vo(c,{excludeElement:!1});return n=u,u}}if(s){const a=vo(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},lt);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new jg(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!Mr(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};Ir=Yn($o);_a=new WeakMap;Ot=new WeakMap;Co=new WeakMap;ot(Ir,4,"autoScrolling",Du,Gr,_a);ln(Ir,Gr);function Dl(e){return e>0?nt.Forward:e<0?nt.Reverse:nt.Idle}var Eg=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))}},Og=new Eg(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Mg=10,jo=class extends _e{constructor(e,t){super(e,t);const n=e.registry.plugins.get(Gr);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=st(()=>{var r,i,s;if(this.disabled)return;const{position:o,status:a}=e.dragOperation;if(a.dragging){const c={acceleration:(r=this.options)==null?void 0:r.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(s=this.options)==null?void 0:s.threshold};if(n.scroll(void 0,c)){n.autoScrolling=!0;const u=setInterval(()=>Og.schedule(()=>n.scroll(void 0,c)),Mg);return()=>{clearInterval(u)}}else n.autoScrolling=!1}})}};jo.configure=_r(jo);var Iu=jo,Il={capture:!0,passive:!0},fr,Ag=class extends Br{constructor(e){super(e),Ae(this,fr),this.handleScroll=()=>{me(this,fr)==null&&Ge(this,fr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ge(this,fr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=st(()=>{var n,r,i;if(t.status.dragging){const s=(i=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?i:document;return s.addEventListener("scroll",this.handleScroll,Il),()=>{s.removeEventListener("scroll",this.handleScroll,Il)}}})}};fr=new WeakMap;var Tg="* { user-select: none !important; -webkit-user-select: none !important; }",Dg=class extends _e{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(us),n=t?.register(Tg);if(this.destroy=st(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Ts(),document.addEventListener("selectionchange",Ts,{capture:!0}),()=>{document.removeEventListener("selectionchange",Ts,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Ts(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var hr=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}}),wn,Gi=class extends In{constructor(e,t){super(e),this.manager=e,this.options=t,Ae(this,wn,[]),this.listeners=new tu,this.handleSourceKeyDown=(n,r,i)=>{if(this.disabled||n.defaultPrevented||!nn(n.target)||r.disabled)return;const{keyboardCodes:s=hr.keyboardCodes,preventActivation:o=hr.preventActivation}=i??{};s.start.includes(n.code)&&this.manager.dragOperation.status.idle&&(o?.(n,r)||this.handleStart(n,r,i))}}bind(e,t=this.options){return st(()=>{var n;const r=(n=e.handle)!=null?n:e.element,i=s=>{Mr(s)&&this.handleSourceKeyDown(s,e,t)};if(r)return r.addEventListener("keydown",i),()=>{r.removeEventListener("keydown",i)}})}handleStart(e,t,n){const{element:r}=t;if(!r)throw new Error("Source draggable does not have an associated element");e.preventDefault(),e.stopImmediatePropagation(),lu(r);const{center:i}=new mt(r);if(this.manager.actions.start({event:e,coordinates:{x:i.x,y:i.y},source:t}).signal.aborted)return this.cleanup();this.sideEffects();const s=Un(r),o=[this.listeners.bind(s,[{type:"keydown",listener:a=>this.handleKeyDown(a,t,n),options:{capture:!0}}])];me(this,wn).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=hr.keyboardCodes}=n??{};if(fn(e,[...r.end,...r.cancel])){e.preventDefault();const i=fn(e,r.cancel);this.handleEnd(e,i);return}fn(e,r.up)?this.handleMove("up",e):fn(e,r.down)&&this.handleMove("down",e),fn(e,r.left)?this.handleMove("left",e):fn(e,r.right)&&this.handleMove("right",e)}handleEnd(e,t){this.manager.actions.stop({event:e,canceled:t}),this.cleanup()}handleMove(e,t){var n,r;const{shape:i}=this.manager.dragOperation,s=t.shiftKey?5:1;let o={x:0,y:0},a=(r=(n=this.options)==null?void 0:n.offset)!=null?r:hr.offset;if(typeof a=="number"&&(a={x:a,y:a}),!!i){switch(e){case"up":o={x:0,y:-a.y*s};break;case"down":o={x:0,y:a.y*s};break;case"left":o={x:-a.x*s,y:0};break;case"right":o={x:a.x*s,y:0};break}(o.x||o.y)&&(t.preventDefault(),this.manager.actions.move({event:t,by:o}))}}sideEffects(){const e=this.manager.registry.plugins.get(Iu);e?.disabled===!1&&(e.disable(),me(this,wn).push(()=>{e.enable()}))}cleanup(){me(this,wn).forEach(e=>e()),Ge(this,wn,[])}destroy(){this.cleanup(),this.listeners.clear()}};wn=new WeakMap;Gi.configure=_r(Gi);Gi.defaults=hr;var Pu=Gi;function fn(e,t){return t.includes(e.code)}var Zt,Ig=class extends Wd{constructor(){super(...arguments),Ae(this,Zt)}onEvent(e){switch(e.type){case"pointerdown":Ge(this,Zt,Pn(e));break;case"pointermove":if(!me(this,Zt))return;const{x:t,y:n}=Pn(e),r={x:t-me(this,Zt).x,y:n-me(this,Zt).y},{tolerance:i}=this.options;if(i&&lo(r,i)){this.abort();return}lo(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Ge(this,Zt,void 0)}};Zt=new WeakMap;var kn,Qt,Pg=class extends Wd{constructor(){super(...arguments),Ae(this,kn),Ae(this,Qt)}onEvent(e){switch(e.type){case"pointerdown":Ge(this,Qt,Pn(e)),Ge(this,kn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!me(this,Qt))return;const{x:t,y:n}=Pn(e),r={x:t-me(this,Qt).x,y:n-me(this,Qt).y};lo(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){me(this,kn)&&(clearTimeout(me(this,kn)),Ge(this,Qt,void 0),Ge(this,kn,void 0))}};kn=new WeakMap;Qt=new WeakMap;var jn=class{};jn.Delay=Pg;jn.Distance=Ig;var Eo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&nn(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new jn.Delay({value:250,tolerance:5})]:Hm(i)&&!e.defaultPrevented?[new jn.Delay({value:200,tolerance:0})]:[new jn.Delay({value:200,tolerance:10}),new jn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!nn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=um(r);return i===t.element?!1:!!i}}),Sn,Vi=class extends In{constructor(e,t){super(e),this.manager=e,this.options=t,Ae(this,Sn,new Set),this.listeners=new tu,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=Eo.activationConstraints}=n??{};return typeof r=="function"?r(e,t):r}bind(e,t=this.options){return st(()=>{var n;const r=new AbortController,{signal:i}=r,s=a=>{qm(a)&&this.handlePointerDown(a,e,t)};let o=[(n=e.handle)!=null?n:e.element];t?.activatorElements&&(Array.isArray(t.activatorElements)?o=t.activatorElements:o=t.activatorElements(e));for(const a of o)a&&(Ng(a.ownerDocument.defaultView),a.addEventListener("pointerdown",s,{signal:i}));return()=>r.abort()})}handlePointerDown(e,t,n){if(this.disabled||!e.isPrimary||e.button!==0||!nn(e.target)||t.disabled||Rg(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=Eo.preventActivation}=n??{};if(r?.(e,t))return;const{target:i}=e,s=zt(i)&&i.draggable&&i.getAttribute("draggable")==="true",o=Ln(t.element),{x:a,y:c}=Pn(e);this.initialCoordinates={x:a*o.scaleX+o.x,y:c*o.scaleY+o.y};const u=this.activationConstraints(e,t,n);e.sensor=this;const l=new nm(u,g=>this.handleStart(t,g));l.signal.onabort=()=>this.handleCancel(e),l.onEvent(e),this.controller=l;const d=ho(),f=this.listeners.bind(d,[{type:"pointermove",listener:g=>this.handlePointerMove(g,t)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:s?this.handleCancel:si,options:{capture:!0}}]),h=()=>{f(),this.initialCoordinates=void 0};me(this,Sn).add(h)}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=Pn(e),s=Ln(t.element);i.x=i.x*s.scaleX+s.x,i.y=i.y*s.scaleY+s.y,e.preventDefault(),e.stopPropagation(),this.latest.event=e,this.latest.coordinates=i,Fi.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=Un(t.target).body;try{i.setPointerCapture(t.pointerId)}catch{this.handleCancel(t);return}const s=nn(t.target)?[t.target,i]:i,o=this.listeners.bind(s,[{type:"touchmove",listener:si,options:{passive:!1}},{type:"click",listener:si},{type:"contextmenu",listener:si},{type:"keydown",listener:this.handleKeyDown}]);me(this,Sn).add(o)}handleCancel(e){const{dragOperation:t}=this.manager;t.status.initialized&&this.manager.actions.stop({event:e,canceled:!0}),this.cleanup()}cleanup(){const{controller:e}=this;this.controller=void 0,e&&!e.signal.aborted&&e.abort(),this.latest={event:void 0,coordinates:void 0},me(this,Sn).forEach(t=>t()),me(this,Sn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Sn=new WeakMap;Vi.configure=_r(Vi);Vi.defaults=Eo;var Oo=Vi;function Rg(e){return"sensor"in e}function si(e){e.preventDefault()}function Lg(){}var Pl=new WeakSet;function Ng(e){!e||Pl.has(e)||(e.addEventListener("touchmove",Lg,{capture:!1,passive:!1}),Pl.add(e))}var Mn={modifiers:[],plugins:[lg,Iu,dg,Wa,Dg],sensors:[Oo,Pu]},Ru=class extends sm{constructor(e={}){const t=ft(e.plugins,Mn.plugins),n=ft(e.sensors,Mn.sensors),r=ft(e.modifiers,Mn.modifiers);super(Pa(Ar({},e),{plugins:[Ag,Gr,us,...t],sensors:n,modifiers:r}))}},Lu,Nu,Mo,It,Ba,qa,fs=class extends(Mo=vt,Nu=[ce],Lu=[ce],Mo){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=pu(n,["element","effects","handle"]);super(Ar({effects:()=>[...i(),()=>{var a,c;const{manager:u}=this;if(!u)return;const l=((c=(a=this.sensors)==null?void 0:a.map(Cr))!=null?c:[...u.sensors]).map(d=>{const f=d instanceof In?d:u.registry.register(d.plugin),h=d instanceof In?void 0:d.options;return f.bind(this,h)});return function(){l.forEach(d=>d())}}]},o),t),Ae(this,Ba,Pe(It,8,this)),Pe(It,11,this),Ae(this,qa,Pe(It,12,this)),Pe(It,15,this),this.element=r,this.handle=s}};It=Yn(Mo);Ba=new WeakMap;qa=new WeakMap;ot(It,4,"handle",Nu,fs,Ba);ot(It,4,"element",Lu,fs,qa);ln(It,fs);var Wu,zu,Ao,Pt,Ha,Ds,Fu,_u,$r,Ga,hs=class extends(Ao=bt,zu=[ce],Wu=[ce],Ao){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=pu(n,["element","effects"]);const{collisionDetector:o=du}=s,a=u=>{const{manager:l,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!l)return;const f=new mt(d),h=le(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},c=zn(!1);super(Pa(Ar({},s),{collisionDetector:o,effects:()=>[...i(),()=>{const{element:u,manager:l}=this;if(!l)return;const{dragOperation:d}=l,{source:f}=d;c.value=!!(f&&d.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(c.value&&u){const l=new wm(u,a);return()=>{l.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Ae(this,$r),Ae(this,Ha,Pe(Pt,8,this)),Pe(Pt,11,this),Ae(this,Ga,Pe(Pt,12,this)),Pe(Pt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ge(this,$r,e,_u)}get element(){var e;return(e=this.proxy)!=null?e:me(this,$r,Fu)}};Pt=Yn(Ao);Ha=new WeakMap;$r=new WeakSet;Ga=new WeakMap;Ds=ot(Pt,20,"#element",zu,$r,Ha),Fu=Ds.get,_u=Ds.set;ot(Pt,4,"proxy",Wu,hs,Ga);ln(Pt,hs);function Wg(e){return e!=null&&typeof e=="object"&&"current"in e}function An(e){var t;if(e!=null)return Wg(e)?(t=e.current)!=null?t:void 0:e}var zg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Kn=zg?S.useLayoutEffect:S.useEffect;function Fg(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Bu(e,t){const n=S.useRef(new Map),r=Fg();return Kn(()=>{if(!e){n.current.clear();return}return st(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[c]=a,u=le(()=>a[1]),l=e[c];u!==l&&(s=!0,n.current.set(c,l),o=(i=t?.(c,u,l))!=null?i:!1)}s&&(o?queueMicrotask(()=>Vh.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(i,s){const o=i[s];return n.current.set(s,o),o}}),[e])}function _g(e,t){e()}function hn(e){const t=S.useRef(e);return Kn(()=>{t.current=e},[e]),t}function Se(e,t,n=S.useEffect,r=Object.is){const i=S.useRef(e);n(()=>{const s=i.current;r(e,s)||(i.current=e,t(e,s))},[t,e])}function ji(e,t){const n=S.useRef(An(e));Kn(()=>{const r=An(e);r!==n.current&&(n.current=r,t(r))})}var Bg=Object.defineProperty,qg=Object.defineProperties,Hg=Object.getOwnPropertyDescriptors,Ui=Object.getOwnPropertySymbols,qu=Object.prototype.hasOwnProperty,Hu=Object.prototype.propertyIsEnumerable,Rl=(e,t,n)=>t in e?Bg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gg=(e,t)=>{for(var n in t||(t={}))qu.call(t,n)&&Rl(e,n,t[n]);if(Ui)for(var n of Ui(t))Hu.call(t,n)&&Rl(e,n,t[n]);return e},Vg=(e,t)=>qg(e,Hg(t)),Ug=(e,t)=>{var n={};for(var r in e)qu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ui)for(var r of Ui(e))t.indexOf(r)<0&&Hu.call(e,r)&&(n[r]=e[r]);return n},Xg=new Ru,Gu=S.createContext(Xg),Yg=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),i=S.useRef(null),s=S.useRef(null),o=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=i.current)!=null?a:Promise.resolve()}},trackRendering(a){i.current||(i.current=new Promise(c=>{s.current=c})),S.startTransition(()=>{a(),r(c=>c+1)})}}),[]);return Kn(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),S.useImperativeHandle(t,()=>o),null})),Is=[void 0,lt];function Kg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:c}=t,u=Ug(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const l=S.useRef(null),{plugins:d,modifiers:f,sensors:h}=u,g=ft(d,Mn.plugins),m=ft(h,Mn.sensors),y=ft(f,Mn.modifiers),w=hn(i),p=hn(s),v=hn(a),x=hn(o),k=hn(c),C=hn(r),O=Zg(()=>{var T;return(T=u.manager)!=null?T:new Ru(u)});return S.useEffect(()=>{if(!l.current)throw new Error("Renderer not found");const{renderer:T,trackRendering:$}=l.current,{monitor:D}=O;O.renderer=T;const z=[D.addEventListener("beforedragstart",N=>{const L=w.current;L&&$(()=>L(N,O))}),D.addEventListener("dragstart",N=>{var L;return(L=p.current)==null?void 0:L.call(p,N,O)}),D.addEventListener("dragover",N=>{const L=v.current;L&&$(()=>L(N,O))}),D.addEventListener("dragmove",N=>{const L=x.current;L&&$(()=>L(N,O))}),D.addEventListener("dragend",N=>{const L=k.current;L&&$(()=>L(N,O))}),D.addEventListener("collision",N=>{var L;return(L=C.current)==null?void 0:L.call(C,N,O)})];return()=>z.forEach(N=>N())},[O]),Se(g,()=>O&&(O.plugins=g),...Is),Se(m,()=>O&&(O.sensors=m),...Is),Se(y,()=>O&&(O.modifiers=y),...Is),b.jsxs(Gu.Provider,{value:O,children:[b.jsx(Yg,{ref:l,children:n}),n]})}function Zg(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 Qg(){return S.useContext(Gu)}function Vu(e){var t;const n=(t=Qg())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Kn(r.register,[n,r]),r}var Jg=Object.create,Uu=Object.defineProperty,ev=Object.getOwnPropertyDescriptor,Xu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ps=e=>{throw TypeError(e)},tv=(e,t,n)=>t in e?Uu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nv=e=>{var t;return[,,,Jg((t=e?.[Xu("metadata")])!=null?t:null)]},Yu=["class","method","getter","setter","accessor","field","value","get","set"],Ku=e=>e!==void 0&&typeof e!="function"?ps("Function expected"):e,rv=(e,t,n,r,i)=>({kind:Yu[e],name:t,metadata:r,addInitializer:s=>n._?ps("Already initialized"):i.push(Ku(s||null))}),iv=(e,t)=>tv(t,Xu("metadata"),e[3]),sv=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},Zu=(e,t,n,r,i,s)=>{for(var o,a,c,u,l=t&7,d=!1,f=!1,h=2,g=Yu[l+5],m=e[h]||(e[h]=[]),y=(i=i.prototype,ev(i,n)),w=r.length-1;w>=0;w--)c=rv(l,n,a={},e[3],m),c.static=d,c.private=f,u=c.access={has:p=>n in p},u.get=p=>p[n],o=(0,r[w])(y[g],c),a._=1,Ku(o)&&(y[g]=o);return y&&Uu(i,n,y),i},Qu=(e,t,n)=>t.has(e)||ps("Cannot "+n),ov=(e,t,n)=>(Qu(e,t,"read from private field"),t.get(e)),av=(e,t,n)=>t.has(e)?ps("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),lv=(e,t,n,r)=>(Qu(e,t,"write to private field"),t.set(e,n),n),en=class To{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new To(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 To(t,n)}},Ju,ef,Do,Ei,Vr,Va=class extends(Do=on,ef=[Ee],Ju=[Ee],Do){constructor(e){const t=en.from(e);super(t,(n,r)=>en.equals(n,r)),sv(Vr,5,this),av(this,Ei,0),this.velocity={x:0,y:0}}get delta(){return en.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=en.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-ov(this,Ei),o=a=>Math.round(a/s*100);Ce(()=>{lv(this,Ei,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(en.from(e)),this.velocity={x:0,y:0}}};Vr=nv(Do);Ei=new WeakMap;Zu(Vr,2,"delta",ef,Va);Zu(Vr,2,"direction",Ju,Va);iv(Vr,Va);var tf=(e=>(e.Horizontal="x",e.Vertical="y",e))(tf||{});Object.values(tf);var cv=({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=en.distance(t.shape.center,n);return{id:r,value:1/i,type:Vn.PointerIntersection,priority:Gn.High}}return null},dv=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=en.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:Vn.ShapeIntersection,priority:Gn.Normal}}return null},uv=e=>{var t;return(t=cv(e))!=null?t:dv(e)};function fv(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,c=Vu(l=>new hs(Vg(Gg({},e),{register:!1,element:An(i)}),l)),u=Bu(c);return Se(s,()=>c.id=s),ji(i,l=>c.element=l),Se(o,()=>c.accept=o,void 0,lt),Se(t,()=>c.collisionDetector=t??uv),Se(n,()=>n&&(c.data=n)),Se(r,()=>c.disabled=r===!0),Se(a,()=>c.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:S.useCallback(l=>{var d,f;!l&&(d=c.element)!=null&&d.isConnected&&!((f=c.manager)!=null&&f.dragOperation.status.idle)||(c.element=l??void 0)},[c])}}const Ll=`url("data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>')}")`,nf=(e,t="line")=>{const n=[":is(p, h1, h2, h3, h4, h5, h6):first-child::after","> * > span:only-child::after"],r=o=>n.map(a=>`${o} ${a}`).join(", "),i=t==="line"?"&::after":r("&"),s=t==="line"?"&:hover::after, &:focus-visible::after":`${r("&:hover")}, ${r("&:focus-visible")}`;return{cursor:"text",borderRadius:"2px",[i]:{content:'""',display:"inline-block",width:"0.8em",height:"0.8em",ml:"0.4em",verticalAlign:"-0.05em",backgroundColor:"currentColor",maskImage:Ll,WebkitMaskImage:Ll,maskSize:"contain",WebkitMaskSize:"contain",maskRepeat:"no-repeat",WebkitMaskRepeat:"no-repeat",opacity:.35,transition:`opacity ${dt}`,...Lt,pointerEvents:"none"},[s]:{opacity:.8},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:2}}},rf=S.createContext(void 0);function sf(e,t){const n=S.useContext(rf),r=S.useRef(t);r.current=t,S.useEffect(()=>{if(!n||!e)return;const s=()=>r.current();return n.commitRef.current=s,()=>{n.commitRef.current===s&&(n.commitRef.current=void 0)}},[n,e]);const i=S.useRef(!1);S.useLayoutEffect(()=>{!e&&!i.current||(i.current=e,n?.setDirty(e))},[n,e]),S.useLayoutEffect(()=>()=>{i.current&&n?.setDirty(!1)},[n])}function Io({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:i=!1}){const{theme:s}=Ze(),[o,a]=S.useState(void 0),c=S.useRef(!1),u=()=>{c.current||o===void 0||(a(void 0),o!==e&&r(o))};sf(o!==void 0&&o!==e,()=>(u(),!0));const l=()=>{c.current=!1,a(e)};if(o===void 0){const d=e==="",f=d&&i;return b.jsx(De,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:l,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),l())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...d&&{fontStyle:"italic",opacity:f?0:.6}},nf(s)],children:d?t:e})}return b.jsx(Oh,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:d=>d.target.select(),onChange:d=>a(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.nativeEvent.isComposing?u():d.key==="Escape"&&(c.current=!0,a(void 0))},onBlur:u,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const hv=(e,t)=>e.map((n,r)=>{const i=t[r]??!1;if(i===(n.break??!1))return n;const s={...n};return i?s.break=!0:delete s.break,s}),pv=(e,t,n)=>{const r=[...e],[i]=r.splice(t,1);if(!i)return[...e];const s=r[t];i.break&&s&&!s.break&&(r[t]={...s,break:!0});const o={...i};return delete o.break,r.splice(n,0,o),r},of=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),af=e=>`gap.${e}`,mv=(e,t)=>{const n=[];let r=0;e.forEach((s,o)=>{const a=Math.min(s.colspan??1,t),c=o===0||s.break===!0||r+a>t;c&&o>0&&r<t&&n.push({kind:"gap",after:ze(e[o-1]),colspan:t-r}),c&&(r=0),n.push(of(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:ze(i),colspan:t-r}),n};var gv=Object.create,lf=Object.defineProperty,vv=Object.defineProperties,bv=Object.getOwnPropertyDescriptor,yv=Object.getOwnPropertyDescriptors,Xi=Object.getOwnPropertySymbols,cf=Object.prototype.hasOwnProperty,df=Object.prototype.propertyIsEnumerable,xv=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ur=e=>{throw TypeError(e)},Po=(e,t,n)=>t in e?lf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ps=(e,t)=>{for(var n in t||(t={}))cf.call(t,n)&&Po(e,n,t[n]);if(Xi)for(var n of Xi(t))df.call(t,n)&&Po(e,n,t[n]);return e},Rs=(e,t)=>vv(e,yv(t)),wv=(e,t)=>{var n={};for(var r in e)cf.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Xi)for(var r of Xi(e))t.indexOf(r)<0&&df.call(e,r)&&(n[r]=e[r]);return n},kv=e=>{var t;return[,,,gv((t=void 0)!=null?t:null)]},uf=["class","method","getter","setter","accessor","field","value","get","set"],pr=e=>e!==void 0&&typeof e!="function"?Ur("Function expected"):e,Sv=(e,t,n,r,i)=>({kind:uf[e],name:t,metadata:r,addInitializer:s=>n._?Ur("Already initialized"):i.push(pr(s||null))}),$v=(e,t)=>Po(t,xv("metadata"),e[3]),oi=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},ff=(e,t,n,r,i,s)=>{for(var o,a,c,u,l,d=t&7,f=!1,h=!1,g=e.length+1,m=uf[d+5],y=e[g-1]=[],w=e[g]||(e[g]=[]),p=(i=i.prototype,bv({get[n](){return mr(this,s)},set[n](x){return Jt(this,s,x)}},n)),v=r.length-1;v>=0;v--)u=Sv(d,n,c={},e[3],w),u.static=f,u.private=h,l=u.access={has:x=>n in x},l.get=x=>x[n],l.set=(x,k)=>x[n]=k,a=(0,r[v])({get:p.get,set:p.set},u),c._=1,a===void 0?pr(a)&&(p[m]=a):typeof a!="object"||a===null?Ur("Object expected"):(pr(o=a.get)&&(p.get=o),pr(o=a.set)&&(p.set=o),pr(o=a.init)&&y.unshift(o));return p&&lf(i,n,p),i},hf=(e,t,n)=>t.has(e)||Ur("Cannot "+n),mr=(e,t,n)=>(hf(e,t,"read from private field"),t.get(e)),er=(e,t,n)=>t.has(e)?Ur("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Jt=(e,t,n,r)=>(hf(e,t,"write to private field"),t.set(e,n),n);function tn(e){return e instanceof Ya||e instanceof vf}var ai=10,Cv=class extends _e{constructor(e){super(e);const t=st(()=>{const{dragOperation:r}=e;if(Mr(r.activatorEvent)&&tn(r.source)&&r.status.initialized){const i=e.registry.plugins.get(Gr);if(i)return i.disable(),()=>i.enable()}}),n=e.monitor.addEventListener("dragmove",(r,i)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:s}=i;if(!Mr(r.nativeEvent)||!tn(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:c}=i,{by:u}=r;if(!u)return;const l=jv(u),{source:d,target:f}=s,{center:h}=s.shape.current,g=[],m=[];Ce(()=>{for(const k of c.droppables){const{id:C}=k;if(!k.accepts(d)||C===f?.id&&tn(k)||!k.element)continue;let O=k.shape;const T=new mt(k.element,{getBoundingClientRect:$=>Er($,void 0,.2)});!T.height||!T.width||(l=="down"&&h.y+ai<T.center.y||l=="up"&&h.y-ai>T.center.y||l=="left"&&h.x-ai>T.center.x||l=="right"&&h.x+ai<T.center.x)&&(g.push(k),k.shape=T,m.push(()=>k.shape=O))}}),r.preventDefault(),a.disable();const y=a.computeCollisions(g,Um);Ce(()=>m.forEach(k=>k()));const[w]=y;if(!w)return;const{id:p}=w,{index:v,group:x}=d.sortable;o.setDropTarget(p).then(()=>{const{source:k,target:C,shape:O}=s;if(!k||!tn(k)||!O)return;const{index:T,group:$,target:D}=k.sortable,z=v!==T||x!==$,N=z?D:C?.element;if(!N)return;lu(N);const L=new mt(N);if(!L)return;const B=gt.delta(L,gt.from(O.current.boundingRectangle),k.alignment);o.move({by:B}),z?o.setDropTarget(k.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function jv(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 Ev=Object.defineProperty,Ov=Object.defineProperties,Mv=Object.getOwnPropertyDescriptors,Nl=Object.getOwnPropertySymbols,Av=Object.prototype.hasOwnProperty,Tv=Object.prototype.propertyIsEnumerable,Wl=(e,t,n)=>t in e?Ev(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pn=(e,t)=>{for(var n in t||(t={}))Av.call(t,n)&&Wl(e,n,t[n]);if(Nl)for(var n of Nl(t))Tv.call(t,n)&&Wl(e,n,t[n]);return e},mn=(e,t)=>Ov(e,Mv(t));function Dv(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function li(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Ls(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Iv(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(p,v)=>p===v||p!==null&&typeof p=="object"&&"id"in p&&p.id===v;if(Array.isArray(e)){const p=e.findIndex(x=>c(x,s.id)),v=e.findIndex(x=>c(x,o.id));if(p===-1||v===-1){if(Ls(s)){const x=s.initialIndex,k=s.index;return x===k||x<0||x>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,x,k)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const x=s.index;if(x!==p)return n(e,p,x)}return n(e,p,v)}const u=Object.entries(e);let l=-1,d,f=-1,h;for(const[p,v]of u)if(l===-1&&(l=v.findIndex(x=>c(x,s.id)),l!==-1&&(d=p)),f===-1&&(f=v.findIndex(x=>c(x,o.id)),f!==-1&&(h=p)),l!==-1&&f!==-1)break;if(l===-1&&Ls(s)){const p=s.initialGroup==null?void 0:li(e,s.initialGroup),v=s.initialIndex,x=s.group==null?void 0:li(e,s.group),k=s.index;if(p==null||x==null||p===x&&v===k)return"preventDefault"in t&&t.preventDefault(),e;if(p===x)return mn(pn({},e),{[p]:n(e[p],v,k)});const C=e[p][v];return mn(pn({},e),{[p]:[...e[p].slice(0,v),...e[p].slice(v+1)],[x]:[...e[x].slice(0,k),C,...e[x].slice(k)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,m=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(h==null){const p=li(e,o.id);if(p!=null){const v=o.shape&&m.y>o.shape.center.y?e[p].length:0;h=p,f=v}}if(d==null||h==null||d===h&&l===f){if(d!=null&&d===h&&l===f&&Ls(s)){const p=s.group==null?void 0:li(e,s.group),v=s.group!=null&&p!==d,x=s.index!==l;if(v||x){const k=s.group==null?d:p;if(k!=null){if(d===k)return mn(pn({},e),{[d]:n(e[d],l,s.index)});const C=e[d][l];return mn(pn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[k]:[...e[k].slice(0,s.index),C,...e[k].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return mn(pn({},e),{[d]:n(e[d],l,f)});const y=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,w=e[d][l];return mn(pn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[h]:[...e[h].slice(0,f+y),w,...e[h].slice(f+y)]})}function Pv(e,t){return Iv(e,t,Dv)}function zl(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Fl(e,t,n){var r;for(const[i,s]of t)for(const o of s){const a=e.get(o.id);if(o.index!==a||o.group!==i||!((r=n.get(i))!=null&&r.has(o)))return!0}return!1}var _l="__default__",Rv=class extends _e{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof Ya){const{sortable:s}=i,{group:o}=s;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(s)}return r},n=[e.monitor.addEventListener("dragover",(r,i)=>{if(this.disabled)return;const{dragOperation:s}=i,{source:o,target:a}=s;if(!tn(o)||!tn(a)||o.sortable===a.sortable)return;const c=t(),u=zl(c),l=o.sortable.group===a.sortable.group,d=c.get(o.sortable.group),f=l?d:c.get(a.sortable.group);!d||!f||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var h,g;const m=t();if(Fl(u,c,m))return;const y=o.sortable.element,w=a.sortable.element;if(!w||!y||!l&&a.id===o.sortable.group)return;const p=ci(d),v=l?p:ci(f),x=(h=o.sortable.group)!=null?h:_l,k=(g=a.sortable.group)!=null?g:_l,C={[x]:p,[k]:v},O=Pv(C,r);if(C===O)return;const T=O[k].indexOf(o.sortable),$=O[k].indexOf(a.sortable);i.collisionObserver.disable(),Bl(y,T,w,$),Ce(()=>{for(const[D,z]of O[x].entries())z.index=D;if(!l)for(const[D,z]of O[k].entries())z.group=a.sortable.group,z.index=D}),i.actions.setDropTarget(o.id).then(()=>i.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,i)=>{if(!r.canceled)return;const{dragOperation:s}=i,{source:o}=s;tn(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),c=zl(a),u=a.get(o.sortable.initialGroup);u&&i.renderer.rendering.then(()=>{const l=t();if(Fl(c,a,l))return;const d=ci(u),f=ci(u,Nv),h=o.sortable.element,g=f.indexOf(o.sortable),m=d[g],y=m?.element;!m||!y||!h||(Bl(h,m.index,y,o.index),Ce(()=>{for(const w of a.values()){const p=Array.from(w).values();for(const v of p)v.index=v.initialIndex,v.group=v.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function Bl(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function Lv(e,t){return e.index-t.index}function Nv(e,t){return e.initialIndex-t.initialIndex}function ci(e,t=Lv){return Array.from(e).sort(t)}var ql=[Cv,Rv],pf={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Hl(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 Ap,mf,gf,Rt,Ua,gr,vr,Xa,$n;gf=[ce],mf=[ce];var ms=class{constructor(e,t){er(this,Ua,oi(Rt,8,this)),oi(Rt,11,this),er(this,gr),er(this,vr),er(this,Xa,oi(Rt,12,this)),oi(Rt,15,this),er(this,$n),this.register=()=>(Ce(()=>{var g,m;(g=this.manager)==null||g.registry.register(this.droppable),(m=this.manager)==null||m.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ce(()=>{var g,m;(g=this.manager)==null||g.registry.unregister(this.droppable),(m=this.manager)==null||m.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:c,transition:u=pf,plugins:l}=n,d=wv(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=ft(l,ql),h=Hl(i);this.droppable=new Ya(Rs(Ps({},d),{disabled:h.droppable}),t,this),this.draggable=new vf(Rs(Ps({},d),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var g,m,y;const w=(g=this.manager)==null?void 0:g.dragOperation.status;w?.initializing&&this.id===((y=(m=this.manager)==null?void 0:m.dragOperation.source)==null?void 0:y.id)&&di.clear(this.manager),w?.dragging&&di.set(this.manager,this.id,le(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:m,manager:y}=this,w=mr(this,vr),p=mr(this,gr);(g!==w||m!==p)&&(Jt(this,vr,g),Jt(this,gr,m),this.animate())},()=>{var g,m;const{target:y}=this,{isDragSource:w}=this.draggable;((m=(g=this.draggable.pluginConfig(Wa))==null?void 0:g.feedback)!=null?m:"default")==="move"&&w&&(this.droppable.disabled=!y)},...r()],type:c,sensors:a}),t,this),Jt(this,$n,d.element),this.manager=t,this.index=o,Jt(this,vr,o),this.group=s,Jt(this,gr,s),this.type=c,this.transition=u}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 s=this.refreshShape();if(!s)return;const o={x:n.boundingRectangle.left-s.boundingRectangle.left,y:n.boundingRectangle.top-s.boundingRectangle.top},{translate:a}=yt(i),c=jl(i,a,!1),u=jl(i,a);if(o.x||o.y){const l=Aa(Qe(i))?Rs(Ps({},t),{duration:0}):t;cu({element:i,keyframes:{translate:[`${c.x+o.x}px ${c.y+o.y}px ${c.z}`,`${u.x}px ${u.y}px ${u.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=mr(this,$n),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Jt(this,$n,e)})}get element(){var e,t;const n=mr(this,$n);if(n)return(t=(e=po.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=ft(e,ql)}set disabled(e){const t=Hl(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??du}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)}};Rt=kv();Ua=new WeakMap;gr=new WeakMap;vr=new WeakMap;Xa=new WeakMap;$n=new WeakMap;ff(Rt,4,"index",gf,ms,Ua);ff(Rt,4,"group",mf,ms,Xa);$v(Rt,ms);var vf=class extends fs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},Ya=class extends hs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Wv=Object.defineProperty,zv=Object.defineProperties,Fv=Object.getOwnPropertyDescriptors,Gl=Object.getOwnPropertySymbols,_v=Object.prototype.hasOwnProperty,Bv=Object.prototype.propertyIsEnumerable,Vl=(e,t,n)=>t in e?Wv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ns=(e,t)=>{for(var n in t||(t={}))_v.call(t,n)&&Vl(e,n,t[n]);if(Gl)for(var n of Gl(t))Bv.call(t,n)&&Vl(e,n,t[n]);return e},qv=(e,t)=>zv(e,Fv(t));function Hv(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:i,data:s,element:o,handle:a,index:c,group:u,disabled:l,modifiers:d,sensors:f,target:h,type:g,plugins:m}=e,y=Ns(Ns({},pf),e.transition),w=Vu(v=>new ms(qv(Ns({},e),{transition:y,register:!1,handle:An(a),element:An(o),target:An(h)}),v)),p=Bu(w,Gv);return Se(i,()=>w.id=i),Kn(()=>{Ce(()=>{w.group=u,w.index=c})},[w,u,c]),Se(g,()=>w.type=g),Se(t,()=>w.accept=t,void 0,lt),Se(s,()=>s&&(w.data=s)),Se(c,()=>{var v;(v=w.manager)!=null&&v.dragOperation.status.idle&&y?.idle&&w.refreshShape()},_g),ji(a,v=>w.handle=v),ji(o,v=>w.element=v),ji(h,v=>w.target=v),Se(l,()=>w.disabled=l??!1,void 0,lt),Se(f,()=>w.sensors=f,void 0,lt),Se(n,()=>w.collisionDetector=n),Se(r,()=>w.collisionPriority=r),Se(m,()=>w.plugins=m,void 0,lt),Se(y,()=>w.transition=y,void 0,lt),Se(d,()=>w.modifiers=d,void 0,lt),Se(e.alignment,()=>w.alignment=e.alignment),{sortable:p,get isDragging(){return p.isDragging},get isDropping(){return p.isDropping},get isDragSource(){return p.isDragSource},get isDropTarget(){return p.isDropTarget},handleRef:S.useCallback(v=>{w.handle=v??void 0},[w]),ref:S.useCallback(v=>{var x,k;!v&&(x=w.element)!=null&&x.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.element=v??void 0)},[w]),sourceRef:S.useCallback(v=>{var x,k;!v&&(x=w.source)!=null&&x.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.source=v??void 0)},[w]),targetRef:S.useCallback(v=>{var x,k;!v&&(x=w.target)!=null&&x.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.target=v??void 0)},[w])}}function Gv(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Ro="tile",bf="gap",Vv=[Oo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${yf}]`)!==null||(Oo.defaults.preventActivation?.(e,t)??!1)}),Pu],yf="data-no-drag",Uv=e=>[...e,Wa.configure({feedback:"clone"})];function Xv({id:e,index:t,children:n}){const{ref:r,handleRef:i,isDragSource:s}=Hv({id:e,index:t,type:Ro,accept:Ro,collisionDetector:Da,plugins:Uv});return b.jsx(b.Fragment,{children:n({ref:r,handleRef:i,isDragSource:s})})}function Yv({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=fv({id:e,type:bf,accept:Ro,collisionDetector:Da,data:{after:t}});return b.jsx(b.Fragment,{children:n({ref:r,isDropTarget:i})})}const xf=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],wf=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],gs=e=>wf.includes(e),Lo=new Set([...xf,"viz"]);function Wt(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let i;for(const s of n)if(s.startsWith("-")){if(i!==void 0)return;const o=s.slice(1);if(!Lo.has(o))return;r.push(o)}else{if(i!==void 0||!Lo.has(s))return;i=s}return{negated:r,...i!==void 0&&{pick:i}}}function Pr(e){const t=e.trim();return!/^#[ \t]/.test(t)||Wt(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(n=>Lo.has(n))}function Tn(e,t){return["#",...wf.filter(n=>n!==e&&(t===void 0||t.includes(n))).map(n=>`-${n}`),"-viz",...e==="none"?[]:[e]].join(" ")}function Kv(e){return e.pick!==void 0?gs(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function Zv(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=Wt(e[0]);return t?Kv(t):"custom"}function Qv(e){const t=e.filter(n=>Wt(n));return e.some(Pr)?"custom":t.length===0?void 0:Zv(t)}const Jv=e=>e.filter(t=>Wt(t)||Pr(t)),kf=e=>e.ok===!1,Te=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),cn=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>Te(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Te(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Te(e,"VIEW","subQueryDefList"),defDimension:e=>Te(e,"defList","DIMENSION"),exploreProperties:e=>Te(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Te(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Te(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Te(e,"WHERE","filterClauseList"),givenDef:e=>Te(e,"givenNameDef"),givenStatement:e=>Te(e,"GIVEN","givenDefList"),importStatement:e=>Te(e,"IMPORT","importURL"),vArrow:e=>Te(e,"ARROW","vExpr","segExpr"),segRefine:e=>Te(e,"PLUS","segExpr"),segOps:e=>Te(e,"queryProperties"),segField:e=>Te(e,"fieldPath")&&!Te(e,"segExpr"),segParen:e=>Te(e,"OPAREN","CPAREN","vExpr"),compare:e=>Te(e,"fieldExpr","compareOp"),givenRef:e=>Te(e,"GIVEN_REF")};function eb(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 tb(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
-
`&&t.push(n+1);return t}function Sf(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const i=t.getChild(r);if(!cn(i))continue;const s=Me(i,"docAnnotations");if(s)for(const o of _t(s,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class vs{constructor(t){this.text=t,this.map=eb(t),this.lineStarts=tb(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!cn(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const i=this.map[n.startIndex],s=this.map[r.stopIndex+1];if(!(i===void 0||s===void 0||s<i))return{start:i,end:s}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],i=this.map[n.stopIndex+1];if(!(r===void 0||i===void 0||i<r))return{start:r,end:i}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const i=n+r+1>>1;this.lineStarts[i]<=t?n=i:r=i-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function
|
|
69
|
-
`),c=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:s,closeStart:o,statements:r,wheres:i,indent:c,oneLine:a}}function Ka(e,t,n){const r=[],i=e.line(t.start),s=e.line(n);for(let o=i;o<s;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function ib(e,t){const n=Me(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const i=Me(n,"queryProperties"),s=i&&No(e,i);return s?{kind:"inline",stage:s,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(ke.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(ke.segRefine(n)){const i=_t(n,"segExpr"),s=i[0],o=i[i.length-1];let a=s;for(;ke.segRefine(a);){const f=_t(a,"segExpr");if(f.some(h=>ke.segOps(h)||ke.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&ke.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!ke.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const c=e.span(s);if(!c||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!ke.segOps(o)){const f=e.span(n);return f?{kind:"reference",from:e.text.slice(f.start,f.end),fromSpan:f}:{kind:"unsupported",why:"an unreadable refinement"}}const u=e.text.slice(c.start,c.end),l=Me(o,"queryProperties"),d=l&&No(e,l);return d?{kind:"reference",from:u,fromSpan:c,refinement:d}:{kind:"reference",from:u,fromSpan:c}}return{kind:"unsupported",why:"a parenthesized expression"}}function sb(e,t){const n=[];for(const r of Rr(t,ke.defExploreQuery)){const i=e.span(r),s=Me(r,"subQueryDefList");if(!i||!s)continue;const o=_t(s,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Me(r,"VIEW"));for(const c of o){const u=e.span(c),l=Me(c,"exploreQueryNameDef"),d=e.text_(l),f=Me(c,"vExpr");!u||!d||!f||n.push({name:d,span:u,line:e.line(u.start),statement:i,tags:Ka(e,i,a?.start??u.start),siblings:o.length,body:ib(e,f)})}}return n}function ob(e,t){const n=[];for(const r of Rr(t,ke.defDimension)){const i=e.span(r),s=Me(r,"defList");if(!i||!s)continue;const o=e.terminal(Me(r,"DIMENSION"));for(const a of _t(s,"fieldDef")){const c=e.span(a),u=e.text_(Me(a,"fieldNameDef"))?.trim(),l=e.text_(Me(a,"fieldExpr"))?.trim();!c||!u||l===void 0||n.push({name:u,expression:l,span:c,line:e.line(c.start),statement:i,tags:Ka(e,i,o?.start??c.start)})}}return n}function ab(e,t){const n=[];for(const r of
|
|
70
|
-
`),l=f=>c.lines.has(f);a.proseLines=Nh(u,l),a.blocks=Wh(u,l).filter(([f])=>!u[f].trimStart().startsWith("##"));const d=ab(a,i);return d.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:cb(a,i),sources:d,givens:lb(a,i),textBlocks:ub(a,s),modelNotes:Sf(a,i),trailingComment:f=>c.trailing.get(f),comments:c.all,commentLine:f=>c.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>c.all.find(h=>h.start>=f.start&&h.start<f.end),blockStart:f=>db(a,c.lines,f)}}}async function
|
|
67
|
+
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function pg(e,t="hidden"){return le(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=mg(n,r.registry.droppables),s=[],o=cm(n),{remove:a}=o;return gg(i,o,s),vg(o,t),o.remove=()=>{s.forEach(c=>c()),a.call(o)},o})}function mg(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${Hr}${bo("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function gg(e,t,n){for(const[r,i]of e){if(!r.element)continue;const s=`[${i}]`,o=t.matches(s)?t:t.querySelector(s);if(r.element.removeAttribute(i),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(i),po.set(a,o),n.push(()=>{po.delete(a),r.proxy=void 0})}}function vg(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Hi,t)}function $u(e,t){return e===t?!0:Rn(e)===Rn(t)}function Ml(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&nn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>On(t))}function ko(e){return e.tagName==="TR"}function bg(e,t,n){const r=new MutationObserver(i=>{let s=!1;for(const o of i){if(o.target!==e){s=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||ug.includes(a))continue;const c=e.getAttribute(a);if(a==="style"){if(kr(e)&&kr(t)){const u=e.style;for(const l of Array.from(t.style))u.getPropertyValue(l)===""&&t.style.removeProperty(l);for(const l of Array.from(u)){if(fg.includes(l)||l.startsWith(Ne))continue;const d=u.getPropertyValue(l);t.style.setProperty(l,d)}}}else c!==null?t.setAttribute(a,c):t.removeAttribute(a)}s&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function yg(e,t,n){const r=new MutationObserver(i=>{for(const s of i)if(s.addedNodes.length!==0)for(const o of Array.from(s.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),On(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),On(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),On(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function xg(e){return new ResizeObserver(()=>{var t,n,r;const i=new mt(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-i.width)*s.x+e.delta.x,a=(e.height-i.height)*s.y+e.delta.y,c=Jd();if(e.styles.set({width:i.width-e.widthOffset,height:i.height-e.heightOffset,top:e.top+a+c.y,left:e.left+o+c.x},Ne),(n=e.getElementMutationObserver())==null||n.takeRecords(),ko(e.element)&&ko(e.placeholder)){const m=Array.from(e.element.cells),y=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(m.map(w=>w.style.width));for(const[w,p]of m.entries()){const v=y[w];p.style.width=`${v.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},l=e.left+o+c.x+u.x,d=e.top+a+c.y+u.y,f=i.width-e.widthOffset,h=i.height-e.heightOffset,g=e.frameTransform;e.dragOperation.shape=new gt(l*g.scaleX+g.x,d*g.scaleY+g.y,f*g.scaleX,h*g.scaleY)})}var wg=250,kg="ease";function Sg(e){var t,n,r,i;const{animation:s}=e;if(typeof s=="function"){const p=s({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(p).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=wg,easing:a=kg}=s??{};On(e.feedbackElement);const[,c]=(t=Kd(e.feedbackElement,p=>"translate"in p))!=null?t:[];c?.pause();const u=(n=e.placeholder)!=null?n:e.element,l={frameTransform:$u(e.feedbackElement,u)?null:void 0},d=new mt(e.feedbackElement,l),f=(r=Or(yt(e.feedbackElement).translate))!=null?r:e.translate,h=new mt(u,l),g=gt.delta(d,h,e.alignment),m={x:f.x-g.x,y:f.y-g.y},y=Math.round(d.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},w=Math.round(d.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Ne),e.feedbackElement.setAttribute(wo,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),cu({element:e.feedbackElement,keyframes:Pa(Ar(Ar({},y),w),{translate:[`${f.x}px ${f.y}px 0`,`${m.x}px ${m.y}px 0`]}),options:{duration:Aa(Qe(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(wo),c?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Cu,So,Tr,Na,Ci,ju,Eu,Wn=class extends(So=_e,Cu=[ce],So){constructor(e,t){super(e,t),Ae(this,Ci),Ae(this,Na,Pe(Tr,8,this)),Pe(Tr,11,this),this.state={initial:{},current:{}};const n=e.registry.plugins.get(us),r=n?.register(hg);if(r){const i=this.destroy.bind(this);this.destroy=()=>{r(),i()}}this.registerEffect(rn(this,Ci,ju).bind(this,n)),this.registerEffect(rn(this,Ci,Eu))}};Tr=Xn(So);Na=new WeakMap;Ci=new WeakSet;ju=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Ni(t);if(n)return e.addRoot(n)};Eu=function(){var e,t,n,r,i,s,o;const{state:a,manager:c,options:u}=this,{dragOperation:l}=c,{position:d,source:f,status:h}=l;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:g}=f,m=f.pluginConfig(Wn),y=(t=(e=m?.feedback)!=null?e:u?.feedback)!=null?t:"default",w=typeof y=="function"?y(f,c):y;if(!g||w==="none"||!h.initialized||h.initializing)return;const{initial:p}=a,v=(n=this.overlay)!=null?n:g,x=Ln(v),k=Ln(g),C=!$u(g,v),O=new mt(g,{frameTransform:C?k:null,ignoreTransforms:!C}),T={x:k.scaleX/x.scaleX,y:k.scaleY/x.scaleY};let{width:$,height:D,top:z,left:N}=O;C&&($=$/T.x,D=D/T.y);const L=new Bm(v),B=yt(g),{transition:H,translate:Y,boxSizing:Z,paddingBlockStart:ne,paddingBlockEnd:J,paddingInlineStart:M,paddingInlineEnd:F,borderInlineStartWidth:W,borderInlineEndWidth:R,borderBlockStartWidth:_,borderBlockEndWidth:X}=B,Q=H.split(",").filter(ge=>!/^\s*(transform|translate|scale)\b/.test(ge)).join(","),E=ds(B),j=B.transform,A=w==="clone",K=Z==="content-box",V=K?parseInt(M)+parseInt(F)+parseInt(W)+parseInt(R):0,te=K?parseInt(ne)+parseInt(J)+parseInt(_)+parseInt(X):0,G=w!=="move"&&!this.overlay?pg(f,A?"clone":"hidden"):null,ae=le(()=>Mr(c.dragOperation.activatorEvent));if(!p.translate){if(this.overlay&&E)p.translate={x:E.x,y:E.y};else if(Y!=="none"){const ge=Or(Y);ge&&(p.translate=ge)}}if(!p.transformOrigin){const ge=le(()=>d.current),Le=N+((r=E?.x)!=null?r:0),Ue=z+((i=E?.y)!=null?i:0);p.transformOrigin={x:(ge.x-Le*x.scaleX-x.x)/($*x.scaleX),y:(ge.y-Ue*x.scaleY-x.y)/(D*x.scaleY)}}const{transformOrigin:ee}=p,I=z*x.scaleY+x.y,re=N*x.scaleX+x.x;if(!p.coordinates&&(p.coordinates={x:re,y:I},T.x!==1||T.y!==1)){const{scaleX:ge,scaleY:Le}=k,{x:Ue,y:jt}=ee;p.coordinates.x+=($*ge-$)*Ue,p.coordinates.y+=(D*Le-D)*jt}p.dimensions||(p.dimensions={width:$,height:D}),p.frameTransform||(p.frameTransform=x);const he={x:p.coordinates.x-re,y:p.coordinates.y-I},we={width:(p.dimensions.width*p.frameTransform.scaleX-$*x.scaleX)*ee.x,height:(p.dimensions.height*p.frameTransform.scaleY-D*x.scaleY)*ee.y},U={x:he.x/x.scaleX+we.width,y:he.y/x.scaleY+we.height},P={left:N+U.x,top:z+U.y};v.setAttribute(pt,"true");const q=le(()=>l.transform),oe=(s=p.translate)!=null?s:{x:0,y:0},pe=q.x*x.scaleX+oe.x,Be=q.y*x.scaleY+oe.y,Zn=Jd();L.set({width:$-V,height:D-te,top:P.top+Zn.y,left:P.left+Zn.x,translate:`${pe}px ${Be}px 0`,transform:this.overlay?"none":j,transition:Q?`${Q}, translate 0ms linear`:"translate 0ms linear",scale:C?`${T.x} ${T.y}`:"","transform-origin":`${ee.x*100}% ${ee.y*100}%`},Ne),G&&(g.insertAdjacentElement("afterend",G),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(g)),go(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),On(v),v.addEventListener("beforetoggle",Ml));let Bt,dn,qt;const Zr=xg({placeholder:G,element:g,feedbackElement:v,frameTransform:x,transformOrigin:ee,width:$,height:D,top:z,left:N,widthOffset:V,heightOffset:te,delta:U,styles:L,dragOperation:l,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>Bt,getSavedCellWidths:()=>qt,setSavedCellWidths:ge=>{qt=ge}}),Qr=new mt(v);le(()=>l.shape=Qr);const Ct=Qe(v),tl=ge=>{this.manager.actions.stop({event:ge})},Bf=Aa(Ct);ae&&Ct.addEventListener("resize",tl),le(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),G&&(Zr.observe(G),Bt=bg(g,G,A),dn=yg(g,G,v));const nl=(o=c.dragOperation.source)==null?void 0:o.id,qf=()=>{var ge;if(!ae||nl==null)return;const Le=c.registry.draggables.get(nl),Ue=(ge=Le?.handle)!=null?ge:Le?.element;zt(Ue)&&Ue.focus()},bs=()=>{Bt?.disconnect(),dn?.disconnect(),Zr.disconnect(),Ct.removeEventListener("resize",tl),go(v)&&(v.removeEventListener("beforetoggle",Ml),v.removeAttribute("popover")),v.removeAttribute(pt),L.reset();const ge=()=>{var Le;if(qt&&ko(g)){const ys=Array.from(g.cells);for(const[Jr,un]of ys.entries())un.style.width=(Le=qt[Jr])!=null?Le:""}f.status="idle";const Ue=a.current.translate!=null,jt=l.status.dragging;G&&(!jt&&Ue||G.parentElement!==v.parentElement)&&v.isConnected&&G.replaceWith(v),G?.remove()};v===this.overlay?setTimeout(ge,0):ge()},Hf=u?.dropAnimation,rl=this,Gf=zr(()=>{var ge,Le,Ue;const{transform:jt,status:ys}=l;if(!(!jt.x&&!jt.y&&!a.current.translate)&&ys.dragging){const Jr=(ge=p.translate)!=null?ge:{x:0,y:0},un={x:jt.x/x.scaleX+Jr.x,y:jt.y/x.scaleY+Jr.y},il=a.current.translate,Vf=le(()=>l.modifiers),xs=le(()=>{var Qn;return(Qn=l.shape)==null?void 0:Qn.current}),ws=u?.keyboardTransition,sl=ae&&!Bf&&ws!==null?`${(Le=ws?.duration)!=null?Le:250}ms ${(Ue=ws?.easing)!=null?Ue:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:Q?`${Q}, translate ${sl}`:`translate ${sl}`,translate:`${un.x}px ${un.y}px 0`},Ne),Bt?.takeRecords(),xs&&xs!==Qr&&il&&!Vf.length){const Qn=tt.delta(un,il);l.shape=gt.from(xs.boundingRectangle).translate(Qn.x*x.scaleX,Qn.y*x.scaleY)}else l.shape=new mt(v);a.current.translate=un}},function(){if(l.status.dropped){this.dispose(),f.status="dropping";const ge=m?.dropAnimation!==void 0?m.dropAnimation:rl.dropAnimation!==void 0?rl.dropAnimation:Hf;let Le=a.current.translate;const Ue=Le!=null;if(!Le&&g!==v&&(Le={x:0,y:0}),!Le||ge===null){bs();return}c.renderer.rendering.then(()=>{Sg({source:f,element:g,feedbackElement:v,placeholder:G,translate:Le,moved:Ue,transition:H,alignment:f.alignment,styles:L,animation:ge??void 0,getElementMutationObserver:()=>Bt,cleanup:bs,restoreFocus:qf})})}});return()=>{bs(),Gf()}};ot(Tr,4,"overlay",Cu,Wn,Na);ln(Tr,Wn);Wn.configure=_r(Wn);var Wa=Wn,Jn=!0,$g=!1,Ou,Mu,Au,Tu,Dt,za,Fa;Tu=(Au=[ce],nt.Forward),Mu=(Ou=[ce],nt.Reverse);var Dr=class{constructor(){Ae(this,za,Pe(Dt,8,this,Jn)),Pe(Dt,11,this),Ae(this,Fa,Pe(Dt,12,this,Jn)),Pe(Dt,15,this)}isLocked(e){return e===nt.Idle?!1:e==null?this[nt.Forward]===Jn&&this[nt.Reverse]===Jn:this[e]===Jn}unlock(e){e!==nt.Idle&&(this[e]=$g)}};Dt=Xn(null);za=new WeakMap;Fa=new WeakMap;ot(Dt,4,Tu,Au,Dr,za);ot(Dt,4,Mu,Ou,Dr,Fa);ln(Dt,Dr);var Cg=[nt.Forward,nt.Reverse],Al=class{constructor(){this.x=new Dr,this.y=new Dr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},jg=class extends _e{constructor(e){super(e);const t=zn(new Al);let n=null;this.signal=t,st(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new Al;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:Tl(i.x,n.x),y:Tl(i.y,n.y)},o=t.peek();Ce(()=>{for(const a of od)for(const c of Cg)s[a]===c&&o[a].unlock(c);t.value=o})}n=i})}get current(){return this.signal.peek()}};function Tl(e,t){return Math.sign(e-t)}var Du,$o,Ir,_a,Ot,Co,Gr=class extends($o=Br,Du=[ce],$o){constructor(e){super(e),Ae(this,_a,Pe(Ir,8,this,!1)),Pe(Ir,11,this),Ae(this,Ot),Ae(this,Co,()=>{if(!me(this,Ot))return;const{element:s,by:o}=me(this,Ot);o.y&&(s.scrollTop+=o.y),o.x&&(s.scrollLeft+=o.x)}),this.scroll=(s,o)=>{var a;if(this.disabled)return!1;const c=this.getScrollableElements();if(!c)return Ge(this,Ot,void 0),!1;const{position:u}=this.manager.dragOperation,l=u?.current;if(l){const{by:d}=s??{},f=d?{x:Dl(d.x),y:Dl(d.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const g of c){const m=km(g,d);if(m.x||m.y){const{speed:y,direction:w}=Im(g,l,f,o?.acceleration,o?.threshold);if(h)for(const p of od)h[p].isLocked(w[p])&&(y[p]=0,w[p]=0);if(w.x||w.y){const{x:p,y:v}=d??w,x=p*y.x,k=v*y.y;if(x||k){const C=(a=me(this,Ot))==null?void 0:a.by;if(this.autoScrolling&&C&&(C.x&&!x||C.y&&!k))continue;return Ge(this,Ot,{element:g,by:{x,y:k}}),Fi.schedule(me(this,Co)),!0}}}}}return Ge(this,Ot,void 0),!1};let t=null,n=null;const r=Js(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=eu(Ni(o?.element),s.current);return a&&(t=a),a??t}),i=Js(()=>{const s=r.value,{documentElement:o}=Yn(s);if(!s||s===o){const{target:a}=e.dragOperation,c=a?.element;if(c){const u=vo(c,{excludeElement:!1});return n=u,u}}if(s){const a=vo(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},lt);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new jg(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!Mr(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};Ir=Xn($o);_a=new WeakMap;Ot=new WeakMap;Co=new WeakMap;ot(Ir,4,"autoScrolling",Du,Gr,_a);ln(Ir,Gr);function Dl(e){return e>0?nt.Forward:e<0?nt.Reverse:nt.Idle}var Eg=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))}},Og=new Eg(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Mg=10,jo=class extends _e{constructor(e,t){super(e,t);const n=e.registry.plugins.get(Gr);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=st(()=>{var r,i,s;if(this.disabled)return;const{position:o,status:a}=e.dragOperation;if(a.dragging){const c={acceleration:(r=this.options)==null?void 0:r.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(s=this.options)==null?void 0:s.threshold};if(n.scroll(void 0,c)){n.autoScrolling=!0;const u=setInterval(()=>Og.schedule(()=>n.scroll(void 0,c)),Mg);return()=>{clearInterval(u)}}else n.autoScrolling=!1}})}};jo.configure=_r(jo);var Iu=jo,Il={capture:!0,passive:!0},fr,Ag=class extends Br{constructor(e){super(e),Ae(this,fr),this.handleScroll=()=>{me(this,fr)==null&&Ge(this,fr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ge(this,fr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=st(()=>{var n,r,i;if(t.status.dragging){const s=(i=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?i:document;return s.addEventListener("scroll",this.handleScroll,Il),()=>{s.removeEventListener("scroll",this.handleScroll,Il)}}})}};fr=new WeakMap;var Tg="* { user-select: none !important; -webkit-user-select: none !important; }",Dg=class extends _e{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(us),n=t?.register(Tg);if(this.destroy=st(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Ts(),document.addEventListener("selectionchange",Ts,{capture:!0}),()=>{document.removeEventListener("selectionchange",Ts,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Ts(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var hr=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}}),wn,Gi=class extends In{constructor(e,t){super(e),this.manager=e,this.options=t,Ae(this,wn,[]),this.listeners=new tu,this.handleSourceKeyDown=(n,r,i)=>{if(this.disabled||n.defaultPrevented||!nn(n.target)||r.disabled)return;const{keyboardCodes:s=hr.keyboardCodes,preventActivation:o=hr.preventActivation}=i??{};s.start.includes(n.code)&&this.manager.dragOperation.status.idle&&(o?.(n,r)||this.handleStart(n,r,i))}}bind(e,t=this.options){return st(()=>{var n;const r=(n=e.handle)!=null?n:e.element,i=s=>{Mr(s)&&this.handleSourceKeyDown(s,e,t)};if(r)return r.addEventListener("keydown",i),()=>{r.removeEventListener("keydown",i)}})}handleStart(e,t,n){const{element:r}=t;if(!r)throw new Error("Source draggable does not have an associated element");e.preventDefault(),e.stopImmediatePropagation(),lu(r);const{center:i}=new mt(r);if(this.manager.actions.start({event:e,coordinates:{x:i.x,y:i.y},source:t}).signal.aborted)return this.cleanup();this.sideEffects();const s=Yn(r),o=[this.listeners.bind(s,[{type:"keydown",listener:a=>this.handleKeyDown(a,t,n),options:{capture:!0}}])];me(this,wn).push(...o)}handleKeyDown(e,t,n){const{keyboardCodes:r=hr.keyboardCodes}=n??{};if(fn(e,[...r.end,...r.cancel])){e.preventDefault();const i=fn(e,r.cancel);this.handleEnd(e,i);return}fn(e,r.up)?this.handleMove("up",e):fn(e,r.down)&&this.handleMove("down",e),fn(e,r.left)?this.handleMove("left",e):fn(e,r.right)&&this.handleMove("right",e)}handleEnd(e,t){this.manager.actions.stop({event:e,canceled:t}),this.cleanup()}handleMove(e,t){var n,r;const{shape:i}=this.manager.dragOperation,s=t.shiftKey?5:1;let o={x:0,y:0},a=(r=(n=this.options)==null?void 0:n.offset)!=null?r:hr.offset;if(typeof a=="number"&&(a={x:a,y:a}),!!i){switch(e){case"up":o={x:0,y:-a.y*s};break;case"down":o={x:0,y:a.y*s};break;case"left":o={x:-a.x*s,y:0};break;case"right":o={x:a.x*s,y:0};break}(o.x||o.y)&&(t.preventDefault(),this.manager.actions.move({event:t,by:o}))}}sideEffects(){const e=this.manager.registry.plugins.get(Iu);e?.disabled===!1&&(e.disable(),me(this,wn).push(()=>{e.enable()}))}cleanup(){me(this,wn).forEach(e=>e()),Ge(this,wn,[])}destroy(){this.cleanup(),this.listeners.clear()}};wn=new WeakMap;Gi.configure=_r(Gi);Gi.defaults=hr;var Pu=Gi;function fn(e,t){return t.includes(e.code)}var Zt,Ig=class extends Wd{constructor(){super(...arguments),Ae(this,Zt)}onEvent(e){switch(e.type){case"pointerdown":Ge(this,Zt,Pn(e));break;case"pointermove":if(!me(this,Zt))return;const{x:t,y:n}=Pn(e),r={x:t-me(this,Zt).x,y:n-me(this,Zt).y},{tolerance:i}=this.options;if(i&&lo(r,i)){this.abort();return}lo(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Ge(this,Zt,void 0)}};Zt=new WeakMap;var kn,Qt,Pg=class extends Wd{constructor(){super(...arguments),Ae(this,kn),Ae(this,Qt)}onEvent(e){switch(e.type){case"pointerdown":Ge(this,Qt,Pn(e)),Ge(this,kn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!me(this,Qt))return;const{x:t,y:n}=Pn(e),r={x:t-me(this,Qt).x,y:n-me(this,Qt).y};lo(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){me(this,kn)&&(clearTimeout(me(this,kn)),Ge(this,Qt,void 0),Ge(this,kn,void 0))}};kn=new WeakMap;Qt=new WeakMap;var jn=class{};jn.Delay=Pg;jn.Distance=Ig;var Eo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&nn(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new jn.Delay({value:250,tolerance:5})]:Hm(i)&&!e.defaultPrevented?[new jn.Delay({value:200,tolerance:0})]:[new jn.Delay({value:200,tolerance:10}),new jn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!nn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=um(r);return i===t.element?!1:!!i}}),Sn,Vi=class extends In{constructor(e,t){super(e),this.manager=e,this.options=t,Ae(this,Sn,new Set),this.listeners=new tu,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=Eo.activationConstraints}=n??{};return typeof r=="function"?r(e,t):r}bind(e,t=this.options){return st(()=>{var n;const r=new AbortController,{signal:i}=r,s=a=>{qm(a)&&this.handlePointerDown(a,e,t)};let o=[(n=e.handle)!=null?n:e.element];t?.activatorElements&&(Array.isArray(t.activatorElements)?o=t.activatorElements:o=t.activatorElements(e));for(const a of o)a&&(Ng(a.ownerDocument.defaultView),a.addEventListener("pointerdown",s,{signal:i}));return()=>r.abort()})}handlePointerDown(e,t,n){if(this.disabled||!e.isPrimary||e.button!==0||!nn(e.target)||t.disabled||Rg(e)||!this.manager.dragOperation.status.idle)return;const{preventActivation:r=Eo.preventActivation}=n??{};if(r?.(e,t))return;const{target:i}=e,s=zt(i)&&i.draggable&&i.getAttribute("draggable")==="true",o=Ln(t.element),{x:a,y:c}=Pn(e);this.initialCoordinates={x:a*o.scaleX+o.x,y:c*o.scaleY+o.y};const u=this.activationConstraints(e,t,n);e.sensor=this;const l=new nm(u,g=>this.handleStart(t,g));l.signal.onabort=()=>this.handleCancel(e),l.onEvent(e),this.controller=l;const d=ho(),f=this.listeners.bind(d,[{type:"pointermove",listener:g=>this.handlePointerMove(g,t)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:s?this.handleCancel:si,options:{capture:!0}}]),h=()=>{f(),this.initialCoordinates=void 0};me(this,Sn).add(h)}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=Pn(e),s=Ln(t.element);i.x=i.x*s.scaleX+s.x,i.y=i.y*s.scaleY+s.y,e.preventDefault(),e.stopPropagation(),this.latest.event=e,this.latest.coordinates=i,Fi.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=Yn(t.target).body;try{i.setPointerCapture(t.pointerId)}catch{this.handleCancel(t);return}const s=nn(t.target)?[t.target,i]:i,o=this.listeners.bind(s,[{type:"touchmove",listener:si,options:{passive:!1}},{type:"click",listener:si},{type:"contextmenu",listener:si},{type:"keydown",listener:this.handleKeyDown}]);me(this,Sn).add(o)}handleCancel(e){const{dragOperation:t}=this.manager;t.status.initialized&&this.manager.actions.stop({event:e,canceled:!0}),this.cleanup()}cleanup(){const{controller:e}=this;this.controller=void 0,e&&!e.signal.aborted&&e.abort(),this.latest={event:void 0,coordinates:void 0},me(this,Sn).forEach(t=>t()),me(this,Sn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Sn=new WeakMap;Vi.configure=_r(Vi);Vi.defaults=Eo;var Oo=Vi;function Rg(e){return"sensor"in e}function si(e){e.preventDefault()}function Lg(){}var Pl=new WeakSet;function Ng(e){!e||Pl.has(e)||(e.addEventListener("touchmove",Lg,{capture:!1,passive:!1}),Pl.add(e))}var Mn={modifiers:[],plugins:[lg,Iu,dg,Wa,Dg],sensors:[Oo,Pu]},Ru=class extends sm{constructor(e={}){const t=ft(e.plugins,Mn.plugins),n=ft(e.sensors,Mn.sensors),r=ft(e.modifiers,Mn.modifiers);super(Pa(Ar({},e),{plugins:[Ag,Gr,us,...t],sensors:n,modifiers:r}))}},Lu,Nu,Mo,It,Ba,qa,fs=class extends(Mo=vt,Nu=[ce],Lu=[ce],Mo){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=pu(n,["element","effects","handle"]);super(Ar({effects:()=>[...i(),()=>{var a,c;const{manager:u}=this;if(!u)return;const l=((c=(a=this.sensors)==null?void 0:a.map(Cr))!=null?c:[...u.sensors]).map(d=>{const f=d instanceof In?d:u.registry.register(d.plugin),h=d instanceof In?void 0:d.options;return f.bind(this,h)});return function(){l.forEach(d=>d())}}]},o),t),Ae(this,Ba,Pe(It,8,this)),Pe(It,11,this),Ae(this,qa,Pe(It,12,this)),Pe(It,15,this),this.element=r,this.handle=s}};It=Xn(Mo);Ba=new WeakMap;qa=new WeakMap;ot(It,4,"handle",Nu,fs,Ba);ot(It,4,"element",Lu,fs,qa);ln(It,fs);var Wu,zu,Ao,Pt,Ha,Ds,Fu,_u,$r,Ga,hs=class extends(Ao=bt,zu=[ce],Wu=[ce],Ao){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=pu(n,["element","effects"]);const{collisionDetector:o=du}=s,a=u=>{const{manager:l,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!l)return;const f=new mt(d),h=le(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},c=zn(!1);super(Pa(Ar({},s),{collisionDetector:o,effects:()=>[...i(),()=>{const{element:u,manager:l}=this;if(!l)return;const{dragOperation:d}=l,{source:f}=d;c.value=!!(f&&d.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(c.value&&u){const l=new wm(u,a);return()=>{l.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Ae(this,$r),Ae(this,Ha,Pe(Pt,8,this)),Pe(Pt,11,this),Ae(this,Ga,Pe(Pt,12,this)),Pe(Pt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ge(this,$r,e,_u)}get element(){var e;return(e=this.proxy)!=null?e:me(this,$r,Fu)}};Pt=Xn(Ao);Ha=new WeakMap;$r=new WeakSet;Ga=new WeakMap;Ds=ot(Pt,20,"#element",zu,$r,Ha),Fu=Ds.get,_u=Ds.set;ot(Pt,4,"proxy",Wu,hs,Ga);ln(Pt,hs);function Wg(e){return e!=null&&typeof e=="object"&&"current"in e}function An(e){var t;if(e!=null)return Wg(e)?(t=e.current)!=null?t:void 0:e}var zg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Kn=zg?S.useLayoutEffect:S.useEffect;function Fg(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Bu(e,t){const n=S.useRef(new Map),r=Fg();return Kn(()=>{if(!e){n.current.clear();return}return st(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[c]=a,u=le(()=>a[1]),l=e[c];u!==l&&(s=!0,n.current.set(c,l),o=(i=t?.(c,u,l))!=null?i:!1)}s&&(o?queueMicrotask(()=>Vh.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(i,s){const o=i[s];return n.current.set(s,o),o}}),[e])}function _g(e,t){e()}function hn(e){const t=S.useRef(e);return Kn(()=>{t.current=e},[e]),t}function Se(e,t,n=S.useEffect,r=Object.is){const i=S.useRef(e);n(()=>{const s=i.current;r(e,s)||(i.current=e,t(e,s))},[t,e])}function ji(e,t){const n=S.useRef(An(e));Kn(()=>{const r=An(e);r!==n.current&&(n.current=r,t(r))})}var Bg=Object.defineProperty,qg=Object.defineProperties,Hg=Object.getOwnPropertyDescriptors,Yi=Object.getOwnPropertySymbols,qu=Object.prototype.hasOwnProperty,Hu=Object.prototype.propertyIsEnumerable,Rl=(e,t,n)=>t in e?Bg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gg=(e,t)=>{for(var n in t||(t={}))qu.call(t,n)&&Rl(e,n,t[n]);if(Yi)for(var n of Yi(t))Hu.call(t,n)&&Rl(e,n,t[n]);return e},Vg=(e,t)=>qg(e,Hg(t)),Yg=(e,t)=>{var n={};for(var r in e)qu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Yi)for(var r of Yi(e))t.indexOf(r)<0&&Hu.call(e,r)&&(n[r]=e[r]);return n},Ug=new Ru,Gu=S.createContext(Ug),Xg=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),i=S.useRef(null),s=S.useRef(null),o=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=i.current)!=null?a:Promise.resolve()}},trackRendering(a){i.current||(i.current=new Promise(c=>{s.current=c})),S.startTransition(()=>{a(),r(c=>c+1)})}}),[]);return Kn(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),S.useImperativeHandle(t,()=>o),null})),Is=[void 0,lt];function Kg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:c}=t,u=Yg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const l=S.useRef(null),{plugins:d,modifiers:f,sensors:h}=u,g=ft(d,Mn.plugins),m=ft(h,Mn.sensors),y=ft(f,Mn.modifiers),w=hn(i),p=hn(s),v=hn(a),x=hn(o),k=hn(c),C=hn(r),O=Zg(()=>{var T;return(T=u.manager)!=null?T:new Ru(u)});return S.useEffect(()=>{if(!l.current)throw new Error("Renderer not found");const{renderer:T,trackRendering:$}=l.current,{monitor:D}=O;O.renderer=T;const z=[D.addEventListener("beforedragstart",N=>{const L=w.current;L&&$(()=>L(N,O))}),D.addEventListener("dragstart",N=>{var L;return(L=p.current)==null?void 0:L.call(p,N,O)}),D.addEventListener("dragover",N=>{const L=v.current;L&&$(()=>L(N,O))}),D.addEventListener("dragmove",N=>{const L=x.current;L&&$(()=>L(N,O))}),D.addEventListener("dragend",N=>{const L=k.current;L&&$(()=>L(N,O))}),D.addEventListener("collision",N=>{var L;return(L=C.current)==null?void 0:L.call(C,N,O)})];return()=>z.forEach(N=>N())},[O]),Se(g,()=>O&&(O.plugins=g),...Is),Se(m,()=>O&&(O.sensors=m),...Is),Se(y,()=>O&&(O.modifiers=y),...Is),b.jsxs(Gu.Provider,{value:O,children:[b.jsx(Xg,{ref:l,children:n}),n]})}function Zg(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 Qg(){return S.useContext(Gu)}function Vu(e){var t;const n=(t=Qg())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Kn(r.register,[n,r]),r}var Jg=Object.create,Yu=Object.defineProperty,ev=Object.getOwnPropertyDescriptor,Uu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ps=e=>{throw TypeError(e)},tv=(e,t,n)=>t in e?Yu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nv=e=>{var t;return[,,,Jg((t=e?.[Uu("metadata")])!=null?t:null)]},Xu=["class","method","getter","setter","accessor","field","value","get","set"],Ku=e=>e!==void 0&&typeof e!="function"?ps("Function expected"):e,rv=(e,t,n,r,i)=>({kind:Xu[e],name:t,metadata:r,addInitializer:s=>n._?ps("Already initialized"):i.push(Ku(s||null))}),iv=(e,t)=>tv(t,Uu("metadata"),e[3]),sv=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},Zu=(e,t,n,r,i,s)=>{for(var o,a,c,u,l=t&7,d=!1,f=!1,h=2,g=Xu[l+5],m=e[h]||(e[h]=[]),y=(i=i.prototype,ev(i,n)),w=r.length-1;w>=0;w--)c=rv(l,n,a={},e[3],m),c.static=d,c.private=f,u=c.access={has:p=>n in p},u.get=p=>p[n],o=(0,r[w])(y[g],c),a._=1,Ku(o)&&(y[g]=o);return y&&Yu(i,n,y),i},Qu=(e,t,n)=>t.has(e)||ps("Cannot "+n),ov=(e,t,n)=>(Qu(e,t,"read from private field"),t.get(e)),av=(e,t,n)=>t.has(e)?ps("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),lv=(e,t,n,r)=>(Qu(e,t,"write to private field"),t.set(e,n),n),en=class To{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new To(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 To(t,n)}},Ju,ef,Do,Ei,Vr,Va=class extends(Do=on,ef=[Ee],Ju=[Ee],Do){constructor(e){const t=en.from(e);super(t,(n,r)=>en.equals(n,r)),sv(Vr,5,this),av(this,Ei,0),this.velocity={x:0,y:0}}get delta(){return en.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=en.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-ov(this,Ei),o=a=>Math.round(a/s*100);Ce(()=>{lv(this,Ei,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(en.from(e)),this.velocity={x:0,y:0}}};Vr=nv(Do);Ei=new WeakMap;Zu(Vr,2,"delta",ef,Va);Zu(Vr,2,"direction",Ju,Va);iv(Vr,Va);var tf=(e=>(e.Horizontal="x",e.Vertical="y",e))(tf||{});Object.values(tf);var cv=({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=en.distance(t.shape.center,n);return{id:r,value:1/i,type:Vn.PointerIntersection,priority:Gn.High}}return null},dv=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=en.distance(t.shape.center,i.current),o=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:o,type:Vn.ShapeIntersection,priority:Gn.Normal}}return null},uv=e=>{var t;return(t=cv(e))!=null?t:dv(e)};function fv(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,c=Vu(l=>new hs(Vg(Gg({},e),{register:!1,element:An(i)}),l)),u=Bu(c);return Se(s,()=>c.id=s),ji(i,l=>c.element=l),Se(o,()=>c.accept=o,void 0,lt),Se(t,()=>c.collisionDetector=t??uv),Se(n,()=>n&&(c.data=n)),Se(r,()=>c.disabled=r===!0),Se(a,()=>c.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:S.useCallback(l=>{var d,f;!l&&(d=c.element)!=null&&d.isConnected&&!((f=c.manager)!=null&&f.dragOperation.status.idle)||(c.element=l??void 0)},[c])}}const Ll=`url("data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>')}")`,nf=(e,t="line")=>{const n=[":is(p, h1, h2, h3, h4, h5, h6):first-child::after","> * > span:only-child::after"],r=o=>n.map(a=>`${o} ${a}`).join(", "),i=t==="line"?"&::after":r("&"),s=t==="line"?"&:hover::after, &:focus-visible::after":`${r("&:hover")}, ${r("&:focus-visible")}`;return{cursor:"text",borderRadius:"2px",[i]:{content:'""',display:"inline-block",width:"0.8em",height:"0.8em",ml:"0.4em",verticalAlign:"-0.05em",backgroundColor:"currentColor",maskImage:Ll,WebkitMaskImage:Ll,maskSize:"contain",WebkitMaskSize:"contain",maskRepeat:"no-repeat",WebkitMaskRepeat:"no-repeat",opacity:.35,transition:`opacity ${dt}`,...Lt,pointerEvents:"none"},[s]:{opacity:.8},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:2}}},rf=S.createContext(void 0);function sf(e,t){const n=S.useContext(rf),r=S.useRef(t);r.current=t,S.useEffect(()=>{if(!n||!e)return;const s=()=>r.current();return n.commitRef.current=s,()=>{n.commitRef.current===s&&(n.commitRef.current=void 0)}},[n,e]);const i=S.useRef(!1);S.useLayoutEffect(()=>{!e&&!i.current||(i.current=e,n?.setDirty(e))},[n,e]),S.useLayoutEffect(()=>()=>{i.current&&n?.setDirty(!1)},[n])}function Io({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:i=!1}){const{theme:s}=Ze(),[o,a]=S.useState(void 0),c=S.useRef(!1),u=()=>{c.current||o===void 0||(a(void 0),o!==e&&r(o))};sf(o!==void 0&&o!==e,()=>(u(),!0));const l=()=>{c.current=!1,a(e)};if(o===void 0){const d=e==="",f=d&&i;return b.jsx(De,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:l,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),l())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...d&&{fontStyle:"italic",opacity:f?0:.6}},nf(s)],children:d?t:e})}return b.jsx(Oh,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:d=>d.target.select(),onChange:d=>a(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.nativeEvent.isComposing?u():d.key==="Escape"&&(c.current=!0,a(void 0))},onBlur:u,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const hv=(e,t)=>e.map((n,r)=>{const i=t[r]??!1;if(i===(n.break??!1))return n;const s={...n};return i?s.break=!0:delete s.break,s}),pv=(e,t,n)=>{const r=[...e],[i]=r.splice(t,1);if(!i)return[...e];const s=r[t];i.break&&s&&!s.break&&(r[t]={...s,break:!0});const o={...i};return delete o.break,r.splice(n,0,o),r},of=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),af=e=>`gap.${e}`,mv=(e,t)=>{const n=[];let r=0;e.forEach((s,o)=>{const a=Math.min(s.colspan??1,t),c=o===0||s.break===!0||r+a>t;c&&o>0&&r<t&&n.push({kind:"gap",after:ze(e[o-1]),colspan:t-r}),c&&(r=0),n.push(of(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:ze(i),colspan:t-r}),n};var gv=Object.create,lf=Object.defineProperty,vv=Object.defineProperties,bv=Object.getOwnPropertyDescriptor,yv=Object.getOwnPropertyDescriptors,Ui=Object.getOwnPropertySymbols,cf=Object.prototype.hasOwnProperty,df=Object.prototype.propertyIsEnumerable,xv=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Yr=e=>{throw TypeError(e)},Po=(e,t,n)=>t in e?lf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ps=(e,t)=>{for(var n in t||(t={}))cf.call(t,n)&&Po(e,n,t[n]);if(Ui)for(var n of Ui(t))df.call(t,n)&&Po(e,n,t[n]);return e},Rs=(e,t)=>vv(e,yv(t)),wv=(e,t)=>{var n={};for(var r in e)cf.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ui)for(var r of Ui(e))t.indexOf(r)<0&&df.call(e,r)&&(n[r]=e[r]);return n},kv=e=>{var t;return[,,,gv((t=void 0)!=null?t:null)]},uf=["class","method","getter","setter","accessor","field","value","get","set"],pr=e=>e!==void 0&&typeof e!="function"?Yr("Function expected"):e,Sv=(e,t,n,r,i)=>({kind:uf[e],name:t,metadata:r,addInitializer:s=>n._?Yr("Already initialized"):i.push(pr(s||null))}),$v=(e,t)=>Po(t,xv("metadata"),e[3]),oi=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},ff=(e,t,n,r,i,s)=>{for(var o,a,c,u,l,d=t&7,f=!1,h=!1,g=e.length+1,m=uf[d+5],y=e[g-1]=[],w=e[g]||(e[g]=[]),p=(i=i.prototype,bv({get[n](){return mr(this,s)},set[n](x){return Jt(this,s,x)}},n)),v=r.length-1;v>=0;v--)u=Sv(d,n,c={},e[3],w),u.static=f,u.private=h,l=u.access={has:x=>n in x},l.get=x=>x[n],l.set=(x,k)=>x[n]=k,a=(0,r[v])({get:p.get,set:p.set},u),c._=1,a===void 0?pr(a)&&(p[m]=a):typeof a!="object"||a===null?Yr("Object expected"):(pr(o=a.get)&&(p.get=o),pr(o=a.set)&&(p.set=o),pr(o=a.init)&&y.unshift(o));return p&&lf(i,n,p),i},hf=(e,t,n)=>t.has(e)||Yr("Cannot "+n),mr=(e,t,n)=>(hf(e,t,"read from private field"),t.get(e)),er=(e,t,n)=>t.has(e)?Yr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Jt=(e,t,n,r)=>(hf(e,t,"write to private field"),t.set(e,n),n);function tn(e){return e instanceof Xa||e instanceof vf}var ai=10,Cv=class extends _e{constructor(e){super(e);const t=st(()=>{const{dragOperation:r}=e;if(Mr(r.activatorEvent)&&tn(r.source)&&r.status.initialized){const i=e.registry.plugins.get(Gr);if(i)return i.disable(),()=>i.enable()}}),n=e.monitor.addEventListener("dragmove",(r,i)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:s}=i;if(!Mr(r.nativeEvent)||!tn(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:c}=i,{by:u}=r;if(!u)return;const l=jv(u),{source:d,target:f}=s,{center:h}=s.shape.current,g=[],m=[];Ce(()=>{for(const k of c.droppables){const{id:C}=k;if(!k.accepts(d)||C===f?.id&&tn(k)||!k.element)continue;let O=k.shape;const T=new mt(k.element,{getBoundingClientRect:$=>Er($,void 0,.2)});!T.height||!T.width||(l=="down"&&h.y+ai<T.center.y||l=="up"&&h.y-ai>T.center.y||l=="left"&&h.x-ai>T.center.x||l=="right"&&h.x+ai<T.center.x)&&(g.push(k),k.shape=T,m.push(()=>k.shape=O))}}),r.preventDefault(),a.disable();const y=a.computeCollisions(g,Ym);Ce(()=>m.forEach(k=>k()));const[w]=y;if(!w)return;const{id:p}=w,{index:v,group:x}=d.sortable;o.setDropTarget(p).then(()=>{const{source:k,target:C,shape:O}=s;if(!k||!tn(k)||!O)return;const{index:T,group:$,target:D}=k.sortable,z=v!==T||x!==$,N=z?D:C?.element;if(!N)return;lu(N);const L=new mt(N);if(!L)return;const B=gt.delta(L,gt.from(O.current.boundingRectangle),k.alignment);o.move({by:B}),z?o.setDropTarget(k.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function jv(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 Ev=Object.defineProperty,Ov=Object.defineProperties,Mv=Object.getOwnPropertyDescriptors,Nl=Object.getOwnPropertySymbols,Av=Object.prototype.hasOwnProperty,Tv=Object.prototype.propertyIsEnumerable,Wl=(e,t,n)=>t in e?Ev(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pn=(e,t)=>{for(var n in t||(t={}))Av.call(t,n)&&Wl(e,n,t[n]);if(Nl)for(var n of Nl(t))Tv.call(t,n)&&Wl(e,n,t[n]);return e},mn=(e,t)=>Ov(e,Mv(t));function Dv(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function li(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Ls(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Iv(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(p,v)=>p===v||p!==null&&typeof p=="object"&&"id"in p&&p.id===v;if(Array.isArray(e)){const p=e.findIndex(x=>c(x,s.id)),v=e.findIndex(x=>c(x,o.id));if(p===-1||v===-1){if(Ls(s)){const x=s.initialIndex,k=s.index;return x===k||x<0||x>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,x,k)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const x=s.index;if(x!==p)return n(e,p,x)}return n(e,p,v)}const u=Object.entries(e);let l=-1,d,f=-1,h;for(const[p,v]of u)if(l===-1&&(l=v.findIndex(x=>c(x,s.id)),l!==-1&&(d=p)),f===-1&&(f=v.findIndex(x=>c(x,o.id)),f!==-1&&(h=p)),l!==-1&&f!==-1)break;if(l===-1&&Ls(s)){const p=s.initialGroup==null?void 0:li(e,s.initialGroup),v=s.initialIndex,x=s.group==null?void 0:li(e,s.group),k=s.index;if(p==null||x==null||p===x&&v===k)return"preventDefault"in t&&t.preventDefault(),e;if(p===x)return mn(pn({},e),{[p]:n(e[p],v,k)});const C=e[p][v];return mn(pn({},e),{[p]:[...e[p].slice(0,v),...e[p].slice(v+1)],[x]:[...e[x].slice(0,k),C,...e[x].slice(k)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,m=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(h==null){const p=li(e,o.id);if(p!=null){const v=o.shape&&m.y>o.shape.center.y?e[p].length:0;h=p,f=v}}if(d==null||h==null||d===h&&l===f){if(d!=null&&d===h&&l===f&&Ls(s)){const p=s.group==null?void 0:li(e,s.group),v=s.group!=null&&p!==d,x=s.index!==l;if(v||x){const k=s.group==null?d:p;if(k!=null){if(d===k)return mn(pn({},e),{[d]:n(e[d],l,s.index)});const C=e[d][l];return mn(pn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[k]:[...e[k].slice(0,s.index),C,...e[k].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return mn(pn({},e),{[d]:n(e[d],l,f)});const y=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,w=e[d][l];return mn(pn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[h]:[...e[h].slice(0,f+y),w,...e[h].slice(f+y)]})}function Pv(e,t){return Iv(e,t,Dv)}function zl(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Fl(e,t,n){var r;for(const[i,s]of t)for(const o of s){const a=e.get(o.id);if(o.index!==a||o.group!==i||!((r=n.get(i))!=null&&r.has(o)))return!0}return!1}var _l="__default__",Rv=class extends _e{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof Xa){const{sortable:s}=i,{group:o}=s;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(s)}return r},n=[e.monitor.addEventListener("dragover",(r,i)=>{if(this.disabled)return;const{dragOperation:s}=i,{source:o,target:a}=s;if(!tn(o)||!tn(a)||o.sortable===a.sortable)return;const c=t(),u=zl(c),l=o.sortable.group===a.sortable.group,d=c.get(o.sortable.group),f=l?d:c.get(a.sortable.group);!d||!f||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var h,g;const m=t();if(Fl(u,c,m))return;const y=o.sortable.element,w=a.sortable.element;if(!w||!y||!l&&a.id===o.sortable.group)return;const p=ci(d),v=l?p:ci(f),x=(h=o.sortable.group)!=null?h:_l,k=(g=a.sortable.group)!=null?g:_l,C={[x]:p,[k]:v},O=Pv(C,r);if(C===O)return;const T=O[k].indexOf(o.sortable),$=O[k].indexOf(a.sortable);i.collisionObserver.disable(),Bl(y,T,w,$),Ce(()=>{for(const[D,z]of O[x].entries())z.index=D;if(!l)for(const[D,z]of O[k].entries())z.group=a.sortable.group,z.index=D}),i.actions.setDropTarget(o.id).then(()=>i.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,i)=>{if(!r.canceled)return;const{dragOperation:s}=i,{source:o}=s;tn(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),c=zl(a),u=a.get(o.sortable.initialGroup);u&&i.renderer.rendering.then(()=>{const l=t();if(Fl(c,a,l))return;const d=ci(u),f=ci(u,Nv),h=o.sortable.element,g=f.indexOf(o.sortable),m=d[g],y=m?.element;!m||!y||!h||(Bl(h,m.index,y,o.index),Ce(()=>{for(const w of a.values()){const p=Array.from(w).values();for(const v of p)v.index=v.initialIndex,v.group=v.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function Bl(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function Lv(e,t){return e.index-t.index}function Nv(e,t){return e.initialIndex-t.initialIndex}function ci(e,t=Lv){return Array.from(e).sort(t)}var ql=[Cv,Rv],pf={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Hl(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 Ap,mf,gf,Rt,Ya,gr,vr,Ua,$n;gf=[ce],mf=[ce];var ms=class{constructor(e,t){er(this,Ya,oi(Rt,8,this)),oi(Rt,11,this),er(this,gr),er(this,vr),er(this,Ua,oi(Rt,12,this)),oi(Rt,15,this),er(this,$n),this.register=()=>(Ce(()=>{var g,m;(g=this.manager)==null||g.registry.register(this.droppable),(m=this.manager)==null||m.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ce(()=>{var g,m;(g=this.manager)==null||g.registry.unregister(this.droppable),(m=this.manager)==null||m.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:c,transition:u=pf,plugins:l}=n,d=wv(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=ft(l,ql),h=Hl(i);this.droppable=new Xa(Rs(Ps({},d),{disabled:h.droppable}),t,this),this.draggable=new vf(Rs(Ps({},d),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var g,m,y;const w=(g=this.manager)==null?void 0:g.dragOperation.status;w?.initializing&&this.id===((y=(m=this.manager)==null?void 0:m.dragOperation.source)==null?void 0:y.id)&&di.clear(this.manager),w?.dragging&&di.set(this.manager,this.id,le(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:m,manager:y}=this,w=mr(this,vr),p=mr(this,gr);(g!==w||m!==p)&&(Jt(this,vr,g),Jt(this,gr,m),this.animate())},()=>{var g,m;const{target:y}=this,{isDragSource:w}=this.draggable;((m=(g=this.draggable.pluginConfig(Wa))==null?void 0:g.feedback)!=null?m:"default")==="move"&&w&&(this.droppable.disabled=!y)},...r()],type:c,sensors:a}),t,this),Jt(this,$n,d.element),this.manager=t,this.index=o,Jt(this,vr,o),this.group=s,Jt(this,gr,s),this.type=c,this.transition=u}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 s=this.refreshShape();if(!s)return;const o={x:n.boundingRectangle.left-s.boundingRectangle.left,y:n.boundingRectangle.top-s.boundingRectangle.top},{translate:a}=yt(i),c=jl(i,a,!1),u=jl(i,a);if(o.x||o.y){const l=Aa(Qe(i))?Rs(Ps({},t),{duration:0}):t;cu({element:i,keyframes:{translate:[`${c.x+o.x}px ${c.y+o.y}px ${c.z}`,`${u.x}px ${u.y}px ${u.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=mr(this,$n),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Jt(this,$n,e)})}get element(){var e,t;const n=mr(this,$n);if(n)return(t=(e=po.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=ft(e,ql)}set disabled(e){const t=Hl(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??du}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)}};Rt=kv();Ya=new WeakMap;gr=new WeakMap;vr=new WeakMap;Ua=new WeakMap;$n=new WeakMap;ff(Rt,4,"index",gf,ms,Ya);ff(Rt,4,"group",mf,ms,Ua);$v(Rt,ms);var vf=class extends fs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},Xa=class extends hs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Wv=Object.defineProperty,zv=Object.defineProperties,Fv=Object.getOwnPropertyDescriptors,Gl=Object.getOwnPropertySymbols,_v=Object.prototype.hasOwnProperty,Bv=Object.prototype.propertyIsEnumerable,Vl=(e,t,n)=>t in e?Wv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ns=(e,t)=>{for(var n in t||(t={}))_v.call(t,n)&&Vl(e,n,t[n]);if(Gl)for(var n of Gl(t))Bv.call(t,n)&&Vl(e,n,t[n]);return e},qv=(e,t)=>zv(e,Fv(t));function Hv(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:i,data:s,element:o,handle:a,index:c,group:u,disabled:l,modifiers:d,sensors:f,target:h,type:g,plugins:m}=e,y=Ns(Ns({},pf),e.transition),w=Vu(v=>new ms(qv(Ns({},e),{transition:y,register:!1,handle:An(a),element:An(o),target:An(h)}),v)),p=Bu(w,Gv);return Se(i,()=>w.id=i),Kn(()=>{Ce(()=>{w.group=u,w.index=c})},[w,u,c]),Se(g,()=>w.type=g),Se(t,()=>w.accept=t,void 0,lt),Se(s,()=>s&&(w.data=s)),Se(c,()=>{var v;(v=w.manager)!=null&&v.dragOperation.status.idle&&y?.idle&&w.refreshShape()},_g),ji(a,v=>w.handle=v),ji(o,v=>w.element=v),ji(h,v=>w.target=v),Se(l,()=>w.disabled=l??!1,void 0,lt),Se(f,()=>w.sensors=f,void 0,lt),Se(n,()=>w.collisionDetector=n),Se(r,()=>w.collisionPriority=r),Se(m,()=>w.plugins=m,void 0,lt),Se(y,()=>w.transition=y,void 0,lt),Se(d,()=>w.modifiers=d,void 0,lt),Se(e.alignment,()=>w.alignment=e.alignment),{sortable:p,get isDragging(){return p.isDragging},get isDropping(){return p.isDropping},get isDragSource(){return p.isDragSource},get isDropTarget(){return p.isDropTarget},handleRef:S.useCallback(v=>{w.handle=v??void 0},[w]),ref:S.useCallback(v=>{var x,k;!v&&(x=w.element)!=null&&x.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.element=v??void 0)},[w]),sourceRef:S.useCallback(v=>{var x,k;!v&&(x=w.source)!=null&&x.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.source=v??void 0)},[w]),targetRef:S.useCallback(v=>{var x,k;!v&&(x=w.target)!=null&&x.isConnected&&!((k=w.manager)!=null&&k.dragOperation.status.idle)||(w.target=v??void 0)},[w])}}function Gv(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Ro="tile",bf="gap",Vv=[Oo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${yf}]`)!==null||(Oo.defaults.preventActivation?.(e,t)??!1)}),Pu],yf="data-no-drag",Yv=e=>[...e,Wa.configure({feedback:"clone"})];function Uv({id:e,index:t,children:n}){const{ref:r,handleRef:i,isDragSource:s}=Hv({id:e,index:t,type:Ro,accept:Ro,collisionDetector:Da,plugins:Yv});return b.jsx(b.Fragment,{children:n({ref:r,handleRef:i,isDragSource:s})})}function Xv({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=fv({id:e,type:bf,accept:Ro,collisionDetector:Da,data:{after:t}});return b.jsx(b.Fragment,{children:n({ref:r,isDropTarget:i})})}const xf=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],wf=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],gs=e=>wf.includes(e),Lo=new Set([...xf,"viz"]);function Wt(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let i;for(const s of n)if(s.startsWith("-")){if(i!==void 0)return;const o=s.slice(1);if(!Lo.has(o))return;r.push(o)}else{if(i!==void 0||!Lo.has(s))return;i=s}return{negated:r,...i!==void 0&&{pick:i}}}function Pr(e){const t=e.trim();return!/^#[ \t]/.test(t)||Wt(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(n=>Lo.has(n))}function Tn(e,t){return["#",...wf.filter(n=>n!==e&&(t===void 0||t.includes(n))).map(n=>`-${n}`),"-viz",...e==="none"?[]:[e]].join(" ")}function Kv(e){return e.pick!==void 0?gs(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function Zv(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=Wt(e[0]);return t?Kv(t):"custom"}function Qv(e){const t=e.filter(n=>Wt(n));return e.some(Pr)?"custom":t.length===0?void 0:Zv(t)}const Jv=e=>e.filter(t=>Wt(t)||Pr(t)),kf=e=>e.ok===!1,Te=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),cn=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>Te(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Te(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Te(e,"VIEW","subQueryDefList"),defDimension:e=>Te(e,"defList","DIMENSION"),exploreProperties:e=>Te(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Te(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Te(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Te(e,"WHERE","filterClauseList"),givenDef:e=>Te(e,"givenNameDef"),givenStatement:e=>Te(e,"GIVEN","givenDefList"),importStatement:e=>Te(e,"IMPORT","importURL"),vArrow:e=>Te(e,"ARROW","vExpr","segExpr"),segRefine:e=>Te(e,"PLUS","segExpr"),segOps:e=>Te(e,"queryProperties"),segField:e=>Te(e,"fieldPath")&&!Te(e,"segExpr"),segParen:e=>Te(e,"OPAREN","CPAREN","vExpr"),compare:e=>Te(e,"fieldExpr","compareOp"),givenRef:e=>Te(e,"GIVEN_REF")};function eb(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 tb(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
+
`&&t.push(n+1);return t}function Sf(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const i=t.getChild(r);if(!cn(i))continue;const s=Me(i,"docAnnotations");if(s)for(const o of _t(s,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class vs{constructor(t){this.text=t,this.map=eb(t),this.lineStarts=tb(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!cn(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const i=this.map[n.startIndex],s=this.map[r.stopIndex+1];if(!(i===void 0||s===void 0||s<i))return{start:i,end:s}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],i=this.map[n.stopIndex+1];if(!(r===void 0||i===void 0||i<r))return{start:r,end:i}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const i=n+r+1>>1;this.lineStarts[i]<=t?n=i:r=i-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function Ur(e,t,n=[]){cn(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Ur(e.getChild(r),t,n);return n}const nb=e=>Te(e,"OCURLY","CCURLY");function Rr(e,t){const n=[],r=i=>{if(cn(i)){if(t(i)){n.push(i);return}if(!nb(i))for(let s=0;s<(i.childCount??0);s++)r(i.getChild(s))}};for(let i=0;i<(e.childCount??0);i++)r(e.getChild(i));return n}const Me=(e,t)=>e[t]?.call(e),_t=(e,t)=>e[t]?.call(e)??[];function rb(e,t){if(!ke.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!ke.givenRef(n))return;const r=e.text_(t.getChild(0)),i=e.text_(t.getChild(1)),s=e.text_(n)??"";if(!(r===void 0||i===void 0))return{field:r,op:i.trim(),given:s.replace(/^\$/,"")}}function $f(e,t){const n=e.positioned(t);if(!n)return;const r=Me(t,"filterClauseList"),i=[];for(const s of r?_t(r,"fieldExpr"):[]){const o=e.positioned(s);if(!o)continue;const a=Ur(s,ke.givenRef).map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.replace(/^\$/,""));i.push({...o,givens:a,binding:rb(e,s)})}return{...n,clauses:i}}function No(e,t){const n=e.span(t);if(!n)return;const r=[],i=[];for(const u of Rr(t,ke.queryStatement)){const l=e.positioned(u);l&&r.push(l);const d=Me(u,"whereStatement");if(d&&ke.whereStatement(d)){const f=$f(e,d);f&&i.push(f)}}const s=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
|
|
69
|
+
`),c=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:s,closeStart:o,statements:r,wheres:i,indent:c,oneLine:a}}function Ka(e,t,n){const r=[],i=e.line(t.start),s=e.line(n);for(let o=i;o<s;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function ib(e,t){const n=Me(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const i=Me(n,"queryProperties"),s=i&&No(e,i);return s?{kind:"inline",stage:s,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(ke.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(ke.segRefine(n)){const i=_t(n,"segExpr"),s=i[0],o=i[i.length-1];let a=s;for(;ke.segRefine(a);){const f=_t(a,"segExpr");if(f.some(h=>ke.segOps(h)||ke.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&ke.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!ke.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const c=e.span(s);if(!c||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!ke.segOps(o)){const f=e.span(n);return f?{kind:"reference",from:e.text.slice(f.start,f.end),fromSpan:f}:{kind:"unsupported",why:"an unreadable refinement"}}const u=e.text.slice(c.start,c.end),l=Me(o,"queryProperties"),d=l&&No(e,l);return d?{kind:"reference",from:u,fromSpan:c,refinement:d}:{kind:"reference",from:u,fromSpan:c}}return{kind:"unsupported",why:"a parenthesized expression"}}function sb(e,t){const n=[];for(const r of Rr(t,ke.defExploreQuery)){const i=e.span(r),s=Me(r,"subQueryDefList");if(!i||!s)continue;const o=_t(s,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Me(r,"VIEW"));for(const c of o){const u=e.span(c),l=Me(c,"exploreQueryNameDef"),d=e.text_(l),f=Me(c,"vExpr");!u||!d||!f||n.push({name:d,span:u,line:e.line(u.start),statement:i,tags:Ka(e,i,a?.start??u.start),siblings:o.length,body:ib(e,f)})}}return n}function ob(e,t){const n=[];for(const r of Rr(t,ke.defDimension)){const i=e.span(r),s=Me(r,"defList");if(!i||!s)continue;const o=e.terminal(Me(r,"DIMENSION"));for(const a of _t(s,"fieldDef")){const c=e.span(a),u=e.text_(Me(a,"fieldNameDef"))?.trim(),l=e.text_(Me(a,"fieldExpr"))?.trim();!c||!u||l===void 0||n.push({name:u,expression:l,span:c,line:e.line(c.start),statement:i,tags:Ka(e,i,o?.start??c.start)})}}return n}function ab(e,t){const n=[];for(const r of Ur(t,ke.sourceDefinition)){const i=e.span(r),s=e.text_(Me(r,"sourceNameDef")),o=Me(r,"sqExplore");if(!i||!s||!o)continue;const a=e.span(o),c=a?e.text.slice(a.start,a.end):"",u=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(c)?.[1]??"").trim(),l=Rr(o,ke.exploreProperties)[0],d=l&&No(e,l),f={start:e.lineStarts[e.line(i.start)],end:i.end},h=[];if(l)for(const g of Rr(l,ke.whereStatement)){const m=$f(e,g);m&&h.push(m)}n.push({name:s,base:u,span:i,line:e.line(i.start),statement:f,...d?{properties:d}:{},views:l?sb(e,l):[],dimensions:l?ob(e,l):[],wheres:h})}return n}function lb(e,t){const n=[];for(const r of Ur(t,ke.givenStatement)){const i=e.terminal(Me(r,"GIVEN")),s=Me(r,"givenDefList"),o=i?e.line(i.start):void 0;for(const a of s?_t(s,"givenDef"):[]){const c=e.span(a),u=e.span(Me(a,"givenNameDef")),l=u&&e.text.slice(u.start,u.end);if(!c||!u||!l)continue;const d={start:u.start,end:c.end},f=e.line(d.start);n.push({name:l,declaration:e.text.slice(d.start,d.end),span:d,line:f,statement:{start:e.lineStarts[f],end:d.end},tags:Ka(e,c,d.start),...o!==void 0&&o!==f?{blockHeader:o}:{}})}}return n}function cb(e,t){const n=[];for(const r of Ur(t,ke.importStatement)){const i=e.span(r),s=e.text_(Me(r,"importURL"));if(!i||s===void 0)continue;const o=Me(r,"importSelect"),a=o?_t(o,"importItem").map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.trim()):void 0;n.push({from:s.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:i,line:e.line(i.start),statement:i})}return n}async function Cf(e){let t;try{t=await Xr(e,"file://dashboard-builder.malloy")}catch(f){return{ok:!1,reason:`Malloy could not read this file: ${f}`}}const n=t.problems.filter(f=>f.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||!cn(i)||typeof i.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const s=r?.tokenStream??{},o=typeof s.getTokens=="function"?s.getTokens():void 0;if(!o||typeof s.tokenSource?.vocabulary?.getSymbolicName!="function"||o.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new vs(e),c=Za(a,s);a.commentLines=c.lines;const u=e.split(`
|
|
70
|
+
`),l=f=>c.lines.has(f);a.proseLines=Nh(u,l),a.blocks=Wh(u,l).filter(([f])=>!u[f].trimStart().startsWith("##"));const d=ab(a,i);return d.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:cb(a,i),sources:d,givens:lb(a,i),textBlocks:ub(a,s),modelNotes:Sf(a,i),trailingComment:f=>c.trailing.get(f),comments:c.all,commentLine:f=>c.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>c.all.find(h=>h.start>=f.start&&h.start<f.end),blockStart:f=>db(a,c.lines,f)}}}async function Xr(e,t){const{MalloyTranslator:n}=await Go(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Za(e,t){const n=new Map,r=new Set,i=[],s=t.tokenSource?.vocabulary;for(const l of t.getTokens?.()??[]){const d=s?.getSymbolicName(l.type);if(d!=="COMMENT_TO_EOL"&&d!=="BLOCK_COMMENT")continue;const f=e.utf16(l.startIndex);let h=e.utf16(l.stopIndex+1);if(!(f===void 0||h===void 0||h<f)){for(;h>f&&(e.text[h-1]===`
|
|
71
71
|
`||e.text[h-1]==="\r");)h--;i.push({start:f,end:h})}}const o=[...i].sort((l,d)=>l.start-d.start);let a="",c=0;for(const l of o)a+=e.text.slice(c,Math.max(c,l.start)),a+=e.text.slice(Math.max(c,l.start),Math.max(c,l.end)).replace(/[^\n\r]/g," "),c=Math.max(c,l.end);a+=e.text.slice(c);const u=l=>a.slice(e.lineStarts[l],e.lineStarts[l+1]??a.length);for(const l of i){const d=e.line(l.start),f=e.line(l.end-1);for(let m=d;m<=f;m++)u(m).trim()===""&&r.add(m);const h=a.slice(e.lineStarts[d],l.start).trim(),g=a.slice(l.end,e.lineStarts[f+1]??a.length).trim();h!==""&&g===""&&n.set(f,l)}return{trailing:n,lines:r,all:i}}function db(e,t,n){const r=s=>e.text.slice(e.lineStarts[s],e.lineStarts[s+1]??e.text.length).trim();let i=n;for(let s=n-1;s>=0;s--){const o=r(s),a=e.blocks.find(([,c])=>c===s);if(a){i=s=a[0];continue}if(o===""&&!t.has(s))break;if(o.startsWith("#")||t.has(s))i=s;else break}return i}function ub(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,i=a=>r?.getSymbolicName(a.type),s=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),o=[];for(let a=0;a<n.length;a++){if(i(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const c=Hh(s(n[a]).replace(/\r?\n$/,""));if(!c)continue;const u=[];let l=a+1;for(;i(n[l]??n[a])==="BLOCK_ANNOTATION_TEXT";l++)u.push(s(n[l]));const d=n[l];if(!d||i(d)!=="BLOCK_ANNOTATION_END")continue;const f=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(d.stopIndex+1)??e.text.length,g=c.name===void 0&&c.rest?[`${c.rest}
|
|
72
72
|
`]:[];o.push({...c.name===void 0?{}:{name:c.name},route:c.route,body:[...g,...u].join("").replace(/\r\n?/g,`
|
|
73
73
|
`).replace(/\n$/,""),span:{start:e.lineStarts[f],end:h},line:f}),a=l}return o}function jf(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function Qa(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')r=jf(e,r);else if(i==="{"||i==="[")t++===0&&n++;else if(i==="}"||i==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const s=/^tiles\s*=\s*\[/.exec(e.slice(r));if(s)return fb(e,r+s[0].length-1)}}}function fb(e,t){const n=[];let r=0,i=t+1;const s=o=>{const a=e.slice(i,o),c=a.length-a.trimStart().length,u=a.trim();u!==""&&n.push({text:u,span:{start:i+c,end:i+c+u.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=jf(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return s(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(s(o),i=o+1)}}function hb(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
|
|
74
74
|
`)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const i=e.indexOf(`
|
|
75
75
|
`,r),s=i===-1?e.length:i;if(e.slice(r,s).trim()===">>>")return s;if(i===-1)return e.length;r=i+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let i=t+3;i<e.length;i++)if(e[i]==="\\")i++;else if(e.startsWith(r,i))return i+3;return e.length}for(let i=t+1;i<e.length;i++)if(e[i]==="\\")i++;else{if(e[i]===n)return i+1;if(e[i]===`
|
|
76
|
-
`)return i}return e.length}return t}function pb(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=hb(e,r);if(i>r){n+=e.slice(r,i),r=i;continue}const s=e[r];if(/[=[,]/.test(s)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${s}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=s,r+=1}return n}function Ja(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(s=>{if(e([s]).log.length===0)return s;const o=pb(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const
|
|
76
|
+
`)return i}return e.length}return t}function pb(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const i=hb(e,r);if(i>r){n+=e.slice(r,i),r=i;continue}const s=e[r];if(/[=[,]/.test(s)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${s}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=s,r+=1}return n}function Ja(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(s=>{if(e([s]).log.length===0)return s;const o=pb(s);return e([o]).log.length===0?o:s}),i=e(r);return{tag:i.tag,errors:i.log.map(s=>s.message)}}const Yl=(e,t)=>{try{return e.text(t)}catch{return}},mb=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),gb=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\`.`;function Ef(e,t){const n=e.filter(mb).filter(c=>!c.includes("@env.")).map(Mc),{tag:r,errors:i}=n.length>0?Ja(t,n):{tag:void 0,errors:[]},s=r?.tag("artifact");if(!s)return e.some(Ac)?{status:"unparsed",errors:i}:{status:"none"};const o=Yl(s,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=Yl(s,"layout");return a==="grid"||a==="linear"?{status:"report",layout:a}:s.has("tiles")||r?.tag("dashboard")!==void 0?{status:"report",layout:"grid"}:{status:"report",layout:"linear"}}async function hx(e){const{parseAnnotation:t}=await Ho();let n=[];try{const r=(await Xr(e,"file://report.malloy")).parse?.root;r&&cn(r)&&typeof r.getChild=="function"&&(n=Sf(new vs(e),r))}catch{n=[]}return Ef(n,t)}const Xi=e=>e.ok===!1;function Kr(e,t,n){const r=e.blockStart(n),i=[],s=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){s.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&i.push({line:o,text:a})}return{start:r,tags:i,prose:s}}const Ki=e=>e.map(t=>t.text);function Ul(e){const t=Ki(e),n=Qv(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:Jv(t)}:{chart:n}}function vb(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:i,op:s,given:o}=r.binding;t.push({field:zh(i),given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function bb(e,t,n){const r=[];for(const i of e.givens){const s=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(i.declaration);s&&r.push({name:s[1],type:s[2],default:s[3].trim(),...yb(n(Ki(Kr(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function yb(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 Ws(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 xb=/^"((?:[^"\\]|\\.)+)"$/,wb=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Zi(e,t,n=!1){try{return await kb(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 kb(e){const{parseAnnotation:t}=await Ho(),n=Ch(e),r=await Cf(e);if(kf(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,s=jc(n).text,o=Ef(i.modelNotes,t);if(o.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(o.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${o.errors[0]?`: ${o.errors[0]}`:"."}`};if(o.status==="kind-removed")return{ok:!1,reason:gb(o.kind)};const a=o.layout,c=rs(n);if(c===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!Ec(c.text))return{ok:!1,reason:Oc,line:c.from+1};const{tag:u,errors:l}=Ja(t,[Mc(c.text)]),d=u?.tag("artifact"),f=Qa(c.text);if(f===void 0)return l.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${l[0]}`}:a==="linear"?{ok:!1,legacyNotebook:!0,reason:"This report is in the cell format, with no `tiles=[…]` list."}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=i.imports.map(C=>C.names?{kind:"names",names:C.names,from:C.from}:{kind:"all",from:C.from}),g=[],m=[],y=new Map;for(const C of i.sources){const O={name:C.name,base:C.base};C.dimensions.length>0&&(O.dimensions=C.dimensions.map($=>({name:$.name,expression:$.expression})));const T=new Set(C.wheres.flatMap($=>$.clauses.flatMap(D=>D.givens)));T.size>0&&(O.scopedBy=Array.from(T)),g.push(O);for(const $ of C.dimensions){const D=t(Ki(Kr(i,n,$.line).tags)).tag?.tag("drill");if(!D)continue;const z=D.textArray("to")??[D.text("to")??""];m.push({source:C.name,name:$.name,expression:$.expression,to:z.filter(Boolean),...D.text("given")?{given:D.text("given")}:{}})}y.set(C.name,new Map(C.views.map($=>[$.name,$])))}const w=[];for(const{text:C}of f.entries){const O=xb.exec(C),T=O?void 0:wb.exec(C)?.[1];if(T!==void 0){const Z=t([`# ${C}`]).tag?.tag(T);if(Z?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${C}\` is neither a quoted \`source -> view\` expression nor a \`${T} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(w.some(J=>Re(J)&&J.name===T))return{ok:!1,reason:`Two text tiles are named \`${T}\`, so the builder cannot tell them apart.`};const ne=Ws(Z,"colspan");w.push({kind:"text",name:T,markdown:i.textBlocks.find(J=>J.name===T)?.body??"",...ne===void 0?{}:{colspan:ne},...Z.has("break")?{break:!0}:{}});continue}const $=O?.[1]??C,D=O?jh($):void 0;if(!D)return{ok:!1,reason:`The tile \`${$}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:z,view:N}=D,L=y.get(z)?.get(N);if(L===void 0){w.push({name:N,source:z,declaration:{kind:"inherited"}});continue}const B=t(Ki(L.tags)).tag,H=L.body.kind==="reference"?{kind:"reference",from:L.body.from}:L.body.kind==="inline"?{kind:"inline"}:void 0;if(H===void 0){w.push({name:N,source:z,declaration:{kind:"opaque",why:L.body.kind==="unsupported"?L.body.why:"unreadable"},...B?.text("label")?{label:B.text("label")}:{},...B?.text("subtitle")?{subtitle:B.text("subtitle")}:{},...B?.numeric("colspan")!==void 0?{colspan:B.numeric("colspan")}:{},...Ul(L.tags),...B?.has("break")?{break:!0}:{},...B?.has("borderless")?{borderless:!0}:{}});continue}const Y=vb(L.body.kind==="reference"?L.body.refinement:L.body.kind==="inline"?L.body.stage:void 0);w.push({name:N,source:z,declaration:H,...Y?{filters:Y}:{},...B?.text("label")?{label:B.text("label")}:{},...B?.text("subtitle")?{subtitle:B.text("subtitle")}:{},...B?.numeric("colspan")!==void 0?{colspan:B.numeric("colspan")}:{},...Ul(L.tags),...B?.has("break")?{break:!0}:{},...B?.has("borderless")?{borderless:!0}:{}})}const p=bb(i,n,t),v={},x=d?.tag("givens");for(const C of Object.keys(x?.dict??{})){const O=x?.text(C);O!==void 0&&(v[C]=O)}const k=u?.tag("dashboard")?.has("columns")?Ws(u.tag("dashboard"),"columns"):d?.array("tiles")?Ws(d,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:d?.text("title")??"",...s?{description:s}:{},...k===void 0?{}:{columns:k},...d?.has("autorun")?{autorun:d.isTrue("autorun")}:{},imports:h,sources:g,...p?{localGivens:p}:{},...Object.keys(v).length>0?{startingGivens:v}:{},...m.length>0?{drills:m}:{},tiles:w}}}const Wo=e=>e.ok===!1;async function Xl(e){const{problems:t}=await Xr(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function xe(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 Of(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Sb(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
77
|
`&&t.push(n+1);return t}function $b(e,t){let n=e;const r=t.map((i,s)=>({edit:i,index:s}));for(const{edit:i}of r.sort((s,o)=>o.edit.start-s.edit.start||o.edit.end-s.edit.end||o.index-s.index))n=n.slice(0,i.start)+i.text+n.slice(i.end);return n}const Mf=e=>e==="none"||gs(e)?e:void 0;function Af(e,t=!0){const n=[];e.colspan!==void 0&&n.push(`# colspan=${e.colspan}`),e.break&&n.push("# break"),e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${ut(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${ut(e.subtitle)}`);const r=t?Mf(e.chart):void 0;return r!==void 0&&n.push(Tn(r,e.chartCarried)),n}function Oi(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Cb=new Set(["colspan","break","borderless","label","subtitle"]),jb=new Set(["label","description","control","suggest","range_min","range_max"]);function Kl(e){const t=[];if(e.label!==void 0&&t.push(`label=${ut(e.label)}`),e.description!==void 0&&t.push(`description=${ut(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=${ut(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${ut(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 Zl=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Eb(e,t,n){const r=e.sources.find(i=>i.name===t)?.views.find(i=>i.name===n);return r?r.line:-1}function Ql(e){const t=n=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(n)?n:ut(n);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(ut).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Qi=e=>`${e.source}.${e.name}`,ut=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,zo=e=>Re(e)?xe(["text",e.name]):xe([e.name,e.source,e.declaration]),rt=zo,Jl=e=>xe(e.tiles.map(rt));function Ob(e,t,n){const r=new Set(e.tiles.map(rt)),i=new Set(t.tiles.map(rt)),s=e.tiles.filter(f=>!i.has(rt(f))),o=t.tiles.filter(f=>!r.has(rt(f))),a=s.length>0||o.length>0||Jl(e)!==Jl(t);for(const f of o)if(ve(f)&&f.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${f.name}\` is ${f.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const c=new Map(e.sources.map(f=>[f.name,f])),u=new Set(t.imports.flatMap(f=>f.kind==="names"?f.names:[]));for(const f of e.sources)u.add(f.base);const l=t.imports.some(f=>f.kind==="all"),d=t.sources.filter(f=>!c.has(f.name));for(const f of e.sources){const h=t.sources.find(g=>g.name===f.name);if(!h||h.base!==f.base)return{ok:!1,reason:`The source \`${f.name}\` cannot be changed or removed here.`}}for(const f of d){if(!o.some(h=>ve(h)&&h.source===f.name))return{ok:!1,reason:`A new source \`${f.name}\` needs a tile on it.`};if(!u.has(f.base)&&!l&&!n?.includes(f.base))return{ok:!1,reason:`\`${f.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:i,removedTiles:s,addedTiles:o,newSources:d,currentSources:c,reordered:a}}const ec=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function Mb(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Lr(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function tc(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=Mb(t),r=n.indexOf("{"),i=n.lastIndexOf("}");let s=t.slice(r+1,i),o=n.slice(r+1,i);const a=u=>{const l=u.exec(o);l&&(s=s.slice(0,l.index)+s.slice(l.index+l[0].length),o=o.slice(0,l.index)+o.slice(l.index+l[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const c=[s.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${c.join(" ")} }${t.slice(i+1)}`}function Ab(e){const{lines:t,wholeLine:n,current:r,next:i,reordered:s,currentKeys:o,nextKeys:a,edits:c}=e,u=new Map(r.tiles.filter(Re).map(p=>[p.name,p])),l=i.tiles.filter(Re).some(p=>{const v=u.get(p.name);return v!==void 0&&ec(v,p)});if(!s&&!l)return;const d=rs(t);if(!d)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=d.text,h=Qa(f);if(!h)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&o.size>0)return{ok:!1,reason:"A grid report with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const g=new Map;for(const{text:p}of h.entries){const v=/^"((?:[^"\\]|\\.)+)"$/.exec(p);if(v){const k=v[1].split("->").map(C=>C.trim());k.length===2&&g.set(`${k[0]}->${k[1]}`,p);continue}const x=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(p)?.[1];x!==void 0&&g.set(`text.${x}`,p)}const m=i.tiles.map(p=>{const v=!o.has(rt(p));if(Re(p)){const x=g.get(`text.${p.name}`);return x!==void 0?u.has(p.name)&&!ec(u.get(p.name),p)?x:tc(p,x):v?tc(p):void 0}return g.get(`${p.source}->${p.name}`)??(v?`"${p.source} -> ${p.name}"`:void 0)});if(m.some(p=>p===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const y=f.slice(0,h.open).search(/tiles\s*=\s*$/),w=`${f.slice(0,y)}tiles=[${Tb(f,h,m)}]${f.slice(h.close+1)}`;w!==f&&c.push({...Tf(n,d),text:`${w}
|
|
78
78
|
`})}function Tf(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Tb(e,t,n){const r=t.entries[0],i=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const s=e.slice(t.open+1,r.span.start),o=e.slice(i.span.end,t.close),a=s.slice(s.lastIndexOf(`
|
|
79
79
|
`)),c=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
|
|
@@ -98,7 +98,7 @@ ${y}`}),t.some(p=>p.trim().startsWith("##! experimental.givens"))||o.push({start
|
|
|
98
98
|
`})}}const nc=(e,t)=>`import { ${e.join(", ")} } from ${ut(t)}`;function Lb(e){const{parsed:t,current:n,next:r,edits:i,wholeLine:s}=e,o=d=>xe(d.imports.flatMap(f=>f.kind==="all"?[f.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(xe(n.imports)===xe(r.imports))return;const a=r.imports.flatMap(d=>d.kind==="names"?[{...d,claimed:!1}]:[]),c=new Set([...r.sources.map(d=>d.base),...r.tiles.filter(ve).map(d=>d.source)]),u=t.imports.map((d,f)=>({statement:d,entry:n.imports[f]}));for(const{statement:d,entry:f}of u){if(!f||f.kind!=="names")continue;const h=a.find(p=>!p.claimed&&p.from===f.from);h&&(h.claimed=!0);const g=h?.names??[],m=f.names.filter(p=>!g.includes(p)).find(p=>c.has(p));if(m!==void 0)return{ok:!1,reason:`\`${m}\` is still read by a tile, so its import cannot be removed.`};if(xe(g)===xe(f.names))continue;const y=g.length===0?el(t,d.statement):d.statement,w=t.commentIn(y);if(w)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(w.start,w.end).trim()}\`), so nothing was written. Delete it in the file first.`};i.push({...y,text:g.length===0?"":nc(g,f.from)})}const l=a.filter(d=>!d.claimed);if(l.length>0){const d=t.imports.at(-1);if(!d)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const f=s(St(t,d.statement.end-1)).end;i.push({start:f,end:f,text:l.map(h=>`${nc(h.names,h.from)}
|
|
99
99
|
`).join("")})}}function Nb(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,c=new Map((i.drills??[]).map(l=>[Qi(l),l])),u=new Map((s.drills??[]).map(l=>[Qi(l),l]));for(const l of new Set([...c.keys(),...u.keys()])){const d=c.get(l),f=u.get(l);if(d&&f&&xe(d)===xe(f))continue;const h=f??d;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${l}\` names no destination.`};const g=a.sources.find(p=>p.name===h.source)?.dimensions.find(p=>p.name===h.name);if(g===void 0)return{ok:!1,reason:`\`${h.name}\` is not a dimension \`${h.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:m}=Kr(a,t,g.line),y=m.find(p=>/^#\s*drill\b/.test(p.text)),w=r(g.line);if(f===void 0)y&&o.push({...n(y.line),text:""});else if(y)o.push({...n(y.line),text:`${w}${Ql(f)}
|
|
100
100
|
`});else{const p=n(g.line).start;o.push({start:p,end:p,text:`${w}${Ql(f)}
|
|
101
|
-
`})}}}function Wb(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if(Re(o)||o.declaration.kind==="inherited")continue;const a=Df(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const c=St(s,a.statement.start),u=St(s,a.statement.end-1),l=s.trailingComment(u),d=l&&l.start>=a.statement.end?l.end:a.statement.end;if(s.text.slice(s.lineStarts[c],a.statement.start).trim()!==""||s.text.slice(d,n(u).end).trim()!==""){i.push({...el(s,a.statement),text:""});continue}i.push({start:s.lineStarts[c],end:n(u).end,text:""});const f=c===0?"":t[c-1].trim();(t[u+1]??"x").trim()===""&&(c===0||f===""||f.endsWith("{"))&&i.push({...n(u+1),text:""})}}function zb(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:i,newSources:s,currentSources:o,edits:a,parsed:c}=e,u=new Map;for(const f of i){if(Re(f))continue;const h=u.get(f.source)??[];h.push(f),u.set(f.source,h)}const l=(f,h)=>{const g=f.declaration.kind==="reference"?f.declaration.from:f.name,m=(f.filters??[]).map(y=>`where: ${
|
|
101
|
+
`})}}}function Wb(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if(Re(o)||o.declaration.kind==="inherited")continue;const a=Df(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const c=St(s,a.statement.start),u=St(s,a.statement.end-1),l=s.trailingComment(u),d=l&&l.start>=a.statement.end?l.end:a.statement.end;if(s.text.slice(s.lineStarts[c],a.statement.start).trim()!==""||s.text.slice(d,n(u).end).trim()!==""){i.push({...el(s,a.statement),text:""});continue}i.push({start:s.lineStarts[c],end:n(u).end,text:""});const f=c===0?"":t[c-1].trim();(t[u+1]??"x").trim()===""&&(c===0||f===""||f.endsWith("{"))&&i.push({...n(u+1),text:""})}}function zb(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:i,newSources:s,currentSources:o,edits:a,parsed:c}=e,u=new Map;for(const f of i){if(Re(f))continue;const h=u.get(f.source)??[];h.push(f),u.set(f.source,h)}const l=(f,h)=>{const g=f.declaration.kind==="reference"?f.declaration.from:f.name,m=(f.filters??[]).map(y=>`where: ${Uo(y.field)} ${y.op??"~"} $${y.given}`).join(", ");return[...Af(f).map(y=>`${h}${y}`),`${h}view: ${f.name} is ${g}${m?` + { ${m} }`:""}`].join(`
|
|
102
102
|
`)};let d=-1;for(const f of c.sources)d=Math.max(d,St(c,f.span.end-1));for(const[f,h]of u)if(o.has(f)){const g=c.sources.find(x=>x.name===f);if(!g)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!g.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const m=g.line,y=St(c,g.properties.closeStart);let w=" ";for(let x=m+1;x<y;x++){const k=/^(\s+)view:/.exec(n[x]);if(k){w=k[1];break}}const p=r(y).start,v=(n[y-1]??"").trim()==="";a.push({start:p,end:p,text:(v?"":`
|
|
103
103
|
`)+h.map(x=>l(x,w)).join(`
|
|
104
104
|
|
|
@@ -114,7 +114,7 @@ source: ${g.name} is ${g.base} extend {
|
|
|
114
114
|
`:"";a.push({start:w,end:w,text:p+m}),d=y}}function Fb(e){const{lines:t,starts:n,wholeLine:r,indentOf:i,current:s,next:o,edits:a,parsed:c}=e,u=new Map(s.tiles.map(l=>[rt(l),l]));for(const l of o.tiles){const d=u.get(rt(l));if(d===void 0||Re(l)||Re(d)||xe(Ji(d))===xe(Ji(l)))continue;if(l.declaration.kind==="inherited")return{ok:!1,reason:`\`${l.source} -> ${l.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const f=Eb(c,l.source,l.name);if(f<0)return{ok:!1,reason:`Could not find where \`${l.name}\` is declared inside \`${l.source}\`.`};const{tags:h}=Kr(c,t,f),g=i(f),m=Af(l,!1),y=new Map(m.map($=>[Oi($)??$,$])),w=new Set,p=Mf(l.chart),v=rc(d)!==rc(l);if(v){const $=h.filter(N=>Pr(N.text)),D=h.filter(N=>Wt(N.text)),z=d.chart==="custom"?h.filter(N=>Wt(N.text)||Pr(N.text)):$.length>0?$:D.length>1?D:[];if(z.length>0)return{ok:!1,reason:`\`${l.source} -> ${l.name}\` has a chart line the builder does not model (${z.map(N=>N.text).join(" and ")}), so its chart cannot be changed here.`}}let x=!1;for(const $ of h){if(v&&Wt($.text)){p===void 0?a.push({...r($.line),text:""}):$.text!==Tn(p,l.chartCarried)&&a.push({...r($.line),text:`${g}${Tn(p,l.chartCarried)}
|
|
115
115
|
`}),x=!0;continue}const D=Oi($.text);if(D===void 0||!Cb.has(D))continue;const z=y.get(D);if(z===void 0){a.push({...r($.line),text:""});continue}w.add(D),z!==$.text&&a.push({...r($.line),text:`${g}${z}
|
|
116
116
|
`})}const k=m.filter($=>!w.has(Oi($)??$));if(v&&p!==void 0&&!x&&k.push(Tn(p,l.chartCarried)),k.length>0){const $=n[f];a.push({start:$,end:$,text:k.map(D=>`${g}${D}
|
|
117
|
-
`).join("")})}if(xe(d.filters)===xe(l.filters))continue;const C=Df(e,l);if(!C)return{ok:!1,reason:`Could not find \`${l.name}\`'s declaration to filter it.`};if(C.body.kind==="reference"){const $=
|
|
117
|
+
`).join("")})}if(xe(d.filters)===xe(l.filters))continue;const C=Df(e,l);if(!C)return{ok:!1,reason:`Could not find \`${l.name}\`'s declaration to filter it.`};if(C.body.kind==="reference"){const $=Yb(e,l,C);if($)return $;continue}if(C.body.kind!=="inline")return{ok:!1,reason:`\`${l.name}\`'s body is ${C.body.why}, so there is no single first stage to write its filter into.`};const O=If(l.filters,C.body.stage);if(O)return Pf(l.name,O.given);const T=Rf(e,l,C.body.stage);if(T)return T}}const rc=e=>e.chart==="default"?void 0:e.chart,Ji=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:i,...s}=r;return s};function _b(e,t){const n=new Map(e.tiles.map(r=>[rt(r),r]));return{...t,tiles:t.tiles.map(r=>{const i=n.get(rt(r));return ve(r)&&r.chart===void 0&&i&&ve(i)&&i.chart!==void 0?{...r,chart:i.chart}:r})}}function Mi(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 Bb(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&&!Gh(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=Mi(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 zs=e=>`##|(markdown) ${e.name}
|
|
118
118
|
${e.markdown===""?"":`${e.markdown}
|
|
119
119
|
`}|##
|
|
120
120
|
`;function qb(e){const{sourceText:t,lines:n,wholeLine:r,current:i,next:s,parsed:o,edits:a}=e,c=new Map(i.tiles.filter(Re).map(h=>[h.name,h])),u=s.tiles.filter(Re),l=h=>o.textBlocks.find(g=>g.name===h),d=new Set(u.map(h=>h.name));for(const h of c.keys()){const g=d.has(h)?void 0:l(h);if(!g)continue;const m=St(o,g.span.end-1);a.push({...g.span,text:""});const y=r(m+1),w=g.line===0||n[g.line-1].trim()==="";y.end>y.start&&n[m+1].trim()===""&&w?a.push({...y,text:""}):g.line>0&&w&&t.slice(g.span.end).trim()===""&&a.push({...r(g.line-1),text:""})}const f=[];for(const h of u){const g=c.get(h.name),m=l(h.name);if(g===void 0){if(m)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};f.push(zs(h))}else g.markdown!==h.markdown&&(m?a.push({...m.span,text:zs(h)}):f.push(zs(h)))}if(f.length>0){const h=o.textBlocks.filter(p=>p.name===void 0||d.has(p.name)),g=h[h.length-1],m=o.sources.find(p=>p.name.endsWith("_tiles"));if(g){const p=g.span.end,v=t.slice(p);a.push({start:p,end:p,text:`
|
|
@@ -133,39 +133,39 @@ ${f.join(`
|
|
|
133
133
|
`:`
|
|
134
134
|
|
|
135
135
|
`;a.push({start:y,end:y,text:w+f.join(`
|
|
136
|
-
`)})}}const ui=(e,t=
|
|
136
|
+
`)})}}const ui=(e,t=Yo)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function Hb(e,t){const n=new Map(e.tiles.map(o=>[rt(o),o]));if(t.layout==="linear"&&t.columns!==void 0&&t.columns!==e.columns)return"A linear report is one column, so its width is not written.";const r=new Set;for(const o of t.tiles){const a=n.get(rt(o));if(Re(o)){const d=Bb(o,a&&Re(a)?a:void 0,r);if(d)return d;continue}const c=a&&ve(a)?a:void 0;if(a&&!c)continue;const u=o.chart;if(u!==void 0&&u!=="default"&&u!=="none"&&!gs(u)&&!(u==="custom"&&c?.chart==="custom"))return`"${String(u)}" is not a chart this editor writes.`;const l=new Set(c?.filters?.map(d=>d.field));for(const d of o.filters??[])if(!l.has(d.field)&&/[\r\n]/.test(d.field))return"A filter field is one line.";if(a===void 0){const d=[o.name,o.source];o.declaration.kind==="reference"&&d.push(o.declaration.from);for(const f of d){const h=ui(f);if(h)return h}}for(const d of["label","subtitle"]){const f=o[d];if(f===void 0||f===c?.[d])continue;const h=Gt(`tile ${d}`,f);if(h)return h}}const i=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!i.has(o.name))for(const a of[o.name,o.base]){const c=ui(a);if(c)return c}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=Gt("description line",o);if(a)return a}if(t.title!==e.title){const o=Gt("title",t.title);if(o)return o}const s=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=s.get(o.name);if(a===void 0){const u=ui(o.name,Pc);if(u)return u}const c=o.suggest?.source;if(c!==void 0&&c!==a?.suggest?.source){const u=ui(c);if(u)return`The suggest source is not a name. ${u}`}for(const u of["query","dimension"]){const l=o.suggest?.[u];if(l===void 0||l===a?.suggest?.[u])continue;const d=Gt(`suggest ${u}`,l);if(d)return d}for(const u of["label","description"]){const l=o[u];if(l===void 0||l===s.get(o.name)?.[u])continue;const d=Gt(`given ${u}`,l);if(d)return d}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const c=Gt(`starting value for ${o}`,a);if(c)return c}}const St=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Df(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function If(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const i of r.clauses)if(!i.binding)for(const s of i.givens)n.add(s);return(e??[]).find(r=>n.has(r.given))}function Pf(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 Ai=e=>`where: ${Uo(e.field)} ${e.op??"~"} $${e.given}`;function ic(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 Gb(e,t,n){const r=e.commentIn(n);if(r)return r;const i=e.trailingComment(St(e,t.end-1));return i&&i.start>=t.end&&e.text.slice(t.end,i.start).trim()===""?i:void 0}function Vb(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 el(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),i=e.text.indexOf(`
|
|
137
137
|
`,t.end),s=e.text.slice(t.end,i<0?void 0:i);if(r.trim()===""&&s.trim()==="")return{start:n,end:i<0?e.text.length:i+1};if(r.trim()===""){const a=/^\s*/.exec(s)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function Rf(e,t,n){const{parsed:r,edits:i}=e,s=new Map((t.filters??[]).map(f=>[f.given,f])),o=new Set;let a;for(const f of n.wheres){const h=f.clauses.map((m,y)=>({clause:m,index:y})).filter(({clause:m})=>m.binding!==void 0);if(h.length===0)continue;const g=h.filter(({clause:m})=>s.has(m.binding.given));for(const{clause:m}of h)o.add(m.binding.given);if(g.length===0&&h.length===f.clauses.length){const m=el(r,f.span),y=Gb(r,f.span,m);if(y)return ic(t.name,r,y);i.push({...m,text:""});continue}g.length>0&&(a=f.span);for(let m=h.length-1;m>=0;m--){const{clause:y,index:w}=h[m],p=s.get(y.binding.given);if(!p){const x=Vb(f.clauses,w),k=r.commentIn(x);if(k)return ic(t.name,r,k);i.push({...x,text:""});continue}const v=Ai(p).replace(/^where:\s*/,"");v!==r.text.slice(y.span.start,y.span.end)&&i.push({...y.span,text:v})}}const c=(t.filters??[]).filter(f=>!o.has(f.given));if(c.length===0)return;let u=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const f=r.trailingComment(St(r,u));f&&f.start>=u&&(u=f.end)}const l=a!==void 0&&!/,\s*$/.test(r.text.slice(0,u))?", ":" ",d=n.oneLine?`${l}${c.map(Ai).join(", ")}`:c.map(f=>`
|
|
138
|
-
${n.indent}${Ai(f)}`).join("");i.push({start:u,end:u,text:d})}function
|
|
138
|
+
${n.indent}${Ai(f)}`).join("");i.push({start:u,end:u,text:d})}function Yb(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:s}=n.body,o=If(t.filters,s);if(o)return Pf(t.name,o.given);const a=t.filters??[];if(!s){if(a.length===0)return;const l=` + { ${a.map(Ai).join(", ")} }`;r.push({start:i.end,end:i.end,text:l});return}const c=s.wheres.some(l=>l.clauses.some(d=>!d.binding)),u=s.statements.some(l=>!s.wheres.some(d=>d.span.start===l.span.start));if(a.length===0&&!c&&!u){const l={start:i.end,end:s.span.end},d=e.parsed.commentIn(l);if(d)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(d.start,d.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,s)}async function Ub(e,t,n={}){if(!(e.includes(`\r
|
|
139
139
|
`)&&!/(?<!\r)\n/.test(e)))return sc(e,t,n);const r=await sc(e.replace(/\r\n/g,`
|
|
140
140
|
`),t,n);return Wo(r)?r:{...r,source:r.source.replace(/\n/g,`\r
|
|
141
|
-
`)}}async function sc(e,t,n){const r=await Zi(e);if(
|
|
142
|
-
`),l=Sb(e),d=p=>({start:l[p],end:p+1<l.length?l[p+1]:e.length}),f=p=>/^\s*/.exec(u[p])?.[0]??"",h=[],g={...o,sourceText:e,parsed:c.parsed,lines:u,starts:l,wholeLine:d,indentOf:f,current:i,next:s,edits:h};for(const p of[Ab,Pb,Lb,Rb,Nb,Wb,zb,Fb,qb]){const v=p(g);if(v)return v}const m=p=>{const{drills:v,localGivens:x,description:k,...C}=p,O=p.tiles.map(T=>{if(Re(T))return T;if(T.filters?.length)return Ji(T);const{filters:$,...D}=T;return Ji(D)});return{...C,...k===void 0?{}:{description:Of(k)},tiles:O,...v?.length?{drills:[...v].sort((T,$)=>Qi(T).localeCompare(Qi($)))}:{},...x?.length?{localGivens:x}:{}}};if(h.length===0)return xe(m(i))!==xe(m(s))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const y=$b(e,h);if((await Yl(e)).length===0){const p=await Yl(y);if(p.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${p[0]}). Your changes are still here.`}}const w=await Zi(y);return Yi(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:xe(m(w.document))!==xe(m(s))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:y}}function Lf({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=Ze(),[s,o]=S.useState(!1),a=S.useMemo(()=>s?{text:e}:void 0,[s,e]),{draft:c,patch:u,close:l,discard:d}=Lc(a,s,v=>n(v.text),()=>o(!1)),f=s&&c!==void 0&&c.text!==e,h=c!==void 0&&c.text!==e?Mi(c.text):void 0;sf(f,()=>h!==void 0?!1:(l(),!0));const g=S.useRef(null),m=S.useRef(!1);S.useEffect(()=>{s||(m.current=!1)},[s]);const y=S.useCallback(v=>{!v||m.current||(m.current=!0,v.setSelectionRange(v.value.length,v.value.length))},[]);if(!s||c===void 0){const v=e.trim()?Mi(e):void 0;return b.jsxs(De,{role:"button",tabIndex:0,onClick:x=>{x.target.closest("a")?x.preventDefault():o(!0)},onKeyDown:x=>{x.target===x.currentTarget&&(x.key!=="Enter"&&x.key!==" "||(x.preventDefault(),o(!0)))},sx:[{minHeight:24},nf(i,"prose")],children:[e.trim()?b.jsx(Mh,{variant:r,children:e}):b.jsx(ue,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),v&&b.jsx(ue,{variant:"caption",color:"error",role:"alert",children:v})]})}const w=c.text!==e?Mi(c.text):void 0,p=()=>{w===void 0&&l()};return b.jsxs(ye,{spacing:1,children:[b.jsx(Je,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:c.text,placeholder:t,error:w!==void 0,helperText:w,inputRef:y,inputProps:{"aria-label":"Markdown"},onChange:v=>u(x=>{x.text=v.target.value}),onKeyDown:v=>{v.key==="Escape"?p():v.key==="Enter"&&(v.metaKey||v.ctrlKey)&&(v.preventDefault(),p())},onBlur:v=>{v.relatedTarget instanceof Node&&g.current?.contains(v.relatedTarget)||l()}}),b.jsxs(ye,{ref:g,direction:"row",spacing:1,children:[b.jsx(Oe,{size:"small",variant:"outlined",disabled:w!==void 0,onClick:p,children:"Done"}),b.jsx(Oe,{size:"small",onMouseDown:v=>v.preventDefault(),onClick:()=>{d(),o(!1)},children:"Cancel"})]})]})}const Yb="Write markdown: # heading, **bold**, - list";function Kb({tile:e,onChange:t,chrome:n="card"}){return b.jsx(ts,{chrome:n,kind:"text",children:b.jsx(Lf,{markdown:e.markdown,placeholder:Yb,onCommit:t})})}const es=e=>e.label??Ph(`${e.source} -> ${e.name}`);function Zb({tile:e,index:t,selected:n,flash:r=!1,menuOpen:i,bare:s=!1,onInsertAfter:o,onSelect:a,onOpenMenu:c,resizing:u=!1,width:l,onResizeStart:d,onResizeMove:f,onResizeEnd:h,children:g}){const{theme:m}=Ze();return b.jsx(Xv,{id:ze(e),index:t,children:({ref:y,handleRef:w})=>b.jsxs(De,{ref:y,onClick:a,onPointerDown:p=>{p.button===0&&a()},role:"group","aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":ze(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Nf(m,{selected:n,flash:r,bare:s}),"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:m.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${m.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[g,b.jsx(De,{ref:w,"aria-label":`Move ${ei(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),b.jsx(Ti,{className:"builder-affordance",size:"small","aria-label":`Settings for ${ei(e)}`,onClick:p=>{p.stopPropagation(),c(p.currentTarget)},sx:{position:"absolute",top:`${-((s?Tc+1:0)+12)}px`,right:s?0:"12px",border:m.cardBorder,borderRadius:1,width:28,height:24,zIndex:2,color:m.tileTitle,bgcolor:m.tile,opacity:n||i?.9:0,transition:`opacity ${dt}`,...Lt,"&:hover":{opacity:1,bgcolor:m.tile}},children:b.jsx(ty,{})}),d&&b.jsx(De,{className:"builder-affordance",[yf]:"",role:"separator",tabIndex:l?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${ei(e)}`,...l?{"aria-valuenow":l.span,"aria-valuemin":1,"aria-valuemax":l.columns,"aria-valuetext":`${l.span} of ${l.columns} columns`}:{},onKeyDown:p=>{if(!l)return;const v=p.key==="ArrowRight"?l.span+1:p.key==="ArrowLeft"?l.span-1:p.key==="Home"?1:p.key==="End"?l.columns:void 0;v!==void 0&&(p.preventDefault(),p.stopPropagation(),l.onStep(Math.min(Math.max(v,1),l.columns)))},onPointerDown:d,onPointerMove:f,onPointerUp:h,onPointerCancel:h,onClick:p=>p.stopPropagation(),sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:u||n?1:0,transition:`opacity ${dt}`,...Lt,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${m.accent}`,outlineOffset:1,borderRadius:"3px"},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"28px",borderRadius:"2px",bgcolor:m.accent}}}),o&&b.jsx(Ti,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${ei(e)}`,onClick:p=>{p.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${(s?wc:En)/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:m.tileTitle,bgcolor:m.tile,border:m.cardBorder,opacity:0,transition:`opacity ${dt}`,...Lt,"&:hover, &:focus-visible":{opacity:1,bgcolor:m.tile}},children:b.jsx(Nr,{sx:{fontSize:14}})})]})})}const Fs=4,Nf=(e,{selected:t,flash:n=!1,bare:r=!1})=>{const i=t||n?e.accent:"transparent",s=t?e.accent:e.cardBorder.replace(/^1px solid /,""),o=`outline-color ${dt}, border-color ${dt}, opacity ${dt}, box-shadow ${dt}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-Tc}px`,borderRadius:1,border:`2px solid ${i}`,pointerEvents:"none",transition:o,...Lt},"&:hover::before":{borderColor:s}}:{borderRadius:1,outline:`2px solid ${i}`,outlineOffset:2,...n&&{boxShadow:`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`},transition:o,...Lt,"&:hover":{outlineColor:s,boxShadow:e.shadow.lift}}};function Qb({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=Ze();return b.jsxs(ts,{chrome:r,children:[b.jsx(Cc,{title:t?.title??es(e),subtitle:t?t.subtitle:e.subtitle}),n&&b.jsx(ue,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),b.jsxs(ue,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function Jb({after:e}){const{theme:t}=Ze();return b.jsx(Yv,{id:af(e),after:e,children:({ref:n,isDropTarget:r})=>b.jsx(De,{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 ${dt}, background-color ${dt}`,...Lt}})})}function ey({columns:e}){const{theme:t}=Ze();return b.jsx(De,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${En}px`},children:Array.from({length:e},(n,r)=>b.jsx(De,{sx:{borderLeft:`1px dashed ${t.accent}`,borderRight:r===e-1?`1px dashed ${t.accent}`:"none",opacity:.35}},r))})}function ty(){return b.jsxs(Fh,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[b.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),b.jsx("circle",{cx:"12",cy:"12",r:"2"}),b.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function ny({editor:e,reorder:t,resizing:n,gridBox:r,columns:i,notebook:s,chrome:o,canAdd:a,selected:c,flash:u,menuIndex:l,onSelect:d,onOpenMenu:f,openAdd:h,editTile:g,renderTile:m}){const{dragging:y,preview:w,onDragStart:p,onDragOver:v,onDragEnd:x}=t,{resize:k,startResize:C,onResize:O,endResize:T}=n,$=k!==void 0?e.document.tiles.map((L,B)=>B===k.index?{...L,colspan:k.span}:L):w??e.document.tiles,D=e.document.tiles.length===0,z=y?mv($,i):$.map(of),N=L=>ry(L,es(L),g);return b.jsxs(b.Fragment,{children:[b.jsx(Kg,{sensors:Vv,onDragStart:p,onDragOver:v,onDragEnd:x,children:b.jsxs(De,{ref:r,sx:{position:"relative"},children:[!s&&(y||k!==void 0)&&b.jsx(ey,{columns:i}),b.jsx(ch,{tiles:z,columns:i,rowGapPx:o==="none"?wc:En,keyOf:L=>L.kind==="gap"?af(L.after):ze(L.tile),renderTile:L=>{if(L.kind==="gap")return b.jsx(Jb,{after:L.after});const{tile:B,index:H}=L;return b.jsx(Zb,{tile:B,index:H,selected:H===c,flash:ze(B)===u,menuOpen:l===H,bare:o==="none",...s&&a?{onInsertAfter:()=>h(H+1)}:{},...i>1&&iy(B)?{resizing:k?.index===H,width:{span:B.colspan??1,columns:i,onStep:U=>{U!==(B.colspan??1)&&e.update(Z=>{const ne=Z.tiles[H];ne&&(ne.colspan=U)})}},onResizeStart:U=>C(U,H),onResizeMove:O,onResizeEnd:T}:{},onSelect:()=>d(H),onOpenMenu:U=>f(U,H),children:Re(B)?b.jsx(Kb,{tile:B,chrome:o,onChange:U=>g(ze(B),Z=>{Re(Z)&&(Z.markdown=U)})}):m&&!e.pendingOpen?m(B,N(B),o):b.jsx(Qb,{tile:B,chrome:o,heading:N(B),...e.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),s&&a&&!D&&b.jsx(Oe,{size:"small",startIcon:b.jsx(Nr,{}),"aria-label":"Add tile at the end",onClick:()=>h(),sx:{alignSelf:"center"},children:"Add tile"})]})}const ry=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=ze(e),i=s=>o=>n(r,a=>{ve(a)&&(o===""?delete a[s]:a[s]=o)});return{title:b.jsx(Io,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:i("label")}),subtitle:b.jsx(Io,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:i("subtitle")})}},iy=e=>Re(e)||e.declaration.kind!=="inherited";function sy({editor:e,documentSlug:t,chrome:n,actions:r,descriptionSelected:i,selectDescription:s}){const{theme:o}=Ze();return b.jsxs(b.Fragment,{children:[b.jsxs(ye,{direction:"row",sx:{alignItems:"center",gap:2},children:[b.jsx(ue,{variant:"h5",sx:{flex:1,minWidth:0},children:b.jsx(Io,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:a=>e.update(c=>{c.title=a})})}),b.jsx(De,{sx:{my:"-4px"},children:r})]}),b.jsx(De,{role:"group","aria-label":"Description","aria-current":i,onPointerDown:s,onFocus:s,sx:n==="none"?{my:`${ah}px`}:void 0,children:b.jsx(ts,{chrome:n,kind:"text",sx:{position:"relative",overflow:"visible",...Nf(o,{selected:i,bare:n==="none"})},children:b.jsx(Lf,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:a=>e.update(c=>{a.trim()===""?delete c.description:c.description=a})})})})]})}const oy=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:s}=_o({path:t,layout:n},i);return{size:e,saved:({size:o,structural:a,durationMs:c,fromOpen:u})=>s({type:"report.saved",tiles:o,structural:a,...u?{converted:!0}:{},where:r,durationMs:c}),refused:o=>s({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:c})=>s({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:c}),undoRefused:o=>s({type:"report.save_undo_refused",reason:o})}},ay=Wr(b.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"})),ly=Wr(b.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"})),Fo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),_s=Fo?"⌘":"Ctrl+",oc=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Bs=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function cy(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e});const[n,r]=S.useState(!1);S.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),S.useEffect(()=>{const i=s=>{const o=t.current;if(o.paused)return;const a=Fo?s.metaKey:s.ctrlKey,c=s.key.toLowerCase();if(s.key==="Escape"){if(oc(s.target)||Bs(s.target))return;o.escape();return}if(oc(s.target)){if(a&&c==="s"){if(s.preventDefault(),!o.save||Bs(s.target))return;s.target.blur(),r(!0)}return}if(Bs(s.target)){a&&c==="s"&&s.preventDefault();return}if(a&&c==="z"){s.preventDefault(),s.shiftKey?o.redo():o.undo();return}if(!Fo&&a&&c==="y"){s.preventDefault(),o.redo();return}if(a&&c==="s"){s.preventDefault(),o.save?.();return}o.nudge&&!a&&!s.altKey&&!s.shiftKey&&(s.key==="ArrowLeft"||s.key==="ArrowRight")&&(s.preventDefault(),o.nudge(s.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[])}const ac={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function dy({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:i,saving:s,onSave:o,savesTo:a="package",saveLabel:c,saveButton:u,actions:l,onAddTile:d,onExit:f,layout:h,onLayoutChange:g}){return b.jsxs(ye,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[h&&g&&b.jsxs(b.Fragment,{children:[b.jsx(Tt,{title:"Layout: tiles side by side, or one after another",children:b.jsxs(Yo,{size:"small",exclusive:!0,value:h,"aria-label":"Layout",onChange:(m,y)=>{y&&y!==h&&g(y)},sx:{"& .MuiToggleButton-root":{py:.25,px:1}},children:[b.jsx(Dn,{value:"linear","aria-label":"Linear layout",children:"Linear"}),b.jsx(Dn,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),b.jsx(ks,{orientation:"vertical",flexItem:!0,sx:{mx:.5}})]}),d&&b.jsx(Oe,{startIcon:b.jsx(Nr,{}),onClick:d,"aria-label":"Add tile",children:"Tile"}),d&&b.jsx(ks,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),b.jsx(Tt,{title:`Undo (${_s}Z)`,children:b.jsx("span",{children:b.jsx(Ti,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:b.jsx(ly,{fontSize:"small"})})})}),b.jsx(Tt,{title:`Redo (${_s}⇧Z)`,children:b.jsx("span",{children:b.jsx(Ti,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:b.jsx(ay,{fontSize:"small"})})})}),(l||o||f)&&b.jsx(ks,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),l,o?b.jsx(Tt,{title:i?`Save (${_s}S) · ${c??ac[a]}`:c??ac[a],children:b.jsx("span",{children:b.jsx(Oe,{ref:u,variant:i?"contained":"outlined",disabled:!i||s,onClick:o,sx:{minWidth:124},children:s?"Saving…":i?"Save":"Saved"})})}):null,o&&b.jsx(De,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:s?"Saving":i?"Unsaved changes":"All changes saved"}),f&&b.jsx(sh,{label:"Close",icon:b.jsx(oh,{}),onClick:f})]})}const uy=Wr(b.jsx("path",{d:"M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12z"})),fy=Wr(b.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function hy({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:i,addDisabledReason:s,onRemove:o,children:a}){const{theme:c}=Ze();return b.jsx(b.Fragment,{children:b.jsxs(ye,{sx:{gap:1,position:"sticky",top:0,zIndex:lh,bgcolor:"background.default",pb:1},children:[b.jsx(ye,{direction:"row",sx:{gap:2,alignItems:"center",minHeight:32},children:b.jsxs(ye,{direction:"row",role:"group","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",flex:1,minWidth:0},children:[b.jsx(fy,{sx:{fontSize:18,color:c.tileTitle,opacity:.7}}),b.jsx(ue,{variant:"subtitle2",sx:{color:c.tileTitle,mr:.5},children:"Filters"}),e.length===0&&b.jsx(ue,{variant:"body2",sx:{color:c.tileTitle,opacity:.8},children:"None yet."}),e.map(u=>{const l=n(u.name,u.type);return b.jsx(Tt,{title:l.length>0?`$${u.name} · cannot filter on: ${l.join(", ")}`:`$${u.name} · ${u.origin==="dashboard"?"declared here":"from the model"} · ${u.boundTiles} of ${t} tiles`,children:b.jsx(Us,{size:"small",label:`${u.label??u.name}${u.boundTiles===0?" · unused":""}`,"aria-label":`Edit filter ${u.name}`,color:l.length>0?"warning":"default",variant:u.origin==="dashboard"?"filled":"outlined",onClick:()=>r(u),onDelete:()=>o(u.name),deleteIcon:b.jsx(uy,{"aria-label":`Remove filter ${u.name}`}),sx:{opacity:u.boundTiles===0?.6:1,cursor:"pointer",transition:`opacity ${dt}`,...Lt}})},u.name)}),b.jsx(Tt,{title:s??"",children:b.jsx("span",{children:b.jsx(Us,{component:"button",size:"small",variant:"outlined",icon:b.jsx(Nr,{}),label:"Filter","aria-label":"Add filter","aria-haspopup":"dialog",disabled:s!==void 0,onClick:()=>i(),sx:{cursor:"pointer",color:c.tileTitle,borderStyle:"dashed","& .MuiChip-icon":{color:"inherit",fontSize:16}}})})})]})}),a]})})}function py(e,t){const n=new Map(e.tiles.map((r,i)=>[ze(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(ze(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return ze(i)}}function my({editor:e,gridBox:t}){const[n,r]=S.useState(void 0),i=typeof n=="object"?n.tile:void 0,s=n==="description",o=S.useCallback(m=>r(y=>typeof y=="object"&&y.tile===m?y:{tile:m}),[]),a=S.useCallback(()=>r(m=>m==="description"?m:void 0),[]),c=S.useCallback(()=>r("description"),[]),u=S.useCallback(()=>r(void 0),[]),[l,d]=S.useState(void 0),f=S.useRef(!1),h=S.useRef(e.document);S.useEffect(()=>{const m=h.current;if(h.current=e.document,!f.current)return;f.current=!1;const y=py(m,e.document);y!==void 0&&(d(y),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(w=>w.dataset.tileKey===y)?.scrollIntoView?.({block:"nearest",behavior:ih()}))},[e.document,t]),S.useEffect(()=>{if(l===void 0)return;const m=setTimeout(()=>d(void 0),1500);return()=>clearTimeout(m)},[l]);const g=S.useMemo(()=>({...e,undo:()=>{f.current=!0,e.undo()},redo:()=>{f.current=!0,e.redo()}}),[e]);return{selected:i,descriptionSelected:s,selectTile:o,deselectTile:a,selectDescription:c,clearSelection:u,flash:l,stepEditor:g}}function gy({dirty:e,saving:t,canSave:n,save:r,onExit:i}){const[s,o]=S.useState("idle"),[a,c]=S.useState(!1),u=S.useRef(r);u.current=r;const l=S.useRef(i);l.current=i;const d=S.useRef(0),f=S.useCallback(async()=>{const h=++d.current;c(!1),o("saving");try{await u.current()}catch{d.current===h&&o("idle");return}d.current===h&&c(!0)},[]);return S.useEffect(()=>{if(s==="waiting"){if(t)return;e?f():(o("idle"),l.current())}else if(s==="saving"){if(!a||t)return;o("idle"),e||l.current()}},[s,a,t,e,f]),{requestExit:S.useCallback(()=>{s==="idle"&&(e?o("asking"):l.current())},[s,e]),dialog:{open:s==="asking",canSave:n,onKeepEditing:()=>{s==="asking"&&o("idle")},onDiscard:()=>{s==="asking"&&(o("idle"),l.current())},onSaveAndExit:()=>{s==="asking"&&(t?o("waiting"):f())}}}}function vy({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:i,extraDirty:s=!1,report:o,unit:a,prepare:c,shortcuts:u}){const[l,d]=S.useState(!1),[f,h]=S.useState(!1),g=S.useRef(null),m=S.useRef(o);m.current=o;const y=e.dirty||s,w=(e.edited??e.dirty)||s;S.useEffect(()=>{i?.(e.document)},[e.document,i]),S.useLayoutEffect(()=>{n?.(w)},[w,n]);const p=S.useRef(n);p.current=n,S.useEffect(()=>()=>p.current?.(!1),[]);const v=S.useRef(a);v.current=a,S.useEffect(()=>{h(!1)},[e.document]);const x=S.useCallback(()=>{d(!0),h(!1);const H=At(),{structural:U}=e,Z=e.pendingOpen??!1,ne=m.current.size;return e.save().then(J=>{J.ok===!0?m.current.saved({size:ne,structural:U,fromOpen:Z,durationMs:At()-H}):m.current.refused(J.reason)}).finally(()=>d(!1))},[e]),k=S.useRef(!1),C=S.useRef(!1);S.useEffect(()=>{!C.current||l||(C.current=!1,g.current?.focus())},[f,l]);const O=S.useCallback(()=>{if(!t||l||k.current||!e.canUndoSave)return;k.current=!0,d(!0);const H=At(),U=e.lastSave?.structural??!1,Z=m.current.size;return e.undoSave().then(ne=>{ne.ok===!0?(C.current=!0,h(!0),m.current.undone({size:Z,structural:U,fromOpen:!1,durationMs:At()-H})):m.current.undoRefused(ne.reason)}).finally(()=>{k.current=!1,d(!1)})},[t,l,e]),T=S.useCallback(()=>{if(!(!t||!e.dirty||l))return x()},[t,e,l,x]),$=S.useRef(T);$.current=T;const D=S.useCallback(()=>{const H=()=>$.current();return c?c(H):H()},[c]),z=gy({dirty:w,saving:l,canSave:!!t,save:D,onExit:()=>r?.()});cy(S.useMemo(()=>({...u,undo:e.undo,redo:e.redo,...t?{save:D}:{},paused:z.dialog.open}),[u,e,t,D,z.dialog.open]));const N=!!t&&!l&&e.canUndoSave,L=e.lastSave,B={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:y,saving:l,saveButton:g,...t?{onSave:D}:{},...r?{onExit:z.requestExit}:{}};return{saving:l,save:D,exitGuard:z,undoSave:O,canUndoSave:N,lastSave:L,toolbarProps:B}}function fi(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function lc(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&xf.includes(n))return n}}const by=1;function Wf(e,t,n){const r=[];for(const i of e??[]){const s=i.name,o=i.kind;if(typeof s=="string"){if(o==="dimension"||o==="measure"){const a=i.type?.kind;r.push({name:t+s,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=i.schema?.fields;r.push(...Wf(a,`${t}${s}.`,n-1))}}}return r}function yy(e){const t=new Map;for(const n of zf(e))t.set(n.name,Wf(n.schema?.fields,"",by));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}const xy=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&Lh.parseTag(n.slice(9)).tag?.has("calculation")===!0});function wy(e){const t=new Map;for(const n of zf(e)){const r=new Set;for(const i of n.schema?.fields??[]){if(i.kind!=="view"||typeof i.name!="string")continue;const s=i.schema?.fields;s&&s.length>0&&s.every(xy)&&r.add(i.name)}t.set(n.name,r)}return t}function cc(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const dc=(e,t)=>e!==void 0&&t.has(e),uc=e=>e.modelPath??e.path??"";function ky(e,t=new Set){const n=[],r=new Set,i=new Map,s=new Map,o=new Map;for(const a of e){const c=uc(a);if(dc(c,t))continue;const u=rh(a.modelInfo);s.set(a,u);for(const{name:l}of a.sources??[])l&&o.set(l,[...o.get(l)??[],c]);for(const l of u)i.set(l,[...i.get(l)??[],c])}for(const a of e){const c=uc(a);if(dc(c,t))continue;const u=yy(a),l=wy(a);for(const d of a.sources??[]){const f=d.name;if(!f||!s.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(d.givens??[]).map(g=>g.name).filter(g=>typeof g=="string");n.push({name:f,modelPath:c,exporters:i.get(f)??[c],visibleIn:o.get(f)??[c],...fi(d.annotations)?{description:fi(d.annotations)}:{},views:(d.views??[]).filter(g=>typeof g.name=="string").map(g=>({name:g.name,...fi(g.annotations)?{description:fi(g.annotations)}:{},...lc(g.annotations)?{chart:lc(g.annotations)}:{},...l.get(f)?.has(g.name)?{aggregateOnly:!0}:{}})),givens:h,fields:u.get(f)??[]})}}return{sources:n}}function Sy({editor:e,opened:t,givens:n,catalog:r}){const[i,s]=S.useState(void 0),o=S.useMemo(()=>{const f=new Set((t.localGivens??[]).map(h=>h.name));return(n??[]).filter(h=>!f.has(h.name))},[t,n]),a=S.useMemo(()=>Qh(e.document,o),[e.document,o]),c=S.useMemo(()=>new Map(e.document.sources.map(f=>[f.name,cc(r,f.base)])),[r,e.document.sources]),u=S.useCallback(f=>c.get(f.source)??cc(r,f.source),[c,r]),l=(f,h)=>{const g=[];for(const m of e.document.tiles){if(!ve(m))continue;const y=u(m);if(!y)continue;const w=new Map(y.map(p=>[p.name,p.type]));for(const p of m.filters??[])p.given===f&&(!w.has(p.field)||!gi(h,w.get(p.field)))&&g.push(`${p.field} on ${m.label??m.name} (${e.document.sources.find(v=>v.name===m.source)?.base??m.source})`)}return g},d=S.useMemo(()=>a.filter(f=>f.origin==="model"&&f.boundTiles===0),[a]);return{filterDialog:i,setFilterDialog:s,controlList:a,fieldsFor:u,unknownFieldsOf:l,available:d,applyFilter:(f,h,g)=>{s(void 0),e.update(m=>{g&&sp(m,g),ip(m,f,h)})},dropControl:f=>{s(void 0),e.update(h=>op(h,f))}}}function $y({pendingOpen:e,prepare:t}){const[n,r]=S.useState(void 0),i=S.useRef(e);i.current=e;const s=S.useCallback(o=>i.current?new Promise(a=>r({go:()=>{r(void 0),a(t(o))},stop:()=>{r(void 0),a()}})):t(o),[t]);return{confirmConversion:n,prepareSave:s}}function Cy(e){const{splice:t,onSave:n,structural:r,clearsHistory:i,opensDirty:s=!1}=e,[o,a]=S.useState({stack:[e.document],index:0}),[c,u]=S.useState(e.source),[l,d]=S.useState(void 0),[f,h]=S.useState(e.document),[g,m]=S.useState(s),[y,w]=S.useState(e.replaces),[p,v]=S.useState(!1),x=o.stack[o.index],k=S.useRef(o);k.current=o;const C=S.useRef(!1),[O,T]=S.useState(!1),$=R=>{C.current=R,T(R)},[D,z]=S.useState(void 0),N=S.useCallback(R=>{d(void 0),a(_=>{const Y=structuredClone(_.stack[_.index]);if(R(Y),JSON.stringify(Y)===JSON.stringify(_.stack[_.index]))return _;const Q=[..._.stack.slice(0,_.index+1),Y].slice(-100);return{stack:Q,index:Q.length-1}})},[]),L=S.useCallback(()=>{d(void 0),a(R=>R.index>0?{...R,index:R.index-1}:R)},[]),B=S.useCallback(()=>{d(void 0),a(R=>R.index<R.stack.length-1?{...R,index:R.index+1}:R)},[]),H=S.useCallback(async(R,_)=>{try{return await t(R,_)}catch(Y){return{ok:!1,reason:`Could not build the file: ${Y instanceof Error?Y.message:String(Y)}`}}},[t]),U=S.useCallback(async()=>{if(C.current)return{ok:!1,reason:"A save is still being written."};const R={source:c,saved:f,history:k.current,pendingOpen:g,replacing:y,unwritten:p},_=i?.(f,x)??!1,Y=r?.(f,x)??!1;$(!0);try{const Q=await H(c,x);if(Wo(Q))return d(Q.reason),{ok:!1,reason:Q.reason};try{await n?.(Q.source,{purpose:"save",document:x})}catch(j){const A=`Could not save: ${j instanceof Error?j.message:String(j)}`;return d(A),{ok:!1,reason:A}}u(Q.source),h(x),m(!1),w(void 0),v(!1);const E=_?{stack:[x],index:0}:R.history;return a(j=>j===R.history?E:_?{stack:[j.stack[j.index]],index:0}:j),z(n?{before:R,after:E,lastSave:{before:y??c,after:Q.source,structural:Y,clearsHistory:_}}:void 0),d(void 0),{ok:!0}}finally{$(!1)}},[x,H,n,c,f,g,y,p,i,r]),Z=S.useCallback(async()=>{if(C.current)return{ok:!1,reason:"A save is still being written."};if(!n||D===void 0||D.after!==k.current)return{ok:!1,reason:"There is no save to undo."};const{before:R}=D;$(!0);try{await n(R.replacing??R.source,{purpose:"undo",document:R.saved})}catch(_){const Y=`Could not undo the save: ${_ instanceof Error?_.message:String(_)}`;return d(Y),{ok:!1,reason:Y}}finally{$(!1)}return u(R.source),h(R.saved),m(R.pendingOpen),w(R.replacing),v(R.unwritten||R.replacing!==void 0),a(_=>_===D.after?R.history:_),z(void 0),d(void 0),{ok:!0}},[n,D]),ne=S.useMemo(()=>p||JSON.stringify(x)!==JSON.stringify(f),[x,f,p]),J=S.useMemo(()=>r?.(f,x)??!1,[x,f,r]),M=S.useMemo(()=>i?.(f,x)??!1,[x,f,i]),F=D!==void 0&&D.after===o,W=S.useCallback(async()=>{const R=await H(c,x);return Wo(R)?{ok:!1,reason:R.reason}:{ok:!0,source:R.source}},[x,H,c]);return{document:x,saved:f,source:c,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:ne||g,edited:ne,pendingOpen:g,...l===void 0?{}:{error:l},update:N,undo:L,redo:B,save:U,preview:W,structural:J,clearsHistory:M,canUndoSave:F&&!O&&n!==void 0,...F?{lastSave:D.lastSave}:{},undoSave:Z}}const jy=(e,t)=>{const n=new Set(e.tiles.map(zo)),r=new Set(t.tiles.map(zo));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function Ey(e){const{conversion:t,visibleSources:n,...r}=e,i=t?.from,s=t?.to,o=S.useCallback((a,c)=>Xb(i!==void 0&&a===i?s:a,c,n?{visibleSources:n}:{}),[i,s,n]);return Cy({...r,splice:o,structural:jy,opensDirty:t!==void 0})}function Oy({editorDirty:e}){const[t,n]=S.useState(!1),r=S.useRef(void 0),i=S.useRef(void 0),s=S.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=S.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(c=>{i.current=()=>c(a())})},[]);return S.useEffect(()=>{if(t||!i.current)return;const a=i.current;i.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:s,prepare:o}}function My(e,t,{modelPath:n,textHeld:r,notebook:i,insertAt:s}){t.modelPath&&!r&&(e.imports=Eh(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));let o=e.sources.find(u=>u.base===t.base);if(!o){const u=new Set(e.sources.map(d=>d.name));let l=`${t.base}_tiles`;for(let d=2;u.has(l);d++)l=`${t.base}_tiles_${d}`;o={name:l,base:t.base},e.sources.push(o)}const a=new Set(e.tiles.filter(ve).filter(u=>u.source===o.name).map(u=>u.name));let c=`${t.view}_tile`;for(let u=2;a.has(c);u++)c=`${t.view}_tile_${u}`;e.tiles.splice(s??e.tiles.length,0,{name:c,source:o.name,declaration:{kind:"reference",from:t.view},...i?{}:{colspan:t.colspan},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Ay({editor:e,notebook:t,columns:n,modelPath:r,textHeld:i,selectTile:s,deselectTile:o}){const[a,c]=S.useState(void 0),[u,l]=S.useState(!1),[d,f]=S.useState(void 0);return{menu:a,setMenu:c,addingTile:u,openAdd:h=>{f(h),l(!0)},closeAdd:()=>l(!1),addTile:h=>{l(!1),e.update(g=>My(g,h,{modelPath:r,textHeld:i,notebook:t,insertAt:d})),s(d??e.document.tiles.length)},addText:()=>{l(!1),e.update(h=>{const g=new Set(h.tiles.filter(Re).map(y=>y.name));let m=1;for(;g.has(`text_${m}`);)m++;h.tiles.splice(d??h.tiles.length,0,{kind:"text",name:`text_${m}`,markdown:"",...t?{}:{colspan:n}})}),s(d??e.document.tiles.length)},editTile:(h,g)=>e.update(m=>{const y=m.tiles.find(w=>ze(w)===h);y&&g(y)}),removeTile:h=>{c(void 0),o(),e.update(g=>{g.tiles.splice(h,1)})}}}var Ty=Object.defineProperty,Dy=Object.defineProperties,Iy=Object.getOwnPropertyDescriptors,fc=Object.getOwnPropertySymbols,Py=Object.prototype.hasOwnProperty,Ry=Object.prototype.propertyIsEnumerable,hc=(e,t,n)=>t in e?Ty(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gn=(e,t)=>{for(var n in t||(t={}))Py.call(t,n)&&hc(e,n,t[n]);if(fc)for(var n of fc(t))Ry.call(t,n)&&hc(e,n,t[n]);return e},vn=(e,t)=>Dy(e,Iy(t));function Ly(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function hi(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function qs(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Ny(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(p,v)=>p===v||p!==null&&typeof p=="object"&&"id"in p&&p.id===v;if(Array.isArray(e)){const p=e.findIndex(x=>c(x,s.id)),v=e.findIndex(x=>c(x,o.id));if(p===-1||v===-1){if(qs(s)){const x=s.initialIndex,k=s.index;return x===k||x<0||x>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,x,k)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const x=s.index;if(x!==p)return n(e,p,x)}return n(e,p,v)}const u=Object.entries(e);let l=-1,d,f=-1,h;for(const[p,v]of u)if(l===-1&&(l=v.findIndex(x=>c(x,s.id)),l!==-1&&(d=p)),f===-1&&(f=v.findIndex(x=>c(x,o.id)),f!==-1&&(h=p)),l!==-1&&f!==-1)break;if(l===-1&&qs(s)){const p=s.initialGroup==null?void 0:hi(e,s.initialGroup),v=s.initialIndex,x=s.group==null?void 0:hi(e,s.group),k=s.index;if(p==null||x==null||p===x&&v===k)return"preventDefault"in t&&t.preventDefault(),e;if(p===x)return vn(gn({},e),{[p]:n(e[p],v,k)});const C=e[p][v];return vn(gn({},e),{[p]:[...e[p].slice(0,v),...e[p].slice(v+1)],[x]:[...e[x].slice(0,k),C,...e[x].slice(k)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,m=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(h==null){const p=hi(e,o.id);if(p!=null){const v=o.shape&&m.y>o.shape.center.y?e[p].length:0;h=p,f=v}}if(d==null||h==null||d===h&&l===f){if(d!=null&&d===h&&l===f&&qs(s)){const p=s.group==null?void 0:hi(e,s.group),v=s.group!=null&&p!==d,x=s.index!==l;if(v||x){const k=s.group==null?d:p;if(k!=null){if(d===k)return vn(gn({},e),{[d]:n(e[d],l,s.index)});const C=e[d][l];return vn(gn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[k]:[...e[k].slice(0,s.index),C,...e[k].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return vn(gn({},e),{[d]:n(e[d],l,f)});const y=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,w=e[d][l];return vn(gn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[h]:[...e[h].slice(0,f+y),w,...e[h].slice(f+y)]})}function Wy(e,t){return Ny(e,t,Ly)}function zy({tiles:e,commit:t,onLanded:n}){const[r,i]=S.useState(void 0),s=S.useRef(void 0),[o,a]=S.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),s.current=e},onDragOver:c=>{const{source:u,target:l}=c.operation;if(!u||!l)return;const d=s.current??e;let f;if(l.type===bf){const{after:h}=l.data,g=d.findIndex(y=>ze(y)===u.id);if(g<0||h===u.id)return;const m=d.filter((y,w)=>w!==g).findIndex(y=>ze(y)===h)+1;f=pv(d,g,m)}else{const h=d.map(ze),g=Wy(h,c);if(g.every((y,w)=>y===h[w]))return;const m=new Map(d.map(y=>[ze(y),y]));f=hv(g.map(y=>m.get(y)),e.map(y=>y.break??!1))}s.current=f,i(f)},onDragEnd:c=>{a(!1);const u=s.current;if(s.current=void 0,i(void 0),c.canceled||!u)return;t(u);const l=u.findIndex(d=>ze(d)===c.operation.source?.id);l>=0&&n(l)}}}const Hs=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Fy({tiles:e,columns:t,gridBox:n,onStart:r,commit:i}){const[s,o]=S.useState(void 0),a=S.useRef(void 0),c=u=>{a.current=u,o(u)};return S.useEffect(()=>()=>Hs(!1),[]),{resize:s,startResize:(u,l)=>{const d=n.current?.getBoundingClientRect(),f=u.currentTarget.parentElement?.getBoundingClientRect();if(!d||!f)return;u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Hs(!0),r(l);const h=e[l]?.colspan??1;c({index:l,span:h,from:h,left:f.left,track:(d.width-En*(t-1))/t})},onResize:u=>{const l=a.current;if(!l)return;const d=u.clientX-l.left,f=Math.round((d+En)/(l.track+En)),h=Math.min(Math.max(f,1),t);h!==l.span&&c({...l,span:h})},endResize:u=>{u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Hs(!1);const l=a.current;if(!l)return;const{index:d,span:f,from:h}=l;c(void 0),!(u.type==="pointercancel"||f===h)&&i(d,f)}}}function Ff({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,onExit:s,allowLayoutChange:o=!0,renderTile:a,controls:c,givens:u,catalog:l,toolbar:d,dashboards:f,onEvent:h,conversion:g,savesTo:m="package",saveLabel:y,replaces:w,modelPath:p,visibleSources:v,addFilterDisabledReason:x}){const k=Ey({source:e,document:t,...n?{onSave:n}:{},...g?{conversion:g}:{},...w!==void 0?{replaces:w}:{},...v?{visibleSources:v}:{}}),C=S.useRef(null),{selected:O,descriptionSelected:T,selectTile:$,deselectTile:D,selectDescription:z,clearSelection:N,flash:L,stepEditor:B}=my({editor:k,gridBox:C}),H=k.document.layout==="linear",U=H?1:k.document.columns??Uf,Z=H?"none":"card",ne=p?.split("/").at(-1)?.replace(/\.malloy$/,""),J=zy({tiles:k.document.tiles,commit:X=>k.update(P=>{P.tiles=X}),onLanded:$}),{dragging:M}=J,F=Fy({tiles:k.document.tiles,columns:U,gridBox:C,onStart:$,commit:(X,P)=>k.update(q=>{const oe=q.tiles[X];oe&&(oe.colspan=P)})}),W=Ay({editor:k,notebook:H,columns:U,modelPath:p,textHeld:v!==void 0,selectTile:$,deselectTile:D}),{menu:R,addingTile:_,openAdd:Y}=W,Q=Sy({editor:k,opened:t,givens:u,catalog:l}),{filterDialog:E,setFilterDialog:j}=Q,[A,K]=S.useState(void 0),{draftDirty:V,openDraft:te,prepare:G}=Oy({editorDirty:k.dirty}),{confirmConversion:ae,prepareSave:ee}=$y({pendingOpen:k.pendingOpen,prepare:G}),I=S.useMemo(()=>({escape:()=>{!R&&!E&&!_&&A===void 0&&ae===void 0&&N()},nudge:X=>{if(M||O===void 0||H)return;const P=k.document.tiles[O];if(!P||ve(P)&&P.declaration.kind==="inherited")return;const q=Xf(P.colspan??1,X,U);q!==(P.colspan??1)&&k.update(oe=>{oe.tiles[O].colspan=q})}}),[k,R,E,_,A,ae,N,O,U,H,M]),re=vy({editor:B,extraDirty:V,prepare:ee,unit:{name:"tile",count:X=>X.tiles.length},onSave:n,onDirtyChange:i,onExit:s,onChange:r,shortcuts:I,report:oy({size:k.document.tiles.length,path:p??"",layout:k.document.layout,savesTo:m,onEvent:h})}),he=k.document.tiles.length===0,we=b.jsx(dy,{...re.toolbarProps,...d?{actions:d}:{},...l?{onAddTile:()=>Y()}:{},savesTo:m,...y?{saveLabel:y}:{},...v===void 0&&o?{layout:k.document.layout,onLayoutChange:X=>{const P=k.document.layout;X!==P&&(k.update(q=>{q.layout=X}),_o({path:p??"",layout:X},h).emit({type:"report.layout_changed",from:P,to:X}))}}:{}});return b.jsx(rf.Provider,{value:te,children:b.jsx(ye,{sx:{gap:0,mx:`-${Fs}px`},children:b.jsxs(ye,{sx:{gap:2,px:`${Fs}px`,pb:`${Fs}px`},children:[k.pendingOpen&&b.jsx(at,{severity:"info",children:"This report is in the cell format. Saving rewrites it as a layout notebook, and a named query run once becomes that tile's view."}),b.jsx(sy,{editor:k,notebook:H,documentSlug:ne,chrome:Z,actions:we,descriptionSelected:T,selectDescription:z}),he?b.jsx(b.Fragment,{children:b.jsxs(ye,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[b.jsx(ue,{variant:"body2",children:"This report is not served until it has a tile."}),l&&b.jsx(Oe,{size:"small",startIcon:b.jsx(Nr,{}),onClick:()=>Y(),children:"Add tile"})]})}):b.jsx(hy,{controls:Q.controlList,tileCount:k.document.tiles.length,unknownFieldsOf:Q.unknownFieldsOf,onEdit:X=>j({control:X}),onAdd:()=>j({}),...x?{addDisabledReason:x}:{},onRemove:Q.dropControl,children:c}),k.error&&b.jsx(at,{severity:"warning",children:k.error}),b.jsx(ny,{editor:k,reorder:J,resizing:F,gridBox:C,columns:U,notebook:H,chrome:Z,canAdd:!!l,selected:O,flash:L,menuIndex:R?.index,onSelect:$,onOpenMenu:(X,P)=>{$(P),W.setMenu({anchor:X,index:P})},openAdd:Y,editTile:W.editTile,...a?{renderTile:a}:{}}),b.jsx(hp,{editor:k,catalog:l,columns:U,dashboards:f,bindings:Q,tiles:W,drillSource:A,setDrillSource:K,confirmConversion:ae,exitDialog:re.exitGuard.dialog})]})})})}function _y(e,t){const n=new Set;for(const s of e.tiles)for(const o of ve(s)?s.filters??[]:[])n.add(o.given);const r=[],i=new Set;for(const s of e.localGivens??[])n.has(s.name)&&(i.add(s.name),r.push(By(s)));for(const s of t)s.name===void 0||i.has(s.name)||!n.has(s.name)||(i.add(s.name),r.push(s));return r}function By(e){const t=qy(e);return{name:e.name,type:e.type,...t===void 0?{}:{default:t},...e.label===void 0?{}:{label:e.label},...e.description===void 0?{}:{description:e.description},...e.control===void 0?{}:{control:e.control},...e.suggest?{suggest:{...e.suggest.source===void 0?{}:{source:e.suggest.source},...e.suggest.query===void 0?{}:{query:e.suggest.query},dimension:e.suggest.dimension}}:{},...e.rangeMin===void 0?{}:{rangeMin:e.rangeMin},...e.rangeMax===void 0?{}:{rangeMax:e.rangeMax}}}function qy(e){if(!e.type?.startsWith("filter<"))return e.default;const t=e.default?.match(/^f(['"])([\s\S]*)\1$/)?.[2];return t===void 0?e.default:t===""?void 0:t}function Hy(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function pi(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function Gy(e,t,n,r=new Map,i){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:i&&[...i]};const s=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(m=>[m.name,m.type])),c=e.sources.find(m=>m.name===s)?.scopedBy??[],u=new Set([...c,...i??[]].filter(m=>n.has(m))),l=new Set([...c,...i??[]]),d=[];for(const m of t.filters??[]){const y=`where: ${Xo(m.field)} ${m.op??"~"}`;if(n.has(m.given)){u.add(m.given),l.add(m.given),d.push(`${y} $${m.given}`);continue}if(!a.has(m.given))continue;l.add(m.given);const w=Rh(r.get(m.given),a.get(m.given));w!==void 0&&d.push(`${y} ${w}`)}const f=d.join(", "),h=t.chart,g=h==="none"||gs(h)?Tn(h,t.chartCarried):h==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
-
`):h==="default"&&Hy(t.declaration)?Tn("none"):void 0;return{...g?{annotation:g}:{},expression:`${s} -> ${o}`+(f?` + { ${f} }`:""),givenNames:Array.from(u),reads:i||l.size>0?Array.from(l):void 0}}function Vy({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:i,reportsSettled:s}){const{apiClients:o,server:a}=Bo(),{data:c}=qo({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(g=>g.path&&!g.error?[g.path]:[])}),u=S.useMemo(()=>new Set([r,...i.flatMap(g=>g.path?[g.path]:[])]),[i,r]),l=S.useMemo(()=>s?(c??[]).filter(g=>!u.has(g)):[],[c,u,s]),d=Ih({queries:l.map(g=>({queryKey:["report-editor-model",e,t,g,n,a],queryFn:async()=>(await o.models.getModel(e,t,g,n)).data,retry:!1}))}),f=c!==void 0&&s&&d.every(g=>g.isSuccess||g.isError),h=d.map(g=>g.dataUpdatedAt).join();return S.useMemo(()=>f?ky(d.flatMap(g=>g.data?[g.data]:[]),u):void 0,[f,l,h,u])}const
|
|
141
|
+
`)}}async function sc(e,t,n){const r=await Zi(e);if(Xi(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const i=r.document,s=_b(i,t),o=Ob(i,s,n.visibleSources);if("reason"in o)return o;const a=Hb(i,s);if(a)return{ok:!1,reason:a};const c=await Cf(e);if(kf(c))return{ok:!1,reason:`Cannot edit a file that will not open: ${c.reason}`};const u=e.split(`
|
|
142
|
+
`),l=Sb(e),d=p=>({start:l[p],end:p+1<l.length?l[p+1]:e.length}),f=p=>/^\s*/.exec(u[p])?.[0]??"",h=[],g={...o,sourceText:e,parsed:c.parsed,lines:u,starts:l,wholeLine:d,indentOf:f,current:i,next:s,edits:h};for(const p of[Ab,Pb,Lb,Rb,Nb,Wb,zb,Fb,qb]){const v=p(g);if(v)return v}const m=p=>{const{drills:v,localGivens:x,description:k,...C}=p,O=p.tiles.map(T=>{if(Re(T))return T;if(T.filters?.length)return Ji(T);const{filters:$,...D}=T;return Ji(D)});return{...C,...k===void 0?{}:{description:Of(k)},tiles:O,...v?.length?{drills:[...v].sort((T,$)=>Qi(T).localeCompare(Qi($)))}:{},...x?.length?{localGivens:x}:{}}};if(h.length===0)return xe(m(i))!==xe(m(s))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const y=$b(e,h);if((await Xl(e)).length===0){const p=await Xl(y);if(p.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${p[0]}). Your changes are still here.`}}const w=await Zi(y);return Xi(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:xe(m(w.document))!==xe(m(s))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:y}}function Lf({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:i}=Ze(),[s,o]=S.useState(!1),a=S.useMemo(()=>s?{text:e}:void 0,[s,e]),{draft:c,patch:u,close:l,discard:d}=Lc(a,s,v=>n(v.text),()=>o(!1)),f=s&&c!==void 0&&c.text!==e,h=c!==void 0&&c.text!==e?Mi(c.text):void 0;sf(f,()=>h!==void 0?!1:(l(),!0));const g=S.useRef(null),m=S.useRef(!1);S.useEffect(()=>{s||(m.current=!1)},[s]);const y=S.useCallback(v=>{!v||m.current||(m.current=!0,v.setSelectionRange(v.value.length,v.value.length))},[]);if(!s||c===void 0){const v=e.trim()?Mi(e):void 0;return b.jsxs(De,{role:"button",tabIndex:0,onClick:x=>{x.target.closest("a")?x.preventDefault():o(!0)},onKeyDown:x=>{x.target===x.currentTarget&&(x.key!=="Enter"&&x.key!==" "||(x.preventDefault(),o(!0)))},sx:[{minHeight:24},nf(i,"prose")],children:[e.trim()?b.jsx(Mh,{variant:r,children:e}):b.jsx(ue,{variant:"body2",sx:{color:i.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),v&&b.jsx(ue,{variant:"caption",color:"error",role:"alert",children:v})]})}const w=c.text!==e?Mi(c.text):void 0,p=()=>{w===void 0&&l()};return b.jsxs(ye,{spacing:1,children:[b.jsx(Je,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:c.text,placeholder:t,error:w!==void 0,helperText:w,inputRef:y,inputProps:{"aria-label":"Markdown"},onChange:v=>u(x=>{x.text=v.target.value}),onKeyDown:v=>{v.key==="Escape"?p():v.key==="Enter"&&(v.metaKey||v.ctrlKey)&&(v.preventDefault(),p())},onBlur:v=>{v.relatedTarget instanceof Node&&g.current?.contains(v.relatedTarget)||l()}}),b.jsxs(ye,{ref:g,direction:"row",spacing:1,children:[b.jsx(Oe,{size:"small",variant:"outlined",disabled:w!==void 0,onClick:p,children:"Done"}),b.jsx(Oe,{size:"small",onMouseDown:v=>v.preventDefault(),onClick:()=>{d(),o(!1)},children:"Cancel"})]})]})}const Xb="Write markdown: # heading, **bold**, - list";function Kb({tile:e,onChange:t,chrome:n="card"}){return b.jsx(ts,{chrome:n,kind:"text",children:b.jsx(Lf,{markdown:e.markdown,placeholder:Xb,onCommit:t})})}const es=e=>e.label??Ph(`${e.source} -> ${e.name}`);function Zb({tile:e,index:t,selected:n,flash:r=!1,menuOpen:i,bare:s=!1,onInsertAfter:o,onSelect:a,onOpenMenu:c,resizing:u=!1,width:l,onResizeStart:d,onResizeMove:f,onResizeEnd:h,children:g}){const{theme:m}=Ze();return b.jsx(Uv,{id:ze(e),index:t,children:({ref:y,handleRef:w})=>b.jsxs(De,{ref:y,onClick:a,onPointerDown:p=>{p.button===0&&a()},role:"group","aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":ze(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Nf(m,{selected:n,flash:r,bare:s}),"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:m.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${m.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[g,b.jsx(De,{ref:w,"aria-label":`Move ${ei(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),b.jsx(Ti,{className:"builder-affordance",size:"small","aria-label":`Settings for ${ei(e)}`,onClick:p=>{p.stopPropagation(),c(p.currentTarget)},sx:{position:"absolute",top:`${-((s?Tc+1:0)+12)}px`,right:s?0:"12px",border:m.cardBorder,borderRadius:1,width:28,height:24,zIndex:2,color:m.tileTitle,bgcolor:m.tile,opacity:n||i?.9:0,transition:`opacity ${dt}`,...Lt,"&:hover":{opacity:1,bgcolor:m.tile}},children:b.jsx(ty,{})}),d&&b.jsx(De,{className:"builder-affordance",[yf]:"",role:"separator",tabIndex:l?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${ei(e)}`,...l?{"aria-valuenow":l.span,"aria-valuemin":1,"aria-valuemax":l.columns,"aria-valuetext":`${l.span} of ${l.columns} columns`}:{},onKeyDown:p=>{if(!l)return;const v=p.key==="ArrowRight"?l.span+1:p.key==="ArrowLeft"?l.span-1:p.key==="Home"?1:p.key==="End"?l.columns:void 0;v!==void 0&&(p.preventDefault(),p.stopPropagation(),l.onStep(Math.min(Math.max(v,1),l.columns)))},onPointerDown:d,onPointerMove:f,onPointerUp:h,onPointerCancel:h,onClick:p=>p.stopPropagation(),sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:u||n?1:0,transition:`opacity ${dt}`,...Lt,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${m.accent}`,outlineOffset:1,borderRadius:"3px"},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"28px",borderRadius:"2px",bgcolor:m.accent}}}),o&&b.jsx(Ti,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${ei(e)}`,onClick:p=>{p.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${(s?wc:En)/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:m.tileTitle,bgcolor:m.tile,border:m.cardBorder,opacity:0,transition:`opacity ${dt}`,...Lt,"&:hover, &:focus-visible":{opacity:1,bgcolor:m.tile}},children:b.jsx(Nr,{sx:{fontSize:14}})})]})})}const Fs=4,Nf=(e,{selected:t,flash:n=!1,bare:r=!1})=>{const i=t||n?e.accent:"transparent",s=t?e.accent:e.cardBorder.replace(/^1px solid /,""),o=`outline-color ${dt}, border-color ${dt}, opacity ${dt}, box-shadow ${dt}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-Tc}px`,borderRadius:1,border:`2px solid ${i}`,pointerEvents:"none",transition:o,...Lt},"&:hover::before":{borderColor:s}}:{borderRadius:1,outline:`2px solid ${i}`,outlineOffset:2,...n&&{boxShadow:`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`},transition:o,...Lt,"&:hover":{outlineColor:s,boxShadow:e.shadow.lift}}};function Qb({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:i}=Ze();return b.jsxs(ts,{chrome:r,children:[b.jsx(Cc,{title:t?.title??es(e),subtitle:t?t.subtitle:e.subtitle}),n&&b.jsx(ue,{variant:"body2",sx:{color:i.tileTitle,py:2},children:n}),b.jsxs(ue,{variant:"caption",sx:{display:"block",color:i.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function Jb({after:e}){const{theme:t}=Ze();return b.jsx(Xv,{id:af(e),after:e,children:({ref:n,isDropTarget:r})=>b.jsx(De,{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 ${dt}, background-color ${dt}`,...Lt}})})}function ey({columns:e}){const{theme:t}=Ze();return b.jsx(De,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${En}px`},children:Array.from({length:e},(n,r)=>b.jsx(De,{sx:{borderLeft:`1px dashed ${t.accent}`,borderRight:r===e-1?`1px dashed ${t.accent}`:"none",opacity:.35}},r))})}function ty(){return b.jsxs(Fh,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[b.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),b.jsx("circle",{cx:"12",cy:"12",r:"2"}),b.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function ny({editor:e,reorder:t,resizing:n,gridBox:r,columns:i,notebook:s,chrome:o,canAdd:a,selected:c,flash:u,menuIndex:l,onSelect:d,onOpenMenu:f,openAdd:h,editTile:g,renderTile:m}){const{dragging:y,preview:w,onDragStart:p,onDragOver:v,onDragEnd:x}=t,{resize:k,startResize:C,onResize:O,endResize:T}=n,$=k!==void 0?e.document.tiles.map((L,B)=>B===k.index?{...L,colspan:k.span}:L):w??e.document.tiles,D=e.document.tiles.length===0,z=y?mv($,i):$.map(of),N=L=>ry(L,es(L),g);return b.jsxs(b.Fragment,{children:[b.jsx(Kg,{sensors:Vv,onDragStart:p,onDragOver:v,onDragEnd:x,children:b.jsxs(De,{ref:r,sx:{position:"relative"},children:[!s&&(y||k!==void 0)&&b.jsx(ey,{columns:i}),b.jsx(ch,{tiles:z,columns:i,rowGapPx:o==="none"?wc:En,keyOf:L=>L.kind==="gap"?af(L.after):ze(L.tile),renderTile:L=>{if(L.kind==="gap")return b.jsx(Jb,{after:L.after});const{tile:B,index:H}=L;return b.jsx(Zb,{tile:B,index:H,selected:H===c,flash:ze(B)===u,menuOpen:l===H,bare:o==="none",...s&&a?{onInsertAfter:()=>h(H+1)}:{},...i>1&&iy(B)?{resizing:k?.index===H,width:{span:B.colspan??1,columns:i,onStep:Y=>{Y!==(B.colspan??1)&&e.update(Z=>{const ne=Z.tiles[H];ne&&(ne.colspan=Y)})}},onResizeStart:Y=>C(Y,H),onResizeMove:O,onResizeEnd:T}:{},onSelect:()=>d(H),onOpenMenu:Y=>f(Y,H),children:Re(B)?b.jsx(Kb,{tile:B,chrome:o,onChange:Y=>g(ze(B),Z=>{Re(Z)&&(Z.markdown=Y)})}):m&&!e.pendingOpen?m(B,N(B),o):b.jsx(Qb,{tile:B,chrome:o,heading:N(B),...e.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),s&&a&&!D&&b.jsx(Oe,{size:"small",startIcon:b.jsx(Nr,{}),"aria-label":"Add tile at the end",onClick:()=>h(),sx:{alignSelf:"center"},children:"Add tile"})]})}const ry=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=ze(e),i=s=>o=>n(r,a=>{ve(a)&&(o===""?delete a[s]:a[s]=o)});return{title:b.jsx(Io,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:i("label")}),subtitle:b.jsx(Io,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:i("subtitle")})}},iy=e=>Re(e)||e.declaration.kind!=="inherited";function sy({editor:e,documentSlug:t,chrome:n,actions:r,descriptionSelected:i,selectDescription:s}){const{theme:o}=Ze();return b.jsxs(b.Fragment,{children:[b.jsxs(ye,{direction:"row",sx:{alignItems:"center",gap:2},children:[b.jsx(ue,{variant:"h5",sx:{flex:1,minWidth:0},children:b.jsx(Io,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:a=>e.update(c=>{c.title=a})})}),b.jsx(De,{sx:{my:"-4px"},children:r})]}),b.jsx(De,{role:"group","aria-label":"Description","aria-current":i,onPointerDown:s,onFocus:s,sx:n==="none"?{my:`${ah}px`}:void 0,children:b.jsx(ts,{chrome:n,kind:"text",sx:{position:"relative",overflow:"visible",...Nf(o,{selected:i,bare:n==="none"})},children:b.jsx(Lf,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:a=>e.update(c=>{a.trim()===""?delete c.description:c.description=a})})})})]})}const oy=({size:e,path:t,layout:n,savesTo:r,onEvent:i})=>{const{emit:s}=_o({path:t,layout:n},i);return{size:e,saved:({size:o,structural:a,durationMs:c,fromOpen:u})=>s({type:"report.saved",tiles:o,structural:a,...u?{converted:!0}:{},where:r,durationMs:c}),refused:o=>s({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:c})=>s({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:c}),undoRefused:o=>s({type:"report.save_undo_refused",reason:o})}},ay=Wr(b.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"})),ly=Wr(b.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"})),Fo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),_s=Fo?"⌘":"Ctrl+",oc=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Bs=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function cy(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e});const[n,r]=S.useState(!1);S.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),S.useEffect(()=>{const i=s=>{const o=t.current;if(o.paused)return;const a=Fo?s.metaKey:s.ctrlKey,c=s.key.toLowerCase();if(s.key==="Escape"){if(oc(s.target)||Bs(s.target))return;o.escape();return}if(oc(s.target)){if(a&&c==="s"){if(s.preventDefault(),!o.save||Bs(s.target))return;s.target.blur(),r(!0)}return}if(Bs(s.target)){a&&c==="s"&&s.preventDefault();return}if(a&&c==="z"){s.preventDefault(),s.shiftKey?o.redo():o.undo();return}if(!Fo&&a&&c==="y"){s.preventDefault(),o.redo();return}if(a&&c==="s"){s.preventDefault(),o.save?.();return}o.nudge&&!a&&!s.altKey&&!s.shiftKey&&(s.key==="ArrowLeft"||s.key==="ArrowRight")&&(s.preventDefault(),o.nudge(s.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[])}const ac={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function dy({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:i,saving:s,onSave:o,savesTo:a="package",saveLabel:c,saveButton:u,actions:l,onAddTile:d,onExit:f,layout:h,onLayoutChange:g}){return b.jsxs(ye,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[h&&g&&b.jsxs(b.Fragment,{children:[b.jsx(Tt,{title:"Layout: tiles side by side, or one after another",children:b.jsxs(Xo,{size:"small",exclusive:!0,value:h,"aria-label":"Layout",onChange:(m,y)=>{y&&y!==h&&g(y)},sx:{"& .MuiToggleButton-root":{py:.25,px:1}},children:[b.jsx(Dn,{value:"linear","aria-label":"Linear layout",children:"Linear"}),b.jsx(Dn,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),b.jsx(ks,{orientation:"vertical",flexItem:!0,sx:{mx:.5}})]}),d&&b.jsx(Oe,{startIcon:b.jsx(Nr,{}),onClick:d,"aria-label":"Add tile",children:"Tile"}),d&&b.jsx(ks,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),b.jsx(Tt,{title:`Undo (${_s}Z)`,children:b.jsx("span",{children:b.jsx(Ti,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:b.jsx(ly,{fontSize:"small"})})})}),b.jsx(Tt,{title:`Redo (${_s}⇧Z)`,children:b.jsx("span",{children:b.jsx(Ti,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:b.jsx(ay,{fontSize:"small"})})})}),(l||o||f)&&b.jsx(ks,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),l,o?b.jsx(Tt,{title:i?`Save (${_s}S) · ${c??ac[a]}`:c??ac[a],children:b.jsx("span",{children:b.jsx(Oe,{ref:u,variant:i?"contained":"outlined",disabled:!i||s,onClick:o,sx:{minWidth:124},children:s?"Saving…":i?"Save":"Saved"})})}):null,o&&b.jsx(De,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:s?"Saving":i?"Unsaved changes":"All changes saved"}),f&&b.jsx(sh,{label:"Close",icon:b.jsx(oh,{}),onClick:f})]})}const uy=Wr(b.jsx("path",{d:"M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12z"})),fy=Wr(b.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function hy({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:i,addDisabledReason:s,onRemove:o,children:a}){const{theme:c}=Ze();return b.jsx(b.Fragment,{children:b.jsxs(ye,{sx:{gap:1,position:"sticky",top:0,zIndex:lh,bgcolor:"background.default",pb:1},children:[b.jsx(ye,{direction:"row",sx:{gap:2,alignItems:"center",minHeight:32},children:b.jsxs(ye,{direction:"row",role:"group","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",flex:1,minWidth:0},children:[b.jsx(fy,{sx:{fontSize:18,color:c.tileTitle,opacity:.7}}),b.jsx(ue,{variant:"subtitle2",sx:{color:c.tileTitle,mr:.5},children:"Filters"}),e.length===0&&b.jsx(ue,{variant:"body2",sx:{color:c.tileTitle,opacity:.8},children:"None yet."}),e.map(u=>{const l=n(u.name,u.type);return b.jsx(Tt,{title:l.length>0?`$${u.name} · cannot filter on: ${l.join(", ")}`:`$${u.name} · ${u.origin==="dashboard"?"declared here":"from the model"} · ${u.boundTiles} of ${t} tiles`,children:b.jsx(Ys,{size:"small",label:`${u.label??u.name}${u.boundTiles===0?" · unused":""}`,"aria-label":`Edit filter ${u.name}`,color:l.length>0?"warning":"default",variant:u.origin==="dashboard"?"filled":"outlined",onClick:()=>r(u),onDelete:()=>o(u.name),deleteIcon:b.jsx(uy,{"aria-label":`Remove filter ${u.name}`}),sx:{opacity:u.boundTiles===0?.6:1,cursor:"pointer",transition:`opacity ${dt}`,...Lt}})},u.name)}),b.jsx(Tt,{title:s??"",children:b.jsx("span",{children:b.jsx(Ys,{component:"button",size:"small",variant:"outlined",icon:b.jsx(Nr,{}),label:"Filter","aria-label":"Add filter","aria-haspopup":"dialog",disabled:s!==void 0,onClick:()=>i(),sx:{cursor:"pointer",color:c.tileTitle,borderStyle:"dashed","& .MuiChip-icon":{color:"inherit",fontSize:16}}})})})]})}),a]})})}function py(e,t){const n=new Map(e.tiles.map((r,i)=>[ze(r),{tile:r,index:i}]));for(const[r,i]of t.tiles.entries()){const s=n.get(ze(i));if(!s||s.index!==r||JSON.stringify(s.tile)!==JSON.stringify(i))return ze(i)}}function my({editor:e,gridBox:t}){const[n,r]=S.useState(void 0),i=typeof n=="object"?n.tile:void 0,s=n==="description",o=S.useCallback(m=>r(y=>typeof y=="object"&&y.tile===m?y:{tile:m}),[]),a=S.useCallback(()=>r(m=>m==="description"?m:void 0),[]),c=S.useCallback(()=>r("description"),[]),u=S.useCallback(()=>r(void 0),[]),[l,d]=S.useState(void 0),f=S.useRef(!1),h=S.useRef(e.document);S.useEffect(()=>{const m=h.current;if(h.current=e.document,!f.current)return;f.current=!1;const y=py(m,e.document);y!==void 0&&(d(y),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(w=>w.dataset.tileKey===y)?.scrollIntoView?.({block:"nearest",behavior:ih()}))},[e.document,t]),S.useEffect(()=>{if(l===void 0)return;const m=setTimeout(()=>d(void 0),1500);return()=>clearTimeout(m)},[l]);const g=S.useMemo(()=>({...e,undo:()=>{f.current=!0,e.undo()},redo:()=>{f.current=!0,e.redo()}}),[e]);return{selected:i,descriptionSelected:s,selectTile:o,deselectTile:a,selectDescription:c,clearSelection:u,flash:l,stepEditor:g}}function gy({dirty:e,saving:t,canSave:n,save:r,onExit:i}){const[s,o]=S.useState("idle"),[a,c]=S.useState(!1),u=S.useRef(r);u.current=r;const l=S.useRef(i);l.current=i;const d=S.useRef(0),f=S.useCallback(async()=>{const h=++d.current;c(!1),o("saving");try{await u.current()}catch{d.current===h&&o("idle");return}d.current===h&&c(!0)},[]);return S.useEffect(()=>{if(s==="waiting"){if(t)return;e?f():(o("idle"),l.current())}else if(s==="saving"){if(!a||t)return;o("idle"),e||l.current()}},[s,a,t,e,f]),{requestExit:S.useCallback(()=>{s==="idle"&&(e?o("asking"):l.current())},[s,e]),dialog:{open:s==="asking",canSave:n,onKeepEditing:()=>{s==="asking"&&o("idle")},onDiscard:()=>{s==="asking"&&(o("idle"),l.current())},onSaveAndExit:()=>{s==="asking"&&(t?o("waiting"):f())}}}}function vy({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:i,extraDirty:s=!1,report:o,unit:a,prepare:c,shortcuts:u}){const[l,d]=S.useState(!1),[f,h]=S.useState(!1),g=S.useRef(null),m=S.useRef(o);m.current=o;const y=e.dirty||s,w=(e.edited??e.dirty)||s;S.useEffect(()=>{i?.(e.document)},[e.document,i]),S.useLayoutEffect(()=>{n?.(w)},[w,n]);const p=S.useRef(n);p.current=n,S.useEffect(()=>()=>p.current?.(!1),[]);const v=S.useRef(a);v.current=a,S.useEffect(()=>{h(!1)},[e.document]);const x=S.useCallback(()=>{d(!0),h(!1);const H=At(),{structural:Y}=e,Z=e.pendingOpen??!1,ne=m.current.size;return e.save().then(J=>{J.ok===!0?m.current.saved({size:ne,structural:Y,fromOpen:Z,durationMs:At()-H}):m.current.refused(J.reason)}).finally(()=>d(!1))},[e]),k=S.useRef(!1),C=S.useRef(!1);S.useEffect(()=>{!C.current||l||(C.current=!1,g.current?.focus())},[f,l]);const O=S.useCallback(()=>{if(!t||l||k.current||!e.canUndoSave)return;k.current=!0,d(!0);const H=At(),Y=e.lastSave?.structural??!1,Z=m.current.size;return e.undoSave().then(ne=>{ne.ok===!0?(C.current=!0,h(!0),m.current.undone({size:Z,structural:Y,fromOpen:!1,durationMs:At()-H})):m.current.undoRefused(ne.reason)}).finally(()=>{k.current=!1,d(!1)})},[t,l,e]),T=S.useCallback(()=>{if(!(!t||!e.dirty||l))return x()},[t,e,l,x]),$=S.useRef(T);$.current=T;const D=S.useCallback(()=>{const H=()=>$.current();return c?c(H):H()},[c]),z=gy({dirty:w,saving:l,canSave:!!t,save:D,onExit:()=>r?.()});cy(S.useMemo(()=>({...u,undo:e.undo,redo:e.redo,...t?{save:D}:{},paused:z.dialog.open}),[u,e,t,D,z.dialog.open]));const N=!!t&&!l&&e.canUndoSave,L=e.lastSave,B={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:y,saving:l,saveButton:g,...t?{onSave:D}:{},...r?{onExit:z.requestExit}:{}};return{saving:l,save:D,exitGuard:z,undoSave:O,canUndoSave:N,lastSave:L,toolbarProps:B}}function fi(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function lc(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&xf.includes(n))return n}}const by=1;function Wf(e,t,n){const r=[];for(const i of e??[]){const s=i.name,o=i.kind;if(typeof s=="string"){if(o==="dimension"||o==="measure"){const a=i.type?.kind;r.push({name:t+s,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=i.schema?.fields;r.push(...Wf(a,`${t}${s}.`,n-1))}}}return r}function yy(e){const t=new Map;for(const n of zf(e))t.set(n.name,Wf(n.schema?.fields,"",by));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}const xy=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&Lh.parseTag(n.slice(9)).tag?.has("calculation")===!0});function wy(e){const t=new Map;for(const n of zf(e)){const r=new Set;for(const i of n.schema?.fields??[]){if(i.kind!=="view"||typeof i.name!="string")continue;const s=i.schema?.fields;s&&s.length>0&&s.every(xy)&&r.add(i.name)}t.set(n.name,r)}return t}function cc(e,t){return!e||t===void 0?void 0:e.sources.find(n=>n.name===t)?.fields.filter(n=>n.kind==="dimension")}const dc=(e,t)=>e!==void 0&&t.has(e),uc=e=>e.modelPath??e.path??"";function ky(e,t=new Set){const n=[],r=new Set,i=new Map,s=new Map,o=new Map;for(const a of e){const c=uc(a);if(dc(c,t))continue;const u=rh(a.modelInfo);s.set(a,u);for(const{name:l}of a.sources??[])l&&o.set(l,[...o.get(l)??[],c]);for(const l of u)i.set(l,[...i.get(l)??[],c])}for(const a of e){const c=uc(a);if(dc(c,t))continue;const u=yy(a),l=wy(a);for(const d of a.sources??[]){const f=d.name;if(!f||!s.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(d.givens??[]).map(g=>g.name).filter(g=>typeof g=="string");n.push({name:f,modelPath:c,exporters:i.get(f)??[c],visibleIn:o.get(f)??[c],...fi(d.annotations)?{description:fi(d.annotations)}:{},views:(d.views??[]).filter(g=>typeof g.name=="string").map(g=>({name:g.name,...fi(g.annotations)?{description:fi(g.annotations)}:{},...lc(g.annotations)?{chart:lc(g.annotations)}:{},...l.get(f)?.has(g.name)?{aggregateOnly:!0}:{}})),givens:h,fields:u.get(f)??[]})}}return{sources:n}}function Sy({editor:e,opened:t,givens:n,catalog:r}){const[i,s]=S.useState(void 0),o=S.useMemo(()=>{const f=new Set((t.localGivens??[]).map(h=>h.name));return(n??[]).filter(h=>!f.has(h.name))},[t,n]),a=S.useMemo(()=>Qh(e.document,o),[e.document,o]),c=S.useMemo(()=>new Map(e.document.sources.map(f=>[f.name,cc(r,f.base)])),[r,e.document.sources]),u=S.useCallback(f=>c.get(f.source)??cc(r,f.source),[c,r]),l=(f,h)=>{const g=[];for(const m of e.document.tiles){if(!ve(m))continue;const y=u(m);if(!y)continue;const w=new Map(y.map(p=>[p.name,p.type]));for(const p of m.filters??[])p.given===f&&(!w.has(p.field)||!gi(h,w.get(p.field)))&&g.push(`${p.field} on ${m.label??m.name} (${e.document.sources.find(v=>v.name===m.source)?.base??m.source})`)}return g},d=S.useMemo(()=>a.filter(f=>f.origin==="model"&&f.boundTiles===0),[a]);return{filterDialog:i,setFilterDialog:s,controlList:a,fieldsFor:u,unknownFieldsOf:l,available:d,applyFilter:(f,h,g)=>{s(void 0),e.update(m=>{g&&sp(m,g),ip(m,f,h)})},dropControl:f=>{s(void 0),e.update(h=>op(h,f))}}}function $y({pendingOpen:e,prepare:t}){const[n,r]=S.useState(void 0),i=S.useRef(e);i.current=e;const s=S.useCallback(o=>i.current?new Promise(a=>r({go:()=>{r(void 0),a(t(o))},stop:()=>{r(void 0),a()}})):t(o),[t]);return{confirmConversion:n,prepareSave:s}}function Cy(e){const{splice:t,onSave:n,structural:r,clearsHistory:i,opensDirty:s=!1}=e,[o,a]=S.useState({stack:[e.document],index:0}),[c,u]=S.useState(e.source),[l,d]=S.useState(void 0),[f,h]=S.useState(e.document),[g,m]=S.useState(s),[y,w]=S.useState(e.replaces),[p,v]=S.useState(!1),x=o.stack[o.index],k=S.useRef(o);k.current=o;const C=S.useRef(!1),[O,T]=S.useState(!1),$=R=>{C.current=R,T(R)},[D,z]=S.useState(void 0),N=S.useCallback(R=>{d(void 0),a(_=>{const X=structuredClone(_.stack[_.index]);if(R(X),JSON.stringify(X)===JSON.stringify(_.stack[_.index]))return _;const Q=[..._.stack.slice(0,_.index+1),X].slice(-100);return{stack:Q,index:Q.length-1}})},[]),L=S.useCallback(()=>{d(void 0),a(R=>R.index>0?{...R,index:R.index-1}:R)},[]),B=S.useCallback(()=>{d(void 0),a(R=>R.index<R.stack.length-1?{...R,index:R.index+1}:R)},[]),H=S.useCallback(async(R,_)=>{try{return await t(R,_)}catch(X){return{ok:!1,reason:`Could not build the file: ${X instanceof Error?X.message:String(X)}`}}},[t]),Y=S.useCallback(async()=>{if(C.current)return{ok:!1,reason:"A save is still being written."};const R={source:c,saved:f,history:k.current,pendingOpen:g,replacing:y,unwritten:p},_=i?.(f,x)??!1,X=r?.(f,x)??!1;$(!0);try{const Q=await H(c,x);if(Wo(Q))return d(Q.reason),{ok:!1,reason:Q.reason};try{await n?.(Q.source,{purpose:"save",document:x})}catch(j){const A=`Could not save: ${j instanceof Error?j.message:String(j)}`;return d(A),{ok:!1,reason:A}}u(Q.source),h(x),m(!1),w(void 0),v(!1);const E=_?{stack:[x],index:0}:R.history;return a(j=>j===R.history?E:_?{stack:[j.stack[j.index]],index:0}:j),z(n?{before:R,after:E,lastSave:{before:y??c,after:Q.source,structural:X,clearsHistory:_}}:void 0),d(void 0),{ok:!0}}finally{$(!1)}},[x,H,n,c,f,g,y,p,i,r]),Z=S.useCallback(async()=>{if(C.current)return{ok:!1,reason:"A save is still being written."};if(!n||D===void 0||D.after!==k.current)return{ok:!1,reason:"There is no save to undo."};const{before:R}=D;$(!0);try{await n(R.replacing??R.source,{purpose:"undo",document:R.saved})}catch(_){const X=`Could not undo the save: ${_ instanceof Error?_.message:String(_)}`;return d(X),{ok:!1,reason:X}}finally{$(!1)}return u(R.source),h(R.saved),m(R.pendingOpen),w(R.replacing),v(R.unwritten||R.replacing!==void 0),a(_=>_===D.after?R.history:_),z(void 0),d(void 0),{ok:!0}},[n,D]),ne=S.useMemo(()=>p||JSON.stringify(x)!==JSON.stringify(f),[x,f,p]),J=S.useMemo(()=>r?.(f,x)??!1,[x,f,r]),M=S.useMemo(()=>i?.(f,x)??!1,[x,f,i]),F=D!==void 0&&D.after===o,W=S.useCallback(async()=>{const R=await H(c,x);return Wo(R)?{ok:!1,reason:R.reason}:{ok:!0,source:R.source}},[x,H,c]);return{document:x,saved:f,source:c,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:ne||g,edited:ne,pendingOpen:g,...l===void 0?{}:{error:l},update:N,undo:L,redo:B,save:Y,preview:W,structural:J,clearsHistory:M,canUndoSave:F&&!O&&n!==void 0,...F?{lastSave:D.lastSave}:{},undoSave:Z}}const jy=(e,t)=>{const n=new Set(e.tiles.map(zo)),r=new Set(t.tiles.map(zo));return[...n].some(i=>!r.has(i))||[...r].some(i=>!n.has(i))};function Ey(e){const{conversion:t,visibleSources:n,...r}=e,i=t?.from,s=t?.to,o=S.useCallback((a,c)=>Ub(i!==void 0&&a===i?s:a,c,n?{visibleSources:n}:{}),[i,s,n]);return Cy({...r,splice:o,structural:jy,opensDirty:t!==void 0})}function Oy({editorDirty:e}){const[t,n]=S.useState(!1),r=S.useRef(void 0),i=S.useRef(void 0),s=S.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=S.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(c=>{i.current=()=>c(a())})},[]);return S.useEffect(()=>{if(t||!i.current)return;const a=i.current;i.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:s,prepare:o}}function My(e,t,{modelPath:n,textHeld:r,notebook:i,insertAt:s}){t.modelPath&&!r&&(e.imports=Eh(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));let o=e.sources.find(u=>u.base===t.base);if(!o){const u=new Set(e.sources.map(d=>d.name));let l=`${t.base}_tiles`;for(let d=2;u.has(l);d++)l=`${t.base}_tiles_${d}`;o={name:l,base:t.base},e.sources.push(o)}const a=new Set(e.tiles.filter(ve).filter(u=>u.source===o.name).map(u=>u.name));let c=`${t.view}_tile`;for(let u=2;a.has(c);u++)c=`${t.view}_tile_${u}`;e.tiles.splice(s??e.tiles.length,0,{name:c,source:o.name,declaration:{kind:"reference",from:t.view},...i?{}:{colspan:t.colspan},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Ay({editor:e,notebook:t,columns:n,modelPath:r,textHeld:i,selectTile:s,deselectTile:o}){const[a,c]=S.useState(void 0),[u,l]=S.useState(!1),[d,f]=S.useState(void 0);return{menu:a,setMenu:c,addingTile:u,openAdd:h=>{f(h),l(!0)},closeAdd:()=>l(!1),addTile:h=>{l(!1),e.update(g=>My(g,h,{modelPath:r,textHeld:i,notebook:t,insertAt:d})),s(d??e.document.tiles.length)},addText:()=>{l(!1),e.update(h=>{const g=new Set(h.tiles.filter(Re).map(y=>y.name));let m=1;for(;g.has(`text_${m}`);)m++;h.tiles.splice(d??h.tiles.length,0,{kind:"text",name:`text_${m}`,markdown:"",...t?{}:{colspan:n}})}),s(d??e.document.tiles.length)},editTile:(h,g)=>e.update(m=>{const y=m.tiles.find(w=>ze(w)===h);y&&g(y)}),removeTile:h=>{c(void 0),o(),e.update(g=>{g.tiles.splice(h,1)})}}}var Ty=Object.defineProperty,Dy=Object.defineProperties,Iy=Object.getOwnPropertyDescriptors,fc=Object.getOwnPropertySymbols,Py=Object.prototype.hasOwnProperty,Ry=Object.prototype.propertyIsEnumerable,hc=(e,t,n)=>t in e?Ty(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gn=(e,t)=>{for(var n in t||(t={}))Py.call(t,n)&&hc(e,n,t[n]);if(fc)for(var n of fc(t))Ry.call(t,n)&&hc(e,n,t[n]);return e},vn=(e,t)=>Dy(e,Iy(t));function Ly(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function hi(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function qs(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Ny(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(p,v)=>p===v||p!==null&&typeof p=="object"&&"id"in p&&p.id===v;if(Array.isArray(e)){const p=e.findIndex(x=>c(x,s.id)),v=e.findIndex(x=>c(x,o.id));if(p===-1||v===-1){if(qs(s)){const x=s.initialIndex,k=s.index;return x===k||x<0||x>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,x,k)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const x=s.index;if(x!==p)return n(e,p,x)}return n(e,p,v)}const u=Object.entries(e);let l=-1,d,f=-1,h;for(const[p,v]of u)if(l===-1&&(l=v.findIndex(x=>c(x,s.id)),l!==-1&&(d=p)),f===-1&&(f=v.findIndex(x=>c(x,o.id)),f!==-1&&(h=p)),l!==-1&&f!==-1)break;if(l===-1&&qs(s)){const p=s.initialGroup==null?void 0:hi(e,s.initialGroup),v=s.initialIndex,x=s.group==null?void 0:hi(e,s.group),k=s.index;if(p==null||x==null||p===x&&v===k)return"preventDefault"in t&&t.preventDefault(),e;if(p===x)return vn(gn({},e),{[p]:n(e[p],v,k)});const C=e[p][v];return vn(gn({},e),{[p]:[...e[p].slice(0,v),...e[p].slice(v+1)],[x]:[...e[x].slice(0,k),C,...e[x].slice(k)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,m=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(h==null){const p=hi(e,o.id);if(p!=null){const v=o.shape&&m.y>o.shape.center.y?e[p].length:0;h=p,f=v}}if(d==null||h==null||d===h&&l===f){if(d!=null&&d===h&&l===f&&qs(s)){const p=s.group==null?void 0:hi(e,s.group),v=s.group!=null&&p!==d,x=s.index!==l;if(v||x){const k=s.group==null?d:p;if(k!=null){if(d===k)return vn(gn({},e),{[d]:n(e[d],l,s.index)});const C=e[d][l];return vn(gn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[k]:[...e[k].slice(0,s.index),C,...e[k].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return vn(gn({},e),{[d]:n(e[d],l,f)});const y=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,w=e[d][l];return vn(gn({},e),{[d]:[...e[d].slice(0,l),...e[d].slice(l+1)],[h]:[...e[h].slice(0,f+y),w,...e[h].slice(f+y)]})}function Wy(e,t){return Ny(e,t,Ly)}function zy({tiles:e,commit:t,onLanded:n}){const[r,i]=S.useState(void 0),s=S.useRef(void 0),[o,a]=S.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),s.current=e},onDragOver:c=>{const{source:u,target:l}=c.operation;if(!u||!l)return;const d=s.current??e;let f;if(l.type===bf){const{after:h}=l.data,g=d.findIndex(y=>ze(y)===u.id);if(g<0||h===u.id)return;const m=d.filter((y,w)=>w!==g).findIndex(y=>ze(y)===h)+1;f=pv(d,g,m)}else{const h=d.map(ze),g=Wy(h,c);if(g.every((y,w)=>y===h[w]))return;const m=new Map(d.map(y=>[ze(y),y]));f=hv(g.map(y=>m.get(y)),e.map(y=>y.break??!1))}s.current=f,i(f)},onDragEnd:c=>{a(!1);const u=s.current;if(s.current=void 0,i(void 0),c.canceled||!u)return;t(u);const l=u.findIndex(d=>ze(d)===c.operation.source?.id);l>=0&&n(l)}}}const Hs=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Fy({tiles:e,columns:t,gridBox:n,onStart:r,commit:i}){const[s,o]=S.useState(void 0),a=S.useRef(void 0),c=u=>{a.current=u,o(u)};return S.useEffect(()=>()=>Hs(!1),[]),{resize:s,startResize:(u,l)=>{const d=n.current?.getBoundingClientRect(),f=u.currentTarget.parentElement?.getBoundingClientRect();if(!d||!f)return;u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Hs(!0),r(l);const h=e[l]?.colspan??1;c({index:l,span:h,from:h,left:f.left,track:(d.width-En*(t-1))/t})},onResize:u=>{const l=a.current;if(!l)return;const d=u.clientX-l.left,f=Math.round((d+En)/(l.track+En)),h=Math.min(Math.max(f,1),t);h!==l.span&&c({...l,span:h})},endResize:u=>{u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Hs(!1);const l=a.current;if(!l)return;const{index:d,span:f,from:h}=l;c(void 0),!(u.type==="pointercancel"||f===h)&&i(d,f)}}}function Ff({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,onExit:s,allowLayoutChange:o=!0,renderTile:a,controls:c,givens:u,catalog:l,toolbar:d,dashboards:f,onEvent:h,conversion:g,savesTo:m="package",saveLabel:y,replaces:w,modelPath:p,visibleSources:v,addFilterDisabledReason:x}){const k=Ey({source:e,document:t,...n?{onSave:n}:{},...g?{conversion:g}:{},...w!==void 0?{replaces:w}:{},...v?{visibleSources:v}:{}}),C=S.useRef(null),{selected:O,descriptionSelected:T,selectTile:$,deselectTile:D,selectDescription:z,clearSelection:N,flash:L,stepEditor:B}=my({editor:k,gridBox:C}),H=k.document.layout==="linear",Y=H?1:k.document.columns??Yf,Z=H?"none":"card",ne=p?.split("/").at(-1)?.replace(/\.malloy$/,""),J=zy({tiles:k.document.tiles,commit:U=>k.update(P=>{P.tiles=U}),onLanded:$}),{dragging:M}=J,F=Fy({tiles:k.document.tiles,columns:Y,gridBox:C,onStart:$,commit:(U,P)=>k.update(q=>{const oe=q.tiles[U];oe&&(oe.colspan=P)})}),W=Ay({editor:k,notebook:H,columns:Y,modelPath:p,textHeld:v!==void 0,selectTile:$,deselectTile:D}),{menu:R,addingTile:_,openAdd:X}=W,Q=Sy({editor:k,opened:t,givens:u,catalog:l}),{filterDialog:E,setFilterDialog:j}=Q,[A,K]=S.useState(void 0),{draftDirty:V,openDraft:te,prepare:G}=Oy({editorDirty:k.dirty}),{confirmConversion:ae,prepareSave:ee}=$y({pendingOpen:k.pendingOpen,prepare:G}),I=S.useMemo(()=>({escape:()=>{!R&&!E&&!_&&A===void 0&&ae===void 0&&N()},nudge:U=>{if(M||O===void 0||H)return;const P=k.document.tiles[O];if(!P||ve(P)&&P.declaration.kind==="inherited")return;const q=Uf(P.colspan??1,U,Y);q!==(P.colspan??1)&&k.update(oe=>{oe.tiles[O].colspan=q})}}),[k,R,E,_,A,ae,N,O,Y,H,M]),re=vy({editor:B,extraDirty:V,prepare:ee,unit:{name:"tile",count:U=>U.tiles.length},onSave:n,onDirtyChange:i,onExit:s,onChange:r,shortcuts:I,report:oy({size:k.document.tiles.length,path:p??"",layout:k.document.layout,savesTo:m,onEvent:h})}),he=k.document.tiles.length===0,we=b.jsx(dy,{...re.toolbarProps,...d?{actions:d}:{},...l?{onAddTile:()=>X()}:{},savesTo:m,...y?{saveLabel:y}:{},...v===void 0&&o?{layout:k.document.layout,onLayoutChange:U=>{const P=k.document.layout;U!==P&&(k.update(q=>{q.layout=U}),_o({path:p??"",layout:U},h).emit({type:"report.layout_changed",from:P,to:U}))}}:{}});return b.jsx(rf.Provider,{value:te,children:b.jsx(ye,{sx:{gap:0,mx:`-${Fs}px`},children:b.jsxs(ye,{sx:{gap:2,px:`${Fs}px`,pb:`${Fs}px`},children:[k.pendingOpen&&b.jsx(at,{severity:"info",children:"This report is in the cell format. Saving rewrites it as a layout notebook, and a named query run once becomes that tile's view."}),b.jsx(sy,{editor:k,notebook:H,documentSlug:ne,chrome:Z,actions:we,descriptionSelected:T,selectDescription:z}),he?b.jsx(b.Fragment,{children:b.jsxs(ye,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[b.jsx(ue,{variant:"body2",children:"This report is not served until it has a tile."}),l&&b.jsx(Oe,{size:"small",startIcon:b.jsx(Nr,{}),onClick:()=>X(),children:"Add tile"})]})}):b.jsx(hy,{controls:Q.controlList,tileCount:k.document.tiles.length,unknownFieldsOf:Q.unknownFieldsOf,onEdit:U=>j({control:U}),onAdd:()=>j({}),...x?{addDisabledReason:x}:{},onRemove:Q.dropControl,children:c}),k.error&&b.jsx(at,{severity:"warning",children:k.error}),b.jsx(ny,{editor:k,reorder:J,resizing:F,gridBox:C,columns:Y,notebook:H,chrome:Z,canAdd:!!l,selected:O,flash:L,menuIndex:R?.index,onSelect:$,onOpenMenu:(U,P)=>{$(P),W.setMenu({anchor:U,index:P})},openAdd:X,editTile:W.editTile,...a?{renderTile:a}:{}}),b.jsx(hp,{editor:k,catalog:l,columns:Y,dashboards:f,bindings:Q,tiles:W,drillSource:A,setDrillSource:K,confirmConversion:ae,exitDialog:re.exitGuard.dialog})]})})})}function _y(e,t){const n=new Set;for(const s of e.tiles)for(const o of ve(s)?s.filters??[]:[])n.add(o.given);const r=[],i=new Set;for(const s of e.localGivens??[])n.has(s.name)&&(i.add(s.name),r.push(By(s)));for(const s of t)s.name===void 0||i.has(s.name)||!n.has(s.name)||(i.add(s.name),r.push(s));return r}function By(e){const t=qy(e);return{name:e.name,type:e.type,...t===void 0?{}:{default:t},...e.label===void 0?{}:{label:e.label},...e.description===void 0?{}:{description:e.description},...e.control===void 0?{}:{control:e.control},...e.suggest?{suggest:{...e.suggest.source===void 0?{}:{source:e.suggest.source},...e.suggest.query===void 0?{}:{query:e.suggest.query},dimension:e.suggest.dimension}}:{},...e.rangeMin===void 0?{}:{rangeMin:e.rangeMin},...e.rangeMax===void 0?{}:{rangeMax:e.rangeMax}}}function qy(e){if(!e.type?.startsWith("filter<"))return e.default;const t=e.default?.match(/^f(['"])([\s\S]*)\1$/)?.[2];return t===void 0?e.default:t===""?void 0:t}function Hy(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function pi(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function Gy(e,t,n,r=new Map,i){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:i&&[...i]};const s=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(m=>[m.name,m.type])),c=e.sources.find(m=>m.name===s)?.scopedBy??[],u=new Set([...c,...i??[]].filter(m=>n.has(m))),l=new Set([...c,...i??[]]),d=[];for(const m of t.filters??[]){const y=`where: ${Uo(m.field)} ${m.op??"~"}`;if(n.has(m.given)){u.add(m.given),l.add(m.given),d.push(`${y} $${m.given}`);continue}if(!a.has(m.given))continue;l.add(m.given);const w=Rh(r.get(m.given),a.get(m.given));w!==void 0&&d.push(`${y} ${w}`)}const f=d.join(", "),h=t.chart,g=h==="none"||gs(h)?Tn(h,t.chartCarried):h==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
+
`):h==="default"&&Hy(t.declaration)?Tn("none"):void 0;return{...g?{annotation:g}:{},expression:`${s} -> ${o}`+(f?` + { ${f} }`:""),givenNames:Array.from(u),reads:i||l.size>0?Array.from(l):void 0}}function Vy({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:i,reportsSettled:s}){const{apiClients:o,server:a}=Bo(),{data:c}=qo({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(g=>g.path&&!g.error?[g.path]:[])}),u=S.useMemo(()=>new Set([r,...i.flatMap(g=>g.path?[g.path]:[])]),[i,r]),l=S.useMemo(()=>s?(c??[]).filter(g=>!u.has(g)):[],[c,u,s]),d=Ih({queries:l.map(g=>({queryKey:["report-editor-model",e,t,g,n,a],queryFn:async()=>(await o.models.getModel(e,t,g,n)).data,retry:!1}))}),f=c!==void 0&&s&&d.every(g=>g.isSuccess||g.isError),h=d.map(g=>g.dataUpdatedAt).join();return S.useMemo(()=>f?ky(d.flatMap(g=>g.data?[g.data]:[]),u):void 0,[f,l,h,u])}const Yy={};function Uy({textSource:e,modelGivens:t,environmentName:n,packageName:r,modelPath:i,versionId:s,opened:o,replaces:a,onSave:c,onDirtyChange:u,onExit:l,allowLayoutChange:d,onEvent:f,savesTo:h,saveLabel:g,note:m}){const{apiClients:y}=Bo(),[w,p]=S.useState(o.document.tiles.length>0);S.useEffect(()=>p(o.document.tiles.length>0),[o.generation,o.document]);const{data:v,isSuccess:x,isError:k}=qo({queryKey:["dashboard-editor-manifest",n,r,i,s],queryFn:async()=>{const I=(await y.reports.getReport(n,r,i,s)).data;return I.notebook?{...I.notebook.startingGivens?{startingGivens:I.notebook.startingGivens}:{},...I.notebook.autorun===void 0?{}:{autorun:I.notebook.autorun}}:I},enabled:w&&!e}),C=e?.modelPath??i,O=vh({environmentName:n,packageName:r,modelPath:C,source:o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0}),T=O.data?.document,$=e?O.isSuccess?T?.manifest??Yy:void 0:v,D=e?O.isSuccess:x,z=e?O.isError:k,N=e?bh(T?.cells):void 0,L=(O.data?.result.problems??[]).filter(I=>I.severity==="error"),B=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),H=e?.givens,Y=S.useMemo(()=>new Set(($?.tiles??[]).flatMap(I=>I.restricted&&I.query?[pi(I.query)]:[])),[$]),{reports:Z,settled:ne}=yh(n,r,s),J=S.useMemo(()=>Z.map(I=>I.path).filter(I=>!!I&&I!==i&&I.endsWith(".malloy")).map(I=>I.replace(/\.malloy$/,"")),[Z,i]),M=Vy({environmentName:n,packageName:r,...s!==void 0?{versionId:s}:{},modelPath:i,reports:Z,reportsSettled:ne}),F=S.useMemo(()=>e?(M?.sources??[]).filter(I=>(I.visibleIn??I.exporters??[I.modelPath]).includes(C)).map(I=>I.name):void 0,[M,e,C]),W=S.useMemo(()=>M&&F?{sources:M.sources.filter(I=>F.includes(I.name))}:M,[M,F]),[R,_]=S.useState(o.document);S.useEffect(()=>_(o.document),[o.document]);const X=S.useMemo(()=>c&&(async(I,re)=>{await c(I,re.document.layout),h==="package"&&p(re.document.tiles.length>0)}),[c,h]),Q=S.useMemo(()=>($?.givens??(o.conversion?t??[]:[])).filter(I=>!(e&&I.secure===!0)&&!(I.name!==void 0&&B.has(I.name))),[$,o.conversion,t,B,e]),E=S.useMemo(()=>new Set([...Q.map(I=>I.name).filter(I=>I!==void 0),...Object.keys(H??{})]),[Q,H]),j=S.useMemo(()=>_y(R,Q),[R,Q]),{declaredTypes:A,applied:K,panel:V}=xh({specs:j,loaded:D,startingValues:$?.startingGivens,documentKey:`${n}/${r}/${s??""}/${i}/edit`,autorun:$?.autorun!==!1,environmentName:n,packageName:r,modelPath:e?C:$?.path,versionId:s,documentName:i,...N!==void 0?{preamble:N}:{},...H?{hostGivens:H}:{}}),te=S.useMemo(()=>Object.fromEntries(Object.entries(H??{}).filter(([I])=>!A.has(I))),[H,A]),G=!w||D||z,ae=S.useMemo(()=>new Map(($?.tiles??[]).flatMap(I=>I.kind!=="text"&&I.query&&I.givenNames?[[pi(I.query),I.givenNames]]:[])),[$]),ee=S.useMemo(()=>function(I,re,he="card"){if(!G)return b.jsxs(ts,{chrome:he,children:[b.jsx(Cc,{title:re?.title??es(I),subtitle:re?re.subtitle:I.subtitle}),b.jsx(xc,{text:"Running…"})]});const we=Gy(R,I,E,K,ae.get(pi(`${I.source} -> ${I.name}`)));return b.jsx(wh,{environmentName:n,packageName:r,versionId:s,modelPath:C,...N!==void 0?{preamble:N}:{},...Y.has(pi(`${I.source} -> ${I.name}`))?{restricted:!0}:{},tile:we.expression,...we.annotation?{annotation:we.annotation}:{},label:es(I),chrome:he,subtitle:I.subtitle,...re?{heading:re}:{},borderless:I.borderless,givens:K,hostGivens:te,declaredTypes:A,givenNames:we.givenNames,ignoredFilters:Sh(we.reads,j),height:kh})},[R,G,E,ae,n,r,s,C,N,Y,K,te,A,j]);return b.jsxs(ye,{sx:{gap:1},children:[e&&L.length>0&&b.jsxs(at,{severity:"error",children:["The server could not compile this document:"," ",L.map(I=>I.message).join("; ")]}),e&&O.isError&&b.jsxs(at,{severity:"error",children:["The server could not compile this document:"," ",O.error?.message]}),b.jsx(Ff,{...e?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:o.source,document:o.document,renderTile:ee,givens:j.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:_,onDirtyChange:u,...l?{onExit:l}:{},...d!==void 0?{allowLayoutChange:d}:{},...o.conversion?{conversion:o.conversion}:{},...W?{catalog:W}:{},dashboards:J,...f?{onEvent:f}:{},controls:D?b.jsx($h,{...V,layout:R.layout==="linear"?"panel":"bar"}):void 0,...X?{onSave:X}:{},savesTo:h,...g?{saveLabel:g}:{},...a!==void 0?{replaces:a}:{},modelPath:i,...e?{visibleSources:F}:{}}),b.jsx(De,{sx:{px:.5},children:b.jsx(ue,{variant:"caption",sx:{opacity:.7},children:m})})]})}function Xy({storage:e,layout:t,notebook:n,environmentName:r,packageName:i,modelPath:s}){const[o,a]=S.useState(void 0),[c,u]=S.useState(void 0),[l,d]=S.useState(e===void 0),[f,h]=S.useState(!1),[g,m]=S.useState(void 0);return S.useEffect(()=>{if(!e)return;let y=!1;return m(void 0),(async()=>{try{const w=fh(await e.listWorkspaces(!1));if(y)return;if(a(w),w!==void 0&&(!n||w.authoritative)){const p=await e.getDocument(kc(t,w.name,r,i,s)).catch(v=>{if(!Sc(v))throw v});if(y)return;u(p),h(p!==void 0)}}catch(w){if(y)return;m($c(w))}y||d(!0)})(),()=>{y=!0}},[e,t,n,r,i,s]),{workspace:o,draft:c,setDraft:u,draftChecked:l,offered:f,setOffered:h,readFailure:g}}const Ky=e=>e.ok===!1,tr=(e,t)=>{const n=e[t];return typeof n=="function"?n.call(e):void 0},Zy=[["runStatement","run"],["docAnnotations","notes"],["importStatement","definition"],["defineSourceStatement","definition"],["defineQuery","definition"],["defineGivenStatement","definition"],["defineUserTypeStatement","definition"],["exportStatement","definition"]],Qy=/^[A-Za-z_][A-Za-z0-9_]*$/,Jy="file:///publisher-notebook-builder/notebook.malloy",mi=e=>e.replace(/\r\n?/g,`
|
|
144
144
|
`);async function ex(e){const t=(M,F)=>({ok:!1,refused:`Line ${M+1}: ${F}`,line:M+1}),n=/\r(?!\n)/.exec(e);if(n)return t(e.slice(0,n.index).split(`
|
|
145
|
-
`).length-1,"a carriage return that is not part of a CRLF line ending, so the cells cannot be located. Fix: save the file with LF or CRLF line endings.");let r,i;try{r=await
|
|
145
|
+
`).length-1,"a carriage return that is not part of a CRLF line ending, so the cells cannot be located. Fix: save the file with LF or CRLF line endings.");let r,i;try{r=await Xr(e,Jy),i=await Go()}catch(M){return t(0,`Malloy could not read this notebook: ${M}`)}const s=r.problems.find(M=>M.code==="syntax-error");if(s)return t(s.at?.range?.start?.line??0,`Malloy could not parse this notebook (${s.message??"unknown"}), so it cannot be edited here. Fix: correct the syntax on that line.`);const o=r.parse?.root,a=r.parse?.tokenStream,c=a?.tokenSource?.vocabulary,u=typeof a?.getTokens=="function"?a.getTokens():void 0;if(!o||typeof o.getChild!="function"||!a||!u||typeof c?.getSymbolicName!="function"||u.length===0&&e.trim()!=="")return{ok:!1,refused:"This build of Malloy does not expose a parse tree and token stream the notebook builder can read, so editing is off."};const l=M=>c.getSymbolicName(M.type),d=M=>i.routeOf({value:M.trimStart()}),f=M=>i.payloadOf({value:M}),h=M=>M==="markdown"||M==='"'||M==="text",g=M=>mi(f(M)).replace(/\n$/,""),m=(M,F)=>{const W=f(M).trim(),R=d(M)!=='"'&&Qy.test(W)?"":W;return mi([R&&`${R}
|
|
146
146
|
`,...F].join("")).replace(/\n$/,"")},y=new vs(e),w=Za(y,a),p=M=>e.slice(y.utf16(M.startIndex),y.utf16(M.stopIndex+1)),v=M=>{const F=M.start?.startIndex,W=M.stop?.stopIndex,R=y.span(M);if(F===void 0||W===void 0||!R)return;let _=R.end;for(;_>R.start&&(e[_-1]===`
|
|
147
|
-
`||e[_-1]==="\r");)_--;return{startCp:F,stopCp:W,...R,startLine:y.line(R.start),endLine:y.line(Math.max(R.start,_-1))}},x=M=>{let F=0,W=u.length;for(;F<W;){const R=F+W>>1;u[R].startIndex<M?F=R+1:W=R}return F},k=(M,F)=>{const W=[],R=[],_={lines:[],insertAt:y.utf16(M)};let
|
|
148
|
-
${V}`:W.push(V),
|
|
147
|
+
`||e[_-1]==="\r");)_--;return{startCp:F,stopCp:W,...R,startLine:y.line(R.start),endLine:y.line(Math.max(R.start,_-1))}},x=M=>{let F=0,W=u.length;for(;F<W;){const R=F+W>>1;u[R].startIndex<M?F=R+1:W=R}return F},k=(M,F)=>{const W=[],R=[],_={lines:[],insertAt:y.utf16(M)};let X=-2;for(let Q=x(M);Q<u.length;Q++){const E=u[Q];if(E.startIndex>F)break;if(E.channel!==0)continue;const j=l(E);if(j!=="ANNOTATION"&&j!=="BLOCK_ANNOTATION_BEGIN"){_.insertAt=y.lineStarts[y.line(y.utf16(E.startIndex))];break}const A=mi(p(E)),K=[];if(j==="BLOCK_ANNOTATION_BEGIN"){for(;l(u[Q+1]??E)==="BLOCK_ANNOTATION_TEXT";)K.push(p(u[++Q]));l(u[Q+1]??E)==="BLOCK_ANNOTATION_END"&&Q++}if(h(d(A))){const V=y.utf16(E.startIndex),te=y.lineStarts[y.line(V)],G=/^[ \t]*$/.test(e.slice(te,V));R.push({start:G?te:V,end:y.utf16(u[Q].stopIndex+1)})}if(j==="ANNOTATION"){const V=A.replace(/\n$/,"");if(Wt(V)){const te=y.utf16(E.startIndex),G=y.lineStarts[y.line(te)];_.lines.push({span:{start:/^[ \t]*$/.test(e.slice(G,te))?G:te,end:y.utf16(E.stopIndex+1)},text:V})}else Pr(V)&&_.unmodelled===void 0&&(_.unmodelled=V.trim())}if(d(A)!=="markdown")X=-2;else if(j==="BLOCK_ANNOTATION_BEGIN")W.push(m(A,K)),X=-2;else{const V=g(A);E.line===X+1?W[W.length-1]+=`
|
|
148
|
+
${V}`:W.push(V),X=E.line}}return{markdown:W.length>0?W.join(`
|
|
149
149
|
|
|
150
150
|
`):void 0,prose:R,chart:_}},C=[],O=[],T=(M,F,W="remove it, or rewrite it as an import, source:, query:, given:, type: or export statement, a run:, or a `##(markdown)` / `##|(markdown)` prose note.")=>t(M,`${F}, which no notebook cell can hold, so the notebook cannot be edited here. Fix: ${W}`);for(let M=0;M<(o.childCount??0);M++){const F=o.getChild(M);if(!cn(F)){const E=F?.symbol,j=E?l(E):void 0;if(E&&j==="EOF")continue;if(E&&j==="SEMI"){C.push([E.startIndex,E.stopIndex]);continue}return T((E?.line??1)-1,"a token outside any statement")}const W=v(F);if(!W)return T(0,"a statement with no readable range");const R=Zy.find(([E])=>tr(F,E)!==void 0);if(!R&&tr(F,"ignoredObjectAnnotations"))return T(W.startLine,"a # tag that annotates no statement","move the tag directly above its run:, or write trailing prose as a `##(markdown)` note.");if(!R){const E=e.slice(W.start,W.end).split(`
|
|
151
|
-
`)[0];return T(W.startLine,`\`${E.trim()}\` is a statement the notebook reader does not recognize`)}C.push([W.startCp,W.stopCp]);const[_,
|
|
152
|
-
`,1)[0],V.map(p)):g(G):void 0;O.push({kind:"note",note:{text:G,route:ae,...ee!==void 0&&{body:ee},block:A,startLine:j.startLine,endLine:j.endLine}})}}for(const M of u){if(l(M)!=="BLOCK_ANNOTATION_END")continue;const F=p(M).trimStart().replace(/^\|#{1,2}/,"").trim();if(F)return t(M.line-1,`the text after a block's closer (\`${F}\`) is not part of any cell, so the notebook cannot be edited here. Fix: put it on its own line, or inside the block.`)}let $=0;for(const M of u){if(M.channel!==0||l(M)==="EOF")continue;for(;$<C.length&&C[$][1]<M.startIndex;)$++;const[F,W]=C[$]??[1/0,-1/0];if(M.startIndex<F||M.stopIndex>W)return T(M.line-1,"a token outside any statement")}const D=O.findIndex(M=>M.kind==="note"&&Ac(M.note.text));if(D<0)return t(0,"this file has no ## artifact note, so it is not a notebook the builder can edit. Fix: add `## artifact { layout=linear }` after the ##! line.");const z=O.findIndex((M,F)=>F<D&&M.kind==="statement");if(z>=0)return t(O[z].startLine,'a statement sits above the `## artifact` tag, where only `##!` flags, comments and `"` notes may. Fix: move it below the artifact tag.');for(let M=1;M<O.length;M++){const F=O[M-1],W=O[M],R=F.kind==="note"?F.note.endLine:F.endLine,_=W.kind==="note"?W.note.startLine:W.startLine;if(_<=R)return T(_,"a line holding two statements or notes","put each statement and note on its own line.")}const N=M=>y.lineStarts[M+1]??e.length,L=[];let B=-1,H=!0,
|
|
153
|
-
${W.body}`,
|
|
151
|
+
`)[0];return T(W.startLine,`\`${E.trim()}\` is a statement the notebook reader does not recognize`)}C.push([W.startCp,W.stopCp]);const[_,X]=R;if(X!=="notes"){const{markdown:E,prose:j,chart:A}=k(W.startCp,W.stopCp);O.push({kind:"statement",run:X==="run",...E!==void 0&&{markdown:E},prose:j,chart:A,startLine:W.startLine,endLine:W.endLine});continue}const Q=tr(F,_);for(const E of tr(Q,"docAnnotation")??[]){const j=v(E);if(!j)return T(W.startLine,"a note with no readable range");const A=tr(E,"docBlockAnnotation")!==void 0,K=u.filter(I=>I.startIndex>=j.startCp&&I.stopIndex<=j.stopCp),V=K.filter(I=>l(I)==="BLOCK_ANNOTATION_TEXT"),te=V[V.length-1]??K[0],G=mi(A&&te?e.slice(j.start,y.utf16(te.stopIndex+1)).replace(/\r?\n$/,""):e.slice(j.start,j.end)),ae=d(G),ee=h(ae)?A?m(G.split(`
|
|
152
|
+
`,1)[0],V.map(p)):g(G):void 0;O.push({kind:"note",note:{text:G,route:ae,...ee!==void 0&&{body:ee},block:A,startLine:j.startLine,endLine:j.endLine}})}}for(const M of u){if(l(M)!=="BLOCK_ANNOTATION_END")continue;const F=p(M).trimStart().replace(/^\|#{1,2}/,"").trim();if(F)return t(M.line-1,`the text after a block's closer (\`${F}\`) is not part of any cell, so the notebook cannot be edited here. Fix: put it on its own line, or inside the block.`)}let $=0;for(const M of u){if(M.channel!==0||l(M)==="EOF")continue;for(;$<C.length&&C[$][1]<M.startIndex;)$++;const[F,W]=C[$]??[1/0,-1/0];if(M.startIndex<F||M.stopIndex>W)return T(M.line-1,"a token outside any statement")}const D=O.findIndex(M=>M.kind==="note"&&Ac(M.note.text));if(D<0)return t(0,"this file has no ## artifact note, so it is not a notebook the builder can edit. Fix: add `## artifact { layout=linear }` after the ##! line.");const z=O.findIndex((M,F)=>F<D&&M.kind==="statement");if(z>=0)return t(O[z].startLine,'a statement sits above the `## artifact` tag, where only `##!` flags, comments and `"` notes may. Fix: move it below the artifact tag.');for(let M=1;M<O.length;M++){const F=O[M-1],W=O[M],R=F.kind==="note"?F.note.endLine:F.endLine,_=W.kind==="note"?W.note.startLine:W.startLine;if(_<=R)return T(_,"a line holding two statements or notes","put each statement and note on its own line.")}const N=M=>y.lineStarts[M+1]??e.length,L=[];let B=-1,H=!0,Y;O.forEach((M,F)=>{if(M.kind==="statement"){H=!1,Y=void 0,L.push({cell:{kind:M.run?"query":"definition",...M.markdown!==void 0&&{markdown:M.markdown},...M.prose.length>0&&{prose:M.prose},...M.run&&{chart:M.chart},id:""},startLine:M.startLine,endLine:M.endLine});return}const{note:W}=M;if(!(F>D&&W.body!==void 0)){H&&(B=W.endLine),Y=void 0;return}if(H=!1,!W.block&&Y&&Y.endLine+1===W.startLine){Y.cell.markdown+=`
|
|
153
|
+
${W.body}`,Y.endLine=W.endLine;return}const R={cell:{kind:"markdown",markdown:W.body,id:""},startLine:W.startLine,endLine:W.endLine};L.push(R),Y=W.block?void 0:R});const Z={start:0,end:N(B)};let ne=B;const J=L.map(({cell:M,startLine:F,endLine:W},R)=>{let _=F;for(;_-1>ne&&w.lines.has(_-1);)_--;return ne=W,{...M,span:{start:y.lineStarts[_],end:N(W)},id:String(R)}});for(const M of[Z,...J.map(F=>F.span)]){const F=w.all.find(W=>W.start<M.start&&W.end>M.start||W.start<M.end&&W.end>M.end);if(F)return T(y.line(F.start),"a comment that straddles a cell","start the comment on its own line.")}return{ok:!0,source:{text:e,header:Z,cells:J}}}const tx=e=>e.ok===!1,nx=/^[A-Za-z_][A-Za-z0-9_]*$/,pc=/^query\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s+is\s+/,mc=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;function Gs(e){let t="",n=0;for(;n<e.length;){const r=e.slice(n,n+2);if(r==="//"||r==="--"){const i=e.indexOf(`
|
|
154
154
|
`,n),s=i<0?e.length:i;t+=" ".repeat(s-n),n=s}else if(r==="/*"){const i=e.indexOf("*/",n+2),s=i<0?e.length:i+2;t+=e.slice(n,s).replace(/[^\n]/g," "),n=s}else if(e[n]==="'"||e[n]==='"'||e[n]==="`"){const i=e[n];let s=n+1;for(;s<e.length&&e[s]!==i;)s+=e[s]==="\\"?2:1;const o=Math.min(s,e.length);t+=i+e.slice(n+1,o).replace(/[^\n]/g," "),o<e.length&&(t+=i),n=o+1}else t+=e[n],n++}return t}function gc(e){const t=[];let n=0;for(let r=0;r<e.length;r++){const i=e[r];i==="{"||i==="("||i==="["?n++:i==="}"||i===")"||i==="]"?n--:n===0&&i==="-"&&e[r+1]===">"&&t.push(r)}return t}function vc(e,t,n){let r=e;for(const i of[...n].sort((s,o)=>o.start-s.start))r=r.slice(0,i.start-t)+r.slice(i.end-t);return r}function bc(e,t){const n=t.split(`
|
|
155
155
|
`).map(r=>r.startsWith("|##")?` ${r}`:r).join(`
|
|
156
156
|
`);return`##|(markdown) ${e}
|
|
157
157
|
${n===""?"":`${n}
|
|
158
158
|
`}|##
|
|
159
|
-
`}function rx(e){return e.trim()===""?"":/^\s*(#|\/\/|--|\/\*)/.test(e)?` ${e.trimStart()}`:` ${e}`}function ix(e){const t=(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),n=t.length>40?t.lastIndexOf("_",40):t.length,r=t.slice(0,n>0?n:40);return/^[a-z]/.test(r)&&
|
|
160
|
-
`),o=rs(s);if(o&&!Ec(o.text))return i(o.from,Oc);if(!o||Qa(o.text))return i(Math.max(o?.from??0,0),"this notebook already lists its tiles, so there is nothing to convert.");const a=(await
|
|
161
|
-
`),v=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),x=E=>{let j=E;for(let A=2;v.has(j);A++)j=`${E}_${A}`;return v.add(j),j},k=E=>{const j=u.filter(ee=>ee.channel===0&&h.utf16(ee.startIndex)>=E.span.start&&h.utf16(ee.stopIndex+1)<=E.span.end),A=[],K=[],V=[];let te;for(let ee=0;ee<j.length;ee++){const I=f(j[ee]);if(I!=="ANNOTATION"&&I!=="BLOCK_ANNOTATION_BEGIN"){te=j[ee];break}let re=ee;const he=[];if(I==="BLOCK_ANNOTATION_BEGIN"){for(;f(j[re+1]??j[ee])==="BLOCK_ANNOTATION_TEXT";)he.push(m(j[++re]));f(j[re+1]??j[ee])==="BLOCK_ANNOTATION_END"&&re++}const we=p(m(j[ee])),
|
|
162
|
-
`,1)[0])),...he.map(p)].map(pe=>pe.trim()).filter(Boolean).join(" "))),ee=re}if(!te)return;const G=h.utf16(te.startIndex),ae=e.slice(E.span.start,E.span.end);return{cell:E,above:vc(e.slice(E.span.start,G),E.span.start,(E.kind==="query"?[...A,...K]:A).filter(ee=>ee.end<=G)),statement:e.slice(G,E.span.end).trimEnd(),kept:vc(ae,E.span.start,A),...E.kind==="query"&&V.length>0&&{caption:V.join(" ")},line:h.line(G)}},C=new Map,O=new Map;for(const[E,j]of r.entries()){if(j.kind==="markdown")continue;const A=k(j);if(!A)return i(h.line(j.span.start),"a cell with no statement the converter can place.");O.set(E,A);const K=pc.exec(A.statement);j.kind==="definition"&&K&&C.set(K[1],{expression:A.statement.slice(K[0].length).trim(),cell:E})}const T=E=>{const j=/^run\s*:\s*/.exec(E.statement);if(!j)return i(E.line,"a run that is not `run: <query>`.");let A=E.statement.slice(j[0].length).trim();const K=[];for(let ee=0;ee<10;ee++){const I=Gs(A),re=/^[A-Za-z_][A-Za-z0-9_]*/.exec(I)?.[0],he=re?C.get(re):void 0;if(!re||!he)break;const we=A.slice(re.length).trim(),
|
|
163
|
-
`:" ";A=`${he.expression}${we===""?"":`${P}${we}`}`}const V=Gs(A);if(C.has(/^[A-Za-z_][A-Za-z0-9_]*/.exec(V)?.[0]??""))return i(E.line,"this run names a query defined through more than 10 other queries, which the converter does not follow.");const te=gc(V);if(te.length===0)return i(E.line,"this run is not `source -> view`, so it cannot become a tile. Fix: write it as `run: <source> -> <view>`.");const G=A.slice(0,te[0]).trim();if(/\bextend\b/.test(V.slice(0,te[0])))return i(E.line,"this run extends its source inline before `->`, so it cannot become a tile. Fix: declare the extension with a `source:` statement and run that.");if(!nx.test(G)&&!/^`[^`]+`$/.test(G))return i(E.line,"the source of this run is not a name, so it cannot become a tile. Fix: name it with a `source:` statement and run that.");const ae=A.slice(te[0]+2).trim();return ae===""?i(E.line,"this run has nothing after `->`."):{source:G,body:ae,used:K}},$=new Map,D=[],z=new Set,N=new Map;let L=0,B=0;const H=new Map;for(const E of O.values()){if(E.cell.kind!=="query")continue;const j=T(E);if("ok"in j)return j;for(const A of j.used)H.set(A,(H.get(A)??0)+1)}const
|
|
164
|
-
`).join("");N.set(E,P+bc(
|
|
165
|
-
`}if(j.kind==="definition"){const
|
|
166
|
-
`).filter(P=>P.trim()!=="")),K&&N.set(E,K.replace(/\n$/,""));continue}N.set(E,`${K}${A.kept}`);continue}const V=T(A),te=V.source.replace(/`/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/^(?=[0-9])/,"_");let G=$.get(V.source);G||(G={name:x(`${te}_tiles`),base:V.source,views:[]},$.set(V.source,G));const ae=[...V.used.flatMap(
|
|
167
|
-
`)].filter(
|
|
168
|
-
`).map((
|
|
159
|
+
`}function rx(e){return e.trim()===""?"":/^\s*(#|\/\/|--|\/\*)/.test(e)?` ${e.trimStart()}`:` ${e}`}function ix(e){const t=(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),n=t.length>40?t.lastIndexOf("_",40):t.length,r=t.slice(0,n>0?n:40);return/^[a-z]/.test(r)&&Yo(r)?r:void 0}async function sx(e){const t=await ex(e);if(Ky(t))return{ok:!1,refused:t.refused,line:t.line};const{header:n,cells:r}=t.source,i=(E,j)=>({ok:!1,refused:`Line ${E+1}: ${j}`,line:E+1}),s=e.slice(n.start,n.end).split(`
|
|
160
|
+
`),o=rs(s);if(o&&!Ec(o.text))return i(o.from,Oc);if(!o||Qa(o.text))return i(Math.max(o?.from??0,0),"this notebook already lists its tiles, so there is nothing to convert.");const a=(await Xr(e,"file:///publisher-notebook-builder/convert.malloy")).parse?.tokenStream,c=a?.tokenSource?.vocabulary,u=a?.getTokens?.()??[];if(typeof c?.getSymbolicName!="function")return i(0,"Malloy's token stream is not available.");const l=await Go(),{parseAnnotation:d}=await Ho(),f=E=>c.getSymbolicName(E.type),h=new vs(e),g=Za(h,a),m=E=>e.slice(h.utf16(E.startIndex),h.utf16(E.stopIndex+1)),y=E=>l.routeOf({value:E.trimStart()}),w=E=>l.payloadOf({value:E}),p=E=>E.replace(/\r\n?/g,`
|
|
161
|
+
`),v=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),x=E=>{let j=E;for(let A=2;v.has(j);A++)j=`${E}_${A}`;return v.add(j),j},k=E=>{const j=u.filter(ee=>ee.channel===0&&h.utf16(ee.startIndex)>=E.span.start&&h.utf16(ee.stopIndex+1)<=E.span.end),A=[],K=[],V=[];let te;for(let ee=0;ee<j.length;ee++){const I=f(j[ee]);if(I!=="ANNOTATION"&&I!=="BLOCK_ANNOTATION_BEGIN"){te=j[ee];break}let re=ee;const he=[];if(I==="BLOCK_ANNOTATION_BEGIN"){for(;f(j[re+1]??j[ee])==="BLOCK_ANNOTATION_TEXT";)he.push(m(j[++re]));f(j[re+1]??j[ee])==="BLOCK_ANNOTATION_END"&&re++}const we=p(m(j[ee])),U=y(we),P=h.utf16(j[ee].startIndex),q=h.lineStarts[h.line(P)],oe={start:/^[ \t]*$/.test(e.slice(q,P))?q:P,end:h.utf16(j[re].stopIndex+1)};U==="markdown"?A.push(oe):U==='"'&&(K.push(oe),V.push(I==="ANNOTATION"?p(w(we)).replace(/\n$/,"").trim():[p(w(we.split(`
|
|
162
|
+
`,1)[0])),...he.map(p)].map(pe=>pe.trim()).filter(Boolean).join(" "))),ee=re}if(!te)return;const G=h.utf16(te.startIndex),ae=e.slice(E.span.start,E.span.end);return{cell:E,above:vc(e.slice(E.span.start,G),E.span.start,(E.kind==="query"?[...A,...K]:A).filter(ee=>ee.end<=G)),statement:e.slice(G,E.span.end).trimEnd(),kept:vc(ae,E.span.start,A),...E.kind==="query"&&V.length>0&&{caption:V.join(" ")},line:h.line(G)}},C=new Map,O=new Map;for(const[E,j]of r.entries()){if(j.kind==="markdown")continue;const A=k(j);if(!A)return i(h.line(j.span.start),"a cell with no statement the converter can place.");O.set(E,A);const K=pc.exec(A.statement);j.kind==="definition"&&K&&C.set(K[1],{expression:A.statement.slice(K[0].length).trim(),cell:E})}const T=E=>{const j=/^run\s*:\s*/.exec(E.statement);if(!j)return i(E.line,"a run that is not `run: <query>`.");let A=E.statement.slice(j[0].length).trim();const K=[];for(let ee=0;ee<10;ee++){const I=Gs(A),re=/^[A-Za-z_][A-Za-z0-9_]*/.exec(I)?.[0],he=re?C.get(re):void 0;if(!re||!he)break;const we=A.slice(re.length).trim(),U=I.slice(re.length).trim();if(U!==""&&!U.startsWith("->")&&!U.startsWith("+"))break;if(U.startsWith("+")&&gc(Gs(he.expression)).length!==1)return i(E.line,`\`${re} + { … }\` refines a query with more than one stage, which cannot become one view.`);K.push(re);const P=/(\/\/|--)[^\n]*$/.test(he.expression)?`
|
|
163
|
+
`:" ";A=`${he.expression}${we===""?"":`${P}${we}`}`}const V=Gs(A);if(C.has(/^[A-Za-z_][A-Za-z0-9_]*/.exec(V)?.[0]??""))return i(E.line,"this run names a query defined through more than 10 other queries, which the converter does not follow.");const te=gc(V);if(te.length===0)return i(E.line,"this run is not `source -> view`, so it cannot become a tile. Fix: write it as `run: <source> -> <view>`.");const G=A.slice(0,te[0]).trim();if(/\bextend\b/.test(V.slice(0,te[0])))return i(E.line,"this run extends its source inline before `->`, so it cannot become a tile. Fix: declare the extension with a `source:` statement and run that.");if(!nx.test(G)&&!/^`[^`]+`$/.test(G))return i(E.line,"the source of this run is not a name, so it cannot become a tile. Fix: name it with a `source:` statement and run that.");const ae=A.slice(te[0]+2).trim();return ae===""?i(E.line,"this run has nothing after `->`."):{source:G,body:ae,used:K}},$=new Map,D=[],z=new Set,N=new Map;let L=0,B=0;const H=new Map;for(const E of O.values()){if(E.cell.kind!=="query")continue;const j=T(E);if("ok"in j)return j;for(const A of j.used)H.set(A,(H.get(A)??0)+1)}const Y=E=>H.get(E)===1&&(e.match(new RegExp(`\\b${E}\\b`,"g"))??[]).length===2,Z=new Map;for(const[E,j]of r.entries()){if(j.kind==="markdown"){const U=x(`text_${++L}`);D.push(`${U} { kind=text }`);const P=g.all.filter(q=>q.start>=j.span.start&&q.end<=j.span.end).map(q=>`${e.slice(q.start,q.end)}
|
|
164
|
+
`).join("");N.set(E,P+bc(U,j.markdown??""));continue}const A=O.get(E);let K="";if(j.markdown!==void 0){const U=x(`text_${++L}`);D.push(`${U} { kind=text }`),K=`${bc(U,j.markdown)}
|
|
165
|
+
`}if(j.kind==="definition"){const U=pc.exec(A.statement)?.[1];if(U&&Y(U)){z.add(E),Z.set(U,A.above.split(`
|
|
166
|
+
`).filter(P=>P.trim()!=="")),K&&N.set(E,K.replace(/\n$/,""));continue}N.set(E,`${K}${A.kept}`);continue}const V=T(A),te=V.source.replace(/`/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/^(?=[0-9])/,"_");let G=$.get(V.source);G||(G={name:x(`${te}_tiles`),base:V.source,views:[]},$.set(V.source,G));const ae=[...V.used.flatMap(U=>Z.get(U)??[]),...A.above.split(`
|
|
167
|
+
`)].filter(U=>U.trim()!==""),ee=ae.filter(U=>/^\s*#(?!["(|])/.test(U)),I=ee.length>0?Ja(d,ee).tag:void 0,re=x(ix(I?.text("label")??A.caption)??`tile_${B+1}`);B++,D.push(`"${G.name} -> ${re}"`);const he=ae.map(rx);if(A.caption!==void 0){const U=Gt("caption",A.caption)===void 0;U&&!I?.has("label")?he.push(` # label=${mc(A.caption)}`):U&&!I?.has("subtitle")?he.push(` # subtitle=${mc(A.caption)}`):he.push(` #" ${A.caption}`)}const we=V.body.split(`
|
|
168
|
+
`).map((U,P)=>P===0||U.trim()===""?U:` ${U}`).join(`
|
|
169
169
|
`);G.views.push([...he,` view: ${re} is ${we}`].join(`
|
|
170
170
|
`)),z.add(E),K&&N.set(E,K.replace(/\n$/,""))}const ne=(()=>{let E=0;const j=o.text;for(let A=j.indexOf("{");A<j.length;A++)if(j[A]==='"')for(A++;A<j.length&&j[A]!=='"';A++)j[A]==="\\"&&A++;else if(j[A]==="{")E++;else if(j[A]==="}"&&--E===0)return A;return-1})();if(ne<0)return i(o.from,"the `## artifact { … }` tag never closes.");const J=D.length===0?`
|
|
171
171
|
tiles=[]
|
|
@@ -179,9 +179,9 @@ ${D.map(E=>` ${E}`).join(`,
|
|
|
179
179
|
`));const F=E=>{const j=E.text.split(`
|
|
180
180
|
`),A=j.pop(),K=[];let V=0;for(const te of j){const G=E.at[V]??-1,ae=g.all.some(ee=>G>=ee.start&&G<ee.end);(te.trim()!==""||K.at(-1)?.trim()!==""||ae)&&K.push(te),V+=te.length+1}return K.map(te=>`${te}
|
|
181
181
|
`).join("")+A},W={text:"",at:[]},R=(E,j)=>{W.text+=e.slice(E,j);for(let A=E;A<j;A++)W.at.push(A)};let _=s.join(`
|
|
182
|
-
`),
|
|
182
|
+
`),X=n.end;for(const[E,j]of r.entries()){R(X,j.span.start),X=j.span.end;const A=N.get(E);A!==void 0&&(_+=F(W)+(A.endsWith(`
|
|
183
183
|
`)?A:`${A}
|
|
184
|
-
`),W.text="",W.at=[])}R(
|
|
184
|
+
`),W.text="",W.at=[])}R(X,e.length),_=`${_.trimEnd()}
|
|
185
185
|
`+(W.text.trim()===""?"":F(W)),_=`${_.trimEnd()}
|
|
186
186
|
`;const Q=[...$.values()].map(E=>`source: ${E.name} is ${E.base} extend {
|
|
187
187
|
${E.views.join(`
|
|
@@ -192,4 +192,4 @@ ${E.views.join(`
|
|
|
192
192
|
${Q.join(`
|
|
193
193
|
`)}`),e.includes(`\r
|
|
194
194
|
`)&&(_=_.replace(/\r?\n/g,`\r
|
|
195
|
-
`)),{ok:!0,text:_,tiles:D.length}}const Vs=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function ox(e){const t=await Zi(e);if(!Yi(t))return{ok:!0,document:t.document};if(!t.legacyNotebook)return{ok:!1,reason:Vs(t.reason,t.line)};const n=await sx(e);if(tx(n))return{ok:!1,reason:Vs(n.refused,n.line)};const r=await Zi(n.text);return Yi(r)?{ok:!1,reason:`The converted notebook cannot be opened: ${Vs(r.reason,r.line)}`}:{ok:!0,document:r.document,conversion:{from:e,to:n.text}}}const ax="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",lx="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function cx({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:i,fetchedAt:s,packageSettled:o,modelPath:a,layout:c,notebook:u,noun:l,legacyFormat:d,textHeld:f,startedAt:h,onEventRef:g}){const m=S.useRef({path:a,layout:c});m.current={path:a,layout:c};const y=S.useRef((G,ae)=>{try{g.current?.(hh(G,{...m.current,...ae?{layout:ae}:{}}))}catch{}}),w=e?.authoritative===!0,p=w&&r!==void 0,[v,x]=S.useState(void 0),k=(w||v===!0)&&t!==void 0,[C,O]=S.useState(void 0),[T,$]=S.useState(d?ax:void 0),D=S.useRef(void 0),z=S.useRef(void 0),[N,L]=S.useState(void 0),B=S.useRef(s);B.current=s;const H=N!==void 0&&N.onFetch===s?N.text:i,U=S.useRef(H);U.current=H;const Z=k?t:H,[ne,J]=S.useState(!1),[M,F]=S.useState(void 0),[W,R]=S.useState(void 0),_=Z!==void 0&&Z!==W,Y=C?.source,Q=_&&(ne||!w&&t!==void 0&&Y===t&&t!==H)&&Y!==void 0&&Z!==M,E=Q?Y:_?Z:Y??Z,j=Q?Z:void 0,A=S.useRef(Y);A.current=Y;const K=S.useRef(Z);K.current=Z;const V=S.useRef("package");V.current=k?w?"record":"draft":"package",S.useEffect(()=>{if(E===void 0||!n||p||E===A.current)return;let G=!1;const ae=U.current,ee=K.current;return ox(E).then(I=>{if(!G){if(I.ok===!1){$(I.reason),y.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}$(void 0),D.current=void 0,z.current=ae,L(void 0),F(void 0),R(ee),O(re=>({source:E,document:I.document,...I.conversion?{conversion:I.conversion}:{},...ae!==void 0?{packageText:ae}:{},generation:(re?.generation??0)+1})),y.current({type:"report.opened",surface:"edit",from:V.current,tiles:I.document.tiles.length,durationMs:At()-h.current},I.document.layout)}}).catch(I=>{if(G)return;const re=`Could not read the ${l}: ${I instanceof Error?I.message:String(I)}`;$(re),y.current({type:"report.load_failed",surface:"edit",category:yc(I)})}),()=>{G=!0}},[E,a,n,p,u,l,f,h]),S.useEffect(()=>{d&&y.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[d]),S.useEffect(()=>{!f||!n||C||r!==void 0||(w?t===void 0&&$("the host's storage has no document at this location."):$("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,C,r,w,t]);const te=u&&!f&&!C&&n&&!k&&o&&i===void 0;return S.useEffect(()=>{te&&($(lx),y.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[te]),{authoritative:w,blockedOnRecord:p,resume:v,setResume:x,fromDraft:k,opened:C,setOpened:O,openError:T,savedHashRef:D,packageBaseRef:z,setWrote:L,fetchedAtRef:B,setDirty:J,setSeen:R,held:j,choose:G=>{h.current=At(),F(G?t:H),x(G)},acceptHeld:()=>{h.current=At(),F(j)}}}function dx({storage:e,workspace:t,layout:n,notebook:r,environmentName:i,packageName:s,modelPath:o,versionId:a,apiClients:c,queryClient:u,mutable:l,textHeld:d,readFailure:f,authoritative:h,resume:g,setResume:m,setOpened:y,setDraft:w,setOffered:p,setSeen:v,setWrote:x,savedHashRef:k,packageBaseRef:C,fetchedAtRef:O}){const T=S.useCallback(J=>t===void 0?void 0:kc(J,t.name,i,s,o),[t,i,s,o]),$=T(n),D=S.useCallback(async(J,M=n)=>{const F=T(M);if(!e||!F)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(F,J),y(W=>W&&{...W,source:J}),w(J),(h||g===!0)&&v(J),h||m(W=>W??!1)},[e,T,n,h,g,y,w,v,m]),[z,N]=S.useState(void 0),L=S.useCallback(async J=>{const M=await ph(k.current,C.current);if(M===void 0)throw new Error("The package file is still loading; try again.");const F=["dashboard-editor-model",i,s,o,a,r];await mh({apiClients:c,queryClient:u,environmentName:i,packageName:s,modelPath:o,source:J,expectedHash:M,invalidateOnError:[F],afterWrite:async W=>{if(y(R=>R&&{...R,source:J}),x({text:J,onFetch:O.current}),v(J),k.current=W,N(void 0),e&&$)try{await e.deleteDocument($),w(void 0),p(!1)}catch(R){Sc(R)?(w(void 0),p(!1)):N($c(R))}m(!1)},invalidate:[{queryKey:F,wait:!0},{queryKey:Dh({environmentName:i,packageName:s,versionId:a,modelPath:o})},{queryKey:["dashboard-editor-manifest"]}]}),gh(u,i,s,o)},[c,i,s,o,a,r,e,$,u,k,C,O,y,x,v,w,p,m]),B=t?.writeable===!0,H=l===!0&&!d,{savesTo:U,pinnedPackageSave:Z,writer:ne}=Th({authoritative:h,mutable:H,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!$&&B&&(!r||h),readFailed:f!==void 0});return{save:ne==="storage"?D:ne==="package"?L:void 0,savesTo:U,writer:ne,pinnedPackageSave:Z,takesWrites:H,supersedeFailure:z}}function _f(e){const{onEvent:t,onDirtyChange:n,onExit:r,kind:i,path:s,textSource:o,allowLayoutChange:a}=e,c=e.layout??(i?Yf(i):"grid"),u=c==="linear",l=o!==void 0,{environmentName:d,packageName:f,versionId:h,namesBoth:g}=Kf(e),m=("resourceUri"in e?e.dashboard:e.dashboardName)??Zf(s)??"",y="report",{apiClients:w,mutable:p,isLoadingStatus:v}=Bo(),x=Qf(),k=S.useRef(At()),C=S.useRef(t);C.current=t;const O=S.useRef(n);O.current=n;const T=Jf()?.documentStorage,$=s??uh(i??"dashboard",m),D=/\.malloynb$/i.test($)||u&&/\.malloynb$/i.test(m),z=qo({queryKey:["dashboard-editor-model",d,f,$,h,u],queryFn:()=>w.models.getModel(d,f,$,h,u?!0:void 0),enabled:g&&!D&&!l}),N=z.data?.data?.sourceText,{workspace:L,draft:B,setDraft:H,draftChecked:U,offered:Z,setOffered:ne,readFailure:J}=Yy({storage:T,layout:c,notebook:u,environmentName:d,packageName:f,modelPath:$}),{authoritative:M,blockedOnRecord:F,resume:W,setResume:R,fromDraft:_,opened:Y,setOpened:Q,openError:E,savedHashRef:j,packageBaseRef:A,setWrote:K,fetchedAtRef:V,setDirty:te,setSeen:G,held:ae,choose:ee,acceptHeld:I}=cx({workspace:L,draft:B,draftChecked:U,readFailure:J,packageText:N,fetchedAt:z.dataUpdatedAt,packageSettled:z.isSuccess&&!z.isFetching,modelPath:$,layout:c,notebook:u,noun:y,legacyFormat:D,textHeld:l,startedAt:k,onEventRef:C}),{save:re,savesTo:he,writer:we,pinnedPackageSave:X,takesWrites:P,supersedeFailure:q}=dx({storage:T,workspace:L,layout:c,notebook:u,environmentName:d,packageName:f,modelPath:$,versionId:h,apiClients:w,queryClient:x,mutable:p,textHeld:l,readFailure:J,authoritative:M,resume:W,setResume:R,setOpened:Q,setDraft:H,setOffered:ne,setSeen:G,setWrote:K,savedHashRef:j,packageBaseRef:A,fetchedAtRef:V}),oe=L?.name,pe=S.useCallback(Ct=>{C.current?.(eh(Ct,oe))},[oe]),Be=z.isError&&!Y,Zn=S.useRef(!1);S.useEffect(()=>{!Be||Zn.current||(Zn.current=!0,_o({path:$,layout:c},C.current).emit({type:"report.load_failed",surface:"edit",category:yc(z.error)}))},[Be,z.error,$,c]);const Bt=S.useCallback(Ct=>{te(Ct),O.current?.(Ct)},[te]),dn=he==="host"&&L?.description?L.description:void 0,qt=!M&&!l&&p===void 0?v?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":th({authoritative:M,mutable:P,pinnedPackageSave:X,...L?{workspace:L}:{},...J!==void 0?{readFailure:J}:{},...h!==void 0?{versionId:h}:{}}),Zr=qt===dn?"":qt;if(!g&&"resourceUri"in e)return b.jsxs(at,{severity:"error",sx:{m:2},children:["A ",y," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(E)return b.jsxs(at,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened in the builder: ",E]});if(z.isError&&!Y)return b.jsx(nh,{error:z.error,context:`Opening the ${y}`});if(!Y&&(!(l||N)||!U))return b.jsx(xc,{text:`Opening the ${y}…`});if(F)return b.jsxs(at,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened: ",J]});const Qr=B!==void 0&&B!==N;return b.jsxs(ye,{sx:{gap:2},children:[z.isError&&b.jsxs(at,{severity:"warning",children:["The ",y," could not be re-read from the server:"," ",z.error?.message,". Your edits are still here."]}),!u&&!M&&Z&&Qr&&W===void 0&&b.jsx(at,{severity:"info",action:b.jsxs(ye,{direction:"row",sx:{gap:1},children:[b.jsx(Oe,{size:"small",onClick:()=>ee(!0),children:"Resume"}),b.jsx(Oe,{size:"small",onClick:()=>ee(!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&&b.jsx(at,{severity:"warning",action:b.jsx(Oe,{size:"small",onClick:I,children:"Load it"}),children:he==="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.":he==="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."}),q!==void 0&&b.jsxs(at,{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:"," ",q]}),Y&&b.jsx(Xy,{environmentName:d,packageName:f,modelPath:$,...o?{textSource:o}:{},slug:m,modelGivens:z.data?.data?.givens,...h!==void 0?{versionId:h}:{},opened:Y,..._&&we==="package"&&Y.packageText!==void 0?{replaces:Y.packageText}:{},onSave:re,onDirtyChange:Bt,...r?{onExit:r}:{},...a!==void 0?{allowLayoutChange:a}:{},savesTo:he,...dn?{saveLabel:dn}:{},...t?{onEvent:pe}:{},note:Zr},Y.generation)]})}const px=_f,mx=Ff;function gx(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:i}=e,s="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return b.jsx(_f,{...s,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:al===void 0&&(al={});export{mx as DashboardBuilder,px as DashboardEditor,yx as MAX_SLUG_ATTEMPTS,gx as NotebookEditor,Ff as ReportBuilder,_f as ReportEditor,ky as buildCatalog,xx as createDocument,wx as createRoute,kc as locatorFor,kx as newDashboardSource,Sx as newDocumentProblem,$x as newNotebookSource,Zi as readDashboardDocument,Yi as readFailed,hx as readReportTagOfText,Cx as reportPathFor,jx as reportPathForTitle,Ex as slugFor,Ox as slugOrFallback,Xb as spliceDashboardDocument,Wo as spliceFailed,Mx as useDocumentChoices};
|
|
195
|
+
`)),{ok:!0,text:_,tiles:D.length}}const Vs=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function ox(e){const t=await Zi(e);if(!Xi(t))return{ok:!0,document:t.document};if(!t.legacyNotebook)return{ok:!1,reason:Vs(t.reason,t.line)};const n=await sx(e);if(tx(n))return{ok:!1,reason:Vs(n.refused,n.line)};const r=await Zi(n.text);return Xi(r)?{ok:!1,reason:`The converted notebook cannot be opened: ${Vs(r.reason,r.line)}`}:{ok:!0,document:r.document,conversion:{from:e,to:n.text}}}const ax="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",lx="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function cx({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:i,fetchedAt:s,packageSettled:o,modelPath:a,layout:c,notebook:u,noun:l,legacyFormat:d,textHeld:f,startedAt:h,onEventRef:g}){const m=S.useRef({path:a,layout:c});m.current={path:a,layout:c};const y=S.useRef((G,ae)=>{try{g.current?.(hh(G,{...m.current,...ae?{layout:ae}:{}}))}catch{}}),w=e?.authoritative===!0,p=w&&r!==void 0,[v,x]=S.useState(void 0),k=(w||v===!0)&&t!==void 0,[C,O]=S.useState(void 0),[T,$]=S.useState(d?ax:void 0),D=S.useRef(void 0),z=S.useRef(void 0),[N,L]=S.useState(void 0),B=S.useRef(s);B.current=s;const H=N!==void 0&&N.onFetch===s?N.text:i,Y=S.useRef(H);Y.current=H;const Z=k?t:H,[ne,J]=S.useState(!1),[M,F]=S.useState(void 0),[W,R]=S.useState(void 0),_=Z!==void 0&&Z!==W,X=C?.source,Q=_&&(ne||!w&&t!==void 0&&X===t&&t!==H)&&X!==void 0&&Z!==M,E=Q?X:_?Z:X??Z,j=Q?Z:void 0,A=S.useRef(X);A.current=X;const K=S.useRef(Z);K.current=Z;const V=S.useRef("package");V.current=k?w?"record":"draft":"package",S.useEffect(()=>{if(E===void 0||!n||p||E===A.current)return;let G=!1;const ae=Y.current,ee=K.current;return ox(E).then(I=>{if(!G){if(I.ok===!1){$(I.reason),y.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}$(void 0),D.current=void 0,z.current=ae,L(void 0),F(void 0),R(ee),O(re=>({source:E,document:I.document,...I.conversion?{conversion:I.conversion}:{},...ae!==void 0?{packageText:ae}:{},generation:(re?.generation??0)+1})),y.current({type:"report.opened",surface:"edit",from:V.current,tiles:I.document.tiles.length,durationMs:At()-h.current},I.document.layout)}}).catch(I=>{if(G)return;const re=`Could not read the ${l}: ${I instanceof Error?I.message:String(I)}`;$(re),y.current({type:"report.load_failed",surface:"edit",category:yc(I)})}),()=>{G=!0}},[E,a,n,p,u,l,f,h]),S.useEffect(()=>{d&&y.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[d]),S.useEffect(()=>{!f||!n||C||r!==void 0||(w?t===void 0&&$("the host's storage has no document at this location."):$("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,C,r,w,t]);const te=u&&!f&&!C&&n&&!k&&o&&i===void 0;return S.useEffect(()=>{te&&($(lx),y.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[te]),{authoritative:w,blockedOnRecord:p,resume:v,setResume:x,fromDraft:k,opened:C,setOpened:O,openError:T,savedHashRef:D,packageBaseRef:z,setWrote:L,fetchedAtRef:B,setDirty:J,setSeen:R,held:j,choose:G=>{h.current=At(),F(G?t:H),x(G)},acceptHeld:()=>{h.current=At(),F(j)}}}function dx({storage:e,workspace:t,layout:n,notebook:r,environmentName:i,packageName:s,modelPath:o,versionId:a,apiClients:c,queryClient:u,mutable:l,textHeld:d,readFailure:f,authoritative:h,resume:g,setResume:m,setOpened:y,setDraft:w,setOffered:p,setSeen:v,setWrote:x,savedHashRef:k,packageBaseRef:C,fetchedAtRef:O}){const T=S.useCallback(J=>t===void 0?void 0:kc(J,t.name,i,s,o),[t,i,s,o]),$=T(n),D=S.useCallback(async(J,M=n)=>{const F=T(M);if(!e||!F)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(F,J),y(W=>W&&{...W,source:J}),w(J),(h||g===!0)&&v(J),h||m(W=>W??!1)},[e,T,n,h,g,y,w,v,m]),[z,N]=S.useState(void 0),L=S.useCallback(async J=>{const M=await ph(k.current,C.current);if(M===void 0)throw new Error("The package file is still loading; try again.");const F=["dashboard-editor-model",i,s,o,a,r];await mh({apiClients:c,queryClient:u,environmentName:i,packageName:s,modelPath:o,source:J,expectedHash:M,invalidateOnError:[F],afterWrite:async W=>{if(y(R=>R&&{...R,source:J}),x({text:J,onFetch:O.current}),v(J),k.current=W,N(void 0),e&&$)try{await e.deleteDocument($),w(void 0),p(!1)}catch(R){Sc(R)?(w(void 0),p(!1)):N($c(R))}m(!1)},invalidate:[{queryKey:F,wait:!0},{queryKey:Dh({environmentName:i,packageName:s,versionId:a,modelPath:o})},{queryKey:["dashboard-editor-manifest"]}]}),gh(u,i,s,o)},[c,i,s,o,a,r,e,$,u,k,C,O,y,x,v,w,p,m]),B=t?.writeable===!0,H=l===!0&&!d,{savesTo:Y,pinnedPackageSave:Z,writer:ne}=Th({authoritative:h,mutable:H,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!$&&B&&(!r||h),readFailed:f!==void 0});return{save:ne==="storage"?D:ne==="package"?L:void 0,savesTo:Y,writer:ne,pinnedPackageSave:Z,takesWrites:H,supersedeFailure:z}}function _f(e){const{onEvent:t,onDirtyChange:n,onExit:r,kind:i,path:s,textSource:o,allowLayoutChange:a}=e,c=e.layout??(i?Xf(i):"grid"),u=c==="linear",l=o!==void 0,{environmentName:d,packageName:f,versionId:h,namesBoth:g}=Kf(e),m=("resourceUri"in e?e.dashboard:e.dashboardName)??Zf(s)??"",y="report",{apiClients:w,mutable:p,isLoadingStatus:v}=Bo(),x=Qf(),k=S.useRef(At()),C=S.useRef(t);C.current=t;const O=S.useRef(n);O.current=n;const T=Jf()?.documentStorage,$=s??uh(i??"dashboard",m),D=/\.malloynb$/i.test($)||u&&/\.malloynb$/i.test(m),z=qo({queryKey:["dashboard-editor-model",d,f,$,h,u],queryFn:()=>w.models.getModel(d,f,$,h,u?!0:void 0),enabled:g&&!D&&!l}),N=z.data?.data?.sourceText,{workspace:L,draft:B,setDraft:H,draftChecked:Y,offered:Z,setOffered:ne,readFailure:J}=Xy({storage:T,layout:c,notebook:u,environmentName:d,packageName:f,modelPath:$}),{authoritative:M,blockedOnRecord:F,resume:W,setResume:R,fromDraft:_,opened:X,setOpened:Q,openError:E,savedHashRef:j,packageBaseRef:A,setWrote:K,fetchedAtRef:V,setDirty:te,setSeen:G,held:ae,choose:ee,acceptHeld:I}=cx({workspace:L,draft:B,draftChecked:Y,readFailure:J,packageText:N,fetchedAt:z.dataUpdatedAt,packageSettled:z.isSuccess&&!z.isFetching,modelPath:$,layout:c,notebook:u,noun:y,legacyFormat:D,textHeld:l,startedAt:k,onEventRef:C}),{save:re,savesTo:he,writer:we,pinnedPackageSave:U,takesWrites:P,supersedeFailure:q}=dx({storage:T,workspace:L,layout:c,notebook:u,environmentName:d,packageName:f,modelPath:$,versionId:h,apiClients:w,queryClient:x,mutable:p,textHeld:l,readFailure:J,authoritative:M,resume:W,setResume:R,setOpened:Q,setDraft:H,setOffered:ne,setSeen:G,setWrote:K,savedHashRef:j,packageBaseRef:A,fetchedAtRef:V}),oe=L?.name,pe=S.useCallback(Ct=>{C.current?.(eh(Ct,oe))},[oe]),Be=z.isError&&!X,Zn=S.useRef(!1);S.useEffect(()=>{!Be||Zn.current||(Zn.current=!0,_o({path:$,layout:c},C.current).emit({type:"report.load_failed",surface:"edit",category:yc(z.error)}))},[Be,z.error,$,c]);const Bt=S.useCallback(Ct=>{te(Ct),O.current?.(Ct)},[te]),dn=he==="host"&&L?.description?L.description:void 0,qt=!M&&!l&&p===void 0?v?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":th({authoritative:M,mutable:P,pinnedPackageSave:U,...L?{workspace:L}:{},...J!==void 0?{readFailure:J}:{},...h!==void 0?{versionId:h}:{}}),Zr=qt===dn?"":qt;if(!g&&"resourceUri"in e)return b.jsxs(at,{severity:"error",sx:{m:2},children:["A ",y," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(E)return b.jsxs(at,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened in the builder: ",E]});if(z.isError&&!X)return b.jsx(nh,{error:z.error,context:`Opening the ${y}`});if(!X&&(!(l||N)||!Y))return b.jsx(xc,{text:`Opening the ${y}…`});if(F)return b.jsxs(at,{severity:"error",sx:{m:2},children:["This ",y," cannot be opened: ",J]});const Qr=B!==void 0&&B!==N;return b.jsxs(ye,{sx:{gap:2},children:[z.isError&&b.jsxs(at,{severity:"warning",children:["The ",y," could not be re-read from the server:"," ",z.error?.message,". Your edits are still here."]}),!u&&!M&&Z&&Qr&&W===void 0&&b.jsx(at,{severity:"info",action:b.jsxs(ye,{direction:"row",sx:{gap:1},children:[b.jsx(Oe,{size:"small",onClick:()=>ee(!0),children:"Resume"}),b.jsx(Oe,{size:"small",onClick:()=>ee(!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&&b.jsx(at,{severity:"warning",action:b.jsx(Oe,{size:"small",onClick:I,children:"Load it"}),children:he==="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.":he==="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."}),q!==void 0&&b.jsxs(at,{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:"," ",q]}),X&&b.jsx(Uy,{environmentName:d,packageName:f,modelPath:$,...o?{textSource:o}:{},slug:m,modelGivens:z.data?.data?.givens,...h!==void 0?{versionId:h}:{},opened:X,..._&&we==="package"&&X.packageText!==void 0?{replaces:X.packageText}:{},onSave:re,onDirtyChange:Bt,...r?{onExit:r}:{},...a!==void 0?{allowLayoutChange:a}:{},savesTo:he,...dn?{saveLabel:dn}:{},...t?{onEvent:pe}:{},note:Zr},X.generation)]})}const px=_f,mx=Ff;function gx(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:i}=e,s="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return b.jsx(_f,{...s,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...i!==void 0?{path:i}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:al===void 0&&(al={});export{mx as DashboardBuilder,px as DashboardEditor,yx as MAX_SLUG_ATTEMPTS,gx as NotebookEditor,Ff as ReportBuilder,_f as ReportEditor,ky as buildCatalog,xx as createDocument,wx as createRoute,kc as locatorFor,kx as newDashboardSource,Sx as newDocumentProblem,$x as newNotebookSource,Zi as readDashboardDocument,Xi as readFailed,hx as readReportTagOfText,Cx as reportPathFor,jx as reportPathForTitle,Ex as slugFor,Ox as slugOrFallback,Ub as spliceDashboardDocument,Wo as spliceFailed,Mx as useDocumentChoices};
|