@malloy-publisher/sdk 0.17.0 → 0.17.2
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/README.md +32 -50
- package/dist/{RenderedResult-BcEDcw0V.es.js → RenderedResult-CYJ2Y9Fm.es.js} +24 -24
- package/dist/{RenderedResult-uT2oc6ke.cjs.js → RenderedResult-hRvgFMAF.cjs.js} +1 -1
- package/dist/ServerProvider-DeVejmVr.cjs.js +1 -0
- package/dist/{ServerProvider-vmEUjlEu.es.js → ServerProvider-DzzfVDg_.es.js} +1314 -1712
- package/dist/builder/index.cjs.js +12 -12
- package/dist/builder/index.es.js +4 -9
- package/dist/client/api.d.ts +63 -506
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +132 -144
- package/dist/components/Dashboard/DashboardGrid.d.ts +1 -1
- package/dist/components/Model/ExplorerPage.d.ts +1 -3
- package/dist/components/Model/Model.d.ts +1 -4
- package/dist/components/Model/ModelExplorer.d.ts +1 -2
- package/dist/components/Package/reportQueries.d.ts +2 -4
- package/dist/components/Report/Report.d.ts +20 -9
- package/dist/components/{legacy → Report}/malloynb/CellRunnerView.d.ts +13 -16
- package/dist/components/Report/malloynb/MalloynbReport.d.ts +11 -0
- package/dist/components/{legacy → Report}/malloynb/cellKind.d.ts +1 -1
- package/dist/components/ServerProvider.d.ts +1 -3
- package/dist/components/drill/drillClauses.d.ts +8 -9
- package/dist/components/drill/rowsTarget.d.ts +7 -9
- package/dist/components/legacy/index.d.ts +3 -7
- package/dist/components/modelPage.d.ts +2 -5
- package/dist/hooks/useModelGivens.d.ts +2 -2
- package/dist/hooks/useQueryResult.d.ts +7 -0
- package/dist/index.cjs.js +33 -33
- package/dist/index.es.js +8799 -8903
- package/dist/{useCompiledDocument-h5-Kc1Zh.cjs.js → useCompiledDocument-BCr-xB_i.cjs.js} +4 -4
- package/dist/{useCompiledDocument-rOwDSK_s.es.js → useCompiledDocument-E0tU5KzP.es.js} +266 -277
- package/package.json +1 -1
- package/src/components/Dashboard/DashboardGrid.tsx +1 -1
- package/src/components/Dashboard/DashboardTile.spec.tsx +1 -1
- package/src/components/Model/ExplorerPage.tsx +1 -3
- package/src/components/Model/Model.tsx +1 -4
- package/src/components/Model/ModelExplorer.tsx +1 -2
- package/src/components/Package/Package.tsx +1 -5
- package/src/components/Package/reportQueries.ts +3 -15
- package/src/components/Report/Report.malloynb.spec.tsx +230 -0
- package/src/components/Report/Report.spec.tsx +429 -38
- package/src/components/Report/Report.telemetry.spec.tsx +51 -10
- package/src/components/Report/Report.tsx +63 -44
- package/src/components/{legacy → Report}/malloynb/CellRunnerView.spec.tsx +11 -44
- package/src/components/{legacy → Report}/malloynb/CellRunnerView.tsx +63 -107
- package/src/components/Report/malloynb/MalloynbReport.tsx +110 -0
- package/src/components/{legacy → Report}/malloynb/cellKind.ts +5 -4
- package/src/components/ReportBuilder/EditorSurface.tsx +3 -3
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +2 -2
- package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +0 -4
- package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +0 -1
- package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -3
- package/src/components/ReportBuilder/ReportEditor.tsx +1 -1
- package/src/components/ReportBuilder/loadMalloy.ts +1 -4
- package/src/components/ReportBuilder/useSaveChannel.ts +1 -6
- package/src/components/ServerProvider.tsx +0 -4
- package/src/components/drill/drillClauses.ts +8 -9
- package/src/components/drill/rowsTarget.ts +7 -9
- package/src/components/index.ts +2 -3
- package/src/components/legacy/index.ts +3 -7
- package/src/components/modelPage.ts +2 -5
- package/src/hooks/useGivensState.ts +8 -8
- package/src/hooks/useModelGivens.ts +2 -2
- package/src/hooks/useQueryResult.ts +30 -18
- package/test/README.md +4 -4
- package/dist/ServerProvider-DDRwHiPz.cjs.js +0 -1
- package/dist/components/legacy/Dashboard.d.ts +0 -68
- package/dist/components/legacy/malloynb/MalloynbCells.d.ts +0 -13
- package/dist/components/legacy/malloynb/Notebook.d.ts +0 -15
- package/dist/components/legacy/queryKeys.d.ts +0 -8
- package/src/components/legacy/Dashboard.spec.tsx +0 -242
- package/src/components/legacy/Dashboard.tsx +0 -181
- package/src/components/legacy/malloynb/MalloynbCells.tsx +0 -88
- package/src/components/legacy/malloynb/Notebook.layout.spec.tsx +0 -103
- package/src/components/legacy/malloynb/Notebook.served.spec.tsx +0 -84
- package/src/components/legacy/malloynb/Notebook.spec.tsx +0 -223
- package/src/components/legacy/malloynb/Notebook.tsx +0 -46
- package/src/components/legacy/queryKeys.ts +0 -26
- /package/dist/components/{legacy → Report}/malloynb/NotebookCell.d.ts +0 -0
- /package/dist/components/{legacy → Report}/malloynb/runPlan.d.ts +0 -0
- /package/dist/components/{legacy → Report}/malloynb/types.d.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/NotebookCell.tsx +0 -0
- /package/src/components/{legacy → Report}/malloynb/cellKind.spec.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/runPlan.spec.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/runPlan.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/types.ts +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),k=require("../useCompiledDocument-h5-Kc1Zh.cjs.js"),$=require("@mui/material"),S=require("react"),be=require("../ServerProvider-DDRwHiPz.cjs.js"),me=require("../text-entry-BJwltZiy.cjs.js"),Nf=require("react-dom"),uc=require("@tanstack/react-query"),Ce=e=>e.kind==="text",ce=e=>e.kind!=="text",lr=e=>ce(e)?e.label??e.name:e.name,dt=e=>e.declaration.kind==="query"?e.name:`${e.source} -> ${e.name}`,Hn=e=>e.declaration.kind==="inherited"||e.declaration.kind==="query",fe=e=>Ce(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,Ka=".malloy-big-value, .malloy-table",zf=e=>e.querySelector(Ka)!==null&&![...e.querySelectorAll(".malloy-chart")].some(t=>t.closest(Ka)===null),As=(e,t)=>Ce(e)?k.MIN_TEXT_TILE_ROWS:t&&zf(t)?k.MIN_VALUE_TILE_ROWS:k.MIN_TILE_ROWS,Fr=e=>e.rowspan??k.PLACED_DEFAULT_ROWSPAN[Ce(e)?"text":"query"];function Ut(e,t){if(e.row===void 0||e.col===void 0)return;const n=Math.min(e.colspan??1,t);return{row:e.row,col:Math.min(e.col,t-n+1),colspan:n,rowspan:Fr(e)}}const Wr=(e,t)=>e.col<t.col+t.colspan&&t.col<e.col+e.colspan&&e.row<t.row+t.rowspan&&t.row<e.row+e.rowspan;function In(e){return e.map((t,n)=>({tile:t,index:n})).sort((t,n)=>(t.tile.row??1/0)-(n.tile.row??1/0)||(t.tile.col??1/0)-(n.tile.col??1/0)||t.index-n.index).map(({tile:t})=>t)}function Rt(e,t,n){const r=e.map(a=>({...a})),s=[],o=a=>{const l=Ut(r[a],t);l&&(r[a].col=l.col,s.push(l))};n!==void 0&&o(n);const i=r.map((a,l)=>({tile:a,index:l})).filter(({index:a,tile:l})=>a!==n&&l.row!==void 0).sort((a,l)=>(a.tile.row??0)-(l.tile.row??0)||(a.tile.col??0)-(l.tile.col??0)||a.index-l.index);for(const{index:a}of i){const l=Ut(r[a],t);if(l){for(;;){const u=s.filter(c=>Wr(l,c));if(u.length===0)break;l.row=Math.max(...u.map(c=>c.row+c.rowspan))}r[a].row=l.row,o(a)}}return r}function Gf(e,t,n,r){const s=e.flatMap((l,u)=>{const c=u===t?void 0:Ut(l,r);return c?[c]:[]}),o=Math.max(1,...s.map(l=>l.row+l.rowspan)),i={...e[t],...n,row:Math.min(n.row,o)},a=Ut(i,r);if(a){for(;;){const l=s.filter(u=>u.row<a.row&&Wr(a,u));if(l.length===0)break;a.row=Math.max(...l.map(u=>u.row+u.rowspan))}i.row=a.row}return Rt(e.map((l,u)=>u===t?i:l),r,t)}const Ls=(e,t)=>(e-k.GRID_GAP_PX*(t-1))/t,fc=k.TILE_ROW_PX+k.GRID_GAP_PX;function hc(e,t,n,r,s){const o=Math.min(n,r),i=Math.round(e/(s+k.GRID_GAP_PX))+1;return{row:Math.max(1,Math.round(t/fc)+1),col:Math.min(Math.max(i,1),r-o+1)}}function pc(e,t,n,r){const s=e.map((o,i)=>{if(o.row!==void 0&&o.col!==void 0)return o;const a=t[i];if(!a)return o;const{break:l,...u}=o,c=o.colspan??Math.max(1,Math.round((a.width+k.GRID_GAP_PX)/(r+k.GRID_GAP_PX))),d=hc(a.left,a.top,c,n,r),f=(a.top+a.height+k.GRID_GAP_PX)/fc,h=Ce(o)?Math.ceil(f-.02):Math.round(f);return{...u,...d,colspan:c,rowspan:o.rowspan??Math.max(As(o),h-d.row+1)}});return Rt(s,n)}function Va(e,t,n){const r=e.flatMap((o,i)=>{const a=i===t?void 0:Ut(o,n);return a?[a]:[]});if(r.length===0)return[...e];const s=Math.max(...r.map(o=>o.row+o.rowspan));return e.map((o,i)=>i===t?{...o,row:s,col:1}:o)}function gc(e,t){const n=e.map(o=>({...o})),r=[],s=n.map((o,i)=>({tile:o,index:i})).filter(({tile:o})=>o.row!==void 0&&o.col!==void 0).sort((o,i)=>(o.tile.row??0)-(i.tile.row??0)||(o.tile.col??0)-(i.tile.col??0)||o.index-i.index);for(const{index:o}of s){const i=Ut(n[o],t);if(i){for(;i.row>1&&!r.some(a=>Wr({...i,row:i.row-1},a));)i.row-=1;n[o].row=i.row,n[o].col=i.col,r.push(i)}}return n}const Hf=(e,t)=>gc(e,t).some((n,r)=>n.row!==e[r].row||n.col!==e[r].col);function qf(e){return In(e).map(t=>{const{row:n,col:r,...s}=t;return s})}const Uf=(e,t,n)=>e.map((r,s)=>s===t?{...r,...n}:r);function Xa(e,t,n,r,s){const o=Ut(e[t],s);if(!o)return[...e];const i={row:Math.max(1,o.row+n),col:Math.min(Math.max(1,o.col+r),s-o.colspan+1)};if(i.row===o.row&&i.col===o.col)return[...e];const a={...o,...i},l=e.flatMap((h,y)=>{const g=y===t?void 0:Ut(h,s);return g&&Wr(a,g)&&!Wr(o,g)?[{i:y,other:g}]:[]}),u=l.length===1?l[0]:void 0;if(!u)return Rt(Uf(e,t,i),s,t);const{i:c,other:d}=u,f=e.map(h=>({...h}));return n>0?(f[c].row=o.row,f[t].row=o.row+d.rowspan):n<0?(f[t].row=d.row,f[c].row=d.row+o.rowspan):r>0?(f[c].col=o.col,f[t].col=o.col+d.colspan):(f[t].col=d.col,f[c].col=d.col+o.colspan),Rt(f,s,t)}const mc=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1);function Kf(e){return Ce(e)||e.rowspan===void 0?e:k.isChartPick(e.chart)&&e.chart!=="big_value"&&e.rowspan<k.MIN_TILE_ROWS?{...e,rowspan:k.MIN_TILE_ROWS}:e}const vc=k.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"})),yc=k.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"})),Vf=k.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 xc(e){const{theme:t}=be.usePublisherTheme(),n=t.ui,[r,s]=S.useState(null),{status:o,draftKeptAt:i,discard:a,restored:l,dismissRestored:u}=e,c=l!==void 0&&!l.pending&&o==="unsaved"?l:void 0,d=o==="saved"?"Saved":o==="saving"?"Saving…":i!==void 0?"Draft saved":"Unsaved changes",f=c?`Restored your unsaved edits from ${qo(c.savedAt)}`:void 0,h=o==="unsaved"&&i!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,y=a!==void 0&&o==="unsaved",g=()=>{s(null),c&&u?.()},w=v=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:o==="saved"?v.palette.text.secondary:v.palette.text.primary,transition:`color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,...y?{"&:hover":{bgcolor:v.palette.action.hover}}:{}}),x=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:o==="saved"?m.jsx(k.CheckIcon,{sx:{fontSize:16}}):m.jsx($.Box,{component:"span","data-restored":c?"true":void 0,sx:v=>({width:7,height:7,borderRadius:"50%",bgcolor:c?t.accent:o==="saving"||i!==void 0?v.palette.text.disabled:v.palette.warning.main,transition:`background-color ${k.MOTION_FAST}`})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:d}),m.jsx(k.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:y?"visible":"hidden"}})]}),p=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:Xf,children:f?`${d}. ${f}.`:d});return m.jsxs(m.Fragment,{children:[p,m.jsx($.Tooltip,{title:f??h,describeChild:!0,children:y?m.jsx($.ButtonBase,{className:k.reportClasses.saveStatus,"aria-label":d,...f?{"aria-description":f}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:v=>s(v.currentTarget),sx:w,children:x}):m.jsx($.Box,{component:"span",className:k.reportClasses.saveStatus,sx:w,children:x})}),m.jsxs($.Menu,{className:k.reportClasses.menu,anchorEl:r,open:r!==null,onClose:g,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${k.edgeColor(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(f!==void 0||i!==void 0)&&m.jsx($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:f??`Kept in this browser at ${qo(i)}`}),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(Vf,{fontSize:"small"}),"Discard edits"]})]})]})}function qo(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 Xf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},Uo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),cn=Uo?"⌘":"Ctrl+",Ya=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},So=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function Yf(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e});const[n,r]=S.useState(!1);S.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),S.useEffect(()=>{const s=o=>{const i=t.current;if(i.paused)return;const a=Uo?o.metaKey:o.ctrlKey,l=o.key.toLowerCase();if(o.key==="Escape"){if(Ya(o.target)||So(o.target))return;i.escape();return}if(Ya(o.target)){if(a&&l==="s"){if(o.preventDefault(),!i.save||So(o.target))return;o.target.blur(),r(!0)}return}if(So(o.target)){a&&l==="s"&&o.preventDefault();return}if(a&&l==="z"){o.preventDefault(),o.shiftKey?i.redo():i.undo();return}if(!Uo&&a&&l==="y"){o.preventDefault(),i.redo();return}if(a&&l==="s"){o.preventDefault(),i.save?.();return}if(i.move&&o.altKey&&!a&&!o.shiftKey){const u=o.key==="ArrowLeft"?[0,-1]:o.key==="ArrowRight"?[0,1]:o.key==="ArrowUp"?[-1,0]:o.key==="ArrowDown"?[1,0]:void 0;if(u&&i.move(u[0],u[1])){o.preventDefault();return}}i.nudge&&!a&&!o.altKey&&!o.shiftKey&&(o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.preventDefault(),i.nudge(o.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Mr=(e,t,n=be.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}}}),Nr=(e=be.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),Bs={height:20,alignSelf:"center",mx:.5,my:0},Fs=(e,t=be.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"}}}),Ko={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Qf({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:o,onSave:i,savesTo:a="package",saveLabel:l,saveButton:u,actions:c,onAddTile:d,arrange:f,onExit:h,saveStatus:y}){const{theme:g}=be.usePublisherTheme(),w=k.edgeColor(g.cardBorder),x=k.hoverEdgeColor(g.cardBorder,g.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[f,d&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(k.AddIcon,{}),onClick:d,"aria-label":"Add tile",sx:Mr(w,x,g.ui),children:"Tile"}),d&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),m.jsx($.Tooltip,{title:`Undo (${cn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Nr(g.ui),children:m.jsx(yc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${cn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:Nr(g.ui),children:m.jsx(vc,{fontSize:"small"})})})}),(c||i||h)&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),c,i&&y&&m.jsx(xc,{...y}),i?m.jsx($.Tooltip,{title:s?`Save (${cn}S) · ${l??Ko[a]}`:l??Ko[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:u,variant:s?"contained":"outlined",disabled:!s||o,onClick:i,sx:{...Mr(w,x,g.ui),minWidth:88},children:o?"Saving…":s?"Save":"Saved"})})}):null,i&&m.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:o?"Saving":s?"Unsaved changes":"All changes saved"}),h&&m.jsx(k.SecondaryButton,{label:"Close",icon:m.jsx(k.CheckIcon,{}),onClick:h})]})}const Zf=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Qa={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map",combo_chart:"Bar and line"};function bc(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this tile's details":n==="unlisted"?"Not in the model's list, so its shape is unknown":void 0,s=e?.shape,o=a=>{if(t===a)return;if(a==="big_value")return e?.aggregateOnly===!0?void 0:s&&s.groupBys>0?"This view has a group by, so it is more than one row; big numbers need a view of totals only":r??"Needs results that are only totals (no group by)";if(a==="shape_map"||a==="segment_map")return e?.chart===a?void 0:r??"Needs a map chart set in the model";if(e?.chart===a)return;if(!s)return a==="combo_chart"?r??"Needs a view with a group by and exactly two totals: the first is drawn as bars, the second as a line":void 0;const l=`A ${Qa[a].toLowerCase()} chart`;switch(k.chartShapeGap(a,s)){case"no_x_axis":return Zf(l);case"combo_totals":return`A bar and line chart needs exactly two totals, the first drawn as bars and the second as a line; this view has ${s.totals}`;case"no_y_axis":return`This view has no total for the y-axis: ${l.toLowerCase()} needs at least one aggregate`;default:return}};return[{value:"default",label:"Default",hint:"As set in the model"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map","combo_chart"].map(a=>{const l=o(a);return{value:a,label:Qa[a],...l?{disabled:!0,reason:l}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Za(e){return e.description??k.readableName(e.name)}const Jf={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",combo_chart:"a bar and line chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},ls=(e,t)=>`${e}\0${t}`;function eh({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:o,onAddText:i,renderPreview:a}){const{theme:l}=be.usePublisherTheme(),u=l.ui,c=k.edgeColor(l.cardBorder),d=S.useMemo(()=>n?.sources??[],[n]),[f,h]=S.useState(""),[y,g]=S.useState(),[w,x]=S.useState(""),[p,v]=S.useState("default"),_=S.useRef(null),b=S.useMemo(()=>{const P=new Set(t.sources.map(z=>z.base));return[...d].sort((z,D)=>Number(P.has(D.name))-Number(P.has(z.name)))},[d,t]),E=b.filter(P=>P.views.length>0),T=b.filter(P=>P.views.length===0),M=S.useMemo(()=>new Map(E.flatMap(P=>P.views.map(z=>[ls(P.name,z.name),{source:P,view:z,key:ls(P.name,z.name)}]))),[E]),O=S.useMemo(()=>E.map(P=>({key:P.name,label:P.name,...P.description?{detail:P.description}:{},entries:P.views.map(z=>({key:ls(P.name,z.name),name:z.name,title:Za(z),...z.chart?{chart:z.chart}:{}}))})),[E]),C=y===void 0?void 0:M.get(y);S.useEffect(()=>{if(!e)return;h(""),x(""),v("default");const P=E[0]?.views[0];g(P&&E[0]?ls(E[0].name,P.name):void 0)},[e]);const A=C?[C.source.name,C.view.name].filter(P=>!me.isBareName(P)).map(P=>`"${P}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,R=C!==void 0&&A===void 0,L=C?Za(C.view):"",G=p!=="default"&&C?{chart:p,chartCarried:C.view.chart?[C.view.chart]:[]}:{},N=(P=C)=>{if(!P||![P.source.name,P.view.name].every(me.isBareName))return;const z=P.key===C?.key,D=k.writtenSpan(Math.ceil(r/2),r);o({base:P.source.name,modelPath:P.source.modelPath,...P.source.exporters?{exporters:P.source.exporters}:{},view:P.view.name,...z&&w.trim()?{label:w.trim()}:{},...z?G:{},...D!==void 0?{colspan:D}:{}})},X=C?bc(C.view,p).filter(P=>P.value!=="custom"&&P.disabled!==!0):[];return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:_,title:"Add a tile",description:"Pick what the tile shows from the model. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:i,sx:{mr:"auto"},children:"Add text instead"}),m.jsx($.Button,{onClick:s,children:"Cancel"}),m.jsx($.Button,{variant:"contained",disabled:!R,onClick:()=>N(),children:"Add tile"})]}),children:m.jsxs($.Box,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${c}`,borderBottom:`1px solid ${c}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx($.Box,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(k.ViewPicker,{groups:O,query:f,onQuery:h,picked:C?.key,onPick:P=>{g(P),v("default")},onTake:P=>N(M.get(P)),searchRef:_,empty:m.jsx($.Typography,{variant:"body2",sx:{color:l.tileTitle,p:2},children:n?"This package's models have nothing to put on a tile yet.":"The package's sources are still loading."}),footer:T.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:"," ",T.map(P=>P.name).join(", "),"."]})})}),m.jsx($.Box,{sx:P=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${P.palette.text.primary} 3%, ${P.palette.background.paper})`}),children:C?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:P=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:u.radius.tile,border:`1px solid ${c}`,bgcolor:P.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${P.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:C.source.name,modelPath:C.source.modelPath,view:C.view.name,label:w.trim()||L,...p!=="default"?G:{},givens:C.source.givens})}):m.jsxs($.Box,{sx:P=>({flex:1,border:`1px solid ${c}`,borderRadius:u.radius.tile,bgcolor:P.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(k.ChartGlyph,{chart:C.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[C.source.name," → ",C.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:L,value:w,onChange:P=>x(P.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs($.Box,{children:[m.jsx($.Typography,{component:"div",sx:{...u.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($.ToggleButtonGroup,{size:"small",exclusive:!0,value:p,"aria-label":"Chart",onChange:(P,z)=>{z!==null&&v(z)},sx:{...Fs(c,u),"& .MuiToggleButton-root":{...Fs(c,u)["& .MuiToggleButton-root"],textTransform:"none"}},children:X.map(P=>m.jsx($.ToggleButton,{value:P.value,children:P.label},P.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:C.view.chart?`The model sets ${Jf[C.view.chart]??"a chart"}.`:"The model sets 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."})})]})})}function th(e,t,{modelPath:n,textHeld:r,widths:s,insertAt:o}){t.modelPath&&!r&&(e.imports=k.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const i=wc(e,t.base),a=Vo(e,i.name,t.view);e.tiles.splice(o??e.tiles.length,0,{name:a,source:i.name,declaration:{kind:"reference",from:t.view},...s&&t.colspan!==void 0?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function wc(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 o=`${t}_tiles`;for(let a=2;s.has(o);a++)o=`${t}_tiles_${a}`;const i={name:o,base:t};return e.sources.push(i),i}function Vo(e,t,n){const r=new Set(e.tiles.filter(ce).filter(o=>o.source===t).map(o=>o.name));let s=`${n}_tile`;for(let o=2;r.has(s);o++)s=`${n}_tile_${o}`;return s}function Ws(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;case"query":return"It names a query, and a copy could not be told apart from it: the builder writes nothing about such a tile but its place.";default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function nh(e,t){const n=e.tiles[t];if(!n||!ce(n)||Ws(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:o,...i}=structuredClone(n);r={...i,name:Vo(e,n.source,n.declaration.from)}}else{const i=e.sources.find(a=>a.name===n.source)??wc(e,n.source,{unscoped:!0});r={name:Vo(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}const s=n.row!==void 0&&n.col!==void 0;return s&&(r={...r,row:(n.row??1)+Fr(n),col:n.col,...n.rowspan!==void 0?{rowspan:n.rowspan}:{}}),e.tiles.splice(t+1,0,r),s&&(e.tiles=Rt(e.tiles,e.columns??k.DEFAULT_COLUMNS,t+1)),t+1}const cs="self";function rh({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:o,onClose:i,onApply:a}){const{theme:l}=be.usePublisherTheme(),u=l.ui,[c,d]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(v=>v.source===n.name);d((n.dimensions??[]).map(v=>{const _=p.find(b=>b.name===v.name);return{name:v.name,expression:v.expression,to:_?.to??[],given:_?.given??""}}))},[e,n,t]);const f=(p,v)=>d(_=>_.map((b,E)=>{if(E!==p)return b;const T={...b};return v(T),T})),h=[cs,...s.filter(p=>p!==cs)],y=p=>p===cs?"This report":p,g=()=>{n&&(a(c.filter(p=>p.to.length>0).map(p=>({source:n.name,name:p.name,expression:p.expression,to:p.to,...p.given?{given:p.given}:{}}))),i())},w=k.edgeColor(l.cardBorder),x=(p,v)=>f(p,_=>{v?_.to=_.lastTo?.length?_.lastTo:[cs]:(_.lastTo=_.to,_.to=[])});return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.clickableCellsDialog}`,open:e,onClose:i,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[o&&m.jsxs($.Box,{component:"span",sx:{fontWeight:u.type.label.fontWeight},children:[o," ·"," "]}),"A click on a table cell sets a filter to its value, on this report or on the one it opens. Bars, lines and points on a chart do not respond to a click. Clicks work in the report, not while you edit it."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:i,children:"Cancel"}),m.jsx($.Button,{variant:"contained",onClick:g,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx($.Typography,{variant:"body2",sx:{color:l.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:c.map((p,v)=>{const _=p.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:_,onChange:b=>x(v,b.target.checked),slotProps:{input:{"aria-label":`${p.name} is clickable`}}}),m.jsxs($.Box,{sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...u.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:sh(p.name)}),m.jsxs($.Box,{title:p.expression,sx:{...u.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[p.name," is ",p.expression]})]}),_?m.jsxs($.Stack,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...u.type.control},children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx($.TextField,{select:!0,size:"small",value:p.to,inputProps:{"aria-label":`Where ${p.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.map(y).join(", ")},onChange:b=>f(v,E=>{const T=b.target.value,M=Array.isArray(T)?T:String(T).split(",").filter(Boolean);M.length===0&&(E.lastTo=E.to),E.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:p.to.includes(b),sx:{p:0,mr:1}}),m.jsx($.ListItemText,{primary:y(b)})]},b))}),m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs($.TextField,{select:!0,size:"small",value:p.given,inputProps:{"aria-label":`Control ${p.name} sets`},SelectProps:{displayEmpty:!0,renderValue:b=>b===""?p.name:String(b)},onChange:b=>f(v,E=>{E.given=b.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx($.MenuItem,{value:"",children:m.jsx($.ListItemText,{primary:p.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"})]},p.name)})})})}function sh(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const oh=k.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"})),ih=k.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"})),ah=k.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"})),lh=k.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"})),ch=k.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),dh=k.createSvgIcon(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function uh(e,t=[]){const n=new Map;for(const o of e.tiles)for(const i of ce(o)?o.filters??[]:[])n.set(i.given,(n.get(i.given)??0)+1);const r=[],s=new Set;for(const o of e.localGivens??[])s.add(o.name),r.push({name:o.name,...o.label===void 0?{}:{label:o.label},type:o.type,...o.suggest?{field:o.suggest.dimension}:{},origin:"dashboard",local:o,boundTiles:n.get(o.name)??0});for(const o of t)s.has(o.name)||(s.add(o.name),r.push({...o,origin:"model",boundTiles:n.get(o.name)??0}));for(const[o,i]of n)s.has(o)||r.push({name:o,origin:"model",boundTiles:i});return r}function Ns(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function fh(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function Ir(e,t){const n=fh(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 Xo(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 hh(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const ph=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function gh(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}`,o=me.isStrictName(s)?s:`${s}_FILTER`,i=new Set(t);if(!i.has(o))return o;for(let a=2;;a++)if(!i.has(`${o}_${a}`))return`${o}_${a}`}const mh=[{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 fr(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 Yo=e=>ce(e)&&!Hn(e)&&e.declaration.kind!=="opaque";function vh(e,t){return e.tiles.map(n=>{const r=(ce(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}:Ns(t.type)!==void 0?{op:Ns(t.type)}:{}}})}function yh(e,t,n){n.forEach((r,s)=>{const o=e.tiles[s];if(!o||!Yo(o))return;const i=(o.filters??[]).filter(l=>l.given!==t),a=r.include?[...i,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:i;a.length>0?o.filters=a:delete o.filters})}function xh(e,t){const n=(e.localGivens??[]).filter(o=>o.name!==t.name),r=(e.localGivens??[]).findIndex(o=>o.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function bh(e,t){for(const r of e.tiles){if(!ce(r))continue;const s=(r.filters??[]).filter(o=>o.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 Qo=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function wh({open:e,document:t,control:n,available:r,takenNames:s=[],fieldsFor:o,onApply:i}){const a=S.useRef(n);e&&(a.current=n);const l=e?n:a.current,u=l!==void 0,[c,d]=S.useState({kind:"new"}),[f,h]=S.useState(""),[y,g]=S.useState("select"),[w,x]=S.useState(""),[p,v]=S.useState(""),[_,b]=S.useState([]),[E,T]=S.useState(!1),[M,O]=S.useState(!1),C=j=>t.sources.find(F=>F.name===j.source)?.base??j.source;S.useEffect(()=>{if(e)if(O(n!==void 0),n){d({kind:"existing",name:n.name}),h(n.label??"");const j=vh(t,n);b(j);const F=j.filter(Y=>Y.include),U=new Set(F.map(Y=>Y.field));v(U.size===1?F[0].field:n.field??""),T(U.size>1)}else d({kind:"new"}),h(""),g("select"),v(""),x(new Date().toISOString().slice(0,10)),b(t.tiles.map(j=>({include:Yo(j),field:""}))),T(!1)},[e,n,t]);const A=S.useMemo(()=>[...(t.localGivens??[]).map(j=>j.name),...r.map(j=>j.name),...s],[t,r,s]),R=S.useMemo(()=>p.trim()?gh(p.trim(),A):"",[p,A]),L=c.kind==="existing"?n??r.find(j=>j.name===c.name):R?{name:R,type:fr({name:R,label:f,kind:y,field:p}).type}:void 0,G=L?.type!==void 0&&!L.type.startsWith("filter<"),N=_.find(j=>j.include)?.op??Ns(L?.type),X=(j,F)=>{O(!0),b(U=>U.map((Y,Se)=>Se===j?{...Y,...F}:Y))},P=j=>{O(!0),b(F=>F.map(U=>({...U,op:j})))},z=j=>{const F=Ns(j);b(U=>U.map(({op:Y,...Se})=>F?{...Se,op:F}:Se))},D=j=>{O(!0),d({kind:"existing",name:j.name}),v(j.field??""),z(j.type)},I=j=>{O(!0),g(j),z(fr({name:"X",label:f,kind:j,field:p}).type)},B=t.tiles.map(Yo),q=B.filter(Boolean).length,H=_.filter((j,F)=>j.include&&B[F]).length,K=t.tiles.filter((j,F)=>(_[F]?.include??!1)&&B[F]&&ce(j)),te=K.length>0?K:t.tiles.filter((j,F)=>B[F]&&ce(j)),ye=S.useMemo(()=>{const j=new Map;let F=!1;for(const U of te){const Y=o?.(U);if(Y){F=!0;for(const Se of Y)j.has(Se.name)||j.set(Se.name,Se)}}return F?[...j.values()]:void 0},[_,t.tiles,o]),_e=(()=>{const j=p.trim();for(const F of K){const U=o?.(F);if(!U||U.some(Y=>Y.name===j))return C(F)}return K[0]?C(K[0]):t.sources[0]?.base})(),re=j=>{O(!0),b(F=>F.map((U,Y)=>({...U,include:j&&B[Y]})))},De=S.useMemo(()=>E?_:_.map(j=>({...j,field:p})),[E,_,p]),ge=j=>{for(const F of te){const U=o?.(F)?.find(Y=>Y.name===j.trim());if(U?.type)return U.type}},ve=j=>Ir(L?.type,j.type),Ge=(j,F)=>{if(j.trim()==="")return"Pick the field this filter compares.";const U=F?o?.(F):void 0;if(!U)return;const Y=U.find(Se=>Se.name===j.trim());if(!Y)return`Not a field of ${F?C(F):"the tiles' source"}.`;if(Y.type&&!Ir(L?.type,Y.type))return`${j.trim()} is ${Xo(Y.type)}; this filter compares ${Xo(L?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},Z=j=>{if(O(!0),v(j),u||c.kind!=="new")return;const F=ge(j),U=fr({name:"X",label:f,kind:y,field:j}).type;F&&!Ir(U,F)&&I(hh(F))},Xe=j=>{const F=t.tiles[j];return F&&ce(F)?F:void 0},ke=De.map((j,F)=>j.include&&B[F]?Ge(j.field,Xe(F)):void 0),ue=ke.every(j=>j===void 0),Oe=M?ke:ke.map(()=>{}),Ae=M&&!E&&H>0?K.map(j=>Ge(p,j)).find(Boolean):void 0,ie=L!==void 0&&ue&&(c.kind==="existing"||p.trim()!==""&&R!==""),qe=()=>{if(!(!L||!ie))if(c.kind==="new")i(L.name,De,fr({name:L.name,label:f.trim()||Qo(L.name),kind:y,field:p.trim(),..._e?{source:_e}:{},...w?{dateDefault:w}:{}}));else if(n?.origin==="dashboard"&&n.local){const j=f.trim(),F=j!==(n.local.label??"");i(L.name,De,F?{...n.local,...j?{label:j}:{}}:void 0)}else i(L.name,De)},Ye=u&&l.origin==="model";return{editing:u,shown:l,fromModel:Ye,source:c,setSource:d,label:f,setLabel:h,kind:y,dateDefault:w,setDateDefault:x,field:p,rows:_,setRows:b,perTile:E,setPerTile:T,newName:R,target:L,valueTyped:G,commonOp:N,setRow:X,setCommonOp:P,pickExisting:D,pickKind:I,bindable:B,bindableCount:q,included:H,commonFields:ye,setAll:re,accepts:ve,pickField:Z,rowProblems:Oe,commonProblem:Ae,canApply:ie,apply:qe}}function Ja({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:o,error:i,helperText:a,disabled:l,autoFocus:u,placeholder:c,inputRef:d,sx:f}){const h=S.useMemo(()=>(n??[]).filter(g=>r?.(g)??!0).map(g=>g.name),[n,r]),y=S.useMemo(()=>new Map((n??[]).map(g=>[g.name,g.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(g,w)=>t(w),value:e,onChange:(g,w)=>t(typeof w=="string"?w:""),disabled:l,disableClearable:!0,renderOption:(g,w)=>S.createElement("li",{...g,key:w},m.jsx(tl,{type:y.get(w)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:w})),renderInput:g=>m.jsx($.TextField,{...g,label:s,placeholder:c,autoFocus:u,...d?{inputRef:d}:{},error:i,helperText:a,InputLabelProps:{...g.InputLabelProps,shrink:!0},InputProps:{...g.InputProps,startAdornment:y.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(tl,{type:y.get(e.trim())})}):void 0},inputProps:{...g.inputProps,"aria-label":o}}),sx:f})}const _h=e=>e&&ce(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:e&&ce(e)&&e.declaration.kind==="query"?{label:"Not bindable",reason:"It names a query, whose filters live in that query's own definition."}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function kh({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:o,onClose:i,onApply:a,onRemove:l}){const{theme:u}=be.usePublisherTheme(),c=u.ui,{editing:d,shown:f,fromModel:h,source:y,setSource:g,label:w,setLabel:x,kind:p,dateDefault:v,setDateDefault:_,field:b,rows:E,setRows:T,perTile:M,setPerTile:O,newName:C,target:A,valueTyped:R,commonOp:L,setRow:G,setCommonOp:N,pickExisting:X,pickKind:P,bindable:z,bindableCount:D,included:I,commonFields:B,setAll:q,accepts:H,pickField:K,rowProblems:te,commonProblem:ye,canApply:_e,apply:re}=wh({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:o,onApply:a}),De=S.useRef(null),ge=k.edgeColor(u.cardBorder),ve=k.hoverEdgeColor(u.cardBorder,u.tileTitle),[Ge,Z]=S.useState(!1),[Xe,ke]=S.useState(!1);S.useEffect(()=>{e?ke(!0):Z(!1)},[e]),S.useEffect(()=>{Xe&&(ke(!1),Z(d&&I<D))},[Xe]),S.useEffect(()=>{M&&Z(!0)},[M]);const ue=B?.find(j=>j.name===b.trim())?.type,Oe=j=>{if(!ue)return;const F=fr({name:"X",label:w,kind:j,field:b}).type;return Ir(F,ue)?void 0:`${b.trim()} is ${Xo(ue)}, which this control cannot filter.`},Ae=w.trim()||(C?Qo(C):"Filter"),ie=p==="number"?"Any":p==="date"?v?new Date(`${v}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",qe={...Fs(ge,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...Fs(ge,c)["& .MuiToggleButton-root"],textTransform:"none"}},Ye=(j,F,U)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:j??">=",onChange:Y=>F(Y.target.value),inputProps:{"aria-label":U},sx:{width:130},children:ph.filter(Y=>Y.op!=="~").map(Y=>m.jsx($.MenuItem,{value:Y.op,children:Y.label},Y.op))});return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.filterDialog}`,open:e,onClose:i,...d?{}:{initialFocus:De},title:d?f.label??f.name:"Add a filter",description:d?m.jsxs(m.Fragment,{children:[m.jsxs($.Box,{component:"span",sx:{fontFamily:c.font.mono},children:["$",f.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:[d&&m.jsx($.Button,{color:"error",startIcon:m.jsx(k.DeleteOutlineIcon,{}),onClick:()=>l(f.name),sx:j=>({mr:"auto",color:k.dangerTextColor(j)}),children:"Remove filter"}),m.jsx($.Button,{onClick:i,children:"Cancel"}),m.jsx($.Tooltip,{title:_e||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:re,disabled:!_e,children:d?"Apply":"Add filter"})})})]}),children:m.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!d&&r.length>0&&m.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:y.kind,onChange:(j,F)=>{F==="new"?g({kind:"new"}):F==="existing"&&r[0]&&X(r[0])},"aria-label":"Where the filter comes from",sx:qe,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&y.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:y.name,onChange:j=>{const F=r.find(U=>U.name===j.target.value);F&&X(F)},children:r.map(j=>m.jsxs($.MenuItem,{value:j.name,children:[j.label??j.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",j.name]})]},j.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(Ja,{value:b,onChange:K,fields:B,accepts:H,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:De,error:ye!==void 0,helperText:ye??(!d&&C?`Declared as $${C}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:C?Qo(C):"",value:w,onChange:j=>x(j.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),R&&!M&&Ye(L,N,"Comparison"),!d&&y.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(el,{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:mh.map(j=>{const F=j.kind===p,U=Oe(j.kind);return m.jsx($.Tooltip,{title:U??j.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":F,"aria-label":j.label,"aria-disabled":U!==void 0,onClick:()=>{U===void 0&&P(j.kind)},sx:Y=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${F?u.accent:ge}`,boxShadow:F?`0 0 0 1px ${u.accent}`:"none",bgcolor:F?`color-mix(in srgb, ${u.accent} 6%, ${Y.palette.background.paper})`:Y.palette.background.paper,color:F?u.accent:Y.palette.text.secondary,opacity:U?.45:1,cursor:U?"default":"pointer",transition:`border-color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,"&:hover":U||F?{}:{borderColor:ve}}),children:[m.jsx($h,{kind:j.kind}),m.jsx($.Box,{component:"span",sx:{...c.type.caption,fontWeight:F?600:500,color:F?u.accent:"text.primary",textAlign:"center"},children:Sh[j.kind]})]})},j.kind)})}),p==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:v,onChange:j=>_(j.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${ge}`,borderRadius:c.radius.tile,overflow:"hidden"},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(dh,{"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:c.type.label.fontWeight},children:I===D&&D>0?`Applies to all ${I} tile${I===1?"":"s"}`:`Applies to ${I} of ${D} tile${D===1?"":"s"}`}),!M&&b.trim()!==""&&I>0&&m.jsxs($.Box,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx($.Box,{component:"span",sx:{...c.type.code},children:b.trim()})]})]}),!M&&m.jsx($.Button,{size:"small","aria-expanded":Ge,onClick:()=>Z(j=>!j),children:Ge?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:Ge,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${ge}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:D>0&&I===D,indeterminate:I>0&&I<D,disabled:D===0,onChange:j=>q(j.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||T(j=>j.map(F=>({...F,field:b}))),O(j=>!j)},children:M?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:M?1:0},children:t.tiles.map((j,F)=>{if(!ce(j))return null;const U=E[F],Y=j.label??j.name,Se=M?te[F]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:M?"flex-start":"center",opacity:z[F]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!z[F],checked:(U?.include??!1)&&z[F],inputProps:{"aria-label":`Filter ${Y}`},onChange:we=>G(F,{include:we.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:M?1:0},noWrap:!0,children:Y}),z[F]?M&&m.jsxs(m.Fragment,{children:[R&&Ye(U?.op,we=>G(F,{op:we}),`Comparison for ${Y}`),m.jsx(Ja,{value:U?.field??"",onChange:we=>G(F,{field:we}),fields:o?.(j),accepts:H,label:"Field",ariaLabel:`Field for ${Y}`,disabled:!U?.include,error:Se!==void 0,helperText:Se,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:u.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:_h(t.tiles[F]).reason})]},fe(j))})})]})})]}),I===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(el,{children:"Preview"}),m.jsx($.Box,{sx:j=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:j.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:j=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${ge}`,bgcolor:j.palette.background.paper,...c.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:Ae}),m.jsx($.Box,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:ie}),m.jsx(k.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function el({children:e}){const t=be.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const Sh={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function $h({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(oh,{sx:t});case"multiselect":return m.jsx(ih,{sx:t});case"text":return m.jsx(ch,{sx:t});case"number":return m.jsx(lh,{sx:t});case"date":return m.jsx(ah,{sx:t})}}function tl({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=be.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 nl=k.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function _c(e,t,n,r){const[s,o]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&o(structuredClone(e))},[t,e]),{draft:s,patch:c=>o(d=>{if(d===void 0)return d;const f=structuredClone(d);return c(f),f}),apply:c=>{if(s===void 0)return;const d=structuredClone(s);c(d),o(d),JSON.stringify(d)!==JSON.stringify(e)&&n(d)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>o(void 0)}}const Th=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.`,Eh=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Ch="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",Oh="Declared on its source, so its chart is set in the model.",Mh="It names a query, so its chart is set where that query is declared.";function Ih({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:o,duplicateBlocked:i,view:a,viewStatus:l}){const{theme:u}=be.usePublisherTheme(),c=u.ui,{draft:d,apply:f,patch:h,close:y}=_c(t,e!==null,r,n),[g,w]=S.useState(void 0),x=d!==void 0&&ce(d)?d:void 0,p=x!==void 0&&!Hn(x),v=D=>f(I=>{ce(I)&&D(I)}),_=S.useRef(void 0),b=S.useRef(null),E=e!==null;S.useEffect(()=>{E?_.current=t&&ce(t)?t.chart:void 0:w(void 0)},[E]);const T=x?.chart??"default",M=bc(a,T,l),O=x?x.declaration.kind==="query"?Mh:p?x.chart==="custom"?Th(x.chartLines):void 0:Oh:void 0,C=D=>v(I=>{const B=_.current;D===(B??"default")?(B===void 0?delete I.chart:I.chart=B,delete I.chartCarried):(I.chart=D,a?I.chartCarried=a.chart?[a.chart]:[]:delete I.chartCarried)}),A=p?s?void 0:"Its source declares no dimension a click could filter by.":void 0,R=T==="default"?a?.chart:T,L=R!==void 0&&Eh.has(R)?Ch:void 0,G=D=>I=>w({kind:D,anchor:I.currentTarget}),N=O??(R===void 0||!Dh.has(R)?"Only a bar, line, scatter or bar and line chart has a color to set.":void 0),X=Array.from(new Set(u.series.map(k.seriesColorFrom).filter(D=>D!==void 0))).slice(0,8),P=D=>v(I=>{D===void 0?delete I.color:I.color=D.toLowerCase()}),z=(D,I,B)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:D,...B?{secondary:B}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),I&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:I})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:k.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:y,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":x?dt(x):"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:c.radius.menu,border:`1px solid ${k.edgeColor(u.cardBorder)}`,boxShadow:c.shadow.menu}}},children:[x&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":g?.kind==="chart",disabled:O!==void 0,onClick:G("chart"),onKeyDown:D=>{D.key==="ArrowRight"&&O===void 0&&w({kind:"chart",anchor:D.currentTarget})},children:[z("Chart",O?void 0:M.find(D=>D.value===T)?.label,O),m.jsx(nl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),x&&O===void 0&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":g?.kind==="color",disabled:N!==void 0,onClick:G("color"),onKeyDown:D=>{D.key==="ArrowRight"&&N===void 0&&w({kind:"color",anchor:D.currentTarget})},children:[z("Color",N?void 0:x.color??"Theme",N),!N&&m.jsx($o,{color:x.color??u.series[0],trailing:!0}),m.jsx(nl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),p&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:A!==void 0,onClick:()=>{y(),s?.()},children:z("Clickable cells…",void 0,A??L)}),x&&o&&m.jsx($.MenuItem,{disabled:i!==void 0,onClick:()=>{y(),o()},children:z("Duplicate",void 0,i)}),x?.declaration.kind==="opaque"&&m.jsxs($.Typography,{variant:"body2",sx:{color:u.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",x.declaration.why,", so a filter has no single place to go."]}),x&&m.jsx($.Divider,{}),x&&m.jsx($.Box,{"aria-hidden":!0,sx:{px:2,py:.5,...c.type.code,color:"text.secondary"},children:dt(x).replace("->","→")})]}),m.jsx($.Menu,{className:k.reportClasses.menu,open:g?.kind==="chart",anchorEl:g?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:D=>{D.key==="ArrowLeft"&&(D.preventDefault(),w(void 0))}},children:M.filter(D=>D.value!=="custom").map(D=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":D.value===T,disabled:D.disabled===!0,onClick:()=>{C(D.value),w(void 0)},children:[m.jsx($.ListItemText,{primary:D.label,...D.reason??D.hint?{secondary:D.reason??D.hint}:{}}),D.value===T&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:u.accent}})})]},D.value))}),m.jsxs($.Menu,{className:k.reportClasses.menu,open:g?.kind==="color",anchorEl:g?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,"aria-label":"Color",onKeyDown:D=>{D.key==="ArrowLeft"&&(D.preventDefault(),w(void 0))}},children:[m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===void 0,onClick:()=>{P(void 0),w(void 0)},children:[m.jsx($o,{color:u.series[0]}),m.jsx($.ListItemText,{primary:"Theme",secondary:"The page's own colors"}),x?.color===void 0&&m.jsx(rl,{color:u.accent})]}),X.map(D=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===D.toLowerCase(),onClick:()=>{P(D),w(void 0)},children:[m.jsx($o,{color:D}),m.jsx($.ListItemText,{primary:D.toLowerCase()}),x?.color===D.toLowerCase()&&m.jsx(rl,{color:u.accent})]},D)),m.jsx($.Divider,{}),m.jsxs($.MenuItem,{component:"label","aria-checked":x?.color!==void 0&&!X.some(D=>D.toLowerCase()===x.color),role:"menuitemradio",onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),b.current?.click())},children:[m.jsx("input",{ref:b,type:"color","aria-label":"Other color",value:x?.color??jh(u.series[0]),onChange:D=>{const I=D.target.value;k.isSeriesColor(I)&&h(B=>{ce(B)&&(B.color=I.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx($.ListItemText,{primary:"Other color…"})]})]})]})}const Dh=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),jh=e=>(e&&k.seriesColorFrom(e))??"#000000";function $o({color:e,trailing:t=!1}){return m.jsx($.Box,{"aria-hidden":!0,"data-swatch":t?"trailing":"leading",sx:{width:14,height:14,borderRadius:"3px",bgcolor:e,border:"1px solid rgba(0,0,0,0.15)",...t?{ml:1}:{mr:1.5},flex:"none"}})}function rl({color:e}){return m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:e}})})}const co=e=>e.label??k.tileTitle(dt(e));function Ph({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:o,drillSource:i,setDrillSource:a,exitDialog:l,renderViewPreview:u,takenGivenNames:c}){const{filterDialog:d,setFilterDialog:f}=s,{menu:h,setMenu:y}=o,[g,w]=S.useState(),x=h===void 0?void 0:e.document.tiles[h.index],p=x&&ce(x)?x:void 0,v=(()=>{if(!p||!t)return;const _=t.documentViews?.get(p.source??"")?.get(p.name);if(_&&e.document.sources.some(T=>T.name===p.source))return _;if(p.declaration.kind==="inline"||p.declaration.kind==="opaque")return;const b=e.document.sources.find(T=>T.name===p.source)?.base??p.source,E=p.declaration.kind==="reference"?p.declaration.from:p.name;return t.sources.find(T=>T.name===b)?.views.find(T=>T.name===E)})();return m.jsxs(m.Fragment,{children:[m.jsx(kh,{open:d!==void 0,document:e.document,...d?.control?{control:d.control}:{},available:s.available,...c?{takenNames:c}:{},...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>f(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),m.jsx(Ih,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>y(void 0),onCommit:_=>{const b=h?.index;if(b===void 0)return;const E=Kf(_);e.update(T=>{T.tiles[b]=E,E!==_&&k.isPlaced(T.tiles)&&(T.tiles=Rt(T.tiles,n,b))})},view:v,...v===void 0&&p?{viewStatus:t?"unlisted":"loading"}:{},onDuplicate:()=>{h&&o.duplicate(h.index)},...p&&Ws(p)!==void 0?{duplicateBlocked:Ws(p)}:{},...(e.document.sources.find(_=>_.name===p?.source)?.dimensions?.length??0)>0?{onDrills:()=>{w(p?co(p):void 0),a(p?.source)}}:{}}),m.jsx(rh,{open:i!==void 0,document:e.document,source:e.document.sources.find(_=>_.name===i),givenNames:s.controlList.map(_=>_.name),dashboards:r??[],...g?{tileLabel:g}:{},onClose:()=>a(void 0),onApply:_=>e.update(b=>{const T=[...(b.drills??[]).filter(M=>M.source!==i),..._];T.length===0?delete b.drills:b.drills=T})}),m.jsx(k.UnsavedChangesDialog,{...l}),m.jsx(eh,{open:o.addingTile,document:e.document,catalog:t,columns:n,onClose:o.closeAdd,onAdd:o.addTile,onAddText:o.addText,...u?{renderPreview:u}:{}})]})}var Rh=Symbol.for("preact-signals");function uo(){if(jt>1)jt--;else{var e,t=!1;for((function(){var s=Gs;for(Gs=void 0;s!==void 0;){var o=s.S;if(o.v===s.v)for(var i=o.t;i!==void 0;i=i.x)i.i===s.i&&(i.i=o.i);s=s.o}})();jr!==void 0;){var n=jr;for(jr=void 0,zs++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Sc(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(zs=0,jt--,t)throw e}}function Re(e){if(jt>0)return e();Zo=++Ah,jt++;try{return e()}finally{uo()}}var Dr,Te=void 0;function ae(e){var t=Te,n=Dr;Te=void 0,Dr=void 0;try{return e()}finally{Te=t,Dr=n}}var jr=void 0,jt=0,zs=0,Ah=0,Zo=0,Gs=void 0,Hs=0;function kc(e){if(Te!==void 0){var t=e.n;if(t===void 0||t.t!==Te)return t={i:0,S:e,p:Te.s,n:void 0,t:Te,e:void 0,x:void 0,r:t},Te.s!==void 0&&(Te.s.n=t),Te.s=t,e.n=t,32&Te.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=Te.s,t.n=void 0,Te.s.n=t,Te.s=t),t}}function it(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}it.prototype.brand=Rh;it.prototype.h=function(){return!0};it.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:ae(function(){var r;(r=t.W)==null||r.call(t)}))};it.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&&ae(function(){var s;(s=t.Z)==null||s.call(t)}))}};it.prototype.subscribe=function(e){var t=this;return yt(function(){var n=t.value;ae(function(){return e(n)})},{name:"sub"})};it.prototype.valueOf=function(){return this.value};it.prototype.toString=function(){return this.value+""};it.prototype.toJSON=function(){return this.value};it.prototype.peek=function(){var e=this;return ae(function(){return e.value})};Object.defineProperty(it.prototype,"value",{get:function(){var e=kc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(zs>100)throw new Error("Cycle detected");(function(n){jt!==0&&zs===0&&n.l!==Zo&&(n.l=Zo,Gs={S:n,v:n.v,i:n.i,o:Gs})})(this),this.v=e,this.i++,Hs++,jt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{uo()}}}});function qn(e,t){return new it(e,t)}function Sc(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 $c(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 Tc(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function fn(e,t){it.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Hs-1,this.f=4}fn.prototype=new it;fn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Hs))return!0;if(this.g=Hs,this.f|=1,this.i>0&&!Sc(this))return this.f&=-2,!0;var e=Te;try{$c(this),Te=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 Te=e,Tc(this),this.f&=-2,!0};fn.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}it.prototype.S.call(this,e)};fn.prototype.U=function(e){if(this.t!==void 0&&(it.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};fn.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(fn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=kc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function sl(e,t){return new fn(e,t)}function Ec(e){var t=e.m;if(e.m=void 0,typeof t=="function"){jt++;var n=Te;Te=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Wi(e),r}finally{Te=n,uo()}}}function Wi(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Ec(e)}function Lh(e){if(Te!==this)throw new Error("Out-of-order effect");Tc(this),Te=e,this.f&=-2,8&this.f&&Wi(this),uo()}function Un(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Dr&&Dr.push(this)}Un.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()}};Un.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ec(this),$c(this),jt++;var e=Te;return Te=this,Lh.bind(this,e)};Un.prototype.N=function(){2&this.f||(this.f|=2,this.u=jr,jr=this)};Un.prototype.d=function(){this.f|=8,1&this.f||Wi(this)};Un.prototype.dispose=function(){this.d()};function yt(e,t){var n=new Un(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Bh=Object.create,Ni=Object.defineProperty,Fh=Object.defineProperties,Wh=Object.getOwnPropertyDescriptor,Nh=Object.getOwnPropertyDescriptors,ol=Object.getOwnPropertySymbols,zh=Object.prototype.hasOwnProperty,Gh=Object.prototype.propertyIsEnumerable,Hh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Kn=e=>{throw TypeError(e)},Jo=(e,t,n)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qh=(e,t)=>{for(var n in t||(t={}))zh.call(t,n)&&Jo(e,n,t[n]);if(ol)for(var n of ol(t))Gh.call(t,n)&&Jo(e,n,t[n]);return e},Uh=(e,t)=>Fh(e,Nh(t)),il=(e,t)=>Ni(e,"name",{value:t,configurable:!0}),Kh=e=>{var t;return[,,,Bh((t=void 0)!=null?t:null)]},Cc=["class","method","getter","setter","accessor","field","value","get","set"],hr=e=>e!==void 0&&typeof e!="function"?Kn("Function expected"):e,Vh=(e,t,n,r,s)=>({kind:Cc[e],name:t,metadata:r,addInitializer:o=>n._?Kn("Already initialized"):s.push(hr(o||null))}),Oc=(e,t)=>Jo(t,Hh("metadata"),e[3]),Qt=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Vn=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=Cc[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&Wh(d<4?s:{get[n](){return pt(this,o)},set[n](_){return Nt(this,o,_)}},n));d?h&&d<4&&il(o,(d>2?"set ":d>1?"get ":"")+n):il(s,n);for(var v=r.length-1;v>=0;v--)u=Vh(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>Xh(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?pt:Yh)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>Nt(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?hr(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?Kn("Object expected"):(hr(i=a.get)&&(p.get=i),hr(i=a.set)&&(p.set=i),hr(i=a.init)&&w.unshift(i));return d||Oc(e,s),p&&Ni(s,n,p),h?d^4?o:p:s},zi=(e,t,n)=>t.has(e)||Kn("Cannot "+n),Xh=(e,t)=>Object(t)!==t?Kn('Cannot use the "in" operator on this value'):e.has(t),pt=(e,t,n)=>(zi(e,t,"read from private field"),n?n.call(e):t.get(e)),pr=(e,t,n)=>t.has(e)?Kn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Nt=(e,t,n,r)=>(zi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Yh=(e,t,n)=>(zi(e,t,"access private method"),n);function ei(e,t){if(t){let n;return sl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return sl(e)}function wt(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)=>!wt(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(o=>!wt(e[o],t[o]))}return!1}function le({get:e},t){return{init(n){return qn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function We(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ei(e.bind(this)),n.set(this,r)),r.value}}function To(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,Uh(qh({},s),{enumerable:e}))})}}function Zr(...e){const t=e.map(n=>yt(n));return()=>t.forEach(n=>n())}var Mc,Ic,Dc,jc,Pc,Rc,nt,Gi,Eo,ti,ni,Je,Hi,Co,Ac,ri,qi,Oo,si,oi;Rc=[le],Pc=[le],jc=[le],Dc=[To()],Ic=[To()],Mc=[To()];var hn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Qt(nt,5,this),pr(this,Je),pr(this,Gi,Qt(nt,8,this)),Qt(nt,11,this),pr(this,Hi,Qt(nt,12,this)),Qt(nt,15,this),pr(this,qi,Qt(nt,16,this)),Qt(nt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return pt(this,Je,si)}get initial(){return pt(this,Je,ti)}get previous(){return pt(this,Je,Ac)}set current(e){const t=ae(()=>pt(this,Je,si));e&&t&&this.equals(t,e)||Re(()=>{pt(this,Je,ti)||Nt(this,Je,e,ni),Nt(this,Je,t,ri),Nt(this,Je,e,oi)})}reset(e=this.defaultValue){Re(()=>{Nt(this,Je,void 0,ri),Nt(this,Je,e,ni),Nt(this,Je,e,oi)})}};nt=Kh();Gi=new WeakMap;Je=new WeakSet;Hi=new WeakMap;qi=new WeakMap;Eo=Vn(nt,20,"#initial",Rc,Je,Gi),ti=Eo.get,ni=Eo.set;Co=Vn(nt,20,"#previous",Pc,Je,Hi),Ac=Co.get,ri=Co.set;Oo=Vn(nt,20,"#current",jc,Je,qi),si=Oo.get,oi=Oo.set;Vn(nt,2,"current",Dc,hn);Vn(nt,2,"initial",Ic,hn);Vn(nt,2,"previous",Mc,hn);Oc(nt,hn);function Mo(e){return ae(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Zt,Qh=class{constructor(){pr(this,Zt,new WeakMap)}get(e,t){var n;return e?(n=pt(this,Zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return pt(this,Zt).has(e)||pt(this,Zt).set(e,new Map),(r=pt(this,Zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=pt(this,Zt).get(e))==null?void 0:t.clear():void 0}};Zt=new WeakMap;var Zh=Object.create,Lc=Object.defineProperty,Jh=Object.getOwnPropertyDescriptor,al=Object.getOwnPropertySymbols,ep=Object.prototype.hasOwnProperty,tp=Object.prototype.propertyIsEnumerable,Bc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),fo=e=>{throw TypeError(e)},ll=Math.pow,ii=(e,t,n)=>t in e?Lc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,np=(e,t)=>{for(var n in t||(t={}))ep.call(t,n)&&ii(e,n,t[n]);if(al)for(var n of al(t))tp.call(t,n)&&ii(e,n,t[n]);return e},rp=e=>{var t;return[,,,Zh((t=e?.[Bc("metadata")])!=null?t:null)]},Fc=["class","method","getter","setter","accessor","field","value","get","set"],Wc=e=>e!==void 0&&typeof e!="function"?fo("Function expected"):e,sp=(e,t,n,r,s)=>({kind:Fc[e],name:t,metadata:r,addInitializer:o=>n._?fo("Already initialized"):s.push(Wc(o||null))}),op=(e,t)=>ii(t,Bc("metadata"),e[3]),ip=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Nc=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,y=Fc[c+5],g=e[h]||(e[h]=[]),w=(s=s.prototype,Jh(s,n)),x=r.length-1;x>=0;x--)l=sp(c,n,a={},e[3],g),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(w[y],l),a._=1,Wc(i)&&(w[y]=i);return w&&Lc(s,n,w),s},zc=(e,t,n)=>t.has(e)||fo("Cannot "+n),ap=(e,t,n)=>(zc(e,t,"read from private field"),t.get(e)),lp=(e,t,n)=>t.has(e)?fo("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),cp=(e,t,n,r)=>(zc(e,t,"write to private field"),t.set(e,n),n),gt=class ai{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ai(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 ai(t,n)}},Ct=class Jt{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:o,height:i,scale:a}=this,l=new Jt(s+t,r+n,o,i);return l.scale=np({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:o,bottom:i}=this;return{width:t,height:n,left:r,top:s,right:o,bottom:i}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new gt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Jt))return!1;const{left:n,top:r,width:s,height:o}=this;return n===t.left&&r===t.top&&s===t.width&&o===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:o}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=o}intersectionArea(t){return t instanceof Jt?dp(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 Jt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(o,i)=>{const a=r[i],l=i==="x"?o.left:o.top,u=i==="x"?o.width:o.height;return a=="start"?l:a=="end"?l+u:l+u/2};return gt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Jt.from(t).intersectionRatio(Jt.from(n))}};function dp(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),o=Math.min(t.top+t.height,e.top+e.height),i=s-r,a=o-n;return r<s&&n<o?i*a:0}var Gc,Hc,li,_s,Jr,ho=class extends(li=hn,Hc=[We],Gc=[We],li){constructor(t){const n=gt.from(t);super(n,(r,s)=>gt.equals(r,s)),ip(Jr,5,this),lp(this,_s,0),this.velocity={x:0,y:0}}get delta(){return gt.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=gt.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),i=o-ap(this,_s),a=l=>Math.round(l/i*100);Re(()=>{cp(this,_s,o),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(gt.from(t)),this.velocity={x:0,y:0}}};Jr=rp(li);_s=new WeakMap;Nc(Jr,2,"delta",Hc,ho);Nc(Jr,2,"direction",Gc,ho);op(Jr,ho);function ci({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(ll(r,2)+ll(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 qc=(e=>(e.Horizontal="x",e.Vertical="y",e))(qc||{}),Uc=Object.values(qc),up=Object.create,Ui=Object.defineProperty,fp=Object.defineProperties,hp=Object.getOwnPropertyDescriptor,pp=Object.getOwnPropertyDescriptors,qs=Object.getOwnPropertySymbols,Kc=Object.prototype.hasOwnProperty,Vc=Object.prototype.propertyIsEnumerable,Xc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Xn=e=>{throw TypeError(e)},di=(e,t,n)=>t in e?Ui(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ki=(e,t)=>{for(var n in t||(t={}))Kc.call(t,n)&&di(e,n,t[n]);if(qs)for(var n of qs(t))Vc.call(t,n)&&di(e,n,t[n]);return e},Vi=(e,t)=>fp(e,pp(t)),cl=(e,t)=>Ui(e,"name",{value:t,configurable:!0}),Yc=(e,t)=>{var n={};for(var r in e)Kc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&qs)for(var r of qs(e))t.indexOf(r)<0&&Vc.call(e,r)&&(n[r]=e[r]);return n},Yn=e=>{var t;return[,,,up((t=e?.[Xc("metadata")])!=null?t:null)]},Qc=["class","method","getter","setter","accessor","field","value","get","set"],gr=e=>e!==void 0&&typeof e!="function"?Xn("Function expected"):e,gp=(e,t,n,r,s)=>({kind:Qc[e],name:t,metadata:r,addInitializer:o=>n._?Xn("Already initialized"):s.push(gr(o||null))}),pn=(e,t)=>di(t,Xc("metadata"),e[3]),ee=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},de=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=Qc[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&hp(d<4?s:{get[n](){return Fe(this,o)},set[n](_){return ut(this,o,_)}},n));d?h&&d<4&&cl(o,(d>2?"set ":d>1?"get ":"")+n):cl(s,n);for(var v=r.length-1;v>=0;v--)u=gp(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>mp(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?Fe:Zc)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>ut(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?gr(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?Xn("Object expected"):(gr(i=a.get)&&(p.get=i),gr(i=a.set)&&(p.set=i),gr(i=a.init)&&w.unshift(i));return d||pn(e,s),p&&Ui(s,n,p),h?d^4?o:p:s},Xi=(e,t,n)=>t.has(e)||Xn("Cannot "+n),mp=(e,t)=>Object(t)!==t?Xn('Cannot use the "in" operator on this value'):e.has(t),Fe=(e,t,n)=>(Xi(e,t,"read from private field"),n?n.call(e):t.get(e)),pe=(e,t,n)=>t.has(e)?Xn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ut=(e,t,n,r)=>(Xi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zc=(e,t,n)=>(Xi(e,t,"access private method"),n);function Jc(e,t){return{plugin:e,options:t}}function es(e){return t=>Jc(e,t)}function zr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var ed,Gr,Yi,ks;ed=[le];var et=class{constructor(e,t){this.manager=e,this.options=t,pe(this,Yi,ee(Gr,8,this,!1)),ee(Gr,11,this),pe(this,ks,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ae(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=yt(e.bind(this));return Fe(this,ks).add(t),t}destroy(){Fe(this,ks).forEach(e=>e())}static configure(e){return Jc(this,e)}};Gr=Yn(null);Yi=new WeakMap;ks=new WeakMap;de(Gr,4,"disabled",ed,et,Yi);pn(Gr,et);var ts=class extends et{},Ss,Io=class{constructor(e){this.manager=e,this.instances=new Map,pe(this,Ss,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(zr).reduce((r,s)=>{const o=r.find(({plugin:i})=>i===s.plugin);return o?(o.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Fe(this,Ss))if(!n.includes(r)){if(r.prototype instanceof ts)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);ut(this,Ss,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()}};Ss=new WeakMap;function vp(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var ds=[],Sn,$n,yp=class extends et{constructor(e){super(e),pe(this,Sn),pe(this,$n),this.computeCollisions=this.computeCollisions.bind(this),ut(this,$n,qn(ds)),this.destroy=Zr(()=>{const t=this.computeCollisions(),n=ae(()=>this.manager.dragOperation.position.current);if(t!==ds){const r=Fe(this,Sn);if(ut(this,Sn,n),r&&n.x==r.x&&n.y==r.y)return}else ut(this,Sn,void 0);Fe(this,$n).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ae(()=>{e?Fe(this,$n).value=this.computeCollisions():ut(this,Sn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:o,status:i}=r;if(!i.initialized||!o)return ds;const a=[],l=[];for(const u of e??n.droppables){if(u.disabled||s&&!u.accepts(s))continue;const c=t??u.collisionDetector;if(!c)continue;l.push(u),u.shape;const d=ae(()=>c({droppable:u,dragOperation:r}));d&&(u.collisionPriority!=null&&(d.priority=u.collisionPriority),a.push(d))}return l.length===0?ds:(a.sort(vp),a)}get collisions(){return Fe(this,$n).value}};Sn=new WeakMap;$n=new WeakMap;var td,nd,rd,Qi,sd,_t,Zi,Dn,Ji,ea;rd=[le],nd=[le],td=[le];var At=class en{constructor(t,n){pe(this,Zi,ee(_t,8,this)),ee(_t,11,this),pe(this,Dn),pe(this,Ji,ee(_t,12,this)),ee(_t,15,this),pe(this,ea,ee(_t,16,this)),ee(_t,19,this);const{effects:r,id:s,data:o={},disabled:i=!1,register:a=!0}=t;let l=s;ut(this,Dn,qn(s)),this.manager=n,this.data=o,this.disabled=i,this.effects=()=>{var u;return[()=>{const{id:c,manager:d}=this;if(c!==l)return l=c,d?.registry.register(this),()=>d?.registry.unregister(this)},...(u=r?.())!=null?u:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=Fe(this,Dn).value;return(n=(t=en.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=en.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Fe(this,Dn).peek();t!==s&&(en.pendingIdChanges||(en.pendingIdChanges=new Map,queueMicrotask(()=>{var o;return Zc(o=en,Qi,sd).call(o)})),en.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};_t=Yn(null);Qi=new WeakSet;sd=function(){const e=At.pendingIdChanges;At.pendingIdChanges=null,e&&Re(()=>{for(const[t,n]of e)Fe(t,Dn).value=n})};Zi=new WeakMap;Dn=new WeakMap;Ji=new WeakMap;ea=new WeakMap;de(_t,4,"manager",rd,At,Zi);de(_t,4,"data",nd,At,Ji);de(_t,4,"disabled",td,At,ea);pe(At,Qi);pn(_t,At);At.pendingIdChanges=null;var po=At,dl=class{constructor(){this.map=qn(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 o=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){o.delete(a);break}o.set(e,t),this.map.value=o;const i=Zr(...t.effects());return this.cleanupFunctions.set(t,i),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}},od,id,ad,ld,cd,dd,ui,rt,ta,na,ra,Ot=class extends(ui=po,dd=[le],cd=[le],ld=[le],ad=[We],id=[We],od=[We],ui){constructor(t,n){var r=t,{modifiers:s,type:o,sensors:i,plugins:a,effects:l}=r,u=Yc(r,["modifiers","type","sensors","plugins","effects"]);super(Vi(Ki({},u),{effects:()=>{var c;return[...(c=l?.())!=null?c:[],()=>{const{manager:d,plugins:f}=this;if(!(!d||!f))for(const h of f){const{plugin:y}=zr(h);d.registry.plugins.register(y)}}]}}),n),ee(rt,5,this),pe(this,ta,ee(rt,8,this)),ee(rt,11,this),pe(this,na,ee(rt,12,this)),ee(rt,15,this),pe(this,ra,ee(rt,16,this,this.isDragSource?"dragging":"idle")),ee(rt,19,this),this.type=o,this.sensors=i,this.modifiers=s,this.alignment=u.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=zr(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}};rt=Yn(ui);ta=new WeakMap;na=new WeakMap;ra=new WeakMap;de(rt,4,"type",dd,Ot,ta);de(rt,4,"modifiers",cd,Ot,na);de(rt,4,"status",ld,Ot,ra);de(rt,2,"isDropping",ad,Ot);de(rt,2,"isDragging",id,Ot);de(rt,2,"isDragSource",od,Ot);pn(rt,Ot);var ud,fd,hd,pd,gd,md,fi,Ke,sa,oa,ia,aa,la,Mt=class extends(fi=po,md=[le],gd=[le],pd=[le],hd=[le],fd=[le],ud=[We],fi){constructor(t,n){var r=t,{accept:s,collisionDetector:o,collisionPriority:i,type:a}=r,l=Yc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ee(Ke,5,this),pe(this,sa,ee(Ke,8,this)),ee(Ke,11,this),pe(this,oa,ee(Ke,12,this)),ee(Ke,15,this),pe(this,ia,ee(Ke,16,this)),ee(Ke,19,this),pe(this,aa,ee(Ke,20,this)),ee(Ke,23,this),pe(this,la,ee(Ke,24,this)),ee(Ke,27,this),this.accept=s,this.collisionDetector=o,this.collisionPriority=i,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}};Ke=Yn(fi);sa=new WeakMap;oa=new WeakMap;ia=new WeakMap;aa=new WeakMap;la=new WeakMap;de(Ke,4,"accept",md,Mt,sa);de(Ke,4,"type",gd,Mt,oa);de(Ke,4,"collisionDetector",pd,Mt,ia);de(Ke,4,"collisionPriority",hd,Mt,aa);de(Ke,4,"shape",fd,Mt,la);de(Ke,2,"isDropTarget",ud,Mt);pn(Ke,Mt);var xp=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)}},bp=class extends xp{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function $s(e,t=!0){let n=!1;return Vi(Ki({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var wp=class extends ts{constructor(e){super(e);const t=(r,s)=>r.map(({id:o})=>o).join("")===s.map(({id:o})=>o).join("");let n=[];this.destroy=Zr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:o}=r;if(r.isDisabled()||po.pendingIdChanges)return;const i=$s({collisions:o});if(s.dispatch("collision",i),i.defaultPrevented||t(o,n))return;n=o;const[a]=o;ae(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Qn=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Qn||{}),Zn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Zn||{}),vd,yd,xd,bd,wd,_d,kd,vt,ca;kd=[le],_d=[We],wd=[We],bd=[We],xd=[We],yd=[We],vd=[We];var Bt=class{constructor(){ee(vt,5,this),pe(this,ca,ee(vt,8,this,"idle")),ee(vt,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}};vt=Yn(null);ca=new WeakMap;de(vt,4,"value",kd,Bt,ca);de(vt,2,"current",_d,Bt);de(vt,2,"idle",wd,Bt);de(vt,2,"initializing",bd,Bt);de(vt,2,"initialized",xd,Bt);de(vt,2,"dragging",yd,Bt);de(vt,2,"dropped",vd,Bt);pn(vt,Bt);var _p=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 ae(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=$s({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ae(()=>{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:o}=e;Re(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(o)});const i=$s({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",i),i.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"&&Re(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return ae(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:o}=r;if(!s.dragging||!o||o.signal.aborted)return;const i=$s({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",i),queueMicrotask(()=>{var a,l,u,c,d;if(i.defaultPrevented)return;const f=(d=e.to)!=null?d:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((c=(u=e.by)==null?void 0:u.y)!=null?c:0)};r.position.current=f})})}stop(e={}){return ae(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let o;const i=()=>{const l={resume:()=>{},abort:()=>{}};return o=new Promise((u,c)=>{l.resume=u,l.abort=c}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=ae(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),u=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:c}=r,d=yt(()=>{c?.status==="idle"&&(d(),u())})}else this.manager.renderer.rendering.then(u)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:i}),o?o.then(a).catch(()=>r.reset()):a()})}},Bn=class extends et{constructor(e,t){super(e,t),this.manager=e,this.options=t}},kp=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)}},Ts,Sd=class{constructor(e){this.options=e,pe(this,Ts)}set controller(e){ut(this,Ts,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Fe(this,Ts))==null||t.activate(e)}};Ts=new WeakMap;var ul=class extends et{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Sp=class{constructor(e){this.draggables=new dl,this.droppables=new dl,this.plugins=new Io(e),this.sensors=new Io(e),this.modifiers=new Io(e)}register(e,t){if(e instanceof Ot)return this.draggables.register(e.id,e);if(e instanceof Mt)return this.droppables.register(e.id,e);if(e.prototype instanceof ul)return this.modifiers.register(e,t);if(e.prototype instanceof Bn)return this.sensors.register(e,t);if(e.prototype instanceof et)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof po)return e instanceof Ot?this.draggables.unregister(e.id,e):e instanceof Mt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof ul)return this.modifiers.unregister(e);if(e.prototype instanceof Bn)return this.sensors.unregister(e);if(e.prototype instanceof et)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()}},$d,Td,Ed,Cd,Od,Md,Id,Dd,jd,mr,Es,Tn,Pe,da,ua,fa,ha,pa,vr;jd=[We],Dd=[le],Id=[le],Md=[le],Od=[le],Cd=[le],Ed=[We],Td=[We],$d=[We];var $t=class{constructor(e){ee(Pe,5,this),pe(this,mr),pe(this,Es),pe(this,Tn,new hn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Bt,pe(this,da,ee(Pe,8,this,!1)),ee(Pe,11,this),pe(this,ua,ee(Pe,12,this,null)),ee(Pe,15,this),pe(this,fa,ee(Pe,16,this,null)),ee(Pe,19,this),pe(this,ha,ee(Pe,20,this,null)),ee(Pe,23,this),pe(this,pa,ee(Pe,24,this,[])),ee(Pe,27,this),this.position=new ho({x:0,y:0}),pe(this,vr,{x:0,y:0}),ut(this,mr,e)}get shape(){const{current:e,initial:t,previous:n}=Fe(this,Tn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Fe(this,Tn).current=e:Fe(this,Tn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Fe(this,mr).registry.draggables.get(t);return n&&ut(this,Es,n),(e=n??Fe(this,Es))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Fe(this,mr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Vi(Ki({},this.snapshot()),{transform:n}));return ut(this,vr,n),n}snapshot(){return ae(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Fe(this,vr),shape:this.shape?Mo(this.shape):null,position:Mo(this.position),status:Mo(this.status),canceled:this.canceled}))}reset(){Re(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Fe(this,Tn).reset(),this.position.reset({x:0,y:0}),ut(this,vr,{x:0,y:0}),this.modifiers=[]})}};Pe=Yn(null);mr=new WeakMap;Es=new WeakMap;Tn=new WeakMap;da=new WeakMap;ua=new WeakMap;fa=new WeakMap;ha=new WeakMap;pa=new WeakMap;vr=new WeakMap;de(Pe,2,"shape",jd,$t);de(Pe,4,"canceled",Dd,$t,da);de(Pe,4,"activatorEvent",Id,$t,ua);de(Pe,4,"sourceIdentifier",Md,$t,fa);de(Pe,4,"targetIdentifier",Od,$t,ha);de(Pe,4,"modifiers",Cd,$t,pa);de(Pe,2,"source",Ed,$t);de(Pe,2,"target",Td,$t);de(Pe,2,"transform",$d,$t);pn(Pe,$t);var $p={get rendering(){return Promise.resolve()}};function St(e,t){return typeof e=="function"?e(t):e??t}var Tp=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=St(r.plugins,[]),o=St(r.sensors,[]),i=St(r.modifiers,[]),a=(n=r.renderer)!=null?n:$p,l=new bp(this),u=new Sp(this);this.registry=u,this.monitor=l,this.renderer=a,this.actions=new _p(this),this.dragOperation=new $t(this),this.collisionObserver=new yp(this),this.plugins=[wp,...s],this.modifiers=i,this.sensors=o;const{destroy:c}=this,d=Zr(()=>{var f,h,y;const g=ae(()=>this.dragOperation.modifiers),w=this.modifiers;for(const x of g)w.includes(x)||x.destroy();this.dragOperation.modifiers=(y=(h=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:h.map(x=>{const{plugin:p,options:v}=zr(x);return new p(this,v)}))!=null?y:w});this.destroy=()=>{d(),c()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},Pd=e=>{throw TypeError(e)},ga=(e,t,n)=>t.has(e)||Pd("Cannot "+n),J=(e,t,n)=>(ga(e,t,"read from private field"),t.get(e)),at=(e,t,n)=>t.has(e)?Pd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ct=(e,t,n,r)=>(ga(e,t,"write to private field"),t.set(e,n),n),Rd=(e,t,n)=>(ga(e,t,"access private method"),n);function go(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Ad(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:o}=s,a=(go(o)?o.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function mo(e){const{width:t,height:n,top:r,left:s,bottom:o,right:i}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:o,right:i}}function ma(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function ns(e){return"nodeType"in e}function ft(e){var t,n,r;return e?ma(e)?e:ns(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 va(e){const{Document:t}=ft(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Kt(e){return!e||ma(e)?!1:e instanceof ft(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Ld(e){return e instanceof ft(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Jn(e){return e?ma(e)?e.document:ns(e)?va(e)?e:Kt(e)||Ld(e)?e.ownerDocument:document:document:document}function Ep(e){var t,n,r,s;const{documentElement:o}=Jn(e),i=ft(e).visualViewport,a=(t=i?.width)!=null?t:o.clientWidth,l=(n=i?.height)!=null?n:o.clientHeight,u=(r=i?.offsetTop)!=null?r:0,c=(s=i?.offsetLeft)!=null?s:0;return{top:u,left:c,right:c+a,bottom:u+l,width:a,height:l}}function Cp(e,t){if(Op(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Op(e){return e.tagName==="DETAILS"}function Hr(e,t=e.getBoundingClientRect(),n=0){var r,s,o,i,a;let l=t;const{ownerDocument:u}=e,c=(r=u.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==u.documentElement;){if(!Cp(d)){const v=d.getBoundingClientRect(),_=n*(v.bottom-v.top),b=n*(v.right-v.left),E=n*(v.bottom-v.top),T=n*(v.right-v.left);l={top:Math.max(l.top,v.top-_),right:Math.min(l.right,v.right+b),bottom:Math.min(l.bottom,v.bottom+E),left:Math.max(l.left,v.left-T),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}d=d.parentElement}const f=c.visualViewport,h=(s=f?.offsetTop)!=null?s:0,y=(o=f?.offsetLeft)!=null?o:0,g=(i=f?.width)!=null?i:c.innerWidth,w=(a=f?.height)!=null?a:c.innerHeight,x=n*w,p=n*g;return l={top:Math.max(l.top,h-x),right:Math.min(l.right,y+g+p),bottom:Math.min(l.bottom,h+w+x),left:Math.max(l.left,y-p),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function Fn(e){return{x:e.clientX,y:e.clientY}}var Bd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function hi(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...hi(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...hi(s.document,t))}}catch{}return n}function ya(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Fd(){var e,t;const n=ya()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function xa(e){return!e||!ns(e)?!1:e instanceof ft(e).ShadowRoot}function Us(e){if(e&&ns(e)){let t=e.getRootNode();if(xa(t))return t;if(t instanceof Document)return t}return Jn(e)}function ba(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Mp(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((o,i)=>{const a=r[i];if(fl(o)&&fl(a)&&(o.type!=="file"&&(o.value=a.value),o.type==="radio"&&o.name&&(o.name=`Cloned__${o.name}`)),hl(o)&&hl(a)&&a.width>0&&a.height>0){const l=o.getContext("2d");l?.drawImage(a,0,0)}}),n}function fl(e){return"value"in e}function hl(e){return e.tagName==="CANVAS"}function Wd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Ip(r)){const{contentDocument:s}=r;if(s){const{left:o,top:i}=r.getBoundingClientRect();return Wd(s,{x:t-o,y:n-i})}}return r}function Ip(e){return e?.tagName==="IFRAME"}var pi=new WeakMap;function Dp(e){return e.closest(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),k=require("../useCompiledDocument-BCr-xB_i.cjs.js"),$=require("@mui/material"),S=require("react"),be=require("../ServerProvider-DeVejmVr.cjs.js"),me=require("../text-entry-BJwltZiy.cjs.js"),Nf=require("react-dom"),uc=require("@tanstack/react-query"),Ce=e=>e.kind==="text",ce=e=>e.kind!=="text",lr=e=>ce(e)?e.label??e.name:e.name,dt=e=>e.declaration.kind==="query"?e.name:`${e.source} -> ${e.name}`,Hn=e=>e.declaration.kind==="inherited"||e.declaration.kind==="query",fe=e=>Ce(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,Ka=".malloy-big-value, .malloy-table",zf=e=>e.querySelector(Ka)!==null&&![...e.querySelectorAll(".malloy-chart")].some(t=>t.closest(Ka)===null),As=(e,t)=>Ce(e)?k.MIN_TEXT_TILE_ROWS:t&&zf(t)?k.MIN_VALUE_TILE_ROWS:k.MIN_TILE_ROWS,Fr=e=>e.rowspan??k.PLACED_DEFAULT_ROWSPAN[Ce(e)?"text":"query"];function Ut(e,t){if(e.row===void 0||e.col===void 0)return;const n=Math.min(e.colspan??1,t);return{row:e.row,col:Math.min(e.col,t-n+1),colspan:n,rowspan:Fr(e)}}const Wr=(e,t)=>e.col<t.col+t.colspan&&t.col<e.col+e.colspan&&e.row<t.row+t.rowspan&&t.row<e.row+e.rowspan;function In(e){return e.map((t,n)=>({tile:t,index:n})).sort((t,n)=>(t.tile.row??1/0)-(n.tile.row??1/0)||(t.tile.col??1/0)-(n.tile.col??1/0)||t.index-n.index).map(({tile:t})=>t)}function Rt(e,t,n){const r=e.map(a=>({...a})),s=[],o=a=>{const l=Ut(r[a],t);l&&(r[a].col=l.col,s.push(l))};n!==void 0&&o(n);const i=r.map((a,l)=>({tile:a,index:l})).filter(({index:a,tile:l})=>a!==n&&l.row!==void 0).sort((a,l)=>(a.tile.row??0)-(l.tile.row??0)||(a.tile.col??0)-(l.tile.col??0)||a.index-l.index);for(const{index:a}of i){const l=Ut(r[a],t);if(l){for(;;){const u=s.filter(c=>Wr(l,c));if(u.length===0)break;l.row=Math.max(...u.map(c=>c.row+c.rowspan))}r[a].row=l.row,o(a)}}return r}function Gf(e,t,n,r){const s=e.flatMap((l,u)=>{const c=u===t?void 0:Ut(l,r);return c?[c]:[]}),o=Math.max(1,...s.map(l=>l.row+l.rowspan)),i={...e[t],...n,row:Math.min(n.row,o)},a=Ut(i,r);if(a){for(;;){const l=s.filter(u=>u.row<a.row&&Wr(a,u));if(l.length===0)break;a.row=Math.max(...l.map(u=>u.row+u.rowspan))}i.row=a.row}return Rt(e.map((l,u)=>u===t?i:l),r,t)}const Ls=(e,t)=>(e-k.GRID_GAP_PX*(t-1))/t,fc=k.TILE_ROW_PX+k.GRID_GAP_PX;function hc(e,t,n,r,s){const o=Math.min(n,r),i=Math.round(e/(s+k.GRID_GAP_PX))+1;return{row:Math.max(1,Math.round(t/fc)+1),col:Math.min(Math.max(i,1),r-o+1)}}function pc(e,t,n,r){const s=e.map((o,i)=>{if(o.row!==void 0&&o.col!==void 0)return o;const a=t[i];if(!a)return o;const{break:l,...u}=o,c=o.colspan??Math.max(1,Math.round((a.width+k.GRID_GAP_PX)/(r+k.GRID_GAP_PX))),d=hc(a.left,a.top,c,n,r),f=(a.top+a.height+k.GRID_GAP_PX)/fc,h=Ce(o)?Math.ceil(f-.02):Math.round(f);return{...u,...d,colspan:c,rowspan:o.rowspan??Math.max(As(o),h-d.row+1)}});return Rt(s,n)}function Va(e,t,n){const r=e.flatMap((o,i)=>{const a=i===t?void 0:Ut(o,n);return a?[a]:[]});if(r.length===0)return[...e];const s=Math.max(...r.map(o=>o.row+o.rowspan));return e.map((o,i)=>i===t?{...o,row:s,col:1}:o)}function gc(e,t){const n=e.map(o=>({...o})),r=[],s=n.map((o,i)=>({tile:o,index:i})).filter(({tile:o})=>o.row!==void 0&&o.col!==void 0).sort((o,i)=>(o.tile.row??0)-(i.tile.row??0)||(o.tile.col??0)-(i.tile.col??0)||o.index-i.index);for(const{index:o}of s){const i=Ut(n[o],t);if(i){for(;i.row>1&&!r.some(a=>Wr({...i,row:i.row-1},a));)i.row-=1;n[o].row=i.row,n[o].col=i.col,r.push(i)}}return n}const Hf=(e,t)=>gc(e,t).some((n,r)=>n.row!==e[r].row||n.col!==e[r].col);function qf(e){return In(e).map(t=>{const{row:n,col:r,...s}=t;return s})}const Uf=(e,t,n)=>e.map((r,s)=>s===t?{...r,...n}:r);function Xa(e,t,n,r,s){const o=Ut(e[t],s);if(!o)return[...e];const i={row:Math.max(1,o.row+n),col:Math.min(Math.max(1,o.col+r),s-o.colspan+1)};if(i.row===o.row&&i.col===o.col)return[...e];const a={...o,...i},l=e.flatMap((h,y)=>{const g=y===t?void 0:Ut(h,s);return g&&Wr(a,g)&&!Wr(o,g)?[{i:y,other:g}]:[]}),u=l.length===1?l[0]:void 0;if(!u)return Rt(Uf(e,t,i),s,t);const{i:c,other:d}=u,f=e.map(h=>({...h}));return n>0?(f[c].row=o.row,f[t].row=o.row+d.rowspan):n<0?(f[t].row=d.row,f[c].row=d.row+o.rowspan):r>0?(f[c].col=o.col,f[t].col=o.col+d.colspan):(f[t].col=d.col,f[c].col=d.col+o.colspan),Rt(f,s,t)}const mc=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1);function Kf(e){return Ce(e)||e.rowspan===void 0?e:k.isChartPick(e.chart)&&e.chart!=="big_value"&&e.rowspan<k.MIN_TILE_ROWS?{...e,rowspan:k.MIN_TILE_ROWS}:e}const vc=k.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"})),yc=k.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"})),Vf=k.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 xc(e){const{theme:t}=be.usePublisherTheme(),n=t.ui,[r,s]=S.useState(null),{status:o,draftKeptAt:i,discard:a,restored:l,dismissRestored:u}=e,c=l!==void 0&&!l.pending&&o==="unsaved"?l:void 0,d=o==="saved"?"Saved":o==="saving"?"Saving…":i!==void 0?"Draft saved":"Unsaved changes",f=c?`Restored your unsaved edits from ${qo(c.savedAt)}`:void 0,h=o==="unsaved"&&i!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,y=a!==void 0&&o==="unsaved",g=()=>{s(null),c&&u?.()},w=v=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:o==="saved"?v.palette.text.secondary:v.palette.text.primary,transition:`color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,...y?{"&:hover":{bgcolor:v.palette.action.hover}}:{}}),x=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:o==="saved"?m.jsx(k.CheckIcon,{sx:{fontSize:16}}):m.jsx($.Box,{component:"span","data-restored":c?"true":void 0,sx:v=>({width:7,height:7,borderRadius:"50%",bgcolor:c?t.accent:o==="saving"||i!==void 0?v.palette.text.disabled:v.palette.warning.main,transition:`background-color ${k.MOTION_FAST}`})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:d}),m.jsx(k.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:y?"visible":"hidden"}})]}),p=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:Xf,children:f?`${d}. ${f}.`:d});return m.jsxs(m.Fragment,{children:[p,m.jsx($.Tooltip,{title:f??h,describeChild:!0,children:y?m.jsx($.ButtonBase,{className:k.reportClasses.saveStatus,"aria-label":d,...f?{"aria-description":f}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:v=>s(v.currentTarget),sx:w,children:x}):m.jsx($.Box,{component:"span",className:k.reportClasses.saveStatus,sx:w,children:x})}),m.jsxs($.Menu,{className:k.reportClasses.menu,anchorEl:r,open:r!==null,onClose:g,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${k.edgeColor(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(f!==void 0||i!==void 0)&&m.jsx($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:f??`Kept in this browser at ${qo(i)}`}),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(Vf,{fontSize:"small"}),"Discard edits"]})]})]})}function qo(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 Xf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},Uo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),cn=Uo?"⌘":"Ctrl+",Ya=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},So=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function Yf(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e});const[n,r]=S.useState(!1);S.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),S.useEffect(()=>{const s=o=>{const i=t.current;if(i.paused)return;const a=Uo?o.metaKey:o.ctrlKey,l=o.key.toLowerCase();if(o.key==="Escape"){if(Ya(o.target)||So(o.target))return;i.escape();return}if(Ya(o.target)){if(a&&l==="s"){if(o.preventDefault(),!i.save||So(o.target))return;o.target.blur(),r(!0)}return}if(So(o.target)){a&&l==="s"&&o.preventDefault();return}if(a&&l==="z"){o.preventDefault(),o.shiftKey?i.redo():i.undo();return}if(!Uo&&a&&l==="y"){o.preventDefault(),i.redo();return}if(a&&l==="s"){o.preventDefault(),i.save?.();return}if(i.move&&o.altKey&&!a&&!o.shiftKey){const u=o.key==="ArrowLeft"?[0,-1]:o.key==="ArrowRight"?[0,1]:o.key==="ArrowUp"?[-1,0]:o.key==="ArrowDown"?[1,0]:void 0;if(u&&i.move(u[0],u[1])){o.preventDefault();return}}i.nudge&&!a&&!o.altKey&&!o.shiftKey&&(o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.preventDefault(),i.nudge(o.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Mr=(e,t,n=be.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}}}),Nr=(e=be.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),Bs={height:20,alignSelf:"center",mx:.5,my:0},Fs=(e,t=be.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"}}}),Ko={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Qf({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:o,onSave:i,savesTo:a="package",saveLabel:l,saveButton:u,actions:c,onAddTile:d,arrange:f,onExit:h,saveStatus:y}){const{theme:g}=be.usePublisherTheme(),w=k.edgeColor(g.cardBorder),x=k.hoverEdgeColor(g.cardBorder,g.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[f,d&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(k.AddIcon,{}),onClick:d,"aria-label":"Add tile",sx:Mr(w,x,g.ui),children:"Tile"}),d&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),m.jsx($.Tooltip,{title:`Undo (${cn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Nr(g.ui),children:m.jsx(yc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${cn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:Nr(g.ui),children:m.jsx(vc,{fontSize:"small"})})})}),(c||i||h)&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),c,i&&y&&m.jsx(xc,{...y}),i?m.jsx($.Tooltip,{title:s?`Save (${cn}S) · ${l??Ko[a]}`:l??Ko[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:u,variant:s?"contained":"outlined",disabled:!s||o,onClick:i,sx:{...Mr(w,x,g.ui),minWidth:88},children:o?"Saving…":s?"Save":"Saved"})})}):null,i&&m.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:o?"Saving":s?"Unsaved changes":"All changes saved"}),h&&m.jsx(k.SecondaryButton,{label:"Close",icon:m.jsx(k.CheckIcon,{}),onClick:h})]})}const Zf=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Qa={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map",combo_chart:"Bar and line"};function bc(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this tile's details":n==="unlisted"?"Not in the model's list, so its shape is unknown":void 0,s=e?.shape,o=a=>{if(t===a)return;if(a==="big_value")return e?.aggregateOnly===!0?void 0:s&&s.groupBys>0?"This view has a group by, so it is more than one row; big numbers need a view of totals only":r??"Needs results that are only totals (no group by)";if(a==="shape_map"||a==="segment_map")return e?.chart===a?void 0:r??"Needs a map chart set in the model";if(e?.chart===a)return;if(!s)return a==="combo_chart"?r??"Needs a view with a group by and exactly two totals: the first is drawn as bars, the second as a line":void 0;const l=`A ${Qa[a].toLowerCase()} chart`;switch(k.chartShapeGap(a,s)){case"no_x_axis":return Zf(l);case"combo_totals":return`A bar and line chart needs exactly two totals, the first drawn as bars and the second as a line; this view has ${s.totals}`;case"no_y_axis":return`This view has no total for the y-axis: ${l.toLowerCase()} needs at least one aggregate`;default:return}};return[{value:"default",label:"Default",hint:"As set in the model"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map","combo_chart"].map(a=>{const l=o(a);return{value:a,label:Qa[a],...l?{disabled:!0,reason:l}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Za(e){return e.description??k.readableName(e.name)}const Jf={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",combo_chart:"a bar and line chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},ls=(e,t)=>`${e}\0${t}`;function eh({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:o,onAddText:i,renderPreview:a}){const{theme:l}=be.usePublisherTheme(),u=l.ui,c=k.edgeColor(l.cardBorder),d=S.useMemo(()=>n?.sources??[],[n]),[f,h]=S.useState(""),[y,g]=S.useState(),[w,x]=S.useState(""),[p,v]=S.useState("default"),_=S.useRef(null),b=S.useMemo(()=>{const j=new Set(t.sources.map(z=>z.base));return[...d].sort((z,D)=>Number(j.has(D.name))-Number(j.has(z.name)))},[d,t]),E=b.filter(j=>j.views.length>0),T=b.filter(j=>j.views.length===0),M=S.useMemo(()=>new Map(E.flatMap(j=>j.views.map(z=>[ls(j.name,z.name),{source:j,view:z,key:ls(j.name,z.name)}]))),[E]),O=S.useMemo(()=>E.map(j=>({key:j.name,label:j.name,...j.description?{detail:j.description}:{},entries:j.views.map(z=>({key:ls(j.name,z.name),name:z.name,title:Za(z),...z.chart?{chart:z.chart}:{}}))})),[E]),C=y===void 0?void 0:M.get(y);S.useEffect(()=>{if(!e)return;h(""),x(""),v("default");const j=E[0]?.views[0];g(j&&E[0]?ls(E[0].name,j.name):void 0)},[e]);const A=C?[C.source.name,C.view.name].filter(j=>!me.isBareName(j)).map(j=>`"${j}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,R=C!==void 0&&A===void 0,L=C?Za(C.view):"",G=p!=="default"&&C?{chart:p,chartCarried:C.view.chart?[C.view.chart]:[]}:{},N=(j=C)=>{if(!j||![j.source.name,j.view.name].every(me.isBareName))return;const z=j.key===C?.key,D=k.writtenSpan(Math.ceil(r/2),r);o({base:j.source.name,modelPath:j.source.modelPath,...j.source.exporters?{exporters:j.source.exporters}:{},view:j.view.name,...z&&w.trim()?{label:w.trim()}:{},...z?G:{},...D!==void 0?{colspan:D}:{}})},X=C?bc(C.view,p).filter(j=>j.value!=="custom"&&j.disabled!==!0):[];return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:_,title:"Add a tile",description:"Pick what the tile shows from the model. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:i,sx:{mr:"auto"},children:"Add text instead"}),m.jsx($.Button,{onClick:s,children:"Cancel"}),m.jsx($.Button,{variant:"contained",disabled:!R,onClick:()=>N(),children:"Add tile"})]}),children:m.jsxs($.Box,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${c}`,borderBottom:`1px solid ${c}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx($.Box,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(k.ViewPicker,{groups:O,query:f,onQuery:h,picked:C?.key,onPick:j=>{g(j),v("default")},onTake:j=>N(M.get(j)),searchRef:_,empty:m.jsx($.Typography,{variant:"body2",sx:{color:l.tileTitle,p:2},children:n?"This package's models have nothing to put on a tile yet.":"The package's sources are still loading."}),footer:T.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:"," ",T.map(j=>j.name).join(", "),"."]})})}),m.jsx($.Box,{sx:j=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${j.palette.text.primary} 3%, ${j.palette.background.paper})`}),children:C?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:j=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:u.radius.tile,border:`1px solid ${c}`,bgcolor:j.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${j.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:C.source.name,modelPath:C.source.modelPath,view:C.view.name,label:w.trim()||L,...p!=="default"?G:{},givens:C.source.givens})}):m.jsxs($.Box,{sx:j=>({flex:1,border:`1px solid ${c}`,borderRadius:u.radius.tile,bgcolor:j.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(k.ChartGlyph,{chart:C.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[C.source.name," → ",C.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:L,value:w,onChange:j=>x(j.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs($.Box,{children:[m.jsx($.Typography,{component:"div",sx:{...u.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($.ToggleButtonGroup,{size:"small",exclusive:!0,value:p,"aria-label":"Chart",onChange:(j,z)=>{z!==null&&v(z)},sx:{...Fs(c,u),"& .MuiToggleButton-root":{...Fs(c,u)["& .MuiToggleButton-root"],textTransform:"none"}},children:X.map(j=>m.jsx($.ToggleButton,{value:j.value,children:j.label},j.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:C.view.chart?`The model sets ${Jf[C.view.chart]??"a chart"}.`:"The model sets 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."})})]})})}function th(e,t,{modelPath:n,textHeld:r,widths:s,insertAt:o}){t.modelPath&&!r&&(e.imports=k.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const i=wc(e,t.base),a=Vo(e,i.name,t.view);e.tiles.splice(o??e.tiles.length,0,{name:a,source:i.name,declaration:{kind:"reference",from:t.view},...s&&t.colspan!==void 0?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function wc(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 o=`${t}_tiles`;for(let a=2;s.has(o);a++)o=`${t}_tiles_${a}`;const i={name:o,base:t};return e.sources.push(i),i}function Vo(e,t,n){const r=new Set(e.tiles.filter(ce).filter(o=>o.source===t).map(o=>o.name));let s=`${n}_tile`;for(let o=2;r.has(s);o++)s=`${n}_tile_${o}`;return s}function Ws(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;case"query":return"It names a query, and a copy could not be told apart from it: the builder writes nothing about such a tile but its place.";default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function nh(e,t){const n=e.tiles[t];if(!n||!ce(n)||Ws(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:o,...i}=structuredClone(n);r={...i,name:Vo(e,n.source,n.declaration.from)}}else{const i=e.sources.find(a=>a.name===n.source)??wc(e,n.source,{unscoped:!0});r={name:Vo(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}const s=n.row!==void 0&&n.col!==void 0;return s&&(r={...r,row:(n.row??1)+Fr(n),col:n.col,...n.rowspan!==void 0?{rowspan:n.rowspan}:{}}),e.tiles.splice(t+1,0,r),s&&(e.tiles=Rt(e.tiles,e.columns??k.DEFAULT_COLUMNS,t+1)),t+1}const cs="self";function rh({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:o,onClose:i,onApply:a}){const{theme:l}=be.usePublisherTheme(),u=l.ui,[c,d]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(v=>v.source===n.name);d((n.dimensions??[]).map(v=>{const _=p.find(b=>b.name===v.name);return{name:v.name,expression:v.expression,to:_?.to??[],given:_?.given??""}}))},[e,n,t]);const f=(p,v)=>d(_=>_.map((b,E)=>{if(E!==p)return b;const T={...b};return v(T),T})),h=[cs,...s.filter(p=>p!==cs)],y=p=>p===cs?"This report":p,g=()=>{n&&(a(c.filter(p=>p.to.length>0).map(p=>({source:n.name,name:p.name,expression:p.expression,to:p.to,...p.given?{given:p.given}:{}}))),i())},w=k.edgeColor(l.cardBorder),x=(p,v)=>f(p,_=>{v?_.to=_.lastTo?.length?_.lastTo:[cs]:(_.lastTo=_.to,_.to=[])});return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.clickableCellsDialog}`,open:e,onClose:i,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[o&&m.jsxs($.Box,{component:"span",sx:{fontWeight:u.type.label.fontWeight},children:[o," ·"," "]}),"A click on a table cell sets a filter to its value, on this report or on the one it opens. Bars, lines and points on a chart do not respond to a click. Clicks work in the report, not while you edit it."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:i,children:"Cancel"}),m.jsx($.Button,{variant:"contained",onClick:g,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx($.Typography,{variant:"body2",sx:{color:l.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:c.map((p,v)=>{const _=p.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:_,onChange:b=>x(v,b.target.checked),slotProps:{input:{"aria-label":`${p.name} is clickable`}}}),m.jsxs($.Box,{sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...u.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:sh(p.name)}),m.jsxs($.Box,{title:p.expression,sx:{...u.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[p.name," is ",p.expression]})]}),_?m.jsxs($.Stack,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...u.type.control},children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx($.TextField,{select:!0,size:"small",value:p.to,inputProps:{"aria-label":`Where ${p.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.map(y).join(", ")},onChange:b=>f(v,E=>{const T=b.target.value,M=Array.isArray(T)?T:String(T).split(",").filter(Boolean);M.length===0&&(E.lastTo=E.to),E.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:p.to.includes(b),sx:{p:0,mr:1}}),m.jsx($.ListItemText,{primary:y(b)})]},b))}),m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs($.TextField,{select:!0,size:"small",value:p.given,inputProps:{"aria-label":`Control ${p.name} sets`},SelectProps:{displayEmpty:!0,renderValue:b=>b===""?p.name:String(b)},onChange:b=>f(v,E=>{E.given=b.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx($.MenuItem,{value:"",children:m.jsx($.ListItemText,{primary:p.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"})]},p.name)})})})}function sh(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const oh=k.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"})),ih=k.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"})),ah=k.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"})),lh=k.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"})),ch=k.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),dh=k.createSvgIcon(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function uh(e,t=[]){const n=new Map;for(const o of e.tiles)for(const i of ce(o)?o.filters??[]:[])n.set(i.given,(n.get(i.given)??0)+1);const r=[],s=new Set;for(const o of e.localGivens??[])s.add(o.name),r.push({name:o.name,...o.label===void 0?{}:{label:o.label},type:o.type,...o.suggest?{field:o.suggest.dimension}:{},origin:"dashboard",local:o,boundTiles:n.get(o.name)??0});for(const o of t)s.has(o.name)||(s.add(o.name),r.push({...o,origin:"model",boundTiles:n.get(o.name)??0}));for(const[o,i]of n)s.has(o)||r.push({name:o,origin:"model",boundTiles:i});return r}function Ns(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function fh(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function Ir(e,t){const n=fh(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 Xo(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 hh(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const ph=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function gh(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}`,o=me.isStrictName(s)?s:`${s}_FILTER`,i=new Set(t);if(!i.has(o))return o;for(let a=2;;a++)if(!i.has(`${o}_${a}`))return`${o}_${a}`}const mh=[{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 fr(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 Yo=e=>ce(e)&&!Hn(e)&&e.declaration.kind!=="opaque";function vh(e,t){return e.tiles.map(n=>{const r=(ce(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}:Ns(t.type)!==void 0?{op:Ns(t.type)}:{}}})}function yh(e,t,n){n.forEach((r,s)=>{const o=e.tiles[s];if(!o||!Yo(o))return;const i=(o.filters??[]).filter(l=>l.given!==t),a=r.include?[...i,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:i;a.length>0?o.filters=a:delete o.filters})}function xh(e,t){const n=(e.localGivens??[]).filter(o=>o.name!==t.name),r=(e.localGivens??[]).findIndex(o=>o.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function bh(e,t){for(const r of e.tiles){if(!ce(r))continue;const s=(r.filters??[]).filter(o=>o.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 Qo=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function wh({open:e,document:t,control:n,available:r,takenNames:s=[],fieldsFor:o,onApply:i}){const a=S.useRef(n);e&&(a.current=n);const l=e?n:a.current,u=l!==void 0,[c,d]=S.useState({kind:"new"}),[f,h]=S.useState(""),[y,g]=S.useState("select"),[w,x]=S.useState(""),[p,v]=S.useState(""),[_,b]=S.useState([]),[E,T]=S.useState(!1),[M,O]=S.useState(!1),C=P=>t.sources.find(F=>F.name===P.source)?.base??P.source;S.useEffect(()=>{if(e)if(O(n!==void 0),n){d({kind:"existing",name:n.name}),h(n.label??"");const P=vh(t,n);b(P);const F=P.filter(Y=>Y.include),U=new Set(F.map(Y=>Y.field));v(U.size===1?F[0].field:n.field??""),T(U.size>1)}else d({kind:"new"}),h(""),g("select"),v(""),x(new Date().toISOString().slice(0,10)),b(t.tiles.map(P=>({include:Yo(P),field:""}))),T(!1)},[e,n,t]);const A=S.useMemo(()=>[...(t.localGivens??[]).map(P=>P.name),...r.map(P=>P.name),...s],[t,r,s]),R=S.useMemo(()=>p.trim()?gh(p.trim(),A):"",[p,A]),L=c.kind==="existing"?n??r.find(P=>P.name===c.name):R?{name:R,type:fr({name:R,label:f,kind:y,field:p}).type}:void 0,G=L?.type!==void 0&&!L.type.startsWith("filter<"),N=_.find(P=>P.include)?.op??Ns(L?.type),X=(P,F)=>{O(!0),b(U=>U.map((Y,Se)=>Se===P?{...Y,...F}:Y))},j=P=>{O(!0),b(F=>F.map(U=>({...U,op:P})))},z=P=>{const F=Ns(P);b(U=>U.map(({op:Y,...Se})=>F?{...Se,op:F}:Se))},D=P=>{O(!0),d({kind:"existing",name:P.name}),v(P.field??""),z(P.type)},I=P=>{O(!0),g(P),z(fr({name:"X",label:f,kind:P,field:p}).type)},B=t.tiles.map(Yo),q=B.filter(Boolean).length,H=_.filter((P,F)=>P.include&&B[F]).length,K=t.tiles.filter((P,F)=>(_[F]?.include??!1)&&B[F]&&ce(P)),te=K.length>0?K:t.tiles.filter((P,F)=>B[F]&&ce(P)),ye=S.useMemo(()=>{const P=new Map;let F=!1;for(const U of te){const Y=o?.(U);if(Y){F=!0;for(const Se of Y)P.has(Se.name)||P.set(Se.name,Se)}}return F?[...P.values()]:void 0},[_,t.tiles,o]),_e=(()=>{const P=p.trim();for(const F of K){const U=o?.(F);if(!U||U.some(Y=>Y.name===P))return C(F)}return K[0]?C(K[0]):t.sources[0]?.base})(),re=P=>{O(!0),b(F=>F.map((U,Y)=>({...U,include:P&&B[Y]})))},De=S.useMemo(()=>E?_:_.map(P=>({...P,field:p})),[E,_,p]),ge=P=>{for(const F of te){const U=o?.(F)?.find(Y=>Y.name===P.trim());if(U?.type)return U.type}},ve=P=>Ir(L?.type,P.type),Ge=(P,F)=>{if(P.trim()==="")return"Pick the field this filter compares.";const U=F?o?.(F):void 0;if(!U)return;const Y=U.find(Se=>Se.name===P.trim());if(!Y)return`Not a field of ${F?C(F):"the tiles' source"}.`;if(Y.type&&!Ir(L?.type,Y.type))return`${P.trim()} is ${Xo(Y.type)}; this filter compares ${Xo(L?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},Z=P=>{if(O(!0),v(P),u||c.kind!=="new")return;const F=ge(P),U=fr({name:"X",label:f,kind:y,field:P}).type;F&&!Ir(U,F)&&I(hh(F))},Xe=P=>{const F=t.tiles[P];return F&&ce(F)?F:void 0},ke=De.map((P,F)=>P.include&&B[F]?Ge(P.field,Xe(F)):void 0),ue=ke.every(P=>P===void 0),Oe=M?ke:ke.map(()=>{}),Ae=M&&!E&&H>0?K.map(P=>Ge(p,P)).find(Boolean):void 0,ie=L!==void 0&&ue&&(c.kind==="existing"||p.trim()!==""&&R!==""),qe=()=>{if(!(!L||!ie))if(c.kind==="new")i(L.name,De,fr({name:L.name,label:f.trim()||Qo(L.name),kind:y,field:p.trim(),..._e?{source:_e}:{},...w?{dateDefault:w}:{}}));else if(n?.origin==="dashboard"&&n.local){const P=f.trim(),F=P!==(n.local.label??"");i(L.name,De,F?{...n.local,...P?{label:P}:{}}:void 0)}else i(L.name,De)},Ye=u&&l.origin==="model";return{editing:u,shown:l,fromModel:Ye,source:c,setSource:d,label:f,setLabel:h,kind:y,dateDefault:w,setDateDefault:x,field:p,rows:_,setRows:b,perTile:E,setPerTile:T,newName:R,target:L,valueTyped:G,commonOp:N,setRow:X,setCommonOp:j,pickExisting:D,pickKind:I,bindable:B,bindableCount:q,included:H,commonFields:ye,setAll:re,accepts:ve,pickField:Z,rowProblems:Oe,commonProblem:Ae,canApply:ie,apply:qe}}function Ja({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:o,error:i,helperText:a,disabled:l,autoFocus:u,placeholder:c,inputRef:d,sx:f}){const h=S.useMemo(()=>(n??[]).filter(g=>r?.(g)??!0).map(g=>g.name),[n,r]),y=S.useMemo(()=>new Map((n??[]).map(g=>[g.name,g.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(g,w)=>t(w),value:e,onChange:(g,w)=>t(typeof w=="string"?w:""),disabled:l,disableClearable:!0,renderOption:(g,w)=>S.createElement("li",{...g,key:w},m.jsx(tl,{type:y.get(w)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:w})),renderInput:g=>m.jsx($.TextField,{...g,label:s,placeholder:c,autoFocus:u,...d?{inputRef:d}:{},error:i,helperText:a,InputLabelProps:{...g.InputLabelProps,shrink:!0},InputProps:{...g.InputProps,startAdornment:y.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(tl,{type:y.get(e.trim())})}):void 0},inputProps:{...g.inputProps,"aria-label":o}}),sx:f})}const _h=e=>e&&ce(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:e&&ce(e)&&e.declaration.kind==="query"?{label:"Not bindable",reason:"It names a query, whose filters live in that query's own definition."}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function kh({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:o,onClose:i,onApply:a,onRemove:l}){const{theme:u}=be.usePublisherTheme(),c=u.ui,{editing:d,shown:f,fromModel:h,source:y,setSource:g,label:w,setLabel:x,kind:p,dateDefault:v,setDateDefault:_,field:b,rows:E,setRows:T,perTile:M,setPerTile:O,newName:C,target:A,valueTyped:R,commonOp:L,setRow:G,setCommonOp:N,pickExisting:X,pickKind:j,bindable:z,bindableCount:D,included:I,commonFields:B,setAll:q,accepts:H,pickField:K,rowProblems:te,commonProblem:ye,canApply:_e,apply:re}=wh({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:o,onApply:a}),De=S.useRef(null),ge=k.edgeColor(u.cardBorder),ve=k.hoverEdgeColor(u.cardBorder,u.tileTitle),[Ge,Z]=S.useState(!1),[Xe,ke]=S.useState(!1);S.useEffect(()=>{e?ke(!0):Z(!1)},[e]),S.useEffect(()=>{Xe&&(ke(!1),Z(d&&I<D))},[Xe]),S.useEffect(()=>{M&&Z(!0)},[M]);const ue=B?.find(P=>P.name===b.trim())?.type,Oe=P=>{if(!ue)return;const F=fr({name:"X",label:w,kind:P,field:b}).type;return Ir(F,ue)?void 0:`${b.trim()} is ${Xo(ue)}, which this control cannot filter.`},Ae=w.trim()||(C?Qo(C):"Filter"),ie=p==="number"?"Any":p==="date"?v?new Date(`${v}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",qe={...Fs(ge,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...Fs(ge,c)["& .MuiToggleButton-root"],textTransform:"none"}},Ye=(P,F,U)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:P??">=",onChange:Y=>F(Y.target.value),inputProps:{"aria-label":U},sx:{width:130},children:ph.filter(Y=>Y.op!=="~").map(Y=>m.jsx($.MenuItem,{value:Y.op,children:Y.label},Y.op))});return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.filterDialog}`,open:e,onClose:i,...d?{}:{initialFocus:De},title:d?f.label??f.name:"Add a filter",description:d?m.jsxs(m.Fragment,{children:[m.jsxs($.Box,{component:"span",sx:{fontFamily:c.font.mono},children:["$",f.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:[d&&m.jsx($.Button,{color:"error",startIcon:m.jsx(k.DeleteOutlineIcon,{}),onClick:()=>l(f.name),sx:P=>({mr:"auto",color:k.dangerTextColor(P)}),children:"Remove filter"}),m.jsx($.Button,{onClick:i,children:"Cancel"}),m.jsx($.Tooltip,{title:_e||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:re,disabled:!_e,children:d?"Apply":"Add filter"})})})]}),children:m.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!d&&r.length>0&&m.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:y.kind,onChange:(P,F)=>{F==="new"?g({kind:"new"}):F==="existing"&&r[0]&&X(r[0])},"aria-label":"Where the filter comes from",sx:qe,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&y.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:y.name,onChange:P=>{const F=r.find(U=>U.name===P.target.value);F&&X(F)},children:r.map(P=>m.jsxs($.MenuItem,{value:P.name,children:[P.label??P.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",P.name]})]},P.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(Ja,{value:b,onChange:K,fields:B,accepts:H,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:De,error:ye!==void 0,helperText:ye??(!d&&C?`Declared as $${C}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:C?Qo(C):"",value:w,onChange:P=>x(P.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),R&&!M&&Ye(L,N,"Comparison"),!d&&y.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(el,{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:mh.map(P=>{const F=P.kind===p,U=Oe(P.kind);return m.jsx($.Tooltip,{title:U??P.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":F,"aria-label":P.label,"aria-disabled":U!==void 0,onClick:()=>{U===void 0&&j(P.kind)},sx:Y=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${F?u.accent:ge}`,boxShadow:F?`0 0 0 1px ${u.accent}`:"none",bgcolor:F?`color-mix(in srgb, ${u.accent} 6%, ${Y.palette.background.paper})`:Y.palette.background.paper,color:F?u.accent:Y.palette.text.secondary,opacity:U?.45:1,cursor:U?"default":"pointer",transition:`border-color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,"&:hover":U||F?{}:{borderColor:ve}}),children:[m.jsx($h,{kind:P.kind}),m.jsx($.Box,{component:"span",sx:{...c.type.caption,fontWeight:F?600:500,color:F?u.accent:"text.primary",textAlign:"center"},children:Sh[P.kind]})]})},P.kind)})}),p==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:v,onChange:P=>_(P.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${ge}`,borderRadius:c.radius.tile,overflow:"hidden"},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(dh,{"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:c.type.label.fontWeight},children:I===D&&D>0?`Applies to all ${I} tile${I===1?"":"s"}`:`Applies to ${I} of ${D} tile${D===1?"":"s"}`}),!M&&b.trim()!==""&&I>0&&m.jsxs($.Box,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx($.Box,{component:"span",sx:{...c.type.code},children:b.trim()})]})]}),!M&&m.jsx($.Button,{size:"small","aria-expanded":Ge,onClick:()=>Z(P=>!P),children:Ge?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:Ge,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${ge}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:D>0&&I===D,indeterminate:I>0&&I<D,disabled:D===0,onChange:P=>q(P.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||T(P=>P.map(F=>({...F,field:b}))),O(P=>!P)},children:M?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:M?1:0},children:t.tiles.map((P,F)=>{if(!ce(P))return null;const U=E[F],Y=P.label??P.name,Se=M?te[F]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:M?"flex-start":"center",opacity:z[F]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!z[F],checked:(U?.include??!1)&&z[F],inputProps:{"aria-label":`Filter ${Y}`},onChange:we=>G(F,{include:we.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:M?1:0},noWrap:!0,children:Y}),z[F]?M&&m.jsxs(m.Fragment,{children:[R&&Ye(U?.op,we=>G(F,{op:we}),`Comparison for ${Y}`),m.jsx(Ja,{value:U?.field??"",onChange:we=>G(F,{field:we}),fields:o?.(P),accepts:H,label:"Field",ariaLabel:`Field for ${Y}`,disabled:!U?.include,error:Se!==void 0,helperText:Se,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:u.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:_h(t.tiles[F]).reason})]},fe(P))})})]})})]}),I===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(el,{children:"Preview"}),m.jsx($.Box,{sx:P=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:P.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:P=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${ge}`,bgcolor:P.palette.background.paper,...c.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:Ae}),m.jsx($.Box,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:ie}),m.jsx(k.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function el({children:e}){const t=be.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const Sh={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function $h({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(oh,{sx:t});case"multiselect":return m.jsx(ih,{sx:t});case"text":return m.jsx(ch,{sx:t});case"number":return m.jsx(lh,{sx:t});case"date":return m.jsx(ah,{sx:t})}}function tl({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=be.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 nl=k.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function _c(e,t,n,r){const[s,o]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&o(structuredClone(e))},[t,e]),{draft:s,patch:c=>o(d=>{if(d===void 0)return d;const f=structuredClone(d);return c(f),f}),apply:c=>{if(s===void 0)return;const d=structuredClone(s);c(d),o(d),JSON.stringify(d)!==JSON.stringify(e)&&n(d)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>o(void 0)}}const Th=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.`,Eh=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Ch="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",Oh="Declared on its source, so its chart is set in the model.",Mh="It names a query, so its chart is set where that query is declared.";function Ih({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:o,duplicateBlocked:i,view:a,viewStatus:l}){const{theme:u}=be.usePublisherTheme(),c=u.ui,{draft:d,apply:f,patch:h,close:y}=_c(t,e!==null,r,n),[g,w]=S.useState(void 0),x=d!==void 0&&ce(d)?d:void 0,p=x!==void 0&&!Hn(x),v=D=>f(I=>{ce(I)&&D(I)}),_=S.useRef(void 0),b=S.useRef(null),E=e!==null;S.useEffect(()=>{E?_.current=t&&ce(t)?t.chart:void 0:w(void 0)},[E]);const T=x?.chart??"default",M=bc(a,T,l),O=x?x.declaration.kind==="query"?Mh:p?x.chart==="custom"?Th(x.chartLines):void 0:Oh:void 0,C=D=>v(I=>{const B=_.current;D===(B??"default")?(B===void 0?delete I.chart:I.chart=B,delete I.chartCarried):(I.chart=D,a?I.chartCarried=a.chart?[a.chart]:[]:delete I.chartCarried)}),A=p?s?void 0:"Its source declares no dimension a click could filter by.":void 0,R=T==="default"?a?.chart:T,L=R!==void 0&&Eh.has(R)?Ch:void 0,G=D=>I=>w({kind:D,anchor:I.currentTarget}),N=O??(R===void 0||!Dh.has(R)?"Only a bar, line, scatter or bar and line chart has a color to set.":void 0),X=Array.from(new Set(u.series.map(k.seriesColorFrom).filter(D=>D!==void 0))).slice(0,8),j=D=>v(I=>{D===void 0?delete I.color:I.color=D.toLowerCase()}),z=(D,I,B)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:D,...B?{secondary:B}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),I&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:I})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:k.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:y,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":x?dt(x):"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:c.radius.menu,border:`1px solid ${k.edgeColor(u.cardBorder)}`,boxShadow:c.shadow.menu}}},children:[x&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":g?.kind==="chart",disabled:O!==void 0,onClick:G("chart"),onKeyDown:D=>{D.key==="ArrowRight"&&O===void 0&&w({kind:"chart",anchor:D.currentTarget})},children:[z("Chart",O?void 0:M.find(D=>D.value===T)?.label,O),m.jsx(nl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),x&&O===void 0&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":g?.kind==="color",disabled:N!==void 0,onClick:G("color"),onKeyDown:D=>{D.key==="ArrowRight"&&N===void 0&&w({kind:"color",anchor:D.currentTarget})},children:[z("Color",N?void 0:x.color??"Theme",N),!N&&m.jsx($o,{color:x.color??u.series[0],trailing:!0}),m.jsx(nl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),p&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:A!==void 0,onClick:()=>{y(),s?.()},children:z("Clickable cells…",void 0,A??L)}),x&&o&&m.jsx($.MenuItem,{disabled:i!==void 0,onClick:()=>{y(),o()},children:z("Duplicate",void 0,i)}),x?.declaration.kind==="opaque"&&m.jsxs($.Typography,{variant:"body2",sx:{color:u.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",x.declaration.why,", so a filter has no single place to go."]}),x&&m.jsx($.Divider,{}),x&&m.jsx($.Box,{"aria-hidden":!0,sx:{px:2,py:.5,...c.type.code,color:"text.secondary"},children:dt(x).replace("->","→")})]}),m.jsx($.Menu,{className:k.reportClasses.menu,open:g?.kind==="chart",anchorEl:g?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:D=>{D.key==="ArrowLeft"&&(D.preventDefault(),w(void 0))}},children:M.filter(D=>D.value!=="custom").map(D=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":D.value===T,disabled:D.disabled===!0,onClick:()=>{C(D.value),w(void 0)},children:[m.jsx($.ListItemText,{primary:D.label,...D.reason??D.hint?{secondary:D.reason??D.hint}:{}}),D.value===T&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:u.accent}})})]},D.value))}),m.jsxs($.Menu,{className:k.reportClasses.menu,open:g?.kind==="color",anchorEl:g?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,"aria-label":"Color",onKeyDown:D=>{D.key==="ArrowLeft"&&(D.preventDefault(),w(void 0))}},children:[m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===void 0,onClick:()=>{j(void 0),w(void 0)},children:[m.jsx($o,{color:u.series[0]}),m.jsx($.ListItemText,{primary:"Theme",secondary:"The page's own colors"}),x?.color===void 0&&m.jsx(rl,{color:u.accent})]}),X.map(D=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===D.toLowerCase(),onClick:()=>{j(D),w(void 0)},children:[m.jsx($o,{color:D}),m.jsx($.ListItemText,{primary:D.toLowerCase()}),x?.color===D.toLowerCase()&&m.jsx(rl,{color:u.accent})]},D)),m.jsx($.Divider,{}),m.jsxs($.MenuItem,{component:"label","aria-checked":x?.color!==void 0&&!X.some(D=>D.toLowerCase()===x.color),role:"menuitemradio",onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),b.current?.click())},children:[m.jsx("input",{ref:b,type:"color","aria-label":"Other color",value:x?.color??Ph(u.series[0]),onChange:D=>{const I=D.target.value;k.isSeriesColor(I)&&h(B=>{ce(B)&&(B.color=I.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx($.ListItemText,{primary:"Other color…"})]})]})]})}const Dh=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Ph=e=>(e&&k.seriesColorFrom(e))??"#000000";function $o({color:e,trailing:t=!1}){return m.jsx($.Box,{"aria-hidden":!0,"data-swatch":t?"trailing":"leading",sx:{width:14,height:14,borderRadius:"3px",bgcolor:e,border:"1px solid rgba(0,0,0,0.15)",...t?{ml:1}:{mr:1.5},flex:"none"}})}function rl({color:e}){return m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:e}})})}const co=e=>e.label??k.tileTitle(dt(e));function jh({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:o,drillSource:i,setDrillSource:a,exitDialog:l,renderViewPreview:u,takenGivenNames:c}){const{filterDialog:d,setFilterDialog:f}=s,{menu:h,setMenu:y}=o,[g,w]=S.useState(),x=h===void 0?void 0:e.document.tiles[h.index],p=x&&ce(x)?x:void 0,v=(()=>{if(!p||!t)return;const _=t.documentViews?.get(p.source??"")?.get(p.name);if(_&&e.document.sources.some(T=>T.name===p.source))return _;if(p.declaration.kind==="inline"||p.declaration.kind==="opaque")return;const b=e.document.sources.find(T=>T.name===p.source)?.base??p.source,E=p.declaration.kind==="reference"?p.declaration.from:p.name;return t.sources.find(T=>T.name===b)?.views.find(T=>T.name===E)})();return m.jsxs(m.Fragment,{children:[m.jsx(kh,{open:d!==void 0,document:e.document,...d?.control?{control:d.control}:{},available:s.available,...c?{takenNames:c}:{},...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>f(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),m.jsx(Ih,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>y(void 0),onCommit:_=>{const b=h?.index;if(b===void 0)return;const E=Kf(_);e.update(T=>{T.tiles[b]=E,E!==_&&k.isPlaced(T.tiles)&&(T.tiles=Rt(T.tiles,n,b))})},view:v,...v===void 0&&p?{viewStatus:t?"unlisted":"loading"}:{},onDuplicate:()=>{h&&o.duplicate(h.index)},...p&&Ws(p)!==void 0?{duplicateBlocked:Ws(p)}:{},...(e.document.sources.find(_=>_.name===p?.source)?.dimensions?.length??0)>0?{onDrills:()=>{w(p?co(p):void 0),a(p?.source)}}:{}}),m.jsx(rh,{open:i!==void 0,document:e.document,source:e.document.sources.find(_=>_.name===i),givenNames:s.controlList.map(_=>_.name),dashboards:r??[],...g?{tileLabel:g}:{},onClose:()=>a(void 0),onApply:_=>e.update(b=>{const T=[...(b.drills??[]).filter(M=>M.source!==i),..._];T.length===0?delete b.drills:b.drills=T})}),m.jsx(k.UnsavedChangesDialog,{...l}),m.jsx(eh,{open:o.addingTile,document:e.document,catalog:t,columns:n,onClose:o.closeAdd,onAdd:o.addTile,onAddText:o.addText,...u?{renderPreview:u}:{}})]})}var Rh=Symbol.for("preact-signals");function uo(){if(Pt>1)Pt--;else{var e,t=!1;for((function(){var s=Gs;for(Gs=void 0;s!==void 0;){var o=s.S;if(o.v===s.v)for(var i=o.t;i!==void 0;i=i.x)i.i===s.i&&(i.i=o.i);s=s.o}})();Pr!==void 0;){var n=Pr;for(Pr=void 0,zs++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Sc(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(zs=0,Pt--,t)throw e}}function Re(e){if(Pt>0)return e();Zo=++Ah,Pt++;try{return e()}finally{uo()}}var Dr,Te=void 0;function ae(e){var t=Te,n=Dr;Te=void 0,Dr=void 0;try{return e()}finally{Te=t,Dr=n}}var Pr=void 0,Pt=0,zs=0,Ah=0,Zo=0,Gs=void 0,Hs=0;function kc(e){if(Te!==void 0){var t=e.n;if(t===void 0||t.t!==Te)return t={i:0,S:e,p:Te.s,n:void 0,t:Te,e:void 0,x:void 0,r:t},Te.s!==void 0&&(Te.s.n=t),Te.s=t,e.n=t,32&Te.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=Te.s,t.n=void 0,Te.s.n=t,Te.s=t),t}}function it(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}it.prototype.brand=Rh;it.prototype.h=function(){return!0};it.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:ae(function(){var r;(r=t.W)==null||r.call(t)}))};it.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&&ae(function(){var s;(s=t.Z)==null||s.call(t)}))}};it.prototype.subscribe=function(e){var t=this;return yt(function(){var n=t.value;ae(function(){return e(n)})},{name:"sub"})};it.prototype.valueOf=function(){return this.value};it.prototype.toString=function(){return this.value+""};it.prototype.toJSON=function(){return this.value};it.prototype.peek=function(){var e=this;return ae(function(){return e.value})};Object.defineProperty(it.prototype,"value",{get:function(){var e=kc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(zs>100)throw new Error("Cycle detected");(function(n){Pt!==0&&zs===0&&n.l!==Zo&&(n.l=Zo,Gs={S:n,v:n.v,i:n.i,o:Gs})})(this),this.v=e,this.i++,Hs++,Pt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{uo()}}}});function qn(e,t){return new it(e,t)}function Sc(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 $c(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 Tc(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function fn(e,t){it.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Hs-1,this.f=4}fn.prototype=new it;fn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Hs))return!0;if(this.g=Hs,this.f|=1,this.i>0&&!Sc(this))return this.f&=-2,!0;var e=Te;try{$c(this),Te=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 Te=e,Tc(this),this.f&=-2,!0};fn.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}it.prototype.S.call(this,e)};fn.prototype.U=function(e){if(this.t!==void 0&&(it.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};fn.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(fn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=kc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function sl(e,t){return new fn(e,t)}function Ec(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Pt++;var n=Te;Te=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Wi(e),r}finally{Te=n,uo()}}}function Wi(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Ec(e)}function Lh(e){if(Te!==this)throw new Error("Out-of-order effect");Tc(this),Te=e,this.f&=-2,8&this.f&&Wi(this),uo()}function Un(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Dr&&Dr.push(this)}Un.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()}};Un.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ec(this),$c(this),Pt++;var e=Te;return Te=this,Lh.bind(this,e)};Un.prototype.N=function(){2&this.f||(this.f|=2,this.u=Pr,Pr=this)};Un.prototype.d=function(){this.f|=8,1&this.f||Wi(this)};Un.prototype.dispose=function(){this.d()};function yt(e,t){var n=new Un(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Bh=Object.create,Ni=Object.defineProperty,Fh=Object.defineProperties,Wh=Object.getOwnPropertyDescriptor,Nh=Object.getOwnPropertyDescriptors,ol=Object.getOwnPropertySymbols,zh=Object.prototype.hasOwnProperty,Gh=Object.prototype.propertyIsEnumerable,Hh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Kn=e=>{throw TypeError(e)},Jo=(e,t,n)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qh=(e,t)=>{for(var n in t||(t={}))zh.call(t,n)&&Jo(e,n,t[n]);if(ol)for(var n of ol(t))Gh.call(t,n)&&Jo(e,n,t[n]);return e},Uh=(e,t)=>Fh(e,Nh(t)),il=(e,t)=>Ni(e,"name",{value:t,configurable:!0}),Kh=e=>{var t;return[,,,Bh((t=void 0)!=null?t:null)]},Cc=["class","method","getter","setter","accessor","field","value","get","set"],hr=e=>e!==void 0&&typeof e!="function"?Kn("Function expected"):e,Vh=(e,t,n,r,s)=>({kind:Cc[e],name:t,metadata:r,addInitializer:o=>n._?Kn("Already initialized"):s.push(hr(o||null))}),Oc=(e,t)=>Jo(t,Hh("metadata"),e[3]),Qt=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Vn=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=Cc[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&Wh(d<4?s:{get[n](){return pt(this,o)},set[n](_){return Nt(this,o,_)}},n));d?h&&d<4&&il(o,(d>2?"set ":d>1?"get ":"")+n):il(s,n);for(var v=r.length-1;v>=0;v--)u=Vh(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>Xh(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?pt:Yh)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>Nt(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?hr(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?Kn("Object expected"):(hr(i=a.get)&&(p.get=i),hr(i=a.set)&&(p.set=i),hr(i=a.init)&&w.unshift(i));return d||Oc(e,s),p&&Ni(s,n,p),h?d^4?o:p:s},zi=(e,t,n)=>t.has(e)||Kn("Cannot "+n),Xh=(e,t)=>Object(t)!==t?Kn('Cannot use the "in" operator on this value'):e.has(t),pt=(e,t,n)=>(zi(e,t,"read from private field"),n?n.call(e):t.get(e)),pr=(e,t,n)=>t.has(e)?Kn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Nt=(e,t,n,r)=>(zi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Yh=(e,t,n)=>(zi(e,t,"access private method"),n);function ei(e,t){if(t){let n;return sl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return sl(e)}function wt(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)=>!wt(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(o=>!wt(e[o],t[o]))}return!1}function le({get:e},t){return{init(n){return qn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function We(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ei(e.bind(this)),n.set(this,r)),r.value}}function To(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,Uh(qh({},s),{enumerable:e}))})}}function Zr(...e){const t=e.map(n=>yt(n));return()=>t.forEach(n=>n())}var Mc,Ic,Dc,Pc,jc,Rc,nt,Gi,Eo,ti,ni,Je,Hi,Co,Ac,ri,qi,Oo,si,oi;Rc=[le],jc=[le],Pc=[le],Dc=[To()],Ic=[To()],Mc=[To()];var hn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Qt(nt,5,this),pr(this,Je),pr(this,Gi,Qt(nt,8,this)),Qt(nt,11,this),pr(this,Hi,Qt(nt,12,this)),Qt(nt,15,this),pr(this,qi,Qt(nt,16,this)),Qt(nt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return pt(this,Je,si)}get initial(){return pt(this,Je,ti)}get previous(){return pt(this,Je,Ac)}set current(e){const t=ae(()=>pt(this,Je,si));e&&t&&this.equals(t,e)||Re(()=>{pt(this,Je,ti)||Nt(this,Je,e,ni),Nt(this,Je,t,ri),Nt(this,Je,e,oi)})}reset(e=this.defaultValue){Re(()=>{Nt(this,Je,void 0,ri),Nt(this,Je,e,ni),Nt(this,Je,e,oi)})}};nt=Kh();Gi=new WeakMap;Je=new WeakSet;Hi=new WeakMap;qi=new WeakMap;Eo=Vn(nt,20,"#initial",Rc,Je,Gi),ti=Eo.get,ni=Eo.set;Co=Vn(nt,20,"#previous",jc,Je,Hi),Ac=Co.get,ri=Co.set;Oo=Vn(nt,20,"#current",Pc,Je,qi),si=Oo.get,oi=Oo.set;Vn(nt,2,"current",Dc,hn);Vn(nt,2,"initial",Ic,hn);Vn(nt,2,"previous",Mc,hn);Oc(nt,hn);function Mo(e){return ae(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Zt,Qh=class{constructor(){pr(this,Zt,new WeakMap)}get(e,t){var n;return e?(n=pt(this,Zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return pt(this,Zt).has(e)||pt(this,Zt).set(e,new Map),(r=pt(this,Zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=pt(this,Zt).get(e))==null?void 0:t.clear():void 0}};Zt=new WeakMap;var Zh=Object.create,Lc=Object.defineProperty,Jh=Object.getOwnPropertyDescriptor,al=Object.getOwnPropertySymbols,ep=Object.prototype.hasOwnProperty,tp=Object.prototype.propertyIsEnumerable,Bc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),fo=e=>{throw TypeError(e)},ll=Math.pow,ii=(e,t,n)=>t in e?Lc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,np=(e,t)=>{for(var n in t||(t={}))ep.call(t,n)&&ii(e,n,t[n]);if(al)for(var n of al(t))tp.call(t,n)&&ii(e,n,t[n]);return e},rp=e=>{var t;return[,,,Zh((t=e?.[Bc("metadata")])!=null?t:null)]},Fc=["class","method","getter","setter","accessor","field","value","get","set"],Wc=e=>e!==void 0&&typeof e!="function"?fo("Function expected"):e,sp=(e,t,n,r,s)=>({kind:Fc[e],name:t,metadata:r,addInitializer:o=>n._?fo("Already initialized"):s.push(Wc(o||null))}),op=(e,t)=>ii(t,Bc("metadata"),e[3]),ip=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Nc=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,y=Fc[c+5],g=e[h]||(e[h]=[]),w=(s=s.prototype,Jh(s,n)),x=r.length-1;x>=0;x--)l=sp(c,n,a={},e[3],g),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(w[y],l),a._=1,Wc(i)&&(w[y]=i);return w&&Lc(s,n,w),s},zc=(e,t,n)=>t.has(e)||fo("Cannot "+n),ap=(e,t,n)=>(zc(e,t,"read from private field"),t.get(e)),lp=(e,t,n)=>t.has(e)?fo("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),cp=(e,t,n,r)=>(zc(e,t,"write to private field"),t.set(e,n),n),gt=class ai{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ai(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 ai(t,n)}},Ct=class Jt{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:o,height:i,scale:a}=this,l=new Jt(s+t,r+n,o,i);return l.scale=np({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:o,bottom:i}=this;return{width:t,height:n,left:r,top:s,right:o,bottom:i}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new gt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Jt))return!1;const{left:n,top:r,width:s,height:o}=this;return n===t.left&&r===t.top&&s===t.width&&o===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:o}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=o}intersectionArea(t){return t instanceof Jt?dp(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 Jt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(o,i)=>{const a=r[i],l=i==="x"?o.left:o.top,u=i==="x"?o.width:o.height;return a=="start"?l:a=="end"?l+u:l+u/2};return gt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Jt.from(t).intersectionRatio(Jt.from(n))}};function dp(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),o=Math.min(t.top+t.height,e.top+e.height),i=s-r,a=o-n;return r<s&&n<o?i*a:0}var Gc,Hc,li,_s,Jr,ho=class extends(li=hn,Hc=[We],Gc=[We],li){constructor(t){const n=gt.from(t);super(n,(r,s)=>gt.equals(r,s)),ip(Jr,5,this),lp(this,_s,0),this.velocity={x:0,y:0}}get delta(){return gt.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=gt.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),i=o-ap(this,_s),a=l=>Math.round(l/i*100);Re(()=>{cp(this,_s,o),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(gt.from(t)),this.velocity={x:0,y:0}}};Jr=rp(li);_s=new WeakMap;Nc(Jr,2,"delta",Hc,ho);Nc(Jr,2,"direction",Gc,ho);op(Jr,ho);function ci({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(ll(r,2)+ll(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 qc=(e=>(e.Horizontal="x",e.Vertical="y",e))(qc||{}),Uc=Object.values(qc),up=Object.create,Ui=Object.defineProperty,fp=Object.defineProperties,hp=Object.getOwnPropertyDescriptor,pp=Object.getOwnPropertyDescriptors,qs=Object.getOwnPropertySymbols,Kc=Object.prototype.hasOwnProperty,Vc=Object.prototype.propertyIsEnumerable,Xc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Xn=e=>{throw TypeError(e)},di=(e,t,n)=>t in e?Ui(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ki=(e,t)=>{for(var n in t||(t={}))Kc.call(t,n)&&di(e,n,t[n]);if(qs)for(var n of qs(t))Vc.call(t,n)&&di(e,n,t[n]);return e},Vi=(e,t)=>fp(e,pp(t)),cl=(e,t)=>Ui(e,"name",{value:t,configurable:!0}),Yc=(e,t)=>{var n={};for(var r in e)Kc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&qs)for(var r of qs(e))t.indexOf(r)<0&&Vc.call(e,r)&&(n[r]=e[r]);return n},Yn=e=>{var t;return[,,,up((t=e?.[Xc("metadata")])!=null?t:null)]},Qc=["class","method","getter","setter","accessor","field","value","get","set"],gr=e=>e!==void 0&&typeof e!="function"?Xn("Function expected"):e,gp=(e,t,n,r,s)=>({kind:Qc[e],name:t,metadata:r,addInitializer:o=>n._?Xn("Already initialized"):s.push(gr(o||null))}),pn=(e,t)=>di(t,Xc("metadata"),e[3]),ee=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},de=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=Qc[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&hp(d<4?s:{get[n](){return Fe(this,o)},set[n](_){return ut(this,o,_)}},n));d?h&&d<4&&cl(o,(d>2?"set ":d>1?"get ":"")+n):cl(s,n);for(var v=r.length-1;v>=0;v--)u=gp(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>mp(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?Fe:Zc)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>ut(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?gr(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?Xn("Object expected"):(gr(i=a.get)&&(p.get=i),gr(i=a.set)&&(p.set=i),gr(i=a.init)&&w.unshift(i));return d||pn(e,s),p&&Ui(s,n,p),h?d^4?o:p:s},Xi=(e,t,n)=>t.has(e)||Xn("Cannot "+n),mp=(e,t)=>Object(t)!==t?Xn('Cannot use the "in" operator on this value'):e.has(t),Fe=(e,t,n)=>(Xi(e,t,"read from private field"),n?n.call(e):t.get(e)),pe=(e,t,n)=>t.has(e)?Xn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ut=(e,t,n,r)=>(Xi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zc=(e,t,n)=>(Xi(e,t,"access private method"),n);function Jc(e,t){return{plugin:e,options:t}}function es(e){return t=>Jc(e,t)}function zr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var ed,Gr,Yi,ks;ed=[le];var et=class{constructor(e,t){this.manager=e,this.options=t,pe(this,Yi,ee(Gr,8,this,!1)),ee(Gr,11,this),pe(this,ks,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ae(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=yt(e.bind(this));return Fe(this,ks).add(t),t}destroy(){Fe(this,ks).forEach(e=>e())}static configure(e){return Jc(this,e)}};Gr=Yn(null);Yi=new WeakMap;ks=new WeakMap;de(Gr,4,"disabled",ed,et,Yi);pn(Gr,et);var ts=class extends et{},Ss,Io=class{constructor(e){this.manager=e,this.instances=new Map,pe(this,Ss,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(zr).reduce((r,s)=>{const o=r.find(({plugin:i})=>i===s.plugin);return o?(o.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Fe(this,Ss))if(!n.includes(r)){if(r.prototype instanceof ts)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);ut(this,Ss,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()}};Ss=new WeakMap;function vp(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var ds=[],Sn,$n,yp=class extends et{constructor(e){super(e),pe(this,Sn),pe(this,$n),this.computeCollisions=this.computeCollisions.bind(this),ut(this,$n,qn(ds)),this.destroy=Zr(()=>{const t=this.computeCollisions(),n=ae(()=>this.manager.dragOperation.position.current);if(t!==ds){const r=Fe(this,Sn);if(ut(this,Sn,n),r&&n.x==r.x&&n.y==r.y)return}else ut(this,Sn,void 0);Fe(this,$n).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ae(()=>{e?Fe(this,$n).value=this.computeCollisions():ut(this,Sn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:o,status:i}=r;if(!i.initialized||!o)return ds;const a=[],l=[];for(const u of e??n.droppables){if(u.disabled||s&&!u.accepts(s))continue;const c=t??u.collisionDetector;if(!c)continue;l.push(u),u.shape;const d=ae(()=>c({droppable:u,dragOperation:r}));d&&(u.collisionPriority!=null&&(d.priority=u.collisionPriority),a.push(d))}return l.length===0?ds:(a.sort(vp),a)}get collisions(){return Fe(this,$n).value}};Sn=new WeakMap;$n=new WeakMap;var td,nd,rd,Qi,sd,_t,Zi,Dn,Ji,ea;rd=[le],nd=[le],td=[le];var At=class en{constructor(t,n){pe(this,Zi,ee(_t,8,this)),ee(_t,11,this),pe(this,Dn),pe(this,Ji,ee(_t,12,this)),ee(_t,15,this),pe(this,ea,ee(_t,16,this)),ee(_t,19,this);const{effects:r,id:s,data:o={},disabled:i=!1,register:a=!0}=t;let l=s;ut(this,Dn,qn(s)),this.manager=n,this.data=o,this.disabled=i,this.effects=()=>{var u;return[()=>{const{id:c,manager:d}=this;if(c!==l)return l=c,d?.registry.register(this),()=>d?.registry.unregister(this)},...(u=r?.())!=null?u:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=Fe(this,Dn).value;return(n=(t=en.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=en.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Fe(this,Dn).peek();t!==s&&(en.pendingIdChanges||(en.pendingIdChanges=new Map,queueMicrotask(()=>{var o;return Zc(o=en,Qi,sd).call(o)})),en.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};_t=Yn(null);Qi=new WeakSet;sd=function(){const e=At.pendingIdChanges;At.pendingIdChanges=null,e&&Re(()=>{for(const[t,n]of e)Fe(t,Dn).value=n})};Zi=new WeakMap;Dn=new WeakMap;Ji=new WeakMap;ea=new WeakMap;de(_t,4,"manager",rd,At,Zi);de(_t,4,"data",nd,At,Ji);de(_t,4,"disabled",td,At,ea);pe(At,Qi);pn(_t,At);At.pendingIdChanges=null;var po=At,dl=class{constructor(){this.map=qn(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 o=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){o.delete(a);break}o.set(e,t),this.map.value=o;const i=Zr(...t.effects());return this.cleanupFunctions.set(t,i),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}},od,id,ad,ld,cd,dd,ui,rt,ta,na,ra,Ot=class extends(ui=po,dd=[le],cd=[le],ld=[le],ad=[We],id=[We],od=[We],ui){constructor(t,n){var r=t,{modifiers:s,type:o,sensors:i,plugins:a,effects:l}=r,u=Yc(r,["modifiers","type","sensors","plugins","effects"]);super(Vi(Ki({},u),{effects:()=>{var c;return[...(c=l?.())!=null?c:[],()=>{const{manager:d,plugins:f}=this;if(!(!d||!f))for(const h of f){const{plugin:y}=zr(h);d.registry.plugins.register(y)}}]}}),n),ee(rt,5,this),pe(this,ta,ee(rt,8,this)),ee(rt,11,this),pe(this,na,ee(rt,12,this)),ee(rt,15,this),pe(this,ra,ee(rt,16,this,this.isDragSource?"dragging":"idle")),ee(rt,19,this),this.type=o,this.sensors=i,this.modifiers=s,this.alignment=u.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=zr(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}};rt=Yn(ui);ta=new WeakMap;na=new WeakMap;ra=new WeakMap;de(rt,4,"type",dd,Ot,ta);de(rt,4,"modifiers",cd,Ot,na);de(rt,4,"status",ld,Ot,ra);de(rt,2,"isDropping",ad,Ot);de(rt,2,"isDragging",id,Ot);de(rt,2,"isDragSource",od,Ot);pn(rt,Ot);var ud,fd,hd,pd,gd,md,fi,Ke,sa,oa,ia,aa,la,Mt=class extends(fi=po,md=[le],gd=[le],pd=[le],hd=[le],fd=[le],ud=[We],fi){constructor(t,n){var r=t,{accept:s,collisionDetector:o,collisionPriority:i,type:a}=r,l=Yc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ee(Ke,5,this),pe(this,sa,ee(Ke,8,this)),ee(Ke,11,this),pe(this,oa,ee(Ke,12,this)),ee(Ke,15,this),pe(this,ia,ee(Ke,16,this)),ee(Ke,19,this),pe(this,aa,ee(Ke,20,this)),ee(Ke,23,this),pe(this,la,ee(Ke,24,this)),ee(Ke,27,this),this.accept=s,this.collisionDetector=o,this.collisionPriority=i,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}};Ke=Yn(fi);sa=new WeakMap;oa=new WeakMap;ia=new WeakMap;aa=new WeakMap;la=new WeakMap;de(Ke,4,"accept",md,Mt,sa);de(Ke,4,"type",gd,Mt,oa);de(Ke,4,"collisionDetector",pd,Mt,ia);de(Ke,4,"collisionPriority",hd,Mt,aa);de(Ke,4,"shape",fd,Mt,la);de(Ke,2,"isDropTarget",ud,Mt);pn(Ke,Mt);var xp=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)}},bp=class extends xp{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function $s(e,t=!0){let n=!1;return Vi(Ki({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var wp=class extends ts{constructor(e){super(e);const t=(r,s)=>r.map(({id:o})=>o).join("")===s.map(({id:o})=>o).join("");let n=[];this.destroy=Zr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:o}=r;if(r.isDisabled()||po.pendingIdChanges)return;const i=$s({collisions:o});if(s.dispatch("collision",i),i.defaultPrevented||t(o,n))return;n=o;const[a]=o;ae(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Qn=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Qn||{}),Zn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Zn||{}),vd,yd,xd,bd,wd,_d,kd,vt,ca;kd=[le],_d=[We],wd=[We],bd=[We],xd=[We],yd=[We],vd=[We];var Bt=class{constructor(){ee(vt,5,this),pe(this,ca,ee(vt,8,this,"idle")),ee(vt,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}};vt=Yn(null);ca=new WeakMap;de(vt,4,"value",kd,Bt,ca);de(vt,2,"current",_d,Bt);de(vt,2,"idle",wd,Bt);de(vt,2,"initializing",bd,Bt);de(vt,2,"initialized",xd,Bt);de(vt,2,"dragging",yd,Bt);de(vt,2,"dropped",vd,Bt);pn(vt,Bt);var _p=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 ae(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=$s({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ae(()=>{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:o}=e;Re(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(o)});const i=$s({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",i),i.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"&&Re(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return ae(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:o}=r;if(!s.dragging||!o||o.signal.aborted)return;const i=$s({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",i),queueMicrotask(()=>{var a,l,u,c,d;if(i.defaultPrevented)return;const f=(d=e.to)!=null?d:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((c=(u=e.by)==null?void 0:u.y)!=null?c:0)};r.position.current=f})})}stop(e={}){return ae(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let o;const i=()=>{const l={resume:()=>{},abort:()=>{}};return o=new Promise((u,c)=>{l.resume=u,l.abort=c}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=ae(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),u=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:c}=r,d=yt(()=>{c?.status==="idle"&&(d(),u())})}else this.manager.renderer.rendering.then(u)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:i}),o?o.then(a).catch(()=>r.reset()):a()})}},Bn=class extends et{constructor(e,t){super(e,t),this.manager=e,this.options=t}},kp=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)}},Ts,Sd=class{constructor(e){this.options=e,pe(this,Ts)}set controller(e){ut(this,Ts,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Fe(this,Ts))==null||t.activate(e)}};Ts=new WeakMap;var ul=class extends et{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Sp=class{constructor(e){this.draggables=new dl,this.droppables=new dl,this.plugins=new Io(e),this.sensors=new Io(e),this.modifiers=new Io(e)}register(e,t){if(e instanceof Ot)return this.draggables.register(e.id,e);if(e instanceof Mt)return this.droppables.register(e.id,e);if(e.prototype instanceof ul)return this.modifiers.register(e,t);if(e.prototype instanceof Bn)return this.sensors.register(e,t);if(e.prototype instanceof et)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof po)return e instanceof Ot?this.draggables.unregister(e.id,e):e instanceof Mt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof ul)return this.modifiers.unregister(e);if(e.prototype instanceof Bn)return this.sensors.unregister(e);if(e.prototype instanceof et)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()}},$d,Td,Ed,Cd,Od,Md,Id,Dd,Pd,mr,Es,Tn,je,da,ua,fa,ha,pa,vr;Pd=[We],Dd=[le],Id=[le],Md=[le],Od=[le],Cd=[le],Ed=[We],Td=[We],$d=[We];var $t=class{constructor(e){ee(je,5,this),pe(this,mr),pe(this,Es),pe(this,Tn,new hn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Bt,pe(this,da,ee(je,8,this,!1)),ee(je,11,this),pe(this,ua,ee(je,12,this,null)),ee(je,15,this),pe(this,fa,ee(je,16,this,null)),ee(je,19,this),pe(this,ha,ee(je,20,this,null)),ee(je,23,this),pe(this,pa,ee(je,24,this,[])),ee(je,27,this),this.position=new ho({x:0,y:0}),pe(this,vr,{x:0,y:0}),ut(this,mr,e)}get shape(){const{current:e,initial:t,previous:n}=Fe(this,Tn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Fe(this,Tn).current=e:Fe(this,Tn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Fe(this,mr).registry.draggables.get(t);return n&&ut(this,Es,n),(e=n??Fe(this,Es))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Fe(this,mr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Vi(Ki({},this.snapshot()),{transform:n}));return ut(this,vr,n),n}snapshot(){return ae(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Fe(this,vr),shape:this.shape?Mo(this.shape):null,position:Mo(this.position),status:Mo(this.status),canceled:this.canceled}))}reset(){Re(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Fe(this,Tn).reset(),this.position.reset({x:0,y:0}),ut(this,vr,{x:0,y:0}),this.modifiers=[]})}};je=Yn(null);mr=new WeakMap;Es=new WeakMap;Tn=new WeakMap;da=new WeakMap;ua=new WeakMap;fa=new WeakMap;ha=new WeakMap;pa=new WeakMap;vr=new WeakMap;de(je,2,"shape",Pd,$t);de(je,4,"canceled",Dd,$t,da);de(je,4,"activatorEvent",Id,$t,ua);de(je,4,"sourceIdentifier",Md,$t,fa);de(je,4,"targetIdentifier",Od,$t,ha);de(je,4,"modifiers",Cd,$t,pa);de(je,2,"source",Ed,$t);de(je,2,"target",Td,$t);de(je,2,"transform",$d,$t);pn(je,$t);var $p={get rendering(){return Promise.resolve()}};function St(e,t){return typeof e=="function"?e(t):e??t}var Tp=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=St(r.plugins,[]),o=St(r.sensors,[]),i=St(r.modifiers,[]),a=(n=r.renderer)!=null?n:$p,l=new bp(this),u=new Sp(this);this.registry=u,this.monitor=l,this.renderer=a,this.actions=new _p(this),this.dragOperation=new $t(this),this.collisionObserver=new yp(this),this.plugins=[wp,...s],this.modifiers=i,this.sensors=o;const{destroy:c}=this,d=Zr(()=>{var f,h,y;const g=ae(()=>this.dragOperation.modifiers),w=this.modifiers;for(const x of g)w.includes(x)||x.destroy();this.dragOperation.modifiers=(y=(h=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:h.map(x=>{const{plugin:p,options:v}=zr(x);return new p(this,v)}))!=null?y:w});this.destroy=()=>{d(),c()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},jd=e=>{throw TypeError(e)},ga=(e,t,n)=>t.has(e)||jd("Cannot "+n),J=(e,t,n)=>(ga(e,t,"read from private field"),t.get(e)),at=(e,t,n)=>t.has(e)?jd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ct=(e,t,n,r)=>(ga(e,t,"write to private field"),t.set(e,n),n),Rd=(e,t,n)=>(ga(e,t,"access private method"),n);function go(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Ad(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:o}=s,a=(go(o)?o.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function mo(e){const{width:t,height:n,top:r,left:s,bottom:o,right:i}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:o,right:i}}function ma(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function ns(e){return"nodeType"in e}function ft(e){var t,n,r;return e?ma(e)?e:ns(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 va(e){const{Document:t}=ft(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Kt(e){return!e||ma(e)?!1:e instanceof ft(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Ld(e){return e instanceof ft(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Jn(e){return e?ma(e)?e.document:ns(e)?va(e)?e:Kt(e)||Ld(e)?e.ownerDocument:document:document:document}function Ep(e){var t,n,r,s;const{documentElement:o}=Jn(e),i=ft(e).visualViewport,a=(t=i?.width)!=null?t:o.clientWidth,l=(n=i?.height)!=null?n:o.clientHeight,u=(r=i?.offsetTop)!=null?r:0,c=(s=i?.offsetLeft)!=null?s:0;return{top:u,left:c,right:c+a,bottom:u+l,width:a,height:l}}function Cp(e,t){if(Op(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Op(e){return e.tagName==="DETAILS"}function Hr(e,t=e.getBoundingClientRect(),n=0){var r,s,o,i,a;let l=t;const{ownerDocument:u}=e,c=(r=u.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==u.documentElement;){if(!Cp(d)){const v=d.getBoundingClientRect(),_=n*(v.bottom-v.top),b=n*(v.right-v.left),E=n*(v.bottom-v.top),T=n*(v.right-v.left);l={top:Math.max(l.top,v.top-_),right:Math.min(l.right,v.right+b),bottom:Math.min(l.bottom,v.bottom+E),left:Math.max(l.left,v.left-T),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}d=d.parentElement}const f=c.visualViewport,h=(s=f?.offsetTop)!=null?s:0,y=(o=f?.offsetLeft)!=null?o:0,g=(i=f?.width)!=null?i:c.innerWidth,w=(a=f?.height)!=null?a:c.innerHeight,x=n*w,p=n*g;return l={top:Math.max(l.top,h-x),right:Math.min(l.right,y+g+p),bottom:Math.min(l.bottom,h+w+x),left:Math.max(l.left,y-p),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function Fn(e){return{x:e.clientX,y:e.clientY}}var Bd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function hi(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...hi(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...hi(s.document,t))}}catch{}return n}function ya(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Fd(){var e,t;const n=ya()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function xa(e){return!e||!ns(e)?!1:e instanceof ft(e).ShadowRoot}function Us(e){if(e&&ns(e)){let t=e.getRootNode();if(xa(t))return t;if(t instanceof Document)return t}return Jn(e)}function ba(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Mp(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((o,i)=>{const a=r[i];if(fl(o)&&fl(a)&&(o.type!=="file"&&(o.value=a.value),o.type==="radio"&&o.name&&(o.name=`Cloned__${o.name}`)),hl(o)&&hl(a)&&a.width>0&&a.height>0){const l=o.getContext("2d");l?.drawImage(a,0,0)}}),n}function fl(e){return"value"in e}function hl(e){return e.tagName==="CANVAS"}function Wd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Ip(r)){const{contentDocument:s}=r;if(s){const{left:o,top:i}=r.getBoundingClientRect();return Wd(s,{x:t-o,y:n-i})}}return r}function Ip(e){return e?.tagName==="IFRAME"}var pi=new WeakMap;function Dp(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 Nd=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 i of n)for(const a of r){const{type:l,listener:u,options:c}=a,d=[i,a];i.addEventListener(l,u,c),this.entries.add(d),s.push(d)}const o=this.entries;return function(){for(const a of s){const[l,{type:u,listener:c,options:d}]=a;l.removeEventListener(u,c,d),o.delete(a)}}}};function Wn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function jp(e){const t=new Set;let n=Wn(e);for(;n;)t.add(n),n=Wn(n);return t}function Pp(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function zd(e,t){const n=()=>performance.now();let r,s;return function(...o){const i=this;s?(r?.(),r=Pp(()=>{e.apply(i,o),s=n()},t-(n()-s))):(e.apply(i,o),s=n())}}function Rp(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 Ap(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Hr(e,t);return n>0&&r>0}var Lp=Bd?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Cs,Bp=class extends Lp{constructor(e){super(t=>{if(!J(this,Cs)){ct(this,Cs,!0);return}e(t,this)}),at(this,Cs,!1)}};Cs=new WeakMap;var pl=Array.from({length:100},(e,t)=>t/100),Gd=75,tn,Ks,Ft,nn,yr,Ze,Pr,xr,Vs,Hd,qd,Ud=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,at(this,Vs),this.disconnect=()=>{var o,i,a;ct(this,Pr,!0),(o=J(this,Ft))==null||o.disconnect(),(i=J(this,nn))==null||i.disconnect(),J(this,yr).disconnect(),(a=J(this,Ze))==null||a.remove()},at(this,tn,!0),at(this,Ks),at(this,Ft),at(this,nn),at(this,yr),at(this,Ze),at(this,Pr,!1),at(this,xr,zd(()=>{var o,i,a;const{element:l}=this;if((o=J(this,nn))==null||o.disconnect(),J(this,Pr)||!J(this,tn)||!l.isConnected)return;const u=(i=l.ownerDocument)!=null?i:document,{innerHeight:c,innerWidth:d}=(a=u.defaultView)!=null?a:window,f=l.getBoundingClientRect(),h=Hr(l,f),{top:y,left:g,bottom:w,right:x}=h,p=-Math.floor(y),v=-Math.floor(g),_=-Math.floor(d-x),b=-Math.floor(c-w),E=`${p}px ${_}px ${b}px ${v}px`;this.boundingClientRect=f,ct(this,nn,new IntersectionObserver(T=>{const[M]=T,{intersectionRect:O}=M;(M.intersectionRatio!==1?M.intersectionRatio:Ct.intersectionRatio(O,Hr(l)))!==1&&J(this,xr).call(this)},{threshold:pl,rootMargin:E,root:u})),J(this,nn).observe(l),Rd(this,Vs,Hd).call(this)},Gd)),this.boundingClientRect=e.getBoundingClientRect(),ct(this,tn,Ap(e,this.boundingClientRect));let r=!0;this.callback=o=>{r&&(r=!1,n.skipInitial)||t(o)};const s=e.ownerDocument;n?.debug&&(ct(this,Ze,document.createElement("div")),J(this,Ze).style.background="rgba(0,0,0,0.15)",J(this,Ze).style.position="fixed",J(this,Ze).style.pointerEvents="none",s.body.appendChild(J(this,Ze))),ct(this,yr,new IntersectionObserver(o=>{var i,a;const l=o[o.length-1],{boundingClientRect:u,isIntersecting:c}=l,{width:d,height:f}=u,h=J(this,tn);ct(this,tn,c),!(!d&&!f)&&(h&&!c?((i=J(this,nn))==null||i.disconnect(),this.callback(null),(a=J(this,Ft))==null||a.disconnect(),ct(this,Ft,void 0),J(this,Ze)&&(J(this,Ze).style.visibility="hidden")):J(this,xr).call(this),c&&!J(this,Ft)&&(ct(this,Ft,new Bp(J(this,xr))),J(this,Ft).observe(e)))},{threshold:pl,root:s})),J(this,tn)&&!n.skipInitial&&this.callback(this.boundingClientRect),J(this,yr).observe(e)}};tn=new WeakMap;Ks=new WeakMap;Ft=new WeakMap;nn=new WeakMap;yr=new WeakMap;Ze=new WeakMap;Pr=new WeakMap;xr=new WeakMap;Vs=new WeakSet;Hd=function(){J(this,Pr)||(Rd(this,Vs,qd).call(this),!Rp(this.boundingClientRect,J(this,Ks))&&(this.callback(this.boundingClientRect),ct(this,Ks,this.boundingClientRect)))};qd=function(){if(J(this,Ze)){const{top:e,left:t,width:n,height:r}=Hr(this.element);J(this,Ze).style.overflow="hidden",J(this,Ze).style.visibility="visible",J(this,Ze).style.top=`${Math.floor(e)}px`,J(this,Ze).style.left=`${Math.floor(t)}px`,J(this,Ze).style.width=`${Math.floor(n)}px`,J(this,Ze).style.height=`${Math.floor(r)}px`}};var us=new WeakMap,fs=new WeakMap;function Fp(e,t){let n=us.get(e);return n||(n={disconnect:new Ud(e,s=>{const o=us.get(e);o&&o.callbacks.forEach(i=>i(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),us.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(us.delete(e),n.disconnect())}}function Wp(e,t){const n=new Set;for(const r of e){const s=Fp(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Np(e,t){var n;const r=e.ownerDocument;if(!fs.has(r)){const i=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(u=>u(l)),{capture:!0,passive:!0,signal:i.signal}),fs.set(r,{disconnect:()=>i.abort(),listeners:a})}const{listeners:s,disconnect:o}=(n=fs.get(r))!=null?n:{};return!s||!o?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(o(),fs.delete(r))})}var br,wr,Os,gi,zp=class{constructor(e,t,n){this.callback=t,at(this,br),at(this,wr,!1),at(this,Os),at(this,gi,zd(i=>{if(!J(this,wr)&&i.target&&"contains"in i.target&&typeof i.target.contains=="function"){for(const a of J(this,Os))if(i.target.contains(a)){this.callback(J(this,br).boundingClientRect);break}}},Gd));const r=jp(e),s=Wp(r,t),o=Np(e,J(this,gi));ct(this,Os,r),ct(this,br,new Ud(e,t,n)),this.disconnect=()=>{J(this,wr)||(ct(this,wr,!0),s(),o(),J(this,br).disconnect())}}};br=new WeakMap;wr=new WeakMap;Os=new WeakMap;gi=new WeakMap;function mi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Pn(e){try{mi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function gl(e){return!Bd||!e?!1:e===Jn(e).scrollingElement}function Kd(e){var t,n;const r=ft(e),s=gl(e)?Ep(e):mo(e),o=r.visualViewport,i=gl(e)?{height:(t=o?.height)!=null?t:r.innerHeight,width:(n=o?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-i.width,y:e.scrollHeight-i.height}},l=a.current.y<=0,u=a.current.x<=0,c=a.current.y>=a.max.y,d=a.current.x>=a.max.x;return{rect:s,position:a,isTop:l,isLeft:u,isBottom:c,isRight:d}}function Gp(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:o,position:i}=Kd(e),{x:a,y:l}=t??{x:0,y:0},u=!n&&i.current.y+l>0,c=!r&&i.current.y+l<i.max.y,d=!s&&i.current.x+a>0,f=!o&&i.current.x+a<i.max.x;return{top:u,bottom:c,left:d,right:f,x:d||f,y:u||c}}var wa=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))}},Xs=new wa(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Hp=new wa(e=>setTimeout(e,50)),Ys=new Map,qp=Ys.clear.bind(Ys);function It(e,t=!1){if(!t)return ml(e);let n=Ys.get(e);return n||(n=ml(e),Ys.set(e,n),Hp.schedule(qp),n)}function ml(e){return ft(e).getComputedStyle(e)}function Up(e,t=It(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Kp(e,t=It(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const o=t[s];return typeof o=="string"?n.test(o):!1})}var Vp={excludeElement:!0,escapeShadowDOM:!0};function vi(e,t=Vp){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,o=new Set;function i(a){if(n!=null&&o.size>=n||!a)return o;if(va(a)&&a.scrollingElement!=null&&!o.has(a.scrollingElement))return o.add(a.scrollingElement),o;if(s&&xa(a))return i(a.host);if(!Kt(a))return Ld(a)?i(a.parentElement):o;if(o.has(a))return o;const l=It(a,!0);if(r&&a===e||Kp(a,l)&&o.add(a),Up(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&o.add(u),o}return i(a.parentNode)}return e?i(e):o}function Nn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Wn(e);for(;r;){if(r===t)return n;const s=mo(r),{x:o,y:i}=Xp(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*o,n.scaleY=n.scaleY*i,r=Wn(r)}return n}function Xp(e,t=mo(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Kt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=It(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Yp(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function qr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),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 vo(e){var t,n,r,s,o,i,a,l,u;const{scale:c,transform:d,translate:f}=e,h=Yp(c),y=qr(f),g=Qp(d);if(!g&&!h&&!y)return null;const w={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},x={x:(r=y?.x)!=null?r:0,y:(s=y?.y)!=null?s:0},p={x:(o=g?.x)!=null?o:0,y:(i=g?.y)!=null?i:0,scaleX:(a=g?.scaleX)!=null?a:1,scaleY:(l=g?.scaleY)!=null?l:1};return{x:x.x+p.x,y:x.y+p.y,z:(u=y?.z)!=null?u:0,scaleX:w.x*p.scaleX,scaleY:w.y*p.scaleY}}function Qp(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 mt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(mt||{}),Zp={x:.2,y:.2},Jp={x:10,y:10};function eg(e,t,n,r=25,s=Zp,o=Jp){const{x:i,y:a}=t,{rect:l,isTop:u,isBottom:c,isLeft:d,isRight:f}=Kd(e),h=Nn(e),y=It(e,!0),g=vo(y),w=g!==null?g?.scaleX<0:!1,x=g!==null?g?.scaleY<0:!1,p=new Ct(l.left*h.scaleX+h.x,l.top*h.scaleY+h.y,l.width*h.scaleX,l.height*h.scaleY),v={x:0,y:0},_={x:0,y:0},b={height:p.height*s.y,width:p.width*s.x};return b.height>0&&(!u||x&&!c)&&a<=p.top+b.height&&n?.y!==1&&i>=p.left-o.x&&i<=p.right+o.x?(v.y=x?1:-1,_.y=r*Math.abs((p.top+b.height-a)/b.height)):b.height>0&&(!c||x&&!u)&&a>=p.bottom-b.height&&n?.y!==-1&&i>=p.left-o.x&&i<=p.right+o.x&&(v.y=x?-1:1,_.y=r*Math.abs((p.bottom-b.height-a)/b.height)),b.width>0&&(!f||w&&!d)&&i>=p.right-b.width&&n?.x!==-1&&a>=p.top-o.y&&a<=p.bottom+o.y?(v.x=w?-1:1,_.x=r*Math.abs((p.right-b.width-i)/b.width)):b.width>0&&(!d||w&&!f)&&i<=p.left+b.width&&n?.x!==1&&a>=p.top-o.y&&a<=p.bottom+o.y&&(v.x=w?1:-1,_.x=r*Math.abs((p.left+b.width-i)/b.width)),{direction:v,speed:_}}function Vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Kt(e))return;const r=vi(e),s=[];for(const o of r){if(!Kt(o))continue;const{top:i,left:a}=tg(e,o);let l=i,u=a;for(const c of s)l-=c.scrollTop,u-=c.scrollLeft;if(t!=="none"){const c=l<o.scrollTop,d=l+e.offsetHeight>o.scrollTop+o.clientHeight;c!==d&&(t==="center"?o.scrollTop=l-o.clientHeight/2+e.offsetHeight/2:c?o.scrollTop=l:o.scrollTop=l+e.offsetHeight-o.clientHeight)}if(n!=="none"){const c=u<o.scrollLeft,d=u+e.offsetWidth>o.scrollLeft+o.clientWidth;c!==d&&(n==="center"?o.scrollLeft=u-o.clientWidth/2+e.offsetWidth/2:c?o.scrollLeft=u:o.scrollLeft=u+e.offsetWidth-o.clientWidth)}s.push(o)}}function vl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Kt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function tg(e,t){const n=vl(e),r=vl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function ng(e,t,n){const{scaleX:r,scaleY:s,x:o,y:i}=t,a=e.left+o+(1-r)*parseFloat(n),l=e.top+i+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,c=s?e.height*s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function rg(e,t,n){const{scaleX:r,scaleY:s,x:o,y:i}=t,a=e.left-o-(1-r)*parseFloat(n),l=e.top-i-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,c=s?e.height/s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function Xd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function yl(e,t=It(e).translate,n=!0){if(n){const r=Ad(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const o=qr(s);if(o)return o}}}if(t){const r=qr(t);if(r)return r}return{x:0,y:0,z:0}}var sg=new wa(e=>setTimeout(e,0)),Rr=new Map,og=Rr.clear.bind(Rr);function ig(e){const t=e.ownerDocument;let n=Rr.get(t);if(n)return n;n=t.getAnimations(),Rr.set(t,n),sg.schedule(og);const r=n.filter(s=>go(s.effect)&&s.effect.target===e);return Rr.set(e,r),n}function ag(e,t){const n=ig(e).filter(r=>{var s,o;if(go(r.effect)){const{target:i}=r.effect;if((o=i&&((s=t.isValidTarget)==null?void 0:s.call(t,i)))!=null?o:!0)return r.effect.getKeyframes().some(l=>{for(const u of t.properties)if(l[u])return!0})}}).map(r=>{const{effect:s,currentTime:o}=r,i=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof i=="number"&&typeof o=="number"&&o<i)return r.currentTime=i,()=>{r.currentTime=o}});if(n.length>0)return()=>n.forEach(r=>r?.())}var Et=class extends Ct{constructor(e,t={}){var n,r,s,o;const{frameTransform:i=Nn(e),ignoreTransforms:a,getBoundingClientRect:l=mo}=t,u=ag(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||ya())&&b.contains(e)}),c=l(e);let{top:d,left:f,width:h,height:y}=c,g;const w=It(e),x=vo(w),p={x:(n=x?.scaleX)!=null?n:1,y:(r=x?.scaleY)!=null?r:1},v=lg(e,w);u?.(),x&&(g=rg(c,x,w.transformOrigin),(a||v)&&(d=g.top,f=g.left,h=g.width,y=g.height));const _={width:(s=g?.width)!=null?s:h,height:(o=g?.height)!=null?o:y};if(v&&!a&&g){const b=ng(g,v,w.transformOrigin);d=b.top,f=b.left,h=b.width,y=b.height,p.x=v.scaleX,p.y=v.scaleY}i&&(a||(f*=i.scaleX,h*=i.scaleX,d*=i.scaleY,y*=i.scaleY),f+=i.x,d+=i.y),super(f,d,h,y),this.scale=p,this.intrinsicWidth=_.width,this.intrinsicHeight=_.height}};function lg(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,o,i=!1;for(const a of n){if(a.playState!=="running")continue;const l=go(a.effect)?a.effect.getKeyframes():[],u=l[l.length-1];if(!u)continue;const{transform:c,translate:d,scale:f}=u;typeof c=="string"&&c&&(r=c,i=!0),typeof d=="string"&&d&&(s=d,i=!0),typeof f=="string"&&f&&(o=f,i=!0)}return i?vo({transform:r??t.transform,translate:s??t.translate,scale:o??t.scale}):null}function Ar(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 cg=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Ar(n))for(const[r,s]of Object.entries(e)){const o=`${t}${r}`;this.initial.has(o)||this.initial.set(o,n.style.getPropertyValue(o)),n.style.setProperty(o,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(Ar(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(Ar(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function dn(e){return e?e instanceof ft(e).Element||ns(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Ur(e){if(!e)return!1;const{KeyboardEvent:t}=ft(e.target);return e instanceof t}function dg(e){if(!e)return!1;const{PointerEvent:t}=ft(e.target);return e instanceof t}function ug(e){if(!dn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||fg(e)}function fg(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Do={};function yi(e){const t=Do[e]==null?0:Do[e]+1;return Do[e]=t,`${e}-${t}`}var _a=({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=gt.distance(t.shape.center,n);return{id:r,value:1/s,type:Zn.PointerIntersection,priority:Qn.High}}return null},hg=({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,o=gt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Zn.ShapeIntersection,priority:Qn.Normal}}return null},Yd=e=>{var t;return(t=_a(e))!=null?t:hg(e)},pg=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const o=r?Ct.from(r.current.boundingRectangle).corners:void 0,a=Ct.from(n.shape.boundingRectangle).corners.reduce((l,u,c)=>{var d;return l+gt.distance(gt.from(u),(d=o?.[c])!=null?d:s.current)},0)/4;return{id:n.id,value:1/a,type:Zn.Collision,priority:Qn.Normal}},gg=Object.create,ka=Object.defineProperty,mg=Object.defineProperties,vg=Object.getOwnPropertyDescriptor,yg=Object.getOwnPropertyDescriptors,Qs=Object.getOwnPropertySymbols,Qd=Object.prototype.hasOwnProperty,Zd=Object.prototype.propertyIsEnumerable,Jd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),er=e=>{throw TypeError(e)},xi=(e,t,n)=>t in e?ka(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Kr=(e,t)=>{for(var n in t||(t={}))Qd.call(t,n)&&xi(e,n,t[n]);if(Qs)for(var n of Qs(t))Zd.call(t,n)&&xi(e,n,t[n]);return e},Sa=(e,t)=>mg(e,yg(t)),xl=(e,t)=>ka(e,"name",{value:t,configurable:!0}),eu=(e,t)=>{var n={};for(var r in e)Qd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Qs)for(var r of Qs(e))t.indexOf(r)<0&&Zd.call(e,r)&&(n[r]=e[r]);return n},tr=e=>{var t;return[,,,gg((t=e?.[Jd("metadata")])!=null?t:null)]},tu=["class","method","getter","setter","accessor","field","value","get","set"],_r=e=>e!==void 0&&typeof e!="function"?er("Function expected"):e,xg=(e,t,n,r,s)=>({kind:tu[e],name:t,metadata:r,addInitializer:o=>n._?er("Already initialized"):s.push(_r(o||null))}),gn=(e,t)=>xi(t,Jd("metadata"),e[3]),Ve=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},xt=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=tu[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&vg(d<4?s:{get[n](){return xe(this,o)},set[n](_){return st(this,o,_)}},n));d?h&&d<4&&xl(o,(d>2?"set ":d>1?"get ":"")+n):xl(s,n);for(var v=r.length-1;v>=0;v--)u=xg(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>bg(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?xe:un)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>st(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?_r(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?er("Object expected"):(_r(i=a.get)&&(p.get=i),_r(i=a.set)&&(p.set=i),_r(i=a.init)&&w.unshift(i));return d||gn(e,s),p&&ka(s,n,p),h?d^4?o:p:s},$a=(e,t,n)=>t.has(e)||er("Cannot "+n),bg=(e,t)=>Object(t)!==t?er('Cannot use the "in" operator on this value'):e.has(t),xe=(e,t,n)=>($a(e,t,"read from private field"),n?n.call(e):t.get(e)),ze=(e,t,n)=>t.has(e)?er("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),st=(e,t,n,r)=>($a(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),un=(e,t,n)=>($a(e,t,"access private method"),n),bl={role:"button",roleDescription:"draggable"},wg="dnd-kit-description",_g="dnd-kit-announcement",kg={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."},Sg={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 $g(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Tg(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Eg(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 Cg=["dragover","dragmove"],Og=class extends et{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=wg,announcement:s=_g}={},announcements:o=Sg,screenReaderInstructions:i=kg,debounce:a=500}=t??{},l=n?`${r}-${n}`:yi(r),u=n?`${s}-${n}`:yi(s);let c,d,f,h;const y=(b=h)=>{!f||!b||f?.nodeValue!==b&&(f.nodeValue=b)},g=()=>Xs.schedule(y),w=Mg(g,a),x=Object.entries(o).map(([b,E])=>this.manager.monitor.addEventListener(b,(T,M)=>{const O=f;if(!O)return;const C=E?.(T,M);C&&O.nodeValue!==C&&(h=C,Cg.includes(b)?w():(g(),w.cancel()))})),p=()=>{let b=[];c?.isConnected||(c=Tg(l,i.draggable),b.push(c)),d?.isConnected||(d=Eg(u),f=document.createTextNode(""),d.appendChild(f),b.push(d)),b.length>0&&document.body.append(...b)},v=new Set;function _(){for(const b of v)b()}this.registerEffect(()=>{var b;v.clear();for(const E of this.manager.registry.draggables.value){const T=(b=E.handle)!=null?b:E.element;if(T){(!c||!d)&&v.add(p),(!$g(T)||ya())&&!T.hasAttribute("tabindex")&&v.add(()=>T.setAttribute("tabindex","0")),!T.hasAttribute("role")&&T.tagName.toLowerCase()!=="button"&&v.add(()=>T.setAttribute("role",bl.role)),T.hasAttribute("aria-roledescription")||v.add(()=>T.setAttribute("aria-roledescription",bl.roleDescription)),T.hasAttribute("aria-describedby")||v.add(()=>T.setAttribute("aria-describedby",l));for(const O of["aria-pressed","aria-grabbed"]){const C=String(E.isDragging);T.getAttribute(O)!==C&&v.add(()=>T.setAttribute(O,C))}const M=String(E.disabled);T.getAttribute("aria-disabled")!==M&&v.add(()=>T.setAttribute("aria-disabled",M))}}v.size>0&&Xs.schedule(_)}),this.destroy=()=>{super.destroy(),c?.remove(),d?.remove(),x.forEach(b=>b())}}};function Mg(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Zs=new Map,nu,ru,su,ou,bi,Lr,Pt,Ta,zn,iu,au,lu,cu,Vt=class extends(bi=ts,ou=[le],su=[We],ru=[We],nu=[We],bi){constructor(t,n){super(t,n),Ve(Pt,5,this),ze(this,zn),ze(this,Lr,new Set),ze(this,Ta,Ve(Pt,8,this,new Set)),Ve(Pt,11,this),this.registerEffect(un(this,zn,iu))}register(t){return xe(this,Lr).add(t),()=>{xe(this,Lr).delete(t)}}addRoot(t){return ae(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{ae(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Us((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Us((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}};Pt=tr(bi);Lr=new WeakMap;Ta=new WeakMap;zn=new WeakSet;iu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of xe(this,Lr))t.push(un(this,zn,au).call(this,n,r));return()=>{for(const n of t)n()}};au=function(e,t){let n=Zs.get(e);n||(n=new Map,Zs.set(e,n));let r=n.get(t);if(!r){const o=va(e)?un(this,zn,lu).call(this,e,n,t):un(this,zn,cu).call(this,e,n,t);if(!o)return()=>{};r=o,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};lu=function(e,t,n){var r;const s=e.createElement("style"),{nonce:o}=(r=this.options)!=null?r:{};o&&s.setAttribute("nonce",o),s.textContent=n,e.head.prepend(s);const i=new MutationObserver(a=>{for(const l of a)for(const u of Array.from(l.removedNodes))if(u===s){e.head.prepend(s);return}});return i.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{i.disconnect(),s.remove(),t.delete(n),t.size===0&&Zs.delete(e)}}};cu=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const o=new s;return o.replaceSync(n),e.adoptedStyleSheets.push(o),{refCount:0,cleanup:()=>{var i;if(xa(e)&&((i=e.host)!=null&&i.isConnected)){const a=e.adoptedStyleSheets.indexOf(o);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Zs.delete(e)}}};xt(Pt,4,"additionalRoots",ou,Vt,Ta);xt(Pt,2,"sourceRoot",su,Vt);xt(Pt,2,"targetRoot",ru,Vt);xt(Pt,2,"roots",nu,Vt);gn(Pt,Vt);Vt.configure=es(Vt);var yo=Vt,Ig=class extends et{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(yo),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}}},rs="data-dnd-",wi=`${rs}dropping`,Qe="--dnd-",Tt=`${rs}dragging`,Js=`${rs}placeholder`,Dg=[Tt,Js,"popover","aria-pressed","aria-grabbing"],jg=["view-transition-name"],Pg=`
|
|
8
|
+
`)}var Nd=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 i of n)for(const a of r){const{type:l,listener:u,options:c}=a,d=[i,a];i.addEventListener(l,u,c),this.entries.add(d),s.push(d)}const o=this.entries;return function(){for(const a of s){const[l,{type:u,listener:c,options:d}]=a;l.removeEventListener(u,c,d),o.delete(a)}}}};function Wn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Pp(e){const t=new Set;let n=Wn(e);for(;n;)t.add(n),n=Wn(n);return t}function jp(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function zd(e,t){const n=()=>performance.now();let r,s;return function(...o){const i=this;s?(r?.(),r=jp(()=>{e.apply(i,o),s=n()},t-(n()-s))):(e.apply(i,o),s=n())}}function Rp(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 Ap(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Hr(e,t);return n>0&&r>0}var Lp=Bd?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Cs,Bp=class extends Lp{constructor(e){super(t=>{if(!J(this,Cs)){ct(this,Cs,!0);return}e(t,this)}),at(this,Cs,!1)}};Cs=new WeakMap;var pl=Array.from({length:100},(e,t)=>t/100),Gd=75,tn,Ks,Ft,nn,yr,Ze,jr,xr,Vs,Hd,qd,Ud=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,at(this,Vs),this.disconnect=()=>{var o,i,a;ct(this,jr,!0),(o=J(this,Ft))==null||o.disconnect(),(i=J(this,nn))==null||i.disconnect(),J(this,yr).disconnect(),(a=J(this,Ze))==null||a.remove()},at(this,tn,!0),at(this,Ks),at(this,Ft),at(this,nn),at(this,yr),at(this,Ze),at(this,jr,!1),at(this,xr,zd(()=>{var o,i,a;const{element:l}=this;if((o=J(this,nn))==null||o.disconnect(),J(this,jr)||!J(this,tn)||!l.isConnected)return;const u=(i=l.ownerDocument)!=null?i:document,{innerHeight:c,innerWidth:d}=(a=u.defaultView)!=null?a:window,f=l.getBoundingClientRect(),h=Hr(l,f),{top:y,left:g,bottom:w,right:x}=h,p=-Math.floor(y),v=-Math.floor(g),_=-Math.floor(d-x),b=-Math.floor(c-w),E=`${p}px ${_}px ${b}px ${v}px`;this.boundingClientRect=f,ct(this,nn,new IntersectionObserver(T=>{const[M]=T,{intersectionRect:O}=M;(M.intersectionRatio!==1?M.intersectionRatio:Ct.intersectionRatio(O,Hr(l)))!==1&&J(this,xr).call(this)},{threshold:pl,rootMargin:E,root:u})),J(this,nn).observe(l),Rd(this,Vs,Hd).call(this)},Gd)),this.boundingClientRect=e.getBoundingClientRect(),ct(this,tn,Ap(e,this.boundingClientRect));let r=!0;this.callback=o=>{r&&(r=!1,n.skipInitial)||t(o)};const s=e.ownerDocument;n?.debug&&(ct(this,Ze,document.createElement("div")),J(this,Ze).style.background="rgba(0,0,0,0.15)",J(this,Ze).style.position="fixed",J(this,Ze).style.pointerEvents="none",s.body.appendChild(J(this,Ze))),ct(this,yr,new IntersectionObserver(o=>{var i,a;const l=o[o.length-1],{boundingClientRect:u,isIntersecting:c}=l,{width:d,height:f}=u,h=J(this,tn);ct(this,tn,c),!(!d&&!f)&&(h&&!c?((i=J(this,nn))==null||i.disconnect(),this.callback(null),(a=J(this,Ft))==null||a.disconnect(),ct(this,Ft,void 0),J(this,Ze)&&(J(this,Ze).style.visibility="hidden")):J(this,xr).call(this),c&&!J(this,Ft)&&(ct(this,Ft,new Bp(J(this,xr))),J(this,Ft).observe(e)))},{threshold:pl,root:s})),J(this,tn)&&!n.skipInitial&&this.callback(this.boundingClientRect),J(this,yr).observe(e)}};tn=new WeakMap;Ks=new WeakMap;Ft=new WeakMap;nn=new WeakMap;yr=new WeakMap;Ze=new WeakMap;jr=new WeakMap;xr=new WeakMap;Vs=new WeakSet;Hd=function(){J(this,jr)||(Rd(this,Vs,qd).call(this),!Rp(this.boundingClientRect,J(this,Ks))&&(this.callback(this.boundingClientRect),ct(this,Ks,this.boundingClientRect)))};qd=function(){if(J(this,Ze)){const{top:e,left:t,width:n,height:r}=Hr(this.element);J(this,Ze).style.overflow="hidden",J(this,Ze).style.visibility="visible",J(this,Ze).style.top=`${Math.floor(e)}px`,J(this,Ze).style.left=`${Math.floor(t)}px`,J(this,Ze).style.width=`${Math.floor(n)}px`,J(this,Ze).style.height=`${Math.floor(r)}px`}};var us=new WeakMap,fs=new WeakMap;function Fp(e,t){let n=us.get(e);return n||(n={disconnect:new Ud(e,s=>{const o=us.get(e);o&&o.callbacks.forEach(i=>i(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),us.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(us.delete(e),n.disconnect())}}function Wp(e,t){const n=new Set;for(const r of e){const s=Fp(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Np(e,t){var n;const r=e.ownerDocument;if(!fs.has(r)){const i=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(u=>u(l)),{capture:!0,passive:!0,signal:i.signal}),fs.set(r,{disconnect:()=>i.abort(),listeners:a})}const{listeners:s,disconnect:o}=(n=fs.get(r))!=null?n:{};return!s||!o?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(o(),fs.delete(r))})}var br,wr,Os,gi,zp=class{constructor(e,t,n){this.callback=t,at(this,br),at(this,wr,!1),at(this,Os),at(this,gi,zd(i=>{if(!J(this,wr)&&i.target&&"contains"in i.target&&typeof i.target.contains=="function"){for(const a of J(this,Os))if(i.target.contains(a)){this.callback(J(this,br).boundingClientRect);break}}},Gd));const r=Pp(e),s=Wp(r,t),o=Np(e,J(this,gi));ct(this,Os,r),ct(this,br,new Ud(e,t,n)),this.disconnect=()=>{J(this,wr)||(ct(this,wr,!0),s(),o(),J(this,br).disconnect())}}};br=new WeakMap;wr=new WeakMap;Os=new WeakMap;gi=new WeakMap;function mi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function jn(e){try{mi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function gl(e){return!Bd||!e?!1:e===Jn(e).scrollingElement}function Kd(e){var t,n;const r=ft(e),s=gl(e)?Ep(e):mo(e),o=r.visualViewport,i=gl(e)?{height:(t=o?.height)!=null?t:r.innerHeight,width:(n=o?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-i.width,y:e.scrollHeight-i.height}},l=a.current.y<=0,u=a.current.x<=0,c=a.current.y>=a.max.y,d=a.current.x>=a.max.x;return{rect:s,position:a,isTop:l,isLeft:u,isBottom:c,isRight:d}}function Gp(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:o,position:i}=Kd(e),{x:a,y:l}=t??{x:0,y:0},u=!n&&i.current.y+l>0,c=!r&&i.current.y+l<i.max.y,d=!s&&i.current.x+a>0,f=!o&&i.current.x+a<i.max.x;return{top:u,bottom:c,left:d,right:f,x:d||f,y:u||c}}var wa=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))}},Xs=new wa(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Hp=new wa(e=>setTimeout(e,50)),Ys=new Map,qp=Ys.clear.bind(Ys);function It(e,t=!1){if(!t)return ml(e);let n=Ys.get(e);return n||(n=ml(e),Ys.set(e,n),Hp.schedule(qp),n)}function ml(e){return ft(e).getComputedStyle(e)}function Up(e,t=It(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Kp(e,t=It(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const o=t[s];return typeof o=="string"?n.test(o):!1})}var Vp={excludeElement:!0,escapeShadowDOM:!0};function vi(e,t=Vp){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,o=new Set;function i(a){if(n!=null&&o.size>=n||!a)return o;if(va(a)&&a.scrollingElement!=null&&!o.has(a.scrollingElement))return o.add(a.scrollingElement),o;if(s&&xa(a))return i(a.host);if(!Kt(a))return Ld(a)?i(a.parentElement):o;if(o.has(a))return o;const l=It(a,!0);if(r&&a===e||Kp(a,l)&&o.add(a),Up(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&o.add(u),o}return i(a.parentNode)}return e?i(e):o}function Nn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Wn(e);for(;r;){if(r===t)return n;const s=mo(r),{x:o,y:i}=Xp(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*o,n.scaleY=n.scaleY*i,r=Wn(r)}return n}function Xp(e,t=mo(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Kt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=It(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Yp(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function qr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),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 vo(e){var t,n,r,s,o,i,a,l,u;const{scale:c,transform:d,translate:f}=e,h=Yp(c),y=qr(f),g=Qp(d);if(!g&&!h&&!y)return null;const w={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},x={x:(r=y?.x)!=null?r:0,y:(s=y?.y)!=null?s:0},p={x:(o=g?.x)!=null?o:0,y:(i=g?.y)!=null?i:0,scaleX:(a=g?.scaleX)!=null?a:1,scaleY:(l=g?.scaleY)!=null?l:1};return{x:x.x+p.x,y:x.y+p.y,z:(u=y?.z)!=null?u:0,scaleX:w.x*p.scaleX,scaleY:w.y*p.scaleY}}function Qp(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 mt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(mt||{}),Zp={x:.2,y:.2},Jp={x:10,y:10};function eg(e,t,n,r=25,s=Zp,o=Jp){const{x:i,y:a}=t,{rect:l,isTop:u,isBottom:c,isLeft:d,isRight:f}=Kd(e),h=Nn(e),y=It(e,!0),g=vo(y),w=g!==null?g?.scaleX<0:!1,x=g!==null?g?.scaleY<0:!1,p=new Ct(l.left*h.scaleX+h.x,l.top*h.scaleY+h.y,l.width*h.scaleX,l.height*h.scaleY),v={x:0,y:0},_={x:0,y:0},b={height:p.height*s.y,width:p.width*s.x};return b.height>0&&(!u||x&&!c)&&a<=p.top+b.height&&n?.y!==1&&i>=p.left-o.x&&i<=p.right+o.x?(v.y=x?1:-1,_.y=r*Math.abs((p.top+b.height-a)/b.height)):b.height>0&&(!c||x&&!u)&&a>=p.bottom-b.height&&n?.y!==-1&&i>=p.left-o.x&&i<=p.right+o.x&&(v.y=x?-1:1,_.y=r*Math.abs((p.bottom-b.height-a)/b.height)),b.width>0&&(!f||w&&!d)&&i>=p.right-b.width&&n?.x!==-1&&a>=p.top-o.y&&a<=p.bottom+o.y?(v.x=w?-1:1,_.x=r*Math.abs((p.right-b.width-i)/b.width)):b.width>0&&(!d||w&&!f)&&i<=p.left+b.width&&n?.x!==1&&a>=p.top-o.y&&a<=p.bottom+o.y&&(v.x=w?1:-1,_.x=r*Math.abs((p.left+b.width-i)/b.width)),{direction:v,speed:_}}function Vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Kt(e))return;const r=vi(e),s=[];for(const o of r){if(!Kt(o))continue;const{top:i,left:a}=tg(e,o);let l=i,u=a;for(const c of s)l-=c.scrollTop,u-=c.scrollLeft;if(t!=="none"){const c=l<o.scrollTop,d=l+e.offsetHeight>o.scrollTop+o.clientHeight;c!==d&&(t==="center"?o.scrollTop=l-o.clientHeight/2+e.offsetHeight/2:c?o.scrollTop=l:o.scrollTop=l+e.offsetHeight-o.clientHeight)}if(n!=="none"){const c=u<o.scrollLeft,d=u+e.offsetWidth>o.scrollLeft+o.clientWidth;c!==d&&(n==="center"?o.scrollLeft=u-o.clientWidth/2+e.offsetWidth/2:c?o.scrollLeft=u:o.scrollLeft=u+e.offsetWidth-o.clientWidth)}s.push(o)}}function vl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Kt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function tg(e,t){const n=vl(e),r=vl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function ng(e,t,n){const{scaleX:r,scaleY:s,x:o,y:i}=t,a=e.left+o+(1-r)*parseFloat(n),l=e.top+i+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,c=s?e.height*s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function rg(e,t,n){const{scaleX:r,scaleY:s,x:o,y:i}=t,a=e.left-o-(1-r)*parseFloat(n),l=e.top-i-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,c=s?e.height/s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function Xd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function yl(e,t=It(e).translate,n=!0){if(n){const r=Ad(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const o=qr(s);if(o)return o}}}if(t){const r=qr(t);if(r)return r}return{x:0,y:0,z:0}}var sg=new wa(e=>setTimeout(e,0)),Rr=new Map,og=Rr.clear.bind(Rr);function ig(e){const t=e.ownerDocument;let n=Rr.get(t);if(n)return n;n=t.getAnimations(),Rr.set(t,n),sg.schedule(og);const r=n.filter(s=>go(s.effect)&&s.effect.target===e);return Rr.set(e,r),n}function ag(e,t){const n=ig(e).filter(r=>{var s,o;if(go(r.effect)){const{target:i}=r.effect;if((o=i&&((s=t.isValidTarget)==null?void 0:s.call(t,i)))!=null?o:!0)return r.effect.getKeyframes().some(l=>{for(const u of t.properties)if(l[u])return!0})}}).map(r=>{const{effect:s,currentTime:o}=r,i=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof i=="number"&&typeof o=="number"&&o<i)return r.currentTime=i,()=>{r.currentTime=o}});if(n.length>0)return()=>n.forEach(r=>r?.())}var Et=class extends Ct{constructor(e,t={}){var n,r,s,o;const{frameTransform:i=Nn(e),ignoreTransforms:a,getBoundingClientRect:l=mo}=t,u=ag(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||ya())&&b.contains(e)}),c=l(e);let{top:d,left:f,width:h,height:y}=c,g;const w=It(e),x=vo(w),p={x:(n=x?.scaleX)!=null?n:1,y:(r=x?.scaleY)!=null?r:1},v=lg(e,w);u?.(),x&&(g=rg(c,x,w.transformOrigin),(a||v)&&(d=g.top,f=g.left,h=g.width,y=g.height));const _={width:(s=g?.width)!=null?s:h,height:(o=g?.height)!=null?o:y};if(v&&!a&&g){const b=ng(g,v,w.transformOrigin);d=b.top,f=b.left,h=b.width,y=b.height,p.x=v.scaleX,p.y=v.scaleY}i&&(a||(f*=i.scaleX,h*=i.scaleX,d*=i.scaleY,y*=i.scaleY),f+=i.x,d+=i.y),super(f,d,h,y),this.scale=p,this.intrinsicWidth=_.width,this.intrinsicHeight=_.height}};function lg(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,o,i=!1;for(const a of n){if(a.playState!=="running")continue;const l=go(a.effect)?a.effect.getKeyframes():[],u=l[l.length-1];if(!u)continue;const{transform:c,translate:d,scale:f}=u;typeof c=="string"&&c&&(r=c,i=!0),typeof d=="string"&&d&&(s=d,i=!0),typeof f=="string"&&f&&(o=f,i=!0)}return i?vo({transform:r??t.transform,translate:s??t.translate,scale:o??t.scale}):null}function Ar(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 cg=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Ar(n))for(const[r,s]of Object.entries(e)){const o=`${t}${r}`;this.initial.has(o)||this.initial.set(o,n.style.getPropertyValue(o)),n.style.setProperty(o,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(Ar(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(Ar(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function dn(e){return e?e instanceof ft(e).Element||ns(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Ur(e){if(!e)return!1;const{KeyboardEvent:t}=ft(e.target);return e instanceof t}function dg(e){if(!e)return!1;const{PointerEvent:t}=ft(e.target);return e instanceof t}function ug(e){if(!dn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||fg(e)}function fg(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Do={};function yi(e){const t=Do[e]==null?0:Do[e]+1;return Do[e]=t,`${e}-${t}`}var _a=({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=gt.distance(t.shape.center,n);return{id:r,value:1/s,type:Zn.PointerIntersection,priority:Qn.High}}return null},hg=({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,o=gt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Zn.ShapeIntersection,priority:Qn.Normal}}return null},Yd=e=>{var t;return(t=_a(e))!=null?t:hg(e)},pg=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const o=r?Ct.from(r.current.boundingRectangle).corners:void 0,a=Ct.from(n.shape.boundingRectangle).corners.reduce((l,u,c)=>{var d;return l+gt.distance(gt.from(u),(d=o?.[c])!=null?d:s.current)},0)/4;return{id:n.id,value:1/a,type:Zn.Collision,priority:Qn.Normal}},gg=Object.create,ka=Object.defineProperty,mg=Object.defineProperties,vg=Object.getOwnPropertyDescriptor,yg=Object.getOwnPropertyDescriptors,Qs=Object.getOwnPropertySymbols,Qd=Object.prototype.hasOwnProperty,Zd=Object.prototype.propertyIsEnumerable,Jd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),er=e=>{throw TypeError(e)},xi=(e,t,n)=>t in e?ka(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Kr=(e,t)=>{for(var n in t||(t={}))Qd.call(t,n)&&xi(e,n,t[n]);if(Qs)for(var n of Qs(t))Zd.call(t,n)&&xi(e,n,t[n]);return e},Sa=(e,t)=>mg(e,yg(t)),xl=(e,t)=>ka(e,"name",{value:t,configurable:!0}),eu=(e,t)=>{var n={};for(var r in e)Qd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Qs)for(var r of Qs(e))t.indexOf(r)<0&&Zd.call(e,r)&&(n[r]=e[r]);return n},tr=e=>{var t;return[,,,gg((t=e?.[Jd("metadata")])!=null?t:null)]},tu=["class","method","getter","setter","accessor","field","value","get","set"],_r=e=>e!==void 0&&typeof e!="function"?er("Function expected"):e,xg=(e,t,n,r,s)=>({kind:tu[e],name:t,metadata:r,addInitializer:o=>n._?er("Already initialized"):s.push(_r(o||null))}),gn=(e,t)=>xi(t,Jd("metadata"),e[3]),Ve=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},xt=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=tu[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&vg(d<4?s:{get[n](){return xe(this,o)},set[n](_){return st(this,o,_)}},n));d?h&&d<4&&xl(o,(d>2?"set ":d>1?"get ":"")+n):xl(s,n);for(var v=r.length-1;v>=0;v--)u=xg(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>bg(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?xe:un)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>st(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?_r(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?er("Object expected"):(_r(i=a.get)&&(p.get=i),_r(i=a.set)&&(p.set=i),_r(i=a.init)&&w.unshift(i));return d||gn(e,s),p&&ka(s,n,p),h?d^4?o:p:s},$a=(e,t,n)=>t.has(e)||er("Cannot "+n),bg=(e,t)=>Object(t)!==t?er('Cannot use the "in" operator on this value'):e.has(t),xe=(e,t,n)=>($a(e,t,"read from private field"),n?n.call(e):t.get(e)),ze=(e,t,n)=>t.has(e)?er("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),st=(e,t,n,r)=>($a(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),un=(e,t,n)=>($a(e,t,"access private method"),n),bl={role:"button",roleDescription:"draggable"},wg="dnd-kit-description",_g="dnd-kit-announcement",kg={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."},Sg={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 $g(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Tg(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Eg(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 Cg=["dragover","dragmove"],Og=class extends et{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=wg,announcement:s=_g}={},announcements:o=Sg,screenReaderInstructions:i=kg,debounce:a=500}=t??{},l=n?`${r}-${n}`:yi(r),u=n?`${s}-${n}`:yi(s);let c,d,f,h;const y=(b=h)=>{!f||!b||f?.nodeValue!==b&&(f.nodeValue=b)},g=()=>Xs.schedule(y),w=Mg(g,a),x=Object.entries(o).map(([b,E])=>this.manager.monitor.addEventListener(b,(T,M)=>{const O=f;if(!O)return;const C=E?.(T,M);C&&O.nodeValue!==C&&(h=C,Cg.includes(b)?w():(g(),w.cancel()))})),p=()=>{let b=[];c?.isConnected||(c=Tg(l,i.draggable),b.push(c)),d?.isConnected||(d=Eg(u),f=document.createTextNode(""),d.appendChild(f),b.push(d)),b.length>0&&document.body.append(...b)},v=new Set;function _(){for(const b of v)b()}this.registerEffect(()=>{var b;v.clear();for(const E of this.manager.registry.draggables.value){const T=(b=E.handle)!=null?b:E.element;if(T){(!c||!d)&&v.add(p),(!$g(T)||ya())&&!T.hasAttribute("tabindex")&&v.add(()=>T.setAttribute("tabindex","0")),!T.hasAttribute("role")&&T.tagName.toLowerCase()!=="button"&&v.add(()=>T.setAttribute("role",bl.role)),T.hasAttribute("aria-roledescription")||v.add(()=>T.setAttribute("aria-roledescription",bl.roleDescription)),T.hasAttribute("aria-describedby")||v.add(()=>T.setAttribute("aria-describedby",l));for(const O of["aria-pressed","aria-grabbed"]){const C=String(E.isDragging);T.getAttribute(O)!==C&&v.add(()=>T.setAttribute(O,C))}const M=String(E.disabled);T.getAttribute("aria-disabled")!==M&&v.add(()=>T.setAttribute("aria-disabled",M))}}v.size>0&&Xs.schedule(_)}),this.destroy=()=>{super.destroy(),c?.remove(),d?.remove(),x.forEach(b=>b())}}};function Mg(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Zs=new Map,nu,ru,su,ou,bi,Lr,jt,Ta,zn,iu,au,lu,cu,Vt=class extends(bi=ts,ou=[le],su=[We],ru=[We],nu=[We],bi){constructor(t,n){super(t,n),Ve(jt,5,this),ze(this,zn),ze(this,Lr,new Set),ze(this,Ta,Ve(jt,8,this,new Set)),Ve(jt,11,this),this.registerEffect(un(this,zn,iu))}register(t){return xe(this,Lr).add(t),()=>{xe(this,Lr).delete(t)}}addRoot(t){return ae(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{ae(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Us((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Us((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}};jt=tr(bi);Lr=new WeakMap;Ta=new WeakMap;zn=new WeakSet;iu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of xe(this,Lr))t.push(un(this,zn,au).call(this,n,r));return()=>{for(const n of t)n()}};au=function(e,t){let n=Zs.get(e);n||(n=new Map,Zs.set(e,n));let r=n.get(t);if(!r){const o=va(e)?un(this,zn,lu).call(this,e,n,t):un(this,zn,cu).call(this,e,n,t);if(!o)return()=>{};r=o,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};lu=function(e,t,n){var r;const s=e.createElement("style"),{nonce:o}=(r=this.options)!=null?r:{};o&&s.setAttribute("nonce",o),s.textContent=n,e.head.prepend(s);const i=new MutationObserver(a=>{for(const l of a)for(const u of Array.from(l.removedNodes))if(u===s){e.head.prepend(s);return}});return i.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{i.disconnect(),s.remove(),t.delete(n),t.size===0&&Zs.delete(e)}}};cu=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const o=new s;return o.replaceSync(n),e.adoptedStyleSheets.push(o),{refCount:0,cleanup:()=>{var i;if(xa(e)&&((i=e.host)!=null&&i.isConnected)){const a=e.adoptedStyleSheets.indexOf(o);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Zs.delete(e)}}};xt(jt,4,"additionalRoots",ou,Vt,Ta);xt(jt,2,"sourceRoot",su,Vt);xt(jt,2,"targetRoot",ru,Vt);xt(jt,2,"roots",nu,Vt);gn(jt,Vt);Vt.configure=es(Vt);var yo=Vt,Ig=class extends et{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(yo),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}}},rs="data-dnd-",wi=`${rs}dropping`,Qe="--dnd-",Tt=`${rs}dragging`,Js=`${rs}placeholder`,Dg=[Tt,Js,"popover","aria-pressed","aria-grabbing"],Pg=["view-transition-name"],jg=`
|
|
9
9
|
:is(:root,:host) [${Tt}] {
|
|
10
10
|
position: fixed !important;
|
|
11
11
|
pointer-events: none !important;
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
display: none;
|
|
65
65
|
visibility: hidden;
|
|
66
66
|
}
|
|
67
|
-
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Rg(e,t="hidden"){return ae(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Ag(n,r.registry.droppables),o=[],i=Mp(n),{remove:a}=i;return Lg(s,i,o),Bg(i,t),i.remove=()=>{o.forEach(l=>l()),a.call(i)},i})}function Ag(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${rs}${yi("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Lg(e,t,n){for(const[r,s]of e){if(!r.element)continue;const o=`[${s}]`,i=t.matches(o)?t:t.querySelector(o);if(r.element.removeAttribute(s),!i)continue;const a=r.element;r.proxy=i,i.removeAttribute(s),pi.set(a,i),n.push(()=>{pi.delete(a),r.proxy=void 0})}}function Bg(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Js,t)}function du(e,t){return e===t?!0:Wn(e)===Wn(t)}function wl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&dn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Pn(t))}function _i(e){return e.tagName==="TR"}function Fg(e,t,n){const r=new MutationObserver(s=>{let o=!1;for(const i of s){if(i.target!==e){o=!0;continue}if(i.type!=="attributes")continue;const a=i.attributeName;if(a.startsWith("aria-")||Dg.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(Ar(e)&&Ar(t)){const u=e.style;for(const c of Array.from(t.style))u.getPropertyValue(c)===""&&t.style.removeProperty(c);for(const c of Array.from(u)){if(jg.includes(c)||c.startsWith(Qe))continue;const d=u.getPropertyValue(c);t.style.setProperty(c,d)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}o&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Wg(e,t,n){const r=new MutationObserver(s=>{for(const o of s)if(o.addedNodes.length!==0)for(const i of Array.from(o.addedNodes)){if(i.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),Pn(n);return}if(i.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Pn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Pn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Ng(e){return new ResizeObserver(()=>{var t,n,r;const s=new Et(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),o=(t=e.transformOrigin)!=null?t:{x:1,y:1},i=(e.width-s.width)*o.x+e.delta.x,a=(e.height-s.height)*o.y+e.delta.y,l=Fd();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+i+l.x},Qe),(n=e.getElementMutationObserver())==null||n.takeRecords(),_i(e.element)&&_i(e.placeholder)){const g=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(g.map(x=>x.style.width));for(const[x,p]of g.entries()){const v=w[x];p.style.width=`${v.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},c=e.left+i+l.x+u.x,d=e.top+a+l.y+u.y,f=s.width-e.widthOffset,h=s.height-e.heightOffset,y=e.frameTransform;e.dragOperation.shape=new Ct(c*y.scaleX+y.x,d*y.scaleY+y.y,f*y.scaleX,h*y.scaleY)})}var zg=250,Gg="ease";function Hg(e){var t,n,r,s;const{animation:o}=e;if(typeof o=="function"){const p=o({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(p).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:i=zg,easing:a=Gg}=o??{};Pn(e.feedbackElement);const[,l]=(t=Ad(e.feedbackElement,p=>"translate"in p))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,c={frameTransform:du(e.feedbackElement,u)?null:void 0},d=new Et(e.feedbackElement,c),f=(r=qr(It(e.feedbackElement).translate))!=null?r:e.translate,h=new Et(u,c),y=Ct.delta(d,h,e.alignment),g={x:f.x-y.x,y:f.y-y.y},w=Math.round(d.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},x=Math.round(d.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Qe),e.feedbackElement.setAttribute(wi,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),Xd({element:e.feedbackElement,keyframes:Sa(Kr(Kr({},w),x),{translate:[`${f.x}px ${f.y}px 0`,`${g.x}px ${g.y}px 0`]}),options:{duration:ba(ft(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?i:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(wi),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var uu,ki,Vr,Ea,Ms,fu,hu,Gn=class extends(ki=et,uu=[le],ki){constructor(t,n){super(t,n),ze(this,Ms),ze(this,Ea,Ve(Vr,8,this)),Ve(Vr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(yo),s=r?.register(Pg);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}this.registerEffect(un(this,Ms,fu).bind(this,r)),this.registerEffect(un(this,Ms,hu))}};Vr=tr(ki);Ea=new WeakMap;Ms=new WeakSet;fu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Us(t);if(n)return e.addRoot(n)};hu=function(){var e,t,n,r,s,o,i;const{state:a,manager:l,options:u}=this,{dragOperation:c}=l,{position:d,source:f,status:h}=c;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:y}=f,g=f.pluginConfig(Gn),w=(t=(e=g?.feedback)!=null?e:u?.feedback)!=null?t:"default",x=typeof w=="function"?w(f,l):w;if(!y||x==="none"||!h.initialized||h.initializing)return;const{initial:p}=a,v=(n=this.overlay)!=null?n:y,_=Nn(v),b=Nn(y),E=!du(y,v),T=new Et(y,{frameTransform:E?b:null,ignoreTransforms:!E}),M={x:b.scaleX/_.scaleX,y:b.scaleY/_.scaleY};let{width:O,height:C,top:A,left:R}=T;E&&(O=O/M.x,C=C/M.y);const L=new cg(v),G=It(y),{transition:N,translate:X,boxSizing:P,paddingBlockStart:z,paddingBlockEnd:D,paddingInlineStart:I,paddingInlineEnd:B,borderInlineStartWidth:q,borderInlineEndWidth:H,borderBlockStartWidth:K,borderBlockEndWidth:te}=G,ye=N.split(",").filter(ne=>!/^\s*(transform|translate|scale)\b/.test(ne)).join(","),_e=vo(G),re=G.transform,De=x==="clone",ge=P==="content-box",ve=ge?parseInt(I)+parseInt(B)+parseInt(q)+parseInt(H):0,Ge=ge?parseInt(z)+parseInt(D)+parseInt(K)+parseInt(te):0,Z=x!=="move"&&!this.overlay?Rg(f,De?"clone":"hidden"):null,Xe=ae(()=>Ur(l.dragOperation.activatorEvent));if(!p.translate){if(this.overlay&&_e)p.translate={x:_e.x,y:_e.y};else if(X!=="none"){const ne=qr(X);ne&&(p.translate=ne)}}if(!p.transformOrigin){const ne=ae(()=>d.current),oe=R+((r=_e?.x)!=null?r:0),Ue=A+((s=_e?.y)!=null?s:0);p.transformOrigin={x:(ne.x-oe*_.scaleX-_.x)/(O*_.scaleX),y:(ne.y-Ue*_.scaleY-_.y)/(C*_.scaleY)}}const{transformOrigin:ke}=p,ue=A*_.scaleY+_.y,Oe=R*_.scaleX+_.x;if(!p.coordinates&&(p.coordinates={x:Oe,y:ue},M.x!==1||M.y!==1)){const{scaleX:ne,scaleY:oe}=b,{x:Ue,y:bt}=ke;p.coordinates.x+=(O*ne-O)*Ue,p.coordinates.y+=(C*oe-C)*bt}p.dimensions||(p.dimensions={width:O,height:C}),p.frameTransform||(p.frameTransform=_);const Ae={x:p.coordinates.x-Oe,y:p.coordinates.y-ue},ie={width:(p.dimensions.width*p.frameTransform.scaleX-O*_.scaleX)*ke.x,height:(p.dimensions.height*p.frameTransform.scaleY-C*_.scaleY)*ke.y},qe={x:Ae.x/_.scaleX+ie.width,y:Ae.y/_.scaleY+ie.height},Ye={left:R+qe.x,top:A+qe.y};v.setAttribute(Tt,"true");const j=ae(()=>c.transform),F=(o=p.translate)!=null?o:{x:0,y:0},U=j.x*_.scaleX+F.x,Y=j.y*_.scaleY+F.y,Se=Fd();L.set({width:O-ve,height:C-Ge,top:Ye.top+Se.y,left:Ye.left+Se.x,translate:`${U}px ${Y}px 0`,transform:this.overlay?"none":re,transition:ye?`${ye}, translate 0ms linear`:"translate 0ms linear",scale:E?`${M.x} ${M.y}`:"","transform-origin":`${ke.x*100}% ${ke.y*100}%`},Qe),Z&&(y.insertAdjacentElement("afterend",Z),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(y)),mi(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),Pn(v),v.addEventListener("beforetoggle",wl));let we,ht,W;const Q=Ng({placeholder:Z,element:y,feedbackElement:v,frameTransform:_,transformOrigin:ke,width:O,height:C,top:A,left:R,widthOffset:ve,heightOffset:Ge,delta:qe,styles:L,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>we,getSavedCellWidths:()=>W,setSavedCellWidths:ne=>{W=ne}}),Le=new Et(v);ae(()=>c.shape=Le);const Be=ft(v),lt=ne=>{this.manager.actions.stop({event:ne})},he=ba(Be);Xe&&Be.addEventListener("resize",lt),ae(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),Z&&(Q.observe(Z),we=Fg(y,Z,De),ht=Wg(y,Z,v));const tt=(i=l.dragOperation.source)==null?void 0:i.id,V=()=>{var ne;if(!Xe||tt==null)return;const oe=l.registry.draggables.get(tt),Ue=(ne=oe?.handle)!=null?ne:oe?.element;Kt(Ue)&&Ue.focus()},se=()=>{we?.disconnect(),ht?.disconnect(),Q.disconnect(),Be.removeEventListener("resize",lt),mi(v)&&(v.removeEventListener("beforetoggle",wl),v.removeAttribute("popover")),v.removeAttribute(Tt),L.reset();const ne=()=>{var oe;if(W&&_i(y)){const or=Array.from(y.cells);for(const[mn,vn]of or.entries())vn.style.width=(oe=W[mn])!=null?oe:""}f.status="idle";const Ue=a.current.translate!=null,bt=c.status.dragging;Z&&(!bt&&Ue||Z.parentElement!==v.parentElement)&&v.isConnected&&Z.replaceWith(v),Z?.remove()};v===this.overlay?setTimeout(ne,0):ne()},Me=u?.dropAnimation,$e=this,Yt=Zr(()=>{var ne,oe,Ue;const{transform:bt,status:or}=c;if(!(!bt.x&&!bt.y&&!a.current.translate)&&or.dragging){const mn=(ne=p.translate)!=null?ne:{x:0,y:0},vn={x:bt.x/_.scaleX+mn.x,y:bt.y/_.scaleY+mn.y},qa=a.current.translate,Wf=ae(()=>c.modifiers),ko=ae(()=>{var ar;return(ar=c.shape)==null?void 0:ar.current}),ir=u?.keyboardTransition,Ua=Xe&&!he&&ir!==null?`${(oe=ir?.duration)!=null?oe:250}ms ${(Ue=ir?.easing)!=null?Ue:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:ye?`${ye}, translate ${Ua}`:`translate ${Ua}`,translate:`${vn.x}px ${vn.y}px 0`},Qe),we?.takeRecords(),ko&&ko!==Le&&qa&&!Wf.length){const ar=gt.delta(vn,qa);c.shape=Ct.from(ko.boundingRectangle).translate(ar.x*_.scaleX,ar.y*_.scaleY)}else c.shape=new Et(v);a.current.translate=vn}},function(){if(c.status.dropped){this.dispose(),f.status="dropping";const ne=g?.dropAnimation!==void 0?g.dropAnimation:$e.dropAnimation!==void 0?$e.dropAnimation:Me;let oe=a.current.translate;const Ue=oe!=null;if(!oe&&y!==v&&(oe={x:0,y:0}),!oe||ne===null){se();return}l.renderer.rendering.then(()=>{Hg({source:f,element:y,feedbackElement:v,placeholder:Z,translate:oe,moved:Ue,transition:N,alignment:f.alignment,styles:L,animation:ne??void 0,getElementMutationObserver:()=>we,cleanup:se,restoreFocus:V})})}});return()=>{se(),Yt()}};xt(Vr,4,"overlay",uu,Gn,Ea);gn(Vr,Gn);Gn.configure=es(Gn);var Ca=Gn,cr=!0,qg=!1,pu,gu,mu,vu,zt,Oa,Ma;vu=(mu=[le],mt.Forward),gu=(pu=[le],mt.Reverse);var Xr=class{constructor(){ze(this,Oa,Ve(zt,8,this,cr)),Ve(zt,11,this),ze(this,Ma,Ve(zt,12,this,cr)),Ve(zt,15,this)}isLocked(e){return e===mt.Idle?!1:e==null?this[mt.Forward]===cr&&this[mt.Reverse]===cr:this[e]===cr}unlock(e){e!==mt.Idle&&(this[e]=qg)}};zt=tr(null);Oa=new WeakMap;Ma=new WeakMap;xt(zt,4,vu,mu,Xr,Oa);xt(zt,4,gu,pu,Xr,Ma);gn(zt,Xr);var Ug=[mt.Forward,mt.Reverse],_l=class{constructor(){this.x=new Xr,this.y=new Xr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Kg=class extends et{constructor(e){super(e);const t=qn(new _l);let n=null;this.signal=t,yt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new _l;return}const{delta:s}=e.dragOperation.position;if(n){const o={x:kl(s.x,n.x),y:kl(s.y,n.y)},i=t.peek();Re(()=>{for(const a of Uc)for(const l of Ug)o[a]===l&&i[a].unlock(l);t.value=i})}n=s})}get current(){return this.signal.peek()}};function kl(e,t){return Math.sign(e-t)}var yu,Si,Yr,Ia,Wt,$i,ss=class extends(Si=ts,yu=[le],Si){constructor(e){super(e),ze(this,Ia,Ve(Yr,8,this,!1)),Ve(Yr,11,this),ze(this,Wt),ze(this,$i,()=>{if(!xe(this,Wt))return;const{element:o,by:i}=xe(this,Wt);i.y&&(o.scrollTop+=i.y),i.x&&(o.scrollLeft+=i.x)}),this.scroll=(o,i)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return st(this,Wt,void 0),!1;const{position:u}=this.manager.dragOperation,c=u?.current;if(c){const{by:d}=o??{},f=d?{x:Sl(d.x),y:Sl(d.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const y of l){const g=Gp(y,d);if(g.x||g.y){const{speed:w,direction:x}=eg(y,c,f,i?.acceleration,i?.threshold);if(h)for(const p of Uc)h[p].isLocked(x[p])&&(w[p]=0,x[p]=0);if(x.x||x.y){const{x:p,y:v}=d??x,_=p*w.x,b=v*w.y;if(_||b){const E=(a=xe(this,Wt))==null?void 0:a.by;if(this.autoScrolling&&E&&(E.x&&!_||E.y&&!b))continue;return st(this,Wt,{element:y,by:{x:_,y:b}}),Xs.schedule(xe(this,$i)),!0}}}}}return st(this,Wt,void 0),!1};let t=null,n=null;const r=ei(()=>{const{position:o,source:i}=e.dragOperation;if(!o)return null;const a=Wd(Us(i?.element),o.current);return a&&(t=a),a??t}),s=ei(()=>{const o=r.value,{documentElement:i}=Jn(o);if(!o||o===i){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=vi(l,{excludeElement:!1});return n=u,u}}if(o){const a=vi(o,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},wt);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Kg(e),this.destroy=e.monitor.addEventListener("dragmove",o=>{this.disabled||o.defaultPrevented||!Ur(e.dragOperation.activatorEvent)||!o.by||this.scroll({by:o.by})&&o.preventDefault()})}};Yr=tr(Si);Ia=new WeakMap;Wt=new WeakMap;$i=new WeakMap;xt(Yr,4,"autoScrolling",yu,ss,Ia);gn(Yr,ss);function Sl(e){return e>0?mt.Forward:e<0?mt.Reverse:mt.Idle}var Vg=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))}},Xg=new Vg(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Yg=10,Ti=class extends et{constructor(t,n){super(t,n);const r=t.registry.plugins.get(ss);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=yt(()=>{var s,o,i;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const u={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((o=this.options)==null?void 0:o.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(i=this.options)==null?void 0:i.threshold};if(r.scroll(void 0,u)){r.autoScrolling=!0;const d=setInterval(()=>Xg.schedule(()=>r.scroll(void 0,u)),Yg);return()=>{clearInterval(d)}}else r.autoScrolling=!1}})}};Ti.configure=es(Ti);var xu=Ti,$l={capture:!0,passive:!0},kr,Qg=class extends ts{constructor(e){super(e),ze(this,kr),this.handleScroll=()=>{xe(this,kr)==null&&st(this,kr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),st(this,kr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=yt(()=>{var n,r,s;if(t.status.dragging){const i=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return i.addEventListener("scroll",this.handleScroll,$l),()=>{i.removeEventListener("scroll",this.handleScroll,$l)}}})}};kr=new WeakMap;var Zg="* { user-select: none !important; -webkit-user-select: none !important; }",Jg=class extends et{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(yo),n=t?.register(Zg);if(this.destroy=yt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return jo(),document.addEventListener("selectionchange",jo,{capture:!0}),()=>{document.removeEventListener("selectionchange",jo,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function jo(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Sr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),En,eo=class extends Bn{constructor(t,n){super(t),this.manager=t,this.options=n,ze(this,En,[]),this.listeners=new Nd,this.handleSourceKeyDown=(r,s,o)=>{if(this.disabled||r.defaultPrevented||!dn(r.target)||s.disabled)return;const{keyboardCodes:i=Sr.keyboardCodes,preventActivation:a=Sr.preventActivation}=o??{};i.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,o))}}bind(t,n=this.options){return yt(()=>{var s;const o=(s=t.handle)!=null?s:t.element,i=a=>{Ur(a)&&this.handleSourceKeyDown(a,t,n)};if(o)return o.addEventListener("keydown",i),()=>{o.removeEventListener("keydown",i)}})}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:o}=new Et(s);if(this.manager.actions.start({event:t,coordinates:{x:o.x,y:o.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Jn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:u=>this.handleKeyDown(u,n,r),options:{capture:!0}}])];xe(this,En).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=Sr.keyboardCodes}=r??{};if(yn(t,[...s.end,...s.cancel])){t.preventDefault();const o=yn(t,s.cancel);this.handleEnd(t,o);return}yn(t,s.up)?this.handleMove("up",t):yn(t,s.down)&&this.handleMove("down",t),yn(t,s.left)?this.handleMove("left",t):yn(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:o}=this.manager.dragOperation,i=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:Sr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!o){switch(t){case"up":a={x:0,y:-l.y*i};break;case"down":a={x:0,y:l.y*i};break;case"left":a={x:-l.x*i,y:0};break;case"right":a={x:l.x*i,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(xu);t?.disabled===!1&&(t.disable(),xe(this,En).push(()=>{t.enable()}))}cleanup(){xe(this,En).forEach(t=>t()),st(this,En,[])}destroy(){this.cleanup(),this.listeners.clear()}};En=new WeakMap;eo.configure=es(eo);eo.defaults=Sr;var bu=eo;function yn(e,t){return t.includes(e.code)}var rn,em=class extends Sd{constructor(){super(...arguments),ze(this,rn)}onEvent(e){switch(e.type){case"pointerdown":st(this,rn,Fn(e));break;case"pointermove":if(!xe(this,rn))return;const{x:t,y:n}=Fn(e),r={x:t-xe(this,rn).x,y:n-xe(this,rn).y},{tolerance:s}=this.options;if(s&&ci(r,s)){this.abort();return}ci(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){st(this,rn,void 0)}};rn=new WeakMap;var Cn,sn,tm=class extends Sd{constructor(){super(...arguments),ze(this,Cn),ze(this,sn)}onEvent(e){switch(e.type){case"pointerdown":st(this,sn,Fn(e)),st(this,Cn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!xe(this,sn))return;const{x:t,y:n}=Fn(e),r={x:t-xe(this,sn).x,y:n-xe(this,sn).y};ci(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){xe(this,Cn)&&(clearTimeout(xe(this,Cn)),st(this,sn,void 0),st(this,Cn,void 0))}};Cn=new WeakMap;sn=new WeakMap;var jn=class{};jn.Delay=tm;jn.Distance=em;var Ei=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&dn(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new jn.Delay({value:250,tolerance:5})]:ug(s)&&!e.defaultPrevented?[new jn.Delay({value:200,tolerance:0})]:[new jn.Delay({value:200,tolerance:10}),new jn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!dn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Dp(r);return s===t.element?!1:!!s}}),On,to=class extends Bn{constructor(t,n){super(t),this.manager=t,this.options=n,ze(this,On,new Set),this.listeners=new Nd,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=Ei.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return yt(()=>{var s;const o=new AbortController,{signal:i}=o,a=u=>{dg(u)&&this.handlePointerDown(u,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const u of l)u&&(sm(u.ownerDocument.defaultView),u.addEventListener("pointerdown",a,{signal:i}));return()=>o.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!dn(t.target)||n.disabled||nm(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=Ei.preventActivation}=r??{};if(s?.(t,n))return;const{target:o}=t,i=Kt(o)&&o.draggable&&o.getAttribute("draggable")==="true",a=Nn(n.element),{x:l,y:u}=Fn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:u*a.scaleY+a.y};const c=this.activationConstraints(t,n,r);t.sensor=this;const d=new kp(c,g=>this.handleStart(n,g));d.signal.onabort=()=>this.handleCancel(t),d.onEvent(t),this.controller=d;const f=hi(),h=this.listeners.bind(f,[{type:"pointermove",listener:g=>this.handlePointerMove(g,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:i?this.handleCancel:hs,options:{capture:!0}}]),y=()=>{h(),this.initialCoordinates=void 0};xe(this,On).add(y)}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 o=Fn(t),i=Nn(n.element);o.x=o.x*i.scaleX+i.x,o.y=o.y*i.scaleY+i.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=o,Xs.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Jn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=dn(n.target)?[n.target,a]:a,u=this.listeners.bind(l,[{type:"touchmove",listener:hs,options:{passive:!1}},{type:"click",listener:hs},{type:"contextmenu",listener:hs},{type:"keydown",listener:this.handleKeyDown}]);xe(this,On).add(u)}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},xe(this,On).forEach(n=>n()),xe(this,On).clear()}destroy(){this.cleanup(),this.listeners.clear()}};On=new WeakMap;to.configure=es(to);to.defaults=Ei;var Ci=to;function nm(e){return"sensor"in e}function hs(e){e.preventDefault()}function rm(){}var Tl=new WeakSet;function sm(e){!e||Tl.has(e)||(e.addEventListener("touchmove",rm,{capture:!1,passive:!1}),Tl.add(e))}var Rn={modifiers:[],plugins:[Og,xu,Ig,Ca,Jg],sensors:[Ci,bu]},wu=class extends Tp{constructor(e={}){const t=St(e.plugins,Rn.plugins),n=St(e.sensors,Rn.sensors),r=St(e.modifiers,Rn.modifiers);super(Sa(Kr({},e),{plugins:[Qg,ss,yo,...t],sensors:n,modifiers:r}))}},_u,ku,Oi,Gt,Da,ja,xo=class extends(Oi=Ot,ku=[le],_u=[le],Oi){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:o}=n,i=eu(n,["element","effects","handle"]);super(Kr({effects:()=>[...s(),()=>{var a,l;const{manager:u}=this;if(!u)return;const d=((l=(a=this.sensors)==null?void 0:a.map(zr))!=null?l:[...u.sensors]).map(f=>{const h=f instanceof Bn?f:u.registry.register(f.plugin),y=f instanceof Bn?void 0:f.options;return h.bind(this,y)});return function(){d.forEach(h=>h())}}]},i),t),ze(this,Da,Ve(Gt,8,this)),Ve(Gt,11,this),ze(this,ja,Ve(Gt,12,this)),Ve(Gt,15,this),this.element=r,this.handle=o}};Gt=tr(Oi);Da=new WeakMap;ja=new WeakMap;xt(Gt,4,"handle",ku,xo,Da);xt(Gt,4,"element",_u,xo,ja);gn(Gt,xo);var Su,$u,Mi,Ht,Pa,Po,Tu,Eu,Br,Ra,bo=class extends(Mi=Mt,$u=[le],Su=[le],Mi){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,o=eu(n,["element","effects"]);const{collisionDetector:i=Yd}=o,a=u=>{const{manager:c,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!c)return;const f=new Et(d),h=ae(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},l=qn(!1);super(Sa(Kr({},o),{collisionDetector:i,effects:()=>[...s(),()=>{const{element:u,manager:c}=this;if(!c)return;const{dragOperation:d}=c,{source:f}=d;l.value=!!(f&&d.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(l.value&&u){const c=new zp(u,a);return()=>{c.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),ze(this,Br),ze(this,Pa,Ve(Ht,8,this)),Ve(Ht,11,this),ze(this,Ra,Ve(Ht,12,this)),Ve(Ht,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){st(this,Br,e,Eu)}get element(){var e;return(e=this.proxy)!=null?e:xe(this,Br,Tu)}};Ht=tr(Mi);Pa=new WeakMap;Br=new WeakSet;Ra=new WeakMap;Po=xt(Ht,20,"#element",$u,Br,Pa),Tu=Po.get,Eu=Po.set;xt(Ht,4,"proxy",Su,bo,Ra);gn(Ht,bo);function om(e){return e!=null&&typeof e=="object"&&"current"in e}function An(e){var t;if(e!=null)return om(e)?(t=e.current)!=null?t:void 0:e}var im=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",nr=im?S.useLayoutEffect:S.useEffect;function am(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Cu(e,t){const n=S.useRef(new Map),r=am();return nr(()=>{if(!e){n.current.clear();return}return yt(()=>{var s;let o=!1,i=!1;for(const a of n.current){const[l]=a,u=ae(()=>a[1]),c=e[l];u!==c&&(o=!0,n.current.set(l,c),i=(s=t?.(l,u,c))!=null?s:!1)}o&&(i?queueMicrotask(()=>Nf.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(s,o){const i=s[o];return n.current.set(o,i),i}}),[e])}function lm(e,t){e()}function xn(e){const t=S.useRef(e);return nr(()=>{t.current=e},[e]),t}function je(e,t,n=S.useEffect,r=Object.is){const s=S.useRef(e);n(()=>{const o=s.current;r(e,o)||(s.current=e,t(e,o))},[t,e])}function Is(e,t){const n=S.useRef(An(e));nr(()=>{const r=An(e);r!==n.current&&(n.current=r,t(r))})}var cm=Object.defineProperty,dm=Object.defineProperties,um=Object.getOwnPropertyDescriptors,no=Object.getOwnPropertySymbols,Ou=Object.prototype.hasOwnProperty,Mu=Object.prototype.propertyIsEnumerable,El=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fm=(e,t)=>{for(var n in t||(t={}))Ou.call(t,n)&&El(e,n,t[n]);if(no)for(var n of no(t))Mu.call(t,n)&&El(e,n,t[n]);return e},hm=(e,t)=>dm(e,um(t)),pm=(e,t)=>{var n={};for(var r in e)Ou.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&no)for(var r of no(e))t.indexOf(r)<0&&Mu.call(e,r)&&(n[r]=e[r]);return n},gm=new wu,Iu=S.createContext(gm),mm=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),s=S.useRef(null),o=S.useRef(null),i=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{o.current=l})),S.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return nr(()=>{var a;(a=o.current)==null||a.call(o),s.current=null},[e,n]),S.useImperativeHandle(t,()=>i),null})),Ro=[void 0,wt];function vm(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:o,onDragMove:i,onDragOver:a,onDragEnd:l}=t,u=pm(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:d,modifiers:f,sensors:h}=u,y=St(d,Rn.plugins),g=St(h,Rn.sensors),w=St(f,Rn.modifiers),x=xn(s),p=xn(o),v=xn(a),_=xn(i),b=xn(l),E=xn(r),T=ym(()=>{var M;return(M=u.manager)!=null?M:new wu(u)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:O}=c.current,{monitor:C}=T;T.renderer=M;const A=[C.addEventListener("beforedragstart",R=>{const L=x.current;L&&O(()=>L(R,T))}),C.addEventListener("dragstart",R=>{var L;return(L=p.current)==null?void 0:L.call(p,R,T)}),C.addEventListener("dragover",R=>{const L=v.current;L&&O(()=>L(R,T))}),C.addEventListener("dragmove",R=>{const L=_.current;L&&O(()=>L(R,T))}),C.addEventListener("dragend",R=>{const L=b.current;L&&O(()=>L(R,T))}),C.addEventListener("collision",R=>{var L;return(L=E.current)==null?void 0:L.call(E,R,T)})];return()=>A.forEach(R=>R())},[T]),je(y,()=>T&&(T.plugins=y),...Ro),je(g,()=>T&&(T.sensors=g),...Ro),je(w,()=>T&&(T.modifiers=w),...Ro),m.jsxs(Iu.Provider,{value:T,children:[m.jsx(mm,{ref:c,children:n}),n]})}function ym(e){const t=S.useRef(null);return t.current||(t.current=e()),S.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function Du(){return S.useContext(Iu)}function ju(e){var t;const n=(t=Du())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),nr(r.register,[n,r]),r}var xm=Object.create,Pu=Object.defineProperty,bm=Object.getOwnPropertyDescriptor,Ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),wo=e=>{throw TypeError(e)},wm=(e,t,n)=>t in e?Pu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_m=e=>{var t;return[,,,xm((t=e?.[Ru("metadata")])!=null?t:null)]},Au=["class","method","getter","setter","accessor","field","value","get","set"],Lu=e=>e!==void 0&&typeof e!="function"?wo("Function expected"):e,km=(e,t,n,r,s)=>({kind:Au[e],name:t,metadata:r,addInitializer:o=>n._?wo("Already initialized"):s.push(Lu(o||null))}),Sm=(e,t)=>wm(t,Ru("metadata"),e[3]),$m=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Bu=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,y=Au[c+5],g=e[h]||(e[h]=[]),w=(s=s.prototype,bm(s,n)),x=r.length-1;x>=0;x--)l=km(c,n,a={},e[3],g),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(w[y],l),a._=1,Lu(i)&&(w[y]=i);return w&&Pu(s,n,w),s},Fu=(e,t,n)=>t.has(e)||wo("Cannot "+n),Tm=(e,t,n)=>(Fu(e,t,"read from private field"),t.get(e)),Em=(e,t,n)=>t.has(e)?wo("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Cm=(e,t,n,r)=>(Fu(e,t,"write to private field"),t.set(e,n),n),an=class Ii{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ii(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 Ii(t,n)}},Wu,Nu,Di,Ds,os,Aa=class extends(Di=hn,Nu=[We],Wu=[We],Di){constructor(e){const t=an.from(e);super(t,(n,r)=>an.equals(n,r)),$m(os,5,this),Em(this,Ds,0),this.velocity={x:0,y:0}}get delta(){return an.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=an.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),o=s-Tm(this,Ds),i=a=>Math.round(a/o*100);Re(()=>{Cm(this,Ds,s),this.velocity={x:i(r.x),y:i(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(an.from(e)),this.velocity={x:0,y:0}}};os=_m(Di);Ds=new WeakMap;Bu(os,2,"delta",Nu,Aa);Bu(os,2,"direction",Wu,Aa);Sm(os,Aa);var zu=(e=>(e.Horizontal="x",e.Vertical="y",e))(zu||{});Object.values(zu);var Om=({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=an.distance(t.shape.center,n);return{id:r,value:1/s,type:Zn.PointerIntersection,priority:Qn.High}}return null},Mm=({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,o=an.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Zn.ShapeIntersection,priority:Qn.Normal}}return null},Im=e=>{var t;return(t=Om(e))!=null?t:Mm(e)};function Dm(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:o,accept:i,type:a}=e,l=ju(c=>new bo(hm(fm({},e),{register:!1,element:An(s)}),c)),u=Cu(l);return je(o,()=>l.id=o),Is(s,c=>l.element=c),je(i,()=>l.accept=i,void 0,wt),je(t,()=>l.collisionDetector=t??Im),je(n,()=>n&&(l.data=n)),je(r,()=>l.disabled=r===!0),je(a,()=>l.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:S.useCallback(c=>{var d,f;!c&&((d=l.element)!=null&&d.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=c??void 0)},[l])}}const Gu=(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 ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},Hu=S.createContext(void 0);function qu(e,t){const n=S.useContext(Hu),r=S.useRef(t);r.current=t,S.useEffect(()=>{if(!n||!e)return;const o=()=>r.current();return n.commitRef.current=o,()=>{n.commitRef.current===o&&(n.commitRef.current=void 0)}},[n,e]);const s=S.useRef(!1);S.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),S.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function ji({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:o}=be.usePublisherTheme(),[i,a]=S.useState(void 0),l=S.useRef(!1),u=()=>{l.current||i===void 0||(a(void 0),i!==e&&r(i))};qu(i!==void 0&&i!==e,()=>(u(),!0));const c=()=>{l.current=!1,a(e)};if(i===void 0){const d=e==="",f=d&&s;return m.jsx($.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:c,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),c())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...d&&{fontStyle:"italic",opacity:f?0:.6}},Gu(o)],children:d?t:e})}return m.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:i,placeholder:t,inputProps:{"aria-label":n},onFocus:d=>d.target.select(),onChange:d=>a(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.nativeEvent.isComposing?u():d.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:u,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const jm=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const o={...n};return s?o.break=!0:delete o.break,o}),Pm=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const o=r[t];s.break&&o&&!o.break&&(r[t]={...o,break:!0});const i={...s};return delete i.break,r.splice(n,0,i),r},Uu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),Ku=e=>`gap.${e}`,Rm=(e,t)=>{const n=[];let r=0;e.forEach((o,i)=>{const a=Math.min(o.colspan??1,t),l=i===0||o.break===!0||r+a>t;l&&i>0&&r<t&&n.push({kind:"gap",after:fe(e[i-1]),colspan:t-r}),l&&(r=0),n.push(Uu(o,i)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:fe(s),colspan:t-r}),n};var Am=Object.create,Vu=Object.defineProperty,Lm=Object.defineProperties,Bm=Object.getOwnPropertyDescriptor,Fm=Object.getOwnPropertyDescriptors,ro=Object.getOwnPropertySymbols,Xu=Object.prototype.hasOwnProperty,Yu=Object.prototype.propertyIsEnumerable,Wm=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),is=e=>{throw TypeError(e)},Pi=(e,t,n)=>t in e?Vu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ao=(e,t)=>{for(var n in t||(t={}))Xu.call(t,n)&&Pi(e,n,t[n]);if(ro)for(var n of ro(t))Yu.call(t,n)&&Pi(e,n,t[n]);return e},Lo=(e,t)=>Lm(e,Fm(t)),Nm=(e,t)=>{var n={};for(var r in e)Xu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ro)for(var r of ro(e))t.indexOf(r)<0&&Yu.call(e,r)&&(n[r]=e[r]);return n},zm=e=>{var t;return[,,,Am((t=void 0)!=null?t:null)]},Qu=["class","method","getter","setter","accessor","field","value","get","set"],$r=e=>e!==void 0&&typeof e!="function"?is("Function expected"):e,Gm=(e,t,n,r,s)=>({kind:Qu[e],name:t,metadata:r,addInitializer:o=>n._?is("Already initialized"):s.push($r(o||null))}),Hm=(e,t)=>Pi(t,Wm("metadata"),e[3]),ps=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Zu=(e,t,n,r,s,o)=>{for(var i,a,l,u,c,d=t&7,f=!1,h=!1,y=e.length+1,g=Qu[d+5],w=e[y-1]=[],x=e[y]||(e[y]=[]),p=(s=s.prototype,Bm({get[n](){return Tr(this,o)},set[n](_){return on(this,o,_)}},n)),v=r.length-1;v>=0;v--)u=Gm(d,n,l={},e[3],x),u.static=f,u.private=h,c=u.access={has:_=>n in _},c.get=_=>_[n],c.set=(_,b)=>_[n]=b,a=(0,r[v])({get:p.get,set:p.set},u),l._=1,a===void 0?$r(a)&&(p[g]=a):typeof a!="object"||a===null?is("Object expected"):($r(i=a.get)&&(p.get=i),$r(i=a.set)&&(p.set=i),$r(i=a.init)&&w.unshift(i));return p&&Vu(s,n,p),s},Ju=(e,t,n)=>t.has(e)||is("Cannot "+n),Tr=(e,t,n)=>(Ju(e,t,"read from private field"),t.get(e)),dr=(e,t,n)=>t.has(e)?is("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),on=(e,t,n,r)=>(Ju(e,t,"write to private field"),t.set(e,n),n);function ln(e){return e instanceof Fa||e instanceof rf}var gs=10,qm=class extends et{constructor(e){super(e);const t=yt(()=>{const{dragOperation:r}=e;if(Ur(r.activatorEvent)&&ln(r.source)&&r.status.initialized){const s=e.registry.plugins.get(ss);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:o}=s;if(!Ur(r.nativeEvent)||!ln(o.source)||!o.shape)return;const{actions:i,collisionObserver:a,registry:l}=s,{by:u}=r;if(!u)return;const c=Um(u),{source:d,target:f}=o,{center:h}=o.shape.current,y=[],g=[];Re(()=>{for(const b of l.droppables){const{id:E}=b;if(!b.accepts(d)||E===f?.id&&ln(b)||!b.element)continue;let T=b.shape;const M=new Et(b.element,{getBoundingClientRect:O=>Hr(O,void 0,.2)});!M.height||!M.width||(c=="down"&&h.y+gs<M.center.y||c=="up"&&h.y-gs>M.center.y||c=="left"&&h.x-gs>M.center.x||c=="right"&&h.x+gs<M.center.x)&&(y.push(b),b.shape=M,g.push(()=>b.shape=T))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(y,pg);Re(()=>g.forEach(b=>b()));const[x]=w;if(!x)return;const{id:p}=x,{index:v,group:_}=d.sortable;i.setDropTarget(p).then(()=>{const{source:b,target:E,shape:T}=o;if(!b||!ln(b)||!T)return;const{index:M,group:O,target:C}=b.sortable,A=v!==M||_!==O,R=A?C:E?.element;if(!R)return;Vd(R);const L=new Et(R);if(!L)return;const G=Ct.delta(L,Ct.from(T.current.boundingRectangle),b.alignment);i.move({by:G}),A?i.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Um(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 Km=Object.defineProperty,Vm=Object.defineProperties,Xm=Object.getOwnPropertyDescriptors,Cl=Object.getOwnPropertySymbols,Ym=Object.prototype.hasOwnProperty,Qm=Object.prototype.propertyIsEnumerable,Ol=(e,t,n)=>t in e?Km(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))Ym.call(t,n)&&Ol(e,n,t[n]);if(Cl)for(var n of Cl(t))Qm.call(t,n)&&Ol(e,n,t[n]);return e},wn=(e,t)=>Vm(e,Xm(t));function Zm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ms(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Bo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Jm(e,t,n){var r,s;const{source:o,target:i,canceled:a}=t.operation;if(!o||!i||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(v,_)=>v===_||v!==null&&typeof v=="object"&&"id"in v&&v.id===_;if(Array.isArray(e)){const v=e.findIndex(b=>l(b,o.id)),_=e.findIndex(b=>l(b,i.id));if(v===-1||_===-1){if(Bo(o)){const b=o.initialIndex,E=o.index;return b===E||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,E)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==v)return n(e,v,b)}return n(e,v,_)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[v,_]of u)if(c===-1&&(c=_.findIndex(b=>l(b,o.id)),c!==-1&&(d=v)),f===-1&&(f=_.findIndex(b=>l(b,i.id)),f!==-1&&(h=v)),c!==-1&&f!==-1)break;if(c===-1&&Bo(o)){const v=o.initialGroup==null?void 0:ms(e,o.initialGroup),_=o.initialIndex,b=o.group==null?void 0:ms(e,o.group),E=o.index;if(v==null||b==null||v===b&&_===E)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return wn(bn({},e),{[v]:n(e[v],_,E)});const T=e[v][_];return wn(bn({},e),{[v]:[...e[v].slice(0,_),...e[v].slice(_+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:y}=o.manager,g=(s=(r=y.shape)==null?void 0:r.current.center)!=null?s:y.position.current;if(h==null){const v=ms(e,i.id);if(v!=null){const _=i.shape&&g.y>i.shape.center.y?e[v].length:0;h=v,f=_}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&Bo(o)){const v=o.group==null?void 0:ms(e,o.group),_=o.group!=null&&v!==d,b=o.index!==c;if(_||b){const E=o.group==null?d:v;if(E!=null){if(d===E)return wn(bn({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return wn(bn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[E]:[...e[E].slice(0,o.index),T,...e[E].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return wn(bn({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(g.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return wn(bn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[h]:[...e[h].slice(0,f+x),p,...e[h].slice(f+x)]})}function ev(e,t){return Jm(e,t,Zm)}function Ml(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Il(e,t,n){var r;for(const[s,o]of t)for(const i of o){const a=e.get(i.id);if(i.index!==a||i.group!==s||!((r=n.get(s))!=null&&r.has(i)))return!0}return!1}var Dl="__default__",tv=class extends et{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof Fa){const{sortable:o}=s,{group:i}=o;let a=r.get(i);a||(a=new Set,r.set(i,a)),a.add(o)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:o}=s,{source:i,target:a}=o;if(!ln(i)||!ln(a)||i.sortable===a.sortable)return;const l=t(),u=Ml(l),c=i.sortable.group===a.sortable.group,d=l.get(i.sortable.group),f=c?d:l.get(a.sortable.group);!d||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,y;const g=t();if(Il(u,l,g))return;const w=i.sortable.element,x=a.sortable.element;if(!x||!w||!c&&a.id===i.sortable.group)return;const p=vs(d),v=c?p:vs(f),_=(h=i.sortable.group)!=null?h:Dl,b=(y=a.sortable.group)!=null?y:Dl,E={[_]:p,[b]:v},T=ev(E,r);if(E===T)return;const M=T[b].indexOf(i.sortable),O=T[b].indexOf(a.sortable);s.collisionObserver.disable(),jl(w,M,x,O),Re(()=>{for(const[C,A]of T[_].entries())A.index=C;if(!c)for(const[C,A]of T[b].entries())A.group=a.sortable.group,A.index=C}),s.actions.setDropTarget(i.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:o}=s,{source:i}=o;ln(i)&&(i.sortable.initialIndex===i.sortable.index&&i.sortable.initialGroup===i.sortable.group||queueMicrotask(()=>{const a=t(),l=Ml(a),u=a.get(i.sortable.initialGroup);u&&s.renderer.rendering.then(()=>{const c=t();if(Il(l,a,c))return;const d=vs(u),f=vs(u,rv),h=i.sortable.element,y=f.indexOf(i.sortable),g=d[y],w=g?.element;!g||!w||!h||(jl(h,g.index,w,i.index),Re(()=>{for(const x of a.values()){const p=Array.from(x).values();for(const v of p)v.index=v.initialIndex,v.group=v.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function jl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function nv(e,t){return e.index-t.index}function rv(e,t){return e.initialIndex-t.initialIndex}function vs(e,t=nv){return Array.from(e).sort(t)}var Pl=[qm,tv],ef={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Rl(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 ys=new Qh,tf,nf,qt,La,Er,Cr,Ba,Mn;nf=[le],tf=[le];var _o=class{constructor(e,t){dr(this,La,ps(qt,8,this)),ps(qt,11,this),dr(this,Er),dr(this,Cr),dr(this,Ba,ps(qt,12,this)),ps(qt,15,this),dr(this,Mn),this.register=()=>(Re(()=>{var y,g;(y=this.manager)==null||y.registry.register(this.droppable),(g=this.manager)==null||g.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Re(()=>{var y,g;(y=this.manager)==null||y.registry.unregister(this.droppable),(g=this.manager)==null||g.registry.unregister(this.draggable)})},this.destroy=()=>{Re(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:o,index:i,sensors:a,type:l,transition:u=ef,plugins:c}=n,d=Nm(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=St(c,Pl),h=Rl(s);this.droppable=new Fa(Lo(Ao({},d),{disabled:h.droppable}),t,this),this.draggable=new rf(Lo(Ao({},d),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var y,g,w;const x=(y=this.manager)==null?void 0:y.dragOperation.status;x?.initializing&&this.id===((w=(g=this.manager)==null?void 0:g.dragOperation.source)==null?void 0:w.id)&&ys.clear(this.manager),x?.dragging&&ys.set(this.manager,this.id,ae(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:y,group:g,manager:w}=this,x=Tr(this,Cr),p=Tr(this,Er);(y!==x||g!==p)&&(on(this,Cr,y),on(this,Er,g),this.animate())},()=>{var y,g;const{target:w}=this,{isDragSource:x}=this.draggable;((g=(y=this.draggable.pluginConfig(Ca))==null?void 0:y.feedback)!=null?g:"default")==="move"&&x&&(this.droppable.disabled=!w)},...r()],type:l,sensors:a}),t,this),on(this,Mn,d.element),this.manager=t,this.index=i,on(this,Cr,i),this.group=o,on(this,Er,o),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=ys.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=ys.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ae(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:s}=this;if(!s)return;for(const c of s.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const o=this.refreshShape();if(!o)return;const i={x:n.boundingRectangle.left-o.boundingRectangle.left,y:n.boundingRectangle.top-o.boundingRectangle.top},{translate:a}=It(s),l=yl(s,a,!1),u=yl(s,a);if(i.x||i.y){const c=ba(ft(s))?Lo(Ao({},t),{duration:0}):t;Xd({element:s,keyframes:{translate:[`${l.x+i.x}px ${l.y+i.y}px ${l.z}`,`${u.x}px ${u.y}px ${u.z}`]},options:c}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Re(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Re(()=>{const t=Tr(this,Mn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),on(this,Mn,e)})}get element(){var e,t;const n=Tr(this,Mn);if(n)return(t=(e=pi.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=St(e,Pl)}set disabled(e){const t=Rl(e);Re(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Re(()=>{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??Yd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Re(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};qt=zm();La=new WeakMap;Er=new WeakMap;Cr=new WeakMap;Ba=new WeakMap;Mn=new WeakMap;Zu(qt,4,"index",nf,_o,La);Zu(qt,4,"group",tf,_o,Ba);Hm(qt,_o);var rf=class extends xo{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}},Fa=class extends bo{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},sv=Object.defineProperty,ov=Object.defineProperties,iv=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,av=Object.prototype.hasOwnProperty,lv=Object.prototype.propertyIsEnumerable,Ll=(e,t,n)=>t in e?sv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fo=(e,t)=>{for(var n in t||(t={}))av.call(t,n)&&Ll(e,n,t[n]);if(Al)for(var n of Al(t))lv.call(t,n)&&Ll(e,n,t[n]);return e},cv=(e,t)=>ov(e,iv(t));function dv(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:o,element:i,handle:a,index:l,group:u,disabled:c,modifiers:d,sensors:f,target:h,type:y,plugins:g}=e,w=Fo(Fo({},ef),e.transition),x=ju(v=>new _o(cv(Fo({},e),{transition:w,register:!1,handle:An(a),element:An(i),target:An(h)}),v)),p=Cu(x,uv);return je(s,()=>x.id=s),nr(()=>{Re(()=>{x.group=u,x.index=l})},[x,u,l]),je(y,()=>x.type=y),je(t,()=>x.accept=t,void 0,wt),je(o,()=>o&&(x.data=o)),je(l,()=>{var v;(v=x.manager)!=null&&v.dragOperation.status.idle&&w?.idle&&x.refreshShape()},lm),Is(a,v=>x.handle=v),Is(i,v=>x.element=v),Is(h,v=>x.target=v),je(c,()=>x.disabled=c??!1,void 0,wt),je(f,()=>x.sensors=f,void 0,wt),je(n,()=>x.collisionDetector=n),je(r,()=>x.collisionPriority=r),je(g,()=>x.plugins=g,void 0,wt),je(w,()=>x.transition=w,void 0,wt),je(d,()=>x.modifiers=d,void 0,wt),je(e.alignment,()=>x.alignment=e.alignment),{sortable:p,get isDragging(){return p.isDragging},get isDropping(){return p.isDropping},get isDragSource(){return p.isDragSource},get isDropTarget(){return p.isDropTarget},handleRef:S.useCallback(v=>{x.handle=v??void 0},[x]),ref:S.useCallback(v=>{var _,b;!v&&((_=x.element)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.element=v??void 0)},[x]),sourceRef:S.useCallback(v=>{var _,b;!v&&((_=x.source)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.source=v??void 0)},[x]),targetRef:S.useCallback(v=>{var _,b;!v&&((_=x.target)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.target=v??void 0)},[x])}}function uv(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Ri="tile",sf="gap",fv=[Ci.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${of}], ${hv}`)!==null||(Ci.defaults.preventActivation?.(e,t)??!1)}),bu],of="data-no-drag",hv=".malloy-render, .malloy-table",pv=e=>[...e,Ca.configure({feedback:"clone"})];function gv({id:e,index:t,disabled:n=!1,children:r}){const{ref:s,handleRef:o,isDragSource:i}=dv({id:e,index:t,disabled:n,type:Ri,accept:Ri,collisionDetector:_a,plugins:pv});return m.jsx(m.Fragment,{children:r({ref:s,handleRef:o,isDragSource:i})})}function mv({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Dm({id:e,type:sf,accept:Ri,collisionDetector:_a,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}function vv({active:e}){const t=Du();return S.useEffect(()=>{if(!e||!t)return;const n=r=>{r.key!=="Escape"||t.dragOperation.status.idle||(r.preventDefault(),r.stopPropagation(),t.actions.stop({event:r,canceled:!0}))};return window.addEventListener("keydown",n,!0),()=>window.removeEventListener("keydown",n,!0)},[e,t]),null}const af=e=>e.ok===!1,He=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),rr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,Ie={sourceDefinition:e=>He(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>He(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>He(e,"VIEW","subQueryDefList"),defDimension:e=>He(e,"defList","DIMENSION"),exploreProperties:e=>He(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>He(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>He(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>He(e,"WHERE","filterClauseList"),givenDef:e=>He(e,"givenNameDef"),givenStatement:e=>He(e,"GIVEN","givenDefList"),importStatement:e=>He(e,"IMPORT","importURL"),vArrow:e=>He(e,"ARROW","vExpr","segExpr"),segRefine:e=>He(e,"PLUS","segExpr"),segOps:e=>He(e,"queryProperties"),segField:e=>He(e,"fieldPath")&&!He(e,"segExpr"),segParen:e=>He(e,"OPAREN","CPAREN","vExpr"),compare:e=>He(e,"fieldExpr","compareOp"),givenRef:e=>He(e,"GIVEN_REF")};function yv(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 xv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
67
|
+
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Rg(e,t="hidden"){return ae(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Ag(n,r.registry.droppables),o=[],i=Mp(n),{remove:a}=i;return Lg(s,i,o),Bg(i,t),i.remove=()=>{o.forEach(l=>l()),a.call(i)},i})}function Ag(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${rs}${yi("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Lg(e,t,n){for(const[r,s]of e){if(!r.element)continue;const o=`[${s}]`,i=t.matches(o)?t:t.querySelector(o);if(r.element.removeAttribute(s),!i)continue;const a=r.element;r.proxy=i,i.removeAttribute(s),pi.set(a,i),n.push(()=>{pi.delete(a),r.proxy=void 0})}}function Bg(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Js,t)}function du(e,t){return e===t?!0:Wn(e)===Wn(t)}function wl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&dn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>jn(t))}function _i(e){return e.tagName==="TR"}function Fg(e,t,n){const r=new MutationObserver(s=>{let o=!1;for(const i of s){if(i.target!==e){o=!0;continue}if(i.type!=="attributes")continue;const a=i.attributeName;if(a.startsWith("aria-")||Dg.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(Ar(e)&&Ar(t)){const u=e.style;for(const c of Array.from(t.style))u.getPropertyValue(c)===""&&t.style.removeProperty(c);for(const c of Array.from(u)){if(Pg.includes(c)||c.startsWith(Qe))continue;const d=u.getPropertyValue(c);t.style.setProperty(c,d)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}o&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Wg(e,t,n){const r=new MutationObserver(s=>{for(const o of s)if(o.addedNodes.length!==0)for(const i of Array.from(o.addedNodes)){if(i.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),jn(n);return}if(i.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),jn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),jn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Ng(e){return new ResizeObserver(()=>{var t,n,r;const s=new Et(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),o=(t=e.transformOrigin)!=null?t:{x:1,y:1},i=(e.width-s.width)*o.x+e.delta.x,a=(e.height-s.height)*o.y+e.delta.y,l=Fd();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+i+l.x},Qe),(n=e.getElementMutationObserver())==null||n.takeRecords(),_i(e.element)&&_i(e.placeholder)){const g=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(g.map(x=>x.style.width));for(const[x,p]of g.entries()){const v=w[x];p.style.width=`${v.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},c=e.left+i+l.x+u.x,d=e.top+a+l.y+u.y,f=s.width-e.widthOffset,h=s.height-e.heightOffset,y=e.frameTransform;e.dragOperation.shape=new Ct(c*y.scaleX+y.x,d*y.scaleY+y.y,f*y.scaleX,h*y.scaleY)})}var zg=250,Gg="ease";function Hg(e){var t,n,r,s;const{animation:o}=e;if(typeof o=="function"){const p=o({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(p).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:i=zg,easing:a=Gg}=o??{};jn(e.feedbackElement);const[,l]=(t=Ad(e.feedbackElement,p=>"translate"in p))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,c={frameTransform:du(e.feedbackElement,u)?null:void 0},d=new Et(e.feedbackElement,c),f=(r=qr(It(e.feedbackElement).translate))!=null?r:e.translate,h=new Et(u,c),y=Ct.delta(d,h,e.alignment),g={x:f.x-y.x,y:f.y-y.y},w=Math.round(d.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},x=Math.round(d.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Qe),e.feedbackElement.setAttribute(wi,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),Xd({element:e.feedbackElement,keyframes:Sa(Kr(Kr({},w),x),{translate:[`${f.x}px ${f.y}px 0`,`${g.x}px ${g.y}px 0`]}),options:{duration:ba(ft(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?i:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(wi),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var uu,ki,Vr,Ea,Ms,fu,hu,Gn=class extends(ki=et,uu=[le],ki){constructor(t,n){super(t,n),ze(this,Ms),ze(this,Ea,Ve(Vr,8,this)),Ve(Vr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(yo),s=r?.register(jg);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}this.registerEffect(un(this,Ms,fu).bind(this,r)),this.registerEffect(un(this,Ms,hu))}};Vr=tr(ki);Ea=new WeakMap;Ms=new WeakSet;fu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Us(t);if(n)return e.addRoot(n)};hu=function(){var e,t,n,r,s,o,i;const{state:a,manager:l,options:u}=this,{dragOperation:c}=l,{position:d,source:f,status:h}=c;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:y}=f,g=f.pluginConfig(Gn),w=(t=(e=g?.feedback)!=null?e:u?.feedback)!=null?t:"default",x=typeof w=="function"?w(f,l):w;if(!y||x==="none"||!h.initialized||h.initializing)return;const{initial:p}=a,v=(n=this.overlay)!=null?n:y,_=Nn(v),b=Nn(y),E=!du(y,v),T=new Et(y,{frameTransform:E?b:null,ignoreTransforms:!E}),M={x:b.scaleX/_.scaleX,y:b.scaleY/_.scaleY};let{width:O,height:C,top:A,left:R}=T;E&&(O=O/M.x,C=C/M.y);const L=new cg(v),G=It(y),{transition:N,translate:X,boxSizing:j,paddingBlockStart:z,paddingBlockEnd:D,paddingInlineStart:I,paddingInlineEnd:B,borderInlineStartWidth:q,borderInlineEndWidth:H,borderBlockStartWidth:K,borderBlockEndWidth:te}=G,ye=N.split(",").filter(ne=>!/^\s*(transform|translate|scale)\b/.test(ne)).join(","),_e=vo(G),re=G.transform,De=x==="clone",ge=j==="content-box",ve=ge?parseInt(I)+parseInt(B)+parseInt(q)+parseInt(H):0,Ge=ge?parseInt(z)+parseInt(D)+parseInt(K)+parseInt(te):0,Z=x!=="move"&&!this.overlay?Rg(f,De?"clone":"hidden"):null,Xe=ae(()=>Ur(l.dragOperation.activatorEvent));if(!p.translate){if(this.overlay&&_e)p.translate={x:_e.x,y:_e.y};else if(X!=="none"){const ne=qr(X);ne&&(p.translate=ne)}}if(!p.transformOrigin){const ne=ae(()=>d.current),oe=R+((r=_e?.x)!=null?r:0),Ue=A+((s=_e?.y)!=null?s:0);p.transformOrigin={x:(ne.x-oe*_.scaleX-_.x)/(O*_.scaleX),y:(ne.y-Ue*_.scaleY-_.y)/(C*_.scaleY)}}const{transformOrigin:ke}=p,ue=A*_.scaleY+_.y,Oe=R*_.scaleX+_.x;if(!p.coordinates&&(p.coordinates={x:Oe,y:ue},M.x!==1||M.y!==1)){const{scaleX:ne,scaleY:oe}=b,{x:Ue,y:bt}=ke;p.coordinates.x+=(O*ne-O)*Ue,p.coordinates.y+=(C*oe-C)*bt}p.dimensions||(p.dimensions={width:O,height:C}),p.frameTransform||(p.frameTransform=_);const Ae={x:p.coordinates.x-Oe,y:p.coordinates.y-ue},ie={width:(p.dimensions.width*p.frameTransform.scaleX-O*_.scaleX)*ke.x,height:(p.dimensions.height*p.frameTransform.scaleY-C*_.scaleY)*ke.y},qe={x:Ae.x/_.scaleX+ie.width,y:Ae.y/_.scaleY+ie.height},Ye={left:R+qe.x,top:A+qe.y};v.setAttribute(Tt,"true");const P=ae(()=>c.transform),F=(o=p.translate)!=null?o:{x:0,y:0},U=P.x*_.scaleX+F.x,Y=P.y*_.scaleY+F.y,Se=Fd();L.set({width:O-ve,height:C-Ge,top:Ye.top+Se.y,left:Ye.left+Se.x,translate:`${U}px ${Y}px 0`,transform:this.overlay?"none":re,transition:ye?`${ye}, translate 0ms linear`:"translate 0ms linear",scale:E?`${M.x} ${M.y}`:"","transform-origin":`${ke.x*100}% ${ke.y*100}%`},Qe),Z&&(y.insertAdjacentElement("afterend",Z),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(y)),mi(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),jn(v),v.addEventListener("beforetoggle",wl));let we,ht,W;const Q=Ng({placeholder:Z,element:y,feedbackElement:v,frameTransform:_,transformOrigin:ke,width:O,height:C,top:A,left:R,widthOffset:ve,heightOffset:Ge,delta:qe,styles:L,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>we,getSavedCellWidths:()=>W,setSavedCellWidths:ne=>{W=ne}}),Le=new Et(v);ae(()=>c.shape=Le);const Be=ft(v),lt=ne=>{this.manager.actions.stop({event:ne})},he=ba(Be);Xe&&Be.addEventListener("resize",lt),ae(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),Z&&(Q.observe(Z),we=Fg(y,Z,De),ht=Wg(y,Z,v));const tt=(i=l.dragOperation.source)==null?void 0:i.id,V=()=>{var ne;if(!Xe||tt==null)return;const oe=l.registry.draggables.get(tt),Ue=(ne=oe?.handle)!=null?ne:oe?.element;Kt(Ue)&&Ue.focus()},se=()=>{we?.disconnect(),ht?.disconnect(),Q.disconnect(),Be.removeEventListener("resize",lt),mi(v)&&(v.removeEventListener("beforetoggle",wl),v.removeAttribute("popover")),v.removeAttribute(Tt),L.reset();const ne=()=>{var oe;if(W&&_i(y)){const or=Array.from(y.cells);for(const[mn,vn]of or.entries())vn.style.width=(oe=W[mn])!=null?oe:""}f.status="idle";const Ue=a.current.translate!=null,bt=c.status.dragging;Z&&(!bt&&Ue||Z.parentElement!==v.parentElement)&&v.isConnected&&Z.replaceWith(v),Z?.remove()};v===this.overlay?setTimeout(ne,0):ne()},Me=u?.dropAnimation,$e=this,Yt=Zr(()=>{var ne,oe,Ue;const{transform:bt,status:or}=c;if(!(!bt.x&&!bt.y&&!a.current.translate)&&or.dragging){const mn=(ne=p.translate)!=null?ne:{x:0,y:0},vn={x:bt.x/_.scaleX+mn.x,y:bt.y/_.scaleY+mn.y},qa=a.current.translate,Wf=ae(()=>c.modifiers),ko=ae(()=>{var ar;return(ar=c.shape)==null?void 0:ar.current}),ir=u?.keyboardTransition,Ua=Xe&&!he&&ir!==null?`${(oe=ir?.duration)!=null?oe:250}ms ${(Ue=ir?.easing)!=null?Ue:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:ye?`${ye}, translate ${Ua}`:`translate ${Ua}`,translate:`${vn.x}px ${vn.y}px 0`},Qe),we?.takeRecords(),ko&&ko!==Le&&qa&&!Wf.length){const ar=gt.delta(vn,qa);c.shape=Ct.from(ko.boundingRectangle).translate(ar.x*_.scaleX,ar.y*_.scaleY)}else c.shape=new Et(v);a.current.translate=vn}},function(){if(c.status.dropped){this.dispose(),f.status="dropping";const ne=g?.dropAnimation!==void 0?g.dropAnimation:$e.dropAnimation!==void 0?$e.dropAnimation:Me;let oe=a.current.translate;const Ue=oe!=null;if(!oe&&y!==v&&(oe={x:0,y:0}),!oe||ne===null){se();return}l.renderer.rendering.then(()=>{Hg({source:f,element:y,feedbackElement:v,placeholder:Z,translate:oe,moved:Ue,transition:N,alignment:f.alignment,styles:L,animation:ne??void 0,getElementMutationObserver:()=>we,cleanup:se,restoreFocus:V})})}});return()=>{se(),Yt()}};xt(Vr,4,"overlay",uu,Gn,Ea);gn(Vr,Gn);Gn.configure=es(Gn);var Ca=Gn,cr=!0,qg=!1,pu,gu,mu,vu,zt,Oa,Ma;vu=(mu=[le],mt.Forward),gu=(pu=[le],mt.Reverse);var Xr=class{constructor(){ze(this,Oa,Ve(zt,8,this,cr)),Ve(zt,11,this),ze(this,Ma,Ve(zt,12,this,cr)),Ve(zt,15,this)}isLocked(e){return e===mt.Idle?!1:e==null?this[mt.Forward]===cr&&this[mt.Reverse]===cr:this[e]===cr}unlock(e){e!==mt.Idle&&(this[e]=qg)}};zt=tr(null);Oa=new WeakMap;Ma=new WeakMap;xt(zt,4,vu,mu,Xr,Oa);xt(zt,4,gu,pu,Xr,Ma);gn(zt,Xr);var Ug=[mt.Forward,mt.Reverse],_l=class{constructor(){this.x=new Xr,this.y=new Xr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Kg=class extends et{constructor(e){super(e);const t=qn(new _l);let n=null;this.signal=t,yt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new _l;return}const{delta:s}=e.dragOperation.position;if(n){const o={x:kl(s.x,n.x),y:kl(s.y,n.y)},i=t.peek();Re(()=>{for(const a of Uc)for(const l of Ug)o[a]===l&&i[a].unlock(l);t.value=i})}n=s})}get current(){return this.signal.peek()}};function kl(e,t){return Math.sign(e-t)}var yu,Si,Yr,Ia,Wt,$i,ss=class extends(Si=ts,yu=[le],Si){constructor(e){super(e),ze(this,Ia,Ve(Yr,8,this,!1)),Ve(Yr,11,this),ze(this,Wt),ze(this,$i,()=>{if(!xe(this,Wt))return;const{element:o,by:i}=xe(this,Wt);i.y&&(o.scrollTop+=i.y),i.x&&(o.scrollLeft+=i.x)}),this.scroll=(o,i)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return st(this,Wt,void 0),!1;const{position:u}=this.manager.dragOperation,c=u?.current;if(c){const{by:d}=o??{},f=d?{x:Sl(d.x),y:Sl(d.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const y of l){const g=Gp(y,d);if(g.x||g.y){const{speed:w,direction:x}=eg(y,c,f,i?.acceleration,i?.threshold);if(h)for(const p of Uc)h[p].isLocked(x[p])&&(w[p]=0,x[p]=0);if(x.x||x.y){const{x:p,y:v}=d??x,_=p*w.x,b=v*w.y;if(_||b){const E=(a=xe(this,Wt))==null?void 0:a.by;if(this.autoScrolling&&E&&(E.x&&!_||E.y&&!b))continue;return st(this,Wt,{element:y,by:{x:_,y:b}}),Xs.schedule(xe(this,$i)),!0}}}}}return st(this,Wt,void 0),!1};let t=null,n=null;const r=ei(()=>{const{position:o,source:i}=e.dragOperation;if(!o)return null;const a=Wd(Us(i?.element),o.current);return a&&(t=a),a??t}),s=ei(()=>{const o=r.value,{documentElement:i}=Jn(o);if(!o||o===i){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=vi(l,{excludeElement:!1});return n=u,u}}if(o){const a=vi(o,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},wt);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Kg(e),this.destroy=e.monitor.addEventListener("dragmove",o=>{this.disabled||o.defaultPrevented||!Ur(e.dragOperation.activatorEvent)||!o.by||this.scroll({by:o.by})&&o.preventDefault()})}};Yr=tr(Si);Ia=new WeakMap;Wt=new WeakMap;$i=new WeakMap;xt(Yr,4,"autoScrolling",yu,ss,Ia);gn(Yr,ss);function Sl(e){return e>0?mt.Forward:e<0?mt.Reverse:mt.Idle}var Vg=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))}},Xg=new Vg(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Yg=10,Ti=class extends et{constructor(t,n){super(t,n);const r=t.registry.plugins.get(ss);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=yt(()=>{var s,o,i;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const u={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((o=this.options)==null?void 0:o.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(i=this.options)==null?void 0:i.threshold};if(r.scroll(void 0,u)){r.autoScrolling=!0;const d=setInterval(()=>Xg.schedule(()=>r.scroll(void 0,u)),Yg);return()=>{clearInterval(d)}}else r.autoScrolling=!1}})}};Ti.configure=es(Ti);var xu=Ti,$l={capture:!0,passive:!0},kr,Qg=class extends ts{constructor(e){super(e),ze(this,kr),this.handleScroll=()=>{xe(this,kr)==null&&st(this,kr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),st(this,kr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=yt(()=>{var n,r,s;if(t.status.dragging){const i=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return i.addEventListener("scroll",this.handleScroll,$l),()=>{i.removeEventListener("scroll",this.handleScroll,$l)}}})}};kr=new WeakMap;var Zg="* { user-select: none !important; -webkit-user-select: none !important; }",Jg=class extends et{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(yo),n=t?.register(Zg);if(this.destroy=yt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Po(),document.addEventListener("selectionchange",Po,{capture:!0}),()=>{document.removeEventListener("selectionchange",Po,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Po(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Sr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),En,eo=class extends Bn{constructor(t,n){super(t),this.manager=t,this.options=n,ze(this,En,[]),this.listeners=new Nd,this.handleSourceKeyDown=(r,s,o)=>{if(this.disabled||r.defaultPrevented||!dn(r.target)||s.disabled)return;const{keyboardCodes:i=Sr.keyboardCodes,preventActivation:a=Sr.preventActivation}=o??{};i.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,o))}}bind(t,n=this.options){return yt(()=>{var s;const o=(s=t.handle)!=null?s:t.element,i=a=>{Ur(a)&&this.handleSourceKeyDown(a,t,n)};if(o)return o.addEventListener("keydown",i),()=>{o.removeEventListener("keydown",i)}})}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:o}=new Et(s);if(this.manager.actions.start({event:t,coordinates:{x:o.x,y:o.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Jn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:u=>this.handleKeyDown(u,n,r),options:{capture:!0}}])];xe(this,En).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=Sr.keyboardCodes}=r??{};if(yn(t,[...s.end,...s.cancel])){t.preventDefault();const o=yn(t,s.cancel);this.handleEnd(t,o);return}yn(t,s.up)?this.handleMove("up",t):yn(t,s.down)&&this.handleMove("down",t),yn(t,s.left)?this.handleMove("left",t):yn(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:o}=this.manager.dragOperation,i=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:Sr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!o){switch(t){case"up":a={x:0,y:-l.y*i};break;case"down":a={x:0,y:l.y*i};break;case"left":a={x:-l.x*i,y:0};break;case"right":a={x:l.x*i,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(xu);t?.disabled===!1&&(t.disable(),xe(this,En).push(()=>{t.enable()}))}cleanup(){xe(this,En).forEach(t=>t()),st(this,En,[])}destroy(){this.cleanup(),this.listeners.clear()}};En=new WeakMap;eo.configure=es(eo);eo.defaults=Sr;var bu=eo;function yn(e,t){return t.includes(e.code)}var rn,em=class extends Sd{constructor(){super(...arguments),ze(this,rn)}onEvent(e){switch(e.type){case"pointerdown":st(this,rn,Fn(e));break;case"pointermove":if(!xe(this,rn))return;const{x:t,y:n}=Fn(e),r={x:t-xe(this,rn).x,y:n-xe(this,rn).y},{tolerance:s}=this.options;if(s&&ci(r,s)){this.abort();return}ci(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){st(this,rn,void 0)}};rn=new WeakMap;var Cn,sn,tm=class extends Sd{constructor(){super(...arguments),ze(this,Cn),ze(this,sn)}onEvent(e){switch(e.type){case"pointerdown":st(this,sn,Fn(e)),st(this,Cn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!xe(this,sn))return;const{x:t,y:n}=Fn(e),r={x:t-xe(this,sn).x,y:n-xe(this,sn).y};ci(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){xe(this,Cn)&&(clearTimeout(xe(this,Cn)),st(this,sn,void 0),st(this,Cn,void 0))}};Cn=new WeakMap;sn=new WeakMap;var Pn=class{};Pn.Delay=tm;Pn.Distance=em;var Ei=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&dn(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new Pn.Delay({value:250,tolerance:5})]:ug(s)&&!e.defaultPrevented?[new Pn.Delay({value:200,tolerance:0})]:[new Pn.Delay({value:200,tolerance:10}),new Pn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!dn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Dp(r);return s===t.element?!1:!!s}}),On,to=class extends Bn{constructor(t,n){super(t),this.manager=t,this.options=n,ze(this,On,new Set),this.listeners=new Nd,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=Ei.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return yt(()=>{var s;const o=new AbortController,{signal:i}=o,a=u=>{dg(u)&&this.handlePointerDown(u,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const u of l)u&&(sm(u.ownerDocument.defaultView),u.addEventListener("pointerdown",a,{signal:i}));return()=>o.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!dn(t.target)||n.disabled||nm(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=Ei.preventActivation}=r??{};if(s?.(t,n))return;const{target:o}=t,i=Kt(o)&&o.draggable&&o.getAttribute("draggable")==="true",a=Nn(n.element),{x:l,y:u}=Fn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:u*a.scaleY+a.y};const c=this.activationConstraints(t,n,r);t.sensor=this;const d=new kp(c,g=>this.handleStart(n,g));d.signal.onabort=()=>this.handleCancel(t),d.onEvent(t),this.controller=d;const f=hi(),h=this.listeners.bind(f,[{type:"pointermove",listener:g=>this.handlePointerMove(g,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:i?this.handleCancel:hs,options:{capture:!0}}]),y=()=>{h(),this.initialCoordinates=void 0};xe(this,On).add(y)}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 o=Fn(t),i=Nn(n.element);o.x=o.x*i.scaleX+i.x,o.y=o.y*i.scaleY+i.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=o,Xs.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Jn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=dn(n.target)?[n.target,a]:a,u=this.listeners.bind(l,[{type:"touchmove",listener:hs,options:{passive:!1}},{type:"click",listener:hs},{type:"contextmenu",listener:hs},{type:"keydown",listener:this.handleKeyDown}]);xe(this,On).add(u)}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},xe(this,On).forEach(n=>n()),xe(this,On).clear()}destroy(){this.cleanup(),this.listeners.clear()}};On=new WeakMap;to.configure=es(to);to.defaults=Ei;var Ci=to;function nm(e){return"sensor"in e}function hs(e){e.preventDefault()}function rm(){}var Tl=new WeakSet;function sm(e){!e||Tl.has(e)||(e.addEventListener("touchmove",rm,{capture:!1,passive:!1}),Tl.add(e))}var Rn={modifiers:[],plugins:[Og,xu,Ig,Ca,Jg],sensors:[Ci,bu]},wu=class extends Tp{constructor(e={}){const t=St(e.plugins,Rn.plugins),n=St(e.sensors,Rn.sensors),r=St(e.modifiers,Rn.modifiers);super(Sa(Kr({},e),{plugins:[Qg,ss,yo,...t],sensors:n,modifiers:r}))}},_u,ku,Oi,Gt,Da,Pa,xo=class extends(Oi=Ot,ku=[le],_u=[le],Oi){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:o}=n,i=eu(n,["element","effects","handle"]);super(Kr({effects:()=>[...s(),()=>{var a,l;const{manager:u}=this;if(!u)return;const d=((l=(a=this.sensors)==null?void 0:a.map(zr))!=null?l:[...u.sensors]).map(f=>{const h=f instanceof Bn?f:u.registry.register(f.plugin),y=f instanceof Bn?void 0:f.options;return h.bind(this,y)});return function(){d.forEach(h=>h())}}]},i),t),ze(this,Da,Ve(Gt,8,this)),Ve(Gt,11,this),ze(this,Pa,Ve(Gt,12,this)),Ve(Gt,15,this),this.element=r,this.handle=o}};Gt=tr(Oi);Da=new WeakMap;Pa=new WeakMap;xt(Gt,4,"handle",ku,xo,Da);xt(Gt,4,"element",_u,xo,Pa);gn(Gt,xo);var Su,$u,Mi,Ht,ja,jo,Tu,Eu,Br,Ra,bo=class extends(Mi=Mt,$u=[le],Su=[le],Mi){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,o=eu(n,["element","effects"]);const{collisionDetector:i=Yd}=o,a=u=>{const{manager:c,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!c)return;const f=new Et(d),h=ae(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},l=qn(!1);super(Sa(Kr({},o),{collisionDetector:i,effects:()=>[...s(),()=>{const{element:u,manager:c}=this;if(!c)return;const{dragOperation:d}=c,{source:f}=d;l.value=!!(f&&d.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(l.value&&u){const c=new zp(u,a);return()=>{c.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),ze(this,Br),ze(this,ja,Ve(Ht,8,this)),Ve(Ht,11,this),ze(this,Ra,Ve(Ht,12,this)),Ve(Ht,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){st(this,Br,e,Eu)}get element(){var e;return(e=this.proxy)!=null?e:xe(this,Br,Tu)}};Ht=tr(Mi);ja=new WeakMap;Br=new WeakSet;Ra=new WeakMap;jo=xt(Ht,20,"#element",$u,Br,ja),Tu=jo.get,Eu=jo.set;xt(Ht,4,"proxy",Su,bo,Ra);gn(Ht,bo);function om(e){return e!=null&&typeof e=="object"&&"current"in e}function An(e){var t;if(e!=null)return om(e)?(t=e.current)!=null?t:void 0:e}var im=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",nr=im?S.useLayoutEffect:S.useEffect;function am(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Cu(e,t){const n=S.useRef(new Map),r=am();return nr(()=>{if(!e){n.current.clear();return}return yt(()=>{var s;let o=!1,i=!1;for(const a of n.current){const[l]=a,u=ae(()=>a[1]),c=e[l];u!==c&&(o=!0,n.current.set(l,c),i=(s=t?.(l,u,c))!=null?s:!1)}o&&(i?queueMicrotask(()=>Nf.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(s,o){const i=s[o];return n.current.set(o,i),i}}),[e])}function lm(e,t){e()}function xn(e){const t=S.useRef(e);return nr(()=>{t.current=e},[e]),t}function Pe(e,t,n=S.useEffect,r=Object.is){const s=S.useRef(e);n(()=>{const o=s.current;r(e,o)||(s.current=e,t(e,o))},[t,e])}function Is(e,t){const n=S.useRef(An(e));nr(()=>{const r=An(e);r!==n.current&&(n.current=r,t(r))})}var cm=Object.defineProperty,dm=Object.defineProperties,um=Object.getOwnPropertyDescriptors,no=Object.getOwnPropertySymbols,Ou=Object.prototype.hasOwnProperty,Mu=Object.prototype.propertyIsEnumerable,El=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fm=(e,t)=>{for(var n in t||(t={}))Ou.call(t,n)&&El(e,n,t[n]);if(no)for(var n of no(t))Mu.call(t,n)&&El(e,n,t[n]);return e},hm=(e,t)=>dm(e,um(t)),pm=(e,t)=>{var n={};for(var r in e)Ou.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&no)for(var r of no(e))t.indexOf(r)<0&&Mu.call(e,r)&&(n[r]=e[r]);return n},gm=new wu,Iu=S.createContext(gm),mm=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),s=S.useRef(null),o=S.useRef(null),i=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{o.current=l})),S.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return nr(()=>{var a;(a=o.current)==null||a.call(o),s.current=null},[e,n]),S.useImperativeHandle(t,()=>i),null})),Ro=[void 0,wt];function vm(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:o,onDragMove:i,onDragOver:a,onDragEnd:l}=t,u=pm(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:d,modifiers:f,sensors:h}=u,y=St(d,Rn.plugins),g=St(h,Rn.sensors),w=St(f,Rn.modifiers),x=xn(s),p=xn(o),v=xn(a),_=xn(i),b=xn(l),E=xn(r),T=ym(()=>{var M;return(M=u.manager)!=null?M:new wu(u)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:O}=c.current,{monitor:C}=T;T.renderer=M;const A=[C.addEventListener("beforedragstart",R=>{const L=x.current;L&&O(()=>L(R,T))}),C.addEventListener("dragstart",R=>{var L;return(L=p.current)==null?void 0:L.call(p,R,T)}),C.addEventListener("dragover",R=>{const L=v.current;L&&O(()=>L(R,T))}),C.addEventListener("dragmove",R=>{const L=_.current;L&&O(()=>L(R,T))}),C.addEventListener("dragend",R=>{const L=b.current;L&&O(()=>L(R,T))}),C.addEventListener("collision",R=>{var L;return(L=E.current)==null?void 0:L.call(E,R,T)})];return()=>A.forEach(R=>R())},[T]),Pe(y,()=>T&&(T.plugins=y),...Ro),Pe(g,()=>T&&(T.sensors=g),...Ro),Pe(w,()=>T&&(T.modifiers=w),...Ro),m.jsxs(Iu.Provider,{value:T,children:[m.jsx(mm,{ref:c,children:n}),n]})}function ym(e){const t=S.useRef(null);return t.current||(t.current=e()),S.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function Du(){return S.useContext(Iu)}function Pu(e){var t;const n=(t=Du())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),nr(r.register,[n,r]),r}var xm=Object.create,ju=Object.defineProperty,bm=Object.getOwnPropertyDescriptor,Ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),wo=e=>{throw TypeError(e)},wm=(e,t,n)=>t in e?ju(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_m=e=>{var t;return[,,,xm((t=e?.[Ru("metadata")])!=null?t:null)]},Au=["class","method","getter","setter","accessor","field","value","get","set"],Lu=e=>e!==void 0&&typeof e!="function"?wo("Function expected"):e,km=(e,t,n,r,s)=>({kind:Au[e],name:t,metadata:r,addInitializer:o=>n._?wo("Already initialized"):s.push(Lu(o||null))}),Sm=(e,t)=>wm(t,Ru("metadata"),e[3]),$m=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Bu=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,y=Au[c+5],g=e[h]||(e[h]=[]),w=(s=s.prototype,bm(s,n)),x=r.length-1;x>=0;x--)l=km(c,n,a={},e[3],g),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(w[y],l),a._=1,Lu(i)&&(w[y]=i);return w&&ju(s,n,w),s},Fu=(e,t,n)=>t.has(e)||wo("Cannot "+n),Tm=(e,t,n)=>(Fu(e,t,"read from private field"),t.get(e)),Em=(e,t,n)=>t.has(e)?wo("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Cm=(e,t,n,r)=>(Fu(e,t,"write to private field"),t.set(e,n),n),an=class Ii{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ii(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 Ii(t,n)}},Wu,Nu,Di,Ds,os,Aa=class extends(Di=hn,Nu=[We],Wu=[We],Di){constructor(e){const t=an.from(e);super(t,(n,r)=>an.equals(n,r)),$m(os,5,this),Em(this,Ds,0),this.velocity={x:0,y:0}}get delta(){return an.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=an.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),o=s-Tm(this,Ds),i=a=>Math.round(a/o*100);Re(()=>{Cm(this,Ds,s),this.velocity={x:i(r.x),y:i(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(an.from(e)),this.velocity={x:0,y:0}}};os=_m(Di);Ds=new WeakMap;Bu(os,2,"delta",Nu,Aa);Bu(os,2,"direction",Wu,Aa);Sm(os,Aa);var zu=(e=>(e.Horizontal="x",e.Vertical="y",e))(zu||{});Object.values(zu);var Om=({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=an.distance(t.shape.center,n);return{id:r,value:1/s,type:Zn.PointerIntersection,priority:Qn.High}}return null},Mm=({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,o=an.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Zn.ShapeIntersection,priority:Qn.Normal}}return null},Im=e=>{var t;return(t=Om(e))!=null?t:Mm(e)};function Dm(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:o,accept:i,type:a}=e,l=Pu(c=>new bo(hm(fm({},e),{register:!1,element:An(s)}),c)),u=Cu(l);return Pe(o,()=>l.id=o),Is(s,c=>l.element=c),Pe(i,()=>l.accept=i,void 0,wt),Pe(t,()=>l.collisionDetector=t??Im),Pe(n,()=>n&&(l.data=n)),Pe(r,()=>l.disabled=r===!0),Pe(a,()=>l.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:S.useCallback(c=>{var d,f;!c&&((d=l.element)!=null&&d.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=c??void 0)},[l])}}const Gu=(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 ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},Hu=S.createContext(void 0);function qu(e,t){const n=S.useContext(Hu),r=S.useRef(t);r.current=t,S.useEffect(()=>{if(!n||!e)return;const o=()=>r.current();return n.commitRef.current=o,()=>{n.commitRef.current===o&&(n.commitRef.current=void 0)}},[n,e]);const s=S.useRef(!1);S.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),S.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function Pi({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:o}=be.usePublisherTheme(),[i,a]=S.useState(void 0),l=S.useRef(!1),u=()=>{l.current||i===void 0||(a(void 0),i!==e&&r(i))};qu(i!==void 0&&i!==e,()=>(u(),!0));const c=()=>{l.current=!1,a(e)};if(i===void 0){const d=e==="",f=d&&s;return m.jsx($.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:c,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),c())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...d&&{fontStyle:"italic",opacity:f?0:.6}},Gu(o)],children:d?t:e})}return m.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:i,placeholder:t,inputProps:{"aria-label":n},onFocus:d=>d.target.select(),onChange:d=>a(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.nativeEvent.isComposing?u():d.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:u,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Pm=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const o={...n};return s?o.break=!0:delete o.break,o}),jm=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const o=r[t];s.break&&o&&!o.break&&(r[t]={...o,break:!0});const i={...s};return delete i.break,r.splice(n,0,i),r},Uu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),Ku=e=>`gap.${e}`,Rm=(e,t)=>{const n=[];let r=0;e.forEach((o,i)=>{const a=Math.min(o.colspan??1,t),l=i===0||o.break===!0||r+a>t;l&&i>0&&r<t&&n.push({kind:"gap",after:fe(e[i-1]),colspan:t-r}),l&&(r=0),n.push(Uu(o,i)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:fe(s),colspan:t-r}),n};var Am=Object.create,Vu=Object.defineProperty,Lm=Object.defineProperties,Bm=Object.getOwnPropertyDescriptor,Fm=Object.getOwnPropertyDescriptors,ro=Object.getOwnPropertySymbols,Xu=Object.prototype.hasOwnProperty,Yu=Object.prototype.propertyIsEnumerable,Wm=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),is=e=>{throw TypeError(e)},ji=(e,t,n)=>t in e?Vu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ao=(e,t)=>{for(var n in t||(t={}))Xu.call(t,n)&&ji(e,n,t[n]);if(ro)for(var n of ro(t))Yu.call(t,n)&&ji(e,n,t[n]);return e},Lo=(e,t)=>Lm(e,Fm(t)),Nm=(e,t)=>{var n={};for(var r in e)Xu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ro)for(var r of ro(e))t.indexOf(r)<0&&Yu.call(e,r)&&(n[r]=e[r]);return n},zm=e=>{var t;return[,,,Am((t=void 0)!=null?t:null)]},Qu=["class","method","getter","setter","accessor","field","value","get","set"],$r=e=>e!==void 0&&typeof e!="function"?is("Function expected"):e,Gm=(e,t,n,r,s)=>({kind:Qu[e],name:t,metadata:r,addInitializer:o=>n._?is("Already initialized"):s.push($r(o||null))}),Hm=(e,t)=>ji(t,Wm("metadata"),e[3]),ps=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Zu=(e,t,n,r,s,o)=>{for(var i,a,l,u,c,d=t&7,f=!1,h=!1,y=e.length+1,g=Qu[d+5],w=e[y-1]=[],x=e[y]||(e[y]=[]),p=(s=s.prototype,Bm({get[n](){return Tr(this,o)},set[n](_){return on(this,o,_)}},n)),v=r.length-1;v>=0;v--)u=Gm(d,n,l={},e[3],x),u.static=f,u.private=h,c=u.access={has:_=>n in _},c.get=_=>_[n],c.set=(_,b)=>_[n]=b,a=(0,r[v])({get:p.get,set:p.set},u),l._=1,a===void 0?$r(a)&&(p[g]=a):typeof a!="object"||a===null?is("Object expected"):($r(i=a.get)&&(p.get=i),$r(i=a.set)&&(p.set=i),$r(i=a.init)&&w.unshift(i));return p&&Vu(s,n,p),s},Ju=(e,t,n)=>t.has(e)||is("Cannot "+n),Tr=(e,t,n)=>(Ju(e,t,"read from private field"),t.get(e)),dr=(e,t,n)=>t.has(e)?is("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),on=(e,t,n,r)=>(Ju(e,t,"write to private field"),t.set(e,n),n);function ln(e){return e instanceof Fa||e instanceof rf}var gs=10,qm=class extends et{constructor(e){super(e);const t=yt(()=>{const{dragOperation:r}=e;if(Ur(r.activatorEvent)&&ln(r.source)&&r.status.initialized){const s=e.registry.plugins.get(ss);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:o}=s;if(!Ur(r.nativeEvent)||!ln(o.source)||!o.shape)return;const{actions:i,collisionObserver:a,registry:l}=s,{by:u}=r;if(!u)return;const c=Um(u),{source:d,target:f}=o,{center:h}=o.shape.current,y=[],g=[];Re(()=>{for(const b of l.droppables){const{id:E}=b;if(!b.accepts(d)||E===f?.id&&ln(b)||!b.element)continue;let T=b.shape;const M=new Et(b.element,{getBoundingClientRect:O=>Hr(O,void 0,.2)});!M.height||!M.width||(c=="down"&&h.y+gs<M.center.y||c=="up"&&h.y-gs>M.center.y||c=="left"&&h.x-gs>M.center.x||c=="right"&&h.x+gs<M.center.x)&&(y.push(b),b.shape=M,g.push(()=>b.shape=T))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(y,pg);Re(()=>g.forEach(b=>b()));const[x]=w;if(!x)return;const{id:p}=x,{index:v,group:_}=d.sortable;i.setDropTarget(p).then(()=>{const{source:b,target:E,shape:T}=o;if(!b||!ln(b)||!T)return;const{index:M,group:O,target:C}=b.sortable,A=v!==M||_!==O,R=A?C:E?.element;if(!R)return;Vd(R);const L=new Et(R);if(!L)return;const G=Ct.delta(L,Ct.from(T.current.boundingRectangle),b.alignment);i.move({by:G}),A?i.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Um(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 Km=Object.defineProperty,Vm=Object.defineProperties,Xm=Object.getOwnPropertyDescriptors,Cl=Object.getOwnPropertySymbols,Ym=Object.prototype.hasOwnProperty,Qm=Object.prototype.propertyIsEnumerable,Ol=(e,t,n)=>t in e?Km(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))Ym.call(t,n)&&Ol(e,n,t[n]);if(Cl)for(var n of Cl(t))Qm.call(t,n)&&Ol(e,n,t[n]);return e},wn=(e,t)=>Vm(e,Xm(t));function Zm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ms(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Bo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Jm(e,t,n){var r,s;const{source:o,target:i,canceled:a}=t.operation;if(!o||!i||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(v,_)=>v===_||v!==null&&typeof v=="object"&&"id"in v&&v.id===_;if(Array.isArray(e)){const v=e.findIndex(b=>l(b,o.id)),_=e.findIndex(b=>l(b,i.id));if(v===-1||_===-1){if(Bo(o)){const b=o.initialIndex,E=o.index;return b===E||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,E)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==v)return n(e,v,b)}return n(e,v,_)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[v,_]of u)if(c===-1&&(c=_.findIndex(b=>l(b,o.id)),c!==-1&&(d=v)),f===-1&&(f=_.findIndex(b=>l(b,i.id)),f!==-1&&(h=v)),c!==-1&&f!==-1)break;if(c===-1&&Bo(o)){const v=o.initialGroup==null?void 0:ms(e,o.initialGroup),_=o.initialIndex,b=o.group==null?void 0:ms(e,o.group),E=o.index;if(v==null||b==null||v===b&&_===E)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return wn(bn({},e),{[v]:n(e[v],_,E)});const T=e[v][_];return wn(bn({},e),{[v]:[...e[v].slice(0,_),...e[v].slice(_+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:y}=o.manager,g=(s=(r=y.shape)==null?void 0:r.current.center)!=null?s:y.position.current;if(h==null){const v=ms(e,i.id);if(v!=null){const _=i.shape&&g.y>i.shape.center.y?e[v].length:0;h=v,f=_}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&Bo(o)){const v=o.group==null?void 0:ms(e,o.group),_=o.group!=null&&v!==d,b=o.index!==c;if(_||b){const E=o.group==null?d:v;if(E!=null){if(d===E)return wn(bn({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return wn(bn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[E]:[...e[E].slice(0,o.index),T,...e[E].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return wn(bn({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(g.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return wn(bn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[h]:[...e[h].slice(0,f+x),p,...e[h].slice(f+x)]})}function ev(e,t){return Jm(e,t,Zm)}function Ml(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Il(e,t,n){var r;for(const[s,o]of t)for(const i of o){const a=e.get(i.id);if(i.index!==a||i.group!==s||!((r=n.get(s))!=null&&r.has(i)))return!0}return!1}var Dl="__default__",tv=class extends et{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof Fa){const{sortable:o}=s,{group:i}=o;let a=r.get(i);a||(a=new Set,r.set(i,a)),a.add(o)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:o}=s,{source:i,target:a}=o;if(!ln(i)||!ln(a)||i.sortable===a.sortable)return;const l=t(),u=Ml(l),c=i.sortable.group===a.sortable.group,d=l.get(i.sortable.group),f=c?d:l.get(a.sortable.group);!d||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,y;const g=t();if(Il(u,l,g))return;const w=i.sortable.element,x=a.sortable.element;if(!x||!w||!c&&a.id===i.sortable.group)return;const p=vs(d),v=c?p:vs(f),_=(h=i.sortable.group)!=null?h:Dl,b=(y=a.sortable.group)!=null?y:Dl,E={[_]:p,[b]:v},T=ev(E,r);if(E===T)return;const M=T[b].indexOf(i.sortable),O=T[b].indexOf(a.sortable);s.collisionObserver.disable(),Pl(w,M,x,O),Re(()=>{for(const[C,A]of T[_].entries())A.index=C;if(!c)for(const[C,A]of T[b].entries())A.group=a.sortable.group,A.index=C}),s.actions.setDropTarget(i.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:o}=s,{source:i}=o;ln(i)&&(i.sortable.initialIndex===i.sortable.index&&i.sortable.initialGroup===i.sortable.group||queueMicrotask(()=>{const a=t(),l=Ml(a),u=a.get(i.sortable.initialGroup);u&&s.renderer.rendering.then(()=>{const c=t();if(Il(l,a,c))return;const d=vs(u),f=vs(u,rv),h=i.sortable.element,y=f.indexOf(i.sortable),g=d[y],w=g?.element;!g||!w||!h||(Pl(h,g.index,w,i.index),Re(()=>{for(const x of a.values()){const p=Array.from(x).values();for(const v of p)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 nv(e,t){return e.index-t.index}function rv(e,t){return e.initialIndex-t.initialIndex}function vs(e,t=nv){return Array.from(e).sort(t)}var jl=[qm,tv],ef={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Rl(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 ys=new Qh,tf,nf,qt,La,Er,Cr,Ba,Mn;nf=[le],tf=[le];var _o=class{constructor(e,t){dr(this,La,ps(qt,8,this)),ps(qt,11,this),dr(this,Er),dr(this,Cr),dr(this,Ba,ps(qt,12,this)),ps(qt,15,this),dr(this,Mn),this.register=()=>(Re(()=>{var y,g;(y=this.manager)==null||y.registry.register(this.droppable),(g=this.manager)==null||g.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Re(()=>{var y,g;(y=this.manager)==null||y.registry.unregister(this.droppable),(g=this.manager)==null||g.registry.unregister(this.draggable)})},this.destroy=()=>{Re(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:o,index:i,sensors:a,type:l,transition:u=ef,plugins:c}=n,d=Nm(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=St(c,jl),h=Rl(s);this.droppable=new Fa(Lo(Ao({},d),{disabled:h.droppable}),t,this),this.draggable=new rf(Lo(Ao({},d),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var y,g,w;const x=(y=this.manager)==null?void 0:y.dragOperation.status;x?.initializing&&this.id===((w=(g=this.manager)==null?void 0:g.dragOperation.source)==null?void 0:w.id)&&ys.clear(this.manager),x?.dragging&&ys.set(this.manager,this.id,ae(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:y,group:g,manager:w}=this,x=Tr(this,Cr),p=Tr(this,Er);(y!==x||g!==p)&&(on(this,Cr,y),on(this,Er,g),this.animate())},()=>{var y,g;const{target:w}=this,{isDragSource:x}=this.draggable;((g=(y=this.draggable.pluginConfig(Ca))==null?void 0:y.feedback)!=null?g:"default")==="move"&&x&&(this.droppable.disabled=!w)},...r()],type:l,sensors:a}),t,this),on(this,Mn,d.element),this.manager=t,this.index=i,on(this,Cr,i),this.group=o,on(this,Er,o),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=ys.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=ys.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ae(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:s}=this;if(!s)return;for(const c of s.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const o=this.refreshShape();if(!o)return;const i={x:n.boundingRectangle.left-o.boundingRectangle.left,y:n.boundingRectangle.top-o.boundingRectangle.top},{translate:a}=It(s),l=yl(s,a,!1),u=yl(s,a);if(i.x||i.y){const c=ba(ft(s))?Lo(Ao({},t),{duration:0}):t;Xd({element:s,keyframes:{translate:[`${l.x+i.x}px ${l.y+i.y}px ${l.z}`,`${u.x}px ${u.y}px ${u.z}`]},options:c}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Re(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Re(()=>{const t=Tr(this,Mn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),on(this,Mn,e)})}get element(){var e,t;const n=Tr(this,Mn);if(n)return(t=(e=pi.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=St(e,jl)}set disabled(e){const t=Rl(e);Re(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Re(()=>{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??Yd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Re(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};qt=zm();La=new WeakMap;Er=new WeakMap;Cr=new WeakMap;Ba=new WeakMap;Mn=new WeakMap;Zu(qt,4,"index",nf,_o,La);Zu(qt,4,"group",tf,_o,Ba);Hm(qt,_o);var rf=class extends xo{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}},Fa=class extends bo{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},sv=Object.defineProperty,ov=Object.defineProperties,iv=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,av=Object.prototype.hasOwnProperty,lv=Object.prototype.propertyIsEnumerable,Ll=(e,t,n)=>t in e?sv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fo=(e,t)=>{for(var n in t||(t={}))av.call(t,n)&&Ll(e,n,t[n]);if(Al)for(var n of Al(t))lv.call(t,n)&&Ll(e,n,t[n]);return e},cv=(e,t)=>ov(e,iv(t));function dv(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:o,element:i,handle:a,index:l,group:u,disabled:c,modifiers:d,sensors:f,target:h,type:y,plugins:g}=e,w=Fo(Fo({},ef),e.transition),x=Pu(v=>new _o(cv(Fo({},e),{transition:w,register:!1,handle:An(a),element:An(i),target:An(h)}),v)),p=Cu(x,uv);return Pe(s,()=>x.id=s),nr(()=>{Re(()=>{x.group=u,x.index=l})},[x,u,l]),Pe(y,()=>x.type=y),Pe(t,()=>x.accept=t,void 0,wt),Pe(o,()=>o&&(x.data=o)),Pe(l,()=>{var v;(v=x.manager)!=null&&v.dragOperation.status.idle&&w?.idle&&x.refreshShape()},lm),Is(a,v=>x.handle=v),Is(i,v=>x.element=v),Is(h,v=>x.target=v),Pe(c,()=>x.disabled=c??!1,void 0,wt),Pe(f,()=>x.sensors=f,void 0,wt),Pe(n,()=>x.collisionDetector=n),Pe(r,()=>x.collisionPriority=r),Pe(g,()=>x.plugins=g,void 0,wt),Pe(w,()=>x.transition=w,void 0,wt),Pe(d,()=>x.modifiers=d,void 0,wt),Pe(e.alignment,()=>x.alignment=e.alignment),{sortable:p,get isDragging(){return p.isDragging},get isDropping(){return p.isDropping},get isDragSource(){return p.isDragSource},get isDropTarget(){return p.isDropTarget},handleRef:S.useCallback(v=>{x.handle=v??void 0},[x]),ref:S.useCallback(v=>{var _,b;!v&&((_=x.element)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.element=v??void 0)},[x]),sourceRef:S.useCallback(v=>{var _,b;!v&&((_=x.source)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.source=v??void 0)},[x]),targetRef:S.useCallback(v=>{var _,b;!v&&((_=x.target)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.target=v??void 0)},[x])}}function uv(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Ri="tile",sf="gap",fv=[Ci.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${of}], ${hv}`)!==null||(Ci.defaults.preventActivation?.(e,t)??!1)}),bu],of="data-no-drag",hv=".malloy-render, .malloy-table",pv=e=>[...e,Ca.configure({feedback:"clone"})];function gv({id:e,index:t,disabled:n=!1,children:r}){const{ref:s,handleRef:o,isDragSource:i}=dv({id:e,index:t,disabled:n,type:Ri,accept:Ri,collisionDetector:_a,plugins:pv});return m.jsx(m.Fragment,{children:r({ref:s,handleRef:o,isDragSource:i})})}function mv({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Dm({id:e,type:sf,accept:Ri,collisionDetector:_a,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}function vv({active:e}){const t=Du();return S.useEffect(()=>{if(!e||!t)return;const n=r=>{r.key!=="Escape"||t.dragOperation.status.idle||(r.preventDefault(),r.stopPropagation(),t.actions.stop({event:r,canceled:!0}))};return window.addEventListener("keydown",n,!0),()=>window.removeEventListener("keydown",n,!0)},[e,t]),null}const af=e=>e.ok===!1,He=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),rr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,Ie={sourceDefinition:e=>He(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>He(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>He(e,"VIEW","subQueryDefList"),defDimension:e=>He(e,"defList","DIMENSION"),exploreProperties:e=>He(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>He(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>He(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>He(e,"WHERE","filterClauseList"),givenDef:e=>He(e,"givenNameDef"),givenStatement:e=>He(e,"GIVEN","givenDefList"),importStatement:e=>He(e,"IMPORT","importURL"),vArrow:e=>He(e,"ARROW","vExpr","segExpr"),segRefine:e=>He(e,"PLUS","segExpr"),segOps:e=>He(e,"queryProperties"),segField:e=>He(e,"fieldPath")&&!He(e,"segExpr"),segParen:e=>He(e,"OPAREN","CPAREN","vExpr"),compare:e=>He(e,"fieldExpr","compareOp"),givenRef:e=>He(e,"GIVEN_REF")};function yv(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 xv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
68
|
`&&t.push(n+1);return t}function lf(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!rr(s))continue;const o=Ne(s,"docAnnotations");if(o)for(const i of Xt(o,"docAnnotation")){const a=e.text_(i);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class cf{constructor(t){this.text=t,this.map=yv(t),this.lineStarts=xv(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!rr(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],o=this.map[r.stopIndex+1];if(!(s===void 0||o===void 0||o<s))return{start:s,end:o}}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 as(e,t,n=[]){rr(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)as(e.getChild(r),t,n);return n}const bv=e=>He(e,"OCURLY","CCURLY");function Qr(e,t){const n=[],r=s=>{if(rr(s)){if(t(s)){n.push(s);return}if(!bv(s))for(let o=0;o<(s.childCount??0);o++)r(s.getChild(o))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Ne=(e,t)=>e[t]?.call(e),Xt=(e,t)=>e[t]?.call(e)??[];function wv(e,t){if(!Ie.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!Ie.givenRef(n))return;const r=e.text_(t.getChild(0)),s=e.text_(t.getChild(1)),o=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:o.replace(/^\$/,"")}}function df(e,t){const n=e.positioned(t);if(!n)return;const r=Ne(t,"filterClauseList"),s=[];for(const o of r?Xt(r,"fieldExpr"):[]){const i=e.positioned(o);if(!i)continue;const a=as(o,Ie.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));s.push({...i,givens:a,binding:wv(e,o)})}return{...n,clauses:s}}function Ai(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const u of Qr(t,Ie.queryStatement)){const c=e.positioned(u);c&&r.push(c);const d=Ne(u,"whereStatement");if(d&&Ie.whereStatement(d)){const f=df(e,d);f&&s.push(f)}}const o=n.start+1,i=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
|
|
69
69
|
`),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:o,closeStart:i,statements:r,wheres:s,indent:l,oneLine:a}}function Wa(e,t,n){const r=[],s=e.line(t.start),o=e.line(n);for(let i=s;i<o;i++){if(e.commentLines.has(i)||e.proseLines.has(i))continue;const a=e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:i,text:a})}return r}function _v(e,t){const n=Ne(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=Ie.vArrow(t);if(Ie.segOps(n)){const s=Ne(n,"queryProperties"),o=s&&Ai(e,s);return o?{kind:"inline",stage:o,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(Ie.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(Ie.segRefine(n)){const s=Xt(n,"segExpr"),o=s[0],i=s[s.length-1];let a=o;for(;Ie.segRefine(a);){const f=Xt(a,"segExpr");if(f.some(h=>Ie.segOps(h)||Ie.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&Ie.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!Ie.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const l=e.span(o);if(!l||!i)return{kind:"unsupported",why:"an unreadable refinement"};if(!Ie.segOps(i)){const f=e.span(n);return f?{kind:"reference",from:e.text.slice(f.start,f.end),fromSpan:f}:{kind:"unsupported",why:"an unreadable refinement"}}const u=e.text.slice(l.start,l.end),c=Ne(i,"queryProperties"),d=c&&Ai(e,c);return d?{kind:"reference",from:u,fromSpan:l,refinement:d}:{kind:"reference",from:u,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function kv(e,t){const n=[];for(const r of Qr(t,Ie.defExploreQuery)){const s=e.span(r),o=Ne(r,"subQueryDefList");if(!s||!o)continue;const i=Xt(o,"exploreQueryDef").filter(Ie.exploreQueryDef),a=e.terminal(Ne(r,"VIEW"));for(const l of i){const u=e.span(l),c=Ne(l,"exploreQueryNameDef"),d=e.text_(c),f=Ne(l,"vExpr");!u||!d||!f||n.push({name:d,span:u,line:e.line(u.start),statement:s,tags:Wa(e,s,a?.start??u.start),siblings:i.length,body:_v(e,f)})}}return n}function Sv(e,t){const n=[];for(const r of Qr(t,Ie.defDimension)){const s=e.span(r),o=Ne(r,"defList");if(!s||!o)continue;const i=e.terminal(Ne(r,"DIMENSION"));for(const a of Xt(o,"fieldDef")){const l=e.span(a),u=e.text_(Ne(a,"fieldNameDef"))?.trim(),c=e.text_(Ne(a,"fieldExpr"))?.trim();!l||!u||c===void 0||n.push({name:u,expression:c,span:l,line:e.line(l.start),statement:s,tags:Wa(e,s,i?.start??l.start)})}}return n}function $v(e,t){const n=[];for(const r of as(t,Ie.sourceDefinition)){const s=e.span(r),o=e.text_(Ne(r,"sourceNameDef")),i=Ne(r,"sqExplore");if(!s||!o||!i)continue;const a=e.span(i),l=a?e.text.slice(a.start,a.end):"",u=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(l)?.[1]??"").trim(),c=Qr(i,Ie.exploreProperties)[0],d=c&&Ai(e,c),f={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(c)for(const y of Qr(c,Ie.whereStatement)){const g=df(e,y);g&&h.push(g)}n.push({name:o,base:u,span:s,line:e.line(s.start),statement:f,...d?{properties:d}:{},views:c?kv(e,c):[],dimensions:c?Sv(e,c):[],wheres:h})}return n}function Tv(e,t){const n=[];for(const r of as(t,Ie.givenStatement)){const s=e.terminal(Ne(r,"GIVEN")),o=Ne(r,"givenDefList"),i=s?e.line(s.start):void 0;for(const a of o?Xt(o,"givenDef"):[]){const l=e.span(a),u=e.span(Ne(a,"givenNameDef")),c=u&&e.text.slice(u.start,u.end);if(!l||!u||!c)continue;const d={start:u.start,end:l.end},f=e.line(d.start);n.push({name:c,declaration:e.text.slice(d.start,d.end),span:d,line:f,statement:{start:e.lineStarts[f],end:d.end},tags:Wa(e,l,d.start),...i!==void 0&&i!==f?{blockHeader:i}:{}})}}return n}function Ev(e,t){const n=[];for(const r of as(t,Ie.importStatement)){const s=e.span(r),o=e.text_(Ne(r,"importURL"));if(!s||o===void 0)continue;const i=Ne(r,"importSelect"),a=i?Xt(i,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:o.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function uf(e){let t;try{t=await Na(e,"file://dashboard-builder.malloy")}catch(f){return{ok:!1,reason:`Malloy could not read this file: ${f}`}}const n=t.problems.filter(f=>f.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,s=r?.root;if(!s||!rr(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 o=r?.tokenStream??{},i=typeof o.getTokens=="function"?o.getTokens():void 0;if(!i||typeof o.tokenSource?.vocabulary?.getSymbolicName!="function"||i.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 cf(e),l=Cv(a,o);a.commentLines=l.lines;const u=e.split(`
|
|
70
70
|
`),c=f=>l.lines.has(f);a.proseLines=me.markdownLines(u,c),a.blocks=me.blockSpans(u,c).filter(([f])=>!u[f].trimStart().startsWith("##"));const d=$v(a,s);return d.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:Ev(a,s),sources:d,givens:Tv(a,s),textBlocks:Mv(a,o),modelNotes:lf(a,s),trailingComment:f=>l.trailing.get(f),comments:l.all,commentLine:f=>l.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>l.all.find(h=>h.start>=f.start&&h.start<f.end),blockStart:f=>Ov(a,l.lines,f)}}}async function Na(e,t){const{MalloyTranslator:n}=await k.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Cv(e,t){const n=new Map,r=new Set,s=[],o=t.tokenSource?.vocabulary;for(const c of t.getTokens?.()??[]){const d=o?.getSymbolicName(c.type);if(d!=="COMMENT_TO_EOL"&&d!=="BLOCK_COMMENT")continue;const f=e.utf16(c.startIndex);let h=e.utf16(c.stopIndex+1);if(!(f===void 0||h===void 0||h<f)){for(;h>f&&(e.text[h-1]===`
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
`).replace(/\n$/,""),span:{start:e.lineStarts[f],end:h},line:f}),a=c}return i}function ff(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 hf(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=ff(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 o=/^tiles\s*=\s*\[/.exec(e.slice(r));if(o)return Iv(e,r+o[0].length-1)}}}function Iv(e,t){const n=[];let r=0,s=t+1;const o=i=>{const a=e.slice(s,i),l=a.length-a.trimStart().length,u=a.trim();u!==""&&n.push({text:u,span:{start:s+l,end:s+l+u.length}})};for(let i=t+1;i<e.length;i++){const a=e[i];if(a==='"')i=ff(e,i);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return o(i),{open:t,close:i,entries:n};r--}else a===","&&r===0&&(o(i),s=i+1)}}function Dv(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),o=s===-1?e.length:s;if(e.slice(r,o).trim()===">>>")return o;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 jv(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Dv(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const o=e[r];if(/[=[,]/.test(o)){const i=t.exec(e.slice(r+1));if(i){const a=i[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${o}${i[1]}"f'${a}'"`,r+=1+i[0].length;continue}}n+=o,r+=1}return n}function pf(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(o=>{if(e([o]).log.length===0)return o;const i=jv(o);return e([i]).log.length===0?i:o}),s=e(r);return{tag:s.tag,errors:s.log.map(o=>o.message)}}const Bl=(e,t)=>{try{return e.text(t)}catch{return}},Pv=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Rv=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\`.`,Av=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=[…]\`.`,Lv="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 gf(e,t){const n=e.filter(Pv).filter(c=>!c.includes("@env.")).map(me.tagAnnotation),{tag:r,errors:s}=n.length>0?pf(t,n):{tag:void 0,errors:[]},o=r?.tag("artifact");if(!o)return e.some(me.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const i=Bl(o,"kind");if(i!==void 0)return{status:"kind-removed",kind:i};const a=Bl(o,"layout"),l=o.has("tiles");if(l&&o.array("tiles")===void 0)return{status:"unparsed",errors:s};const u=a==="grid"||a==="linear"?a:l||r?.tag("dashboard")!==void 0?"grid":"linear";return u==="linear"&&!l?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:u}}async function Bv(e){const{parseAnnotation:t}=await k.loadMalloyTag();let n=[];try{const r=(await Na(e,"file://report.malloy")).parse?.root;r&&rr(r)&&typeof r.getChild=="function"&&(n=lf(new cf(e),r))}catch{n=[]}return gf(n,t)}const so=e=>e.ok===!1;function sr(e,t,n){const r=e.blockStart(n),s=[],o=[];for(let i=r;i<n;i++){if(e.commentLine(i))continue;if(e.proseLine(i)){o.push(i);continue}const a=t[i].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:i,text:a})}return{start:r,tags:s,prose:o}}const Ln=e=>e.map(t=>t.text);function Fl(e){const t=Ln(e),n=k.chartStateOfTagLines(t),r=t.map(k.seriesColorOf).filter(Boolean).at(-1),s=r?{color:r}:{};return n===void 0?s:n==="custom"?{chart:n,chartLines:k.chartLinesOf(t),...s}:{chart:n,...s}}function Wl(e,t){return Ln(e).some(r=>k.seriesColorOf(r)===void 0&&t([r]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Fv(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:o,given:i}=r.binding;t.push({field:me.readPath(s),given:i,...o==="~"?{}:{op:o}})}return t.length>0?t:void 0}function Wv(e,t,n){const r=[];for(const s of e.givens){const o=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);o&&r.push({name:o[1],type:o[2],default:o[3].trim(),...Nv(n(Ln(sr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Nv(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 Nl(e){const t=e?.numeric("colspan");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:!0}:{}}}function Or(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 zv=/^"((?:[^"\\]|\\.)+)"\s*(\{[\s\S]*\})?$/;function Wo(e){const t=Or(e,"colspan"),n=Or(e,"rowspan"),r=Or(e,"row"),s=Or(e,"col");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:e.text("break")!=="false"}:{},...n===void 0?{}:{rowspan:n},...r===void 0?{}:{row:r},...s===void 0?{}:{col:s}}}function ur(e,t){const n=t.colspan??e.colspan;return{...n===void 0?{}:{colspan:n},...t.break??e.break?{break:!0}:{},...t.rowspan===void 0?{}:{rowspan:t.rowspan},...t.row===void 0?{}:{row:t.row},...t.col===void 0?{}:{col:t.col}}}const Gv=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,Hv=/^[A-Za-z_][A-Za-z0-9_]*$/;function qv(e,t,n){const r=new RegExp(`^\\s*query\\s*:\\s*${n}\\s+is\\b`);for(let s=0;s<t.length;s++)if(!(e.commentLine(s)||e.proseLine(s))&&r.test(t[s]))return sr(e,t,s).tags;return[]}function zl(e){return{...e?.text("label")?{label:e.text("label")}:{},...e?.text("subtitle")?{subtitle:e.text("subtitle")}:{},...e?.numeric("colspan")!==void 0?{colspan:e.numeric("colspan")}:{},...e?.has("break")?{break:!0}:{},...e?.has("borderless")?{borderless:!0}:{}}}function Gl(e){const{colspan:t,break:n,...r}=e;return r}async function oo(e,t,n=!1){try{return await Uv(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 Uv(e){const{parseAnnotation:t}=await k.loadMalloyTag(),n=me.splitSourceLines(e),r=await uf(e);if(af(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,o=me.descriptionNotes(n).text,i=gf(s.modelNotes,t);if(i.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(i.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${i.errors[0]?`: ${i.errors[0]}`:"."}`};if(i.status==="kind-removed")return{ok:!1,reason:Rv(i.kind)};if(i.status==="cells-removed")return{ok:!1,reason:i.unknownLayout!==void 0?Av(i.unknownLayout):Lv};const a=i.layout,l=me.artifactTag(n);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!me.artifactLeads(l.text))return{ok:!1,reason:me.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:u,errors:c}=pf(t,[me.tagAnnotation(l.text)]),d=u?.tag("artifact"),f=hf(l.text);if(f===void 0)return c.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${c[0]}`}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=s.imports.map(T=>T.names?{kind:"names",names:T.names,from:T.from}:{kind:"all",from:T.from}),y=[],g=[],w=new Map;for(const T of s.sources){const M={name:T.name,base:T.base};T.dimensions.length>0&&(M.dimensions=T.dimensions.map(C=>({name:C.name,expression:C.expression})));const O=new Set(T.wheres.flatMap(C=>C.clauses.flatMap(A=>A.givens)));O.size>0&&(M.scopedBy=Array.from(O)),y.push(M);for(const C of T.dimensions){const A=t(Ln(sr(s,n,C.line).tags)).tag?.tag("drill");if(!A)continue;const R=A.textArray("to")??[A.text("to")??""];g.push({source:T.name,name:C.name,expression:C.expression,to:R.filter(Boolean),...A.text("given")?{given:A.text("given")}:{}})}w.set(T.name,new Map(T.views.map(C=>[C.name,C])))}const x=[],p=(T,M)=>{const O=zl(t(Ln(qv(s,n,T))).tag);return{name:T,declaration:{kind:"query"},...Gl(O),...ur({colspan:O.colspan,break:O.break},M)}};for(const{text:T}of f.entries){const M=zv.exec(T),O=M?void 0:Gv.exec(T)?.[1];if(O!==void 0){const D=t([`# ${T}`]).tag?.tag(O),I=D?.text("kind");if(I===void 0||I==="query"){x.push(p(O,Wo(D)));continue}if(I!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${O} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(x.some(B=>Ce(B)&&B.name===O))return{ok:!1,reason:`Two text tiles are named \`${O}\`, so the builder cannot tell them apart.`};x.push({kind:"text",name:O,markdown:s.textBlocks.find(B=>B.name===O)?.body??"",...ur({},Wo(D))});continue}const C=M?.[1]??T,A=Wo(M?.[2]?t([`# tile ${M[2]}`]).tag?.tag("tile")??void 0:void 0);if(Hv.test(C.trim())){x.push(p(C.trim(),A));continue}const R=M?me.tileSteps(C):void 0;if(!R)return{ok:!1,reason:`The tile \`${C}\` is neither a \`source -> view\` expression nor the name of a query, which are the forms the builder can lay out.`};const{source:L,view:G}=R,N=w.get(L)?.get(G);if(N===void 0){x.push({name:G,source:L,declaration:{kind:"inherited"},...ur({},A)});continue}const X=t(Ln(N.tags)).tag,P=N.body.kind==="reference"?{kind:"reference",from:N.body.from}:N.body.kind==="inline"?{kind:"inline"}:void 0;if(P===void 0){x.push({name:G,source:L,declaration:{kind:"opaque",why:N.body.kind==="unsupported"?N.body.why:"unreadable"},...Gl(zl(X)),...ur(Nl(X),A),...Fl(N.tags),...Wl(N.tags,t)});continue}const z=Fv(N.body.kind==="reference"?N.body.refinement:N.body.kind==="inline"?N.body.stage:void 0);x.push({name:G,source:L,declaration:P,...z?{filters:z}:{},...X?.text("label")?{label:X.text("label")}:{},...X?.text("subtitle")?{subtitle:X.text("subtitle")}:{},...ur(Nl(X),A),...Fl(N.tags),...Wl(N.tags,t),...X?.has("borderless")?{borderless:!0}:{}})}const v=Wv(s,n,t),_={},b=d?.tag("givens");for(const T of Object.keys(b?.dict??{})){const M=b?.text(T);M!==void 0&&(_[T]=M)}const E=u?.tag("dashboard")?.has("columns")?Or(u.tag("dashboard"),"columns"):void 0;return{ok:!0,document:{layout:a,title:d?.text("title")??"",...o?{description:o}:{},...E===void 0?{}:{columns:E},...d?.has("autorun")?{autorun:d.isTrue("autorun")}:{},imports:h,sources:y,...v?{localGivens:v}:{},...Object.keys(_).length>0?{startingGivens:_}:{},...g.length>0?{drills:g}:{},tiles:x}}}const io=e=>e.ok===!1;async function Hl(e){const{problems:t}=await Na(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function Ee(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 mf(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Kv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
-
`&&t.push(n+1);return t}function Vv(e,t){let n=e;const r=t.map((s,o)=>({edit:s,index:o}));for(const{edit:s}of r.sort((o,i)=>i.edit.start-o.edit.start||i.edit.end-o.edit.end||i.index-o.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const vf=e=>e==="none"||k.isChartPick(e)?e:void 0;function yf(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${kt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${kt(e.subtitle)}`);const r=t?vf(e.chart):void 0;return r!==void 0&&n.push(k.chartLineText(r,e.chartCarried)),e.color!==void 0&&n.push(k.seriesColorLine(e.color)),n}const xf="theme.palette.series";function
|
|
76
|
+
`)return s}return e.length}return t}function Pv(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Dv(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const o=e[r];if(/[=[,]/.test(o)){const i=t.exec(e.slice(r+1));if(i){const a=i[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${o}${i[1]}"f'${a}'"`,r+=1+i[0].length;continue}}n+=o,r+=1}return n}function pf(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(o=>{if(e([o]).log.length===0)return o;const i=Pv(o);return e([i]).log.length===0?i:o}),s=e(r);return{tag:s.tag,errors:s.log.map(o=>o.message)}}const Bl=(e,t)=>{try{return e.text(t)}catch{return}},jv=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Rv=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\`.`,Av=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=[…]\`.`,Lv="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 gf(e,t){const n=e.filter(jv).filter(c=>!c.includes("@env.")).map(me.tagAnnotation),{tag:r,errors:s}=n.length>0?pf(t,n):{tag:void 0,errors:[]},o=r?.tag("artifact");if(!o)return e.some(me.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const i=Bl(o,"kind");if(i!==void 0)return{status:"kind-removed",kind:i};const a=Bl(o,"layout"),l=o.has("tiles");if(l&&o.array("tiles")===void 0)return{status:"unparsed",errors:s};const u=a==="grid"||a==="linear"?a:l||r?.tag("dashboard")!==void 0?"grid":"linear";return u==="linear"&&!l?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:u}}async function Bv(e){const{parseAnnotation:t}=await k.loadMalloyTag();let n=[];try{const r=(await Na(e,"file://report.malloy")).parse?.root;r&&rr(r)&&typeof r.getChild=="function"&&(n=lf(new cf(e),r))}catch{n=[]}return gf(n,t)}const so=e=>e.ok===!1;function sr(e,t,n){const r=e.blockStart(n),s=[],o=[];for(let i=r;i<n;i++){if(e.commentLine(i))continue;if(e.proseLine(i)){o.push(i);continue}const a=t[i].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:i,text:a})}return{start:r,tags:s,prose:o}}const Ln=e=>e.map(t=>t.text);function Fl(e){const t=Ln(e),n=k.chartStateOfTagLines(t),r=t.map(k.seriesColorOf).filter(Boolean).at(-1),s=r?{color:r}:{};return n===void 0?s:n==="custom"?{chart:n,chartLines:k.chartLinesOf(t),...s}:{chart:n,...s}}function Wl(e,t){return Ln(e).some(r=>k.seriesColorOf(r)===void 0&&t([r]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Fv(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:o,given:i}=r.binding;t.push({field:me.readPath(s),given:i,...o==="~"?{}:{op:o}})}return t.length>0?t:void 0}function Wv(e,t,n){const r=[];for(const s of e.givens){const o=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);o&&r.push({name:o[1],type:o[2],default:o[3].trim(),...Nv(n(Ln(sr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Nv(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 Nl(e){const t=e?.numeric("colspan");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:!0}:{}}}function Or(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 zv=/^"((?:[^"\\]|\\.)+)"\s*(\{[\s\S]*\})?$/;function Wo(e){const t=Or(e,"colspan"),n=Or(e,"rowspan"),r=Or(e,"row"),s=Or(e,"col");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:e.text("break")!=="false"}:{},...n===void 0?{}:{rowspan:n},...r===void 0?{}:{row:r},...s===void 0?{}:{col:s}}}function ur(e,t){const n=t.colspan??e.colspan;return{...n===void 0?{}:{colspan:n},...t.break??e.break?{break:!0}:{},...t.rowspan===void 0?{}:{rowspan:t.rowspan},...t.row===void 0?{}:{row:t.row},...t.col===void 0?{}:{col:t.col}}}const Gv=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,Hv=/^[A-Za-z_][A-Za-z0-9_]*$/;function qv(e,t,n){const r=new RegExp(`^\\s*query\\s*:\\s*${n}\\s+is\\b`);for(let s=0;s<t.length;s++)if(!(e.commentLine(s)||e.proseLine(s))&&r.test(t[s]))return sr(e,t,s).tags;return[]}function zl(e){return{...e?.text("label")?{label:e.text("label")}:{},...e?.text("subtitle")?{subtitle:e.text("subtitle")}:{},...e?.numeric("colspan")!==void 0?{colspan:e.numeric("colspan")}:{},...e?.has("break")?{break:!0}:{},...e?.has("borderless")?{borderless:!0}:{}}}function Gl(e){const{colspan:t,break:n,...r}=e;return r}async function oo(e,t,n=!1){try{return await Uv(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 Uv(e){const{parseAnnotation:t}=await k.loadMalloyTag(),n=me.splitSourceLines(e),r=await uf(e);if(af(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,o=me.descriptionNotes(n).text,i=gf(s.modelNotes,t);if(i.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(i.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${i.errors[0]?`: ${i.errors[0]}`:"."}`};if(i.status==="kind-removed")return{ok:!1,reason:Rv(i.kind)};if(i.status==="cells-removed")return{ok:!1,reason:i.unknownLayout!==void 0?Av(i.unknownLayout):Lv};const a=i.layout,l=me.artifactTag(n);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!me.artifactLeads(l.text))return{ok:!1,reason:me.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:u,errors:c}=pf(t,[me.tagAnnotation(l.text)]),d=u?.tag("artifact"),f=hf(l.text);if(f===void 0)return c.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${c[0]}`}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=s.imports.map(T=>T.names?{kind:"names",names:T.names,from:T.from}:{kind:"all",from:T.from}),y=[],g=[],w=new Map;for(const T of s.sources){const M={name:T.name,base:T.base};T.dimensions.length>0&&(M.dimensions=T.dimensions.map(C=>({name:C.name,expression:C.expression})));const O=new Set(T.wheres.flatMap(C=>C.clauses.flatMap(A=>A.givens)));O.size>0&&(M.scopedBy=Array.from(O)),y.push(M);for(const C of T.dimensions){const A=t(Ln(sr(s,n,C.line).tags)).tag?.tag("drill");if(!A)continue;const R=A.textArray("to")??[A.text("to")??""];g.push({source:T.name,name:C.name,expression:C.expression,to:R.filter(Boolean),...A.text("given")?{given:A.text("given")}:{}})}w.set(T.name,new Map(T.views.map(C=>[C.name,C])))}const x=[],p=(T,M)=>{const O=zl(t(Ln(qv(s,n,T))).tag);return{name:T,declaration:{kind:"query"},...Gl(O),...ur({colspan:O.colspan,break:O.break},M)}};for(const{text:T}of f.entries){const M=zv.exec(T),O=M?void 0:Gv.exec(T)?.[1];if(O!==void 0){const D=t([`# ${T}`]).tag?.tag(O),I=D?.text("kind");if(I===void 0||I==="query"){x.push(p(O,Wo(D)));continue}if(I!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${O} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(x.some(B=>Ce(B)&&B.name===O))return{ok:!1,reason:`Two text tiles are named \`${O}\`, so the builder cannot tell them apart.`};x.push({kind:"text",name:O,markdown:s.textBlocks.find(B=>B.name===O)?.body??"",...ur({},Wo(D))});continue}const C=M?.[1]??T,A=Wo(M?.[2]?t([`# tile ${M[2]}`]).tag?.tag("tile")??void 0:void 0);if(Hv.test(C.trim())){x.push(p(C.trim(),A));continue}const R=M?me.tileSteps(C):void 0;if(!R)return{ok:!1,reason:`The tile \`${C}\` is neither a \`source -> view\` expression nor the name of a query, which are the forms the builder can lay out.`};const{source:L,view:G}=R,N=w.get(L)?.get(G);if(N===void 0){x.push({name:G,source:L,declaration:{kind:"inherited"},...ur({},A)});continue}const X=t(Ln(N.tags)).tag,j=N.body.kind==="reference"?{kind:"reference",from:N.body.from}:N.body.kind==="inline"?{kind:"inline"}:void 0;if(j===void 0){x.push({name:G,source:L,declaration:{kind:"opaque",why:N.body.kind==="unsupported"?N.body.why:"unreadable"},...Gl(zl(X)),...ur(Nl(X),A),...Fl(N.tags),...Wl(N.tags,t)});continue}const z=Fv(N.body.kind==="reference"?N.body.refinement:N.body.kind==="inline"?N.body.stage:void 0);x.push({name:G,source:L,declaration:j,...z?{filters:z}:{},...X?.text("label")?{label:X.text("label")}:{},...X?.text("subtitle")?{subtitle:X.text("subtitle")}:{},...ur(Nl(X),A),...Fl(N.tags),...Wl(N.tags,t),...X?.has("borderless")?{borderless:!0}:{}})}const v=Wv(s,n,t),_={},b=d?.tag("givens");for(const T of Object.keys(b?.dict??{})){const M=b?.text(T);M!==void 0&&(_[T]=M)}const E=u?.tag("dashboard")?.has("columns")?Or(u.tag("dashboard"),"columns"):void 0;return{ok:!0,document:{layout:a,title:d?.text("title")??"",...o?{description:o}:{},...E===void 0?{}:{columns:E},...d?.has("autorun")?{autorun:d.isTrue("autorun")}:{},imports:h,sources:y,...v?{localGivens:v}:{},...Object.keys(_).length>0?{startingGivens:_}:{},...g.length>0?{drills:g}:{},tiles:x}}}const io=e=>e.ok===!1;async function Hl(e){const{problems:t}=await Na(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function Ee(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 mf(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Kv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
+
`&&t.push(n+1);return t}function Vv(e,t){let n=e;const r=t.map((s,o)=>({edit:s,index:o}));for(const{edit:s}of r.sort((o,i)=>i.edit.start-o.edit.start||i.edit.end-o.edit.end||i.index-o.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const vf=e=>e==="none"||k.isChartPick(e)?e:void 0;function yf(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${kt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${kt(e.subtitle)}`);const r=t?vf(e.chart):void 0;return r!==void 0&&n.push(k.chartLineText(r,e.chartCarried)),e.color!==void 0&&n.push(k.seriesColorLine(e.color)),n}const xf="theme.palette.series";function Ps(e){return k.seriesColorOf(e)!==void 0?xf:/^#\s*([a-z_]+)/.exec(e)?.[1]}const Xv=new Set(["colspan","break","borderless","label","subtitle",xf]),Yv=new Set(["label","description","control","suggest","range_min","range_max"]);function ql(e){const t=[];if(e.label!==void 0&&t.push(`label=${kt(e.label)}`),e.description!==void 0&&t.push(`description=${kt(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=${kt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${kt(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 Ul=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Qv(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function Kl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:kt(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(kt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const ao=e=>`${e.source}.${e.name}`,kt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,Li=e=>Ce(e)?Ee(["text",e.name]):Ee([e.name,e.source,e.declaration]),ot=Li,Vl=e=>Ee(e.tiles.map(ot));function Zv(e,t,n){const r=new Set(e.tiles.map(ot)),s=new Set(t.tiles.map(ot)),o=e.tiles.filter(h=>!s.has(ot(h))),i=t.tiles.filter(h=>!r.has(ot(h))),l=o.length>0||i.length>0||Vl(e)!==Vl(t);for(const h of i)if(ce(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 u=new Map(e.sources.map(h=>[h.name,h])),c=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)c.add(h.base);const d=t.imports.some(h=>h.kind==="all"),f=t.sources.filter(h=>!u.has(h.name));for(const h of e.sources){const y=t.sources.find(g=>g.name===h.name);if(!y||y.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of f){if(!i.some(y=>ce(y)&&y.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!c.has(h.base)&&!d&&!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:o,addedTiles:i,newSources:f,currentSources:u,reordered:l}}const Jv=new Set(["colspan","break"]),Bi=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break||e.rowspan!==t.rowspan||e.row!==t.row||e.col!==t.col,Xl=e=>{const{colspan:t,break:n,rowspan:r,row:s,col:o,...i}=e;return i},ey=e=>[...e.row===void 0?[]:[`row=${e.row}`],...e.col===void 0?[]:[`col=${e.col}`],...e.colspan===void 0?[]:[`colspan=${e.colspan}`],...e.break?["break"]:[],...e.rowspan===void 0?[]:[`rowspan=${e.rowspan}`]];function bf(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Fi(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Yl(e,t){const n=ey(e);if(t===void 0){const c=Ce(e)?e.name:`"${dt(e)}"`,d=[...Ce(e)?["kind=text"]:[],...n];return d.length>0?`${c} { ${d.join(" ")} }`:c}const r=bf(t),s=r.indexOf("{");if(s===-1)return n.length>0?`${t} { ${n.join(" ")} }`:t;const o=r.lastIndexOf("}");let i=t.slice(s+1,o),a=r.slice(s+1,o);const l=c=>{const d=c.exec(a);d&&(i=i.slice(0,d.index)+i.slice(d.index+d[0].length),a=a.slice(0,d.index)+a.slice(d.index+d[0].length))};l(/\s*\bcolspan\s*=\s*[^\s}]+/),l(/\s*\bbreak\b(?:\s*=\s*[^\s}]+)?/),l(/\s*\browspan\s*=\s*[^\s}]+/),l(/\s*\brow\s*=\s*[^\s}]+/),l(/\s*\bcol\s*=\s*[^\s}]+/);const u=[i.trim(),...n].filter(Boolean);return u.length===0?t.slice(0,s).trimEnd():`${t.slice(0,s)}{ ${u.join(" ")} }${t.slice(o+1)}`}function ty(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:o,currentKeys:i,nextKeys:a,edits:l}=e,u=new Map(r.tiles.map(p=>[ot(p),p])),c=s.tiles.some(p=>{const v=u.get(ot(p));return v!==void 0&&Bi(v,p)});if(!o&&!c)return;const d=me.artifactTag(t);if(!d)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=d.text,h=hf(f);if(!h)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&i.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 y=new Map;for(const{text:p}of h.entries){const v=/^"((?:[^"\\]|\\.)+)"\s*(?:\{[\s\S]*\})?$/.exec(p);if(v){const b=v[1].split("->").map(E=>E.trim());b.length===2?y.set(`${b[0]}->${b[1]}`,p):b.length===1&&y.set(`query.${b[0]}`,p);continue}if(me.isIdentifier(p)){y.set(`query.${p}`,p);continue}const _=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(p)?.[1];_!==void 0&&y.set(/\bkind\s*=\s*text\b/.test(bf(p))?`text.${_}`:`query.${_}`,p)}const g=s.tiles.map(p=>{const v=!i.has(ot(p)),_=y.get(Ce(p)?`text.${p.name}`:p.declaration.kind==="query"?`query.${p.name}`:`${p.source}->${p.name}`);if(_===void 0)return v?Yl(p):void 0;const b=u.get(ot(p));return b!==void 0&&!Bi(b,p)?_:Yl(p,_)});if(g.some(p=>p===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const w=f.slice(0,h.open).search(/tiles\s*=\s*$/),x=`${f.slice(0,w)}tiles=[${ny(f,h,g)}]${f.slice(h.close+1)}`;x!==f&&l.push({...wf(n,d),text:`${x}
|
|
78
78
|
`})}function wf(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function ny(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 o=e.slice(t.open+1,r.span.start),i=e.slice(s.span.end,t.close),a=o.slice(o.lastIndexOf(`
|
|
79
79
|
`)),l=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
|
|
80
80
|
`)?a:" "}`;return`${o}${n.join(l)}${i}`}function ry(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Fi(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 o=1,i=n+s[0].length;for(;i<e.length&&o>0;i++)e[i]==='"'?i=Fi(e,i):e[i]==="{"?o++:e[i]==="}"&&o--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(i)}}return e}function Fi(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 sy(e){const{lines:t,wholeLine:n,current:r,next:s,edits:o}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||Ee(r.startingGivens)!==Ee(s.startingGivens)){const i=me.artifactTag(t);if(!i)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=wf(n,i),l=o.find(v=>v.start===a.start&&v.end===a.end);let u=l?l.text.replace(/\n$/,""):i.text;const c=r.layout!==s.layout,d=u.indexOf("artifact"),f=u.indexOf("{",d);let h=0,y=-1;for(let v=f;v<u.length;v++)if(u[v]==="{")h++;else if(u[v]==="}"&&--h===0){y=v;break}if(f<0||y<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let g=u.slice(f+1,y);const w=i.block?`
|
|
@@ -87,7 +87,7 @@ ${b.source}[ \\t]*(?=
|
|
|
87
87
|
`).map(g=>g.trim()===""?'##"':`##" ${g.trim()}`).join(`
|
|
88
88
|
`),f=i.length>0&&i[0]<me.artifactLine(t),h=s.description===void 0,y=f?[...i.slice(1),...h?l:[]]:[...i,...a];for(const g of y)o.push({...n(g),text:""});if(f)o.push({...n(i[0]),text:s.description===void 0?"":`${d}
|
|
89
89
|
`});else if(s.description!==void 0){const g=n(me.artifactLine(t)).start;o.push({start:g,end:g,text:`${d}
|
|
90
|
-
`})}}}function oy(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:o,edits:i,parsed:a}=e,l=new Map((s.localGivens??[]).map(h=>[h.name,h])),u=new Map((o.localGivens??[]).map(h=>[h.name,h])),c=new Map(a.givens.map(h=>[h.name,h])),d=new Set;for(const[h,y]of l){const g=u.get(h);if(g!==void 0&&Ee(g)===Ee(y))continue;const w=c.get(h);if(w===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:x,prose:p}=sr(a,t,w.line),_=[...(g===void 0?x:x.filter(C=>{const A=
|
|
90
|
+
`})}}}function oy(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:o,edits:i,parsed:a}=e,l=new Map((s.localGivens??[]).map(h=>[h.name,h])),u=new Map((o.localGivens??[]).map(h=>[h.name,h])),c=new Map(a.givens.map(h=>[h.name,h])),d=new Set;for(const[h,y]of l){const g=u.get(h);if(g!==void 0&&Ee(g)===Ee(y))continue;const w=c.get(h);if(w===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:x,prose:p}=sr(a,t,w.line),_=[...(g===void 0?x:x.filter(C=>{const A=Ps(C.text);return A!==void 0&&Yv.has(A)})).map(C=>C.line),...g===void 0?p:[]];for(const C of _)i.push({...n(C),text:""}),d.add(C);const b=Lt(a,w.span.end-1);if(g===void 0){i.push({start:n(w.line).start,end:n(b).end,text:""});for(let N=w.line;N<=b;N++)d.add(N);const C=Math.min(w.line,..._),A=w.blockHeader??C,R=(t[b+1]??"x").trim()==="",L=A===0||t[A-1].trim()==="",G=w.blockHeader===void 0||![...c.values()].some(N=>N.blockHeader===w.blockHeader&&N.line>w.line&&u.has([...c.entries()].find(([,X])=>X===N)?.[0]??""));R&&L&&G&&!d.has(b+1)&&(i.push({...n(b+1),text:""}),d.add(b+1));continue}const E=r(w.line),T=ql(g),O=g.type!==y.type||g.default!==y.default?w.blockHeader===void 0?Ul(g):`${g.name} :: ${g.type} is ${g.default}`:t.slice(w.line,b+1).join(`
|
|
91
91
|
`).trim();i.push({start:n(w.line).start,end:n(b).end,text:(T?`${E}${T}
|
|
92
92
|
`:"")+`${E}${O}
|
|
93
93
|
`})}for(const[h,y]of c){if(y.blockHeader===void 0||u.has(h))continue;![...c.values()].some(w=>w.blockHeader===y.blockHeader&&!d.has(w.line))&&!d.has(y.blockHeader)&&(i.push({...n(y.blockHeader),text:""}),d.add(y.blockHeader))}const f=[...u.values()].filter(h=>!l.has(h.name));if(f.length>0){const h=Math.max(-1,...[...c.values()].map(v=>v.line)),y=(()=>{let v=-1;for(let _=0;_<t.length;_++){const b=t[_].trim();(b.startsWith("import ")||v>=0&&/^}\s*from\s/.test(b))&&(v=_)}return v})(),g=h>=0?h:y,w=f.map(v=>{const _=ql(v);return(_?`${_}
|
|
@@ -111,10 +111,10 @@ source: ${y.name} is ${y.base} extend {
|
|
|
111
111
|
}
|
|
112
112
|
`;let w=d;if(w<0)for(let v=0;v<n.length;v++){const _=n[v].trim();(/^(import\s|given:|}\s*from\s)/.test(_)||/^[A-Z_]+\s*::/.test(_))&&(w=v)}const x=w>=0?r(w).end:t.length,p=x===t.length&&!t.endsWith(`
|
|
113
113
|
`)?`
|
|
114
|
-
`:"";a.push({start:x,end:x,text:p+g}),d=w}}function dy(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:o,next:i,edits:a,parsed:l}=e,u=new Map(o.tiles.map(c=>[ot(c),c]));for(const c of i.tiles){const d=u.get(ot(c));if(d===void 0||Ce(c)||Ce(d))continue;const f=Bi(d,c),h=Ee(Xl(lo(d)))!==Ee(Xl(lo(c)));if(!h&&!f)continue;if(c.declaration.kind==="inherited"){if(!h)continue;return{ok:!1,reason:`\`${dt(c)}\` is declared on its source, not in this report, so its presentation cannot be changed here.`}}if(c.declaration.kind==="query"){if(!h)continue;return{ok:!1,reason:`\`${c.name}\` names a query, whose presentation is the query's own, so it cannot be changed here.`}}const y=Qv(l,c.source,c.name);if(y<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:g}=sr(l,t,y),w=s(y),x=yf(c,!1),p=new Map(x.map(A=>[
|
|
115
|
-
`}),E=!0;continue}const R=
|
|
116
|
-
`})}const T=x.filter(A=>!v.has(
|
|
117
|
-
`).join("")})}if(Ee(d.filters)===Ee(c.filters))continue;const M=_f(e,c);if(!M)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(M.body.kind==="reference"){const A=vy(e,c,M);if(A)return A;continue}if(M.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${M.body.why}, so there is no single first stage to write its filter into.`};const O=kf(c.filters,M.body.stage);if(O)return Sf(c.name,O.given);const C=$f(e,c,M.body.stage);if(C)return C}}const Zl=e=>e.chart==="default"?void 0:e.chart,lo=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...o}=r;return o};function uy(e,t){const n=new Map(e.tiles.map(r=>[ot(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(ot(r));return ce(r)&&r.chart===void 0&&s&&ce(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function
|
|
114
|
+
`:"";a.push({start:x,end:x,text:p+g}),d=w}}function dy(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:o,next:i,edits:a,parsed:l}=e,u=new Map(o.tiles.map(c=>[ot(c),c]));for(const c of i.tiles){const d=u.get(ot(c));if(d===void 0||Ce(c)||Ce(d))continue;const f=Bi(d,c),h=Ee(Xl(lo(d)))!==Ee(Xl(lo(c)));if(!h&&!f)continue;if(c.declaration.kind==="inherited"){if(!h)continue;return{ok:!1,reason:`\`${dt(c)}\` is declared on its source, not in this report, so its presentation cannot be changed here.`}}if(c.declaration.kind==="query"){if(!h)continue;return{ok:!1,reason:`\`${c.name}\` names a query, whose presentation is the query's own, so it cannot be changed here.`}}const y=Qv(l,c.source,c.name);if(y<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:g}=sr(l,t,y),w=s(y),x=yf(c,!1),p=new Map(x.map(A=>[Ps(A)??A,A])),v=new Set,_=vf(c.chart),b=Zl(d)!==Zl(c);if(b){const A=g.filter(G=>k.mentionsChartTag(G.text)),R=g.filter(G=>k.parseChartLine(G.text)),L=d.chart==="custom"?g.filter(G=>k.parseChartLine(G.text)||k.mentionsChartTag(G.text)):A.length>0?A:R.length>1?R:[];if(L.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${L.map(G=>G.text).join(" and ")}), so its chart cannot be changed here.`}}let E=!1;for(const A of g){if(b&&k.parseChartLine(A.text)){_===void 0?a.push({...r(A.line),text:""}):A.text!==k.chartLineText(_,c.chartCarried)&&a.push({...r(A.line),text:`${w}${k.chartLineText(_,c.chartCarried)}
|
|
115
|
+
`}),E=!0;continue}const R=Ps(A.text);if(R===void 0||!Xv.has(R))continue;if(Jv.has(R)){f&&a.push({...r(A.line),text:""});continue}const L=p.get(R);if(L===void 0){a.push({...r(A.line),text:""});continue}v.add(R),L!==A.text&&a.push({...r(A.line),text:`${w}${L}
|
|
116
|
+
`})}const T=x.filter(A=>!v.has(Ps(A)??A));if(b&&_!==void 0&&!E&&T.push(k.chartLineText(_,c.chartCarried)),T.length>0){const A=n[y];a.push({start:A,end:A,text:T.map(R=>`${w}${R}
|
|
117
|
+
`).join("")})}if(Ee(d.filters)===Ee(c.filters))continue;const M=_f(e,c);if(!M)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(M.body.kind==="reference"){const A=vy(e,c,M);if(A)return A;continue}if(M.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${M.body.why}, so there is no single first stage to write its filter into.`};const O=kf(c.filters,M.body.stage);if(O)return Sf(c.name,O.given);const C=$f(e,c,M.body.stage);if(C)return C}}const Zl=e=>e.chart==="default"?void 0:e.chart,lo=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...o}=r;return o};function uy(e,t){const n=new Map(e.tiles.map(r=>[ot(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(ot(r));return ce(r)&&r.chart===void 0&&s&&ce(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function js(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 fy(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&&!me.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=js(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 No=e=>`##|(markdown) ${e.name}
|
|
118
118
|
${e.markdown===""?"":`${e.markdown}
|
|
119
119
|
`}|##
|
|
120
120
|
`;function hy(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:o,parsed:i,edits:a}=e,l=new Map(s.tiles.filter(Ce).map(h=>[h.name,h])),u=o.tiles.filter(Ce),c=h=>i.textBlocks.find(y=>y.name===h),d=new Set(u.map(h=>h.name));for(const h of l.keys()){const y=d.has(h)?void 0:c(h);if(!y)continue;const g=Lt(i,y.span.end-1);a.push({...y.span,text:""});const w=r(g+1),x=y.line===0||n[y.line-1].trim()==="";w.end>w.start&&n[g+1].trim()===""&&x?a.push({...w,text:""}):y.line>0&&x&&t.slice(y.span.end).trim()===""&&a.push({...r(y.line-1),text:""})}const f=[];for(const h of u){const y=l.get(h.name),g=c(h.name);if(y===void 0){if(g)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};f.push(No(h))}else y.markdown!==h.markdown&&(g?a.push({...g.span,text:No(h)}):f.push(No(h)))}if(f.length>0){const h=i.textBlocks.filter(p=>p.name===void 0||d.has(p.name)),y=h[h.length-1],g=i.sources.find(p=>p.name.endsWith("_tiles"));if(y){const p=y.span.end,v=t.slice(p);a.push({start:p,end:p,text:`
|
|
@@ -139,6 +139,6 @@ ${n.indent}${Rs(f)}`).join("");s.push({start:u,end:u,text:d})}function vy(e,t,n)
|
|
|
139
139
|
`)&&!/(?<!\r)\n/.test(e)))return ec(e,t,n);const s=await ec(e.replace(/\r\n/g,`
|
|
140
140
|
`),t,n);return io(s)?s:{...s,source:s.source.replace(/\n/g,`\r
|
|
141
141
|
`)}}async function ec(e,t,n){const r=await oo(e);if(so(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,o=uy(s,t),i=Zv(s,o,n.visibleSources);if("reason"in i)return i;const a=py(s,o);if(a)return{ok:!1,reason:a};const l=await uf(e);if(af(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const u=e.split(`
|
|
142
|
-
`),c=Kv(e),d=p=>({start:c[p],end:p+1<c.length?c[p+1]:e.length}),f=p=>/^\s*/.exec(u[p])?.[0]??"",h=[],y={...i,sourceText:e,parsed:l.parsed,lines:u,starts:c,wholeLine:d,indentOf:f,current:s,next:o,edits:h};for(const p of[ty,sy,iy,oy,ay,ly,cy,dy,hy]){const v=p(y);if(v)return v}const g=p=>{const{drills:v,localGivens:_,description:b,...E}=p,T=p.tiles.map(M=>{if(Ce(M))return M;if(M.filters?.length)return lo(M);const{filters:O,...C}=M;return lo(C)});return{...E,...b===void 0?{}:{description:mf(b)},tiles:T,...v?.length?{drills:[...v].sort((M,O)=>ao(M).localeCompare(ao(O)))}:{},..._?.length?{localGivens:_}:{}}};if(h.length===0)return Ee(g(s))!==Ee(g(o))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const w=Vv(e,h);if((await Hl(e)).length===0){const p=await Hl(w);if(p.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${p[0]}). Your changes are still here.`}}const x=await oo(w);return so(x)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${x.reason}`}:Ee(g(x.document))!==Ee(g(o))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:w}}function Ef({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=be.usePublisherTheme(),o=s.ui,i=S.useId(),[a,l]=S.useState(!1),u=S.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:c,patch:d,close:f,discard:h}=_c(u,a,_=>n(_.text),()=>l(!1)),y=a&&c!==void 0&&c.text!==e,g=c!==void 0&&c.text!==e?Ps(c.text):void 0;qu(y,()=>g!==void 0?!1:(f(),!0));const w=S.useRef(!1);S.useEffect(()=>{a||(w.current=!1)},[a]);const x=S.useCallback(_=>{!_||w.current||(w.current=!0,_.setSelectionRange(_.value.length,_.value.length))},[]);if(!a||c===void 0){const _=e.trim()?Ps(e):void 0;return m.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():l(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),l(!0)))},sx:[{minHeight:24},Gu(s,"prose")],children:[e.trim()?m.jsx(k.Prose,{variant:r,children:e}):m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),_&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:_})]})}const p=c.text!==e?Ps(c.text):void 0,v=()=>{p===void 0&&f()};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:c.text,placeholder:t,error:p!==void 0,inputRef:x,inputProps:{"aria-label":"Markdown","aria-describedby":i,...p!==void 0?{"aria-invalid":!0}:{}},onChange:_=>d(b=>{b.text=_.target.value}),onKeyDown:_=>{_.key==="Escape"?(_.preventDefault(),h(),l(!1)):_.key==="Enter"&&(_.metaKey||_.ctrlKey)&&(_.preventDefault(),v())},onBlur:()=>f(),sx:{p:0,...o.type.prose,color:"inherit",maxWidth:k.PROSE_MAX_WIDTH,"& textarea":{p:0}}}),p!==void 0&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:p}),m.jsxs($.Typography,{id:i,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",cn,"↩ done · Esc cancels"]})]})}const yy="Write markdown: # heading, **bold**, - list";function xy({tile:e,sized:t=!1,onChange:n}){const r=m.jsx(k.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Ef,{markdown:e.markdown,placeholder:yy,onCommit:n})});return t?m.jsx($.Box,{"data-testid":"text-tile-scroller",sx:{minHeight:0,overflow:"auto",p:"4px",m:"-4px"},children:r}):r}var by=Object.defineProperty,wy=Object.defineProperties,_y=Object.getOwnPropertyDescriptors,tc=Object.getOwnPropertySymbols,ky=Object.prototype.hasOwnProperty,Sy=Object.prototype.propertyIsEnumerable,nc=(e,t,n)=>t in e?by(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_n=(e,t)=>{for(var n in t||(t={}))ky.call(t,n)&&nc(e,n,t[n]);if(tc)for(var n of tc(t))Sy.call(t,n)&&nc(e,n,t[n]);return e},kn=(e,t)=>wy(e,_y(t));function $y(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function bs(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function zo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Ty(e,t,n){var r,s;const{source:o,target:i,canceled:a}=t.operation;if(!o||!i||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(v,_)=>v===_||v!==null&&typeof v=="object"&&"id"in v&&v.id===_;if(Array.isArray(e)){const v=e.findIndex(b=>l(b,o.id)),_=e.findIndex(b=>l(b,i.id));if(v===-1||_===-1){if(zo(o)){const b=o.initialIndex,E=o.index;return b===E||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,E)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==v)return n(e,v,b)}return n(e,v,_)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[v,_]of u)if(c===-1&&(c=_.findIndex(b=>l(b,o.id)),c!==-1&&(d=v)),f===-1&&(f=_.findIndex(b=>l(b,i.id)),f!==-1&&(h=v)),c!==-1&&f!==-1)break;if(c===-1&&zo(o)){const v=o.initialGroup==null?void 0:bs(e,o.initialGroup),_=o.initialIndex,b=o.group==null?void 0:bs(e,o.group),E=o.index;if(v==null||b==null||v===b&&_===E)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return kn(_n({},e),{[v]:n(e[v],_,E)});const T=e[v][_];return kn(_n({},e),{[v]:[...e[v].slice(0,_),...e[v].slice(_+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:y}=o.manager,g=(s=(r=y.shape)==null?void 0:r.current.center)!=null?s:y.position.current;if(h==null){const v=bs(e,i.id);if(v!=null){const _=i.shape&&g.y>i.shape.center.y?e[v].length:0;h=v,f=_}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&zo(o)){const v=o.group==null?void 0:bs(e,o.group),_=o.group!=null&&v!==d,b=o.index!==c;if(_||b){const E=o.group==null?d:v;if(E!=null){if(d===E)return kn(_n({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return kn(_n({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[E]:[...e[E].slice(0,o.index),T,...e[E].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return kn(_n({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(g.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return kn(_n({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[h]:[...e[h].slice(0,f+x),p,...e[h].slice(f+x)]})}function Ey(e,t){return Ty(e,t,$y)}function Cf(e){const t=e.getBoundingClientRect(),n=new Map;for(const r of e.querySelectorAll("[data-tile-key]")){const s=r.dataset.tileKey;if(!s)continue;const o=r.getBoundingClientRect();n.set(s,{top:o.top-t.top,left:o.left-t.left,width:o.width,height:o.height})}return n}function Cy({tiles:e,commit:t,onLanded:n,placement:r}){const[s,o]=S.useState(void 0),i=S.useRef(void 0),[a,l]=S.useState(!1),u=S.useRef(void 0);return{dragging:a,preview:s,onDragStart:y=>{l(!0),i.current=e;const g=r?.gridBox.current,w=y?.operation.source?.id;if(!r||!g)return;const x=e.findIndex(M=>fe(M)===w),p=Cf(g),v=p.get(String(w));if(x<0||!v)return;const _=pc(e,e.map(M=>p.get(fe(M))),r.columns,Ls(g.getBoundingClientRect().width,r.columns)),b=g.getBoundingClientRect(),E=y?.operation.position?.current,T=E?{x:E.x-(b.left+v.left),y:E.y-(b.top+v.top)}:{x:0,y:0};u.current={base:_,index:x,from:v,grab:T},i.current=_,o(_)},onDragMove:y=>{const g=u.current,w=r?.gridBox.current;if(!g||!r||!w)return;const x=w.getBoundingClientRect(),p=y.operation.position.current,v=y.to??(y.by?{x:p.x+y.by.x,y:p.y+y.by.y}:p),_=g.base[g.index],b=hc(v.x-g.grab.x-x.left,v.y-g.grab.y-x.top,_.colspan??1,r.columns,Ls(w.getBoundingClientRect().width,r.columns)),E=i.current?.[g.index];if(E?.row===b.row&&E.col===b.col)return;const T=Gf(g.base,g.index,b,r.columns);i.current=T,o(T)},onDragOver:y=>{if(u.current){y.preventDefault();return}const{source:g,target:w}=y.operation;if(!g||!w)return;const x=i.current??e;let p;if(w.type===sf){const{after:v}=w.data,_=x.findIndex(T=>fe(T)===g.id);if(_<0||v===g.id)return;const E=x.filter((T,M)=>M!==_).findIndex(T=>fe(T)===v)+1;p=Pm(x,_,E)}else{const v=x.map(fe),_=Ey(v,y);if(_.every((E,T)=>E===v[T]))return;const b=new Map(x.map(E=>[fe(E),E]));p=jm(_.map(E=>b.get(E)),e.map(E=>E.break??!1))}i.current=p,o(p)},onDragEnd:y=>{l(!1);const g=u.current,w=g!==void 0;u.current=void 0;const x=i.current,p=g!==void 0&&x!==void 0&&x[g.index]?.row===g.base[g.index]?.row&&x[g.index]?.col===g.base[g.index]?.col,v=w&&x?In(x):x;if(i.current=void 0,o(void 0),y.canceled||!v||p)return;t(v);const _=v.findIndex(b=>fe(b)===y.operation.source?.id);_>=0&&n(_)}}}const Oy={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Of=(e,t)=>t===0?e:Of(t,e%t);function My(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Of(e,t),s=Oy[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}const rc=k.TILE_ROW_PX+k.GRID_GAP_PX,Mf=e=>e.n&&e.w||e.s&&e.e?"nwse-resize":e.n&&e.e||e.s&&e.w?"nesw-resize":e.n||e.s?"ns-resize":"ew-resize",ws=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e??""},Iy=e=>({...e.row!==void 0?{row:e.row}:{},...e.col!==void 0?{col:e.col}:{},colspan:e.colspan??1,rowspan:e.rowspan}),sc=(e,t)=>e.row===t.row&&e.col===t.col&&e.colspan===t.colspan&&e.rowspan===t.rowspan;function If(e,t,n,r){const s={...e};return(n.e||n.w)&&(s.colspan=t.colspan,r&&t.col!==void 0&&(s.col=t.col)),(n.n||n.s)&&(t.rowspan===void 0?delete s.rowspan:s.rowspan=t.rowspan,r&&t.row!==void 0&&(s.row=t.row)),s}function Dy({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[o,i]=S.useState(void 0),a=S.useRef(void 0),l=S.useRef(void 0),u=g=>{a.current=g,i(g)};S.useEffect(()=>()=>ws(void 0),[]);const c=o!==void 0;S.useEffect(()=>{if(!c)return;const g=w=>{w.key!=="Escape"||!a.current||(w.preventDefault(),w.stopPropagation(),a.current=void 0,i(void 0),l.current=void 0,ws(void 0))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[c]);const d=g=>{const w=new Set(g.base.filter(v=>v.rowspan===void 0).map(fe)),x=g.base[g.index];let p=l.current;for(const v of n.current?.querySelectorAll("[data-tile-key]")??[]){const _=v.dataset.tileKey;if(!_||!w.has(_)||x&&_===fe(x))continue;const b=v.getBoundingClientRect();Math.abs(b.top-g.top)>1||(p=Math.max(p??0,b.height))}return p};return{drag:o,start:(g,w,x)=>{const p=n.current,v=p?.getBoundingClientRect(),_=g.currentTarget.parentElement?.getBoundingClientRect();if(!p||!v||!_||!e[w])return;g.stopPropagation(),g.preventDefault(),g.currentTarget.setPointerCapture(g.pointerId),ws(Mf(x)),r(w);const b=(x.n||x.w)&&(!k.isPlaced(e)||e[w].row===void 0||e[w].col===void 0),E=b?(()=>{const A=Cf(p);return pc(e,e.map(R=>A.get(fe(R))),t,Ls(v.width,t))})():[...e],T=k.isPlaced(E),M=E[w],O=Iy(M);!T&&O.rowspan===void 0?l.current=_.height:l.current=void 0;const C=T?{...O,rowspan:Fr(M)}:O;u({index:w,edges:x,base:E,placedHere:!!b,placed:T,from:O,begun:C,shape:C,guideTop:_.top-v.top,min:As(M,g.currentTarget.parentElement),top:_.top,left:_.left})},move:g=>{const w=a.current,x=n.current?.getBoundingClientRect();if(!w||!x)return;const p=w.base[w.index];if(!p)return;const _=Ls(x.width,t)+k.GRID_GAP_PX,b=g.clientX-x.left,E=g.clientY-x.top,T=g.currentTarget.parentElement?.getBoundingClientRect(),M=T?.top??w.top,O=T?.left??w.left,{min:C}=w,A=w.shape;let{row:R,col:L,colspan:G,rowspan:N}=A;if(w.placed&&L!==void 0&&R!==void 0){const P=w.from,z=P.col??L,D=z+P.colspan-1,I=P.row??R,B=P.rowspan??Fr(p),q=I+B-1;if(w.edges.e){const H=Math.round((b+k.GRID_GAP_PX)/_);G=Math.min(Math.max(H,z),t)-z+1,L=z}if(w.edges.w){const H=Math.round(b/_)+1;L=Math.min(Math.max(H,1),D),G=D-L+1}if(w.edges.s){const H=w.edges.n?x.top+(I-1)*rc:M;N=k.rowsForHeight(g.clientY-H,C),R=I}if(w.edges.n){const H=Math.round(E/rc)+1,K=Math.min(C,B);R=Math.max(1,Math.min(Math.max(H,q-k.MAX_TILE_ROWS+1),q-K+1)),N=q-R+1}}else{if(w.edges.e){const P=Math.round((g.clientX-O+k.GRID_GAP_PX)/_);G=Math.min(Math.max(P,1),t)}if(w.edges.s){const P=g.clientY-M,z=k.rowsForHeight(P,C),D=d(w);N=D!==void 0&&Math.abs(P-D)<Math.abs(P-k.tileHeightPx(z))?void 0:z}}const X={...R!==void 0?{row:R}:{},...L!==void 0?{col:L}:{},colspan:G,rowspan:N};sc(X,A)||u({...w,shape:X})},end:g=>{g.currentTarget.hasPointerCapture(g.pointerId)&&g.currentTarget.releasePointerCapture(g.pointerId),ws(void 0);const w=a.current;l.current=void 0,w&&(u(void 0),!(g.type==="pointercancel"||sc(w.shape,w.begun))&&s({index:w.index,edges:w.edges,shape:w.shape,placed:w.placed,...w.placedHere?{placedAll:w.base}:{}}))}}}function jy(e,t){const n=[];return(e.edges.e||e.edges.w)&&n.push(My(e.shape.colspan,t)),(e.edges.n||e.edges.s)&&n.push(e.shape.rowspan===void 0?"Auto height":`${e.shape.rowspan} rows tall`),n.join(" · ")}function Py({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:o=!1,onInsertAfter:i,onSelect:a,onOpenMenu:l,onRemove:u,removeBlocked:c,width:d,edges:f,heightEdge:h,fixed:y=!1,children:g}){const{theme:w}=be.usePublisherTheme(),x=w.ui;return m.jsx(gv,{id:fe(e),index:t,disabled:y,children:({ref:p,handleRef:v})=>m.jsxs($.Box,{ref:p,onClick:a,onPointerDown:_=>{_.button===0&&a()},role:"group",className:k.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",...(e.rowspan!==void 0||e.row!==void 0)&&{gridTemplateRows:"minmax(0, 1fr)",minHeight:0},minWidth:0,cursor:"grab",...Df(w,{selected:n,flash:r,bare:o}),...!o&&{[`& .${k.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:w.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${w.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...k.removeBadgeRevealSx,...n&&{[`& .${k.REMOVE_BADGE_CLASS}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[g,m.jsx($.Box,{ref:v,"aria-label":`Move ${lr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(k.RemoveBadge,{label:`Remove ${lr(e)}`,onRemove:u,...c?{disabledReason:c}:{},inset:o?k.BARE_RING_OFFSET_PX:0}),!Ce(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${lr(e)}`,onClick:_=>{_.stopPropagation(),l(_.currentTarget)},sx:{position:"absolute",top:o?0:`${oc}px`,right:o?0:`${oc}px`,borderRadius:x.radius.control,width:28,height:28,zIndex:3,color:"text.secondary",bgcolor:"action.hover",opacity:n||s?1:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(By,{})}),f&&m.jsx(Wy,{edges:f,width:d,heightEdge:h,label:lr(e)}),i&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${lr(e)}`,onClick:_=>{_.stopPropagation(),i()},sx:{position:"absolute",bottom:`-${k.GRID_GAP_PX/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:w.tileTitle,bgcolor:w.tile,border:w.cardBorder,opacity:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:w.tile}},children:m.jsx(k.AddIcon,{sx:{fontSize:14}})})]})})}const oc=14,Go=7,Df=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:s=k.BARE_RING_OFFSET_PX})=>{const o=e.ui,i=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,l=`outline-color ${k.MOTION_FAST}, border-color ${k.MOTION_FAST}, opacity ${k.MOTION_FAST}, box-shadow ${k.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 ${i}`,...a&&{boxShadow:a},pointerEvents:"none",transition:l,...k.reducedMotionSx}}:{borderRadius:o.radius.tile,"& > .MuiPaper-root":{transition:l,...k.reducedMotionSx,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:l,...k.reducedMotionSx,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:k.hoverEdgeColor(e.cardBorder,e.tileTitle)}}}}};function Ry({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=be.usePublisherTheme();return m.jsxs(k.TileCard,{chrome:r,children:[m.jsx(k.TileHeading,{title:t?.title??co(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),m.jsx($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:dt(e).replace("->","→")})]})}function Ay({after:e}){const{theme:t}=be.usePublisherTheme();return m.jsx(mv,{id:Ku(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 ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,...k.reducedMotionSx}})})}function Ly({columns:e,faint:t=!1}){const{theme:n}=be.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:`${k.GRID_GAP_PX}px`},children:Array.from({length:e},(r,s)=>m.jsx($.Box,{sx:{bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},s))})}function ic({top:e,faint:t=!1}){const{theme:n}=be.usePublisherTheme(),r=k.TILE_ROW_PX+k.GRID_GAP_PX,s=-Math.ceil(e/r);return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,overflow:"hidden",pointerEvents:"none",zIndex:0},children:Array.from({length:-s+4*k.MAX_TILE_ROWS},(o,i)=>m.jsx($.Box,{sx:{position:"absolute",top:e+(s+i)*r,left:0,right:0,height:k.TILE_ROW_PX,bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},i))})}function By(){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"})]})}const Fy=[{edges:{n:!0},sx:{top:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{s:!0},sx:{bottom:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{e:!0},sx:{right:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{w:!0},sx:{left:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{n:!0,w:!0},sx:{top:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{n:!0,e:!0},sx:{top:"-8px",right:"-8px",width:"32px",height:"32px"}},{edges:{s:!0,w:!0},sx:{bottom:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{s:!0,e:!0},sx:{bottom:"-8px",right:"-8px",width:"20px",height:"20px"}}];function Wy({edges:e,width:t,heightEdge:n,label:r}){const{theme:s}=be.usePublisherTheme(),o=s.ui,[i,a]=S.useState(void 0),l=i??n?.min??k.MIN_TILE_ROWS,u=f=>n&&a(n.minFor?.(f)??n.min),c=f=>(!(f.n||f.w)||e.all)&&(!f.e||e.right),d={"&:focus-visible":{outline:`2px solid ${s.accent}`,outlineOffset:-4,borderRadius:"3px"}};return m.jsxs(m.Fragment,{children:[Fy.filter(f=>c(f.edges)).map(f=>{const h=Object.keys(f.edges).join(""),y=h==="e",w=y&&t?{role:"separator",tabIndex:0,"aria-orientation":"vertical","aria-label":`Width of ${r}`,"aria-valuenow":t.span,"aria-valuemin":1,"aria-valuemax":t.max??t.columns,"aria-valuetext":`${t.span} of ${t.columns} columns`,onKeyDown:x=>{if(x.altKey)return;const p=t.max??t.columns,v=x.key==="ArrowRight"?t.span+1:x.key==="ArrowLeft"?t.span-1:x.key==="Home"?1:x.key==="End"?p:void 0;v!==void 0&&(x.preventDefault(),x.stopPropagation(),t.onStep(Math.min(Math.max(v,1),p)))}}:h==="s"&&n?{role:"separator",tabIndex:0,"aria-orientation":"horizontal","aria-label":`Height of ${r}`,"aria-valuemin":l,onFocus:x=>u(x.currentTarget.parentElement),onPointerEnter:x=>u(x.currentTarget.parentElement),"aria-valuemax":k.MAX_TILE_ROWS,...n.rows===void 0?{}:{"aria-valuenow":n.rows},"aria-valuetext":Ny(n.rows),onKeyDown:x=>{if(x.altKey)return;const p=n.rows,v=p??l,_=x.key==="ArrowDown"?v+1:x.key==="ArrowUp"?v-1:x.key==="Home"?l:x.key==="End"?k.MAX_TILE_ROWS:x.key==="Delete"||x.key==="Backspace"?null:void 0;if(_===void 0)return;if(x.preventDefault(),x.stopPropagation(),_===null){p!==void 0&&n.onStep(void 0);return}const b=Math.min(Math.max(_,l),k.MAX_TILE_ROWS);b!==p&&n.onStep(b)}}:{"aria-hidden":!0};return m.jsx($.Box,{className:`builder-affordance${y?` ${k.reportClasses.widthHandle}`:""}`,[of]:"",...w,"data-edge":h,onPointerDown:x=>{x.button===0&&e.start(x,f.edges)},onPointerMove:e.move,onPointerUp:e.end,onPointerCancel:e.end,onClick:x=>x.stopPropagation(),onDoubleClick:x=>{!f.edges.s||f.edges.e||f.edges.w||(x.stopPropagation(),n&&n.rows!==void 0&&n.onStep(void 0))},sx:{position:"absolute",...f.sx,cursor:Mf(f.edges),touchAction:"none",zIndex:Object.keys(f.edges).length>1?2:1,...d}},h)}),e.label&&m.jsx($.Box,{"aria-hidden":!0,sx:f=>({position:"absolute",right:12,bottom:12,px:1,py:.5,borderRadius:o.radius.control,bgcolor:f.palette.text.primary,color:f.palette.background.paper,...o.type.label,whiteSpace:"nowrap",pointerEvents:"none",zIndex:4}),children:e.label})]})}const Ny=e=>e===void 0?"Auto height":`${e} rows tall`;function zy({editor:e,reorder:t,edging:n,place:r=v=>v,arrange:s=!0,gridBox:o,defaultSpan:i=1,rules:a,canAdd:l,selected:u,flash:c,menuIndex:d,onSelect:f,onOpenMenu:h,onRemove:y,removeBlocked:g,openAdd:w,editTile:x,renderTile:p}){const{dragging:v,preview:_,onDragStart:b,onDragMove:E,onDragOver:T,onDragEnd:M}=t,{columns:O}=a,C=n.drag,A=D=>D.colspan===void 0?{...D,colspan:i}:D,R=(C!==void 0?(()=>{const D=C.placedHere?C.base:e.document.tiles;if(!D[C.index])return D;const B=D.map((q,H)=>H===C.index?If(q,C.shape,C.edges,C.placed):q);return C.placed?Rt(B,O,C.index):B})():_??e.document.tiles).map(A),L=k.isPlaced(R),G=v||C!==void 0,N=!G&&L&&s&&u!==void 0,X=e.document.tiles.length===0,P=G&&!L?Rm(R,O):R.map(Uu),z=D=>Gy(D,co(D),x);return m.jsxs(m.Fragment,{children:[m.jsxs(vm,{sensors:fv,onDragStart:b,onDragMove:E,onDragOver:T,onDragEnd:M,children:[m.jsx(vv,{active:v}),m.jsxs($.Box,{ref:o,sx:{position:"relative"},children:[a.widths&&(G||N)&&m.jsx(Ly,{columns:O,faint:!G}),C!==void 0&&!C.placed?(C.edges.s||C.edges.n)&&m.jsx(ic,{top:C.guideTop}):L&&(G||N)&&m.jsx(ic,{top:0,faint:!G}),m.jsx(k.DashboardGrid,{tiles:P,columns:O,rowGapPx:k.GRID_GAP_PX,defaultRowspan:D=>D.kind==="tile"?Fr(D.tile):k.PLACED_DEFAULT_ROWSPAN.query,keyOf:D=>D.kind==="gap"?Ku(D.after):fe(D.tile),renderTile:D=>{if(D.kind==="gap")return m.jsx(Ay,{after:D.after});const{tile:I,index:B}=D;return m.jsx(Py,{tile:I,index:B,selected:B===u,flash:fe(I)===c,menuOpen:d===B,bare:Ce(I),...a.insertBetween&&l&&B<e.document.tiles.length-1?{onInsertAfter:()=>w(B+1)}:{},fixed:!s,...a.widths?{edges:{all:s,right:s,start:(q,H)=>n.start(q,B,H),move:n.move,end:n.end,...C?.index===B?{label:jy(C,O)}:{}}}:{},...a.widths&&s?{width:{span:I.colspan??1,columns:O,max:mc(I,O),onStep:q=>{q!==(I.colspan??1)&&e.update(H=>{if(!Number.isInteger(B)||B<0)return;const K=H.tiles[B];K&&(H.tiles[B]=k.withSpan(K,q,O,i)),H.tiles=r(H.tiles,B)})}}}:{},...a.widths?{heightEdge:{rows:I.rowspan,min:As(I),minFor:q=>As(I,q),onStep:q=>e.update(H=>{if(!Number.isInteger(B)||B<0)return;const K=H.tiles[B];K&&(q===void 0?delete K.rowspan:K.rowspan=q,H.tiles=r(H.tiles,B))})}}:{},onSelect:()=>f(B),onOpenMenu:q=>h(q,B),onRemove:()=>y(B),...g?{removeBlocked:g}:{},children:Ce(I)?m.jsx(xy,{tile:I,sized:I.rowspan!==void 0||L,onChange:q=>x(fe(I),H=>{Ce(H)&&(H.markdown=q)})}):p?p(I,z(I),"card"):m.jsx(Ry,{tile:I,heading:z(I)})})}})]})]}),a.insertBetween&&l&&!X&&m.jsx($.Button,{size:"small",startIcon:m.jsx(k.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>w(),sx:{alignSelf:"center"},children:"Add tile"})]})}const Gy=(e,t,n)=>{if(Hn(e))return;const r=fe(e),s=o=>i=>n(r,a=>{ce(a)&&(i===""?delete a[o]:a[o]=i)});return{title:m.jsx(ji,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(ji,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Hy={x:12,y:6};function qy({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:o}=be.usePublisherTheme();return m.jsx(k.ReportHeader,{actions:n,title:m.jsx(ji,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:i=>e.update(a=>{a.title=i})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(k.TextTileFrame,{sx:{position:"relative",overflow:"visible",...Df(o,{selected:r,bare:!0,ringOffset:Hy})},children:m.jsx(Ef,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:i=>e.update(a=>{i.trim()===""?delete a.description:a.description=i})})})})})}const Uy=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:o}=k.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:i,structural:a,durationMs:l})=>o({type:"report.saved",tiles:i,structural:a,where:r,durationMs:l}),refused:i=>o({type:"report.save_refused",reason:i}),undone:({size:i,structural:a,durationMs:l})=>o({type:"report.save_undone",tiles:i,structural:a,where:r,durationMs:l}),undoRefused:i=>o({type:"report.save_undo_refused",reason:i})}};function Ky(e,t){const n=S.useRef(t);n.current=t;const r=S.useRef(e);r.current=e;const s=S.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.(),pack:()=>n.current.arrange?.pack?.(),flow:()=>n.current.arrange?.flow()}),[]),{status:o,saveTarget:i,canUndo:a,canRedo:l,add:{filterUnavailable:u}}=t,c=t.save!==void 0,d=t.add.tile!==void 0,f=t.add.text!==void 0,h=t.add.filter!==void 0,y=t.exit!==void 0,g=t.done!==void 0,w=t.discard!==void 0,{draftKeptAt:x}=t,p=t.restored?.savedAt,v=t.restored?.stale??!1,_=t.restored?.pending??!1,b=t.restore!==void 0,E=t.dismissRestored!==void 0,T=t.arrange!==void 0,M=t.arrange?.pack!==void 0,O=S.useMemo(()=>({status:o,saveTarget:i,...c?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:l,redo:s.redo,add:{...d?{tile:s.addTile}:{},...f?{text:s.addText}:{},...h?{filter:s.addFilter}:{},...u!==void 0?{filterUnavailable:u}:{}},...y?{exit:s.exit}:{},...g?{done:s.done}:{},...x!==void 0?{draftKeptAt:x}:{},...w?{discard:s.discard}:{},...p!==void 0?{restored:{savedAt:p,stale:v,pending:_}}:{},...b?{restore:s.restore}:{},...E?{dismissRestored:s.dismissRestored}:{},...T?{arrange:{...M?{pack:s.pack}:{},flow:s.flow}}:{}}),[s,o,i,c,a,l,d,f,h,u,y,g,x,w,p,v,_,b,E,T,M]),C=e!==void 0;S.useEffect(()=>{r.current?.(O)},[O,C]),S.useEffect(()=>()=>r.current?.(void 0),[])}function Vy({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:s,onRemove:o,fixedFilters:i,onOpenModel:a,startingValues:l,onStartingValue:u,children:c}){const d=c!=null,f=S.useMemo(()=>{const h=new Map(e.map(y=>[y.name,y]));return{stateOf:y=>{const g=i?.get(y);if(g!==void 0){const{modelPath:p}=g;return{origin:h.get(y)?.origin??"model",fixed:g.reason,...p!==void 0&&a?{openModel:()=>a(p)}:{}}}const w=h.get(y);if(!w)return;const x=t(w.name,w.type);return{origin:w.origin,...x.length>0?{problem:`Cannot filter on ${x.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:d?e.filter(y=>y.boundTiles===0&&!i?.has(y.name)).map(y=>({name:y.name,label:y.label??y.name})):[],onEdit:y=>{const g=h.get(y);g&&n(g)},onRemove:o,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...u?{startingValueOf:y=>l?.[y],setStartingValue:u}:{}}},[e,t,d,n,o,r,s,i,a,l,u]);return m.jsx(k.StickyControls,{children:m.jsx(k.FilterEditingContext.Provider,{value:f,children:d?c: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(k.FilterSettingsButton,{name:h.name,label:h.label??h.name,unused:h.boundTiles===0},h.name)),m.jsx(k.AddFilterButton,{})]})})})}function Xy(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 o=n.get(fe(s));if(!o||o.index!==r||JSON.stringify(o.tile)!==JSON.stringify(s))return fe(s)}}function Yy({editor:e,gridBox:t}){const[n,r]=S.useState(void 0),s=typeof n=="object"?n.tile:void 0,o=n==="description",i=S.useCallback(w=>r(x=>typeof x=="object"&&x.tile===w?x:{tile:w}),[]),a=S.useCallback(()=>r(w=>w==="description"?w:void 0),[]),l=S.useCallback(()=>r("description"),[]),u=S.useCallback(()=>r(void 0),[]),c=n!==void 0;S.useEffect(()=>{if(!c)return;const w=x=>{const p=x.target;p instanceof Element&&p!==document.documentElement&&p.closest(Qy)===null&&u()};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[c,u]);const[d,f]=S.useState(void 0),h=S.useRef(!1),y=S.useRef(e.document);S.useEffect(()=>{const w=y.current;if(y.current=e.document,!h.current)return;h.current=!1;const x=Xy(w,e.document);if(x===void 0)return;f(x),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===x)?.scrollIntoView?.({block:"nearest",behavior:k.scrollBehavior()})},[e.document,t]),S.useEffect(()=>{if(d===void 0)return;const w=setTimeout(()=>f(void 0),1500);return()=>clearTimeout(w)},[d]);const g=S.useMemo(()=>({...e,undo:()=>{h.current=!0,e.undo()},redo:()=>{h.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:o,selectTile:i,deselectTile:a,selectDescription:l,clearSelection:u,flash:d,stepEditor:g}}const Qy=["[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 Zy({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[o,i]=S.useState("idle"),[a,l]=S.useState(!1),u=S.useRef(r);u.current=r;const c=S.useRef(s);c.current=s;const d=S.useRef(0),f=S.useCallback(async()=>{const g=++d.current;l(!1),i("saving");try{await u.current()}catch{d.current===g&&i("idle");return}d.current===g&&l(!0)},[]);S.useEffect(()=>{if(o==="waiting"){if(t)return;e?f():(i("idle"),c.current())}else if(o==="saving"){if(!a||t)return;i("idle"),e||c.current()}},[o,a,t,e,f]);const h=S.useCallback(()=>{o==="idle"&&(e?i("asking"):c.current())},[o,e]),y=S.useCallback(()=>{o==="idle"&&(e?n?t?i("waiting"):f():i("asking"):c.current())},[o,e,n,t,f]);return{requestExit:h,saveAndExit:y,finishing:o==="saving"||o==="waiting",dialog:{open:o==="asking",canSave:n,onKeepEditing:()=>{o==="asking"&&i("idle")},onDiscard:()=>{o==="asking"&&(i("idle"),c.current())},onSaveAndExit:()=>{o==="asking"&&(t?i("waiting"):f())}}}}function Jy({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:o=!1,keepsEdits:i=!1,report:a,unit:l,prepare:u,shortcuts:c}){const[d,f]=S.useState(!1),[h,y]=S.useState(!1),g=S.useRef(null),w=S.useRef(a);w.current=a;const x=e.dirty||o,p=(e.edited??e.dirty)||o,v=i?o:p;S.useEffect(()=>{s?.(e.document)},[e.document,s]),S.useLayoutEffect(()=>{n?.(p,v)},[p,v,n]);const _=S.useRef(n);_.current=n,S.useEffect(()=>()=>_.current?.(!1,!1),[]);const b=S.useRef(l);b.current=l,S.useEffect(()=>{y(!1)},[e.document]);const E=S.useCallback(()=>{f(!0),y(!1);const P=k.now(),{structural:z}=e,D=w.current.size;return e.save().then(I=>{I.ok===!0?w.current.saved({size:D,structural:z,durationMs:k.now()-P}):w.current.refused(I.reason)}).finally(()=>f(!1))},[e]),T=S.useRef(!1),M=S.useRef(!1);S.useEffect(()=>{!M.current||d||(M.current=!1,g.current?.focus())},[h,d]);const O=S.useCallback(()=>{if(!t||d||T.current||!e.canUndoSave)return;T.current=!0,f(!0);const P=k.now(),z=e.lastSave?.structural??!1,D=w.current.size;return e.undoSave().then(I=>{I.ok===!0?(M.current=!0,y(!0),w.current.undone({size:D,structural:z,durationMs:k.now()-P})):w.current.undoRefused(I.reason)}).finally(()=>{T.current=!1,f(!1)})},[t,d,e]),C=S.useCallback(()=>{if(!(!t||!e.dirty||d))return E()},[t,e,d,E]),A=S.useRef(C);A.current=C;const R=S.useCallback(()=>{const P=()=>A.current();return u?u(P):P()},[u]),L=Zy({dirty:p,saving:d,canSave:!!t,save:R,onExit:()=>r?.()});Yf(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:R}:{},paused:L.dialog.open||c.paused===!0}),[c,e,t,R,L.dialog.open]));const G=!!t&&!d&&e.canUndoSave,N=e.lastSave,X={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:x,saving:d,saveButton:g,...t?{onSave:R}:{},...r?{onExit:L.requestExit}:{}};return{saving:d,save:R,exitGuard:L,...r?{done:L.saveAndExit}:{},undoSave:O,canUndoSave:G,lastSave:N,toolbarProps:X}}const ex=1;function jf(e,t,n){const r=[];for(const s of e??[]){const o=s.name,i=s.kind;if(typeof o=="string"){if(i==="dimension"||i==="measure"){const a=s.type?.kind;r.push({name:t+o,kind:i,...a?{type:a}:{}})}else if(i==="join"&&n>0){const a=s.schema?.fields;r.push(...jf(a,`${t}${o}.`,n-1))}}}return r}function tx(e){const t=new Map;for(const n of Pf(e))t.set(n.name,jf(n.schema?.fields,"",ex));return t}function Pf(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}function Rf(e){const t=new Map;for(const n of Pf(e)){const r=new Map;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const o=s.schema?.fields;if(!o||o.length===0)continue;const{groupBys:i,totals:a}=k.columnCounts(o);r.set(s.name,{shape:{groupBys:i,totals:a},...a===o.length?{aggregateOnly:!0}:{}})}t.set(n.name,r)}return t}function Af(e,t){const n=k.docOf(e.annotations),r=k.chartOf(e.annotations);return{name:e.name,...n?{description:n}:{},...r?{chart:r}:{},...t}}const Lf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function nx(e){const t=Rf(e),n=new Map;for(const r of e.sources??[]){if(!r.name)continue;const s=t.get(r.name);n.set(r.name,new Map(Lf(r).map(o=>[o.name,Af(o,s?.get(o.name))])))}return n}function ac(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const lc=(e,t)=>e!==void 0&&t.has(e),cc=e=>e.path||e.modelPath||"";function Bf(e,t=new Set){const n=[],r=new Set,s=new Map,o=new Map,i=new Map;for(const a of e){const l=cc(a);if(lc(l,t))continue;const u=k.exportedSources(a.modelInfo);o.set(a,u);for(const{name:c}of a.sources??[])c&&i.set(c,[...i.get(c)??[],l]);for(const c of u)s.set(c,[...s.get(c)??[],l])}for(const a of e){const l=cc(a);if(lc(l,t))continue;const u=tx(a),c=Rf(a);for(const d of a.sources??[]){const f=d.name;if(!f||!o.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(d.givens??[]).map(y=>y.name).filter(y=>typeof y=="string");n.push({name:f,modelPath:l,exporters:s.get(f)??[l],visibleIn:i.get(f)??[l],...k.docOf(d.annotations)?{description:k.docOf(d.annotations)}:{},views:Lf(d).map(y=>Af(y,c.get(f)?.get(y.name))),givens:h,fields:u.get(f)??[]})}}return{sources:n}}function rx({editor:e,opened:t,givens:n,catalog:r}){const[s,o]=S.useState(void 0),i=S.useMemo(()=>{const y=new Set((t.localGivens??[]).map(g=>g.name));return(n??[]).filter(g=>!y.has(g.name))},[t,n]),a=S.useMemo(()=>uh(e.document,i),[e.document,i]),l=S.useMemo(()=>new Map(e.document.sources.map(y=>[y.name,ac(r,y.base)])),[r,e.document.sources]),u=S.useCallback(y=>l.get(y.source)??ac(r,y.source),[l,r]),c=(y,g)=>{const w=[];for(const x of e.document.tiles){if(!ce(x))continue;const p=u(x);if(!p)continue;const v=new Map(p.map(_=>[_.name,_.type]));for(const _ of x.filters??[])_.given===y&&(!v.has(_.field)||!Ir(g,v.get(_.field)))&&w.push(`${_.field} on ${x.label??x.name} (${e.document.sources.find(b=>b.name===x.source)?.base??x.source})`)}return w},d=S.useMemo(()=>a.filter(y=>y.origin==="model"&&y.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:o,controlList:a,fieldsFor:u,unknownFieldsOf:c,available:d,applyFilter:(y,g,w)=>{o(void 0),e.update(x=>{w&&xh(x,w),yh(x,y,g)})},dropControl:y=>{o(void 0),e.update(g=>bh(g,y))}}}function sx(e){const{splice:t,onSave:n,structural:r,clearsHistory:s}=e,[o,i]=S.useState({stack:[e.document],index:0}),[a,l]=S.useState(e.source),[u,c]=S.useState(void 0),[d,f]=S.useState(e.document),[h,y]=S.useState(e.replaces),[g,w]=S.useState(!1),x=o.stack[o.index],p=S.useRef(o);p.current=o;const v=S.useRef(!1),[_,b]=S.useState(!1),E=I=>{v.current=I,b(I)},[T,M]=S.useState(void 0),O=S.useCallback(I=>{c(void 0),i(B=>{const q=structuredClone(B.stack[B.index]);if(I(q),JSON.stringify(q)===JSON.stringify(B.stack[B.index]))return B;const K=[...B.stack.slice(0,B.index+1),q].slice(-100);return{stack:K,index:K.length-1}})},[]),C=S.useCallback(()=>{c(void 0),i(I=>I.index>0?{...I,index:I.index-1}:I)},[]),A=S.useCallback(()=>{c(void 0),i(I=>I.index<I.stack.length-1?{...I,index:I.index+1}:I)},[]),R=S.useCallback(async(I,B)=>{try{return await t(I,B)}catch(q){return{ok:!1,reason:`Could not build the file: ${q instanceof Error?q.message:String(q)}`}}},[t]),L=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};const I={source:a,saved:d,history:p.current,replacing:h,unwritten:g},B=s?.(d,x)??!1,q=r?.(d,x)??!1;E(!0);try{const H=await R(a,x);if(io(H))return c(H.reason),{ok:!1,reason:H.reason};try{await n?.(H.source,{purpose:"save",document:x})}catch(te){const ye=`Could not save: ${te instanceof Error?te.message:String(te)}`;return c(ye),{ok:!1,reason:ye}}l(H.source),f(x),y(void 0),w(!1);const K=B?{stack:[x],index:0}:I.history;return i(te=>te===I.history?K:B?{stack:[te.stack[te.index]],index:0}:te),M(n?{before:I,after:K,lastSave:{before:h??a,after:H.source,structural:q,clearsHistory:B}}:void 0),c(void 0),{ok:!0}}finally{E(!1)}},[x,R,n,a,d,h,g,s,r]),G=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};if(!n||T===void 0||T.after!==p.current)return{ok:!1,reason:"There is no save to undo."};const{before:I}=T;E(!0);try{await n(I.replacing??I.source,{purpose:"undo",document:I.saved})}catch(B){const q=`Could not undo the save: ${B instanceof Error?B.message:String(B)}`;return c(q),{ok:!1,reason:q}}finally{E(!1)}return l(I.source),f(I.saved),y(I.replacing),w(I.unwritten||I.replacing!==void 0),i(B=>B===T.after?I.history:B),M(void 0),c(void 0),{ok:!0}},[n,T]),N=S.useMemo(()=>g||JSON.stringify(x)!==JSON.stringify(d),[x,d,g]),X=S.useMemo(()=>r?.(d,x)??!1,[x,d,r]),P=S.useMemo(()=>s?.(d,x)??!1,[x,d,s]),z=T!==void 0&&T.after===o,D=S.useCallback(async()=>{const I=await R(a,x);return io(I)?{ok:!1,reason:I.reason}:{ok:!0,source:I.source}},[x,R,a]);return{document:x,saved:d,source:a,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:N,edited:N,...u===void 0?{}:{error:u},update:O,undo:C,redo:A,save:L,preview:D,structural:X,clearsHistory:P,canUndoSave:z&&!_&&n!==void 0,...z?{lastSave:T.lastSave}:{},undoSave:G}}const ox=(e,t)=>{const n=new Set(e.tiles.map(Li)),r=new Set(t.tiles.map(Li));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function ix(e){const{visibleSources:t,...n}=e,r=S.useCallback((s,o)=>Tf(s,o,t?{visibleSources:t}:{}),[t]);return sx({...n,splice:r,structural:ox})}function ax({editorDirty:e}){const[t,n]=S.useState(!1),r=S.useRef(void 0),s=S.useRef(void 0),o=S.useMemo(()=>({setDirty:n,commitRef:r}),[]),i=S.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return S.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:o,prepare:i}}function lx({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:s,deselectTile:o}){const[i,a]=S.useState(void 0),[l,u]=S.useState(!1),[c,d]=S.useState(void 0),f=b=>{d(b),u(!0)},h=()=>u(!1),y=b=>{u(!1),e.update(E=>{th(E,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c}),t.widths&&(E.tiles=Va(E.tiles,c??E.tiles.length-1,t.columns))}),s(c??e.document.tiles.length)},g=()=>x(c),w=()=>x(void 0),x=b=>{u(!1),e.update(E=>{const T=new Set(E.tiles.filter(Ce).map(O=>O.name));let M=1;for(;T.has(`text_${M}`);)M++;E.tiles.splice(b??E.tiles.length,0,{kind:"text",name:`text_${M}`,markdown:"",...t.widths?{colspan:t.columns}:{}}),t.widths&&(E.tiles=Va(E.tiles,b??E.tiles.length-1,t.columns))}),s(b??e.document.tiles.length)};return{menu:i,setMenu:a,addingTile:l,openAdd:f,closeAdd:h,addTile:y,addText:g,appendText:w,editTile:(b,E)=>e.update(T=>{const M=T.tiles.find(O=>fe(O)===b);M&&E(M)}),removeTile:b=>{a(void 0),o(),e.update(E=>{E.tiles.splice(b,1)})},duplicate:b=>{a(void 0);const E=e.document.tiles[b],T=E&&ce(E)&&Ws(E)===void 0?b+1:void 0;e.update(M=>{nh(M,b)}),T!==void 0&&s(T)}}}const cx=k.createSvgIcon(m.jsx("path",{d:"M19 5v2h-4V5zM9 5v6H5V5zm10 8v6h-4v-6zM9 17v2H5v-2zM21 3h-8v6h8zM11 3H3v10h8zm10 8h-8v10h8zm-10 4H3v6h8z"}));function Ff({arrange:e}){const{theme:t}=be.usePublisherTheme(),[n,r]=S.useState(null),s=o=>()=>{r(null),o?.()};return m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:"Arrange tiles",children:m.jsx($.IconButton,{"aria-label":"Arrange tiles","aria-haspopup":"menu","aria-expanded":n!==null,onClick:o=>r(o.currentTarget),sx:Nr(t.ui),children:m.jsx(cx,{fontSize:"small"})})}),m.jsxs($.Menu,{anchorEl:n,open:n!==null,onClose:()=>r(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:{minWidth:260,borderRadius:t.ui.radius.menu,border:`1px solid ${k.edgeColor(t.cardBorder)}`,boxShadow:t.ui.shadow.menu}}},children:[m.jsx($.MenuItem,{disabled:!e.pack,onClick:s(e.pack),children:m.jsx($.ListItemText,{primary:"Pack tiles upward",secondary:e.pack?"Close every gap above a tile":"There are no gaps to close"})}),m.jsx($.MenuItem,{onClick:s(e.flow),children:m.jsx($.ListItemText,{primary:"Let tiles flow",secondary:"Clear each tile's place; keep its size"})})]})]})}function Ga({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:o,renderTile:i,renderViewPreview:a,controls:l,givens:u,catalog:c,toolbar:d,dashboards:f,onEvent:h,savesTo:y="package",saveLabel:g,replaces:w,modelPath:x,visibleSources:p,addFilterDisabledReason:v,fixedFilters:_,onOpenModel:b,takenGivenNames:E,onControlsChange:T,draftKey:M}){const O=ix({source:e,document:t,...n?{onSave:n}:{},...w!==void 0?{replaces:w}:{},...p?{visibleSources:p}:{}}),C=k.useReportDraft(M,O,e),A=S.useRef(null),{selected:R,descriptionSelected:L,selectTile:G,deselectTile:N,selectDescription:X,clearSelection:P,flash:z,stepEditor:D}=Yy({editor:O,gridBox:A}),I=k.layoutRules(O.document.layout,O.document.columns),{columns:B}=I,q=x?.split("/").at(-1)?.replace(/\.malloy$/,""),H=$.useMediaQuery("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),K=!I.widths||H,te=Cy({tiles:O.document.tiles,commit:V=>O.update(se=>{se.tiles=V}),onLanded:G,...I.widths&&H?{placement:{columns:B,gridBox:A}}:{}}),ye=(V,se)=>{if(O.update($e=>{$e.tiles=V}),se===void 0)return;const Me=V.findIndex($e=>fe($e)===se);Me>=0&&G(Me)},_e=I.widths,re=S.useCallback((V,se)=>_e&&k.isPlaced(V)?Rt(V,B,se):V,[_e,B]),{dragging:De}=te,ge=k.useDefaultTileSpan(A,B),ve=S.useMemo(()=>O.document.tiles.map(V=>V.colspan===void 0?{...V,colspan:ge}:V),[O.document.tiles,ge]),Ge=Dy({tiles:ve,columns:B,gridBox:A,onStart:G,commit:({index:V,edges:se,shape:Me,placed:$e,placedAll:Yt})=>{const ne=Yt??O.document.tiles,oe=ne[V];if(!oe)return;let Ue=If(oe,Me,se,$e);(se.e||se.w)&&(Ue=k.withSpan(Ue,Me.colspan,B,ge));const bt=ne.map((or,mn)=>mn===V?Ue:or);ye($e?In(Rt(bt,B,V)):bt,fe(oe))}}),Z=lx({editor:O,rules:I,modelPath:x,textHeld:p!==void 0,selectTile:G,deselectTile:N}),{menu:Xe,addingTile:ke,openAdd:ue}=Z,Oe=rx({editor:O,opened:t,givens:u,catalog:c}),{filterDialog:Ae,setFilterDialog:ie}=Oe,[qe,Ye]=S.useState(void 0),{draftDirty:j,openDraft:F,prepare:U}=ax({editorDirty:O.dirty}),Y=Ge.drag!==void 0,Se=S.useMemo(()=>({paused:Y,escape:()=>{!Xe&&!Ae&&!ke&&qe===void 0&&P()},move:(V,se)=>{if(De||R===void 0||!I.widths||!K)return!1;const Me=O.document.tiles[R];if(!Me||Me.row===void 0||Me.col===void 0)return!1;const $e=Xa(O.document.tiles,R,V,se,B);if($e.every((oe,Ue)=>oe===O.document.tiles[Ue]))return!0;const Yt=fe(Me);O.update(oe=>{oe.tiles=In(Xa(oe.tiles,R,V,se,B))});const ne=In($e).findIndex(oe=>fe(oe)===Yt);return ne>=0&&G(ne),!0},nudge:V=>{if(De||R===void 0||!I.widths||!K)return;const se=O.document.tiles[R];if(!se)return;const Me=k.nudgedSpan(se.colspan??ge,V,mc(se,B));Me!==(se.colspan??ge)&&O.update($e=>{$e.tiles[R]=k.withSpan($e.tiles[R],Me,B,ge),$e.tiles=re($e.tiles,R)})}}),[Y,ge,K,re,G,O,Xe,Ae,ke,qe,P,R,B,I,De]),we=Jy({editor:D,extraDirty:j,keepsEdits:M!==void 0&&C.keeping,prepare:U,unit:{name:"tile",count:V=>V.tiles.length},onSave:n,onDirtyChange:s,onExit:o,onChange:r,shortcuts:Se,report:Uy({size:O.document.tiles.length,path:x??"",layout:O.document.layout,savesTo:y,onEvent:h})}),ht=O.document.tiles.length===0,{toolbarProps:W}=we,Q=C.restored,Le={status:we.saving?"saving":W.dirty?"unsaved":"saved",saveTarget:g??Ko[y],...C.keptAt!==void 0?{draftKeptAt:C.keptAt}:{},...(W.dirty||Q?.pending)&&M!==void 0?{discard:C.discard}:{},...Q?{restored:Q}:{},...Q&&!Q.pending?{dismissRestored:C.dismissRestored}:{}},Be=O.document.tiles,lt=R!==void 0&&Be[R]?fe(Be[R]):void 0,he=I.widths&&K&&k.isPlaced(Be)?{...Hf(Be,B)?{pack:()=>ye(In(gc(Be,B)),lt)}:{},flow:()=>ye(qf(Be),lt)}:void 0;Ky(T,{...Le,...W.onSave?{save:W.onSave}:{},canUndo:W.canUndo,undo:W.onUndo,canRedo:W.canRedo,redo:W.onRedo,add:{...c?{tile:()=>Z.openAdd()}:{},text:Z.appendText,...v!==void 0?{filterUnavailable:v}:ht?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>ie({})}},...W.onExit?{exit:W.onExit}:{},...we.done?{done:we.done}:{},...Q?.pending?{restore:C.restoreOffered}:{},...he?{arrange:he}:{}});const tt=T?void 0:m.jsx(Qf,{...we.toolbarProps,...d?{actions:d}:{},...c?{onAddTile:()=>ue()}:{},...he?{arrange:m.jsx(Ff,{arrange:he})}:{},savesTo:y,...g?{saveLabel:g}:{},...M!==void 0&&W.onSave?{saveStatus:Le}:{}});return m.jsx(Hu.Provider,{value:F,children:m.jsx($.Stack,{className:k.reportClasses.builder,"data-saves-to":y,sx:{gap:0,mx:`-${Go}px`},children:m.jsxs(k.ReportPage,{layout:I.layout,sx:{px:`${Go}px`,pb:`${Go}px`},header:m.jsx(qy,{editor:O,documentSlug:q,actions:tt,descriptionSelected:L,selectDescription:X}),controls:ht?void 0:m.jsx(Vy,{controls:Oe.controlList,unknownFieldsOf:Oe.unknownFieldsOf,onEdit:V=>ie({control:V}),onAdd:()=>ie({}),...v?{addDisabledReason:v}:{},onRemove:Oe.dropControl,..._?{fixedFilters:_}:{},...b?{onOpenModel:b}:{},...O.document.startingGivens?{startingValues:O.document.startingGivens}:{},onStartingValue:(V,se)=>O.update(Me=>{const $e={...Me.startingGivens??{}};se===void 0?delete $e[V]:$e[V]=se,Object.keys($e).length>0?Me.startingGivens=$e:delete Me.startingGivens}),children:l}),children:[ht&&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."}),c&&m.jsx($.Button,{size:"small",startIcon:m.jsx(k.AddIcon,{}),onClick:()=>ue(),children:"Add tile"})]}),Q?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:C.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:C.discard,children:"Discard"})]}),children:`You have unsaved edits from ${qo(Q.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),O.error&&m.jsx($.Alert,{severity:"warning",children:O.error}),!K&&m.jsx($.Alert,{severity:"info",children:"This window is too narrow for the grid, so tiles stack in one column, as on a phone. Widen it to move tiles or change their width."}),m.jsx(zy,{editor:O,arrange:K,reorder:te,edging:Ge,place:re,gridBox:A,defaultSpan:ge,rules:I,canAdd:!!c,selected:R,flash:z,menuIndex:Xe?.index,onSelect:G,onOpenMenu:(V,se)=>{G(se),Z.setMenu({anchor:V,index:se})},onRemove:Z.removeTile,...O.document.tiles.length===1&&O.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:ue,editTile:Z.editTile,...i?{renderTile:i}:{}}),m.jsx(Ph,{editor:O,catalog:c,columns:B,dashboards:f,bindings:Oe,tiles:Z,drillSource:qe,setDrillSource:Ye,exitDialog:we.exitGuard.dialog,...a?{renderViewPreview:a}:{},...E?{takenGivenNames:E}:{}})]})})})}const dx=k.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),ux=k.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"})),fx=k.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function hx({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=be.usePublisherTheme(),o=k.edgeColor(s.cardBorder),i=k.hoverEdgeColor(s.cardBorder,s.tileTitle),[a,l]=S.useState(null),u=e?.save!==void 0&&e.status!=="saved",c=e?.done??n,d=u&&e?.done===void 0,f=e?.add,h=f!==void 0&&(f.tile!==void 0||f.text!==void 0||f.filter!==void 0||f.filterUnavailable!==void 0),y=g=>()=>{l(null),g?.()};return m.jsxs($.Stack,{direction:"row",role:"toolbar",className:k.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(xc,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${cn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:Nr(s.ui),children:m.jsx(yc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${cn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:Nr(s.ui),children:m.jsx(vc,{fontSize:"small"})})})}),e.arrange&&m.jsx(Ff,{arrange:e.arrange}),h&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),h&&m.jsxs(m.Fragment,{children:[m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(k.AddIcon,{}),endIcon:m.jsx(k.ExpandMoreIcon,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:g=>l(g.currentTarget),sx:{...Mr(o,i),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs($.Menu,{anchorEl:a,open:a!==null,onClose:()=>l(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:px(o,s.ui)}},MenuListProps:{sx:{p:.5}},children:[f?.tile&&m.jsx(Ho,{icon:m.jsx(ux,{}),title:"Tile",detail:"A chart or table from the model",onClick:y(f.tile)}),f?.text&&m.jsx(Ho,{icon:m.jsx(fx,{}),title:"Text",detail:"Prose between the tiles",onClick:y(f.text)}),(f?.filter||f?.filterUnavailable)&&m.jsx(Ho,{icon:m.jsx(dx,{}),title:"Filter",detail:f.filterUnavailable??"A control the tiles read",disabled:f.filter===void 0,onClick:y(f.filter)})]})]})]})]}),(c||d)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),c&&m.jsx($.Tooltip,{enterDelay:800,enterNextDelay:800,title:e?.done&&u?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx($.Button,{variant:d?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:c,sx:{...Mr(o,i,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&d&&m.jsx($.Tooltip,{title:`Save (${cn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...Mr(o,i,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const px=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Ho({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:o}=be.usePublisherTheme(),i=o.ui;return m.jsxs($.MenuItem,{onClick:s,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:i.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:i.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:o.accent,bgcolor:`color-mix(in srgb, ${o.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx($.Box,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs($.Box,{className:"add-text",sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...i.type.control,fontWeight:i.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx($.Box,{sx:{...i.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function gx(e,t,n=new Set,r=new Map){const s=[];for(const c of e.tiles){if(!ce(c))continue;const d=(c.filters??[]).map(h=>h.given),f=r.get(Dt(`${c.source} -> ${c.name}`))??[];for(const h of f)(n.has(h)||d.includes(h))&&s.push(h);s.push(...d)}const o=new Set(s),i=t.flatMap(c=>c.name!==void 0&&n.has(c.name)&&!o.has(c.name)?[c.name]:[]),a=new Map((e.localGivens??[]).map(c=>[c.name,c])),l=new Map(t.flatMap(c=>c.name===void 0?[]:[[c.name,c]])),u=[];for(const c of new Set([...i,...s])){const d=a.get(c),f=d?k.localGivenSpec(d):l.get(c);f&&u.push(f)}return u}function mx(e,t,n){const r=new Map;for(const o of t.tiles)ce(o)&&r.set(Dt(dt(o)),new Set((o.filters??[]).map(i=>i.given)));const s=new Set;for(const o of e.tiles){if(!ce(o))continue;const i=Dt(dt(o)),a=r.get(i);for(const l of n.get(i)??[])a?.has(l)||s.add(l)}return s}function vx(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function yx(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function Dt(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function xx(e,t,n,r){const s=new Set(t.sources.map(a=>a.name)),o=new Set(e.sources.map(a=>a.name).filter(a=>!s.has(a)));return o.size===0?void 0:{sources:o,modelOf:a=>{if(r)return;const l=e.imports.find(c=>c.kind==="names"&&c.names.includes(a));if(l===void 0)return;const u=k.resolvedOf(l.from,n);return k.reaches(t,a,u,n)?void 0:u}}}function bx(e,t,n){if(!n||t.declaration.kind!=="reference")return;let r=t.source,s=t.declaration.from;if(r===void 0||!n.sources.has(r))return;const o=e.tiles.length+e.sources.length;for(let i=0;i<=o;i++){if(!n.sources.has(r)){const u=n.modelOf?.(r);return{source:r,view:s,...u?{modelPath:u}:{}}}const a=e.sources.find(u=>u.name===r);if(!a||a.scopedBy?.length)return;const l=e.tiles.find(u=>ce(u)&&u.source===r&&u.name===s);if(!l)r=a.base;else if(l.declaration.kind==="reference")s=l.declaration.from;else return}}function wx(e,t,n,r=new Map,s,o){if(Hn(t))return{expression:dt(t),givenNames:void 0,reads:s&&[...s]};const i=bx(e,t,o),a=i?.source??t.source,l=i?.view??(t.declaration.kind==="reference"?t.declaration.from:t.name),u=i?.modelPath!==void 0?new Set:n,c=new Map((e.localGivens??[]).map(b=>[b.name,b.type])),d=new Map((e.localGivens??[]).map(b=>[b.name,b.default])),f=e.sources.find(b=>b.name===a)?.scopedBy??[],h=new Set([...f,...s??[]].filter(b=>u.has(b))),y=new Set([...f,...s??[]]),g=[];for(const b of t.filters??[]){const E=`where: ${me.malloyPath(b.field)} ${b.op??"~"}`;if(u.has(b.given)){h.add(b.given),y.add(b.given),g.push(`${E} $${b.given}`);continue}if(!c.has(b.given))continue;y.add(b.given);const T=k.malloyLiteral(r.get(b.given),c.get(b.given))??vx(d.get(b.given));T!==void 0&&g.push(`${E} ${T}`)}const w=g.join(", "),x=t.chart,p=x==="none"||k.isChartPick(x)?k.chartLineText(x,t.chartCarried):x==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
142
|
+
`),c=Kv(e),d=p=>({start:c[p],end:p+1<c.length?c[p+1]:e.length}),f=p=>/^\s*/.exec(u[p])?.[0]??"",h=[],y={...i,sourceText:e,parsed:l.parsed,lines:u,starts:c,wholeLine:d,indentOf:f,current:s,next:o,edits:h};for(const p of[ty,sy,iy,oy,ay,ly,cy,dy,hy]){const v=p(y);if(v)return v}const g=p=>{const{drills:v,localGivens:_,description:b,...E}=p,T=p.tiles.map(M=>{if(Ce(M))return M;if(M.filters?.length)return lo(M);const{filters:O,...C}=M;return lo(C)});return{...E,...b===void 0?{}:{description:mf(b)},tiles:T,...v?.length?{drills:[...v].sort((M,O)=>ao(M).localeCompare(ao(O)))}:{},..._?.length?{localGivens:_}:{}}};if(h.length===0)return Ee(g(s))!==Ee(g(o))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const w=Vv(e,h);if((await Hl(e)).length===0){const p=await Hl(w);if(p.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${p[0]}). Your changes are still here.`}}const x=await oo(w);return so(x)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${x.reason}`}:Ee(g(x.document))!==Ee(g(o))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:w}}function Ef({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=be.usePublisherTheme(),o=s.ui,i=S.useId(),[a,l]=S.useState(!1),u=S.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:c,patch:d,close:f,discard:h}=_c(u,a,_=>n(_.text),()=>l(!1)),y=a&&c!==void 0&&c.text!==e,g=c!==void 0&&c.text!==e?js(c.text):void 0;qu(y,()=>g!==void 0?!1:(f(),!0));const w=S.useRef(!1);S.useEffect(()=>{a||(w.current=!1)},[a]);const x=S.useCallback(_=>{!_||w.current||(w.current=!0,_.setSelectionRange(_.value.length,_.value.length))},[]);if(!a||c===void 0){const _=e.trim()?js(e):void 0;return m.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():l(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),l(!0)))},sx:[{minHeight:24},Gu(s,"prose")],children:[e.trim()?m.jsx(k.Prose,{variant:r,children:e}):m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),_&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:_})]})}const p=c.text!==e?js(c.text):void 0,v=()=>{p===void 0&&f()};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:c.text,placeholder:t,error:p!==void 0,inputRef:x,inputProps:{"aria-label":"Markdown","aria-describedby":i,...p!==void 0?{"aria-invalid":!0}:{}},onChange:_=>d(b=>{b.text=_.target.value}),onKeyDown:_=>{_.key==="Escape"?(_.preventDefault(),h(),l(!1)):_.key==="Enter"&&(_.metaKey||_.ctrlKey)&&(_.preventDefault(),v())},onBlur:()=>f(),sx:{p:0,...o.type.prose,color:"inherit",maxWidth:k.PROSE_MAX_WIDTH,"& textarea":{p:0}}}),p!==void 0&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:p}),m.jsxs($.Typography,{id:i,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",cn,"↩ done · Esc cancels"]})]})}const yy="Write markdown: # heading, **bold**, - list";function xy({tile:e,sized:t=!1,onChange:n}){const r=m.jsx(k.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Ef,{markdown:e.markdown,placeholder:yy,onCommit:n})});return t?m.jsx($.Box,{"data-testid":"text-tile-scroller",sx:{minHeight:0,overflow:"auto",p:"4px",m:"-4px"},children:r}):r}var by=Object.defineProperty,wy=Object.defineProperties,_y=Object.getOwnPropertyDescriptors,tc=Object.getOwnPropertySymbols,ky=Object.prototype.hasOwnProperty,Sy=Object.prototype.propertyIsEnumerable,nc=(e,t,n)=>t in e?by(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_n=(e,t)=>{for(var n in t||(t={}))ky.call(t,n)&&nc(e,n,t[n]);if(tc)for(var n of tc(t))Sy.call(t,n)&&nc(e,n,t[n]);return e},kn=(e,t)=>wy(e,_y(t));function $y(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function bs(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function zo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Ty(e,t,n){var r,s;const{source:o,target:i,canceled:a}=t.operation;if(!o||!i||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(v,_)=>v===_||v!==null&&typeof v=="object"&&"id"in v&&v.id===_;if(Array.isArray(e)){const v=e.findIndex(b=>l(b,o.id)),_=e.findIndex(b=>l(b,i.id));if(v===-1||_===-1){if(zo(o)){const b=o.initialIndex,E=o.index;return b===E||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,E)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==v)return n(e,v,b)}return n(e,v,_)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[v,_]of u)if(c===-1&&(c=_.findIndex(b=>l(b,o.id)),c!==-1&&(d=v)),f===-1&&(f=_.findIndex(b=>l(b,i.id)),f!==-1&&(h=v)),c!==-1&&f!==-1)break;if(c===-1&&zo(o)){const v=o.initialGroup==null?void 0:bs(e,o.initialGroup),_=o.initialIndex,b=o.group==null?void 0:bs(e,o.group),E=o.index;if(v==null||b==null||v===b&&_===E)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return kn(_n({},e),{[v]:n(e[v],_,E)});const T=e[v][_];return kn(_n({},e),{[v]:[...e[v].slice(0,_),...e[v].slice(_+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:y}=o.manager,g=(s=(r=y.shape)==null?void 0:r.current.center)!=null?s:y.position.current;if(h==null){const v=bs(e,i.id);if(v!=null){const _=i.shape&&g.y>i.shape.center.y?e[v].length:0;h=v,f=_}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&zo(o)){const v=o.group==null?void 0:bs(e,o.group),_=o.group!=null&&v!==d,b=o.index!==c;if(_||b){const E=o.group==null?d:v;if(E!=null){if(d===E)return kn(_n({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return kn(_n({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[E]:[...e[E].slice(0,o.index),T,...e[E].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return kn(_n({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(g.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return kn(_n({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[h]:[...e[h].slice(0,f+x),p,...e[h].slice(f+x)]})}function Ey(e,t){return Ty(e,t,$y)}function Cf(e){const t=e.getBoundingClientRect(),n=new Map;for(const r of e.querySelectorAll("[data-tile-key]")){const s=r.dataset.tileKey;if(!s)continue;const o=r.getBoundingClientRect();n.set(s,{top:o.top-t.top,left:o.left-t.left,width:o.width,height:o.height})}return n}function Cy({tiles:e,commit:t,onLanded:n,placement:r}){const[s,o]=S.useState(void 0),i=S.useRef(void 0),[a,l]=S.useState(!1),u=S.useRef(void 0);return{dragging:a,preview:s,onDragStart:y=>{l(!0),i.current=e;const g=r?.gridBox.current,w=y?.operation.source?.id;if(!r||!g)return;const x=e.findIndex(M=>fe(M)===w),p=Cf(g),v=p.get(String(w));if(x<0||!v)return;const _=pc(e,e.map(M=>p.get(fe(M))),r.columns,Ls(g.getBoundingClientRect().width,r.columns)),b=g.getBoundingClientRect(),E=y?.operation.position?.current,T=E?{x:E.x-(b.left+v.left),y:E.y-(b.top+v.top)}:{x:0,y:0};u.current={base:_,index:x,from:v,grab:T},i.current=_,o(_)},onDragMove:y=>{const g=u.current,w=r?.gridBox.current;if(!g||!r||!w)return;const x=w.getBoundingClientRect(),p=y.operation.position.current,v=y.to??(y.by?{x:p.x+y.by.x,y:p.y+y.by.y}:p),_=g.base[g.index],b=hc(v.x-g.grab.x-x.left,v.y-g.grab.y-x.top,_.colspan??1,r.columns,Ls(w.getBoundingClientRect().width,r.columns)),E=i.current?.[g.index];if(E?.row===b.row&&E.col===b.col)return;const T=Gf(g.base,g.index,b,r.columns);i.current=T,o(T)},onDragOver:y=>{if(u.current){y.preventDefault();return}const{source:g,target:w}=y.operation;if(!g||!w)return;const x=i.current??e;let p;if(w.type===sf){const{after:v}=w.data,_=x.findIndex(T=>fe(T)===g.id);if(_<0||v===g.id)return;const E=x.filter((T,M)=>M!==_).findIndex(T=>fe(T)===v)+1;p=jm(x,_,E)}else{const v=x.map(fe),_=Ey(v,y);if(_.every((E,T)=>E===v[T]))return;const b=new Map(x.map(E=>[fe(E),E]));p=Pm(_.map(E=>b.get(E)),e.map(E=>E.break??!1))}i.current=p,o(p)},onDragEnd:y=>{l(!1);const g=u.current,w=g!==void 0;u.current=void 0;const x=i.current,p=g!==void 0&&x!==void 0&&x[g.index]?.row===g.base[g.index]?.row&&x[g.index]?.col===g.base[g.index]?.col,v=w&&x?In(x):x;if(i.current=void 0,o(void 0),y.canceled||!v||p)return;t(v);const _=v.findIndex(b=>fe(b)===y.operation.source?.id);_>=0&&n(_)}}}const Oy={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Of=(e,t)=>t===0?e:Of(t,e%t);function My(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Of(e,t),s=Oy[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}const rc=k.TILE_ROW_PX+k.GRID_GAP_PX,Mf=e=>e.n&&e.w||e.s&&e.e?"nwse-resize":e.n&&e.e||e.s&&e.w?"nesw-resize":e.n||e.s?"ns-resize":"ew-resize",ws=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e??""},Iy=e=>({...e.row!==void 0?{row:e.row}:{},...e.col!==void 0?{col:e.col}:{},colspan:e.colspan??1,rowspan:e.rowspan}),sc=(e,t)=>e.row===t.row&&e.col===t.col&&e.colspan===t.colspan&&e.rowspan===t.rowspan;function If(e,t,n,r){const s={...e};return(n.e||n.w)&&(s.colspan=t.colspan,r&&t.col!==void 0&&(s.col=t.col)),(n.n||n.s)&&(t.rowspan===void 0?delete s.rowspan:s.rowspan=t.rowspan,r&&t.row!==void 0&&(s.row=t.row)),s}function Dy({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[o,i]=S.useState(void 0),a=S.useRef(void 0),l=S.useRef(void 0),u=g=>{a.current=g,i(g)};S.useEffect(()=>()=>ws(void 0),[]);const c=o!==void 0;S.useEffect(()=>{if(!c)return;const g=w=>{w.key!=="Escape"||!a.current||(w.preventDefault(),w.stopPropagation(),a.current=void 0,i(void 0),l.current=void 0,ws(void 0))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[c]);const d=g=>{const w=new Set(g.base.filter(v=>v.rowspan===void 0).map(fe)),x=g.base[g.index];let p=l.current;for(const v of n.current?.querySelectorAll("[data-tile-key]")??[]){const _=v.dataset.tileKey;if(!_||!w.has(_)||x&&_===fe(x))continue;const b=v.getBoundingClientRect();Math.abs(b.top-g.top)>1||(p=Math.max(p??0,b.height))}return p};return{drag:o,start:(g,w,x)=>{const p=n.current,v=p?.getBoundingClientRect(),_=g.currentTarget.parentElement?.getBoundingClientRect();if(!p||!v||!_||!e[w])return;g.stopPropagation(),g.preventDefault(),g.currentTarget.setPointerCapture(g.pointerId),ws(Mf(x)),r(w);const b=(x.n||x.w)&&(!k.isPlaced(e)||e[w].row===void 0||e[w].col===void 0),E=b?(()=>{const A=Cf(p);return pc(e,e.map(R=>A.get(fe(R))),t,Ls(v.width,t))})():[...e],T=k.isPlaced(E),M=E[w],O=Iy(M);!T&&O.rowspan===void 0?l.current=_.height:l.current=void 0;const C=T?{...O,rowspan:Fr(M)}:O;u({index:w,edges:x,base:E,placedHere:!!b,placed:T,from:O,begun:C,shape:C,guideTop:_.top-v.top,min:As(M,g.currentTarget.parentElement),top:_.top,left:_.left})},move:g=>{const w=a.current,x=n.current?.getBoundingClientRect();if(!w||!x)return;const p=w.base[w.index];if(!p)return;const _=Ls(x.width,t)+k.GRID_GAP_PX,b=g.clientX-x.left,E=g.clientY-x.top,T=g.currentTarget.parentElement?.getBoundingClientRect(),M=T?.top??w.top,O=T?.left??w.left,{min:C}=w,A=w.shape;let{row:R,col:L,colspan:G,rowspan:N}=A;if(w.placed&&L!==void 0&&R!==void 0){const j=w.from,z=j.col??L,D=z+j.colspan-1,I=j.row??R,B=j.rowspan??Fr(p),q=I+B-1;if(w.edges.e){const H=Math.round((b+k.GRID_GAP_PX)/_);G=Math.min(Math.max(H,z),t)-z+1,L=z}if(w.edges.w){const H=Math.round(b/_)+1;L=Math.min(Math.max(H,1),D),G=D-L+1}if(w.edges.s){const H=w.edges.n?x.top+(I-1)*rc:M;N=k.rowsForHeight(g.clientY-H,C),R=I}if(w.edges.n){const H=Math.round(E/rc)+1,K=Math.min(C,B);R=Math.max(1,Math.min(Math.max(H,q-k.MAX_TILE_ROWS+1),q-K+1)),N=q-R+1}}else{if(w.edges.e){const j=Math.round((g.clientX-O+k.GRID_GAP_PX)/_);G=Math.min(Math.max(j,1),t)}if(w.edges.s){const j=g.clientY-M,z=k.rowsForHeight(j,C),D=d(w);N=D!==void 0&&Math.abs(j-D)<Math.abs(j-k.tileHeightPx(z))?void 0:z}}const X={...R!==void 0?{row:R}:{},...L!==void 0?{col:L}:{},colspan:G,rowspan:N};sc(X,A)||u({...w,shape:X})},end:g=>{g.currentTarget.hasPointerCapture(g.pointerId)&&g.currentTarget.releasePointerCapture(g.pointerId),ws(void 0);const w=a.current;l.current=void 0,w&&(u(void 0),!(g.type==="pointercancel"||sc(w.shape,w.begun))&&s({index:w.index,edges:w.edges,shape:w.shape,placed:w.placed,...w.placedHere?{placedAll:w.base}:{}}))}}}function Py(e,t){const n=[];return(e.edges.e||e.edges.w)&&n.push(My(e.shape.colspan,t)),(e.edges.n||e.edges.s)&&n.push(e.shape.rowspan===void 0?"Auto height":`${e.shape.rowspan} rows tall`),n.join(" · ")}function jy({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:o=!1,onInsertAfter:i,onSelect:a,onOpenMenu:l,onRemove:u,removeBlocked:c,width:d,edges:f,heightEdge:h,fixed:y=!1,children:g}){const{theme:w}=be.usePublisherTheme(),x=w.ui;return m.jsx(gv,{id:fe(e),index:t,disabled:y,children:({ref:p,handleRef:v})=>m.jsxs($.Box,{ref:p,onClick:a,onPointerDown:_=>{_.button===0&&a()},role:"group",className:k.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",...(e.rowspan!==void 0||e.row!==void 0)&&{gridTemplateRows:"minmax(0, 1fr)",minHeight:0},minWidth:0,cursor:"grab",...Df(w,{selected:n,flash:r,bare:o}),...!o&&{[`& .${k.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:w.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${w.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...k.removeBadgeRevealSx,...n&&{[`& .${k.REMOVE_BADGE_CLASS}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[g,m.jsx($.Box,{ref:v,"aria-label":`Move ${lr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(k.RemoveBadge,{label:`Remove ${lr(e)}`,onRemove:u,...c?{disabledReason:c}:{},inset:o?k.BARE_RING_OFFSET_PX:0}),!Ce(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${lr(e)}`,onClick:_=>{_.stopPropagation(),l(_.currentTarget)},sx:{position:"absolute",top:o?0:`${oc}px`,right:o?0:`${oc}px`,borderRadius:x.radius.control,width:28,height:28,zIndex:3,color:"text.secondary",bgcolor:"action.hover",opacity:n||s?1:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(By,{})}),f&&m.jsx(Wy,{edges:f,width:d,heightEdge:h,label:lr(e)}),i&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${lr(e)}`,onClick:_=>{_.stopPropagation(),i()},sx:{position:"absolute",bottom:`-${k.GRID_GAP_PX/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:w.tileTitle,bgcolor:w.tile,border:w.cardBorder,opacity:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:w.tile}},children:m.jsx(k.AddIcon,{sx:{fontSize:14}})})]})})}const oc=14,Go=7,Df=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:s=k.BARE_RING_OFFSET_PX})=>{const o=e.ui,i=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,l=`outline-color ${k.MOTION_FAST}, border-color ${k.MOTION_FAST}, opacity ${k.MOTION_FAST}, box-shadow ${k.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 ${i}`,...a&&{boxShadow:a},pointerEvents:"none",transition:l,...k.reducedMotionSx}}:{borderRadius:o.radius.tile,"& > .MuiPaper-root":{transition:l,...k.reducedMotionSx,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:l,...k.reducedMotionSx,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:k.hoverEdgeColor(e.cardBorder,e.tileTitle)}}}}};function Ry({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=be.usePublisherTheme();return m.jsxs(k.TileCard,{chrome:r,children:[m.jsx(k.TileHeading,{title:t?.title??co(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),m.jsx($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:dt(e).replace("->","→")})]})}function Ay({after:e}){const{theme:t}=be.usePublisherTheme();return m.jsx(mv,{id:Ku(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 ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,...k.reducedMotionSx}})})}function Ly({columns:e,faint:t=!1}){const{theme:n}=be.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:`${k.GRID_GAP_PX}px`},children:Array.from({length:e},(r,s)=>m.jsx($.Box,{sx:{bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},s))})}function ic({top:e,faint:t=!1}){const{theme:n}=be.usePublisherTheme(),r=k.TILE_ROW_PX+k.GRID_GAP_PX,s=-Math.ceil(e/r);return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,overflow:"hidden",pointerEvents:"none",zIndex:0},children:Array.from({length:-s+4*k.MAX_TILE_ROWS},(o,i)=>m.jsx($.Box,{sx:{position:"absolute",top:e+(s+i)*r,left:0,right:0,height:k.TILE_ROW_PX,bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},i))})}function By(){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"})]})}const Fy=[{edges:{n:!0},sx:{top:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{s:!0},sx:{bottom:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{e:!0},sx:{right:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{w:!0},sx:{left:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{n:!0,w:!0},sx:{top:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{n:!0,e:!0},sx:{top:"-8px",right:"-8px",width:"32px",height:"32px"}},{edges:{s:!0,w:!0},sx:{bottom:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{s:!0,e:!0},sx:{bottom:"-8px",right:"-8px",width:"20px",height:"20px"}}];function Wy({edges:e,width:t,heightEdge:n,label:r}){const{theme:s}=be.usePublisherTheme(),o=s.ui,[i,a]=S.useState(void 0),l=i??n?.min??k.MIN_TILE_ROWS,u=f=>n&&a(n.minFor?.(f)??n.min),c=f=>(!(f.n||f.w)||e.all)&&(!f.e||e.right),d={"&:focus-visible":{outline:`2px solid ${s.accent}`,outlineOffset:-4,borderRadius:"3px"}};return m.jsxs(m.Fragment,{children:[Fy.filter(f=>c(f.edges)).map(f=>{const h=Object.keys(f.edges).join(""),y=h==="e",w=y&&t?{role:"separator",tabIndex:0,"aria-orientation":"vertical","aria-label":`Width of ${r}`,"aria-valuenow":t.span,"aria-valuemin":1,"aria-valuemax":t.max??t.columns,"aria-valuetext":`${t.span} of ${t.columns} columns`,onKeyDown:x=>{if(x.altKey)return;const p=t.max??t.columns,v=x.key==="ArrowRight"?t.span+1:x.key==="ArrowLeft"?t.span-1:x.key==="Home"?1:x.key==="End"?p:void 0;v!==void 0&&(x.preventDefault(),x.stopPropagation(),t.onStep(Math.min(Math.max(v,1),p)))}}:h==="s"&&n?{role:"separator",tabIndex:0,"aria-orientation":"horizontal","aria-label":`Height of ${r}`,"aria-valuemin":l,onFocus:x=>u(x.currentTarget.parentElement),onPointerEnter:x=>u(x.currentTarget.parentElement),"aria-valuemax":k.MAX_TILE_ROWS,...n.rows===void 0?{}:{"aria-valuenow":n.rows},"aria-valuetext":Ny(n.rows),onKeyDown:x=>{if(x.altKey)return;const p=n.rows,v=p??l,_=x.key==="ArrowDown"?v+1:x.key==="ArrowUp"?v-1:x.key==="Home"?l:x.key==="End"?k.MAX_TILE_ROWS:x.key==="Delete"||x.key==="Backspace"?null:void 0;if(_===void 0)return;if(x.preventDefault(),x.stopPropagation(),_===null){p!==void 0&&n.onStep(void 0);return}const b=Math.min(Math.max(_,l),k.MAX_TILE_ROWS);b!==p&&n.onStep(b)}}:{"aria-hidden":!0};return m.jsx($.Box,{className:`builder-affordance${y?` ${k.reportClasses.widthHandle}`:""}`,[of]:"",...w,"data-edge":h,onPointerDown:x=>{x.button===0&&e.start(x,f.edges)},onPointerMove:e.move,onPointerUp:e.end,onPointerCancel:e.end,onClick:x=>x.stopPropagation(),onDoubleClick:x=>{!f.edges.s||f.edges.e||f.edges.w||(x.stopPropagation(),n&&n.rows!==void 0&&n.onStep(void 0))},sx:{position:"absolute",...f.sx,cursor:Mf(f.edges),touchAction:"none",zIndex:Object.keys(f.edges).length>1?2:1,...d}},h)}),e.label&&m.jsx($.Box,{"aria-hidden":!0,sx:f=>({position:"absolute",right:12,bottom:12,px:1,py:.5,borderRadius:o.radius.control,bgcolor:f.palette.text.primary,color:f.palette.background.paper,...o.type.label,whiteSpace:"nowrap",pointerEvents:"none",zIndex:4}),children:e.label})]})}const Ny=e=>e===void 0?"Auto height":`${e} rows tall`;function zy({editor:e,reorder:t,edging:n,place:r=v=>v,arrange:s=!0,gridBox:o,defaultSpan:i=1,rules:a,canAdd:l,selected:u,flash:c,menuIndex:d,onSelect:f,onOpenMenu:h,onRemove:y,removeBlocked:g,openAdd:w,editTile:x,renderTile:p}){const{dragging:v,preview:_,onDragStart:b,onDragMove:E,onDragOver:T,onDragEnd:M}=t,{columns:O}=a,C=n.drag,A=D=>D.colspan===void 0?{...D,colspan:i}:D,R=(C!==void 0?(()=>{const D=C.placedHere?C.base:e.document.tiles;if(!D[C.index])return D;const B=D.map((q,H)=>H===C.index?If(q,C.shape,C.edges,C.placed):q);return C.placed?Rt(B,O,C.index):B})():_??e.document.tiles).map(A),L=k.isPlaced(R),G=v||C!==void 0,N=!G&&L&&s&&u!==void 0,X=e.document.tiles.length===0,j=G&&!L?Rm(R,O):R.map(Uu),z=D=>Gy(D,co(D),x);return m.jsxs(m.Fragment,{children:[m.jsxs(vm,{sensors:fv,onDragStart:b,onDragMove:E,onDragOver:T,onDragEnd:M,children:[m.jsx(vv,{active:v}),m.jsxs($.Box,{ref:o,sx:{position:"relative"},children:[a.widths&&(G||N)&&m.jsx(Ly,{columns:O,faint:!G}),C!==void 0&&!C.placed?(C.edges.s||C.edges.n)&&m.jsx(ic,{top:C.guideTop}):L&&(G||N)&&m.jsx(ic,{top:0,faint:!G}),m.jsx(k.DashboardGrid,{tiles:j,columns:O,rowGapPx:k.GRID_GAP_PX,defaultRowspan:D=>D.kind==="tile"?Fr(D.tile):k.PLACED_DEFAULT_ROWSPAN.query,keyOf:D=>D.kind==="gap"?Ku(D.after):fe(D.tile),renderTile:D=>{if(D.kind==="gap")return m.jsx(Ay,{after:D.after});const{tile:I,index:B}=D;return m.jsx(jy,{tile:I,index:B,selected:B===u,flash:fe(I)===c,menuOpen:d===B,bare:Ce(I),...a.insertBetween&&l&&B<e.document.tiles.length-1?{onInsertAfter:()=>w(B+1)}:{},fixed:!s,...a.widths?{edges:{all:s,right:s,start:(q,H)=>n.start(q,B,H),move:n.move,end:n.end,...C?.index===B?{label:Py(C,O)}:{}}}:{},...a.widths&&s?{width:{span:I.colspan??1,columns:O,max:mc(I,O),onStep:q=>{q!==(I.colspan??1)&&e.update(H=>{if(!Number.isInteger(B)||B<0)return;const K=H.tiles[B];K&&(H.tiles[B]=k.withSpan(K,q,O,i)),H.tiles=r(H.tiles,B)})}}}:{},...a.widths?{heightEdge:{rows:I.rowspan,min:As(I),minFor:q=>As(I,q),onStep:q=>e.update(H=>{if(!Number.isInteger(B)||B<0)return;const K=H.tiles[B];K&&(q===void 0?delete K.rowspan:K.rowspan=q,H.tiles=r(H.tiles,B))})}}:{},onSelect:()=>f(B),onOpenMenu:q=>h(q,B),onRemove:()=>y(B),...g?{removeBlocked:g}:{},children:Ce(I)?m.jsx(xy,{tile:I,sized:I.rowspan!==void 0||L,onChange:q=>x(fe(I),H=>{Ce(H)&&(H.markdown=q)})}):p?p(I,z(I),"card"):m.jsx(Ry,{tile:I,heading:z(I)})})}})]})]}),a.insertBetween&&l&&!X&&m.jsx($.Button,{size:"small",startIcon:m.jsx(k.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>w(),sx:{alignSelf:"center"},children:"Add tile"})]})}const Gy=(e,t,n)=>{if(Hn(e))return;const r=fe(e),s=o=>i=>n(r,a=>{ce(a)&&(i===""?delete a[o]:a[o]=i)});return{title:m.jsx(Pi,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(Pi,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Hy={x:12,y:6};function qy({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:o}=be.usePublisherTheme();return m.jsx(k.ReportHeader,{actions:n,title:m.jsx(Pi,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:i=>e.update(a=>{a.title=i})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(k.TextTileFrame,{sx:{position:"relative",overflow:"visible",...Df(o,{selected:r,bare:!0,ringOffset:Hy})},children:m.jsx(Ef,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:i=>e.update(a=>{i.trim()===""?delete a.description:a.description=i})})})})})}const Uy=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:o}=k.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:i,structural:a,durationMs:l})=>o({type:"report.saved",tiles:i,structural:a,where:r,durationMs:l}),refused:i=>o({type:"report.save_refused",reason:i}),undone:({size:i,structural:a,durationMs:l})=>o({type:"report.save_undone",tiles:i,structural:a,where:r,durationMs:l}),undoRefused:i=>o({type:"report.save_undo_refused",reason:i})}};function Ky(e,t){const n=S.useRef(t);n.current=t;const r=S.useRef(e);r.current=e;const s=S.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.(),pack:()=>n.current.arrange?.pack?.(),flow:()=>n.current.arrange?.flow()}),[]),{status:o,saveTarget:i,canUndo:a,canRedo:l,add:{filterUnavailable:u}}=t,c=t.save!==void 0,d=t.add.tile!==void 0,f=t.add.text!==void 0,h=t.add.filter!==void 0,y=t.exit!==void 0,g=t.done!==void 0,w=t.discard!==void 0,{draftKeptAt:x}=t,p=t.restored?.savedAt,v=t.restored?.stale??!1,_=t.restored?.pending??!1,b=t.restore!==void 0,E=t.dismissRestored!==void 0,T=t.arrange!==void 0,M=t.arrange?.pack!==void 0,O=S.useMemo(()=>({status:o,saveTarget:i,...c?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:l,redo:s.redo,add:{...d?{tile:s.addTile}:{},...f?{text:s.addText}:{},...h?{filter:s.addFilter}:{},...u!==void 0?{filterUnavailable:u}:{}},...y?{exit:s.exit}:{},...g?{done:s.done}:{},...x!==void 0?{draftKeptAt:x}:{},...w?{discard:s.discard}:{},...p!==void 0?{restored:{savedAt:p,stale:v,pending:_}}:{},...b?{restore:s.restore}:{},...E?{dismissRestored:s.dismissRestored}:{},...T?{arrange:{...M?{pack:s.pack}:{},flow:s.flow}}:{}}),[s,o,i,c,a,l,d,f,h,u,y,g,x,w,p,v,_,b,E,T,M]),C=e!==void 0;S.useEffect(()=>{r.current?.(O)},[O,C]),S.useEffect(()=>()=>r.current?.(void 0),[])}function Vy({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:s,onRemove:o,fixedFilters:i,onOpenModel:a,startingValues:l,onStartingValue:u,children:c}){const d=c!=null,f=S.useMemo(()=>{const h=new Map(e.map(y=>[y.name,y]));return{stateOf:y=>{const g=i?.get(y);if(g!==void 0){const{modelPath:p}=g;return{origin:h.get(y)?.origin??"model",fixed:g.reason,...p!==void 0&&a?{openModel:()=>a(p)}:{}}}const w=h.get(y);if(!w)return;const x=t(w.name,w.type);return{origin:w.origin,...x.length>0?{problem:`Cannot filter on ${x.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:d?e.filter(y=>y.boundTiles===0&&!i?.has(y.name)).map(y=>({name:y.name,label:y.label??y.name})):[],onEdit:y=>{const g=h.get(y);g&&n(g)},onRemove:o,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...u?{startingValueOf:y=>l?.[y],setStartingValue:u}:{}}},[e,t,d,n,o,r,s,i,a,l,u]);return m.jsx(k.StickyControls,{children:m.jsx(k.FilterEditingContext.Provider,{value:f,children:d?c: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(k.FilterSettingsButton,{name:h.name,label:h.label??h.name,unused:h.boundTiles===0},h.name)),m.jsx(k.AddFilterButton,{})]})})})}function Xy(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 o=n.get(fe(s));if(!o||o.index!==r||JSON.stringify(o.tile)!==JSON.stringify(s))return fe(s)}}function Yy({editor:e,gridBox:t}){const[n,r]=S.useState(void 0),s=typeof n=="object"?n.tile:void 0,o=n==="description",i=S.useCallback(w=>r(x=>typeof x=="object"&&x.tile===w?x:{tile:w}),[]),a=S.useCallback(()=>r(w=>w==="description"?w:void 0),[]),l=S.useCallback(()=>r("description"),[]),u=S.useCallback(()=>r(void 0),[]),c=n!==void 0;S.useEffect(()=>{if(!c)return;const w=x=>{const p=x.target;p instanceof Element&&p!==document.documentElement&&p.closest(Qy)===null&&u()};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[c,u]);const[d,f]=S.useState(void 0),h=S.useRef(!1),y=S.useRef(e.document);S.useEffect(()=>{const w=y.current;if(y.current=e.document,!h.current)return;h.current=!1;const x=Xy(w,e.document);if(x===void 0)return;f(x),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===x)?.scrollIntoView?.({block:"nearest",behavior:k.scrollBehavior()})},[e.document,t]),S.useEffect(()=>{if(d===void 0)return;const w=setTimeout(()=>f(void 0),1500);return()=>clearTimeout(w)},[d]);const g=S.useMemo(()=>({...e,undo:()=>{h.current=!0,e.undo()},redo:()=>{h.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:o,selectTile:i,deselectTile:a,selectDescription:l,clearSelection:u,flash:d,stepEditor:g}}const Qy=["[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 Zy({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[o,i]=S.useState("idle"),[a,l]=S.useState(!1),u=S.useRef(r);u.current=r;const c=S.useRef(s);c.current=s;const d=S.useRef(0),f=S.useCallback(async()=>{const g=++d.current;l(!1),i("saving");try{await u.current()}catch{d.current===g&&i("idle");return}d.current===g&&l(!0)},[]);S.useEffect(()=>{if(o==="waiting"){if(t)return;e?f():(i("idle"),c.current())}else if(o==="saving"){if(!a||t)return;i("idle"),e||c.current()}},[o,a,t,e,f]);const h=S.useCallback(()=>{o==="idle"&&(e?i("asking"):c.current())},[o,e]),y=S.useCallback(()=>{o==="idle"&&(e?n?t?i("waiting"):f():i("asking"):c.current())},[o,e,n,t,f]);return{requestExit:h,saveAndExit:y,finishing:o==="saving"||o==="waiting",dialog:{open:o==="asking",canSave:n,onKeepEditing:()=>{o==="asking"&&i("idle")},onDiscard:()=>{o==="asking"&&(i("idle"),c.current())},onSaveAndExit:()=>{o==="asking"&&(t?i("waiting"):f())}}}}function Jy({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:o=!1,keepsEdits:i=!1,report:a,unit:l,prepare:u,shortcuts:c}){const[d,f]=S.useState(!1),[h,y]=S.useState(!1),g=S.useRef(null),w=S.useRef(a);w.current=a;const x=e.dirty||o,p=(e.edited??e.dirty)||o,v=i?o:p;S.useEffect(()=>{s?.(e.document)},[e.document,s]),S.useLayoutEffect(()=>{n?.(p,v)},[p,v,n]);const _=S.useRef(n);_.current=n,S.useEffect(()=>()=>_.current?.(!1,!1),[]);const b=S.useRef(l);b.current=l,S.useEffect(()=>{y(!1)},[e.document]);const E=S.useCallback(()=>{f(!0),y(!1);const j=k.now(),{structural:z}=e,D=w.current.size;return e.save().then(I=>{I.ok===!0?w.current.saved({size:D,structural:z,durationMs:k.now()-j}):w.current.refused(I.reason)}).finally(()=>f(!1))},[e]),T=S.useRef(!1),M=S.useRef(!1);S.useEffect(()=>{!M.current||d||(M.current=!1,g.current?.focus())},[h,d]);const O=S.useCallback(()=>{if(!t||d||T.current||!e.canUndoSave)return;T.current=!0,f(!0);const j=k.now(),z=e.lastSave?.structural??!1,D=w.current.size;return e.undoSave().then(I=>{I.ok===!0?(M.current=!0,y(!0),w.current.undone({size:D,structural:z,durationMs:k.now()-j})):w.current.undoRefused(I.reason)}).finally(()=>{T.current=!1,f(!1)})},[t,d,e]),C=S.useCallback(()=>{if(!(!t||!e.dirty||d))return E()},[t,e,d,E]),A=S.useRef(C);A.current=C;const R=S.useCallback(()=>{const j=()=>A.current();return u?u(j):j()},[u]),L=Zy({dirty:p,saving:d,canSave:!!t,save:R,onExit:()=>r?.()});Yf(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:R}:{},paused:L.dialog.open||c.paused===!0}),[c,e,t,R,L.dialog.open]));const G=!!t&&!d&&e.canUndoSave,N=e.lastSave,X={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:x,saving:d,saveButton:g,...t?{onSave:R}:{},...r?{onExit:L.requestExit}:{}};return{saving:d,save:R,exitGuard:L,...r?{done:L.saveAndExit}:{},undoSave:O,canUndoSave:G,lastSave:N,toolbarProps:X}}const ex=1;function Pf(e,t,n){const r=[];for(const s of e??[]){const o=s.name,i=s.kind;if(typeof o=="string"){if(i==="dimension"||i==="measure"){const a=s.type?.kind;r.push({name:t+o,kind:i,...a?{type:a}:{}})}else if(i==="join"&&n>0){const a=s.schema?.fields;r.push(...Pf(a,`${t}${o}.`,n-1))}}}return r}function tx(e){const t=new Map;for(const n of jf(e))t.set(n.name,Pf(n.schema?.fields,"",ex));return t}function jf(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}function Rf(e){const t=new Map;for(const n of jf(e)){const r=new Map;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const o=s.schema?.fields;if(!o||o.length===0)continue;const{groupBys:i,totals:a}=k.columnCounts(o);r.set(s.name,{shape:{groupBys:i,totals:a},...a===o.length?{aggregateOnly:!0}:{}})}t.set(n.name,r)}return t}function Af(e,t){const n=k.docOf(e.annotations),r=k.chartOf(e.annotations);return{name:e.name,...n?{description:n}:{},...r?{chart:r}:{},...t}}const Lf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function nx(e){const t=Rf(e),n=new Map;for(const r of e.sources??[]){if(!r.name)continue;const s=t.get(r.name);n.set(r.name,new Map(Lf(r).map(o=>[o.name,Af(o,s?.get(o.name))])))}return n}function ac(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const lc=(e,t)=>e!==void 0&&t.has(e),cc=e=>e.path||e.modelPath||"";function Bf(e,t=new Set){const n=[],r=new Set,s=new Map,o=new Map,i=new Map;for(const a of e){const l=cc(a);if(lc(l,t))continue;const u=k.exportedSources(a.modelInfo);o.set(a,u);for(const{name:c}of a.sources??[])c&&i.set(c,[...i.get(c)??[],l]);for(const c of u)s.set(c,[...s.get(c)??[],l])}for(const a of e){const l=cc(a);if(lc(l,t))continue;const u=tx(a),c=Rf(a);for(const d of a.sources??[]){const f=d.name;if(!f||!o.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(d.givens??[]).map(y=>y.name).filter(y=>typeof y=="string");n.push({name:f,modelPath:l,exporters:s.get(f)??[l],visibleIn:i.get(f)??[l],...k.docOf(d.annotations)?{description:k.docOf(d.annotations)}:{},views:Lf(d).map(y=>Af(y,c.get(f)?.get(y.name))),givens:h,fields:u.get(f)??[]})}}return{sources:n}}function rx({editor:e,opened:t,givens:n,catalog:r}){const[s,o]=S.useState(void 0),i=S.useMemo(()=>{const y=new Set((t.localGivens??[]).map(g=>g.name));return(n??[]).filter(g=>!y.has(g.name))},[t,n]),a=S.useMemo(()=>uh(e.document,i),[e.document,i]),l=S.useMemo(()=>new Map(e.document.sources.map(y=>[y.name,ac(r,y.base)])),[r,e.document.sources]),u=S.useCallback(y=>l.get(y.source)??ac(r,y.source),[l,r]),c=(y,g)=>{const w=[];for(const x of e.document.tiles){if(!ce(x))continue;const p=u(x);if(!p)continue;const v=new Map(p.map(_=>[_.name,_.type]));for(const _ of x.filters??[])_.given===y&&(!v.has(_.field)||!Ir(g,v.get(_.field)))&&w.push(`${_.field} on ${x.label??x.name} (${e.document.sources.find(b=>b.name===x.source)?.base??x.source})`)}return w},d=S.useMemo(()=>a.filter(y=>y.origin==="model"&&y.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:o,controlList:a,fieldsFor:u,unknownFieldsOf:c,available:d,applyFilter:(y,g,w)=>{o(void 0),e.update(x=>{w&&xh(x,w),yh(x,y,g)})},dropControl:y=>{o(void 0),e.update(g=>bh(g,y))}}}function sx(e){const{splice:t,onSave:n,structural:r,clearsHistory:s}=e,[o,i]=S.useState({stack:[e.document],index:0}),[a,l]=S.useState(e.source),[u,c]=S.useState(void 0),[d,f]=S.useState(e.document),[h,y]=S.useState(e.replaces),[g,w]=S.useState(!1),x=o.stack[o.index],p=S.useRef(o);p.current=o;const v=S.useRef(!1),[_,b]=S.useState(!1),E=I=>{v.current=I,b(I)},[T,M]=S.useState(void 0),O=S.useCallback(I=>{c(void 0),i(B=>{const q=structuredClone(B.stack[B.index]);if(I(q),JSON.stringify(q)===JSON.stringify(B.stack[B.index]))return B;const K=[...B.stack.slice(0,B.index+1),q].slice(-100);return{stack:K,index:K.length-1}})},[]),C=S.useCallback(()=>{c(void 0),i(I=>I.index>0?{...I,index:I.index-1}:I)},[]),A=S.useCallback(()=>{c(void 0),i(I=>I.index<I.stack.length-1?{...I,index:I.index+1}:I)},[]),R=S.useCallback(async(I,B)=>{try{return await t(I,B)}catch(q){return{ok:!1,reason:`Could not build the file: ${q instanceof Error?q.message:String(q)}`}}},[t]),L=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};const I={source:a,saved:d,history:p.current,replacing:h,unwritten:g},B=s?.(d,x)??!1,q=r?.(d,x)??!1;E(!0);try{const H=await R(a,x);if(io(H))return c(H.reason),{ok:!1,reason:H.reason};try{await n?.(H.source,{purpose:"save",document:x})}catch(te){const ye=`Could not save: ${te instanceof Error?te.message:String(te)}`;return c(ye),{ok:!1,reason:ye}}l(H.source),f(x),y(void 0),w(!1);const K=B?{stack:[x],index:0}:I.history;return i(te=>te===I.history?K:B?{stack:[te.stack[te.index]],index:0}:te),M(n?{before:I,after:K,lastSave:{before:h??a,after:H.source,structural:q,clearsHistory:B}}:void 0),c(void 0),{ok:!0}}finally{E(!1)}},[x,R,n,a,d,h,g,s,r]),G=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};if(!n||T===void 0||T.after!==p.current)return{ok:!1,reason:"There is no save to undo."};const{before:I}=T;E(!0);try{await n(I.replacing??I.source,{purpose:"undo",document:I.saved})}catch(B){const q=`Could not undo the save: ${B instanceof Error?B.message:String(B)}`;return c(q),{ok:!1,reason:q}}finally{E(!1)}return l(I.source),f(I.saved),y(I.replacing),w(I.unwritten||I.replacing!==void 0),i(B=>B===T.after?I.history:B),M(void 0),c(void 0),{ok:!0}},[n,T]),N=S.useMemo(()=>g||JSON.stringify(x)!==JSON.stringify(d),[x,d,g]),X=S.useMemo(()=>r?.(d,x)??!1,[x,d,r]),j=S.useMemo(()=>s?.(d,x)??!1,[x,d,s]),z=T!==void 0&&T.after===o,D=S.useCallback(async()=>{const I=await R(a,x);return io(I)?{ok:!1,reason:I.reason}:{ok:!0,source:I.source}},[x,R,a]);return{document:x,saved:d,source:a,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:N,edited:N,...u===void 0?{}:{error:u},update:O,undo:C,redo:A,save:L,preview:D,structural:X,clearsHistory:j,canUndoSave:z&&!_&&n!==void 0,...z?{lastSave:T.lastSave}:{},undoSave:G}}const ox=(e,t)=>{const n=new Set(e.tiles.map(Li)),r=new Set(t.tiles.map(Li));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function ix(e){const{visibleSources:t,...n}=e,r=S.useCallback((s,o)=>Tf(s,o,t?{visibleSources:t}:{}),[t]);return sx({...n,splice:r,structural:ox})}function ax({editorDirty:e}){const[t,n]=S.useState(!1),r=S.useRef(void 0),s=S.useRef(void 0),o=S.useMemo(()=>({setDirty:n,commitRef:r}),[]),i=S.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return S.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:o,prepare:i}}function lx({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:s,deselectTile:o}){const[i,a]=S.useState(void 0),[l,u]=S.useState(!1),[c,d]=S.useState(void 0),f=b=>{d(b),u(!0)},h=()=>u(!1),y=b=>{u(!1),e.update(E=>{th(E,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c}),t.widths&&(E.tiles=Va(E.tiles,c??E.tiles.length-1,t.columns))}),s(c??e.document.tiles.length)},g=()=>x(c),w=()=>x(void 0),x=b=>{u(!1),e.update(E=>{const T=new Set(E.tiles.filter(Ce).map(O=>O.name));let M=1;for(;T.has(`text_${M}`);)M++;E.tiles.splice(b??E.tiles.length,0,{kind:"text",name:`text_${M}`,markdown:"",...t.widths?{colspan:t.columns}:{}}),t.widths&&(E.tiles=Va(E.tiles,b??E.tiles.length-1,t.columns))}),s(b??e.document.tiles.length)};return{menu:i,setMenu:a,addingTile:l,openAdd:f,closeAdd:h,addTile:y,addText:g,appendText:w,editTile:(b,E)=>e.update(T=>{const M=T.tiles.find(O=>fe(O)===b);M&&E(M)}),removeTile:b=>{a(void 0),o(),e.update(E=>{E.tiles.splice(b,1)})},duplicate:b=>{a(void 0);const E=e.document.tiles[b],T=E&&ce(E)&&Ws(E)===void 0?b+1:void 0;e.update(M=>{nh(M,b)}),T!==void 0&&s(T)}}}const cx=k.createSvgIcon(m.jsx("path",{d:"M19 5v2h-4V5zM9 5v6H5V5zm10 8v6h-4v-6zM9 17v2H5v-2zM21 3h-8v6h8zM11 3H3v10h8zm10 8h-8v10h8zm-10 4H3v6h8z"}));function Ff({arrange:e}){const{theme:t}=be.usePublisherTheme(),[n,r]=S.useState(null),s=o=>()=>{r(null),o?.()};return m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:"Arrange tiles",children:m.jsx($.IconButton,{"aria-label":"Arrange tiles","aria-haspopup":"menu","aria-expanded":n!==null,onClick:o=>r(o.currentTarget),sx:Nr(t.ui),children:m.jsx(cx,{fontSize:"small"})})}),m.jsxs($.Menu,{anchorEl:n,open:n!==null,onClose:()=>r(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:{minWidth:260,borderRadius:t.ui.radius.menu,border:`1px solid ${k.edgeColor(t.cardBorder)}`,boxShadow:t.ui.shadow.menu}}},children:[m.jsx($.MenuItem,{disabled:!e.pack,onClick:s(e.pack),children:m.jsx($.ListItemText,{primary:"Pack tiles upward",secondary:e.pack?"Close every gap above a tile":"There are no gaps to close"})}),m.jsx($.MenuItem,{onClick:s(e.flow),children:m.jsx($.ListItemText,{primary:"Let tiles flow",secondary:"Clear each tile's place; keep its size"})})]})]})}function Ga({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:o,renderTile:i,renderViewPreview:a,controls:l,givens:u,catalog:c,toolbar:d,dashboards:f,onEvent:h,savesTo:y="package",saveLabel:g,replaces:w,modelPath:x,visibleSources:p,addFilterDisabledReason:v,fixedFilters:_,onOpenModel:b,takenGivenNames:E,onControlsChange:T,draftKey:M}){const O=ix({source:e,document:t,...n?{onSave:n}:{},...w!==void 0?{replaces:w}:{},...p?{visibleSources:p}:{}}),C=k.useReportDraft(M,O,e),A=S.useRef(null),{selected:R,descriptionSelected:L,selectTile:G,deselectTile:N,selectDescription:X,clearSelection:j,flash:z,stepEditor:D}=Yy({editor:O,gridBox:A}),I=k.layoutRules(O.document.layout,O.document.columns),{columns:B}=I,q=x?.split("/").at(-1)?.replace(/\.malloy$/,""),H=$.useMediaQuery("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),K=!I.widths||H,te=Cy({tiles:O.document.tiles,commit:V=>O.update(se=>{se.tiles=V}),onLanded:G,...I.widths&&H?{placement:{columns:B,gridBox:A}}:{}}),ye=(V,se)=>{if(O.update($e=>{$e.tiles=V}),se===void 0)return;const Me=V.findIndex($e=>fe($e)===se);Me>=0&&G(Me)},_e=I.widths,re=S.useCallback((V,se)=>_e&&k.isPlaced(V)?Rt(V,B,se):V,[_e,B]),{dragging:De}=te,ge=k.useDefaultTileSpan(A,B),ve=S.useMemo(()=>O.document.tiles.map(V=>V.colspan===void 0?{...V,colspan:ge}:V),[O.document.tiles,ge]),Ge=Dy({tiles:ve,columns:B,gridBox:A,onStart:G,commit:({index:V,edges:se,shape:Me,placed:$e,placedAll:Yt})=>{const ne=Yt??O.document.tiles,oe=ne[V];if(!oe)return;let Ue=If(oe,Me,se,$e);(se.e||se.w)&&(Ue=k.withSpan(Ue,Me.colspan,B,ge));const bt=ne.map((or,mn)=>mn===V?Ue:or);ye($e?In(Rt(bt,B,V)):bt,fe(oe))}}),Z=lx({editor:O,rules:I,modelPath:x,textHeld:p!==void 0,selectTile:G,deselectTile:N}),{menu:Xe,addingTile:ke,openAdd:ue}=Z,Oe=rx({editor:O,opened:t,givens:u,catalog:c}),{filterDialog:Ae,setFilterDialog:ie}=Oe,[qe,Ye]=S.useState(void 0),{draftDirty:P,openDraft:F,prepare:U}=ax({editorDirty:O.dirty}),Y=Ge.drag!==void 0,Se=S.useMemo(()=>({paused:Y,escape:()=>{!Xe&&!Ae&&!ke&&qe===void 0&&j()},move:(V,se)=>{if(De||R===void 0||!I.widths||!K)return!1;const Me=O.document.tiles[R];if(!Me||Me.row===void 0||Me.col===void 0)return!1;const $e=Xa(O.document.tiles,R,V,se,B);if($e.every((oe,Ue)=>oe===O.document.tiles[Ue]))return!0;const Yt=fe(Me);O.update(oe=>{oe.tiles=In(Xa(oe.tiles,R,V,se,B))});const ne=In($e).findIndex(oe=>fe(oe)===Yt);return ne>=0&&G(ne),!0},nudge:V=>{if(De||R===void 0||!I.widths||!K)return;const se=O.document.tiles[R];if(!se)return;const Me=k.nudgedSpan(se.colspan??ge,V,mc(se,B));Me!==(se.colspan??ge)&&O.update($e=>{$e.tiles[R]=k.withSpan($e.tiles[R],Me,B,ge),$e.tiles=re($e.tiles,R)})}}),[Y,ge,K,re,G,O,Xe,Ae,ke,qe,j,R,B,I,De]),we=Jy({editor:D,extraDirty:P,keepsEdits:M!==void 0&&C.keeping,prepare:U,unit:{name:"tile",count:V=>V.tiles.length},onSave:n,onDirtyChange:s,onExit:o,onChange:r,shortcuts:Se,report:Uy({size:O.document.tiles.length,path:x??"",layout:O.document.layout,savesTo:y,onEvent:h})}),ht=O.document.tiles.length===0,{toolbarProps:W}=we,Q=C.restored,Le={status:we.saving?"saving":W.dirty?"unsaved":"saved",saveTarget:g??Ko[y],...C.keptAt!==void 0?{draftKeptAt:C.keptAt}:{},...(W.dirty||Q?.pending)&&M!==void 0?{discard:C.discard}:{},...Q?{restored:Q}:{},...Q&&!Q.pending?{dismissRestored:C.dismissRestored}:{}},Be=O.document.tiles,lt=R!==void 0&&Be[R]?fe(Be[R]):void 0,he=I.widths&&K&&k.isPlaced(Be)?{...Hf(Be,B)?{pack:()=>ye(In(gc(Be,B)),lt)}:{},flow:()=>ye(qf(Be),lt)}:void 0;Ky(T,{...Le,...W.onSave?{save:W.onSave}:{},canUndo:W.canUndo,undo:W.onUndo,canRedo:W.canRedo,redo:W.onRedo,add:{...c?{tile:()=>Z.openAdd()}:{},text:Z.appendText,...v!==void 0?{filterUnavailable:v}:ht?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>ie({})}},...W.onExit?{exit:W.onExit}:{},...we.done?{done:we.done}:{},...Q?.pending?{restore:C.restoreOffered}:{},...he?{arrange:he}:{}});const tt=T?void 0:m.jsx(Qf,{...we.toolbarProps,...d?{actions:d}:{},...c?{onAddTile:()=>ue()}:{},...he?{arrange:m.jsx(Ff,{arrange:he})}:{},savesTo:y,...g?{saveLabel:g}:{},...M!==void 0&&W.onSave?{saveStatus:Le}:{}});return m.jsx(Hu.Provider,{value:F,children:m.jsx($.Stack,{className:k.reportClasses.builder,"data-saves-to":y,sx:{gap:0,mx:`-${Go}px`},children:m.jsxs(k.ReportPage,{layout:I.layout,sx:{px:`${Go}px`,pb:`${Go}px`},header:m.jsx(qy,{editor:O,documentSlug:q,actions:tt,descriptionSelected:L,selectDescription:X}),controls:ht?void 0:m.jsx(Vy,{controls:Oe.controlList,unknownFieldsOf:Oe.unknownFieldsOf,onEdit:V=>ie({control:V}),onAdd:()=>ie({}),...v?{addDisabledReason:v}:{},onRemove:Oe.dropControl,..._?{fixedFilters:_}:{},...b?{onOpenModel:b}:{},...O.document.startingGivens?{startingValues:O.document.startingGivens}:{},onStartingValue:(V,se)=>O.update(Me=>{const $e={...Me.startingGivens??{}};se===void 0?delete $e[V]:$e[V]=se,Object.keys($e).length>0?Me.startingGivens=$e:delete Me.startingGivens}),children:l}),children:[ht&&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."}),c&&m.jsx($.Button,{size:"small",startIcon:m.jsx(k.AddIcon,{}),onClick:()=>ue(),children:"Add tile"})]}),Q?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:C.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:C.discard,children:"Discard"})]}),children:`You have unsaved edits from ${qo(Q.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),O.error&&m.jsx($.Alert,{severity:"warning",children:O.error}),!K&&m.jsx($.Alert,{severity:"info",children:"This window is too narrow for the grid, so tiles stack in one column, as on a phone. Widen it to move tiles or change their width."}),m.jsx(zy,{editor:O,arrange:K,reorder:te,edging:Ge,place:re,gridBox:A,defaultSpan:ge,rules:I,canAdd:!!c,selected:R,flash:z,menuIndex:Xe?.index,onSelect:G,onOpenMenu:(V,se)=>{G(se),Z.setMenu({anchor:V,index:se})},onRemove:Z.removeTile,...O.document.tiles.length===1&&O.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:ue,editTile:Z.editTile,...i?{renderTile:i}:{}}),m.jsx(jh,{editor:O,catalog:c,columns:B,dashboards:f,bindings:Oe,tiles:Z,drillSource:qe,setDrillSource:Ye,exitDialog:we.exitGuard.dialog,...a?{renderViewPreview:a}:{},...E?{takenGivenNames:E}:{}})]})})})}const dx=k.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),ux=k.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"})),fx=k.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function hx({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=be.usePublisherTheme(),o=k.edgeColor(s.cardBorder),i=k.hoverEdgeColor(s.cardBorder,s.tileTitle),[a,l]=S.useState(null),u=e?.save!==void 0&&e.status!=="saved",c=e?.done??n,d=u&&e?.done===void 0,f=e?.add,h=f!==void 0&&(f.tile!==void 0||f.text!==void 0||f.filter!==void 0||f.filterUnavailable!==void 0),y=g=>()=>{l(null),g?.()};return m.jsxs($.Stack,{direction:"row",role:"toolbar",className:k.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(xc,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${cn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:Nr(s.ui),children:m.jsx(yc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${cn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:Nr(s.ui),children:m.jsx(vc,{fontSize:"small"})})})}),e.arrange&&m.jsx(Ff,{arrange:e.arrange}),h&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),h&&m.jsxs(m.Fragment,{children:[m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(k.AddIcon,{}),endIcon:m.jsx(k.ExpandMoreIcon,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:g=>l(g.currentTarget),sx:{...Mr(o,i),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs($.Menu,{anchorEl:a,open:a!==null,onClose:()=>l(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:px(o,s.ui)}},MenuListProps:{sx:{p:.5}},children:[f?.tile&&m.jsx(Ho,{icon:m.jsx(ux,{}),title:"Tile",detail:"A chart or table from the model",onClick:y(f.tile)}),f?.text&&m.jsx(Ho,{icon:m.jsx(fx,{}),title:"Text",detail:"Prose between the tiles",onClick:y(f.text)}),(f?.filter||f?.filterUnavailable)&&m.jsx(Ho,{icon:m.jsx(dx,{}),title:"Filter",detail:f.filterUnavailable??"A control the tiles read",disabled:f.filter===void 0,onClick:y(f.filter)})]})]})]})]}),(c||d)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),c&&m.jsx($.Tooltip,{enterDelay:800,enterNextDelay:800,title:e?.done&&u?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx($.Button,{variant:d?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:c,sx:{...Mr(o,i,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&d&&m.jsx($.Tooltip,{title:`Save (${cn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...Mr(o,i,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const px=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Ho({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:o}=be.usePublisherTheme(),i=o.ui;return m.jsxs($.MenuItem,{onClick:s,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:i.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:i.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:o.accent,bgcolor:`color-mix(in srgb, ${o.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx($.Box,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs($.Box,{className:"add-text",sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...i.type.control,fontWeight:i.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx($.Box,{sx:{...i.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function gx(e,t,n=new Set,r=new Map){const s=[];for(const c of e.tiles){if(!ce(c))continue;const d=(c.filters??[]).map(h=>h.given),f=r.get(Dt(`${c.source} -> ${c.name}`))??[];for(const h of f)(n.has(h)||d.includes(h))&&s.push(h);s.push(...d)}const o=new Set(s),i=t.flatMap(c=>c.name!==void 0&&n.has(c.name)&&!o.has(c.name)?[c.name]:[]),a=new Map((e.localGivens??[]).map(c=>[c.name,c])),l=new Map(t.flatMap(c=>c.name===void 0?[]:[[c.name,c]])),u=[];for(const c of new Set([...i,...s])){const d=a.get(c),f=d?k.localGivenSpec(d):l.get(c);f&&u.push(f)}return u}function mx(e,t,n){const r=new Map;for(const o of t.tiles)ce(o)&&r.set(Dt(dt(o)),new Set((o.filters??[]).map(i=>i.given)));const s=new Set;for(const o of e.tiles){if(!ce(o))continue;const i=Dt(dt(o)),a=r.get(i);for(const l of n.get(i)??[])a?.has(l)||s.add(l)}return s}function vx(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function yx(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function Dt(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function xx(e,t,n,r){const s=new Set(t.sources.map(a=>a.name)),o=new Set(e.sources.map(a=>a.name).filter(a=>!s.has(a)));return o.size===0?void 0:{sources:o,modelOf:a=>{if(r)return;const l=e.imports.find(c=>c.kind==="names"&&c.names.includes(a));if(l===void 0)return;const u=k.resolvedOf(l.from,n);return k.reaches(t,a,u,n)?void 0:u}}}function bx(e,t,n){if(!n||t.declaration.kind!=="reference")return;let r=t.source,s=t.declaration.from;if(r===void 0||!n.sources.has(r))return;const o=e.tiles.length+e.sources.length;for(let i=0;i<=o;i++){if(!n.sources.has(r)){const u=n.modelOf?.(r);return{source:r,view:s,...u?{modelPath:u}:{}}}const a=e.sources.find(u=>u.name===r);if(!a||a.scopedBy?.length)return;const l=e.tiles.find(u=>ce(u)&&u.source===r&&u.name===s);if(!l)r=a.base;else if(l.declaration.kind==="reference")s=l.declaration.from;else return}}function wx(e,t,n,r=new Map,s,o){if(Hn(t))return{expression:dt(t),givenNames:void 0,reads:s&&[...s]};const i=bx(e,t,o),a=i?.source??t.source,l=i?.view??(t.declaration.kind==="reference"?t.declaration.from:t.name),u=i?.modelPath!==void 0?new Set:n,c=new Map((e.localGivens??[]).map(b=>[b.name,b.type])),d=new Map((e.localGivens??[]).map(b=>[b.name,b.default])),f=e.sources.find(b=>b.name===a)?.scopedBy??[],h=new Set([...f,...s??[]].filter(b=>u.has(b))),y=new Set([...f,...s??[]]),g=[];for(const b of t.filters??[]){const E=`where: ${me.malloyPath(b.field)} ${b.op??"~"}`;if(u.has(b.given)){h.add(b.given),y.add(b.given),g.push(`${E} $${b.given}`);continue}if(!c.has(b.given))continue;y.add(b.given);const T=k.malloyLiteral(r.get(b.given),c.get(b.given))??vx(d.get(b.given));T!==void 0&&g.push(`${E} ${T}`)}const w=g.join(", "),x=t.chart,p=x==="none"||k.isChartPick(x)?k.chartLineText(x,t.chartCarried):x==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
143
|
`):x==="default"&&yx(t.declaration)?k.chartResetLine():void 0,v=t.color!==void 0?k.seriesColorLine(t.color):t.declaration.kind!=="reference"&&!t.ownPalette?k.seriesColorResetLine:void 0,_=[p,v].filter(Boolean).join(`
|
|
144
|
-
`)||void 0;return{..._?{annotation:_}:{},...i?.modelPath!==void 0?{modelPath:i.modelPath}:{},expression:`${a} -> ${l}`+(w?` + { ${w} }`:""),givenNames:Array.from(h),reads:s||y.size>0?Array.from(y):void 0}}function _x({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:o}){const{apiClients:i,server:a}=be.useServer(),{data:l}=k.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await i.models.listModels(e,t,n)).data.flatMap(y=>y.path&&!y.error?[y.path]:[])}),u=S.useMemo(()=>new Set([r,...s.flatMap(y=>y.path?[y.path]:[])]),[s,r]),c=S.useMemo(()=>o?(l??[]).filter(y=>!u.has(y)):[],[l,u,o]),d=uc.useQueries({queries:c.map(y=>({queryKey:["report-editor-model",e,t,y,n,a],queryFn:async()=>(await i.models.getModel(e,t,y,n)).data,retry:!1}))}),f=l!==void 0&&o&&d.every(y=>y.isSuccess||y.isError),h=d.map(y=>y.dataUpdatedAt).join();return S.useMemo(()=>f?Bf(d.flatMap((y,g)=>y.data?[{...y.data,path:c[g]}]:[]),u):void 0,[f,c,h,u])}const kx={};function Sx({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:s,queryVersionId:o,opened:i,replaces:a,onSave:l,onDirtyChange:u,onExit:c,onOpenModel:d,onControlsChange:f,draftKey:h,onEvent:y,savesTo:g,saveLabel:w,note:x,fileModel:p}){const{apiClients:v}=be.useServer(),[_,b]=S.useState(i.document.tiles.length>0);S.useEffect(()=>b(i.document.tiles.length>0),[i.generation,i.document]);const{data:E,isSuccess:T,isError:M}=k.useQueryWithApiError({...k.reportQueryOptions(v,{environmentName:t,packageName:n,path:r,versionId:o},k.BUILDER_HANDOFF_STALE_MS),enabled:_&&!e}),O=e?.modelPath??r,C=Tx(i.source,e?.compileSource),A=k.useCompiledDocument({environmentName:t,packageName:n,modelPath:O,source:C.text??i.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&C.text!==void 0}),R=A.data?.document,L=e?A.isSuccess?R?.manifest??kx:void 0:E,G=e?A.isSuccess:T,N=e?A.isError||C.problem!==void 0:M,X=e?k.documentPreamble(R?.cells):void 0,P=(A.data?.result.problems??[]).filter(W=>W.severity==="error"),z=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),D=e?.givens,I=S.useMemo(()=>new Set((L?.tiles??[]).flatMap(W=>W.restricted&&W.query?[Dt(W.query)]:[])),[L]),{reports:B,settled:q}=k.useReportListing(t,n,o),H=S.useMemo(()=>B.map(W=>W.path).filter(W=>!!W&&W!==r&&W.endsWith(".malloy")).map(W=>W.replace(/\.malloy$/,"")),[B,r]),K=_x({environmentName:t,packageName:n,...o!==void 0?{versionId:o}:{},modelPath:r,reports:B,reportsSettled:q}),te=S.useMemo(()=>e?(K?.sources??[]).filter(W=>(W.visibleIn??W.exporters??[W.modelPath]).includes(O)).map(W=>W.name):void 0,[K,e,O]),ye=S.useMemo(()=>p?nx(p):void 0,[p]),_e=S.useMemo(()=>{const W=K&&te?{sources:K.sources.filter(Q=>te.includes(Q.name))}:K;return W&&ye?{...W,documentViews:ye}:W},[K,te,ye]),[re,De]=S.useState(i.document);S.useEffect(()=>De(i.document),[i.document]);const ge=S.useMemo(()=>l&&(async(W,Q)=>{await l(W,Q.document.layout),g==="package"&&b(Q.document.tiles.length>0)}),[l,g]),ve=S.useMemo(()=>(L?.givens??[]).filter(W=>!(e&&W.secure===!0)&&!(W.name!==void 0&&z.has(W.name))),[L,z,e]),Ge=S.useMemo(()=>new Set([...ve.map(W=>W.name).filter(W=>W!==void 0),...Object.keys(D??{})]),[ve,D]),Z=S.useMemo(()=>new Map((L?.tiles??[]).flatMap(W=>W.kind!=="text"&&W.query&&W.givenNames?[[Dt(W.query),W.givenNames]]:[])),[L]),Xe=S.useMemo(()=>new Map((L?.tiles??[]).flatMap(W=>W.kind!=="text"&&W.query&&W.label?[[Dt(W.query),W.label]]:[])),[L]),ke=S.useMemo(()=>mx(re,i.document,Z),[re,i.document,Z]),ue=S.useMemo(()=>gx(re,ve,ke,Z),[re,ve,ke,Z]),Oe=S.useMemo(()=>{const W=new Set(re.tiles.flatMap(he=>ce(he)?(he.filters??[]).map(tt=>tt.given):[])),Q=new Set((re.localGivens??[]).map(he=>he.name)),Le=[...new Set(re.imports.map(he=>he.from))],Be=Le.length===1?Ex(r,Le[0]):Le.length===0&&e?e.modelPath:void 0,lt=he=>{const tt=re.sources.filter(V=>V.scopedBy?.includes(he)).map(V=>V.name);return tt.length>0?{reason:`Applied to every tile on ${tt.join(", ")} by this report's own source. Edit the file to change it.`}:Q.has(he)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:Be!==void 0?{reason:`Set in the model ${Be}. Edit the model to change it.`,modelPath:Be}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...ke].filter(he=>!W.has(he)).map(he=>[he,lt(he)]))},[re,ke,e,r]),{declaredTypes:Ae,applied:ie,panel:qe}=k.useDocumentControls({specs:ue,loaded:G,startingValues:L?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:L?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?O:L?.path,versionId:o,documentName:r,...X!==void 0?{preamble:X}:{},...D?{hostGivens:D}:{}}),Ye=S.useMemo(()=>k.missingRequiredGivens(ue,ie,D),[ue,ie,D]),j=S.useMemo(()=>Object.fromEntries(Object.entries(D??{}).filter(([W])=>!Ae.has(W))),[D,Ae]),F=!_||G||N,U=e!==void 0&&(C.problem!==void 0||A.isError||P.length>0),Y=S.useMemo(()=>new Map(i.document.tiles.map(W=>[fe(W),W])),[i.document]),Se=S.useMemo(()=>xx(re,i.document,r,!!e),[re,i.document,r,e]),we=S.useMemo(()=>function(Q,Le,Be="card"){const lt=(Hn(Q)?Xe.get(Dt(dt(Q))):void 0)??co(Q);if(U)return m.jsxs(k.TileCard,{chrome:Be,children:[m.jsx(k.TileHeading,{title:Le?.title??lt,subtitle:Le?Le.subtitle:Q.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!F)return m.jsxs(k.TileCard,{chrome:Be,children:[m.jsx(k.TileHeading,{title:Le?.title??lt,subtitle:Le?Le.subtitle:Q.subtitle}),m.jsx(k.Loading,{text:"Running…"})]});const he=Z.get(Dt(dt(Q))),V=X===void 0&&he!==void 0&&$x(Y.get(fe(Q)),Q)?{expression:dt(Q),givenNames:[...he],reads:[...he]}:wx(re,Q,Ge,ie,he,Se),se=k.layoutRules(re.layout,re.columns);return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:V.modelPath??O,...X!==void 0&&V.modelPath===void 0?{preamble:X}:{},...I.has(Dt(dt(Q)))?{restricted:!0}:{},tile:V.expression,...V.annotation?{annotation:V.annotation}:{},label:lt,chrome:Be,subtitle:Q.subtitle,...Le?{heading:Le}:{},borderless:Q.borderless,givens:ie,hostGivens:j,declaredTypes:Ae,givenNames:V.givenNames,...(()=>{const Me=k.waitingOn(Ye,V.reads??V.givenNames);return Me.length>0?{waitingFor:k.waitingText(Me)}:{}})(),ignoredFilters:k.tileIgnoredFilterLabels(V.reads,ue),height:Q.rowspan!==void 0||k.isPlaced(re.tiles)?k.tileHeightPx(Q.rowspan??k.PLACED_DEFAULT_ROWSPAN.query):se.tileMaxHeight,tableMaxHeight:se.tableMaxHeight,fixedHeight:Q.rowspan!==void 0||k.isPlaced(re.tiles)})},[re,Y,F,U,Ye,Ge,Z,Xe,t,n,o,O,X,Se,I,ie,j,Ae,ue]),ht=S.useMemo(()=>function(Q){return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:Q.modelPath,tile:`${Q.base} -> ${Q.view}`,...Q.chart?{annotation:k.chartLineText(Q.chart,Q.chartCarried)}:{},label:Q.label,borderless:!0,givens:ie,hostGivens:j,declaredTypes:Ae,givenNames:Q.givens,height:200})},[t,n,o,ie,j,Ae]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&P.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",P.map(W=>W.message).join("; ")]}),Ye.length>0&&!U&&m.jsx($.Alert,{severity:"info",children:k.requiredPrompt(Ye)}),e&&C.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",C.problem]}),e&&A.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",A.error?.message]}),m.jsx(Ga,{...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:Oe,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:we,renderViewPreview:ht,givens:ue.filter(W=>W.name!==void 0).map(W=>({name:W.name,...W.label?{label:W.label}:{},...W.type?{type:W.type}:{},...W.suggest?.dimension?{field:W.suggest.dimension}:{}})),onChange:De,onDirtyChange:u,...c?{onExit:c}:{},...d?{onOpenModel:d}:{},...f?{onControlsChange:f}:{},...h!==void 0?{draftKey:h}:{},..._e?{catalog:_e}:{},dashboards:H,...y?{onEvent:y}:{},controls:G?m.jsx(k.GivensPanel,{...qe,layout:"bar"}):void 0,...ge?{onSave:ge}:{},savesTo:g,...w?{saveLabel:w}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:te}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:x})})]})}function $x(e,t){return e!==void 0&&JSON.stringify(dc(e))===JSON.stringify(dc(t))}function dc(e){const{label:t,subtitle:n,colspan:r,break:s,rowspan:o,row:i,col:a,borderless:l,...u}=e;return u}function Tx(e,t){const n=S.useRef(t);n.current=t;const r=t!==void 0,[s,o]=S.useState();return S.useEffect(()=>{if(!r)return;let i=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{i&&o({from:e,text:a})},a=>{i&&o({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{i=!1}},[e,r]),r?s?.from!==e?{}:s.problem!==void 0?{problem:s.problem}:{text:s.text}:{text:e}}function Ex(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 Cx({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:o}){const[i,a]=S.useState(void 0),[l,u]=S.useState(void 0),[c,d]=S.useState(e===void 0),[f,h]=S.useState(!1),[y,g]=S.useState(void 0);return S.useEffect(()=>{if(!e)return;let w=!1;return g(void 0),(async()=>{try{const x=k.chooseWorkspace(await e.listWorkspaces(!1));if(w)return;if(a(x),x!==void 0&&(!n||x.authoritative)){const p=await e.getDocument(k.locatorFor(t,x.name,r,s,o)).catch(v=>{if(!k.isDocumentNotFound(v))throw v});if(w)return;u(p),h(p!==void 0)}}catch(x){if(w)return;g(k.storageErrorMessage(x))}w||d(!0)})(),()=>{w=!0}},[e,t,n,r,s,o]),{workspace:i,draft:l,setDraft:u,draftChecked:c,offered:f,setOffered:h,readFailure:y}}const Ox=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Mx(e){const t=await oo(e);return so(t)?{ok:!1,reason:Ox(t.reason,t.line)}:{ok:!0,document:t.document}}const Ix="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Dx="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function jx({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:o,packageSettled:i,modelPath:a,layout:l,notebook:u,noun:c,legacyFormat:d,textHeld:f,startedAt:h,onEventRef:y}){const g=S.useRef({path:a,layout:l});g.current={path:a,layout:l};const w=S.useRef((ue,Oe)=>{try{y.current?.(k.withReportContext(ue,{...g.current,...Oe?{layout:Oe}:{}}))}catch{}}),x=e?.authoritative===!0,p=x&&r!==void 0,[v,_]=S.useState(void 0),b=(x||v===!0)&&t!==void 0,[E,T]=S.useState(void 0),[M,O]=S.useState(d?Ix:void 0),C=S.useRef(void 0),A=S.useRef(void 0),[R,L]=S.useState(void 0),G=S.useRef(o);G.current=o;const N=R!==void 0&&R.onFetch===o?R.text:s,X=S.useRef(N);X.current=N;const P=b?t:N,[z,D]=S.useState(!1),[I,B]=S.useState(void 0),[q,H]=S.useState(void 0),K=P!==void 0&&P!==q,te=E?.source,_e=K&&(z||!x&&t!==void 0&&te===t&&t!==N)&&te!==void 0&&P!==I,re=_e?te:K?P:te??P,De=_e?P:void 0,ge=S.useRef(te);ge.current=te;const ve=S.useRef(P);ve.current=P;const Ge=S.useRef("package");Ge.current=b?x?"record":"draft":"package",S.useEffect(()=>{if(re===void 0||!n||p||re===ge.current)return;let ue=!1;const Oe=X.current,Ae=ve.current;return Mx(re).then(ie=>{if(!ue){if(ie.ok===!1){O(ie.reason),w.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}O(void 0),C.current=void 0,A.current=Oe,L(void 0),B(void 0),H(Ae),T(qe=>({source:re,document:ie.document,...Oe!==void 0?{packageText:Oe}:{},generation:(qe?.generation??0)+1})),w.current({type:"report.opened",surface:"edit",from:Ge.current,tiles:ie.document.tiles.length,durationMs:k.now()-h.current},ie.document.layout)}}).catch(ie=>{if(ue)return;const qe=`Could not read the ${c}: ${ie instanceof Error?ie.message:String(ie)}`;O(qe),w.current({type:"report.load_failed",surface:"edit",category:k.failureCategory(ie)})}),()=>{ue=!0}},[re,a,n,p,u,c,f,h]),S.useEffect(()=>{d&&w.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[d]),S.useEffect(()=>{!f||!n||E||r!==void 0||(x?t===void 0&&O("the host's storage has no document at this location."):O("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,E,r,x,t]);const Z=u&&!f&&!E&&n&&!b&&i&&s===void 0;return S.useEffect(()=>{Z&&(O(Dx),w.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Z]),{authoritative:x,blockedOnRecord:p,resume:v,setResume:_,fromDraft:b,opened:E,setOpened:T,openError:M,savedHashRef:C,packageBaseRef:A,setWrote:L,fetchedAtRef:G,setDirty:D,setSeen:H,held:De,choose:ue=>{h.current=k.now(),B(ue?t:N),_(ue)},acceptHeld:()=>{h.current=k.now(),B(De)}}}function Px({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:o,modelPath:i,versionId:a,apiClients:l,queryClient:u,mutable:c,textHeld:d,readFailure:f,authoritative:h,resume:y,setResume:g,setOpened:w,setDraft:x,setOffered:p,setSeen:v,setWrote:_,savedHashRef:b,packageBaseRef:E,fetchedAtRef:T}){const M=S.useCallback(I=>t===void 0?void 0:k.locatorFor(I,t.name,s,o,i),[t,s,o,i]),O=M(n),C=S.useCallback(async(I,B=n)=>{const q=M(B);if(!e||!q)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(q,I),w(H=>H&&{...H,source:I}),x(I),(h||y===!0)&&v(I),h||g(H=>H??!1)},[e,M,n,h,y,w,x,v,g]),[A,R]=S.useState(void 0),L=S.useCallback(async I=>{const B=await k.expectedHashFor(b.current,E.current);if(B===void 0)throw new Error("The package file is still loading; try again.");const q=["dashboard-editor-model",s,o,i,a,r];await k.writePackageFile({apiClients:l,queryClient:u,environmentName:s,packageName:o,modelPath:i,source:I,expectedHash:B,invalidateOnError:[q],afterWrite:async H=>{if(w(K=>K&&{...K,source:I}),_({text:I,onFetch:T.current}),v(I),b.current=H,R(void 0),e&&O)try{await e.deleteDocument(O),x(void 0),p(!1)}catch(K){k.isDocumentNotFound(K)?(x(void 0),p(!1)):R(k.storageErrorMessage(K))}g(!1)},invalidate:[{queryKey:q,wait:!0},{queryKey:k.modelResultsKey({environmentName:s,packageName:o,versionId:a,modelPath:i})}]}),k.invalidateReportQueries(u,s,o,i)},[l,s,o,i,a,r,e,O,u,b,E,T,w,_,v,x,p,g]),G=t?.writeable===!0,N=c===!0&&!d,{savesTo:X,pinnedPackageSave:P,writer:z}=k.saveTarget({authoritative:h,mutable:N,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!O&&G&&(!r||h),readFailed:f!==void 0});return{save:z==="storage"?C:z==="package"?L:void 0,savesTo:X,writer:z,pinnedPackageSave:P,takesWrites:N,supersedeFailure:A}}function Ha(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:o,onControlsChange:i,keepDraft:a,kind:l,path:u,textSource:c,queryVersionId:d}=e,f=e.layout??(l?k.layoutOfKind(l):"grid"),h=f==="linear",y=c!==void 0,{environmentName:g,packageName:w,versionId:x,namesBoth:p}=k.resolveEditorTarget(e),_=("resourceUri"in e?e.dashboard:e.dashboardName)??k.documentSlug(u)??"",b="report",{apiClients:E,mutable:T,isLoadingStatus:M,server:O}=be.useServer(),C=uc.useQueryClient(),A=S.useRef(k.now()),R=S.useRef(t);R.current=t;const L=S.useRef(r);L.current=r;const G=k.useOptionalDocumentStorage()?.documentStorage,N=u??k.legacyNamedPath(l??"dashboard",_),X=/\.malloynb$/i.test(N)||h&&/\.malloynb$/i.test(_),P=k.useQueryWithApiError({queryKey:["dashboard-editor-model",g,w,N,x,h],queryFn:()=>E.models.getModel(g,w,N,x,h?!0:void 0),enabled:p&&!X&&!y}),z=P.data?.data?.sourceText,{workspace:D,draft:I,setDraft:B,draftChecked:q,offered:H,setOffered:K,readFailure:te}=Cx({storage:G,layout:f,notebook:h,environmentName:g,packageName:w,modelPath:N}),{authoritative:ye,blockedOnRecord:_e,resume:re,setResume:De,fromDraft:ge,opened:ve,setOpened:Ge,openError:Z,savedHashRef:Xe,packageBaseRef:ke,setWrote:ue,fetchedAtRef:Oe,setDirty:Ae,setSeen:ie,held:qe,choose:Ye,acceptHeld:j}=jx({workspace:D,draft:I,draftChecked:q,readFailure:te,packageText:z,fetchedAt:P.dataUpdatedAt,packageSettled:P.isSuccess&&!P.isFetching,modelPath:N,layout:f,notebook:h,noun:b,legacyFormat:X,textHeld:y,startedAt:A,onEventRef:R}),{save:F,savesTo:U,writer:Y,pinnedPackageSave:Se,takesWrites:we,supersedeFailure:ht}=Px({storage:G,workspace:D,layout:f,notebook:h,environmentName:g,packageName:w,modelPath:N,versionId:x,apiClients:E,queryClient:C,mutable:T,textHeld:y,readFailure:te,authoritative:ye,resume:re,setResume:De,setOpened:Ge,setDraft:B,setOffered:K,setSeen:ie,setWrote:ue,savedHashRef:Xe,packageBaseRef:ke,fetchedAtRef:Oe}),W=D?.name,Q=S.useCallback(ne=>{R.current?.(k.withWorkspace(ne,W))},[W]),Le=P.isError&&!ve,Be=S.useRef(!1);S.useEffect(()=>{!Le||Be.current||(Be.current=!0,k.reportEmitter({path:N,layout:f},R.current).emit({type:"report.load_failed",surface:"edit",category:k.failureCategory(P.error)}))},[Le,P.error,N,f]);const lt=S.useCallback((ne,oe)=>{Ae(ne),L.current?.(oe)},[Ae]),he=!c&&P.data?.data&&z!==void 0&&ve?.source===z?P.data.data:void 0,tt=a?k.reportDraftKey({server:O,environmentName:g,packageName:w,versionId:x,path:u??_}):void 0,V=U==="host"&&D?.description?D.description:void 0,se=!ye&&!y&&T===void 0?M?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":k.saveCaption({authoritative:ye,mutable:we,pinnedPackageSave:Se,...D?{workspace:D}:{},...te!==void 0?{readFailure:te}:{},...x!==void 0?{versionId:x}:{}}),$e=U==="package"&&we===!0&&!Se&&te===void 0||se===V?"":se;if(!p&&"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(P.isError&&!ve)return m.jsx(k.ApiErrorDisplay,{error:P.error,context:`Opening the ${b}`});if(!ve&&(!(y||z)||!q))return n??m.jsx(k.Loading,{text:`Opening the ${b}…`});if(_e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",te]});const Yt=I!==void 0&&I!==z;return m.jsxs($.Stack,{sx:{gap:2},children:[P.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",P.error?.message,". Your edits are still here."]}),!h&&!ye&&H&&Yt&&re===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Ye(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Ye(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),qe!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{tt!==void 0&&k.clearReportDraft(tt),j()},children:"Load it"}),children:U==="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.":U==="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."}),ht!==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:"," ",ht]}),!ve&&(n??m.jsx(k.Loading,{text:`Opening the ${b}…`})),ve&&m.jsx(Sx,{environmentName:g,packageName:w,modelPath:N,...c?{textSource:c}:{},slug:_,...x!==void 0?{versionId:x}:{},...(d??x)!==void 0?{queryVersionId:d??x}:{},opened:ve,...ge&&Y==="package"&&ve.packageText!==void 0?{replaces:ve.packageText}:{},onSave:F,onDirtyChange:lt,...s?{onExit:s}:{},...o?{onOpenModel:o}:{},...i?{onControlsChange:i}:{},...tt!==void 0?{draftKey:tt}:{},savesTo:U,...V?{saveLabel:V}:{},...t?{onEvent:Q}:{},note:$e,...he?{fileModel:he}:{}},ve.generation)]})}const Rx=Ha,Ax=Ga;function Lx(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,o="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(Ha,{...o,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=k.MAX_SLUG_ATTEMPTS;exports.createDocument=k.createDocument;exports.createRoute=k.createRoute;exports.locatorFor=k.locatorFor;exports.newDashboardSource=k.newDashboardSource;exports.newDocumentProblem=k.newDocumentProblem;exports.newNotebookSource=k.newNotebookSource;exports.reportPathFor=k.reportPathFor;exports.reportPathForTitle=k.reportPathForTitle;exports.slugFor=k.slugFor;exports.slugOrFallback=k.slugOrFallback;exports.useDocumentChoices=k.useDocumentChoices;exports.BuilderBar=hx;exports.DashboardBuilder=Ax;exports.DashboardEditor=Rx;exports.NotebookEditor=Lx;exports.ReportBuilder=Ga;exports.ReportEditor=Ha;exports.buildCatalog=Bf;exports.readDashboardDocument=oo;exports.readFailed=so;exports.readReportTagOfText=Bv;exports.spliceDashboardDocument=Tf;exports.spliceFailed=io;
|
|
144
|
+
`)||void 0;return{..._?{annotation:_}:{},...i?.modelPath!==void 0?{modelPath:i.modelPath}:{},expression:`${a} -> ${l}`+(w?` + { ${w} }`:""),givenNames:Array.from(h),reads:s||y.size>0?Array.from(y):void 0}}function _x({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:o}){const{apiClients:i,server:a}=be.useServer(),{data:l}=k.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await i.models.listModels(e,t,n)).data.flatMap(y=>y.path&&!y.error?[y.path]:[])}),u=S.useMemo(()=>new Set([r,...s.flatMap(y=>y.path?[y.path]:[])]),[s,r]),c=S.useMemo(()=>o?(l??[]).filter(y=>!u.has(y)):[],[l,u,o]),d=uc.useQueries({queries:c.map(y=>({queryKey:["report-editor-model",e,t,y,n,a],queryFn:async()=>(await i.models.getModel(e,t,y,n)).data,retry:!1}))}),f=l!==void 0&&o&&d.every(y=>y.isSuccess||y.isError),h=d.map(y=>y.dataUpdatedAt).join();return S.useMemo(()=>f?Bf(d.flatMap((y,g)=>y.data?[{...y.data,path:c[g]}]:[]),u):void 0,[f,c,h,u])}const kx={};function Sx({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:s,queryVersionId:o,opened:i,replaces:a,onSave:l,onDirtyChange:u,onExit:c,onOpenModel:d,onControlsChange:f,draftKey:h,onEvent:y,savesTo:g,saveLabel:w,note:x,fileModel:p}){const{apiClients:v}=be.useServer(),[_,b]=S.useState(i.document.tiles.length>0);S.useEffect(()=>b(i.document.tiles.length>0),[i.generation,i.document]);const{data:E,isSuccess:T,isError:M}=k.useQueryWithApiError({...k.reportQueryOptions(v,{environmentName:t,packageName:n,path:r,versionId:o},k.BUILDER_HANDOFF_STALE_MS),enabled:_&&!e}),O=e?.modelPath??r,C=Tx(i.source,e?.compileSource),A=k.useCompiledDocument({environmentName:t,packageName:n,modelPath:O,source:C.text??i.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&C.text!==void 0}),R=A.data?.document,L=e?A.isSuccess?R?.manifest??kx:void 0:E,G=e?A.isSuccess:T,N=e?A.isError||C.problem!==void 0:M,X=e?k.documentPreamble(R?.cells):void 0,j=(A.data?.result.problems??[]).filter(W=>W.severity==="error"),z=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),D=e?.givens,I=S.useMemo(()=>new Set((L?.tiles??[]).flatMap(W=>W.restricted&&W.query?[Dt(W.query)]:[])),[L]),{reports:B,settled:q}=k.useReportListing(t,n,o),H=S.useMemo(()=>B.map(W=>W.path).filter(W=>!!W&&W!==r&&W.endsWith(".malloy")).map(W=>W.replace(/\.malloy$/,"")),[B,r]),K=_x({environmentName:t,packageName:n,...o!==void 0?{versionId:o}:{},modelPath:r,reports:B,reportsSettled:q}),te=S.useMemo(()=>e?(K?.sources??[]).filter(W=>(W.visibleIn??W.exporters??[W.modelPath]).includes(O)).map(W=>W.name):void 0,[K,e,O]),ye=S.useMemo(()=>p?nx(p):void 0,[p]),_e=S.useMemo(()=>{const W=K&&te?{sources:K.sources.filter(Q=>te.includes(Q.name))}:K;return W&&ye?{...W,documentViews:ye}:W},[K,te,ye]),[re,De]=S.useState(i.document);S.useEffect(()=>De(i.document),[i.document]);const ge=S.useMemo(()=>l&&(async(W,Q)=>{await l(W,Q.document.layout),g==="package"&&b(Q.document.tiles.length>0)}),[l,g]),ve=S.useMemo(()=>(L?.givens??[]).filter(W=>!(e&&W.secure===!0)&&!(W.name!==void 0&&z.has(W.name))),[L,z,e]),Ge=S.useMemo(()=>new Set([...ve.map(W=>W.name).filter(W=>W!==void 0),...Object.keys(D??{})]),[ve,D]),Z=S.useMemo(()=>new Map((L?.tiles??[]).flatMap(W=>W.kind!=="text"&&W.query&&W.givenNames?[[Dt(W.query),W.givenNames]]:[])),[L]),Xe=S.useMemo(()=>new Map((L?.tiles??[]).flatMap(W=>W.kind!=="text"&&W.query&&W.label?[[Dt(W.query),W.label]]:[])),[L]),ke=S.useMemo(()=>mx(re,i.document,Z),[re,i.document,Z]),ue=S.useMemo(()=>gx(re,ve,ke,Z),[re,ve,ke,Z]),Oe=S.useMemo(()=>{const W=new Set(re.tiles.flatMap(he=>ce(he)?(he.filters??[]).map(tt=>tt.given):[])),Q=new Set((re.localGivens??[]).map(he=>he.name)),Le=[...new Set(re.imports.map(he=>he.from))],Be=Le.length===1?Ex(r,Le[0]):Le.length===0&&e?e.modelPath:void 0,lt=he=>{const tt=re.sources.filter(V=>V.scopedBy?.includes(he)).map(V=>V.name);return tt.length>0?{reason:`Applied to every tile on ${tt.join(", ")} by this report's own source. Edit the file to change it.`}:Q.has(he)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:Be!==void 0?{reason:`Set in the model ${Be}. Edit the model to change it.`,modelPath:Be}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...ke].filter(he=>!W.has(he)).map(he=>[he,lt(he)]))},[re,ke,e,r]),{declaredTypes:Ae,applied:ie,panel:qe}=k.useDocumentControls({specs:ue,loaded:G,startingValues:L?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:L?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?O:L?.path,versionId:o,documentName:r,...X!==void 0?{preamble:X}:{},...D?{hostGivens:D}:{}}),Ye=S.useMemo(()=>k.missingRequiredGivens(ue,ie,D),[ue,ie,D]),P=S.useMemo(()=>Object.fromEntries(Object.entries(D??{}).filter(([W])=>!Ae.has(W))),[D,Ae]),F=!_||G||N,U=e!==void 0&&(C.problem!==void 0||A.isError||j.length>0),Y=S.useMemo(()=>new Map(i.document.tiles.map(W=>[fe(W),W])),[i.document]),Se=S.useMemo(()=>xx(re,i.document,r,!!e),[re,i.document,r,e]),we=S.useMemo(()=>function(Q,Le,Be="card"){const lt=(Hn(Q)?Xe.get(Dt(dt(Q))):void 0)??co(Q);if(U)return m.jsxs(k.TileCard,{chrome:Be,children:[m.jsx(k.TileHeading,{title:Le?.title??lt,subtitle:Le?Le.subtitle:Q.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!F)return m.jsxs(k.TileCard,{chrome:Be,children:[m.jsx(k.TileHeading,{title:Le?.title??lt,subtitle:Le?Le.subtitle:Q.subtitle}),m.jsx(k.Loading,{text:"Running…"})]});const he=Z.get(Dt(dt(Q))),V=X===void 0&&he!==void 0&&$x(Y.get(fe(Q)),Q)?{expression:dt(Q),givenNames:[...he],reads:[...he]}:wx(re,Q,Ge,ie,he,Se),se=k.layoutRules(re.layout,re.columns);return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:V.modelPath??O,...X!==void 0&&V.modelPath===void 0?{preamble:X}:{},...I.has(Dt(dt(Q)))?{restricted:!0}:{},tile:V.expression,...V.annotation?{annotation:V.annotation}:{},label:lt,chrome:Be,subtitle:Q.subtitle,...Le?{heading:Le}:{},borderless:Q.borderless,givens:ie,hostGivens:P,declaredTypes:Ae,givenNames:V.givenNames,...(()=>{const Me=k.waitingOn(Ye,V.reads??V.givenNames);return Me.length>0?{waitingFor:k.waitingText(Me)}:{}})(),ignoredFilters:k.tileIgnoredFilterLabels(V.reads,ue),height:Q.rowspan!==void 0||k.isPlaced(re.tiles)?k.tileHeightPx(Q.rowspan??k.PLACED_DEFAULT_ROWSPAN.query):se.tileMaxHeight,tableMaxHeight:se.tableMaxHeight,fixedHeight:Q.rowspan!==void 0||k.isPlaced(re.tiles)})},[re,Y,F,U,Ye,Ge,Z,Xe,t,n,o,O,X,Se,I,ie,P,Ae,ue]),ht=S.useMemo(()=>function(Q){return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:Q.modelPath,tile:`${Q.base} -> ${Q.view}`,...Q.chart?{annotation:k.chartLineText(Q.chart,Q.chartCarried)}:{},label:Q.label,borderless:!0,givens:ie,hostGivens:P,declaredTypes:Ae,givenNames:Q.givens,height:200})},[t,n,o,ie,P,Ae]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&j.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",j.map(W=>W.message).join("; ")]}),Ye.length>0&&!U&&m.jsx($.Alert,{severity:"info",children:k.requiredPrompt(Ye)}),e&&C.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",C.problem]}),e&&A.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",A.error?.message]}),m.jsx(Ga,{...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:Oe,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:we,renderViewPreview:ht,givens:ue.filter(W=>W.name!==void 0).map(W=>({name:W.name,...W.label?{label:W.label}:{},...W.type?{type:W.type}:{},...W.suggest?.dimension?{field:W.suggest.dimension}:{}})),onChange:De,onDirtyChange:u,...c?{onExit:c}:{},...d?{onOpenModel:d}:{},...f?{onControlsChange:f}:{},...h!==void 0?{draftKey:h}:{},..._e?{catalog:_e}:{},dashboards:H,...y?{onEvent:y}:{},controls:G?m.jsx(k.GivensPanel,{...qe,layout:"bar"}):void 0,...ge?{onSave:ge}:{},savesTo:g,...w?{saveLabel:w}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:te}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:x})})]})}function $x(e,t){return e!==void 0&&JSON.stringify(dc(e))===JSON.stringify(dc(t))}function dc(e){const{label:t,subtitle:n,colspan:r,break:s,rowspan:o,row:i,col:a,borderless:l,...u}=e;return u}function Tx(e,t){const n=S.useRef(t);n.current=t;const r=t!==void 0,[s,o]=S.useState();return S.useEffect(()=>{if(!r)return;let i=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{i&&o({from:e,text:a})},a=>{i&&o({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{i=!1}},[e,r]),r?s?.from!==e?{}:s.problem!==void 0?{problem:s.problem}:{text:s.text}:{text:e}}function Ex(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 Cx({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:o}){const[i,a]=S.useState(void 0),[l,u]=S.useState(void 0),[c,d]=S.useState(e===void 0),[f,h]=S.useState(!1),[y,g]=S.useState(void 0);return S.useEffect(()=>{if(!e)return;let w=!1;return g(void 0),(async()=>{try{const x=k.chooseWorkspace(await e.listWorkspaces(!1));if(w)return;if(a(x),x!==void 0&&(!n||x.authoritative)){const p=await e.getDocument(k.locatorFor(t,x.name,r,s,o)).catch(v=>{if(!k.isDocumentNotFound(v))throw v});if(w)return;u(p),h(p!==void 0)}}catch(x){if(w)return;g(k.storageErrorMessage(x))}w||d(!0)})(),()=>{w=!0}},[e,t,n,r,s,o]),{workspace:i,draft:l,setDraft:u,draftChecked:c,offered:f,setOffered:h,readFailure:y}}const Ox=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Mx(e){const t=await oo(e);return so(t)?{ok:!1,reason:Ox(t.reason,t.line)}:{ok:!0,document:t.document}}const Ix="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Dx="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Px({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:o,packageSettled:i,modelPath:a,layout:l,notebook:u,noun:c,legacyFormat:d,textHeld:f,startedAt:h,onEventRef:y}){const g=S.useRef({path:a,layout:l});g.current={path:a,layout:l};const w=S.useRef((ue,Oe)=>{try{y.current?.(k.withReportContext(ue,{...g.current,...Oe?{layout:Oe}:{}}))}catch{}}),x=e?.authoritative===!0,p=x&&r!==void 0,[v,_]=S.useState(void 0),b=(x||v===!0)&&t!==void 0,[E,T]=S.useState(void 0),[M,O]=S.useState(d?Ix:void 0),C=S.useRef(void 0),A=S.useRef(void 0),[R,L]=S.useState(void 0),G=S.useRef(o);G.current=o;const N=R!==void 0&&R.onFetch===o?R.text:s,X=S.useRef(N);X.current=N;const j=b?t:N,[z,D]=S.useState(!1),[I,B]=S.useState(void 0),[q,H]=S.useState(void 0),K=j!==void 0&&j!==q,te=E?.source,_e=K&&(z||!x&&t!==void 0&&te===t&&t!==N)&&te!==void 0&&j!==I,re=_e?te:K?j:te??j,De=_e?j:void 0,ge=S.useRef(te);ge.current=te;const ve=S.useRef(j);ve.current=j;const Ge=S.useRef("package");Ge.current=b?x?"record":"draft":"package",S.useEffect(()=>{if(re===void 0||!n||p||re===ge.current)return;let ue=!1;const Oe=X.current,Ae=ve.current;return Mx(re).then(ie=>{if(!ue){if(ie.ok===!1){O(ie.reason),w.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}O(void 0),C.current=void 0,A.current=Oe,L(void 0),B(void 0),H(Ae),T(qe=>({source:re,document:ie.document,...Oe!==void 0?{packageText:Oe}:{},generation:(qe?.generation??0)+1})),w.current({type:"report.opened",surface:"edit",from:Ge.current,tiles:ie.document.tiles.length,durationMs:k.now()-h.current},ie.document.layout)}}).catch(ie=>{if(ue)return;const qe=`Could not read the ${c}: ${ie instanceof Error?ie.message:String(ie)}`;O(qe),w.current({type:"report.load_failed",surface:"edit",category:k.failureCategory(ie)})}),()=>{ue=!0}},[re,a,n,p,u,c,f,h]),S.useEffect(()=>{d&&w.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[d]),S.useEffect(()=>{!f||!n||E||r!==void 0||(x?t===void 0&&O("the host's storage has no document at this location."):O("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,E,r,x,t]);const Z=u&&!f&&!E&&n&&!b&&i&&s===void 0;return S.useEffect(()=>{Z&&(O(Dx),w.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Z]),{authoritative:x,blockedOnRecord:p,resume:v,setResume:_,fromDraft:b,opened:E,setOpened:T,openError:M,savedHashRef:C,packageBaseRef:A,setWrote:L,fetchedAtRef:G,setDirty:D,setSeen:H,held:De,choose:ue=>{h.current=k.now(),B(ue?t:N),_(ue)},acceptHeld:()=>{h.current=k.now(),B(De)}}}function jx({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:o,modelPath:i,versionId:a,apiClients:l,queryClient:u,mutable:c,textHeld:d,readFailure:f,authoritative:h,resume:y,setResume:g,setOpened:w,setDraft:x,setOffered:p,setSeen:v,setWrote:_,savedHashRef:b,packageBaseRef:E,fetchedAtRef:T}){const M=S.useCallback(I=>t===void 0?void 0:k.locatorFor(I,t.name,s,o,i),[t,s,o,i]),O=M(n),C=S.useCallback(async(I,B=n)=>{const q=M(B);if(!e||!q)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(q,I),w(H=>H&&{...H,source:I}),x(I),(h||y===!0)&&v(I),h||g(H=>H??!1)},[e,M,n,h,y,w,x,v,g]),[A,R]=S.useState(void 0),L=S.useCallback(async I=>{const B=await k.expectedHashFor(b.current,E.current);if(B===void 0)throw new Error("The package file is still loading; try again.");const q=["dashboard-editor-model",s,o,i,a,r];await k.writePackageFile({apiClients:l,queryClient:u,environmentName:s,packageName:o,modelPath:i,source:I,expectedHash:B,invalidateOnError:[q],afterWrite:async H=>{if(w(K=>K&&{...K,source:I}),_({text:I,onFetch:T.current}),v(I),b.current=H,R(void 0),e&&O)try{await e.deleteDocument(O),x(void 0),p(!1)}catch(K){k.isDocumentNotFound(K)?(x(void 0),p(!1)):R(k.storageErrorMessage(K))}g(!1)},invalidate:[{queryKey:q,wait:!0},{queryKey:k.modelResultsKey({environmentName:s,packageName:o,versionId:a,modelPath:i})}]}),k.invalidateReportQueries(u)},[l,s,o,i,a,r,e,O,u,b,E,T,w,_,v,x,p,g]),G=t?.writeable===!0,N=c===!0&&!d,{savesTo:X,pinnedPackageSave:j,writer:z}=k.saveTarget({authoritative:h,mutable:N,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!O&&G&&(!r||h),readFailed:f!==void 0});return{save:z==="storage"?C:z==="package"?L:void 0,savesTo:X,writer:z,pinnedPackageSave:j,takesWrites:N,supersedeFailure:A}}function Ha(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:o,onControlsChange:i,keepDraft:a,kind:l,path:u,textSource:c,queryVersionId:d}=e,f=e.layout??(l?k.layoutOfKind(l):"grid"),h=f==="linear",y=c!==void 0,{environmentName:g,packageName:w,versionId:x,namesBoth:p}=k.resolveEditorTarget(e),_=("resourceUri"in e?e.dashboard:e.dashboardName)??k.documentSlug(u)??"",b="report",{apiClients:E,mutable:T,isLoadingStatus:M,server:O}=be.useServer(),C=uc.useQueryClient(),A=S.useRef(k.now()),R=S.useRef(t);R.current=t;const L=S.useRef(r);L.current=r;const G=k.useOptionalDocumentStorage()?.documentStorage,N=u??k.legacyNamedPath(l??"dashboard",_),X=/\.malloynb$/i.test(N)||h&&/\.malloynb$/i.test(_),j=k.useQueryWithApiError({queryKey:["dashboard-editor-model",g,w,N,x,h],queryFn:()=>E.models.getModel(g,w,N,x,h?!0:void 0),enabled:p&&!X&&!y}),z=j.data?.data?.sourceText,{workspace:D,draft:I,setDraft:B,draftChecked:q,offered:H,setOffered:K,readFailure:te}=Cx({storage:G,layout:f,notebook:h,environmentName:g,packageName:w,modelPath:N}),{authoritative:ye,blockedOnRecord:_e,resume:re,setResume:De,fromDraft:ge,opened:ve,setOpened:Ge,openError:Z,savedHashRef:Xe,packageBaseRef:ke,setWrote:ue,fetchedAtRef:Oe,setDirty:Ae,setSeen:ie,held:qe,choose:Ye,acceptHeld:P}=Px({workspace:D,draft:I,draftChecked:q,readFailure:te,packageText:z,fetchedAt:j.dataUpdatedAt,packageSettled:j.isSuccess&&!j.isFetching,modelPath:N,layout:f,notebook:h,noun:b,legacyFormat:X,textHeld:y,startedAt:A,onEventRef:R}),{save:F,savesTo:U,writer:Y,pinnedPackageSave:Se,takesWrites:we,supersedeFailure:ht}=jx({storage:G,workspace:D,layout:f,notebook:h,environmentName:g,packageName:w,modelPath:N,versionId:x,apiClients:E,queryClient:C,mutable:T,textHeld:y,readFailure:te,authoritative:ye,resume:re,setResume:De,setOpened:Ge,setDraft:B,setOffered:K,setSeen:ie,setWrote:ue,savedHashRef:Xe,packageBaseRef:ke,fetchedAtRef:Oe}),W=D?.name,Q=S.useCallback(ne=>{R.current?.(k.withWorkspace(ne,W))},[W]),Le=j.isError&&!ve,Be=S.useRef(!1);S.useEffect(()=>{!Le||Be.current||(Be.current=!0,k.reportEmitter({path:N,layout:f},R.current).emit({type:"report.load_failed",surface:"edit",category:k.failureCategory(j.error)}))},[Le,j.error,N,f]);const lt=S.useCallback((ne,oe)=>{Ae(ne),L.current?.(oe)},[Ae]),he=!c&&j.data?.data&&z!==void 0&&ve?.source===z?j.data.data:void 0,tt=a?k.reportDraftKey({server:O,environmentName:g,packageName:w,versionId:x,path:u??_}):void 0,V=U==="host"&&D?.description?D.description:void 0,se=!ye&&!y&&T===void 0?M?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":k.saveCaption({authoritative:ye,mutable:we,pinnedPackageSave:Se,...D?{workspace:D}:{},...te!==void 0?{readFailure:te}:{},...x!==void 0?{versionId:x}:{}}),$e=U==="package"&&we===!0&&!Se&&te===void 0||se===V?"":se;if(!p&&"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(j.isError&&!ve)return m.jsx(k.ApiErrorDisplay,{error:j.error,context:`Opening the ${b}`});if(!ve&&(!(y||z)||!q))return n??m.jsx(k.Loading,{text:`Opening the ${b}…`});if(_e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",te]});const Yt=I!==void 0&&I!==z;return m.jsxs($.Stack,{sx:{gap:2},children:[j.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",j.error?.message,". Your edits are still here."]}),!h&&!ye&&H&&Yt&&re===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Ye(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Ye(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),qe!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{tt!==void 0&&k.clearReportDraft(tt),P()},children:"Load it"}),children:U==="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.":U==="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."}),ht!==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:"," ",ht]}),!ve&&(n??m.jsx(k.Loading,{text:`Opening the ${b}…`})),ve&&m.jsx(Sx,{environmentName:g,packageName:w,modelPath:N,...c?{textSource:c}:{},slug:_,...x!==void 0?{versionId:x}:{},...(d??x)!==void 0?{queryVersionId:d??x}:{},opened:ve,...ge&&Y==="package"&&ve.packageText!==void 0?{replaces:ve.packageText}:{},onSave:F,onDirtyChange:lt,...s?{onExit:s}:{},...o?{onOpenModel:o}:{},...i?{onControlsChange:i}:{},...tt!==void 0?{draftKey:tt}:{},savesTo:U,...V?{saveLabel:V}:{},...t?{onEvent:Q}:{},note:$e,...he?{fileModel:he}:{}},ve.generation)]})}const Rx=Ha,Ax=Ga;function Lx(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,o="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(Ha,{...o,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=k.MAX_SLUG_ATTEMPTS;exports.createDocument=k.createDocument;exports.createRoute=k.createRoute;exports.locatorFor=k.locatorFor;exports.newDashboardSource=k.newDashboardSource;exports.newDocumentProblem=k.newDocumentProblem;exports.newNotebookSource=k.newNotebookSource;exports.reportPathFor=k.reportPathFor;exports.reportPathForTitle=k.reportPathForTitle;exports.slugFor=k.slugFor;exports.slugOrFallback=k.slugOrFallback;exports.useDocumentChoices=k.useDocumentChoices;exports.BuilderBar=hx;exports.DashboardBuilder=Ax;exports.DashboardEditor=Rx;exports.NotebookEditor=Lx;exports.ReportBuilder=Ga;exports.ReportEditor=Ha;exports.buildCatalog=Bf;exports.readDashboardDocument=oo;exports.readFailed=so;exports.readReportTagOfText=Bv;exports.spliceDashboardDocument=Tf;exports.spliceFailed=io;
|