@malloy-publisher/sdk 0.9.8 → 0.9.10

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.
Files changed (36) hide show
  1. package/dist/{RenderedResult-BrvrMDAP.cjs.js → RenderedResult-BcgYjkZ0.cjs.js} +1 -1
  2. package/dist/{RenderedResult-DZj-FnOJ.es.js → RenderedResult-Dp1Qdajz.es.js} +2 -2
  3. package/dist/ServerProvider-B0dUY8be.cjs.js +1 -0
  4. package/dist/{ServerProvider-B_bPAsu2.es.js → ServerProvider-CQy4jVYK.es.js} +1394 -1051
  5. package/dist/builder/index.cjs.js +61 -61
  6. package/dist/builder/index.es.js +783 -794
  7. package/dist/client/api.d.ts +412 -1
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.es.js +125 -114
  10. package/dist/components/Dashboard/DashboardView.d.ts +11 -0
  11. package/dist/components/Dashboard/useStuck.d.ts +14 -0
  12. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -5
  13. package/dist/components/Package/ContentTypeIcon.d.ts +3 -3
  14. package/dist/components/ReportBuilder/FilterStrip.d.ts +3 -1
  15. package/dist/components/ReportBuilder/TileMenu.d.ts +7 -2
  16. package/dist/index.cjs.js +9 -9
  17. package/dist/index.es.js +2112 -2063
  18. package/dist/{useCompiledDocument-x0B2RAH3.es.js → useCompiledDocument-BMPDvdFx.es.js} +2348 -2310
  19. package/dist/{useCompiledDocument-oocN5cGE.cjs.js → useCompiledDocument-UY28ITET.cjs.js} +34 -34
  20. package/package.json +1 -1
  21. package/src/components/Dashboard/DashboardView.tsx +62 -13
  22. package/src/components/Dashboard/useStuck.ts +38 -0
  23. package/src/components/DocumentCreate/newNotebook.spec.ts +8 -6
  24. package/src/components/DocumentCreate/newNotebook.ts +26 -12
  25. package/src/components/Package/ContentTypeIcon.tsx +16 -3
  26. package/src/components/Package/Package.agents.spec.tsx +76 -0
  27. package/src/components/Package/Package.tsx +44 -1
  28. package/src/components/ReportBuilder/BuilderDialogs.tsx +5 -3
  29. package/src/components/ReportBuilder/BuilderGrid.tsx +13 -3
  30. package/src/components/ReportBuilder/FilterStrip.tsx +118 -118
  31. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +0 -1
  32. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +5 -6
  33. package/src/components/ReportBuilder/ReportBuilder.tsx +1 -0
  34. package/src/components/ReportBuilder/TileMenu.tsx +8 -3
  35. package/src/components/ReportBuilder/newDashboard.spec.ts +2 -3
  36. package/dist/ServerProvider-DuEOzwPc.cjs.js +0 -1
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),O=require("../useCompiledDocument-oocN5cGE.cjs.js"),$=require("@mui/material"),k=require("react"),Be=require("../ServerProvider-DuEOzwPc.cjs.js"),ge=require("../text-entry-BJwltZiy.cjs.js"),nf=require("react-dom"),rf=require("@malloydata/malloy-tag"),ql=require("@tanstack/react-query"),sf={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function of(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,s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?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(o=>{const a=s(o);return{value:o,label:sf[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Di({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:s,onOpen:i,onChange:o,variant:a="standard"}){const l=of(t,e,n),d=k.useId();return x.jsx($.TextField,{select:!0,size:"small",variant:a,label:"Viz type",value:e,disabled:s!==void 0,onChange:u=>{const c=u.target.value;l.find(f=>f.value===c)?.disabled||o(c)},helperText:s,FormHelperTextProps:{id:d},SelectProps:{...i?{onOpen:i}:{},renderValue:u=>l.find(c=>c.value===u)?.label??String(u),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...s?{"aria-describedby":d}:{}}},sx:{minWidth:140},children:l.map(u=>x.jsx($.MenuItem,{value:u.value,disabled:u.value==="custom"||u.disabled===!0,children:x.jsx($.ListItemText,{primary:u.label,...u.reason?{secondary:u.reason}:{}})},u.value))})}function af({sources:e,source:t,view:n,onSource:r,onView:s}){const{theme:i}=Be.usePublisherTheme(),o=e.find(a=>a.name===t);return x.jsxs(x.Fragment,{children:[x.jsx($.TextField,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>x.jsxs($.MenuItem,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&x.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&x.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),x.jsxs($.Box,{children:[x.jsx($.Typography,{variant:"subtitle2",sx:{mb:.5},children:"View"}),x.jsxs($.List,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:i.border,borderRadius:1},children:[(o?.views??[]).map(a=>x.jsxs($.ListItemButton,{selected:n===a.name,onClick:()=>s(a.name),"aria-label":`View ${a.name}`,children:[x.jsx($.ListItemText,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&x.jsx($.Chip,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&x.jsx($.Typography,{variant:"body2",sx:{p:1.5,color:i.tileTitle},children:"This source declares no views."})]})]})]})}function lf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o}){const{theme:a}=Be.usePublisherTheme(),l=k.useMemo(()=>n?.sources??[],[n]),[d,u]=k.useState("query"),[c,f]=k.useState(""),[h,p]=k.useState(""),[m,b]=k.useState(""),[w,v]=k.useState("default"),[g,y]=k.useState(Math.ceil(r/2));k.useEffect(()=>{if(!e)return;u("query");const T=D=>l.some(q=>q.name===D&&q.views.length>0);f(t.sources.map(D=>D.base).find(T)??l.find(D=>D.views.length>0)?.name??""),p(""),b(""),v("default"),y(Math.ceil(r/2))},[e,t,l,r]);const _=c!==""&&h!=="",S=[c,h].filter(T=>T!==""&&!ge.isBareName(T)).map(T=>`"${T}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],E=l.find(T=>T.name===c),A=E?.views.find(T=>T.name===h);return x.jsx(O.AppDialog,{open:e,onClose:s,title:"Add a tile",description:"A tile shows one view of a source in this package.",actions:x.jsxs(x.Fragment,{children:[x.jsx($.Button,{onClick:s,children:"Cancel"}),x.jsx($.Button,{variant:"contained",disabled:d==="query"&&(!_||S!==void 0),onClick:()=>d==="text"?o():i({base:c,modelPath:E?.modelPath??"",...E?.exporters?{exporters:E.exporters}:{},view:h,...m.trim()?{label:m.trim()}:{},...w!=="default"?{chart:w,...A?{chartCarried:A.chart?[A.chart]:[]}:{}}:{},colspan:g}),children:d==="text"?"Add text":"Add tile"})]}),children:x.jsxs($.Stack,{sx:{gap:2,pt:1},children:[x.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:d,"aria-label":"Tile type",onChange:(T,D)=>{D!==null&&u(D)},children:[x.jsx($.ToggleButton,{value:"query",sx:{px:1.5},children:"Query"}),x.jsx($.ToggleButton,{value:"text",sx:{px:1.5},children:"Text"})]}),d==="text"?x.jsx($.Typography,{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."}):l.length===0?x.jsx($.Typography,{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."}):x.jsxs(x.Fragment,{children:[x.jsx(af,{sources:l,source:c,view:h,onSource:T=>{f(T),p("")},onView:T=>{p(T),v("default")}}),S&&x.jsx($.Typography,{variant:"body2",color:"error",children:S}),x.jsx(Di,{state:w,view:A,cellLabel:"new tile",variant:"outlined",...A?{}:{disabledReason:"Pick a view to choose its chart."},onChange:T=>v(T)}),x.jsx($.Stack,{direction:"row",sx:{gap:1.5},children:x.jsx($.TextField,{size:"small",label:"Title",placeholder:"Uses the view's name",value:m,onChange:T=>b(T.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}})})]})]})})}const Re=e=>e.kind==="text",xe=e=>e.kind!=="text",Kr=e=>xe(e)?e.label??e.name:e.name,Fe=e=>Re(e)?`text.${e.name}`:`${e.source}.${e.name}`,ai="self";function cf({open:e,document:t,source:n,givenNames:r,dashboards:s,onClose:i,onApply:o}){const{theme:a}=Be.usePublisherTheme(),[l,d]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(m=>m.source===n.name);d((n.dimensions??[]).map(m=>{const b=p.find(w=>w.name===m.name);return{name:m.name,expression:m.expression,to:b?.to??[],given:b?.given??""}}))},[e,n,t]);const u=(p,m)=>d(b=>b.map((w,v)=>{if(v!==p)return w;const g={...w};return m(g),g})),c=[ai,...s.filter(p=>p!==ai)],f=p=>p===ai?"This report":p,h=()=>{n&&(o(l.filter(p=>p.to.length>0).map(p=>({source:n.name,name:p.name,expression:p.expression,to:p.to,...p.given?{given:p.given}:{}}))),i())};return x.jsx(O.AppDialog,{open:e,onClose:i,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:x.jsxs(x.Fragment,{children:[x.jsx($.Button,{onClick:i,children:"Cancel"}),x.jsx($.Button,{variant:"contained",onClick:h,disabled:l.length===0,children:"Apply"})]}),children:x.jsx($.Stack,{sx:{gap:2,pt:1},children:l.length===0?x.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?x.jsxs(x.Fragment,{children:[x.jsx($.Box,{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"," ",x.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((p,m)=>x.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[x.jsxs($.Box,{sx:{minWidth:0,pt:.75},children:[x.jsx($.Typography,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:p.name}),x.jsxs($.Typography,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:p.expression,children:["is ",p.expression]})]}),x.jsx($.TextField,{select:!0,size:"small",label:"Clicks go to",value:p.to,inputProps:{"aria-label":`Where ${p.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.length===0?"Not clickable":b.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:b=>u(m,w=>{const v=b.target.value;w.to=Array.isArray(v)?v:String(v).split(",").filter(Boolean)}),children:c.map(b=>x.jsxs($.MenuItem,{value:b,children:[x.jsx($.Checkbox,{size:"small",checked:p.to.includes(b),sx:{p:0,mr:1}}),x.jsx($.ListItemText,{primary:f(b)})]},b))}),x.jsxs($.TextField,{select:!0,size:"small",label:"Sets the filter",value:p.given,disabled:p.to.length===0,inputProps:{"aria-label":`Control ${p.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:p.given===""?`Named ${p.name}, like the dimension`:void 0,onChange:b=>u(m,w=>{w.given=b.target.value}),children:[x.jsx($.MenuItem,{value:"",children:x.jsx("em",{children:"Same name as the dimension"})}),r.map(b=>x.jsx($.MenuItem,{value:b,children:b},b))]})]},p.name))})})}function uf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],s=new Set;for(const i of e.localGivens??[])s.add(i.name),r.push({name:i.name,...i.label===void 0?{}:{label:i.label},type:i.type,...i.suggest?{field:i.suggest.dimension}:{},origin:"dashboard",local:i,boundTiles:n.get(i.name)??0});for(const i of t)s.has(i.name)||(s.add(i.name),r.push({...i,origin:"model",boundTiles:n.get(i.name)??0}));for(const[i,o]of n)s.has(i)||r.push({name:i,origin:"model",boundTiles:o});return r}function _s(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function df(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function as(e,t){const n=df(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Ma(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 ff(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const hf=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function pf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=ge.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const Pa=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function Vr(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Ai=e=>xe(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function gf(e,t){return e.tiles.map(n=>{const r=(xe(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:_s(t.type)!==void 0?{op:_s(t.type)}:{}}})}function mf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Ai(i))return;const o=(i.filters??[]).filter(l=>l.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?i.filters=a:delete i.filters})}function vf(e,t){const n=(e.localGivens??[]).filter(i=>i.name!==t.name),r=(e.localGivens??[]).findIndex(i=>i.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function yf(e,t){for(const r of e.tiles){if(!xe(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Kl=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function bf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:i}){const o=k.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[d,u]=k.useState({kind:"new"}),[c,f]=k.useState(""),[h,p]=k.useState("select"),[m,b]=k.useState(""),[w,v]=k.useState(""),[g,y]=k.useState([]),[_,S]=k.useState(!1),[E,A]=k.useState(!1),T=j=>t.sources.find(F=>F.name===j.source)?.base??j.source;k.useEffect(()=>{if(e)if(A(n!==void 0),n){u({kind:"existing",name:n.name}),f(n.label??"");const j=gf(t,n);y(j);const F=j.filter(ue=>ue.include),re=new Set(F.map(ue=>ue.field));v(re.size===1?F[0].field:n.field??""),S(re.size>1)}else u({kind:"new"}),f(""),p("select"),v(""),b(new Date().toISOString().slice(0,10)),y(t.tiles.map(j=>({include:Ai(j),field:""}))),S(!1)},[e,n,t]);const D=k.useMemo(()=>[...(t.localGivens??[]).map(j=>j.name),...r.map(j=>j.name)],[t,r]),q=k.useMemo(()=>w.trim()?pf(w.trim(),D):"",[w,D]),P=d.kind==="existing"?n??r.find(j=>j.name===d.name):q?{name:q,type:Vr({name:q,label:c,kind:h,field:w}).type}:void 0,z=P?.type!==void 0&&!P.type.startsWith("filter<"),U=g.find(j=>j.include)?.op??_s(P?.type),K=(j,F)=>{A(!0),y(re=>re.map((ue,je)=>je===j?{...ue,...F}:ue))},Z=j=>{A(!0),y(F=>F.map(re=>({...re,op:j})))},J=j=>{const F=_s(j);y(re=>re.map(({op:ue,...je})=>F?{...je,op:F}:je))},ie=j=>{A(!0),u({kind:"existing",name:j.name}),v(j.field??""),J(j.type)},de=j=>{A(!0),p(j),J(Vr({name:"X",label:c,kind:j,field:w}).type)},I=t.tiles.map(Ai),V=I.filter(Boolean).length,B=g.filter((j,F)=>j.include&&I[F]).length,R=t.tiles.filter((j,F)=>(g[F]?.include??!1)&&I[F]&&xe(j)),G=R.length>0?R:t.tiles.filter((j,F)=>I[F]&&xe(j)),ne=k.useMemo(()=>{const j=new Map;let F=!1;for(const re of G){const ue=s?.(re);if(ue){F=!0;for(const je of ue)j.has(je.name)||j.set(je.name,je)}}return F?[...j.values()]:void 0},[g,t.tiles,s]),Y=(()=>{const j=w.trim();for(const F of R){const re=s?.(F);if(!re||re.some(ue=>ue.name===j))return T(F)}return R[0]?T(R[0]):t.sources[0]?.base})(),H=j=>{A(!0),y(F=>F.map((re,ue)=>({...re,include:j&&I[ue]})))},L=k.useMemo(()=>_?g:g.map(j=>({...j,field:w})),[_,g,w]),C=j=>{for(const F of G){const re=s?.(F)?.find(ue=>ue.name===j.trim());if(re?.type)return re.type}},W=j=>as(P?.type,j.type),M=(j,F)=>{if(j.trim()==="")return"Pick the field this filter compares.";const re=F?s?.(F):void 0;if(!re)return;const ue=re.find(je=>je.name===j.trim());if(!ue)return`Not a field of ${F?T(F):"the tiles' source"}.`;if(ue.type&&!as(P?.type,ue.type))return`${j.trim()} is ${Ma(ue.type)}; this filter compares ${Ma(P?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},ee=j=>{if(A(!0),v(j),l||d.kind!=="new")return;const F=C(j),re=Vr({name:"X",label:c,kind:h,field:j}).type;F&&!as(re,F)&&de(ff(F))},X=j=>{const F=t.tiles[j];return F&&xe(F)?F:void 0},le=L.map((j,F)=>j.include&&I[F]?M(j.field,X(F)):void 0),ce=le.every(j=>j===void 0),N=E?le:le.map(()=>{}),Q=E&&!_&&B>0?R.map(j=>M(w,j)).find(Boolean):void 0,me=P!==void 0&&ce&&(d.kind==="existing"||w.trim()!==""&&q!==""),se=()=>{if(!(!P||!me))if(d.kind==="new")i(P.name,L,Vr({name:P.name,label:c.trim()||Kl(P.name),kind:h,field:w.trim(),...Y?{source:Y}:{},...m?{dateDefault:m}:{}}));else if(n?.origin==="dashboard"&&n.local){const j=c.trim(),F=j!==(n.local.label??"");i(P.name,L,F?{...n.local,...j?{label:j}:{}}:void 0)}else i(P.name,L)},te=l&&a.origin==="model";return{editing:l,shown:a,fromModel:te,source:d,setSource:u,label:c,setLabel:f,kind:h,dateDefault:m,setDateDefault:b,field:w,rows:g,setRows:y,perTile:_,setPerTile:S,newName:q,target:P,valueTyped:z,commonOp:U,setRow:K,setCommonOp:Z,pickExisting:ie,pickKind:de,bindable:I,bindableCount:V,included:B,commonFields:ne,setAll:H,accepts:W,pickField:ee,rowProblems:N,commonProblem:Q,canApply:me,apply:se}}function Ra({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:l,autoFocus:d,placeholder:u,sx:c}){const f=k.useMemo(()=>(n??[]).filter(p=>r?.(p)??!0).map(p=>p.name),[n,r]),h=k.useMemo(()=>new Map((n??[]).map(p=>[p.name,p.type])),[n]);return x.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(p,m)=>t(m),value:e,onChange:(p,m)=>t(typeof m=="string"?m:""),disabled:l,disableClearable:!0,renderOption:(p,m)=>k.createElement("li",{...p,key:m},x.jsx($.Typography,{variant:"body2",sx:{flex:1},children:m}),h.get(m)&&x.jsx($.Typography,{variant:"caption",sx:{opacity:.6},children:h.get(m)?.replace(/_type$/,"")})),renderInput:p=>x.jsx($.TextField,{...p,label:s,placeholder:u,autoFocus:d,error:o,helperText:a,inputProps:{...p.inputProps,"aria-label":i}}),sx:c})}const ja=e=>e&&xe(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 xf({open:e,document:t,control:n,available:r,fieldsFor:s,onClose:i,onApply:o,onRemove:a}){const{theme:l}=Be.usePublisherTheme(),{editing:d,shown:u,fromModel:c,source:f,setSource:h,label:p,setLabel:m,kind:b,dateDefault:w,setDateDefault:v,field:g,rows:y,setRows:_,perTile:S,setPerTile:E,newName:A,target:T,valueTyped:D,commonOp:q,setRow:P,setCommonOp:z,pickExisting:U,pickKind:K,bindable:Z,bindableCount:J,included:ie,commonFields:de,setAll:I,accepts:V,pickField:B,rowProblems:R,commonProblem:G,canApply:ne,apply:Y}=bf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:o}),H=(L,C,W)=>x.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:L??">=",onChange:M=>C(M.target.value),inputProps:{"aria-label":W},sx:{width:130},children:hf.filter(M=>M.op!=="~").map(M=>x.jsx($.MenuItem,{value:M.op,children:M.label},M.op))});return x.jsx(O.AppDialog,{open:e,onClose:i,title:d?u.label??u.name:"Add a filter",description:d?x.jsxs(x.Fragment,{children:[x.jsxs($.Box,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",u.name]}),c?" · 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:x.jsxs(x.Fragment,{children:[d&&x.jsx($.Button,{color:"error",startIcon:x.jsx(O.DeleteOutlineIcon,{}),onClick:()=>a(u.name),sx:L=>({mr:"auto",color:O.dangerTextColor(L)}),children:"Remove filter"}),x.jsx($.Button,{onClick:i,children:"Cancel"}),x.jsx($.Tooltip,{title:ne||T===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:x.jsx("span",{children:x.jsx($.Button,{variant:"contained",onClick:Y,disabled:!ne,children:d?"Apply":"Add filter"})})})]}),children:x.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!d&&r.length>0&&x.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:f.kind,onChange:(L,C)=>{C==="new"?h({kind:"new"}):C==="existing"&&r[0]&&U(r[0])},"aria-label":"Where the filter comes from",children:[x.jsx($.ToggleButton,{value:"new",children:"New in this report"}),x.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&f.kind==="existing"?x.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:f.name,onChange:L=>{const C=r.find(W=>W.name===L.target.value);C&&U(C)},children:r.map(L=>x.jsxs($.MenuItem,{value:L.name,children:[L.label??L.name,x.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",L.name]})]},L.name))}):null,x.jsxs($.Stack,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!S&&x.jsx(Ra,{value:g,onChange:B,fields:de,accepts:V,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!d,error:G!==void 0,helperText:G??(!d&&A?`Declared as $${A}`:void 0),sx:{flex:1,minWidth:200}}),!c&&x.jsx($.TextField,{size:"small",label:"Label",placeholder:A?Kl(A):"",value:p,onChange:L=>m(L.target.value),inputProps:{"aria-label":"Filter label"},sx:{flex:1,minWidth:160}}),D&&!S&&H(q,z,"Comparison")]}),!d&&f.kind==="new"&&x.jsxs($.Stack,{direction:"row",sx:{gap:1.5},children:[x.jsx($.TextField,{select:!0,size:"small",label:"Filter kind",value:b,onChange:L=>K(L.target.value),inputProps:{"aria-label":"Filter kind"},slotProps:{select:{renderValue:L=>Pa.find(C=>C.kind===L)?.label??String(L)}},sx:{flex:1},children:Pa.map(L=>x.jsxs($.MenuItem,{value:L.kind,children:[L.label,x.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:L.hint})]},L.kind))}),b==="date"&&x.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:w,onChange:L=>v(L.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),x.jsxs($.Box,{children:[x.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5},children:[x.jsx($.Checkbox,{size:"small",checked:J>0&&ie===J,indeterminate:ie>0&&ie<J,disabled:J===0,onChange:L=>I(L.target.checked),inputProps:{"aria-label":"All tiles"}}),x.jsxs($.Typography,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",ie," of ",t.tiles.length," tiles"]}),x.jsx($.Button,{size:"small",onClick:()=>{S||_(L=>L.map(C=>({...C,field:g}))),E(L=>!L)},children:S?"Same field for all":"Adjust per tile"})]}),x.jsx($.Stack,{sx:{gap:S?1:0},children:t.tiles.map((L,C)=>{if(!xe(L))return null;const W=y[C],M=L.label??L.name,ee=S?R[C]:void 0;return x.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:S?"flex-start":"center",opacity:Z[C]?1:.6},children:[x.jsx($.Checkbox,{size:"small",disabled:!Z[C],checked:(W?.include??!1)&&Z[C],inputProps:{"aria-label":`Filter ${M}`},onChange:X=>P(C,{include:X.target.checked})}),x.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:S?1:0},noWrap:!0,children:M}),Z[C]?S&&x.jsxs(x.Fragment,{children:[D&&H(W?.op,X=>P(C,{op:X}),`Comparison for ${M}`),x.jsx(Ra,{value:W?.field??"",onChange:X=>P(C,{field:X}),fields:s?.(L),accepts:V,label:"Field",ariaLabel:`Field for ${M}`,disabled:!W?.include,error:ee!==void 0,helperText:ee,sx:{width:220}})]}):x.jsx($.Tooltip,{title:ja(t.tiles[C]).reason,children:x.jsx($.Typography,{variant:"caption",sx:{color:l.tileTitle},children:ja(t.tiles[C]).label})})]},`${L.source}.${L.name}`)})}),ie===0&&x.jsx($.Typography,{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 wf=O.createSvgIcon(x.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 Vl(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch:u=>i(c=>{if(c===void 0)return c;const f=structuredClone(c);return u(f),f}),apply:u=>{if(s===void 0)return;const c=structuredClone(s);u(c),i(c),JSON.stringify(c)!==JSON.stringify(e)&&n(c)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const _f=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.`,kf="This tile's view is declared on its source, so its chart is set in the model.";function Sf({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:s,removeBlocked:i,onDrills:o,view:a}){const l=k.useId(),{theme:d}=Be.usePublisherTheme(),{draft:u,apply:c,close:f,discard:h}=Vl(t,e!==null,r,n),p=u!==void 0&&xe(u)?u:void 0,m=p!==void 0&&p.declaration.kind!=="inherited",b=g=>c(y=>{xe(y)&&g(y)}),w=k.useRef(void 0),v=e!==null;return k.useEffect(()=>{v&&(w.current=t&&xe(t)?t.chart:void 0)},[v]),x.jsx($.Popover,{open:e!==null&&u!==void 0,anchorEl:e,onClose:f,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:u&&x.jsxs($.Stack,{sx:{gap:1.5},children:[x.jsx($.Typography,{variant:"overline",sx:{color:d.tileTitle,lineHeight:1.5},children:p?`${p.source} → ${p.name}`:`Text · ${u.name}`}),p&&m&&x.jsx(x.Fragment,{children:x.jsx(Di,{state:p.chart??"default",view:a,cellLabel:`${p.source} ${p.name}`,...p.chart==="custom"?{disabledReason:_f(p.chartLines)}:{},onChange:g=>b(y=>{const _=w.current;g===(_??"default")?(_===void 0?delete y.chart:y.chart=_,delete y.chartCarried):(y.chart=g,a?y.chartCarried=a.chart?[a.chart]:[]:delete y.chartCarried)})})}),p&&!m&&x.jsxs(x.Fragment,{children:[x.jsx($.Typography,{variant:"body2",sx:{color:d.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),x.jsx(Di,{state:"default",view:a,cellLabel:`${p.source} ${p.name}`,disabledReason:kf,onChange:()=>{}})]}),p?.declaration.kind==="opaque"&&x.jsxs($.Typography,{variant:"body2",sx:{color:d.tileTitle},children:["Its body is ",p.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),x.jsxs($.Stack,{direction:"row",sx:{justifyContent:"space-between"},children:[m?x.jsx($.Button,{size:"small",startIcon:x.jsx(wf,{}),"aria-haspopup":"dialog",onClick:()=>{f(),o()},children:"Drill"}):x.jsx("span",{}),x.jsx($.Button,{color:"error",size:"small",startIcon:x.jsx(O.DeleteOutlineIcon,{}),"aria-disabled":i!==void 0||void 0,"aria-describedby":i!==void 0?l:void 0,disableRipple:i!==void 0,sx:g=>({color:O.dangerTextColor(g),...i!==void 0?{opacity:.5,cursor:"default"}:{}}),onClick:()=>{i===void 0&&(h(),s())},children:"Delete"})]}),i!==void 0&&x.jsx($.Typography,{id:l,variant:"caption",sx:{color:d.tileTitle},children:i})]})})}function $f({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,confirmConversion:l,exitDialog:d}){const{filterDialog:u,setFilterDialog:c}=s,{menu:f,setMenu:h}=i,p=f===void 0?void 0:e.document.tiles[f.index],m=p&&xe(p)?p:void 0,b=(()=>{if(!m||!t)return;const w=e.document.sources.find(g=>g.name===m.source)?.base??m.source,v=m.declaration.kind==="reference"?m.declaration.from:m.name;return t.sources.find(g=>g.name===w)?.views.find(g=>g.name===v)})();return x.jsxs(x.Fragment,{children:[x.jsx(xf,{open:u!==void 0,document:e.document,...u?.control?{control:u.control}:{},available:s.available,...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>c(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),x.jsx(Sf,{anchor:f?.anchor??null,tile:f===void 0?void 0:e.document.tiles[f.index],onClose:()=>h(void 0),onCommit:w=>{const v=f?.index;v!==void 0&&e.update(g=>{g.tiles[v]=w})},onRemove:()=>{f!==void 0&&i.removeTile(f.index)},...e.document.tiles.length===1&&e.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},view:b,onDrills:()=>{a(m?.source)}}),x.jsx(cf,{open:o!==void 0,document:e.document,source:e.document.sources.find(w=>w.name===o),givenNames:s.controlList.map(w=>w.name),dashboards:r??[],onClose:()=>a(void 0),onApply:w=>e.update(v=>{const y=[...(v.drills??[]).filter(_=>_.source!==o),...w];y.length===0?delete v.drills:v.drills=y})}),x.jsx(O.AppDialog,{open:l!==void 0,onClose:()=>l?.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:x.jsxs(x.Fragment,{children:[x.jsx($.Button,{onClick:()=>l?.stop(),children:"Cancel"}),x.jsx($.Button,{variant:"contained",onClick:()=>l?.go(),children:"Convert and save"})]}),children:null}),x.jsx(O.UnsavedChangesDialog,{...d}),x.jsx(lf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText})]})}var Tf=Symbol.for("preact-signals");function qs(){if(vt>1)vt--;else{var e,t=!1;for((function(){var s=Ss;for(Ss=void 0;s!==void 0;){var i=s.S;if(i.v===s.v)for(var o=i.t;o!==void 0;o=o.x)o.i===s.i&&(o.i=i.i);s=s.o}})();dr!==void 0;){var n=dr;for(dr=void 0,ks++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Hl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ks=0,vt--,t)throw e}}function Te(e){if(vt>0)return e();Mi=++Of,vt++;try{return e()}finally{qs()}}var ur,we=void 0;function fe(e){var t=we,n=ur;we=void 0,ur=void 0;try{return e()}finally{we=t,ur=n}}var dr=void 0,vt=0,ks=0,Of=0,Mi=0,Ss=void 0,$s=0;function Ul(e){if(we!==void 0){var t=e.n;if(t===void 0||t.t!==we)return t={i:0,S:e,p:we.s,n:void 0,t:we,e:void 0,x:void 0,r:t},we.s!==void 0&&(we.s.n=t),we.s=t,e.n=t,32&we.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=we.s,t.n=void 0,we.s.n=t,we.s=t),t}}function 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=Tf;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:fe(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&&fe(function(){var s;(s=t.Z)==null||s.call(t)}))}};Ve.prototype.subscribe=function(e){var t=this;return rt(function(){var n=t.value;fe(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 fe(function(){return e.value})};Object.defineProperty(Ve.prototype,"value",{get:function(){var e=Ul(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ks>100)throw new Error("Cycle detected");(function(n){vt!==0&&ks===0&&n.l!==Mi&&(n.l=Mi,Ss={S:n,v:n.v,i:n.i,o:Ss})})(this),this.v=e,this.i++,$s++,vt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{qs()}}}});function En(e,t){return new Ve(e,t)}function Hl(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 Xl(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 Yl(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 Yt(e,t){Ve.call(this,void 0,t),this.x=e,this.s=void 0,this.g=$s-1,this.f=4}Yt.prototype=new Ve;Yt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===$s))return!0;if(this.g=$s,this.f|=1,this.i>0&&!Hl(this))return this.f&=-2,!0;var e=we;try{Xl(this),we=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return we=e,Yl(this),this.f&=-2,!0};Yt.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)};Yt.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)}};Yt.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(Yt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Ul(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function La(e,t){return new Yt(e,t)}function Zl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){vt++;var n=we;we=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,_o(e),r}finally{we=n,qs()}}}function _o(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Zl(e)}function Ef(e){if(we!==this)throw new Error("Out-of-order effect");Yl(this),we=e,this.f&=-2,8&this.f&&_o(this),qs()}function Cn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,ur&&ur.push(this)}Cn.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()}};Cn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Zl(this),Xl(this),vt++;var e=we;return we=this,Ef.bind(this,e)};Cn.prototype.N=function(){2&this.f||(this.f|=2,this.u=dr,dr=this)};Cn.prototype.d=function(){this.f|=8,1&this.f||_o(this)};Cn.prototype.dispose=function(){this.d()};function rt(e,t){var n=new Cn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Cf=Object.create,ko=Object.defineProperty,If=Object.defineProperties,Df=Object.getOwnPropertyDescriptor,Af=Object.getOwnPropertyDescriptors,Na=Object.getOwnPropertySymbols,Mf=Object.prototype.hasOwnProperty,Pf=Object.prototype.propertyIsEnumerable,Rf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),In=e=>{throw TypeError(e)},Pi=(e,t,n)=>t in e?ko(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jf=(e,t)=>{for(var n in t||(t={}))Mf.call(t,n)&&Pi(e,n,t[n]);if(Na)for(var n of Na(t))Pf.call(t,n)&&Pi(e,n,t[n]);return e},Lf=(e,t)=>If(e,Af(t)),Fa=(e,t)=>ko(e,"name",{value:t,configurable:!0}),Nf=e=>{var t;return[,,,Cf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],Hn=e=>e!==void 0&&typeof e!="function"?In("Function expected"):e,Ff=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:i=>n._?In("Already initialized"):s.push(Hn(i||null))}),Jl=(e,t)=>Pi(t,Rf("metadata"),e[3]),Lt=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},Dn=(e,t,n,r,s,i)=>{var o,a,l,d,u,c=t&7,f=!!(t&8),h=!!(t&16),p=c>3?e.length+1:c?f?1:2:0,m=Ql[c+5],b=c>3&&(e[p-1]=[]),w=e[p]||(e[p]=[]),v=c&&(!h&&!f&&(s=s.prototype),c<5&&(c>3||!h)&&Df(c<4?s:{get[n](){return Qe(this,i)},set[n](y){return Tt(this,i,y)}},n));c?h&&c<4&&Fa(i,(c>2?"set ":c>1?"get ":"")+n):Fa(s,n);for(var g=r.length-1;g>=0;g--)d=Ff(c,n,l={},e[3],w),c&&(d.static=f,d.private=h,u=d.access={has:h?y=>zf(s,y):y=>n in y},c^3&&(u.get=h?y=>(c^1?Qe:Wf)(y,s,c^4?i:v.get):y=>y[n]),c>2&&(u.set=h?(y,_)=>Tt(y,s,_,c^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(c?c<4?h?i:v[m]:c>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,c^4||a===void 0?Hn(a)&&(c>4?b.unshift(a):c?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?In("Object expected"):(Hn(o=a.get)&&(v.get=o),Hn(o=a.set)&&(v.set=o),Hn(o=a.init)&&b.unshift(o));return c||Jl(e,s),v&&ko(s,n,v),h?c^4?i:v:s},So=(e,t,n)=>t.has(e)||In("Cannot "+n),zf=(e,t)=>Object(t)!==t?In('Cannot use the "in" operator on this value'):e.has(t),Qe=(e,t,n)=>(So(e,t,"read from private field"),n?n.call(e):t.get(e)),Xn=(e,t,n)=>t.has(e)?In("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Tt=(e,t,n,r)=>(So(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Wf=(e,t,n)=>(So(e,t,"access private method"),n);function Ri(e,t){if(t){let n;return La(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return La(e)}function it(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((r,s)=>!it(r,t[s]));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=>!it(e[i],t[i]))}return!1}function he({get:e},t){return{init(n){return En(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=Ri(e.bind(this)),n.set(this,r)),r.value}}function li(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Lf(jf({},s),{enumerable:e}))})}}function Dr(...e){const t=e.map(n=>rt(n));return()=>t.forEach(n=>n())}var ec,tc,nc,rc,sc,ic,Ge,$o,ci,ji,Li,ze,To,ui,oc,Ni,Oo,di,Fi,zi;ic=[he],sc=[he],rc=[he],nc=[li()],tc=[li()],ec=[li()];var Zt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Lt(Ge,5,this),Xn(this,ze),Xn(this,$o,Lt(Ge,8,this)),Lt(Ge,11,this),Xn(this,To,Lt(Ge,12,this)),Lt(Ge,15,this),Xn(this,Oo,Lt(Ge,16,this)),Lt(Ge,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return Qe(this,ze,Fi)}get initial(){return Qe(this,ze,ji)}get previous(){return Qe(this,ze,oc)}set current(e){const t=fe(()=>Qe(this,ze,Fi));e&&t&&this.equals(t,e)||Te(()=>{Qe(this,ze,ji)||Tt(this,ze,e,Li),Tt(this,ze,t,Ni),Tt(this,ze,e,zi)})}reset(e=this.defaultValue){Te(()=>{Tt(this,ze,void 0,Ni),Tt(this,ze,e,Li),Tt(this,ze,e,zi)})}};Ge=Nf();$o=new WeakMap;ze=new WeakSet;To=new WeakMap;Oo=new WeakMap;ci=Dn(Ge,20,"#initial",ic,ze,$o),ji=ci.get,Li=ci.set;ui=Dn(Ge,20,"#previous",sc,ze,To),oc=ui.get,Ni=ui.set;di=Dn(Ge,20,"#current",rc,ze,Oo),Fi=di.get,zi=di.set;Dn(Ge,2,"current",nc,Zt);Dn(Ge,2,"initial",tc,Zt);Dn(Ge,2,"previous",ec,Zt);Jl(Ge,Zt);function fi(e){return fe(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Nt,Bf=class{constructor(){Xn(this,Nt,new WeakMap)}get(e,t){var n;return e?(n=Qe(this,Nt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return Qe(this,Nt).has(e)||Qe(this,Nt).set(e,new Map),(r=Qe(this,Nt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=Qe(this,Nt).get(e))==null?void 0:t.clear():void 0}};Nt=new WeakMap;var Gf=Object.create,ac=Object.defineProperty,qf=Object.getOwnPropertyDescriptor,za=Object.getOwnPropertySymbols,Kf=Object.prototype.hasOwnProperty,Vf=Object.prototype.propertyIsEnumerable,lc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ks=e=>{throw TypeError(e)},Wa=Math.pow,Wi=(e,t,n)=>t in e?ac(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Uf=(e,t)=>{for(var n in t||(t={}))Kf.call(t,n)&&Wi(e,n,t[n]);if(za)for(var n of za(t))Vf.call(t,n)&&Wi(e,n,t[n]);return e},Hf=e=>{var t;return[,,,Gf((t=e?.[lc("metadata")])!=null?t:null)]},cc=["class","method","getter","setter","accessor","field","value","get","set"],uc=e=>e!==void 0&&typeof e!="function"?Ks("Function expected"):e,Xf=(e,t,n,r,s)=>({kind:cc[e],name:t,metadata:r,addInitializer:i=>n._?Ks("Already initialized"):s.push(uc(i||null))}),Yf=(e,t)=>Wi(t,lc("metadata"),e[3]),Zf=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},dc=(e,t,n,r,s,i)=>{for(var o,a,l,d,u=t&7,c=!1,f=!1,h=2,p=cc[u+5],m=e[h]||(e[h]=[]),b=(s=s.prototype,qf(s,n)),w=r.length-1;w>=0;w--)l=Xf(u,n,a={},e[3],m),l.static=c,l.private=f,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[w])(b[p],l),a._=1,uc(o)&&(b[p]=o);return b&&ac(s,n,b),s},fc=(e,t,n)=>t.has(e)||Ks("Cannot "+n),Qf=(e,t,n)=>(fc(e,t,"read from private field"),t.get(e)),Jf=(e,t,n)=>t.has(e)?Ks("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),eh=(e,t,n,r)=>(fc(e,t,"write to private field"),t.set(e,n),n),Je=class Bi{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Bi(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 Bi(t,n)}},ht=class Ft{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,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:s,width:i,height:o,scale:a}=this,l=new Ft(s+t,r+n,i,o);return l.scale=Uf({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:i,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:i,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Je((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Ft))return!1;const{left:n,top:r,width:s,height:i}=this;return n===t.left&&r===t.top&&s===t.width&&i===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:i}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=i}intersectionArea(t){return t instanceof Ft?th(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:s}){return new Ft(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],l=o==="x"?i.left:i.top,d=o==="x"?i.width:i.height;return a=="start"?l:a=="end"?l+d:l+d/2};return Je.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Ft.from(t).intersectionRatio(Ft.from(n))}};function th(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),o=s-r,a=i-n;return r<s&&n<i?o*a:0}var hc,pc,Gi,ls,Ar,Vs=class extends(Gi=Zt,pc=[Ee],hc=[Ee],Gi){constructor(t){const n=Je.from(t);super(n,(r,s)=>Je.equals(r,s)),Zf(Ar,5,this),Jf(this,ls,0),this.velocity={x:0,y:0}}get delta(){return Je.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Je.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-Qf(this,ls),a=l=>Math.round(l/o*100);Te(()=>{eh(this,ls,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Je.from(t)),this.velocity={x:0,y:0}}};Ar=Hf(Gi);ls=new WeakMap;dc(Ar,2,"delta",pc,Vs);dc(Ar,2,"direction",hc,Vs);Yf(Ar,Vs);function qi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Wa(r,2)+Wa(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var gc=(e=>(e.Horizontal="x",e.Vertical="y",e))(gc||{}),mc=Object.values(gc),nh=Object.create,Eo=Object.defineProperty,rh=Object.defineProperties,sh=Object.getOwnPropertyDescriptor,ih=Object.getOwnPropertyDescriptors,Ts=Object.getOwnPropertySymbols,vc=Object.prototype.hasOwnProperty,yc=Object.prototype.propertyIsEnumerable,bc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),An=e=>{throw TypeError(e)},Ki=(e,t,n)=>t in e?Eo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Co=(e,t)=>{for(var n in t||(t={}))vc.call(t,n)&&Ki(e,n,t[n]);if(Ts)for(var n of Ts(t))yc.call(t,n)&&Ki(e,n,t[n]);return e},Io=(e,t)=>rh(e,ih(t)),Ba=(e,t)=>Eo(e,"name",{value:t,configurable:!0}),xc=(e,t)=>{var n={};for(var r in e)vc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ts)for(var r of Ts(e))t.indexOf(r)<0&&yc.call(e,r)&&(n[r]=e[r]);return n},Mn=e=>{var t;return[,,,nh((t=e?.[bc("metadata")])!=null?t:null)]},wc=["class","method","getter","setter","accessor","field","value","get","set"],Yn=e=>e!==void 0&&typeof e!="function"?An("Function expected"):e,oh=(e,t,n,r,s)=>({kind:wc[e],name:t,metadata:r,addInitializer:i=>n._?An("Already initialized"):s.push(Yn(i||null))}),Qt=(e,t)=>Ki(t,bc("metadata"),e[3]),ae=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},pe=(e,t,n,r,s,i)=>{var o,a,l,d,u,c=t&7,f=!!(t&8),h=!!(t&16),p=c>3?e.length+1:c?f?1:2:0,m=wc[c+5],b=c>3&&(e[p-1]=[]),w=e[p]||(e[p]=[]),v=c&&(!h&&!f&&(s=s.prototype),c<5&&(c>3||!h)&&sh(c<4?s:{get[n](){return Oe(this,i)},set[n](y){return Ye(this,i,y)}},n));c?h&&c<4&&Ba(i,(c>2?"set ":c>1?"get ":"")+n):Ba(s,n);for(var g=r.length-1;g>=0;g--)d=oh(c,n,l={},e[3],w),c&&(d.static=f,d.private=h,u=d.access={has:h?y=>ah(s,y):y=>n in y},c^3&&(u.get=h?y=>(c^1?Oe:_c)(y,s,c^4?i:v.get):y=>y[n]),c>2&&(u.set=h?(y,_)=>Ye(y,s,_,c^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(c?c<4?h?i:v[m]:c>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,c^4||a===void 0?Yn(a)&&(c>4?b.unshift(a):c?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?An("Object expected"):(Yn(o=a.get)&&(v.get=o),Yn(o=a.set)&&(v.set=o),Yn(o=a.init)&&b.unshift(o));return c||Qt(e,s),v&&Eo(s,n,v),h?c^4?i:v:s},Do=(e,t,n)=>t.has(e)||An("Cannot "+n),ah=(e,t)=>Object(t)!==t?An('Cannot use the "in" operator on this value'):e.has(t),Oe=(e,t,n)=>(Do(e,t,"read from private field"),n?n.call(e):t.get(e)),ve=(e,t,n)=>t.has(e)?An("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,r)=>(Do(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),_c=(e,t,n)=>(Do(e,t,"access private method"),n);function kc(e,t){return{plugin:e,options:t}}function Mr(e){return t=>kc(e,t)}function vr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Sc,yr,Ao,cs;Sc=[he];var We=class{constructor(e,t){this.manager=e,this.options=t,ve(this,Ao,ae(yr,8,this,!1)),ae(yr,11,this),ve(this,cs,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return fe(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=rt(e.bind(this));return Oe(this,cs).add(t),t}destroy(){Oe(this,cs).forEach(e=>e())}static configure(e){return kc(this,e)}};yr=Mn(null);Ao=new WeakMap;cs=new WeakMap;pe(yr,4,"disabled",Sc,We,Ao);Qt(yr,We);var Pr=class extends We{},us,hi=class{constructor(e){this.manager=e,this.instances=new Map,ve(this,us,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(vr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Oe(this,us))if(!n.includes(r)){if(r.prototype instanceof Pr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);Ye(this,us,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()}};us=new WeakMap;function lh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Ur=[],cn,un,ch=class extends We{constructor(e){super(e),ve(this,cn),ve(this,un),this.computeCollisions=this.computeCollisions.bind(this),Ye(this,un,En(Ur)),this.destroy=Dr(()=>{const t=this.computeCollisions(),n=fe(()=>this.manager.dragOperation.position.current);if(t!==Ur){const r=Oe(this,cn);if(Ye(this,cn,n),r&&n.x==r.x&&n.y==r.y)return}else Ye(this,cn,void 0);Oe(this,un).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){fe(()=>{e?Oe(this,un).value=this.computeCollisions():Ye(this,cn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Ur;const a=[],l=[];for(const d of e??n.droppables){if(d.disabled||s&&!d.accepts(s))continue;const u=t??d.collisionDetector;if(!u)continue;l.push(d),d.shape;const c=fe(()=>u({droppable:d,dragOperation:r}));c&&(d.collisionPriority!=null&&(c.priority=d.collisionPriority),a.push(c))}return l.length===0?Ur:(a.sort(lh),a)}get collisions(){return Oe(this,un).value}};cn=new WeakMap;un=new WeakMap;var $c,Tc,Oc,Mo,Ec,ot,Po,mn,Ro,jo;Oc=[he],Tc=[he],$c=[he];var bt=class zt{constructor(t,n){ve(this,Po,ae(ot,8,this)),ae(ot,11,this),ve(this,mn),ve(this,Ro,ae(ot,12,this)),ae(ot,15,this),ve(this,jo,ae(ot,16,this)),ae(ot,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let l=s;Ye(this,mn,En(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var d;return[()=>{const{id:u,manager:c}=this;if(u!==l)return l=u,c?.registry.register(this),()=>c?.registry.unregister(this)},...(d=r?.())!=null?d:[]]},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=Oe(this,mn).value;return(n=(t=zt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=zt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Oe(this,mn).peek();t!==s&&(zt.pendingIdChanges||(zt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return _c(i=zt,Mo,Ec).call(i)})),zt.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)}};ot=Mn(null);Mo=new WeakSet;Ec=function(){const e=bt.pendingIdChanges;bt.pendingIdChanges=null,e&&Te(()=>{for(const[t,n]of e)Oe(t,mn).value=n})};Po=new WeakMap;mn=new WeakMap;Ro=new WeakMap;jo=new WeakMap;pe(ot,4,"manager",Oc,bt,Po);pe(ot,4,"data",Tc,bt,Ro);pe(ot,4,"disabled",$c,bt,jo);ve(bt,Mo);Qt(ot,bt);bt.pendingIdChanges=null;var Us=bt,Ga=class{constructor(){this.map=En(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Dr(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[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){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Cc,Ic,Dc,Ac,Mc,Pc,Vi,qe,Lo,No,Fo,pt=class extends(Vi=Us,Pc=[he],Mc=[he],Ac=[he],Dc=[Ee],Ic=[Ee],Cc=[Ee],Vi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:l}=r,d=xc(r,["modifiers","type","sensors","plugins","effects"]);super(Io(Co({},d),{effects:()=>{var u;return[...(u=l?.())!=null?u:[],()=>{const{manager:c,plugins:f}=this;if(!(!c||!f))for(const h of f){const{plugin:p}=vr(h);c.registry.plugins.register(p)}}]}}),n),ae(qe,5,this),ve(this,Lo,ae(qe,8,this)),ae(qe,11,this),ve(this,No,ae(qe,12,this)),ae(qe,15,this),ve(this,Fo,ae(qe,16,this,this.isDragSource?"dragging":"idle")),ae(qe,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=d.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=vr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};qe=Mn(Vi);Lo=new WeakMap;No=new WeakMap;Fo=new WeakMap;pe(qe,4,"type",Pc,pt,Lo);pe(qe,4,"modifiers",Mc,pt,No);pe(qe,4,"status",Ac,pt,Fo);pe(qe,2,"isDropping",Dc,pt);pe(qe,2,"isDragging",Ic,pt);pe(qe,2,"isDragSource",Cc,pt);Qt(qe,pt);var Rc,jc,Lc,Nc,Fc,zc,Ui,Me,zo,Wo,Bo,Go,qo,gt=class extends(Ui=Us,zc=[he],Fc=[he],Nc=[he],Lc=[he],jc=[he],Rc=[Ee],Ui){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,l=xc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ae(Me,5,this),ve(this,zo,ae(Me,8,this)),ae(Me,11,this),ve(this,Wo,ae(Me,12,this)),ae(Me,15,this),ve(this,Bo,ae(Me,16,this)),ae(Me,19,this),ve(this,Go,ae(Me,20,this)),ae(Me,23,this),ve(this,qo,ae(Me,24,this)),ae(Me,27,this),this.accept=s,this.collisionDetector=i,this.collisionPriority=o,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Me=Mn(Ui);zo=new WeakMap;Wo=new WeakMap;Bo=new WeakMap;Go=new WeakMap;qo=new WeakMap;pe(Me,4,"accept",zc,gt,zo);pe(Me,4,"type",Fc,gt,Wo);pe(Me,4,"collisionDetector",Nc,gt,Bo);pe(Me,4,"collisionPriority",Lc,gt,Go);pe(Me,4,"shape",jc,gt,qo);pe(Me,2,"isDropTarget",Rc,gt);Qt(Me,gt);var uh=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 s of r)s(...t)}},dh=class extends uh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function ds(e,t=!0){let n=!1;return Io(Co({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var fh=class extends Pr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Dr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||Us.pendingIdChanges)return;const o=ds({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;fe(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Pn=(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))(Pn||{}),Rn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Rn||{}),Wc,Bc,Gc,qc,Kc,Vc,Uc,nt,Ko;Uc=[he],Vc=[Ee],Kc=[Ee],qc=[Ee],Gc=[Ee],Bc=[Ee],Wc=[Ee];var wt=class{constructor(){ae(nt,5,this),ve(this,Ko,ae(nt,8,this,"idle")),ae(nt,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}};nt=Mn(null);Ko=new WeakMap;pe(nt,4,"value",Uc,wt,Ko);pe(nt,2,"current",Vc,wt);pe(nt,2,"idle",Kc,wt);pe(nt,2,"initializing",qc,wt);pe(nt,2,"initialized",Gc,wt);pe(nt,2,"dragging",Bc,wt);pe(nt,2,"dropped",Wc,wt);Qt(nt,wt);var hh=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 fe(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=ds({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return fe(()=>{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 r=new AbortController,{event:s,coordinates:i}=e;Te(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=ds({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&Te(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return fe(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=ds({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,l,d,u,c;if(o.defaultPrevented)return;const f=(c=e.to)!=null?c:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((u=(d=e.by)==null?void 0:d.y)!=null?u:0)};r.position.current=f})})}stop(e={}){return fe(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const l={resume:()=>{},abort:()=>{}};return i=new Promise((d,u)=>{l.resume=d,l.abort=u}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=fe(()=>{var u;return((u=r.source)==null?void 0:u.status)==="dropping"}),d=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:u}=r,c=rt(()=>{u?.status==="idle"&&(c(),d())})}else this.manager.renderer.rendering.then(d)})};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}),i?i.then(a).catch(()=>r.reset()):a()})}},_n=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}},ph=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)}},fs,Hc=class{constructor(e){this.options=e,ve(this,fs)}set controller(e){Ye(this,fs,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Oe(this,fs))==null||t.activate(e)}};fs=new WeakMap;var qa=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},gh=class{constructor(e){this.draggables=new Ga,this.droppables=new Ga,this.plugins=new hi(e),this.sensors=new hi(e),this.modifiers=new hi(e)}register(e,t){if(e instanceof pt)return this.draggables.register(e.id,e);if(e instanceof gt)return this.droppables.register(e.id,e);if(e.prototype instanceof qa)return this.modifiers.register(e,t);if(e.prototype instanceof _n)return this.sensors.register(e,t);if(e.prototype instanceof We)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Us)return e instanceof pt?this.draggables.unregister(e.id,e):e instanceof gt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof qa)return this.modifiers.unregister(e);if(e.prototype instanceof _n)return this.sensors.unregister(e);if(e.prototype instanceof We)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()}},Xc,Yc,Zc,Qc,Jc,eu,tu,nu,ru,Zn,hs,dn,$e,Vo,Uo,Ho,Xo,Yo,Qn;ru=[Ee],nu=[he],tu=[he],eu=[he],Jc=[he],Qc=[he],Zc=[Ee],Yc=[Ee],Xc=[Ee];var ct=class{constructor(e){ae($e,5,this),ve(this,Zn),ve(this,hs),ve(this,dn,new Zt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new wt,ve(this,Vo,ae($e,8,this,!1)),ae($e,11,this),ve(this,Uo,ae($e,12,this,null)),ae($e,15,this),ve(this,Ho,ae($e,16,this,null)),ae($e,19,this),ve(this,Xo,ae($e,20,this,null)),ae($e,23,this),ve(this,Yo,ae($e,24,this,[])),ae($e,27,this),this.position=new Vs({x:0,y:0}),ve(this,Qn,{x:0,y:0}),Ye(this,Zn,e)}get shape(){const{current:e,initial:t,previous:n}=Oe(this,dn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Oe(this,dn).current=e:Oe(this,dn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Oe(this,Zn).registry.draggables.get(t);return n&&Ye(this,hs,n),(e=n??Oe(this,hs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Oe(this,Zn).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(Io(Co({},this.snapshot()),{transform:n}));return Ye(this,Qn,n),n}snapshot(){return fe(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Oe(this,Qn),shape:this.shape?fi(this.shape):null,position:fi(this.position),status:fi(this.status),canceled:this.canceled}))}reset(){Te(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Oe(this,dn).reset(),this.position.reset({x:0,y:0}),Ye(this,Qn,{x:0,y:0}),this.modifiers=[]})}};$e=Mn(null);Zn=new WeakMap;hs=new WeakMap;dn=new WeakMap;Vo=new WeakMap;Uo=new WeakMap;Ho=new WeakMap;Xo=new WeakMap;Yo=new WeakMap;Qn=new WeakMap;pe($e,2,"shape",ru,ct);pe($e,4,"canceled",nu,ct,Vo);pe($e,4,"activatorEvent",tu,ct,Uo);pe($e,4,"sourceIdentifier",eu,ct,Ho);pe($e,4,"targetIdentifier",Jc,ct,Xo);pe($e,4,"modifiers",Qc,ct,Yo);pe($e,2,"source",Zc,ct);pe($e,2,"target",Yc,ct);pe($e,2,"transform",Xc,ct);Qt($e,ct);var mh={get rendering(){return Promise.resolve()}};function lt(e,t){return typeof e=="function"?e(t):e??t}var vh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=lt(r.plugins,[]),i=lt(r.sensors,[]),o=lt(r.modifiers,[]),a=(n=r.renderer)!=null?n:mh,l=new dh(this),d=new gh(this);this.registry=d,this.monitor=l,this.renderer=a,this.actions=new hh(this),this.dragOperation=new ct(this),this.collisionObserver=new ch(this),this.plugins=[fh,...s],this.modifiers=o,this.sensors=i;const{destroy:u}=this,c=Dr(()=>{var f,h,p;const m=fe(()=>this.dragOperation.modifiers),b=this.modifiers;for(const w of m)b.includes(w)||w.destroy();this.dragOperation.modifiers=(p=(h=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:h.map(w=>{const{plugin:v,options:g}=vr(w);return new v(this,g)}))!=null?p:b});this.destroy=()=>{c(),u()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},su=e=>{throw TypeError(e)},Zo=(e,t,n)=>t.has(e)||su("Cannot "+n),oe=(e,t,n)=>(Zo(e,t,"read from private field"),t.get(e)),Ue=(e,t,n)=>t.has(e)?su("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Xe=(e,t,n,r)=>(Zo(e,t,"write to private field"),t.set(e,n),n),iu=(e,t,n)=>(Zo(e,t,"access private method"),n);function Hs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function ou(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(Hs(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function Xs(e){const{width:t,height:n,top:r,left:s,bottom:i,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:i,right:o}}function Qo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Rr(e){return"nodeType"in e}function Ze(e){var t,n,r;return e?Qo(e)?e:Rr(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 Jo(e){const{Document:t}=Ze(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function At(e){return!e||Qo(e)?!1:e instanceof Ze(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function au(e){return e instanceof Ze(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function jn(e){return e?Qo(e)?e.document:Rr(e)?Jo(e)?e:At(e)||au(e)?e.ownerDocument:document:document:document}function yh(e){var t,n,r,s;const{documentElement:i}=jn(e),o=Ze(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,l=(n=o?.height)!=null?n:i.clientHeight,d=(r=o?.offsetTop)!=null?r:0,u=(s=o?.offsetLeft)!=null?s:0;return{top:d,left:u,right:u+a,bottom:d+l,width:a,height:l}}function bh(e,t){if(xh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function xh(e){return e.tagName==="DETAILS"}function br(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let l=t;const{ownerDocument:d}=e,u=(r=d.defaultView)!=null?r:window;let c=e.parentElement;for(;c&&c!==d.documentElement;){if(!bh(c)){const g=c.getBoundingClientRect(),y=n*(g.bottom-g.top),_=n*(g.right-g.left),S=n*(g.bottom-g.top),E=n*(g.right-g.left);l={top:Math.max(l.top,g.top-y),right:Math.min(l.right,g.right+_),bottom:Math.min(l.bottom,g.bottom+S),left:Math.max(l.left,g.left-E),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}c=c.parentElement}const f=u.visualViewport,h=(s=f?.offsetTop)!=null?s:0,p=(i=f?.offsetLeft)!=null?i:0,m=(o=f?.width)!=null?o:u.innerWidth,b=(a=f?.height)!=null?a:u.innerHeight,w=n*b,v=n*m;return l={top:Math.max(l.top,h-w),right:Math.min(l.right,p+m+v),bottom:Math.min(l.bottom,h+b+w),left:Math.max(l.left,p-v),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function kn(e){return{x:e.clientX,y:e.clientY}}var lu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Hi(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 s=r.contentDocument;s&&!t.has(s)&&n.push(...Hi(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...Hi(s.document,t))}}catch{}return n}function ea(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function cu(){var e,t;const n=ea()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function ta(e){return!e||!Rr(e)?!1:e instanceof Ze(e).ShadowRoot}function Os(e){if(e&&Rr(e)){let t=e.getRootNode();if(ta(t))return t;if(t instanceof Document)return t}return jn(e)}function na(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function wh(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,o)=>{const a=r[o];if(Ka(i)&&Ka(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),Va(i)&&Va(a)&&a.width>0&&a.height>0){const l=i.getContext("2d");l?.drawImage(a,0,0)}}),n}function Ka(e){return"value"in e}function Va(e){return e.tagName==="CANVAS"}function uu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(_h(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return uu(s,{x:t-i,y:n-o})}}return r}function _h(e){return e?.tagName==="IFRAME"}var Xi=new WeakMap;function kh(e){return e.closest(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),O=require("../useCompiledDocument-UY28ITET.cjs.js"),$=require("@mui/material"),k=require("react"),Be=require("../ServerProvider-B0dUY8be.cjs.js"),ge=require("../text-entry-BJwltZiy.cjs.js"),nf=require("react-dom"),rf=require("@malloydata/malloy-tag"),ql=require("@tanstack/react-query"),sf={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function of(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,s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?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(o=>{const a=s(o);return{value:o,label:sf[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ai({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:s,onOpen:i,onChange:o,variant:a="standard"}){const l=of(t,e,n),d=k.useId();return w.jsx($.TextField,{select:!0,size:"small",variant:a,label:"Viz type",value:e,disabled:s!==void 0,onChange:c=>{const u=c.target.value;l.find(f=>f.value===u)?.disabled||o(u)},helperText:s,FormHelperTextProps:{id:d},SelectProps:{...i?{onOpen:i}:{},renderValue:c=>l.find(u=>u.value===c)?.label??String(c),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...s?{"aria-describedby":d}:{}}},sx:{minWidth:140},children:l.map(c=>w.jsx($.MenuItem,{value:c.value,disabled:c.value==="custom"||c.disabled===!0,children:w.jsx($.ListItemText,{primary:c.label,...c.reason?{secondary:c.reason}:{}})},c.value))})}function af({sources:e,source:t,view:n,onSource:r,onView:s}){const{theme:i}=Be.usePublisherTheme(),o=e.find(a=>a.name===t);return w.jsxs(w.Fragment,{children:[w.jsx($.TextField,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>w.jsxs($.MenuItem,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&w.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&w.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),w.jsxs($.Box,{children:[w.jsx($.Typography,{variant:"subtitle2",sx:{mb:.5},children:"View"}),w.jsxs($.List,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:i.border,borderRadius:1},children:[(o?.views??[]).map(a=>w.jsxs($.ListItemButton,{selected:n===a.name,onClick:()=>s(a.name),"aria-label":`View ${a.name}`,children:[w.jsx($.ListItemText,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&w.jsx($.Chip,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&w.jsx($.Typography,{variant:"body2",sx:{p:1.5,color:i.tileTitle},children:"This source declares no views."})]})]})]})}function lf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o}){const{theme:a}=Be.usePublisherTheme(),l=k.useMemo(()=>n?.sources??[],[n]),[d,c]=k.useState("query"),[u,f]=k.useState(""),[h,p]=k.useState(""),[m,b]=k.useState(""),[x,v]=k.useState("default"),[g,y]=k.useState(Math.ceil(r/2));k.useEffect(()=>{if(!e)return;c("query");const T=A=>l.some(q=>q.name===A&&q.views.length>0);f(t.sources.map(A=>A.base).find(T)??l.find(A=>A.views.length>0)?.name??""),p(""),b(""),v("default"),y(Math.ceil(r/2))},[e,t,l,r]);const _=u!==""&&h!=="",S=[u,h].filter(T=>T!==""&&!ge.isBareName(T)).map(T=>`"${T}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],E=l.find(T=>T.name===u),D=E?.views.find(T=>T.name===h);return w.jsx(O.AppDialog,{open:e,onClose:s,title:"Add a tile",description:"A tile shows one view of a source in this package.",actions:w.jsxs(w.Fragment,{children:[w.jsx($.Button,{onClick:s,children:"Cancel"}),w.jsx($.Button,{variant:"contained",disabled:d==="query"&&(!_||S!==void 0),onClick:()=>d==="text"?o():i({base:u,modelPath:E?.modelPath??"",...E?.exporters?{exporters:E.exporters}:{},view:h,...m.trim()?{label:m.trim()}:{},...x!=="default"?{chart:x,...D?{chartCarried:D.chart?[D.chart]:[]}:{}}:{},colspan:g}),children:d==="text"?"Add text":"Add tile"})]}),children:w.jsxs($.Stack,{sx:{gap:2,pt:1},children:[w.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:d,"aria-label":"Tile type",onChange:(T,A)=>{A!==null&&c(A)},children:[w.jsx($.ToggleButton,{value:"query",sx:{px:1.5},children:"Query"}),w.jsx($.ToggleButton,{value:"text",sx:{px:1.5},children:"Text"})]}),d==="text"?w.jsx($.Typography,{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."}):l.length===0?w.jsx($.Typography,{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."}):w.jsxs(w.Fragment,{children:[w.jsx(af,{sources:l,source:u,view:h,onSource:T=>{f(T),p("")},onView:T=>{p(T),v("default")}}),S&&w.jsx($.Typography,{variant:"body2",color:"error",children:S}),w.jsx(Ai,{state:x,view:D,cellLabel:"new tile",variant:"outlined",...D?{}:{disabledReason:"Pick a view to choose its chart."},onChange:T=>v(T)}),w.jsx($.Stack,{direction:"row",sx:{gap:1.5},children:w.jsx($.TextField,{size:"small",label:"Title",placeholder:"Uses the view's name",value:m,onChange:T=>b(T.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}})})]})]})})}const je=e=>e.kind==="text",xe=e=>e.kind!=="text",Kr=e=>xe(e)?e.label??e.name:e.name,Fe=e=>je(e)?`text.${e.name}`:`${e.source}.${e.name}`,ai="self";function cf({open:e,document:t,source:n,givenNames:r,dashboards:s,onClose:i,onApply:o}){const{theme:a}=Be.usePublisherTheme(),[l,d]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(m=>m.source===n.name);d((n.dimensions??[]).map(m=>{const b=p.find(x=>x.name===m.name);return{name:m.name,expression:m.expression,to:b?.to??[],given:b?.given??""}}))},[e,n,t]);const c=(p,m)=>d(b=>b.map((x,v)=>{if(v!==p)return x;const g={...x};return m(g),g})),u=[ai,...s.filter(p=>p!==ai)],f=p=>p===ai?"This report":p,h=()=>{n&&(o(l.filter(p=>p.to.length>0).map(p=>({source:n.name,name:p.name,expression:p.expression,to:p.to,...p.given?{given:p.given}:{}}))),i())};return w.jsx(O.AppDialog,{open:e,onClose:i,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:w.jsxs(w.Fragment,{children:[w.jsx($.Button,{onClick:i,children:"Cancel"}),w.jsx($.Button,{variant:"contained",onClick:h,disabled:l.length===0,children:"Apply"})]}),children:w.jsx($.Stack,{sx:{gap:2,pt:1},children:l.length===0?w.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?w.jsxs(w.Fragment,{children:[w.jsx($.Box,{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"," ",w.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((p,m)=>w.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[w.jsxs($.Box,{sx:{minWidth:0,pt:.75},children:[w.jsx($.Typography,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:p.name}),w.jsxs($.Typography,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:p.expression,children:["is ",p.expression]})]}),w.jsx($.TextField,{select:!0,size:"small",label:"Clicks go to",value:p.to,inputProps:{"aria-label":`Where ${p.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.length===0?"Not clickable":b.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:b=>c(m,x=>{const v=b.target.value;x.to=Array.isArray(v)?v:String(v).split(",").filter(Boolean)}),children:u.map(b=>w.jsxs($.MenuItem,{value:b,children:[w.jsx($.Checkbox,{size:"small",checked:p.to.includes(b),sx:{p:0,mr:1}}),w.jsx($.ListItemText,{primary:f(b)})]},b))}),w.jsxs($.TextField,{select:!0,size:"small",label:"Sets the filter",value:p.given,disabled:p.to.length===0,inputProps:{"aria-label":`Control ${p.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:p.given===""?`Named ${p.name}, like the dimension`:void 0,onChange:b=>c(m,x=>{x.given=b.target.value}),children:[w.jsx($.MenuItem,{value:"",children:w.jsx("em",{children:"Same name as the dimension"})}),r.map(b=>w.jsx($.MenuItem,{value:b,children:b},b))]})]},p.name))})})}function uf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],s=new Set;for(const i of e.localGivens??[])s.add(i.name),r.push({name:i.name,...i.label===void 0?{}:{label:i.label},type:i.type,...i.suggest?{field:i.suggest.dimension}:{},origin:"dashboard",local:i,boundTiles:n.get(i.name)??0});for(const i of t)s.has(i.name)||(s.add(i.name),r.push({...i,origin:"model",boundTiles:n.get(i.name)??0}));for(const[i,o]of n)s.has(i)||r.push({name:i,origin:"model",boundTiles:o});return r}function _s(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function df(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function as(e,t){const n=df(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Ma(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 ff(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const hf=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function pf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=ge.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const Pa=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function Vr(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Di=e=>xe(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function gf(e,t){return e.tiles.map(n=>{const r=(xe(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:_s(t.type)!==void 0?{op:_s(t.type)}:{}}})}function mf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Di(i))return;const o=(i.filters??[]).filter(l=>l.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?i.filters=a:delete i.filters})}function vf(e,t){const n=(e.localGivens??[]).filter(i=>i.name!==t.name),r=(e.localGivens??[]).findIndex(i=>i.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function yf(e,t){for(const r of e.tiles){if(!xe(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Kl=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function bf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:i}){const o=k.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[d,c]=k.useState({kind:"new"}),[u,f]=k.useState(""),[h,p]=k.useState("select"),[m,b]=k.useState(""),[x,v]=k.useState(""),[g,y]=k.useState([]),[_,S]=k.useState(!1),[E,D]=k.useState(!1),T=R=>t.sources.find(F=>F.name===R.source)?.base??R.source;k.useEffect(()=>{if(e)if(D(n!==void 0),n){c({kind:"existing",name:n.name}),f(n.label??"");const R=gf(t,n);y(R);const F=R.filter(ue=>ue.include),re=new Set(F.map(ue=>ue.field));v(re.size===1?F[0].field:n.field??""),S(re.size>1)}else c({kind:"new"}),f(""),p("select"),v(""),b(new Date().toISOString().slice(0,10)),y(t.tiles.map(R=>({include:Di(R),field:""}))),S(!1)},[e,n,t]);const A=k.useMemo(()=>[...(t.localGivens??[]).map(R=>R.name),...r.map(R=>R.name)],[t,r]),q=k.useMemo(()=>x.trim()?pf(x.trim(),A):"",[x,A]),P=d.kind==="existing"?n??r.find(R=>R.name===d.name):q?{name:q,type:Vr({name:q,label:u,kind:h,field:x}).type}:void 0,z=P?.type!==void 0&&!P.type.startsWith("filter<"),U=g.find(R=>R.include)?.op??_s(P?.type),K=(R,F)=>{D(!0),y(re=>re.map((ue,Re)=>Re===R?{...ue,...F}:ue))},Z=R=>{D(!0),y(F=>F.map(re=>({...re,op:R})))},J=R=>{const F=_s(R);y(re=>re.map(({op:ue,...Re})=>F?{...Re,op:F}:Re))},ie=R=>{D(!0),c({kind:"existing",name:R.name}),v(R.field??""),J(R.type)},de=R=>{D(!0),p(R),J(Vr({name:"X",label:u,kind:R,field:x}).type)},I=t.tiles.map(Di),V=I.filter(Boolean).length,B=g.filter((R,F)=>R.include&&I[F]).length,j=t.tiles.filter((R,F)=>(g[F]?.include??!1)&&I[F]&&xe(R)),G=j.length>0?j:t.tiles.filter((R,F)=>I[F]&&xe(R)),ne=k.useMemo(()=>{const R=new Map;let F=!1;for(const re of G){const ue=s?.(re);if(ue){F=!0;for(const Re of ue)R.has(Re.name)||R.set(Re.name,Re)}}return F?[...R.values()]:void 0},[g,t.tiles,s]),Y=(()=>{const R=x.trim();for(const F of j){const re=s?.(F);if(!re||re.some(ue=>ue.name===R))return T(F)}return j[0]?T(j[0]):t.sources[0]?.base})(),H=R=>{D(!0),y(F=>F.map((re,ue)=>({...re,include:R&&I[ue]})))},L=k.useMemo(()=>_?g:g.map(R=>({...R,field:x})),[_,g,x]),C=R=>{for(const F of G){const re=s?.(F)?.find(ue=>ue.name===R.trim());if(re?.type)return re.type}},W=R=>as(P?.type,R.type),M=(R,F)=>{if(R.trim()==="")return"Pick the field this filter compares.";const re=F?s?.(F):void 0;if(!re)return;const ue=re.find(Re=>Re.name===R.trim());if(!ue)return`Not a field of ${F?T(F):"the tiles' source"}.`;if(ue.type&&!as(P?.type,ue.type))return`${R.trim()} is ${Ma(ue.type)}; this filter compares ${Ma(P?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},ee=R=>{if(D(!0),v(R),l||d.kind!=="new")return;const F=C(R),re=Vr({name:"X",label:u,kind:h,field:R}).type;F&&!as(re,F)&&de(ff(F))},X=R=>{const F=t.tiles[R];return F&&xe(F)?F:void 0},le=L.map((R,F)=>R.include&&I[F]?M(R.field,X(F)):void 0),ce=le.every(R=>R===void 0),N=E?le:le.map(()=>{}),Q=E&&!_&&B>0?j.map(R=>M(x,R)).find(Boolean):void 0,me=P!==void 0&&ce&&(d.kind==="existing"||x.trim()!==""&&q!==""),se=()=>{if(!(!P||!me))if(d.kind==="new")i(P.name,L,Vr({name:P.name,label:u.trim()||Kl(P.name),kind:h,field:x.trim(),...Y?{source:Y}:{},...m?{dateDefault:m}:{}}));else if(n?.origin==="dashboard"&&n.local){const R=u.trim(),F=R!==(n.local.label??"");i(P.name,L,F?{...n.local,...R?{label:R}:{}}:void 0)}else i(P.name,L)},te=l&&a.origin==="model";return{editing:l,shown:a,fromModel:te,source:d,setSource:c,label:u,setLabel:f,kind:h,dateDefault:m,setDateDefault:b,field:x,rows:g,setRows:y,perTile:_,setPerTile:S,newName:q,target:P,valueTyped:z,commonOp:U,setRow:K,setCommonOp:Z,pickExisting:ie,pickKind:de,bindable:I,bindableCount:V,included:B,commonFields:ne,setAll:H,accepts:W,pickField:ee,rowProblems:N,commonProblem:Q,canApply:me,apply:se}}function ja({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:l,autoFocus:d,placeholder:c,sx:u}){const f=k.useMemo(()=>(n??[]).filter(p=>r?.(p)??!0).map(p=>p.name),[n,r]),h=k.useMemo(()=>new Map((n??[]).map(p=>[p.name,p.type])),[n]);return w.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(p,m)=>t(m),value:e,onChange:(p,m)=>t(typeof m=="string"?m:""),disabled:l,disableClearable:!0,renderOption:(p,m)=>k.createElement("li",{...p,key:m},w.jsx($.Typography,{variant:"body2",sx:{flex:1},children:m}),h.get(m)&&w.jsx($.Typography,{variant:"caption",sx:{opacity:.6},children:h.get(m)?.replace(/_type$/,"")})),renderInput:p=>w.jsx($.TextField,{...p,label:s,placeholder:c,autoFocus:d,error:o,helperText:a,inputProps:{...p.inputProps,"aria-label":i}}),sx:u})}const Ra=e=>e&&xe(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 xf({open:e,document:t,control:n,available:r,fieldsFor:s,onClose:i,onApply:o,onRemove:a}){const{theme:l}=Be.usePublisherTheme(),{editing:d,shown:c,fromModel:u,source:f,setSource:h,label:p,setLabel:m,kind:b,dateDefault:x,setDateDefault:v,field:g,rows:y,setRows:_,perTile:S,setPerTile:E,newName:D,target:T,valueTyped:A,commonOp:q,setRow:P,setCommonOp:z,pickExisting:U,pickKind:K,bindable:Z,bindableCount:J,included:ie,commonFields:de,setAll:I,accepts:V,pickField:B,rowProblems:j,commonProblem:G,canApply:ne,apply:Y}=bf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:o}),H=(L,C,W)=>w.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:L??">=",onChange:M=>C(M.target.value),inputProps:{"aria-label":W},sx:{width:130},children:hf.filter(M=>M.op!=="~").map(M=>w.jsx($.MenuItem,{value:M.op,children:M.label},M.op))});return w.jsx(O.AppDialog,{open:e,onClose:i,title:d?c.label??c.name:"Add a filter",description:d?w.jsxs(w.Fragment,{children:[w.jsxs($.Box,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",c.name]}),u?" · 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:w.jsxs(w.Fragment,{children:[d&&w.jsx($.Button,{color:"error",startIcon:w.jsx(O.DeleteOutlineIcon,{}),onClick:()=>a(c.name),sx:L=>({mr:"auto",color:O.dangerTextColor(L)}),children:"Remove filter"}),w.jsx($.Button,{onClick:i,children:"Cancel"}),w.jsx($.Tooltip,{title:ne||T===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:w.jsx("span",{children:w.jsx($.Button,{variant:"contained",onClick:Y,disabled:!ne,children:d?"Apply":"Add filter"})})})]}),children:w.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!d&&r.length>0&&w.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:f.kind,onChange:(L,C)=>{C==="new"?h({kind:"new"}):C==="existing"&&r[0]&&U(r[0])},"aria-label":"Where the filter comes from",children:[w.jsx($.ToggleButton,{value:"new",children:"New in this report"}),w.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&f.kind==="existing"?w.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:f.name,onChange:L=>{const C=r.find(W=>W.name===L.target.value);C&&U(C)},children:r.map(L=>w.jsxs($.MenuItem,{value:L.name,children:[L.label??L.name,w.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",L.name]})]},L.name))}):null,w.jsxs($.Stack,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!S&&w.jsx(ja,{value:g,onChange:B,fields:de,accepts:V,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!d,error:G!==void 0,helperText:G??(!d&&D?`Declared as $${D}`:void 0),sx:{flex:1,minWidth:200}}),!u&&w.jsx($.TextField,{size:"small",label:"Label",placeholder:D?Kl(D):"",value:p,onChange:L=>m(L.target.value),inputProps:{"aria-label":"Filter label"},sx:{flex:1,minWidth:160}}),A&&!S&&H(q,z,"Comparison")]}),!d&&f.kind==="new"&&w.jsxs($.Stack,{direction:"row",sx:{gap:1.5},children:[w.jsx($.TextField,{select:!0,size:"small",label:"Filter kind",value:b,onChange:L=>K(L.target.value),inputProps:{"aria-label":"Filter kind"},slotProps:{select:{renderValue:L=>Pa.find(C=>C.kind===L)?.label??String(L)}},sx:{flex:1},children:Pa.map(L=>w.jsxs($.MenuItem,{value:L.kind,children:[L.label,w.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:L.hint})]},L.kind))}),b==="date"&&w.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:x,onChange:L=>v(L.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),w.jsxs($.Box,{children:[w.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5},children:[w.jsx($.Checkbox,{size:"small",checked:J>0&&ie===J,indeterminate:ie>0&&ie<J,disabled:J===0,onChange:L=>I(L.target.checked),inputProps:{"aria-label":"All tiles"}}),w.jsxs($.Typography,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",ie," of ",t.tiles.length," tiles"]}),w.jsx($.Button,{size:"small",onClick:()=>{S||_(L=>L.map(C=>({...C,field:g}))),E(L=>!L)},children:S?"Same field for all":"Adjust per tile"})]}),w.jsx($.Stack,{sx:{gap:S?1:0},children:t.tiles.map((L,C)=>{if(!xe(L))return null;const W=y[C],M=L.label??L.name,ee=S?j[C]:void 0;return w.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:S?"flex-start":"center",opacity:Z[C]?1:.6},children:[w.jsx($.Checkbox,{size:"small",disabled:!Z[C],checked:(W?.include??!1)&&Z[C],inputProps:{"aria-label":`Filter ${M}`},onChange:X=>P(C,{include:X.target.checked})}),w.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:S?1:0},noWrap:!0,children:M}),Z[C]?S&&w.jsxs(w.Fragment,{children:[A&&H(W?.op,X=>P(C,{op:X}),`Comparison for ${M}`),w.jsx(ja,{value:W?.field??"",onChange:X=>P(C,{field:X}),fields:s?.(L),accepts:V,label:"Field",ariaLabel:`Field for ${M}`,disabled:!W?.include,error:ee!==void 0,helperText:ee,sx:{width:220}})]}):w.jsx($.Tooltip,{title:Ra(t.tiles[C]).reason,children:w.jsx($.Typography,{variant:"caption",sx:{color:l.tileTitle},children:Ra(t.tiles[C]).label})})]},`${L.source}.${L.name}`)})}),ie===0&&w.jsx($.Typography,{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 wf=O.createSvgIcon(w.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 Vl(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch:c=>i(u=>{if(u===void 0)return u;const f=structuredClone(u);return c(f),f}),apply:c=>{if(s===void 0)return;const u=structuredClone(s);c(u),i(u),JSON.stringify(u)!==JSON.stringify(e)&&n(u)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const _f=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.`,kf="This tile's view is declared on its source, so its chart is set in the model.";function Sf({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:s,removeBlocked:i,onDrills:o,view:a}){const l=k.useId(),{theme:d}=Be.usePublisherTheme(),{draft:c,apply:u,close:f,discard:h}=Vl(t,e!==null,r,n),p=c!==void 0&&xe(c)?c:void 0,m=p!==void 0&&p.declaration.kind!=="inherited",b=g=>u(y=>{xe(y)&&g(y)}),x=k.useRef(void 0),v=e!==null;return k.useEffect(()=>{v&&(x.current=t&&xe(t)?t.chart:void 0)},[v]),w.jsx($.Popover,{open:e!==null&&c!==void 0,anchorEl:e,onClose:f,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:c&&w.jsxs($.Stack,{sx:{gap:1.5},children:[w.jsx($.Typography,{variant:"overline",sx:{color:d.tileTitle,lineHeight:1.5},children:p?`${p.source} → ${p.name}`:`Text · ${c.name}`}),p&&m&&w.jsx(w.Fragment,{children:w.jsx(Ai,{state:p.chart??"default",view:a,cellLabel:`${p.source} ${p.name}`,...p.chart==="custom"?{disabledReason:_f(p.chartLines)}:{},onChange:g=>b(y=>{const _=x.current;g===(_??"default")?(_===void 0?delete y.chart:y.chart=_,delete y.chartCarried):(y.chart=g,a?y.chartCarried=a.chart?[a.chart]:[]:delete y.chartCarried)})})}),p&&!m&&w.jsxs(w.Fragment,{children:[w.jsx($.Typography,{variant:"body2",sx:{color:d.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),w.jsx(Ai,{state:"default",view:a,cellLabel:`${p.source} ${p.name}`,disabledReason:kf,onChange:()=>{}})]}),p?.declaration.kind==="opaque"&&w.jsxs($.Typography,{variant:"body2",sx:{color:d.tileTitle},children:["Its body is ",p.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),w.jsxs($.Stack,{direction:"row",sx:{justifyContent:"space-between"},children:[m&&o?w.jsx($.Button,{size:"small",startIcon:w.jsx(wf,{}),"aria-haspopup":"dialog",onClick:()=>{f(),o()},children:"Drill"}):w.jsx("span",{}),w.jsx($.Button,{color:"error",size:"small",startIcon:w.jsx(O.DeleteOutlineIcon,{}),"aria-disabled":i!==void 0||void 0,"aria-describedby":i!==void 0?l:void 0,disableRipple:i!==void 0,sx:g=>({color:O.dangerTextColor(g),...i!==void 0?{opacity:.5,cursor:"default"}:{}}),onClick:()=>{i===void 0&&(h(),s())},children:"Delete"})]}),i!==void 0&&w.jsx($.Typography,{id:l,variant:"caption",sx:{color:d.tileTitle},children:i})]})})}function $f({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,confirmConversion:l,exitDialog:d}){const{filterDialog:c,setFilterDialog:u}=s,{menu:f,setMenu:h}=i,p=f===void 0?void 0:e.document.tiles[f.index],m=p&&xe(p)?p:void 0,b=(()=>{if(!m||!t)return;const x=e.document.sources.find(g=>g.name===m.source)?.base??m.source,v=m.declaration.kind==="reference"?m.declaration.from:m.name;return t.sources.find(g=>g.name===x)?.views.find(g=>g.name===v)})();return w.jsxs(w.Fragment,{children:[w.jsx(xf,{open:c!==void 0,document:e.document,...c?.control?{control:c.control}:{},available:s.available,...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>u(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),w.jsx(Sf,{anchor:f?.anchor??null,tile:f===void 0?void 0:e.document.tiles[f.index],onClose:()=>h(void 0),onCommit:x=>{const v=f?.index;v!==void 0&&e.update(g=>{g.tiles[v]=x})},onRemove:()=>{f!==void 0&&i.removeTile(f.index)},...e.document.tiles.length===1&&e.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},view:b,...(e.document.sources.find(x=>x.name===m?.source)?.dimensions?.length??0)>0?{onDrills:()=>a(m?.source)}:{}}),w.jsx(cf,{open:o!==void 0,document:e.document,source:e.document.sources.find(x=>x.name===o),givenNames:s.controlList.map(x=>x.name),dashboards:r??[],onClose:()=>a(void 0),onApply:x=>e.update(v=>{const y=[...(v.drills??[]).filter(_=>_.source!==o),...x];y.length===0?delete v.drills:v.drills=y})}),w.jsx(O.AppDialog,{open:l!==void 0,onClose:()=>l?.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:w.jsxs(w.Fragment,{children:[w.jsx($.Button,{onClick:()=>l?.stop(),children:"Cancel"}),w.jsx($.Button,{variant:"contained",onClick:()=>l?.go(),children:"Convert and save"})]}),children:null}),w.jsx(O.UnsavedChangesDialog,{...d}),w.jsx(lf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText})]})}var Tf=Symbol.for("preact-signals");function qs(){if(vt>1)vt--;else{var e,t=!1;for((function(){var s=Ss;for(Ss=void 0;s!==void 0;){var i=s.S;if(i.v===s.v)for(var o=i.t;o!==void 0;o=o.x)o.i===s.i&&(o.i=i.i);s=s.o}})();dr!==void 0;){var n=dr;for(dr=void 0,ks++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Hl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ks=0,vt--,t)throw e}}function Te(e){if(vt>0)return e();Mi=++Of,vt++;try{return e()}finally{qs()}}var ur,we=void 0;function fe(e){var t=we,n=ur;we=void 0,ur=void 0;try{return e()}finally{we=t,ur=n}}var dr=void 0,vt=0,ks=0,Of=0,Mi=0,Ss=void 0,$s=0;function Ul(e){if(we!==void 0){var t=e.n;if(t===void 0||t.t!==we)return t={i:0,S:e,p:we.s,n:void 0,t:we,e:void 0,x:void 0,r:t},we.s!==void 0&&(we.s.n=t),we.s=t,e.n=t,32&we.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=we.s,t.n=void 0,we.s.n=t,we.s=t),t}}function 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=Tf;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:fe(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&&fe(function(){var s;(s=t.Z)==null||s.call(t)}))}};Ve.prototype.subscribe=function(e){var t=this;return rt(function(){var n=t.value;fe(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 fe(function(){return e.value})};Object.defineProperty(Ve.prototype,"value",{get:function(){var e=Ul(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ks>100)throw new Error("Cycle detected");(function(n){vt!==0&&ks===0&&n.l!==Mi&&(n.l=Mi,Ss={S:n,v:n.v,i:n.i,o:Ss})})(this),this.v=e,this.i++,$s++,vt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{qs()}}}});function En(e,t){return new Ve(e,t)}function Hl(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 Xl(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 Yl(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 Yt(e,t){Ve.call(this,void 0,t),this.x=e,this.s=void 0,this.g=$s-1,this.f=4}Yt.prototype=new Ve;Yt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===$s))return!0;if(this.g=$s,this.f|=1,this.i>0&&!Hl(this))return this.f&=-2,!0;var e=we;try{Xl(this),we=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return we=e,Yl(this),this.f&=-2,!0};Yt.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)};Yt.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)}};Yt.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(Yt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Ul(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function La(e,t){return new Yt(e,t)}function Zl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){vt++;var n=we;we=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,_o(e),r}finally{we=n,qs()}}}function _o(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Zl(e)}function Ef(e){if(we!==this)throw new Error("Out-of-order effect");Yl(this),we=e,this.f&=-2,8&this.f&&_o(this),qs()}function Cn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,ur&&ur.push(this)}Cn.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()}};Cn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Zl(this),Xl(this),vt++;var e=we;return we=this,Ef.bind(this,e)};Cn.prototype.N=function(){2&this.f||(this.f|=2,this.u=dr,dr=this)};Cn.prototype.d=function(){this.f|=8,1&this.f||_o(this)};Cn.prototype.dispose=function(){this.d()};function rt(e,t){var n=new Cn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Cf=Object.create,ko=Object.defineProperty,If=Object.defineProperties,Af=Object.getOwnPropertyDescriptor,Df=Object.getOwnPropertyDescriptors,Na=Object.getOwnPropertySymbols,Mf=Object.prototype.hasOwnProperty,Pf=Object.prototype.propertyIsEnumerable,jf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),In=e=>{throw TypeError(e)},Pi=(e,t,n)=>t in e?ko(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rf=(e,t)=>{for(var n in t||(t={}))Mf.call(t,n)&&Pi(e,n,t[n]);if(Na)for(var n of Na(t))Pf.call(t,n)&&Pi(e,n,t[n]);return e},Lf=(e,t)=>If(e,Df(t)),Fa=(e,t)=>ko(e,"name",{value:t,configurable:!0}),Nf=e=>{var t;return[,,,Cf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],Hn=e=>e!==void 0&&typeof e!="function"?In("Function expected"):e,Ff=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:i=>n._?In("Already initialized"):s.push(Hn(i||null))}),Jl=(e,t)=>Pi(t,jf("metadata"),e[3]),Lt=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},An=(e,t,n,r,s,i)=>{var o,a,l,d,c,u=t&7,f=!!(t&8),h=!!(t&16),p=u>3?e.length+1:u?f?1:2:0,m=Ql[u+5],b=u>3&&(e[p-1]=[]),x=e[p]||(e[p]=[]),v=u&&(!h&&!f&&(s=s.prototype),u<5&&(u>3||!h)&&Af(u<4?s:{get[n](){return Qe(this,i)},set[n](y){return Tt(this,i,y)}},n));u?h&&u<4&&Fa(i,(u>2?"set ":u>1?"get ":"")+n):Fa(s,n);for(var g=r.length-1;g>=0;g--)d=Ff(u,n,l={},e[3],x),u&&(d.static=f,d.private=h,c=d.access={has:h?y=>zf(s,y):y=>n in y},u^3&&(c.get=h?y=>(u^1?Qe:Wf)(y,s,u^4?i:v.get):y=>y[n]),u>2&&(c.set=h?(y,_)=>Tt(y,s,_,u^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(u?u<4?h?i:v[m]:u>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,u^4||a===void 0?Hn(a)&&(u>4?b.unshift(a):u?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?In("Object expected"):(Hn(o=a.get)&&(v.get=o),Hn(o=a.set)&&(v.set=o),Hn(o=a.init)&&b.unshift(o));return u||Jl(e,s),v&&ko(s,n,v),h?u^4?i:v:s},So=(e,t,n)=>t.has(e)||In("Cannot "+n),zf=(e,t)=>Object(t)!==t?In('Cannot use the "in" operator on this value'):e.has(t),Qe=(e,t,n)=>(So(e,t,"read from private field"),n?n.call(e):t.get(e)),Xn=(e,t,n)=>t.has(e)?In("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Tt=(e,t,n,r)=>(So(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Wf=(e,t,n)=>(So(e,t,"access private method"),n);function ji(e,t){if(t){let n;return La(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return La(e)}function it(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((r,s)=>!it(r,t[s]));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=>!it(e[i],t[i]))}return!1}function he({get:e},t){return{init(n){return En(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=ji(e.bind(this)),n.set(this,r)),r.value}}function li(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Lf(Rf({},s),{enumerable:e}))})}}function Ar(...e){const t=e.map(n=>rt(n));return()=>t.forEach(n=>n())}var ec,tc,nc,rc,sc,ic,Ge,$o,ci,Ri,Li,ze,To,ui,oc,Ni,Oo,di,Fi,zi;ic=[he],sc=[he],rc=[he],nc=[li()],tc=[li()],ec=[li()];var Zt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Lt(Ge,5,this),Xn(this,ze),Xn(this,$o,Lt(Ge,8,this)),Lt(Ge,11,this),Xn(this,To,Lt(Ge,12,this)),Lt(Ge,15,this),Xn(this,Oo,Lt(Ge,16,this)),Lt(Ge,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return Qe(this,ze,Fi)}get initial(){return Qe(this,ze,Ri)}get previous(){return Qe(this,ze,oc)}set current(e){const t=fe(()=>Qe(this,ze,Fi));e&&t&&this.equals(t,e)||Te(()=>{Qe(this,ze,Ri)||Tt(this,ze,e,Li),Tt(this,ze,t,Ni),Tt(this,ze,e,zi)})}reset(e=this.defaultValue){Te(()=>{Tt(this,ze,void 0,Ni),Tt(this,ze,e,Li),Tt(this,ze,e,zi)})}};Ge=Nf();$o=new WeakMap;ze=new WeakSet;To=new WeakMap;Oo=new WeakMap;ci=An(Ge,20,"#initial",ic,ze,$o),Ri=ci.get,Li=ci.set;ui=An(Ge,20,"#previous",sc,ze,To),oc=ui.get,Ni=ui.set;di=An(Ge,20,"#current",rc,ze,Oo),Fi=di.get,zi=di.set;An(Ge,2,"current",nc,Zt);An(Ge,2,"initial",tc,Zt);An(Ge,2,"previous",ec,Zt);Jl(Ge,Zt);function fi(e){return fe(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Nt,Bf=class{constructor(){Xn(this,Nt,new WeakMap)}get(e,t){var n;return e?(n=Qe(this,Nt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return Qe(this,Nt).has(e)||Qe(this,Nt).set(e,new Map),(r=Qe(this,Nt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=Qe(this,Nt).get(e))==null?void 0:t.clear():void 0}};Nt=new WeakMap;var Gf=Object.create,ac=Object.defineProperty,qf=Object.getOwnPropertyDescriptor,za=Object.getOwnPropertySymbols,Kf=Object.prototype.hasOwnProperty,Vf=Object.prototype.propertyIsEnumerable,lc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ks=e=>{throw TypeError(e)},Wa=Math.pow,Wi=(e,t,n)=>t in e?ac(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Uf=(e,t)=>{for(var n in t||(t={}))Kf.call(t,n)&&Wi(e,n,t[n]);if(za)for(var n of za(t))Vf.call(t,n)&&Wi(e,n,t[n]);return e},Hf=e=>{var t;return[,,,Gf((t=e?.[lc("metadata")])!=null?t:null)]},cc=["class","method","getter","setter","accessor","field","value","get","set"],uc=e=>e!==void 0&&typeof e!="function"?Ks("Function expected"):e,Xf=(e,t,n,r,s)=>({kind:cc[e],name:t,metadata:r,addInitializer:i=>n._?Ks("Already initialized"):s.push(uc(i||null))}),Yf=(e,t)=>Wi(t,lc("metadata"),e[3]),Zf=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},dc=(e,t,n,r,s,i)=>{for(var o,a,l,d,c=t&7,u=!1,f=!1,h=2,p=cc[c+5],m=e[h]||(e[h]=[]),b=(s=s.prototype,qf(s,n)),x=r.length-1;x>=0;x--)l=Xf(c,n,a={},e[3],m),l.static=u,l.private=f,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[x])(b[p],l),a._=1,uc(o)&&(b[p]=o);return b&&ac(s,n,b),s},fc=(e,t,n)=>t.has(e)||Ks("Cannot "+n),Qf=(e,t,n)=>(fc(e,t,"read from private field"),t.get(e)),Jf=(e,t,n)=>t.has(e)?Ks("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),eh=(e,t,n,r)=>(fc(e,t,"write to private field"),t.set(e,n),n),Je=class Bi{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Bi(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 Bi(t,n)}},ht=class Ft{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,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:s,width:i,height:o,scale:a}=this,l=new Ft(s+t,r+n,i,o);return l.scale=Uf({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:i,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:i,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Je((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Ft))return!1;const{left:n,top:r,width:s,height:i}=this;return n===t.left&&r===t.top&&s===t.width&&i===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:i}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=i}intersectionArea(t){return t instanceof Ft?th(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:s}){return new Ft(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],l=o==="x"?i.left:i.top,d=o==="x"?i.width:i.height;return a=="start"?l:a=="end"?l+d:l+d/2};return Je.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Ft.from(t).intersectionRatio(Ft.from(n))}};function th(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),o=s-r,a=i-n;return r<s&&n<i?o*a:0}var hc,pc,Gi,ls,Dr,Vs=class extends(Gi=Zt,pc=[Ee],hc=[Ee],Gi){constructor(t){const n=Je.from(t);super(n,(r,s)=>Je.equals(r,s)),Zf(Dr,5,this),Jf(this,ls,0),this.velocity={x:0,y:0}}get delta(){return Je.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Je.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-Qf(this,ls),a=l=>Math.round(l/o*100);Te(()=>{eh(this,ls,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Je.from(t)),this.velocity={x:0,y:0}}};Dr=Hf(Gi);ls=new WeakMap;dc(Dr,2,"delta",pc,Vs);dc(Dr,2,"direction",hc,Vs);Yf(Dr,Vs);function qi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Wa(r,2)+Wa(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var gc=(e=>(e.Horizontal="x",e.Vertical="y",e))(gc||{}),mc=Object.values(gc),nh=Object.create,Eo=Object.defineProperty,rh=Object.defineProperties,sh=Object.getOwnPropertyDescriptor,ih=Object.getOwnPropertyDescriptors,Ts=Object.getOwnPropertySymbols,vc=Object.prototype.hasOwnProperty,yc=Object.prototype.propertyIsEnumerable,bc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Dn=e=>{throw TypeError(e)},Ki=(e,t,n)=>t in e?Eo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Co=(e,t)=>{for(var n in t||(t={}))vc.call(t,n)&&Ki(e,n,t[n]);if(Ts)for(var n of Ts(t))yc.call(t,n)&&Ki(e,n,t[n]);return e},Io=(e,t)=>rh(e,ih(t)),Ba=(e,t)=>Eo(e,"name",{value:t,configurable:!0}),xc=(e,t)=>{var n={};for(var r in e)vc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ts)for(var r of Ts(e))t.indexOf(r)<0&&yc.call(e,r)&&(n[r]=e[r]);return n},Mn=e=>{var t;return[,,,nh((t=e?.[bc("metadata")])!=null?t:null)]},wc=["class","method","getter","setter","accessor","field","value","get","set"],Yn=e=>e!==void 0&&typeof e!="function"?Dn("Function expected"):e,oh=(e,t,n,r,s)=>({kind:wc[e],name:t,metadata:r,addInitializer:i=>n._?Dn("Already initialized"):s.push(Yn(i||null))}),Qt=(e,t)=>Ki(t,bc("metadata"),e[3]),ae=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},pe=(e,t,n,r,s,i)=>{var o,a,l,d,c,u=t&7,f=!!(t&8),h=!!(t&16),p=u>3?e.length+1:u?f?1:2:0,m=wc[u+5],b=u>3&&(e[p-1]=[]),x=e[p]||(e[p]=[]),v=u&&(!h&&!f&&(s=s.prototype),u<5&&(u>3||!h)&&sh(u<4?s:{get[n](){return Oe(this,i)},set[n](y){return Ye(this,i,y)}},n));u?h&&u<4&&Ba(i,(u>2?"set ":u>1?"get ":"")+n):Ba(s,n);for(var g=r.length-1;g>=0;g--)d=oh(u,n,l={},e[3],x),u&&(d.static=f,d.private=h,c=d.access={has:h?y=>ah(s,y):y=>n in y},u^3&&(c.get=h?y=>(u^1?Oe:_c)(y,s,u^4?i:v.get):y=>y[n]),u>2&&(c.set=h?(y,_)=>Ye(y,s,_,u^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(u?u<4?h?i:v[m]:u>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,u^4||a===void 0?Yn(a)&&(u>4?b.unshift(a):u?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?Dn("Object expected"):(Yn(o=a.get)&&(v.get=o),Yn(o=a.set)&&(v.set=o),Yn(o=a.init)&&b.unshift(o));return u||Qt(e,s),v&&Eo(s,n,v),h?u^4?i:v:s},Ao=(e,t,n)=>t.has(e)||Dn("Cannot "+n),ah=(e,t)=>Object(t)!==t?Dn('Cannot use the "in" operator on this value'):e.has(t),Oe=(e,t,n)=>(Ao(e,t,"read from private field"),n?n.call(e):t.get(e)),ve=(e,t,n)=>t.has(e)?Dn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,r)=>(Ao(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),_c=(e,t,n)=>(Ao(e,t,"access private method"),n);function kc(e,t){return{plugin:e,options:t}}function Mr(e){return t=>kc(e,t)}function vr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Sc,yr,Do,cs;Sc=[he];var We=class{constructor(e,t){this.manager=e,this.options=t,ve(this,Do,ae(yr,8,this,!1)),ae(yr,11,this),ve(this,cs,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return fe(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=rt(e.bind(this));return Oe(this,cs).add(t),t}destroy(){Oe(this,cs).forEach(e=>e())}static configure(e){return kc(this,e)}};yr=Mn(null);Do=new WeakMap;cs=new WeakMap;pe(yr,4,"disabled",Sc,We,Do);Qt(yr,We);var Pr=class extends We{},us,hi=class{constructor(e){this.manager=e,this.instances=new Map,ve(this,us,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(vr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Oe(this,us))if(!n.includes(r)){if(r.prototype instanceof Pr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);Ye(this,us,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()}};us=new WeakMap;function lh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Ur=[],cn,un,ch=class extends We{constructor(e){super(e),ve(this,cn),ve(this,un),this.computeCollisions=this.computeCollisions.bind(this),Ye(this,un,En(Ur)),this.destroy=Ar(()=>{const t=this.computeCollisions(),n=fe(()=>this.manager.dragOperation.position.current);if(t!==Ur){const r=Oe(this,cn);if(Ye(this,cn,n),r&&n.x==r.x&&n.y==r.y)return}else Ye(this,cn,void 0);Oe(this,un).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){fe(()=>{e?Oe(this,un).value=this.computeCollisions():Ye(this,cn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Ur;const a=[],l=[];for(const d of e??n.droppables){if(d.disabled||s&&!d.accepts(s))continue;const c=t??d.collisionDetector;if(!c)continue;l.push(d),d.shape;const u=fe(()=>c({droppable:d,dragOperation:r}));u&&(d.collisionPriority!=null&&(u.priority=d.collisionPriority),a.push(u))}return l.length===0?Ur:(a.sort(lh),a)}get collisions(){return Oe(this,un).value}};cn=new WeakMap;un=new WeakMap;var $c,Tc,Oc,Mo,Ec,ot,Po,mn,jo,Ro;Oc=[he],Tc=[he],$c=[he];var bt=class zt{constructor(t,n){ve(this,Po,ae(ot,8,this)),ae(ot,11,this),ve(this,mn),ve(this,jo,ae(ot,12,this)),ae(ot,15,this),ve(this,Ro,ae(ot,16,this)),ae(ot,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let l=s;Ye(this,mn,En(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var d;return[()=>{const{id:c,manager:u}=this;if(c!==l)return l=c,u?.registry.register(this),()=>u?.registry.unregister(this)},...(d=r?.())!=null?d:[]]},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=Oe(this,mn).value;return(n=(t=zt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=zt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Oe(this,mn).peek();t!==s&&(zt.pendingIdChanges||(zt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return _c(i=zt,Mo,Ec).call(i)})),zt.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)}};ot=Mn(null);Mo=new WeakSet;Ec=function(){const e=bt.pendingIdChanges;bt.pendingIdChanges=null,e&&Te(()=>{for(const[t,n]of e)Oe(t,mn).value=n})};Po=new WeakMap;mn=new WeakMap;jo=new WeakMap;Ro=new WeakMap;pe(ot,4,"manager",Oc,bt,Po);pe(ot,4,"data",Tc,bt,jo);pe(ot,4,"disabled",$c,bt,Ro);ve(bt,Mo);Qt(ot,bt);bt.pendingIdChanges=null;var Us=bt,Ga=class{constructor(){this.map=En(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Ar(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[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){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Cc,Ic,Ac,Dc,Mc,Pc,Vi,qe,Lo,No,Fo,pt=class extends(Vi=Us,Pc=[he],Mc=[he],Dc=[he],Ac=[Ee],Ic=[Ee],Cc=[Ee],Vi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:l}=r,d=xc(r,["modifiers","type","sensors","plugins","effects"]);super(Io(Co({},d),{effects:()=>{var c;return[...(c=l?.())!=null?c:[],()=>{const{manager:u,plugins:f}=this;if(!(!u||!f))for(const h of f){const{plugin:p}=vr(h);u.registry.plugins.register(p)}}]}}),n),ae(qe,5,this),ve(this,Lo,ae(qe,8,this)),ae(qe,11,this),ve(this,No,ae(qe,12,this)),ae(qe,15,this),ve(this,Fo,ae(qe,16,this,this.isDragSource?"dragging":"idle")),ae(qe,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=d.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=vr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};qe=Mn(Vi);Lo=new WeakMap;No=new WeakMap;Fo=new WeakMap;pe(qe,4,"type",Pc,pt,Lo);pe(qe,4,"modifiers",Mc,pt,No);pe(qe,4,"status",Dc,pt,Fo);pe(qe,2,"isDropping",Ac,pt);pe(qe,2,"isDragging",Ic,pt);pe(qe,2,"isDragSource",Cc,pt);Qt(qe,pt);var jc,Rc,Lc,Nc,Fc,zc,Ui,Me,zo,Wo,Bo,Go,qo,gt=class extends(Ui=Us,zc=[he],Fc=[he],Nc=[he],Lc=[he],Rc=[he],jc=[Ee],Ui){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,l=xc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ae(Me,5,this),ve(this,zo,ae(Me,8,this)),ae(Me,11,this),ve(this,Wo,ae(Me,12,this)),ae(Me,15,this),ve(this,Bo,ae(Me,16,this)),ae(Me,19,this),ve(this,Go,ae(Me,20,this)),ae(Me,23,this),ve(this,qo,ae(Me,24,this)),ae(Me,27,this),this.accept=s,this.collisionDetector=i,this.collisionPriority=o,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Me=Mn(Ui);zo=new WeakMap;Wo=new WeakMap;Bo=new WeakMap;Go=new WeakMap;qo=new WeakMap;pe(Me,4,"accept",zc,gt,zo);pe(Me,4,"type",Fc,gt,Wo);pe(Me,4,"collisionDetector",Nc,gt,Bo);pe(Me,4,"collisionPriority",Lc,gt,Go);pe(Me,4,"shape",Rc,gt,qo);pe(Me,2,"isDropTarget",jc,gt);Qt(Me,gt);var uh=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 s of r)s(...t)}},dh=class extends uh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function ds(e,t=!0){let n=!1;return Io(Co({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var fh=class extends Pr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Ar(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||Us.pendingIdChanges)return;const o=ds({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;fe(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Pn=(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))(Pn||{}),jn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(jn||{}),Wc,Bc,Gc,qc,Kc,Vc,Uc,nt,Ko;Uc=[he],Vc=[Ee],Kc=[Ee],qc=[Ee],Gc=[Ee],Bc=[Ee],Wc=[Ee];var wt=class{constructor(){ae(nt,5,this),ve(this,Ko,ae(nt,8,this,"idle")),ae(nt,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}};nt=Mn(null);Ko=new WeakMap;pe(nt,4,"value",Uc,wt,Ko);pe(nt,2,"current",Vc,wt);pe(nt,2,"idle",Kc,wt);pe(nt,2,"initializing",qc,wt);pe(nt,2,"initialized",Gc,wt);pe(nt,2,"dragging",Bc,wt);pe(nt,2,"dropped",Wc,wt);Qt(nt,wt);var hh=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 fe(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=ds({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return fe(()=>{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 r=new AbortController,{event:s,coordinates:i}=e;Te(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=ds({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&Te(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return fe(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=ds({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,l,d,c,u;if(o.defaultPrevented)return;const f=(u=e.to)!=null?u:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((c=(d=e.by)==null?void 0:d.y)!=null?c:0)};r.position.current=f})})}stop(e={}){return fe(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const l={resume:()=>{},abort:()=>{}};return i=new Promise((d,c)=>{l.resume=d,l.abort=c}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=fe(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),d=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:c}=r,u=rt(()=>{c?.status==="idle"&&(u(),d())})}else this.manager.renderer.rendering.then(d)})};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}),i?i.then(a).catch(()=>r.reset()):a()})}},_n=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}},ph=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)}},fs,Hc=class{constructor(e){this.options=e,ve(this,fs)}set controller(e){Ye(this,fs,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Oe(this,fs))==null||t.activate(e)}};fs=new WeakMap;var qa=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},gh=class{constructor(e){this.draggables=new Ga,this.droppables=new Ga,this.plugins=new hi(e),this.sensors=new hi(e),this.modifiers=new hi(e)}register(e,t){if(e instanceof pt)return this.draggables.register(e.id,e);if(e instanceof gt)return this.droppables.register(e.id,e);if(e.prototype instanceof qa)return this.modifiers.register(e,t);if(e.prototype instanceof _n)return this.sensors.register(e,t);if(e.prototype instanceof We)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Us)return e instanceof pt?this.draggables.unregister(e.id,e):e instanceof gt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof qa)return this.modifiers.unregister(e);if(e.prototype instanceof _n)return this.sensors.unregister(e);if(e.prototype instanceof We)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()}},Xc,Yc,Zc,Qc,Jc,eu,tu,nu,ru,Zn,hs,dn,$e,Vo,Uo,Ho,Xo,Yo,Qn;ru=[Ee],nu=[he],tu=[he],eu=[he],Jc=[he],Qc=[he],Zc=[Ee],Yc=[Ee],Xc=[Ee];var ct=class{constructor(e){ae($e,5,this),ve(this,Zn),ve(this,hs),ve(this,dn,new Zt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new wt,ve(this,Vo,ae($e,8,this,!1)),ae($e,11,this),ve(this,Uo,ae($e,12,this,null)),ae($e,15,this),ve(this,Ho,ae($e,16,this,null)),ae($e,19,this),ve(this,Xo,ae($e,20,this,null)),ae($e,23,this),ve(this,Yo,ae($e,24,this,[])),ae($e,27,this),this.position=new Vs({x:0,y:0}),ve(this,Qn,{x:0,y:0}),Ye(this,Zn,e)}get shape(){const{current:e,initial:t,previous:n}=Oe(this,dn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Oe(this,dn).current=e:Oe(this,dn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Oe(this,Zn).registry.draggables.get(t);return n&&Ye(this,hs,n),(e=n??Oe(this,hs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Oe(this,Zn).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(Io(Co({},this.snapshot()),{transform:n}));return Ye(this,Qn,n),n}snapshot(){return fe(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Oe(this,Qn),shape:this.shape?fi(this.shape):null,position:fi(this.position),status:fi(this.status),canceled:this.canceled}))}reset(){Te(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Oe(this,dn).reset(),this.position.reset({x:0,y:0}),Ye(this,Qn,{x:0,y:0}),this.modifiers=[]})}};$e=Mn(null);Zn=new WeakMap;hs=new WeakMap;dn=new WeakMap;Vo=new WeakMap;Uo=new WeakMap;Ho=new WeakMap;Xo=new WeakMap;Yo=new WeakMap;Qn=new WeakMap;pe($e,2,"shape",ru,ct);pe($e,4,"canceled",nu,ct,Vo);pe($e,4,"activatorEvent",tu,ct,Uo);pe($e,4,"sourceIdentifier",eu,ct,Ho);pe($e,4,"targetIdentifier",Jc,ct,Xo);pe($e,4,"modifiers",Qc,ct,Yo);pe($e,2,"source",Zc,ct);pe($e,2,"target",Yc,ct);pe($e,2,"transform",Xc,ct);Qt($e,ct);var mh={get rendering(){return Promise.resolve()}};function lt(e,t){return typeof e=="function"?e(t):e??t}var vh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=lt(r.plugins,[]),i=lt(r.sensors,[]),o=lt(r.modifiers,[]),a=(n=r.renderer)!=null?n:mh,l=new dh(this),d=new gh(this);this.registry=d,this.monitor=l,this.renderer=a,this.actions=new hh(this),this.dragOperation=new ct(this),this.collisionObserver=new ch(this),this.plugins=[fh,...s],this.modifiers=o,this.sensors=i;const{destroy:c}=this,u=Ar(()=>{var f,h,p;const m=fe(()=>this.dragOperation.modifiers),b=this.modifiers;for(const x of m)b.includes(x)||x.destroy();this.dragOperation.modifiers=(p=(h=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:h.map(x=>{const{plugin:v,options:g}=vr(x);return new v(this,g)}))!=null?p:b});this.destroy=()=>{u(),c()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},su=e=>{throw TypeError(e)},Zo=(e,t,n)=>t.has(e)||su("Cannot "+n),oe=(e,t,n)=>(Zo(e,t,"read from private field"),t.get(e)),Ue=(e,t,n)=>t.has(e)?su("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Xe=(e,t,n,r)=>(Zo(e,t,"write to private field"),t.set(e,n),n),iu=(e,t,n)=>(Zo(e,t,"access private method"),n);function Hs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function ou(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(Hs(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function Xs(e){const{width:t,height:n,top:r,left:s,bottom:i,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:i,right:o}}function Qo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function jr(e){return"nodeType"in e}function Ze(e){var t,n,r;return e?Qo(e)?e:jr(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 Jo(e){const{Document:t}=Ze(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Dt(e){return!e||Qo(e)?!1:e instanceof Ze(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function au(e){return e instanceof Ze(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Rn(e){return e?Qo(e)?e.document:jr(e)?Jo(e)?e:Dt(e)||au(e)?e.ownerDocument:document:document:document}function yh(e){var t,n,r,s;const{documentElement:i}=Rn(e),o=Ze(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,l=(n=o?.height)!=null?n:i.clientHeight,d=(r=o?.offsetTop)!=null?r:0,c=(s=o?.offsetLeft)!=null?s:0;return{top:d,left:c,right:c+a,bottom:d+l,width:a,height:l}}function bh(e,t){if(xh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function xh(e){return e.tagName==="DETAILS"}function br(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let l=t;const{ownerDocument:d}=e,c=(r=d.defaultView)!=null?r:window;let u=e.parentElement;for(;u&&u!==d.documentElement;){if(!bh(u)){const g=u.getBoundingClientRect(),y=n*(g.bottom-g.top),_=n*(g.right-g.left),S=n*(g.bottom-g.top),E=n*(g.right-g.left);l={top:Math.max(l.top,g.top-y),right:Math.min(l.right,g.right+_),bottom:Math.min(l.bottom,g.bottom+S),left:Math.max(l.left,g.left-E),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}u=u.parentElement}const f=c.visualViewport,h=(s=f?.offsetTop)!=null?s:0,p=(i=f?.offsetLeft)!=null?i:0,m=(o=f?.width)!=null?o:c.innerWidth,b=(a=f?.height)!=null?a:c.innerHeight,x=n*b,v=n*m;return l={top:Math.max(l.top,h-x),right:Math.min(l.right,p+m+v),bottom:Math.min(l.bottom,h+b+x),left:Math.max(l.left,p-v),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function kn(e){return{x:e.clientX,y:e.clientY}}var lu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Hi(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 s=r.contentDocument;s&&!t.has(s)&&n.push(...Hi(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...Hi(s.document,t))}}catch{}return n}function ea(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function cu(){var e,t;const n=ea()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function ta(e){return!e||!jr(e)?!1:e instanceof Ze(e).ShadowRoot}function Os(e){if(e&&jr(e)){let t=e.getRootNode();if(ta(t))return t;if(t instanceof Document)return t}return Rn(e)}function na(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function wh(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,o)=>{const a=r[o];if(Ka(i)&&Ka(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),Va(i)&&Va(a)&&a.width>0&&a.height>0){const l=i.getContext("2d");l?.drawImage(a,0,0)}}),n}function Ka(e){return"value"in e}function Va(e){return e.tagName==="CANVAS"}function uu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(_h(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return uu(s,{x:t-i,y:n-o})}}return r}function _h(e){return e?.tagName==="IFRAME"}var Xi=new WeakMap;function kh(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 du=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:l,listener:d,options:u}=a,c=[o,a];o.addEventListener(l,d,u),this.entries.add(c),s.push(c)}const i=this.entries;return function(){for(const a of s){const[l,{type:d,listener:u,options:c}]=a;l.removeEventListener(d,u,c),i.delete(a)}}}};function Sn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Sh(e){const t=new Set;let n=Sn(e);for(;n;)t.add(n),n=Sn(n);return t}function $h(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function fu(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=$h(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Th(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 Oh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=br(e,t);return n>0&&r>0}var Eh=lu?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ps,Ch=class extends Eh{constructor(e){super(t=>{if(!oe(this,ps)){Xe(this,ps,!0);return}e(t,this)}),Ue(this,ps,!1)}};ps=new WeakMap;var Ua=Array.from({length:100},(e,t)=>t/100),hu=75,Wt,Es,St,Bt,Jn,Ne,fr,er,Cs,pu,gu,mu=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ue(this,Cs),this.disconnect=()=>{var i,o,a;Xe(this,fr,!0),(i=oe(this,St))==null||i.disconnect(),(o=oe(this,Bt))==null||o.disconnect(),oe(this,Jn).disconnect(),(a=oe(this,Ne))==null||a.remove()},Ue(this,Wt,!0),Ue(this,Es),Ue(this,St),Ue(this,Bt),Ue(this,Jn),Ue(this,Ne),Ue(this,fr,!1),Ue(this,er,fu(()=>{var i,o,a;const{element:l}=this;if((i=oe(this,Bt))==null||i.disconnect(),oe(this,fr)||!oe(this,Wt)||!l.isConnected)return;const d=(o=l.ownerDocument)!=null?o:document,{innerHeight:u,innerWidth:c}=(a=d.defaultView)!=null?a:window,f=l.getBoundingClientRect(),h=br(l,f),{top:p,left:m,bottom:b,right:w}=h,v=-Math.floor(p),g=-Math.floor(m),y=-Math.floor(c-w),_=-Math.floor(u-b),S=`${v}px ${y}px ${_}px ${g}px`;this.boundingClientRect=f,Xe(this,Bt,new IntersectionObserver(E=>{const[A]=E,{intersectionRect:T}=A;(A.intersectionRatio!==1?A.intersectionRatio:ht.intersectionRatio(T,br(l)))!==1&&oe(this,er).call(this)},{threshold:Ua,rootMargin:S,root:d})),oe(this,Bt).observe(l),iu(this,Cs,pu).call(this)},hu)),this.boundingClientRect=e.getBoundingClientRect(),Xe(this,Wt,Oh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(Xe(this,Ne,document.createElement("div")),oe(this,Ne).style.background="rgba(0,0,0,0.15)",oe(this,Ne).style.position="fixed",oe(this,Ne).style.pointerEvents="none",s.body.appendChild(oe(this,Ne))),Xe(this,Jn,new IntersectionObserver(i=>{var o,a;const l=i[i.length-1],{boundingClientRect:d,isIntersecting:u}=l,{width:c,height:f}=d,h=oe(this,Wt);Xe(this,Wt,u),!(!c&&!f)&&(h&&!u?((o=oe(this,Bt))==null||o.disconnect(),this.callback(null),(a=oe(this,St))==null||a.disconnect(),Xe(this,St,void 0),oe(this,Ne)&&(oe(this,Ne).style.visibility="hidden")):oe(this,er).call(this),u&&!oe(this,St)&&(Xe(this,St,new Ch(oe(this,er))),oe(this,St).observe(e)))},{threshold:Ua,root:s})),oe(this,Wt)&&!n.skipInitial&&this.callback(this.boundingClientRect),oe(this,Jn).observe(e)}};Wt=new WeakMap;Es=new WeakMap;St=new WeakMap;Bt=new WeakMap;Jn=new WeakMap;Ne=new WeakMap;fr=new WeakMap;er=new WeakMap;Cs=new WeakSet;pu=function(){oe(this,fr)||(iu(this,Cs,gu).call(this),!Th(this.boundingClientRect,oe(this,Es))&&(this.callback(this.boundingClientRect),Xe(this,Es,this.boundingClientRect)))};gu=function(){if(oe(this,Ne)){const{top:e,left:t,width:n,height:r}=br(this.element);oe(this,Ne).style.overflow="hidden",oe(this,Ne).style.visibility="visible",oe(this,Ne).style.top=`${Math.floor(e)}px`,oe(this,Ne).style.left=`${Math.floor(t)}px`,oe(this,Ne).style.width=`${Math.floor(n)}px`,oe(this,Ne).style.height=`${Math.floor(r)}px`}};var Hr=new WeakMap,Xr=new WeakMap;function Ih(e,t){let n=Hr.get(e);return n||(n={disconnect:new mu(e,s=>{const i=Hr.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Hr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Hr.delete(e),n.disconnect())}}function Dh(e,t){const n=new Set;for(const r of e){const s=Ih(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Ah(e,t){var n;const r=e.ownerDocument;if(!Xr.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(d=>d(l)),{capture:!0,passive:!0,signal:o.signal}),Xr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=Xr.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),Xr.delete(r))})}var tr,nr,gs,Yi,Mh=class{constructor(e,t,n){this.callback=t,Ue(this,tr),Ue(this,nr,!1),Ue(this,gs),Ue(this,Yi,fu(o=>{if(!oe(this,nr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of oe(this,gs))if(o.target.contains(a)){this.callback(oe(this,tr).boundingClientRect);break}}},hu));const r=Sh(e),s=Dh(r,t),i=Ah(e,oe(this,Yi));Xe(this,gs,r),Xe(this,tr,new mu(e,t,n)),this.disconnect=()=>{oe(this,nr)||(Xe(this,nr,!0),s(),i(),oe(this,tr).disconnect())}}};tr=new WeakMap;nr=new WeakMap;gs=new WeakMap;Yi=new WeakMap;function Zi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function yn(e){try{Zi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Ha(e){return!lu||!e?!1:e===jn(e).scrollingElement}function vu(e){var t,n;const r=Ze(e),s=Ha(e)?yh(e):Xs(e),i=r.visualViewport,o=Ha(e)?{height:(t=i?.height)!=null?t:r.innerHeight,width:(n=i?.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}},l=a.current.y<=0,d=a.current.x<=0,u=a.current.y>=a.max.y,c=a.current.x>=a.max.x;return{rect:s,position:a,isTop:l,isLeft:d,isBottom:u,isRight:c}}function Ph(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=vu(e),{x:a,y:l}=t??{x:0,y:0},d=!n&&o.current.y+l>0,u=!r&&o.current.y+l<o.max.y,c=!s&&o.current.x+a>0,f=!i&&o.current.x+a<o.max.x;return{top:d,bottom:u,left:c,right:f,x:c||f,y:d||u}}var ra=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Is=new ra(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Rh=new ra(e=>setTimeout(e,50)),Ds=new Map,jh=Ds.clear.bind(Ds);function mt(e,t=!1){if(!t)return Xa(e);let n=Ds.get(e);return n||(n=Xa(e),Ds.set(e,n),Rh.schedule(jh),n)}function Xa(e){return Ze(e).getComputedStyle(e)}function Lh(e,t=mt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Nh(e,t=mt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?n.test(i):!1})}var Fh={excludeElement:!0,escapeShadowDOM:!0};function Qi(e,t=Fh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(Jo(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&ta(a))return o(a.host);if(!At(a))return au(a)?o(a.parentElement):i;if(i.has(a))return i;const l=mt(a,!0);if(r&&a===e||Nh(a,l)&&i.add(a),Lh(a,l)){const{scrollingElement:d}=a.ownerDocument;return d&&i.add(d),i}return o(a.parentNode)}return e?o(e):i}function $n(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Sn(e);for(;r;){if(r===t)return n;const s=Xs(r),{x:i,y:o}=zh(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*i,n.scaleY=n.scaleY*o,r=Sn(r)}return n}function zh(e,t=Xs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(At(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=mt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Wh(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 xr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function Ys(e){var t,n,r,s,i,o,a,l,d;const{scale:u,transform:c,translate:f}=e,h=Wh(u),p=xr(f),m=Bh(c);if(!m&&!h&&!p)return null;const b={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},w={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},v={x:(i=m?.x)!=null?i:0,y:(o=m?.y)!=null?o:0,scaleX:(a=m?.scaleX)!=null?a:1,scaleY:(l=m?.scaleY)!=null?l:1};return{x:w.x+v.x,y:w.y+v.y,z:(d=p?.z)!=null?d:0,scaleX:b.x*v.scaleX,scaleY:b.y*v.scaleY}}function Bh(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 et=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(et||{}),Gh={x:.2,y:.2},qh={x:10,y:10};function Kh(e,t,n,r=25,s=Gh,i=qh){const{x:o,y:a}=t,{rect:l,isTop:d,isBottom:u,isLeft:c,isRight:f}=vu(e),h=$n(e),p=mt(e,!0),m=Ys(p),b=m!==null?m?.scaleX<0:!1,w=m!==null?m?.scaleY<0:!1,v=new ht(l.left*h.scaleX+h.x,l.top*h.scaleY+h.y,l.width*h.scaleX,l.height*h.scaleY),g={x:0,y:0},y={x:0,y:0},_={height:v.height*s.y,width:v.width*s.x};return _.height>0&&(!d||w&&!u)&&a<=v.top+_.height&&n?.y!==1&&o>=v.left-i.x&&o<=v.right+i.x?(g.y=w?1:-1,y.y=r*Math.abs((v.top+_.height-a)/_.height)):_.height>0&&(!u||w&&!d)&&a>=v.bottom-_.height&&n?.y!==-1&&o>=v.left-i.x&&o<=v.right+i.x&&(g.y=w?-1:1,y.y=r*Math.abs((v.bottom-_.height-a)/_.height)),_.width>0&&(!f||b&&!c)&&o>=v.right-_.width&&n?.x!==-1&&a>=v.top-i.y&&a<=v.bottom+i.y?(g.x=b?-1:1,y.x=r*Math.abs((v.right-_.width-o)/_.width)):_.width>0&&(!c||b&&!f)&&o<=v.left+_.width&&n?.x!==1&&a>=v.top-i.y&&a<=v.bottom+i.y&&(g.x=b?1:-1,y.x=r*Math.abs((v.left+_.width-o)/_.width)),{direction:g,speed:y}}function yu(e,{block:t="nearest",inline:n="nearest"}={}){if(!At(e))return;const r=Qi(e),s=[];for(const i of r){if(!At(i))continue;const{top:o,left:a}=Vh(e,i);let l=o,d=a;for(const u of s)l-=u.scrollTop,d-=u.scrollLeft;if(t!=="none"){const u=l<i.scrollTop,c=l+e.offsetHeight>i.scrollTop+i.clientHeight;u!==c&&(t==="center"?i.scrollTop=l-i.clientHeight/2+e.offsetHeight/2:u?i.scrollTop=l:i.scrollTop=l+e.offsetHeight-i.clientHeight)}if(n!=="none"){const u=d<i.scrollLeft,c=d+e.offsetWidth>i.scrollLeft+i.clientWidth;u!==c&&(n==="center"?i.scrollLeft=d-i.clientWidth/2+e.offsetWidth/2:u?i.scrollLeft=d:i.scrollLeft=d+e.offsetWidth-i.clientWidth)}s.push(i)}}function Ya(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!At(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function Vh(e,t){const n=Ya(e),r=Ya(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Uh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),l=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width*r:e.width,u=s?e.height*s:e.height;return{width:d,height:u,top:l,right:a+d,bottom:l+u,left:a}}function Hh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),l=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width/r:e.width,u=s?e.height/s:e.height;return{width:d,height:u,top:l,right:a+d,bottom:l+u,left:a}}function bu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Za(e,t=mt(e).translate,n=!0){if(n){const r=ou(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=xr(s);if(i)return i}}}if(t){const r=xr(t);if(r)return r}return{x:0,y:0,z:0}}var Xh=new ra(e=>setTimeout(e,0)),hr=new Map,Yh=hr.clear.bind(hr);function Zh(e){const t=e.ownerDocument;let n=hr.get(t);if(n)return n;n=t.getAnimations(),hr.set(t,n),Xh.schedule(Yh);const r=n.filter(s=>Hs(s.effect)&&s.effect.target===e);return hr.set(e,r),n}function Qh(e,t){const n=Zh(e).filter(r=>{var s,i;if(Hs(r.effect)){const{target:o}=r.effect;if((i=o&&((s=t.isValidTarget)==null?void 0:s.call(t,o)))!=null?i:!0)return r.effect.getKeyframes().some(l=>{for(const d of t.properties)if(l[d])return!0})}}).map(r=>{const{effect:s,currentTime:i}=r,o=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof i=="number"&&i<o)return r.currentTime=o,()=>{r.currentTime=i}});if(n.length>0)return()=>n.forEach(r=>r?.())}var ft=class extends ht{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=$n(e),ignoreTransforms:a,getBoundingClientRect:l=Xs}=t,d=Qh(e,{properties:["transform","translate","scale","width","height"],isValidTarget:_=>(_!==e||ea())&&_.contains(e)}),u=l(e);let{top:c,left:f,width:h,height:p}=u,m;const b=mt(e),w=Ys(b),v={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},g=Jh(e,b);d?.(),w&&(m=Hh(u,w,b.transformOrigin),(a||g)&&(c=m.top,f=m.left,h=m.width,p=m.height));const y={width:(s=m?.width)!=null?s:h,height:(i=m?.height)!=null?i:p};if(g&&!a&&m){const _=Uh(m,g,b.transformOrigin);c=_.top,f=_.left,h=_.width,p=_.height,v.x=g.scaleX,v.y=g.scaleY}o&&(a||(f*=o.scaleX,h*=o.scaleX,c*=o.scaleY,p*=o.scaleY),f+=o.x,c+=o.y),super(f,c,h,p),this.scale=v,this.intrinsicWidth=y.width,this.intrinsicHeight=y.height}};function Jh(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,i,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=Hs(a.effect)?a.effect.getKeyframes():[],d=l[l.length-1];if(!d)continue;const{transform:u,translate:c,scale:f}=d;typeof u=="string"&&u&&(r=u,o=!0),typeof c=="string"&&c&&(s=c,o=!0),typeof f=="string"&&f&&(i=f,o=!0)}return o?Ys({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function pr(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 ep=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(pr(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(pr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(pr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Ht(e){return e?e instanceof Ze(e).Element||Rr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function wr(e){if(!e)return!1;const{KeyboardEvent:t}=Ze(e.target);return e instanceof t}function tp(e){if(!e)return!1;const{PointerEvent:t}=Ze(e.target);return e instanceof t}function np(e){if(!Ht(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||rp(e)}function rp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var pi={};function Ji(e){const t=pi[e]==null?0:pi[e]+1;return pi[e]=t,`${e}-${t}`}var sa=({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 s=Je.distance(t.shape.center,n);return{id:r,value:1/s,type:Rn.PointerIntersection,priority:Pn.High}}return null},sp=({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:s}=e,i=Je.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Rn.ShapeIntersection,priority:Pn.Normal}}return null},xu=e=>{var t;return(t=sa(e))!=null?t:sp(e)},ip=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?ht.from(r.current.boundingRectangle).corners:void 0,a=ht.from(n.shape.boundingRectangle).corners.reduce((l,d,u)=>{var c;return l+Je.distance(Je.from(d),(c=i?.[u])!=null?c:s.current)},0)/4;return{id:n.id,value:1/a,type:Rn.Collision,priority:Pn.Normal}},op=Object.create,ia=Object.defineProperty,ap=Object.defineProperties,lp=Object.getOwnPropertyDescriptor,cp=Object.getOwnPropertyDescriptors,As=Object.getOwnPropertySymbols,wu=Object.prototype.hasOwnProperty,_u=Object.prototype.propertyIsEnumerable,ku=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ln=e=>{throw TypeError(e)},eo=(e,t,n)=>t in e?ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_r=(e,t)=>{for(var n in t||(t={}))wu.call(t,n)&&eo(e,n,t[n]);if(As)for(var n of As(t))_u.call(t,n)&&eo(e,n,t[n]);return e},oa=(e,t)=>ap(e,cp(t)),Qa=(e,t)=>ia(e,"name",{value:t,configurable:!0}),Su=(e,t)=>{var n={};for(var r in e)wu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&As)for(var r of As(e))t.indexOf(r)<0&&_u.call(e,r)&&(n[r]=e[r]);return n},Nn=e=>{var t;return[,,,op((t=e?.[ku("metadata")])!=null?t:null)]},$u=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Ln("Function expected"):e,up=(e,t,n,r,s)=>({kind:$u[e],name:t,metadata:r,addInitializer:i=>n._?Ln("Already initialized"):s.push(rr(i||null))}),Jt=(e,t)=>eo(t,ku("metadata"),e[3]),Pe=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},st=(e,t,n,r,s,i)=>{var o,a,l,d,u,c=t&7,f=!!(t&8),h=!!(t&16),p=c>3?e.length+1:c?f?1:2:0,m=$u[c+5],b=c>3&&(e[p-1]=[]),w=e[p]||(e[p]=[]),v=c&&(!h&&!f&&(s=s.prototype),c<5&&(c>3||!h)&&lp(c<4?s:{get[n](){return be(this,i)},set[n](y){return Ke(this,i,y)}},n));c?h&&c<4&&Qa(i,(c>2?"set ":c>1?"get ":"")+n):Qa(s,n);for(var g=r.length-1;g>=0;g--)d=up(c,n,l={},e[3],w),c&&(d.static=f,d.private=h,u=d.access={has:h?y=>dp(s,y):y=>n in y},c^3&&(u.get=h?y=>(c^1?be:Xt)(y,s,c^4?i:v.get):y=>y[n]),c>2&&(u.set=h?(y,_)=>Ke(y,s,_,c^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(c?c<4?h?i:v[m]:c>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,c^4||a===void 0?rr(a)&&(c>4?b.unshift(a):c?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?Ln("Object expected"):(rr(o=a.get)&&(v.get=o),rr(o=a.set)&&(v.set=o),rr(o=a.init)&&b.unshift(o));return c||Jt(e,s),v&&ia(s,n,v),h?c^4?i:v:s},aa=(e,t,n)=>t.has(e)||Ln("Cannot "+n),dp=(e,t)=>Object(t)!==t?Ln('Cannot use the "in" operator on this value'):e.has(t),be=(e,t,n)=>(aa(e,t,"read from private field"),n?n.call(e):t.get(e)),Ie=(e,t,n)=>t.has(e)?Ln("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ke=(e,t,n,r)=>(aa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Xt=(e,t,n)=>(aa(e,t,"access private method"),n),Ja={role:"button",roleDescription:"draggable"},fp="dnd-kit-description",hp="dnd-kit-announcement",pp={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."},gp={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 mp(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function vp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function yp(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 bp=["dragover","dragmove"],xp=class extends We{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=fp,announcement:s=hp}={},announcements:i=gp,screenReaderInstructions:o=pp,debounce:a=500}=t??{},l=n?`${r}-${n}`:Ji(r),d=n?`${s}-${n}`:Ji(s);let u,c,f,h;const p=(_=h)=>{!f||!_||f?.nodeValue!==_&&(f.nodeValue=_)},m=()=>Is.schedule(p),b=wp(m,a),w=Object.entries(i).map(([_,S])=>this.manager.monitor.addEventListener(_,(E,A)=>{const T=f;if(!T)return;const D=S?.(E,A);D&&T.nodeValue!==D&&(h=D,bp.includes(_)?b():(m(),b.cancel()))})),v=()=>{let _=[];u?.isConnected||(u=vp(l,o.draggable),_.push(u)),c?.isConnected||(c=yp(d),f=document.createTextNode(""),c.appendChild(f),_.push(c)),_.length>0&&document.body.append(..._)},g=new Set;function y(){for(const _ of g)_()}this.registerEffect(()=>{var _;g.clear();for(const S of this.manager.registry.draggables.value){const E=(_=S.handle)!=null?_:S.element;if(E){(!u||!c)&&g.add(v),(!mp(E)||ea())&&!E.hasAttribute("tabindex")&&g.add(()=>E.setAttribute("tabindex","0")),!E.hasAttribute("role")&&E.tagName.toLowerCase()!=="button"&&g.add(()=>E.setAttribute("role",Ja.role)),E.hasAttribute("aria-roledescription")||g.add(()=>E.setAttribute("aria-roledescription",Ja.roleDescription)),E.hasAttribute("aria-describedby")||g.add(()=>E.setAttribute("aria-describedby",l));for(const T of["aria-pressed","aria-grabbed"]){const D=String(S.isDragging);E.getAttribute(T)!==D&&g.add(()=>E.setAttribute(T,D))}const A=String(S.disabled);E.getAttribute("aria-disabled")!==A&&g.add(()=>E.setAttribute("aria-disabled",A))}}g.size>0&&Is.schedule(y)}),this.destroy=()=>{super.destroy(),u?.remove(),c?.remove(),w.forEach(_=>_())}}};function wp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Ms=new Map,Tu,Ou,Eu,Cu,to,gr,yt,la,Tn,Iu,Du,Au,Mu,Mt=class extends(to=Pr,Cu=[he],Eu=[Ee],Ou=[Ee],Tu=[Ee],to){constructor(t,n){super(t,n),Pe(yt,5,this),Ie(this,Tn),Ie(this,gr,new Set),Ie(this,la,Pe(yt,8,this,new Set)),Pe(yt,11,this),this.registerEffect(Xt(this,Tn,Iu))}register(t){return be(this,gr).add(t),()=>{be(this,gr).delete(t)}}addRoot(t){return fe(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{fe(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Os((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Os((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};yt=Nn(to);gr=new WeakMap;la=new WeakMap;Tn=new WeakSet;Iu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of be(this,gr))t.push(Xt(this,Tn,Du).call(this,n,r));return()=>{for(const n of t)n()}};Du=function(e,t){let n=Ms.get(e);n||(n=new Map,Ms.set(e,n));let r=n.get(t);if(!r){const i=Jo(e)?Xt(this,Tn,Au).call(this,e,n,t):Xt(this,Tn,Mu).call(this,e,n,t);if(!i)return()=>{};r=i,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Au=function(e,t,n){var r;const s=e.createElement("style"),{nonce:i}=(r=this.options)!=null?r:{};i&&s.setAttribute("nonce",i),s.textContent=n,e.head.prepend(s);const o=new MutationObserver(a=>{for(const l of a)for(const d of Array.from(l.removedNodes))if(d===s){e.head.prepend(s);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),s.remove(),t.delete(n),t.size===0&&Ms.delete(e)}}};Mu=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(ta(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Ms.delete(e)}}};st(yt,4,"additionalRoots",Cu,Mt,la);st(yt,2,"sourceRoot",Eu,Mt);st(yt,2,"targetRoot",Ou,Mt);st(yt,2,"roots",Tu,Mt);Jt(yt,Mt);Mt.configure=Mr(Mt);var Zs=Mt,_p=class extends We{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Zs),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},jr="data-dnd-",no=`${jr}dropping`,Le="--dnd-",dt=`${jr}dragging`,Ps=`${jr}placeholder`,kp=[dt,Ps,"popover","aria-pressed","aria-grabbing"],Sp=["view-transition-name"],$p=`
8
+ `)}var du=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:l,listener:d,options:c}=a,u=[o,a];o.addEventListener(l,d,c),this.entries.add(u),s.push(u)}const i=this.entries;return function(){for(const a of s){const[l,{type:d,listener:c,options:u}]=a;l.removeEventListener(d,c,u),i.delete(a)}}}};function Sn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Sh(e){const t=new Set;let n=Sn(e);for(;n;)t.add(n),n=Sn(n);return t}function $h(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function fu(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=$h(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Th(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 Oh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=br(e,t);return n>0&&r>0}var Eh=lu?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ps,Ch=class extends Eh{constructor(e){super(t=>{if(!oe(this,ps)){Xe(this,ps,!0);return}e(t,this)}),Ue(this,ps,!1)}};ps=new WeakMap;var Ua=Array.from({length:100},(e,t)=>t/100),hu=75,Wt,Es,St,Bt,Jn,Ne,fr,er,Cs,pu,gu,mu=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ue(this,Cs),this.disconnect=()=>{var i,o,a;Xe(this,fr,!0),(i=oe(this,St))==null||i.disconnect(),(o=oe(this,Bt))==null||o.disconnect(),oe(this,Jn).disconnect(),(a=oe(this,Ne))==null||a.remove()},Ue(this,Wt,!0),Ue(this,Es),Ue(this,St),Ue(this,Bt),Ue(this,Jn),Ue(this,Ne),Ue(this,fr,!1),Ue(this,er,fu(()=>{var i,o,a;const{element:l}=this;if((i=oe(this,Bt))==null||i.disconnect(),oe(this,fr)||!oe(this,Wt)||!l.isConnected)return;const d=(o=l.ownerDocument)!=null?o:document,{innerHeight:c,innerWidth:u}=(a=d.defaultView)!=null?a:window,f=l.getBoundingClientRect(),h=br(l,f),{top:p,left:m,bottom:b,right:x}=h,v=-Math.floor(p),g=-Math.floor(m),y=-Math.floor(u-x),_=-Math.floor(c-b),S=`${v}px ${y}px ${_}px ${g}px`;this.boundingClientRect=f,Xe(this,Bt,new IntersectionObserver(E=>{const[D]=E,{intersectionRect:T}=D;(D.intersectionRatio!==1?D.intersectionRatio:ht.intersectionRatio(T,br(l)))!==1&&oe(this,er).call(this)},{threshold:Ua,rootMargin:S,root:d})),oe(this,Bt).observe(l),iu(this,Cs,pu).call(this)},hu)),this.boundingClientRect=e.getBoundingClientRect(),Xe(this,Wt,Oh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(Xe(this,Ne,document.createElement("div")),oe(this,Ne).style.background="rgba(0,0,0,0.15)",oe(this,Ne).style.position="fixed",oe(this,Ne).style.pointerEvents="none",s.body.appendChild(oe(this,Ne))),Xe(this,Jn,new IntersectionObserver(i=>{var o,a;const l=i[i.length-1],{boundingClientRect:d,isIntersecting:c}=l,{width:u,height:f}=d,h=oe(this,Wt);Xe(this,Wt,c),!(!u&&!f)&&(h&&!c?((o=oe(this,Bt))==null||o.disconnect(),this.callback(null),(a=oe(this,St))==null||a.disconnect(),Xe(this,St,void 0),oe(this,Ne)&&(oe(this,Ne).style.visibility="hidden")):oe(this,er).call(this),c&&!oe(this,St)&&(Xe(this,St,new Ch(oe(this,er))),oe(this,St).observe(e)))},{threshold:Ua,root:s})),oe(this,Wt)&&!n.skipInitial&&this.callback(this.boundingClientRect),oe(this,Jn).observe(e)}};Wt=new WeakMap;Es=new WeakMap;St=new WeakMap;Bt=new WeakMap;Jn=new WeakMap;Ne=new WeakMap;fr=new WeakMap;er=new WeakMap;Cs=new WeakSet;pu=function(){oe(this,fr)||(iu(this,Cs,gu).call(this),!Th(this.boundingClientRect,oe(this,Es))&&(this.callback(this.boundingClientRect),Xe(this,Es,this.boundingClientRect)))};gu=function(){if(oe(this,Ne)){const{top:e,left:t,width:n,height:r}=br(this.element);oe(this,Ne).style.overflow="hidden",oe(this,Ne).style.visibility="visible",oe(this,Ne).style.top=`${Math.floor(e)}px`,oe(this,Ne).style.left=`${Math.floor(t)}px`,oe(this,Ne).style.width=`${Math.floor(n)}px`,oe(this,Ne).style.height=`${Math.floor(r)}px`}};var Hr=new WeakMap,Xr=new WeakMap;function Ih(e,t){let n=Hr.get(e);return n||(n={disconnect:new mu(e,s=>{const i=Hr.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Hr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Hr.delete(e),n.disconnect())}}function Ah(e,t){const n=new Set;for(const r of e){const s=Ih(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Dh(e,t){var n;const r=e.ownerDocument;if(!Xr.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(d=>d(l)),{capture:!0,passive:!0,signal:o.signal}),Xr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=Xr.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),Xr.delete(r))})}var tr,nr,gs,Yi,Mh=class{constructor(e,t,n){this.callback=t,Ue(this,tr),Ue(this,nr,!1),Ue(this,gs),Ue(this,Yi,fu(o=>{if(!oe(this,nr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of oe(this,gs))if(o.target.contains(a)){this.callback(oe(this,tr).boundingClientRect);break}}},hu));const r=Sh(e),s=Ah(r,t),i=Dh(e,oe(this,Yi));Xe(this,gs,r),Xe(this,tr,new mu(e,t,n)),this.disconnect=()=>{oe(this,nr)||(Xe(this,nr,!0),s(),i(),oe(this,tr).disconnect())}}};tr=new WeakMap;nr=new WeakMap;gs=new WeakMap;Yi=new WeakMap;function Zi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function yn(e){try{Zi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Ha(e){return!lu||!e?!1:e===Rn(e).scrollingElement}function vu(e){var t,n;const r=Ze(e),s=Ha(e)?yh(e):Xs(e),i=r.visualViewport,o=Ha(e)?{height:(t=i?.height)!=null?t:r.innerHeight,width:(n=i?.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}},l=a.current.y<=0,d=a.current.x<=0,c=a.current.y>=a.max.y,u=a.current.x>=a.max.x;return{rect:s,position:a,isTop:l,isLeft:d,isBottom:c,isRight:u}}function Ph(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=vu(e),{x:a,y:l}=t??{x:0,y:0},d=!n&&o.current.y+l>0,c=!r&&o.current.y+l<o.max.y,u=!s&&o.current.x+a>0,f=!i&&o.current.x+a<o.max.x;return{top:d,bottom:c,left:u,right:f,x:u||f,y:d||c}}var ra=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Is=new ra(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),jh=new ra(e=>setTimeout(e,50)),As=new Map,Rh=As.clear.bind(As);function mt(e,t=!1){if(!t)return Xa(e);let n=As.get(e);return n||(n=Xa(e),As.set(e,n),jh.schedule(Rh),n)}function Xa(e){return Ze(e).getComputedStyle(e)}function Lh(e,t=mt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Nh(e,t=mt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?n.test(i):!1})}var Fh={excludeElement:!0,escapeShadowDOM:!0};function Qi(e,t=Fh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(Jo(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&ta(a))return o(a.host);if(!Dt(a))return au(a)?o(a.parentElement):i;if(i.has(a))return i;const l=mt(a,!0);if(r&&a===e||Nh(a,l)&&i.add(a),Lh(a,l)){const{scrollingElement:d}=a.ownerDocument;return d&&i.add(d),i}return o(a.parentNode)}return e?o(e):i}function $n(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Sn(e);for(;r;){if(r===t)return n;const s=Xs(r),{x:i,y:o}=zh(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*i,n.scaleY=n.scaleY*o,r=Sn(r)}return n}function zh(e,t=Xs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Dt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=mt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Wh(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 xr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function Ys(e){var t,n,r,s,i,o,a,l,d;const{scale:c,transform:u,translate:f}=e,h=Wh(c),p=xr(f),m=Bh(u);if(!m&&!h&&!p)return null;const b={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},x={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},v={x:(i=m?.x)!=null?i:0,y:(o=m?.y)!=null?o:0,scaleX:(a=m?.scaleX)!=null?a:1,scaleY:(l=m?.scaleY)!=null?l:1};return{x:x.x+v.x,y:x.y+v.y,z:(d=p?.z)!=null?d:0,scaleX:b.x*v.scaleX,scaleY:b.y*v.scaleY}}function Bh(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 et=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(et||{}),Gh={x:.2,y:.2},qh={x:10,y:10};function Kh(e,t,n,r=25,s=Gh,i=qh){const{x:o,y:a}=t,{rect:l,isTop:d,isBottom:c,isLeft:u,isRight:f}=vu(e),h=$n(e),p=mt(e,!0),m=Ys(p),b=m!==null?m?.scaleX<0:!1,x=m!==null?m?.scaleY<0:!1,v=new ht(l.left*h.scaleX+h.x,l.top*h.scaleY+h.y,l.width*h.scaleX,l.height*h.scaleY),g={x:0,y:0},y={x:0,y:0},_={height:v.height*s.y,width:v.width*s.x};return _.height>0&&(!d||x&&!c)&&a<=v.top+_.height&&n?.y!==1&&o>=v.left-i.x&&o<=v.right+i.x?(g.y=x?1:-1,y.y=r*Math.abs((v.top+_.height-a)/_.height)):_.height>0&&(!c||x&&!d)&&a>=v.bottom-_.height&&n?.y!==-1&&o>=v.left-i.x&&o<=v.right+i.x&&(g.y=x?-1:1,y.y=r*Math.abs((v.bottom-_.height-a)/_.height)),_.width>0&&(!f||b&&!u)&&o>=v.right-_.width&&n?.x!==-1&&a>=v.top-i.y&&a<=v.bottom+i.y?(g.x=b?-1:1,y.x=r*Math.abs((v.right-_.width-o)/_.width)):_.width>0&&(!u||b&&!f)&&o<=v.left+_.width&&n?.x!==1&&a>=v.top-i.y&&a<=v.bottom+i.y&&(g.x=b?1:-1,y.x=r*Math.abs((v.left+_.width-o)/_.width)),{direction:g,speed:y}}function yu(e,{block:t="nearest",inline:n="nearest"}={}){if(!Dt(e))return;const r=Qi(e),s=[];for(const i of r){if(!Dt(i))continue;const{top:o,left:a}=Vh(e,i);let l=o,d=a;for(const c of s)l-=c.scrollTop,d-=c.scrollLeft;if(t!=="none"){const c=l<i.scrollTop,u=l+e.offsetHeight>i.scrollTop+i.clientHeight;c!==u&&(t==="center"?i.scrollTop=l-i.clientHeight/2+e.offsetHeight/2:c?i.scrollTop=l:i.scrollTop=l+e.offsetHeight-i.clientHeight)}if(n!=="none"){const c=d<i.scrollLeft,u=d+e.offsetWidth>i.scrollLeft+i.clientWidth;c!==u&&(n==="center"?i.scrollLeft=d-i.clientWidth/2+e.offsetWidth/2:c?i.scrollLeft=d:i.scrollLeft=d+e.offsetWidth-i.clientWidth)}s.push(i)}}function Ya(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Dt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function Vh(e,t){const n=Ya(e),r=Ya(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Uh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),l=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width*r:e.width,c=s?e.height*s:e.height;return{width:d,height:c,top:l,right:a+d,bottom:l+c,left:a}}function Hh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),l=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width/r:e.width,c=s?e.height/s:e.height;return{width:d,height:c,top:l,right:a+d,bottom:l+c,left:a}}function bu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Za(e,t=mt(e).translate,n=!0){if(n){const r=ou(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=xr(s);if(i)return i}}}if(t){const r=xr(t);if(r)return r}return{x:0,y:0,z:0}}var Xh=new ra(e=>setTimeout(e,0)),hr=new Map,Yh=hr.clear.bind(hr);function Zh(e){const t=e.ownerDocument;let n=hr.get(t);if(n)return n;n=t.getAnimations(),hr.set(t,n),Xh.schedule(Yh);const r=n.filter(s=>Hs(s.effect)&&s.effect.target===e);return hr.set(e,r),n}function Qh(e,t){const n=Zh(e).filter(r=>{var s,i;if(Hs(r.effect)){const{target:o}=r.effect;if((i=o&&((s=t.isValidTarget)==null?void 0:s.call(t,o)))!=null?i:!0)return r.effect.getKeyframes().some(l=>{for(const d of t.properties)if(l[d])return!0})}}).map(r=>{const{effect:s,currentTime:i}=r,o=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof i=="number"&&i<o)return r.currentTime=o,()=>{r.currentTime=i}});if(n.length>0)return()=>n.forEach(r=>r?.())}var ft=class extends ht{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=$n(e),ignoreTransforms:a,getBoundingClientRect:l=Xs}=t,d=Qh(e,{properties:["transform","translate","scale","width","height"],isValidTarget:_=>(_!==e||ea())&&_.contains(e)}),c=l(e);let{top:u,left:f,width:h,height:p}=c,m;const b=mt(e),x=Ys(b),v={x:(n=x?.scaleX)!=null?n:1,y:(r=x?.scaleY)!=null?r:1},g=Jh(e,b);d?.(),x&&(m=Hh(c,x,b.transformOrigin),(a||g)&&(u=m.top,f=m.left,h=m.width,p=m.height));const y={width:(s=m?.width)!=null?s:h,height:(i=m?.height)!=null?i:p};if(g&&!a&&m){const _=Uh(m,g,b.transformOrigin);u=_.top,f=_.left,h=_.width,p=_.height,v.x=g.scaleX,v.y=g.scaleY}o&&(a||(f*=o.scaleX,h*=o.scaleX,u*=o.scaleY,p*=o.scaleY),f+=o.x,u+=o.y),super(f,u,h,p),this.scale=v,this.intrinsicWidth=y.width,this.intrinsicHeight=y.height}};function Jh(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,i,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=Hs(a.effect)?a.effect.getKeyframes():[],d=l[l.length-1];if(!d)continue;const{transform:c,translate:u,scale:f}=d;typeof c=="string"&&c&&(r=c,o=!0),typeof u=="string"&&u&&(s=u,o=!0),typeof f=="string"&&f&&(i=f,o=!0)}return o?Ys({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function pr(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 ep=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(pr(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(pr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(pr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Ht(e){return e?e instanceof Ze(e).Element||jr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function wr(e){if(!e)return!1;const{KeyboardEvent:t}=Ze(e.target);return e instanceof t}function tp(e){if(!e)return!1;const{PointerEvent:t}=Ze(e.target);return e instanceof t}function np(e){if(!Ht(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||rp(e)}function rp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var pi={};function Ji(e){const t=pi[e]==null?0:pi[e]+1;return pi[e]=t,`${e}-${t}`}var sa=({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 s=Je.distance(t.shape.center,n);return{id:r,value:1/s,type:jn.PointerIntersection,priority:Pn.High}}return null},sp=({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:s}=e,i=Je.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:jn.ShapeIntersection,priority:Pn.Normal}}return null},xu=e=>{var t;return(t=sa(e))!=null?t:sp(e)},ip=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?ht.from(r.current.boundingRectangle).corners:void 0,a=ht.from(n.shape.boundingRectangle).corners.reduce((l,d,c)=>{var u;return l+Je.distance(Je.from(d),(u=i?.[c])!=null?u:s.current)},0)/4;return{id:n.id,value:1/a,type:jn.Collision,priority:Pn.Normal}},op=Object.create,ia=Object.defineProperty,ap=Object.defineProperties,lp=Object.getOwnPropertyDescriptor,cp=Object.getOwnPropertyDescriptors,Ds=Object.getOwnPropertySymbols,wu=Object.prototype.hasOwnProperty,_u=Object.prototype.propertyIsEnumerable,ku=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ln=e=>{throw TypeError(e)},eo=(e,t,n)=>t in e?ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_r=(e,t)=>{for(var n in t||(t={}))wu.call(t,n)&&eo(e,n,t[n]);if(Ds)for(var n of Ds(t))_u.call(t,n)&&eo(e,n,t[n]);return e},oa=(e,t)=>ap(e,cp(t)),Qa=(e,t)=>ia(e,"name",{value:t,configurable:!0}),Su=(e,t)=>{var n={};for(var r in e)wu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ds)for(var r of Ds(e))t.indexOf(r)<0&&_u.call(e,r)&&(n[r]=e[r]);return n},Nn=e=>{var t;return[,,,op((t=e?.[ku("metadata")])!=null?t:null)]},$u=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Ln("Function expected"):e,up=(e,t,n,r,s)=>({kind:$u[e],name:t,metadata:r,addInitializer:i=>n._?Ln("Already initialized"):s.push(rr(i||null))}),Jt=(e,t)=>eo(t,ku("metadata"),e[3]),Pe=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},st=(e,t,n,r,s,i)=>{var o,a,l,d,c,u=t&7,f=!!(t&8),h=!!(t&16),p=u>3?e.length+1:u?f?1:2:0,m=$u[u+5],b=u>3&&(e[p-1]=[]),x=e[p]||(e[p]=[]),v=u&&(!h&&!f&&(s=s.prototype),u<5&&(u>3||!h)&&lp(u<4?s:{get[n](){return be(this,i)},set[n](y){return Ke(this,i,y)}},n));u?h&&u<4&&Qa(i,(u>2?"set ":u>1?"get ":"")+n):Qa(s,n);for(var g=r.length-1;g>=0;g--)d=up(u,n,l={},e[3],x),u&&(d.static=f,d.private=h,c=d.access={has:h?y=>dp(s,y):y=>n in y},u^3&&(c.get=h?y=>(u^1?be:Xt)(y,s,u^4?i:v.get):y=>y[n]),u>2&&(c.set=h?(y,_)=>Ke(y,s,_,u^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(u?u<4?h?i:v[m]:u>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,u^4||a===void 0?rr(a)&&(u>4?b.unshift(a):u?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?Ln("Object expected"):(rr(o=a.get)&&(v.get=o),rr(o=a.set)&&(v.set=o),rr(o=a.init)&&b.unshift(o));return u||Jt(e,s),v&&ia(s,n,v),h?u^4?i:v:s},aa=(e,t,n)=>t.has(e)||Ln("Cannot "+n),dp=(e,t)=>Object(t)!==t?Ln('Cannot use the "in" operator on this value'):e.has(t),be=(e,t,n)=>(aa(e,t,"read from private field"),n?n.call(e):t.get(e)),Ie=(e,t,n)=>t.has(e)?Ln("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ke=(e,t,n,r)=>(aa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Xt=(e,t,n)=>(aa(e,t,"access private method"),n),Ja={role:"button",roleDescription:"draggable"},fp="dnd-kit-description",hp="dnd-kit-announcement",pp={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."},gp={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 mp(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function vp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function yp(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 bp=["dragover","dragmove"],xp=class extends We{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=fp,announcement:s=hp}={},announcements:i=gp,screenReaderInstructions:o=pp,debounce:a=500}=t??{},l=n?`${r}-${n}`:Ji(r),d=n?`${s}-${n}`:Ji(s);let c,u,f,h;const p=(_=h)=>{!f||!_||f?.nodeValue!==_&&(f.nodeValue=_)},m=()=>Is.schedule(p),b=wp(m,a),x=Object.entries(i).map(([_,S])=>this.manager.monitor.addEventListener(_,(E,D)=>{const T=f;if(!T)return;const A=S?.(E,D);A&&T.nodeValue!==A&&(h=A,bp.includes(_)?b():(m(),b.cancel()))})),v=()=>{let _=[];c?.isConnected||(c=vp(l,o.draggable),_.push(c)),u?.isConnected||(u=yp(d),f=document.createTextNode(""),u.appendChild(f),_.push(u)),_.length>0&&document.body.append(..._)},g=new Set;function y(){for(const _ of g)_()}this.registerEffect(()=>{var _;g.clear();for(const S of this.manager.registry.draggables.value){const E=(_=S.handle)!=null?_:S.element;if(E){(!c||!u)&&g.add(v),(!mp(E)||ea())&&!E.hasAttribute("tabindex")&&g.add(()=>E.setAttribute("tabindex","0")),!E.hasAttribute("role")&&E.tagName.toLowerCase()!=="button"&&g.add(()=>E.setAttribute("role",Ja.role)),E.hasAttribute("aria-roledescription")||g.add(()=>E.setAttribute("aria-roledescription",Ja.roleDescription)),E.hasAttribute("aria-describedby")||g.add(()=>E.setAttribute("aria-describedby",l));for(const T of["aria-pressed","aria-grabbed"]){const A=String(S.isDragging);E.getAttribute(T)!==A&&g.add(()=>E.setAttribute(T,A))}const D=String(S.disabled);E.getAttribute("aria-disabled")!==D&&g.add(()=>E.setAttribute("aria-disabled",D))}}g.size>0&&Is.schedule(y)}),this.destroy=()=>{super.destroy(),c?.remove(),u?.remove(),x.forEach(_=>_())}}};function wp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Ms=new Map,Tu,Ou,Eu,Cu,to,gr,yt,la,Tn,Iu,Au,Du,Mu,Mt=class extends(to=Pr,Cu=[he],Eu=[Ee],Ou=[Ee],Tu=[Ee],to){constructor(t,n){super(t,n),Pe(yt,5,this),Ie(this,Tn),Ie(this,gr,new Set),Ie(this,la,Pe(yt,8,this,new Set)),Pe(yt,11,this),this.registerEffect(Xt(this,Tn,Iu))}register(t){return be(this,gr).add(t),()=>{be(this,gr).delete(t)}}addRoot(t){return fe(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{fe(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Os((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Os((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};yt=Nn(to);gr=new WeakMap;la=new WeakMap;Tn=new WeakSet;Iu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of be(this,gr))t.push(Xt(this,Tn,Au).call(this,n,r));return()=>{for(const n of t)n()}};Au=function(e,t){let n=Ms.get(e);n||(n=new Map,Ms.set(e,n));let r=n.get(t);if(!r){const i=Jo(e)?Xt(this,Tn,Du).call(this,e,n,t):Xt(this,Tn,Mu).call(this,e,n,t);if(!i)return()=>{};r=i,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Du=function(e,t,n){var r;const s=e.createElement("style"),{nonce:i}=(r=this.options)!=null?r:{};i&&s.setAttribute("nonce",i),s.textContent=n,e.head.prepend(s);const o=new MutationObserver(a=>{for(const l of a)for(const d of Array.from(l.removedNodes))if(d===s){e.head.prepend(s);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),s.remove(),t.delete(n),t.size===0&&Ms.delete(e)}}};Mu=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(ta(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Ms.delete(e)}}};st(yt,4,"additionalRoots",Cu,Mt,la);st(yt,2,"sourceRoot",Eu,Mt);st(yt,2,"targetRoot",Ou,Mt);st(yt,2,"roots",Tu,Mt);Jt(yt,Mt);Mt.configure=Mr(Mt);var Zs=Mt,_p=class extends We{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Zs),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},Rr="data-dnd-",no=`${Rr}dropping`,Le="--dnd-",dt=`${Rr}dragging`,Ps=`${Rr}placeholder`,kp=[dt,Ps,"popover","aria-pressed","aria-grabbing"],Sp=["view-transition-name"],$p=`
9
9
  :is(:root,:host) [${dt}] {
10
10
  position: fixed !important;
11
11
  pointer-events: none !important;
@@ -60,64 +60,64 @@
60
60
  }
61
61
  }
62
62
  }
63
- [${dt}]::backdrop, [${jr}overlay]:not([${dt}]) {
63
+ [${dt}]::backdrop, [${Rr}overlay]:not([${dt}]) {
64
64
  display: none;
65
65
  visibility: hidden;
66
66
  }
67
- `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Tp(e,t="hidden"){return fe(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Op(n,r.registry.droppables),i=[],o=wh(n),{remove:a}=o;return Ep(s,o,i),Cp(o,t),o.remove=()=>{i.forEach(l=>l()),a.call(o)},o})}function Op(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${jr}${Ji("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Ep(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),Xi.set(a,o),n.push(()=>{Xi.delete(a),r.proxy=void 0})}}function Cp(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Ps,t)}function Pu(e,t){return e===t?!0:Sn(e)===Sn(t)}function el(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Ht(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>yn(t))}function ro(e){return e.tagName==="TR"}function Ip(e,t,n){const r=new MutationObserver(s=>{let i=!1;for(const o of s){if(o.target!==e){i=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||kp.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(pr(e)&&pr(t)){const d=e.style;for(const u of Array.from(t.style))d.getPropertyValue(u)===""&&t.style.removeProperty(u);for(const u of Array.from(d)){if(Sp.includes(u)||u.startsWith(Le))continue;const c=d.getPropertyValue(u);t.style.setProperty(u,c)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Dp(e,t,n){const r=new MutationObserver(s=>{for(const i of s)if(i.addedNodes.length!==0)for(const o of Array.from(i.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),yn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),yn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),yn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Ap(e){return new ResizeObserver(()=>{var t,n,r;const s=new ft(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),i=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-s.width)*i.x+e.delta.x,a=(e.height-s.height)*i.y+e.delta.y,l=cu();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},Le),(n=e.getElementMutationObserver())==null||n.takeRecords(),ro(e.element)&&ro(e.placeholder)){const m=Array.from(e.element.cells),b=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(m.map(w=>w.style.width));for(const[w,v]of m.entries()){const g=b[w];v.style.width=`${g.getBoundingClientRect().width}px`}}const d=(r=e.getTranslate())!=null?r:{x:0,y:0},u=e.left+o+l.x+d.x,c=e.top+a+l.y+d.y,f=s.width-e.widthOffset,h=s.height-e.heightOffset,p=e.frameTransform;e.dragOperation.shape=new ht(u*p.scaleX+p.x,c*p.scaleY+p.y,f*p.scaleX,h*p.scaleY)})}var Mp=250,Pp="ease";function Rp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const v=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(v).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Mp,easing:a=Pp}=i??{};yn(e.feedbackElement);const[,l]=(t=ou(e.feedbackElement,v=>"translate"in v))!=null?t:[];l?.pause();const d=(n=e.placeholder)!=null?n:e.element,u={frameTransform:Pu(e.feedbackElement,d)?null:void 0},c=new ft(e.feedbackElement,u),f=(r=xr(mt(e.feedbackElement).translate))!=null?r:e.translate,h=new ft(d,u),p=ht.delta(c,h,e.alignment),m={x:f.x-p.x,y:f.y-p.y},b=Math.round(c.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${c.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${c.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},w=Math.round(c.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${c.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${c.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Le),e.feedbackElement.setAttribute(no,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),bu({element:e.feedbackElement,keyframes:oa(_r(_r({},b),w),{translate:[`${f.x}px ${f.y}px 0`,`${m.x}px ${m.y}px 0`]}),options:{duration:na(Ze(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(no),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Ru,so,kr,ca,ms,ju,Lu,On=class extends(so=We,Ru=[he],so){constructor(t,n){super(t,n),Ie(this,ms),Ie(this,ca,Pe(kr,8,this)),Pe(kr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(Zs),s=r?.register($p);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Xt(this,ms,ju).bind(this,r)),this.registerEffect(Xt(this,ms,Lu))}};kr=Nn(so);ca=new WeakMap;ms=new WeakSet;ju=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Os(t);if(n)return e.addRoot(n)};Lu=function(){var e,t,n,r,s,i,o;const{state:a,manager:l,options:d}=this,{dragOperation:u}=l,{position:c,source:f,status:h}=u;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:p}=f,m=f.pluginConfig(On),b=(t=(e=m?.feedback)!=null?e:d?.feedback)!=null?t:"default",w=typeof b=="function"?b(f,l):b;if(!p||w==="none"||!h.initialized||h.initializing)return;const{initial:v}=a,g=(n=this.overlay)!=null?n:p,y=$n(g),_=$n(p),S=!Pu(p,g),E=new ft(p,{frameTransform:S?_:null,ignoreTransforms:!S}),A={x:_.scaleX/y.scaleX,y:_.scaleY/y.scaleY};let{width:T,height:D,top:q,left:P}=E;S&&(T=T/A.x,D=D/A.y);const z=new ep(g),U=mt(p),{transition:K,translate:Z,boxSizing:J,paddingBlockStart:ie,paddingBlockEnd:de,paddingInlineStart:I,paddingInlineEnd:V,borderInlineStartWidth:B,borderInlineEndWidth:R,borderBlockStartWidth:G,borderBlockEndWidth:ne}=U,Y=K.split(",").filter(ye=>!/^\s*(transform|translate|scale)\b/.test(ye)).join(","),H=Ys(U),L=U.transform,C=w==="clone",W=J==="content-box",M=W?parseInt(I)+parseInt(V)+parseInt(B)+parseInt(R):0,ee=W?parseInt(ie)+parseInt(de)+parseInt(G)+parseInt(ne):0,X=w!=="move"&&!this.overlay?Tp(f,C?"clone":"hidden"):null,le=fe(()=>wr(l.dragOperation.activatorEvent));if(!v.translate){if(this.overlay&&H)v.translate={x:H.x,y:H.y};else if(Z!=="none"){const ye=xr(Z);ye&&(v.translate=ye)}}if(!v.transformOrigin){const ye=fe(()=>c.current),De=P+((r=H?.x)!=null?r:0),He=q+((s=H?.y)!=null?s:0);v.transformOrigin={x:(ye.x-De*y.scaleX-y.x)/(T*y.scaleX),y:(ye.y-He*y.scaleY-y.y)/(D*y.scaleY)}}const{transformOrigin:ce}=v,N=q*y.scaleY+y.y,Q=P*y.scaleX+y.x;if(!v.coordinates&&(v.coordinates={x:Q,y:N},A.x!==1||A.y!==1)){const{scaleX:ye,scaleY:De}=_,{x:He,y:kt}=ce;v.coordinates.x+=(T*ye-T)*He,v.coordinates.y+=(D*De-D)*kt}v.dimensions||(v.dimensions={width:T,height:D}),v.frameTransform||(v.frameTransform=y);const me={x:v.coordinates.x-Q,y:v.coordinates.y-N},se={width:(v.dimensions.width*v.frameTransform.scaleX-T*y.scaleX)*ce.x,height:(v.dimensions.height*v.frameTransform.scaleY-D*y.scaleY)*ce.y},te={x:me.x/y.scaleX+se.width,y:me.y/y.scaleY+se.height},j={left:P+te.x,top:q+te.y};g.setAttribute(dt,"true");const F=fe(()=>u.transform),re=(i=v.translate)!=null?i:{x:0,y:0},ue=F.x*y.scaleX+re.x,je=F.y*y.scaleY+re.y,Rt=cu();z.set({width:T-M,height:D-ee,top:j.top+Rt.y,left:j.left+Rt.x,translate:`${ue}px ${je}px 0`,transform:this.overlay?"none":L,transition:Y?`${Y}, translate 0ms linear`:"translate 0ms linear",scale:S?`${A.x} ${A.y}`:"","transform-origin":`${ce.x*100}% ${ce.y*100}%`},Le),X&&(p.insertAdjacentElement("afterend",X),d?.rootElement&&(typeof d.rootElement=="function"?d.rootElement(f):d.rootElement).appendChild(p)),Zi(g)&&(g.hasAttribute("popover")||g.setAttribute("popover","manual"),yn(g),g.addEventListener("beforetoggle",el));let ut,zn,_t;const Wn=Ap({placeholder:X,element:p,feedbackElement:g,frameTransform:y,transformOrigin:ce,width:T,height:D,top:q,left:P,widthOffset:M,heightOffset:ee,delta:te,styles:z,dragOperation:u,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>ut,getSavedCellWidths:()=>_t,setSavedCellWidths:ye=>{_t=ye}}),Gr=new ft(g);fe(()=>u.shape=Gr);const Bn=Ze(g),jt=ye=>{this.manager.actions.stop({event:ye})},Zd=na(Bn);le&&Bn.addEventListener("resize",jt),fe(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),X&&(Wn.observe(X),ut=Ip(p,X,C),zn=Dp(p,X,g));const Ca=(o=l.dragOperation.source)==null?void 0:o.id,Qd=()=>{var ye;if(!le||Ca==null)return;const De=l.registry.draggables.get(Ca),He=(ye=De?.handle)!=null?ye:De?.element;At(He)&&He.focus()},si=()=>{ut?.disconnect(),zn?.disconnect(),Wn.disconnect(),Bn.removeEventListener("resize",jt),Zi(g)&&(g.removeEventListener("beforetoggle",el),g.removeAttribute("popover")),g.removeAttribute(dt),z.reset();const ye=()=>{var De;if(_t&&ro(p)){const ii=Array.from(p.cells);for(const[qr,tn]of ii.entries())tn.style.width=(De=_t[qr])!=null?De:""}f.status="idle";const He=a.current.translate!=null,kt=u.status.dragging;X&&(!kt&&He||X.parentElement!==g.parentElement)&&g.isConnected&&X.replaceWith(g),X?.remove()};g===this.overlay?setTimeout(ye,0):ye()},Jd=d?.dropAnimation,Ia=this,ef=Dr(()=>{var ye,De,He;const{transform:kt,status:ii}=u;if(!(!kt.x&&!kt.y&&!a.current.translate)&&ii.dragging){const qr=(ye=v.translate)!=null?ye:{x:0,y:0},tn={x:kt.x/y.scaleX+qr.x,y:kt.y/y.scaleY+qr.y},Da=a.current.translate,tf=fe(()=>u.modifiers),oi=fe(()=>{var qn;return(qn=u.shape)==null?void 0:qn.current}),Gn=d?.keyboardTransition,Aa=le&&!Zd&&Gn!==null?`${(De=Gn?.duration)!=null?De:250}ms ${(He=Gn?.easing)!=null?He:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(z.set({transition:Y?`${Y}, translate ${Aa}`:`translate ${Aa}`,translate:`${tn.x}px ${tn.y}px 0`},Le),ut?.takeRecords(),oi&&oi!==Gr&&Da&&!tf.length){const qn=Je.delta(tn,Da);u.shape=ht.from(oi.boundingRectangle).translate(qn.x*y.scaleX,qn.y*y.scaleY)}else u.shape=new ft(g);a.current.translate=tn}},function(){if(u.status.dropped){this.dispose(),f.status="dropping";const ye=m?.dropAnimation!==void 0?m.dropAnimation:Ia.dropAnimation!==void 0?Ia.dropAnimation:Jd;let De=a.current.translate;const He=De!=null;if(!De&&p!==g&&(De={x:0,y:0}),!De||ye===null){si();return}l.renderer.rendering.then(()=>{Rp({source:f,element:p,feedbackElement:g,placeholder:X,translate:De,moved:He,transition:K,alignment:f.alignment,styles:z,animation:ye??void 0,getElementMutationObserver:()=>ut,cleanup:si,restoreFocus:Qd})})}});return()=>{si(),ef()}};st(kr,4,"overlay",Ru,On,ca);Jt(kr,On);On.configure=Mr(On);var ua=On,Kn=!0,jp=!1,Nu,Fu,zu,Wu,Ot,da,fa;Wu=(zu=[he],et.Forward),Fu=(Nu=[he],et.Reverse);var Sr=class{constructor(){Ie(this,da,Pe(Ot,8,this,Kn)),Pe(Ot,11,this),Ie(this,fa,Pe(Ot,12,this,Kn)),Pe(Ot,15,this)}isLocked(e){return e===et.Idle?!1:e==null?this[et.Forward]===Kn&&this[et.Reverse]===Kn:this[e]===Kn}unlock(e){e!==et.Idle&&(this[e]=jp)}};Ot=Nn(null);da=new WeakMap;fa=new WeakMap;st(Ot,4,Wu,zu,Sr,da);st(Ot,4,Fu,Nu,Sr,fa);Jt(Ot,Sr);var Lp=[et.Forward,et.Reverse],tl=class{constructor(){this.x=new Sr,this.y=new Sr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Np=class extends We{constructor(e){super(e);const t=En(new tl);let n=null;this.signal=t,rt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new tl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:nl(s.x,n.x),y:nl(s.y,n.y)},o=t.peek();Te(()=>{for(const a of mc)for(const l of Lp)i[a]===l&&o[a].unlock(l);t.value=o})}n=s})}get current(){return this.signal.peek()}};function nl(e,t){return Math.sign(e-t)}var Bu,io,$r,ha,$t,oo,Lr=class extends(io=Pr,Bu=[he],io){constructor(e){super(e),Ie(this,ha,Pe($r,8,this,!1)),Pe($r,11,this),Ie(this,$t),Ie(this,oo,()=>{if(!be(this,$t))return;const{element:i,by:o}=be(this,$t);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return Ke(this,$t,void 0),!1;const{position:d}=this.manager.dragOperation,u=d?.current;if(u){const{by:c}=i??{},f=c?{x:rl(c.x),y:rl(c.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of l){const m=Ph(p,c);if(m.x||m.y){const{speed:b,direction:w}=Kh(p,u,f,o?.acceleration,o?.threshold);if(h)for(const v of mc)h[v].isLocked(w[v])&&(b[v]=0,w[v]=0);if(w.x||w.y){const{x:v,y:g}=c??w,y=v*b.x,_=g*b.y;if(y||_){const S=(a=be(this,$t))==null?void 0:a.by;if(this.autoScrolling&&S&&(S.x&&!y||S.y&&!_))continue;return Ke(this,$t,{element:p,by:{x:y,y:_}}),Is.schedule(be(this,oo)),!0}}}}}return Ke(this,$t,void 0),!1};let t=null,n=null;const r=Ri(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=uu(Os(o?.element),i.current);return a&&(t=a),a??t}),s=Ri(()=>{const i=r.value,{documentElement:o}=jn(i);if(!i||i===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const d=Qi(l,{excludeElement:!1});return n=d,d}}if(i){const a=Qi(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},it);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Np(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!wr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};$r=Nn(io);ha=new WeakMap;$t=new WeakMap;oo=new WeakMap;st($r,4,"autoScrolling",Bu,Lr,ha);Jt($r,Lr);function rl(e){return e>0?et.Forward:e<0?et.Reverse:et.Idle}var Fp=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))}},zp=new Fp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Wp=10,ao=class extends We{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Lr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=rt(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const d={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(o=this.options)==null?void 0:o.threshold};if(r.scroll(void 0,d)){r.autoScrolling=!0;const c=setInterval(()=>zp.schedule(()=>r.scroll(void 0,d)),Wp);return()=>{clearInterval(c)}}else r.autoScrolling=!1}})}};ao.configure=Mr(ao);var Gu=ao,sl={capture:!0,passive:!0},sr,Bp=class extends Pr{constructor(e){super(e),Ie(this,sr),this.handleScroll=()=>{be(this,sr)==null&&Ke(this,sr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ke(this,sr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=rt(()=>{var n,r,s;if(t.status.dragging){const o=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return o.addEventListener("scroll",this.handleScroll,sl),()=>{o.removeEventListener("scroll",this.handleScroll,sl)}}})}};sr=new WeakMap;var Gp="* { user-select: none !important; -webkit-user-select: none !important; }",qp=class extends We{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Zs),n=t?.register(Gp);if(this.destroy=rt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return gi(),document.addEventListener("selectionchange",gi,{capture:!0}),()=>{document.removeEventListener("selectionchange",gi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function gi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var ir=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}}),fn,Rs=class extends _n{constructor(t,n){super(t),this.manager=t,this.options=n,Ie(this,fn,[]),this.listeners=new du,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Ht(r.target)||s.disabled)return;const{keyboardCodes:o=ir.keyboardCodes,preventActivation:a=ir.preventActivation}=i??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,i))}}bind(t,n=this.options){return rt(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{wr(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),yu(s);const{center:i}=new ft(s);if(this.manager.actions.start({event:t,coordinates:{x:i.x,y:i.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=jn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:d=>this.handleKeyDown(d,n,r),options:{capture:!0}}])];be(this,fn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=ir.keyboardCodes}=r??{};if(nn(t,[...s.end,...s.cancel])){t.preventDefault();const i=nn(t,s.cancel);this.handleEnd(t,i);return}nn(t,s.up)?this.handleMove("up",t):nn(t,s.down)&&this.handleMove("down",t),nn(t,s.left)?this.handleMove("left",t):nn(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:i}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:ir.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!i){switch(t){case"up":a={x:0,y:-l.y*o};break;case"down":a={x:0,y:l.y*o};break;case"left":a={x:-l.x*o,y:0};break;case"right":a={x:l.x*o,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(Gu);t?.disabled===!1&&(t.disable(),be(this,fn).push(()=>{t.enable()}))}cleanup(){be(this,fn).forEach(t=>t()),Ke(this,fn,[])}destroy(){this.cleanup(),this.listeners.clear()}};fn=new WeakMap;Rs.configure=Mr(Rs);Rs.defaults=ir;var qu=Rs;function nn(e,t){return t.includes(e.code)}var Gt,Kp=class extends Hc{constructor(){super(...arguments),Ie(this,Gt)}onEvent(e){switch(e.type){case"pointerdown":Ke(this,Gt,kn(e));break;case"pointermove":if(!be(this,Gt))return;const{x:t,y:n}=kn(e),r={x:t-be(this,Gt).x,y:n-be(this,Gt).y},{tolerance:s}=this.options;if(s&&qi(r,s)){this.abort();return}qi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Ke(this,Gt,void 0)}};Gt=new WeakMap;var hn,qt,Vp=class extends Hc{constructor(){super(...arguments),Ie(this,hn),Ie(this,qt)}onEvent(e){switch(e.type){case"pointerdown":Ke(this,qt,kn(e)),Ke(this,hn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!be(this,qt))return;const{x:t,y:n}=kn(e),r={x:t-be(this,qt).x,y:n-be(this,qt).y};qi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){be(this,hn)&&(clearTimeout(be(this,hn)),Ke(this,qt,void 0),Ke(this,hn,void 0))}};hn=new WeakMap;qt=new WeakMap;var vn=class{};vn.Delay=Vp;vn.Distance=Kp;var lo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Ht(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new vn.Delay({value:250,tolerance:5})]:np(s)&&!e.defaultPrevented?[new vn.Delay({value:200,tolerance:0})]:[new vn.Delay({value:200,tolerance:10}),new vn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Ht(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=kh(r);return s===t.element?!1:!!s}}),pn,js=class extends _n{constructor(t,n){super(t),this.manager=t,this.options=n,Ie(this,pn,new Set),this.listeners=new du,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=lo.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return rt(()=>{var s;const i=new AbortController,{signal:o}=i,a=d=>{tp(d)&&this.handlePointerDown(d,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const d of l)d&&(Xp(d.ownerDocument.defaultView),d.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Ht(t.target)||n.disabled||Up(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=lo.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=At(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=$n(n.element),{x:l,y:d}=kn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:d*a.scaleY+a.y};const u=this.activationConstraints(t,n,r);t.sensor=this;const c=new ph(u,m=>this.handleStart(n,m));c.signal.onabort=()=>this.handleCancel(t),c.onEvent(t),this.controller=c;const f=Hi(),h=this.listeners.bind(f,[{type:"pointermove",listener:m=>this.handlePointerMove(m,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:Yr,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};be(this,pn).add(p)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const i=kn(t),o=$n(n.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=i,Is.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=jn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=Ht(n.target)?[n.target,a]:a,d=this.listeners.bind(l,[{type:"touchmove",listener:Yr,options:{passive:!1}},{type:"click",listener:Yr},{type:"contextmenu",listener:Yr},{type:"keydown",listener:this.handleKeyDown}]);be(this,pn).add(d)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},be(this,pn).forEach(n=>n()),be(this,pn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};pn=new WeakMap;js.configure=Mr(js);js.defaults=lo;var co=js;function Up(e){return"sensor"in e}function Yr(e){e.preventDefault()}function Hp(){}var il=new WeakSet;function Xp(e){!e||il.has(e)||(e.addEventListener("touchmove",Hp,{capture:!1,passive:!1}),il.add(e))}var bn={modifiers:[],plugins:[xp,Gu,_p,ua,qp],sensors:[co,qu]},Ku=class extends vh{constructor(e={}){const t=lt(e.plugins,bn.plugins),n=lt(e.sensors,bn.sensors),r=lt(e.modifiers,bn.modifiers);super(oa(_r({},e),{plugins:[Bp,Lr,Zs,...t],sensors:n,modifiers:r}))}},Vu,Uu,uo,Et,pa,ga,Qs=class extends(uo=pt,Uu=[he],Vu=[he],uo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=Su(n,["element","effects","handle"]);super(_r({effects:()=>[...s(),()=>{var a,l;const{manager:d}=this;if(!d)return;const c=((l=(a=this.sensors)==null?void 0:a.map(vr))!=null?l:[...d.sensors]).map(f=>{const h=f instanceof _n?f:d.registry.register(f.plugin),p=f instanceof _n?void 0:f.options;return h.bind(this,p)});return function(){c.forEach(h=>h())}}]},o),t),Ie(this,pa,Pe(Et,8,this)),Pe(Et,11,this),Ie(this,ga,Pe(Et,12,this)),Pe(Et,15,this),this.element=r,this.handle=i}};Et=Nn(uo);pa=new WeakMap;ga=new WeakMap;st(Et,4,"handle",Uu,Qs,pa);st(Et,4,"element",Vu,Qs,ga);Jt(Et,Qs);var Hu,Xu,fo,Ct,ma,mi,Yu,Zu,mr,va,Js=class extends(fo=gt,Xu=[he],Hu=[he],fo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=Su(n,["element","effects"]);const{collisionDetector:o=xu}=i,a=d=>{const{manager:u,element:c}=this;if(!c||d===null){this.shape=void 0;return}if(!u)return;const f=new ft(c),h=fe(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},l=En(!1);super(oa(_r({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:d,manager:u}=this;if(!u)return;const{dragOperation:c}=u,{source:f}=c;l.value=!!(f&&c.status.initialized&&d&&!this.disabled&&this.accepts(f))},()=>{const{element:d}=this;if(l.value&&d){const u=new Mh(d,a);return()=>{u.disconnect(),this.shape=void 0}}},()=>{var d;if((d=this.manager)!=null&&d.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Ie(this,mr),Ie(this,ma,Pe(Ct,8,this)),Pe(Ct,11,this),Ie(this,va,Pe(Ct,12,this)),Pe(Ct,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ke(this,mr,e,Zu)}get element(){var e;return(e=this.proxy)!=null?e:be(this,mr,Yu)}};Ct=Nn(fo);ma=new WeakMap;mr=new WeakSet;va=new WeakMap;mi=st(Ct,20,"#element",Xu,mr,ma),Yu=mi.get,Zu=mi.set;st(Ct,4,"proxy",Hu,Js,va);Jt(Ct,Js);function Yp(e){return e!=null&&typeof e=="object"&&"current"in e}function xn(e){var t;if(e!=null)return Yp(e)?(t=e.current)!=null?t:void 0:e}var Zp=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Fn=Zp?k.useLayoutEffect:k.useEffect;function Qp(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Qu(e,t){const n=k.useRef(new Map),r=Qp();return Fn(()=>{if(!e){n.current.clear();return}return rt(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[l]=a,d=fe(()=>a[1]),u=e[l];d!==u&&(i=!0,n.current.set(l,u),o=(s=t?.(l,d,u))!=null?s:!1)}i&&(o?queueMicrotask(()=>nf.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(s,i){const o=s[i];return n.current.set(i,o),o}}),[e])}function Jp(e,t){e()}function rn(e){const t=k.useRef(e);return Fn(()=>{t.current=e},[e]),t}function Se(e,t,n=k.useEffect,r=Object.is){const s=k.useRef(e);n(()=>{const i=s.current;r(e,i)||(s.current=e,t(e,i))},[t,e])}function vs(e,t){const n=k.useRef(xn(e));Fn(()=>{const r=xn(e);r!==n.current&&(n.current=r,t(r))})}var eg=Object.defineProperty,tg=Object.defineProperties,ng=Object.getOwnPropertyDescriptors,Ls=Object.getOwnPropertySymbols,Ju=Object.prototype.hasOwnProperty,ed=Object.prototype.propertyIsEnumerable,ol=(e,t,n)=>t in e?eg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rg=(e,t)=>{for(var n in t||(t={}))Ju.call(t,n)&&ol(e,n,t[n]);if(Ls)for(var n of Ls(t))ed.call(t,n)&&ol(e,n,t[n]);return e},sg=(e,t)=>tg(e,ng(t)),ig=(e,t)=>{var n={};for(var r in e)Ju.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ls)for(var r of Ls(e))t.indexOf(r)<0&&ed.call(e,r)&&(n[r]=e[r]);return n},og=new Ku,td=k.createContext(og),ag=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),s=k.useRef(null),i=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{i.current=l})),k.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return Fn(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),vi=[void 0,it];function lg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:l}=t,d=ig(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const u=k.useRef(null),{plugins:c,modifiers:f,sensors:h}=d,p=lt(c,bn.plugins),m=lt(h,bn.sensors),b=lt(f,bn.modifiers),w=rn(s),v=rn(i),g=rn(a),y=rn(o),_=rn(l),S=rn(r),E=cg(()=>{var A;return(A=d.manager)!=null?A:new Ku(d)});return k.useEffect(()=>{if(!u.current)throw new Error("Renderer not found");const{renderer:A,trackRendering:T}=u.current,{monitor:D}=E;E.renderer=A;const q=[D.addEventListener("beforedragstart",P=>{const z=w.current;z&&T(()=>z(P,E))}),D.addEventListener("dragstart",P=>{var z;return(z=v.current)==null?void 0:z.call(v,P,E)}),D.addEventListener("dragover",P=>{const z=g.current;z&&T(()=>z(P,E))}),D.addEventListener("dragmove",P=>{const z=y.current;z&&T(()=>z(P,E))}),D.addEventListener("dragend",P=>{const z=_.current;z&&T(()=>z(P,E))}),D.addEventListener("collision",P=>{var z;return(z=S.current)==null?void 0:z.call(S,P,E)})];return()=>q.forEach(P=>P())},[E]),Se(p,()=>E&&(E.plugins=p),...vi),Se(m,()=>E&&(E.sensors=m),...vi),Se(b,()=>E&&(E.modifiers=b),...vi),x.jsxs(td.Provider,{value:E,children:[x.jsx(ag,{ref:u,children:n}),n]})}function cg(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function ug(){return k.useContext(td)}function nd(e){var t;const n=(t=ug())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Fn(r.register,[n,r]),r}var dg=Object.create,rd=Object.defineProperty,fg=Object.getOwnPropertyDescriptor,sd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ei=e=>{throw TypeError(e)},hg=(e,t,n)=>t in e?rd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pg=e=>{var t;return[,,,dg((t=e?.[sd("metadata")])!=null?t:null)]},id=["class","method","getter","setter","accessor","field","value","get","set"],od=e=>e!==void 0&&typeof e!="function"?ei("Function expected"):e,gg=(e,t,n,r,s)=>({kind:id[e],name:t,metadata:r,addInitializer:i=>n._?ei("Already initialized"):s.push(od(i||null))}),mg=(e,t)=>hg(t,sd("metadata"),e[3]),vg=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},ad=(e,t,n,r,s,i)=>{for(var o,a,l,d,u=t&7,c=!1,f=!1,h=2,p=id[u+5],m=e[h]||(e[h]=[]),b=(s=s.prototype,fg(s,n)),w=r.length-1;w>=0;w--)l=gg(u,n,a={},e[3],m),l.static=c,l.private=f,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[w])(b[p],l),a._=1,od(o)&&(b[p]=o);return b&&rd(s,n,b),s},ld=(e,t,n)=>t.has(e)||ei("Cannot "+n),yg=(e,t,n)=>(ld(e,t,"read from private field"),t.get(e)),bg=(e,t,n)=>t.has(e)?ei("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),xg=(e,t,n,r)=>(ld(e,t,"write to private field"),t.set(e,n),n),Vt=class ho{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ho(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new ho(t,n)}},cd,ud,po,ys,Nr,ya=class extends(po=Zt,ud=[Ee],cd=[Ee],po){constructor(e){const t=Vt.from(e);super(t,(n,r)=>Vt.equals(n,r)),vg(Nr,5,this),bg(this,ys,0),this.velocity={x:0,y:0}}get delta(){return Vt.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=Vt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-yg(this,ys),o=a=>Math.round(a/i*100);Te(()=>{xg(this,ys,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(Vt.from(e)),this.velocity={x:0,y:0}}};Nr=pg(po);ys=new WeakMap;ad(Nr,2,"delta",ud,ya);ad(Nr,2,"direction",cd,ya);mg(Nr,ya);var dd=(e=>(e.Horizontal="x",e.Vertical="y",e))(dd||{});Object.values(dd);var wg=({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 s=Vt.distance(t.shape.center,n);return{id:r,value:1/s,type:Rn.PointerIntersection,priority:Pn.High}}return null},_g=({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:s}=e,i=Vt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Rn.ShapeIntersection,priority:Pn.Normal}}return null},kg=e=>{var t;return(t=wg(e))!=null?t:_g(e)};function Sg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,l=nd(u=>new Js(sg(rg({},e),{register:!1,element:xn(s)}),u)),d=Qu(l);return Se(i,()=>l.id=i),vs(s,u=>l.element=u),Se(o,()=>l.accept=o,void 0,it),Se(t,()=>l.collisionDetector=t??kg),Se(n,()=>n&&(l.data=n)),Se(r,()=>l.disabled=r===!0),Se(a,()=>l.type=a),{droppable:d,get isDropTarget(){return d.isDropTarget},ref:k.useCallback(u=>{var c,f;!u&&((c=l.element)!=null&&c.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=u??void 0)},[l])}}const al=`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>')}")`,fd=(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(", "),s=t==="line"?"&::after":r("&"),i=t==="line"?"&:hover::after, &:focus-visible::after":`${r("&:hover")}, ${r("&:focus-visible")}`;return{cursor:"text",borderRadius:"2px",[s]:{content:'""',display:"inline-block",width:"0.8em",height:"0.8em",ml:"0.4em",verticalAlign:"-0.05em",backgroundColor:"currentColor",maskImage:al,WebkitMaskImage:al,maskSize:"contain",WebkitMaskSize:"contain",maskRepeat:"no-repeat",WebkitMaskRepeat:"no-repeat",opacity:.35,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,pointerEvents:"none"},[i]:{opacity:.8},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:2}}},hd=k.createContext(void 0);function pd(e,t){const n=k.useContext(hd),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function go({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=Be.usePublisherTheme(),[o,a]=k.useState(void 0),l=k.useRef(!1),d=()=>{l.current||o===void 0||(a(void 0),o!==e&&r(o))};pd(o!==void 0&&o!==e,()=>(d(),!0));const u=()=>{l.current=!1,a(e)};if(o===void 0){const c=e==="",f=c&&s;return x.jsx($.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:u,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),u())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...c&&{fontStyle:"italic",opacity:f?0:.6}},fd(i)],children:c?t:e})}return x.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:c=>c.target.select(),onChange:c=>a(c.target.value),onKeyDown:c=>{c.key==="Enter"&&!c.nativeEvent.isComposing?d():c.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:d,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const $g=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const i={...n};return s?i.break=!0:delete i.break,i}),Tg=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const i=r[t];s.break&&i&&!i.break&&(r[t]={...i,break:!0});const o={...s};return delete o.break,r.splice(n,0,o),r},gd=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),md=e=>`gap.${e}`,Og=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),l=o===0||i.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:Fe(e[o-1]),colspan:t-r}),l&&(r=0),n.push(gd(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Fe(s),colspan:t-r}),n};var Eg=Object.create,vd=Object.defineProperty,Cg=Object.defineProperties,Ig=Object.getOwnPropertyDescriptor,Dg=Object.getOwnPropertyDescriptors,Ns=Object.getOwnPropertySymbols,yd=Object.prototype.hasOwnProperty,bd=Object.prototype.propertyIsEnumerable,Ag=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Fr=e=>{throw TypeError(e)},mo=(e,t,n)=>t in e?vd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yi=(e,t)=>{for(var n in t||(t={}))yd.call(t,n)&&mo(e,n,t[n]);if(Ns)for(var n of Ns(t))bd.call(t,n)&&mo(e,n,t[n]);return e},bi=(e,t)=>Cg(e,Dg(t)),Mg=(e,t)=>{var n={};for(var r in e)yd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ns)for(var r of Ns(e))t.indexOf(r)<0&&bd.call(e,r)&&(n[r]=e[r]);return n},Pg=e=>{var t;return[,,,Eg((t=void 0)!=null?t:null)]},xd=["class","method","getter","setter","accessor","field","value","get","set"],or=e=>e!==void 0&&typeof e!="function"?Fr("Function expected"):e,Rg=(e,t,n,r,s)=>({kind:xd[e],name:t,metadata:r,addInitializer:i=>n._?Fr("Already initialized"):s.push(or(i||null))}),jg=(e,t)=>mo(t,Ag("metadata"),e[3]),Zr=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},wd=(e,t,n,r,s,i)=>{for(var o,a,l,d,u,c=t&7,f=!1,h=!1,p=e.length+1,m=xd[c+5],b=e[p-1]=[],w=e[p]||(e[p]=[]),v=(s=s.prototype,Ig({get[n](){return ar(this,i)},set[n](y){return Kt(this,i,y)}},n)),g=r.length-1;g>=0;g--)d=Rg(c,n,l={},e[3],w),d.static=f,d.private=h,u=d.access={has:y=>n in y},u.get=y=>y[n],u.set=(y,_)=>y[n]=_,a=(0,r[g])({get:v.get,set:v.set},d),l._=1,a===void 0?or(a)&&(v[m]=a):typeof a!="object"||a===null?Fr("Object expected"):(or(o=a.get)&&(v.get=o),or(o=a.set)&&(v.set=o),or(o=a.init)&&b.unshift(o));return v&&vd(s,n,v),s},_d=(e,t,n)=>t.has(e)||Fr("Cannot "+n),ar=(e,t,n)=>(_d(e,t,"read from private field"),t.get(e)),Vn=(e,t,n)=>t.has(e)?Fr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Kt=(e,t,n,r)=>(_d(e,t,"write to private field"),t.set(e,n),n);function Ut(e){return e instanceof wa||e instanceof Td}var Qr=10,Lg=class extends We{constructor(e){super(e);const t=rt(()=>{const{dragOperation:r}=e;if(wr(r.activatorEvent)&&Ut(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Lr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!wr(r.nativeEvent)||!Ut(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:l}=s,{by:d}=r;if(!d)return;const u=Ng(d),{source:c,target:f}=i,{center:h}=i.shape.current,p=[],m=[];Te(()=>{for(const _ of l.droppables){const{id:S}=_;if(!_.accepts(c)||S===f?.id&&Ut(_)||!_.element)continue;let E=_.shape;const A=new ft(_.element,{getBoundingClientRect:T=>br(T,void 0,.2)});!A.height||!A.width||(u=="down"&&h.y+Qr<A.center.y||u=="up"&&h.y-Qr>A.center.y||u=="left"&&h.x-Qr>A.center.x||u=="right"&&h.x+Qr<A.center.x)&&(p.push(_),_.shape=A,m.push(()=>_.shape=E))}}),r.preventDefault(),a.disable();const b=a.computeCollisions(p,ip);Te(()=>m.forEach(_=>_()));const[w]=b;if(!w)return;const{id:v}=w,{index:g,group:y}=c.sortable;o.setDropTarget(v).then(()=>{const{source:_,target:S,shape:E}=i;if(!_||!Ut(_)||!E)return;const{index:A,group:T,target:D}=_.sortable,q=g!==A||y!==T,P=q?D:S?.element;if(!P)return;yu(P);const z=new ft(P);if(!z)return;const U=ht.delta(z,ht.from(E.current.boundingRectangle),_.alignment);o.move({by:U}),q?o.setDropTarget(_.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Ng(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 Fg=Object.defineProperty,zg=Object.defineProperties,Wg=Object.getOwnPropertyDescriptors,ll=Object.getOwnPropertySymbols,Bg=Object.prototype.hasOwnProperty,Gg=Object.prototype.propertyIsEnumerable,cl=(e,t,n)=>t in e?Fg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))Bg.call(t,n)&&cl(e,n,t[n]);if(ll)for(var n of ll(t))Gg.call(t,n)&&cl(e,n,t[n]);return e},on=(e,t)=>zg(e,Wg(t));function qg(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Jr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function xi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Kg(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,y)=>g===y||g!==null&&typeof g=="object"&&"id"in g&&g.id===y;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),y=e.findIndex(_=>l(_,o.id));if(g===-1||y===-1){if(xi(i)){const _=i.initialIndex,S=i.index;return _===S||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,S)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,y)}const d=Object.entries(e);let u=-1,c,f=-1,h;for(const[g,y]of d)if(u===-1&&(u=y.findIndex(_=>l(_,i.id)),u!==-1&&(c=g)),f===-1&&(f=y.findIndex(_=>l(_,o.id)),f!==-1&&(h=g)),u!==-1&&f!==-1)break;if(u===-1&&xi(i)){const g=i.initialGroup==null?void 0:Jr(e,i.initialGroup),y=i.initialIndex,_=i.group==null?void 0:Jr(e,i.group),S=i.index;if(g==null||_==null||g===_&&y===S)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return on(sn({},e),{[g]:n(e[g],y,S)});const E=e[g][y];return on(sn({},e),{[g]:[...e[g].slice(0,y),...e[g].slice(y+1)],[_]:[...e[_].slice(0,S),E,...e[_].slice(S)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,m=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const g=Jr(e,o.id);if(g!=null){const y=o.shape&&m.y>o.shape.center.y?e[g].length:0;h=g,f=y}}if(c==null||h==null||c===h&&u===f){if(c!=null&&c===h&&u===f&&xi(i)){const g=i.group==null?void 0:Jr(e,i.group),y=i.group!=null&&g!==c,_=i.index!==u;if(y||_){const S=i.group==null?c:g;if(S!=null){if(c===S)return on(sn({},e),{[c]:n(e[c],u,i.index)});const E=e[c][u];return on(sn({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[S]:[...e[S].slice(0,i.index),E,...e[S].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===h)return on(sn({},e),{[c]:n(e[c],u,f)});const w=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[c][u];return on(sn({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[h]:[...e[h].slice(0,f+w),v,...e[h].slice(f+w)]})}function Vg(e,t){return Kg(e,t,qg)}function ul(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function dl(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var fl="__default__",Ug=class extends We{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof wa){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Ut(o)||!Ut(a)||o.sortable===a.sortable)return;const l=t(),d=ul(l),u=o.sortable.group===a.sortable.group,c=l.get(o.sortable.group),f=u?c:l.get(a.sortable.group);!c||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,p;const m=t();if(dl(d,l,m))return;const b=o.sortable.element,w=a.sortable.element;if(!w||!b||!u&&a.id===o.sortable.group)return;const v=es(c),g=u?v:es(f),y=(h=o.sortable.group)!=null?h:fl,_=(p=a.sortable.group)!=null?p:fl,S={[y]:v,[_]:g},E=Vg(S,r);if(S===E)return;const A=E[_].indexOf(o.sortable),T=E[_].indexOf(a.sortable);s.collisionObserver.disable(),hl(b,A,w,T),Te(()=>{for(const[D,q]of E[y].entries())q.index=D;if(!u)for(const[D,q]of E[_].entries())q.group=a.sortable.group,q.index=D}),s.actions.setDropTarget(o.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:i}=s,{source:o}=i;Ut(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=ul(a),d=a.get(o.sortable.initialGroup);d&&s.renderer.rendering.then(()=>{const u=t();if(dl(l,a,u))return;const c=es(d),f=es(d,Xg),h=o.sortable.element,p=f.indexOf(o.sortable),m=c[p],b=m?.element;!m||!b||!h||(hl(h,m.index,b,o.index),Te(()=>{for(const w of a.values()){const v=Array.from(w).values();for(const g of v)g.index=g.initialIndex,g.group=g.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function hl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function Hg(e,t){return e.index-t.index}function Xg(e,t){return e.initialIndex-t.initialIndex}function es(e,t=Hg){return Array.from(e).sort(t)}var pl=[Lg,Ug],kd={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function gl(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 ts=new Bf,Sd,$d,It,ba,lr,cr,xa,gn;$d=[he],Sd=[he];var ti=class{constructor(e,t){Vn(this,ba,Zr(It,8,this)),Zr(It,11,this),Vn(this,lr),Vn(this,cr),Vn(this,xa,Zr(It,12,this)),Zr(It,15,this),Vn(this,gn),this.register=()=>(Te(()=>{var p,m;(p=this.manager)==null||p.registry.register(this.droppable),(m=this.manager)==null||m.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Te(()=>{var p,m;(p=this.manager)==null||p.registry.unregister(this.droppable),(m=this.manager)==null||m.registry.unregister(this.draggable)})},this.destroy=()=>{Te(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:l,transition:d=kd,plugins:u}=n,c=Mg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=lt(u,pl),h=gl(s);this.droppable=new wa(bi(yi({},c),{disabled:h.droppable}),t,this),this.draggable=new Td(bi(yi({},c),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var p,m,b;const w=(p=this.manager)==null?void 0:p.dragOperation.status;w?.initializing&&this.id===((b=(m=this.manager)==null?void 0:m.dragOperation.source)==null?void 0:b.id)&&ts.clear(this.manager),w?.dragging&&ts.set(this.manager,this.id,fe(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:m,manager:b}=this,w=ar(this,cr),v=ar(this,lr);(p!==w||m!==v)&&(Kt(this,cr,p),Kt(this,lr,m),this.animate())},()=>{var p,m;const{target:b}=this,{isDragSource:w}=this.draggable;((m=(p=this.draggable.pluginConfig(ua))==null?void 0:p.feedback)!=null?m:"default")==="move"&&w&&(this.droppable.disabled=!b)},...r()],type:l,sensors:a}),t,this),Kt(this,gn,c.element),this.manager=t,this.index=o,Kt(this,cr,o),this.group=i,Kt(this,lr,i),this.type=l,this.transition=d}get initialIndex(){var e,t;return(t=(e=ts.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=ts.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){fe(()=>{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:s}=this;if(!s)return;for(const u of s.getAnimations())"transitionProperty"in u&&(u.transitionProperty==="transform"||u.transitionProperty==="translate"||u.transitionProperty==="scale")&&u.cancel();const i=this.refreshShape();if(!i)return;const o={x:n.boundingRectangle.left-i.boundingRectangle.left,y:n.boundingRectangle.top-i.boundingRectangle.top},{translate:a}=mt(s),l=Za(s,a,!1),d=Za(s,a);if(o.x||o.y){const u=na(Ze(s))?bi(yi({},t),{duration:0}):t;bu({element:s,keyframes:{translate:[`${l.x+o.x}px ${l.y+o.y}px ${l.z}`,`${d.x}px ${d.y}px ${d.z}`]},options:u}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Te(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Te(()=>{const t=ar(this,gn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Kt(this,gn,e)})}get element(){var e,t;const n=ar(this,gn);if(n)return(t=(e=Xi.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=lt(e,pl)}set disabled(e){const t=gl(e);Te(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Te(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??xu}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Te(()=>{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)}};It=Pg();ba=new WeakMap;lr=new WeakMap;cr=new WeakMap;xa=new WeakMap;gn=new WeakMap;wd(It,4,"index",$d,ti,ba);wd(It,4,"group",Sd,ti,xa);jg(It,ti);var Td=class extends Qs{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}},wa=class extends Js{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Yg=Object.defineProperty,Zg=Object.defineProperties,Qg=Object.getOwnPropertyDescriptors,ml=Object.getOwnPropertySymbols,Jg=Object.prototype.hasOwnProperty,em=Object.prototype.propertyIsEnumerable,vl=(e,t,n)=>t in e?Yg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wi=(e,t)=>{for(var n in t||(t={}))Jg.call(t,n)&&vl(e,n,t[n]);if(ml)for(var n of ml(t))em.call(t,n)&&vl(e,n,t[n]);return e},tm=(e,t)=>Zg(e,Qg(t));function nm(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:l,group:d,disabled:u,modifiers:c,sensors:f,target:h,type:p,plugins:m}=e,b=wi(wi({},kd),e.transition),w=nd(g=>new ti(tm(wi({},e),{transition:b,register:!1,handle:xn(a),element:xn(o),target:xn(h)}),g)),v=Qu(w,rm);return Se(s,()=>w.id=s),Fn(()=>{Te(()=>{w.group=d,w.index=l})},[w,d,l]),Se(p,()=>w.type=p),Se(t,()=>w.accept=t,void 0,it),Se(i,()=>i&&(w.data=i)),Se(l,()=>{var g;(g=w.manager)!=null&&g.dragOperation.status.idle&&b?.idle&&w.refreshShape()},Jp),vs(a,g=>w.handle=g),vs(o,g=>w.element=g),vs(h,g=>w.target=g),Se(u,()=>w.disabled=u??!1,void 0,it),Se(f,()=>w.sensors=f,void 0,it),Se(n,()=>w.collisionDetector=n),Se(r,()=>w.collisionPriority=r),Se(m,()=>w.plugins=m,void 0,it),Se(b,()=>w.transition=b,void 0,it),Se(c,()=>w.modifiers=c,void 0,it),Se(e.alignment,()=>w.alignment=e.alignment),{sortable:v,get isDragging(){return v.isDragging},get isDropping(){return v.isDropping},get isDragSource(){return v.isDragSource},get isDropTarget(){return v.isDropTarget},handleRef:k.useCallback(g=>{w.handle=g??void 0},[w]),ref:k.useCallback(g=>{var y,_;!g&&((y=w.element)!=null&&y.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.element=g??void 0)},[w]),sourceRef:k.useCallback(g=>{var y,_;!g&&((y=w.source)!=null&&y.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.source=g??void 0)},[w]),targetRef:k.useCallback(g=>{var y,_;!g&&((y=w.target)!=null&&y.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.target=g??void 0)},[w])}}function rm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const vo="tile",Od="gap",sm=[co.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Ed}]`)!==null||(co.defaults.preventActivation?.(e,t)??!1)}),qu],Ed="data-no-drag",im=e=>[...e,ua.configure({feedback:"clone"})];function om({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=nm({id:e,index:t,type:vo,accept:vo,collisionDetector:sa,plugins:im});return x.jsx(x.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function am({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Sg({id:e,type:Od,accept:vo,collisionDetector:sa,data:{after:t}});return x.jsx(x.Fragment,{children:n({ref:r,isDropTarget:s})})}const Cd=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],Id=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],ni=e=>Id.includes(e),yo=new Set([...Cd,"viz"]);function Dt(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let s;for(const i of n)if(i.startsWith("-")){if(s!==void 0)return;const o=i.slice(1);if(!yo.has(o))return;r.push(o)}else{if(s!==void 0||!yo.has(i))return;s=i}return{negated:r,...s!==void 0&&{pick:s}}}function Tr(e){const t=e.trim();return!/^#[ \t]/.test(t)||Dt(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(r=>yo.has(r))}function wn(e,t){return["#",...Id.filter(r=>r!==e&&(t===void 0||t.includes(r))).map(r=>`-${r}`),"-viz",...e==="none"?[]:[e]].join(" ")}function lm(e){return e.pick!==void 0?ni(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function cm(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=Dt(e[0]);return t?lm(t):"custom"}function um(e){const t=e.filter(n=>Dt(n));return e.some(Tr)?"custom":t.length===0?void 0:cm(t)}const dm=e=>e.filter(t=>Dt(t)||Tr(t)),Dd=e=>e.ok===!1,Ae=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),en=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>Ae(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Ae(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Ae(e,"VIEW","subQueryDefList"),defDimension:e=>Ae(e,"defList","DIMENSION"),exploreProperties:e=>Ae(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Ae(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Ae(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Ae(e,"WHERE","filterClauseList"),givenDef:e=>Ae(e,"givenNameDef"),givenStatement:e=>Ae(e,"GIVEN","givenDefList"),importStatement:e=>Ae(e,"IMPORT","importURL"),vArrow:e=>Ae(e,"ARROW","vExpr","segExpr"),segRefine:e=>Ae(e,"PLUS","segExpr"),segOps:e=>Ae(e,"queryProperties"),segField:e=>Ae(e,"fieldPath")&&!Ae(e,"segExpr"),segParen:e=>Ae(e,"OPAREN","CPAREN","vExpr"),compare:e=>Ae(e,"fieldExpr","compareOp"),givenRef:e=>Ae(e,"GIVEN_REF")};function fm(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 hm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
- `&&t.push(n+1);return t}function Ad(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!en(s))continue;const i=Ce(s,"docAnnotations");if(i)for(const o of Pt(i,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class ri{constructor(t){this.text=t,this.map=fm(t),this.lineStarts=hm(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!en(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],i=this.map[r.stopIndex+1];if(!(s===void 0||i===void 0||i<s))return{start:s,end:i}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],s=this.map[n.stopIndex+1];if(!(r===void 0||s===void 0||s<r))return{start:r,end:s}}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 s=n+r+1>>1;this.lineStarts[s]<=t?n=s:r=s-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 zr(e,t,n=[]){en(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)zr(e.getChild(r),t,n);return n}const pm=e=>Ae(e,"OCURLY","CCURLY");function Or(e,t){const n=[],r=s=>{if(en(s)){if(t(s)){n.push(s);return}if(!pm(s))for(let i=0;i<(s.childCount??0);i++)r(s.getChild(i))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Ce=(e,t)=>e[t]?.call(e),Pt=(e,t)=>e[t]?.call(e)??[];function gm(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)),s=e.text_(t.getChild(1)),i=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:i.replace(/^\$/,"")}}function Md(e,t){const n=e.positioned(t);if(!n)return;const r=Ce(t,"filterClauseList"),s=[];for(const i of r?Pt(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=zr(i,ke.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));s.push({...o,givens:a,binding:gm(e,i)})}return{...n,clauses:s}}function bo(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const d of Or(t,ke.queryStatement)){const u=e.positioned(d);u&&r.push(u);const c=Ce(d,"whereStatement");if(c&&ke.whereStatement(c)){const f=Md(e,c);f&&s.push(f)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
- `),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:l,oneLine:a}}function _a(e,t,n){const r=[],s=e.line(t.start),i=e.line(n);for(let o=s;o<i;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 mm(e,t){const n=Ce(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const s=Ce(n,"queryProperties"),i=s&&bo(e,s);return i?{kind:"inline",stage:i,...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 s=e.span(n);return s?{kind:"reference",from:e.text.slice(s.start,s.end),fromSpan:s}:{kind:"unsupported",why:"an unreadable name"}}if(ke.segRefine(n)){const s=Pt(n,"segExpr"),i=s[0],o=s[s.length-1];let a=i;for(;ke.segRefine(a);){const f=Pt(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 l=e.span(i);if(!l||!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 d=e.text.slice(l.start,l.end),u=Ce(o,"queryProperties"),c=u&&bo(e,u);return c?{kind:"reference",from:d,fromSpan:l,refinement:c}:{kind:"reference",from:d,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function vm(e,t){const n=[];for(const r of Or(t,ke.defExploreQuery)){const s=e.span(r),i=Ce(r,"subQueryDefList");if(!s||!i)continue;const o=Pt(i,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Ce(r,"VIEW"));for(const l of o){const d=e.span(l),u=Ce(l,"exploreQueryNameDef"),c=e.text_(u),f=Ce(l,"vExpr");!d||!c||!f||n.push({name:c,span:d,line:e.line(d.start),statement:s,tags:_a(e,s,a?.start??d.start),siblings:o.length,body:mm(e,f)})}}return n}function ym(e,t){const n=[];for(const r of Or(t,ke.defDimension)){const s=e.span(r),i=Ce(r,"defList");if(!s||!i)continue;const o=e.terminal(Ce(r,"DIMENSION"));for(const a of Pt(i,"fieldDef")){const l=e.span(a),d=e.text_(Ce(a,"fieldNameDef"))?.trim(),u=e.text_(Ce(a,"fieldExpr"))?.trim();!l||!d||u===void 0||n.push({name:d,expression:u,span:l,line:e.line(l.start),statement:s,tags:_a(e,s,o?.start??l.start)})}}return n}function bm(e,t){const n=[];for(const r of zr(t,ke.sourceDefinition)){const s=e.span(r),i=e.text_(Ce(r,"sourceNameDef")),o=Ce(r,"sqExplore");if(!s||!i||!o)continue;const a=e.span(o),l=a?e.text.slice(a.start,a.end):"",d=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(l)?.[1]??"").trim(),u=Or(o,ke.exploreProperties)[0],c=u&&bo(e,u),f={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(u)for(const p of Or(u,ke.whereStatement)){const m=Md(e,p);m&&h.push(m)}n.push({name:i,base:d,span:s,line:e.line(s.start),statement:f,...c?{properties:c}:{},views:u?vm(e,u):[],dimensions:u?ym(e,u):[],wheres:h})}return n}function xm(e,t){const n=[];for(const r of zr(t,ke.givenStatement)){const s=e.terminal(Ce(r,"GIVEN")),i=Ce(r,"givenDefList"),o=s?e.line(s.start):void 0;for(const a of i?Pt(i,"givenDef"):[]){const l=e.span(a),d=e.span(Ce(a,"givenNameDef")),u=d&&e.text.slice(d.start,d.end);if(!l||!d||!u)continue;const c={start:d.start,end:l.end},f=e.line(c.start);n.push({name:u,declaration:e.text.slice(c.start,c.end),span:c,line:f,statement:{start:e.lineStarts[f],end:c.end},tags:_a(e,l,c.start),...o!==void 0&&o!==f?{blockHeader:o}:{}})}}return n}function wm(e,t){const n=[];for(const r of zr(t,ke.importStatement)){const s=e.span(r),i=e.text_(Ce(r,"importURL"));if(!s||i===void 0)continue;const o=Ce(r,"importSelect"),a=o?Pt(o,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:i.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function Pd(e){let t;try{t=await Wr(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,s=r?.root;if(!s||!en(s)||typeof s.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 i=r?.tokenStream??{},o=typeof i.getTokens=="function"?i.getTokens():void 0;if(!o||typeof i.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 ri(e),l=ka(a,i);a.commentLines=l.lines;const d=e.split(`
70
- `),u=f=>l.lines.has(f);a.proseLines=ge.markdownLines(d,u),a.blocks=ge.blockSpans(d,u).filter(([f])=>!d[f].trimStart().startsWith("##"));const c=bm(a,s);return c.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:wm(a,s),sources:c,givens:xm(a,s),textBlocks:km(a,i),modelNotes:Ad(a,s),trailingComment:f=>l.trailing.get(f),comments:l.all,commentLine:f=>l.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>l.all.find(h=>h.start>=f.start&&h.start<f.end),blockStart:f=>_m(a,l.lines,f)}}}async function Wr(e,t){const{MalloyTranslator:n}=await O.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function ka(e,t){const n=new Map,r=new Set,s=[],i=t.tokenSource?.vocabulary;for(const u of t.getTokens?.()??[]){const c=i?.getSymbolicName(u.type);if(c!=="COMMENT_TO_EOL"&&c!=="BLOCK_COMMENT")continue;const f=e.utf16(u.startIndex);let h=e.utf16(u.stopIndex+1);if(!(f===void 0||h===void 0||h<f)){for(;h>f&&(e.text[h-1]===`
71
- `||e.text[h-1]==="\r");)h--;s.push({start:f,end:h})}}const o=[...s].sort((u,c)=>u.start-c.start);let a="",l=0;for(const u of o)a+=e.text.slice(l,Math.max(l,u.start)),a+=e.text.slice(Math.max(l,u.start),Math.max(l,u.end)).replace(/[^\n\r]/g," "),l=Math.max(l,u.end);a+=e.text.slice(l);const d=u=>a.slice(e.lineStarts[u],e.lineStarts[u+1]??a.length);for(const u of s){const c=e.line(u.start),f=e.line(u.end-1);for(let m=c;m<=f;m++)d(m).trim()===""&&r.add(m);const h=a.slice(e.lineStarts[c],u.start).trim(),p=a.slice(u.end,e.lineStarts[f+1]??a.length).trim();h!==""&&p===""&&n.set(f,u)}return{trailing:n,lines:r,all:s}}function _m(e,t,n){const r=i=>e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();let s=n;for(let i=n-1;i>=0;i--){const o=r(i),a=e.blocks.find(([,l])=>l===i);if(a){s=i=a[0];continue}if(o===""&&!t.has(i))break;if(o.startsWith("#")||t.has(i))s=i;else break}return s}function km(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,s=a=>r?.getSymbolicName(a.type),i=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(s(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const l=ge.textBlockOpener(i(n[a]).replace(/\r?\n$/,""));if(!l)continue;const d=[];let u=a+1;for(;s(n[u]??n[a])==="BLOCK_ANNOTATION_TEXT";u++)d.push(i(n[u]));const c=n[u];if(!c||s(c)!=="BLOCK_ANNOTATION_END")continue;const f=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(c.stopIndex+1)??e.text.length,p=l.name===void 0&&l.rest?[`${l.rest}
67
+ `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Tp(e,t="hidden"){return fe(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Op(n,r.registry.droppables),i=[],o=wh(n),{remove:a}=o;return Ep(s,o,i),Cp(o,t),o.remove=()=>{i.forEach(l=>l()),a.call(o)},o})}function Op(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Rr}${Ji("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Ep(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),Xi.set(a,o),n.push(()=>{Xi.delete(a),r.proxy=void 0})}}function Cp(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Ps,t)}function Pu(e,t){return e===t?!0:Sn(e)===Sn(t)}function el(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Ht(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>yn(t))}function ro(e){return e.tagName==="TR"}function Ip(e,t,n){const r=new MutationObserver(s=>{let i=!1;for(const o of s){if(o.target!==e){i=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||kp.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(pr(e)&&pr(t)){const d=e.style;for(const c of Array.from(t.style))d.getPropertyValue(c)===""&&t.style.removeProperty(c);for(const c of Array.from(d)){if(Sp.includes(c)||c.startsWith(Le))continue;const u=d.getPropertyValue(c);t.style.setProperty(c,u)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Ap(e,t,n){const r=new MutationObserver(s=>{for(const i of s)if(i.addedNodes.length!==0)for(const o of Array.from(i.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),yn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),yn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),yn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Dp(e){return new ResizeObserver(()=>{var t,n,r;const s=new ft(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),i=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-s.width)*i.x+e.delta.x,a=(e.height-s.height)*i.y+e.delta.y,l=cu();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},Le),(n=e.getElementMutationObserver())==null||n.takeRecords(),ro(e.element)&&ro(e.placeholder)){const m=Array.from(e.element.cells),b=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(m.map(x=>x.style.width));for(const[x,v]of m.entries()){const g=b[x];v.style.width=`${g.getBoundingClientRect().width}px`}}const d=(r=e.getTranslate())!=null?r:{x:0,y:0},c=e.left+o+l.x+d.x,u=e.top+a+l.y+d.y,f=s.width-e.widthOffset,h=s.height-e.heightOffset,p=e.frameTransform;e.dragOperation.shape=new ht(c*p.scaleX+p.x,u*p.scaleY+p.y,f*p.scaleX,h*p.scaleY)})}var Mp=250,Pp="ease";function jp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const v=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(v).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Mp,easing:a=Pp}=i??{};yn(e.feedbackElement);const[,l]=(t=ou(e.feedbackElement,v=>"translate"in v))!=null?t:[];l?.pause();const d=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Pu(e.feedbackElement,d)?null:void 0},u=new ft(e.feedbackElement,c),f=(r=xr(mt(e.feedbackElement).translate))!=null?r:e.translate,h=new ft(d,c),p=ht.delta(u,h,e.alignment),m={x:f.x-p.x,y:f.y-p.y},b=Math.round(u.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${u.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${u.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},x=Math.round(u.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${u.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${u.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Le),e.feedbackElement.setAttribute(no,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),bu({element:e.feedbackElement,keyframes:oa(_r(_r({},b),x),{translate:[`${f.x}px ${f.y}px 0`,`${m.x}px ${m.y}px 0`]}),options:{duration:na(Ze(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(no),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var ju,so,kr,ca,ms,Ru,Lu,On=class extends(so=We,ju=[he],so){constructor(t,n){super(t,n),Ie(this,ms),Ie(this,ca,Pe(kr,8,this)),Pe(kr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(Zs),s=r?.register($p);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Xt(this,ms,Ru).bind(this,r)),this.registerEffect(Xt(this,ms,Lu))}};kr=Nn(so);ca=new WeakMap;ms=new WeakSet;Ru=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Os(t);if(n)return e.addRoot(n)};Lu=function(){var e,t,n,r,s,i,o;const{state:a,manager:l,options:d}=this,{dragOperation:c}=l,{position:u,source:f,status:h}=c;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:p}=f,m=f.pluginConfig(On),b=(t=(e=m?.feedback)!=null?e:d?.feedback)!=null?t:"default",x=typeof b=="function"?b(f,l):b;if(!p||x==="none"||!h.initialized||h.initializing)return;const{initial:v}=a,g=(n=this.overlay)!=null?n:p,y=$n(g),_=$n(p),S=!Pu(p,g),E=new ft(p,{frameTransform:S?_:null,ignoreTransforms:!S}),D={x:_.scaleX/y.scaleX,y:_.scaleY/y.scaleY};let{width:T,height:A,top:q,left:P}=E;S&&(T=T/D.x,A=A/D.y);const z=new ep(g),U=mt(p),{transition:K,translate:Z,boxSizing:J,paddingBlockStart:ie,paddingBlockEnd:de,paddingInlineStart:I,paddingInlineEnd:V,borderInlineStartWidth:B,borderInlineEndWidth:j,borderBlockStartWidth:G,borderBlockEndWidth:ne}=U,Y=K.split(",").filter(ye=>!/^\s*(transform|translate|scale)\b/.test(ye)).join(","),H=Ys(U),L=U.transform,C=x==="clone",W=J==="content-box",M=W?parseInt(I)+parseInt(V)+parseInt(B)+parseInt(j):0,ee=W?parseInt(ie)+parseInt(de)+parseInt(G)+parseInt(ne):0,X=x!=="move"&&!this.overlay?Tp(f,C?"clone":"hidden"):null,le=fe(()=>wr(l.dragOperation.activatorEvent));if(!v.translate){if(this.overlay&&H)v.translate={x:H.x,y:H.y};else if(Z!=="none"){const ye=xr(Z);ye&&(v.translate=ye)}}if(!v.transformOrigin){const ye=fe(()=>u.current),Ae=P+((r=H?.x)!=null?r:0),He=q+((s=H?.y)!=null?s:0);v.transformOrigin={x:(ye.x-Ae*y.scaleX-y.x)/(T*y.scaleX),y:(ye.y-He*y.scaleY-y.y)/(A*y.scaleY)}}const{transformOrigin:ce}=v,N=q*y.scaleY+y.y,Q=P*y.scaleX+y.x;if(!v.coordinates&&(v.coordinates={x:Q,y:N},D.x!==1||D.y!==1)){const{scaleX:ye,scaleY:Ae}=_,{x:He,y:kt}=ce;v.coordinates.x+=(T*ye-T)*He,v.coordinates.y+=(A*Ae-A)*kt}v.dimensions||(v.dimensions={width:T,height:A}),v.frameTransform||(v.frameTransform=y);const me={x:v.coordinates.x-Q,y:v.coordinates.y-N},se={width:(v.dimensions.width*v.frameTransform.scaleX-T*y.scaleX)*ce.x,height:(v.dimensions.height*v.frameTransform.scaleY-A*y.scaleY)*ce.y},te={x:me.x/y.scaleX+se.width,y:me.y/y.scaleY+se.height},R={left:P+te.x,top:q+te.y};g.setAttribute(dt,"true");const F=fe(()=>c.transform),re=(i=v.translate)!=null?i:{x:0,y:0},ue=F.x*y.scaleX+re.x,Re=F.y*y.scaleY+re.y,jt=cu();z.set({width:T-M,height:A-ee,top:R.top+jt.y,left:R.left+jt.x,translate:`${ue}px ${Re}px 0`,transform:this.overlay?"none":L,transition:Y?`${Y}, translate 0ms linear`:"translate 0ms linear",scale:S?`${D.x} ${D.y}`:"","transform-origin":`${ce.x*100}% ${ce.y*100}%`},Le),X&&(p.insertAdjacentElement("afterend",X),d?.rootElement&&(typeof d.rootElement=="function"?d.rootElement(f):d.rootElement).appendChild(p)),Zi(g)&&(g.hasAttribute("popover")||g.setAttribute("popover","manual"),yn(g),g.addEventListener("beforetoggle",el));let ut,zn,_t;const Wn=Dp({placeholder:X,element:p,feedbackElement:g,frameTransform:y,transformOrigin:ce,width:T,height:A,top:q,left:P,widthOffset:M,heightOffset:ee,delta:te,styles:z,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>ut,getSavedCellWidths:()=>_t,setSavedCellWidths:ye=>{_t=ye}}),Gr=new ft(g);fe(()=>c.shape=Gr);const Bn=Ze(g),Rt=ye=>{this.manager.actions.stop({event:ye})},Zd=na(Bn);le&&Bn.addEventListener("resize",Rt),fe(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),X&&(Wn.observe(X),ut=Ip(p,X,C),zn=Ap(p,X,g));const Ca=(o=l.dragOperation.source)==null?void 0:o.id,Qd=()=>{var ye;if(!le||Ca==null)return;const Ae=l.registry.draggables.get(Ca),He=(ye=Ae?.handle)!=null?ye:Ae?.element;Dt(He)&&He.focus()},si=()=>{ut?.disconnect(),zn?.disconnect(),Wn.disconnect(),Bn.removeEventListener("resize",Rt),Zi(g)&&(g.removeEventListener("beforetoggle",el),g.removeAttribute("popover")),g.removeAttribute(dt),z.reset();const ye=()=>{var Ae;if(_t&&ro(p)){const ii=Array.from(p.cells);for(const[qr,tn]of ii.entries())tn.style.width=(Ae=_t[qr])!=null?Ae:""}f.status="idle";const He=a.current.translate!=null,kt=c.status.dragging;X&&(!kt&&He||X.parentElement!==g.parentElement)&&g.isConnected&&X.replaceWith(g),X?.remove()};g===this.overlay?setTimeout(ye,0):ye()},Jd=d?.dropAnimation,Ia=this,ef=Ar(()=>{var ye,Ae,He;const{transform:kt,status:ii}=c;if(!(!kt.x&&!kt.y&&!a.current.translate)&&ii.dragging){const qr=(ye=v.translate)!=null?ye:{x:0,y:0},tn={x:kt.x/y.scaleX+qr.x,y:kt.y/y.scaleY+qr.y},Aa=a.current.translate,tf=fe(()=>c.modifiers),oi=fe(()=>{var qn;return(qn=c.shape)==null?void 0:qn.current}),Gn=d?.keyboardTransition,Da=le&&!Zd&&Gn!==null?`${(Ae=Gn?.duration)!=null?Ae:250}ms ${(He=Gn?.easing)!=null?He:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(z.set({transition:Y?`${Y}, translate ${Da}`:`translate ${Da}`,translate:`${tn.x}px ${tn.y}px 0`},Le),ut?.takeRecords(),oi&&oi!==Gr&&Aa&&!tf.length){const qn=Je.delta(tn,Aa);c.shape=ht.from(oi.boundingRectangle).translate(qn.x*y.scaleX,qn.y*y.scaleY)}else c.shape=new ft(g);a.current.translate=tn}},function(){if(c.status.dropped){this.dispose(),f.status="dropping";const ye=m?.dropAnimation!==void 0?m.dropAnimation:Ia.dropAnimation!==void 0?Ia.dropAnimation:Jd;let Ae=a.current.translate;const He=Ae!=null;if(!Ae&&p!==g&&(Ae={x:0,y:0}),!Ae||ye===null){si();return}l.renderer.rendering.then(()=>{jp({source:f,element:p,feedbackElement:g,placeholder:X,translate:Ae,moved:He,transition:K,alignment:f.alignment,styles:z,animation:ye??void 0,getElementMutationObserver:()=>ut,cleanup:si,restoreFocus:Qd})})}});return()=>{si(),ef()}};st(kr,4,"overlay",ju,On,ca);Jt(kr,On);On.configure=Mr(On);var ua=On,Kn=!0,Rp=!1,Nu,Fu,zu,Wu,Ot,da,fa;Wu=(zu=[he],et.Forward),Fu=(Nu=[he],et.Reverse);var Sr=class{constructor(){Ie(this,da,Pe(Ot,8,this,Kn)),Pe(Ot,11,this),Ie(this,fa,Pe(Ot,12,this,Kn)),Pe(Ot,15,this)}isLocked(e){return e===et.Idle?!1:e==null?this[et.Forward]===Kn&&this[et.Reverse]===Kn:this[e]===Kn}unlock(e){e!==et.Idle&&(this[e]=Rp)}};Ot=Nn(null);da=new WeakMap;fa=new WeakMap;st(Ot,4,Wu,zu,Sr,da);st(Ot,4,Fu,Nu,Sr,fa);Jt(Ot,Sr);var Lp=[et.Forward,et.Reverse],tl=class{constructor(){this.x=new Sr,this.y=new Sr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Np=class extends We{constructor(e){super(e);const t=En(new tl);let n=null;this.signal=t,rt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new tl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:nl(s.x,n.x),y:nl(s.y,n.y)},o=t.peek();Te(()=>{for(const a of mc)for(const l of Lp)i[a]===l&&o[a].unlock(l);t.value=o})}n=s})}get current(){return this.signal.peek()}};function nl(e,t){return Math.sign(e-t)}var Bu,io,$r,ha,$t,oo,Lr=class extends(io=Pr,Bu=[he],io){constructor(e){super(e),Ie(this,ha,Pe($r,8,this,!1)),Pe($r,11,this),Ie(this,$t),Ie(this,oo,()=>{if(!be(this,$t))return;const{element:i,by:o}=be(this,$t);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return Ke(this,$t,void 0),!1;const{position:d}=this.manager.dragOperation,c=d?.current;if(c){const{by:u}=i??{},f=u?{x:rl(u.x),y:rl(u.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of l){const m=Ph(p,u);if(m.x||m.y){const{speed:b,direction:x}=Kh(p,c,f,o?.acceleration,o?.threshold);if(h)for(const v of mc)h[v].isLocked(x[v])&&(b[v]=0,x[v]=0);if(x.x||x.y){const{x:v,y:g}=u??x,y=v*b.x,_=g*b.y;if(y||_){const S=(a=be(this,$t))==null?void 0:a.by;if(this.autoScrolling&&S&&(S.x&&!y||S.y&&!_))continue;return Ke(this,$t,{element:p,by:{x:y,y:_}}),Is.schedule(be(this,oo)),!0}}}}}return Ke(this,$t,void 0),!1};let t=null,n=null;const r=ji(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=uu(Os(o?.element),i.current);return a&&(t=a),a??t}),s=ji(()=>{const i=r.value,{documentElement:o}=Rn(i);if(!i||i===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const d=Qi(l,{excludeElement:!1});return n=d,d}}if(i){const a=Qi(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},it);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Np(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!wr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};$r=Nn(io);ha=new WeakMap;$t=new WeakMap;oo=new WeakMap;st($r,4,"autoScrolling",Bu,Lr,ha);Jt($r,Lr);function rl(e){return e>0?et.Forward:e<0?et.Reverse:et.Idle}var Fp=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))}},zp=new Fp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Wp=10,ao=class extends We{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Lr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=rt(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const d={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(o=this.options)==null?void 0:o.threshold};if(r.scroll(void 0,d)){r.autoScrolling=!0;const u=setInterval(()=>zp.schedule(()=>r.scroll(void 0,d)),Wp);return()=>{clearInterval(u)}}else r.autoScrolling=!1}})}};ao.configure=Mr(ao);var Gu=ao,sl={capture:!0,passive:!0},sr,Bp=class extends Pr{constructor(e){super(e),Ie(this,sr),this.handleScroll=()=>{be(this,sr)==null&&Ke(this,sr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ke(this,sr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=rt(()=>{var n,r,s;if(t.status.dragging){const o=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return o.addEventListener("scroll",this.handleScroll,sl),()=>{o.removeEventListener("scroll",this.handleScroll,sl)}}})}};sr=new WeakMap;var Gp="* { user-select: none !important; -webkit-user-select: none !important; }",qp=class extends We{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Zs),n=t?.register(Gp);if(this.destroy=rt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return gi(),document.addEventListener("selectionchange",gi,{capture:!0}),()=>{document.removeEventListener("selectionchange",gi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function gi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var ir=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}}),fn,js=class extends _n{constructor(t,n){super(t),this.manager=t,this.options=n,Ie(this,fn,[]),this.listeners=new du,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Ht(r.target)||s.disabled)return;const{keyboardCodes:o=ir.keyboardCodes,preventActivation:a=ir.preventActivation}=i??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,i))}}bind(t,n=this.options){return rt(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{wr(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),yu(s);const{center:i}=new ft(s);if(this.manager.actions.start({event:t,coordinates:{x:i.x,y:i.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Rn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:d=>this.handleKeyDown(d,n,r),options:{capture:!0}}])];be(this,fn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=ir.keyboardCodes}=r??{};if(nn(t,[...s.end,...s.cancel])){t.preventDefault();const i=nn(t,s.cancel);this.handleEnd(t,i);return}nn(t,s.up)?this.handleMove("up",t):nn(t,s.down)&&this.handleMove("down",t),nn(t,s.left)?this.handleMove("left",t):nn(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:i}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:ir.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!i){switch(t){case"up":a={x:0,y:-l.y*o};break;case"down":a={x:0,y:l.y*o};break;case"left":a={x:-l.x*o,y:0};break;case"right":a={x:l.x*o,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(Gu);t?.disabled===!1&&(t.disable(),be(this,fn).push(()=>{t.enable()}))}cleanup(){be(this,fn).forEach(t=>t()),Ke(this,fn,[])}destroy(){this.cleanup(),this.listeners.clear()}};fn=new WeakMap;js.configure=Mr(js);js.defaults=ir;var qu=js;function nn(e,t){return t.includes(e.code)}var Gt,Kp=class extends Hc{constructor(){super(...arguments),Ie(this,Gt)}onEvent(e){switch(e.type){case"pointerdown":Ke(this,Gt,kn(e));break;case"pointermove":if(!be(this,Gt))return;const{x:t,y:n}=kn(e),r={x:t-be(this,Gt).x,y:n-be(this,Gt).y},{tolerance:s}=this.options;if(s&&qi(r,s)){this.abort();return}qi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Ke(this,Gt,void 0)}};Gt=new WeakMap;var hn,qt,Vp=class extends Hc{constructor(){super(...arguments),Ie(this,hn),Ie(this,qt)}onEvent(e){switch(e.type){case"pointerdown":Ke(this,qt,kn(e)),Ke(this,hn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!be(this,qt))return;const{x:t,y:n}=kn(e),r={x:t-be(this,qt).x,y:n-be(this,qt).y};qi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){be(this,hn)&&(clearTimeout(be(this,hn)),Ke(this,qt,void 0),Ke(this,hn,void 0))}};hn=new WeakMap;qt=new WeakMap;var vn=class{};vn.Delay=Vp;vn.Distance=Kp;var lo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Ht(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new vn.Delay({value:250,tolerance:5})]:np(s)&&!e.defaultPrevented?[new vn.Delay({value:200,tolerance:0})]:[new vn.Delay({value:200,tolerance:10}),new vn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Ht(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=kh(r);return s===t.element?!1:!!s}}),pn,Rs=class extends _n{constructor(t,n){super(t),this.manager=t,this.options=n,Ie(this,pn,new Set),this.listeners=new du,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=lo.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return rt(()=>{var s;const i=new AbortController,{signal:o}=i,a=d=>{tp(d)&&this.handlePointerDown(d,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const d of l)d&&(Xp(d.ownerDocument.defaultView),d.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Ht(t.target)||n.disabled||Up(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=lo.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=Dt(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=$n(n.element),{x:l,y:d}=kn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:d*a.scaleY+a.y};const c=this.activationConstraints(t,n,r);t.sensor=this;const u=new ph(c,m=>this.handleStart(n,m));u.signal.onabort=()=>this.handleCancel(t),u.onEvent(t),this.controller=u;const f=Hi(),h=this.listeners.bind(f,[{type:"pointermove",listener:m=>this.handlePointerMove(m,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:Yr,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};be(this,pn).add(p)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const i=kn(t),o=$n(n.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=i,Is.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Rn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=Ht(n.target)?[n.target,a]:a,d=this.listeners.bind(l,[{type:"touchmove",listener:Yr,options:{passive:!1}},{type:"click",listener:Yr},{type:"contextmenu",listener:Yr},{type:"keydown",listener:this.handleKeyDown}]);be(this,pn).add(d)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},be(this,pn).forEach(n=>n()),be(this,pn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};pn=new WeakMap;Rs.configure=Mr(Rs);Rs.defaults=lo;var co=Rs;function Up(e){return"sensor"in e}function Yr(e){e.preventDefault()}function Hp(){}var il=new WeakSet;function Xp(e){!e||il.has(e)||(e.addEventListener("touchmove",Hp,{capture:!1,passive:!1}),il.add(e))}var bn={modifiers:[],plugins:[xp,Gu,_p,ua,qp],sensors:[co,qu]},Ku=class extends vh{constructor(e={}){const t=lt(e.plugins,bn.plugins),n=lt(e.sensors,bn.sensors),r=lt(e.modifiers,bn.modifiers);super(oa(_r({},e),{plugins:[Bp,Lr,Zs,...t],sensors:n,modifiers:r}))}},Vu,Uu,uo,Et,pa,ga,Qs=class extends(uo=pt,Uu=[he],Vu=[he],uo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=Su(n,["element","effects","handle"]);super(_r({effects:()=>[...s(),()=>{var a,l;const{manager:d}=this;if(!d)return;const u=((l=(a=this.sensors)==null?void 0:a.map(vr))!=null?l:[...d.sensors]).map(f=>{const h=f instanceof _n?f:d.registry.register(f.plugin),p=f instanceof _n?void 0:f.options;return h.bind(this,p)});return function(){u.forEach(h=>h())}}]},o),t),Ie(this,pa,Pe(Et,8,this)),Pe(Et,11,this),Ie(this,ga,Pe(Et,12,this)),Pe(Et,15,this),this.element=r,this.handle=i}};Et=Nn(uo);pa=new WeakMap;ga=new WeakMap;st(Et,4,"handle",Uu,Qs,pa);st(Et,4,"element",Vu,Qs,ga);Jt(Et,Qs);var Hu,Xu,fo,Ct,ma,mi,Yu,Zu,mr,va,Js=class extends(fo=gt,Xu=[he],Hu=[he],fo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=Su(n,["element","effects"]);const{collisionDetector:o=xu}=i,a=d=>{const{manager:c,element:u}=this;if(!u||d===null){this.shape=void 0;return}if(!c)return;const f=new ft(u),h=fe(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},l=En(!1);super(oa(_r({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:d,manager:c}=this;if(!c)return;const{dragOperation:u}=c,{source:f}=u;l.value=!!(f&&u.status.initialized&&d&&!this.disabled&&this.accepts(f))},()=>{const{element:d}=this;if(l.value&&d){const c=new Mh(d,a);return()=>{c.disconnect(),this.shape=void 0}}},()=>{var d;if((d=this.manager)!=null&&d.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Ie(this,mr),Ie(this,ma,Pe(Ct,8,this)),Pe(Ct,11,this),Ie(this,va,Pe(Ct,12,this)),Pe(Ct,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ke(this,mr,e,Zu)}get element(){var e;return(e=this.proxy)!=null?e:be(this,mr,Yu)}};Ct=Nn(fo);ma=new WeakMap;mr=new WeakSet;va=new WeakMap;mi=st(Ct,20,"#element",Xu,mr,ma),Yu=mi.get,Zu=mi.set;st(Ct,4,"proxy",Hu,Js,va);Jt(Ct,Js);function Yp(e){return e!=null&&typeof e=="object"&&"current"in e}function xn(e){var t;if(e!=null)return Yp(e)?(t=e.current)!=null?t:void 0:e}var Zp=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Fn=Zp?k.useLayoutEffect:k.useEffect;function Qp(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Qu(e,t){const n=k.useRef(new Map),r=Qp();return Fn(()=>{if(!e){n.current.clear();return}return rt(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[l]=a,d=fe(()=>a[1]),c=e[l];d!==c&&(i=!0,n.current.set(l,c),o=(s=t?.(l,d,c))!=null?s:!1)}i&&(o?queueMicrotask(()=>nf.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(s,i){const o=s[i];return n.current.set(i,o),o}}),[e])}function Jp(e,t){e()}function rn(e){const t=k.useRef(e);return Fn(()=>{t.current=e},[e]),t}function Se(e,t,n=k.useEffect,r=Object.is){const s=k.useRef(e);n(()=>{const i=s.current;r(e,i)||(s.current=e,t(e,i))},[t,e])}function vs(e,t){const n=k.useRef(xn(e));Fn(()=>{const r=xn(e);r!==n.current&&(n.current=r,t(r))})}var eg=Object.defineProperty,tg=Object.defineProperties,ng=Object.getOwnPropertyDescriptors,Ls=Object.getOwnPropertySymbols,Ju=Object.prototype.hasOwnProperty,ed=Object.prototype.propertyIsEnumerable,ol=(e,t,n)=>t in e?eg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rg=(e,t)=>{for(var n in t||(t={}))Ju.call(t,n)&&ol(e,n,t[n]);if(Ls)for(var n of Ls(t))ed.call(t,n)&&ol(e,n,t[n]);return e},sg=(e,t)=>tg(e,ng(t)),ig=(e,t)=>{var n={};for(var r in e)Ju.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ls)for(var r of Ls(e))t.indexOf(r)<0&&ed.call(e,r)&&(n[r]=e[r]);return n},og=new Ku,td=k.createContext(og),ag=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),s=k.useRef(null),i=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{i.current=l})),k.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return Fn(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),vi=[void 0,it];function lg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:l}=t,d=ig(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=k.useRef(null),{plugins:u,modifiers:f,sensors:h}=d,p=lt(u,bn.plugins),m=lt(h,bn.sensors),b=lt(f,bn.modifiers),x=rn(s),v=rn(i),g=rn(a),y=rn(o),_=rn(l),S=rn(r),E=cg(()=>{var D;return(D=d.manager)!=null?D:new Ku(d)});return k.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:D,trackRendering:T}=c.current,{monitor:A}=E;E.renderer=D;const q=[A.addEventListener("beforedragstart",P=>{const z=x.current;z&&T(()=>z(P,E))}),A.addEventListener("dragstart",P=>{var z;return(z=v.current)==null?void 0:z.call(v,P,E)}),A.addEventListener("dragover",P=>{const z=g.current;z&&T(()=>z(P,E))}),A.addEventListener("dragmove",P=>{const z=y.current;z&&T(()=>z(P,E))}),A.addEventListener("dragend",P=>{const z=_.current;z&&T(()=>z(P,E))}),A.addEventListener("collision",P=>{var z;return(z=S.current)==null?void 0:z.call(S,P,E)})];return()=>q.forEach(P=>P())},[E]),Se(p,()=>E&&(E.plugins=p),...vi),Se(m,()=>E&&(E.sensors=m),...vi),Se(b,()=>E&&(E.modifiers=b),...vi),w.jsxs(td.Provider,{value:E,children:[w.jsx(ag,{ref:c,children:n}),n]})}function cg(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function ug(){return k.useContext(td)}function nd(e){var t;const n=(t=ug())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Fn(r.register,[n,r]),r}var dg=Object.create,rd=Object.defineProperty,fg=Object.getOwnPropertyDescriptor,sd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ei=e=>{throw TypeError(e)},hg=(e,t,n)=>t in e?rd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pg=e=>{var t;return[,,,dg((t=e?.[sd("metadata")])!=null?t:null)]},id=["class","method","getter","setter","accessor","field","value","get","set"],od=e=>e!==void 0&&typeof e!="function"?ei("Function expected"):e,gg=(e,t,n,r,s)=>({kind:id[e],name:t,metadata:r,addInitializer:i=>n._?ei("Already initialized"):s.push(od(i||null))}),mg=(e,t)=>hg(t,sd("metadata"),e[3]),vg=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},ad=(e,t,n,r,s,i)=>{for(var o,a,l,d,c=t&7,u=!1,f=!1,h=2,p=id[c+5],m=e[h]||(e[h]=[]),b=(s=s.prototype,fg(s,n)),x=r.length-1;x>=0;x--)l=gg(c,n,a={},e[3],m),l.static=u,l.private=f,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[x])(b[p],l),a._=1,od(o)&&(b[p]=o);return b&&rd(s,n,b),s},ld=(e,t,n)=>t.has(e)||ei("Cannot "+n),yg=(e,t,n)=>(ld(e,t,"read from private field"),t.get(e)),bg=(e,t,n)=>t.has(e)?ei("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),xg=(e,t,n,r)=>(ld(e,t,"write to private field"),t.set(e,n),n),Vt=class ho{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ho(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new ho(t,n)}},cd,ud,po,ys,Nr,ya=class extends(po=Zt,ud=[Ee],cd=[Ee],po){constructor(e){const t=Vt.from(e);super(t,(n,r)=>Vt.equals(n,r)),vg(Nr,5,this),bg(this,ys,0),this.velocity={x:0,y:0}}get delta(){return Vt.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=Vt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-yg(this,ys),o=a=>Math.round(a/i*100);Te(()=>{xg(this,ys,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(Vt.from(e)),this.velocity={x:0,y:0}}};Nr=pg(po);ys=new WeakMap;ad(Nr,2,"delta",ud,ya);ad(Nr,2,"direction",cd,ya);mg(Nr,ya);var dd=(e=>(e.Horizontal="x",e.Vertical="y",e))(dd||{});Object.values(dd);var wg=({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 s=Vt.distance(t.shape.center,n);return{id:r,value:1/s,type:jn.PointerIntersection,priority:Pn.High}}return null},_g=({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:s}=e,i=Vt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:jn.ShapeIntersection,priority:Pn.Normal}}return null},kg=e=>{var t;return(t=wg(e))!=null?t:_g(e)};function Sg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,l=nd(c=>new Js(sg(rg({},e),{register:!1,element:xn(s)}),c)),d=Qu(l);return Se(i,()=>l.id=i),vs(s,c=>l.element=c),Se(o,()=>l.accept=o,void 0,it),Se(t,()=>l.collisionDetector=t??kg),Se(n,()=>n&&(l.data=n)),Se(r,()=>l.disabled=r===!0),Se(a,()=>l.type=a),{droppable:d,get isDropTarget(){return d.isDropTarget},ref:k.useCallback(c=>{var u,f;!c&&((u=l.element)!=null&&u.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=c??void 0)},[l])}}const al=`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>')}")`,fd=(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(", "),s=t==="line"?"&::after":r("&"),i=t==="line"?"&:hover::after, &:focus-visible::after":`${r("&:hover")}, ${r("&:focus-visible")}`;return{cursor:"text",borderRadius:"2px",[s]:{content:'""',display:"inline-block",width:"0.8em",height:"0.8em",ml:"0.4em",verticalAlign:"-0.05em",backgroundColor:"currentColor",maskImage:al,WebkitMaskImage:al,maskSize:"contain",WebkitMaskSize:"contain",maskRepeat:"no-repeat",WebkitMaskRepeat:"no-repeat",opacity:.35,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,pointerEvents:"none"},[i]:{opacity:.8},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:2}}},hd=k.createContext(void 0);function pd(e,t){const n=k.useContext(hd),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function go({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=Be.usePublisherTheme(),[o,a]=k.useState(void 0),l=k.useRef(!1),d=()=>{l.current||o===void 0||(a(void 0),o!==e&&r(o))};pd(o!==void 0&&o!==e,()=>(d(),!0));const c=()=>{l.current=!1,a(e)};if(o===void 0){const u=e==="",f=u&&s;return w.jsx($.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:c,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),c())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...u&&{fontStyle:"italic",opacity:f?0:.6}},fd(i)],children:u?t:e})}return w.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:u=>u.target.select(),onChange:u=>a(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.nativeEvent.isComposing?d():u.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:d,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const $g=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const i={...n};return s?i.break=!0:delete i.break,i}),Tg=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const i=r[t];s.break&&i&&!i.break&&(r[t]={...i,break:!0});const o={...s};return delete o.break,r.splice(n,0,o),r},gd=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),md=e=>`gap.${e}`,Og=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),l=o===0||i.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:Fe(e[o-1]),colspan:t-r}),l&&(r=0),n.push(gd(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Fe(s),colspan:t-r}),n};var Eg=Object.create,vd=Object.defineProperty,Cg=Object.defineProperties,Ig=Object.getOwnPropertyDescriptor,Ag=Object.getOwnPropertyDescriptors,Ns=Object.getOwnPropertySymbols,yd=Object.prototype.hasOwnProperty,bd=Object.prototype.propertyIsEnumerable,Dg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Fr=e=>{throw TypeError(e)},mo=(e,t,n)=>t in e?vd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yi=(e,t)=>{for(var n in t||(t={}))yd.call(t,n)&&mo(e,n,t[n]);if(Ns)for(var n of Ns(t))bd.call(t,n)&&mo(e,n,t[n]);return e},bi=(e,t)=>Cg(e,Ag(t)),Mg=(e,t)=>{var n={};for(var r in e)yd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ns)for(var r of Ns(e))t.indexOf(r)<0&&bd.call(e,r)&&(n[r]=e[r]);return n},Pg=e=>{var t;return[,,,Eg((t=void 0)!=null?t:null)]},xd=["class","method","getter","setter","accessor","field","value","get","set"],or=e=>e!==void 0&&typeof e!="function"?Fr("Function expected"):e,jg=(e,t,n,r,s)=>({kind:xd[e],name:t,metadata:r,addInitializer:i=>n._?Fr("Already initialized"):s.push(or(i||null))}),Rg=(e,t)=>mo(t,Dg("metadata"),e[3]),Zr=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},wd=(e,t,n,r,s,i)=>{for(var o,a,l,d,c,u=t&7,f=!1,h=!1,p=e.length+1,m=xd[u+5],b=e[p-1]=[],x=e[p]||(e[p]=[]),v=(s=s.prototype,Ig({get[n](){return ar(this,i)},set[n](y){return Kt(this,i,y)}},n)),g=r.length-1;g>=0;g--)d=jg(u,n,l={},e[3],x),d.static=f,d.private=h,c=d.access={has:y=>n in y},c.get=y=>y[n],c.set=(y,_)=>y[n]=_,a=(0,r[g])({get:v.get,set:v.set},d),l._=1,a===void 0?or(a)&&(v[m]=a):typeof a!="object"||a===null?Fr("Object expected"):(or(o=a.get)&&(v.get=o),or(o=a.set)&&(v.set=o),or(o=a.init)&&b.unshift(o));return v&&vd(s,n,v),s},_d=(e,t,n)=>t.has(e)||Fr("Cannot "+n),ar=(e,t,n)=>(_d(e,t,"read from private field"),t.get(e)),Vn=(e,t,n)=>t.has(e)?Fr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Kt=(e,t,n,r)=>(_d(e,t,"write to private field"),t.set(e,n),n);function Ut(e){return e instanceof wa||e instanceof Td}var Qr=10,Lg=class extends We{constructor(e){super(e);const t=rt(()=>{const{dragOperation:r}=e;if(wr(r.activatorEvent)&&Ut(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Lr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!wr(r.nativeEvent)||!Ut(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:l}=s,{by:d}=r;if(!d)return;const c=Ng(d),{source:u,target:f}=i,{center:h}=i.shape.current,p=[],m=[];Te(()=>{for(const _ of l.droppables){const{id:S}=_;if(!_.accepts(u)||S===f?.id&&Ut(_)||!_.element)continue;let E=_.shape;const D=new ft(_.element,{getBoundingClientRect:T=>br(T,void 0,.2)});!D.height||!D.width||(c=="down"&&h.y+Qr<D.center.y||c=="up"&&h.y-Qr>D.center.y||c=="left"&&h.x-Qr>D.center.x||c=="right"&&h.x+Qr<D.center.x)&&(p.push(_),_.shape=D,m.push(()=>_.shape=E))}}),r.preventDefault(),a.disable();const b=a.computeCollisions(p,ip);Te(()=>m.forEach(_=>_()));const[x]=b;if(!x)return;const{id:v}=x,{index:g,group:y}=u.sortable;o.setDropTarget(v).then(()=>{const{source:_,target:S,shape:E}=i;if(!_||!Ut(_)||!E)return;const{index:D,group:T,target:A}=_.sortable,q=g!==D||y!==T,P=q?A:S?.element;if(!P)return;yu(P);const z=new ft(P);if(!z)return;const U=ht.delta(z,ht.from(E.current.boundingRectangle),_.alignment);o.move({by:U}),q?o.setDropTarget(_.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Ng(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 Fg=Object.defineProperty,zg=Object.defineProperties,Wg=Object.getOwnPropertyDescriptors,ll=Object.getOwnPropertySymbols,Bg=Object.prototype.hasOwnProperty,Gg=Object.prototype.propertyIsEnumerable,cl=(e,t,n)=>t in e?Fg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))Bg.call(t,n)&&cl(e,n,t[n]);if(ll)for(var n of ll(t))Gg.call(t,n)&&cl(e,n,t[n]);return e},on=(e,t)=>zg(e,Wg(t));function qg(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Jr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function xi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Kg(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,y)=>g===y||g!==null&&typeof g=="object"&&"id"in g&&g.id===y;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),y=e.findIndex(_=>l(_,o.id));if(g===-1||y===-1){if(xi(i)){const _=i.initialIndex,S=i.index;return _===S||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,S)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,y)}const d=Object.entries(e);let c=-1,u,f=-1,h;for(const[g,y]of d)if(c===-1&&(c=y.findIndex(_=>l(_,i.id)),c!==-1&&(u=g)),f===-1&&(f=y.findIndex(_=>l(_,o.id)),f!==-1&&(h=g)),c!==-1&&f!==-1)break;if(c===-1&&xi(i)){const g=i.initialGroup==null?void 0:Jr(e,i.initialGroup),y=i.initialIndex,_=i.group==null?void 0:Jr(e,i.group),S=i.index;if(g==null||_==null||g===_&&y===S)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return on(sn({},e),{[g]:n(e[g],y,S)});const E=e[g][y];return on(sn({},e),{[g]:[...e[g].slice(0,y),...e[g].slice(y+1)],[_]:[...e[_].slice(0,S),E,...e[_].slice(S)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,m=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const g=Jr(e,o.id);if(g!=null){const y=o.shape&&m.y>o.shape.center.y?e[g].length:0;h=g,f=y}}if(u==null||h==null||u===h&&c===f){if(u!=null&&u===h&&c===f&&xi(i)){const g=i.group==null?void 0:Jr(e,i.group),y=i.group!=null&&g!==u,_=i.index!==c;if(y||_){const S=i.group==null?u:g;if(S!=null){if(u===S)return on(sn({},e),{[u]:n(e[u],c,i.index)});const E=e[u][c];return on(sn({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[S]:[...e[S].slice(0,i.index),E,...e[S].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(u===h)return on(sn({},e),{[u]:n(e[u],c,f)});const x=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[u][c];return on(sn({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[h]:[...e[h].slice(0,f+x),v,...e[h].slice(f+x)]})}function Vg(e,t){return Kg(e,t,qg)}function ul(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function dl(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var fl="__default__",Ug=class extends We{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof wa){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Ut(o)||!Ut(a)||o.sortable===a.sortable)return;const l=t(),d=ul(l),c=o.sortable.group===a.sortable.group,u=l.get(o.sortable.group),f=c?u:l.get(a.sortable.group);!u||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,p;const m=t();if(dl(d,l,m))return;const b=o.sortable.element,x=a.sortable.element;if(!x||!b||!c&&a.id===o.sortable.group)return;const v=es(u),g=c?v:es(f),y=(h=o.sortable.group)!=null?h:fl,_=(p=a.sortable.group)!=null?p:fl,S={[y]:v,[_]:g},E=Vg(S,r);if(S===E)return;const D=E[_].indexOf(o.sortable),T=E[_].indexOf(a.sortable);s.collisionObserver.disable(),hl(b,D,x,T),Te(()=>{for(const[A,q]of E[y].entries())q.index=A;if(!c)for(const[A,q]of E[_].entries())q.group=a.sortable.group,q.index=A}),s.actions.setDropTarget(o.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:i}=s,{source:o}=i;Ut(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=ul(a),d=a.get(o.sortable.initialGroup);d&&s.renderer.rendering.then(()=>{const c=t();if(dl(l,a,c))return;const u=es(d),f=es(d,Xg),h=o.sortable.element,p=f.indexOf(o.sortable),m=u[p],b=m?.element;!m||!b||!h||(hl(h,m.index,b,o.index),Te(()=>{for(const x of a.values()){const v=Array.from(x).values();for(const g of v)g.index=g.initialIndex,g.group=g.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function hl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function Hg(e,t){return e.index-t.index}function Xg(e,t){return e.initialIndex-t.initialIndex}function es(e,t=Hg){return Array.from(e).sort(t)}var pl=[Lg,Ug],kd={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function gl(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 ts=new Bf,Sd,$d,It,ba,lr,cr,xa,gn;$d=[he],Sd=[he];var ti=class{constructor(e,t){Vn(this,ba,Zr(It,8,this)),Zr(It,11,this),Vn(this,lr),Vn(this,cr),Vn(this,xa,Zr(It,12,this)),Zr(It,15,this),Vn(this,gn),this.register=()=>(Te(()=>{var p,m;(p=this.manager)==null||p.registry.register(this.droppable),(m=this.manager)==null||m.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Te(()=>{var p,m;(p=this.manager)==null||p.registry.unregister(this.droppable),(m=this.manager)==null||m.registry.unregister(this.draggable)})},this.destroy=()=>{Te(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:l,transition:d=kd,plugins:c}=n,u=Mg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=lt(c,pl),h=gl(s);this.droppable=new wa(bi(yi({},u),{disabled:h.droppable}),t,this),this.draggable=new Td(bi(yi({},u),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var p,m,b;const x=(p=this.manager)==null?void 0:p.dragOperation.status;x?.initializing&&this.id===((b=(m=this.manager)==null?void 0:m.dragOperation.source)==null?void 0:b.id)&&ts.clear(this.manager),x?.dragging&&ts.set(this.manager,this.id,fe(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:m,manager:b}=this,x=ar(this,cr),v=ar(this,lr);(p!==x||m!==v)&&(Kt(this,cr,p),Kt(this,lr,m),this.animate())},()=>{var p,m;const{target:b}=this,{isDragSource:x}=this.draggable;((m=(p=this.draggable.pluginConfig(ua))==null?void 0:p.feedback)!=null?m:"default")==="move"&&x&&(this.droppable.disabled=!b)},...r()],type:l,sensors:a}),t,this),Kt(this,gn,u.element),this.manager=t,this.index=o,Kt(this,cr,o),this.group=i,Kt(this,lr,i),this.type=l,this.transition=d}get initialIndex(){var e,t;return(t=(e=ts.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=ts.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){fe(()=>{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:s}=this;if(!s)return;for(const c of s.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const i=this.refreshShape();if(!i)return;const o={x:n.boundingRectangle.left-i.boundingRectangle.left,y:n.boundingRectangle.top-i.boundingRectangle.top},{translate:a}=mt(s),l=Za(s,a,!1),d=Za(s,a);if(o.x||o.y){const c=na(Ze(s))?bi(yi({},t),{duration:0}):t;bu({element:s,keyframes:{translate:[`${l.x+o.x}px ${l.y+o.y}px ${l.z}`,`${d.x}px ${d.y}px ${d.z}`]},options:c}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Te(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Te(()=>{const t=ar(this,gn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Kt(this,gn,e)})}get element(){var e,t;const n=ar(this,gn);if(n)return(t=(e=Xi.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=lt(e,pl)}set disabled(e){const t=gl(e);Te(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Te(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??xu}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Te(()=>{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)}};It=Pg();ba=new WeakMap;lr=new WeakMap;cr=new WeakMap;xa=new WeakMap;gn=new WeakMap;wd(It,4,"index",$d,ti,ba);wd(It,4,"group",Sd,ti,xa);Rg(It,ti);var Td=class extends Qs{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}},wa=class extends Js{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Yg=Object.defineProperty,Zg=Object.defineProperties,Qg=Object.getOwnPropertyDescriptors,ml=Object.getOwnPropertySymbols,Jg=Object.prototype.hasOwnProperty,em=Object.prototype.propertyIsEnumerable,vl=(e,t,n)=>t in e?Yg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wi=(e,t)=>{for(var n in t||(t={}))Jg.call(t,n)&&vl(e,n,t[n]);if(ml)for(var n of ml(t))em.call(t,n)&&vl(e,n,t[n]);return e},tm=(e,t)=>Zg(e,Qg(t));function nm(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:l,group:d,disabled:c,modifiers:u,sensors:f,target:h,type:p,plugins:m}=e,b=wi(wi({},kd),e.transition),x=nd(g=>new ti(tm(wi({},e),{transition:b,register:!1,handle:xn(a),element:xn(o),target:xn(h)}),g)),v=Qu(x,rm);return Se(s,()=>x.id=s),Fn(()=>{Te(()=>{x.group=d,x.index=l})},[x,d,l]),Se(p,()=>x.type=p),Se(t,()=>x.accept=t,void 0,it),Se(i,()=>i&&(x.data=i)),Se(l,()=>{var g;(g=x.manager)!=null&&g.dragOperation.status.idle&&b?.idle&&x.refreshShape()},Jp),vs(a,g=>x.handle=g),vs(o,g=>x.element=g),vs(h,g=>x.target=g),Se(c,()=>x.disabled=c??!1,void 0,it),Se(f,()=>x.sensors=f,void 0,it),Se(n,()=>x.collisionDetector=n),Se(r,()=>x.collisionPriority=r),Se(m,()=>x.plugins=m,void 0,it),Se(b,()=>x.transition=b,void 0,it),Se(u,()=>x.modifiers=u,void 0,it),Se(e.alignment,()=>x.alignment=e.alignment),{sortable:v,get isDragging(){return v.isDragging},get isDropping(){return v.isDropping},get isDragSource(){return v.isDragSource},get isDropTarget(){return v.isDropTarget},handleRef:k.useCallback(g=>{x.handle=g??void 0},[x]),ref:k.useCallback(g=>{var y,_;!g&&((y=x.element)!=null&&y.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.element=g??void 0)},[x]),sourceRef:k.useCallback(g=>{var y,_;!g&&((y=x.source)!=null&&y.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.source=g??void 0)},[x]),targetRef:k.useCallback(g=>{var y,_;!g&&((y=x.target)!=null&&y.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.target=g??void 0)},[x])}}function rm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const vo="tile",Od="gap",sm=[co.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Ed}]`)!==null||(co.defaults.preventActivation?.(e,t)??!1)}),qu],Ed="data-no-drag",im=e=>[...e,ua.configure({feedback:"clone"})];function om({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=nm({id:e,index:t,type:vo,accept:vo,collisionDetector:sa,plugins:im});return w.jsx(w.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function am({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Sg({id:e,type:Od,accept:vo,collisionDetector:sa,data:{after:t}});return w.jsx(w.Fragment,{children:n({ref:r,isDropTarget:s})})}const Cd=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],Id=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],ni=e=>Id.includes(e),yo=new Set([...Cd,"viz"]);function At(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let s;for(const i of n)if(i.startsWith("-")){if(s!==void 0)return;const o=i.slice(1);if(!yo.has(o))return;r.push(o)}else{if(s!==void 0||!yo.has(i))return;s=i}return{negated:r,...s!==void 0&&{pick:s}}}function Tr(e){const t=e.trim();return!/^#[ \t]/.test(t)||At(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(r=>yo.has(r))}function wn(e,t){return["#",...Id.filter(r=>r!==e&&(t===void 0||t.includes(r))).map(r=>`-${r}`),"-viz",...e==="none"?[]:[e]].join(" ")}function lm(e){return e.pick!==void 0?ni(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function cm(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=At(e[0]);return t?lm(t):"custom"}function um(e){const t=e.filter(n=>At(n));return e.some(Tr)?"custom":t.length===0?void 0:cm(t)}const dm=e=>e.filter(t=>At(t)||Tr(t)),Ad=e=>e.ok===!1,De=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),en=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>De(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>De(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>De(e,"VIEW","subQueryDefList"),defDimension:e=>De(e,"defList","DIMENSION"),exploreProperties:e=>De(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>De(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>De(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>De(e,"WHERE","filterClauseList"),givenDef:e=>De(e,"givenNameDef"),givenStatement:e=>De(e,"GIVEN","givenDefList"),importStatement:e=>De(e,"IMPORT","importURL"),vArrow:e=>De(e,"ARROW","vExpr","segExpr"),segRefine:e=>De(e,"PLUS","segExpr"),segOps:e=>De(e,"queryProperties"),segField:e=>De(e,"fieldPath")&&!De(e,"segExpr"),segParen:e=>De(e,"OPAREN","CPAREN","vExpr"),compare:e=>De(e,"fieldExpr","compareOp"),givenRef:e=>De(e,"GIVEN_REF")};function fm(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 hm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
+ `&&t.push(n+1);return t}function Dd(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!en(s))continue;const i=Ce(s,"docAnnotations");if(i)for(const o of Pt(i,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class ri{constructor(t){this.text=t,this.map=fm(t),this.lineStarts=hm(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!en(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],i=this.map[r.stopIndex+1];if(!(s===void 0||i===void 0||i<s))return{start:s,end:i}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],s=this.map[n.stopIndex+1];if(!(r===void 0||s===void 0||s<r))return{start:r,end:s}}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 s=n+r+1>>1;this.lineStarts[s]<=t?n=s:r=s-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 zr(e,t,n=[]){en(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)zr(e.getChild(r),t,n);return n}const pm=e=>De(e,"OCURLY","CCURLY");function Or(e,t){const n=[],r=s=>{if(en(s)){if(t(s)){n.push(s);return}if(!pm(s))for(let i=0;i<(s.childCount??0);i++)r(s.getChild(i))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Ce=(e,t)=>e[t]?.call(e),Pt=(e,t)=>e[t]?.call(e)??[];function gm(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)),s=e.text_(t.getChild(1)),i=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:i.replace(/^\$/,"")}}function Md(e,t){const n=e.positioned(t);if(!n)return;const r=Ce(t,"filterClauseList"),s=[];for(const i of r?Pt(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=zr(i,ke.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));s.push({...o,givens:a,binding:gm(e,i)})}return{...n,clauses:s}}function bo(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const d of Or(t,ke.queryStatement)){const c=e.positioned(d);c&&r.push(c);const u=Ce(d,"whereStatement");if(u&&ke.whereStatement(u)){const f=Md(e,u);f&&s.push(f)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
+ `),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:l,oneLine:a}}function _a(e,t,n){const r=[],s=e.line(t.start),i=e.line(n);for(let o=s;o<i;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 mm(e,t){const n=Ce(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const s=Ce(n,"queryProperties"),i=s&&bo(e,s);return i?{kind:"inline",stage:i,...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 s=e.span(n);return s?{kind:"reference",from:e.text.slice(s.start,s.end),fromSpan:s}:{kind:"unsupported",why:"an unreadable name"}}if(ke.segRefine(n)){const s=Pt(n,"segExpr"),i=s[0],o=s[s.length-1];let a=i;for(;ke.segRefine(a);){const f=Pt(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 l=e.span(i);if(!l||!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 d=e.text.slice(l.start,l.end),c=Ce(o,"queryProperties"),u=c&&bo(e,c);return u?{kind:"reference",from:d,fromSpan:l,refinement:u}:{kind:"reference",from:d,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function vm(e,t){const n=[];for(const r of Or(t,ke.defExploreQuery)){const s=e.span(r),i=Ce(r,"subQueryDefList");if(!s||!i)continue;const o=Pt(i,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Ce(r,"VIEW"));for(const l of o){const d=e.span(l),c=Ce(l,"exploreQueryNameDef"),u=e.text_(c),f=Ce(l,"vExpr");!d||!u||!f||n.push({name:u,span:d,line:e.line(d.start),statement:s,tags:_a(e,s,a?.start??d.start),siblings:o.length,body:mm(e,f)})}}return n}function ym(e,t){const n=[];for(const r of Or(t,ke.defDimension)){const s=e.span(r),i=Ce(r,"defList");if(!s||!i)continue;const o=e.terminal(Ce(r,"DIMENSION"));for(const a of Pt(i,"fieldDef")){const l=e.span(a),d=e.text_(Ce(a,"fieldNameDef"))?.trim(),c=e.text_(Ce(a,"fieldExpr"))?.trim();!l||!d||c===void 0||n.push({name:d,expression:c,span:l,line:e.line(l.start),statement:s,tags:_a(e,s,o?.start??l.start)})}}return n}function bm(e,t){const n=[];for(const r of zr(t,ke.sourceDefinition)){const s=e.span(r),i=e.text_(Ce(r,"sourceNameDef")),o=Ce(r,"sqExplore");if(!s||!i||!o)continue;const a=e.span(o),l=a?e.text.slice(a.start,a.end):"",d=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(l)?.[1]??"").trim(),c=Or(o,ke.exploreProperties)[0],u=c&&bo(e,c),f={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(c)for(const p of Or(c,ke.whereStatement)){const m=Md(e,p);m&&h.push(m)}n.push({name:i,base:d,span:s,line:e.line(s.start),statement:f,...u?{properties:u}:{},views:c?vm(e,c):[],dimensions:c?ym(e,c):[],wheres:h})}return n}function xm(e,t){const n=[];for(const r of zr(t,ke.givenStatement)){const s=e.terminal(Ce(r,"GIVEN")),i=Ce(r,"givenDefList"),o=s?e.line(s.start):void 0;for(const a of i?Pt(i,"givenDef"):[]){const l=e.span(a),d=e.span(Ce(a,"givenNameDef")),c=d&&e.text.slice(d.start,d.end);if(!l||!d||!c)continue;const u={start:d.start,end:l.end},f=e.line(u.start);n.push({name:c,declaration:e.text.slice(u.start,u.end),span:u,line:f,statement:{start:e.lineStarts[f],end:u.end},tags:_a(e,l,u.start),...o!==void 0&&o!==f?{blockHeader:o}:{}})}}return n}function wm(e,t){const n=[];for(const r of zr(t,ke.importStatement)){const s=e.span(r),i=e.text_(Ce(r,"importURL"));if(!s||i===void 0)continue;const o=Ce(r,"importSelect"),a=o?Pt(o,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:i.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function Pd(e){let t;try{t=await Wr(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,s=r?.root;if(!s||!en(s)||typeof s.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 i=r?.tokenStream??{},o=typeof i.getTokens=="function"?i.getTokens():void 0;if(!o||typeof i.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 ri(e),l=ka(a,i);a.commentLines=l.lines;const d=e.split(`
70
+ `),c=f=>l.lines.has(f);a.proseLines=ge.markdownLines(d,c),a.blocks=ge.blockSpans(d,c).filter(([f])=>!d[f].trimStart().startsWith("##"));const u=bm(a,s);return u.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:wm(a,s),sources:u,givens:xm(a,s),textBlocks:km(a,i),modelNotes:Dd(a,s),trailingComment:f=>l.trailing.get(f),comments:l.all,commentLine:f=>l.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>l.all.find(h=>h.start>=f.start&&h.start<f.end),blockStart:f=>_m(a,l.lines,f)}}}async function Wr(e,t){const{MalloyTranslator:n}=await O.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function ka(e,t){const n=new Map,r=new Set,s=[],i=t.tokenSource?.vocabulary;for(const c of t.getTokens?.()??[]){const u=i?.getSymbolicName(c.type);if(u!=="COMMENT_TO_EOL"&&u!=="BLOCK_COMMENT")continue;const f=e.utf16(c.startIndex);let h=e.utf16(c.stopIndex+1);if(!(f===void 0||h===void 0||h<f)){for(;h>f&&(e.text[h-1]===`
71
+ `||e.text[h-1]==="\r");)h--;s.push({start:f,end:h})}}const o=[...s].sort((c,u)=>c.start-u.start);let a="",l=0;for(const c of o)a+=e.text.slice(l,Math.max(l,c.start)),a+=e.text.slice(Math.max(l,c.start),Math.max(l,c.end)).replace(/[^\n\r]/g," "),l=Math.max(l,c.end);a+=e.text.slice(l);const d=c=>a.slice(e.lineStarts[c],e.lineStarts[c+1]??a.length);for(const c of s){const u=e.line(c.start),f=e.line(c.end-1);for(let m=u;m<=f;m++)d(m).trim()===""&&r.add(m);const h=a.slice(e.lineStarts[u],c.start).trim(),p=a.slice(c.end,e.lineStarts[f+1]??a.length).trim();h!==""&&p===""&&n.set(f,c)}return{trailing:n,lines:r,all:s}}function _m(e,t,n){const r=i=>e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();let s=n;for(let i=n-1;i>=0;i--){const o=r(i),a=e.blocks.find(([,l])=>l===i);if(a){s=i=a[0];continue}if(o===""&&!t.has(i))break;if(o.startsWith("#")||t.has(i))s=i;else break}return s}function km(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,s=a=>r?.getSymbolicName(a.type),i=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(s(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const l=ge.textBlockOpener(i(n[a]).replace(/\r?\n$/,""));if(!l)continue;const d=[];let c=a+1;for(;s(n[c]??n[a])==="BLOCK_ANNOTATION_TEXT";c++)d.push(i(n[c]));const u=n[c];if(!u||s(u)!=="BLOCK_ANNOTATION_END")continue;const f=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(u.stopIndex+1)??e.text.length,p=l.name===void 0&&l.rest?[`${l.rest}
72
72
  `]:[];o.push({...l.name===void 0?{}:{name:l.name},route:l.route,body:[...p,...d].join("").replace(/\r\n?/g,`
73
- `).replace(/\n$/,""),span:{start:e.lineStarts[f],end:h},line:f}),a=u}return o}function Rd(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 Sa(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=Rd(e,r);else if(s==="{"||s==="[")t++===0&&n++;else if(s==="}"||s==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const i=/^tiles\s*=\s*\[/.exec(e.slice(r));if(i)return Sm(e,r+i[0].length-1)}}}function Sm(e,t){const n=[];let r=0,s=t+1;const i=o=>{const a=e.slice(s,o),l=a.length-a.trimStart().length,d=a.trim();d!==""&&n.push({text:d,span:{start:s+l,end:s+l+d.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=Rd(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return i(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(i(o),s=o+1)}}function $m(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]===`
73
+ `).replace(/\n$/,""),span:{start:e.lineStarts[f],end:h},line:f}),a=c}return o}function jd(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 Sa(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=jd(e,r);else if(s==="{"||s==="[")t++===0&&n++;else if(s==="}"||s==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const i=/^tiles\s*=\s*\[/.exec(e.slice(r));if(i)return Sm(e,r+i[0].length-1)}}}function Sm(e,t){const n=[];let r=0,s=t+1;const i=o=>{const a=e.slice(s,o),l=a.length-a.trimStart().length,d=a.trim();d!==""&&n.push({text:d,span:{start:s+l,end:s+l+d.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=jd(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return i(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(i(o),s=o+1)}}function $m(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 s=e.indexOf(`
75
75
  `,r),i=s===-1?e.length:s;if(e.slice(r,i).trim()===">>>")return i;if(s===-1)return e.length;r=s+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let s=t+3;s<e.length;s++)if(e[s]==="\\")s++;else if(e.startsWith(r,s))return s+3;return e.length}for(let s=t+1;s<e.length;s++)if(e[s]==="\\")s++;else{if(e[s]===n)return s+1;if(e[s]===`
76
- `)return s}return e.length}return t}function Tm(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=$m(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const i=e[r];if(/[=[,]/.test(i)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${i}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=i,r+=1}return n}function $a(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(i=>{if(e([i]).log.length===0)return i;const o=Tm(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const yl=(e,t)=>{try{return e.text(t)}catch{return}},Om=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Em=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 jd(e,t){const n=e.filter(Om).filter(l=>!l.includes("@env.")).map(ge.tagAnnotation),{tag:r,errors:s}=n.length>0?$a(t,n):{tag:void 0,errors:[]},i=r?.tag("artifact");if(!i)return e.some(ge.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const o=yl(i,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=yl(i,"layout");return a==="grid"||a==="linear"?{status:"report",layout:a}:i.has("tiles")||r?.tag("dashboard")!==void 0?{status:"report",layout:"grid"}:{status:"report",layout:"linear"}}async function Cm(e){const{parseAnnotation:t}=await O.loadMalloyTag();let n=[];try{const r=(await Wr(e,"file://report.malloy")).parse?.root;r&&en(r)&&typeof r.getChild=="function"&&(n=Ad(new ri(e),r))}catch{n=[]}return jd(n,t)}const Er=e=>e.ok===!1;function Br(e,t,n){const r=e.blockStart(n),s=[],i=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){i.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:o,text:a})}return{start:r,tags:s,prose:i}}const Fs=e=>e.map(t=>t.text);function bl(e){const t=Fs(e),n=um(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:dm(t)}:{chart:n}}function Im(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:i,given:o}=r.binding;t.push({field:ge.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Dm(e,t,n){const r=[];for(const s of e.givens){const i=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);i&&r.push({name:i[1],type:i[2],default:i[3].trim(),...Am(n(Fs(Br(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Am(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),s=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},...s===void 0?{}:{rangeMax:s}}}function _i(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 Mm=/^"((?:[^"\\]|\\.)+)"$/,Pm=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Cr(e,t,n=!1){try{return await Rm(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 Rm(e){const{parseAnnotation:t}=await O.loadMalloyTag(),n=ge.splitSourceLines(e),r=await Pd(e);if(Dd(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,i=ge.descriptionNotes(n).text,o=jd(s.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:Em(o.kind)};const a=o.layout,l=ge.artifactTag(n);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!ge.artifactLeads(l.text))return{ok:!1,reason:ge.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:d,errors:u}=$a(t,[ge.tagAnnotation(l.text)]),c=d?.tag("artifact"),f=Sa(l.text);if(f===void 0)return u.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${u[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=s.imports.map(S=>S.names?{kind:"names",names:S.names,from:S.from}:{kind:"all",from:S.from}),p=[],m=[],b=new Map;for(const S of s.sources){const E={name:S.name,base:S.base};S.dimensions.length>0&&(E.dimensions=S.dimensions.map(T=>({name:T.name,expression:T.expression})));const A=new Set(S.wheres.flatMap(T=>T.clauses.flatMap(D=>D.givens)));A.size>0&&(E.scopedBy=Array.from(A)),p.push(E);for(const T of S.dimensions){const D=t(Fs(Br(s,n,T.line).tags)).tag?.tag("drill");if(!D)continue;const q=D.textArray("to")??[D.text("to")??""];m.push({source:S.name,name:T.name,expression:T.expression,to:q.filter(Boolean),...D.text("given")?{given:D.text("given")}:{}})}b.set(S.name,new Map(S.views.map(T=>[T.name,T])))}const w=[];for(const{text:S}of f.entries){const E=Mm.exec(S),A=E?void 0:Pm.exec(S)?.[1];if(A!==void 0){const J=t([`# ${S}`]).tag?.tag(A);if(J?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${S}\` is neither a quoted \`source -> view\` expression nor a \`${A} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(w.some(de=>Re(de)&&de.name===A))return{ok:!1,reason:`Two text tiles are named \`${A}\`, so the builder cannot tell them apart.`};const ie=_i(J,"colspan");w.push({kind:"text",name:A,markdown:s.textBlocks.find(de=>de.name===A)?.body??"",...ie===void 0?{}:{colspan:ie},...J.has("break")?{break:!0}:{}});continue}const T=E?.[1]??S,D=E?ge.tileSteps(T):void 0;if(!D)return{ok:!1,reason:`The tile \`${T}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:q,view:P}=D,z=b.get(q)?.get(P);if(z===void 0){w.push({name:P,source:q,declaration:{kind:"inherited"}});continue}const U=t(Fs(z.tags)).tag,K=z.body.kind==="reference"?{kind:"reference",from:z.body.from}:z.body.kind==="inline"?{kind:"inline"}:void 0;if(K===void 0){w.push({name:P,source:q,declaration:{kind:"opaque",why:z.body.kind==="unsupported"?z.body.why:"unreadable"},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(z.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}});continue}const Z=Im(z.body.kind==="reference"?z.body.refinement:z.body.kind==="inline"?z.body.stage:void 0);w.push({name:P,source:q,declaration:K,...Z?{filters:Z}:{},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(z.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}})}const v=Dm(s,n,t),g={},y=c?.tag("givens");for(const S of Object.keys(y?.dict??{})){const E=y?.text(S);E!==void 0&&(g[S]=E)}const _=d?.tag("dashboard")?.has("columns")?_i(d.tag("dashboard"),"columns"):c?.array("tiles")?_i(c,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:c?.text("title")??"",...i?{description:i}:{},..._===void 0?{}:{columns:_},...c?.has("autorun")?{autorun:c.isTrue("autorun")}:{},imports:h,sources:p,...v?{localGivens:v}:{},...Object.keys(g).length>0?{startingGivens:g}:{},...m.length>0?{drills:m}:{},tiles:w}}}const zs=e=>e.ok===!1;async function xl(e){const{problems:t}=await Wr(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function _e(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function Ld(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function jm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
- `&&t.push(n+1);return t}function Lm(e,t){let n=e;const r=t.map((s,i)=>({edit:s,index:i}));for(const{edit:s}of r.sort((i,o)=>o.edit.start-i.edit.start||o.edit.end-i.edit.end||o.index-i.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const Nd=e=>e==="none"||ni(e)?e:void 0;function Fd(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=${at(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${at(e.subtitle)}`);const r=t?Nd(e.chart):void 0;return r!==void 0&&n.push(wn(r,e.chartCarried)),n}function bs(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Nm=new Set(["colspan","break","borderless","label","subtitle"]),Fm=new Set(["label","description","control","suggest","range_min","range_max"]);function wl(e){const t=[];if(e.label!==void 0&&t.push(`label=${at(e.label)}`),e.description!==void 0&&t.push(`description=${at(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=${at(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${at(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 _l=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function zm(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function kl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:at(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(at).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ws=e=>`${e.source}.${e.name}`,at=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,xo=e=>Re(e)?_e(["text",e.name]):_e([e.name,e.source,e.declaration]),tt=xo,Sl=e=>_e(e.tiles.map(tt));function Wm(e,t,n){const r=new Set(e.tiles.map(tt)),s=new Set(t.tiles.map(tt)),i=e.tiles.filter(h=>!s.has(tt(h))),o=t.tiles.filter(h=>!r.has(tt(h))),l=i.length>0||o.length>0||Sl(e)!==Sl(t);for(const h of o)if(xe(h)&&h.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${h.name}\` is ${h.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const d=new Map(e.sources.map(h=>[h.name,h])),u=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)u.add(h.base);const c=t.imports.some(h=>h.kind==="all"),f=t.sources.filter(h=>!d.has(h.name));for(const h of e.sources){const p=t.sources.find(m=>m.name===h.name);if(!p||p.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of f){if(!o.some(p=>xe(p)&&p.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!u.has(h.base)&&!c&&!n?.includes(h.base))return{ok:!1,reason:`\`${h.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:s,removedTiles:i,addedTiles:o,newSources:f,currentSources:d,reordered:l}}const $l=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function Bm(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Ir(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Tl(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=Bm(t),r=n.indexOf("{"),s=n.lastIndexOf("}");let i=t.slice(r+1,s),o=n.slice(r+1,s);const a=d=>{const u=d.exec(o);u&&(i=i.slice(0,u.index)+i.slice(u.index+u[0].length),o=o.slice(0,u.index)+o.slice(u.index+u[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const l=[i.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${l.join(" ")} }${t.slice(s+1)}`}function Gm(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:i,currentKeys:o,nextKeys:a,edits:l}=e,d=new Map(r.tiles.filter(Re).map(v=>[v.name,v])),u=s.tiles.filter(Re).some(v=>{const g=d.get(v.name);return g!==void 0&&$l(g,v)});if(!i&&!u)return;const c=ge.artifactTag(t);if(!c)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=c.text,h=Sa(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 p=new Map;for(const{text:v}of h.entries){const g=/^"((?:[^"\\]|\\.)+)"$/.exec(v);if(g){const _=g[1].split("->").map(S=>S.trim());_.length===2&&p.set(`${_[0]}->${_[1]}`,v);continue}const y=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(v)?.[1];y!==void 0&&p.set(`text.${y}`,v)}const m=s.tiles.map(v=>{const g=!o.has(tt(v));if(Re(v)){const y=p.get(`text.${v.name}`);return y!==void 0?d.has(v.name)&&!$l(d.get(v.name),v)?y:Tl(v,y):g?Tl(v):void 0}return p.get(`${v.source}->${v.name}`)??(g?`"${v.source} -> ${v.name}"`:void 0)});if(m.some(v=>v===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const b=f.slice(0,h.open).search(/tiles\s*=\s*$/),w=`${f.slice(0,b)}tiles=[${qm(f,h,m)}]${f.slice(h.close+1)}`;w!==f&&l.push({...zd(n,c),text:`${w}
76
+ `)return s}return e.length}return t}function Tm(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=$m(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const i=e[r];if(/[=[,]/.test(i)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${i}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=i,r+=1}return n}function $a(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(i=>{if(e([i]).log.length===0)return i;const o=Tm(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const yl=(e,t)=>{try{return e.text(t)}catch{return}},Om=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Em=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 Rd(e,t){const n=e.filter(Om).filter(l=>!l.includes("@env.")).map(ge.tagAnnotation),{tag:r,errors:s}=n.length>0?$a(t,n):{tag:void 0,errors:[]},i=r?.tag("artifact");if(!i)return e.some(ge.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const o=yl(i,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=yl(i,"layout");return a==="grid"||a==="linear"?{status:"report",layout:a}:i.has("tiles")||r?.tag("dashboard")!==void 0?{status:"report",layout:"grid"}:{status:"report",layout:"linear"}}async function Cm(e){const{parseAnnotation:t}=await O.loadMalloyTag();let n=[];try{const r=(await Wr(e,"file://report.malloy")).parse?.root;r&&en(r)&&typeof r.getChild=="function"&&(n=Dd(new ri(e),r))}catch{n=[]}return Rd(n,t)}const Er=e=>e.ok===!1;function Br(e,t,n){const r=e.blockStart(n),s=[],i=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){i.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:o,text:a})}return{start:r,tags:s,prose:i}}const Fs=e=>e.map(t=>t.text);function bl(e){const t=Fs(e),n=um(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:dm(t)}:{chart:n}}function Im(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:i,given:o}=r.binding;t.push({field:ge.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Am(e,t,n){const r=[];for(const s of e.givens){const i=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);i&&r.push({name:i[1],type:i[2],default:i[3].trim(),...Dm(n(Fs(Br(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Dm(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),s=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},...s===void 0?{}:{rangeMax:s}}}function _i(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 Mm=/^"((?:[^"\\]|\\.)+)"$/,Pm=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Cr(e,t,n=!1){try{return await jm(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 jm(e){const{parseAnnotation:t}=await O.loadMalloyTag(),n=ge.splitSourceLines(e),r=await Pd(e);if(Ad(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,i=ge.descriptionNotes(n).text,o=Rd(s.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:Em(o.kind)};const a=o.layout,l=ge.artifactTag(n);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!ge.artifactLeads(l.text))return{ok:!1,reason:ge.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:d,errors:c}=$a(t,[ge.tagAnnotation(l.text)]),u=d?.tag("artifact"),f=Sa(l.text);if(f===void 0)return c.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${c[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=s.imports.map(S=>S.names?{kind:"names",names:S.names,from:S.from}:{kind:"all",from:S.from}),p=[],m=[],b=new Map;for(const S of s.sources){const E={name:S.name,base:S.base};S.dimensions.length>0&&(E.dimensions=S.dimensions.map(T=>({name:T.name,expression:T.expression})));const D=new Set(S.wheres.flatMap(T=>T.clauses.flatMap(A=>A.givens)));D.size>0&&(E.scopedBy=Array.from(D)),p.push(E);for(const T of S.dimensions){const A=t(Fs(Br(s,n,T.line).tags)).tag?.tag("drill");if(!A)continue;const q=A.textArray("to")??[A.text("to")??""];m.push({source:S.name,name:T.name,expression:T.expression,to:q.filter(Boolean),...A.text("given")?{given:A.text("given")}:{}})}b.set(S.name,new Map(S.views.map(T=>[T.name,T])))}const x=[];for(const{text:S}of f.entries){const E=Mm.exec(S),D=E?void 0:Pm.exec(S)?.[1];if(D!==void 0){const J=t([`# ${S}`]).tag?.tag(D);if(J?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${S}\` is neither a quoted \`source -> view\` expression nor a \`${D} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(x.some(de=>je(de)&&de.name===D))return{ok:!1,reason:`Two text tiles are named \`${D}\`, so the builder cannot tell them apart.`};const ie=_i(J,"colspan");x.push({kind:"text",name:D,markdown:s.textBlocks.find(de=>de.name===D)?.body??"",...ie===void 0?{}:{colspan:ie},...J.has("break")?{break:!0}:{}});continue}const T=E?.[1]??S,A=E?ge.tileSteps(T):void 0;if(!A)return{ok:!1,reason:`The tile \`${T}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:q,view:P}=A,z=b.get(q)?.get(P);if(z===void 0){x.push({name:P,source:q,declaration:{kind:"inherited"}});continue}const U=t(Fs(z.tags)).tag,K=z.body.kind==="reference"?{kind:"reference",from:z.body.from}:z.body.kind==="inline"?{kind:"inline"}:void 0;if(K===void 0){x.push({name:P,source:q,declaration:{kind:"opaque",why:z.body.kind==="unsupported"?z.body.why:"unreadable"},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(z.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}});continue}const Z=Im(z.body.kind==="reference"?z.body.refinement:z.body.kind==="inline"?z.body.stage:void 0);x.push({name:P,source:q,declaration:K,...Z?{filters:Z}:{},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(z.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}})}const v=Am(s,n,t),g={},y=u?.tag("givens");for(const S of Object.keys(y?.dict??{})){const E=y?.text(S);E!==void 0&&(g[S]=E)}const _=d?.tag("dashboard")?.has("columns")?_i(d.tag("dashboard"),"columns"):u?.array("tiles")?_i(u,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:u?.text("title")??"",...i?{description:i}:{},..._===void 0?{}:{columns:_},...u?.has("autorun")?{autorun:u.isTrue("autorun")}:{},imports:h,sources:p,...v?{localGivens:v}:{},...Object.keys(g).length>0?{startingGivens:g}:{},...m.length>0?{drills:m}:{},tiles:x}}}const zs=e=>e.ok===!1;async function xl(e){const{problems:t}=await Wr(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function _e(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function Ld(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Rm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
+ `&&t.push(n+1);return t}function Lm(e,t){let n=e;const r=t.map((s,i)=>({edit:s,index:i}));for(const{edit:s}of r.sort((i,o)=>o.edit.start-i.edit.start||o.edit.end-i.edit.end||o.index-i.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const Nd=e=>e==="none"||ni(e)?e:void 0;function Fd(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=${at(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${at(e.subtitle)}`);const r=t?Nd(e.chart):void 0;return r!==void 0&&n.push(wn(r,e.chartCarried)),n}function bs(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Nm=new Set(["colspan","break","borderless","label","subtitle"]),Fm=new Set(["label","description","control","suggest","range_min","range_max"]);function wl(e){const t=[];if(e.label!==void 0&&t.push(`label=${at(e.label)}`),e.description!==void 0&&t.push(`description=${at(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=${at(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${at(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 _l=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function zm(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function kl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:at(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(at).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ws=e=>`${e.source}.${e.name}`,at=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,xo=e=>je(e)?_e(["text",e.name]):_e([e.name,e.source,e.declaration]),tt=xo,Sl=e=>_e(e.tiles.map(tt));function Wm(e,t,n){const r=new Set(e.tiles.map(tt)),s=new Set(t.tiles.map(tt)),i=e.tiles.filter(h=>!s.has(tt(h))),o=t.tiles.filter(h=>!r.has(tt(h))),l=i.length>0||o.length>0||Sl(e)!==Sl(t);for(const h of o)if(xe(h)&&h.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${h.name}\` is ${h.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const d=new Map(e.sources.map(h=>[h.name,h])),c=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)c.add(h.base);const u=t.imports.some(h=>h.kind==="all"),f=t.sources.filter(h=>!d.has(h.name));for(const h of e.sources){const p=t.sources.find(m=>m.name===h.name);if(!p||p.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of f){if(!o.some(p=>xe(p)&&p.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!c.has(h.base)&&!u&&!n?.includes(h.base))return{ok:!1,reason:`\`${h.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:s,removedTiles:i,addedTiles:o,newSources:f,currentSources:d,reordered:l}}const $l=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function Bm(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Ir(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Tl(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=Bm(t),r=n.indexOf("{"),s=n.lastIndexOf("}");let i=t.slice(r+1,s),o=n.slice(r+1,s);const a=d=>{const c=d.exec(o);c&&(i=i.slice(0,c.index)+i.slice(c.index+c[0].length),o=o.slice(0,c.index)+o.slice(c.index+c[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const l=[i.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${l.join(" ")} }${t.slice(s+1)}`}function Gm(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:i,currentKeys:o,nextKeys:a,edits:l}=e,d=new Map(r.tiles.filter(je).map(v=>[v.name,v])),c=s.tiles.filter(je).some(v=>{const g=d.get(v.name);return g!==void 0&&$l(g,v)});if(!i&&!c)return;const u=ge.artifactTag(t);if(!u)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=u.text,h=Sa(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 p=new Map;for(const{text:v}of h.entries){const g=/^"((?:[^"\\]|\\.)+)"$/.exec(v);if(g){const _=g[1].split("->").map(S=>S.trim());_.length===2&&p.set(`${_[0]}->${_[1]}`,v);continue}const y=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(v)?.[1];y!==void 0&&p.set(`text.${y}`,v)}const m=s.tiles.map(v=>{const g=!o.has(tt(v));if(je(v)){const y=p.get(`text.${v.name}`);return y!==void 0?d.has(v.name)&&!$l(d.get(v.name),v)?y:Tl(v,y):g?Tl(v):void 0}return p.get(`${v.source}->${v.name}`)??(g?`"${v.source} -> ${v.name}"`:void 0)});if(m.some(v=>v===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const b=f.slice(0,h.open).search(/tiles\s*=\s*$/),x=`${f.slice(0,b)}tiles=[${qm(f,h,m)}]${f.slice(h.close+1)}`;x!==f&&l.push({...zd(n,u),text:`${x}
78
78
  `})}function zd(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function qm(e,t,n){const r=t.entries[0],s=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const i=e.slice(t.open+1,r.span.start),o=e.slice(s.span.end,t.close),a=i.slice(i.lastIndexOf(`
79
79
  `)),l=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
80
- `)?a:" "}`;return`${i}${n.join(l)}${o}`}function Km(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=Ir(e,s);else if(i==="{"||i==="[")n++===0&&r++;else if(i==="}"||i==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(s+t.length));if(!o)continue;const a=s+t.length+o[0].length,l=e[a]==='"'?Ir(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),d=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,d)+e.slice(l)}}return e}function Vm(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Ir(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let i=1,o=n+s[0].length;for(;o<e.length&&i>0;o++)e[o]==='"'?o=Ir(e,o):e[o]==="{"?i++:e[o]==="}"&&i--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function Ir(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 Um(e){const{lines:t,wholeLine:n,current:r,next:s,edits:i}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||_e(r.startingGivens)!==_e(s.startingGivens)){const o=ge.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=zd(n,o),l=i.find(g=>g.start===a.start&&g.end===a.end);let d=l?l.text.replace(/\n$/,""):o.text;const u=r.layout!==s.layout,c=d.indexOf("artifact"),f=d.indexOf("{",c);let h=0,p=-1;for(let g=f;g<d.length;g++)if(d[g]==="{")h++;else if(d[g]==="}"&&--h===0){p=g;break}if(f<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let m=d.slice(f+1,p);const b=o.block?`
81
- ${/\n([ \t]+)\S/.exec(m)?.[1]??" "}`:" ",w=g=>o.block?`${m.trimEnd()}${b}${g}
80
+ `)?a:" "}`;return`${i}${n.join(l)}${o}`}function Km(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=Ir(e,s);else if(i==="{"||i==="[")n++===0&&r++;else if(i==="}"||i==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(s+t.length));if(!o)continue;const a=s+t.length+o[0].length,l=e[a]==='"'?Ir(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),d=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,d)+e.slice(l)}}return e}function Vm(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Ir(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let i=1,o=n+s[0].length;for(;o<e.length&&i>0;o++)e[o]==='"'?o=Ir(e,o):e[o]==="{"?i++:e[o]==="}"&&i--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function Ir(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 Um(e){const{lines:t,wholeLine:n,current:r,next:s,edits:i}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||_e(r.startingGivens)!==_e(s.startingGivens)){const o=ge.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=zd(n,o),l=i.find(g=>g.start===a.start&&g.end===a.end);let d=l?l.text.replace(/\n$/,""):o.text;const c=r.layout!==s.layout,u=d.indexOf("artifact"),f=d.indexOf("{",u);let h=0,p=-1;for(let g=f;g<d.length;g++)if(d[g]==="{")h++;else if(d[g]==="}"&&--h===0){p=g;break}if(f<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let m=d.slice(f+1,p);const b=o.block?`
81
+ ${/\n([ \t]+)\S/.exec(m)?.[1]??" "}`:" ",x=g=>o.block?`${m.trimEnd()}${b}${g}
82
82
  `:`${m.trimEnd()} ${g} `,v=(g,y)=>{const _=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${g}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(y===void 0){const S=new RegExp(`
83
83
  ${_.source}[ \\t]*(?=
84
- )`);m=m.replace(o.block&&S.test(m)?S:_,"")}else _.test(m)?m=m.replace(_,S=>`${o.block?S.slice(0,S.length-S.trimStart().length):" "}${g}=${y}`):m=w(`${g}=${y}`)};if(u&&v("layout",s.layout),r.title!==s.title&&v("title",s.title?at(s.title):void 0),r.autorun!==s.autorun&&v("autorun",s.autorun===void 0?void 0:String(s.autorun)),_e(r.startingGivens)!==_e(s.startingGivens)){m=m.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const g=Object.entries(s.startingGivens??{});g.length>0&&(m=w(`givens { ${g.map(([y,_])=>`${y}=${at(_)}`).join(" ")} }`))}o.block?d=`${d.slice(0,f+1)}${m}${d.slice(p)}`:(m=m.replace(/\s{2,}/g," "),d=`${d.slice(0,f+1)}${m.startsWith(" ")?m:` ${m}`}${m.endsWith(" ")?"":" "}${d.slice(p)}`),r.columns!==s.columns&&(d=Km(d,"dashboard_columns"),d=Vm(d),s.columns!==void 0&&(d=`${d.trimEnd()} dashboard { columns=${s.columns} }`)),l?l.text=`${d}
84
+ )`);m=m.replace(o.block&&S.test(m)?S:_,"")}else _.test(m)?m=m.replace(_,S=>`${o.block?S.slice(0,S.length-S.trimStart().length):" "}${g}=${y}`):m=x(`${g}=${y}`)};if(c&&v("layout",s.layout),r.title!==s.title&&v("title",s.title?at(s.title):void 0),r.autorun!==s.autorun&&v("autorun",s.autorun===void 0?void 0:String(s.autorun)),_e(r.startingGivens)!==_e(s.startingGivens)){m=m.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const g=Object.entries(s.startingGivens??{});g.length>0&&(m=x(`givens { ${g.map(([y,_])=>`${y}=${at(_)}`).join(" ")} }`))}o.block?d=`${d.slice(0,f+1)}${m}${d.slice(p)}`:(m=m.replace(/\s{2,}/g," "),d=`${d.slice(0,f+1)}${m.startsWith(" ")?m:` ${m}`}${m.endsWith(" ")?"":" "}${d.slice(p)}`),r.columns!==s.columns&&(d=Km(d,"dashboard_columns"),d=Vm(d),s.columns!==void 0&&(d=`${d.trimEnd()} dashboard { columns=${s.columns} }`)),l?l.text=`${d}
85
85
  `:i.push({...a,text:`${d}
86
- `})}if(r.description!==s.description){const{read:o,blankAbove:a,below:l,belowBlock:d,inBlock:u}=ge.descriptionNotes(t);if(u||s.description===void 0&&d)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const c=Ld(s.description??"").split(`
86
+ `})}if(r.description!==s.description){const{read:o,blankAbove:a,below:l,belowBlock:d,inBlock:c}=ge.descriptionNotes(t);if(c||s.description===void 0&&d)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const u=Ld(s.description??"").split(`
87
87
  `).map(m=>m.trim()===""?'##"':`##" ${m.trim()}`).join(`
88
- `),f=o.length>0&&o[0]<ge.artifactLine(t),h=s.description===void 0,p=f?[...o.slice(1),...h?l:[]]:[...o,...a];for(const m of p)i.push({...n(m),text:""});if(f)i.push({...n(o[0]),text:s.description===void 0?"":`${c}
89
- `});else if(s.description!==void 0){const m=n(ge.artifactLine(t)).start;i.push({start:m,end:m,text:`${c}
90
- `})}}}function Hm(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.localGivens??[]).map(h=>[h.name,h])),d=new Map((i.localGivens??[]).map(h=>[h.name,h])),u=new Map(a.givens.map(h=>[h.name,h])),c=new Set;for(const[h,p]of l){const m=d.get(h);if(m!==void 0&&_e(m)===_e(p))continue;const b=u.get(h);if(b===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:w,prose:v}=Br(a,t,b.line),y=[...(m===void 0?w:w.filter(D=>{const q=bs(D.text);return q!==void 0&&Fm.has(q)})).map(D=>D.line),...m===void 0?v:[]];for(const D of y)o.push({...n(D),text:""}),c.add(D);const _=xt(a,b.span.end-1);if(m===void 0){o.push({start:n(b.line).start,end:n(_).end,text:""});for(let K=b.line;K<=_;K++)c.add(K);const D=Math.min(b.line,...y),q=b.blockHeader??D,P=(t[_+1]??"x").trim()==="",z=q===0||t[q-1].trim()==="",U=b.blockHeader===void 0||![...u.values()].some(K=>K.blockHeader===b.blockHeader&&K.line>b.line&&d.has([...u.entries()].find(([,Z])=>Z===K)?.[0]??""));P&&z&&U&&!c.has(_+1)&&(o.push({...n(_+1),text:""}),c.add(_+1));continue}const S=r(b.line),E=wl(m),T=m.type!==p.type||m.default!==p.default?b.blockHeader===void 0?_l(m):`${m.name} :: ${m.type} is ${m.default}`:t.slice(b.line,_+1).join(`
88
+ `),f=o.length>0&&o[0]<ge.artifactLine(t),h=s.description===void 0,p=f?[...o.slice(1),...h?l:[]]:[...o,...a];for(const m of p)i.push({...n(m),text:""});if(f)i.push({...n(o[0]),text:s.description===void 0?"":`${u}
89
+ `});else if(s.description!==void 0){const m=n(ge.artifactLine(t)).start;i.push({start:m,end:m,text:`${u}
90
+ `})}}}function Hm(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.localGivens??[]).map(h=>[h.name,h])),d=new Map((i.localGivens??[]).map(h=>[h.name,h])),c=new Map(a.givens.map(h=>[h.name,h])),u=new Set;for(const[h,p]of l){const m=d.get(h);if(m!==void 0&&_e(m)===_e(p))continue;const b=c.get(h);if(b===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:x,prose:v}=Br(a,t,b.line),y=[...(m===void 0?x:x.filter(A=>{const q=bs(A.text);return q!==void 0&&Fm.has(q)})).map(A=>A.line),...m===void 0?v:[]];for(const A of y)o.push({...n(A),text:""}),u.add(A);const _=xt(a,b.span.end-1);if(m===void 0){o.push({start:n(b.line).start,end:n(_).end,text:""});for(let K=b.line;K<=_;K++)u.add(K);const A=Math.min(b.line,...y),q=b.blockHeader??A,P=(t[_+1]??"x").trim()==="",z=q===0||t[q-1].trim()==="",U=b.blockHeader===void 0||![...c.values()].some(K=>K.blockHeader===b.blockHeader&&K.line>b.line&&d.has([...c.entries()].find(([,Z])=>Z===K)?.[0]??""));P&&z&&U&&!u.has(_+1)&&(o.push({...n(_+1),text:""}),u.add(_+1));continue}const S=r(b.line),E=wl(m),T=m.type!==p.type||m.default!==p.default?b.blockHeader===void 0?_l(m):`${m.name} :: ${m.type} is ${m.default}`:t.slice(b.line,_+1).join(`
91
91
  `).trim();o.push({start:n(b.line).start,end:n(_).end,text:(E?`${S}${E}
92
92
  `:"")+`${S}${T}
93
- `})}for(const[h,p]of u){if(p.blockHeader===void 0||d.has(h))continue;![...u.values()].some(b=>b.blockHeader===p.blockHeader&&!c.has(b.line))&&!c.has(p.blockHeader)&&(o.push({...n(p.blockHeader),text:""}),c.add(p.blockHeader))}const f=[...d.values()].filter(h=>!l.has(h.name));if(f.length>0){const h=Math.max(-1,...[...u.values()].map(g=>g.line)),p=(()=>{let g=-1;for(let y=0;y<t.length;y++){const _=t[y].trim();(_.startsWith("import ")||g>=0&&/^}\s*from\s/.test(_))&&(g=y)}return g})(),m=h>=0?h:p,b=f.map(g=>{const y=wl(g);return(y?`${y}
93
+ `})}for(const[h,p]of c){if(p.blockHeader===void 0||d.has(h))continue;![...c.values()].some(b=>b.blockHeader===p.blockHeader&&!u.has(b.line))&&!u.has(p.blockHeader)&&(o.push({...n(p.blockHeader),text:""}),u.add(p.blockHeader))}const f=[...d.values()].filter(h=>!l.has(h.name));if(f.length>0){const h=Math.max(-1,...[...c.values()].map(g=>g.line)),p=(()=>{let g=-1;for(let y=0;y<t.length;y++){const _=t[y].trim();(_.startsWith("import ")||g>=0&&/^}\s*from\s/.test(_))&&(g=y)}return g})(),m=h>=0?h:p,b=f.map(g=>{const y=wl(g);return(y?`${y}
94
94
  `:"")+`${_l(g)}
95
95
  `}).join(`
96
- `),w=m>=0?n(m).end:n(0).end;o.push({start:w,end:w,text:`
96
+ `),x=m>=0?n(m).end:n(0).end;o.push({start:x,end:x,text:`
97
97
  ${b}`}),t.some(g=>g.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
98
- `})}}const Ol=(e,t)=>`import { ${e.join(", ")} } from ${at(t)}`;function Xm(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=c=>_e(c.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(_e(n.imports)===_e(r.imports))return;const a=r.imports.flatMap(c=>c.kind==="names"?[{...c,claimed:!1}]:[]),l=new Set([...r.sources.map(c=>c.base),...r.tiles.filter(xe).map(c=>c.source)]),d=t.imports.map((c,f)=>({statement:c,entry:n.imports[f]}));for(const{statement:c,entry:f}of d){if(!f||f.kind!=="names")continue;const h=a.find(g=>!g.claimed&&g.from===f.from);h&&(h.claimed=!0);const p=h?.names??[],b=f.names.filter(g=>!p.includes(g)).find(g=>l.has(g));if(b!==void 0)return{ok:!1,reason:`\`${b}\` is still read by a tile, so its import cannot be removed.`};if(_e(p)===_e(f.names))continue;const w=p.length===0?Ta(t,c.statement):c.statement,v=t.commentIn(w);if(v)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(v.start,v.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({...w,text:p.length===0?"":Ol(p,f.from)})}const u=a.filter(c=>!c.claimed);if(u.length>0){const c=t.imports.at(-1);if(!c)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const f=i(xt(t,c.statement.end-1)).end;s.push({start:f,end:f,text:u.map(h=>`${Ol(h.names,h.from)}
99
- `).join("")})}}function Ym(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.drills??[]).map(u=>[Ws(u),u])),d=new Map((i.drills??[]).map(u=>[Ws(u),u]));for(const u of new Set([...l.keys(),...d.keys()])){const c=l.get(u),f=d.get(u);if(c&&f&&_e(c)===_e(f))continue;const h=f??c;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${u}\` names no destination.`};const p=a.sources.find(v=>v.name===h.source)?.dimensions.find(v=>v.name===h.name);if(p===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}=Br(a,t,p.line),b=m.find(v=>/^#\s*drill\b/.test(v.text)),w=r(p.line);if(f===void 0)b&&o.push({...n(b.line),text:""});else if(b)o.push({...n(b.line),text:`${w}${kl(f)}
100
- `});else{const v=n(p.line).start;o.push({start:v,end:v,text:`${w}${kl(f)}
101
- `})}}}function Zm(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:i}=e;for(const o of r){if(Re(o)||o.declaration.kind==="inherited")continue;const a=Wd(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 l=xt(i,a.statement.start),d=xt(i,a.statement.end-1),u=i.trailingComment(d),c=u&&u.start>=a.statement.end?u.end:a.statement.end;if(i.text.slice(i.lineStarts[l],a.statement.start).trim()!==""||i.text.slice(c,n(d).end).trim()!==""){s.push({...Ta(i,a.statement),text:""});continue}s.push({start:i.lineStarts[l],end:n(d).end,text:""});const h=l===0?"":t[l-1].trim();(t[d+1]??"x").trim()===""&&(l===0||h===""||h.endsWith("{"))&&s.push({...n(d+1),text:""})}}function Qm(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:i,currentSources:o,edits:a,parsed:l}=e,d=new Map;for(const f of s){if(Re(f))continue;const h=d.get(f.source)??[];h.push(f),d.set(f.source,h)}const u=(f,h)=>{const p=f.declaration.kind==="reference"?f.declaration.from:f.name,m=(f.filters??[]).map(b=>`where: ${ge.malloyPath(b.field)} ${b.op??"~"} $${b.given}`).join(", ");return[...Fd(f).map(b=>`${h}${b}`),`${h}view: ${f.name} is ${p}${m?` + { ${m} }`:""}`].join(`
102
- `)};let c=-1;for(const f of l.sources)c=Math.max(c,xt(l,f.span.end-1));for(const[f,h]of d)if(o.has(f)){const p=l.sources.find(y=>y.name===f);if(!p)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!p.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const m=p.line,b=xt(l,p.properties.closeStart);let w=" ";for(let y=m+1;y<b;y++){const _=/^(\s+)view:/.exec(n[y]);if(_){w=_[1];break}}const v=r(b).start,g=(n[b-1]??"").trim()==="";a.push({start:v,end:v,text:(g?"":`
103
- `)+h.map(y=>u(y,w)).join(`
98
+ `})}}const Ol=(e,t)=>`import { ${e.join(", ")} } from ${at(t)}`;function Xm(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=u=>_e(u.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(_e(n.imports)===_e(r.imports))return;const a=r.imports.flatMap(u=>u.kind==="names"?[{...u,claimed:!1}]:[]),l=new Set([...r.sources.map(u=>u.base),...r.tiles.filter(xe).map(u=>u.source)]),d=t.imports.map((u,f)=>({statement:u,entry:n.imports[f]}));for(const{statement:u,entry:f}of d){if(!f||f.kind!=="names")continue;const h=a.find(g=>!g.claimed&&g.from===f.from);h&&(h.claimed=!0);const p=h?.names??[],b=f.names.filter(g=>!p.includes(g)).find(g=>l.has(g));if(b!==void 0)return{ok:!1,reason:`\`${b}\` is still read by a tile, so its import cannot be removed.`};if(_e(p)===_e(f.names))continue;const x=p.length===0?Ta(t,u.statement):u.statement,v=t.commentIn(x);if(v)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(v.start,v.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({...x,text:p.length===0?"":Ol(p,f.from)})}const c=a.filter(u=>!u.claimed);if(c.length>0){const u=t.imports.at(-1);if(!u)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const f=i(xt(t,u.statement.end-1)).end;s.push({start:f,end:f,text:c.map(h=>`${Ol(h.names,h.from)}
99
+ `).join("")})}}function Ym(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.drills??[]).map(c=>[Ws(c),c])),d=new Map((i.drills??[]).map(c=>[Ws(c),c]));for(const c of new Set([...l.keys(),...d.keys()])){const u=l.get(c),f=d.get(c);if(u&&f&&_e(u)===_e(f))continue;const h=f??u;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${c}\` names no destination.`};const p=a.sources.find(v=>v.name===h.source)?.dimensions.find(v=>v.name===h.name);if(p===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}=Br(a,t,p.line),b=m.find(v=>/^#\s*drill\b/.test(v.text)),x=r(p.line);if(f===void 0)b&&o.push({...n(b.line),text:""});else if(b)o.push({...n(b.line),text:`${x}${kl(f)}
100
+ `});else{const v=n(p.line).start;o.push({start:v,end:v,text:`${x}${kl(f)}
101
+ `})}}}function Zm(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:i}=e;for(const o of r){if(je(o)||o.declaration.kind==="inherited")continue;const a=Wd(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 l=xt(i,a.statement.start),d=xt(i,a.statement.end-1),c=i.trailingComment(d),u=c&&c.start>=a.statement.end?c.end:a.statement.end;if(i.text.slice(i.lineStarts[l],a.statement.start).trim()!==""||i.text.slice(u,n(d).end).trim()!==""){s.push({...Ta(i,a.statement),text:""});continue}s.push({start:i.lineStarts[l],end:n(d).end,text:""});const h=l===0?"":t[l-1].trim();(t[d+1]??"x").trim()===""&&(l===0||h===""||h.endsWith("{"))&&s.push({...n(d+1),text:""})}}function Qm(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:i,currentSources:o,edits:a,parsed:l}=e,d=new Map;for(const f of s){if(je(f))continue;const h=d.get(f.source)??[];h.push(f),d.set(f.source,h)}const c=(f,h)=>{const p=f.declaration.kind==="reference"?f.declaration.from:f.name,m=(f.filters??[]).map(b=>`where: ${ge.malloyPath(b.field)} ${b.op??"~"} $${b.given}`).join(", ");return[...Fd(f).map(b=>`${h}${b}`),`${h}view: ${f.name} is ${p}${m?` + { ${m} }`:""}`].join(`
102
+ `)};let u=-1;for(const f of l.sources)u=Math.max(u,xt(l,f.span.end-1));for(const[f,h]of d)if(o.has(f)){const p=l.sources.find(y=>y.name===f);if(!p)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!p.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const m=p.line,b=xt(l,p.properties.closeStart);let x=" ";for(let y=m+1;y<b;y++){const _=/^(\s+)view:/.exec(n[y]);if(_){x=_[1];break}}const v=r(b).start,g=(n[b-1]??"").trim()==="";a.push({start:v,end:v,text:(g?"":`
103
+ `)+h.map(y=>c(y,x)).join(`
104
104
 
105
105
  `)+`
106
106
  `})}else{const p=i.find(g=>g.name===f);if(!p)return{ok:!1,reason:`The tile's source \`${f}\` is not declared.`};const m=`
107
107
  source: ${p.name} is ${p.base} extend {
108
- `+h.map(g=>u(g," ")).join(`
108
+ `+h.map(g=>c(g," ")).join(`
109
109
 
110
110
  `)+`
111
111
  }
112
- `;let b=c;if(b<0)for(let g=0;g<n.length;g++){const y=n[g].trim();(/^(import\s|given:|}\s*from\s)/.test(y)||/^[A-Z_]+\s*::/.test(y))&&(b=g)}const w=b>=0?r(b).end:t.length,v=w===t.length&&!t.endsWith(`
112
+ `;let b=u;if(b<0)for(let g=0;g<n.length;g++){const y=n[g].trim();(/^(import\s|given:|}\s*from\s)/.test(y)||/^[A-Z_]+\s*::/.test(y))&&(b=g)}const x=b>=0?r(b).end:t.length,v=x===t.length&&!t.endsWith(`
113
113
  `)?`
114
- `:"";a.push({start:w,end:w,text:v+m}),c=b}}function Jm(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:i,next:o,edits:a,parsed:l}=e,d=new Map(i.tiles.map(u=>[tt(u),u]));for(const u of o.tiles){const c=d.get(tt(u));if(c===void 0||Re(u)||Re(c)||_e(Bs(c))===_e(Bs(u)))continue;if(u.declaration.kind==="inherited")return{ok:!1,reason:`\`${u.source} -> ${u.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const f=zm(l,u.source,u.name);if(f<0)return{ok:!1,reason:`Could not find where \`${u.name}\` is declared inside \`${u.source}\`.`};const{tags:h}=Br(l,t,f),p=s(f),m=Fd(u,!1),b=new Map(m.map(T=>[bs(T)??T,T])),w=new Set,v=Nd(u.chart),g=El(c)!==El(u);if(g){const T=h.filter(P=>Tr(P.text)),D=h.filter(P=>Dt(P.text)),q=c.chart==="custom"?h.filter(P=>Dt(P.text)||Tr(P.text)):T.length>0?T:D.length>1?D:[];if(q.length>0)return{ok:!1,reason:`\`${u.source} -> ${u.name}\` has a chart line the builder does not model (${q.map(P=>P.text).join(" and ")}), so its chart cannot be changed here.`}}let y=!1;for(const T of h){if(g&&Dt(T.text)){v===void 0?a.push({...r(T.line),text:""}):T.text!==wn(v,u.chartCarried)&&a.push({...r(T.line),text:`${p}${wn(v,u.chartCarried)}
115
- `}),y=!0;continue}const D=bs(T.text);if(D===void 0||!Nm.has(D))continue;const q=b.get(D);if(q===void 0){a.push({...r(T.line),text:""});continue}w.add(D),q!==T.text&&a.push({...r(T.line),text:`${p}${q}
116
- `})}const _=m.filter(T=>!w.has(bs(T)??T));if(g&&v!==void 0&&!y&&_.push(wn(v,u.chartCarried)),_.length>0){const T=n[f];a.push({start:T,end:T,text:_.map(D=>`${p}${D}
117
- `).join("")})}if(_e(c.filters)===_e(u.filters))continue;const S=Wd(e,u);if(!S)return{ok:!1,reason:`Could not find \`${u.name}\`'s declaration to filter it.`};if(S.body.kind==="reference"){const T=ov(e,u,S);if(T)return T;continue}if(S.body.kind!=="inline")return{ok:!1,reason:`\`${u.name}\`'s body is ${S.body.why}, so there is no single first stage to write its filter into.`};const E=Bd(u.filters,S.body.stage);if(E)return Gd(u.name,E.given);const A=qd(e,u,S.body.stage);if(A)return A}}const El=e=>e.chart==="default"?void 0:e.chart,Bs=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...i}=r;return i};function ev(e,t){const n=new Map(e.tiles.map(r=>[tt(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(tt(r));return xe(r)&&r.chart===void 0&&s&&xe(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function xs(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 tv(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&&!ge.isIdentifier(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=xs(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 ki=e=>`##|(markdown) ${e.name}
114
+ `:"";a.push({start:x,end:x,text:v+m}),u=b}}function Jm(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:i,next:o,edits:a,parsed:l}=e,d=new Map(i.tiles.map(c=>[tt(c),c]));for(const c of o.tiles){const u=d.get(tt(c));if(u===void 0||je(c)||je(u)||_e(Bs(u))===_e(Bs(c)))continue;if(c.declaration.kind==="inherited")return{ok:!1,reason:`\`${c.source} -> ${c.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const f=zm(l,c.source,c.name);if(f<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:h}=Br(l,t,f),p=s(f),m=Fd(c,!1),b=new Map(m.map(T=>[bs(T)??T,T])),x=new Set,v=Nd(c.chart),g=El(u)!==El(c);if(g){const T=h.filter(P=>Tr(P.text)),A=h.filter(P=>At(P.text)),q=u.chart==="custom"?h.filter(P=>At(P.text)||Tr(P.text)):T.length>0?T:A.length>1?A:[];if(q.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${q.map(P=>P.text).join(" and ")}), so its chart cannot be changed here.`}}let y=!1;for(const T of h){if(g&&At(T.text)){v===void 0?a.push({...r(T.line),text:""}):T.text!==wn(v,c.chartCarried)&&a.push({...r(T.line),text:`${p}${wn(v,c.chartCarried)}
115
+ `}),y=!0;continue}const A=bs(T.text);if(A===void 0||!Nm.has(A))continue;const q=b.get(A);if(q===void 0){a.push({...r(T.line),text:""});continue}x.add(A),q!==T.text&&a.push({...r(T.line),text:`${p}${q}
116
+ `})}const _=m.filter(T=>!x.has(bs(T)??T));if(g&&v!==void 0&&!y&&_.push(wn(v,c.chartCarried)),_.length>0){const T=n[f];a.push({start:T,end:T,text:_.map(A=>`${p}${A}
117
+ `).join("")})}if(_e(u.filters)===_e(c.filters))continue;const S=Wd(e,c);if(!S)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(S.body.kind==="reference"){const T=ov(e,c,S);if(T)return T;continue}if(S.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${S.body.why}, so there is no single first stage to write its filter into.`};const E=Bd(c.filters,S.body.stage);if(E)return Gd(c.name,E.given);const D=qd(e,c,S.body.stage);if(D)return D}}const El=e=>e.chart==="default"?void 0:e.chart,Bs=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...i}=r;return i};function ev(e,t){const n=new Map(e.tiles.map(r=>[tt(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(tt(r));return xe(r)&&r.chart===void 0&&s&&xe(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function xs(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 tv(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&&!ge.isIdentifier(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=xs(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 ki=e=>`##|(markdown) ${e.name}
118
118
  ${e.markdown===""?"":`${e.markdown}
119
119
  `}|##
120
- `;function nv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,l=new Map(s.tiles.filter(Re).map(h=>[h.name,h])),d=i.tiles.filter(Re),u=h=>o.textBlocks.find(p=>p.name===h),c=new Set(d.map(h=>h.name));for(const h of l.keys()){const p=c.has(h)?void 0:u(h);if(!p)continue;const m=xt(o,p.span.end-1);a.push({...p.span,text:""});const b=r(m+1),w=p.line===0||n[p.line-1].trim()==="";b.end>b.start&&n[m+1].trim()===""&&w?a.push({...b,text:""}):p.line>0&&w&&t.slice(p.span.end).trim()===""&&a.push({...r(p.line-1),text:""})}const f=[];for(const h of d){const p=l.get(h.name),m=u(h.name);if(p===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(ki(h))}else p.markdown!==h.markdown&&(m?a.push({...m.span,text:ki(h)}):f.push(ki(h)))}if(f.length>0){const h=o.textBlocks.filter(v=>v.name===void 0||c.has(v.name)),p=h[h.length-1],m=o.sources.find(v=>v.name.endsWith("_tiles"));if(p){const v=p.span.end,g=t.slice(v);a.push({start:v,end:v,text:`
120
+ `;function nv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,l=new Map(s.tiles.filter(je).map(h=>[h.name,h])),d=i.tiles.filter(je),c=h=>o.textBlocks.find(p=>p.name===h),u=new Set(d.map(h=>h.name));for(const h of l.keys()){const p=u.has(h)?void 0:c(h);if(!p)continue;const m=xt(o,p.span.end-1);a.push({...p.span,text:""});const b=r(m+1),x=p.line===0||n[p.line-1].trim()==="";b.end>b.start&&n[m+1].trim()===""&&x?a.push({...b,text:""}):p.line>0&&x&&t.slice(p.span.end).trim()===""&&a.push({...r(p.line-1),text:""})}const f=[];for(const h of d){const p=l.get(h.name),m=c(h.name);if(p===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(ki(h))}else p.markdown!==h.markdown&&(m?a.push({...m.span,text:ki(h)}):f.push(ki(h)))}if(f.length>0){const h=o.textBlocks.filter(v=>v.name===void 0||u.has(v.name)),p=h[h.length-1],m=o.sources.find(v=>v.name.endsWith("_tiles"));if(p){const v=p.span.end,g=t.slice(v);a.push({start:v,end:v,text:`
121
121
  ${f.join(`
122
122
  `)}${g===""||g.startsWith(`
123
123
  `)?"":`
@@ -126,47 +126,47 @@ ${f.join(`
126
126
  `);a.push({start:v,end:v,text:`${g?"":`
127
127
  `}${f.join(`
128
128
  `)}
129
- `});return}const b=t.length,w=t===""||t.endsWith(`
129
+ `});return}const b=t.length,x=t===""||t.endsWith(`
130
130
 
131
131
  `)?"":t.endsWith(`
132
132
  `)?`
133
133
  `:`
134
134
 
135
- `;a.push({start:b,end:b,text:w+f.join(`
136
- `)})}}const ns=(e,t=ge.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function rv(e,t){const n=new Map(e.tiles.map(o=>[tt(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(tt(o));if(Re(o)){const c=tv(o,a&&Re(a)?a:void 0,r);if(c)return c;continue}const l=a&&xe(a)?a:void 0;if(a&&!l)continue;const d=o.chart;if(d!==void 0&&d!=="default"&&d!=="none"&&!ni(d)&&!(d==="custom"&&l?.chart==="custom"))return`"${String(d)}" is not a chart this editor writes.`;const u=new Set(l?.filters?.map(c=>c.field));for(const c of o.filters??[])if(!u.has(c.field)&&/[\r\n]/.test(c.field))return"A filter field is one line.";if(a===void 0){const c=[o.name,o.source];o.declaration.kind==="reference"&&c.push(o.declaration.from);for(const f of c){const h=ns(f);if(h)return h}}for(const c of["label","subtitle"]){const f=o[c];if(f===void 0||f===l?.[c])continue;const h=O.annotationTextProblem(`tile ${c}`,f);if(h)return h}}const s=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!s.has(o.name))for(const a of[o.name,o.base]){const l=ns(a);if(l)return l}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=O.annotationTextProblem("description line",o);if(a)return a}if(t.title!==e.title){const o=O.annotationTextProblem("title",t.title);if(o)return o}const i=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=i.get(o.name);if(a===void 0){const d=ns(o.name,ge.isStrictName);if(d)return d}const l=o.suggest?.source;if(l!==void 0&&l!==a?.suggest?.source){const d=ns(l);if(d)return`The suggest source is not a name. ${d}`}for(const d of["query","dimension"]){const u=o.suggest?.[d];if(u===void 0||u===a?.suggest?.[d])continue;const c=O.annotationTextProblem(`suggest ${d}`,u);if(c)return c}for(const d of["label","description"]){const u=o[d];if(u===void 0||u===i.get(o.name)?.[d])continue;const c=O.annotationTextProblem(`given ${d}`,u);if(c)return c}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const l=O.annotationTextProblem(`starting value for ${o}`,a);if(l)return l}}const xt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Wd(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Bd(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const s of r.clauses)if(!s.binding)for(const i of s.givens)n.add(i);return(e??[]).find(r=>n.has(r.given))}function Gd(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 ws=e=>`where: ${ge.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Cl(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 sv(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(xt(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function iv(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 Ta(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
137
- `,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[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 qd(e,t,n){const{parsed:r,edits:s}=e,i=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,b)=>({clause:m,index:b})).filter(({clause:m})=>m.binding!==void 0);if(h.length===0)continue;const p=h.filter(({clause:m})=>i.has(m.binding.given));for(const{clause:m}of h)o.add(m.binding.given);if(p.length===0&&h.length===f.clauses.length){const m=Ta(r,f.span),b=sv(r,f.span,m);if(b)return Cl(t.name,r,b);s.push({...m,text:""});continue}p.length>0&&(a=f.span);for(let m=h.length-1;m>=0;m--){const{clause:b,index:w}=h[m],v=i.get(b.binding.given);if(!v){const y=iv(f.clauses,w),_=r.commentIn(y);if(_)return Cl(t.name,r,_);s.push({...y,text:""});continue}const g=ws(v).replace(/^where:\s*/,"");g!==r.text.slice(b.span.start,b.span.end)&&s.push({...b.span,text:g})}}const l=(t.filters??[]).filter(f=>!o.has(f.given));if(l.length===0)return;let d=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const f=r.trailingComment(xt(r,d));f&&f.start>=d&&(d=f.end)}const u=a!==void 0&&!/,\s*$/.test(r.text.slice(0,d))?", ":" ",c=n.oneLine?`${u}${l.map(ws).join(", ")}`:l.map(f=>`
138
- ${n.indent}${ws(f)}`).join("");s.push({start:d,end:d,text:c})}function ov(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=Bd(t.filters,i);if(o)return Gd(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const u=` + { ${a.map(ws).join(", ")} }`;r.push({start:s.end,end:s.end,text:u});return}const l=i.wheres.some(u=>u.clauses.some(c=>!c.binding)),d=i.statements.some(u=>!i.wheres.some(c=>c.span.start===u.span.start));if(a.length===0&&!l&&!d){const u={start:s.end,end:i.span.end},c=e.parsed.commentIn(u);if(c)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(c.start,c.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...u,text:""});return}return qd(e,t,i)}async function Kd(e,t,n={}){if(!(e.includes(`\r
135
+ `;a.push({start:b,end:b,text:x+f.join(`
136
+ `)})}}const ns=(e,t=ge.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function rv(e,t){const n=new Map(e.tiles.map(o=>[tt(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(tt(o));if(je(o)){const u=tv(o,a&&je(a)?a:void 0,r);if(u)return u;continue}const l=a&&xe(a)?a:void 0;if(a&&!l)continue;const d=o.chart;if(d!==void 0&&d!=="default"&&d!=="none"&&!ni(d)&&!(d==="custom"&&l?.chart==="custom"))return`"${String(d)}" is not a chart this editor writes.`;const c=new Set(l?.filters?.map(u=>u.field));for(const u of o.filters??[])if(!c.has(u.field)&&/[\r\n]/.test(u.field))return"A filter field is one line.";if(a===void 0){const u=[o.name,o.source];o.declaration.kind==="reference"&&u.push(o.declaration.from);for(const f of u){const h=ns(f);if(h)return h}}for(const u of["label","subtitle"]){const f=o[u];if(f===void 0||f===l?.[u])continue;const h=O.annotationTextProblem(`tile ${u}`,f);if(h)return h}}const s=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!s.has(o.name))for(const a of[o.name,o.base]){const l=ns(a);if(l)return l}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=O.annotationTextProblem("description line",o);if(a)return a}if(t.title!==e.title){const o=O.annotationTextProblem("title",t.title);if(o)return o}const i=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=i.get(o.name);if(a===void 0){const d=ns(o.name,ge.isStrictName);if(d)return d}const l=o.suggest?.source;if(l!==void 0&&l!==a?.suggest?.source){const d=ns(l);if(d)return`The suggest source is not a name. ${d}`}for(const d of["query","dimension"]){const c=o.suggest?.[d];if(c===void 0||c===a?.suggest?.[d])continue;const u=O.annotationTextProblem(`suggest ${d}`,c);if(u)return u}for(const d of["label","description"]){const c=o[d];if(c===void 0||c===i.get(o.name)?.[d])continue;const u=O.annotationTextProblem(`given ${d}`,c);if(u)return u}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const l=O.annotationTextProblem(`starting value for ${o}`,a);if(l)return l}}const xt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Wd(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Bd(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const s of r.clauses)if(!s.binding)for(const i of s.givens)n.add(i);return(e??[]).find(r=>n.has(r.given))}function Gd(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 ws=e=>`where: ${ge.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Cl(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 sv(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(xt(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function iv(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 Ta(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
137
+ `,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[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 qd(e,t,n){const{parsed:r,edits:s}=e,i=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,b)=>({clause:m,index:b})).filter(({clause:m})=>m.binding!==void 0);if(h.length===0)continue;const p=h.filter(({clause:m})=>i.has(m.binding.given));for(const{clause:m}of h)o.add(m.binding.given);if(p.length===0&&h.length===f.clauses.length){const m=Ta(r,f.span),b=sv(r,f.span,m);if(b)return Cl(t.name,r,b);s.push({...m,text:""});continue}p.length>0&&(a=f.span);for(let m=h.length-1;m>=0;m--){const{clause:b,index:x}=h[m],v=i.get(b.binding.given);if(!v){const y=iv(f.clauses,x),_=r.commentIn(y);if(_)return Cl(t.name,r,_);s.push({...y,text:""});continue}const g=ws(v).replace(/^where:\s*/,"");g!==r.text.slice(b.span.start,b.span.end)&&s.push({...b.span,text:g})}}const l=(t.filters??[]).filter(f=>!o.has(f.given));if(l.length===0)return;let d=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const f=r.trailingComment(xt(r,d));f&&f.start>=d&&(d=f.end)}const c=a!==void 0&&!/,\s*$/.test(r.text.slice(0,d))?", ":" ",u=n.oneLine?`${c}${l.map(ws).join(", ")}`:l.map(f=>`
138
+ ${n.indent}${ws(f)}`).join("");s.push({start:d,end:d,text:u})}function ov(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=Bd(t.filters,i);if(o)return Gd(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const c=` + { ${a.map(ws).join(", ")} }`;r.push({start:s.end,end:s.end,text:c});return}const l=i.wheres.some(c=>c.clauses.some(u=>!u.binding)),d=i.statements.some(c=>!i.wheres.some(u=>u.span.start===c.span.start));if(a.length===0&&!l&&!d){const c={start:s.end,end:i.span.end},u=e.parsed.commentIn(c);if(u)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(u.start,u.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...c,text:""});return}return qd(e,t,i)}async function Kd(e,t,n={}){if(!(e.includes(`\r
139
139
  `)&&!/(?<!\r)\n/.test(e)))return Il(e,t,n);const s=await Il(e.replace(/\r\n/g,`
140
140
  `),t,n);return zs(s)?s:{...s,source:s.source.replace(/\n/g,`\r
141
- `)}}async function Il(e,t,n){const r=await Cr(e);if(Er(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=ev(s,t),o=Wm(s,i,n.visibleSources);if("reason"in o)return o;const a=rv(s,i);if(a)return{ok:!1,reason:a};const l=await Pd(e);if(Dd(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const d=e.split(`
142
- `),u=jm(e),c=v=>({start:u[v],end:v+1<u.length?u[v+1]:e.length}),f=v=>/^\s*/.exec(d[v])?.[0]??"",h=[],p={...o,sourceText:e,parsed:l.parsed,lines:d,starts:u,wholeLine:c,indentOf:f,current:s,next:i,edits:h};for(const v of[Gm,Um,Xm,Hm,Ym,Zm,Qm,Jm,nv]){const g=v(p);if(g)return g}const m=v=>{const{drills:g,localGivens:y,description:_,...S}=v,E=v.tiles.map(A=>{if(Re(A))return A;if(A.filters?.length)return Bs(A);const{filters:T,...D}=A;return Bs(D)});return{...S,..._===void 0?{}:{description:Ld(_)},tiles:E,...g?.length?{drills:[...g].sort((A,T)=>Ws(A).localeCompare(Ws(T)))}:{},...y?.length?{localGivens:y}:{}}};if(h.length===0)return _e(m(s))!==_e(m(i))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const b=Lm(e,h);if((await xl(e)).length===0){const v=await xl(b);if(v.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${v[0]}). Your changes are still here.`}}const w=await Cr(b);return Er(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:_e(m(w.document))!==_e(m(i))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:b}}function Vd({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=Be.usePublisherTheme(),[i,o]=k.useState(!1),a=k.useMemo(()=>i?{text:e}:void 0,[i,e]),{draft:l,patch:d,close:u,discard:c}=Vl(a,i,g=>n(g.text),()=>o(!1)),f=i&&l!==void 0&&l.text!==e,h=l!==void 0&&l.text!==e?xs(l.text):void 0;pd(f,()=>h!==void 0?!1:(u(),!0));const p=k.useRef(null),m=k.useRef(!1);k.useEffect(()=>{i||(m.current=!1)},[i]);const b=k.useCallback(g=>{!g||m.current||(m.current=!0,g.setSelectionRange(g.value.length,g.value.length))},[]);if(!i||l===void 0){const g=e.trim()?xs(e):void 0;return x.jsxs($.Box,{role:"button",tabIndex:0,onClick:y=>{y.target.closest("a")?y.preventDefault():o(!0)},onKeyDown:y=>{y.target===y.currentTarget&&(y.key!=="Enter"&&y.key!==" "||(y.preventDefault(),o(!0)))},sx:[{minHeight:24},fd(s,"prose")],children:[e.trim()?x.jsx(O.Prose,{variant:r,children:e}):x.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),g&&x.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:g})]})}const w=l.text!==e?xs(l.text):void 0,v=()=>{w===void 0&&u()};return x.jsxs($.Stack,{spacing:1,children:[x.jsx($.TextField,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:l.text,placeholder:t,error:w!==void 0,helperText:w,inputRef:b,inputProps:{"aria-label":"Markdown"},onChange:g=>d(y=>{y.text=g.target.value}),onKeyDown:g=>{g.key==="Escape"?v():g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&(g.preventDefault(),v())},onBlur:g=>{g.relatedTarget instanceof Node&&p.current?.contains(g.relatedTarget)||u()}}),x.jsxs($.Stack,{ref:p,direction:"row",spacing:1,children:[x.jsx($.Button,{size:"small",variant:"outlined",disabled:w!==void 0,onClick:v,children:"Done"}),x.jsx($.Button,{size:"small",onMouseDown:g=>g.preventDefault(),onClick:()=>{c(),o(!1)},children:"Cancel"})]})]})}const av="Write markdown: # heading, **bold**, - list";function lv({tile:e,onChange:t,chrome:n="card"}){return x.jsx(O.TileCard,{chrome:n,kind:"text",children:x.jsx(Vd,{markdown:e.markdown,placeholder:av,onCommit:t})})}const Gs=e=>e.label??O.tileTitle(`${e.source} -> ${e.name}`);function cv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:l,resizing:d=!1,width:u,onResizeStart:c,onResizeMove:f,onResizeEnd:h,children:p}){const{theme:m}=Be.usePublisherTheme();return x.jsx(om,{id:Fe(e),index:t,children:({ref:b,handleRef:w})=>x.jsxs($.Box,{ref:b,onClick:a,onPointerDown:v=>{v.button===0&&a()},role:"group","aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Ud(m,{selected:n,flash:r,bare:i}),"&&[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:[p,x.jsx($.Box,{ref:w,"aria-label":`Move ${Kr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),x.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Kr(e)}`,onClick:v=>{v.stopPropagation(),l(v.currentTarget)},sx:{position:"absolute",top:`${-((i?O.BARE_RING_OFFSET_PX+1:0)+12)}px`,right:i?0:"12px",border:m.cardBorder,borderRadius:1,width:28,height:24,zIndex:2,color:m.tileTitle,bgcolor:m.tile,opacity:n||s?.9:0,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,"&:hover":{opacity:1,bgcolor:m.tile}},children:x.jsx(hv,{})}),c&&x.jsx($.Box,{className:"builder-affordance",[Ed]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Kr(e)}`,...u?{"aria-valuenow":u.span,"aria-valuemin":1,"aria-valuemax":u.columns,"aria-valuetext":`${u.span} of ${u.columns} columns`}:{},onKeyDown:v=>{if(!u)return;const g=v.key==="ArrowRight"?u.span+1:v.key==="ArrowLeft"?u.span-1:v.key==="Home"?1:v.key==="End"?u.columns:void 0;g!==void 0&&(v.preventDefault(),v.stopPropagation(),u.onStep(Math.min(Math.max(g,1),u.columns)))},onPointerDown:c,onPointerMove:f,onPointerUp:h,onPointerCancel:h,onClick:v=>v.stopPropagation(),sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:d||n?1:0,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,"&: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&&x.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Kr(e)}`,onClick:v=>{v.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${(i?O.NOTEBOOK_GAP_PX:O.GRID_GAP_PX)/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 ${O.MOTION_FAST}`,...O.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:m.tile}},children:x.jsx(O.AddIcon,{sx:{fontSize:14}})})]})})}const Si=4,Ud=(e,{selected:t,flash:n=!1,bare:r=!1})=>{const s=t||n?e.accent:"transparent",i=t?e.accent:e.cardBorder.replace(/^1px solid /,""),o=`outline-color ${O.MOTION_FAST}, border-color ${O.MOTION_FAST}, opacity ${O.MOTION_FAST}, box-shadow ${O.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-O.BARE_RING_OFFSET_PX}px`,borderRadius:1,border:`2px solid ${s}`,pointerEvents:"none",transition:o,...O.reducedMotionSx},"&:hover::before":{borderColor:i}}:{borderRadius:1,outline:`2px solid ${s}`,outlineOffset:2,...n&&{boxShadow:`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`},transition:o,...O.reducedMotionSx,"&:hover":{outlineColor:i,boxShadow:e.shadow.lift}}};function uv({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=Be.usePublisherTheme();return x.jsxs(O.TileCard,{chrome:r,children:[x.jsx(O.TileHeading,{title:t?.title??Gs(e),subtitle:t?t.subtitle:e.subtitle}),n&&x.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),x.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function dv({after:e}){const{theme:t}=Be.usePublisherTheme();return x.jsx(am,{id:md(e),after:e,children:({ref:n,isDropTarget:r})=>x.jsx($.Box,{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 ${O.MOTION_FAST}, background-color ${O.MOTION_FAST}`,...O.reducedMotionSx}})})}function fv({columns:e}){const{theme:t}=Be.usePublisherTheme();return x.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${O.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>x.jsx($.Box,{sx:{borderLeft:`1px dashed ${t.accent}`,borderRight:r===e-1?`1px dashed ${t.accent}`:"none",opacity:.35}},r))})}function hv(){return x.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[x.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),x.jsx("circle",{cx:"12",cy:"12",r:"2"}),x.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function pv({editor:e,reorder:t,resizing:n,gridBox:r,columns:s,notebook:i,chrome:o,canAdd:a,selected:l,flash:d,menuIndex:u,onSelect:c,onOpenMenu:f,openAdd:h,editTile:p,renderTile:m}){const{dragging:b,preview:w,onDragStart:v,onDragOver:g,onDragEnd:y}=t,{resize:_,startResize:S,onResize:E,endResize:A}=n,T=_!==void 0?e.document.tiles.map((z,U)=>U===_.index?{...z,colspan:_.span}:z):w??e.document.tiles,D=e.document.tiles.length===0,q=b?Og(T,s):T.map(gd),P=z=>gv(z,Gs(z),p);return x.jsxs(x.Fragment,{children:[x.jsx(lg,{sensors:sm,onDragStart:v,onDragOver:g,onDragEnd:y,children:x.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[!i&&(b||_!==void 0)&&x.jsx(fv,{columns:s}),x.jsx(O.DashboardGrid,{tiles:q,columns:s,rowGapPx:o==="none"?O.NOTEBOOK_GAP_PX:O.GRID_GAP_PX,keyOf:z=>z.kind==="gap"?md(z.after):Fe(z.tile),renderTile:z=>{if(z.kind==="gap")return x.jsx(dv,{after:z.after});const{tile:U,index:K}=z;return x.jsx(cv,{tile:U,index:K,selected:K===l,flash:Fe(U)===d,menuOpen:u===K,bare:o==="none",...i&&a?{onInsertAfter:()=>h(K+1)}:{},...s>1&&mv(U)?{resizing:_?.index===K,width:{span:U.colspan??1,columns:s,onStep:Z=>{Z!==(U.colspan??1)&&e.update(J=>{const ie=J.tiles[K];ie&&(ie.colspan=Z)})}},onResizeStart:Z=>S(Z,K),onResizeMove:E,onResizeEnd:A}:{},onSelect:()=>c(K),onOpenMenu:Z=>f(Z,K),children:Re(U)?x.jsx(lv,{tile:U,chrome:o,onChange:Z=>p(Fe(U),J=>{Re(J)&&(J.markdown=Z)})}):m&&!e.pendingOpen?m(U,P(U),o):x.jsx(uv,{tile:U,chrome:o,heading:P(U),...e.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),i&&a&&!D&&x.jsx($.Button,{size:"small",startIcon:x.jsx(O.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>h(),sx:{alignSelf:"center"},children:"Add tile"})]})}const gv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Fe(e),s=i=>o=>n(r,a=>{xe(a)&&(o===""?delete a[i]:a[i]=o)});return{title:x.jsx(go,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:x.jsx(go,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},mv=e=>Re(e)||e.declaration.kind!=="inherited";function vv({editor:e,documentSlug:t,chrome:n,actions:r,descriptionSelected:s,selectDescription:i}){const{theme:o}=Be.usePublisherTheme();return x.jsxs(x.Fragment,{children:[x.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:2},children:[x.jsx($.Typography,{variant:"h5",sx:{flex:1,minWidth:0},children:x.jsx(go,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:a=>e.update(l=>{l.title=a})})}),x.jsx($.Box,{sx:{my:"-4px"},children:r})]}),x.jsx($.Box,{role:"group","aria-label":"Description","aria-current":s,onPointerDown:i,onFocus:i,sx:n==="none"?{my:`${O.BARE_DESCRIPTION_MARGIN_PX}px`}:void 0,children:x.jsx(O.TileCard,{chrome:n,kind:"text",sx:{position:"relative",overflow:"visible",...Ud(o,{selected:s,bare:n==="none"})},children:x.jsx(Vd,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:a=>e.update(l=>{a.trim()===""?delete l.description:l.description=a})})})})]})}const yv=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:i}=O.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:o,structural:a,durationMs:l,fromOpen:d})=>i({type:"report.saved",tiles:o,structural:a,...d?{converted:!0}:{},where:r,durationMs:l}),refused:o=>i({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:l})=>i({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:l}),undoRefused:o=>i({type:"report.save_undo_refused",reason:o})}},bv=O.createSvgIcon(x.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"})),xv=O.createSvgIcon(x.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"})),wo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),$i=wo?"⌘":"Ctrl+",Dl=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Ti=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function wv(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const s=i=>{const o=t.current;if(o.paused)return;const a=wo?i.metaKey:i.ctrlKey,l=i.key.toLowerCase();if(i.key==="Escape"){if(Dl(i.target)||Ti(i.target))return;o.escape();return}if(Dl(i.target)){if(a&&l==="s"){if(i.preventDefault(),!o.save||Ti(i.target))return;i.target.blur(),r(!0)}return}if(Ti(i.target)){a&&l==="s"&&i.preventDefault();return}if(a&&l==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!wo&&a&&l==="y"){i.preventDefault(),o.redo();return}if(a&&l==="s"){i.preventDefault(),o.save?.();return}o.nudge&&!a&&!i.altKey&&!i.shiftKey&&(i.key==="ArrowLeft"||i.key==="ArrowRight")&&(i.preventDefault(),o.nudge(i.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Al={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function _v({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:l,saveButton:d,actions:u,onAddTile:c,onExit:f,layout:h,onLayoutChange:p}){return x.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[h&&p&&x.jsxs(x.Fragment,{children:[x.jsx($.Tooltip,{title:"Layout: tiles side by side, or one after another",children:x.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:h,"aria-label":"Layout",onChange:(m,b)=>{b&&b!==h&&p(b)},sx:{"& .MuiToggleButton-root":{py:.25,px:1}},children:[x.jsx($.ToggleButton,{value:"linear","aria-label":"Linear layout",children:"Linear"}),x.jsx($.ToggleButton,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),x.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}})]}),c&&x.jsx($.Button,{startIcon:x.jsx(O.AddIcon,{}),onClick:c,"aria-label":"Add tile",children:"Tile"}),c&&x.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),x.jsx($.Tooltip,{title:`Undo (${$i}Z)`,children:x.jsx("span",{children:x.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:x.jsx(xv,{fontSize:"small"})})})}),x.jsx($.Tooltip,{title:`Redo (${$i}⇧Z)`,children:x.jsx("span",{children:x.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:x.jsx(bv,{fontSize:"small"})})})}),(u||o||f)&&x.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),u,o?x.jsx($.Tooltip,{title:s?`Save (${$i}S) · ${l??Al[a]}`:l??Al[a],children:x.jsx("span",{children:x.jsx($.Button,{ref:d,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{minWidth:124},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&x.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:i?"Saving":s?"Unsaved changes":"All changes saved"}),f&&x.jsx(O.SecondaryButton,{label:"Close",icon:x.jsx(O.CheckIcon,{}),onClick:f})]})}const kv=O.createSvgIcon(x.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"})),Sv=O.createSvgIcon(x.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function $v({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:s,addDisabledReason:i,onRemove:o,children:a}){const{theme:l}=Be.usePublisherTheme();return x.jsx(x.Fragment,{children:x.jsxs($.Stack,{sx:{gap:1,position:"sticky",top:0,zIndex:O.STICKY_CONTROLS_Z,bgcolor:"background.default",pb:1},children:[x.jsx($.Stack,{direction:"row",sx:{gap:2,alignItems:"center",minHeight:32},children:x.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",flex:1,minWidth:0},children:[x.jsx(Sv,{sx:{fontSize:18,color:l.tileTitle,opacity:.7}}),x.jsx($.Typography,{variant:"subtitle2",sx:{color:l.tileTitle,mr:.5},children:"Filters"}),e.length===0&&x.jsx($.Typography,{variant:"body2",sx:{color:l.tileTitle,opacity:.8},children:"None yet."}),e.map(d=>{const u=n(d.name,d.type);return x.jsx($.Tooltip,{title:u.length>0?`$${d.name} · cannot filter on: ${u.join(", ")}`:`$${d.name} · ${d.origin==="dashboard"?"declared here":"from the model"} · ${d.boundTiles} of ${t} tiles`,children:x.jsx($.Chip,{size:"small",label:`${d.label??d.name}${d.boundTiles===0?" · unused":""}`,"aria-label":`Edit filter ${d.name}`,color:u.length>0?"warning":"default",variant:d.origin==="dashboard"?"filled":"outlined",onClick:()=>r(d),onDelete:()=>o(d.name),deleteIcon:x.jsx(kv,{"aria-label":`Remove filter ${d.name}`}),sx:{opacity:d.boundTiles===0?.6:1,cursor:"pointer",transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx}})},d.name)}),x.jsx($.Tooltip,{title:i??"",children:x.jsx("span",{children:x.jsx($.Chip,{component:"button",size:"small",variant:"outlined",icon:x.jsx(O.AddIcon,{}),label:"Filter","aria-label":"Add filter","aria-haspopup":"dialog",disabled:i!==void 0,onClick:()=>s(),sx:{cursor:"pointer",color:l.tileTitle,borderStyle:"dashed","& .MuiChip-icon":{color:"inherit",fontSize:16}}})})})]})}),a]})})}function Tv(e,t){const n=new Map(e.tiles.map((r,s)=>[Fe(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(Fe(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return Fe(s)}}function Ov({editor:e,gridBox:t}){const[n,r]=k.useState(void 0),s=typeof n=="object"?n.tile:void 0,i=n==="description",o=k.useCallback(m=>r(b=>typeof b=="object"&&b.tile===m?b:{tile:m}),[]),a=k.useCallback(()=>r(m=>m==="description"?m:void 0),[]),l=k.useCallback(()=>r("description"),[]),d=k.useCallback(()=>r(void 0),[]),[u,c]=k.useState(void 0),f=k.useRef(!1),h=k.useRef(e.document);k.useEffect(()=>{const m=h.current;if(h.current=e.document,!f.current)return;f.current=!1;const b=Tv(m,e.document);if(b===void 0)return;c(b),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===b)?.scrollIntoView?.({block:"nearest",behavior:O.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(u===void 0)return;const m=setTimeout(()=>c(void 0),1500);return()=>clearTimeout(m)},[u]);const p=k.useMemo(()=>({...e,undo:()=>{f.current=!0,e.undo()},redo:()=>{f.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:l,clearSelection:d,flash:u,stepEditor:p}}function Ev({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,l]=k.useState(!1),d=k.useRef(r);d.current=r;const u=k.useRef(s);u.current=s;const c=k.useRef(0),f=k.useCallback(async()=>{const p=++c.current;l(!1),o("saving");try{await d.current()}catch{c.current===p&&o("idle");return}c.current===p&&l(!0)},[]);return k.useEffect(()=>{if(i==="waiting"){if(t)return;e?f():(o("idle"),u.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||u.current()}},[i,a,t,e,f]),{requestExit:k.useCallback(()=>{i==="idle"&&(e?o("asking"):u.current())},[i,e]),dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),u.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):f())}}}}function Cv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,report:o,unit:a,prepare:l,shortcuts:d}){const[u,c]=k.useState(!1),[f,h]=k.useState(!1),p=k.useRef(null),m=k.useRef(o);m.current=o;const b=e.dirty||i,w=(e.edited??e.dirty)||i;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(w)},[w,n]);const v=k.useRef(n);v.current=n,k.useEffect(()=>()=>v.current?.(!1),[]);const g=k.useRef(a);g.current=a,k.useEffect(()=>{h(!1)},[e.document]);const y=k.useCallback(()=>{c(!0),h(!1);const K=O.now(),{structural:Z}=e,J=e.pendingOpen??!1,ie=m.current.size;return e.save().then(de=>{de.ok===!0?m.current.saved({size:ie,structural:Z,fromOpen:J,durationMs:O.now()-K}):m.current.refused(de.reason)}).finally(()=>c(!1))},[e]),_=k.useRef(!1),S=k.useRef(!1);k.useEffect(()=>{!S.current||u||(S.current=!1,p.current?.focus())},[f,u]);const E=k.useCallback(()=>{if(!t||u||_.current||!e.canUndoSave)return;_.current=!0,c(!0);const K=O.now(),Z=e.lastSave?.structural??!1,J=m.current.size;return e.undoSave().then(ie=>{ie.ok===!0?(S.current=!0,h(!0),m.current.undone({size:J,structural:Z,fromOpen:!1,durationMs:O.now()-K})):m.current.undoRefused(ie.reason)}).finally(()=>{_.current=!1,c(!1)})},[t,u,e]),A=k.useCallback(()=>{if(!(!t||!e.dirty||u))return y()},[t,e,u,y]),T=k.useRef(A);T.current=A;const D=k.useCallback(()=>{const K=()=>T.current();return l?l(K):K()},[l]),q=Ev({dirty:w,saving:u,canSave:!!t,save:D,onExit:()=>r?.()});wv(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:D}:{},paused:q.dialog.open}),[d,e,t,D,q.dialog.open]));const P=!!t&&!u&&e.canUndoSave,z=e.lastSave,U={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:b,saving:u,saveButton:p,...t?{onSave:D}:{},...r?{onExit:q.requestExit}:{}};return{saving:u,save:D,exitGuard:q,undoSave:E,canUndoSave:P,lastSave:z,toolbarProps:U}}function rs(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function Ml(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&Cd.includes(n))return n}}const Iv=1;function Hd(e,t,n){const r=[];for(const s of e??[]){const i=s.name,o=s.kind;if(typeof i=="string"){if(o==="dimension"||o==="measure"){const a=s.type?.kind;r.push({name:t+i,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=s.schema?.fields;r.push(...Hd(a,`${t}${i}.`,n-1))}}}return r}function Dv(e){const t=new Map;for(const n of Xd(e))t.set(n.name,Hd(n.schema?.fields,"",Iv));return t}function Xd(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 Av=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&rf.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Mv(e){const t=new Map;for(const n of Xd(e)){const r=new Set;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const i=s.schema?.fields;i&&i.length>0&&i.every(Av)&&r.add(s.name)}t.set(n.name,r)}return t}function Pl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const Rl=(e,t)=>e!==void 0&&t.has(e),jl=e=>e.modelPath??e.path??"";function Yd(e,t=new Set){const n=[],r=new Set,s=new Map,i=new Map,o=new Map;for(const a of e){const l=jl(a);if(Rl(l,t))continue;const d=O.exportedSources(a.modelInfo);i.set(a,d);for(const{name:u}of a.sources??[])u&&o.set(u,[...o.get(u)??[],l]);for(const u of d)s.set(u,[...s.get(u)??[],l])}for(const a of e){const l=jl(a);if(Rl(l,t))continue;const d=Dv(a),u=Mv(a);for(const c of a.sources??[]){const f=c.name;if(!f||!i.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(c.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");n.push({name:f,modelPath:l,exporters:s.get(f)??[l],visibleIn:o.get(f)??[l],...rs(c.annotations)?{description:rs(c.annotations)}:{},views:(c.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...rs(p.annotations)?{description:rs(p.annotations)}:{},...Ml(p.annotations)?{chart:Ml(p.annotations)}:{},...u.get(f)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:h,fields:d.get(f)??[]})}}return{sources:n}}function Pv({editor:e,opened:t,givens:n,catalog:r}){const[s,i]=k.useState(void 0),o=k.useMemo(()=>{const p=new Set((t.localGivens??[]).map(m=>m.name));return(n??[]).filter(m=>!p.has(m.name))},[t,n]),a=k.useMemo(()=>uf(e.document,o),[e.document,o]),l=k.useMemo(()=>new Map(e.document.sources.map(p=>[p.name,Pl(r,p.base)])),[r,e.document.sources]),d=k.useCallback(p=>l.get(p.source)??Pl(r,p.source),[l,r]),u=(p,m)=>{const b=[];for(const w of e.document.tiles){if(!xe(w))continue;const v=d(w);if(!v)continue;const g=new Map(v.map(y=>[y.name,y.type]));for(const y of w.filters??[])y.given===p&&(!g.has(y.field)||!as(m,g.get(y.field)))&&b.push(`${y.field} on ${w.label??w.name} (${e.document.sources.find(_=>_.name===w.source)?.base??w.source})`)}return b},c=k.useMemo(()=>a.filter(p=>p.origin==="model"&&p.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:d,unknownFieldsOf:u,available:c,applyFilter:(p,m,b)=>{i(void 0),e.update(w=>{b&&vf(w,b),mf(w,p,m)})},dropControl:p=>{i(void 0),e.update(m=>yf(m,p))}}}function Rv({pendingOpen:e,prepare:t}){const[n,r]=k.useState(void 0),s=k.useRef(e);s.current=e;const i=k.useCallback(o=>s.current?new Promise(a=>r({go:()=>{r(void 0),a(t(o))},stop:()=>{r(void 0),a()}})):t(o),[t]);return{confirmConversion:n,prepareSave:i}}function jv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s,opensDirty:i=!1}=e,[o,a]=k.useState({stack:[e.document],index:0}),[l,d]=k.useState(e.source),[u,c]=k.useState(void 0),[f,h]=k.useState(e.document),[p,m]=k.useState(i),[b,w]=k.useState(e.replaces),[v,g]=k.useState(!1),y=o.stack[o.index],_=k.useRef(o);_.current=o;const S=k.useRef(!1),[E,A]=k.useState(!1),T=R=>{S.current=R,A(R)},[D,q]=k.useState(void 0),P=k.useCallback(R=>{c(void 0),a(G=>{const ne=structuredClone(G.stack[G.index]);if(R(ne),JSON.stringify(ne)===JSON.stringify(G.stack[G.index]))return G;const H=[...G.stack.slice(0,G.index+1),ne].slice(-100);return{stack:H,index:H.length-1}})},[]),z=k.useCallback(()=>{c(void 0),a(R=>R.index>0?{...R,index:R.index-1}:R)},[]),U=k.useCallback(()=>{c(void 0),a(R=>R.index<R.stack.length-1?{...R,index:R.index+1}:R)},[]),K=k.useCallback(async(R,G)=>{try{return await t(R,G)}catch(ne){return{ok:!1,reason:`Could not build the file: ${ne instanceof Error?ne.message:String(ne)}`}}},[t]),Z=k.useCallback(async()=>{if(S.current)return{ok:!1,reason:"A save is still being written."};const R={source:l,saved:f,history:_.current,pendingOpen:p,replacing:b,unwritten:v},G=s?.(f,y)??!1,ne=r?.(f,y)??!1;T(!0);try{const Y=await K(l,y);if(zs(Y))return c(Y.reason),{ok:!1,reason:Y.reason};try{await n?.(Y.source,{purpose:"save",document:y})}catch(L){const C=`Could not save: ${L instanceof Error?L.message:String(L)}`;return c(C),{ok:!1,reason:C}}d(Y.source),h(y),m(!1),w(void 0),g(!1);const H=G?{stack:[y],index:0}:R.history;return a(L=>L===R.history?H:G?{stack:[L.stack[L.index]],index:0}:L),q(n?{before:R,after:H,lastSave:{before:b??l,after:Y.source,structural:ne,clearsHistory:G}}:void 0),c(void 0),{ok:!0}}finally{T(!1)}},[y,K,n,l,f,p,b,v,s,r]),J=k.useCallback(async()=>{if(S.current)return{ok:!1,reason:"A save is still being written."};if(!n||D===void 0||D.after!==_.current)return{ok:!1,reason:"There is no save to undo."};const{before:R}=D;T(!0);try{await n(R.replacing??R.source,{purpose:"undo",document:R.saved})}catch(G){const ne=`Could not undo the save: ${G instanceof Error?G.message:String(G)}`;return c(ne),{ok:!1,reason:ne}}finally{T(!1)}return d(R.source),h(R.saved),m(R.pendingOpen),w(R.replacing),g(R.unwritten||R.replacing!==void 0),a(G=>G===D.after?R.history:G),q(void 0),c(void 0),{ok:!0}},[n,D]),ie=k.useMemo(()=>v||JSON.stringify(y)!==JSON.stringify(f),[y,f,v]),de=k.useMemo(()=>r?.(f,y)??!1,[y,f,r]),I=k.useMemo(()=>s?.(f,y)??!1,[y,f,s]),V=D!==void 0&&D.after===o,B=k.useCallback(async()=>{const R=await K(l,y);return zs(R)?{ok:!1,reason:R.reason}:{ok:!0,source:R.source}},[y,K,l]);return{document:y,saved:f,source:l,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:ie||p,edited:ie,pendingOpen:p,...u===void 0?{}:{error:u},update:P,undo:z,redo:U,save:Z,preview:B,structural:de,clearsHistory:I,canUndoSave:V&&!E&&n!==void 0,...V?{lastSave:D.lastSave}:{},undoSave:J}}const Lv=(e,t)=>{const n=new Set(e.tiles.map(xo)),r=new Set(t.tiles.map(xo));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Nv(e){const{conversion:t,visibleSources:n,...r}=e,s=t?.from,i=t?.to,o=k.useCallback((a,l)=>Kd(s!==void 0&&a===s?i:a,l,n?{visibleSources:n}:{}),[s,i,n]);return jv({...r,splice:o,structural:Lv,opensDirty:t!==void 0})}function Fv({editorDirty:e}){const[t,n]=k.useState(!1),r=k.useRef(void 0),s=k.useRef(void 0),i=k.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=k.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return k.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:i,prepare:o}}function zv(e,t,{modelPath:n,textHeld:r,notebook:s,insertAt:i}){t.modelPath&&!r&&(e.imports=O.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));let o=e.sources.find(d=>d.base===t.base);if(!o){const d=new Set(e.sources.map(c=>c.name));let u=`${t.base}_tiles`;for(let c=2;d.has(u);c++)u=`${t.base}_tiles_${c}`;o={name:u,base:t.base},e.sources.push(o)}const a=new Set(e.tiles.filter(xe).filter(d=>d.source===o.name).map(d=>d.name));let l=`${t.view}_tile`;for(let d=2;a.has(l);d++)l=`${t.view}_tile_${d}`;e.tiles.splice(i??e.tiles.length,0,{name:l,source:o.name,declaration:{kind:"reference",from:t.view},...s?{}:{colspan:t.colspan},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Wv({editor:e,notebook:t,columns:n,modelPath:r,textHeld:s,selectTile:i,deselectTile:o}){const[a,l]=k.useState(void 0),[d,u]=k.useState(!1),[c,f]=k.useState(void 0);return{menu:a,setMenu:l,addingTile:d,openAdd:g=>{f(g),u(!0)},closeAdd:()=>u(!1),addTile:g=>{u(!1),e.update(y=>zv(y,g,{modelPath:r,textHeld:s,notebook:t,insertAt:c})),i(c??e.document.tiles.length)},addText:()=>{u(!1),e.update(g=>{const y=new Set(g.tiles.filter(Re).map(S=>S.name));let _=1;for(;y.has(`text_${_}`);)_++;g.tiles.splice(c??g.tiles.length,0,{kind:"text",name:`text_${_}`,markdown:"",...t?{}:{colspan:n}})}),i(c??e.document.tiles.length)},editTile:(g,y)=>e.update(_=>{const S=_.tiles.find(E=>Fe(E)===g);S&&y(S)}),removeTile:g=>{l(void 0),o(),e.update(y=>{y.tiles.splice(g,1)})}}}var Bv=Object.defineProperty,Gv=Object.defineProperties,qv=Object.getOwnPropertyDescriptors,Ll=Object.getOwnPropertySymbols,Kv=Object.prototype.hasOwnProperty,Vv=Object.prototype.propertyIsEnumerable,Nl=(e,t,n)=>t in e?Bv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,an=(e,t)=>{for(var n in t||(t={}))Kv.call(t,n)&&Nl(e,n,t[n]);if(Ll)for(var n of Ll(t))Vv.call(t,n)&&Nl(e,n,t[n]);return e},ln=(e,t)=>Gv(e,qv(t));function Uv(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ss(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Oi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Hv(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,y)=>g===y||g!==null&&typeof g=="object"&&"id"in g&&g.id===y;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),y=e.findIndex(_=>l(_,o.id));if(g===-1||y===-1){if(Oi(i)){const _=i.initialIndex,S=i.index;return _===S||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,S)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,y)}const d=Object.entries(e);let u=-1,c,f=-1,h;for(const[g,y]of d)if(u===-1&&(u=y.findIndex(_=>l(_,i.id)),u!==-1&&(c=g)),f===-1&&(f=y.findIndex(_=>l(_,o.id)),f!==-1&&(h=g)),u!==-1&&f!==-1)break;if(u===-1&&Oi(i)){const g=i.initialGroup==null?void 0:ss(e,i.initialGroup),y=i.initialIndex,_=i.group==null?void 0:ss(e,i.group),S=i.index;if(g==null||_==null||g===_&&y===S)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return ln(an({},e),{[g]:n(e[g],y,S)});const E=e[g][y];return ln(an({},e),{[g]:[...e[g].slice(0,y),...e[g].slice(y+1)],[_]:[...e[_].slice(0,S),E,...e[_].slice(S)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,m=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const g=ss(e,o.id);if(g!=null){const y=o.shape&&m.y>o.shape.center.y?e[g].length:0;h=g,f=y}}if(c==null||h==null||c===h&&u===f){if(c!=null&&c===h&&u===f&&Oi(i)){const g=i.group==null?void 0:ss(e,i.group),y=i.group!=null&&g!==c,_=i.index!==u;if(y||_){const S=i.group==null?c:g;if(S!=null){if(c===S)return ln(an({},e),{[c]:n(e[c],u,i.index)});const E=e[c][u];return ln(an({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[S]:[...e[S].slice(0,i.index),E,...e[S].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===h)return ln(an({},e),{[c]:n(e[c],u,f)});const w=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[c][u];return ln(an({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[h]:[...e[h].slice(0,f+w),v,...e[h].slice(f+w)]})}function Xv(e,t){return Hv(e,t,Uv)}function Yv({tiles:e,commit:t,onLanded:n}){const[r,s]=k.useState(void 0),i=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),i.current=e},onDragOver:c=>{const{source:f,target:h}=c.operation;if(!f||!h)return;const p=i.current??e;let m;if(h.type===Od){const{after:b}=h.data,w=p.findIndex(y=>Fe(y)===f.id);if(w<0||b===f.id)return;const g=p.filter((y,_)=>_!==w).findIndex(y=>Fe(y)===b)+1;m=Tg(p,w,g)}else{const b=p.map(Fe),w=Xv(b,c);if(w.every((g,y)=>g===b[y]))return;const v=new Map(p.map(g=>[Fe(g),g]));m=$g(w.map(g=>v.get(g)),e.map(g=>g.break??!1))}i.current=m,s(m)},onDragEnd:c=>{a(!1);const f=i.current;if(i.current=void 0,s(void 0),c.canceled||!f)return;t(f);const h=f.findIndex(p=>Fe(p)===c.operation.source?.id);h>=0&&n(h)}}}const Ei=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Zv({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),l=f=>{a.current=f,o(f)};return k.useEffect(()=>()=>Ei(!1),[]),{resize:i,startResize:(f,h)=>{const p=n.current?.getBoundingClientRect(),m=f.currentTarget.parentElement?.getBoundingClientRect();if(!p||!m)return;f.stopPropagation(),f.preventDefault(),f.currentTarget.setPointerCapture(f.pointerId),Ei(!0),r(h);const b=e[h]?.colspan??1;l({index:h,span:b,from:b,left:m.left,track:(p.width-O.GRID_GAP_PX*(t-1))/t})},onResize:f=>{const h=a.current;if(!h)return;const p=f.clientX-h.left,m=Math.round((p+O.GRID_GAP_PX)/(h.track+O.GRID_GAP_PX)),b=Math.min(Math.max(m,1),t);b!==h.span&&l({...h,span:b})},endResize:f=>{f.currentTarget.hasPointerCapture(f.pointerId)&&f.currentTarget.releasePointerCapture(f.pointerId),Ei(!1);const h=a.current;if(!h)return;const{index:p,span:m,from:b}=h;l(void 0),!(f.type==="pointercancel"||m===b)&&s(p,m)}}}function Oa({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,allowLayoutChange:o=!0,renderTile:a,controls:l,givens:d,catalog:u,toolbar:c,dashboards:f,onEvent:h,conversion:p,savesTo:m="package",saveLabel:b,replaces:w,modelPath:v,visibleSources:g,addFilterDisabledReason:y}){const _=Nv({source:e,document:t,...n?{onSave:n}:{},...p?{conversion:p}:{},...w!==void 0?{replaces:w}:{},...g?{visibleSources:g}:{}}),S=k.useRef(null),{selected:E,descriptionSelected:A,selectTile:T,deselectTile:D,selectDescription:q,clearSelection:P,flash:z,stepEditor:U}=Ov({editor:_,gridBox:S}),K=_.document.layout==="linear",Z=K?1:_.document.columns??O.DEFAULT_COLUMNS,J=K?"none":"card",ie=v?.split("/").at(-1)?.replace(/\.malloy$/,""),de=Yv({tiles:_.document.tiles,commit:te=>_.update(j=>{j.tiles=te}),onLanded:T}),{dragging:I}=de,V=Zv({tiles:_.document.tiles,columns:Z,gridBox:S,onStart:T,commit:(te,j)=>_.update(F=>{const re=F.tiles[te];re&&(re.colspan=j)})}),B=Wv({editor:_,notebook:K,columns:Z,modelPath:v,textHeld:g!==void 0,selectTile:T,deselectTile:D}),{menu:R,addingTile:G,openAdd:ne}=B,Y=Pv({editor:_,opened:t,givens:d,catalog:u}),{filterDialog:H,setFilterDialog:L}=Y,[C,W]=k.useState(void 0),{draftDirty:M,openDraft:ee,prepare:X}=Fv({editorDirty:_.dirty}),{confirmConversion:le,prepareSave:ce}=Rv({pendingOpen:_.pendingOpen,prepare:X}),N=k.useMemo(()=>({escape:()=>{!R&&!H&&!G&&C===void 0&&le===void 0&&P()},nudge:te=>{if(I||E===void 0||K)return;const j=_.document.tiles[E];if(!j||xe(j)&&j.declaration.kind==="inherited")return;const F=O.nudgedSpan(j.colspan??1,te,Z);F!==(j.colspan??1)&&_.update(re=>{re.tiles[E].colspan=F})}}),[_,R,H,G,C,le,P,E,Z,K,I]),Q=Cv({editor:U,extraDirty:M,prepare:ce,unit:{name:"tile",count:te=>te.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:N,report:yv({size:_.document.tiles.length,path:v??"",layout:_.document.layout,savesTo:m,onEvent:h})}),me=_.document.tiles.length===0,se=x.jsx(_v,{...Q.toolbarProps,...c?{actions:c}:{},...u?{onAddTile:()=>ne()}:{},savesTo:m,...b?{saveLabel:b}:{},...g===void 0&&o?{layout:_.document.layout,onLayoutChange:te=>{const j=_.document.layout;te!==j&&(_.update(F=>{F.layout=te}),O.reportEmitter({path:v??"",layout:te},h).emit({type:"report.layout_changed",from:j,to:te}))}}:{}});return x.jsx(hd.Provider,{value:ee,children:x.jsx($.Stack,{sx:{gap:0,mx:`-${Si}px`},children:x.jsxs($.Stack,{sx:{gap:2,px:`${Si}px`,pb:`${Si}px`},children:[_.pendingOpen&&x.jsx($.Alert,{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."}),x.jsx(vv,{editor:_,notebook:K,documentSlug:ie,chrome:J,actions:se,descriptionSelected:A,selectDescription:q}),me?x.jsx(x.Fragment,{children:x.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[x.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),u&&x.jsx($.Button,{size:"small",startIcon:x.jsx(O.AddIcon,{}),onClick:()=>ne(),children:"Add tile"})]})}):x.jsx($v,{controls:Y.controlList,tileCount:_.document.tiles.length,unknownFieldsOf:Y.unknownFieldsOf,onEdit:te=>L({control:te}),onAdd:()=>L({}),...y?{addDisabledReason:y}:{},onRemove:Y.dropControl,children:l}),_.error&&x.jsx($.Alert,{severity:"warning",children:_.error}),x.jsx(pv,{editor:_,reorder:de,resizing:V,gridBox:S,columns:Z,notebook:K,chrome:J,canAdd:!!u,selected:E,flash:z,menuIndex:R?.index,onSelect:T,onOpenMenu:(te,j)=>{T(j),B.setMenu({anchor:te,index:j})},openAdd:ne,editTile:B.editTile,...a?{renderTile:a}:{}}),x.jsx($f,{editor:_,catalog:u,columns:Z,dashboards:f,bindings:Y,tiles:B,drillSource:C,setDrillSource:W,confirmConversion:le,exitDialog:Q.exitGuard.dialog})]})})})}function Qv(e,t){const n=new Set;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.add(o.given);const r=[],s=new Set;for(const i of e.localGivens??[])n.has(i.name)&&(s.add(i.name),r.push(Jv(i)));for(const i of t)i.name===void 0||s.has(i.name)||!n.has(i.name)||(s.add(i.name),r.push(i));return r}function Jv(e){const t=ey(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 ey(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 ty(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function is(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function ny(e,t,n,r=new Map,s){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:s&&[...s]};const i=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(m=>[m.name,m.type])),l=e.sources.find(m=>m.name===i)?.scopedBy??[],d=new Set([...l,...s??[]].filter(m=>n.has(m))),u=new Set([...l,...s??[]]),c=[];for(const m of t.filters??[]){const b=`where: ${ge.malloyPath(m.field)} ${m.op??"~"}`;if(n.has(m.given)){d.add(m.given),u.add(m.given),c.push(`${b} $${m.given}`);continue}if(!a.has(m.given))continue;u.add(m.given);const w=O.malloyLiteral(r.get(m.given),a.get(m.given));w!==void 0&&c.push(`${b} ${w}`)}const f=c.join(", "),h=t.chart,p=h==="none"||ni(h)?wn(h,t.chartCarried):h==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
- `):h==="default"&&ty(t.declaration)?wn("none"):void 0;return{...p?{annotation:p}:{},expression:`${i} -> ${o}`+(f?` + { ${f} }`:""),givenNames:Array.from(d),reads:s||u.size>0?Array.from(u):void 0}}function ry({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:i}){const{apiClients:o,server:a}=Be.useServer(),{data:l}=O.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(p=>p.path&&!p.error?[p.path]:[])}),d=k.useMemo(()=>new Set([r,...s.flatMap(p=>p.path?[p.path]:[])]),[s,r]),u=k.useMemo(()=>i?(l??[]).filter(p=>!d.has(p)):[],[l,d,i]),c=ql.useQueries({queries:u.map(p=>({queryKey:["report-editor-model",e,t,p,n,a],queryFn:async()=>(await o.models.getModel(e,t,p,n)).data,retry:!1}))}),f=l!==void 0&&i&&c.every(p=>p.isSuccess||p.isError),h=c.map(p=>p.dataUpdatedAt).join();return k.useMemo(()=>f?Yd(c.flatMap(p=>p.data?[p.data]:[]),d):void 0,[f,u,h,d])}const sy={};function iy({textSource:e,modelGivens:t,environmentName:n,packageName:r,modelPath:s,versionId:i,opened:o,replaces:a,onSave:l,onDirtyChange:d,onExit:u,allowLayoutChange:c,onEvent:f,savesTo:h,saveLabel:p,note:m}){const{apiClients:b}=Be.useServer(),[w,v]=k.useState(o.document.tiles.length>0);k.useEffect(()=>v(o.document.tiles.length>0),[o.generation,o.document]);const{data:g,isSuccess:y,isError:_}=O.useQueryWithApiError({queryKey:["dashboard-editor-manifest",n,r,s,i],queryFn:async()=>{const N=(await b.reports.getReport(n,r,s,i)).data;return N.notebook?{...N.notebook.startingGivens?{startingGivens:N.notebook.startingGivens}:{},...N.notebook.autorun===void 0?{}:{autorun:N.notebook.autorun}}:N},enabled:w&&!e}),S=e?.modelPath??s,E=O.useCompiledDocument({environmentName:n,packageName:r,modelPath:S,source:o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0}),A=E.data?.document,T=e?E.isSuccess?A?.manifest??sy:void 0:g,D=e?E.isSuccess:y,q=e?E.isError:_,P=e?O.documentPreamble(A?.cells):void 0,z=(E.data?.result.problems??[]).filter(N=>N.severity==="error"),U=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),K=e?.givens,Z=k.useMemo(()=>new Set((T?.tiles??[]).flatMap(N=>N.restricted&&N.query?[is(N.query)]:[])),[T]),{reports:J,settled:ie}=O.useReportListing(n,r,i),de=k.useMemo(()=>J.map(N=>N.path).filter(N=>!!N&&N!==s&&N.endsWith(".malloy")).map(N=>N.replace(/\.malloy$/,"")),[J,s]),I=ry({environmentName:n,packageName:r,...i!==void 0?{versionId:i}:{},modelPath:s,reports:J,reportsSettled:ie}),V=k.useMemo(()=>e?(I?.sources??[]).filter(N=>(N.visibleIn??N.exporters??[N.modelPath]).includes(S)).map(N=>N.name):void 0,[I,e,S]),B=k.useMemo(()=>I&&V?{sources:I.sources.filter(N=>V.includes(N.name))}:I,[I,V]),[R,G]=k.useState(o.document);k.useEffect(()=>G(o.document),[o.document]);const ne=k.useMemo(()=>l&&(async(N,Q)=>{await l(N,Q.document.layout),h==="package"&&v(Q.document.tiles.length>0)}),[l,h]),Y=k.useMemo(()=>(T?.givens??(o.conversion?t??[]:[])).filter(N=>!(e&&N.secure===!0)&&!(N.name!==void 0&&U.has(N.name))),[T,o.conversion,t,U,e]),H=k.useMemo(()=>new Set([...Y.map(N=>N.name).filter(N=>N!==void 0),...Object.keys(K??{})]),[Y,K]),L=k.useMemo(()=>Qv(R,Y),[R,Y]),{declaredTypes:C,applied:W,panel:M}=O.useDocumentControls({specs:L,loaded:D,startingValues:T?.startingGivens,documentKey:`${n}/${r}/${i??""}/${s}/edit`,autorun:T?.autorun!==!1,environmentName:n,packageName:r,modelPath:e?S:T?.path,versionId:i,documentName:s,...P!==void 0?{preamble:P}:{},...K?{hostGivens:K}:{}}),ee=k.useMemo(()=>Object.fromEntries(Object.entries(K??{}).filter(([N])=>!C.has(N))),[K,C]),X=!w||D||q,le=k.useMemo(()=>new Map((T?.tiles??[]).flatMap(N=>N.kind!=="text"&&N.query&&N.givenNames?[[is(N.query),N.givenNames]]:[])),[T]),ce=k.useMemo(()=>function(Q,me,se="card"){if(!X)return x.jsxs(O.TileCard,{chrome:se,children:[x.jsx(O.TileHeading,{title:me?.title??Gs(Q),subtitle:me?me.subtitle:Q.subtitle}),x.jsx(O.Loading,{text:"Running…"})]});const te=ny(R,Q,H,W,le.get(is(`${Q.source} -> ${Q.name}`)));return x.jsx(O.DashboardTile,{environmentName:n,packageName:r,versionId:i,modelPath:S,...P!==void 0?{preamble:P}:{},...Z.has(is(`${Q.source} -> ${Q.name}`))?{restricted:!0}:{},tile:te.expression,...te.annotation?{annotation:te.annotation}:{},label:Gs(Q),chrome:se,subtitle:Q.subtitle,...me?{heading:me}:{},borderless:Q.borderless,givens:W,hostGivens:ee,declaredTypes:C,givenNames:te.givenNames,ignoredFilters:O.tileIgnoredFilterLabels(te.reads,L),height:O.TILE_MAX_HEIGHT})},[R,X,H,le,n,r,i,S,P,Z,W,ee,C,L]);return x.jsxs($.Stack,{sx:{gap:1},children:[e&&z.length>0&&x.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",z.map(N=>N.message).join("; ")]}),e&&E.isError&&x.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",E.error?.message]}),x.jsx(Oa,{...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:ce,givens:L.filter(N=>N.name!==void 0).map(N=>({name:N.name,...N.label?{label:N.label}:{},...N.type?{type:N.type}:{},...N.suggest?.dimension?{field:N.suggest.dimension}:{}})),onChange:G,onDirtyChange:d,...u?{onExit:u}:{},...c!==void 0?{allowLayoutChange:c}:{},...o.conversion?{conversion:o.conversion}:{},...B?{catalog:B}:{},dashboards:de,...f?{onEvent:f}:{},controls:D?x.jsx(O.GivensPanel,{...M,layout:R.layout==="linear"?"panel":"bar"}):void 0,...ne?{onSave:ne}:{},savesTo:h,...p?{saveLabel:p}:{},...a!==void 0?{replaces:a}:{},modelPath:s,...e?{visibleSources:V}:{}}),x.jsx($.Box,{sx:{px:.5},children:x.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:m})})]})}function oy({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[l,d]=k.useState(void 0),[u,c]=k.useState(e===void 0),[f,h]=k.useState(!1),[p,m]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let b=!1;return m(void 0),(async()=>{try{const w=O.chooseWorkspace(await e.listWorkspaces(!1));if(b)return;if(a(w),w!==void 0&&(!n||w.authoritative)){const v=await e.getDocument(O.locatorFor(t,w.name,r,s,i)).catch(g=>{if(!O.isDocumentNotFound(g))throw g});if(b)return;d(v),h(v!==void 0)}}catch(w){if(b)return;m(O.storageErrorMessage(w))}b||c(!0)})(),()=>{b=!0}},[e,t,n,r,s,i]),{workspace:o,draft:l,setDraft:d,draftChecked:u,offered:f,setOffered:h,readFailure:p}}const ay=e=>e.ok===!1,Un=(e,t)=>{const n=e[t];return typeof n=="function"?n.call(e):void 0},ly=[["runStatement","run"],["docAnnotations","notes"],["importStatement","definition"],["defineSourceStatement","definition"],["defineQuery","definition"],["defineGivenStatement","definition"],["defineUserTypeStatement","definition"],["exportStatement","definition"]],cy=/^[A-Za-z_][A-Za-z0-9_]*$/,uy="file:///publisher-notebook-builder/notebook.malloy",os=e=>e.replace(/\r\n?/g,`
141
+ `)}}async function Il(e,t,n){const r=await Cr(e);if(Er(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=ev(s,t),o=Wm(s,i,n.visibleSources);if("reason"in o)return o;const a=rv(s,i);if(a)return{ok:!1,reason:a};const l=await Pd(e);if(Ad(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const d=e.split(`
142
+ `),c=Rm(e),u=v=>({start:c[v],end:v+1<c.length?c[v+1]:e.length}),f=v=>/^\s*/.exec(d[v])?.[0]??"",h=[],p={...o,sourceText:e,parsed:l.parsed,lines:d,starts:c,wholeLine:u,indentOf:f,current:s,next:i,edits:h};for(const v of[Gm,Um,Xm,Hm,Ym,Zm,Qm,Jm,nv]){const g=v(p);if(g)return g}const m=v=>{const{drills:g,localGivens:y,description:_,...S}=v,E=v.tiles.map(D=>{if(je(D))return D;if(D.filters?.length)return Bs(D);const{filters:T,...A}=D;return Bs(A)});return{...S,..._===void 0?{}:{description:Ld(_)},tiles:E,...g?.length?{drills:[...g].sort((D,T)=>Ws(D).localeCompare(Ws(T)))}:{},...y?.length?{localGivens:y}:{}}};if(h.length===0)return _e(m(s))!==_e(m(i))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const b=Lm(e,h);if((await xl(e)).length===0){const v=await xl(b);if(v.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${v[0]}). Your changes are still here.`}}const x=await Cr(b);return Er(x)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${x.reason}`}:_e(m(x.document))!==_e(m(i))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:b}}function Vd({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=Be.usePublisherTheme(),[i,o]=k.useState(!1),a=k.useMemo(()=>i?{text:e}:void 0,[i,e]),{draft:l,patch:d,close:c,discard:u}=Vl(a,i,g=>n(g.text),()=>o(!1)),f=i&&l!==void 0&&l.text!==e,h=l!==void 0&&l.text!==e?xs(l.text):void 0;pd(f,()=>h!==void 0?!1:(c(),!0));const p=k.useRef(null),m=k.useRef(!1);k.useEffect(()=>{i||(m.current=!1)},[i]);const b=k.useCallback(g=>{!g||m.current||(m.current=!0,g.setSelectionRange(g.value.length,g.value.length))},[]);if(!i||l===void 0){const g=e.trim()?xs(e):void 0;return w.jsxs($.Box,{role:"button",tabIndex:0,onClick:y=>{y.target.closest("a")?y.preventDefault():o(!0)},onKeyDown:y=>{y.target===y.currentTarget&&(y.key!=="Enter"&&y.key!==" "||(y.preventDefault(),o(!0)))},sx:[{minHeight:24},fd(s,"prose")],children:[e.trim()?w.jsx(O.Prose,{variant:r,children:e}):w.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),g&&w.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:g})]})}const x=l.text!==e?xs(l.text):void 0,v=()=>{x===void 0&&c()};return w.jsxs($.Stack,{spacing:1,children:[w.jsx($.TextField,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:l.text,placeholder:t,error:x!==void 0,helperText:x,inputRef:b,inputProps:{"aria-label":"Markdown"},onChange:g=>d(y=>{y.text=g.target.value}),onKeyDown:g=>{g.key==="Escape"?v():g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&(g.preventDefault(),v())},onBlur:g=>{g.relatedTarget instanceof Node&&p.current?.contains(g.relatedTarget)||c()}}),w.jsxs($.Stack,{ref:p,direction:"row",spacing:1,children:[w.jsx($.Button,{size:"small",variant:"outlined",disabled:x!==void 0,onClick:v,children:"Done"}),w.jsx($.Button,{size:"small",onMouseDown:g=>g.preventDefault(),onClick:()=>{u(),o(!1)},children:"Cancel"})]})]})}const av="Write markdown: # heading, **bold**, - list";function lv({tile:e,onChange:t,chrome:n="card"}){return w.jsx(O.TileCard,{chrome:n,kind:"text",children:w.jsx(Vd,{markdown:e.markdown,placeholder:av,onCommit:t})})}const Gs=e=>e.label??O.tileTitle(`${e.source} -> ${e.name}`);function cv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:l,resizing:d=!1,width:c,onResizeStart:u,onResizeMove:f,onResizeEnd:h,children:p}){const{theme:m}=Be.usePublisherTheme();return w.jsx(om,{id:Fe(e),index:t,children:({ref:b,handleRef:x})=>w.jsxs($.Box,{ref:b,onClick:a,onPointerDown:v=>{v.button===0&&a()},role:"group","aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Ud(m,{selected:n,flash:r,bare:i}),"&&[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:[p,w.jsx($.Box,{ref:x,"aria-label":`Move ${Kr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),w.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Kr(e)}`,onClick:v=>{v.stopPropagation(),l(v.currentTarget)},sx:{position:"absolute",top:`${-((i?O.BARE_RING_OFFSET_PX+1:0)+12)}px`,right:i?0:"12px",border:m.cardBorder,borderRadius:1,width:28,height:24,zIndex:2,color:m.tileTitle,bgcolor:m.tile,opacity:n||s?.9:0,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,"&:hover":{opacity:1,bgcolor:m.tile}},children:w.jsx(hv,{})}),u&&w.jsx($.Box,{className:"builder-affordance",[Ed]:"",role:"separator",tabIndex:c?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Kr(e)}`,...c?{"aria-valuenow":c.span,"aria-valuemin":1,"aria-valuemax":c.columns,"aria-valuetext":`${c.span} of ${c.columns} columns`}:{},onKeyDown:v=>{if(!c)return;const g=v.key==="ArrowRight"?c.span+1:v.key==="ArrowLeft"?c.span-1:v.key==="Home"?1:v.key==="End"?c.columns:void 0;g!==void 0&&(v.preventDefault(),v.stopPropagation(),c.onStep(Math.min(Math.max(g,1),c.columns)))},onPointerDown:u,onPointerMove:f,onPointerUp:h,onPointerCancel:h,onClick:v=>v.stopPropagation(),sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:d||n?1:0,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,"&: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&&w.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Kr(e)}`,onClick:v=>{v.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${(i?O.NOTEBOOK_GAP_PX:O.GRID_GAP_PX)/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 ${O.MOTION_FAST}`,...O.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:m.tile}},children:w.jsx(O.AddIcon,{sx:{fontSize:14}})})]})})}const Si=4,Ud=(e,{selected:t,flash:n=!1,bare:r=!1})=>{const s=t||n?e.accent:"transparent",i=t?e.accent:e.cardBorder.replace(/^1px solid /,""),o=`outline-color ${O.MOTION_FAST}, border-color ${O.MOTION_FAST}, opacity ${O.MOTION_FAST}, box-shadow ${O.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-O.BARE_RING_OFFSET_PX}px`,borderRadius:1,border:`2px solid ${s}`,pointerEvents:"none",transition:o,...O.reducedMotionSx},"&:hover::before":{borderColor:i}}:{borderRadius:1,outline:`2px solid ${s}`,outlineOffset:2,...n&&{boxShadow:`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`},transition:o,...O.reducedMotionSx,"&:hover":{outlineColor:i,boxShadow:e.shadow.lift}}};function uv({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=Be.usePublisherTheme();return w.jsxs(O.TileCard,{chrome:r,children:[w.jsx(O.TileHeading,{title:t?.title??Gs(e),subtitle:t?t.subtitle:e.subtitle}),n&&w.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),w.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function dv({after:e}){const{theme:t}=Be.usePublisherTheme();return w.jsx(am,{id:md(e),after:e,children:({ref:n,isDropTarget:r})=>w.jsx($.Box,{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 ${O.MOTION_FAST}, background-color ${O.MOTION_FAST}`,...O.reducedMotionSx}})})}function fv({columns:e}){const{theme:t}=Be.usePublisherTheme();return w.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${O.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>w.jsx($.Box,{sx:{borderLeft:`1px dashed ${t.accent}`,borderRight:r===e-1?`1px dashed ${t.accent}`:"none",opacity:.35}},r))})}function hv(){return w.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[w.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),w.jsx("circle",{cx:"12",cy:"12",r:"2"}),w.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function pv({editor:e,reorder:t,resizing:n,gridBox:r,columns:s,notebook:i,chrome:o,canAdd:a,selected:l,flash:d,menuIndex:c,onSelect:u,onOpenMenu:f,openAdd:h,editTile:p,renderTile:m}){const{dragging:b,preview:x,onDragStart:v,onDragOver:g,onDragEnd:y}=t,{resize:_,startResize:S,onResize:E,endResize:D}=n,T=_!==void 0?e.document.tiles.map((z,U)=>U===_.index?{...z,colspan:_.span}:z):x??e.document.tiles,A=e.document.tiles.length===0,q=b||_!==void 0?Og(T,s):T.map(gd),P=z=>gv(z,Gs(z),p);return w.jsxs(w.Fragment,{children:[w.jsx(lg,{sensors:sm,onDragStart:v,onDragOver:g,onDragEnd:y,children:w.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[!i&&(b||_!==void 0)&&w.jsx(fv,{columns:s}),w.jsx(O.DashboardGrid,{tiles:q,columns:s,rowGapPx:o==="none"?O.NOTEBOOK_GAP_PX:O.GRID_GAP_PX,keyOf:z=>z.kind==="gap"?md(z.after):Fe(z.tile),renderTile:z=>{if(z.kind==="gap")return w.jsx(dv,{after:z.after});const{tile:U,index:K}=z;return w.jsx(cv,{tile:U,index:K,selected:K===l,flash:Fe(U)===d,menuOpen:c===K,bare:o==="none",...i&&a&&K<e.document.tiles.length-1?{onInsertAfter:()=>h(K+1)}:{},...s>1&&mv(U)?{resizing:_?.index===K,width:{span:U.colspan??1,columns:s,onStep:Z=>{Z!==(U.colspan??1)&&e.update(J=>{const ie=J.tiles[K];ie&&(ie.colspan=Z)})}},onResizeStart:Z=>S(Z,K),onResizeMove:E,onResizeEnd:D}:{},onSelect:()=>u(K),onOpenMenu:Z=>f(Z,K),children:je(U)?w.jsx(lv,{tile:U,chrome:o,onChange:Z=>p(Fe(U),J=>{je(J)&&(J.markdown=Z)})}):m&&!e.pendingOpen?m(U,P(U),o):w.jsx(uv,{tile:U,chrome:o,heading:P(U),...e.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),i&&a&&!A&&w.jsx($.Button,{size:"small",startIcon:w.jsx(O.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>h(),sx:{alignSelf:"center"},children:"Add tile"})]})}const gv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Fe(e),s=i=>o=>n(r,a=>{xe(a)&&(o===""?delete a[i]:a[i]=o)});return{title:w.jsx(go,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:w.jsx(go,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},mv=e=>je(e)||e.declaration.kind!=="inherited";function vv({editor:e,documentSlug:t,chrome:n,actions:r,descriptionSelected:s,selectDescription:i}){const{theme:o}=Be.usePublisherTheme();return w.jsxs(w.Fragment,{children:[w.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:2},children:[w.jsx($.Typography,{variant:"h5",sx:{flex:1,minWidth:0},children:w.jsx(go,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:a=>e.update(l=>{l.title=a})})}),w.jsx($.Box,{sx:{my:"-4px"},children:r})]}),w.jsx($.Box,{role:"group","aria-label":"Description","aria-current":s,onPointerDown:i,onFocus:i,sx:n==="none"?{my:`${O.BARE_DESCRIPTION_MARGIN_PX}px`}:void 0,children:w.jsx(O.TileCard,{chrome:n,kind:"text",sx:{position:"relative",overflow:"visible",...Ud(o,{selected:s,bare:n==="none"})},children:w.jsx(Vd,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:a=>e.update(l=>{a.trim()===""?delete l.description:l.description=a})})})})]})}const yv=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:i}=O.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:o,structural:a,durationMs:l,fromOpen:d})=>i({type:"report.saved",tiles:o,structural:a,...d?{converted:!0}:{},where:r,durationMs:l}),refused:o=>i({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:l})=>i({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:l}),undoRefused:o=>i({type:"report.save_undo_refused",reason:o})}},bv=O.createSvgIcon(w.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"})),xv=O.createSvgIcon(w.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"})),wo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),$i=wo?"⌘":"Ctrl+",Al=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Ti=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function wv(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const s=i=>{const o=t.current;if(o.paused)return;const a=wo?i.metaKey:i.ctrlKey,l=i.key.toLowerCase();if(i.key==="Escape"){if(Al(i.target)||Ti(i.target))return;o.escape();return}if(Al(i.target)){if(a&&l==="s"){if(i.preventDefault(),!o.save||Ti(i.target))return;i.target.blur(),r(!0)}return}if(Ti(i.target)){a&&l==="s"&&i.preventDefault();return}if(a&&l==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!wo&&a&&l==="y"){i.preventDefault(),o.redo();return}if(a&&l==="s"){i.preventDefault(),o.save?.();return}o.nudge&&!a&&!i.altKey&&!i.shiftKey&&(i.key==="ArrowLeft"||i.key==="ArrowRight")&&(i.preventDefault(),o.nudge(i.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Dl={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function _v({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:l,saveButton:d,actions:c,onAddTile:u,onExit:f,layout:h,onLayoutChange:p}){return w.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[h&&p&&w.jsxs(w.Fragment,{children:[w.jsx($.Tooltip,{title:"Layout: tiles side by side, or one after another",children:w.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:h,"aria-label":"Layout",onChange:(m,b)=>{b&&b!==h&&p(b)},sx:{"& .MuiToggleButton-root":{py:.25,px:1}},children:[w.jsx($.ToggleButton,{value:"linear","aria-label":"Linear layout",children:"Linear"}),w.jsx($.ToggleButton,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),w.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}})]}),u&&w.jsx($.Button,{startIcon:w.jsx(O.AddIcon,{}),onClick:u,"aria-label":"Add tile",children:"Tile"}),u&&w.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),w.jsx($.Tooltip,{title:`Undo (${$i}Z)`,children:w.jsx("span",{children:w.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:w.jsx(xv,{fontSize:"small"})})})}),w.jsx($.Tooltip,{title:`Redo (${$i}⇧Z)`,children:w.jsx("span",{children:w.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:w.jsx(bv,{fontSize:"small"})})})}),(c||o||f)&&w.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),c,o?w.jsx($.Tooltip,{title:s?`Save (${$i}S) · ${l??Dl[a]}`:l??Dl[a],children:w.jsx("span",{children:w.jsx($.Button,{ref:d,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{minWidth:124},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&w.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:i?"Saving":s?"Unsaved changes":"All changes saved"}),f&&w.jsx(O.SecondaryButton,{label:"Close",icon:w.jsx(O.CheckIcon,{}),onClick:f})]})}const kv=O.createSvgIcon(w.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"})),Sv=O.createSvgIcon(w.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function $v({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:s,addDisabledReason:i,onRemove:o,sticky:a=!0,children:l}){const{theme:d}=Be.usePublisherTheme();return w.jsx(w.Fragment,{children:w.jsx(O.StickyControls,{sticky:a,children:w.jsxs($.Stack,{sx:{gap:1},children:[w.jsx($.Stack,{direction:"row",sx:{gap:2,alignItems:"center",minHeight:32},children:w.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",flex:1,minWidth:0},children:[w.jsx(Sv,{sx:{fontSize:18,color:d.tileTitle,opacity:.7}}),w.jsx($.Typography,{variant:"subtitle2",sx:{color:d.tileTitle,mr:.5},children:"Filters"}),e.length===0&&w.jsx($.Typography,{variant:"body2",sx:{color:d.tileTitle,opacity:.8},children:"None yet."}),e.map(c=>{const u=n(c.name,c.type);return w.jsx($.Tooltip,{title:u.length>0?`$${c.name} · cannot filter on: ${u.join(", ")}`:`$${c.name} · ${c.origin==="dashboard"?"declared here":"from the model"} · ${c.boundTiles} of ${t} tiles`,children:w.jsx($.Chip,{size:"small",label:`${c.label??c.name}${c.boundTiles===0?" · unused":""}`,"aria-label":`Edit filter ${c.name}`,color:u.length>0?"warning":"default",variant:c.origin==="dashboard"?"filled":"outlined",onClick:()=>r(c),onDelete:()=>o(c.name),deleteIcon:w.jsx(kv,{"aria-label":`Remove filter ${c.name}`}),sx:{opacity:c.boundTiles===0?.6:1,cursor:"pointer",transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx}})},c.name)}),w.jsx($.Tooltip,{title:i??"",children:w.jsx("span",{children:w.jsx($.Chip,{component:"button",size:"small",variant:"outlined",icon:w.jsx(O.AddIcon,{}),label:"Filter","aria-label":"Add filter","aria-haspopup":"dialog",disabled:i!==void 0,onClick:()=>s(),sx:{cursor:"pointer",color:d.tileTitle,borderStyle:"dashed","& .MuiChip-icon":{color:"inherit",fontSize:16}}})})})]})}),l]})})})}function Tv(e,t){const n=new Map(e.tiles.map((r,s)=>[Fe(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(Fe(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return Fe(s)}}function Ov({editor:e,gridBox:t}){const[n,r]=k.useState(void 0),s=typeof n=="object"?n.tile:void 0,i=n==="description",o=k.useCallback(m=>r(b=>typeof b=="object"&&b.tile===m?b:{tile:m}),[]),a=k.useCallback(()=>r(m=>m==="description"?m:void 0),[]),l=k.useCallback(()=>r("description"),[]),d=k.useCallback(()=>r(void 0),[]),[c,u]=k.useState(void 0),f=k.useRef(!1),h=k.useRef(e.document);k.useEffect(()=>{const m=h.current;if(h.current=e.document,!f.current)return;f.current=!1;const b=Tv(m,e.document);if(b===void 0)return;u(b),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===b)?.scrollIntoView?.({block:"nearest",behavior:O.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(c===void 0)return;const m=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(m)},[c]);const p=k.useMemo(()=>({...e,undo:()=>{f.current=!0,e.undo()},redo:()=>{f.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:l,clearSelection:d,flash:c,stepEditor:p}}function Ev({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,l]=k.useState(!1),d=k.useRef(r);d.current=r;const c=k.useRef(s);c.current=s;const u=k.useRef(0),f=k.useCallback(async()=>{const p=++u.current;l(!1),o("saving");try{await d.current()}catch{u.current===p&&o("idle");return}u.current===p&&l(!0)},[]);return k.useEffect(()=>{if(i==="waiting"){if(t)return;e?f():(o("idle"),c.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||c.current()}},[i,a,t,e,f]),{requestExit:k.useCallback(()=>{i==="idle"&&(e?o("asking"):c.current())},[i,e]),dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),c.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):f())}}}}function Cv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,report:o,unit:a,prepare:l,shortcuts:d}){const[c,u]=k.useState(!1),[f,h]=k.useState(!1),p=k.useRef(null),m=k.useRef(o);m.current=o;const b=e.dirty||i,x=(e.edited??e.dirty)||i;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(x)},[x,n]);const v=k.useRef(n);v.current=n,k.useEffect(()=>()=>v.current?.(!1),[]);const g=k.useRef(a);g.current=a,k.useEffect(()=>{h(!1)},[e.document]);const y=k.useCallback(()=>{u(!0),h(!1);const K=O.now(),{structural:Z}=e,J=e.pendingOpen??!1,ie=m.current.size;return e.save().then(de=>{de.ok===!0?m.current.saved({size:ie,structural:Z,fromOpen:J,durationMs:O.now()-K}):m.current.refused(de.reason)}).finally(()=>u(!1))},[e]),_=k.useRef(!1),S=k.useRef(!1);k.useEffect(()=>{!S.current||c||(S.current=!1,p.current?.focus())},[f,c]);const E=k.useCallback(()=>{if(!t||c||_.current||!e.canUndoSave)return;_.current=!0,u(!0);const K=O.now(),Z=e.lastSave?.structural??!1,J=m.current.size;return e.undoSave().then(ie=>{ie.ok===!0?(S.current=!0,h(!0),m.current.undone({size:J,structural:Z,fromOpen:!1,durationMs:O.now()-K})):m.current.undoRefused(ie.reason)}).finally(()=>{_.current=!1,u(!1)})},[t,c,e]),D=k.useCallback(()=>{if(!(!t||!e.dirty||c))return y()},[t,e,c,y]),T=k.useRef(D);T.current=D;const A=k.useCallback(()=>{const K=()=>T.current();return l?l(K):K()},[l]),q=Ev({dirty:x,saving:c,canSave:!!t,save:A,onExit:()=>r?.()});wv(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:A}:{},paused:q.dialog.open}),[d,e,t,A,q.dialog.open]));const P=!!t&&!c&&e.canUndoSave,z=e.lastSave,U={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:b,saving:c,saveButton:p,...t?{onSave:A}:{},...r?{onExit:q.requestExit}:{}};return{saving:c,save:A,exitGuard:q,undoSave:E,canUndoSave:P,lastSave:z,toolbarProps:U}}function rs(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function Ml(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&Cd.includes(n))return n}}const Iv=1;function Hd(e,t,n){const r=[];for(const s of e??[]){const i=s.name,o=s.kind;if(typeof i=="string"){if(o==="dimension"||o==="measure"){const a=s.type?.kind;r.push({name:t+i,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=s.schema?.fields;r.push(...Hd(a,`${t}${i}.`,n-1))}}}return r}function Av(e){const t=new Map;for(const n of Xd(e))t.set(n.name,Hd(n.schema?.fields,"",Iv));return t}function Xd(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 Dv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&rf.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Mv(e){const t=new Map;for(const n of Xd(e)){const r=new Set;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const i=s.schema?.fields;i&&i.length>0&&i.every(Dv)&&r.add(s.name)}t.set(n.name,r)}return t}function Pl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const jl=(e,t)=>e!==void 0&&t.has(e),Rl=e=>e.modelPath??e.path??"";function Yd(e,t=new Set){const n=[],r=new Set,s=new Map,i=new Map,o=new Map;for(const a of e){const l=Rl(a);if(jl(l,t))continue;const d=O.exportedSources(a.modelInfo);i.set(a,d);for(const{name:c}of a.sources??[])c&&o.set(c,[...o.get(c)??[],l]);for(const c of d)s.set(c,[...s.get(c)??[],l])}for(const a of e){const l=Rl(a);if(jl(l,t))continue;const d=Av(a),c=Mv(a);for(const u of a.sources??[]){const f=u.name;if(!f||!i.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(u.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");n.push({name:f,modelPath:l,exporters:s.get(f)??[l],visibleIn:o.get(f)??[l],...rs(u.annotations)?{description:rs(u.annotations)}:{},views:(u.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...rs(p.annotations)?{description:rs(p.annotations)}:{},...Ml(p.annotations)?{chart:Ml(p.annotations)}:{},...c.get(f)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:h,fields:d.get(f)??[]})}}return{sources:n}}function Pv({editor:e,opened:t,givens:n,catalog:r}){const[s,i]=k.useState(void 0),o=k.useMemo(()=>{const p=new Set((t.localGivens??[]).map(m=>m.name));return(n??[]).filter(m=>!p.has(m.name))},[t,n]),a=k.useMemo(()=>uf(e.document,o),[e.document,o]),l=k.useMemo(()=>new Map(e.document.sources.map(p=>[p.name,Pl(r,p.base)])),[r,e.document.sources]),d=k.useCallback(p=>l.get(p.source)??Pl(r,p.source),[l,r]),c=(p,m)=>{const b=[];for(const x of e.document.tiles){if(!xe(x))continue;const v=d(x);if(!v)continue;const g=new Map(v.map(y=>[y.name,y.type]));for(const y of x.filters??[])y.given===p&&(!g.has(y.field)||!as(m,g.get(y.field)))&&b.push(`${y.field} on ${x.label??x.name} (${e.document.sources.find(_=>_.name===x.source)?.base??x.source})`)}return b},u=k.useMemo(()=>a.filter(p=>p.origin==="model"&&p.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:d,unknownFieldsOf:c,available:u,applyFilter:(p,m,b)=>{i(void 0),e.update(x=>{b&&vf(x,b),mf(x,p,m)})},dropControl:p=>{i(void 0),e.update(m=>yf(m,p))}}}function jv({pendingOpen:e,prepare:t}){const[n,r]=k.useState(void 0),s=k.useRef(e);s.current=e;const i=k.useCallback(o=>s.current?new Promise(a=>r({go:()=>{r(void 0),a(t(o))},stop:()=>{r(void 0),a()}})):t(o),[t]);return{confirmConversion:n,prepareSave:i}}function Rv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s,opensDirty:i=!1}=e,[o,a]=k.useState({stack:[e.document],index:0}),[l,d]=k.useState(e.source),[c,u]=k.useState(void 0),[f,h]=k.useState(e.document),[p,m]=k.useState(i),[b,x]=k.useState(e.replaces),[v,g]=k.useState(!1),y=o.stack[o.index],_=k.useRef(o);_.current=o;const S=k.useRef(!1),[E,D]=k.useState(!1),T=j=>{S.current=j,D(j)},[A,q]=k.useState(void 0),P=k.useCallback(j=>{u(void 0),a(G=>{const ne=structuredClone(G.stack[G.index]);if(j(ne),JSON.stringify(ne)===JSON.stringify(G.stack[G.index]))return G;const H=[...G.stack.slice(0,G.index+1),ne].slice(-100);return{stack:H,index:H.length-1}})},[]),z=k.useCallback(()=>{u(void 0),a(j=>j.index>0?{...j,index:j.index-1}:j)},[]),U=k.useCallback(()=>{u(void 0),a(j=>j.index<j.stack.length-1?{...j,index:j.index+1}:j)},[]),K=k.useCallback(async(j,G)=>{try{return await t(j,G)}catch(ne){return{ok:!1,reason:`Could not build the file: ${ne instanceof Error?ne.message:String(ne)}`}}},[t]),Z=k.useCallback(async()=>{if(S.current)return{ok:!1,reason:"A save is still being written."};const j={source:l,saved:f,history:_.current,pendingOpen:p,replacing:b,unwritten:v},G=s?.(f,y)??!1,ne=r?.(f,y)??!1;T(!0);try{const Y=await K(l,y);if(zs(Y))return u(Y.reason),{ok:!1,reason:Y.reason};try{await n?.(Y.source,{purpose:"save",document:y})}catch(L){const C=`Could not save: ${L instanceof Error?L.message:String(L)}`;return u(C),{ok:!1,reason:C}}d(Y.source),h(y),m(!1),x(void 0),g(!1);const H=G?{stack:[y],index:0}:j.history;return a(L=>L===j.history?H:G?{stack:[L.stack[L.index]],index:0}:L),q(n?{before:j,after:H,lastSave:{before:b??l,after:Y.source,structural:ne,clearsHistory:G}}:void 0),u(void 0),{ok:!0}}finally{T(!1)}},[y,K,n,l,f,p,b,v,s,r]),J=k.useCallback(async()=>{if(S.current)return{ok:!1,reason:"A save is still being written."};if(!n||A===void 0||A.after!==_.current)return{ok:!1,reason:"There is no save to undo."};const{before:j}=A;T(!0);try{await n(j.replacing??j.source,{purpose:"undo",document:j.saved})}catch(G){const ne=`Could not undo the save: ${G instanceof Error?G.message:String(G)}`;return u(ne),{ok:!1,reason:ne}}finally{T(!1)}return d(j.source),h(j.saved),m(j.pendingOpen),x(j.replacing),g(j.unwritten||j.replacing!==void 0),a(G=>G===A.after?j.history:G),q(void 0),u(void 0),{ok:!0}},[n,A]),ie=k.useMemo(()=>v||JSON.stringify(y)!==JSON.stringify(f),[y,f,v]),de=k.useMemo(()=>r?.(f,y)??!1,[y,f,r]),I=k.useMemo(()=>s?.(f,y)??!1,[y,f,s]),V=A!==void 0&&A.after===o,B=k.useCallback(async()=>{const j=await K(l,y);return zs(j)?{ok:!1,reason:j.reason}:{ok:!0,source:j.source}},[y,K,l]);return{document:y,saved:f,source:l,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:ie||p,edited:ie,pendingOpen:p,...c===void 0?{}:{error:c},update:P,undo:z,redo:U,save:Z,preview:B,structural:de,clearsHistory:I,canUndoSave:V&&!E&&n!==void 0,...V?{lastSave:A.lastSave}:{},undoSave:J}}const Lv=(e,t)=>{const n=new Set(e.tiles.map(xo)),r=new Set(t.tiles.map(xo));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Nv(e){const{conversion:t,visibleSources:n,...r}=e,s=t?.from,i=t?.to,o=k.useCallback((a,l)=>Kd(s!==void 0&&a===s?i:a,l,n?{visibleSources:n}:{}),[s,i,n]);return Rv({...r,splice:o,structural:Lv,opensDirty:t!==void 0})}function Fv({editorDirty:e}){const[t,n]=k.useState(!1),r=k.useRef(void 0),s=k.useRef(void 0),i=k.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=k.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return k.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:i,prepare:o}}function zv(e,t,{modelPath:n,textHeld:r,notebook:s,insertAt:i}){t.modelPath&&!r&&(e.imports=O.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));let o=e.sources.find(d=>d.base===t.base);if(!o){const d=new Set(e.sources.map(u=>u.name));let c=`${t.base}_tiles`;for(let u=2;d.has(c);u++)c=`${t.base}_tiles_${u}`;o={name:c,base:t.base},e.sources.push(o)}const a=new Set(e.tiles.filter(xe).filter(d=>d.source===o.name).map(d=>d.name));let l=`${t.view}_tile`;for(let d=2;a.has(l);d++)l=`${t.view}_tile_${d}`;e.tiles.splice(i??e.tiles.length,0,{name:l,source:o.name,declaration:{kind:"reference",from:t.view},...s?{}:{colspan:t.colspan},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Wv({editor:e,notebook:t,columns:n,modelPath:r,textHeld:s,selectTile:i,deselectTile:o}){const[a,l]=k.useState(void 0),[d,c]=k.useState(!1),[u,f]=k.useState(void 0);return{menu:a,setMenu:l,addingTile:d,openAdd:g=>{f(g),c(!0)},closeAdd:()=>c(!1),addTile:g=>{c(!1),e.update(y=>zv(y,g,{modelPath:r,textHeld:s,notebook:t,insertAt:u})),i(u??e.document.tiles.length)},addText:()=>{c(!1),e.update(g=>{const y=new Set(g.tiles.filter(je).map(S=>S.name));let _=1;for(;y.has(`text_${_}`);)_++;g.tiles.splice(u??g.tiles.length,0,{kind:"text",name:`text_${_}`,markdown:"",...t?{}:{colspan:n}})}),i(u??e.document.tiles.length)},editTile:(g,y)=>e.update(_=>{const S=_.tiles.find(E=>Fe(E)===g);S&&y(S)}),removeTile:g=>{l(void 0),o(),e.update(y=>{y.tiles.splice(g,1)})}}}var Bv=Object.defineProperty,Gv=Object.defineProperties,qv=Object.getOwnPropertyDescriptors,Ll=Object.getOwnPropertySymbols,Kv=Object.prototype.hasOwnProperty,Vv=Object.prototype.propertyIsEnumerable,Nl=(e,t,n)=>t in e?Bv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,an=(e,t)=>{for(var n in t||(t={}))Kv.call(t,n)&&Nl(e,n,t[n]);if(Ll)for(var n of Ll(t))Vv.call(t,n)&&Nl(e,n,t[n]);return e},ln=(e,t)=>Gv(e,qv(t));function Uv(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ss(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Oi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Hv(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,y)=>g===y||g!==null&&typeof g=="object"&&"id"in g&&g.id===y;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),y=e.findIndex(_=>l(_,o.id));if(g===-1||y===-1){if(Oi(i)){const _=i.initialIndex,S=i.index;return _===S||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,S)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,y)}const d=Object.entries(e);let c=-1,u,f=-1,h;for(const[g,y]of d)if(c===-1&&(c=y.findIndex(_=>l(_,i.id)),c!==-1&&(u=g)),f===-1&&(f=y.findIndex(_=>l(_,o.id)),f!==-1&&(h=g)),c!==-1&&f!==-1)break;if(c===-1&&Oi(i)){const g=i.initialGroup==null?void 0:ss(e,i.initialGroup),y=i.initialIndex,_=i.group==null?void 0:ss(e,i.group),S=i.index;if(g==null||_==null||g===_&&y===S)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return ln(an({},e),{[g]:n(e[g],y,S)});const E=e[g][y];return ln(an({},e),{[g]:[...e[g].slice(0,y),...e[g].slice(y+1)],[_]:[...e[_].slice(0,S),E,...e[_].slice(S)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,m=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const g=ss(e,o.id);if(g!=null){const y=o.shape&&m.y>o.shape.center.y?e[g].length:0;h=g,f=y}}if(u==null||h==null||u===h&&c===f){if(u!=null&&u===h&&c===f&&Oi(i)){const g=i.group==null?void 0:ss(e,i.group),y=i.group!=null&&g!==u,_=i.index!==c;if(y||_){const S=i.group==null?u:g;if(S!=null){if(u===S)return ln(an({},e),{[u]:n(e[u],c,i.index)});const E=e[u][c];return ln(an({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[S]:[...e[S].slice(0,i.index),E,...e[S].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(u===h)return ln(an({},e),{[u]:n(e[u],c,f)});const x=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[u][c];return ln(an({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[h]:[...e[h].slice(0,f+x),v,...e[h].slice(f+x)]})}function Xv(e,t){return Hv(e,t,Uv)}function Yv({tiles:e,commit:t,onLanded:n}){const[r,s]=k.useState(void 0),i=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),i.current=e},onDragOver:u=>{const{source:f,target:h}=u.operation;if(!f||!h)return;const p=i.current??e;let m;if(h.type===Od){const{after:b}=h.data,x=p.findIndex(y=>Fe(y)===f.id);if(x<0||b===f.id)return;const g=p.filter((y,_)=>_!==x).findIndex(y=>Fe(y)===b)+1;m=Tg(p,x,g)}else{const b=p.map(Fe),x=Xv(b,u);if(x.every((g,y)=>g===b[y]))return;const v=new Map(p.map(g=>[Fe(g),g]));m=$g(x.map(g=>v.get(g)),e.map(g=>g.break??!1))}i.current=m,s(m)},onDragEnd:u=>{a(!1);const f=i.current;if(i.current=void 0,s(void 0),u.canceled||!f)return;t(f);const h=f.findIndex(p=>Fe(p)===u.operation.source?.id);h>=0&&n(h)}}}const Ei=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Zv({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),l=f=>{a.current=f,o(f)};return k.useEffect(()=>()=>Ei(!1),[]),{resize:i,startResize:(f,h)=>{const p=n.current?.getBoundingClientRect(),m=f.currentTarget.parentElement?.getBoundingClientRect();if(!p||!m)return;f.stopPropagation(),f.preventDefault(),f.currentTarget.setPointerCapture(f.pointerId),Ei(!0),r(h);const b=e[h]?.colspan??1;l({index:h,span:b,from:b,left:m.left,track:(p.width-O.GRID_GAP_PX*(t-1))/t})},onResize:f=>{const h=a.current;if(!h)return;const p=f.clientX-h.left,m=Math.round((p+O.GRID_GAP_PX)/(h.track+O.GRID_GAP_PX)),b=Math.min(Math.max(m,1),t);b!==h.span&&l({...h,span:b})},endResize:f=>{f.currentTarget.hasPointerCapture(f.pointerId)&&f.currentTarget.releasePointerCapture(f.pointerId),Ei(!1);const h=a.current;if(!h)return;const{index:p,span:m,from:b}=h;l(void 0),!(f.type==="pointercancel"||m===b)&&s(p,m)}}}function Oa({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,allowLayoutChange:o=!0,renderTile:a,controls:l,givens:d,catalog:c,toolbar:u,dashboards:f,onEvent:h,conversion:p,savesTo:m="package",saveLabel:b,replaces:x,modelPath:v,visibleSources:g,addFilterDisabledReason:y}){const _=Nv({source:e,document:t,...n?{onSave:n}:{},...p?{conversion:p}:{},...x!==void 0?{replaces:x}:{},...g?{visibleSources:g}:{}}),S=k.useRef(null),{selected:E,descriptionSelected:D,selectTile:T,deselectTile:A,selectDescription:q,clearSelection:P,flash:z,stepEditor:U}=Ov({editor:_,gridBox:S}),K=_.document.layout==="linear",Z=K?1:_.document.columns??O.DEFAULT_COLUMNS,J=K?"none":"card",ie=v?.split("/").at(-1)?.replace(/\.malloy$/,""),de=Yv({tiles:_.document.tiles,commit:te=>_.update(R=>{R.tiles=te}),onLanded:T}),{dragging:I}=de,V=Zv({tiles:_.document.tiles,columns:Z,gridBox:S,onStart:T,commit:(te,R)=>_.update(F=>{const re=F.tiles[te];re&&(re.colspan=R)})}),B=Wv({editor:_,notebook:K,columns:Z,modelPath:v,textHeld:g!==void 0,selectTile:T,deselectTile:A}),{menu:j,addingTile:G,openAdd:ne}=B,Y=Pv({editor:_,opened:t,givens:d,catalog:c}),{filterDialog:H,setFilterDialog:L}=Y,[C,W]=k.useState(void 0),{draftDirty:M,openDraft:ee,prepare:X}=Fv({editorDirty:_.dirty}),{confirmConversion:le,prepareSave:ce}=jv({pendingOpen:_.pendingOpen,prepare:X}),N=k.useMemo(()=>({escape:()=>{!j&&!H&&!G&&C===void 0&&le===void 0&&P()},nudge:te=>{if(I||E===void 0||K)return;const R=_.document.tiles[E];if(!R||xe(R)&&R.declaration.kind==="inherited")return;const F=O.nudgedSpan(R.colspan??1,te,Z);F!==(R.colspan??1)&&_.update(re=>{re.tiles[E].colspan=F})}}),[_,j,H,G,C,le,P,E,Z,K,I]),Q=Cv({editor:U,extraDirty:M,prepare:ce,unit:{name:"tile",count:te=>te.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:N,report:yv({size:_.document.tiles.length,path:v??"",layout:_.document.layout,savesTo:m,onEvent:h})}),me=_.document.tiles.length===0,se=w.jsx(_v,{...Q.toolbarProps,...u?{actions:u}:{},...c?{onAddTile:()=>ne()}:{},savesTo:m,...b?{saveLabel:b}:{},...g===void 0&&o?{layout:_.document.layout,onLayoutChange:te=>{const R=_.document.layout;te!==R&&(_.update(F=>{F.layout=te}),O.reportEmitter({path:v??"",layout:te},h).emit({type:"report.layout_changed",from:R,to:te}))}}:{}});return w.jsx(hd.Provider,{value:ee,children:w.jsx($.Stack,{sx:{gap:0,mx:`-${Si}px`},children:w.jsxs($.Stack,{sx:{gap:2,px:`${Si}px`,pb:`${Si}px`},children:[_.pendingOpen&&w.jsx($.Alert,{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."}),w.jsx(vv,{editor:_,notebook:K,documentSlug:ie,chrome:J,actions:se,descriptionSelected:D,selectDescription:q}),me?w.jsx(w.Fragment,{children:w.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[w.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),c&&w.jsx($.Button,{size:"small",startIcon:w.jsx(O.AddIcon,{}),onClick:()=>ne(),children:"Add tile"})]})}):w.jsx($v,{sticky:!K,controls:Y.controlList,tileCount:_.document.tiles.length,unknownFieldsOf:Y.unknownFieldsOf,onEdit:te=>L({control:te}),onAdd:()=>L({}),...y?{addDisabledReason:y}:{},onRemove:Y.dropControl,children:l}),_.error&&w.jsx($.Alert,{severity:"warning",children:_.error}),w.jsx(pv,{editor:_,reorder:de,resizing:V,gridBox:S,columns:Z,notebook:K,chrome:J,canAdd:!!c,selected:E,flash:z,menuIndex:j?.index,onSelect:T,onOpenMenu:(te,R)=>{T(R),B.setMenu({anchor:te,index:R})},openAdd:ne,editTile:B.editTile,...a?{renderTile:a}:{}}),w.jsx($f,{editor:_,catalog:c,columns:Z,dashboards:f,bindings:Y,tiles:B,drillSource:C,setDrillSource:W,confirmConversion:le,exitDialog:Q.exitGuard.dialog})]})})})}function Qv(e,t){const n=new Set;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.add(o.given);const r=[],s=new Set;for(const i of e.localGivens??[])n.has(i.name)&&(s.add(i.name),r.push(Jv(i)));for(const i of t)i.name===void 0||s.has(i.name)||!n.has(i.name)||(s.add(i.name),r.push(i));return r}function Jv(e){const t=ey(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 ey(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 ty(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function is(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function ny(e,t,n,r=new Map,s){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:s&&[...s]};const i=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(m=>[m.name,m.type])),l=e.sources.find(m=>m.name===i)?.scopedBy??[],d=new Set([...l,...s??[]].filter(m=>n.has(m))),c=new Set([...l,...s??[]]),u=[];for(const m of t.filters??[]){const b=`where: ${ge.malloyPath(m.field)} ${m.op??"~"}`;if(n.has(m.given)){d.add(m.given),c.add(m.given),u.push(`${b} $${m.given}`);continue}if(!a.has(m.given))continue;c.add(m.given);const x=O.malloyLiteral(r.get(m.given),a.get(m.given));x!==void 0&&u.push(`${b} ${x}`)}const f=u.join(", "),h=t.chart,p=h==="none"||ni(h)?wn(h,t.chartCarried):h==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
+ `):h==="default"&&ty(t.declaration)?wn("none"):void 0;return{...p?{annotation:p}:{},expression:`${i} -> ${o}`+(f?` + { ${f} }`:""),givenNames:Array.from(d),reads:s||c.size>0?Array.from(c):void 0}}function ry({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:i}){const{apiClients:o,server:a}=Be.useServer(),{data:l}=O.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(p=>p.path&&!p.error?[p.path]:[])}),d=k.useMemo(()=>new Set([r,...s.flatMap(p=>p.path?[p.path]:[])]),[s,r]),c=k.useMemo(()=>i?(l??[]).filter(p=>!d.has(p)):[],[l,d,i]),u=ql.useQueries({queries:c.map(p=>({queryKey:["report-editor-model",e,t,p,n,a],queryFn:async()=>(await o.models.getModel(e,t,p,n)).data,retry:!1}))}),f=l!==void 0&&i&&u.every(p=>p.isSuccess||p.isError),h=u.map(p=>p.dataUpdatedAt).join();return k.useMemo(()=>f?Yd(u.flatMap(p=>p.data?[p.data]:[]),d):void 0,[f,c,h,d])}const sy={};function iy({textSource:e,modelGivens:t,environmentName:n,packageName:r,modelPath:s,versionId:i,opened:o,replaces:a,onSave:l,onDirtyChange:d,onExit:c,allowLayoutChange:u,onEvent:f,savesTo:h,saveLabel:p,note:m}){const{apiClients:b}=Be.useServer(),[x,v]=k.useState(o.document.tiles.length>0);k.useEffect(()=>v(o.document.tiles.length>0),[o.generation,o.document]);const{data:g,isSuccess:y,isError:_}=O.useQueryWithApiError({queryKey:["dashboard-editor-manifest",n,r,s,i],queryFn:async()=>{const N=(await b.reports.getReport(n,r,s,i)).data;return N.notebook?{...N.notebook.startingGivens?{startingGivens:N.notebook.startingGivens}:{},...N.notebook.autorun===void 0?{}:{autorun:N.notebook.autorun}}:N},enabled:x&&!e}),S=e?.modelPath??s,E=O.useCompiledDocument({environmentName:n,packageName:r,modelPath:S,source:o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0}),D=E.data?.document,T=e?E.isSuccess?D?.manifest??sy:void 0:g,A=e?E.isSuccess:y,q=e?E.isError:_,P=e?O.documentPreamble(D?.cells):void 0,z=(E.data?.result.problems??[]).filter(N=>N.severity==="error"),U=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),K=e?.givens,Z=k.useMemo(()=>new Set((T?.tiles??[]).flatMap(N=>N.restricted&&N.query?[is(N.query)]:[])),[T]),{reports:J,settled:ie}=O.useReportListing(n,r,i),de=k.useMemo(()=>J.map(N=>N.path).filter(N=>!!N&&N!==s&&N.endsWith(".malloy")).map(N=>N.replace(/\.malloy$/,"")),[J,s]),I=ry({environmentName:n,packageName:r,...i!==void 0?{versionId:i}:{},modelPath:s,reports:J,reportsSettled:ie}),V=k.useMemo(()=>e?(I?.sources??[]).filter(N=>(N.visibleIn??N.exporters??[N.modelPath]).includes(S)).map(N=>N.name):void 0,[I,e,S]),B=k.useMemo(()=>I&&V?{sources:I.sources.filter(N=>V.includes(N.name))}:I,[I,V]),[j,G]=k.useState(o.document);k.useEffect(()=>G(o.document),[o.document]);const ne=k.useMemo(()=>l&&(async(N,Q)=>{await l(N,Q.document.layout),h==="package"&&v(Q.document.tiles.length>0)}),[l,h]),Y=k.useMemo(()=>(T?.givens??(o.conversion?t??[]:[])).filter(N=>!(e&&N.secure===!0)&&!(N.name!==void 0&&U.has(N.name))),[T,o.conversion,t,U,e]),H=k.useMemo(()=>new Set([...Y.map(N=>N.name).filter(N=>N!==void 0),...Object.keys(K??{})]),[Y,K]),L=k.useMemo(()=>Qv(j,Y),[j,Y]),{declaredTypes:C,applied:W,panel:M}=O.useDocumentControls({specs:L,loaded:A,startingValues:T?.startingGivens,documentKey:`${n}/${r}/${i??""}/${s}/edit`,autorun:T?.autorun!==!1,environmentName:n,packageName:r,modelPath:e?S:T?.path,versionId:i,documentName:s,...P!==void 0?{preamble:P}:{},...K?{hostGivens:K}:{}}),ee=k.useMemo(()=>Object.fromEntries(Object.entries(K??{}).filter(([N])=>!C.has(N))),[K,C]),X=!x||A||q,le=k.useMemo(()=>new Map((T?.tiles??[]).flatMap(N=>N.kind!=="text"&&N.query&&N.givenNames?[[is(N.query),N.givenNames]]:[])),[T]),ce=k.useMemo(()=>function(Q,me,se="card"){if(!X)return w.jsxs(O.TileCard,{chrome:se,children:[w.jsx(O.TileHeading,{title:me?.title??Gs(Q),subtitle:me?me.subtitle:Q.subtitle}),w.jsx(O.Loading,{text:"Running…"})]});const te=ny(j,Q,H,W,le.get(is(`${Q.source} -> ${Q.name}`)));return w.jsx(O.DashboardTile,{environmentName:n,packageName:r,versionId:i,modelPath:S,...P!==void 0?{preamble:P}:{},...Z.has(is(`${Q.source} -> ${Q.name}`))?{restricted:!0}:{},tile:te.expression,...te.annotation?{annotation:te.annotation}:{},label:Gs(Q),chrome:se,subtitle:Q.subtitle,...me?{heading:me}:{},borderless:Q.borderless,givens:W,hostGivens:ee,declaredTypes:C,givenNames:te.givenNames,ignoredFilters:O.tileIgnoredFilterLabels(te.reads,L),height:O.TILE_MAX_HEIGHT})},[j,X,H,le,n,r,i,S,P,Z,W,ee,C,L]);return w.jsxs($.Stack,{sx:{gap:1},children:[e&&z.length>0&&w.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",z.map(N=>N.message).join("; ")]}),e&&E.isError&&w.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",E.error?.message]}),w.jsx(Oa,{...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:ce,givens:L.filter(N=>N.name!==void 0).map(N=>({name:N.name,...N.label?{label:N.label}:{},...N.type?{type:N.type}:{},...N.suggest?.dimension?{field:N.suggest.dimension}:{}})),onChange:G,onDirtyChange:d,...c?{onExit:c}:{},...u!==void 0?{allowLayoutChange:u}:{},...o.conversion?{conversion:o.conversion}:{},...B?{catalog:B}:{},dashboards:de,...f?{onEvent:f}:{},controls:A?w.jsx(O.GivensPanel,{...M,layout:j.layout==="linear"?"panel":"bar"}):void 0,...ne?{onSave:ne}:{},savesTo:h,...p?{saveLabel:p}:{},...a!==void 0?{replaces:a}:{},modelPath:s,...e?{visibleSources:V}:{}}),w.jsx($.Box,{sx:{px:.5},children:w.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:m})})]})}function oy({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[l,d]=k.useState(void 0),[c,u]=k.useState(e===void 0),[f,h]=k.useState(!1),[p,m]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let b=!1;return m(void 0),(async()=>{try{const x=O.chooseWorkspace(await e.listWorkspaces(!1));if(b)return;if(a(x),x!==void 0&&(!n||x.authoritative)){const v=await e.getDocument(O.locatorFor(t,x.name,r,s,i)).catch(g=>{if(!O.isDocumentNotFound(g))throw g});if(b)return;d(v),h(v!==void 0)}}catch(x){if(b)return;m(O.storageErrorMessage(x))}b||u(!0)})(),()=>{b=!0}},[e,t,n,r,s,i]),{workspace:o,draft:l,setDraft:d,draftChecked:c,offered:f,setOffered:h,readFailure:p}}const ay=e=>e.ok===!1,Un=(e,t)=>{const n=e[t];return typeof n=="function"?n.call(e):void 0},ly=[["runStatement","run"],["docAnnotations","notes"],["importStatement","definition"],["defineSourceStatement","definition"],["defineQuery","definition"],["defineGivenStatement","definition"],["defineUserTypeStatement","definition"],["exportStatement","definition"]],cy=/^[A-Za-z_][A-Za-z0-9_]*$/,uy="file:///publisher-notebook-builder/notebook.malloy",os=e=>e.replace(/\r\n?/g,`
144
144
  `);async function dy(e){const t=(I,V)=>({ok:!1,refused:`Line ${I+1}: ${V}`,line:I+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,s;try{r=await Wr(e,uy),s=await O.loadMalloy()}catch(I){return t(0,`Malloy could not read this notebook: ${I}`)}const i=r.problems.find(I=>I.code==="syntax-error");if(i)return t(i.at?.range?.start?.line??0,`Malloy could not parse this notebook (${i.message??"unknown"}), so it cannot be edited here. Fix: correct the syntax on that line.`);const o=r.parse?.root,a=r.parse?.tokenStream,l=a?.tokenSource?.vocabulary,d=typeof a?.getTokens=="function"?a.getTokens():void 0;if(!o||typeof o.getChild!="function"||!a||!d||typeof l?.getSymbolicName!="function"||d.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 u=I=>l.getSymbolicName(I.type),c=I=>s.routeOf({value:I.trimStart()}),f=I=>s.payloadOf({value:I}),h=I=>I==="markdown"||I==='"'||I==="text",p=I=>os(f(I)).replace(/\n$/,""),m=(I,V)=>{const B=f(I).trim(),R=c(I)!=='"'&&cy.test(B)?"":B;return os([R&&`${R}
146
- `,...V].join("")).replace(/\n$/,"")},b=new ri(e),w=ka(b,a),v=I=>e.slice(b.utf16(I.startIndex),b.utf16(I.stopIndex+1)),g=I=>{const V=I.start?.startIndex,B=I.stop?.stopIndex,R=b.span(I);if(V===void 0||B===void 0||!R)return;let G=R.end;for(;G>R.start&&(e[G-1]===`
147
- `||e[G-1]==="\r");)G--;return{startCp:V,stopCp:B,...R,startLine:b.line(R.start),endLine:b.line(Math.max(R.start,G-1))}},y=I=>{let V=0,B=d.length;for(;V<B;){const R=V+B>>1;d[R].startIndex<I?V=R+1:B=R}return V},_=(I,V)=>{const B=[],R=[],G={lines:[],insertAt:b.utf16(I)};let ne=-2;for(let Y=y(I);Y<d.length;Y++){const H=d[Y];if(H.startIndex>V)break;if(H.channel!==0)continue;const L=u(H);if(L!=="ANNOTATION"&&L!=="BLOCK_ANNOTATION_BEGIN"){G.insertAt=b.lineStarts[b.line(b.utf16(H.startIndex))];break}const C=os(v(H)),W=[];if(L==="BLOCK_ANNOTATION_BEGIN"){for(;u(d[Y+1]??H)==="BLOCK_ANNOTATION_TEXT";)W.push(v(d[++Y]));u(d[Y+1]??H)==="BLOCK_ANNOTATION_END"&&Y++}if(h(c(C))){const M=b.utf16(H.startIndex),ee=b.lineStarts[b.line(M)],X=/^[ \t]*$/.test(e.slice(ee,M));R.push({start:X?ee:M,end:b.utf16(d[Y].stopIndex+1)})}if(L==="ANNOTATION"){const M=C.replace(/\n$/,"");if(Dt(M)){const ee=b.utf16(H.startIndex),X=b.lineStarts[b.line(ee)];G.lines.push({span:{start:/^[ \t]*$/.test(e.slice(X,ee))?X:ee,end:b.utf16(H.stopIndex+1)},text:M})}else Tr(M)&&G.unmodelled===void 0&&(G.unmodelled=M.trim())}if(c(C)!=="markdown")ne=-2;else if(L==="BLOCK_ANNOTATION_BEGIN")B.push(m(C,W)),ne=-2;else{const M=p(C);H.line===ne+1?B[B.length-1]+=`
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,s;try{r=await Wr(e,uy),s=await O.loadMalloy()}catch(I){return t(0,`Malloy could not read this notebook: ${I}`)}const i=r.problems.find(I=>I.code==="syntax-error");if(i)return t(i.at?.range?.start?.line??0,`Malloy could not parse this notebook (${i.message??"unknown"}), so it cannot be edited here. Fix: correct the syntax on that line.`);const o=r.parse?.root,a=r.parse?.tokenStream,l=a?.tokenSource?.vocabulary,d=typeof a?.getTokens=="function"?a.getTokens():void 0;if(!o||typeof o.getChild!="function"||!a||!d||typeof l?.getSymbolicName!="function"||d.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 c=I=>l.getSymbolicName(I.type),u=I=>s.routeOf({value:I.trimStart()}),f=I=>s.payloadOf({value:I}),h=I=>I==="markdown"||I==='"'||I==="text",p=I=>os(f(I)).replace(/\n$/,""),m=(I,V)=>{const B=f(I).trim(),j=u(I)!=='"'&&cy.test(B)?"":B;return os([j&&`${j}
146
+ `,...V].join("")).replace(/\n$/,"")},b=new ri(e),x=ka(b,a),v=I=>e.slice(b.utf16(I.startIndex),b.utf16(I.stopIndex+1)),g=I=>{const V=I.start?.startIndex,B=I.stop?.stopIndex,j=b.span(I);if(V===void 0||B===void 0||!j)return;let G=j.end;for(;G>j.start&&(e[G-1]===`
147
+ `||e[G-1]==="\r");)G--;return{startCp:V,stopCp:B,...j,startLine:b.line(j.start),endLine:b.line(Math.max(j.start,G-1))}},y=I=>{let V=0,B=d.length;for(;V<B;){const j=V+B>>1;d[j].startIndex<I?V=j+1:B=j}return V},_=(I,V)=>{const B=[],j=[],G={lines:[],insertAt:b.utf16(I)};let ne=-2;for(let Y=y(I);Y<d.length;Y++){const H=d[Y];if(H.startIndex>V)break;if(H.channel!==0)continue;const L=c(H);if(L!=="ANNOTATION"&&L!=="BLOCK_ANNOTATION_BEGIN"){G.insertAt=b.lineStarts[b.line(b.utf16(H.startIndex))];break}const C=os(v(H)),W=[];if(L==="BLOCK_ANNOTATION_BEGIN"){for(;c(d[Y+1]??H)==="BLOCK_ANNOTATION_TEXT";)W.push(v(d[++Y]));c(d[Y+1]??H)==="BLOCK_ANNOTATION_END"&&Y++}if(h(u(C))){const M=b.utf16(H.startIndex),ee=b.lineStarts[b.line(M)],X=/^[ \t]*$/.test(e.slice(ee,M));j.push({start:X?ee:M,end:b.utf16(d[Y].stopIndex+1)})}if(L==="ANNOTATION"){const M=C.replace(/\n$/,"");if(At(M)){const ee=b.utf16(H.startIndex),X=b.lineStarts[b.line(ee)];G.lines.push({span:{start:/^[ \t]*$/.test(e.slice(X,ee))?X:ee,end:b.utf16(H.stopIndex+1)},text:M})}else Tr(M)&&G.unmodelled===void 0&&(G.unmodelled=M.trim())}if(u(C)!=="markdown")ne=-2;else if(L==="BLOCK_ANNOTATION_BEGIN")B.push(m(C,W)),ne=-2;else{const M=p(C);H.line===ne+1?B[B.length-1]+=`
148
148
  ${M}`:B.push(M),ne=H.line}}return{markdown:B.length>0?B.join(`
149
149
 
150
- `):void 0,prose:R,chart:G}},S=[],E=[],A=(I,V,B="remove it, or rewrite it as an import, source:, query:, given:, type: or export statement, a run:, or a `##(markdown)` / `##|(markdown)` prose note.")=>t(I,`${V}, which no notebook cell can hold, so the notebook cannot be edited here. Fix: ${B}`);for(let I=0;I<(o.childCount??0);I++){const V=o.getChild(I);if(!en(V)){const H=V?.symbol,L=H?u(H):void 0;if(H&&L==="EOF")continue;if(H&&L==="SEMI"){S.push([H.startIndex,H.stopIndex]);continue}return A((H?.line??1)-1,"a token outside any statement")}const B=g(V);if(!B)return A(0,"a statement with no readable range");const R=ly.find(([H])=>Un(V,H)!==void 0);if(!R&&Un(V,"ignoredObjectAnnotations"))return A(B.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 H=e.slice(B.start,B.end).split(`
151
- `)[0];return A(B.startLine,`\`${H.trim()}\` is a statement the notebook reader does not recognize`)}S.push([B.startCp,B.stopCp]);const[G,ne]=R;if(ne!=="notes"){const{markdown:H,prose:L,chart:C}=_(B.startCp,B.stopCp);E.push({kind:"statement",run:ne==="run",...H!==void 0&&{markdown:H},prose:L,chart:C,startLine:B.startLine,endLine:B.endLine});continue}const Y=Un(V,G);for(const H of Un(Y,"docAnnotation")??[]){const L=g(H);if(!L)return A(B.startLine,"a note with no readable range");const C=Un(H,"docBlockAnnotation")!==void 0,W=d.filter(N=>N.startIndex>=L.startCp&&N.stopIndex<=L.stopCp),M=W.filter(N=>u(N)==="BLOCK_ANNOTATION_TEXT"),ee=M[M.length-1]??W[0],X=os(C&&ee?e.slice(L.start,b.utf16(ee.stopIndex+1)).replace(/\r?\n$/,""):e.slice(L.start,L.end)),le=c(X),ce=h(le)?C?m(X.split(`
152
- `,1)[0],M.map(v)):p(X):void 0;E.push({kind:"note",note:{text:X,route:le,...ce!==void 0&&{body:ce},block:C,startLine:L.startLine,endLine:L.endLine}})}}for(const I of d){if(u(I)!=="BLOCK_ANNOTATION_END")continue;const V=v(I).trimStart().replace(/^\|#{1,2}/,"").trim();if(V)return t(I.line-1,`the text after a block's closer (\`${V}\`) 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 T=0;for(const I of d){if(I.channel!==0||u(I)==="EOF")continue;for(;T<S.length&&S[T][1]<I.startIndex;)T++;const[V,B]=S[T]??[1/0,-1/0];if(I.startIndex<V||I.stopIndex>B)return A(I.line-1,"a token outside any statement")}const D=E.findIndex(I=>I.kind==="note"&&ge.setsArtifactProperty(I.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 q=E.findIndex((I,V)=>V<D&&I.kind==="statement");if(q>=0)return t(E[q].startLine,'a statement sits above the `## artifact` tag, where only `##!` flags, comments and `"` notes may. Fix: move it below the artifact tag.');for(let I=1;I<E.length;I++){const V=E[I-1],B=E[I],R=V.kind==="note"?V.note.endLine:V.endLine,G=B.kind==="note"?B.note.startLine:B.startLine;if(G<=R)return A(G,"a line holding two statements or notes","put each statement and note on its own line.")}const P=I=>b.lineStarts[I+1]??e.length,z=[];let U=-1,K=!0,Z;E.forEach((I,V)=>{if(I.kind==="statement"){K=!1,Z=void 0,z.push({cell:{kind:I.run?"query":"definition",...I.markdown!==void 0&&{markdown:I.markdown},...I.prose.length>0&&{prose:I.prose},...I.run&&{chart:I.chart},id:""},startLine:I.startLine,endLine:I.endLine});return}const{note:B}=I;if(!(V>D&&B.body!==void 0)){K&&(U=B.endLine),Z=void 0;return}if(K=!1,!B.block&&Z&&Z.endLine+1===B.startLine){Z.cell.markdown+=`
153
- ${B.body}`,Z.endLine=B.endLine;return}const G={cell:{kind:"markdown",markdown:B.body,id:""},startLine:B.startLine,endLine:B.endLine};z.push(G),Z=B.block?void 0:G});const J={start:0,end:P(U)};let ie=U;const de=z.map(({cell:I,startLine:V,endLine:B},R)=>{let G=V;for(;G-1>ie&&w.lines.has(G-1);)G--;return ie=B,{...I,span:{start:b.lineStarts[G],end:P(B)},id:String(R)}});for(const I of[J,...de.map(V=>V.span)]){const V=w.all.find(B=>B.start<I.start&&B.end>I.start||B.start<I.end&&B.end>I.end);if(V)return A(b.line(V.start),"a comment that straddles a cell","start the comment on its own line.")}return{ok:!0,source:{text:e,header:J,cells:de}}}const fy=e=>e.ok===!1,hy=/^[A-Za-z_][A-Za-z0-9_]*$/,Fl=/^query\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s+is\s+/,zl=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;function Ci(e){let t="",n=0;for(;n<e.length;){const r=e.slice(n,n+2);if(r==="//"||r==="--"){const s=e.indexOf(`
150
+ `):void 0,prose:j,chart:G}},S=[],E=[],D=(I,V,B="remove it, or rewrite it as an import, source:, query:, given:, type: or export statement, a run:, or a `##(markdown)` / `##|(markdown)` prose note.")=>t(I,`${V}, which no notebook cell can hold, so the notebook cannot be edited here. Fix: ${B}`);for(let I=0;I<(o.childCount??0);I++){const V=o.getChild(I);if(!en(V)){const H=V?.symbol,L=H?c(H):void 0;if(H&&L==="EOF")continue;if(H&&L==="SEMI"){S.push([H.startIndex,H.stopIndex]);continue}return D((H?.line??1)-1,"a token outside any statement")}const B=g(V);if(!B)return D(0,"a statement with no readable range");const j=ly.find(([H])=>Un(V,H)!==void 0);if(!j&&Un(V,"ignoredObjectAnnotations"))return D(B.startLine,"a # tag that annotates no statement","move the tag directly above its run:, or write trailing prose as a `##(markdown)` note.");if(!j){const H=e.slice(B.start,B.end).split(`
151
+ `)[0];return D(B.startLine,`\`${H.trim()}\` is a statement the notebook reader does not recognize`)}S.push([B.startCp,B.stopCp]);const[G,ne]=j;if(ne!=="notes"){const{markdown:H,prose:L,chart:C}=_(B.startCp,B.stopCp);E.push({kind:"statement",run:ne==="run",...H!==void 0&&{markdown:H},prose:L,chart:C,startLine:B.startLine,endLine:B.endLine});continue}const Y=Un(V,G);for(const H of Un(Y,"docAnnotation")??[]){const L=g(H);if(!L)return D(B.startLine,"a note with no readable range");const C=Un(H,"docBlockAnnotation")!==void 0,W=d.filter(N=>N.startIndex>=L.startCp&&N.stopIndex<=L.stopCp),M=W.filter(N=>c(N)==="BLOCK_ANNOTATION_TEXT"),ee=M[M.length-1]??W[0],X=os(C&&ee?e.slice(L.start,b.utf16(ee.stopIndex+1)).replace(/\r?\n$/,""):e.slice(L.start,L.end)),le=u(X),ce=h(le)?C?m(X.split(`
152
+ `,1)[0],M.map(v)):p(X):void 0;E.push({kind:"note",note:{text:X,route:le,...ce!==void 0&&{body:ce},block:C,startLine:L.startLine,endLine:L.endLine}})}}for(const I of d){if(c(I)!=="BLOCK_ANNOTATION_END")continue;const V=v(I).trimStart().replace(/^\|#{1,2}/,"").trim();if(V)return t(I.line-1,`the text after a block's closer (\`${V}\`) 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 T=0;for(const I of d){if(I.channel!==0||c(I)==="EOF")continue;for(;T<S.length&&S[T][1]<I.startIndex;)T++;const[V,B]=S[T]??[1/0,-1/0];if(I.startIndex<V||I.stopIndex>B)return D(I.line-1,"a token outside any statement")}const A=E.findIndex(I=>I.kind==="note"&&ge.setsArtifactProperty(I.note.text));if(A<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 q=E.findIndex((I,V)=>V<A&&I.kind==="statement");if(q>=0)return t(E[q].startLine,'a statement sits above the `## artifact` tag, where only `##!` flags, comments and `"` notes may. Fix: move it below the artifact tag.');for(let I=1;I<E.length;I++){const V=E[I-1],B=E[I],j=V.kind==="note"?V.note.endLine:V.endLine,G=B.kind==="note"?B.note.startLine:B.startLine;if(G<=j)return D(G,"a line holding two statements or notes","put each statement and note on its own line.")}const P=I=>b.lineStarts[I+1]??e.length,z=[];let U=-1,K=!0,Z;E.forEach((I,V)=>{if(I.kind==="statement"){K=!1,Z=void 0,z.push({cell:{kind:I.run?"query":"definition",...I.markdown!==void 0&&{markdown:I.markdown},...I.prose.length>0&&{prose:I.prose},...I.run&&{chart:I.chart},id:""},startLine:I.startLine,endLine:I.endLine});return}const{note:B}=I;if(!(V>A&&B.body!==void 0)){K&&(U=B.endLine),Z=void 0;return}if(K=!1,!B.block&&Z&&Z.endLine+1===B.startLine){Z.cell.markdown+=`
153
+ ${B.body}`,Z.endLine=B.endLine;return}const G={cell:{kind:"markdown",markdown:B.body,id:""},startLine:B.startLine,endLine:B.endLine};z.push(G),Z=B.block?void 0:G});const J={start:0,end:P(U)};let ie=U;const de=z.map(({cell:I,startLine:V,endLine:B},j)=>{let G=V;for(;G-1>ie&&x.lines.has(G-1);)G--;return ie=B,{...I,span:{start:b.lineStarts[G],end:P(B)},id:String(j)}});for(const I of[J,...de.map(V=>V.span)]){const V=x.all.find(B=>B.start<I.start&&B.end>I.start||B.start<I.end&&B.end>I.end);if(V)return D(b.line(V.start),"a comment that straddles a cell","start the comment on its own line.")}return{ok:!0,source:{text:e,header:J,cells:de}}}const fy=e=>e.ok===!1,hy=/^[A-Za-z_][A-Za-z0-9_]*$/,Fl=/^query\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s+is\s+/,zl=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;function Ci(e){let t="",n=0;for(;n<e.length;){const r=e.slice(n,n+2);if(r==="//"||r==="--"){const s=e.indexOf(`
154
154
  `,n),i=s<0?e.length:s;t+=" ".repeat(i-n),n=i}else if(r==="/*"){const s=e.indexOf("*/",n+2),i=s<0?e.length:s+2;t+=e.slice(n,i).replace(/[^\n]/g," "),n=i}else if(e[n]==="'"||e[n]==='"'||e[n]==="`"){const s=e[n];let i=n+1;for(;i<e.length&&e[i]!==s;)i+=e[i]==="\\"?2:1;const o=Math.min(i,e.length);t+=s+e.slice(n+1,o).replace(/[^\n]/g," "),o<e.length&&(t+=s),n=o+1}else t+=e[n],n++}return t}function Wl(e){const t=[];let n=0;for(let r=0;r<e.length;r++){const s=e[r];s==="{"||s==="("||s==="["?n++:s==="}"||s===")"||s==="]"?n--:n===0&&s==="-"&&e[r+1]===">"&&t.push(r)}return t}function Bl(e,t,n){let r=e;for(const s of[...n].sort((i,o)=>o.start-i.start))r=r.slice(0,s.start-t)+r.slice(s.end-t);return r}function Gl(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
159
  `}function py(e){return e.trim()===""?"":/^\s*(#|\/\/|--|\/\*)/.test(e)?` ${e.trimStart()}`:` ${e}`}function gy(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)&&ge.isBareName(r)?r:void 0}async function my(e){const t=await dy(e);if(ay(t))return{ok:!1,refused:t.refused,line:t.line};const{header:n,cells:r}=t.source,s=(C,W)=>({ok:!1,refused:`Line ${C+1}: ${W}`,line:C+1}),i=e.slice(n.start,n.end).split(`
160
- `),o=ge.artifactTag(i);if(o&&!ge.artifactLeads(o.text))return s(o.from,ge.ARTIFACT_NOT_FIRST);if(!o||Sa(o.text))return s(Math.max(o?.from??0,0),"this notebook already lists its tiles, so there is nothing to convert.");const l=(await Wr(e,"file:///publisher-notebook-builder/convert.malloy")).parse?.tokenStream,d=l?.tokenSource?.vocabulary,u=l?.getTokens?.()??[];if(typeof d?.getSymbolicName!="function")return s(0,"Malloy's token stream is not available.");const c=await O.loadMalloy(),{parseAnnotation:f}=await O.loadMalloyTag(),h=C=>d.getSymbolicName(C.type),p=new ri(e),m=ka(p,l),b=C=>e.slice(p.utf16(C.startIndex),p.utf16(C.stopIndex+1)),w=C=>c.routeOf({value:C.trimStart()}),v=C=>c.payloadOf({value:C}),g=C=>C.replace(/\r\n?/g,`
161
- `),y=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),_=C=>{let W=C;for(let M=2;y.has(W);M++)W=`${C}_${M}`;return y.add(W),W},S=C=>{const W=u.filter(Q=>Q.channel===0&&p.utf16(Q.startIndex)>=C.span.start&&p.utf16(Q.stopIndex+1)<=C.span.end),M=[],ee=[],X=[];let le;for(let Q=0;Q<W.length;Q++){const me=h(W[Q]);if(me!=="ANNOTATION"&&me!=="BLOCK_ANNOTATION_BEGIN"){le=W[Q];break}let se=Q;const te=[];if(me==="BLOCK_ANNOTATION_BEGIN"){for(;h(W[se+1]??W[Q])==="BLOCK_ANNOTATION_TEXT";)te.push(b(W[++se]));h(W[se+1]??W[Q])==="BLOCK_ANNOTATION_END"&&se++}const j=g(b(W[Q])),F=w(j),re=p.utf16(W[Q].startIndex),ue=p.lineStarts[p.line(re)],je={start:/^[ \t]*$/.test(e.slice(ue,re))?ue:re,end:p.utf16(W[se].stopIndex+1)};F==="markdown"?M.push(je):F==='"'&&(ee.push(je),X.push(me==="ANNOTATION"?g(v(j)).replace(/\n$/,"").trim():[g(v(j.split(`
162
- `,1)[0])),...te.map(g)].map(Rt=>Rt.trim()).filter(Boolean).join(" "))),Q=se}if(!le)return;const ce=p.utf16(le.startIndex),N=e.slice(C.span.start,C.span.end);return{cell:C,above:Bl(e.slice(C.span.start,ce),C.span.start,(C.kind==="query"?[...M,...ee]:M).filter(Q=>Q.end<=ce)),statement:e.slice(ce,C.span.end).trimEnd(),kept:Bl(N,C.span.start,M),...C.kind==="query"&&X.length>0&&{caption:X.join(" ")},line:p.line(ce)}},E=new Map,A=new Map;for(const[C,W]of r.entries()){if(W.kind==="markdown")continue;const M=S(W);if(!M)return s(p.line(W.span.start),"a cell with no statement the converter can place.");A.set(C,M);const ee=Fl.exec(M.statement);W.kind==="definition"&&ee&&E.set(ee[1],{expression:M.statement.slice(ee[0].length).trim(),cell:C})}const T=C=>{const W=/^run\s*:\s*/.exec(C.statement);if(!W)return s(C.line,"a run that is not `run: <query>`.");let M=C.statement.slice(W[0].length).trim();const ee=[];for(let Q=0;Q<10;Q++){const me=Ci(M),se=/^[A-Za-z_][A-Za-z0-9_]*/.exec(me)?.[0],te=se?E.get(se):void 0;if(!se||!te)break;const j=M.slice(se.length).trim(),F=me.slice(se.length).trim();if(F!==""&&!F.startsWith("->")&&!F.startsWith("+"))break;if(F.startsWith("+")&&Wl(Ci(te.expression)).length!==1)return s(C.line,`\`${se} + { … }\` refines a query with more than one stage, which cannot become one view.`);ee.push(se);const re=/(\/\/|--)[^\n]*$/.test(te.expression)?`
163
- `:" ";M=`${te.expression}${j===""?"":`${re}${j}`}`}const X=Ci(M);if(E.has(/^[A-Za-z_][A-Za-z0-9_]*/.exec(X)?.[0]??""))return s(C.line,"this run names a query defined through more than 10 other queries, which the converter does not follow.");const le=Wl(X);if(le.length===0)return s(C.line,"this run is not `source -> view`, so it cannot become a tile. Fix: write it as `run: <source> -> <view>`.");const ce=M.slice(0,le[0]).trim();if(/\bextend\b/.test(X.slice(0,le[0])))return s(C.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(!hy.test(ce)&&!/^`[^`]+`$/.test(ce))return s(C.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 N=M.slice(le[0]+2).trim();return N===""?s(C.line,"this run has nothing after `->`."):{source:ce,body:N,used:ee}},D=new Map,q=[],P=new Set,z=new Map;let U=0,K=0;const Z=new Map;for(const C of A.values()){if(C.cell.kind!=="query")continue;const W=T(C);if("ok"in W)return W;for(const M of W.used)Z.set(M,(Z.get(M)??0)+1)}const J=C=>Z.get(C)===1&&(e.match(new RegExp(`\\b${C}\\b`,"g"))??[]).length===2,ie=new Map;for(const[C,W]of r.entries()){if(W.kind==="markdown"){const F=_(`text_${++U}`);q.push(`${F} { kind=text }`);const re=m.all.filter(ue=>ue.start>=W.span.start&&ue.end<=W.span.end).map(ue=>`${e.slice(ue.start,ue.end)}
164
- `).join("");z.set(C,re+Gl(F,W.markdown??""));continue}const M=A.get(C);let ee="";if(W.markdown!==void 0){const F=_(`text_${++U}`);q.push(`${F} { kind=text }`),ee=`${Gl(F,W.markdown)}
160
+ `),o=ge.artifactTag(i);if(o&&!ge.artifactLeads(o.text))return s(o.from,ge.ARTIFACT_NOT_FIRST);if(!o||Sa(o.text))return s(Math.max(o?.from??0,0),"this notebook already lists its tiles, so there is nothing to convert.");const l=(await Wr(e,"file:///publisher-notebook-builder/convert.malloy")).parse?.tokenStream,d=l?.tokenSource?.vocabulary,c=l?.getTokens?.()??[];if(typeof d?.getSymbolicName!="function")return s(0,"Malloy's token stream is not available.");const u=await O.loadMalloy(),{parseAnnotation:f}=await O.loadMalloyTag(),h=C=>d.getSymbolicName(C.type),p=new ri(e),m=ka(p,l),b=C=>e.slice(p.utf16(C.startIndex),p.utf16(C.stopIndex+1)),x=C=>u.routeOf({value:C.trimStart()}),v=C=>u.payloadOf({value:C}),g=C=>C.replace(/\r\n?/g,`
161
+ `),y=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),_=C=>{let W=C;for(let M=2;y.has(W);M++)W=`${C}_${M}`;return y.add(W),W},S=C=>{const W=c.filter(Q=>Q.channel===0&&p.utf16(Q.startIndex)>=C.span.start&&p.utf16(Q.stopIndex+1)<=C.span.end),M=[],ee=[],X=[];let le;for(let Q=0;Q<W.length;Q++){const me=h(W[Q]);if(me!=="ANNOTATION"&&me!=="BLOCK_ANNOTATION_BEGIN"){le=W[Q];break}let se=Q;const te=[];if(me==="BLOCK_ANNOTATION_BEGIN"){for(;h(W[se+1]??W[Q])==="BLOCK_ANNOTATION_TEXT";)te.push(b(W[++se]));h(W[se+1]??W[Q])==="BLOCK_ANNOTATION_END"&&se++}const R=g(b(W[Q])),F=x(R),re=p.utf16(W[Q].startIndex),ue=p.lineStarts[p.line(re)],Re={start:/^[ \t]*$/.test(e.slice(ue,re))?ue:re,end:p.utf16(W[se].stopIndex+1)};F==="markdown"?M.push(Re):F==='"'&&(ee.push(Re),X.push(me==="ANNOTATION"?g(v(R)).replace(/\n$/,"").trim():[g(v(R.split(`
162
+ `,1)[0])),...te.map(g)].map(jt=>jt.trim()).filter(Boolean).join(" "))),Q=se}if(!le)return;const ce=p.utf16(le.startIndex),N=e.slice(C.span.start,C.span.end);return{cell:C,above:Bl(e.slice(C.span.start,ce),C.span.start,(C.kind==="query"?[...M,...ee]:M).filter(Q=>Q.end<=ce)),statement:e.slice(ce,C.span.end).trimEnd(),kept:Bl(N,C.span.start,M),...C.kind==="query"&&X.length>0&&{caption:X.join(" ")},line:p.line(ce)}},E=new Map,D=new Map;for(const[C,W]of r.entries()){if(W.kind==="markdown")continue;const M=S(W);if(!M)return s(p.line(W.span.start),"a cell with no statement the converter can place.");D.set(C,M);const ee=Fl.exec(M.statement);W.kind==="definition"&&ee&&E.set(ee[1],{expression:M.statement.slice(ee[0].length).trim(),cell:C})}const T=C=>{const W=/^run\s*:\s*/.exec(C.statement);if(!W)return s(C.line,"a run that is not `run: <query>`.");let M=C.statement.slice(W[0].length).trim();const ee=[];for(let Q=0;Q<10;Q++){const me=Ci(M),se=/^[A-Za-z_][A-Za-z0-9_]*/.exec(me)?.[0],te=se?E.get(se):void 0;if(!se||!te)break;const R=M.slice(se.length).trim(),F=me.slice(se.length).trim();if(F!==""&&!F.startsWith("->")&&!F.startsWith("+"))break;if(F.startsWith("+")&&Wl(Ci(te.expression)).length!==1)return s(C.line,`\`${se} + { … }\` refines a query with more than one stage, which cannot become one view.`);ee.push(se);const re=/(\/\/|--)[^\n]*$/.test(te.expression)?`
163
+ `:" ";M=`${te.expression}${R===""?"":`${re}${R}`}`}const X=Ci(M);if(E.has(/^[A-Za-z_][A-Za-z0-9_]*/.exec(X)?.[0]??""))return s(C.line,"this run names a query defined through more than 10 other queries, which the converter does not follow.");const le=Wl(X);if(le.length===0)return s(C.line,"this run is not `source -> view`, so it cannot become a tile. Fix: write it as `run: <source> -> <view>`.");const ce=M.slice(0,le[0]).trim();if(/\bextend\b/.test(X.slice(0,le[0])))return s(C.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(!hy.test(ce)&&!/^`[^`]+`$/.test(ce))return s(C.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 N=M.slice(le[0]+2).trim();return N===""?s(C.line,"this run has nothing after `->`."):{source:ce,body:N,used:ee}},A=new Map,q=[],P=new Set,z=new Map;let U=0,K=0;const Z=new Map;for(const C of D.values()){if(C.cell.kind!=="query")continue;const W=T(C);if("ok"in W)return W;for(const M of W.used)Z.set(M,(Z.get(M)??0)+1)}const J=C=>Z.get(C)===1&&(e.match(new RegExp(`\\b${C}\\b`,"g"))??[]).length===2,ie=new Map;for(const[C,W]of r.entries()){if(W.kind==="markdown"){const F=_(`text_${++U}`);q.push(`${F} { kind=text }`);const re=m.all.filter(ue=>ue.start>=W.span.start&&ue.end<=W.span.end).map(ue=>`${e.slice(ue.start,ue.end)}
164
+ `).join("");z.set(C,re+Gl(F,W.markdown??""));continue}const M=D.get(C);let ee="";if(W.markdown!==void 0){const F=_(`text_${++U}`);q.push(`${F} { kind=text }`),ee=`${Gl(F,W.markdown)}
165
165
  `}if(W.kind==="definition"){const F=Fl.exec(M.statement)?.[1];if(F&&J(F)){P.add(C),ie.set(F,M.above.split(`
166
- `).filter(re=>re.trim()!=="")),ee&&z.set(C,ee.replace(/\n$/,""));continue}z.set(C,`${ee}${M.kept}`);continue}const X=T(M),le=X.source.replace(/`/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/^(?=[0-9])/,"_");let ce=D.get(X.source);ce||(ce={name:_(`${le}_tiles`),base:X.source,views:[]},D.set(X.source,ce));const N=[...X.used.flatMap(F=>ie.get(F)??[]),...M.above.split(`
167
- `)].filter(F=>F.trim()!==""),Q=N.filter(F=>/^\s*#(?!["(|])/.test(F)),me=Q.length>0?$a(f,Q).tag:void 0,se=_(gy(me?.text("label")??M.caption)??`tile_${K+1}`);K++,q.push(`"${ce.name} -> ${se}"`);const te=N.map(py);if(M.caption!==void 0){const F=O.annotationTextProblem("caption",M.caption)===void 0;F&&!me?.has("label")?te.push(` # label=${zl(M.caption)}`):F&&!me?.has("subtitle")?te.push(` # subtitle=${zl(M.caption)}`):te.push(` #" ${M.caption}`)}const j=X.body.split(`
166
+ `).filter(re=>re.trim()!=="")),ee&&z.set(C,ee.replace(/\n$/,""));continue}z.set(C,`${ee}${M.kept}`);continue}const X=T(M),le=X.source.replace(/`/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/^(?=[0-9])/,"_");let ce=A.get(X.source);ce||(ce={name:_(`${le}_tiles`),base:X.source,views:[]},A.set(X.source,ce));const N=[...X.used.flatMap(F=>ie.get(F)??[]),...M.above.split(`
167
+ `)].filter(F=>F.trim()!==""),Q=N.filter(F=>/^\s*#(?!["(|])/.test(F)),me=Q.length>0?$a(f,Q).tag:void 0,se=_(gy(me?.text("label")??M.caption)??`tile_${K+1}`);K++,q.push(`"${ce.name} -> ${se}"`);const te=N.map(py);if(M.caption!==void 0){const F=O.annotationTextProblem("caption",M.caption)===void 0;F&&!me?.has("label")?te.push(` # label=${zl(M.caption)}`):F&&!me?.has("subtitle")?te.push(` # subtitle=${zl(M.caption)}`):te.push(` #" ${M.caption}`)}const R=X.body.split(`
168
168
  `).map((F,re)=>re===0||F.trim()===""?F:` ${F}`).join(`
169
- `);ce.views.push([...te,` view: ${se} is ${j}`].join(`
169
+ `);ce.views.push([...te,` view: ${se} is ${R}`].join(`
170
170
  `)),P.add(C),ee&&z.set(C,ee.replace(/\n$/,""))}const de=(()=>{let C=0;const W=o.text;for(let M=W.indexOf("{");M<W.length;M++)if(W[M]==='"')for(M++;M<W.length&&W[M]!=='"';M++)W[M]==="\\"&&M++;else if(W[M]==="{")C++;else if(W[M]==="}"&&--C===0)return M;return-1})();if(de<0)return s(o.from,"the `## artifact { … }` tag never closes.");const I=q.length===0?`
171
171
  tiles=[]
172
172
  `:`
@@ -176,14 +176,14 @@ ${q.map(C=>` ${C}`).join(`,
176
176
  ]
177
177
  `,B=`${o.text.slice(0,de).replace(/[ \t]*\blayout\s*=\s*(?:"(?:[^"\\]|\\.)*"|[^\s}]+)/g,"").replace(/\bartifact\s*\{/,C=>`${C} layout=linear`).trimEnd().replace(/^##(?!\|)/,"##|")}${I}${o.text.slice(de)}`;i.splice(o.from,o.block?o.to-o.from:1,...(o.block?B:`${B}
178
178
  |##`).split(`
179
- `));const R=C=>{const W=C.text.split(`
179
+ `));const j=C=>{const W=C.text.split(`
180
180
  `),M=W.pop(),ee=[];let X=0;for(const le of W){const ce=C.at[X]??-1,N=m.all.some(Q=>ce>=Q.start&&ce<Q.end);(le.trim()!==""||ee.at(-1)?.trim()!==""||N)&&ee.push(le),X+=le.length+1}return ee.map(le=>`${le}
181
181
  `).join("")+M},G={text:"",at:[]},ne=(C,W)=>{G.text+=e.slice(C,W);for(let M=C;M<W;M++)G.at.push(M)};let Y=i.join(`
182
- `),H=n.end;for(const[C,W]of r.entries()){ne(H,W.span.start),H=W.span.end;const M=z.get(C);M!==void 0&&(Y+=R(G)+(M.endsWith(`
182
+ `),H=n.end;for(const[C,W]of r.entries()){ne(H,W.span.start),H=W.span.end;const M=z.get(C);M!==void 0&&(Y+=j(G)+(M.endsWith(`
183
183
  `)?M:`${M}
184
184
  `),G.text="",G.at=[])}ne(H,e.length),Y=`${Y.trimEnd()}
185
- `+(G.text.trim()===""?"":R(G)),Y=`${Y.trimEnd()}
186
- `;const L=[...D.values()].map(C=>`source: ${C.name} is ${C.base} extend {
185
+ `+(G.text.trim()===""?"":j(G)),Y=`${Y.trimEnd()}
186
+ `;const L=[...A.values()].map(C=>`source: ${C.name} is ${C.base} extend {
187
187
  ${C.views.join(`
188
188
 
189
189
  `)}
@@ -192,4 +192,4 @@ ${C.views.join(`
192
192
  ${L.join(`
193
193
  `)}`),e.includes(`\r
194
194
  `)&&(Y=Y.replace(/\r?\n/g,`\r
195
- `)),{ok:!0,text:Y,tiles:q.length}}const Ii=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function vy(e){const t=await Cr(e);if(!Er(t))return{ok:!0,document:t.document};if(!t.legacyNotebook)return{ok:!1,reason:Ii(t.reason,t.line)};const n=await my(e);if(fy(n))return{ok:!1,reason:Ii(n.refused,n.line)};const r=await Cr(n.text);return Er(r)?{ok:!1,reason:`The converted notebook cannot be opened: ${Ii(r.reason,r.line)}`}:{ok:!0,document:r.document,conversion:{from:e,to:n.text}}}const yy="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",by="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function xy({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,layout:l,notebook:d,noun:u,legacyFormat:c,textHeld:f,startedAt:h,onEventRef:p}){const m=k.useRef({path:a,layout:l});m.current={path:a,layout:l};const b=k.useRef((N,Q)=>{try{p.current?.(O.withReportContext(N,{...m.current,...Q?{layout:Q}:{}}))}catch{}}),w=e?.authoritative===!0,v=w&&r!==void 0,[g,y]=k.useState(void 0),_=(w||g===!0)&&t!==void 0,[S,E]=k.useState(void 0),[A,T]=k.useState(c?yy:void 0),D=k.useRef(void 0),q=k.useRef(void 0),[P,z]=k.useState(void 0),U=k.useRef(i);U.current=i;const K=P!==void 0&&P.onFetch===i?P.text:s,Z=k.useRef(K);Z.current=K;const J=_?t:K,[ie,de]=k.useState(!1),[I,V]=k.useState(void 0),[B,R]=k.useState(void 0),G=J!==void 0&&J!==B,ne=S?.source,H=G&&(ie||!w&&t!==void 0&&ne===t&&t!==K)&&ne!==void 0&&J!==I,L=H?ne:G?J:ne??J,C=H?J:void 0,W=k.useRef(ne);W.current=ne;const M=k.useRef(J);M.current=J;const ee=k.useRef("package");ee.current=_?w?"record":"draft":"package",k.useEffect(()=>{if(L===void 0||!n||v||L===W.current)return;let N=!1;const Q=Z.current,me=M.current;return vy(L).then(se=>{if(!N){if(se.ok===!1){T(se.reason),b.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}T(void 0),D.current=void 0,q.current=Q,z(void 0),V(void 0),R(me),E(te=>({source:L,document:se.document,...se.conversion?{conversion:se.conversion}:{},...Q!==void 0?{packageText:Q}:{},generation:(te?.generation??0)+1})),b.current({type:"report.opened",surface:"edit",from:ee.current,tiles:se.document.tiles.length,durationMs:O.now()-h.current},se.document.layout)}}).catch(se=>{if(N)return;const te=`Could not read the ${u}: ${se instanceof Error?se.message:String(se)}`;T(te),b.current({type:"report.load_failed",surface:"edit",category:O.failureCategory(se)})}),()=>{N=!0}},[L,a,n,v,d,u,f,h]),k.useEffect(()=>{c&&b.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[c]),k.useEffect(()=>{!f||!n||S||r!==void 0||(w?t===void 0&&T("the host's storage has no document at this location."):T("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,S,r,w,t]);const X=d&&!f&&!S&&n&&!_&&o&&s===void 0;return k.useEffect(()=>{X&&(T(by),b.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[X]),{authoritative:w,blockedOnRecord:v,resume:g,setResume:y,fromDraft:_,opened:S,setOpened:E,openError:A,savedHashRef:D,packageBaseRef:q,setWrote:z,fetchedAtRef:U,setDirty:de,setSeen:R,held:C,choose:N=>{h.current=O.now(),V(N?t:K),y(N)},acceptHeld:()=>{h.current=O.now(),V(C)}}}function wy({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:l,queryClient:d,mutable:u,textHeld:c,readFailure:f,authoritative:h,resume:p,setResume:m,setOpened:b,setDraft:w,setOffered:v,setSeen:g,setWrote:y,savedHashRef:_,packageBaseRef:S,fetchedAtRef:E}){const A=k.useCallback(I=>t===void 0?void 0:O.locatorFor(I,t.name,s,i,o),[t,s,i,o]),T=A(n),D=k.useCallback(async(I,V=n)=>{const B=A(V);if(!e||!B)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(B,I),b(R=>R&&{...R,source:I}),w(I),(h||p===!0)&&g(I),h||m(R=>R??!1)},[e,A,n,h,p,b,w,g,m]),[q,P]=k.useState(void 0),z=k.useCallback(async I=>{const V=await O.expectedHashFor(_.current,S.current);if(V===void 0)throw new Error("The package file is still loading; try again.");const B=["dashboard-editor-model",s,i,o,a,r];await O.writePackageFile({apiClients:l,queryClient:d,environmentName:s,packageName:i,modelPath:o,source:I,expectedHash:V,invalidateOnError:[B],afterWrite:async R=>{if(b(G=>G&&{...G,source:I}),y({text:I,onFetch:E.current}),g(I),_.current=R,P(void 0),e&&T)try{await e.deleteDocument(T),w(void 0),v(!1)}catch(G){O.isDocumentNotFound(G)?(w(void 0),v(!1)):P(O.storageErrorMessage(G))}m(!1)},invalidate:[{queryKey:B,wait:!0},{queryKey:O.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})},{queryKey:["dashboard-editor-manifest"]}]}),O.invalidateReportQueries(d,s,i,o)},[l,s,i,o,a,r,e,T,d,_,S,E,b,y,g,w,v,m]),U=t?.writeable===!0,K=u===!0&&!c,{savesTo:Z,pinnedPackageSave:J,writer:ie}=O.saveTarget({authoritative:h,mutable:K,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!T&&U&&(!r||h),readFailed:f!==void 0});return{save:ie==="storage"?D:ie==="package"?z:void 0,savesTo:Z,writer:ie,pinnedPackageSave:J,takesWrites:K,supersedeFailure:q}}function Ea(e){const{onEvent:t,onDirtyChange:n,onExit:r,kind:s,path:i,textSource:o,allowLayoutChange:a}=e,l=e.layout??(s?O.layoutOfKind(s):"grid"),d=l==="linear",u=o!==void 0,{environmentName:c,packageName:f,versionId:h,namesBoth:p}=O.resolveEditorTarget(e),b=("resourceUri"in e?e.dashboard:e.dashboardName)??O.documentSlug(i)??"",w="report",{apiClients:v,mutable:g,isLoadingStatus:y}=Be.useServer(),_=ql.useQueryClient(),S=k.useRef(O.now()),E=k.useRef(t);E.current=t;const A=k.useRef(n);A.current=n;const T=O.useOptionalDocumentStorage()?.documentStorage,D=i??O.legacyNamedPath(s??"dashboard",b),q=/\.malloynb$/i.test(D)||d&&/\.malloynb$/i.test(b),P=O.useQueryWithApiError({queryKey:["dashboard-editor-model",c,f,D,h,d],queryFn:()=>v.models.getModel(c,f,D,h,d?!0:void 0),enabled:p&&!q&&!u}),z=P.data?.data?.sourceText,{workspace:U,draft:K,setDraft:Z,draftChecked:J,offered:ie,setOffered:de,readFailure:I}=oy({storage:T,layout:l,notebook:d,environmentName:c,packageName:f,modelPath:D}),{authoritative:V,blockedOnRecord:B,resume:R,setResume:G,fromDraft:ne,opened:Y,setOpened:H,openError:L,savedHashRef:C,packageBaseRef:W,setWrote:M,fetchedAtRef:ee,setDirty:X,setSeen:le,held:ce,choose:N,acceptHeld:Q}=xy({workspace:U,draft:K,draftChecked:J,readFailure:I,packageText:z,fetchedAt:P.dataUpdatedAt,packageSettled:P.isSuccess&&!P.isFetching,modelPath:D,layout:l,notebook:d,noun:w,legacyFormat:q,textHeld:u,startedAt:S,onEventRef:E}),{save:me,savesTo:se,writer:te,pinnedPackageSave:j,takesWrites:F,supersedeFailure:re}=wy({storage:T,workspace:U,layout:l,notebook:d,environmentName:c,packageName:f,modelPath:D,versionId:h,apiClients:v,queryClient:_,mutable:g,textHeld:u,readFailure:I,authoritative:V,resume:R,setResume:G,setOpened:H,setDraft:Z,setOffered:de,setSeen:le,setWrote:M,savedHashRef:C,packageBaseRef:W,fetchedAtRef:ee}),ue=U?.name,je=k.useCallback(jt=>{E.current?.(O.withWorkspace(jt,ue))},[ue]),Rt=P.isError&&!Y,ut=k.useRef(!1);k.useEffect(()=>{!Rt||ut.current||(ut.current=!0,O.reportEmitter({path:D,layout:l},E.current).emit({type:"report.load_failed",surface:"edit",category:O.failureCategory(P.error)}))},[Rt,P.error,D,l]);const zn=k.useCallback(jt=>{X(jt),A.current?.(jt)},[X]),_t=se==="host"&&U?.description?U.description:void 0,Wn=!V&&!u&&g===void 0?y?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":O.saveCaption({authoritative:V,mutable:F,pinnedPackageSave:j,...U?{workspace:U}:{},...I!==void 0?{readFailure:I}:{},...h!==void 0?{versionId:h}:{}}),Gr=Wn===_t?"":Wn;if(!p&&"resourceUri"in e)return x.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",w," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(L)return x.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",w," cannot be opened in the builder: ",L]});if(P.isError&&!Y)return x.jsx(O.ApiErrorDisplay,{error:P.error,context:`Opening the ${w}`});if(!Y&&(!(u||z)||!J))return x.jsx(O.Loading,{text:`Opening the ${w}…`});if(B)return x.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",w," cannot be opened: ",I]});const Bn=K!==void 0&&K!==z;return x.jsxs($.Stack,{sx:{gap:2},children:[P.isError&&x.jsxs($.Alert,{severity:"warning",children:["The ",w," could not be re-read from the server:"," ",P.error?.message,". Your edits are still here."]}),!d&&!V&&ie&&Bn&&R===void 0&&x.jsx($.Alert,{severity:"info",action:x.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[x.jsx($.Button,{size:"small",onClick:()=>N(!0),children:"Resume"}),x.jsx($.Button,{size:"small",onClick:()=>N(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),ce!==void 0&&x.jsx($.Alert,{severity:"warning",action:x.jsx($.Button,{size:"small",onClick:Q,children:"Load it"}),children:se==="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.":se==="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."}),re!==void 0&&x.jsxs($.Alert,{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:"," ",re]}),Y&&x.jsx(iy,{environmentName:c,packageName:f,modelPath:D,...o?{textSource:o}:{},slug:b,modelGivens:P.data?.data?.givens,...h!==void 0?{versionId:h}:{},opened:Y,...ne&&te==="package"&&Y.packageText!==void 0?{replaces:Y.packageText}:{},onSave:me,onDirtyChange:zn,...r?{onExit:r}:{},...a!==void 0?{allowLayoutChange:a}:{},savesTo:se,..._t?{saveLabel:_t}:{},...t?{onEvent:je}:{},note:Gr},Y.generation)]})}const _y=Ea,ky=Oa;function Sy(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return x.jsx(Ea,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=O.MAX_SLUG_ATTEMPTS;exports.createDocument=O.createDocument;exports.createRoute=O.createRoute;exports.locatorFor=O.locatorFor;exports.newDashboardSource=O.newDashboardSource;exports.newDocumentProblem=O.newDocumentProblem;exports.newNotebookSource=O.newNotebookSource;exports.reportPathFor=O.reportPathFor;exports.reportPathForTitle=O.reportPathForTitle;exports.slugFor=O.slugFor;exports.slugOrFallback=O.slugOrFallback;exports.useDocumentChoices=O.useDocumentChoices;exports.DashboardBuilder=ky;exports.DashboardEditor=_y;exports.NotebookEditor=Sy;exports.ReportBuilder=Oa;exports.ReportEditor=Ea;exports.buildCatalog=Yd;exports.readDashboardDocument=Cr;exports.readFailed=Er;exports.readReportTagOfText=Cm;exports.spliceDashboardDocument=Kd;exports.spliceFailed=zs;
195
+ `)),{ok:!0,text:Y,tiles:q.length}}const Ii=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function vy(e){const t=await Cr(e);if(!Er(t))return{ok:!0,document:t.document};if(!t.legacyNotebook)return{ok:!1,reason:Ii(t.reason,t.line)};const n=await my(e);if(fy(n))return{ok:!1,reason:Ii(n.refused,n.line)};const r=await Cr(n.text);return Er(r)?{ok:!1,reason:`The converted notebook cannot be opened: ${Ii(r.reason,r.line)}`}:{ok:!0,document:r.document,conversion:{from:e,to:n.text}}}const yy="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",by="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function xy({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,layout:l,notebook:d,noun:c,legacyFormat:u,textHeld:f,startedAt:h,onEventRef:p}){const m=k.useRef({path:a,layout:l});m.current={path:a,layout:l};const b=k.useRef((N,Q)=>{try{p.current?.(O.withReportContext(N,{...m.current,...Q?{layout:Q}:{}}))}catch{}}),x=e?.authoritative===!0,v=x&&r!==void 0,[g,y]=k.useState(void 0),_=(x||g===!0)&&t!==void 0,[S,E]=k.useState(void 0),[D,T]=k.useState(u?yy:void 0),A=k.useRef(void 0),q=k.useRef(void 0),[P,z]=k.useState(void 0),U=k.useRef(i);U.current=i;const K=P!==void 0&&P.onFetch===i?P.text:s,Z=k.useRef(K);Z.current=K;const J=_?t:K,[ie,de]=k.useState(!1),[I,V]=k.useState(void 0),[B,j]=k.useState(void 0),G=J!==void 0&&J!==B,ne=S?.source,H=G&&(ie||!x&&t!==void 0&&ne===t&&t!==K)&&ne!==void 0&&J!==I,L=H?ne:G?J:ne??J,C=H?J:void 0,W=k.useRef(ne);W.current=ne;const M=k.useRef(J);M.current=J;const ee=k.useRef("package");ee.current=_?x?"record":"draft":"package",k.useEffect(()=>{if(L===void 0||!n||v||L===W.current)return;let N=!1;const Q=Z.current,me=M.current;return vy(L).then(se=>{if(!N){if(se.ok===!1){T(se.reason),b.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}T(void 0),A.current=void 0,q.current=Q,z(void 0),V(void 0),j(me),E(te=>({source:L,document:se.document,...se.conversion?{conversion:se.conversion}:{},...Q!==void 0?{packageText:Q}:{},generation:(te?.generation??0)+1})),b.current({type:"report.opened",surface:"edit",from:ee.current,tiles:se.document.tiles.length,durationMs:O.now()-h.current},se.document.layout)}}).catch(se=>{if(N)return;const te=`Could not read the ${c}: ${se instanceof Error?se.message:String(se)}`;T(te),b.current({type:"report.load_failed",surface:"edit",category:O.failureCategory(se)})}),()=>{N=!0}},[L,a,n,v,d,c,f,h]),k.useEffect(()=>{u&&b.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[u]),k.useEffect(()=>{!f||!n||S||r!==void 0||(x?t===void 0&&T("the host's storage has no document at this location."):T("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,S,r,x,t]);const X=d&&!f&&!S&&n&&!_&&o&&s===void 0;return k.useEffect(()=>{X&&(T(by),b.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[X]),{authoritative:x,blockedOnRecord:v,resume:g,setResume:y,fromDraft:_,opened:S,setOpened:E,openError:D,savedHashRef:A,packageBaseRef:q,setWrote:z,fetchedAtRef:U,setDirty:de,setSeen:j,held:C,choose:N=>{h.current=O.now(),V(N?t:K),y(N)},acceptHeld:()=>{h.current=O.now(),V(C)}}}function wy({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:l,queryClient:d,mutable:c,textHeld:u,readFailure:f,authoritative:h,resume:p,setResume:m,setOpened:b,setDraft:x,setOffered:v,setSeen:g,setWrote:y,savedHashRef:_,packageBaseRef:S,fetchedAtRef:E}){const D=k.useCallback(I=>t===void 0?void 0:O.locatorFor(I,t.name,s,i,o),[t,s,i,o]),T=D(n),A=k.useCallback(async(I,V=n)=>{const B=D(V);if(!e||!B)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(B,I),b(j=>j&&{...j,source:I}),x(I),(h||p===!0)&&g(I),h||m(j=>j??!1)},[e,D,n,h,p,b,x,g,m]),[q,P]=k.useState(void 0),z=k.useCallback(async I=>{const V=await O.expectedHashFor(_.current,S.current);if(V===void 0)throw new Error("The package file is still loading; try again.");const B=["dashboard-editor-model",s,i,o,a,r];await O.writePackageFile({apiClients:l,queryClient:d,environmentName:s,packageName:i,modelPath:o,source:I,expectedHash:V,invalidateOnError:[B],afterWrite:async j=>{if(b(G=>G&&{...G,source:I}),y({text:I,onFetch:E.current}),g(I),_.current=j,P(void 0),e&&T)try{await e.deleteDocument(T),x(void 0),v(!1)}catch(G){O.isDocumentNotFound(G)?(x(void 0),v(!1)):P(O.storageErrorMessage(G))}m(!1)},invalidate:[{queryKey:B,wait:!0},{queryKey:O.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})},{queryKey:["dashboard-editor-manifest"]}]}),O.invalidateReportQueries(d,s,i,o)},[l,s,i,o,a,r,e,T,d,_,S,E,b,y,g,x,v,m]),U=t?.writeable===!0,K=c===!0&&!u,{savesTo:Z,pinnedPackageSave:J,writer:ie}=O.saveTarget({authoritative:h,mutable:K,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!T&&U&&(!r||h),readFailed:f!==void 0});return{save:ie==="storage"?A:ie==="package"?z:void 0,savesTo:Z,writer:ie,pinnedPackageSave:J,takesWrites:K,supersedeFailure:q}}function Ea(e){const{onEvent:t,onDirtyChange:n,onExit:r,kind:s,path:i,textSource:o,allowLayoutChange:a}=e,l=e.layout??(s?O.layoutOfKind(s):"grid"),d=l==="linear",c=o!==void 0,{environmentName:u,packageName:f,versionId:h,namesBoth:p}=O.resolveEditorTarget(e),b=("resourceUri"in e?e.dashboard:e.dashboardName)??O.documentSlug(i)??"",x="report",{apiClients:v,mutable:g,isLoadingStatus:y}=Be.useServer(),_=ql.useQueryClient(),S=k.useRef(O.now()),E=k.useRef(t);E.current=t;const D=k.useRef(n);D.current=n;const T=O.useOptionalDocumentStorage()?.documentStorage,A=i??O.legacyNamedPath(s??"dashboard",b),q=/\.malloynb$/i.test(A)||d&&/\.malloynb$/i.test(b),P=O.useQueryWithApiError({queryKey:["dashboard-editor-model",u,f,A,h,d],queryFn:()=>v.models.getModel(u,f,A,h,d?!0:void 0),enabled:p&&!q&&!c}),z=P.data?.data?.sourceText,{workspace:U,draft:K,setDraft:Z,draftChecked:J,offered:ie,setOffered:de,readFailure:I}=oy({storage:T,layout:l,notebook:d,environmentName:u,packageName:f,modelPath:A}),{authoritative:V,blockedOnRecord:B,resume:j,setResume:G,fromDraft:ne,opened:Y,setOpened:H,openError:L,savedHashRef:C,packageBaseRef:W,setWrote:M,fetchedAtRef:ee,setDirty:X,setSeen:le,held:ce,choose:N,acceptHeld:Q}=xy({workspace:U,draft:K,draftChecked:J,readFailure:I,packageText:z,fetchedAt:P.dataUpdatedAt,packageSettled:P.isSuccess&&!P.isFetching,modelPath:A,layout:l,notebook:d,noun:x,legacyFormat:q,textHeld:c,startedAt:S,onEventRef:E}),{save:me,savesTo:se,writer:te,pinnedPackageSave:R,takesWrites:F,supersedeFailure:re}=wy({storage:T,workspace:U,layout:l,notebook:d,environmentName:u,packageName:f,modelPath:A,versionId:h,apiClients:v,queryClient:_,mutable:g,textHeld:c,readFailure:I,authoritative:V,resume:j,setResume:G,setOpened:H,setDraft:Z,setOffered:de,setSeen:le,setWrote:M,savedHashRef:C,packageBaseRef:W,fetchedAtRef:ee}),ue=U?.name,Re=k.useCallback(Rt=>{E.current?.(O.withWorkspace(Rt,ue))},[ue]),jt=P.isError&&!Y,ut=k.useRef(!1);k.useEffect(()=>{!jt||ut.current||(ut.current=!0,O.reportEmitter({path:A,layout:l},E.current).emit({type:"report.load_failed",surface:"edit",category:O.failureCategory(P.error)}))},[jt,P.error,A,l]);const zn=k.useCallback(Rt=>{X(Rt),D.current?.(Rt)},[X]),_t=se==="host"&&U?.description?U.description:void 0,Wn=!V&&!c&&g===void 0?y?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":O.saveCaption({authoritative:V,mutable:F,pinnedPackageSave:R,...U?{workspace:U}:{},...I!==void 0?{readFailure:I}:{},...h!==void 0?{versionId:h}:{}}),Gr=Wn===_t?"":Wn;if(!p&&"resourceUri"in e)return w.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",x," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(L)return w.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened in the builder: ",L]});if(P.isError&&!Y)return w.jsx(O.ApiErrorDisplay,{error:P.error,context:`Opening the ${x}`});if(!Y&&(!(c||z)||!J))return w.jsx(O.Loading,{text:`Opening the ${x}…`});if(B)return w.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened: ",I]});const Bn=K!==void 0&&K!==z;return w.jsxs($.Stack,{sx:{gap:2},children:[P.isError&&w.jsxs($.Alert,{severity:"warning",children:["The ",x," could not be re-read from the server:"," ",P.error?.message,". Your edits are still here."]}),!d&&!V&&ie&&Bn&&j===void 0&&w.jsx($.Alert,{severity:"info",action:w.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[w.jsx($.Button,{size:"small",onClick:()=>N(!0),children:"Resume"}),w.jsx($.Button,{size:"small",onClick:()=>N(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),ce!==void 0&&w.jsx($.Alert,{severity:"warning",action:w.jsx($.Button,{size:"small",onClick:Q,children:"Load it"}),children:se==="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.":se==="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."}),re!==void 0&&w.jsxs($.Alert,{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:"," ",re]}),Y&&w.jsx(iy,{environmentName:u,packageName:f,modelPath:A,...o?{textSource:o}:{},slug:b,modelGivens:P.data?.data?.givens,...h!==void 0?{versionId:h}:{},opened:Y,...ne&&te==="package"&&Y.packageText!==void 0?{replaces:Y.packageText}:{},onSave:me,onDirtyChange:zn,...r?{onExit:r}:{},...a!==void 0?{allowLayoutChange:a}:{},savesTo:se,..._t?{saveLabel:_t}:{},...t?{onEvent:Re}:{},note:Gr},Y.generation)]})}const _y=Ea,ky=Oa;function Sy(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return w.jsx(Ea,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=O.MAX_SLUG_ATTEMPTS;exports.createDocument=O.createDocument;exports.createRoute=O.createRoute;exports.locatorFor=O.locatorFor;exports.newDashboardSource=O.newDashboardSource;exports.newDocumentProblem=O.newDocumentProblem;exports.newNotebookSource=O.newNotebookSource;exports.reportPathFor=O.reportPathFor;exports.reportPathForTitle=O.reportPathForTitle;exports.slugFor=O.slugFor;exports.slugOrFallback=O.slugOrFallback;exports.useDocumentChoices=O.useDocumentChoices;exports.DashboardBuilder=ky;exports.DashboardEditor=_y;exports.NotebookEditor=Sy;exports.ReportBuilder=Oa;exports.ReportEditor=Ea;exports.buildCatalog=Yd;exports.readDashboardDocument=Cr;exports.readFailed=Er;exports.readReportTagOfText=Cm;exports.spliceDashboardDocument=Kd;exports.spliceFailed=zs;