@malloy-publisher/sdk 0.9.13 → 0.9.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builder/index.cjs.js +67 -67
- package/dist/builder/index.es.js +3267 -3264
- package/dist/components/ReportBuilder/EditorSurface.d.ts +8 -1
- package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
- package/package.json +1 -1
- package/src/components/ReportBuilder/EditorSurface.tsx +16 -8
- package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +22 -0
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),S=require("../useCompiledDocument-D0OAMejE.cjs.js"),$=require("@mui/material"),k=require("react"),ke=require("../ServerProvider-BIFPCzTD.cjs.js"),he=require("../text-entry-BJwltZiy.cjs.js"),Ju=require("react-dom"),ef=require("@malloydata/malloy-tag"),Fl=require("@tanstack/react-query"),zl=S.createSvgIcon(m.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),Wl=S.createSvgIcon(m.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),tf=S.createSvgIcon(m.jsx("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}));function Nl(e){const{theme:t}=ke.usePublisherTheme(),n=t.ui,[r,s]=k.useState(null),{status:i,draftKeptAt:o,discard:a,restored:c,dismissRestored:f}=e,d=c!==void 0&&!c.pending&&i==="unsaved"?c:void 0,l=i==="saved"?"Saved":i==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",u=d?`Restored your unsaved edits from ${Ii(d.savedAt)}`:void 0,h=i==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,p=a!==void 0&&i==="unsaved",y=()=>{s(null),d&&f?.()},w=v=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:i==="saved"?v.palette.text.secondary:v.palette.text.primary,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...p?{"&:hover":{bgcolor:v.palette.action.hover}}:{}}),_=m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:i==="saved"?m.jsx(S.CheckIcon,{sx:{fontSize:16}}):m.jsx($.Box,{component:"span","data-restored":d?"true":void 0,sx:v=>({width:7,height:7,borderRadius:"50%",bgcolor:d?t.accent:i==="saving"||o!==void 0?v.palette.text.disabled:v.palette.warning.main,transition:`background-color ${S.MOTION_FAST}`})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:l}),m.jsx(S.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:p?"visible":"hidden"}})]}),g=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:nf,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[g,m.jsx($.Tooltip,{title:u??h,describeChild:!0,children:p?m.jsx($.ButtonBase,{className:S.reportClasses.saveStatus,"aria-label":l,...u?{"aria-description":u}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:v=>s(v.currentTarget),sx:w,children:_}):m.jsx($.Box,{component:"span",className:S.reportClasses.saveStatus,sx:w,children:_})}),m.jsxs($.Menu,{className:S.reportClasses.menu,anchorEl:r,open:r!==null,onClose:y,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${S.edgeColor(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(u!==void 0||o!==void 0)&&m.jsx($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:u??`Kept in this browser at ${Ii(o)}`}),m.jsxs($.MenuItem,{onClick:()=>{s(null),a?.()},sx:{mx:.5,borderRadius:n.radius.control,gap:1.25,color:"error.main","&.Mui-focusVisible":{outline:"none",bgcolor:"action.hover"}},children:[m.jsx(tf,{fontSize:"small"}),"Discard edits"]})]})]})}function Ii(e){const t=new Date(e);return new Date().toDateString()===t.toDateString()?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}const nf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},ji=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Xt=ji?"⌘":"Ctrl+",Pa=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},ui=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function rf(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=ji?i.metaKey:i.ctrlKey,c=i.key.toLowerCase();if(i.key==="Escape"){if(Pa(i.target)||ui(i.target))return;o.escape();return}if(Pa(i.target)){if(a&&c==="s"){if(i.preventDefault(),!o.save||ui(i.target))return;i.target.blur(),r(!0)}return}if(ui(i.target)){a&&c==="s"&&i.preventDefault();return}if(a&&c==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!ji&&a&&c==="y"){i.preventDefault(),o.redo();return}if(a&&c==="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 vr=(e,t,n=ke.DEFAULT_UI)=>({height:n.size.control,minHeight:n.size.control,px:1.5,borderRadius:n.radius.control,boxShadow:"none",...n.type.control,"&:hover":{boxShadow:"none"},"& .MuiButton-startIcon":{mr:.5,"& svg":{fontSize:18}},"&.MuiButton-outlined":{borderColor:e,"&:hover":{borderColor:t}}}),_s=(e=ke.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),ks={height:20,alignSelf:"center",mx:.5,my:0},Ss=(e,t=ke.DEFAULT_UI)=>({height:t.size.control,boxSizing:"border-box",borderRadius:t.radius.control,border:`1px solid ${e}`,overflow:"hidden",bgcolor:"background.paper","& .MuiToggleButton-root":{border:"none",borderRadius:"0 !important",m:"0 !important",px:1.5,py:0,height:"100%",...t.type.control,color:"text.secondary","& + .MuiToggleButton-root":{borderLeft:`1px solid ${e}`},"&:hover":{bgcolor:"action.hover"},"&.Mui-selected, &.Mui-selected:hover":{bgcolor:"action.selected",color:"text.primary"}}}),Pi={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function sf({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:c,saveButton:f,actions:d,onAddTile:l,onExit:u,saveStatus:h}){const{theme:p}=ke.usePublisherTheme(),y=S.edgeColor(p.cardBorder),w=S.hoverEdgeColor(p.cardBorder,p.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[l&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),onClick:l,"aria-label":"Add tile",sx:vr(y,w,p.ui),children:"Tile"}),l&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:_s(p.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:_s(p.ui),children:m.jsx(zl,{fontSize:"small"})})})}),(d||o||u)&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),d,o&&h&&m.jsx(Nl,{...h}),o?m.jsx($.Tooltip,{title:s?`Save (${Xt}S) · ${c??Pi[a]}`:c??Pi[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:f,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{...vr(y,w,p.ui),minWidth:88},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&m.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"}),u&&m.jsx(S.SecondaryButton,{label:"Close",icon:m.jsx(S.CheckIcon,{}),onClick:u})]})}const of={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Gl(e,t,n){const s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(o=>{const a=s(o);return{value:o,label:of[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ra(e){return e.description??S.readableName(e.name)}const af={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},Yr=(e,t)=>`${e}\0${t}`;function lf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o,renderPreview:a}){const{theme:c}=ke.usePublisherTheme(),f=c.ui,d=S.edgeColor(c.cardBorder),l=k.useMemo(()=>n?.sources??[],[n]),[u,h]=k.useState(""),[p,y]=k.useState(),[w,_]=k.useState(""),[g,v]=k.useState("default"),x=k.useRef(null),b=k.useMemo(()=>{const I=new Set(t.sources.map(z=>z.base));return[...l].sort((z,V)=>Number(I.has(V.name))-Number(I.has(z.name)))},[l,t]),T=b.filter(I=>I.views.length>0),C=b.filter(I=>I.views.length===0),M=k.useMemo(()=>new Map(T.flatMap(I=>I.views.map(z=>[Yr(I.name,z.name),{source:I,view:z,key:Yr(I.name,z.name)}]))),[T]),E=k.useMemo(()=>T.map(I=>({key:I.name,label:I.name,...I.description?{detail:I.description}:{},entries:I.views.map(z=>({key:Yr(I.name,z.name),name:z.name,title:Ra(z),...z.chart?{chart:z.chart}:{}}))})),[T]),O=p===void 0?void 0:M.get(p);k.useEffect(()=>{if(!e)return;h(""),_(""),v("default");const I=T[0]?.views[0];y(I&&T[0]?Yr(T[0].name,I.name):void 0)},[e]);const P=O?[O.source.name,O.view.name].filter(I=>!he.isBareName(I)).map(I=>`"${I}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,A=O!==void 0&&P===void 0,L=O?Ra(O.view):"",W=g!=="default"&&O?{chart:g,chartCarried:O.view.chart?[O.view.chart]:[]}:{},U=(I=O)=>{if(!I||![I.source.name,I.view.name].every(he.isBareName))return;const z=I.key===O?.key;i({base:I.source.name,modelPath:I.source.modelPath,...I.source.exporters?{exporters:I.source.exporters}:{},view:I.view.name,...z&&w.trim()?{label:w.trim()}:{},...z?W:{},colspan:Math.ceil(r/2)})},N=O?Gl(O.view,g).filter(I=>I.value!=="custom"&&I.disabled!==!0):[];return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:x,title:"Add a tile",description:"Pick a view from this package. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx($.Button,{onClick:s,children:"Cancel"}),m.jsx($.Button,{variant:"contained",disabled:!A,onClick:()=>U(),children:"Add tile"})]}),children:m.jsxs($.Box,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${d}`,borderBottom:`1px solid ${d}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx($.Box,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${d}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(S.ViewPicker,{groups:E,query:u,onQuery:h,picked:O?.key,onPick:I=>{y(I),v("default")},onTake:I=>U(M.get(I)),searchRef:x,empty:m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,p:2},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}),footer:C.length>0&&m.jsxs($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",C.map(I=>I.name).join(", "),"."]})})}),m.jsx($.Box,{sx:I=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${I.palette.text.primary} 3%, ${I.palette.background.paper})`}),children:O?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:I=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${d}`,bgcolor:I.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${I.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:O.source.name,modelPath:O.source.modelPath,view:O.view.name,label:w.trim()||L,...g!=="default"?W:{},givens:O.source.givens})}):m.jsxs($.Box,{sx:I=>({flex:1,border:`1px solid ${d}`,borderRadius:f.radius.tile,bgcolor:I.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(S.ChartGlyph,{chart:O.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[O.source.name," → ",O.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:L,value:w,onChange:I=>_(I.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs($.Box,{children:[m.jsx($.Typography,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($.ToggleButtonGroup,{size:"small",exclusive:!0,value:g,"aria-label":"Chart",onChange:(I,z)=>{z!==null&&v(z)},sx:{...Ss(d,f),"& .MuiToggleButton-root":{...Ss(d,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:N.map(I=>m.jsx($.ToggleButton,{value:I.value,children:I.label},I.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:O.view.chart?`The view declares ${af[O.view.chart]??"a chart"}.`:"The view declares no chart, so it shows as a table."})]}),P&&m.jsx($.Typography,{variant:"body2",color:"error",children:P})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const Ie=e=>e.kind==="text",oe=e=>e.kind!=="text",Qn=e=>oe(e)?e.label??e.name:e.name,We=e=>Ie(e)?`text.${e.name}`:`${e.source}.${e.name}`;function cf(e,t,{modelPath:n,textHeld:r,widths:s,insertAt:i}){t.modelPath&&!r&&(e.imports=S.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Vl(e,t.base),a=Ri(e,o.name,t.view);e.tiles.splice(i??e.tiles.length,0,{name:a,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 Vl(e,t,{unscoped:n=!1}={}){const r=e.sources.find(a=>a.base===t&&(!n||!a.scopedBy?.length));if(r)return r;const s=new Set(e.sources.map(a=>a.name));let i=`${t}_tiles`;for(let a=2;s.has(i);a++)i=`${t}_tiles_${a}`;const o={name:i,base:t};return e.sources.push(o),o}function Ri(e,t,n){const r=new Set(e.tiles.filter(oe).filter(i=>i.source===t).map(i=>i.name));let s=`${n}_tile`;for(let i=2;r.has(s);i++)s=`${n}_tile_${i}`;return s}function $s(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function df(e,t){const n=e.tiles[t];if(!n||!oe(n)||$s(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...i}=structuredClone(n);r={...i,name:Ri(e,n.source,n.declaration.from)}}else{const i=e.sources.find(o=>o.name===n.source)??Vl(e,n.source,{unscoped:!0});r={name:Ri(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}return e.tiles.splice(t+1,0,r),t+1}const Xr="self";function uf({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:i,onClose:o,onApply:a}){const{theme:c}=ke.usePublisherTheme(),f=c.ui,[d,l]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const g=(t.drills??[]).filter(v=>v.source===n.name);l((n.dimensions??[]).map(v=>{const x=g.find(b=>b.name===v.name);return{name:v.name,expression:v.expression,to:x?.to??[],given:x?.given??""}}))},[e,n,t]);const u=(g,v)=>l(x=>x.map((b,T)=>{if(T!==g)return b;const C={...b};return v(C),C})),h=[Xr,...s.filter(g=>g!==Xr)],p=g=>g===Xr?"This report":g,y=()=>{n&&(a(d.filter(g=>g.to.length>0).map(g=>({source:n.name,name:g.name,expression:g.expression,to:g.to,...g.given?{given:g.given}:{}}))),o())},w=S.edgeColor(c.cardBorder),_=(g,v)=>u(g,x=>{v?x.to=x.lastTo?.length?x.lastTo:[Xr]:(x.lastTo=x.to,x.to=[])});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[i&&m.jsxs($.Box,{component:"span",sx:{fontWeight:f.type.label.fontWeight},children:[i," ·"," "]}),"A click on a cell sets a filter to its value, on this report or on the one it opens."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Button,{variant:"contained",onClick:y,disabled:d.length===0,children:"Apply"})]}),children:d.length===0?m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A click is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",m.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx($.Box,{role:"list","aria-label":"Dimensions",children:d.map((g,v)=>{const x=g.to.length>0;return m.jsxs($.Box,{role:"listitem",sx:{display:"grid",gridTemplateColumns:{xs:"auto minmax(0, 1fr)",sm:"auto minmax(0, 0.9fr) minmax(0, 1.6fr)"},alignItems:"center",columnGap:1.5,rowGap:1,py:1.25,borderTop:v===0?"none":`1px solid ${w}`},children:[m.jsx($.Switch,{size:"small",checked:x,onChange:b=>_(v,b.target.checked),slotProps:{input:{"aria-label":`${g.name} is clickable`}}}),m.jsxs($.Box,{sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:ff(g.name)}),m.jsxs($.Box,{title:g.expression,sx:{...f.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[g.name," is ",g.expression]})]}),x?m.jsxs($.Stack,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...f.type.control},children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx($.TextField,{select:!0,size:"small",value:g.to,inputProps:{"aria-label":`Where ${g.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.map(p).join(", ")},onChange:b=>u(v,T=>{const C=b.target.value,M=Array.isArray(C)?C:String(C).split(",").filter(Boolean);M.length===0&&(T.lastTo=T.to),T.to=M}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:h.map(b=>m.jsxs($.MenuItem,{value:b,children:[m.jsx($.Checkbox,{size:"small",checked:g.to.includes(b),sx:{p:0,mr:1}}),m.jsx($.ListItemText,{primary:p(b)})]},b))}),m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs($.TextField,{select:!0,size:"small",value:g.given,inputProps:{"aria-label":`Control ${g.name} sets`},SelectProps:{displayEmpty:!0,renderValue:b=>b===""?g.name:String(b)},onChange:b=>u(v,T=>{T.given=b.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx($.MenuItem,{value:"",children:m.jsx($.ListItemText,{primary:g.name,secondary:"Named like the dimension"})}),r.map(b=>m.jsx($.MenuItem,{value:b,children:b},b))]})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},g.name)})})})}function ff(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const hf=S.createSvgIcon(m.jsx("path",{d:"M12 4c4.41 0 8 3.59 8 8s-3.59 8-8 8-8-3.59-8-8 3.59-8 8-8m0-2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 13-4-4h8z"})),pf=S.createSvgIcon(m.jsx("path",{d:"M11 7H2v2h9zm0 8H2v2h9zm5.34-4L12.8 7.46l1.41-1.41 2.12 2.12 4.24-4.24L22 5.34zm0 8-3.54-3.54 1.41-1.41 2.12 2.12 4.24-4.24L22 13.34z"})),gf=S.createSvgIcon(m.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 16H5V10h14zm0-12H5V6h14zm-7 5h5v5h-5z"})),mf=S.createSvgIcon(m.jsx("path",{d:"M19.5 9.5c-1.03 0-1.9.62-2.29 1.5h-2.92c-.39-.88-1.26-1.5-2.29-1.5s-1.9.62-2.29 1.5H6.79c-.39-.88-1.26-1.5-2.29-1.5C3.12 9.5 2 10.62 2 12s1.12 2.5 2.5 2.5c1.03 0 1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5s1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5 1.38 0 2.5-1.12 2.5-2.5s-1.12-2.5-2.5-2.5"})),vf=S.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),yf=S.createSvgIcon(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function bf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of oe(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 Ts(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function xf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function yr(e,t){const n=xf(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 Ai(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 wf(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const _f=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function kf(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=he.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 Sf=[{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 er(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 Li=e=>oe(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function $f(e,t){return e.tiles.map(n=>{const r=(oe(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}:Ts(t.type)!==void 0?{op:Ts(t.type)}:{}}})}function Tf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Li(i))return;const o=(i.filters??[]).filter(c=>c.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?i.filters=a:delete i.filters})}function Ef(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 Cf(e,t){for(const r of e.tiles){if(!oe(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 Bi=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function Of({open:e,document:t,control:n,available:r,takenNames:s=[],fieldsFor:i,onApply:o}){const a=k.useRef(n);e&&(a.current=n);const c=e?n:a.current,f=c!==void 0,[d,l]=k.useState({kind:"new"}),[u,h]=k.useState(""),[p,y]=k.useState("select"),[w,_]=k.useState(""),[g,v]=k.useState(""),[x,b]=k.useState([]),[T,C]=k.useState(!1),[M,E]=k.useState(!1),O=D=>t.sources.find(R=>R.name===D.source)?.base??D.source;k.useEffect(()=>{if(e)if(E(n!==void 0),n){l({kind:"existing",name:n.name}),h(n.label??"");const D=$f(t,n);b(D);const R=D.filter(F=>F.include),j=new Set(R.map(F=>F.field));v(j.size===1?R[0].field:n.field??""),C(j.size>1)}else l({kind:"new"}),h(""),y("select"),v(""),_(new Date().toISOString().slice(0,10)),b(t.tiles.map(D=>({include:Li(D),field:""}))),C(!1)},[e,n,t]);const P=k.useMemo(()=>[...(t.localGivens??[]).map(D=>D.name),...r.map(D=>D.name),...s],[t,r,s]),A=k.useMemo(()=>g.trim()?kf(g.trim(),P):"",[g,P]),L=d.kind==="existing"?n??r.find(D=>D.name===d.name):A?{name:A,type:er({name:A,label:u,kind:p,field:g}).type}:void 0,W=L?.type!==void 0&&!L.type.startsWith("filter<"),U=x.find(D=>D.include)?.op??Ts(L?.type),N=(D,R)=>{E(!0),b(j=>j.map((F,J)=>J===D?{...F,...R}:F))},I=D=>{E(!0),b(R=>R.map(j=>({...j,op:D})))},z=D=>{const R=Ts(D);b(j=>j.map(({op:F,...J})=>R?{...J,op:R}:J))},V=D=>{E(!0),l({kind:"existing",name:D.name}),v(D.field??""),z(D.type)},B=D=>{E(!0),y(D),z(er({name:"X",label:u,kind:D,field:g}).type)},G=t.tiles.map(Li),Q=G.filter(Boolean).length,Z=x.filter((D,R)=>D.include&&G[R]).length,X=t.tiles.filter((D,R)=>(x[R]?.include??!1)&&G[R]&&oe(D)),H=X.length>0?X:t.tiles.filter((D,R)=>G[R]&&oe(D)),Pe=k.useMemo(()=>{const D=new Map;let R=!1;for(const j of H){const F=i?.(j);if(F){R=!0;for(const J of F)D.has(J.name)||D.set(J.name,J)}}return R?[...D.values()]:void 0},[x,t.tiles,i]),ve=(()=>{const D=g.trim();for(const R of X){const j=i?.(R);if(!j||j.some(F=>F.name===D))return O(R)}return X[0]?O(X[0]):t.sources[0]?.base})(),pe=D=>{E(!0),b(R=>R.map((j,F)=>({...j,include:D&&G[F]})))},Se=k.useMemo(()=>T?x:x.map(D=>({...D,field:g})),[T,x,g]),ee=D=>{for(const R of H){const j=i?.(R)?.find(F=>F.name===D.trim());if(j?.type)return j.type}},Re=D=>yr(L?.type,D.type),ce=(D,R)=>{if(D.trim()==="")return"Pick the field this filter compares.";const j=R?i?.(R):void 0;if(!j)return;const F=j.find(J=>J.name===D.trim());if(!F)return`Not a field of ${R?O(R):"the tiles' source"}.`;if(F.type&&!yr(L?.type,F.type))return`${D.trim()} is ${Ai(F.type)}; this filter compares ${Ai(L?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},ie=D=>{if(E(!0),v(D),f||d.kind!=="new")return;const R=ee(D),j=er({name:"X",label:u,kind:p,field:D}).type;R&&!yr(j,R)&&B(wf(R))},$e=D=>{const R=t.tiles[D];return R&&oe(R)?R:void 0},de=Se.map((D,R)=>D.include&&G[R]?ce(D.field,$e(R)):void 0),xe=de.every(D=>D===void 0),we=M?de:de.map(()=>{}),Ge=M&&!T&&Z>0?X.map(D=>ce(g,D)).find(Boolean):void 0,me=L!==void 0&&xe&&(d.kind==="existing"||g.trim()!==""&&A!==""),Ae=()=>{if(!(!L||!me))if(d.kind==="new")o(L.name,Se,er({name:L.name,label:u.trim()||Bi(L.name),kind:p,field:g.trim(),...ve?{source:ve}:{},...w?{dateDefault:w}:{}}));else if(n?.origin==="dashboard"&&n.local){const D=u.trim(),R=D!==(n.local.label??"");o(L.name,Se,R?{...n.local,...D?{label:D}:{}}:void 0)}else o(L.name,Se)},Fe=f&&c.origin==="model";return{editing:f,shown:c,fromModel:Fe,source:d,setSource:l,label:u,setLabel:h,kind:p,dateDefault:w,setDateDefault:_,field:g,rows:x,setRows:b,perTile:T,setPerTile:C,newName:A,target:L,valueTyped:W,commonOp:U,setRow:N,setCommonOp:I,pickExisting:V,pickKind:B,bindable:G,bindableCount:Q,included:Z,commonFields:Pe,setAll:pe,accepts:Re,pickField:ie,rowProblems:we,commonProblem:Ge,canApply:me,apply:Ae}}function Aa({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:c,autoFocus:f,placeholder:d,inputRef:l,sx:u}){const h=k.useMemo(()=>(n??[]).filter(y=>r?.(y)??!0).map(y=>y.name),[n,r]),p=k.useMemo(()=>new Map((n??[]).map(y=>[y.name,y.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(y,w)=>t(w),value:e,onChange:(y,w)=>t(typeof w=="string"?w:""),disabled:c,disableClearable:!0,renderOption:(y,w)=>k.createElement("li",{...y,key:w},m.jsx(Ba,{type:p.get(w)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:w})),renderInput:y=>m.jsx($.TextField,{...y,label:s,placeholder:d,autoFocus:f,...l?{inputRef:l}:{},error:o,helperText:a,InputLabelProps:{...y.InputLabelProps,shrink:!0},InputProps:{...y.InputProps,startAdornment:p.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Ba,{type:p.get(e.trim())})}):void 0},inputProps:{...y.inputProps,"aria-label":i}}),sx:u})}const Df=e=>e&&oe(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 Mf({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:i,onClose:o,onApply:a,onRemove:c}){const{theme:f}=ke.usePublisherTheme(),d=f.ui,{editing:l,shown:u,fromModel:h,source:p,setSource:y,label:w,setLabel:_,kind:g,dateDefault:v,setDateDefault:x,field:b,rows:T,setRows:C,perTile:M,setPerTile:E,newName:O,target:P,valueTyped:A,commonOp:L,setRow:W,setCommonOp:U,pickExisting:N,pickKind:I,bindable:z,bindableCount:V,included:B,commonFields:G,setAll:Q,accepts:Z,pickField:X,rowProblems:H,commonProblem:Pe,canApply:ve,apply:pe}=Of({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:i,onApply:a}),Se=k.useRef(null),ee=S.edgeColor(f.cardBorder),Re=S.hoverEdgeColor(f.cardBorder,f.tileTitle),[ce,ie]=k.useState(!1),[$e,de]=k.useState(!1);k.useEffect(()=>{e?de(!0):ie(!1)},[e]),k.useEffect(()=>{$e&&(de(!1),ie(l&&B<V))},[$e]),k.useEffect(()=>{M&&ie(!0)},[M]);const xe=G?.find(D=>D.name===b.trim())?.type,we=D=>{if(!xe)return;const R=er({name:"X",label:w,kind:D,field:b}).type;return yr(R,xe)?void 0:`${b.trim()} is ${Ai(xe)}, which this control cannot filter.`},Ge=w.trim()||(O?Bi(O):"Filter"),me=g==="number"?"Any":g==="date"?v?new Date(`${v}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ae={...Ss(ee,d),alignSelf:"flex-start","& .MuiToggleButton-root":{...Ss(ee,d)["& .MuiToggleButton-root"],textTransform:"none"}},Fe=(D,R,j)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:D??">=",onChange:F=>R(F.target.value),inputProps:{"aria-label":j},sx:{width:130},children:_f.filter(F=>F.op!=="~").map(F=>m.jsx($.MenuItem,{value:F.op,children:F.label},F.op))});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:Se},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs($.Box,{component:"span",sx:{fontFamily:d.font.mono},children:["$",u.name]}),h?" · declared in the model, so its label and options are set there":" · declared in this report"]}):"A filter on the page, and the tiles it filters.",actions:m.jsxs(m.Fragment,{children:[l&&m.jsx($.Button,{color:"error",startIcon:m.jsx(S.DeleteOutlineIcon,{}),onClick:()=>c(u.name),sx:D=>({mr:"auto",color:S.dangerTextColor(D)}),children:"Remove filter"}),m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Tooltip,{title:ve||P===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",onClick:pe,disabled:!ve,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:p.kind,onChange:(D,R)=>{R==="new"?y({kind:"new"}):R==="existing"&&r[0]&&N(r[0])},"aria-label":"Where the filter comes from",sx:Ae,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!l&&p.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:p.name,onChange:D=>{const R=r.find(j=>j.name===D.target.value);R&&N(R)},children:r.map(D=>m.jsxs($.MenuItem,{value:D.name,children:[D.label??D.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",D.name]})]},D.name))}):null,m.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:h?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!M&&m.jsx(Aa,{value:b,onChange:X,fields:G,accepts:Z,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:Se,error:Pe!==void 0,helperText:Pe??(!l&&O?`Declared as $${O}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:O?Bi(O):"",value:w,onChange:D=>_(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),A&&!M&&Fe(L,U,"Comparison"),!l&&p.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Control"}),m.jsx($.Box,{role:"radiogroup","aria-label":"Filter kind",sx:{display:"grid",gridTemplateColumns:{xs:"repeat(3, minmax(0, 1fr))",sm:"repeat(5, minmax(0, 1fr))"},gap:1},children:Sf.map(D=>{const R=D.kind===g,j=we(D.kind);return m.jsx($.Tooltip,{title:j??D.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":R,"aria-label":D.label,"aria-disabled":j!==void 0,onClick:()=>{j===void 0&&I(D.kind)},sx:F=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:d.radius.tile,border:`1px solid ${R?f.accent:ee}`,boxShadow:R?`0 0 0 1px ${f.accent}`:"none",bgcolor:R?`color-mix(in srgb, ${f.accent} 6%, ${F.palette.background.paper})`:F.palette.background.paper,color:R?f.accent:F.palette.text.secondary,opacity:j?.45:1,cursor:j?"default":"pointer",transition:`border-color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"&:hover":j||R?{}:{borderColor:Re}}),children:[m.jsx(jf,{kind:D.kind}),m.jsx($.Box,{component:"span",sx:{...d.type.caption,fontWeight:R?600:500,color:R?f.accent:"text.primary",textAlign:"center"},children:If[D.kind]})]})},D.kind)})}),g==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:v,onChange:D=>x(D.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${ee}`,borderRadius:d.radius.tile,overflow:"hidden"},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(yf,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs($.Typography,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:B===V&&V>0?`Applies to all ${B} tile${B===1?"":"s"}`:`Applies to ${B} of ${V} tile${V===1?"":"s"}`}),!M&&b.trim()!==""&&B>0&&m.jsxs($.Box,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx($.Box,{component:"span",sx:{...d.type.code},children:b.trim()})]})]}),!M&&m.jsx($.Button,{size:"small","aria-expanded":ce,onClick:()=>ie(D=>!D),children:ce?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:ce,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${ee}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:V>0&&B===V,indeterminate:B>0&&B<V,disabled:V===0,onChange:D=>Q(D.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx($.Button,{size:"small",onClick:()=>{M||C(D=>D.map(R=>({...R,field:b}))),E(D=>!D)},children:M?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:M?1:0},children:t.tiles.map((D,R)=>{if(!oe(D))return null;const j=T[R],F=D.label??D.name,J=M?H[R]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:M?"flex-start":"center",opacity:z[R]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!z[R],checked:(j?.include??!1)&&z[R],inputProps:{"aria-label":`Filter ${F}`},onChange:q=>W(R,{include:q.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:M?1:0},noWrap:!0,children:F}),z[R]?M&&m.jsxs(m.Fragment,{children:[A&&Fe(j?.op,q=>W(R,{op:q}),`Comparison for ${F}`),m.jsx(Aa,{value:j?.field??"",onChange:q=>W(R,{field:q}),fields:i?.(D),accepts:Z,label:"Field",ariaLabel:`Field for ${F}`,disabled:!j?.include,error:J!==void 0,helperText:J,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:Df(t.tiles[R]).reason})]},`${D.source}.${D.name}`)})})]})})]}),B===0&&m.jsx($.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!h&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Preview"}),m.jsx($.Box,{sx:D=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:d.radius.tile,bgcolor:D.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:D=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:d.radius.control,border:`1px solid ${ee}`,bgcolor:D.palette.background.paper,...d.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:Ge}),m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:me}),m.jsx(S.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function La({children:e}){const t=ke.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const If={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function jf({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(hf,{sx:t});case"multiselect":return m.jsx(pf,{sx:t});case"text":return m.jsx(vf,{sx:t});case"number":return m.jsx(mf,{sx:t});case"date":return m.jsx(gf,{sx:t})}}function Ba({type:e}){const t=e?.replace(/_type$/,""),n=t==="string"?"Abc":t==="number"?"#":t==="date"||t==="timestamp"?"Date":t==="boolean"?"T/F":void 0,r=ke.usePublisherTheme().theme.ui;return n?m.jsx($.Box,{component:"span","aria-hidden":!0,sx:s=>({fontFamily:r.font.mono,fontSize:10,fontWeight:r.type.label.fontWeight,color:s.palette.text.secondary,bgcolor:s.palette.action.hover,borderRadius:"4px",px:.5,py:.25,minWidth:22,textAlign:"center",flex:"none"}),children:n}):null}const Pf=S.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Ul(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:d=>i(l=>{if(l===void 0)return l;const u=structuredClone(l);return d(u),u}),apply:d=>{if(s===void 0)return;const l=structuredClone(s);d(l),i(l),JSON.stringify(l)!==JSON.stringify(e)&&n(l)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const Rf=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.`,Af="Declared on its source, so its chart is set in the model.";function Lf({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:i,duplicateBlocked:o,view:a}){const{theme:c}=ke.usePublisherTheme(),f=c.ui,{draft:d,apply:l,close:u}=Ul(t,e!==null,r,n),[h,p]=k.useState(void 0),y=d!==void 0&&oe(d)?d:void 0,w=y!==void 0&&y.declaration.kind!=="inherited",_=P=>l(A=>{oe(A)&&P(A)}),g=k.useRef(void 0),v=e!==null;k.useEffect(()=>{v?g.current=t&&oe(t)?t.chart:void 0:p(void 0)},[v]);const x=y?.chart??"default",b=Gl(a,x),T=y?w?y.chart==="custom"?Rf(y.chartLines):void 0:Af:void 0,C=P=>_(A=>{const L=g.current;P===(L??"default")?(L===void 0?delete A.chart:A.chart=L,delete A.chartCarried):(A.chart=P,a?A.chartCarried=a.chart?[a.chart]:[]:delete A.chartCarried)}),M=w?s?void 0:"Its source declares no dimension a click could filter by.":void 0,E=P=>A=>p({kind:P,anchor:A.currentTarget}),O=(P,A,L)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:P,...L?{secondary:L}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),A&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:A})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:S.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":y?`${y.source} ${y.name}`:"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:f.radius.menu,border:`1px solid ${S.edgeColor(c.cardBorder)}`,boxShadow:f.shadow.menu}}},children:[y&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":h?.kind==="chart",disabled:T!==void 0,onClick:E("chart"),onKeyDown:P=>{P.key==="ArrowRight"&&T===void 0&&p({kind:"chart",anchor:P.currentTarget})},children:[O("Chart",T?void 0:b.find(P=>P.value===x)?.label,T),m.jsx(Pf,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),w&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:M!==void 0,onClick:()=>{u(),s?.()},children:O("Clickable cells…",void 0,M)}),y&&i&&m.jsx($.MenuItem,{disabled:o!==void 0,onClick:()=>{u(),i()},children:O("Duplicate",void 0,o)}),y?.declaration.kind==="opaque"&&m.jsxs($.Typography,{variant:"body2",sx:{color:c.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",y.declaration.why,", so a filter has no single place to go."]}),y&&m.jsx($.Divider,{}),y&&m.jsxs($.Box,{"aria-hidden":!0,sx:{px:2,py:.5,...f.type.code,color:"text.secondary"},children:[y.source," → ",y.name]})]}),m.jsx($.Menu,{className:S.reportClasses.menu,open:h?.kind==="chart",anchorEl:h?.anchor??null,onClose:()=>p(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:P=>{P.key==="ArrowLeft"&&(P.preventDefault(),p(void 0))}},children:b.filter(P=>P.value!=="custom").map(P=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":P.value===x,disabled:P.disabled===!0,onClick:()=>{C(P.value),p(void 0)},children:[m.jsx($.ListItemText,{primary:P.label,...P.reason?{secondary:P.reason}:{}}),P.value===x&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(S.CheckIcon,{fontSize:"small",sx:{color:c.accent}})})]},P.value))})]})}const _n=e=>e.label??S.tileTitle(`${e.source} -> ${e.name}`);function Bf({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,exitDialog:c,renderViewPreview:f,takenGivenNames:d}){const{filterDialog:l,setFilterDialog:u}=s,{menu:h,setMenu:p}=i,[y,w]=k.useState(),_=h===void 0?void 0:e.document.tiles[h.index],g=_&&oe(_)?_:void 0,v=(()=>{if(!g||!t)return;const x=e.document.sources.find(T=>T.name===g.source)?.base??g.source,b=g.declaration.kind==="reference"?g.declaration.from:g.name;return t.sources.find(T=>T.name===x)?.views.find(T=>T.name===b)})();return m.jsxs(m.Fragment,{children:[m.jsx(Mf,{open:l!==void 0,document:e.document,...l?.control?{control:l.control}:{},available:s.available,...d?{takenNames:d}:{},...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>u(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),m.jsx(Lf,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>p(void 0),onCommit:x=>{const b=h?.index;b!==void 0&&e.update(T=>{T.tiles[b]=x})},view:v,onDuplicate:()=>{h&&i.duplicate(h.index)},...g&&$s(g)!==void 0?{duplicateBlocked:$s(g)}:{},...(e.document.sources.find(x=>x.name===g?.source)?.dimensions?.length??0)>0?{onDrills:()=>{w(g?_n(g):void 0),a(g?.source)}}:{}}),m.jsx(uf,{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??[],...y?{tileLabel:y}:{},onClose:()=>a(void 0),onApply:x=>e.update(b=>{const C=[...(b.drills??[]).filter(M=>M.source!==o),...x];C.length===0?delete b.drills:b.drills=C})}),m.jsx(S.UnsavedChangesDialog,{...c}),m.jsx(lf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText,...f?{renderPreview:f}:{}})]})}var Ff=Symbol.for("preact-signals");function Ys(){if(_t>1)_t--;else{var e,t=!1;for((function(){var s=Cs;for(Cs=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}})();xr!==void 0;){var n=xr;for(xr=void 0,Es++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&ql(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Es=0,_t--,t)throw e}}function Ce(e){if(_t>0)return e();Fi=++zf,_t++;try{return e()}finally{Ys()}}var br,ye=void 0;function te(e){var t=ye,n=br;ye=void 0,br=void 0;try{return e()}finally{ye=t,br=n}}var xr=void 0,_t=0,Es=0,zf=0,Fi=0,Cs=void 0,Os=0;function Hl(e){if(ye!==void 0){var t=e.n;if(t===void 0||t.t!==ye)return t={i:0,S:e,p:ye.s,n:void 0,t:ye,e:void 0,x:void 0,r:t},ye.s!==void 0&&(ye.s.n=t),ye.s=t,e.n=t,32&ye.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=ye.s,t.n=void 0,ye.s.n=t,ye.s=t),t}}function Qe(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Qe.prototype.brand=Ff;Qe.prototype.h=function(){return!0};Qe.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:te(function(){var r;(r=t.W)==null||r.call(t)}))};Qe.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&te(function(){var s;(s=t.Z)==null||s.call(t)}))}};Qe.prototype.subscribe=function(e){var t=this;return ct(function(){var n=t.value;te(function(){return e(n)})},{name:"sub"})};Qe.prototype.valueOf=function(){return this.value};Qe.prototype.toString=function(){return this.value+""};Qe.prototype.toJSON=function(){return this.value};Qe.prototype.peek=function(){var e=this;return te(function(){return e.value})};Object.defineProperty(Qe.prototype,"value",{get:function(){var e=Hl(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Es>100)throw new Error("Cycle detected");(function(n){_t!==0&&Es===0&&n.l!==Fi&&(n.l=Fi,Cs={S:n,v:n.v,i:n.i,o:Cs})})(this),this.v=e,this.i++,Os++,_t++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Ys()}}}});function In(e,t){return new Qe(e,t)}function ql(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 Kl(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 Jt(e,t){Qe.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Os-1,this.f=4}Jt.prototype=new Qe;Jt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Os))return!0;if(this.g=Os,this.f|=1,this.i>0&&!ql(this))return this.f&=-2,!0;var e=ye;try{Kl(this),ye=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 ye=e,Yl(this),this.f&=-2,!0};Jt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}Qe.prototype.S.call(this,e)};Jt.prototype.U=function(e){if(this.t!==void 0&&(Qe.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Jt.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(Jt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Hl(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Fa(e,t){return new Jt(e,t)}function Xl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){_t++;var n=ye;ye=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,To(e),r}finally{ye=n,Ys()}}}function To(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Xl(e)}function Wf(e){if(ye!==this)throw new Error("Out-of-order effect");Yl(this),ye=e,this.f&=-2,8&this.f&&To(this),Ys()}function jn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,br&&br.push(this)}jn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};jn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Xl(this),Kl(this),_t++;var e=ye;return ye=this,Wf.bind(this,e)};jn.prototype.N=function(){2&this.f||(this.f|=2,this.u=xr,xr=this)};jn.prototype.d=function(){this.f|=8,1&this.f||To(this)};jn.prototype.dispose=function(){this.d()};function ct(e,t){var n=new jn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Nf=Object.create,Eo=Object.defineProperty,Gf=Object.defineProperties,Vf=Object.getOwnPropertyDescriptor,Uf=Object.getOwnPropertyDescriptors,za=Object.getOwnPropertySymbols,Hf=Object.prototype.hasOwnProperty,qf=Object.prototype.propertyIsEnumerable,Kf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Pn=e=>{throw TypeError(e)},zi=(e,t,n)=>t in e?Eo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yf=(e,t)=>{for(var n in t||(t={}))Hf.call(t,n)&&zi(e,n,t[n]);if(za)for(var n of za(t))qf.call(t,n)&&zi(e,n,t[n]);return e},Xf=(e,t)=>Gf(e,Uf(t)),Wa=(e,t)=>Eo(e,"name",{value:t,configurable:!0}),Qf=e=>{var t;return[,,,Nf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],tr=e=>e!==void 0&&typeof e!="function"?Pn("Function expected"):e,Zf=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:i=>n._?Pn("Already initialized"):s.push(tr(i||null))}),Zl=(e,t)=>zi(t,Kf("metadata"),e[3]),Ft=(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},Rn=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,y=Ql[l+5],w=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&Vf(l<4?s:{get[n](){return st(this,i)},set[n](x){return Dt(this,i,x)}},n));l?h&&l<4&&Wa(i,(l>2?"set ":l>1?"get ":"")+n):Wa(s,n);for(var v=r.length-1;v>=0;v--)f=Zf(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?x=>Jf(s,x):x=>n in x},l^3&&(d.get=h?x=>(l^1?st:eh)(x,s,l^4?i:g.get):x=>x[n]),l>2&&(d.set=h?(x,b)=>Dt(x,s,b,l^4?i:g.set):(x,b)=>x[n]=b)),a=(0,r[v])(l?l<4?h?i:g[y]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?tr(a)&&(l>4?w.unshift(a):l?h?i=a:g[y]=a:s=a):typeof a!="object"||a===null?Pn("Object expected"):(tr(o=a.get)&&(g.get=o),tr(o=a.set)&&(g.set=o),tr(o=a.init)&&w.unshift(o));return l||Zl(e,s),g&&Eo(s,n,g),h?l^4?i:g:s},Co=(e,t,n)=>t.has(e)||Pn("Cannot "+n),Jf=(e,t)=>Object(t)!==t?Pn('Cannot use the "in" operator on this value'):e.has(t),st=(e,t,n)=>(Co(e,t,"read from private field"),n?n.call(e):t.get(e)),nr=(e,t,n)=>t.has(e)?Pn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Dt=(e,t,n,r)=>(Co(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),eh=(e,t,n)=>(Co(e,t,"access private method"),n);function Wi(e,t){if(t){let n;return Fa(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Fa(e)}function ut(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)=>!ut(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=>!ut(e[i],t[i]))}return!1}function ne({get:e},t){return{init(n){return In(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function De(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Wi(e.bind(this)),n.set(this,r)),r.value}}function fi(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,Xf(Yf({},s),{enumerable:e}))})}}function Lr(...e){const t=e.map(n=>ct(n));return()=>t.forEach(n=>n())}var Jl,ec,tc,nc,rc,sc,Ke,Oo,hi,Ni,Gi,He,Do,pi,ic,Vi,Mo,gi,Ui,Hi;sc=[ne],rc=[ne],nc=[ne],tc=[fi()],ec=[fi()],Jl=[fi()];var en=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ft(Ke,5,this),nr(this,He),nr(this,Oo,Ft(Ke,8,this)),Ft(Ke,11,this),nr(this,Do,Ft(Ke,12,this)),Ft(Ke,15,this),nr(this,Mo,Ft(Ke,16,this)),Ft(Ke,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return st(this,He,Ui)}get initial(){return st(this,He,Ni)}get previous(){return st(this,He,ic)}set current(e){const t=te(()=>st(this,He,Ui));e&&t&&this.equals(t,e)||Ce(()=>{st(this,He,Ni)||Dt(this,He,e,Gi),Dt(this,He,t,Vi),Dt(this,He,e,Hi)})}reset(e=this.defaultValue){Ce(()=>{Dt(this,He,void 0,Vi),Dt(this,He,e,Gi),Dt(this,He,e,Hi)})}};Ke=Qf();Oo=new WeakMap;He=new WeakSet;Do=new WeakMap;Mo=new WeakMap;hi=Rn(Ke,20,"#initial",sc,He,Oo),Ni=hi.get,Gi=hi.set;pi=Rn(Ke,20,"#previous",rc,He,Do),ic=pi.get,Vi=pi.set;gi=Rn(Ke,20,"#current",nc,He,Mo),Ui=gi.get,Hi=gi.set;Rn(Ke,2,"current",tc,en);Rn(Ke,2,"initial",ec,en);Rn(Ke,2,"previous",Jl,en);Zl(Ke,en);function mi(e){return te(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var zt,th=class{constructor(){nr(this,zt,new WeakMap)}get(e,t){var n;return e?(n=st(this,zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return st(this,zt).has(e)||st(this,zt).set(e,new Map),(r=st(this,zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=st(this,zt).get(e))==null?void 0:t.clear():void 0}};zt=new WeakMap;var nh=Object.create,oc=Object.defineProperty,rh=Object.getOwnPropertyDescriptor,Na=Object.getOwnPropertySymbols,sh=Object.prototype.hasOwnProperty,ih=Object.prototype.propertyIsEnumerable,ac=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Xs=e=>{throw TypeError(e)},Ga=Math.pow,qi=(e,t,n)=>t in e?oc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oh=(e,t)=>{for(var n in t||(t={}))sh.call(t,n)&&qi(e,n,t[n]);if(Na)for(var n of Na(t))ih.call(t,n)&&qi(e,n,t[n]);return e},ah=e=>{var t;return[,,,nh((t=e?.[ac("metadata")])!=null?t:null)]},lc=["class","method","getter","setter","accessor","field","value","get","set"],cc=e=>e!==void 0&&typeof e!="function"?Xs("Function expected"):e,lh=(e,t,n,r,s)=>({kind:lc[e],name:t,metadata:r,addInitializer:i=>n._?Xs("Already initialized"):s.push(cc(i||null))}),ch=(e,t)=>qi(t,ac("metadata"),e[3]),dh=(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,c,f,d=t&7,l=!1,u=!1,h=2,p=lc[d+5],y=e[h]||(e[h]=[]),w=(s=s.prototype,rh(s,n)),_=r.length-1;_>=0;_--)c=lh(d,n,a={},e[3],y),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(w[p],c),a._=1,cc(o)&&(w[p]=o);return w&&oc(s,n,w),s},uc=(e,t,n)=>t.has(e)||Xs("Cannot "+n),uh=(e,t,n)=>(uc(e,t,"read from private field"),t.get(e)),fh=(e,t,n)=>t.has(e)?Xs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),hh=(e,t,n,r)=>(uc(e,t,"write to private field"),t.set(e,n),n),it=class Ki{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ki(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 Ki(t,n)}},yt=class Wt{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,c=new Wt(s+t,r+n,i,o);return c.scale=oh({},a),c}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 it((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Wt))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 Wt?ph(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 Wt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],c=o==="x"?i.left:i.top,f=o==="x"?i.width:i.height;return a=="start"?c:a=="end"?c+f:c+f/2};return it.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Wt.from(t).intersectionRatio(Wt.from(n))}};function ph(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 fc,hc,Yi,ls,Br,Qs=class extends(Yi=en,hc=[De],fc=[De],Yi){constructor(t){const n=it.from(t);super(n,(r,s)=>it.equals(r,s)),dh(Br,5,this),fh(this,ls,0),this.velocity={x:0,y:0}}get delta(){return it.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=it.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-uh(this,ls),a=c=>Math.round(c/o*100);Ce(()=>{hh(this,ls,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(it.from(t)),this.velocity={x:0,y:0}}};Br=ah(Yi);ls=new WeakMap;dc(Br,2,"delta",hc,Qs);dc(Br,2,"direction",fc,Qs);ch(Br,Qs);function Xi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Ga(r,2)+Ga(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 pc=(e=>(e.Horizontal="x",e.Vertical="y",e))(pc||{}),gc=Object.values(pc),gh=Object.create,Io=Object.defineProperty,mh=Object.defineProperties,vh=Object.getOwnPropertyDescriptor,yh=Object.getOwnPropertyDescriptors,Ds=Object.getOwnPropertySymbols,mc=Object.prototype.hasOwnProperty,vc=Object.prototype.propertyIsEnumerable,yc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),An=e=>{throw TypeError(e)},Qi=(e,t,n)=>t in e?Io(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jo=(e,t)=>{for(var n in t||(t={}))mc.call(t,n)&&Qi(e,n,t[n]);if(Ds)for(var n of Ds(t))vc.call(t,n)&&Qi(e,n,t[n]);return e},Po=(e,t)=>mh(e,yh(t)),Va=(e,t)=>Io(e,"name",{value:t,configurable:!0}),bc=(e,t)=>{var n={};for(var r in e)mc.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&&vc.call(e,r)&&(n[r]=e[r]);return n},Ln=e=>{var t;return[,,,gh((t=e?.[yc("metadata")])!=null?t:null)]},xc=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?An("Function expected"):e,bh=(e,t,n,r,s)=>({kind:xc[e],name:t,metadata:r,addInitializer:i=>n._?An("Already initialized"):s.push(rr(i||null))}),tn=(e,t)=>Qi(t,yc("metadata"),e[3]),Y=(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},re=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,y=xc[l+5],w=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&vh(l<4?s:{get[n](){return Oe(this,i)},set[n](x){return tt(this,i,x)}},n));l?h&&l<4&&Va(i,(l>2?"set ":l>1?"get ":"")+n):Va(s,n);for(var v=r.length-1;v>=0;v--)f=bh(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?x=>xh(s,x):x=>n in x},l^3&&(d.get=h?x=>(l^1?Oe:wc)(x,s,l^4?i:g.get):x=>x[n]),l>2&&(d.set=h?(x,b)=>tt(x,s,b,l^4?i:g.set):(x,b)=>x[n]=b)),a=(0,r[v])(l?l<4?h?i:g[y]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?rr(a)&&(l>4?w.unshift(a):l?h?i=a:g[y]=a:s=a):typeof a!="object"||a===null?An("Object expected"):(rr(o=a.get)&&(g.get=o),rr(o=a.set)&&(g.set=o),rr(o=a.init)&&w.unshift(o));return l||tn(e,s),g&&Io(s,n,g),h?l^4?i:g:s},Ro=(e,t,n)=>t.has(e)||An("Cannot "+n),xh=(e,t)=>Object(t)!==t?An('Cannot use the "in" operator on this value'):e.has(t),Oe=(e,t,n)=>(Ro(e,t,"read from private field"),n?n.call(e):t.get(e)),le=(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),tt=(e,t,n,r)=>(Ro(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),wc=(e,t,n)=>(Ro(e,t,"access private method"),n);function _c(e,t){return{plugin:e,options:t}}function Fr(e){return t=>_c(e,t)}function Tr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var kc,Er,Ao,cs;kc=[ne];var qe=class{constructor(e,t){this.manager=e,this.options=t,le(this,Ao,Y(Er,8,this,!1)),Y(Er,11,this),le(this,cs,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return te(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=ct(e.bind(this));return Oe(this,cs).add(t),t}destroy(){Oe(this,cs).forEach(e=>e())}static configure(e){return _c(this,e)}};Er=Ln(null);Ao=new WeakMap;cs=new WeakMap;re(Er,4,"disabled",kc,qe,Ao);tn(Er,qe);var zr=class extends qe{},ds,vi=class{constructor(e){this.manager=e,this.instances=new Map,le(this,ds,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Tr).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,ds))if(!n.includes(r)){if(r.prototype instanceof zr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);tt(this,ds,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()}};ds=new WeakMap;function wh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Qr=[],fn,hn,_h=class extends qe{constructor(e){super(e),le(this,fn),le(this,hn),this.computeCollisions=this.computeCollisions.bind(this),tt(this,hn,In(Qr)),this.destroy=Lr(()=>{const t=this.computeCollisions(),n=te(()=>this.manager.dragOperation.position.current);if(t!==Qr){const r=Oe(this,fn);if(tt(this,fn,n),r&&n.x==r.x&&n.y==r.y)return}else tt(this,fn,void 0);Oe(this,hn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){te(()=>{e?Oe(this,hn).value=this.computeCollisions():tt(this,fn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Qr;const a=[],c=[];for(const f of e??n.droppables){if(f.disabled||s&&!f.accepts(s))continue;const d=t??f.collisionDetector;if(!d)continue;c.push(f),f.shape;const l=te(()=>d({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return c.length===0?Qr:(a.sort(wh),a)}get collisions(){return Oe(this,hn).value}};fn=new WeakMap;hn=new WeakMap;var Sc,$c,Tc,Lo,Ec,ft,Bo,bn,Fo,zo;Tc=[ne],$c=[ne],Sc=[ne];var St=class Nt{constructor(t,n){le(this,Bo,Y(ft,8,this)),Y(ft,11,this),le(this,bn),le(this,Fo,Y(ft,12,this)),Y(ft,15,this),le(this,zo,Y(ft,16,this)),Y(ft,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let c=s;tt(this,bn,In(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var f;return[()=>{const{id:d,manager:l}=this;if(d!==c)return c=d,l?.registry.register(this),()=>l?.registry.unregister(this)},...(f=r?.())!=null?f:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=Oe(this,bn).value;return(n=(t=Nt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=Nt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Oe(this,bn).peek();t!==s&&(Nt.pendingIdChanges||(Nt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return wc(i=Nt,Lo,Ec).call(i)})),Nt.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)}};ft=Ln(null);Lo=new WeakSet;Ec=function(){const e=St.pendingIdChanges;St.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)Oe(t,bn).value=n})};Bo=new WeakMap;bn=new WeakMap;Fo=new WeakMap;zo=new WeakMap;re(ft,4,"manager",Tc,St,Bo);re(ft,4,"data",$c,St,Fo);re(ft,4,"disabled",Sc,St,zo);le(St,Lo);tn(ft,St);St.pendingIdChanges=null;var Zs=St,Ua=class{constructor(){this.map=In(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,c]of n)if(c===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Lr(...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,Oc,Dc,Mc,Ic,jc,Zi,Ye,Wo,No,Go,bt=class extends(Zi=Zs,jc=[ne],Ic=[ne],Mc=[ne],Dc=[De],Oc=[De],Cc=[De],Zi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:c}=r,f=bc(r,["modifiers","type","sensors","plugins","effects"]);super(Po(jo({},f),{effects:()=>{var d;return[...(d=c?.())!=null?d:[],()=>{const{manager:l,plugins:u}=this;if(!(!l||!u))for(const h of u){const{plugin:p}=Tr(h);l.registry.plugins.register(p)}}]}}),n),Y(Ye,5,this),le(this,Wo,Y(Ye,8,this)),Y(Ye,11,this),le(this,No,Y(Ye,12,this)),Y(Ye,15,this),le(this,Go,Y(Ye,16,this,this.isDragSource?"dragging":"idle")),Y(Ye,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=f.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=Tr(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}};Ye=Ln(Zi);Wo=new WeakMap;No=new WeakMap;Go=new WeakMap;re(Ye,4,"type",jc,bt,Wo);re(Ye,4,"modifiers",Ic,bt,No);re(Ye,4,"status",Mc,bt,Go);re(Ye,2,"isDropping",Dc,bt);re(Ye,2,"isDragging",Oc,bt);re(Ye,2,"isDragSource",Cc,bt);tn(Ye,bt);var Pc,Rc,Ac,Lc,Bc,Fc,Ji,ze,Vo,Uo,Ho,qo,Ko,xt=class extends(Ji=Zs,Fc=[ne],Bc=[ne],Lc=[ne],Ac=[ne],Rc=[ne],Pc=[De],Ji){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,c=bc(r,["accept","collisionDetector","collisionPriority","type"]);super(c,n),Y(ze,5,this),le(this,Vo,Y(ze,8,this)),Y(ze,11,this),le(this,Uo,Y(ze,12,this)),Y(ze,15,this),le(this,Ho,Y(ze,16,this)),Y(ze,19,this),le(this,qo,Y(ze,20,this)),Y(ze,23,this),le(this,Ko,Y(ze,24,this)),Y(ze,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}};ze=Ln(Ji);Vo=new WeakMap;Uo=new WeakMap;Ho=new WeakMap;qo=new WeakMap;Ko=new WeakMap;re(ze,4,"accept",Fc,xt,Vo);re(ze,4,"type",Bc,xt,Uo);re(ze,4,"collisionDetector",Lc,xt,Ho);re(ze,4,"collisionPriority",Ac,xt,qo);re(ze,4,"shape",Rc,xt,Ko);re(ze,2,"isDropTarget",Pc,xt);tn(ze,xt);var kh=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)}},Sh=class extends kh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function us(e,t=!0){let n=!1;return Po(jo({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var $h=class extends zr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Lr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||Zs.pendingIdChanges)return;const o=us({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;te(()=>{var c;a?.id!==((c=e.dragOperation.target)==null?void 0:c.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Bn=(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))(Bn||{}),Fn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Fn||{}),zc,Wc,Nc,Gc,Vc,Uc,Hc,lt,Yo;Hc=[ne],Uc=[De],Vc=[De],Gc=[De],Nc=[De],Wc=[De],zc=[De];var Tt=class{constructor(){Y(lt,5,this),le(this,Yo,Y(lt,8,this,"idle")),Y(lt,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}};lt=Ln(null);Yo=new WeakMap;re(lt,4,"value",Hc,Tt,Yo);re(lt,2,"current",Uc,Tt);re(lt,2,"idle",Vc,Tt);re(lt,2,"initializing",Gc,Tt);re(lt,2,"initialized",Nc,Tt);re(lt,2,"dragging",Wc,Tt);re(lt,2,"dropped",zc,Tt);tn(lt,Tt);var Th=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 te(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=us({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return te(()=>{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;Ce(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=us({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"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return te(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=us({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,c,f,d,l;if(o.defaultPrevented)return;const u=(l=e.to)!=null?l:{x:r.position.current.x+((c=(a=e.by)==null?void 0:a.x)!=null?c:0),y:r.position.current.y+((d=(f=e.by)==null?void 0:f.y)!=null?d:0)};r.position.current=u})})}stop(e={}){return te(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const c={resume:()=>{},abort:()=>{}};return i=new Promise((f,d)=>{c.resume=f,c.abort=d}),c};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const c=te(()=>{var d;return((d=r.source)==null?void 0:d.status)==="dropping"}),f=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(c){const{source:d}=r,l=ct(()=>{d?.status==="idle"&&(l(),f())})}else this.manager.renderer.rendering.then(f)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),i?i.then(a).catch(()=>r.reset()):a()})}},Tn=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Eh=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,qc=class{constructor(e){this.options=e,le(this,fs)}set controller(e){tt(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 Ha=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Ch=class{constructor(e){this.draggables=new Ua,this.droppables=new Ua,this.plugins=new vi(e),this.sensors=new vi(e),this.modifiers=new vi(e)}register(e,t){if(e instanceof bt)return this.draggables.register(e.id,e);if(e instanceof xt)return this.droppables.register(e.id,e);if(e.prototype instanceof Ha)return this.modifiers.register(e,t);if(e.prototype instanceof Tn)return this.sensors.register(e,t);if(e.prototype instanceof qe)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Zs)return e instanceof bt?this.draggables.unregister(e.id,e):e instanceof xt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Ha)return this.modifiers.unregister(e);if(e.prototype instanceof Tn)return this.sensors.unregister(e);if(e.prototype instanceof qe)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},Kc,Yc,Xc,Qc,Zc,Jc,ed,td,nd,sr,hs,pn,Ee,Xo,Qo,Zo,Jo,ea,ir;nd=[De],td=[ne],ed=[ne],Jc=[ne],Zc=[ne],Qc=[ne],Xc=[De],Yc=[De],Kc=[De];var gt=class{constructor(e){Y(Ee,5,this),le(this,sr),le(this,hs),le(this,pn,new en(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Tt,le(this,Xo,Y(Ee,8,this,!1)),Y(Ee,11,this),le(this,Qo,Y(Ee,12,this,null)),Y(Ee,15,this),le(this,Zo,Y(Ee,16,this,null)),Y(Ee,19,this),le(this,Jo,Y(Ee,20,this,null)),Y(Ee,23,this),le(this,ea,Y(Ee,24,this,[])),Y(Ee,27,this),this.position=new Qs({x:0,y:0}),le(this,ir,{x:0,y:0}),tt(this,sr,e)}get shape(){const{current:e,initial:t,previous:n}=Oe(this,pn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Oe(this,pn).current=e:Oe(this,pn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Oe(this,sr).registry.draggables.get(t);return n&&tt(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,sr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Po(jo({},this.snapshot()),{transform:n}));return tt(this,ir,n),n}snapshot(){return te(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Oe(this,ir),shape:this.shape?mi(this.shape):null,position:mi(this.position),status:mi(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Oe(this,pn).reset(),this.position.reset({x:0,y:0}),tt(this,ir,{x:0,y:0}),this.modifiers=[]})}};Ee=Ln(null);sr=new WeakMap;hs=new WeakMap;pn=new WeakMap;Xo=new WeakMap;Qo=new WeakMap;Zo=new WeakMap;Jo=new WeakMap;ea=new WeakMap;ir=new WeakMap;re(Ee,2,"shape",nd,gt);re(Ee,4,"canceled",td,gt,Xo);re(Ee,4,"activatorEvent",ed,gt,Qo);re(Ee,4,"sourceIdentifier",Jc,gt,Zo);re(Ee,4,"targetIdentifier",Zc,gt,Jo);re(Ee,4,"modifiers",Qc,gt,ea);re(Ee,2,"source",Xc,gt);re(Ee,2,"target",Yc,gt);re(Ee,2,"transform",Kc,gt);tn(Ee,gt);var Oh={get rendering(){return Promise.resolve()}};function pt(e,t){return typeof e=="function"?e(t):e??t}var Dh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(u=>u.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=pt(r.plugins,[]),i=pt(r.sensors,[]),o=pt(r.modifiers,[]),a=(n=r.renderer)!=null?n:Oh,c=new Sh(this),f=new Ch(this);this.registry=f,this.monitor=c,this.renderer=a,this.actions=new Th(this),this.dragOperation=new gt(this),this.collisionObserver=new _h(this),this.plugins=[$h,...s],this.modifiers=o,this.sensors=i;const{destroy:d}=this,l=Lr(()=>{var u,h,p;const y=te(()=>this.dragOperation.modifiers),w=this.modifiers;for(const _ of y)w.includes(_)||_.destroy();this.dragOperation.modifiers=(p=(h=(u=this.dragOperation.source)==null?void 0:u.modifiers)==null?void 0:h.map(_=>{const{plugin:g,options:v}=Tr(_);return new g(this,v)}))!=null?p:w});this.destroy=()=>{l(),d()}}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}},rd=e=>{throw TypeError(e)},ta=(e,t,n)=>t.has(e)||rd("Cannot "+n),K=(e,t,n)=>(ta(e,t,"read from private field"),t.get(e)),Ze=(e,t,n)=>t.has(e)?rd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),et=(e,t,n,r)=>(ta(e,t,"write to private field"),t.set(e,n),n),sd=(e,t,n)=>(ta(e,t,"access private method"),n);function Js(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function id(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(Js(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function ei(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 na(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Wr(e){return"nodeType"in e}function nt(e){var t,n,r;return e?na(e)?e:Wr(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 ra(e){const{Document:t}=nt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Rt(e){return!e||na(e)?!1:e instanceof nt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function od(e){return e instanceof nt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function zn(e){return e?na(e)?e.document:Wr(e)?ra(e)?e:Rt(e)||od(e)?e.ownerDocument:document:document:document}function Mh(e){var t,n,r,s;const{documentElement:i}=zn(e),o=nt(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,c=(n=o?.height)!=null?n:i.clientHeight,f=(r=o?.offsetTop)!=null?r:0,d=(s=o?.offsetLeft)!=null?s:0;return{top:f,left:d,right:d+a,bottom:f+c,width:a,height:c}}function Ih(e,t){if(jh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function jh(e){return e.tagName==="DETAILS"}function Cr(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let c=t;const{ownerDocument:f}=e,d=(r=f.defaultView)!=null?r:window;let l=e.parentElement;for(;l&&l!==f.documentElement;){if(!Ih(l)){const v=l.getBoundingClientRect(),x=n*(v.bottom-v.top),b=n*(v.right-v.left),T=n*(v.bottom-v.top),C=n*(v.right-v.left);c={top:Math.max(c.top,v.top-x),right:Math.min(c.right,v.right+b),bottom:Math.min(c.bottom,v.bottom+T),left:Math.max(c.left,v.left-C),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top}l=l.parentElement}const u=d.visualViewport,h=(s=u?.offsetTop)!=null?s:0,p=(i=u?.offsetLeft)!=null?i:0,y=(o=u?.width)!=null?o:d.innerWidth,w=(a=u?.height)!=null?a:d.innerHeight,_=n*w,g=n*y;return c={top:Math.max(c.top,h-_),right:Math.min(c.right,p+y+g),bottom:Math.min(c.bottom,h+w+_),left:Math.max(c.left,p-g),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top,c.width<0&&(c.width=0),c.height<0&&(c.height=0),c}function En(e){return{x:e.clientX,y:e.clientY}}var ad=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function eo(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(...eo(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(...eo(s.document,t))}}catch{}return n}function sa(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ld(){var e,t;const n=sa()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function ia(e){return!e||!Wr(e)?!1:e instanceof nt(e).ShadowRoot}function Ms(e){if(e&&Wr(e)){let t=e.getRootNode();if(ia(t))return t;if(t instanceof Document)return t}return zn(e)}function oa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Ph(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(qa(i)&&qa(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),Ka(i)&&Ka(a)&&a.width>0&&a.height>0){const c=i.getContext("2d");c?.drawImage(a,0,0)}}),n}function qa(e){return"value"in e}function Ka(e){return e.tagName==="CANVAS"}function cd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Rh(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return cd(s,{x:t-i,y:n-o})}}return r}function Rh(e){return e?.tagName==="IFRAME"}var to=new WeakMap;function Ah(e){return e.closest(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),S=require("../useCompiledDocument-D0OAMejE.cjs.js"),$=require("@mui/material"),k=require("react"),Se=require("../ServerProvider-BIFPCzTD.cjs.js"),pe=require("../text-entry-BJwltZiy.cjs.js"),Ju=require("react-dom"),ef=require("@malloydata/malloy-tag"),Fl=require("@tanstack/react-query"),zl=S.createSvgIcon(m.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),Wl=S.createSvgIcon(m.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),tf=S.createSvgIcon(m.jsx("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}));function Nl(e){const{theme:t}=Se.usePublisherTheme(),n=t.ui,[r,s]=k.useState(null),{status:i,draftKeptAt:o,discard:a,restored:c,dismissRestored:f}=e,d=c!==void 0&&!c.pending&&i==="unsaved"?c:void 0,l=i==="saved"?"Saved":i==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",u=d?`Restored your unsaved edits from ${ji(d.savedAt)}`:void 0,h=i==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,p=a!==void 0&&i==="unsaved",v=()=>{s(null),d&&f?.()},x=y=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:i==="saved"?y.palette.text.secondary:y.palette.text.primary,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...p?{"&:hover":{bgcolor:y.palette.action.hover}}:{}}),_=m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:i==="saved"?m.jsx(S.CheckIcon,{sx:{fontSize:16}}):m.jsx($.Box,{component:"span","data-restored":d?"true":void 0,sx:y=>({width:7,height:7,borderRadius:"50%",bgcolor:d?t.accent:i==="saving"||o!==void 0?y.palette.text.disabled:y.palette.warning.main,transition:`background-color ${S.MOTION_FAST}`})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:l}),m.jsx(S.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:p?"visible":"hidden"}})]}),g=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:nf,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[g,m.jsx($.Tooltip,{title:u??h,describeChild:!0,children:p?m.jsx($.ButtonBase,{className:S.reportClasses.saveStatus,"aria-label":l,...u?{"aria-description":u}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:y=>s(y.currentTarget),sx:x,children:_}):m.jsx($.Box,{component:"span",className:S.reportClasses.saveStatus,sx:x,children:_})}),m.jsxs($.Menu,{className:S.reportClasses.menu,anchorEl:r,open:r!==null,onClose:v,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${S.edgeColor(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(u!==void 0||o!==void 0)&&m.jsx($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:u??`Kept in this browser at ${ji(o)}`}),m.jsxs($.MenuItem,{onClick:()=>{s(null),a?.()},sx:{mx:.5,borderRadius:n.radius.control,gap:1.25,color:"error.main","&.Mui-focusVisible":{outline:"none",bgcolor:"action.hover"}},children:[m.jsx(tf,{fontSize:"small"}),"Discard edits"]})]})]})}function ji(e){const t=new Date(e);return new Date().toDateString()===t.toDateString()?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}const nf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},Pi=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Xt=Pi?"⌘":"Ctrl+",Pa=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},fi=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function rf(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=Pi?i.metaKey:i.ctrlKey,c=i.key.toLowerCase();if(i.key==="Escape"){if(Pa(i.target)||fi(i.target))return;o.escape();return}if(Pa(i.target)){if(a&&c==="s"){if(i.preventDefault(),!o.save||fi(i.target))return;i.target.blur(),r(!0)}return}if(fi(i.target)){a&&c==="s"&&i.preventDefault();return}if(a&&c==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!Pi&&a&&c==="y"){i.preventDefault(),o.redo();return}if(a&&c==="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 gr=(e,t,n=Se.DEFAULT_UI)=>({height:n.size.control,minHeight:n.size.control,px:1.5,borderRadius:n.radius.control,boxShadow:"none",...n.type.control,"&:hover":{boxShadow:"none"},"& .MuiButton-startIcon":{mr:.5,"& svg":{fontSize:18}},"&.MuiButton-outlined":{borderColor:e,"&:hover":{borderColor:t}}}),Ss=(e=Se.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),$s={height:20,alignSelf:"center",mx:.5,my:0},Ts=(e,t=Se.DEFAULT_UI)=>({height:t.size.control,boxSizing:"border-box",borderRadius:t.radius.control,border:`1px solid ${e}`,overflow:"hidden",bgcolor:"background.paper","& .MuiToggleButton-root":{border:"none",borderRadius:"0 !important",m:"0 !important",px:1.5,py:0,height:"100%",...t.type.control,color:"text.secondary","& + .MuiToggleButton-root":{borderLeft:`1px solid ${e}`},"&:hover":{bgcolor:"action.hover"},"&.Mui-selected, &.Mui-selected:hover":{bgcolor:"action.selected",color:"text.primary"}}}),Ri={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function sf({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:c,saveButton:f,actions:d,onAddTile:l,onExit:u,saveStatus:h}){const{theme:p}=Se.usePublisherTheme(),v=S.edgeColor(p.cardBorder),x=S.hoverEdgeColor(p.cardBorder,p.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[l&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),onClick:l,"aria-label":"Add tile",sx:gr(v,x,p.ui),children:"Tile"}),l&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Ss(p.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:Ss(p.ui),children:m.jsx(zl,{fontSize:"small"})})})}),(d||o||u)&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),d,o&&h&&m.jsx(Nl,{...h}),o?m.jsx($.Tooltip,{title:s?`Save (${Xt}S) · ${c??Ri[a]}`:c??Ri[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:f,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{...gr(v,x,p.ui),minWidth:88},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&m.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"}),u&&m.jsx(S.SecondaryButton,{label:"Close",icon:m.jsx(S.CheckIcon,{}),onClick:u})]})}const of={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Gl(e,t,n){const s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(o=>{const a=s(o);return{value:o,label:of[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ra(e){return e.description??S.readableName(e.name)}const af={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},Qr=(e,t)=>`${e}\0${t}`;function lf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o,renderPreview:a}){const{theme:c}=Se.usePublisherTheme(),f=c.ui,d=S.edgeColor(c.cardBorder),l=k.useMemo(()=>n?.sources??[],[n]),[u,h]=k.useState(""),[p,v]=k.useState(),[x,_]=k.useState(""),[g,y]=k.useState("default"),w=k.useRef(null),b=k.useMemo(()=>{const I=new Set(t.sources.map(F=>F.base));return[...l].sort((F,H)=>Number(I.has(H.name))-Number(I.has(F.name)))},[l,t]),T=b.filter(I=>I.views.length>0),C=b.filter(I=>I.views.length===0),M=k.useMemo(()=>new Map(T.flatMap(I=>I.views.map(F=>[Qr(I.name,F.name),{source:I,view:F,key:Qr(I.name,F.name)}]))),[T]),E=k.useMemo(()=>T.map(I=>({key:I.name,label:I.name,...I.description?{detail:I.description}:{},entries:I.views.map(F=>({key:Qr(I.name,F.name),name:F.name,title:Ra(F),...F.chart?{chart:F.chart}:{}}))})),[T]),O=p===void 0?void 0:M.get(p);k.useEffect(()=>{if(!e)return;h(""),_(""),y("default");const I=T[0]?.views[0];v(I&&T[0]?Qr(T[0].name,I.name):void 0)},[e]);const A=O?[O.source.name,O.view.name].filter(I=>!pe.isBareName(I)).map(I=>`"${I}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,j=O!==void 0&&A===void 0,L=O?Ra(O.view):"",N=g!=="default"&&O?{chart:g,chartCarried:O.view.chart?[O.view.chart]:[]}:{},W=(I=O)=>{if(!I||![I.source.name,I.view.name].every(pe.isBareName))return;const F=I.key===O?.key;i({base:I.source.name,modelPath:I.source.modelPath,...I.source.exporters?{exporters:I.source.exporters}:{},view:I.view.name,...F&&x.trim()?{label:x.trim()}:{},...F?N:{},colspan:Math.ceil(r/2)})},V=O?Gl(O.view,g).filter(I=>I.value!=="custom"&&I.disabled!==!0):[];return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:w,title:"Add a tile",description:"Pick a view from this package. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx($.Button,{onClick:s,children:"Cancel"}),m.jsx($.Button,{variant:"contained",disabled:!j,onClick:()=>W(),children:"Add tile"})]}),children:m.jsxs($.Box,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${d}`,borderBottom:`1px solid ${d}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx($.Box,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${d}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(S.ViewPicker,{groups:E,query:u,onQuery:h,picked:O?.key,onPick:I=>{v(I),y("default")},onTake:I=>W(M.get(I)),searchRef:w,empty:m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,p:2},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}),footer:C.length>0&&m.jsxs($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",C.map(I=>I.name).join(", "),"."]})})}),m.jsx($.Box,{sx:I=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${I.palette.text.primary} 3%, ${I.palette.background.paper})`}),children:O?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:I=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${d}`,bgcolor:I.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${I.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:O.source.name,modelPath:O.source.modelPath,view:O.view.name,label:x.trim()||L,...g!=="default"?N:{},givens:O.source.givens})}):m.jsxs($.Box,{sx:I=>({flex:1,border:`1px solid ${d}`,borderRadius:f.radius.tile,bgcolor:I.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(S.ChartGlyph,{chart:O.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[O.source.name," → ",O.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:L,value:x,onChange:I=>_(I.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs($.Box,{children:[m.jsx($.Typography,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($.ToggleButtonGroup,{size:"small",exclusive:!0,value:g,"aria-label":"Chart",onChange:(I,F)=>{F!==null&&y(F)},sx:{...Ts(d,f),"& .MuiToggleButton-root":{...Ts(d,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:V.map(I=>m.jsx($.ToggleButton,{value:I.value,children:I.label},I.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:O.view.chart?`The view declares ${af[O.view.chart]??"a chart"}.`:"The view declares no chart, so it shows as a table."})]}),A&&m.jsx($.Typography,{variant:"body2",color:"error",children:A})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const je=e=>e.kind==="text",ae=e=>e.kind!=="text",Yn=e=>ae(e)?e.label??e.name:e.name,Fe=e=>je(e)?`text.${e.name}`:`${e.source}.${e.name}`;function cf(e,t,{modelPath:n,textHeld:r,widths:s,insertAt:i}){t.modelPath&&!r&&(e.imports=S.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Ul(e,t.base),a=Ai(e,o.name,t.view);e.tiles.splice(i??e.tiles.length,0,{name:a,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 Ul(e,t,{unscoped:n=!1}={}){const r=e.sources.find(a=>a.base===t&&(!n||!a.scopedBy?.length));if(r)return r;const s=new Set(e.sources.map(a=>a.name));let i=`${t}_tiles`;for(let a=2;s.has(i);a++)i=`${t}_tiles_${a}`;const o={name:i,base:t};return e.sources.push(o),o}function Ai(e,t,n){const r=new Set(e.tiles.filter(ae).filter(i=>i.source===t).map(i=>i.name));let s=`${n}_tile`;for(let i=2;r.has(s);i++)s=`${n}_tile_${i}`;return s}function Es(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function df(e,t){const n=e.tiles[t];if(!n||!ae(n)||Es(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...i}=structuredClone(n);r={...i,name:Ai(e,n.source,n.declaration.from)}}else{const i=e.sources.find(o=>o.name===n.source)??Ul(e,n.source,{unscoped:!0});r={name:Ai(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}return e.tiles.splice(t+1,0,r),t+1}const Zr="self";function uf({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:i,onClose:o,onApply:a}){const{theme:c}=Se.usePublisherTheme(),f=c.ui,[d,l]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const g=(t.drills??[]).filter(y=>y.source===n.name);l((n.dimensions??[]).map(y=>{const w=g.find(b=>b.name===y.name);return{name:y.name,expression:y.expression,to:w?.to??[],given:w?.given??""}}))},[e,n,t]);const u=(g,y)=>l(w=>w.map((b,T)=>{if(T!==g)return b;const C={...b};return y(C),C})),h=[Zr,...s.filter(g=>g!==Zr)],p=g=>g===Zr?"This report":g,v=()=>{n&&(a(d.filter(g=>g.to.length>0).map(g=>({source:n.name,name:g.name,expression:g.expression,to:g.to,...g.given?{given:g.given}:{}}))),o())},x=S.edgeColor(c.cardBorder),_=(g,y)=>u(g,w=>{y?w.to=w.lastTo?.length?w.lastTo:[Zr]:(w.lastTo=w.to,w.to=[])});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[i&&m.jsxs($.Box,{component:"span",sx:{fontWeight:f.type.label.fontWeight},children:[i," ·"," "]}),"A click on a cell sets a filter to its value, on this report or on the one it opens."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Button,{variant:"contained",onClick:v,disabled:d.length===0,children:"Apply"})]}),children:d.length===0?m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A click is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",m.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx($.Box,{role:"list","aria-label":"Dimensions",children:d.map((g,y)=>{const w=g.to.length>0;return m.jsxs($.Box,{role:"listitem",sx:{display:"grid",gridTemplateColumns:{xs:"auto minmax(0, 1fr)",sm:"auto minmax(0, 0.9fr) minmax(0, 1.6fr)"},alignItems:"center",columnGap:1.5,rowGap:1,py:1.25,borderTop:y===0?"none":`1px solid ${x}`},children:[m.jsx($.Switch,{size:"small",checked:w,onChange:b=>_(y,b.target.checked),slotProps:{input:{"aria-label":`${g.name} is clickable`}}}),m.jsxs($.Box,{sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:ff(g.name)}),m.jsxs($.Box,{title:g.expression,sx:{...f.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[g.name," is ",g.expression]})]}),w?m.jsxs($.Stack,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...f.type.control},children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx($.TextField,{select:!0,size:"small",value:g.to,inputProps:{"aria-label":`Where ${g.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.map(p).join(", ")},onChange:b=>u(y,T=>{const C=b.target.value,M=Array.isArray(C)?C:String(C).split(",").filter(Boolean);M.length===0&&(T.lastTo=T.to),T.to=M}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:h.map(b=>m.jsxs($.MenuItem,{value:b,children:[m.jsx($.Checkbox,{size:"small",checked:g.to.includes(b),sx:{p:0,mr:1}}),m.jsx($.ListItemText,{primary:p(b)})]},b))}),m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs($.TextField,{select:!0,size:"small",value:g.given,inputProps:{"aria-label":`Control ${g.name} sets`},SelectProps:{displayEmpty:!0,renderValue:b=>b===""?g.name:String(b)},onChange:b=>u(y,T=>{T.given=b.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx($.MenuItem,{value:"",children:m.jsx($.ListItemText,{primary:g.name,secondary:"Named like the dimension"})}),r.map(b=>m.jsx($.MenuItem,{value:b,children:b},b))]})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},g.name)})})})}function ff(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const hf=S.createSvgIcon(m.jsx("path",{d:"M12 4c4.41 0 8 3.59 8 8s-3.59 8-8 8-8-3.59-8-8 3.59-8 8-8m0-2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 13-4-4h8z"})),pf=S.createSvgIcon(m.jsx("path",{d:"M11 7H2v2h9zm0 8H2v2h9zm5.34-4L12.8 7.46l1.41-1.41 2.12 2.12 4.24-4.24L22 5.34zm0 8-3.54-3.54 1.41-1.41 2.12 2.12 4.24-4.24L22 13.34z"})),gf=S.createSvgIcon(m.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 16H5V10h14zm0-12H5V6h14zm-7 5h5v5h-5z"})),mf=S.createSvgIcon(m.jsx("path",{d:"M19.5 9.5c-1.03 0-1.9.62-2.29 1.5h-2.92c-.39-.88-1.26-1.5-2.29-1.5s-1.9.62-2.29 1.5H6.79c-.39-.88-1.26-1.5-2.29-1.5C3.12 9.5 2 10.62 2 12s1.12 2.5 2.5 2.5c1.03 0 1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5s1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5 1.38 0 2.5-1.12 2.5-2.5s-1.12-2.5-2.5-2.5"})),vf=S.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),yf=S.createSvgIcon(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function bf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of ae(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 Cs(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function xf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function mr(e,t){const n=xf(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 Li(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 wf(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const _f=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function kf(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=pe.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 Sf=[{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 Zn(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 Bi=e=>ae(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function $f(e,t){return e.tiles.map(n=>{const r=(ae(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}:Cs(t.type)!==void 0?{op:Cs(t.type)}:{}}})}function Tf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Bi(i))return;const o=(i.filters??[]).filter(c=>c.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?i.filters=a:delete i.filters})}function Ef(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 Cf(e,t){for(const r of e.tiles){if(!ae(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 Fi=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function Of({open:e,document:t,control:n,available:r,takenNames:s=[],fieldsFor:i,onApply:o}){const a=k.useRef(n);e&&(a.current=n);const c=e?n:a.current,f=c!==void 0,[d,l]=k.useState({kind:"new"}),[u,h]=k.useState(""),[p,v]=k.useState("select"),[x,_]=k.useState(""),[g,y]=k.useState(""),[w,b]=k.useState([]),[T,C]=k.useState(!1),[M,E]=k.useState(!1),O=D=>t.sources.find(R=>R.name===D.source)?.base??D.source;k.useEffect(()=>{if(e)if(E(n!==void 0),n){l({kind:"existing",name:n.name}),h(n.label??"");const D=$f(t,n);b(D);const R=D.filter(P=>P.include),z=new Set(R.map(P=>P.field));y(z.size===1?R[0].field:n.field??""),C(z.size>1)}else l({kind:"new"}),h(""),v("select"),y(""),_(new Date().toISOString().slice(0,10)),b(t.tiles.map(D=>({include:Bi(D),field:""}))),C(!1)},[e,n,t]);const A=k.useMemo(()=>[...(t.localGivens??[]).map(D=>D.name),...r.map(D=>D.name),...s],[t,r,s]),j=k.useMemo(()=>g.trim()?kf(g.trim(),A):"",[g,A]),L=d.kind==="existing"?n??r.find(D=>D.name===d.name):j?{name:j,type:Zn({name:j,label:u,kind:p,field:g}).type}:void 0,N=L?.type!==void 0&&!L.type.startsWith("filter<"),W=w.find(D=>D.include)?.op??Cs(L?.type),V=(D,R)=>{E(!0),b(z=>z.map((P,U)=>U===D?{...P,...R}:P))},I=D=>{E(!0),b(R=>R.map(z=>({...z,op:D})))},F=D=>{const R=Cs(D);b(z=>z.map(({op:P,...U})=>R?{...U,op:R}:U))},H=D=>{E(!0),l({kind:"existing",name:D.name}),y(D.field??""),F(D.type)},B=D=>{E(!0),v(D),F(Zn({name:"X",label:u,kind:D,field:g}).type)},G=t.tiles.map(Bi),ee=G.filter(Boolean).length,Q=w.filter((D,R)=>D.include&&G[R]).length,J=t.tiles.filter((D,R)=>(w[R]?.include??!1)&&G[R]&&ae(D)),X=J.length>0?J:t.tiles.filter((D,R)=>G[R]&&ae(D)),te=k.useMemo(()=>{const D=new Map;let R=!1;for(const z of X){const P=i?.(z);if(P){R=!0;for(const U of P)D.has(U.name)||D.set(U.name,U)}}return R?[...D.values()]:void 0},[w,t.tiles,i]),we=(()=>{const D=g.trim();for(const R of J){const z=i?.(R);if(!z||z.some(P=>P.name===D))return O(R)}return J[0]?O(J[0]):t.sources[0]?.base})(),me=D=>{E(!0),b(R=>R.map((z,P)=>({...z,include:D&&G[P]})))},ye=k.useMemo(()=>T?w:w.map(D=>({...D,field:g})),[T,w,g]),$e=D=>{for(const R of X){const z=i?.(R)?.find(P=>P.name===D.trim());if(z?.type)return z.type}},ue=D=>mr(L?.type,D.type),ve=(D,R)=>{if(D.trim()==="")return"Pick the field this filter compares.";const z=R?i?.(R):void 0;if(!z)return;const P=z.find(U=>U.name===D.trim());if(!P)return`Not a field of ${R?O(R):"the tiles' source"}.`;if(P.type&&!mr(L?.type,P.type))return`${D.trim()} is ${Li(P.type)}; this filter compares ${Li(L?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},Z=D=>{if(E(!0),y(D),f||d.kind!=="new")return;const R=$e(D),z=Zn({name:"X",label:u,kind:p,field:D}).type;R&&!mr(z,R)&&B(wf(R))},Ue=D=>{const R=t.tiles[D];return R&&ae(R)?R:void 0},fe=ye.map((D,R)=>D.include&&G[R]?ve(D.field,Ue(R)):void 0),le=fe.every(D=>D===void 0),Le=M?fe:fe.map(()=>{}),We=M&&!T&&Q>0?J.map(D=>ve(g,D)).find(Boolean):void 0,he=L!==void 0&&le&&(d.kind==="existing"||g.trim()!==""&&j!==""),Ne=()=>{if(!(!L||!he))if(d.kind==="new")o(L.name,ye,Zn({name:L.name,label:u.trim()||Fi(L.name),kind:p,field:g.trim(),...we?{source:we}:{},...x?{dateDefault:x}:{}}));else if(n?.origin==="dashboard"&&n.local){const D=u.trim(),R=D!==(n.local.label??"");o(L.name,ye,R?{...n.local,...D?{label:D}:{}}:void 0)}else o(L.name,ye)},Oe=f&&c.origin==="model";return{editing:f,shown:c,fromModel:Oe,source:d,setSource:l,label:u,setLabel:h,kind:p,dateDefault:x,setDateDefault:_,field:g,rows:w,setRows:b,perTile:T,setPerTile:C,newName:j,target:L,valueTyped:N,commonOp:W,setRow:V,setCommonOp:I,pickExisting:H,pickKind:B,bindable:G,bindableCount:ee,included:Q,commonFields:te,setAll:me,accepts:ue,pickField:Z,rowProblems:Le,commonProblem:We,canApply:he,apply:Ne}}function Aa({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:c,autoFocus:f,placeholder:d,inputRef:l,sx:u}){const h=k.useMemo(()=>(n??[]).filter(v=>r?.(v)??!0).map(v=>v.name),[n,r]),p=k.useMemo(()=>new Map((n??[]).map(v=>[v.name,v.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(v,x)=>t(x),value:e,onChange:(v,x)=>t(typeof x=="string"?x:""),disabled:c,disableClearable:!0,renderOption:(v,x)=>k.createElement("li",{...v,key:x},m.jsx(Ba,{type:p.get(x)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:x})),renderInput:v=>m.jsx($.TextField,{...v,label:s,placeholder:d,autoFocus:f,...l?{inputRef:l}:{},error:o,helperText:a,InputLabelProps:{...v.InputLabelProps,shrink:!0},InputProps:{...v.InputProps,startAdornment:p.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Ba,{type:p.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":i}}),sx:u})}const Df=e=>e&&ae(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 Mf({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:i,onClose:o,onApply:a,onRemove:c}){const{theme:f}=Se.usePublisherTheme(),d=f.ui,{editing:l,shown:u,fromModel:h,source:p,setSource:v,label:x,setLabel:_,kind:g,dateDefault:y,setDateDefault:w,field:b,rows:T,setRows:C,perTile:M,setPerTile:E,newName:O,target:A,valueTyped:j,commonOp:L,setRow:N,setCommonOp:W,pickExisting:V,pickKind:I,bindable:F,bindableCount:H,included:B,commonFields:G,setAll:ee,accepts:Q,pickField:J,rowProblems:X,commonProblem:te,canApply:we,apply:me}=Of({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:i,onApply:a}),ye=k.useRef(null),$e=S.edgeColor(f.cardBorder),ue=S.hoverEdgeColor(f.cardBorder,f.tileTitle),[ve,Z]=k.useState(!1),[Ue,fe]=k.useState(!1);k.useEffect(()=>{e?fe(!0):Z(!1)},[e]),k.useEffect(()=>{Ue&&(fe(!1),Z(l&&B<H))},[Ue]),k.useEffect(()=>{M&&Z(!0)},[M]);const le=G?.find(D=>D.name===b.trim())?.type,Le=D=>{if(!le)return;const R=Zn({name:"X",label:x,kind:D,field:b}).type;return mr(R,le)?void 0:`${b.trim()} is ${Li(le)}, which this control cannot filter.`},We=x.trim()||(O?Fi(O):"Filter"),he=g==="number"?"Any":g==="date"?y?new Date(`${y}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ne={...Ts($e,d),alignSelf:"flex-start","& .MuiToggleButton-root":{...Ts($e,d)["& .MuiToggleButton-root"],textTransform:"none"}},Oe=(D,R,z)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:D??">=",onChange:P=>R(P.target.value),inputProps:{"aria-label":z},sx:{width:130},children:_f.filter(P=>P.op!=="~").map(P=>m.jsx($.MenuItem,{value:P.op,children:P.label},P.op))});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:ye},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs($.Box,{component:"span",sx:{fontFamily:d.font.mono},children:["$",u.name]}),h?" · declared in the model, so its label and options are set there":" · declared in this report"]}):"A filter on the page, and the tiles it filters.",actions:m.jsxs(m.Fragment,{children:[l&&m.jsx($.Button,{color:"error",startIcon:m.jsx(S.DeleteOutlineIcon,{}),onClick:()=>c(u.name),sx:D=>({mr:"auto",color:S.dangerTextColor(D)}),children:"Remove filter"}),m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Tooltip,{title:we||A===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",onClick:me,disabled:!we,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:p.kind,onChange:(D,R)=>{R==="new"?v({kind:"new"}):R==="existing"&&r[0]&&V(r[0])},"aria-label":"Where the filter comes from",sx:Ne,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!l&&p.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:p.name,onChange:D=>{const R=r.find(z=>z.name===D.target.value);R&&V(R)},children:r.map(D=>m.jsxs($.MenuItem,{value:D.name,children:[D.label??D.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",D.name]})]},D.name))}):null,m.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:h?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!M&&m.jsx(Aa,{value:b,onChange:J,fields:G,accepts:Q,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:ye,error:te!==void 0,helperText:te??(!l&&O?`Declared as $${O}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:O?Fi(O):"",value:x,onChange:D=>_(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),j&&!M&&Oe(L,W,"Comparison"),!l&&p.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Control"}),m.jsx($.Box,{role:"radiogroup","aria-label":"Filter kind",sx:{display:"grid",gridTemplateColumns:{xs:"repeat(3, minmax(0, 1fr))",sm:"repeat(5, minmax(0, 1fr))"},gap:1},children:Sf.map(D=>{const R=D.kind===g,z=Le(D.kind);return m.jsx($.Tooltip,{title:z??D.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":R,"aria-label":D.label,"aria-disabled":z!==void 0,onClick:()=>{z===void 0&&I(D.kind)},sx:P=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:d.radius.tile,border:`1px solid ${R?f.accent:$e}`,boxShadow:R?`0 0 0 1px ${f.accent}`:"none",bgcolor:R?`color-mix(in srgb, ${f.accent} 6%, ${P.palette.background.paper})`:P.palette.background.paper,color:R?f.accent:P.palette.text.secondary,opacity:z?.45:1,cursor:z?"default":"pointer",transition:`border-color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"&:hover":z||R?{}:{borderColor:ue}}),children:[m.jsx(jf,{kind:D.kind}),m.jsx($.Box,{component:"span",sx:{...d.type.caption,fontWeight:R?600:500,color:R?f.accent:"text.primary",textAlign:"center"},children:If[D.kind]})]})},D.kind)})}),g==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:y,onChange:D=>w(D.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${$e}`,borderRadius:d.radius.tile,overflow:"hidden"},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(yf,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs($.Typography,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:B===H&&H>0?`Applies to all ${B} tile${B===1?"":"s"}`:`Applies to ${B} of ${H} tile${H===1?"":"s"}`}),!M&&b.trim()!==""&&B>0&&m.jsxs($.Box,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx($.Box,{component:"span",sx:{...d.type.code},children:b.trim()})]})]}),!M&&m.jsx($.Button,{size:"small","aria-expanded":ve,onClick:()=>Z(D=>!D),children:ve?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:ve,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${$e}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:H>0&&B===H,indeterminate:B>0&&B<H,disabled:H===0,onChange:D=>ee(D.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx($.Button,{size:"small",onClick:()=>{M||C(D=>D.map(R=>({...R,field:b}))),E(D=>!D)},children:M?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:M?1:0},children:t.tiles.map((D,R)=>{if(!ae(D))return null;const z=T[R],P=D.label??D.name,U=M?X[R]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:M?"flex-start":"center",opacity:F[R]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!F[R],checked:(z?.include??!1)&&F[R],inputProps:{"aria-label":`Filter ${P}`},onChange:K=>N(R,{include:K.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:M?1:0},noWrap:!0,children:P}),F[R]?M&&m.jsxs(m.Fragment,{children:[j&&Oe(z?.op,K=>N(R,{op:K}),`Comparison for ${P}`),m.jsx(Aa,{value:z?.field??"",onChange:K=>N(R,{field:K}),fields:i?.(D),accepts:Q,label:"Field",ariaLabel:`Field for ${P}`,disabled:!z?.include,error:U!==void 0,helperText:U,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:Df(t.tiles[R]).reason})]},`${D.source}.${D.name}`)})})]})})]}),B===0&&m.jsx($.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!h&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Preview"}),m.jsx($.Box,{sx:D=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:d.radius.tile,bgcolor:D.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:D=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:d.radius.control,border:`1px solid ${$e}`,bgcolor:D.palette.background.paper,...d.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:We}),m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:he}),m.jsx(S.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function La({children:e}){const t=Se.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const If={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function jf({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(hf,{sx:t});case"multiselect":return m.jsx(pf,{sx:t});case"text":return m.jsx(vf,{sx:t});case"number":return m.jsx(mf,{sx:t});case"date":return m.jsx(gf,{sx:t})}}function Ba({type:e}){const t=e?.replace(/_type$/,""),n=t==="string"?"Abc":t==="number"?"#":t==="date"||t==="timestamp"?"Date":t==="boolean"?"T/F":void 0,r=Se.usePublisherTheme().theme.ui;return n?m.jsx($.Box,{component:"span","aria-hidden":!0,sx:s=>({fontFamily:r.font.mono,fontSize:10,fontWeight:r.type.label.fontWeight,color:s.palette.text.secondary,bgcolor:s.palette.action.hover,borderRadius:"4px",px:.5,py:.25,minWidth:22,textAlign:"center",flex:"none"}),children:n}):null}const Pf=S.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Hl(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:d=>i(l=>{if(l===void 0)return l;const u=structuredClone(l);return d(u),u}),apply:d=>{if(s===void 0)return;const l=structuredClone(s);d(l),i(l),JSON.stringify(l)!==JSON.stringify(e)&&n(l)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const Rf=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.`,Af="Declared on its source, so its chart is set in the model.";function Lf({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:i,duplicateBlocked:o,view:a}){const{theme:c}=Se.usePublisherTheme(),f=c.ui,{draft:d,apply:l,close:u}=Hl(t,e!==null,r,n),[h,p]=k.useState(void 0),v=d!==void 0&&ae(d)?d:void 0,x=v!==void 0&&v.declaration.kind!=="inherited",_=A=>l(j=>{ae(j)&&A(j)}),g=k.useRef(void 0),y=e!==null;k.useEffect(()=>{y?g.current=t&&ae(t)?t.chart:void 0:p(void 0)},[y]);const w=v?.chart??"default",b=Gl(a,w),T=v?x?v.chart==="custom"?Rf(v.chartLines):void 0:Af:void 0,C=A=>_(j=>{const L=g.current;A===(L??"default")?(L===void 0?delete j.chart:j.chart=L,delete j.chartCarried):(j.chart=A,a?j.chartCarried=a.chart?[a.chart]:[]:delete j.chartCarried)}),M=x?s?void 0:"Its source declares no dimension a click could filter by.":void 0,E=A=>j=>p({kind:A,anchor:j.currentTarget}),O=(A,j,L)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:A,...L?{secondary:L}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),j&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:j})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:S.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":v?`${v.source} ${v.name}`:"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:f.radius.menu,border:`1px solid ${S.edgeColor(c.cardBorder)}`,boxShadow:f.shadow.menu}}},children:[v&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":h?.kind==="chart",disabled:T!==void 0,onClick:E("chart"),onKeyDown:A=>{A.key==="ArrowRight"&&T===void 0&&p({kind:"chart",anchor:A.currentTarget})},children:[O("Chart",T?void 0:b.find(A=>A.value===w)?.label,T),m.jsx(Pf,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),x&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:M!==void 0,onClick:()=>{u(),s?.()},children:O("Clickable cells…",void 0,M)}),v&&i&&m.jsx($.MenuItem,{disabled:o!==void 0,onClick:()=>{u(),i()},children:O("Duplicate",void 0,o)}),v?.declaration.kind==="opaque"&&m.jsxs($.Typography,{variant:"body2",sx:{color:c.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",v.declaration.why,", so a filter has no single place to go."]}),v&&m.jsx($.Divider,{}),v&&m.jsxs($.Box,{"aria-hidden":!0,sx:{px:2,py:.5,...f.type.code,color:"text.secondary"},children:[v.source," → ",v.name]})]}),m.jsx($.Menu,{className:S.reportClasses.menu,open:h?.kind==="chart",anchorEl:h?.anchor??null,onClose:()=>p(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:A=>{A.key==="ArrowLeft"&&(A.preventDefault(),p(void 0))}},children:b.filter(A=>A.value!=="custom").map(A=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":A.value===w,disabled:A.disabled===!0,onClick:()=>{C(A.value),p(void 0)},children:[m.jsx($.ListItemText,{primary:A.label,...A.reason?{secondary:A.reason}:{}}),A.value===w&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(S.CheckIcon,{fontSize:"small",sx:{color:c.accent}})})]},A.value))})]})}const kn=e=>e.label??S.tileTitle(`${e.source} -> ${e.name}`);function Bf({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,exitDialog:c,renderViewPreview:f,takenGivenNames:d}){const{filterDialog:l,setFilterDialog:u}=s,{menu:h,setMenu:p}=i,[v,x]=k.useState(),_=h===void 0?void 0:e.document.tiles[h.index],g=_&&ae(_)?_:void 0,y=(()=>{if(!g||!t)return;const w=e.document.sources.find(T=>T.name===g.source)?.base??g.source,b=g.declaration.kind==="reference"?g.declaration.from:g.name;return t.sources.find(T=>T.name===w)?.views.find(T=>T.name===b)})();return m.jsxs(m.Fragment,{children:[m.jsx(Mf,{open:l!==void 0,document:e.document,...l?.control?{control:l.control}:{},available:s.available,...d?{takenNames:d}:{},...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>u(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),m.jsx(Lf,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>p(void 0),onCommit:w=>{const b=h?.index;b!==void 0&&e.update(T=>{T.tiles[b]=w})},view:y,onDuplicate:()=>{h&&i.duplicate(h.index)},...g&&Es(g)!==void 0?{duplicateBlocked:Es(g)}:{},...(e.document.sources.find(w=>w.name===g?.source)?.dimensions?.length??0)>0?{onDrills:()=>{x(g?kn(g):void 0),a(g?.source)}}:{}}),m.jsx(uf,{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??[],...v?{tileLabel:v}:{},onClose:()=>a(void 0),onApply:w=>e.update(b=>{const C=[...(b.drills??[]).filter(M=>M.source!==o),...w];C.length===0?delete b.drills:b.drills=C})}),m.jsx(S.UnsavedChangesDialog,{...c}),m.jsx(lf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText,...f?{renderPreview:f}:{}})]})}var Ff=Symbol.for("preact-signals");function Qs(){if(kt>1)kt--;else{var e,t=!1;for((function(){var s=Ds;for(Ds=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}})();yr!==void 0;){var n=yr;for(yr=void 0,Os++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Kl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Os=0,kt--,t)throw e}}function Ce(e){if(kt>0)return e();zi=++zf,kt++;try{return e()}finally{Qs()}}var vr,be=void 0;function ne(e){var t=be,n=vr;be=void 0,vr=void 0;try{return e()}finally{be=t,vr=n}}var yr=void 0,kt=0,Os=0,zf=0,zi=0,Ds=void 0,Ms=0;function Vl(e){if(be!==void 0){var t=e.n;if(t===void 0||t.t!==be)return t={i:0,S:e,p:be.s,n:void 0,t:be,e:void 0,x:void 0,r:t},be.s!==void 0&&(be.s.n=t),be.s=t,e.n=t,32&be.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=be.s,t.n=void 0,be.s.n=t,be.s=t),t}}function Ze(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}Ze.prototype.brand=Ff;Ze.prototype.h=function(){return!0};Ze.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:ne(function(){var r;(r=t.W)==null||r.call(t)}))};Ze.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&&ne(function(){var s;(s=t.Z)==null||s.call(t)}))}};Ze.prototype.subscribe=function(e){var t=this;return dt(function(){var n=t.value;ne(function(){return e(n)})},{name:"sub"})};Ze.prototype.valueOf=function(){return this.value};Ze.prototype.toString=function(){return this.value+""};Ze.prototype.toJSON=function(){return this.value};Ze.prototype.peek=function(){var e=this;return ne(function(){return e.value})};Object.defineProperty(Ze.prototype,"value",{get:function(){var e=Vl(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Os>100)throw new Error("Cycle detected");(function(n){kt!==0&&Os===0&&n.l!==zi&&(n.l=zi,Ds={S:n,v:n.v,i:n.i,o:Ds})})(this),this.v=e,this.i++,Ms++,kt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Qs()}}}});function jn(e,t){return new Ze(e,t)}function Kl(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 ql(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 Jt(e,t){Ze.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Ms-1,this.f=4}Jt.prototype=new Ze;Jt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ms))return!0;if(this.g=Ms,this.f|=1,this.i>0&&!Kl(this))return this.f&=-2,!0;var e=be;try{ql(this),be=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return be=e,Yl(this),this.f&=-2,!0};Jt.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)}Ze.prototype.S.call(this,e)};Jt.prototype.U=function(e){if(this.t!==void 0&&(Ze.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)}};Jt.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(Jt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Vl(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Fa(e,t){return new Jt(e,t)}function Xl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){kt++;var n=be;be=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Eo(e),r}finally{be=n,Qs()}}}function Eo(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Xl(e)}function Wf(e){if(be!==this)throw new Error("Out-of-order effect");Yl(this),be=e,this.f&=-2,8&this.f&&Eo(this),Qs()}function Pn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,vr&&vr.push(this)}Pn.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()}};Pn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Xl(this),ql(this),kt++;var e=be;return be=this,Wf.bind(this,e)};Pn.prototype.N=function(){2&this.f||(this.f|=2,this.u=yr,yr=this)};Pn.prototype.d=function(){this.f|=8,1&this.f||Eo(this)};Pn.prototype.dispose=function(){this.d()};function dt(e,t){var n=new Pn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Nf=Object.create,Co=Object.defineProperty,Gf=Object.defineProperties,Uf=Object.getOwnPropertyDescriptor,Hf=Object.getOwnPropertyDescriptors,za=Object.getOwnPropertySymbols,Vf=Object.prototype.hasOwnProperty,Kf=Object.prototype.propertyIsEnumerable,qf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Rn=e=>{throw TypeError(e)},Wi=(e,t,n)=>t in e?Co(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yf=(e,t)=>{for(var n in t||(t={}))Vf.call(t,n)&&Wi(e,n,t[n]);if(za)for(var n of za(t))Kf.call(t,n)&&Wi(e,n,t[n]);return e},Xf=(e,t)=>Gf(e,Hf(t)),Wa=(e,t)=>Co(e,"name",{value:t,configurable:!0}),Qf=e=>{var t;return[,,,Nf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],Jn=e=>e!==void 0&&typeof e!="function"?Rn("Function expected"):e,Zf=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:i=>n._?Rn("Already initialized"):s.push(Jn(i||null))}),Zl=(e,t)=>Wi(t,qf("metadata"),e[3]),Ft=(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,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,v=Ql[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&Uf(l<4?s:{get[n](){return it(this,i)},set[n](w){return Mt(this,i,w)}},n));l?h&&l<4&&Wa(i,(l>2?"set ":l>1?"get ":"")+n):Wa(s,n);for(var y=r.length-1;y>=0;y--)f=Zf(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>Jf(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?it:eh)(w,s,l^4?i:g.get):w=>w[n]),l>2&&(d.set=h?(w,b)=>Mt(w,s,b,l^4?i:g.set):(w,b)=>w[n]=b)),a=(0,r[y])(l?l<4?h?i:g[v]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?Jn(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Rn("Object expected"):(Jn(o=a.get)&&(g.get=o),Jn(o=a.set)&&(g.set=o),Jn(o=a.init)&&x.unshift(o));return l||Zl(e,s),g&&Co(s,n,g),h?l^4?i:g:s},Oo=(e,t,n)=>t.has(e)||Rn("Cannot "+n),Jf=(e,t)=>Object(t)!==t?Rn('Cannot use the "in" operator on this value'):e.has(t),it=(e,t,n)=>(Oo(e,t,"read from private field"),n?n.call(e):t.get(e)),er=(e,t,n)=>t.has(e)?Rn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Mt=(e,t,n,r)=>(Oo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),eh=(e,t,n)=>(Oo(e,t,"access private method"),n);function Ni(e,t){if(t){let n;return Fa(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Fa(e)}function ft(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)=>!ft(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=>!ft(e[i],t[i]))}return!1}function re({get:e},t){return{init(n){return jn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Me(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Ni(e.bind(this)),n.set(this,r)),r.value}}function hi(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,Xf(Yf({},s),{enumerable:e}))})}}function Rr(...e){const t=e.map(n=>dt(n));return()=>t.forEach(n=>n())}var Jl,ec,tc,nc,rc,sc,Ye,Do,pi,Gi,Ui,Ke,Mo,gi,ic,Hi,Io,mi,Vi,Ki;sc=[re],rc=[re],nc=[re],tc=[hi()],ec=[hi()],Jl=[hi()];var en=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ft(Ye,5,this),er(this,Ke),er(this,Do,Ft(Ye,8,this)),Ft(Ye,11,this),er(this,Mo,Ft(Ye,12,this)),Ft(Ye,15,this),er(this,Io,Ft(Ye,16,this)),Ft(Ye,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return it(this,Ke,Vi)}get initial(){return it(this,Ke,Gi)}get previous(){return it(this,Ke,ic)}set current(e){const t=ne(()=>it(this,Ke,Vi));e&&t&&this.equals(t,e)||Ce(()=>{it(this,Ke,Gi)||Mt(this,Ke,e,Ui),Mt(this,Ke,t,Hi),Mt(this,Ke,e,Ki)})}reset(e=this.defaultValue){Ce(()=>{Mt(this,Ke,void 0,Hi),Mt(this,Ke,e,Ui),Mt(this,Ke,e,Ki)})}};Ye=Qf();Do=new WeakMap;Ke=new WeakSet;Mo=new WeakMap;Io=new WeakMap;pi=An(Ye,20,"#initial",sc,Ke,Do),Gi=pi.get,Ui=pi.set;gi=An(Ye,20,"#previous",rc,Ke,Mo),ic=gi.get,Hi=gi.set;mi=An(Ye,20,"#current",nc,Ke,Io),Vi=mi.get,Ki=mi.set;An(Ye,2,"current",tc,en);An(Ye,2,"initial",ec,en);An(Ye,2,"previous",Jl,en);Zl(Ye,en);function vi(e){return ne(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var zt,th=class{constructor(){er(this,zt,new WeakMap)}get(e,t){var n;return e?(n=it(this,zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return it(this,zt).has(e)||it(this,zt).set(e,new Map),(r=it(this,zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=it(this,zt).get(e))==null?void 0:t.clear():void 0}};zt=new WeakMap;var nh=Object.create,oc=Object.defineProperty,rh=Object.getOwnPropertyDescriptor,Na=Object.getOwnPropertySymbols,sh=Object.prototype.hasOwnProperty,ih=Object.prototype.propertyIsEnumerable,ac=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zs=e=>{throw TypeError(e)},Ga=Math.pow,qi=(e,t,n)=>t in e?oc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oh=(e,t)=>{for(var n in t||(t={}))sh.call(t,n)&&qi(e,n,t[n]);if(Na)for(var n of Na(t))ih.call(t,n)&&qi(e,n,t[n]);return e},ah=e=>{var t;return[,,,nh((t=e?.[ac("metadata")])!=null?t:null)]},lc=["class","method","getter","setter","accessor","field","value","get","set"],cc=e=>e!==void 0&&typeof e!="function"?Zs("Function expected"):e,lh=(e,t,n,r,s)=>({kind:lc[e],name:t,metadata:r,addInitializer:i=>n._?Zs("Already initialized"):s.push(cc(i||null))}),ch=(e,t)=>qi(t,ac("metadata"),e[3]),dh=(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,c,f,d=t&7,l=!1,u=!1,h=2,p=lc[d+5],v=e[h]||(e[h]=[]),x=(s=s.prototype,rh(s,n)),_=r.length-1;_>=0;_--)c=lh(d,n,a={},e[3],v),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(x[p],c),a._=1,cc(o)&&(x[p]=o);return x&&oc(s,n,x),s},uc=(e,t,n)=>t.has(e)||Zs("Cannot "+n),uh=(e,t,n)=>(uc(e,t,"read from private field"),t.get(e)),fh=(e,t,n)=>t.has(e)?Zs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),hh=(e,t,n,r)=>(uc(e,t,"write to private field"),t.set(e,n),n),ot=class Yi{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Yi(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 Yi(t,n)}},bt=class Wt{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,c=new Wt(s+t,r+n,i,o);return c.scale=oh({},a),c}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 ot((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Wt))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 Wt?ph(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 Wt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],c=o==="x"?i.left:i.top,f=o==="x"?i.width:i.height;return a=="start"?c:a=="end"?c+f:c+f/2};return ot.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Wt.from(t).intersectionRatio(Wt.from(n))}};function ph(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 fc,hc,Xi,ds,Ar,Js=class extends(Xi=en,hc=[Me],fc=[Me],Xi){constructor(t){const n=ot.from(t);super(n,(r,s)=>ot.equals(r,s)),dh(Ar,5,this),fh(this,ds,0),this.velocity={x:0,y:0}}get delta(){return ot.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=ot.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-uh(this,ds),a=c=>Math.round(c/o*100);Ce(()=>{hh(this,ds,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(ot.from(t)),this.velocity={x:0,y:0}}};Ar=ah(Xi);ds=new WeakMap;dc(Ar,2,"delta",hc,Js);dc(Ar,2,"direction",fc,Js);ch(Ar,Js);function Qi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Ga(r,2)+Ga(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 pc=(e=>(e.Horizontal="x",e.Vertical="y",e))(pc||{}),gc=Object.values(pc),gh=Object.create,jo=Object.defineProperty,mh=Object.defineProperties,vh=Object.getOwnPropertyDescriptor,yh=Object.getOwnPropertyDescriptors,Is=Object.getOwnPropertySymbols,mc=Object.prototype.hasOwnProperty,vc=Object.prototype.propertyIsEnumerable,yc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ln=e=>{throw TypeError(e)},Zi=(e,t,n)=>t in e?jo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Po=(e,t)=>{for(var n in t||(t={}))mc.call(t,n)&&Zi(e,n,t[n]);if(Is)for(var n of Is(t))vc.call(t,n)&&Zi(e,n,t[n]);return e},Ro=(e,t)=>mh(e,yh(t)),Ua=(e,t)=>jo(e,"name",{value:t,configurable:!0}),bc=(e,t)=>{var n={};for(var r in e)mc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Is)for(var r of Is(e))t.indexOf(r)<0&&vc.call(e,r)&&(n[r]=e[r]);return n},Bn=e=>{var t;return[,,,gh((t=e?.[yc("metadata")])!=null?t:null)]},xc=["class","method","getter","setter","accessor","field","value","get","set"],tr=e=>e!==void 0&&typeof e!="function"?Ln("Function expected"):e,bh=(e,t,n,r,s)=>({kind:xc[e],name:t,metadata:r,addInitializer:i=>n._?Ln("Already initialized"):s.push(tr(i||null))}),tn=(e,t)=>Zi(t,yc("metadata"),e[3]),Y=(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},se=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,v=xc[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&vh(l<4?s:{get[n](){return De(this,i)},set[n](w){return rt(this,i,w)}},n));l?h&&l<4&&Ua(i,(l>2?"set ":l>1?"get ":"")+n):Ua(s,n);for(var y=r.length-1;y>=0;y--)f=bh(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>xh(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?De:wc)(w,s,l^4?i:g.get):w=>w[n]),l>2&&(d.set=h?(w,b)=>rt(w,s,b,l^4?i:g.set):(w,b)=>w[n]=b)),a=(0,r[y])(l?l<4?h?i:g[v]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?tr(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Ln("Object expected"):(tr(o=a.get)&&(g.get=o),tr(o=a.set)&&(g.set=o),tr(o=a.init)&&x.unshift(o));return l||tn(e,s),g&&jo(s,n,g),h?l^4?i:g:s},Ao=(e,t,n)=>t.has(e)||Ln("Cannot "+n),xh=(e,t)=>Object(t)!==t?Ln('Cannot use the "in" operator on this value'):e.has(t),De=(e,t,n)=>(Ao(e,t,"read from private field"),n?n.call(e):t.get(e)),de=(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),rt=(e,t,n,r)=>(Ao(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),wc=(e,t,n)=>(Ao(e,t,"access private method"),n);function _c(e,t){return{plugin:e,options:t}}function Lr(e){return t=>_c(e,t)}function Sr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var kc,$r,Lo,us;kc=[re];var qe=class{constructor(e,t){this.manager=e,this.options=t,de(this,Lo,Y($r,8,this,!1)),Y($r,11,this),de(this,us,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ne(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=dt(e.bind(this));return De(this,us).add(t),t}destroy(){De(this,us).forEach(e=>e())}static configure(e){return _c(this,e)}};$r=Bn(null);Lo=new WeakMap;us=new WeakMap;se($r,4,"disabled",kc,qe,Lo);tn($r,qe);var Br=class extends qe{},fs,yi=class{constructor(e){this.manager=e,this.instances=new Map,de(this,fs,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Sr).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 De(this,fs))if(!n.includes(r)){if(r.prototype instanceof Br)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);rt(this,fs,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()}};fs=new WeakMap;function wh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Jr=[],hn,pn,_h=class extends qe{constructor(e){super(e),de(this,hn),de(this,pn),this.computeCollisions=this.computeCollisions.bind(this),rt(this,pn,jn(Jr)),this.destroy=Rr(()=>{const t=this.computeCollisions(),n=ne(()=>this.manager.dragOperation.position.current);if(t!==Jr){const r=De(this,hn);if(rt(this,hn,n),r&&n.x==r.x&&n.y==r.y)return}else rt(this,hn,void 0);De(this,pn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ne(()=>{e?De(this,pn).value=this.computeCollisions():rt(this,hn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Jr;const a=[],c=[];for(const f of e??n.droppables){if(f.disabled||s&&!f.accepts(s))continue;const d=t??f.collisionDetector;if(!d)continue;c.push(f),f.shape;const l=ne(()=>d({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return c.length===0?Jr:(a.sort(wh),a)}get collisions(){return De(this,pn).value}};hn=new WeakMap;pn=new WeakMap;var Sc,$c,Tc,Bo,Ec,ht,Fo,xn,zo,Wo;Tc=[re],$c=[re],Sc=[re];var $t=class Nt{constructor(t,n){de(this,Fo,Y(ht,8,this)),Y(ht,11,this),de(this,xn),de(this,zo,Y(ht,12,this)),Y(ht,15,this),de(this,Wo,Y(ht,16,this)),Y(ht,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let c=s;rt(this,xn,jn(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var f;return[()=>{const{id:d,manager:l}=this;if(d!==c)return c=d,l?.registry.register(this),()=>l?.registry.unregister(this)},...(f=r?.())!=null?f:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=De(this,xn).value;return(n=(t=Nt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=Nt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:De(this,xn).peek();t!==s&&(Nt.pendingIdChanges||(Nt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return wc(i=Nt,Bo,Ec).call(i)})),Nt.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)}};ht=Bn(null);Bo=new WeakSet;Ec=function(){const e=$t.pendingIdChanges;$t.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)De(t,xn).value=n})};Fo=new WeakMap;xn=new WeakMap;zo=new WeakMap;Wo=new WeakMap;se(ht,4,"manager",Tc,$t,Fo);se(ht,4,"data",$c,$t,zo);se(ht,4,"disabled",Sc,$t,Wo);de($t,Bo);tn(ht,$t);$t.pendingIdChanges=null;var ei=$t,Ha=class{constructor(){this.map=jn(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,c]of n)if(c===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Rr(...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,Oc,Dc,Mc,Ic,jc,Ji,Xe,No,Go,Uo,xt=class extends(Ji=ei,jc=[re],Ic=[re],Mc=[re],Dc=[Me],Oc=[Me],Cc=[Me],Ji){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:c}=r,f=bc(r,["modifiers","type","sensors","plugins","effects"]);super(Ro(Po({},f),{effects:()=>{var d;return[...(d=c?.())!=null?d:[],()=>{const{manager:l,plugins:u}=this;if(!(!l||!u))for(const h of u){const{plugin:p}=Sr(h);l.registry.plugins.register(p)}}]}}),n),Y(Xe,5,this),de(this,No,Y(Xe,8,this)),Y(Xe,11,this),de(this,Go,Y(Xe,12,this)),Y(Xe,15,this),de(this,Uo,Y(Xe,16,this,this.isDragSource?"dragging":"idle")),Y(Xe,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=f.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=Sr(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}};Xe=Bn(Ji);No=new WeakMap;Go=new WeakMap;Uo=new WeakMap;se(Xe,4,"type",jc,xt,No);se(Xe,4,"modifiers",Ic,xt,Go);se(Xe,4,"status",Mc,xt,Uo);se(Xe,2,"isDropping",Dc,xt);se(Xe,2,"isDragging",Oc,xt);se(Xe,2,"isDragSource",Cc,xt);tn(Xe,xt);var Pc,Rc,Ac,Lc,Bc,Fc,eo,Be,Ho,Vo,Ko,qo,Yo,wt=class extends(eo=ei,Fc=[re],Bc=[re],Lc=[re],Ac=[re],Rc=[re],Pc=[Me],eo){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,c=bc(r,["accept","collisionDetector","collisionPriority","type"]);super(c,n),Y(Be,5,this),de(this,Ho,Y(Be,8,this)),Y(Be,11,this),de(this,Vo,Y(Be,12,this)),Y(Be,15,this),de(this,Ko,Y(Be,16,this)),Y(Be,19,this),de(this,qo,Y(Be,20,this)),Y(Be,23,this),de(this,Yo,Y(Be,24,this)),Y(Be,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}};Be=Bn(eo);Ho=new WeakMap;Vo=new WeakMap;Ko=new WeakMap;qo=new WeakMap;Yo=new WeakMap;se(Be,4,"accept",Fc,wt,Ho);se(Be,4,"type",Bc,wt,Vo);se(Be,4,"collisionDetector",Lc,wt,Ko);se(Be,4,"collisionPriority",Ac,wt,qo);se(Be,4,"shape",Rc,wt,Yo);se(Be,2,"isDropTarget",Pc,wt);tn(Be,wt);var kh=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)}},Sh=class extends kh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function hs(e,t=!0){let n=!1;return Ro(Po({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var $h=class extends Br{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Rr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||ei.pendingIdChanges)return;const o=hs({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;ne(()=>{var c;a?.id!==((c=e.dragOperation.target)==null?void 0:c.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Fn=(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))(Fn||{}),zn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(zn||{}),zc,Wc,Nc,Gc,Uc,Hc,Vc,ct,Xo;Vc=[re],Hc=[Me],Uc=[Me],Gc=[Me],Nc=[Me],Wc=[Me],zc=[Me];var Et=class{constructor(){Y(ct,5,this),de(this,Xo,Y(ct,8,this,"idle")),Y(ct,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}};ct=Bn(null);Xo=new WeakMap;se(ct,4,"value",Vc,Et,Xo);se(ct,2,"current",Hc,Et);se(ct,2,"idle",Uc,Et);se(ct,2,"initializing",Gc,Et);se(ct,2,"initialized",Nc,Et);se(ct,2,"dragging",Wc,Et);se(ct,2,"dropped",zc,Et);tn(ct,Et);var Th=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 ne(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=hs({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ne(()=>{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;Ce(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=hs({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"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return ne(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=hs({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,c,f,d,l;if(o.defaultPrevented)return;const u=(l=e.to)!=null?l:{x:r.position.current.x+((c=(a=e.by)==null?void 0:a.x)!=null?c:0),y:r.position.current.y+((d=(f=e.by)==null?void 0:f.y)!=null?d:0)};r.position.current=u})})}stop(e={}){return ne(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const c={resume:()=>{},abort:()=>{}};return i=new Promise((f,d)=>{c.resume=f,c.abort=d}),c};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const c=ne(()=>{var d;return((d=r.source)==null?void 0:d.status)==="dropping"}),f=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(c){const{source:d}=r,l=dt(()=>{d?.status==="idle"&&(l(),f())})}else this.manager.renderer.rendering.then(f)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),i?i.then(a).catch(()=>r.reset()):a()})}},En=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Eh=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)}},ps,Kc=class{constructor(e){this.options=e,de(this,ps)}set controller(e){rt(this,ps,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=De(this,ps))==null||t.activate(e)}};ps=new WeakMap;var Va=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Ch=class{constructor(e){this.draggables=new Ha,this.droppables=new Ha,this.plugins=new yi(e),this.sensors=new yi(e),this.modifiers=new yi(e)}register(e,t){if(e instanceof xt)return this.draggables.register(e.id,e);if(e instanceof wt)return this.droppables.register(e.id,e);if(e.prototype instanceof Va)return this.modifiers.register(e,t);if(e.prototype instanceof En)return this.sensors.register(e,t);if(e.prototype instanceof qe)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof ei)return e instanceof xt?this.draggables.unregister(e.id,e):e instanceof wt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Va)return this.modifiers.unregister(e);if(e.prototype instanceof En)return this.sensors.unregister(e);if(e.prototype instanceof qe)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},qc,Yc,Xc,Qc,Zc,Jc,ed,td,nd,nr,gs,gn,Ee,Qo,Zo,Jo,ea,ta,rr;nd=[Me],td=[re],ed=[re],Jc=[re],Zc=[re],Qc=[re],Xc=[Me],Yc=[Me],qc=[Me];var mt=class{constructor(e){Y(Ee,5,this),de(this,nr),de(this,gs),de(this,gn,new en(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Et,de(this,Qo,Y(Ee,8,this,!1)),Y(Ee,11,this),de(this,Zo,Y(Ee,12,this,null)),Y(Ee,15,this),de(this,Jo,Y(Ee,16,this,null)),Y(Ee,19,this),de(this,ea,Y(Ee,20,this,null)),Y(Ee,23,this),de(this,ta,Y(Ee,24,this,[])),Y(Ee,27,this),this.position=new Js({x:0,y:0}),de(this,rr,{x:0,y:0}),rt(this,nr,e)}get shape(){const{current:e,initial:t,previous:n}=De(this,gn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?De(this,gn).current=e:De(this,gn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=De(this,nr).registry.draggables.get(t);return n&&rt(this,gs,n),(e=n??De(this,gs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=De(this,nr).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(Ro(Po({},this.snapshot()),{transform:n}));return rt(this,rr,n),n}snapshot(){return ne(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:De(this,rr),shape:this.shape?vi(this.shape):null,position:vi(this.position),status:vi(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,De(this,gn).reset(),this.position.reset({x:0,y:0}),rt(this,rr,{x:0,y:0}),this.modifiers=[]})}};Ee=Bn(null);nr=new WeakMap;gs=new WeakMap;gn=new WeakMap;Qo=new WeakMap;Zo=new WeakMap;Jo=new WeakMap;ea=new WeakMap;ta=new WeakMap;rr=new WeakMap;se(Ee,2,"shape",nd,mt);se(Ee,4,"canceled",td,mt,Qo);se(Ee,4,"activatorEvent",ed,mt,Zo);se(Ee,4,"sourceIdentifier",Jc,mt,Jo);se(Ee,4,"targetIdentifier",Zc,mt,ea);se(Ee,4,"modifiers",Qc,mt,ta);se(Ee,2,"source",Xc,mt);se(Ee,2,"target",Yc,mt);se(Ee,2,"transform",qc,mt);tn(Ee,mt);var Oh={get rendering(){return Promise.resolve()}};function gt(e,t){return typeof e=="function"?e(t):e??t}var Dh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(u=>u.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=gt(r.plugins,[]),i=gt(r.sensors,[]),o=gt(r.modifiers,[]),a=(n=r.renderer)!=null?n:Oh,c=new Sh(this),f=new Ch(this);this.registry=f,this.monitor=c,this.renderer=a,this.actions=new Th(this),this.dragOperation=new mt(this),this.collisionObserver=new _h(this),this.plugins=[$h,...s],this.modifiers=o,this.sensors=i;const{destroy:d}=this,l=Rr(()=>{var u,h,p;const v=ne(()=>this.dragOperation.modifiers),x=this.modifiers;for(const _ of v)x.includes(_)||_.destroy();this.dragOperation.modifiers=(p=(h=(u=this.dragOperation.source)==null?void 0:u.modifiers)==null?void 0:h.map(_=>{const{plugin:g,options:y}=Sr(_);return new g(this,y)}))!=null?p:x});this.destroy=()=>{l(),d()}}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}},rd=e=>{throw TypeError(e)},na=(e,t,n)=>t.has(e)||rd("Cannot "+n),q=(e,t,n)=>(na(e,t,"read from private field"),t.get(e)),Je=(e,t,n)=>t.has(e)?rd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),nt=(e,t,n,r)=>(na(e,t,"write to private field"),t.set(e,n),n),sd=(e,t,n)=>(na(e,t,"access private method"),n);function ti(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function id(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(ti(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function ni(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 ra(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Fr(e){return"nodeType"in e}function st(e){var t,n,r;return e?ra(e)?e:Fr(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 sa(e){const{Document:t}=st(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function At(e){return!e||ra(e)?!1:e instanceof st(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function od(e){return e instanceof st(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Wn(e){return e?ra(e)?e.document:Fr(e)?sa(e)?e:At(e)||od(e)?e.ownerDocument:document:document:document}function Mh(e){var t,n,r,s;const{documentElement:i}=Wn(e),o=st(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,c=(n=o?.height)!=null?n:i.clientHeight,f=(r=o?.offsetTop)!=null?r:0,d=(s=o?.offsetLeft)!=null?s:0;return{top:f,left:d,right:d+a,bottom:f+c,width:a,height:c}}function Ih(e,t){if(jh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function jh(e){return e.tagName==="DETAILS"}function Tr(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let c=t;const{ownerDocument:f}=e,d=(r=f.defaultView)!=null?r:window;let l=e.parentElement;for(;l&&l!==f.documentElement;){if(!Ih(l)){const y=l.getBoundingClientRect(),w=n*(y.bottom-y.top),b=n*(y.right-y.left),T=n*(y.bottom-y.top),C=n*(y.right-y.left);c={top:Math.max(c.top,y.top-w),right:Math.min(c.right,y.right+b),bottom:Math.min(c.bottom,y.bottom+T),left:Math.max(c.left,y.left-C),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top}l=l.parentElement}const u=d.visualViewport,h=(s=u?.offsetTop)!=null?s:0,p=(i=u?.offsetLeft)!=null?i:0,v=(o=u?.width)!=null?o:d.innerWidth,x=(a=u?.height)!=null?a:d.innerHeight,_=n*x,g=n*v;return c={top:Math.max(c.top,h-_),right:Math.min(c.right,p+v+g),bottom:Math.min(c.bottom,h+x+_),left:Math.max(c.left,p-g),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top,c.width<0&&(c.width=0),c.height<0&&(c.height=0),c}function Cn(e){return{x:e.clientX,y:e.clientY}}var ad=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function to(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(...to(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(...to(s.document,t))}}catch{}return n}function ia(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ld(){var e,t;const n=ia()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function oa(e){return!e||!Fr(e)?!1:e instanceof st(e).ShadowRoot}function js(e){if(e&&Fr(e)){let t=e.getRootNode();if(oa(t))return t;if(t instanceof Document)return t}return Wn(e)}function aa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Ph(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}`)),qa(i)&&qa(a)&&a.width>0&&a.height>0){const c=i.getContext("2d");c?.drawImage(a,0,0)}}),n}function Ka(e){return"value"in e}function qa(e){return e.tagName==="CANVAS"}function cd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Rh(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return cd(s,{x:t-i,y:n-o})}}return r}function Rh(e){return e?.tagName==="IFRAME"}var no=new WeakMap;function Ah(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 dd=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:c,listener:f,options:d}=a,l=[o,a];o.addEventListener(c,f,d),this.entries.add(l),s.push(l)}const i=this.entries;return function(){for(const a of s){const[c,{type:f,listener:d,options:l}]=a;c.removeEventListener(f,d,l),i.delete(a)}}}};function Cn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Lh(e){const t=new Set;let n=Cn(e);for(;n;)t.add(n),n=Cn(n);return t}function Bh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function ud(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=Bh(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Fh(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 zh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Cr(e,t);return n>0&&r>0}var Wh=ad?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ps,Nh=class extends Wh{constructor(e){super(t=>{if(!K(this,ps)){et(this,ps,!0);return}e(t,this)}),Ze(this,ps,!1)}};ps=new WeakMap;var Ya=Array.from({length:100},(e,t)=>t/100),fd=75,Gt,Is,Ct,Vt,or,Ue,wr,ar,js,hd,pd,gd=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ze(this,js),this.disconnect=()=>{var i,o,a;et(this,wr,!0),(i=K(this,Ct))==null||i.disconnect(),(o=K(this,Vt))==null||o.disconnect(),K(this,or).disconnect(),(a=K(this,Ue))==null||a.remove()},Ze(this,Gt,!0),Ze(this,Is),Ze(this,Ct),Ze(this,Vt),Ze(this,or),Ze(this,Ue),Ze(this,wr,!1),Ze(this,ar,ud(()=>{var i,o,a;const{element:c}=this;if((i=K(this,Vt))==null||i.disconnect(),K(this,wr)||!K(this,Gt)||!c.isConnected)return;const f=(o=c.ownerDocument)!=null?o:document,{innerHeight:d,innerWidth:l}=(a=f.defaultView)!=null?a:window,u=c.getBoundingClientRect(),h=Cr(c,u),{top:p,left:y,bottom:w,right:_}=h,g=-Math.floor(p),v=-Math.floor(y),x=-Math.floor(l-_),b=-Math.floor(d-w),T=`${g}px ${x}px ${b}px ${v}px`;this.boundingClientRect=u,et(this,Vt,new IntersectionObserver(C=>{const[M]=C,{intersectionRect:E}=M;(M.intersectionRatio!==1?M.intersectionRatio:yt.intersectionRatio(E,Cr(c)))!==1&&K(this,ar).call(this)},{threshold:Ya,rootMargin:T,root:f})),K(this,Vt).observe(c),sd(this,js,hd).call(this)},fd)),this.boundingClientRect=e.getBoundingClientRect(),et(this,Gt,zh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(et(this,Ue,document.createElement("div")),K(this,Ue).style.background="rgba(0,0,0,0.15)",K(this,Ue).style.position="fixed",K(this,Ue).style.pointerEvents="none",s.body.appendChild(K(this,Ue))),et(this,or,new IntersectionObserver(i=>{var o,a;const c=i[i.length-1],{boundingClientRect:f,isIntersecting:d}=c,{width:l,height:u}=f,h=K(this,Gt);et(this,Gt,d),!(!l&&!u)&&(h&&!d?((o=K(this,Vt))==null||o.disconnect(),this.callback(null),(a=K(this,Ct))==null||a.disconnect(),et(this,Ct,void 0),K(this,Ue)&&(K(this,Ue).style.visibility="hidden")):K(this,ar).call(this),d&&!K(this,Ct)&&(et(this,Ct,new Nh(K(this,ar))),K(this,Ct).observe(e)))},{threshold:Ya,root:s})),K(this,Gt)&&!n.skipInitial&&this.callback(this.boundingClientRect),K(this,or).observe(e)}};Gt=new WeakMap;Is=new WeakMap;Ct=new WeakMap;Vt=new WeakMap;or=new WeakMap;Ue=new WeakMap;wr=new WeakMap;ar=new WeakMap;js=new WeakSet;hd=function(){K(this,wr)||(sd(this,js,pd).call(this),!Fh(this.boundingClientRect,K(this,Is))&&(this.callback(this.boundingClientRect),et(this,Is,this.boundingClientRect)))};pd=function(){if(K(this,Ue)){const{top:e,left:t,width:n,height:r}=Cr(this.element);K(this,Ue).style.overflow="hidden",K(this,Ue).style.visibility="visible",K(this,Ue).style.top=`${Math.floor(e)}px`,K(this,Ue).style.left=`${Math.floor(t)}px`,K(this,Ue).style.width=`${Math.floor(n)}px`,K(this,Ue).style.height=`${Math.floor(r)}px`}};var Zr=new WeakMap,Jr=new WeakMap;function Gh(e,t){let n=Zr.get(e);return n||(n={disconnect:new gd(e,s=>{const i=Zr.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Zr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Zr.delete(e),n.disconnect())}}function Vh(e,t){const n=new Set;for(const r of e){const s=Gh(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Uh(e,t){var n;const r=e.ownerDocument;if(!Jr.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",c=>a.forEach(f=>f(c)),{capture:!0,passive:!0,signal:o.signal}),Jr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=Jr.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),Jr.delete(r))})}var lr,cr,gs,no,Hh=class{constructor(e,t,n){this.callback=t,Ze(this,lr),Ze(this,cr,!1),Ze(this,gs),Ze(this,no,ud(o=>{if(!K(this,cr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of K(this,gs))if(o.target.contains(a)){this.callback(K(this,lr).boundingClientRect);break}}},fd));const r=Lh(e),s=Vh(r,t),i=Uh(e,K(this,no));et(this,gs,r),et(this,lr,new gd(e,t,n)),this.disconnect=()=>{K(this,cr)||(et(this,cr,!0),s(),i(),K(this,lr).disconnect())}}};lr=new WeakMap;cr=new WeakMap;gs=new WeakMap;no=new WeakMap;function ro(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function kn(e){try{ro(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Xa(e){return!ad||!e?!1:e===zn(e).scrollingElement}function md(e){var t,n;const r=nt(e),s=Xa(e)?Mh(e):ei(e),i=r.visualViewport,o=Xa(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}},c=a.current.y<=0,f=a.current.x<=0,d=a.current.y>=a.max.y,l=a.current.x>=a.max.x;return{rect:s,position:a,isTop:c,isLeft:f,isBottom:d,isRight:l}}function qh(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=md(e),{x:a,y:c}=t??{x:0,y:0},f=!n&&o.current.y+c>0,d=!r&&o.current.y+c<o.max.y,l=!s&&o.current.x+a>0,u=!i&&o.current.x+a<o.max.x;return{top:f,bottom:d,left:l,right:u,x:l||u,y:f||d}}var aa=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))}},Ps=new aa(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Kh=new aa(e=>setTimeout(e,50)),Rs=new Map,Yh=Rs.clear.bind(Rs);function wt(e,t=!1){if(!t)return Qa(e);let n=Rs.get(e);return n||(n=Qa(e),Rs.set(e,n),Kh.schedule(Yh),n)}function Qa(e){return nt(e).getComputedStyle(e)}function Xh(e,t=wt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Qh(e,t=wt(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 Zh={excludeElement:!0,escapeShadowDOM:!0};function so(e,t=Zh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(ra(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&ia(a))return o(a.host);if(!Rt(a))return od(a)?o(a.parentElement):i;if(i.has(a))return i;const c=wt(a,!0);if(r&&a===e||Qh(a,c)&&i.add(a),Xh(a,c)){const{scrollingElement:f}=a.ownerDocument;return f&&i.add(f),i}return o(a.parentNode)}return e?o(e):i}function On(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Cn(e);for(;r;){if(r===t)return n;const s=ei(r),{x:i,y:o}=Jh(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=Cn(r)}return n}function Jh(e,t=ei(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Rt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=wt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function ep(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function Or(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),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 ti(e){var t,n,r,s,i,o,a,c,f;const{scale:d,transform:l,translate:u}=e,h=ep(d),p=Or(u),y=tp(l);if(!y&&!h&&!p)return null;const w={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},_={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},g={x:(i=y?.x)!=null?i:0,y:(o=y?.y)!=null?o:0,scaleX:(a=y?.scaleX)!=null?a:1,scaleY:(c=y?.scaleY)!=null?c:1};return{x:_.x+g.x,y:_.y+g.y,z:(f=p?.z)!=null?f:0,scaleX:w.x*g.scaleX,scaleY:w.y*g.scaleY}}function tp(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 ot=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(ot||{}),np={x:.2,y:.2},rp={x:10,y:10};function sp(e,t,n,r=25,s=np,i=rp){const{x:o,y:a}=t,{rect:c,isTop:f,isBottom:d,isLeft:l,isRight:u}=md(e),h=On(e),p=wt(e,!0),y=ti(p),w=y!==null?y?.scaleX<0:!1,_=y!==null?y?.scaleY<0:!1,g=new yt(c.left*h.scaleX+h.x,c.top*h.scaleY+h.y,c.width*h.scaleX,c.height*h.scaleY),v={x:0,y:0},x={x:0,y:0},b={height:g.height*s.y,width:g.width*s.x};return b.height>0&&(!f||_&&!d)&&a<=g.top+b.height&&n?.y!==1&&o>=g.left-i.x&&o<=g.right+i.x?(v.y=_?1:-1,x.y=r*Math.abs((g.top+b.height-a)/b.height)):b.height>0&&(!d||_&&!f)&&a>=g.bottom-b.height&&n?.y!==-1&&o>=g.left-i.x&&o<=g.right+i.x&&(v.y=_?-1:1,x.y=r*Math.abs((g.bottom-b.height-a)/b.height)),b.width>0&&(!u||w&&!l)&&o>=g.right-b.width&&n?.x!==-1&&a>=g.top-i.y&&a<=g.bottom+i.y?(v.x=w?-1:1,x.x=r*Math.abs((g.right-b.width-o)/b.width)):b.width>0&&(!l||w&&!u)&&o<=g.left+b.width&&n?.x!==1&&a>=g.top-i.y&&a<=g.bottom+i.y&&(v.x=w?1:-1,x.x=r*Math.abs((g.left+b.width-o)/b.width)),{direction:v,speed:x}}function vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Rt(e))return;const r=so(e),s=[];for(const i of r){if(!Rt(i))continue;const{top:o,left:a}=ip(e,i);let c=o,f=a;for(const d of s)c-=d.scrollTop,f-=d.scrollLeft;if(t!=="none"){const d=c<i.scrollTop,l=c+e.offsetHeight>i.scrollTop+i.clientHeight;d!==l&&(t==="center"?i.scrollTop=c-i.clientHeight/2+e.offsetHeight/2:d?i.scrollTop=c:i.scrollTop=c+e.offsetHeight-i.clientHeight)}if(n!=="none"){const d=f<i.scrollLeft,l=f+e.offsetWidth>i.scrollLeft+i.clientWidth;d!==l&&(n==="center"?i.scrollLeft=f-i.clientWidth/2+e.offsetWidth/2:d?i.scrollLeft=f:i.scrollLeft=f+e.offsetWidth-i.clientWidth)}s.push(i)}}function Za(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Rt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function ip(e,t){const n=Za(e),r=Za(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function op(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),c=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width*r:e.width,d=s?e.height*s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function ap(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),c=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width/r:e.width,d=s?e.height/s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function yd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Ja(e,t=wt(e).translate,n=!0){if(n){const r=id(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=Or(s);if(i)return i}}}if(t){const r=Or(t);if(r)return r}return{x:0,y:0,z:0}}var lp=new aa(e=>setTimeout(e,0)),_r=new Map,cp=_r.clear.bind(_r);function dp(e){const t=e.ownerDocument;let n=_r.get(t);if(n)return n;n=t.getAnimations(),_r.set(t,n),lp.schedule(cp);const r=n.filter(s=>Js(s.effect)&&s.effect.target===e);return _r.set(e,r),n}function up(e,t){const n=dp(e).filter(r=>{var s,i;if(Js(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(c=>{for(const f of t.properties)if(c[f])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 vt=class extends yt{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=On(e),ignoreTransforms:a,getBoundingClientRect:c=ei}=t,f=up(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||sa())&&b.contains(e)}),d=c(e);let{top:l,left:u,width:h,height:p}=d,y;const w=wt(e),_=ti(w),g={x:(n=_?.scaleX)!=null?n:1,y:(r=_?.scaleY)!=null?r:1},v=fp(e,w);f?.(),_&&(y=ap(d,_,w.transformOrigin),(a||v)&&(l=y.top,u=y.left,h=y.width,p=y.height));const x={width:(s=y?.width)!=null?s:h,height:(i=y?.height)!=null?i:p};if(v&&!a&&y){const b=op(y,v,w.transformOrigin);l=b.top,u=b.left,h=b.width,p=b.height,g.x=v.scaleX,g.y=v.scaleY}o&&(a||(u*=o.scaleX,h*=o.scaleX,l*=o.scaleY,p*=o.scaleY),u+=o.x,l+=o.y),super(u,l,h,p),this.scale=g,this.intrinsicWidth=x.width,this.intrinsicHeight=x.height}};function fp(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 c=Js(a.effect)?a.effect.getKeyframes():[],f=c[c.length-1];if(!f)continue;const{transform:d,translate:l,scale:u}=f;typeof d=="string"&&d&&(r=d,o=!0),typeof l=="string"&&l&&(s=l,o=!0),typeof u=="string"&&u&&(i=u,o=!0)}return o?ti({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function kr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var hp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(kr(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(kr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(kr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Qt(e){return e?e instanceof nt(e).Element||Wr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Dr(e){if(!e)return!1;const{KeyboardEvent:t}=nt(e.target);return e instanceof t}function pp(e){if(!e)return!1;const{PointerEvent:t}=nt(e.target);return e instanceof t}function gp(e){if(!Qt(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||mp(e)}function mp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var yi={};function io(e){const t=yi[e]==null?0:yi[e]+1;return yi[e]=t,`${e}-${t}`}var la=({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=it.distance(t.shape.center,n);return{id:r,value:1/s,type:Fn.PointerIntersection,priority:Bn.High}}return null},vp=({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=it.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Fn.ShapeIntersection,priority:Bn.Normal}}return null},bd=e=>{var t;return(t=la(e))!=null?t:vp(e)},yp=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?yt.from(r.current.boundingRectangle).corners:void 0,a=yt.from(n.shape.boundingRectangle).corners.reduce((c,f,d)=>{var l;return c+it.distance(it.from(f),(l=i?.[d])!=null?l:s.current)},0)/4;return{id:n.id,value:1/a,type:Fn.Collision,priority:Bn.Normal}},bp=Object.create,ca=Object.defineProperty,xp=Object.defineProperties,wp=Object.getOwnPropertyDescriptor,_p=Object.getOwnPropertyDescriptors,As=Object.getOwnPropertySymbols,xd=Object.prototype.hasOwnProperty,wd=Object.prototype.propertyIsEnumerable,_d=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Wn=e=>{throw TypeError(e)},oo=(e,t,n)=>t in e?ca(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mr=(e,t)=>{for(var n in t||(t={}))xd.call(t,n)&&oo(e,n,t[n]);if(As)for(var n of As(t))wd.call(t,n)&&oo(e,n,t[n]);return e},da=(e,t)=>xp(e,_p(t)),el=(e,t)=>ca(e,"name",{value:t,configurable:!0}),kd=(e,t)=>{var n={};for(var r in e)xd.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&&wd.call(e,r)&&(n[r]=e[r]);return n},Nn=e=>{var t;return[,,,bp((t=e?.[_d("metadata")])!=null?t:null)]},Sd=["class","method","getter","setter","accessor","field","value","get","set"],dr=e=>e!==void 0&&typeof e!="function"?Wn("Function expected"):e,kp=(e,t,n,r,s)=>({kind:Sd[e],name:t,metadata:r,addInitializer:i=>n._?Wn("Already initialized"):s.push(dr(i||null))}),nn=(e,t)=>oo(t,_d("metadata"),e[3]),Ne=(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},dt=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,y=Sd[l+5],w=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&wp(l<4?s:{get[n](){return ge(this,i)},set[n](x){return Xe(this,i,x)}},n));l?h&&l<4&&el(i,(l>2?"set ":l>1?"get ":"")+n):el(s,n);for(var v=r.length-1;v>=0;v--)f=kp(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?x=>Sp(s,x):x=>n in x},l^3&&(d.get=h?x=>(l^1?ge:Zt)(x,s,l^4?i:g.get):x=>x[n]),l>2&&(d.set=h?(x,b)=>Xe(x,s,b,l^4?i:g.set):(x,b)=>x[n]=b)),a=(0,r[v])(l?l<4?h?i:g[y]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?dr(a)&&(l>4?w.unshift(a):l?h?i=a:g[y]=a:s=a):typeof a!="object"||a===null?Wn("Object expected"):(dr(o=a.get)&&(g.get=o),dr(o=a.set)&&(g.set=o),dr(o=a.init)&&w.unshift(o));return l||nn(e,s),g&&ca(s,n,g),h?l^4?i:g:s},ua=(e,t,n)=>t.has(e)||Wn("Cannot "+n),Sp=(e,t)=>Object(t)!==t?Wn('Cannot use the "in" operator on this value'):e.has(t),ge=(e,t,n)=>(ua(e,t,"read from private field"),n?n.call(e):t.get(e)),je=(e,t,n)=>t.has(e)?Wn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Xe=(e,t,n,r)=>(ua(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zt=(e,t,n)=>(ua(e,t,"access private method"),n),tl={role:"button",roleDescription:"draggable"},$p="dnd-kit-description",Tp="dnd-kit-announcement",Ep={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."},Cp={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 Op(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Dp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Mp(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 Ip=["dragover","dragmove"],jp=class extends qe{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=$p,announcement:s=Tp}={},announcements:i=Cp,screenReaderInstructions:o=Ep,debounce:a=500}=t??{},c=n?`${r}-${n}`:io(r),f=n?`${s}-${n}`:io(s);let d,l,u,h;const p=(b=h)=>{!u||!b||u?.nodeValue!==b&&(u.nodeValue=b)},y=()=>Ps.schedule(p),w=Pp(y,a),_=Object.entries(i).map(([b,T])=>this.manager.monitor.addEventListener(b,(C,M)=>{const E=u;if(!E)return;const O=T?.(C,M);O&&E.nodeValue!==O&&(h=O,Ip.includes(b)?w():(y(),w.cancel()))})),g=()=>{let b=[];d?.isConnected||(d=Dp(c,o.draggable),b.push(d)),l?.isConnected||(l=Mp(f),u=document.createTextNode(""),l.appendChild(u),b.push(l)),b.length>0&&document.body.append(...b)},v=new Set;function x(){for(const b of v)b()}this.registerEffect(()=>{var b;v.clear();for(const T of this.manager.registry.draggables.value){const C=(b=T.handle)!=null?b:T.element;if(C){(!d||!l)&&v.add(g),(!Op(C)||sa())&&!C.hasAttribute("tabindex")&&v.add(()=>C.setAttribute("tabindex","0")),!C.hasAttribute("role")&&C.tagName.toLowerCase()!=="button"&&v.add(()=>C.setAttribute("role",tl.role)),C.hasAttribute("aria-roledescription")||v.add(()=>C.setAttribute("aria-roledescription",tl.roleDescription)),C.hasAttribute("aria-describedby")||v.add(()=>C.setAttribute("aria-describedby",c));for(const E of["aria-pressed","aria-grabbed"]){const O=String(T.isDragging);C.getAttribute(E)!==O&&v.add(()=>C.setAttribute(E,O))}const M=String(T.disabled);C.getAttribute("aria-disabled")!==M&&v.add(()=>C.setAttribute("aria-disabled",M))}}v.size>0&&Ps.schedule(x)}),this.destroy=()=>{super.destroy(),d?.remove(),l?.remove(),_.forEach(b=>b())}}};function Pp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Ls=new Map,$d,Td,Ed,Cd,ao,Sr,kt,fa,Dn,Od,Dd,Md,Id,At=class extends(ao=zr,Cd=[ne],Ed=[De],Td=[De],$d=[De],ao){constructor(t,n){super(t,n),Ne(kt,5,this),je(this,Dn),je(this,Sr,new Set),je(this,fa,Ne(kt,8,this,new Set)),Ne(kt,11,this),this.registerEffect(Zt(this,Dn,Od))}register(t){return ge(this,Sr).add(t),()=>{ge(this,Sr).delete(t)}}addRoot(t){return te(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{te(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Ms((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Ms((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}};kt=Nn(ao);Sr=new WeakMap;fa=new WeakMap;Dn=new WeakSet;Od=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ge(this,Sr))t.push(Zt(this,Dn,Dd).call(this,n,r));return()=>{for(const n of t)n()}};Dd=function(e,t){let n=Ls.get(e);n||(n=new Map,Ls.set(e,n));let r=n.get(t);if(!r){const i=ra(e)?Zt(this,Dn,Md).call(this,e,n,t):Zt(this,Dn,Id).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())}};Md=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 c of a)for(const f of Array.from(c.removedNodes))if(f===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&&Ls.delete(e)}}};Id=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(ia(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&&Ls.delete(e)}}};dt(kt,4,"additionalRoots",Cd,At,fa);dt(kt,2,"sourceRoot",Ed,At);dt(kt,2,"targetRoot",Td,At);dt(kt,2,"roots",$d,At);nn(kt,At);At.configure=Fr(At);var ni=At,Rp=class extends qe{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(ni),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},Nr="data-dnd-",lo=`${Nr}dropping`,Ve="--dnd-",mt=`${Nr}dragging`,Bs=`${Nr}placeholder`,Ap=[mt,Bs,"popover","aria-pressed","aria-grabbing"],Lp=["view-transition-name"],Bp=`
|
|
9
|
-
:is(:root,:host) [${
|
|
8
|
+
`)}var dd=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:c,listener:f,options:d}=a,l=[o,a];o.addEventListener(c,f,d),this.entries.add(l),s.push(l)}const i=this.entries;return function(){for(const a of s){const[c,{type:f,listener:d,options:l}]=a;c.removeEventListener(f,d,l),i.delete(a)}}}};function On(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Lh(e){const t=new Set;let n=On(e);for(;n;)t.add(n),n=On(n);return t}function Bh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function ud(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=Bh(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Fh(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 zh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Tr(e,t);return n>0&&r>0}var Wh=ad?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ms,Nh=class extends Wh{constructor(e){super(t=>{if(!q(this,ms)){nt(this,ms,!0);return}e(t,this)}),Je(this,ms,!1)}};ms=new WeakMap;var Ya=Array.from({length:100},(e,t)=>t/100),fd=75,Gt,Ps,Ot,Ut,sr,Ve,br,ir,Rs,hd,pd,gd=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Je(this,Rs),this.disconnect=()=>{var i,o,a;nt(this,br,!0),(i=q(this,Ot))==null||i.disconnect(),(o=q(this,Ut))==null||o.disconnect(),q(this,sr).disconnect(),(a=q(this,Ve))==null||a.remove()},Je(this,Gt,!0),Je(this,Ps),Je(this,Ot),Je(this,Ut),Je(this,sr),Je(this,Ve),Je(this,br,!1),Je(this,ir,ud(()=>{var i,o,a;const{element:c}=this;if((i=q(this,Ut))==null||i.disconnect(),q(this,br)||!q(this,Gt)||!c.isConnected)return;const f=(o=c.ownerDocument)!=null?o:document,{innerHeight:d,innerWidth:l}=(a=f.defaultView)!=null?a:window,u=c.getBoundingClientRect(),h=Tr(c,u),{top:p,left:v,bottom:x,right:_}=h,g=-Math.floor(p),y=-Math.floor(v),w=-Math.floor(l-_),b=-Math.floor(d-x),T=`${g}px ${w}px ${b}px ${y}px`;this.boundingClientRect=u,nt(this,Ut,new IntersectionObserver(C=>{const[M]=C,{intersectionRect:E}=M;(M.intersectionRatio!==1?M.intersectionRatio:bt.intersectionRatio(E,Tr(c)))!==1&&q(this,ir).call(this)},{threshold:Ya,rootMargin:T,root:f})),q(this,Ut).observe(c),sd(this,Rs,hd).call(this)},fd)),this.boundingClientRect=e.getBoundingClientRect(),nt(this,Gt,zh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(nt(this,Ve,document.createElement("div")),q(this,Ve).style.background="rgba(0,0,0,0.15)",q(this,Ve).style.position="fixed",q(this,Ve).style.pointerEvents="none",s.body.appendChild(q(this,Ve))),nt(this,sr,new IntersectionObserver(i=>{var o,a;const c=i[i.length-1],{boundingClientRect:f,isIntersecting:d}=c,{width:l,height:u}=f,h=q(this,Gt);nt(this,Gt,d),!(!l&&!u)&&(h&&!d?((o=q(this,Ut))==null||o.disconnect(),this.callback(null),(a=q(this,Ot))==null||a.disconnect(),nt(this,Ot,void 0),q(this,Ve)&&(q(this,Ve).style.visibility="hidden")):q(this,ir).call(this),d&&!q(this,Ot)&&(nt(this,Ot,new Nh(q(this,ir))),q(this,Ot).observe(e)))},{threshold:Ya,root:s})),q(this,Gt)&&!n.skipInitial&&this.callback(this.boundingClientRect),q(this,sr).observe(e)}};Gt=new WeakMap;Ps=new WeakMap;Ot=new WeakMap;Ut=new WeakMap;sr=new WeakMap;Ve=new WeakMap;br=new WeakMap;ir=new WeakMap;Rs=new WeakSet;hd=function(){q(this,br)||(sd(this,Rs,pd).call(this),!Fh(this.boundingClientRect,q(this,Ps))&&(this.callback(this.boundingClientRect),nt(this,Ps,this.boundingClientRect)))};pd=function(){if(q(this,Ve)){const{top:e,left:t,width:n,height:r}=Tr(this.element);q(this,Ve).style.overflow="hidden",q(this,Ve).style.visibility="visible",q(this,Ve).style.top=`${Math.floor(e)}px`,q(this,Ve).style.left=`${Math.floor(t)}px`,q(this,Ve).style.width=`${Math.floor(n)}px`,q(this,Ve).style.height=`${Math.floor(r)}px`}};var es=new WeakMap,ts=new WeakMap;function Gh(e,t){let n=es.get(e);return n||(n={disconnect:new gd(e,s=>{const i=es.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),es.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(es.delete(e),n.disconnect())}}function Uh(e,t){const n=new Set;for(const r of e){const s=Gh(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Hh(e,t){var n;const r=e.ownerDocument;if(!ts.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",c=>a.forEach(f=>f(c)),{capture:!0,passive:!0,signal:o.signal}),ts.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=ts.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),ts.delete(r))})}var or,ar,vs,ro,Vh=class{constructor(e,t,n){this.callback=t,Je(this,or),Je(this,ar,!1),Je(this,vs),Je(this,ro,ud(o=>{if(!q(this,ar)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of q(this,vs))if(o.target.contains(a)){this.callback(q(this,or).boundingClientRect);break}}},fd));const r=Lh(e),s=Uh(r,t),i=Hh(e,q(this,ro));nt(this,vs,r),nt(this,or,new gd(e,t,n)),this.disconnect=()=>{q(this,ar)||(nt(this,ar,!0),s(),i(),q(this,or).disconnect())}}};or=new WeakMap;ar=new WeakMap;vs=new WeakMap;ro=new WeakMap;function so(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Sn(e){try{so(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Xa(e){return!ad||!e?!1:e===Wn(e).scrollingElement}function md(e){var t,n;const r=st(e),s=Xa(e)?Mh(e):ni(e),i=r.visualViewport,o=Xa(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}},c=a.current.y<=0,f=a.current.x<=0,d=a.current.y>=a.max.y,l=a.current.x>=a.max.x;return{rect:s,position:a,isTop:c,isLeft:f,isBottom:d,isRight:l}}function Kh(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=md(e),{x:a,y:c}=t??{x:0,y:0},f=!n&&o.current.y+c>0,d=!r&&o.current.y+c<o.max.y,l=!s&&o.current.x+a>0,u=!i&&o.current.x+a<o.max.x;return{top:f,bottom:d,left:l,right:u,x:l||u,y:f||d}}var la=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))}},As=new la(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),qh=new la(e=>setTimeout(e,50)),Ls=new Map,Yh=Ls.clear.bind(Ls);function _t(e,t=!1){if(!t)return Qa(e);let n=Ls.get(e);return n||(n=Qa(e),Ls.set(e,n),qh.schedule(Yh),n)}function Qa(e){return st(e).getComputedStyle(e)}function Xh(e,t=_t(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Qh(e,t=_t(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 Zh={excludeElement:!0,escapeShadowDOM:!0};function io(e,t=Zh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(sa(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&oa(a))return o(a.host);if(!At(a))return od(a)?o(a.parentElement):i;if(i.has(a))return i;const c=_t(a,!0);if(r&&a===e||Qh(a,c)&&i.add(a),Xh(a,c)){const{scrollingElement:f}=a.ownerDocument;return f&&i.add(f),i}return o(a.parentNode)}return e?o(e):i}function Dn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=On(e);for(;r;){if(r===t)return n;const s=ni(r),{x:i,y:o}=Jh(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=On(r)}return n}function Jh(e,t=ni(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=_t(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function ep(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 Er(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 ri(e){var t,n,r,s,i,o,a,c,f;const{scale:d,transform:l,translate:u}=e,h=ep(d),p=Er(u),v=tp(l);if(!v&&!h&&!p)return null;const x={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},_={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},g={x:(i=v?.x)!=null?i:0,y:(o=v?.y)!=null?o:0,scaleX:(a=v?.scaleX)!=null?a:1,scaleY:(c=v?.scaleY)!=null?c:1};return{x:_.x+g.x,y:_.y+g.y,z:(f=p?.z)!=null?f:0,scaleX:x.x*g.scaleX,scaleY:x.y*g.scaleY}}function tp(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 at=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(at||{}),np={x:.2,y:.2},rp={x:10,y:10};function sp(e,t,n,r=25,s=np,i=rp){const{x:o,y:a}=t,{rect:c,isTop:f,isBottom:d,isLeft:l,isRight:u}=md(e),h=Dn(e),p=_t(e,!0),v=ri(p),x=v!==null?v?.scaleX<0:!1,_=v!==null?v?.scaleY<0:!1,g=new bt(c.left*h.scaleX+h.x,c.top*h.scaleY+h.y,c.width*h.scaleX,c.height*h.scaleY),y={x:0,y:0},w={x:0,y:0},b={height:g.height*s.y,width:g.width*s.x};return b.height>0&&(!f||_&&!d)&&a<=g.top+b.height&&n?.y!==1&&o>=g.left-i.x&&o<=g.right+i.x?(y.y=_?1:-1,w.y=r*Math.abs((g.top+b.height-a)/b.height)):b.height>0&&(!d||_&&!f)&&a>=g.bottom-b.height&&n?.y!==-1&&o>=g.left-i.x&&o<=g.right+i.x&&(y.y=_?-1:1,w.y=r*Math.abs((g.bottom-b.height-a)/b.height)),b.width>0&&(!u||x&&!l)&&o>=g.right-b.width&&n?.x!==-1&&a>=g.top-i.y&&a<=g.bottom+i.y?(y.x=x?-1:1,w.x=r*Math.abs((g.right-b.width-o)/b.width)):b.width>0&&(!l||x&&!u)&&o<=g.left+b.width&&n?.x!==1&&a>=g.top-i.y&&a<=g.bottom+i.y&&(y.x=x?1:-1,w.x=r*Math.abs((g.left+b.width-o)/b.width)),{direction:y,speed:w}}function vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!At(e))return;const r=io(e),s=[];for(const i of r){if(!At(i))continue;const{top:o,left:a}=ip(e,i);let c=o,f=a;for(const d of s)c-=d.scrollTop,f-=d.scrollLeft;if(t!=="none"){const d=c<i.scrollTop,l=c+e.offsetHeight>i.scrollTop+i.clientHeight;d!==l&&(t==="center"?i.scrollTop=c-i.clientHeight/2+e.offsetHeight/2:d?i.scrollTop=c:i.scrollTop=c+e.offsetHeight-i.clientHeight)}if(n!=="none"){const d=f<i.scrollLeft,l=f+e.offsetWidth>i.scrollLeft+i.clientWidth;d!==l&&(n==="center"?i.scrollLeft=f-i.clientWidth/2+e.offsetWidth/2:d?i.scrollLeft=f:i.scrollLeft=f+e.offsetWidth-i.clientWidth)}s.push(i)}}function Za(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 ip(e,t){const n=Za(e),r=Za(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function op(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),c=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width*r:e.width,d=s?e.height*s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function ap(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),c=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width/r:e.width,d=s?e.height/s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function yd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Ja(e,t=_t(e).translate,n=!0){if(n){const r=id(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=Er(s);if(i)return i}}}if(t){const r=Er(t);if(r)return r}return{x:0,y:0,z:0}}var lp=new la(e=>setTimeout(e,0)),xr=new Map,cp=xr.clear.bind(xr);function dp(e){const t=e.ownerDocument;let n=xr.get(t);if(n)return n;n=t.getAnimations(),xr.set(t,n),lp.schedule(cp);const r=n.filter(s=>ti(s.effect)&&s.effect.target===e);return xr.set(e,r),n}function up(e,t){const n=dp(e).filter(r=>{var s,i;if(ti(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(c=>{for(const f of t.properties)if(c[f])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 yt=class extends bt{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=Dn(e),ignoreTransforms:a,getBoundingClientRect:c=ni}=t,f=up(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||ia())&&b.contains(e)}),d=c(e);let{top:l,left:u,width:h,height:p}=d,v;const x=_t(e),_=ri(x),g={x:(n=_?.scaleX)!=null?n:1,y:(r=_?.scaleY)!=null?r:1},y=fp(e,x);f?.(),_&&(v=ap(d,_,x.transformOrigin),(a||y)&&(l=v.top,u=v.left,h=v.width,p=v.height));const w={width:(s=v?.width)!=null?s:h,height:(i=v?.height)!=null?i:p};if(y&&!a&&v){const b=op(v,y,x.transformOrigin);l=b.top,u=b.left,h=b.width,p=b.height,g.x=y.scaleX,g.y=y.scaleY}o&&(a||(u*=o.scaleX,h*=o.scaleX,l*=o.scaleY,p*=o.scaleY),u+=o.x,l+=o.y),super(u,l,h,p),this.scale=g,this.intrinsicWidth=w.width,this.intrinsicHeight=w.height}};function fp(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 c=ti(a.effect)?a.effect.getKeyframes():[],f=c[c.length-1];if(!f)continue;const{transform:d,translate:l,scale:u}=f;typeof d=="string"&&d&&(r=d,o=!0),typeof l=="string"&&l&&(s=l,o=!0),typeof u=="string"&&u&&(i=u,o=!0)}return o?ri({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function wr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var hp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(wr(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(wr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(wr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Qt(e){return e?e instanceof st(e).Element||Fr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Cr(e){if(!e)return!1;const{KeyboardEvent:t}=st(e.target);return e instanceof t}function pp(e){if(!e)return!1;const{PointerEvent:t}=st(e.target);return e instanceof t}function gp(e){if(!Qt(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||mp(e)}function mp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var bi={};function oo(e){const t=bi[e]==null?0:bi[e]+1;return bi[e]=t,`${e}-${t}`}var ca=({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=ot.distance(t.shape.center,n);return{id:r,value:1/s,type:zn.PointerIntersection,priority:Fn.High}}return null},vp=({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=ot.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:zn.ShapeIntersection,priority:Fn.Normal}}return null},bd=e=>{var t;return(t=ca(e))!=null?t:vp(e)},yp=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?bt.from(r.current.boundingRectangle).corners:void 0,a=bt.from(n.shape.boundingRectangle).corners.reduce((c,f,d)=>{var l;return c+ot.distance(ot.from(f),(l=i?.[d])!=null?l:s.current)},0)/4;return{id:n.id,value:1/a,type:zn.Collision,priority:Fn.Normal}},bp=Object.create,da=Object.defineProperty,xp=Object.defineProperties,wp=Object.getOwnPropertyDescriptor,_p=Object.getOwnPropertyDescriptors,Bs=Object.getOwnPropertySymbols,xd=Object.prototype.hasOwnProperty,wd=Object.prototype.propertyIsEnumerable,_d=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Nn=e=>{throw TypeError(e)},ao=(e,t,n)=>t in e?da(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Or=(e,t)=>{for(var n in t||(t={}))xd.call(t,n)&&ao(e,n,t[n]);if(Bs)for(var n of Bs(t))wd.call(t,n)&&ao(e,n,t[n]);return e},ua=(e,t)=>xp(e,_p(t)),el=(e,t)=>da(e,"name",{value:t,configurable:!0}),kd=(e,t)=>{var n={};for(var r in e)xd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Bs)for(var r of Bs(e))t.indexOf(r)<0&&wd.call(e,r)&&(n[r]=e[r]);return n},Gn=e=>{var t;return[,,,bp((t=e?.[_d("metadata")])!=null?t:null)]},Sd=["class","method","getter","setter","accessor","field","value","get","set"],lr=e=>e!==void 0&&typeof e!="function"?Nn("Function expected"):e,kp=(e,t,n,r,s)=>({kind:Sd[e],name:t,metadata:r,addInitializer:i=>n._?Nn("Already initialized"):s.push(lr(i||null))}),nn=(e,t)=>ao(t,_d("metadata"),e[3]),ze=(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},ut=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,v=Sd[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&wp(l<4?s:{get[n](){return ge(this,i)},set[n](w){return Qe(this,i,w)}},n));l?h&&l<4&&el(i,(l>2?"set ":l>1?"get ":"")+n):el(s,n);for(var y=r.length-1;y>=0;y--)f=kp(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>Sp(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?ge:Zt)(w,s,l^4?i:g.get):w=>w[n]),l>2&&(d.set=h?(w,b)=>Qe(w,s,b,l^4?i:g.set):(w,b)=>w[n]=b)),a=(0,r[y])(l?l<4?h?i:g[v]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?lr(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Nn("Object expected"):(lr(o=a.get)&&(g.get=o),lr(o=a.set)&&(g.set=o),lr(o=a.init)&&x.unshift(o));return l||nn(e,s),g&&da(s,n,g),h?l^4?i:g:s},fa=(e,t,n)=>t.has(e)||Nn("Cannot "+n),Sp=(e,t)=>Object(t)!==t?Nn('Cannot use the "in" operator on this value'):e.has(t),ge=(e,t,n)=>(fa(e,t,"read from private field"),n?n.call(e):t.get(e)),Pe=(e,t,n)=>t.has(e)?Nn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Qe=(e,t,n,r)=>(fa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zt=(e,t,n)=>(fa(e,t,"access private method"),n),tl={role:"button",roleDescription:"draggable"},$p="dnd-kit-description",Tp="dnd-kit-announcement",Ep={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."},Cp={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 Op(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Dp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Mp(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 Ip=["dragover","dragmove"],jp=class extends qe{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=$p,announcement:s=Tp}={},announcements:i=Cp,screenReaderInstructions:o=Ep,debounce:a=500}=t??{},c=n?`${r}-${n}`:oo(r),f=n?`${s}-${n}`:oo(s);let d,l,u,h;const p=(b=h)=>{!u||!b||u?.nodeValue!==b&&(u.nodeValue=b)},v=()=>As.schedule(p),x=Pp(v,a),_=Object.entries(i).map(([b,T])=>this.manager.monitor.addEventListener(b,(C,M)=>{const E=u;if(!E)return;const O=T?.(C,M);O&&E.nodeValue!==O&&(h=O,Ip.includes(b)?x():(v(),x.cancel()))})),g=()=>{let b=[];d?.isConnected||(d=Dp(c,o.draggable),b.push(d)),l?.isConnected||(l=Mp(f),u=document.createTextNode(""),l.appendChild(u),b.push(l)),b.length>0&&document.body.append(...b)},y=new Set;function w(){for(const b of y)b()}this.registerEffect(()=>{var b;y.clear();for(const T of this.manager.registry.draggables.value){const C=(b=T.handle)!=null?b:T.element;if(C){(!d||!l)&&y.add(g),(!Op(C)||ia())&&!C.hasAttribute("tabindex")&&y.add(()=>C.setAttribute("tabindex","0")),!C.hasAttribute("role")&&C.tagName.toLowerCase()!=="button"&&y.add(()=>C.setAttribute("role",tl.role)),C.hasAttribute("aria-roledescription")||y.add(()=>C.setAttribute("aria-roledescription",tl.roleDescription)),C.hasAttribute("aria-describedby")||y.add(()=>C.setAttribute("aria-describedby",c));for(const E of["aria-pressed","aria-grabbed"]){const O=String(T.isDragging);C.getAttribute(E)!==O&&y.add(()=>C.setAttribute(E,O))}const M=String(T.disabled);C.getAttribute("aria-disabled")!==M&&y.add(()=>C.setAttribute("aria-disabled",M))}}y.size>0&&As.schedule(w)}),this.destroy=()=>{super.destroy(),d?.remove(),l?.remove(),_.forEach(b=>b())}}};function Pp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Fs=new Map,$d,Td,Ed,Cd,lo,_r,St,ha,Mn,Od,Dd,Md,Id,Lt=class extends(lo=Br,Cd=[re],Ed=[Me],Td=[Me],$d=[Me],lo){constructor(t,n){super(t,n),ze(St,5,this),Pe(this,Mn),Pe(this,_r,new Set),Pe(this,ha,ze(St,8,this,new Set)),ze(St,11,this),this.registerEffect(Zt(this,Mn,Od))}register(t){return ge(this,_r).add(t),()=>{ge(this,_r).delete(t)}}addRoot(t){return ne(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{ne(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return js((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return js((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}};St=Gn(lo);_r=new WeakMap;ha=new WeakMap;Mn=new WeakSet;Od=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ge(this,_r))t.push(Zt(this,Mn,Dd).call(this,n,r));return()=>{for(const n of t)n()}};Dd=function(e,t){let n=Fs.get(e);n||(n=new Map,Fs.set(e,n));let r=n.get(t);if(!r){const i=sa(e)?Zt(this,Mn,Md).call(this,e,n,t):Zt(this,Mn,Id).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())}};Md=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 c of a)for(const f of Array.from(c.removedNodes))if(f===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&&Fs.delete(e)}}};Id=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(oa(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&&Fs.delete(e)}}};ut(St,4,"additionalRoots",Cd,Lt,ha);ut(St,2,"sourceRoot",Ed,Lt);ut(St,2,"targetRoot",Td,Lt);ut(St,2,"roots",$d,Lt);nn(St,Lt);Lt.configure=Lr(Lt);var si=Lt,Rp=class extends qe{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(si),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},zr="data-dnd-",co=`${zr}dropping`,He="--dnd-",vt=`${zr}dragging`,zs=`${zr}placeholder`,Ap=[vt,zs,"popover","aria-pressed","aria-grabbing"],Lp=["view-transition-name"],Bp=`
|
|
9
|
+
:is(:root,:host) [${vt}] {
|
|
10
10
|
position: fixed !important;
|
|
11
11
|
pointer-events: none !important;
|
|
12
12
|
touch-action: none;
|
|
13
13
|
z-index: calc(infinity);
|
|
14
14
|
will-change: translate;
|
|
15
|
-
top: var(${
|
|
16
|
-
left: var(${
|
|
15
|
+
top: var(${He}top, 0px) !important;
|
|
16
|
+
left: var(${He}left, 0px) !important;
|
|
17
17
|
right: unset !important;
|
|
18
18
|
bottom: unset !important;
|
|
19
|
-
width: var(${
|
|
20
|
-
max-width: var(${
|
|
21
|
-
height: var(${
|
|
22
|
-
max-height: var(${
|
|
23
|
-
transform: var(${
|
|
24
|
-
transition: var(${
|
|
19
|
+
width: var(${He}width, auto);
|
|
20
|
+
max-width: var(${He}width, auto);
|
|
21
|
+
height: var(${He}height, auto);
|
|
22
|
+
max-height: var(${He}height, auto);
|
|
23
|
+
transform: var(${He}transform, none) !important;
|
|
24
|
+
transition: var(${He}transition) !important;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
:is(:root,:host) [${
|
|
27
|
+
:is(:root,:host) [${zs}] {
|
|
28
28
|
transition: none;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
:is(:root,:host) [${
|
|
31
|
+
:is(:root,:host) [${zs}='hidden'] {
|
|
32
32
|
visibility: hidden;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
[${
|
|
35
|
+
[${vt}] * {
|
|
36
36
|
pointer-events: none !important;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
[${
|
|
40
|
-
translate: var(${
|
|
39
|
+
[${vt}]:not([${co}]) {
|
|
40
|
+
translate: var(${He}translate) !important;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
[${
|
|
44
|
-
scale: var(${
|
|
45
|
-
transform-origin: var(${
|
|
43
|
+
[${vt}][style*='${He}scale'] {
|
|
44
|
+
scale: var(${He}scale) !important;
|
|
45
|
+
transform-origin: var(${He}transform-origin) !important;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
@layer dnd-kit {
|
|
49
|
-
:where([${
|
|
49
|
+
:where([${vt}][popover]) {
|
|
50
50
|
overflow: visible;
|
|
51
51
|
background: unset;
|
|
52
52
|
border: unset;
|
|
@@ -60,84 +60,84 @@
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
[${
|
|
63
|
+
[${vt}]::backdrop, [${zr}overlay]:not([${vt}]) {
|
|
64
64
|
display: none;
|
|
65
65
|
visibility: hidden;
|
|
66
66
|
}
|
|
67
|
-
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Fp(e,t="hidden"){return te(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=zp(n,r.registry.droppables),i=[],o=Ph(n),{remove:a}=o;return Wp(s,o,i),Np(o,t),o.remove=()=>{i.forEach(c=>c()),a.call(o)},o})}function zp(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Nr}${io("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Wp(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),to.set(a,o),n.push(()=>{to.delete(a),r.proxy=void 0})}}function Np(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Bs,t)}function jd(e,t){return e===t?!0:Cn(e)===Cn(t)}function nl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Qt(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>kn(t))}function co(e){return e.tagName==="TR"}function Gp(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-")||Ap.includes(a))continue;const c=e.getAttribute(a);if(a==="style"){if(kr(e)&&kr(t)){const f=e.style;for(const d of Array.from(t.style))f.getPropertyValue(d)===""&&t.style.removeProperty(d);for(const d of Array.from(f)){if(Lp.includes(d)||d.startsWith(Ve))continue;const l=f.getPropertyValue(d);t.style.setProperty(d,l)}}}else c!==null?t.setAttribute(a,c):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Vp(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),kn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),kn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),kn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Up(e){return new ResizeObserver(()=>{var t,n,r;const s=new vt(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,c=ld();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+c.y,left:e.left+o+c.x},Ve),(n=e.getElementMutationObserver())==null||n.takeRecords(),co(e.element)&&co(e.placeholder)){const y=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(y.map(_=>_.style.width));for(const[_,g]of y.entries()){const v=w[_];g.style.width=`${v.getBoundingClientRect().width}px`}}const f=(r=e.getTranslate())!=null?r:{x:0,y:0},d=e.left+o+c.x+f.x,l=e.top+a+c.y+f.y,u=s.width-e.widthOffset,h=s.height-e.heightOffset,p=e.frameTransform;e.dragOperation.shape=new yt(d*p.scaleX+p.x,l*p.scaleY+p.y,u*p.scaleX,h*p.scaleY)})}var Hp=250,qp="ease";function Kp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const g=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(g).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Hp,easing:a=qp}=i??{};kn(e.feedbackElement);const[,c]=(t=id(e.feedbackElement,g=>"translate"in g))!=null?t:[];c?.pause();const f=(n=e.placeholder)!=null?n:e.element,d={frameTransform:jd(e.feedbackElement,f)?null:void 0},l=new vt(e.feedbackElement,d),u=(r=Or(wt(e.feedbackElement).translate))!=null?r:e.translate,h=new vt(f,d),p=yt.delta(l,h,e.alignment),y={x:u.x-p.x,y:u.y-p.y},w=Math.round(l.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},_=Math.round(l.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Ve),e.feedbackElement.setAttribute(lo,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),yd({element:e.feedbackElement,keyframes:da(Mr(Mr({},w),_),{translate:[`${u.x}px ${u.y}px 0`,`${y.x}px ${y.y}px 0`]}),options:{duration:oa(nt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(lo),c?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Pd,uo,Ir,ha,ms,Rd,Ad,Mn=class extends(uo=qe,Pd=[ne],uo){constructor(t,n){super(t,n),je(this,ms),je(this,ha,Ne(Ir,8,this)),Ne(Ir,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(ni),s=r?.register(Bp);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Zt(this,ms,Rd).bind(this,r)),this.registerEffect(Zt(this,ms,Ad))}};Ir=Nn(uo);ha=new WeakMap;ms=new WeakSet;Rd=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Ms(t);if(n)return e.addRoot(n)};Ad=function(){var e,t,n,r,s,i,o;const{state:a,manager:c,options:f}=this,{dragOperation:d}=c,{position:l,source:u,status:h}=d;if(h.idle){a.current={},a.initial={};return}if(!u)return;const{element:p}=u,y=u.pluginConfig(Mn),w=(t=(e=y?.feedback)!=null?e:f?.feedback)!=null?t:"default",_=typeof w=="function"?w(u,c):w;if(!p||_==="none"||!h.initialized||h.initializing)return;const{initial:g}=a,v=(n=this.overlay)!=null?n:p,x=On(v),b=On(p),T=!jd(p,v),C=new vt(p,{frameTransform:T?b:null,ignoreTransforms:!T}),M={x:b.scaleX/x.scaleX,y:b.scaleY/x.scaleY};let{width:E,height:O,top:P,left:A}=C;T&&(E=E/M.x,O=O/M.y);const L=new hp(v),W=wt(p),{transition:U,translate:N,boxSizing:I,paddingBlockStart:z,paddingBlockEnd:V,paddingInlineStart:B,paddingInlineEnd:G,borderInlineStartWidth:Q,borderInlineEndWidth:Z,borderBlockStartWidth:X,borderBlockEndWidth:H}=W,Pe=U.split(",").filter(fe=>!/^\s*(transform|translate|scale)\b/.test(fe)).join(","),ve=ti(W),pe=W.transform,Se=_==="clone",ee=I==="content-box",Re=ee?parseInt(B)+parseInt(G)+parseInt(Q)+parseInt(Z):0,ce=ee?parseInt(z)+parseInt(V)+parseInt(X)+parseInt(H):0,ie=_!=="move"&&!this.overlay?Fp(u,Se?"clone":"hidden"):null,$e=te(()=>Dr(c.dragOperation.activatorEvent));if(!g.translate){if(this.overlay&&ve)g.translate={x:ve.x,y:ve.y};else if(N!=="none"){const fe=Or(N);fe&&(g.translate=fe)}}if(!g.transformOrigin){const fe=te(()=>l.current),Le=A+((r=ve?.x)!=null?r:0),Je=P+((s=ve?.y)!=null?s:0);g.transformOrigin={x:(fe.x-Le*x.scaleX-x.x)/(E*x.scaleX),y:(fe.y-Je*x.scaleY-x.y)/(O*x.scaleY)}}const{transformOrigin:de}=g,xe=P*x.scaleY+x.y,we=A*x.scaleX+x.x;if(!g.coordinates&&(g.coordinates={x:we,y:xe},M.x!==1||M.y!==1)){const{scaleX:fe,scaleY:Le}=b,{x:Je,y:Et}=de;g.coordinates.x+=(E*fe-E)*Je,g.coordinates.y+=(O*Le-O)*Et}g.dimensions||(g.dimensions={width:E,height:O}),g.frameTransform||(g.frameTransform=x);const Ge={x:g.coordinates.x-we,y:g.coordinates.y-xe},me={width:(g.dimensions.width*g.frameTransform.scaleX-E*x.scaleX)*de.x,height:(g.dimensions.height*g.frameTransform.scaleY-O*x.scaleY)*de.y},Ae={x:Ge.x/x.scaleX+me.width,y:Ge.y/x.scaleY+me.height},Fe={left:A+Ae.x,top:P+Ae.y};v.setAttribute(mt,"true");const D=te(()=>d.transform),R=(i=g.translate)!=null?i:{x:0,y:0},j=D.x*x.scaleX+R.x,F=D.y*x.scaleY+R.y,J=ld();L.set({width:E-Re,height:O-ce,top:Fe.top+J.y,left:Fe.left+J.x,translate:`${j}px ${F}px 0`,transform:this.overlay?"none":pe,transition:Pe?`${Pe}, translate 0ms linear`:"translate 0ms linear",scale:T?`${M.x} ${M.y}`:"","transform-origin":`${de.x*100}% ${de.y*100}%`},Ve),ie&&(p.insertAdjacentElement("afterend",ie),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(p)),ro(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),kn(v),v.addEventListener("beforetoggle",nl));let q,ae,se;const ue=Up({placeholder:ie,element:p,feedbackElement:v,frameTransform:x,transformOrigin:de,width:E,height:O,top:P,left:A,widthOffset:Re,heightOffset:ce,delta:Ae,styles:L,dragOperation:d,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>q,getSavedCellWidths:()=>se,setSavedCellWidths:fe=>{se=fe}}),rt=new vt(v);te(()=>d.shape=rt);const Un=nt(v),Bt=fe=>{this.manager.actions.stop({event:fe})},Hn=oa(Un);$e&&Un.addEventListener("resize",Bt),te(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),ie&&(ue.observe(ie),q=Gp(p,ie,Se),ae=Vp(p,ie,v));const qn=(o=c.dragOperation.source)==null?void 0:o.id,Ma=()=>{var fe;if(!$e||qn==null)return;const Le=c.registry.draggables.get(qn),Je=(fe=Le?.handle)!=null?fe:Le?.element;Rt(Je)&&Je.focus()},Kn=()=>{q?.disconnect(),ae?.disconnect(),ue.disconnect(),Un.removeEventListener("resize",Bt),ro(v)&&(v.removeEventListener("beforetoggle",nl),v.removeAttribute("popover")),v.removeAttribute(mt),L.reset();const fe=()=>{var Le;if(se&&co(p)){const ci=Array.from(p.cells);for(const[Kr,sn]of ci.entries())sn.style.width=(Le=se[Kr])!=null?Le:""}u.status="idle";const Je=a.current.translate!=null,Et=d.status.dragging;ie&&(!Et&&Je||ie.parentElement!==v.parentElement)&&v.isConnected&&ie.replaceWith(v),ie?.remove()};v===this.overlay?setTimeout(fe,0):fe()},ai=f?.dropAnimation,rn=this,li=Lr(()=>{var fe,Le,Je;const{transform:Et,status:ci}=d;if(!(!Et.x&&!Et.y&&!a.current.translate)&&ci.dragging){const Kr=(fe=g.translate)!=null?fe:{x:0,y:0},sn={x:Et.x/x.scaleX+Kr.x,y:Et.y/x.scaleY+Kr.y},Ia=a.current.translate,Zu=te(()=>d.modifiers),di=te(()=>{var Xn;return(Xn=d.shape)==null?void 0:Xn.current}),Yn=f?.keyboardTransition,ja=$e&&!Hn&&Yn!==null?`${(Le=Yn?.duration)!=null?Le:250}ms ${(Je=Yn?.easing)!=null?Je:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:Pe?`${Pe}, translate ${ja}`:`translate ${ja}`,translate:`${sn.x}px ${sn.y}px 0`},Ve),q?.takeRecords(),di&&di!==rt&&Ia&&!Zu.length){const Xn=it.delta(sn,Ia);d.shape=yt.from(di.boundingRectangle).translate(Xn.x*x.scaleX,Xn.y*x.scaleY)}else d.shape=new vt(v);a.current.translate=sn}},function(){if(d.status.dropped){this.dispose(),u.status="dropping";const fe=y?.dropAnimation!==void 0?y.dropAnimation:rn.dropAnimation!==void 0?rn.dropAnimation:ai;let Le=a.current.translate;const Je=Le!=null;if(!Le&&p!==v&&(Le={x:0,y:0}),!Le||fe===null){Kn();return}c.renderer.rendering.then(()=>{Kp({source:u,element:p,feedbackElement:v,placeholder:ie,translate:Le,moved:Je,transition:U,alignment:u.alignment,styles:L,animation:fe??void 0,getElementMutationObserver:()=>q,cleanup:Kn,restoreFocus:Ma})})}});return()=>{Kn(),li()}};dt(Ir,4,"overlay",Pd,Mn,ha);nn(Ir,Mn);Mn.configure=Fr(Mn);var pa=Mn,Zn=!0,Yp=!1,Ld,Bd,Fd,zd,Mt,ga,ma;zd=(Fd=[ne],ot.Forward),Bd=(Ld=[ne],ot.Reverse);var jr=class{constructor(){je(this,ga,Ne(Mt,8,this,Zn)),Ne(Mt,11,this),je(this,ma,Ne(Mt,12,this,Zn)),Ne(Mt,15,this)}isLocked(e){return e===ot.Idle?!1:e==null?this[ot.Forward]===Zn&&this[ot.Reverse]===Zn:this[e]===Zn}unlock(e){e!==ot.Idle&&(this[e]=Yp)}};Mt=Nn(null);ga=new WeakMap;ma=new WeakMap;dt(Mt,4,zd,Fd,jr,ga);dt(Mt,4,Bd,Ld,jr,ma);nn(Mt,jr);var Xp=[ot.Forward,ot.Reverse],rl=class{constructor(){this.x=new jr,this.y=new jr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Qp=class extends qe{constructor(e){super(e);const t=In(new rl);let n=null;this.signal=t,ct(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new rl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:sl(s.x,n.x),y:sl(s.y,n.y)},o=t.peek();Ce(()=>{for(const a of gc)for(const c of Xp)i[a]===c&&o[a].unlock(c);t.value=o})}n=s})}get current(){return this.signal.peek()}};function sl(e,t){return Math.sign(e-t)}var Wd,fo,Pr,va,Ot,ho,Gr=class extends(fo=zr,Wd=[ne],fo){constructor(e){super(e),je(this,va,Ne(Pr,8,this,!1)),Ne(Pr,11,this),je(this,Ot),je(this,ho,()=>{if(!ge(this,Ot))return;const{element:i,by:o}=ge(this,Ot);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const c=this.getScrollableElements();if(!c)return Xe(this,Ot,void 0),!1;const{position:f}=this.manager.dragOperation,d=f?.current;if(d){const{by:l}=i??{},u=l?{x:il(l.x),y:il(l.y)}:void 0,h=u?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of c){const y=qh(p,l);if(y.x||y.y){const{speed:w,direction:_}=sp(p,d,u,o?.acceleration,o?.threshold);if(h)for(const g of gc)h[g].isLocked(_[g])&&(w[g]=0,_[g]=0);if(_.x||_.y){const{x:g,y:v}=l??_,x=g*w.x,b=v*w.y;if(x||b){const T=(a=ge(this,Ot))==null?void 0:a.by;if(this.autoScrolling&&T&&(T.x&&!x||T.y&&!b))continue;return Xe(this,Ot,{element:p,by:{x,y:b}}),Ps.schedule(ge(this,ho)),!0}}}}}return Xe(this,Ot,void 0),!1};let t=null,n=null;const r=Wi(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=cd(Ms(o?.element),i.current);return a&&(t=a),a??t}),s=Wi(()=>{const i=r.value,{documentElement:o}=zn(i);if(!i||i===o){const{target:a}=e.dragOperation,c=a?.element;if(c){const f=so(c,{excludeElement:!1});return n=f,f}}if(i){const a=so(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},ut);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Qp(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!Dr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};Pr=Nn(fo);va=new WeakMap;Ot=new WeakMap;ho=new WeakMap;dt(Pr,4,"autoScrolling",Wd,Gr,va);nn(Pr,Gr);function il(e){return e>0?ot.Forward:e<0?ot.Reverse:ot.Idle}var Zp=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))}},Jp=new Zp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),eg=10,po=class extends qe{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Gr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=ct(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:c}=t.dragOperation;if(c.dragging){const f={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,f)){r.autoScrolling=!0;const l=setInterval(()=>Jp.schedule(()=>r.scroll(void 0,f)),eg);return()=>{clearInterval(l)}}else r.autoScrolling=!1}})}};po.configure=Fr(po);var Nd=po,ol={capture:!0,passive:!0},ur,tg=class extends zr{constructor(e){super(e),je(this,ur),this.handleScroll=()=>{ge(this,ur)==null&&Xe(this,ur,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Xe(this,ur,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=ct(()=>{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,ol),()=>{o.removeEventListener("scroll",this.handleScroll,ol)}}})}};ur=new WeakMap;var ng="* { user-select: none !important; -webkit-user-select: none !important; }",rg=class extends qe{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(ni),n=t?.register(ng);if(this.destroy=ct(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return bi(),document.addEventListener("selectionchange",bi,{capture:!0}),()=>{document.removeEventListener("selectionchange",bi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function bi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var fr=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}}),gn,Fs=class extends Tn{constructor(t,n){super(t),this.manager=t,this.options=n,je(this,gn,[]),this.listeners=new dd,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Qt(r.target)||s.disabled)return;const{keyboardCodes:o=fr.keyboardCodes,preventActivation:a=fr.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 ct(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{Dr(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(),vd(s);const{center:i}=new vt(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=zn(s),c=[this.listeners.bind(a,[{type:"keydown",listener:f=>this.handleKeyDown(f,n,r),options:{capture:!0}}])];ge(this,gn).push(...c)}handleKeyDown(t,n,r){const{keyboardCodes:s=fr.keyboardCodes}=r??{};if(on(t,[...s.end,...s.cancel])){t.preventDefault();const i=on(t,s.cancel);this.handleEnd(t,i);return}on(t,s.up)?this.handleMove("up",t):on(t,s.down)&&this.handleMove("down",t),on(t,s.left)?this.handleMove("left",t):on(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},c=(s=(r=this.options)==null?void 0:r.offset)!=null?s:fr.offset;if(typeof c=="number"&&(c={x:c,y:c}),!!i){switch(t){case"up":a={x:0,y:-c.y*o};break;case"down":a={x:0,y:c.y*o};break;case"left":a={x:-c.x*o,y:0};break;case"right":a={x:c.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(Nd);t?.disabled===!1&&(t.disable(),ge(this,gn).push(()=>{t.enable()}))}cleanup(){ge(this,gn).forEach(t=>t()),Xe(this,gn,[])}destroy(){this.cleanup(),this.listeners.clear()}};gn=new WeakMap;Fs.configure=Fr(Fs);Fs.defaults=fr;var Gd=Fs;function on(e,t){return t.includes(e.code)}var Ut,sg=class extends qc{constructor(){super(...arguments),je(this,Ut)}onEvent(e){switch(e.type){case"pointerdown":Xe(this,Ut,En(e));break;case"pointermove":if(!ge(this,Ut))return;const{x:t,y:n}=En(e),r={x:t-ge(this,Ut).x,y:n-ge(this,Ut).y},{tolerance:s}=this.options;if(s&&Xi(r,s)){this.abort();return}Xi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Xe(this,Ut,void 0)}};Ut=new WeakMap;var mn,Ht,ig=class extends qc{constructor(){super(...arguments),je(this,mn),je(this,Ht)}onEvent(e){switch(e.type){case"pointerdown":Xe(this,Ht,En(e)),Xe(this,mn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ge(this,Ht))return;const{x:t,y:n}=En(e),r={x:t-ge(this,Ht).x,y:n-ge(this,Ht).y};Xi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ge(this,mn)&&(clearTimeout(ge(this,mn)),Xe(this,Ht,void 0),Xe(this,mn,void 0))}};mn=new WeakMap;Ht=new WeakMap;var xn=class{};xn.Delay=ig;xn.Distance=sg;var go=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Qt(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new xn.Delay({value:250,tolerance:5})]:gp(s)&&!e.defaultPrevented?[new xn.Delay({value:200,tolerance:0})]:[new xn.Delay({value:200,tolerance:10}),new xn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Qt(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Ah(r);return s===t.element?!1:!!s}}),vn,zs=class extends Tn{constructor(t,n){super(t),this.manager=t,this.options=n,je(this,vn,new Set),this.listeners=new dd,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=go.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return ct(()=>{var s;const i=new AbortController,{signal:o}=i,a=f=>{pp(f)&&this.handlePointerDown(f,t,n)};let c=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?c=n.activatorElements:c=n.activatorElements(t));for(const f of c)f&&(lg(f.ownerDocument.defaultView),f.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Qt(t.target)||n.disabled||og(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=go.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=Rt(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=On(n.element),{x:c,y:f}=En(t);this.initialCoordinates={x:c*a.scaleX+a.x,y:f*a.scaleY+a.y};const d=this.activationConstraints(t,n,r);t.sensor=this;const l=new Eh(d,y=>this.handleStart(n,y));l.signal.onabort=()=>this.handleCancel(t),l.onEvent(t),this.controller=l;const u=eo(),h=this.listeners.bind(u,[{type:"pointermove",listener:y=>this.handlePointerMove(y,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:es,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};ge(this,vn).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=En(t),o=On(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,Ps.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=zn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const c=Qt(n.target)?[n.target,a]:a,f=this.listeners.bind(c,[{type:"touchmove",listener:es,options:{passive:!1}},{type:"click",listener:es},{type:"contextmenu",listener:es},{type:"keydown",listener:this.handleKeyDown}]);ge(this,vn).add(f)}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},ge(this,vn).forEach(n=>n()),ge(this,vn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};vn=new WeakMap;zs.configure=Fr(zs);zs.defaults=go;var mo=zs;function og(e){return"sensor"in e}function es(e){e.preventDefault()}function ag(){}var al=new WeakSet;function lg(e){!e||al.has(e)||(e.addEventListener("touchmove",ag,{capture:!1,passive:!1}),al.add(e))}var Sn={modifiers:[],plugins:[jp,Nd,Rp,pa,rg],sensors:[mo,Gd]},Vd=class extends Dh{constructor(e={}){const t=pt(e.plugins,Sn.plugins),n=pt(e.sensors,Sn.sensors),r=pt(e.modifiers,Sn.modifiers);super(da(Mr({},e),{plugins:[tg,Gr,ni,...t],sensors:n,modifiers:r}))}},Ud,Hd,vo,It,ya,ba,ri=class extends(vo=bt,Hd=[ne],Ud=[ne],vo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=kd(n,["element","effects","handle"]);super(Mr({effects:()=>[...s(),()=>{var a,c;const{manager:f}=this;if(!f)return;const l=((c=(a=this.sensors)==null?void 0:a.map(Tr))!=null?c:[...f.sensors]).map(u=>{const h=u instanceof Tn?u:f.registry.register(u.plugin),p=u instanceof Tn?void 0:u.options;return h.bind(this,p)});return function(){l.forEach(h=>h())}}]},o),t),je(this,ya,Ne(It,8,this)),Ne(It,11,this),je(this,ba,Ne(It,12,this)),Ne(It,15,this),this.element=r,this.handle=i}};It=Nn(vo);ya=new WeakMap;ba=new WeakMap;dt(It,4,"handle",Hd,ri,ya);dt(It,4,"element",Ud,ri,ba);nn(It,ri);var qd,Kd,yo,jt,xa,xi,Yd,Xd,$r,wa,si=class extends(yo=xt,Kd=[ne],qd=[ne],yo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=kd(n,["element","effects"]);const{collisionDetector:o=bd}=i,a=f=>{const{manager:d,element:l}=this;if(!l||f===null){this.shape=void 0;return}if(!d)return;const u=new vt(l),h=te(()=>this.shape);return u&&h?.equals(u)?h:(this.shape=u,u)},c=In(!1);super(da(Mr({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:f,manager:d}=this;if(!d)return;const{dragOperation:l}=d,{source:u}=l;c.value=!!(u&&l.status.initialized&&f&&!this.disabled&&this.accepts(u))},()=>{const{element:f}=this;if(c.value&&f){const d=new Hh(f,a);return()=>{d.disconnect(),this.shape=void 0}}},()=>{var f;if((f=this.manager)!=null&&f.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),je(this,$r),je(this,xa,Ne(jt,8,this)),Ne(jt,11,this),je(this,wa,Ne(jt,12,this)),Ne(jt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Xe(this,$r,e,Xd)}get element(){var e;return(e=this.proxy)!=null?e:ge(this,$r,Yd)}};jt=Nn(yo);xa=new WeakMap;$r=new WeakSet;wa=new WeakMap;xi=dt(jt,20,"#element",Kd,$r,xa),Yd=xi.get,Xd=xi.set;dt(jt,4,"proxy",qd,si,wa);nn(jt,si);function cg(e){return e!=null&&typeof e=="object"&&"current"in e}function $n(e){var t;if(e!=null)return cg(e)?(t=e.current)!=null?t:void 0:e}var dg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Gn=dg?k.useLayoutEffect:k.useEffect;function ug(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Qd(e,t){const n=k.useRef(new Map),r=ug();return Gn(()=>{if(!e){n.current.clear();return}return ct(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[c]=a,f=te(()=>a[1]),d=e[c];f!==d&&(i=!0,n.current.set(c,d),o=(s=t?.(c,f,d))!=null?s:!1)}i&&(o?queueMicrotask(()=>Ju.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 fg(e,t){e()}function an(e){const t=k.useRef(e);return Gn(()=>{t.current=e},[e]),t}function Te(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($n(e));Gn(()=>{const r=$n(e);r!==n.current&&(n.current=r,t(r))})}var hg=Object.defineProperty,pg=Object.defineProperties,gg=Object.getOwnPropertyDescriptors,Ws=Object.getOwnPropertySymbols,Zd=Object.prototype.hasOwnProperty,Jd=Object.prototype.propertyIsEnumerable,ll=(e,t,n)=>t in e?hg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mg=(e,t)=>{for(var n in t||(t={}))Zd.call(t,n)&&ll(e,n,t[n]);if(Ws)for(var n of Ws(t))Jd.call(t,n)&&ll(e,n,t[n]);return e},vg=(e,t)=>pg(e,gg(t)),yg=(e,t)=>{var n={};for(var r in e)Zd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ws)for(var r of Ws(e))t.indexOf(r)<0&&Jd.call(e,r)&&(n[r]=e[r]);return n},bg=new Vd,eu=k.createContext(bg),xg=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(c=>{i.current=c})),k.startTransition(()=>{a(),r(c=>c+1)})}}),[]);return Gn(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),wi=[void 0,ut];function wg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:c}=t,f=yg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const d=k.useRef(null),{plugins:l,modifiers:u,sensors:h}=f,p=pt(l,Sn.plugins),y=pt(h,Sn.sensors),w=pt(u,Sn.modifiers),_=an(s),g=an(i),v=an(a),x=an(o),b=an(c),T=an(r),C=_g(()=>{var M;return(M=f.manager)!=null?M:new Vd(f)});return k.useEffect(()=>{if(!d.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:E}=d.current,{monitor:O}=C;C.renderer=M;const P=[O.addEventListener("beforedragstart",A=>{const L=_.current;L&&E(()=>L(A,C))}),O.addEventListener("dragstart",A=>{var L;return(L=g.current)==null?void 0:L.call(g,A,C)}),O.addEventListener("dragover",A=>{const L=v.current;L&&E(()=>L(A,C))}),O.addEventListener("dragmove",A=>{const L=x.current;L&&E(()=>L(A,C))}),O.addEventListener("dragend",A=>{const L=b.current;L&&E(()=>L(A,C))}),O.addEventListener("collision",A=>{var L;return(L=T.current)==null?void 0:L.call(T,A,C)})];return()=>P.forEach(A=>A())},[C]),Te(p,()=>C&&(C.plugins=p),...wi),Te(y,()=>C&&(C.sensors=y),...wi),Te(w,()=>C&&(C.modifiers=w),...wi),m.jsxs(eu.Provider,{value:C,children:[m.jsx(xg,{ref:d,children:n}),n]})}function _g(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 kg(){return k.useContext(eu)}function tu(e){var t;const n=(t=kg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Gn(r.register,[n,r]),r}var Sg=Object.create,nu=Object.defineProperty,$g=Object.getOwnPropertyDescriptor,ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ii=e=>{throw TypeError(e)},Tg=(e,t,n)=>t in e?nu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Eg=e=>{var t;return[,,,Sg((t=e?.[ru("metadata")])!=null?t:null)]},su=["class","method","getter","setter","accessor","field","value","get","set"],iu=e=>e!==void 0&&typeof e!="function"?ii("Function expected"):e,Cg=(e,t,n,r,s)=>({kind:su[e],name:t,metadata:r,addInitializer:i=>n._?ii("Already initialized"):s.push(iu(i||null))}),Og=(e,t)=>Tg(t,ru("metadata"),e[3]),Dg=(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},ou=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=su[d+5],y=e[h]||(e[h]=[]),w=(s=s.prototype,$g(s,n)),_=r.length-1;_>=0;_--)c=Cg(d,n,a={},e[3],y),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(w[p],c),a._=1,iu(o)&&(w[p]=o);return w&&nu(s,n,w),s},au=(e,t,n)=>t.has(e)||ii("Cannot "+n),Mg=(e,t,n)=>(au(e,t,"read from private field"),t.get(e)),Ig=(e,t,n)=>t.has(e)?ii("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jg=(e,t,n,r)=>(au(e,t,"write to private field"),t.set(e,n),n),Kt=class bo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new bo(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 bo(t,n)}},lu,cu,xo,ys,Vr,_a=class extends(xo=en,cu=[De],lu=[De],xo){constructor(e){const t=Kt.from(e);super(t,(n,r)=>Kt.equals(n,r)),Dg(Vr,5,this),Ig(this,ys,0),this.velocity={x:0,y:0}}get delta(){return Kt.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=Kt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-Mg(this,ys),o=a=>Math.round(a/i*100);Ce(()=>{jg(this,ys,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(Kt.from(e)),this.velocity={x:0,y:0}}};Vr=Eg(xo);ys=new WeakMap;ou(Vr,2,"delta",cu,_a);ou(Vr,2,"direction",lu,_a);Og(Vr,_a);var du=(e=>(e.Horizontal="x",e.Vertical="y",e))(du||{});Object.values(du);var Pg=({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=Kt.distance(t.shape.center,n);return{id:r,value:1/s,type:Fn.PointerIntersection,priority:Bn.High}}return null},Rg=({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=Kt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Fn.ShapeIntersection,priority:Bn.Normal}}return null},Ag=e=>{var t;return(t=Pg(e))!=null?t:Rg(e)};function Lg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,c=tu(d=>new si(vg(mg({},e),{register:!1,element:$n(s)}),d)),f=Qd(c);return Te(i,()=>c.id=i),vs(s,d=>c.element=d),Te(o,()=>c.accept=o,void 0,ut),Te(t,()=>c.collisionDetector=t??Ag),Te(n,()=>n&&(c.data=n)),Te(r,()=>c.disabled=r===!0),Te(a,()=>c.type=a),{droppable:f,get isDropTarget(){return f.isDropTarget},ref:k.useCallback(d=>{var l,u;!d&&((l=c.element)!=null&&l.isConnected)&&!((u=c.manager)!=null&&u.dragOperation.status.idle)||(c.element=d??void 0)},[c])}}const uu=(e,t="line")=>{const[n,r]=t==="line"?["6px","2px"]:["10px","6px"];return{cursor:"text",borderRadius:t==="line"?"4px":"6px",mx:`-${n}`,px:n,my:`-${r}`,py:r,transition:`background-color ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},fu=k.createContext(void 0);function hu(e,t){const n=k.useContext(fu),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 wo({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=ke.usePublisherTheme(),[o,a]=k.useState(void 0),c=k.useRef(!1),f=()=>{c.current||o===void 0||(a(void 0),o!==e&&r(o))};hu(o!==void 0&&o!==e,()=>(f(),!0));const d=()=>{c.current=!1,a(e)};if(o===void 0){const l=e==="",u=l&&s;return m.jsx($.Box,{component:"button",type:"button",className:u?"builder-affordance":void 0,onClick:d,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),d())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...l&&{fontStyle:"italic",opacity:u?0:.6}},uu(i)],children:l?t:e})}return m.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:l=>l.target.select(),onChange:l=>a(l.target.value),onKeyDown:l=>{l.key==="Enter"&&!l.nativeEvent.isComposing?f():l.key==="Escape"&&(c.current=!0,a(void 0))},onBlur:f,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Bg=(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}),Fg=(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},pu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),gu=e=>`gap.${e}`,zg=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),c=o===0||i.break===!0||r+a>t;c&&o>0&&r<t&&n.push({kind:"gap",after:We(e[o-1]),colspan:t-r}),c&&(r=0),n.push(pu(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:We(s),colspan:t-r}),n};var Wg=Object.create,mu=Object.defineProperty,Ng=Object.defineProperties,Gg=Object.getOwnPropertyDescriptor,Vg=Object.getOwnPropertyDescriptors,Ns=Object.getOwnPropertySymbols,vu=Object.prototype.hasOwnProperty,yu=Object.prototype.propertyIsEnumerable,Ug=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ur=e=>{throw TypeError(e)},_o=(e,t,n)=>t in e?mu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_i=(e,t)=>{for(var n in t||(t={}))vu.call(t,n)&&_o(e,n,t[n]);if(Ns)for(var n of Ns(t))yu.call(t,n)&&_o(e,n,t[n]);return e},ki=(e,t)=>Ng(e,Vg(t)),Hg=(e,t)=>{var n={};for(var r in e)vu.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&&yu.call(e,r)&&(n[r]=e[r]);return n},qg=e=>{var t;return[,,,Wg((t=void 0)!=null?t:null)]},bu=["class","method","getter","setter","accessor","field","value","get","set"],hr=e=>e!==void 0&&typeof e!="function"?Ur("Function expected"):e,Kg=(e,t,n,r,s)=>({kind:bu[e],name:t,metadata:r,addInitializer:i=>n._?Ur("Already initialized"):s.push(hr(i||null))}),Yg=(e,t)=>_o(t,Ug("metadata"),e[3]),ts=(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},xu=(e,t,n,r,s,i)=>{for(var o,a,c,f,d,l=t&7,u=!1,h=!1,p=e.length+1,y=bu[l+5],w=e[p-1]=[],_=e[p]||(e[p]=[]),g=(s=s.prototype,Gg({get[n](){return pr(this,i)},set[n](x){return qt(this,i,x)}},n)),v=r.length-1;v>=0;v--)f=Kg(l,n,c={},e[3],_),f.static=u,f.private=h,d=f.access={has:x=>n in x},d.get=x=>x[n],d.set=(x,b)=>x[n]=b,a=(0,r[v])({get:g.get,set:g.set},f),c._=1,a===void 0?hr(a)&&(g[y]=a):typeof a!="object"||a===null?Ur("Object expected"):(hr(o=a.get)&&(g.get=o),hr(o=a.set)&&(g.set=o),hr(o=a.init)&&w.unshift(o));return g&&mu(s,n,g),s},wu=(e,t,n)=>t.has(e)||Ur("Cannot "+n),pr=(e,t,n)=>(wu(e,t,"read from private field"),t.get(e)),Jn=(e,t,n)=>t.has(e)?Ur("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qt=(e,t,n,r)=>(wu(e,t,"write to private field"),t.set(e,n),n);function Yt(e){return e instanceof $a||e instanceof $u}var ns=10,Xg=class extends qe{constructor(e){super(e);const t=ct(()=>{const{dragOperation:r}=e;if(Dr(r.activatorEvent)&&Yt(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Gr);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(!Dr(r.nativeEvent)||!Yt(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:c}=s,{by:f}=r;if(!f)return;const d=Qg(f),{source:l,target:u}=i,{center:h}=i.shape.current,p=[],y=[];Ce(()=>{for(const b of c.droppables){const{id:T}=b;if(!b.accepts(l)||T===u?.id&&Yt(b)||!b.element)continue;let C=b.shape;const M=new vt(b.element,{getBoundingClientRect:E=>Cr(E,void 0,.2)});!M.height||!M.width||(d=="down"&&h.y+ns<M.center.y||d=="up"&&h.y-ns>M.center.y||d=="left"&&h.x-ns>M.center.x||d=="right"&&h.x+ns<M.center.x)&&(p.push(b),b.shape=M,y.push(()=>b.shape=C))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(p,yp);Ce(()=>y.forEach(b=>b()));const[_]=w;if(!_)return;const{id:g}=_,{index:v,group:x}=l.sortable;o.setDropTarget(g).then(()=>{const{source:b,target:T,shape:C}=i;if(!b||!Yt(b)||!C)return;const{index:M,group:E,target:O}=b.sortable,P=v!==M||x!==E,A=P?O:T?.element;if(!A)return;vd(A);const L=new vt(A);if(!L)return;const W=yt.delta(L,yt.from(C.current.boundingRectangle),b.alignment);o.move({by:W}),P?o.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Qg(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 Zg=Object.defineProperty,Jg=Object.defineProperties,em=Object.getOwnPropertyDescriptors,cl=Object.getOwnPropertySymbols,tm=Object.prototype.hasOwnProperty,nm=Object.prototype.propertyIsEnumerable,dl=(e,t,n)=>t in e?Zg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ln=(e,t)=>{for(var n in t||(t={}))tm.call(t,n)&&dl(e,n,t[n]);if(cl)for(var n of cl(t))nm.call(t,n)&&dl(e,n,t[n]);return e},cn=(e,t)=>Jg(e,em(t));function rm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function rs(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Si(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function sm(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 c=(v,x)=>v===x||v!==null&&typeof v=="object"&&"id"in v&&v.id===x;if(Array.isArray(e)){const v=e.findIndex(b=>c(b,i.id)),x=e.findIndex(b=>c(b,o.id));if(v===-1||x===-1){if(Si(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==v)return n(e,v,b)}return n(e,v,x)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[v,x]of f)if(d===-1&&(d=x.findIndex(b=>c(b,i.id)),d!==-1&&(l=v)),u===-1&&(u=x.findIndex(b=>c(b,o.id)),u!==-1&&(h=v)),d!==-1&&u!==-1)break;if(d===-1&&Si(i)){const v=i.initialGroup==null?void 0:rs(e,i.initialGroup),x=i.initialIndex,b=i.group==null?void 0:rs(e,i.group),T=i.index;if(v==null||b==null||v===b&&x===T)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return cn(ln({},e),{[v]:n(e[v],x,T)});const C=e[v][x];return cn(ln({},e),{[v]:[...e[v].slice(0,x),...e[v].slice(x+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,y=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const v=rs(e,o.id);if(v!=null){const x=o.shape&&y.y>o.shape.center.y?e[v].length:0;h=v,u=x}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&Si(i)){const v=i.group==null?void 0:rs(e,i.group),x=i.group!=null&&v!==l,b=i.index!==d;if(x||b){const T=i.group==null?l:v;if(T!=null){if(l===T)return cn(ln({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return cn(ln({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return cn(ln({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(y.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return cn(ln({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function im(e,t){return sm(e,t,rm)}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 fl(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 hl="__default__",om=class extends qe{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof $a){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(!Yt(o)||!Yt(a)||o.sortable===a.sortable)return;const c=t(),f=ul(c),d=o.sortable.group===a.sortable.group,l=c.get(o.sortable.group),u=d?l:c.get(a.sortable.group);!l||!u||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,p;const y=t();if(fl(f,c,y))return;const w=o.sortable.element,_=a.sortable.element;if(!_||!w||!d&&a.id===o.sortable.group)return;const g=ss(l),v=d?g:ss(u),x=(h=o.sortable.group)!=null?h:hl,b=(p=a.sortable.group)!=null?p:hl,T={[x]:g,[b]:v},C=im(T,r);if(T===C)return;const M=C[b].indexOf(o.sortable),E=C[b].indexOf(a.sortable);s.collisionObserver.disable(),pl(w,M,_,E),Ce(()=>{for(const[O,P]of C[x].entries())P.index=O;if(!d)for(const[O,P]of C[b].entries())P.group=a.sortable.group,P.index=O}),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;Yt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),c=ul(a),f=a.get(o.sortable.initialGroup);f&&s.renderer.rendering.then(()=>{const d=t();if(fl(c,a,d))return;const l=ss(f),u=ss(f,lm),h=o.sortable.element,p=u.indexOf(o.sortable),y=l[p],w=y?.element;!y||!w||!h||(pl(h,y.index,w,o.index),Ce(()=>{for(const _ of a.values()){const g=Array.from(_).values();for(const v of g)v.index=v.initialIndex,v.group=v.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function pl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function am(e,t){return e.index-t.index}function lm(e,t){return e.initialIndex-t.initialIndex}function ss(e,t=am){return Array.from(e).sort(t)}var gl=[Xg,om],_u={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function ml(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 is=new th,ku,Su,Pt,ka,gr,mr,Sa,yn;Su=[ne],ku=[ne];var oi=class{constructor(e,t){Jn(this,ka,ts(Pt,8,this)),ts(Pt,11,this),Jn(this,gr),Jn(this,mr),Jn(this,Sa,ts(Pt,12,this)),ts(Pt,15,this),Jn(this,yn),this.register=()=>(Ce(()=>{var p,y;(p=this.manager)==null||p.registry.register(this.droppable),(y=this.manager)==null||y.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ce(()=>{var p,y;(p=this.manager)==null||p.registry.unregister(this.droppable),(y=this.manager)==null||y.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:c,transition:f=_u,plugins:d}=n,l=Hg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=pt(d,gl),h=ml(s);this.droppable=new $a(ki(_i({},l),{disabled:h.droppable}),t,this),this.draggable=new $u(ki(_i({},l),{disabled:h.draggable,plugins:u,effects:()=>[()=>{var p,y,w;const _=(p=this.manager)==null?void 0:p.dragOperation.status;_?.initializing&&this.id===((w=(y=this.manager)==null?void 0:y.dragOperation.source)==null?void 0:w.id)&&is.clear(this.manager),_?.dragging&&is.set(this.manager,this.id,te(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:y,manager:w}=this,_=pr(this,mr),g=pr(this,gr);(p!==_||y!==g)&&(qt(this,mr,p),qt(this,gr,y),this.animate())},()=>{var p,y;const{target:w}=this,{isDragSource:_}=this.draggable;((y=(p=this.draggable.pluginConfig(pa))==null?void 0:p.feedback)!=null?y:"default")==="move"&&_&&(this.droppable.disabled=!w)},...r()],type:c,sensors:a}),t,this),qt(this,yn,l.element),this.manager=t,this.index=o,qt(this,mr,o),this.group=i,qt(this,gr,i),this.type=c,this.transition=f}get initialIndex(){var e,t;return(t=(e=is.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=is.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){te(()=>{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 d of s.getAnimations())"transitionProperty"in d&&(d.transitionProperty==="transform"||d.transitionProperty==="translate"||d.transitionProperty==="scale")&&d.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}=wt(s),c=Ja(s,a,!1),f=Ja(s,a);if(o.x||o.y){const d=oa(nt(s))?ki(_i({},t),{duration:0}):t;yd({element:s,keyframes:{translate:[`${c.x+o.x}px ${c.y+o.y}px ${c.z}`,`${f.x}px ${f.y}px ${f.z}`]},options:d}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Ce(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ce(()=>{const t=pr(this,yn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),qt(this,yn,e)})}get element(){var e,t;const n=pr(this,yn);if(n)return(t=(e=to.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=pt(e,gl)}set disabled(e){const t=ml(e);Ce(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ce(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??bd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Ce(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};Pt=qg();ka=new WeakMap;gr=new WeakMap;mr=new WeakMap;Sa=new WeakMap;yn=new WeakMap;xu(Pt,4,"index",Su,oi,ka);xu(Pt,4,"group",ku,oi,Sa);Yg(Pt,oi);var $u=class extends ri{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}},$a=class extends si{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},cm=Object.defineProperty,dm=Object.defineProperties,um=Object.getOwnPropertyDescriptors,vl=Object.getOwnPropertySymbols,fm=Object.prototype.hasOwnProperty,hm=Object.prototype.propertyIsEnumerable,yl=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$i=(e,t)=>{for(var n in t||(t={}))fm.call(t,n)&&yl(e,n,t[n]);if(vl)for(var n of vl(t))hm.call(t,n)&&yl(e,n,t[n]);return e},pm=(e,t)=>dm(e,um(t));function gm(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:c,group:f,disabled:d,modifiers:l,sensors:u,target:h,type:p,plugins:y}=e,w=$i($i({},_u),e.transition),_=tu(v=>new oi(pm($i({},e),{transition:w,register:!1,handle:$n(a),element:$n(o),target:$n(h)}),v)),g=Qd(_,mm);return Te(s,()=>_.id=s),Gn(()=>{Ce(()=>{_.group=f,_.index=c})},[_,f,c]),Te(p,()=>_.type=p),Te(t,()=>_.accept=t,void 0,ut),Te(i,()=>i&&(_.data=i)),Te(c,()=>{var v;(v=_.manager)!=null&&v.dragOperation.status.idle&&w?.idle&&_.refreshShape()},fg),vs(a,v=>_.handle=v),vs(o,v=>_.element=v),vs(h,v=>_.target=v),Te(d,()=>_.disabled=d??!1,void 0,ut),Te(u,()=>_.sensors=u,void 0,ut),Te(n,()=>_.collisionDetector=n),Te(r,()=>_.collisionPriority=r),Te(y,()=>_.plugins=y,void 0,ut),Te(w,()=>_.transition=w,void 0,ut),Te(l,()=>_.modifiers=l,void 0,ut),Te(e.alignment,()=>_.alignment=e.alignment),{sortable:g,get isDragging(){return g.isDragging},get isDropping(){return g.isDropping},get isDragSource(){return g.isDragSource},get isDropTarget(){return g.isDropTarget},handleRef:k.useCallback(v=>{_.handle=v??void 0},[_]),ref:k.useCallback(v=>{var x,b;!v&&((x=_.element)!=null&&x.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.element=v??void 0)},[_]),sourceRef:k.useCallback(v=>{var x,b;!v&&((x=_.source)!=null&&x.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.source=v??void 0)},[_]),targetRef:k.useCallback(v=>{var x,b;!v&&((x=_.target)!=null&&x.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.target=v??void 0)},[_])}}function mm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const ko="tile",Tu="gap",vm=[mo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Eu}], ${ym}`)!==null||(mo.defaults.preventActivation?.(e,t)??!1)}),Gd],Eu="data-no-drag",ym=".malloy-render, .malloy-table",bm=e=>[...e,pa.configure({feedback:"clone"})];function xm({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=gm({id:e,index:t,type:ko,accept:ko,collisionDetector:la,plugins:bm});return m.jsx(m.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function wm({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Lg({id:e,type:Tu,accept:ko,collisionDetector:la,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}const Cu=e=>e.ok===!1,Be=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Vn=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,_e={sourceDefinition:e=>Be(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Be(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Be(e,"VIEW","subQueryDefList"),defDimension:e=>Be(e,"defList","DIMENSION"),exploreProperties:e=>Be(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Be(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Be(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Be(e,"WHERE","filterClauseList"),givenDef:e=>Be(e,"givenNameDef"),givenStatement:e=>Be(e,"GIVEN","givenDefList"),importStatement:e=>Be(e,"IMPORT","importURL"),vArrow:e=>Be(e,"ARROW","vExpr","segExpr"),segRefine:e=>Be(e,"PLUS","segExpr"),segOps:e=>Be(e,"queryProperties"),segField:e=>Be(e,"fieldPath")&&!Be(e,"segExpr"),segParen:e=>Be(e,"OPAREN","CPAREN","vExpr"),compare:e=>Be(e,"fieldExpr","compareOp"),givenRef:e=>Be(e,"GIVEN_REF")};function _m(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 km(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
-
`&&t.push(n+1);return t}function Ou(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!
|
|
69
|
-
`),c=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:c,oneLine:a}}function
|
|
70
|
-
`),d=u=>c.lines.has(u);a.proseLines=
|
|
71
|
-
`||e.text[h-1]==="\r");)h--;s.push({start:u,end:h})}}const o=[...s].sort((d,l)=>d.start-l.start);let a="",c=0;for(const d of o)a+=e.text.slice(c,Math.max(c,d.start)),a+=e.text.slice(Math.max(c,d.start),Math.max(c,d.end)).replace(/[^\n\r]/g," "),c=Math.max(c,d.end);a+=e.text.slice(c);const f=d=>a.slice(e.lineStarts[d],e.lineStarts[d+1]??a.length);for(const d of s){const l=e.line(d.start),u=e.line(d.end-1);for(let
|
|
67
|
+
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Fp(e,t="hidden"){return ne(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=zp(n,r.registry.droppables),i=[],o=Ph(n),{remove:a}=o;return Wp(s,o,i),Np(o,t),o.remove=()=>{i.forEach(c=>c()),a.call(o)},o})}function zp(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${zr}${oo("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Wp(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),no.set(a,o),n.push(()=>{no.delete(a),r.proxy=void 0})}}function Np(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(zs,t)}function jd(e,t){return e===t?!0:On(e)===On(t)}function nl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Qt(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Sn(t))}function uo(e){return e.tagName==="TR"}function Gp(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-")||Ap.includes(a))continue;const c=e.getAttribute(a);if(a==="style"){if(wr(e)&&wr(t)){const f=e.style;for(const d of Array.from(t.style))f.getPropertyValue(d)===""&&t.style.removeProperty(d);for(const d of Array.from(f)){if(Lp.includes(d)||d.startsWith(He))continue;const l=f.getPropertyValue(d);t.style.setProperty(d,l)}}}else c!==null?t.setAttribute(a,c):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Up(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),Sn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Sn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Sn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Hp(e){return new ResizeObserver(()=>{var t,n,r;const s=new yt(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,c=ld();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+c.y,left:e.left+o+c.x},He),(n=e.getElementMutationObserver())==null||n.takeRecords(),uo(e.element)&&uo(e.placeholder)){const v=Array.from(e.element.cells),x=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(v.map(_=>_.style.width));for(const[_,g]of v.entries()){const y=x[_];g.style.width=`${y.getBoundingClientRect().width}px`}}const f=(r=e.getTranslate())!=null?r:{x:0,y:0},d=e.left+o+c.x+f.x,l=e.top+a+c.y+f.y,u=s.width-e.widthOffset,h=s.height-e.heightOffset,p=e.frameTransform;e.dragOperation.shape=new bt(d*p.scaleX+p.x,l*p.scaleY+p.y,u*p.scaleX,h*p.scaleY)})}var Vp=250,Kp="ease";function qp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const g=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(g).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Vp,easing:a=Kp}=i??{};Sn(e.feedbackElement);const[,c]=(t=id(e.feedbackElement,g=>"translate"in g))!=null?t:[];c?.pause();const f=(n=e.placeholder)!=null?n:e.element,d={frameTransform:jd(e.feedbackElement,f)?null:void 0},l=new yt(e.feedbackElement,d),u=(r=Er(_t(e.feedbackElement).translate))!=null?r:e.translate,h=new yt(f,d),p=bt.delta(l,h,e.alignment),v={x:u.x-p.x,y:u.y-p.y},x=Math.round(l.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},_=Math.round(l.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},He),e.feedbackElement.setAttribute(co,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),yd({element:e.feedbackElement,keyframes:ua(Or(Or({},x),_),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:aa(st(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(co),c?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Pd,fo,Dr,pa,ys,Rd,Ad,In=class extends(fo=qe,Pd=[re],fo){constructor(t,n){super(t,n),Pe(this,ys),Pe(this,pa,ze(Dr,8,this)),ze(Dr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(si),s=r?.register(Bp);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Zt(this,ys,Rd).bind(this,r)),this.registerEffect(Zt(this,ys,Ad))}};Dr=Gn(fo);pa=new WeakMap;ys=new WeakSet;Rd=function(e){const{overlay:t}=this;if(!t||!e)return;const n=js(t);if(n)return e.addRoot(n)};Ad=function(){var e,t,n,r,s,i,o;const{state:a,manager:c,options:f}=this,{dragOperation:d}=c,{position:l,source:u,status:h}=d;if(h.idle){a.current={},a.initial={};return}if(!u)return;const{element:p}=u,v=u.pluginConfig(In),x=(t=(e=v?.feedback)!=null?e:f?.feedback)!=null?t:"default",_=typeof x=="function"?x(u,c):x;if(!p||_==="none"||!h.initialized||h.initializing)return;const{initial:g}=a,y=(n=this.overlay)!=null?n:p,w=Dn(y),b=Dn(p),T=!jd(p,y),C=new yt(p,{frameTransform:T?b:null,ignoreTransforms:!T}),M={x:b.scaleX/w.scaleX,y:b.scaleY/w.scaleY};let{width:E,height:O,top:A,left:j}=C;T&&(E=E/M.x,O=O/M.y);const L=new hp(y),N=_t(p),{transition:W,translate:V,boxSizing:I,paddingBlockStart:F,paddingBlockEnd:H,paddingInlineStart:B,paddingInlineEnd:G,borderInlineStartWidth:ee,borderInlineEndWidth:Q,borderBlockStartWidth:J,borderBlockEndWidth:X}=N,te=W.split(",").filter(ce=>!/^\s*(transform|translate|scale)\b/.test(ce)).join(","),we=ri(N),me=N.transform,ye=_==="clone",$e=I==="content-box",ue=$e?parseInt(B)+parseInt(G)+parseInt(ee)+parseInt(Q):0,ve=$e?parseInt(F)+parseInt(H)+parseInt(J)+parseInt(X):0,Z=_!=="move"&&!this.overlay?Fp(u,ye?"clone":"hidden"):null,Ue=ne(()=>Cr(c.dragOperation.activatorEvent));if(!g.translate){if(this.overlay&&we)g.translate={x:we.x,y:we.y};else if(V!=="none"){const ce=Er(V);ce&&(g.translate=ce)}}if(!g.transformOrigin){const ce=ne(()=>l.current),Re=j+((r=we?.x)!=null?r:0),tt=A+((s=we?.y)!=null?s:0);g.transformOrigin={x:(ce.x-Re*w.scaleX-w.x)/(E*w.scaleX),y:(ce.y-tt*w.scaleY-w.y)/(O*w.scaleY)}}const{transformOrigin:fe}=g,le=A*w.scaleY+w.y,Le=j*w.scaleX+w.x;if(!g.coordinates&&(g.coordinates={x:Le,y:le},M.x!==1||M.y!==1)){const{scaleX:ce,scaleY:Re}=b,{x:tt,y:Ct}=fe;g.coordinates.x+=(E*ce-E)*tt,g.coordinates.y+=(O*Re-O)*Ct}g.dimensions||(g.dimensions={width:E,height:O}),g.frameTransform||(g.frameTransform=w);const We={x:g.coordinates.x-Le,y:g.coordinates.y-le},he={width:(g.dimensions.width*g.frameTransform.scaleX-E*w.scaleX)*fe.x,height:(g.dimensions.height*g.frameTransform.scaleY-O*w.scaleY)*fe.y},Ne={x:We.x/w.scaleX+he.width,y:We.y/w.scaleY+he.height},Oe={left:j+Ne.x,top:A+Ne.y};y.setAttribute(vt,"true");const D=ne(()=>d.transform),R=(i=g.translate)!=null?i:{x:0,y:0},z=D.x*w.scaleX+R.x,P=D.y*w.scaleY+R.y,U=ld();L.set({width:E-ue,height:O-ve,top:Oe.top+U.y,left:Oe.left+U.x,translate:`${z}px ${P}px 0`,transform:this.overlay?"none":me,transition:te?`${te}, translate 0ms linear`:"translate 0ms linear",scale:T?`${M.x} ${M.y}`:"","transform-origin":`${fe.x*100}% ${fe.y*100}%`},He),Z&&(p.insertAdjacentElement("afterend",Z),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(p)),so(y)&&(y.hasAttribute("popover")||y.setAttribute("popover","manual"),Sn(y),y.addEventListener("beforetoggle",nl));let K,ie,_e;const oe=Hp({placeholder:Z,element:p,feedbackElement:y,frameTransform:w,transformOrigin:fe,width:E,height:O,top:A,left:j,widthOffset:ue,heightOffset:ve,delta:Ne,styles:L,dragOperation:d,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>K,getSavedCellWidths:()=>_e,setSavedCellWidths:ce=>{_e=ce}}),Ge=new yt(y);ne(()=>d.shape=Ge);const et=st(y),Vr=ce=>{this.manager.actions.stop({event:ce})},rn=aa(et);Ue&&et.addEventListener("resize",Vr),ne(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),Z&&(oe.observe(Z),K=Gp(p,Z,ye),ie=Up(p,Z,y));const sn=(o=c.dragOperation.source)==null?void 0:o.id,Kr=()=>{var ce;if(!Ue||sn==null)return;const Re=c.registry.draggables.get(sn),tt=(ce=Re?.handle)!=null?ce:Re?.element;At(tt)&&tt.focus()},qr=()=>{K?.disconnect(),ie?.disconnect(),oe.disconnect(),et.removeEventListener("resize",Vr),so(y)&&(y.removeEventListener("beforetoggle",nl),y.removeAttribute("popover")),y.removeAttribute(vt),L.reset();const ce=()=>{var Re;if(_e&&uo(p)){const di=Array.from(p.cells);for(const[Xr,on]of di.entries())on.style.width=(Re=_e[Xr])!=null?Re:""}u.status="idle";const tt=a.current.translate!=null,Ct=d.status.dragging;Z&&(!Ct&&tt||Z.parentElement!==y.parentElement)&&y.isConnected&&Z.replaceWith(y),Z?.remove()};y===this.overlay?setTimeout(ce,0):ce()},ci=f?.dropAnimation,Yr=this,Vn=Rr(()=>{var ce,Re,tt;const{transform:Ct,status:di}=d;if(!(!Ct.x&&!Ct.y&&!a.current.translate)&&di.dragging){const Xr=(ce=g.translate)!=null?ce:{x:0,y:0},on={x:Ct.x/w.scaleX+Xr.x,y:Ct.y/w.scaleY+Xr.y},Ia=a.current.translate,Zu=ne(()=>d.modifiers),ui=ne(()=>{var qn;return(qn=d.shape)==null?void 0:qn.current}),Kn=f?.keyboardTransition,ja=Ue&&!rn&&Kn!==null?`${(Re=Kn?.duration)!=null?Re:250}ms ${(tt=Kn?.easing)!=null?tt:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:te?`${te}, translate ${ja}`:`translate ${ja}`,translate:`${on.x}px ${on.y}px 0`},He),K?.takeRecords(),ui&&ui!==Ge&&Ia&&!Zu.length){const qn=ot.delta(on,Ia);d.shape=bt.from(ui.boundingRectangle).translate(qn.x*w.scaleX,qn.y*w.scaleY)}else d.shape=new yt(y);a.current.translate=on}},function(){if(d.status.dropped){this.dispose(),u.status="dropping";const ce=v?.dropAnimation!==void 0?v.dropAnimation:Yr.dropAnimation!==void 0?Yr.dropAnimation:ci;let Re=a.current.translate;const tt=Re!=null;if(!Re&&p!==y&&(Re={x:0,y:0}),!Re||ce===null){qr();return}c.renderer.rendering.then(()=>{qp({source:u,element:p,feedbackElement:y,placeholder:Z,translate:Re,moved:tt,transition:W,alignment:u.alignment,styles:L,animation:ce??void 0,getElementMutationObserver:()=>K,cleanup:qr,restoreFocus:Kr})})}});return()=>{qr(),Vn()}};ut(Dr,4,"overlay",Pd,In,pa);nn(Dr,In);In.configure=Lr(In);var ga=In,Xn=!0,Yp=!1,Ld,Bd,Fd,zd,It,ma,va;zd=(Fd=[re],at.Forward),Bd=(Ld=[re],at.Reverse);var Mr=class{constructor(){Pe(this,ma,ze(It,8,this,Xn)),ze(It,11,this),Pe(this,va,ze(It,12,this,Xn)),ze(It,15,this)}isLocked(e){return e===at.Idle?!1:e==null?this[at.Forward]===Xn&&this[at.Reverse]===Xn:this[e]===Xn}unlock(e){e!==at.Idle&&(this[e]=Yp)}};It=Gn(null);ma=new WeakMap;va=new WeakMap;ut(It,4,zd,Fd,Mr,ma);ut(It,4,Bd,Ld,Mr,va);nn(It,Mr);var Xp=[at.Forward,at.Reverse],rl=class{constructor(){this.x=new Mr,this.y=new Mr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Qp=class extends qe{constructor(e){super(e);const t=jn(new rl);let n=null;this.signal=t,dt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new rl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:sl(s.x,n.x),y:sl(s.y,n.y)},o=t.peek();Ce(()=>{for(const a of gc)for(const c of Xp)i[a]===c&&o[a].unlock(c);t.value=o})}n=s})}get current(){return this.signal.peek()}};function sl(e,t){return Math.sign(e-t)}var Wd,ho,Ir,ya,Dt,po,Wr=class extends(ho=Br,Wd=[re],ho){constructor(e){super(e),Pe(this,ya,ze(Ir,8,this,!1)),ze(Ir,11,this),Pe(this,Dt),Pe(this,po,()=>{if(!ge(this,Dt))return;const{element:i,by:o}=ge(this,Dt);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const c=this.getScrollableElements();if(!c)return Qe(this,Dt,void 0),!1;const{position:f}=this.manager.dragOperation,d=f?.current;if(d){const{by:l}=i??{},u=l?{x:il(l.x),y:il(l.y)}:void 0,h=u?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of c){const v=Kh(p,l);if(v.x||v.y){const{speed:x,direction:_}=sp(p,d,u,o?.acceleration,o?.threshold);if(h)for(const g of gc)h[g].isLocked(_[g])&&(x[g]=0,_[g]=0);if(_.x||_.y){const{x:g,y}=l??_,w=g*x.x,b=y*x.y;if(w||b){const T=(a=ge(this,Dt))==null?void 0:a.by;if(this.autoScrolling&&T&&(T.x&&!w||T.y&&!b))continue;return Qe(this,Dt,{element:p,by:{x:w,y:b}}),As.schedule(ge(this,po)),!0}}}}}return Qe(this,Dt,void 0),!1};let t=null,n=null;const r=Ni(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=cd(js(o?.element),i.current);return a&&(t=a),a??t}),s=Ni(()=>{const i=r.value,{documentElement:o}=Wn(i);if(!i||i===o){const{target:a}=e.dragOperation,c=a?.element;if(c){const f=io(c,{excludeElement:!1});return n=f,f}}if(i){const a=io(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},ft);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Qp(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!Cr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};Ir=Gn(ho);ya=new WeakMap;Dt=new WeakMap;po=new WeakMap;ut(Ir,4,"autoScrolling",Wd,Wr,ya);nn(Ir,Wr);function il(e){return e>0?at.Forward:e<0?at.Reverse:at.Idle}var Zp=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))}},Jp=new Zp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),eg=10,go=class extends qe{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Wr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=dt(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:c}=t.dragOperation;if(c.dragging){const f={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,f)){r.autoScrolling=!0;const l=setInterval(()=>Jp.schedule(()=>r.scroll(void 0,f)),eg);return()=>{clearInterval(l)}}else r.autoScrolling=!1}})}};go.configure=Lr(go);var Nd=go,ol={capture:!0,passive:!0},cr,tg=class extends Br{constructor(e){super(e),Pe(this,cr),this.handleScroll=()=>{ge(this,cr)==null&&Qe(this,cr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Qe(this,cr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=dt(()=>{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,ol),()=>{o.removeEventListener("scroll",this.handleScroll,ol)}}})}};cr=new WeakMap;var ng="* { user-select: none !important; -webkit-user-select: none !important; }",rg=class extends qe{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(si),n=t?.register(ng);if(this.destroy=dt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return xi(),document.addEventListener("selectionchange",xi,{capture:!0}),()=>{document.removeEventListener("selectionchange",xi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function xi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var dr=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}}),mn,Ws=class extends En{constructor(t,n){super(t),this.manager=t,this.options=n,Pe(this,mn,[]),this.listeners=new dd,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Qt(r.target)||s.disabled)return;const{keyboardCodes:o=dr.keyboardCodes,preventActivation:a=dr.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 dt(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{Cr(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(),vd(s);const{center:i}=new yt(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=Wn(s),c=[this.listeners.bind(a,[{type:"keydown",listener:f=>this.handleKeyDown(f,n,r),options:{capture:!0}}])];ge(this,mn).push(...c)}handleKeyDown(t,n,r){const{keyboardCodes:s=dr.keyboardCodes}=r??{};if(an(t,[...s.end,...s.cancel])){t.preventDefault();const i=an(t,s.cancel);this.handleEnd(t,i);return}an(t,s.up)?this.handleMove("up",t):an(t,s.down)&&this.handleMove("down",t),an(t,s.left)?this.handleMove("left",t):an(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},c=(s=(r=this.options)==null?void 0:r.offset)!=null?s:dr.offset;if(typeof c=="number"&&(c={x:c,y:c}),!!i){switch(t){case"up":a={x:0,y:-c.y*o};break;case"down":a={x:0,y:c.y*o};break;case"left":a={x:-c.x*o,y:0};break;case"right":a={x:c.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(Nd);t?.disabled===!1&&(t.disable(),ge(this,mn).push(()=>{t.enable()}))}cleanup(){ge(this,mn).forEach(t=>t()),Qe(this,mn,[])}destroy(){this.cleanup(),this.listeners.clear()}};mn=new WeakMap;Ws.configure=Lr(Ws);Ws.defaults=dr;var Gd=Ws;function an(e,t){return t.includes(e.code)}var Ht,sg=class extends Kc{constructor(){super(...arguments),Pe(this,Ht)}onEvent(e){switch(e.type){case"pointerdown":Qe(this,Ht,Cn(e));break;case"pointermove":if(!ge(this,Ht))return;const{x:t,y:n}=Cn(e),r={x:t-ge(this,Ht).x,y:n-ge(this,Ht).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(){Qe(this,Ht,void 0)}};Ht=new WeakMap;var vn,Vt,ig=class extends Kc{constructor(){super(...arguments),Pe(this,vn),Pe(this,Vt)}onEvent(e){switch(e.type){case"pointerdown":Qe(this,Vt,Cn(e)),Qe(this,vn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ge(this,Vt))return;const{x:t,y:n}=Cn(e),r={x:t-ge(this,Vt).x,y:n-ge(this,Vt).y};Qi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ge(this,vn)&&(clearTimeout(ge(this,vn)),Qe(this,Vt,void 0),Qe(this,vn,void 0))}};vn=new WeakMap;Vt=new WeakMap;var wn=class{};wn.Delay=ig;wn.Distance=sg;var mo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Qt(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new wn.Delay({value:250,tolerance:5})]:gp(s)&&!e.defaultPrevented?[new wn.Delay({value:200,tolerance:0})]:[new wn.Delay({value:200,tolerance:10}),new wn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Qt(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Ah(r);return s===t.element?!1:!!s}}),yn,Ns=class extends En{constructor(t,n){super(t),this.manager=t,this.options=n,Pe(this,yn,new Set),this.listeners=new dd,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=mo.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return dt(()=>{var s;const i=new AbortController,{signal:o}=i,a=f=>{pp(f)&&this.handlePointerDown(f,t,n)};let c=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?c=n.activatorElements:c=n.activatorElements(t));for(const f of c)f&&(lg(f.ownerDocument.defaultView),f.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Qt(t.target)||n.disabled||og(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=mo.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=At(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=Dn(n.element),{x:c,y:f}=Cn(t);this.initialCoordinates={x:c*a.scaleX+a.x,y:f*a.scaleY+a.y};const d=this.activationConstraints(t,n,r);t.sensor=this;const l=new Eh(d,v=>this.handleStart(n,v));l.signal.onabort=()=>this.handleCancel(t),l.onEvent(t),this.controller=l;const u=to(),h=this.listeners.bind(u,[{type:"pointermove",listener:v=>this.handlePointerMove(v,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:ns,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};ge(this,yn).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=Cn(t),o=Dn(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,As.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=Wn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const c=Qt(n.target)?[n.target,a]:a,f=this.listeners.bind(c,[{type:"touchmove",listener:ns,options:{passive:!1}},{type:"click",listener:ns},{type:"contextmenu",listener:ns},{type:"keydown",listener:this.handleKeyDown}]);ge(this,yn).add(f)}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},ge(this,yn).forEach(n=>n()),ge(this,yn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};yn=new WeakMap;Ns.configure=Lr(Ns);Ns.defaults=mo;var vo=Ns;function og(e){return"sensor"in e}function ns(e){e.preventDefault()}function ag(){}var al=new WeakSet;function lg(e){!e||al.has(e)||(e.addEventListener("touchmove",ag,{capture:!1,passive:!1}),al.add(e))}var $n={modifiers:[],plugins:[jp,Nd,Rp,ga,rg],sensors:[vo,Gd]},Ud=class extends Dh{constructor(e={}){const t=gt(e.plugins,$n.plugins),n=gt(e.sensors,$n.sensors),r=gt(e.modifiers,$n.modifiers);super(ua(Or({},e),{plugins:[tg,Wr,si,...t],sensors:n,modifiers:r}))}},Hd,Vd,yo,jt,ba,xa,ii=class extends(yo=xt,Vd=[re],Hd=[re],yo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=kd(n,["element","effects","handle"]);super(Or({effects:()=>[...s(),()=>{var a,c;const{manager:f}=this;if(!f)return;const l=((c=(a=this.sensors)==null?void 0:a.map(Sr))!=null?c:[...f.sensors]).map(u=>{const h=u instanceof En?u:f.registry.register(u.plugin),p=u instanceof En?void 0:u.options;return h.bind(this,p)});return function(){l.forEach(h=>h())}}]},o),t),Pe(this,ba,ze(jt,8,this)),ze(jt,11,this),Pe(this,xa,ze(jt,12,this)),ze(jt,15,this),this.element=r,this.handle=i}};jt=Gn(yo);ba=new WeakMap;xa=new WeakMap;ut(jt,4,"handle",Vd,ii,ba);ut(jt,4,"element",Hd,ii,xa);nn(jt,ii);var Kd,qd,bo,Pt,wa,wi,Yd,Xd,kr,_a,oi=class extends(bo=wt,qd=[re],Kd=[re],bo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=kd(n,["element","effects"]);const{collisionDetector:o=bd}=i,a=f=>{const{manager:d,element:l}=this;if(!l||f===null){this.shape=void 0;return}if(!d)return;const u=new yt(l),h=ne(()=>this.shape);return u&&h?.equals(u)?h:(this.shape=u,u)},c=jn(!1);super(ua(Or({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:f,manager:d}=this;if(!d)return;const{dragOperation:l}=d,{source:u}=l;c.value=!!(u&&l.status.initialized&&f&&!this.disabled&&this.accepts(u))},()=>{const{element:f}=this;if(c.value&&f){const d=new Vh(f,a);return()=>{d.disconnect(),this.shape=void 0}}},()=>{var f;if((f=this.manager)!=null&&f.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Pe(this,kr),Pe(this,wa,ze(Pt,8,this)),ze(Pt,11,this),Pe(this,_a,ze(Pt,12,this)),ze(Pt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Qe(this,kr,e,Xd)}get element(){var e;return(e=this.proxy)!=null?e:ge(this,kr,Yd)}};Pt=Gn(bo);wa=new WeakMap;kr=new WeakSet;_a=new WeakMap;wi=ut(Pt,20,"#element",qd,kr,wa),Yd=wi.get,Xd=wi.set;ut(Pt,4,"proxy",Kd,oi,_a);nn(Pt,oi);function cg(e){return e!=null&&typeof e=="object"&&"current"in e}function Tn(e){var t;if(e!=null)return cg(e)?(t=e.current)!=null?t:void 0:e}var dg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Un=dg?k.useLayoutEffect:k.useEffect;function ug(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Qd(e,t){const n=k.useRef(new Map),r=ug();return Un(()=>{if(!e){n.current.clear();return}return dt(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[c]=a,f=ne(()=>a[1]),d=e[c];f!==d&&(i=!0,n.current.set(c,d),o=(s=t?.(c,f,d))!=null?s:!1)}i&&(o?queueMicrotask(()=>Ju.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 fg(e,t){e()}function ln(e){const t=k.useRef(e);return Un(()=>{t.current=e},[e]),t}function Te(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 bs(e,t){const n=k.useRef(Tn(e));Un(()=>{const r=Tn(e);r!==n.current&&(n.current=r,t(r))})}var hg=Object.defineProperty,pg=Object.defineProperties,gg=Object.getOwnPropertyDescriptors,Gs=Object.getOwnPropertySymbols,Zd=Object.prototype.hasOwnProperty,Jd=Object.prototype.propertyIsEnumerable,ll=(e,t,n)=>t in e?hg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mg=(e,t)=>{for(var n in t||(t={}))Zd.call(t,n)&&ll(e,n,t[n]);if(Gs)for(var n of Gs(t))Jd.call(t,n)&&ll(e,n,t[n]);return e},vg=(e,t)=>pg(e,gg(t)),yg=(e,t)=>{var n={};for(var r in e)Zd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Gs)for(var r of Gs(e))t.indexOf(r)<0&&Jd.call(e,r)&&(n[r]=e[r]);return n},bg=new Ud,eu=k.createContext(bg),xg=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(c=>{i.current=c})),k.startTransition(()=>{a(),r(c=>c+1)})}}),[]);return Un(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),_i=[void 0,ft];function wg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:c}=t,f=yg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const d=k.useRef(null),{plugins:l,modifiers:u,sensors:h}=f,p=gt(l,$n.plugins),v=gt(h,$n.sensors),x=gt(u,$n.modifiers),_=ln(s),g=ln(i),y=ln(a),w=ln(o),b=ln(c),T=ln(r),C=_g(()=>{var M;return(M=f.manager)!=null?M:new Ud(f)});return k.useEffect(()=>{if(!d.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:E}=d.current,{monitor:O}=C;C.renderer=M;const A=[O.addEventListener("beforedragstart",j=>{const L=_.current;L&&E(()=>L(j,C))}),O.addEventListener("dragstart",j=>{var L;return(L=g.current)==null?void 0:L.call(g,j,C)}),O.addEventListener("dragover",j=>{const L=y.current;L&&E(()=>L(j,C))}),O.addEventListener("dragmove",j=>{const L=w.current;L&&E(()=>L(j,C))}),O.addEventListener("dragend",j=>{const L=b.current;L&&E(()=>L(j,C))}),O.addEventListener("collision",j=>{var L;return(L=T.current)==null?void 0:L.call(T,j,C)})];return()=>A.forEach(j=>j())},[C]),Te(p,()=>C&&(C.plugins=p),..._i),Te(v,()=>C&&(C.sensors=v),..._i),Te(x,()=>C&&(C.modifiers=x),..._i),m.jsxs(eu.Provider,{value:C,children:[m.jsx(xg,{ref:d,children:n}),n]})}function _g(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 kg(){return k.useContext(eu)}function tu(e){var t;const n=(t=kg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Un(r.register,[n,r]),r}var Sg=Object.create,nu=Object.defineProperty,$g=Object.getOwnPropertyDescriptor,ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ai=e=>{throw TypeError(e)},Tg=(e,t,n)=>t in e?nu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Eg=e=>{var t;return[,,,Sg((t=e?.[ru("metadata")])!=null?t:null)]},su=["class","method","getter","setter","accessor","field","value","get","set"],iu=e=>e!==void 0&&typeof e!="function"?ai("Function expected"):e,Cg=(e,t,n,r,s)=>({kind:su[e],name:t,metadata:r,addInitializer:i=>n._?ai("Already initialized"):s.push(iu(i||null))}),Og=(e,t)=>Tg(t,ru("metadata"),e[3]),Dg=(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},ou=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=su[d+5],v=e[h]||(e[h]=[]),x=(s=s.prototype,$g(s,n)),_=r.length-1;_>=0;_--)c=Cg(d,n,a={},e[3],v),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(x[p],c),a._=1,iu(o)&&(x[p]=o);return x&&nu(s,n,x),s},au=(e,t,n)=>t.has(e)||ai("Cannot "+n),Mg=(e,t,n)=>(au(e,t,"read from private field"),t.get(e)),Ig=(e,t,n)=>t.has(e)?ai("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jg=(e,t,n,r)=>(au(e,t,"write to private field"),t.set(e,n),n),qt=class xo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new xo(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 xo(t,n)}},lu,cu,wo,xs,Nr,ka=class extends(wo=en,cu=[Me],lu=[Me],wo){constructor(e){const t=qt.from(e);super(t,(n,r)=>qt.equals(n,r)),Dg(Nr,5,this),Ig(this,xs,0),this.velocity={x:0,y:0}}get delta(){return qt.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=qt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-Mg(this,xs),o=a=>Math.round(a/i*100);Ce(()=>{jg(this,xs,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(qt.from(e)),this.velocity={x:0,y:0}}};Nr=Eg(wo);xs=new WeakMap;ou(Nr,2,"delta",cu,ka);ou(Nr,2,"direction",lu,ka);Og(Nr,ka);var du=(e=>(e.Horizontal="x",e.Vertical="y",e))(du||{});Object.values(du);var Pg=({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=qt.distance(t.shape.center,n);return{id:r,value:1/s,type:zn.PointerIntersection,priority:Fn.High}}return null},Rg=({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=qt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:zn.ShapeIntersection,priority:Fn.Normal}}return null},Ag=e=>{var t;return(t=Pg(e))!=null?t:Rg(e)};function Lg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,c=tu(d=>new oi(vg(mg({},e),{register:!1,element:Tn(s)}),d)),f=Qd(c);return Te(i,()=>c.id=i),bs(s,d=>c.element=d),Te(o,()=>c.accept=o,void 0,ft),Te(t,()=>c.collisionDetector=t??Ag),Te(n,()=>n&&(c.data=n)),Te(r,()=>c.disabled=r===!0),Te(a,()=>c.type=a),{droppable:f,get isDropTarget(){return f.isDropTarget},ref:k.useCallback(d=>{var l,u;!d&&((l=c.element)!=null&&l.isConnected)&&!((u=c.manager)!=null&&u.dragOperation.status.idle)||(c.element=d??void 0)},[c])}}const uu=(e,t="line")=>{const[n,r]=t==="line"?["6px","2px"]:["10px","6px"];return{cursor:"text",borderRadius:t==="line"?"4px":"6px",mx:`-${n}`,px:n,my:`-${r}`,py:r,transition:`background-color ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},fu=k.createContext(void 0);function hu(e,t){const n=k.useContext(fu),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 _o({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=Se.usePublisherTheme(),[o,a]=k.useState(void 0),c=k.useRef(!1),f=()=>{c.current||o===void 0||(a(void 0),o!==e&&r(o))};hu(o!==void 0&&o!==e,()=>(f(),!0));const d=()=>{c.current=!1,a(e)};if(o===void 0){const l=e==="",u=l&&s;return m.jsx($.Box,{component:"button",type:"button",className:u?"builder-affordance":void 0,onClick:d,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),d())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...l&&{fontStyle:"italic",opacity:u?0:.6}},uu(i)],children:l?t:e})}return m.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:l=>l.target.select(),onChange:l=>a(l.target.value),onKeyDown:l=>{l.key==="Enter"&&!l.nativeEvent.isComposing?f():l.key==="Escape"&&(c.current=!0,a(void 0))},onBlur:f,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Bg=(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}),Fg=(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},pu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),gu=e=>`gap.${e}`,zg=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),c=o===0||i.break===!0||r+a>t;c&&o>0&&r<t&&n.push({kind:"gap",after:Fe(e[o-1]),colspan:t-r}),c&&(r=0),n.push(pu(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 Wg=Object.create,mu=Object.defineProperty,Ng=Object.defineProperties,Gg=Object.getOwnPropertyDescriptor,Ug=Object.getOwnPropertyDescriptors,Us=Object.getOwnPropertySymbols,vu=Object.prototype.hasOwnProperty,yu=Object.prototype.propertyIsEnumerable,Hg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Gr=e=>{throw TypeError(e)},ko=(e,t,n)=>t in e?mu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ki=(e,t)=>{for(var n in t||(t={}))vu.call(t,n)&&ko(e,n,t[n]);if(Us)for(var n of Us(t))yu.call(t,n)&&ko(e,n,t[n]);return e},Si=(e,t)=>Ng(e,Ug(t)),Vg=(e,t)=>{var n={};for(var r in e)vu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Us)for(var r of Us(e))t.indexOf(r)<0&&yu.call(e,r)&&(n[r]=e[r]);return n},Kg=e=>{var t;return[,,,Wg((t=void 0)!=null?t:null)]},bu=["class","method","getter","setter","accessor","field","value","get","set"],ur=e=>e!==void 0&&typeof e!="function"?Gr("Function expected"):e,qg=(e,t,n,r,s)=>({kind:bu[e],name:t,metadata:r,addInitializer:i=>n._?Gr("Already initialized"):s.push(ur(i||null))}),Yg=(e,t)=>ko(t,Hg("metadata"),e[3]),rs=(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},xu=(e,t,n,r,s,i)=>{for(var o,a,c,f,d,l=t&7,u=!1,h=!1,p=e.length+1,v=bu[l+5],x=e[p-1]=[],_=e[p]||(e[p]=[]),g=(s=s.prototype,Gg({get[n](){return fr(this,i)},set[n](w){return Kt(this,i,w)}},n)),y=r.length-1;y>=0;y--)f=qg(l,n,c={},e[3],_),f.static=u,f.private=h,d=f.access={has:w=>n in w},d.get=w=>w[n],d.set=(w,b)=>w[n]=b,a=(0,r[y])({get:g.get,set:g.set},f),c._=1,a===void 0?ur(a)&&(g[v]=a):typeof a!="object"||a===null?Gr("Object expected"):(ur(o=a.get)&&(g.get=o),ur(o=a.set)&&(g.set=o),ur(o=a.init)&&x.unshift(o));return g&&mu(s,n,g),s},wu=(e,t,n)=>t.has(e)||Gr("Cannot "+n),fr=(e,t,n)=>(wu(e,t,"read from private field"),t.get(e)),Qn=(e,t,n)=>t.has(e)?Gr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Kt=(e,t,n,r)=>(wu(e,t,"write to private field"),t.set(e,n),n);function Yt(e){return e instanceof Ta||e instanceof $u}var ss=10,Xg=class extends qe{constructor(e){super(e);const t=dt(()=>{const{dragOperation:r}=e;if(Cr(r.activatorEvent)&&Yt(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Wr);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(!Cr(r.nativeEvent)||!Yt(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:c}=s,{by:f}=r;if(!f)return;const d=Qg(f),{source:l,target:u}=i,{center:h}=i.shape.current,p=[],v=[];Ce(()=>{for(const b of c.droppables){const{id:T}=b;if(!b.accepts(l)||T===u?.id&&Yt(b)||!b.element)continue;let C=b.shape;const M=new yt(b.element,{getBoundingClientRect:E=>Tr(E,void 0,.2)});!M.height||!M.width||(d=="down"&&h.y+ss<M.center.y||d=="up"&&h.y-ss>M.center.y||d=="left"&&h.x-ss>M.center.x||d=="right"&&h.x+ss<M.center.x)&&(p.push(b),b.shape=M,v.push(()=>b.shape=C))}}),r.preventDefault(),a.disable();const x=a.computeCollisions(p,yp);Ce(()=>v.forEach(b=>b()));const[_]=x;if(!_)return;const{id:g}=_,{index:y,group:w}=l.sortable;o.setDropTarget(g).then(()=>{const{source:b,target:T,shape:C}=i;if(!b||!Yt(b)||!C)return;const{index:M,group:E,target:O}=b.sortable,A=y!==M||w!==E,j=A?O:T?.element;if(!j)return;vd(j);const L=new yt(j);if(!L)return;const N=bt.delta(L,bt.from(C.current.boundingRectangle),b.alignment);o.move({by:N}),A?o.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Qg(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 Zg=Object.defineProperty,Jg=Object.defineProperties,em=Object.getOwnPropertyDescriptors,cl=Object.getOwnPropertySymbols,tm=Object.prototype.hasOwnProperty,nm=Object.prototype.propertyIsEnumerable,dl=(e,t,n)=>t in e?Zg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,cn=(e,t)=>{for(var n in t||(t={}))tm.call(t,n)&&dl(e,n,t[n]);if(cl)for(var n of cl(t))nm.call(t,n)&&dl(e,n,t[n]);return e},dn=(e,t)=>Jg(e,em(t));function rm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function is(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function $i(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function sm(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 c=(y,w)=>y===w||y!==null&&typeof y=="object"&&"id"in y&&y.id===w;if(Array.isArray(e)){const y=e.findIndex(b=>c(b,i.id)),w=e.findIndex(b=>c(b,o.id));if(y===-1||w===-1){if($i(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==y)return n(e,y,b)}return n(e,y,w)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[y,w]of f)if(d===-1&&(d=w.findIndex(b=>c(b,i.id)),d!==-1&&(l=y)),u===-1&&(u=w.findIndex(b=>c(b,o.id)),u!==-1&&(h=y)),d!==-1&&u!==-1)break;if(d===-1&&$i(i)){const y=i.initialGroup==null?void 0:is(e,i.initialGroup),w=i.initialIndex,b=i.group==null?void 0:is(e,i.group),T=i.index;if(y==null||b==null||y===b&&w===T)return"preventDefault"in t&&t.preventDefault(),e;if(y===b)return dn(cn({},e),{[y]:n(e[y],w,T)});const C=e[y][w];return dn(cn({},e),{[y]:[...e[y].slice(0,w),...e[y].slice(w+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,v=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const y=is(e,o.id);if(y!=null){const w=o.shape&&v.y>o.shape.center.y?e[y].length:0;h=y,u=w}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&$i(i)){const y=i.group==null?void 0:is(e,i.group),w=i.group!=null&&y!==l,b=i.index!==d;if(w||b){const T=i.group==null?l:y;if(T!=null){if(l===T)return dn(cn({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return dn(cn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return dn(cn({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return dn(cn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function im(e,t){return sm(e,t,rm)}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 fl(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 hl="__default__",om=class extends qe{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof Ta){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(!Yt(o)||!Yt(a)||o.sortable===a.sortable)return;const c=t(),f=ul(c),d=o.sortable.group===a.sortable.group,l=c.get(o.sortable.group),u=d?l:c.get(a.sortable.group);!l||!u||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,p;const v=t();if(fl(f,c,v))return;const x=o.sortable.element,_=a.sortable.element;if(!_||!x||!d&&a.id===o.sortable.group)return;const g=os(l),y=d?g:os(u),w=(h=o.sortable.group)!=null?h:hl,b=(p=a.sortable.group)!=null?p:hl,T={[w]:g,[b]:y},C=im(T,r);if(T===C)return;const M=C[b].indexOf(o.sortable),E=C[b].indexOf(a.sortable);s.collisionObserver.disable(),pl(x,M,_,E),Ce(()=>{for(const[O,A]of C[w].entries())A.index=O;if(!d)for(const[O,A]of C[b].entries())A.group=a.sortable.group,A.index=O}),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;Yt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),c=ul(a),f=a.get(o.sortable.initialGroup);f&&s.renderer.rendering.then(()=>{const d=t();if(fl(c,a,d))return;const l=os(f),u=os(f,lm),h=o.sortable.element,p=u.indexOf(o.sortable),v=l[p],x=v?.element;!v||!x||!h||(pl(h,v.index,x,o.index),Ce(()=>{for(const _ of a.values()){const g=Array.from(_).values();for(const y of g)y.index=y.initialIndex,y.group=y.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function pl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function am(e,t){return e.index-t.index}function lm(e,t){return e.initialIndex-t.initialIndex}function os(e,t=am){return Array.from(e).sort(t)}var gl=[Xg,om],_u={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function ml(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 as=new th,ku,Su,Rt,Sa,hr,pr,$a,bn;Su=[re],ku=[re];var li=class{constructor(e,t){Qn(this,Sa,rs(Rt,8,this)),rs(Rt,11,this),Qn(this,hr),Qn(this,pr),Qn(this,$a,rs(Rt,12,this)),rs(Rt,15,this),Qn(this,bn),this.register=()=>(Ce(()=>{var p,v;(p=this.manager)==null||p.registry.register(this.droppable),(v=this.manager)==null||v.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ce(()=>{var p,v;(p=this.manager)==null||p.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:c,transition:f=_u,plugins:d}=n,l=Vg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=gt(d,gl),h=ml(s);this.droppable=new Ta(Si(ki({},l),{disabled:h.droppable}),t,this),this.draggable=new $u(Si(ki({},l),{disabled:h.draggable,plugins:u,effects:()=>[()=>{var p,v,x;const _=(p=this.manager)==null?void 0:p.dragOperation.status;_?.initializing&&this.id===((x=(v=this.manager)==null?void 0:v.dragOperation.source)==null?void 0:x.id)&&as.clear(this.manager),_?.dragging&&as.set(this.manager,this.id,ne(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:v,manager:x}=this,_=fr(this,pr),g=fr(this,hr);(p!==_||v!==g)&&(Kt(this,pr,p),Kt(this,hr,v),this.animate())},()=>{var p,v;const{target:x}=this,{isDragSource:_}=this.draggable;((v=(p=this.draggable.pluginConfig(ga))==null?void 0:p.feedback)!=null?v:"default")==="move"&&_&&(this.droppable.disabled=!x)},...r()],type:c,sensors:a}),t,this),Kt(this,bn,l.element),this.manager=t,this.index=o,Kt(this,pr,o),this.group=i,Kt(this,hr,i),this.type=c,this.transition=f}get initialIndex(){var e,t;return(t=(e=as.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=as.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ne(()=>{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 d of s.getAnimations())"transitionProperty"in d&&(d.transitionProperty==="transform"||d.transitionProperty==="translate"||d.transitionProperty==="scale")&&d.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}=_t(s),c=Ja(s,a,!1),f=Ja(s,a);if(o.x||o.y){const d=aa(st(s))?Si(ki({},t),{duration:0}):t;yd({element:s,keyframes:{translate:[`${c.x+o.x}px ${c.y+o.y}px ${c.z}`,`${f.x}px ${f.y}px ${f.z}`]},options:d}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Ce(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ce(()=>{const t=fr(this,bn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Kt(this,bn,e)})}get element(){var e,t;const n=fr(this,bn);if(n)return(t=(e=no.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=gt(e,gl)}set disabled(e){const t=ml(e);Ce(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ce(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??bd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Ce(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};Rt=Kg();Sa=new WeakMap;hr=new WeakMap;pr=new WeakMap;$a=new WeakMap;bn=new WeakMap;xu(Rt,4,"index",Su,li,Sa);xu(Rt,4,"group",ku,li,$a);Yg(Rt,li);var $u=class extends ii{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}},Ta=class extends oi{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},cm=Object.defineProperty,dm=Object.defineProperties,um=Object.getOwnPropertyDescriptors,vl=Object.getOwnPropertySymbols,fm=Object.prototype.hasOwnProperty,hm=Object.prototype.propertyIsEnumerable,yl=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ti=(e,t)=>{for(var n in t||(t={}))fm.call(t,n)&&yl(e,n,t[n]);if(vl)for(var n of vl(t))hm.call(t,n)&&yl(e,n,t[n]);return e},pm=(e,t)=>dm(e,um(t));function gm(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:c,group:f,disabled:d,modifiers:l,sensors:u,target:h,type:p,plugins:v}=e,x=Ti(Ti({},_u),e.transition),_=tu(y=>new li(pm(Ti({},e),{transition:x,register:!1,handle:Tn(a),element:Tn(o),target:Tn(h)}),y)),g=Qd(_,mm);return Te(s,()=>_.id=s),Un(()=>{Ce(()=>{_.group=f,_.index=c})},[_,f,c]),Te(p,()=>_.type=p),Te(t,()=>_.accept=t,void 0,ft),Te(i,()=>i&&(_.data=i)),Te(c,()=>{var y;(y=_.manager)!=null&&y.dragOperation.status.idle&&x?.idle&&_.refreshShape()},fg),bs(a,y=>_.handle=y),bs(o,y=>_.element=y),bs(h,y=>_.target=y),Te(d,()=>_.disabled=d??!1,void 0,ft),Te(u,()=>_.sensors=u,void 0,ft),Te(n,()=>_.collisionDetector=n),Te(r,()=>_.collisionPriority=r),Te(v,()=>_.plugins=v,void 0,ft),Te(x,()=>_.transition=x,void 0,ft),Te(l,()=>_.modifiers=l,void 0,ft),Te(e.alignment,()=>_.alignment=e.alignment),{sortable:g,get isDragging(){return g.isDragging},get isDropping(){return g.isDropping},get isDragSource(){return g.isDragSource},get isDropTarget(){return g.isDropTarget},handleRef:k.useCallback(y=>{_.handle=y??void 0},[_]),ref:k.useCallback(y=>{var w,b;!y&&((w=_.element)!=null&&w.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.element=y??void 0)},[_]),sourceRef:k.useCallback(y=>{var w,b;!y&&((w=_.source)!=null&&w.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.source=y??void 0)},[_]),targetRef:k.useCallback(y=>{var w,b;!y&&((w=_.target)!=null&&w.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.target=y??void 0)},[_])}}function mm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const So="tile",Tu="gap",vm=[vo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Eu}], ${ym}`)!==null||(vo.defaults.preventActivation?.(e,t)??!1)}),Gd],Eu="data-no-drag",ym=".malloy-render, .malloy-table",bm=e=>[...e,ga.configure({feedback:"clone"})];function xm({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=gm({id:e,index:t,type:So,accept:So,collisionDetector:ca,plugins:bm});return m.jsx(m.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function wm({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Lg({id:e,type:Tu,accept:So,collisionDetector:ca,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}const Cu=e=>e.ok===!1,Ae=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Hn=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 _m(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 km(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
+
`&&t.push(n+1);return t}function Ou(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!Hn(s))continue;const i=Ie(s,"docAnnotations");if(i)for(const o of Bt(i,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class Du{constructor(t){this.text=t,this.map=_m(t),this.lineStarts=km(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!Hn(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 Ur(e,t,n=[]){Hn(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Ur(e.getChild(r),t,n);return n}const Sm=e=>Ae(e,"OCURLY","CCURLY");function jr(e,t){const n=[],r=s=>{if(Hn(s)){if(t(s)){n.push(s);return}if(!Sm(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 Ie=(e,t)=>e[t]?.call(e),Bt=(e,t)=>e[t]?.call(e)??[];function $m(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 Mu(e,t){const n=e.positioned(t);if(!n)return;const r=Ie(t,"filterClauseList"),s=[];for(const i of r?Bt(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=Ur(i,ke.givenRef).map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.replace(/^\$/,""));s.push({...o,givens:a,binding:$m(e,i)})}return{...n,clauses:s}}function $o(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const f of jr(t,ke.queryStatement)){const d=e.positioned(f);d&&r.push(d);const l=Ie(f,"whereStatement");if(l&&ke.whereStatement(l)){const u=Mu(e,l);u&&s.push(u)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
|
|
69
|
+
`),c=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:c,oneLine:a}}function Ea(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 Tm(e,t){const n=Ie(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const s=Ie(n,"queryProperties"),i=s&&$o(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=Bt(n,"segExpr"),i=s[0],o=s[s.length-1];let a=i;for(;ke.segRefine(a);){const u=Bt(a,"segExpr");if(u.some(h=>ke.segOps(h)||ke.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=u[0]}if(a&&ke.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!ke.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const c=e.span(i);if(!c||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!ke.segOps(o)){const u=e.span(n);return u?{kind:"reference",from:e.text.slice(u.start,u.end),fromSpan:u}:{kind:"unsupported",why:"an unreadable refinement"}}const f=e.text.slice(c.start,c.end),d=Ie(o,"queryProperties"),l=d&&$o(e,d);return l?{kind:"reference",from:f,fromSpan:c,refinement:l}:{kind:"reference",from:f,fromSpan:c}}return{kind:"unsupported",why:"a parenthesized expression"}}function Em(e,t){const n=[];for(const r of jr(t,ke.defExploreQuery)){const s=e.span(r),i=Ie(r,"subQueryDefList");if(!s||!i)continue;const o=Bt(i,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Ie(r,"VIEW"));for(const c of o){const f=e.span(c),d=Ie(c,"exploreQueryNameDef"),l=e.text_(d),u=Ie(c,"vExpr");!f||!l||!u||n.push({name:l,span:f,line:e.line(f.start),statement:s,tags:Ea(e,s,a?.start??f.start),siblings:o.length,body:Tm(e,u)})}}return n}function Cm(e,t){const n=[];for(const r of jr(t,ke.defDimension)){const s=e.span(r),i=Ie(r,"defList");if(!s||!i)continue;const o=e.terminal(Ie(r,"DIMENSION"));for(const a of Bt(i,"fieldDef")){const c=e.span(a),f=e.text_(Ie(a,"fieldNameDef"))?.trim(),d=e.text_(Ie(a,"fieldExpr"))?.trim();!c||!f||d===void 0||n.push({name:f,expression:d,span:c,line:e.line(c.start),statement:s,tags:Ea(e,s,o?.start??c.start)})}}return n}function Om(e,t){const n=[];for(const r of Ur(t,ke.sourceDefinition)){const s=e.span(r),i=e.text_(Ie(r,"sourceNameDef")),o=Ie(r,"sqExplore");if(!s||!i||!o)continue;const a=e.span(o),c=a?e.text.slice(a.start,a.end):"",f=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(c)?.[1]??"").trim(),d=jr(o,ke.exploreProperties)[0],l=d&&$o(e,d),u={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(d)for(const p of jr(d,ke.whereStatement)){const v=Mu(e,p);v&&h.push(v)}n.push({name:i,base:f,span:s,line:e.line(s.start),statement:u,...l?{properties:l}:{},views:d?Em(e,d):[],dimensions:d?Cm(e,d):[],wheres:h})}return n}function Dm(e,t){const n=[];for(const r of Ur(t,ke.givenStatement)){const s=e.terminal(Ie(r,"GIVEN")),i=Ie(r,"givenDefList"),o=s?e.line(s.start):void 0;for(const a of i?Bt(i,"givenDef"):[]){const c=e.span(a),f=e.span(Ie(a,"givenNameDef")),d=f&&e.text.slice(f.start,f.end);if(!c||!f||!d)continue;const l={start:f.start,end:c.end},u=e.line(l.start);n.push({name:d,declaration:e.text.slice(l.start,l.end),span:l,line:u,statement:{start:e.lineStarts[u],end:l.end},tags:Ea(e,c,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function Mm(e,t){const n=[];for(const r of Ur(t,ke.importStatement)){const s=e.span(r),i=e.text_(Ie(r,"importURL"));if(!s||i===void 0)continue;const o=Ie(r,"importSelect"),a=o?Bt(o,"importItem").map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.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 Iu(e){let t;try{t=await Ca(e,"file://dashboard-builder.malloy")}catch(u){return{ok:!1,reason:`Malloy could not read this file: ${u}`}}const n=t.problems.filter(u=>u.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,s=r?.root;if(!s||!Hn(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 Du(e),c=Im(a,i);a.commentLines=c.lines;const f=e.split(`
|
|
70
|
+
`),d=u=>c.lines.has(u);a.proseLines=pe.markdownLines(f,d),a.blocks=pe.blockSpans(f,d).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=Om(a,s);return l.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:Mm(a,s),sources:l,givens:Dm(a,s),textBlocks:Pm(a,i),modelNotes:Ou(a,s),trailingComment:u=>c.trailing.get(u),comments:c.all,commentLine:u=>c.lines.has(u),proseLine:u=>a.proseLines.has(u),commentIn:u=>c.all.find(h=>h.start>=u.start&&h.start<u.end),blockStart:u=>jm(a,c.lines,u)}}}async function Ca(e,t){const{MalloyTranslator:n}=await S.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Im(e,t){const n=new Map,r=new Set,s=[],i=t.tokenSource?.vocabulary;for(const d of t.getTokens?.()??[]){const l=i?.getSymbolicName(d.type);if(l!=="COMMENT_TO_EOL"&&l!=="BLOCK_COMMENT")continue;const u=e.utf16(d.startIndex);let h=e.utf16(d.stopIndex+1);if(!(u===void 0||h===void 0||h<u)){for(;h>u&&(e.text[h-1]===`
|
|
71
|
+
`||e.text[h-1]==="\r");)h--;s.push({start:u,end:h})}}const o=[...s].sort((d,l)=>d.start-l.start);let a="",c=0;for(const d of o)a+=e.text.slice(c,Math.max(c,d.start)),a+=e.text.slice(Math.max(c,d.start),Math.max(c,d.end)).replace(/[^\n\r]/g," "),c=Math.max(c,d.end);a+=e.text.slice(c);const f=d=>a.slice(e.lineStarts[d],e.lineStarts[d+1]??a.length);for(const d of s){const l=e.line(d.start),u=e.line(d.end-1);for(let v=l;v<=u;v++)f(v).trim()===""&&r.add(v);const h=a.slice(e.lineStarts[l],d.start).trim(),p=a.slice(d.end,e.lineStarts[u+1]??a.length).trim();h!==""&&p===""&&n.set(u,d)}return{trailing:n,lines:r,all:s}}function jm(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(([,c])=>c===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 Pm(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 c=pe.textBlockOpener(i(n[a]).replace(/\r?\n$/,""));if(!c)continue;const f=[];let d=a+1;for(;s(n[d]??n[a])==="BLOCK_ANNOTATION_TEXT";d++)f.push(i(n[d]));const l=n[d];if(!l||s(l)!=="BLOCK_ANNOTATION_END")continue;const u=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(l.stopIndex+1)??e.text.length,p=c.name===void 0&&c.rest?[`${c.rest}
|
|
72
72
|
`]:[];o.push({...c.name===void 0?{}:{name:c.name},route:c.route,body:[...p,...f].join("").replace(/\r\n?/g,`
|
|
73
73
|
`).replace(/\n$/,""),span:{start:e.lineStarts[u],end:h},line:u}),a=d}return o}function ju(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 Pu(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=ju(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 Rm(e,r+i[0].length-1)}}}function Rm(e,t){const n=[];let r=0,s=t+1;const i=o=>{const a=e.slice(s,o),c=a.length-a.trimStart().length,f=a.trim();f!==""&&n.push({text:f,span:{start:s+c,end:s+c+f.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=ju(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 Am(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 Lm(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Am(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 Ru(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=Lm(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const bl=(e,t)=>{try{return e.text(t)}catch{return}},Bm=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Fm=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\`.`,zm=e=>`\`layout=${e}\` is not a layout Publisher knows (grid, linear), and the tag lists no tiles, so this file is not a report. Fix: write \`layout=grid\` or \`layout=linear\`, and list the tiles in \`tiles=[…]\`.`,Wm="A linear report written as `run:` cells is no longer read, so this file is not a report. Fix: list its tiles in `tiles=[…]` (a text tile per prose block, a query tile per view), or remove the `## artifact` tag.";function Au(e,t){const n=e.filter(Bm).filter(d=>!d.includes("@env.")).map(
|
|
77
|
-
`&&t.push(n+1);return t}function Xm(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 Bu=e=>e==="none"||S.isChartPick(e)?e:void 0;function Fu(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=${
|
|
76
|
+
`)return s}return e.length}return t}function Lm(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Am(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 Ru(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=Lm(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const bl=(e,t)=>{try{return e.text(t)}catch{return}},Bm=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Fm=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\`.`,zm=e=>`\`layout=${e}\` is not a layout Publisher knows (grid, linear), and the tag lists no tiles, so this file is not a report. Fix: write \`layout=grid\` or \`layout=linear\`, and list the tiles in \`tiles=[…]\`.`,Wm="A linear report written as `run:` cells is no longer read, so this file is not a report. Fix: list its tiles in `tiles=[…]` (a text tile per prose block, a query tile per view), or remove the `## artifact` tag.";function Au(e,t){const n=e.filter(Bm).filter(d=>!d.includes("@env.")).map(pe.tagAnnotation),{tag:r,errors:s}=n.length>0?Ru(t,n):{tag:void 0,errors:[]},i=r?.tag("artifact");if(!i)return e.some(pe.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const o=bl(i,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=bl(i,"layout"),c=i.has("tiles");if(c&&i.array("tiles")===void 0)return{status:"unparsed",errors:s};const f=a==="grid"||a==="linear"?a:c||r?.tag("dashboard")!==void 0?"grid":"linear";return f==="linear"&&!c?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:f}}async function Nm(e){const{parseAnnotation:t}=await S.loadMalloyTag();let n=[];try{const r=(await Ca(e,"file://report.malloy")).parse?.root;r&&Hn(r)&&typeof r.getChild=="function"&&(n=Ou(new Du(e),r))}catch{n=[]}return Au(n,t)}const Hs=e=>e.ok===!1;function Hr(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 Vs=e=>e.map(t=>t.text);function xl(e){const t=Vs(e),n=S.chartStateOfTagLines(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:S.chartLinesOf(t)}:{chart:n}}function Gm(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:pe.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Um(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(),...Hm(n(Vs(Hr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Hm(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 Ei(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 Vm=/^"((?:[^"\\]|\\.)+)"$/,Km=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Ks(e,t,n=!1){try{return await qm(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 qm(e){const{parseAnnotation:t}=await S.loadMalloyTag(),n=pe.splitSourceLines(e),r=await Iu(e);if(Cu(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,i=pe.descriptionNotes(n).text,o=Au(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:Fm(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?zm(o.unknownLayout):Wm};const a=o.layout,c=pe.artifactTag(n);if(c===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!pe.artifactLeads(c.text))return{ok:!1,reason:pe.ARTIFACT_NOT_FIRST,line:c.from+1};const{tag:f,errors:d}=Ru(t,[pe.tagAnnotation(c.text)]),l=f?.tag("artifact"),u=Pu(c.text);if(u===void 0)return d.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${d[0]}`}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=s.imports.map(T=>T.names?{kind:"names",names:T.names,from:T.from}:{kind:"all",from:T.from}),p=[],v=[],x=new Map;for(const T of s.sources){const C={name:T.name,base:T.base};T.dimensions.length>0&&(C.dimensions=T.dimensions.map(E=>({name:E.name,expression:E.expression})));const M=new Set(T.wheres.flatMap(E=>E.clauses.flatMap(O=>O.givens)));M.size>0&&(C.scopedBy=Array.from(M)),p.push(C);for(const E of T.dimensions){const O=t(Vs(Hr(s,n,E.line).tags)).tag?.tag("drill");if(!O)continue;const A=O.textArray("to")??[O.text("to")??""];v.push({source:T.name,name:E.name,expression:E.expression,to:A.filter(Boolean),...O.text("given")?{given:O.text("given")}:{}})}x.set(T.name,new Map(T.views.map(E=>[E.name,E])))}const _=[];for(const{text:T}of u.entries){const C=Vm.exec(T),M=C?void 0:Km.exec(T)?.[1];if(M!==void 0){const I=t([`# ${T}`]).tag?.tag(M);if(I?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${M} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(_.some(H=>je(H)&&H.name===M))return{ok:!1,reason:`Two text tiles are named \`${M}\`, so the builder cannot tell them apart.`};const F=Ei(I,"colspan");_.push({kind:"text",name:M,markdown:s.textBlocks.find(H=>H.name===M)?.body??"",...F===void 0?{}:{colspan:F},...I.has("break")?{break:!0}:{}});continue}const E=C?.[1]??T,O=C?pe.tileSteps(E):void 0;if(!O)return{ok:!1,reason:`The tile \`${E}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:A,view:j}=O,L=x.get(A)?.get(j);if(L===void 0){_.push({name:j,source:A,declaration:{kind:"inherited"}});continue}const N=t(Vs(L.tags)).tag,W=L.body.kind==="reference"?{kind:"reference",from:L.body.from}:L.body.kind==="inline"?{kind:"inline"}:void 0;if(W===void 0){_.push({name:j,source:A,declaration:{kind:"opaque",why:L.body.kind==="unsupported"?L.body.why:"unreadable"},...N?.text("label")?{label:N.text("label")}:{},...N?.text("subtitle")?{subtitle:N.text("subtitle")}:{},...N?.numeric("colspan")!==void 0?{colspan:N.numeric("colspan")}:{},...xl(L.tags),...N?.has("break")?{break:!0}:{},...N?.has("borderless")?{borderless:!0}:{}});continue}const V=Gm(L.body.kind==="reference"?L.body.refinement:L.body.kind==="inline"?L.body.stage:void 0);_.push({name:j,source:A,declaration:W,...V?{filters:V}:{},...N?.text("label")?{label:N.text("label")}:{},...N?.text("subtitle")?{subtitle:N.text("subtitle")}:{},...N?.numeric("colspan")!==void 0?{colspan:N.numeric("colspan")}:{},...xl(L.tags),...N?.has("break")?{break:!0}:{},...N?.has("borderless")?{borderless:!0}:{}})}const g=Um(s,n,t),y={},w=l?.tag("givens");for(const T of Object.keys(w?.dict??{})){const C=w?.text(T);C!==void 0&&(y[T]=C)}const b=f?.tag("dashboard")?.has("columns")?Ei(f.tag("dashboard"),"columns"):l?.array("tiles")?Ei(l,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:l?.text("title")??"",...i?{description:i}:{},...b===void 0?{}:{columns:b},...l?.has("autorun")?{autorun:l.isTrue("autorun")}:{},imports:h,sources:p,...g?{localGivens:g}:{},...Object.keys(y).length>0?{startingGivens:y}:{},...v.length>0?{drills:v}:{},tiles:_}}}const qs=e=>e.ok===!1;async function wl(e){const{problems:t}=await Ca(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function xe(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function Lu(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Ym(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
+
`&&t.push(n+1);return t}function Xm(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 Bu=e=>e==="none"||S.isChartPick(e)?e:void 0;function Fu(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=${pt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${pt(e.subtitle)}`);const r=t?Bu(e.chart):void 0;return r!==void 0&&n.push(S.chartLineText(r,e.chartCarried)),n}function ws(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Qm=new Set(["colspan","break","borderless","label","subtitle"]),Zm=new Set(["label","description","control","suggest","range_min","range_max"]);function _l(e){const t=[];if(e.label!==void 0&&t.push(`label=${pt(e.label)}`),e.description!==void 0&&t.push(`description=${pt(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=${pt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${pt(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 kl=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Jm(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function Sl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:pt(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(pt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ys=e=>`${e.source}.${e.name}`,pt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,To=e=>je(e)?xe(["text",e.name]):xe([e.name,e.source,e.declaration]),lt=To,$l=e=>xe(e.tiles.map(lt));function ev(e,t,n){const r=new Set(e.tiles.map(lt)),s=new Set(t.tiles.map(lt)),i=e.tiles.filter(h=>!s.has(lt(h))),o=t.tiles.filter(h=>!r.has(lt(h))),c=i.length>0||o.length>0||$l(e)!==$l(t);for(const h of o)if(ae(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 f=new Map(e.sources.map(h=>[h.name,h])),d=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)d.add(h.base);const l=t.imports.some(h=>h.kind==="all"),u=t.sources.filter(h=>!f.has(h.name));for(const h of e.sources){const p=t.sources.find(v=>v.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 u){if(!o.some(p=>ae(p)&&p.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!d.has(h.base)&&!l&&!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:u,currentSources:f,reordered:c}}const Tl=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function tv(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Pr(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function El(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=tv(t),r=n.indexOf("{"),s=n.lastIndexOf("}");let i=t.slice(r+1,s),o=n.slice(r+1,s);const a=f=>{const d=f.exec(o);d&&(i=i.slice(0,d.index)+i.slice(d.index+d[0].length),o=o.slice(0,d.index)+o.slice(d.index+d[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const c=[i.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${c.join(" ")} }${t.slice(s+1)}`}function nv(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:i,currentKeys:o,nextKeys:a,edits:c}=e,f=new Map(r.tiles.filter(je).map(g=>[g.name,g])),d=s.tiles.filter(je).some(g=>{const y=f.get(g.name);return y!==void 0&&Tl(y,g)});if(!i&&!d)return;const l=pe.artifactTag(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,h=Pu(u);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:g}of h.entries){const y=/^"((?:[^"\\]|\\.)+)"$/.exec(g);if(y){const b=y[1].split("->").map(T=>T.trim());b.length===2&&p.set(`${b[0]}->${b[1]}`,g);continue}const w=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(g)?.[1];w!==void 0&&p.set(`text.${w}`,g)}const v=s.tiles.map(g=>{const y=!o.has(lt(g));if(je(g)){const w=p.get(`text.${g.name}`);return w!==void 0?f.has(g.name)&&!Tl(f.get(g.name),g)?w:El(g,w):y?El(g):void 0}return p.get(`${g.source}->${g.name}`)??(y?`"${g.source} -> ${g.name}"`:void 0)});if(v.some(g=>g===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const x=u.slice(0,h.open).search(/tiles\s*=\s*$/),_=`${u.slice(0,x)}tiles=[${rv(u,h,v)}]${u.slice(h.close+1)}`;_!==u&&c.push({...zu(n,l),text:`${_}
|
|
78
78
|
`})}function zu(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function rv(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
|
`)),c=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
|
|
80
|
-
`)?a:" "}`;return`${i}${n.join(c)}${o}`}function sv(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=
|
|
81
|
-
${/\n([ \t]+)\S/.exec(
|
|
82
|
-
`:`${
|
|
80
|
+
`)?a:" "}`;return`${i}${n.join(c)}${o}`}function sv(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=Pr(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,c=e[a]==='"'?Pr(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),f=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,f)+e.slice(c)}}return e}function iv(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Pr(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=Pr(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 Pr(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 ov(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||xe(r.startingGivens)!==xe(s.startingGivens)){const o=pe.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=zu(n,o),c=i.find(y=>y.start===a.start&&y.end===a.end);let f=c?c.text.replace(/\n$/,""):o.text;const d=r.layout!==s.layout,l=f.indexOf("artifact"),u=f.indexOf("{",l);let h=0,p=-1;for(let y=u;y<f.length;y++)if(f[y]==="{")h++;else if(f[y]==="}"&&--h===0){p=y;break}if(u<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let v=f.slice(u+1,p);const x=o.block?`
|
|
81
|
+
${/\n([ \t]+)\S/.exec(v)?.[1]??" "}`:" ",_=y=>o.block?`${v.trimEnd()}${x}${y}
|
|
82
|
+
`:`${v.trimEnd()} ${y} `,g=(y,w)=>{const b=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${y}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(w===void 0){const T=new RegExp(`
|
|
83
83
|
${b.source}[ \\t]*(?=
|
|
84
|
-
)`);
|
|
84
|
+
)`);v=v.replace(o.block&&T.test(v)?T:b,"")}else b.test(v)?v=v.replace(b,T=>`${o.block?T.slice(0,T.length-T.trimStart().length):" "}${y}=${w}`):v=_(`${y}=${w}`)};if(d&&g("layout",s.layout),r.title!==s.title&&g("title",s.title?pt(s.title):void 0),r.autorun!==s.autorun&&g("autorun",s.autorun===void 0?void 0:String(s.autorun)),xe(r.startingGivens)!==xe(s.startingGivens)){v=v.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const y=Object.entries(s.startingGivens??{});y.length>0&&(v=_(`givens { ${y.map(([w,b])=>`${w}=${pt(b)}`).join(" ")} }`))}o.block?f=`${f.slice(0,u+1)}${v}${f.slice(p)}`:(v=v.replace(/\s{2,}/g," "),f=`${f.slice(0,u+1)}${v.startsWith(" ")?v:` ${v}`}${v.endsWith(" ")?"":" "}${f.slice(p)}`),r.columns!==s.columns&&(f=sv(f,"dashboard_columns"),f=iv(f),s.columns!==void 0&&(f=`${f.trimEnd()} dashboard { columns=${s.columns} }`)),c?c.text=`${f}
|
|
85
85
|
`:i.push({...a,text:`${f}
|
|
86
|
-
`})}if(r.description!==s.description){const{read:o,blankAbove:a,below:c,belowBlock:f,inBlock:d}=
|
|
87
|
-
`).map(
|
|
88
|
-
`),u=o.length>0&&o[0]<
|
|
89
|
-
`});else if(s.description!==void 0){const
|
|
90
|
-
`})}}}function av(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.localGivens??[]).map(h=>[h.name,h])),f=new Map((i.localGivens??[]).map(h=>[h.name,h])),d=new Map(a.givens.map(h=>[h.name,h])),l=new Set;for(const[h,p]of c){const
|
|
91
|
-
`).trim();o.push({start:n(
|
|
86
|
+
`})}if(r.description!==s.description){const{read:o,blankAbove:a,below:c,belowBlock:f,inBlock:d}=pe.descriptionNotes(t);if(d||s.description===void 0&&f)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const l=Lu(s.description??"").split(`
|
|
87
|
+
`).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
|
|
88
|
+
`),u=o.length>0&&o[0]<pe.artifactLine(t),h=s.description===void 0,p=u?[...o.slice(1),...h?c:[]]:[...o,...a];for(const v of p)i.push({...n(v),text:""});if(u)i.push({...n(o[0]),text:s.description===void 0?"":`${l}
|
|
89
|
+
`});else if(s.description!==void 0){const v=n(pe.artifactLine(t)).start;i.push({start:v,end:v,text:`${l}
|
|
90
|
+
`})}}}function av(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.localGivens??[]).map(h=>[h.name,h])),f=new Map((i.localGivens??[]).map(h=>[h.name,h])),d=new Map(a.givens.map(h=>[h.name,h])),l=new Set;for(const[h,p]of c){const v=f.get(h);if(v!==void 0&&xe(v)===xe(p))continue;const x=d.get(h);if(x===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:_,prose:g}=Hr(a,t,x.line),w=[...(v===void 0?_:_.filter(O=>{const A=ws(O.text);return A!==void 0&&Zm.has(A)})).map(O=>O.line),...v===void 0?g:[]];for(const O of w)o.push({...n(O),text:""}),l.add(O);const b=Tt(a,x.span.end-1);if(v===void 0){o.push({start:n(x.line).start,end:n(b).end,text:""});for(let W=x.line;W<=b;W++)l.add(W);const O=Math.min(x.line,...w),A=x.blockHeader??O,j=(t[b+1]??"x").trim()==="",L=A===0||t[A-1].trim()==="",N=x.blockHeader===void 0||![...d.values()].some(W=>W.blockHeader===x.blockHeader&&W.line>x.line&&f.has([...d.entries()].find(([,V])=>V===W)?.[0]??""));j&&L&&N&&!l.has(b+1)&&(o.push({...n(b+1),text:""}),l.add(b+1));continue}const T=r(x.line),C=_l(v),E=v.type!==p.type||v.default!==p.default?x.blockHeader===void 0?kl(v):`${v.name} :: ${v.type} is ${v.default}`:t.slice(x.line,b+1).join(`
|
|
91
|
+
`).trim();o.push({start:n(x.line).start,end:n(b).end,text:(C?`${T}${C}
|
|
92
92
|
`:"")+`${T}${E}
|
|
93
|
-
`})}for(const[h,p]of d){if(p.blockHeader===void 0||f.has(h))continue;![...d.values()].some(
|
|
94
|
-
`:"")+`${kl(
|
|
93
|
+
`})}for(const[h,p]of d){if(p.blockHeader===void 0||f.has(h))continue;![...d.values()].some(x=>x.blockHeader===p.blockHeader&&!l.has(x.line))&&!l.has(p.blockHeader)&&(o.push({...n(p.blockHeader),text:""}),l.add(p.blockHeader))}const u=[...f.values()].filter(h=>!c.has(h.name));if(u.length>0){const h=Math.max(-1,...[...d.values()].map(y=>y.line)),p=(()=>{let y=-1;for(let w=0;w<t.length;w++){const b=t[w].trim();(b.startsWith("import ")||y>=0&&/^}\s*from\s/.test(b))&&(y=w)}return y})(),v=h>=0?h:p,x=u.map(y=>{const w=_l(y);return(w?`${w}
|
|
94
|
+
`:"")+`${kl(y)}
|
|
95
95
|
`}).join(`
|
|
96
|
-
`),_=
|
|
97
|
-
${
|
|
98
|
-
`})}}const Cl=(e,t)=>`import { ${e.join(", ")} } from ${
|
|
99
|
-
`).join("")})}}function cv(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.drills??[]).map(d=>[
|
|
96
|
+
`),_=v>=0?n(v).end:n(0).end;o.push({start:_,end:_,text:`
|
|
97
|
+
${x}`}),t.some(y=>y.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
|
|
98
|
+
`})}}const Cl=(e,t)=>`import { ${e.join(", ")} } from ${pt(t)}`;function lv(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=l=>xe(l.imports.flatMap(u=>u.kind==="all"?[u.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(xe(n.imports)===xe(r.imports))return;const a=r.imports.flatMap(l=>l.kind==="names"?[{...l,claimed:!1}]:[]),c=new Set([...r.sources.map(l=>l.base),...r.tiles.filter(ae).map(l=>l.source)]),f=t.imports.map((l,u)=>({statement:l,entry:n.imports[u]}));for(const{statement:l,entry:u}of f){if(!u||u.kind!=="names")continue;const h=a.find(y=>!y.claimed&&y.from===u.from);h&&(h.claimed=!0);const p=h?.names??[],x=u.names.filter(y=>!p.includes(y)).find(y=>c.has(y));if(x!==void 0)return{ok:!1,reason:`\`${x}\` is still read by a tile, so its import cannot be removed.`};if(xe(p)===xe(u.names))continue;const _=p.length===0?Oa(t,l.statement):l.statement,g=t.commentIn(_);if(g)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(g.start,g.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({..._,text:p.length===0?"":Cl(p,u.from)})}const d=a.filter(l=>!l.claimed);if(d.length>0){const l=t.imports.at(-1);if(!l)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const u=i(Tt(t,l.statement.end-1)).end;s.push({start:u,end:u,text:d.map(h=>`${Cl(h.names,h.from)}
|
|
99
|
+
`).join("")})}}function cv(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.drills??[]).map(d=>[Ys(d),d])),f=new Map((i.drills??[]).map(d=>[Ys(d),d]));for(const d of new Set([...c.keys(),...f.keys()])){const l=c.get(d),u=f.get(d);if(l&&u&&xe(l)===xe(u))continue;const h=u??l;if(u&&u.to.length===0)return{ok:!1,reason:`The drill on \`${d}\` names no destination.`};const p=a.sources.find(g=>g.name===h.source)?.dimensions.find(g=>g.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:v}=Hr(a,t,p.line),x=v.find(g=>/^#\s*drill\b/.test(g.text)),_=r(p.line);if(u===void 0)x&&o.push({...n(x.line),text:""});else if(x)o.push({...n(x.line),text:`${_}${Sl(u)}
|
|
100
100
|
`});else{const g=n(p.line).start;o.push({start:g,end:g,text:`${_}${Sl(u)}
|
|
101
|
-
`})}}}function dv(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:i}=e;for(const o of r){if(
|
|
102
|
-
`)};let l=-1;for(const u of c.sources)l=Math.max(l
|
|
103
|
-
`)+h.map(
|
|
101
|
+
`})}}}function dv(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=Wu(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const c=Tt(i,a.statement.start),f=Tt(i,a.statement.end-1),d=i.trailingComment(f),l=d&&d.start>=a.statement.end?d.end:a.statement.end;if(i.text.slice(i.lineStarts[c],a.statement.start).trim()!==""||i.text.slice(l,n(f).end).trim()!==""){s.push({...Oa(i,a.statement),text:""});continue}s.push({start:i.lineStarts[c],end:n(f).end,text:""});const h=c===0?"":t[c-1].trim();(t[f+1]??"x").trim()===""&&(c===0||h===""||h.endsWith("{"))&&s.push({...n(f+1),text:""})}}function uv(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:i,currentSources:o,edits:a,parsed:c}=e,f=new Map;for(const u of s){if(je(u))continue;const h=f.get(u.source)??[];h.push(u),f.set(u.source,h)}const d=(u,h)=>{const p=u.declaration.kind==="reference"?u.declaration.from:u.name,v=(u.filters??[]).map(x=>`where: ${pe.malloyPath(x.field)} ${x.op??"~"} $${x.given}`).join(", ");return[...Fu(u).map(x=>`${h}${x}`),`${h}view: ${u.name} is ${p}${v?` + { ${v} }`:""}`].join(`
|
|
102
|
+
`)};let l=-1;for(const u of c.sources)l=Math.max(l,Tt(c,u.span.end-1));for(const[u,h]of f)if(o.has(u)){const p=c.sources.find(w=>w.name===u);if(!p)return{ok:!1,reason:`Could not find where the source \`${u}\` is declared.`};if(!p.properties)return{ok:!1,reason:`\`${u}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const v=p.line,x=Tt(c,p.properties.closeStart);let _=" ";for(let w=v+1;w<x;w++){const b=/^(\s+)view:/.exec(n[w]);if(b){_=b[1];break}}const g=r(x).start,y=(n[x-1]??"").trim()==="";a.push({start:g,end:g,text:(y?"":`
|
|
103
|
+
`)+h.map(w=>d(w,_)).join(`
|
|
104
104
|
|
|
105
105
|
`)+`
|
|
106
|
-
`})}else{const p=i.find(
|
|
106
|
+
`})}else{const p=i.find(y=>y.name===u);if(!p)return{ok:!1,reason:`The tile's source \`${u}\` is not declared.`};const v=`
|
|
107
107
|
source: ${p.name} is ${p.base} extend {
|
|
108
|
-
`+h.map(
|
|
108
|
+
`+h.map(y=>d(y," ")).join(`
|
|
109
109
|
|
|
110
110
|
`)+`
|
|
111
111
|
}
|
|
112
|
-
`;let
|
|
112
|
+
`;let x=l;if(x<0)for(let y=0;y<n.length;y++){const w=n[y].trim();(/^(import\s|given:|}\s*from\s)/.test(w)||/^[A-Z_]+\s*::/.test(w))&&(x=y)}const _=x>=0?r(x).end:t.length,g=_===t.length&&!t.endsWith(`
|
|
113
113
|
`)?`
|
|
114
|
-
`:"";a.push({start:_,end:_,text:g+
|
|
115
|
-
`}),
|
|
116
|
-
`})}const b=
|
|
117
|
-
`).join("")})}if(
|
|
114
|
+
`:"";a.push({start:_,end:_,text:g+v}),l=x}}function fv(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:i,next:o,edits:a,parsed:c}=e,f=new Map(i.tiles.map(d=>[lt(d),d]));for(const d of o.tiles){const l=f.get(lt(d));if(l===void 0||je(d)||je(l)||xe(Xs(l))===xe(Xs(d)))continue;if(d.declaration.kind==="inherited")return{ok:!1,reason:`\`${d.source} -> ${d.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const u=Jm(c,d.source,d.name);if(u<0)return{ok:!1,reason:`Could not find where \`${d.name}\` is declared inside \`${d.source}\`.`};const{tags:h}=Hr(c,t,u),p=s(u),v=Fu(d,!1),x=new Map(v.map(E=>[ws(E)??E,E])),_=new Set,g=Bu(d.chart),y=Ol(l)!==Ol(d);if(y){const E=h.filter(j=>S.mentionsChartTag(j.text)),O=h.filter(j=>S.parseChartLine(j.text)),A=l.chart==="custom"?h.filter(j=>S.parseChartLine(j.text)||S.mentionsChartTag(j.text)):E.length>0?E:O.length>1?O:[];if(A.length>0)return{ok:!1,reason:`\`${d.source} -> ${d.name}\` has a chart line the builder does not model (${A.map(j=>j.text).join(" and ")}), so its chart cannot be changed here.`}}let w=!1;for(const E of h){if(y&&S.parseChartLine(E.text)){g===void 0?a.push({...r(E.line),text:""}):E.text!==S.chartLineText(g,d.chartCarried)&&a.push({...r(E.line),text:`${p}${S.chartLineText(g,d.chartCarried)}
|
|
115
|
+
`}),w=!0;continue}const O=ws(E.text);if(O===void 0||!Qm.has(O))continue;const A=x.get(O);if(A===void 0){a.push({...r(E.line),text:""});continue}_.add(O),A!==E.text&&a.push({...r(E.line),text:`${p}${A}
|
|
116
|
+
`})}const b=v.filter(E=>!_.has(ws(E)??E));if(y&&g!==void 0&&!w&&b.push(S.chartLineText(g,d.chartCarried)),b.length>0){const E=n[u];a.push({start:E,end:E,text:b.map(O=>`${p}${O}
|
|
117
|
+
`).join("")})}if(xe(l.filters)===xe(d.filters))continue;const T=Wu(e,d);if(!T)return{ok:!1,reason:`Could not find \`${d.name}\`'s declaration to filter it.`};if(T.body.kind==="reference"){const E=bv(e,d,T);if(E)return E;continue}if(T.body.kind!=="inline")return{ok:!1,reason:`\`${d.name}\`'s body is ${T.body.why}, so there is no single first stage to write its filter into.`};const C=Nu(d.filters,T.body.stage);if(C)return Gu(d.name,C.given);const M=Uu(e,d,T.body.stage);if(M)return M}}const Ol=e=>e.chart==="default"?void 0:e.chart,Xs=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...i}=r;return i};function hv(e,t){const n=new Map(e.tiles.map(r=>[lt(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(lt(r));return ae(r)&&r.chart===void 0&&s&&ae(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function _s(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 pv(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&&!pe.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=_s(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 Ci=e=>`##|(markdown) ${e.name}
|
|
118
118
|
${e.markdown===""?"":`${e.markdown}
|
|
119
119
|
`}|##
|
|
120
|
-
`;function gv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,c=new Map(s.tiles.filter(
|
|
120
|
+
`;function gv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,c=new Map(s.tiles.filter(je).map(h=>[h.name,h])),f=i.tiles.filter(je),d=h=>o.textBlocks.find(p=>p.name===h),l=new Set(f.map(h=>h.name));for(const h of c.keys()){const p=l.has(h)?void 0:d(h);if(!p)continue;const v=Tt(o,p.span.end-1);a.push({...p.span,text:""});const x=r(v+1),_=p.line===0||n[p.line-1].trim()==="";x.end>x.start&&n[v+1].trim()===""&&_?a.push({...x,text:""}):p.line>0&&_&&t.slice(p.span.end).trim()===""&&a.push({...r(p.line-1),text:""})}const u=[];for(const h of f){const p=c.get(h.name),v=d(h.name);if(p===void 0){if(v)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};u.push(Ci(h))}else p.markdown!==h.markdown&&(v?a.push({...v.span,text:Ci(h)}):u.push(Ci(h)))}if(u.length>0){const h=o.textBlocks.filter(g=>g.name===void 0||l.has(g.name)),p=h[h.length-1],v=o.sources.find(g=>g.name.endsWith("_tiles"));if(p){const g=p.span.end,y=t.slice(g);a.push({start:g,end:g,text:`
|
|
121
121
|
${u.join(`
|
|
122
|
-
`)}${
|
|
122
|
+
`)}${y===""||y.startsWith(`
|
|
123
123
|
`)?"":`
|
|
124
|
-
`}`});return}if(
|
|
124
|
+
`}`});return}if(v){const g=e.starts[o.blockStart(v.line)],y=g===0||t.slice(0,g).endsWith(`
|
|
125
125
|
|
|
126
|
-
`);a.push({start:g,end:g,text:`${
|
|
126
|
+
`);a.push({start:g,end:g,text:`${y?"":`
|
|
127
127
|
`}${u.join(`
|
|
128
128
|
`)}
|
|
129
|
-
`});return}const
|
|
129
|
+
`});return}const x=t.length,_=t===""||t.endsWith(`
|
|
130
130
|
|
|
131
131
|
`)?"":t.endsWith(`
|
|
132
132
|
`)?`
|
|
133
133
|
`:`
|
|
134
134
|
|
|
135
|
-
`;a.push({start:
|
|
136
|
-
`)})}}const
|
|
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
|
|
138
|
-
${n.indent}${
|
|
135
|
+
`;a.push({start:x,end:x,text:_+u.join(`
|
|
136
|
+
`)})}}const ls=(e,t=pe.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function mv(e,t){const n=new Map(e.tiles.map(o=>[lt(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(lt(o));if(je(o)){const l=pv(o,a&&je(a)?a:void 0,r);if(l)return l;continue}const c=a&&ae(a)?a:void 0;if(a&&!c)continue;const f=o.chart;if(f!==void 0&&f!=="default"&&f!=="none"&&!S.isChartPick(f)&&!(f==="custom"&&c?.chart==="custom"))return`"${String(f)}" is not a chart this editor writes.`;const d=new Set(c?.filters?.map(l=>l.field));for(const l of o.filters??[])if(!d.has(l.field)&&/[\r\n]/.test(l.field))return"A filter field is one line.";if(a===void 0){const l=[o.name,o.source];o.declaration.kind==="reference"&&l.push(o.declaration.from);for(const u of l){const h=ls(u);if(h)return h}}for(const l of["label","subtitle"]){const u=o[l];if(u===void 0||u===c?.[l])continue;const h=S.annotationTextProblem(`tile ${l}`,u);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 c=ls(a);if(c)return c}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=S.annotationTextProblem("description line",o);if(a)return a}if(t.title!==e.title){const o=S.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 f=ls(o.name,pe.isStrictName);if(f)return f}const c=o.suggest?.source;if(c!==void 0&&c!==a?.suggest?.source){const f=ls(c);if(f)return`The suggest source is not a name. ${f}`}for(const f of["query","dimension"]){const d=o.suggest?.[f];if(d===void 0||d===a?.suggest?.[f])continue;const l=S.annotationTextProblem(`suggest ${f}`,d);if(l)return l}for(const f of["label","description"]){const d=o[f];if(d===void 0||d===i.get(o.name)?.[f])continue;const l=S.annotationTextProblem(`given ${f}`,d);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const c=S.annotationTextProblem(`starting value for ${o}`,a);if(c)return c}}const Tt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Wu(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Nu(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 Gu(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 ks=e=>`where: ${pe.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Dl(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 vv(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(Tt(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function yv(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 Oa(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 Uu(e,t,n){const{parsed:r,edits:s}=e,i=new Map((t.filters??[]).map(u=>[u.given,u])),o=new Set;let a;for(const u of n.wheres){const h=u.clauses.map((v,x)=>({clause:v,index:x})).filter(({clause:v})=>v.binding!==void 0);if(h.length===0)continue;const p=h.filter(({clause:v})=>i.has(v.binding.given));for(const{clause:v}of h)o.add(v.binding.given);if(p.length===0&&h.length===u.clauses.length){const v=Oa(r,u.span),x=vv(r,u.span,v);if(x)return Dl(t.name,r,x);s.push({...v,text:""});continue}p.length>0&&(a=u.span);for(let v=h.length-1;v>=0;v--){const{clause:x,index:_}=h[v],g=i.get(x.binding.given);if(!g){const w=yv(u.clauses,_),b=r.commentIn(w);if(b)return Dl(t.name,r,b);s.push({...w,text:""});continue}const y=ks(g).replace(/^where:\s*/,"");y!==r.text.slice(x.span.start,x.span.end)&&s.push({...x.span,text:y})}}const c=(t.filters??[]).filter(u=>!o.has(u.given));if(c.length===0)return;let f=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const u=r.trailingComment(Tt(r,f));u&&u.start>=f&&(f=u.end)}const d=a!==void 0&&!/,\s*$/.test(r.text.slice(0,f))?", ":" ",l=n.oneLine?`${d}${c.map(ks).join(", ")}`:c.map(u=>`
|
|
138
|
+
${n.indent}${ks(u)}`).join("");s.push({start:f,end:f,text:l})}function bv(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=Nu(t.filters,i);if(o)return Gu(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const d=` + { ${a.map(ks).join(", ")} }`;r.push({start:s.end,end:s.end,text:d});return}const c=i.wheres.some(d=>d.clauses.some(l=>!l.binding)),f=i.statements.some(d=>!i.wheres.some(l=>l.span.start===d.span.start));if(a.length===0&&!c&&!f){const d={start:s.end,end:i.span.end},l=e.parsed.commentIn(d);if(l)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(l.start,l.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...d,text:""});return}return Uu(e,t,i)}async function Hu(e,t,n={}){if(!(e.includes(`\r
|
|
139
139
|
`)&&!/(?<!\r)\n/.test(e)))return Ml(e,t,n);const s=await Ml(e.replace(/\r\n/g,`
|
|
140
|
-
`),t,n);return
|
|
141
|
-
`)}}async function Ml(e,t,n){const r=await
|
|
142
|
-
`),d=Ym(e),l=g=>({start:d[g],end:g+1<d.length?d[g+1]:e.length}),u=g=>/^\s*/.exec(f[g])?.[0]??"",h=[],p={...o,sourceText:e,parsed:c.parsed,lines:f,starts:d,wholeLine:l,indentOf:u,current:s,next:i,edits:h};for(const g of[nv,ov,lv,av,cv,dv,uv,fv,gv]){const v=g(p);if(v)return v}const y=g=>{const{drills:v,localGivens:x,description:b,...T}=g,C=g.tiles.map(M=>{if(Ie(M))return M;if(M.filters?.length)return Ks(M);const{filters:E,...O}=M;return Ks(O)});return{...T,...b===void 0?{}:{description:Lu(b)},tiles:C,...v?.length?{drills:[...v].sort((M,E)=>qs(M).localeCompare(qs(E)))}:{},...x?.length?{localGivens:x}:{}}};if(h.length===0)return be(y(s))!==be(y(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 w=Xm(e,h);if((await wl(e)).length===0){const g=await wl(w);if(g.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${g[0]}). Your changes are still here.`}}const _=await Us(w);return Gs(_)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${_.reason}`}:be(y(_.document))!==be(y(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:w}}function Hu({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=ke.usePublisherTheme(),i=s.ui,o=k.useId(),[a,c]=k.useState(!1),f=k.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:d,patch:l,close:u,discard:h}=Ul(f,a,x=>n(x.text),()=>c(!1)),p=a&&d!==void 0&&d.text!==e,y=d!==void 0&&d.text!==e?xs(d.text):void 0;hu(p,()=>y!==void 0?!1:(u(),!0));const w=k.useRef(!1);k.useEffect(()=>{a||(w.current=!1)},[a]);const _=k.useCallback(x=>{!x||w.current||(w.current=!0,x.setSelectionRange(x.value.length,x.value.length))},[]);if(!a||d===void 0){const x=e.trim()?xs(e):void 0;return m.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():c(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),c(!0)))},sx:[{minHeight:24},uu(s,"prose")],children:[e.trim()?m.jsx(S.Prose,{variant:r,children:e}):m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),x&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:x})]})}const g=d.text!==e?xs(d.text):void 0,v=()=>{g===void 0&&u()};return m.jsxs($.Box,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx($.InputBase,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:d.text,placeholder:t,error:g!==void 0,inputRef:_,inputProps:{"aria-label":"Markdown","aria-describedby":o,...g!==void 0?{"aria-invalid":!0}:{}},onChange:x=>l(b=>{b.text=x.target.value}),onKeyDown:x=>{x.key==="Escape"?(x.preventDefault(),h(),c(!1)):x.key==="Enter"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),v())},onBlur:()=>u(),sx:{p:0,...i.type.prose,color:"inherit",maxWidth:S.PROSE_MAX_WIDTH,"& textarea":{p:0}}}),g!==void 0&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:g}),m.jsxs($.Typography,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",Xt,"↩ done · Esc cancels"]})]})}const xv="Write markdown: # heading, **bold**, - list";function wv({tile:e,onChange:t}){return m.jsx(S.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Hu,{markdown:e.markdown,placeholder:xv,onCommit:t})})}const _v={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},qu=(e,t)=>t===0?e:qu(t,e%t);function kv(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=qu(e,t),s=_v[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}function Sv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:c,onRemove:f,removeBlocked:d,resizing:l=!1,width:u,onResizeStart:h,onResizeMove:p,onResizeEnd:y,children:w}){const{theme:_}=ke.usePublisherTheme(),g=_.ui;return m.jsx(xm,{id:We(e),index:t,children:({ref:v,handleRef:x})=>m.jsxs($.Box,{ref:v,onClick:a,onPointerDown:b=>{b.button===0&&a()},role:"group",className:S.reportClasses.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":We(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Ku(_,{selected:n,flash:r,bare:i}),...!i&&{[`& .${S.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:_.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${_.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...S.removeBadgeRevealSx,...n&&{[`& .${S.REMOVE_BADGE_CLASS}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[w,m.jsx($.Box,{ref:x,"aria-label":`Move ${Qn(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(S.RemoveBadge,{label:`Remove ${Qn(e)}`,onRemove:f,...d?{disabledReason:d}:{},inset:i?S.BARE_RING_OFFSET_PX:0}),!Ie(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Qn(e)}`,onClick:b=>{b.stopPropagation(),c(b.currentTarget)},sx:{position:"absolute",top:i?0:`${Il}px`,right:i?0:`${Il}px`,borderRadius:g.radius.control,width:28,height:28,zIndex:2,color:"text.secondary",bgcolor:"action.hover",opacity:n||s?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(Cv,{})}),h&&m.jsx($.Box,{className:`builder-affordance ${S.reportClasses.widthHandle}`,[Eu]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Qn(e)}`,...u?{"aria-valuenow":u.span,"aria-valuemin":1,"aria-valuemax":u.columns,"aria-valuetext":`${u.span} of ${u.columns} columns`}:{},onKeyDown:b=>{if(!u)return;const T=b.key==="ArrowRight"?u.span+1:b.key==="ArrowLeft"?u.span-1:b.key==="Home"?1:b.key==="End"?u.columns:void 0;T!==void 0&&(b.preventDefault(),b.stopPropagation(),u.onStep(Math.min(Math.max(T,1),u.columns)))},onPointerDown:h,onPointerMove:p,onPointerUp:y,onPointerCancel:y,onClick:b=>b.stopPropagation(),sx:b=>({position:"absolute",top:0,bottom:0,right:"-8px",width:"16px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:l||n?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${_.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"12px",height:"40px",boxSizing:"border-box",borderRadius:g.radius.control,border:`1px solid ${l?_.accent:S.edgeColor(_.cardBorder)}`,bgcolor:b.palette.background.paper,boxShadow:"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",transition:`border-color ${S.MOTION_FAST}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"5px",height:"16px",borderLeft:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,borderRight:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,boxSizing:"border-box",opacity:l?1:.7},"&:hover::before":{borderColor:_.accent},"&:hover::after":{borderColor:_.accent,opacity:1}}),children:l&&u&&m.jsx($.Box,{"aria-hidden":!0,sx:b=>({position:"absolute",top:"50%",right:"50%",transform:"translateY(calc(-100% - 28px))",px:1,py:.5,borderRadius:g.radius.control,bgcolor:b.palette.text.primary,color:b.palette.background.paper,...g.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:kv(u.span,u.columns)})}),o&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Qn(e)}`,onClick:b=>{b.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${S.GRID_GAP_PX/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:_.tileTitle,bgcolor:_.tile,border:_.cardBorder,opacity:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:_.tile}},children:m.jsx(S.AddIcon,{sx:{fontSize:14}})})]})})}const Il=14,Ci=7,Ku=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:s=S.BARE_RING_OFFSET_PX})=>{const i=e.ui,o=t||n?e.accent:"transparent",a=n?`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`:t?`0 0 0 4px color-mix(in srgb, ${e.accent} 14%, transparent)`:void 0,c=`outline-color ${S.MOTION_FAST}, border-color ${S.MOTION_FAST}, opacity ${S.MOTION_FAST}, box-shadow ${S.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:typeof s=="number"?`${-s}px`:`${-s.y}px ${-s.x}px`,borderRadius:1,border:`2px solid ${o}`,...a&&{boxShadow:a},pointerEvents:"none",transition:c,...S.reducedMotionSx}}:{borderRadius:i.radius.tile,"& > .MuiPaper-root":{transition:c,...S.reducedMotionSx,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:c,...S.reducedMotionSx,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:S.hoverEdgeColor(e.cardBorder,e.tileTitle)}}}}};function $v({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=ke.usePublisherTheme();return m.jsxs(S.TileCard,{chrome:r,children:[m.jsx(S.TileHeading,{title:t?.title??_n(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),m.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function Tv({after:e}){const{theme:t}=ke.usePublisherTheme();return m.jsx(wm,{id:gu(e),after:e,children:({ref:n,isDropTarget:r})=>m.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 ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...S.reducedMotionSx}})})}function Ev({columns:e}){const{theme:t}=ke.usePublisherTheme();return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${S.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>m.jsx($.Box,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function Cv(){return m.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[m.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),m.jsx("circle",{cx:"12",cy:"12",r:"2"}),m.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function Ov({editor:e,reorder:t,resizing:n,gridBox:r,defaultSpan:s=1,rules:i,canAdd:o,selected:a,flash:c,menuIndex:f,onSelect:d,onOpenMenu:l,onRemove:u,removeBlocked:h,openAdd:p,editTile:y,renderTile:w}){const{dragging:_,preview:g,onDragStart:v,onDragOver:x,onDragEnd:b}=t,{columns:T}=i,{resize:C,startResize:M,onResize:E,endResize:O}=n,P=N=>N.colspan===void 0?{...N,colspan:s}:N,A=(C!==void 0?e.document.tiles.map((N,I)=>I===C.index?{...N,colspan:C.span}:N):g??e.document.tiles).map(P),L=e.document.tiles.length===0,W=_||C!==void 0?zg(A,T):A.map(pu),U=N=>Dv(N,_n(N),y);return m.jsxs(m.Fragment,{children:[m.jsx(wg,{sensors:vm,onDragStart:v,onDragOver:x,onDragEnd:b,children:m.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[i.widths&&(_||C!==void 0)&&m.jsx(Ev,{columns:T}),m.jsx(S.DashboardGrid,{tiles:W,columns:T,rowGapPx:S.GRID_GAP_PX,keyOf:N=>N.kind==="gap"?gu(N.after):We(N.tile),renderTile:N=>{if(N.kind==="gap")return m.jsx(Tv,{after:N.after});const{tile:I,index:z}=N;return m.jsx(Sv,{tile:I,index:z,selected:z===a,flash:We(I)===c,menuOpen:f===z,bare:Ie(I),...i.insertBetween&&o&&z<e.document.tiles.length-1?{onInsertAfter:()=>p(z+1)}:{},...i.widths&&Mv(I)?{resizing:C?.index===z,width:{span:I.colspan??1,columns:T,onStep:V=>{V!==(I.colspan??1)&&e.update(B=>{const G=B.tiles[z];G&&(G.colspan=V)})}},onResizeStart:V=>M(V,z),onResizeMove:E,onResizeEnd:O}:{},onSelect:()=>d(z),onOpenMenu:V=>l(V,z),onRemove:()=>u(z),...h?{removeBlocked:h}:{},children:Ie(I)?m.jsx(wv,{tile:I,onChange:V=>y(We(I),B=>{Ie(B)&&(B.markdown=V)})}):w?w(I,U(I),"card"):m.jsx($v,{tile:I,heading:U(I)})})}})]})}),i.insertBetween&&o&&!L&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>p(),sx:{alignSelf:"center"},children:"Add tile"})]})}const Dv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=We(e),s=i=>o=>n(r,a=>{oe(a)&&(o===""?delete a[i]:a[i]=o)});return{title:m.jsx(wo,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(wo,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Mv=e=>Ie(e)||e.declaration.kind!=="inherited",Iv={x:12,y:6};function jv({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:i}=ke.usePublisherTheme();return m.jsx(S.ReportHeader,{actions:n,title:m.jsx(wo,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(S.TextTileFrame,{sx:{position:"relative",overflow:"visible",...Ku(i,{selected:r,bare:!0,ringOffset:Iv})},children:m.jsx(Hu,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const Pv=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:i}=S.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:o,structural:a,durationMs:c})=>i({type:"report.saved",tiles:o,structural:a,where:r,durationMs:c}),refused:o=>i({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:c})=>i({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:c}),undoRefused:o=>i({type:"report.save_undo_refused",reason:o})}};function Rv(e,t){const n=k.useRef(t);n.current=t;const r=k.useRef(e);r.current=e;const s=k.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.()}),[]),{status:i,saveTarget:o,canUndo:a,canRedo:c,add:{filterUnavailable:f}}=t,d=t.save!==void 0,l=t.add.tile!==void 0,u=t.add.text!==void 0,h=t.add.filter!==void 0,p=t.exit!==void 0,y=t.done!==void 0,w=t.discard!==void 0,{draftKeptAt:_}=t,g=t.restored?.savedAt,v=t.restored?.stale??!1,x=t.restored?.pending??!1,b=t.restore!==void 0,T=t.dismissRestored!==void 0,C=k.useMemo(()=>({status:i,saveTarget:o,...d?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:c,redo:s.redo,add:{...l?{tile:s.addTile}:{},...u?{text:s.addText}:{},...h?{filter:s.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...p?{exit:s.exit}:{},...y?{done:s.done}:{},..._!==void 0?{draftKeptAt:_}:{},...w?{discard:s.discard}:{},...g!==void 0?{restored:{savedAt:g,stale:v,pending:x}}:{},...b?{restore:s.restore}:{},...T?{dismissRestored:s.dismissRestored}:{}}),[s,i,o,d,a,c,l,u,h,f,p,y,_,w,g,v,x,b,T]),M=e!==void 0;k.useEffect(()=>{r.current?.(C)},[C,M]),k.useEffect(()=>()=>r.current?.(void 0),[])}function Av({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:s,onRemove:i,fixedFilters:o,onOpenModel:a,startingValues:c,onStartingValue:f,children:d}){const l=d!=null,u=k.useMemo(()=>{const h=new Map(e.map(p=>[p.name,p]));return{stateOf:p=>{const y=o?.get(p);if(y!==void 0){const{modelPath:g}=y;return{origin:"model",fixed:y.reason,...g!==void 0&&a?{openModel:()=>a(g)}:{}}}const w=h.get(p);if(!w)return;const _=t(w.name,w.type);return{origin:w.origin,..._.length>0?{problem:`Cannot filter on ${_.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:l?e.filter(p=>p.boundTiles===0&&!o?.has(p.name)).map(p=>({name:p.name,label:p.label??p.name})):[],onEdit:p=>{const y=h.get(p);y&&n(y)},onRemove:i,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...f?{startingValueOf:p=>c?.[p],setStartingValue:f}:{}}},[e,t,l,n,i,r,s,o,a,c,f]);return m.jsx(S.StickyControls,{children:m.jsx(S.FilterEditingContext.Provider,{value:u,children:l?d:m.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(h=>m.jsx(S.FilterSettingsButton,{name:h.name,label:h.label??h.name,unused:h.boundTiles===0},h.name)),m.jsx(S.AddFilterButton,{})]})})})}function Lv(e,t){const n=new Map(e.tiles.map((r,s)=>[We(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(We(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return We(s)}}function Bv({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(w=>r(_=>typeof _=="object"&&_.tile===w?_:{tile:w}),[]),a=k.useCallback(()=>r(w=>w==="description"?w:void 0),[]),c=k.useCallback(()=>r("description"),[]),f=k.useCallback(()=>r(void 0),[]),d=n!==void 0;k.useEffect(()=>{if(!d)return;const w=_=>{const g=_.target;g instanceof Element&&g!==document.documentElement&&g.closest(Fv)===null&&f()};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[d,f]);const[l,u]=k.useState(void 0),h=k.useRef(!1),p=k.useRef(e.document);k.useEffect(()=>{const w=p.current;if(p.current=e.document,!h.current)return;h.current=!1;const _=Lv(w,e.document);if(_===void 0)return;u(_),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===_)?.scrollIntoView?.({block:"nearest",behavior:S.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(l===void 0)return;const w=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(w)},[l]);const y=k.useMemo(()=>({...e,undo:()=>{h.current=!0,e.undo()},redo:()=>{h.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:c,clearSelection:f,flash:l,stepEditor:y}}const Fv=["[data-tile-key]",'[role="group"][aria-label="Description"]','[role="toolbar"][aria-label="Report builder"]','[aria-label="Builder actions"]',".MuiPopover-root",".MuiPopper-root",".MuiDialog-root",".MuiModal-root",'[role="menu"]','[role="dialog"]','[role="listbox"]','[role="tooltip"]'].join(", ");function zv({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,c]=k.useState(!1),f=k.useRef(r);f.current=r;const d=k.useRef(s);d.current=s;const l=k.useRef(0),u=k.useCallback(async()=>{const y=++l.current;c(!1),o("saving");try{await f.current()}catch{l.current===y&&o("idle");return}l.current===y&&c(!0)},[]);k.useEffect(()=>{if(i==="waiting"){if(t)return;e?u():(o("idle"),d.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||d.current()}},[i,a,t,e,u]);const h=k.useCallback(()=>{i==="idle"&&(e?o("asking"):d.current())},[i,e]),p=k.useCallback(()=>{i==="idle"&&(e?n?t?o("waiting"):u():o("asking"):d.current())},[i,e,n,t,u]);return{requestExit:h,saveAndExit:p,finishing:i==="saving"||i==="waiting",dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),d.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):u())}}}}function Wv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,keepsEdits:o=!1,report:a,unit:c,prepare:f,shortcuts:d}){const[l,u]=k.useState(!1),[h,p]=k.useState(!1),y=k.useRef(null),w=k.useRef(a);w.current=a;const _=e.dirty||i,g=(e.edited??e.dirty)||i,v=o?i:g;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(g,v)},[g,v,n]);const x=k.useRef(n);x.current=n,k.useEffect(()=>()=>x.current?.(!1,!1),[]);const b=k.useRef(c);b.current=c,k.useEffect(()=>{p(!1)},[e.document]);const T=k.useCallback(()=>{u(!0),p(!1);const I=S.now(),{structural:z}=e,V=w.current.size;return e.save().then(B=>{B.ok===!0?w.current.saved({size:V,structural:z,durationMs:S.now()-I}):w.current.refused(B.reason)}).finally(()=>u(!1))},[e]),C=k.useRef(!1),M=k.useRef(!1);k.useEffect(()=>{!M.current||l||(M.current=!1,y.current?.focus())},[h,l]);const E=k.useCallback(()=>{if(!t||l||C.current||!e.canUndoSave)return;C.current=!0,u(!0);const I=S.now(),z=e.lastSave?.structural??!1,V=w.current.size;return e.undoSave().then(B=>{B.ok===!0?(M.current=!0,p(!0),w.current.undone({size:V,structural:z,durationMs:S.now()-I})):w.current.undoRefused(B.reason)}).finally(()=>{C.current=!1,u(!1)})},[t,l,e]),O=k.useCallback(()=>{if(!(!t||!e.dirty||l))return T()},[t,e,l,T]),P=k.useRef(O);P.current=O;const A=k.useCallback(()=>{const I=()=>P.current();return f?f(I):I()},[f]),L=zv({dirty:g,saving:l,canSave:!!t,save:A,onExit:()=>r?.()});rf(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:A}:{},paused:L.dialog.open}),[d,e,t,A,L.dialog.open]));const W=!!t&&!l&&e.canUndoSave,U=e.lastSave,N={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:_,saving:l,saveButton:y,...t?{onSave:A}:{},...r?{onExit:L.requestExit}:{}};return{saving:l,save:A,exitGuard:L,...r?{done:L.saveAndExit}:{},undoSave:E,canUndoSave:W,lastSave:U,toolbarProps:N}}const Nv=1;function Yu(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(...Yu(a,`${t}${i}.`,n-1))}}}return r}function Gv(e){const t=new Map;for(const n of Xu(e))t.set(n.name,Yu(n.schema?.fields,"",Nv));return t}function Xu(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 Vv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&ef.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Uv(e){const t=new Map;for(const n of Xu(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(Vv)&&r.add(s.name)}t.set(n.name,r)}return t}function jl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const Pl=(e,t)=>e!==void 0&&t.has(e),Rl=e=>e.path||e.modelPath||"";function Qu(e,t=new Set){const n=[],r=new Set,s=new Map,i=new Map,o=new Map;for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=S.exportedSources(a.modelInfo);i.set(a,f);for(const{name:d}of a.sources??[])d&&o.set(d,[...o.get(d)??[],c]);for(const d of f)s.set(d,[...s.get(d)??[],c])}for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=Gv(a),d=Uv(a);for(const l of a.sources??[]){const u=l.name;if(!u||!i.get(a)?.has(u)||r.has(u))continue;r.add(u);const h=(l.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");n.push({name:u,modelPath:c,exporters:s.get(u)??[c],visibleIn:o.get(u)??[c],...S.docOf(l.annotations)?{description:S.docOf(l.annotations)}:{},views:(l.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...S.docOf(p.annotations)?{description:S.docOf(p.annotations)}:{},...S.chartOf(p.annotations)?{chart:S.chartOf(p.annotations)}:{},...d.get(u)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:h,fields:f.get(u)??[]})}}return{sources:n}}function Hv({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(y=>y.name));return(n??[]).filter(y=>!p.has(y.name))},[t,n]),a=k.useMemo(()=>bf(e.document,o),[e.document,o]),c=k.useMemo(()=>new Map(e.document.sources.map(p=>[p.name,jl(r,p.base)])),[r,e.document.sources]),f=k.useCallback(p=>c.get(p.source)??jl(r,p.source),[c,r]),d=(p,y)=>{const w=[];for(const _ of e.document.tiles){if(!oe(_))continue;const g=f(_);if(!g)continue;const v=new Map(g.map(x=>[x.name,x.type]));for(const x of _.filters??[])x.given===p&&(!v.has(x.field)||!yr(y,v.get(x.field)))&&w.push(`${x.field} on ${_.label??_.name} (${e.document.sources.find(b=>b.name===_.source)?.base??_.source})`)}return w},l=k.useMemo(()=>a.filter(p=>p.origin==="model"&&p.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:f,unknownFieldsOf:d,available:l,applyFilter:(p,y,w)=>{i(void 0),e.update(_=>{w&&Ef(_,w),Tf(_,p,y)})},dropControl:p=>{i(void 0),e.update(y=>Cf(y,p))}}}function qv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s}=e,[i,o]=k.useState({stack:[e.document],index:0}),[a,c]=k.useState(e.source),[f,d]=k.useState(void 0),[l,u]=k.useState(e.document),[h,p]=k.useState(e.replaces),[y,w]=k.useState(!1),_=i.stack[i.index],g=k.useRef(i);g.current=i;const v=k.useRef(!1),[x,b]=k.useState(!1),T=B=>{v.current=B,b(B)},[C,M]=k.useState(void 0),E=k.useCallback(B=>{d(void 0),o(G=>{const Q=structuredClone(G.stack[G.index]);if(B(Q),JSON.stringify(Q)===JSON.stringify(G.stack[G.index]))return G;const X=[...G.stack.slice(0,G.index+1),Q].slice(-100);return{stack:X,index:X.length-1}})},[]),O=k.useCallback(()=>{d(void 0),o(B=>B.index>0?{...B,index:B.index-1}:B)},[]),P=k.useCallback(()=>{d(void 0),o(B=>B.index<B.stack.length-1?{...B,index:B.index+1}:B)},[]),A=k.useCallback(async(B,G)=>{try{return await t(B,G)}catch(Q){return{ok:!1,reason:`Could not build the file: ${Q instanceof Error?Q.message:String(Q)}`}}},[t]),L=k.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};const B={source:a,saved:l,history:g.current,replacing:h,unwritten:y},G=s?.(l,_)??!1,Q=r?.(l,_)??!1;T(!0);try{const Z=await A(a,_);if(Hs(Z))return d(Z.reason),{ok:!1,reason:Z.reason};try{await n?.(Z.source,{purpose:"save",document:_})}catch(H){const Pe=`Could not save: ${H instanceof Error?H.message:String(H)}`;return d(Pe),{ok:!1,reason:Pe}}c(Z.source),u(_),p(void 0),w(!1);const X=G?{stack:[_],index:0}:B.history;return o(H=>H===B.history?X:G?{stack:[H.stack[H.index]],index:0}:H),M(n?{before:B,after:X,lastSave:{before:h??a,after:Z.source,structural:Q,clearsHistory:G}}:void 0),d(void 0),{ok:!0}}finally{T(!1)}},[_,A,n,a,l,h,y,s,r]),W=k.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};if(!n||C===void 0||C.after!==g.current)return{ok:!1,reason:"There is no save to undo."};const{before:B}=C;T(!0);try{await n(B.replacing??B.source,{purpose:"undo",document:B.saved})}catch(G){const Q=`Could not undo the save: ${G instanceof Error?G.message:String(G)}`;return d(Q),{ok:!1,reason:Q}}finally{T(!1)}return c(B.source),u(B.saved),p(B.replacing),w(B.unwritten||B.replacing!==void 0),o(G=>G===C.after?B.history:G),M(void 0),d(void 0),{ok:!0}},[n,C]),U=k.useMemo(()=>y||JSON.stringify(_)!==JSON.stringify(l),[_,l,y]),N=k.useMemo(()=>r?.(l,_)??!1,[_,l,r]),I=k.useMemo(()=>s?.(l,_)??!1,[_,l,s]),z=C!==void 0&&C.after===i,V=k.useCallback(async()=>{const B=await A(a,_);return Hs(B)?{ok:!1,reason:B.reason}:{ok:!0,source:B.source}},[_,A,a]);return{document:_,saved:l,source:a,canUndo:i.index>0,canRedo:i.index<i.stack.length-1,dirty:U,edited:U,...f===void 0?{}:{error:f},update:E,undo:O,redo:P,save:L,preview:V,structural:N,clearsHistory:I,canUndoSave:z&&!x&&n!==void 0,...z?{lastSave:C.lastSave}:{},undoSave:W}}const Kv=(e,t)=>{const n=new Set(e.tiles.map($o)),r=new Set(t.tiles.map($o));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Yv(e){const{visibleSources:t,...n}=e,r=k.useCallback((s,i)=>Uu(s,i,t?{visibleSources:t}:{}),[t]);return qv({...n,splice:r,structural:Kv})}function Xv({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(c=>{s.current=()=>c(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 Qv({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:s,deselectTile:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(!1),[d,l]=k.useState(void 0),u=b=>{l(b),f(!0)},h=()=>f(!1),p=b=>{f(!1),e.update(T=>cf(T,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:d})),s(d??e.document.tiles.length)},y=()=>_(d),w=()=>_(void 0),_=b=>{f(!1),e.update(T=>{const C=new Set(T.tiles.filter(Ie).map(E=>E.name));let M=1;for(;C.has(`text_${M}`);)M++;T.tiles.splice(b??T.tiles.length,0,{kind:"text",name:`text_${M}`,markdown:"",...t.widths?{colspan:t.columns}:{}})}),s(b??e.document.tiles.length)};return{menu:o,setMenu:a,addingTile:c,openAdd:u,closeAdd:h,addTile:p,addText:y,appendText:w,editTile:(b,T)=>e.update(C=>{const M=C.tiles.find(E=>We(E)===b);M&&T(M)}),removeTile:b=>{a(void 0),i(),e.update(T=>{T.tiles.splice(b,1)})},duplicate:b=>{a(void 0);const T=e.document.tiles[b],C=T&&oe(T)&&$s(T)===void 0?b+1:void 0;e.update(M=>{df(M,b)}),C!==void 0&&s(C)}}}var Zv=Object.defineProperty,Jv=Object.defineProperties,ey=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,ty=Object.prototype.hasOwnProperty,ny=Object.prototype.propertyIsEnumerable,Ll=(e,t,n)=>t in e?Zv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dn=(e,t)=>{for(var n in t||(t={}))ty.call(t,n)&&Ll(e,n,t[n]);if(Al)for(var n of Al(t))ny.call(t,n)&&Ll(e,n,t[n]);return e},un=(e,t)=>Jv(e,ey(t));function ry(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function as(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 sy(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 c=(v,x)=>v===x||v!==null&&typeof v=="object"&&"id"in v&&v.id===x;if(Array.isArray(e)){const v=e.findIndex(b=>c(b,i.id)),x=e.findIndex(b=>c(b,o.id));if(v===-1||x===-1){if(Oi(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==v)return n(e,v,b)}return n(e,v,x)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[v,x]of f)if(d===-1&&(d=x.findIndex(b=>c(b,i.id)),d!==-1&&(l=v)),u===-1&&(u=x.findIndex(b=>c(b,o.id)),u!==-1&&(h=v)),d!==-1&&u!==-1)break;if(d===-1&&Oi(i)){const v=i.initialGroup==null?void 0:as(e,i.initialGroup),x=i.initialIndex,b=i.group==null?void 0:as(e,i.group),T=i.index;if(v==null||b==null||v===b&&x===T)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return un(dn({},e),{[v]:n(e[v],x,T)});const C=e[v][x];return un(dn({},e),{[v]:[...e[v].slice(0,x),...e[v].slice(x+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,y=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const v=as(e,o.id);if(v!=null){const x=o.shape&&y.y>o.shape.center.y?e[v].length:0;h=v,u=x}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&Oi(i)){const v=i.group==null?void 0:as(e,i.group),x=i.group!=null&&v!==l,b=i.index!==d;if(x||b){const T=i.group==null?l:v;if(T!=null){if(l===T)return un(dn({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return un(dn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return un(dn({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(y.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return un(dn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function iy(e,t){return sy(e,t,ry)}function oy({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:l=>{const{source:u,target:h}=l.operation;if(!u||!h)return;const p=i.current??e;let y;if(h.type===Tu){const{after:w}=h.data,_=p.findIndex(x=>We(x)===u.id);if(_<0||w===u.id)return;const v=p.filter((x,b)=>b!==_).findIndex(x=>We(x)===w)+1;y=Fg(p,_,v)}else{const w=p.map(We),_=iy(w,l);if(_.every((v,x)=>v===w[x]))return;const g=new Map(p.map(v=>[We(v),v]));y=Bg(_.map(v=>g.get(v)),e.map(v=>v.break??!1))}i.current=y,s(y)},onDragEnd:l=>{a(!1);const u=i.current;if(i.current=void 0,s(void 0),l.canceled||!u)return;t(u);const h=u.findIndex(p=>We(p)===l.operation.source?.id);h>=0&&n(h)}}}const Di=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function ay({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),c=u=>{a.current=u,o(u)};return k.useEffect(()=>()=>Di(!1),[]),{resize:i,startResize:(u,h)=>{const p=n.current?.getBoundingClientRect(),y=u.currentTarget.parentElement?.getBoundingClientRect();if(!p||!y)return;u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Di(!0),r(h);const w=e[h]?.colspan??1;c({index:h,span:w,from:w,left:y.left,track:(p.width-S.GRID_GAP_PX*(t-1))/t})},onResize:u=>{const h=a.current;if(!h)return;const p=u.clientX-h.left,y=Math.round((p+S.GRID_GAP_PX)/(h.track+S.GRID_GAP_PX)),w=Math.min(Math.max(y,1),t);w!==h.span&&c({...h,span:w})},endResize:u=>{u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Di(!1);const h=a.current;if(!h)return;const{index:p,span:y,from:w}=h;c(void 0),!(u.type==="pointercancel"||y===w)&&s(p,y)}}}function Oa({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,renderTile:o,renderViewPreview:a,controls:c,givens:f,catalog:d,toolbar:l,dashboards:u,onEvent:h,savesTo:p="package",saveLabel:y,replaces:w,modelPath:_,visibleSources:g,addFilterDisabledReason:v,fixedFilters:x,onOpenModel:b,takenGivenNames:T,onControlsChange:C,draftKey:M}){const E=Yv({source:e,document:t,...n?{onSave:n}:{},...w!==void 0?{replaces:w}:{},...g?{visibleSources:g}:{}}),O=S.useReportDraft(M,E,e),P=k.useRef(null),{selected:A,descriptionSelected:L,selectTile:W,deselectTile:U,selectDescription:N,clearSelection:I,flash:z,stepEditor:V}=Bv({editor:E,gridBox:P}),B=S.layoutRules(E.document.layout,E.document.columns),{columns:G}=B,Q=_?.split("/").at(-1)?.replace(/\.malloy$/,""),Z=oy({tiles:E.document.tiles,commit:q=>E.update(ae=>{ae.tiles=q}),onLanded:W}),{dragging:X}=Z,H=S.useDefaultTileSpan(P,G),Pe=k.useMemo(()=>E.document.tiles.map(q=>q.colspan===void 0?{...q,colspan:H}:q),[E.document.tiles,H]),ve=ay({tiles:Pe,columns:G,gridBox:P,onStart:W,commit:(q,ae)=>E.update(se=>{const ue=se.tiles[q];ue&&(ue.colspan=ae)})}),pe=Qv({editor:E,rules:B,modelPath:_,textHeld:g!==void 0,selectTile:W,deselectTile:U}),{menu:Se,addingTile:ee,openAdd:Re}=pe,ce=Hv({editor:E,opened:t,givens:f,catalog:d}),{filterDialog:ie,setFilterDialog:$e}=ce,[de,xe]=k.useState(void 0),{draftDirty:we,openDraft:Ge,prepare:me}=Xv({editorDirty:E.dirty}),Ae=k.useMemo(()=>({escape:()=>{!Se&&!ie&&!ee&&de===void 0&&I()},nudge:q=>{if(X||A===void 0||!B.widths)return;const ae=E.document.tiles[A];if(!ae||oe(ae)&&ae.declaration.kind==="inherited")return;const se=S.nudgedSpan(ae.colspan??H,q,G);se!==(ae.colspan??H)&&E.update(ue=>{ue.tiles[A].colspan=se})}}),[H,E,Se,ie,ee,de,I,A,G,B,X]),Fe=Wv({editor:V,extraDirty:we,keepsEdits:M!==void 0&&O.keeping,prepare:me,unit:{name:"tile",count:q=>q.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:Ae,report:Pv({size:E.document.tiles.length,path:_??"",layout:E.document.layout,savesTo:p,onEvent:h})}),D=E.document.tiles.length===0,{toolbarProps:R}=Fe,j=O.restored,F={status:Fe.saving?"saving":R.dirty?"unsaved":"saved",saveTarget:y??Pi[p],...O.keptAt!==void 0?{draftKeptAt:O.keptAt}:{},...(R.dirty||j?.pending)&&M!==void 0?{discard:O.discard}:{},...j?{restored:j}:{},...j&&!j.pending?{dismissRestored:O.dismissRestored}:{}};Rv(C,{...F,...R.onSave?{save:R.onSave}:{},canUndo:R.canUndo,undo:R.onUndo,canRedo:R.canRedo,redo:R.onRedo,add:{...d?{tile:()=>pe.openAdd()}:{},text:pe.appendText,...v!==void 0?{filterUnavailable:v}:D?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>$e({})}},...R.onExit?{exit:R.onExit}:{},...Fe.done?{done:Fe.done}:{},...j?.pending?{restore:O.restoreOffered}:{}});const J=C?void 0:m.jsx(sf,{...Fe.toolbarProps,...l?{actions:l}:{},...d?{onAddTile:()=>Re()}:{},savesTo:p,...y?{saveLabel:y}:{},...M!==void 0&&R.onSave?{saveStatus:F}:{}});return m.jsx(fu.Provider,{value:Ge,children:m.jsx($.Stack,{className:S.reportClasses.builder,"data-saves-to":p,sx:{gap:0,mx:`-${Ci}px`},children:m.jsxs(S.ReportPage,{layout:B.layout,sx:{px:`${Ci}px`,pb:`${Ci}px`},header:m.jsx(jv,{editor:E,documentSlug:Q,actions:J,descriptionSelected:L,selectDescription:N}),controls:D?void 0:m.jsx(Av,{controls:ce.controlList,unknownFieldsOf:ce.unknownFieldsOf,onEdit:q=>$e({control:q}),onAdd:()=>$e({}),...v?{addDisabledReason:v}:{},onRemove:ce.dropControl,...x?{fixedFilters:x}:{},...b?{onOpenModel:b}:{},...E.document.startingGivens?{startingValues:E.document.startingGivens}:{},onStartingValue:(q,ae)=>E.update(se=>{const ue={...se.startingGivens??{}};ae===void 0?delete ue[q]:ue[q]=ae,Object.keys(ue).length>0?se.startingGivens=ue:delete se.startingGivens}),children:c}),children:[D&&m.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),d&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),onClick:()=>Re(),children:"Add tile"})]}),j?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:O.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:O.discard,children:"Discard"})]}),children:`You have unsaved edits from ${Ii(j.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),E.error&&m.jsx($.Alert,{severity:"warning",children:E.error}),m.jsx(Ov,{editor:E,reorder:Z,resizing:ve,gridBox:P,defaultSpan:H,rules:B,canAdd:!!d,selected:A,flash:z,menuIndex:Se?.index,onSelect:W,onOpenMenu:(q,ae)=>{W(ae),pe.setMenu({anchor:q,index:ae})},onRemove:pe.removeTile,...E.document.tiles.length===1&&E.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:Re,editTile:pe.editTile,...o?{renderTile:o}:{}}),m.jsx(Bf,{editor:E,catalog:d,columns:G,dashboards:u,bindings:ce,tiles:pe,drillSource:de,setDrillSource:xe,exitDialog:Fe.exitGuard.dialog,...a?{renderViewPreview:a}:{},...T?{takenGivenNames:T}:{}})]})})})}const ly=S.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),cy=S.createSvgIcon(m.jsx("path",{d:"M9 17H7v-7h2zm4 0h-2V7h2zm4 0h-2v-4h2zm2.5 2.1h-15V5h15zm0-16.1h-15c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"})),dy=S.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function uy({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=ke.usePublisherTheme(),i=S.edgeColor(s.cardBorder),o=S.hoverEdgeColor(s.cardBorder,s.tileTitle),[a,c]=k.useState(null),f=e?.save!==void 0&&e.status!=="saved",d=e?.done??n,l=f&&e?.done===void 0,u=e?.add,h=u!==void 0&&(u.tile!==void 0||u.text!==void 0||u.filter!==void 0||u.filterUnavailable!==void 0),p=y=>()=>{c(null),y?.()};return m.jsxs($.Stack,{direction:"row",role:"toolbar",className:S.reportClasses.builderBar,"aria-label":"Report builder",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[e&&m.jsxs(m.Fragment,{children:[e.save&&m.jsx(Nl,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:_s(s.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:_s(s.ui),children:m.jsx(zl,{fontSize:"small"})})})}),h&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),h&&m.jsxs(m.Fragment,{children:[m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),endIcon:m.jsx(S.ExpandMoreIcon,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:y=>c(y.currentTarget),sx:{...vr(i,o),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs($.Menu,{anchorEl:a,open:a!==null,onClose:()=>c(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:fy(i,s.ui)}},MenuListProps:{sx:{p:.5}},children:[u?.tile&&m.jsx(Mi,{icon:m.jsx(cy,{}),title:"Tile",detail:"A view from the model",onClick:p(u.tile)}),u?.text&&m.jsx(Mi,{icon:m.jsx(dy,{}),title:"Text",detail:"Prose between the tiles",onClick:p(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(Mi,{icon:m.jsx(ly,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:p(u.filter)})]})]})]})]}),(d||l)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),d&&m.jsx($.Tooltip,{enterDelay:800,enterNextDelay:800,title:e?.done&&f?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx($.Button,{variant:l?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:d,sx:{...vr(i,o,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&l&&m.jsx($.Tooltip,{title:`Save (${Xt}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...vr(i,o,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const fy=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Mi({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:i}=ke.usePublisherTheme(),o=i.ui;return m.jsxs($.MenuItem,{onClick:s,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:o.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:o.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:i.accent,bgcolor:`color-mix(in srgb, ${i.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx($.Box,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs($.Box,{className:"add-text",sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx($.Box,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function hy(e,t,n=new Set){const r=new Set;for(const o of e.tiles)for(const a of oe(o)?o.filters??[]:[])r.add(a.given);const s=[],i=new Set;for(const o of e.localGivens??[])r.has(o.name)&&(i.add(o.name),s.push(S.localGivenSpec(o)));for(const o of t)o.name===void 0||i.has(o.name)||!(r.has(o.name)||n.has(o.name))||(i.add(o.name),s.push(o));return s}function py(e,t,n){const r=new Map;for(const i of t.tiles)oe(i)&&r.set(wn(`${i.source} -> ${i.name}`),new Set((i.filters??[]).map(o=>o.given)));const s=new Set;for(const i of e.tiles){if(!oe(i))continue;const o=wn(`${i.source} -> ${i.name}`),a=r.get(o);for(const c of n.get(o)??[])a?.has(c)||s.add(c)}return s}function gy(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function my(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function wn(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function vy(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(w=>[w.name,w.type])),c=new Map((e.localGivens??[]).map(w=>[w.name,w.default])),f=e.sources.find(w=>w.name===i)?.scopedBy??[],d=new Set([...f,...s??[]].filter(w=>n.has(w))),l=new Set([...f,...s??[]]),u=[];for(const w of t.filters??[]){const _=`where: ${he.malloyPath(w.field)} ${w.op??"~"}`;if(n.has(w.given)){d.add(w.given),l.add(w.given),u.push(`${_} $${w.given}`);continue}if(!a.has(w.given))continue;l.add(w.given);const g=S.malloyLiteral(r.get(w.given),a.get(w.given))??gy(c.get(w.given));g!==void 0&&u.push(`${_} ${g}`)}const h=u.join(", "),p=t.chart,y=p==="none"||S.isChartPick(p)?S.chartLineText(p,t.chartCarried):p==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
-
`):p==="default"&&my(t.declaration)?S.chartLineText("none"):void 0;return{...y?{annotation:y}:{},expression:`${i} -> ${o}`+(h?` + { ${h} }`:""),givenNames:Array.from(d),reads:s||l.size>0?Array.from(l):void 0}}function yy({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:i}){const{apiClients:o,server:a}=ke.useServer(),{data:c}=S.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]:[])}),f=k.useMemo(()=>new Set([r,...s.flatMap(p=>p.path?[p.path]:[])]),[s,r]),d=k.useMemo(()=>i?(c??[]).filter(p=>!f.has(p)):[],[c,f,i]),l=Fl.useQueries({queries:d.map(p=>({queryKey:["report-editor-model",e,t,p,n,a],queryFn:async()=>(await o.models.getModel(e,t,p,n)).data,retry:!1}))}),u=c!==void 0&&i&&l.every(p=>p.isSuccess||p.isError),h=l.map(p=>p.dataUpdatedAt).join();return k.useMemo(()=>u?Qu(l.flatMap((p,y)=>p.data?[{...p.data,path:d[y]}]:[]),f):void 0,[u,d,h,f])}const by={};function xy({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:s,opened:i,replaces:o,onSave:a,onDirtyChange:c,onExit:f,onOpenModel:d,onControlsChange:l,draftKey:u,onEvent:h,savesTo:p,saveLabel:y,note:w}){const{apiClients:_}=ke.useServer(),[g,v]=k.useState(i.document.tiles.length>0);k.useEffect(()=>v(i.document.tiles.length>0),[i.generation,i.document]);const{data:x,isSuccess:b,isError:T}=S.useQueryWithApiError({...S.reportQueryOptions(_,{environmentName:t,packageName:n,path:r,versionId:s},S.BUILDER_HANDOFF_STALE_MS),enabled:g&&!e}),C=e?.modelPath??r,M=_y(i.source,e?.compileSource),E=S.useCompiledDocument({environmentName:t,packageName:n,modelPath:C,source:M.text??i.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&M.text!==void 0}),O=E.data?.document,P=e?E.isSuccess?O?.manifest??by:void 0:x,A=e?E.isSuccess:b,L=e?E.isError||M.problem!==void 0:T,W=e?S.documentPreamble(O?.cells):void 0,U=(E.data?.result.problems??[]).filter(j=>j.severity==="error"),N=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),I=e?.givens,z=k.useMemo(()=>new Set((P?.tiles??[]).flatMap(j=>j.restricted&&j.query?[wn(j.query)]:[])),[P]),{reports:V,settled:B}=S.useReportListing(t,n,s),G=k.useMemo(()=>V.map(j=>j.path).filter(j=>!!j&&j!==r&&j.endsWith(".malloy")).map(j=>j.replace(/\.malloy$/,"")),[V,r]),Q=yy({environmentName:t,packageName:n,...s!==void 0?{versionId:s}:{},modelPath:r,reports:V,reportsSettled:B}),Z=k.useMemo(()=>e?(Q?.sources??[]).filter(j=>(j.visibleIn??j.exporters??[j.modelPath]).includes(C)).map(j=>j.name):void 0,[Q,e,C]),X=k.useMemo(()=>Q&&Z?{sources:Q.sources.filter(j=>Z.includes(j.name))}:Q,[Q,Z]),[H,Pe]=k.useState(i.document);k.useEffect(()=>Pe(i.document),[i.document]);const ve=k.useMemo(()=>a&&(async(j,F)=>{await a(j,F.document.layout),p==="package"&&v(F.document.tiles.length>0)}),[a,p]),pe=k.useMemo(()=>(P?.givens??[]).filter(j=>!(e&&j.secure===!0)&&!(j.name!==void 0&&N.has(j.name))),[P,N,e]),Se=k.useMemo(()=>new Set([...pe.map(j=>j.name).filter(j=>j!==void 0),...Object.keys(I??{})]),[pe,I]),ee=k.useMemo(()=>new Map((P?.tiles??[]).flatMap(j=>j.kind!=="text"&&j.query&&j.givenNames?[[wn(j.query),j.givenNames]]:[])),[P]),Re=k.useMemo(()=>py(H,i.document,ee),[H,i.document,ee]),ce=k.useMemo(()=>hy(H,pe,Re),[H,pe,Re]),ie=k.useMemo(()=>{const j=new Set(H.tiles.flatMap(se=>oe(se)?(se.filters??[]).map(ue=>ue.given):[])),F=new Set((H.localGivens??[]).map(se=>se.name)),J=[...new Set(H.imports.map(se=>se.from))],q=J.length===1?ky(r,J[0]):J.length===0&&e?e.modelPath:void 0,ae=se=>{const ue=H.sources.filter(rt=>rt.scopedBy?.includes(se)).map(rt=>rt.name);return ue.length>0?{reason:`Applied to every tile on ${ue.join(", ")} by this report's own source. Edit the file to change it.`}:F.has(se)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:q!==void 0?{reason:`Set in the model ${q}. Edit the model to change it.`,modelPath:q}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...Re].filter(se=>!j.has(se)).map(se=>[se,ae(se)]))},[H,Re,e,r]),{declaredTypes:$e,applied:de,panel:xe}=S.useDocumentControls({specs:ce,loaded:A,startingValues:P?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:P?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?C:P?.path,versionId:s,documentName:r,...W!==void 0?{preamble:W}:{},...I?{hostGivens:I}:{}}),we=k.useMemo(()=>S.missingRequiredGivens(ce,de,I),[ce,de,I]),Ge=k.useMemo(()=>Object.fromEntries(Object.entries(I??{}).filter(([j])=>!$e.has(j))),[I,$e]),me=!g||A||L,Ae=e!==void 0&&(M.problem!==void 0||E.isError||U.length>0),Fe=k.useMemo(()=>new Map(i.document.tiles.map(j=>[We(j),j])),[i.document]),D=k.useMemo(()=>function(F,J,q="card"){if(Ae)return m.jsxs(S.TileCard,{chrome:q,children:[m.jsx(S.TileHeading,{title:J?.title??_n(F),subtitle:J?J.subtitle:F.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!me)return m.jsxs(S.TileCard,{chrome:q,children:[m.jsx(S.TileHeading,{title:J?.title??_n(F),subtitle:J?J.subtitle:F.subtitle}),m.jsx(S.Loading,{text:"Running…"})]});const ae=ee.get(wn(`${F.source} -> ${F.name}`)),ue=W===void 0&&ae!==void 0&&wy(Fe.get(We(F)),F)?{expression:`${F.source} -> ${F.name}`,givenNames:[...ae],reads:[...ae]}:vy(H,F,Se,de,ae);return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:s,modelPath:C,...W!==void 0?{preamble:W}:{},...z.has(wn(`${F.source} -> ${F.name}`))?{restricted:!0}:{},tile:ue.expression,...ue.annotation?{annotation:ue.annotation}:{},label:_n(F),chrome:q,subtitle:F.subtitle,...J?{heading:J}:{},borderless:F.borderless,givens:de,hostGivens:Ge,declaredTypes:$e,givenNames:ue.givenNames,...(()=>{const rt=S.waitingOn(we,ue.reads??ue.givenNames);return rt.length>0?{waitingFor:S.waitingText(rt)}:{}})(),ignoredFilters:S.tileIgnoredFilterLabels(ue.reads,ce),height:S.TILE_MAX_HEIGHT})},[H,Fe,me,Ae,we,Se,ee,t,n,s,C,W,z,de,Ge,$e,ce]),R=k.useMemo(()=>function(F){return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:s,modelPath:F.modelPath,tile:`${F.base} -> ${F.view}`,...F.chart?{annotation:S.chartLineText(F.chart,F.chartCarried)}:{},label:F.label,borderless:!0,givens:de,hostGivens:Ge,declaredTypes:$e,givenNames:F.givens,height:200})},[t,n,s,de,Ge,$e]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&U.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",U.map(j=>j.message).join("; ")]}),we.length>0&&!Ae&&m.jsx($.Alert,{severity:"info",children:S.requiredPrompt(we)}),e&&M.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",M.problem]}),e&&E.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",E.error?.message]}),m.jsx(Oa,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:i.source,document:i.document,fixedFilters:ie,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:D,renderViewPreview:R,givens:ce.filter(j=>j.name!==void 0).map(j=>({name:j.name,...j.label?{label:j.label}:{},...j.type?{type:j.type}:{},...j.suggest?.dimension?{field:j.suggest.dimension}:{}})),onChange:Pe,onDirtyChange:c,...f?{onExit:f}:{},...d?{onOpenModel:d}:{},...l?{onControlsChange:l}:{},...u!==void 0?{draftKey:u}:{},...X?{catalog:X}:{},dashboards:G,...h?{onEvent:h}:{},controls:A?m.jsx(S.GivensPanel,{...xe,layout:"bar"}):void 0,...ve?{onSave:ve}:{},savesTo:p,...y?{saveLabel:y}:{},...o!==void 0?{replaces:o}:{},modelPath:r,...e?{visibleSources:Z}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:w})})]})}function wy(e,t){return e!==void 0&&JSON.stringify(Bl(e))===JSON.stringify(Bl(t))}function Bl(e){const{label:t,subtitle:n,colspan:r,break:s,borderless:i,...o}=e;return o}function _y(e,t){const n=k.useRef(t);n.current=t;const r=t!==void 0,[s,i]=k.useState();return k.useEffect(()=>{if(!r)return;let o=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{o&&i({from:e,text:a})},a=>{o&&i({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{o=!1}},[e,r]),r?s?.from!==e?{}:s.problem!==void 0?{problem:s.problem}:{text:s.text}:{text:e}}function ky(e,t){const n=e.split("/").slice(0,-1);for(const r of t.split("/"))r===".."?n.pop():r!=="."&&r!==""&&n.push(r);return n.join("/")}function Sy({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(void 0),[d,l]=k.useState(e===void 0),[u,h]=k.useState(!1),[p,y]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let w=!1;return y(void 0),(async()=>{try{const _=S.chooseWorkspace(await e.listWorkspaces(!1));if(w)return;if(a(_),_!==void 0&&(!n||_.authoritative)){const g=await e.getDocument(S.locatorFor(t,_.name,r,s,i)).catch(v=>{if(!S.isDocumentNotFound(v))throw v});if(w)return;f(g),h(g!==void 0)}}catch(_){if(w)return;y(S.storageErrorMessage(_))}w||l(!0)})(),()=>{w=!0}},[e,t,n,r,s,i]),{workspace:o,draft:c,setDraft:f,draftChecked:d,offered:u,setOffered:h,readFailure:p}}const $y=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Ty(e){const t=await Us(e);return Gs(t)?{ok:!1,reason:$y(t.reason,t.line)}:{ok:!0,document:t.document}}const Ey="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Cy="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Oy({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,layout:c,notebook:f,noun:d,legacyFormat:l,textHeld:u,startedAt:h,onEventRef:p}){const y=k.useRef({path:a,layout:c});y.current={path:a,layout:c};const w=k.useRef((xe,we)=>{try{p.current?.(S.withReportContext(xe,{...y.current,...we?{layout:we}:{}}))}catch{}}),_=e?.authoritative===!0,g=_&&r!==void 0,[v,x]=k.useState(void 0),b=(_||v===!0)&&t!==void 0,[T,C]=k.useState(void 0),[M,E]=k.useState(l?Ey:void 0),O=k.useRef(void 0),P=k.useRef(void 0),[A,L]=k.useState(void 0),W=k.useRef(i);W.current=i;const U=A!==void 0&&A.onFetch===i?A.text:s,N=k.useRef(U);N.current=U;const I=b?t:U,[z,V]=k.useState(!1),[B,G]=k.useState(void 0),[Q,Z]=k.useState(void 0),X=I!==void 0&&I!==Q,H=T?.source,ve=X&&(z||!_&&t!==void 0&&H===t&&t!==U)&&H!==void 0&&I!==B,pe=ve?H:X?I:H??I,Se=ve?I:void 0,ee=k.useRef(H);ee.current=H;const Re=k.useRef(I);Re.current=I;const ce=k.useRef("package");ce.current=b?_?"record":"draft":"package",k.useEffect(()=>{if(pe===void 0||!n||g||pe===ee.current)return;let xe=!1;const we=N.current,Ge=Re.current;return Ty(pe).then(me=>{if(!xe){if(me.ok===!1){E(me.reason),w.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}E(void 0),O.current=void 0,P.current=we,L(void 0),G(void 0),Z(Ge),C(Ae=>({source:pe,document:me.document,...we!==void 0?{packageText:we}:{},generation:(Ae?.generation??0)+1})),w.current({type:"report.opened",surface:"edit",from:ce.current,tiles:me.document.tiles.length,durationMs:S.now()-h.current},me.document.layout)}}).catch(me=>{if(xe)return;const Ae=`Could not read the ${d}: ${me instanceof Error?me.message:String(me)}`;E(Ae),w.current({type:"report.load_failed",surface:"edit",category:S.failureCategory(me)})}),()=>{xe=!0}},[pe,a,n,g,f,d,u,h]),k.useEffect(()=>{l&&w.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[l]),k.useEffect(()=>{!u||!n||T||r!==void 0||(_?t===void 0&&E("the host's storage has no document at this location."):E("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,T,r,_,t]);const ie=f&&!u&&!T&&n&&!b&&o&&s===void 0;return k.useEffect(()=>{ie&&(E(Cy),w.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[ie]),{authoritative:_,blockedOnRecord:g,resume:v,setResume:x,fromDraft:b,opened:T,setOpened:C,openError:M,savedHashRef:O,packageBaseRef:P,setWrote:L,fetchedAtRef:W,setDirty:V,setSeen:Z,held:Se,choose:xe=>{h.current=S.now(),G(xe?t:U),x(xe)},acceptHeld:()=>{h.current=S.now(),G(Se)}}}function Dy({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:c,queryClient:f,mutable:d,textHeld:l,readFailure:u,authoritative:h,resume:p,setResume:y,setOpened:w,setDraft:_,setOffered:g,setSeen:v,setWrote:x,savedHashRef:b,packageBaseRef:T,fetchedAtRef:C}){const M=k.useCallback(B=>t===void 0?void 0:S.locatorFor(B,t.name,s,i,o),[t,s,i,o]),E=M(n),O=k.useCallback(async(B,G=n)=>{const Q=M(G);if(!e||!Q)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(Q,B),w(Z=>Z&&{...Z,source:B}),_(B),(h||p===!0)&&v(B),h||y(Z=>Z??!1)},[e,M,n,h,p,w,_,v,y]),[P,A]=k.useState(void 0),L=k.useCallback(async B=>{const G=await S.expectedHashFor(b.current,T.current);if(G===void 0)throw new Error("The package file is still loading; try again.");const Q=["dashboard-editor-model",s,i,o,a,r];await S.writePackageFile({apiClients:c,queryClient:f,environmentName:s,packageName:i,modelPath:o,source:B,expectedHash:G,invalidateOnError:[Q],afterWrite:async Z=>{if(w(X=>X&&{...X,source:B}),x({text:B,onFetch:C.current}),v(B),b.current=Z,A(void 0),e&&E)try{await e.deleteDocument(E),_(void 0),g(!1)}catch(X){S.isDocumentNotFound(X)?(_(void 0),g(!1)):A(S.storageErrorMessage(X))}y(!1)},invalidate:[{queryKey:Q,wait:!0},{queryKey:S.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})}]}),S.invalidateReportQueries(f,s,i,o)},[c,s,i,o,a,r,e,E,f,b,T,C,w,x,v,_,g,y]),W=t?.writeable===!0,U=d===!0&&!l,{savesTo:N,pinnedPackageSave:I,writer:z}=S.saveTarget({authoritative:h,mutable:U,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!E&&W&&(!r||h),readFailed:u!==void 0});return{save:z==="storage"?O:z==="package"?L:void 0,savesTo:N,writer:z,pinnedPackageSave:I,takesWrites:U,supersedeFailure:P}}function Da(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:i,onControlsChange:o,keepDraft:a,kind:c,path:f,textSource:d}=e,l=e.layout??(c?S.layoutOfKind(c):"grid"),u=l==="linear",h=d!==void 0,{environmentName:p,packageName:y,versionId:w,namesBoth:_}=S.resolveEditorTarget(e),v=("resourceUri"in e?e.dashboard:e.dashboardName)??S.documentSlug(f)??"",x="report",{apiClients:b,mutable:T,isLoadingStatus:C,server:M}=ke.useServer(),E=Fl.useQueryClient(),O=k.useRef(S.now()),P=k.useRef(t);P.current=t;const A=k.useRef(r);A.current=r;const L=S.useOptionalDocumentStorage()?.documentStorage,W=f??S.legacyNamedPath(c??"dashboard",v),U=/\.malloynb$/i.test(W)||u&&/\.malloynb$/i.test(v),N=S.useQueryWithApiError({queryKey:["dashboard-editor-model",p,y,W,w,u],queryFn:()=>b.models.getModel(p,y,W,w,u?!0:void 0),enabled:_&&!U&&!h}),I=N.data?.data?.sourceText,{workspace:z,draft:V,setDraft:B,draftChecked:G,offered:Q,setOffered:Z,readFailure:X}=Sy({storage:L,layout:l,notebook:u,environmentName:p,packageName:y,modelPath:W}),{authoritative:H,blockedOnRecord:Pe,resume:ve,setResume:pe,fromDraft:Se,opened:ee,setOpened:Re,openError:ce,savedHashRef:ie,packageBaseRef:$e,setWrote:de,fetchedAtRef:xe,setDirty:we,setSeen:Ge,held:me,choose:Ae,acceptHeld:Fe}=Oy({workspace:z,draft:V,draftChecked:G,readFailure:X,packageText:I,fetchedAt:N.dataUpdatedAt,packageSettled:N.isSuccess&&!N.isFetching,modelPath:W,layout:l,notebook:u,noun:x,legacyFormat:U,textHeld:h,startedAt:O,onEventRef:P}),{save:D,savesTo:R,writer:j,pinnedPackageSave:F,takesWrites:J,supersedeFailure:q}=Dy({storage:L,workspace:z,layout:l,notebook:u,environmentName:p,packageName:y,modelPath:W,versionId:w,apiClients:b,queryClient:E,mutable:T,textHeld:h,readFailure:X,authoritative:H,resume:ve,setResume:pe,setOpened:Re,setDraft:B,setOffered:Z,setSeen:Ge,setWrote:de,savedHashRef:ie,packageBaseRef:$e,fetchedAtRef:xe}),ae=z?.name,se=k.useCallback(rn=>{P.current?.(S.withWorkspace(rn,ae))},[ae]),ue=N.isError&&!ee,rt=k.useRef(!1);k.useEffect(()=>{!ue||rt.current||(rt.current=!0,S.reportEmitter({path:W,layout:l},P.current).emit({type:"report.load_failed",surface:"edit",category:S.failureCategory(N.error)}))},[ue,N.error,W,l]);const Un=k.useCallback((rn,li)=>{we(rn),A.current?.(li)},[we]),Bt=a?S.reportDraftKey({server:M,environmentName:p,packageName:y,versionId:w,path:f??v}):void 0,Hn=R==="host"&&z?.description?z.description:void 0,qn=!H&&!h&&T===void 0?C?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":S.saveCaption({authoritative:H,mutable:J,pinnedPackageSave:F,...z?{workspace:z}:{},...X!==void 0?{readFailure:X}:{},...w!==void 0?{versionId:w}:{}}),Kn=R==="package"&&J===!0&&!F&&X===void 0||qn===Hn?"":qn;if(!_&&"resourceUri"in e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",x," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(ce)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened in the builder: ",ce]});if(N.isError&&!ee)return m.jsx(S.ApiErrorDisplay,{error:N.error,context:`Opening the ${x}`});if(!ee&&(!(h||I)||!G))return n??m.jsx(S.Loading,{text:`Opening the ${x}…`});if(Pe)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened: ",X]});const ai=V!==void 0&&V!==I;return m.jsxs($.Stack,{sx:{gap:2},children:[N.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",x," could not be re-read from the server:"," ",N.error?.message,". Your edits are still here."]}),!u&&!H&&Q&&ai&&ve===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Ae(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Ae(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),me!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{Bt!==void 0&&S.clearReportDraft(Bt),Fe()},children:"Load it"}),children:R==="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.":R==="host"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this report changed since you opened it. Your edits are still here; loading the new version replaces them."}),q!==void 0&&m.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:"," ",q]}),!ee&&(n??m.jsx(S.Loading,{text:`Opening the ${x}…`})),ee&&m.jsx(xy,{environmentName:p,packageName:y,modelPath:W,...d?{textSource:d}:{},slug:v,...w!==void 0?{versionId:w}:{},opened:ee,...Se&&j==="package"&&ee.packageText!==void 0?{replaces:ee.packageText}:{},onSave:D,onDirtyChange:Un,...s?{onExit:s}:{},...i?{onOpenModel:i}:{},...o?{onControlsChange:o}:{},...Bt!==void 0?{draftKey:Bt}:{},savesTo:R,...Hn?{saveLabel:Hn}:{},...t?{onEvent:se}:{},note:Kn},ee.generation)]})}const My=Da,Iy=Oa;function jy(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 m.jsx(Da,{...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=S.MAX_SLUG_ATTEMPTS;exports.createDocument=S.createDocument;exports.createRoute=S.createRoute;exports.locatorFor=S.locatorFor;exports.newDashboardSource=S.newDashboardSource;exports.newDocumentProblem=S.newDocumentProblem;exports.newNotebookSource=S.newNotebookSource;exports.reportPathFor=S.reportPathFor;exports.reportPathForTitle=S.reportPathForTitle;exports.slugFor=S.slugFor;exports.slugOrFallback=S.slugOrFallback;exports.useDocumentChoices=S.useDocumentChoices;exports.BuilderBar=uy;exports.DashboardBuilder=Iy;exports.DashboardEditor=My;exports.NotebookEditor=jy;exports.ReportBuilder=Oa;exports.ReportEditor=Da;exports.buildCatalog=Qu;exports.readDashboardDocument=Us;exports.readFailed=Gs;exports.readReportTagOfText=Nm;exports.spliceDashboardDocument=Uu;exports.spliceFailed=Hs;
|
|
140
|
+
`),t,n);return qs(s)?s:{...s,source:s.source.replace(/\n/g,`\r
|
|
141
|
+
`)}}async function Ml(e,t,n){const r=await Ks(e);if(Hs(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=hv(s,t),o=ev(s,i,n.visibleSources);if("reason"in o)return o;const a=mv(s,i);if(a)return{ok:!1,reason:a};const c=await Iu(e);if(Cu(c))return{ok:!1,reason:`Cannot edit a file that will not open: ${c.reason}`};const f=e.split(`
|
|
142
|
+
`),d=Ym(e),l=g=>({start:d[g],end:g+1<d.length?d[g+1]:e.length}),u=g=>/^\s*/.exec(f[g])?.[0]??"",h=[],p={...o,sourceText:e,parsed:c.parsed,lines:f,starts:d,wholeLine:l,indentOf:u,current:s,next:i,edits:h};for(const g of[nv,ov,lv,av,cv,dv,uv,fv,gv]){const y=g(p);if(y)return y}const v=g=>{const{drills:y,localGivens:w,description:b,...T}=g,C=g.tiles.map(M=>{if(je(M))return M;if(M.filters?.length)return Xs(M);const{filters:E,...O}=M;return Xs(O)});return{...T,...b===void 0?{}:{description:Lu(b)},tiles:C,...y?.length?{drills:[...y].sort((M,E)=>Ys(M).localeCompare(Ys(E)))}:{},...w?.length?{localGivens:w}:{}}};if(h.length===0)return xe(v(s))!==xe(v(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 x=Xm(e,h);if((await wl(e)).length===0){const g=await wl(x);if(g.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${g[0]}). Your changes are still here.`}}const _=await Ks(x);return Hs(_)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${_.reason}`}:xe(v(_.document))!==xe(v(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:x}}function Vu({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=Se.usePublisherTheme(),i=s.ui,o=k.useId(),[a,c]=k.useState(!1),f=k.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:d,patch:l,close:u,discard:h}=Hl(f,a,w=>n(w.text),()=>c(!1)),p=a&&d!==void 0&&d.text!==e,v=d!==void 0&&d.text!==e?_s(d.text):void 0;hu(p,()=>v!==void 0?!1:(u(),!0));const x=k.useRef(!1);k.useEffect(()=>{a||(x.current=!1)},[a]);const _=k.useCallback(w=>{!w||x.current||(x.current=!0,w.setSelectionRange(w.value.length,w.value.length))},[]);if(!a||d===void 0){const w=e.trim()?_s(e):void 0;return m.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():c(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),c(!0)))},sx:[{minHeight:24},uu(s,"prose")],children:[e.trim()?m.jsx(S.Prose,{variant:r,children:e}):m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),w&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:w})]})}const g=d.text!==e?_s(d.text):void 0,y=()=>{g===void 0&&u()};return m.jsxs($.Box,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx($.InputBase,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:d.text,placeholder:t,error:g!==void 0,inputRef:_,inputProps:{"aria-label":"Markdown","aria-describedby":o,...g!==void 0?{"aria-invalid":!0}:{}},onChange:w=>l(b=>{b.text=w.target.value}),onKeyDown:w=>{w.key==="Escape"?(w.preventDefault(),h(),c(!1)):w.key==="Enter"&&(w.metaKey||w.ctrlKey)&&(w.preventDefault(),y())},onBlur:()=>u(),sx:{p:0,...i.type.prose,color:"inherit",maxWidth:S.PROSE_MAX_WIDTH,"& textarea":{p:0}}}),g!==void 0&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:g}),m.jsxs($.Typography,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",Xt,"↩ done · Esc cancels"]})]})}const xv="Write markdown: # heading, **bold**, - list";function wv({tile:e,onChange:t}){return m.jsx(S.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Vu,{markdown:e.markdown,placeholder:xv,onCommit:t})})}const _v={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Ku=(e,t)=>t===0?e:Ku(t,e%t);function kv(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Ku(e,t),s=_v[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}function Sv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:c,onRemove:f,removeBlocked:d,resizing:l=!1,width:u,onResizeStart:h,onResizeMove:p,onResizeEnd:v,children:x}){const{theme:_}=Se.usePublisherTheme(),g=_.ui;return m.jsx(xm,{id:Fe(e),index:t,children:({ref:y,handleRef:w})=>m.jsxs($.Box,{ref:y,onClick:a,onPointerDown:b=>{b.button===0&&a()},role:"group",className:S.reportClasses.builderTile,"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",...qu(_,{selected:n,flash:r,bare:i}),...!i&&{[`& .${S.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:_.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${_.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...S.removeBadgeRevealSx,...n&&{[`& .${S.REMOVE_BADGE_CLASS}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[x,m.jsx($.Box,{ref:w,"aria-label":`Move ${Yn(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(S.RemoveBadge,{label:`Remove ${Yn(e)}`,onRemove:f,...d?{disabledReason:d}:{},inset:i?S.BARE_RING_OFFSET_PX:0}),!je(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Yn(e)}`,onClick:b=>{b.stopPropagation(),c(b.currentTarget)},sx:{position:"absolute",top:i?0:`${Il}px`,right:i?0:`${Il}px`,borderRadius:g.radius.control,width:28,height:28,zIndex:2,color:"text.secondary",bgcolor:"action.hover",opacity:n||s?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(Cv,{})}),h&&m.jsx($.Box,{className:`builder-affordance ${S.reportClasses.widthHandle}`,[Eu]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Yn(e)}`,...u?{"aria-valuenow":u.span,"aria-valuemin":1,"aria-valuemax":u.columns,"aria-valuetext":`${u.span} of ${u.columns} columns`}:{},onKeyDown:b=>{if(!u)return;const T=b.key==="ArrowRight"?u.span+1:b.key==="ArrowLeft"?u.span-1:b.key==="Home"?1:b.key==="End"?u.columns:void 0;T!==void 0&&(b.preventDefault(),b.stopPropagation(),u.onStep(Math.min(Math.max(T,1),u.columns)))},onPointerDown:h,onPointerMove:p,onPointerUp:v,onPointerCancel:v,onClick:b=>b.stopPropagation(),sx:b=>({position:"absolute",top:0,bottom:0,right:"-8px",width:"16px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:l||n?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${_.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"12px",height:"40px",boxSizing:"border-box",borderRadius:g.radius.control,border:`1px solid ${l?_.accent:S.edgeColor(_.cardBorder)}`,bgcolor:b.palette.background.paper,boxShadow:"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",transition:`border-color ${S.MOTION_FAST}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"5px",height:"16px",borderLeft:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,borderRight:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,boxSizing:"border-box",opacity:l?1:.7},"&:hover::before":{borderColor:_.accent},"&:hover::after":{borderColor:_.accent,opacity:1}}),children:l&&u&&m.jsx($.Box,{"aria-hidden":!0,sx:b=>({position:"absolute",top:"50%",right:"50%",transform:"translateY(calc(-100% - 28px))",px:1,py:.5,borderRadius:g.radius.control,bgcolor:b.palette.text.primary,color:b.palette.background.paper,...g.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:kv(u.span,u.columns)})}),o&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Yn(e)}`,onClick:b=>{b.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${S.GRID_GAP_PX/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:_.tileTitle,bgcolor:_.tile,border:_.cardBorder,opacity:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:_.tile}},children:m.jsx(S.AddIcon,{sx:{fontSize:14}})})]})})}const Il=14,Oi=7,qu=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:s=S.BARE_RING_OFFSET_PX})=>{const i=e.ui,o=t||n?e.accent:"transparent",a=n?`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`:t?`0 0 0 4px color-mix(in srgb, ${e.accent} 14%, transparent)`:void 0,c=`outline-color ${S.MOTION_FAST}, border-color ${S.MOTION_FAST}, opacity ${S.MOTION_FAST}, box-shadow ${S.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:typeof s=="number"?`${-s}px`:`${-s.y}px ${-s.x}px`,borderRadius:1,border:`2px solid ${o}`,...a&&{boxShadow:a},pointerEvents:"none",transition:c,...S.reducedMotionSx}}:{borderRadius:i.radius.tile,"& > .MuiPaper-root":{transition:c,...S.reducedMotionSx,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:c,...S.reducedMotionSx,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:S.hoverEdgeColor(e.cardBorder,e.tileTitle)}}}}};function $v({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=Se.usePublisherTheme();return m.jsxs(S.TileCard,{chrome:r,children:[m.jsx(S.TileHeading,{title:t?.title??kn(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),m.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function Tv({after:e}){const{theme:t}=Se.usePublisherTheme();return m.jsx(wm,{id:gu(e),after:e,children:({ref:n,isDropTarget:r})=>m.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 ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...S.reducedMotionSx}})})}function Ev({columns:e}){const{theme:t}=Se.usePublisherTheme();return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${S.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>m.jsx($.Box,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function Cv(){return m.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[m.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),m.jsx("circle",{cx:"12",cy:"12",r:"2"}),m.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function Ov({editor:e,reorder:t,resizing:n,gridBox:r,defaultSpan:s=1,rules:i,canAdd:o,selected:a,flash:c,menuIndex:f,onSelect:d,onOpenMenu:l,onRemove:u,removeBlocked:h,openAdd:p,editTile:v,renderTile:x}){const{dragging:_,preview:g,onDragStart:y,onDragOver:w,onDragEnd:b}=t,{columns:T}=i,{resize:C,startResize:M,onResize:E,endResize:O}=n,A=V=>V.colspan===void 0?{...V,colspan:s}:V,j=(C!==void 0?e.document.tiles.map((V,I)=>I===C.index?{...V,colspan:C.span}:V):g??e.document.tiles).map(A),L=e.document.tiles.length===0,N=_||C!==void 0?zg(j,T):j.map(pu),W=V=>Dv(V,kn(V),v);return m.jsxs(m.Fragment,{children:[m.jsx(wg,{sensors:vm,onDragStart:y,onDragOver:w,onDragEnd:b,children:m.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[i.widths&&(_||C!==void 0)&&m.jsx(Ev,{columns:T}),m.jsx(S.DashboardGrid,{tiles:N,columns:T,rowGapPx:S.GRID_GAP_PX,keyOf:V=>V.kind==="gap"?gu(V.after):Fe(V.tile),renderTile:V=>{if(V.kind==="gap")return m.jsx(Tv,{after:V.after});const{tile:I,index:F}=V;return m.jsx(Sv,{tile:I,index:F,selected:F===a,flash:Fe(I)===c,menuOpen:f===F,bare:je(I),...i.insertBetween&&o&&F<e.document.tiles.length-1?{onInsertAfter:()=>p(F+1)}:{},...i.widths&&Mv(I)?{resizing:C?.index===F,width:{span:I.colspan??1,columns:T,onStep:H=>{H!==(I.colspan??1)&&e.update(B=>{const G=B.tiles[F];G&&(G.colspan=H)})}},onResizeStart:H=>M(H,F),onResizeMove:E,onResizeEnd:O}:{},onSelect:()=>d(F),onOpenMenu:H=>l(H,F),onRemove:()=>u(F),...h?{removeBlocked:h}:{},children:je(I)?m.jsx(wv,{tile:I,onChange:H=>v(Fe(I),B=>{je(B)&&(B.markdown=H)})}):x?x(I,W(I),"card"):m.jsx($v,{tile:I,heading:W(I)})})}})]})}),i.insertBetween&&o&&!L&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>p(),sx:{alignSelf:"center"},children:"Add tile"})]})}const Dv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Fe(e),s=i=>o=>n(r,a=>{ae(a)&&(o===""?delete a[i]:a[i]=o)});return{title:m.jsx(_o,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(_o,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Mv=e=>je(e)||e.declaration.kind!=="inherited",Iv={x:12,y:6};function jv({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:i}=Se.usePublisherTheme();return m.jsx(S.ReportHeader,{actions:n,title:m.jsx(_o,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(S.TextTileFrame,{sx:{position:"relative",overflow:"visible",...qu(i,{selected:r,bare:!0,ringOffset:Iv})},children:m.jsx(Vu,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const Pv=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:i}=S.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:o,structural:a,durationMs:c})=>i({type:"report.saved",tiles:o,structural:a,where:r,durationMs:c}),refused:o=>i({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:c})=>i({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:c}),undoRefused:o=>i({type:"report.save_undo_refused",reason:o})}};function Rv(e,t){const n=k.useRef(t);n.current=t;const r=k.useRef(e);r.current=e;const s=k.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.()}),[]),{status:i,saveTarget:o,canUndo:a,canRedo:c,add:{filterUnavailable:f}}=t,d=t.save!==void 0,l=t.add.tile!==void 0,u=t.add.text!==void 0,h=t.add.filter!==void 0,p=t.exit!==void 0,v=t.done!==void 0,x=t.discard!==void 0,{draftKeptAt:_}=t,g=t.restored?.savedAt,y=t.restored?.stale??!1,w=t.restored?.pending??!1,b=t.restore!==void 0,T=t.dismissRestored!==void 0,C=k.useMemo(()=>({status:i,saveTarget:o,...d?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:c,redo:s.redo,add:{...l?{tile:s.addTile}:{},...u?{text:s.addText}:{},...h?{filter:s.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...p?{exit:s.exit}:{},...v?{done:s.done}:{},..._!==void 0?{draftKeptAt:_}:{},...x?{discard:s.discard}:{},...g!==void 0?{restored:{savedAt:g,stale:y,pending:w}}:{},...b?{restore:s.restore}:{},...T?{dismissRestored:s.dismissRestored}:{}}),[s,i,o,d,a,c,l,u,h,f,p,v,_,x,g,y,w,b,T]),M=e!==void 0;k.useEffect(()=>{r.current?.(C)},[C,M]),k.useEffect(()=>()=>r.current?.(void 0),[])}function Av({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:s,onRemove:i,fixedFilters:o,onOpenModel:a,startingValues:c,onStartingValue:f,children:d}){const l=d!=null,u=k.useMemo(()=>{const h=new Map(e.map(p=>[p.name,p]));return{stateOf:p=>{const v=o?.get(p);if(v!==void 0){const{modelPath:g}=v;return{origin:"model",fixed:v.reason,...g!==void 0&&a?{openModel:()=>a(g)}:{}}}const x=h.get(p);if(!x)return;const _=t(x.name,x.type);return{origin:x.origin,..._.length>0?{problem:`Cannot filter on ${_.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:l?e.filter(p=>p.boundTiles===0&&!o?.has(p.name)).map(p=>({name:p.name,label:p.label??p.name})):[],onEdit:p=>{const v=h.get(p);v&&n(v)},onRemove:i,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...f?{startingValueOf:p=>c?.[p],setStartingValue:f}:{}}},[e,t,l,n,i,r,s,o,a,c,f]);return m.jsx(S.StickyControls,{children:m.jsx(S.FilterEditingContext.Provider,{value:u,children:l?d:m.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(h=>m.jsx(S.FilterSettingsButton,{name:h.name,label:h.label??h.name,unused:h.boundTiles===0},h.name)),m.jsx(S.AddFilterButton,{})]})})})}function Lv(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 Bv({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(x=>r(_=>typeof _=="object"&&_.tile===x?_:{tile:x}),[]),a=k.useCallback(()=>r(x=>x==="description"?x:void 0),[]),c=k.useCallback(()=>r("description"),[]),f=k.useCallback(()=>r(void 0),[]),d=n!==void 0;k.useEffect(()=>{if(!d)return;const x=_=>{const g=_.target;g instanceof Element&&g!==document.documentElement&&g.closest(Fv)===null&&f()};return document.addEventListener("pointerdown",x,!0),()=>document.removeEventListener("pointerdown",x,!0)},[d,f]);const[l,u]=k.useState(void 0),h=k.useRef(!1),p=k.useRef(e.document);k.useEffect(()=>{const x=p.current;if(p.current=e.document,!h.current)return;h.current=!1;const _=Lv(x,e.document);if(_===void 0)return;u(_),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(y=>y.dataset.tileKey===_)?.scrollIntoView?.({block:"nearest",behavior:S.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(l===void 0)return;const x=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(x)},[l]);const v=k.useMemo(()=>({...e,undo:()=>{h.current=!0,e.undo()},redo:()=>{h.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:c,clearSelection:f,flash:l,stepEditor:v}}const Fv=["[data-tile-key]",'[role="group"][aria-label="Description"]','[role="toolbar"][aria-label="Report builder"]','[aria-label="Builder actions"]',".MuiPopover-root",".MuiPopper-root",".MuiDialog-root",".MuiModal-root",'[role="menu"]','[role="dialog"]','[role="listbox"]','[role="tooltip"]'].join(", ");function zv({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,c]=k.useState(!1),f=k.useRef(r);f.current=r;const d=k.useRef(s);d.current=s;const l=k.useRef(0),u=k.useCallback(async()=>{const v=++l.current;c(!1),o("saving");try{await f.current()}catch{l.current===v&&o("idle");return}l.current===v&&c(!0)},[]);k.useEffect(()=>{if(i==="waiting"){if(t)return;e?u():(o("idle"),d.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||d.current()}},[i,a,t,e,u]);const h=k.useCallback(()=>{i==="idle"&&(e?o("asking"):d.current())},[i,e]),p=k.useCallback(()=>{i==="idle"&&(e?n?t?o("waiting"):u():o("asking"):d.current())},[i,e,n,t,u]);return{requestExit:h,saveAndExit:p,finishing:i==="saving"||i==="waiting",dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),d.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):u())}}}}function Wv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,keepsEdits:o=!1,report:a,unit:c,prepare:f,shortcuts:d}){const[l,u]=k.useState(!1),[h,p]=k.useState(!1),v=k.useRef(null),x=k.useRef(a);x.current=a;const _=e.dirty||i,g=(e.edited??e.dirty)||i,y=o?i:g;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(g,y)},[g,y,n]);const w=k.useRef(n);w.current=n,k.useEffect(()=>()=>w.current?.(!1,!1),[]);const b=k.useRef(c);b.current=c,k.useEffect(()=>{p(!1)},[e.document]);const T=k.useCallback(()=>{u(!0),p(!1);const I=S.now(),{structural:F}=e,H=x.current.size;return e.save().then(B=>{B.ok===!0?x.current.saved({size:H,structural:F,durationMs:S.now()-I}):x.current.refused(B.reason)}).finally(()=>u(!1))},[e]),C=k.useRef(!1),M=k.useRef(!1);k.useEffect(()=>{!M.current||l||(M.current=!1,v.current?.focus())},[h,l]);const E=k.useCallback(()=>{if(!t||l||C.current||!e.canUndoSave)return;C.current=!0,u(!0);const I=S.now(),F=e.lastSave?.structural??!1,H=x.current.size;return e.undoSave().then(B=>{B.ok===!0?(M.current=!0,p(!0),x.current.undone({size:H,structural:F,durationMs:S.now()-I})):x.current.undoRefused(B.reason)}).finally(()=>{C.current=!1,u(!1)})},[t,l,e]),O=k.useCallback(()=>{if(!(!t||!e.dirty||l))return T()},[t,e,l,T]),A=k.useRef(O);A.current=O;const j=k.useCallback(()=>{const I=()=>A.current();return f?f(I):I()},[f]),L=zv({dirty:g,saving:l,canSave:!!t,save:j,onExit:()=>r?.()});rf(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:j}:{},paused:L.dialog.open}),[d,e,t,j,L.dialog.open]));const N=!!t&&!l&&e.canUndoSave,W=e.lastSave,V={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:_,saving:l,saveButton:v,...t?{onSave:j}:{},...r?{onExit:L.requestExit}:{}};return{saving:l,save:j,exitGuard:L,...r?{done:L.saveAndExit}:{},undoSave:E,canUndoSave:N,lastSave:W,toolbarProps:V}}const Nv=1;function Yu(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(...Yu(a,`${t}${i}.`,n-1))}}}return r}function Gv(e){const t=new Map;for(const n of Xu(e))t.set(n.name,Yu(n.schema?.fields,"",Nv));return t}function Xu(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 Uv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&ef.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Hv(e){const t=new Map;for(const n of Xu(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(Uv)&&r.add(s.name)}t.set(n.name,r)}return t}function jl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const Pl=(e,t)=>e!==void 0&&t.has(e),Rl=e=>e.path||e.modelPath||"";function Qu(e,t=new Set){const n=[],r=new Set,s=new Map,i=new Map,o=new Map;for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=S.exportedSources(a.modelInfo);i.set(a,f);for(const{name:d}of a.sources??[])d&&o.set(d,[...o.get(d)??[],c]);for(const d of f)s.set(d,[...s.get(d)??[],c])}for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=Gv(a),d=Hv(a);for(const l of a.sources??[]){const u=l.name;if(!u||!i.get(a)?.has(u)||r.has(u))continue;r.add(u);const h=(l.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");n.push({name:u,modelPath:c,exporters:s.get(u)??[c],visibleIn:o.get(u)??[c],...S.docOf(l.annotations)?{description:S.docOf(l.annotations)}:{},views:(l.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...S.docOf(p.annotations)?{description:S.docOf(p.annotations)}:{},...S.chartOf(p.annotations)?{chart:S.chartOf(p.annotations)}:{},...d.get(u)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:h,fields:f.get(u)??[]})}}return{sources:n}}function Vv({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(v=>v.name));return(n??[]).filter(v=>!p.has(v.name))},[t,n]),a=k.useMemo(()=>bf(e.document,o),[e.document,o]),c=k.useMemo(()=>new Map(e.document.sources.map(p=>[p.name,jl(r,p.base)])),[r,e.document.sources]),f=k.useCallback(p=>c.get(p.source)??jl(r,p.source),[c,r]),d=(p,v)=>{const x=[];for(const _ of e.document.tiles){if(!ae(_))continue;const g=f(_);if(!g)continue;const y=new Map(g.map(w=>[w.name,w.type]));for(const w of _.filters??[])w.given===p&&(!y.has(w.field)||!mr(v,y.get(w.field)))&&x.push(`${w.field} on ${_.label??_.name} (${e.document.sources.find(b=>b.name===_.source)?.base??_.source})`)}return x},l=k.useMemo(()=>a.filter(p=>p.origin==="model"&&p.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:f,unknownFieldsOf:d,available:l,applyFilter:(p,v,x)=>{i(void 0),e.update(_=>{x&&Ef(_,x),Tf(_,p,v)})},dropControl:p=>{i(void 0),e.update(v=>Cf(v,p))}}}function Kv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s}=e,[i,o]=k.useState({stack:[e.document],index:0}),[a,c]=k.useState(e.source),[f,d]=k.useState(void 0),[l,u]=k.useState(e.document),[h,p]=k.useState(e.replaces),[v,x]=k.useState(!1),_=i.stack[i.index],g=k.useRef(i);g.current=i;const y=k.useRef(!1),[w,b]=k.useState(!1),T=B=>{y.current=B,b(B)},[C,M]=k.useState(void 0),E=k.useCallback(B=>{d(void 0),o(G=>{const ee=structuredClone(G.stack[G.index]);if(B(ee),JSON.stringify(ee)===JSON.stringify(G.stack[G.index]))return G;const J=[...G.stack.slice(0,G.index+1),ee].slice(-100);return{stack:J,index:J.length-1}})},[]),O=k.useCallback(()=>{d(void 0),o(B=>B.index>0?{...B,index:B.index-1}:B)},[]),A=k.useCallback(()=>{d(void 0),o(B=>B.index<B.stack.length-1?{...B,index:B.index+1}:B)},[]),j=k.useCallback(async(B,G)=>{try{return await t(B,G)}catch(ee){return{ok:!1,reason:`Could not build the file: ${ee instanceof Error?ee.message:String(ee)}`}}},[t]),L=k.useCallback(async()=>{if(y.current)return{ok:!1,reason:"A save is still being written."};const B={source:a,saved:l,history:g.current,replacing:h,unwritten:v},G=s?.(l,_)??!1,ee=r?.(l,_)??!1;T(!0);try{const Q=await j(a,_);if(qs(Q))return d(Q.reason),{ok:!1,reason:Q.reason};try{await n?.(Q.source,{purpose:"save",document:_})}catch(X){const te=`Could not save: ${X instanceof Error?X.message:String(X)}`;return d(te),{ok:!1,reason:te}}c(Q.source),u(_),p(void 0),x(!1);const J=G?{stack:[_],index:0}:B.history;return o(X=>X===B.history?J:G?{stack:[X.stack[X.index]],index:0}:X),M(n?{before:B,after:J,lastSave:{before:h??a,after:Q.source,structural:ee,clearsHistory:G}}:void 0),d(void 0),{ok:!0}}finally{T(!1)}},[_,j,n,a,l,h,v,s,r]),N=k.useCallback(async()=>{if(y.current)return{ok:!1,reason:"A save is still being written."};if(!n||C===void 0||C.after!==g.current)return{ok:!1,reason:"There is no save to undo."};const{before:B}=C;T(!0);try{await n(B.replacing??B.source,{purpose:"undo",document:B.saved})}catch(G){const ee=`Could not undo the save: ${G instanceof Error?G.message:String(G)}`;return d(ee),{ok:!1,reason:ee}}finally{T(!1)}return c(B.source),u(B.saved),p(B.replacing),x(B.unwritten||B.replacing!==void 0),o(G=>G===C.after?B.history:G),M(void 0),d(void 0),{ok:!0}},[n,C]),W=k.useMemo(()=>v||JSON.stringify(_)!==JSON.stringify(l),[_,l,v]),V=k.useMemo(()=>r?.(l,_)??!1,[_,l,r]),I=k.useMemo(()=>s?.(l,_)??!1,[_,l,s]),F=C!==void 0&&C.after===i,H=k.useCallback(async()=>{const B=await j(a,_);return qs(B)?{ok:!1,reason:B.reason}:{ok:!0,source:B.source}},[_,j,a]);return{document:_,saved:l,source:a,canUndo:i.index>0,canRedo:i.index<i.stack.length-1,dirty:W,edited:W,...f===void 0?{}:{error:f},update:E,undo:O,redo:A,save:L,preview:H,structural:V,clearsHistory:I,canUndoSave:F&&!w&&n!==void 0,...F?{lastSave:C.lastSave}:{},undoSave:N}}const qv=(e,t)=>{const n=new Set(e.tiles.map(To)),r=new Set(t.tiles.map(To));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Yv(e){const{visibleSources:t,...n}=e,r=k.useCallback((s,i)=>Hu(s,i,t?{visibleSources:t}:{}),[t]);return Kv({...n,splice:r,structural:qv})}function Xv({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(c=>{s.current=()=>c(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 Qv({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:s,deselectTile:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(!1),[d,l]=k.useState(void 0),u=b=>{l(b),f(!0)},h=()=>f(!1),p=b=>{f(!1),e.update(T=>cf(T,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:d})),s(d??e.document.tiles.length)},v=()=>_(d),x=()=>_(void 0),_=b=>{f(!1),e.update(T=>{const C=new Set(T.tiles.filter(je).map(E=>E.name));let M=1;for(;C.has(`text_${M}`);)M++;T.tiles.splice(b??T.tiles.length,0,{kind:"text",name:`text_${M}`,markdown:"",...t.widths?{colspan:t.columns}:{}})}),s(b??e.document.tiles.length)};return{menu:o,setMenu:a,addingTile:c,openAdd:u,closeAdd:h,addTile:p,addText:v,appendText:x,editTile:(b,T)=>e.update(C=>{const M=C.tiles.find(E=>Fe(E)===b);M&&T(M)}),removeTile:b=>{a(void 0),i(),e.update(T=>{T.tiles.splice(b,1)})},duplicate:b=>{a(void 0);const T=e.document.tiles[b],C=T&&ae(T)&&Es(T)===void 0?b+1:void 0;e.update(M=>{df(M,b)}),C!==void 0&&s(C)}}}var Zv=Object.defineProperty,Jv=Object.defineProperties,ey=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,ty=Object.prototype.hasOwnProperty,ny=Object.prototype.propertyIsEnumerable,Ll=(e,t,n)=>t in e?Zv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,un=(e,t)=>{for(var n in t||(t={}))ty.call(t,n)&&Ll(e,n,t[n]);if(Al)for(var n of Al(t))ny.call(t,n)&&Ll(e,n,t[n]);return e},fn=(e,t)=>Jv(e,ey(t));function ry(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function cs(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Di(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function sy(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 c=(y,w)=>y===w||y!==null&&typeof y=="object"&&"id"in y&&y.id===w;if(Array.isArray(e)){const y=e.findIndex(b=>c(b,i.id)),w=e.findIndex(b=>c(b,o.id));if(y===-1||w===-1){if(Di(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==y)return n(e,y,b)}return n(e,y,w)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[y,w]of f)if(d===-1&&(d=w.findIndex(b=>c(b,i.id)),d!==-1&&(l=y)),u===-1&&(u=w.findIndex(b=>c(b,o.id)),u!==-1&&(h=y)),d!==-1&&u!==-1)break;if(d===-1&&Di(i)){const y=i.initialGroup==null?void 0:cs(e,i.initialGroup),w=i.initialIndex,b=i.group==null?void 0:cs(e,i.group),T=i.index;if(y==null||b==null||y===b&&w===T)return"preventDefault"in t&&t.preventDefault(),e;if(y===b)return fn(un({},e),{[y]:n(e[y],w,T)});const C=e[y][w];return fn(un({},e),{[y]:[...e[y].slice(0,w),...e[y].slice(w+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,v=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const y=cs(e,o.id);if(y!=null){const w=o.shape&&v.y>o.shape.center.y?e[y].length:0;h=y,u=w}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&Di(i)){const y=i.group==null?void 0:cs(e,i.group),w=i.group!=null&&y!==l,b=i.index!==d;if(w||b){const T=i.group==null?l:y;if(T!=null){if(l===T)return fn(un({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return fn(un({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return fn(un({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return fn(un({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function iy(e,t){return sy(e,t,ry)}function oy({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:l=>{const{source:u,target:h}=l.operation;if(!u||!h)return;const p=i.current??e;let v;if(h.type===Tu){const{after:x}=h.data,_=p.findIndex(w=>Fe(w)===u.id);if(_<0||x===u.id)return;const y=p.filter((w,b)=>b!==_).findIndex(w=>Fe(w)===x)+1;v=Fg(p,_,y)}else{const x=p.map(Fe),_=iy(x,l);if(_.every((y,w)=>y===x[w]))return;const g=new Map(p.map(y=>[Fe(y),y]));v=Bg(_.map(y=>g.get(y)),e.map(y=>y.break??!1))}i.current=v,s(v)},onDragEnd:l=>{a(!1);const u=i.current;if(i.current=void 0,s(void 0),l.canceled||!u)return;t(u);const h=u.findIndex(p=>Fe(p)===l.operation.source?.id);h>=0&&n(h)}}}const Mi=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function ay({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),c=u=>{a.current=u,o(u)};return k.useEffect(()=>()=>Mi(!1),[]),{resize:i,startResize:(u,h)=>{const p=n.current?.getBoundingClientRect(),v=u.currentTarget.parentElement?.getBoundingClientRect();if(!p||!v)return;u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Mi(!0),r(h);const x=e[h]?.colspan??1;c({index:h,span:x,from:x,left:v.left,track:(p.width-S.GRID_GAP_PX*(t-1))/t})},onResize:u=>{const h=a.current;if(!h)return;const p=u.clientX-h.left,v=Math.round((p+S.GRID_GAP_PX)/(h.track+S.GRID_GAP_PX)),x=Math.min(Math.max(v,1),t);x!==h.span&&c({...h,span:x})},endResize:u=>{u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Mi(!1);const h=a.current;if(!h)return;const{index:p,span:v,from:x}=h;c(void 0),!(u.type==="pointercancel"||v===x)&&s(p,v)}}}function Da({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,renderTile:o,renderViewPreview:a,controls:c,givens:f,catalog:d,toolbar:l,dashboards:u,onEvent:h,savesTo:p="package",saveLabel:v,replaces:x,modelPath:_,visibleSources:g,addFilterDisabledReason:y,fixedFilters:w,onOpenModel:b,takenGivenNames:T,onControlsChange:C,draftKey:M}){const E=Yv({source:e,document:t,...n?{onSave:n}:{},...x!==void 0?{replaces:x}:{},...g?{visibleSources:g}:{}}),O=S.useReportDraft(M,E,e),A=k.useRef(null),{selected:j,descriptionSelected:L,selectTile:N,deselectTile:W,selectDescription:V,clearSelection:I,flash:F,stepEditor:H}=Bv({editor:E,gridBox:A}),B=S.layoutRules(E.document.layout,E.document.columns),{columns:G}=B,ee=_?.split("/").at(-1)?.replace(/\.malloy$/,""),Q=oy({tiles:E.document.tiles,commit:K=>E.update(ie=>{ie.tiles=K}),onLanded:N}),{dragging:J}=Q,X=S.useDefaultTileSpan(A,G),te=k.useMemo(()=>E.document.tiles.map(K=>K.colspan===void 0?{...K,colspan:X}:K),[E.document.tiles,X]),we=ay({tiles:te,columns:G,gridBox:A,onStart:N,commit:(K,ie)=>E.update(_e=>{const oe=_e.tiles[K];oe&&(oe.colspan=ie)})}),me=Qv({editor:E,rules:B,modelPath:_,textHeld:g!==void 0,selectTile:N,deselectTile:W}),{menu:ye,addingTile:$e,openAdd:ue}=me,ve=Vv({editor:E,opened:t,givens:f,catalog:d}),{filterDialog:Z,setFilterDialog:Ue}=ve,[fe,le]=k.useState(void 0),{draftDirty:Le,openDraft:We,prepare:he}=Xv({editorDirty:E.dirty}),Ne=k.useMemo(()=>({escape:()=>{!ye&&!Z&&!$e&&fe===void 0&&I()},nudge:K=>{if(J||j===void 0||!B.widths)return;const ie=E.document.tiles[j];if(!ie||ae(ie)&&ie.declaration.kind==="inherited")return;const _e=S.nudgedSpan(ie.colspan??X,K,G);_e!==(ie.colspan??X)&&E.update(oe=>{oe.tiles[j].colspan=_e})}}),[X,E,ye,Z,$e,fe,I,j,G,B,J]),Oe=Wv({editor:H,extraDirty:Le,keepsEdits:M!==void 0&&O.keeping,prepare:he,unit:{name:"tile",count:K=>K.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:Ne,report:Pv({size:E.document.tiles.length,path:_??"",layout:E.document.layout,savesTo:p,onEvent:h})}),D=E.document.tiles.length===0,{toolbarProps:R}=Oe,z=O.restored,P={status:Oe.saving?"saving":R.dirty?"unsaved":"saved",saveTarget:v??Ri[p],...O.keptAt!==void 0?{draftKeptAt:O.keptAt}:{},...(R.dirty||z?.pending)&&M!==void 0?{discard:O.discard}:{},...z?{restored:z}:{},...z&&!z.pending?{dismissRestored:O.dismissRestored}:{}};Rv(C,{...P,...R.onSave?{save:R.onSave}:{},canUndo:R.canUndo,undo:R.onUndo,canRedo:R.canRedo,redo:R.onRedo,add:{...d?{tile:()=>me.openAdd()}:{},text:me.appendText,...y!==void 0?{filterUnavailable:y}:D?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>Ue({})}},...R.onExit?{exit:R.onExit}:{},...Oe.done?{done:Oe.done}:{},...z?.pending?{restore:O.restoreOffered}:{}});const U=C?void 0:m.jsx(sf,{...Oe.toolbarProps,...l?{actions:l}:{},...d?{onAddTile:()=>ue()}:{},savesTo:p,...v?{saveLabel:v}:{},...M!==void 0&&R.onSave?{saveStatus:P}:{}});return m.jsx(fu.Provider,{value:We,children:m.jsx($.Stack,{className:S.reportClasses.builder,"data-saves-to":p,sx:{gap:0,mx:`-${Oi}px`},children:m.jsxs(S.ReportPage,{layout:B.layout,sx:{px:`${Oi}px`,pb:`${Oi}px`},header:m.jsx(jv,{editor:E,documentSlug:ee,actions:U,descriptionSelected:L,selectDescription:V}),controls:D?void 0:m.jsx(Av,{controls:ve.controlList,unknownFieldsOf:ve.unknownFieldsOf,onEdit:K=>Ue({control:K}),onAdd:()=>Ue({}),...y?{addDisabledReason:y}:{},onRemove:ve.dropControl,...w?{fixedFilters:w}:{},...b?{onOpenModel:b}:{},...E.document.startingGivens?{startingValues:E.document.startingGivens}:{},onStartingValue:(K,ie)=>E.update(_e=>{const oe={..._e.startingGivens??{}};ie===void 0?delete oe[K]:oe[K]=ie,Object.keys(oe).length>0?_e.startingGivens=oe:delete _e.startingGivens}),children:c}),children:[D&&m.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),d&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),onClick:()=>ue(),children:"Add tile"})]}),z?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:O.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:O.discard,children:"Discard"})]}),children:`You have unsaved edits from ${ji(z.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),E.error&&m.jsx($.Alert,{severity:"warning",children:E.error}),m.jsx(Ov,{editor:E,reorder:Q,resizing:we,gridBox:A,defaultSpan:X,rules:B,canAdd:!!d,selected:j,flash:F,menuIndex:ye?.index,onSelect:N,onOpenMenu:(K,ie)=>{N(ie),me.setMenu({anchor:K,index:ie})},onRemove:me.removeTile,...E.document.tiles.length===1&&E.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:ue,editTile:me.editTile,...o?{renderTile:o}:{}}),m.jsx(Bf,{editor:E,catalog:d,columns:G,dashboards:u,bindings:ve,tiles:me,drillSource:fe,setDrillSource:le,exitDialog:Oe.exitGuard.dialog,...a?{renderViewPreview:a}:{},...T?{takenGivenNames:T}:{}})]})})})}const ly=S.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),cy=S.createSvgIcon(m.jsx("path",{d:"M9 17H7v-7h2zm4 0h-2V7h2zm4 0h-2v-4h2zm2.5 2.1h-15V5h15zm0-16.1h-15c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"})),dy=S.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function uy({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=Se.usePublisherTheme(),i=S.edgeColor(s.cardBorder),o=S.hoverEdgeColor(s.cardBorder,s.tileTitle),[a,c]=k.useState(null),f=e?.save!==void 0&&e.status!=="saved",d=e?.done??n,l=f&&e?.done===void 0,u=e?.add,h=u!==void 0&&(u.tile!==void 0||u.text!==void 0||u.filter!==void 0||u.filterUnavailable!==void 0),p=v=>()=>{c(null),v?.()};return m.jsxs($.Stack,{direction:"row",role:"toolbar",className:S.reportClasses.builderBar,"aria-label":"Report builder",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[e&&m.jsxs(m.Fragment,{children:[e.save&&m.jsx(Nl,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:Ss(s.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:Ss(s.ui),children:m.jsx(zl,{fontSize:"small"})})})}),h&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),h&&m.jsxs(m.Fragment,{children:[m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),endIcon:m.jsx(S.ExpandMoreIcon,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:v=>c(v.currentTarget),sx:{...gr(i,o),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs($.Menu,{anchorEl:a,open:a!==null,onClose:()=>c(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:fy(i,s.ui)}},MenuListProps:{sx:{p:.5}},children:[u?.tile&&m.jsx(Ii,{icon:m.jsx(cy,{}),title:"Tile",detail:"A view from the model",onClick:p(u.tile)}),u?.text&&m.jsx(Ii,{icon:m.jsx(dy,{}),title:"Text",detail:"Prose between the tiles",onClick:p(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(Ii,{icon:m.jsx(ly,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:p(u.filter)})]})]})]})]}),(d||l)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),d&&m.jsx($.Tooltip,{enterDelay:800,enterNextDelay:800,title:e?.done&&f?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx($.Button,{variant:l?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:d,sx:{...gr(i,o,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&l&&m.jsx($.Tooltip,{title:`Save (${Xt}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...gr(i,o,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const fy=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Ii({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:i}=Se.usePublisherTheme(),o=i.ui;return m.jsxs($.MenuItem,{onClick:s,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:o.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:o.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:i.accent,bgcolor:`color-mix(in srgb, ${i.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx($.Box,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs($.Box,{className:"add-text",sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx($.Box,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function hy(e,t,n=new Set){const r=new Set;for(const o of e.tiles)for(const a of ae(o)?o.filters??[]:[])r.add(a.given);const s=[],i=new Set;for(const o of e.localGivens??[])r.has(o.name)&&(i.add(o.name),s.push(S.localGivenSpec(o)));for(const o of t)o.name===void 0||i.has(o.name)||!(r.has(o.name)||n.has(o.name))||(i.add(o.name),s.push(o));return s}function py(e,t,n){const r=new Map;for(const i of t.tiles)ae(i)&&r.set(_n(`${i.source} -> ${i.name}`),new Set((i.filters??[]).map(o=>o.given)));const s=new Set;for(const i of e.tiles){if(!ae(i))continue;const o=_n(`${i.source} -> ${i.name}`),a=r.get(o);for(const c of n.get(o)??[])a?.has(c)||s.add(c)}return s}function gy(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function my(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function _n(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function vy(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(x=>[x.name,x.type])),c=new Map((e.localGivens??[]).map(x=>[x.name,x.default])),f=e.sources.find(x=>x.name===i)?.scopedBy??[],d=new Set([...f,...s??[]].filter(x=>n.has(x))),l=new Set([...f,...s??[]]),u=[];for(const x of t.filters??[]){const _=`where: ${pe.malloyPath(x.field)} ${x.op??"~"}`;if(n.has(x.given)){d.add(x.given),l.add(x.given),u.push(`${_} $${x.given}`);continue}if(!a.has(x.given))continue;l.add(x.given);const g=S.malloyLiteral(r.get(x.given),a.get(x.given))??gy(c.get(x.given));g!==void 0&&u.push(`${_} ${g}`)}const h=u.join(", "),p=t.chart,v=p==="none"||S.isChartPick(p)?S.chartLineText(p,t.chartCarried):p==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
+
`):p==="default"&&my(t.declaration)?S.chartLineText("none"):void 0;return{...v?{annotation:v}:{},expression:`${i} -> ${o}`+(h?` + { ${h} }`:""),givenNames:Array.from(d),reads:s||l.size>0?Array.from(l):void 0}}function yy({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:i}){const{apiClients:o,server:a}=Se.useServer(),{data:c}=S.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]:[])}),f=k.useMemo(()=>new Set([r,...s.flatMap(p=>p.path?[p.path]:[])]),[s,r]),d=k.useMemo(()=>i?(c??[]).filter(p=>!f.has(p)):[],[c,f,i]),l=Fl.useQueries({queries:d.map(p=>({queryKey:["report-editor-model",e,t,p,n,a],queryFn:async()=>(await o.models.getModel(e,t,p,n)).data,retry:!1}))}),u=c!==void 0&&i&&l.every(p=>p.isSuccess||p.isError),h=l.map(p=>p.dataUpdatedAt).join();return k.useMemo(()=>u?Qu(l.flatMap((p,v)=>p.data?[{...p.data,path:d[v]}]:[]),f):void 0,[u,d,h,f])}const by={};function xy({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:s,queryVersionId:i,opened:o,replaces:a,onSave:c,onDirtyChange:f,onExit:d,onOpenModel:l,onControlsChange:u,draftKey:h,onEvent:p,savesTo:v,saveLabel:x,note:_}){const{apiClients:g}=Se.useServer(),[y,w]=k.useState(o.document.tiles.length>0);k.useEffect(()=>w(o.document.tiles.length>0),[o.generation,o.document]);const{data:b,isSuccess:T,isError:C}=S.useQueryWithApiError({...S.reportQueryOptions(g,{environmentName:t,packageName:n,path:r,versionId:i},S.BUILDER_HANDOFF_STALE_MS),enabled:y&&!e}),M=e?.modelPath??r,E=_y(o.source,e?.compileSource),O=S.useCompiledDocument({environmentName:t,packageName:n,modelPath:M,source:E.text??o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&E.text!==void 0}),A=O.data?.document,j=e?O.isSuccess?A?.manifest??by:void 0:b,L=e?O.isSuccess:T,N=e?O.isError||E.problem!==void 0:C,W=e?S.documentPreamble(A?.cells):void 0,V=(O.data?.result.problems??[]).filter(P=>P.severity==="error"),I=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),F=e?.givens,H=k.useMemo(()=>new Set((j?.tiles??[]).flatMap(P=>P.restricted&&P.query?[_n(P.query)]:[])),[j]),{reports:B,settled:G}=S.useReportListing(t,n,i),ee=k.useMemo(()=>B.map(P=>P.path).filter(P=>!!P&&P!==r&&P.endsWith(".malloy")).map(P=>P.replace(/\.malloy$/,"")),[B,r]),Q=yy({environmentName:t,packageName:n,...i!==void 0?{versionId:i}:{},modelPath:r,reports:B,reportsSettled:G}),J=k.useMemo(()=>e?(Q?.sources??[]).filter(P=>(P.visibleIn??P.exporters??[P.modelPath]).includes(M)).map(P=>P.name):void 0,[Q,e,M]),X=k.useMemo(()=>Q&&J?{sources:Q.sources.filter(P=>J.includes(P.name))}:Q,[Q,J]),[te,we]=k.useState(o.document);k.useEffect(()=>we(o.document),[o.document]);const me=k.useMemo(()=>c&&(async(P,U)=>{await c(P,U.document.layout),v==="package"&&w(U.document.tiles.length>0)}),[c,v]),ye=k.useMemo(()=>(j?.givens??[]).filter(P=>!(e&&P.secure===!0)&&!(P.name!==void 0&&I.has(P.name))),[j,I,e]),$e=k.useMemo(()=>new Set([...ye.map(P=>P.name).filter(P=>P!==void 0),...Object.keys(F??{})]),[ye,F]),ue=k.useMemo(()=>new Map((j?.tiles??[]).flatMap(P=>P.kind!=="text"&&P.query&&P.givenNames?[[_n(P.query),P.givenNames]]:[])),[j]),ve=k.useMemo(()=>py(te,o.document,ue),[te,o.document,ue]),Z=k.useMemo(()=>hy(te,ye,ve),[te,ye,ve]),Ue=k.useMemo(()=>{const P=new Set(te.tiles.flatMap(oe=>ae(oe)?(oe.filters??[]).map(Ge=>Ge.given):[])),U=new Set((te.localGivens??[]).map(oe=>oe.name)),K=[...new Set(te.imports.map(oe=>oe.from))],ie=K.length===1?ky(r,K[0]):K.length===0&&e?e.modelPath:void 0,_e=oe=>{const Ge=te.sources.filter(et=>et.scopedBy?.includes(oe)).map(et=>et.name);return Ge.length>0?{reason:`Applied to every tile on ${Ge.join(", ")} by this report's own source. Edit the file to change it.`}:U.has(oe)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:ie!==void 0?{reason:`Set in the model ${ie}. Edit the model to change it.`,modelPath:ie}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...ve].filter(oe=>!P.has(oe)).map(oe=>[oe,_e(oe)]))},[te,ve,e,r]),{declaredTypes:fe,applied:le,panel:Le}=S.useDocumentControls({specs:Z,loaded:L,startingValues:j?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:j?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?M:j?.path,versionId:i,documentName:r,...W!==void 0?{preamble:W}:{},...F?{hostGivens:F}:{}}),We=k.useMemo(()=>S.missingRequiredGivens(Z,le,F),[Z,le,F]),he=k.useMemo(()=>Object.fromEntries(Object.entries(F??{}).filter(([P])=>!fe.has(P))),[F,fe]),Ne=!y||L||N,Oe=e!==void 0&&(E.problem!==void 0||O.isError||V.length>0),D=k.useMemo(()=>new Map(o.document.tiles.map(P=>[Fe(P),P])),[o.document]),R=k.useMemo(()=>function(U,K,ie="card"){if(Oe)return m.jsxs(S.TileCard,{chrome:ie,children:[m.jsx(S.TileHeading,{title:K?.title??kn(U),subtitle:K?K.subtitle:U.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!Ne)return m.jsxs(S.TileCard,{chrome:ie,children:[m.jsx(S.TileHeading,{title:K?.title??kn(U),subtitle:K?K.subtitle:U.subtitle}),m.jsx(S.Loading,{text:"Running…"})]});const _e=ue.get(_n(`${U.source} -> ${U.name}`)),Ge=W===void 0&&_e!==void 0&&wy(D.get(Fe(U)),U)?{expression:`${U.source} -> ${U.name}`,givenNames:[..._e],reads:[..._e]}:vy(te,U,$e,le,_e);return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:i,modelPath:M,...W!==void 0?{preamble:W}:{},...H.has(_n(`${U.source} -> ${U.name}`))?{restricted:!0}:{},tile:Ge.expression,...Ge.annotation?{annotation:Ge.annotation}:{},label:kn(U),chrome:ie,subtitle:U.subtitle,...K?{heading:K}:{},borderless:U.borderless,givens:le,hostGivens:he,declaredTypes:fe,givenNames:Ge.givenNames,...(()=>{const et=S.waitingOn(We,Ge.reads??Ge.givenNames);return et.length>0?{waitingFor:S.waitingText(et)}:{}})(),ignoredFilters:S.tileIgnoredFilterLabels(Ge.reads,Z),height:S.TILE_MAX_HEIGHT})},[te,D,Ne,Oe,We,$e,ue,t,n,i,M,W,H,le,he,fe,Z]),z=k.useMemo(()=>function(U){return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:i,modelPath:U.modelPath,tile:`${U.base} -> ${U.view}`,...U.chart?{annotation:S.chartLineText(U.chart,U.chartCarried)}:{},label:U.label,borderless:!0,givens:le,hostGivens:he,declaredTypes:fe,givenNames:U.givens,height:200})},[t,n,i,le,he,fe]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&V.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",V.map(P=>P.message).join("; ")]}),We.length>0&&!Oe&&m.jsx($.Alert,{severity:"info",children:S.requiredPrompt(We)}),e&&E.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",E.problem]}),e&&O.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",O.error?.message]}),m.jsx(Da,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:o.source,document:o.document,fixedFilters:Ue,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:R,renderViewPreview:z,givens:Z.filter(P=>P.name!==void 0).map(P=>({name:P.name,...P.label?{label:P.label}:{},...P.type?{type:P.type}:{},...P.suggest?.dimension?{field:P.suggest.dimension}:{}})),onChange:we,onDirtyChange:f,...d?{onExit:d}:{},...l?{onOpenModel:l}:{},...u?{onControlsChange:u}:{},...h!==void 0?{draftKey:h}:{},...X?{catalog:X}:{},dashboards:ee,...p?{onEvent:p}:{},controls:L?m.jsx(S.GivensPanel,{...Le,layout:"bar"}):void 0,...me?{onSave:me}:{},savesTo:v,...x?{saveLabel:x}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:J}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:_})})]})}function wy(e,t){return e!==void 0&&JSON.stringify(Bl(e))===JSON.stringify(Bl(t))}function Bl(e){const{label:t,subtitle:n,colspan:r,break:s,borderless:i,...o}=e;return o}function _y(e,t){const n=k.useRef(t);n.current=t;const r=t!==void 0,[s,i]=k.useState();return k.useEffect(()=>{if(!r)return;let o=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{o&&i({from:e,text:a})},a=>{o&&i({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{o=!1}},[e,r]),r?s?.from!==e?{}:s.problem!==void 0?{problem:s.problem}:{text:s.text}:{text:e}}function ky(e,t){const n=e.split("/").slice(0,-1);for(const r of t.split("/"))r===".."?n.pop():r!=="."&&r!==""&&n.push(r);return n.join("/")}function Sy({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(void 0),[d,l]=k.useState(e===void 0),[u,h]=k.useState(!1),[p,v]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let x=!1;return v(void 0),(async()=>{try{const _=S.chooseWorkspace(await e.listWorkspaces(!1));if(x)return;if(a(_),_!==void 0&&(!n||_.authoritative)){const g=await e.getDocument(S.locatorFor(t,_.name,r,s,i)).catch(y=>{if(!S.isDocumentNotFound(y))throw y});if(x)return;f(g),h(g!==void 0)}}catch(_){if(x)return;v(S.storageErrorMessage(_))}x||l(!0)})(),()=>{x=!0}},[e,t,n,r,s,i]),{workspace:o,draft:c,setDraft:f,draftChecked:d,offered:u,setOffered:h,readFailure:p}}const $y=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Ty(e){const t=await Ks(e);return Hs(t)?{ok:!1,reason:$y(t.reason,t.line)}:{ok:!0,document:t.document}}const Ey="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Cy="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Oy({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,layout:c,notebook:f,noun:d,legacyFormat:l,textHeld:u,startedAt:h,onEventRef:p}){const v=k.useRef({path:a,layout:c});v.current={path:a,layout:c};const x=k.useRef((le,Le)=>{try{p.current?.(S.withReportContext(le,{...v.current,...Le?{layout:Le}:{}}))}catch{}}),_=e?.authoritative===!0,g=_&&r!==void 0,[y,w]=k.useState(void 0),b=(_||y===!0)&&t!==void 0,[T,C]=k.useState(void 0),[M,E]=k.useState(l?Ey:void 0),O=k.useRef(void 0),A=k.useRef(void 0),[j,L]=k.useState(void 0),N=k.useRef(i);N.current=i;const W=j!==void 0&&j.onFetch===i?j.text:s,V=k.useRef(W);V.current=W;const I=b?t:W,[F,H]=k.useState(!1),[B,G]=k.useState(void 0),[ee,Q]=k.useState(void 0),J=I!==void 0&&I!==ee,X=T?.source,we=J&&(F||!_&&t!==void 0&&X===t&&t!==W)&&X!==void 0&&I!==B,me=we?X:J?I:X??I,ye=we?I:void 0,$e=k.useRef(X);$e.current=X;const ue=k.useRef(I);ue.current=I;const ve=k.useRef("package");ve.current=b?_?"record":"draft":"package",k.useEffect(()=>{if(me===void 0||!n||g||me===$e.current)return;let le=!1;const Le=V.current,We=ue.current;return Ty(me).then(he=>{if(!le){if(he.ok===!1){E(he.reason),x.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}E(void 0),O.current=void 0,A.current=Le,L(void 0),G(void 0),Q(We),C(Ne=>({source:me,document:he.document,...Le!==void 0?{packageText:Le}:{},generation:(Ne?.generation??0)+1})),x.current({type:"report.opened",surface:"edit",from:ve.current,tiles:he.document.tiles.length,durationMs:S.now()-h.current},he.document.layout)}}).catch(he=>{if(le)return;const Ne=`Could not read the ${d}: ${he instanceof Error?he.message:String(he)}`;E(Ne),x.current({type:"report.load_failed",surface:"edit",category:S.failureCategory(he)})}),()=>{le=!0}},[me,a,n,g,f,d,u,h]),k.useEffect(()=>{l&&x.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[l]),k.useEffect(()=>{!u||!n||T||r!==void 0||(_?t===void 0&&E("the host's storage has no document at this location."):E("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,T,r,_,t]);const Z=f&&!u&&!T&&n&&!b&&o&&s===void 0;return k.useEffect(()=>{Z&&(E(Cy),x.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Z]),{authoritative:_,blockedOnRecord:g,resume:y,setResume:w,fromDraft:b,opened:T,setOpened:C,openError:M,savedHashRef:O,packageBaseRef:A,setWrote:L,fetchedAtRef:N,setDirty:H,setSeen:Q,held:ye,choose:le=>{h.current=S.now(),G(le?t:W),w(le)},acceptHeld:()=>{h.current=S.now(),G(ye)}}}function Dy({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:c,queryClient:f,mutable:d,textHeld:l,readFailure:u,authoritative:h,resume:p,setResume:v,setOpened:x,setDraft:_,setOffered:g,setSeen:y,setWrote:w,savedHashRef:b,packageBaseRef:T,fetchedAtRef:C}){const M=k.useCallback(B=>t===void 0?void 0:S.locatorFor(B,t.name,s,i,o),[t,s,i,o]),E=M(n),O=k.useCallback(async(B,G=n)=>{const ee=M(G);if(!e||!ee)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(ee,B),x(Q=>Q&&{...Q,source:B}),_(B),(h||p===!0)&&y(B),h||v(Q=>Q??!1)},[e,M,n,h,p,x,_,y,v]),[A,j]=k.useState(void 0),L=k.useCallback(async B=>{const G=await S.expectedHashFor(b.current,T.current);if(G===void 0)throw new Error("The package file is still loading; try again.");const ee=["dashboard-editor-model",s,i,o,a,r];await S.writePackageFile({apiClients:c,queryClient:f,environmentName:s,packageName:i,modelPath:o,source:B,expectedHash:G,invalidateOnError:[ee],afterWrite:async Q=>{if(x(J=>J&&{...J,source:B}),w({text:B,onFetch:C.current}),y(B),b.current=Q,j(void 0),e&&E)try{await e.deleteDocument(E),_(void 0),g(!1)}catch(J){S.isDocumentNotFound(J)?(_(void 0),g(!1)):j(S.storageErrorMessage(J))}v(!1)},invalidate:[{queryKey:ee,wait:!0},{queryKey:S.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})}]}),S.invalidateReportQueries(f,s,i,o)},[c,s,i,o,a,r,e,E,f,b,T,C,x,w,y,_,g,v]),N=t?.writeable===!0,W=d===!0&&!l,{savesTo:V,pinnedPackageSave:I,writer:F}=S.saveTarget({authoritative:h,mutable:W,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!E&&N&&(!r||h),readFailed:u!==void 0});return{save:F==="storage"?O:F==="package"?L:void 0,savesTo:V,writer:F,pinnedPackageSave:I,takesWrites:W,supersedeFailure:A}}function Ma(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:i,onControlsChange:o,keepDraft:a,kind:c,path:f,textSource:d,queryVersionId:l}=e,u=e.layout??(c?S.layoutOfKind(c):"grid"),h=u==="linear",p=d!==void 0,{environmentName:v,packageName:x,versionId:_,namesBoth:g}=S.resolveEditorTarget(e),w=("resourceUri"in e?e.dashboard:e.dashboardName)??S.documentSlug(f)??"",b="report",{apiClients:T,mutable:C,isLoadingStatus:M,server:E}=Se.useServer(),O=Fl.useQueryClient(),A=k.useRef(S.now()),j=k.useRef(t);j.current=t;const L=k.useRef(r);L.current=r;const N=S.useOptionalDocumentStorage()?.documentStorage,W=f??S.legacyNamedPath(c??"dashboard",w),V=/\.malloynb$/i.test(W)||h&&/\.malloynb$/i.test(w),I=S.useQueryWithApiError({queryKey:["dashboard-editor-model",v,x,W,_,h],queryFn:()=>T.models.getModel(v,x,W,_,h?!0:void 0),enabled:g&&!V&&!p}),F=I.data?.data?.sourceText,{workspace:H,draft:B,setDraft:G,draftChecked:ee,offered:Q,setOffered:J,readFailure:X}=Sy({storage:N,layout:u,notebook:h,environmentName:v,packageName:x,modelPath:W}),{authoritative:te,blockedOnRecord:we,resume:me,setResume:ye,fromDraft:$e,opened:ue,setOpened:ve,openError:Z,savedHashRef:Ue,packageBaseRef:fe,setWrote:le,fetchedAtRef:Le,setDirty:We,setSeen:he,held:Ne,choose:Oe,acceptHeld:D}=Oy({workspace:H,draft:B,draftChecked:ee,readFailure:X,packageText:F,fetchedAt:I.dataUpdatedAt,packageSettled:I.isSuccess&&!I.isFetching,modelPath:W,layout:u,notebook:h,noun:b,legacyFormat:V,textHeld:p,startedAt:A,onEventRef:j}),{save:R,savesTo:z,writer:P,pinnedPackageSave:U,takesWrites:K,supersedeFailure:ie}=Dy({storage:N,workspace:H,layout:u,notebook:h,environmentName:v,packageName:x,modelPath:W,versionId:_,apiClients:T,queryClient:O,mutable:C,textHeld:p,readFailure:X,authoritative:te,resume:me,setResume:ye,setOpened:ve,setDraft:G,setOffered:J,setSeen:he,setWrote:le,savedHashRef:Ue,packageBaseRef:fe,fetchedAtRef:Le}),_e=H?.name,oe=k.useCallback(Vn=>{j.current?.(S.withWorkspace(Vn,_e))},[_e]),Ge=I.isError&&!ue,et=k.useRef(!1);k.useEffect(()=>{!Ge||et.current||(et.current=!0,S.reportEmitter({path:W,layout:u},j.current).emit({type:"report.load_failed",surface:"edit",category:S.failureCategory(I.error)}))},[Ge,I.error,W,u]);const Vr=k.useCallback((Vn,ce)=>{We(Vn),L.current?.(ce)},[We]),rn=a?S.reportDraftKey({server:E,environmentName:v,packageName:x,versionId:_,path:f??w}):void 0,sn=z==="host"&&H?.description?H.description:void 0,Kr=!te&&!p&&C===void 0?M?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":S.saveCaption({authoritative:te,mutable:K,pinnedPackageSave:U,...H?{workspace:H}:{},...X!==void 0?{readFailure:X}:{},..._!==void 0?{versionId:_}:{}}),ci=z==="package"&&K===!0&&!U&&X===void 0||Kr===sn?"":Kr;if(!g&&"resourceUri"in e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",b," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(Z)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened in the builder: ",Z]});if(I.isError&&!ue)return m.jsx(S.ApiErrorDisplay,{error:I.error,context:`Opening the ${b}`});if(!ue&&(!(p||F)||!ee))return n??m.jsx(S.Loading,{text:`Opening the ${b}…`});if(we)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",X]});const Yr=B!==void 0&&B!==F;return m.jsxs($.Stack,{sx:{gap:2},children:[I.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",I.error?.message,". Your edits are still here."]}),!h&&!te&&Q&&Yr&&me===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Oe(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Oe(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),Ne!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{rn!==void 0&&S.clearReportDraft(rn),D()},children:"Load it"}),children:z==="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.":z==="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."}),ie!==void 0&&m.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:"," ",ie]}),!ue&&(n??m.jsx(S.Loading,{text:`Opening the ${b}…`})),ue&&m.jsx(xy,{environmentName:v,packageName:x,modelPath:W,...d?{textSource:d}:{},slug:w,..._!==void 0?{versionId:_}:{},...(l??_)!==void 0?{queryVersionId:l??_}:{},opened:ue,...$e&&P==="package"&&ue.packageText!==void 0?{replaces:ue.packageText}:{},onSave:R,onDirtyChange:Vr,...s?{onExit:s}:{},...i?{onOpenModel:i}:{},...o?{onControlsChange:o}:{},...rn!==void 0?{draftKey:rn}:{},savesTo:z,...sn?{saveLabel:sn}:{},...t?{onEvent:oe}:{},note:ci},ue.generation)]})}const My=Ma,Iy=Da;function jy(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 m.jsx(Ma,{...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=S.MAX_SLUG_ATTEMPTS;exports.createDocument=S.createDocument;exports.createRoute=S.createRoute;exports.locatorFor=S.locatorFor;exports.newDashboardSource=S.newDashboardSource;exports.newDocumentProblem=S.newDocumentProblem;exports.newNotebookSource=S.newNotebookSource;exports.reportPathFor=S.reportPathFor;exports.reportPathForTitle=S.reportPathForTitle;exports.slugFor=S.slugFor;exports.slugOrFallback=S.slugOrFallback;exports.useDocumentChoices=S.useDocumentChoices;exports.BuilderBar=uy;exports.DashboardBuilder=Iy;exports.DashboardEditor=My;exports.NotebookEditor=jy;exports.ReportBuilder=Da;exports.ReportEditor=Ma;exports.buildCatalog=Qu;exports.readDashboardDocument=Ks;exports.readFailed=Hs;exports.readReportTagOfText=Nm;exports.spliceDashboardDocument=Hu;exports.spliceFailed=qs;
|